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,76 @@
1
+ import { Span, Tracer } from '@opentelemetry/api';
2
+ import BaseWrapper from '../base-wrapper';
3
+ import { GradientEndpointKind } from './utils';
4
+ type ChatPatchOptions = {
5
+ operationName: string;
6
+ endpointKind: GradientEndpointKind;
7
+ genAIEndpoint: string;
8
+ apiType: string;
9
+ isAgent?: boolean;
10
+ };
11
+ declare class GradientWrapper extends BaseWrapper {
12
+ static aiSystem: string;
13
+ static _patchChatCompletionCreate(tracer: Tracer): any;
14
+ static _patchAgentChatCompletionCreate(tracer: Tracer): any;
15
+ static _buildChatPatch(tracer: Tracer, options: ChatPatchOptions): any;
16
+ static _patchImageGenerate(tracer: Tracer): any;
17
+ static _chatCompletion({ args, genAIEndpoint, response, span, serverAddress, serverPort, operationName, apiType, }: {
18
+ args: any[];
19
+ genAIEndpoint: string;
20
+ response: any;
21
+ span: Span;
22
+ serverAddress: string;
23
+ serverPort: number;
24
+ operationName: string;
25
+ apiType: string;
26
+ }): Promise<any>;
27
+ static _chatCompletionGenerator({ args, genAIEndpoint, response, span, serverAddress, serverPort, operationName, apiType, }: {
28
+ args: any[];
29
+ genAIEndpoint: string;
30
+ response: any;
31
+ span: Span;
32
+ serverAddress: string;
33
+ serverPort: number;
34
+ operationName: string;
35
+ apiType: string;
36
+ }): AsyncGenerator<unknown, any, unknown>;
37
+ static _imageGenerateCommonSetter({ args, genAIEndpoint, response, span, serverAddress, serverPort, }: {
38
+ args: any[];
39
+ genAIEndpoint: string;
40
+ response: any;
41
+ span: Span;
42
+ serverAddress: string;
43
+ serverPort: number;
44
+ }): {
45
+ genAIEndpoint: string;
46
+ model: any;
47
+ user: any;
48
+ cost: number;
49
+ aiSystem: string;
50
+ serverAddress: string;
51
+ serverPort: number;
52
+ };
53
+ static _chatCompletionCommonSetter({ args, genAIEndpoint, result, span, ttft, tbt, serverAddress, serverPort, operationName, apiType, reasoningText, }: {
54
+ args: any[];
55
+ genAIEndpoint: string;
56
+ result: any;
57
+ span: Span;
58
+ ttft?: number;
59
+ tbt?: number;
60
+ serverAddress: string;
61
+ serverPort: number;
62
+ operationName?: string;
63
+ apiType?: string;
64
+ reasoningText?: string;
65
+ }): Promise<{
66
+ genAIEndpoint: string;
67
+ model: any;
68
+ user: any;
69
+ cost: number;
70
+ aiSystem: string;
71
+ serverAddress: string;
72
+ serverPort: number;
73
+ }>;
74
+ static _buildOutputMessages(text: string, finishReason: string, toolCalls?: any[], reasoning?: string): string;
75
+ }
76
+ export default GradientWrapper;
@@ -0,0 +1,584 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const api_1 = require("@opentelemetry/api");
40
+ const config_1 = __importDefault(require("../../config"));
41
+ const helpers_1 = __importStar(require("../../helpers"));
42
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
43
+ const base_wrapper_1 = __importDefault(require("../base-wrapper"));
44
+ const utils_1 = require("./utils");
45
+ const AI_SYSTEM = semantic_convention_1.default.GEN_AI_SYSTEM_DIGITALOCEAN;
46
+ class GradientWrapper extends base_wrapper_1.default {
47
+ static _patchChatCompletionCreate(tracer) {
48
+ return GradientWrapper._buildChatPatch(tracer, {
49
+ operationName: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
50
+ endpointKind: 'inference',
51
+ genAIEndpoint: 'digitalocean.chat.completions',
52
+ apiType: 'chat',
53
+ });
54
+ }
55
+ static _patchAgentChatCompletionCreate(tracer) {
56
+ return GradientWrapper._buildChatPatch(tracer, {
57
+ operationName: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
58
+ endpointKind: 'agent',
59
+ genAIEndpoint: 'digitalocean.agents.chat.completions',
60
+ apiType: 'chat',
61
+ isAgent: true,
62
+ });
63
+ }
64
+ static _buildChatPatch(tracer, options) {
65
+ const { operationName, endpointKind, genAIEndpoint, apiType, isAgent = false } = options;
66
+ return (originalMethod) => {
67
+ return async function (...args) {
68
+ if ((0, helpers_1.isFrameworkLlmActive)())
69
+ return originalMethod.apply(this, args);
70
+ const body = args[0] || {};
71
+ const requestModel = body.model || 'unknown';
72
+ const [serverAddress, serverPort] = (0, utils_1.resolveGradientEndpoint)(this, endpointKind);
73
+ const spanName = `${operationName} ${requestModel}`;
74
+ const effectiveCtx = (0, helpers_1.getFrameworkParentContext)() ?? api_1.context.active();
75
+ const span = tracer.startSpan(spanName, {
76
+ kind: api_1.SpanKind.CLIENT,
77
+ attributes: (0, utils_1.gradientSpanCreationAttrs)(operationName, requestModel, serverAddress, serverPort),
78
+ }, effectiveCtx);
79
+ if (isAgent) {
80
+ const agentId = (0, utils_1.agentIdFromHost)(serverAddress);
81
+ if (agentId) {
82
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ID, agentId);
83
+ }
84
+ }
85
+ return api_1.context
86
+ .with(api_1.trace.setSpan(effectiveCtx, span), async () => originalMethod.apply(this, args))
87
+ .then((response) => {
88
+ if (body.stream) {
89
+ return helpers_1.default.createStreamProxy(response, GradientWrapper._chatCompletionGenerator({
90
+ args,
91
+ genAIEndpoint,
92
+ response,
93
+ span,
94
+ serverAddress,
95
+ serverPort,
96
+ operationName,
97
+ apiType,
98
+ }));
99
+ }
100
+ return GradientWrapper._chatCompletion({
101
+ args,
102
+ genAIEndpoint,
103
+ response,
104
+ span,
105
+ serverAddress,
106
+ serverPort,
107
+ operationName,
108
+ apiType,
109
+ });
110
+ })
111
+ .catch((e) => {
112
+ helpers_1.default.handleException(span, e);
113
+ base_wrapper_1.default.recordMetrics(span, {
114
+ genAIEndpoint,
115
+ model: requestModel,
116
+ aiSystem: AI_SYSTEM,
117
+ serverAddress,
118
+ serverPort,
119
+ errorType: e?.constructor?.name || '_OTHER',
120
+ });
121
+ span.end();
122
+ throw e;
123
+ });
124
+ };
125
+ };
126
+ }
127
+ static _patchImageGenerate(tracer) {
128
+ const genAIEndpoint = 'digitalocean.images.generate';
129
+ return (originalMethod) => {
130
+ return async function (...args) {
131
+ if ((0, helpers_1.isFrameworkLlmActive)())
132
+ return originalMethod.apply(this, args);
133
+ const body = args[0] || {};
134
+ const requestModel = body.model || 'unknown';
135
+ const [serverAddress, serverPort] = (0, utils_1.resolveGradientEndpoint)(this, 'inference');
136
+ const spanName = `${semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT} ${requestModel}`;
137
+ const effectiveCtx = (0, helpers_1.getFrameworkParentContext)() ?? api_1.context.active();
138
+ const span = tracer.startSpan(spanName, {
139
+ kind: api_1.SpanKind.CLIENT,
140
+ attributes: (0, utils_1.gradientSpanCreationAttrs)(semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT, requestModel, serverAddress, serverPort),
141
+ }, effectiveCtx);
142
+ return api_1.context.with(api_1.trace.setSpan(effectiveCtx, span), async () => {
143
+ let metricParams;
144
+ try {
145
+ const response = await originalMethod.apply(this, args);
146
+ metricParams = GradientWrapper._imageGenerateCommonSetter({
147
+ args,
148
+ genAIEndpoint,
149
+ response,
150
+ span,
151
+ serverAddress,
152
+ serverPort,
153
+ });
154
+ return response;
155
+ }
156
+ catch (e) {
157
+ helpers_1.default.handleException(span, e);
158
+ base_wrapper_1.default.recordMetrics(span, {
159
+ genAIEndpoint,
160
+ model: requestModel,
161
+ aiSystem: AI_SYSTEM,
162
+ serverAddress,
163
+ serverPort,
164
+ errorType: e?.constructor?.name || '_OTHER',
165
+ });
166
+ throw e;
167
+ }
168
+ finally {
169
+ span.end();
170
+ if (metricParams) {
171
+ base_wrapper_1.default.recordMetrics(span, metricParams);
172
+ }
173
+ }
174
+ });
175
+ };
176
+ };
177
+ }
178
+ static async _chatCompletion({ args, genAIEndpoint, response, span, serverAddress, serverPort, operationName, apiType, }) {
179
+ let metricParams;
180
+ try {
181
+ metricParams = await GradientWrapper._chatCompletionCommonSetter({
182
+ args,
183
+ genAIEndpoint,
184
+ result: response,
185
+ span,
186
+ serverAddress,
187
+ serverPort,
188
+ operationName,
189
+ apiType,
190
+ });
191
+ return response;
192
+ }
193
+ catch (e) {
194
+ helpers_1.default.handleException(span, e);
195
+ throw e;
196
+ }
197
+ finally {
198
+ span.end();
199
+ if (metricParams) {
200
+ base_wrapper_1.default.recordMetrics(span, metricParams);
201
+ }
202
+ }
203
+ }
204
+ static async *_chatCompletionGenerator({ args, genAIEndpoint, response, span, serverAddress, serverPort, operationName, apiType, }) {
205
+ let metricParams;
206
+ const timestamps = [];
207
+ const startTime = Date.now();
208
+ try {
209
+ const { messages } = args[0];
210
+ let { tools } = args[0];
211
+ const result = {
212
+ id: '0',
213
+ created: -1,
214
+ model: '',
215
+ system_fingerprint: '',
216
+ choices: [
217
+ {
218
+ index: 0,
219
+ logprobs: null,
220
+ finish_reason: 'stop',
221
+ message: { role: 'assistant', content: '', reasoning_content: '' },
222
+ },
223
+ ],
224
+ usage: {
225
+ prompt_tokens: 0,
226
+ completion_tokens: 0,
227
+ total_tokens: 0,
228
+ output_tokens_details: { reasoning_tokens: 0 },
229
+ },
230
+ };
231
+ const toolCalls = [];
232
+ let reasoningText = '';
233
+ for await (const chunk of response) {
234
+ timestamps.push(Date.now());
235
+ if (chunk.id)
236
+ result.id = chunk.id;
237
+ if (chunk.created)
238
+ result.created = chunk.created;
239
+ if (chunk.model)
240
+ result.model = chunk.model;
241
+ if (chunk.system_fingerprint)
242
+ result.system_fingerprint = chunk.system_fingerprint;
243
+ if (chunk.choices?.[0]?.finish_reason) {
244
+ result.choices[0].finish_reason = chunk.choices[0].finish_reason;
245
+ }
246
+ if (chunk.choices?.[0]?.logprobs) {
247
+ result.choices[0].logprobs = chunk.choices[0].logprobs;
248
+ }
249
+ if (chunk.choices?.[0]?.delta?.content) {
250
+ result.choices[0].message.content += chunk.choices[0].delta.content;
251
+ }
252
+ if (chunk.choices?.[0]?.delta?.reasoning_content) {
253
+ reasoningText += chunk.choices[0].delta.reasoning_content;
254
+ result.choices[0].message.reasoning_content = reasoningText;
255
+ }
256
+ if (chunk.choices?.[0]?.delta?.tool_calls) {
257
+ const deltaTools = chunk.choices[0].delta.tool_calls;
258
+ for (const tool of deltaTools) {
259
+ const idx = tool.index || 0;
260
+ while (toolCalls.length <= idx) {
261
+ toolCalls.push({
262
+ id: '',
263
+ type: 'function',
264
+ function: { name: '', arguments: '' },
265
+ });
266
+ }
267
+ if (tool.id) {
268
+ toolCalls[idx].id = tool.id;
269
+ toolCalls[idx].type = tool.type || 'function';
270
+ if (tool.function?.name)
271
+ toolCalls[idx].function.name = tool.function.name;
272
+ if (tool.function?.arguments)
273
+ toolCalls[idx].function.arguments = tool.function.arguments;
274
+ }
275
+ else if (tool.function?.arguments) {
276
+ toolCalls[idx].function.arguments += tool.function.arguments;
277
+ }
278
+ }
279
+ tools = true;
280
+ }
281
+ if (chunk.usage) {
282
+ result.usage.prompt_tokens = chunk.usage.prompt_tokens || 0;
283
+ result.usage.completion_tokens = chunk.usage.completion_tokens || 0;
284
+ result.usage.total_tokens = chunk.usage.total_tokens || 0;
285
+ const details = chunk.usage.output_tokens_details || chunk.usage.completion_tokens_details;
286
+ if (details?.reasoning_tokens) {
287
+ result.usage.output_tokens_details.reasoning_tokens = details.reasoning_tokens;
288
+ }
289
+ }
290
+ yield chunk;
291
+ }
292
+ if (toolCalls.length > 0) {
293
+ result.choices[0].message = {
294
+ ...result.choices[0].message,
295
+ tool_calls: toolCalls,
296
+ };
297
+ }
298
+ if (!result.usage.prompt_tokens && !result.usage.completion_tokens) {
299
+ let promptTokens = 0;
300
+ for (const message of messages || []) {
301
+ promptTokens += helpers_1.default.openaiTokens(message.content, result.model) ?? 0;
302
+ }
303
+ const completionTokens = helpers_1.default.openaiTokens(result.choices[0].message.content ?? '', result.model);
304
+ if (completionTokens) {
305
+ result.usage = {
306
+ ...result.usage,
307
+ prompt_tokens: promptTokens,
308
+ completion_tokens: completionTokens,
309
+ total_tokens: promptTokens + completionTokens,
310
+ };
311
+ }
312
+ }
313
+ args[0].tools = tools;
314
+ const ttft = timestamps.length > 0 ? (timestamps[0] - startTime) / 1000 : 0;
315
+ let tbt = 0;
316
+ if (timestamps.length > 1) {
317
+ const timeDiffs = timestamps.slice(1).map((t, i) => t - timestamps[i]);
318
+ tbt = timeDiffs.reduce((a, b) => a + b, 0) / timeDiffs.length / 1000;
319
+ }
320
+ metricParams = await GradientWrapper._chatCompletionCommonSetter({
321
+ args,
322
+ genAIEndpoint,
323
+ result,
324
+ span,
325
+ ttft,
326
+ tbt,
327
+ serverAddress,
328
+ serverPort,
329
+ operationName,
330
+ apiType,
331
+ reasoningText,
332
+ });
333
+ return result;
334
+ }
335
+ catch (e) {
336
+ helpers_1.default.handleException(span, e);
337
+ throw e;
338
+ }
339
+ finally {
340
+ span.end();
341
+ if (metricParams) {
342
+ base_wrapper_1.default.recordMetrics(span, metricParams);
343
+ }
344
+ }
345
+ }
346
+ static _imageGenerateCommonSetter({ args, genAIEndpoint, response, span, serverAddress, serverPort, }) {
347
+ const captureContent = config_1.default.captureMessageContent;
348
+ const body = args[0] || {};
349
+ const requestModel = body.model || 'unknown';
350
+ const responseModel = response?.model || requestModel;
351
+ const size = body.size || response?.size || '1024x1024';
352
+ const quality = body.quality || response?.quality || 'standard';
353
+ const pricingInfo = config_1.default.pricingInfo || {};
354
+ const cost = helpers_1.default.getImageModelCost(requestModel, pricingInfo, size, quality);
355
+ GradientWrapper.setBaseSpanAttributes(span, {
356
+ genAIEndpoint,
357
+ model: requestModel,
358
+ user: body.user,
359
+ cost,
360
+ aiSystem: AI_SYSTEM,
361
+ serverAddress,
362
+ serverPort,
363
+ });
364
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, 'image');
365
+ if (response?.created != null) {
366
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_ID, String(response.created));
367
+ }
368
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, responseModel);
369
+ if (captureContent && body.prompt) {
370
+ span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, JSON.stringify([
371
+ {
372
+ role: 'user',
373
+ parts: [{ type: 'text', content: String(body.prompt) }],
374
+ },
375
+ ]));
376
+ }
377
+ return {
378
+ genAIEndpoint,
379
+ model: requestModel,
380
+ user: body.user,
381
+ cost,
382
+ aiSystem: AI_SYSTEM,
383
+ serverAddress,
384
+ serverPort,
385
+ };
386
+ }
387
+ static async _chatCompletionCommonSetter({ args, genAIEndpoint, result, span, ttft = 0, tbt = 0, serverAddress, serverPort, operationName = semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT, apiType = 'chat', reasoningText, }) {
388
+ const captureContent = config_1.default.captureMessageContent;
389
+ const body = args[0] || {};
390
+ const requestModel = body.model || 'unknown';
391
+ const { messages, tools: _tools, stream: _stream = false } = body;
392
+ (0, utils_1.applyGradientChatRequestAttributes)(span, body);
393
+ span.setAttribute(semantic_convention_1.default.OPENAI_API_TYPE, apiType);
394
+ if (captureContent) {
395
+ span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages(messages || []));
396
+ }
397
+ if (result.id) {
398
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_ID, result.id);
399
+ }
400
+ const responseModel = result.model || requestModel;
401
+ const usage = result.usage || { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 };
402
+ const pricingInfo = config_1.default.pricingInfo || {};
403
+ const cost = helpers_1.default.getChatModelCost(requestModel, pricingInfo, usage.prompt_tokens, usage.completion_tokens);
404
+ GradientWrapper.setBaseSpanAttributes(span, {
405
+ genAIEndpoint,
406
+ model: requestModel,
407
+ user: body.user,
408
+ cost,
409
+ aiSystem: AI_SYSTEM,
410
+ serverAddress,
411
+ serverPort,
412
+ });
413
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, responseModel);
414
+ if (result.system_fingerprint) {
415
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT, result.system_fingerprint);
416
+ }
417
+ const inputTokens = usage.prompt_tokens || 0;
418
+ const outputTokens = usage.completion_tokens || 0;
419
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
420
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
421
+ span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_TOKEN_USAGE, inputTokens + outputTokens);
422
+ const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ??
423
+ usage.completion_tokens_details?.reasoning_tokens ??
424
+ 0;
425
+ if (reasoningTokens) {
426
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_REASONING_TOKENS, reasoningTokens);
427
+ }
428
+ if (ttft > 0) {
429
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TTFT, ttft);
430
+ }
431
+ if (tbt > 0) {
432
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SERVER_TBT, tbt);
433
+ }
434
+ if (result.choices?.[0]?.finish_reason) {
435
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, [
436
+ result.choices[0].finish_reason,
437
+ ]);
438
+ }
439
+ const outputType = body.response_format?.type === 'json_object'
440
+ ? semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_JSON
441
+ : semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT;
442
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, outputType);
443
+ const message = result.choices?.[0]?.message || {};
444
+ const resolvedReasoning = reasoningText ||
445
+ message.reasoning_content ||
446
+ '';
447
+ if (message.tool_calls) {
448
+ const toolCalls = message.tool_calls;
449
+ const toolNames = toolCalls.map((t) => t.function?.name || '').filter(Boolean);
450
+ const toolIds = toolCalls.map((t) => t.id || '').filter(Boolean);
451
+ const toolArgs = toolCalls.map((t) => t.function?.arguments || '').filter(Boolean);
452
+ if (toolNames.length > 0) {
453
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_NAME, toolNames.join(', '));
454
+ }
455
+ if (toolIds.length > 0) {
456
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, toolIds.join(', '));
457
+ }
458
+ if (toolArgs.length > 0) {
459
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_ARGS, toolArgs.join(', '));
460
+ }
461
+ }
462
+ let inputMessagesJson;
463
+ let outputMessagesJson;
464
+ const toolDefinitionsJson = helpers_1.default.buildToolDefinitions(_tools);
465
+ const systemInstructionsJson = helpers_1.default.buildSystemInstructionsFromMessages(messages || []);
466
+ const versionExtras = {};
467
+ try {
468
+ const maxTokens = body.max_completion_tokens ?? body.max_tokens ?? null;
469
+ const versionHash = helpers_1.default.computeAgentVersionHash({
470
+ systemInstructions: systemInstructionsJson ?? null,
471
+ toolDefinitions: toolDefinitionsJson ?? null,
472
+ primaryModel: responseModel || requestModel,
473
+ runtimeConfig: {
474
+ temperature: body.temperature ?? null,
475
+ top_p: body.top_p ?? null,
476
+ max_tokens: maxTokens,
477
+ provider: AI_SYSTEM,
478
+ },
479
+ providers: [AI_SYSTEM],
480
+ });
481
+ if (versionHash) {
482
+ versionExtras[semantic_convention_1.default.OPENLIT_AGENT_VERSION_HASH] = versionHash;
483
+ span.setAttribute(semantic_convention_1.default.OPENLIT_AGENT_VERSION_HASH, versionHash);
484
+ }
485
+ }
486
+ catch {
487
+ // Never fail the wrapped call on hash issues.
488
+ }
489
+ const versionLabel = (0, helpers_1.getCurrentAgentVersion)();
490
+ if (versionLabel) {
491
+ versionExtras[semantic_convention_1.default.GEN_AI_AGENT_VERSION] = versionLabel;
492
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_VERSION, versionLabel);
493
+ }
494
+ if (captureContent) {
495
+ const toolCalls = message.tool_calls;
496
+ outputMessagesJson = GradientWrapper._buildOutputMessages(message.content || '', result.choices?.[0]?.finish_reason || 'stop', toolCalls, resolvedReasoning || undefined);
497
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, outputMessagesJson);
498
+ inputMessagesJson = helpers_1.default.buildInputMessages(messages || []);
499
+ if (systemInstructionsJson) {
500
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, systemInstructionsJson);
501
+ }
502
+ }
503
+ if (toolDefinitionsJson) {
504
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, toolDefinitionsJson);
505
+ }
506
+ if (!config_1.default.disableEvents) {
507
+ const eventAttrs = {
508
+ [semantic_convention_1.default.GEN_AI_OPERATION]: operationName,
509
+ [semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
510
+ [semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: responseModel,
511
+ [semantic_convention_1.default.SERVER_ADDRESS]: serverAddress,
512
+ [semantic_convention_1.default.SERVER_PORT]: serverPort,
513
+ [semantic_convention_1.default.GEN_AI_RESPONSE_ID]: result.id,
514
+ [semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: [result.choices?.[0]?.finish_reason],
515
+ [semantic_convention_1.default.GEN_AI_OUTPUT_TYPE]: outputType,
516
+ [semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: inputTokens,
517
+ [semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: outputTokens,
518
+ ...versionExtras,
519
+ };
520
+ if (captureContent) {
521
+ if (inputMessagesJson)
522
+ eventAttrs[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES] = inputMessagesJson;
523
+ if (systemInstructionsJson) {
524
+ eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS] = systemInstructionsJson;
525
+ }
526
+ if (outputMessagesJson) {
527
+ eventAttrs[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES] = outputMessagesJson;
528
+ }
529
+ }
530
+ if (toolDefinitionsJson) {
531
+ eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS] = toolDefinitionsJson;
532
+ }
533
+ helpers_1.default.emitInferenceEvent(span, eventAttrs);
534
+ }
535
+ return {
536
+ genAIEndpoint,
537
+ model: requestModel,
538
+ user: body.user,
539
+ cost,
540
+ aiSystem: AI_SYSTEM,
541
+ serverAddress,
542
+ serverPort,
543
+ };
544
+ }
545
+ static _buildOutputMessages(text, finishReason, toolCalls, reasoning) {
546
+ try {
547
+ const parts = [];
548
+ if (reasoning) {
549
+ parts.push({ type: 'reasoning', content: reasoning });
550
+ }
551
+ if (text) {
552
+ parts.push({ type: 'text', content: text });
553
+ }
554
+ if (toolCalls?.length) {
555
+ for (const tc of toolCalls) {
556
+ let argsVal = tc.function?.arguments || tc.arguments || {};
557
+ if (typeof argsVal === 'string') {
558
+ try {
559
+ argsVal = JSON.parse(argsVal);
560
+ }
561
+ catch {
562
+ argsVal = { raw: argsVal };
563
+ }
564
+ }
565
+ parts.push({
566
+ type: 'tool_call',
567
+ id: tc.id || '',
568
+ name: tc.function?.name || tc.name || '',
569
+ arguments: argsVal,
570
+ });
571
+ }
572
+ }
573
+ return JSON.stringify([
574
+ { role: 'assistant', parts, finish_reason: finishReason || 'stop' },
575
+ ]);
576
+ }
577
+ catch {
578
+ return '[]';
579
+ }
580
+ }
581
+ }
582
+ GradientWrapper.aiSystem = AI_SYSTEM;
583
+ exports.default = GradientWrapper;
584
+ //# sourceMappingURL=wrapper.js.map