@copilotkit/vue 1.57.1

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 (437) hide show
  1. package/AGENTS.md +50 -0
  2. package/CHANGELOG.md +13 -0
  3. package/PARITY.md +434 -0
  4. package/README.md +396 -0
  5. package/dist/components/copilot-provider/CopilotKit.vue.d.ts +20 -0
  6. package/dist/components/copilot-provider/CopilotKit.vue.d.ts.map +1 -0
  7. package/dist/components/copilot-provider/index.d.ts +3 -0
  8. package/dist/components/copilot-provider/index.d.ts.map +1 -0
  9. package/dist/components/copilot-provider/types.d.ts +22 -0
  10. package/dist/components/copilot-provider/types.d.ts.map +1 -0
  11. package/dist/hooks/index.d.ts +7 -0
  12. package/dist/hooks/index.d.ts.map +1 -0
  13. package/dist/hooks/use-copilot-action.d.ts +27 -0
  14. package/dist/hooks/use-copilot-action.d.ts.map +1 -0
  15. package/dist/hooks/use-copilot-readable.d.ts +20 -0
  16. package/dist/hooks/use-copilot-readable.d.ts.map +1 -0
  17. package/dist/hooks/use-frontend-tool.d.ts +21 -0
  18. package/dist/hooks/use-frontend-tool.d.ts.map +1 -0
  19. package/dist/index.cjs +2 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +10 -0
  22. package/dist/index.d.mts +10 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.mjs +252 -0
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/styles.css +2 -0
  28. package/dist/use-render-activity-message-BRL1Rpl-.cjs +85 -0
  29. package/dist/use-render-activity-message-BRL1Rpl-.cjs.map +1 -0
  30. package/dist/use-render-activity-message-CqtxiFSs.js +8927 -0
  31. package/dist/use-render-activity-message-CqtxiFSs.js.map +1 -0
  32. package/dist/v2/components/A2UIMessageRenderer.d.ts +9 -0
  33. package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -0
  34. package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts +16 -0
  35. package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -0
  36. package/dist/v2/components/CopilotKitInspector.vue.d.ts +7 -0
  37. package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -0
  38. package/dist/v2/components/InlineFeatureWarning.vue.d.ts +6 -0
  39. package/dist/v2/components/InlineFeatureWarning.vue.d.ts.map +1 -0
  40. package/dist/v2/components/LicenseWarningBanner.vue.d.ts +18 -0
  41. package/dist/v2/components/LicenseWarningBanner.vue.d.ts.map +1 -0
  42. package/dist/v2/components/MCPAppsActivityRenderer.d.ts +88 -0
  43. package/dist/v2/components/MCPAppsActivityRenderer.d.ts.map +1 -0
  44. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +154 -0
  45. package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -0
  46. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +19 -0
  47. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -0
  48. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +16 -0
  49. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -0
  50. package/dist/v2/components/a2ui/VueSurface.d.ts +62 -0
  51. package/dist/v2/components/a2ui/VueSurface.d.ts.map +1 -0
  52. package/dist/v2/components/a2ui/adapter.d.ts +38 -0
  53. package/dist/v2/components/a2ui/adapter.d.ts.map +1 -0
  54. package/dist/v2/components/a2ui/catalog.d.ts +29 -0
  55. package/dist/v2/components/a2ui/catalog.d.ts.map +1 -0
  56. package/dist/v2/components/a2ui/index.d.ts +5 -0
  57. package/dist/v2/components/a2ui/index.d.ts.map +1 -0
  58. package/dist/v2/components/a2ui/utils.d.ts +18 -0
  59. package/dist/v2/components/a2ui/utils.d.ts.map +1 -0
  60. package/dist/v2/components/a2ui.d.ts +12 -0
  61. package/dist/v2/components/a2ui.d.ts.map +1 -0
  62. package/dist/v2/components/chat/CopilotChat.vue.d.ts +50 -0
  63. package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -0
  64. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +164 -0
  65. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -0
  66. package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts +12 -0
  67. package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -0
  68. package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts +7 -0
  69. package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -0
  70. package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts +12 -0
  71. package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -0
  72. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +290 -0
  73. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -0
  74. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +72 -0
  75. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -0
  76. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts +65 -0
  77. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -0
  78. package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts +27 -0
  79. package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts.map +1 -0
  80. package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts +26 -0
  81. package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts.map +1 -0
  82. package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts +17 -0
  83. package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts.map +1 -0
  84. package/dist/v2/components/chat/CopilotChatToggleButtonCloseIcon.d.ts +5 -0
  85. package/dist/v2/components/chat/CopilotChatToggleButtonCloseIcon.d.ts.map +1 -0
  86. package/dist/v2/components/chat/CopilotChatToggleButtonOpenIcon.d.ts +5 -0
  87. package/dist/v2/components/chat/CopilotChatToggleButtonOpenIcon.d.ts.map +1 -0
  88. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +21 -0
  89. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -0
  90. package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts +34 -0
  91. package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -0
  92. package/dist/v2/components/chat/CopilotChatView.vue.d.ts +106 -0
  93. package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -0
  94. package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts +15 -0
  95. package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -0
  96. package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts +5 -0
  97. package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts.map +1 -0
  98. package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts +5 -0
  99. package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts.map +1 -0
  100. package/dist/v2/components/chat/CopilotPopup.vue.d.ts +50 -0
  101. package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -0
  102. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +55 -0
  103. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -0
  104. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +55 -0
  105. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -0
  106. package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts +28 -0
  107. package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts.map +1 -0
  108. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +48 -0
  109. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -0
  110. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +62 -0
  111. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -0
  112. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +53 -0
  113. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -0
  114. package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts +28 -0
  115. package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts.map +1 -0
  116. package/dist/v2/components/chat/audioRecorder.d.ts +11 -0
  117. package/dist/v2/components/chat/audioRecorder.d.ts.map +1 -0
  118. package/dist/v2/components/chat/index.d.ts +682 -0
  119. package/dist/v2/components/chat/index.d.ts.map +1 -0
  120. package/dist/v2/components/chat/last-user-message-context.d.ts +29 -0
  121. package/dist/v2/components/chat/last-user-message-context.d.ts.map +1 -0
  122. package/dist/v2/components/chat/normalize-auto-scroll.d.ts +3 -0
  123. package/dist/v2/components/chat/normalize-auto-scroll.d.ts.map +1 -0
  124. package/dist/v2/components/chat/types.d.ts +380 -0
  125. package/dist/v2/components/chat/types.d.ts.map +1 -0
  126. package/dist/v2/components/icons/index.d.ts +2 -0
  127. package/dist/v2/components/icons/index.d.ts.map +1 -0
  128. package/dist/v2/components/index.d.ts +8 -0
  129. package/dist/v2/components/index.d.ts.map +1 -0
  130. package/dist/v2/hooks/index.d.ts +24 -0
  131. package/dist/v2/hooks/index.d.ts.map +1 -0
  132. package/dist/v2/hooks/use-agent-context.d.ts +24 -0
  133. package/dist/v2/hooks/use-agent-context.d.ts.map +1 -0
  134. package/dist/v2/hooks/use-agent.d.ts +53 -0
  135. package/dist/v2/hooks/use-agent.d.ts.map +1 -0
  136. package/dist/v2/hooks/use-attachments.d.ts +21 -0
  137. package/dist/v2/hooks/use-attachments.d.ts.map +1 -0
  138. package/dist/v2/hooks/use-capabilities.d.ts +16 -0
  139. package/dist/v2/hooks/use-capabilities.d.ts.map +1 -0
  140. package/dist/v2/hooks/use-component.d.ts +13 -0
  141. package/dist/v2/hooks/use-component.d.ts.map +1 -0
  142. package/dist/v2/hooks/use-configure-suggestions.d.ts +24 -0
  143. package/dist/v2/hooks/use-configure-suggestions.d.ts.map +1 -0
  144. package/dist/v2/hooks/use-default-render-tool.d.ts +14 -0
  145. package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -0
  146. package/dist/v2/hooks/use-frontend-tool.d.ts +19 -0
  147. package/dist/v2/hooks/use-frontend-tool.d.ts.map +1 -0
  148. package/dist/v2/hooks/use-human-in-the-loop.d.ts +19 -0
  149. package/dist/v2/hooks/use-human-in-the-loop.d.ts.map +1 -0
  150. package/dist/v2/hooks/use-interrupt.d.ts +36 -0
  151. package/dist/v2/hooks/use-interrupt.d.ts.map +1 -0
  152. package/dist/v2/hooks/use-katex-styles.d.ts +22 -0
  153. package/dist/v2/hooks/use-katex-styles.d.ts.map +1 -0
  154. package/dist/v2/hooks/use-keyboard-height.d.ts +33 -0
  155. package/dist/v2/hooks/use-keyboard-height.d.ts.map +1 -0
  156. package/dist/v2/hooks/use-pin-to-send.d.ts +28 -0
  157. package/dist/v2/hooks/use-pin-to-send.d.ts.map +1 -0
  158. package/dist/v2/hooks/use-render-activity-message.d.ts +21 -0
  159. package/dist/v2/hooks/use-render-activity-message.d.ts.map +1 -0
  160. package/dist/v2/hooks/use-render-custom-messages.d.ts +27 -0
  161. package/dist/v2/hooks/use-render-custom-messages.d.ts.map +1 -0
  162. package/dist/v2/hooks/use-render-tool.d.ts +36 -0
  163. package/dist/v2/hooks/use-render-tool.d.ts.map +1 -0
  164. package/dist/v2/hooks/use-suggestions.d.ts +26 -0
  165. package/dist/v2/hooks/use-suggestions.d.ts.map +1 -0
  166. package/dist/v2/hooks/use-threads.d.ts +42 -0
  167. package/dist/v2/hooks/use-threads.d.ts.map +1 -0
  168. package/dist/v2/index.cjs +2 -0
  169. package/dist/v2/index.cjs.map +1 -0
  170. package/dist/v2/index.d.cts +9 -0
  171. package/dist/v2/index.d.mts +9 -0
  172. package/dist/v2/index.d.ts +9 -0
  173. package/dist/v2/index.d.ts.map +1 -0
  174. package/dist/v2/index.mjs +75 -0
  175. package/dist/v2/index.mjs.map +1 -0
  176. package/dist/v2/lib/processPartialHtml.d.ts +3 -0
  177. package/dist/v2/lib/processPartialHtml.d.ts.map +1 -0
  178. package/dist/v2/lib/shallow-stable.d.ts +7 -0
  179. package/dist/v2/lib/shallow-stable.d.ts.map +1 -0
  180. package/dist/v2/lib/transcription-client.d.ts +19 -0
  181. package/dist/v2/lib/transcription-client.d.ts.map +1 -0
  182. package/dist/v2/lib/vue-core.d.ts +47 -0
  183. package/dist/v2/lib/vue-core.d.ts.map +1 -0
  184. package/dist/v2/providers/CopilotChatConfigurationProvider.types.d.ts +15 -0
  185. package/dist/v2/providers/CopilotChatConfigurationProvider.types.d.ts.map +1 -0
  186. package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts +17 -0
  187. package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -0
  188. package/dist/v2/providers/CopilotKitProvider.types.d.ts +61 -0
  189. package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -0
  190. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +37 -0
  191. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -0
  192. package/dist/v2/providers/SandboxFunctionsContext.d.ts +4 -0
  193. package/dist/v2/providers/SandboxFunctionsContext.d.ts.map +1 -0
  194. package/dist/v2/providers/index.d.ts +13 -0
  195. package/dist/v2/providers/index.d.ts.map +1 -0
  196. package/dist/v2/providers/keys.d.ts +17 -0
  197. package/dist/v2/providers/keys.d.ts.map +1 -0
  198. package/dist/v2/providers/license-context.d.ts +7 -0
  199. package/dist/v2/providers/license-context.d.ts.map +1 -0
  200. package/dist/v2/providers/types.d.ts +38 -0
  201. package/dist/v2/providers/types.d.ts.map +1 -0
  202. package/dist/v2/providers/useCopilotChatConfiguration.d.ts +4 -0
  203. package/dist/v2/providers/useCopilotChatConfiguration.d.ts.map +1 -0
  204. package/dist/v2/providers/useCopilotKit.d.ts +2 -0
  205. package/dist/v2/providers/useCopilotKit.d.ts.map +1 -0
  206. package/dist/v2/providers/useLicenseContext.d.ts +14 -0
  207. package/dist/v2/providers/useLicenseContext.d.ts.map +1 -0
  208. package/dist/v2/types/a2ui.d.ts +5 -0
  209. package/dist/v2/types/a2ui.d.ts.map +1 -0
  210. package/dist/v2/types/defineToolCallRenderer.d.ts +15 -0
  211. package/dist/v2/types/defineToolCallRenderer.d.ts.map +1 -0
  212. package/dist/v2/types/frontend-tool.d.ts +6 -0
  213. package/dist/v2/types/frontend-tool.d.ts.map +1 -0
  214. package/dist/v2/types/human-in-the-loop.d.ts +29 -0
  215. package/dist/v2/types/human-in-the-loop.d.ts.map +1 -0
  216. package/dist/v2/types/index.d.ts +10 -0
  217. package/dist/v2/types/index.d.ts.map +1 -0
  218. package/dist/v2/types/interrupt.d.ts +14 -0
  219. package/dist/v2/types/interrupt.d.ts.map +1 -0
  220. package/dist/v2/types/sandbox-function.d.ts +8 -0
  221. package/dist/v2/types/sandbox-function.d.ts.map +1 -0
  222. package/dist/v2/types/vue-activity-message-renderer.d.ts +18 -0
  223. package/dist/v2/types/vue-activity-message-renderer.d.ts.map +1 -0
  224. package/dist/v2/types/vue-custom-message-renderer.d.ts +19 -0
  225. package/dist/v2/types/vue-custom-message-renderer.d.ts.map +1 -0
  226. package/dist/v2/types/vue-tool-call-renderer.d.ts +37 -0
  227. package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -0
  228. package/env.d.ts +7 -0
  229. package/eslint.config.mjs +42 -0
  230. package/package.json +130 -0
  231. package/scripts/scope-preflight.mjs +100 -0
  232. package/src/components/copilot-provider/CopilotKit.vue +18 -0
  233. package/src/components/copilot-provider/index.ts +2 -0
  234. package/src/components/copilot-provider/types.ts +24 -0
  235. package/src/hooks/index.ts +9 -0
  236. package/src/hooks/use-copilot-action.ts +168 -0
  237. package/src/hooks/use-copilot-readable.ts +75 -0
  238. package/src/hooks/use-frontend-tool.ts +76 -0
  239. package/src/index.ts +12 -0
  240. package/src/styles/globals.css +314 -0
  241. package/src/v2/__tests__/exports.test.ts +35 -0
  242. package/src/v2/__tests__/mocks/web-inspector.ts +5 -0
  243. package/src/v2/__tests__/setup.ts +141 -0
  244. package/src/v2/__tests__/utils/agents.ts +391 -0
  245. package/src/v2/__tests__/utils/mount.ts +83 -0
  246. package/src/v2/__tests__/utils/test-helpers.ts +712 -0
  247. package/src/v2/components/A2UIMessageRenderer.ts +125 -0
  248. package/src/v2/components/A2UISurfaceActivityRenderer.vue +186 -0
  249. package/src/v2/components/CopilotKitInspector.vue +42 -0
  250. package/src/v2/components/InlineFeatureWarning.vue +35 -0
  251. package/src/v2/components/LicenseWarningBanner.vue +196 -0
  252. package/src/v2/components/MCPAppsActivityRenderer.ts +778 -0
  253. package/src/v2/components/OpenGenerativeUIRenderer.ts +550 -0
  254. package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +271 -0
  255. package/src/v2/components/__tests__/CopilotKitInspector.test.ts +57 -0
  256. package/src/v2/components/__tests__/MCPAppsActivityRenderer.e2e.test.ts +851 -0
  257. package/src/v2/components/__tests__/MCPAppsActivityRenderer.test.ts +237 -0
  258. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +516 -0
  259. package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +295 -0
  260. package/src/v2/components/a2ui/A2UICatalogContext.ts +190 -0
  261. package/src/v2/components/a2ui/VueSurface.ts +144 -0
  262. package/src/v2/components/a2ui/adapter.ts +156 -0
  263. package/src/v2/components/a2ui/catalog.ts +858 -0
  264. package/src/v2/components/a2ui/index.ts +7 -0
  265. package/src/v2/components/a2ui/utils.ts +67 -0
  266. package/src/v2/components/a2ui.ts +30 -0
  267. package/src/v2/components/chat/CopilotChat.vue +777 -0
  268. package/src/v2/components/chat/CopilotChatAssistantMessage.vue +891 -0
  269. package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +411 -0
  270. package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +87 -0
  271. package/src/v2/components/chat/CopilotChatAudioRecorder.vue +269 -0
  272. package/src/v2/components/chat/CopilotChatInput.vue +1271 -0
  273. package/src/v2/components/chat/CopilotChatMessageView.vue +476 -0
  274. package/src/v2/components/chat/CopilotChatReasoningMessage.vue +247 -0
  275. package/src/v2/components/chat/CopilotChatSuggestionPill.vue +56 -0
  276. package/src/v2/components/chat/CopilotChatSuggestionView.vue +93 -0
  277. package/src/v2/components/chat/CopilotChatToggleButton.vue +145 -0
  278. package/src/v2/components/chat/CopilotChatToggleButtonCloseIcon.ts +17 -0
  279. package/src/v2/components/chat/CopilotChatToggleButtonOpenIcon.ts +18 -0
  280. package/src/v2/components/chat/CopilotChatToolCallsView.vue +161 -0
  281. package/src/v2/components/chat/CopilotChatUserMessage.vue +322 -0
  282. package/src/v2/components/chat/CopilotChatView.vue +740 -0
  283. package/src/v2/components/chat/CopilotModalHeader.vue +73 -0
  284. package/src/v2/components/chat/CopilotModalHeaderCloseButton.ts +38 -0
  285. package/src/v2/components/chat/CopilotModalHeaderTitle.ts +22 -0
  286. package/src/v2/components/chat/CopilotPopup.vue +182 -0
  287. package/src/v2/components/chat/CopilotPopupView.vue +168 -0
  288. package/src/v2/components/chat/CopilotPopupViewInternal.vue +453 -0
  289. package/src/v2/components/chat/CopilotPopupWelcomeScreen.vue +140 -0
  290. package/src/v2/components/chat/CopilotSidebar.vue +178 -0
  291. package/src/v2/components/chat/CopilotSidebarView.vue +172 -0
  292. package/src/v2/components/chat/CopilotSidebarViewInternal.vue +366 -0
  293. package/src/v2/components/chat/CopilotSidebarWelcomeScreen.vue +142 -0
  294. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.ts +237 -0
  295. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.ts +1240 -0
  296. package/src/v2/components/chat/__tests__/CopilotChat.licenseWarning.test.ts +138 -0
  297. package/src/v2/components/chat/__tests__/CopilotChat.onError.test.ts +85 -0
  298. package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.ts +141 -0
  299. package/src/v2/components/chat/__tests__/CopilotChat.test.ts +652 -0
  300. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +683 -0
  301. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.ts +768 -0
  302. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.ts +1108 -0
  303. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.ts +87 -0
  304. package/src/v2/components/chat/__tests__/CopilotChatAttachmentQueue.test.ts +277 -0
  305. package/src/v2/components/chat/__tests__/CopilotChatAttachmentRenderer.test.ts +124 -0
  306. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.ts +230 -0
  307. package/src/v2/components/chat/__tests__/CopilotChatInput.bottomAnchored.test.ts +83 -0
  308. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.ts +1139 -0
  309. package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +1051 -0
  310. package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.ts +141 -0
  311. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.ts +494 -0
  312. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.ts +181 -0
  313. package/src/v2/components/chat/__tests__/CopilotChatReasoningMessage.test.ts +73 -0
  314. package/src/v2/components/chat/__tests__/CopilotChatSuggestionPill.test.ts +73 -0
  315. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.ts +674 -0
  316. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.test.ts +91 -0
  317. package/src/v2/components/chat/__tests__/CopilotChatToggleButton.test.ts +93 -0
  318. package/src/v2/components/chat/__tests__/CopilotChatToolCallsView.test.ts +382 -0
  319. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.ts +1019 -0
  320. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.ts +516 -0
  321. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.ts +701 -0
  322. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.test.ts +337 -0
  323. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.ts +135 -0
  324. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.ts +278 -0
  325. package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.ts +1082 -0
  326. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.ts +166 -0
  327. package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.ts +1145 -0
  328. package/src/v2/components/chat/__tests__/CopilotChatView.test.ts +374 -0
  329. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.ts +636 -0
  330. package/src/v2/components/chat/__tests__/CopilotModalHeader.test.ts +112 -0
  331. package/src/v2/components/chat/__tests__/CopilotPopup.test.ts +58 -0
  332. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.ts +725 -0
  333. package/src/v2/components/chat/__tests__/CopilotPopupView.test.ts +112 -0
  334. package/src/v2/components/chat/__tests__/CopilotSidebar.test.ts +58 -0
  335. package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.ts +603 -0
  336. package/src/v2/components/chat/__tests__/CopilotSidebarView.test.ts +214 -0
  337. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.ts +394 -0
  338. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.ts +82 -0
  339. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +39 -0
  340. package/src/v2/components/chat/audioRecorder.ts +15 -0
  341. package/src/v2/components/chat/index.ts +52 -0
  342. package/src/v2/components/chat/last-user-message-context.ts +39 -0
  343. package/src/v2/components/chat/normalize-auto-scroll.ts +17 -0
  344. package/src/v2/components/chat/types.ts +481 -0
  345. package/src/v2/components/icons/__tests__/icons.test.ts +86 -0
  346. package/src/v2/components/icons/index.ts +22 -0
  347. package/src/v2/components/index.ts +7 -0
  348. package/src/v2/hooks/__tests__/standard-schema-types.test.ts +149 -0
  349. package/src/v2/hooks/__tests__/standard-schema.test.ts +315 -0
  350. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.ts +144 -0
  351. package/src/v2/hooks/__tests__/use-agent-context.test.ts +271 -0
  352. package/src/v2/hooks/__tests__/use-agent-error-state.test.ts +64 -0
  353. package/src/v2/hooks/__tests__/use-agent-stability.test.ts +268 -0
  354. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.ts +433 -0
  355. package/src/v2/hooks/__tests__/use-agent-throttle.test.ts +747 -0
  356. package/src/v2/hooks/__tests__/use-agent.e2e.test.ts +187 -0
  357. package/src/v2/hooks/__tests__/use-agent.test.ts +126 -0
  358. package/src/v2/hooks/__tests__/use-attachments.test.ts +181 -0
  359. package/src/v2/hooks/__tests__/use-component.test.ts +145 -0
  360. package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.ts +527 -0
  361. package/src/v2/hooks/__tests__/use-configure-suggestions.test.ts +399 -0
  362. package/src/v2/hooks/__tests__/use-default-render-tool.test.ts +214 -0
  363. package/src/v2/hooks/__tests__/use-frontend-tool-available.test.ts +220 -0
  364. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +2320 -0
  365. package/src/v2/hooks/__tests__/use-frontend-tool.test.ts +648 -0
  366. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.ts +1379 -0
  367. package/src/v2/hooks/__tests__/use-human-in-the-loop.test.ts +282 -0
  368. package/src/v2/hooks/__tests__/use-interrupt.test.ts +345 -0
  369. package/src/v2/hooks/__tests__/use-katex-styles.test.ts +69 -0
  370. package/src/v2/hooks/__tests__/use-keyboard-height.test.ts +199 -0
  371. package/src/v2/hooks/__tests__/use-pin-to-send.test.ts +363 -0
  372. package/src/v2/hooks/__tests__/use-render-tool.test.ts +329 -0
  373. package/src/v2/hooks/__tests__/use-suggestions.e2e.test.ts +397 -0
  374. package/src/v2/hooks/__tests__/use-suggestions.test.ts +198 -0
  375. package/src/v2/hooks/__tests__/use-threads.test.ts +1041 -0
  376. package/src/v2/hooks/__tests__/zod-regression.test.ts +339 -0
  377. package/src/v2/hooks/index.ts +29 -0
  378. package/src/v2/hooks/use-agent-context.ts +55 -0
  379. package/src/v2/hooks/use-agent.ts +345 -0
  380. package/src/v2/hooks/use-attachments.ts +261 -0
  381. package/src/v2/hooks/use-capabilities.ts +30 -0
  382. package/src/v2/hooks/use-component.ts +46 -0
  383. package/src/v2/hooks/use-configure-suggestions.ts +252 -0
  384. package/src/v2/hooks/use-default-render-tool.ts +130 -0
  385. package/src/v2/hooks/use-frontend-tool.ts +68 -0
  386. package/src/v2/hooks/use-human-in-the-loop.ts +90 -0
  387. package/src/v2/hooks/use-interrupt.ts +257 -0
  388. package/src/v2/hooks/use-katex-styles.ts +44 -0
  389. package/src/v2/hooks/use-keyboard-height.ts +87 -0
  390. package/src/v2/hooks/use-pin-to-send.ts +160 -0
  391. package/src/v2/hooks/use-render-activity-message.ts +92 -0
  392. package/src/v2/hooks/use-render-custom-messages.ts +129 -0
  393. package/src/v2/hooks/use-render-tool.ts +128 -0
  394. package/src/v2/hooks/use-suggestions.ts +98 -0
  395. package/src/v2/hooks/use-threads.ts +208 -0
  396. package/src/v2/index.ts +11 -0
  397. package/src/v2/lib/__tests__/processPartialHtml.test.ts +84 -0
  398. package/src/v2/lib/__tests__/transcription-client.test.ts +65 -0
  399. package/src/v2/lib/processPartialHtml.ts +21 -0
  400. package/src/v2/lib/shallow-stable.ts +54 -0
  401. package/src/v2/lib/transcription-client.ts +151 -0
  402. package/src/v2/lib/vue-core.ts +161 -0
  403. package/src/v2/providers/CopilotChatConfigurationProvider.types.ts +15 -0
  404. package/src/v2/providers/CopilotChatConfigurationProvider.vue +95 -0
  405. package/src/v2/providers/CopilotKitProvider.types.ts +66 -0
  406. package/src/v2/providers/CopilotKitProvider.vue +653 -0
  407. package/src/v2/providers/SandboxFunctionsContext.ts +11 -0
  408. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.ts +309 -0
  409. package/src/v2/providers/__tests__/CopilotKitProvider.debug.test.ts +295 -0
  410. package/src/v2/providers/__tests__/CopilotKitProvider.license.test.ts +110 -0
  411. package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.ts +67 -0
  412. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.ts +901 -0
  413. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.ts +141 -0
  414. package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.ts +871 -0
  415. package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +603 -0
  416. package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.ts +104 -0
  417. package/src/v2/providers/index.ts +21 -0
  418. package/src/v2/providers/keys.ts +25 -0
  419. package/src/v2/providers/license-context.ts +16 -0
  420. package/src/v2/providers/types.ts +40 -0
  421. package/src/v2/providers/useCopilotChatConfiguration.ts +11 -0
  422. package/src/v2/providers/useCopilotKit.ts +11 -0
  423. package/src/v2/providers/useLicenseContext.ts +21 -0
  424. package/src/v2/types/__tests__/defineToolCallRenderer.test.ts +157 -0
  425. package/src/v2/types/a2ui.ts +5 -0
  426. package/src/v2/types/defineToolCallRenderer.ts +32 -0
  427. package/src/v2/types/frontend-tool.ts +8 -0
  428. package/src/v2/types/human-in-the-loop.ts +38 -0
  429. package/src/v2/types/index.ts +9 -0
  430. package/src/v2/types/interrupt.ts +15 -0
  431. package/src/v2/types/sandbox-function.ts +8 -0
  432. package/src/v2/types/vue-activity-message-renderer.ts +22 -0
  433. package/src/v2/types/vue-custom-message-renderer.ts +24 -0
  434. package/src/v2/types/vue-tool-call-renderer.ts +44 -0
  435. package/tsconfig.json +27 -0
  436. package/vite.config.ts +49 -0
  437. package/vitest.config.ts +23 -0
