@copilotkit/runtime 2.0.0-rc.4 → 2.0.0-rc.41

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 (357) hide show
  1. package/README.md +28 -3
  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 +16 -3
  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 +201 -29
  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 +201 -28
  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 +21 -27
  63. package/dist/index.d.cts +10 -11
  64. package/dist/index.d.mts +10 -11
  65. package/dist/index.mjs +5 -6
  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 +1 -2
  69. package/dist/node.d.cts +2 -2
  70. package/dist/node.d.mts +2 -2
  71. package/dist/node.mjs +2 -2
  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-handler.cjs +15 -12
  87. package/dist/runtime/core/fetch-handler.cjs.map +1 -1
  88. package/dist/runtime/core/fetch-handler.d.cts +8 -0
  89. package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
  90. package/dist/runtime/core/fetch-handler.d.mts +8 -0
  91. package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
  92. package/dist/runtime/core/fetch-handler.mjs +7 -3
  93. package/dist/runtime/core/fetch-handler.mjs.map +1 -1
  94. package/dist/runtime/core/learning.d.cts +1 -1
  95. package/dist/runtime/core/logger.cjs +105 -14
  96. package/dist/runtime/core/logger.cjs.map +1 -1
  97. package/dist/runtime/core/logger.d.cts +25 -8
  98. package/dist/runtime/core/logger.d.cts.map +1 -1
  99. package/dist/runtime/core/logger.d.mts +25 -8
  100. package/dist/runtime/core/logger.d.mts.map +1 -1
  101. package/dist/runtime/core/logger.mjs +105 -12
  102. package/dist/runtime/core/logger.mjs.map +1 -1
  103. package/dist/runtime/core/middleware-sse-parser.cjs +3 -4
  104. package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -1
  105. package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -1
  106. package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -1
  107. package/dist/runtime/core/middleware-sse-parser.mjs +2 -2
  108. package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -1
  109. package/dist/runtime/core/middleware.cjs +5 -5
  110. package/dist/runtime/core/middleware.cjs.map +1 -1
  111. package/dist/runtime/core/middleware.mjs +4 -3
  112. package/dist/runtime/core/middleware.mjs.map +1 -1
  113. package/dist/runtime/core/package-info.cjs +1 -1
  114. package/dist/runtime/core/package-info.mjs +1 -1
  115. package/dist/runtime/core/runtime.cjs +11 -10
  116. package/dist/runtime/core/runtime.cjs.map +1 -1
  117. package/dist/runtime/core/runtime.d.cts +22 -4
  118. package/dist/runtime/core/runtime.d.cts.map +1 -1
  119. package/dist/runtime/core/runtime.d.mts +22 -4
  120. package/dist/runtime/core/runtime.d.mts.map +1 -1
  121. package/dist/runtime/core/runtime.mjs +11 -9
  122. package/dist/runtime/core/runtime.mjs.map +1 -1
  123. package/dist/runtime/endpoints/auto-start-channels.cjs +3 -4
  124. package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -1
  125. package/dist/runtime/endpoints/auto-start-channels.mjs +2 -2
  126. package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -1
  127. package/dist/runtime/endpoints/node-fetch-handler.cjs +3 -7
  128. package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
  129. package/dist/runtime/endpoints/node-fetch-handler.d.cts +3 -4
  130. package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
  131. package/dist/runtime/endpoints/node-fetch-handler.d.mts +3 -4
  132. package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
  133. package/dist/runtime/endpoints/node-fetch-handler.mjs +3 -5
  134. package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
  135. package/dist/runtime/endpoints/node.cjs +4 -2
  136. package/dist/runtime/endpoints/node.cjs.map +1 -1
  137. package/dist/runtime/endpoints/node.d.cts.map +1 -1
  138. package/dist/runtime/endpoints/node.d.mts.map +1 -1
  139. package/dist/runtime/endpoints/node.mjs +4 -2
  140. package/dist/runtime/endpoints/node.mjs.map +1 -1
  141. package/dist/runtime/event-transforms/index.d.cts +4 -0
  142. package/dist/runtime/event-transforms/index.d.mts +4 -0
  143. package/dist/runtime/event-transforms/index.mjs +5 -0
  144. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +277 -0
  145. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  146. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts +61 -0
  147. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  148. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts +61 -0
  149. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  150. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +276 -0
  151. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  152. package/dist/runtime/event-transforms/recorded-events.cjs +58 -0
  153. package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -0
  154. package/dist/runtime/event-transforms/recorded-events.d.cts +23 -0
  155. package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -0
  156. package/dist/runtime/event-transforms/recorded-events.d.mts +23 -0
  157. package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -0
  158. package/dist/runtime/event-transforms/recorded-events.mjs +58 -0
  159. package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -0
  160. package/dist/runtime/event-transforms/streaming-json-scanner.cjs +289 -0
  161. package/dist/runtime/event-transforms/streaming-json-scanner.cjs.map +1 -0
  162. package/dist/runtime/event-transforms/streaming-json-scanner.mjs +288 -0
  163. package/dist/runtime/event-transforms/streaming-json-scanner.mjs.map +1 -0
  164. package/dist/runtime/generative-ui/generative-ui-middleware.cjs +0 -1
  165. package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -1
  166. package/dist/runtime/generative-ui/surface-writer.cjs +4 -5
  167. package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -1
  168. package/dist/runtime/generative-ui/surface-writer.d.cts +1 -1
  169. package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -1
  170. package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -1
  171. package/dist/runtime/generative-ui/surface-writer.mjs +5 -5
  172. package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -1
  173. package/dist/runtime/handlers/get-runtime-info.cjs +5 -1
  174. package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
  175. package/dist/runtime/handlers/get-runtime-info.mjs +5 -1
  176. package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
  177. package/dist/runtime/handlers/handle-connect.cjs +3 -8
  178. package/dist/runtime/handlers/handle-connect.cjs.map +1 -1
  179. package/dist/runtime/handlers/handle-connect.mjs +3 -8
  180. package/dist/runtime/handlers/handle-connect.mjs.map +1 -1
  181. package/dist/runtime/handlers/handle-inspector-learning.cjs +2 -3
  182. package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -1
  183. package/dist/runtime/handlers/handle-inspector-metadata.cjs +2 -3
  184. package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -1
  185. package/dist/runtime/handlers/handle-run.cjs +11 -14
  186. package/dist/runtime/handlers/handle-run.cjs.map +1 -1
  187. package/dist/runtime/handlers/handle-run.mjs +8 -10
  188. package/dist/runtime/handlers/handle-run.mjs.map +1 -1
  189. package/dist/runtime/handlers/handle-stop.cjs +5 -5
  190. package/dist/runtime/handlers/handle-stop.cjs.map +1 -1
  191. package/dist/runtime/handlers/handle-stop.mjs +2 -1
  192. package/dist/runtime/handlers/handle-stop.mjs.map +1 -1
  193. package/dist/runtime/handlers/handle-suggest.cjs +6 -3
  194. package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
  195. package/dist/runtime/handlers/handle-suggest.mjs +6 -2
  196. package/dist/runtime/handlers/handle-suggest.mjs.map +1 -1
  197. package/dist/runtime/handlers/handle-transcribe.cjs +0 -1
  198. package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -1
  199. package/dist/runtime/handlers/intelligence/annotate.cjs +8 -8
  200. package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -1
  201. package/dist/runtime/handlers/intelligence/annotate.mjs +4 -3
  202. package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -1
  203. package/dist/runtime/handlers/intelligence/connect.cjs +6 -2
  204. package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -1
  205. package/dist/runtime/handlers/intelligence/connect.mjs +6 -2
  206. package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -1
  207. package/dist/runtime/handlers/intelligence/memories.cjs +27 -22
  208. package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -1
  209. package/dist/runtime/handlers/intelligence/memories.mjs +11 -5
  210. package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -1
  211. package/dist/runtime/handlers/intelligence/run.cjs +38 -30
  212. package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
  213. package/dist/runtime/handlers/intelligence/run.mjs +37 -28
  214. package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
  215. package/dist/runtime/handlers/intelligence/thread-names.cjs +6 -5
  216. package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
  217. package/dist/runtime/handlers/intelligence/thread-names.mjs +3 -1
  218. package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
  219. package/dist/runtime/handlers/intelligence/threads.cjs +36 -27
  220. package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -1
  221. package/dist/runtime/handlers/intelligence/threads.mjs +13 -3
  222. package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -1
  223. package/dist/runtime/handlers/shared/agent-utils.cjs +35 -34
  224. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  225. package/dist/runtime/handlers/shared/agent-utils.mjs +29 -27
  226. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  227. package/dist/runtime/handlers/shared/cloud-telemetry.cjs +0 -1
  228. package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -1
  229. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +4 -3
  230. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
  231. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +4 -3
  232. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
  233. package/dist/runtime/handlers/shared/sse-response.cjs +77 -78
  234. package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -1
  235. package/dist/runtime/handlers/shared/sse-response.mjs +77 -77
  236. package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -1
  237. package/dist/runtime/handlers/shared/thread-access.cjs +3 -2
  238. package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -1
  239. package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -1
  240. package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -1
  241. package/dist/runtime/handlers/shared/thread-access.mjs +3 -2
  242. package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -1
  243. package/dist/runtime/handlers/sse/connect.cjs +2 -0
  244. package/dist/runtime/handlers/sse/connect.cjs.map +1 -1
  245. package/dist/runtime/handlers/sse/connect.mjs +2 -0
  246. package/dist/runtime/handlers/sse/connect.mjs.map +1 -1
  247. package/dist/runtime/handlers/sse/run.cjs +5 -2
  248. package/dist/runtime/handlers/sse/run.cjs.map +1 -1
  249. package/dist/runtime/handlers/sse/run.mjs +5 -2
  250. package/dist/runtime/handlers/sse/run.mjs.map +1 -1
  251. package/dist/runtime/index.d.cts +9 -15
  252. package/dist/runtime/index.d.mts +9 -15
  253. package/dist/runtime/intelligence-platform/analytics-context.cjs +84 -0
  254. package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -0
  255. package/dist/runtime/intelligence-platform/analytics-context.mjs +83 -0
  256. package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -0
  257. package/dist/runtime/intelligence-platform/client.cjs +27 -1
  258. package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
  259. package/dist/runtime/intelligence-platform/client.d.cts +24 -1
  260. package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
  261. package/dist/runtime/intelligence-platform/client.d.mts +24 -1
  262. package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
  263. package/dist/runtime/intelligence-platform/client.mjs +27 -0
  264. package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
  265. package/dist/runtime/intelligence-platform/learning-management.cjs +7 -8
  266. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
  267. package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
  268. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
  269. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -110
  270. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
  271. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
  272. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
  273. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
  274. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
  275. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
  276. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
  277. package/dist/runtime/intelligence-platform/skill-registry/config.cjs +0 -1
  278. package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
  279. package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +1 -1
  280. package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +1 -1
  281. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +22 -19
  282. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
  283. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
  284. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
  285. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +22 -19
  286. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
  287. package/dist/runtime/intelligence-platform/stop-run.cjs +50 -0
  288. package/dist/runtime/intelligence-platform/stop-run.cjs.map +1 -0
  289. package/dist/runtime/intelligence-platform/stop-run.mjs +50 -0
  290. package/dist/runtime/intelligence-platform/stop-run.mjs.map +1 -0
  291. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +3 -3
  292. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
  293. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +2 -1
  294. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -1
  295. package/dist/runtime/intelligence-platform/trajectories.cjs +2 -3
  296. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
  297. package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
  298. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
  299. package/dist/runtime/node.d.cts +1 -1
  300. package/dist/runtime/node.d.mts +1 -1
  301. package/dist/runtime/runner/agent-runner.cjs +0 -1
  302. package/dist/runtime/runner/agent-runner.cjs.map +1 -1
  303. package/dist/runtime/runner/agent-runner.d.cts +9 -0
  304. package/dist/runtime/runner/agent-runner.d.cts.map +1 -1
  305. package/dist/runtime/runner/agent-runner.d.mts +9 -0
  306. package/dist/runtime/runner/agent-runner.d.mts.map +1 -1
  307. package/dist/runtime/runner/agent-runner.mjs.map +1 -1
  308. package/dist/runtime/runner/in-memory.cjs +0 -1
  309. package/dist/runtime/runner/in-memory.cjs.map +1 -1
  310. package/dist/runtime/runner/index.d.cts +1 -1
  311. package/dist/runtime/runner/index.d.mts +1 -1
  312. package/dist/runtime/runner/index.mjs +1 -1
  313. package/dist/runtime/runner/intelligence.cjs +55 -9
  314. package/dist/runtime/runner/intelligence.cjs.map +1 -1
  315. package/dist/runtime/runner/intelligence.d.cts +12 -1
  316. package/dist/runtime/runner/intelligence.d.cts.map +1 -1
  317. package/dist/runtime/runner/intelligence.d.mts +12 -1
  318. package/dist/runtime/runner/intelligence.d.mts.map +1 -1
  319. package/dist/runtime/runner/intelligence.mjs +56 -10
  320. package/dist/runtime/runner/intelligence.mjs.map +1 -1
  321. package/dist/runtime/telemetry/disclosure.cjs +2 -3
  322. package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
  323. package/dist/runtime/telemetry/disclosure.mjs +3 -3
  324. package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
  325. package/dist/runtime/telemetry/events.d.cts +1 -1
  326. package/dist/runtime/telemetry/events.d.mts +1 -1
  327. package/dist/runtime/telemetry/instance-created.cjs +33 -12
  328. package/dist/runtime/telemetry/instance-created.cjs.map +1 -1
  329. package/dist/runtime/telemetry/instance-created.mjs +33 -12
  330. package/dist/runtime/telemetry/instance-created.mjs.map +1 -1
  331. package/dist/runtime/telemetry/telemetry-client.cjs +0 -5
  332. package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
  333. package/dist/runtime/telemetry/telemetry-client.mjs +0 -4
  334. package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
  335. package/dist/runtime/telemetry/telemetry-identity.cjs +0 -1
  336. package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -1
  337. package/package.json +55 -30
  338. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  339. package/dist/agent/converters/index.d.mts +0 -2
  340. package/dist/agent/index.cjs +0 -1328
  341. package/dist/agent/index.cjs.map +0 -1
  342. package/dist/agent/index.d.cts +0 -467
  343. package/dist/agent/index.d.cts.map +0 -1
  344. package/dist/agent/index.d.mts +0 -468
  345. package/dist/agent/index.d.mts.map +0 -1
  346. package/dist/agent/index.mjs +0 -1318
  347. package/dist/agent/index.mjs.map +0 -1
  348. package/dist/agent/mcp-tool-names.cjs +0 -82
  349. package/dist/agent/mcp-tool-names.cjs.map +0 -1
  350. package/dist/agent/mcp-tool-names.mjs +0 -80
  351. package/dist/agent/mcp-tool-names.mjs.map +0 -1
  352. package/dist/agent/url-download.cjs.map +0 -1
  353. package/dist/agent/url-download.d.cts.map +0 -1
  354. package/dist/agent/url-download.d.mts.map +0 -1
  355. package/dist/agent/url-download.mjs.map +0 -1
  356. package/dist/runtime/index.d.cts.map +0 -1
  357. package/dist/runtime/index.d.mts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"node.mjs","names":[],"sources":["../../../src/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n autoStartChannels(listener.channels);\n return listener;\n}\n"],"mappings":";;;;;AA8GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,WAAgC,yBAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,mBAAkB,SAAS,SAAS;AACpC,QAAO"}
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../../../src/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\nimport { getRuntimeLogger } from \"../core/logger\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const logger = getRuntimeLogger(options.runtime);\n const listener: NodeCopilotListener = createCopilotNodeHandler(\n handler,\n logger,\n );\n listener.channels = handler.channels;\n autoStartChannels(listener.channels, logger);\n return listener;\n}\n"],"mappings":";;;;;;AA+GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,SAAS,iBAAiB,QAAQ,QAAQ;CAChD,MAAM,WAAgC,yBACpC,SACA,OACD;AACD,UAAS,WAAW,QAAQ;AAC5B,mBAAkB,SAAS,UAAU,OAAO;AAC5C,QAAO"}
@@ -0,0 +1,4 @@
1
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.cjs";
2
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.cjs";
3
+ import { A2UIMiddleware, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
4
+ export { A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
@@ -0,0 +1,4 @@
1
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
2
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.mjs";
3
+ import { A2UIMiddleware as A2UIMiddleware$1, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
4
+ export { A2UIMiddleware$1 as A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
@@ -0,0 +1,5 @@
1
+ import { ArgsParser, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
2
+ import { transformRecordedEvents } from "./recorded-events.mjs";
3
+ import { A2UIMiddleware as A2UIMiddleware$1 } from "@ag-ui/a2ui-middleware";
4
+
5
+ export { A2UIMiddleware$1 as A2UIMiddleware };
@@ -0,0 +1,277 @@
1
+ const require_streaming_json_scanner = require('./streaming-json-scanner.cjs');
2
+ let rxjs = require("rxjs");
3
+ let _ag_ui_client = require("@ag-ui/client");
4
+
5
+ //#region src/runtime/event-transforms/open-generative-ui-middleware.ts
6
+ const TOOL_NAME = "generateSandboxedUi";
7
+ const ACTIVITY_TYPE = "open-generative-ui";
8
+ /**
9
+ * Tracks incremental JSON parsing state for a single tool call's arguments.
10
+ * Emits activity events via the onEvent callback as parameters complete.
11
+ */
12
+ var ArgsParser = class {
13
+ constructor(toolCallId, onEvent) {
14
+ this.currentKey = null;
15
+ this.depth = 0;
16
+ this.currentArrayKey = null;
17
+ this.snapshotEmitted = false;
18
+ this.streamingHtmlKey = false;
19
+ this.htmlEmittedLength = 0;
20
+ this.htmlArrayEmitted = false;
21
+ this.params = {};
22
+ this.messageId = `${toolCallId}-activity`;
23
+ this.onEvent = onEvent;
24
+ this.scanner = new require_streaming_json_scanner.StreamingJsonScanner({
25
+ onOpenObject: () => {
26
+ this.depth++;
27
+ },
28
+ onKey: (key) => {
29
+ if (this.depth === 1) {
30
+ this.currentKey = key;
31
+ this.initHtmlStreaming(key);
32
+ }
33
+ },
34
+ onValue: (value) => {
35
+ if (this.depth === 1 && this.currentKey) if (this.currentArrayKey) {
36
+ const strValue = String(value);
37
+ if (this.currentArrayKey === "jsExpressions") {
38
+ if (!this.params.jsExpressions) this.params.jsExpressions = [];
39
+ this.params.jsExpressions.push(strValue);
40
+ } else if (this.currentArrayKey === "placeholderMessages") {
41
+ if (!this.params.placeholderMessages) this.params.placeholderMessages = [];
42
+ this.params.placeholderMessages.push(strValue);
43
+ }
44
+ this.emitArrayItemDelta(this.currentArrayKey, strValue);
45
+ } else if (this.streamingHtmlKey) {
46
+ const fullHtml = value != null ? String(value) : "";
47
+ this.params.html = fullHtml || void 0;
48
+ this.emitPendingHtml(fullHtml);
49
+ this.emitParamDelta("htmlComplete", true);
50
+ this.streamingHtmlKey = false;
51
+ } else this.setParam(this.currentKey, value);
52
+ },
53
+ onOpenArray: () => {
54
+ if (this.depth === 1 && this.currentKey) {
55
+ const key = this.currentKey;
56
+ if (key === "jsExpressions" || key === "placeholderMessages") {
57
+ this.currentArrayKey = key;
58
+ if (key === "jsExpressions") this.params.jsExpressions = [];
59
+ else this.params.placeholderMessages = [];
60
+ this.emitParamDelta(key, []);
61
+ }
62
+ }
63
+ },
64
+ onCloseArray: () => {
65
+ if (this.depth === 1) {
66
+ if (this.currentArrayKey === "jsExpressions") this.emitParamDelta("jsExpressionsComplete", true);
67
+ this.currentArrayKey = null;
68
+ }
69
+ },
70
+ onCloseObject: () => {
71
+ this.depth--;
72
+ }
73
+ });
74
+ }
75
+ write(chunk) {
76
+ this.scanner.write(chunk);
77
+ this.flushHtmlChunks();
78
+ }
79
+ initHtmlStreaming(key) {
80
+ if (key === "html") {
81
+ this.streamingHtmlKey = true;
82
+ this.htmlEmittedLength = 0;
83
+ this.htmlArrayEmitted = false;
84
+ }
85
+ }
86
+ /**
87
+ * Emit the html read so far while the html string streams in.
88
+ * Called after every write(). It reads only while the top-level `html`
89
+ * value is being read, so a nested string is never emitted as html.
90
+ */
91
+ flushHtmlChunks() {
92
+ if (!this.streamingHtmlKey || this.depth !== 1) return;
93
+ const partialHtml = this.scanner.partialString;
94
+ if (partialHtml === void 0) return;
95
+ if (partialHtml.length === this.htmlEmittedLength) return;
96
+ this.emitPendingHtml(partialHtml);
97
+ }
98
+ /**
99
+ * Emit accumulated html content since the last emission.
100
+ * Called by flushHtmlChunks and directly when html completes.
101
+ */
102
+ emitPendingHtml(html) {
103
+ const newContent = html.slice(this.htmlEmittedLength);
104
+ if (newContent.length === 0) return;
105
+ if (!this.htmlArrayEmitted) {
106
+ this.htmlArrayEmitted = true;
107
+ this.emitParamDelta("html", []);
108
+ }
109
+ this.emitArrayItemDelta("html", newContent);
110
+ this.htmlEmittedLength = html.length;
111
+ }
112
+ setParam(key, value) {
113
+ switch (key) {
114
+ case "initialHeight":
115
+ this.params.initialHeight = typeof value === "number" ? value : void 0;
116
+ if (this.snapshotEmitted) this.emitParamDelta("initialHeight", this.params.initialHeight);
117
+ else this.emitSnapshot();
118
+ break;
119
+ case "css":
120
+ this.params.css = value != null ? String(value) : void 0;
121
+ this.emitParamDelta("css", this.params.css);
122
+ this.emitParamDelta("cssComplete", true);
123
+ break;
124
+ case "jsFunctions":
125
+ this.params.jsFunctions = value != null ? String(value) : void 0;
126
+ this.emitParamDelta("jsFunctions", this.params.jsFunctions);
127
+ this.emitParamDelta("jsFunctionsComplete", true);
128
+ break;
129
+ }
130
+ }
131
+ emitSnapshot() {
132
+ if (this.snapshotEmitted) return;
133
+ this.snapshotEmitted = true;
134
+ const event = {
135
+ type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
136
+ messageId: this.messageId,
137
+ activityType: ACTIVITY_TYPE,
138
+ content: {
139
+ initialHeight: this.params.initialHeight,
140
+ generating: true
141
+ }
142
+ };
143
+ this.onEvent(event);
144
+ }
145
+ emitParamDelta(key, value) {
146
+ if (value === void 0) return;
147
+ this.emitSnapshot();
148
+ const event = {
149
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
150
+ messageId: this.messageId,
151
+ activityType: ACTIVITY_TYPE,
152
+ patch: [{
153
+ op: "add",
154
+ path: `/${key}`,
155
+ value
156
+ }]
157
+ };
158
+ this.onEvent(event);
159
+ }
160
+ emitArrayItemDelta(arrayKey, value) {
161
+ this.emitSnapshot();
162
+ const event = {
163
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
164
+ messageId: this.messageId,
165
+ activityType: ACTIVITY_TYPE,
166
+ patch: [{
167
+ op: "add",
168
+ path: `/${arrayKey}/-`,
169
+ value
170
+ }]
171
+ };
172
+ this.onEvent(event);
173
+ }
174
+ };
175
+ var OpenGenerativeUIMiddleware = class extends _ag_ui_client.Middleware {
176
+ run(input, next) {
177
+ return this.processStream(this.runNextWithState(input, next));
178
+ }
179
+ processStream(source) {
180
+ return new rxjs.Observable((subscriber) => {
181
+ let heldRunFinished = null;
182
+ const activeParsers = /* @__PURE__ */ new Map();
183
+ const heldToolCallEvents = /* @__PURE__ */ new Map();
184
+ const flushedToolCalls = /* @__PURE__ */ new Set();
185
+ const flushHeldEvents = (toolCallId) => {
186
+ if (flushedToolCalls.has(toolCallId)) return;
187
+ flushedToolCalls.add(toolCallId);
188
+ const held = heldToolCallEvents.get(toolCallId);
189
+ if (held) {
190
+ for (const e of held) subscriber.next(e);
191
+ heldToolCallEvents.delete(toolCallId);
192
+ }
193
+ };
194
+ const subscription = source.subscribe({
195
+ next: (eventWithState) => {
196
+ const event = eventWithState.event;
197
+ if (heldRunFinished) {
198
+ subscriber.next(heldRunFinished.event);
199
+ heldRunFinished = null;
200
+ }
201
+ if (event.type === _ag_ui_client.EventType.RUN_FINISHED) {
202
+ heldRunFinished = eventWithState;
203
+ return;
204
+ }
205
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_START) {
206
+ const startEvent = event;
207
+ if (startEvent.toolCallName === TOOL_NAME) {
208
+ heldToolCallEvents.set(startEvent.toolCallId, [event]);
209
+ activeParsers.set(startEvent.toolCallId, new ArgsParser(startEvent.toolCallId, (activityEvent) => {
210
+ subscriber.next(activityEvent);
211
+ flushHeldEvents(startEvent.toolCallId);
212
+ }));
213
+ return;
214
+ }
215
+ }
216
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_ARGS) {
217
+ const argsEvent = event;
218
+ const parser = activeParsers.get(argsEvent.toolCallId);
219
+ if (parser) {
220
+ if (!flushedToolCalls.has(argsEvent.toolCallId)) heldToolCallEvents.get(argsEvent.toolCallId).push(event);
221
+ else subscriber.next(event);
222
+ parser.write(argsEvent.delta);
223
+ return;
224
+ }
225
+ }
226
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_END) {
227
+ const endEvent = event;
228
+ const parser = activeParsers.get(endEvent.toolCallId);
229
+ if (parser) {
230
+ const completeEvent = {
231
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
232
+ messageId: parser.messageId,
233
+ activityType: ACTIVITY_TYPE,
234
+ patch: [{
235
+ op: "add",
236
+ path: "/generating",
237
+ value: false
238
+ }]
239
+ };
240
+ subscriber.next(completeEvent);
241
+ if (!flushedToolCalls.has(endEvent.toolCallId)) heldToolCallEvents.get(endEvent.toolCallId).push(event);
242
+ else subscriber.next(event);
243
+ return;
244
+ }
245
+ }
246
+ subscriber.next(event);
247
+ },
248
+ error: (err) => {
249
+ for (const [, events] of heldToolCallEvents) for (const event of events) subscriber.next(event);
250
+ heldToolCallEvents.clear();
251
+ if (heldRunFinished) {
252
+ subscriber.next(heldRunFinished.event);
253
+ heldRunFinished = null;
254
+ }
255
+ subscriber.error(err);
256
+ },
257
+ complete: () => {
258
+ heldToolCallEvents.forEach((_, toolCallId) => {
259
+ flushHeldEvents(toolCallId);
260
+ });
261
+ if (heldRunFinished) {
262
+ subscriber.next(heldRunFinished.event);
263
+ heldRunFinished = null;
264
+ }
265
+ activeParsers.clear();
266
+ subscriber.complete();
267
+ }
268
+ });
269
+ return () => subscription.unsubscribe();
270
+ });
271
+ }
272
+ };
273
+
274
+ //#endregion
275
+ exports.ArgsParser = ArgsParser;
276
+ exports.OpenGenerativeUIMiddleware = OpenGenerativeUIMiddleware;
277
+ //# sourceMappingURL=open-generative-ui-middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-generative-ui-middleware.cjs","names":["StreamingJsonScanner","EventType","Middleware","Observable"],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"sourcesContent":["import type {\n RunAgentInput,\n AbstractAgent,\n BaseEvent,\n ToolCallStartEvent,\n ToolCallArgsEvent,\n ActivitySnapshotEventProps,\n ActivityDeltaEvent,\n} from \"@ag-ui/client\";\nimport { Middleware, EventType } from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport { StreamingJsonScanner } from \"./streaming-json-scanner\";\nimport type { JsonScalar } from \"./streaming-json-scanner\";\n\nconst TOOL_NAME = \"generateSandboxedUi\";\nconst ACTIVITY_TYPE = \"open-generative-ui\";\n\n/**\n * Parsed parameters from the generateSandboxedUi tool call.\n */\nexport interface GenerateSandboxedUIParams {\n initialHeight?: number;\n placeholderMessages?: string[];\n css?: string;\n html?: string;\n jsFunctions?: string;\n jsExpressions?: string[];\n}\n\n/**\n * Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.\n */\nexport type OnParamEvent = (event: BaseEvent) => void;\n\n/**\n * Tracks incremental JSON parsing state for a single tool call's arguments.\n * Emits activity events via the onEvent callback as parameters complete.\n */\nexport class ArgsParser {\n private readonly scanner: StreamingJsonScanner;\n private currentKey: string | null = null;\n private depth = 0;\n private currentArrayKey: string | null = null;\n private snapshotEmitted = false;\n\n // Streaming html state. flushHtmlChunks reads scanner.partialString to emit\n // the html in chunks while it streams in.\n private streamingHtmlKey = false;\n private htmlEmittedLength = 0;\n private htmlArrayEmitted = false;\n\n public readonly params: GenerateSandboxedUIParams = {};\n public readonly messageId: string;\n private readonly onEvent: OnParamEvent;\n\n constructor(toolCallId: string, onEvent: OnParamEvent) {\n this.messageId = `${toolCallId}-activity`;\n this.onEvent = onEvent;\n // The scanner skips bad characters and warns by itself, so no error\n // handler is needed here.\n this.scanner = new StreamingJsonScanner({\n onOpenObject: () => {\n this.depth++;\n },\n\n onKey: (key) => {\n if (this.depth === 1) {\n this.currentKey = key;\n this.initHtmlStreaming(key);\n }\n },\n\n onValue: (value) => {\n if (this.depth === 1 && this.currentKey) {\n if (this.currentArrayKey) {\n const strValue = String(value);\n if (this.currentArrayKey === \"jsExpressions\") {\n if (!this.params.jsExpressions) this.params.jsExpressions = [];\n this.params.jsExpressions.push(strValue);\n } else if (this.currentArrayKey === \"placeholderMessages\") {\n if (!this.params.placeholderMessages)\n this.params.placeholderMessages = [];\n this.params.placeholderMessages.push(strValue);\n }\n this.emitArrayItemDelta(this.currentArrayKey, strValue);\n } else if (this.streamingHtmlKey) {\n // The html string is complete. Emit the rest of it now, then htmlComplete.\n const fullHtml = value != null ? String(value) : \"\";\n this.params.html = fullHtml || undefined;\n this.emitPendingHtml(fullHtml);\n this.emitParamDelta(\"htmlComplete\", true);\n this.streamingHtmlKey = false;\n } else {\n this.setParam(this.currentKey, value);\n }\n }\n },\n\n onOpenArray: () => {\n if (this.depth === 1 && this.currentKey) {\n const key = this.currentKey;\n if (key === \"jsExpressions\" || key === \"placeholderMessages\") {\n this.currentArrayKey = key;\n if (key === \"jsExpressions\") this.params.jsExpressions = [];\n else this.params.placeholderMessages = [];\n // Emit a delta to create the array in the activity content.\n // Subsequent \"add\" ops with path \"/<key>/-\" append to this array.\n this.emitParamDelta(key, []);\n }\n }\n },\n\n onCloseArray: () => {\n if (this.depth === 1) {\n if (this.currentArrayKey === \"jsExpressions\") {\n this.emitParamDelta(\"jsExpressionsComplete\", true);\n }\n this.currentArrayKey = null;\n }\n },\n\n onCloseObject: () => {\n this.depth--;\n },\n });\n }\n\n write(chunk: string) {\n this.scanner.write(chunk);\n this.flushHtmlChunks();\n }\n\n private initHtmlStreaming(key: string) {\n if (key === \"html\") {\n this.streamingHtmlKey = true;\n this.htmlEmittedLength = 0;\n this.htmlArrayEmitted = false;\n }\n }\n\n /**\n * Emit the html read so far while the html string streams in.\n * Called after every write(). It reads only while the top-level `html`\n * value is being read, so a nested string is never emitted as html.\n */\n private flushHtmlChunks() {\n if (!this.streamingHtmlKey || this.depth !== 1) return;\n const partialHtml = this.scanner.partialString;\n if (partialHtml === undefined) return;\n if (partialHtml.length === this.htmlEmittedLength) return;\n\n this.emitPendingHtml(partialHtml);\n }\n\n /**\n * Emit accumulated html content since the last emission.\n * Called by flushHtmlChunks and directly when html completes.\n */\n private emitPendingHtml(html: string) {\n const newContent = html.slice(this.htmlEmittedLength);\n if (newContent.length === 0) return;\n\n if (!this.htmlArrayEmitted) {\n this.htmlArrayEmitted = true;\n this.emitParamDelta(\"html\", []);\n }\n this.emitArrayItemDelta(\"html\", newContent);\n this.htmlEmittedLength = html.length;\n }\n\n private setParam(key: string, value: JsonScalar) {\n switch (key) {\n case \"initialHeight\":\n this.params.initialHeight =\n typeof value === \"number\" ? value : undefined;\n if (this.snapshotEmitted) {\n // Snapshot already went out (another param parsed first) — deliver\n // the height as a delta instead.\n this.emitParamDelta(\"initialHeight\", this.params.initialHeight);\n } else {\n this.emitSnapshot();\n }\n break;\n case \"css\":\n this.params.css = value != null ? String(value) : undefined;\n this.emitParamDelta(\"css\", this.params.css);\n this.emitParamDelta(\"cssComplete\", true);\n break;\n case \"jsFunctions\":\n this.params.jsFunctions = value != null ? String(value) : undefined;\n this.emitParamDelta(\"jsFunctions\", this.params.jsFunctions);\n this.emitParamDelta(\"jsFunctionsComplete\", true);\n break;\n }\n }\n\n private emitSnapshot() {\n if (this.snapshotEmitted) return;\n this.snapshotEmitted = true;\n\n const event = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n content: { initialHeight: this.params.initialHeight, generating: true },\n } satisfies ActivitySnapshotEventProps;\n this.onEvent(event);\n }\n\n private emitParamDelta(key: string, value: unknown) {\n // A JSON Patch \"add\" requires a value; emitting one without it (e.g. when\n // the LLM sends a null/empty jsFunctions or css) makes fast-json-patch\n // reject the whole patch client-side with OPERATION_VALUE_REQUIRED and\n // drops it. Skip the delta when there's nothing to add.\n if (value === undefined) return;\n // The activity message must exist before any delta can be applied —\n // the client silently drops ACTIVITY_DELTA events whose messageId has\n // no prior ACTIVITY_SNAPSHOT. The LLM controls the key order of the\n // streamed args, so the snapshot cannot wait for initialHeight.\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${key}`, value }],\n };\n this.onEvent(event);\n }\n\n private emitArrayItemDelta(arrayKey: string, value: string) {\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${arrayKey}/-`, value }],\n };\n this.onEvent(event);\n }\n}\n\n/**\n * Extract EventWithState type from Middleware.runNextWithState return type\n */\ntype ExtractObservableType<T> = T extends Observable<infer U> ? U : never;\ntype RunNextWithStateReturn = ReturnType<Middleware[\"runNextWithState\"]>;\ntype EventWithState = ExtractObservableType<RunNextWithStateReturn>;\n\nexport class OpenGenerativeUIMiddleware extends Middleware {\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n return this.processStream(this.runNextWithState(input, next));\n }\n\n private processStream(\n source: Observable<EventWithState>,\n ): Observable<BaseEvent> {\n return new Observable<BaseEvent>((subscriber) => {\n let heldRunFinished: EventWithState | null = null;\n // Track active generateSandboxedUi tool call IDs → their streaming parser\n const activeParsers = new Map<string, ArgsParser>();\n // Hold genui tool call events until the first activity event is emitted\n const heldToolCallEvents = new Map<string, BaseEvent[]>();\n const flushedToolCalls = new Set<string>();\n\n const flushHeldEvents = (toolCallId: string) => {\n if (flushedToolCalls.has(toolCallId)) return;\n flushedToolCalls.add(toolCallId);\n const held = heldToolCallEvents.get(toolCallId);\n if (held) {\n for (const e of held) {\n subscriber.next(e);\n }\n heldToolCallEvents.delete(toolCallId);\n }\n };\n\n const subscription = source.subscribe({\n next: (eventWithState) => {\n const event = eventWithState.event;\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n\n if (event.type === EventType.RUN_FINISHED) {\n heldRunFinished = eventWithState;\n return;\n }\n\n // Hold TOOL_CALL_START for genui until the first activity event\n if (event.type === EventType.TOOL_CALL_START) {\n const startEvent = event as ToolCallStartEvent;\n if (startEvent.toolCallName === TOOL_NAME) {\n heldToolCallEvents.set(startEvent.toolCallId, [event]);\n activeParsers.set(\n startEvent.toolCallId,\n new ArgsParser(startEvent.toolCallId, (activityEvent) => {\n subscriber.next(activityEvent);\n flushHeldEvents(startEvent.toolCallId);\n }),\n );\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_ARGS for genui tool calls\n if (event.type === EventType.TOOL_CALL_ARGS) {\n const argsEvent = event as ToolCallArgsEvent;\n const parser = activeParsers.get(argsEvent.toolCallId);\n if (parser) {\n if (!flushedToolCalls.has(argsEvent.toolCallId)) {\n heldToolCallEvents.get(argsEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n parser.write(argsEvent.delta);\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_END for genui tool calls\n if (event.type === EventType.TOOL_CALL_END) {\n const endEvent = event as { toolCallId: string } & BaseEvent;\n const parser = activeParsers.get(endEvent.toolCallId);\n if (parser) {\n // Mark generation complete\n const completeEvent: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: parser.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: \"/generating\", value: false }],\n };\n subscriber.next(completeEvent);\n\n if (!flushedToolCalls.has(endEvent.toolCallId)) {\n heldToolCallEvents.get(endEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n return;\n }\n }\n\n subscriber.next(event);\n },\n error: (err) => {\n // Flush any held tool call events so downstream sees them before the error\n for (const [, events] of heldToolCallEvents) {\n for (const event of events) {\n subscriber.next(event);\n }\n }\n heldToolCallEvents.clear();\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n subscriber.error(err);\n },\n complete: () => {\n // Flush any remaining held tool call events (e.g. parser never emitted)\n heldToolCallEvents.forEach((_, toolCallId) => {\n flushHeldEvents(toolCallId);\n });\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n activeParsers.clear();\n subscriber.complete();\n },\n });\n\n return () => subscription.unsubscribe();\n });\n }\n}\n"],"mappings":";;;;;AAcA,MAAM,YAAY;AAClB,MAAM,gBAAgB;;;;;AAuBtB,IAAa,aAAb,MAAwB;CAiBtB,YAAY,YAAoB,SAAuB;oBAfnB;eACpB;yBACyB;yBACf;0BAIC;2BACC;0BACD;gBAEyB,EAAE;AAKpD,OAAK,YAAY,GAAG,WAAW;AAC/B,OAAK,UAAU;AAGf,OAAK,UAAU,IAAIA,oDAAqB;GACtC,oBAAoB;AAClB,SAAK;;GAGP,QAAQ,QAAQ;AACd,QAAI,KAAK,UAAU,GAAG;AACpB,UAAK,aAAa;AAClB,UAAK,kBAAkB,IAAI;;;GAI/B,UAAU,UAAU;AAClB,QAAI,KAAK,UAAU,KAAK,KAAK,WAC3B,KAAI,KAAK,iBAAiB;KACxB,MAAM,WAAW,OAAO,MAAM;AAC9B,SAAI,KAAK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B,mBAAc,OAAO;AACrB,gBAAW,UAAU;;IAExB,CAAC;AAEF,gBAAa,aAAa,aAAa;IACvC"}
@@ -0,0 +1,61 @@
1
+ import { AbstractAgent, BaseEvent, Middleware, RunAgentInput } from "@ag-ui/client";
2
+ import { Observable } from "rxjs";
3
+
4
+ //#region src/runtime/event-transforms/open-generative-ui-middleware.d.ts
5
+ /**
6
+ * Parsed parameters from the generateSandboxedUi tool call.
7
+ */
8
+ interface GenerateSandboxedUIParams {
9
+ initialHeight?: number;
10
+ placeholderMessages?: string[];
11
+ css?: string;
12
+ html?: string;
13
+ jsFunctions?: string;
14
+ jsExpressions?: string[];
15
+ }
16
+ /**
17
+ * Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.
18
+ */
19
+ type OnParamEvent = (event: BaseEvent) => void;
20
+ /**
21
+ * Tracks incremental JSON parsing state for a single tool call's arguments.
22
+ * Emits activity events via the onEvent callback as parameters complete.
23
+ */
24
+ declare class ArgsParser {
25
+ private readonly scanner;
26
+ private currentKey;
27
+ private depth;
28
+ private currentArrayKey;
29
+ private snapshotEmitted;
30
+ private streamingHtmlKey;
31
+ private htmlEmittedLength;
32
+ private htmlArrayEmitted;
33
+ readonly params: GenerateSandboxedUIParams;
34
+ readonly messageId: string;
35
+ private readonly onEvent;
36
+ constructor(toolCallId: string, onEvent: OnParamEvent);
37
+ write(chunk: string): void;
38
+ private initHtmlStreaming;
39
+ /**
40
+ * Emit the html read so far while the html string streams in.
41
+ * Called after every write(). It reads only while the top-level `html`
42
+ * value is being read, so a nested string is never emitted as html.
43
+ */
44
+ private flushHtmlChunks;
45
+ /**
46
+ * Emit accumulated html content since the last emission.
47
+ * Called by flushHtmlChunks and directly when html completes.
48
+ */
49
+ private emitPendingHtml;
50
+ private setParam;
51
+ private emitSnapshot;
52
+ private emitParamDelta;
53
+ private emitArrayItemDelta;
54
+ }
55
+ declare class OpenGenerativeUIMiddleware extends Middleware {
56
+ run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent>;
57
+ private processStream;
58
+ }
59
+ //#endregion
60
+ export { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware };
61
+ //# sourceMappingURL=open-generative-ui-middleware.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-generative-ui-middleware.d.cts","names":[],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"mappings":";;;;;AAoBA;;UAAiB,yBAAA;EACf,aAAA;EACA,mBAAA;EACA,GAAA;EACA,IAAA;EACA,WAAA;EACA,aAAA;AAAA;;;AAMF;KAAY,YAAA,IAAgB,KAAA,EAAO,SAAA;;;;AAMnC;cAAa,UAAA;EAAA,iBACM,OAAA;EAAA,QACT,UAAA;EAAA,QACA,KAAA;EAAA,QACA,eAAA;EAAA,QACA,eAAA;EAAA,QAIA,gBAAA;EAAA,QACA,iBAAA;EAAA,QACA,gBAAA;EAAA,SAEQ,MAAA,EAAQ,yBAAA;EAAA,SACR,SAAA;EAAA,iBACC,OAAA;cAEL,UAAA,UAAoB,OAAA,EAAS,YAAA;EAwEzC,KAAA,CAAM,KAAA;EAAA,QAKE,iBAAA;;;;;;UAaA,eAAA;EAbA;;;;EAAA,QA0BA,eAAA;EAAA,QAYA,QAAA;EAAA,QA0BA,YAAA;EAAA,QAaA,cAAA;EAAA,QAoBA,kBAAA;AAAA;AAAA,cAmBG,0BAAA,SAAmC,UAAA;EAC9C,GAAA,CAAI,KAAA,EAAO,aAAA,EAAe,IAAA,EAAM,aAAA,GAAgB,UAAA,CAAW,SAAA;EAAA,QAInD,aAAA;AAAA"}
@@ -0,0 +1,61 @@
1
+ import { Observable } from "rxjs";
2
+ import { AbstractAgent, BaseEvent, Middleware, RunAgentInput } from "@ag-ui/client";
3
+
4
+ //#region src/runtime/event-transforms/open-generative-ui-middleware.d.ts
5
+ /**
6
+ * Parsed parameters from the generateSandboxedUi tool call.
7
+ */
8
+ interface GenerateSandboxedUIParams {
9
+ initialHeight?: number;
10
+ placeholderMessages?: string[];
11
+ css?: string;
12
+ html?: string;
13
+ jsFunctions?: string;
14
+ jsExpressions?: string[];
15
+ }
16
+ /**
17
+ * Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.
18
+ */
19
+ type OnParamEvent = (event: BaseEvent) => void;
20
+ /**
21
+ * Tracks incremental JSON parsing state for a single tool call's arguments.
22
+ * Emits activity events via the onEvent callback as parameters complete.
23
+ */
24
+ declare class ArgsParser {
25
+ private readonly scanner;
26
+ private currentKey;
27
+ private depth;
28
+ private currentArrayKey;
29
+ private snapshotEmitted;
30
+ private streamingHtmlKey;
31
+ private htmlEmittedLength;
32
+ private htmlArrayEmitted;
33
+ readonly params: GenerateSandboxedUIParams;
34
+ readonly messageId: string;
35
+ private readonly onEvent;
36
+ constructor(toolCallId: string, onEvent: OnParamEvent);
37
+ write(chunk: string): void;
38
+ private initHtmlStreaming;
39
+ /**
40
+ * Emit the html read so far while the html string streams in.
41
+ * Called after every write(). It reads only while the top-level `html`
42
+ * value is being read, so a nested string is never emitted as html.
43
+ */
44
+ private flushHtmlChunks;
45
+ /**
46
+ * Emit accumulated html content since the last emission.
47
+ * Called by flushHtmlChunks and directly when html completes.
48
+ */
49
+ private emitPendingHtml;
50
+ private setParam;
51
+ private emitSnapshot;
52
+ private emitParamDelta;
53
+ private emitArrayItemDelta;
54
+ }
55
+ declare class OpenGenerativeUIMiddleware extends Middleware {
56
+ run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent>;
57
+ private processStream;
58
+ }
59
+ //#endregion
60
+ export { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware };
61
+ //# sourceMappingURL=open-generative-ui-middleware.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-generative-ui-middleware.d.mts","names":[],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"mappings":";;;;;AAoBA;;UAAiB,yBAAA;EACf,aAAA;EACA,mBAAA;EACA,GAAA;EACA,IAAA;EACA,WAAA;EACA,aAAA;AAAA;;;AAMF;KAAY,YAAA,IAAgB,KAAA,EAAO,SAAA;;;;AAMnC;cAAa,UAAA;EAAA,iBACM,OAAA;EAAA,QACT,UAAA;EAAA,QACA,KAAA;EAAA,QACA,eAAA;EAAA,QACA,eAAA;EAAA,QAIA,gBAAA;EAAA,QACA,iBAAA;EAAA,QACA,gBAAA;EAAA,SAEQ,MAAA,EAAQ,yBAAA;EAAA,SACR,SAAA;EAAA,iBACC,OAAA;cAEL,UAAA,UAAoB,OAAA,EAAS,YAAA;EAwEzC,KAAA,CAAM,KAAA;EAAA,QAKE,iBAAA;;;;;;UAaA,eAAA;EAbA;;;;EAAA,QA0BA,eAAA;EAAA,QAYA,QAAA;EAAA,QA0BA,YAAA;EAAA,QAaA,cAAA;EAAA,QAoBA,kBAAA;AAAA;AAAA,cAmBG,0BAAA,SAAmC,UAAA;EAC9C,GAAA,CAAI,KAAA,EAAO,aAAA,EAAe,IAAA,EAAM,aAAA,GAAgB,UAAA,CAAW,SAAA;EAAA,QAInD,aAAA;AAAA"}