@copilotkit/runtime 2.0.0-rc.6 → 2.0.0-rc.60

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 (417) hide show
  1. package/README.md +29 -4
  2. package/dist/agent/{url-download.cjs → ai-sdk/url-download.cjs} +19 -76
  3. package/dist/agent/ai-sdk/url-download.cjs.map +1 -0
  4. package/dist/agent/{url-download.d.cts → ai-sdk/url-download.d.cts} +11 -8
  5. package/dist/agent/ai-sdk/url-download.d.cts.map +1 -0
  6. package/dist/agent/{url-download.d.mts → ai-sdk/url-download.d.mts} +11 -8
  7. package/dist/agent/ai-sdk/url-download.d.mts.map +1 -0
  8. package/dist/agent/{url-download.mjs → ai-sdk/url-download.mjs} +20 -74
  9. package/dist/agent/ai-sdk/url-download.mjs.map +1 -0
  10. package/dist/agent/ai-sdk.cjs +425 -0
  11. package/dist/agent/ai-sdk.cjs.map +1 -0
  12. package/dist/agent/ai-sdk.d.cts +119 -0
  13. package/dist/agent/ai-sdk.d.cts.map +1 -0
  14. package/dist/agent/ai-sdk.d.mts +119 -0
  15. package/dist/agent/ai-sdk.d.mts.map +1 -0
  16. package/dist/agent/ai-sdk.mjs +419 -0
  17. package/dist/agent/ai-sdk.mjs.map +1 -0
  18. package/dist/agent/classic-tools.cjs +185 -0
  19. package/dist/agent/classic-tools.cjs.map +1 -0
  20. package/dist/agent/classic-tools.mjs +183 -0
  21. package/dist/agent/classic-tools.mjs.map +1 -0
  22. package/dist/agent/converters/aisdk.cjs +17 -4
  23. package/dist/agent/converters/aisdk.cjs.map +1 -1
  24. package/dist/agent/converters/aisdk.d.cts.map +1 -1
  25. package/dist/agent/converters/aisdk.d.mts.map +1 -1
  26. package/dist/agent/converters/aisdk.mjs +18 -2
  27. package/dist/agent/converters/aisdk.mjs.map +1 -1
  28. package/dist/agent/converters/tanstack.cjs +202 -30
  29. package/dist/agent/converters/tanstack.cjs.map +1 -1
  30. package/dist/agent/converters/tanstack.d.cts +90 -6
  31. package/dist/agent/converters/tanstack.d.cts.map +1 -1
  32. package/dist/agent/converters/tanstack.d.mts +90 -6
  33. package/dist/agent/converters/tanstack.d.mts.map +1 -1
  34. package/dist/agent/converters/tanstack.mjs +202 -29
  35. package/dist/agent/converters/tanstack.mjs.map +1 -1
  36. package/dist/agent/learned-skills.cjs +15 -17
  37. package/dist/agent/learned-skills.cjs.map +1 -1
  38. package/dist/agent/learned-skills.d.cts +9 -3
  39. package/dist/agent/learned-skills.d.cts.map +1 -1
  40. package/dist/agent/learned-skills.d.mts +9 -3
  41. package/dist/agent/learned-skills.d.mts.map +1 -1
  42. package/dist/agent/learned-skills.mjs +15 -16
  43. package/dist/agent/learned-skills.mjs.map +1 -1
  44. package/dist/agent/model.cjs +42 -0
  45. package/dist/agent/model.cjs.map +1 -0
  46. package/dist/agent/model.d.cts +19 -0
  47. package/dist/agent/model.d.cts.map +1 -0
  48. package/dist/agent/model.d.mts +19 -0
  49. package/dist/agent/model.d.mts.map +1 -0
  50. package/dist/agent/model.mjs +41 -0
  51. package/dist/agent/model.mjs.map +1 -0
  52. package/dist/agent/state-delta.cjs +0 -1
  53. package/dist/agent/state-delta.cjs.map +1 -1
  54. package/dist/agent.cjs +558 -0
  55. package/dist/agent.cjs.map +1 -0
  56. package/dist/agent.d.cts +455 -0
  57. package/dist/agent.d.cts.map +1 -0
  58. package/dist/agent.d.mts +455 -0
  59. package/dist/agent.d.mts.map +1 -0
  60. package/dist/agent.mjs +551 -0
  61. package/dist/agent.mjs.map +1 -0
  62. package/dist/index.cjs +23 -28
  63. package/dist/index.d.cts +14 -14
  64. package/dist/index.d.mts +14 -14
  65. package/dist/index.mjs +8 -8
  66. package/dist/internal/learned-skills.d.cts +1 -1
  67. package/dist/internal/learned-skills.d.mts +1 -1
  68. package/dist/node.cjs +2 -3
  69. package/dist/node.d.cts +3 -3
  70. package/dist/node.d.mts +3 -3
  71. package/dist/node.mjs +3 -3
  72. package/dist/runtime/core/channel-manager.cjs +10 -2
  73. package/dist/runtime/core/channel-manager.cjs.map +1 -1
  74. package/dist/runtime/core/channel-manager.d.cts +1 -1
  75. package/dist/runtime/core/channel-manager.d.mts +1 -1
  76. package/dist/runtime/core/channel-manager.mjs +10 -1
  77. package/dist/runtime/core/channel-manager.mjs.map +1 -1
  78. package/dist/runtime/core/debug-event-bus.cjs +4 -3
  79. package/dist/runtime/core/debug-event-bus.cjs.map +1 -1
  80. package/dist/runtime/core/debug-event-bus.d.cts +5 -1
  81. package/dist/runtime/core/debug-event-bus.d.cts.map +1 -1
  82. package/dist/runtime/core/debug-event-bus.d.mts +4 -0
  83. package/dist/runtime/core/debug-event-bus.d.mts.map +1 -1
  84. package/dist/runtime/core/debug-event-bus.mjs +5 -3
  85. package/dist/runtime/core/debug-event-bus.mjs.map +1 -1
  86. package/dist/runtime/core/fetch-cors.cjs.map +1 -1
  87. package/dist/runtime/core/fetch-cors.d.cts +2 -2
  88. package/dist/runtime/core/fetch-cors.d.cts.map +1 -1
  89. package/dist/runtime/core/fetch-cors.d.mts +2 -2
  90. package/dist/runtime/core/fetch-cors.d.mts.map +1 -1
  91. package/dist/runtime/core/fetch-cors.mjs.map +1 -1
  92. package/dist/runtime/core/fetch-handler.cjs +17 -14
  93. package/dist/runtime/core/fetch-handler.cjs.map +1 -1
  94. package/dist/runtime/core/fetch-handler.d.cts +22 -14
  95. package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
  96. package/dist/runtime/core/fetch-handler.d.mts +22 -14
  97. package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
  98. package/dist/runtime/core/fetch-handler.mjs +9 -5
  99. package/dist/runtime/core/fetch-handler.mjs.map +1 -1
  100. package/dist/runtime/core/hooks.cjs.map +1 -1
  101. package/dist/runtime/core/hooks.d.cts +5 -5
  102. package/dist/runtime/core/hooks.d.cts.map +1 -1
  103. package/dist/runtime/core/hooks.d.mts +5 -5
  104. package/dist/runtime/core/hooks.d.mts.map +1 -1
  105. package/dist/runtime/core/hooks.mjs.map +1 -1
  106. package/dist/runtime/core/learning.cjs.map +1 -1
  107. package/dist/runtime/core/learning.d.cts +9 -9
  108. package/dist/runtime/core/learning.d.cts.map +1 -1
  109. package/dist/runtime/core/learning.d.mts +8 -8
  110. package/dist/runtime/core/learning.d.mts.map +1 -1
  111. package/dist/runtime/core/learning.mjs.map +1 -1
  112. package/dist/runtime/core/logger.cjs +105 -14
  113. package/dist/runtime/core/logger.cjs.map +1 -1
  114. package/dist/runtime/core/logger.d.cts +26 -9
  115. package/dist/runtime/core/logger.d.cts.map +1 -1
  116. package/dist/runtime/core/logger.d.mts +26 -9
  117. package/dist/runtime/core/logger.d.mts.map +1 -1
  118. package/dist/runtime/core/logger.mjs +105 -12
  119. package/dist/runtime/core/logger.mjs.map +1 -1
  120. package/dist/runtime/core/middleware-sse-parser.cjs +3 -4
  121. package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -1
  122. package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -1
  123. package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -1
  124. package/dist/runtime/core/middleware-sse-parser.mjs +2 -2
  125. package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -1
  126. package/dist/runtime/core/middleware.cjs +5 -5
  127. package/dist/runtime/core/middleware.cjs.map +1 -1
  128. package/dist/runtime/core/middleware.d.cts +3 -3
  129. package/dist/runtime/core/middleware.d.cts.map +1 -1
  130. package/dist/runtime/core/middleware.d.mts +3 -3
  131. package/dist/runtime/core/middleware.d.mts.map +1 -1
  132. package/dist/runtime/core/middleware.mjs +4 -3
  133. package/dist/runtime/core/middleware.mjs.map +1 -1
  134. package/dist/runtime/core/package-info.cjs +1 -1
  135. package/dist/runtime/core/package-info.mjs +1 -1
  136. package/dist/runtime/core/runtime-error-reporter.cjs.map +1 -1
  137. package/dist/runtime/core/runtime-error-reporter.mjs.map +1 -1
  138. package/dist/runtime/core/runtime.cjs +44 -46
  139. package/dist/runtime/core/runtime.cjs.map +1 -1
  140. package/dist/runtime/core/runtime.d.cts +178 -91
  141. package/dist/runtime/core/runtime.d.cts.map +1 -1
  142. package/dist/runtime/core/runtime.d.mts +178 -91
  143. package/dist/runtime/core/runtime.d.mts.map +1 -1
  144. package/dist/runtime/core/runtime.mjs +42 -42
  145. package/dist/runtime/core/runtime.mjs.map +1 -1
  146. package/dist/runtime/endpoints/auto-start-channels.cjs +3 -4
  147. package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -1
  148. package/dist/runtime/endpoints/auto-start-channels.mjs +2 -2
  149. package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -1
  150. package/dist/runtime/endpoints/node-fetch-handler.cjs +4 -8
  151. package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
  152. package/dist/runtime/endpoints/node-fetch-handler.d.cts +4 -5
  153. package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
  154. package/dist/runtime/endpoints/node-fetch-handler.d.mts +4 -5
  155. package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
  156. package/dist/runtime/endpoints/node-fetch-handler.mjs +3 -5
  157. package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
  158. package/dist/runtime/endpoints/node.cjs +7 -5
  159. package/dist/runtime/endpoints/node.cjs.map +1 -1
  160. package/dist/runtime/endpoints/node.d.cts +16 -16
  161. package/dist/runtime/endpoints/node.d.cts.map +1 -1
  162. package/dist/runtime/endpoints/node.d.mts +16 -16
  163. package/dist/runtime/endpoints/node.d.mts.map +1 -1
  164. package/dist/runtime/endpoints/node.mjs +9 -7
  165. package/dist/runtime/endpoints/node.mjs.map +1 -1
  166. package/dist/runtime/event-transforms/index.d.cts +4 -0
  167. package/dist/runtime/event-transforms/index.d.mts +4 -0
  168. package/dist/runtime/event-transforms/index.mjs +5 -0
  169. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +277 -0
  170. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  171. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts +61 -0
  172. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  173. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts +61 -0
  174. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  175. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +276 -0
  176. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  177. package/dist/runtime/event-transforms/recorded-events.cjs +68 -0
  178. package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -0
  179. package/dist/runtime/event-transforms/recorded-events.d.cts +27 -0
  180. package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -0
  181. package/dist/runtime/event-transforms/recorded-events.d.mts +27 -0
  182. package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -0
  183. package/dist/runtime/event-transforms/recorded-events.mjs +68 -0
  184. package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -0
  185. package/dist/runtime/event-transforms/streaming-json-scanner.cjs +289 -0
  186. package/dist/runtime/event-transforms/streaming-json-scanner.cjs.map +1 -0
  187. package/dist/runtime/event-transforms/streaming-json-scanner.mjs +288 -0
  188. package/dist/runtime/event-transforms/streaming-json-scanner.mjs.map +1 -0
  189. package/dist/runtime/generative-ui/a2ui-v09-actions.cjs +106 -0
  190. package/dist/runtime/generative-ui/a2ui-v09-actions.cjs.map +1 -0
  191. package/dist/runtime/generative-ui/a2ui-v09-actions.mjs +106 -0
  192. package/dist/runtime/generative-ui/a2ui-v09-actions.mjs.map +1 -0
  193. package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs +422 -0
  194. package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs.map +1 -0
  195. package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs +422 -0
  196. package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs.map +1 -0
  197. package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs +84 -0
  198. package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs.map +1 -0
  199. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts +41 -0
  200. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts.map +1 -0
  201. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts +41 -0
  202. package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts.map +1 -0
  203. package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs +83 -0
  204. package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs.map +1 -0
  205. package/dist/runtime/generative-ui/a2ui-v09-operations.cjs +694 -0
  206. package/dist/runtime/generative-ui/a2ui-v09-operations.cjs.map +1 -0
  207. package/dist/runtime/generative-ui/a2ui-v09-operations.mjs +694 -0
  208. package/dist/runtime/generative-ui/a2ui-v09-operations.mjs.map +1 -0
  209. package/dist/runtime/generative-ui/generative-ui-middleware.cjs +0 -1
  210. package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -1
  211. package/dist/runtime/generative-ui/index.d.cts +1 -0
  212. package/dist/runtime/generative-ui/index.d.mts +1 -0
  213. package/dist/runtime/generative-ui/surface-writer.cjs +4 -5
  214. package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -1
  215. package/dist/runtime/generative-ui/surface-writer.d.cts +1 -1
  216. package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -1
  217. package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -1
  218. package/dist/runtime/generative-ui/surface-writer.mjs +5 -5
  219. package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -1
  220. package/dist/runtime/handlers/get-runtime-info.cjs +24 -6
  221. package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
  222. package/dist/runtime/handlers/get-runtime-info.mjs +25 -7
  223. package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
  224. package/dist/runtime/handlers/handle-connect.cjs +3 -8
  225. package/dist/runtime/handlers/handle-connect.cjs.map +1 -1
  226. package/dist/runtime/handlers/handle-connect.mjs +3 -8
  227. package/dist/runtime/handlers/handle-connect.mjs.map +1 -1
  228. package/dist/runtime/handlers/handle-debug-events.cjs.map +1 -1
  229. package/dist/runtime/handlers/handle-debug-events.mjs.map +1 -1
  230. package/dist/runtime/handlers/handle-inspector-learning.cjs +2 -3
  231. package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -1
  232. package/dist/runtime/handlers/handle-inspector-learning.mjs.map +1 -1
  233. package/dist/runtime/handlers/handle-inspector-metadata.cjs +2 -3
  234. package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -1
  235. package/dist/runtime/handlers/handle-inspector-metadata.mjs.map +1 -1
  236. package/dist/runtime/handlers/handle-run.cjs +11 -16
  237. package/dist/runtime/handlers/handle-run.cjs.map +1 -1
  238. package/dist/runtime/handlers/handle-run.mjs +8 -12
  239. package/dist/runtime/handlers/handle-run.mjs.map +1 -1
  240. package/dist/runtime/handlers/handle-stop.cjs +5 -5
  241. package/dist/runtime/handlers/handle-stop.cjs.map +1 -1
  242. package/dist/runtime/handlers/handle-stop.mjs +2 -1
  243. package/dist/runtime/handlers/handle-stop.mjs.map +1 -1
  244. package/dist/runtime/handlers/handle-suggest.cjs +6 -3
  245. package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
  246. package/dist/runtime/handlers/handle-suggest.mjs +6 -2
  247. package/dist/runtime/handlers/handle-suggest.mjs.map +1 -1
  248. package/dist/runtime/handlers/handle-trajectory-connect.cjs.map +1 -1
  249. package/dist/runtime/handlers/handle-trajectory-connect.mjs.map +1 -1
  250. package/dist/runtime/handlers/handle-transcribe.cjs +0 -1
  251. package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -1
  252. package/dist/runtime/handlers/handle-transcribe.mjs.map +1 -1
  253. package/dist/runtime/handlers/intelligence/annotate.cjs +8 -8
  254. package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -1
  255. package/dist/runtime/handlers/intelligence/annotate.mjs +5 -4
  256. package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -1
  257. package/dist/runtime/handlers/intelligence/connect.cjs +6 -2
  258. package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -1
  259. package/dist/runtime/handlers/intelligence/connect.mjs +6 -2
  260. package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -1
  261. package/dist/runtime/handlers/intelligence/memories.cjs +28 -23
  262. package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -1
  263. package/dist/runtime/handlers/intelligence/memories.mjs +12 -6
  264. package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -1
  265. package/dist/runtime/handlers/intelligence/run.cjs +38 -30
  266. package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
  267. package/dist/runtime/handlers/intelligence/run.mjs +37 -28
  268. package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
  269. package/dist/runtime/handlers/intelligence/thread-names.cjs +6 -5
  270. package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
  271. package/dist/runtime/handlers/intelligence/thread-names.mjs +3 -1
  272. package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
  273. package/dist/runtime/handlers/intelligence/threads.cjs +40 -31
  274. package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -1
  275. package/dist/runtime/handlers/intelligence/threads.mjs +18 -8
  276. package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -1
  277. package/dist/runtime/handlers/shared/agent-utils.cjs +50 -46
  278. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  279. package/dist/runtime/handlers/shared/agent-utils.mjs +47 -42
  280. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  281. package/dist/runtime/handlers/shared/cloud-telemetry.cjs +0 -1
  282. package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -1
  283. package/dist/runtime/handlers/shared/memory-policy.cjs.map +1 -1
  284. package/dist/runtime/handlers/shared/memory-policy.mjs.map +1 -1
  285. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +4 -3
  286. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
  287. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +4 -3
  288. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
  289. package/dist/runtime/handlers/shared/sse-response.cjs +77 -78
  290. package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -1
  291. package/dist/runtime/handlers/shared/sse-response.mjs +77 -77
  292. package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -1
  293. package/dist/runtime/handlers/shared/thread-access.cjs +4 -3
  294. package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -1
  295. package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -1
  296. package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -1
  297. package/dist/runtime/handlers/shared/thread-access.mjs +4 -3
  298. package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -1
  299. package/dist/runtime/handlers/sse/connect.cjs +2 -0
  300. package/dist/runtime/handlers/sse/connect.cjs.map +1 -1
  301. package/dist/runtime/handlers/sse/connect.mjs +2 -0
  302. package/dist/runtime/handlers/sse/connect.mjs.map +1 -1
  303. package/dist/runtime/handlers/sse/run.cjs +5 -2
  304. package/dist/runtime/handlers/sse/run.cjs.map +1 -1
  305. package/dist/runtime/handlers/sse/run.mjs +5 -2
  306. package/dist/runtime/handlers/sse/run.mjs.map +1 -1
  307. package/dist/runtime/index.d.cts +13 -18
  308. package/dist/runtime/index.d.mts +13 -18
  309. package/dist/runtime/intelligence-platform/analytics-context.cjs +84 -0
  310. package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -0
  311. package/dist/runtime/intelligence-platform/analytics-context.mjs +83 -0
  312. package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -0
  313. package/dist/runtime/intelligence-platform/client.cjs +30 -4
  314. package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
  315. package/dist/runtime/intelligence-platform/client.d.cts +25 -2
  316. package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
  317. package/dist/runtime/intelligence-platform/client.d.mts +25 -2
  318. package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
  319. package/dist/runtime/intelligence-platform/client.mjs +30 -3
  320. package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
  321. package/dist/runtime/intelligence-platform/learning-management.cjs +7 -8
  322. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
  323. package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
  324. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
  325. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -110
  326. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
  327. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
  328. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
  329. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
  330. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
  331. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
  332. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
  333. package/dist/runtime/intelligence-platform/skill-registry/config.cjs +0 -1
  334. package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
  335. package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +1 -1
  336. package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +1 -1
  337. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +22 -19
  338. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
  339. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
  340. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
  341. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +22 -19
  342. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
  343. package/dist/runtime/intelligence-platform/stop-run.cjs +50 -0
  344. package/dist/runtime/intelligence-platform/stop-run.cjs.map +1 -0
  345. package/dist/runtime/intelligence-platform/stop-run.mjs +50 -0
  346. package/dist/runtime/intelligence-platform/stop-run.mjs.map +1 -0
  347. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +3 -3
  348. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
  349. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +2 -1
  350. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -1
  351. package/dist/runtime/intelligence-platform/trajectories.cjs +2 -3
  352. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
  353. package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
  354. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
  355. package/dist/runtime/node.d.cts +2 -2
  356. package/dist/runtime/node.d.mts +2 -2
  357. package/dist/runtime/runner/agent-runner.cjs +0 -1
  358. package/dist/runtime/runner/agent-runner.cjs.map +1 -1
  359. package/dist/runtime/runner/agent-runner.d.cts +9 -0
  360. package/dist/runtime/runner/agent-runner.d.cts.map +1 -1
  361. package/dist/runtime/runner/agent-runner.d.mts +9 -0
  362. package/dist/runtime/runner/agent-runner.d.mts.map +1 -1
  363. package/dist/runtime/runner/agent-runner.mjs.map +1 -1
  364. package/dist/runtime/runner/in-memory.cjs +0 -1
  365. package/dist/runtime/runner/in-memory.cjs.map +1 -1
  366. package/dist/runtime/runner/index.d.cts +1 -1
  367. package/dist/runtime/runner/index.d.mts +1 -1
  368. package/dist/runtime/runner/index.mjs +1 -1
  369. package/dist/runtime/runner/intelligence.cjs +55 -9
  370. package/dist/runtime/runner/intelligence.cjs.map +1 -1
  371. package/dist/runtime/runner/intelligence.d.cts +12 -1
  372. package/dist/runtime/runner/intelligence.d.cts.map +1 -1
  373. package/dist/runtime/runner/intelligence.d.mts +12 -1
  374. package/dist/runtime/runner/intelligence.d.mts.map +1 -1
  375. package/dist/runtime/runner/intelligence.mjs +56 -10
  376. package/dist/runtime/runner/intelligence.mjs.map +1 -1
  377. package/dist/runtime/telemetry/disclosure.cjs +2 -3
  378. package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
  379. package/dist/runtime/telemetry/disclosure.mjs +3 -3
  380. package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
  381. package/dist/runtime/telemetry/events.d.cts +1 -1
  382. package/dist/runtime/telemetry/events.d.mts +1 -1
  383. package/dist/runtime/telemetry/instance-created.cjs +33 -12
  384. package/dist/runtime/telemetry/instance-created.cjs.map +1 -1
  385. package/dist/runtime/telemetry/instance-created.mjs +33 -12
  386. package/dist/runtime/telemetry/instance-created.mjs.map +1 -1
  387. package/dist/runtime/telemetry/telemetry-client.cjs +0 -5
  388. package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
  389. package/dist/runtime/telemetry/telemetry-client.mjs +0 -4
  390. package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
  391. package/dist/runtime/telemetry/telemetry-identity.cjs +0 -1
  392. package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -1
  393. package/dist/v2/index.d.cts +242 -0
  394. package/dist/v2/index.d.mts +242 -0
  395. package/dist/v2/node.d.cts +18 -0
  396. package/dist/v2/node.d.mts +18 -0
  397. package/package.json +84 -29
  398. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  399. package/dist/agent/converters/index.d.mts +0 -2
  400. package/dist/agent/index.cjs +0 -1328
  401. package/dist/agent/index.cjs.map +0 -1
  402. package/dist/agent/index.d.cts +0 -467
  403. package/dist/agent/index.d.cts.map +0 -1
  404. package/dist/agent/index.d.mts +0 -468
  405. package/dist/agent/index.d.mts.map +0 -1
  406. package/dist/agent/index.mjs +0 -1318
  407. package/dist/agent/index.mjs.map +0 -1
  408. package/dist/agent/mcp-tool-names.cjs +0 -82
  409. package/dist/agent/mcp-tool-names.cjs.map +0 -1
  410. package/dist/agent/mcp-tool-names.mjs +0 -80
  411. package/dist/agent/mcp-tool-names.mjs.map +0 -1
  412. package/dist/agent/url-download.cjs.map +0 -1
  413. package/dist/agent/url-download.d.cts.map +0 -1
  414. package/dist/agent/url-download.d.mts.map +0 -1
  415. package/dist/agent/url-download.mjs.map +0 -1
  416. package/dist/runtime/index.d.cts.map +0 -1
  417. package/dist/runtime/index.d.mts.map +0 -1
