@amplitude/ai 0.1.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 (510) hide show
  1. package/.cursor/skills/instrument-with-amplitude-ai/SKILL.md +50 -0
  2. package/AGENTS.md +79 -0
  3. package/LICENSE +21 -0
  4. package/README.md +2111 -0
  5. package/bin/amplitude-ai-completions.mjs +19 -0
  6. package/bin/amplitude-ai-doctor.mjs +26 -0
  7. package/bin/amplitude-ai-init.mjs +27 -0
  8. package/bin/amplitude-ai-instrument.mjs +52 -0
  9. package/bin/amplitude-ai-mcp.mjs +8 -0
  10. package/bin/amplitude-ai-register-catalog.mjs +156 -0
  11. package/bin/amplitude-ai-status.mjs +28 -0
  12. package/bin/amplitude-ai.mjs +43 -0
  13. package/bin/validate-catalog-constants.mjs +134 -0
  14. package/data/agent_event_catalog.json +1277 -0
  15. package/dist/_virtual/rolldown_runtime.js +31 -0
  16. package/dist/bound-agent.d.ts +56 -0
  17. package/dist/bound-agent.d.ts.map +1 -0
  18. package/dist/bound-agent.js +155 -0
  19. package/dist/bound-agent.js.map +1 -0
  20. package/dist/cli/doctor.d.ts +17 -0
  21. package/dist/cli/doctor.d.ts.map +1 -0
  22. package/dist/cli/doctor.js +89 -0
  23. package/dist/cli/doctor.js.map +1 -0
  24. package/dist/cli/init.d.ts +14 -0
  25. package/dist/cli/init.d.ts.map +1 -0
  26. package/dist/cli/init.js +40 -0
  27. package/dist/cli/init.js.map +1 -0
  28. package/dist/cli/providers.d.ts +32 -0
  29. package/dist/cli/providers.d.ts.map +1 -0
  30. package/dist/cli/providers.js +46 -0
  31. package/dist/cli/providers.js.map +1 -0
  32. package/dist/cli/status.d.ts +14 -0
  33. package/dist/cli/status.d.ts.map +1 -0
  34. package/dist/cli/status.js +38 -0
  35. package/dist/cli/status.js.map +1 -0
  36. package/dist/client.d.ts +246 -0
  37. package/dist/client.d.ts.map +1 -0
  38. package/dist/client.js +369 -0
  39. package/dist/client.js.map +1 -0
  40. package/dist/config.d.ts +60 -0
  41. package/dist/config.d.ts.map +1 -0
  42. package/dist/config.js +57 -0
  43. package/dist/config.js.map +1 -0
  44. package/dist/context.d.ts +44 -0
  45. package/dist/context.d.ts.map +1 -0
  46. package/dist/context.js +53 -0
  47. package/dist/context.js.map +1 -0
  48. package/dist/core/constants.d.ts +96 -0
  49. package/dist/core/constants.d.ts.map +1 -0
  50. package/dist/core/constants.js +105 -0
  51. package/dist/core/constants.js.map +1 -0
  52. package/dist/core/enrichments.d.ts +139 -0
  53. package/dist/core/enrichments.d.ts.map +1 -0
  54. package/dist/core/enrichments.js +177 -0
  55. package/dist/core/enrichments.js.map +1 -0
  56. package/dist/core/privacy.d.ts +53 -0
  57. package/dist/core/privacy.d.ts.map +1 -0
  58. package/dist/core/privacy.js +235 -0
  59. package/dist/core/privacy.js.map +1 -0
  60. package/dist/core/tracking.d.ts +242 -0
  61. package/dist/core/tracking.d.ts.map +1 -0
  62. package/dist/core/tracking.js +469 -0
  63. package/dist/core/tracking.js.map +1 -0
  64. package/dist/decorators.d.ts +109 -0
  65. package/dist/decorators.d.ts.map +1 -0
  66. package/dist/decorators.js +281 -0
  67. package/dist/decorators.js.map +1 -0
  68. package/dist/exceptions.d.ts +19 -0
  69. package/dist/exceptions.d.ts.map +1 -0
  70. package/dist/exceptions.js +35 -0
  71. package/dist/exceptions.js.map +1 -0
  72. package/dist/index.d.ts +37 -0
  73. package/dist/index.js +38 -0
  74. package/dist/integrations/anthropic-tools.d.ts +38 -0
  75. package/dist/integrations/anthropic-tools.d.ts.map +1 -0
  76. package/dist/integrations/anthropic-tools.js +175 -0
  77. package/dist/integrations/anthropic-tools.js.map +1 -0
  78. package/dist/integrations/crewai.d.ts +14 -0
  79. package/dist/integrations/crewai.d.ts.map +1 -0
  80. package/dist/integrations/crewai.js +19 -0
  81. package/dist/integrations/crewai.js.map +1 -0
  82. package/dist/integrations/langchain.d.ts +37 -0
  83. package/dist/integrations/langchain.d.ts.map +1 -0
  84. package/dist/integrations/langchain.js +189 -0
  85. package/dist/integrations/langchain.js.map +1 -0
  86. package/dist/integrations/llamaindex.d.ts +44 -0
  87. package/dist/integrations/llamaindex.d.ts.map +1 -0
  88. package/dist/integrations/llamaindex.js +144 -0
  89. package/dist/integrations/llamaindex.js.map +1 -0
  90. package/dist/integrations/openai-agents.d.ts +35 -0
  91. package/dist/integrations/openai-agents.d.ts.map +1 -0
  92. package/dist/integrations/openai-agents.js +248 -0
  93. package/dist/integrations/openai-agents.js.map +1 -0
  94. package/dist/integrations/opentelemetry.d.ts +40 -0
  95. package/dist/integrations/opentelemetry.d.ts.map +1 -0
  96. package/dist/integrations/opentelemetry.js +146 -0
  97. package/dist/integrations/opentelemetry.js.map +1 -0
  98. package/dist/internals.d.ts +5 -0
  99. package/dist/internals.js +5 -0
  100. package/dist/mcp/contract.d.ts +27 -0
  101. package/dist/mcp/contract.d.ts.map +1 -0
  102. package/dist/mcp/contract.js +25 -0
  103. package/dist/mcp/contract.js.map +1 -0
  104. package/dist/mcp/index.d.ts +4 -0
  105. package/dist/mcp/index.js +5 -0
  106. package/dist/mcp/patterns.d.ts +11 -0
  107. package/dist/mcp/patterns.d.ts.map +1 -0
  108. package/dist/mcp/patterns.js +38 -0
  109. package/dist/mcp/patterns.js.map +1 -0
  110. package/dist/mcp/server.d.ts +10 -0
  111. package/dist/mcp/server.d.ts.map +1 -0
  112. package/dist/mcp/server.js +241 -0
  113. package/dist/mcp/server.js.map +1 -0
  114. package/dist/mcp/validate-file.d.ts +20 -0
  115. package/dist/mcp/validate-file.d.ts.map +1 -0
  116. package/dist/mcp/validate-file.js +122 -0
  117. package/dist/mcp/validate-file.js.map +1 -0
  118. package/dist/middleware.d.ts +32 -0
  119. package/dist/middleware.d.ts.map +1 -0
  120. package/dist/middleware.js +67 -0
  121. package/dist/middleware.js.map +1 -0
  122. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js +54 -0
  123. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js.map +1 -0
  124. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js +20 -0
  125. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js.map +1 -0
  126. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js +34 -0
  127. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js.map +1 -0
  128. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js +225 -0
  129. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js.map +1 -0
  130. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js +22 -0
  131. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js.map +1 -0
  132. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +351 -0
  133. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map +1 -0
  134. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +634 -0
  135. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js.map +1 -0
  136. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js +60 -0
  137. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js.map +1 -0
  138. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +122 -0
  139. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js.map +1 -0
  140. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js +37 -0
  141. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js.map +1 -0
  142. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js +858 -0
  143. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js.map +1 -0
  144. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js +32 -0
  145. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js.map +1 -0
  146. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js +74 -0
  147. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js.map +1 -0
  148. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js +1262 -0
  149. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js.map +1 -0
  150. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js +83 -0
  151. package/dist/node_modules/.pnpm/@modelcontextprotocol_sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js.map +1 -0
  152. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/formats.js +195 -0
  153. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/formats.js.map +1 -0
  154. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/index.js +44 -0
  155. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/index.js.map +1 -0
  156. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/limit.js +88 -0
  157. package/dist/node_modules/.pnpm/ajv-formats@3.0.1_ajv@8.18.0/node_modules/ajv-formats/dist/limit.js.map +1 -0
  158. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/ajv.js +107 -0
  159. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/ajv.js.map +1 -0
  160. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js +142 -0
  161. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js.map +1 -0
  162. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/index.js +678 -0
  163. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/index.js.map +1 -0
  164. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/scope.js +145 -0
  165. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/scope.js.map +1 -0
  166. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/errors.js +106 -0
  167. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/errors.js.map +1 -0
  168. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/index.js +227 -0
  169. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/index.js.map +1 -0
  170. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/names.js +33 -0
  171. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/names.js.map +1 -0
  172. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/ref_error.js +22 -0
  173. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/ref_error.js.map +1 -0
  174. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/resolve.js +137 -0
  175. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/resolve.js.map +1 -0
  176. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/rules.js +65 -0
  177. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/rules.js.map +1 -0
  178. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/util.js +150 -0
  179. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/util.js.map +1 -0
  180. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/applicability.js +27 -0
  181. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/applicability.js.map +1 -0
  182. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/boolSchema.js +52 -0
  183. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/boolSchema.js.map +1 -0
  184. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/dataType.js +176 -0
  185. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/dataType.js.map +1 -0
  186. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
  187. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/defaults.js.map +1 -0
  188. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/index.js +437 -0
  189. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/index.js.map +1 -0
  190. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/keyword.js +117 -0
  191. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/keyword.js.map +1 -0
  192. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/subschema.js +76 -0
  193. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/validate/subschema.js.map +1 -0
  194. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/core.js +587 -0
  195. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/core.js.map +1 -0
  196. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/refs/data.js +22 -0
  197. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/refs/data.js.map +1 -0
  198. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/refs/json-schema-draft-07.js +145 -0
  199. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/refs/json-schema-draft-07.js.map +1 -0
  200. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/equal.js +16 -0
  201. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/equal.js.map +1 -0
  202. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/ucs2length.js +29 -0
  203. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/ucs2length.js.map +1 -0
  204. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/uri.js +16 -0
  205. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/uri.js.map +1 -0
  206. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/validation_error.js +20 -0
  207. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/runtime/validation_error.js.map +1 -0
  208. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +61 -0
  209. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js.map +1 -0
  210. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +101 -0
  211. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js.map +1 -0
  212. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +34 -0
  213. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js.map +1 -0
  214. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +21 -0
  215. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js.map +1 -0
  216. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +94 -0
  217. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/contains.js.map +1 -0
  218. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +91 -0
  219. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js.map +1 -0
  220. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
  221. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/if.js.map +1 -0
  222. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/index.js +64 -0
  223. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/index.js.map +1 -0
  224. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/items.js +63 -0
  225. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/items.js.map +1 -0
  226. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +39 -0
  227. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js.map +1 -0
  228. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/not.js +36 -0
  229. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/not.js.map +1 -0
  230. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +56 -0
  231. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js.map +1 -0
  232. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +66 -0
  233. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js.map +1 -0
  234. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +22 -0
  235. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js.map +1 -0
  236. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +57 -0
  237. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/properties.js.map +1 -0
  238. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +46 -0
  239. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js.map +1 -0
  240. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +22 -0
  241. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js.map +1 -0
  242. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/code.js +134 -0
  243. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/code.js.map +1 -0
  244. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/id.js +19 -0
  245. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/id.js.map +1 -0
  246. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/index.js +27 -0
  247. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/index.js.map +1 -0
  248. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/ref.js +116 -0
  249. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/core/ref.js.map +1 -0
  250. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +106 -0
  251. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -0
  252. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +18 -0
  253. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/discriminator/types.js.map +1 -0
  254. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/draft7.js +31 -0
  255. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/draft7.js.map +1 -0
  256. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/format/format.js +97 -0
  257. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/format/format.js.map +1 -0
  258. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/format/index.js +15 -0
  259. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/format/index.js.map +1 -0
  260. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/metadata.js +27 -0
  261. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/metadata.js.map +1 -0
  262. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/const.js +32 -0
  263. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/const.js.map +1 -0
  264. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/enum.js +54 -0
  265. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/enum.js.map +1 -0
  266. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/index.js +53 -0
  267. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/index.js.map +1 -0
  268. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +33 -0
  269. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js.map +1 -0
  270. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +38 -0
  271. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js.map +1 -0
  272. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +52 -0
  273. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js.map +1 -0
  274. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +33 -0
  275. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js.map +1 -0
  276. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +32 -0
  277. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js.map +1 -0
  278. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +43 -0
  279. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/pattern.js.map +1 -0
  280. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/required.js +77 -0
  281. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/required.js.map +1 -0
  282. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +75 -0
  283. package/dist/node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js.map +1 -0
  284. package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +37 -0
  285. package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js.map +1 -0
  286. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +240 -0
  287. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js.map +1 -0
  288. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +194 -0
  289. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js.map +1 -0
  290. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +286 -0
  291. package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js.map +1 -0
  292. package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +82 -0
  293. package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js.map +1 -0
  294. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js +37 -0
  295. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js.map +1 -0
  296. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Refs.js +30 -0
  297. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Refs.js.map +1 -0
  298. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +16 -0
  299. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/errorMessages.js.map +1 -0
  300. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js +10 -0
  301. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js.map +1 -0
  302. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parseDef.js +57 -0
  303. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parseDef.js.map +1 -0
  304. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +17 -0
  305. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/any.js.map +1 -0
  306. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +23 -0
  307. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js.map +1 -0
  308. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +36 -0
  309. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js.map +1 -0
  310. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +8 -0
  311. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js.map +1 -0
  312. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +10 -0
  313. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js.map +1 -0
  314. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +10 -0
  315. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js.map +1 -0
  316. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +39 -0
  317. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/date.js.map +1 -0
  318. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +13 -0
  319. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/default.js.map +1 -0
  320. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +11 -0
  321. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js.map +1 -0
  322. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +11 -0
  323. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js.map +1 -0
  324. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +47 -0
  325. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js.map +1 -0
  326. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +17 -0
  327. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js.map +1 -0
  328. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +38 -0
  329. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/map.js.map +1 -0
  330. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +16 -0
  331. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js.map +1 -0
  332. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +13 -0
  333. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/never.js.map +1 -0
  334. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +11 -0
  335. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/null.js.map +1 -0
  336. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +46 -0
  337. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js.map +1 -0
  338. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +37 -0
  339. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/number.js.map +1 -0
  340. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +64 -0
  341. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/object.js.map +1 -0
  342. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +20 -0
  343. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js.map +1 -0
  344. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +27 -0
  345. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js.map +1 -0
  346. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +10 -0
  347. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js.map +1 -0
  348. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +10 -0
  349. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js.map +1 -0
  350. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +56 -0
  351. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js.map +1 -0
  352. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +21 -0
  353. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/set.js.map +1 -0
  354. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +250 -0
  355. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
  356. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +38 -0
  357. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js.map +1 -0
  358. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +10 -0
  359. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js.map +1 -0
  360. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +64 -0
  361. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/union.js.map +1 -0
  362. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +10 -0
  363. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js.map +1 -0
  364. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js +78 -0
  365. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js.map +1 -0
  366. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +70 -0
  367. package/dist/node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js.map +1 -0
  368. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js +104 -0
  369. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js.map +1 -0
  370. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js +11 -0
  371. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js.map +1 -0
  372. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js +10 -0
  373. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js.map +1 -0
  374. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js +110 -0
  375. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js.map +1 -0
  376. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js +99 -0
  377. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js.map +1 -0
  378. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js +84 -0
  379. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js.map +1 -0
  380. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +3160 -0
  381. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -0
  382. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/errors.js +23 -0
  383. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/errors.js.map +1 -0
  384. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/iso.js +38 -0
  385. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/iso.js.map +1 -0
  386. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/parse.js +12 -0
  387. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/parse.js.map +1 -0
  388. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/schemas.js +611 -0
  389. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/schemas.js.map +1 -0
  390. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/api.js +437 -0
  391. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/api.js.map +1 -0
  392. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/checks.js +360 -0
  393. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/checks.js.map +1 -0
  394. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js +50 -0
  395. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js.map +1 -0
  396. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/doc.js +34 -0
  397. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/doc.js.map +1 -0
  398. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/errors.js +71 -0
  399. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/errors.js.map +1 -0
  400. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/parse.js +74 -0
  401. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/parse.js.map +1 -0
  402. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/regexes.js +63 -0
  403. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/regexes.js.map +1 -0
  404. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/registries.js +50 -0
  405. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/registries.js.map +1 -0
  406. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.js +1098 -0
  407. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.js.map +1 -0
  408. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/to-json-schema.js +599 -0
  409. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/to-json-schema.js.map +1 -0
  410. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/util.js +267 -0
  411. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/util.js.map +1 -0
  412. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/versions.js +10 -0
  413. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/versions.js.map +1 -0
  414. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/mini/schemas.js +50 -0
  415. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/mini/schemas.js.map +1 -0
  416. package/dist/patching.d.ts +59 -0
  417. package/dist/patching.d.ts.map +1 -0
  418. package/dist/patching.js +891 -0
  419. package/dist/patching.js.map +1 -0
  420. package/dist/propagation.d.ts +8 -0
  421. package/dist/propagation.d.ts.map +1 -0
  422. package/dist/propagation.js +46 -0
  423. package/dist/propagation.js.map +1 -0
  424. package/dist/providers/anthropic.d.ts +44 -0
  425. package/dist/providers/anthropic.d.ts.map +1 -0
  426. package/dist/providers/anthropic.js +287 -0
  427. package/dist/providers/anthropic.js.map +1 -0
  428. package/dist/providers/azure-openai.d.ts +32 -0
  429. package/dist/providers/azure-openai.d.ts.map +1 -0
  430. package/dist/providers/azure-openai.js +39 -0
  431. package/dist/providers/azure-openai.js.map +1 -0
  432. package/dist/providers/base.d.ts +70 -0
  433. package/dist/providers/base.d.ts.map +1 -0
  434. package/dist/providers/base.js +141 -0
  435. package/dist/providers/base.js.map +1 -0
  436. package/dist/providers/bedrock.d.ts +41 -0
  437. package/dist/providers/bedrock.d.ts.map +1 -0
  438. package/dist/providers/bedrock.js +229 -0
  439. package/dist/providers/bedrock.js.map +1 -0
  440. package/dist/providers/gemini.d.ts +34 -0
  441. package/dist/providers/gemini.d.ts.map +1 -0
  442. package/dist/providers/gemini.js +225 -0
  443. package/dist/providers/gemini.js.map +1 -0
  444. package/dist/providers/mistral.d.ts +32 -0
  445. package/dist/providers/mistral.d.ts.map +1 -0
  446. package/dist/providers/mistral.js +218 -0
  447. package/dist/providers/mistral.js.map +1 -0
  448. package/dist/providers/openai.d.ts +61 -0
  449. package/dist/providers/openai.d.ts.map +1 -0
  450. package/dist/providers/openai.js +530 -0
  451. package/dist/providers/openai.js.map +1 -0
  452. package/dist/register.d.ts +1 -0
  453. package/dist/register.js +46 -0
  454. package/dist/register.js.map +1 -0
  455. package/dist/session.d.ts +46 -0
  456. package/dist/session.d.ts.map +1 -0
  457. package/dist/session.js +144 -0
  458. package/dist/session.js.map +1 -0
  459. package/dist/tenant.d.ts +30 -0
  460. package/dist/tenant.d.ts.map +1 -0
  461. package/dist/tenant.js +23 -0
  462. package/dist/tenant.js.map +1 -0
  463. package/dist/testing.d.ts +46 -0
  464. package/dist/testing.d.ts.map +1 -0
  465. package/dist/testing.js +120 -0
  466. package/dist/testing.js.map +1 -0
  467. package/dist/types.d.ts +384 -0
  468. package/dist/types.d.ts.map +1 -0
  469. package/dist/types.js +13 -0
  470. package/dist/types.js.map +1 -0
  471. package/dist/utils/costs.d.ts +27 -0
  472. package/dist/utils/costs.d.ts.map +1 -0
  473. package/dist/utils/costs.js +63 -0
  474. package/dist/utils/costs.js.map +1 -0
  475. package/dist/utils/debug.d.ts +6 -0
  476. package/dist/utils/debug.d.ts.map +1 -0
  477. package/dist/utils/debug.js +73 -0
  478. package/dist/utils/debug.js.map +1 -0
  479. package/dist/utils/logger.d.ts +11 -0
  480. package/dist/utils/logger.d.ts.map +1 -0
  481. package/dist/utils/logger.js +18 -0
  482. package/dist/utils/logger.js.map +1 -0
  483. package/dist/utils/model-tiers.d.ts +8 -0
  484. package/dist/utils/model-tiers.d.ts.map +1 -0
  485. package/dist/utils/model-tiers.js +76 -0
  486. package/dist/utils/model-tiers.js.map +1 -0
  487. package/dist/utils/providers.d.ts +5 -0
  488. package/dist/utils/providers.d.ts.map +1 -0
  489. package/dist/utils/providers.js +20 -0
  490. package/dist/utils/providers.js.map +1 -0
  491. package/dist/utils/resolve-module.d.ts +5 -0
  492. package/dist/utils/resolve-module.d.ts.map +1 -0
  493. package/dist/utils/resolve-module.js +29 -0
  494. package/dist/utils/resolve-module.js.map +1 -0
  495. package/dist/utils/streaming.d.ts +55 -0
  496. package/dist/utils/streaming.d.ts.map +1 -0
  497. package/dist/utils/streaming.js +72 -0
  498. package/dist/utils/streaming.js.map +1 -0
  499. package/dist/utils/tokens.d.ts +16 -0
  500. package/dist/utils/tokens.d.ts.map +1 -0
  501. package/dist/utils/tokens.js +80 -0
  502. package/dist/utils/tokens.js.map +1 -0
  503. package/dist/wrappers.d.ts +37 -0
  504. package/dist/wrappers.d.ts.map +1 -0
  505. package/dist/wrappers.js +61 -0
  506. package/dist/wrappers.js.map +1 -0
  507. package/llms-full.txt +127 -0
  508. package/llms.txt +28 -0
  509. package/mcp.schema.json +18 -0
  510. package/package.json +189 -0
