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
package/dist/index.d.ts CHANGED
@@ -1,47 +1,71 @@
1
1
  import { resourceFromAttributes } from '@opentelemetry/resources';
2
2
  import { OpenlitOptions, ResolvedOptions } from './types';
3
3
  import BaseOpenlit from './features/base';
4
- import { usingAttributes, injectAdditionalAttributes } from './helpers';
5
- import { Hallucination, Bias, Toxicity, All } from './evals';
4
+ import { usingAttributes, injectAdditionalAttributes, setAgentVersion, resetAgentVersion, runWithAgentVersion, getCurrentAgentVersion } from './helpers';
5
+ import { runEval, runEvalBatch, fetchEvalTypes } from './evals';
6
+ import { logScore } from './score';
7
+ import { TracedSpan, startTrace, trace as traceManual } from './manual-trace';
8
+ import { PII } from './guard/pii';
6
9
  import { PromptInjection } from './guard/prompt-injection';
10
+ import { Moderation } from './guard/moderation';
7
11
  import { SensitiveTopic } from './guard/sensitive-topic';
8
12
  import { TopicRestriction } from './guard/topic-restriction';
9
- import { All as GuardAll } from './guard/all';
10
- declare const evals: {
11
- Hallucination: (options: ConstructorParameters<typeof Hallucination>[0]) => Hallucination;
12
- Bias: (options: ConstructorParameters<typeof Bias>[0]) => Bias;
13
- Toxicity: (options: ConstructorParameters<typeof Toxicity>[0]) => Toxicity;
14
- All: (options: ConstructorParameters<typeof All>[0]) => All;
15
- };
16
- declare const guard: {
17
- PromptInjection: (options: ConstructorParameters<typeof PromptInjection>[0]) => PromptInjection;
18
- SensitiveTopic: (options: ConstructorParameters<typeof SensitiveTopic>[0]) => SensitiveTopic;
19
- TopicRestriction: (options: ConstructorParameters<typeof TopicRestriction>[0]) => TopicRestriction;
20
- All: (options: ConstructorParameters<typeof GuardAll>[0]) => GuardAll;
21
- };
13
+ import { Schema } from './guard/schema';
14
+ import { Custom } from './guard/custom';
15
+ import { Pipeline } from './guard/pipeline';
16
+ import { Guard, GuardAction, GuardPhase, GuardError, GuardDeniedError, GuardTimeoutError, GuardConfigError, PipelineResult } from './guard/base';
22
17
  declare class Openlit extends BaseOpenlit {
23
18
  static resource: ReturnType<typeof resourceFromAttributes>;
24
19
  static options: ResolvedOptions;
25
- static evals: {
26
- Hallucination: (options: ConstructorParameters<typeof Hallucination>[0]) => Hallucination;
27
- Bias: (options: ConstructorParameters<typeof Bias>[0]) => Bias;
28
- Toxicity: (options: ConstructorParameters<typeof Toxicity>[0]) => Toxicity;
29
- All: (options: ConstructorParameters<typeof All>[0]) => All;
30
- };
31
- static guard: {
32
- PromptInjection: (options: ConstructorParameters<typeof PromptInjection>[0]) => PromptInjection;
33
- SensitiveTopic: (options: ConstructorParameters<typeof SensitiveTopic>[0]) => SensitiveTopic;
34
- TopicRestriction: (options: ConstructorParameters<typeof TopicRestriction>[0]) => TopicRestriction;
35
- All: (options: ConstructorParameters<typeof GuardAll>[0]) => GuardAll;
36
- };
20
+ static PII: typeof PII;
21
+ static PromptInjection: typeof PromptInjection;
22
+ static Moderation: typeof Moderation;
23
+ static SensitiveTopic: typeof SensitiveTopic;
24
+ static TopicRestriction: typeof TopicRestriction;
25
+ static Schema: typeof Schema;
26
+ static Custom: typeof Custom;
27
+ static Pipeline: typeof Pipeline;
28
+ static GuardAction: typeof GuardAction;
29
+ static GuardPhase: typeof GuardPhase;
30
+ static GuardError: typeof GuardError;
31
+ static GuardDeniedError: typeof GuardDeniedError;
32
+ static GuardTimeoutError: typeof GuardTimeoutError;
33
+ static GuardConfigError: typeof GuardConfigError;
34
+ static eval: typeof runEval;
35
+ static evalBatch: typeof runEvalBatch;
36
+ static getEvalTypes: typeof fetchEvalTypes;
37
+ static logScore: typeof logScore;
38
+ /**
39
+ * Public API: stamp every subsequent chat span / inference event in the
40
+ * current async scope with a user-supplied agent version label
41
+ * (`gen_ai.agent.version`). Useful when you want versions to follow a
42
+ * release tag, git SHA, or business-meaningful name instead of the SDK's
43
+ * auto-computed fingerprint.
44
+ *
45
+ * For a one-shot block, prefer `OpenLit.withAgentVersion(label, fn)`.
46
+ */
47
+ static setAgentVersion: typeof setAgentVersion;
48
+ /**
49
+ * Clear the agent version label set by `setAgentVersion`. Always call this
50
+ * in a `finally` block when you use `setAgentVersion` directly, otherwise
51
+ * the label will persist on subsequent requests handled by the same
52
+ * worker. Prefer `withAgentVersion(label, fn)` for scoped usage.
53
+ */
54
+ static resetAgentVersion: typeof resetAgentVersion;
55
+ static withAgentVersion: typeof runWithAgentVersion;
56
+ static getAgentVersion: typeof getCurrentAgentVersion;
57
+ static startTrace: typeof startTrace;
58
+ static trace: typeof traceManual;
37
59
  static init(options?: OpenlitOptions): void;
38
60
  }
