openlit 1.12.0 → 1.14.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/README.md +34 -1
- package/dist/__tests__/manual-trace.test.js +118 -0
- package/dist/__tests__/manual-trace.test.js.map +1 -0
- package/dist/__tests__/register.test.js +90 -0
- package/dist/__tests__/register.test.js.map +1 -0
- package/dist/config.d.ts +7 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/evals/__tests__/offline.test.js +418 -0
- package/dist/evals/__tests__/offline.test.js.map +1 -0
- package/dist/evals/index.d.ts +2 -5
- package/dist/evals/index.js +12 -26
- package/dist/evals/index.js.map +1 -1
- package/dist/evals/offline.d.ts +6 -0
- package/dist/evals/offline.js +347 -0
- package/dist/evals/offline.js.map +1 -0
- package/dist/evals/types.d.ts +69 -18
- package/dist/evals/types.js +20 -0
- package/dist/evals/types.js.map +1 -1
- package/dist/guard/__tests__/integration.test.js +178 -0
- package/dist/guard/__tests__/integration.test.js.map +1 -0
- package/dist/guard/__tests__/pii.test.js +109 -0
- package/dist/guard/__tests__/pii.test.js.map +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.js +92 -0
- package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
- package/dist/guard/base.d.ts +75 -14
- package/dist/guard/base.js +130 -53
- package/dist/guard/base.js.map +1 -1
- 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/index.d.ts +24 -5
- package/dist/guard/index.js +39 -21
- package/dist/guard/index.js.map +1 -1
- package/dist/guard/integration.d.ts +32 -0
- package/dist/guard/integration.js +328 -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 +94 -0
- package/dist/guard/pii.js.map +1 -0
- package/dist/guard/pipeline.d.ts +18 -0
- package/dist/guard/pipeline.js +96 -0
- package/dist/guard/pipeline.js.map +1 -0
- package/dist/guard/prompt-injection.d.ts +20 -6
- package/dist/guard/prompt-injection.js +59 -68
- package/dist/guard/prompt-injection.js.map +1 -1
- 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 +22 -6
- package/dist/guard/sensitive-topic.js +78 -64
- package/dist/guard/sensitive-topic.js.map +1 -1
- package/dist/guard/topic-restriction.d.ts +21 -6
- package/dist/guard/topic-restriction.js +43 -64
- package/dist/guard/topic-restriction.js.map +1 -1
- package/dist/helpers.d.ts +133 -2
- package/dist/helpers.js +416 -5
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +54 -30
- package/dist/index.js +104 -22
- package/dist/index.js.map +1 -1
- 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__/assemblyai-wrapper.test.js +262 -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__/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 +12 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js +95 -0
- package/dist/instrumentation/__tests__/cache-pricing.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__/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.js +150 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
- 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__/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__/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__/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__/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__/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/wrapper.js +56 -2
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
- 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 +233 -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/wrapper.d.ts +13 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js +60 -1
- package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -1
- package/dist/instrumentation/bedrock/wrapper.d.ts +13 -0
- package/dist/instrumentation/bedrock/wrapper.js +78 -2
- package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
- 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/claude-agent-sdk/wrapper.js +90 -4
- package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -1
- package/dist/instrumentation/cohere/wrapper.d.ts +13 -0
- package/dist/instrumentation/cohere/wrapper.js +59 -0
- package/dist/instrumentation/cohere/wrapper.js.map +1 -1
- 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 +785 -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-ai/wrapper.d.ts +13 -0
- package/dist/instrumentation/google-ai/wrapper.js +85 -1
- package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
- 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/wrapper.js +42 -0
- package/dist/instrumentation/groq/wrapper.js.map +1 -1
- package/dist/instrumentation/huggingface/wrapper.d.ts +13 -0
- package/dist/instrumentation/huggingface/wrapper.js +66 -0
- package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
- package/dist/instrumentation/index.js +28 -0
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/instrumentation/langchain/wrapper.js +5 -8
- package/dist/instrumentation/langchain/wrapper.js.map +1 -1
- package/dist/instrumentation/langgraph/wrapper.js +12 -11
- package/dist/instrumentation/langgraph/wrapper.js.map +1 -1
- package/dist/instrumentation/llamaindex/wrapper.d.ts +14 -1
- package/dist/instrumentation/llamaindex/wrapper.js +68 -0
- package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
- 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/mistral/wrapper.d.ts +13 -0
- package/dist/instrumentation/mistral/wrapper.js +60 -1
- package/dist/instrumentation/mistral/wrapper.js.map +1 -1
- package/dist/instrumentation/ollama/wrapper.d.ts +13 -0
- package/dist/instrumentation/ollama/wrapper.js +67 -1
- package/dist/instrumentation/ollama/wrapper.js.map +1 -1
- package/dist/instrumentation/openai/wrapper.d.ts +13 -0
- package/dist/instrumentation/openai/wrapper.js +89 -3
- package/dist/instrumentation/openai/wrapper.js.map +1 -1
- 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/replicate/wrapper.d.ts +13 -0
- package/dist/instrumentation/replicate/wrapper.js +61 -0
- package/dist/instrumentation/replicate/wrapper.js.map +1 -1
- package/dist/instrumentation/strands/processor.d.ts +6 -0
- package/dist/instrumentation/strands/processor.js +73 -3
- package/dist/instrumentation/strands/processor.js.map +1 -1
- package/dist/instrumentation/strands/utils.d.ts +2 -2
- package/dist/instrumentation/strands/utils.js +15 -2
- package/dist/instrumentation/strands/utils.js.map +1 -1
- package/dist/instrumentation/together/wrapper.d.ts +13 -0
- package/dist/instrumentation/together/wrapper.js +59 -1
- package/dist/instrumentation/together/wrapper.js.map +1 -1
- 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/wrapper.d.ts +13 -0
- package/dist/instrumentation/vercel-ai/wrapper.js +106 -1
- package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
- 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 +529 -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/index.d.ts +9 -2
- package/dist/llm/index.js.map +1 -1
- 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/metrics.d.ts +11 -0
- package/dist/otel/metrics.js +48 -0
- package/dist/otel/metrics.js.map +1 -1
- 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 +278 -0
- package/dist/semantic-convention.js +322 -0
- package/dist/semantic-convention.js.map +1 -1
- package/dist/types.d.ts +15 -1
- package/package.json +18 -1
- package/dist/evals/__tests__/anthropic.test.js +0 -9
- package/dist/evals/__tests__/anthropic.test.js.map +0 -1
- package/dist/evals/__tests__/base.test.js +0 -37
- package/dist/evals/__tests__/base.test.js.map +0 -1
- package/dist/evals/__tests__/core.test.js +0 -33
- package/dist/evals/__tests__/core.test.js.map +0 -1
- package/dist/evals/__tests__/metrics.test.js +0 -59
- package/dist/evals/__tests__/metrics.test.js.map +0 -1
- package/dist/evals/__tests__/openai.test.js +0 -9
- package/dist/evals/__tests__/openai.test.js.map +0 -1
- package/dist/evals/__tests__/providers.test.js +0 -14
- package/dist/evals/__tests__/providers.test.js.map +0 -1
- package/dist/evals/__tests__/utils.test.js +0 -46
- package/dist/evals/__tests__/utils.test.js.map +0 -1
- package/dist/evals/all.d.ts +0 -4
- package/dist/evals/all.js +0 -35
- package/dist/evals/all.js.map +0 -1
- package/dist/evals/base.d.ts +0 -15
- package/dist/evals/base.js +0 -51
- package/dist/evals/base.js.map +0 -1
- package/dist/evals/bias.d.ts +0 -4
- package/dist/evals/bias.js +0 -35
- package/dist/evals/bias.js.map +0 -1
- package/dist/evals/hallucination.d.ts +0 -4
- package/dist/evals/hallucination.js +0 -32
- package/dist/evals/hallucination.js.map +0 -1
- package/dist/evals/llm/anthropic.d.ts +0 -5
- package/dist/evals/llm/anthropic.js +0 -42
- package/dist/evals/llm/anthropic.js.map +0 -1
- package/dist/evals/llm/openai.d.ts +0 -6
- package/dist/evals/llm/openai.js +0 -28
- package/dist/evals/llm/openai.js.map +0 -1
- package/dist/evals/llm/providers.d.ts +0 -7
- package/dist/evals/llm/providers.js +0 -10
- package/dist/evals/llm/providers.js.map +0 -1
- package/dist/evals/metrics.d.ts +0 -9
- package/dist/evals/metrics.js +0 -38
- package/dist/evals/metrics.js.map +0 -1
- package/dist/evals/toxicity.d.ts +0 -4
- package/dist/evals/toxicity.js +0 -33
- package/dist/evals/toxicity.js.map +0 -1
- package/dist/evals/utils.d.ts +0 -4
- package/dist/evals/utils.js +0 -39
- package/dist/evals/utils.js.map +0 -1
- package/dist/guard/__tests__/gaurd.test.js +0 -136
- package/dist/guard/__tests__/gaurd.test.js.map +0 -1
- package/dist/guard/__tests__/utils.test.js +0 -64
- package/dist/guard/__tests__/utils.test.js.map +0 -1
- package/dist/guard/all.d.ts +0 -8
- package/dist/guard/all.js +0 -28
- package/dist/guard/all.js.map +0 -1
- package/dist/guard/types.d.ts +0 -26
- package/dist/guard/types.js +0 -4
- package/dist/guard/types.js.map +0 -1
- package/dist/guard/utils.d.ts +0 -13
- package/dist/guard/utils.js +0 -79
- package/dist/guard/utils.js.map +0 -1
- /package/dist/{evals/__tests__/anthropic.test.d.ts → __tests__/manual-trace.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/metrics.test.d.ts → __tests__/register.test.d.ts} +0 -0
- /package/dist/evals/__tests__/{base.test.d.ts → offline.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/core.test.d.ts → guard/__tests__/integration.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/openai.test.d.ts → guard/__tests__/pii.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/providers.test.d.ts → guard/__tests__/pipeline.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/utils.test.d.ts → guard/__tests__/prompt-injection.test.d.ts} +0 -0
- /package/dist/{guard/__tests__/gaurd.test.d.ts → instrumentation/__tests__/assemblyai-wrapper.test.d.ts} +0 -0
- /package/dist/{guard/__tests__/utils.test.d.ts → instrumentation/__tests__/browser-use-wrapper.test.d.ts} +0 -0
|
@@ -0,0 +1,706 @@
|
|
|
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 core_1 = require("@opentelemetry/core");
|
|
41
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
42
|
+
const config_1 = __importDefault(require("../../config"));
|
|
43
|
+
const constant_1 = require("../../constant");
|
|
44
|
+
const helpers_1 = __importStar(require("../../helpers"));
|
|
45
|
+
const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
|
|
46
|
+
const SERVER_ADDRESS = 'browser-use.com';
|
|
47
|
+
const SERVER_PORT = 443;
|
|
48
|
+
const ACTION_PARAM_KEYS = new Set([
|
|
49
|
+
'index',
|
|
50
|
+
'text',
|
|
51
|
+
'url',
|
|
52
|
+
'query',
|
|
53
|
+
'selector',
|
|
54
|
+
'new_tab',
|
|
55
|
+
'down',
|
|
56
|
+
'num_pages',
|
|
57
|
+
]);
|
|
58
|
+
function truncateContent(content) {
|
|
59
|
+
const maxLen = config_1.default.maxContentLength;
|
|
60
|
+
if (typeof maxLen === 'number' && maxLen > 0 && content.length > maxLen) {
|
|
61
|
+
return content.slice(0, maxLen);
|
|
62
|
+
}
|
|
63
|
+
return content;
|
|
64
|
+
}
|
|
65
|
+
function safeStringify(value) {
|
|
66
|
+
if (typeof value === 'string')
|
|
67
|
+
return value;
|
|
68
|
+
try {
|
|
69
|
+
return JSON.stringify(value);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return String(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function buildUserMessage(content) {
|
|
76
|
+
return JSON.stringify([
|
|
77
|
+
{
|
|
78
|
+
role: 'user',
|
|
79
|
+
parts: [{ type: 'text', content: truncateContent(content) }],
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
function setCommonSpanAttributes(span, operation, sdkVersion, operationType) {
|
|
84
|
+
span.setAttribute(semantic_conventions_1.ATTR_TELEMETRY_SDK_NAME, constant_1.SDK_NAME);
|
|
85
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME, semantic_convention_1.default.GEN_AI_SYSTEM_BROWSER_USE);
|
|
86
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, semantic_convention_1.default.GEN_AI_SYSTEM_BROWSER_USE);
|
|
87
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, operation);
|
|
88
|
+
if (operationType) {
|
|
89
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION_TYPE, operationType);
|
|
90
|
+
}
|
|
91
|
+
span.setAttribute(semantic_convention_1.default.ATTR_DEPLOYMENT_ENVIRONMENT, config_1.default.environment || '');
|
|
92
|
+
span.setAttribute(semantic_conventions_1.ATTR_SERVICE_NAME, config_1.default.applicationName || '');
|
|
93
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, sdkVersion);
|
|
94
|
+
span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, SERVER_ADDRESS);
|
|
95
|
+
span.setAttribute(semantic_convention_1.default.SERVER_PORT, SERVER_PORT);
|
|
96
|
+
}
|
|
97
|
+
function resolveAgentName(instance) {
|
|
98
|
+
const explicitName = instance?.name ?? instance?.agent_name;
|
|
99
|
+
if (typeof explicitName === 'string' && explicitName.trim()) {
|
|
100
|
+
return explicitName.trim();
|
|
101
|
+
}
|
|
102
|
+
return 'browser_use';
|
|
103
|
+
}
|
|
104
|
+
function resolveAgentDescription(instance) {
|
|
105
|
+
if (typeof instance?.task === 'string' && instance.task.trim()) {
|
|
106
|
+
return instance.task.trim();
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
function resolveModelName(instance) {
|
|
111
|
+
const llm = instance?.llm;
|
|
112
|
+
if (!llm)
|
|
113
|
+
return null;
|
|
114
|
+
for (const key of ['model_name', 'model', 'name']) {
|
|
115
|
+
const value = llm?.[key];
|
|
116
|
+
if (typeof value === 'string' && value.trim()) {
|
|
117
|
+
return value.trim();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
function resolveCurrentUrl(instance) {
|
|
123
|
+
try {
|
|
124
|
+
const browserSession = instance?.browser_session ?? instance?.browserSession;
|
|
125
|
+
const page = browserSession?.current_page ?? browserSession?.currentPage ?? instance?.page;
|
|
126
|
+
const url = page?.url;
|
|
127
|
+
return typeof url === 'string' && url.trim() ? url : null;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function resolveMaxSteps(instance, args) {
|
|
134
|
+
for (const arg of args) {
|
|
135
|
+
if (typeof arg === 'number' && Number.isFinite(arg)) {
|
|
136
|
+
return arg;
|
|
137
|
+
}
|
|
138
|
+
if (arg && typeof arg === 'object' && typeof arg.max_steps === 'number') {
|
|
139
|
+
return arg.max_steps;
|
|
140
|
+
}
|
|
141
|
+
if (arg && typeof arg === 'object' && typeof arg.maxSteps === 'number') {
|
|
142
|
+
return arg.maxSteps;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (typeof instance?.max_steps === 'number') {
|
|
146
|
+
return instance.max_steps;
|
|
147
|
+
}
|
|
148
|
+
if (typeof instance?.maxSteps === 'number') {
|
|
149
|
+
return instance.maxSteps;
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function applyAgentIdentityAttributes(span, instance) {
|
|
154
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_TYPE, semantic_convention_1.default.GEN_AI_AGENT_TYPE_BROWSER);
|
|
155
|
+
if (instance?.id !== undefined && instance?.id !== null) {
|
|
156
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ID, String(instance.id));
|
|
157
|
+
}
|
|
158
|
+
if (instance?.task_id !== undefined && instance?.task_id !== null) {
|
|
159
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_BROWSER_AGENT_TASK_ID, String(instance.task_id));
|
|
160
|
+
}
|
|
161
|
+
if (instance?.session_id !== undefined && instance?.session_id !== null) {
|
|
162
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_SESSION_ID, String(instance.session_id));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function applyAgentConfigAttributes(span, instance, args) {
|
|
166
|
+
const maxSteps = resolveMaxSteps(instance, args);
|
|
167
|
+
if (typeof maxSteps === 'number') {
|
|
168
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_MAX_STEPS, maxSteps);
|
|
169
|
+
}
|
|
170
|
+
const currentUrl = resolveCurrentUrl(instance);
|
|
171
|
+
if (currentUrl) {
|
|
172
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_BROWSE_URL, currentUrl);
|
|
173
|
+
}
|
|
174
|
+
const settings = instance?.settings;
|
|
175
|
+
if (settings && typeof settings === 'object') {
|
|
176
|
+
if (typeof settings.use_vision === 'boolean') {
|
|
177
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_USE_VISION, settings.use_vision);
|
|
178
|
+
}
|
|
179
|
+
else if (typeof settings.useVision === 'boolean') {
|
|
180
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_USE_VISION, settings.useVision);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (typeof instance?.use_vision === 'boolean') {
|
|
184
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_USE_VISION, instance.use_vision);
|
|
185
|
+
}
|
|
186
|
+
else if (typeof instance?.useVision === 'boolean') {
|
|
187
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_USE_VISION, instance.useVision);
|
|
188
|
+
}
|
|
189
|
+
const profile = instance?.browser_profile ?? instance?.browserProfile;
|
|
190
|
+
if (profile && typeof profile === 'object') {
|
|
191
|
+
if (typeof profile.headless === 'boolean') {
|
|
192
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_HEADLESS, profile.headless);
|
|
193
|
+
}
|
|
194
|
+
const allowedDomains = profile.allowed_domains ?? profile.allowedDomains;
|
|
195
|
+
if (Array.isArray(allowedDomains) && allowedDomains.length > 0) {
|
|
196
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ALLOWED_DOMAINS, safeStringify(allowedDomains));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function resolveToolDescription(instance, actionName) {
|
|
201
|
+
try {
|
|
202
|
+
const registry = instance?.registry;
|
|
203
|
+
const action = registry?.get_action?.(actionName) ??
|
|
204
|
+
registry?.getAction?.(actionName) ??
|
|
205
|
+
registry?.getActions?.()?.[actionName];
|
|
206
|
+
const description = action?.description;
|
|
207
|
+
return typeof description === 'string' && description.trim() ? description.trim() : null;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function firstActionEntry(action) {
|
|
214
|
+
const entries = action ? Object.entries(action) : [];
|
|
215
|
+
if (entries.length === 0)
|
|
216
|
+
return ['unknown', {}];
|
|
217
|
+
const [key, value] = entries[0];
|
|
218
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
219
|
+
return [key, value];
|
|
220
|
+
}
|
|
221
|
+
return [key, value ?? {}];
|
|
222
|
+
}
|
|
223
|
+
function actionDictFromModel(action) {
|
|
224
|
+
if (!action || typeof action !== 'object')
|
|
225
|
+
return null;
|
|
226
|
+
if (typeof action.model_dump === 'function') {
|
|
227
|
+
return action.model_dump();
|
|
228
|
+
}
|
|
229
|
+
if (typeof action.toJSON === 'function') {
|
|
230
|
+
return action.toJSON();
|
|
231
|
+
}
|
|
232
|
+
return action;
|
|
233
|
+
}
|
|
234
|
+
function calculateStepStats(history) {
|
|
235
|
+
let successfulSteps = 0;
|
|
236
|
+
let failedSteps = 0;
|
|
237
|
+
let totalActions = 0;
|
|
238
|
+
for (const step of history) {
|
|
239
|
+
const results = step?.result;
|
|
240
|
+
if (!Array.isArray(results) || results.length === 0) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
let stepSuccess = true;
|
|
244
|
+
for (const result of results) {
|
|
245
|
+
totalActions += 1;
|
|
246
|
+
if (result?.is_success === false || result?.isSuccess === false) {
|
|
247
|
+
stepSuccess = false;
|
|
248
|
+
}
|
|
249
|
+
if (result?.error) {
|
|
250
|
+
stepSuccess = false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (stepSuccess) {
|
|
254
|
+
successfulSteps += 1;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
failedSteps += 1;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { successfulSteps, failedSteps, totalActions };
|
|
261
|
+
}
|
|
262
|
+
function captureTokenAndCost(span, response, modelName) {
|
|
263
|
+
if (!modelName)
|
|
264
|
+
return;
|
|
265
|
+
const usage = response?.usage;
|
|
266
|
+
if (!usage || typeof usage !== 'object')
|
|
267
|
+
return;
|
|
268
|
+
const inputTokens = usage.total_input_tokens ?? usage.input_tokens ?? usage.inputTokens ?? 0;
|
|
269
|
+
const outputTokens = usage.total_output_tokens ?? usage.output_tokens ?? usage.outputTokens ?? 0;
|
|
270
|
+
if (inputTokens > 0) {
|
|
271
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
272
|
+
}
|
|
273
|
+
if (outputTokens > 0) {
|
|
274
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
275
|
+
}
|
|
276
|
+
const directCost = usage.total_cost ?? usage.cost;
|
|
277
|
+
if (typeof directCost === 'number' && directCost > 0) {
|
|
278
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COST, directCost);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const pricingInfo = config_1.default.pricingInfo;
|
|
282
|
+
if (pricingInfo && inputTokens + outputTokens > 0) {
|
|
283
|
+
const cost = helpers_1.default.getChatModelCost(modelName, pricingInfo, inputTokens, outputTokens);
|
|
284
|
+
if (cost > 0) {
|
|
285
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COST, cost);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function processAgentHistoryResponse(span, response) {
|
|
290
|
+
if (!response || typeof response !== 'object')
|
|
291
|
+
return;
|
|
292
|
+
const history = response.history;
|
|
293
|
+
if (!Array.isArray(history))
|
|
294
|
+
return;
|
|
295
|
+
const totalSteps = history.length;
|
|
296
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_STEP_COUNT, totalSteps);
|
|
297
|
+
const stats = calculateStepStats(history);
|
|
298
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_TOTAL_ACTIONS, stats.totalActions);
|
|
299
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_SUCCESSFUL_STEPS, stats.successfulSteps);
|
|
300
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_FAILED_STEPS, stats.failedSteps);
|
|
301
|
+
if (totalSteps > 0) {
|
|
302
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_SUCCESS_RATE, (stats.successfulSteps / totalSteps) * 100);
|
|
303
|
+
}
|
|
304
|
+
if (config_1.default.captureMessageContent) {
|
|
305
|
+
const finalResult = typeof response.final_result === 'function'
|
|
306
|
+
? response.final_result()
|
|
307
|
+
: response.finalResult?.() ?? response.finalResult ?? response.final_result;
|
|
308
|
+
if (finalResult) {
|
|
309
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_FINAL_RESULT, truncateContent(String(finalResult)));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (typeof response.total_duration_seconds === 'function') {
|
|
313
|
+
const duration = response.total_duration_seconds();
|
|
314
|
+
if (typeof duration === 'number') {
|
|
315
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_EXECUTION_TIME, duration);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else if (typeof response.totalDurationSeconds === 'function') {
|
|
319
|
+
const duration = response.totalDurationSeconds();
|
|
320
|
+
if (typeof duration === 'number') {
|
|
321
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_EXECUTION_TIME, duration);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function createIndividualActionSpan(tracer, ctx, actionName, actionData, actionIndex, step) {
|
|
326
|
+
const span = tracer.startSpan(`invoke_agent ${actionName}`, {
|
|
327
|
+
kind: api_1.SpanKind.INTERNAL,
|
|
328
|
+
attributes: {
|
|
329
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
|
|
330
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_BROWSER_USE,
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
setCommonSpanAttributes(span, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT, ctx.sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK);
|
|
334
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, ctx.agentName);
|
|
335
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_TYPE, actionName);
|
|
336
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_INDEX, actionIndex + 1);
|
|
337
|
+
if (actionData && typeof actionData === 'object') {
|
|
338
|
+
for (const [key, value] of Object.entries(actionData)) {
|
|
339
|
+
if (ACTION_PARAM_KEYS.has(key) && value !== undefined && value !== null) {
|
|
340
|
+
span.setAttribute(`gen_ai.action.${key}`, truncateContent(String(value)));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const results = step?.result;
|
|
345
|
+
if (Array.isArray(results) && results[actionIndex]) {
|
|
346
|
+
const result = results[actionIndex];
|
|
347
|
+
if (typeof result?.is_success === 'boolean') {
|
|
348
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_SUCCESS, result.is_success);
|
|
349
|
+
}
|
|
350
|
+
else if (typeof result?.isSuccess === 'boolean') {
|
|
351
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_SUCCESS, result.isSuccess);
|
|
352
|
+
}
|
|
353
|
+
if (result?.error && config_1.default.captureMessageContent) {
|
|
354
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_ERROR, truncateContent(String(result.error)));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const stepState = step?.state;
|
|
358
|
+
if (stepState?.url) {
|
|
359
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_BROWSE_URL, String(stepState.url));
|
|
360
|
+
}
|
|
361
|
+
if (stepState?.title && config_1.default.captureMessageContent) {
|
|
362
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_PAGE_TITLE, truncateContent(String(stepState.title)));
|
|
363
|
+
}
|
|
364
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
365
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
366
|
+
span.end();
|
|
367
|
+
}
|
|
368
|
+
function createDetailedStepSpan(tracer, agentInstance, ctx) {
|
|
369
|
+
const history = agentInstance?.state?.history?.history ??
|
|
370
|
+
agentInstance?.state?.history ??
|
|
371
|
+
agentInstance?.history?.history;
|
|
372
|
+
if (!Array.isArray(history) || history.length === 0) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const latestStep = history[history.length - 1];
|
|
376
|
+
const stepNumber = history.length;
|
|
377
|
+
const span = tracer.startSpan(`execute_task step ${stepNumber}`, { kind: api_1.SpanKind.INTERNAL });
|
|
378
|
+
setCommonSpanAttributes(span, 'step', ctx.sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK);
|
|
379
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, ctx.agentName);
|
|
380
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_STEP_COUNT, stepNumber);
|
|
381
|
+
const modelOutput = latestStep?.model_output ?? latestStep?.modelOutput;
|
|
382
|
+
if (modelOutput && typeof modelOutput === 'object') {
|
|
383
|
+
if (modelOutput.thinking && config_1.default.captureMessageContent) {
|
|
384
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_THINKING, truncateContent(String(modelOutput.thinking)));
|
|
385
|
+
}
|
|
386
|
+
if (modelOutput.memory && config_1.default.captureMessageContent) {
|
|
387
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_MEMORY, truncateContent(String(modelOutput.memory)));
|
|
388
|
+
}
|
|
389
|
+
if (modelOutput.next_goal && config_1.default.captureMessageContent) {
|
|
390
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NEXT_GOAL, truncateContent(String(modelOutput.next_goal ?? modelOutput.nextGoal)));
|
|
391
|
+
}
|
|
392
|
+
const evaluation = modelOutput.evaluation_previous_goal ?? modelOutput.evaluationPreviousGoal;
|
|
393
|
+
if (evaluation && config_1.default.captureMessageContent) {
|
|
394
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_EVALUATION, truncateContent(String(evaluation)));
|
|
395
|
+
}
|
|
396
|
+
const actions = modelOutput.action ?? modelOutput.actions;
|
|
397
|
+
if (Array.isArray(actions)) {
|
|
398
|
+
const actionsSummary = [];
|
|
399
|
+
actions.forEach((action, index) => {
|
|
400
|
+
const actionDict = actionDictFromModel(action);
|
|
401
|
+
const [actionName] = firstActionEntry(actionDict);
|
|
402
|
+
actionsSummary.push(actionName);
|
|
403
|
+
createIndividualActionSpan(tracer, ctx, actionName, actionDict?.[actionName], index, latestStep);
|
|
404
|
+
});
|
|
405
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ACTIONS, safeStringify(actionsSummary));
|
|
406
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ACTIONS_COUNT, actions.length);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const state = latestStep?.state;
|
|
410
|
+
if (state && typeof state === 'object') {
|
|
411
|
+
if (state.url) {
|
|
412
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_BROWSE_URL, String(state.url));
|
|
413
|
+
}
|
|
414
|
+
if (state.title && config_1.default.captureMessageContent) {
|
|
415
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_PAGE_TITLE, truncateContent(String(state.title)));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
419
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
420
|
+
span.end();
|
|
421
|
+
}
|
|
422
|
+
function createStepSpansFromHistory(tracer, agentInstance, response, ctx) {
|
|
423
|
+
const history = response?.history ??
|
|
424
|
+
agentInstance?.state?.history?.history ??
|
|
425
|
+
agentInstance?.state?.history;
|
|
426
|
+
if (!Array.isArray(history))
|
|
427
|
+
return;
|
|
428
|
+
history.forEach((_step, index) => {
|
|
429
|
+
const stepNumber = index + 1;
|
|
430
|
+
const step = history[index];
|
|
431
|
+
const span = tracer.startSpan(`execute_task step ${stepNumber}`, { kind: api_1.SpanKind.INTERNAL });
|
|
432
|
+
setCommonSpanAttributes(span, 'step', ctx.sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK);
|
|
433
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, ctx.agentName);
|
|
434
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_STEP_COUNT, stepNumber);
|
|
435
|
+
const modelOutput = step?.model_output ?? step?.modelOutput;
|
|
436
|
+
const actions = modelOutput?.action ?? modelOutput?.actions;
|
|
437
|
+
if (Array.isArray(actions)) {
|
|
438
|
+
const actionsSummary = [];
|
|
439
|
+
actions.forEach((action, actionIndex) => {
|
|
440
|
+
const actionDict = actionDictFromModel(action);
|
|
441
|
+
const [actionName] = firstActionEntry(actionDict);
|
|
442
|
+
actionsSummary.push(actionName);
|
|
443
|
+
createIndividualActionSpan(tracer, ctx, actionName, actionDict?.[actionName], actionIndex, step);
|
|
444
|
+
});
|
|
445
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ACTIONS, safeStringify(actionsSummary));
|
|
446
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ACTIONS_COUNT, actions.length);
|
|
447
|
+
}
|
|
448
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
449
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
450
|
+
span.end();
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function findRunOptionsArg(args) {
|
|
454
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
455
|
+
const arg = args[index];
|
|
456
|
+
if (!arg || typeof arg !== 'object' || Array.isArray(arg))
|
|
457
|
+
continue;
|
|
458
|
+
if ('on_step_end' in arg ||
|
|
459
|
+
'on_step_start' in arg ||
|
|
460
|
+
'onStepEnd' in arg ||
|
|
461
|
+
'onStepStart' in arg ||
|
|
462
|
+
'max_steps' in arg ||
|
|
463
|
+
'maxSteps' in arg) {
|
|
464
|
+
return { index, options: arg };
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
function installStepHooks(tracer, agentInstance, ctx, args, onStepCompleted) {
|
|
470
|
+
const patchedArgs = [...args];
|
|
471
|
+
let optionsEntry = findRunOptionsArg(patchedArgs);
|
|
472
|
+
if (!optionsEntry) {
|
|
473
|
+
const options = {};
|
|
474
|
+
patchedArgs.push(options);
|
|
475
|
+
optionsEntry = { index: patchedArgs.length - 1, options };
|
|
476
|
+
}
|
|
477
|
+
const options = optionsEntry.options;
|
|
478
|
+
const originalOnStepEnd = options.on_step_end ?? options.onStepEnd;
|
|
479
|
+
const originalOnStepStart = options.on_step_start ?? options.onStepStart;
|
|
480
|
+
options.on_step_end = options.onStepEnd = async (agent) => {
|
|
481
|
+
createDetailedStepSpan(tracer, agent ?? agentInstance, ctx);
|
|
482
|
+
onStepCompleted();
|
|
483
|
+
if (typeof originalOnStepEnd === 'function') {
|
|
484
|
+
await originalOnStepEnd(agent);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
options.on_step_start = options.onStepStart = async (agent) => {
|
|
488
|
+
if (typeof originalOnStepStart === 'function') {
|
|
489
|
+
await originalOnStepStart(agent);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
patchedArgs[optionsEntry.index] = options;
|
|
493
|
+
return patchedArgs;
|
|
494
|
+
}
|
|
495
|
+
function finalizeSpan(span, startTime) {
|
|
496
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, (Date.now() - startTime) / 1000);
|
|
497
|
+
span.end();
|
|
498
|
+
}
|
|
499
|
+
class BrowserUseWrapper {
|
|
500
|
+
static _patchAgentRun(tracer, version) {
|
|
501
|
+
const sdkVersion = version || 'unknown';
|
|
502
|
+
return (originalMethod) => {
|
|
503
|
+
return async function wrappedAgentRun(...args) {
|
|
504
|
+
if ((0, core_1.isTracingSuppressed)(api_1.context.active())) {
|
|
505
|
+
return originalMethod.apply(this, args);
|
|
506
|
+
}
|
|
507
|
+
const agentName = resolveAgentName(this);
|
|
508
|
+
const ctx = { agentName, sdkVersion };
|
|
509
|
+
const span = tracer.startSpan(`invoke_agent ${agentName}`, {
|
|
510
|
+
kind: api_1.SpanKind.CLIENT,
|
|
511
|
+
attributes: {
|
|
512
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
|
|
513
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_BROWSER_USE,
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
const startTime = Date.now();
|
|
517
|
+
setCommonSpanAttributes(span, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT, sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT);
|
|
518
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, agentName);
|
|
519
|
+
applyAgentIdentityAttributes(span, this);
|
|
520
|
+
applyAgentConfigAttributes(span, this, args);
|
|
521
|
+
const description = resolveAgentDescription(this);
|
|
522
|
+
if (description) {
|
|
523
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_DESCRIPTION, truncateContent(description));
|
|
524
|
+
if (config_1.default.captureMessageContent) {
|
|
525
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, buildUserMessage(description));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const model = resolveModelName(this);
|
|
529
|
+
if (model) {
|
|
530
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, model);
|
|
531
|
+
}
|
|
532
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
533
|
+
let stepSpansCreated = false;
|
|
534
|
+
const patchedArgs = installStepHooks(tracer, this, ctx, args, () => {
|
|
535
|
+
stepSpansCreated = true;
|
|
536
|
+
});
|
|
537
|
+
try {
|
|
538
|
+
const result = await api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => originalMethod.apply(this, patchedArgs));
|
|
539
|
+
processAgentHistoryResponse(span, result);
|
|
540
|
+
captureTokenAndCost(span, result, model);
|
|
541
|
+
if (!stepSpansCreated) {
|
|
542
|
+
createStepSpansFromHistory(tracer, this, result, ctx);
|
|
543
|
+
}
|
|
544
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
545
|
+
return result;
|
|
546
|
+
}
|
|
547
|
+
catch (e) {
|
|
548
|
+
helpers_1.default.handleException(span, e);
|
|
549
|
+
throw e;
|
|
550
|
+
}
|
|
551
|
+
finally {
|
|
552
|
+
finalizeSpan(span, startTime);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
static _patchAgentStep(tracer, version) {
|
|
558
|
+
const sdkVersion = version || 'unknown';
|
|
559
|
+
return (originalMethod) => {
|
|
560
|
+
return async function wrappedAgentStep(...args) {
|
|
561
|
+
if ((0, core_1.isTracingSuppressed)(api_1.context.active())) {
|
|
562
|
+
return originalMethod.apply(this, args);
|
|
563
|
+
}
|
|
564
|
+
const agentName = resolveAgentName(this);
|
|
565
|
+
const stepCount = this?.step_count ??
|
|
566
|
+
this?.stepCount ??
|
|
567
|
+
this?.state?.history?.history?.length ??
|
|
568
|
+
this?.state?.history?.length;
|
|
569
|
+
const model = resolveModelName(this);
|
|
570
|
+
const spanName = typeof stepCount === 'number'
|
|
571
|
+
? `execute_task step ${stepCount}`
|
|
572
|
+
: `invoke_model ${model ?? 'llm'}`;
|
|
573
|
+
const span = tracer.startSpan(spanName, { kind: api_1.SpanKind.CLIENT });
|
|
574
|
+
const startTime = Date.now();
|
|
575
|
+
setCommonSpanAttributes(span, 'step', sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK);
|
|
576
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, agentName);
|
|
577
|
+
applyAgentIdentityAttributes(span, this);
|
|
578
|
+
if (typeof stepCount === 'number') {
|
|
579
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_STEP_COUNT, stepCount);
|
|
580
|
+
}
|
|
581
|
+
if (model) {
|
|
582
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, model);
|
|
583
|
+
}
|
|
584
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
585
|
+
try {
|
|
586
|
+
const result = await api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => originalMethod.apply(this, args));
|
|
587
|
+
if (result && typeof result === 'object') {
|
|
588
|
+
if (typeof result.is_success === 'boolean') {
|
|
589
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_SUCCESS, result.is_success);
|
|
590
|
+
}
|
|
591
|
+
if (result.error && config_1.default.captureMessageContent) {
|
|
592
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_ERROR, truncateContent(String(result.error)));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
596
|
+
return result;
|
|
597
|
+
}
|
|
598
|
+
catch (e) {
|
|
599
|
+
helpers_1.default.handleException(span, e);
|
|
600
|
+
throw e;
|
|
601
|
+
}
|
|
602
|
+
finally {
|
|
603
|
+
finalizeSpan(span, startTime);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
static _patchAgentLifecycle(tracer, operation, version) {
|
|
609
|
+
const sdkVersion = version || 'unknown';
|
|
610
|
+
return (originalMethod) => {
|
|
611
|
+
return async function wrappedAgentLifecycle(...args) {
|
|
612
|
+
if ((0, core_1.isTracingSuppressed)(api_1.context.active())) {
|
|
613
|
+
return originalMethod.apply(this, args);
|
|
614
|
+
}
|
|
615
|
+
const agentName = resolveAgentName(this);
|
|
616
|
+
const span = tracer.startSpan(`browser ${operation}`, { kind: api_1.SpanKind.CLIENT });
|
|
617
|
+
const startTime = Date.now();
|
|
618
|
+
setCommonSpanAttributes(span, operation, sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK);
|
|
619
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, agentName);
|
|
620
|
+
applyAgentIdentityAttributes(span, this);
|
|
621
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
622
|
+
try {
|
|
623
|
+
const result = await api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => originalMethod.apply(this, args));
|
|
624
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
625
|
+
return result;
|
|
626
|
+
}
|
|
627
|
+
catch (e) {
|
|
628
|
+
helpers_1.default.handleException(span, e);
|
|
629
|
+
throw e;
|
|
630
|
+
}
|
|
631
|
+
finally {
|
|
632
|
+
finalizeSpan(span, startTime);
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
static _patchControllerAct(tracer, version) {
|
|
638
|
+
const sdkVersion = version || 'unknown';
|
|
639
|
+
return (originalMethod) => {
|
|
640
|
+
return async function wrappedControllerAct(action, ...rest) {
|
|
641
|
+
if ((0, core_1.isTracingSuppressed)(api_1.context.active())) {
|
|
642
|
+
return originalMethod.apply(this, [action, ...rest]);
|
|
643
|
+
}
|
|
644
|
+
const [actionName, params] = firstActionEntry(action);
|
|
645
|
+
const span = tracer.startSpan(`invoke_agent ${actionName}`, {
|
|
646
|
+
kind: api_1.SpanKind.INTERNAL,
|
|
647
|
+
attributes: {
|
|
648
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
|
|
649
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_BROWSER_USE,
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
const startTime = Date.now();
|
|
653
|
+
setCommonSpanAttributes(span, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT, sdkVersion, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK);
|
|
654
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_TYPE, actionName);
|
|
655
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_INDEX, 1);
|
|
656
|
+
const controllerAgentName = resolveAgentName(this);
|
|
657
|
+
if (controllerAgentName !== 'browser_use') {
|
|
658
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, controllerAgentName);
|
|
659
|
+
}
|
|
660
|
+
const description = resolveToolDescription(this, actionName);
|
|
661
|
+
if (description) {
|
|
662
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DESCRIPTION, truncateContent(description));
|
|
663
|
+
}
|
|
664
|
+
if (params && typeof params === 'object') {
|
|
665
|
+
for (const [key, value] of Object.entries(params)) {
|
|
666
|
+
if (ACTION_PARAM_KEYS.has(key) && value !== undefined && value !== null) {
|
|
667
|
+
span.setAttribute(`gen_ai.action.${key}`, truncateContent(String(value)));
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (config_1.default.captureMessageContent && params !== undefined) {
|
|
672
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ARGUMENTS, truncateContent(safeStringify(params)));
|
|
673
|
+
}
|
|
674
|
+
(0, helpers_1.applyCustomSpanAttributes)(span);
|
|
675
|
+
try {
|
|
676
|
+
const result = await originalMethod.apply(this, [action, ...rest]);
|
|
677
|
+
if (result && typeof result === 'object') {
|
|
678
|
+
if (typeof result.is_success === 'boolean') {
|
|
679
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_SUCCESS, result.is_success);
|
|
680
|
+
}
|
|
681
|
+
else if (typeof result.isSuccess === 'boolean') {
|
|
682
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_SUCCESS, result.isSuccess);
|
|
683
|
+
}
|
|
684
|
+
if (result.error && config_1.default.captureMessageContent) {
|
|
685
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_ACTION_ERROR, truncateContent(String(result.error)));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (config_1.default.captureMessageContent && result !== undefined) {
|
|
689
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_RESULT, truncateContent(safeStringify(result)));
|
|
690
|
+
}
|
|
691
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
catch (e) {
|
|
695
|
+
helpers_1.default.handleException(span, e);
|
|
696
|
+
throw e;
|
|
697
|
+
}
|
|
698
|
+
finally {
|
|
699
|
+
finalizeSpan(span, startTime);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
exports.default = BrowserUseWrapper;
|
|
706
|
+
//# sourceMappingURL=wrapper.js.map
|