@@ -0,0 +1,530 @@
1
+ import { trackUserMessage } from "../core/tracking.js";
2
+ import { getDefaultPropagateContext, injectContext } from "../propagation.js";
3
+ import { tryRequire } from "../utils/resolve-module.js";
4
+ import { calculateCost } from "../utils/costs.js";
5
+ import { StreamingAccumulator } from "../utils/streaming.js";
6
+ import { BaseAIProvider, applySessionContext } from "./base.js";
7
+
8
+ //#region src/providers/openai.ts
9
+ const _resolved = tryRequire("openai");
10
+ const OPENAI_AVAILABLE = _resolved != null;
11
+ const _OpenAIModule = _resolved;
12
+ var OpenAI = class extends BaseAIProvider {
13
+ _client;
14
+ chat;
15
+ responses;
16
+ _propagateContext;
17
+ constructor(options) {
18
+ super({
19
+ amplitude: options.amplitude,
20
+ privacyConfig: options.privacyConfig,
21
+ providerName: "openai"
22
+ });
23
+ const mod = options.openaiModule ?? _OpenAIModule;
24
+ if (mod == null) throw new Error("openai package is required. Install it with: npm install openai — or pass the module directly via the openaiModule option.");
25
+ const OpenAISDK = mod.OpenAI;
26
+ const clientOpts = {};
27
+ if (options.apiKey) clientOpts.apiKey = options.apiKey;
28
+ if (options.baseUrl) clientOpts.baseURL = options.baseUrl;
29
+ this._client = new OpenAISDK(clientOpts);
30
+ this._propagateContext = options.propagateContext ?? getDefaultPropagateContext();
31
+ this.chat = new WrappedChat(this._client, this.trackFn(), this._amplitude, this._privacyConfig, this._propagateContext);
32
+ this.responses = new WrappedResponses(this._client, this.trackFn(), this._amplitude, this._privacyConfig, this._propagateContext);
33
+ }
34
+ get client() {
35
+ return this._client;
36
+ }
37
+ };
38
+ var WrappedChat = class {
39
+ completions;
40
+ constructor(client, trackFn, amplitude, privacyConfig, propagateContext) {
41
+ const chat = client.chat;
42
+ this.completions = new WrappedCompletions(chat.completions, trackFn, amplitude, privacyConfig, propagateContext);
43
+ }
44
+ };
45
+ var WrappedCompletions = class {
46
+ _original;
47
+ _trackFn;
48
+ _amplitude;
49
+ _privacyConfig;
50
+ _propagateContext;
51
+ _providerName;
52
+ constructor(completions, trackFn, amplitude, privacyConfig, propagateContext, providerName = "openai") {
53
+ this._original = completions;
54
+ this._trackFn = typeof trackFn === "function" ? trackFn : trackFn.trackFn();
55
+ this._amplitude = amplitude;
56
+ this._privacyConfig = privacyConfig;
57
+ this._propagateContext = propagateContext;
58
+ this._providerName = providerName;
59
+ }
60
+ async create(params, amplitudeOverrides) {
61
+ const createFn = this._original.create;
62
+ const startTime = performance.now();
63
+ let requestParams = this._withContextHeaders(params);
64
+ const ctx = applySessionContext(amplitudeOverrides);
65
+ if (requestParams.stream === true && requestParams.stream_options == null) requestParams = {
66
+ ...requestParams,
67
+ stream_options: { include_usage: true }
68
+ };
69
+ try {
70
+ this._trackInputMessages(requestParams.messages, ctx, amplitudeOverrides?.trackInputMessages ?? true);
71
+ const response = await createFn.call(this._original, requestParams);
72
+ if (requestParams.stream === true && _isAsyncIterable(response)) return this._wrapStream(response, requestParams, startTime, ctx);
73
+ const latencyMs = performance.now() - startTime;
74
+ const resp = response;
75
+ const usage = resp.usage;
76
+ const choice = resp.choices?.[0];
77
+ const modelName = String(resp.model ?? requestParams.model ?? "unknown");
78
+ const toolCalls = choice?.message?.tool_calls;
79
+ const usageExt = usage;
80
+ const promptDetails = usageExt?.prompt_tokens_details;
81
+ const reasoningTokens = (usageExt?.completion_tokens_details)?.reasoning_tokens;
82
+ const cachedTokens = promptDetails?.cached_tokens;
83
+ let costUsd = null;
84
+ if (usage?.prompt_tokens != null && usage?.completion_tokens != null) try {
85
+ costUsd = calculateCost({
86
+ modelName,
87
+ inputTokens: usage.prompt_tokens,
88
+ outputTokens: usage.completion_tokens,
89
+ reasoningTokens: reasoningTokens ?? 0,
90
+ cacheReadInputTokens: cachedTokens ?? 0
91
+ });
92
+ } catch {}
93
+ this._trackFn({
94
+ userId: ctx.userId ?? "unknown",
95
+ modelName,
96
+ provider: this._providerName,
97
+ responseContent: String(choice?.message?.content ?? ""),
98
+ latencyMs,
99
+ sessionId: ctx.sessionId,
100
+ traceId: ctx.traceId,
101
+ turnId: ctx.turnId ?? void 0,
102
+ agentId: ctx.agentId,
103
+ env: ctx.env,
104
+ inputTokens: usage?.prompt_tokens,
105
+ outputTokens: usage?.completion_tokens,
106
+ totalTokens: usage?.total_tokens,
107
+ reasoningTokens,
108
+ cacheReadInputTokens: cachedTokens,
109
+ totalCostUsd: costUsd,
110
+ finishReason: choice?.finish_reason,
111
+ toolCalls: toolCalls ?? void 0,
112
+ isStreaming: false,
113
+ systemPrompt: extractSystemPrompt(requestParams),
114
+ temperature: requestParams.temperature,
115
+ maxOutputTokens: requestParams.max_tokens,
116
+ topP: requestParams.top_p
117
+ });
118
+ return response;
119
+ } catch (error) {
120
+ const latencyMs = performance.now() - startTime;
121
+ this._trackFn({
122
+ userId: ctx.userId ?? "unknown",
123
+ modelName: String(requestParams.model ?? "unknown"),
124
+ provider: this._providerName,
125
+ responseContent: "",
126
+ latencyMs,
127
+ sessionId: ctx.sessionId,
128
+ traceId: ctx.traceId,
129
+ agentId: ctx.agentId,
130
+ env: ctx.env,
131
+ isError: true,
132
+ errorMessage: error instanceof Error ? error.message : String(error)
133
+ });
134
+ throw error;
135
+ }
136
+ }
137
+ async parse(params, amplitudeOverrides) {
138
+ const parseFn = this._original.parse;
139
+ if (typeof parseFn !== "function") throw new Error("OpenAI SDK does not expose chat.completions.parse");
140
+ const originalCreate = this._original.create;
141
+ this._original.create = parseFn;
142
+ try {
143
+ return await this.create(params, amplitudeOverrides);
144
+ } finally {
145
+ this._original.create = originalCreate;
146
+ }
147
+ }
148
+ async *_wrapStream(stream, params, _startTime, sessionCtx) {
149
+ const accumulator = new StreamingAccumulator();
150
+ accumulator.model = String(params.model ?? "unknown");
151
+ let reasoningContent = "";
152
+ try {
153
+ for await (const chunk of stream) {
154
+ const c = chunk;
155
+ const choices = c.choices;
156
+ const delta = choices?.[0]?.delta;
157
+ if (delta?.content != null) accumulator.addContent(String(delta.content));
158
+ const deltaToolCalls = delta?.tool_calls;
159
+ if (Array.isArray(deltaToolCalls)) for (const call of deltaToolCalls) accumulator.addToolCall(call);
160
+ if (delta?.reasoning_content != null) reasoningContent += String(delta.reasoning_content);
161
+ const finishReason = choices?.[0]?.finish_reason;
162
+ if (finishReason != null) accumulator.finishReason = String(finishReason);
163
+ const usage = c.usage;
164
+ if (usage != null) {
165
+ const promptDetails = usage.prompt_tokens_details;
166
+ const completionDetails = usage.completion_tokens_details;
167
+ accumulator.setUsage({
168
+ inputTokens: usage.prompt_tokens,
169
+ outputTokens: usage.completion_tokens,
170
+ totalTokens: usage.total_tokens,
171
+ reasoningTokens: completionDetails?.reasoning_tokens,
172
+ cacheReadTokens: promptDetails?.cached_tokens
173
+ });
174
+ }
175
+ yield chunk;
176
+ }
177
+ } catch (error) {
178
+ accumulator.setError(error instanceof Error ? error.message : String(error));
179
+ throw error;
180
+ } finally {
181
+ const state = accumulator.getState();
182
+ const modelName = String(accumulator.model ?? params.model ?? "unknown");
183
+ let costUsd = null;
184
+ if (state.inputTokens != null && state.outputTokens != null) try {
185
+ costUsd = calculateCost({
186
+ modelName,
187
+ inputTokens: state.inputTokens,
188
+ outputTokens: state.outputTokens,
189
+ reasoningTokens: state.reasoningTokens ?? 0,
190
+ cacheReadInputTokens: state.cacheReadTokens ?? 0
191
+ });
192
+ } catch {}
193
+ this._trackFn({
194
+ userId: sessionCtx.userId ?? "unknown",
195
+ modelName,
196
+ provider: this._providerName,
197
+ responseContent: state.content,
198
+ latencyMs: accumulator.elapsedMs,
199
+ sessionId: sessionCtx.sessionId,
200
+ traceId: sessionCtx.traceId,
201
+ turnId: sessionCtx.turnId ?? void 0,
202
+ agentId: sessionCtx.agentId,
203
+ env: sessionCtx.env,
204
+ inputTokens: state.inputTokens,
205
+ outputTokens: state.outputTokens,
206
+ totalTokens: state.totalTokens,
207
+ reasoningTokens: state.reasoningTokens,
208
+ cacheReadInputTokens: state.cacheReadTokens,
209
+ totalCostUsd: costUsd,
210
+ finishReason: state.finishReason,
211
+ toolCalls: state.toolCalls.length > 0 ? state.toolCalls : void 0,
212
+ providerTtfbMs: state.ttfbMs,
213
+ isStreaming: true,
214
+ isError: state.isError,
215
+ errorMessage: state.errorMessage,
216
+ reasoningContent: reasoningContent || void 0,
217
+ systemPrompt: extractSystemPrompt(params),
218
+ temperature: params.temperature,
219
+ maxOutputTokens: params.max_tokens,
220
+ topP: params.top_p
221
+ });
222
+ }
223
+ }
224
+ _withContextHeaders(params) {
225
+ if (!this._propagateContext) return params;
226
+ const injected = injectContext(params.extra_headers ?? params.headers);
227
+ return {
228
+ ...params,
229
+ extra_headers: injected
230
+ };
231
+ }
232
+ _trackInputMessages(messages, ctx, shouldTrackInputMessages) {
233
+ if (!shouldTrackInputMessages) return;
234
+ if (ctx.userId == null || ctx.sessionId == null) return;
235
+ if (!Array.isArray(messages)) return;
236
+ for (const msg of messages) {
237
+ if (msg?.role !== "user") continue;
238
+ const content = msg.content;
239
+ if (typeof content !== "string" || content.length === 0) continue;
240
+ trackUserMessage({
241
+ amplitude: this._amplitude,
242
+ userId: ctx.userId,
243
+ messageContent: content,
244
+ sessionId: ctx.sessionId,
245
+ traceId: ctx.traceId,
246
+ turnId: ctx.turnId ?? void 0,
247
+ agentId: ctx.agentId,
248
+ parentAgentId: ctx.parentAgentId,
249
+ customerOrgId: ctx.customerOrgId,
250
+ env: ctx.env,
251
+ groups: ctx.groups,
252
+ privacyConfig: this._privacyConfig
253
+ });
254
+ }
255
+ }
256
+ };
257
+ var WrappedResponses = class {
258
+ _original;
259
+ _trackFn;
260
+ _amplitude;
261
+ _privacyConfig;
262
+ _propagateContext;
263
+ _providerName;
264
+ constructor(client, trackFn, amplitude, privacyConfig, propagateContext, providerName = "openai") {
265
+ this._original = client.responses ?? {};
266
+ this._trackFn = typeof trackFn === "function" ? trackFn : trackFn.trackFn();
267
+ this._amplitude = amplitude;
268
+ this._privacyConfig = privacyConfig;
269
+ this._propagateContext = propagateContext;
270
+ this._providerName = providerName;
271
+ }
272
+ async create(params, amplitudeOverrides) {
273
+ const createFn = this._original.create;
274
+ const startTime = performance.now();
275
+ const requestParams = this._withContextHeaders(params);
276
+ const ctx = applySessionContext(amplitudeOverrides);
277
+ try {
278
+ this._trackInputMessages(requestParams.input, ctx, amplitudeOverrides?.trackInputMessages ?? true);
279
+ const response = await createFn.call(this._original, requestParams);
280
+ if (requestParams.stream === true && _isAsyncIterable(response)) return this._wrapStream(response, requestParams, startTime, ctx);
281
+ const latencyMs = performance.now() - startTime;
282
+ const resp = response;
283
+ const usage = resp.usage;
284
+ const responseText = extractResponsesText(resp);
285
+ const responseToolCalls = extractResponsesToolCalls(resp);
286
+ const modelName = String(resp.model ?? requestParams.model ?? "unknown");
287
+ let costUsd = null;
288
+ if (usage?.input_tokens != null && usage?.output_tokens != null) try {
289
+ costUsd = calculateCost({
290
+ modelName,
291
+ inputTokens: usage.input_tokens,
292
+ outputTokens: usage.output_tokens,
293
+ reasoningTokens: usage.output_tokens_details?.reasoning_tokens ?? 0
294
+ });
295
+ } catch {}
296
+ this._trackFn({
297
+ userId: ctx.userId ?? "unknown",
298
+ modelName,
299
+ provider: this._providerName,
300
+ responseContent: responseText,
301
+ latencyMs,
302
+ sessionId: ctx.sessionId,
303
+ traceId: ctx.traceId,
304
+ turnId: ctx.turnId ?? void 0,
305
+ agentId: ctx.agentId,
306
+ env: ctx.env,
307
+ inputTokens: usage?.input_tokens,
308
+ outputTokens: usage?.output_tokens,
309
+ totalTokens: usage?.total_tokens,
310
+ reasoningTokens: usage?.output_tokens_details?.reasoning_tokens,
311
+ totalCostUsd: costUsd,
312
+ finishReason: extractResponsesFinishReason(resp),
313
+ toolCalls: responseToolCalls.length > 0 ? responseToolCalls : void 0,
314
+ isStreaming: false,
315
+ systemPrompt: extractResponsesSystemPrompt(requestParams),
316
+ temperature: requestParams.temperature,
317
+ maxOutputTokens: requestParams.max_output_tokens,
318
+ topP: requestParams.top_p
319
+ });
320
+ return response;
321
+ } catch (error) {
322
+ const latencyMs = performance.now() - startTime;
323
+ this._trackFn({
324
+ userId: ctx.userId ?? "unknown",
325
+ modelName: String(requestParams.model ?? "unknown"),
326
+ provider: this._providerName,
327
+ responseContent: "",
328
+ latencyMs,
329
+ sessionId: ctx.sessionId,
330
+ traceId: ctx.traceId,
331
+ agentId: ctx.agentId,
332
+ env: ctx.env,
333
+ isError: true,
334
+ errorMessage: error instanceof Error ? error.message : String(error)
335
+ });
336
+ throw error;
337
+ }
338
+ }
339
+ async stream(params, amplitudeOverrides) {
340
+ const streamFn = this._original.stream;
341
+ if (typeof streamFn !== "function") throw new Error("OpenAI SDK does not expose responses.stream");
342
+ const startTime = performance.now();
343
+ const requestParams = this._withContextHeaders(params);
344
+ const ctx = applySessionContext(amplitudeOverrides);
345
+ try {
346
+ this._trackInputMessages(requestParams.input, ctx, amplitudeOverrides?.trackInputMessages ?? true);
347
+ const response = await streamFn.call(this._original, requestParams);
348
+ if (!_isAsyncIterable(response)) throw new Error("OpenAI responses.stream did not return AsyncIterable");
349
+ return this._wrapStream(response, requestParams, startTime, ctx);
350
+ } catch (error) {
351
+ this._trackFn({
352
+ userId: ctx.userId ?? "unknown",
353
+ modelName: String(requestParams.model ?? "unknown"),
354
+ provider: this._providerName,
355
+ responseContent: "",
356
+ latencyMs: performance.now() - startTime,
357
+ sessionId: ctx.sessionId,
358
+ traceId: ctx.traceId,
359
+ agentId: ctx.agentId,
360
+ env: ctx.env,
361
+ isError: true,
362
+ errorMessage: error instanceof Error ? error.message : String(error),
363
+ isStreaming: true
364
+ });
365
+ throw error;
366
+ }
367
+ }
368
+ async *_wrapStream(stream, params, _startTime, sessionCtx) {
369
+ const accumulator = new StreamingAccumulator();
370
+ accumulator.model = String(params.model ?? "unknown");
371
+ try {
372
+ for await (const event of stream) {
373
+ const e = event;
374
+ const type = e.type;
375
+ if (type === "response.output_text.delta") {
376
+ const delta = e.delta;
377
+ if (typeof delta === "string") accumulator.addContent(delta);
378
+ } else if (type === "response.completed") {
379
+ const response = e.response;
380
+ if (response != null) {
381
+ const outputText = extractResponsesText(response);
382
+ if (outputText.length > 0) accumulator.content = outputText;
383
+ const usage = response.usage;
384
+ accumulator.setUsage({
385
+ inputTokens: usage?.input_tokens,
386
+ outputTokens: usage?.output_tokens,
387
+ totalTokens: usage?.total_tokens,
388
+ reasoningTokens: usage?.output_tokens_details?.reasoning_tokens
389
+ });
390
+ const finishReason = extractResponsesFinishReason(response);
391
+ if (finishReason != null) accumulator.finishReason = finishReason;
392
+ }
393
+ }
394
+ yield event;
395
+ }
396
+ } catch (error) {
397
+ accumulator.setError(error instanceof Error ? error.message : String(error));
398
+ throw error;
399
+ } finally {
400
+ const state = accumulator.getState();
401
+ let costUsd = null;
402
+ if (state.inputTokens != null && state.outputTokens != null) try {
403
+ costUsd = calculateCost({
404
+ modelName: String(accumulator.model ?? params.model ?? "unknown"),
405
+ inputTokens: state.inputTokens,
406
+ outputTokens: state.outputTokens,
407
+ reasoningTokens: state.reasoningTokens ?? 0
408
+ });
409
+ } catch {}
410
+ this._trackFn({
411
+ userId: sessionCtx.userId ?? "unknown",
412
+ modelName: String(accumulator.model ?? params.model ?? "unknown"),
413
+ provider: this._providerName,
414
+ responseContent: state.content,
415
+ latencyMs: accumulator.elapsedMs,
416
+ sessionId: sessionCtx.sessionId,
417
+ traceId: sessionCtx.traceId,
418
+ turnId: sessionCtx.turnId ?? void 0,
419
+ agentId: sessionCtx.agentId,
420
+ env: sessionCtx.env,
421
+ inputTokens: state.inputTokens,
422
+ outputTokens: state.outputTokens,
423
+ totalTokens: state.totalTokens,
424
+ reasoningTokens: state.reasoningTokens,
425
+ totalCostUsd: costUsd,
426
+ finishReason: state.finishReason,
427
+ providerTtfbMs: state.ttfbMs,
428
+ isStreaming: true,
429
+ isError: state.isError,
430
+ errorMessage: state.errorMessage,
431
+ systemPrompt: extractResponsesSystemPrompt(params),
432
+ temperature: params.temperature,
433
+ maxOutputTokens: params.max_output_tokens,
434
+ topP: params.top_p
435
+ });
436
+ }
437
+ }
438
+ _withContextHeaders(params) {
439
+ if (!this._propagateContext) return params;
440
+ const injected = injectContext(params.extra_headers ?? params.headers);
441
+ return {
442
+ ...params,
443
+ extra_headers: injected
444
+ };
445
+ }
446
+ _trackInputMessages(input, ctx, shouldTrackInputMessages) {
447
+ if (!shouldTrackInputMessages) return;
448
+ if (ctx.userId == null || ctx.sessionId == null) return;
449
+ for (const text of extractResponsesUserInputs(input)) {
450
+ if (!text) continue;
451
+ trackUserMessage({
452
+ amplitude: this._amplitude,
453
+ userId: ctx.userId,
454
+ messageContent: text,
455
+ sessionId: ctx.sessionId,
456
+ traceId: ctx.traceId,
457
+ turnId: ctx.turnId ?? void 0,
458
+ agentId: ctx.agentId,
459
+ parentAgentId: ctx.parentAgentId,
460
+ customerOrgId: ctx.customerOrgId,
461
+ env: ctx.env,
462
+ groups: ctx.groups,
463
+ privacyConfig: this._privacyConfig
464
+ });
465
+ }
466
+ }
467
+ };
468
+ function _isAsyncIterable(value) {
469
+ return value != null && typeof value[Symbol.asyncIterator] === "function";
470
+ }
471
+ function extractSystemPrompt(params) {
472
+ const messages = params.messages;
473
+ if (!messages?.length) return void 0;
474
+ const systemMsg = messages.find((m) => m.role === "system" || m.role === "developer");
475
+ return systemMsg ? String(systemMsg.content ?? "") : void 0;
476
+ }
477
+ function extractResponsesSystemPrompt(params) {
478
+ const instructions = params.instructions;
479
+ return typeof instructions === "string" ? instructions : void 0;
480
+ }
481
+ function extractResponsesFinishReason(resp) {
482
+ const status = resp.status;
483
+ if (typeof status === "string" && status.length > 0) return status;
484
+ const out = resp.output?.[0];
485
+ if (out != null && typeof out.status === "string") return out.status;
486
+ }
487
+ function extractResponsesText(resp) {
488
+ if (typeof resp.output_text === "string") return resp.output_text;
489
+ const outputs = resp.output ?? [];
490
+ let text = "";
491
+ for (const item of outputs) text += extractOutputItemText(item);
492
+ return text;
493
+ }
494
+ function extractResponsesToolCalls(resp) {
495
+ const toolCalls = [];
496
+ const outputs = resp.output ?? [];
497
+ for (const item of outputs) {
498
+ if (!Array.isArray(item.content)) continue;
499
+ for (const contentItem of item.content) if (contentItem?.type === "tool_call" || contentItem?.type === "function_call") toolCalls.push(contentItem);
500
+ }
501
+ return toolCalls;
502
+ }
503
+ function extractOutputItemText(item) {
504
+ if (!Array.isArray(item.content)) return "";
505
+ let text = "";
506
+ for (const c of item.content) if (typeof c?.text === "string") text += c.text;
507
+ return text;
508
+ }
509
+ function extractResponsesUserInputs(input) {
510
+ if (typeof input === "string") return [input];
511
+ if (!Array.isArray(input)) return [];
512
+ const result = [];
513
+ for (const entry of input) {
514
+ if (typeof entry === "string") {
515
+ result.push(entry);
516
+ continue;
517
+ }
518
+ if (entry.role !== "user") continue;
519
+ const content = entry.content;
520
+ if (typeof content === "string") result.push(content);
521
+ else if (Array.isArray(content)) {
522
+ for (const part of content) if (typeof part?.text === "string") result.push(part.text);
523
+ }
524
+ }
525
+ return result;
526
+ }
527
+
528
+ //#endregion
529
+ export { OPENAI_AVAILABLE, OpenAI, WrappedChat, WrappedCompletions, WrappedResponses, _OpenAIModule, extractSystemPrompt };
530
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","names":["_OpenAIModule: Record<string, unknown> | null","clientOpts: Record<string, unknown>","costUsd: number | null","toolCalls: Array<Record<string, unknown>>","result: string[]"],"sources":["../../src/providers/openai.ts"],"sourcesContent":["/**\n * OpenAI provider wrapper with automatic tracking.\n *\n * Wraps the OpenAI client and instruments:\n * - chat.completions.create()\n * - responses.create()\n * to track AI response events via Amplitude.\n */\n\nimport type { PrivacyConfig } from '../core/privacy.js';\nimport { trackUserMessage } from '../core/tracking.js';\nimport { getDefaultPropagateContext, injectContext } from '../propagation.js';\nimport type {\n AmplitudeLike,\n AmplitudeOrAI,\n ChatCompletionResponse,\n ChatMessage,\n OpenAIResponse,\n OpenAIResponseInput,\n OpenAIResponseOutputItem,\n TrackFn,\n} from '../types.js';\nimport { calculateCost } from '../utils/costs.js';\nimport { tryRequire } from '../utils/resolve-module.js';\nimport { StreamingAccumulator } from '../utils/streaming.js';\nimport {\n applySessionContext,\n BaseAIProvider,\n type ProviderTrackOptions,\n} from './base.js';\n\nconst _resolved = tryRequire('openai');\nexport const OPENAI_AVAILABLE = _resolved != null;\nconst _OpenAIModule: Record<string, unknown> | null = _resolved;\n\nexport { _OpenAIModule };\n\nexport interface OpenAIOptions {\n amplitude: AmplitudeOrAI;\n apiKey?: string;\n baseUrl?: string;\n privacyConfig?: PrivacyConfig | null;\n propagateContext?: boolean;\n /** Pass the `openai` module directly to bypass `tryRequire` (required in bundler environments). */\n openaiModule?: unknown;\n}\n\nexport class OpenAI<\n TClient extends Record<string, unknown> = Record<string, unknown>,\n> extends BaseAIProvider {\n private _client: TClient;\n readonly chat: WrappedChat;\n readonly responses: WrappedResponses;\n private _propagateContext: boolean;\n\n constructor(options: OpenAIOptions) {\n super({\n amplitude: options.amplitude,\n privacyConfig: options.privacyConfig,\n providerName: 'openai',\n });\n\n const mod =\n (options.openaiModule as Record<string, unknown> | null) ?? _OpenAIModule;\n if (mod == null) {\n throw new Error(\n 'openai package is required. Install it with: npm install openai — or pass the module directly via the openaiModule option.',\n );\n }\n\n const OpenAISDK = mod.OpenAI as new (\n opts: Record<string, unknown>,\n ) => unknown;\n\n const clientOpts: Record<string, unknown> = {};\n if (options.apiKey) clientOpts.apiKey = options.apiKey;\n if (options.baseUrl) clientOpts.baseURL = options.baseUrl;\n\n this._client = new OpenAISDK(clientOpts) as TClient;\n this._propagateContext =\n options.propagateContext ?? getDefaultPropagateContext();\n this.chat = new WrappedChat(\n this._client,\n this.trackFn(),\n this._amplitude,\n this._privacyConfig,\n this._propagateContext,\n );\n this.responses = new WrappedResponses(\n this._client,\n this.trackFn(),\n this._amplitude,\n this._privacyConfig,\n this._propagateContext,\n );\n }\n\n get client(): TClient {\n return this._client;\n }\n}\n\nexport class WrappedChat {\n readonly completions: WrappedCompletions;\n\n constructor(\n client: unknown,\n trackFn: TrackFn,\n amplitude: AmplitudeLike,\n privacyConfig: PrivacyConfig | null,\n propagateContext: boolean,\n ) {\n const clientObj = client as Record<string, unknown>;\n const chat = clientObj.chat as Record<string, unknown>;\n this.completions = new WrappedCompletions(\n chat.completions as Record<string, unknown>,\n trackFn,\n amplitude,\n privacyConfig,\n propagateContext,\n );\n }\n}\n\nexport class WrappedCompletions {\n _original: Record<string, unknown>;\n private _trackFn: TrackFn;\n private _amplitude: AmplitudeLike;\n private _privacyConfig: PrivacyConfig | null;\n private _propagateContext: boolean;\n private _providerName: string;\n\n constructor(\n completions: Record<string, unknown>,\n trackFn: TrackFn,\n amplitude: AmplitudeLike,\n privacyConfig: PrivacyConfig | null,\n propagateContext: boolean,\n providerName = 'openai',\n ) {\n this._original = completions;\n this._trackFn =\n typeof trackFn === 'function'\n ? trackFn\n : (trackFn as unknown as { trackFn(): TrackFn }).trackFn();\n this._amplitude = amplitude;\n this._privacyConfig = privacyConfig;\n this._propagateContext = propagateContext;\n this._providerName = providerName;\n }\n\n async create(\n params: Record<string, unknown>,\n amplitudeOverrides?: ProviderTrackOptions,\n ): Promise<ChatCompletionResponse | AsyncIterable<unknown>> {\n const createFn = this._original.create as (\n ...args: unknown[]\n ) => Promise<unknown>;\n const startTime = performance.now();\n let requestParams = this._withContextHeaders(params);\n const ctx = applySessionContext(amplitudeOverrides);\n\n if (requestParams.stream === true && requestParams.stream_options == null) {\n requestParams = {\n ...requestParams,\n stream_options: { include_usage: true },\n };\n }\n\n try {\n this._trackInputMessages(\n requestParams.messages as unknown,\n ctx,\n amplitudeOverrides?.trackInputMessages ?? true,\n );\n const response = await createFn.call(this._original, requestParams);\n\n if (requestParams.stream === true && _isAsyncIterable(response)) {\n return this._wrapStream(\n response as AsyncIterable<unknown>,\n requestParams,\n startTime,\n ctx,\n );\n }\n\n const latencyMs = performance.now() - startTime;\n\n const resp = response as ChatCompletionResponse;\n const usage = resp.usage;\n const choice = resp.choices?.[0];\n const modelName = String(resp.model ?? requestParams.model ?? 'unknown');\n const toolCalls = choice?.message?.tool_calls;\n\n const usageExt = usage as Record<string, unknown> | undefined;\n const promptDetails = usageExt?.prompt_tokens_details as\n | Record<string, number>\n | undefined;\n const completionDetails = usageExt?.completion_tokens_details as\n | Record<string, number>\n | undefined;\n const reasoningTokens = completionDetails?.reasoning_tokens;\n const cachedTokens = promptDetails?.cached_tokens;\n\n let costUsd: number | null = null;\n if (usage?.prompt_tokens != null && usage?.completion_tokens != null) {\n try {\n costUsd = calculateCost({\n modelName,\n inputTokens: usage.prompt_tokens,\n outputTokens: usage.completion_tokens,\n reasoningTokens: reasoningTokens ?? 0,\n cacheReadInputTokens: cachedTokens ?? 0,\n });\n } catch {\n // cost calculation is best-effort\n }\n }\n\n this._trackFn({\n userId: ctx.userId ?? 'unknown',\n modelName,\n provider: this._providerName,\n responseContent: String(choice?.message?.content ?? ''),\n latencyMs,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n turnId: ctx.turnId ?? undefined,\n agentId: ctx.agentId,\n env: ctx.env,\n inputTokens: usage?.prompt_tokens,\n outputTokens: usage?.completion_tokens,\n totalTokens: usage?.total_tokens,\n reasoningTokens,\n cacheReadInputTokens: cachedTokens,\n totalCostUsd: costUsd,\n finishReason: choice?.finish_reason,\n toolCalls: toolCalls ?? undefined,\n isStreaming: false,\n systemPrompt: extractSystemPrompt(requestParams),\n temperature: requestParams.temperature as number | undefined,\n maxOutputTokens: requestParams.max_tokens as number | undefined,\n topP: requestParams.top_p as number | undefined,\n });\n\n return response as ChatCompletionResponse;\n } catch (error) {\n const latencyMs = performance.now() - startTime;\n this._trackFn({\n userId: ctx.userId ?? 'unknown',\n modelName: String(requestParams.model ?? 'unknown'),\n provider: this._providerName,\n responseContent: '',\n latencyMs,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n agentId: ctx.agentId,\n env: ctx.env,\n isError: true,\n errorMessage: error instanceof Error ? error.message : String(error),\n });\n\n throw error;\n }\n }\n\n async parse(\n params: Record<string, unknown>,\n amplitudeOverrides?: ProviderTrackOptions,\n ): Promise<ChatCompletionResponse | AsyncIterable<unknown>> {\n const parseFn = this._original.parse as\n | ((...args: unknown[]) => Promise<unknown>)\n | undefined;\n if (typeof parseFn !== 'function') {\n throw new Error('OpenAI SDK does not expose chat.completions.parse');\n }\n const originalCreate = this._original.create;\n this._original.create = parseFn;\n try {\n return await this.create(params, amplitudeOverrides);\n } finally {\n this._original.create = originalCreate;\n }\n }\n\n private async *_wrapStream(\n stream: AsyncIterable<unknown>,\n params: Record<string, unknown>,\n _startTime: number,\n sessionCtx: ProviderTrackOptions,\n ): AsyncGenerator<unknown> {\n const accumulator = new StreamingAccumulator();\n accumulator.model = String(params.model ?? 'unknown');\n let reasoningContent = '';\n\n try {\n for await (const chunk of stream) {\n const c = chunk as Record<string, unknown>;\n const choices = c.choices as Array<Record<string, unknown>> | undefined;\n const delta = choices?.[0]?.delta as\n | Record<string, unknown>\n | undefined;\n\n if (delta?.content != null) {\n accumulator.addContent(String(delta.content));\n }\n\n const deltaToolCalls = delta?.tool_calls as\n | Array<Record<string, unknown>>\n | undefined;\n if (Array.isArray(deltaToolCalls)) {\n for (const call of deltaToolCalls) {\n accumulator.addToolCall(call);\n }\n }\n\n if (delta?.reasoning_content != null) {\n reasoningContent += String(delta.reasoning_content);\n }\n\n const finishReason = choices?.[0]?.finish_reason;\n if (finishReason != null) {\n accumulator.finishReason = String(finishReason);\n }\n\n const usage = c.usage as Record<string, unknown> | undefined;\n if (usage != null) {\n const promptDetails = usage.prompt_tokens_details as\n | Record<string, number>\n | undefined;\n const completionDetails = usage.completion_tokens_details as\n | Record<string, number>\n | undefined;\n\n accumulator.setUsage({\n inputTokens: usage.prompt_tokens as number | undefined,\n outputTokens: usage.completion_tokens as number | undefined,\n totalTokens: usage.total_tokens as number | undefined,\n reasoningTokens: completionDetails?.reasoning_tokens,\n cacheReadTokens: promptDetails?.cached_tokens,\n });\n }\n\n yield chunk;\n }\n } catch (error) {\n accumulator.setError(\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n } finally {\n const state = accumulator.getState();\n const modelName = String(accumulator.model ?? params.model ?? 'unknown');\n\n let costUsd: number | null = null;\n if (state.inputTokens != null && state.outputTokens != null) {\n try {\n costUsd = calculateCost({\n modelName,\n inputTokens: state.inputTokens,\n outputTokens: state.outputTokens,\n reasoningTokens: state.reasoningTokens ?? 0,\n cacheReadInputTokens: state.cacheReadTokens ?? 0,\n });\n } catch {\n // cost calculation is best-effort\n }\n }\n\n this._trackFn({\n userId: sessionCtx.userId ?? 'unknown',\n modelName,\n provider: this._providerName,\n responseContent: state.content,\n latencyMs: accumulator.elapsedMs,\n sessionId: sessionCtx.sessionId,\n traceId: sessionCtx.traceId,\n turnId: sessionCtx.turnId ?? undefined,\n agentId: sessionCtx.agentId,\n env: sessionCtx.env,\n inputTokens: state.inputTokens,\n outputTokens: state.outputTokens,\n totalTokens: state.totalTokens,\n reasoningTokens: state.reasoningTokens,\n cacheReadInputTokens: state.cacheReadTokens,\n totalCostUsd: costUsd,\n finishReason: state.finishReason,\n toolCalls: state.toolCalls.length > 0 ? state.toolCalls : undefined,\n providerTtfbMs: state.ttfbMs,\n isStreaming: true,\n isError: state.isError,\n errorMessage: state.errorMessage,\n reasoningContent: reasoningContent || undefined,\n systemPrompt: extractSystemPrompt(params),\n temperature: params.temperature as number | undefined,\n maxOutputTokens: params.max_tokens as number | undefined,\n topP: params.top_p as number | undefined,\n });\n }\n }\n\n private _withContextHeaders(\n params: Record<string, unknown>,\n ): Record<string, unknown> {\n if (!this._propagateContext) return params;\n const existing = (params.extra_headers ?? params.headers) as\n | Record<string, string>\n | undefined;\n const injected = injectContext(existing);\n return {\n ...params,\n extra_headers: injected,\n };\n }\n\n private _trackInputMessages(\n messages: unknown,\n ctx: ProviderTrackOptions,\n shouldTrackInputMessages: boolean,\n ): void {\n if (!shouldTrackInputMessages) return;\n if (ctx.userId == null || ctx.sessionId == null) return;\n if (!Array.isArray(messages)) return;\n for (const msg of messages as ChatMessage[]) {\n if (msg?.role !== 'user') continue;\n const content = msg.content;\n if (typeof content !== 'string' || content.length === 0) continue;\n trackUserMessage({\n amplitude: this._amplitude,\n userId: ctx.userId,\n messageContent: content,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n turnId: ctx.turnId ?? undefined,\n agentId: ctx.agentId,\n parentAgentId: ctx.parentAgentId,\n customerOrgId: ctx.customerOrgId,\n env: ctx.env,\n groups: ctx.groups,\n privacyConfig: this._privacyConfig,\n });\n }\n }\n}\n\nexport class WrappedResponses {\n _original: Record<string, unknown>;\n private _trackFn: TrackFn;\n private _amplitude: AmplitudeLike;\n private _privacyConfig: PrivacyConfig | null;\n private _propagateContext: boolean;\n private _providerName: string;\n\n constructor(\n client: unknown,\n trackFn: TrackFn,\n amplitude: AmplitudeLike,\n privacyConfig: PrivacyConfig | null,\n propagateContext: boolean,\n providerName = 'openai',\n ) {\n const clientObj = client as Record<string, unknown>;\n const responses = (clientObj.responses ?? {}) as Record<string, unknown>;\n this._original = responses;\n this._trackFn =\n typeof trackFn === 'function'\n ? trackFn\n : (trackFn as unknown as { trackFn(): TrackFn }).trackFn();\n this._amplitude = amplitude;\n this._privacyConfig = privacyConfig;\n this._propagateContext = propagateContext;\n this._providerName = providerName;\n }\n\n async create(\n params: Record<string, unknown>,\n amplitudeOverrides?: ProviderTrackOptions,\n ): Promise<OpenAIResponse | AsyncIterable<unknown>> {\n const createFn = this._original.create as (\n ...args: unknown[]\n ) => Promise<unknown>;\n const startTime = performance.now();\n const requestParams = this._withContextHeaders(params);\n const ctx = applySessionContext(amplitudeOverrides);\n\n try {\n this._trackInputMessages(\n requestParams.input as unknown,\n ctx,\n amplitudeOverrides?.trackInputMessages ?? true,\n );\n const response = await createFn.call(this._original, requestParams);\n if (requestParams.stream === true && _isAsyncIterable(response)) {\n return this._wrapStream(\n response as AsyncIterable<unknown>,\n requestParams,\n startTime,\n ctx,\n );\n }\n\n const latencyMs = performance.now() - startTime;\n const resp = response as OpenAIResponse;\n const usage = resp.usage;\n const responseText = extractResponsesText(resp);\n const responseToolCalls = extractResponsesToolCalls(resp);\n const modelName = String(resp.model ?? requestParams.model ?? 'unknown');\n\n let costUsd: number | null = null;\n if (usage?.input_tokens != null && usage?.output_tokens != null) {\n try {\n costUsd = calculateCost({\n modelName,\n inputTokens: usage.input_tokens,\n outputTokens: usage.output_tokens,\n reasoningTokens: usage.output_tokens_details?.reasoning_tokens ?? 0,\n });\n } catch {\n // cost calculation is best-effort\n }\n }\n\n this._trackFn({\n userId: ctx.userId ?? 'unknown',\n modelName,\n provider: this._providerName,\n responseContent: responseText,\n latencyMs,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n turnId: ctx.turnId ?? undefined,\n agentId: ctx.agentId,\n env: ctx.env,\n inputTokens: usage?.input_tokens,\n outputTokens: usage?.output_tokens,\n totalTokens: usage?.total_tokens,\n reasoningTokens: usage?.output_tokens_details?.reasoning_tokens,\n totalCostUsd: costUsd,\n finishReason: extractResponsesFinishReason(resp),\n toolCalls: responseToolCalls.length > 0 ? responseToolCalls : undefined,\n isStreaming: false,\n systemPrompt: extractResponsesSystemPrompt(requestParams),\n temperature: requestParams.temperature as number | undefined,\n maxOutputTokens: requestParams.max_output_tokens as number | undefined,\n topP: requestParams.top_p as number | undefined,\n });\n\n return response as OpenAIResponse;\n } catch (error) {\n const latencyMs = performance.now() - startTime;\n this._trackFn({\n userId: ctx.userId ?? 'unknown',\n modelName: String(requestParams.model ?? 'unknown'),\n provider: this._providerName,\n responseContent: '',\n latencyMs,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n agentId: ctx.agentId,\n env: ctx.env,\n isError: true,\n errorMessage: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n }\n\n async stream(\n params: Record<string, unknown>,\n amplitudeOverrides?: ProviderTrackOptions,\n ): Promise<AsyncIterable<unknown>> {\n const streamFn = this._original.stream as\n | ((...args: unknown[]) => Promise<unknown>)\n | undefined;\n if (typeof streamFn !== 'function') {\n throw new Error('OpenAI SDK does not expose responses.stream');\n }\n const startTime = performance.now();\n const requestParams = this._withContextHeaders(params);\n const ctx = applySessionContext(amplitudeOverrides);\n\n try {\n this._trackInputMessages(\n requestParams.input as unknown,\n ctx,\n amplitudeOverrides?.trackInputMessages ?? true,\n );\n const response = await streamFn.call(this._original, requestParams);\n if (!_isAsyncIterable(response)) {\n throw new Error('OpenAI responses.stream did not return AsyncIterable');\n }\n return this._wrapStream(\n response as AsyncIterable<unknown>,\n requestParams,\n startTime,\n ctx,\n );\n } catch (error) {\n this._trackFn({\n userId: ctx.userId ?? 'unknown',\n modelName: String(requestParams.model ?? 'unknown'),\n provider: this._providerName,\n responseContent: '',\n latencyMs: performance.now() - startTime,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n agentId: ctx.agentId,\n env: ctx.env,\n isError: true,\n errorMessage: error instanceof Error ? error.message : String(error),\n isStreaming: true,\n });\n throw error;\n }\n }\n\n private async *_wrapStream(\n stream: AsyncIterable<unknown>,\n params: Record<string, unknown>,\n _startTime: number,\n sessionCtx: ProviderTrackOptions,\n ): AsyncGenerator<unknown> {\n const accumulator = new StreamingAccumulator();\n accumulator.model = String(params.model ?? 'unknown');\n\n try {\n for await (const event of stream) {\n const e = event as Record<string, unknown>;\n const type = e.type as string | undefined;\n if (type === 'response.output_text.delta') {\n const delta = e.delta;\n if (typeof delta === 'string') accumulator.addContent(delta);\n } else if (type === 'response.completed') {\n const response = e.response as OpenAIResponse | undefined;\n if (response != null) {\n const outputText = extractResponsesText(response);\n if (outputText.length > 0) {\n accumulator.content = outputText;\n }\n const usage = response.usage;\n accumulator.setUsage({\n inputTokens: usage?.input_tokens,\n outputTokens: usage?.output_tokens,\n totalTokens: usage?.total_tokens,\n reasoningTokens: usage?.output_tokens_details?.reasoning_tokens,\n });\n const finishReason = extractResponsesFinishReason(response);\n if (finishReason != null) accumulator.finishReason = finishReason;\n }\n }\n yield event;\n }\n } catch (error) {\n accumulator.setError(\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n } finally {\n const state = accumulator.getState();\n let costUsd: number | null = null;\n if (state.inputTokens != null && state.outputTokens != null) {\n try {\n costUsd = calculateCost({\n modelName: String(accumulator.model ?? params.model ?? 'unknown'),\n inputTokens: state.inputTokens,\n outputTokens: state.outputTokens,\n reasoningTokens: state.reasoningTokens ?? 0,\n });\n } catch {\n // cost calculation is best-effort\n }\n }\n this._trackFn({\n userId: sessionCtx.userId ?? 'unknown',\n modelName: String(accumulator.model ?? params.model ?? 'unknown'),\n provider: this._providerName,\n responseContent: state.content,\n latencyMs: accumulator.elapsedMs,\n sessionId: sessionCtx.sessionId,\n traceId: sessionCtx.traceId,\n turnId: sessionCtx.turnId ?? undefined,\n agentId: sessionCtx.agentId,\n env: sessionCtx.env,\n inputTokens: state.inputTokens,\n outputTokens: state.outputTokens,\n totalTokens: state.totalTokens,\n reasoningTokens: state.reasoningTokens,\n totalCostUsd: costUsd,\n finishReason: state.finishReason,\n providerTtfbMs: state.ttfbMs,\n isStreaming: true,\n isError: state.isError,\n errorMessage: state.errorMessage,\n systemPrompt: extractResponsesSystemPrompt(params),\n temperature: params.temperature as number | undefined,\n maxOutputTokens: params.max_output_tokens as number | undefined,\n topP: params.top_p as number | undefined,\n });\n }\n }\n\n private _withContextHeaders(\n params: Record<string, unknown>,\n ): Record<string, unknown> {\n if (!this._propagateContext) return params;\n const existing = (params.extra_headers ?? params.headers) as\n | Record<string, string>\n | undefined;\n const injected = injectContext(existing);\n return {\n ...params,\n extra_headers: injected,\n };\n }\n\n private _trackInputMessages(\n input: unknown,\n ctx: ProviderTrackOptions,\n shouldTrackInputMessages: boolean,\n ): void {\n if (!shouldTrackInputMessages) return;\n if (ctx.userId == null || ctx.sessionId == null) return;\n for (const text of extractResponsesUserInputs(input)) {\n if (!text) continue;\n trackUserMessage({\n amplitude: this._amplitude,\n userId: ctx.userId,\n messageContent: text,\n sessionId: ctx.sessionId,\n traceId: ctx.traceId,\n turnId: ctx.turnId ?? undefined,\n agentId: ctx.agentId,\n parentAgentId: ctx.parentAgentId,\n customerOrgId: ctx.customerOrgId,\n env: ctx.env,\n groups: ctx.groups,\n privacyConfig: this._privacyConfig,\n });\n }\n }\n}\n\nfunction _isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {\n return (\n value != null &&\n typeof (value as Record<symbol, unknown>)[Symbol.asyncIterator] ===\n 'function'\n );\n}\n\nexport function extractSystemPrompt(\n params: Record<string, unknown>,\n): string | undefined {\n const messages = params.messages as\n | Array<Record<string, unknown>>\n | undefined;\n if (!messages?.length) return undefined;\n const systemMsg = messages.find(\n (m) => m.role === 'system' || m.role === 'developer',\n );\n return systemMsg ? String(systemMsg.content ?? '') : undefined;\n}\n\nfunction extractResponsesSystemPrompt(\n params: Record<string, unknown>,\n): string | undefined {\n const instructions = params.instructions;\n return typeof instructions === 'string' ? instructions : undefined;\n}\n\nfunction extractResponsesFinishReason(\n resp: OpenAIResponse,\n): string | undefined {\n const status = resp.status;\n if (typeof status === 'string' && status.length > 0) return status;\n const out = resp.output?.[0];\n if (out != null && typeof out.status === 'string') return out.status;\n return undefined;\n}\n\nfunction extractResponsesText(resp: OpenAIResponse): string {\n if (typeof resp.output_text === 'string') return resp.output_text;\n const outputs = resp.output ?? [];\n let text = '';\n for (const item of outputs) {\n text += extractOutputItemText(item);\n }\n return text;\n}\n\nfunction extractResponsesToolCalls(\n resp: OpenAIResponse,\n): Array<Record<string, unknown>> {\n const toolCalls: Array<Record<string, unknown>> = [];\n const outputs = resp.output ?? [];\n for (const item of outputs) {\n if (!Array.isArray(item.content)) continue;\n for (const contentItem of item.content) {\n if (\n contentItem?.type === 'tool_call' ||\n contentItem?.type === 'function_call'\n ) {\n toolCalls.push(contentItem as Record<string, unknown>);\n }\n }\n }\n return toolCalls;\n}\n\nfunction extractOutputItemText(item: OpenAIResponseOutputItem): string {\n if (!Array.isArray(item.content)) return '';\n let text = '';\n for (const c of item.content) {\n if (typeof c?.text === 'string') text += c.text;\n }\n return text;\n}\n\nfunction extractResponsesUserInputs(input: unknown): string[] {\n if (typeof input === 'string') return [input];\n if (!Array.isArray(input)) return [];\n\n const result: string[] = [];\n for (const entry of input as OpenAIResponseInput[]) {\n if (typeof entry === 'string') {\n result.push(entry);\n continue;\n }\n const role = entry.role;\n if (role !== 'user') continue;\n const content = entry.content;\n if (typeof content === 'string') {\n result.push(content);\n } else if (Array.isArray(content)) {\n for (const part of content) {\n if (typeof part?.text === 'string') result.push(part.text);\n }\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;;AA+BA,MAAM,YAAY,WAAW,SAAS;AACtC,MAAa,mBAAmB,aAAa;AAC7C,MAAMA,gBAAgD;AActD,IAAa,SAAb,cAEU,eAAe;CACvB,AAAQ;CACR,AAAS;CACT,AAAS;CACT,AAAQ;CAER,YAAY,SAAwB;AAClC,QAAM;GACJ,WAAW,QAAQ;GACnB,eAAe,QAAQ;GACvB,cAAc;GACf,CAAC;EAEF,MAAM,MACH,QAAQ,gBAAmD;AAC9D,MAAI,OAAO,KACT,OAAM,IAAI,MACR,6HACD;EAGH,MAAM,YAAY,IAAI;EAItB,MAAMC,aAAsC,EAAE;AAC9C,MAAI,QAAQ,OAAQ,YAAW,SAAS,QAAQ;AAChD,MAAI,QAAQ,QAAS,YAAW,UAAU,QAAQ;AAElD,OAAK,UAAU,IAAI,UAAU,WAAW;AACxC,OAAK,oBACH,QAAQ,oBAAoB,4BAA4B;AAC1D,OAAK,OAAO,IAAI,YACd,KAAK,SACL,KAA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AO,GAAG,SAAS,SAAU,SAAQ,EAAE;AAE7C,QAAO;;AAGT,SAAS,2BAA2B,OAA0B;AAC5D,KAAI,OAAO,UAAU,SAAU,QAAO,CAAC,MAAM;AAC7C,KAAI,CAAC,MAAM,QAAQ,MAAM,CAAE,QAAO,EAAE;CAEpC,MAAMC,SAAmB,EAAE;AAC3B,MAAK,MAAM,SAAS,OAAgC;AAClD,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAO,KAAK,MAAM;AAClB;;AAGF,MADa,MAAM,SACN,OAAQ;EACrB,MAAM,UAAU,MAAM;AACtB,MAAI,OAAO,YAAY,SACrB,QAAO,KAAK,QAAQ;WACX,MAAM,QAAQ,QAAQ,EAC/B;QAAK,MAAM,QAAQ,QACjB,KAAI,OAAO,MAAM,SAAS,SAAU,QAAO,KAAK,KAAK,KAAK;;;AAIhE,QAAO"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,46 @@
1
+ import { AIConfig, ContentMode } from "./config.js";
2
+ import { patch } from "./patching.js";
3
+ import { AmplitudeAI } from "./client.js";
4
+
5
+ //#region src/register.ts
6
+ /**
7
+ * Preload module for zero-code LLM instrumentation.
8
+ *
9
+ * Usage:
10
+ * node --import @amplitude/ai/register app.js
11
+ *
12
+ * Or via the CLI wrapper:
13
+ * AMPLITUDE_AI_API_KEY=xxx AMPLITUDE_AI_AUTO_PATCH=true amplitude-ai-instrument node app.js
14
+ *
15
+ * Environment variables:
16
+ * - AMPLITUDE_AI_API_KEY (required): Amplitude API key
17
+ * - AMPLITUDE_AI_AUTO_PATCH: Must be "true" to enable auto-patching
18
+ * - AMPLITUDE_AI_CONTENT_MODE: "full" (default), "metadata_only", or "customer_enriched"
19
+ * - AMPLITUDE_AI_DEBUG: "true" for debug output to stderr
20
+ */
21
+ const apiKey = process.env.AMPLITUDE_AI_API_KEY ?? "";
22
+ const autoPatch = (process.env.AMPLITUDE_AI_AUTO_PATCH ?? "").toLowerCase() === "true";
23
+ if (!apiKey) {
24
+ if (autoPatch) process.stderr.write("amplitude-ai: AMPLITUDE_AI_API_KEY not set, skipping auto-patch.\n");
25
+ } else if (autoPatch) try {
26
+ const debug = (process.env.AMPLITUDE_AI_DEBUG ?? "").toLowerCase() === "true";
27
+ const contentModeStr = (process.env.AMPLITUDE_AI_CONTENT_MODE ?? "full").toLowerCase();
28
+ let contentMode = ContentMode.FULL;
29
+ if (contentModeStr === "metadata_only") contentMode = ContentMode.METADATA_ONLY;
30
+ else if (contentModeStr === "customer_enriched") contentMode = ContentMode.CUSTOMER_ENRICHED;
31
+ patch({ amplitudeAI: new AmplitudeAI({
32
+ apiKey,
33
+ config: new AIConfig({
34
+ debug,
35
+ contentMode
36
+ })
37
+ }) });
38
+ const note = contentModeStr === "metadata_only" || contentModeStr === "customer_enriched" ? ` (content_mode=${contentModeStr})` : "";
39
+ process.stderr.write(`amplitude-ai: auto-patched providers${note}\n`);
40
+ } catch (err) {
41
+ process.stderr.write(`amplitude-ai: bootstrap error: ${err instanceof Error ? err.message : String(err)}\n`);
42
+ }
43
+
44
+ //#endregion
45
+ export { };
46
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","names":[],"sources":["../src/register.ts"],"sourcesContent":["/**\n * Preload module for zero-code LLM instrumentation.\n *\n * Usage:\n * node --import @amplitude/ai/register app.js\n *\n * Or via the CLI wrapper:\n * AMPLITUDE_AI_API_KEY=xxx AMPLITUDE_AI_AUTO_PATCH=true amplitude-ai-instrument node app.js\n *\n * Environment variables:\n * - AMPLITUDE_AI_API_KEY (required): Amplitude API key\n * - AMPLITUDE_AI_AUTO_PATCH: Must be \"true\" to enable auto-patching\n * - AMPLITUDE_AI_CONTENT_MODE: \"full\" (default), \"metadata_only\", or \"customer_enriched\"\n * - AMPLITUDE_AI_DEBUG: \"true\" for debug output to stderr\n */\n\nimport { AmplitudeAI } from './client.js';\nimport { AIConfig, ContentMode } from './config.js';\nimport { patch } from './patching.js';\n\nconst apiKey = process.env.AMPLITUDE_AI_API_KEY ?? '';\nconst autoPatch =\n (process.env.AMPLITUDE_AI_AUTO_PATCH ?? '').toLowerCase() === 'true';\n\nif (!apiKey) {\n if (autoPatch) {\n process.stderr.write(\n 'amplitude-ai: AMPLITUDE_AI_API_KEY not set, skipping auto-patch.\\n',\n );\n }\n} else if (autoPatch) {\n try {\n const debug =\n (process.env.AMPLITUDE_AI_DEBUG ?? '').toLowerCase() === 'true';\n const contentModeStr = (\n process.env.AMPLITUDE_AI_CONTENT_MODE ?? 'full'\n ).toLowerCase();\n\n let contentMode = ContentMode.FULL;\n if (contentModeStr === 'metadata_only')\n contentMode = ContentMode.METADATA_ONLY;\n else if (contentModeStr === 'customer_enriched')\n contentMode = ContentMode.CUSTOMER_ENRICHED;\n\n const config = new AIConfig({ debug, contentMode });\n const ai = new AmplitudeAI({ apiKey, config });\n\n patch({ amplitudeAI: ai });\n\n const privacyMode =\n contentModeStr === 'metadata_only' ||\n contentModeStr === 'customer_enriched';\n const note = privacyMode ? ` (content_mode=${contentModeStr})` : '';\n process.stderr.write(`amplitude-ai: auto-patched providers${note}\\n`);\n } catch (err) {\n process.stderr.write(\n `amplitude-ai: bootstrap error: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,SAAS,QAAQ,IAAI,wBAAwB;AACnD,MAAM,aACH,QAAQ,IAAI,2BAA2B,IAAI,aAAa,KAAK;AAEhE,IAAI,CAAC,QACH;KAAI,UACF,SAAQ,OAAO,MACb,qEACD;WAEM,UACT,KAAI;CACF,MAAM,SACH,QAAQ,IAAI,sBAAsB,IAAI,aAAa,KAAK;CAC3D,MAAM,kBACJ,QAAQ,IAAI,6BAA6B,QACzC,aAAa;CAEf,IAAI,cAAc,YAAY;AAC9B,KAAI,mBAAmB,gBACrB,eAAc,YAAY;UACnB,mBAAmB,oBAC1B,eAAc,YAAY;AAK5B,OAAM,EAAE,aAFG,IAAI,YAAY;EAAE;EAAQ,QADtB,IAAI,SAAS;GAAE;GAAO;GAAa,CAAC;EACN,CAAC,EAErB,CAAC;CAK1B,MAAM,OAFJ,mBAAmB,mBACnB,mBAAmB,sBACM,kBAAkB,eAAe,KAAK;AACjE,SAAQ,OAAO,MAAM,uCAAuC,KAAK,IAAI;SAC9D,KAAK;AACZ,SAAQ,OAAO,MACb,kCAAkC,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,CAAC,IACpF"}