openlit 1.13.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 (348) 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 +415 -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/wrapper.js +111 -15
  156. package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -1
  157. package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
  158. package/dist/instrumentation/elevenlabs/index.js +92 -0
  159. package/dist/instrumentation/elevenlabs/index.js.map +1 -0
  160. package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
  161. package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
  162. package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
  163. package/dist/instrumentation/firecrawl/index.d.ts +13 -0
  164. package/dist/instrumentation/firecrawl/index.js +115 -0
  165. package/dist/instrumentation/firecrawl/index.js.map +1 -0
  166. package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
  167. package/dist/instrumentation/firecrawl/wrapper.js +378 -0
  168. package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
  169. package/dist/instrumentation/google-ai/wrapper.d.ts +13 -0
  170. package/dist/instrumentation/google-ai/wrapper.js +85 -1
  171. package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
  172. package/dist/instrumentation/gpu/index.d.ts +38 -0
  173. package/dist/instrumentation/gpu/index.js +233 -0
  174. package/dist/instrumentation/gpu/index.js.map +1 -0
  175. package/dist/instrumentation/gradient/index.d.ts +12 -0
  176. package/dist/instrumentation/gradient/index.js +74 -0
  177. package/dist/instrumentation/gradient/index.js.map +1 -0
  178. package/dist/instrumentation/gradient/utils.d.ts +14 -0
  179. package/dist/instrumentation/gradient/utils.js +119 -0
  180. package/dist/instrumentation/gradient/utils.js.map +1 -0
  181. package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
  182. package/dist/instrumentation/gradient/wrapper.js +584 -0
  183. package/dist/instrumentation/gradient/wrapper.js.map +1 -0
  184. package/dist/instrumentation/groq/wrapper.js +42 -0
  185. package/dist/instrumentation/groq/wrapper.js.map +1 -1
  186. package/dist/instrumentation/huggingface/wrapper.d.ts +13 -0
  187. package/dist/instrumentation/huggingface/wrapper.js +66 -0
  188. package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
  189. package/dist/instrumentation/index.js +26 -0
  190. package/dist/instrumentation/index.js.map +1 -1
  191. package/dist/instrumentation/langchain/wrapper.js +5 -8
  192. package/dist/instrumentation/langchain/wrapper.js.map +1 -1
  193. package/dist/instrumentation/langgraph/wrapper.js +12 -11
  194. package/dist/instrumentation/langgraph/wrapper.js.map +1 -1
  195. package/dist/instrumentation/llamaindex/wrapper.d.ts +14 -1
  196. package/dist/instrumentation/llamaindex/wrapper.js +68 -0
  197. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
  198. package/dist/instrumentation/mcp/index.d.ts +20 -0
  199. package/dist/instrumentation/mcp/index.js +282 -0
  200. package/dist/instrumentation/mcp/index.js.map +1 -0
  201. package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
  202. package/dist/instrumentation/mcp/wrapper.js +571 -0
  203. package/dist/instrumentation/mcp/wrapper.js.map +1 -0
  204. package/dist/instrumentation/mem0/index.d.ts +17 -0
  205. package/dist/instrumentation/mem0/index.js +113 -0
  206. package/dist/instrumentation/mem0/index.js.map +1 -0
  207. package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
  208. package/dist/instrumentation/mem0/wrapper.js +298 -0
  209. package/dist/instrumentation/mem0/wrapper.js.map +1 -0
  210. package/dist/instrumentation/mistral/wrapper.d.ts +13 -0
  211. package/dist/instrumentation/mistral/wrapper.js +60 -1
  212. package/dist/instrumentation/mistral/wrapper.js.map +1 -1
  213. package/dist/instrumentation/ollama/wrapper.d.ts +13 -0
  214. package/dist/instrumentation/ollama/wrapper.js +67 -1
  215. package/dist/instrumentation/ollama/wrapper.js.map +1 -1
  216. package/dist/instrumentation/openai/wrapper.d.ts +13 -0
  217. package/dist/instrumentation/openai/wrapper.js +89 -3
  218. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  219. package/dist/instrumentation/pg/index.d.ts +20 -0
  220. package/dist/instrumentation/pg/index.js +74 -0
  221. package/dist/instrumentation/pg/index.js.map +1 -0
  222. package/dist/instrumentation/pg/wrapper.d.ts +66 -0
  223. package/dist/instrumentation/pg/wrapper.js +441 -0
  224. package/dist/instrumentation/pg/wrapper.js.map +1 -0
  225. package/dist/instrumentation/replicate/wrapper.d.ts +13 -0
  226. package/dist/instrumentation/replicate/wrapper.js +61 -0
  227. package/dist/instrumentation/replicate/wrapper.js.map +1 -1
  228. package/dist/instrumentation/strands/processor.d.ts +6 -0
  229. package/dist/instrumentation/strands/processor.js +73 -3
  230. package/dist/instrumentation/strands/processor.js.map +1 -1
  231. package/dist/instrumentation/strands/utils.d.ts +2 -2
  232. package/dist/instrumentation/strands/utils.js +15 -2
  233. package/dist/instrumentation/strands/utils.js.map +1 -1
  234. package/dist/instrumentation/together/wrapper.d.ts +13 -0
  235. package/dist/instrumentation/together/wrapper.js +59 -1
  236. package/dist/instrumentation/together/wrapper.js.map +1 -1
  237. package/dist/instrumentation/transformers/index.d.ts +35 -0
  238. package/dist/instrumentation/transformers/index.js +119 -0
  239. package/dist/instrumentation/transformers/index.js.map +1 -0
  240. package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
  241. package/dist/instrumentation/transformers/wrapper.js +472 -0
  242. package/dist/instrumentation/transformers/wrapper.js.map +1 -0
  243. package/dist/instrumentation/vercel-ai/wrapper.d.ts +13 -0
  244. package/dist/instrumentation/vercel-ai/wrapper.js +106 -1
  245. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
  246. package/dist/instrumentation/vertexai/index.d.ts +11 -0
  247. package/dist/instrumentation/vertexai/index.js +70 -0
  248. package/dist/instrumentation/vertexai/index.js.map +1 -0
  249. package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
  250. package/dist/instrumentation/vertexai/wrapper.js +529 -0
  251. package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
  252. package/dist/instrumentation/vllm/index.d.ts +13 -0
  253. package/dist/instrumentation/vllm/index.js +67 -0
  254. package/dist/instrumentation/vllm/index.js.map +1 -0
  255. package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
  256. package/dist/instrumentation/vllm/wrapper.js +482 -0
  257. package/dist/instrumentation/vllm/wrapper.js.map +1 -0
  258. package/dist/llm/index.d.ts +9 -2
  259. package/dist/llm/index.js.map +1 -1
  260. package/dist/manual-trace.d.ts +40 -0
  261. package/dist/manual-trace.js +103 -0
  262. package/dist/manual-trace.js.map +1 -0
  263. package/dist/otel/metrics.d.ts +11 -0
  264. package/dist/otel/metrics.js +48 -0
  265. package/dist/otel/metrics.js.map +1 -1
  266. package/dist/register.d.ts +4 -0
  267. package/dist/register.js +52 -0
  268. package/dist/register.js.map +1 -0
  269. package/dist/score/__tests__/score.test.d.ts +1 -0
  270. package/dist/score/__tests__/score.test.js +143 -0
  271. package/dist/score/__tests__/score.test.js.map +1 -0
  272. package/dist/score/index.d.ts +2 -0
  273. package/dist/score/index.js +6 -0
  274. package/dist/score/index.js.map +1 -0
  275. package/dist/score/score.d.ts +15 -0
  276. package/dist/score/score.js +135 -0
  277. package/dist/score/score.js.map +1 -0
  278. package/dist/semantic-convention.d.ts +273 -0
  279. package/dist/semantic-convention.js +317 -0
  280. package/dist/semantic-convention.js.map +1 -1
  281. package/dist/types.d.ts +15 -1
  282. package/package.json +18 -1
  283. package/dist/evals/__tests__/anthropic.test.js +0 -9
  284. package/dist/evals/__tests__/anthropic.test.js.map +0 -1
  285. package/dist/evals/__tests__/base.test.js +0 -37
  286. package/dist/evals/__tests__/base.test.js.map +0 -1
  287. package/dist/evals/__tests__/core.test.js +0 -33
  288. package/dist/evals/__tests__/core.test.js.map +0 -1
  289. package/dist/evals/__tests__/metrics.test.js +0 -59
  290. package/dist/evals/__tests__/metrics.test.js.map +0 -1
  291. package/dist/evals/__tests__/openai.test.js +0 -9
  292. package/dist/evals/__tests__/openai.test.js.map +0 -1
  293. package/dist/evals/__tests__/providers.test.js +0 -14
  294. package/dist/evals/__tests__/providers.test.js.map +0 -1
  295. package/dist/evals/__tests__/utils.test.js +0 -46
  296. package/dist/evals/__tests__/utils.test.js.map +0 -1
  297. package/dist/evals/all.d.ts +0 -4
  298. package/dist/evals/all.js +0 -35
  299. package/dist/evals/all.js.map +0 -1
  300. package/dist/evals/base.d.ts +0 -15
  301. package/dist/evals/base.js +0 -51
  302. package/dist/evals/base.js.map +0 -1
  303. package/dist/evals/bias.d.ts +0 -4
  304. package/dist/evals/bias.js +0 -35
  305. package/dist/evals/bias.js.map +0 -1
  306. package/dist/evals/hallucination.d.ts +0 -4
  307. package/dist/evals/hallucination.js +0 -32
  308. package/dist/evals/hallucination.js.map +0 -1
  309. package/dist/evals/llm/anthropic.d.ts +0 -5
  310. package/dist/evals/llm/anthropic.js +0 -42
  311. package/dist/evals/llm/anthropic.js.map +0 -1
  312. package/dist/evals/llm/openai.d.ts +0 -6
  313. package/dist/evals/llm/openai.js +0 -28
  314. package/dist/evals/llm/openai.js.map +0 -1
  315. package/dist/evals/llm/providers.d.ts +0 -7
  316. package/dist/evals/llm/providers.js +0 -10
  317. package/dist/evals/llm/providers.js.map +0 -1
  318. package/dist/evals/metrics.d.ts +0 -9
  319. package/dist/evals/metrics.js +0 -38
  320. package/dist/evals/metrics.js.map +0 -1
  321. package/dist/evals/toxicity.d.ts +0 -4
  322. package/dist/evals/toxicity.js +0 -33
  323. package/dist/evals/toxicity.js.map +0 -1
  324. package/dist/evals/utils.d.ts +0 -4
  325. package/dist/evals/utils.js +0 -39
  326. package/dist/evals/utils.js.map +0 -1
  327. package/dist/guard/__tests__/gaurd.test.js +0 -136
  328. package/dist/guard/__tests__/gaurd.test.js.map +0 -1
  329. package/dist/guard/__tests__/utils.test.js +0 -64
  330. package/dist/guard/__tests__/utils.test.js.map +0 -1
  331. package/dist/guard/all.d.ts +0 -8
  332. package/dist/guard/all.js +0 -28
  333. package/dist/guard/all.js.map +0 -1
  334. package/dist/guard/types.d.ts +0 -26
  335. package/dist/guard/types.js +0 -4
  336. package/dist/guard/types.js.map +0 -1
  337. package/dist/guard/utils.d.ts +0 -13
  338. package/dist/guard/utils.js +0 -79
  339. package/dist/guard/utils.js.map +0 -1
  340. /package/dist/{evals/__tests__/anthropic.test.d.ts → __tests__/manual-trace.test.d.ts} +0 -0
  341. /package/dist/{evals/__tests__/metrics.test.d.ts → __tests__/register.test.d.ts} +0 -0
  342. /package/dist/evals/__tests__/{base.test.d.ts → offline.test.d.ts} +0 -0
  343. /package/dist/{evals/__tests__/core.test.d.ts → guard/__tests__/integration.test.d.ts} +0 -0
  344. /package/dist/{evals/__tests__/openai.test.d.ts → guard/__tests__/pii.test.d.ts} +0 -0
  345. /package/dist/{evals/__tests__/providers.test.d.ts → guard/__tests__/pipeline.test.d.ts} +0 -0
  346. /package/dist/{evals/__tests__/utils.test.d.ts → guard/__tests__/prompt-injection.test.d.ts} +0 -0
  347. /package/dist/{guard/__tests__/gaurd.test.d.ts → instrumentation/__tests__/assemblyai-wrapper.test.d.ts} +0 -0
  348. /package/dist/{guard/__tests__/utils.test.d.ts → instrumentation/__tests__/browser-use-wrapper.test.d.ts} +0 -0
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
7
+ const api_1 = require("@opentelemetry/api");
8
+ const constant_1 = require("../../constant");
9
+ const wrapper_1 = __importDefault(require("./wrapper"));
10
+ /**
11
+ * mem0 method name -> span name. Span names reuse the Python endpoint strings
12
+ * (snake_case `get_all` / `delete_all`) so TS and Python emit identical span names,
13
+ * even though the JS methods are camelCase (`getAll` / `deleteAll`).
14
+ */
15
+ const MEM0_METHODS = [
16
+ ['add', 'memory add'],
17
+ ['search', 'memory search'],
18
+ ['get', 'memory get'],
19
+ ['getAll', 'memory get_all'],
20
+ ['update', 'memory update'],
21
+ ['delete', 'memory delete'],
22
+ ['deleteAll', 'memory delete_all'],
23
+ ['history', 'memory history'],
24
+ ['reset', 'memory reset'],
25
+ ];
26
+ class OpenlitMem0Instrumentation extends instrumentation_1.InstrumentationBase {
27
+ constructor(config = {}) {
28
+ super(`${constant_1.INSTRUMENTATION_PREFIX}/instrumentation-mem0`, '1.0.0', config);
29
+ }
30
+ init() {
31
+ // mem0ai ships two clients at two specifiers:
32
+ // - `mem0ai` -> hosted MemoryClient (the package entry, patched below)
33
+ // - `mem0ai/oss` -> self-hosted Memory (an internal file)
34
+ // require-in-the-middle reaches internal files via the `files` array, so the OSS
35
+ // entry is registered as InstrumentationNodeModuleFile(s) on the main definition.
36
+ // A few candidate paths are listed to stay robust across build layouts.
37
+ const ossFiles = ['mem0ai/dist/oss/index.js', 'mem0ai/dist/oss/index.cjs', 'mem0ai/oss/index.js'].map((filePath) => new instrumentation_1.InstrumentationNodeModuleFile(filePath, ['>=0.1.32'], (moduleExports, moduleVersion) => {
38
+ this._patchOss(moduleExports, moduleVersion);
39
+ return moduleExports;
40
+ }, (moduleExports) => {
41
+ if (moduleExports !== undefined)
42
+ this._unpatchOss(moduleExports);
43
+ }));
44
+ const module = new instrumentation_1.InstrumentationNodeModuleDefinition('mem0ai', ['>=0.1.32'], (moduleExports, moduleVersion) => {
45
+ this._patch(moduleExports, moduleVersion);
46
+ return moduleExports;
47
+ }, (moduleExports) => {
48
+ if (moduleExports !== undefined)
49
+ this._unpatch(moduleExports);
50
+ }, ossFiles);
51
+ return [module];
52
+ }
53
+ manualPatch(mem0) {
54
+ // Manual entry point (openlit.init({ instrumentations: { mem0 } })). The caller may
55
+ // pass either the hosted module/class or the OSS one, so try both resolvers — the
56
+ // isWrapped guard in _patchClass keeps it idempotent.
57
+ this._patch(mem0);
58
+ this._patchOss(mem0);
59
+ }
60
+ /** Patch the hosted MemoryClient (default export of `mem0ai`). */
61
+ _patch(moduleExports, moduleVersion) {
62
+ const ClientClass = moduleExports?.MemoryClient ?? moduleExports?.default ?? moduleExports;
63
+ this._patchClass(ClientClass, moduleVersion);
64
+ }
65
+ /** Patch the self-hosted Memory class (`mem0ai/oss`). */
66
+ _patchOss(moduleExports, moduleVersion) {
67
+ const MemoryClass = moduleExports?.Memory ?? moduleExports?.default ?? moduleExports;
68
+ this._patchClass(MemoryClass, moduleVersion);
69
+ }
70
+ _patchClass(target, moduleVersion) {
71
+ try {
72
+ const proto = target?.prototype;
73
+ if (!proto)
74
+ return;
75
+ for (const [method, spanName] of MEM0_METHODS) {
76
+ if (typeof proto[method] !== 'function')
77
+ continue;
78
+ if ((0, instrumentation_1.isWrapped)(proto[method])) {
79
+ this._unwrap(proto, method);
80
+ }
81
+ this._wrap(proto, method, wrapper_1.default._patchMemoryOperation(this.tracer, spanName, moduleVersion));
82
+ }
83
+ }
84
+ catch (e) {
85
+ api_1.diag.error('mem0 instrumentation: error in _patch method', e);
86
+ }
87
+ }
88
+ _unpatch(moduleExports) {
89
+ const ClientClass = moduleExports?.MemoryClient ?? moduleExports?.default ?? moduleExports;
90
+ this._unpatchClass(ClientClass);
91
+ }
92
+ _unpatchOss(moduleExports) {
93
+ const MemoryClass = moduleExports?.Memory ?? moduleExports?.default ?? moduleExports;
94
+ this._unpatchClass(MemoryClass);
95
+ }
96
+ _unpatchClass(target) {
97
+ try {
98
+ const proto = target?.prototype;
99
+ if (!proto)
100
+ return;
101
+ for (const [method] of MEM0_METHODS) {
102
+ if (typeof proto[method] === 'function' && (0, instrumentation_1.isWrapped)(proto[method])) {
103
+ this._unwrap(proto, method);
104
+ }
105
+ }
106
+ }
107
+ catch {
108
+ /* ignore */
109
+ }
110
+ }
111
+ }
112
+ exports.default = OpenlitMem0Instrumentation;
113
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/instrumentation/mem0/index.ts"],"names":[],"mappings":";;;;;AAAA,oEAMwC;AAExC,4CAA0C;AAC1C,6CAAwD;AACxD,wDAAoC;AAIpC;;;;GAIG;AACH,MAAM,YAAY,GAA4B;IAC5C,CAAC,KAAK,EAAE,YAAY,CAAC;IACrB,CAAC,QAAQ,EAAE,eAAe,CAAC;IAC3B,CAAC,KAAK,EAAE,YAAY,CAAC;IACrB,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAC5B,CAAC,QAAQ,EAAE,eAAe,CAAC;IAC3B,CAAC,QAAQ,EAAE,eAAe,CAAC;IAC3B,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAClC,CA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AA8C,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAES,QAAQ,CAAC,aAAkB;QACnC,MAAM,WAAW,GAAG,aAAa,EAAE,YAAY,IAAI,aAAa,EAAE,OAAO,IAAI,aAAa,CAAC;QAC3F,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAES,WAAW,CAAC,aAAkB;QACtC,MAAM,WAAW,GAAG,aAAa,EAAE,MAAM,IAAI,aAAa,EAAE,OAAO,IAAI,aAAa,CAAC;QACrF,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAEO,aAAa,CAAC,MAAW;QAC/B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,EAAE,SAAS,CAAC;YAChC,IAAI,CAAC,KAAK;gBAAE,OAAO;YACnB,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;gBACpC,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,UAAU,IAAI,IAAA,2BAAS,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;oBACpE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;CACF;AAvGD,6CAuGC"}
@@ -0,0 +1,37 @@
1
+ import { Tracer } from '@opentelemetry/api';
2
+ /**
3
+ * Wrapper for mem0 memory-layer operations. mem0 exposes the same method surface on
4
+ * the hosted `MemoryClient` (`mem0ai`) and the self-hosted `Memory` (`mem0ai/oss`):
5
+ * add / search / get / getAll / update / delete / deleteAll / history. Every method
6
+ * returns a Promise, so a single async wrapper handles them all. The emitted spans
7
+ * mirror the Python reference (sdk/python/src/openlit/instrumentation/mem0): one
8
+ * CLIENT span per call named `memory <op>`, with `gen_ai.*` attributes. No tokens,
9
+ * model, cost, or metrics are involved (matching Python) so this does not use the
10
+ * chat-oriented BaseWrapper.
11
+ */
12
+ declare class Mem0Wrapper {
13
+ static aiSystem: string;
14
+ /**
15
+ * Returns a wrapper (over an original Promise-returning method) that emits one
16
+ * `memory <op>` CLIENT span. `spanName` is the Python endpoint string, e.g.
17
+ * `memory add` or `memory get_all`.
18
+ */
19
+ static _patchMemoryOperation(tracer: Tracer, spanName: string, version?: string): any;
20
+ /** Sets every non-content attribute (core + scope + memory + operation + response). */
21
+ static _setSpanAttributes(span: any, spanName: string, args: any[], response?: any, sdkVersion?: string): void;
22
+ private static _setOperationAttributes;
23
+ private static _setResponseAttributes;
24
+ /** Captures input (add) / output (search) content when capture is enabled. */
25
+ static _setContentAttributes(span: any, spanName: string, args: any[], response: any): void;
26
+ /**
27
+ * Returns the options/config object for an operation, accounting for the fact that
28
+ * its argument position differs by method: add/search take it as the 2nd arg, while
29
+ * getAll/deleteAll take it as the 1st. get/update/history take a positional id and
30
+ * carry no scope config.
31
+ */
32
+ private static _extractConfig;
33
+ private static _scopeValue;
34
+ private static _hasMessages;
35
+ private static _safeStringify;
36
+ }
37
+ export default Mem0Wrapper;
@@ -0,0 +1,298 @@
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 semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
41
+ const config_1 = __importDefault(require("../../config"));
42
+ const constant_1 = require("../../constant");
43
+ const helpers_1 = __importStar(require("../../helpers"));
44
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
45
+ // `gen_ai.sdk.version` reports the *instrumented* package version (mem0ai), matching
46
+ // the Python SDK (importlib.metadata.version("mem0ai")) rather than OpenLIT's version.
47
+ // The reliable source is the version OTel passes to the patch hook, threaded in as the
48
+ // `version` arg of _patchMemoryOperation. This module-level require is only a fallback
49
+ // for manualPatch — and note mem0ai's "exports" map blocks `mem0ai/package.json`, so it
50
+ // resolves to 'unknown' for mem0ai itself; that's fine, the OTel-provided version wins.
51
+ let mem0SdkVersion = 'unknown';
52
+ try {
53
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
54
+ mem0SdkVersion = require('mem0ai/package.json')?.version || 'unknown';
55
+ }
56
+ catch {
57
+ mem0SdkVersion = 'unknown';
58
+ }
59
+ /**
60
+ * Wrapper for mem0 memory-layer operations. mem0 exposes the same method surface on
61
+ * the hosted `MemoryClient` (`mem0ai`) and the self-hosted `Memory` (`mem0ai/oss`):
62
+ * add / search / get / getAll / update / delete / deleteAll / history. Every method
63
+ * returns a Promise, so a single async wrapper handles them all. The emitted spans
64
+ * mirror the Python reference (sdk/python/src/openlit/instrumentation/mem0): one
65
+ * CLIENT span per call named `memory <op>`, with `gen_ai.*` attributes. No tokens,
66
+ * model, cost, or metrics are involved (matching Python) so this does not use the
67
+ * chat-oriented BaseWrapper.
68
+ */
69
+ class Mem0Wrapper {
70
+ /**
71
+ * Returns a wrapper (over an original Promise-returning method) that emits one
72
+ * `memory <op>` CLIENT span. `spanName` is the Python endpoint string, e.g.
73
+ * `memory add` or `memory get_all`.
74
+ */
75
+ static _patchMemoryOperation(tracer, spanName, version) {
76
+ const sdkVersion = version || mem0SdkVersion;
77
+ return (originalMethod) => {
78
+ return async function (...args) {
79
+ const span = tracer.startSpan(spanName, { kind: api_1.SpanKind.CLIENT });
80
+ const startTime = Date.now();
81
+ return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), async () => {
82
+ try {
83
+ const response = await originalMethod.apply(this, args);
84
+ const duration = (Date.now() - startTime) / 1000;
85
+ Mem0Wrapper._setSpanAttributes(span, spanName, args, response, sdkVersion);
86
+ span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
87
+ Mem0Wrapper._setContentAttributes(span, spanName, args, response);
88
+ span.setStatus({ code: api_1.SpanStatusCode.OK });
89
+ return response;
90
+ }
91
+ catch (e) {
92
+ const duration = (Date.now() - startTime) / 1000;
93
+ span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
94
+ try {
95
+ Mem0Wrapper._setSpanAttributes(span, spanName, args, undefined, sdkVersion);
96
+ }
97
+ catch {
98
+ /* best-effort attributes on the error path */
99
+ }
100
+ helpers_1.default.handleException(span, e);
101
+ throw e;
102
+ }
103
+ finally {
104
+ span.end();
105
+ }
106
+ });
107
+ };
108
+ };
109
+ }
110
+ /** Sets every non-content attribute (core + scope + memory + operation + response). */
111
+ static _setSpanAttributes(span, spanName, args, response, sdkVersion = mem0SdkVersion) {
112
+ const applicationName = config_1.default.applicationName || '';
113
+ const environment = config_1.default.environment || '';
114
+ // Core attributes (set on every memory span).
115
+ span.setAttribute(semantic_conventions_1.ATTR_TELEMETRY_SDK_NAME, constant_1.SDK_NAME);
116
+ // Set both provider-name keys to 'mem0': gen_ai.system (the key Python mem0 uses)
117
+ // and gen_ai.provider.name (the OTel framework convention). Same value either way.
118
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME, Mem0Wrapper.aiSystem);
119
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, Mem0Wrapper.aiSystem);
120
+ span.setAttribute(semantic_convention_1.default.GEN_AI_ENDPOINT, spanName);
121
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_MEMORY);
122
+ span.setAttribute(semantic_convention_1.default.ATTR_DEPLOYMENT_ENVIRONMENT, environment);
123
+ span.setAttribute(semantic_conventions_1.ATTR_SERVICE_NAME, applicationName);
124
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, sdkVersion);
125
+ const config = Mem0Wrapper._extractConfig(spanName, args);
126
+ // Session scope — present either at the top level of the config object or inside a
127
+ // nested `filters` object, in camelCase (v3 SDK) or snake_case (filters / hosted API).
128
+ const userId = Mem0Wrapper._scopeValue(config, 'userId', 'user_id');
129
+ const agentId = Mem0Wrapper._scopeValue(config, 'agentId', 'agent_id');
130
+ const runId = Mem0Wrapper._scopeValue(config, 'runId', 'run_id');
131
+ if (userId !== undefined)
132
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USER_ID, userId);
133
+ if (agentId !== undefined)
134
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_ID, agentId);
135
+ if (runId !== undefined)
136
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RUN_ID, runId);
137
+ // Memory type / metadata.
138
+ const memoryType = config?.memoryType ?? config?.memory_type;
139
+ if (memoryType !== undefined) {
140
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_TYPE, memoryType);
141
+ }
142
+ if (config?.metadata !== undefined && config?.metadata !== null) {
143
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_METADATA, Mem0Wrapper._safeStringify(config.metadata));
144
+ }
145
+ Mem0Wrapper._setOperationAttributes(span, spanName, args, config);
146
+ Mem0Wrapper._setResponseAttributes(span, response);
147
+ (0, helpers_1.applyCustomSpanAttributes)(span);
148
+ }
149
+ static _setOperationAttributes(span, spanName, args, config) {
150
+ switch (spanName) {
151
+ case 'memory add': {
152
+ const messages = args[0];
153
+ if (config && Object.prototype.hasOwnProperty.call(config, 'infer')) {
154
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_INFER, config.infer);
155
+ }
156
+ if (Mem0Wrapper._hasMessages(messages)) {
157
+ const count = Array.isArray(messages) ? messages.length : 1;
158
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_COUNT, count);
159
+ }
160
+ break;
161
+ }
162
+ case 'memory search': {
163
+ const query = args[0];
164
+ if (query !== undefined) {
165
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_SEARCH_QUERY, query);
166
+ }
167
+ // v3 SDK uses `topK`; older / hosted shapes use `limit`.
168
+ const limit = config?.topK ?? config?.limit;
169
+ if (limit !== undefined) {
170
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_SEARCH_LIMIT, limit);
171
+ }
172
+ if (config?.threshold !== undefined) {
173
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_SEARCH_THRESHOLD, config.threshold);
174
+ }
175
+ break;
176
+ }
177
+ case 'memory update': {
178
+ const memoryId = args[0];
179
+ if (memoryId !== undefined)
180
+ span.setAttribute(semantic_convention_1.default.DB_UPDATE_ID, memoryId);
181
+ break;
182
+ }
183
+ case 'memory delete': {
184
+ const memoryId = args[0];
185
+ if (memoryId !== undefined)
186
+ span.setAttribute(semantic_convention_1.default.DB_DELETE_ID, memoryId);
187
+ break;
188
+ }
189
+ case 'memory get': {
190
+ const memoryId = args[0];
191
+ if (memoryId !== undefined)
192
+ span.setAttribute(semantic_convention_1.default.DB_OPERATION_ID, memoryId);
193
+ break;
194
+ }
195
+ default:
196
+ // get_all, delete_all, history: no extra operation-specific id attribute.
197
+ break;
198
+ }
199
+ }
200
+ static _setResponseAttributes(span, response) {
201
+ if (!response)
202
+ return;
203
+ let count;
204
+ if (Array.isArray(response)) {
205
+ count = response.length;
206
+ }
207
+ else if (typeof response === 'object') {
208
+ // A results array reflects the true count — an empty list is 0; a single-object
209
+ // response (e.g. get / update) counts as 1. NOTE: the Python reference reports 1
210
+ // for an empty results list (its `if results` is falsy on []); we intentionally
211
+ // report the accurate 0 here (per a Sourcery review; Python sync tracked separately).
212
+ count = Array.isArray(response.results) ? response.results.length : 1;
213
+ }
214
+ else {
215
+ count = 1;
216
+ }
217
+ span.setAttribute(semantic_convention_1.default.GEN_AI_MEMORY_OPERATION_RESULT_COUNT, count);
218
+ span.setAttribute(semantic_convention_1.default.GEN_AI_DATA_SOURCES, count);
219
+ }
220
+ /** Captures input (add) / output (search) content when capture is enabled. */
221
+ static _setContentAttributes(span, spanName, args, response) {
222
+ if (!config_1.default.captureMessageContent)
223
+ return;
224
+ try {
225
+ if (spanName === 'memory add') {
226
+ const messages = args[0];
227
+ if (Mem0Wrapper._hasMessages(messages)) {
228
+ const content = typeof messages === 'object' ? Mem0Wrapper._safeStringify(messages) : String(messages);
229
+ span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, content);
230
+ }
231
+ }
232
+ if (spanName === 'memory search' && response) {
233
+ const content = typeof response === 'object' ? Mem0Wrapper._safeStringify(response) : String(response);
234
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, content);
235
+ }
236
+ }
237
+ catch {
238
+ /* best-effort content capture */
239
+ }
240
+ }
241
+ /**
242
+ * Returns the options/config object for an operation, accounting for the fact that
243
+ * its argument position differs by method: add/search take it as the 2nd arg, while
244
+ * getAll/deleteAll take it as the 1st. get/update/history take a positional id and
245
+ * carry no scope config.
246
+ */
247
+ static _extractConfig(spanName, args) {
248
+ switch (spanName) {
249
+ case 'memory add':
250
+ case 'memory search':
251
+ case 'memory delete':
252
+ return args[1] && typeof args[1] === 'object' ? args[1] : {};
253
+ case 'memory get_all':
254
+ case 'memory delete_all':
255
+ return args[0] && typeof args[0] === 'object' ? args[0] : {};
256
+ default:
257
+ return {};
258
+ }
259
+ }
260
+ static _scopeValue(config, camelKey, snakeKey) {
261
+ if (!config || typeof config !== 'object')
262
+ return undefined;
263
+ if (config[camelKey] !== undefined)
264
+ return config[camelKey];
265
+ if (config[snakeKey] !== undefined)
266
+ return config[snakeKey];
267
+ const filters = config.filters;
268
+ if (filters && typeof filters === 'object') {
269
+ if (filters[camelKey] !== undefined)
270
+ return filters[camelKey];
271
+ if (filters[snakeKey] !== undefined)
272
+ return filters[snakeKey];
273
+ }
274
+ return undefined;
275
+ }
276
+ static _hasMessages(messages) {
277
+ if (messages === undefined || messages === null)
278
+ return false;
279
+ if (Array.isArray(messages))
280
+ return messages.length > 0;
281
+ if (typeof messages === 'string')
282
+ return messages.length > 0;
283
+ return true;
284
+ }
285
+ static _safeStringify(value) {
286
+ if (typeof value === 'string')
287
+ return value;
288
+ try {
289
+ return JSON.stringify(value);
290
+ }
291
+ catch {
292
+ return String(value);
293
+ }
294
+ }
295
+ }
296
+ Mem0Wrapper.aiSystem = semantic_convention_1.default.GEN_AI_SYSTEM_MEM0;
297
+ exports.default = Mem0Wrapper;
298
+ //# sourceMappingURL=wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../../src/instrumentation/mem0/wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsF;AACtF,8EAAiG;AACjG,0DAAyC;AACzC,6CAA0C;AAC1C,yDAAyE;AACzE,oFAA2D;AAE3D,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,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;;AAzOM,oBAAQ,GAAG,6BAAkB,CAAC,kBAAkB,CAAC;AA4O1D,kBAAe,WAAW,CAAC"}
@@ -4,6 +4,19 @@ declare class MistralWrapper extends BaseWrapper {
4
4
  static aiSystem: string;
5
5
  static serverAddress: string;
6
6
  static serverPort: number;
7
+ /**
8
+ * Stamp `openlit.agent.version_hash` (auto) and `gen_ai.agent.version`
9
+ * (user override, if set) on the span and return the same attributes so
10
+ * the caller can merge them into the inference event extras.
11
+ */
12
+ static _stampAgentVersion(span: Span, args: {
13
+ systemInstructionsJson?: string;
14
+ toolDefinitionsJson?: string;
15
+ primaryModel?: string;
16
+ temperature?: number | null;
17
+ top_p?: number | null;
18
+ max_tokens?: number | null;
19
+ }): Record<string, string>;
7
20
  static _patchChatCompletionCreate(tracer: Tracer): any;
8
21
  static _chatCompletion({ args, genAIEndpoint, response, span, }: {
9
22
  args: any[];
@@ -51,6 +51,41 @@ function spanCreationAttrs(operationName, requestModel) {
51
51
  };
52
52
  }
53
53
  class MistralWrapper extends base_wrapper_1.default {
54
+ /**
55
+ * Stamp `openlit.agent.version_hash` (auto) and `gen_ai.agent.version`
56
+ * (user override, if set) on the span and return the same attributes so
57
+ * the caller can merge them into the inference event extras.
58
+ */
59
+ static _stampAgentVersion(span, args) {
60
+ const out = {};
61
+ try {
62
+ const versionHash = helpers_1.default.computeAgentVersionHash({
63
+ systemInstructions: args.systemInstructionsJson ?? null,
64
+ toolDefinitions: args.toolDefinitionsJson ?? null,
65
+ primaryModel: args.primaryModel ?? null,
66
+ runtimeConfig: {
67
+ temperature: args.temperature ?? null,
68
+ top_p: args.top_p ?? null,
69
+ max_tokens: args.max_tokens ?? null,
70
+ provider: semantic_convention_1.default.GEN_AI_SYSTEM_MISTRAL,
71
+ },
72
+ providers: [semantic_convention_1.default.GEN_AI_SYSTEM_MISTRAL],
73
+ });
74
+ if (versionHash) {
75
+ out[semantic_convention_1.default.OPENLIT_AGENT_VERSION_HASH] = versionHash;
76
+ span.setAttribute(semantic_convention_1.default.OPENLIT_AGENT_VERSION_HASH, versionHash);
77
+ }
78
+ }
79
+ catch {
80
+ // Hash computation must never fail the wrapped call.
81
+ }
82
+ const versionLabel = (0, helpers_1.getCurrentAgentVersion)();
83
+ if (versionLabel) {
84
+ out[semantic_convention_1.default.GEN_AI_AGENT_VERSION] = versionLabel;
85
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_VERSION, versionLabel);
86
+ }
87
+ return out;
88
+ }
54
89
  static _patchChatCompletionCreate(tracer) {
55
90
  const genAIEndpoint = 'mistral.chat.completions';
56
91
  return (originalMethod) => {
@@ -237,7 +272,7 @@ class MistralWrapper extends base_wrapper_1.default {
237
272
  static async _chatCompletionCommonSetter({ args, genAIEndpoint, result, span, ttft = 0, tbt = 0, }) {
238
273
  const captureContent = config_1.default.captureMessageContent;
239
274
  const requestModel = args[0]?.model || 'mistral-small-latest';
240
- const { messages, frequency_penalty = 0, max_tokens = null, n = 1, presence_penalty = 0, seed = null, stop = null, temperature = 1, top_p, user, stream = false, } = args[0];
275
+ const { messages, frequency_penalty = 0, max_tokens = null, n = 1, presence_penalty = 0, seed = null, stop = null, temperature = 1, top_p, user, stream = false, tools: _tools, } = args[0];
241
276
  span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_P, top_p || 1);
242
277
  if (max_tokens != null) {
243
278
  span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, max_tokens);
@@ -313,11 +348,30 @@ class MistralWrapper extends base_wrapper_1.default {
313
348
  }
314
349
  let inputMessagesJson;
315
350
  let outputMessagesJson;
351
+ const toolDefinitionsJson = helpers_1.default.buildToolDefinitions(_tools);
352
+ // Compute system_instructions and version hash regardless of
353
+ // captureContent so versions still group correctly when content
354
+ // capture is disabled.
355
+ const systemInstructionsJson = helpers_1.default.buildSystemInstructionsFromMessages(messages || []);
356
+ const versionExtras = MistralWrapper._stampAgentVersion(span, {
357
+ systemInstructionsJson,
358
+ toolDefinitionsJson,
359
+ primaryModel: responseModel || requestModel,
360
+ temperature,
361
+ top_p,
362
+ max_tokens,
363
+ });
316
364
  if (captureContent) {
317
365
  const toolCalls = result.choices[0].message.tool_calls;
318
366
  outputMessagesJson = helpers_1.default.buildOutputMessages(result.choices[0].message.content || '', finishReason || 'stop', toolCalls);
319
367
  span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, outputMessagesJson);
320
368
  inputMessagesJson = helpers_1.default.buildInputMessages(messages || []);
369
+ if (systemInstructionsJson) {
370
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, systemInstructionsJson);
371
+ }
372
+ }
373
+ if (toolDefinitionsJson) {
374
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, toolDefinitionsJson);
321
375
  }
322
376
  if (!config_1.default.disableEvents) {
323
377
  const eventAttrs = {
@@ -331,13 +385,18 @@ class MistralWrapper extends base_wrapper_1.default {
331
385
  [semantic_convention_1.default.GEN_AI_OUTPUT_TYPE]: outputType,
332
386
  [semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: inputTokens,
333
387
  [semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: outputTokens,
388
+ ...versionExtras,
334
389
  };
335
390
  if (captureContent) {
336
391
  if (inputMessagesJson)
337
392
  eventAttrs[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES] = inputMessagesJson;
338
393
  if (outputMessagesJson)
339
394
  eventAttrs[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES] = outputMessagesJson;
395
+ if (systemInstructionsJson)
396
+ eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS] = systemInstructionsJson;
340
397
  }
398
+ if (toolDefinitionsJson)
399
+ eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS] = toolDefinitionsJson;
341
400
  helpers_1.default.emitInferenceEvent(span, eventAttrs);
342
401
  }
343
402
  return {