@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
@@ -3,8 +3,8 @@ import { computed, onBeforeUnmount, ref, watch } from "vue";
3
3
  import type { Message, ReasoningMessage } from "@ag-ui/core";
4
4
  import { IconChevronRight } from "../icons";
5
5
  import StreamingMarkdownDefault from "./StreamingMarkdownDefault.vue";
6
- import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
7
- import { CopilotChatDefaultLabels } from "../../providers/types";
6
+ import { ɵformatLabel, ɵformatReasoningDurationLabel } from "@copilotkit/core";
7
+ import { useChatLabels } from "./use-chat-labels";
8
8
 
9
9
  const props = withDefaults(
10
10
  defineProps<{
@@ -69,15 +69,6 @@ defineSlots<{
69
69
  }) => unknown;
70
70
  }>();
71
71
 
72
- function formatDuration(seconds: number): string {
73
- if (seconds < 1) return "a few seconds";
74
- if (seconds < 60) return `${Math.round(seconds)} seconds`;
75
- const mins = Math.floor(seconds / 60);
76
- const secs = Math.round(seconds % 60);
77
- if (secs === 0) return `${mins} minute${mins > 1 ? "s" : ""}`;
78
- return `${mins}m ${secs}s`;
79
- }
80
-
81
72
  const normalizedContent = computed(() =>
82
73
  typeof props.message.content === "string" ? props.message.content : "",
83
74
  );
@@ -133,13 +124,14 @@ onBeforeUnmount(() => {
133
124
  clearElapsedInterval();
134
125
  });
135
126
 
136
- const config = useCopilotChatConfiguration();
127
+ const labels = useChatLabels();
137
128
  /** `labels.reasoningMessageThinkingLabel` while streaming, then "Thought for …". */
138
129
  const label = computed(() =>
139
130
  isStreaming.value
140
- ? (config.value?.labels ?? CopilotChatDefaultLabels)
141
- .reasoningMessageThinkingLabel
142
- : `Thought for ${formatDuration(elapsed.value)}`,
131
+ ? labels.value.reasoningMessageThinkingLabel
132
+ : ɵformatLabel(labels.value.reasoningMessageThoughtForLabel, {
133
+ duration: ɵformatReasoningDurationLabel(elapsed.value, labels.value),
134
+ }),
143
135
  );
144
136
 
