shield360 1.0.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 (520) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +310 -0
  3. package/dist/__tests__/manual-trace.test.d.ts +1 -0
  4. package/dist/__tests__/manual-trace.test.js +118 -0
  5. package/dist/__tests__/manual-trace.test.js.map +1 -0
  6. package/dist/__tests__/register.test.d.ts +0 -0
  7. package/dist/__tests__/register.test.js +90 -0
  8. package/dist/__tests__/register.test.js.map +1 -0
  9. package/dist/config.d.ts +28 -0
  10. package/dist/config.js +22 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/constant.d.ts +6 -0
  13. package/dist/constant.js +14 -0
  14. package/dist/constant.js.map +1 -0
  15. package/dist/evals/__tests__/offline.test.d.ts +1 -0
  16. package/dist/evals/__tests__/offline.test.js +427 -0
  17. package/dist/evals/__tests__/offline.test.js.map +1 -0
  18. package/dist/evals/index.d.ts +2 -0
  19. package/dist/evals/index.js +15 -0
  20. package/dist/evals/index.js.map +1 -0
  21. package/dist/evals/offline.d.ts +6 -0
  22. package/dist/evals/offline.js +350 -0
  23. package/dist/evals/offline.js.map +1 -0
  24. package/dist/evals/types.d.ts +74 -0
  25. package/dist/evals/types.js +23 -0
  26. package/dist/evals/types.js.map +1 -0
  27. package/dist/features/__tests__/rule-engine.test.d.ts +1 -0
  28. package/dist/features/__tests__/rule-engine.test.js +146 -0
  29. package/dist/features/__tests__/rule-engine.test.js.map +1 -0
  30. package/dist/features/base.d.ts +8 -0
  31. package/dist/features/base.js +15 -0
  32. package/dist/features/base.js.map +1 -0
  33. package/dist/features/prompt-hub.d.ts +4 -0
  34. package/dist/features/prompt-hub.js +66 -0
  35. package/dist/features/prompt-hub.js.map +1 -0
  36. package/dist/features/rule-engine.d.ts +6 -0
  37. package/dist/features/rule-engine.js +60 -0
  38. package/dist/features/rule-engine.js.map +1 -0
  39. package/dist/features/vault.d.ts +4 -0
  40. package/dist/features/vault.js +63 -0
  41. package/dist/features/vault.js.map +1 -0
  42. package/dist/guard/__tests__/findings.test.d.ts +1 -0
  43. package/dist/guard/__tests__/findings.test.js +79 -0
  44. package/dist/guard/__tests__/findings.test.js.map +1 -0
  45. package/dist/guard/__tests__/integration.test.d.ts +1 -0
  46. package/dist/guard/__tests__/integration.test.js +215 -0
  47. package/dist/guard/__tests__/integration.test.js.map +1 -0
  48. package/dist/guard/__tests__/pii.test.d.ts +1 -0
  49. package/dist/guard/__tests__/pii.test.js +131 -0
  50. package/dist/guard/__tests__/pii.test.js.map +1 -0
  51. package/dist/guard/__tests__/pipeline.test.d.ts +1 -0
  52. package/dist/guard/__tests__/pipeline.test.js +162 -0
  53. package/dist/guard/__tests__/pipeline.test.js.map +1 -0
  54. package/dist/guard/__tests__/prompt-injection.test.d.ts +1 -0
  55. package/dist/guard/__tests__/prompt-injection.test.js +92 -0
  56. package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
  57. package/dist/guard/__tests__/report.test.d.ts +1 -0
  58. package/dist/guard/__tests__/report.test.js +50 -0
  59. package/dist/guard/__tests__/report.test.js.map +1 -0
  60. package/dist/guard/base.d.ts +79 -0
  61. package/dist/guard/base.js +136 -0
  62. package/dist/guard/base.js.map +1 -0
  63. package/dist/guard/custom.d.ts +19 -0
  64. package/dist/guard/custom.js +46 -0
  65. package/dist/guard/custom.js.map +1 -0
  66. package/dist/guard/findings.d.ts +31 -0
  67. package/dist/guard/findings.js +156 -0
  68. package/dist/guard/findings.js.map +1 -0
  69. package/dist/guard/index.d.ts +24 -0
  70. package/dist/guard/index.js +42 -0
  71. package/dist/guard/index.js.map +1 -0
  72. package/dist/guard/integration.d.ts +44 -0
  73. package/dist/guard/integration.js +363 -0
  74. package/dist/guard/integration.js.map +1 -0
  75. package/dist/guard/moderation.d.ts +18 -0
  76. package/dist/guard/moderation.js +61 -0
  77. package/dist/guard/moderation.js.map +1 -0
  78. package/dist/guard/pii.d.ts +17 -0
  79. package/dist/guard/pii.js +114 -0
  80. package/dist/guard/pii.js.map +1 -0
  81. package/dist/guard/pipeline.d.ts +26 -0
  82. package/dist/guard/pipeline.js +139 -0
  83. package/dist/guard/pipeline.js.map +1 -0
  84. package/dist/guard/prompt-injection.d.ts +21 -0
  85. package/dist/guard/prompt-injection.js +70 -0
  86. package/dist/guard/prompt-injection.js.map +1 -0
  87. package/dist/guard/report.d.ts +34 -0
  88. package/dist/guard/report.js +182 -0
  89. package/dist/guard/report.js.map +1 -0
  90. package/dist/guard/schema.d.ts +20 -0
  91. package/dist/guard/schema.js +99 -0
  92. package/dist/guard/schema.js.map +1 -0
  93. package/dist/guard/sensitive-topic.d.ts +23 -0
  94. package/dist/guard/sensitive-topic.js +89 -0
  95. package/dist/guard/sensitive-topic.js.map +1 -0
  96. package/dist/guard/topic-restriction.d.ts +22 -0
  97. package/dist/guard/topic-restriction.js +54 -0
  98. package/dist/guard/topic-restriction.js.map +1 -0
  99. package/dist/helpers.d.ts +246 -0
  100. package/dist/helpers.js +903 -0
  101. package/dist/helpers.js.map +1 -0
  102. package/dist/index.d.ts +71 -0
  103. package/dist/index.js +234 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
  106. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
  107. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
  108. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
  109. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
  110. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
  111. package/dist/instrumentation/__tests__/anthropic-wrapper.test.d.ts +1 -0
  112. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +284 -0
  113. package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -0
  114. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.d.ts +1 -0
  115. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +284 -0
  116. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
  117. package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
  118. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
  119. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
  120. package/dist/instrumentation/__tests__/base-wrapper.test.d.ts +1 -0
  121. package/dist/instrumentation/__tests__/base-wrapper.test.js +171 -0
  122. package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -0
  123. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
  124. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
  125. package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
  126. package/dist/instrumentation/__tests__/browser-use-wrapper.test.d.ts +1 -0
  127. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
  128. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
  129. package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +15 -0
  130. package/dist/instrumentation/__tests__/cache-pricing.test.js +155 -0
  131. package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
  132. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.d.ts +18 -0
  133. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +209 -0
  134. package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -0
  135. package/dist/instrumentation/__tests__/cohere-wrapper.test.d.ts +1 -0
  136. package/dist/instrumentation/__tests__/cohere-wrapper.test.js +256 -0
  137. package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -0
  138. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
  139. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
  140. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
  141. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
  142. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
  143. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
  144. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.d.ts +4 -0
  145. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +229 -0
  146. package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -0
  147. package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
  148. package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
  149. package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
  150. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
  151. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
  152. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
  153. package/dist/instrumentation/__tests__/groq-trace-comparison.test.d.ts +7 -0
  154. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +687 -0
  155. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -0
  156. package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
  157. package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
  158. package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
  159. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +7 -0
  160. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +529 -0
  161. package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -0
  162. package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
  163. package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
  164. package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
  165. package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
  166. package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
  167. package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
  168. package/dist/instrumentation/__tests__/letta-wrapper.test.d.ts +1 -0
  169. package/dist/instrumentation/__tests__/letta-wrapper.test.js +285 -0
  170. package/dist/instrumentation/__tests__/letta-wrapper.test.js.map +1 -0
  171. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
  172. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
  173. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
  174. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.d.ts +17 -0
  175. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +206 -0
  176. package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -0
  177. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +1 -0
  178. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +345 -0
  179. package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -0
  180. package/dist/instrumentation/__tests__/openai-wrapper.test.d.ts +1 -0
  181. package/dist/instrumentation/__tests__/openai-wrapper.test.js +179 -0
  182. package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -0
  183. package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
  184. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
  185. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
  186. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.d.ts +17 -0
  187. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +182 -0
  188. package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -0
  189. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +8 -0
  190. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +346 -0
  191. package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -0
  192. package/dist/instrumentation/__tests__/together-trace-comparison.test.d.ts +4 -0
  193. package/dist/instrumentation/__tests__/together-trace-comparison.test.js +289 -0
  194. package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -0
  195. package/dist/instrumentation/__tests__/trace-comparison-utils.d.ts +67 -0
  196. package/dist/instrumentation/__tests__/trace-comparison-utils.js +255 -0
  197. package/dist/instrumentation/__tests__/trace-comparison-utils.js.map +1 -0
  198. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
  199. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
  200. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
  201. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
  202. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
  203. package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
  204. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
  205. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
  206. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
  207. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
  208. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
  209. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
  210. package/dist/instrumentation/ai21/index.d.ts +11 -0
  211. package/dist/instrumentation/ai21/index.js +67 -0
  212. package/dist/instrumentation/ai21/index.js.map +1 -0
  213. package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
  214. package/dist/instrumentation/ai21/wrapper.js +511 -0
  215. package/dist/instrumentation/ai21/wrapper.js.map +1 -0
  216. package/dist/instrumentation/anthropic/index.d.ts +11 -0
  217. package/dist/instrumentation/anthropic/index.js +45 -0
  218. package/dist/instrumentation/anthropic/index.js.map +1 -0
  219. package/dist/instrumentation/anthropic/wrapper.d.ts +34 -0
  220. package/dist/instrumentation/anthropic/wrapper.js +426 -0
  221. package/dist/instrumentation/anthropic/wrapper.js.map +1 -0
  222. package/dist/instrumentation/assemblyai/index.d.ts +12 -0
  223. package/dist/instrumentation/assemblyai/index.js +91 -0
  224. package/dist/instrumentation/assemblyai/index.js.map +1 -0
  225. package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
  226. package/dist/instrumentation/assemblyai/wrapper.js +238 -0
  227. package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
  228. package/dist/instrumentation/astra/index.d.ts +11 -0
  229. package/dist/instrumentation/astra/index.js +87 -0
  230. package/dist/instrumentation/astra/index.js.map +1 -0
  231. package/dist/instrumentation/astra/wrapper.d.ts +39 -0
  232. package/dist/instrumentation/astra/wrapper.js +349 -0
  233. package/dist/instrumentation/astra/wrapper.js.map +1 -0
  234. package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
  235. package/dist/instrumentation/azure-ai-inference/index.js +76 -0
  236. package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
  237. package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +55 -0
  238. package/dist/instrumentation/azure-ai-inference/wrapper.js +580 -0
  239. package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
  240. package/dist/instrumentation/base-wrapper.d.ts +16 -0
  241. package/dist/instrumentation/base-wrapper.js +139 -0
  242. package/dist/instrumentation/base-wrapper.js.map +1 -0
  243. package/dist/instrumentation/bedrock/index.d.ts +11 -0
  244. package/dist/instrumentation/bedrock/index.js +52 -0
  245. package/dist/instrumentation/bedrock/index.js.map +1 -0
  246. package/dist/instrumentation/bedrock/wrapper.d.ts +41 -0
  247. package/dist/instrumentation/bedrock/wrapper.js +494 -0
  248. package/dist/instrumentation/bedrock/wrapper.js.map +1 -0
  249. package/dist/instrumentation/browser-use/index.d.ts +11 -0
  250. package/dist/instrumentation/browser-use/index.js +98 -0
  251. package/dist/instrumentation/browser-use/index.js.map +1 -0
  252. package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
  253. package/dist/instrumentation/browser-use/wrapper.js +706 -0
  254. package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
  255. package/dist/instrumentation/chroma/index.d.ts +11 -0
  256. package/dist/instrumentation/chroma/index.js +70 -0
  257. package/dist/instrumentation/chroma/index.js.map +1 -0
  258. package/dist/instrumentation/chroma/wrapper.d.ts +10 -0
  259. package/dist/instrumentation/chroma/wrapper.js +127 -0
  260. package/dist/instrumentation/chroma/wrapper.js.map +1 -0
  261. package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
  262. package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
  263. package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
  264. package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
  265. package/dist/instrumentation/claude-agent-sdk/wrapper.js +1123 -0
  266. package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
  267. package/dist/instrumentation/cohere/index.d.ts +11 -0
  268. package/dist/instrumentation/cohere/index.js +53 -0
  269. package/dist/instrumentation/cohere/index.js.map +1 -0
  270. package/dist/instrumentation/cohere/wrapper.d.ts +50 -0
  271. package/dist/instrumentation/cohere/wrapper.js +452 -0
  272. package/dist/instrumentation/cohere/wrapper.js.map +1 -0
  273. package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
  274. package/dist/instrumentation/cursor-sdk/index.js +58 -0
  275. package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
  276. package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
  277. package/dist/instrumentation/cursor-sdk/wrapper.js +789 -0
  278. package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
  279. package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
  280. package/dist/instrumentation/elevenlabs/index.js +92 -0
  281. package/dist/instrumentation/elevenlabs/index.js.map +1 -0
  282. package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
  283. package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
  284. package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
  285. package/dist/instrumentation/firecrawl/index.d.ts +13 -0
  286. package/dist/instrumentation/firecrawl/index.js +115 -0
  287. package/dist/instrumentation/firecrawl/index.js.map +1 -0
  288. package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
  289. package/dist/instrumentation/firecrawl/wrapper.js +378 -0
  290. package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
  291. package/dist/instrumentation/google-adk/index.d.ts +57 -0
  292. package/dist/instrumentation/google-adk/index.js +371 -0
  293. package/dist/instrumentation/google-adk/index.js.map +1 -0
  294. package/dist/instrumentation/google-adk/utils.d.ts +45 -0
  295. package/dist/instrumentation/google-adk/utils.js +663 -0
  296. package/dist/instrumentation/google-adk/utils.js.map +1 -0
  297. package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
  298. package/dist/instrumentation/google-adk/wrapper.js +391 -0
  299. package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
  300. package/dist/instrumentation/google-ai/index.d.ts +11 -0
  301. package/dist/instrumentation/google-ai/index.js +48 -0
  302. package/dist/instrumentation/google-ai/index.js.map +1 -0
  303. package/dist/instrumentation/google-ai/wrapper.d.ts +52 -0
  304. package/dist/instrumentation/google-ai/wrapper.js +466 -0
  305. package/dist/instrumentation/google-ai/wrapper.js.map +1 -0
  306. package/dist/instrumentation/gpu/index.d.ts +38 -0
  307. package/dist/instrumentation/gpu/index.js +233 -0
  308. package/dist/instrumentation/gpu/index.js.map +1 -0
  309. package/dist/instrumentation/gradient/index.d.ts +12 -0
  310. package/dist/instrumentation/gradient/index.js +74 -0
  311. package/dist/instrumentation/gradient/index.js.map +1 -0
  312. package/dist/instrumentation/gradient/utils.d.ts +14 -0
  313. package/dist/instrumentation/gradient/utils.js +119 -0
  314. package/dist/instrumentation/gradient/utils.js.map +1 -0
  315. package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
  316. package/dist/instrumentation/gradient/wrapper.js +584 -0
  317. package/dist/instrumentation/gradient/wrapper.js.map +1 -0
  318. package/dist/instrumentation/groq/index.d.ts +11 -0
  319. package/dist/instrumentation/groq/index.js +43 -0
  320. package/dist/instrumentation/groq/index.js.map +1 -0
  321. package/dist/instrumentation/groq/wrapper.d.ts +35 -0
  322. package/dist/instrumentation/groq/wrapper.js +442 -0
  323. package/dist/instrumentation/groq/wrapper.js.map +1 -0
  324. package/dist/instrumentation/huggingface/index.d.ts +13 -0
  325. package/dist/instrumentation/huggingface/index.js +110 -0
  326. package/dist/instrumentation/huggingface/index.js.map +1 -0
  327. package/dist/instrumentation/huggingface/wrapper.d.ts +54 -0
  328. package/dist/instrumentation/huggingface/wrapper.js +514 -0
  329. package/dist/instrumentation/huggingface/wrapper.js.map +1 -0
  330. package/dist/instrumentation/index.d.ts +7 -0
  331. package/dist/instrumentation/index.js +176 -0
  332. package/dist/instrumentation/index.js.map +1 -0
  333. package/dist/instrumentation/langchain/index.d.ts +16 -0
  334. package/dist/instrumentation/langchain/index.js +91 -0
  335. package/dist/instrumentation/langchain/index.js.map +1 -0
  336. package/dist/instrumentation/langchain/wrapper.d.ts +41 -0
  337. package/dist/instrumentation/langchain/wrapper.js +1235 -0
  338. package/dist/instrumentation/langchain/wrapper.js.map +1 -0
  339. package/dist/instrumentation/langgraph/index.d.ts +12 -0
  340. package/dist/instrumentation/langgraph/index.js +99 -0
  341. package/dist/instrumentation/langgraph/index.js.map +1 -0
  342. package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
  343. package/dist/instrumentation/langgraph/wrapper.js +620 -0
  344. package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
  345. package/dist/instrumentation/letta/index.d.ts +10 -0
  346. package/dist/instrumentation/letta/index.js +122 -0
  347. package/dist/instrumentation/letta/index.js.map +1 -0
  348. package/dist/instrumentation/letta/utils.d.ts +24 -0
  349. package/dist/instrumentation/letta/utils.js +343 -0
  350. package/dist/instrumentation/letta/utils.js.map +1 -0
  351. package/dist/instrumentation/letta/wrapper.d.ts +37 -0
  352. package/dist/instrumentation/letta/wrapper.js +180 -0
  353. package/dist/instrumentation/letta/wrapper.js.map +1 -0
  354. package/dist/instrumentation/llamaindex/index.d.ts +36 -0
  355. package/dist/instrumentation/llamaindex/index.js +221 -0
  356. package/dist/instrumentation/llamaindex/index.js.map +1 -0
  357. package/dist/instrumentation/llamaindex/wrapper.d.ts +36 -0
  358. package/dist/instrumentation/llamaindex/wrapper.js +811 -0
  359. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -0
  360. package/dist/instrumentation/mcp/index.d.ts +20 -0
  361. package/dist/instrumentation/mcp/index.js +282 -0
  362. package/dist/instrumentation/mcp/index.js.map +1 -0
  363. package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
  364. package/dist/instrumentation/mcp/wrapper.js +571 -0
  365. package/dist/instrumentation/mcp/wrapper.js.map +1 -0
  366. package/dist/instrumentation/mem0/index.d.ts +17 -0
  367. package/dist/instrumentation/mem0/index.js +113 -0
  368. package/dist/instrumentation/mem0/index.js.map +1 -0
  369. package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
  370. package/dist/instrumentation/mem0/wrapper.js +298 -0
  371. package/dist/instrumentation/mem0/wrapper.js.map +1 -0
  372. package/dist/instrumentation/milvus/index.d.ts +11 -0
  373. package/dist/instrumentation/milvus/index.js +67 -0
  374. package/dist/instrumentation/milvus/index.js.map +1 -0
  375. package/dist/instrumentation/milvus/wrapper.d.ts +15 -0
  376. package/dist/instrumentation/milvus/wrapper.js +219 -0
  377. package/dist/instrumentation/milvus/wrapper.js.map +1 -0
  378. package/dist/instrumentation/mistral/index.d.ts +11 -0
  379. package/dist/instrumentation/mistral/index.js +66 -0
  380. package/dist/instrumentation/mistral/index.js.map +1 -0
  381. package/dist/instrumentation/mistral/wrapper.d.ts +49 -0
  382. package/dist/instrumentation/mistral/wrapper.js +482 -0
  383. package/dist/instrumentation/mistral/wrapper.js.map +1 -0
  384. package/dist/instrumentation/ollama/index.d.ts +11 -0
  385. package/dist/instrumentation/ollama/index.js +72 -0
  386. package/dist/instrumentation/ollama/index.js.map +1 -0
  387. package/dist/instrumentation/ollama/wrapper.d.ts +73 -0
  388. package/dist/instrumentation/ollama/wrapper.js +629 -0
  389. package/dist/instrumentation/ollama/wrapper.js.map +1 -0
  390. package/dist/instrumentation/openai/index.d.ts +11 -0
  391. package/dist/instrumentation/openai/index.js +79 -0
  392. package/dist/instrumentation/openai/index.js.map +1 -0
  393. package/dist/instrumentation/openai/wrapper.d.ts +80 -0
  394. package/dist/instrumentation/openai/wrapper.js +1121 -0
  395. package/dist/instrumentation/openai/wrapper.js.map +1 -0
  396. package/dist/instrumentation/openai-agents/index.d.ts +20 -0
  397. package/dist/instrumentation/openai-agents/index.js +174 -0
  398. package/dist/instrumentation/openai-agents/index.js.map +1 -0
  399. package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
  400. package/dist/instrumentation/openai-agents/processor.js +249 -0
  401. package/dist/instrumentation/openai-agents/processor.js.map +1 -0
  402. package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
  403. package/dist/instrumentation/openai-agents/utils.js +624 -0
  404. package/dist/instrumentation/openai-agents/utils.js.map +1 -0
  405. package/dist/instrumentation/pg/index.d.ts +20 -0
  406. package/dist/instrumentation/pg/index.js +74 -0
  407. package/dist/instrumentation/pg/index.js.map +1 -0
  408. package/dist/instrumentation/pg/wrapper.d.ts +66 -0
  409. package/dist/instrumentation/pg/wrapper.js +441 -0
  410. package/dist/instrumentation/pg/wrapper.js.map +1 -0
  411. package/dist/instrumentation/pinecone/index.d.ts +11 -0
  412. package/dist/instrumentation/pinecone/index.js +79 -0
  413. package/dist/instrumentation/pinecone/index.js.map +1 -0
  414. package/dist/instrumentation/pinecone/wrapper.d.ts +14 -0
  415. package/dist/instrumentation/pinecone/wrapper.js +198 -0
  416. package/dist/instrumentation/pinecone/wrapper.js.map +1 -0
  417. package/dist/instrumentation/qdrant/index.d.ts +11 -0
  418. package/dist/instrumentation/qdrant/index.js +67 -0
  419. package/dist/instrumentation/qdrant/index.js.map +1 -0
  420. package/dist/instrumentation/qdrant/wrapper.d.ts +14 -0
  421. package/dist/instrumentation/qdrant/wrapper.js +213 -0
  422. package/dist/instrumentation/qdrant/wrapper.js.map +1 -0
  423. package/dist/instrumentation/replicate/index.d.ts +11 -0
  424. package/dist/instrumentation/replicate/index.js +57 -0
  425. package/dist/instrumentation/replicate/index.js.map +1 -0
  426. package/dist/instrumentation/replicate/wrapper.d.ts +28 -0
  427. package/dist/instrumentation/replicate/wrapper.js +242 -0
  428. package/dist/instrumentation/replicate/wrapper.js.map +1 -0
  429. package/dist/instrumentation/strands/index.d.ts +21 -0
  430. package/dist/instrumentation/strands/index.js +83 -0
  431. package/dist/instrumentation/strands/index.js.map +1 -0
  432. package/dist/instrumentation/strands/processor.d.ts +51 -0
  433. package/dist/instrumentation/strands/processor.js +625 -0
  434. package/dist/instrumentation/strands/processor.js.map +1 -0
  435. package/dist/instrumentation/strands/utils.d.ts +24 -0
  436. package/dist/instrumentation/strands/utils.js +373 -0
  437. package/dist/instrumentation/strands/utils.js.map +1 -0
  438. package/dist/instrumentation/together/index.d.ts +11 -0
  439. package/dist/instrumentation/together/index.js +43 -0
  440. package/dist/instrumentation/together/index.js.map +1 -0
  441. package/dist/instrumentation/together/wrapper.d.ts +48 -0
  442. package/dist/instrumentation/together/wrapper.js +409 -0
  443. package/dist/instrumentation/together/wrapper.js.map +1 -0
  444. package/dist/instrumentation/transformers/index.d.ts +35 -0
  445. package/dist/instrumentation/transformers/index.js +119 -0
  446. package/dist/instrumentation/transformers/index.js.map +1 -0
  447. package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
  448. package/dist/instrumentation/transformers/wrapper.js +472 -0
  449. package/dist/instrumentation/transformers/wrapper.js.map +1 -0
  450. package/dist/instrumentation/vercel-ai/index.d.ts +10 -0
  451. package/dist/instrumentation/vercel-ai/index.js +59 -0
  452. package/dist/instrumentation/vercel-ai/index.js.map +1 -0
  453. package/dist/instrumentation/vercel-ai/wrapper.d.ts +50 -0
  454. package/dist/instrumentation/vercel-ai/wrapper.js +539 -0
  455. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -0
  456. package/dist/instrumentation/vertexai/index.d.ts +11 -0
  457. package/dist/instrumentation/vertexai/index.js +70 -0
  458. package/dist/instrumentation/vertexai/index.js.map +1 -0
  459. package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
  460. package/dist/instrumentation/vertexai/wrapper.js +530 -0
  461. package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
  462. package/dist/instrumentation/vllm/index.d.ts +13 -0
  463. package/dist/instrumentation/vllm/index.js +67 -0
  464. package/dist/instrumentation/vllm/index.js.map +1 -0
  465. package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
  466. package/dist/instrumentation/vllm/wrapper.js +482 -0
  467. package/dist/instrumentation/vllm/wrapper.js.map +1 -0
  468. package/dist/llm/anthropic.d.ts +5 -0
  469. package/dist/llm/anthropic.js +39 -0
  470. package/dist/llm/anthropic.js.map +1 -0
  471. package/dist/llm/index.d.ts +10 -0
  472. package/dist/llm/index.js +93 -0
  473. package/dist/llm/index.js.map +1 -0
  474. package/dist/llm/openai.d.ts +6 -0
  475. package/dist/llm/openai.js +52 -0
  476. package/dist/llm/openai.js.map +1 -0
  477. package/dist/llm/providers.d.ts +7 -0
  478. package/dist/llm/providers.js +10 -0
  479. package/dist/llm/providers.js.map +1 -0
  480. package/dist/manual-trace.d.ts +40 -0
  481. package/dist/manual-trace.js +103 -0
  482. package/dist/manual-trace.js.map +1 -0
  483. package/dist/otel/__tests__/metrics.test.d.ts +1 -0
  484. package/dist/otel/__tests__/metrics.test.js +40 -0
  485. package/dist/otel/__tests__/metrics.test.js.map +1 -0
  486. package/dist/otel/events.d.ts +11 -0
  487. package/dist/otel/events.js +74 -0
  488. package/dist/otel/events.js.map +1 -0
  489. package/dist/otel/metrics.d.ts +35 -0
  490. package/dist/otel/metrics.js +219 -0
  491. package/dist/otel/metrics.js.map +1 -0
  492. package/dist/otel/tracing.d.ts +12 -0
  493. package/dist/otel/tracing.js +93 -0
  494. package/dist/otel/tracing.js.map +1 -0
  495. package/dist/otel/utils.d.ts +11 -0
  496. package/dist/otel/utils.js +34 -0
  497. package/dist/otel/utils.js.map +1 -0
  498. package/dist/pricing.json +951 -0
  499. package/dist/prompt-hub.d.ts +4 -0
  500. package/dist/prompt-hub.js +66 -0
  501. package/dist/prompt-hub.js.map +1 -0
  502. package/dist/register.d.ts +4 -0
  503. package/dist/register.js +52 -0
  504. package/dist/register.js.map +1 -0
  505. package/dist/score/__tests__/score.test.d.ts +1 -0
  506. package/dist/score/__tests__/score.test.js +143 -0
  507. package/dist/score/__tests__/score.test.js.map +1 -0
  508. package/dist/score/index.d.ts +2 -0
  509. package/dist/score/index.js +6 -0
  510. package/dist/score/index.js.map +1 -0
  511. package/dist/score/score.d.ts +15 -0
  512. package/dist/score/score.js +135 -0
  513. package/dist/score/score.js.map +1 -0
  514. package/dist/semantic-convention.d.ts +555 -0
  515. package/dist/semantic-convention.js +630 -0
  516. package/dist/semantic-convention.js.map +1 -0
  517. package/dist/types.d.ts +131 -0
  518. package/dist/types.js +3 -0
  519. package/dist/types.js.map +1 -0
  520. package/package.json +136 -0
