@docyrus/ui-pro-ai-assistant 0.0.1 → 0.0.2
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/dist/chunk-VSTHZ22Q.js +165 -0
- package/dist/chunk-VSTHZ22Q.js.map +1 -0
- package/dist/components/assistant-animations.d.ts +12 -0
- package/dist/components/assistant-dialogs.d.ts +30 -0
- package/dist/components/code-view.d.ts +30 -0
- package/dist/components/create-agent-task.d.ts +9 -0
- package/dist/components/create-new-work-version.d.ts +7 -0
- package/dist/components/extract-web.d.ts +9 -0
- package/dist/components/forward-to-agent.d.ts +8 -0
- package/dist/components/generate-chart.d.ts +11 -0
- package/dist/components/generative-action-button.d.ts +11 -0
- package/dist/components/generative-tool.d.ts +61 -0
- package/dist/components/generative-ui-object.d.ts +26 -0
- package/dist/components/input-area.d.ts +49 -0
- package/dist/components/json-schema-layout.d.ts +6 -0
- package/dist/components/list-item-card.d.ts +17 -0
- package/dist/components/mermaid-diagram.d.ts +8 -0
- package/dist/components/preview-image.d.ts +16 -0
- package/dist/components/request-approval.d.ts +9 -0
- package/dist/components/request-user-input.d.ts +31 -0
- package/dist/components/search-web.d.ts +8 -0
- package/dist/components/sheet-command.d.ts +11 -0
- package/dist/components/shell-canvas.d.ts +16 -0
- package/dist/components/show-advanced-data-table.d.ts +34 -0
- package/dist/components/show-generated-content-options.d.ts +16 -0
- package/dist/components/show-people-cards.d.ts +8 -0
- package/dist/components/subagent-tool.d.ts +22 -0
- package/dist/components/text-editor-tool.d.ts +23 -0
- package/dist/components/work-canvas.d.ts +13 -0
- package/dist/components/work-card.d.ts +9 -0
- package/dist/docy-assistant.d.ts +5 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/use-assistant-api.d.ts +44 -0
- package/dist/hooks/use-deployment-data.d.ts +31 -0
- package/dist/hooks/use-project-state.d.ts +64 -0
- package/dist/hooks/use-session-state.d.ts +31 -0
- package/dist/hooks/use-speech-recognition.d.ts +25 -0
- package/dist/hooks/use-ui-state.d.ts +29 -0
- package/dist/hooks/use-works-state.d.ts +22 -0
- package/dist/i18n/context.d.ts +11 -0
- package/dist/i18n/index.d.ts +13 -0
- package/dist/i18n/types.d.ts +18 -0
- package/dist/i18n/use-translation.d.ts +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -20
- package/dist/index.js.map +1 -1
- package/dist/internal/plate-editor/editor/auth-context.d.ts +6 -0
- package/dist/internal/plate-editor/editor/editor-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/editor-kit.d.ts +5 -0
- package/dist/internal/plate-editor/editor/plate-editor.d.ts +20 -0
- package/dist/internal/plate-editor/editor/plate-types.d.ts +70 -0
- package/dist/internal/plate-editor/editor/plugins/ai-kit.d.ts +98 -0
- package/dist/internal/plate-editor/editor/plugins/autoformat-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/basic-blocks-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/basic-blocks-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/basic-marks-base-kit.d.ts +17 -0
- package/dist/internal/plate-editor/editor/plugins/basic-marks-kit.d.ts +17 -0
- package/dist/internal/plate-editor/editor/plugins/basic-nodes-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/block-menu-kit.d.ts +165 -0
- package/dist/internal/plate-editor/editor/plugins/block-placeholder-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/block-selection-kit.d.ts +137 -0
- package/dist/internal/plate-editor/editor/plugins/callout-base-kit.d.ts +20 -0
- package/dist/internal/plate-editor/editor/plugins/callout-kit.d.ts +20 -0
- package/dist/internal/plate-editor/editor/plugins/code-block-base-kit.d.ts +7 -0
- package/dist/internal/plate-editor/editor/plugins/code-block-kit.d.ts +7 -0
- package/dist/internal/plate-editor/editor/plugins/column-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/column-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/comment-base-kit.d.ts +47 -0
- package/dist/internal/plate-editor/editor/plugins/comment-kit.d.ts +71 -0
- package/dist/internal/plate-editor/editor/plugins/copilot-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/cursor-overlay-kit.d.ts +11 -0
- package/dist/internal/plate-editor/editor/plugins/date-base-kit.d.ts +19 -0
- package/dist/internal/plate-editor/editor/plugins/date-kit.d.ts +19 -0
- package/dist/internal/plate-editor/editor/plugins/discussion-kit.d.ts +55 -0
- package/dist/internal/plate-editor/editor/plugins/dnd-kit.d.ts +20 -0
- package/dist/internal/plate-editor/editor/plugins/docx-export-kit.d.ts +19 -0
- package/dist/internal/plate-editor/editor/plugins/docx-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/emoji-kit.d.ts +5 -0
- package/dist/internal/plate-editor/editor/plugins/exit-break-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/floating-toolbar-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/font-base-kit.d.ts +13 -0
- package/dist/internal/plate-editor/editor/plugins/font-kit.d.ts +13 -0
- package/dist/internal/plate-editor/editor/plugins/indent-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/indent-kit.d.ts +5 -0
- package/dist/internal/plate-editor/editor/plugins/link-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/link-kit.d.ts +68 -0
- package/dist/internal/plate-editor/editor/plugins/list-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/list-kit.d.ts +8 -0
- package/dist/internal/plate-editor/editor/plugins/markdown-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/math-base-kit.d.ts +9 -0
- package/dist/internal/plate-editor/editor/plugins/math-kit.d.ts +9 -0
- package/dist/internal/plate-editor/editor/plugins/media-base-kit.d.ts +25 -0
- package/dist/internal/plate-editor/editor/plugins/media-kit.d.ts +38 -0
- package/dist/internal/plate-editor/editor/plugins/mention-base-kit.d.ts +11 -0
- package/dist/internal/plate-editor/editor/plugins/mention-kit.d.ts +11 -0
- package/dist/internal/plate-editor/editor/plugins/slash-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/suggestion-base-kit.d.ts +32 -0
- package/dist/internal/plate-editor/editor/plugins/suggestion-kit.d.ts +53 -0
- package/dist/internal/plate-editor/editor/plugins/table-base-kit.d.ts +77 -0
- package/dist/internal/plate-editor/editor/plugins/table-kit.d.ts +138 -0
- package/dist/internal/plate-editor/editor/plugins/toc-base-kit.d.ts +1 -0
- package/dist/internal/plate-editor/editor/plugins/toc-kit.d.ts +5 -0
- package/dist/internal/plate-editor/editor/plugins/toggle-base-kit.d.ts +12 -0
- package/dist/internal/plate-editor/editor/plugins/toggle-kit.d.ts +16 -0
- package/dist/internal/plate-editor/editor/transforms.d.ts +8 -0
- package/dist/internal/plate-editor/editor/use-chat.d.ts +26 -0
- package/dist/internal/plate-editor/hooks/index.d.ts +3 -0
- package/dist/internal/plate-editor/hooks/use-copy-to-clipboard.d.ts +6 -0
- package/dist/internal/plate-editor/hooks/use-is-touch-device.d.ts +1 -0
- package/dist/internal/plate-editor/hooks/use-lock-scroll.d.ts +1 -0
- package/dist/internal/plate-editor/hooks/use-media-query.d.ts +2 -0
- package/dist/internal/plate-editor/hooks/use-mounted.d.ts +6 -0
- package/dist/internal/plate-editor/hooks/use-on-click-outside.d.ts +18 -0
- package/dist/internal/plate-editor/hooks/use-upload-file.d.ts +21 -0
- package/dist/internal/plate-editor/i18n/context.d.ts +12 -0
- package/dist/internal/plate-editor/i18n/index.d.ts +3 -0
- package/dist/internal/plate-editor/i18n/types.d.ts +58 -0
- package/dist/internal/plate-editor/i18n/use-translation.d.ts +4 -0
- package/dist/internal/plate-editor/index.d.ts +9 -0
- package/dist/internal/plate-editor/lib/ai-output-converter.d.ts +57 -0
- package/dist/internal/plate-editor/lib/download-file.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/ai-chat-editor.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/ai-menu.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/ai-node.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/ai-toolbar-button.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/alert-dialog.d.ts +50 -0
- package/dist/internal/plate-editor/plate-ui/align-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/avatar.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/block-context-menu.d.ts +8 -0
- package/dist/internal/plate-editor/plate-ui/block-discussion.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/block-draggable.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/block-list-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/block-list.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/block-menu.d.ts +167 -0
- package/dist/internal/plate-editor/plate-ui/block-selection.d.ts +5 -0
- package/dist/internal/plate-editor/plate-ui/block-suggestion.d.ts +16 -0
- package/dist/internal/plate-editor/plate-ui/blockquote-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/blockquote-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/button.d.ts +40 -0
- package/dist/internal/plate-editor/plate-ui/calendar.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/callout-node-static.d.ts +6 -0
- package/dist/internal/plate-editor/plate-ui/callout-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/caption.d.ts +10 -0
- package/dist/internal/plate-editor/plate-ui/checkbox.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/code-block-node-static.d.ts +12 -0
- package/dist/internal/plate-editor/plate-ui/code-block-node.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/code-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/code-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/column-node-static.d.ts +12 -0
- package/dist/internal/plate-editor/plate-ui/column-node.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/command.d.ts +25 -0
- package/dist/internal/plate-editor/plate-ui/comment-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/comment-node.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/comment-toolbar-button.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/comment.d.ts +45 -0
- package/dist/internal/plate-editor/plate-ui/cursor-overlay.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/date-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/date-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/dialog.d.ts +52 -0
- package/dist/internal/plate-editor/plate-ui/dropdown-menu.d.ts +36 -0
- package/dist/internal/plate-editor/plate-ui/editor-static.d.ts +6 -0
- package/dist/internal/plate-editor/plate-ui/editor.d.ts +15 -0
- package/dist/internal/plate-editor/plate-ui/emoji-node.d.ts +7 -0
- package/dist/internal/plate-editor/plate-ui/emoji-toolbar-button.d.ts +20 -0
- package/dist/internal/plate-editor/plate-ui/equation-node-static.d.ts +14 -0
- package/dist/internal/plate-editor/plate-ui/equation-node.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/equation-toolbar-button.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/export-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/fixed-toolbar-buttons.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/fixed-toolbar.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/floating-discussion.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/floating-toolbar-buttons.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/floating-toolbar.d.ts +6 -0
- package/dist/internal/plate-editor/plate-ui/font-color-toolbar-button.d.ts +15 -0
- package/dist/internal/plate-editor/plate-ui/font-size-toolbar-button.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/ghost-text.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/heading-node-static.d.ts +7 -0
- package/dist/internal/plate-editor/plate-ui/heading-node.d.ts +11 -0
- package/dist/internal/plate-editor/plate-ui/highlight-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/highlight-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/history-toolbar-button.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/hover-card.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/hr-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/hr-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/import-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/indent-toolbar-button.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/inline-combobox.d.ts +37 -0
- package/dist/internal/plate-editor/plate-ui/input.d.ts +7 -0
- package/dist/internal/plate-editor/plate-ui/insert-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/label.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/line-height-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/link-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/link-node.d.ts +7 -0
- package/dist/internal/plate-editor/plate-ui/link-toolbar-button.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/link-toolbar.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/list-toolbar-button.d.ts +5 -0
- package/dist/internal/plate-editor/plate-ui/mark-toolbar-button.d.ts +6 -0
- package/dist/internal/plate-editor/plate-ui/media-audio-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-audio-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/media-embed-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/media-file-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-file-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/media-image-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-image-node.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-placeholder-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/media-preview-dialog.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/media-toolbar-button.d.ts +4 -0
- package/dist/internal/plate-editor/plate-ui/media-toolbar.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-upload-toast.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/media-video-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/media-video-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/mention-node-static.d.ts +5 -0
- package/dist/internal/plate-editor/plate-ui/mention-node.d.ts +11 -0
- package/dist/internal/plate-editor/plate-ui/menu.d.ts +103 -0
- package/dist/internal/plate-editor/plate-ui/mode-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/more-toolbar-button.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/paragraph-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/paragraph-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/popover.d.ts +11 -0
- package/dist/internal/plate-editor/plate-ui/progress.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/remote-cursor-overlay.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/resize-handle.d.ts +17 -0
- package/dist/internal/plate-editor/plate-ui/separator.d.ts +8 -0
- package/dist/internal/plate-editor/plate-ui/slash-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/spinner.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/suggestion-node-static.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/suggestion-node.d.ts +5 -0
- package/dist/internal/plate-editor/plate-ui/suggestion-toolbar-button.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/table-node-static.d.ts +8 -0
- package/dist/internal/plate-editor/plate-ui/table-node.d.ts +9 -0
- package/dist/internal/plate-editor/plate-ui/table-toolbar-button.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/tabs.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/textarea.d.ts +10 -0
- package/dist/internal/plate-editor/plate-ui/toc-node-static.d.ts +7 -0
- package/dist/internal/plate-editor/plate-ui/toc-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/toc-sidebar.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/toggle-node-static.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/toggle-node.d.ts +2 -0
- package/dist/internal/plate-editor/plate-ui/toggle-toolbar-button.d.ts +3 -0
- package/dist/internal/plate-editor/plate-ui/toggle.d.ts +1 -0
- package/dist/internal/plate-editor/plate-ui/toolbar.d.ts +39 -0
- package/dist/internal/plate-editor/plate-ui/tooltip.d.ts +19 -0
- package/dist/internal/plate-editor/plate-ui/turn-into-toolbar-button.d.ts +63 -0
- package/dist/internal/plate-editor/types/index.d.ts +1 -0
- package/dist/internal/plate-editor/vite.d.ts +4 -0
- package/dist/internal/sheets/components/univer-sheets.d.ts +61 -0
- package/dist/internal/sheets/i18n/context.d.ts +11 -0
- package/dist/internal/sheets/i18n/index.d.ts +13 -0
- package/dist/internal/sheets/i18n/types.d.ts +18 -0
- package/dist/internal/sheets/i18n/use-translation.d.ts +2 -0
- package/dist/internal/sheets/index.d.ts +5 -0
- package/dist/internal/sheets/types/index.d.ts +259 -0
- package/dist/internal/sheets/xlsx.d.ts +40 -0
- package/dist/lib/api-client.d.ts +17 -0
- package/dist/lib/assistant-api-actions.d.ts +57 -0
- package/dist/lib/assistant-config.d.ts +39 -0
- package/dist/lib/class-utils.d.ts +22 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/message-utils.d.ts +40 -0
- package/dist/types/index.d.ts +214 -0
- package/dist/views/assistant-view.d.ts +82 -0
- package/dist/views/canvas-app.d.ts +5 -0
- package/dist/views/canvas-code.d.ts +9 -0
- package/dist/views/canvas-deep-research.d.ts +8 -0
- package/dist/views/canvas-image.d.ts +13 -0
- package/dist/views/canvas-record-view.d.ts +10 -0
- package/dist/views/canvas-spreadsheet.d.ts +13 -0
- package/dist/views/canvas-text.d.ts +8 -0
- package/dist/views/canvas.d.ts +12 -0
- package/dist/views/chat-panel.d.ts +56 -0
- package/dist/views/index.d.ts +14 -0
- package/dist/views/memories-panel.d.ts +6 -0
- package/dist/views/message-list.d.ts +31 -0
- package/dist/views/project-detail.d.ts +31 -0
- package/dist/views/projects-panel.d.ts +15 -0
- package/dist/views/sessions-list.d.ts +15 -0
- package/dist/views/sidebar-content.d.ts +22 -0
- package/dist/views/work-detail.d.ts +9 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +55 -0
- package/dist/vite.js.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +3 -0
- package/dist/worker.js.map +1 -0
- package/package.json +12 -5
- package/src/internal/plate-editor/editor/editor-kit.tsx +1 -1
- package/src/internal/plate-editor/editor/plugins/ai-kit.tsx +1 -1
- package/src/internal/plate-editor/editor/plugins/comment-kit.tsx +2 -2
- package/src/internal/plate-editor/editor/plugins/copilot-kit.tsx +1 -1
- package/src/internal/plate-editor/editor/plugins/markdown-kit.tsx +1 -1
- package/src/internal/plate-editor/editor/transforms.ts +4 -4
- package/src/internal/plate-editor/plate-ui/ai-chat-editor.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/ai-menu.tsx +1 -1
- package/src/internal/plate-editor/plate-ui/ai-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/alert-dialog.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/align-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/block-context-menu.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/block-discussion.tsx +1 -1
- package/src/internal/plate-editor/plate-ui/block-draggable.tsx +9 -8
- package/src/internal/plate-editor/plate-ui/block-list-static.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/block-menu.tsx +3 -5
- package/src/internal/plate-editor/plate-ui/block-suggestion.tsx +6 -6
- package/src/internal/plate-editor/plate-ui/button.tsx +17 -6
- package/src/internal/plate-editor/plate-ui/caption.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/code-block-node.tsx +2 -4
- package/src/internal/plate-editor/plate-ui/command.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/comment.tsx +2 -2
- package/src/internal/plate-editor/plate-ui/date-node.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/dialog.tsx +33 -14
- package/src/internal/plate-editor/plate-ui/dropdown-menu.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/editor.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/export-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/fixed-toolbar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/floating-discussion.tsx +20 -20
- package/src/internal/plate-editor/plate-ui/floating-toolbar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/font-color-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/font-size-toolbar-button.tsx +1 -3
- package/src/internal/plate-editor/plate-ui/history-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/import-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/indent-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/input.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/insert-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/line-height-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/link-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/link-toolbar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/list-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/mark-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/media-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/media-toolbar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/menu.tsx +16 -9
- package/src/internal/plate-editor/plate-ui/mode-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/popover.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/remote-cursor-overlay.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/resize-handle.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/separator.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/slash-node.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/suggestion-node-static.tsx +1 -1
- package/src/internal/plate-editor/plate-ui/suggestion-node.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/table-node-static.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/table-node.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/table-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/textarea.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/toc-node-static.tsx +2 -2
- package/src/internal/plate-editor/plate-ui/toc-sidebar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/toggle-toolbar-button.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/toolbar.tsx +0 -2
- package/src/internal/plate-editor/plate-ui/tooltip.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/turn-into-toolbar-button.tsx +0 -2
- package/src/lib/assistant-config.tsx +6 -2
- package/src/vite.ts +1 -221
- package/src/worker.ts +203 -0
package/src/vite.ts
CHANGED
|
@@ -2,23 +2,7 @@ import { type IncomingMessage } from 'node:http';
|
|
|
2
2
|
|
|
3
3
|
import { type Plugin, loadEnv } from 'vite';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* ---------------------------------------------------------------------------
|
|
7
|
-
* Shared helpers
|
|
8
|
-
* ---------------------------------------------------------------------------
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const COPILOT_SYSTEM_PROMPT = `You are an advanced AI writing assistant, similar to VSCode Copilot but for general text. Your task is to predict and generate the next part of the text based on the given context.
|
|
12
|
-
|
|
13
|
-
Rules:
|
|
14
|
-
- Continue the text naturally up to the next punctuation mark (., ,, ;, :, ?, or !).
|
|
15
|
-
- Maintain style and tone. Don't repeat given text.
|
|
16
|
-
- For unclear context, provide the most likely continuation.
|
|
17
|
-
- Handle code snippets, lists, or structured text if needed.
|
|
18
|
-
- Don't include """ in your response.
|
|
19
|
-
- CRITICAL: Always end with a punctuation mark.
|
|
20
|
-
- CRITICAL: Avoid starting a new block. Do not use block formatting like >, #, 1., 2., -, etc. The suggestion should continue in the same block as the context.
|
|
21
|
-
- If no context is provided or you can't generate a continuation, return "0" without explanation.`;
|
|
5
|
+
import { handleAiCommand, handleAiCopilot } from './worker';
|
|
22
6
|
|
|
23
7
|
function readBody(req: IncomingMessage): Promise<Buffer> {
|
|
24
8
|
return new Promise((resolve, reject) => {
|
|
@@ -30,210 +14,6 @@ function readBody(req: IncomingMessage): Promise<Buffer> {
|
|
|
30
14
|
});
|
|
31
15
|
}
|
|
32
16
|
|
|
33
|
-
function getApiBaseUrl(env: Record<string, string>): string | undefined {
|
|
34
|
-
return env.VITE_DOCYRUS_API_URL;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getAgentId(env: Record<string, string>): string | undefined {
|
|
38
|
-
return env.VITE_DOCYRUS_EDITOR_AGENT_ID || env.VITE_DOCYRUS_AGENT_ID;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getAuthToken(request: Request): string | undefined {
|
|
42
|
-
const authHeader = request.headers.get('authorization');
|
|
43
|
-
|
|
44
|
-
return authHeader?.replace('Bearer ', '') || undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* ---------------------------------------------------------------------------
|
|
49
|
-
* Route handlers (also exported for use in Cloudflare Workers)
|
|
50
|
-
* ---------------------------------------------------------------------------
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
export async function handleAiCommand(
|
|
54
|
-
request: Request,
|
|
55
|
-
env: Record<string, string>
|
|
56
|
-
): Promise<Response> {
|
|
57
|
-
if (request.method !== 'POST') {
|
|
58
|
-
return new Response(JSON.stringify({ error: 'Method not allowed' }), {
|
|
59
|
-
status: 405,
|
|
60
|
-
headers: { 'Content-Type': 'application/json' }
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const body = await request.json() as {
|
|
66
|
-
messages?: unknown[];
|
|
67
|
-
ctx?: { selection?: unknown; children?: unknown; toolName?: string };
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const token = getAuthToken(request);
|
|
71
|
-
|
|
72
|
-
if (!token) {
|
|
73
|
-
return new Response(
|
|
74
|
-
JSON.stringify({ error: 'Unauthorized', message: 'No authentication token found. Please log in.' }),
|
|
75
|
-
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const apiBaseUrl = getApiBaseUrl(env);
|
|
80
|
-
|
|
81
|
-
if (!apiBaseUrl) {
|
|
82
|
-
return new Response(
|
|
83
|
-
JSON.stringify({ error: 'VITE_DOCYRUS_API_URL is not configured' }),
|
|
84
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const agentId = getAgentId(env);
|
|
89
|
-
|
|
90
|
-
if (!agentId) {
|
|
91
|
-
return new Response(
|
|
92
|
-
JSON.stringify({ error: 'VITE_DOCYRUS_AGENT_ID is not configured' }),
|
|
93
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const { messages, ctx } = body;
|
|
98
|
-
|
|
99
|
-
let editorContext: string | undefined;
|
|
100
|
-
|
|
101
|
-
if (ctx) {
|
|
102
|
-
const contextData: Record<string, unknown> = { toolName: ctx.toolName };
|
|
103
|
-
|
|
104
|
-
if (ctx.selection) contextData.selection = ctx.selection;
|
|
105
|
-
if (ctx.children) contextData.children = ctx.children;
|
|
106
|
-
editorContext = JSON.stringify(contextData);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const response = await fetch(`${apiBaseUrl}/v1/ai/agents/${agentId}/chat`, {
|
|
110
|
-
method: 'POST',
|
|
111
|
-
headers: {
|
|
112
|
-
'Content-Type': 'application/json',
|
|
113
|
-
Authorization: `Bearer ${token}`
|
|
114
|
-
},
|
|
115
|
-
body: JSON.stringify({
|
|
116
|
-
agentId,
|
|
117
|
-
messages: messages ?? [],
|
|
118
|
-
mode: 'agent',
|
|
119
|
-
stream: true,
|
|
120
|
-
additionalContext: editorContext
|
|
121
|
-
})
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (!response.ok) {
|
|
125
|
-
const errorText = await response.text();
|
|
126
|
-
|
|
127
|
-
return new Response(
|
|
128
|
-
errorText || JSON.stringify({ error: 'Backend API error' }),
|
|
129
|
-
{ status: response.status, headers: { 'Content-Type': 'application/json' } }
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return new Response(response.body, {
|
|
134
|
-
headers: {
|
|
135
|
-
'Content-Type': 'text/event-stream',
|
|
136
|
-
'Cache-Control': 'no-cache',
|
|
137
|
-
Connection: 'keep-alive'
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
} catch (error) {
|
|
141
|
-
console.error('[AI Command] Error:', error);
|
|
142
|
-
|
|
143
|
-
return new Response(
|
|
144
|
-
JSON.stringify({ error: 'Internal server error', message: error instanceof Error ? error.message : 'Unknown error' }),
|
|
145
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function handleAiCopilot(
|
|
151
|
-
request: Request,
|
|
152
|
-
env: Record<string, string>
|
|
153
|
-
): Promise<Response> {
|
|
154
|
-
if (request.method !== 'POST') {
|
|
155
|
-
return new Response(JSON.stringify({ error: 'Method not allowed' }), {
|
|
156
|
-
status: 405,
|
|
157
|
-
headers: { 'Content-Type': 'application/json' }
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
const body = await request.json() as { prompt?: string };
|
|
163
|
-
|
|
164
|
-
const token = getAuthToken(request);
|
|
165
|
-
|
|
166
|
-
if (!token) {
|
|
167
|
-
return new Response(
|
|
168
|
-
JSON.stringify({ error: 'Unauthorized' }),
|
|
169
|
-
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const apiBaseUrl = getApiBaseUrl(env);
|
|
174
|
-
|
|
175
|
-
if (!apiBaseUrl) {
|
|
176
|
-
return new Response(
|
|
177
|
-
JSON.stringify({ error: 'VITE_DOCYRUS_API_URL is not configured' }),
|
|
178
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const agentId = getAgentId(env);
|
|
183
|
-
|
|
184
|
-
if (!agentId) {
|
|
185
|
-
return new Response(
|
|
186
|
-
JSON.stringify({ error: 'VITE_DOCYRUS_AGENT_ID is not configured' }),
|
|
187
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const response = await fetch(`${apiBaseUrl}/v1/ai/agents/${agentId}/chat`, {
|
|
192
|
-
method: 'POST',
|
|
193
|
-
headers: {
|
|
194
|
-
'Content-Type': 'application/json',
|
|
195
|
-
Authorization: `Bearer ${token}`
|
|
196
|
-
},
|
|
197
|
-
body: JSON.stringify({
|
|
198
|
-
agentId,
|
|
199
|
-
messages: [{ role: 'system', content: COPILOT_SYSTEM_PROMPT }, { role: 'user', content: body.prompt }],
|
|
200
|
-
mode: 'agent',
|
|
201
|
-
stream: true
|
|
202
|
-
})
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
if (!response.ok) {
|
|
206
|
-
const errorText = await response.text();
|
|
207
|
-
|
|
208
|
-
return new Response(
|
|
209
|
-
errorText || JSON.stringify({ error: 'Backend API error' }),
|
|
210
|
-
{ status: response.status, headers: { 'Content-Type': 'application/json' } }
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return new Response(response.body, {
|
|
215
|
-
headers: {
|
|
216
|
-
'Content-Type': 'text/event-stream',
|
|
217
|
-
'Cache-Control': 'no-cache',
|
|
218
|
-
Connection: 'keep-alive'
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error('[AI Copilot] Error:', error);
|
|
223
|
-
|
|
224
|
-
return new Response(
|
|
225
|
-
JSON.stringify({ error: 'Internal server error', message: error instanceof Error ? error.message : 'Unknown error' }),
|
|
226
|
-
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/*
|
|
232
|
-
* ---------------------------------------------------------------------------
|
|
233
|
-
* Vite plugin (dev server middleware)
|
|
234
|
-
* ---------------------------------------------------------------------------
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
17
|
export function plateEditorPlugin(): Plugin {
|
|
238
18
|
let env: Record<string, string>;
|
|
239
19
|
|
package/src/worker.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
const COPILOT_SYSTEM_PROMPT = `You are an advanced AI writing assistant, similar to VSCode Copilot but for general text. Your task is to predict and generate the next part of the text based on the given context.
|
|
2
|
+
|
|
3
|
+
Rules:
|
|
4
|
+
- Continue the text naturally up to the next punctuation mark (., ,, ;, :, ?, or !).
|
|
5
|
+
- Maintain style and tone. Don't repeat given text.
|
|
6
|
+
- For unclear context, provide the most likely continuation.
|
|
7
|
+
- Handle code snippets, lists, or structured text if needed.
|
|
8
|
+
- Don't include """ in your response.
|
|
9
|
+
- CRITICAL: Always end with a punctuation mark.
|
|
10
|
+
- CRITICAL: Avoid starting a new block. Do not use block formatting like >, #, 1., 2., -, etc. The suggestion should continue in the same block as the context.
|
|
11
|
+
- If no context is provided or you can't generate a continuation, return "0" without explanation.`;
|
|
12
|
+
|
|
13
|
+
function getApiBaseUrl(env: Record<string, string>): string | undefined {
|
|
14
|
+
return env.VITE_DOCYRUS_API_URL;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getAgentId(env: Record<string, string>): string | undefined {
|
|
18
|
+
return env.VITE_DOCYRUS_EDITOR_AGENT_ID || env.VITE_DOCYRUS_AGENT_ID;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getAuthToken(request: Request): string | undefined {
|
|
22
|
+
const authHeader = request.headers.get('authorization');
|
|
23
|
+
|
|
24
|
+
return authHeader?.replace('Bearer ', '') || undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function handleAiCommand(
|
|
28
|
+
request: Request,
|
|
29
|
+
env: Record<string, string>
|
|
30
|
+
): Promise<Response> {
|
|
31
|
+
if (request.method !== 'POST') {
|
|
32
|
+
return new Response(JSON.stringify({ error: 'Method not allowed' }), {
|
|
33
|
+
status: 405,
|
|
34
|
+
headers: { 'Content-Type': 'application/json' }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const body = await request.json() as {
|
|
40
|
+
messages?: unknown[];
|
|
41
|
+
ctx?: { selection?: unknown; children?: unknown; toolName?: string };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const token = getAuthToken(request);
|
|
45
|
+
|
|
46
|
+
if (!token) {
|
|
47
|
+
return new Response(
|
|
48
|
+
JSON.stringify({ error: 'Unauthorized', message: 'No authentication token found. Please log in.' }),
|
|
49
|
+
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const apiBaseUrl = getApiBaseUrl(env);
|
|
54
|
+
|
|
55
|
+
if (!apiBaseUrl) {
|
|
56
|
+
return new Response(
|
|
57
|
+
JSON.stringify({ error: 'VITE_DOCYRUS_API_URL is not configured' }),
|
|
58
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const agentId = getAgentId(env);
|
|
63
|
+
|
|
64
|
+
if (!agentId) {
|
|
65
|
+
return new Response(
|
|
66
|
+
JSON.stringify({ error: 'VITE_DOCYRUS_AGENT_ID is not configured' }),
|
|
67
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { messages, ctx } = body;
|
|
72
|
+
|
|
73
|
+
let editorContext: string | undefined;
|
|
74
|
+
|
|
75
|
+
if (ctx) {
|
|
76
|
+
const contextData: Record<string, unknown> = { toolName: ctx.toolName };
|
|
77
|
+
|
|
78
|
+
if (ctx.selection) contextData.selection = ctx.selection;
|
|
79
|
+
if (ctx.children) contextData.children = ctx.children;
|
|
80
|
+
editorContext = JSON.stringify(contextData);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const response = await fetch(`${apiBaseUrl}/v1/ai/agents/${agentId}/chat`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: {
|
|
86
|
+
'Content-Type': 'application/json',
|
|
87
|
+
Authorization: `Bearer ${token}`
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
agentId,
|
|
91
|
+
messages: messages ?? [],
|
|
92
|
+
mode: 'agent',
|
|
93
|
+
stream: true,
|
|
94
|
+
additionalContext: editorContext
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
const errorText = await response.text();
|
|
100
|
+
|
|
101
|
+
return new Response(
|
|
102
|
+
errorText || JSON.stringify({ error: 'Backend API error' }),
|
|
103
|
+
{ status: response.status, headers: { 'Content-Type': 'application/json' } }
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return new Response(response.body, {
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'text/event-stream',
|
|
110
|
+
'Cache-Control': 'no-cache',
|
|
111
|
+
Connection: 'keep-alive'
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error('[AI Command] Error:', error);
|
|
116
|
+
|
|
117
|
+
return new Response(
|
|
118
|
+
JSON.stringify({ error: 'Internal server error', message: error instanceof Error ? error.message : 'Unknown error' }),
|
|
119
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function handleAiCopilot(
|
|
125
|
+
request: Request,
|
|
126
|
+
env: Record<string, string>
|
|
127
|
+
): Promise<Response> {
|
|
128
|
+
if (request.method !== 'POST') {
|
|
129
|
+
return new Response(JSON.stringify({ error: 'Method not allowed' }), {
|
|
130
|
+
status: 405,
|
|
131
|
+
headers: { 'Content-Type': 'application/json' }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const body = await request.json() as { prompt?: string };
|
|
137
|
+
|
|
138
|
+
const token = getAuthToken(request);
|
|
139
|
+
|
|
140
|
+
if (!token) {
|
|
141
|
+
return new Response(
|
|
142
|
+
JSON.stringify({ error: 'Unauthorized' }),
|
|
143
|
+
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const apiBaseUrl = getApiBaseUrl(env);
|
|
148
|
+
|
|
149
|
+
if (!apiBaseUrl) {
|
|
150
|
+
return new Response(
|
|
151
|
+
JSON.stringify({ error: 'VITE_DOCYRUS_API_URL is not configured' }),
|
|
152
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const agentId = getAgentId(env);
|
|
157
|
+
|
|
158
|
+
if (!agentId) {
|
|
159
|
+
return new Response(
|
|
160
|
+
JSON.stringify({ error: 'VITE_DOCYRUS_AGENT_ID is not configured' }),
|
|
161
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const response = await fetch(`${apiBaseUrl}/v1/ai/agents/${agentId}/chat`, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
Authorization: `Bearer ${token}`
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
agentId,
|
|
173
|
+
messages: [{ role: 'system', content: COPILOT_SYSTEM_PROMPT }, { role: 'user', content: body.prompt }],
|
|
174
|
+
mode: 'agent',
|
|
175
|
+
stream: true
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
const errorText = await response.text();
|
|
181
|
+
|
|
182
|
+
return new Response(
|
|
183
|
+
errorText || JSON.stringify({ error: 'Backend API error' }),
|
|
184
|
+
{ status: response.status, headers: { 'Content-Type': 'application/json' } }
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return new Response(response.body, {
|
|
189
|
+
headers: {
|
|
190
|
+
'Content-Type': 'text/event-stream',
|
|
191
|
+
'Cache-Control': 'no-cache',
|
|
192
|
+
Connection: 'keep-alive'
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error('[AI Copilot] Error:', error);
|
|
197
|
+
|
|
198
|
+
return new Response(
|
|
199
|
+
JSON.stringify({ error: 'Internal server error', message: error instanceof Error ? error.message : 'Unknown error' }),
|
|
200
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|