@@ -0,0 +1,694 @@
1
+ const require_usage = require('../../agent/converters/usage.cjs');
2
+ let _copilotkit_shared = require("@copilotkit/shared");
3
+ let _ag_ui_client = require("@ag-ui/client");
4
+ let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
5
+
6
+ //#region src/runtime/generative-ui/a2ui-v09-operations.ts
7
+ /**
8
+ * The activity type and content key of v0.9 surfaces, as
9
+ * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.
10
+ */
11
+ const A2UI_SURFACE_ACTIVITY_TYPE = "a2ui-surface";
12
+ const A2UI_OPERATIONS_KEY = "a2ui_operations";
13
+ /** The `version` values of A2UI v0.9 messages. */
14
+ const V09_VERSIONS = new Set(["v0.9", "v0.9.1"]);
15
+ const V09_KINDS = [
16
+ "createSurface",
17
+ "updateComponents",
18
+ "updateDataModel",
19
+ "deleteSurface"
20
+ ];
21
+ /**
22
+ * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of
23
+ * the published catalog document. Both become the standard catalog, which has
24
+ * the same 18 components.
25
+ */
26
+ const V09_BASIC_CATALOG_IDS = new Set(["https://a2ui.org/specification/v0_9/basic_catalog.json", "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json"]);
27
+ /**
28
+ * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for
29
+ * example ADK) send. It has the 18 components of the v0.9 basic catalog
30
+ * with 1.0 bindings, so it becomes the standard catalog too.
31
+ */
32
+ const V10_BASIC_CATALOG_IDS = new Set(["https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json"]);
33
+ /** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */
34
+ const HEADING_SIZES = {
35
+ h1: "2xl",
36
+ h2: "xl",
37
+ h3: "lg",
38
+ h4: "md",
39
+ h5: "sm"
40
+ };
41
+ /** The one v0.9 operation key of `op`, when it has exactly one. */
42
+ function v09Kind(op) {
43
+ const kinds = V09_KINDS.filter((kind) => kind in op);
44
+ return kinds.length === 1 ? kinds[0] : void 0;
45
+ }
46
+ /**
47
+ * True for an A2UI v0.9 operation: an object whose `version` is `"v0.9"` (or
48
+ * `"v0.9.1"`). An object without `version` counts when it has exactly one
49
+ * v0.9 operation key with an object payload. A 1.0 operation always carries
50
+ * `version: "1.0"` (the client rejects one without it), and v0.8 uses other
51
+ * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with
52
+ * a v0.9 key can only be v0.9. Agents leave `version` out often enough that
53
+ * requiring it would drop their surfaces.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * isA2UIV09Operation({ version: "v0.9", deleteSurface: { surfaceId: "s" } }); // true
58
+ * isA2UIV09Operation({ deleteSurface: { surfaceId: "s" } }); // true
59
+ * isA2UIV09Operation({ version: "1.0", deleteSurface: { surfaceId: "s" } }); // false
60
+ * ```
61
+ */
62
+ function isA2UIV09Operation(value) {
63
+ if (!require_usage.isRecord(value)) return false;
64
+ if (value.version !== void 0) return typeof value.version === "string" && V09_VERSIONS.has(value.version);
65
+ const kind = v09Kind(value);
66
+ return kind !== void 0 && require_usage.isRecord(value[kind]);
67
+ }
68
+ const ok = (value) => ({
69
+ ok: true,
70
+ value
71
+ });
72
+ const failed = (reason) => ({
73
+ ok: false,
74
+ reason
75
+ });
76
+ /**
77
+ * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ "@path" }` and
78
+ * `{ call, args }` becomes `{ "@call", args }`, at any depth. Literals stay.
79
+ */
80
+ function convertValue(value) {
81
+ if (Array.isArray(value)) return value.map(convertValue);
82
+ if (!require_usage.isRecord(value)) return value;
83
+ const keys = Object.keys(value);
84
+ if (keys.length === 1 && typeof value.path === "string") return { "@path": value.path };
85
+ if (typeof value.call === "string" && keys.every((key) => key === "call" || key === "args" || key === "returnType")) return convertCall(value);
86
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, convertValue(item)]));
87
+ }
88
+ /** A v0.9 function call `{ call, args, returnType }` as `{ "@call", args }`. */
89
+ function convertCall(call) {
90
+ return {
91
+ "@call": call.call,
92
+ ...call.args === void 0 ? {} : { args: convertValue(call.args) }
93
+ };
94
+ }
95
+ /** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */
96
+ function isV09Action(value) {
97
+ if (!require_usage.isRecord(value)) return false;
98
+ return Object.keys(value).length === 1 && (require_usage.isRecord(value.event) || require_usage.isRecord(value.functionCall));
99
+ }
100
+ /**
101
+ * A v0.9 action as a 1.0 event binding. The event keeps its name and
102
+ * context (with converted values); a function call gets the `@call` form.
103
+ */
104
+ function convertAction(action) {
105
+ if (!isV09Action(action)) return failed("action must be { \"event\": ... } or { \"functionCall\": ... }");
106
+ if (require_usage.isRecord(action.functionCall)) {
107
+ const call = action.functionCall;
108
+ if (typeof call.call !== "string" || !call.call) return failed("action.functionCall.call must be a function name");
109
+ return ok({ functionCall: convertCall(call) });
110
+ }
111
+ const event = action.event;
112
+ if (typeof event.name !== "string" || !event.name) return failed("action.event.name is required");
113
+ return ok({ event: {
114
+ name: event.name,
115
+ ...event.context === void 0 ? {} : { context: convertValue(event.context) }
116
+ } });
117
+ }
118
+ /**
119
+ * The basic-catalog changes of one component. Every other prop keeps its
120
+ * name; the 1.0 standard catalog uses the v0.9 names.
121
+ *
122
+ * - `Text` with a heading `variant` becomes `Title` (h1 "2xl" to h5 "sm"),
123
+ * with `caption` it becomes `Caption`; `variant` goes. Title and Caption
124
+ * have no `weight`, so it goes too.
125
+ * - `Button.action` becomes `onClick`.
126
+ * - `TextField.validationRegexp` becomes a `regex` check on its value.
127
+ */
128
+ function applyBasicCatalogChanges(node) {
129
+ if (node.component === "Text" && "variant" in node) {
130
+ const { variant, ...rest } = node;
131
+ const size = typeof variant === "string" ? HEADING_SIZES[variant] : void 0;
132
+ if (size !== void 0) {
133
+ const { weight: _weight, ...title } = rest;
134
+ return {
135
+ ...title,
136
+ component: "Title",
137
+ size
138
+ };
139
+ }
140
+ if (variant === "caption") {
141
+ const { weight: _weight, ...caption } = rest;
142
+ return {
143
+ ...caption,
144
+ component: "Caption"
145
+ };
146
+ }
147
+ return rest;
148
+ }
149
+ if (node.component === "Button" && "action" in node) {
150
+ const { action, ...rest } = node;
151
+ return {
152
+ ...rest,
153
+ onClick: action
154
+ };
155
+ }
156
+ if (node.component === "TextField" && "validationRegexp" in node) {
157
+ const { validationRegexp, ...rest } = node;
158
+ if (typeof validationRegexp !== "string" || rest.value === void 0) return rest;
159
+ const check = { condition: {
160
+ "@call": "regex",
161
+ args: {
162
+ value: rest.value,
163
+ pattern: validationRegexp
164
+ }
165
+ } };
166
+ const checks = Array.isArray(rest.checks) ? rest.checks : [];
167
+ return {
168
+ ...rest,
169
+ checks: [...checks, check]
170
+ };
171
+ }
172
+ return node;
173
+ }
174
+ /** One v0.9 component (flat format) as a 1.0 component node. */
175
+ function convertComponent(node) {
176
+ if (!require_usage.isRecord(node) || typeof node.id !== "string" || !node.id) return failed("a component needs a string id");
177
+ if (typeof node.component !== "string" || !node.component) return failed(`component "${node.id}": the component type must be a string (the v0.9 flat format)`);
178
+ const converted = {};
179
+ for (const [key, value] of Object.entries(node)) if (key === "id" || key === "component") converted[key] = value;
180
+ else if (key === "action" || isV09Action(value)) {
181
+ const action = convertAction(value);
182
+ if (action.ok === false) return failed(`component "${node.id}": ${action.reason}`);
183
+ converted[key] = action.value;
184
+ } else converted[key] = convertValue(value);
185
+ return ok(applyBasicCatalogChanges(converted));
186
+ }
187
+ function convertUpdateComponents(payload, surfaceId) {
188
+ const { components } = payload;
189
+ if (!Array.isArray(components) || components.length === 0) return failed("updateComponents.components must be a non-empty array");
190
+ const nodes = [];
191
+ for (const component of components) {
192
+ const converted = convertComponent(component);
193
+ if (converted.ok === false) return converted;
194
+ nodes.push(converted.value);
195
+ }
196
+ return ok({
197
+ version: _copilotkit_shared.A2UI_VERSION,
198
+ updateComponents: {
199
+ surfaceId,
200
+ components: nodes
201
+ }
202
+ });
203
+ }
204
+ /**
205
+ * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it
206
+ * for `null`. At the root, removing means an empty data model.
207
+ */
208
+ function convertUpdateDataModel(payload, surfaceId) {
209
+ const { path, value } = payload;
210
+ if (path !== void 0 && typeof path !== "string") return failed("updateDataModel.path must be a string");
211
+ const relative = typeof path === "string" ? path : "";
212
+ const pointer = relative.startsWith("/") ? relative : `/${relative}`;
213
+ const isRoot = pointer === "/";
214
+ if (isRoot && value !== void 0 && !require_usage.isRecord(value)) return failed("a root updateDataModel value must be a JSON object in A2UI 1.0");
215
+ return ok({
216
+ version: _copilotkit_shared.A2UI_VERSION,
217
+ updateDataModel: {
218
+ surfaceId,
219
+ path: pointer,
220
+ value: value === void 0 ? isRoot ? {} : null : value
221
+ }
222
+ });
223
+ }
224
+ function convertCreateSurface(payload, surfaceId) {
225
+ const { catalogId } = payload;
226
+ const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;
227
+ return {
228
+ version: _copilotkit_shared.A2UI_VERSION,
229
+ createSurface: {
230
+ surfaceId,
231
+ ...typeof catalogId === "string" && catalogId ? { catalogId: V09_BASIC_CATALOG_IDS.has(catalogId) ? _copilotkit_shared_generative_ui.STANDARD_CATALOG_ID : catalogId } : {},
232
+ ...typeof sendDataModel === "boolean" ? { sendDataModel } : {}
233
+ }
234
+ };
235
+ }
236
+ /** Basic catalog components as standard ones; anything else stays. */
237
+ function standardComponents(components) {
238
+ return Array.isArray(components) ? components.map((node) => require_usage.isRecord(node) ? applyBasicCatalogChanges(node) : node) : components;
239
+ }
240
+ /**
241
+ * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic
242
+ * catalog id becomes the standard catalog id, and the basic catalog
243
+ * components (inline in createSurface, or in updateComponents) get the
244
+ * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.
245
+ * Everything else stays; the client validates the operation.
246
+ */
247
+ function upgradeV10Operation(op) {
248
+ const { createSurface: create, updateComponents: update } = op;
249
+ if (require_usage.isRecord(create)) {
250
+ const { catalogId } = create;
251
+ return {
252
+ ...op,
253
+ createSurface: {
254
+ ...create,
255
+ ...typeof catalogId === "string" && V10_BASIC_CATALOG_IDS.has(catalogId) ? { catalogId: _copilotkit_shared_generative_ui.STANDARD_CATALOG_ID } : {},
256
+ ...create.components === void 0 ? {} : { components: standardComponents(create.components) }
257
+ }
258
+ };
259
+ }
260
+ if (require_usage.isRecord(update)) return {
261
+ ...op,
262
+ updateComponents: {
263
+ ...update,
264
+ ...update.components === void 0 ? {} : { components: standardComponents(update.components) }
265
+ }
266
+ };
267
+ return op;
268
+ }
269
+ /** One operation as 1.0, or why it cannot be converted. */
270
+ function upgradeOperation(op) {
271
+ if (!require_usage.isRecord(op)) return failed("operation must be a JSON object");
272
+ if (op.version === _copilotkit_shared.A2UI_VERSION) return ok(upgradeV10Operation(op));
273
+ if (!isA2UIV09Operation(op)) return failed(typeof op.version === "string" ? `unsupported A2UI version "${op.version}"; only v0.9 and 1.0 operations are supported` : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(", ")}`);
274
+ const kind = v09Kind(op);
275
+ if (!kind) return failed(`operation must contain exactly one of ${V09_KINDS.join(", ")}`);
276
+ const payload = op[kind];
277
+ if (!require_usage.isRecord(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return failed(`${kind}.surfaceId is required`);
278
+ const { surfaceId } = payload;
279
+ switch (kind) {
280
+ case "createSurface": return ok(convertCreateSurface(payload, surfaceId));
281
+ case "updateComponents": return convertUpdateComponents(payload, surfaceId);
282
+ case "updateDataModel": return convertUpdateDataModel(payload, surfaceId);
283
+ case "deleteSurface": return ok({
284
+ version: _copilotkit_shared.A2UI_VERSION,
285
+ deleteSurface: { surfaceId }
286
+ });
287
+ }
288
+ }
289
+ /**
290
+ * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.
291
+ *
292
+ * - createSurface: the v0.9 basic catalog id becomes the standard catalog
293
+ * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no
294
+ * 1.0 field and goes; `sendDataModel` stays.
295
+ * - updateComponents: `{ path }` becomes `{ "@path" }` and `{ call, args }`
296
+ * becomes `{ "@call", args }` at any depth; an action becomes an
297
+ * `{ event }` or `{ functionCall }` binding; child lists and templates
298
+ * stay. See {@link applyBasicCatalogChanges} for the props that change.
299
+ * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at
300
+ * the root.
301
+ * - deleteSurface: unchanged.
302
+ *
303
+ * An operation that is already 1.0 (native, for example from ADK) keeps its
304
+ * form: only the 1.0 basic catalog id becomes the standard catalog id, and
305
+ * its basic catalog components get the same changes as v0.9 ones. Any other
306
+ * operation, and any v0.9 operation that cannot be converted, goes to
307
+ * `dropped` with the reason.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * upgradeA2UIV09Operations([
312
+ * { version: "v0.9", updateDataModel: { surfaceId: "s", path: "/x" } },
313
+ * ]);
314
+ * // { operations: [{ version: "1.0", updateDataModel: { surfaceId: "s", path: "/x", value: null } }], dropped: [] }
315
+ * ```
316
+ */
317
+ function upgradeA2UIV09Operations(operations) {
318
+ const upgraded = [];
319
+ const dropped = [];
320
+ for (const operation of Array.isArray(operations) ? operations : []) {
321
+ let result;
322
+ try {
323
+ result = upgradeOperation(operation);
324
+ } catch (error) {
325
+ result = failed(`operation could not be read: ${error instanceof Error ? error.message : String(error)}`);
326
+ }
327
+ if (result.ok === false) dropped.push({
328
+ operation,
329
+ reason: result.reason
330
+ });
331
+ else upgraded.push(result.value);
332
+ }
333
+ return {
334
+ operations: upgraded,
335
+ dropped
336
+ };
337
+ }
338
+ /** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */
339
+ function surfaceIdOf(op) {
340
+ if (!require_usage.isRecord(op)) return void 0;
341
+ for (const kind of V09_KINDS) {
342
+ const payload = op[kind];
343
+ if (require_usage.isRecord(payload) && typeof payload.surfaceId === "string") return payload.surfaceId || void 0;
344
+ }
345
+ }
346
+ /**
347
+ * The error of a `failed` lifecycle snapshot: the agent's A2UI recovery
348
+ * gave up (`a2ui_recovery_exhausted`). Undefined for any other content.
349
+ */
350
+ function failedLifecycleError(content) {
351
+ if (!require_usage.isRecord(content) || content.status !== "failed") return void 0;
352
+ return (typeof content.error === "string" && content.error ? content.error : "A2UI generation failed").slice(0, _copilotkit_shared.GENERATIVE_UI_MAX_REJECTION_LENGTH);
353
+ }
354
+ /** The operations of `a2ui-surface` content. Lifecycle content has none. */
355
+ function readOperations(content) {
356
+ if (!require_usage.isRecord(content)) return [];
357
+ const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;
358
+ return Array.isArray(operations) ? operations : [];
359
+ }
360
+ function pointerSegments(pointer) {
361
+ if (pointer === "") return [];
362
+ if (!pointer.startsWith("/")) throw new Error(`invalid pointer "${pointer}"`);
363
+ return pointer.slice(1).split("/").map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
364
+ }
365
+ const FORBIDDEN_SEGMENTS = new Set([
366
+ "__proto__",
367
+ "constructor",
368
+ "prototype"
369
+ ]);
370
+ /**
371
+ * Applies RFC 6902 operations to `document` in place and returns the new
372
+ * root. Throws on a path that does not resolve, like `fast-json-patch` in
373
+ * the AG-UI client, so a bad delta leaves the stored content alone.
374
+ */
375
+ function applyJsonPatch(document, patch) {
376
+ if (!Array.isArray(patch)) throw new Error("patch must be an array");
377
+ let root = document;
378
+ const parentOf = (pointer) => {
379
+ const segments = pointerSegments(pointer);
380
+ const key = segments.pop();
381
+ let parent = root;
382
+ for (const segment of segments) {
383
+ if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error("forbidden path");
384
+ parent = Array.isArray(parent) ? parent[Number(segment)] : require_usage.isRecord(parent) ? parent[segment] : void 0;
385
+ if (parent === void 0) throw new Error(`path "${pointer}" not found`);
386
+ }
387
+ if (key !== void 0 && FORBIDDEN_SEGMENTS.has(key)) throw new Error("forbidden path");
388
+ return {
389
+ parent,
390
+ key
391
+ };
392
+ };
393
+ const read = (pointer) => {
394
+ const { parent, key } = parentOf(pointer);
395
+ if (key === void 0) return root;
396
+ if (Array.isArray(parent)) return parent[Number(key)];
397
+ return require_usage.isRecord(parent) ? parent[key] : void 0;
398
+ };
399
+ const remove = (pointer) => {
400
+ const { parent, key } = parentOf(pointer);
401
+ if (key === void 0) throw new Error("cannot remove the root");
402
+ if (Array.isArray(parent)) parent.splice(Number(key), 1);
403
+ else if (require_usage.isRecord(parent) && key in parent) delete parent[key];
404
+ else throw new Error(`path "${pointer}" not found`);
405
+ };
406
+ const write = (pointer, value, insert) => {
407
+ const { parent, key } = parentOf(pointer);
408
+ if (key === void 0) root = value;
409
+ else if (Array.isArray(parent)) {
410
+ const index = key === "-" ? parent.length : Number(key);
411
+ if (!Number.isInteger(index) || index < 0 || index > parent.length) throw new Error(`index "${key}" is out of range`);
412
+ parent.splice(index, insert ? 0 : 1, value);
413
+ } else if (require_usage.isRecord(parent)) parent[key] = value;
414
+ else throw new Error(`path "${pointer}" not found`);
415
+ };
416
+ for (const entry of patch) {
417
+ if (!require_usage.isRecord(entry) || typeof entry.path !== "string") throw new Error("invalid patch operation");
418
+ switch (entry.op) {
419
+ case "add":
420
+ write(entry.path, (0, _copilotkit_shared.cloneValue)(entry.value), true);
421
+ break;
422
+ case "replace":
423
+ if (read(entry.path) === void 0) throw new Error(`path "${entry.path}" not found`);
424
+ write(entry.path, (0, _copilotkit_shared.cloneValue)(entry.value), false);
425
+ break;
426
+ case "remove":
427
+ remove(entry.path);
428
+ break;
429
+ case "copy":
430
+ write(entry.path, (0, _copilotkit_shared.cloneValue)(read(entry.from ?? "")), true);
431
+ break;
432
+ case "move": {
433
+ const value = read(entry.from ?? "");
434
+ remove(entry.from ?? "");
435
+ write(entry.path, value, true);
436
+ break;
437
+ }
438
+ case "test":
439
+ if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) throw new Error(`test failed at "${entry.path}"`);
440
+ break;
441
+ default: throw new Error(`unknown patch op "${String(entry.op)}"`);
442
+ }
443
+ }
444
+ return root;
445
+ }
446
+ /**
447
+ * The operations of the next snapshot of a surface, so that the client
448
+ * applies every change of the source.
449
+ *
450
+ * The client applies only the operations after the ones it applied, when the
451
+ * operation at its last applied index did not change. A source that changes
452
+ * an earlier operation but not that one (a progressive render that rewrites
453
+ * its components, then sends the same data again) would lose the change. In
454
+ * that case the changed operations of the source are appended to the sent
455
+ * ones: v0.9 updates replace by id or path, so sending them again is safe,
456
+ * and a second createSurface is left out. In every other case the source
457
+ * operations go as they are: the client either extends its surface with them
458
+ * or builds it again from them.
459
+ *
460
+ * @param lastSource - The source operations of the last snapshot (none
461
+ * before the first one).
462
+ * @param sent - The operations of the last snapshot.
463
+ * @param source - The source operations now.
464
+ * @returns The operations of the next snapshot.
465
+ */
466
+ function clientOperations(lastSource, sent, source) {
467
+ let same = 0;
468
+ while (same < lastSource.length && same < source.length && JSON.stringify(lastSource[same]) === JSON.stringify(source[same])) same++;
469
+ const appended = source.slice(same);
470
+ if (same === lastSource.length) return [...sent, ...appended];
471
+ const last = sent.length - 1;
472
+ if (source.length < sent.length || JSON.stringify(source[last]) !== JSON.stringify(sent[last])) return source;
473
+ return [...sent, ...appended.filter((op) => !("createSurface" in op))];
474
+ }
475
+ /**
476
+ * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native
477
+ * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass
478
+ * every event of the run through `transform`, in order.
479
+ *
480
+ * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per
481
+ * messageId (a delta is applied to the stored content), and its
482
+ * operations are converted with {@link upgradeA2UIV09Operations}.
483
+ * - Each surface becomes one `generative-ui-surface` message,
484
+ * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is
485
+ * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the
486
+ * cumulative 1.0 content: the operations of every source message for it,
487
+ * in order, with only the first createSurface. The target is the chat,
488
+ * the status is "ready", dropped operations are `rejected` (at their
489
+ * index in the source message), and `a2uiSourceVersion` is "0.9" for a
490
+ * surface written in v0.9.
491
+ * - A surface written in native A2UI 1.0 (`version: "1.0"`, for example
492
+ * from ADK) becomes the same `generative-ui-surface` message, without
493
+ * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the
494
+ * agent unchanged. One surface has one version, the version of its
495
+ * first operation; an operation of the other version is rejected.
496
+ * - A surface that this run updates but does not create (v0.9 sends no
497
+ * second createSurface) was created in an earlier run, so its new
498
+ * operations are appended to its message with an `ACTIVITY_DELTA`, as
499
+ * the `render_ui` path updates an existing surface.
500
+ * - A lifecycle snapshot (`status: "building"` and so on, no operations)
501
+ * names no surface, so it is consumed. A `failed` one (the agent's
502
+ * recovery gave up) becomes a surface with no operations, status
503
+ * "error", and its error as the one rejected entry, so the chat shows
504
+ * that the UI could not be made. Its surfaceId is the source messageId.
505
+ * Every other event passes through.
506
+ *
507
+ * @example
508
+ * ```ts
509
+ * const upgrader = createA2UIV09ActivityUpgrader();
510
+ * source.pipe(mergeMap((event) => upgrader.transform(event)));
511
+ * ```
512
+ */
513
+ function createA2UIV09ActivityUpgrader() {
514
+ const sources = /* @__PURE__ */ new Map();
515
+ const surfaces = /* @__PURE__ */ new Map();
516
+ /** The source messages whose `failed` snapshot was sent. */
517
+ const failures = /* @__PURE__ */ new Set();
518
+ /** The surface that shows a failed lifecycle snapshot, sent once. */
519
+ const failureOf = (messageId, error) => {
520
+ if (failures.has(messageId)) return [];
521
+ failures.add(messageId);
522
+ const content = {
523
+ surfaceId: messageId,
524
+ target: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
525
+ catalogId: _copilotkit_shared_generative_ui.STANDARD_CATALOG_ID,
526
+ operations: [],
527
+ status: "error",
528
+ rejected: [{
529
+ index: 0,
530
+ reason: error
531
+ }],
532
+ a2uiSourceVersion: "0.9"
533
+ };
534
+ return [{
535
+ type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
536
+ messageId: (0, _copilotkit_shared.generativeUISurfaceMessageId)(messageId),
537
+ activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
538
+ content,
539
+ replace: true
540
+ }];
541
+ };
542
+ const snapshotOf = (surfaceId, state, source, rejected, version) => {
543
+ const operations = clientOperations(state.snapshotSource, state.snapshotOperations, source);
544
+ const create = operations.find((op) => "createSurface" in op);
545
+ const content = {
546
+ surfaceId,
547
+ target: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
548
+ catalogId: create && "createSurface" in create && create.createSurface.catalogId || _copilotkit_shared_generative_ui.STANDARD_CATALOG_ID,
549
+ operations,
550
+ status: "ready",
551
+ rejected,
552
+ ...version === "0.9" ? { a2uiSourceVersion: "0.9" } : {}
553
+ };
554
+ const json = JSON.stringify(content);
555
+ if (json === state.lastSnapshot) return [];
556
+ state.lastSnapshot = json;
557
+ state.snapshotSource = source;
558
+ state.snapshotOperations = operations;
559
+ return [{
560
+ type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
561
+ messageId: (0, _copilotkit_shared.generativeUISurfaceMessageId)(surfaceId),
562
+ activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
563
+ content: (0, _copilotkit_shared.cloneValue)(content),
564
+ replace: true
565
+ }];
566
+ };
567
+ const deltaOf = (surfaceId, state, operations, rejected) => {
568
+ const sent = state.sentOperations;
569
+ let same = 0;
570
+ while (same < sent.length && same < operations.length && JSON.stringify(sent[same]) === JSON.stringify(operations[same])) same++;
571
+ const patch = operations.slice(same).map((op) => ({
572
+ op: "add",
573
+ path: "/operations/-",
574
+ value: (0, _copilotkit_shared.cloneValue)(op)
575
+ }));
576
+ const rejectedJson = JSON.stringify(rejected);
577
+ if (rejectedJson !== state.sentRejected) patch.push({
578
+ op: "replace",
579
+ path: "/rejected",
580
+ value: rejected
581
+ });
582
+ state.sentOperations = operations;
583
+ state.sentRejected = rejectedJson;
584
+ if (patch.length === 0) return [];
585
+ return [{
586
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
587
+ messageId: (0, _copilotkit_shared.generativeUISurfaceMessageId)(surfaceId),
588
+ activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
589
+ patch
590
+ }];
591
+ };
592
+ const emitSurface = (surfaceId) => {
593
+ const state = surfaces.get(surfaceId);
594
+ if (!state) return [];
595
+ const operations = [];
596
+ const rejected = [];
597
+ let created = false;
598
+ let version;
599
+ for (const part of state.parts.values()) {
600
+ for (const { operation, index, version: opVersion } of part.operations) {
601
+ version ??= opVersion;
602
+ if (opVersion !== version) {
603
+ rejected.push({
604
+ index,
605
+ reason: `surface "${surfaceId}" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`
606
+ });
607
+ continue;
608
+ }
609
+ if ("createSurface" in operation) {
610
+ if (created) continue;
611
+ created = true;
612
+ }
613
+ operations.push(operation);
614
+ }
615
+ rejected.push(...part.rejected);
616
+ }
617
+ return created ? snapshotOf(surfaceId, state, operations, rejected, version ?? "0.9") : deltaOf(surfaceId, state, operations, rejected);
618
+ };
619
+ /** Converts the stored content of one source message again. */
620
+ const refresh = (messageId) => {
621
+ const parts = /* @__PURE__ */ new Map();
622
+ readOperations(sources.get(messageId)).forEach((op, index) => {
623
+ const surfaceId = surfaceIdOf(op);
624
+ if (surfaceId === void 0) return;
625
+ let part = parts.get(surfaceId);
626
+ if (!part) {
627
+ part = {
628
+ operations: [],
629
+ rejected: []
630
+ };
631
+ parts.set(surfaceId, part);
632
+ }
633
+ const { operations, dropped } = upgradeA2UIV09Operations([op]);
634
+ const version = require_usage.isRecord(op) && op.version === _copilotkit_shared.A2UI_VERSION ? "1.0" : "0.9";
635
+ for (const operation of operations) part.operations.push({
636
+ operation,
637
+ index,
638
+ version
639
+ });
640
+ for (const { reason } of dropped) part.rejected.push({
641
+ index,
642
+ reason
643
+ });
644
+ });
645
+ const touched = new Set(parts.keys());
646
+ for (const [surfaceId, state] of surfaces) if (!parts.has(surfaceId) && state.parts.delete(messageId)) touched.add(surfaceId);
647
+ for (const [surfaceId, part] of parts) {
648
+ let state = surfaces.get(surfaceId);
649
+ if (!state) {
650
+ state = {
651
+ parts: /* @__PURE__ */ new Map(),
652
+ snapshotSource: [],
653
+ snapshotOperations: [],
654
+ sentOperations: [],
655
+ sentRejected: "[]"
656
+ };
657
+ surfaces.set(surfaceId, state);
658
+ }
659
+ state.parts.set(messageId, part);
660
+ }
661
+ const events = [...touched].flatMap(emitSurface);
662
+ const error = failedLifecycleError(sources.get(messageId));
663
+ return error === void 0 ? events : [...events, ...failureOf(messageId, error)];
664
+ };
665
+ return { transform(event) {
666
+ if (event.type === _ag_ui_client.EventType.ACTIVITY_SNAPSHOT) {
667
+ const snapshot = event;
668
+ if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];
669
+ const { messageId } = snapshot;
670
+ if (snapshot.replace === false && sources.has(messageId)) return [];
671
+ sources.set(messageId, (0, _copilotkit_shared.cloneValue)(snapshot.content));
672
+ return refresh(messageId);
673
+ }
674
+ if (event.type === _ag_ui_client.EventType.ACTIVITY_DELTA) {
675
+ const delta = event;
676
+ if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];
677
+ const { messageId } = delta;
678
+ if (!sources.has(messageId)) return [];
679
+ let content;
680
+ try {
681
+ content = applyJsonPatch((0, _copilotkit_shared.cloneValue)(sources.get(messageId)), delta.patch);
682
+ } catch {
683
+ return [];
684
+ }
685
+ sources.set(messageId, content);
686
+ return refresh(messageId);
687
+ }
688
+ return [event];
689
+ } };
690
+ }
691
+
692
+ //#endregion
693
+ exports.createA2UIV09ActivityUpgrader = createA2UIV09ActivityUpgrader;
694
+ //# sourceMappingURL=a2ui-v09-operations.cjs.map