@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.
- package/AGENTS.md +50 -0
- package/CHANGELOG.md +13 -0
- package/PARITY.md +434 -0
- package/README.md +396 -0
- package/dist/components/copilot-provider/CopilotKit.vue.d.ts +20 -0
- package/dist/components/copilot-provider/CopilotKit.vue.d.ts.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +3 -0
- package/dist/components/copilot-provider/index.d.ts.map +1 -0
- package/dist/components/copilot-provider/types.d.ts +22 -0
- package/dist/components/copilot-provider/types.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +27 -0
- package/dist/hooks/use-copilot-action.d.ts.map +1 -0
- package/dist/hooks/use-copilot-readable.d.ts +20 -0
- package/dist/hooks/use-copilot-readable.d.ts.map +1 -0
- package/dist/hooks/use-frontend-tool.d.ts +21 -0
- package/dist/hooks/use-frontend-tool.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +252 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +2 -0
- package/dist/use-render-activity-message-BRL1Rpl-.cjs +85 -0
- package/dist/use-render-activity-message-BRL1Rpl-.cjs.map +1 -0
- package/dist/use-render-activity-message-CqtxiFSs.js +8927 -0
- package/dist/use-render-activity-message-CqtxiFSs.js.map +1 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts +9 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -0
- package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts +16 -0
- package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts +7 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -0
- package/dist/v2/components/InlineFeatureWarning.vue.d.ts +6 -0
- package/dist/v2/components/InlineFeatureWarning.vue.d.ts.map +1 -0
- package/dist/v2/components/LicenseWarningBanner.vue.d.ts +18 -0
- package/dist/v2/components/LicenseWarningBanner.vue.d.ts.map +1 -0
- package/dist/v2/components/MCPAppsActivityRenderer.d.ts +88 -0
- package/dist/v2/components/MCPAppsActivityRenderer.d.ts.map +1 -0
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +154 -0
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -0
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +19 -0
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -0
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +16 -0
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -0
- package/dist/v2/components/a2ui/VueSurface.d.ts +62 -0
- package/dist/v2/components/a2ui/VueSurface.d.ts.map +1 -0
- package/dist/v2/components/a2ui/adapter.d.ts +38 -0
- package/dist/v2/components/a2ui/adapter.d.ts.map +1 -0
- package/dist/v2/components/a2ui/catalog.d.ts +29 -0
- package/dist/v2/components/a2ui/catalog.d.ts.map +1 -0
- package/dist/v2/components/a2ui/index.d.ts +5 -0
- package/dist/v2/components/a2ui/index.d.ts.map +1 -0
- package/dist/v2/components/a2ui/utils.d.ts +18 -0
- package/dist/v2/components/a2ui/utils.d.ts.map +1 -0
- package/dist/v2/components/a2ui.d.ts +12 -0
- package/dist/v2/components/a2ui.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChat.vue.d.ts +50 -0
- package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +164 -0
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts +12 -0
- package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts +7 -0
- package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts +12 -0
- package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +290 -0
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +72 -0
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts +65 -0
- package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts +27 -0
- package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts +26 -0
- package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts +17 -0
- package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToggleButtonCloseIcon.d.ts +5 -0
- package/dist/v2/components/chat/CopilotChatToggleButtonCloseIcon.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToggleButtonOpenIcon.d.ts +5 -0
- package/dist/v2/components/chat/CopilotChatToggleButtonOpenIcon.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +21 -0
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts +34 -0
- package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts +106 -0
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts +15 -0
- package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts +5 -0
- package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts +5 -0
- package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts +50 -0
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +55 -0
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +55 -0
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts +28 -0
- package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +48 -0
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +62 -0
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +53 -0
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts +28 -0
- package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/audioRecorder.d.ts +11 -0
- package/dist/v2/components/chat/audioRecorder.d.ts.map +1 -0
- package/dist/v2/components/chat/index.d.ts +682 -0
- package/dist/v2/components/chat/index.d.ts.map +1 -0
- package/dist/v2/components/chat/last-user-message-context.d.ts +29 -0
- package/dist/v2/components/chat/last-user-message-context.d.ts.map +1 -0
- package/dist/v2/components/chat/normalize-auto-scroll.d.ts +3 -0
- package/dist/v2/components/chat/normalize-auto-scroll.d.ts.map +1 -0
- package/dist/v2/components/chat/types.d.ts +380 -0
- package/dist/v2/components/chat/types.d.ts.map +1 -0
- package/dist/v2/components/icons/index.d.ts +2 -0
- package/dist/v2/components/icons/index.d.ts.map +1 -0
- package/dist/v2/components/index.d.ts +8 -0
- package/dist/v2/components/index.d.ts.map +1 -0
- package/dist/v2/hooks/index.d.ts +24 -0
- package/dist/v2/hooks/index.d.ts.map +1 -0
- package/dist/v2/hooks/use-agent-context.d.ts +24 -0
- package/dist/v2/hooks/use-agent-context.d.ts.map +1 -0
- package/dist/v2/hooks/use-agent.d.ts +53 -0
- package/dist/v2/hooks/use-agent.d.ts.map +1 -0
- package/dist/v2/hooks/use-attachments.d.ts +21 -0
- package/dist/v2/hooks/use-attachments.d.ts.map +1 -0
- package/dist/v2/hooks/use-capabilities.d.ts +16 -0
- package/dist/v2/hooks/use-capabilities.d.ts.map +1 -0
- package/dist/v2/hooks/use-component.d.ts +13 -0
- package/dist/v2/hooks/use-component.d.ts.map +1 -0
- package/dist/v2/hooks/use-configure-suggestions.d.ts +24 -0
- package/dist/v2/hooks/use-configure-suggestions.d.ts.map +1 -0
- package/dist/v2/hooks/use-default-render-tool.d.ts +14 -0
- package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -0
- package/dist/v2/hooks/use-frontend-tool.d.ts +19 -0
- package/dist/v2/hooks/use-frontend-tool.d.ts.map +1 -0
- package/dist/v2/hooks/use-human-in-the-loop.d.ts +19 -0
- package/dist/v2/hooks/use-human-in-the-loop.d.ts.map +1 -0
- package/dist/v2/hooks/use-interrupt.d.ts +36 -0
- package/dist/v2/hooks/use-interrupt.d.ts.map +1 -0
- package/dist/v2/hooks/use-katex-styles.d.ts +22 -0
- package/dist/v2/hooks/use-katex-styles.d.ts.map +1 -0
- package/dist/v2/hooks/use-keyboard-height.d.ts +33 -0
- package/dist/v2/hooks/use-keyboard-height.d.ts.map +1 -0
- package/dist/v2/hooks/use-pin-to-send.d.ts +28 -0
- package/dist/v2/hooks/use-pin-to-send.d.ts.map +1 -0
- package/dist/v2/hooks/use-render-activity-message.d.ts +21 -0
- package/dist/v2/hooks/use-render-activity-message.d.ts.map +1 -0
- package/dist/v2/hooks/use-render-custom-messages.d.ts +27 -0
- package/dist/v2/hooks/use-render-custom-messages.d.ts.map +1 -0
- package/dist/v2/hooks/use-render-tool.d.ts +36 -0
- package/dist/v2/hooks/use-render-tool.d.ts.map +1 -0
- package/dist/v2/hooks/use-suggestions.d.ts +26 -0
- package/dist/v2/hooks/use-suggestions.d.ts.map +1 -0
- package/dist/v2/hooks/use-threads.d.ts +42 -0
- package/dist/v2/hooks/use-threads.d.ts.map +1 -0
- package/dist/v2/index.cjs +2 -0
- package/dist/v2/index.cjs.map +1 -0
- package/dist/v2/index.d.cts +9 -0
- package/dist/v2/index.d.mts +9 -0
- package/dist/v2/index.d.ts +9 -0
- package/dist/v2/index.d.ts.map +1 -0
- package/dist/v2/index.mjs +75 -0
- package/dist/v2/index.mjs.map +1 -0
- package/dist/v2/lib/processPartialHtml.d.ts +3 -0
- package/dist/v2/lib/processPartialHtml.d.ts.map +1 -0
- package/dist/v2/lib/shallow-stable.d.ts +7 -0
- package/dist/v2/lib/shallow-stable.d.ts.map +1 -0
- package/dist/v2/lib/transcription-client.d.ts +19 -0
- package/dist/v2/lib/transcription-client.d.ts.map +1 -0
- package/dist/v2/lib/vue-core.d.ts +47 -0
- package/dist/v2/lib/vue-core.d.ts.map +1 -0
- package/dist/v2/providers/CopilotChatConfigurationProvider.types.d.ts +15 -0
- package/dist/v2/providers/CopilotChatConfigurationProvider.types.d.ts.map +1 -0
- package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts +17 -0
- package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -0
- package/dist/v2/providers/CopilotKitProvider.types.d.ts +61 -0
- package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -0
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts +37 -0
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -0
- package/dist/v2/providers/SandboxFunctionsContext.d.ts +4 -0
- package/dist/v2/providers/SandboxFunctionsContext.d.ts.map +1 -0
- package/dist/v2/providers/index.d.ts +13 -0
- package/dist/v2/providers/index.d.ts.map +1 -0
- package/dist/v2/providers/keys.d.ts +17 -0
- package/dist/v2/providers/keys.d.ts.map +1 -0
- package/dist/v2/providers/license-context.d.ts +7 -0
- package/dist/v2/providers/license-context.d.ts.map +1 -0
- package/dist/v2/providers/types.d.ts +38 -0
- package/dist/v2/providers/types.d.ts.map +1 -0
- package/dist/v2/providers/useCopilotChatConfiguration.d.ts +4 -0
- package/dist/v2/providers/useCopilotChatConfiguration.d.ts.map +1 -0
- package/dist/v2/providers/useCopilotKit.d.ts +2 -0
- package/dist/v2/providers/useCopilotKit.d.ts.map +1 -0
- package/dist/v2/providers/useLicenseContext.d.ts +14 -0
- package/dist/v2/providers/useLicenseContext.d.ts.map +1 -0
- package/dist/v2/types/a2ui.d.ts +5 -0
- package/dist/v2/types/a2ui.d.ts.map +1 -0
- package/dist/v2/types/defineToolCallRenderer.d.ts +15 -0
- package/dist/v2/types/defineToolCallRenderer.d.ts.map +1 -0
- package/dist/v2/types/frontend-tool.d.ts +6 -0
- package/dist/v2/types/frontend-tool.d.ts.map +1 -0
- package/dist/v2/types/human-in-the-loop.d.ts +29 -0
- package/dist/v2/types/human-in-the-loop.d.ts.map +1 -0
- package/dist/v2/types/index.d.ts +10 -0
- package/dist/v2/types/index.d.ts.map +1 -0
- package/dist/v2/types/interrupt.d.ts +14 -0
- package/dist/v2/types/interrupt.d.ts.map +1 -0
- package/dist/v2/types/sandbox-function.d.ts +8 -0
- package/dist/v2/types/sandbox-function.d.ts.map +1 -0
- package/dist/v2/types/vue-activity-message-renderer.d.ts +18 -0
- package/dist/v2/types/vue-activity-message-renderer.d.ts.map +1 -0
- package/dist/v2/types/vue-custom-message-renderer.d.ts +19 -0
- package/dist/v2/types/vue-custom-message-renderer.d.ts.map +1 -0
- package/dist/v2/types/vue-tool-call-renderer.d.ts +37 -0
- package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -0
- package/env.d.ts +7 -0
- package/eslint.config.mjs +42 -0
- package/package.json +130 -0
- package/scripts/scope-preflight.mjs +100 -0
- package/src/components/copilot-provider/CopilotKit.vue +18 -0
- package/src/components/copilot-provider/index.ts +2 -0
- package/src/components/copilot-provider/types.ts +24 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/use-copilot-action.ts +168 -0
- package/src/hooks/use-copilot-readable.ts +75 -0
- package/src/hooks/use-frontend-tool.ts +76 -0
- package/src/index.ts +12 -0
- package/src/styles/globals.css +314 -0
- package/src/v2/__tests__/exports.test.ts +35 -0
- package/src/v2/__tests__/mocks/web-inspector.ts +5 -0
- package/src/v2/__tests__/setup.ts +141 -0
- package/src/v2/__tests__/utils/agents.ts +391 -0
- package/src/v2/__tests__/utils/mount.ts +83 -0
- package/src/v2/__tests__/utils/test-helpers.ts +712 -0
- package/src/v2/components/A2UIMessageRenderer.ts +125 -0
- package/src/v2/components/A2UISurfaceActivityRenderer.vue +186 -0
- package/src/v2/components/CopilotKitInspector.vue +42 -0
- package/src/v2/components/InlineFeatureWarning.vue +35 -0
- package/src/v2/components/LicenseWarningBanner.vue +196 -0
- package/src/v2/components/MCPAppsActivityRenderer.ts +778 -0
- package/src/v2/components/OpenGenerativeUIRenderer.ts +550 -0
- package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +271 -0
- package/src/v2/components/__tests__/CopilotKitInspector.test.ts +57 -0
- package/src/v2/components/__tests__/MCPAppsActivityRenderer.e2e.test.ts +851 -0
- package/src/v2/components/__tests__/MCPAppsActivityRenderer.test.ts +237 -0
- package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +516 -0
- package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +295 -0
- package/src/v2/components/a2ui/A2UICatalogContext.ts +190 -0
- package/src/v2/components/a2ui/VueSurface.ts +144 -0
- package/src/v2/components/a2ui/adapter.ts +156 -0
- package/src/v2/components/a2ui/catalog.ts +858 -0
- package/src/v2/components/a2ui/index.ts +7 -0
- package/src/v2/components/a2ui/utils.ts +67 -0
- package/src/v2/components/a2ui.ts +30 -0
- package/src/v2/components/chat/CopilotChat.vue +777 -0
- package/src/v2/components/chat/CopilotChatAssistantMessage.vue +891 -0
- package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +411 -0
- package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +87 -0
- package/src/v2/components/chat/CopilotChatAudioRecorder.vue +269 -0
- package/src/v2/components/chat/CopilotChatInput.vue +1271 -0
- package/src/v2/components/chat/CopilotChatMessageView.vue +476 -0
- package/src/v2/components/chat/CopilotChatReasoningMessage.vue +247 -0
- package/src/v2/components/chat/CopilotChatSuggestionPill.vue +56 -0
- package/src/v2/components/chat/CopilotChatSuggestionView.vue +93 -0
- package/src/v2/components/chat/CopilotChatToggleButton.vue +145 -0
- package/src/v2/components/chat/CopilotChatToggleButtonCloseIcon.ts +17 -0
- package/src/v2/components/chat/CopilotChatToggleButtonOpenIcon.ts +18 -0
- package/src/v2/components/chat/CopilotChatToolCallsView.vue +161 -0
- package/src/v2/components/chat/CopilotChatUserMessage.vue +322 -0
- package/src/v2/components/chat/CopilotChatView.vue +740 -0
- package/src/v2/components/chat/CopilotModalHeader.vue +73 -0
- package/src/v2/components/chat/CopilotModalHeaderCloseButton.ts +38 -0
- package/src/v2/components/chat/CopilotModalHeaderTitle.ts +22 -0
- package/src/v2/components/chat/CopilotPopup.vue +182 -0
- package/src/v2/components/chat/CopilotPopupView.vue +168 -0
- package/src/v2/components/chat/CopilotPopupViewInternal.vue +453 -0
- package/src/v2/components/chat/CopilotPopupWelcomeScreen.vue +140 -0
- package/src/v2/components/chat/CopilotSidebar.vue +178 -0
- package/src/v2/components/chat/CopilotSidebarView.vue +172 -0
- package/src/v2/components/chat/CopilotSidebarViewInternal.vue +366 -0
- package/src/v2/components/chat/CopilotSidebarWelcomeScreen.vue +142 -0
- package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.ts +237 -0
- package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.ts +1240 -0
- package/src/v2/components/chat/__tests__/CopilotChat.licenseWarning.test.ts +138 -0
- package/src/v2/components/chat/__tests__/CopilotChat.onError.test.ts +85 -0
- package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.ts +141 -0
- package/src/v2/components/chat/__tests__/CopilotChat.test.ts +652 -0
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +683 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.ts +768 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.ts +1108 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.ts +87 -0
- package/src/v2/components/chat/__tests__/CopilotChatAttachmentQueue.test.ts +277 -0
- package/src/v2/components/chat/__tests__/CopilotChatAttachmentRenderer.test.ts +124 -0
- package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.ts +230 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.bottomAnchored.test.ts +83 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.ts +1139 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +1051 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.ts +141 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.ts +494 -0
- package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.ts +181 -0
- package/src/v2/components/chat/__tests__/CopilotChatReasoningMessage.test.ts +73 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionPill.test.ts +73 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.ts +674 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.test.ts +91 -0
- package/src/v2/components/chat/__tests__/CopilotChatToggleButton.test.ts +93 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolCallsView.test.ts +382 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.ts +1019 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.ts +516 -0
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.ts +701 -0
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.test.ts +337 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.ts +135 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.ts +278 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.ts +1082 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.ts +166 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.ts +1145 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.test.ts +374 -0
- package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.ts +636 -0
- package/src/v2/components/chat/__tests__/CopilotModalHeader.test.ts +112 -0
- package/src/v2/components/chat/__tests__/CopilotPopup.test.ts +58 -0
- package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.ts +725 -0
- package/src/v2/components/chat/__tests__/CopilotPopupView.test.ts +112 -0
- package/src/v2/components/chat/__tests__/CopilotSidebar.test.ts +58 -0
- package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.ts +603 -0
- package/src/v2/components/chat/__tests__/CopilotSidebarView.test.ts +214 -0
- package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.ts +394 -0
- package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.ts +82 -0
- package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +39 -0
- package/src/v2/components/chat/audioRecorder.ts +15 -0
- package/src/v2/components/chat/index.ts +52 -0
- package/src/v2/components/chat/last-user-message-context.ts +39 -0
- package/src/v2/components/chat/normalize-auto-scroll.ts +17 -0
- package/src/v2/components/chat/types.ts +481 -0
- package/src/v2/components/icons/__tests__/icons.test.ts +86 -0
- package/src/v2/components/icons/index.ts +22 -0
- package/src/v2/components/index.ts +7 -0
- package/src/v2/hooks/__tests__/standard-schema-types.test.ts +149 -0
- package/src/v2/hooks/__tests__/standard-schema.test.ts +315 -0
- package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.ts +144 -0
- package/src/v2/hooks/__tests__/use-agent-context.test.ts +271 -0
- package/src/v2/hooks/__tests__/use-agent-error-state.test.ts +64 -0
- package/src/v2/hooks/__tests__/use-agent-stability.test.ts +268 -0
- package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.ts +433 -0
- package/src/v2/hooks/__tests__/use-agent-throttle.test.ts +747 -0
- package/src/v2/hooks/__tests__/use-agent.e2e.test.ts +187 -0
- package/src/v2/hooks/__tests__/use-agent.test.ts +126 -0
- package/src/v2/hooks/__tests__/use-attachments.test.ts +181 -0
- package/src/v2/hooks/__tests__/use-component.test.ts +145 -0
- package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.ts +527 -0
- package/src/v2/hooks/__tests__/use-configure-suggestions.test.ts +399 -0
- package/src/v2/hooks/__tests__/use-default-render-tool.test.ts +214 -0
- package/src/v2/hooks/__tests__/use-frontend-tool-available.test.ts +220 -0
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +2320 -0
- package/src/v2/hooks/__tests__/use-frontend-tool.test.ts +648 -0
- package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.ts +1379 -0
- package/src/v2/hooks/__tests__/use-human-in-the-loop.test.ts +282 -0
- package/src/v2/hooks/__tests__/use-interrupt.test.ts +345 -0
- package/src/v2/hooks/__tests__/use-katex-styles.test.ts +69 -0
- package/src/v2/hooks/__tests__/use-keyboard-height.test.ts +199 -0
- package/src/v2/hooks/__tests__/use-pin-to-send.test.ts +363 -0
- package/src/v2/hooks/__tests__/use-render-tool.test.ts +329 -0
- package/src/v2/hooks/__tests__/use-suggestions.e2e.test.ts +397 -0
- package/src/v2/hooks/__tests__/use-suggestions.test.ts +198 -0
- package/src/v2/hooks/__tests__/use-threads.test.ts +1041 -0
- package/src/v2/hooks/__tests__/zod-regression.test.ts +339 -0
- package/src/v2/hooks/index.ts +29 -0
- package/src/v2/hooks/use-agent-context.ts +55 -0
- package/src/v2/hooks/use-agent.ts +345 -0
- package/src/v2/hooks/use-attachments.ts +261 -0
- package/src/v2/hooks/use-capabilities.ts +30 -0
- package/src/v2/hooks/use-component.ts +46 -0
- package/src/v2/hooks/use-configure-suggestions.ts +252 -0
- package/src/v2/hooks/use-default-render-tool.ts +130 -0
- package/src/v2/hooks/use-frontend-tool.ts +68 -0
- package/src/v2/hooks/use-human-in-the-loop.ts +90 -0
- package/src/v2/hooks/use-interrupt.ts +257 -0
- package/src/v2/hooks/use-katex-styles.ts +44 -0
- package/src/v2/hooks/use-keyboard-height.ts +87 -0
- package/src/v2/hooks/use-pin-to-send.ts +160 -0
- package/src/v2/hooks/use-render-activity-message.ts +92 -0
- package/src/v2/hooks/use-render-custom-messages.ts +129 -0
- package/src/v2/hooks/use-render-tool.ts +128 -0
- package/src/v2/hooks/use-suggestions.ts +98 -0
- package/src/v2/hooks/use-threads.ts +208 -0
- package/src/v2/index.ts +11 -0
- package/src/v2/lib/__tests__/processPartialHtml.test.ts +84 -0
- package/src/v2/lib/__tests__/transcription-client.test.ts +65 -0
- package/src/v2/lib/processPartialHtml.ts +21 -0
- package/src/v2/lib/shallow-stable.ts +54 -0
- package/src/v2/lib/transcription-client.ts +151 -0
- package/src/v2/lib/vue-core.ts +161 -0
- package/src/v2/providers/CopilotChatConfigurationProvider.types.ts +15 -0
- package/src/v2/providers/CopilotChatConfigurationProvider.vue +95 -0
- package/src/v2/providers/CopilotKitProvider.types.ts +66 -0
- package/src/v2/providers/CopilotKitProvider.vue +653 -0
- package/src/v2/providers/SandboxFunctionsContext.ts +11 -0
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.ts +309 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.debug.test.ts +295 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.license.test.ts +110 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.ts +67 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.ts +901 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.ts +141 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.ts +871 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +603 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.ts +104 -0
- package/src/v2/providers/index.ts +21 -0
- package/src/v2/providers/keys.ts +25 -0
- package/src/v2/providers/license-context.ts +16 -0
- package/src/v2/providers/types.ts +40 -0
- package/src/v2/providers/useCopilotChatConfiguration.ts +11 -0
- package/src/v2/providers/useCopilotKit.ts +11 -0
- package/src/v2/providers/useLicenseContext.ts +21 -0
- package/src/v2/types/__tests__/defineToolCallRenderer.test.ts +157 -0
- package/src/v2/types/a2ui.ts +5 -0
- package/src/v2/types/defineToolCallRenderer.ts +32 -0
- package/src/v2/types/frontend-tool.ts +8 -0
- package/src/v2/types/human-in-the-loop.ts +38 -0
- package/src/v2/types/index.ts +9 -0
- package/src/v2/types/interrupt.ts +15 -0
- package/src/v2/types/sandbox-function.ts +8 -0
- package/src/v2/types/vue-activity-message-renderer.ts +22 -0
- package/src/v2/types/vue-custom-message-renderer.ts +24 -0
- package/src/v2/types/vue-tool-call-renderer.ts +44 -0
- package/tsconfig.json +27 -0
- package/vite.config.ts +49 -0
- package/vitest.config.ts +23 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import { computed, defineComponent, h, onBeforeUnmount, ref, watch } from "vue";
|
|
2
|
+
import type { PropType } from "vue";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import type { AbstractAgent, RunAgentResult } from "@ag-ui/client";
|
|
5
|
+
import { randomUUID } from "@copilotkit/shared";
|
|
6
|
+
import type { VueActivityMessageRendererProps } from "../types";
|
|
7
|
+
import { useCopilotKit } from "../providers/useCopilotKit";
|
|
8
|
+
|
|
9
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
10
|
+
|
|
11
|
+
function buildSandboxHTML(extraCspDomains?: string[]): string {
|
|
12
|
+
const baseScriptSrc =
|
|
13
|
+
"'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
14
|
+
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
15
|
+
const extra = extraCspDomains?.length ? ` ${extraCspDomains.join(" ")}` : "";
|
|
16
|
+
const scriptSrc = `${baseScriptSrc}${extra}`;
|
|
17
|
+
const frameSrc = `${baseFrameSrc}${extra}`;
|
|
18
|
+
|
|
19
|
+
return `<!doctype html>
|
|
20
|
+
<html>
|
|
21
|
+
<head>
|
|
22
|
+
<meta charset="utf-8" />
|
|
23
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${scriptSrc}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${frameSrc}; base-uri 'self';" />
|
|
24
|
+
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<script>
|
|
28
|
+
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
29
|
+
const inner=document.createElement("iframe");
|
|
30
|
+
inner.style="width:100%;height:100%;border:none;";
|
|
31
|
+
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
32
|
+
document.body.appendChild(inner);
|
|
33
|
+
window.addEventListener("message",async(event)=>{
|
|
34
|
+
if(event.source===window.parent){
|
|
35
|
+
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
36
|
+
const{html,sandbox}=event.data.params;
|
|
37
|
+
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
38
|
+
if(typeof html==="string")inner.srcdoc=html;
|
|
39
|
+
}else if(inner&&inner.contentWindow){
|
|
40
|
+
inner.contentWindow.postMessage(event.data,"*");
|
|
41
|
+
}
|
|
42
|
+
}else if(event.source===inner.contentWindow){
|
|
43
|
+
window.parent.postMessage(event.data,"*");
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
47
|
+
</script>
|
|
48
|
+
</body>
|
|
49
|
+
</html>`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class MCPAppsRequestQueue {
|
|
53
|
+
private queues = new Map<
|
|
54
|
+
string,
|
|
55
|
+
Array<{
|
|
56
|
+
execute: () => Promise<RunAgentResult>;
|
|
57
|
+
resolve: (result: RunAgentResult) => void;
|
|
58
|
+
reject: (error: Error) => void;
|
|
59
|
+
}>
|
|
60
|
+
>();
|
|
61
|
+
|
|
62
|
+
private processing = new Map<string, boolean>();
|
|
63
|
+
|
|
64
|
+
async enqueue(
|
|
65
|
+
agent: AbstractAgent,
|
|
66
|
+
request: () => Promise<RunAgentResult>,
|
|
67
|
+
): Promise<RunAgentResult> {
|
|
68
|
+
const threadId = agent.threadId || "default";
|
|
69
|
+
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
let queue = this.queues.get(threadId);
|
|
72
|
+
if (!queue) {
|
|
73
|
+
queue = [];
|
|
74
|
+
this.queues.set(threadId, queue);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
queue.push({ execute: request, resolve, reject });
|
|
78
|
+
void this.processQueue(threadId, agent);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async processQueue(
|
|
83
|
+
threadId: string,
|
|
84
|
+
agent: AbstractAgent,
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
if (this.processing.get(threadId)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.processing.set(threadId, true);
|
|
91
|
+
try {
|
|
92
|
+
const queue = this.queues.get(threadId);
|
|
93
|
+
if (!queue) return;
|
|
94
|
+
|
|
95
|
+
while (queue.length > 0) {
|
|
96
|
+
const item = queue[0]!;
|
|
97
|
+
try {
|
|
98
|
+
await this.waitForAgentIdle(agent);
|
|
99
|
+
const result = await item.execute();
|
|
100
|
+
item.resolve(result);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
item.reject(
|
|
103
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
queue.shift();
|
|
107
|
+
}
|
|
108
|
+
} finally {
|
|
109
|
+
this.processing.set(threadId, false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
cancel(threadId: string): void {
|
|
114
|
+
const queue = this.queues.get(threadId);
|
|
115
|
+
if (queue) {
|
|
116
|
+
for (const item of queue) {
|
|
117
|
+
item.reject(new Error("MCPAppsRequestQueue cancelled on unmount"));
|
|
118
|
+
}
|
|
119
|
+
queue.length = 0;
|
|
120
|
+
}
|
|
121
|
+
this.queues.delete(threadId);
|
|
122
|
+
this.processing.delete(threadId);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private waitForAgentIdle(agent: AbstractAgent): Promise<void> {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
if (!agent.isRunning) {
|
|
128
|
+
resolve();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let done = false;
|
|
133
|
+
|
|
134
|
+
const timeout = setTimeout(() => {
|
|
135
|
+
if (done) return;
|
|
136
|
+
done = true;
|
|
137
|
+
clearInterval(checkInterval);
|
|
138
|
+
sub.unsubscribe();
|
|
139
|
+
reject(
|
|
140
|
+
new Error(
|
|
141
|
+
"[CopilotKit] Timed out waiting for agent to become idle",
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
}, 30_000);
|
|
145
|
+
|
|
146
|
+
const finish = () => {
|
|
147
|
+
if (done) return;
|
|
148
|
+
done = true;
|
|
149
|
+
clearTimeout(timeout);
|
|
150
|
+
clearInterval(checkInterval);
|
|
151
|
+
sub.unsubscribe();
|
|
152
|
+
resolve();
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const sub = agent.subscribe({
|
|
156
|
+
onRunFinalized: finish,
|
|
157
|
+
onRunFailed: finish,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const checkInterval = setInterval(() => {
|
|
161
|
+
if (!agent.isRunning) {
|
|
162
|
+
finish();
|
|
163
|
+
}
|
|
164
|
+
}, 500);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const mcpAppsRequestQueue = new MCPAppsRequestQueue();
|
|
170
|
+
|
|
171
|
+
export const MCPAppsActivityType = "mcp-apps";
|
|
172
|
+
|
|
173
|
+
export const MCPAppsActivityContentSchema = z.object({
|
|
174
|
+
result: z.object({
|
|
175
|
+
content: z.array(z.any()).optional(),
|
|
176
|
+
structuredContent: z.any().optional(),
|
|
177
|
+
isError: z.boolean().optional(),
|
|
178
|
+
}),
|
|
179
|
+
resourceUri: z.string(),
|
|
180
|
+
serverHash: z.string(),
|
|
181
|
+
serverId: z.string().optional(),
|
|
182
|
+
toolInput: z.record(z.unknown()).optional(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export type MCPAppsActivityContent = z.infer<
|
|
186
|
+
typeof MCPAppsActivityContentSchema
|
|
187
|
+
>;
|
|
188
|
+
|
|
189
|
+
interface FetchedResource {
|
|
190
|
+
uri: string;
|
|
191
|
+
mimeType?: string;
|
|
192
|
+
text?: string;
|
|
193
|
+
blob?: string;
|
|
194
|
+
_meta?: {
|
|
195
|
+
ui?: {
|
|
196
|
+
prefersBorder?: boolean;
|
|
197
|
+
csp?: {
|
|
198
|
+
connectDomains?: string[];
|
|
199
|
+
resourceDomains?: string[];
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface JSONRPCRequest {
|
|
206
|
+
jsonrpc: "2.0";
|
|
207
|
+
id: string | number;
|
|
208
|
+
method: string;
|
|
209
|
+
params?: Record<string, unknown>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
interface JSONRPCResponse {
|
|
213
|
+
jsonrpc: "2.0";
|
|
214
|
+
id: string | number;
|
|
215
|
+
result?: unknown;
|
|
216
|
+
error?: { code: number; message: string };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface JSONRPCNotification {
|
|
220
|
+
jsonrpc: "2.0";
|
|
221
|
+
method: string;
|
|
222
|
+
params?: Record<string, unknown>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
type JSONRPCMessage = JSONRPCRequest | JSONRPCResponse | JSONRPCNotification;
|
|
226
|
+
|
|
227
|
+
function isRequest(message: JSONRPCMessage): message is JSONRPCRequest {
|
|
228
|
+
return "id" in message && "method" in message;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function isNotification(
|
|
232
|
+
message: JSONRPCMessage,
|
|
233
|
+
): message is JSONRPCNotification {
|
|
234
|
+
return !("id" in message) && "method" in message;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export const MCPAppsActivityRenderer = defineComponent({
|
|
238
|
+
name: "MCPAppsActivityRenderer",
|
|
239
|
+
props: {
|
|
240
|
+
activityType: {
|
|
241
|
+
type: String,
|
|
242
|
+
required: true,
|
|
243
|
+
},
|
|
244
|
+
content: {
|
|
245
|
+
type: Object as PropType<MCPAppsActivityContent>,
|
|
246
|
+
required: true,
|
|
247
|
+
},
|
|
248
|
+
message: {
|
|
249
|
+
type: Object as PropType<
|
|
250
|
+
VueActivityMessageRendererProps<MCPAppsActivityContent>["message"]
|
|
251
|
+
>,
|
|
252
|
+
required: true,
|
|
253
|
+
},
|
|
254
|
+
agent: {
|
|
255
|
+
type: Object as PropType<AbstractAgent | undefined>,
|
|
256
|
+
required: false,
|
|
257
|
+
default: undefined,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
setup(props) {
|
|
261
|
+
const { copilotkit } = useCopilotKit();
|
|
262
|
+
const containerRef = ref<HTMLDivElement | null>(null);
|
|
263
|
+
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
264
|
+
const iframeReady = ref(false);
|
|
265
|
+
const error = ref<Error | null>(null);
|
|
266
|
+
const isLoading = ref(true);
|
|
267
|
+
const iframeSize = ref<{ width?: number; height?: number }>({});
|
|
268
|
+
const fetchedResource = ref<FetchedResource | null>(null);
|
|
269
|
+
|
|
270
|
+
const fetchStateRef = ref<{
|
|
271
|
+
inProgress: boolean;
|
|
272
|
+
promise: Promise<FetchedResource | null> | null;
|
|
273
|
+
resourceUri: string | null;
|
|
274
|
+
}>({
|
|
275
|
+
inProgress: false,
|
|
276
|
+
promise: null,
|
|
277
|
+
resourceUri: null,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const sendToIframe = (message: JSONRPCMessage) => {
|
|
281
|
+
if (iframeRef.value?.contentWindow) {
|
|
282
|
+
iframeRef.value.contentWindow.postMessage(message, "*");
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const sendResponse = (id: string | number, result: unknown) => {
|
|
287
|
+
sendToIframe({
|
|
288
|
+
jsonrpc: "2.0",
|
|
289
|
+
id,
|
|
290
|
+
result,
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const sendErrorResponse = (
|
|
295
|
+
id: string | number,
|
|
296
|
+
code: number,
|
|
297
|
+
message: string,
|
|
298
|
+
) => {
|
|
299
|
+
sendToIframe({
|
|
300
|
+
jsonrpc: "2.0",
|
|
301
|
+
id,
|
|
302
|
+
error: { code, message },
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const sendNotification = (
|
|
307
|
+
method: string,
|
|
308
|
+
params?: Record<string, unknown>,
|
|
309
|
+
) => {
|
|
310
|
+
sendToIframe({
|
|
311
|
+
jsonrpc: "2.0",
|
|
312
|
+
method,
|
|
313
|
+
params: params || {},
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
watch(
|
|
318
|
+
[() => props.agent, () => props.content],
|
|
319
|
+
([agent, content]) => {
|
|
320
|
+
isLoading.value = true;
|
|
321
|
+
error.value = null;
|
|
322
|
+
iframeReady.value = false;
|
|
323
|
+
iframeSize.value = {};
|
|
324
|
+
fetchedResource.value = null;
|
|
325
|
+
|
|
326
|
+
const { resourceUri, serverHash, serverId } = content;
|
|
327
|
+
|
|
328
|
+
if (
|
|
329
|
+
fetchStateRef.value.inProgress &&
|
|
330
|
+
fetchStateRef.value.resourceUri === resourceUri
|
|
331
|
+
) {
|
|
332
|
+
void fetchStateRef.value.promise
|
|
333
|
+
?.then((resource) => {
|
|
334
|
+
if (resource) {
|
|
335
|
+
fetchedResource.value = resource;
|
|
336
|
+
isLoading.value = false;
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
.catch((err: unknown) => {
|
|
340
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
341
|
+
isLoading.value = false;
|
|
342
|
+
});
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!agent) {
|
|
347
|
+
error.value = new Error("No agent available to fetch resource");
|
|
348
|
+
isLoading.value = false;
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
fetchStateRef.value.inProgress = true;
|
|
353
|
+
fetchStateRef.value.resourceUri = resourceUri;
|
|
354
|
+
|
|
355
|
+
const fetchPromise = (async (): Promise<FetchedResource | null> => {
|
|
356
|
+
try {
|
|
357
|
+
const runResult = await mcpAppsRequestQueue.enqueue(agent, () =>
|
|
358
|
+
agent.runAgent({
|
|
359
|
+
forwardedProps: {
|
|
360
|
+
__proxiedMCPRequest: {
|
|
361
|
+
serverHash,
|
|
362
|
+
serverId,
|
|
363
|
+
method: "resources/read",
|
|
364
|
+
params: { uri: resourceUri },
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const resultData = runResult.result as
|
|
371
|
+
| { contents?: FetchedResource[] }
|
|
372
|
+
| undefined;
|
|
373
|
+
const resource = resultData?.contents?.[0];
|
|
374
|
+
|
|
375
|
+
if (!resource) {
|
|
376
|
+
throw new Error("No resource content in response");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return resource;
|
|
380
|
+
} finally {
|
|
381
|
+
fetchStateRef.value.inProgress = false;
|
|
382
|
+
}
|
|
383
|
+
})();
|
|
384
|
+
|
|
385
|
+
fetchStateRef.value.promise = fetchPromise;
|
|
386
|
+
|
|
387
|
+
void fetchPromise
|
|
388
|
+
.then((resource) => {
|
|
389
|
+
if (resource) {
|
|
390
|
+
fetchedResource.value = resource;
|
|
391
|
+
isLoading.value = false;
|
|
392
|
+
}
|
|
393
|
+
})
|
|
394
|
+
.catch((err: unknown) => {
|
|
395
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
396
|
+
isLoading.value = false;
|
|
397
|
+
});
|
|
398
|
+
},
|
|
399
|
+
{ immediate: true },
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
watch(
|
|
403
|
+
[isLoading, fetchedResource],
|
|
404
|
+
([loading, resource], _old, onCleanup) => {
|
|
405
|
+
if (loading || !resource) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const container = containerRef.value;
|
|
410
|
+
if (!container) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let mounted = true;
|
|
415
|
+
let messageHandler: ((event: MessageEvent) => void) | null = null;
|
|
416
|
+
let initialListener: ((event: MessageEvent) => void) | null = null;
|
|
417
|
+
let createdIframe: HTMLIFrameElement | null = null;
|
|
418
|
+
|
|
419
|
+
const setup = async () => {
|
|
420
|
+
try {
|
|
421
|
+
const iframe = document.createElement("iframe");
|
|
422
|
+
createdIframe = iframe;
|
|
423
|
+
iframe.style.width = "100%";
|
|
424
|
+
iframe.style.height = "100px";
|
|
425
|
+
iframe.style.border = "none";
|
|
426
|
+
iframe.style.backgroundColor = "transparent";
|
|
427
|
+
iframe.style.display = "block";
|
|
428
|
+
iframe.setAttribute(
|
|
429
|
+
"sandbox",
|
|
430
|
+
"allow-scripts allow-same-origin allow-forms",
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
const sandboxReady = new Promise<void>((resolve) => {
|
|
434
|
+
initialListener = (event: MessageEvent) => {
|
|
435
|
+
if (
|
|
436
|
+
event.source === iframe.contentWindow &&
|
|
437
|
+
event.data?.method === "ui/notifications/sandbox-proxy-ready"
|
|
438
|
+
) {
|
|
439
|
+
if (initialListener) {
|
|
440
|
+
window.removeEventListener("message", initialListener);
|
|
441
|
+
initialListener = null;
|
|
442
|
+
}
|
|
443
|
+
resolve();
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
window.addEventListener("message", initialListener);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
if (!mounted) {
|
|
450
|
+
if (initialListener) {
|
|
451
|
+
window.removeEventListener("message", initialListener);
|
|
452
|
+
initialListener = null;
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const cspDomains =
|
|
458
|
+
fetchedResource.value?._meta?.ui?.csp?.resourceDomains;
|
|
459
|
+
iframe.srcdoc = buildSandboxHTML(cspDomains);
|
|
460
|
+
iframeRef.value = iframe;
|
|
461
|
+
container.appendChild(iframe);
|
|
462
|
+
|
|
463
|
+
await sandboxReady;
|
|
464
|
+
if (!mounted) return;
|
|
465
|
+
|
|
466
|
+
messageHandler = async (event: MessageEvent) => {
|
|
467
|
+
if (event.source !== iframe.contentWindow) return;
|
|
468
|
+
|
|
469
|
+
const msg = event.data as JSONRPCMessage;
|
|
470
|
+
if (!msg || typeof msg !== "object" || msg.jsonrpc !== "2.0") {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (isRequest(msg)) {
|
|
475
|
+
switch (msg.method) {
|
|
476
|
+
case "ui/initialize": {
|
|
477
|
+
sendResponse(msg.id, {
|
|
478
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
479
|
+
hostInfo: {
|
|
480
|
+
name: "CopilotKit MCP Apps Host",
|
|
481
|
+
version: "1.0.0",
|
|
482
|
+
},
|
|
483
|
+
hostCapabilities: {
|
|
484
|
+
openLinks: {},
|
|
485
|
+
logging: {},
|
|
486
|
+
},
|
|
487
|
+
hostContext: {
|
|
488
|
+
theme: "light",
|
|
489
|
+
platform: "web",
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
case "ui/message": {
|
|
496
|
+
const currentAgent = props.agent;
|
|
497
|
+
if (!currentAgent) {
|
|
498
|
+
sendResponse(msg.id, { isError: false });
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
const params = msg.params as
|
|
504
|
+
| {
|
|
505
|
+
role?: string;
|
|
506
|
+
content?: Array<{ type: string; text?: string }>;
|
|
507
|
+
followUp?: boolean;
|
|
508
|
+
}
|
|
509
|
+
| undefined;
|
|
510
|
+
|
|
511
|
+
const role =
|
|
512
|
+
(params?.role as "user" | "assistant") || "user";
|
|
513
|
+
const textContent =
|
|
514
|
+
params?.content
|
|
515
|
+
?.filter((part) => part.type === "text" && part.text)
|
|
516
|
+
.map((part) => part.text)
|
|
517
|
+
.join("\n") || "";
|
|
518
|
+
|
|
519
|
+
if (textContent) {
|
|
520
|
+
currentAgent.addMessage({
|
|
521
|
+
id: randomUUID(),
|
|
522
|
+
role,
|
|
523
|
+
content: textContent,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
sendResponse(msg.id, { isError: false });
|
|
528
|
+
|
|
529
|
+
const shouldFollowUp =
|
|
530
|
+
params?.followUp ?? role === "user";
|
|
531
|
+
if (shouldFollowUp && textContent) {
|
|
532
|
+
void mcpAppsRequestQueue
|
|
533
|
+
.enqueue(currentAgent, () =>
|
|
534
|
+
copilotkit.value.runAgent({ agent: currentAgent }),
|
|
535
|
+
)
|
|
536
|
+
.catch((err) => {
|
|
537
|
+
console.error(
|
|
538
|
+
"[MCPAppsRenderer] ui/message agent run failed:",
|
|
539
|
+
err,
|
|
540
|
+
);
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
} catch (err) {
|
|
544
|
+
console.error(
|
|
545
|
+
"[CopilotKit] MCPApps ui/message handler error:",
|
|
546
|
+
err,
|
|
547
|
+
);
|
|
548
|
+
sendResponse(msg.id, { isError: true });
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
case "ui/open-link": {
|
|
554
|
+
const url = msg.params?.url as string | undefined;
|
|
555
|
+
if (!url) {
|
|
556
|
+
sendErrorResponse(
|
|
557
|
+
msg.id,
|
|
558
|
+
-32602,
|
|
559
|
+
"Missing url parameter",
|
|
560
|
+
);
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
564
|
+
sendResponse(msg.id, { isError: false });
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
case "tools/call": {
|
|
569
|
+
const { serverHash, serverId } = props.content;
|
|
570
|
+
const currentAgent = props.agent;
|
|
571
|
+
|
|
572
|
+
if (!serverHash) {
|
|
573
|
+
sendErrorResponse(
|
|
574
|
+
msg.id,
|
|
575
|
+
-32603,
|
|
576
|
+
"No server hash available for proxying",
|
|
577
|
+
);
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
if (!currentAgent) {
|
|
581
|
+
sendErrorResponse(
|
|
582
|
+
msg.id,
|
|
583
|
+
-32603,
|
|
584
|
+
"No agent available for proxying",
|
|
585
|
+
);
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
try {
|
|
590
|
+
const runResult = await mcpAppsRequestQueue.enqueue(
|
|
591
|
+
currentAgent,
|
|
592
|
+
() =>
|
|
593
|
+
currentAgent.runAgent({
|
|
594
|
+
forwardedProps: {
|
|
595
|
+
__proxiedMCPRequest: {
|
|
596
|
+
serverHash,
|
|
597
|
+
serverId,
|
|
598
|
+
method: "tools/call",
|
|
599
|
+
params: msg.params,
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
}),
|
|
603
|
+
);
|
|
604
|
+
sendResponse(msg.id, runResult.result || {});
|
|
605
|
+
} catch (err) {
|
|
606
|
+
sendErrorResponse(msg.id, -32603, String(err));
|
|
607
|
+
}
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
default: {
|
|
612
|
+
sendErrorResponse(
|
|
613
|
+
msg.id,
|
|
614
|
+
-32601,
|
|
615
|
+
`Method not found: ${msg.method}`,
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (isNotification(msg)) {
|
|
622
|
+
switch (msg.method) {
|
|
623
|
+
case "ui/notifications/initialized":
|
|
624
|
+
if (mounted) {
|
|
625
|
+
iframeReady.value = true;
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
628
|
+
|
|
629
|
+
case "ui/notifications/size-changed": {
|
|
630
|
+
const { width, height } = msg.params || {};
|
|
631
|
+
if (mounted) {
|
|
632
|
+
iframeSize.value = {
|
|
633
|
+
width: typeof width === "number" ? width : undefined,
|
|
634
|
+
height: typeof height === "number" ? height : undefined,
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
window.addEventListener("message", messageHandler);
|
|
644
|
+
|
|
645
|
+
const html = resource.text
|
|
646
|
+
? resource.text
|
|
647
|
+
: resource.blob
|
|
648
|
+
? atob(resource.blob)
|
|
649
|
+
: null;
|
|
650
|
+
|
|
651
|
+
if (!html) {
|
|
652
|
+
throw new Error("Resource has no text or blob content");
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
sendNotification("ui/notifications/sandbox-resource-ready", {
|
|
656
|
+
html,
|
|
657
|
+
});
|
|
658
|
+
} catch (err) {
|
|
659
|
+
if (mounted) {
|
|
660
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
void setup();
|
|
666
|
+
|
|
667
|
+
onCleanup(() => {
|
|
668
|
+
mounted = false;
|
|
669
|
+
if (initialListener) {
|
|
670
|
+
window.removeEventListener("message", initialListener);
|
|
671
|
+
initialListener = null;
|
|
672
|
+
}
|
|
673
|
+
if (messageHandler) {
|
|
674
|
+
window.removeEventListener("message", messageHandler);
|
|
675
|
+
}
|
|
676
|
+
if (createdIframe) {
|
|
677
|
+
createdIframe.remove();
|
|
678
|
+
createdIframe = null;
|
|
679
|
+
}
|
|
680
|
+
iframeRef.value = null;
|
|
681
|
+
});
|
|
682
|
+
},
|
|
683
|
+
{ flush: "post" },
|
|
684
|
+
);
|
|
685
|
+
|
|
686
|
+
watch(
|
|
687
|
+
iframeSize,
|
|
688
|
+
(size) => {
|
|
689
|
+
if (!iframeRef.value) return;
|
|
690
|
+
if (size.width !== undefined) {
|
|
691
|
+
iframeRef.value.style.minWidth = `min(${size.width}px, 100%)`;
|
|
692
|
+
iframeRef.value.style.width = "100%";
|
|
693
|
+
}
|
|
694
|
+
if (size.height !== undefined) {
|
|
695
|
+
iframeRef.value.style.height = `${size.height}px`;
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
{ deep: true },
|
|
699
|
+
);
|
|
700
|
+
|
|
701
|
+
watch(
|
|
702
|
+
[iframeReady, () => props.content.toolInput],
|
|
703
|
+
([ready, toolInput]) => {
|
|
704
|
+
if (ready && toolInput) {
|
|
705
|
+
sendNotification("ui/notifications/tool-input", {
|
|
706
|
+
arguments: toolInput,
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
{ deep: true },
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
watch(
|
|
714
|
+
[iframeReady, () => props.content.result],
|
|
715
|
+
([ready, result]) => {
|
|
716
|
+
if (ready && result) {
|
|
717
|
+
sendNotification(
|
|
718
|
+
"ui/notifications/tool-result",
|
|
719
|
+
result as Record<string, unknown>,
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
{ deep: true },
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
const borderStyle = computed(() => {
|
|
727
|
+
const prefersBorder = fetchedResource.value?._meta?.ui?.prefersBorder;
|
|
728
|
+
if (prefersBorder !== true) return {};
|
|
729
|
+
return {
|
|
730
|
+
borderRadius: "8px",
|
|
731
|
+
backgroundColor: "#f9f9f9",
|
|
732
|
+
border: "1px solid #e0e0e0",
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
onBeforeUnmount(() => {
|
|
737
|
+
const threadId = props.agent?.threadId || "default";
|
|
738
|
+
mcpAppsRequestQueue.cancel(threadId);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
return () =>
|
|
742
|
+
h(
|
|
743
|
+
"div",
|
|
744
|
+
{
|
|
745
|
+
ref: containerRef,
|
|
746
|
+
style: {
|
|
747
|
+
width: "100%",
|
|
748
|
+
height:
|
|
749
|
+
iframeSize.value.height !== undefined
|
|
750
|
+
? `${iframeSize.value.height}px`
|
|
751
|
+
: "auto",
|
|
752
|
+
minHeight: "100px",
|
|
753
|
+
overflow: "hidden",
|
|
754
|
+
position: "relative",
|
|
755
|
+
...borderStyle.value,
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
[
|
|
759
|
+
isLoading.value
|
|
760
|
+
? h(
|
|
761
|
+
"div",
|
|
762
|
+
{ style: { padding: "1rem", color: "#666" } },
|
|
763
|
+
"Loading...",
|
|
764
|
+
)
|
|
765
|
+
: null,
|
|
766
|
+
error.value
|
|
767
|
+
? h(
|
|
768
|
+
"div",
|
|
769
|
+
{ style: { color: "red", padding: "1rem" } },
|
|
770
|
+
`Error: ${error.value.message}`,
|
|
771
|
+
)
|
|
772
|
+
: null,
|
|
773
|
+
],
|
|
774
|
+
);
|
|
775
|
+
},
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
export default MCPAppsActivityRenderer;
|