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,663 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PassthroughTracer = exports.OPERATION_MAP = exports.adkWorkflowActive = void 0;
7
+ exports.isAdkWorkflowActive = isAdkWorkflowActive;
8
+ exports.getOperationType = getOperationType;
9
+ exports.getSpanKind = getSpanKind;
10
+ exports.generateSpanName = generateSpanName;
11
+ exports.resolveModelString = resolveModelString;
12
+ exports.extractModelName = extractModelName;
13
+ exports.resolveServerInfo = resolveServerInfo;
14
+ exports.setCommonSpanAttributes = setCommonSpanAttributes;
15
+ exports.captureInputMessages = captureInputMessages;
16
+ exports.captureOutputMessages = captureOutputMessages;
17
+ exports.captureEventOutput = captureEventOutput;
18
+ exports.extractTokenUsage = extractTokenUsage;
19
+ exports.enrichLlmSpan = enrichLlmSpan;
20
+ exports.enrichToolSpan = enrichToolSpan;
21
+ exports.enrichMergedToolSpan = enrichMergedToolSpan;
22
+ exports.setRunnerAgentAttributes = setRunnerAgentAttributes;
23
+ exports.setAgentAttributes = setAgentAttributes;
24
+ exports.processGoogleAdkResponse = processGoogleAdkResponse;
25
+ exports.recordGoogleAdkMetrics = recordGoogleAdkMetrics;
26
+ const api_1 = require("@opentelemetry/api");
27
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
28
+ const async_hooks_1 = require("async_hooks");
29
+ const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
30
+ const config_1 = __importDefault(require("../../config"));
31
+ const constant_1 = require("../../constant");
32
+ const helpers_1 = require("../../helpers");
33
+ /**
34
+ * Prevents Runner.run_async from creating a second invoke_agent span
35
+ * when called internally by Runner.run (mirrors Python _ADK_WORKFLOW_ACTIVE).
36
+ */
37
+ exports.adkWorkflowActive = new async_hooks_1.AsyncLocalStorage();
38
+ function isAdkWorkflowActive() {
39
+ return exports.adkWorkflowActive.getStore() === true;
40
+ }
41
+ // ---------------------------------------------------------------------------
42
+ // OTel GenAI operation mapping (mirrors Python OPERATION_MAP)
43
+ // ---------------------------------------------------------------------------
44
+ exports.OPERATION_MAP = {
45
+ agent_init: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CREATE_AGENT,
46
+ runner_run_async: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
47
+ runner_run: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
48
+ runner_run_live: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
49
+ agent_run_async: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT,
50
+ };
51
+ const SPAN_KIND_MAP = {
52
+ [semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CREATE_AGENT]: api_1.SpanKind.CLIENT,
53
+ [semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK]: api_1.SpanKind.INTERNAL,
54
+ [semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT]: api_1.SpanKind.INTERNAL,
55
+ [semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TOOLS]: api_1.SpanKind.INTERNAL,
56
+ [semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT]: api_1.SpanKind.CLIENT,
57
+ };
58
+ function getOperationType(endpoint) {
59
+ return exports.OPERATION_MAP[endpoint] ?? semantic_convention_1.default.GEN_AI_OPERATION_TYPE_AGENT;
60
+ }
61
+ function getSpanKind(operationType) {
62
+ return SPAN_KIND_MAP[operationType] ?? api_1.SpanKind.INTERNAL;
63
+ }
64
+ // ---------------------------------------------------------------------------
65
+ // Span name generation (mirrors Python generate_span_name)
66
+ // ---------------------------------------------------------------------------
67
+ function generateSpanName(endpoint, instance) {
68
+ if (endpoint === 'agent_init') {
69
+ const name = instance?.name ?? 'agent';
70
+ return `create_agent ${name}`;
71
+ }
72
+ if (endpoint === 'runner_run_async' || endpoint === 'runner_run' || endpoint === 'runner_run_live') {
73
+ const appName = instance?.app_name ?? instance?._app_name ?? 'google_adk';
74
+ return `invoke_agent ${appName}`;
75
+ }
76
+ if (endpoint === 'agent_run_async') {
77
+ const name = instance?.name ?? 'agent';
78
+ return `invoke_agent ${name}`;
79
+ }
80
+ return `${getOperationType(endpoint)} ${endpoint}`;
81
+ }
82
+ // ---------------------------------------------------------------------------
83
+ // PassthroughTracer (mirrors Python _PassthroughTracer)
84
+ // ---------------------------------------------------------------------------
85
+ /**
86
+ * Drop-in replacement for ADK's tracer objects. Overrides
87
+ * `startActiveSpan` to yield the current span instead of creating a new one,
88
+ * letting Shield360 own top-level spans while ADK's code still runs.
89
+ */
90
+ class PassthroughTracer {
91
+ constructor(wrapped) {
92
+ this._wrapped = wrapped;
93
+ }
94
+ startActiveSpan(...args) {
95
+ const fn = args[args.length - 1];
96
+ if (typeof fn === 'function') {
97
+ const currentSpan = api_1.trace.getActiveSpan();
98
+ return fn(currentSpan);
99
+ }
100
+ return undefined;
101
+ }
102
+ startSpan(...args) {
103
+ return this._wrapped.startSpan(...args);
104
+ }
105
+ }
106
+ exports.PassthroughTracer = PassthroughTracer;
107
+ // ---------------------------------------------------------------------------
108
+ // Model extraction (mirrors Python _resolve_model_string / extract_model_name)
109
+ // ---------------------------------------------------------------------------
110
+ function resolveModelString(modelObj) {
111
+ if (typeof modelObj === 'string')
112
+ return modelObj;
113
+ if (!modelObj)
114
+ return null;
115
+ const modelName = modelObj.model_name ?? modelObj.modelName;
116
+ if (typeof modelName === 'string')
117
+ return modelName;
118
+ const inner = modelObj.model;
119
+ if (typeof inner === 'string')
120
+ return inner;
121
+ return null;
122
+ }
123
+ function extractModelName(instance) {
124
+ try {
125
+ const model = instance?.model;
126
+ if (model) {
127
+ const resolved = resolveModelString(model);
128
+ if (resolved)
129
+ return resolved;
130
+ }
131
+ const rootAgent = instance?.agent;
132
+ if (rootAgent)
133
+ return extractModelName(rootAgent);
134
+ }
135
+ catch { /* ignore */ }
136
+ return 'unknown';
137
+ }
138
+ // ---------------------------------------------------------------------------
139
+ // Server address resolution (mirrors Python resolve_server_info)
140
+ // ---------------------------------------------------------------------------
141
+ const PREFIX_TO_PROVIDER = {
142
+ anthropic: 'anthropic',
143
+ claude: 'anthropic',
144
+ openai: 'openai',
145
+ gpt: 'openai',
146
+ mistral: 'mistral_ai',
147
+ cohere: 'cohere',
148
+ };
149
+ function detectProviderFromModelStr(modelStr) {
150
+ if (!modelStr)
151
+ return null;
152
+ const lower = modelStr.toLowerCase();
153
+ const prefix = lower.includes('/') ? lower.split('/')[0] : lower.split('-')[0];
154
+ const providerKey = PREFIX_TO_PROVIDER[prefix];
155
+ if (!providerKey)
156
+ return null;
157
+ const [addr, port] = (0, helpers_1.getServerAddressForProvider)(providerKey);
158
+ if (!addr)
159
+ return null;
160
+ return [addr, port, providerKey];
161
+ }
162
+ function resolveServerInfo(instance, modelName) {
163
+ if (modelName) {
164
+ const detected = detectProviderFromModelStr(modelName);
165
+ if (detected)
166
+ return detected;
167
+ }
168
+ if (instance) {
169
+ try {
170
+ let modelObj = instance.model;
171
+ if (!modelObj) {
172
+ const agent = instance.agent;
173
+ if (agent)
174
+ modelObj = agent.model;
175
+ }
176
+ if (modelObj) {
177
+ const resolved = resolveModelString(modelObj);
178
+ if (resolved) {
179
+ const detected = detectProviderFromModelStr(resolved);
180
+ if (detected)
181
+ return detected;
182
+ }
183
+ }
184
+ }
185
+ catch { /* ignore */ }
186
+ }
187
+ const useVertex = (process.env.GOOGLE_GENAI_USE_VERTEXAI || '').toLowerCase();
188
+ if (useVertex === 'true' || useVertex === '1') {
189
+ const [addr, port] = (0, helpers_1.getServerAddressForProvider)('gcp.vertex_ai');
190
+ return [addr, port, 'gcp.vertex_ai'];
191
+ }
192
+ const [addr, port] = (0, helpers_1.getServerAddressForProvider)('gcp.gemini');
193
+ return [addr, port, 'gcp.gemini'];
194
+ }
195
+ // ---------------------------------------------------------------------------
196
+ // Common span attributes (mirrors Python common_framework_span_attributes)
197
+ // ---------------------------------------------------------------------------
198
+ function setCommonSpanAttributes(span, operationType) {
199
+ span.setAttribute(semantic_conventions_1.ATTR_TELEMETRY_SDK_NAME, constant_1.SDK_NAME);
200
+ span.setAttribute(semantic_convention_1.default.ATTR_DEPLOYMENT_ENVIRONMENT, config_1.default.environment || 'default');
201
+ span.setAttribute(semantic_conventions_1.ATTR_SERVICE_NAME, config_1.default.applicationName || 'default');
202
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, constant_1.SDK_VERSION);
203
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, operationType);
204
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, semantic_convention_1.default.GEN_AI_SYSTEM_GOOGLE_ADK);
205
+ }
206
+ // ---------------------------------------------------------------------------
207
+ // Content extraction helpers (mirrors Python _extract_parts)
208
+ // ---------------------------------------------------------------------------
209
+ function truncateContent(str, maxLen) {
210
+ const limit = maxLen ?? config_1.default.maxContentLength;
211
+ if (limit && str.length > limit)
212
+ return str.slice(0, limit) + '...';
213
+ return str;
214
+ }
215
+ function extractParts(parts) {
216
+ const textParts = [];
217
+ const toolCalls = [];
218
+ const toolResponses = [];
219
+ for (const part of parts || []) {
220
+ const text = part?.text;
221
+ if (text)
222
+ textParts.push(truncateContent(String(text)));
223
+ const fc = part?.function_call ?? part?.functionCall;
224
+ if (fc) {
225
+ const entry = {
226
+ name: fc.name ?? '',
227
+ id: fc.id ?? '',
228
+ };
229
+ const fcArgs = fc.args;
230
+ if (fcArgs) {
231
+ try {
232
+ entry.arguments = typeof fcArgs === 'object' ? JSON.stringify(fcArgs) : String(fcArgs);
233
+ }
234
+ catch {
235
+ entry.arguments = String(fcArgs);
236
+ }
237
+ }
238
+ toolCalls.push(entry);
239
+ }
240
+ const fr = part?.function_response ?? part?.functionResponse;
241
+ if (fr) {
242
+ const respEntry = {
243
+ name: fr.name ?? '',
244
+ id: fr.id ?? '',
245
+ };
246
+ const frResp = fr.response;
247
+ if (frResp != null) {
248
+ try {
249
+ respEntry.content = typeof frResp === 'object' ? JSON.stringify(frResp) : String(frResp);
250
+ }
251
+ catch {
252
+ respEntry.content = String(frResp);
253
+ }
254
+ }
255
+ toolResponses.push(respEntry);
256
+ }
257
+ }
258
+ return { textParts, toolCalls, toolResponses };
259
+ }
260
+ // ---------------------------------------------------------------------------
261
+ // Input/Output message capture (mirrors Python capture_input_messages / capture_output_messages)
262
+ // ---------------------------------------------------------------------------
263
+ function captureInputMessages(span, llmRequest, captureContent) {
264
+ if (!captureContent)
265
+ return;
266
+ try {
267
+ const contents = llmRequest?.contents;
268
+ if (!contents)
269
+ return;
270
+ const messages = [];
271
+ for (const content of contents.slice(0, 20)) {
272
+ const role = content?.role ?? 'user';
273
+ const rawParts = content?.parts ?? [];
274
+ const { textParts, toolCalls, toolResponses } = extractParts(rawParts);
275
+ const parts = [];
276
+ for (const text of textParts)
277
+ parts.push({ type: 'text', content: text });
278
+ for (const tc of toolCalls) {
279
+ parts.push({ type: 'tool_call', id: tc.id, name: tc.name, arguments: tc.arguments ?? '' });
280
+ }
281
+ for (const tr of toolResponses) {
282
+ parts.push({ type: 'tool_call_response', id: tr.id, response: tr.content ?? '' });
283
+ }
284
+ if (parts.length > 0)
285
+ messages.push({ role: String(role), parts });
286
+ }
287
+ if (messages.length > 0) {
288
+ span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, JSON.stringify(messages));
289
+ }
290
+ }
291
+ catch { /* ignore */ }
292
+ }
293
+ function captureOutputMessages(span, llmResponse, captureContent, finishReason = 'stop') {
294
+ if (!captureContent)
295
+ return;
296
+ try {
297
+ const content = llmResponse?.content;
298
+ if (!content)
299
+ return;
300
+ const rawParts = content.parts ?? [];
301
+ const { textParts, toolCalls } = extractParts(rawParts);
302
+ const parts = [];
303
+ for (const text of textParts)
304
+ parts.push({ type: 'text', content: text });
305
+ for (const tc of toolCalls) {
306
+ parts.push({ type: 'tool_call', id: tc.id, name: tc.name, arguments: tc.arguments ?? '' });
307
+ }
308
+ if (parts.length > 0) {
309
+ const messages = [{ role: 'assistant', parts, finish_reason: finishReason }];
310
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, JSON.stringify(messages));
311
+ }
312
+ }
313
+ catch { /* ignore */ }
314
+ }
315
+ function captureEventOutput(span, event, captureContent) {
316
+ if (!captureContent)
317
+ return;
318
+ try {
319
+ const content = event?.content;
320
+ if (!content)
321
+ return;
322
+ const rawParts = content.parts ?? [];
323
+ const { textParts, toolCalls } = extractParts(rawParts);
324
+ const parts = [];
325
+ for (const text of textParts)
326
+ parts.push({ type: 'text', content: text });
327
+ for (const tc of toolCalls) {
328
+ parts.push({ type: 'tool_call', id: tc.id, name: tc.name, arguments: tc.arguments ?? '' });
329
+ }
330
+ if (parts.length > 0) {
331
+ const messages = [{ role: 'assistant', parts, finish_reason: 'stop' }];
332
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, JSON.stringify(messages));
333
+ }
334
+ }
335
+ catch { /* ignore */ }
336
+ }
337
+ function extractTokenUsage(llmResponse) {
338
+ try {
339
+ const usage = llmResponse?.usage_metadata ?? llmResponse?.usageMetadata;
340
+ if (!usage)
341
+ return {};
342
+ return {
343
+ inputTokens: usage.prompt_token_count ?? usage.promptTokenCount,
344
+ outputTokens: usage.candidates_token_count ?? usage.candidatesTokenCount,
345
+ reasoningTokens: usage.thoughts_token_count ?? usage.thoughtsTokenCount,
346
+ cachedTokens: usage.cached_content_token_count ?? usage.cachedContentTokenCount,
347
+ totalTokens: usage.total_token_count ?? usage.totalTokenCount,
348
+ };
349
+ }
350
+ catch {
351
+ return {};
352
+ }
353
+ }
354
+ // ---------------------------------------------------------------------------
355
+ // Output type detection (mirrors Python _determine_output_type)
356
+ // ---------------------------------------------------------------------------
357
+ function determineOutputType(llmResponse) {
358
+ try {
359
+ const content = llmResponse?.content;
360
+ if (content) {
361
+ for (const part of (content.parts ?? [])) {
362
+ if (part?.function_call || part?.functionCall)
363
+ return 'tool_calls';
364
+ }
365
+ }
366
+ }
367
+ catch { /* ignore */ }
368
+ return 'text';
369
+ }
370
+ // ---------------------------------------------------------------------------
371
+ // LLM span enrichment (mirrors Python enrich_llm_span)
372
+ // ---------------------------------------------------------------------------
373
+ function enrichLlmSpan(span, llmRequest, llmResponse, captureMessageContent) {
374
+ try {
375
+ const requestModel = llmRequest?.model;
376
+ const modelStr = requestModel ? String(requestModel) : null;
377
+ const [serverAddress, serverPort, providerName] = resolveServerInfo(undefined, modelStr);
378
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT);
379
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, providerName);
380
+ span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, serverAddress);
381
+ span.setAttribute(semantic_convention_1.default.SERVER_PORT, serverPort);
382
+ if (llmRequest) {
383
+ if (modelStr)
384
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, modelStr);
385
+ const config = llmRequest.config;
386
+ if (config) {
387
+ const temp = config.temperature;
388
+ if (temp != null)
389
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TEMPERATURE, Number(temp));
390
+ const topP = config.top_p ?? config.topP;
391
+ if (topP != null)
392
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_TOP_P, Number(topP));
393
+ const maxTokens = config.max_output_tokens ?? config.maxOutputTokens;
394
+ if (maxTokens != null)
395
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, Number(maxTokens));
396
+ }
397
+ if (captureMessageContent) {
398
+ const sysInstr = config?.system_instruction ?? config?.systemInstruction;
399
+ if (sysInstr) {
400
+ const instrText = typeof sysInstr === 'string' ? sysInstr : String(sysInstr);
401
+ span.setAttribute(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, JSON.stringify([{ type: 'text', content: truncateContent(instrText) }]));
402
+ }
403
+ }
404
+ captureInputMessages(span, llmRequest, captureMessageContent);
405
+ }
406
+ if (llmResponse) {
407
+ const { inputTokens, outputTokens, reasoningTokens, cachedTokens, totalTokens } = extractTokenUsage(llmResponse);
408
+ if (inputTokens != null)
409
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
410
+ if (outputTokens != null)
411
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
412
+ if (reasoningTokens != null)
413
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COMPLETION_TOKENS_DETAILS_REASONING, reasoningTokens);
414
+ if (cachedTokens != null)
415
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, cachedTokens);
416
+ if (totalTokens != null)
417
+ span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_TOTAL_TOKENS, totalTokens);
418
+ const responseModel = llmResponse.model_version ?? llmResponse.modelVersion;
419
+ if (responseModel)
420
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, String(responseModel));
421
+ let frStr = 'stop';
422
+ const finishReason = llmResponse.finish_reason ?? llmResponse.finishReason;
423
+ if (finishReason) {
424
+ try {
425
+ frStr = (typeof finishReason === 'object' && finishReason.value)
426
+ ? String(finishReason.value).toLowerCase()
427
+ : String(finishReason).toLowerCase();
428
+ }
429
+ catch {
430
+ frStr = String(finishReason).toLowerCase();
431
+ }
432
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, [frStr]);
433
+ }
434
+ const responseId = llmResponse.response_id ?? llmResponse.responseId ?? llmResponse.id;
435
+ if (responseId)
436
+ span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_ID, String(responseId));
437
+ const errorCode = llmResponse.error_code ?? llmResponse.errorCode;
438
+ if (errorCode) {
439
+ span.setAttribute(semantic_convention_1.default.ERROR_TYPE, String(errorCode));
440
+ const errorMessage = llmResponse.error_message ?? llmResponse.errorMessage;
441
+ if (errorMessage)
442
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: String(errorMessage) });
443
+ }
444
+ captureOutputMessages(span, llmResponse, captureMessageContent, frStr);
445
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, determineOutputType(llmResponse));
446
+ }
447
+ }
448
+ catch { /* ignore */ }
449
+ }
450
+ // ---------------------------------------------------------------------------
451
+ // ADK Event extraction (mirrors Python _extract_from_event / _is_adk_event)
452
+ // ---------------------------------------------------------------------------
453
+ function isAdkEvent(obj) {
454
+ if (!obj)
455
+ return false;
456
+ return (obj.constructor?.name === 'Event') && ('content' in obj);
457
+ }
458
+ function extractFromEvent(eventObj) {
459
+ try {
460
+ const content = eventObj?.content;
461
+ if (!content)
462
+ return [null, null];
463
+ const parts = content.parts;
464
+ if (!parts || parts.length === 0)
465
+ return [null, null];
466
+ const fnResp = parts[0]?.function_response ?? parts[0]?.functionResponse;
467
+ if (!fnResp)
468
+ return [null, null];
469
+ return [fnResp.response ?? null, fnResp.id ?? null];
470
+ }
471
+ catch {
472
+ return [null, null];
473
+ }
474
+ }
475
+ // ---------------------------------------------------------------------------
476
+ // Tool type mapping (mirrors Python _otel_gen_ai_tool_type)
477
+ // ---------------------------------------------------------------------------
478
+ function otelToolType(tool) {
479
+ const name = tool?.constructor?.name ?? '';
480
+ if (name.includes('Function'))
481
+ return 'function';
482
+ if (name.includes('Agent'))
483
+ return 'extension';
484
+ return 'function';
485
+ }
486
+ // ---------------------------------------------------------------------------
487
+ // Tool span enrichment (mirrors Python enrich_tool_span)
488
+ // ---------------------------------------------------------------------------
489
+ function enrichToolSpan(span, tool, functionArgs, functionResponseEvent, captureMessageContent, error) {
490
+ try {
491
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TOOLS);
492
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, semantic_convention_1.default.GEN_AI_SYSTEM_GOOGLE_ADK);
493
+ if (tool) {
494
+ const toolName = tool.name ?? tool.constructor?.name ?? 'unknown';
495
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_NAME, String(toolName));
496
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_TYPE, otelToolType(tool));
497
+ const toolDesc = tool.description;
498
+ if (toolDesc)
499
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DESCRIPTION, truncateContent(String(toolDesc)));
500
+ }
501
+ let responseDict = null;
502
+ let toolCallId = null;
503
+ if (isAdkEvent(functionResponseEvent)) {
504
+ [responseDict, toolCallId] = extractFromEvent(functionResponseEvent);
505
+ }
506
+ else if (typeof functionResponseEvent === 'object' && functionResponseEvent !== null) {
507
+ responseDict = functionResponseEvent;
508
+ toolCallId = functionResponseEvent.id ?? null;
509
+ }
510
+ if (captureMessageContent) {
511
+ if (functionArgs != null) {
512
+ try {
513
+ const argsStr = typeof functionArgs === 'object' ? JSON.stringify(functionArgs) : String(functionArgs);
514
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ARGUMENTS, truncateContent(argsStr));
515
+ }
516
+ catch {
517
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ARGUMENTS, truncateContent(String(functionArgs)));
518
+ }
519
+ }
520
+ if (responseDict != null) {
521
+ try {
522
+ const resultStr = typeof responseDict === 'object' ? JSON.stringify(responseDict) : String(responseDict);
523
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_RESULT, truncateContent(resultStr));
524
+ }
525
+ catch {
526
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_RESULT, truncateContent(String(responseDict)));
527
+ }
528
+ }
529
+ }
530
+ if (toolCallId)
531
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, String(toolCallId));
532
+ if (error != null) {
533
+ const errorType = error.constructor?.name || '_OTHER';
534
+ span.setAttribute(semantic_convention_1.default.ERROR_TYPE, errorType);
535
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: String(error) });
536
+ }
537
+ }
538
+ catch { /* ignore */ }
539
+ }
540
+ // ---------------------------------------------------------------------------
541
+ // Merged tool span enrichment (mirrors Python enrich_merged_tool_span)
542
+ // ---------------------------------------------------------------------------
543
+ function enrichMergedToolSpan(span, responseEventId, functionResponseEvent, captureMessageContent) {
544
+ try {
545
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OPERATION, semantic_convention_1.default.GEN_AI_OPERATION_TYPE_TOOLS);
546
+ span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, semantic_convention_1.default.GEN_AI_SYSTEM_GOOGLE_ADK);
547
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_NAME, '(merged tools)');
548
+ if (responseEventId)
549
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, String(responseEventId));
550
+ if (captureMessageContent && functionResponseEvent != null) {
551
+ try {
552
+ const content = functionResponseEvent.content;
553
+ if (content) {
554
+ const parts = content.parts ?? [];
555
+ const toolResults = [];
556
+ for (const part of parts) {
557
+ const fnResp = part?.function_response ?? part?.functionResponse;
558
+ if (fnResp) {
559
+ const entry = {};
560
+ const name = fnResp.name;
561
+ if (name)
562
+ entry.name = String(name);
563
+ const resp = fnResp.response;
564
+ if (resp != null)
565
+ entry.response = resp;
566
+ if (Object.keys(entry).length > 0)
567
+ toolResults.push(entry);
568
+ }
569
+ }
570
+ if (toolResults.length > 0) {
571
+ span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_CALL_RESULT, truncateContent(JSON.stringify(toolResults)));
572
+ }
573
+ }
574
+ }
575
+ catch { /* ignore */ }
576
+ }
577
+ }
578
+ catch { /* ignore */ }
579
+ }
580
+ // ---------------------------------------------------------------------------
581
+ // Runner/Agent attribute setters (mirrors Python _set_runner_agent_attributes / _set_agent_attributes)
582
+ // ---------------------------------------------------------------------------
583
+ function setRunnerAgentAttributes(span, instance, endpoint) {
584
+ try {
585
+ const appName = instance?.app_name ?? instance?._app_name ?? 'google_adk';
586
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, String(appName));
587
+ if (endpoint === 'runner_run_live') {
588
+ span.setAttribute(semantic_convention_1.default.GEN_AI_EXECUTION_MODE, 'live');
589
+ }
590
+ else if (endpoint === 'runner_run') {
591
+ span.setAttribute(semantic_convention_1.default.GEN_AI_EXECUTION_MODE, 'sync');
592
+ }
593
+ else {
594
+ span.setAttribute(semantic_convention_1.default.GEN_AI_EXECUTION_MODE, 'async');
595
+ }
596
+ }
597
+ catch { /* ignore */ }
598
+ }
599
+ function setAgentAttributes(span, instance) {
600
+ try {
601
+ const name = instance?.name;
602
+ if (name)
603
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_NAME, String(name));
604
+ const description = instance?.description;
605
+ if (description)
606
+ span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_DESCRIPTION, String(description));
607
+ }
608
+ catch { /* ignore */ }
609
+ }
610
+ // ---------------------------------------------------------------------------
611
+ // Response processing for Runner/Agent spans (mirrors Python process_google_adk_response)
612
+ // ---------------------------------------------------------------------------
613
+ function processGoogleAdkResponse(span, endpoint, instance, startTime, _captureMessageContent) {
614
+ const endTime = Date.now();
615
+ const operationType = getOperationType(endpoint);
616
+ const [serverAddress, serverPort] = resolveServerInfo(instance);
617
+ const requestModel = extractModelName(instance);
618
+ setCommonSpanAttributes(span, operationType);
619
+ if (requestModel && requestModel !== 'unknown') {
620
+ span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, requestModel);
621
+ }
622
+ if (serverAddress)
623
+ span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, serverAddress);
624
+ if (serverPort)
625
+ span.setAttribute(semantic_convention_1.default.SERVER_PORT, serverPort);
626
+ if (endpoint === 'runner_run_async' || endpoint === 'runner_run' || endpoint === 'runner_run_live') {
627
+ setRunnerAgentAttributes(span, instance, endpoint);
628
+ }
629
+ else if (endpoint === 'agent_run_async') {
630
+ setAgentAttributes(span, instance);
631
+ }
632
+ span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT);
633
+ span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, (endTime - startTime) / 1000);
634
+ (0, helpers_1.applyCustomSpanAttributes)(span);
635
+ span.setStatus({ code: api_1.SpanStatusCode.OK });
636
+ }
637
+ // ---------------------------------------------------------------------------
638
+ // Metrics recording (mirrors Python record_google_adk_metrics)
639
+ // ---------------------------------------------------------------------------
640
+ function recordGoogleAdkMetrics(operationType, duration, requestModel, serverAddress, serverPort) {
641
+ try {
642
+ const Metrics = require('../../otel/metrics').default;
643
+ const attributes = {
644
+ [semantic_conventions_1.ATTR_TELEMETRY_SDK_NAME]: constant_1.SDK_NAME,
645
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: config_1.default.applicationName || 'default',
646
+ [semantic_convention_1.default.ATTR_DEPLOYMENT_ENVIRONMENT]: config_1.default.environment || 'default',
647
+ [semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
648
+ [semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: semantic_convention_1.default.GEN_AI_SYSTEM_GOOGLE_ADK,
649
+ };
650
+ if (requestModel && requestModel !== 'unknown') {
651
+ attributes[semantic_convention_1.default.GEN_AI_REQUEST_MODEL] = requestModel;
652
+ }
653
+ if (serverAddress)
654
+ attributes[semantic_convention_1.default.SERVER_ADDRESS] = serverAddress;
655
+ if (serverPort)
656
+ attributes[semantic_convention_1.default.SERVER_PORT] = serverPort;
657
+ if (Metrics.genaiClientOperationDuration) {
658
+ Metrics.genaiClientOperationDuration.record(duration, attributes);
659
+ }
660
+ }
661
+ catch { /* ignore */ }
662
+ }
663
+ //# sourceMappingURL=utils.js.map