@copilotkit/vue 2.0.0-rc.2 → 2.0.0-rc.21

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 (335) hide show
  1. package/PARITY.md +3 -3
  2. package/dist/hooks/use-copilot-action.d.ts.map +1 -1
  3. package/dist/hooks/use-frontend-tool.d.ts +1 -1
  4. package/dist/hooks/use-frontend-tool.d.ts.map +1 -1
  5. package/dist/hooks/zod-parameters.d.ts +14 -0
  6. package/dist/hooks/zod-parameters.d.ts.map +1 -0
  7. package/dist/index.cjs +1 -73
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.mjs +365 -16920
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/use-render-activity-message-BAhbpSDh.js +16200 -0
  12. package/dist/use-render-activity-message-BAhbpSDh.js.map +1 -0
  13. package/dist/use-render-activity-message-DJ6q1qHV.cjs +114 -0
  14. package/dist/use-render-activity-message-DJ6q1qHV.cjs.map +1 -0
  15. package/dist/v2/components/A2UIMessageRenderer.d.ts +14 -0
  16. package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -1
  17. package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts +10 -3
  18. package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -1
  19. package/dist/v2/components/CopilotKitInspector.vue.d.ts +5 -1
  20. package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -1
  21. package/dist/v2/components/InlineFeatureWarning.vue.d.ts.map +1 -1
  22. package/dist/v2/components/LicenseWarningBanner.vue.d.ts +2 -2
  23. package/dist/v2/components/LicenseWarningBanner.vue.d.ts.map +1 -1
  24. package/dist/v2/components/MCPAppsActivityRenderer.d.ts.map +1 -1
  25. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +13 -59
  26. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -1
  27. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +0 -5
  28. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -1
  29. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +10 -15
  30. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -1
  31. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts +14 -130
  32. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts.map +1 -1
  33. package/dist/v2/components/a2ui/catalog.d.ts.map +1 -1
  34. package/dist/v2/components/a2ui/utils.d.ts +3 -15
  35. package/dist/v2/components/a2ui/utils.d.ts.map +1 -1
  36. package/dist/v2/components/a2ui.d.ts +9 -8
  37. package/dist/v2/components/a2ui.d.ts.map +1 -1
  38. package/dist/v2/components/chat/CopilotChat.vue.d.ts +2 -2
  39. package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
  40. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
  41. package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -1
  42. package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -1
  43. package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts +4 -8
  44. package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -1
  45. package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts +1 -1
  46. package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts.map +1 -1
  47. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +6 -270
  48. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -1
  49. package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts.map +1 -1
  50. package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts.map +1 -1
  51. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +1 -1
  52. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -1
  53. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
  54. package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts +1 -1
  55. package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts.map +1 -1
  56. package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts.map +1 -1
  57. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +1 -1
  58. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
  59. package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -1
  60. package/dist/v2/components/chat/CopilotChatView.vue.d.ts +3 -3
  61. package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -1
  62. package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts.map +1 -1
  63. package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -1
  64. package/dist/v2/components/chat/CopilotPopup.vue.d.ts +8 -3
  65. package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -1
  66. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +5 -3
  67. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -1
  68. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +5 -3
  69. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -1
  70. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +8 -3
  71. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -1
  72. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +6 -4
  73. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -1
  74. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +6 -4
  75. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -1
  76. package/dist/v2/components/chat/CopilotThreadsDrawer.vue.d.ts.map +1 -1
  77. package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts +1 -0
  78. package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts.map +1 -1
  79. package/dist/v2/components/chat/audioRecorder.d.ts +3 -4
  80. package/dist/v2/components/chat/audioRecorder.d.ts.map +1 -1
  81. package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts +3 -3
  82. package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -1
  83. package/dist/v2/components/chat/forwarded-slots.d.ts +12 -0
  84. package/dist/v2/components/chat/forwarded-slots.d.ts.map +1 -0
  85. package/dist/v2/components/chat/index.d.ts +34 -31
  86. package/dist/v2/components/chat/index.d.ts.map +1 -1
  87. package/dist/v2/components/chat/inspector-shortcuts.d.ts +2 -1
  88. package/dist/v2/components/chat/inspector-shortcuts.d.ts.map +1 -1
  89. package/dist/v2/components/chat/message-feedback.d.ts +18 -49
  90. package/dist/v2/components/chat/message-feedback.d.ts.map +1 -1
  91. package/dist/v2/components/chat/tool-call-display-context.d.ts +4 -19
  92. package/dist/v2/components/chat/tool-call-display-context.d.ts.map +1 -1
  93. package/dist/v2/components/chat/tool-call-group-parts.d.ts +7 -20
  94. package/dist/v2/components/chat/tool-call-group-parts.d.ts.map +1 -1
  95. package/dist/v2/components/chat/turn-work.d.ts +0 -2
  96. package/dist/v2/components/chat/turn-work.d.ts.map +1 -1
  97. package/dist/v2/components/chat/types.d.ts +9 -4
  98. package/dist/v2/components/chat/types.d.ts.map +1 -1
  99. package/dist/v2/components/chat/use-chat-labels.d.ts +8 -0
  100. package/dist/v2/components/chat/use-chat-labels.d.ts.map +1 -0
  101. package/dist/v2/components/chat/use-copy-feedback.d.ts +11 -0
  102. package/dist/v2/components/chat/use-copy-feedback.d.ts.map +1 -0
  103. package/dist/v2/components/chat/use-lightbox.d.ts.map +1 -1
  104. package/dist/v2/components/icons/index.d.ts +968 -1
  105. package/dist/v2/components/icons/index.d.ts.map +1 -1
  106. package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts +1 -1
  107. package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts.map +1 -1
  108. package/dist/v2/hooks/use-agent-context.d.ts +2 -3
  109. package/dist/v2/hooks/use-agent-context.d.ts.map +1 -1
  110. package/dist/v2/hooks/use-agent.d.ts +4 -1
  111. package/dist/v2/hooks/use-agent.d.ts.map +1 -1
  112. package/dist/v2/hooks/use-attachments.d.ts +7 -0
  113. package/dist/v2/hooks/use-attachments.d.ts.map +1 -1
  114. package/dist/v2/hooks/use-capabilities.d.ts.map +1 -1
  115. package/dist/v2/hooks/use-component.d.ts +1 -0
  116. package/dist/v2/hooks/use-component.d.ts.map +1 -1
  117. package/dist/v2/hooks/use-configure-suggestions.d.ts +4 -9
  118. package/dist/v2/hooks/use-configure-suggestions.d.ts.map +1 -1
  119. package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -1
  120. package/dist/v2/hooks/use-frontend-tool.d.ts +5 -0
  121. package/dist/v2/hooks/use-frontend-tool.d.ts.map +1 -1
  122. package/dist/v2/hooks/use-human-in-the-loop.d.ts +2 -1
  123. package/dist/v2/hooks/use-human-in-the-loop.d.ts.map +1 -1
  124. package/dist/v2/hooks/use-interrupt.d.ts +0 -1
  125. package/dist/v2/hooks/use-interrupt.d.ts.map +1 -1
  126. package/dist/v2/hooks/use-keyboard-height.d.ts +1 -1
  127. package/dist/v2/hooks/use-keyboard-height.d.ts.map +1 -1
  128. package/dist/v2/hooks/use-pin-to-send.d.ts +4 -12
  129. package/dist/v2/hooks/use-pin-to-send.d.ts.map +1 -1
  130. package/dist/v2/hooks/use-render-activity-message.d.ts +13 -9
  131. package/dist/v2/hooks/use-render-activity-message.d.ts.map +1 -1
  132. package/dist/v2/hooks/use-render-custom-messages.d.ts +5 -7
  133. package/dist/v2/hooks/use-render-custom-messages.d.ts.map +1 -1
  134. package/dist/v2/hooks/use-suggestions.d.ts.map +1 -1
  135. package/dist/v2/hooks/use-threads.d.ts +0 -8
  136. package/dist/v2/hooks/use-threads.d.ts.map +1 -1
  137. package/dist/v2/index.cjs +1 -1
  138. package/dist/v2/index.mjs +197 -200
  139. package/dist/v2/index.mjs.map +1 -1
  140. package/dist/v2/lib/processPartialHtml.d.ts +1 -2
  141. package/dist/v2/lib/processPartialHtml.d.ts.map +1 -1
  142. package/dist/v2/lib/shallow-stable.d.ts.map +1 -1
  143. package/dist/v2/lib/vue-core.d.ts +12 -12
  144. package/dist/v2/lib/vue-core.d.ts.map +1 -1
  145. package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -1
  146. package/dist/v2/providers/CopilotKitProvider.types.d.ts +9 -129
  147. package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
  148. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +9 -10
  149. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
  150. package/dist/v2/providers/chat-configuration-store-key.d.ts +8 -0
  151. package/dist/v2/providers/chat-configuration-store-key.d.ts.map +1 -0
  152. package/dist/v2/providers/markdown-renderer.d.ts +4 -2
  153. package/dist/v2/providers/markdown-renderer.d.ts.map +1 -1
  154. package/dist/v2/providers/types.d.ts +3 -46
  155. package/dist/v2/providers/types.d.ts.map +1 -1
  156. package/dist/v2/providers/use-inspector-thread-override.d.ts +5 -0
  157. package/dist/v2/providers/use-inspector-thread-override.d.ts.map +1 -1
  158. package/dist/v2/types/human-in-the-loop.d.ts +8 -29
  159. package/dist/v2/types/human-in-the-loop.d.ts.map +1 -1
  160. package/dist/v2/types/interrupt.d.ts +1 -22
  161. package/dist/v2/types/interrupt.d.ts.map +1 -1
  162. package/dist/v2/types/vue-activity-message-renderer.d.ts +16 -15
  163. package/dist/v2/types/vue-activity-message-renderer.d.ts.map +1 -1
  164. package/dist/v2/types/vue-custom-message-renderer.d.ts +7 -16
  165. package/dist/v2/types/vue-custom-message-renderer.d.ts.map +1 -1
  166. package/dist/v2/types/vue-tool-call-renderer.d.ts +16 -35
  167. package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -1
  168. package/package.json +10 -11
  169. package/src/__tests__/build-entries.test.ts +27 -0
  170. package/src/hooks/__tests__/zod-parameters.test.ts +520 -0
  171. package/src/hooks/use-copilot-action.ts +2 -1
  172. package/src/hooks/use-frontend-tool.ts +3 -6
  173. package/src/hooks/zod-parameters.ts +162 -0
  174. package/src/v2/__tests__/exports.test.ts +10 -0
  175. package/src/v2/__tests__/mocks/web-inspector.ts +6 -0
  176. package/src/v2/__tests__/utils/test-helpers.ts +34 -4
  177. package/src/v2/components/A2UIMessageRenderer.ts +98 -68
  178. package/src/v2/components/A2UISurfaceActivityRenderer.vue +68 -103
  179. package/src/v2/components/CopilotKitInspector.vue +104 -51
  180. package/src/v2/components/InlineFeatureWarning.vue +20 -21
  181. package/src/v2/components/LicenseWarningBanner.vue +27 -135
  182. package/src/v2/components/MCPAppsActivityRenderer.ts +75 -201
  183. package/src/v2/components/OpenGenerativeUIRenderer.ts +122 -446
  184. package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +171 -8
  185. package/src/v2/components/__tests__/CopilotKitInspector.test.ts +42 -0
  186. package/src/v2/components/__tests__/LicenseWarningBanner.test.ts +60 -0
  187. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +64 -8
  188. package/src/v2/components/__tests__/OpenGenerativeUIToolRenderer.test.ts +38 -0
  189. package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +2 -7
  190. package/src/v2/components/a2ui/A2UICatalogContext.ts +27 -185
  191. package/src/v2/components/a2ui/A2UIRecoveryStates.ts +127 -327
  192. package/src/v2/components/a2ui/catalog.ts +3 -3
  193. package/src/v2/components/a2ui/utils.ts +13 -65
  194. package/src/v2/components/a2ui.ts +15 -22
  195. package/src/v2/components/chat/CopilotChat.vue +147 -356
  196. package/src/v2/components/chat/CopilotChatAssistantMessage.vue +19 -43
  197. package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +36 -55
  198. package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +14 -6
  199. package/src/v2/components/chat/CopilotChatAudioRecorder.vue +19 -246
  200. package/src/v2/components/chat/CopilotChatFeedbackCommentPopover.vue +2 -2
  201. package/src/v2/components/chat/CopilotChatInput.vue +108 -436
  202. package/src/v2/components/chat/CopilotChatInspectorButton.vue +45 -108
  203. package/src/v2/components/chat/CopilotChatLightbox.vue +10 -31
  204. package/src/v2/components/chat/CopilotChatMessageView.vue +82 -210
  205. package/src/v2/components/chat/CopilotChatReasoningMessage.vue +7 -15
  206. package/src/v2/components/chat/CopilotChatToolCallGroup.vue +63 -71
  207. package/src/v2/components/chat/CopilotChatToolCallItem.vue +8 -6
  208. package/src/v2/components/chat/CopilotChatToolCallsView.vue +31 -32
  209. package/src/v2/components/chat/CopilotChatUserMessage.vue +24 -112
  210. package/src/v2/components/chat/CopilotChatView.vue +33 -28
  211. package/src/v2/components/chat/CopilotChatWorkSummary.vue +26 -36
  212. package/src/v2/components/chat/CopilotModalHeader.vue +11 -23
  213. package/src/v2/components/chat/CopilotPopup.vue +23 -25
  214. package/src/v2/components/chat/CopilotPopupView.vue +10 -39
  215. package/src/v2/components/chat/CopilotPopupViewInternal.vue +35 -131
  216. package/src/v2/components/chat/CopilotSidebar.vue +23 -25
  217. package/src/v2/components/chat/CopilotSidebarView.vue +10 -39
  218. package/src/v2/components/chat/CopilotSidebarViewInternal.vue +38 -59
  219. package/src/v2/components/chat/CopilotThreadsDrawer.vue +37 -102
  220. package/src/v2/components/chat/StreamingMarkdownDefault.vue +15 -28
  221. package/src/v2/components/chat/__tests__/CopilotChat.labels.test.ts +19 -4
  222. package/src/v2/components/chat/__tests__/CopilotChat.test.ts +12 -10
  223. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +26 -9
  224. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.learningFeedback.test.ts +5 -5
  225. package/src/v2/components/chat/__tests__/CopilotChatAttachmentQueue.test.ts +28 -0
  226. package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +89 -1
  227. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.ts +247 -403
  228. package/src/v2/components/chat/__tests__/CopilotChatMessageView.toolCallDisplay.test.ts +1 -99
  229. package/src/v2/components/chat/__tests__/CopilotPopup.test.ts +90 -1
  230. package/src/v2/components/chat/__tests__/CopilotPopupView.test.ts +19 -0
  231. package/src/v2/components/chat/__tests__/CopilotSidebar.test.ts +90 -1
  232. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.ts +32 -8
  233. package/src/v2/components/chat/__tests__/CopilotSidebarView.test.ts +2 -1
  234. package/src/v2/components/chat/__tests__/StreamingMarkdownDefault.test.ts +54 -0
  235. package/src/v2/components/chat/audioRecorder.ts +4 -7
  236. package/src/v2/components/chat/copilotChatToolCallItemRender.ts +24 -89
  237. package/src/v2/components/chat/forwarded-slots.ts +17 -0
  238. package/src/v2/components/chat/index.ts +0 -1
  239. package/src/v2/components/chat/inspector-shortcuts.ts +10 -16
  240. package/src/v2/components/chat/message-feedback.ts +62 -197
  241. package/src/v2/components/chat/tool-call-display-context.ts +6 -22
  242. package/src/v2/components/chat/tool-call-group-parts.ts +47 -108
  243. package/src/v2/components/chat/turn-work.ts +0 -9
  244. package/src/v2/components/chat/types.ts +12 -4
  245. package/src/v2/components/chat/use-chat-labels.ts +16 -0
  246. package/src/v2/components/chat/use-copy-feedback.ts +21 -0
  247. package/src/v2/components/chat/use-lightbox.ts +15 -33
  248. package/src/v2/components/icons/__tests__/icons.test.ts +72 -68
  249. package/src/v2/components/icons/index.ts +109 -27
  250. package/src/v2/hooks/__tests__/use-agent-error-state.test.ts +5 -3
  251. package/src/v2/hooks/__tests__/use-agent-stability.test.ts +25 -4
  252. package/src/v2/hooks/__tests__/use-agent-throttle.test.ts +5 -1
  253. package/src/v2/hooks/__tests__/use-agent.test.ts +6 -3
  254. package/src/v2/hooks/__tests__/use-component.test.ts +21 -0
  255. package/src/v2/hooks/__tests__/use-configure-suggestions.test.ts +30 -1
  256. package/src/v2/hooks/__tests__/use-default-render-tool.test.ts +10 -10
  257. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +66 -1
  258. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.ts +6 -1
  259. package/src/v2/hooks/__tests__/use-human-in-the-loop.test.ts +187 -12
  260. package/src/v2/hooks/__tests__/use-interrupt.test.ts +97 -0
  261. package/src/v2/hooks/__tests__/use-render-activity-message.test.ts +106 -0
  262. package/src/v2/hooks/__tests__/use-render-tool.test.ts +3 -6
  263. package/src/v2/hooks/__tests__/use-threads.test.ts +48 -6
  264. package/src/v2/hooks/__tests__/zod-regression.test.ts +5 -4
  265. package/src/v2/hooks/use-agent-context.ts +4 -10
  266. package/src/v2/hooks/use-agent.ts +86 -290
  267. package/src/v2/hooks/use-attachments.ts +48 -168
  268. package/src/v2/hooks/use-capabilities.ts +2 -7
  269. package/src/v2/hooks/use-component.ts +7 -4
  270. package/src/v2/hooks/use-configure-suggestions.ts +28 -218
  271. package/src/v2/hooks/use-default-render-tool.ts +34 -94
  272. package/src/v2/hooks/use-frontend-tool.ts +10 -10
  273. package/src/v2/hooks/use-human-in-the-loop.ts +11 -80
  274. package/src/v2/hooks/use-interrupt.ts +29 -308
  275. package/src/v2/hooks/use-keyboard-height.ts +17 -40
  276. package/src/v2/hooks/use-pin-to-send.ts +15 -99
  277. package/src/v2/hooks/use-render-activity-message.ts +31 -55
  278. package/src/v2/hooks/use-render-custom-messages.ts +24 -88
  279. package/src/v2/hooks/use-suggestions.ts +9 -33
  280. package/src/v2/hooks/use-threads.ts +43 -273
  281. package/src/v2/lib/__tests__/shallow-stable.test.ts +54 -0
  282. package/src/v2/lib/__tests__/vue-core-renderers.test.ts +42 -0
  283. package/src/v2/lib/processPartialHtml.ts +6 -21
  284. package/src/v2/lib/shallow-stable.ts +2 -16
  285. package/src/v2/lib/vue-core.ts +69 -78
  286. package/src/v2/providers/CopilotChatConfigurationProvider.vue +48 -186
  287. package/src/v2/providers/CopilotKitProvider.types.ts +12 -132
  288. package/src/v2/providers/CopilotKitProvider.vue +237 -510
  289. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.ts +22 -2
  290. package/src/v2/providers/__tests__/CopilotKitProvider.a2ui.test.ts +20 -2
  291. package/src/v2/providers/__tests__/CopilotKitProvider.config.test.ts +124 -0
  292. package/src/v2/providers/__tests__/CopilotKitProvider.headersAtSendTime.test.ts +3 -3
  293. package/src/v2/providers/__tests__/CopilotKitProvider.learning.test.ts +3 -1
  294. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.ts +4 -1
  295. package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +53 -26
  296. package/src/v2/providers/chat-configuration-store-key.ts +9 -0
  297. package/src/v2/providers/markdown-renderer.ts +8 -2
  298. package/src/v2/providers/types.ts +3 -49
  299. package/src/v2/providers/use-inspector-thread-override.ts +22 -80
  300. package/src/v2/types/__tests__/defineToolCallRenderer.test.ts +28 -33
  301. package/src/v2/types/defineToolCallRenderer.ts +5 -4
  302. package/src/v2/types/human-in-the-loop.ts +8 -32
  303. package/src/v2/types/interrupt.ts +7 -31
  304. package/src/v2/types/vue-activity-message-renderer.ts +24 -15
  305. package/src/v2/types/vue-custom-message-renderer.ts +12 -16
  306. package/src/v2/types/vue-tool-call-renderer.ts +23 -38
  307. package/tsconfig.json +0 -1
  308. package/vite.config.ts +8 -5
  309. package/vitest.config.ts +12 -7
  310. package/dist/v2/components/chat/BasicMarkdown.vue.d.ts +0 -9
  311. package/dist/v2/components/chat/BasicMarkdown.vue.d.ts.map +0 -1
  312. package/dist/v2/components/chat/normalize-auto-scroll.d.ts +0 -3
  313. package/dist/v2/components/chat/normalize-auto-scroll.d.ts.map +0 -1
  314. package/dist/v2/components/chat/tool-call-layout.d.ts +0 -115
  315. package/dist/v2/components/chat/tool-call-layout.d.ts.map +0 -1
  316. package/dist/v2/lib/is-mobile-viewport.d.ts +0 -15
  317. package/dist/v2/lib/is-mobile-viewport.d.ts.map +0 -1
  318. package/dist/v2/lib/message-feedback.d.ts +0 -33
  319. package/dist/v2/lib/message-feedback.d.ts.map +0 -1
  320. package/dist/v2/lib/transcription-client.d.ts +0 -19
  321. package/dist/v2/lib/transcription-client.d.ts.map +0 -1
  322. package/src/v2/components/__tests__/A2UICatalogContext.test.ts +0 -63
  323. package/src/v2/components/a2ui/__tests__/A2UIRecoveryStates.test.ts +0 -175
  324. package/src/v2/components/chat/BasicMarkdown.vue +0 -160
  325. package/src/v2/components/chat/__tests__/BasicMarkdown.test.ts +0 -69
  326. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -39
  327. package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
  328. package/src/v2/components/chat/tool-call-layout.ts +0 -304
  329. package/src/v2/lib/__tests__/is-mobile-viewport.test.ts +0 -48
  330. package/src/v2/lib/__tests__/message-feedback.test.ts +0 -152
  331. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -84
  332. package/src/v2/lib/__tests__/transcription-client.test.ts +0 -67
  333. package/src/v2/lib/is-mobile-viewport.ts +0 -23
  334. package/src/v2/lib/message-feedback.ts +0 -120
  335. package/src/v2/lib/transcription-client.ts +0 -151
