@copilotkit/runtime 2.0.0-rc.5 → 2.0.0-rc.50

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 +27 -27
  63. package/dist/index.d.cts +15 -15
  64. package/dist/index.d.mts +15 -15
  65. package/dist/index.mjs +9 -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 +3 -2
  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 +24 -13
  93. package/dist/runtime/core/fetch-handler.cjs.map +1 -1
  94. package/dist/runtime/core/fetch-handler.d.cts +35 -14
  95. package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
  96. package/dist/runtime/core/fetch-handler.d.mts +35 -14
  97. package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
  98. package/dist/runtime/core/fetch-handler.mjs +16 -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 +29 -46
  139. package/dist/runtime/core/runtime.cjs.map +1 -1
  140. package/dist/runtime/core/runtime.d.cts +157 -91
  141. package/dist/runtime/core/runtime.d.cts.map +1 -1
  142. package/dist/runtime/core/runtime.d.mts +157 -91
  143. package/dist/runtime/core/runtime.d.mts.map +1 -1
  144. package/dist/runtime/core/runtime.mjs +27 -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 +11 -7
  151. package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
  152. package/dist/runtime/endpoints/node-fetch-handler.d.cts +9 -5
  153. package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
  154. package/dist/runtime/endpoints/node-fetch-handler.d.mts +9 -5
  155. package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
  156. package/dist/runtime/endpoints/node-fetch-handler.mjs +10 -5
  157. package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
  158. package/dist/runtime/endpoints/node.cjs +14 -4
  159. package/dist/runtime/endpoints/node.cjs.map +1 -1
  160. package/dist/runtime/endpoints/node.d.cts +39 -16
  161. package/dist/runtime/endpoints/node.d.cts.map +1 -1
  162. package/dist/runtime/endpoints/node.d.mts +39 -16
  163. package/dist/runtime/endpoints/node.d.mts.map +1 -1
  164. package/dist/runtime/endpoints/node.mjs +16 -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.cjs +29 -0
  308. package/dist/runtime/index.cjs.map +1 -0
  309. package/dist/runtime/index.d.cts +61 -15
  310. package/dist/runtime/index.d.cts.map +1 -1
  311. package/dist/runtime/index.d.mts +61 -15
  312. package/dist/runtime/index.d.mts.map +1 -1
  313. package/dist/runtime/index.mjs +27 -0
  314. package/dist/runtime/index.mjs.map +1 -0
  315. package/dist/runtime/intelligence-platform/analytics-context.cjs +84 -0
  316. package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -0
  317. package/dist/runtime/intelligence-platform/analytics-context.mjs +83 -0
  318. package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -0
  319. package/dist/runtime/intelligence-platform/client.cjs +30 -4
  320. package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
  321. package/dist/runtime/intelligence-platform/client.d.cts +25 -2
  322. package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
  323. package/dist/runtime/intelligence-platform/client.d.mts +25 -2
  324. package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
  325. package/dist/runtime/intelligence-platform/client.mjs +30 -3
  326. package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
  327. package/dist/runtime/intelligence-platform/learning-management.cjs +7 -8
  328. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
  329. package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
  330. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
  331. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -110
  332. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
  333. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
  334. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
  335. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
  336. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
  337. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
  338. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
  339. package/dist/runtime/intelligence-platform/skill-registry/config.cjs +0 -1
  340. package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
  341. package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +1 -1
  342. package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +1 -1
  343. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +22 -19
  344. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
  345. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
  346. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
  347. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +22 -19
  348. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
  349. package/dist/runtime/intelligence-platform/stop-run.cjs +50 -0
  350. package/dist/runtime/intelligence-platform/stop-run.cjs.map +1 -0
  351. package/dist/runtime/intelligence-platform/stop-run.mjs +50 -0
  352. package/dist/runtime/intelligence-platform/stop-run.mjs.map +1 -0
  353. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +3 -3
  354. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
  355. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +2 -1
  356. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -1
  357. package/dist/runtime/intelligence-platform/trajectories.cjs +2 -3
  358. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
  359. package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
  360. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
  361. package/dist/runtime/node.d.cts +2 -2
  362. package/dist/runtime/node.d.mts +2 -2
  363. package/dist/runtime/runner/agent-runner.cjs +0 -1
  364. package/dist/runtime/runner/agent-runner.cjs.map +1 -1
  365. package/dist/runtime/runner/agent-runner.d.cts +9 -0
  366. package/dist/runtime/runner/agent-runner.d.cts.map +1 -1
  367. package/dist/runtime/runner/agent-runner.d.mts +9 -0
  368. package/dist/runtime/runner/agent-runner.d.mts.map +1 -1
  369. package/dist/runtime/runner/agent-runner.mjs.map +1 -1
  370. package/dist/runtime/runner/in-memory.cjs +0 -1
  371. package/dist/runtime/runner/in-memory.cjs.map +1 -1
  372. package/dist/runtime/runner/index.d.cts +1 -1
  373. package/dist/runtime/runner/index.d.mts +1 -1
  374. package/dist/runtime/runner/index.mjs +1 -1
  375. package/dist/runtime/runner/intelligence.cjs +55 -9
  376. package/dist/runtime/runner/intelligence.cjs.map +1 -1
  377. package/dist/runtime/runner/intelligence.d.cts +12 -1
  378. package/dist/runtime/runner/intelligence.d.cts.map +1 -1
  379. package/dist/runtime/runner/intelligence.d.mts +12 -1
  380. package/dist/runtime/runner/intelligence.d.mts.map +1 -1
  381. package/dist/runtime/runner/intelligence.mjs +56 -10
  382. package/dist/runtime/runner/intelligence.mjs.map +1 -1
  383. package/dist/runtime/telemetry/disclosure.cjs +2 -3
  384. package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
  385. package/dist/runtime/telemetry/disclosure.mjs +3 -3
  386. package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
  387. package/dist/runtime/telemetry/events.d.cts +1 -1
  388. package/dist/runtime/telemetry/events.d.mts +1 -1
  389. package/dist/runtime/telemetry/instance-created.cjs +33 -12
  390. package/dist/runtime/telemetry/instance-created.cjs.map +1 -1
  391. package/dist/runtime/telemetry/instance-created.mjs +33 -12
  392. package/dist/runtime/telemetry/instance-created.mjs.map +1 -1
  393. package/dist/runtime/telemetry/telemetry-client.cjs +0 -5
  394. package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
  395. package/dist/runtime/telemetry/telemetry-client.mjs +0 -4
  396. package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
  397. package/dist/runtime/telemetry/telemetry-identity.cjs +0 -1
  398. package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -1
  399. package/package.json +54 -29
  400. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  401. package/dist/agent/converters/index.d.mts +0 -2
  402. package/dist/agent/index.cjs +0 -1328
  403. package/dist/agent/index.cjs.map +0 -1
  404. package/dist/agent/index.d.cts +0 -467
  405. package/dist/agent/index.d.cts.map +0 -1
  406. package/dist/agent/index.d.mts +0 -468
  407. package/dist/agent/index.d.mts.map +0 -1
  408. package/dist/agent/index.mjs +0 -1318
  409. package/dist/agent/index.mjs.map +0 -1
  410. package/dist/agent/mcp-tool-names.cjs +0 -82
  411. package/dist/agent/mcp-tool-names.cjs.map +0 -1
  412. package/dist/agent/mcp-tool-names.mjs +0 -80
  413. package/dist/agent/mcp-tool-names.mjs.map +0 -1
  414. package/dist/agent/url-download.cjs.map +0 -1
  415. package/dist/agent/url-download.d.cts.map +0 -1
  416. package/dist/agent/url-download.d.mts.map +0 -1
  417. package/dist/agent/url-download.mjs.map +0 -1