39
61
  declare const openlit: typeof Openlit & {
40
- evals: typeof evals;
41
- guard: typeof guard;
42
62
  usingAttributes: typeof usingAttributes;
43
63
  injectAdditionalAttributes: typeof injectAdditionalAttributes;
44
64
  };
45
65
  export default openlit;
46
- export { Openlit, usingAttributes, injectAdditionalAttributes };
66
+ export { Openlit, usingAttributes, injectAdditionalAttributes, logScore };
67
+ export { TracedSpan, startTrace, traceManual as trace };
47
68
  export type { OpenlitOptions } from './types';
69
+ export type { LogScoreOptions } from './score';
70
+ export { PII, PromptInjection, Moderation, SensitiveTopic, TopicRestriction, Schema, Custom, Pipeline, Guard, GuardAction, GuardPhase, GuardError, GuardDeniedError, GuardTimeoutError, GuardConfigError, PipelineResult, };
71
+ export type { GuardResult } from './guard/base';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.injectAdditionalAttributes = exports.usingAttributes = exports.Openlit = void 0;
6
+ exports.PipelineResult = exports.GuardConfigError = exports.GuardTimeoutError = exports.GuardDeniedError = exports.GuardError = exports.GuardPhase = exports.GuardAction = exports.Guard = exports.Pipeline = exports.Custom = exports.Schema = exports.TopicRestriction = exports.SensitiveTopic = exports.Moderation = exports.PromptInjection = exports.PII = exports.trace = exports.startTrace = exports.TracedSpan = exports.logScore = exports.injectAdditionalAttributes = exports.usingAttributes = exports.Openlit = void 0;
7
7
  const resources_1 = require("@opentelemetry/resources");
8
8
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
9
9
  const api_1 = require("@opentelemetry/api");
@@ -17,25 +17,42 @@ const helpers_2 = require("./helpers");
17
17
  Object.defineProperty(exports, "usingAttributes", { enumerable: true, get: function () { return helpers_2.usingAttributes; } });
18
18
  Object.defineProperty(exports, "injectAdditionalAttributes", { enumerable: true, get: function () { return helpers_2.injectAdditionalAttributes; } });
