@copilotkit/vue 2.0.0-rc.1 → 2.0.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PARITY.md +13 -12
- package/README.md +1 -2
- package/dist/components/copilot-provider/CopilotKit.vue.d.ts +3 -1
- package/dist/components/copilot-provider/CopilotKit.vue.d.ts.map +1 -1
- package/dist/hooks/use-copilot-action.d.ts.map +1 -1
- package/dist/hooks/use-frontend-tool.d.ts +1 -1
- package/dist/hooks/use-frontend-tool.d.ts.map +1 -1
- package/dist/hooks/zod-parameters.d.ts +14 -0
- package/dist/hooks/zod-parameters.d.ts.map +1 -0
- package/dist/index.cjs +1 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +384 -14275
- package/dist/index.mjs.map +1 -1
- package/dist/use-render-activity-message-2np7y4Qt.cjs +92 -0
- package/dist/use-render-activity-message-2np7y4Qt.cjs.map +1 -0
- package/dist/use-render-activity-message-D59E9t0x.js +18097 -0
- package/dist/use-render-activity-message-D59E9t0x.js.map +1 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts +7 -0
- package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -1
- package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -1
- package/dist/v2/components/LicenseWarningBanner.vue.d.ts.map +1 -1
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts +13 -45
- package/dist/v2/components/OpenGenerativeUIRenderer.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +11 -2
- package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts +1 -1
- package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -1
- package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts +144 -0
- package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts.map +1 -0
- package/dist/v2/components/a2ui.d.ts +3 -7
- package/dist/v2/components/a2ui.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChat.vue.d.ts +1 -0
- package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +3 -1
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAssistantToolbarButton.vue.d.ts +16 -0
- package/dist/v2/components/chat/CopilotChatAssistantToolbarButton.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts +22 -0
- package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +21 -232
- package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts +12 -0
- package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts +22 -0
- package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +20 -0
- package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts +32 -0
- package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +11 -1
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts +1 -0
- package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts +5 -0
- package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts +1 -0
- package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +1 -0
- package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +1 -0
- package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +2 -0
- package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +2 -0
- package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +2 -0
- package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts +0 -1
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -1
- package/dist/v2/components/chat/index.d.ts +17 -1
- package/dist/v2/components/chat/index.d.ts.map +1 -1
- package/dist/v2/components/chat/inspector-shortcuts.d.ts +12 -0
- package/dist/v2/components/chat/inspector-shortcuts.d.ts.map +1 -0
- package/dist/v2/components/chat/message-feedback.d.ts +89 -0
- package/dist/v2/components/chat/message-feedback.d.ts.map +1 -0
- package/dist/v2/components/chat/tool-call-capture.d.ts +39 -0
- package/dist/v2/components/chat/tool-call-capture.d.ts.map +1 -0
- package/dist/v2/components/chat/tool-call-display-context.d.ts +22 -0
- package/dist/v2/components/chat/tool-call-display-context.d.ts.map +1 -0
- package/dist/v2/components/chat/tool-call-group-parts.d.ts +131 -0
- package/dist/v2/components/chat/tool-call-group-parts.d.ts.map +1 -0
- package/dist/v2/components/chat/turn-work.d.ts +33 -0
- package/dist/v2/components/chat/turn-work.d.ts.map +1 -0
- package/dist/v2/components/chat/types.d.ts +104 -5
- package/dist/v2/components/chat/types.d.ts.map +1 -1
- package/dist/v2/components/chat/use-chat-labels.d.ts +8 -0
- package/dist/v2/components/chat/use-chat-labels.d.ts.map +1 -0
- package/dist/v2/components/chat/use-lightbox.d.ts +18 -0
- package/dist/v2/components/chat/use-lightbox.d.ts.map +1 -0
- package/dist/v2/components/icons/index.d.ts +968 -1
- package/dist/v2/components/icons/index.d.ts.map +1 -1
- package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts +55 -0
- package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts.map +1 -0
- package/dist/v2/components/ui/CopilotPopover.vue.d.ts +40 -0
- package/dist/v2/components/ui/CopilotPopover.vue.d.ts.map +1 -0
- package/dist/v2/components/ui/CopilotTooltip.vue.d.ts +37 -0
- package/dist/v2/components/ui/CopilotTooltip.vue.d.ts.map +1 -0
- package/dist/v2/components/ui/dropdown-menu.d.ts +14 -0
- package/dist/v2/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/v2/components/ui/floating.d.ts +84 -0
- package/dist/v2/components/ui/floating.d.ts.map +1 -0
- package/dist/v2/components/ui/presence.d.ts +9 -0
- package/dist/v2/components/ui/presence.d.ts.map +1 -0
- package/dist/v2/components/ui/use-id.d.ts +9 -0
- package/dist/v2/components/ui/use-id.d.ts.map +1 -0
- package/dist/v2/hooks/use-default-render-tool.d.ts +6 -0
- package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -1
- package/dist/v2/hooks/use-frontend-tool.d.ts +5 -0
- package/dist/v2/hooks/use-frontend-tool.d.ts.map +1 -1
- package/dist/v2/hooks/use-render-activity-message.d.ts +13 -9
- package/dist/v2/hooks/use-render-activity-message.d.ts.map +1 -1
- package/dist/v2/hooks/use-render-custom-messages.d.ts +5 -7
- package/dist/v2/hooks/use-render-custom-messages.d.ts.map +1 -1
- package/dist/v2/hooks/use-render-tool.d.ts +4 -0
- package/dist/v2/hooks/use-render-tool.d.ts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +3 -0
- package/dist/v2/index.d.mts +3 -0
- package/dist/v2/index.d.ts +3 -0
- package/dist/v2/index.d.ts.map +1 -1
- package/dist/v2/index.mjs +197 -197
- package/dist/v2/index.mjs.map +1 -1
- package/dist/v2/lib/message-feedback.d.ts +33 -0
- package/dist/v2/lib/message-feedback.d.ts.map +1 -0
- package/dist/v2/lib/processPartialHtml.d.ts +1 -2
- package/dist/v2/lib/processPartialHtml.d.ts.map +1 -1
- package/dist/v2/lib/vue-core.d.ts +0 -1
- package/dist/v2/lib/vue-core.d.ts.map +1 -1
- package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.types.d.ts +56 -6
- package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts +6 -2
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/index.d.ts +1 -1
- package/dist/v2/providers/index.d.ts.map +1 -1
- package/dist/v2/providers/keys.d.ts +8 -0
- package/dist/v2/providers/keys.d.ts.map +1 -1
- package/dist/v2/providers/types.d.ts +3 -37
- package/dist/v2/providers/types.d.ts.map +1 -1
- package/dist/v2/styles/CopilotKitStyles.d.ts +18 -0
- package/dist/v2/styles/CopilotKitStyles.d.ts.map +1 -0
- package/dist/v2/types/defineToolCallRenderer.d.ts +2 -0
- package/dist/v2/types/defineToolCallRenderer.d.ts.map +1 -1
- package/dist/v2/types/human-in-the-loop.d.ts +8 -29
- package/dist/v2/types/human-in-the-loop.d.ts.map +1 -1
- package/dist/v2/types/interrupt.d.ts +1 -22
- package/dist/v2/types/interrupt.d.ts.map +1 -1
- package/dist/v2/types/vue-activity-message-renderer.d.ts +16 -15
- package/dist/v2/types/vue-activity-message-renderer.d.ts.map +1 -1
- package/dist/v2/types/vue-custom-message-renderer.d.ts +7 -16
- package/dist/v2/types/vue-custom-message-renderer.d.ts.map +1 -1
- package/dist/v2/types/vue-tool-call-renderer.d.ts +16 -28
- package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -1
- package/package.json +14 -27
- package/src/__tests__/build-entries.test.ts +27 -0
- package/src/components/copilot-provider/CopilotKit.vue +4 -1
- package/src/hooks/__tests__/zod-parameters.test.ts +520 -0
- package/src/hooks/use-copilot-action.ts +2 -1
- package/src/hooks/use-frontend-tool.ts +3 -6
- package/src/hooks/zod-parameters.ts +162 -0
- package/src/v2/__tests__/exports.test.ts +4 -2
- package/src/v2/components/A2UIMessageRenderer.ts +56 -68
- package/src/v2/components/A2UISurfaceActivityRenderer.vue +11 -23
- package/src/v2/components/LicenseWarningBanner.vue +31 -15
- package/src/v2/components/OpenGenerativeUIRenderer.ts +51 -373
- package/src/v2/components/__tests__/A2UIBasicCatalogColors.test.ts +8 -9
- package/src/v2/components/__tests__/A2UICatalogContext.test.ts +1 -1
- package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +63 -36
- package/src/v2/components/__tests__/LicenseWarningBanner.test.ts +20 -0
- package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.ts +55 -6
- package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +15 -258
- package/src/v2/components/a2ui/A2UICatalogContext.ts +10 -102
- package/src/v2/components/a2ui/A2UIRecoveryStates.ts +444 -0
- package/src/v2/components/a2ui/__tests__/A2UIRecoveryStates.test.ts +175 -0
- package/src/v2/components/a2ui.ts +1 -1
- package/src/v2/components/chat/CopilotChat.vue +26 -40
- package/src/v2/components/chat/CopilotChatAssistantMessage.vue +267 -67
- package/src/v2/components/chat/CopilotChatAssistantToolbarButton.vue +46 -0
- package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +150 -173
- package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +77 -20
- package/src/v2/components/chat/CopilotChatAudioRecorder.vue +2 -2
- package/src/v2/components/chat/CopilotChatFeedbackCommentPopover.vue +240 -0
- package/src/v2/components/chat/CopilotChatInput.vue +250 -191
- package/src/v2/components/chat/CopilotChatInspectorButton.vue +331 -0
- package/src/v2/components/chat/CopilotChatLightbox.vue +105 -0
- package/src/v2/components/chat/CopilotChatMessageView.vue +262 -87
- package/src/v2/components/chat/CopilotChatReasoningMessage.vue +52 -35
- package/src/v2/components/chat/CopilotChatSuggestionPill.vue +5 -14
- package/src/v2/components/chat/CopilotChatSuggestionView.vue +1 -4
- package/src/v2/components/chat/CopilotChatToggleButton.vue +3 -9
- package/src/v2/components/chat/CopilotChatToggleButtonCloseIcon.ts +1 -1
- package/src/v2/components/chat/CopilotChatToggleButtonOpenIcon.ts +1 -1
- package/src/v2/components/chat/CopilotChatToolCallGroup.vue +353 -0
- package/src/v2/components/chat/CopilotChatToolCallItem.vue +24 -14
- package/src/v2/components/chat/CopilotChatToolCallsView.vue +194 -21
- package/src/v2/components/chat/CopilotChatUserMessage.vue +105 -42
- package/src/v2/components/chat/CopilotChatView.vue +37 -42
- package/src/v2/components/chat/CopilotChatWorkSummary.vue +111 -0
- package/src/v2/components/chat/CopilotModalHeader.vue +10 -8
- package/src/v2/components/chat/CopilotModalHeaderCloseButton.ts +7 -6
- package/src/v2/components/chat/CopilotModalHeaderTitle.ts +1 -4
- package/src/v2/components/chat/CopilotPopup.vue +3 -0
- package/src/v2/components/chat/CopilotPopupView.vue +1 -0
- package/src/v2/components/chat/CopilotPopupViewInternal.vue +9 -19
- package/src/v2/components/chat/CopilotPopupWelcomeScreen.vue +5 -8
- package/src/v2/components/chat/CopilotSidebar.vue +5 -0
- package/src/v2/components/chat/CopilotSidebarView.vue +2 -0
- package/src/v2/components/chat/CopilotSidebarViewInternal.vue +24 -17
- package/src/v2/components/chat/CopilotSidebarWelcomeScreen.vue +7 -10
- package/src/v2/components/chat/StreamingMarkdownDefault.vue +3 -5
- package/src/v2/components/chat/__tests__/CopilotChat.labels.test.ts +19 -4
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.ts +26 -9
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.inspector.test.ts +269 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.learningFeedback.test.ts +760 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.ts +3 -5
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.ts +2 -2
- package/src/v2/components/chat/__tests__/CopilotChatInput.addMenu.test.ts +328 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.ts +6 -3
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +55 -14
- package/src/v2/components/chat/__tests__/CopilotChatLightbox.test.ts +160 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.ts +247 -403
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.toolCallDisplay.test.ts +637 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionPill.test.ts +1 -1
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.ts +3 -1
- package/src/v2/components/chat/__tests__/CopilotChatToolCallsView.learning.test.ts +75 -0
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.attachments.test.ts +143 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.ts +5 -4
- package/src/v2/components/chat/__tests__/CopilotChatView.rootWidth.test.ts +7 -33
- package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.ts +1 -1
- package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.ts +3 -3
- package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.ts +126 -0
- package/src/v2/components/chat/__tests__/messageFeedbackDefaults.test.ts +33 -0
- package/src/v2/components/chat/__tests__/modalChatDisplayProps.test.ts +44 -0
- package/src/v2/components/chat/copilotChatToolCallItemRender.ts +3 -19
- package/src/v2/components/chat/index.ts +2 -1
- package/src/v2/components/chat/inspector-shortcuts.ts +34 -0
- package/src/v2/components/chat/message-feedback.ts +291 -0
- package/src/v2/components/chat/tool-call-capture.ts +55 -0
- package/src/v2/components/chat/tool-call-display-context.ts +28 -0
- package/src/v2/components/chat/tool-call-group-parts.ts +251 -0
- package/src/v2/components/chat/turn-work.ts +52 -0
- package/src/v2/components/chat/types.ts +114 -4
- package/src/v2/components/chat/use-chat-labels.ts +16 -0
- package/src/v2/components/chat/use-lightbox.ts +64 -0
- package/src/v2/components/icons/__tests__/icons.test.ts +72 -68
- package/src/v2/components/icons/index.ts +109 -23
- package/src/v2/components/ui/CopilotDropdownMenuContent.vue +465 -0
- package/src/v2/components/ui/CopilotPopover.vue +138 -0
- package/src/v2/components/ui/CopilotTooltip.vue +237 -0
- package/src/v2/components/ui/__tests__/CopilotTooltip.test.ts +168 -0
- package/src/v2/components/ui/dropdown-menu.ts +15 -0
- package/src/v2/components/ui/floating.ts +321 -0
- package/src/v2/components/ui/presence.ts +54 -0
- package/src/v2/components/ui/use-id.ts +16 -0
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +62 -1
- package/src/v2/hooks/__tests__/use-render-activity-message.test.ts +105 -0
- package/src/v2/hooks/__tests__/use-render-tool.test.ts +3 -6
- package/src/v2/hooks/__tests__/zod-regression.test.ts +5 -4
- package/src/v2/hooks/use-default-render-tool.ts +123 -62
- package/src/v2/hooks/use-frontend-tool.ts +10 -10
- package/src/v2/hooks/use-render-activity-message.ts +27 -48
- package/src/v2/hooks/use-render-custom-messages.ts +14 -35
- package/src/v2/hooks/use-render-tool.ts +8 -0
- package/src/v2/index.ts +3 -0
- package/src/v2/lib/__tests__/message-feedback.test.ts +152 -0
- package/src/v2/lib/message-feedback.ts +120 -0
- package/src/v2/lib/processPartialHtml.ts +6 -21
- package/src/v2/lib/vue-core.ts +3 -5
- package/src/v2/providers/CopilotChatConfigurationProvider.vue +29 -2
- package/src/v2/providers/CopilotKitProvider.types.ts +57 -5
- package/src/v2/providers/CopilotKitProvider.vue +177 -114
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.openThread.test.ts +69 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.a2ui.test.ts +1 -1
- package/src/v2/providers/__tests__/CopilotKitProvider.headersAtSendTime.test.ts +3 -3
- package/src/v2/providers/__tests__/CopilotKitProvider.learning.test.ts +536 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +17 -33
- package/src/v2/providers/index.ts +4 -1
- package/src/v2/providers/keys.ts +12 -0
- package/src/v2/providers/types.ts +3 -38
- package/src/v2/styles/CopilotKitStyles.ts +95 -0
- package/src/v2/styles/__tests__/CopilotKitStyles.client.test.ts +149 -0
- package/src/v2/styles/__tests__/CopilotKitStyles.ssr.test.ts +71 -0
- package/src/v2/types/__tests__/defineToolCallRenderer.test.ts +28 -33
- package/src/v2/types/defineToolCallRenderer.ts +9 -4
- package/src/v2/types/human-in-the-loop.ts +8 -32
- package/src/v2/types/interrupt.ts +7 -31
- package/src/v2/types/vue-activity-message-renderer.ts +24 -15
- package/src/v2/types/vue-custom-message-renderer.ts +12 -16
- package/src/v2/types/vue-tool-call-renderer.ts +23 -31
- package/vite.config.ts +5 -5
- package/dist/styles.css +0 -2
- package/dist/v2/components/chat/BasicMarkdown.vue.d.ts +0 -9
- package/dist/v2/components/chat/BasicMarkdown.vue.d.ts.map +0 -1
- package/dist/v2/lib/transcription-client.d.ts +0 -19
- package/dist/v2/lib/transcription-client.d.ts.map +0 -1
- package/scripts/scope-preflight.mjs +0 -100
- package/src/styles/globals.css +0 -233
- package/src/v2/components/chat/BasicMarkdown.vue +0 -158
- package/src/v2/components/chat/__tests__/BasicMarkdown.test.ts +0 -69
- package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -84
- package/src/v2/lib/__tests__/transcription-client.test.ts +0 -67
- package/src/v2/lib/transcription-client.ts +0 -151
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { Parameter } from "@copilotkit/shared";
|
|
4
|
+
import {
|
|
5
|
+
convertJsonSchemaToZodSchema,
|
|
6
|
+
getZodParameters,
|
|
7
|
+
} from "../zod-parameters";
|
|
8
|
+
|
|
9
|
+
describe("convertJsonSchemaToZodSchema", () => {
|
|
10
|
+
it("should convert a simple JSON schema to a Zod schema", () => {
|
|
11
|
+
const jsonSchema = {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
name: { type: "string" },
|
|
15
|
+
age: { type: "number" },
|
|
16
|
+
},
|
|
17
|
+
required: ["name", "age"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const expectedSchema = z.object({
|
|
21
|
+
name: z.string(),
|
|
22
|
+
age: z.number(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
26
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
27
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
28
|
+
|
|
29
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should convert a JSON schema with nested objects to a Zod schema", () => {
|
|
33
|
+
const jsonSchema = {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
name: { type: "string" },
|
|
37
|
+
address: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
street: { type: "string" },
|
|
41
|
+
city: { type: "string" },
|
|
42
|
+
},
|
|
43
|
+
required: ["street", "city"],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
required: ["name", "address"],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const expectedSchema = z.object({
|
|
50
|
+
name: z.string(),
|
|
51
|
+
address: z.object({
|
|
52
|
+
street: z.string(),
|
|
53
|
+
city: z.string(),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
58
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
59
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
60
|
+
|
|
61
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should convert a JSON schema with arrays to a Zod schema", () => {
|
|
65
|
+
const jsonSchema = {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
names: {
|
|
69
|
+
type: "array",
|
|
70
|
+
items: { type: "string" },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ["names"],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const expectedSchema = z.object({
|
|
77
|
+
names: z.array(z.string()),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
81
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
82
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
83
|
+
|
|
84
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should convert a JSON schema with optional properties to a Zod schema", () => {
|
|
88
|
+
const jsonSchema = {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
name: { type: "string" },
|
|
92
|
+
age: { type: "number", required: false },
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const expectedSchema = z
|
|
97
|
+
.object({
|
|
98
|
+
name: z.string().optional(),
|
|
99
|
+
age: z.number().optional(),
|
|
100
|
+
})
|
|
101
|
+
.optional();
|
|
102
|
+
|
|
103
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
104
|
+
|
|
105
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
106
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
107
|
+
|
|
108
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should convert a JSON schema with different types to a Zod schema", () => {
|
|
112
|
+
const jsonSchema = {
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: {
|
|
115
|
+
name: { type: "string" },
|
|
116
|
+
age: { type: "number" },
|
|
117
|
+
isAdmin: { type: "boolean" },
|
|
118
|
+
},
|
|
119
|
+
required: ["name", "age", "isAdmin"],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const expectedSchema = z.object({
|
|
123
|
+
name: z.string(),
|
|
124
|
+
age: z.number(),
|
|
125
|
+
isAdmin: z.boolean(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
129
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
130
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
131
|
+
|
|
132
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should handle edge case where JSON schema has no properties", () => {
|
|
136
|
+
const jsonSchema = {
|
|
137
|
+
type: "object",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const expectedSchema = z.object({});
|
|
141
|
+
|
|
142
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
143
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
144
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
145
|
+
|
|
146
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should preserve string enum constraints", () => {
|
|
150
|
+
const jsonSchema = {
|
|
151
|
+
type: "object",
|
|
152
|
+
properties: {
|
|
153
|
+
status: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "The status",
|
|
156
|
+
enum: ["todo", "done"],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
required: ["status"],
|
|
160
|
+
};
|
|
161
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
162
|
+
const statusSchema = (result as z.ZodObject<any>).shape.status;
|
|
163
|
+
expect(statusSchema).toBeInstanceOf(z.ZodEnum);
|
|
164
|
+
expect(statusSchema.options).toEqual(["todo", "done"]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("should handle null-union type ['string', 'null'] as nullable", () => {
|
|
168
|
+
const jsonSchema = {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: {
|
|
171
|
+
nickname: {
|
|
172
|
+
type: ["string", "null"],
|
|
173
|
+
description: "Optional nickname",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
required: ["nickname"],
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
180
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
181
|
+
|
|
182
|
+
// The nickname field should accept both string and null
|
|
183
|
+
expect(shape.nickname.safeParse("hello").success).toBe(true);
|
|
184
|
+
expect(shape.nickname.safeParse(null).success).toBe(true);
|
|
185
|
+
expect(shape.nickname.safeParse(42).success).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("should handle null-union type ['number', 'null'] as nullable number", () => {
|
|
189
|
+
const jsonSchema = {
|
|
190
|
+
type: "object",
|
|
191
|
+
properties: {
|
|
192
|
+
score: {
|
|
193
|
+
type: ["number", "null"],
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
required: ["score"],
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
200
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
201
|
+
|
|
202
|
+
expect(shape.score.safeParse(42).success).toBe(true);
|
|
203
|
+
expect(shape.score.safeParse(null).success).toBe(true);
|
|
204
|
+
expect(shape.score.safeParse("hello").success).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should handle edge case where JSON schema has no required properties", () => {
|
|
208
|
+
const jsonSchema = {
|
|
209
|
+
type: "object",
|
|
210
|
+
properties: {
|
|
211
|
+
name: { type: "string" },
|
|
212
|
+
age: { type: "number" },
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const expectedSchema = z
|
|
217
|
+
.object({
|
|
218
|
+
name: z.string().optional(),
|
|
219
|
+
age: z.number().optional(),
|
|
220
|
+
})
|
|
221
|
+
.optional();
|
|
222
|
+
|
|
223
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
224
|
+
const resultSchemaJson = z.toJSONSchema(result);
|
|
225
|
+
const expectedSchemaJson = z.toJSONSchema(expectedSchema);
|
|
226
|
+
|
|
227
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("should resolve non-circular $ref definitions correctly", () => {
|
|
231
|
+
const jsonSchema = {
|
|
232
|
+
type: "object",
|
|
233
|
+
properties: {
|
|
234
|
+
address: { $ref: "#/$defs/Address" },
|
|
235
|
+
},
|
|
236
|
+
required: ["address"],
|
|
237
|
+
$defs: {
|
|
238
|
+
Address: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
street: { type: "string", description: "Street name" },
|
|
242
|
+
city: { type: "string", description: "City name" },
|
|
243
|
+
},
|
|
244
|
+
required: ["street", "city"],
|
|
245
|
+
description: "A postal address",
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
251
|
+
const resultJson = z.toJSONSchema(result);
|
|
252
|
+
|
|
253
|
+
const expectedSchema = z.object({
|
|
254
|
+
address: z
|
|
255
|
+
.object({
|
|
256
|
+
street: z.string().describe("Street name"),
|
|
257
|
+
city: z.string().describe("City name"),
|
|
258
|
+
})
|
|
259
|
+
.describe("A postal address"),
|
|
260
|
+
});
|
|
261
|
+
const expectedJson = z.toJSONSchema(expectedSchema);
|
|
262
|
+
|
|
263
|
+
expect(resultJson).toStrictEqual(expectedJson);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("should handle circular $ref without crashing and return z.any()", () => {
|
|
267
|
+
// A schema where Node references itself — this would cause infinite
|
|
268
|
+
// recursion without cycle detection.
|
|
269
|
+
const jsonSchema = {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
root: { $ref: "#/$defs/Node" },
|
|
273
|
+
},
|
|
274
|
+
required: ["root"],
|
|
275
|
+
$defs: {
|
|
276
|
+
Node: {
|
|
277
|
+
type: "object",
|
|
278
|
+
properties: {
|
|
279
|
+
value: { type: "string", description: "Node value" },
|
|
280
|
+
child: { $ref: "#/$defs/Node" },
|
|
281
|
+
},
|
|
282
|
+
required: ["value"],
|
|
283
|
+
description: "A tree node",
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
289
|
+
|
|
290
|
+
// Must not throw or hang
|
|
291
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
292
|
+
expect(result).toBeDefined();
|
|
293
|
+
|
|
294
|
+
// The circular ref should have produced a console.warn
|
|
295
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
296
|
+
expect.stringContaining("Circular $ref detected"),
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// The top-level shape should still have a "root" key that is an object
|
|
300
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
301
|
+
expect(shape.root).toBeDefined();
|
|
302
|
+
|
|
303
|
+
// Inside root, "value" should be a string and "child" should be z.any()
|
|
304
|
+
// (child is optional since it's not in required[], so unwrap ZodOptional)
|
|
305
|
+
const rootShape = (shape.root as z.ZodObject<any>).shape;
|
|
306
|
+
expect(rootShape.value).toBeInstanceOf(z.ZodString);
|
|
307
|
+
const child = rootShape.child;
|
|
308
|
+
if (child instanceof z.ZodOptional) {
|
|
309
|
+
expect(child.unwrap()).toBeInstanceOf(z.ZodAny);
|
|
310
|
+
} else {
|
|
311
|
+
expect(child).toBeInstanceOf(z.ZodAny);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
warnSpy.mockRestore();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("should resolve the same $ref used by multiple sibling properties", () => {
|
|
318
|
+
// Two properties reference the same $def — the visited set must NOT
|
|
319
|
+
// mark the second usage as circular.
|
|
320
|
+
const jsonSchema = {
|
|
321
|
+
type: "object",
|
|
322
|
+
properties: {
|
|
323
|
+
billing: { $ref: "#/$defs/Address" },
|
|
324
|
+
shipping: { $ref: "#/$defs/Address" },
|
|
325
|
+
},
|
|
326
|
+
required: ["billing", "shipping"],
|
|
327
|
+
$defs: {
|
|
328
|
+
Address: {
|
|
329
|
+
type: "object",
|
|
330
|
+
properties: {
|
|
331
|
+
street: { type: "string", description: "Street" },
|
|
332
|
+
city: { type: "string", description: "City" },
|
|
333
|
+
},
|
|
334
|
+
required: ["street", "city"],
|
|
335
|
+
description: "An address",
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
341
|
+
|
|
342
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
343
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
344
|
+
|
|
345
|
+
// Both should be fully resolved objects, NOT z.any()
|
|
346
|
+
expect(shape.billing).toBeInstanceOf(z.ZodObject);
|
|
347
|
+
expect(shape.shipping).toBeInstanceOf(z.ZodObject);
|
|
348
|
+
|
|
349
|
+
// No circular-ref warning should have been emitted
|
|
350
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
351
|
+
|
|
352
|
+
warnSpy.mockRestore();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("should resolve a shared $ref used in different branches of a $ref chain", () => {
|
|
356
|
+
// Wrapper -> Container (via $ref) which has two children both using $ref to Leaf.
|
|
357
|
+
// Without set cloning, the second Leaf ref in Container would be wrongly flagged
|
|
358
|
+
// as circular because the first Leaf resolution already added it to the set.
|
|
359
|
+
const jsonSchema = {
|
|
360
|
+
type: "object",
|
|
361
|
+
properties: {
|
|
362
|
+
wrapper: { $ref: "#/$defs/Container" },
|
|
363
|
+
},
|
|
364
|
+
required: ["wrapper"],
|
|
365
|
+
$defs: {
|
|
366
|
+
Container: {
|
|
367
|
+
type: "object",
|
|
368
|
+
properties: {
|
|
369
|
+
first: { $ref: "#/$defs/Leaf" },
|
|
370
|
+
second: { $ref: "#/$defs/Leaf" },
|
|
371
|
+
},
|
|
372
|
+
required: ["first", "second"],
|
|
373
|
+
description: "A container with two leaves",
|
|
374
|
+
},
|
|
375
|
+
Leaf: {
|
|
376
|
+
type: "object",
|
|
377
|
+
properties: {
|
|
378
|
+
label: { type: "string", description: "Leaf label" },
|
|
379
|
+
},
|
|
380
|
+
required: ["label"],
|
|
381
|
+
description: "A leaf node",
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
387
|
+
|
|
388
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
389
|
+
const wrapperShape = (
|
|
390
|
+
(result as z.ZodObject<any>).shape.wrapper as z.ZodObject<any>
|
|
391
|
+
).shape;
|
|
392
|
+
|
|
393
|
+
// Both first and second should be fully resolved Leaf objects
|
|
394
|
+
expect(wrapperShape.first).toBeInstanceOf(z.ZodObject);
|
|
395
|
+
expect(wrapperShape.second).toBeInstanceOf(z.ZodObject);
|
|
396
|
+
|
|
397
|
+
// No circular-ref warning should have been emitted
|
|
398
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
399
|
+
|
|
400
|
+
warnSpy.mockRestore();
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("should handle anyOf with $ref variants", () => {
|
|
404
|
+
const jsonSchema = {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: {
|
|
407
|
+
pet: {
|
|
408
|
+
anyOf: [{ $ref: "#/$defs/Cat" }, { $ref: "#/$defs/Dog" }],
|
|
409
|
+
description: "A pet",
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
required: ["pet"],
|
|
413
|
+
$defs: {
|
|
414
|
+
Cat: {
|
|
415
|
+
type: "object",
|
|
416
|
+
properties: { meow: { type: "boolean" } },
|
|
417
|
+
required: ["meow"],
|
|
418
|
+
},
|
|
419
|
+
Dog: {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: { bark: { type: "boolean" } },
|
|
422
|
+
required: ["bark"],
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
428
|
+
expect(result).toBeDefined();
|
|
429
|
+
|
|
430
|
+
// Should produce a union inside the "pet" property
|
|
431
|
+
const petSchema = (result as z.ZodObject<any>).shape.pet;
|
|
432
|
+
expect(petSchema).toBeInstanceOf(z.ZodUnion);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("should handle integer type as z.number()", () => {
|
|
436
|
+
const jsonSchema = {
|
|
437
|
+
type: "object",
|
|
438
|
+
properties: {
|
|
439
|
+
count: { type: "integer", description: "A count" },
|
|
440
|
+
},
|
|
441
|
+
required: ["count"],
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
445
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
446
|
+
expect(shape.count).toBeInstanceOf(z.ZodNumber);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it("should handle null type", () => {
|
|
450
|
+
const jsonSchema = {
|
|
451
|
+
type: "object",
|
|
452
|
+
properties: {
|
|
453
|
+
empty: { type: "null", description: "Always null" },
|
|
454
|
+
},
|
|
455
|
+
required: ["empty"],
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
459
|
+
const shape = (result as z.ZodObject<any>).shape;
|
|
460
|
+
expect(shape.empty).toBeInstanceOf(z.ZodNull);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it("should warn and return z.any() for unsupported schema types", () => {
|
|
464
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
465
|
+
|
|
466
|
+
const jsonSchema = { type: "custom_unsupported" };
|
|
467
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
468
|
+
|
|
469
|
+
expect(result).toBeInstanceOf(z.ZodAny);
|
|
470
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
471
|
+
expect.stringContaining(
|
|
472
|
+
'Unsupported JSON schema type "custom_unsupported"',
|
|
473
|
+
),
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
warnSpy.mockRestore();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
describe("getZodParameters", () => {
|
|
481
|
+
it("returns an empty object schema without parameters", () => {
|
|
482
|
+
expect(z.toJSONSchema(getZodParameters(undefined))).toStrictEqual(
|
|
483
|
+
z.toJSONSchema(z.object({})),
|
|
484
|
+
);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("converts v1 parameters to a Zod object schema", () => {
|
|
488
|
+
const parameters: Parameter[] = [
|
|
489
|
+
{ name: "name", type: "string", description: "User name" },
|
|
490
|
+
{ name: "age", type: "number", required: false },
|
|
491
|
+
{ name: "role", type: "string", enum: ["admin", "user"] },
|
|
492
|
+
{
|
|
493
|
+
name: "address",
|
|
494
|
+
type: "object",
|
|
495
|
+
attributes: [{ name: "city", type: "string" }],
|
|
496
|
+
},
|
|
497
|
+
{ name: "tags", type: "string[]" },
|
|
498
|
+
];
|
|
499
|
+
|
|
500
|
+
const schema = getZodParameters(parameters);
|
|
501
|
+
|
|
502
|
+
expect(
|
|
503
|
+
schema.safeParse({
|
|
504
|
+
name: "Ada",
|
|
505
|
+
role: "admin",
|
|
506
|
+
address: { city: "London" },
|
|
507
|
+
tags: ["a"],
|
|
508
|
+
}).success,
|
|
509
|
+
).toBe(true);
|
|
510
|
+
expect(
|
|
511
|
+
schema.safeParse({
|
|
512
|
+
name: "Ada",
|
|
513
|
+
role: "owner",
|
|
514
|
+
address: { city: "London" },
|
|
515
|
+
tags: [],
|
|
516
|
+
}).success,
|
|
517
|
+
).toBe(false);
|
|
518
|
+
expect(schema.safeParse({ role: "user" }).success).toBe(false);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import type { WatchSource } from "vue";
|
|
8
8
|
import type { WebMCPToolConfig } from "@copilotkit/core";
|
|
9
9
|
import type { Parameter, MappedParameterTypes } from "@copilotkit/shared";
|
|
10
|
-
import {
|
|
10
|
+
import { parseJson } from "@copilotkit/shared";
|
|
11
|
+
import { getZodParameters } from "./zod-parameters";
|
|
11
12
|
import { useFrontendTool as useFrontendToolV2 } from "../v2/hooks/use-frontend-tool";
|
|
12
13
|
import { useHumanInTheLoop as useHumanInTheLoopV2 } from "../v2/hooks/use-human-in-the-loop";
|
|
13
14
|
import { useRenderTool as useRenderToolV2 } from "../v2/hooks/use-render-tool";
|
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { WatchSource } from "vue";
|
|
8
8
|
import type { WebMCPToolConfig } from "@copilotkit/core";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getZodParameters,
|
|
13
|
-
parseJson,
|
|
14
|
-
} from "@copilotkit/shared";
|
|
9
|
+
import { parseJson } from "@copilotkit/shared";
|
|
10
|
+
import type { Parameter, MappedParameterTypes } from "@copilotkit/shared";
|
|
11
|
+
import { getZodParameters } from "./zod-parameters";
|
|
15
12
|
import { useFrontendTool as useFrontendToolV2 } from "../v2/hooks/use-frontend-tool";
|
|
16
13
|
import type { VueFrontendTool } from "../v2/types";
|
|
17
14
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
3
|
+
import type { Parameter } from "@copilotkit/shared";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert a JSON Schema to a Zod schema. Resolves `$ref` against `$defs` /
|
|
7
|
+
* `definitions`, maps `anyOf` / `oneOf` to unions, and falls back to
|
|
8
|
+
* `z.any()` for circular refs and unsupported types.
|
|
9
|
+
*
|
|
10
|
+
* Moved here from `@copilotkit/shared` in 2.0 so that shared does not depend
|
|
11
|
+
* on zod.
|
|
12
|
+
*/
|
|
13
|
+
export function convertJsonSchemaToZodSchema(
|
|
14
|
+
jsonSchema: any,
|
|
15
|
+
required: boolean,
|
|
16
|
+
definitions?: Record<string, any>,
|
|
17
|
+
visitedRefs?: Set<string>,
|
|
18
|
+
): z.ZodSchema {
|
|
19
|
+
// Resolve $ref references
|
|
20
|
+
if (jsonSchema.$ref && definitions) {
|
|
21
|
+
const refPath = jsonSchema.$ref.replace(
|
|
22
|
+
/^#\/\$defs\/|^#\/definitions\//,
|
|
23
|
+
"",
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Detect circular $ref cycles
|
|
27
|
+
const refs = visitedRefs ?? new Set<string>();
|
|
28
|
+
if (refs.has(refPath)) {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`,
|
|
31
|
+
);
|
|
32
|
+
let schema = z.any();
|
|
33
|
+
if (jsonSchema.description) {
|
|
34
|
+
schema = schema.describe(jsonSchema.description);
|
|
35
|
+
}
|
|
36
|
+
return required ? schema : schema.optional();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const resolved = definitions[refPath];
|
|
40
|
+
if (resolved) {
|
|
41
|
+
// Clone the set so sibling branches don't see each other's visited refs
|
|
42
|
+
const nextRefs = new Set(refs);
|
|
43
|
+
nextRefs.add(refPath);
|
|
44
|
+
return convertJsonSchemaToZodSchema(
|
|
45
|
+
resolved,
|
|
46
|
+
required,
|
|
47
|
+
definitions,
|
|
48
|
+
nextRefs,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Collect top-level definitions for $ref resolution
|
|
54
|
+
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
55
|
+
|
|
56
|
+
// Handle null-union types like ["string", "null"]
|
|
57
|
+
if (Array.isArray(jsonSchema.type)) {
|
|
58
|
+
const types = jsonSchema.type as string[];
|
|
59
|
+
const hasNull = types.includes("null");
|
|
60
|
+
const nonNullTypes = types.filter((t: string) => t !== "null");
|
|
61
|
+
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
62
|
+
const innerSchema = convertJsonSchemaToZodSchema(
|
|
63
|
+
{ ...jsonSchema, type: resolvedType },
|
|
64
|
+
true,
|
|
65
|
+
defs,
|
|
66
|
+
visitedRefs,
|
|
67
|
+
);
|
|
68
|
+
let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;
|
|
69
|
+
if (jsonSchema.description) {
|
|
70
|
+
schema = schema.describe(jsonSchema.description);
|
|
71
|
+
}
|
|
72
|
+
return required ? schema : schema.optional();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Handle anyOf / oneOf as z.union
|
|
76
|
+
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
77
|
+
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
78
|
+
if (unionVariants.length === 1) {
|
|
79
|
+
return convertJsonSchemaToZodSchema(
|
|
80
|
+
unionVariants[0],
|
|
81
|
+
required,
|
|
82
|
+
defs,
|
|
83
|
+
visitedRefs,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const schemas = unionVariants.map((v: any) =>
|
|
87
|
+
convertJsonSchemaToZodSchema(v, true, defs, visitedRefs),
|
|
88
|
+
);
|
|
89
|
+
let schema = z.union(
|
|
90
|
+
schemas as [z.ZodSchema, z.ZodSchema, ...z.ZodSchema[]],
|
|
91
|
+
);
|
|
92
|
+
if (jsonSchema.description) {
|
|
93
|
+
schema = schema.describe(jsonSchema.description);
|
|
94
|
+
}
|
|
95
|
+
return required ? schema : schema.optional();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (jsonSchema.type === "object") {
|
|
99
|
+
const spec: { [key: string]: z.ZodSchema } = {};
|
|
100
|
+
|
|
101
|
+
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
102
|
+
return !required ? z.object(spec).optional() : z.object(spec);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
106
|
+
spec[key] = convertJsonSchemaToZodSchema(
|
|
107
|
+
value,
|
|
108
|
+
jsonSchema.required ? jsonSchema.required.includes(key) : false,
|
|
109
|
+
defs,
|
|
110
|
+
visitedRefs,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
let schema = z.object(spec).describe(jsonSchema.description);
|
|
114
|
+
return required ? schema : schema.optional();
|
|
115
|
+
} else if (jsonSchema.type === "string") {
|
|
116
|
+
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
117
|
+
let schema = z
|
|
118
|
+
.enum(jsonSchema.enum as [string, ...string[]])
|
|
119
|
+
.describe(jsonSchema.description);
|
|
120
|
+
return required ? schema : schema.optional();
|
|
121
|
+
}
|
|
122
|
+
let schema = z.string().describe(jsonSchema.description);
|
|
123
|
+
return required ? schema : schema.optional();
|
|
124
|
+
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
125
|
+
let schema = z.number().describe(jsonSchema.description);
|
|
126
|
+
return required ? schema : schema.optional();
|
|
127
|
+
} else if (jsonSchema.type === "boolean") {
|
|
128
|
+
let schema = z.boolean().describe(jsonSchema.description);
|
|
129
|
+
return required ? schema : schema.optional();
|
|
130
|
+
} else if (jsonSchema.type === "array") {
|
|
131
|
+
let itemSchema = convertJsonSchemaToZodSchema(
|
|
132
|
+
jsonSchema.items,
|
|
133
|
+
true,
|
|
134
|
+
defs,
|
|
135
|
+
visitedRefs,
|
|
136
|
+
);
|
|
137
|
+
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
138
|
+
return required ? schema : schema.optional();
|
|
139
|
+
} else if (jsonSchema.type === "null") {
|
|
140
|
+
let schema = z.null().describe(jsonSchema.description);
|
|
141
|
+
return required ? schema : schema.optional();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Fallback: accept any value rather than throwing
|
|
145
|
+
console.warn(
|
|
146
|
+
`[CopilotKit] Unsupported JSON schema type "${jsonSchema.type ?? "unknown"}" — falling back to z.any()`,
|
|
147
|
+
);
|
|
148
|
+
let schema = z.any();
|
|
149
|
+
if (jsonSchema.description) {
|
|
150
|
+
schema = schema.describe(jsonSchema.description);
|
|
151
|
+
}
|
|
152
|
+
return required ? schema : schema.optional();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Convert v1 `Parameter[]` action parameters to a Zod object schema. */
|
|
156
|
+
export function getZodParameters<T extends [] | Parameter[] | undefined>(
|
|
157
|
+
parameters: T,
|
|
158
|
+
): any {
|
|
159
|
+
if (!parameters) return z.object({});
|
|
160
|
+
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
161
|
+
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
162
|
+
}
|