@@ -0,0 +1,687 @@
1
+ "use strict";
2
+ /**
3
+ * Cross-Language Trace Comparison Tests for Groq Integration
4
+ *
5
+ * These tests verify that TypeScript and Python generate equivalent traces
6
+ * for the same operations.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const wrapper_1 = __importDefault(require("../groq/wrapper"));
13
+ const config_1 = __importDefault(require("../../config"));
14
+ const helpers_1 = __importDefault(require("../../helpers"));
15
+ const base_wrapper_1 = __importDefault(require("../base-wrapper"));
16
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
17
+ jest.mock('../../config');
18
+ jest.mock('../../helpers');
19
+ jest.mock('../base-wrapper');
20
+ describe('Groq Cross-Language Trace Comparison', () => {
21
+ let mockSpan;
22
+ let _mockTracer;
23
+ beforeEach(() => {
24
+ mockSpan = {
25
+ setAttribute: jest.fn(),
26
+ addEvent: jest.fn(),
27
+ end: jest.fn(),
28
+ setStatus: jest.fn(),
29
+ };
30
+ _mockTracer = {
31
+ startSpan: jest.fn().mockReturnValue(mockSpan),
32
+ };
33
+ config_1.default.environment = 'shield360-testing';
34
+ config_1.default.applicationName = 'shield360-test';
35
+ config_1.default.captureMessageContent = true;
36
+ config_1.default.pricingInfo = {};
37
+ config_1.default.disableEvents = false;
38
+ helpers_1.default.getChatModelCost = jest.fn().mockReturnValue(0.001);
39
+ helpers_1.default.openaiTokens = jest.fn().mockReturnValue(5);
40
+ helpers_1.default.handleException = jest.fn();
41
+ helpers_1.default.createStreamProxy = jest.fn().mockImplementation((stream, _generator) => stream);
42
+ helpers_1.default.buildInputMessages = jest.fn().mockReturnValue('[{"role":"user","parts":[{"type":"text","content":"Test"}]}]');
43
+ helpers_1.default.buildOutputMessages = jest.fn().mockReturnValue('[{"role":"assistant","parts":[{"type":"text","content":"Response"}],"finish_reason":"stop"}]');
44
+ helpers_1.default.buildSystemInstructionsFromMessages = jest.fn().mockImplementation((messages) => {
45
+ const sys = (messages || []).find((m) => m?.role === 'system');
46
+ return sys ? JSON.stringify([{ type: 'text', content: String(sys.content) }]) : undefined;
47
+ });
48
+ helpers_1.default.buildToolDefinitions = jest.fn().mockImplementation((tools) => {
49
+ if (!Array.isArray(tools) || tools.length === 0)
50
+ return undefined;
51
+ return JSON.stringify(tools
52
+ .filter((t) => t?.function?.name || t?.name)
53
+ .map((t) => ({
54
+ type: 'function',
55
+ name: t.function?.name ?? t.name,
56
+ description: t.function?.description ?? t.description ?? '',
57
+ parameters: t.function?.parameters ?? t.parameters ?? {},
58
+ })));
59
+ });
60
+ helpers_1.default.emitInferenceEvent = jest.fn();
61
+ // Stamp a deterministic agent version hash so the assertions below can
62
+ // pin the exact attribute value. The real helper would canonicalise the
63
+ // prompt + tools + model + runtime config — none of which matters for
64
+ // verifying the wrapper *plumbs* the result onto the span.
65
+ helpers_1.default.computeAgentVersionHash = jest
66
+ .fn()
67
+ .mockReturnValue('ts-test-version-hash');
68
+ base_wrapper_1.default.recordMetrics = jest.fn();
69
+ base_wrapper_1.default.setBaseSpanAttributes = jest.fn().mockImplementation((span, attrs) => {
70
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, attrs.aiSystem);
71
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, attrs.model);
72
+ if (attrs.cost !== undefined) {
73
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COST, attrs.cost);
74
+ }
75
+ if (attrs.serverAddress) {
76
+ span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, attrs.serverAddress);
77
+ }
78
+ if (attrs.serverPort !== undefined) {
79
+ span.setAttribute(semantic_convention_1.default.SERVER_PORT, attrs.serverPort);
80
+ }
81
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, '1.9.0');
82
+ });
83
+ });
84
+ afterEach(() => {
85
+ jest.clearAllMocks();
86
+ });
87
+ describe('Chat Completion Trace Consistency', () => {
88
+ it('should set same attributes as Python SDK', async () => {
89
+ const mockArgs = [
90
+ {
91
+ messages: [{ role: 'user', content: 'What is LLM Observability?' }],
92
+ model: 'llama-3.1-8b-instant',
93
+ max_tokens: 100,
94
+ temperature: 0.7,
95
+ stream: false,
96
+ },
97
+ ];
98
+ const mockResponse = {
99
+ id: 'test-id-123',
100
+ created: Date.now(),
101
+ model: 'llama-3.1-8b-instant',
102
+ choices: [
103
+ {
104
+ index: 0,
105
+ finish_reason: 'stop',
106
+ message: { role: 'assistant', content: 'LLM Observability is...' },
107
+ },
108
+ ],
109
+ usage: {
110
+ prompt_tokens: 10,
111
+ completion_tokens: 20,
112
+ total_tokens: 30,
113
+ },
114
+ };
115
+ await wrapper_1.default._chatCompletion({
116
+ args: mockArgs,
117
+ genAIEndpoint: 'groq.chat.completions',
118
+ response: mockResponse,
119
+ span: mockSpan,
120
+ });
121
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, 'groq');
122
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, 'llama-3.1-8b-instant');
123
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, 'llama-3.1-8b-instant');
124
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_ID, 'test-id-123');
125
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, 10);
126
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, 20);
127
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_TEMPERATURE, 0.7);
128
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, 100);
129
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, false);
130
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, ['stop']);
131
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, 'text');
132
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_ADDRESS, 'api.groq.com');
133
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_PORT, 443);
134
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_SDK_VERSION, '1.9.0');
135
+ });
136
+ it('stamps shield360.agent.version_hash on the chat span', async () => {
137
+ const mockArgs = [
138
+ {
139
+ messages: [{ role: 'user', content: 'Hash me' }],
140
+ model: 'llama-3.1-8b-instant',
141
+ stream: false,
142
+ },
143
+ ];
144
+ const mockResponse = {
145
+ id: 'hash-id',
146
+ created: Date.now(),
147
+ model: 'llama-3.1-8b-instant',
148
+ choices: [
149
+ { index: 0, finish_reason: 'stop', message: { role: 'assistant', content: 'ok' } },
150
+ ],
151
+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
152
+ };
153
+ await wrapper_1.default._chatCompletion({
154
+ args: mockArgs,
155
+ genAIEndpoint: 'groq.chat.completions',
156
+ response: mockResponse,
157
+ span: mockSpan,
158
+ });
159
+ expect(helpers_1.default.computeAgentVersionHash).toHaveBeenCalled();
160
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH, 'ts-test-version-hash');
161
+ });
162
+ it('should NOT set total_tokens or client.token.usage on span', async () => {
163
+ const mockArgs = [
164
+ {
165
+ messages: [{ role: 'user', content: 'Test' }],
166
+ model: 'llama-3.1-8b-instant',
167
+ stream: false,
168
+ },
169
+ ];
170
+ const mockResponse = {
171
+ id: 'test',
172
+ model: 'llama-3.1-8b-instant',
173
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
174
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
175
+ };
176
+ await wrapper_1.default._chatCompletion({
177
+ args: mockArgs,
178
+ genAIEndpoint: 'groq.chat.completions',
179
+ response: mockResponse,
180
+ span: mockSpan,
181
+ });
182
+ const setAttributeCalls = mockSpan.setAttribute.mock.calls;
183
+ const attributeKeys = setAttributeCalls.map(([key]) => key);
184
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_USAGE_TOTAL_TOKENS);
185
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_CLIENT_TOKEN_USAGE);
186
+ });
187
+ it('should not set sentinel values for optional params', async () => {
188
+ const mockArgs = [
189
+ {
190
+ messages: [{ role: 'user', content: 'Test' }],
191
+ model: 'llama-3.1-8b-instant',
192
+ stream: false,
193
+ },
194
+ ];
195
+ const mockResponse = {
196
+ id: 'test',
197
+ model: 'llama-3.1-8b-instant',
198
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
199
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
200
+ };
201
+ await wrapper_1.default._chatCompletion({
202
+ args: mockArgs,
203
+ genAIEndpoint: 'groq.chat.completions',
204
+ response: mockResponse,
205
+ span: mockSpan,
206
+ });
207
+ const setAttributeCalls = mockSpan.setAttribute.mock.calls;
208
+ const attributeKeys = setAttributeCalls.map(([key]) => key);
209
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_SEED);
210
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY);
211
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_PRESENCE_PENALTY);
212
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS);
213
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES);
214
+ expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_CHOICE_COUNT);
215
+ });
216
+ it('should set conditional params only when explicitly provided', async () => {
217
+ const mockArgs = [
218
+ {
219
+ messages: [{ role: 'user', content: 'Test' }],
220
+ model: 'llama-3.1-8b-instant',
221
+ max_tokens: 200,
222
+ seed: 42,
223
+ frequency_penalty: 0.5,
224
+ presence_penalty: 0.3,
225
+ stop: ['END'],
226
+ n: 2,
227
+ stream: false,
228
+ },
229
+ ];
230
+ const mockResponse = {
231
+ id: 'test',
232
+ model: 'llama-3.1-8b-instant',
233
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
234
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
235
+ };
236
+ await wrapper_1.default._chatCompletion({
237
+ args: mockArgs,
238
+ genAIEndpoint: 'groq.chat.completions',
239
+ response: mockResponse,
240
+ span: mockSpan,
241
+ });
242
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, 200);
243
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_SEED, 42);
244
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY, 0.5);
245
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_PRESENCE_PENALTY, 0.3);
246
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES, ['END']);
247
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_CHOICE_COUNT, 2);
248
+ });
249
+ it('should emit inference event via LoggerProvider', async () => {
250
+ const mockArgs = [
251
+ {
252
+ messages: [{ role: 'user', content: 'Test' }],
253
+ model: 'llama-3.1-8b-instant',
254
+ stream: false,
255
+ },
256
+ ];
257
+ const mockResponse = {
258
+ id: 'test-id',
259
+ model: 'llama-3.1-8b-instant',
260
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
261
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
262
+ };
263
+ await wrapper_1.default._chatCompletion({
264
+ args: mockArgs,
265
+ genAIEndpoint: 'groq.chat.completions',
266
+ response: mockResponse,
267
+ span: mockSpan,
268
+ });
269
+ expect(helpers_1.default.emitInferenceEvent).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
270
+ [semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
271
+ [semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: 'llama-3.1-8b-instant',
272
+ [semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: 'llama-3.1-8b-instant',
273
+ [semantic_convention_1.default.SERVER_ADDRESS]: 'api.groq.com',
274
+ [semantic_convention_1.default.SERVER_PORT]: 443,
275
+ [semantic_convention_1.default.GEN_AI_RESPONSE_ID]: 'test-id',
276
+ [semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: ['stop'],
277
+ [semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: 5,
278
+ [semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: 10,
279
+ }));
280
+ });
281
+ it('should include message content in event when captureMessageContent is true', async () => {
282
+ config_1.default.captureMessageContent = true;
283
+ const mockArgs = [
284
+ {
285
+ messages: [{ role: 'user', content: 'Test' }],
286
+ model: 'llama-3.1-8b-instant',
287
+ stream: false,
288
+ },
289
+ ];
290
+ const mockResponse = {
291
+ id: 'test-id',
292
+ model: 'llama-3.1-8b-instant',
293
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
294
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
295
+ };
296
+ await wrapper_1.default._chatCompletion({
297
+ args: mockArgs,
298
+ genAIEndpoint: 'groq.chat.completions',
299
+ response: mockResponse,
300
+ span: mockSpan,
301
+ });
302
+ expect(helpers_1.default.emitInferenceEvent).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
303
+ [semantic_convention_1.default.GEN_AI_INPUT_MESSAGES]: expect.any(String),
304
+ [semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES]: expect.any(String),
305
+ }));
306
+ });
307
+ it('should NOT include message content in event when captureMessageContent is false', async () => {
308
+ config_1.default.captureMessageContent = false;
309
+ const mockArgs = [
310
+ {
311
+ messages: [{ role: 'user', content: 'Test' }],
312
+ model: 'llama-3.1-8b-instant',
313
+ stream: false,
314
+ },
315
+ ];
316
+ const mockResponse = {
317
+ id: 'test-id',
318
+ model: 'llama-3.1-8b-instant',
319
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
320
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
321
+ };
322
+ await wrapper_1.default._chatCompletion({
323
+ args: mockArgs,
324
+ genAIEndpoint: 'groq.chat.completions',
325
+ response: mockResponse,
326
+ span: mockSpan,
327
+ });
328
+ const eventCall = helpers_1.default.emitInferenceEvent.mock.calls[0];
329
+ const eventAttrs = eventCall[1];
330
+ expect(eventAttrs).not.toHaveProperty(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES);
331
+ expect(eventAttrs).not.toHaveProperty(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES);
332
+ });
333
+ it('should handle tool calls properly', async () => {
334
+ const mockArgs = [
335
+ {
336
+ messages: [{ role: 'user', content: 'What is the weather?' }],
337
+ model: 'llama-3.1-8b-instant',
338
+ tools: [{ type: 'function', function: { name: 'get_weather' } }],
339
+ stream: false,
340
+ },
341
+ ];
342
+ const mockResponse = {
343
+ id: 'test-id',
344
+ model: 'llama-3.1-8b-instant',
345
+ choices: [
346
+ {
347
+ message: {
348
+ content: null,
349
+ role: 'assistant',
350
+ tool_calls: [
351
+ {
352
+ id: 'call_123',
353
+ type: 'function',
354
+ function: { name: 'get_weather', arguments: '{"location":"SF"}' },
355
+ },
356
+ ],
357
+ },
358
+ finish_reason: 'tool_calls',
359
+ },
360
+ ],
361
+ usage: { prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 },
362
+ };
363
+ await wrapper_1.default._chatCompletion({
364
+ args: mockArgs,
365
+ genAIEndpoint: 'groq.chat.completions',
366
+ response: mockResponse,
367
+ span: mockSpan,
368
+ });
369
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_NAME, 'get_weather');
370
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, 'call_123');
371
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_ARGS, '{"location":"SF"}');
372
+ });
373
+ it('should set system_fingerprint when present', async () => {
374
+ const mockArgs = [
375
+ {
376
+ messages: [{ role: 'user', content: 'Test' }],
377
+ model: 'llama-3.1-8b-instant',
378
+ stream: false,
379
+ },
380
+ ];
381
+ const mockResponse = {
382
+ id: 'test-id',
383
+ model: 'llama-3.1-8b-instant',
384
+ system_fingerprint: 'fp_groq_test',
385
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
386
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
387
+ };
388
+ await wrapper_1.default._chatCompletion({
389
+ args: mockArgs,
390
+ genAIEndpoint: 'groq.chat.completions',
391
+ response: mockResponse,
392
+ span: mockSpan,
393
+ });
394
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT, 'fp_groq_test');
395
+ });
396
+ it('should record metrics via BaseWrapper.recordMetrics', async () => {
397
+ const mockArgs = [
398
+ {
399
+ messages: [{ role: 'user', content: 'Test' }],
400
+ model: 'llama-3.1-8b-instant',
401
+ stream: false,
402
+ },
403
+ ];
404
+ const mockResponse = {
405
+ id: 'test',
406
+ model: 'llama-3.1-8b-instant',
407
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
408
+ usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
409
+ };
410
+ await wrapper_1.default._chatCompletion({
411
+ args: mockArgs,
412
+ genAIEndpoint: 'groq.chat.completions',
413
+ response: mockResponse,
414
+ span: mockSpan,
415
+ });
416
+ expect(base_wrapper_1.default.recordMetrics).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
417
+ genAIEndpoint: 'groq.chat.completions',
418
+ model: 'llama-3.1-8b-instant',
419
+ aiSystem: 'groq',
420
+ }));
421
+ });
422
+ it('should use Shield360Config.pricingInfo for cost calculation', async () => {
423
+ config_1.default.pricingInfo = { chat: { 'llama-3.1-8b-instant': { promptPrice: 0.05, completionPrice: 0.08 } } };
424
+ const mockArgs = [
425
+ {
426
+ messages: [{ role: 'user', content: 'Test' }],
427
+ model: 'llama-3.1-8b-instant',
428
+ stream: false,
429
+ },
430
+ ];
431
+ const mockResponse = {
432
+ id: 'test',
433
+ model: 'llama-3.1-8b-instant',
434
+ choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
435
+ usage: { prompt_tokens: 100, completion_tokens: 50, total_tokens: 150 },
436
+ };
437
+ await wrapper_1.default._chatCompletion({
438
+ args: mockArgs,
439
+ genAIEndpoint: 'groq.chat.completions',
440
+ response: mockResponse,
441
+ span: mockSpan,
442
+ });
443
+ expect(helpers_1.default.getChatModelCost).toHaveBeenCalledWith('llama-3.1-8b-instant', expect.any(Object), 100, 50, 0, 0, true);
444
+ });
445
+ });
446
+ describe('Streaming Chat Completion', () => {
447
+ it('should set streaming attributes matching Python SDK', async () => {
448
+ const mockArgs = [
449
+ {
450
+ messages: [{ role: 'user', content: 'Test streaming' }],
451
+ model: 'llama-3.1-8b-instant',
452
+ stream: true,
453
+ },
454
+ ];
455
+ async function* mockStream() {
456
+ yield {
457
+ id: 'test-id',
458
+ created: Date.now(),
459
+ model: 'llama-3.1-8b-instant',
460
+ choices: [{ delta: { content: 'Hello' } }],
461
+ };
462
+ yield {
463
+ id: 'test-id',
464
+ created: Date.now(),
465
+ model: 'llama-3.1-8b-instant',
466
+ choices: [{ delta: { content: ' world' } }],
467
+ };
468
+ }
469
+ const generator = wrapper_1.default._chatCompletionGenerator({
470
+ args: mockArgs,
471
+ genAIEndpoint: 'groq.chat.completions',
472
+ response: mockStream(),
473
+ span: mockSpan,
474
+ });
475
+ for await (const _ of generator) {
476
+ // consume
477
+ }
478
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, true);
479
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, 'groq');
480
+ });
481
+ it('should handle x_groq usage data in streaming', async () => {
482
+ const mockArgs = [
483
+ {
484
+ messages: [{ role: 'user', content: 'Test' }],
485
+ model: 'llama-3.1-8b-instant',
486
+ stream: true,
487
+ },
488
+ ];
489
+ async function* mockStream() {
490
+ yield {
491
+ id: 'test-id',
492
+ created: Date.now(),
493
+ model: 'llama-3.1-8b-instant',
494
+ choices: [{ delta: { content: 'Hello' } }],
495
+ };
496
+ yield {
497
+ id: 'test-id',
498
+ created: Date.now(),
499
+ model: 'llama-3.1-8b-instant',
500
+ choices: [{ delta: { content: '' }, finish_reason: 'stop' }],
501
+ x_groq: {
502
+ usage: { prompt_tokens: 15, completion_tokens: 25, total_tokens: 40 },
503
+ },
504
+ };
505
+ }
506
+ const generator = wrapper_1.default._chatCompletionGenerator({
507
+ args: mockArgs,
508
+ genAIEndpoint: 'groq.chat.completions',
509
+ response: mockStream(),
510
+ span: mockSpan,
511
+ });
512
+ for await (const _ of generator) {
513
+ // consume
514
+ }
515
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, 15);
516
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, 25);
517
+ });
518
+ it('should handle tool calls in streaming', async () => {
519
+ const mockArgs = [
520
+ {
521
+ messages: [{ role: 'user', content: 'Get the weather' }],
522
+ model: 'llama-3.1-8b-instant',
523
+ stream: true,
524
+ },
525
+ ];
526
+ async function* mockStream() {
527
+ yield {
528
+ id: 'test-id',
529
+ created: Date.now(),
530
+ model: 'llama-3.1-8b-instant',
531
+ choices: [{
532
+ delta: {
533
+ tool_calls: [{
534
+ index: 0,
535
+ id: 'call_abc',
536
+ type: 'function',
537
+ function: { name: 'get_weather', arguments: '{"loc' },
538
+ }],
539
+ },
540
+ }],
541
+ };
542
+ yield {
543
+ id: 'test-id',
544
+ created: Date.now(),
545
+ model: 'llama-3.1-8b-instant',
546
+ choices: [{
547
+ delta: {
548
+ tool_calls: [{
549
+ index: 0,
550
+ function: { arguments: 'ation":"SF"}' },
551
+ }],
552
+ },
553
+ }],
554
+ };
555
+ yield {
556
+ id: 'test-id',
557
+ created: Date.now(),
558
+ model: 'llama-3.1-8b-instant',
559
+ choices: [{ delta: {}, finish_reason: 'tool_calls' }],
560
+ };
561
+ }
562
+ const generator = wrapper_1.default._chatCompletionGenerator({
563
+ args: mockArgs,
564
+ genAIEndpoint: 'groq.chat.completions',
565
+ response: mockStream(),
566
+ span: mockSpan,
567
+ });
568
+ for await (const _ of generator) {
569
+ // consume
570
+ }
571
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_NAME, 'get_weather');
572
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, 'call_abc');
573
+ });
574
+ });
575
+ describe('Span Creation Attributes', () => {
576
+ it('should use aiSystem from SemanticConvention.GEN_AI_SYSTEM_GROQ', () => {
577
+ expect(wrapper_1.default.aiSystem).toBe(semantic_convention_1.default.GEN_AI_SYSTEM_GROQ);
578
+ expect(wrapper_1.default.aiSystem).toBe('groq');
579
+ });
580
+ it('should set correct server address and port', () => {
581
+ expect(wrapper_1.default.serverAddress).toBe('api.groq.com');
582
+ expect(wrapper_1.default.serverPort).toBe(443);
583
+ });
584
+ });
585
+ describe('GenAI semantic conventions: system_instructions + tool_definitions', () => {
586
+ const buildResponse = () => ({
587
+ id: 'sys-tools-test',
588
+ created: Date.now(),
589
+ model: 'llama-3.1-8b-instant',
590
+ choices: [
591
+ {
592
+ index: 0,
593
+ finish_reason: 'stop',
594
+ message: { role: 'assistant', content: 'ok' },
595
+ },
596
+ ],
597
+ usage: { prompt_tokens: 5, completion_tokens: 5, total_tokens: 10 },
598
+ });
599
+ it('writes gen_ai.system_instructions on the span and emitted event when a system message is present', async () => {
600
+ const mockArgs = [
601
+ {
602
+ messages: [
603
+ { role: 'system', content: 'You are a helpful assistant.' },
604
+ { role: 'user', content: 'hi' },
605
+ ],
606
+ model: 'llama-3.1-8b-instant',
607
+ stream: false,
608
+ },
609
+ ];
610
+ await wrapper_1.default._chatCompletion({
611
+ args: mockArgs,
612
+ genAIEndpoint: 'groq.chat.completions',
613
+ response: buildResponse(),
614
+ span: mockSpan,
615
+ });
616
+ const expectedSysJson = JSON.stringify([
617
+ { type: 'text', content: 'You are a helpful assistant.' },
618
+ ]);
619
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, expectedSysJson);
620
+ const emit = helpers_1.default.emitInferenceEvent;
621
+ expect(emit).toHaveBeenCalled();
622
+ const eventAttrs = emit.mock.calls[0][1];
623
+ expect(eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS]).toBe(expectedSysJson);
624
+ });
625
+ it('writes gen_ai.tool.definitions on the span and emitted event when tools are present', async () => {
626
+ const mockArgs = [
627
+ {
628
+ messages: [{ role: 'user', content: 'use a tool' }],
629
+ model: 'llama-3.1-8b-instant',
630
+ stream: false,
631
+ tools: [
632
+ {
633
+ type: 'function',
634
+ function: {
635
+ name: 'get_weather',
636
+ description: 'Get current weather',
637
+ parameters: { type: 'object', properties: {} },
638
+ },
639
+ },
640
+ ],
641
+ },
642
+ ];
643
+ await wrapper_1.default._chatCompletion({
644
+ args: mockArgs,
645
+ genAIEndpoint: 'groq.chat.completions',
646
+ response: buildResponse(),
647
+ span: mockSpan,
648
+ });
649
+ const expectedToolJson = JSON.stringify([
650
+ {
651
+ type: 'function',
652
+ name: 'get_weather',
653
+ description: 'Get current weather',
654
+ parameters: { type: 'object', properties: {} },
655
+ },
656
+ ]);
657
+ expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, expectedToolJson);
658
+ const emit = helpers_1.default.emitInferenceEvent;
659
+ expect(emit).toHaveBeenCalled();
660
+ const eventAttrs = emit.mock.calls[0][1];
661
+ expect(eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS]).toBe(expectedToolJson);
662
+ });
663
+ it('omits both attributes when neither system messages nor tools are provided', async () => {
664
+ const mockArgs = [
665
+ {
666
+ messages: [{ role: 'user', content: 'hi' }],
667
+ model: 'llama-3.1-8b-instant',
668
+ stream: false,
669
+ },
670
+ ];
671
+ await wrapper_1.default._chatCompletion({
672
+ args: mockArgs,
673
+ genAIEndpoint: 'groq.chat.completions',
674
+ response: buildResponse(),
675
+ span: mockSpan,
676
+ });
677
+ const setAttrKeys = mockSpan.setAttribute.mock.calls.map(([k]) => k);
678
+ expect(setAttrKeys).not.toContain(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS);
679
+ expect(setAttrKeys).not.toContain(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS);
680
+ const emit = helpers_1.default.emitInferenceEvent;
681
+ const eventAttrs = emit.mock.calls[0][1];
682
+ expect(eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS]).toBeUndefined();
683
+ expect(eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS]).toBeUndefined();
684
+ });
685
+ });
686
+ });
687
+ //# sourceMappingURL=groq-trace-comparison.test.js.map