@@ -4,6 +4,19 @@ import type { Ref } from "vue";
4
4
  import { describe, expect, it, beforeEach, vi } from "vitest";
5
5
  import { useCopilotKit } from "../../providers/useCopilotKit";
6
6
 
7
+ /** Core's `ɵruntimeInfo` snapshot, built from a fake core's runtime fields. */
8
+ function runtimeInfoOf(core: {
9
+ runtimeConnectionStatus: CopilotKitCoreRuntimeConnectionStatus;
10
+ threadEndpoints?: unknown;
11
+ intelligence?: unknown;
12
+ }) {
13
+ return {
14
+ status: core.runtimeConnectionStatus,
15
+ threadEndpoints: core.threadEndpoints,
16
+ intelligence: core.intelligence,
17
+ };
18
+ }
19
+
7
20
  type ThreadRecord = {
8
21
  id: string;
9
22
  organizationId: string;
@@ -54,7 +67,8 @@ function compareThreadsByActivity(left: ThreadRecord, right: ThreadRecord) {
54
67
  return rightKey.localeCompare(leftKey);
55
68
  }
56
69
 
57
- vi.mock("@copilotkit/core", () => {
70
+ vi.mock("@copilotkit/core", async (importOriginal) => {
71
+ const actual = await importOriginal<typeof import("@copilotkit/core")>();
58
72
  class MockChannel {
59
73
  topic: string;
60
74
  left = false;
@@ -118,6 +132,16 @@ vi.mock("@copilotkit/core", () => {
118
132
  private listeners = new Set<() => void>();
119
133
  private socket: MockSocket | null = null;
120
134
 
135
+ readonly selectors = {
136
+ threads: (state: ThreadState) => state.threads,
137
+ isLoading: (state: ThreadState) => state.isLoading,
138
+ error: (state: ThreadState) => state.error,
139
+ fetchMoreError: (state: ThreadState) => state.fetchMoreError,
140
+ hasNextPage: (state: ThreadState) => state.hasNextPage,
141
+ isFetchingNextPage: (state: ThreadState) => state.isFetchingNextPage,
142
+ isMutating: (state: ThreadState) => state.isMutating,
143
+ };
144
+
121
145
  start(): void {}
122
146
 
123
147
  stop(): void {
@@ -317,6 +341,10 @@ vi.mock("@copilotkit/core", () => {
317
341
  return this.state;
318
342
  }
319
343
 
344
+ getServerState(): ThreadState {
345
+ return { ...this.state, threads: [] };
346
+ }
347
+
320
348
  select<T>(selector: (state: ThreadState) => T) {
321
349
  return {
322
350
  subscribe: (callback: () => void) => {
@@ -357,6 +385,8 @@ vi.mock("@copilotkit/core", () => {
357
385
  ɵselectHasNextPage: select((state) => state.hasNextPage),
358
386
  ɵselectIsFetchingNextPage: select((state) => state.isFetchingNextPage),
359
387
  ɵselectIsMutating: select((state) => state.isMutating),
388
+ // The real view model, driving the mock store above.
389
+ ɵThreadsController: actual.ɵThreadsController,
360
390
  };
361
391
  });
362
392
 
@@ -394,6 +424,7 @@ const supportedThreadEndpoints: ThreadEndpointRuntimeInfo = {
394
424
 
395
425
  type MockCopilotKit = {
396
426
  runtimeUrl: string | undefined;
427
+ readonly ɵruntimeInfo: unknown;
397
428
  runtimeConnectionStatus: CopilotKitCoreRuntimeConnectionStatus;
398
429
  headers: Record<string, string>;
399
430
  /**
@@ -417,6 +448,9 @@ function setupCopilotKit(
417
448
  ) {
418
449
  const copilotkit = ref<MockCopilotKit>({
419
450
  runtimeUrl,
451
+ get ɵruntimeInfo() {
452
+ return runtimeInfoOf(this);
453
+ },
420
454
  runtimeConnectionStatus,
421
455
  headers: { Authorization: "Bearer test-token" },
422
456
  ɵheadersGeneration: 0,
@@ -965,6 +999,9 @@ describe("useThreads", () => {
965
999
  // exactly one list fetch (+ one subscribe after it lands).
966
1000
  copilotkit.value = {
967
1001
  ...copilotkit.value,
1002
+ get ɵruntimeInfo() {
1003
+ return runtimeInfoOf(this);
1004
+ },
968
1005
  runtimeConnectionStatus:
969
1006
  CopilotKitCoreRuntimeConnectionStatus.Connected,
970
1007
  intelligence: { wsUrl: "ws://localhost:4000/client" },
@@ -1020,6 +1057,9 @@ describe("useThreads", () => {
1020
1057
 
1021
1058
  copilotkit.value = {
1022
1059
  ...copilotkit.value,
1060
+ get ɵruntimeInfo() {
1061
+ return runtimeInfoOf(this);
1062
+ },
1023
1063
  runtimeConnectionStatus:
1024
1064
  CopilotKitCoreRuntimeConnectionStatus.Disconnected,
1025
1065
  };
@@ -1216,8 +1256,9 @@ describe("useThreads", () => {
1216
1256
 
1217
1257
  expect(fetchMock).not.toHaveBeenCalled();
1218
1258
  expect(getResult().threads.value).toEqual([]);
1219
- const lastDispatched = getDispatchedContexts().at(-1);
1220
- expect(lastDispatched).toBeNull();
1259
+ // Nothing was ever sent, so nothing is cleared either (no extra
1260
+ // queued list fetch).
1261
+ expect(getDispatchedContexts()).toEqual([]);
1221
1262
  // A disabled consumer must not be stuck in a permanent loading state:
1222
1263
  // preConnectLoading must factor in `enabled`, otherwise isLoading would
1223
1264
  // stay true forever since hasDispatchedContext never gets set.
@@ -1240,7 +1281,7 @@ describe("useThreads", () => {
1240
1281
  // Disabled: inert, not loading, no fetch.
1241
1282
  expect(getResult().isLoading.value).toBe(false);
1242
1283
  expect(fetchMock).not.toHaveBeenCalled();
1243
- expect(getDispatchedContexts().at(-1)).toBeNull();
1284
+ expect(getDispatchedContexts().filter(Boolean)).toEqual([]);
1244
1285
 
1245
1286
  // Re-enable: the pre-connect loading indicator must re-arm (i.e.
1246
1287
  // hasDispatchedContext was reset to false on disable) so consumers see
@@ -1343,8 +1384,9 @@ describe("useThreads", () => {
1343
1384
 
1344
1385
  expect(fetchMock).not.toHaveBeenCalled();
1345
1386
  expect(getResult().threads.value).toEqual([]);
1346
- const lastDispatched = getDispatchedContexts().at(-1);
1347
- expect(lastDispatched).toBeNull();
1387
+ // Nothing was ever sent, so nothing is cleared either (no extra
1388
+ // queued list fetch).
1389
+ expect(getDispatchedContexts()).toEqual([]);
1348
1390
  expect(getResult().error.value?.message).toBe(
1349
1391
  "Thread endpoints are not available on this CopilotKit runtime",
1350
1392
  );
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Covers:
6
6
  * 1. useRenderTool with complex Zod schemas
7
- * 2. defineToolCallRenderer with Zod (named + wildcard default z.any())
7
+ * 2. defineToolCallRenderer with Zod (named + wildcard default schema)
8
8
  * 3. useComponent with Zod schemas
9
9
  * 4. The registered schema object is the original Zod instance (identity check)
10
10
  */
@@ -134,7 +134,7 @@ describe("useRenderTool Zod regression", () => {
134
134
  const schema = z.object({
135
135
  action: z.discriminatedUnion("type", [
136
136
  z.object({ type: z.literal("search"), query: z.string() }),
137
- z.object({ type: z.literal("navigate"), url: z.string().url() }),
137
+ z.object({ type: z.literal("navigate"), url: z.url() }),
138
138
  ]),
139
139
  });
140
140
 
@@ -196,14 +196,15 @@ describe("useRenderTool Zod regression", () => {
196
196
  });
197
197
 
198
198
  describe("defineToolCallRenderer Zod regression", () => {
199
- it("wildcard tool defaults to z.any() for args", () => {
199
+ it("wildcard tool defaults to a schema that accepts any value", () => {
200
200
  const renderer = defineToolCallRenderer({
201
201
  name: "*",
202
202
  render: () => "wildcard",
203
203
  });
204
204
 
205
205
  expect(renderer.name).toBe("*");
206
- expect((renderer.args as any)["~standard"].vendor).toBe("zod");
206
+ const result = renderer.args["~standard"].validate({ city: "Paris" });
207
+ expect(result).toEqual({ value: { city: "Paris" } });
207
208
  });
208
209
 
209
210
  it("named tool with Zod args preserves schema identity", () => {
@@ -1,14 +1,10 @@
1
1
  import { computed, toValue, watch } from "vue";
2
2
  import type { MaybeRefOrGetter } from "vue";
3
+ import { ɵserializeContextValue } from "@copilotkit/core";
4
+ import type { ɵJsonSerializable } from "@copilotkit/core";
3
5
  import { useCopilotKit } from "../providers/useCopilotKit";
4
6
 
5
- export type JsonSerializable =
6
- | string
7
- | number
8
- | boolean
9
- | null
10
- | JsonSerializable[]
11
- | { [key: string]: JsonSerializable };
7
+ export type JsonSerializable = ɵJsonSerializable;
12
8
 
13
9
  export interface AgentContextInput {
14
10
  description: MaybeRefOrGetter<string>;
@@ -35,9 +31,7 @@ export function useAgentContext(context: AgentContextInput): void {
35
31
  const resolvedValue = computed(() => toValue(context.value));
36
32
 
37
33
  const stringValue = computed(() =>
38
- typeof resolvedValue.value === "string"
39
- ? resolvedValue.value
40
- : JSON.stringify(resolvedValue.value),
34
+ ɵserializeContextValue(resolvedValue.value),
41
35
  );
42
36
 
43
37
  watch(
@@ -1,15 +1,12 @@
1
1
  import { computed, shallowRef, toValue, triggerRef, watch } from "vue";
2
2
  import type { MaybeRefOrGetter } from "vue";
3
- import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
4
3
  import type { AbstractAgent } from "@ag-ui/client";
5
4
  import {
6
- ProxiedCopilotRuntimeAgent,
7
- CopilotKitCoreRuntimeConnectionStatus,
8
- ɵisHttpAgent,
9
- } from "@copilotkit/core";
10
- import type {
11
- CopilotRuntimeTransport,
12
- SubscribeToAgentSubscriber,
5
+ ɵgetAgentResolver,
6
+ ɵresolveAgentId,
7
+ ɵresolveAgentThreadId,
8
+ ɵsubscribeToAgentUpdates,
9
+ ɵvalidateAgentBinding,
13
10
  } from "@copilotkit/core";
14
11
  import { useCopilotKit } from "../providers/useCopilotKit";
15
12
  import { useCopilotChatConfiguration } from "../providers/useCopilotChatConfiguration";
@@ -126,7 +123,9 @@ export type UseAgentProps = UseAgentPropsBase &
126
123
  *
127
124
  * It returns a reactive `agent` ref that updates when the selected agent
128
125
  * changes, when runtime connection state changes, or when subscribed update
129
- * events fire.
126
+ * events fire, and an `isReady` ref: `false` while `agent` is a provisional
127
+ * stand-in used before the runtime `/info` sync lands (or after it failed),
128
+ * `true` once it is the real agent.
130
129
  *
131
130
  * @example
132
131
  * ```ts
@@ -134,348 +133,145 @@ export type UseAgentProps = UseAgentPropsBase &
134
133
  * ```
135
134
  */
136
135
  export function useAgent(props: UseAgentProps = {}) {
137
- // `threadId`, `runtimeAgentId` and an explicit `agentId` are all-or-nothing.
138
- // UseAgentProps rejects a partial set at compile time; these are the runtime
139
- // backstop for callers TypeScript doesn't reach (plain JS, `as any`). Same
140
- // three checks, same messages, as React's useAgent.
141
- const hasThreadId = props.threadId !== undefined;
142
- const hasRuntimeAgentId = props.runtimeAgentId !== undefined;
143
- const hasAgentId = props.agentId !== undefined;
144
-
145
- if (hasThreadId && !hasRuntimeAgentId) {
146
- throw new Error(
147
- "useAgent: `threadId` requires `runtimeAgentId`. A threadId is written onto a " +
148
- "single agent, but an agent resolved by agentId alone is shared, so scoping a " +
149
- "thread to it would clobber other useAgent callers. Pass a distinct local `agentId` " +
150
- 'and the runtime agent to route to, e.g. useAgent({ agentId: "chat-1", ' +
151
- 'runtimeAgentId: "assistant", threadId }).',
152
- );
153
- }
154
-
155
- if (hasRuntimeAgentId && !hasThreadId) {
156
- throw new Error(
157
- "useAgent: `runtimeAgentId` requires `threadId`. A proxied agent exists to scope a " +
158
- "thread to a private instance; without a threadId it behaves like the shared agent " +
159
- "while adding a registration and a local agentId to keep unique. Either pass the " +
160
- "thread, or bind to the agent directly with useAgent({ agentId }).",
161
- );
162
- }
163
-
164
- if (hasRuntimeAgentId && !hasAgentId) {
165
- throw new Error(
166
- "useAgent: `runtimeAgentId` requires an explicit `agentId`. The proxied agent is " +
167
- "registered under `agentId`, and the usual fallbacks (chat configuration, then " +
168
- `"${DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws ` +
169
- "or shadows it. Pick a local id for this hook, e.g. " +
170
- 'useAgent({ agentId: "chat-1", runtimeAgentId: "assistant", threadId }).',
171
- );
172
- }
173
-
174
- // After the guards, all three are present or none are.
175
- const isThreadScoped = hasRuntimeAgentId;
136
+ // Runtime backstop for the all-or-nothing rule UseAgentProps enforces at
137
+ // compile time (plain JS, `as any`). Same checks and messages as React.
138
+ ɵvalidateAgentBinding({
139
+ agentId: toValue(props.agentId),
140
+ threadId: toValue(props.threadId),
141
+ runtimeAgentId: toValue(props.runtimeAgentId),
142
+ });
143
+ const isThreadScoped = props.runtimeAgentId !== undefined;
176
144
 
177
145
  const chatConfig = useCopilotChatConfiguration();
178
- const agentId = computed(
179
- () =>
180
- toValue(props.agentId) ?? chatConfig.value?.agentId ?? DEFAULT_AGENT_ID,
146
+ const agentId = computed(() =>
147
+ ɵresolveAgentId({
148
+ agentId: toValue(props.agentId),
149
+ chatAgentId: chatConfig.value?.agentId,
150
+ }),
181
151
  );
182
152
  const runtimeAgentId = computed(() =>
183
153
  isThreadScoped ? toValue(props.runtimeAgentId) : undefined,
184
154
  );
185
- // Mirrors React: an explicit `threadId` prop wins, otherwise the chat
186
- // configuration's thread, gated on `hasExplicitThreadId` so a
187
- // ThreadsProvider-minted placeholder UUID doesn't overwrite the agent's own
188
- // auto-minted one (both are random and useless to the backend).
189
- const resolvedThreadId = computed(
190
- () =>
191
- toValue(props.threadId) ??
192
- (chatConfig.value?.hasExplicitThreadId
193
- ? chatConfig.value.threadId
194
- : undefined),
155
+ const resolvedThreadId = computed(() =>
156
+ ɵresolveAgentThreadId({
157
+ threadId: toValue(props.threadId),
158
+ chatThreadId: chatConfig.value?.threadId,
159
+ chatHasExplicitThreadId: chatConfig.value?.hasExplicitThreadId,
160
+ }),
195
161
  );
196
162
  const { copilotkit } = useCopilotKit();
163
+ const resolver = computed(() => ɵgetAgentResolver(copilotkit.value));
197
164
  const updateFlags = computed(() => props.updates ?? ALL_UPDATES);
198
165
  // Read the provider-level default so it appears in the subscribe watcher
199
- // deps. `subscribeToAgentWithOptions` reads it from the core instance, but
200
- // Vue still needs the dep to know when to resubscribe (same role it plays
201
- // in React's `useEffect` dep array).
166
+ // deps: core reads it, but Vue needs the dep to resubscribe.
202
167
  const providerThrottleMs = computed(() => copilotkit.value.defaultThrottleMs);
203
168
  const hookThrottleMs = computed(() => toValue(props.throttleMs));
204
169
 
205
170
  const agent = shallowRef<AbstractAgent | null>(null);
206
- const subscriptionAgent = shallowRef<AbstractAgent | null>(null);
207
- const provisionalAgentCache = new Map<string, ProxiedCopilotRuntimeAgent>();
208
-
209
- const createProvisionalAgent = (
210
- id: string,
211
- runtimeUrl: string,
212
- transport: CopilotRuntimeTransport,
213
- ) => {
214
- const provisional = new ProxiedCopilotRuntimeAgent({
215
- runtimeUrl,
216
- agentId: id,
217
- transport,
218
- runtimeMode: "pending",
219
- });
220
- // Never invokes the headers builder — installs `ɵruntimeFetch` and
221
- // own-only headers on this proxied agent, so a request it actually sends
222
- // resolves the current headers at send time (#1937).
223
- copilotkit.value.applyHeadersToAgent(provisional);
224
- return provisional;
225
- };
171
+ const isReady = shallowRef(false);
172
+ const resolverRevision = shallowRef(0);
173
+ watch(
174
+ resolver,
175
+ (current, _old, onCleanup) => {
176
+ onCleanup(
177
+ current.subscribe(() => {
178
+ resolverRevision.value = current.getSnapshot();
179
+ }),
180
+ );
181
+ },
182
+ { immediate: true },
183
+ );
226
184
 
227
- // On the thread-scoped path this hook owns an agent registered under
228
- // `agentId` that routes to `runtimeAgentId`. Register/unregister as one
229
- // balanced watcher — the cleanup runs both when the ids change and when the
230
- // scope is disposed. Mirrors React's registration effect, including its dep
231
- // set (core identity plus the two ids).
232
- const registeredProxy = shallowRef<AbstractAgent | null>(null);
185
+ // Thread-scoped path: this hook owns a proxied agent registered under
186
+ // `agentId` that routes to `runtimeAgentId`. The cleanup unregisters both
187
+ // when the ids change and when the scope is disposed.
233
188
  if (isThreadScoped) {
234
189
  watch(
235
- [agentId, runtimeAgentId, () => copilotkit.value],
236
- ([id, rtId], _old, onCleanup) => {
237
- const { agent: proxy, unregister } =
238
- copilotkit.value.registerProxiedAgent({
239
- agentId: id as string,
240
- runtimeAgentId: rtId as string,
241
- });
242
- provisionalAgentCache.delete(id as string);
243
- registeredProxy.value = proxy;
244
- onCleanup(() => {
245
- unregister();
246
- registeredProxy.value = null;
247
- });
190
+ [agentId, runtimeAgentId, resolver],
191
+ ([id, rtId, current], _old, onCleanup) => {
192
+ if (rtId === undefined) return;
193
+ onCleanup(current.bindProxy({ agentId: id, runtimeAgentId: rtId }));
248
194
  },
249
195
  { immediate: true },
250
196
  );
251
197
  }
252
198
 
253
199
  const resolveAgent = () => {
254
- const id = agentId.value;
255
- const core = copilotkit.value;
256
-
257
- // Proxied path: this hook registered its own agent, so bypass the shared
258
- // registry lookup. Until registration lands, hand back a provisional proxy
259
- // so `agent` is never null and its identity stays stable.
260
- if (isThreadScoped) {
261
- const proxy = registeredProxy.value;
262
- if (proxy) {
263
- provisionalAgentCache.delete(id);
264
- const shouldForceUpdate = agent.value === proxy;
265
- agent.value = proxy;
266
- subscriptionAgent.value = proxy;
267
- if (shouldForceUpdate) triggerRef(agent);
268
- return;
269
- }
270
-
271
- const cachedProxy = provisionalAgentCache.get(id);
272
- if (cachedProxy) {
273
- core.applyHeadersToAgent(cachedProxy);
274
- agent.value = cachedProxy;
275
- subscriptionAgent.value = cachedProxy;
276
- return;
277
- }
278
-
279
- const provisionalProxy = new ProxiedCopilotRuntimeAgent({
280
- runtimeUrl: core.runtimeUrl,
281
- agentId: id,
282
- runtimeAgentId: runtimeAgentId.value as string,
283
- transport: core.runtimeTransport,
284
- runtimeMode: "pending",
285
- });
286
- core.applyHeadersToAgent(provisionalProxy);
287
- provisionalAgentCache.set(id, provisionalProxy);
288
- agent.value = provisionalProxy;
289
- subscriptionAgent.value = provisionalProxy;
290
- return;
291
- }
292
-
293
- const existing = core.getAgent(id);
294
- if (existing) {
295
- provisionalAgentCache.delete(id);
296
-
297
- const shouldForceUpdate = agent.value === existing;
298
- agent.value = existing;
299
- subscriptionAgent.value = existing;
300
- if (shouldForceUpdate) {
301
- triggerRef(agent);
302
- }
303
- return;
304
- }
305
-
306
- const isRuntimeConfigured = core.runtimeUrl !== undefined;
307
- const status = core.runtimeConnectionStatus;
308
-
309
- if (
310
- isRuntimeConfigured &&
311
- (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected ||
312
- status === CopilotKitCoreRuntimeConnectionStatus.Connecting ||
313
- status === CopilotKitCoreRuntimeConnectionStatus.Error)
314
- ) {
315
- const cached = provisionalAgentCache.get(id);
316
- if (cached) {
317
- core.applyHeadersToAgent(cached);
318
- agent.value = cached;
319
- subscriptionAgent.value = cached;
320
- return;
321
- }
322
-
323
- const provisional = createProvisionalAgent(
324
- id,
325
- core.runtimeUrl!,
326
- core.runtimeTransport,
327
- );
328
- provisionalAgentCache.set(id, provisional);
329
- agent.value = provisional;
330
- subscriptionAgent.value = provisional;
200
+ const resolved = resolver.value.resolve({
201
+ agentId: agentId.value,
202
+ runtimeAgentId: runtimeAgentId.value,
203
+ caller: "useAgent",
204
+ });
205
+ isReady.value = resolved.isReady;
206
+ if (agent.value === resolved.agent) {
207
+ triggerRef(agent);
331
208
  return;
332
209
  }
333
-
334
- const knownAgents = Object.keys(core.agents ?? {});
335
- const runtimePart = isRuntimeConfigured
336
- ? `runtimeUrl=${core.runtimeUrl}`
337
- : "no runtimeUrl";
338
- throw new Error(
339
- `useAgent: Agent '${id}' not found after runtime sync (${runtimePart}). ` +
340
- (knownAgents.length
341
- ? `Known agents: [${knownAgents.join(", ")}]`
342
- : "No agents registered.") +
343
- " Verify your runtime /info and/or agents__unsafe_dev_only.",
344
- );
210
+ agent.value = resolved.agent;
345
211
  };
346
212
 
347
213
  // Keyed on `ɵheadersGeneration`, not header VALUES: a builder's returned
348
214
  // token can change on every resolution without a new source ever being
349
- // set (a run refreshing the snapshot), and this must not re-run
350
- // `resolveAgent` (and force-trigger `agent`) on that (#1937).
351
- // A genuine source change (a real `setHeaders()` call) still re-runs it,
352
- // refreshing a cached provisional's headers via the branches above.
215
+ // set, and this must not re-run `resolveAgent` on that (#1937).
353
216
  //
354
- // `registeredProxy` is wrapped as a getter (`() => registeredProxy.value`)
355
- // rather than passed directly: Vue's multi-source `watch` sets
356
- // `forceTrigger = true` for the WHOLE array whenever any raw element is
357
- // itself a shallowRef/reactive object, which makes the callback run on
358
- // ANY dependency dirtying regardless of whether a source's value actually
359
- // changed — silently defeating the `ɵheadersGeneration` rekey above (and
360
- // every other source's diffing) the moment `registeredProxy` is present.
361
- // A getter reads the same value without contributing to that flag.
217
+ // Sources are getters, not refs: Vue's multi-source `watch` force-triggers
218
+ // the whole array when any raw element is a shallowRef, which would defeat
219
+ // the diffing of every other source.
362
220
  watch(
363
221
  [
364
222
  agentId,
365
- () => registeredProxy.value,
223
+ () => resolverRevision.value,
366
224
  () => copilotkit.value.agents,
367
225
  () => copilotkit.value.runtimeConnectionStatus,
368
226
  () => copilotkit.value.runtimeUrl,
369
227
  () => copilotkit.value.runtimeTransport,
370
228
  () => copilotkit.value.ɵheadersGeneration,
229
+ () => copilotkit.value.credentials,
371
230
  ],
372
231
  resolveAgent,
373
232
  { immediate: true },
374
233
  );
375
234
 
376
- // Pin the resolved thread onto the current agent. AbstractAgent auto-mints a
377
- // UUID when none is given, so without this the agent would ship its own random
378
- // id in /agent/run, /agent/connect and /agent/stop. Deps are deliberately just
379
- // the agent and the thread — matching React — so status/header churn cannot
380
- // re-fire this and overwrite a thread `CopilotChat` pinned for its own chat.
381
- // `() => agent.value`, not `agent`: Vue sets `forceTrigger` when any array
382
- // watch source is a shallow ref, which would re-run this on every
383
- // `triggerRef(agent)` — i.e. every streamed message — and re-pin a thread that
384
- // `CopilotChat` may have deliberately overridden for the chat it renders. A
385
- // getter fires only when the identity actually changes.
235
+ // Pin the resolved thread onto the current agent. Deps are just the agent
236
+ // identity and the thread, so status or header churn cannot re-pin a thread
237
+ // `CopilotChat` set for the chat it renders.
386
238
  watch(
387
239
  [() => agent.value, resolvedThreadId],
388
240
  ([currentAgent, threadId]) => {
389
241
  if (!currentAgent || !threadId) return;
390
- currentAgent.threadId = threadId as string;
242
+ currentAgent.threadId = threadId;
391
243
  },
392
244
  { immediate: true },
393
245
  );
394
246
 
395
- // Keyed on `ɵheadersGeneration`, not header VALUES: a builder's returned
396
- // token can change on every resolution without a new source ever being set,
397
- // and this watcher must not re-fire on that (see #1937).
398
247
  watch(
399
- [subscriptionAgent, () => copilotkit.value.ɵheadersGeneration],
248
+ [
249
+ () => agent.value,
250
+ () => copilotkit.value.ɵheadersGeneration,
251
+ () => copilotkit.value.credentials,
252
+ ],
400
253
  ([currentAgent]) => {
401
- if (ɵisHttpAgent(currentAgent)) {
402
- copilotkit.value.applyHeadersToAgent(currentAgent);
403
- }
254
+ if (currentAgent) resolver.value.refreshRequestSettings(currentAgent);
404
255
  },
405
256
  { immediate: true },
406
257
  );
407
258
 
408
- // Subscribe through the shared `CopilotKitCore.subscribeToAgentWithOptions`
409
- // API. Core owns:
410
- // - shared leading+trailing throttle window across `onMessagesChanged`
411
- // and `onStateChanged` (parity with React)
412
- // - safeCall-guarded callbacks (errors in subscribers never poison the
413
- // agent notification loop)
414
- // - validation/fallback for invalid `throttleMs`
415
- // - `onRunErrorEvent` in the run-status callback set
416
- //
417
- // The hook only schedules a microtask-batched `triggerRef(agent)` so
418
- // multiple synchronous notifications (e.g. state + run-status firing in
419
- // the same tick) coalesce into a single Vue re-render — matching React's
420
- // `queueMicrotask`-batched forceUpdate strategy.
259
+ // Core owns throttling, safe callbacks and `throttleMs` validation; the
260
+ // re-render is microtask-batched so notifications in one tick coalesce.
421
261
  watch(
422
- [subscriptionAgent, updateFlags, hookThrottleMs, providerThrottleMs],
423
- ([a, flags], _old, onCleanup) => {
424
- const f = flags as UseAgentUpdate[];
425
- if (!a || f.length === 0) return;
426
-
427
- let active = true;
428
- let batchScheduled = false;
429
- const batchedRefresh = () => {
430
- if (!active) return;
431
- if (!batchScheduled) {
432
- batchScheduled = true;
433
- queueMicrotask(() => {
434
- batchScheduled = false;
435
- if (active) {
436
- triggerRef(agent);
437
- }
438
- });
439
- }
440
- };
441
-
442
- const handlers: SubscribeToAgentSubscriber = {};
443
-
444
- if (f.includes(UseAgentUpdate.OnMessagesChanged)) {
445
- // Messages fire immediately (no microtask indirection) so shared-
446
- // window throttling in core sees an unadorned callback. Matches
447
- // React's `handlers.onMessagesChanged = forceUpdate`.
448
- handlers.onMessagesChanged = () => {
449
- if (active) triggerRef(agent);
450
- };
451
- }
452
-
453
- if (f.includes(UseAgentUpdate.OnStateChanged)) {
454
- handlers.onStateChanged = batchedRefresh;
455
- }
456
-
457
- if (f.includes(UseAgentUpdate.OnRunStatusChanged)) {
458
- handlers.onRunInitialized = batchedRefresh;
459
- handlers.onRunFinalized = batchedRefresh;
460
- handlers.onRunFailed = batchedRefresh;
461
- // Protocol-level RUN_ERROR event (distinct from `onRunFailed`
462
- // which handles local exceptions like network errors).
463
- handlers.onRunErrorEvent = batchedRefresh;
464
- }
465
-
466
- const subscription = copilotkit.value.subscribeToAgentWithOptions(
467
- a as AbstractAgent,
468
- handlers,
469
- { throttleMs: toValue(props.throttleMs) },
262
+ [() => agent.value, updateFlags, hookThrottleMs, providerThrottleMs],
263
+ ([currentAgent, flags], _old, onCleanup) => {
264
+ if (!currentAgent) return;
265
+ onCleanup(
266
+ ɵsubscribeToAgentUpdates(copilotkit.value, currentAgent, {
267
+ updates: flags,
268
+ throttleMs: toValue(props.throttleMs),
269
+ onUpdate: () => triggerRef(agent),
270
+ }),
470
271
  );
471
-
472
- onCleanup(() => {
473
- active = false;
474
- subscription.unsubscribe();
475
- });
476
272
  },
477
273
  { immediate: true },
478
274
  );
479
275
 
480
- return { agent };
276
+ return { agent, isReady };
481
277
  }