@copilotkit/shared 2.0.0-next.1 → 2.0.0-rc.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 (592) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -12
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/a2ui-envelope.cjs +154 -0
  5. package/dist/a2ui-envelope.cjs.map +1 -0
  6. package/dist/a2ui-envelope.d.cts +101 -0
  7. package/dist/a2ui-envelope.d.cts.map +1 -0
  8. package/dist/a2ui-envelope.d.mts +101 -0
  9. package/dist/a2ui-envelope.d.mts.map +1 -0
  10. package/dist/a2ui-envelope.mjs +151 -0
  11. package/dist/a2ui-envelope.mjs.map +1 -0
  12. package/dist/a2ui-prompts.cjs +259 -0
  13. package/dist/a2ui-prompts.cjs.map +1 -0
  14. package/dist/a2ui-prompts.d.cts +79 -0
  15. package/dist/a2ui-prompts.d.cts.map +1 -0
  16. package/dist/a2ui-prompts.d.mts +79 -0
  17. package/dist/a2ui-prompts.d.mts.map +1 -0
  18. package/dist/a2ui-prompts.mjs +251 -0
  19. package/dist/a2ui-prompts.mjs.map +1 -0
  20. package/dist/attachments/content.cjs +17 -0
  21. package/dist/attachments/content.cjs.map +1 -0
  22. package/dist/attachments/content.d.cts +9 -0
  23. package/dist/attachments/content.d.cts.map +1 -0
  24. package/dist/attachments/content.d.mts +9 -0
  25. package/dist/attachments/content.d.mts.map +1 -0
  26. package/dist/attachments/content.mjs +16 -0
  27. package/dist/attachments/content.mjs.map +1 -0
  28. package/dist/attachments/types.d.cts +64 -0
  29. package/dist/attachments/types.d.cts.map +1 -0
  30. package/dist/attachments/types.d.mts +64 -0
  31. package/dist/attachments/types.d.mts.map +1 -0
  32. package/dist/attachments/utils.cjs +137 -0
  33. package/dist/attachments/utils.cjs.map +1 -0
  34. package/dist/attachments/utils.d.cts +44 -0
  35. package/dist/attachments/utils.d.cts.map +1 -0
  36. package/dist/attachments/utils.d.mts +44 -0
  37. package/dist/attachments/utils.d.mts.map +1 -0
  38. package/dist/attachments/utils.mjs +129 -0
  39. package/dist/attachments/utils.mjs.map +1 -0
  40. package/dist/constants/index.cjs +25 -0
  41. package/dist/constants/index.cjs.map +1 -0
  42. package/dist/constants/index.d.cts +17 -0
  43. package/dist/constants/index.d.cts.map +1 -0
  44. package/dist/constants/index.d.mts +17 -0
  45. package/dist/constants/index.d.mts.map +1 -0
  46. package/dist/constants/index.mjs +17 -12
  47. package/dist/constants/index.mjs.map +1 -1
  48. package/dist/debug-event-envelope.d.cts +13 -0
  49. package/dist/debug-event-envelope.d.cts.map +1 -0
  50. package/dist/debug-event-envelope.d.mts +13 -0
  51. package/dist/debug-event-envelope.d.mts.map +1 -0
  52. package/dist/debug.cjs +38 -0
  53. package/dist/debug.cjs.map +1 -0
  54. package/dist/debug.d.cts +29 -0
  55. package/dist/debug.d.cts.map +1 -0
  56. package/dist/debug.d.mts +29 -0
  57. package/dist/debug.d.mts.map +1 -0
  58. package/dist/debug.mjs +37 -0
  59. package/dist/debug.mjs.map +1 -0
  60. package/dist/event-transforms/index.cjs +15 -0
  61. package/dist/event-transforms/index.d.cts +4 -0
  62. package/dist/event-transforms/index.d.mts +4 -0
  63. package/dist/event-transforms/index.mjs +5 -0
  64. package/dist/event-transforms/open-generative-ui-middleware.cjs +286 -0
  65. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  66. package/dist/event-transforms/open-generative-ui-middleware.d.cts +60 -0
  67. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  68. package/dist/event-transforms/open-generative-ui-middleware.d.mts +60 -0
  69. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  70. package/dist/event-transforms/open-generative-ui-middleware.mjs +283 -0
  71. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  72. package/dist/event-transforms/recorded-events.cjs +59 -0
  73. package/dist/event-transforms/recorded-events.cjs.map +1 -0
  74. package/dist/event-transforms/recorded-events.d.cts +23 -0
  75. package/dist/event-transforms/recorded-events.d.cts.map +1 -0
  76. package/dist/event-transforms/recorded-events.d.mts +23 -0
  77. package/dist/event-transforms/recorded-events.d.mts.map +1 -0
  78. package/dist/event-transforms/recorded-events.mjs +58 -0
  79. package/dist/event-transforms/recorded-events.mjs.map +1 -0
  80. package/dist/finalize-events.cjs +186 -0
  81. package/dist/finalize-events.cjs.map +1 -0
  82. package/dist/finalize-events.d.cts +40 -0
  83. package/dist/finalize-events.d.cts.map +1 -0
  84. package/dist/finalize-events.d.mts +40 -0
  85. package/dist/finalize-events.d.mts.map +1 -0
  86. package/dist/finalize-events.mjs +184 -0
  87. package/dist/finalize-events.mjs.map +1 -0
  88. package/dist/generative-ui/basic-functions.cjs +177 -0
  89. package/dist/generative-ui/basic-functions.cjs.map +1 -0
  90. package/dist/generative-ui/basic-functions.d.cts +108 -0
  91. package/dist/generative-ui/basic-functions.d.cts.map +1 -0
  92. package/dist/generative-ui/basic-functions.d.mts +108 -0
  93. package/dist/generative-ui/basic-functions.d.mts.map +1 -0
  94. package/dist/generative-ui/basic-functions.mjs +167 -0
  95. package/dist/generative-ui/basic-functions.mjs.map +1 -0
  96. package/dist/generative-ui/child-refs.cjs +161 -0
  97. package/dist/generative-ui/child-refs.cjs.map +1 -0
  98. package/dist/generative-ui/child-refs.d.cts +68 -0
  99. package/dist/generative-ui/child-refs.d.cts.map +1 -0
  100. package/dist/generative-ui/child-refs.d.mts +68 -0
  101. package/dist/generative-ui/child-refs.d.mts.map +1 -0
  102. package/dist/generative-ui/child-refs.mjs +152 -0
  103. package/dist/generative-ui/child-refs.mjs.map +1 -0
  104. package/dist/generative-ui/is-record.cjs +10 -0
  105. package/dist/generative-ui/is-record.cjs.map +1 -0
  106. package/dist/generative-ui/is-record.mjs +9 -0
  107. package/dist/generative-ui/is-record.mjs.map +1 -0
  108. package/dist/generative-ui/prompt.cjs +91 -0
  109. package/dist/generative-ui/prompt.cjs.map +1 -0
  110. package/dist/generative-ui/prompt.d.cts +13 -0
  111. package/dist/generative-ui/prompt.d.cts.map +1 -0
  112. package/dist/generative-ui/prompt.d.mts +13 -0
  113. package/dist/generative-ui/prompt.d.mts.map +1 -0
  114. package/dist/generative-ui/prompt.mjs +90 -0
  115. package/dist/generative-ui/prompt.mjs.map +1 -0
  116. package/dist/generative-ui/render-ui-args.cjs +160 -0
  117. package/dist/generative-ui/render-ui-args.cjs.map +1 -0
  118. package/dist/generative-ui/render-ui-args.d.cts +40 -0
  119. package/dist/generative-ui/render-ui-args.d.cts.map +1 -0
  120. package/dist/generative-ui/render-ui-args.d.mts +40 -0
  121. package/dist/generative-ui/render-ui-args.d.mts.map +1 -0
  122. package/dist/generative-ui/render-ui-args.mjs +159 -0
  123. package/dist/generative-ui/render-ui-args.mjs.map +1 -0
  124. package/dist/generative-ui/types.cjs +101 -0
  125. package/dist/generative-ui/types.cjs.map +1 -0
  126. package/dist/generative-ui/types.d.cts +270 -0
  127. package/dist/generative-ui/types.d.cts.map +1 -0
  128. package/dist/generative-ui/types.d.mts +270 -0
  129. package/dist/generative-ui/types.d.mts.map +1 -0
  130. package/dist/generative-ui/types.mjs +86 -0
  131. package/dist/generative-ui/types.mjs.map +1 -0
  132. package/dist/generative-ui/validate-operation.cjs +405 -0
  133. package/dist/generative-ui/validate-operation.cjs.map +1 -0
  134. package/dist/generative-ui/validate-operation.d.cts +86 -0
  135. package/dist/generative-ui/validate-operation.d.cts.map +1 -0
  136. package/dist/generative-ui/validate-operation.d.mts +86 -0
  137. package/dist/generative-ui/validate-operation.d.mts.map +1 -0
  138. package/dist/generative-ui/validate-operation.mjs +399 -0
  139. package/dist/generative-ui/validate-operation.mjs.map +1 -0
  140. package/dist/index.cjs +233 -0
  141. package/dist/index.cjs.map +1 -0
  142. package/dist/index.d.cts +80 -0
  143. package/dist/index.d.cts.map +1 -0
  144. package/dist/index.d.mts +80 -0
  145. package/dist/index.d.mts.map +1 -0
  146. package/dist/index.mjs +78 -123
  147. package/dist/index.mjs.map +1 -1
  148. package/dist/index.umd.js +3979 -0
  149. package/dist/index.umd.js.map +1 -0
  150. package/dist/intelligence-routing-fields.cjs +35 -0
  151. package/dist/intelligence-routing-fields.cjs.map +1 -0
  152. package/dist/intelligence-routing-fields.d.cts +18 -0
  153. package/dist/intelligence-routing-fields.d.cts.map +1 -0
  154. package/dist/intelligence-routing-fields.d.mts +18 -0
  155. package/dist/intelligence-routing-fields.d.mts.map +1 -0
  156. package/dist/intelligence-routing-fields.mjs +34 -0
  157. package/dist/intelligence-routing-fields.mjs.map +1 -0
  158. package/dist/logger.cjs +7 -0
  159. package/dist/logger.cjs.map +1 -0
  160. package/dist/logger.d.cts +5 -0
  161. package/dist/logger.d.cts.map +1 -0
  162. package/dist/logger.d.mts +5 -0
  163. package/dist/logger.d.mts.map +1 -0
  164. package/dist/logger.mjs +6 -0
  165. package/dist/logger.mjs.map +1 -0
  166. package/dist/open-generative-ui-prompts.cjs +8 -0
  167. package/dist/open-generative-ui-prompts.cjs.map +1 -0
  168. package/dist/open-generative-ui-prompts.d.cts +6 -0
  169. package/dist/open-generative-ui-prompts.d.cts.map +1 -0
  170. package/dist/open-generative-ui-prompts.d.mts +6 -0
  171. package/dist/open-generative-ui-prompts.d.mts.map +1 -0
  172. package/dist/open-generative-ui-prompts.mjs +7 -0
  173. package/dist/open-generative-ui-prompts.mjs.map +1 -0
  174. package/dist/package.cjs +12 -0
  175. package/dist/package.cjs.map +1 -0
  176. package/dist/package.mjs +6 -0
  177. package/dist/package.mjs.map +1 -0
  178. package/dist/standard-schema.cjs +31 -0
  179. package/dist/standard-schema.cjs.map +1 -0
  180. package/dist/standard-schema.d.cts +33 -0
  181. package/dist/standard-schema.d.cts.map +1 -0
  182. package/dist/standard-schema.d.mts +33 -0
  183. package/dist/standard-schema.d.mts.map +1 -0
  184. package/dist/standard-schema.mjs +30 -0
  185. package/dist/standard-schema.mjs.map +1 -0
  186. package/dist/telemetry/events.d.cts +72 -0
  187. package/dist/telemetry/events.d.cts.map +1 -0
  188. package/dist/telemetry/events.d.mts +72 -0
  189. package/dist/telemetry/events.d.mts.map +1 -0
  190. package/dist/telemetry/index.cjs +18 -0
  191. package/dist/telemetry/index.d.cts +5 -0
  192. package/dist/telemetry/index.d.mts +5 -0
  193. package/dist/telemetry/index.mjs +6 -12
  194. package/dist/telemetry/lambda-client.cjs +91 -0
  195. package/dist/telemetry/lambda-client.cjs.map +1 -0
  196. package/dist/telemetry/lambda-client.d.cts +31 -0
  197. package/dist/telemetry/lambda-client.d.cts.map +1 -0
  198. package/dist/telemetry/lambda-client.d.mts +31 -0
  199. package/dist/telemetry/lambda-client.d.mts.map +1 -0
  200. package/dist/telemetry/lambda-client.mjs +87 -0
  201. package/dist/telemetry/lambda-client.mjs.map +1 -0
  202. package/dist/telemetry/model-host.cjs +104 -0
  203. package/dist/telemetry/model-host.cjs.map +1 -0
  204. package/dist/telemetry/model-host.d.cts +26 -0
  205. package/dist/telemetry/model-host.d.cts.map +1 -0
  206. package/dist/telemetry/model-host.d.mts +26 -0
  207. package/dist/telemetry/model-host.d.mts.map +1 -0
  208. package/dist/telemetry/model-host.mjs +102 -0
  209. package/dist/telemetry/model-host.mjs.map +1 -0
  210. package/dist/telemetry/sampling.cjs +50 -0
  211. package/dist/telemetry/sampling.cjs.map +1 -0
  212. package/dist/telemetry/sampling.d.cts +57 -0
  213. package/dist/telemetry/sampling.d.cts.map +1 -0
  214. package/dist/telemetry/sampling.d.mts +57 -0
  215. package/dist/telemetry/sampling.d.mts.map +1 -0
  216. package/dist/telemetry/sampling.mjs +44 -0
  217. package/dist/telemetry/sampling.mjs.map +1 -0
  218. package/dist/telemetry/telemetry-client.cjs +165 -0
  219. package/dist/telemetry/telemetry-client.cjs.map +1 -0
  220. package/dist/telemetry/telemetry-client.d.cts +87 -0
  221. package/dist/telemetry/telemetry-client.d.cts.map +1 -0
  222. package/dist/telemetry/telemetry-client.d.mts +87 -0
  223. package/dist/telemetry/telemetry-client.d.mts.map +1 -0
  224. package/dist/telemetry/telemetry-client.mjs +162 -9
  225. package/dist/telemetry/telemetry-client.mjs.map +1 -1
  226. package/dist/telemetry/telemetry-disabled.cjs +20 -0
  227. package/dist/telemetry/telemetry-disabled.cjs.map +1 -0
  228. package/dist/telemetry/telemetry-disabled.d.cts +16 -0
  229. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -0
  230. package/dist/telemetry/telemetry-disabled.d.mts +16 -0
  231. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -0
  232. package/dist/telemetry/telemetry-disabled.mjs +19 -0
  233. package/dist/telemetry/telemetry-disabled.mjs.map +1 -0
  234. package/dist/telemetry/utils.cjs +14 -0
  235. package/dist/telemetry/utils.cjs.map +1 -0
  236. package/dist/telemetry/utils.mjs +12 -8
  237. package/dist/telemetry/utils.mjs.map +1 -1
  238. package/dist/transcription-errors.cjs +84 -0
  239. package/dist/transcription-errors.cjs.map +1 -0
  240. package/dist/transcription-errors.d.cts +52 -0
  241. package/dist/transcription-errors.d.cts.map +1 -0
  242. package/dist/transcription-errors.d.mts +52 -0
  243. package/dist/transcription-errors.d.mts.map +1 -0
  244. package/dist/transcription-errors.mjs +82 -0
  245. package/dist/transcription-errors.mjs.map +1 -0
  246. package/dist/types/{action.d.ts → action.d.cts} +32 -32
  247. package/dist/types/action.d.cts.map +1 -0
  248. package/dist/types/action.d.mts +59 -0
  249. package/dist/types/action.d.mts.map +1 -0
  250. package/dist/types/copilot-cloud-config.d.cts +15 -0
  251. package/dist/types/copilot-cloud-config.d.cts.map +1 -0
  252. package/dist/types/copilot-cloud-config.d.mts +15 -0
  253. package/dist/types/copilot-cloud-config.d.mts.map +1 -0
  254. package/dist/types/error.d.cts +57 -0
  255. package/dist/types/error.d.cts.map +1 -0
  256. package/dist/types/error.d.mts +57 -0
  257. package/dist/types/error.d.mts.map +1 -0
  258. package/dist/types/message.d.cts +42 -0
  259. package/dist/types/message.d.cts.map +1 -0
  260. package/dist/types/message.d.mts +42 -0
  261. package/dist/types/message.d.mts.map +1 -0
  262. package/dist/types/openai-assistant.d.cts +55 -0
  263. package/dist/types/openai-assistant.d.cts.map +1 -0
  264. package/dist/types/openai-assistant.d.mts +55 -0
  265. package/dist/types/openai-assistant.d.mts.map +1 -0
  266. package/dist/types/utility.d.cts +6 -0
  267. package/dist/types/utility.d.cts.map +1 -0
  268. package/dist/types/utility.d.mts +6 -0
  269. package/dist/types/utility.d.mts.map +1 -0
  270. package/dist/utils/clipboard.cjs +28 -0
  271. package/dist/utils/clipboard.cjs.map +1 -0
  272. package/dist/utils/clipboard.d.cts +14 -0
  273. package/dist/utils/clipboard.d.cts.map +1 -0
  274. package/dist/utils/clipboard.d.mts +14 -0
  275. package/dist/utils/clipboard.d.mts.map +1 -0
  276. package/dist/utils/clipboard.mjs +27 -0
  277. package/dist/utils/clipboard.mjs.map +1 -0
  278. package/dist/utils/conditions.cjs +32 -0
  279. package/dist/utils/conditions.cjs.map +1 -0
  280. package/dist/utils/{conditions.d.ts → conditions.d.cts} +16 -11
  281. package/dist/utils/conditions.d.cts.map +1 -0
  282. package/dist/utils/conditions.d.mts +31 -0
  283. package/dist/utils/conditions.d.mts.map +1 -0
  284. package/dist/utils/conditions.mjs +30 -6
  285. package/dist/utils/conditions.mjs.map +1 -1
  286. package/dist/utils/console-styling.cjs +91 -0
  287. package/dist/utils/console-styling.cjs.map +1 -0
  288. package/dist/utils/console-styling.d.cts +65 -0
  289. package/dist/utils/console-styling.d.cts.map +1 -0
  290. package/dist/utils/console-styling.d.mts +65 -0
  291. package/dist/utils/console-styling.d.mts.map +1 -0
  292. package/dist/utils/console-styling.mjs +83 -15
  293. package/dist/utils/console-styling.mjs.map +1 -1
  294. package/dist/utils/dashboard-url.cjs +19 -0
  295. package/dist/utils/dashboard-url.cjs.map +1 -0
  296. package/dist/utils/dashboard-url.mjs +18 -0
  297. package/dist/utils/dashboard-url.mjs.map +1 -0
  298. package/dist/utils/errors.cjs +439 -0
  299. package/dist/utils/errors.cjs.map +1 -0
  300. package/dist/utils/{errors.d.ts → errors.d.cts} +188 -156
  301. package/dist/utils/errors.d.cts.map +1 -0
  302. package/dist/utils/errors.d.mts +312 -0
  303. package/dist/utils/errors.d.mts.map +1 -0
  304. package/dist/utils/errors.mjs +416 -63
  305. package/dist/utils/errors.mjs.map +1 -1
  306. package/dist/utils/index.cjs +105 -0
  307. package/dist/utils/index.cjs.map +1 -0
  308. package/dist/utils/index.d.cts +58 -0
  309. package/dist/utils/index.d.cts.map +1 -0
  310. package/dist/utils/index.d.mts +58 -0
  311. package/dist/utils/index.d.mts.map +1 -0
  312. package/dist/utils/index.mjs +97 -107
  313. package/dist/utils/index.mjs.map +1 -1
  314. package/dist/utils/inspector-learning.cjs +217 -0
  315. package/dist/utils/inspector-learning.cjs.map +1 -0
  316. package/dist/utils/inspector-learning.d.cts +104 -0
  317. package/dist/utils/inspector-learning.d.cts.map +1 -0
  318. package/dist/utils/inspector-learning.d.mts +104 -0
  319. package/dist/utils/inspector-learning.d.mts.map +1 -0
  320. package/dist/utils/inspector-learning.mjs +215 -0
  321. package/dist/utils/inspector-learning.mjs.map +1 -0
  322. package/dist/utils/inspector-metadata.cjs +146 -0
  323. package/dist/utils/inspector-metadata.cjs.map +1 -0
  324. package/dist/utils/inspector-metadata.d.cts +55 -0
  325. package/dist/utils/inspector-metadata.d.cts.map +1 -0
  326. package/dist/utils/inspector-metadata.d.mts +55 -0
  327. package/dist/utils/inspector-metadata.d.mts.map +1 -0
  328. package/dist/utils/inspector-metadata.mjs +146 -0
  329. package/dist/utils/inspector-metadata.mjs.map +1 -0
  330. package/dist/utils/inspector-visibility.cjs +13 -0
  331. package/dist/utils/inspector-visibility.cjs.map +1 -0
  332. package/dist/utils/inspector-visibility.d.cts +18 -0
  333. package/dist/utils/inspector-visibility.d.cts.map +1 -0
  334. package/dist/utils/inspector-visibility.d.mts +18 -0
  335. package/dist/utils/inspector-visibility.d.mts.map +1 -0
  336. package/dist/utils/inspector-visibility.mjs +12 -0
  337. package/dist/utils/inspector-visibility.mjs.map +1 -0
  338. package/dist/utils/json-schema.cjs +215 -0
  339. package/dist/utils/json-schema.cjs.map +1 -0
  340. package/dist/utils/{json-schema.d.ts → json-schema.d.cts} +20 -18
  341. package/dist/utils/json-schema.d.cts.map +1 -0
  342. package/dist/utils/json-schema.d.mts +36 -0
  343. package/dist/utils/json-schema.d.mts.map +1 -0
  344. package/dist/utils/json-schema.mjs +210 -12
  345. package/dist/utils/json-schema.mjs.map +1 -1
  346. package/dist/utils/random-id.cjs +38 -0
  347. package/dist/utils/random-id.cjs.map +1 -0
  348. package/dist/utils/{random-id.d.ts → random-id.d.cts} +3 -1
  349. package/dist/utils/random-id.d.cts.map +1 -0
  350. package/dist/utils/random-id.d.mts +8 -0
  351. package/dist/utils/random-id.d.mts.map +1 -0
  352. package/dist/utils/random-id.mjs +33 -12
  353. package/dist/utils/random-id.mjs.map +1 -1
  354. package/dist/utils/requests.cjs +58 -0
  355. package/dist/utils/requests.cjs.map +1 -0
  356. package/dist/utils/{requests.d.ts → requests.d.cts} +3 -1
  357. package/dist/utils/requests.d.cts.map +1 -0
  358. package/dist/utils/requests.d.mts +12 -0
  359. package/dist/utils/requests.d.mts.map +1 -0
  360. package/dist/utils/requests.mjs +56 -6
  361. package/dist/utils/requests.mjs.map +1 -1
  362. package/dist/utils/row-render-keys.cjs +206 -0
  363. package/dist/utils/row-render-keys.cjs.map +1 -0
  364. package/dist/utils/row-render-keys.d.cts +65 -0
  365. package/dist/utils/row-render-keys.d.cts.map +1 -0
  366. package/dist/utils/row-render-keys.d.mts +65 -0
  367. package/dist/utils/row-render-keys.d.mts.map +1 -0
  368. package/dist/utils/row-render-keys.mjs +201 -0
  369. package/dist/utils/row-render-keys.mjs.map +1 -0
  370. package/dist/utils/types.cjs +9 -0
  371. package/dist/utils/types.cjs.map +1 -0
  372. package/dist/utils/types.d.cts +122 -0
  373. package/dist/utils/types.d.cts.map +1 -0
  374. package/dist/utils/types.d.mts +122 -0
  375. package/dist/utils/types.d.mts.map +1 -0
  376. package/dist/utils/types.mjs +6 -1
  377. package/dist/utils/types.mjs.map +1 -1
  378. package/package.json +74 -40
  379. package/scripts/verify-cjs-exports.cjs +16 -0
  380. package/src/__tests__/a2ui-envelope.test.ts +434 -0
  381. package/src/__tests__/a2ui-prompts.test.ts +362 -0
  382. package/src/__tests__/debug.test.ts +116 -0
  383. package/src/__tests__/license-context.test.ts +253 -0
  384. package/src/__tests__/root-entry-browser-safety.test.ts +91 -0
  385. package/src/__tests__/standard-schema-types.test.ts +144 -0
  386. package/src/__tests__/standard-schema.test.ts +359 -0
  387. package/src/__tests__/zod-regression.test.ts +319 -0
  388. package/src/a2ui-envelope.ts +309 -0
  389. package/src/a2ui-prompts.ts +322 -0
  390. package/src/attachments/__tests__/utils.test.ts +214 -0
  391. package/src/attachments/content.test.ts +48 -0
  392. package/src/attachments/content.ts +16 -0
  393. package/src/attachments/index.ts +21 -0
  394. package/src/attachments/types.ts +77 -0
  395. package/src/attachments/utils.ts +169 -0
  396. package/src/constants/index.ts +14 -1
  397. package/src/debug-event-envelope.ts +9 -0
  398. package/src/debug.ts +55 -0
  399. package/src/event-transforms/index.ts +5 -0
  400. package/src/event-transforms/open-generative-ui-middleware.ts +392 -0
  401. package/src/event-transforms/recorded-events.test.ts +166 -0
  402. package/src/event-transforms/recorded-events.ts +74 -0
  403. package/src/finalize-events.test.ts +284 -0
  404. package/src/finalize-events.ts +260 -0
  405. package/src/generative-ui/__tests__/render-ui-args.test.ts +175 -0
  406. package/src/generative-ui/__tests__/validate-operation.test.ts +977 -0
  407. package/src/generative-ui/basic-functions.ts +282 -0
  408. package/src/generative-ui/child-refs.ts +210 -0
  409. package/src/generative-ui/index.ts +6 -0
  410. package/src/generative-ui/is-record.ts +4 -0
  411. package/src/generative-ui/prompt.ts +174 -0
  412. package/src/generative-ui/render-ui-args.ts +199 -0
  413. package/src/generative-ui/types.ts +314 -0
  414. package/src/generative-ui/validate-operation.ts +723 -0
  415. package/src/index.ts +190 -1
  416. package/src/intelligence-routing-fields.test.ts +51 -0
  417. package/src/intelligence-routing-fields.ts +40 -0
  418. package/src/logger.ts +1 -0
  419. package/src/open-generative-ui-prompts.ts +20 -0
  420. package/src/standard-schema.ts +82 -0
  421. package/src/telemetry/events.ts +37 -10
  422. package/src/telemetry/index.ts +8 -0
  423. package/src/telemetry/lambda-client.test.ts +446 -0
  424. package/src/telemetry/lambda-client.ts +194 -0
  425. package/src/telemetry/model-host.test.ts +145 -0
  426. package/src/telemetry/model-host.ts +156 -0
  427. package/src/telemetry/sampling.test.ts +65 -0
  428. package/src/telemetry/sampling.ts +103 -0
  429. package/src/telemetry/telemetry-blank-license-identity.test.ts +128 -0
  430. package/src/telemetry/telemetry-client.test.ts +798 -0
  431. package/src/telemetry/telemetry-client.ts +223 -37
  432. package/src/telemetry/telemetry-disabled.ts +22 -0
  433. package/src/telemetry/utils.ts +0 -24
  434. package/src/transcription-errors.ts +99 -0
  435. package/src/types/__tests__/message.test.ts +62 -0
  436. package/src/types/action.ts +9 -5
  437. package/src/types/error.ts +11 -2
  438. package/src/types/message.ts +33 -5
  439. package/src/types/openai-assistant.ts +6 -2
  440. package/src/utils/__tests__/clipboard.test.ts +87 -0
  441. package/src/utils/__tests__/conditions.test.ts +161 -0
  442. package/src/utils/__tests__/json-schema.test.ts +812 -0
  443. package/src/utils/__tests__/row-render-keys.test.ts +388 -0
  444. package/src/utils/clipboard.ts +23 -0
  445. package/src/utils/conditions.ts +27 -9
  446. package/src/utils/console-styling.ts +10 -8
  447. package/src/utils/dashboard-url.ts +17 -0
  448. package/src/utils/errors.ts +55 -22
  449. package/src/utils/index.ts +70 -1
  450. package/src/utils/inspector-learning.test.ts +423 -0
  451. package/src/utils/inspector-learning.ts +523 -0
  452. package/src/utils/inspector-metadata.test.ts +743 -0
  453. package/src/utils/inspector-metadata.ts +263 -0
  454. package/src/utils/inspector-visibility.test.ts +43 -0
  455. package/src/utils/inspector-visibility.ts +17 -0
  456. package/src/utils/json-schema.ts +156 -12
  457. package/src/utils/random-id.ts +5 -2
  458. package/src/utils/requests.ts +3 -1
  459. package/src/utils/row-render-keys.ts +263 -0
  460. package/src/utils/types.ts +128 -1
  461. package/src/utils.test.ts +137 -0
  462. package/tsconfig.json +10 -2
  463. package/tsdown.config.ts +49 -0
  464. package/vitest.config.mjs +11 -0
  465. package/CHANGELOG.md +0 -1817
  466. package/dist/chunk-2OJ5OJ2D.mjs +0 -1
  467. package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
  468. package/dist/chunk-64DYJ27R.mjs +0 -201
  469. package/dist/chunk-64DYJ27R.mjs.map +0 -1
  470. package/dist/chunk-6QGXWNS5.mjs +0 -34
  471. package/dist/chunk-6QGXWNS5.mjs.map +0 -1
  472. package/dist/chunk-6W2UEO2M.mjs +0 -94
  473. package/dist/chunk-6W2UEO2M.mjs.map +0 -1
  474. package/dist/chunk-7DJDTRNX.mjs +0 -426
  475. package/dist/chunk-7DJDTRNX.mjs.map +0 -1
  476. package/dist/chunk-A66772CV.mjs +0 -107
  477. package/dist/chunk-A66772CV.mjs.map +0 -1
  478. package/dist/chunk-BOKE4OKY.mjs +0 -41
  479. package/dist/chunk-BOKE4OKY.mjs.map +0 -1
  480. package/dist/chunk-FCCOSO5L.mjs +0 -1
  481. package/dist/chunk-FCCOSO5L.mjs.map +0 -1
  482. package/dist/chunk-GYZIHHE6.mjs +0 -13
  483. package/dist/chunk-GYZIHHE6.mjs.map +0 -1
  484. package/dist/chunk-IAFBVORQ.mjs +0 -1
  485. package/dist/chunk-IAFBVORQ.mjs.map +0 -1
  486. package/dist/chunk-JAAUCDUR.mjs +0 -38
  487. package/dist/chunk-JAAUCDUR.mjs.map +0 -1
  488. package/dist/chunk-MSUB6DGR.mjs +0 -1
  489. package/dist/chunk-MSUB6DGR.mjs.map +0 -1
  490. package/dist/chunk-N5EP5OD5.mjs +0 -1
  491. package/dist/chunk-N5EP5OD5.mjs.map +0 -1
  492. package/dist/chunk-NAFEBKSO.mjs +0 -1
  493. package/dist/chunk-NAFEBKSO.mjs.map +0 -1
  494. package/dist/chunk-P7STFMPO.mjs +0 -1
  495. package/dist/chunk-P7STFMPO.mjs.map +0 -1
  496. package/dist/chunk-PL5WNHFZ.mjs +0 -50
  497. package/dist/chunk-PL5WNHFZ.mjs.map +0 -1
  498. package/dist/chunk-UYARLQNA.mjs +0 -1
  499. package/dist/chunk-UYARLQNA.mjs.map +0 -1
  500. package/dist/chunk-XEMZTHQZ.mjs +0 -67
  501. package/dist/chunk-XEMZTHQZ.mjs.map +0 -1
  502. package/dist/chunk-XTHC46M2.mjs +0 -1
  503. package/dist/chunk-XTHC46M2.mjs.map +0 -1
  504. package/dist/constants/index.d.ts +0 -6
  505. package/dist/constants/index.js +0 -40
  506. package/dist/constants/index.js.map +0 -1
  507. package/dist/index.d.ts +0 -25
  508. package/dist/index.js +0 -1098
  509. package/dist/index.js.map +0 -1
  510. package/dist/telemetry/events.d.ts +0 -45
  511. package/dist/telemetry/events.js +0 -19
  512. package/dist/telemetry/events.js.map +0 -1
  513. package/dist/telemetry/events.mjs +0 -1
  514. package/dist/telemetry/events.mjs.map +0 -1
  515. package/dist/telemetry/index.d.ts +0 -3
  516. package/dist/telemetry/index.js +0 -188
  517. package/dist/telemetry/index.js.map +0 -1
  518. package/dist/telemetry/index.mjs.map +0 -1
  519. package/dist/telemetry/scarf-client.d.ts +0 -7
  520. package/dist/telemetry/scarf-client.js +0 -59
  521. package/dist/telemetry/scarf-client.js.map +0 -1
  522. package/dist/telemetry/scarf-client.mjs +0 -7
  523. package/dist/telemetry/scarf-client.mjs.map +0 -1
  524. package/dist/telemetry/security-check.d.ts +0 -2
  525. package/dist/telemetry/security-check.js +0 -2
  526. package/dist/telemetry/security-check.js.map +0 -1
  527. package/dist/telemetry/security-check.mjs +0 -1
  528. package/dist/telemetry/security-check.mjs.map +0 -1
  529. package/dist/telemetry/telemetry-client.d.ts +0 -40
  530. package/dist/telemetry/telemetry-client.js +0 -186
  531. package/dist/telemetry/telemetry-client.js.map +0 -1
  532. package/dist/telemetry/utils.d.ts +0 -8
  533. package/dist/telemetry/utils.js +0 -69
  534. package/dist/telemetry/utils.js.map +0 -1
  535. package/dist/types/action.js +0 -19
  536. package/dist/types/action.js.map +0 -1
  537. package/dist/types/action.mjs +0 -2
  538. package/dist/types/action.mjs.map +0 -1
  539. package/dist/types/copilot-cloud-config.d.ts +0 -13
  540. package/dist/types/copilot-cloud-config.js +0 -19
  541. package/dist/types/copilot-cloud-config.js.map +0 -1
  542. package/dist/types/copilot-cloud-config.mjs +0 -2
  543. package/dist/types/copilot-cloud-config.mjs.map +0 -1
  544. package/dist/types/error.d.ts +0 -55
  545. package/dist/types/error.js +0 -19
  546. package/dist/types/error.js.map +0 -1
  547. package/dist/types/error.mjs +0 -2
  548. package/dist/types/error.mjs.map +0 -1
  549. package/dist/types/index.d.ts +0 -7
  550. package/dist/types/index.js +0 -19
  551. package/dist/types/index.js.map +0 -1
  552. package/dist/types/index.mjs +0 -8
  553. package/dist/types/index.mjs.map +0 -1
  554. package/dist/types/message.d.ts +0 -26
  555. package/dist/types/message.js +0 -19
  556. package/dist/types/message.js.map +0 -1
  557. package/dist/types/message.mjs +0 -2
  558. package/dist/types/message.mjs.map +0 -1
  559. package/dist/types/openai-assistant.d.ts +0 -53
  560. package/dist/types/openai-assistant.js +0 -19
  561. package/dist/types/openai-assistant.js.map +0 -1
  562. package/dist/types/openai-assistant.mjs +0 -2
  563. package/dist/types/openai-assistant.mjs.map +0 -1
  564. package/dist/types/utility.d.ts +0 -6
  565. package/dist/types/utility.js +0 -19
  566. package/dist/types/utility.js.map +0 -1
  567. package/dist/types/utility.mjs +0 -2
  568. package/dist/types/utility.mjs.map +0 -1
  569. package/dist/utils/conditions.js +0 -74
  570. package/dist/utils/conditions.js.map +0 -1
  571. package/dist/utils/console-styling.d.ts +0 -84
  572. package/dist/utils/console-styling.js +0 -123
  573. package/dist/utils/console-styling.js.map +0 -1
  574. package/dist/utils/errors.js +0 -443
  575. package/dist/utils/errors.js.map +0 -1
  576. package/dist/utils/index.d.ts +0 -32
  577. package/dist/utils/index.js +0 -927
  578. package/dist/utils/index.js.map +0 -1
  579. package/dist/utils/json-schema.js +0 -228
  580. package/dist/utils/json-schema.js.map +0 -1
  581. package/dist/utils/random-id.js +0 -68
  582. package/dist/utils/random-id.js.map +0 -1
  583. package/dist/utils/requests.js +0 -91
  584. package/dist/utils/requests.js.map +0 -1
  585. package/dist/utils/types.d.ts +0 -20
  586. package/dist/utils/types.js +0 -19
  587. package/dist/utils/types.js.map +0 -1
  588. package/jest.config.js +0 -5
  589. package/src/telemetry/scarf-client.ts +0 -39
  590. package/src/telemetry/security-check.ts +0 -0
  591. package/src/utils/json-schema.test.ts +0 -383
  592. package/tsup.config.ts +0 -11
