@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.
- package/PARITY.md +3 -3
- package/dist/hooks/use-copilot-action.d.ts.map +1 -1
- package/dist/hooks/use-frontend-tool.d.ts +1 -1
- package/dist/hooks/use-frontend-tool.d.ts.map +1 -1
- package/dist/hooks/zod-parameters.d.ts +14 -0
- package/dist/hooks/zod-parameters.d.ts.map +1 -0
- package/dist/index.cjs +1 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +365 -16920
- package/dist/index.mjs.map +1 -1
- package/dist/use-render-activity-message-BAhbpSDh.js +16200 -0
- package/dist/use-render-activity-message-BAhbpSDh.js.map +1 -0
- package/dist/use-render-activity-message-DJ6q1qHV.cjs +114 -0
- package/dist/use-render-activity-message-DJ6q1qHV.cjs.map +1 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts +14 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -1
- package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts +10 -3
- package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -1
- package/dist/v2/components/CopilotKitInspector.vue.d.ts +5 -1
- package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -1
- package/dist/v2/components/InlineFeatureWarning.vue.d.ts.map +1 -1
- package/dist/v2/components/LicenseWarningBanner.vue.d.ts +2 -2
- package/dist/v2/components/LicenseWarningBanner.vue.d.ts.map +1 -1
- package/dist/v2/components/MCPAppsActivityRenderer.d.ts.map +1 -1
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +13 -59
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +0 -5
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +10 -15
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts +14 -130
- package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts.map +1 -1
- package/dist/v2/components/a2ui/catalog.d.ts.map +1 -1
- package/dist/v2/components/a2ui/utils.d.ts +3 -15
- package/dist/v2/components/a2ui/utils.d.ts.map +1 -1
- package/dist/v2/components/a2ui.d.ts +9 -8
- package/dist/v2/components/a2ui.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChat.vue.d.ts +2 -2
- package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts +4 -8
- package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts +1 -1
- package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +6 -270
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +1 -1
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts +3 -3
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts +8 -3
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +5 -3
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +5 -3
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +8 -3
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +6 -4
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +6 -4
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotThreadsDrawer.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts +1 -0
- package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/audioRecorder.d.ts +3 -4
- package/dist/v2/components/chat/audioRecorder.d.ts.map +1 -1
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts +3 -3
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -1
- package/dist/v2/components/chat/forwarded-slots.d.ts +12 -0
- package/dist/v2/components/chat/forwarded-slots.d.ts.map +1 -0
- package/dist/v2/components/chat/index.d.ts +34 -31
- package/dist/v2/components/chat/index.d.ts.map +1 -1
- package/dist/v2/components/chat/inspector-shortcuts.d.ts +2 -1
- package/dist/v2/components/chat/inspector-shortcuts.d.ts.map +1 -1
- package/dist/v2/components/chat/message-feedback.d.ts +18 -49
- package/dist/v2/components/chat/message-feedback.d.ts.map +1 -1
- package/dist/v2/components/chat/tool-call-display-context.d.ts +4 -19
- package/dist/v2/components/chat/tool-call-display-context.d.ts.map +1 -1
- package/dist/v2/components/chat/tool-call-group-parts.d.ts +7 -20
- package/dist/v2/components/chat/tool-call-group-parts.d.ts.map +1 -1
- package/dist/v2/components/chat/turn-work.d.ts +0 -2
- package/dist/v2/components/chat/turn-work.d.ts.map +1 -1
- package/dist/v2/components/chat/types.d.ts +9 -4
- package/dist/v2/components/chat/types.d.ts.map +1 -1
- package/dist/v2/components/chat/use-chat-labels.d.ts +8 -0
- package/dist/v2/components/chat/use-chat-labels.d.ts.map +1 -0
- package/dist/v2/components/chat/use-copy-feedback.d.ts +11 -0
- package/dist/v2/components/chat/use-copy-feedback.d.ts.map +1 -0
- package/dist/v2/components/chat/use-lightbox.d.ts.map +1 -1
- package/dist/v2/components/icons/index.d.ts +968 -1
- package/dist/v2/components/icons/index.d.ts.map +1 -1
- package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts +1 -1
- package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts.map +1 -1
- package/dist/v2/hooks/use-agent-context.d.ts +2 -3
- package/dist/v2/hooks/use-agent-context.d.ts.map +1 -1
- package/dist/v2/hooks/use-agent.d.ts +4 -1
- package/dist/v2/hooks/use-agent.d.ts.map +1 -1
- package/dist/v2/hooks/use-attachments.d.ts +7 -0
- package/dist/v2/hooks/use-attachments.d.ts.map +1 -1
- package/dist/v2/hooks/use-capabilities.d.ts.map +1 -1
- package/dist/v2/hooks/use-component.d.ts +1 -0
- package/dist/v2/hooks/use-component.d.ts.map +1 -1
- package/dist/v2/hooks/use-configure-suggestions.d.ts +4 -9
- package/dist/v2/hooks/use-configure-suggestions.d.ts.map +1 -1
- package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -1
- package/dist/v2/hooks/use-frontend-tool.d.ts +5 -0
- package/dist/v2/hooks/use-frontend-tool.d.ts.map +1 -1
- package/dist/v2/hooks/use-human-in-the-loop.d.ts +2 -1
- package/dist/v2/hooks/use-human-in-the-loop.d.ts.map +1 -1
- package/dist/v2/hooks/use-interrupt.d.ts +0 -1
- package/dist/v2/hooks/use-interrupt.d.ts.map +1 -1
- package/dist/v2/hooks/use-keyboard-height.d.ts +1 -1
- package/dist/v2/hooks/use-keyboard-height.d.ts.map +1 -1
- package/dist/v2/hooks/use-pin-to-send.d.ts +4 -12
- package/dist/v2/hooks/use-pin-to-send.d.ts.map +1 -1
- package/dist/v2/hooks/use-render-activity-message.d.ts +13 -9
- package/dist/v2/hooks/use-render-activity-message.d.ts.map +1 -1
- package/dist/v2/hooks/use-render-custom-messages.d.ts +5 -7
- package/dist/v2/hooks/use-render-custom-messages.d.ts.map +1 -1
- package/dist/v2/hooks/use-suggestions.d.ts.map +1 -1
- package/dist/v2/hooks/use-threads.d.ts +0 -8
- package/dist/v2/hooks/use-threads.d.ts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +197 -200
- package/dist/v2/index.mjs.map +1 -1
- package/dist/v2/lib/processPartialHtml.d.ts +1 -2
- package/dist/v2/lib/processPartialHtml.d.ts.map +1 -1
- package/dist/v2/lib/shallow-stable.d.ts.map +1 -1
- package/dist/v2/lib/vue-core.d.ts +12 -12
- package/dist/v2/lib/vue-core.d.ts.map +1 -1
- package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.types.d.ts +9 -129
- package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts +9 -10
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/chat-configuration-store-key.d.ts +8 -0
- package/dist/v2/providers/chat-configuration-store-key.d.ts.map +1 -0
- package/dist/v2/providers/markdown-renderer.d.ts +4 -2
- package/dist/v2/providers/markdown-renderer.d.ts.map +1 -1
- package/dist/v2/providers/types.d.ts +3 -46
- package/dist/v2/providers/types.d.ts.map +1 -1
- package/dist/v2/providers/use-inspector-thread-override.d.ts +5 -0
- package/dist/v2/providers/use-inspector-thread-override.d.ts.map +1 -1
- package/dist/v2/types/human-in-the-loop.d.ts +8 -29
- package/dist/v2/types/human-in-the-loop.d.ts.map +1 -1
- package/dist/v2/types/interrupt.d.ts +1 -22
- package/dist/v2/types/interrupt.d.ts.map +1 -1
- package/dist/v2/types/vue-activity-message-renderer.d.ts +16 -15
- package/dist/v2/types/vue-activity-message-renderer.d.ts.map +1 -1
- package/dist/v2/types/vue-custom-message-renderer.d.ts +7 -16
- package/dist/v2/types/vue-custom-message-renderer.d.ts.map +1 -1
- package/dist/v2/types/vue-tool-call-renderer.d.ts +16 -35
- package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -1
- package/package.json +10 -11
- package/src/__tests__/build-entries.test.ts +27 -0
- package/src/hooks/__tests__/zod-parameters.test.ts +520 -0
- package/src/hooks/use-copilot-action.ts +2 -1
- package/src/hooks/use-frontend-tool.ts +3 -6
- package/src/hooks/zod-parameters.ts +162 -0
- package/src/v2/__tests__/exports.test.ts +10 -0
- package/src/v2/__tests__/mocks/web-inspector.ts +6 -0
- package/src/v2/__tests__/utils/test-helpers.ts +34 -4
- package/src/v2/components/A2UIMessageRenderer.ts +98 -68
- package/src/v2/components/A2UISurfaceActivityRenderer.vue +68 -103
- package/src/v2/components/CopilotKitInspector.vue +104 -51
- package/src/v2/components/InlineFeatureWarning.vue +20 -21
- package/src/v2/components/LicenseWarningBanner.vue +27 -135
- package/src/v2/components/MCPAppsActivityRenderer.ts +75 -201
- package/src/v2/components/OpenGenerativeUIRenderer.ts +122 -446
- package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +171 -8
- package/src/v2/components/__tests__/CopilotKitInspector.test.ts +42 -0
- package/src/v2/components/__tests__/LicenseWarningBanner.test.ts +60 -0
- package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +64 -8
- package/src/v2/components/__tests__/OpenGenerativeUIToolRenderer.test.ts +38 -0
- package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +2 -7
- package/src/v2/components/a2ui/A2UICatalogContext.ts +27 -185
- package/src/v2/components/a2ui/A2UIRecoveryStates.ts +127 -327
- package/src/v2/components/a2ui/catalog.ts +3 -3
- package/src/v2/components/a2ui/utils.ts +13 -65
- package/src/v2/components/a2ui.ts +15 -22
- package/src/v2/components/chat/CopilotChat.vue +147 -356
- package/src/v2/components/chat/CopilotChatAssistantMessage.vue +19 -43
- package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +36 -55
- package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +14 -6
- package/src/v2/components/chat/CopilotChatAudioRecorder.vue +19 -246
- package/src/v2/components/chat/CopilotChatFeedbackCommentPopover.vue +2 -2
- package/src/v2/components/chat/CopilotChatInput.vue +108 -436
- package/src/v2/components/chat/CopilotChatInspectorButton.vue +45 -108
- package/src/v2/components/chat/CopilotChatLightbox.vue +10 -31
- package/src/v2/components/chat/CopilotChatMessageView.vue +82 -210
- package/src/v2/components/chat/CopilotChatReasoningMessage.vue +7 -15
- package/src/v2/components/chat/CopilotChatToolCallGroup.vue +63 -71
- package/src/v2/components/chat/CopilotChatToolCallItem.vue +8 -6
- package/src/v2/components/chat/CopilotChatToolCallsView.vue +31 -32
- package/src/v2/components/chat/CopilotChatUserMessage.vue +24 -112
- package/src/v2/components/chat/CopilotChatView.vue +33 -28
- package/src/v2/components/chat/CopilotChatWorkSummary.vue +26 -36
- package/src/v2/components/chat/CopilotModalHeader.vue +11 -23
- package/src/v2/components/chat/CopilotPopup.vue +23 -25
- package/src/v2/components/chat/CopilotPopupView.vue +10 -39
- package/src/v2/components/chat/CopilotPopupViewInternal.vue +35 -131
- package/src/v2/components/chat/CopilotSidebar.vue +23 -25
- package/src/v2/components/chat/CopilotSidebarView.vue +10 -39
- package/src/v2/components/chat/CopilotSidebarViewInternal.vue +38 -59
- package/src/v2/components/chat/CopilotThreadsDrawer.vue +37 -102
- package/src/v2/components/chat/StreamingMarkdownDefault.vue +15 -28
- package/src/v2/components/chat/__tests__/CopilotChat.labels.test.ts +19 -4
- package/src/v2/components/chat/__tests__/CopilotChat.test.ts +12 -10
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +26 -9
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.learningFeedback.test.ts +5 -5
- package/src/v2/components/chat/__tests__/CopilotChatAttachmentQueue.test.ts +28 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +89 -1
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.ts +247 -403
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.toolCallDisplay.test.ts +1 -99
- package/src/v2/components/chat/__tests__/CopilotPopup.test.ts +90 -1
- package/src/v2/components/chat/__tests__/CopilotPopupView.test.ts +19 -0
- package/src/v2/components/chat/__tests__/CopilotSidebar.test.ts +90 -1
- package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.ts +32 -8
- package/src/v2/components/chat/__tests__/CopilotSidebarView.test.ts +2 -1
- package/src/v2/components/chat/__tests__/StreamingMarkdownDefault.test.ts +54 -0
- package/src/v2/components/chat/audioRecorder.ts +4 -7
- package/src/v2/components/chat/copilotChatToolCallItemRender.ts +24 -89
- package/src/v2/components/chat/forwarded-slots.ts +17 -0
- package/src/v2/components/chat/index.ts +0 -1
- package/src/v2/components/chat/inspector-shortcuts.ts +10 -16
- package/src/v2/components/chat/message-feedback.ts +62 -197
- package/src/v2/components/chat/tool-call-display-context.ts +6 -22
- package/src/v2/components/chat/tool-call-group-parts.ts +47 -108
- package/src/v2/components/chat/turn-work.ts +0 -9
- package/src/v2/components/chat/types.ts +12 -4
- package/src/v2/components/chat/use-chat-labels.ts +16 -0
- package/src/v2/components/chat/use-copy-feedback.ts +21 -0
- package/src/v2/components/chat/use-lightbox.ts +15 -33
- package/src/v2/components/icons/__tests__/icons.test.ts +72 -68
- package/src/v2/components/icons/index.ts +109 -27
- package/src/v2/hooks/__tests__/use-agent-error-state.test.ts +5 -3
- package/src/v2/hooks/__tests__/use-agent-stability.test.ts +25 -4
- package/src/v2/hooks/__tests__/use-agent-throttle.test.ts +5 -1
- package/src/v2/hooks/__tests__/use-agent.test.ts +6 -3
- package/src/v2/hooks/__tests__/use-component.test.ts +21 -0
- package/src/v2/hooks/__tests__/use-configure-suggestions.test.ts +30 -1
- package/src/v2/hooks/__tests__/use-default-render-tool.test.ts +10 -10
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +66 -1
- package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.ts +6 -1
- package/src/v2/hooks/__tests__/use-human-in-the-loop.test.ts +187 -12
- package/src/v2/hooks/__tests__/use-interrupt.test.ts +97 -0
- package/src/v2/hooks/__tests__/use-render-activity-message.test.ts +106 -0
- package/src/v2/hooks/__tests__/use-render-tool.test.ts +3 -6
- package/src/v2/hooks/__tests__/use-threads.test.ts +48 -6
- package/src/v2/hooks/__tests__/zod-regression.test.ts +5 -4
- package/src/v2/hooks/use-agent-context.ts +4 -10
- package/src/v2/hooks/use-agent.ts +86 -290
- package/src/v2/hooks/use-attachments.ts +48 -168
- package/src/v2/hooks/use-capabilities.ts +2 -7
- package/src/v2/hooks/use-component.ts +7 -4
- package/src/v2/hooks/use-configure-suggestions.ts +28 -218
- package/src/v2/hooks/use-default-render-tool.ts +34 -94
- package/src/v2/hooks/use-frontend-tool.ts +10 -10
- package/src/v2/hooks/use-human-in-the-loop.ts +11 -80
- package/src/v2/hooks/use-interrupt.ts +29 -308
- package/src/v2/hooks/use-keyboard-height.ts +17 -40
- package/src/v2/hooks/use-pin-to-send.ts +15 -99
- package/src/v2/hooks/use-render-activity-message.ts +31 -55
- package/src/v2/hooks/use-render-custom-messages.ts +24 -88
- package/src/v2/hooks/use-suggestions.ts +9 -33
- package/src/v2/hooks/use-threads.ts +43 -273
- package/src/v2/lib/__tests__/shallow-stable.test.ts +54 -0
- package/src/v2/lib/__tests__/vue-core-renderers.test.ts +42 -0
- package/src/v2/lib/processPartialHtml.ts +6 -21
- package/src/v2/lib/shallow-stable.ts +2 -16
- package/src/v2/lib/vue-core.ts +69 -78
- package/src/v2/providers/CopilotChatConfigurationProvider.vue +48 -186
- package/src/v2/providers/CopilotKitProvider.types.ts +12 -132
- package/src/v2/providers/CopilotKitProvider.vue +237 -510
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.ts +22 -2
- package/src/v2/providers/__tests__/CopilotKitProvider.a2ui.test.ts +20 -2
- package/src/v2/providers/__tests__/CopilotKitProvider.config.test.ts +124 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.headersAtSendTime.test.ts +3 -3
- package/src/v2/providers/__tests__/CopilotKitProvider.learning.test.ts +3 -1
- package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.ts +4 -1
- package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +53 -26
- package/src/v2/providers/chat-configuration-store-key.ts +9 -0
- package/src/v2/providers/markdown-renderer.ts +8 -2
- package/src/v2/providers/types.ts +3 -49
- package/src/v2/providers/use-inspector-thread-override.ts +22 -80
- package/src/v2/types/__tests__/defineToolCallRenderer.test.ts +28 -33
- package/src/v2/types/defineToolCallRenderer.ts +5 -4
- package/src/v2/types/human-in-the-loop.ts +8 -32
- package/src/v2/types/interrupt.ts +7 -31
- package/src/v2/types/vue-activity-message-renderer.ts +24 -15
- package/src/v2/types/vue-custom-message-renderer.ts +12 -16
- package/src/v2/types/vue-tool-call-renderer.ts +23 -38
- package/tsconfig.json +0 -1
- package/vite.config.ts +8 -5
- package/vitest.config.ts +12 -7
- package/dist/v2/components/chat/BasicMarkdown.vue.d.ts +0 -9
- package/dist/v2/components/chat/BasicMarkdown.vue.d.ts.map +0 -1
- package/dist/v2/components/chat/normalize-auto-scroll.d.ts +0 -3
- package/dist/v2/components/chat/normalize-auto-scroll.d.ts.map +0 -1
- package/dist/v2/components/chat/tool-call-layout.d.ts +0 -115
- package/dist/v2/components/chat/tool-call-layout.d.ts.map +0 -1
- package/dist/v2/lib/is-mobile-viewport.d.ts +0 -15
- package/dist/v2/lib/is-mobile-viewport.d.ts.map +0 -1
- package/dist/v2/lib/message-feedback.d.ts +0 -33
- package/dist/v2/lib/message-feedback.d.ts.map +0 -1
- package/dist/v2/lib/transcription-client.d.ts +0 -19
- package/dist/v2/lib/transcription-client.d.ts.map +0 -1
- package/src/v2/components/__tests__/A2UICatalogContext.test.ts +0 -63
- package/src/v2/components/a2ui/__tests__/A2UIRecoveryStates.test.ts +0 -175
- package/src/v2/components/chat/BasicMarkdown.vue +0 -160
- package/src/v2/components/chat/__tests__/BasicMarkdown.test.ts +0 -69
- package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -39
- package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
- package/src/v2/components/chat/tool-call-layout.ts +0 -304
- package/src/v2/lib/__tests__/is-mobile-viewport.test.ts +0 -48
- package/src/v2/lib/__tests__/message-feedback.test.ts +0 -152
- package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -84
- package/src/v2/lib/__tests__/transcription-client.test.ts +0 -67
- package/src/v2/lib/is-mobile-viewport.ts +0 -23
- package/src/v2/lib/message-feedback.ts +0 -120
- package/src/v2/lib/transcription-client.ts +0 -151
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { nextTick, shallowRef } from "vue";
|
|
3
|
+
import { useShallowStableRef } from "../shallow-stable";
|
|
4
|
+
|
|
5
|
+
/** A stable ref over a source the test replaces with `set(next)`. */
|
|
6
|
+
function stableOver<T>(initial: T) {
|
|
7
|
+
const source = shallowRef(initial);
|
|
8
|
+
const stable = useShallowStableRef(source);
|
|
9
|
+
const set = async (next: T) => {
|
|
10
|
+
source.value = next;
|
|
11
|
+
await nextTick();
|
|
12
|
+
};
|
|
13
|
+
return { stable, set };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("useShallowStableRef", () => {
|
|
17
|
+
it("keeps the reference for a shallowly equal plain object", async () => {
|
|
18
|
+
const { stable, set } = stableOver({ a: 1 });
|
|
19
|
+
const first = stable.value;
|
|
20
|
+
|
|
21
|
+
await set({ a: 1 });
|
|
22
|
+
|
|
23
|
+
expect(stable.value).toBe(first);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("updates the reference when a value changes", async () => {
|
|
27
|
+
const { stable, set } = stableOver({ a: 1 });
|
|
28
|
+
|
|
29
|
+
await set({ a: 2 });
|
|
30
|
+
|
|
31
|
+
expect(stable.value).toEqual({ a: 2 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("updates the reference when a different key holds undefined", async () => {
|
|
35
|
+
const { stable, set } = stableOver<{ a?: number; b?: number }>({
|
|
36
|
+
a: undefined,
|
|
37
|
+
});
|
|
38
|
+
const first = stable.value;
|
|
39
|
+
|
|
40
|
+
await set({ b: undefined });
|
|
41
|
+
|
|
42
|
+
expect(stable.value).not.toBe(first);
|
|
43
|
+
expect(stable.value).toEqual({ b: undefined });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("compares arrays by reference", async () => {
|
|
47
|
+
const { stable, set } = stableOver([1, 2]);
|
|
48
|
+
const first = stable.value;
|
|
49
|
+
|
|
50
|
+
await set([1, 2]);
|
|
51
|
+
|
|
52
|
+
expect(stable.value).not.toBe(first);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { CopilotKitCoreVue } from "../vue-core";
|
|
4
|
+
import type { VueActivityMessageRenderer } from "../../types";
|
|
5
|
+
|
|
6
|
+
const planRenderer: VueActivityMessageRenderer<unknown> = {
|
|
7
|
+
activityType: "plan",
|
|
8
|
+
content: {
|
|
9
|
+
"~standard": {
|
|
10
|
+
version: 1,
|
|
11
|
+
vendor: "test",
|
|
12
|
+
validate: (value) => ({ value }),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
render: () => null,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("CopilotKitCoreVue renderer lists", () => {
|
|
19
|
+
it("notifies subscribers when activity renderers change", () => {
|
|
20
|
+
const core = new CopilotKitCoreVue({});
|
|
21
|
+
const seen: string[][] = [];
|
|
22
|
+
core.subscribe({
|
|
23
|
+
onRenderActivityMessagesChanged: ({ renderActivityMessages }) => {
|
|
24
|
+
seen.push(renderActivityMessages.map((r) => r.activityType));
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
core.setRenderActivityMessages([planRenderer]);
|
|
29
|
+
|
|
30
|
+
expect(seen).toEqual([["plan"]]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("keeps working behind a Vue reactive proxy", () => {
|
|
34
|
+
const wrapped = ref(new CopilotKitCoreVue({}));
|
|
35
|
+
|
|
36
|
+
wrapped.value.addHookRenderToolCall({ name: "search", render: () => null });
|
|
37
|
+
|
|
38
|
+
expect(wrapped.value.renderToolCalls.map((r) => r.name)).toEqual([
|
|
39
|
+
"search",
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let result = html;
|
|
8
|
-
|
|
9
|
-
result = result.replace(/<[^>]*$/, "");
|
|
10
|
-
result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
|
|
11
|
-
result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*$/gi, "");
|
|
12
|
-
result = result.replace(/&[a-zA-Z0-9#]*$/, "");
|
|
13
|
-
|
|
14
|
-
const bodyMatch = result.match(/<body[^>]*>([\s\S]*)/i);
|
|
15
|
-
if (bodyMatch) {
|
|
16
|
-
result = bodyMatch[1]!;
|
|
17
|
-
result = result.replace(/<\/body>[\s\S]*/i, "");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
1
|
+
// The partial-HTML helpers live in @copilotkit/core; these names stay for
|
|
2
|
+
// existing imports.
|
|
3
|
+
export {
|
|
4
|
+
ɵextractCompleteStyles as extractCompleteStyles,
|
|
5
|
+
ɵprocessPartialHtml as processPartialHtml,
|
|
6
|
+
} from "@copilotkit/core";
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
+
import { ɵshallowEqualRecord } from "@copilotkit/core";
|
|
1
2
|
import { shallowRef, toValue, watch } from "vue";
|
|
2
3
|
import type { MaybeRefOrGetter, ShallowRef } from "vue";
|
|
3
4
|
|
|
4
|
-
function shallowEqualObjects(
|
|
5
|
-
first: Record<string, unknown>,
|
|
6
|
-
second: Record<string, unknown>,
|
|
7
|
-
): boolean {
|
|
8
|
-
const firstKeys = Object.keys(first);
|
|
9
|
-
const secondKeys = Object.keys(second);
|
|
10
|
-
if (firstKeys.length !== secondKeys.length) return false;
|
|
11
|
-
|
|
12
|
-
for (const key of firstKeys) {
|
|
13
|
-
if (first[key] !== second[key]) return false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
5
|
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
20
6
|
return (
|
|
21
7
|
value !== null &&
|
|
@@ -40,7 +26,7 @@ export function useShallowStableRef<T>(
|
|
|
40
26
|
if (previous === next) return;
|
|
41
27
|
|
|
42
28
|
if (isPlainObject(previous) && isPlainObject(next)) {
|
|
43
|
-
if (
|
|
29
|
+
if (ɵshallowEqualRecord(previous, next)) {
|
|
44
30
|
return;
|
|
45
31
|
}
|
|
46
32
|
}
|
package/src/v2/lib/vue-core.ts
CHANGED
|
@@ -5,11 +5,12 @@ import type {
|
|
|
5
5
|
VueCustomMessageRenderer,
|
|
6
6
|
} from "../types";
|
|
7
7
|
import type { InterruptRenderProps } from "../types/interrupt";
|
|
8
|
-
import { CopilotKitCore } from "@copilotkit/core";
|
|
8
|
+
import { CopilotKitCore, ɵRendererRegistry } from "@copilotkit/core";
|
|
9
9
|
import type {
|
|
10
10
|
CopilotKitCoreConfig,
|
|
11
11
|
CopilotKitCoreSubscriber,
|
|
12
12
|
CopilotKitCoreSubscription,
|
|
13
|
+
ɵRendererKind,
|
|
13
14
|
} from "@copilotkit/core";
|
|
14
15
|
|
|
15
16
|
export interface CopilotKitCoreVueConfig extends CopilotKitCoreConfig {
|
|
@@ -27,6 +28,10 @@ export interface CopilotKitCoreVueSubscriber extends CopilotKitCoreSubscriber {
|
|
|
27
28
|
copilotkit: CopilotKitCoreVue;
|
|
28
29
|
renderCustomMessages: VueCustomMessageRenderer[];
|
|
29
30
|
}) => void | Promise<void>;
|
|
31
|
+
onRenderActivityMessagesChanged?: (event: {
|
|
32
|
+
copilotkit: CopilotKitCoreVue;
|
|
33
|
+
renderActivityMessages: VueActivityMessageRenderer<unknown>[];
|
|
34
|
+
}) => void | Promise<void>;
|
|
30
35
|
onInterruptStateChanged?: (event: {
|
|
31
36
|
copilotkit: CopilotKitCoreVue;
|
|
32
37
|
interruptState: InterruptRenderProps<unknown, unknown> | null;
|
|
@@ -34,119 +39,109 @@ export interface CopilotKitCoreVueSubscriber extends CopilotKitCoreSubscriber {
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export class CopilotKitCoreVue extends CopilotKitCore {
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
private _renderCustomMessages: VueCustomMessageRenderer[] = [];
|
|
43
|
-
private _renderActivityMessages: VueActivityMessageRenderer<unknown>[] = [];
|
|
44
|
-
private _interruptState: InterruptRenderProps<unknown, unknown> | null = null;
|
|
42
|
+
private readonly _renderers: ɵRendererRegistry<
|
|
43
|
+
VueToolCallRenderer<unknown>,
|
|
44
|
+
VueActivityMessageRenderer<unknown>,
|
|
45
|
+
VueCustomMessageRenderer
|
|
46
|
+
>;
|
|
45
47
|
|
|
46
48
|
constructor(config: CopilotKitCoreVueConfig) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
49
|
+
// Tool handlers can change reactive state. `nextTick` lets Vue flush those
|
|
50
|
+
// updates before core starts the follow-up run.
|
|
51
|
+
super({ ...config, ɵwaitForFrameworkUpdates: () => nextTick() });
|
|
52
|
+
this._renderers = new ɵRendererRegistry({
|
|
53
|
+
toolCalls: config.renderToolCalls,
|
|
54
|
+
activity: config.renderActivityMessages,
|
|
55
|
+
custom: config.renderCustomMessages,
|
|
56
|
+
});
|
|
57
|
+
this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));
|
|
58
|
+
// The props live in core's generic interrupt slot; keep the Vue
|
|
59
|
+
// subscriber event for existing listeners.
|
|
60
|
+
this.ɵsubscribeToInterruptPayload(() => {
|
|
61
|
+
void this.notifySubscribers((subscriber) => {
|
|
62
|
+
const vueSubscriber = subscriber as CopilotKitCoreVueSubscriber;
|
|
63
|
+
return vueSubscriber.onInterruptStateChanged?.({
|
|
64
|
+
copilotkit: this,
|
|
65
|
+
interruptState: this.interruptState,
|
|
66
|
+
});
|
|
67
|
+
}, "Subscriber onInterruptStateChanged error:");
|
|
68
|
+
});
|
|
51
69
|
}
|
|
52
70
|
|
|
53
|
-
get renderCustomMessages()
|
|
54
|
-
return this.
|
|
71
|
+
get renderCustomMessages() {
|
|
72
|
+
return this._renderers.custom;
|
|
55
73
|
}
|
|
56
74
|
|
|
57
|
-
get renderActivityMessages()
|
|
58
|
-
|
|
59
|
-
> {
|
|
60
|
-
return this._renderActivityMessages;
|
|
75
|
+
get renderActivityMessages() {
|
|
76
|
+
return this._renderers.activity;
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
setRenderActivityMessages(
|
|
64
80
|
renderers: VueActivityMessageRenderer<unknown>[],
|
|
65
81
|
): void {
|
|
66
|
-
this.
|
|
82
|
+
this._renderers.setActivity(renderers);
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
setRenderCustomMessages(renderers: VueCustomMessageRenderer[]): void {
|
|
70
|
-
this.
|
|
71
|
-
void this.notifySubscribers((subscriber) => {
|
|
72
|
-
const vueSubscriber = subscriber as CopilotKitCoreVueSubscriber;
|
|
73
|
-
vueSubscriber.onRenderCustomMessagesChanged?.({
|
|
74
|
-
copilotkit: this,
|
|
75
|
-
renderCustomMessages: [...this.renderCustomMessages],
|
|
76
|
-
});
|
|
77
|
-
}, "Subscriber onRenderCustomMessagesChanged error:");
|
|
86
|
+
this._renderers.setCustom(renderers);
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
/** The renderers the provider was given, without hook renderers. */
|
|
90
|
+
get propRenderToolCalls() {
|
|
91
|
+
return this._renderers.propToolCalls;
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
if (this._cachedMergedRenderToolCalls) {
|
|
89
|
-
return this._cachedMergedRenderToolCalls;
|
|
90
|
-
}
|
|
91
|
-
const merged = new Map<string, VueToolCallRenderer<unknown>>();
|
|
92
|
-
for (const rc of this._renderToolCalls) {
|
|
93
|
-
merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
94
|
-
}
|
|
95
|
-
for (const [key, rc] of this._hookRenderToolCalls) {
|
|
96
|
-
merged.set(key, rc);
|
|
97
|
-
}
|
|
98
|
-
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
99
|
-
return this._cachedMergedRenderToolCalls;
|
|
94
|
+
/** Prop and hook renderers merged; a hook renderer wins over a prop one. */
|
|
95
|
+
get renderToolCalls() {
|
|
96
|
+
return this._renderers.toolCalls;
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
get interruptState(): InterruptRenderProps<unknown, unknown> | null {
|
|
103
|
-
return this
|
|
100
|
+
return this.ɵinterruptPayload as InterruptRenderProps<
|
|
101
|
+
unknown,
|
|
102
|
+
unknown
|
|
103
|
+
> | null;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
setRenderToolCalls(renderToolCalls: VueToolCallRenderer<unknown>[]): void {
|
|
107
|
-
this.
|
|
108
|
-
this._cachedMergedRenderToolCalls = null;
|
|
109
|
-
this._notifyRenderToolCallsChanged();
|
|
107
|
+
this._renderers.setPropToolCalls(renderToolCalls);
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
addHookRenderToolCall(entry: VueToolCallRenderer<unknown>): void {
|
|
113
|
-
|
|
114
|
-
this._hookRenderToolCalls.set(key, entry);
|
|
115
|
-
this._cachedMergedRenderToolCalls = null;
|
|
116
|
-
this._notifyRenderToolCallsChanged();
|
|
111
|
+
this._renderers.addHookToolCall(entry);
|
|
117
112
|
}
|
|
118
113
|
|
|
119
114
|
removeHookRenderToolCall(name: string, agentId?: string): void {
|
|
120
|
-
|
|
121
|
-
if (this._hookRenderToolCalls.delete(key)) {
|
|
122
|
-
this._cachedMergedRenderToolCalls = null;
|
|
123
|
-
this._notifyRenderToolCallsChanged();
|
|
124
|
-
}
|
|
115
|
+
this._renderers.removeHookToolCall(name, agentId);
|
|
125
116
|
}
|
|
126
117
|
|
|
127
|
-
private
|
|
118
|
+
private notifyRenderersChanged(kind: ɵRendererKind): void {
|
|
128
119
|
void this.notifySubscribers((subscriber) => {
|
|
129
120
|
const vueSubscriber = subscriber as CopilotKitCoreVueSubscriber;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
121
|
+
switch (kind) {
|
|
122
|
+
case "toolCalls":
|
|
123
|
+
return vueSubscriber.onRenderToolCallsChanged?.({
|
|
124
|
+
copilotkit: this,
|
|
125
|
+
renderToolCalls: [...this.renderToolCalls],
|
|
126
|
+
});
|
|
127
|
+
case "activity":
|
|
128
|
+
return vueSubscriber.onRenderActivityMessagesChanged?.({
|
|
129
|
+
copilotkit: this,
|
|
130
|
+
renderActivityMessages: [...this.renderActivityMessages],
|
|
131
|
+
});
|
|
132
|
+
case "custom":
|
|
133
|
+
return vueSubscriber.onRenderCustomMessagesChanged?.({
|
|
134
|
+
copilotkit: this,
|
|
135
|
+
renderCustomMessages: [...this.renderCustomMessages],
|
|
136
|
+
});
|
|
135
137
|
}
|
|
136
|
-
},
|
|
138
|
+
}, `Subscriber renderer change (${kind}) error:`);
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
setInterruptState(
|
|
140
142
|
interruptState: InterruptRenderProps<unknown, unknown> | null,
|
|
141
143
|
): void {
|
|
142
|
-
this
|
|
143
|
-
void this.notifySubscribers((subscriber) => {
|
|
144
|
-
const vueSubscriber = subscriber as CopilotKitCoreVueSubscriber;
|
|
145
|
-
vueSubscriber.onInterruptStateChanged?.({
|
|
146
|
-
copilotkit: this,
|
|
147
|
-
interruptState: this._interruptState,
|
|
148
|
-
});
|
|
149
|
-
}, "Subscriber onInterruptStateChanged error:");
|
|
144
|
+
this.ɵsetInterruptPayload(interruptState);
|
|
150
145
|
}
|
|
151
146
|
|
|
152
147
|
subscribe(
|
|
@@ -154,8 +149,4 @@ export class CopilotKitCoreVue extends CopilotKitCore {
|
|
|
154
149
|
): CopilotKitCoreSubscription {
|
|
155
150
|
return super.subscribe(subscriber);
|
|
156
151
|
}
|
|
157
|
-
|
|
158
|
-
async waitForPendingFrameworkUpdates(): Promise<void> {
|
|
159
|
-
await nextTick();
|
|
160
|
-
}
|
|
161
152
|
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
inject,
|
|
5
|
+
onBeforeUnmount,
|
|
6
|
+
onMounted,
|
|
7
|
+
provide,
|
|
8
|
+
shallowRef,
|
|
9
|
+
watch,
|
|
10
|
+
} from "vue";
|
|
11
|
+
import { ɵChatConfigurationStore } from "@copilotkit/core";
|
|
3
12
|
import type { ComputedRef } from "vue";
|
|
4
|
-
import { DEFAULT_AGENT_ID, randomUUID } from "@copilotkit/shared";
|
|
5
|
-
import type { OpenThreadRegistration } from "@copilotkit/core";
|
|
6
13
|
import { CopilotChatConfigurationKey, CopilotKitKey } from "./keys";
|
|
14
|
+
import { ChatConfigurationStoreKey } from "./chat-configuration-store-key";
|
|
7
15
|
import { CopilotChatDefaultLabels } from "./types";
|
|
8
16
|
import type { CopilotChatConfigurationValue, CopilotChatLabels } from "./types";
|
|
9
17
|
import type { CopilotChatConfigurationProviderProps } from "./CopilotChatConfigurationProvider.types";
|
|
10
18
|
import { useShallowStableRef } from "../lib/shallow-stable";
|
|
11
|
-
import { isMobileViewport } from "../lib/is-mobile-viewport";
|
|
12
19
|
|
|
13
|
-
// Vue normalizes optional Boolean props to `false` when not supplied; declare
|
|
14
|
-
// `undefined` defaults so we can faithfully distinguish "caller passed false"
|
|
15
|
-
// from "caller did not pass the prop", matching React's prop semantics.
|
|
16
20
|
const props = withDefaults(
|
|
17
21
|
defineProps<CopilotChatConfigurationProviderProps>(),
|
|
18
22
|
{
|
|
@@ -25,210 +29,68 @@ const parentConfig = inject<ComputedRef<CopilotChatConfigurationValue> | null>(
|
|
|
25
29
|
CopilotChatConfigurationKey,
|
|
26
30
|
null,
|
|
27
31
|
);
|
|
28
|
-
const parentConfigValue = computed(() => parentConfig?.value ?? null);
|
|
29
32
|
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// Core owns thread, agent, modal and drawer resolution across the provider
|
|
34
|
+
// chain; this component feeds it props and projects its snapshot.
|
|
35
|
+
const readOptions = () => ({
|
|
36
|
+
agentId: props.agentId,
|
|
37
|
+
threadId: props.threadId,
|
|
38
|
+
hasExplicitThreadId: props.hasExplicitThreadId,
|
|
39
|
+
isModalDefaultOpen: props.isModalDefaultOpen,
|
|
40
|
+
});
|
|
41
|
+
const store = new ɵChatConfigurationStore(
|
|
42
|
+
readOptions(),
|
|
43
|
+
inject(ChatConfigurationStoreKey, null),
|
|
35
44
|
);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
const snapshot = shallowRef(store.getSnapshot());
|
|
46
|
+
const unsubscribe = store.subscribe(() => {
|
|
47
|
+
snapshot.value = store.getSnapshot();
|
|
48
|
+
});
|
|
49
|
+
watch(readOptions, (options) => store.update(options));
|
|
50
|
+
onBeforeUnmount(() => {
|
|
51
|
+
unsubscribe();
|
|
52
|
+
store.dispose();
|
|
53
|
+
});
|
|
42
54
|
|
|
43
55
|
const stableLabels = useShallowStableRef(computed(() => props.labels));
|
|
44
56
|
|
|
45
57
|
const mergedLabels = computed<CopilotChatLabels>(() => ({
|
|
46
58
|
...CopilotChatDefaultLabels,
|
|
47
|
-
...
|
|
59
|
+
...parentConfig?.value?.labels,
|
|
48
60
|
...stableLabels.value,
|
|
49
61
|
}));
|
|
50
62
|
|
|
51
|
-
const resolvedAgentId = computed(
|
|
52
|
-
() => props.agentId ?? parentConfigValue.value?.agentId ?? DEFAULT_AGENT_ID,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const fallbackThreadId = randomUUID();
|
|
56
|
-
const resolvedThreadId = computed(() => {
|
|
57
|
-
if (propIsAuthoritative.value) return props.threadId as string;
|
|
58
|
-
if (activeThreadOverride.value) return activeThreadOverride.value.threadId;
|
|
59
|
-
if (props.threadId) return props.threadId;
|
|
60
|
-
if (parentConfigValue.value?.threadId)
|
|
61
|
-
return parentConfigValue.value.threadId;
|
|
62
|
-
return fallbackThreadId;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
63
|
// Tell Core which Thread this view shows, so captured interactions can link
|
|
66
|
-
// to it.
|
|
67
|
-
// is nothing to register with. Registration starts on mount, so a server
|
|
68
|
-
// render never registers a Thread that it can't unregister.
|
|
64
|
+
// to it. Works without a CopilotKitProvider: then there is nothing to register.
|
|
69
65
|
const copilotKitContext = inject(CopilotKitKey, null);
|
|
70
|
-
let openThread: OpenThreadRegistration | null = null;
|
|
71
66
|
onMounted(() => {
|
|
72
67
|
watch(
|
|
73
|
-
() =>
|
|
74
|
-
(
|
|
68
|
+
() => copilotKitContext?.copilotkit.value,
|
|
69
|
+
(core, _previous, onCleanup) => {
|
|
75
70
|
if (!core) return;
|
|
76
|
-
|
|
77
|
-
agentId,
|
|
78
|
-
threadId: resolvedThreadId.value,
|
|
79
|
-
});
|
|
80
|
-
openThread = registration;
|
|
81
|
-
onCleanup(() => {
|
|
82
|
-
registration.unregister();
|
|
83
|
-
openThread = null;
|
|
84
|
-
});
|
|
71
|
+
onCleanup(store.bindOpenThread(core));
|
|
85
72
|
},
|
|
86
73
|
{ immediate: true },
|
|
87
74
|
);
|
|
88
|
-
watch(resolvedThreadId, (threadId) => openThread?.update(threadId));
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const resolvedHasExplicitThreadId = computed(() => {
|
|
92
|
-
if (propIsAuthoritative.value) return true;
|
|
93
|
-
const own = activeThreadOverride.value
|
|
94
|
-
? activeThreadOverride.value.explicit
|
|
95
|
-
: props.hasExplicitThreadId !== undefined
|
|
96
|
-
? props.hasExplicitThreadId
|
|
97
|
-
: !!props.threadId;
|
|
98
|
-
return own || !!parentConfigValue.value?.hasExplicitThreadId;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const shouldCreateModalState = computed(
|
|
102
|
-
() => props.isModalDefaultOpen !== undefined,
|
|
103
|
-
);
|
|
104
|
-
const resolvedDefaultOpen = computed(() => props.isModalDefaultOpen ?? true);
|
|
105
|
-
|
|
106
|
-
const internalModalOpen = ref<boolean>(
|
|
107
|
-
parentConfigValue.value?.isModalOpen ?? resolvedDefaultOpen.value,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
function setInternalModalOpen(open: boolean) {
|
|
111
|
-
internalModalOpen.value = open;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const resolvedIsModalOpen = computed(() =>
|
|
115
|
-
shouldCreateModalState.value
|
|
116
|
-
? internalModalOpen.value
|
|
117
|
-
: parentConfigValue.value?.isModalOpen,
|
|
118
|
-
);
|
|
119
|
-
const resolvedSetModalOpen = computed(() =>
|
|
120
|
-
shouldCreateModalState.value
|
|
121
|
-
? setInternalModalOpen
|
|
122
|
-
: parentConfigValue.value?.setModalOpen,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
function setActiveThreadId(threadId: string, options?: { explicit?: boolean }) {
|
|
126
|
-
if (propIsAuthoritative.value) {
|
|
127
|
-
console.warn(
|
|
128
|
-
"[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled " +
|
|
129
|
-
"via the `threadId` prop on CopilotChatConfigurationProvider.",
|
|
130
|
-
);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
activeThreadOverride.value = {
|
|
134
|
-
threadId,
|
|
135
|
-
explicit: options?.explicit ?? true,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function startNewThread() {
|
|
140
|
-
if (propIsAuthoritative.value) {
|
|
141
|
-
console.warn(
|
|
142
|
-
"[CopilotKit] Ignoring startNewThread(): threadId is controlled via " +
|
|
143
|
-
"the `threadId` prop on CopilotChatConfigurationProvider.",
|
|
144
|
-
);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
activeThreadOverride.value = { threadId: randomUUID(), explicit: false };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Drawer presence + open state. The top-most provider owns the state; a nested
|
|
151
|
-
// provider proxies its parent so the whole chain shares one drawer.
|
|
152
|
-
const ownDrawerOpen = ref(false);
|
|
153
|
-
const ownDrawerCount = ref(0);
|
|
154
|
-
|
|
155
|
-
function ownSetDrawerOpen(open: boolean) {
|
|
156
|
-
ownDrawerOpen.value = open;
|
|
157
|
-
// Mobile mutual-exclusion: opening the drawer closes the chat modal.
|
|
158
|
-
if (open && isMobileViewport()) {
|
|
159
|
-
resolvedSetModalOpen.value?.(false);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function ownRegisterDrawer(): () => void {
|
|
164
|
-
ownDrawerCount.value += 1;
|
|
165
|
-
return () => {
|
|
166
|
-
ownDrawerCount.value = Math.max(0, ownDrawerCount.value - 1);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const resolvedDrawerOpen = computed(() =>
|
|
171
|
-
parentConfigValue.value
|
|
172
|
-
? parentConfigValue.value.drawerOpen
|
|
173
|
-
: ownDrawerOpen.value,
|
|
174
|
-
);
|
|
175
|
-
const resolvedSetDrawerOpen = computed(() =>
|
|
176
|
-
parentConfigValue.value
|
|
177
|
-
? parentConfigValue.value.setDrawerOpen
|
|
178
|
-
: ownSetDrawerOpen,
|
|
179
|
-
);
|
|
180
|
-
const resolvedDrawerRegistered = computed(() =>
|
|
181
|
-
parentConfigValue.value
|
|
182
|
-
? parentConfigValue.value.drawerRegistered
|
|
183
|
-
: ownDrawerCount.value > 0,
|
|
184
|
-
);
|
|
185
|
-
const resolvedRegisterDrawer = computed(() =>
|
|
186
|
-
parentConfigValue.value
|
|
187
|
-
? parentConfigValue.value.registerDrawer
|
|
188
|
-
: ownRegisterDrawer,
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// Public modal setter (mobile mutual-exclusion, other direction: opening the
|
|
192
|
-
// chat modal closes the drawer). Preserve the contract that it is `undefined`
|
|
193
|
-
// when this provider owns no modal state AND no parent provides one —
|
|
194
|
-
// CopilotChatToggleButton relies on that absence to fall back to its own
|
|
195
|
-
// local open-state. When a real modal setter exists (own `isModalDefaultOpen`
|
|
196
|
-
// state or an inherited parent setter), wrap it so opening the modal on
|
|
197
|
-
// mobile also closes the drawer.
|
|
198
|
-
//
|
|
199
|
-
// Note: this diverges from the React reference (CopilotChatConfigurationProvider.tsx),
|
|
200
|
-
// which keeps `setModalOpen` always-defined and always backed by internal state. We
|
|
201
|
-
// intentionally take the minimal Vue-local fix here — preserving the `undefined`
|
|
202
|
-
// contract CopilotChatToggleButton depends on — rather than also reworking
|
|
203
|
-
// `resolvedIsModalOpen`'s backing, to avoid changing bare-provider modal-open
|
|
204
|
-
// semantics.
|
|
205
|
-
const publicSetModalOpen = computed(() => {
|
|
206
|
-
const base = resolvedSetModalOpen.value; // undefined when no modal state + no parent
|
|
207
|
-
if (!base) return undefined;
|
|
208
|
-
return (open: boolean) => {
|
|
209
|
-
if (open && isMobileViewport()) {
|
|
210
|
-
resolvedSetDrawerOpen.value?.(false);
|
|
211
|
-
}
|
|
212
|
-
base(open);
|
|
213
|
-
};
|
|
214
75
|
});
|
|
215
76
|
|
|
216
77
|
const configurationValue = computed<CopilotChatConfigurationValue>(() => ({
|
|
217
78
|
labels: mergedLabels.value,
|
|
218
|
-
agentId:
|
|
219
|
-
threadId:
|
|
220
|
-
hasExplicitThreadId:
|
|
221
|
-
isModalOpen:
|
|
222
|
-
setModalOpen:
|
|
223
|
-
drawerOpen:
|
|
224
|
-
setDrawerOpen:
|
|
225
|
-
drawerRegistered:
|
|
226
|
-
registerDrawer:
|
|
227
|
-
setActiveThreadId,
|
|
228
|
-
startNewThread,
|
|
79
|
+
agentId: snapshot.value.agentId,
|
|
80
|
+
threadId: snapshot.value.threadId,
|
|
81
|
+
hasExplicitThreadId: snapshot.value.hasExplicitThreadId,
|
|
82
|
+
isModalOpen: snapshot.value.isModalOpen,
|
|
83
|
+
setModalOpen: store.setModalOpen,
|
|
84
|
+
drawerOpen: snapshot.value.drawerOpen,
|
|
85
|
+
setDrawerOpen: store.setDrawerOpen,
|
|
86
|
+
drawerRegistered: snapshot.value.drawerRegistered,
|
|
87
|
+
registerDrawer: store.registerDrawer,
|
|
88
|
+
setActiveThreadId: store.setActiveThreadId,
|
|
89
|
+
startNewThread: store.startNewThread,
|
|
229
90
|
}));
|
|
230
91
|
|
|
231
92
|
provide(CopilotChatConfigurationKey, configurationValue);
|
|
93
|
+
provide(ChatConfigurationStoreKey, store);
|
|
232
94
|
</script>
|
|
233
95
|
|
|
234
96
|
<template>
|