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.
Files changed (352) hide show
  1. package/README.md +34 -1
  2. package/dist/__tests__/manual-trace.test.js +118 -0
  3. package/dist/__tests__/manual-trace.test.js.map +1 -0
  4. package/dist/__tests__/register.test.js +90 -0
  5. package/dist/__tests__/register.test.js.map +1 -0
  6. package/dist/config.d.ts +7 -1
  7. package/dist/config.js +3 -1
  8. package/dist/config.js.map +1 -1
  9. package/dist/evals/__tests__/offline.test.js +418 -0
  10. package/dist/evals/__tests__/offline.test.js.map +1 -0
  11. package/dist/evals/index.d.ts +2 -5
  12. package/dist/evals/index.js +12 -26
  13. package/dist/evals/index.js.map +1 -1
  14. package/dist/evals/offline.d.ts +6 -0
  15. package/dist/evals/offline.js +347 -0
  16. package/dist/evals/offline.js.map +1 -0
  17. package/dist/evals/types.d.ts +69 -18
  18. package/dist/evals/types.js +20 -0
  19. package/dist/evals/types.js.map +1 -1
  20. package/dist/guard/__tests__/integration.test.js +178 -0
  21. package/dist/guard/__tests__/integration.test.js.map +1 -0
  22. package/dist/guard/__tests__/pii.test.js +109 -0
  23. package/dist/guard/__tests__/pii.test.js.map +1 -0
  24. package/dist/guard/__tests__/pipeline.test.js +162 -0
  25. package/dist/guard/__tests__/pipeline.test.js.map +1 -0
  26. package/dist/guard/__tests__/prompt-injection.test.js +92 -0
  27. package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
  28. package/dist/guard/base.d.ts +75 -14
  29. package/dist/guard/base.js +130 -53
  30. package/dist/guard/base.js.map +1 -1
  31. package/dist/guard/custom.d.ts +19 -0
  32. package/dist/guard/custom.js +46 -0
  33. package/dist/guard/custom.js.map +1 -0
  34. package/dist/guard/index.d.ts +24 -5
  35. package/dist/guard/index.js +39 -21
  36. package/dist/guard/index.js.map +1 -1
  37. package/dist/guard/integration.d.ts +32 -0
  38. package/dist/guard/integration.js +328 -0
  39. package/dist/guard/integration.js.map +1 -0
  40. package/dist/guard/moderation.d.ts +18 -0
  41. package/dist/guard/moderation.js +61 -0
  42. package/dist/guard/moderation.js.map +1 -0
  43. package/dist/guard/pii.d.ts +17 -0
  44. package/dist/guard/pii.js +94 -0
  45. package/dist/guard/pii.js.map +1 -0
  46. package/dist/guard/pipeline.d.ts +18 -0
  47. package/dist/guard/pipeline.js +96 -0
  48. package/dist/guard/pipeline.js.map +1 -0
  49. package/dist/guard/prompt-injection.d.ts +20 -6
  50. package/dist/guard/prompt-injection.js +59 -68
  51. package/dist/guard/prompt-injection.js.map +1 -1
  52. package/dist/guard/schema.d.ts +20 -0
  53. package/dist/guard/schema.js +99 -0
  54. package/dist/guard/schema.js.map +1 -0
  55. package/dist/guard/sensitive-topic.d.ts +22 -6
  56. package/dist/guard/sensitive-topic.js +78 -64
  57. package/dist/guard/sensitive-topic.js.map +1 -1
  58. package/dist/guard/topic-restriction.d.ts +21 -6
  59. package/dist/guard/topic-restriction.js +43 -64
  60. package/dist/guard/topic-restriction.js.map +1 -1
  61. package/dist/helpers.d.ts +133 -2
  62. package/dist/helpers.js +416 -5
  63. package/dist/helpers.js.map +1 -1
  64. package/dist/index.d.ts +54 -30
  65. package/dist/index.js +104 -22
  66. package/dist/index.js.map +1 -1
  67. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
  68. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
  69. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
  70. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
  71. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
  72. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
  73. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +262 -0
  74. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
  75. package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
  76. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
  77. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
  78. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
  79. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
  80. package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +12 -0
  81. package/dist/instrumentation/__tests__/cache-pricing.test.js +95 -0
  82. package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
  83. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
  84. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
  85. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
  86. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
  87. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
  88. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
  89. package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
  90. package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
  91. package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
  92. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
  93. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
  94. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
  95. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +150 -0
  96. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
  97. package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
  98. package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
  99. package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
  100. package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
  101. package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
  102. package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
  103. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
  104. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
  105. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
  106. package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
  107. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
  108. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
  109. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
  110. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
  111. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
  112. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
  113. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
  114. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
  115. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
  116. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
  117. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
  118. package/dist/instrumentation/ai21/index.d.ts +11 -0
  119. package/dist/instrumentation/ai21/index.js +67 -0
  120. package/dist/instrumentation/ai21/index.js.map +1 -0
  121. package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
  122. package/dist/instrumentation/ai21/wrapper.js +511 -0
  123. package/dist/instrumentation/ai21/wrapper.js.map +1 -0
  124. package/dist/instrumentation/anthropic/wrapper.js +56 -2
  125. package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
  126. package/dist/instrumentation/assemblyai/index.d.ts +12 -0
  127. package/dist/instrumentation/assemblyai/index.js +91 -0
  128. package/dist/instrumentation/assemblyai/index.js.map +1 -0
  129. package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
  130. package/dist/instrumentation/assemblyai/wrapper.js +233 -0
  131. package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
  132. package/dist/instrumentation/astra/index.d.ts +11 -0
  133. package/dist/instrumentation/astra/index.js +87 -0
  134. package/dist/instrumentation/astra/index.js.map +1 -0
  135. package/dist/instrumentation/astra/wrapper.d.ts +39 -0
  136. package/dist/instrumentation/astra/wrapper.js +349 -0
  137. package/dist/instrumentation/astra/wrapper.js.map +1 -0
  138. package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +13 -0
  139. package/dist/instrumentation/azure-ai-inference/wrapper.js +60 -1
  140. package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -1
  141. package/dist/instrumentation/bedrock/wrapper.d.ts +13 -0
  142. package/dist/instrumentation/bedrock/wrapper.js +78 -2
  143. package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
  144. package/dist/instrumentation/browser-use/index.d.ts +11 -0
  145. package/dist/instrumentation/browser-use/index.js +98 -0
  146. package/dist/instrumentation/browser-use/index.js.map +1 -0
  147. package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
  148. package/dist/instrumentation/browser-use/wrapper.js +706 -0
  149. package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
  150. package/dist/instrumentation/claude-agent-sdk/wrapper.js +90 -4
  151. package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -1
  152. package/dist/instrumentation/cohere/wrapper.d.ts +13 -0
  153. package/dist/instrumentation/cohere/wrapper.js +59 -0
  154. package/dist/instrumentation/cohere/wrapper.js.map +1 -1
  155. package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
  156. package/dist/instrumentation/cursor-sdk/index.js +58 -0
  157. package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
  158. package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
  159. package/dist/instrumentation/cursor-sdk/wrapper.js +785 -0
  160. package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
  161. package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
  162. package/dist/instrumentation/elevenlabs/index.js +92 -0
  163. package/dist/instrumentation/elevenlabs/index.js.map +1 -0
  164. package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
  165. package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
  166. package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
  167. package/dist/instrumentation/firecrawl/index.d.ts +13 -0
  168. package/dist/instrumentation/firecrawl/index.js +115 -0
  169. package/dist/instrumentation/firecrawl/index.js.map +1 -0
  170. package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
  171. package/dist/instrumentation/firecrawl/wrapper.js +378 -0
  172. package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
  173. package/dist/instrumentation/google-ai/wrapper.d.ts +13 -0
  174. package/dist/instrumentation/google-ai/wrapper.js +85 -1
  175. package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
  176. package/dist/instrumentation/gpu/index.d.ts +38 -0
  177. package/dist/instrumentation/gpu/index.js +233 -0
  178. package/dist/instrumentation/gpu/index.js.map +1 -0
  179. package/dist/instrumentation/gradient/index.d.ts +12 -0
  180. package/dist/instrumentation/gradient/index.js +74 -0
  181. package/dist/instrumentation/gradient/index.js.map +1 -0
  182. package/dist/instrumentation/gradient/utils.d.ts +14 -0
  183. package/dist/instrumentation/gradient/utils.js +119 -0
  184. package/dist/instrumentation/gradient/utils.js.map +1 -0
  185. package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
  186. package/dist/instrumentation/gradient/wrapper.js +584 -0
  187. package/dist/instrumentation/gradient/wrapper.js.map +1 -0
  188. package/dist/instrumentation/groq/wrapper.js +42 -0
  189. package/dist/instrumentation/groq/wrapper.js.map +1 -1
  190. package/dist/instrumentation/huggingface/wrapper.d.ts +13 -0
  191. package/dist/instrumentation/huggingface/wrapper.js +66 -0
  192. package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
  193. package/dist/instrumentation/index.js +28 -0
  194. package/dist/instrumentation/index.js.map +1 -1
  195. package/dist/instrumentation/langchain/wrapper.js +5 -8
  196. package/dist/instrumentation/langchain/wrapper.js.map +1 -1
  197. package/dist/instrumentation/langgraph/wrapper.js +12 -11
  198. package/dist/instrumentation/langgraph/wrapper.js.map +1 -1
  199. package/dist/instrumentation/llamaindex/wrapper.d.ts +14 -1
  200. package/dist/instrumentation/llamaindex/wrapper.js +68 -0
  201. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
  202. package/dist/instrumentation/mcp/index.d.ts +20 -0
  203. package/dist/instrumentation/mcp/index.js +282 -0
  204. package/dist/instrumentation/mcp/index.js.map +1 -0
  205. package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
  206. package/dist/instrumentation/mcp/wrapper.js +571 -0
  207. package/dist/instrumentation/mcp/wrapper.js.map +1 -0
  208. package/dist/instrumentation/mem0/index.d.ts +17 -0
  209. package/dist/instrumentation/mem0/index.js +113 -0
  210. package/dist/instrumentation/mem0/index.js.map +1 -0
  211. package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
  212. package/dist/instrumentation/mem0/wrapper.js +298 -0
  213. package/dist/instrumentation/mem0/wrapper.js.map +1 -0
  214. package/dist/instrumentation/mistral/wrapper.d.ts +13 -0
  215. package/dist/instrumentation/mistral/wrapper.js +60 -1
  216. package/dist/instrumentation/mistral/wrapper.js.map +1 -1
  217. package/dist/instrumentation/ollama/wrapper.d.ts +13 -0
  218. package/dist/instrumentation/ollama/wrapper.js +67 -1
  219. package/dist/instrumentation/ollama/wrapper.js.map +1 -1
  220. package/dist/instrumentation/openai/wrapper.d.ts +13 -0
  221. package/dist/instrumentation/openai/wrapper.js +89 -3
  222. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  223. package/dist/instrumentation/pg/index.d.ts +20 -0
  224. package/dist/instrumentation/pg/index.js +74 -0
  225. package/dist/instrumentation/pg/index.js.map +1 -0
  226. package/dist/instrumentation/pg/wrapper.d.ts +66 -0
  227. package/dist/instrumentation/pg/wrapper.js +441 -0
  228. package/dist/instrumentation/pg/wrapper.js.map +1 -0
  229. package/dist/instrumentation/replicate/wrapper.d.ts +13 -0
  230. package/dist/instrumentation/replicate/wrapper.js +61 -0
  231. package/dist/instrumentation/replicate/wrapper.js.map +1 -1
  232. package/dist/instrumentation/strands/processor.d.ts +6 -0
  233. package/dist/instrumentation/strands/processor.js +73 -3
  234. package/dist/instrumentation/strands/processor.js.map +1 -1
  235. package/dist/instrumentation/strands/utils.d.ts +2 -2
  236. package/dist/instrumentation/strands/utils.js +15 -2
  237. package/dist/instrumentation/strands/utils.js.map +1 -1
  238. package/dist/instrumentation/together/wrapper.d.ts +13 -0
  239. package/dist/instrumentation/together/wrapper.js +59 -1
  240. package/dist/instrumentation/together/wrapper.js.map +1 -1
  241. package/dist/instrumentation/transformers/index.d.ts +35 -0
  242. package/dist/instrumentation/transformers/index.js +119 -0
  243. package/dist/instrumentation/transformers/index.js.map +1 -0
  244. package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
  245. package/dist/instrumentation/transformers/wrapper.js +472 -0
  246. package/dist/instrumentation/transformers/wrapper.js.map +1 -0
  247. package/dist/instrumentation/vercel-ai/wrapper.d.ts +13 -0
  248. package/dist/instrumentation/vercel-ai/wrapper.js +106 -1
  249. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
  250. package/dist/instrumentation/vertexai/index.d.ts +11 -0
  251. package/dist/instrumentation/vertexai/index.js +70 -0
  252. package/dist/instrumentation/vertexai/index.js.map +1 -0
  253. package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
  254. package/dist/instrumentation/vertexai/wrapper.js +529 -0
  255. package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
  256. package/dist/instrumentation/vllm/index.d.ts +13 -0
  257. package/dist/instrumentation/vllm/index.js +67 -0
  258. package/dist/instrumentation/vllm/index.js.map +1 -0
  259. package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
  260. package/dist/instrumentation/vllm/wrapper.js +482 -0
  261. package/dist/instrumentation/vllm/wrapper.js.map +1 -0
  262. package/dist/llm/index.d.ts +9 -2
  263. package/dist/llm/index.js.map +1 -1
  264. package/dist/manual-trace.d.ts +40 -0
  265. package/dist/manual-trace.js +103 -0
  266. package/dist/manual-trace.js.map +1 -0
  267. package/dist/otel/metrics.d.ts +11 -0
  268. package/dist/otel/metrics.js +48 -0
  269. package/dist/otel/metrics.js.map +1 -1
  270. package/dist/register.d.ts +4 -0
  271. package/dist/register.js +52 -0
  272. package/dist/register.js.map +1 -0
  273. package/dist/score/__tests__/score.test.d.ts +1 -0
  274. package/dist/score/__tests__/score.test.js +143 -0
  275. package/dist/score/__tests__/score.test.js.map +1 -0
  276. package/dist/score/index.d.ts +2 -0
  277. package/dist/score/index.js +6 -0
  278. package/dist/score/index.js.map +1 -0
  279. package/dist/score/score.d.ts +15 -0
  280. package/dist/score/score.js +135 -0
  281. package/dist/score/score.js.map +1 -0
  282. package/dist/semantic-convention.d.ts +278 -0
  283. package/dist/semantic-convention.js +322 -0
  284. package/dist/semantic-convention.js.map +1 -1
  285. package/dist/types.d.ts +15 -1
  286. package/package.json +18 -1
  287. package/dist/evals/__tests__/anthropic.test.js +0 -9
  288. package/dist/evals/__tests__/anthropic.test.js.map +0 -1
  289. package/dist/evals/__tests__/base.test.js +0 -37
  290. package/dist/evals/__tests__/base.test.js.map +0 -1
  291. package/dist/evals/__tests__/core.test.js +0 -33
  292. package/dist/evals/__tests__/core.test.js.map +0 -1
  293. package/dist/evals/__tests__/metrics.test.js +0 -59
  294. package/dist/evals/__tests__/metrics.test.js.map +0 -1
  295. package/dist/evals/__tests__/openai.test.js +0 -9
  296. package/dist/evals/__tests__/openai.test.js.map +0 -1
  297. package/dist/evals/__tests__/providers.test.js +0 -14
  298. package/dist/evals/__tests__/providers.test.js.map +0 -1
  299. package/dist/evals/__tests__/utils.test.js +0 -46
  300. package/dist/evals/__tests__/utils.test.js.map +0 -1
  301. package/dist/evals/all.d.ts +0 -4
  302. package/dist/evals/all.js +0 -35
  303. package/dist/evals/all.js.map +0 -1
  304. package/dist/evals/base.d.ts +0 -15
  305. package/dist/evals/base.js +0 -51
  306. package/dist/evals/base.js.map +0 -1
  307. package/dist/evals/bias.d.ts +0 -4
  308. package/dist/evals/bias.js +0 -35
  309. package/dist/evals/bias.js.map +0 -1
  310. package/dist/evals/hallucination.d.ts +0 -4
  311. package/dist/evals/hallucination.js +0 -32
  312. package/dist/evals/hallucination.js.map +0 -1
  313. package/dist/evals/llm/anthropic.d.ts +0 -5
  314. package/dist/evals/llm/anthropic.js +0 -42
  315. package/dist/evals/llm/anthropic.js.map +0 -1
  316. package/dist/evals/llm/openai.d.ts +0 -6
  317. package/dist/evals/llm/openai.js +0 -28
  318. package/dist/evals/llm/openai.js.map +0 -1
  319. package/dist/evals/llm/providers.d.ts +0 -7
  320. package/dist/evals/llm/providers.js +0 -10
  321. package/dist/evals/llm/providers.js.map +0 -1
  322. package/dist/evals/metrics.d.ts +0 -9
  323. package/dist/evals/metrics.js +0 -38
  324. package/dist/evals/metrics.js.map +0 -1
  325. package/dist/evals/toxicity.d.ts +0 -4
  326. package/dist/evals/toxicity.js +0 -33
  327. package/dist/evals/toxicity.js.map +0 -1
  328. package/dist/evals/utils.d.ts +0 -4
  329. package/dist/evals/utils.js +0 -39
  330. package/dist/evals/utils.js.map +0 -1
  331. package/dist/guard/__tests__/gaurd.test.js +0 -136
  332. package/dist/guard/__tests__/gaurd.test.js.map +0 -1
  333. package/dist/guard/__tests__/utils.test.js +0 -64
  334. package/dist/guard/__tests__/utils.test.js.map +0 -1
  335. package/dist/guard/all.d.ts +0 -8
  336. package/dist/guard/all.js +0 -28
  337. package/dist/guard/all.js.map +0 -1
  338. package/dist/guard/types.d.ts +0 -26
  339. package/dist/guard/types.js +0 -4
  340. package/dist/guard/types.js.map +0 -1
  341. package/dist/guard/utils.d.ts +0 -13
  342. package/dist/guard/utils.js +0 -79
  343. package/dist/guard/utils.js.map +0 -1
  344. /package/dist/{evals/__tests__/anthropic.test.d.ts → __tests__/manual-trace.test.d.ts} +0 -0
  345. /package/dist/{evals/__tests__/metrics.test.d.ts → __tests__/register.test.d.ts} +0 -0
  346. /package/dist/evals/__tests__/{base.test.d.ts → offline.test.d.ts} +0 -0
  347. /package/dist/{evals/__tests__/core.test.d.ts → guard/__tests__/integration.test.d.ts} +0 -0
  348. /package/dist/{evals/__tests__/openai.test.d.ts → guard/__tests__/pii.test.d.ts} +0 -0
  349. /package/dist/{evals/__tests__/providers.test.d.ts → guard/__tests__/pipeline.test.d.ts} +0 -0
  350. /package/dist/{evals/__tests__/utils.test.d.ts → guard/__tests__/prompt-injection.test.d.ts} +0 -0
  351. /package/dist/{guard/__tests__/gaurd.test.d.ts → instrumentation/__tests__/assemblyai-wrapper.test.d.ts} +0 -0
  352. /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