[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-f85116f4-d2bf-4367-8eb6-2e6daa56ce3b":3,"$fNu9KhVJas8KreBSEo9kbgM0ja-rbsT9JXZzJlSZkDl0":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"f85116f4-d2bf-4367-8eb6-2e6daa56ce3b","azure-ai-contentsafety-ts","分析文本和图像中的有害内容，使用可自定义的屏蔽列表。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-ai-contentsafety-ts\ndescription: \"Analyze text and images for harmful content with customizable blocklists.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure AI Content Safety REST SDK for TypeScript\n\nAnalyze text and images for harmful content with customizable blocklists.\n\n## Installation\n\n```bash\nnpm install @azure-rest\u002Fai-content-safety @azure\u002Fidentity @azure\u002Fcore-auth\n```\n\n## Environment Variables\n\n```bash\nCONTENT_SAFETY_ENDPOINT=https:\u002F\u002F\u003Cresource>.cognitiveservices.azure.com\nCONTENT_SAFETY_KEY=\u003Capi-key>\n```\n\n## Authentication\n\n**Important**: This is a REST client. `ContentSafetyClient` is a **function**, not a class.\n\n### API Key\n\n```typescript\nimport ContentSafetyClient from \"@azure-rest\u002Fai-content-safety\";\nimport { AzureKeyCredential } from \"@azure\u002Fcore-auth\";\n\nconst client = ContentSafetyClient(\n  process.env.CONTENT_SAFETY_ENDPOINT!,\n  new AzureKeyCredential(process.env.CONTENT_SAFETY_KEY!)\n);\n```\n\n### DefaultAzureCredential\n\n```typescript\nimport ContentSafetyClient from \"@azure-rest\u002Fai-content-safety\";\nimport { DefaultAzureCredential } from \"@azure\u002Fidentity\";\n\nconst client = ContentSafetyClient(\n  process.env.CONTENT_SAFETY_ENDPOINT!,\n  new DefaultAzureCredential()\n);\n```\n\n## Analyze Text\n\n```typescript\nimport ContentSafetyClient, { isUnexpected } from \"@azure-rest\u002Fai-content-safety\";\n\nconst result = await client.path(\"\u002Ftext:analyze\").post({\n  body: {\n    text: \"Text content to analyze\",\n    categories: [\"Hate\", \"Sexual\", \"Violence\", \"SelfHarm\"],\n    outputType: \"FourSeverityLevels\"  \u002F\u002F or \"EightSeverityLevels\"\n  }\n});\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\nfor (const analysis of result.body.categoriesAnalysis) {\n  console.log(`${analysis.category}: severity ${analysis.severity}`);\n}\n```\n\n## Analyze Image\n\n### Base64 Content\n\n```typescript\nimport { readFileSync } from \"node:fs\";\n\nconst imageBuffer = readFileSync(\".\u002Fimage.png\");\nconst base64Image = imageBuffer.toString(\"base64\");\n\nconst result = await client.path(\"\u002Fimage:analyze\").post({\n  body: {\n    image: { content: base64Image }\n  }\n});\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\nfor (const analysis of result.body.categoriesAnalysis) {\n  console.log(`${analysis.category}: severity ${analysis.severity}`);\n}\n```\n\n### Blob URL\n\n```typescript\nconst result = await client.path(\"\u002Fimage:analyze\").post({\n  body: {\n    image: { blobUrl: \"https:\u002F\u002Fstorage.blob.core.windows.net\u002Fcontainer\u002Fimage.png\" }\n  }\n});\n```\n\n## Blocklist Management\n\n### Create Blocklist\n\n```typescript\nconst result = await client\n  .path(\"\u002Ftext\u002Fblocklists\u002F{blocklistName}\", \"my-blocklist\")\n  .patch({\n    contentType: \"application\u002Fmerge-patch+json\",\n    body: {\n      description: \"Custom blocklist for prohibited terms\"\n    }\n  });\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\nconsole.log(`Created: ${result.body.blocklistName}`);\n```\n\n### Add Items to Blocklist\n\n```typescript\nconst result = await client\n  .path(\"\u002Ftext\u002Fblocklists\u002F{blocklistName}:addOrUpdateBlocklistItems\", \"my-blocklist\")\n  .post({\n    body: {\n      blocklistItems: [\n        { text: \"prohibited-term-1\", description: \"First blocked term\" },\n        { text: \"prohibited-term-2\", description: \"Second blocked term\" }\n      ]\n    }\n  });\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\nfor (const item of result.body.blocklistItems ?? []) {\n  console.log(`Added: ${item.blocklistItemId}`);\n}\n```\n\n### Analyze with Blocklist\n\n```typescript\nconst result = await client.path(\"\u002Ftext:analyze\").post({\n  body: {\n    text: \"Text that might contain blocked terms\",\n    blocklistNames: [\"my-blocklist\"],\n    haltOnBlocklistHit: false\n  }\n});\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\n\u002F\u002F Check blocklist matches\nif (result.body.blocklistsMatch) {\n  for (const match of result.body.blocklistsMatch) {\n    console.log(`Blocked: \"${match.blocklistItemText}\" from ${match.blocklistName}`);\n  }\n}\n```\n\n### List Blocklists\n\n```typescript\nconst result = await client.path(\"\u002Ftext\u002Fblocklists\").get();\n\nif (isUnexpected(result)) {\n  throw result.body;\n}\n\nfor (const blocklist of result.body.value ?? []) {\n  console.log(`${blocklist.blocklistName}: ${blocklist.description}`);\n}\n```\n\n### Delete Blocklist\n\n```typescript\nawait client.path(\"\u002Ftext\u002Fblocklists\u002F{blocklistName}\", \"my-blocklist\").delete();\n```\n\n## Harm Categories\n\n| Category | API Term | Description |\n|----------|----------|-------------|\n| Hate and Fairness | `Hate` | Discriminatory language targeting identity groups |\n| Sexual | `Sexual` | Sexual content, nudity, pornography |\n| Violence | `Violence` | Physical harm, weapons, terrorism |\n| Self-Harm | `SelfHarm` | Self-injury, suicide, eating disorders |\n\n## Severity Levels\n\n| Level | Risk | Recommended Action |\n|-------|------|-------------------|\n| 0 | Safe | Allow |\n| 2 | Low | Review or allow with warning |\n| 4 | Medium | Block or require human review |\n| 6 | High | Block immediately |\n\n**Output Types**:\n- `FourSeverityLevels` (default): Returns 0, 2, 4, 6\n- `EightSeverityLevels`: Returns 0-7\n\n## Content Moderation Helper\n\n```typescript\nimport ContentSafetyClient, { \n  isUnexpected, \n  TextCategoriesAnalysisOutput \n} from \"@azure-rest\u002Fai-content-safety\";\n\ninterface ModerationResult {\n  isAllowed: boolean;\n  flaggedCategories: string[];\n  maxSeverity: number;\n  blocklistMatches: string[];\n}\n\nasync function moderateContent(\n  client: ReturnType\u003Ctypeof ContentSafetyClient>,\n  text: string,\n  maxAllowedSeverity = 2,\n  blocklistNames: string[] = []\n): Promise\u003CModerationResult> {\n  const result = await client.path(\"\u002Ftext:analyze\").post({\n    body: { text, blocklistNames, haltOnBlocklistHit: false }\n  });\n\n  if (isUnexpected(result)) {\n    throw result.body;\n  }\n\n  const flaggedCategories = result.body.categoriesAnalysis\n    .filter(c => (c.severity ?? 0) > maxAllowedSeverity)\n    .map(c => c.category!);\n\n  const maxSeverity = Math.max(\n    ...result.body.categoriesAnalysis.map(c => c.severity ?? 0)\n  );\n\n  const blocklistMatches = (result.body.blocklistsMatch ?? [])\n    .map(m => m.blocklistItemText!);\n\n  return {\n    isAllowed: flaggedCategories.length === 0 && blocklistMatches.length === 0,\n    flaggedCategories,\n    maxSeverity,\n    blocklistMatches\n  };\n}\n```\n\n## API Endpoints\n\n| Operation | Method | Path |\n|-----------|--------|------|\n| Analyze Text | POST | `\u002Ftext:analyze` |\n| Analyze Image | POST | `\u002Fimage:analyze` |\n| Create\u002FUpdate Blocklist | PATCH | `\u002Ftext\u002Fblocklists\u002F{blocklistName}` |\n| List Blocklists | GET | `\u002Ftext\u002Fblocklists` |\n| Delete Blocklist | DELETE | `\u002Ftext\u002Fblocklists\u002F{blocklistName}` |\n| Add Blocklist Items | POST | `\u002Ftext\u002Fblocklists\u002F{blocklistName}:addOrUpdateBlocklistItems` |\n| List Blocklist Items | GET | `\u002Ftext\u002Fblocklists\u002F{blocklistName}\u002FblocklistItems` |\n| Remove Blocklist Items | POST | `\u002Ftext\u002Fblocklists\u002F{blocklistName}:removeBlocklistItems` |\n\n## Key Types\n\n```typescript\nimport ContentSafetyClient, {\n  isUnexpected,\n  AnalyzeTextParameters,\n  AnalyzeImageParameters,\n  TextCategoriesAnalysisOutput,\n  ImageCategoriesAnalysisOutput,\n  TextBlocklist,\n  TextBlocklistItem\n} from \"@azure-rest\u002Fai-content-safety\";\n```\n\n## Best Practices\n\n1. **Always use isUnexpected()** - Type guard for error handling\n2. **Set appropriate thresholds** - Different categories may need different severity thresholds\n3. **Use blocklists for domain-specific terms** - Supplement AI detection with custom rules\n4. **Log moderation decisions** - Keep audit trail for compliance\n5. **Handle edge cases** - Empty text, very long text, unsupported image formats\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,192,2037,"2026-05-16 13:05:09",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"d9757292-a167-4dfe-948e-61c31d270055","1.0.0","azure-ai-contentsafety-ts.zip",2736,"uploads\u002Fskills\u002Ff85116f4-d2bf-4367-8eb6-2e6daa56ce3b\u002Fazure-ai-contentsafety-ts.zip","9a184717029ece45cca59aa6108d5ad3c7c73ffb40f080bb732acfae32134359","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":7945}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]