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,629 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const api_1 = require("@opentelemetry/api");
|
|
40
|
+
const config_1 = __importDefault(require("../../config"));
|
|
41
|
+
const helpers_1 = __importStar(require("../../helpers"));
|
|
42
|
+
const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
|
|
43
|
+
const base_wrapper_1 = __importDefault(require("../base-wrapper"));
|
|
44
|
+
function spanCreationAttrs(operationName, requestModel) {
|
|
45
|
+
return {
|
|
46
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationName,
|
|
47
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: OllamaWrapper.aiSystem,
|
|
48
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
49
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: OllamaWrapper.serverAddress,
|
|
50
|
+
[semantic_convention_1.default.SERVER_PORT]: OllamaWrapper.serverPort,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
class OllamaWrapper extends base_wrapper_1.default {
|
|
54
|
+
/**
|
|
55
|
+
* Stamp `shield360.agent.version_hash` (auto) and `gen_ai.agent.version`
|
|
56
|
+
* (user override, if set) on the span and return the same attributes so
|
|
57
|
+
* the caller can merge them into the inference event extras.
|
|
58
|
+
*/
|
|
59
|
+
static _stampAgentVersion(span, args) {
|
|
60
|
+
const out = {};
|
|
61
|
+
try {
|
|
62
|
+
const versionHash = helpers_1.default.computeAgentVersionHash({
|
|
63
|
+
systemInstructions: args.systemInstructionsJson ?? null,
|
|
64
|
+
toolDefinitions: args.toolDefinitionsJson ?? null,
|
|
65
|
+
primaryModel: args.primaryModel ?? null,
|
|
66
|
+
runtimeConfig: {
|
|
67
|
+
temperature: args.temperature ?? null,
|
|
68
|
+
top_p: args.top_p ?? null,
|
|
69
|
+
max_tokens: args.max_tokens ?? null,
|
|
70
|
+
provider: semantic_convention_1.default.GEN_AI_SYSTEM_OLLAMA,
|
|
71
|
+
},
|
|
72
|
+
providers: [semantic_convention_1.default.GEN_AI_SYSTEM_OLLAMA],
|
|
73
|
+
});
|
|
74
|
+
if (versionHash) {
|
|
75
|
+
out[semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH] = versionHash;
|
|
76
|
+
span.setAttribute(semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH, versionHash);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Hash computation must never fail the wrapped call.
|
|
81
|
+
}
|
|
82
|
+
const versionLabel = (0, helpers_1.getCurrentAgentVersion)();
|
|
83
|
+
if (versionLabel) {
|
|
84
|
+
out[semantic_convention_1.default.GEN_AI_AGENT_VERSION] = versionLabel;
|
|
85
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_VERSION, versionLabel);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
// ──────────────────── Chat ────────────────────
|
|
90
|
+
static _patchChat(tracer) {
|
|
91
|
+
const genAIEndpoint = 'ollama.chat';
|
|
92
|
+
return (originalMethod) => {
|
|
93
|
+
return async function (...args) {
|
|
94
|
+
if ((0, helpers_1.isFrameworkLlmActive)())
|
|
95
|
+
return originalMethod.apply(this, args);
|
|
96
|
+
const requestModel = args[0]?.model || 'llama3';
|
|
97
|
+
const spanName = `${semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT} ${requestModel}`;
|
|
98
|
+
const effectiveCtx = (0, helpers_1.getFrameworkParentContext)() ?? api_1.context.active();
|
|
99
|
+
const span = tracer.startSpan(spanName, {
|
|
100
|
+
kind: api_1.SpanKind.CLIENT,
|
|
101
|
+
attributes: spanCreationAttrs(semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT, requestModel),
|
|
102
|
+
}, effectiveCtx);
|
|
103
|
+
return api_1.context
|
|
104
|
+
.with(api_1.trace.setSpan(effectiveCtx, span), async () => {
|
|
105
|
+
return originalMethod.apply(this, args);
|
|
106
|
+
})
|
|
107
|
+
.then((response) => {
|
|
108
|
+
const { stream = false } = args[0];
|
|
109
|
+
if (stream) {
|
|
110
|
+
return helpers_1.default.createStreamProxy(response, OllamaWrapper._chatGenerator({ args, genAIEndpoint, response, span }));
|
|
111
|
+
}
|
|
112
|
+
return OllamaWrapper._chat({ args, genAIEndpoint, response, span });
|
|
113
|
+
})
|
|
114
|
+
.catch((e) => {
|
|
115
|
+
helpers_1.default.handleException(span, e);
|
|
116
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
117
|
+
genAIEndpoint,
|
|
118
|
+
model: requestModel,
|
|
119
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
120
|
+
serverAddress: OllamaWrapper.serverAddress,
|
|
121
|
+
serverPort: OllamaWrapper.serverPort,
|
|
122
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
123
|
+
});
|
|
124
|
+
span.end();
|
|
125
|
+
throw e;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
static async _chat({ args, genAIEndpoint, response, span, }) {
|
|
131
|
+
let metricParams;
|
|
132
|
+
try {
|
|
133
|
+
metricParams = await OllamaWrapper._chatCommonSetter({
|
|
134
|
+
args,
|
|
135
|
+
genAIEndpoint,
|
|
136
|
+
result: response,
|
|
137
|
+
span,
|
|
138
|
+
});
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
helpers_1.default.handleException(span, e);
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
span.end();
|
|
147
|
+
if (metricParams) {
|
|
148
|
+
base_wrapper_1.default.recordMetrics(span, metricParams);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
static async *_chatGenerator({ args, genAIEndpoint, response, span, }) {
|
|
153
|
+
let metricParams;
|
|
154
|
+
const timestamps = [];
|
|
155
|
+
const startTime = Date.now();
|
|
156
|
+
try {
|
|
157
|
+
const result = {
|
|
158
|
+
model: '',
|
|
159
|
+
message: { role: 'assistant', content: '' },
|
|
160
|
+
done_reason: '',
|
|
161
|
+
prompt_eval_count: 0,
|
|
162
|
+
eval_count: 0,
|
|
163
|
+
};
|
|
164
|
+
let toolCalls = [];
|
|
165
|
+
for await (const chunk of response) {
|
|
166
|
+
timestamps.push(Date.now());
|
|
167
|
+
result.model = chunk.model || result.model;
|
|
168
|
+
if (chunk.message?.content) {
|
|
169
|
+
result.message.content += chunk.message.content;
|
|
170
|
+
result.message.role = chunk.message.role || result.message.role;
|
|
171
|
+
}
|
|
172
|
+
if (chunk.message?.tool_calls) {
|
|
173
|
+
toolCalls = chunk.message.tool_calls;
|
|
174
|
+
}
|
|
175
|
+
if (chunk.done) {
|
|
176
|
+
result.done_reason = chunk.done_reason || '';
|
|
177
|
+
result.prompt_eval_count = chunk.prompt_eval_count || 0;
|
|
178
|
+
result.eval_count = chunk.eval_count || 0;
|
|
179
|
+
}
|
|
180
|
+
yield chunk;
|
|
181
|
+
}
|
|
182
|
+
if (toolCalls.length > 0) {
|
|
183
|
+
result.message.tool_calls = toolCalls;
|
|
184
|
+
}
|
|
185
|
+
const ttft = timestamps.length > 0 ? (timestamps[0] - startTime) / 1000 : 0;
|
|
186
|
+
let tbt = 0;
|
|
187
|
+
if (timestamps.length > 1) {
|
|
188
|
+
const timeDiffs = timestamps.slice(1).map((t, i) => t - timestamps[i]);
|
|
189
|
+
tbt = timeDiffs.reduce((a, b) => a + b, 0) / timeDiffs.length / 1000;
|
|
190
|
+
}
|
|
191
|
+
metricParams = await OllamaWrapper._chatCommonSetter({
|
|
192
|
+
args,
|
|
193
|
+
genAIEndpoint,
|
|
194
|
+
result,
|
|
195
|
+
span,
|
|
196
|
+
ttft,
|
|
197
|
+
tbt,
|
|
198
|
+
});
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
helpers_1.default.handleException(span, e);
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
span.end();
|
|
207
|
+
if (metricParams) {
|
|
208
|
+
base_wrapper_1.default.recordMetrics(span, metricParams);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
static async _chatCommonSetter({ args, genAIEndpoint, result, span, ttft = 0, tbt = 0, }) {
|
|
213
|
+
const captureContent = config_1.default.captureMessageContent;
|
|
214
|
+
const requestModel = args[0]?.model || 'llama3';
|
|
215
|
+
const { messages, stream = false, tools: _tools } = args[0];
|
|
216
|
+
const options = args[0]?.options || {};
|
|
217
|
+
if (options.temperature != null) {
|
|
218
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TEMPERATURE, options.temperature);
|
|
219
|
+
}
|
|
220
|
+
if (options.top_p != null) {
|
|
221
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_P, options.top_p);
|
|
222
|
+
}
|
|
223
|
+
if (options.top_k != null) {
|
|
224
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_K, options.top_k);
|
|
225
|
+
}
|
|
226
|
+
if (options.max_tokens != null) {
|
|
227
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, options.max_tokens);
|
|
228
|
+
}
|
|
229
|
+
if (options.repeat_penalty) {
|
|
230
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY, options.repeat_penalty);
|
|
231
|
+
}
|
|
232
|
+
if (options.seed != null) {
|
|
233
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_SEED, Number(options.seed));
|
|
234
|
+
}
|
|
235
|
+
if (options.stop) {
|
|
236
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES, Array.isArray(options.stop) ? options.stop : [options.stop]);
|
|
237
|
+
}
|
|
238
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, stream);
|
|
239
|
+
if (captureContent) {
|
|
240
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages(messages || []));
|
|
241
|
+
}
|
|
242
|
+
const responseModel = result.model || requestModel;
|
|
243
|
+
const pricingInfo = config_1.default.pricingInfo || {};
|
|
244
|
+
const inputTokens = result.prompt_eval_count || 0;
|
|
245
|
+
const outputTokens = result.eval_count || 0;
|
|
246
|
+
const cost = helpers_1.default.getChatModelCost(requestModel, pricingInfo, inputTokens, outputTokens);
|
|
247
|
+
OllamaWrapper.setBaseSpanAttributes(span, {
|
|
248
|
+
genAIEndpoint,
|
|
249
|
+
model: requestModel,
|
|
250
|
+
cost,
|
|
251
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
252
|
+
serverAddress: OllamaWrapper.serverAddress,
|
|
253
|
+
serverPort: OllamaWrapper.serverPort,
|
|
254
|
+
});
|
|
255
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, responseModel);
|
|
256
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
257
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
258
|
+
if (ttft > 0) {
|
|
259
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TTFT, ttft);
|
|
260
|
+
}
|
|
261
|
+
if (tbt > 0) {
|
|
262
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TBT, tbt);
|
|
263
|
+
}
|
|
264
|
+
if (result.done_reason) {
|
|
265
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, [result.done_reason]);
|
|
266
|
+
}
|
|
267
|
+
const outputType = typeof result.message?.content === 'string'
|
|
268
|
+
? semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT
|
|
269
|
+
: semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_JSON;
|
|
270
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, outputType);
|
|
271
|
+
if (result.message?.tool_calls) {
|
|
272
|
+
const resultToolCalls = result.message.tool_calls;
|
|
273
|
+
const toolNames = resultToolCalls.map((t) => t.function?.name || '').filter(Boolean);
|
|
274
|
+
const toolIds = resultToolCalls.map((t) => String(t.id || '')).filter(Boolean);
|
|
275
|
+
const toolArgs = resultToolCalls
|
|
276
|
+
.map((t) => String(t.function?.arguments || ''))
|
|
277
|
+
.filter(Boolean);
|
|
278
|
+
if (toolNames.length > 0) {
|
|
279
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_NAME, toolNames.join(', '));
|
|
280
|
+
}
|
|
281
|
+
if (toolIds.length > 0) {
|
|
282
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, toolIds.join(', '));
|
|
283
|
+
}
|
|
284
|
+
if (toolArgs.length > 0) {
|
|
285
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_ARGS, toolArgs.join(', '));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let inputMessagesJson;
|
|
289
|
+
let outputMessagesJson;
|
|
290
|
+
const toolDefinitionsJson = helpers_1.default.buildToolDefinitions(_tools);
|
|
291
|
+
// Compute system_instructions and version hash regardless of
|
|
292
|
+
// captureContent so versions still group correctly when content
|
|
293
|
+
// capture is disabled.
|
|
294
|
+
const systemInstructionsJson = helpers_1.default.buildSystemInstructionsFromMessages(messages || []);
|
|
295
|
+
const versionExtras = OllamaWrapper._stampAgentVersion(span, {
|
|
296
|
+
systemInstructionsJson,
|
|
297
|
+
toolDefinitionsJson,
|
|
298
|
+
primaryModel: responseModel || requestModel,
|
|
299
|
+
temperature: options.temperature ?? null,
|
|
300
|
+
top_p: options.top_p ?? null,
|
|
301
|
+
max_tokens: options.max_tokens ?? null,
|
|
302
|
+
});
|
|
303
|
+
if (captureContent) {
|
|
304
|
+
const toolCalls = result.message?.tool_calls;
|
|
305
|
+
outputMessagesJson = helpers_1.default.buildOutputMessages(result.message?.content || '', result.done_reason || 'stop', toolCalls);
|
|
306
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, outputMessagesJson);
|
|
307
|
+
inputMessagesJson = helpers_1.default.buildInputMessages(messages || []);
|
|
308
|
+
if (systemInstructionsJson) {
|
|
309
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, systemInstructionsJson);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (toolDefinitionsJson) {
|
|
313
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, toolDefinitionsJson);
|
|
314
|
+
}
|
|
315
|
+
if (!config_1.default.disableEvents) {
|
|
316
|
+
const eventAttrs = {
|
|
317
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
318
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
319
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: responseModel,
|
|
320
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: OllamaWrapper.serverAddress,
|
|
321
|
+
[semantic_convention_1.default.SERVER_PORT]: OllamaWrapper.serverPort,
|
|
322
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: [result.done_reason || 'stop'],
|
|
323
|
+
[semantic_convention_1.default.GEN_AI_OUTPUT_TYPE]: outputType,
|
|
324
|
+
[semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: inputTokens,
|
|
325
|
+
[semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: outputTokens,
|
|
326
|
+
...versionExtras,
|
|
327
|
+
};
|
|
328
|
+
if (captureContent) {
|
|
329
|
+
if (inputMessagesJson)
|
|
330
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES] = inputMessagesJson;
|
|
331
|
+
if (outputMessagesJson)
|
|
332
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES] = outputMessagesJson;
|
|
333
|
+
if (systemInstructionsJson)
|
|
334
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS] = systemInstructionsJson;
|
|
335
|
+
}
|
|
336
|
+
if (toolDefinitionsJson)
|
|
337
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS] = toolDefinitionsJson;
|
|
338
|
+
helpers_1.default.emitInferenceEvent(span, eventAttrs);
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
genAIEndpoint,
|
|
342
|
+
model: requestModel,
|
|
343
|
+
cost,
|
|
344
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
// ──────────────────── Generate (text_completion) ────────────────────
|
|
348
|
+
static _patchGenerate(tracer) {
|
|
349
|
+
const genAIEndpoint = 'ollama.generate';
|
|
350
|
+
return (originalMethod) => {
|
|
351
|
+
return async function (...args) {
|
|
352
|
+
if ((0, helpers_1.isFrameworkLlmActive)())
|
|
353
|
+
return originalMethod.apply(this, args);
|
|
354
|
+
const requestModel = args[0]?.model || 'llama3';
|
|
355
|
+
const spanName = `${semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TEXT_COMPLETION} ${requestModel}`;
|
|
356
|
+
const effectiveCtx = (0, helpers_1.getFrameworkParentContext)() ?? api_1.context.active();
|
|
357
|
+
const span = tracer.startSpan(spanName, {
|
|
358
|
+
kind: api_1.SpanKind.CLIENT,
|
|
359
|
+
attributes: spanCreationAttrs(semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TEXT_COMPLETION, requestModel),
|
|
360
|
+
}, effectiveCtx);
|
|
361
|
+
return api_1.context
|
|
362
|
+
.with(api_1.trace.setSpan(effectiveCtx, span), async () => {
|
|
363
|
+
return originalMethod.apply(this, args);
|
|
364
|
+
})
|
|
365
|
+
.then((response) => {
|
|
366
|
+
const { stream = false } = args[0];
|
|
367
|
+
if (stream) {
|
|
368
|
+
return helpers_1.default.createStreamProxy(response, OllamaWrapper._generateGenerator({ args, genAIEndpoint, response, span }));
|
|
369
|
+
}
|
|
370
|
+
return OllamaWrapper._generate({ args, genAIEndpoint, response, span });
|
|
371
|
+
})
|
|
372
|
+
.catch((e) => {
|
|
373
|
+
helpers_1.default.handleException(span, e);
|
|
374
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
375
|
+
genAIEndpoint,
|
|
376
|
+
model: requestModel,
|
|
377
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
378
|
+
serverAddress: OllamaWrapper.serverAddress,
|
|
379
|
+
serverPort: OllamaWrapper.serverPort,
|
|
380
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
381
|
+
});
|
|
382
|
+
span.end();
|
|
383
|
+
throw e;
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
static async _generate({ args, genAIEndpoint, response, span, }) {
|
|
389
|
+
let metricParams;
|
|
390
|
+
try {
|
|
391
|
+
metricParams = await OllamaWrapper._generateCommonSetter({
|
|
392
|
+
args,
|
|
393
|
+
genAIEndpoint,
|
|
394
|
+
result: response,
|
|
395
|
+
span,
|
|
396
|
+
});
|
|
397
|
+
return response;
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
helpers_1.default.handleException(span, e);
|
|
401
|
+
throw e;
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
span.end();
|
|
405
|
+
if (metricParams) {
|
|
406
|
+
base_wrapper_1.default.recordMetrics(span, metricParams);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
static async *_generateGenerator({ args, genAIEndpoint, response, span, }) {
|
|
411
|
+
let metricParams;
|
|
412
|
+
const timestamps = [];
|
|
413
|
+
const startTime = Date.now();
|
|
414
|
+
try {
|
|
415
|
+
const result = {
|
|
416
|
+
model: '',
|
|
417
|
+
response: '',
|
|
418
|
+
done_reason: '',
|
|
419
|
+
prompt_eval_count: 0,
|
|
420
|
+
eval_count: 0,
|
|
421
|
+
};
|
|
422
|
+
for await (const chunk of response) {
|
|
423
|
+
timestamps.push(Date.now());
|
|
424
|
+
result.model = chunk.model || result.model;
|
|
425
|
+
if (chunk.response) {
|
|
426
|
+
result.response += chunk.response;
|
|
427
|
+
}
|
|
428
|
+
if (chunk.done) {
|
|
429
|
+
result.done_reason = chunk.done_reason || '';
|
|
430
|
+
result.prompt_eval_count = chunk.prompt_eval_count || 0;
|
|
431
|
+
result.eval_count = chunk.eval_count || 0;
|
|
432
|
+
}
|
|
433
|
+
yield chunk;
|
|
434
|
+
}
|
|
435
|
+
const ttft = timestamps.length > 0 ? (timestamps[0] - startTime) / 1000 : 0;
|
|
436
|
+
let tbt = 0;
|
|
437
|
+
if (timestamps.length > 1) {
|
|
438
|
+
const timeDiffs = timestamps.slice(1).map((t, i) => t - timestamps[i]);
|
|
439
|
+
tbt = timeDiffs.reduce((a, b) => a + b, 0) / timeDiffs.length / 1000;
|
|
440
|
+
}
|
|
441
|
+
metricParams = await OllamaWrapper._generateCommonSetter({
|
|
442
|
+
args,
|
|
443
|
+
genAIEndpoint,
|
|
444
|
+
result,
|
|
445
|
+
span,
|
|
446
|
+
ttft,
|
|
447
|
+
tbt,
|
|
448
|
+
});
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
catch (e) {
|
|
452
|
+
helpers_1.default.handleException(span, e);
|
|
453
|
+
throw e;
|
|
454
|
+
}
|
|
455
|
+
finally {
|
|
456
|
+
span.end();
|
|
457
|
+
if (metricParams) {
|
|
458
|
+
base_wrapper_1.default.recordMetrics(span, metricParams);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
static async _generateCommonSetter({ args, genAIEndpoint, result, span, ttft = 0, tbt = 0, }) {
|
|
463
|
+
const captureContent = config_1.default.captureMessageContent;
|
|
464
|
+
const requestModel = args[0]?.model || 'llama3';
|
|
465
|
+
const { prompt, stream = false } = args[0];
|
|
466
|
+
const options = args[0]?.options || {};
|
|
467
|
+
if (options.temperature != null) {
|
|
468
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TEMPERATURE, options.temperature);
|
|
469
|
+
}
|
|
470
|
+
if (options.top_p != null) {
|
|
471
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_P, options.top_p);
|
|
472
|
+
}
|
|
473
|
+
if (options.top_k != null) {
|
|
474
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_K, options.top_k);
|
|
475
|
+
}
|
|
476
|
+
if (options.max_tokens != null) {
|
|
477
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, options.max_tokens);
|
|
478
|
+
}
|
|
479
|
+
if (options.repeat_penalty) {
|
|
480
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY, options.repeat_penalty);
|
|
481
|
+
}
|
|
482
|
+
if (options.seed != null) {
|
|
483
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_SEED, Number(options.seed));
|
|
484
|
+
}
|
|
485
|
+
if (options.stop) {
|
|
486
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES, Array.isArray(options.stop) ? options.stop : [options.stop]);
|
|
487
|
+
}
|
|
488
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, stream);
|
|
489
|
+
if (captureContent) {
|
|
490
|
+
const inputMessages = [{ role: 'user', content: prompt || '' }];
|
|
491
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages(inputMessages));
|
|
492
|
+
}
|
|
493
|
+
const responseModel = result.model || requestModel;
|
|
494
|
+
const pricingInfo = config_1.default.pricingInfo || {};
|
|
495
|
+
const inputTokens = result.prompt_eval_count || 0;
|
|
496
|
+
const outputTokens = result.eval_count || 0;
|
|
497
|
+
const cost = helpers_1.default.getChatModelCost(requestModel, pricingInfo, inputTokens, outputTokens);
|
|
498
|
+
OllamaWrapper.setBaseSpanAttributes(span, {
|
|
499
|
+
genAIEndpoint,
|
|
500
|
+
model: requestModel,
|
|
501
|
+
cost,
|
|
502
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
503
|
+
serverAddress: OllamaWrapper.serverAddress,
|
|
504
|
+
serverPort: OllamaWrapper.serverPort,
|
|
505
|
+
});
|
|
506
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, responseModel);
|
|
507
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
508
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
509
|
+
if (ttft > 0) {
|
|
510
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TTFT, ttft);
|
|
511
|
+
}
|
|
512
|
+
if (tbt > 0) {
|
|
513
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TBT, tbt);
|
|
514
|
+
}
|
|
515
|
+
if (result.done_reason) {
|
|
516
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, [result.done_reason]);
|
|
517
|
+
}
|
|
518
|
+
const llmResponse = result.response || '';
|
|
519
|
+
const outputType = typeof llmResponse === 'string'
|
|
520
|
+
? semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT
|
|
521
|
+
: semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_JSON;
|
|
522
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, outputType);
|
|
523
|
+
let inputMessagesJson;
|
|
524
|
+
let outputMessagesJson;
|
|
525
|
+
if (captureContent) {
|
|
526
|
+
const inputMessages = [{ role: 'user', content: prompt || '' }];
|
|
527
|
+
outputMessagesJson = helpers_1.default.buildOutputMessages(llmResponse, result.done_reason || 'stop');
|
|
528
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, outputMessagesJson);
|
|
529
|
+
inputMessagesJson = helpers_1.default.buildInputMessages(inputMessages);
|
|
530
|
+
}
|
|
531
|
+
const versionExtras = OllamaWrapper._stampAgentVersion(span, {
|
|
532
|
+
primaryModel: responseModel || requestModel,
|
|
533
|
+
temperature: options.temperature ?? null,
|
|
534
|
+
top_p: options.top_p ?? null,
|
|
535
|
+
max_tokens: options.max_tokens ?? null,
|
|
536
|
+
});
|
|
537
|
+
if (!config_1.default.disableEvents) {
|
|
538
|
+
const eventAttrs = {
|
|
539
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TEXT_COMPLETION,
|
|
540
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
541
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: responseModel,
|
|
542
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: OllamaWrapper.serverAddress,
|
|
543
|
+
[semantic_convention_1.default.SERVER_PORT]: OllamaWrapper.serverPort,
|
|
544
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: [result.done_reason || 'stop'],
|
|
545
|
+
[semantic_convention_1.default.GEN_AI_OUTPUT_TYPE]: outputType,
|
|
546
|
+
[semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: inputTokens,
|
|
547
|
+
[semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: outputTokens,
|
|
548
|
+
...versionExtras,
|
|
549
|
+
};
|
|
550
|
+
if (captureContent) {
|
|
551
|
+
if (inputMessagesJson)
|
|
552
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES] = inputMessagesJson;
|
|
553
|
+
if (outputMessagesJson)
|
|
554
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES] = outputMessagesJson;
|
|
555
|
+
}
|
|
556
|
+
helpers_1.default.emitInferenceEvent(span, eventAttrs);
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
genAIEndpoint,
|
|
560
|
+
model: requestModel,
|
|
561
|
+
cost,
|
|
562
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
// ──────────────────── Embeddings ────────────────────
|
|
566
|
+
static _patchEmbeddings(tracer) {
|
|
567
|
+
const genAIEndpoint = 'ollama.embeddings';
|
|
568
|
+
return (originalMethod) => {
|
|
569
|
+
return async function (...args) {
|
|
570
|
+
if ((0, helpers_1.isFrameworkLlmActive)())
|
|
571
|
+
return originalMethod.apply(this, args);
|
|
572
|
+
const requestModel = args[0]?.model || 'llama3';
|
|
573
|
+
const spanName = `${semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EMBEDDING} ${requestModel}`;
|
|
574
|
+
const effectiveCtx = (0, helpers_1.getFrameworkParentContext)() ?? api_1.context.active();
|
|
575
|
+
const span = tracer.startSpan(spanName, {
|
|
576
|
+
kind: api_1.SpanKind.CLIENT,
|
|
577
|
+
attributes: spanCreationAttrs(semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EMBEDDING, requestModel),
|
|
578
|
+
}, effectiveCtx);
|
|
579
|
+
return api_1.context.with(api_1.trace.setSpan(effectiveCtx, span), async () => {
|
|
580
|
+
const captureContent = config_1.default.captureMessageContent;
|
|
581
|
+
let metricParams;
|
|
582
|
+
try {
|
|
583
|
+
const response = await originalMethod.apply(this, args);
|
|
584
|
+
const promptVal = args[0]?.input || args[0]?.prompt || '';
|
|
585
|
+
const promptText = typeof promptVal === 'string' ? promptVal : JSON.stringify(promptVal);
|
|
586
|
+
const inputTokens = helpers_1.default.generalTokens(promptText);
|
|
587
|
+
const pricingInfo = config_1.default.pricingInfo || {};
|
|
588
|
+
const cost = helpers_1.default.getEmbedModelCost(requestModel, pricingInfo, inputTokens);
|
|
589
|
+
OllamaWrapper.setBaseSpanAttributes(span, {
|
|
590
|
+
genAIEndpoint,
|
|
591
|
+
model: requestModel,
|
|
592
|
+
cost,
|
|
593
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
594
|
+
serverAddress: OllamaWrapper.serverAddress,
|
|
595
|
+
serverPort: OllamaWrapper.serverPort,
|
|
596
|
+
});
|
|
597
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, false);
|
|
598
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
599
|
+
if (captureContent) {
|
|
600
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, promptText);
|
|
601
|
+
}
|
|
602
|
+
metricParams = {
|
|
603
|
+
genAIEndpoint,
|
|
604
|
+
model: requestModel,
|
|
605
|
+
cost,
|
|
606
|
+
aiSystem: OllamaWrapper.aiSystem,
|
|
607
|
+
};
|
|
608
|
+
return response;
|
|
609
|
+
}
|
|
610
|
+
catch (e) {
|
|
611
|
+
helpers_1.default.handleException(span, e);
|
|
612
|
+
throw e;
|
|
613
|
+
}
|
|
614
|
+
finally {
|
|
615
|
+
span.end();
|
|
616
|
+
if (metricParams) {
|
|
617
|
+
base_wrapper_1.default.recordMetrics(span, metricParams);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
OllamaWrapper.aiSystem = semantic_convention_1.default.GEN_AI_SYSTEM_OLLAMA;
|
|
626
|
+
OllamaWrapper.serverAddress = '127.0.0.1';
|
|
627
|
+
OllamaWrapper.serverPort = 11434;
|
|
628
|
+
exports.default = OllamaWrapper;
|
|
629
|
+
//# sourceMappingURL=wrapper.js.map
|