@copilotkit/vue 2.0.0-rc.0 → 2.0.0-rc.10
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-CTR_ziWV.js +18097 -0
- package/dist/use-render-activity-message-CTR_ziWV.js.map +1 -0
- package/dist/use-render-activity-message-Dky9_GRG.cjs +92 -0
- package/dist/use-render-activity-message-Dky9_GRG.cjs.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
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, h, type VNode } from "vue";
|
|
3
|
-
import { parseMarkdown, type MarkdownToken } from "@copilotkit/core";
|
|
4
|
-
|
|
5
|
-
const props = withDefaults(
|
|
6
|
-
defineProps<{ content: string; isStreaming?: boolean }>(),
|
|
7
|
-
{ isStreaming: false },
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const tokens = computed(() => parseMarkdown(props.content ?? ""));
|
|
11
|
-
|
|
12
|
-
// Allowlist URL schemes to prevent XSS via javascript:/data:/vbscript: URIs.
|
|
13
|
-
const SAFE_HREF = /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i;
|
|
14
|
-
const SAFE_IMG_SRC = /^(https?:|data:image\/(?!svg)|\/|\.\/|\.\.\/)/i;
|
|
15
|
-
|
|
16
|
-
function sanitizeHref(href: string | undefined): string | undefined {
|
|
17
|
-
if (!href) return undefined;
|
|
18
|
-
return SAFE_HREF.test(href.trim()) ? href : undefined;
|
|
19
|
-
}
|
|
20
|
-
function sanitizeImgSrc(src: string | undefined): string | undefined {
|
|
21
|
-
if (!src) return undefined;
|
|
22
|
-
return SAFE_IMG_SRC.test(src.trim()) ? src : undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function inline(toks: MarkdownToken[] | undefined): (VNode | string)[] {
|
|
26
|
-
if (!toks) return [];
|
|
27
|
-
return toks.map((t) => {
|
|
28
|
-
switch (t.type) {
|
|
29
|
-
case "text":
|
|
30
|
-
return "tokens" in t && (t as any).tokens
|
|
31
|
-
? h("span", inline((t as any).tokens))
|
|
32
|
-
: (t as any).text;
|
|
33
|
-
case "strong":
|
|
34
|
-
return h("strong", inline((t as any).tokens));
|
|
35
|
-
case "em":
|
|
36
|
-
return h("em", inline((t as any).tokens));
|
|
37
|
-
case "del":
|
|
38
|
-
return h("del", inline((t as any).tokens));
|
|
39
|
-
case "codespan":
|
|
40
|
-
return h(
|
|
41
|
-
"code",
|
|
42
|
-
{ class: "cpk:rounded cpk:bg-black/5 cpk:px-1 cpk:py-0.5" },
|
|
43
|
-
(t as any).text,
|
|
44
|
-
);
|
|
45
|
-
case "br":
|
|
46
|
-
return h("br");
|
|
47
|
-
case "link":
|
|
48
|
-
return h(
|
|
49
|
-
"a",
|
|
50
|
-
{
|
|
51
|
-
href: sanitizeHref((t as any).href),
|
|
52
|
-
target: "_blank",
|
|
53
|
-
rel: "noopener noreferrer",
|
|
54
|
-
},
|
|
55
|
-
(t as any).tokens ? inline((t as any).tokens) : (t as any).text,
|
|
56
|
-
);
|
|
57
|
-
case "image":
|
|
58
|
-
return h("img", {
|
|
59
|
-
src: sanitizeImgSrc((t as any).href),
|
|
60
|
-
alt: (t as any).text,
|
|
61
|
-
class: "cpk:max-w-full",
|
|
62
|
-
});
|
|
63
|
-
case "escape":
|
|
64
|
-
return (t as any).text;
|
|
65
|
-
default:
|
|
66
|
-
return "text" in t ? (t as any).text : "";
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function block(t: MarkdownToken): VNode | null {
|
|
72
|
-
switch (t.type) {
|
|
73
|
-
case "space":
|
|
74
|
-
return null;
|
|
75
|
-
case "heading": {
|
|
76
|
-
const depth = Math.min(Math.max((t as any).depth, 1), 6);
|
|
77
|
-
return h(`h${depth}`, inline((t as any).tokens));
|
|
78
|
-
}
|
|
79
|
-
case "paragraph":
|
|
80
|
-
return h("p", inline((t as any).tokens));
|
|
81
|
-
case "blockquote":
|
|
82
|
-
return h(
|
|
83
|
-
"blockquote",
|
|
84
|
-
(((t as any).tokens as MarkdownToken[] | undefined) ?? [])
|
|
85
|
-
.map(block)
|
|
86
|
-
.filter(Boolean),
|
|
87
|
-
);
|
|
88
|
-
case "code":
|
|
89
|
-
return h("pre", { class: "cpk:overflow-x-auto cpk:rounded-lg cpk:p-3" }, [
|
|
90
|
-
h(
|
|
91
|
-
"code",
|
|
92
|
-
{ "data-language": (t as any).lang || undefined },
|
|
93
|
-
(t as any).text,
|
|
94
|
-
),
|
|
95
|
-
]);
|
|
96
|
-
case "hr":
|
|
97
|
-
return h("hr");
|
|
98
|
-
case "list": {
|
|
99
|
-
const list = t as any;
|
|
100
|
-
const items = list.items.map((it: any) =>
|
|
101
|
-
h(
|
|
102
|
-
"li",
|
|
103
|
-
((it.tokens as MarkdownToken[] | undefined) ?? [])
|
|
104
|
-
.map(block)
|
|
105
|
-
.filter(Boolean),
|
|
106
|
-
),
|
|
107
|
-
);
|
|
108
|
-
return list.ordered
|
|
109
|
-
? h(
|
|
110
|
-
"ol",
|
|
111
|
-
{ start: typeof list.start === "number" ? list.start : undefined },
|
|
112
|
-
items,
|
|
113
|
-
)
|
|
114
|
-
: h("ul", items);
|
|
115
|
-
}
|
|
116
|
-
case "table": {
|
|
117
|
-
const tbl = t as any;
|
|
118
|
-
return h("div", { class: "cpk:overflow-x-auto" }, [
|
|
119
|
-
h("table", [
|
|
120
|
-
h("thead", [
|
|
121
|
-
h(
|
|
122
|
-
"tr",
|
|
123
|
-
tbl.header.map((c: any) => h("th", inline(c.tokens))),
|
|
124
|
-
),
|
|
125
|
-
]),
|
|
126
|
-
h(
|
|
127
|
-
"tbody",
|
|
128
|
-
tbl.rows.map((row: any) =>
|
|
129
|
-
h(
|
|
130
|
-
"tr",
|
|
131
|
-
row.map((c: any) => h("td", inline(c.tokens))),
|
|
132
|
-
),
|
|
133
|
-
),
|
|
134
|
-
),
|
|
135
|
-
]),
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
case "text":
|
|
139
|
-
return h(
|
|
140
|
-
"p",
|
|
141
|
-
(t as any).tokens ? inline((t as any).tokens) : (t as any).text,
|
|
142
|
-
);
|
|
143
|
-
default:
|
|
144
|
-
return "text" in t ? h("span", (t as any).text) : null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const Rendered = () =>
|
|
149
|
-
h(
|
|
150
|
-
"div",
|
|
151
|
-
{ class: "copilot-chat-assistant-markdown" },
|
|
152
|
-
tokens.value.map(block).filter(Boolean),
|
|
153
|
-
);
|
|
154
|
-
</script>
|
|
155
|
-
|
|
156
|
-
<template>
|
|
157
|
-
<Rendered v-if="tokens.length" />
|
|
158
|
-
</template>
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { mount } from "@vue/test-utils";
|
|
3
|
-
import BasicMarkdown from "../BasicMarkdown.vue";
|
|
4
|
-
|
|
5
|
-
describe("BasicMarkdown.vue", () => {
|
|
6
|
-
it("renders headings", () => {
|
|
7
|
-
const w = mount(BasicMarkdown, { props: { content: "# Title" } });
|
|
8
|
-
expect(w.find("h1").text()).toBe("Title");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("renders bold/italic", () => {
|
|
12
|
-
const w = mount(BasicMarkdown, { props: { content: "**b** *i*" } });
|
|
13
|
-
expect(w.find("strong").text()).toBe("b");
|
|
14
|
-
expect(w.find("em").text()).toBe("i");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("renders code blocks", () => {
|
|
18
|
-
const w = mount(BasicMarkdown, { props: { content: "```\nx\n```" } });
|
|
19
|
-
expect(w.find("pre code").text()).toContain("x");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("renders tables", () => {
|
|
23
|
-
const w = mount(BasicMarkdown, {
|
|
24
|
-
props: { content: "| a | b |\n| --- | --- |\n| 1 | 2 |" },
|
|
25
|
-
});
|
|
26
|
-
expect(w.findAll("th")).toHaveLength(2);
|
|
27
|
-
expect(w.findAll("tbody td")).toHaveLength(2);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("renders links with safe href", () => {
|
|
31
|
-
const w = mount(BasicMarkdown, {
|
|
32
|
-
props: { content: "[CK](https://copilotkit.ai)" },
|
|
33
|
-
});
|
|
34
|
-
expect(w.find("a").attributes("href")).toBe("https://copilotkit.ai");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("neutralizes javascript: URIs in links (no XSS)", () => {
|
|
38
|
-
const w = mount(BasicMarkdown, {
|
|
39
|
-
props: { content: "[x](javascript:alert(1))" },
|
|
40
|
-
});
|
|
41
|
-
expect(w.find("a").attributes("href")).toBeUndefined();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("neutralizes javascript: image src", () => {
|
|
45
|
-
const w = mount(BasicMarkdown, {
|
|
46
|
-
props: { content: ")" },
|
|
47
|
-
});
|
|
48
|
-
expect(w.find("img").attributes("src")).toBeUndefined();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("renders nothing for empty content", () => {
|
|
52
|
-
const w = mount(BasicMarkdown, { props: { content: "" } });
|
|
53
|
-
expect(w.text()).toBe("");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("rejects data:image/svg+xml image src (SVG script vector)", () => {
|
|
57
|
-
const w = mount(BasicMarkdown, {
|
|
58
|
-
props: { content: "" },
|
|
59
|
-
});
|
|
60
|
-
expect(w.find("img").attributes("src")).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("still allows data:image/png image src", () => {
|
|
64
|
-
const w = mount(BasicMarkdown, {
|
|
65
|
-
props: { content: "" },
|
|
66
|
-
});
|
|
67
|
-
expect(w.find("img").attributes("src")).toContain("data:image/png");
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
processPartialHtml,
|
|
4
|
-
extractCompleteStyles,
|
|
5
|
-
} from "../processPartialHtml";
|
|
6
|
-
|
|
7
|
-
describe("processPartialHtml", () => {
|
|
8
|
-
it("returns empty string for empty input", () => {
|
|
9
|
-
expect(processPartialHtml("")).toBe("");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("strips incomplete tag at end", () => {
|
|
13
|
-
expect(processPartialHtml('<div>Hello<span class="fo')).toBe("<div>Hello");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("strips complete <style> blocks", () => {
|
|
17
|
-
const input =
|
|
18
|
-
"<div>Hello</div><style>.foo { color: red; }</style><p>World</p>";
|
|
19
|
-
expect(processPartialHtml(input)).toBe("<div>Hello</div><p>World</p>");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("strips complete <script> blocks", () => {
|
|
23
|
-
const input = '<div>Hello</div><script>alert("hi")</script><p>World</p>';
|
|
24
|
-
expect(processPartialHtml(input)).toBe("<div>Hello</div><p>World</p>");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("strips incomplete <style> block", () => {
|
|
28
|
-
const input = "<div>Hello</div><style>.foo { color:";
|
|
29
|
-
expect(processPartialHtml(input)).toBe("<div>Hello</div>");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("strips incomplete <script> block", () => {
|
|
33
|
-
const input = '<div>Hello</div><script>const x = "val';
|
|
34
|
-
expect(processPartialHtml(input)).toBe("<div>Hello</div>");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("strips incomplete HTML entities", () => {
|
|
38
|
-
expect(processPartialHtml("<p>Hello &")).toBe("<p>Hello ");
|
|
39
|
-
expect(processPartialHtml("<p>Hello {")).toBe("<p>Hello ");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("preserves complete entities", () => {
|
|
43
|
-
expect(processPartialHtml("<p>Hello & World</p>")).toBe(
|
|
44
|
-
"<p>Hello & World</p>",
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("extracts body content from full HTML document", () => {
|
|
49
|
-
const input =
|
|
50
|
-
"<html><head><title>Test</title></head><body><p>Content</p></body></html>";
|
|
51
|
-
expect(processPartialHtml(input)).toBe("<p>Content</p>");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("handles <body> with attributes", () => {
|
|
55
|
-
const input = '<body class="dark"><p>Content</p></body>';
|
|
56
|
-
expect(processPartialHtml(input)).toBe("<p>Content</p>");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("handles no <body> tag", () => {
|
|
60
|
-
const input = "<div><p>Just content</p></div>";
|
|
61
|
-
expect(processPartialHtml(input)).toBe("<div><p>Just content</p></div>");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("extractCompleteStyles", () => {
|
|
66
|
-
it("returns empty string for no styles", () => {
|
|
67
|
-
expect(extractCompleteStyles("<div>Hello</div>")).toBe("");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("extracts a single complete style block", () => {
|
|
71
|
-
const input =
|
|
72
|
-
"<div>Hello</div><style>.foo { color: red; }</style><p>World</p>";
|
|
73
|
-
expect(extractCompleteStyles(input)).toBe(
|
|
74
|
-
"<style>.foo { color: red; }</style>",
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("extracts multiple complete style blocks", () => {
|
|
79
|
-
const input = "<style>a{}</style><div>X</div><style>b{}</style>";
|
|
80
|
-
expect(extractCompleteStyles(input)).toBe(
|
|
81
|
-
"<style>a{}</style><style>b{}</style>",
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { TranscriptionErrorCode } from "@copilotkit/shared";
|
|
3
|
-
import type { TranscriptionError } from "../transcription-client";
|
|
4
|
-
import { transcribeAudio } from "../transcription-client";
|
|
5
|
-
import type { CopilotKitCoreVue } from "../vue-core";
|
|
6
|
-
|
|
7
|
-
describe("transcription-client", () => {
|
|
8
|
-
const originalFetch = globalThis.fetch;
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
globalThis.fetch = originalFetch;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("transcribes audio in REST mode", async () => {
|
|
15
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
16
|
-
ok: true,
|
|
17
|
-
json: async () => ({
|
|
18
|
-
text: "Transcribed text",
|
|
19
|
-
size: 12,
|
|
20
|
-
type: "audio/webm",
|
|
21
|
-
}),
|
|
22
|
-
} satisfies Partial<Response>) as typeof fetch;
|
|
23
|
-
|
|
24
|
-
const result = await transcribeAudio(
|
|
25
|
-
{
|
|
26
|
-
runtimeUrl: "/api/copilotkit",
|
|
27
|
-
runtimeTransport: "rest",
|
|
28
|
-
headers: {},
|
|
29
|
-
resolveHeaders: async () => ({}),
|
|
30
|
-
} as CopilotKitCoreVue,
|
|
31
|
-
new Blob(["audio"], { type: "audio/webm" }),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expect(globalThis.fetch).toHaveBeenCalledTimes(1);
|
|
35
|
-
expect(result.text).toBe("Transcribed text");
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("maps structured error responses to TranscriptionError", async () => {
|
|
39
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
40
|
-
ok: false,
|
|
41
|
-
status: 429,
|
|
42
|
-
statusText: "Too Many Requests",
|
|
43
|
-
json: async () => ({
|
|
44
|
-
error: TranscriptionErrorCode.RATE_LIMITED,
|
|
45
|
-
message: "Rate limited",
|
|
46
|
-
retryable: true,
|
|
47
|
-
}),
|
|
48
|
-
} satisfies Partial<Response>) as typeof fetch;
|
|
49
|
-
|
|
50
|
-
await expect(
|
|
51
|
-
transcribeAudio(
|
|
52
|
-
{
|
|
53
|
-
runtimeUrl: "/api/copilotkit",
|
|
54
|
-
runtimeTransport: "rest",
|
|
55
|
-
headers: {},
|
|
56
|
-
resolveHeaders: async () => ({}),
|
|
57
|
-
} as CopilotKitCoreVue,
|
|
58
|
-
new Blob(["audio"], { type: "audio/webm" }),
|
|
59
|
-
),
|
|
60
|
-
).rejects.toMatchObject({
|
|
61
|
-
info: {
|
|
62
|
-
code: TranscriptionErrorCode.RATE_LIMITED,
|
|
63
|
-
retryable: true,
|
|
64
|
-
},
|
|
65
|
-
} satisfies Partial<TranscriptionError>);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { CopilotKitCoreVue } from "./vue-core";
|
|
2
|
-
import { TranscriptionErrorCode } from "@copilotkit/shared";
|
|
3
|
-
import type { TranscriptionErrorResponse } from "@copilotkit/shared";
|
|
4
|
-
|
|
5
|
-
export interface TranscriptionResult {
|
|
6
|
-
text: string;
|
|
7
|
-
size: number;
|
|
8
|
-
type: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface TranscriptionErrorInfo {
|
|
12
|
-
code: TranscriptionErrorCode;
|
|
13
|
-
message: string;
|
|
14
|
-
retryable: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { TranscriptionErrorCode };
|
|
18
|
-
|
|
19
|
-
async function blobToBase64(blob: Blob): Promise<string> {
|
|
20
|
-
return await new Promise((resolve, reject) => {
|
|
21
|
-
const reader = new FileReader();
|
|
22
|
-
reader.onloadend = () => {
|
|
23
|
-
const result = reader.result as string;
|
|
24
|
-
resolve(result.split(",")[1] ?? "");
|
|
25
|
-
};
|
|
26
|
-
reader.addEventListener("error", () =>
|
|
27
|
-
reject(new Error("Failed to read audio data")),
|
|
28
|
-
);
|
|
29
|
-
reader.readAsDataURL(blob);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isTranscriptionErrorResponse(
|
|
34
|
-
data: unknown,
|
|
35
|
-
): data is TranscriptionErrorResponse {
|
|
36
|
-
return (
|
|
37
|
-
typeof data === "object" &&
|
|
38
|
-
data !== null &&
|
|
39
|
-
"error" in data &&
|
|
40
|
-
"message" in data &&
|
|
41
|
-
typeof (data as TranscriptionErrorResponse).error === "string" &&
|
|
42
|
-
typeof (data as TranscriptionErrorResponse).message === "string"
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parseTranscriptionError(
|
|
47
|
-
response: TranscriptionErrorResponse,
|
|
48
|
-
): TranscriptionErrorInfo {
|
|
49
|
-
return {
|
|
50
|
-
code: response.error,
|
|
51
|
-
message: response.message,
|
|
52
|
-
retryable: response.retryable ?? false,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class TranscriptionError extends Error {
|
|
57
|
-
public readonly info: TranscriptionErrorInfo;
|
|
58
|
-
|
|
59
|
-
constructor(info: TranscriptionErrorInfo) {
|
|
60
|
-
super(info.message);
|
|
61
|
-
this.name = "TranscriptionError";
|
|
62
|
-
this.info = info;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function transcribeAudio(
|
|
67
|
-
core: CopilotKitCoreVue,
|
|
68
|
-
audioBlob: Blob,
|
|
69
|
-
filename: string = "recording.webm",
|
|
70
|
-
): Promise<TranscriptionResult> {
|
|
71
|
-
const runtimeUrl = core.runtimeUrl;
|
|
72
|
-
if (!runtimeUrl) {
|
|
73
|
-
throw new TranscriptionError({
|
|
74
|
-
code: TranscriptionErrorCode.INVALID_REQUEST,
|
|
75
|
-
message: "Runtime URL is not configured",
|
|
76
|
-
retryable: false,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const headers: Record<string, string> = { ...(await core.resolveHeaders()) };
|
|
81
|
-
let response: Response;
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
if (core.runtimeTransport === "single") {
|
|
85
|
-
const base64Audio = await blobToBase64(audioBlob);
|
|
86
|
-
|
|
87
|
-
headers["Content-Type"] = "application/json";
|
|
88
|
-
|
|
89
|
-
response = await fetch(runtimeUrl, {
|
|
90
|
-
method: "POST",
|
|
91
|
-
headers,
|
|
92
|
-
body: JSON.stringify({
|
|
93
|
-
method: "transcribe",
|
|
94
|
-
body: {
|
|
95
|
-
audio: base64Audio,
|
|
96
|
-
mimeType: audioBlob.type || "audio/webm",
|
|
97
|
-
filename,
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
delete headers["Content-Type"];
|
|
103
|
-
|
|
104
|
-
const formData = new FormData();
|
|
105
|
-
formData.append("audio", audioBlob, filename);
|
|
106
|
-
|
|
107
|
-
response = await fetch(`${runtimeUrl}/transcribe`, {
|
|
108
|
-
method: "POST",
|
|
109
|
-
headers,
|
|
110
|
-
body: formData,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
throw new TranscriptionError({
|
|
115
|
-
code: TranscriptionErrorCode.NETWORK_ERROR,
|
|
116
|
-
message:
|
|
117
|
-
error instanceof Error ? error.message : "Network request failed",
|
|
118
|
-
retryable: true,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!response.ok) {
|
|
123
|
-
let errorData: unknown;
|
|
124
|
-
try {
|
|
125
|
-
errorData = await response.json();
|
|
126
|
-
} catch {
|
|
127
|
-
throw new TranscriptionError({
|
|
128
|
-
code: TranscriptionErrorCode.PROVIDER_ERROR,
|
|
129
|
-
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
130
|
-
retryable: response.status >= 500,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (isTranscriptionErrorResponse(errorData)) {
|
|
135
|
-
throw new TranscriptionError(parseTranscriptionError(errorData));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
throw new TranscriptionError({
|
|
139
|
-
code: TranscriptionErrorCode.PROVIDER_ERROR,
|
|
140
|
-
message:
|
|
141
|
-
typeof errorData === "object" &&
|
|
142
|
-
errorData !== null &&
|
|
143
|
-
"message" in errorData
|
|
144
|
-
? String((errorData as { message: unknown }).message)
|
|
145
|
-
: "Transcription failed",
|
|
146
|
-
retryable: response.status >= 500,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return (await response.json()) as TranscriptionResult;
|
|
151
|
-
}
|