@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,187 @@
|
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
import { screen, fireEvent, waitFor, cleanup } from "@testing-library/vue";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { EventType } from "@ag-ui/client";
|
|
5
|
+
import type { BaseEvent, RunAgentInput } from "@ag-ui/client";
|
|
6
|
+
import type { Observable } from "rxjs";
|
|
7
|
+
import {
|
|
8
|
+
MockStepwiseAgent,
|
|
9
|
+
renderWithCopilotKit,
|
|
10
|
+
runStartedEvent,
|
|
11
|
+
runFinishedEvent,
|
|
12
|
+
textChunkEvent,
|
|
13
|
+
testId,
|
|
14
|
+
} from "../../__tests__/utils/test-helpers";
|
|
15
|
+
import { useAgent } from "../use-agent";
|
|
16
|
+
import { useCopilotKit } from "../../providers/useCopilotKit";
|
|
17
|
+
import CopilotChat from "../../components/chat/CopilotChat.vue";
|
|
18
|
+
|
|
19
|
+
class StateCapturingMockAgent extends MockStepwiseAgent {
|
|
20
|
+
public lastRunInput?: RunAgentInput;
|
|
21
|
+
|
|
22
|
+
run(input: RunAgentInput): Observable<BaseEvent> {
|
|
23
|
+
this.lastRunInput = input;
|
|
24
|
+
return super.run(input);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
cleanup();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("useAgent e2e", () => {
|
|
33
|
+
describe("setState passes state to agent run", () => {
|
|
34
|
+
it("agent receives state set via setState when runAgent is called", async () => {
|
|
35
|
+
const agent = new StateCapturingMockAgent();
|
|
36
|
+
|
|
37
|
+
const StateTestComponent = defineComponent({
|
|
38
|
+
setup() {
|
|
39
|
+
const { agent: hookAgent } = useAgent();
|
|
40
|
+
const { copilotkit } = useCopilotKit();
|
|
41
|
+
|
|
42
|
+
const handleSetStateAndRun = async () => {
|
|
43
|
+
hookAgent.value.setState({ testKey: "testValue", counter: 42 });
|
|
44
|
+
await copilotkit.value.runAgent({ agent: hookAgent.value });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return { handleSetStateAndRun };
|
|
48
|
+
},
|
|
49
|
+
template: `
|
|
50
|
+
<button data-testid="trigger-btn" @click="handleSetStateAndRun">
|
|
51
|
+
Set State and Run
|
|
52
|
+
</button>
|
|
53
|
+
`,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
renderWithCopilotKit({
|
|
57
|
+
agent,
|
|
58
|
+
children: StateTestComponent,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const triggerBtn = await screen.findByTestId("trigger-btn");
|
|
62
|
+
await fireEvent.click(triggerBtn);
|
|
63
|
+
|
|
64
|
+
await waitFor(() => {
|
|
65
|
+
expect(agent.lastRunInput).toBeDefined();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await agent.emit(runStartedEvent());
|
|
69
|
+
await agent.emit(runFinishedEvent());
|
|
70
|
+
await agent.complete();
|
|
71
|
+
|
|
72
|
+
expect(agent.lastRunInput?.state).toEqual({
|
|
73
|
+
testKey: "testValue",
|
|
74
|
+
counter: 42,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("addMessage + runAgent displays in CopilotChat", () => {
|
|
80
|
+
it("messages added via useAgent show up in CopilotChat", async () => {
|
|
81
|
+
const agent = new MockStepwiseAgent();
|
|
82
|
+
|
|
83
|
+
const MessageTestComponent = defineComponent({
|
|
84
|
+
components: { CopilotChat },
|
|
85
|
+
setup() {
|
|
86
|
+
const { agent: hookAgent } = useAgent();
|
|
87
|
+
const { copilotkit } = useCopilotKit();
|
|
88
|
+
|
|
89
|
+
const handleAddMessageAndRun = async () => {
|
|
90
|
+
hookAgent.value.addMessage({
|
|
91
|
+
id: testId("user-msg"),
|
|
92
|
+
role: "user",
|
|
93
|
+
content: "Hello from useAgent!",
|
|
94
|
+
} as any);
|
|
95
|
+
await copilotkit.value.runAgent({ agent: hookAgent.value });
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return { handleAddMessageAndRun };
|
|
99
|
+
},
|
|
100
|
+
template: `
|
|
101
|
+
<div>
|
|
102
|
+
<button data-testid="send-btn" @click="handleAddMessageAndRun">
|
|
103
|
+
Send Message
|
|
104
|
+
</button>
|
|
105
|
+
<div style="height: 400px;">
|
|
106
|
+
<CopilotChat :welcome-screen="false" />
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
`,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
renderWithCopilotKit({
|
|
113
|
+
agent,
|
|
114
|
+
children: MessageTestComponent,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const sendBtn = await screen.findByTestId("send-btn");
|
|
118
|
+
await fireEvent.click(sendBtn);
|
|
119
|
+
|
|
120
|
+
await waitFor(() => {
|
|
121
|
+
expect(screen.getByText("Hello from useAgent!")).toBeDefined();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const responseId = testId("assistant-msg");
|
|
125
|
+
await agent.emit(runStartedEvent());
|
|
126
|
+
await agent.emit(
|
|
127
|
+
textChunkEvent(responseId, "Hello! I received your message."),
|
|
128
|
+
);
|
|
129
|
+
await agent.emit(runFinishedEvent());
|
|
130
|
+
await agent.complete();
|
|
131
|
+
|
|
132
|
+
await waitFor(() => {
|
|
133
|
+
expect(
|
|
134
|
+
screen.getByText("Hello! I received your message."),
|
|
135
|
+
).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe("run error lifecycle", () => {
|
|
141
|
+
it("updates useAgent subscribers when run ends with RUN_ERROR", async () => {
|
|
142
|
+
const agent = new MockStepwiseAgent();
|
|
143
|
+
|
|
144
|
+
const RunErrorStatusComponent = defineComponent({
|
|
145
|
+
setup() {
|
|
146
|
+
const { agent: hookAgent } = useAgent();
|
|
147
|
+
const { copilotkit } = useCopilotKit();
|
|
148
|
+
|
|
149
|
+
const handleRun = async () => {
|
|
150
|
+
await copilotkit.value.runAgent({ agent: hookAgent.value });
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return { hookAgent, handleRun };
|
|
154
|
+
},
|
|
155
|
+
template: `
|
|
156
|
+
<div>
|
|
157
|
+
<button data-testid="run-btn" @click="handleRun">Run</button>
|
|
158
|
+
<span data-testid="status">{{ hookAgent?.isRunning ? "running" : "idle" }}</span>
|
|
159
|
+
</div>
|
|
160
|
+
`,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
renderWithCopilotKit({
|
|
164
|
+
agent,
|
|
165
|
+
children: RunErrorStatusComponent,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(screen.getByTestId("status").textContent).toBe("idle");
|
|
169
|
+
|
|
170
|
+
await fireEvent.click(screen.getByTestId("run-btn"));
|
|
171
|
+
await agent.emit(runStartedEvent());
|
|
172
|
+
|
|
173
|
+
await waitFor(() => {
|
|
174
|
+
expect(screen.getByTestId("status").textContent).toBe("running");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await agent.emit({
|
|
178
|
+
type: EventType.RUN_ERROR,
|
|
179
|
+
} as BaseEvent);
|
|
180
|
+
await agent.complete();
|
|
181
|
+
|
|
182
|
+
await waitFor(() => {
|
|
183
|
+
expect(screen.getByTestId("status").textContent).toBe("idle");
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { defineComponent, h, nextTick, toRaw } from "vue";
|
|
3
|
+
import type { AbstractAgent, Message } from "@ag-ui/client";
|
|
4
|
+
import { randomUUID } from "@copilotkit/shared";
|
|
5
|
+
import { useAgent } from "../use-agent";
|
|
6
|
+
import { useCopilotKit } from "../../providers/useCopilotKit";
|
|
7
|
+
import { mountWithProvider } from "../../__tests__/utils/mount";
|
|
8
|
+
import { StateCapturingAgent } from "../../__tests__/utils/agents";
|
|
9
|
+
|
|
10
|
+
describe("useAgent", () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
console.warn = vi.fn();
|
|
13
|
+
console.error = vi.fn();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("returns local agent from agents__unsafe_dev_only", () => {
|
|
17
|
+
const mockAgent = new StateCapturingAgent([], "test-agent");
|
|
18
|
+
|
|
19
|
+
const Child = defineComponent({
|
|
20
|
+
setup() {
|
|
21
|
+
const { agent } = useAgent({ agentId: "test-agent" });
|
|
22
|
+
return () =>
|
|
23
|
+
h(
|
|
24
|
+
"span",
|
|
25
|
+
{ "data-testid": "agent-id" },
|
|
26
|
+
agent.value?.agentId ?? "none",
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const { wrapper } = mountWithProvider(() => h(Child), {
|
|
32
|
+
agents__unsafe_dev_only: {
|
|
33
|
+
"test-agent": mockAgent as unknown as AbstractAgent,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(wrapper.find("[data-testid=agent-id]").text()).toBe("test-agent");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("passes state set through useAgent into run input", async () => {
|
|
41
|
+
const mockAgent = new StateCapturingAgent(
|
|
42
|
+
[{ newMessages: [] }],
|
|
43
|
+
"test-agent",
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const Child = defineComponent({
|
|
47
|
+
setup() {
|
|
48
|
+
const { agent } = useAgent({ agentId: "test-agent" });
|
|
49
|
+
const { copilotkit } = useCopilotKit();
|
|
50
|
+
|
|
51
|
+
const runWithState = async () => {
|
|
52
|
+
toRaw(agent.value).setState({ testKey: "testValue", counter: 42 });
|
|
53
|
+
await copilotkit.value.runAgent({
|
|
54
|
+
agent: toRaw(agent.value) as AbstractAgent,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return () =>
|
|
59
|
+
h(
|
|
60
|
+
"button",
|
|
61
|
+
{ "data-testid": "run-state", onClick: runWithState },
|
|
62
|
+
"run",
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const { wrapper } = mountWithProvider(() => h(Child), {
|
|
68
|
+
agents__unsafe_dev_only: {
|
|
69
|
+
"test-agent": mockAgent as unknown as AbstractAgent,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await wrapper.find("[data-testid=run-state]").trigger("click");
|
|
74
|
+
await nextTick();
|
|
75
|
+
|
|
76
|
+
expect(mockAgent.state).toEqual({
|
|
77
|
+
testKey: "testValue",
|
|
78
|
+
counter: 42,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("passes messages added through useAgent into run input", async () => {
|
|
83
|
+
const mockAgent = new StateCapturingAgent(
|
|
84
|
+
[{ newMessages: [] }],
|
|
85
|
+
"test-agent",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const Child = defineComponent({
|
|
89
|
+
setup() {
|
|
90
|
+
const { agent } = useAgent({ agentId: "test-agent" });
|
|
91
|
+
const { copilotkit } = useCopilotKit();
|
|
92
|
+
|
|
93
|
+
const runWithMessage = async () => {
|
|
94
|
+
const userMessage: Message = {
|
|
95
|
+
id: randomUUID(),
|
|
96
|
+
role: "user",
|
|
97
|
+
content: "Hello from useAgent",
|
|
98
|
+
} as Message;
|
|
99
|
+
toRaw(agent.value).addMessage(userMessage);
|
|
100
|
+
await copilotkit.value.runAgent({
|
|
101
|
+
agent: toRaw(agent.value) as AbstractAgent,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return () =>
|
|
106
|
+
h(
|
|
107
|
+
"button",
|
|
108
|
+
{ "data-testid": "run-message", onClick: runWithMessage },
|
|
109
|
+
"run",
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const { wrapper } = mountWithProvider(() => h(Child), {
|
|
115
|
+
agents__unsafe_dev_only: {
|
|
116
|
+
"test-agent": mockAgent as unknown as AbstractAgent,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await wrapper.find("[data-testid=run-message]").trigger("click");
|
|
121
|
+
await nextTick();
|
|
122
|
+
|
|
123
|
+
const lastMessage = mockAgent.messages.find((m) => m.role === "user");
|
|
124
|
+
expect(lastMessage?.content).toBe("Hello from useAgent");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { nextTick, defineComponent, h, onUpdated, ref } from "vue";
|
|
2
|
+
import { render } from "@testing-library/vue";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import type {
|
|
5
|
+
AttachmentUploadError,
|
|
6
|
+
AttachmentsConfig,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
8
|
+
import { useAttachments } from "../use-attachments";
|
|
9
|
+
|
|
10
|
+
function createFile(name: string, size: number, type: string): File {
|
|
11
|
+
const content = new Uint8Array(size);
|
|
12
|
+
return new File([content], name, { type });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function mountHook(initialConfig: AttachmentsConfig | undefined) {
|
|
16
|
+
const config = ref<AttachmentsConfig | undefined>(initialConfig);
|
|
17
|
+
const trigger = ref(0);
|
|
18
|
+
let updateCount = 0;
|
|
19
|
+
let api: ReturnType<typeof useAttachments> | null = null;
|
|
20
|
+
|
|
21
|
+
render(
|
|
22
|
+
defineComponent({
|
|
23
|
+
setup() {
|
|
24
|
+
api = useAttachments({ config });
|
|
25
|
+
onUpdated(() => {
|
|
26
|
+
updateCount += 1;
|
|
27
|
+
});
|
|
28
|
+
return { trigger };
|
|
29
|
+
},
|
|
30
|
+
render() {
|
|
31
|
+
return h("div", String(this.trigger));
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const rerender = async () => {
|
|
37
|
+
trigger.value += 1;
|
|
38
|
+
await nextTick();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
config,
|
|
43
|
+
get api() {
|
|
44
|
+
if (!api) {
|
|
45
|
+
throw new Error("Hook harness was not initialized.");
|
|
46
|
+
}
|
|
47
|
+
return api;
|
|
48
|
+
},
|
|
49
|
+
get updateCount() {
|
|
50
|
+
return updateCount;
|
|
51
|
+
},
|
|
52
|
+
rerender,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("useAttachments", () => {
|
|
57
|
+
describe("referential stability", () => {
|
|
58
|
+
it("all actions are stable across rerenders with same config", async () => {
|
|
59
|
+
const harness = mountHook({ enabled: true, accept: "image/*" });
|
|
60
|
+
const first = harness.api;
|
|
61
|
+
|
|
62
|
+
await harness.rerender();
|
|
63
|
+
const second = harness.api;
|
|
64
|
+
|
|
65
|
+
expect(second.processFiles).toBe(first.processFiles);
|
|
66
|
+
expect(second.handleFileUpload).toBe(first.handleFileUpload);
|
|
67
|
+
expect(second.handleDragOver).toBe(first.handleDragOver);
|
|
68
|
+
expect(second.handleDragLeave).toBe(first.handleDragLeave);
|
|
69
|
+
expect(second.handleDrop).toBe(first.handleDrop);
|
|
70
|
+
expect(second.removeAttachment).toBe(first.removeAttachment);
|
|
71
|
+
expect(second.consumeAttachments).toBe(first.consumeAttachments);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("actions remain stable when config object identity changes", async () => {
|
|
75
|
+
const harness = mountHook({ enabled: true, accept: "image/*" });
|
|
76
|
+
const first = harness.api;
|
|
77
|
+
|
|
78
|
+
harness.config.value = { enabled: true, accept: "image/*" };
|
|
79
|
+
await harness.rerender();
|
|
80
|
+
const second = harness.api;
|
|
81
|
+
|
|
82
|
+
expect(second.processFiles).toBe(first.processFiles);
|
|
83
|
+
expect(second.handleFileUpload).toBe(first.handleFileUpload);
|
|
84
|
+
expect(second.handleDragOver).toBe(first.handleDragOver);
|
|
85
|
+
expect(second.handleDragLeave).toBe(first.handleDragLeave);
|
|
86
|
+
expect(second.handleDrop).toBe(first.handleDrop);
|
|
87
|
+
expect(second.removeAttachment).toBe(first.removeAttachment);
|
|
88
|
+
expect(second.consumeAttachments).toBe(first.consumeAttachments);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("refs are stable across rerenders", async () => {
|
|
92
|
+
const harness = mountHook(undefined);
|
|
93
|
+
const first = harness.api;
|
|
94
|
+
|
|
95
|
+
await harness.rerender();
|
|
96
|
+
const second = harness.api;
|
|
97
|
+
|
|
98
|
+
expect(second.fileInputRef).toBe(first.fileInputRef);
|
|
99
|
+
expect(second.containerRef).toBe(first.containerRef);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("re-render counting", () => {
|
|
104
|
+
it("does not re-render when consumeAttachments is called on empty queue", async () => {
|
|
105
|
+
const harness = mountHook(undefined);
|
|
106
|
+
const initialUpdateCount = harness.updateCount;
|
|
107
|
+
|
|
108
|
+
harness.api.consumeAttachments();
|
|
109
|
+
await nextTick();
|
|
110
|
+
|
|
111
|
+
expect(harness.updateCount).toBe(initialUpdateCount);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("does not re-render on repeated consumeAttachments for empty queue", async () => {
|
|
115
|
+
const harness = mountHook(undefined);
|
|
116
|
+
const initialUpdateCount = harness.updateCount;
|
|
117
|
+
|
|
118
|
+
harness.api.consumeAttachments();
|
|
119
|
+
harness.api.consumeAttachments();
|
|
120
|
+
harness.api.consumeAttachments();
|
|
121
|
+
await nextTick();
|
|
122
|
+
|
|
123
|
+
expect(harness.updateCount).toBe(initialUpdateCount);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("initial state", () => {
|
|
128
|
+
it("returns empty attachments and disabled by default", () => {
|
|
129
|
+
const harness = mountHook(undefined);
|
|
130
|
+
expect(harness.api.attachments.value).toEqual([]);
|
|
131
|
+
expect(harness.api.enabled.value).toBe(false);
|
|
132
|
+
expect(harness.api.dragOver.value).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("returns enabled when config.enabled is true", () => {
|
|
136
|
+
const harness = mountHook({ enabled: true });
|
|
137
|
+
expect(harness.api.enabled.value).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("consumeAttachments", () => {
|
|
142
|
+
it("returns an empty array when there are no attachments", () => {
|
|
143
|
+
const harness = mountHook(undefined);
|
|
144
|
+
expect(harness.api.consumeAttachments()).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("removeAttachment", () => {
|
|
149
|
+
it("is a no-op when the id does not exist", () => {
|
|
150
|
+
const harness = mountHook(undefined);
|
|
151
|
+
harness.api.removeAttachment("nonexistent");
|
|
152
|
+
expect(harness.api.attachments.value).toEqual([]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("latest config reads", () => {
|
|
157
|
+
it("stable actions still observe latest config", async () => {
|
|
158
|
+
const onUploadFailed = vi.fn<(error: AttachmentUploadError) => void>();
|
|
159
|
+
const harness = mountHook({
|
|
160
|
+
enabled: true,
|
|
161
|
+
accept: "image/*",
|
|
162
|
+
onUploadFailed,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const stableProcessFiles = harness.api.processFiles;
|
|
166
|
+
harness.config.value = {
|
|
167
|
+
enabled: true,
|
|
168
|
+
accept: "audio/*",
|
|
169
|
+
onUploadFailed,
|
|
170
|
+
};
|
|
171
|
+
await harness.rerender();
|
|
172
|
+
|
|
173
|
+
const imageFile = createFile("photo.png", 128, "image/png");
|
|
174
|
+
await stableProcessFiles([imageFile]);
|
|
175
|
+
|
|
176
|
+
expect(onUploadFailed).toHaveBeenCalledTimes(1);
|
|
177
|
+
expect(onUploadFailed.mock.calls[0][0].reason).toBe("invalid-type");
|
|
178
|
+
expect(onUploadFailed.mock.calls[0][0].message).toContain("audio/*");
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/vue";
|
|
2
|
+
import { defineComponent } from "vue";
|
|
3
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { useComponent } from "../use-component";
|
|
6
|
+
import { useFrontendTool } from "../use-frontend-tool";
|
|
7
|
+
|
|
8
|
+
vi.mock("../use-frontend-tool", () => ({
|
|
9
|
+
useFrontendTool: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const mockUseFrontendTool = useFrontendTool as ReturnType<typeof vi.fn>;
|
|
13
|
+
|
|
14
|
+
describe("useComponent", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("registers a component tool with generated default description", () => {
|
|
20
|
+
const DemoComponent = defineComponent({
|
|
21
|
+
props: {
|
|
22
|
+
city: { type: String, required: true },
|
|
23
|
+
},
|
|
24
|
+
template: `<div>{{ city }}</div>`,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const Harness = defineComponent({
|
|
28
|
+
setup() {
|
|
29
|
+
useComponent({
|
|
30
|
+
name: "showWeatherCard",
|
|
31
|
+
render: DemoComponent,
|
|
32
|
+
});
|
|
33
|
+
return {};
|
|
34
|
+
},
|
|
35
|
+
template: `<div />`,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
render(Harness);
|
|
39
|
+
|
|
40
|
+
expect(mockUseFrontendTool).toHaveBeenCalledTimes(1);
|
|
41
|
+
const [toolConfig] = mockUseFrontendTool.mock.calls[0] as [
|
|
42
|
+
{
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
expect(toolConfig.name).toBe("showWeatherCard");
|
|
49
|
+
expect(toolConfig.description).toContain(
|
|
50
|
+
'Use this tool to display the "showWeatherCard" component in the chat.',
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("appends custom description and forwards parameters, agentId, and deps", () => {
|
|
55
|
+
const weatherSchema = z.object({
|
|
56
|
+
city: z.string(),
|
|
57
|
+
unit: z.enum(["c", "f"]),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const DemoComponent = defineComponent({
|
|
61
|
+
props: {
|
|
62
|
+
city: { type: String, required: true },
|
|
63
|
+
},
|
|
64
|
+
template: `<div>{{ city }}</div>`,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const deps = ["v1"] as const;
|
|
68
|
+
|
|
69
|
+
const Harness = defineComponent({
|
|
70
|
+
setup() {
|
|
71
|
+
useComponent(
|
|
72
|
+
{
|
|
73
|
+
name: "showWeatherCard",
|
|
74
|
+
description: "Render a weather card for the selected city.",
|
|
75
|
+
parameters: weatherSchema,
|
|
76
|
+
render: DemoComponent,
|
|
77
|
+
agentId: "weather-agent",
|
|
78
|
+
},
|
|
79
|
+
deps as unknown as any[],
|
|
80
|
+
);
|
|
81
|
+
return {};
|
|
82
|
+
},
|
|
83
|
+
template: `<div />`,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
render(Harness);
|
|
87
|
+
|
|
88
|
+
expect(mockUseFrontendTool).toHaveBeenCalledTimes(1);
|
|
89
|
+
const [toolConfig, forwardedDeps] = mockUseFrontendTool.mock.calls[0] as [
|
|
90
|
+
{
|
|
91
|
+
description: string;
|
|
92
|
+
parameters: typeof weatherSchema;
|
|
93
|
+
agentId?: string;
|
|
94
|
+
},
|
|
95
|
+
unknown[],
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
expect(toolConfig.description).toContain(
|
|
99
|
+
'Use this tool to display the "showWeatherCard" component in the chat.',
|
|
100
|
+
);
|
|
101
|
+
expect(toolConfig.description).toContain(
|
|
102
|
+
"Render a weather card for the selected city.",
|
|
103
|
+
);
|
|
104
|
+
expect(toolConfig.parameters).toBe(weatherSchema);
|
|
105
|
+
expect(toolConfig.agentId).toBe("weather-agent");
|
|
106
|
+
expect(forwardedDeps).toBe(deps);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("creates a render function that passes args into the component", () => {
|
|
110
|
+
const DemoComponent = defineComponent({
|
|
111
|
+
props: {
|
|
112
|
+
city: { type: String, required: true },
|
|
113
|
+
},
|
|
114
|
+
template: `<div data-testid="city">{{ city }}</div>`,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const Harness = defineComponent({
|
|
118
|
+
setup() {
|
|
119
|
+
useComponent({
|
|
120
|
+
name: "showWeatherCard",
|
|
121
|
+
render: DemoComponent,
|
|
122
|
+
});
|
|
123
|
+
return {};
|
|
124
|
+
},
|
|
125
|
+
template: `<div />`,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
render(Harness);
|
|
129
|
+
|
|
130
|
+
const [toolConfig] = mockUseFrontendTool.mock.calls[0] as [
|
|
131
|
+
{
|
|
132
|
+
render: (props: { args: { city: string } }) => unknown;
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
const RenderHost = defineComponent({
|
|
137
|
+
setup() {
|
|
138
|
+
return () => toolConfig.render({ args: { city: "Paris" } });
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
render(RenderHost);
|
|
143
|
+
expect(screen.getByTestId("city").textContent).toBe("Paris");
|
|
144
|
+
});
|
|
145
|
+
});
|