145
137
  function toggleOpen() {
@@ -10,8 +10,14 @@
10
10
  * a custom wildcard renderer draws whatever it draws.
11
11
  */
12
12
  import { computed, provide, ref } from "vue";
13
+ import {
14
+ ɵformatLabel,
15
+ ɵformatToolNames,
16
+ ɵgetToolCallGroupState,
17
+ ɵformatCountLabel,
18
+ } from "@copilotkit/core";
19
+ import type { ToolCallEntry } from "@copilotkit/core";
13
20
  import { useCopilotId } from "../ui/use-id";
14
- import type { ToolCallEntry } from "./tool-call-layout";
15
21
  import { ToolCallGroupContextKey } from "./tool-call-display-context";
16
22
  import type { ToolCallGroupContextValue } from "./tool-call-display-context";
17
23
  import {
@@ -19,13 +25,9 @@ import {
19
25
  ToolCallChevron,
20
26
  ToolCallFailedCount,
21
27
  ToolCallStatusIcon,
22
- entryPreview,
23
- entryStatus,
24
- pluralize,
25
- statusLabels,
26
- toolNames,
28
+ toolCallStatusLabel,
27
29
  } from "./tool-call-group-parts";
28
- import type { ToolCallStatusName } from "./tool-call-group-parts";
30
+ import { useChatLabels } from "./use-chat-labels";
29
31
  import type { CopilotChatToolCallGroupAppearance } from "./types";
30
32
 
31
33
  const props = withDefaults(
@@ -49,46 +51,22 @@ defineSlots<{
49
51
  call(props: { call: ToolCallEntry }): unknown;
50
52
  }>();
51
53
 
54
+ const labels = useChatLabels();
52
55
  const open = ref(false);
53
56
  const bodyId = useCopilotId("cpk-tool-call-group");
54
57
  const toggle = () => {
55
58
  open.value = !open.value;
56
59
  };
57
60
 
58
- const latest = computed(() => props.calls[props.calls.length - 1]);
59
- // Only an active group has a call in progress. Between calls nothing is
60
- // running, so the latest call stays the subject (or the label flickers).
61
- const current = computed(() =>
62
- props.isActive
63
- ? (props.calls.find((call) => !call.toolMessage) ?? latest.value)
64
- : undefined,
65
- );
66
- const preview = computed(() =>
67
- current.value ? entryPreview(current.value) : undefined,
68
- );
69
- const done = computed(
70
- () => props.calls.filter((call) => call.toolMessage).length,
71
- );
72
- const statuses = computed(() =>
73
- props.calls.map((call) => entryStatus(call, props.isActive)),
74
- );
75
- const failedIds = computed(
76
- () =>
77
- new Set(
78
- props.calls
79
- .filter((_, index) => statuses.value[index] === "failed")
80
- .map((call) => call.toolCall.id),
81
- ),
82
- );
83
- const status = computed<ToolCallStatusName>(() =>
84
- current.value
85
- ? "running"
86
- : failedIds.value.size > 0
87
- ? "failed"
88
- : statuses.value.includes("stopped")
89
- ? "stopped"
90
- : "done",
61
+ const state = computed(() =>
62
+ ɵgetToolCallGroupState(props.calls, props.isActive, open.value),
91
63
  );
64
+ const latest = computed(() => state.value.latest);
65
+ const current = computed(() => state.value.current);
66
+ const preview = computed(() => state.value.preview);
67
+ const done = computed(() => state.value.done);
68
+ const failedIds = computed(() => state.value.failedIds);
69
+ const status = computed(() => state.value.status);
92
70
  const single = computed(
93
71
  () =>
94
72
  props.appearance === "line" && props.calls.length === 1 && !current.value,
@@ -99,19 +77,31 @@ provide(
99
77
  computed<ToolCallGroupContextValue>(() => ({
100
78
  appearance: props.appearance,
101
79
  failedIds: failedIds.value,
80
+ statusById: state.value.statusById,
102
81
  active: props.isActive,
103
82
  })),
104
83
  );
105
84
 
106
85
  // Stack: a lone call is the top card of a stack with nothing behind it yet.
107
- const behind = computed(() =>
108
- open.value ? 0 : Math.min(props.calls.length - 1, 2),
86
+ const behind = computed(() => state.value.behind);
87
+ const latestStatus = computed(() => state.value.latestStatus);
88
+ const latestPreview = computed(() => state.value.latestPreview);
89
+ const runningLabel = computed(() =>
90
+ current.value
91
+ ? ɵformatLabel(labels.value.toolCallRunningLabel, {
92
+ name: current.value.toolCall.function.name,
93
+ })
94
+ : "",
109
95
  );
110
- const latestStatus = computed(() =>
111
- latest.value ? entryStatus(latest.value, props.isActive) : "done",
96
+ const usedToolsLabel = computed(() =>
97
+ ɵformatCountLabel(props.calls.length, {
98
+ one: labels.value.toolCallUsedToolsOne,
99
+ other: labels.value.toolCallUsedToolsOther,
100
+ }),
112
101
  );
113
- const latestPreview = computed(() =>
114
- latest.value ? entryPreview(latest.value) : undefined,
102
+ const toolNames = computed(() => ɵformatToolNames(props.calls));
103
+ const latestStatusLabel = computed(() =>
104
+ toolCallStatusLabel(labels.value, latestStatus.value),
115
105
  );
116
106
  const layer = "cpk-tool-call-group-stack-layer";
117
107
  </script>
@@ -144,20 +134,18 @@ const layer = "cpk-tool-call-group-stack-layer";
144
134
  @click="toggle"
145
135
  >
146
136
  <template v-if="current">
147
- <span class="cpk-tool-call-group-running cpk-shimmer"
148
- >Running {{ current.toolCall.function.name }}</span
149
- >
137
+ <span class="cpk-tool-call-group-running cpk-shimmer">{{
138
+ runningLabel
139
+ }}</span>
150
140
  <span v-if="preview" class="cpk-tool-call-group-preview">{{
151
141
  preview
152
142
  }}</span>
153
143
  </template>
154
144
  <template v-else>
155
- <span class="cpk-tool-call-group-line-summary"
156
- >Used {{ pluralize(calls.length, "tool") }}</span
157
- >
158
- <span class="cpk-tool-call-group-line-names">{{
159
- toolNames(calls)
145
+ <span class="cpk-tool-call-group-line-summary">{{
146
+ usedToolsLabel
160
147
  }}</span>
148
+ <span class="cpk-tool-call-group-line-names">{{ toolNames }}</span>
161
149
  <ToolCallFailedCount :calls="calls" />
162
150
  </template>
163
151
  <ToolCallChevron :open="open" />
@@ -206,10 +194,15 @@ const layer = "cpk-tool-call-group-stack-layer";
206
194
  @click="toggle"
207
195
  >
208
196
  <template v-if="open">
209
- {{ pluralize(calls.length, "tool call") }}
197
+ {{
198
+ ɵformatCountLabel(calls.length, {
199
+ one: labels.toolCallToolCallCountOne,
200
+ other: labels.toolCallToolCallCountOther,
201
+ })
202
+ }}
210
203
  <ToolCallFailedCount :calls="calls" />
211
204
  <span class="cpk-tool-call-group-stack-collapse">
212
- Collapse
205
+ {{ labels.toolCallCollapseLabel }}
213
206
  <ToolCallChevron
214
207
  :open="true"
215
208
  class="cpk-tool-call-group-stack-collapse-icon"
@@ -236,13 +229,16 @@ const layer = "cpk-tool-call-group-stack-layer";
236
229
  >
237
230
  <!-- The status icon is decorative, so say the status. -->
238
231
  <span class="cpk-tool-call-group-stack-status">{{
239
- statusLabels[latestStatus]
232
+ latestStatusLabel
240
233
  }}</span>
241
234
  </span>
242
235
  <span class="cpk-tool-call-group-stack-meta">
243
236
  <ToolCallFailedCount :calls="calls" />
244
237
  <span class="cpk-tool-call-group-stack-count">{{
245
- pluralize(calls.length, "call")
238
+ ɵformatCountLabel(calls.length, {
239
+ one: labels.toolCallCallCountOne,
240
+ other: labels.toolCallCallCountOther,
241
+ })
246
242
  }}</span>
247
243
  <ToolCallChevron
248
244
  :open="false"
@@ -255,9 +251,7 @@ const layer = "cpk-tool-call-group-stack-layer";
255
251
  call change ("read_file: Running", then "read_file: Done"); the
256
252
  button only names it. -->
257
253
  <span aria-live="polite" class="cpk-tool-call-group-stack-live">{{
258
- open
259
- ? ""
260
- : `${latest.toolCall.function.name}: ${statusLabels[latestStatus]}`
254
+ open ? "" : `${latest.toolCall.function.name}: ${latestStatusLabel}`
261
255
  }}</span>
262
256
  </div>
263
257
  <!-- Each call gets the collapsed stack's card, easing out of the stack. -->
@@ -292,28 +286,26 @@ const layer = "cpk-tool-call-group-stack-layer";
292
286
  >
293
287
  <ToolCallStatusIcon :status="status" />
294
288
  <template v-if="current">
295
- <span class="cpk-tool-call-group-running cpk-shimmer"
296
- >Running {{ current.toolCall.function.name }}</span
297
- >
289
+ <span class="cpk-tool-call-group-running cpk-shimmer">{{
290
+ runningLabel
291
+ }}</span>
298
292
  <span v-if="preview" class="cpk-tool-call-group-preview">{{
299
293
  preview
300
294
  }}</span>
301
295
  </template>
302
296
  <template v-else>
303
- <span class="cpk-tool-call-group-card-summary"
304
- >Used {{ pluralize(calls.length, "tool") }}</span
305
- >
306
- <span class="cpk-tool-call-group-card-names">{{
307
- toolNames(calls)
297
+ <span class="cpk-tool-call-group-card-summary">{{
298
+ usedToolsLabel
308
299
  }}</span>
300
+ <span class="cpk-tool-call-group-card-names">{{ toolNames }}</span>
309
301
  </template>
310
302
  <span class="cpk-tool-call-group-card-meta">
311
303
  <ToolCallFailedCount v-if="status === 'failed'" :calls="calls" />
312
304
  <span v-else class="cpk-tool-call-group-card-status">{{
313
305
  status !== "running"
314
- ? statusLabels[status]
306
+ ? toolCallStatusLabel(labels, status)
315
307
  : done > 0
316
- ? `${done} done`
308
+ ? ɵformatLabel(labels.toolCallDoneCountLabel, { count: done })
317
309
  : ""
318
310
  }}</span>
319
311
  <ToolCallChevron :open="open" />
@@ -1,11 +1,13 @@
1
1
  <script setup lang="ts">
2
2
  import type { Message, ToolCall } from "@ag-ui/core";
3
- import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
3
+ import {
4
+ ɵresolveToolCallAgentId,
5
+ ɵresolveToolCallRenderer,
6
+ } from "@copilotkit/core";
4
7
  import { useCopilotKit } from "../../providers/useCopilotKit";
5
8
  import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
6
9
  import type { CopilotChatToolCallRenderSlotProps } from "./types";
7
10
  import {
8
- getCoreRenderConfig,
9
11
  getCoreRenderProps,
10
12
  getToolCallMemoDeps,
11
13
  getToolCallRenderProps,
@@ -54,16 +56,16 @@ function getCoreProps() {
54
56
  }
55
57
 
56
58
  function getRenderConfig() {
57
- const agentId = config.value?.agentId ?? DEFAULT_AGENT_ID;
58
- return getCoreRenderConfig(
59
- props.toolCall,
59
+ const agentId = ɵresolveToolCallAgentId(config.value?.agentId, undefined);
60
+ return ɵresolveToolCallRenderer(
60
61
  copilotkit.value.renderToolCalls,
62
+ props.toolCall.function.name,
61
63
  agentId,
62
64
  );
63
65
  }
64
66
 
65
67
  function getMemoDeps() {
66
- const agentId = config.value?.agentId ?? DEFAULT_AGENT_ID;
68
+ const agentId = ɵresolveToolCallAgentId(config.value?.agentId, undefined);
67
69
  return getToolCallMemoDeps(
68
70
  props.toolCall,
69
71
  props.messages,
@@ -3,9 +3,18 @@ import { computed, defineComponent, h, inject, provide, useSlots } from "vue";
3
3
  import type { PropType } from "vue";
4
4
  import type { Slots, VNode } from "vue";
5
5
  import type { AssistantMessage, Message } from "@ag-ui/core";
6
+ import {
7
+ ɵgetToolCallGroupState,
8
+ ɵgetToolCallLayouts,
9
+ ɵgetToolCallRendererNames,
10
+ ɵtoolCallAppearance,
11
+ } from "@copilotkit/core";
12
+ import type {
13
+ CopilotChatToolCallDisplay,
14
+ ToolCallEntry,
15
+ } from "@copilotkit/core";
6
16
  import { useCopilotKit } from "../../providers/useCopilotKit";
7
17
  import type {
8
- CopilotChatToolCallGroupAppearance,
9
18
  CopilotChatToolCallRenderSlotProps,
10
19
  CopilotChatToolCallsGroupSlotProps,
11
20
  } from "./types";
@@ -17,14 +26,6 @@ import {
17
26
  ToolCallGroupContextKey,
18
27
  } from "./tool-call-display-context";
19
28
  import type { ToolCallGroupContextValue } from "./tool-call-display-context";
20
- import {
21
- getToolCallLayouts,
22
- getToolCallRendererNames,
23
- } from "./tool-call-layout";
24
- import type {
25
- CopilotChatToolCallDisplay,
26
- ToolCallEntry,
27
- } from "./tool-call-layout";
28
29
 
29
30
  const props = withDefaults(
30
31
  defineProps<{
@@ -54,14 +55,6 @@ defineSlots<{
54
55
 
55
56
  type ToolCallSlotName = "tool-call" | `tool-call-${string}`;
56
57
 
57
- const appearances: Partial<
58
- Record<CopilotChatToolCallDisplay, CopilotChatToolCallGroupAppearance>
59
- > = {
60
- grouped: "card",
61
- line: "line",
62
- stacked: "stack",
63
- };
64
-
65
58
  const componentSlots = useSlots() as Slots;
66
59
  const { copilotkit } = useCopilotKit();
67
60
  const context = inject(ToolCallDisplayContextKey, null);
@@ -84,13 +77,15 @@ const layout = computed(() => {
84
77
  if (display.value === "separate") return undefined;
85
78
  const viewLayout = context?.value.layouts.get(props.message.id);
86
79
  if (viewLayout) return viewLayout;
87
- const rendererNames = getToolCallRendererNames(
80
+ const rendererNames = ɵgetToolCallRendererNames(
88
81
  copilotkit.value.renderToolCalls,
89
- getToolCallSlotNames(),
90
- );
91
- return getToolCallLayouts([props.message], props.messages, rendererNames).get(
92
- props.message.id,
82
+ { slotNames: getToolCallSlotNames() },
93
83
  );
84
+ return ɵgetToolCallLayouts(
85
+ [props.message],
86
+ props.messages,
87
+ rendererNames,
88
+ ).get(props.message.id);
94
89
  });
95
90
 
96
91
  // Whether the agent may still finish a trailing group's calls. Without a
@@ -99,7 +94,7 @@ const layout = computed(() => {
99
94
  const groupActive = (trailing: boolean) =>
100
95
  trailing && (context ? context.value.isRunning : true);
101
96
 
102
- const appearance = computed(() => appearances[display.value] ?? "card");
97
+ const appearance = computed(() => ɵtoolCallAppearance(display.value) ?? "card");
103
98
 
104
99
  const workOpen = computed(() => context?.value.workOpen.get(props.message.id));
105
100
 
@@ -115,15 +110,19 @@ const TurnRows = defineComponent({
115
110
  setup(rowProps, { slots }) {
116
111
  provide(
117
112
  ToolCallGroupContextKey,
118
- computed<ToolCallGroupContextValue>(() => ({
119
- appearance: "line",
120
- failedIds: new Set(
121
- rowProps.calls
122
- .filter((call) => call.toolMessage?.error)
123
- .map((call) => call.toolCall.id),
124
- ),
125
- active: rowProps.active,
126
- })),
113
+ computed<ToolCallGroupContextValue>(() => {
114
+ const { failedIds, statusById } = ɵgetToolCallGroupState(
115
+ rowProps.calls,
116
+ rowProps.active,
117
+ false,
118
+ );
119
+ return {
120
+ appearance: "line",
121
+ failedIds,
122
+ statusById,
123
+ active: rowProps.active,
124
+ };
125
+ }),
127
126
  );
128
127
  return () => slots.default?.();
129
128
  },
@@ -1,12 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { computed, onBeforeUnmount, ref } from "vue";
2
+ import { computed } from "vue";
3
3
  import type { UserMessage } from "@ag-ui/core";
4
- import type {
5
- AudioInputPart,
6
- DocumentInputPart,
7
- ImageInputPart,
8
- VideoInputPart,
9
- } from "@copilotkit/shared";
4
+ import {
5
+ ɵflattenUserMessageContent,
6
+ ɵgetBranchNavState,
7
+ ɵgetUserMessageMediaFilename,
8
+ ɵgetUserMessageMediaParts,
9
+ } from "@copilotkit/core";
10
10
  import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
11
11
  import { CopilotChatDefaultLabels } from "../../providers/types";
12
12
  import {
@@ -18,6 +18,7 @@ import {
18
18
  } from "../icons";
19
19
  import CopilotTooltip from "../ui/CopilotTooltip.vue";
20
20
  import CopilotChatAttachmentRenderer from "./CopilotChatAttachmentRenderer.vue";
21
+ import { useCopyFeedback } from "./use-copy-feedback";
21
22
  import type {
22
23
  CopilotChatUserMessageBranchNavigationSlotProps,
23
24
  CopilotChatUserMessageCopyButtonSlotProps,
@@ -66,117 +67,34 @@ const emit = defineEmits<{
66
67
 
67
68
  const config = useCopilotChatConfiguration();
68
69
  const labels = computed(() => config.value?.labels ?? CopilotChatDefaultLabels);
69
- const copied = ref(false);
70
- let copiedResetTimeout: ReturnType<typeof setTimeout> | null = null;
70
+ const { copied, copy } = useCopyFeedback();
71
71
 
72
72
  // Styles live in @copilotkit/core (ui/button.css, user-message.css).
73
73
  const toolbarButtonClass =
74
74
  "cpk-button cpk-button-assistant-message-toolbar cpk-button-size-default";
75
75
 
76
- function flattenUserMessageContent(content?: UserMessage["content"]): string {
77
- if (!content) {
78
- return "";
79
- }
80
-
81
- if (typeof content === "string") {
82
- return content;
83
- }
84
-
85
- return content
86
- .map((part) => {
87
- if (
88
- part &&
89
- typeof part === "object" &&
90
- "type" in part &&
91
- (part as { type?: unknown }).type === "text" &&
92
- typeof (part as { text?: unknown }).text === "string"
93
- ) {
94
- return (part as { text: string }).text;
95
- }
96
- return "";
97
- })
98
- .filter((text) => text.length > 0)
99
- .join("\n");
100
- }
101
-
102
- type MediaPart =
103
- | ImageInputPart
104
- | AudioInputPart
105
- | VideoInputPart
106
- | DocumentInputPart;
107
-
108
- function getMediaParts(content: UserMessage["content"]): MediaPart[] {
109
- if (!content || typeof content === "string") return [];
110
- return content.filter(
111
- (part): part is MediaPart =>
112
- part.type === "image" ||
113
- part.type === "audio" ||
114
- part.type === "video" ||
115
- part.type === "document",
116
- );
117
- }
118
-
119
- function getFilename(part: MediaPart): string | undefined {
120
- const meta = part.metadata;
121
- if (
122
- meta != null &&
123
- typeof meta === "object" &&
124
- "filename" in meta &&
125
- typeof meta.filename === "string"
126
- ) {
127
- return meta.filename;
128
- }
129
- return undefined;
130
- }
131
-
132
- const mediaParts = computed(() => getMediaParts(props.message.content));
76
+ const mediaParts = computed(() =>
77
+ ɵgetUserMessageMediaParts(props.message.content),
78
+ );
133
79
 
134
80
  const flattenedContent = computed(() =>
135
- flattenUserMessageContent(props.message.content),
81
+ ɵflattenUserMessageContent(props.message.content),
136
82
  );
137
83
  const isMultiline = computed(() => flattenedContent.value.includes("\n"));
138
84
  const hasEditAction = computed(() => typeof props.onEditMessage === "function");
139
- const showBranchNavigation = computed(
140
- () =>
141
- props.numberOfBranches > 1 && typeof props.onSwitchToBranch === "function",
142
- );
143
-
144
- const canGoPrev = computed(
145
- () => showBranchNavigation.value && props.branchIndex > 0,
146
- );
147
- const canGoNext = computed(
148
- () =>
149
- showBranchNavigation.value &&
150
- props.branchIndex < props.numberOfBranches - 1,
85
+ const branchNav = computed(() =>
86
+ ɵgetBranchNavState({
87
+ branchIndex: props.branchIndex,
88
+ numberOfBranches: props.numberOfBranches,
89
+ canSwitch: typeof props.onSwitchToBranch === "function",
90
+ }),
151
91
  );
152
-
153
- function resetCopiedStateWithDelay() {
154
- if (copiedResetTimeout) {
155
- clearTimeout(copiedResetTimeout);
156
- }
157
- copied.value = true;
158
- copiedResetTimeout = setTimeout(() => {
159
- copied.value = false;
160
- copiedResetTimeout = null;
161
- }, 2000);
162
- }
92
+ const showBranchNavigation = computed(() => branchNav.value.show);
93
+ const canGoPrev = computed(() => branchNav.value.canGoPrev);
94
+ const canGoNext = computed(() => branchNav.value.canGoNext);
163
95
 
164
96
  async function handleCopyMessage() {
165
- if (!flattenedContent.value) return;
166
-
167
- if (
168
- typeof navigator === "undefined" ||
169
- typeof navigator.clipboard?.writeText !== "function"
170
- ) {
171
- return;
172
- }
173
-
174
- try {
175
- await navigator.clipboard.writeText(flattenedContent.value);
176
- resetCopiedStateWithDelay();
177
- } catch (error) {
178
- console.error("Failed to copy to clipboard:", error);
179
- }
97
+ await copy(flattenedContent.value);
180
98
  }
181
99
 
182
100
  function handleEditMessage() {
@@ -212,12 +130,6 @@ function goNext() {
212
130
  }
213
131
  switchToBranch(props.branchIndex + 1);
214
132
  }
215
-
216
- onBeforeUnmount(() => {
217
- if (copiedResetTimeout) {
218
- clearTimeout(copiedResetTimeout);
219
- }
220
- });
221
133
  </script>
222
134
 
223
135
  <template>
@@ -255,7 +167,7 @@ onBeforeUnmount(() => {
255
167
  :key="index"
256
168
  :type="part.type"
257
169
  :source="part.source"
258
- :filename="getFilename(part)"
170
+ :filename="ɵgetUserMessageMediaFilename(part)"
259
171
  />
260
172
  </div>
261
173