@@ -0,0 +1,5 @@
1
+ import { isTelemetryDisabled } from "./telemetry-disabled.mjs";
2
+ import { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryEmitter, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.mjs";
3
+ import { LambdaSendOptions, firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense } from "./lambda-client.mjs";
4
+ import { TelemetryCapture, TelemetryClient, TelemetryIdentity } from "./telemetry-client.mjs";
5
+ export { type LambdaSendOptions, SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryCapture, TelemetryClient, TelemetryEmitter, TelemetryIdentity, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
@@ -1,12 +1,6 @@
1
- import "../chunk-P7STFMPO.mjs";
2
- import {
3
- TelemetryClient,
4
- isTelemetryDisabled
5
- } from "../chunk-A66772CV.mjs";
6
- import "../chunk-JAAUCDUR.mjs";
7
- import "../chunk-6QGXWNS5.mjs";
8
- export {
9
- TelemetryClient,
10
- isTelemetryDisabled
11
- };
12
- //# sourceMappingURL=index.mjs.map
1
+ import { isTelemetryDisabled } from "./telemetry-disabled.mjs";
2
+ import { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.mjs";
3
+ import { firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense } from "./lambda-client.mjs";
4
+ import { TelemetryClient } from "./telemetry-client.mjs";
5
+
6
+ export { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryClient, UNSAMPLED_RATE, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
@@ -0,0 +1,91 @@
1
+
2
+ //#region src/telemetry/lambda-client.ts
3
+ const TELEMETRY_SINK_URL = typeof process !== "undefined" && process.env?.COPILOTKIT_TELEMETRY_URL || "https://telemetry.copilotkit.ai/ingest";
4
+ const FETCH_TIMEOUT_MS = 3e3;
5
+ const TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
6
+ /**
7
+ * Return the first telemetry identity accepted by the ingest service.
8
+ *
9
+ * Empty and whitespace-only values are unconfigured placeholders and must not
10
+ * suppress a later identity source. Leading and trailing HTTP spaces and tabs
11
+ * are removed before validation. The ingest service accepts 1 to 128 ASCII
12
+ * letters, digits, underscores, and hyphens.
13
+ *
14
+ * @internal
15
+ */
16
+ function firstNonBlankTelemetryId(...candidates) {
17
+ for (const candidate of candidates) {
18
+ if (candidate === void 0) continue;
19
+ const normalized = candidate.replace(/^[\t ]+|[\t ]+$/g, "");
20
+ if (TELEMETRY_ID_PATTERN.test(normalized)) return normalized;
21
+ }
22
+ }
23
+ const STRIPPED_KEYS = new Set(["cloud.public_api_key", "cloud.publicApiKey"]);
24
+ function stripCloudKeys(obj) {
25
+ if (!obj) return {};
26
+ const out = {};
27
+ for (const [k, v] of Object.entries(obj)) if (!STRIPPED_KEYS.has(k)) out[k] = v;
28
+ return out;
29
+ }
30
+ function parseTelemetryIdFromLicense(token) {
31
+ if (!token) return null;
32
+ const parts = token.split(".");
33
+ if (parts.length !== 3) return null;
34
+ try {
35
+ const payload = parts[1];
36
+ if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
37
+ let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
38
+ const padding = (4 - b64.length % 4) % 4;
39
+ b64 += "=".repeat(padding);
40
+ const json = typeof Buffer !== "undefined" ? Buffer.from(b64, "base64").toString("utf8") : new TextDecoder().decode(Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)));
41
+ const decoded = JSON.parse(json);
42
+ return firstNonBlankTelemetryId(typeof decoded.telemetry_id === "string" ? decoded.telemetry_id : void 0) ?? null;
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+ function parseAndWarnTelemetryId(licenseToken) {
48
+ const telemetryId = parseTelemetryIdFromLicense(licenseToken);
49
+ if (!telemetryId) console.warn("[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.");
50
+ return telemetryId;
51
+ }
52
+ async function send(opts) {
53
+ try {
54
+ const body = JSON.stringify({
55
+ event: opts.event,
56
+ properties: stripCloudKeys(opts.properties),
57
+ global_properties: stripCloudKeys(opts.globalProperties),
58
+ package: {
59
+ name: opts.packageName,
60
+ version: opts.packageVersion
61
+ },
62
+ ts: Math.floor(Date.now() / 1e3)
63
+ });
64
+ const telemetryId = firstNonBlankTelemetryId(opts.telemetryId) ?? parseTelemetryIdFromLicense(opts.licenseToken);
65
+ const headers = {
66
+ "Content-Type": "application/json",
67
+ "User-Agent": opts.packageName ? `CopilotKit-Runtime/${opts.packageVersion ?? "unknown"} (${opts.packageName})` : "CopilotKit-Runtime"
68
+ };
69
+ if (telemetryId) headers["X-CopilotKit-Telemetry-Id"] = telemetryId;
70
+ const controller = new AbortController();
71
+ const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
72
+ try {
73
+ await fetch(TELEMETRY_SINK_URL, {
74
+ method: "POST",
75
+ headers,
76
+ body,
77
+ signal: controller.signal
78
+ });
79
+ } finally {
80
+ clearTimeout(timeoutId);
81
+ }
82
+ } catch {}
83
+ }
84
+ const lambdaClient = { send };
85
+
86
+ //#endregion
87
+ exports.firstNonBlankTelemetryId = firstNonBlankTelemetryId;
88
+ exports.lambdaClient = lambdaClient;
89
+ exports.parseAndWarnTelemetryId = parseAndWarnTelemetryId;
90
+ exports.parseTelemetryIdFromLicense = parseTelemetryIdFromLicense;
91
+ //# sourceMappingURL=lambda-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-client.cjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) {\n return null;\n }\n\n let b64 = payload.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padding = (4 - (b64.length % 4)) % 4;\n b64 += \"=\".repeat(padding);\n const json =\n typeof Buffer !== \"undefined\"\n ? Buffer.from(b64, \"base64\").toString(\"utf8\")\n : new TextDecoder().decode(\n Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)),\n );\n const decoded = JSON.parse(json) as { telemetry_id?: unknown };\n const telemetryId =\n typeof decoded.telemetry_id === \"string\"\n ? decoded.telemetry_id\n : undefined;\n return firstNonBlankTelemetryId(telemetryId) ?? null;\n } catch {\n return null;\n }\n}\n\n// Parse the telemetry_id from a license token AND emit the rollout smoke\n// signal if the parse returned null. Returning the parsed id lets callers\n// cache it in one step (avoiding a second parseTelemetryIdFromLicense\n// pass) while keeping the warn text in lockstep between v1 (shared) and\n// v2 (runtime) TelemetryClient.setLicenseToken.\nexport function parseAndWarnTelemetryId(licenseToken: string): string | null {\n const telemetryId = parseTelemetryIdFromLicense(licenseToken);\n if (!telemetryId) {\n console.warn(\n \"[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.\",\n );\n }\n return telemetryId;\n}\n\nexport async function send(opts: LambdaSendOptions): Promise<void> {\n try {\n const body = JSON.stringify({\n event: opts.event,\n properties: stripCloudKeys(opts.properties),\n global_properties: stripCloudKeys(opts.globalProperties),\n package: {\n name: opts.packageName,\n version: opts.packageVersion,\n },\n ts: Math.floor(Date.now() / 1000),\n });\n\n const telemetryId =\n firstNonBlankTelemetryId(opts.telemetryId) ??\n parseTelemetryIdFromLicense(opts.licenseToken);\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"User-Agent\": opts.packageName\n ? `CopilotKit-Runtime/${opts.packageVersion ?? \"unknown\"} (${opts.packageName})`\n : \"CopilotKit-Runtime\",\n };\n if (telemetryId) {\n headers[\"X-CopilotKit-Telemetry-Id\"] = telemetryId;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n await fetch(TELEMETRY_SINK_URL, {\n method: \"POST\",\n headers,\n body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n } catch {\n // Silent failure — telemetry must not break the application.\n }\n}\n\nexport const lambdaClient = { send };\n"],"mappings":";;AA2BA,MAAM,qBACH,OAAO,YAAY,eAAe,QAAQ,KAAK,4BAChD;AAEF,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;;;;;;;;;;;AA2B7B,SAAgB,yBACd,GAAG,YACiB;AACpB,MAAK,MAAM,aAAa,YAAY;AAClC,MAAI,cAAc,OAChB;EAGF,MAAM,aAAa,UAAU,QAAQ,oBAAoB,GAAG;AAC5D,MAAI,qBAAqB,KAAK,WAAW,CACvC,QAAO;;;AAWb,MAAM,gBAAgB,IAAI,IAAI,CAAC,wBAAwB,qBAAqB,CAAC;AAE7E,SAAS,eACP,KACyB;AACzB,KAAI,CAAC,IAAK,QAAO,EAAE;CACnB,MAAM,MAA+B,EAAE;AACvC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,IAAI,CACtC,KAAI,CAAC,cAAc,IAAI,EAAE,CAAE,KAAI,KAAK;AAEtC,QAAO;;AAeT,SAAgB,4BAA4B,OAA+B;AACzE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,KAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,KAAI;EACF,MAAM,UAAU,MAAM;AACtB,MAAI,CAAC,mBAAmB,KAAK,QAAQ,IAAI,QAAQ,SAAS,MAAM,EAC9D,QAAO;EAGT,IAAI,MAAM,QAAQ,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI;EACvD,MAAM,WAAW,IAAK,IAAI,SAAS,KAAM;AACzC,SAAO,IAAI,OAAO,QAAQ;EAC1B,MAAM,OACJ,OAAO,WAAW,cACd,OAAO,KAAK,KAAK,SAAS,CAAC,SAAS,OAAO,GAC3C,IAAI,aAAa,CAAC,OAChB,WAAW,KAAK,KAAK,IAAI,GAAG,cAAc,UAAU,WAAW,EAAE,CAAC,CACnE;EACP,MAAM,UAAU,KAAK,MAAM,KAAK;AAKhC,SAAO,yBAHL,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,OACsC,IAAI;SAC1C;AACN,SAAO;;;AASX,SAAgB,wBAAwB,cAAqC;CAC3E,MAAM,cAAc,4BAA4B,aAAa;AAC7D,KAAI,CAAC,YACH,SAAQ,KACN,sGACD;AAEH,QAAO;;AAGT,eAAsB,KAAK,MAAwC;AACjE,KAAI;EACF,MAAM,OAAO,KAAK,UAAU;GAC1B,OAAO,KAAK;GACZ,YAAY,eAAe,KAAK,WAAW;GAC3C,mBAAmB,eAAe,KAAK,iBAAiB;GACxD,SAAS;IACP,MAAM,KAAK;IACX,SAAS,KAAK;IACf;GACD,IAAI,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;GAClC,CAAC;EAEF,MAAM,cACJ,yBAAyB,KAAK,YAAY,IAC1C,4BAA4B,KAAK,aAAa;EAChD,MAAM,UAAkC;GACtC,gBAAgB;GAChB,cAAc,KAAK,cACf,sBAAsB,KAAK,kBAAkB,UAAU,IAAI,KAAK,YAAY,KAC5E;GACL;AACD,MAAI,YACF,SAAQ,+BAA+B;EAGzC,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,YAAY,iBAAiB,WAAW,OAAO,EAAE,iBAAiB;AACxE,MAAI;AACF,SAAM,MAAM,oBAAoB;IAC9B,QAAQ;IACR;IACA;IACA,QAAQ,WAAW;IACpB,CAAC;YACM;AACR,gBAAa,UAAU;;SAEnB;;AAKV,MAAa,eAAe,EAAE,MAAM"}
@@ -0,0 +1,31 @@
1
+ //#region src/telemetry/lambda-client.d.ts
2
+ interface LambdaSendOptions {
3
+ event: string;
4
+ properties?: Record<string, unknown>;
5
+ globalProperties?: Record<string, unknown>;
6
+ packageName?: string;
7
+ packageVersion?: string;
8
+ /** Standalone analytics identity, resolved before any legacy license claim. */
9
+ telemetryId?: string;
10
+ licenseToken?: string;
11
+ }
12
+ /**
13
+ * Return the first telemetry identity accepted by the ingest service.
14
+ *
15
+ * Empty and whitespace-only values are unconfigured placeholders and must not
16
+ * suppress a later identity source. Leading and trailing HTTP spaces and tabs
17
+ * are removed before validation. The ingest service accepts 1 to 128 ASCII
18
+ * letters, digits, underscores, and hyphens.
19
+ *
20
+ * @internal
21
+ */
22
+ declare function firstNonBlankTelemetryId(...candidates: ReadonlyArray<string | undefined>): string | undefined;
23
+ declare function parseTelemetryIdFromLicense(token?: string): string | null;
24
+ declare function parseAndWarnTelemetryId(licenseToken: string): string | null;
25
+ declare function send(opts: LambdaSendOptions): Promise<void>;
26
+ declare const lambdaClient: {
27
+ send: typeof send;
28
+ };
29
+ //#endregion
30
+ export { LambdaSendOptions, firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
31
+ //# sourceMappingURL=lambda-client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-client.d.cts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,iBAmC5B,uBAAA,CAAwB,YAAA;AAAA,iBAUlB,IAAA,CAAK,IAAA,EAAM,iBAAA,GAAoB,OAAA;AAAA,cA2CxC,YAAA;eAAuB,IAAA;AAAA"}
@@ -0,0 +1,31 @@
1
+ //#region src/telemetry/lambda-client.d.ts
2
+ interface LambdaSendOptions {
3
+ event: string;
4
+ properties?: Record<string, unknown>;
5
+ globalProperties?: Record<string, unknown>;
6
+ packageName?: string;
7
+ packageVersion?: string;
8
+ /** Standalone analytics identity, resolved before any legacy license claim. */
9
+ telemetryId?: string;
10
+ licenseToken?: string;
11
+ }
12
+ /**
13
+ * Return the first telemetry identity accepted by the ingest service.
14
+ *
15
+ * Empty and whitespace-only values are unconfigured placeholders and must not
16
+ * suppress a later identity source. Leading and trailing HTTP spaces and tabs
17
+ * are removed before validation. The ingest service accepts 1 to 128 ASCII
18
+ * letters, digits, underscores, and hyphens.
19
+ *
20
+ * @internal
21
+ */
22
+ declare function firstNonBlankTelemetryId(...candidates: ReadonlyArray<string | undefined>): string | undefined;
23
+ declare function parseTelemetryIdFromLicense(token?: string): string | null;
24
+ declare function parseAndWarnTelemetryId(licenseToken: string): string | null;
25
+ declare function send(opts: LambdaSendOptions): Promise<void>;
26
+ declare const lambdaClient: {
27
+ send: typeof send;
28
+ };
29
+ //#endregion
30
+ export { LambdaSendOptions, firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
31
+ //# sourceMappingURL=lambda-client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-client.d.mts","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"mappings":";UAkCiB,iBAAA;EACf,KAAA;EACA,UAAA,GAAa,MAAA;EACb,gBAAA,GAAmB,MAAA;EACnB,WAAA;EACA,cAAA;EAHA;EAKA,WAAA;EAKA,YAAA;AAAA;;;;;;;AAaF;;;;iBAAgB,wBAAA,CAAA,GACX,UAAA,EAAY,aAAA;AAAA,iBA6CD,2BAAA,CAA4B,KAAA;AAAA,iBAmC5B,uBAAA,CAAwB,YAAA;AAAA,iBAUlB,IAAA,CAAK,IAAA,EAAM,iBAAA,GAAoB,OAAA;AAAA,cA2CxC,YAAA;eAAuB,IAAA;AAAA"}
@@ -0,0 +1,87 @@
1
+ //#region src/telemetry/lambda-client.ts
2
+ const TELEMETRY_SINK_URL = typeof process !== "undefined" && process.env?.COPILOTKIT_TELEMETRY_URL || "https://telemetry.copilotkit.ai/ingest";
3
+ const FETCH_TIMEOUT_MS = 3e3;
4
+ const TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
5
+ /**
6
+ * Return the first telemetry identity accepted by the ingest service.
7
+ *
8
+ * Empty and whitespace-only values are unconfigured placeholders and must not
9
+ * suppress a later identity source. Leading and trailing HTTP spaces and tabs
10
+ * are removed before validation. The ingest service accepts 1 to 128 ASCII
11
+ * letters, digits, underscores, and hyphens.
12
+ *
13
+ * @internal
14
+ */
15
+ function firstNonBlankTelemetryId(...candidates) {
16
+ for (const candidate of candidates) {
17
+ if (candidate === void 0) continue;
18
+ const normalized = candidate.replace(/^[\t ]+|[\t ]+$/g, "");
19
+ if (TELEMETRY_ID_PATTERN.test(normalized)) return normalized;
20
+ }
21
+ }
22
+ const STRIPPED_KEYS = new Set(["cloud.public_api_key", "cloud.publicApiKey"]);
23
+ function stripCloudKeys(obj) {
24
+ if (!obj) return {};
25
+ const out = {};
26
+ for (const [k, v] of Object.entries(obj)) if (!STRIPPED_KEYS.has(k)) out[k] = v;
27
+ return out;
28
+ }
29
+ function parseTelemetryIdFromLicense(token) {
30
+ if (!token) return null;
31
+ const parts = token.split(".");
32
+ if (parts.length !== 3) return null;
33
+ try {
34
+ const payload = parts[1];
35
+ if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
36
+ let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
37
+ const padding = (4 - b64.length % 4) % 4;
38
+ b64 += "=".repeat(padding);
39
+ const json = typeof Buffer !== "undefined" ? Buffer.from(b64, "base64").toString("utf8") : new TextDecoder().decode(Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)));
40
+ const decoded = JSON.parse(json);
41
+ return firstNonBlankTelemetryId(typeof decoded.telemetry_id === "string" ? decoded.telemetry_id : void 0) ?? null;
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+ function parseAndWarnTelemetryId(licenseToken) {
47
+ const telemetryId = parseTelemetryIdFromLicense(licenseToken);
48
+ if (!telemetryId) console.warn("[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.");
49
+ return telemetryId;
50
+ }
51
+ async function send(opts) {
52
+ try {
53
+ const body = JSON.stringify({
54
+ event: opts.event,
55
+ properties: stripCloudKeys(opts.properties),
56
+ global_properties: stripCloudKeys(opts.globalProperties),
57
+ package: {
58
+ name: opts.packageName,
59
+ version: opts.packageVersion
60
+ },
61
+ ts: Math.floor(Date.now() / 1e3)
62
+ });
63
+ const telemetryId = firstNonBlankTelemetryId(opts.telemetryId) ?? parseTelemetryIdFromLicense(opts.licenseToken);
64
+ const headers = {
65
+ "Content-Type": "application/json",
66
+ "User-Agent": opts.packageName ? `CopilotKit-Runtime/${opts.packageVersion ?? "unknown"} (${opts.packageName})` : "CopilotKit-Runtime"
67
+ };
68
+ if (telemetryId) headers["X-CopilotKit-Telemetry-Id"] = telemetryId;
69
+ const controller = new AbortController();
70
+ const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
71
+ try {
72
+ await fetch(TELEMETRY_SINK_URL, {
73
+ method: "POST",
74
+ headers,
75
+ body,
76
+ signal: controller.signal
77
+ });
78
+ } finally {
79
+ clearTimeout(timeoutId);
80
+ }
81
+ } catch {}
82
+ }
83
+ const lambdaClient = { send };
84
+
85
+ //#endregion
86
+ export { firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
87
+ //# sourceMappingURL=lambda-client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-client.mjs","names":[],"sources":["../../src/telemetry/lambda-client.ts"],"sourcesContent":["// Telemetry sink client.\n//\n// Posts events to a CopilotKit-controlled telemetry-sink endpoint, which\n// fans out to Scarf, Reo, and any future destinations. Replaces the direct\n// per-vendor calls (formerly a Scarf-specific client) so that vendor changes\n// don't require SDK releases and so that downstream services we don't want\n// exposed to OSS readers (e.g. the email-enrichment service backing Reo) stay\n// private.\n//\n// Two attribution modes:\n// - Identified: a standalone telemetry id or a CopilotKit license token is\n// configured. Standalone identity takes precedence. License tokens are\n// JWTs (header.payload.sig) whose payload carries `telemetry_id`; the SDK\n// base64url-decodes the payload — without verifying the Ed25519 signature,\n// which is the license-verifier's job. The resolved identity is emitted\n// only via `X-CopilotKit-Telemetry-Id`.\n// - Anonymous: no license token, or a malformed/non-JWT one. No\n// telemetry-id header; events still flow, attribution is best-effort\n// from request-level signals (IP, UA).\n//\n// Note: CopilotCloud customer API keys (`ck_<env>_<id>.<secret>`) are\n// unrelated to telemetry attribution. They flow into Segment / PostHog\n// via the v1 shared TelemetryClient and never reach this code path.\n//\n// Best-effort: every error is swallowed. Telemetry must not break the\n// host application.\n\nconst TELEMETRY_SINK_URL =\n (typeof process !== \"undefined\" && process.env?.COPILOTKIT_TELEMETRY_URL) ||\n \"https://telemetry.copilotkit.ai/ingest\";\n\nconst FETCH_TIMEOUT_MS = 3000;\nconst TELEMETRY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\nexport interface LambdaSendOptions {\n event: string;\n properties?: Record<string, unknown>;\n globalProperties?: Record<string, unknown>;\n packageName?: string;\n packageVersion?: string;\n /** Standalone analytics identity, resolved before any legacy license claim. */\n telemetryId?: string;\n // The CopilotKit license token (Ed25519-signed JWT), when one is\n // configured on the runtime. The sender base64url-decodes the payload\n // segment to extract `telemetry_id`; missing or malformed tokens\n // produce an anonymous send.\n licenseToken?: string;\n}\n\n/**\n * Return the first telemetry identity accepted by the ingest service.\n *\n * Empty and whitespace-only values are unconfigured placeholders and must not\n * suppress a later identity source. Leading and trailing HTTP spaces and tabs\n * are removed before validation. The ingest service accepts 1 to 128 ASCII\n * letters, digits, underscores, and hyphens.\n *\n * @internal\n */\nexport function firstNonBlankTelemetryId(\n ...candidates: ReadonlyArray<string | undefined>\n): string | undefined {\n for (const candidate of candidates) {\n if (candidate === undefined) {\n continue;\n }\n\n const normalized = candidate.replace(/^[\\t ]+|[\\t ]+$/g, \"\");\n if (TELEMETRY_ID_PATTERN.test(normalized)) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\n// These fields aren't used by the telemetry service, so we strip them\n// at the wire boundary rather than rely on every caller to omit them.\n// Both the snake_case and camelCase variants are listed because callers\n// upstream use different conventions.\nconst STRIPPED_KEYS = new Set([\"cloud.public_api_key\", \"cloud.publicApiKey\"]);\n\nfunction stripCloudKeys(\n obj: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n if (!obj) return {};\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!STRIPPED_KEYS.has(k)) out[k] = v;\n }\n return out;\n}\n\n// Pull telemetry_id out of a CopilotKit license token without verifying\n// the signature. The token shape is a standard JWT\n// (`<header>.<payload>.<sig>`) with base64url-encoded segments; the\n// payload is UTF-8 JSON with a telemetry_id accepted by the ingest service.\n//\n// Verification (Ed25519, key rotation, expiry) is the license-verifier\n// package's job. For telemetry attribution we only need the claimed id —\n// the trust model is claim-only on the Lambda side anyway.\n//\n// Exported so TelemetryClient setters can detect unparseable tokens at\n// configuration time and surface a single warning, instead of silently\n// emitting anonymous events on every capture.\nexport function parseTelemetryIdFromLicense(token?: string): string | null {\n if (!token) return null;\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n try {\n const payload = parts[1];\n if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) {\n return null;\n }\n\n let b64 = payload.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padding = (4 - (b64.length % 4)) % 4;\n b64 += \"=\".repeat(padding);\n const json =\n typeof Buffer !== \"undefined\"\n ? Buffer.from(b64, \"base64\").toString(\"utf8\")\n : new TextDecoder().decode(\n Uint8Array.from(atob(b64), (character) => character.charCodeAt(0)),\n );\n const decoded = JSON.parse(json) as { telemetry_id?: unknown };\n const telemetryId =\n typeof decoded.telemetry_id === \"string\"\n ? decoded.telemetry_id\n : undefined;\n return firstNonBlankTelemetryId(telemetryId) ?? null;\n } catch {\n return null;\n }\n}\n\n// Parse the telemetry_id from a license token AND emit the rollout smoke\n// signal if the parse returned null. Returning the parsed id lets callers\n// cache it in one step (avoiding a second parseTelemetryIdFromLicense\n// pass) while keeping the warn text in lockstep between v1 (shared) and\n// v2 (runtime) TelemetryClient.setLicenseToken.\nexport function parseAndWarnTelemetryId(licenseToken: string): string | null {\n const telemetryId = parseTelemetryIdFromLicense(licenseToken);\n if (!telemetryId) {\n console.warn(\n \"[CopilotKit] License token did not yield a telemetry_id; telemetry events will be sent anonymously.\",\n );\n }\n return telemetryId;\n}\n\nexport async function send(opts: LambdaSendOptions): Promise<void> {\n try {\n const body = JSON.stringify({\n event: opts.event,\n properties: stripCloudKeys(opts.properties),\n global_properties: stripCloudKeys(opts.globalProperties),\n package: {\n name: opts.packageName,\n version: opts.packageVersion,\n },\n ts: Math.floor(Date.now() / 1000),\n });\n\n const telemetryId =\n firstNonBlankTelemetryId(opts.telemetryId) ??\n parseTelemetryIdFromLicense(opts.licenseToken);\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"User-Agent\": opts.packageName\n ? `CopilotKit-Runtime/${opts.packageVersion ?? \"unknown\"} (${opts.packageName})`\n : \"CopilotKit-Runtime\",\n };\n if (telemetryId) {\n headers[\"X-CopilotKit-Telemetry-Id\"] = telemetryId;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n await fetch(TELEMETRY_SINK_URL, {\n method: \"POST\",\n headers,\n body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n } catch {\n // Silent failure — telemetry must not break the application.\n }\n}\n\nexport const lambdaClient = { send };\n"],"mappings":";AA2BA,MAAM,qBACH,OAAO,YAAY,eAAe,QAAQ,KAAK,4BAChD;AAEF,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;;;;;;;;;;;AA2B7B,SAAgB,yBACd,GAAG,YACiB;AACpB,MAAK,MAAM,aAAa,YAAY;AAClC,MAAI,cAAc,OAChB;EAGF,MAAM,aAAa,UAAU,QAAQ,oBAAoB,GAAG;AAC5D,MAAI,qBAAqB,KAAK,WAAW,CACvC,QAAO;;;AAWb,MAAM,gBAAgB,IAAI,IAAI,CAAC,wBAAwB,qBAAqB,CAAC;AAE7E,SAAS,eACP,KACyB;AACzB,KAAI,CAAC,IAAK,QAAO,EAAE;CACnB,MAAM,MAA+B,EAAE;AACvC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,IAAI,CACtC,KAAI,CAAC,cAAc,IAAI,EAAE,CAAE,KAAI,KAAK;AAEtC,QAAO;;AAeT,SAAgB,4BAA4B,OAA+B;AACzE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,KAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,KAAI;EACF,MAAM,UAAU,MAAM;AACtB,MAAI,CAAC,mBAAmB,KAAK,QAAQ,IAAI,QAAQ,SAAS,MAAM,EAC9D,QAAO;EAGT,IAAI,MAAM,QAAQ,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI;EACvD,MAAM,WAAW,IAAK,IAAI,SAAS,KAAM;AACzC,SAAO,IAAI,OAAO,QAAQ;EAC1B,MAAM,OACJ,OAAO,WAAW,cACd,OAAO,KAAK,KAAK,SAAS,CAAC,SAAS,OAAO,GAC3C,IAAI,aAAa,CAAC,OAChB,WAAW,KAAK,KAAK,IAAI,GAAG,cAAc,UAAU,WAAW,EAAE,CAAC,CACnE;EACP,MAAM,UAAU,KAAK,MAAM,KAAK;AAKhC,SAAO,yBAHL,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,OACsC,IAAI;SAC1C;AACN,SAAO;;;AASX,SAAgB,wBAAwB,cAAqC;CAC3E,MAAM,cAAc,4BAA4B,aAAa;AAC7D,KAAI,CAAC,YACH,SAAQ,KACN,sGACD;AAEH,QAAO;;AAGT,eAAsB,KAAK,MAAwC;AACjE,KAAI;EACF,MAAM,OAAO,KAAK,UAAU;GAC1B,OAAO,KAAK;GACZ,YAAY,eAAe,KAAK,WAAW;GAC3C,mBAAmB,eAAe,KAAK,iBAAiB;GACxD,SAAS;IACP,MAAM,KAAK;IACX,SAAS,KAAK;IACf;GACD,IAAI,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;GAClC,CAAC;EAEF,MAAM,cACJ,yBAAyB,KAAK,YAAY,IAC1C,4BAA4B,KAAK,aAAa;EAChD,MAAM,UAAkC;GACtC,gBAAgB;GAChB,cAAc,KAAK,cACf,sBAAsB,KAAK,kBAAkB,UAAU,IAAI,KAAK,YAAY,KAC5E;GACL;AACD,MAAI,YACF,SAAQ,+BAA+B;EAGzC,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,YAAY,iBAAiB,WAAW,OAAO,EAAE,iBAAiB;AACxE,MAAI;AACF,SAAM,MAAM,oBAAoB;IAC9B,QAAQ;IACR;IACA;IACA,QAAQ,WAAW;IACpB,CAAC;YACM;AACR,gBAAa,UAAU;;SAEnB;;AAKV,MAAa,eAAe,EAAE,MAAM"}
@@ -0,0 +1,104 @@
1
+
2
+ //#region src/telemetry/model-host.ts
3
+ /**
4
+ * Every value `classifyModelHost` can return.
5
+ *
6
+ * `other` means a host we observed and did not recognize: a gateway, a proxy,
7
+ * or a vendor we have no rule for. `unknown` means we never saw a host at all,
8
+ * which is the case when a caller hands us an already-built LanguageModel.
9
+ * The two are not interchangeable — one is an unrecognized answer, the other
10
+ * is a missing one, and they need different follow-up.
11
+ */
12
+ const MODEL_HOST_CLASSES = [
13
+ "openai",
14
+ "azure",
15
+ "openrouter",
16
+ "anthropic",
17
+ "google",
18
+ "vertex",
19
+ "bedrock",
20
+ "groq",
21
+ "unify",
22
+ "minimax",
23
+ "local",
24
+ "other",
25
+ "unknown"
26
+ ];
27
+ /**
28
+ * Host suffixes mapped to their vendor.
29
+ *
30
+ * Matched on label boundaries, never as substrings, so
31
+ * `myresource.openai.azure.com.attacker.test` does not read as Azure.
32
+ */
33
+ const HOST_SUFFIXES = [
34
+ ["openai.azure.com", "azure"],
35
+ ["services.ai.azure.com", "azure"],
36
+ ["cognitiveservices.azure.com", "azure"],
37
+ ["azure-api.net", "azure"],
38
+ ["api.openai.com", "openai"],
39
+ ["openrouter.ai", "openrouter"],
40
+ ["api.anthropic.com", "anthropic"],
41
+ ["generativelanguage.googleapis.com", "google"],
42
+ ["aiplatform.googleapis.com", "vertex"],
43
+ ["api.groq.com", "groq"],
44
+ ["api.unify.ai", "unify"],
45
+ ["api.minimax.io", "minimax"],
46
+ ["api.minimaxi.com", "minimax"]
47
+ ];
48
+ /** Suffixes that mean the model runs on the same machine or private network. */
49
+ const LOCAL_SUFFIXES = [
50
+ "localhost",
51
+ "local",
52
+ "internal",
53
+ "docker.internal"
54
+ ];
55
+ /** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */
56
+ const REGIONAL_HOST_PATTERNS = [[/^[a-z0-9-]+-aiplatform\.googleapis\.com$/, "vertex"], [/^bedrock[a-z0-9.-]*\.[a-z0-9-]+\.amazonaws\.com$/, "bedrock"]];
57
+ /** True when `host` equals `suffix` or sits directly beneath it. */
58
+ function matchesSuffix(host, suffix) {
59
+ return host === suffix || host.endsWith(`.${suffix}`);
60
+ }
61
+ /** True for loopback, unspecified, and RFC 1918 private addresses. */
62
+ function isPrivateAddress(host) {
63
+ if (host === "127.0.0.1" || host === "0.0.0.0" || host === "::1") return true;
64
+ if (host.startsWith("127.")) return true;
65
+ if (host.startsWith("10.") || host.startsWith("192.168.")) return true;
66
+ const privateClassB = /^172\.(\d{1,3})\./.exec(host);
67
+ if (privateClassB) {
68
+ const secondOctet = Number(privateClassB[1]);
69
+ return secondOctet >= 16 && secondOctet <= 31;
70
+ }
71
+ return false;
72
+ }
73
+ /**
74
+ * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
75
+ *
76
+ * @param baseUrl The endpoint the provider was configured with. Absent when
77
+ * the provider was left on its own default, which is why `providerDefault`
78
+ * exists: "no base URL, provider is openai" means api.openai.com.
79
+ * @param providerDefault What to report when no base URL was supplied. Callers
80
+ * that genuinely cannot observe a host — a pre-built LanguageModel handed in
81
+ * by the developer — leave this alone and get `unknown`.
82
+ */
83
+ function classifyModelHost(baseUrl, providerDefault = "unknown") {
84
+ const trimmed = baseUrl?.trim();
85
+ if (!trimmed) return providerDefault;
86
+ let host;
87
+ try {
88
+ host = new URL(trimmed).hostname.toLowerCase();
89
+ } catch {
90
+ return "other";
91
+ }
92
+ host = host.replace(/^\[|\]$/g, "");
93
+ if (!host) return "other";
94
+ if (isPrivateAddress(host)) return "local";
95
+ for (const suffix of LOCAL_SUFFIXES) if (matchesSuffix(host, suffix)) return "local";
96
+ for (const [suffix, hostClass] of HOST_SUFFIXES) if (matchesSuffix(host, suffix)) return hostClass;
97
+ for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) if (pattern.test(host)) return hostClass;
98
+ return "other";
99
+ }
100
+
101
+ //#endregion
102
+ exports.MODEL_HOST_CLASSES = MODEL_HOST_CLASSES;
103
+ exports.classifyModelHost = classifyModelHost;
104
+ //# sourceMappingURL=model-host.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-host.cjs","names":[],"sources":["../../src/telemetry/model-host.ts"],"sourcesContent":["// Which endpoint the runtime sends completions to, as a closed vocabulary.\n//\n// The AI SDK's provider label cannot answer this. A model built by\n// `createOpenAI` reports only its wire API: `openai.responses` for both\n// api.openai.com and Azure (whose own migration guide tells customers to use\n// exactly that client), and `openai.chat` for OpenRouter and a laptop running\n// Ollama alike. So the provider field reports the wire protocol, and the host\n// reports the vendor.\n//\n// Only the classification travels. A base URL like\n// `myresource.openai.azure.com` carries the customer's Azure resource name,\n// which identifies them, so the raw host must never reach telemetry. That is\n// why this returns a member of a fixed list rather than anything derived from\n// the input.\n\n/**\n * Every value `classifyModelHost` can return.\n *\n * `other` means a host we observed and did not recognize: a gateway, a proxy,\n * or a vendor we have no rule for. `unknown` means we never saw a host at all,\n * which is the case when a caller hands us an already-built LanguageModel.\n * The two are not interchangeable — one is an unrecognized answer, the other\n * is a missing one, and they need different follow-up.\n */\nexport const MODEL_HOST_CLASSES = [\n \"openai\",\n \"azure\",\n \"openrouter\",\n \"anthropic\",\n \"google\",\n \"vertex\",\n \"bedrock\",\n \"groq\",\n \"unify\",\n \"minimax\",\n \"local\",\n \"other\",\n \"unknown\",\n] as const;\n\nexport type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];\n\n/**\n * Host suffixes mapped to their vendor.\n *\n * Matched on label boundaries, never as substrings, so\n * `myresource.openai.azure.com.attacker.test` does not read as Azure.\n */\nconst HOST_SUFFIXES: ReadonlyArray<readonly [string, ModelHostClass]> = [\n // Azure exposes the same models under three host families: the classic\n // Azure OpenAI host, the Foundry Models host, and the general Cognitive\n // Services host. All three are Azure for our purposes.\n [\"openai.azure.com\", \"azure\"],\n [\"services.ai.azure.com\", \"azure\"],\n [\"cognitiveservices.azure.com\", \"azure\"],\n // API Management fronting an Azure OpenAI deployment, a common enterprise\n // pattern. Reported as azure because that is what sits behind it.\n [\"azure-api.net\", \"azure\"],\n\n [\"api.openai.com\", \"openai\"],\n [\"openrouter.ai\", \"openrouter\"],\n [\"api.anthropic.com\", \"anthropic\"],\n [\"generativelanguage.googleapis.com\", \"google\"],\n // Vertex regional hosts are `<region>-aiplatform.googleapis.com`, which is\n // not a suffix of a single label, so both spellings are listed.\n [\"aiplatform.googleapis.com\", \"vertex\"],\n [\"api.groq.com\", \"groq\"],\n [\"api.unify.ai\", \"unify\"],\n [\"api.minimax.io\", \"minimax\"],\n [\"api.minimaxi.com\", \"minimax\"],\n];\n\n/** Suffixes that mean the model runs on the same machine or private network. */\nconst LOCAL_SUFFIXES = [\"localhost\", \"local\", \"internal\", \"docker.internal\"];\n\n/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */\nconst REGIONAL_HOST_PATTERNS: ReadonlyArray<readonly [RegExp, ModelHostClass]> =\n [\n [/^[a-z0-9-]+-aiplatform\\.googleapis\\.com$/, \"vertex\"],\n [/^bedrock[a-z0-9.-]*\\.[a-z0-9-]+\\.amazonaws\\.com$/, \"bedrock\"],\n ];\n\n/** True when `host` equals `suffix` or sits directly beneath it. */\nfunction matchesSuffix(host: string, suffix: string): boolean {\n return host === suffix || host.endsWith(`.${suffix}`);\n}\n\n/** True for loopback, unspecified, and RFC 1918 private addresses. */\nfunction isPrivateAddress(host: string): boolean {\n if (host === \"127.0.0.1\" || host === \"0.0.0.0\" || host === \"::1\") {\n return true;\n }\n // 127.0.0.0/8 is entirely loopback.\n if (host.startsWith(\"127.\")) return true;\n // 10.0.0.0/8 and 192.168.0.0/16.\n if (host.startsWith(\"10.\") || host.startsWith(\"192.168.\")) return true;\n // 172.16.0.0/12 is 172.16 through 172.31 only. 172.32 is public, so the\n // second octet is range-checked rather than prefix-matched.\n const privateClassB = /^172\\.(\\d{1,3})\\./.exec(host);\n if (privateClassB) {\n const secondOctet = Number(privateClassB[1]);\n return secondOctet >= 16 && secondOctet <= 31;\n }\n return false;\n}\n\n/**\n * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.\n *\n * @param baseUrl The endpoint the provider was configured with. Absent when\n * the provider was left on its own default, which is why `providerDefault`\n * exists: \"no base URL, provider is openai\" means api.openai.com.\n * @param providerDefault What to report when no base URL was supplied. Callers\n * that genuinely cannot observe a host — a pre-built LanguageModel handed in\n * by the developer — leave this alone and get `unknown`.\n */\nexport function classifyModelHost(\n baseUrl?: string | null,\n providerDefault: ModelHostClass = \"unknown\",\n): ModelHostClass {\n const trimmed = baseUrl?.trim();\n if (!trimmed) {\n return providerDefault;\n }\n\n let host: string;\n try {\n // `hostname` drops the port, the path, the query and any credentials, so\n // nothing but the host can survive into the return value below.\n host = new URL(trimmed).hostname.toLowerCase();\n } catch {\n // We were given something and could not read it. That is a different fact\n // from having been given nothing, so it does not fall back to the default.\n return \"other\";\n }\n\n // IPv6 hostnames arrive bracketed from the URL parser.\n host = host.replace(/^\\[|\\]$/g, \"\");\n\n if (!host) return \"other\";\n\n if (isPrivateAddress(host)) return \"local\";\n for (const suffix of LOCAL_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return \"local\";\n }\n\n for (const [suffix, hostClass] of HOST_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return hostClass;\n }\n\n for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) {\n if (pattern.test(host)) return hostClass;\n }\n\n return \"other\";\n}\n"],"mappings":";;;;;;;;;;;AAwBA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAUD,MAAM,gBAAkE;CAItE,CAAC,oBAAoB,QAAQ;CAC7B,CAAC,yBAAyB,QAAQ;CAClC,CAAC,+BAA+B,QAAQ;CAGxC,CAAC,iBAAiB,QAAQ;CAE1B,CAAC,kBAAkB,SAAS;CAC5B,CAAC,iBAAiB,aAAa;CAC/B,CAAC,qBAAqB,YAAY;CAClC,CAAC,qCAAqC,SAAS;CAG/C,CAAC,6BAA6B,SAAS;CACvC,CAAC,gBAAgB,OAAO;CACxB,CAAC,gBAAgB,QAAQ;CACzB,CAAC,kBAAkB,UAAU;CAC7B,CAAC,oBAAoB,UAAU;CAChC;;AAGD,MAAM,iBAAiB;CAAC;CAAa;CAAS;CAAY;CAAkB;;AAG5E,MAAM,yBACJ,CACE,CAAC,4CAA4C,SAAS,EACtD,CAAC,oDAAoD,UAAU,CAChE;;AAGH,SAAS,cAAc,MAAc,QAAyB;AAC5D,QAAO,SAAS,UAAU,KAAK,SAAS,IAAI,SAAS;;;AAIvD,SAAS,iBAAiB,MAAuB;AAC/C,KAAI,SAAS,eAAe,SAAS,aAAa,SAAS,MACzD,QAAO;AAGT,KAAI,KAAK,WAAW,OAAO,CAAE,QAAO;AAEpC,KAAI,KAAK,WAAW,MAAM,IAAI,KAAK,WAAW,WAAW,CAAE,QAAO;CAGlE,MAAM,gBAAgB,oBAAoB,KAAK,KAAK;AACpD,KAAI,eAAe;EACjB,MAAM,cAAc,OAAO,cAAc,GAAG;AAC5C,SAAO,eAAe,MAAM,eAAe;;AAE7C,QAAO;;;;;;;;;;;;AAaT,SAAgB,kBACd,SACA,kBAAkC,WAClB;CAChB,MAAM,UAAU,SAAS,MAAM;AAC/B,KAAI,CAAC,QACH,QAAO;CAGT,IAAI;AACJ,KAAI;AAGF,SAAO,IAAI,IAAI,QAAQ,CAAC,SAAS,aAAa;SACxC;AAGN,SAAO;;AAIT,QAAO,KAAK,QAAQ,YAAY,GAAG;AAEnC,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI,iBAAiB,KAAK,CAAE,QAAO;AACnC,MAAK,MAAM,UAAU,eACnB,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,QAAQ,cAAc,cAChC,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,SAAS,cAAc,uBACjC,KAAI,QAAQ,KAAK,KAAK,CAAE,QAAO;AAGjC,QAAO"}
@@ -0,0 +1,26 @@
1
+ //#region src/telemetry/model-host.d.ts
2
+ /**
3
+ * Every value `classifyModelHost` can return.
4
+ *
5
+ * `other` means a host we observed and did not recognize: a gateway, a proxy,
6
+ * or a vendor we have no rule for. `unknown` means we never saw a host at all,
7
+ * which is the case when a caller hands us an already-built LanguageModel.
8
+ * The two are not interchangeable — one is an unrecognized answer, the other
9
+ * is a missing one, and they need different follow-up.
10
+ */
11
+ declare const MODEL_HOST_CLASSES: readonly ["openai", "azure", "openrouter", "anthropic", "google", "vertex", "bedrock", "groq", "unify", "minimax", "local", "other", "unknown"];
12
+ type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];
13
+ /**
14
+ * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
15
+ *
16
+ * @param baseUrl The endpoint the provider was configured with. Absent when
17
+ * the provider was left on its own default, which is why `providerDefault`
18
+ * exists: "no base URL, provider is openai" means api.openai.com.
19
+ * @param providerDefault What to report when no base URL was supplied. Callers
20
+ * that genuinely cannot observe a host — a pre-built LanguageModel handed in
21
+ * by the developer — leave this alone and get `unknown`.
22
+ */
23
+ declare function classifyModelHost(baseUrl?: string | null, providerDefault?: ModelHostClass): ModelHostClass;
24
+ //#endregion
25
+ export { MODEL_HOST_CLASSES, ModelHostClass, classifyModelHost };
26
+ //# sourceMappingURL=model-host.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-host.d.cts","names":[],"sources":["../../src/telemetry/model-host.ts"],"mappings":";;AAwBA;;;;;AAgBA;;;cAhBa,kBAAA;AAAA,KAgBD,cAAA,WAAyB,kBAAA;AA4ErC;;;;;;;;;;AAAA,iBAAgB,iBAAA,CACd,OAAA,kBACA,eAAA,GAAiB,cAAA,GAChB,cAAA"}
@@ -0,0 +1,26 @@
1
+ //#region src/telemetry/model-host.d.ts
2
+ /**
3
+ * Every value `classifyModelHost` can return.
4
+ *
5
+ * `other` means a host we observed and did not recognize: a gateway, a proxy,
6
+ * or a vendor we have no rule for. `unknown` means we never saw a host at all,
7
+ * which is the case when a caller hands us an already-built LanguageModel.
8
+ * The two are not interchangeable — one is an unrecognized answer, the other
9
+ * is a missing one, and they need different follow-up.
10
+ */
11
+ declare const MODEL_HOST_CLASSES: readonly ["openai", "azure", "openrouter", "anthropic", "google", "vertex", "bedrock", "groq", "unify", "minimax", "local", "other", "unknown"];
12
+ type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];
13
+ /**
14
+ * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
15
+ *
16
+ * @param baseUrl The endpoint the provider was configured with. Absent when
17
+ * the provider was left on its own default, which is why `providerDefault`
18
+ * exists: "no base URL, provider is openai" means api.openai.com.
19
+ * @param providerDefault What to report when no base URL was supplied. Callers
20
+ * that genuinely cannot observe a host — a pre-built LanguageModel handed in
21
+ * by the developer — leave this alone and get `unknown`.
22
+ */
23
+ declare function classifyModelHost(baseUrl?: string | null, providerDefault?: ModelHostClass): ModelHostClass;
24
+ //#endregion
25
+ export { MODEL_HOST_CLASSES, ModelHostClass, classifyModelHost };
26
+ //# sourceMappingURL=model-host.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-host.d.mts","names":[],"sources":["../../src/telemetry/model-host.ts"],"mappings":";;AAwBA;;;;;AAgBA;;;cAhBa,kBAAA;AAAA,KAgBD,cAAA,WAAyB,kBAAA;AA4ErC;;;;;;;;;;AAAA,iBAAgB,iBAAA,CACd,OAAA,kBACA,eAAA,GAAiB,cAAA,GAChB,cAAA"}
@@ -0,0 +1,102 @@
1
+ //#region src/telemetry/model-host.ts
2
+ /**
3
+ * Every value `classifyModelHost` can return.
4
+ *
5
+ * `other` means a host we observed and did not recognize: a gateway, a proxy,
6
+ * or a vendor we have no rule for. `unknown` means we never saw a host at all,
7
+ * which is the case when a caller hands us an already-built LanguageModel.
8
+ * The two are not interchangeable — one is an unrecognized answer, the other
9
+ * is a missing one, and they need different follow-up.
10
+ */
11
+ const MODEL_HOST_CLASSES = [
12
+ "openai",
13
+ "azure",
14
+ "openrouter",
15
+ "anthropic",
16
+ "google",
17
+ "vertex",
18
+ "bedrock",
19
+ "groq",
20
+ "unify",
21
+ "minimax",
22
+ "local",
23
+ "other",
24
+ "unknown"
25
+ ];
26
+ /**
27
+ * Host suffixes mapped to their vendor.
28
+ *
29
+ * Matched on label boundaries, never as substrings, so
30
+ * `myresource.openai.azure.com.attacker.test` does not read as Azure.
31
+ */
32
+ const HOST_SUFFIXES = [
33
+ ["openai.azure.com", "azure"],
34
+ ["services.ai.azure.com", "azure"],
35
+ ["cognitiveservices.azure.com", "azure"],
36
+ ["azure-api.net", "azure"],
37
+ ["api.openai.com", "openai"],
38
+ ["openrouter.ai", "openrouter"],
39
+ ["api.anthropic.com", "anthropic"],
40
+ ["generativelanguage.googleapis.com", "google"],
41
+ ["aiplatform.googleapis.com", "vertex"],
42
+ ["api.groq.com", "groq"],
43
+ ["api.unify.ai", "unify"],
44
+ ["api.minimax.io", "minimax"],
45
+ ["api.minimaxi.com", "minimax"]
46
+ ];
47
+ /** Suffixes that mean the model runs on the same machine or private network. */
48
+ const LOCAL_SUFFIXES = [
49
+ "localhost",
50
+ "local",
51
+ "internal",
52
+ "docker.internal"
53
+ ];
54
+ /** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */
55
+ const REGIONAL_HOST_PATTERNS = [[/^[a-z0-9-]+-aiplatform\.googleapis\.com$/, "vertex"], [/^bedrock[a-z0-9.-]*\.[a-z0-9-]+\.amazonaws\.com$/, "bedrock"]];
56
+ /** True when `host` equals `suffix` or sits directly beneath it. */
57
+ function matchesSuffix(host, suffix) {
58
+ return host === suffix || host.endsWith(`.${suffix}`);
59
+ }
60
+ /** True for loopback, unspecified, and RFC 1918 private addresses. */
61
+ function isPrivateAddress(host) {
62
+ if (host === "127.0.0.1" || host === "0.0.0.0" || host === "::1") return true;
63
+ if (host.startsWith("127.")) return true;
64
+ if (host.startsWith("10.") || host.startsWith("192.168.")) return true;
65
+ const privateClassB = /^172\.(\d{1,3})\./.exec(host);
66
+ if (privateClassB) {
67
+ const secondOctet = Number(privateClassB[1]);
68
+ return secondOctet >= 16 && secondOctet <= 31;
69
+ }
70
+ return false;
71
+ }
72
+ /**
73
+ * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
74
+ *
75
+ * @param baseUrl The endpoint the provider was configured with. Absent when
76
+ * the provider was left on its own default, which is why `providerDefault`
77
+ * exists: "no base URL, provider is openai" means api.openai.com.
78
+ * @param providerDefault What to report when no base URL was supplied. Callers
79
+ * that genuinely cannot observe a host — a pre-built LanguageModel handed in
80
+ * by the developer — leave this alone and get `unknown`.
81
+ */
82
+ function classifyModelHost(baseUrl, providerDefault = "unknown") {
83
+ const trimmed = baseUrl?.trim();
84
+ if (!trimmed) return providerDefault;
85
+ let host;
86
+ try {
87
+ host = new URL(trimmed).hostname.toLowerCase();
88
+ } catch {
89
+ return "other";
90
+ }
91
+ host = host.replace(/^\[|\]$/g, "");
92
+ if (!host) return "other";
93
+ if (isPrivateAddress(host)) return "local";
94
+ for (const suffix of LOCAL_SUFFIXES) if (matchesSuffix(host, suffix)) return "local";
95
+ for (const [suffix, hostClass] of HOST_SUFFIXES) if (matchesSuffix(host, suffix)) return hostClass;
96
+ for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) if (pattern.test(host)) return hostClass;
97
+ return "other";
98
+ }
99
+
100
+ //#endregion
101
+ export { MODEL_HOST_CLASSES, classifyModelHost };
102
+ //# sourceMappingURL=model-host.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-host.mjs","names":[],"sources":["../../src/telemetry/model-host.ts"],"sourcesContent":["// Which endpoint the runtime sends completions to, as a closed vocabulary.\n//\n// The AI SDK's provider label cannot answer this. A model built by\n// `createOpenAI` reports only its wire API: `openai.responses` for both\n// api.openai.com and Azure (whose own migration guide tells customers to use\n// exactly that client), and `openai.chat` for OpenRouter and a laptop running\n// Ollama alike. So the provider field reports the wire protocol, and the host\n// reports the vendor.\n//\n// Only the classification travels. A base URL like\n// `myresource.openai.azure.com` carries the customer's Azure resource name,\n// which identifies them, so the raw host must never reach telemetry. That is\n// why this returns a member of a fixed list rather than anything derived from\n// the input.\n\n/**\n * Every value `classifyModelHost` can return.\n *\n * `other` means a host we observed and did not recognize: a gateway, a proxy,\n * or a vendor we have no rule for. `unknown` means we never saw a host at all,\n * which is the case when a caller hands us an already-built LanguageModel.\n * The two are not interchangeable — one is an unrecognized answer, the other\n * is a missing one, and they need different follow-up.\n */\nexport const MODEL_HOST_CLASSES = [\n \"openai\",\n \"azure\",\n \"openrouter\",\n \"anthropic\",\n \"google\",\n \"vertex\",\n \"bedrock\",\n \"groq\",\n \"unify\",\n \"minimax\",\n \"local\",\n \"other\",\n \"unknown\",\n] as const;\n\nexport type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];\n\n/**\n * Host suffixes mapped to their vendor.\n *\n * Matched on label boundaries, never as substrings, so\n * `myresource.openai.azure.com.attacker.test` does not read as Azure.\n */\nconst HOST_SUFFIXES: ReadonlyArray<readonly [string, ModelHostClass]> = [\n // Azure exposes the same models under three host families: the classic\n // Azure OpenAI host, the Foundry Models host, and the general Cognitive\n // Services host. All three are Azure for our purposes.\n [\"openai.azure.com\", \"azure\"],\n [\"services.ai.azure.com\", \"azure\"],\n [\"cognitiveservices.azure.com\", \"azure\"],\n // API Management fronting an Azure OpenAI deployment, a common enterprise\n // pattern. Reported as azure because that is what sits behind it.\n [\"azure-api.net\", \"azure\"],\n\n [\"api.openai.com\", \"openai\"],\n [\"openrouter.ai\", \"openrouter\"],\n [\"api.anthropic.com\", \"anthropic\"],\n [\"generativelanguage.googleapis.com\", \"google\"],\n // Vertex regional hosts are `<region>-aiplatform.googleapis.com`, which is\n // not a suffix of a single label, so both spellings are listed.\n [\"aiplatform.googleapis.com\", \"vertex\"],\n [\"api.groq.com\", \"groq\"],\n [\"api.unify.ai\", \"unify\"],\n [\"api.minimax.io\", \"minimax\"],\n [\"api.minimaxi.com\", \"minimax\"],\n];\n\n/** Suffixes that mean the model runs on the same machine or private network. */\nconst LOCAL_SUFFIXES = [\"localhost\", \"local\", \"internal\", \"docker.internal\"];\n\n/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */\nconst REGIONAL_HOST_PATTERNS: ReadonlyArray<readonly [RegExp, ModelHostClass]> =\n [\n [/^[a-z0-9-]+-aiplatform\\.googleapis\\.com$/, \"vertex\"],\n [/^bedrock[a-z0-9.-]*\\.[a-z0-9-]+\\.amazonaws\\.com$/, \"bedrock\"],\n ];\n\n/** True when `host` equals `suffix` or sits directly beneath it. */\nfunction matchesSuffix(host: string, suffix: string): boolean {\n return host === suffix || host.endsWith(`.${suffix}`);\n}\n\n/** True for loopback, unspecified, and RFC 1918 private addresses. */\nfunction isPrivateAddress(host: string): boolean {\n if (host === \"127.0.0.1\" || host === \"0.0.0.0\" || host === \"::1\") {\n return true;\n }\n // 127.0.0.0/8 is entirely loopback.\n if (host.startsWith(\"127.\")) return true;\n // 10.0.0.0/8 and 192.168.0.0/16.\n if (host.startsWith(\"10.\") || host.startsWith(\"192.168.\")) return true;\n // 172.16.0.0/12 is 172.16 through 172.31 only. 172.32 is public, so the\n // second octet is range-checked rather than prefix-matched.\n const privateClassB = /^172\\.(\\d{1,3})\\./.exec(host);\n if (privateClassB) {\n const secondOctet = Number(privateClassB[1]);\n return secondOctet >= 16 && secondOctet <= 31;\n }\n return false;\n}\n\n/**\n * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.\n *\n * @param baseUrl The endpoint the provider was configured with. Absent when\n * the provider was left on its own default, which is why `providerDefault`\n * exists: \"no base URL, provider is openai\" means api.openai.com.\n * @param providerDefault What to report when no base URL was supplied. Callers\n * that genuinely cannot observe a host — a pre-built LanguageModel handed in\n * by the developer — leave this alone and get `unknown`.\n */\nexport function classifyModelHost(\n baseUrl?: string | null,\n providerDefault: ModelHostClass = \"unknown\",\n): ModelHostClass {\n const trimmed = baseUrl?.trim();\n if (!trimmed) {\n return providerDefault;\n }\n\n let host: string;\n try {\n // `hostname` drops the port, the path, the query and any credentials, so\n // nothing but the host can survive into the return value below.\n host = new URL(trimmed).hostname.toLowerCase();\n } catch {\n // We were given something and could not read it. That is a different fact\n // from having been given nothing, so it does not fall back to the default.\n return \"other\";\n }\n\n // IPv6 hostnames arrive bracketed from the URL parser.\n host = host.replace(/^\\[|\\]$/g, \"\");\n\n if (!host) return \"other\";\n\n if (isPrivateAddress(host)) return \"local\";\n for (const suffix of LOCAL_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return \"local\";\n }\n\n for (const [suffix, hostClass] of HOST_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return hostClass;\n }\n\n for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) {\n if (pattern.test(host)) return hostClass;\n }\n\n return \"other\";\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAUD,MAAM,gBAAkE;CAItE,CAAC,oBAAoB,QAAQ;CAC7B,CAAC,yBAAyB,QAAQ;CAClC,CAAC,+BAA+B,QAAQ;CAGxC,CAAC,iBAAiB,QAAQ;CAE1B,CAAC,kBAAkB,SAAS;CAC5B,CAAC,iBAAiB,aAAa;CAC/B,CAAC,qBAAqB,YAAY;CAClC,CAAC,qCAAqC,SAAS;CAG/C,CAAC,6BAA6B,SAAS;CACvC,CAAC,gBAAgB,OAAO;CACxB,CAAC,gBAAgB,QAAQ;CACzB,CAAC,kBAAkB,UAAU;CAC7B,CAAC,oBAAoB,UAAU;CAChC;;AAGD,MAAM,iBAAiB;CAAC;CAAa;CAAS;CAAY;CAAkB;;AAG5E,MAAM,yBACJ,CACE,CAAC,4CAA4C,SAAS,EACtD,CAAC,oDAAoD,UAAU,CAChE;;AAGH,SAAS,cAAc,MAAc,QAAyB;AAC5D,QAAO,SAAS,UAAU,KAAK,SAAS,IAAI,SAAS;;;AAIvD,SAAS,iBAAiB,MAAuB;AAC/C,KAAI,SAAS,eAAe,SAAS,aAAa,SAAS,MACzD,QAAO;AAGT,KAAI,KAAK,WAAW,OAAO,CAAE,QAAO;AAEpC,KAAI,KAAK,WAAW,MAAM,IAAI,KAAK,WAAW,WAAW,CAAE,QAAO;CAGlE,MAAM,gBAAgB,oBAAoB,KAAK,KAAK;AACpD,KAAI,eAAe;EACjB,MAAM,cAAc,OAAO,cAAc,GAAG;AAC5C,SAAO,eAAe,MAAM,eAAe;;AAE7C,QAAO;;;;;;;;;;;;AAaT,SAAgB,kBACd,SACA,kBAAkC,WAClB;CAChB,MAAM,UAAU,SAAS,MAAM;AAC/B,KAAI,CAAC,QACH,QAAO;CAGT,IAAI;AACJ,KAAI;AAGF,SAAO,IAAI,IAAI,QAAQ,CAAC,SAAS,aAAa;SACxC;AAGN,SAAO;;AAIT,QAAO,KAAK,QAAQ,YAAY,GAAG;AAEnC,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI,iBAAiB,KAAK,CAAE,QAAO;AACnC,MAAK,MAAM,UAAU,eACnB,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,QAAQ,cAAc,cAChC,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,SAAS,cAAc,uBACjC,KAAI,QAAQ,KAAK,KAAK,CAAE,QAAO;AAGjC,QAAO"}