19
19
  const evals_1 = require("./evals");
20
+ const score_1 = require("./score");
21
+ Object.defineProperty(exports, "logScore", { enumerable: true, get: function () { return score_1.logScore; } });
22
+ const manual_trace_1 = require("./manual-trace");
23
+ Object.defineProperty(exports, "TracedSpan", { enumerable: true, get: function () { return manual_trace_1.TracedSpan; } });
24
+ Object.defineProperty(exports, "startTrace", { enumerable: true, get: function () { return manual_trace_1.startTrace; } });
25
+ Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return manual_trace_1.trace; } });
20
26
  const metrics_1 = __importDefault(require("./otel/metrics"));
27
+ const gpu_1 = __importDefault(require("./instrumentation/gpu"));
21
28
  const semantic_convention_1 = __importDefault(require("./semantic-convention"));
29
+ const utils_1 = require("./otel/utils");
30
+ const integration_1 = require("./guard/integration");
31
+ const pii_1 = require("./guard/pii");
32
+ Object.defineProperty(exports, "PII", { enumerable: true, get: function () { return pii_1.PII; } });
22
33
  const prompt_injection_1 = require("./guard/prompt-injection");
34
+ Object.defineProperty(exports, "PromptInjection", { enumerable: true, get: function () { return prompt_injection_1.PromptInjection; } });
35
+ const moderation_1 = require("./guard/moderation");
36
+ Object.defineProperty(exports, "Moderation", { enumerable: true, get: function () { return moderation_1.Moderation; } });
23
37
  const sensitive_topic_1 = require("./guard/sensitive-topic");
38
+ Object.defineProperty(exports, "SensitiveTopic", { enumerable: true, get: function () { return sensitive_topic_1.SensitiveTopic; } });
24
39
  const topic_restriction_1 = require("./guard/topic-restriction");
