shield360 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +310 -0
- package/dist/__tests__/manual-trace.test.d.ts +1 -0
- package/dist/__tests__/manual-trace.test.js +118 -0
- package/dist/__tests__/manual-trace.test.js.map +1 -0
- package/dist/__tests__/register.test.d.ts +0 -0
- package/dist/__tests__/register.test.js +90 -0
- package/dist/__tests__/register.test.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/constant.d.ts +6 -0
- package/dist/constant.js +14 -0
- package/dist/constant.js.map +1 -0
- package/dist/evals/__tests__/offline.test.d.ts +1 -0
- package/dist/evals/__tests__/offline.test.js +427 -0
- package/dist/evals/__tests__/offline.test.js.map +1 -0
- package/dist/evals/index.d.ts +2 -0
- package/dist/evals/index.js +15 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/evals/offline.d.ts +6 -0
- package/dist/evals/offline.js +350 -0
- package/dist/evals/offline.js.map +1 -0
- package/dist/evals/types.d.ts +74 -0
- package/dist/evals/types.js +23 -0
- package/dist/evals/types.js.map +1 -0
- package/dist/features/__tests__/rule-engine.test.d.ts +1 -0
- package/dist/features/__tests__/rule-engine.test.js +146 -0
- package/dist/features/__tests__/rule-engine.test.js.map +1 -0
- package/dist/features/base.d.ts +8 -0
- package/dist/features/base.js +15 -0
- package/dist/features/base.js.map +1 -0
- package/dist/features/prompt-hub.d.ts +4 -0
- package/dist/features/prompt-hub.js +66 -0
- package/dist/features/prompt-hub.js.map +1 -0
- package/dist/features/rule-engine.d.ts +6 -0
- package/dist/features/rule-engine.js +60 -0
- package/dist/features/rule-engine.js.map +1 -0
- package/dist/features/vault.d.ts +4 -0
- package/dist/features/vault.js +63 -0
- package/dist/features/vault.js.map +1 -0
- package/dist/guard/__tests__/findings.test.d.ts +1 -0
- package/dist/guard/__tests__/findings.test.js +79 -0
- package/dist/guard/__tests__/findings.test.js.map +1 -0
- package/dist/guard/__tests__/integration.test.d.ts +1 -0
- package/dist/guard/__tests__/integration.test.js +215 -0
- package/dist/guard/__tests__/integration.test.js.map +1 -0
- package/dist/guard/__tests__/pii.test.d.ts +1 -0
- package/dist/guard/__tests__/pii.test.js +131 -0
- package/dist/guard/__tests__/pii.test.js.map +1 -0
- package/dist/guard/__tests__/pipeline.test.d.ts +1 -0
- package/dist/guard/__tests__/pipeline.test.js +162 -0
- package/dist/guard/__tests__/pipeline.test.js.map +1 -0
- package/dist/guard/__tests__/prompt-injection.test.d.ts +1 -0
- package/dist/guard/__tests__/prompt-injection.test.js +92 -0
- package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
- package/dist/guard/__tests__/report.test.d.ts +1 -0
- package/dist/guard/__tests__/report.test.js +50 -0
- package/dist/guard/__tests__/report.test.js.map +1 -0
- package/dist/guard/base.d.ts +79 -0
- package/dist/guard/base.js +136 -0
- package/dist/guard/base.js.map +1 -0
- package/dist/guard/custom.d.ts +19 -0
- package/dist/guard/custom.js +46 -0
- package/dist/guard/custom.js.map +1 -0
- package/dist/guard/findings.d.ts +31 -0
- package/dist/guard/findings.js +156 -0
- package/dist/guard/findings.js.map +1 -0
- package/dist/guard/index.d.ts +24 -0
- package/dist/guard/index.js +42 -0
- package/dist/guard/index.js.map +1 -0
- package/dist/guard/integration.d.ts +44 -0
- package/dist/guard/integration.js +363 -0
- package/dist/guard/integration.js.map +1 -0
- package/dist/guard/moderation.d.ts +18 -0
- package/dist/guard/moderation.js +61 -0
- package/dist/guard/moderation.js.map +1 -0
- package/dist/guard/pii.d.ts +17 -0
- package/dist/guard/pii.js +114 -0
- package/dist/guard/pii.js.map +1 -0
- package/dist/guard/pipeline.d.ts +26 -0
- package/dist/guard/pipeline.js +139 -0
- package/dist/guard/pipeline.js.map +1 -0
- package/dist/guard/prompt-injection.d.ts +21 -0
- package/dist/guard/prompt-injection.js +70 -0
- package/dist/guard/prompt-injection.js.map +1 -0
- package/dist/guard/report.d.ts +34 -0
- package/dist/guard/report.js +182 -0
- package/dist/guard/report.js.map +1 -0
- package/dist/guard/schema.d.ts +20 -0
- package/dist/guard/schema.js +99 -0
- package/dist/guard/schema.js.map +1 -0
- package/dist/guard/sensitive-topic.d.ts +23 -0
- package/dist/guard/sensitive-topic.js +89 -0
- package/dist/guard/sensitive-topic.js.map +1 -0
- package/dist/guard/topic-restriction.d.ts +22 -0
- package/dist/guard/topic-restriction.js +54 -0
- package/dist/guard/topic-restriction.js.map +1 -0
- package/dist/helpers.d.ts +246 -0
- package/dist/helpers.js +903 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.js +171 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +15 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js +155 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.d.ts +18 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +209 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js +256 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.d.ts +4 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +229 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +687 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +529 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.js +285 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.d.ts +17 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +206 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +345 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.js +179 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.d.ts +17 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +182 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +8 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +346 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.d.ts +4 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js +289 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.d.ts +67 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.js +255 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.js.map +1 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/ai21/index.d.ts +11 -0
- package/dist/instrumentation/ai21/index.js +67 -0
- package/dist/instrumentation/ai21/index.js.map +1 -0
- package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
- package/dist/instrumentation/ai21/wrapper.js +511 -0
- package/dist/instrumentation/ai21/wrapper.js.map +1 -0
- package/dist/instrumentation/anthropic/index.d.ts +11 -0
- package/dist/instrumentation/anthropic/index.js +45 -0
- package/dist/instrumentation/anthropic/index.js.map +1 -0
- package/dist/instrumentation/anthropic/wrapper.d.ts +34 -0
- package/dist/instrumentation/anthropic/wrapper.js +426 -0
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -0
- package/dist/instrumentation/assemblyai/index.d.ts +12 -0
- package/dist/instrumentation/assemblyai/index.js +91 -0
- package/dist/instrumentation/assemblyai/index.js.map +1 -0
- package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
- package/dist/instrumentation/assemblyai/wrapper.js +238 -0
- package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
- package/dist/instrumentation/astra/index.d.ts +11 -0
- package/dist/instrumentation/astra/index.js +87 -0
- package/dist/instrumentation/astra/index.js.map +1 -0
- package/dist/instrumentation/astra/wrapper.d.ts +39 -0
- package/dist/instrumentation/astra/wrapper.js +349 -0
- package/dist/instrumentation/astra/wrapper.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
- package/dist/instrumentation/azure-ai-inference/index.js +76 -0
- package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +55 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js +580 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
- package/dist/instrumentation/base-wrapper.d.ts +16 -0
- package/dist/instrumentation/base-wrapper.js +139 -0
- package/dist/instrumentation/base-wrapper.js.map +1 -0
- package/dist/instrumentation/bedrock/index.d.ts +11 -0
- package/dist/instrumentation/bedrock/index.js +52 -0
- package/dist/instrumentation/bedrock/index.js.map +1 -0
- package/dist/instrumentation/bedrock/wrapper.d.ts +41 -0
- package/dist/instrumentation/bedrock/wrapper.js +494 -0
- package/dist/instrumentation/bedrock/wrapper.js.map +1 -0
- package/dist/instrumentation/browser-use/index.d.ts +11 -0
- package/dist/instrumentation/browser-use/index.js +98 -0
- package/dist/instrumentation/browser-use/index.js.map +1 -0
- package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
- package/dist/instrumentation/browser-use/wrapper.js +706 -0
- package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
- package/dist/instrumentation/chroma/index.d.ts +11 -0
- package/dist/instrumentation/chroma/index.js +70 -0
- package/dist/instrumentation/chroma/index.js.map +1 -0
- package/dist/instrumentation/chroma/wrapper.d.ts +10 -0
- package/dist/instrumentation/chroma/wrapper.js +127 -0
- package/dist/instrumentation/chroma/wrapper.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
- package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
- package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js +1123 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
- package/dist/instrumentation/cohere/index.d.ts +11 -0
- package/dist/instrumentation/cohere/index.js +53 -0
- package/dist/instrumentation/cohere/index.js.map +1 -0
- package/dist/instrumentation/cohere/wrapper.d.ts +50 -0
- package/dist/instrumentation/cohere/wrapper.js +452 -0
- package/dist/instrumentation/cohere/wrapper.js.map +1 -0
- package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
- package/dist/instrumentation/cursor-sdk/index.js +58 -0
- package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
- package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
- package/dist/instrumentation/cursor-sdk/wrapper.js +789 -0
- package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
- package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
- package/dist/instrumentation/elevenlabs/index.js +92 -0
- package/dist/instrumentation/elevenlabs/index.js.map +1 -0
- package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
- package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
- package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
- package/dist/instrumentation/firecrawl/index.d.ts +13 -0
- package/dist/instrumentation/firecrawl/index.js +115 -0
- package/dist/instrumentation/firecrawl/index.js.map +1 -0
- package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
- package/dist/instrumentation/firecrawl/wrapper.js +378 -0
- package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
- package/dist/instrumentation/google-adk/index.d.ts +57 -0
- package/dist/instrumentation/google-adk/index.js +371 -0
- package/dist/instrumentation/google-adk/index.js.map +1 -0
- package/dist/instrumentation/google-adk/utils.d.ts +45 -0
- package/dist/instrumentation/google-adk/utils.js +663 -0
- package/dist/instrumentation/google-adk/utils.js.map +1 -0
- package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
- package/dist/instrumentation/google-adk/wrapper.js +391 -0
- package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
- package/dist/instrumentation/google-ai/index.d.ts +11 -0
- package/dist/instrumentation/google-ai/index.js +48 -0
- package/dist/instrumentation/google-ai/index.js.map +1 -0
- package/dist/instrumentation/google-ai/wrapper.d.ts +52 -0
- package/dist/instrumentation/google-ai/wrapper.js +466 -0
- package/dist/instrumentation/google-ai/wrapper.js.map +1 -0
- package/dist/instrumentation/gpu/index.d.ts +38 -0
- package/dist/instrumentation/gpu/index.js +233 -0
- package/dist/instrumentation/gpu/index.js.map +1 -0
- package/dist/instrumentation/gradient/index.d.ts +12 -0
- package/dist/instrumentation/gradient/index.js +74 -0
- package/dist/instrumentation/gradient/index.js.map +1 -0
- package/dist/instrumentation/gradient/utils.d.ts +14 -0
- package/dist/instrumentation/gradient/utils.js +119 -0
- package/dist/instrumentation/gradient/utils.js.map +1 -0
- package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
- package/dist/instrumentation/gradient/wrapper.js +584 -0
- package/dist/instrumentation/gradient/wrapper.js.map +1 -0
- package/dist/instrumentation/groq/index.d.ts +11 -0
- package/dist/instrumentation/groq/index.js +43 -0
- package/dist/instrumentation/groq/index.js.map +1 -0
- package/dist/instrumentation/groq/wrapper.d.ts +35 -0
- package/dist/instrumentation/groq/wrapper.js +442 -0
- package/dist/instrumentation/groq/wrapper.js.map +1 -0
- package/dist/instrumentation/huggingface/index.d.ts +13 -0
- package/dist/instrumentation/huggingface/index.js +110 -0
- package/dist/instrumentation/huggingface/index.js.map +1 -0
- package/dist/instrumentation/huggingface/wrapper.d.ts +54 -0
- package/dist/instrumentation/huggingface/wrapper.js +514 -0
- package/dist/instrumentation/huggingface/wrapper.js.map +1 -0
- package/dist/instrumentation/index.d.ts +7 -0
- package/dist/instrumentation/index.js +176 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/langchain/index.d.ts +16 -0
- package/dist/instrumentation/langchain/index.js +91 -0
- package/dist/instrumentation/langchain/index.js.map +1 -0
- package/dist/instrumentation/langchain/wrapper.d.ts +41 -0
- package/dist/instrumentation/langchain/wrapper.js +1235 -0
- package/dist/instrumentation/langchain/wrapper.js.map +1 -0
- package/dist/instrumentation/langgraph/index.d.ts +12 -0
- package/dist/instrumentation/langgraph/index.js +99 -0
- package/dist/instrumentation/langgraph/index.js.map +1 -0
- package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
- package/dist/instrumentation/langgraph/wrapper.js +620 -0
- package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
- package/dist/instrumentation/letta/index.d.ts +10 -0
- package/dist/instrumentation/letta/index.js +122 -0
- package/dist/instrumentation/letta/index.js.map +1 -0
- package/dist/instrumentation/letta/utils.d.ts +24 -0
- package/dist/instrumentation/letta/utils.js +343 -0
- package/dist/instrumentation/letta/utils.js.map +1 -0
- package/dist/instrumentation/letta/wrapper.d.ts +37 -0
- package/dist/instrumentation/letta/wrapper.js +180 -0
- package/dist/instrumentation/letta/wrapper.js.map +1 -0
- package/dist/instrumentation/llamaindex/index.d.ts +36 -0
- package/dist/instrumentation/llamaindex/index.js +221 -0
- package/dist/instrumentation/llamaindex/index.js.map +1 -0
- package/dist/instrumentation/llamaindex/wrapper.d.ts +36 -0
- package/dist/instrumentation/llamaindex/wrapper.js +811 -0
- package/dist/instrumentation/llamaindex/wrapper.js.map +1 -0
- package/dist/instrumentation/mcp/index.d.ts +20 -0
- package/dist/instrumentation/mcp/index.js +282 -0
- package/dist/instrumentation/mcp/index.js.map +1 -0
- package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
- package/dist/instrumentation/mcp/wrapper.js +571 -0
- package/dist/instrumentation/mcp/wrapper.js.map +1 -0
- package/dist/instrumentation/mem0/index.d.ts +17 -0
- package/dist/instrumentation/mem0/index.js +113 -0
- package/dist/instrumentation/mem0/index.js.map +1 -0
- package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
- package/dist/instrumentation/mem0/wrapper.js +298 -0
- package/dist/instrumentation/mem0/wrapper.js.map +1 -0
- package/dist/instrumentation/milvus/index.d.ts +11 -0
- package/dist/instrumentation/milvus/index.js +67 -0
- package/dist/instrumentation/milvus/index.js.map +1 -0
- package/dist/instrumentation/milvus/wrapper.d.ts +15 -0
- package/dist/instrumentation/milvus/wrapper.js +219 -0
- package/dist/instrumentation/milvus/wrapper.js.map +1 -0
- package/dist/instrumentation/mistral/index.d.ts +11 -0
- package/dist/instrumentation/mistral/index.js +66 -0
- package/dist/instrumentation/mistral/index.js.map +1 -0
- package/dist/instrumentation/mistral/wrapper.d.ts +49 -0
- package/dist/instrumentation/mistral/wrapper.js +482 -0
- package/dist/instrumentation/mistral/wrapper.js.map +1 -0
- package/dist/instrumentation/ollama/index.d.ts +11 -0
- package/dist/instrumentation/ollama/index.js +72 -0
- package/dist/instrumentation/ollama/index.js.map +1 -0
- package/dist/instrumentation/ollama/wrapper.d.ts +73 -0
- package/dist/instrumentation/ollama/wrapper.js +629 -0
- package/dist/instrumentation/ollama/wrapper.js.map +1 -0
- package/dist/instrumentation/openai/index.d.ts +11 -0
- package/dist/instrumentation/openai/index.js +79 -0
- package/dist/instrumentation/openai/index.js.map +1 -0
- package/dist/instrumentation/openai/wrapper.d.ts +80 -0
- package/dist/instrumentation/openai/wrapper.js +1121 -0
- package/dist/instrumentation/openai/wrapper.js.map +1 -0
- package/dist/instrumentation/openai-agents/index.d.ts +20 -0
- package/dist/instrumentation/openai-agents/index.js +174 -0
- package/dist/instrumentation/openai-agents/index.js.map +1 -0
- package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
- package/dist/instrumentation/openai-agents/processor.js +249 -0
- package/dist/instrumentation/openai-agents/processor.js.map +1 -0
- package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
- package/dist/instrumentation/openai-agents/utils.js +624 -0
- package/dist/instrumentation/openai-agents/utils.js.map +1 -0
- package/dist/instrumentation/pg/index.d.ts +20 -0
- package/dist/instrumentation/pg/index.js +74 -0
- package/dist/instrumentation/pg/index.js.map +1 -0
- package/dist/instrumentation/pg/wrapper.d.ts +66 -0
- package/dist/instrumentation/pg/wrapper.js +441 -0
- package/dist/instrumentation/pg/wrapper.js.map +1 -0
- package/dist/instrumentation/pinecone/index.d.ts +11 -0
- package/dist/instrumentation/pinecone/index.js +79 -0
- package/dist/instrumentation/pinecone/index.js.map +1 -0
- package/dist/instrumentation/pinecone/wrapper.d.ts +14 -0
- package/dist/instrumentation/pinecone/wrapper.js +198 -0
- package/dist/instrumentation/pinecone/wrapper.js.map +1 -0
- package/dist/instrumentation/qdrant/index.d.ts +11 -0
- package/dist/instrumentation/qdrant/index.js +67 -0
- package/dist/instrumentation/qdrant/index.js.map +1 -0
- package/dist/instrumentation/qdrant/wrapper.d.ts +14 -0
- package/dist/instrumentation/qdrant/wrapper.js +213 -0
- package/dist/instrumentation/qdrant/wrapper.js.map +1 -0
- package/dist/instrumentation/replicate/index.d.ts +11 -0
- package/dist/instrumentation/replicate/index.js +57 -0
- package/dist/instrumentation/replicate/index.js.map +1 -0
- package/dist/instrumentation/replicate/wrapper.d.ts +28 -0
- package/dist/instrumentation/replicate/wrapper.js +242 -0
- package/dist/instrumentation/replicate/wrapper.js.map +1 -0
- package/dist/instrumentation/strands/index.d.ts +21 -0
- package/dist/instrumentation/strands/index.js +83 -0
- package/dist/instrumentation/strands/index.js.map +1 -0
- package/dist/instrumentation/strands/processor.d.ts +51 -0
- package/dist/instrumentation/strands/processor.js +625 -0
- package/dist/instrumentation/strands/processor.js.map +1 -0
- package/dist/instrumentation/strands/utils.d.ts +24 -0
- package/dist/instrumentation/strands/utils.js +373 -0
- package/dist/instrumentation/strands/utils.js.map +1 -0
- package/dist/instrumentation/together/index.d.ts +11 -0
- package/dist/instrumentation/together/index.js +43 -0
- package/dist/instrumentation/together/index.js.map +1 -0
- package/dist/instrumentation/together/wrapper.d.ts +48 -0
- package/dist/instrumentation/together/wrapper.js +409 -0
- package/dist/instrumentation/together/wrapper.js.map +1 -0
- package/dist/instrumentation/transformers/index.d.ts +35 -0
- package/dist/instrumentation/transformers/index.js +119 -0
- package/dist/instrumentation/transformers/index.js.map +1 -0
- package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
- package/dist/instrumentation/transformers/wrapper.js +472 -0
- package/dist/instrumentation/transformers/wrapper.js.map +1 -0
- package/dist/instrumentation/vercel-ai/index.d.ts +10 -0
- package/dist/instrumentation/vercel-ai/index.js +59 -0
- package/dist/instrumentation/vercel-ai/index.js.map +1 -0
- package/dist/instrumentation/vercel-ai/wrapper.d.ts +50 -0
- package/dist/instrumentation/vercel-ai/wrapper.js +539 -0
- package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -0
- package/dist/instrumentation/vertexai/index.d.ts +11 -0
- package/dist/instrumentation/vertexai/index.js +70 -0
- package/dist/instrumentation/vertexai/index.js.map +1 -0
- package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
- package/dist/instrumentation/vertexai/wrapper.js +530 -0
- package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
- package/dist/instrumentation/vllm/index.d.ts +13 -0
- package/dist/instrumentation/vllm/index.js +67 -0
- package/dist/instrumentation/vllm/index.js.map +1 -0
- package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
- package/dist/instrumentation/vllm/wrapper.js +482 -0
- package/dist/instrumentation/vllm/wrapper.js.map +1 -0
- package/dist/llm/anthropic.d.ts +5 -0
- package/dist/llm/anthropic.js +39 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/index.d.ts +10 -0
- package/dist/llm/index.js +93 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/openai.d.ts +6 -0
- package/dist/llm/openai.js +52 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/providers.d.ts +7 -0
- package/dist/llm/providers.js +10 -0
- package/dist/llm/providers.js.map +1 -0
- package/dist/manual-trace.d.ts +40 -0
- package/dist/manual-trace.js +103 -0
- package/dist/manual-trace.js.map +1 -0
- package/dist/otel/__tests__/metrics.test.d.ts +1 -0
- package/dist/otel/__tests__/metrics.test.js +40 -0
- package/dist/otel/__tests__/metrics.test.js.map +1 -0
- package/dist/otel/events.d.ts +11 -0
- package/dist/otel/events.js +74 -0
- package/dist/otel/events.js.map +1 -0
- package/dist/otel/metrics.d.ts +35 -0
- package/dist/otel/metrics.js +219 -0
- package/dist/otel/metrics.js.map +1 -0
- package/dist/otel/tracing.d.ts +12 -0
- package/dist/otel/tracing.js +93 -0
- package/dist/otel/tracing.js.map +1 -0
- package/dist/otel/utils.d.ts +11 -0
- package/dist/otel/utils.js +34 -0
- package/dist/otel/utils.js.map +1 -0
- package/dist/pricing.json +951 -0
- package/dist/prompt-hub.d.ts +4 -0
- package/dist/prompt-hub.js +66 -0
- package/dist/prompt-hub.js.map +1 -0
- package/dist/register.d.ts +4 -0
- package/dist/register.js +52 -0
- package/dist/register.js.map +1 -0
- package/dist/score/__tests__/score.test.d.ts +1 -0
- package/dist/score/__tests__/score.test.js +143 -0
- package/dist/score/__tests__/score.test.js.map +1 -0
- package/dist/score/index.d.ts +2 -0
- package/dist/score/index.js +6 -0
- package/dist/score/index.js.map +1 -0
- package/dist/score/score.d.ts +15 -0
- package/dist/score/score.js +135 -0
- package/dist/score/score.js.map +1 -0
- package/dist/semantic-convention.d.ts +555 -0
- package/dist/semantic-convention.js +630 -0
- package/dist/semantic-convention.js.map +1 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +136 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Guard Pipeline -- composes multiple guards into an ordered evaluation chain.
|
|
4
|
+
*
|
|
5
|
+
* Must stay in sync with: sdk/python/src/shield360/guard/_pipeline.py
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Pipeline = void 0;
|
|
9
|
+
const api_1 = require("@opentelemetry/api");
|
|
10
|
+
const base_1 = require("./base");
|
|
11
|
+
const report_1 = require("./report");
|
|
12
|
+
class Pipeline {
|
|
13
|
+
constructor(opts = {}) {
|
|
14
|
+
this._guards = [...(opts.guards || [])];
|
|
15
|
+
this._failOpen = opts.failOpen ?? true;
|
|
16
|
+
}
|
|
17
|
+
get guards() {
|
|
18
|
+
return [...this._guards];
|
|
19
|
+
}
|
|
20
|
+
evaluate(text, phase = 'preflight') {
|
|
21
|
+
const validPhases = Object.values(base_1.GuardPhase);
|
|
22
|
+
if (!validPhases.includes(phase)) {
|
|
23
|
+
throw new base_1.GuardConfigError(`Invalid phase '${phase}'. Must be one of: ${validPhases.join(', ')}`);
|
|
24
|
+
}
|
|
25
|
+
const guardPhase = phase;
|
|
26
|
+
const results = [];
|
|
27
|
+
let currentText = text;
|
|
28
|
+
let worstAction = base_1.GuardAction.ALLOW;
|
|
29
|
+
for (const guard of this._guards) {
|
|
30
|
+
if (!guard.supportsPhase(guardPhase)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
let result;
|
|
34
|
+
try {
|
|
35
|
+
result = guard.run(currentText, guardPhase);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (this._failOpen) {
|
|
39
|
+
console.warn(`Guard '${guard.name}' raised during ${phase} evaluation; fail-open -> allow`, e);
|
|
40
|
+
result = (0, base_1.makeGuardResult)({ guardName: guard.name });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
results.push(result);
|
|
47
|
+
Pipeline._emitOtel(result, phase);
|
|
48
|
+
if (base_1.ACTION_SEVERITY[result.action] > base_1.ACTION_SEVERITY[worstAction]) {
|
|
49
|
+
worstAction = result.action;
|
|
50
|
+
}
|
|
51
|
+
if (result.action === base_1.GuardAction.REDACT && result.transformedText !== null) {
|
|
52
|
+
currentText = result.transformedText;
|
|
53
|
+
}
|
|
54
|
+
if (result.action === base_1.GuardAction.DENY) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const transformed = currentText !== text ? currentText : null;
|
|
59
|
+
return new base_1.PipelineResult(worstAction, results, transformed);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply every redacting guard to `text` and return the result.
|
|
63
|
+
*
|
|
64
|
+
* Used after `evaluate` has already decided a call is redacted, to rewrite
|
|
65
|
+
* each message on its own. Emits nothing: the decision, and its telemetry,
|
|
66
|
+
* came from `evaluate`.
|
|
67
|
+
*/
|
|
68
|
+
redact(text, phase = 'preflight') {
|
|
69
|
+
const guardPhase = phase;
|
|
70
|
+
let current = text;
|
|
71
|
+
for (const guard of this._guards) {
|
|
72
|
+
if (!guard.supportsPhase(guardPhase))
|
|
73
|
+
continue;
|
|
74
|
+
let result;
|
|
75
|
+
try {
|
|
76
|
+
result = guard.run(current, guardPhase);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
if (this._failOpen)
|
|
80
|
+
continue;
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
if (result.action === base_1.GuardAction.REDACT && result.transformedText !== null) {
|
|
84
|
+
current = result.transformedText;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return current;
|
|
88
|
+
}
|
|
89
|
+
static _emitOtel(result, phase) {
|
|
90
|
+
(0, report_1.reportGuardDecision)(result.guardName, result.action, result.classification, phase, result.findings);
|
|
91
|
+
try {
|
|
92
|
+
const Metrics = require('../otel/metrics').default;
|
|
93
|
+
if (Metrics?.guardRequests) {
|
|
94
|
+
Metrics.guardRequests.add(1, {
|
|
95
|
+
'guard.name': result.guardName,
|
|
96
|
+
'guard.action': result.action,
|
|
97
|
+
'guard.score': result.score,
|
|
98
|
+
'guard.classification': result.classification,
|
|
99
|
+
'guard.phase': phase,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// metrics not initialized yet
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const attributes = {
|
|
108
|
+
'guard.name': result.guardName,
|
|
109
|
+
'guard.phase': phase,
|
|
110
|
+
'guard.action': result.action,
|
|
111
|
+
'guard.score': result.score,
|
|
112
|
+
'guard.classification': result.classification,
|
|
113
|
+
'guard.explanation': result.explanation,
|
|
114
|
+
'guard.latency_ms': result.latencyMs,
|
|
115
|
+
};
|
|
116
|
+
const span = api_1.trace.getActiveSpan();
|
|
117
|
+
if (span && span.isRecording()) {
|
|
118
|
+
span.addEvent('guard.evaluation', attributes);
|
|
119
|
+
}
|
|
120
|
+
else if (result.action !== base_1.GuardAction.ALLOW) {
|
|
121
|
+
// Guards run before the LLM call's span starts, and a denied call
|
|
122
|
+
// never starts one. Record what the guard did on a span of its own so
|
|
123
|
+
// a block or redaction is never invisible. Only the kind of data found
|
|
124
|
+
// is recorded, never the text.
|
|
125
|
+
const own = api_1.trace.getTracer('shield360.guard').startSpan('shield360.guard', { attributes });
|
|
126
|
+
own.addEvent('guard.evaluation', attributes);
|
|
127
|
+
if (result.action === base_1.GuardAction.DENY) {
|
|
128
|
+
own.setStatus({ code: api_1.SpanStatusCode.ERROR, message: 'denied by guard' });
|
|
129
|
+
}
|
|
130
|
+
own.end();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// tracing not initialized
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.Pipeline = Pipeline;
|
|
139
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/guard/pipeline.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,4CAA2D;AAC3D,iCASgB;AAChB,qCAA+C;AAO/C,MAAa,QAAQ;IAInB,YAAY,OAAwB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,QAAQ,CAAC,IAAY,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ClE,sEAAsE;gBACtE,uEAAuE;gBACvE,+BAA+B;gBAC/B,MAAM,GAAG,GAAG,WAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;gBAC5F,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;gBAC7C,IAAI,MAAM,CAAC,MAAM,KAAK,kBAAW,CAAC,IAAI,EAAE,CAAC;oBACvC,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,oBAAc,CAAC,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;gBAC5E,CAAC;gBACD,GAAG,CAAC,GAAG,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,0BAA0B;QAC5B,CAAC;IACH,CAAC;CACF;AA1ID,4BA0IC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt injection & jailbreak detection guard.
|
|
3
|
+
*
|
|
4
|
+
* Fast regex patterns catch known injection signatures. An optional
|
|
5
|
+
* user-provided classifier handles ambiguous cases.
|
|
6
|
+
*
|
|
7
|
+
* Patterns must stay in sync with: sdk/python/src/shield360/guard/prompt_injection.py
|
|
8
|
+
*/
|
|
9
|
+
import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
|
|
10
|
+
export interface PromptInjectionOptions extends GuardOptions {
|
|
11
|
+
threshold?: number;
|
|
12
|
+
classifier?: (text: string) => number;
|
|
13
|
+
}
|
|
14
|
+
export declare class PromptInjection extends Guard {
|
|
15
|
+
readonly name = "prompt_injection";
|
|
16
|
+
readonly phases: GuardPhase[];
|
|
17
|
+
private readonly _threshold;
|
|
18
|
+
private readonly _classifier?;
|
|
19
|
+
constructor(opts?: PromptInjectionOptions);
|
|
20
|
+
evaluate(text: string): GuardResult;
|
|
21
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompt injection & jailbreak detection guard.
|
|
4
|
+
*
|
|
5
|
+
* Fast regex patterns catch known injection signatures. An optional
|
|
6
|
+
* user-provided classifier handles ambiguous cases.
|
|
7
|
+
*
|
|
8
|
+
* Patterns must stay in sync with: sdk/python/src/shield360/guard/prompt_injection.py
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PromptInjection = void 0;
|
|
12
|
+
const base_1 = require("./base");
|
|
13
|
+
const INJECTION_PATTERNS = [
|
|
14
|
+
// ---- Instruction override ----
|
|
15
|
+
{ label: 'instruction-override', regex: /ignore\s+(?:all\s+)?(?:previous|above|prior)\s+(?:instructions|prompts|rules)/i, weight: 0.9 },
|
|
16
|
+
{ label: 'instruction-override-2', regex: /disregard\s+(?:all\s+)?(?:previous|above|prior)\s+(?:instructions|context)/i, weight: 0.9 },
|
|
17
|
+
{ label: 'new-instructions', regex: /(?:new|updated|revised)\s+instructions\s*:/i, weight: 0.7 },
|
|
18
|
+
{ label: 'do-anything-now', regex: /(?:DAN|do\s+anything\s+now)\s+mode/i, weight: 0.95 },
|
|
19
|
+
{ label: 'jailbreak-keyword', regex: /jailbreak(?:ed|ing)?/i, weight: 0.8 },
|
|
20
|
+
// ---- System prompt extraction ----
|
|
21
|
+
{ label: 'system-prompt-leak', regex: /(?:show|reveal|display|print|output|repeat|tell\s+me)\s+(?:your|the|me\s+your)\s*(?:system|initial|original|hidden)\s+(?:prompt|instructions|message)/i, weight: 0.85 },
|
|
22
|
+
{ label: 'system-prompt-leak-2', regex: /what\s+(?:are|were)\s+your\s+(?:system|initial|original)\s+(?:instructions|prompt)/i, weight: 0.8 },
|
|
23
|
+
{ label: 'system-prompt-leak-3', regex: /(?:show|reveal|display|print|output|repeat)\s+(?:me\s+)?your\s+(?:system\s+)?prompt/i, weight: 0.8 },
|
|
24
|
+
// ---- Role impersonation ----
|
|
25
|
+
{ label: 'role-play', regex: /(?:you\s+are\s+now|act\s+as|pretend\s+(?:to\s+be|you\s+are)|roleplay\s+as)\s+(?:a\s+)?(?:hacker|evil|malicious|unrestricted|unfiltered)/i, weight: 0.85 },
|
|
26
|
+
{ label: 'developer-mode', regex: /(?:developer|debug|admin|god|sudo|root)\s+mode/i, weight: 0.7 },
|
|
27
|
+
// ---- Encoding bypass ----
|
|
28
|
+
{ label: 'base64-injection', regex: /(?:decode|base64|eval)\s*\(/i, weight: 0.6 },
|
|
29
|
+
{ label: 'markdown-injection', regex: /\[.*?\]\((?:javascript|data):/i, weight: 0.8 },
|
|
30
|
+
// ---- Delimiter abuse ----
|
|
31
|
+
{ label: 'delimiter-abuse', regex: /={5,}|<\|(?:im_start|system|endoftext)\|>|###\s*(?:system|instruction)/i, weight: 0.7 },
|
|
32
|
+
];
|
|
33
|
+
class PromptInjection extends base_1.Guard {
|
|
34
|
+
constructor(opts = {}) {
|
|
35
|
+
super({ action: opts.action ?? 'deny', maxScanLength: opts.maxScanLength });
|
|
36
|
+
this.name = 'prompt_injection';
|
|
37
|
+
this.phases = [base_1.GuardPhase.PREFLIGHT];
|
|
38
|
+
this._threshold = opts.threshold ?? 0.5;
|
|
39
|
+
this._classifier = opts.classifier;
|
|
40
|
+
}
|
|
41
|
+
evaluate(text) {
|
|
42
|
+
const matchedLabels = [];
|
|
43
|
+
let maxWeight = 0;
|
|
44
|
+
for (const { label, regex, weight } of INJECTION_PATTERNS) {
|
|
45
|
+
if (regex.test(text)) {
|
|
46
|
+
matchedLabels.push(label);
|
|
47
|
+
if (weight > maxWeight) {
|
|
48
|
+
maxWeight = weight;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let score = maxWeight;
|
|
53
|
+
if (matchedLabels.length === 0 && this._classifier) {
|
|
54
|
+
score = this._classifier(text);
|
|
55
|
+
}
|
|
56
|
+
if (score >= this._threshold) {
|
|
57
|
+
const classification = matchedLabels.length > 0 ? matchedLabels.join(', ') : 'classifier';
|
|
58
|
+
return (0, base_1.makeGuardResult)({
|
|
59
|
+
action: this._action,
|
|
60
|
+
score: Math.round(score * 1000) / 1000,
|
|
61
|
+
guardName: this.name,
|
|
62
|
+
classification,
|
|
63
|
+
explanation: `Prompt injection detected (score=${score.toFixed(2)}): ${classification}`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return (0, base_1.makeGuardResult)({ guardName: this.name, score: Math.round(score * 1000) / 1000 });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.PromptInjection = PromptInjection;
|
|
70
|
+
//# sourceMappingURL=prompt-injection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-injection.js","sourceRoot":"","sources":["../../src/guard/prompt-injection.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iCAAuF;AAQvF,MAAM,kBAAkB,GAAuB;IAC7C,iCAAiC;IACjC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,gFAAgF,EAAE,MAAM,EAAE,GAAG,EAAE;IACvI,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,6EAA6E,EAAE,MAAM,EAAE,GAAG,EAAE;IACtI,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,6CAA6C,EAAE,MAAM,EAAE,GAAG,EAAE;IAChG,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,qCAAqC,EAAE,MAAM,EAAE,IAAI,EAAE;IACxF,EAAE,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,GAAG,EAAE;IAC3E,qCAAqC;IACrC,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,wJAAwJ,EAAE,MAAM,EAAE,IAAI,EAAE;IAC9M,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,qFAAqF,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5I,EA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;gBACrB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1B,IAAI,MAAM,GAAG,SAAS,EAAE,CAAC;oBACvB,SAAS,GAAG,MAAM,CAAC;gBACrB,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,GAAG,SAAS,CAAC;QAEtB,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnD,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC7B,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;YAC1F,OAAO,IAAA,sBAAe,EAAC;gBACrB,MAAM,EAAE,IAAI,CAAC,OAAO;gBACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI;gBACtC,SAAS,EAAE,IAAI,CAAC,IAAI;gBACpB,cAAc;gBACd,WAAW,EAAE,oCAAoC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,cAAc,EAAE;aACxF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAA,sBAAe,EAAC,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IAC3F,CAAC;CACF;AA7CD,0CA6CC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports guard decisions to Shield360 as compliance evidence.
|
|
3
|
+
*
|
|
4
|
+
* When `init` is given a Shield360 URL and API key (or SHIELD360_URL /
|
|
5
|
+
* SHIELD360_API_KEY), every guard decision other than allow is sent to
|
|
6
|
+
* `/api/guard/events`: which guard, what it did, the kind of data found, in
|
|
7
|
+
* which app, on which host. Never the text that was checked.
|
|
8
|
+
*
|
|
9
|
+
* With each report go the values found, masked, and fingerprinted with the
|
|
10
|
+
* organisation's key (fetched from `/api/guard/config`), so a reviewer can see
|
|
11
|
+
* the same value recurring. The full value is never sent.
|
|
12
|
+
*
|
|
13
|
+
* Reports are queued and sent in batches off the call path, so a guard adds no
|
|
14
|
+
* network time to the call it protects. A batch that cannot be delivered is
|
|
15
|
+
* retried a few times and then dropped; the decision was already enforced.
|
|
16
|
+
*
|
|
17
|
+
* Must stay in sync with: sdk/python/src/shield360/guard/_report.py
|
|
18
|
+
*/
|
|
19
|
+
import { Finding } from './findings';
|
|
20
|
+
export declare const EVENT_NAME = "shield360.guard.decision";
|
|
21
|
+
/** Starts reporting when both a URL and a key are given. Returns whether it did. */
|
|
22
|
+
export declare function configureGuardReports(opts: {
|
|
23
|
+
url?: string;
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
applicationName: string;
|
|
26
|
+
environment: string;
|
|
27
|
+
sdkVersion?: string;
|
|
28
|
+
}): boolean;
|
|
29
|
+
/** Queues one decision. Allow decisions are not evidence of anything. */
|
|
30
|
+
export declare function reportGuardDecision(guardName: string, action: string, classification: string, phase: string, findings?: Finding[]): void;
|
|
31
|
+
/** Sends everything queued now (tests, and short-lived scripts). */
|
|
32
|
+
export declare function flushGuardReports(): Promise<void>;
|
|
33
|
+
/** Stops reporting; for tests. */
|
|
34
|
+
export declare function resetGuardReports(): Promise<void>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reports guard decisions to Shield360 as compliance evidence.
|
|
4
|
+
*
|
|
5
|
+
* When `init` is given a Shield360 URL and API key (or SHIELD360_URL /
|
|
6
|
+
* SHIELD360_API_KEY), every guard decision other than allow is sent to
|
|
7
|
+
* `/api/guard/events`: which guard, what it did, the kind of data found, in
|
|
8
|
+
* which app, on which host. Never the text that was checked.
|
|
9
|
+
*
|
|
10
|
+
* With each report go the values found, masked, and fingerprinted with the
|
|
11
|
+
* organisation's key (fetched from `/api/guard/config`), so a reviewer can see
|
|
12
|
+
* the same value recurring. The full value is never sent.
|
|
13
|
+
*
|
|
14
|
+
* Reports are queued and sent in batches off the call path, so a guard adds no
|
|
15
|
+
* network time to the call it protects. A batch that cannot be delivered is
|
|
16
|
+
* retried a few times and then dropped; the decision was already enforced.
|
|
17
|
+
*
|
|
18
|
+
* Must stay in sync with: sdk/python/src/shield360/guard/_report.py
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.EVENT_NAME = void 0;
|
|
22
|
+
exports.configureGuardReports = configureGuardReports;
|
|
23
|
+
exports.reportGuardDecision = reportGuardDecision;
|
|
24
|
+
exports.flushGuardReports = flushGuardReports;
|
|
25
|
+
exports.resetGuardReports = resetGuardReports;
|
|
26
|
+
const crypto_1 = require("crypto");
|
|
27
|
+
const os_1 = require("os");
|
|
28
|
+
const findings_1 = require("./findings");
|
|
29
|
+
exports.EVENT_NAME = 'shield360.guard.decision';
|
|
30
|
+
const BATCH = 100;
|
|
31
|
+
const FLUSH_MS = 2000;
|
|
32
|
+
const MAX_QUEUED = 5000;
|
|
33
|
+
const ATTEMPTS = 3;
|
|
34
|
+
class Reporter {
|
|
35
|
+
constructor(endpoint, apiKey, resource, applicationName) {
|
|
36
|
+
this.endpoint = endpoint;
|
|
37
|
+
this.apiKey = apiKey;
|
|
38
|
+
this.resource = resource;
|
|
39
|
+
this.applicationName = applicationName;
|
|
40
|
+
this.queue = [];
|
|
41
|
+
this.sending = Promise.resolve();
|
|
42
|
+
/** Settles once the fingerprint key has been fetched (or could not be). */
|
|
43
|
+
this.keyReady = Promise.resolve();
|
|
44
|
+
this.timer = setInterval(() => void this.flush(), FLUSH_MS);
|
|
45
|
+
// Never keep a process alive just to report.
|
|
46
|
+
this.timer.unref?.();
|
|
47
|
+
}
|
|
48
|
+
add(event) {
|
|
49
|
+
if (this.queue.length >= MAX_QUEUED) {
|
|
50
|
+
console.warn('Shield360 guard report queue is full; a report was dropped');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.queue.push(event);
|
|
54
|
+
}
|
|
55
|
+
/** Sends everything queued; resolves when it has been tried. */
|
|
56
|
+
flush() {
|
|
57
|
+
this.sending = this.sending.then(async () => {
|
|
58
|
+
await this.keyReady;
|
|
59
|
+
while (this.queue.length)
|
|
60
|
+
await this.post(this.queue.splice(0, BATCH).map(serialise));
|
|
61
|
+
});
|
|
62
|
+
return this.sending;
|
|
63
|
+
}
|
|
64
|
+
async post(batch) {
|
|
65
|
+
const body = JSON.stringify({ resource: this.resource, events: batch });
|
|
66
|
+
for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
|
|
67
|
+
try {
|
|
68
|
+
const res = await fetch(this.endpoint, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${this.apiKey}` },
|
|
71
|
+
body,
|
|
72
|
+
});
|
|
73
|
+
if (res.ok)
|
|
74
|
+
return;
|
|
75
|
+
if ([400, 401, 403, 413].includes(res.status)) {
|
|
76
|
+
console.warn(`Shield360 rejected guard reports: HTTP ${res.status}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// retried below
|
|
82
|
+
}
|
|
83
|
+
await new Promise((r) => setTimeout(r, 500 * (attempt + 1)));
|
|
84
|
+
}
|
|
85
|
+
console.warn(`Could not deliver ${batch.length} guard report(s) to Shield360`);
|
|
86
|
+
}
|
|
87
|
+
close() {
|
|
88
|
+
clearInterval(this.timer);
|
|
89
|
+
return this.flush();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Findings go out fingerprinted if the key has arrived since they were made. */
|
|
93
|
+
function serialise(event) {
|
|
94
|
+
const { findings, ...rest } = event;
|
|
95
|
+
if (!findings?.length)
|
|
96
|
+
return rest;
|
|
97
|
+
const done = findings.map(findings_1.completeFinding);
|
|
98
|
+
return {
|
|
99
|
+
...rest,
|
|
100
|
+
attrs: {
|
|
101
|
+
...rest.attrs,
|
|
102
|
+
'shield360.guard.findings': JSON.stringify(done),
|
|
103
|
+
'shield360.guard.fingerprints': done.map((f) => f.fingerprint).filter(Boolean).join(','),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let reporter = null;
|
|
108
|
+
/** Starts reporting when both a URL and a key are given. Returns whether it did. */
|
|
109
|
+
function configureGuardReports(opts) {
|
|
110
|
+
if (!opts.url || !opts.apiKey)
|
|
111
|
+
return false;
|
|
112
|
+
let user = '';
|
|
113
|
+
try {
|
|
114
|
+
user = (0, os_1.userInfo)().username;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// no user in some containers
|
|
118
|
+
}
|
|
119
|
+
const resource = {};
|
|
120
|
+
for (const [k, v] of Object.entries({
|
|
121
|
+
'host.name': (0, os_1.hostname)(),
|
|
122
|
+
'user.name': user,
|
|
123
|
+
'deployment.environment': opts.environment,
|
|
124
|
+
'service.version': opts.sdkVersion || '',
|
|
125
|
+
})) {
|
|
126
|
+
if (v)
|
|
127
|
+
resource[k] = v;
|
|
128
|
+
}
|
|
129
|
+
void reporter?.close();
|
|
130
|
+
const base = opts.url.replace(/\/+$/, '');
|
|
131
|
+
reporter = new Reporter(`${base}/api/guard/events`, opts.apiKey, resource, opts.applicationName);
|
|
132
|
+
reporter.keyReady = fetchFingerprintKey(base, opts.apiKey);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
/** The organisation's fingerprint key; without it findings are masked only. */
|
|
136
|
+
async function fetchFingerprintKey(base, apiKey) {
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch(`${base}/api/guard/config`, { headers: { Authorization: `Bearer ${apiKey}` } });
|
|
139
|
+
if (!res.ok)
|
|
140
|
+
return;
|
|
141
|
+
const body = (await res.json());
|
|
142
|
+
if (typeof body.fingerprintKey === 'string' && body.fingerprintKey)
|
|
143
|
+
(0, findings_1.setFingerprintKey)(body.fingerprintKey);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// masked only
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Queues one decision. Allow decisions are not evidence of anything. */
|
|
150
|
+
function reportGuardDecision(guardName, action, classification, phase, findings = []) {
|
|
151
|
+
if (!reporter || action === 'allow')
|
|
152
|
+
return;
|
|
153
|
+
const kept = findings.slice(0, 10);
|
|
154
|
+
const kinds = (classification || '')
|
|
155
|
+
.split(',')
|
|
156
|
+
.map((k) => k.trim())
|
|
157
|
+
.filter(Boolean)
|
|
158
|
+
.join(',');
|
|
159
|
+
reporter.add({
|
|
160
|
+
name: exports.EVENT_NAME,
|
|
161
|
+
time: new Date().toISOString(),
|
|
162
|
+
attrs: {
|
|
163
|
+
'shield360.guard.event_id': (0, crypto_1.randomUUID)().replace(/-/g, ''),
|
|
164
|
+
'shield360.guard.client': reporter.applicationName,
|
|
165
|
+
'shield360.guard.action': action,
|
|
166
|
+
'shield360.guard.target': phase,
|
|
167
|
+
'shield360.guard.kinds': kinds,
|
|
168
|
+
'shield360.guard.name': guardName,
|
|
169
|
+
},
|
|
170
|
+
findings: kept,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/** Sends everything queued now (tests, and short-lived scripts). */
|
|
174
|
+
function flushGuardReports() {
|
|
175
|
+
return reporter ? reporter.flush() : Promise.resolve();
|
|
176
|
+
}
|
|
177
|
+
/** Stops reporting; for tests. */
|
|
178
|
+
async function resetGuardReports() {
|
|
179
|
+
await reporter?.close();
|
|
180
|
+
reporter = null;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/guard/report.ts"],"names":[],"mappings":";AAAA;;;;;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
*
|
|
4
|
+
* Validates that model output is valid JSON and/or conforms to a JSON schema.
|
|
5
|
+
*
|
|
6
|
+
* Must stay in sync with: sdk/python/src/shield360/guard/schema.py
|
|
7
|
+
*/
|
|
8
|
+
import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
|
|
9
|
+
export interface SchemaOptions extends GuardOptions {
|
|
10
|
+
jsonMode?: boolean;
|
|
11
|
+
schema?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export declare class Schema extends Guard {
|
|
14
|
+
readonly name = "schema";
|
|
15
|
+
readonly phases: GuardPhase[];
|
|
16
|
+
private readonly _jsonMode;
|
|
17
|
+
private readonly _schema;
|
|
18
|
+
constructor(opts?: SchemaOptions);
|
|
19
|
+
evaluate(text: string): GuardResult;
|
|
20
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Schema validation guard for structured LLM outputs.
|
|
4
|
+
*
|
|
5
|
+
* Validates that model output is valid JSON and/or conforms to a JSON schema.
|
|
6
|
+
*
|
|
7
|
+
* Must stay in sync with: sdk/python/src/shield360/guard/schema.py
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Schema = void 0;
|
|
11
|
+
const base_1 = require("./base");
|
|
12
|
+
function validateJsonSchema(data, schema, path = '') {
|
|
13
|
+
const schemaType = schema.type;
|
|
14
|
+
if (schemaType) {
|
|
15
|
+
const typeMap = {
|
|
16
|
+
object: (v) => typeof v === 'object' && v !== null && !Array.isArray(v),
|
|
17
|
+
array: (v) => Array.isArray(v),
|
|
18
|
+
string: (v) => typeof v === 'string',
|
|
19
|
+
number: (v) => typeof v === 'number',
|
|
20
|
+
integer: (v) => typeof v === 'number' && Number.isInteger(v),
|
|
21
|
+
boolean: (v) => typeof v === 'boolean',
|
|
22
|
+
null: (v) => v === null,
|
|
23
|
+
};
|
|
24
|
+
const checker = typeMap[schemaType];
|
|
25
|
+
if (checker && !checker(data)) {
|
|
26
|
+
const actual = data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data;
|
|
27
|
+
return `Expected ${schemaType} at ${path || 'root'}, got ${actual}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (schemaType === 'object' && typeof data === 'object' && data !== null && !Array.isArray(data)) {
|
|
31
|
+
const dataObj = data;
|
|
32
|
+
const required = schema.required || [];
|
|
33
|
+
for (const fieldName of required) {
|
|
34
|
+
if (!(fieldName in dataObj)) {
|
|
35
|
+
return `Missing required field '${fieldName}' at ${path || 'root'}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const properties = schema.properties || {};
|
|
39
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
40
|
+
if (propName in dataObj) {
|
|
41
|
+
const err = validateJsonSchema(dataObj[propName], propSchema, `${path}.${propName}`);
|
|
42
|
+
if (err)
|
|
43
|
+
return err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (schemaType === 'array' && Array.isArray(data)) {
|
|
48
|
+
const itemsSchema = schema.items;
|
|
49
|
+
if (itemsSchema) {
|
|
50
|
+
for (let i = 0; i < data.length; i++) {
|
|
51
|
+
const err = validateJsonSchema(data[i], itemsSchema, `${path}[${i}]`);
|
|
52
|
+
if (err)
|
|
53
|
+
return err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
class Schema extends base_1.Guard {
|
|
60
|
+
constructor(opts = {}) {
|
|
61
|
+
super({ action: opts.action ?? 'deny', maxScanLength: opts.maxScanLength });
|
|
62
|
+
this.name = 'schema';
|
|
63
|
+
this.phases = [base_1.GuardPhase.POSTFLIGHT];
|
|
64
|
+
this._jsonMode = opts.jsonMode ?? false;
|
|
65
|
+
this._schema = opts.schema ?? null;
|
|
66
|
+
}
|
|
67
|
+
evaluate(text) {
|
|
68
|
+
const stripped = text.trim();
|
|
69
|
+
let parsed;
|
|
70
|
+
try {
|
|
71
|
+
parsed = JSON.parse(stripped);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
75
|
+
return (0, base_1.makeGuardResult)({
|
|
76
|
+
action: this._action,
|
|
77
|
+
score: 1.0,
|
|
78
|
+
guardName: this.name,
|
|
79
|
+
classification: 'invalid_json',
|
|
80
|
+
explanation: `Output is not valid JSON: ${message}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (this._schema) {
|
|
84
|
+
const err = validateJsonSchema(parsed, this._schema);
|
|
85
|
+
if (err) {
|
|
86
|
+
return (0, base_1.makeGuardResult)({
|
|
87
|
+
action: this._action,
|
|
88
|
+
score: 0.9,
|
|
89
|
+
guardName: this.name,
|
|
90
|
+
classification: 'schema_mismatch',
|
|
91
|
+
explanation: err,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return (0, base_1.makeGuardResult)({ guardName: this.name });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.Schema = Schema;
|
|
99
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/guard/schema.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAAuF;AAEvF,SAAS,kBAAkB,CACzB,IAAa,EACb,MAA+B,EAC/B,IAAI,GAAG,EAAE;IAET,MAAM,UAAU,GAAG,MAAM,CAAC,IAA0B,CAAC;IACrD,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,OAAO,GAA4C;YACvD,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,KAAK,EAAE,CAAC,CAAC,EAAE,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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sensitive topic detection guard.
|
|
3
|
+
*
|
|
4
|
+
* Uses keyword/regex dictionaries for fast-path detection of sensitive
|
|
5
|
+
* content categories. An optional user-provided classifier handles
|
|
6
|
+
* ambiguous cases.
|
|
7
|
+
*
|
|
8
|
+
* Patterns must stay in sync with: sdk/python/src/shield360/guard/sensitive_topic.py
|
|
9
|
+
*/
|
|
10
|
+
import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
|
|
11
|
+
export interface SensitiveTopicOptions extends GuardOptions {
|
|
12
|
+
categories?: Set<string> | string[];
|
|
13
|
+
customCategories?: Record<string, string[]>;
|
|
14
|
+
classifier?: (text: string) => string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare class SensitiveTopic extends Guard {
|
|
17
|
+
readonly name = "sensitive_topic";
|
|
18
|
+
readonly phases: GuardPhase[];
|
|
19
|
+
private readonly _patterns;
|
|
20
|
+
private readonly _classifier?;
|
|
21
|
+
constructor(opts?: SensitiveTopicOptions);
|
|
22
|
+
evaluate(text: string): GuardResult;
|
|
23
|
+
}
|