@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 @@
1
+ {"version":3,"file":"a2ui-v09-catalog.cjs","names":["A2UI_BASIC_FUNCTIONS","STANDARD_CATALOG_ID","standardDeclarations","A2UI_SCHEMA_CONTEXT_DESCRIPTION","A2UI_DEFAULT_GENERATION_GUIDELINES","A2UI_DEFAULT_DESIGN_GUIDELINES"],"sources":["../../../src/runtime/generative-ui/a2ui-v09-catalog.ts"],"sourcesContent":["/**\n * The A2UI v0.9 catalog context for an agent that speaks v0.9.\n *\n * The client renders A2UI 1.0 only and sends its catalog in the run envelope\n * (`forwardedProps.copilotkit.ui`). A v0.9 agent still calls `render_a2ui`\n * (injected by `A2UIMiddleware`) and must be told the components in v0.9\n * terms. The removed v0.9 client (`@copilotkit/a2ui-renderer`) sent that as\n * agent context; this module builds the same entries on the server, from the\n * 1.0 manifest.\n */\nimport type { RunAgentInput } from \"@ag-ui/client\";\nimport { A2UI_SCHEMA_CONTEXT_DESCRIPTION } from \"@ag-ui/a2ui-middleware\";\nimport {\n A2UI_BASIC_FUNCTIONS,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n childRefKind,\n envelopeToManifest,\n functionCallers,\n readCopilotKitUIEnvelope,\n} from \"@copilotkit/shared\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n} from \"@copilotkit/shared\";\nimport {\n STANDARD_CATALOG_ID,\n argsSchemaFromSignature,\n standardDeclarations,\n} from \"@copilotkit/shared/generative-ui\";\n\n/** Id of the A2UI v0.9 basic catalog. */\nconst A2UI_V09_BASIC_CATALOG_ID =\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\";\n\n// The description strings of the context entries, as the v0.9 client sent\n// them (`@copilotkit/a2ui-renderer` `catalog-context.ts`). Agents and the\n// middleware find the entries by them. The schema description comes from\n// `@ag-ui/a2ui-middleware`, which looks it up and can replace the entry.\nconst CAPABILITIES_CONTEXT_DESCRIPTION =\n \"A2UI catalog capabilities: available catalog IDs and custom component definitions the client can render.\";\nconst GENERATION_GUIDELINES_CONTEXT_DESCRIPTION =\n \"A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.\";\nconst DESIGN_GUIDELINES_CONTEXT_DESCRIPTION =\n \"A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.\";\n\n/** The components of the v0.9 basic catalog. The 1.0 standard catalog has each of them. */\nconst V09_BASIC_COMPONENTS: ReadonlySet<string> = new Set([\n \"Text\",\n \"Image\",\n \"Icon\",\n \"Video\",\n \"AudioPlayer\",\n \"Row\",\n \"Column\",\n \"List\",\n \"Card\",\n \"Tabs\",\n \"Modal\",\n \"Divider\",\n \"Button\",\n \"TextField\",\n \"CheckBox\",\n \"ChoicePicker\",\n \"Slider\",\n \"DateTimeInput\",\n]);\n\n/**\n * The props (and events and slots) of standard components that v0.9 names\n * differently: component → 1.0 name → v0.9 name. Every other prop has the\n * same name in both versions.\n */\nconst V10_TO_V09_PROP_NAMES: Readonly<\n Record<string, Readonly<Record<string, string>>>\n> = {\n Button: { onClick: \"action\" },\n};\n\ntype JsonSchema = Record<string, unknown>;\n\nconst COMMON = \"common_types.json#/$defs/\";\nconst ref = (name: string) => ({ $ref: `${COMMON}${name}` });\n\n/**\n * The v0.9 common types the schemas reference, in their v0.9 shapes, so\n * every `common_types.json#/$defs/<Name>` ref resolves within the payload.\n */\nconst V09_COMMON_TYPES: Record<string, JsonSchema> = {\n ComponentId: {\n type: \"string\",\n description:\n \"The unique identifier for a component, used for both definitions and references within the same surface.\",\n },\n ComponentCommon: {\n type: \"object\",\n properties: {\n id: ref(\"ComponentId\"),\n accessibility: ref(\"AccessibilityAttributes\"),\n },\n required: [\"id\"],\n },\n AccessibilityAttributes: {\n type: \"object\",\n description:\n \"Attributes to enhance accessibility when using assistive technologies like screen readers.\",\n properties: {\n label: ref(\"DynamicString\"),\n description: ref(\"DynamicString\"),\n },\n },\n ChildList: {\n oneOf: [\n {\n type: \"array\",\n items: ref(\"ComponentId\"),\n description: \"A static list of child component IDs.\",\n },\n {\n type: \"object\",\n description:\n \"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.\",\n properties: {\n componentId: ref(\"ComponentId\"),\n path: {\n type: \"string\",\n description:\n \"The path to the list of component property objects in the data model.\",\n },\n },\n required: [\"componentId\", \"path\"],\n additionalProperties: false,\n },\n ],\n },\n DataBinding: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description: \"A JSON Pointer path to a value in the data model.\",\n },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n FunctionCall: {\n type: \"object\",\n description: \"Invokes a named function on the client.\",\n properties: {\n call: {\n type: \"string\",\n description: \"The name of the function to call.\",\n },\n args: {\n type: \"object\",\n description: \"Arguments passed to the function.\",\n additionalProperties: ref(\"DynamicValue\"),\n },\n },\n required: [\"call\"],\n additionalProperties: false,\n },\n DynamicValue: {\n description:\n \"A value that can be a literal, a path, or a function call returning any type.\",\n anyOf: [\n { type: \"string\" },\n { type: \"number\" },\n { type: \"boolean\" },\n { type: \"array\" },\n ref(\"DataBinding\"),\n ref(\"FunctionCall\"),\n ],\n },\n DynamicString: {\n anyOf: [{ type: \"string\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicNumber: {\n anyOf: [{ type: \"number\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicBoolean: {\n anyOf: [{ type: \"boolean\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicStringList: {\n anyOf: [\n { type: \"array\", items: { type: \"string\" } },\n ref(\"DataBinding\"),\n ref(\"FunctionCall\"),\n ],\n },\n Action: {\n description:\n \"Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.\",\n oneOf: [\n {\n type: \"object\",\n description: \"Triggers a server-side event.\",\n properties: {\n event: {\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description:\n \"The name of the action to be dispatched to the server.\",\n },\n context: {\n type: \"object\",\n description:\n \"A JSON object containing the key-value pairs for the action context. Values can be literals or paths.\",\n additionalProperties: ref(\"DynamicValue\"),\n },\n },\n required: [\"name\"],\n additionalProperties: false,\n },\n },\n required: [\"event\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n description: \"Executes a local client-side function.\",\n properties: { functionCall: ref(\"FunctionCall\") },\n required: [\"functionCall\"],\n additionalProperties: false,\n },\n ],\n },\n};\n\nfunction isRecord(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** 1.0 binding and call syntax in a description, written the v0.9 way. */\nfunction v09Text(text: string) {\n return text.replaceAll('\"@path\"', '\"path\"').replaceAll('\"@call\"', '\"call\"');\n}\n\n/** The v0.9 dynamic type of a literal schema that is just a primitive type. */\nconst DYNAMIC_TYPES: Readonly<Record<string, string>> = {\n string: \"DynamicString\",\n number: \"DynamicNumber\",\n boolean: \"DynamicBoolean\",\n};\n\n/**\n * A prop value as v0.9 states it: its literal schema, a `{ path }` binding\n * or a `{ call }` function call. A plain string, number, boolean or string\n * list is the v0.9 `Dynamic*` type of the same meaning. A component\n * reference stays one.\n *\n * Only the prop itself is made dynamic, as in the v0.9 basic catalog: the\n * 1.0 catalog marks every nested value dynamic too, which makes the\n * standard catalog several times larger.\n */\nfunction dynamicValue(schema: unknown): JsonSchema {\n if (!isRecord(schema)) return ref(\"DynamicValue\");\n const v09 = v09Schema(schema) as JsonSchema;\n if (childRefKind(schema)) return v09;\n const { description, ...literal } = v09;\n const text = typeof description === \"string\" ? { description } : {};\n const keys = Object.keys(literal);\n if (keys.length === 1 && typeof literal.type === \"string\") {\n const dynamic = DYNAMIC_TYPES[literal.type];\n if (dynamic) return { ...ref(dynamic), ...text };\n }\n const items = literal.items;\n if (\n keys.length === 2 &&\n literal.type === \"array\" &&\n isRecord(items) &&\n Object.keys(items).length === 1 &&\n items.type === \"string\"\n ) {\n return { ...ref(\"DynamicStringList\"), ...text };\n }\n return { ...text, anyOf: [literal, ref(\"DataBinding\"), ref(\"FunctionCall\")] };\n}\n\n/** A copy of a schema, with its descriptions written the v0.9 way. */\nfunction v09Schema(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(v09Schema);\n if (!isRecord(value)) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n key === \"description\" && typeof child === \"string\"\n ? v09Text(child)\n : v09Schema(child),\n ]),\n );\n}\n\nconst mapValues = (\n record: JsonSchema,\n transform: (value: unknown) => unknown,\n): JsonSchema =>\n Object.fromEntries(\n Object.entries(record).map(([key, value]) => [key, transform(value)]),\n );\n\n/** An object schema with each of its properties made dynamic. */\nfunction dynamicProperties(schema: JsonSchema): JsonSchema {\n const result = v09Schema(schema) as JsonSchema;\n if (isRecord(schema.properties)) {\n result.properties = mapValues(schema.properties, dynamicValue);\n }\n return result;\n}\n\n/**\n * Local refs (`#/...`) of a props schema, pointing to where the schema is\n * embedded in the payload instead of to the root of the props schema.\n */\nfunction rebaseRefs(value: unknown, base: string): unknown {\n if (Array.isArray(value)) return value.map((item) => rebaseRefs(item, base));\n if (!isRecord(value)) return value;\n const result = mapValues(value, (child) => rebaseRefs(child, base));\n const target = result.$ref;\n if (target === \"#\") result.$ref = base;\n else if (typeof target === \"string\" && target.startsWith(\"#/\")) {\n result.$ref = `${base}${target.slice(1)}`;\n }\n return result;\n}\n\n/** A JSON Pointer segment: `acme/Card` is `acme~1Card`. */\nfunction pointerSegment(name: string) {\n return name.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n}\n\n/**\n * One component in the v0.9 inline catalog format: `ComponentCommon` and\n * the props, events and slots of the 1.0 manifest under their v0.9 names.\n */\nfunction componentSchema(\n name: string,\n manifest: GenerativeUIComponentManifest,\n renames: Readonly<Record<string, string>>,\n): JsonSchema {\n const v09Name = (key: string) => renames[key] ?? key;\n const { properties, required, description, $defs, definitions } =\n manifest.props;\n const fields: JsonSchema = {};\n for (const [key, schema] of Object.entries(\n isRecord(properties) ? properties : {},\n )) {\n fields[key] = dynamicValue(schema);\n }\n for (const [key, event] of Object.entries(manifest.events ?? {})) {\n fields[key] = {\n ...ref(\"Action\"),\n ...(event.description ? { description: v09Text(event.description) } : {}),\n };\n }\n for (const [key, kind] of Object.entries(manifest.slots ?? {})) {\n fields[key] = ref(kind === \"single\" ? \"ComponentId\" : \"ChildList\");\n }\n const order = [...(manifest.parameterOrder ?? []), ...Object.keys(fields)];\n const ordered: JsonSchema = { component: { const: name } };\n for (const key of order) {\n if (Object.hasOwn(fields, key)) ordered[v09Name(key)] = fields[key];\n }\n // The definitions of the props schema, when its converter made some.\n const defs = {\n ...(isRecord($defs) ? { $defs: v09Schema($defs) } : {}),\n ...(isRecord(definitions) ? { definitions: v09Schema(definitions) } : {}),\n };\n const text = manifest.description ?? description;\n const body = rebaseRefs(\n {\n properties: ordered,\n required: [\n \"component\",\n ...(Array.isArray(required)\n ? required.filter((key) => typeof key === \"string\").map(v09Name)\n : []),\n ],\n ...defs,\n },\n `#/components/${pointerSegment(name)}/allOf/1`,\n ) as JsonSchema;\n return {\n ...(typeof text === \"string\" ? { description: v09Text(text) } : {}),\n allOf: [ref(\"ComponentCommon\"), body],\n };\n}\n\n/** A function in the v0.9 inline catalog `functions` format. */\nfunction functionSchema(\n name: string,\n description: string | undefined,\n returnType: string | undefined,\n parameters: JsonSchema,\n) {\n return {\n name,\n ...(description ? { description: v09Text(description) } : {}),\n // v0.9 has no `validationResult`: its checks are boolean function calls.\n returnType:\n returnType === \"validationResult\" ? \"boolean\" : (returnType ?? \"any\"),\n parameters,\n };\n}\n\n/**\n * The functions a v0.9 `{ call }` may name: the basic ones, which v0.9 names\n * the same, then the app functions the renderer may call.\n */\nfunction catalogFunctions(\n functions: Record<string, GenerativeUIFunctionManifest>,\n) {\n const result = Object.entries(A2UI_BASIC_FUNCTIONS)\n .filter(([name]) => !Object.hasOwn(functions, name))\n .map(([name, info]) =>\n functionSchema(\n name,\n info.description,\n info.returnType,\n argsSchemaFromSignature(info.parameters),\n ),\n );\n for (const [name, fn] of Object.entries(functions)) {\n if (!functionCallers(fn).renderer) continue;\n result.push(\n functionSchema(\n name,\n fn.description,\n fn.returnType,\n dynamicProperties(fn.parameters),\n ),\n );\n }\n return result;\n}\n\n/**\n * The capabilities entry: the catalog id, then the components beyond the\n * v0.9 basic catalog, by name. Their schemas are in the schema entry, so\n * they are not repeated here.\n */\nfunction capabilitiesValue(\n catalogId: string,\n names: readonly string[] | undefined,\n) {\n const lines = [\"Available A2UI catalog:\"];\n if (names === undefined) {\n lines.push(`- ${catalogId}`);\n return lines.join(\"\\n\");\n }\n const extra = names.filter((name) => !V09_BASIC_COMPONENTS.has(name));\n const nameSet = new Set(names);\n const isSuperset = [...V09_BASIC_COMPONENTS].every((name) =>\n nameSet.has(name),\n );\n if (catalogId === A2UI_V09_BASIC_CATALOG_ID && isSuperset && !extra.length) {\n lines.push(`- ${catalogId} (basic catalog)`);\n return lines.join(\"\\n\");\n }\n lines.push(`- ${catalogId}`);\n if (isSuperset) {\n lines.push(\n \" Extends the basic catalog with all standard components plus:\",\n );\n } else {\n lines.push(\" Custom catalog (does NOT include all basic components).\");\n lines.push(\" Custom components:\");\n }\n for (const name of extra) lines.push(` - ${name}`);\n return lines.join(\"\\n\");\n}\n\n/**\n * Builds the A2UI v0.9 catalog context for a run, from the generative UI\n * envelope the client sent (`forwardedProps.copilotkit.ui`).\n *\n * The entries are the ones the v0.9 client sent, with the same descriptions:\n * the catalog capabilities, the component schema (the v0.9 inline catalog\n * format that `A2UIMiddleware` reads, and replaces when it has a server\n * schema), and the v0.9 generation and design guidelines. Without the\n * component schemas in the envelope, only the capabilities entry is built.\n *\n * The components are the v0.9 basic ones of the standard catalog and the\n * UI's own components: the other standard components (Title, Chart, ...)\n * are left out, as a v0.9 agent never knew them and they would make the\n * schema about three times larger. A component of the UI's own that has the\n * name of a standard component counts as the standard one.\n *\n * Components keep their names. Props, events and slots keep their 1.0 names\n * except for `V10_TO_V09_PROP_NAMES` on standard components;\n * values take a v0.9 `{ path }` binding or `{ call }` function call, events\n * take a v0.9 action, and slots a v0.9 `ComponentId` or `ChildList`.\n *\n * The catalog id is the v0.9 basic catalog id when the UI includes the 1.0\n * standard catalog, which has every v0.9 basic component: v0.9 agents and\n * prompts already use that id, and `A2UIMiddleware` stamps the id of the\n * schema entry into the surfaces it creates. Otherwise it is the id of the\n * UI, since the basic id would promise components the UI does not have.\n *\n * @param input - The run input.\n * @returns The catalog id the v0.9 agent should use and the context\n * entries, or `undefined` when the run has no generative UI envelope.\n *\n * @example\n * ```ts\n * const v09 = buildA2UIV09CatalogContext(input);\n * if (v09) input = { ...input, context: [...input.context, ...v09.context] };\n * ```\n */\nexport function buildA2UIV09CatalogContext(input: RunAgentInput):\n | {\n catalogId: string;\n context: Array<{ description: string; value: string }>;\n }\n | undefined {\n const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n if (!envelope) return undefined;\n const manifest = envelopeToManifest(envelope);\n const extendsStandard = (\n manifest.catalogIds ?? [manifest.catalogId]\n ).includes(STANDARD_CATALOG_ID);\n const catalogId = extendsStandard\n ? A2UI_V09_BASIC_CATALOG_ID\n : manifest.catalogId;\n\n if (!manifest.hasComponents) {\n return {\n catalogId,\n context: [\n {\n description: CAPABILITIES_CONTEXT_DESCRIPTION,\n value: capabilitiesValue(catalogId, undefined),\n },\n ],\n };\n }\n\n const components: Record<string, JsonSchema> = {};\n for (const [name, component] of Object.entries(manifest.components)) {\n const isStandard =\n extendsStandard && Object.hasOwn(standardDeclarations, name);\n // Of the standard components, a v0.9 agent knows the basic ones only.\n if (isStandard && !V09_BASIC_COMPONENTS.has(name)) continue;\n const renames = (isStandard && V10_TO_V09_PROP_NAMES[name]) || {};\n components[name] = componentSchema(name, component, renames);\n }\n const schema = {\n catalogId,\n components,\n functions: catalogFunctions(manifest.functions),\n \"common_types.json\": { $defs: V09_COMMON_TYPES },\n };\n\n return {\n catalogId,\n context: [\n {\n description: CAPABILITIES_CONTEXT_DESCRIPTION,\n value: capabilitiesValue(catalogId, Object.keys(components)),\n },\n {\n description: A2UI_SCHEMA_CONTEXT_DESCRIPTION,\n value: JSON.stringify(schema),\n },\n {\n description: GENERATION_GUIDELINES_CONTEXT_DESCRIPTION,\n value: A2UI_DEFAULT_GENERATION_GUIDELINES,\n },\n {\n description: DESIGN_GUIDELINES_CONTEXT_DESCRIPTION,\n value: A2UI_DEFAULT_DESIGN_GUIDELINES,\n },\n ],\n };\n}\n"],"mappings":";;;;;;AAgCA,MAAM,4BACJ;AAMF,MAAM,mCACJ;AACF,MAAM,4CACJ;AACF,MAAM,wCACJ;;AAGF,MAAM,uBAA4C,IAAI,IAAI;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,MAAM,wBAEF,EACF,QAAQ,EAAE,SAAS,UAAU,EAC9B;AAID,MAAM,SAAS;AACf,MAAM,OAAO,UAAkB,EAAE,MAAM,GAAG,SAAS,QAAQ;;;;;AAM3D,MAAM,mBAA+C;CACnD,aAAa;EACX,MAAM;EACN,aACE;EACH;CACD,iBAAiB;EACf,MAAM;EACN,YAAY;GACV,IAAI,IAAI,cAAc;GACtB,eAAe,IAAI,0BAA0B;GAC9C;EACD,UAAU,CAAC,KAAK;EACjB;CACD,yBAAyB;EACvB,MAAM;EACN,aACE;EACF,YAAY;GACV,OAAO,IAAI,gBAAgB;GAC3B,aAAa,IAAI,gBAAgB;GAClC;EACF;CACD,WAAW,EACT,OAAO,CACL;EACE,MAAM;EACN,OAAO,IAAI,cAAc;EACzB,aAAa;EACd,EACD;EACE,MAAM;EACN,aACE;EACF,YAAY;GACV,aAAa,IAAI,cA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;;;;;;AAwCzB,SAAgB,2BAA2B,OAK7B;CACZ,MAAM,4DAAoC,MAAM,eAAe;AAC/D,KAAI,CAAC,SAAU,QAAO;CACtB,MAAM,sDAA8B,SAAS;CAC7C,MAAM,mBACJ,SAAS,cAAc,CAAC,SAAS,UAAU,EAC3C,SAASC,qDAAoB;CAC/B,MAAM,YAAY,kBACd,4BACA,SAAS;AAEb,KAAI,CAAC,SAAS,cACZ,QAAO;EACL;EACA,SAAS,CACP;GACE,aAAa;GACb,OAAO,kBAAkB,WAAW,OAAU;GAC/C,CACF;EACF;CAGH,MAAM,aAAyC,EAAE;AACjD,MAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,SAAS,WAAW,EAAE;EACnE,MAAM,aACJ,mBAAmB,OAAO,OAAOC,uDAAsB,KAAK;AAE9D,MAAI,cAAc,CAAC,qBAAqB,IAAI,KAAK,CAAE;AAEnD,aAAW,QAAQ,gBAAgB,MAAM,WADxB,cAAc,sBAAsB,SAAU,EAAE,CACL;;CAE9D,MAAM,SAAS;EACb;EACA;EACA,WAAW,iBAAiB,SAAS,UAAU;EAC/C,qBAAqB,EAAE,OAAO,kBAAkB;EACjD;AAED,QAAO;EACL;EACA,SAAS;GACP;IACE,aAAa;IACb,OAAO,kBAAkB,WAAW,OAAO,KAAK,WAAW,CAAC;IAC7D;GACD;IACE,aAAaC;IACb,OAAO,KAAK,UAAU,OAAO;IAC9B;GACD;IACE,aAAa;IACb,OAAOC;IACR;GACD;IACE,aAAa;IACb,OAAOC;IACR;GACF;EACF"}
@@ -0,0 +1,422 @@
1
+ import { A2UI_BASIC_FUNCTIONS, A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, childRefKind, envelopeToManifest, functionCallers, readCopilotKitUIEnvelope } from "@copilotkit/shared";
2
+ import { A2UI_SCHEMA_CONTEXT_DESCRIPTION } from "@ag-ui/a2ui-middleware";
3
+ import { STANDARD_CATALOG_ID, argsSchemaFromSignature, standardDeclarations } from "@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 (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(A2UI_BASIC_FUNCTIONS).filter(([name]) => !Object.hasOwn(functions, name)).map(([name, info]) => functionSchema(name, info.description, info.returnType, argsSchemaFromSignature(info.parameters)));
302
+ for (const [name, fn] of Object.entries(functions)) {
303
+ if (!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 = readCopilotKitUIEnvelope(input.forwardedProps);
374
+ if (!envelope) return void 0;
375
+ const manifest = envelopeToManifest(envelope);
376
+ const extendsStandard = (manifest.catalogIds ?? [manifest.catalogId]).includes(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(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: A2UI_SCHEMA_CONTEXT_DESCRIPTION,
406
+ value: JSON.stringify(schema)
407
+ },
408
+ {
409
+ description: GENERATION_GUIDELINES_CONTEXT_DESCRIPTION,
410
+ value: A2UI_DEFAULT_GENERATION_GUIDELINES
411
+ },
412
+ {
413
+ description: DESIGN_GUIDELINES_CONTEXT_DESCRIPTION,
414
+ value: A2UI_DEFAULT_DESIGN_GUIDELINES
415
+ }
416
+ ]
417
+ };
418
+ }
419
+
420
+ //#endregion
421
+ export { buildA2UIV09CatalogContext };
422
+ //# sourceMappingURL=a2ui-v09-catalog.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-v09-catalog.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-catalog.ts"],"sourcesContent":["/**\n * The A2UI v0.9 catalog context for an agent that speaks v0.9.\n *\n * The client renders A2UI 1.0 only and sends its catalog in the run envelope\n * (`forwardedProps.copilotkit.ui`). A v0.9 agent still calls `render_a2ui`\n * (injected by `A2UIMiddleware`) and must be told the components in v0.9\n * terms. The removed v0.9 client (`@copilotkit/a2ui-renderer`) sent that as\n * agent context; this module builds the same entries on the server, from the\n * 1.0 manifest.\n */\nimport type { RunAgentInput } from \"@ag-ui/client\";\nimport { A2UI_SCHEMA_CONTEXT_DESCRIPTION } from \"@ag-ui/a2ui-middleware\";\nimport {\n A2UI_BASIC_FUNCTIONS,\n A2UI_DEFAULT_DESIGN_GUIDELINES,\n A2UI_DEFAULT_GENERATION_GUIDELINES,\n childRefKind,\n envelopeToManifest,\n functionCallers,\n readCopilotKitUIEnvelope,\n} from \"@copilotkit/shared\";\nimport type {\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n} from \"@copilotkit/shared\";\nimport {\n STANDARD_CATALOG_ID,\n argsSchemaFromSignature,\n standardDeclarations,\n} from \"@copilotkit/shared/generative-ui\";\n\n/** Id of the A2UI v0.9 basic catalog. */\nconst A2UI_V09_BASIC_CATALOG_ID =\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\";\n\n// The description strings of the context entries, as the v0.9 client sent\n// them (`@copilotkit/a2ui-renderer` `catalog-context.ts`). Agents and the\n// middleware find the entries by them. The schema description comes from\n// `@ag-ui/a2ui-middleware`, which looks it up and can replace the entry.\nconst CAPABILITIES_CONTEXT_DESCRIPTION =\n \"A2UI catalog capabilities: available catalog IDs and custom component definitions the client can render.\";\nconst GENERATION_GUIDELINES_CONTEXT_DESCRIPTION =\n \"A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.\";\nconst DESIGN_GUIDELINES_CONTEXT_DESCRIPTION =\n \"A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.\";\n\n/** The components of the v0.9 basic catalog. The 1.0 standard catalog has each of them. */\nconst V09_BASIC_COMPONENTS: ReadonlySet<string> = new Set([\n \"Text\",\n \"Image\",\n \"Icon\",\n \"Video\",\n \"AudioPlayer\",\n \"Row\",\n \"Column\",\n \"List\",\n \"Card\",\n \"Tabs\",\n \"Modal\",\n \"Divider\",\n \"Button\",\n \"TextField\",\n \"CheckBox\",\n \"ChoicePicker\",\n \"Slider\",\n \"DateTimeInput\",\n]);\n\n/**\n * The props (and events and slots) of standard components that v0.9 names\n * differently: component → 1.0 name → v0.9 name. Every other prop has the\n * same name in both versions.\n */\nconst V10_TO_V09_PROP_NAMES: Readonly<\n Record<string, Readonly<Record<string, string>>>\n> = {\n Button: { onClick: \"action\" },\n};\n\ntype JsonSchema = Record<string, unknown>;\n\nconst COMMON = \"common_types.json#/$defs/\";\nconst ref = (name: string) => ({ $ref: `${COMMON}${name}` });\n\n/**\n * The v0.9 common types the schemas reference, in their v0.9 shapes, so\n * every `common_types.json#/$defs/<Name>` ref resolves within the payload.\n */\nconst V09_COMMON_TYPES: Record<string, JsonSchema> = {\n ComponentId: {\n type: \"string\",\n description:\n \"The unique identifier for a component, used for both definitions and references within the same surface.\",\n },\n ComponentCommon: {\n type: \"object\",\n properties: {\n id: ref(\"ComponentId\"),\n accessibility: ref(\"AccessibilityAttributes\"),\n },\n required: [\"id\"],\n },\n AccessibilityAttributes: {\n type: \"object\",\n description:\n \"Attributes to enhance accessibility when using assistive technologies like screen readers.\",\n properties: {\n label: ref(\"DynamicString\"),\n description: ref(\"DynamicString\"),\n },\n },\n ChildList: {\n oneOf: [\n {\n type: \"array\",\n items: ref(\"ComponentId\"),\n description: \"A static list of child component IDs.\",\n },\n {\n type: \"object\",\n description:\n \"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.\",\n properties: {\n componentId: ref(\"ComponentId\"),\n path: {\n type: \"string\",\n description:\n \"The path to the list of component property objects in the data model.\",\n },\n },\n required: [\"componentId\", \"path\"],\n additionalProperties: false,\n },\n ],\n },\n DataBinding: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description: \"A JSON Pointer path to a value in the data model.\",\n },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n FunctionCall: {\n type: \"object\",\n description: \"Invokes a named function on the client.\",\n properties: {\n call: {\n type: \"string\",\n description: \"The name of the function to call.\",\n },\n args: {\n type: \"object\",\n description: \"Arguments passed to the function.\",\n additionalProperties: ref(\"DynamicValue\"),\n },\n },\n required: [\"call\"],\n additionalProperties: false,\n },\n DynamicValue: {\n description:\n \"A value that can be a literal, a path, or a function call returning any type.\",\n anyOf: [\n { type: \"string\" },\n { type: \"number\" },\n { type: \"boolean\" },\n { type: \"array\" },\n ref(\"DataBinding\"),\n ref(\"FunctionCall\"),\n ],\n },\n DynamicString: {\n anyOf: [{ type: \"string\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicNumber: {\n anyOf: [{ type: \"number\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicBoolean: {\n anyOf: [{ type: \"boolean\" }, ref(\"DataBinding\"), ref(\"FunctionCall\")],\n },\n DynamicStringList: {\n anyOf: [\n { type: \"array\", items: { type: \"string\" } },\n ref(\"DataBinding\"),\n ref(\"FunctionCall\"),\n ],\n },\n Action: {\n description:\n \"Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.\",\n oneOf: [\n {\n type: \"object\",\n description: \"Triggers a server-side event.\",\n properties: {\n event: {\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description:\n \"The name of the action to be dispatched to the server.\",\n },\n context: {\n type: \"object\",\n description:\n \"A JSON object containing the key-value pairs for the action context. Values can be literals or paths.\",\n additionalProperties: ref(\"DynamicValue\"),\n },\n },\n required: [\"name\"],\n additionalProperties: false,\n },\n },\n required: [\"event\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n description: \"Executes a local client-side function.\",\n properties: { functionCall: ref(\"FunctionCall\") },\n required: [\"functionCall\"],\n additionalProperties: false,\n },\n ],\n },\n};\n\nfunction isRecord(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** 1.0 binding and call syntax in a description, written the v0.9 way. */\nfunction v09Text(text: string) {\n return text.replaceAll('\"@path\"', '\"path\"').replaceAll('\"@call\"', '\"call\"');\n}\n\n/** The v0.9 dynamic type of a literal schema that is just a primitive type. */\nconst DYNAMIC_TYPES: Readonly<Record<string, string>> = {\n string: \"DynamicString\",\n number: \"DynamicNumber\",\n boolean: \"DynamicBoolean\",\n};\n\n/**\n * A prop value as v0.9 states it: its literal schema, a `{ path }` binding\n * or a `{ call }` function call. A plain string, number, boolean or string\n * list is the v0.9 `Dynamic*` type of the same meaning. A component\n * reference stays one.\n *\n * Only the prop itself is made dynamic, as in the v0.9 basic catalog: the\n * 1.0 catalog marks every nested value dynamic too, which makes the\n * standard catalog several times larger.\n */\nfunction dynamicValue(schema: unknown): JsonSchema {\n if (!isRecord(schema)) return ref(\"DynamicValue\");\n const v09 = v09Schema(schema) as JsonSchema;\n if (childRefKind(schema)) return v09;\n const { description, ...literal } = v09;\n const text = typeof description === \"string\" ? { description } : {};\n const keys = Object.keys(literal);\n if (keys.length === 1 && typeof literal.type === \"string\") {\n const dynamic = DYNAMIC_TYPES[literal.type];\n if (dynamic) return { ...ref(dynamic), ...text };\n }\n const items = literal.items;\n if (\n keys.length === 2 &&\n literal.type === \"array\" &&\n isRecord(items) &&\n Object.keys(items).length === 1 &&\n items.type === \"string\"\n ) {\n return { ...ref(\"DynamicStringList\"), ...text };\n }\n return { ...text, anyOf: [literal, ref(\"DataBinding\"), ref(\"FunctionCall\")] };\n}\n\n/** A copy of a schema, with its descriptions written the v0.9 way. */\nfunction v09Schema(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(v09Schema);\n if (!isRecord(value)) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n key === \"description\" && typeof child === \"string\"\n ? v09Text(child)\n : v09Schema(child),\n ]),\n );\n}\n\nconst mapValues = (\n record: JsonSchema,\n transform: (value: unknown) => unknown,\n): JsonSchema =>\n Object.fromEntries(\n Object.entries(record).map(([key, value]) => [key, transform(value)]),\n );\n\n/** An object schema with each of its properties made dynamic. */\nfunction dynamicProperties(schema: JsonSchema): JsonSchema {\n const result = v09Schema(schema) as JsonSchema;\n if (isRecord(schema.properties)) {\n result.properties = mapValues(schema.properties, dynamicValue);\n }\n return result;\n}\n\n/**\n * Local refs (`#/...`) of a props schema, pointing to where the schema is\n * embedded in the payload instead of to the root of the props schema.\n */\nfunction rebaseRefs(value: unknown, base: string): unknown {\n if (Array.isArray(value)) return value.map((item) => rebaseRefs(item, base));\n if (!isRecord(value)) return value;\n const result = mapValues(value, (child) => rebaseRefs(child, base));\n const target = result.$ref;\n if (target === \"#\") result.$ref = base;\n else if (typeof target === \"string\" && target.startsWith(\"#/\")) {\n result.$ref = `${base}${target.slice(1)}`;\n }\n return result;\n}\n\n/** A JSON Pointer segment: `acme/Card` is `acme~1Card`. */\nfunction pointerSegment(name: string) {\n return name.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n}\n\n/**\n * One component in the v0.9 inline catalog format: `ComponentCommon` and\n * the props, events and slots of the 1.0 manifest under their v0.9 names.\n */\nfunction componentSchema(\n name: string,\n manifest: GenerativeUIComponentManifest,\n renames: Readonly<Record<string, string>>,\n): JsonSchema {\n const v09Name = (key: string) => renames[key] ?? key;\n const { properties, required, description, $defs, definitions } =\n manifest.props;\n const fields: JsonSchema = {};\n for (const [key, schema] of Object.entries(\n isRecord(properties) ? properties : {},\n )) {\n fields[key] = dynamicValue(schema);\n }\n for (const [key, event] of Object.entries(manifest.events ?? {})) {\n fields[key] = {\n ...ref(\"Action\"),\n ...(event.description ? { description: v09Text(event.description) } : {}),\n };\n }\n for (const [key, kind] of Object.entries(manifest.slots ?? {})) {\n fields[key] = ref(kind === \"single\" ? \"ComponentId\" : \"ChildList\");\n }\n const order = [...(manifest.parameterOrder ?? []), ...Object.keys(fields)];\n const ordered: JsonSchema = { component: { const: name } };\n for (const key of order) {\n if (Object.hasOwn(fields, key)) ordered[v09Name(key)] = fields[key];\n }\n // The definitions of the props schema, when its converter made some.\n const defs = {\n ...(isRecord($defs) ? { $defs: v09Schema($defs) } : {}),\n ...(isRecord(definitions) ? { definitions: v09Schema(definitions) } : {}),\n };\n const text = manifest.description ?? description;\n const body = rebaseRefs(\n {\n properties: ordered,\n required: [\n \"component\",\n ...(Array.isArray(required)\n ? required.filter((key) => typeof key === \"string\").map(v09Name)\n : []),\n ],\n ...defs,\n },\n `#/components/${pointerSegment(name)}/allOf/1`,\n ) as JsonSchema;\n return {\n ...(typeof text === \"string\" ? { description: v09Text(text) } : {}),\n allOf: [ref(\"ComponentCommon\"), body],\n };\n}\n\n/** A function in the v0.9 inline catalog `functions` format. */\nfunction functionSchema(\n name: string,\n description: string | undefined,\n returnType: string | undefined,\n parameters: JsonSchema,\n) {\n return {\n name,\n ...(description ? { description: v09Text(description) } : {}),\n // v0.9 has no `validationResult`: its checks are boolean function calls.\n returnType:\n returnType === \"validationResult\" ? \"boolean\" : (returnType ?? \"any\"),\n parameters,\n };\n}\n\n/**\n * The functions a v0.9 `{ call }` may name: the basic ones, which v0.9 names\n * the same, then the app functions the renderer may call.\n */\nfunction catalogFunctions(\n functions: Record<string, GenerativeUIFunctionManifest>,\n) {\n const result = Object.entries(A2UI_BASIC_FUNCTIONS)\n .filter(([name]) => !Object.hasOwn(functions, name))\n .map(([name, info]) =>\n functionSchema(\n name,\n info.description,\n info.returnType,\n argsSchemaFromSignature(info.parameters),\n ),\n );\n for (const [name, fn] of Object.entries(functions)) {\n if (!functionCallers(fn).renderer) continue;\n result.push(\n functionSchema(\n name,\n fn.description,\n fn.returnType,\n dynamicProperties(fn.parameters),\n ),\n );\n }\n return result;\n}\n\n/**\n * The capabilities entry: the catalog id, then the components beyond the\n * v0.9 basic catalog, by name. Their schemas are in the schema entry, so\n * they are not repeated here.\n */\nfunction capabilitiesValue(\n catalogId: string,\n names: readonly string[] | undefined,\n) {\n const lines = [\"Available A2UI catalog:\"];\n if (names === undefined) {\n lines.push(`- ${catalogId}`);\n return lines.join(\"\\n\");\n }\n const extra = names.filter((name) => !V09_BASIC_COMPONENTS.has(name));\n const nameSet = new Set(names);\n const isSuperset = [...V09_BASIC_COMPONENTS].every((name) =>\n nameSet.has(name),\n );\n if (catalogId === A2UI_V09_BASIC_CATALOG_ID && isSuperset && !extra.length) {\n lines.push(`- ${catalogId} (basic catalog)`);\n return lines.join(\"\\n\");\n }\n lines.push(`- ${catalogId}`);\n if (isSuperset) {\n lines.push(\n \" Extends the basic catalog with all standard components plus:\",\n );\n } else {\n lines.push(\" Custom catalog (does NOT include all basic components).\");\n lines.push(\" Custom components:\");\n }\n for (const name of extra) lines.push(` - ${name}`);\n return lines.join(\"\\n\");\n}\n\n/**\n * Builds the A2UI v0.9 catalog context for a run, from the generative UI\n * envelope the client sent (`forwardedProps.copilotkit.ui`).\n *\n * The entries are the ones the v0.9 client sent, with the same descriptions:\n * the catalog capabilities, the component schema (the v0.9 inline catalog\n * format that `A2UIMiddleware` reads, and replaces when it has a server\n * schema), and the v0.9 generation and design guidelines. Without the\n * component schemas in the envelope, only the capabilities entry is built.\n *\n * The components are the v0.9 basic ones of the standard catalog and the\n * UI's own components: the other standard components (Title, Chart, ...)\n * are left out, as a v0.9 agent never knew them and they would make the\n * schema about three times larger. A component of the UI's own that has the\n * name of a standard component counts as the standard one.\n *\n * Components keep their names. Props, events and slots keep their 1.0 names\n * except for `V10_TO_V09_PROP_NAMES` on standard components;\n * values take a v0.9 `{ path }` binding or `{ call }` function call, events\n * take a v0.9 action, and slots a v0.9 `ComponentId` or `ChildList`.\n *\n * The catalog id is the v0.9 basic catalog id when the UI includes the 1.0\n * standard catalog, which has every v0.9 basic component: v0.9 agents and\n * prompts already use that id, and `A2UIMiddleware` stamps the id of the\n * schema entry into the surfaces it creates. Otherwise it is the id of the\n * UI, since the basic id would promise components the UI does not have.\n *\n * @param input - The run input.\n * @returns The catalog id the v0.9 agent should use and the context\n * entries, or `undefined` when the run has no generative UI envelope.\n *\n * @example\n * ```ts\n * const v09 = buildA2UIV09CatalogContext(input);\n * if (v09) input = { ...input, context: [...input.context, ...v09.context] };\n * ```\n */\nexport function buildA2UIV09CatalogContext(input: RunAgentInput):\n | {\n catalogId: string;\n context: Array<{ description: string; value: string }>;\n }\n | undefined {\n const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n if (!envelope) return undefined;\n const manifest = envelopeToManifest(envelope);\n const extendsStandard = (\n manifest.catalogIds ?? [manifest.catalogId]\n ).includes(STANDARD_CATALOG_ID);\n const catalogId = extendsStandard\n ? A2UI_V09_BASIC_CATALOG_ID\n : manifest.catalogId;\n\n if (!manifest.hasComponents) {\n return {\n catalogId,\n context: [\n {\n description: CAPABILITIES_CONTEXT_DESCRIPTION,\n value: capabilitiesValue(catalogId, undefined),\n },\n ],\n };\n }\n\n const components: Record<string, JsonSchema> = {};\n for (const [name, component] of Object.entries(manifest.components)) {\n const isStandard =\n extendsStandard && Object.hasOwn(standardDeclarations, name);\n // Of the standard components, a v0.9 agent knows the basic ones only.\n if (isStandard && !V09_BASIC_COMPONENTS.has(name)) continue;\n const renames = (isStandard && V10_TO_V09_PROP_NAMES[name]) || {};\n components[name] = componentSchema(name, component, renames);\n }\n const schema = {\n catalogId,\n components,\n functions: catalogFunctions(manifest.functions),\n \"common_types.json\": { $defs: V09_COMMON_TYPES },\n };\n\n return {\n catalogId,\n context: [\n {\n description: CAPABILITIES_CONTEXT_DESCRIPTION,\n value: capabilitiesValue(catalogId, Object.keys(components)),\n },\n {\n description: A2UI_SCHEMA_CONTEXT_DESCRIPTION,\n value: JSON.stringify(schema),\n },\n {\n description: GENERATION_GUIDELINES_CONTEXT_DESCRIPTION,\n value: A2UI_DEFAULT_GENERATION_GUIDELINES,\n },\n {\n description: DESIGN_GUIDELINES_CONTEXT_DESCRIPTION,\n value: A2UI_DEFAULT_DESIGN_GUIDELINES,\n },\n ],\n };\n}\n"],"mappings":";;;;;;AAgCA,MAAM,4BACJ;AAMF,MAAM,mCACJ;AACF,MAAM,4CACJ;AACF,MAAM,wCACJ;;AAGF,MAAM,uBAA4C,IAAI,IAAI;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,MAAM,wBAEF,EACF,QAAQ,EAAE,SAAS,UAAU,EAC9B;AAID,MAAM,SAAS;AACf,MAAM,OAAO,UAAkB,EAAE,MAAM,GAAG,SAAS,QAAQ;;;;;AAM3D,MAAM,mBAA+C;CACnD,aAAa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C;IAC7D;GACD;IACE,aAAa;IACb,OAAO,KAAK,UAAU,OAAO;IAC9B;GACD;IACE,aAAa;IACb,OAAO;IACR;GACD;IACE,aAAa;IACb,OAAO;IACR;GACF;EACF"}
@@ -0,0 +1,84 @@
1
+ const require_a2ui_v09_actions = require('./a2ui-v09-actions.cjs');
2
+ const require_a2ui_v09_catalog = require('./a2ui-v09-catalog.cjs');
3
+ const require_a2ui_v09_operations = require('./a2ui-v09-operations.cjs');
4
+ let rxjs = require("rxjs");
5
+ let _ag_ui_client = require("@ag-ui/client");
6
+
7
+ //#region src/runtime/generative-ui/a2ui-v09-middleware.ts
8
+ /**
9
+ * The A2UI version of one agent, from the runtime's `generativeUI` option.
10
+ * Without `a2uiVersion`, and for an agent that is not in an `a2uiVersion`
11
+ * record, the version is `"1.0"`.
12
+ *
13
+ * @param generativeUI - The runtime's `generativeUI` option.
14
+ * @param agentId - The id of the agent.
15
+ * @returns `"0.9"` or `"1.0"`.
16
+ */
17
+ function resolveA2UIVersion(generativeUI, agentId) {
18
+ const option = typeof generativeUI === "object" ? generativeUI.a2uiVersion : void 0;
19
+ return (typeof option === "object" && option !== null ? option[agentId] : option) === "0.9" ? "0.9" : "1.0";
20
+ }
21
+ /**
22
+ * The input that the agent side of a run gets:
23
+ * - A click on a surface that was converted from v0.9 becomes the v0.9
24
+ * action (`forwardedProps.a2uiAction`), see {@link downgradeA2UIV09Action}.
25
+ * The input of a middleware has no activity messages (`AbstractAgent`
26
+ * removes them), so in practice `agentVersion` decides: every click of a
27
+ * run of a v0.9 agent becomes a v0.9 action.
28
+ * - For a v0.9 agent, the v0.9 component schema of the client's catalog is
29
+ * added to the context. An entry with the same description is replaced.
30
+ *
31
+ * It never mutates `input`.
32
+ */
33
+ function prepareA2UIV09AgentInput(input, agentVersion) {
34
+ const agentInput = require_a2ui_v09_actions.downgradeA2UIV09Action(input, { agentVersion });
35
+ if (agentVersion !== "0.9") return agentInput;
36
+ const catalog = require_a2ui_v09_catalog.buildA2UIV09CatalogContext(agentInput);
37
+ if (!catalog) return agentInput;
38
+ const descriptions = new Set(catalog.context.map((e) => e.description));
39
+ return {
40
+ ...agentInput,
41
+ context: [...(agentInput.context ?? []).filter((entry) => !descriptions.has(entry.description)), ...catalog.context]
42
+ };
43
+ }
44
+ /**
45
+ * Connects agents that speak A2UI v0.9 to the A2UI 1.0 client.
46
+ *
47
+ * - Input: {@link prepareA2UIV09AgentInput}. Only the agent side gets the
48
+ * changed input. The runtime stores the input of the client, so the
49
+ * thread keeps the click message.
50
+ * - Output: every `a2ui-surface` activity event becomes a
51
+ * `generative-ui-surface` event, see `createA2UIV09ActivityUpgrader`.
52
+ * The version of each operation decides, so v0.9 surfaces convert also
53
+ * for a `"1.0"` agent (for example, from a tool result), and native 1.0
54
+ * operations on this path (for example, from ADK) reach the client as 1.0
55
+ * surfaces too.
56
+ *
57
+ * The first middleware given to `agent.use` is the outermost: it sees the
58
+ * input first and the events last. Use this middleware before
59
+ * `A2UIMiddleware`, so that `A2UIMiddleware` gets the v0.9 input and this
60
+ * middleware converts the surfaces that `A2UIMiddleware` emits.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * agent.use(
65
+ * new A2UIV09BridgeMiddleware({ agentVersion: "0.9" }),
66
+ * new A2UIMiddleware({ injectA2UITool: true }),
67
+ * );
68
+ * ```
69
+ */
70
+ var A2UIV09BridgeMiddleware = class extends _ag_ui_client.Middleware {
71
+ constructor(options = {}) {
72
+ super();
73
+ this.agentVersion = options.agentVersion ?? "1.0";
74
+ }
75
+ run(input, next) {
76
+ const upgrader = require_a2ui_v09_operations.createA2UIV09ActivityUpgrader();
77
+ return this.runNext(prepareA2UIV09AgentInput(input, this.agentVersion), next).pipe((0, rxjs.concatMap)((event) => upgrader.transform(event)));
78
+ }
79
+ };
80
+
81
+ //#endregion
82
+ exports.A2UIV09BridgeMiddleware = A2UIV09BridgeMiddleware;
83
+ exports.resolveA2UIVersion = resolveA2UIVersion;
84
+ //# sourceMappingURL=a2ui-v09-middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-v09-middleware.cjs","names":["downgradeA2UIV09Action","buildA2UIV09CatalogContext","Middleware","createA2UIV09ActivityUpgrader"],"sources":["../../../src/runtime/generative-ui/a2ui-v09-middleware.ts"],"sourcesContent":["import { Middleware } from \"@ag-ui/client\";\nimport type { AbstractAgent, BaseEvent, RunAgentInput } from \"@ag-ui/client\";\nimport { concatMap } from \"rxjs\";\nimport type { Observable } from \"rxjs\";\nimport type { A2UIVersion, CopilotKitRuntimeOptions } from \"../core/runtime\";\nimport { downgradeA2UIV09Action } from \"./a2ui-v09-actions\";\nimport { buildA2UIV09CatalogContext } from \"./a2ui-v09-catalog\";\nimport { createA2UIV09ActivityUpgrader } from \"./a2ui-v09-operations\";\n\n/**\n * The A2UI version of one agent, from the runtime's `generativeUI` option.\n * Without `a2uiVersion`, and for an agent that is not in an `a2uiVersion`\n * record, the version is `\"1.0\"`.\n *\n * @param generativeUI - The runtime's `generativeUI` option.\n * @param agentId - The id of the agent.\n * @returns `\"0.9\"` or `\"1.0\"`.\n */\nexport function resolveA2UIVersion(\n generativeUI: CopilotKitRuntimeOptions[\"generativeUI\"],\n agentId: string,\n): A2UIVersion {\n const option =\n typeof generativeUI === \"object\" ? generativeUI.a2uiVersion : undefined;\n const version =\n typeof option === \"object\" && option !== null ? option[agentId] : option;\n return version === \"0.9\" ? \"0.9\" : \"1.0\";\n}\n\n/**\n * The input that the agent side of a run gets:\n * - A click on a surface that was converted from v0.9 becomes the v0.9\n * action (`forwardedProps.a2uiAction`), see {@link downgradeA2UIV09Action}.\n * The input of a middleware has no activity messages (`AbstractAgent`\n * removes them), so in practice `agentVersion` decides: every click of a\n * run of a v0.9 agent becomes a v0.9 action.\n * - For a v0.9 agent, the v0.9 component schema of the client's catalog is\n * added to the context. An entry with the same description is replaced.\n *\n * It never mutates `input`.\n */\nexport function prepareA2UIV09AgentInput(\n input: RunAgentInput,\n agentVersion: A2UIVersion,\n): RunAgentInput {\n const agentInput = downgradeA2UIV09Action(input, { agentVersion });\n if (agentVersion !== \"0.9\") return agentInput;\n const catalog = buildA2UIV09CatalogContext(agentInput);\n if (!catalog) return agentInput;\n const descriptions = new Set(catalog.context.map((e) => e.description));\n return {\n ...agentInput,\n context: [\n ...(agentInput.context ?? []).filter(\n (entry) => !descriptions.has(entry.description),\n ),\n ...catalog.context,\n ],\n };\n}\n\n/**\n * Connects agents that speak A2UI v0.9 to the A2UI 1.0 client.\n *\n * - Input: {@link prepareA2UIV09AgentInput}. Only the agent side gets the\n * changed input. The runtime stores the input of the client, so the\n * thread keeps the click message.\n * - Output: every `a2ui-surface` activity event becomes a\n * `generative-ui-surface` event, see `createA2UIV09ActivityUpgrader`.\n * The version of each operation decides, so v0.9 surfaces convert also\n * for a `\"1.0\"` agent (for example, from a tool result), and native 1.0\n * operations on this path (for example, from ADK) reach the client as 1.0\n * surfaces too.\n *\n * The first middleware given to `agent.use` is the outermost: it sees the\n * input first and the events last. Use this middleware before\n * `A2UIMiddleware`, so that `A2UIMiddleware` gets the v0.9 input and this\n * middleware converts the surfaces that `A2UIMiddleware` emits.\n *\n * @example\n * ```ts\n * agent.use(\n * new A2UIV09BridgeMiddleware({ agentVersion: \"0.9\" }),\n * new A2UIMiddleware({ injectA2UITool: true }),\n * );\n * ```\n */\nexport class A2UIV09BridgeMiddleware extends Middleware {\n private readonly agentVersion: A2UIVersion;\n\n constructor(options: { agentVersion?: A2UIVersion } = {}) {\n super();\n this.agentVersion = options.agentVersion ?? \"1.0\";\n }\n\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n const upgrader = createA2UIV09ActivityUpgrader();\n return this.runNext(\n prepareA2UIV09AgentInput(input, this.agentVersion),\n next,\n ).pipe(concatMap((event) => upgrader.transform(event)));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,mBACd,cACA,SACa;CACb,MAAM,SACJ,OAAO,iBAAiB,WAAW,aAAa,cAAc;AAGhE,SADE,OAAO,WAAW,YAAY,WAAW,OAAO,OAAO,WAAW,YACjD,QAAQ,QAAQ;;;;;;;;;;;;;;AAerC,SAAgB,yBACd,OACA,cACe;CACf,MAAM,aAAaA,gDAAuB,OAAO,EAAE,cAAc,CAAC;AAClE,KAAI,iBAAiB,MAAO,QAAO;CACnC,MAAM,UAAUC,oDAA2B,WAAW;AACtD,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,eAAe,IAAI,IAAI,QAAQ,QAAQ,KAAK,MAAM,EAAE,YAAY,CAAC;AACvE,QAAO;EACL,GAAG;EACH,SAAS,CACP,IAAI,WAAW,WAAW,EAAE,EAAE,QAC3B,UAAU,CAAC,aAAa,IAAI,MAAM,YAAY,CAChD,EACD,GAAG,QAAQ,QACZ;EACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BH,IAAa,0BAAb,cAA6CC,yBAAW;CAGtD,YAAY,UAA0C,EAAE,EAAE;AACxD,SAAO;AACP,OAAK,eAAe,QAAQ,gBAAgB;;CAG9C,IAAI,OAAsB,MAA4C;EACpE,MAAM,WAAWC,2DAA+B;AAChD,SAAO,KAAK,QACV,yBAAyB,OAAO,KAAK,aAAa,EAClD,KACD,CAAC,0BAAgB,UAAU,SAAS,UAAU,MAAM,CAAC,CAAC"}