25
- const all_1 = require("./guard/all");
26
- const utils_1 = require("./otel/utils");
27
- const evals = {
28
- Hallucination: (options) => new evals_1.Hallucination(options),
29
- Bias: (options) => new evals_1.Bias(options),
30
- Toxicity: (options) => new evals_1.Toxicity(options),
31
- All: (options) => new evals_1.All(options),
32
- };
33
- const guard = {
34
- PromptInjection: (options) => new prompt_injection_1.PromptInjection(options),
35
- SensitiveTopic: (options) => new sensitive_topic_1.SensitiveTopic(options),
36
- TopicRestriction: (options) => new topic_restriction_1.TopicRestriction(options),
37
- All: (options) => new all_1.All(options),
38
- };
40
+ Object.defineProperty(exports, "TopicRestriction", { enumerable: true, get: function () { return topic_restriction_1.TopicRestriction; } });
41
+ const schema_1 = require("./guard/schema");
42
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return schema_1.Schema; } });
43
+ const custom_1 = require("./guard/custom");
44
+ Object.defineProperty(exports, "Custom", { enumerable: true, get: function () { return custom_1.Custom; } });
45
+ const pipeline_1 = require("./guard/pipeline");
46
+ Object.defineProperty(exports, "Pipeline", { enumerable: true, get: function () { return pipeline_1.Pipeline; } });
47
+ const base_2 = require("./guard/base");
48
+ Object.defineProperty(exports, "Guard", { enumerable: true, get: function () { return base_2.Guard; } });
49
+ Object.defineProperty(exports, "GuardAction", { enumerable: true, get: function () { return base_2.GuardAction; } });
50
+ Object.defineProperty(exports, "GuardPhase", { enumerable: true, get: function () { return base_2.GuardPhase; } });
51
+ Object.defineProperty(exports, "GuardError", { enumerable: true, get: function () { return base_2.GuardError; } });
52
+ Object.defineProperty(exports, "GuardDeniedError", { enumerable: true, get: function () { return base_2.GuardDeniedError; } });
53
+ Object.defineProperty(exports, "GuardTimeoutError", { enumerable: true, get: function () { return base_2.GuardTimeoutError; } });
54
+ Object.defineProperty(exports, "GuardConfigError", { enumerable: true, get: function () { return base_2.GuardConfigError; } });
55
+ Object.defineProperty(exports, "PipelineResult", { enumerable: true, get: function () { return base_2.PipelineResult; } });
39
56
  /**
40
57
  * Resolve OpenlitOptions into a single ResolvedOptions object.
41
58
  * Precedence: arg > env var > default.
@@ -80,6 +97,13 @@ function resolveOptions(options) {
80
97
  if (disableEvents === undefined) {
81
98
  disableEvents = envDisableEvents ?? false;
82
99
  }
100
+ let collectGpuStats = o.collectGpuStats ?? undefined;
101
+ const envCollectGpuStats = (0, utils_1.parseBoolEnv)('OPENLIT_COLLECT_GPU_STATS');
102
+ if (collectGpuStats === undefined) {
103
+ collectGpuStats = envCollectGpuStats ?? false;
104
+ }
105
+ const openlitApiKey = o.openlitApiKey ?? process.env.OPENLIT_API_KEY ?? undefined;
106
+ const openlitUrl = o.openlitUrl ?? process.env.OPENLIT_URL ?? undefined;
83
107
  return {
84
108
  environment,
85
109
  applicationName,
@@ -95,13 +119,16 @@ function resolveOptions(options) {
95
119
  pricingJson: o.pricingJson,
96
120
  maxContentLength: o.maxContentLength ?? null,
97
121
  customSpanAttributes: o.customSpanAttributes ?? null,
122
+ openlitApiKey,
123
+ openlitUrl,
124
+ guards: o.guards,
125
+ guardFailOpen: o.guardFailOpen ?? true,
126
+ collectGpuStats,
98
127
  };
99
128
  }
100
129
  class Openlit extends base_1.default {
101
130
  static init(options) {
102
131
  try {
103
- // Enable OTel diagnostic logging so exporter errors (connection refused,
104
- // 404, timeouts) are surfaced to the user — matches Python SDK behavior.
105
132
  api_1.diag.setLogger(new api_1.DiagConsoleLogger(), api_1.DiagLogLevel.WARN);
106
133
  const resolved = resolveOptions(options);
107
134
  this.options = resolved;
@@ -120,22 +147,77 @@ class Openlit extends base_1.default {
120
147
  }
121
148
  if (!resolved.disableMetrics) {
122
149
  const exportIntervalMillis = Number(process.env.OTEL_EXPORTER_OTLP_METRICS_EXPORT_INTERVAL ?? 60000) || 60000;
123
- metrics_1.default.setup({
150
+ const meter = metrics_1.default.setup({
124
151
  ...setupBase,
125
152
  exportIntervalMillis,
126
153
  });
154
+ // GPU metrics: only register gauges when a supported GPU is detected
155
+ // (mirrors Python openlit.init collect_gpu_stats path).
156
+ if (resolved.collectGpuStats && meter) {
157
+ new gpu_1.default()
158
+ .setup({
159
+ meter,
160
+ environment: resolved.environment,
161
+ applicationName: resolved.applicationName,
162
+ })
163
+ .catch((e) => {
164
+ api_1.diag.error(`OpenLIT GPU metrics setup failed: ${e}`);
165
+ });
166
+ }
127
167
  }
128
- // Fetch pricing info once and cache — matches Python SDK behavior.
168
+ config_1.default.openlitApiKey = resolved.openlitApiKey;
169
+ config_1.default.openlitUrl = resolved.openlitUrl;
129
170
  helpers_1.default.fetchPricingInfo(resolved.pricingJson).then((info) => { config_1.default.pricingInfo = info; }, () => { config_1.default.pricingInfo = {}; });
171
+ if (resolved.guards && resolved.guards.length > 0) {
172
+ (0, integration_1.setupAutoGuards)(resolved.guards, resolved.guardFailOpen);
173
+ }
130
174
  }
131
175
  catch (e) {
132
- console.log('Connection time out', e);
176
+ console.error('OpenLIT initialization failed:', e);
133
177
  }
134
178
  }
135
179
  }
136
180
  exports.Openlit = Openlit;
137
- Openlit.evals = evals;
138
- Openlit.guard = guard;
181
+ // Top-level guard class exports
182
+ Openlit.PII = pii_1.PII;
183
+ Openlit.PromptInjection = prompt_injection_1.PromptInjection;
184
+ Openlit.Moderation = moderation_1.Moderation;
185
+ Openlit.SensitiveTopic = sensitive_topic_1.SensitiveTopic;
186
+ Openlit.TopicRestriction = topic_restriction_1.TopicRestriction;
187
+ Openlit.Schema = schema_1.Schema;
188
+ Openlit.Custom = custom_1.Custom;
189
+ Openlit.Pipeline = pipeline_1.Pipeline;
190
+ Openlit.GuardAction = base_2.GuardAction;
191
+ Openlit.GuardPhase = base_2.GuardPhase;
192
+ Openlit.GuardError = base_2.GuardError;
193
+ Openlit.GuardDeniedError = base_2.GuardDeniedError;
194
+ Openlit.GuardTimeoutError = base_2.GuardTimeoutError;
195
+ Openlit.GuardConfigError = base_2.GuardConfigError;
196
+ Openlit.eval = evals_1.runEval;
197
+ Openlit.evalBatch = evals_1.runEvalBatch;
198
+ Openlit.getEvalTypes = evals_1.fetchEvalTypes;
199
+ Openlit.logScore = score_1.logScore;
200
+ /**
201
+ * Public API: stamp every subsequent chat span / inference event in the
202
+ * current async scope with a user-supplied agent version label
203
+ * (`gen_ai.agent.version`). Useful when you want versions to follow a
204
+ * release tag, git SHA, or business-meaningful name instead of the SDK's
205
+ * auto-computed fingerprint.
206
+ *
207
+ * For a one-shot block, prefer `OpenLit.withAgentVersion(label, fn)`.
208
+ */
209
+ Openlit.setAgentVersion = helpers_2.setAgentVersion;
210
+ /**
211
+ * Clear the agent version label set by `setAgentVersion`. Always call this
212
+ * in a `finally` block when you use `setAgentVersion` directly, otherwise
213
+ * the label will persist on subsequent requests handled by the same
214
+ * worker. Prefer `withAgentVersion(label, fn)` for scoped usage.
215
+ */
216
+ Openlit.resetAgentVersion = helpers_2.resetAgentVersion;
217
+ Openlit.withAgentVersion = helpers_2.runWithAgentVersion;
218
+ Openlit.getAgentVersion = helpers_2.getCurrentAgentVersion;
219
+ Openlit.startTrace = manual_trace_1.startTrace;
220
+ Openlit.trace = manual_trace_1.trace;
139
221
  const openlit = Openlit;