@@ -0,0 +1,106 @@
1
+ const require_usage = require('../../agent/converters/usage.cjs');
2
+ let _copilotkit_shared = require("@copilotkit/shared");
3
+
4
+ //#region src/runtime/generative-ui/a2ui-v09-actions.ts
5
+ /** The 1.0 action of the user event that started the run, if one did. */
6
+ function readAction(envelope) {
7
+ const message = envelope?.metadata.extensions.copilotkit_action;
8
+ if (!require_usage.isRecord(message) || !require_usage.isRecord(message.action)) return void 0;
9
+ const { name, surfaceId, sourceComponentId, context, timestamp } = message.action;
10
+ if (typeof name !== "string" || typeof surfaceId !== "string") return;
11
+ return {
12
+ name,
13
+ surfaceId,
14
+ sourceComponentId: typeof sourceComponentId === "string" ? sourceComponentId : "",
15
+ context: require_usage.isRecord(context) ? context : {},
16
+ timestamp: typeof timestamp === "string" ? timestamp : (/* @__PURE__ */ new Date()).toISOString()
17
+ };
18
+ }
19
+ /**
20
+ * True when the surface was converted from A2UI v0.9. The first of these
21
+ * that knows the surface decides:
22
+ * 1. The summary of the surface in the envelope (`copilotkit_surfaces`).
23
+ * 2. The last `generative-ui-surface` activity message of the surface.
24
+ * 3. `agentVersion`.
25
+ */
26
+ function isV09Surface(surfaces, messages, surfaceId, agentVersion) {
27
+ if (Object.hasOwn(surfaces, surfaceId)) return surfaces[surfaceId].a2uiSourceVersion === "0.9";
28
+ const surface = messages.findLast((message) => message.role === "activity" && message.activityType === _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE && require_usage.isRecord(message.content) && message.content.surfaceId === surfaceId);
29
+ if (!surface) return agentVersion === "0.9";
30
+ return surface.content?.a2uiSourceVersion === "0.9";
31
+ }
32
+ /**
33
+ * Removes the visible user message that the 1.0 client added for the click.
34
+ * The client adds it just before the run, so it is the last message.
35
+ */
36
+ function withoutActionUserMessage(messages) {
37
+ const last = messages.at(-1);
38
+ if (last?.role !== "user" || typeof last.content !== "string") return messages;
39
+ return messages.slice(0, -1);
40
+ }
41
+ /**
42
+ * Turns a click on a surface that the runtime converted from A2UI v0.9 into
43
+ * the v0.9 action that the agent side expects.
44
+ *
45
+ * The 1.0 client sends a click as a visible user message plus
46
+ * `forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_action`. A v0.9
47
+ * agent stack reads `forwardedProps.a2uiAction.userAction` instead. When the
48
+ * run carries a 1.0 action for a surface of v0.9 origin, this returns a new
49
+ * input with `forwardedProps.a2uiAction` set and the visible user message
50
+ * removed. Otherwise it returns `input` unchanged. It never mutates `input`.
51
+ *
52
+ * The visible user message is removed because the v0.9 consumers already
53
+ * turn `a2uiAction` into what the agent sees:
54
+ * - `@ag-ui/a2ui-middleware` appends the action as a private user message,
55
+ * `A2UI user action:` and the action JSON. The Python, Go, Ruby and .NET
56
+ * runtimes append a synthetic `log_a2ui_event` tool call and result, and
57
+ * prompt the model to answer them when they end the conversation. With
58
+ * the visible message kept, the model sees the click twice, and the
59
+ * conversation no longer ends with the action.
60
+ * - `@ag-ui/a2a` attaches `a2uiAction` as a data part to the latest user
61
+ * message, and A2A agents read the data part first.
62
+ * The v0.9 client sent no user message for a click, so with it removed the
63
+ * agent gets the same input as it did from the v0.9 client. The 1.0 client
64
+ * still shows the message in its chat.
65
+ *
66
+ * Origin: the first of these that knows the clicked surface decides.
67
+ * 1. Its summary in the envelope
68
+ * (`forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_surfaces`):
69
+ * `a2uiSourceVersion === "0.9"` means v0.9 origin, left out means 1.0. The
70
+ * 1.0 client copies the tag from the surface's activity content, so this
71
+ * is what decides for runs from the 1.0 client.
72
+ * 2. The last `generative-ui-surface` activity message for the surface in
73
+ * `input.messages` (`a2uiSourceVersion === "0.9"`), for a caller that
74
+ * passes activity messages.
75
+ * 3. `options.agentVersion === "0.9"`.
76
+ *
77
+ * @param input - The run input from the 1.0 client.
78
+ * @param options - `agentVersion`: the fallback when the surface is unknown.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const agentInput = downgradeA2UIV09Action(input, { agentVersion: "0.9" });
83
+ * // agentInput.forwardedProps.a2uiAction.userAction:
84
+ * // { name, surfaceId, sourceComponentId, context, timestamp }
85
+ * ```
86
+ */
87
+ function downgradeA2UIV09Action(input, options = {}) {
88
+ const forwardedProps = input.forwardedProps;
89
+ if (!require_usage.isRecord(forwardedProps) || forwardedProps.a2uiAction !== void 0) return input;
90
+ const envelope = (0, _copilotkit_shared.readCopilotKitUIEnvelope)(forwardedProps);
91
+ const userAction = readAction(envelope);
92
+ if (!envelope || !userAction) return input;
93
+ if (!isV09Surface(envelope.metadata.extensions.copilotkit_surfaces, input.messages, userAction.surfaceId, options.agentVersion)) return input;
94
+ return {
95
+ ...input,
96
+ messages: withoutActionUserMessage(input.messages),
97
+ forwardedProps: {
98
+ ...forwardedProps,
99
+ a2uiAction: { userAction }
100
+ }
101
+ };
102
+ }
103
+
104
+ //#endregion
105
+ exports.downgradeA2UIV09Action = downgradeA2UIV09Action;
106
+ //# sourceMappingURL=a2ui-v09-actions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-v09-actions.cjs","names":["isRecord","GENERATIVE_UI_ACTIVITY_TYPE"],"sources":["../../../src/runtime/generative-ui/a2ui-v09-actions.ts"],"sourcesContent":["import type { Message, RunAgentInput } from \"@ag-ui/client\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n readCopilotKitUIEnvelope,\n} from \"@copilotkit/shared\";\nimport type { CopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The A2UI v0.9 user action, as the v0.9 client sent it in\n * `forwardedProps.a2uiAction.userAction`. `@ag-ui/a2ui-middleware`,\n * `@ag-ui/a2a` and the CopilotKit runtimes in other languages read this shape.\n */\ninterface A2UIV09UserAction {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n context: Record<string, unknown>;\n timestamp: string;\n}\n\nexport interface DowngradeA2UIV09ActionOptions {\n /**\n * The A2UI version the agent speaks. Used only when neither the envelope\n * summary nor `input.messages` knows the clicked surface.\n */\n agentVersion?: \"0.9\" | \"1.0\";\n}\n\n/** The 1.0 action of the user event that started the run, if one did. */\nfunction readAction(\n envelope: CopilotKitUIEnvelope | undefined,\n): A2UIV09UserAction | undefined {\n const message: unknown = envelope?.metadata.extensions.copilotkit_action;\n if (!isRecord(message) || !isRecord(message.action)) return undefined;\n const { name, surfaceId, sourceComponentId, context, timestamp } =\n message.action;\n if (typeof name !== \"string\" || typeof surfaceId !== \"string\") {\n return undefined;\n }\n return {\n name,\n surfaceId,\n sourceComponentId:\n typeof sourceComponentId === \"string\" ? sourceComponentId : \"\",\n context: isRecord(context) ? context : {},\n timestamp:\n typeof timestamp === \"string\" ? timestamp : new Date().toISOString(),\n };\n}\n\n/**\n * True when the surface was converted from A2UI v0.9. The first of these\n * that knows the surface decides:\n * 1. The summary of the surface in the envelope (`copilotkit_surfaces`).\n * 2. The last `generative-ui-surface` activity message of the surface.\n * 3. `agentVersion`.\n */\nfunction isV09Surface(\n surfaces: CopilotKitUIEnvelope[\"metadata\"][\"extensions\"][\"copilotkit_surfaces\"],\n messages: readonly Message[],\n surfaceId: string,\n agentVersion: DowngradeA2UIV09ActionOptions[\"agentVersion\"],\n) {\n // `readCopilotKitUIEnvelope` checked the summary, so the tag is \"0.9\" or\n // left out. An own-key check: the ids come from the client.\n if (Object.hasOwn(surfaces, surfaceId)) {\n return surfaces[surfaceId].a2uiSourceVersion === \"0.9\";\n }\n const surface = messages.findLast(\n (message) =>\n message.role === \"activity\" &&\n message.activityType === GENERATIVE_UI_ACTIVITY_TYPE &&\n isRecord(message.content) &&\n message.content.surfaceId === surfaceId,\n );\n if (!surface) return agentVersion === \"0.9\";\n // `a2uiSourceVersion` is set by the runtime on surfaces it converted from\n // v0.9. Read it untyped: not every surface content has it.\n const content = (surface as { content?: { a2uiSourceVersion?: unknown } })\n .content;\n return content?.a2uiSourceVersion === \"0.9\";\n}\n\n/**\n * Removes the visible user message that the 1.0 client added for the click.\n * The client adds it just before the run, so it is the last message.\n */\nfunction withoutActionUserMessage(messages: Message[]) {\n const last = messages.at(-1);\n if (last?.role !== \"user\" || typeof last.content !== \"string\") {\n return messages;\n }\n return messages.slice(0, -1);\n}\n\n/**\n * Turns a click on a surface that the runtime converted from A2UI v0.9 into\n * the v0.9 action that the agent side expects.\n *\n * The 1.0 client sends a click as a visible user message plus\n * `forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_action`. A v0.9\n * agent stack reads `forwardedProps.a2uiAction.userAction` instead. When the\n * run carries a 1.0 action for a surface of v0.9 origin, this returns a new\n * input with `forwardedProps.a2uiAction` set and the visible user message\n * removed. Otherwise it returns `input` unchanged. It never mutates `input`.\n *\n * The visible user message is removed because the v0.9 consumers already\n * turn `a2uiAction` into what the agent sees:\n * - `@ag-ui/a2ui-middleware` appends the action as a private user message,\n * `A2UI user action:` and the action JSON. The Python, Go, Ruby and .NET\n * runtimes append a synthetic `log_a2ui_event` tool call and result, and\n * prompt the model to answer them when they end the conversation. With\n * the visible message kept, the model sees the click twice, and the\n * conversation no longer ends with the action.\n * - `@ag-ui/a2a` attaches `a2uiAction` as a data part to the latest user\n * message, and A2A agents read the data part first.\n * The v0.9 client sent no user message for a click, so with it removed the\n * agent gets the same input as it did from the v0.9 client. The 1.0 client\n * still shows the message in its chat.\n *\n * Origin: the first of these that knows the clicked surface decides.\n * 1. Its summary in the envelope\n * (`forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_surfaces`):\n * `a2uiSourceVersion === \"0.9\"` means v0.9 origin, left out means 1.0. The\n * 1.0 client copies the tag from the surface's activity content, so this\n * is what decides for runs from the 1.0 client.\n * 2. The last `generative-ui-surface` activity message for the surface in\n * `input.messages` (`a2uiSourceVersion === \"0.9\"`), for a caller that\n * passes activity messages.\n * 3. `options.agentVersion === \"0.9\"`.\n *\n * @param input - The run input from the 1.0 client.\n * @param options - `agentVersion`: the fallback when the surface is unknown.\n *\n * @example\n * ```ts\n * const agentInput = downgradeA2UIV09Action(input, { agentVersion: \"0.9\" });\n * // agentInput.forwardedProps.a2uiAction.userAction:\n * // { name, surfaceId, sourceComponentId, context, timestamp }\n * ```\n */\nexport function downgradeA2UIV09Action(\n input: RunAgentInput,\n options: DowngradeA2UIV09ActionOptions = {},\n): RunAgentInput {\n const forwardedProps: unknown = input.forwardedProps;\n // A run that already has a v0.9 action keeps it.\n if (!isRecord(forwardedProps) || forwardedProps.a2uiAction !== undefined) {\n return input;\n }\n const envelope = readCopilotKitUIEnvelope(forwardedProps);\n const userAction = readAction(envelope);\n if (!envelope || !userAction) return input;\n if (\n !isV09Surface(\n envelope.metadata.extensions.copilotkit_surfaces,\n input.messages,\n userAction.surfaceId,\n options.agentVersion,\n )\n ) {\n return input;\n }\n return {\n ...input,\n messages: withoutActionUserMessage(input.messages),\n forwardedProps: { ...forwardedProps, a2uiAction: { userAction } },\n };\n}\n"],"mappings":";;;;;AA8BA,SAAS,WACP,UAC+B;CAC/B,MAAM,UAAmB,UAAU,SAAS,WAAW;AACvD,KAAI,CAACA,uBAAS,QAAQ,IAAI,CAACA,uBAAS,QAAQ,OAAO,CAAE,QAAO;CAC5D,MAAM,EAAE,MAAM,WAAW,mBAAmB,SAAS,cACnD,QAAQ;AACV,KAAI,OAAO,SAAS,YAAY,OAAO,cAAc,SACnD;AAEF,QAAO;EACL;EACA;EACA,mBACE,OAAO,sBAAsB,WAAW,oBAAoB;EAC9D,SAASA,uBAAS,QAAQ,GAAG,UAAU,EAAE;EACzC,WACE,OAAO,cAAc,WAAW,6BAAY,IAAI,MAAM,EAAC,aAAa;EACvE;;;;;;;;;AAUH,SAAS,aACP,UACA,UACA,WACA,cACA;AAGA,KAAI,OAAO,OAAO,UAAU,UAAU,CACpC,QAAO,SAAS,WAAW,sBAAsB;CAEnD,MAAM,UAAU,SAAS,UACtB,YACC,QAAQ,SAAS,cACjB,QAAQ,iBAAiBC,kDACzBD,uBAAS,QAAQ,QAAQ,IACzB,QAAQ,QAAQ,cAAc,UACjC;AACD,KAAI,CAAC,QAAS,QAAO,iBAAiB;AAKtC,QAFiB,QACd,SACa,sBAAsB;;;;;;AAOxC,SAAS,yBAAyB,UAAqB;CACrD,MAAM,OAAO,SAAS,GAAG,GAAG;AAC5B,KAAI,MAAM,SAAS,UAAU,OAAO,KAAK,YAAY,SACnD,QAAO;AAET,QAAO,SAAS,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiD9B,SAAgB,uBACd,OACA,UAAyC,EAAE,EAC5B;CACf,MAAM,iBAA0B,MAAM;AAEtC,KAAI,CAACA,uBAAS,eAAe,IAAI,eAAe,eAAe,OAC7D,QAAO;CAET,MAAM,4DAAoC,eAAe;CACzD,MAAM,aAAa,WAAW,SAAS;AACvC,KAAI,CAAC,YAAY,CAAC,WAAY,QAAO;AACrC,KACE,CAAC,aACC,SAAS,SAAS,WAAW,qBAC7B,MAAM,UACN,WAAW,WACX,QAAQ,aACT,CAED,QAAO;AAET,QAAO;EACL,GAAG;EACH,UAAU,yBAAyB,MAAM,SAAS;EAClD,gBAAgB;GAAE,GAAG;GAAgB,YAAY,EAAE,YAAY;GAAE;EAClE"}
@@ -0,0 +1,106 @@
1
+ import { isRecord } from "../../agent/converters/usage.mjs";
2
+ import { GENERATIVE_UI_ACTIVITY_TYPE, readCopilotKitUIEnvelope } from "@copilotkit/shared";
3
+
4
+ //#region src/runtime/generative-ui/a2ui-v09-actions.ts
5
+ /** The 1.0 action of the user event that started the run, if one did. */
6
+ function readAction(envelope) {
7
+ const message = envelope?.metadata.extensions.copilotkit_action;
8
+ if (!isRecord(message) || !isRecord(message.action)) return void 0;
9
+ const { name, surfaceId, sourceComponentId, context, timestamp } = message.action;
10
+ if (typeof name !== "string" || typeof surfaceId !== "string") return;
11
+ return {
12
+ name,
13
+ surfaceId,
14
+ sourceComponentId: typeof sourceComponentId === "string" ? sourceComponentId : "",
15
+ context: isRecord(context) ? context : {},
16
+ timestamp: typeof timestamp === "string" ? timestamp : (/* @__PURE__ */ new Date()).toISOString()
17
+ };
18
+ }
19
+ /**
20
+ * True when the surface was converted from A2UI v0.9. The first of these
21
+ * that knows the surface decides:
22
+ * 1. The summary of the surface in the envelope (`copilotkit_surfaces`).
23
+ * 2. The last `generative-ui-surface` activity message of the surface.
24
+ * 3. `agentVersion`.
25
+ */
26
+ function isV09Surface(surfaces, messages, surfaceId, agentVersion) {
27
+ if (Object.hasOwn(surfaces, surfaceId)) return surfaces[surfaceId].a2uiSourceVersion === "0.9";
28
+ const surface = messages.findLast((message) => message.role === "activity" && message.activityType === GENERATIVE_UI_ACTIVITY_TYPE && isRecord(message.content) && message.content.surfaceId === surfaceId);
29
+ if (!surface) return agentVersion === "0.9";
30
+ return surface.content?.a2uiSourceVersion === "0.9";
31
+ }
32
+ /**
33
+ * Removes the visible user message that the 1.0 client added for the click.
34
+ * The client adds it just before the run, so it is the last message.
35
+ */
36
+ function withoutActionUserMessage(messages) {
37
+ const last = messages.at(-1);
38
+ if (last?.role !== "user" || typeof last.content !== "string") return messages;
39
+ return messages.slice(0, -1);
40
+ }
41
+ /**
42
+ * Turns a click on a surface that the runtime converted from A2UI v0.9 into
43
+ * the v0.9 action that the agent side expects.
44
+ *
45
+ * The 1.0 client sends a click as a visible user message plus
46
+ * `forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_action`. A v0.9
47
+ * agent stack reads `forwardedProps.a2uiAction.userAction` instead. When the
48
+ * run carries a 1.0 action for a surface of v0.9 origin, this returns a new
49
+ * input with `forwardedProps.a2uiAction` set and the visible user message
50
+ * removed. Otherwise it returns `input` unchanged. It never mutates `input`.
51
+ *
52
+ * The visible user message is removed because the v0.9 consumers already
53
+ * turn `a2uiAction` into what the agent sees:
54
+ * - `@ag-ui/a2ui-middleware` appends the action as a private user message,
55
+ * `A2UI user action:` and the action JSON. The Python, Go, Ruby and .NET
56
+ * runtimes append a synthetic `log_a2ui_event` tool call and result, and
57
+ * prompt the model to answer them when they end the conversation. With
58
+ * the visible message kept, the model sees the click twice, and the
59
+ * conversation no longer ends with the action.
60
+ * - `@ag-ui/a2a` attaches `a2uiAction` as a data part to the latest user
61
+ * message, and A2A agents read the data part first.
62
+ * The v0.9 client sent no user message for a click, so with it removed the
63
+ * agent gets the same input as it did from the v0.9 client. The 1.0 client
64
+ * still shows the message in its chat.
65
+ *
66
+ * Origin: the first of these that knows the clicked surface decides.
67
+ * 1. Its summary in the envelope
68
+ * (`forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_surfaces`):
69
+ * `a2uiSourceVersion === "0.9"` means v0.9 origin, left out means 1.0. The
70
+ * 1.0 client copies the tag from the surface's activity content, so this
71
+ * is what decides for runs from the 1.0 client.
72
+ * 2. The last `generative-ui-surface` activity message for the surface in
73
+ * `input.messages` (`a2uiSourceVersion === "0.9"`), for a caller that
74
+ * passes activity messages.
75
+ * 3. `options.agentVersion === "0.9"`.
76
+ *
77
+ * @param input - The run input from the 1.0 client.
78
+ * @param options - `agentVersion`: the fallback when the surface is unknown.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const agentInput = downgradeA2UIV09Action(input, { agentVersion: "0.9" });
83
+ * // agentInput.forwardedProps.a2uiAction.userAction:
84
+ * // { name, surfaceId, sourceComponentId, context, timestamp }
85
+ * ```
86
+ */
87
+ function downgradeA2UIV09Action(input, options = {}) {
88
+ const forwardedProps = input.forwardedProps;
89
+ if (!isRecord(forwardedProps) || forwardedProps.a2uiAction !== void 0) return input;
90
+ const envelope = readCopilotKitUIEnvelope(forwardedProps);
91
+ const userAction = readAction(envelope);
92
+ if (!envelope || !userAction) return input;
93
+ if (!isV09Surface(envelope.metadata.extensions.copilotkit_surfaces, input.messages, userAction.surfaceId, options.agentVersion)) return input;
94
+ return {
95
+ ...input,
96
+ messages: withoutActionUserMessage(input.messages),
97
+ forwardedProps: {
98
+ ...forwardedProps,
99
+ a2uiAction: { userAction }
100
+ }
101
+ };
102
+ }
103
+
104
+ //#endregion
105
+ export { downgradeA2UIV09Action };
106
+ //# sourceMappingURL=a2ui-v09-actions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-v09-actions.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-actions.ts"],"sourcesContent":["import type { Message, RunAgentInput } from \"@ag-ui/client\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n readCopilotKitUIEnvelope,\n} from \"@copilotkit/shared\";\nimport type { CopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The A2UI v0.9 user action, as the v0.9 client sent it in\n * `forwardedProps.a2uiAction.userAction`. `@ag-ui/a2ui-middleware`,\n * `@ag-ui/a2a` and the CopilotKit runtimes in other languages read this shape.\n */\ninterface A2UIV09UserAction {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n context: Record<string, unknown>;\n timestamp: string;\n}\n\nexport interface DowngradeA2UIV09ActionOptions {\n /**\n * The A2UI version the agent speaks. Used only when neither the envelope\n * summary nor `input.messages` knows the clicked surface.\n */\n agentVersion?: \"0.9\" | \"1.0\";\n}\n\n/** The 1.0 action of the user event that started the run, if one did. */\nfunction readAction(\n envelope: CopilotKitUIEnvelope | undefined,\n): A2UIV09UserAction | undefined {\n const message: unknown = envelope?.metadata.extensions.copilotkit_action;\n if (!isRecord(message) || !isRecord(message.action)) return undefined;\n const { name, surfaceId, sourceComponentId, context, timestamp } =\n message.action;\n if (typeof name !== \"string\" || typeof surfaceId !== \"string\") {\n return undefined;\n }\n return {\n name,\n surfaceId,\n sourceComponentId:\n typeof sourceComponentId === \"string\" ? sourceComponentId : \"\",\n context: isRecord(context) ? context : {},\n timestamp:\n typeof timestamp === \"string\" ? timestamp : new Date().toISOString(),\n };\n}\n\n/**\n * True when the surface was converted from A2UI v0.9. The first of these\n * that knows the surface decides:\n * 1. The summary of the surface in the envelope (`copilotkit_surfaces`).\n * 2. The last `generative-ui-surface` activity message of the surface.\n * 3. `agentVersion`.\n */\nfunction isV09Surface(\n surfaces: CopilotKitUIEnvelope[\"metadata\"][\"extensions\"][\"copilotkit_surfaces\"],\n messages: readonly Message[],\n surfaceId: string,\n agentVersion: DowngradeA2UIV09ActionOptions[\"agentVersion\"],\n) {\n // `readCopilotKitUIEnvelope` checked the summary, so the tag is \"0.9\" or\n // left out. An own-key check: the ids come from the client.\n if (Object.hasOwn(surfaces, surfaceId)) {\n return surfaces[surfaceId].a2uiSourceVersion === \"0.9\";\n }\n const surface = messages.findLast(\n (message) =>\n message.role === \"activity\" &&\n message.activityType === GENERATIVE_UI_ACTIVITY_TYPE &&\n isRecord(message.content) &&\n message.content.surfaceId === surfaceId,\n );\n if (!surface) return agentVersion === \"0.9\";\n // `a2uiSourceVersion` is set by the runtime on surfaces it converted from\n // v0.9. Read it untyped: not every surface content has it.\n const content = (surface as { content?: { a2uiSourceVersion?: unknown } })\n .content;\n return content?.a2uiSourceVersion === \"0.9\";\n}\n\n/**\n * Removes the visible user message that the 1.0 client added for the click.\n * The client adds it just before the run, so it is the last message.\n */\nfunction withoutActionUserMessage(messages: Message[]) {\n const last = messages.at(-1);\n if (last?.role !== \"user\" || typeof last.content !== \"string\") {\n return messages;\n }\n return messages.slice(0, -1);\n}\n\n/**\n * Turns a click on a surface that the runtime converted from A2UI v0.9 into\n * the v0.9 action that the agent side expects.\n *\n * The 1.0 client sends a click as a visible user message plus\n * `forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_action`. A v0.9\n * agent stack reads `forwardedProps.a2uiAction.userAction` instead. When the\n * run carries a 1.0 action for a surface of v0.9 origin, this returns a new\n * input with `forwardedProps.a2uiAction` set and the visible user message\n * removed. Otherwise it returns `input` unchanged. It never mutates `input`.\n *\n * The visible user message is removed because the v0.9 consumers already\n * turn `a2uiAction` into what the agent sees:\n * - `@ag-ui/a2ui-middleware` appends the action as a private user message,\n * `A2UI user action:` and the action JSON. The Python, Go, Ruby and .NET\n * runtimes append a synthetic `log_a2ui_event` tool call and result, and\n * prompt the model to answer them when they end the conversation. With\n * the visible message kept, the model sees the click twice, and the\n * conversation no longer ends with the action.\n * - `@ag-ui/a2a` attaches `a2uiAction` as a data part to the latest user\n * message, and A2A agents read the data part first.\n * The v0.9 client sent no user message for a click, so with it removed the\n * agent gets the same input as it did from the v0.9 client. The 1.0 client\n * still shows the message in its chat.\n *\n * Origin: the first of these that knows the clicked surface decides.\n * 1. Its summary in the envelope\n * (`forwardedProps.copilotkit.ui.metadata.extensions.copilotkit_surfaces`):\n * `a2uiSourceVersion === \"0.9\"` means v0.9 origin, left out means 1.0. The\n * 1.0 client copies the tag from the surface's activity content, so this\n * is what decides for runs from the 1.0 client.\n * 2. The last `generative-ui-surface` activity message for the surface in\n * `input.messages` (`a2uiSourceVersion === \"0.9\"`), for a caller that\n * passes activity messages.\n * 3. `options.agentVersion === \"0.9\"`.\n *\n * @param input - The run input from the 1.0 client.\n * @param options - `agentVersion`: the fallback when the surface is unknown.\n *\n * @example\n * ```ts\n * const agentInput = downgradeA2UIV09Action(input, { agentVersion: \"0.9\" });\n * // agentInput.forwardedProps.a2uiAction.userAction:\n * // { name, surfaceId, sourceComponentId, context, timestamp }\n * ```\n */\nexport function downgradeA2UIV09Action(\n input: RunAgentInput,\n options: DowngradeA2UIV09ActionOptions = {},\n): RunAgentInput {\n const forwardedProps: unknown = input.forwardedProps;\n // A run that already has a v0.9 action keeps it.\n if (!isRecord(forwardedProps) || forwardedProps.a2uiAction !== undefined) {\n return input;\n }\n const envelope = readCopilotKitUIEnvelope(forwardedProps);\n const userAction = readAction(envelope);\n if (!envelope || !userAction) return input;\n if (\n !isV09Surface(\n envelope.metadata.extensions.copilotkit_surfaces,\n input.messages,\n userAction.surfaceId,\n options.agentVersion,\n )\n ) {\n return input;\n }\n return {\n ...input,\n messages: withoutActionUserMessage(input.messages),\n forwardedProps: { ...forwardedProps, a2uiAction: { userAction } },\n };\n}\n"],"mappings":";;;;;AA8BA,SAAS,WACP,UAC+B;CAC/B,MAAM,UAAmB,UAAU,SAAS,WAAW;AACvD,KAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,SAAS,QAAQ,OAAO,CAAE,QAAO;CAC5D,MAAM,EAAE,MAAM,WAAW,mBAAmB,SAAS,cACnD,QAAQ;AACV,KAAI,OAAO,SAAS,YAAY,OAAO,cAAc,SACnD;AAEF,QAAO;EACL;EACA;EACA,mBACE,OAAO,sBAAsB,WAAW,oBAAoB;EAC9D,SAAS,SAAS,QAAQ,GAAG,UAAU,EAAE;EACzC,WACE,OAAO,cAAc,WAAW,6BAAY,IAAI,MAAM,EAAC,aAAa;EACvE;;;;;;;;;AAUH,SAAS,aACP,UACA,UACA,WACA,cACA;AAGA,KAAI,OAAO,OAAO,UAAU,UAAU,CACpC,QAAO,SAAS,WAAW,sBAAsB;CAEnD,MAAM,UAAU,SAAS,UACtB,YACC,QAAQ,SAAS,cACjB,QAAQ,iBAAiB,+BACzB,SAAS,QAAQ,QAAQ,IACzB,QAAQ,QAAQ,cAAc,UACjC;AACD,KAAI,CAAC,QAAS,QAAO,iBAAiB;AAKtC,QAFiB,QACd,SACa,sBAAsB;;;;;;AAOxC,SAAS,yBAAyB,UAAqB;CACrD,MAAM,OAAO,SAAS,GAAG,GAAG;AAC5B,KAAI,MAAM,SAAS,UAAU,OAAO,KAAK,YAAY,SACnD,QAAO;AAET,QAAO,SAAS,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiD9B,SAAgB,uBACd,OACA,UAAyC,EAAE,EAC5B;CACf,MAAM,iBAA0B,MAAM;AAEtC,KAAI,CAAC,SAAS,eAAe,IAAI,eAAe,eAAe,OAC7D,QAAO;CAET,MAAM,WAAW,yBAAyB,eAAe;CACzD,MAAM,aAAa,WAAW,SAAS;AACvC,KAAI,CAAC,YAAY,CAAC,WAAY,QAAO;AACrC,KACE,CAAC,aACC,SAAS,SAAS,WAAW,qBAC7B,MAAM,UACN,WAAW,WACX,QAAQ,aACT,CAED,QAAO;AAET,QAAO;EACL,GAAG;EACH,UAAU,yBAAyB,MAAM,SAAS;EAClD,gBAAgB;GAAE,GAAG;GAAgB,YAAY,EAAE,YAAY;GAAE;EAClE"}
@@ -0,0 +1,422 @@
1
+ let _copilotkit_shared = require("@copilotkit/shared");
2
+ let _ag_ui_a2ui_middleware = require("@ag-ui/a2ui-middleware");
3
+ let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
4
+
5
+ //#region src/runtime/generative-ui/a2ui-v09-catalog.ts
6
+ /** Id of the A2UI v0.9 basic catalog. */
7
+ const A2UI_V09_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
8
+ const CAPABILITIES_CONTEXT_DESCRIPTION = "A2UI catalog capabilities: available catalog IDs and custom component definitions the client can render.";
9
+ const GENERATION_GUIDELINES_CONTEXT_DESCRIPTION = "A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.";
10
+ const DESIGN_GUIDELINES_CONTEXT_DESCRIPTION = "A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.";
11
+ /** The components of the v0.9 basic catalog. The 1.0 standard catalog has each of them. */
12
+ const V09_BASIC_COMPONENTS = new Set([
13
+ "Text",
14
+ "Image",
15
+ "Icon",
16
+ "Video",
17
+ "AudioPlayer",
18
+ "Row",
19
+ "Column",
20
+ "List",
21
+ "Card",
22
+ "Tabs",
23
+ "Modal",
24
+ "Divider",
25
+ "Button",
26
+ "TextField",
27
+ "CheckBox",
28
+ "ChoicePicker",
29
+ "Slider",
30
+ "DateTimeInput"
31
+ ]);
32
+ /**
33
+ * The props (and events and slots) of standard components that v0.9 names
34
+ * differently: component → 1.0 name → v0.9 name. Every other prop has the
35
+ * same name in both versions.
36
+ */
37
+ const V10_TO_V09_PROP_NAMES = { Button: { onClick: "action" } };
38
+ const COMMON = "common_types.json#/$defs/";
39
+ const ref = (name) => ({ $ref: `${COMMON}${name}` });
40
+ /**
41
+ * The v0.9 common types the schemas reference, in their v0.9 shapes, so
42
+ * every `common_types.json#/$defs/<Name>` ref resolves within the payload.
43
+ */
44
+ const V09_COMMON_TYPES = {
45
+ ComponentId: {
46
+ type: "string",
47
+ description: "The unique identifier for a component, used for both definitions and references within the same surface."
48
+ },
49
+ ComponentCommon: {
50
+ type: "object",
51
+ properties: {
52
+ id: ref("ComponentId"),
53
+ accessibility: ref("AccessibilityAttributes")
54
+ },
55
+ required: ["id"]
56
+ },
57
+ AccessibilityAttributes: {
58
+ type: "object",
59
+ description: "Attributes to enhance accessibility when using assistive technologies like screen readers.",
60
+ properties: {
61
+ label: ref("DynamicString"),
62
+ description: ref("DynamicString")
63
+ }
64
+ },
65
+ ChildList: { oneOf: [{
66
+ type: "array",
67
+ items: ref("ComponentId"),
68
+ description: "A static list of child component IDs."
69
+ }, {
70
+ type: "object",
71
+ description: "A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.",
72
+ properties: {
73
+ componentId: ref("ComponentId"),
74
+ path: {
75
+ type: "string",
76
+ description: "The path to the list of component property objects in the data model."
77
+ }
78
+ },
79
+ required: ["componentId", "path"],
80
+ additionalProperties: false
81
+ }] },
82
+ DataBinding: {
83
+ type: "object",
84
+ properties: { path: {
85
+ type: "string",
86
+ description: "A JSON Pointer path to a value in the data model."
87
+ } },
88
+ required: ["path"],
89
+ additionalProperties: false
90
+ },
91
+ FunctionCall: {
92
+ type: "object",
93
+ description: "Invokes a named function on the client.",
94
+ properties: {
95
+ call: {
96
+ type: "string",
97
+ description: "The name of the function to call."
98
+ },
99
+ args: {
100
+ type: "object",
101
+ description: "Arguments passed to the function.",
102
+ additionalProperties: ref("DynamicValue")
103
+ }
104
+ },
105
+ required: ["call"],
106
+ additionalProperties: false
107
+ },
108
+ DynamicValue: {
109
+ description: "A value that can be a literal, a path, or a function call returning any type.",
110
+ anyOf: [
111
+ { type: "string" },
112
+ { type: "number" },
113
+ { type: "boolean" },
114
+ { type: "array" },
115
+ ref("DataBinding"),
116
+ ref("FunctionCall")
117
+ ]
118
+ },
119
+ DynamicString: { anyOf: [
120
+ { type: "string" },
121
+ ref("DataBinding"),
122
+ ref("FunctionCall")
123
+ ] },
124
+ DynamicNumber: { anyOf: [
125
+ { type: "number" },
126
+ ref("DataBinding"),
127
+ ref("FunctionCall")
128
+ ] },
129
+ DynamicBoolean: { anyOf: [
130
+ { type: "boolean" },
131
+ ref("DataBinding"),
132
+ ref("FunctionCall")
133
+ ] },
134
+ DynamicStringList: { anyOf: [
135
+ {
136
+ type: "array",
137
+ items: { type: "string" }
138
+ },
139
+ ref("DataBinding"),
140
+ ref("FunctionCall")
141
+ ] },
142
+ Action: {
143
+ description: "Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.",
144
+ oneOf: [{
145
+ type: "object",
146
+ description: "Triggers a server-side event.",
147
+ properties: { event: {
148
+ type: "object",
149
+ properties: {
150
+ name: {
151
+ type: "string",
152
+ description: "The name of the action to be dispatched to the server."
153
+ },
154
+ context: {
155
+ type: "object",
156
+ description: "A JSON object containing the key-value pairs for the action context. Values can be literals or paths.",
157
+ additionalProperties: ref("DynamicValue")
158
+ }
159
+ },
160
+ required: ["name"],
161
+ additionalProperties: false
162
+ } },
163
+ required: ["event"],
164
+ additionalProperties: false
165
+ }, {
166
+ type: "object",
167
+ description: "Executes a local client-side function.",
168
+ properties: { functionCall: ref("FunctionCall") },
169
+ required: ["functionCall"],
170
+ additionalProperties: false
171
+ }]
172
+ }
173
+ };
174
+ function isRecord(value) {
175
+ return typeof value === "object" && value !== null && !Array.isArray(value);
176
+ }
177
+ /** 1.0 binding and call syntax in a description, written the v0.9 way. */
178
+ function v09Text(text) {
179
+ return text.replaceAll("\"@path\"", "\"path\"").replaceAll("\"@call\"", "\"call\"");
180
+ }
181
+ /** The v0.9 dynamic type of a literal schema that is just a primitive type. */
182
+ const DYNAMIC_TYPES = {
183
+ string: "DynamicString",
184
+ number: "DynamicNumber",
185
+ boolean: "DynamicBoolean"
186
+ };
187
+ /**
188
+ * A prop value as v0.9 states it: its literal schema, a `{ path }` binding
189
+ * or a `{ call }` function call. A plain string, number, boolean or string
190
+ * list is the v0.9 `Dynamic*` type of the same meaning. A component
191
+ * reference stays one.
192
+ *
193
+ * Only the prop itself is made dynamic, as in the v0.9 basic catalog: the
194
+ * 1.0 catalog marks every nested value dynamic too, which makes the
195
+ * standard catalog several times larger.
196
+ */
197
+ function dynamicValue(schema) {
198
+ if (!isRecord(schema)) return ref("DynamicValue");
199
+ const v09 = v09Schema(schema);
200
+ if ((0, _copilotkit_shared.childRefKind)(schema)) return v09;
201
+ const { description, ...literal } = v09;
202
+ const text = typeof description === "string" ? { description } : {};
203
+ const keys = Object.keys(literal);
204
+ if (keys.length === 1 && typeof literal.type === "string") {
205
+ const dynamic = DYNAMIC_TYPES[literal.type];
206
+ if (dynamic) return {
207
+ ...ref(dynamic),
208
+ ...text
209
+ };
210
+ }
211
+ const items = literal.items;
212
+ if (keys.length === 2 && literal.type === "array" && isRecord(items) && Object.keys(items).length === 1 && items.type === "string") return {
213
+ ...ref("DynamicStringList"),
214
+ ...text
215
+ };
216
+ return {
217
+ ...text,
218
+ anyOf: [
219
+ literal,
220
+ ref("DataBinding"),
221
+ ref("FunctionCall")
222
+ ]
223
+ };
224
+ }
225
+ /** A copy of a schema, with its descriptions written the v0.9 way. */
226
+ function v09Schema(value) {
227
+ if (Array.isArray(value)) return value.map(v09Schema);
228
+ if (!isRecord(value)) return value;
229
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, key === "description" && typeof child === "string" ? v09Text(child) : v09Schema(child)]));
230
+ }
231
+ const mapValues = (record, transform) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, transform(value)]));
232
+ /** An object schema with each of its properties made dynamic. */
233
+ function dynamicProperties(schema) {
234
+ const result = v09Schema(schema);
235
+ if (isRecord(schema.properties)) result.properties = mapValues(schema.properties, dynamicValue);
236
+ return result;
237
+ }
238
+ /**
239
+ * Local refs (`#/...`) of a props schema, pointing to where the schema is
240
+ * embedded in the payload instead of to the root of the props schema.
241
+ */
242
+ function rebaseRefs(value, base) {
243
+ if (Array.isArray(value)) return value.map((item) => rebaseRefs(item, base));
244
+ if (!isRecord(value)) return value;
245
+ const result = mapValues(value, (child) => rebaseRefs(child, base));
246
+ const target = result.$ref;
247
+ if (target === "#") result.$ref = base;
248
+ else if (typeof target === "string" && target.startsWith("#/")) result.$ref = `${base}${target.slice(1)}`;
249
+ return result;
250
+ }
251
+ /** A JSON Pointer segment: `acme/Card` is `acme~1Card`. */
252
+ function pointerSegment(name) {
253
+ return name.replace(/~/g, "~0").replace(/\//g, "~1");
254
+ }
255
+ /**
256
+ * One component in the v0.9 inline catalog format: `ComponentCommon` and
257
+ * the props, events and slots of the 1.0 manifest under their v0.9 names.
258
+ */
259
+ function componentSchema(name, manifest, renames) {
260
+ const v09Name = (key) => renames[key] ?? key;
261
+ const { properties, required, description, $defs, definitions } = manifest.props;
262
+ const fields = {};
263
+ for (const [key, schema] of Object.entries(isRecord(properties) ? properties : {})) fields[key] = dynamicValue(schema);
264
+ for (const [key, event] of Object.entries(manifest.events ?? {})) fields[key] = {
265
+ ...ref("Action"),
266
+ ...event.description ? { description: v09Text(event.description) } : {}
267
+ };
268
+ for (const [key, kind] of Object.entries(manifest.slots ?? {})) fields[key] = ref(kind === "single" ? "ComponentId" : "ChildList");
269
+ const order = [...manifest.parameterOrder ?? [], ...Object.keys(fields)];
270
+ const ordered = { component: { const: name } };
271
+ for (const key of order) if (Object.hasOwn(fields, key)) ordered[v09Name(key)] = fields[key];
272
+ const defs = {
273
+ ...isRecord($defs) ? { $defs: v09Schema($defs) } : {},
274
+ ...isRecord(definitions) ? { definitions: v09Schema(definitions) } : {}
275
+ };
276
+ const text = manifest.description ?? description;
277
+ const body = rebaseRefs({
278
+ properties: ordered,
279
+ required: ["component", ...Array.isArray(required) ? required.filter((key) => typeof key === "string").map(v09Name) : []],
280
+ ...defs
281
+ }, `#/components/${pointerSegment(name)}/allOf/1`);
282
+ return {
283
+ ...typeof text === "string" ? { description: v09Text(text) } : {},
284
+ allOf: [ref("ComponentCommon"), body]
285
+ };
286
+ }
287
+ /** A function in the v0.9 inline catalog `functions` format. */
288
+ function functionSchema(name, description, returnType, parameters) {
289
+ return {
290
+ name,
291
+ ...description ? { description: v09Text(description) } : {},
292
+ returnType: returnType === "validationResult" ? "boolean" : returnType ?? "any",
293
+ parameters
294
+ };
295
+ }
296
+ /**
297
+ * The functions a v0.9 `{ call }` may name: the basic ones, which v0.9 names
298
+ * the same, then the app functions the renderer may call.
299
+ */
300
+ function catalogFunctions(functions) {
301
+ const result = Object.entries(_copilotkit_shared.A2UI_BASIC_FUNCTIONS).filter(([name]) => !Object.hasOwn(functions, name)).map(([name, info]) => functionSchema(name, info.description, info.returnType, (0, _copilotkit_shared_generative_ui.argsSchemaFromSignature)(info.parameters)));
302
+ for (const [name, fn] of Object.entries(functions)) {
303
+ if (!(0, _copilotkit_shared.functionCallers)(fn).renderer) continue;
304
+ result.push(functionSchema(name, fn.description, fn.returnType, dynamicProperties(fn.parameters)));
305
+ }
306
+ return result;
307
+ }
308
+ /**
309
+ * The capabilities entry: the catalog id, then the components beyond the
310
+ * v0.9 basic catalog, by name. Their schemas are in the schema entry, so
311
+ * they are not repeated here.
312
+ */
313
+ function capabilitiesValue(catalogId, names) {
314
+ const lines = ["Available A2UI catalog:"];
315
+ if (names === void 0) {
316
+ lines.push(`- ${catalogId}`);
317
+ return lines.join("\n");
318
+ }
319
+ const extra = names.filter((name) => !V09_BASIC_COMPONENTS.has(name));
320
+ const nameSet = new Set(names);
321
+ const isSuperset = [...V09_BASIC_COMPONENTS].every((name) => nameSet.has(name));
322
+ if (catalogId === A2UI_V09_BASIC_CATALOG_ID && isSuperset && !extra.length) {
323
+ lines.push(`- ${catalogId} (basic catalog)`);
324
+ return lines.join("\n");
325
+ }
326
+ lines.push(`- ${catalogId}`);
327
+ if (isSuperset) lines.push(" Extends the basic catalog with all standard components plus:");
328
+ else {
329
+ lines.push(" Custom catalog (does NOT include all basic components).");
330
+ lines.push(" Custom components:");
331
+ }
332
+ for (const name of extra) lines.push(` - ${name}`);
333
+ return lines.join("\n");
334
+ }
335
+ /**
336
+ * Builds the A2UI v0.9 catalog context for a run, from the generative UI
337
+ * envelope the client sent (`forwardedProps.copilotkit.ui`).
338
+ *
339
+ * The entries are the ones the v0.9 client sent, with the same descriptions:
340
+ * the catalog capabilities, the component schema (the v0.9 inline catalog
341
+ * format that `A2UIMiddleware` reads, and replaces when it has a server
342
+ * schema), and the v0.9 generation and design guidelines. Without the
343
+ * component schemas in the envelope, only the capabilities entry is built.
344
+ *
345
+ * The components are the v0.9 basic ones of the standard catalog and the
346
+ * UI's own components: the other standard components (Title, Chart, ...)
347
+ * are left out, as a v0.9 agent never knew them and they would make the
348
+ * schema about three times larger. A component of the UI's own that has the
349
+ * name of a standard component counts as the standard one.
350
+ *
351
+ * Components keep their names. Props, events and slots keep their 1.0 names
352
+ * except for `V10_TO_V09_PROP_NAMES` on standard components;
353
+ * values take a v0.9 `{ path }` binding or `{ call }` function call, events
354
+ * take a v0.9 action, and slots a v0.9 `ComponentId` or `ChildList`.
355
+ *
356
+ * The catalog id is the v0.9 basic catalog id when the UI includes the 1.0
357
+ * standard catalog, which has every v0.9 basic component: v0.9 agents and
358
+ * prompts already use that id, and `A2UIMiddleware` stamps the id of the
359
+ * schema entry into the surfaces it creates. Otherwise it is the id of the
360
+ * UI, since the basic id would promise components the UI does not have.
361
+ *
362
+ * @param input - The run input.
363
+ * @returns The catalog id the v0.9 agent should use and the context
364
+ * entries, or `undefined` when the run has no generative UI envelope.
365
+ *
366
+ * @example
367
+ * ```ts
368
+ * const v09 = buildA2UIV09CatalogContext(input);
369
+ * if (v09) input = { ...input, context: [...input.context, ...v09.context] };
370
+ * ```
371
+ */
372
+ function buildA2UIV09CatalogContext(input) {
373
+ const envelope = (0, _copilotkit_shared.readCopilotKitUIEnvelope)(input.forwardedProps);
374
+ if (!envelope) return void 0;
375
+ const manifest = (0, _copilotkit_shared.envelopeToManifest)(envelope);
376
+ const extendsStandard = (manifest.catalogIds ?? [manifest.catalogId]).includes(_copilotkit_shared_generative_ui.STANDARD_CATALOG_ID);
377
+ const catalogId = extendsStandard ? A2UI_V09_BASIC_CATALOG_ID : manifest.catalogId;
378
+ if (!manifest.hasComponents) return {
379
+ catalogId,
380
+ context: [{
381
+ description: CAPABILITIES_CONTEXT_DESCRIPTION,
382
+ value: capabilitiesValue(catalogId, void 0)
383
+ }]
384
+ };
385
+ const components = {};
386
+ for (const [name, component] of Object.entries(manifest.components)) {
387
+ const isStandard = extendsStandard && Object.hasOwn(_copilotkit_shared_generative_ui.standardDeclarations, name);
388
+ if (isStandard && !V09_BASIC_COMPONENTS.has(name)) continue;
389
+ components[name] = componentSchema(name, component, isStandard && V10_TO_V09_PROP_NAMES[name] || {});
390
+ }
391
+ const schema = {
392
+ catalogId,
393
+ components,
394
+ functions: catalogFunctions(manifest.functions),
395
+ "common_types.json": { $defs: V09_COMMON_TYPES }
396
+ };
397
+ return {
398
+ catalogId,
399
+ context: [
400
+ {
401
+ description: CAPABILITIES_CONTEXT_DESCRIPTION,
402
+ value: capabilitiesValue(catalogId, Object.keys(components))
403
+ },
404
+ {
405
+ description: _ag_ui_a2ui_middleware.A2UI_SCHEMA_CONTEXT_DESCRIPTION,
406
+ value: JSON.stringify(schema)
407
+ },
408
+ {
409
+ description: GENERATION_GUIDELINES_CONTEXT_DESCRIPTION,
410
+ value: _copilotkit_shared.A2UI_DEFAULT_GENERATION_GUIDELINES
411
+ },
412
+ {
413
+ description: DESIGN_GUIDELINES_CONTEXT_DESCRIPTION,
414
+ value: _copilotkit_shared.A2UI_DEFAULT_DESIGN_GUIDELINES
415
+ }
416
+ ]
417
+ };
418
+ }
419
+
420
+ //#endregion
421
+ exports.buildA2UIV09CatalogContext = buildA2UIV09CatalogContext;
422
+ //# sourceMappingURL=a2ui-v09-catalog.cjs.map