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,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const config_1 = __importDefault(require("./config"));
|
|
7
|
+
const constant_1 = require("./constant");
|
|
8
|
+
class PromptHub {
|
|
9
|
+
static async getPrompts(options) {
|
|
10
|
+
const url = process.env.SHIELD360_URL || options.url || constant_1.SHIELD360_URL;
|
|
11
|
+
const apiKey = process.env.SHIELD360_API_KEY || options.apiKey || '';
|
|
12
|
+
let metaProperties = {
|
|
13
|
+
applicationName: config_1.default.applicationName,
|
|
14
|
+
environment: config_1.default.environment,
|
|
15
|
+
};
|
|
16
|
+
if (options.metaProperties &&
|
|
17
|
+
typeof options.metaProperties === 'object' &&
|
|
18
|
+
!Array.isArray(options.metaProperties)) {
|
|
19
|
+
metaProperties = {
|
|
20
|
+
...metaProperties,
|
|
21
|
+
...options.metaProperties,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return await fetch(`${url}/api/prompt/get-compiled`, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
name: options.name,
|
|
29
|
+
version: options.version,
|
|
30
|
+
shouldCompile: !!options.shouldCompile,
|
|
31
|
+
variables: options.variables || {},
|
|
32
|
+
id: options.promptId,
|
|
33
|
+
metaProperties,
|
|
34
|
+
source: 'ts-sdk',
|
|
35
|
+
}),
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: `Bearer ${apiKey}`,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.then(async (response) => {
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
return {
|
|
43
|
+
err: `Shield360 Error : HTTP error! Status: ${response.status}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return response.json();
|
|
47
|
+
})
|
|
48
|
+
.then((resp) => {
|
|
49
|
+
return resp;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
if (e && typeof e.toString === 'function') {
|
|
54
|
+
return {
|
|
55
|
+
err: `Shield360 Error : ${e.toString()}`,
|
|
56
|
+
data: null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
err: `Shield360 Error : ${e}`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.default = PromptHub;
|
|
66
|
+
//# sourceMappingURL=prompt-hub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-hub.js","sourceRoot":"","sources":["../src/prompt-hub.ts"],"names":[],"mappings":";;;;;AAAA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,GAAG,EAAE,yCAAyC,QAAQ,CAAC,MAAM,EAAE;qBAChE,CAAC;gBACJ,CAAC;gBACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC,CAAC;iBACD,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE;gBAClB,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC1C,OAAO;oBACL,GAAG,EAAE,qBAAqB,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACxC,IAAI,EAAE,IAAI;iBACX,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,GAAG,EAAE,qBAAqB,CAAC,EAAE;aAC9B,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA3DD,4BA2DC"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const index_1 = __importDefault(require("./index"));
|
|
7
|
+
const GLOBAL_SENTINEL = '__shield360_register_initialized__';
|
|
8
|
+
const MIN_NODE_MAJOR = 18;
|
|
9
|
+
function parseCSV(value) {
|
|
10
|
+
if (!value)
|
|
11
|
+
return undefined;
|
|
12
|
+
const items = value
|
|
13
|
+
.split(',')
|
|
14
|
+
.map((item) => item.trim())
|
|
15
|
+
.filter(Boolean);
|
|
16
|
+
return items.length > 0 ? items : undefined;
|
|
17
|
+
}
|
|
18
|
+
function parseResourceAttributes(value) {
|
|
19
|
+
if (!value)
|
|
20
|
+
return null;
|
|
21
|
+
const attrs = {};
|
|
22
|
+
for (const item of value.split(',')) {
|
|
23
|
+
const [rawKey, ...rawValue] = item.split('=');
|
|
24
|
+
const key = rawKey?.trim();
|
|
25
|
+
const attrValue = rawValue.join('=').trim();
|
|
26
|
+
if (key && attrValue)
|
|
27
|
+
attrs[key] = attrValue;
|
|
28
|
+
}
|
|
29
|
+
return Object.keys(attrs).length > 0 ? attrs : null;
|
|
30
|
+
}
|
|
31
|
+
function nodeVersionSupported() {
|
|
32
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
33
|
+
return Number.isFinite(major) && major >= MIN_NODE_MAJOR;
|
|
34
|
+
}
|
|
35
|
+
function initFromEnv() {
|
|
36
|
+
if (globalThis[GLOBAL_SENTINEL])
|
|
37
|
+
return;
|
|
38
|
+
globalThis[GLOBAL_SENTINEL] = true;
|
|
39
|
+
if (!nodeVersionSupported()) {
|
|
40
|
+
console.error(`Shield360 auto-instrumentation requires Node.js ${MIN_NODE_MAJOR} or newer; current runtime is ${process.version}.`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const options = {
|
|
44
|
+
applicationName: process.env.OTEL_SERVICE_NAME,
|
|
45
|
+
environment: process.env.OTEL_DEPLOYMENT_ENVIRONMENT,
|
|
46
|
+
disabledInstrumentors: parseCSV(process.env.SHIELD360_DISABLED_INSTRUMENTORS),
|
|
47
|
+
customSpanAttributes: parseResourceAttributes(process.env.OTEL_RESOURCE_ATTRIBUTES),
|
|
48
|
+
};
|
|
49
|
+
index_1.default.init(options);
|
|
50
|
+
}
|
|
51
|
+
initFromEnv();
|
|
52
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;;;AAAA,oDAAgC;AAGhC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAC7D,MAAM,cAAc,GAAG,EAAE,CAAC;AAO1B,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,KAAK,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,OAAO;IAChD,UAAkB,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;IAE5C,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CACX,mDAAmD,cAAc,iCAAiC,OAAO,CAAC,OAAO,GAAG,CACrH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAqB;QAChC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;QAC9C,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B;QACpD,qBAAqB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;QAC7E,oBAAoB,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;KACpF,CAAC;IAEF,eAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const config_1 = __importDefault(require("../../config"));
|
|
8
|
+
const events_1 = __importDefault(require("../../otel/events"));
|
|
9
|
+
const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
|
|
10
|
+
const score_1 = require("../score");
|
|
11
|
+
function createMockSpan(isRecording = true) {
|
|
12
|
+
return {
|
|
13
|
+
isRecording: jest.fn().mockReturnValue(isRecording),
|
|
14
|
+
addEvent: jest.fn(),
|
|
15
|
+
spanContext: jest.fn().mockReturnValue({
|
|
16
|
+
traceId: '0123456789abcdef0123456789abcdef',
|
|
17
|
+
spanId: '0123456789abcdef',
|
|
18
|
+
traceFlags: 1,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.restoreAllMocks();
|
|
24
|
+
config_1.default.disableEvents = undefined;
|
|
25
|
+
events_1.default.logger = undefined;
|
|
26
|
+
});
|
|
27
|
+
describe('logScore', () => {
|
|
28
|
+
test('adds numeric score to explicit span', () => {
|
|
29
|
+
const span = createMockSpan();
|
|
30
|
+
const emitted = (0, score_1.logScore)({ name: 'quality', value: 0.85, span: span });
|
|
31
|
+
expect(emitted).toBe(true);
|
|
32
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, {
|
|
33
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: 'quality',
|
|
34
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: 0.85,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
test('maps true boolean score', () => {
|
|
38
|
+
const span = createMockSpan();
|
|
39
|
+
(0, score_1.logScore)({ name: 'user_feedback', value: true, span: span });
|
|
40
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, {
|
|
41
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: 'user_feedback',
|
|
42
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: 1.0,
|
|
43
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_LABEL]: 'true',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
test('maps false boolean score', () => {
|
|
47
|
+
const span = createMockSpan();
|
|
48
|
+
(0, score_1.logScore)({ name: 'user_feedback', value: false, span: span });
|
|
49
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, {
|
|
50
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: 'user_feedback',
|
|
51
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: 0.0,
|
|
52
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_LABEL]: 'false',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
test('maps categorical score', () => {
|
|
56
|
+
const span = createMockSpan();
|
|
57
|
+
(0, score_1.logScore)({ name: 'category', value: 'accurate', span: span });
|
|
58
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, {
|
|
59
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: 'category',
|
|
60
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_LABEL]: 'accurate',
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
test('auto-attaches to active span', () => {
|
|
64
|
+
const span = createMockSpan();
|
|
65
|
+
jest.spyOn(api_1.trace, 'getActiveSpan').mockReturnValue(span);
|
|
66
|
+
const emitted = (0, score_1.logScore)({ name: 'quality', value: 0.5 });
|
|
67
|
+
expect(emitted).toBe(true);
|
|
68
|
+
expect(span.addEvent).toHaveBeenCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
test('targets span from trace and span ids via log event', () => {
|
|
71
|
+
config_1.default.disableEvents = false;
|
|
72
|
+
events_1.default.logger = { emit: jest.fn() };
|
|
73
|
+
jest.spyOn(api_1.trace, 'getActiveSpan').mockReturnValue(createMockSpan(false));
|
|
74
|
+
const emitted = (0, score_1.logScore)({
|
|
75
|
+
name: 'user_feedback',
|
|
76
|
+
value: false,
|
|
77
|
+
traceId: '0123456789abcdef0123456789abcdef',
|
|
78
|
+
spanId: '0123456789abcdef',
|
|
79
|
+
});
|
|
80
|
+
expect(emitted).toBe(true);
|
|
81
|
+
expect(events_1.default.logger.emit).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
83
|
+
test('returns false for invalid trace and span ids', () => {
|
|
84
|
+
config_1.default.disableEvents = true;
|
|
85
|
+
jest.spyOn(api_1.trace, 'getActiveSpan').mockReturnValue(createMockSpan(false));
|
|
86
|
+
const emitted = (0, score_1.logScore)({
|
|
87
|
+
name: 'quality',
|
|
88
|
+
value: 0.5,
|
|
89
|
+
traceId: 'not-a-valid-trace-id',
|
|
90
|
+
spanId: 'bad',
|
|
91
|
+
});
|
|
92
|
+
expect(emitted).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
test('returns false without target span when events disabled', () => {
|
|
95
|
+
config_1.default.disableEvents = true;
|
|
96
|
+
jest.spyOn(api_1.trace, 'getActiveSpan').mockReturnValue(createMockSpan(false));
|
|
97
|
+
const emitted = (0, score_1.logScore)({ name: 'quality', value: 0.5 });
|
|
98
|
+
expect(emitted).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
test('requires name', () => {
|
|
101
|
+
expect(() => (0, score_1.logScore)({ name: '', value: 0.5 })).toThrow('name is required');
|
|
102
|
+
});
|
|
103
|
+
test('includes comment metadata and idempotency key', () => {
|
|
104
|
+
const span = createMockSpan();
|
|
105
|
+
(0, score_1.logScore)({
|
|
106
|
+
name: 'quality',
|
|
107
|
+
value: 0.9,
|
|
108
|
+
span: span,
|
|
109
|
+
comment: 'Looks good',
|
|
110
|
+
idempotencyKey: 'score-123',
|
|
111
|
+
metadata: { reviewer: 'human' },
|
|
112
|
+
});
|
|
113
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, {
|
|
114
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: 'quality',
|
|
115
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: 0.9,
|
|
116
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_EXPLANATION]: 'Looks good',
|
|
117
|
+
[semantic_convention_1.default.SHIELD360_SCORE_IDEMPOTENCY_KEY]: 'score-123',
|
|
118
|
+
reviewer: 'human',
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
test('includes array metadata values', () => {
|
|
122
|
+
const span = createMockSpan();
|
|
123
|
+
(0, score_1.logScore)({
|
|
124
|
+
name: 'quality',
|
|
125
|
+
value: 0.9,
|
|
126
|
+
span: span,
|
|
127
|
+
metadata: { tags: ['human', 'reviewed'] },
|
|
128
|
+
});
|
|
129
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, expect.objectContaining({
|
|
130
|
+
tags: ['human', 'reviewed'],
|
|
131
|
+
}));
|
|
132
|
+
});
|
|
133
|
+
test('includes custom span attributes', () => {
|
|
134
|
+
const span = createMockSpan();
|
|
135
|
+
const helpers = require('../../helpers');
|
|
136
|
+
jest.spyOn(helpers, 'getMergedCustomAttributes').mockReturnValue({ 'session.id': 'sess-1' });
|
|
137
|
+
(0, score_1.logScore)({ name: 'quality', value: 0.5, span: span });
|
|
138
|
+
expect(span.addEvent).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, expect.objectContaining({
|
|
139
|
+
'session.id': 'sess-1',
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=score.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.test.js","sourceRoot":"","sources":["../../../src/score/__tests__/score.test.ts"],"names":[],"mappings":";;;;;AAAA,4CAA2C;AAC3C,0DAA2C;AAC3C,+DAAuC;AACvC,oFAA2D;AAC3D,oCAAoC;AAEpC,SAAS,cAAc,CAAC,WAAW,GAAG,IAAI;IACxC,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,WAAW,CAAC;QACnD,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACnB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;YACrC,OAAO,EAAE,kCAAkC;YAC3C,MAAM,EAAE,kBAAkB;YAC1B,UAAU,EAAE,CAAC;SACd,CAAC;KACH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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logScore = void 0;
|
|
4
|
+
var score_1 = require("./score");
|
|
5
|
+
Object.defineProperty(exports, "logScore", { enumerable: true, get: function () { return score_1.logScore; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/score/index.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AAA1B,iGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Span } from '@opentelemetry/api';
|
|
2
|
+
type OtelSafeMetadataValue = string | number | boolean;
|
|
3
|
+
type OtelSafeMetadataArray = OtelSafeMetadataValue[];
|
|
4
|
+
export interface LogScoreOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
value: number | boolean | string;
|
|
7
|
+
span?: Span;
|
|
8
|
+
traceId?: string;
|
|
9
|
+
spanId?: string;
|
|
10
|
+
comment?: string;
|
|
11
|
+
idempotencyKey?: string;
|
|
12
|
+
metadata?: Record<string, OtelSafeMetadataValue | OtelSafeMetadataArray>;
|
|
13
|
+
}
|
|
14
|
+
export declare function logScore(options: LogScoreOptions): boolean;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logScore = logScore;
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
|
+
const api_logs_1 = require("@opentelemetry/api-logs");
|
|
9
|
+
const config_1 = __importDefault(require("../config"));
|
|
10
|
+
const helpers_1 = require("../helpers");
|
|
11
|
+
const events_1 = __importDefault(require("../otel/events"));
|
|
12
|
+
const semantic_convention_1 = __importDefault(require("../semantic-convention"));
|
|
13
|
+
function normalizeScoreValue(value) {
|
|
14
|
+
if (typeof value === 'boolean') {
|
|
15
|
+
return {
|
|
16
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: value ? 1.0 : 0.0,
|
|
17
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_LABEL]: value ? 'true' : 'false',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === 'number') {
|
|
21
|
+
return { [semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_VALUE]: value };
|
|
22
|
+
}
|
|
23
|
+
return { [semantic_convention_1.default.GEN_AI_EVALUATION_SCORE_LABEL]: value };
|
|
24
|
+
}
|
|
25
|
+
function eventsDisabled() {
|
|
26
|
+
return Boolean(config_1.default.disableEvents);
|
|
27
|
+
}
|
|
28
|
+
function isOtelSafeMetadataValue(value) {
|
|
29
|
+
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
|
|
30
|
+
}
|
|
31
|
+
function mergeMetadata(eventAttributes, metadata) {
|
|
32
|
+
if (!metadata) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
36
|
+
if (value === undefined || value === null) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (isOtelSafeMetadataValue(value)) {
|
|
40
|
+
eventAttributes[key] = value;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(value) && value.every(isOtelSafeMetadataValue)) {
|
|
44
|
+
eventAttributes[key] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function mergeCustomEventAttributes(eventAttributes) {
|
|
49
|
+
const customAttrs = (0, helpers_1.getMergedCustomAttributes)();
|
|
50
|
+
for (const [key, value] of Object.entries(customAttrs)) {
|
|
51
|
+
if (value !== undefined && value !== null) {
|
|
52
|
+
if (!(key in eventAttributes)) {
|
|
53
|
+
eventAttributes[key] = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const HEX_RE = /^[0-9a-fA-F]+$/;
|
|
59
|
+
function validHexId(value, expectedLen) {
|
|
60
|
+
return value.length === expectedLen && HEX_RE.test(value);
|
|
61
|
+
}
|
|
62
|
+
function spanFromIds(traceId, spanId) {
|
|
63
|
+
if (!validHexId(traceId, 32) || !validHexId(spanId, 16)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const spanContext = {
|
|
67
|
+
traceId,
|
|
68
|
+
spanId,
|
|
69
|
+
traceFlags: api_1.TraceFlags.SAMPLED,
|
|
70
|
+
isRemote: true,
|
|
71
|
+
};
|
|
72
|
+
return api_1.trace.wrapSpanContext(spanContext);
|
|
73
|
+
}
|
|
74
|
+
function resolveTargetSpan(options) {
|
|
75
|
+
if (options.span) {
|
|
76
|
+
return options.span;
|
|
77
|
+
}
|
|
78
|
+
const activeSpan = api_1.trace.getActiveSpan();
|
|
79
|
+
if (activeSpan?.isRecording()) {
|
|
80
|
+
return activeSpan;
|
|
81
|
+
}
|
|
82
|
+
if (options.traceId && options.spanId) {
|
|
83
|
+
return spanFromIds(options.traceId, options.spanId);
|
|
84
|
+
}
|
|
85
|
+
return activeSpan ?? undefined;
|
|
86
|
+
}
|
|
87
|
+
function emitScoreLogEvent(eventAttributes, targetSpan) {
|
|
88
|
+
if (eventsDisabled() || !events_1.default.logger) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
events_1.default.logger.emit({
|
|
92
|
+
eventName: semantic_convention_1.default.GEN_AI_EVALUATION_RESULT,
|
|
93
|
+
context: api_1.trace.setSpan(api_1.context.active(), targetSpan),
|
|
94
|
+
severityNumber: api_logs_1.SeverityNumber.INFO,
|
|
95
|
+
severityText: 'INFO',
|
|
96
|
+
body: semantic_convention_1.default.GEN_AI_EVALUATION_RESULT,
|
|
97
|
+
attributes: {
|
|
98
|
+
...eventAttributes,
|
|
99
|
+
'event.name': semantic_convention_1.default.GEN_AI_EVALUATION_RESULT,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
function logScore(options) {
|
|
105
|
+
const { name, value, comment, idempotencyKey, metadata } = options;
|
|
106
|
+
if (!name) {
|
|
107
|
+
throw new Error('name is required');
|
|
108
|
+
}
|
|
109
|
+
const targetSpan = resolveTargetSpan(options);
|
|
110
|
+
if (!targetSpan) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const eventAttributes = {
|
|
114
|
+
[semantic_convention_1.default.GEN_AI_EVALUATION_NAME]: name,
|
|
115
|
+
...normalizeScoreValue(value),
|
|
116
|
+
};
|
|
117
|
+
if (comment) {
|
|
118
|
+
eventAttributes[semantic_convention_1.default.GEN_AI_EVALUATION_EXPLANATION] = comment;
|
|
119
|
+
}
|
|
120
|
+
if (idempotencyKey) {
|
|
121
|
+
eventAttributes[semantic_convention_1.default.SHIELD360_SCORE_IDEMPOTENCY_KEY] = idempotencyKey;
|
|
122
|
+
}
|
|
123
|
+
mergeMetadata(eventAttributes, metadata);
|
|
124
|
+
mergeCustomEventAttributes(eventAttributes);
|
|
125
|
+
let emitted = false;
|
|
126
|
+
if (targetSpan.isRecording()) {
|
|
127
|
+
targetSpan.addEvent(semantic_convention_1.default.GEN_AI_EVALUATION_RESULT, eventAttributes);
|
|
128
|
+
emitted = true;
|
|
129
|
+
}
|
|
130
|
+
if (emitScoreLogEvent(eventAttributes, targetSpan)) {
|
|
131
|
+
emitted = true;
|
|
132
|
+
}
|
|
133
|
+
return emitted;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../src/score/score.ts"],"names":[],"mappings":";;;;;AA+HA,4BAmCC;AAlKD,4CAA8H;AAC9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