140
222
  openlit.usingAttributes = helpers_2.usingAttributes;
141
223
  openlit.injectAdditionalAttributes = helpers_2.injectAdditionalAttributes;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAkE;AAClE,8EAAiG;AACjG,4CAA2E;AAE3E,6DAAqC;AACrC,2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AACV,uBAAe,GAAG,kCAAe,CAAC;AAClC,kBAAU,GAAG,uBAAU,CAAC;AACxB,sBAAc,GAAG,gCAAc,CAAC;AAChC,wBAAgB,GAAG,oCAAgB,CAAC;AACpC,cAAM,GAAG,eAAM,CAAC;AAChB,cAAM,GAAG,eAAM,CAAC;AAChB,gBAAQ,GAAG,mBAAQ,CAAC;AACpB,mBAAW,GAAG,kBAAW,CAAC;AAC1B,kBAAU,GAAG,iBAAU,CAAC;AACxB,kBAAU,GAAG,iBAAU,CAAC;AACxB,wBAAgB,GAAG,uBAAgB,CAAC;AACpC,yBAAiB,GAAG,wBAAiB,CAAC;AACtC,wBAAgB,GAAG,uBAAgB,CAAC;AAEpC,YAAI,GAAG,eAAO,CAAC;AACf,iBAAS,GAAG,oBAAY,CAAC;AACzB,oBAAY,GAAG,sBAAc,CAAC;AAC9B,gBAAQ,GAAG,gBAAQ,CAAC;AAE3B;;;;;;;;GAQG;AACI,uBAAe,GAAG,yBAAe,CAAC;AACzC;;;;;GAKG;AACI,yBAAiB,GAAG,2BAAiB,CAAC;AACtC,wBAAgB,GAAG,6BAAmB,CAAC;AACvC,uBAAe,GAAG,gCAAsB,CAAC;AAEzC,kBAAU,GAAG,yBAAU,CAAC;AACxB,aAAK,GAAG,oBAAW,CAAC;AAmE7B,MAAM,OAAO,GAAG,OAGf,CAAC;AAED,OAAe,CAAC,eAAe,GAAG,yBAAe,CAAC;AAClD,OAAe,CAAC,0BAA0B,GAAG,oCAA0B,CAAC;AAEzE,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Cross-Language Trace Comparison Tests for the AI21 Conversational RAG path.