@@ -0,0 +1,1271 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ computed,
4
+ getCurrentInstance,
5
+ nextTick,
6
+ onBeforeUnmount,
7
+ onMounted,
8
+ ref,
9
+ useAttrs,
10
+ watch,
11
+ } from "vue";
12
+ import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
13
+ import { CopilotChatDefaultLabels } from "../../providers/types";
14
+ import {
15
+ IconArrowUp,
16
+ IconCheck,
17
+ IconChevronRight,
18
+ IconLoader2,
19
+ IconMic,
20
+ IconPlus,
21
+ IconSquare,
22
+ IconX,
23
+ } from "../icons";
24
+ import CopilotChatAudioRecorder from "./CopilotChatAudioRecorder.vue";
25
+ import type { CopilotChatAudioRecorderRef } from "./audioRecorder";
26
+ import type { CopilotChatInputMode, ToolsMenuItem } from "./types";
27
+
28
+ defineOptions({ inheritAttrs: false });
29
+
30
+ type MenuEntry = ToolsMenuItem | "-";
31
+ type MenuDisplayEntry =
32
+ | { type: "separator"; key: string }
33
+ | { type: "label"; key: string; label: string; depth: number }
34
+ | {
35
+ type: "item";
36
+ key: string;
37
+ label: string;
38
+ depth: number;
39
+ action: () => void;
40
+ };
41
+
42
+ const props = withDefaults(
43
+ defineProps<{
44
+ modelValue?: string;
45
+ disabled?: boolean;
46
+ placeholder?: string;
47
+ autoFocus?: boolean;
48
+ clearOnSubmit?: boolean;
49
+ mode?: CopilotChatInputMode;
50
+ toolsMenu?: MenuEntry[];
51
+ isRunning?: boolean;
52
+ positioning?: "static" | "absolute";
53
+ keyboardHeight?: number;
54
+ showDisclaimer?: boolean;
55
+ maxRows?: number;
56
+ /**
57
+ * Set to `true` when the input sits at the bottom of its container as a
58
+ * flex-last-child (visible position is driven by layout, not CSS
59
+ * positioning). Triggers reservation of bottom space for the fixed
60
+ * CopilotKit license banner via the
61
+ * `--copilotkit-license-banner-offset` CSS var so the two don't overlap.
62
+ *
63
+ * Not needed when `positioning === "absolute"`; that mode already pins
64
+ * the input to the bottom and picks up the same reservation
65
+ * automatically. Leave unset (default `false`) for inputs rendered
66
+ * mid-layout such as the welcome screen, where the banner offset would
67
+ * push the input off-center.
68
+ */
69
+ bottomAnchored?: boolean;
70
+ }>(),
71
+ {
72
+ disabled: false,
73
+ autoFocus: true,
74
+ clearOnSubmit: true,
75
+ mode: "input",
76
+ toolsMenu: () => [],
77
+ isRunning: false,
78
+ positioning: "static",
79
+ keyboardHeight: 0,
80
+ showDisclaimer: undefined,
81
+ maxRows: 5,
82
+ bottomAnchored: false,
83
+ },
84
+ );
85
+
86
+ const emit = defineEmits<{
87
+ "update:modelValue": [value: string];
88
+ "submit-message": [value: string];
89
+ stop: [];
90
+ "add-file": [];
91
+ "start-transcribe": [];
92
+ "cancel-transcribe": [];
93
+ "finish-transcribe": [];
94
+ "finish-transcribe-with-audio": [audioBlob: Blob];
95
+ }>();
96
+
97
+ const attrs = useAttrs();
98
+ const config = useCopilotChatConfiguration();
99
+ const instance = getCurrentInstance();
100
+ const shellRef = ref<HTMLElement | null>(null);
101
+ const textareaRef = ref<HTMLTextAreaElement | null>(null);
102
+ const gridRef = ref<HTMLElement | null>(null);
103
+ const addButtonContainerRef = ref<HTMLElement | null>(null);
104
+ const actionsContainerRef = ref<HTMLElement | null>(null);
105
+ const slashMenuRef = ref<HTMLElement | null>(null);
106
+ const addMenuRef = ref<HTMLElement | null>(null);
107
+ const audioRecorderRef = ref<CopilotChatAudioRecorderRef | null>(null);
108
+ const localValue = ref(props.modelValue ?? "");
109
+ const isComposing = ref(false);
110
+ const layout = ref<"compact" | "expanded">("compact");
111
+ const commandQuery = ref<string | null>(null);
112
+ const slashHighlightIndex = ref(0);
113
+ const previousCommandQuery = ref<string | null>(null);
114
+ const addMenuOpen = ref(false);
115
+ const measurements = ref({
116
+ singleLineHeight: 0,
117
+ maxHeight: 0,
118
+ paddingLeft: 0,
119
+ paddingRight: 0,
120
+ });
121
+ const resizeEvaluationRafRef = ref<number | null>(null);
122
+ const ignoreResizeRef = ref(false);
123
+ const measurementCanvasRef = ref<HTMLCanvasElement | null>(null);
124
+ const containerCacheRef = ref<{
125
+ compactWidth: number;
126
+ } | null>(null);
127
+ const didWarnMissingFontRef = ref(false);
128
+ const didWarnMissingCanvasContextRef = ref(false);
129
+ let resizeObserver: ResizeObserver | null = null;
130
+ let documentPointerDownHandler: ((event: MouseEvent) => void) | null = null;
131
+
132
+ const vnodeProps = computed(
133
+ () => (instance?.vnode.props ?? {}) as Record<string, unknown>,
134
+ );
135
+
136
+ const isControlled = computed(() => props.modelValue !== undefined);
137
+ const inputValue = computed(() =>
138
+ isControlled.value ? (props.modelValue ?? "") : localValue.value,
139
+ );
140
+ const labels = computed(() => config.value?.labels ?? CopilotChatDefaultLabels);
141
+ const resolvedPlaceholder = computed(
142
+ () => props.placeholder ?? labels.value.chatInputPlaceholder,
143
+ );
144
+ const isExpanded = computed(
145
+ () => props.mode === "input" && layout.value === "expanded",
146
+ );
147
+ const isProcessing = computed(
148
+ () => props.mode !== "transcribe" && props.isRunning,
149
+ );
150
+ const shouldShowDisclaimer = computed(
151
+ () => props.showDisclaimer ?? props.positioning === "absolute",
152
+ );
153
+ const hasSubmitAction = computed(() => hasListener("onSubmitMessage"));
154
+ const hasStopAction = computed(() => hasListener("onStop"));
155
+ const hasAddFileAction = computed(() => hasListener("onAddFile"));
156
+ const hasStartTranscribeAction = computed(() =>
157
+ hasListener("onStartTranscribe"),
158
+ );
159
+ const hasCancelTranscribeAction = computed(() =>
160
+ hasListener("onCancelTranscribe"),
161
+ );
162
+ const hasFinishTranscribeAction = computed(() =>
163
+ hasListener("onFinishTranscribe"),
164
+ );
165
+ const canSend = computed(
166
+ () =>
167
+ props.mode === "input" &&
168
+ !props.disabled &&
169
+ hasSubmitAction.value &&
170
+ inputValue.value.trim().length > 0,
171
+ );
172
+ const sendDisabled = computed(() =>
173
+ isProcessing.value ? !hasStopAction.value : !canSend.value,
174
+ );
175
+
176
+ const containerClass = computed(() => [
177
+ props.positioning === "absolute" &&
178
+ "cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none",
179
+ attrs.class,
180
+ ]);
181
+
182
+ const rootAttrs = computed(() => {
183
+ const rest = { ...attrs };
184
+ delete rest.class;
185
+ return rest;
186
+ });
187
+
188
+ function isMenuGroup(
189
+ item: ToolsMenuItem,
190
+ ): item is ToolsMenuItem & { items: MenuEntry[] } {
191
+ return Array.isArray((item as ToolsMenuItem).items);
192
+ }
193
+
194
+ function hasListener(listenerName: string) {
195
+ const listener = vnodeProps.value[listenerName];
196
+ if (Array.isArray(listener)) {
197
+ return listener.length > 0;
198
+ }
199
+ return !!listener;
200
+ }
201
+
202
+ function createDefaultAddItem(): ToolsMenuItem | null {
203
+ if (!hasAddFileAction.value) {
204
+ return null;
205
+ }
206
+ return {
207
+ label: labels.value.chatInputToolbarAddButtonLabel,
208
+ action: () => emit("add-file"),
209
+ };
210
+ }
211
+
212
+ function normalizeMenuItems() {
213
+ const items: MenuEntry[] = [];
214
+ const addItem = createDefaultAddItem();
215
+ if (addItem) {
216
+ items.push(addItem);
217
+ }
218
+
219
+ if (props.toolsMenu.length > 0) {
220
+ if (items.length > 0) {
221
+ items.push("-");
222
+ }
223
+
224
+ for (const menuEntry of props.toolsMenu) {
225
+ if (menuEntry === "-") {
226
+ if (items.length === 0 || items[items.length - 1] === "-") {
227
+ continue;
228
+ }
229
+ items.push("-");
230
+ continue;
231
+ }
232
+
233
+ items.push(menuEntry);
234
+ }
235
+ }
236
+
237
+ while (items.length > 0 && items[items.length - 1] === "-") {
238
+ items.pop();
239
+ }
240
+
241
+ return items;
242
+ }
243
+
244
+ const menuItems = computed(() => normalizeMenuItems());
245
+ const hasMenuItems = computed(() => menuItems.value.length > 0);
246
+
247
+ function flattenMenuForCommands(items: MenuEntry[]) {
248
+ const seen = new Set<string>();
249
+ const commands: ToolsMenuItem[] = [];
250
+
251
+ const walk = (entryList: MenuEntry[]) => {
252
+ for (const entry of entryList) {
253
+ if (entry === "-") {
254
+ continue;
255
+ }
256
+
257
+ if (isMenuGroup(entry) && entry.items.length > 0) {
258
+ walk(entry.items);
259
+ continue;
260
+ }
261
+
262
+ if (!entry.action || seen.has(entry.label)) {
263
+ continue;
264
+ }
265
+
266
+ seen.add(entry.label);
267
+ commands.push(entry);
268
+ }
269
+ };
270
+
271
+ walk(items);
272
+ return commands;
273
+ }
274
+
275
+ const commandItems = computed(() => flattenMenuForCommands(menuItems.value));
276
+
277
+ function flattenMenuDisplay(items: MenuEntry[], depth = 0, prefix = "root") {
278
+ const entries: MenuDisplayEntry[] = [];
279
+ for (const [index, item] of items.entries()) {
280
+ const key = `${prefix}-${index}`;
281
+ if (item === "-") {
282
+ entries.push({ type: "separator", key: `sep-${key}` });
283
+ continue;
284
+ }
285
+ if (isMenuGroup(item) && item.items.length > 0) {
286
+ entries.push({
287
+ type: "label",
288
+ key: `label-${key}`,
289
+ label: item.label,
290
+ depth,
291
+ });
292
+ entries.push(...flattenMenuDisplay(item.items, depth + 1, key));
293
+ continue;
294
+ }
295
+ if (item.action) {
296
+ entries.push({
297
+ type: "item",
298
+ key: `item-${key}`,
299
+ label: item.label,
300
+ depth,
301
+ action: item.action,
302
+ });
303
+ }
304
+ }
305
+ return entries;
306
+ }
307
+
308
+ const menuDisplayItems = computed(() => flattenMenuDisplay(menuItems.value));
309
+
310
+ const filteredCommands = computed(() => {
311
+ if (commandQuery.value === null || commandItems.value.length === 0) {
312
+ return [] as ToolsMenuItem[];
313
+ }
314
+
315
+ const normalized = commandQuery.value.trim().toLowerCase();
316
+ if (normalized.length === 0) {
317
+ return commandItems.value;
318
+ }
319
+
320
+ const startsWith: ToolsMenuItem[] = [];
321
+ const contains: ToolsMenuItem[] = [];
322
+
323
+ for (const command of commandItems.value) {
324
+ const label = command.label.toLowerCase();
325
+ if (label.startsWith(normalized)) {
326
+ startsWith.push(command);
327
+ continue;
328
+ }
329
+ if (label.includes(normalized)) {
330
+ contains.push(command);
331
+ }
332
+ }
333
+
334
+ return [...startsWith, ...contains];
335
+ });
336
+
337
+ const slashMenuVisible = computed(
338
+ () => commandQuery.value !== null && commandItems.value.length > 0,
339
+ );
340
+
341
+ function updateInputValue(nextValue: string) {
342
+ if (!isControlled.value) {
343
+ localValue.value = nextValue;
344
+ }
345
+ emit("update:modelValue", nextValue);
346
+ }
347
+
348
+ function clearInputValue() {
349
+ updateInputValue("");
350
+ }
351
+
352
+ function updateSlashState(value: string) {
353
+ if (commandItems.value.length === 0) {
354
+ commandQuery.value = null;
355
+ return;
356
+ }
357
+
358
+ if (value.startsWith("/")) {
359
+ const firstLine = value.split(/\r?\n/, 1)[0] ?? "";
360
+ commandQuery.value = firstLine.slice(1);
361
+ return;
362
+ }
363
+
364
+ commandQuery.value = null;
365
+ }
366
+
367
+ function runCommand(command: ToolsMenuItem) {
368
+ clearInputValue();
369
+ command.action?.();
370
+ commandQuery.value = null;
371
+ slashHighlightIndex.value = 0;
372
+ requestAnimationFrame(() => {
373
+ textareaRef.value?.focus();
374
+ });
375
+ }
376
+
377
+ function submit() {
378
+ if (props.mode !== "input" || props.disabled || !hasSubmitAction.value) {
379
+ return;
380
+ }
381
+ // In controlled mode, parent-updated modelValue can lag one tick behind
382
+ // the actual textarea value during intense runtime/connect churn.
383
+ const rawValue = textareaRef.value?.value ?? inputValue.value;
384
+ const trimmed = rawValue.trim();
385
+ if (!trimmed) {
386
+ return;
387
+ }
388
+
389
+ emit("submit-message", trimmed);
390
+
391
+ if (props.clearOnSubmit) {
392
+ clearInputValue();
393
+ }
394
+
395
+ textareaRef.value?.focus();
396
+ }
397
+
398
+ function handleInput(event: Event) {
399
+ const nextValue = (event.target as HTMLTextAreaElement).value;
400
+ updateInputValue(nextValue);
401
+ updateSlashState(nextValue);
402
+ }
403
+
404
+ function handleSendButtonClick() {
405
+ if (isProcessing.value) {
406
+ if (hasStopAction.value) {
407
+ emit("stop");
408
+ }
409
+ return;
410
+ }
411
+ submit();
412
+ }
413
+
414
+ function handleKeydown(event: KeyboardEvent) {
415
+ if (props.disabled) {
416
+ return;
417
+ }
418
+
419
+ if (isComposing.value || event.isComposing || event.keyCode === 229) {
420
+ return;
421
+ }
422
+
423
+ if (commandQuery.value !== null && props.mode === "input") {
424
+ if (event.key === "ArrowDown") {
425
+ if (filteredCommands.value.length > 0) {
426
+ event.preventDefault();
427
+ slashHighlightIndex.value =
428
+ slashHighlightIndex.value < 0
429
+ ? 0
430
+ : (slashHighlightIndex.value + 1) % filteredCommands.value.length;
431
+ }
432
+ return;
433
+ }
434
+
435
+ if (event.key === "ArrowUp") {
436
+ if (filteredCommands.value.length > 0) {
437
+ event.preventDefault();
438
+ if (slashHighlightIndex.value < 0) {
439
+ slashHighlightIndex.value = filteredCommands.value.length - 1;
440
+ } else {
441
+ slashHighlightIndex.value =
442
+ slashHighlightIndex.value <= 0
443
+ ? filteredCommands.value.length - 1
444
+ : slashHighlightIndex.value - 1;
445
+ }
446
+ }
447
+ return;
448
+ }
449
+
450
+ if (event.key === "Enter") {
451
+ const selected =
452
+ slashHighlightIndex.value >= 0
453
+ ? filteredCommands.value[slashHighlightIndex.value]
454
+ : undefined;
455
+ if (selected) {
456
+ event.preventDefault();
457
+ runCommand(selected);
458
+ return;
459
+ }
460
+ }
461
+
462
+ if (event.key === "Escape") {
463
+ event.preventDefault();
464
+ commandQuery.value = null;
465
+ return;
466
+ }
467
+ }
468
+
469
+ if (event.key === "Enter" && !event.shiftKey && props.mode === "input") {
470
+ event.preventDefault();
471
+ if (isProcessing.value) {
472
+ if (hasStopAction.value) {
473
+ emit("stop");
474
+ }
475
+ return;
476
+ }
477
+ submit();
478
+ }
479
+ }
480
+
481
+ function toggleAddMenu() {
482
+ if (!hasMenuItems.value || props.mode === "transcribe" || props.disabled) {
483
+ return;
484
+ }
485
+ addMenuOpen.value = !addMenuOpen.value;
486
+ }
487
+
488
+ function closeAddMenu() {
489
+ addMenuOpen.value = false;
490
+ }
491
+
492
+ function handleMenuAction(action: () => void) {
493
+ action();
494
+ closeAddMenu();
495
+ nextTick(() => {
496
+ textareaRef.value?.focus();
497
+ });
498
+ }
499
+
500
+ async function handleFinishTranscribe() {
501
+ const recorder = audioRecorderRef.value;
502
+ if (recorder && recorder.state === "recording") {
503
+ try {
504
+ const blob = await recorder.stop();
505
+ emit("finish-transcribe-with-audio", blob);
506
+ } catch (error) {
507
+ console.error("Failed to stop recording:", error);
508
+ }
509
+ }
510
+ emit("finish-transcribe");
511
+ }
512
+
513
+ function handleContainerClick(event: MouseEvent) {
514
+ const target = event.target as HTMLElement | null;
515
+ if (!target || props.mode !== "input") {
516
+ return;
517
+ }
518
+ if (target.tagName === "BUTTON" || target.closest("button")) {
519
+ return;
520
+ }
521
+ textareaRef.value?.focus();
522
+ }
523
+
524
+ function ensureMeasurements() {
525
+ const textarea = textareaRef.value;
526
+ if (!textarea || isComposing.value) {
527
+ return;
528
+ }
529
+
530
+ const previousValue = textarea.value;
531
+ const previousHeight = textarea.style.height;
532
+ textarea.style.height = "auto";
533
+
534
+ const computedStyle = window.getComputedStyle(textarea);
535
+ const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
536
+ const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
537
+ const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
538
+ const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0;
539
+
540
+ textarea.value = "";
541
+ const singleLineHeight = textarea.scrollHeight;
542
+ textarea.value = previousValue;
543
+
544
+ const contentHeight = singleLineHeight - paddingTop - paddingBottom;
545
+ const maxHeight = contentHeight * props.maxRows + paddingTop + paddingBottom;
546
+
547
+ measurements.value = {
548
+ singleLineHeight,
549
+ maxHeight,
550
+ paddingLeft,
551
+ paddingRight,
552
+ };
553
+
554
+ textarea.style.height = previousHeight;
555
+ textarea.style.maxHeight = `${maxHeight}px`;
556
+ }
557
+
558
+ function adjustTextareaHeight() {
559
+ const textarea = textareaRef.value;
560
+ if (!textarea) {
561
+ return 0;
562
+ }
563
+
564
+ if (measurements.value.singleLineHeight === 0) {
565
+ ensureMeasurements();
566
+ }
567
+
568
+ const { maxHeight } = measurements.value;
569
+ if (maxHeight) {
570
+ textarea.style.maxHeight = `${maxHeight}px`;
571
+ }
572
+
573
+ textarea.style.height = "auto";
574
+ const scrollHeight = textarea.scrollHeight;
575
+ textarea.style.height = `${maxHeight ? Math.min(scrollHeight, maxHeight) : scrollHeight}px`;
576
+ return scrollHeight;
577
+ }
578
+
579
+ function updateLayout(nextLayout: "compact" | "expanded") {
580
+ if (layout.value === nextLayout) {
581
+ return;
582
+ }
583
+ ignoreResizeRef.value = true;
584
+ layout.value = nextLayout;
585
+ }
586
+
587
+ function resolveTextareaFont(textarea: HTMLTextAreaElement): string | null {
588
+ const textareaStyles = window.getComputedStyle(textarea);
589
+ if (textareaStyles.font?.trim()) {
590
+ return textareaStyles.font;
591
+ }
592
+
593
+ if (textareaStyles.fontSize && textareaStyles.fontFamily) {
594
+ const fallbackFont =
595
+ `${textareaStyles.fontStyle} ${textareaStyles.fontVariant} ` +
596
+ `${textareaStyles.fontWeight} ${textareaStyles.fontSize}/${textareaStyles.lineHeight} ` +
597
+ `${textareaStyles.fontFamily}`;
598
+ if (fallbackFont.trim()) {
599
+ return fallbackFont;
600
+ }
601
+ }
602
+
603
+ if (process.env.NODE_ENV !== "production" && !didWarnMissingFontRef.value) {
604
+ didWarnMissingFontRef.value = true;
605
+ console.warn(
606
+ "[CopilotChatInput] Could not resolve textarea font for layout measurement. " +
607
+ "Text-width-based expansion will be skipped until the next container resize.",
608
+ );
609
+ }
610
+ return null;
611
+ }
612
+
613
+ function updateContainerCache() {
614
+ const grid = gridRef.value;
615
+ const addContainer = addButtonContainerRef.value;
616
+ const actionsContainer = actionsContainerRef.value;
617
+ if (!grid || !addContainer || !actionsContainer) {
618
+ containerCacheRef.value = null;
619
+ return null;
620
+ }
621
+
622
+ const gridStyles = window.getComputedStyle(grid);
623
+ const paddingLeft = parseFloat(gridStyles.paddingLeft) || 0;
624
+ const paddingRight = parseFloat(gridStyles.paddingRight) || 0;
625
+ const columnGap = parseFloat(gridStyles.columnGap) || 0;
626
+ const gridAvailableWidth = grid.clientWidth - paddingLeft - paddingRight;
627
+ if (gridAvailableWidth <= 0) {
628
+ containerCacheRef.value = null;
629
+ return null;
630
+ }
631
+
632
+ const addWidth = addContainer.getBoundingClientRect().width;
633
+ const actionsWidth = actionsContainer.getBoundingClientRect().width;
634
+ const compactWidth = Math.max(
635
+ gridAvailableWidth - addWidth - actionsWidth - columnGap * 2,
636
+ 0,
637
+ );
638
+ if (compactWidth <= 0) {
639
+ containerCacheRef.value = null;
640
+ return null;
641
+ }
642
+
643
+ const cache = { compactWidth };
644
+ containerCacheRef.value = cache;
645
+ return cache;
646
+ }
647
+
648
+ function evaluateLayout() {
649
+ if (props.mode !== "input") {
650
+ updateLayout("compact");
651
+ return;
652
+ }
653
+
654
+ if (
655
+ typeof window.matchMedia === "function" &&
656
+ window.matchMedia("(max-width: 767px)").matches
657
+ ) {
658
+ ensureMeasurements();
659
+ adjustTextareaHeight();
660
+ updateLayout("expanded");
661
+ return;
662
+ }
663
+
664
+ const textarea = textareaRef.value;
665
+ if (
666
+ !textarea ||
667
+ !gridRef.value ||
668
+ !addButtonContainerRef.value ||
669
+ !actionsContainerRef.value
670
+ ) {
671
+ return;
672
+ }
673
+
674
+ if (measurements.value.singleLineHeight === 0) {
675
+ ensureMeasurements();
676
+ }
677
+
678
+ const scrollHeight = adjustTextareaHeight();
679
+ const baseline = measurements.value.singleLineHeight;
680
+ const hasExplicitBreak = inputValue.value.includes("\n");
681
+ const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
682
+ let shouldExpand = hasExplicitBreak || renderedMultiline;
683
+
684
+ if (!shouldExpand) {
685
+ const cache = containerCacheRef.value ?? updateContainerCache();
686
+ if (cache && cache.compactWidth > 0) {
687
+ const compactInnerWidth = Math.max(
688
+ cache.compactWidth -
689
+ measurements.value.paddingLeft -
690
+ measurements.value.paddingRight,
691
+ 0,
692
+ );
693
+
694
+ if (compactInnerWidth > 0) {
695
+ const canvas =
696
+ measurementCanvasRef.value ?? document.createElement("canvas");
697
+ if (!measurementCanvasRef.value) {
698
+ measurementCanvasRef.value = canvas;
699
+ }
700
+
701
+ const context = canvas.getContext("2d");
702
+ if (context) {
703
+ const resolvedFont = resolveTextareaFont(textarea);
704
+ if (resolvedFont) {
705
+ context.font = resolvedFont;
706
+ const lines =
707
+ inputValue.value.length > 0 ? inputValue.value.split("\n") : [""];
708
+ let longestLine = 0;
709
+ for (const line of lines) {
710
+ const width = context.measureText(line || " ").width;
711
+ if (width > longestLine) {
712
+ longestLine = width;
713
+ }
714
+ }
715
+ if (longestLine > compactInnerWidth) {
716
+ shouldExpand = true;
717
+ }
718
+ }
719
+ } else if (
720
+ process.env.NODE_ENV !== "production" &&
721
+ !didWarnMissingCanvasContextRef.value
722
+ ) {
723
+ didWarnMissingCanvasContextRef.value = true;
724
+ console.warn(
725
+ "[CopilotChatInput] canvas.getContext('2d') returned null. " +
726
+ "Text-width-based expansion will be skipped.",
727
+ );
728
+ }
729
+ }
730
+ }
731
+ }
732
+
733
+ updateLayout(shouldExpand ? "expanded" : "compact");
734
+ }
735
+
736
+ function scheduleLayoutEvaluation(invalidateCache: boolean) {
737
+ if (ignoreResizeRef.value) {
738
+ ignoreResizeRef.value = false;
739
+ return;
740
+ }
741
+
742
+ if (invalidateCache) {
743
+ containerCacheRef.value = null;
744
+ didWarnMissingFontRef.value = false;
745
+ didWarnMissingCanvasContextRef.value = false;
746
+ }
747
+
748
+ if (resizeEvaluationRafRef.value !== null) {
749
+ cancelAnimationFrame(resizeEvaluationRafRef.value);
750
+ }
751
+
752
+ resizeEvaluationRafRef.value = requestAnimationFrame(() => {
753
+ resizeEvaluationRafRef.value = null;
754
+ evaluateLayout();
755
+ });
756
+ }
757
+
758
+ watch(
759
+ () => props.modelValue,
760
+ (next) => {
761
+ if (isControlled.value) {
762
+ localValue.value = next ?? "";
763
+ }
764
+ },
765
+ );
766
+
767
+ watch(inputValue, (value) => {
768
+ updateSlashState(value);
769
+ evaluateLayout();
770
+ });
771
+
772
+ watch(commandItems, () => {
773
+ if (commandItems.value.length === 0) {
774
+ commandQuery.value = null;
775
+ }
776
+ });
777
+
778
+ watch(
779
+ [commandQuery, () => filteredCommands.value.length],
780
+ ([query, filteredCount]) => {
781
+ if (
782
+ query !== null &&
783
+ query !== previousCommandQuery.value &&
784
+ filteredCount > 0
785
+ ) {
786
+ slashHighlightIndex.value = 0;
787
+ }
788
+
789
+ previousCommandQuery.value = query;
790
+ },
791
+ { immediate: true },
792
+ );
793
+
794
+ watch(
795
+ [commandQuery, filteredCommands],
796
+ () => {
797
+ if (commandQuery.value === null) {
798
+ slashHighlightIndex.value = 0;
799
+ return;
800
+ }
801
+ if (filteredCommands.value.length === 0) {
802
+ slashHighlightIndex.value = -1;
803
+ return;
804
+ }
805
+ if (
806
+ slashHighlightIndex.value < 0 ||
807
+ slashHighlightIndex.value >= filteredCommands.value.length
808
+ ) {
809
+ slashHighlightIndex.value = 0;
810
+ }
811
+ },
812
+ { immediate: true },
813
+ );
814
+
815
+ watch(
816
+ () => props.mode,
817
+ async (mode) => {
818
+ if (mode !== "input") {
819
+ layout.value = "compact";
820
+ commandQuery.value = null;
821
+ closeAddMenu();
822
+ }
823
+
824
+ const recorder = audioRecorderRef.value;
825
+ if (!recorder) {
826
+ return;
827
+ }
828
+
829
+ if (mode === "transcribe") {
830
+ try {
831
+ await recorder.start();
832
+ } catch (error) {
833
+ console.error(error);
834
+ }
835
+ return;
836
+ }
837
+
838
+ if (recorder.state === "recording") {
839
+ try {
840
+ await recorder.stop();
841
+ } catch {
842
+ // ignore transition stop failures
843
+ }
844
+ }
845
+ },
846
+ { immediate: true },
847
+ );
848
+
849
+ watch(
850
+ audioRecorderRef,
851
+ async (recorder) => {
852
+ if (!recorder || props.mode !== "transcribe") {
853
+ return;
854
+ }
855
+ if (recorder.state === "idle") {
856
+ try {
857
+ await recorder.start();
858
+ } catch (error) {
859
+ console.error(error);
860
+ }
861
+ }
862
+ },
863
+ { immediate: true },
864
+ );
865
+
866
+ watch(slashHighlightIndex, async (index) => {
867
+ if (!slashMenuVisible.value || index < 0) {
868
+ return;
869
+ }
870
+ await nextTick();
871
+ const active = slashMenuRef.value?.querySelector<HTMLElement>(
872
+ `[data-slash-index="${index}"]`,
873
+ );
874
+ active?.scrollIntoView?.({ block: "nearest" });
875
+ });
876
+
877
+ watch(
878
+ () => props.disabled,
879
+ (disabled) => {
880
+ if (disabled) {
881
+ closeAddMenu();
882
+ }
883
+ },
884
+ );
885
+
886
+ onMounted(() => {
887
+ if (props.autoFocus && props.mode === "input") {
888
+ textareaRef.value?.focus();
889
+ }
890
+
891
+ evaluateLayout();
892
+
893
+ if (typeof ResizeObserver !== "undefined") {
894
+ const containerTargets = new Set<HTMLElement>();
895
+ if (gridRef.value) containerTargets.add(gridRef.value);
896
+ if (addButtonContainerRef.value)
897
+ containerTargets.add(addButtonContainerRef.value);
898
+ if (actionsContainerRef.value)
899
+ containerTargets.add(actionsContainerRef.value);
900
+
901
+ resizeObserver = new ResizeObserver((entries) => {
902
+ const shouldInvalidate = entries.some((entry) =>
903
+ containerTargets.has(entry.target as HTMLElement),
904
+ );
905
+ scheduleLayoutEvaluation(shouldInvalidate);
906
+ });
907
+
908
+ if (gridRef.value) resizeObserver.observe(gridRef.value);
909
+ if (addButtonContainerRef.value)
910
+ resizeObserver.observe(addButtonContainerRef.value);
911
+ if (actionsContainerRef.value)
912
+ resizeObserver.observe(actionsContainerRef.value);
913
+ if (textareaRef.value) resizeObserver.observe(textareaRef.value);
914
+ }
915
+
916
+ documentPointerDownHandler = (event: MouseEvent) => {
917
+ if (!addMenuOpen.value) {
918
+ return;
919
+ }
920
+ const target = event.target as Node | null;
921
+ if (!target) {
922
+ return;
923
+ }
924
+ if (
925
+ addMenuRef.value?.contains(target) ||
926
+ addButtonContainerRef.value?.contains(target)
927
+ ) {
928
+ return;
929
+ }
930
+ closeAddMenu();
931
+ };
932
+
933
+ document.addEventListener("mousedown", documentPointerDownHandler);
934
+ });
935
+
936
+ onBeforeUnmount(() => {
937
+ if (documentPointerDownHandler) {
938
+ document.removeEventListener("mousedown", documentPointerDownHandler);
939
+ documentPointerDownHandler = null;
940
+ }
941
+ resizeObserver?.disconnect();
942
+ resizeObserver = null;
943
+ if (resizeEvaluationRafRef.value !== null) {
944
+ cancelAnimationFrame(resizeEvaluationRafRef.value);
945
+ resizeEvaluationRafRef.value = null;
946
+ }
947
+ });
948
+ </script>
949
+
950
+ <template>
951
+ <div
952
+ data-copilotkit
953
+ data-testid="copilot-chat-input-container"
954
+ :class="containerClass"
955
+ :style="{
956
+ transform:
957
+ keyboardHeight > 0 ? `translateY(-${keyboardHeight}px)` : undefined,
958
+ transition: 'transform 0.2s ease-out',
959
+ ...(positioning === 'absolute' || bottomAnchored
960
+ ? { paddingBottom: 'var(--copilotkit-license-banner-offset, 0px)' }
961
+ : {}),
962
+ }"
963
+ v-bind="rootAttrs"
964
+ >
965
+ <div
966
+ class="cpk:pointer-events-auto cpk:mx-auto cpk:max-w-3xl cpk:px-4 cpk:py-0 cpk:sm:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-4"
967
+ >
968
+ <slot
969
+ name="layout"
970
+ :mode="mode"
971
+ :is-multiline="isExpanded"
972
+ :value="inputValue"
973
+ :disabled="disabled"
974
+ :placeholder="resolvedPlaceholder"
975
+ :is-processing="isProcessing"
976
+ :send-disabled="sendDisabled"
977
+ :menu-open="addMenuOpen"
978
+ :menu-items="menuDisplayItems"
979
+ :on-toggle-menu="toggleAddMenu"
980
+ :on-menu-action="handleMenuAction"
981
+ :on-update-value="updateInputValue"
982
+ :on-submit="submit"
983
+ :on-keydown="handleKeydown"
984
+ :on-send-click="handleSendButtonClick"
985
+ :on-start-transcribe="() => emit('start-transcribe')"
986
+ :on-cancel-transcribe="() => emit('cancel-transcribe')"
987
+ :on-finish-transcribe="handleFinishTranscribe"
988
+ >
989
+ <div
990
+ ref="shellRef"
991
+ data-testid="copilot-chat-input-shell"
992
+ class="cpk:flex cpk:w-full cpk:cursor-text cpk:flex-col cpk:items-center cpk:justify-center cpk:overflow-visible cpk:rounded-[28px] cpk:bg-white cpk:bg-clip-padding cpk:shadow-[0_4px_4px_0_#0000000a,0_0_1px_0_#0000009e] cpk:contain-inline-size cpk:dark:bg-[#303030]"
993
+ :data-layout="isExpanded ? 'expanded' : 'compact'"
994
+ @click="handleContainerClick"
995
+ >
996
+ <div
997
+ ref="gridRef"
998
+ :class="[
999
+ 'cpk:grid cpk:w-full cpk:gap-x-3 cpk:gap-y-3 cpk:px-3 cpk:py-2',
1000
+ isExpanded
1001
+ ? 'cpk:grid-cols-[auto_minmax(0,1fr)_auto] cpk:grid-rows-[auto_auto]'
1002
+ : 'cpk:grid-cols-[auto_minmax(0,1fr)_auto] cpk:items-center',
1003
+ ]"
1004
+ :data-layout="isExpanded ? 'expanded' : 'compact'"
1005
+ >
1006
+ <div
1007
+ ref="addButtonContainerRef"
1008
+ :class="[
1009
+ 'cpk:relative cpk:flex cpk:items-center cpk:col-start-1',
1010
+ isExpanded ? 'cpk:row-start-2' : 'cpk:row-start-1',
1011
+ ]"
1012
+ >
1013
+ <slot
1014
+ name="add-menu-button"
1015
+ :disabled="disabled || mode === 'transcribe' || !hasMenuItems"
1016
+ :menu-open="addMenuOpen"
1017
+ :toggle-menu="toggleAddMenu"
1018
+ :labels="labels"
1019
+ >
1020
+ <button
1021
+ type="button"
1022
+ data-testid="copilot-chat-input-add"
1023
+ :aria-label="labels.chatInputToolbarAddButtonLabel"
1024
+ :disabled="disabled || mode === 'transcribe' || !hasMenuItems"
1025
+ class="cpk:ml-1 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:hover:bg-transparent cpk:disabled:hover:text-[#444444] cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF] cpk:dark:disabled:hover:bg-transparent cpk:dark:disabled:hover:text-[#CCCCCC]"
1026
+ @click.stop="toggleAddMenu"
1027
+ >
1028
+ <IconPlus class="cpk:size-[20px]" />
1029
+ </button>
1030
+ </slot>
1031
+
1032
+ <div
1033
+ v-if="addMenuOpen && hasMenuItems"
1034
+ ref="addMenuRef"
1035
+ class="cpk:absolute cpk:bottom-full cpk:left-0 cpk:z-30 cpk:mb-2 cpk:min-w-[220px] cpk:overflow-hidden cpk:rounded-lg cpk:border cpk:border-border cpk:bg-white cpk:shadow-lg cpk:dark:border-[#3a3a3a] cpk:dark:bg-[#1f1f1f]"
1036
+ data-testid="copilot-chat-input-add-menu"
1037
+ >
1038
+ <template v-for="entry in menuDisplayItems" :key="entry.key">
1039
+ <div
1040
+ v-if="entry.type === 'separator'"
1041
+ class="cpk:my-1 cpk:h-px cpk:bg-border cpk:dark:bg-[#333333]"
1042
+ />
1043
+ <div
1044
+ v-else-if="entry.type === 'label'"
1045
+ class="cpk:flex cpk:items-center cpk:gap-1 cpk:px-3 cpk:py-1.5 cpk:text-xs cpk:font-semibold cpk:text-muted-foreground"
1046
+ :style="{ paddingLeft: `${12 + entry.depth * 12}px` }"
1047
+ >
1048
+ <span>{{ entry.label }}</span>
1049
+ <IconChevronRight class="cpk:size-3" />
1050
+ </div>
1051
+ <button
1052
+ v-else
1053
+ type="button"
1054
+ role="menuitem"
1055
+ class="cpk:w-full cpk:px-3 cpk:py-2 cpk:text-left cpk:text-sm cpk:transition-colors cpk:hover:bg-muted cpk:dark:hover:bg-[#2f2f2f]"
1056
+ :style="{ paddingLeft: `${12 + entry.depth * 12}px` }"
1057
+ @click="handleMenuAction(entry.action)"
1058
+ >
1059
+ {{ entry.label }}
1060
+ </button>
1061
+ </template>
1062
+ </div>
1063
+ </div>
1064
+
1065
+ <div
1066
+ :class="[
1067
+ 'cpk:relative cpk:flex cpk:min-h-[50px] cpk:min-w-0 cpk:flex-col cpk:justify-center',
1068
+ isExpanded
1069
+ ? 'cpk:col-span-3 cpk:row-start-1'
1070
+ : 'cpk:col-start-2 cpk:row-start-1',
1071
+ ]"
1072
+ >
1073
+ <template v-if="mode === 'transcribe'">
1074
+ <slot name="audio-recorder">
1075
+ <CopilotChatAudioRecorder ref="audioRecorderRef" />
1076
+ </slot>
1077
+ </template>
1078
+ <template v-else-if="mode === 'processing'">
1079
+ <div
1080
+ class="cpk:flex cpk:w-full cpk:items-center cpk:justify-center cpk:px-5 cpk:py-3"
1081
+ >
1082
+ <IconLoader2
1083
+ class="cpk:size-[26px] cpk:animate-spin cpk:text-muted-foreground"
1084
+ />
1085
+ </div>
1086
+ </template>
1087
+ <template v-else>
1088
+ <slot
1089
+ name="text-area"
1090
+ :value="inputValue"
1091
+ :disabled="disabled"
1092
+ :placeholder="resolvedPlaceholder"
1093
+ :on-input="handleInput"
1094
+ :on-keydown="handleKeydown"
1095
+ :auto-focus="autoFocus"
1096
+ :is-expanded="isExpanded"
1097
+ :rows="1"
1098
+ :labels="labels"
1099
+ >
1100
+ <textarea
1101
+ ref="textareaRef"
1102
+ data-testid="copilot-chat-input-textarea"
1103
+ :value="inputValue"
1104
+ :placeholder="resolvedPlaceholder"
1105
+ :disabled="disabled"
1106
+ rows="1"
1107
+ :class="[
1108
+ 'cpk:w-full cpk:bg-transparent cpk:py-3 cpk:text-[16px] cpk:font-normal cpk:leading-relaxed cpk:text-foreground cpk:antialiased cpk:outline-none cpk:placeholder:text-[#00000077] cpk:dark:placeholder:text-[#fffc]',
1109
+ isExpanded ? 'cpk:px-5' : 'cpk:pr-5',
1110
+ ]"
1111
+ style="overflow: auto; resize: none"
1112
+ @input="handleInput"
1113
+ @keydown="handleKeydown"
1114
+ @compositionstart="isComposing = true"
1115
+ @compositionend="isComposing = false"
1116
+ />
1117
+ </slot>
1118
+
1119
+ <div
1120
+ v-if="slashMenuVisible"
1121
+ ref="slashMenuRef"
1122
+ data-testid="copilot-slash-menu"
1123
+ role="listbox"
1124
+ aria-label="Slash commands"
1125
+ class="cpk:absolute cpk:bottom-full cpk:left-0 cpk:right-0 cpk:z-30 cpk:mb-2 cpk:max-h-64 cpk:overflow-y-auto cpk:rounded-lg cpk:border cpk:border-border cpk:bg-white cpk:shadow-lg cpk:dark:border-[#3a3a3a] cpk:dark:bg-[#1f1f1f]"
1126
+ :style="{ maxHeight: `${5 * 40}px` }"
1127
+ >
1128
+ <div
1129
+ v-if="filteredCommands.length === 0"
1130
+ class="cpk:px-3 cpk:py-2 cpk:text-sm cpk:text-muted-foreground"
1131
+ >
1132
+ No commands found
1133
+ </div>
1134
+ <button
1135
+ v-for="(command, index) in filteredCommands"
1136
+ v-else
1137
+ :key="`${command.label}-${index}`"
1138
+ type="button"
1139
+ role="option"
1140
+ :data-slash-index="index"
1141
+ :aria-selected="index === slashHighlightIndex"
1142
+ :data-active="
1143
+ index === slashHighlightIndex ? 'true' : undefined
1144
+ "
1145
+ :class="[
1146
+ 'cpk:w-full cpk:px-3 cpk:py-2 cpk:text-left cpk:text-sm cpk:transition-colors cpk:hover:bg-muted cpk:dark:hover:bg-[#2f2f2f]',
1147
+ index === slashHighlightIndex
1148
+ ? 'cpk:bg-muted cpk:dark:bg-[#2f2f2f]'
1149
+ : 'cpk:bg-transparent',
1150
+ ]"
1151
+ @mouseenter="slashHighlightIndex = index"
1152
+ @mousedown.prevent="runCommand(command)"
1153
+ >
1154
+ {{ command.label }}
1155
+ </button>
1156
+ </div>
1157
+ </template>
1158
+ </div>
1159
+
1160
+ <div
1161
+ ref="actionsContainerRef"
1162
+ :class="[
1163
+ 'cpk:flex cpk:items-center cpk:justify-end cpk:gap-2',
1164
+ isExpanded
1165
+ ? 'cpk:col-start-3 cpk:row-start-2'
1166
+ : 'cpk:col-start-3 cpk:row-start-1',
1167
+ ]"
1168
+ >
1169
+ <template v-if="mode === 'transcribe'">
1170
+ <slot
1171
+ v-if="hasCancelTranscribeAction"
1172
+ name="cancel-transcribe-button"
1173
+ :disabled="disabled"
1174
+ :on-click="() => emit('cancel-transcribe')"
1175
+ :labels="labels"
1176
+ >
1177
+ <button
1178
+ type="button"
1179
+ data-testid="copilot-chat-input-cancel-transcribe"
1180
+ :aria-label="
1181
+ labels.chatInputToolbarCancelTranscribeButtonLabel
1182
+ "
1183
+ :disabled="disabled"
1184
+ class="cpk:mr-2 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF]"
1185
+ @click="emit('cancel-transcribe')"
1186
+ >
1187
+ <IconX class="cpk:size-[18px]" />
1188
+ </button>
1189
+ </slot>
1190
+ <slot
1191
+ v-if="hasFinishTranscribeAction"
1192
+ name="finish-transcribe-button"
1193
+ :disabled="disabled"
1194
+ :on-click="handleFinishTranscribe"
1195
+ :labels="labels"
1196
+ >
1197
+ <button
1198
+ type="button"
1199
+ data-testid="copilot-chat-input-finish-transcribe"
1200
+ :aria-label="
1201
+ labels.chatInputToolbarFinishTranscribeButtonLabel
1202
+ "
1203
+ :disabled="disabled"
1204
+ class="cpk:mr-[10px] cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF]"
1205
+ @click="handleFinishTranscribe"
1206
+ >
1207
+ <IconCheck class="cpk:size-[18px]" />
1208
+ </button>
1209
+ </slot>
1210
+ </template>
1211
+ <template v-else>
1212
+ <slot
1213
+ v-if="hasStartTranscribeAction"
1214
+ name="start-transcribe-button"
1215
+ :disabled="disabled"
1216
+ :on-click="() => emit('start-transcribe')"
1217
+ :labels="labels"
1218
+ >
1219
+ <button
1220
+ type="button"
1221
+ data-testid="copilot-chat-input-start-transcribe"
1222
+ :aria-label="
1223
+ labels.chatInputToolbarStartTranscribeButtonLabel
1224
+ "
1225
+ :disabled="disabled"
1226
+ class="cpk:mr-2 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:hover:bg-transparent cpk:disabled:hover:text-[#444444] cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF] cpk:dark:disabled:hover:bg-transparent cpk:dark:disabled:hover:text-[#CCCCCC]"
1227
+ @click="emit('start-transcribe')"
1228
+ >
1229
+ <IconMic class="cpk:size-[18px]" />
1230
+ </button>
1231
+ </slot>
1232
+ <slot
1233
+ name="send-button"
1234
+ :disabled="sendDisabled"
1235
+ :is-processing="isProcessing"
1236
+ :on-click="handleSendButtonClick"
1237
+ >
1238
+ <div class="cpk:mr-[10px]">
1239
+ <button
1240
+ type="button"
1241
+ data-testid="copilot-chat-input-send"
1242
+ aria-label="Send message"
1243
+ :disabled="sendDisabled"
1244
+ class="cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-black cpk:text-white cpk:transition-colors cpk:hover:opacity-70 cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:bg-[#00000014] cpk:disabled:text-[rgb(13,13,13)] cpk:disabled:hover:opacity-100 cpk:dark:bg-white cpk:dark:text-black cpk:dark:disabled:bg-[#454545] cpk:dark:disabled:text-white"
1245
+ @click="handleSendButtonClick"
1246
+ >
1247
+ <IconSquare
1248
+ v-if="isProcessing && hasStopAction"
1249
+ class="cpk:size-[18px] cpk:fill-current"
1250
+ />
1251
+ <IconArrowUp v-else class="cpk:size-[18px]" />
1252
+ </button>
1253
+ </div>
1254
+ </slot>
1255
+ </template>
1256
+ </div>
1257
+ </div>
1258
+ </div>
1259
+ </slot>
1260
+ </div>
1261
+
1262
+ <slot v-if="shouldShowDisclaimer" name="disclaimer" :labels="labels">
1263
+ <p
1264
+ data-testid="copilot-chat-input-disclaimer"
1265
+ class="cpk:mx-auto cpk:max-w-3xl cpk:px-4 cpk:py-3 cpk:text-center cpk:text-xs cpk:text-muted-foreground"
1266
+ >
1267
+ {{ labels.chatDisclaimerText }}
1268
+ </p>
1269
+ </slot>
1270
+ </div>
1271
+ </template>