@docyrus/ui-pro-ai-assistant 0.0.2 → 0.0.5
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/components/assistant-animations.d.ts +3 -3
- package/dist/docy-assistant.d.ts +1 -1
- package/dist/index.js +74 -47
- package/dist/index.js.map +1 -1
- package/dist/styles.css +5137 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/views/assistant-view.d.ts +2 -2
- package/package.json +38 -36
- package/src/components/assistant-animations.tsx +0 -29
- package/src/components/assistant-dialogs.tsx +0 -235
- package/src/components/code-view.tsx +0 -278
- package/src/components/create-agent-task.tsx +0 -104
- package/src/components/create-new-work-version.tsx +0 -30
- package/src/components/extract-web.tsx +0 -160
- package/src/components/forward-to-agent.tsx +0 -90
- package/src/components/generate-chart.tsx +0 -101
- package/src/components/generative-action-button.tsx +0 -122
- package/src/components/generative-tool.tsx +0 -685
- package/src/components/generative-ui-object.tsx +0 -210
- package/src/components/input-area.tsx +0 -1209
- package/src/components/json-schema-layout.tsx +0 -326
- package/src/components/list-item-card.tsx +0 -92
- package/src/components/mermaid-diagram.tsx +0 -192
- package/src/components/preview-image.tsx +0 -47
- package/src/components/request-approval.tsx +0 -48
- package/src/components/request-user-input.tsx +0 -270
- package/src/components/search-web.tsx +0 -319
- package/src/components/sheet-command.tsx +0 -88
- package/src/components/shell-canvas.tsx +0 -122
- package/src/components/show-advanced-data-table.tsx +0 -352
- package/src/components/show-generated-content-options.tsx +0 -93
- package/src/components/show-people-cards.tsx +0 -180
- package/src/components/subagent-tool.tsx +0 -180
- package/src/components/text-editor-tool.tsx +0 -328
- package/src/components/work-canvas.tsx +0 -88
- package/src/components/work-card.tsx +0 -42
- package/src/declarations.d.ts +0 -1
- package/src/docy-assistant.tsx +0 -1962
- package/src/hooks/index.ts +0 -7
- package/src/hooks/use-assistant-api.ts +0 -507
- package/src/hooks/use-deployment-data.ts +0 -162
- package/src/hooks/use-project-state.ts +0 -347
- package/src/hooks/use-session-state.ts +0 -207
- package/src/hooks/use-speech-recognition.ts +0 -137
- package/src/hooks/use-ui-state.ts +0 -185
- package/src/hooks/use-works-state.ts +0 -146
- package/src/i18n/context.tsx +0 -253
- package/src/i18n/index.ts +0 -19
- package/src/i18n/locales/de.json +0 -198
- package/src/i18n/locales/el.json +0 -198
- package/src/i18n/locales/en.json +0 -226
- package/src/i18n/locales/es.json +0 -198
- package/src/i18n/locales/fr.json +0 -198
- package/src/i18n/locales/it.json +0 -198
- package/src/i18n/locales/pt.json +0 -198
- package/src/i18n/locales/sl.json +0 -198
- package/src/i18n/locales/tr.json +0 -211
- package/src/i18n/types.ts +0 -23
- package/src/i18n/use-translation.ts +0 -17
- package/src/index.ts +0 -18
- package/src/internal/plate-editor/editor/auth-context.ts +0 -11
- package/src/internal/plate-editor/editor/editor-base-kit.tsx +0 -39
- package/src/internal/plate-editor/editor/editor-kit.tsx +0 -89
- package/src/internal/plate-editor/editor/plate-editor.tsx +0 -75
- package/src/internal/plate-editor/editor/plate-types.ts +0 -126
- package/src/internal/plate-editor/editor/plugins/ai-kit.tsx +0 -172
- package/src/internal/plate-editor/editor/plugins/autoformat-kit.tsx +0 -211
- package/src/internal/plate-editor/editor/plugins/basic-blocks-base-kit.tsx +0 -26
- package/src/internal/plate-editor/editor/plugins/basic-blocks-kit.tsx +0 -51
- package/src/internal/plate-editor/editor/plugins/basic-marks-base-kit.tsx +0 -24
- package/src/internal/plate-editor/editor/plugins/basic-marks-kit.tsx +0 -38
- package/src/internal/plate-editor/editor/plugins/basic-nodes-kit.tsx +0 -6
- package/src/internal/plate-editor/editor/plugins/block-menu-kit.tsx +0 -14
- package/src/internal/plate-editor/editor/plugins/block-placeholder-kit.tsx +0 -17
- package/src/internal/plate-editor/editor/plugins/block-selection-kit.tsx +0 -31
- package/src/internal/plate-editor/editor/plugins/callout-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/callout-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/code-block-base-kit.tsx +0 -23
- package/src/internal/plate-editor/editor/plugins/code-block-kit.tsx +0 -26
- package/src/internal/plate-editor/editor/plugins/column-base-kit.tsx +0 -8
- package/src/internal/plate-editor/editor/plugins/column-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/comment-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/comment-kit.tsx +0 -174
- package/src/internal/plate-editor/editor/plugins/copilot-kit.tsx +0 -68
- package/src/internal/plate-editor/editor/plugins/cursor-overlay-kit.tsx +0 -13
- package/src/internal/plate-editor/editor/plugins/date-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/date-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/discussion-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/dnd-kit.tsx +0 -27
- package/src/internal/plate-editor/editor/plugins/docx-export-kit.tsx +0 -43
- package/src/internal/plate-editor/editor/plugins/docx-kit.tsx +0 -6
- package/src/internal/plate-editor/editor/plugins/emoji-kit.tsx +0 -15
- package/src/internal/plate-editor/editor/plugins/exit-break-kit.tsx +0 -12
- package/src/internal/plate-editor/editor/plugins/floating-toolbar-kit.tsx +0 -19
- package/src/internal/plate-editor/editor/plugins/font-base-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/font-kit.tsx +0 -47
- package/src/internal/plate-editor/editor/plugins/indent-base-kit.tsx +0 -19
- package/src/internal/plate-editor/editor/plugins/indent-kit.tsx +0 -22
- package/src/internal/plate-editor/editor/plugins/link-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/link-kit.tsx +0 -35
- package/src/internal/plate-editor/editor/plugins/list-base-kit.tsx +0 -24
- package/src/internal/plate-editor/editor/plugins/list-kit.tsx +0 -27
- package/src/internal/plate-editor/editor/plugins/markdown-kit.tsx +0 -18
- package/src/internal/plate-editor/editor/plugins/math-base-kit.tsx +0 -8
- package/src/internal/plate-editor/editor/plugins/math-kit.tsx +0 -10
- package/src/internal/plate-editor/editor/plugins/media-base-kit.tsx +0 -37
- package/src/internal/plate-editor/editor/plugins/media-kit.tsx +0 -53
- package/src/internal/plate-editor/editor/plugins/mention-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/mention-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/slash-kit.tsx +0 -17
- package/src/internal/plate-editor/editor/plugins/suggestion-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/suggestion-kit.tsx +0 -95
- package/src/internal/plate-editor/editor/plugins/table-base-kit.tsx +0 -20
- package/src/internal/plate-editor/editor/plugins/table-kit.tsx +0 -22
- package/src/internal/plate-editor/editor/plugins/toc-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/toc-kit.tsx +0 -14
- package/src/internal/plate-editor/editor/plugins/toggle-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/toggle-kit.tsx +0 -9
- package/src/internal/plate-editor/editor/transforms.ts +0 -165
- package/src/internal/plate-editor/editor/use-chat.ts +0 -152
- package/src/internal/plate-editor/hooks/index.ts +0 -3
- package/src/internal/plate-editor/hooks/use-copy-to-clipboard.ts +0 -31
- package/src/internal/plate-editor/hooks/use-is-touch-device.ts +0 -26
- package/src/internal/plate-editor/hooks/use-lock-scroll.ts +0 -21
- package/src/internal/plate-editor/hooks/use-media-query.ts +0 -44
- package/src/internal/plate-editor/hooks/use-mounted.ts +0 -18
- package/src/internal/plate-editor/hooks/use-on-click-outside.ts +0 -114
- package/src/internal/plate-editor/hooks/use-upload-file.ts +0 -81
- package/src/internal/plate-editor/i18n/context.tsx +0 -58
- package/src/internal/plate-editor/i18n/index.ts +0 -3
- package/src/internal/plate-editor/i18n/locales/de.json +0 -57
- package/src/internal/plate-editor/i18n/locales/el.json +0 -57
- package/src/internal/plate-editor/i18n/locales/en.json +0 -57
- package/src/internal/plate-editor/i18n/locales/es.json +0 -57
- package/src/internal/plate-editor/i18n/locales/fr.json +0 -57
- package/src/internal/plate-editor/i18n/locales/it.json +0 -57
- package/src/internal/plate-editor/i18n/locales/pt.json +0 -57
- package/src/internal/plate-editor/i18n/locales/sl.json +0 -57
- package/src/internal/plate-editor/i18n/locales/tr.json +0 -57
- package/src/internal/plate-editor/i18n/types.ts +0 -59
- package/src/internal/plate-editor/i18n/use-translation.ts +0 -22
- package/src/internal/plate-editor/index.ts +0 -39
- package/src/internal/plate-editor/lib/ai-output-converter.ts +0 -153
- package/src/internal/plate-editor/lib/download-file.ts +0 -17
- package/src/internal/plate-editor/plate-ui/ai-chat-editor.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/ai-menu.tsx +0 -828
- package/src/internal/plate-editor/plate-ui/ai-node.tsx +0 -41
- package/src/internal/plate-editor/plate-ui/ai-toolbar-button.tsx +0 -25
- package/src/internal/plate-editor/plate-ui/alert-dialog.tsx +0 -145
- package/src/internal/plate-editor/plate-ui/align-toolbar-button.tsx +0 -88
- package/src/internal/plate-editor/plate-ui/avatar.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/block-context-menu.tsx +0 -104
- package/src/internal/plate-editor/plate-ui/block-discussion.tsx +0 -364
- package/src/internal/plate-editor/plate-ui/block-draggable.tsx +0 -557
- package/src/internal/plate-editor/plate-ui/block-list-static.tsx +0 -77
- package/src/internal/plate-editor/plate-ui/block-list.tsx +0 -85
- package/src/internal/plate-editor/plate-ui/block-menu.tsx +0 -555
- package/src/internal/plate-editor/plate-ui/block-selection.tsx +0 -47
- package/src/internal/plate-editor/plate-ui/block-suggestion.tsx +0 -469
- package/src/internal/plate-editor/plate-ui/blockquote-node-static.tsx +0 -10
- package/src/internal/plate-editor/plate-ui/blockquote-node.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/button.tsx +0 -201
- package/src/internal/plate-editor/plate-ui/calendar.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/callout-node-static.tsx +0 -76
- package/src/internal/plate-editor/plate-ui/callout-node.tsx +0 -54
- package/src/internal/plate-editor/plate-ui/caption.tsx +0 -47
- package/src/internal/plate-editor/plate-ui/checkbox.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/code-block-node-static.tsx +0 -172
- package/src/internal/plate-editor/plate-ui/code-block-node.tsx +0 -226
- package/src/internal/plate-editor/plate-ui/code-node-static.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/code-node.tsx +0 -12
- package/src/internal/plate-editor/plate-ui/column-node-static.tsx +0 -65
- package/src/internal/plate-editor/plate-ui/column-node.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/command.tsx +0 -202
- package/src/internal/plate-editor/plate-ui/comment-node-static.tsx +0 -12
- package/src/internal/plate-editor/plate-ui/comment-node.tsx +0 -45
- package/src/internal/plate-editor/plate-ui/comment-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/comment.tsx +0 -619
- package/src/internal/plate-editor/plate-ui/cursor-overlay.tsx +0 -85
- package/src/internal/plate-editor/plate-ui/date-node-static.tsx +0 -43
- package/src/internal/plate-editor/plate-ui/date-node.tsx +0 -54
- package/src/internal/plate-editor/plate-ui/dialog.tsx +0 -445
- package/src/internal/plate-editor/plate-ui/dropdown-menu.tsx +0 -264
- package/src/internal/plate-editor/plate-ui/editor-static.tsx +0 -40
- package/src/internal/plate-editor/plate-ui/editor.tsx +0 -146
- package/src/internal/plate-editor/plate-ui/emoji-node.tsx +0 -48
- package/src/internal/plate-editor/plate-ui/emoji-toolbar-button.tsx +0 -626
- package/src/internal/plate-editor/plate-ui/equation-node-static.tsx +0 -155
- package/src/internal/plate-editor/plate-ui/equation-node.tsx +0 -226
- package/src/internal/plate-editor/plate-ui/equation-toolbar-button.tsx +0 -26
- package/src/internal/plate-editor/plate-ui/export-toolbar-button.tsx +0 -206
- package/src/internal/plate-editor/plate-ui/fixed-toolbar-buttons.tsx +0 -157
- package/src/internal/plate-editor/plate-ui/fixed-toolbar.tsx +0 -25
- package/src/internal/plate-editor/plate-ui/floating-discussion.tsx +0 -1129
- package/src/internal/plate-editor/plate-ui/floating-toolbar-buttons.tsx +0 -129
- package/src/internal/plate-editor/plate-ui/floating-toolbar.tsx +0 -97
- package/src/internal/plate-editor/plate-ui/font-color-toolbar-button.tsx +0 -209
- package/src/internal/plate-editor/plate-ui/font-size-toolbar-button.tsx +0 -152
- package/src/internal/plate-editor/plate-ui/ghost-text.tsx +0 -20
- package/src/internal/plate-editor/plate-ui/heading-node-static.tsx +0 -52
- package/src/internal/plate-editor/plate-ui/heading-node.tsx +0 -56
- package/src/internal/plate-editor/plate-ui/highlight-node-static.tsx +0 -9
- package/src/internal/plate-editor/plate-ui/highlight-node.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/history-toolbar-button.tsx +0 -50
- package/src/internal/plate-editor/plate-ui/hover-card.tsx +0 -7
- package/src/internal/plate-editor/plate-ui/hr-node-static.tsx +0 -18
- package/src/internal/plate-editor/plate-ui/hr-node.tsx +0 -28
- package/src/internal/plate-editor/plate-ui/import-toolbar-button.tsx +0 -122
- package/src/internal/plate-editor/plate-ui/indent-toolbar-button.tsx +0 -32
- package/src/internal/plate-editor/plate-ui/inline-combobox.tsx +0 -409
- package/src/internal/plate-editor/plate-ui/input.tsx +0 -37
- package/src/internal/plate-editor/plate-ui/insert-toolbar-button.tsx +0 -258
- package/src/internal/plate-editor/plate-ui/label.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/line-height-toolbar-button.tsx +0 -69
- package/src/internal/plate-editor/plate-ui/link-node-static.tsx +0 -15
- package/src/internal/plate-editor/plate-ui/link-node.tsx +0 -33
- package/src/internal/plate-editor/plate-ui/link-toolbar-button.tsx +0 -28
- package/src/internal/plate-editor/plate-ui/link-toolbar.tsx +0 -147
- package/src/internal/plate-editor/plate-ui/list-toolbar-button.tsx +0 -177
- package/src/internal/plate-editor/plate-ui/mark-toolbar-button.tsx +0 -34
- package/src/internal/plate-editor/plate-ui/media-audio-node-static.tsx +0 -21
- package/src/internal/plate-editor/plate-ui/media-audio-node.tsx +0 -32
- package/src/internal/plate-editor/plate-ui/media-embed-node.tsx +0 -103
- package/src/internal/plate-editor/plate-ui/media-file-node-static.tsx +0 -30
- package/src/internal/plate-editor/plate-ui/media-file-node.tsx +0 -52
- package/src/internal/plate-editor/plate-ui/media-image-node-static.tsx +0 -37
- package/src/internal/plate-editor/plate-ui/media-image-node.tsx +0 -183
- package/src/internal/plate-editor/plate-ui/media-placeholder-node.tsx +0 -441
- package/src/internal/plate-editor/plate-ui/media-preview-dialog.tsx +0 -127
- package/src/internal/plate-editor/plate-ui/media-toolbar-button.tsx +0 -227
- package/src/internal/plate-editor/plate-ui/media-toolbar.tsx +0 -214
- package/src/internal/plate-editor/plate-ui/media-upload-toast.tsx +0 -73
- package/src/internal/plate-editor/plate-ui/media-video-node-static.tsx +0 -35
- package/src/internal/plate-editor/plate-ui/media-video-node.tsx +0 -119
- package/src/internal/plate-editor/plate-ui/mention-node-static.tsx +0 -46
- package/src/internal/plate-editor/plate-ui/mention-node.tsx +0 -79
- package/src/internal/plate-editor/plate-ui/menu.tsx +0 -539
- package/src/internal/plate-editor/plate-ui/mode-toolbar-button.tsx +0 -124
- package/src/internal/plate-editor/plate-ui/more-toolbar-button.tsx +0 -34
- package/src/internal/plate-editor/plate-ui/paragraph-node-static.tsx +0 -15
- package/src/internal/plate-editor/plate-ui/paragraph-node.tsx +0 -16
- package/src/internal/plate-editor/plate-ui/popover.tsx +0 -75
- package/src/internal/plate-editor/plate-ui/progress.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/remote-cursor-overlay.tsx +0 -79
- package/src/internal/plate-editor/plate-ui/resize-handle.tsx +0 -86
- package/src/internal/plate-editor/plate-ui/separator.tsx +0 -41
- package/src/internal/plate-editor/plate-ui/slash-node.tsx +0 -433
- package/src/internal/plate-editor/plate-ui/spinner.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/suggestion-node-static.tsx +0 -35
- package/src/internal/plate-editor/plate-ui/suggestion-node.tsx +0 -166
- package/src/internal/plate-editor/plate-ui/suggestion-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/table-node-static.tsx +0 -84
- package/src/internal/plate-editor/plate-ui/table-node.tsx +0 -283
- package/src/internal/plate-editor/plate-ui/table-toolbar-button.tsx +0 -252
- package/src/internal/plate-editor/plate-ui/tabs.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/textarea.tsx +0 -57
- package/src/internal/plate-editor/plate-ui/toc-node-static.tsx +0 -142
- package/src/internal/plate-editor/plate-ui/toc-node.tsx +0 -57
- package/src/internal/plate-editor/plate-ui/toc-sidebar.tsx +0 -48
- package/src/internal/plate-editor/plate-ui/toggle-node-static.tsx +0 -18
- package/src/internal/plate-editor/plate-ui/toggle-node.tsx +0 -33
- package/src/internal/plate-editor/plate-ui/toggle-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/toggle.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/toolbar.tsx +0 -378
- package/src/internal/plate-editor/plate-ui/tooltip.tsx +0 -148
- package/src/internal/plate-editor/plate-ui/turn-into-toolbar-button.tsx +0 -175
- package/src/internal/plate-editor/types/index.ts +0 -22
- package/src/internal/plate-editor/vite.ts +0 -284
- package/src/internal/sheets/components/univer-sheets.tsx +0 -1104
- package/src/internal/sheets/i18n/context.tsx +0 -183
- package/src/internal/sheets/i18n/index.ts +0 -19
- package/src/internal/sheets/i18n/locales/de.json +0 -21
- package/src/internal/sheets/i18n/locales/el.json +0 -21
- package/src/internal/sheets/i18n/locales/en.json +0 -21
- package/src/internal/sheets/i18n/locales/es.json +0 -21
- package/src/internal/sheets/i18n/locales/fr.json +0 -21
- package/src/internal/sheets/i18n/locales/it.json +0 -21
- package/src/internal/sheets/i18n/locales/pt.json +0 -21
- package/src/internal/sheets/i18n/locales/sl.json +0 -21
- package/src/internal/sheets/i18n/locales/tr.json +0 -21
- package/src/internal/sheets/i18n/types.ts +0 -23
- package/src/internal/sheets/i18n/use-translation.ts +0 -17
- package/src/internal/sheets/index.ts +0 -14
- package/src/internal/sheets/types/css.d.ts +0 -11
- package/src/internal/sheets/types/index.ts +0 -260
- package/src/internal/sheets/xlsx.ts +0 -1169
- package/src/lib/api-client.ts +0 -77
- package/src/lib/assistant-api-actions.ts +0 -549
- package/src/lib/assistant-config.tsx +0 -75
- package/src/lib/class-utils.ts +0 -40
- package/src/lib/index.ts +0 -7
- package/src/lib/message-utils.ts +0 -131
- package/src/tools/tools-schema.json +0 -512
- package/src/types/index.ts +0 -235
- package/src/views/assistant-view.tsx +0 -1137
- package/src/views/canvas-app.tsx +0 -839
- package/src/views/canvas-code.tsx +0 -93
- package/src/views/canvas-deep-research.tsx +0 -44
- package/src/views/canvas-image.tsx +0 -25
- package/src/views/canvas-record-view.tsx +0 -285
- package/src/views/canvas-spreadsheet.tsx +0 -125
- package/src/views/canvas-text.tsx +0 -52
- package/src/views/canvas.tsx +0 -274
- package/src/views/chat-panel.tsx +0 -149
- package/src/views/index.ts +0 -20
- package/src/views/memories-panel.tsx +0 -365
- package/src/views/message-list.tsx +0 -370
- package/src/views/project-detail.tsx +0 -257
- package/src/views/projects-panel.tsx +0 -131
- package/src/views/sessions-list.tsx +0 -98
- package/src/views/sidebar-content.tsx +0 -256
- package/src/views/work-detail.tsx +0 -98
- package/src/vite.ts +0 -64
- package/src/worker.ts +0 -203
package/src/hooks/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { useAssistantApi } from './use-assistant-api';
|
|
2
|
-
export { useDeploymentData } from './use-deployment-data';
|
|
3
|
-
export { type ProjectState, useProjectState } from './use-project-state';
|
|
4
|
-
export { type SessionState, useSessionState } from './use-session-state';
|
|
5
|
-
export { useSpeechRecognition } from './use-speech-recognition';
|
|
6
|
-
export { createInitialUIState, type UIState, useUIState } from './use-ui-state';
|
|
7
|
-
export { useWorksState, type WorksState } from './use-works-state';
|
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useCallback, useEffect, useRef, useState
|
|
5
|
-
} from 'react';
|
|
6
|
-
|
|
7
|
-
import { toast } from 'sonner';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
type ApiResponse,
|
|
11
|
-
type AssistantSession,
|
|
12
|
-
type Project,
|
|
13
|
-
type Work
|
|
14
|
-
} from '../types';
|
|
15
|
-
|
|
16
|
-
import { useApiClient } from '../lib/api-client';
|
|
17
|
-
import { useAssistantConfig } from '../lib/assistant-config';
|
|
18
|
-
|
|
19
|
-
interface UseAssistantApiProps {
|
|
20
|
-
tenantAiAgentId: string;
|
|
21
|
-
deploymentId?: string;
|
|
22
|
-
logo?: string;
|
|
23
|
-
title?: string;
|
|
24
|
-
t: (key: string) => string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface UseAssistantApiReturn {
|
|
28
|
-
// State
|
|
29
|
-
agentDetails: { logo?: string; name?: string; welcomeMessage?: string } | null;
|
|
30
|
-
isLoadingAgentDetails: boolean;
|
|
31
|
-
|
|
32
|
-
// Thread operations
|
|
33
|
-
fetchThreads: () => Promise<AssistantSession[]>;
|
|
34
|
-
fetchProjectThreads: (projectId: string) => Promise<AssistantSession[]>;
|
|
35
|
-
loadThreadMessages: (threadId: string) => Promise<any[]>;
|
|
36
|
-
createThread: (params: {
|
|
37
|
-
subject: string;
|
|
38
|
-
bodyText: string;
|
|
39
|
-
senderName: string;
|
|
40
|
-
projectId?: string | null;
|
|
41
|
-
}) => Promise<any>;
|
|
42
|
-
|
|
43
|
-
// Project operations
|
|
44
|
-
fetchProjects: () => Promise<Project[]>;
|
|
45
|
-
createProject: (params: {
|
|
46
|
-
name: string;
|
|
47
|
-
description?: string;
|
|
48
|
-
instructions?: string;
|
|
49
|
-
userId?: string;
|
|
50
|
-
}) => Promise<Project | null>;
|
|
51
|
-
updateProject: (projectId: string, params: {
|
|
52
|
-
name?: string;
|
|
53
|
-
description?: string;
|
|
54
|
-
instructions?: string;
|
|
55
|
-
}) => Promise<boolean>;
|
|
56
|
-
deleteProject: (projectId: string) => Promise<boolean>;
|
|
57
|
-
|
|
58
|
-
// Work operations
|
|
59
|
-
fetchWorks: () => Promise<Work[]>;
|
|
60
|
-
fetchProjectWorks: (projectId: string) => Promise<Work[]>;
|
|
61
|
-
|
|
62
|
-
// Session operations
|
|
63
|
-
updateSession: (sessionId: string, subject: string) => Promise<boolean>;
|
|
64
|
-
deleteSession: (sessionId: string) => Promise<boolean>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function useAssistantApi({
|
|
68
|
-
tenantAiAgentId,
|
|
69
|
-
deploymentId,
|
|
70
|
-
logo,
|
|
71
|
-
title,
|
|
72
|
-
t
|
|
73
|
-
}: UseAssistantApiProps): UseAssistantApiReturn {
|
|
74
|
-
const apiClient = useApiClient();
|
|
75
|
-
const { user: configUser } = useAssistantConfig();
|
|
76
|
-
const [agentDetails, setAgentDetails] = useState<{ logo?: string; name?: string; welcomeMessage?: string } | null>(null);
|
|
77
|
-
const [isLoadingAgentDetails, setIsLoadingAgentDetails] = useState(!!tenantAiAgentId);
|
|
78
|
-
const apiClientRef = useRef(apiClient);
|
|
79
|
-
const fetchedAgentIdRef = useRef<string | null>(null);
|
|
80
|
-
|
|
81
|
-
apiClientRef.current = apiClient;
|
|
82
|
-
|
|
83
|
-
// Fetch agent details whenever tenantAiAgentId or deploymentId changes
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
const effectiveId = deploymentId || tenantAiAgentId;
|
|
86
|
-
const endpoint = deploymentId ? `/ai/agent-deployments/${deploymentId}` : `/ai/agent-deployments/base/${tenantAiAgentId}`;
|
|
87
|
-
|
|
88
|
-
if (!effectiveId || fetchedAgentIdRef.current === effectiveId) return;
|
|
89
|
-
|
|
90
|
-
let cancelled = false;
|
|
91
|
-
|
|
92
|
-
const fetchAgentDetails = async () => {
|
|
93
|
-
setAgentDetails(null);
|
|
94
|
-
setIsLoadingAgentDetails(true);
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const response: any = await apiClientRef.current.get(endpoint);
|
|
98
|
-
|
|
99
|
-
if (cancelled) return;
|
|
100
|
-
|
|
101
|
-
fetchedAgentIdRef.current = effectiveId;
|
|
102
|
-
|
|
103
|
-
if (response.success && response.data) {
|
|
104
|
-
const { data } = response;
|
|
105
|
-
const avatar = data.avatar?.signed_url || data.agent?.avatar?.signed_url;
|
|
106
|
-
const name = data.name || data.agent?.agentName || data.agent?.name;
|
|
107
|
-
const welcomeMessage = data.welcomeMessage || data.agent?.welcomeMessage;
|
|
108
|
-
|
|
109
|
-
setAgentDetails({ logo: avatar, name, welcomeMessage });
|
|
110
|
-
} else {
|
|
111
|
-
setAgentDetails({ logo, name: title });
|
|
112
|
-
}
|
|
113
|
-
} catch (err) {
|
|
114
|
-
console.error('[useAssistantApi] fetch error:', err);
|
|
115
|
-
if (cancelled) return;
|
|
116
|
-
fetchedAgentIdRef.current = effectiveId;
|
|
117
|
-
setAgentDetails({ logo, name: title });
|
|
118
|
-
} finally {
|
|
119
|
-
if (!cancelled) setIsLoadingAgentDetails(false);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
fetchAgentDetails();
|
|
124
|
-
|
|
125
|
-
return () => {
|
|
126
|
-
cancelled = true;
|
|
127
|
-
};
|
|
128
|
-
}, [
|
|
129
|
-
tenantAiAgentId,
|
|
130
|
-
deploymentId,
|
|
131
|
-
logo,
|
|
132
|
-
title
|
|
133
|
-
]);
|
|
134
|
-
|
|
135
|
-
// Thread operations
|
|
136
|
-
const fetchThreads = useCallback(async (): Promise<AssistantSession[]> => {
|
|
137
|
-
try {
|
|
138
|
-
const apiParams: any = {
|
|
139
|
-
columns: 'id,subject,created_on,last_modified_on,body_text,tenant_ai_agent_id',
|
|
140
|
-
orderBy: JSON.stringify({ field: 'created_on', direction: 'desc' })
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
apiParams.filters = JSON.stringify({
|
|
144
|
-
rules: [
|
|
145
|
-
{
|
|
146
|
-
field: 'tenant_ai_agent_id',
|
|
147
|
-
operator: '=',
|
|
148
|
-
value: tenantAiAgentId
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const response = (await apiClient.get('/apps/base/data-sources/thread/items', apiParams)) as ApiResponse<
|
|
154
|
-
Array<any>
|
|
155
|
-
>;
|
|
156
|
-
|
|
157
|
-
if (response.success && response.data) {
|
|
158
|
-
const items = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
159
|
-
|
|
160
|
-
return items.map((item: any) => ({
|
|
161
|
-
id: item.id,
|
|
162
|
-
title: item.subject,
|
|
163
|
-
messages: [],
|
|
164
|
-
createdAt: new Date(item.created_on),
|
|
165
|
-
updatedAt: new Date(item.last_modified_on || item.created_on)
|
|
166
|
-
}));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return [];
|
|
170
|
-
} catch (error) {
|
|
171
|
-
console.error('Failed to fetch threads:', error);
|
|
172
|
-
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
}, [apiClient, tenantAiAgentId]);
|
|
176
|
-
|
|
177
|
-
const fetchProjectThreads = useCallback(async (projectId: string): Promise<AssistantSession[]> => {
|
|
178
|
-
try {
|
|
179
|
-
const apiParams: any = {
|
|
180
|
-
columns: 'id,subject,created_on,last_modified_on,body_text,tenant_ai_agent_id,tenant_ai_project_id ',
|
|
181
|
-
orderBy: JSON.stringify({ field: 'created_on', direction: 'desc' })
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
apiParams.filters = JSON.stringify({
|
|
185
|
-
rules: [
|
|
186
|
-
{
|
|
187
|
-
field: 'tenant_ai_project_id ',
|
|
188
|
-
operator: '=',
|
|
189
|
-
value: projectId
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const response = (await apiClient.get('/apps/base/data-sources/thread/items', apiParams)) as ApiResponse<
|
|
195
|
-
Array<any>
|
|
196
|
-
>;
|
|
197
|
-
|
|
198
|
-
if (response.success && response.data) {
|
|
199
|
-
const items = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
200
|
-
|
|
201
|
-
return items.map((item: any) => ({
|
|
202
|
-
id: item.id,
|
|
203
|
-
title: item.subject,
|
|
204
|
-
messages: [],
|
|
205
|
-
createdAt: new Date(item.created_on),
|
|
206
|
-
updatedAt: new Date(item.last_modified_on)
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return [];
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error('Failed to fetch project threads:', error);
|
|
213
|
-
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
}, [apiClient]);
|
|
217
|
-
|
|
218
|
-
const loadThreadMessages = useCallback(async (threadId: string): Promise<any[]> => {
|
|
219
|
-
try {
|
|
220
|
-
const response = (await apiClient.get('/apps/base/data-sources/message/items', {
|
|
221
|
-
columns: 'body_json,created_on,record_owner,role',
|
|
222
|
-
filters: JSON.stringify({
|
|
223
|
-
rules: [
|
|
224
|
-
{
|
|
225
|
-
field: 'thread',
|
|
226
|
-
operator: '=',
|
|
227
|
-
value: threadId
|
|
228
|
-
}
|
|
229
|
-
]
|
|
230
|
-
}),
|
|
231
|
-
sort: JSON.stringify([{ field: 'created_on', direction: 'asc' }])
|
|
232
|
-
})) as ApiResponse<Array<any>>;
|
|
233
|
-
|
|
234
|
-
if (response.success && response.data) {
|
|
235
|
-
return response.data;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return [];
|
|
239
|
-
} catch (error) {
|
|
240
|
-
console.error('Error loading thread messages:', error);
|
|
241
|
-
|
|
242
|
-
return [];
|
|
243
|
-
}
|
|
244
|
-
}, [apiClient]);
|
|
245
|
-
|
|
246
|
-
const createThread = useCallback(async (params: {
|
|
247
|
-
subject: string;
|
|
248
|
-
bodyText: string;
|
|
249
|
-
senderName: string;
|
|
250
|
-
projectId?: string | null;
|
|
251
|
-
}): Promise<any> => {
|
|
252
|
-
const response = (await apiClient.post('/apps/base/data-sources/thread/items', {
|
|
253
|
-
subject: params.subject,
|
|
254
|
-
body_text: params.bodyText,
|
|
255
|
-
sender_name: params.senderName,
|
|
256
|
-
thread_type: 'assistant',
|
|
257
|
-
tenant_ai_agent_deployment_id: deploymentId ? String(deploymentId) : null,
|
|
258
|
-
tenant_ai_agent_id: String(tenantAiAgentId),
|
|
259
|
-
tenant_ai_project_id: params.projectId || null
|
|
260
|
-
})) as ApiResponse<any>;
|
|
261
|
-
|
|
262
|
-
if (response && response.success && response.data) {
|
|
263
|
-
return response.data;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
throw new Error('Failed to create thread');
|
|
267
|
-
}, [apiClient, deploymentId, tenantAiAgentId]);
|
|
268
|
-
|
|
269
|
-
// Project operations
|
|
270
|
-
const fetchProjects = useCallback(async (): Promise<Project[]> => {
|
|
271
|
-
try {
|
|
272
|
-
const userId = configUser?.id || null;
|
|
273
|
-
const response = (await apiClient.get('/ai/projects')) as ApiResponse<Array<any>>;
|
|
274
|
-
|
|
275
|
-
if (response.success && response.data) {
|
|
276
|
-
const responseItems = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
277
|
-
const allProjects: Array<Project> = responseItems.map((item: any) => ({
|
|
278
|
-
id: item.id,
|
|
279
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
280
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
281
|
-
name: item.name,
|
|
282
|
-
description: item.description,
|
|
283
|
-
created_by: item.created_by,
|
|
284
|
-
shared_to: item.shared_to
|
|
285
|
-
}));
|
|
286
|
-
|
|
287
|
-
// Filter projects by user if userId is available
|
|
288
|
-
return userId ? allProjects.filter(
|
|
289
|
-
project => project.created_by === userId || (project.shared_to && project.shared_to.includes(userId))
|
|
290
|
-
) : allProjects;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return [];
|
|
294
|
-
} catch (error) {
|
|
295
|
-
console.error('Failed to fetch projects:', error);
|
|
296
|
-
|
|
297
|
-
return [];
|
|
298
|
-
}
|
|
299
|
-
}, [apiClient, configUser?.id]);
|
|
300
|
-
|
|
301
|
-
const createProject = useCallback(async (params: {
|
|
302
|
-
name: string;
|
|
303
|
-
description?: string;
|
|
304
|
-
instructions?: string;
|
|
305
|
-
userId?: string;
|
|
306
|
-
}): Promise<Project | null> => {
|
|
307
|
-
try {
|
|
308
|
-
const response = (await apiClient.post('/ai/projects', {
|
|
309
|
-
name: params.name,
|
|
310
|
-
description: params.description,
|
|
311
|
-
instructions: params.instructions,
|
|
312
|
-
tenant_ai_agent_id: tenantAiAgentId,
|
|
313
|
-
tenant_ai_agent_deployment_id: deploymentId,
|
|
314
|
-
created_by: params.userId
|
|
315
|
-
})) as ApiResponse<any>;
|
|
316
|
-
|
|
317
|
-
if (response.success && response.data) {
|
|
318
|
-
toast.success(t('toast.project_created_success'));
|
|
319
|
-
|
|
320
|
-
return response.data as Project;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
throw new Error('Failed to create project');
|
|
324
|
-
} catch (error) {
|
|
325
|
-
console.error('Error creating project:', error);
|
|
326
|
-
toast.error(t('toast.failed_create_project'));
|
|
327
|
-
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
}, [
|
|
331
|
-
apiClient,
|
|
332
|
-
tenantAiAgentId,
|
|
333
|
-
deploymentId,
|
|
334
|
-
t
|
|
335
|
-
]);
|
|
336
|
-
|
|
337
|
-
const updateProject = useCallback(async (projectId: string, params: {
|
|
338
|
-
name?: string;
|
|
339
|
-
description?: string;
|
|
340
|
-
instructions?: string;
|
|
341
|
-
}): Promise<boolean> => {
|
|
342
|
-
try {
|
|
343
|
-
const response: ApiResponse = await apiClient.patch(`/ai/projects/${projectId}`, params);
|
|
344
|
-
|
|
345
|
-
if (response.success) {
|
|
346
|
-
toast.success(t('toast.project_updated_success'));
|
|
347
|
-
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
throw new Error('Failed to update project');
|
|
352
|
-
} catch (error) {
|
|
353
|
-
console.error('Error updating project:', error);
|
|
354
|
-
toast.error(t('toast.failed_update_project'));
|
|
355
|
-
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
}, [apiClient, t]);
|
|
359
|
-
|
|
360
|
-
const deleteProject = useCallback(async (projectId: string): Promise<boolean> => {
|
|
361
|
-
try {
|
|
362
|
-
const response: ApiResponse = await apiClient.delete(`/ai/projects/${projectId}`);
|
|
363
|
-
|
|
364
|
-
if (response.success) {
|
|
365
|
-
toast.success(t('toast.project_deleted_success'));
|
|
366
|
-
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
throw new Error('Failed to delete project');
|
|
371
|
-
} catch (error) {
|
|
372
|
-
console.error('Error deleting project:', error);
|
|
373
|
-
toast.error(t('toast.failed_delete_project'));
|
|
374
|
-
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
}, [apiClient, t]);
|
|
378
|
-
|
|
379
|
-
// Work operations
|
|
380
|
-
const fetchWorks = useCallback(async (): Promise<Work[]> => {
|
|
381
|
-
try {
|
|
382
|
-
const response = (await apiClient.get('/ai/works')) as ApiResponse<Array<any>>;
|
|
383
|
-
|
|
384
|
-
if (response.success && response.data) {
|
|
385
|
-
const worksItems = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
386
|
-
|
|
387
|
-
return worksItems.map((item: any) => ({
|
|
388
|
-
id: item.id,
|
|
389
|
-
title: item.title,
|
|
390
|
-
base_thread_id: item.base_thread_id,
|
|
391
|
-
content_json: item.content_json,
|
|
392
|
-
content_text: item.content_text,
|
|
393
|
-
description: item.description,
|
|
394
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
395
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
396
|
-
tenant_data_source_id: item.tenant_data_source_id,
|
|
397
|
-
tenant_ai_project_id: item.tenant_ai_project_id,
|
|
398
|
-
type: item.type,
|
|
399
|
-
created_by: item.created_by,
|
|
400
|
-
created_on: item.created_on,
|
|
401
|
-
last_modified_on: item.last_modified_on,
|
|
402
|
-
image_url: item.image_url || undefined
|
|
403
|
-
}));
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return [];
|
|
407
|
-
} catch (error) {
|
|
408
|
-
console.error('Failed to fetch works:', error);
|
|
409
|
-
|
|
410
|
-
return [];
|
|
411
|
-
}
|
|
412
|
-
}, [apiClient]);
|
|
413
|
-
|
|
414
|
-
const fetchProjectWorks = useCallback(async (projectId: string): Promise<Work[]> => {
|
|
415
|
-
try {
|
|
416
|
-
const response = (await apiClient.get('/ai/works')) as ApiResponse<Array<any>>;
|
|
417
|
-
|
|
418
|
-
if (response.success && response.data) {
|
|
419
|
-
const allWorks = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
420
|
-
|
|
421
|
-
return allWorks
|
|
422
|
-
.filter((work: any) => work.tenant_ai_project_id === projectId)
|
|
423
|
-
.map((item: any) => ({
|
|
424
|
-
id: item.id,
|
|
425
|
-
title: item.title,
|
|
426
|
-
base_thread_id: item.base_thread_id,
|
|
427
|
-
content_json: item.content_json,
|
|
428
|
-
content_text: item.content_text,
|
|
429
|
-
description: item.description,
|
|
430
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
431
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
432
|
-
tenant_data_source_id: item.tenant_data_source_id,
|
|
433
|
-
tenant_ai_project_id: item.tenant_ai_project_id,
|
|
434
|
-
type: item.type,
|
|
435
|
-
created_by: item.created_by,
|
|
436
|
-
created_on: item.created_on,
|
|
437
|
-
last_modified_on: item.last_modified_on,
|
|
438
|
-
image_url: item.image_url || undefined
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return [];
|
|
443
|
-
} catch (error) {
|
|
444
|
-
console.error('Failed to fetch project works:', error);
|
|
445
|
-
|
|
446
|
-
return [];
|
|
447
|
-
}
|
|
448
|
-
}, [apiClient]);
|
|
449
|
-
|
|
450
|
-
// Session operations
|
|
451
|
-
const updateSession = useCallback(async (sessionId: string, subject: string): Promise<boolean> => {
|
|
452
|
-
try {
|
|
453
|
-
const response: ApiResponse = await apiClient.patch(`/apps/base/data-sources/thread/items/${sessionId}`, {
|
|
454
|
-
subject
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
if (response.success) {
|
|
458
|
-
toast.success(t('toast.session_renamed_success'));
|
|
459
|
-
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
throw new Error('Failed to update session');
|
|
464
|
-
} catch (error) {
|
|
465
|
-
console.error('Error updating session:', error);
|
|
466
|
-
toast.error(t('toast.failed_rename_session'));
|
|
467
|
-
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
}, [apiClient, t]);
|
|
471
|
-
|
|
472
|
-
const deleteSession = useCallback(async (sessionId: string): Promise<boolean> => {
|
|
473
|
-
try {
|
|
474
|
-
const response: ApiResponse = await apiClient.delete(`/apps/base/data-sources/thread/items/${sessionId}`);
|
|
475
|
-
|
|
476
|
-
if (response.success) {
|
|
477
|
-
toast.success(t('toast.session_deleted_success'));
|
|
478
|
-
|
|
479
|
-
return true;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
throw new Error('Failed to delete session');
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.error('Error deleting session:', error);
|
|
485
|
-
toast.error(t('toast.failed_delete_session'));
|
|
486
|
-
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
}, [apiClient, t]);
|
|
490
|
-
|
|
491
|
-
return {
|
|
492
|
-
agentDetails,
|
|
493
|
-
isLoadingAgentDetails,
|
|
494
|
-
fetchThreads,
|
|
495
|
-
fetchProjectThreads,
|
|
496
|
-
loadThreadMessages,
|
|
497
|
-
createThread,
|
|
498
|
-
fetchProjects,
|
|
499
|
-
createProject,
|
|
500
|
-
updateProject,
|
|
501
|
-
deleteProject,
|
|
502
|
-
fetchWorks,
|
|
503
|
-
fetchProjectWorks,
|
|
504
|
-
updateSession,
|
|
505
|
-
deleteSession
|
|
506
|
-
};
|
|
507
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import { type Agent, type McpServer, type Model } from '../types';
|
|
6
|
-
|
|
7
|
-
import { useApiClient } from '../lib/api-client';
|
|
8
|
-
|
|
9
|
-
export type { Agent, McpServer, Model };
|
|
10
|
-
|
|
11
|
-
export interface AgentCapabilities {
|
|
12
|
-
supportWebSearch: boolean;
|
|
13
|
-
supportDocumentSearch: boolean;
|
|
14
|
-
supportDeepResearch: boolean;
|
|
15
|
-
supportThinking: boolean;
|
|
16
|
-
supportWorkCanvas: boolean;
|
|
17
|
-
supportFiles: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface UseDeploymentDataResult {
|
|
21
|
-
models: Model[];
|
|
22
|
-
agents: Agent[];
|
|
23
|
-
selectedModel: Model | null;
|
|
24
|
-
setSelectedModel: (model: Model | null) => void;
|
|
25
|
-
showMultiModels: boolean;
|
|
26
|
-
selectedAgent: Agent | null;
|
|
27
|
-
setSelectedAgent: (agent: Agent | null) => void;
|
|
28
|
-
showAgents: boolean;
|
|
29
|
-
agentAvatar?: string;
|
|
30
|
-
mcpServers: McpServer[];
|
|
31
|
-
activeMcpServers: Record<string, boolean>;
|
|
32
|
-
toggleMcpServer: (id: string, active: boolean) => void;
|
|
33
|
-
capabilities: AgentCapabilities | null;
|
|
34
|
-
isLoading: boolean;
|
|
35
|
-
error: Error | null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Hook to fetch deployment data (models and agents)
|
|
40
|
-
*/
|
|
41
|
-
export function useDeploymentData(
|
|
42
|
-
deploymentIdOrAgentId?: string,
|
|
43
|
-
supportMultiModels = false,
|
|
44
|
-
isBaseAgent = false
|
|
45
|
-
): UseDeploymentDataResult {
|
|
46
|
-
const apiClient = useApiClient();
|
|
47
|
-
const [models, setModels] = useState<Model[]>([]);
|
|
48
|
-
const [agents, setAgents] = useState<Agent[]>([]);
|
|
49
|
-
const [mcpServers, setMcpServers] = useState<McpServer[]>([]);
|
|
50
|
-
const [activeMcpServers, setActiveMcpServers] = useState<Record<string, boolean>>({});
|
|
51
|
-
const [selectedModel, setSelectedModel] = useState<Model | null>(null);
|
|
52
|
-
const [selectedAgent, setSelectedAgent] = useState<Agent | null>(null);
|
|
53
|
-
const [capabilities, setCapabilities] = useState<AgentCapabilities | null>(null);
|
|
54
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
55
|
-
const [error, setError] = useState<Error | null>(null);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (!deploymentIdOrAgentId) return;
|
|
59
|
-
|
|
60
|
-
const fetchData = async () => {
|
|
61
|
-
setIsLoading(true);
|
|
62
|
-
setError(null);
|
|
63
|
-
try {
|
|
64
|
-
// Use different endpoint based on whether it's a base agent or deployment
|
|
65
|
-
const endpoint = isBaseAgent ? `/ai/agent-deployments/base/${deploymentIdOrAgentId}` : `/ai/agent-deployments/${deploymentIdOrAgentId}`;
|
|
66
|
-
|
|
67
|
-
const response = await apiClient.get(endpoint);
|
|
68
|
-
|
|
69
|
-
if (response.success && response.data) {
|
|
70
|
-
const agentData = response.data as {
|
|
71
|
-
agent?: {
|
|
72
|
-
models?: Model[];
|
|
73
|
-
agents?: Array<Agent & { isSkill?: boolean }>;
|
|
74
|
-
mcpServers?: McpServer[];
|
|
75
|
-
defaultAiModelId?: string;
|
|
76
|
-
supportWebSearch?: boolean;
|
|
77
|
-
documentSearch?: boolean;
|
|
78
|
-
supportDeepResearch?: boolean;
|
|
79
|
-
supportThinking?: boolean;
|
|
80
|
-
featureWorks?: boolean;
|
|
81
|
-
supportFiles?: boolean;
|
|
82
|
-
};
|
|
83
|
-
defaultAiModelId?: string;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Extract models from agent.models
|
|
87
|
-
if (agentData.agent?.models) {
|
|
88
|
-
const fetchedModels = agentData.agent.models;
|
|
89
|
-
|
|
90
|
-
setModels(fetchedModels);
|
|
91
|
-
|
|
92
|
-
// Set default model based on defaultAiModelId
|
|
93
|
-
const defaultModelId = agentData.defaultAiModelId || agentData.agent.defaultAiModelId;
|
|
94
|
-
|
|
95
|
-
if (fetchedModels.length > 0) {
|
|
96
|
-
const defaultModel = defaultModelId ? fetchedModels.find((m: Model) => m.id === defaultModelId) : fetchedModels[0];
|
|
97
|
-
|
|
98
|
-
setSelectedModel(prev => prev ?? (defaultModel || fetchedModels[0]));
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
console.warn('[useDeploymentData] No models found in agent data');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Extract sub-agents (skills)
|
|
105
|
-
if (agentData.agent?.agents) {
|
|
106
|
-
const fetchedAgents = agentData.agent.agents.filter(a => a.isSkill);
|
|
107
|
-
|
|
108
|
-
setAgents(fetchedAgents);
|
|
109
|
-
if (fetchedAgents.length > 0) {
|
|
110
|
-
setSelectedAgent(prev => prev ?? fetchedAgents[0]);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Extract MCP servers
|
|
115
|
-
if (agentData.agent?.mcpServers) {
|
|
116
|
-
setMcpServers(agentData.agent.mcpServers);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Extract agent capabilities
|
|
120
|
-
if (agentData.agent) {
|
|
121
|
-
setCapabilities({
|
|
122
|
-
supportWebSearch: agentData.agent.supportWebSearch ?? false,
|
|
123
|
-
supportDocumentSearch: agentData.agent.documentSearch ?? false,
|
|
124
|
-
supportDeepResearch: agentData.agent.supportDeepResearch ?? false,
|
|
125
|
-
supportThinking: agentData.agent.supportThinking ?? false,
|
|
126
|
-
supportWorkCanvas: agentData.agent.featureWorks ?? false,
|
|
127
|
-
supportFiles: agentData.agent.supportFiles ?? false
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} catch (err) {
|
|
132
|
-
setError(err instanceof Error ? err : new Error('Failed to fetch deployment data'));
|
|
133
|
-
} finally {
|
|
134
|
-
setIsLoading(false);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
fetchData();
|
|
139
|
-
}, [deploymentIdOrAgentId, isBaseAgent, apiClient]);
|
|
140
|
-
|
|
141
|
-
const toggleMcpServer = (id: string, active: boolean) => {
|
|
142
|
-
setActiveMcpServers(prev => ({ ...prev, [id]: active }));
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
models,
|
|
147
|
-
agents,
|
|
148
|
-
selectedModel,
|
|
149
|
-
setSelectedModel,
|
|
150
|
-
showMultiModels: supportMultiModels && models.length > 1,
|
|
151
|
-
selectedAgent,
|
|
152
|
-
setSelectedAgent,
|
|
153
|
-
showAgents: agents.length > 1,
|
|
154
|
-
agentAvatar: selectedAgent?.avatar,
|
|
155
|
-
mcpServers,
|
|
156
|
-
activeMcpServers,
|
|
157
|
-
toggleMcpServer,
|
|
158
|
-
capabilities,
|
|
159
|
-
isLoading,
|
|
160
|
-
error
|
|
161
|
-
};
|
|
162
|
-
}
|