3
+ *
4
+ * Verifies that the TypeScript AI21 RAG instrumentation emits the same span
5
+ * attributes as the Python SDK reference
6
+ * (sdk/python/src/openlit/instrumentation/ai21: chat_rag / common_chat_rag_logic).
7
+ * The RAG response shape differs from chat: the answer lives at
8
+ * `choices[i].content` (not `choices[i].message.content`), there is no `model`
9
+ * field (falls back to the request model), no usage token counts (counted
10
+ * locally), and the path is never streamed. It additionally emits six
11
+ * `gen_ai.rag.*` attributes mirrored from the Python implementation.
12
+ */
13
+ export {};
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /**
3
+ * Cross-Language Trace Comparison Tests for the AI21 Conversational RAG path.
4
+ *
5
+ * Verifies that the TypeScript AI21 RAG instrumentation emits the same span
6
+ * attributes as the Python SDK reference
7
+ * (sdk/python/src/openlit/instrumentation/ai21: chat_rag / common_chat_rag_logic).
8
+ * The RAG response shape differs from chat: the answer lives at
9
+ * `choices[i].content` (not `choices[i].message.content`), there is no `model`
10
+ * field (falls back to the request model), no usage token counts (counted
11
+ * locally), and the path is never streamed. It additionally emits six
12
+ * `gen_ai.rag.*` attributes mirrored from the Python implementation.
13
+ */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const wrapper_1 = __importDefault(require("../ai21/wrapper"));
19
+ const config_1 = __importDefault(require("../../config"));
20
+ const helpers_1 = __importDefault(require("../../helpers"));
21
+ const base_wrapper_1 = __importDefault(require("../base-wrapper"));
22
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
23
+ jest.mock('../../config');
24
+ jest.mock('../../helpers');
25
+ jest.mock('../base-wrapper');
26
+ describe('AI21 Conversational RAG Trace Comparison', () => {
27
+ let mockSpan;
28
+ beforeEach(() => {
29
+ mockSpan = {
30
+ setAttribute: jest.fn(),
31
+ addEvent: jest.fn(),
32
+ end: jest.fn(),
33
+ setStatus: jest.fn(),
34
+ };
35
+ config_1.default.environment = 'openlit-testing';
36
+ config_1.default.applicationName = 'openlit-test';
37
+ config_1.default.captureMessageContent = true;
38
+ config_1.default.pricingInfo = {};
39
+ config_1.default.disableEvents = false;
40
+ helpers_1.default.getChatModelCost = jest.fn().mockReturnValue(0.002);
41
+ helpers_1.default.openaiTokens = jest.fn().mockReturnValue(5);
42
+ helpers_1.default.handleException = jest.fn();
43
+ helpers_1.default.buildInputMessages = jest.fn().mockReturnValue('[input]');
44
+ helpers_1.default.buildOutputMessages = jest.fn().mockReturnValue('[output]');
45
+ helpers_1.default.buildSystemInstructionsFromMessages = jest.fn().mockReturnValue(undefined);
46
+ helpers_1.default.buildToolDefinitions = jest.fn().mockReturnValue(undefined);
47
+ helpers_1.default.emitInferenceEvent = jest.fn();
48
+ helpers_1.default.computeAgentVersionHash = jest.fn().mockReturnValue('rag-test-hash');
49
+ base_wrapper_1.default.recordMetrics = jest.fn();
50
+ base_wrapper_1.default.setBaseSpanAttributes = jest.fn().mockImplementation((span, attrs) => {
51
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, attrs.aiSystem);
52
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, attrs.model);
53
+ if (attrs.cost !== undefined) {
54
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COST, attrs.cost);
55
+ }
56
+ if (attrs.serverAddress) {
57
+ span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, attrs.serverAddress);
58
+ }
59
+ if (attrs.serverPort !== undefined) {
60
+ span.setAttribute(semantic_convention_1.default.SERVER_PORT, attrs.serverPort);
61
+ }
62
+ });
63
+ });
64
+ afterEach(() => {
65
+ jest.clearAllMocks();
66
+ });
67
+ // AI21 ConversationalRagResponse shape: choices are ChatMessage[] with a flat
68
+ // `content` field, no `model`, no `usage` token counts.
69
+ const mockRagResponse = () => ({
70
+ id: 'ai21-rag-id',
71
+ choices: [{ role: 'assistant', content: 'Jamba RAG answer' }],
72
+ context_retrieved: true,
73
+ answer_in_context: true,
74
+ sources: [],
75
+ });
76
+ it('sets the same core chat attributes as the Python RAG path', async () => {
77
+ const args = [
78
+ {
79
+ messages: [{ role: 'user', content: 'What does the doc say?' }],
80
+ model: 'jamba-large',
81
+ file_ids: ['f1'],
82
+ },
83
+ ];
84
+ await wrapper_1.default._chatRag({
85
+ args,
86
+ genAIEndpoint: 'ai21.conversational_rag',
87
+ response: mockRagResponse(),
88
+ span: mockSpan,
89
+ });
90
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, 'ai21');
91
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, 'jamba-large');
92
+ // RAG responses carry no `model`, so it falls back to the request model.
93
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, 'jamba-large');
94
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_ID, 'ai21-rag-id');
95
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_ADDRESS, 'api.ai21.com');
96
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_PORT, 443);
97
+ });
98
+ it('sets the six RAG-specific attributes from request kwargs', async () => {
99
+ const args = [
100
+ {
101
+ messages: [{ role: 'user', content: 'q' }],
102
+ model: 'jamba-mini',
103
+ max_segments: 10,
104
+ retrieval_strategy: 'semantic',
105
+ max_neighbors: 3,
106
+ file_ids: ['fileA', 'fileB'],
107
+ path: '/docs',
108
+ retrieval_similarity_threshold: 0.5,
109
+ },
110
+ ];
111
+ await wrapper_1.default._chatRag({
112
+ args,
113
+ genAIEndpoint: 'ai21.conversational_rag',
114
+ response: mockRagResponse(),
115
+ span: mockSpan,
116
+ });
117
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_MAX_SEGMENTS, 10);
118
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_STRATEGY, 'semantic');
119
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_MAX_NEIGHBORS, 3);
120
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_FILE_IDS, String(['fileA', 'fileB']));
121
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_DOCUMENTS_PATH, '/docs');
122
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_SIMILARITY_THRESHOLD, 0.5);
123
+ });
124
+ it('applies Python-parity defaults for omitted RAG kwargs', async () => {
125
+ const args = [{ messages: [{ role: 'user', content: 'q' }], model: 'jamba-mini' }];
126
+ await wrapper_1.default._chatRag({
127
+ args,
128
+ genAIEndpoint: 'ai21.conversational_rag',
129
+ response: mockRagResponse(),
130
+ span: mockSpan,
131
+ });
132
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_MAX_SEGMENTS, -1);
133
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_STRATEGY, 'segments');
134
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_MAX_NEIGHBORS, -1);
135
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_FILE_IDS, '');
136
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_DOCUMENTS_PATH, '');
137
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RAG_SIMILARITY_THRESHOLD, -1);
138
+ });
139
+ it('reads the answer from choices[].content and records token usage', async () => {
140
+ const args = [{ messages: [{ role: 'user', content: 'q' }], model: 'jamba-mini' }];
141
+ await wrapper_1.default._chatRag({
142
+ args,
143
+ genAIEndpoint: 'ai21.conversational_rag',
144
+ response: mockRagResponse(),
145
+ span: mockSpan,
146
+ });
147
+ // openaiTokens mocked to 5: 1 input message => 5, output answer => 5.
148
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, 5);
149
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, 5);
150
+ // RAG choices have no tool_calls, so the third arg is undefined.
151
+ expect(helpers_1.default.buildOutputMessages).toHaveBeenCalledWith('Jamba RAG answer', 'stop', undefined);
152
+ });
153
+ it('marks the RAG span as non-streaming with text output', async () => {
154
+ const args = [{ messages: [{ role: 'user', content: 'q' }], model: 'jamba-mini' }];
155
+ await wrapper_1.default._chatRag({
156
+ args,
157
+ genAIEndpoint: 'ai21.conversational_rag',
158
+ response: mockRagResponse(),
159
+ span: mockSpan,
160
+ });
161
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, false);
162
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT);
163
+ });
164
+ it('ends the span and records metrics', async () => {
165
+ const args = [{ messages: [{ role: 'user', content: 'q' }], model: 'jamba-mini' }];
166
+ await wrapper_1.default._chatRag({
167
+ args,
168
+ genAIEndpoint: 'ai21.conversational_rag',
169
+ response: mockRagResponse(),
170
+ span: mockSpan,
171
+ });
172
+ expect(mockSpan.end).toHaveBeenCalled();
173
+ expect(base_wrapper_1.default.recordMetrics).toHaveBeenCalled();
174
+ });
175
+ });
176
+ //# sourceMappingURL=ai21-rag-trace-comparison.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai21-rag-trace-comparison.test.js","sourceRoot":"","sources":["../../../src/instrumentation/__tests__/ai21-rag-trace-comparison.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;AAEH,8DAA0C;AAC1C,0DAAyC;AACzC,4DAA0C;AAC1C,mEAA0C;AAC1C,oFAA2D;AAE3D,IAAI,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AC,CAAC,oBAAoB,CAChD,6BAAkB,CAAC,kBAAkB,EACrC,6BAAkB,CAAC,uBAAuB,CAC3C,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,IAAI,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QAEnF,MAAM,iBAAW,CAAC,QAAQ,CAAC;YACzB,IAAI;YACJ,aAAa,EAAE,yBAAyB;YACxC,QAAQ,EAAE,eAAe,EAAE;YAC3B,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACxC,MAAM,CAAE,sBAAmB,CAAC,aAAa,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Cross-Language Trace Comparison Tests for the AI21 Integration
3
+ *
4
+ * These verify that the TypeScript AI21 instrumentation emits the same span
5
+ * attributes / events as the Python SDK reference
6
+ * (sdk/python/src/openlit/instrumentation/ai21). AI21's request surface has no
7
+ * seed / frequency_penalty / presence_penalty, and its responses carry no
8
+ * `model` field, so the response model falls back to the request model.
9
+ */
10
+ export {};