@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/lib/api-client.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
import { AsyncTokenManager, RestApiClient } from '@docyrus/api-client';
|
|
6
|
-
|
|
7
|
-
import { useAssistantConfig } from './assistant-config';
|
|
8
|
-
|
|
9
|
-
// Response type that matches the API format
|
|
10
|
-
export interface ApiResponse {
|
|
11
|
-
success: boolean;
|
|
12
|
-
data: unknown;
|
|
13
|
-
error?: string;
|
|
14
|
-
error_description?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Hook to create an API client for the assistant
|
|
19
|
-
* Uses @docyrus/api-client with AsyncTokenManager
|
|
20
|
-
*/
|
|
21
|
-
export function useApiClient() {
|
|
22
|
-
const config = useAssistantConfig();
|
|
23
|
-
|
|
24
|
-
return useMemo(() => {
|
|
25
|
-
// Create async token manager that uses config.getAuthToken
|
|
26
|
-
const tokenManager = new AsyncTokenManager(
|
|
27
|
-
async () => {
|
|
28
|
-
const token = await config.getAuthToken();
|
|
29
|
-
|
|
30
|
-
return token || null;
|
|
31
|
-
},
|
|
32
|
-
async () => {
|
|
33
|
-
// No-op: Token is managed externally
|
|
34
|
-
},
|
|
35
|
-
async () => {
|
|
36
|
-
// No-op: Token is managed externally
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
// Create RestApiClient instance
|
|
41
|
-
const client = new RestApiClient({
|
|
42
|
-
baseURL: config.apiBaseUrl,
|
|
43
|
-
tokenManager
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Wrapper to catch errors and return consistent ApiResponse format
|
|
47
|
-
async function wrapRequest(request: () => Promise<unknown>): Promise<ApiResponse> {
|
|
48
|
-
try {
|
|
49
|
-
const data = await request();
|
|
50
|
-
|
|
51
|
-
// If the API returns { success, data, error }, pass it through
|
|
52
|
-
if (data && typeof data === 'object' && 'success' in data) {
|
|
53
|
-
return data as ApiResponse;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Otherwise wrap in success response
|
|
57
|
-
return { success: true, data };
|
|
58
|
-
} catch (error: unknown) {
|
|
59
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
success: false,
|
|
63
|
-
data: undefined,
|
|
64
|
-
error: errorMessage
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
get: <T = unknown>(endpoint: string, params?: Record<string, unknown>) => wrapRequest(() => client.get<T>(endpoint, params as Record<string, string | number | boolean | null | undefined>)),
|
|
71
|
-
post: (endpoint: string, body?: unknown) => wrapRequest(() => client.post(endpoint, body)),
|
|
72
|
-
put: (endpoint: string, body?: unknown) => wrapRequest(() => client.put(endpoint, body)),
|
|
73
|
-
patch: (endpoint: string, body?: unknown) => wrapRequest(() => client.patch(endpoint, body)),
|
|
74
|
-
delete: (endpoint: string) => wrapRequest(() => client.delete(endpoint))
|
|
75
|
-
};
|
|
76
|
-
}, [config]);
|
|
77
|
-
}
|
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { toast } from 'sonner';
|
|
3
|
-
|
|
4
|
-
import { type ProjectState } from '../hooks/use-project-state';
|
|
5
|
-
import { type SessionState } from '../hooks/use-session-state';
|
|
6
|
-
import {
|
|
7
|
-
type ApiResponse, type AssistantSession, type Project, type Work
|
|
8
|
-
} from '../types';
|
|
9
|
-
|
|
10
|
-
import { processMessagesData } from './message-utils';
|
|
11
|
-
|
|
12
|
-
type ApiClient = {
|
|
13
|
-
get: (url: string, params?: any) => Promise<any>;
|
|
14
|
-
post: (url: string, data?: any) => Promise<any>;
|
|
15
|
-
patch: (url: string, data?: any) => Promise<any>;
|
|
16
|
-
delete: (url: string) => Promise<any>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type TranslationFn = (key: string) => string;
|
|
20
|
-
|
|
21
|
-
// Fetch threads for an agent
|
|
22
|
-
export async function fetchAgentThreads(
|
|
23
|
-
apiClient: ApiClient,
|
|
24
|
-
tenantAiAgentId: string,
|
|
25
|
-
onSuccess: (threads: AssistantSession[]) => void,
|
|
26
|
-
userId?: string | null,
|
|
27
|
-
deploymentId?: string | null
|
|
28
|
-
) {
|
|
29
|
-
try {
|
|
30
|
-
const apiParams: any = {
|
|
31
|
-
columns: 'id,subject,created_on,last_modified_on,body_text,tenant_ai_agent_id,created_by',
|
|
32
|
-
orderBy: JSON.stringify({ field: 'created_on', direction: 'desc' })
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const agentRule = deploymentId ? { field: 'tenant_ai_agent_deployment_id', operator: '=', value: deploymentId } : { field: 'tenant_ai_agent_id', operator: '=', value: tenantAiAgentId };
|
|
36
|
-
|
|
37
|
-
const rules: any[] = [agentRule, { field: 'archived', operator: '=', value: 'false' }];
|
|
38
|
-
|
|
39
|
-
if (userId) {
|
|
40
|
-
rules.push({
|
|
41
|
-
combinator: 'or',
|
|
42
|
-
rules: [{ field: 'record_owner', operator: '=', value: userId }, { field: 'record_owner', operator: 'shared_to_me' }]
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
apiParams.filters = JSON.stringify({ combinator: 'and', rules });
|
|
47
|
-
|
|
48
|
-
const response = (await apiClient.get('/apps/base/data-sources/thread/items', apiParams)) as ApiResponse<any[]>;
|
|
49
|
-
|
|
50
|
-
if (response.success && response.data) {
|
|
51
|
-
const items = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
52
|
-
const threads: AssistantSession[] = items.map((item: any) => ({
|
|
53
|
-
id: item.id,
|
|
54
|
-
title: item.subject,
|
|
55
|
-
messages: [],
|
|
56
|
-
createdAt: new Date(item.created_on),
|
|
57
|
-
updatedAt: new Date(item.last_modified_on || item.created_on)
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
onSuccess(threads);
|
|
61
|
-
} else {
|
|
62
|
-
console.error('Failed to fetch threads:', response.error || (response as any).message);
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error('Failed to fetch threads:', error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Fetch threads for a specific project
|
|
70
|
-
export async function fetchProjectThreads(
|
|
71
|
-
apiClient: ApiClient,
|
|
72
|
-
projectId: string,
|
|
73
|
-
onSuccess: (projectId: string, threads: AssistantSession[]) => void
|
|
74
|
-
) {
|
|
75
|
-
try {
|
|
76
|
-
const apiParams: any = {
|
|
77
|
-
columns: 'id,subject,created_on,last_modified_on,body_text,tenant_ai_agent_id,tenant_ai_project_id ',
|
|
78
|
-
orderBy: JSON.stringify({ field: 'created_on', direction: 'desc' })
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
apiParams.filters = JSON.stringify({
|
|
82
|
-
rules: [{ field: 'tenant_ai_project_id ', operator: '=', value: projectId }]
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const response = (await apiClient.get('/apps/base/data-sources/thread/items', apiParams)) as ApiResponse<any[]>;
|
|
86
|
-
|
|
87
|
-
if (response.success && response.data) {
|
|
88
|
-
const items = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
89
|
-
const threads: AssistantSession[] = items.map((item: any) => ({
|
|
90
|
-
id: item.id,
|
|
91
|
-
title: item.subject,
|
|
92
|
-
messages: [],
|
|
93
|
-
createdAt: new Date(item.created_on),
|
|
94
|
-
updatedAt: new Date(item.last_modified_on)
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
onSuccess(projectId, threads);
|
|
98
|
-
} else {
|
|
99
|
-
console.error('Failed to fetch project threads:', response.error || (response as any).message);
|
|
100
|
-
}
|
|
101
|
-
} catch (error) {
|
|
102
|
-
console.error('Failed to fetch project threads:', error);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Fetch works for a specific project
|
|
107
|
-
export async function fetchProjectWorks(
|
|
108
|
-
apiClient: ApiClient,
|
|
109
|
-
projectId: string,
|
|
110
|
-
onSuccess: (projectId: string, works: Work[]) => void,
|
|
111
|
-
tenantAiAgentId?: string,
|
|
112
|
-
userId?: string | null
|
|
113
|
-
) {
|
|
114
|
-
try {
|
|
115
|
-
const response = (await apiClient.get('/ai/works')) as ApiResponse<any[]>;
|
|
116
|
-
|
|
117
|
-
if (response.success && response.data) {
|
|
118
|
-
const allWorks = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
119
|
-
const projectWorks = allWorks.filter((work: any) => work.tenant_ai_project_id === projectId
|
|
120
|
-
&& (!tenantAiAgentId || work.tenant_ai_agent_id === tenantAiAgentId)
|
|
121
|
-
&& (!userId || work.created_by === userId || (Array.isArray(work.shared_to) && work.shared_to.includes(userId))));
|
|
122
|
-
|
|
123
|
-
const formattedWorks: Work[] = projectWorks.map((item: Work) => ({
|
|
124
|
-
id: item.id,
|
|
125
|
-
title: item.title,
|
|
126
|
-
base_thread_id: item.base_thread_id,
|
|
127
|
-
content_json: item.content_json,
|
|
128
|
-
content_text: item.content_text,
|
|
129
|
-
description: item.description,
|
|
130
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
131
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
132
|
-
tenant_data_source_id: item.tenant_data_source_id,
|
|
133
|
-
tenant_ai_project_id: item.tenant_ai_project_id,
|
|
134
|
-
type: item.type,
|
|
135
|
-
created_by: item.created_by,
|
|
136
|
-
created_on: item.created_on,
|
|
137
|
-
last_modified_on: item.last_modified_on,
|
|
138
|
-
image_url: item.image_url || undefined
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
onSuccess(projectId, formattedWorks);
|
|
142
|
-
} else {
|
|
143
|
-
console.error('Failed to fetch project works:', response.error || (response as any).message);
|
|
144
|
-
}
|
|
145
|
-
} catch (error) {
|
|
146
|
-
console.error('Failed to fetch project works:', error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Fetch all projects
|
|
151
|
-
export async function fetchProjects(
|
|
152
|
-
apiClient: ApiClient,
|
|
153
|
-
userId: string | null,
|
|
154
|
-
onSuccess: (projects: Project[]) => void,
|
|
155
|
-
onProjectLoaded: (project: Project) => void,
|
|
156
|
-
onComplete: () => void,
|
|
157
|
-
tenantAiAgentId?: string
|
|
158
|
-
) {
|
|
159
|
-
try {
|
|
160
|
-
const response = (await apiClient.get('/ai/projects')) as ApiResponse<any[]>;
|
|
161
|
-
|
|
162
|
-
if (response.success && response.data) {
|
|
163
|
-
const responseItems = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
164
|
-
const allProjects: Project[] = responseItems.map((item: any) => ({
|
|
165
|
-
id: item.id,
|
|
166
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
167
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
168
|
-
name: item.name,
|
|
169
|
-
description: item.description,
|
|
170
|
-
created_by: item.created_by,
|
|
171
|
-
shared_to: item.shared_to
|
|
172
|
-
}));
|
|
173
|
-
|
|
174
|
-
const filteredProjects = allProjects.filter((project) => {
|
|
175
|
-
const matchesAgent = !tenantAiAgentId || project.tenant_ai_agent_id === tenantAiAgentId;
|
|
176
|
-
const matchesUser = !userId || project.created_by === userId || (project.shared_to && project.shared_to.includes(userId));
|
|
177
|
-
|
|
178
|
-
return matchesAgent && matchesUser;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
onSuccess(filteredProjects);
|
|
182
|
-
filteredProjects.forEach(onProjectLoaded);
|
|
183
|
-
} else {
|
|
184
|
-
console.error('Failed to fetch projects:', response.error || (response as any).message);
|
|
185
|
-
}
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error('Failed to fetch projects:', error);
|
|
188
|
-
} finally {
|
|
189
|
-
onComplete();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Fetch all works
|
|
194
|
-
export async function fetchWorks(
|
|
195
|
-
apiClient: ApiClient,
|
|
196
|
-
onSuccess: (works: Work[]) => void,
|
|
197
|
-
tenantAiAgentId?: string,
|
|
198
|
-
userId?: string | null
|
|
199
|
-
) {
|
|
200
|
-
try {
|
|
201
|
-
const response = (await apiClient.get('/ai/works')) as ApiResponse<any[]>;
|
|
202
|
-
|
|
203
|
-
if (response.success && response.data) {
|
|
204
|
-
const allItems = Array.isArray(response.data) ? response.data : (response.data as any).items || [];
|
|
205
|
-
const worksItems = allItems.filter((item: any) => {
|
|
206
|
-
const matchesAgent = !tenantAiAgentId || item.tenant_ai_agent_id === tenantAiAgentId;
|
|
207
|
-
const matchesUser = !userId || item.created_by === userId || (Array.isArray(item.shared_to) && item.shared_to.includes(userId));
|
|
208
|
-
|
|
209
|
-
return matchesAgent && matchesUser;
|
|
210
|
-
});
|
|
211
|
-
const formattedWorks: Work[] = worksItems.map((item: any) => ({
|
|
212
|
-
id: item.id,
|
|
213
|
-
title: item.title,
|
|
214
|
-
base_thread_id: item.base_thread_id,
|
|
215
|
-
content_json: item.content_json,
|
|
216
|
-
content_text: item.content_text,
|
|
217
|
-
description: item.description,
|
|
218
|
-
tenant_ai_agent_deployment_id: item.tenant_ai_agent_deployment_id,
|
|
219
|
-
tenant_ai_agent_id: item.tenant_ai_agent_id,
|
|
220
|
-
tenant_data_source_id: item.tenant_data_source_id,
|
|
221
|
-
type: item.type,
|
|
222
|
-
created_by: item.created_by,
|
|
223
|
-
created_on: item.created_on,
|
|
224
|
-
last_modified_on: item.last_modified_on,
|
|
225
|
-
image_url: item.image_url || undefined
|
|
226
|
-
}));
|
|
227
|
-
|
|
228
|
-
onSuccess(formattedWorks);
|
|
229
|
-
} else {
|
|
230
|
-
console.error('Failed to fetch works:', response.error || (response as any).message);
|
|
231
|
-
}
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.error('Failed to fetch works:', error);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Load messages for a thread
|
|
238
|
-
export async function loadThreadMessages(
|
|
239
|
-
apiClient: ApiClient,
|
|
240
|
-
threadId: string,
|
|
241
|
-
setMessages: (messages: any[]) => void
|
|
242
|
-
) {
|
|
243
|
-
try {
|
|
244
|
-
const response = (await apiClient.get('/apps/base/data-sources/message/items', {
|
|
245
|
-
columns: 'body_json,created_on,record_owner,role',
|
|
246
|
-
filters: JSON.stringify({ rules: [{ field: 'thread', operator: '=', value: threadId }] }),
|
|
247
|
-
sort: JSON.stringify([{ field: 'created_on', direction: 'asc' }])
|
|
248
|
-
})) as ApiResponse<any[]>;
|
|
249
|
-
|
|
250
|
-
if (response.success && response.data) {
|
|
251
|
-
const formattedMessages = processMessagesData(response.data);
|
|
252
|
-
|
|
253
|
-
setMessages(formattedMessages as any);
|
|
254
|
-
} else {
|
|
255
|
-
console.info('No messages found for thread');
|
|
256
|
-
setMessages([]);
|
|
257
|
-
}
|
|
258
|
-
} catch (error) {
|
|
259
|
-
console.error('Error loading thread messages:', error);
|
|
260
|
-
setMessages([]);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Update project
|
|
265
|
-
export async function updateProject(
|
|
266
|
-
apiClient: ApiClient,
|
|
267
|
-
projectState: ProjectState,
|
|
268
|
-
projectActions: {
|
|
269
|
-
setSaving: (saving: boolean) => void;
|
|
270
|
-
stopEditing: () => void;
|
|
271
|
-
},
|
|
272
|
-
refreshProjects: () => void,
|
|
273
|
-
t: TranslationFn
|
|
274
|
-
) {
|
|
275
|
-
if (!projectState.name.trim() || !projectState.selectedProject) return;
|
|
276
|
-
|
|
277
|
-
projectActions.setSaving(true);
|
|
278
|
-
try {
|
|
279
|
-
const response: ApiResponse = await apiClient.patch(`/ai/projects/${projectState.selectedProject.id}`, {
|
|
280
|
-
name: projectState.name.trim(),
|
|
281
|
-
description: projectState.description.trim()
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
if (response.success) {
|
|
285
|
-
projectActions.stopEditing();
|
|
286
|
-
refreshProjects();
|
|
287
|
-
toast.success(t('toast.project_updated_success'));
|
|
288
|
-
} else {
|
|
289
|
-
throw new Error('Failed to update project');
|
|
290
|
-
}
|
|
291
|
-
} catch (error) {
|
|
292
|
-
console.error('Error updating project:', error);
|
|
293
|
-
toast.error(t('toast.failed_update_project'));
|
|
294
|
-
} finally {
|
|
295
|
-
projectActions.setSaving(false);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Delete project
|
|
300
|
-
export async function deleteProject(
|
|
301
|
-
apiClient: ApiClient,
|
|
302
|
-
projectState: ProjectState,
|
|
303
|
-
projectActions: {
|
|
304
|
-
setDeleteDialogOpen: (open: boolean) => void;
|
|
305
|
-
setDeleting: (deleting: boolean) => void;
|
|
306
|
-
},
|
|
307
|
-
refreshProjects: () => void,
|
|
308
|
-
t: TranslationFn
|
|
309
|
-
) {
|
|
310
|
-
if (!projectState.selectedProject) return;
|
|
311
|
-
|
|
312
|
-
projectActions.setDeleting(true);
|
|
313
|
-
try {
|
|
314
|
-
const response: ApiResponse = await apiClient.delete(`/ai/projects/${projectState.selectedProject.id}`);
|
|
315
|
-
|
|
316
|
-
if (response.success) {
|
|
317
|
-
projectActions.setDeleteDialogOpen(false);
|
|
318
|
-
projectActions.setDeleting(false);
|
|
319
|
-
refreshProjects();
|
|
320
|
-
toast.success(t('toast.project_deleted_success'));
|
|
321
|
-
} else {
|
|
322
|
-
toast.error(t('toast.failed_delete_project'));
|
|
323
|
-
throw new Error('Failed to delete project');
|
|
324
|
-
}
|
|
325
|
-
} catch (error) {
|
|
326
|
-
console.error('Error deleting project:', error);
|
|
327
|
-
toast.error(t('toast.failed_delete_project'));
|
|
328
|
-
} finally {
|
|
329
|
-
projectActions.setDeleting(false);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Update session
|
|
334
|
-
export async function updateSession(
|
|
335
|
-
apiClient: ApiClient,
|
|
336
|
-
sessionState: SessionState,
|
|
337
|
-
sessionActions: {
|
|
338
|
-
setSaving: (saving: boolean) => void;
|
|
339
|
-
stopEditing: () => void;
|
|
340
|
-
},
|
|
341
|
-
refreshThreads: () => void,
|
|
342
|
-
refreshProjectThreads: (projectId: string) => void,
|
|
343
|
-
projectContextId: string | null,
|
|
344
|
-
selectedProjectId: string | null,
|
|
345
|
-
t: TranslationFn
|
|
346
|
-
) {
|
|
347
|
-
if (!sessionState.name.trim() || !sessionState.selectedSession) return;
|
|
348
|
-
|
|
349
|
-
sessionActions.setSaving(true);
|
|
350
|
-
try {
|
|
351
|
-
const response = (await apiClient.patch(
|
|
352
|
-
`/apps/base/data-sources/thread/items/${sessionState.selectedSession.id}`,
|
|
353
|
-
{ subject: sessionState.name.trim() }
|
|
354
|
-
)) as ApiResponse<any>;
|
|
355
|
-
|
|
356
|
-
if (response.success) {
|
|
357
|
-
sessionActions.stopEditing();
|
|
358
|
-
refreshThreads();
|
|
359
|
-
if (projectContextId) refreshProjectThreads(projectContextId);
|
|
360
|
-
if (selectedProjectId) refreshProjectThreads(selectedProjectId);
|
|
361
|
-
toast.success(t('toast.session_renamed_success'));
|
|
362
|
-
} else {
|
|
363
|
-
toast.error(t('toast.failed_rename_session'));
|
|
364
|
-
}
|
|
365
|
-
} catch (error) {
|
|
366
|
-
console.error('Error updating session:', error);
|
|
367
|
-
toast.error(t('toast.failed_rename_session'));
|
|
368
|
-
} finally {
|
|
369
|
-
sessionActions.setSaving(false);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Delete session
|
|
374
|
-
export async function deleteSession(
|
|
375
|
-
apiClient: ApiClient,
|
|
376
|
-
sessionState: SessionState,
|
|
377
|
-
sessionActions: {
|
|
378
|
-
setDeleteDialogOpen: (open: boolean) => void;
|
|
379
|
-
setDeleting: (deleting: boolean) => void;
|
|
380
|
-
},
|
|
381
|
-
refreshThreads: () => void,
|
|
382
|
-
refreshProjectThreads: (projectId: string) => void,
|
|
383
|
-
projectContextId: string | null,
|
|
384
|
-
selectedProjectId: string | null,
|
|
385
|
-
t: TranslationFn
|
|
386
|
-
) {
|
|
387
|
-
if (!sessionState.selectedSession) return;
|
|
388
|
-
|
|
389
|
-
sessionActions.setDeleting(true);
|
|
390
|
-
try {
|
|
391
|
-
const response = (await apiClient.delete(
|
|
392
|
-
`/apps/base/data-sources/thread/items/${sessionState.selectedSession.id}`
|
|
393
|
-
)) as ApiResponse<any>;
|
|
394
|
-
|
|
395
|
-
if (response.success) {
|
|
396
|
-
sessionActions.setDeleteDialogOpen(false);
|
|
397
|
-
refreshThreads();
|
|
398
|
-
if (projectContextId) refreshProjectThreads(projectContextId);
|
|
399
|
-
if (selectedProjectId) refreshProjectThreads(selectedProjectId);
|
|
400
|
-
toast.success(t('toast.session_deleted_success'));
|
|
401
|
-
} else {
|
|
402
|
-
toast.error(t('toast.failed_delete_session'));
|
|
403
|
-
}
|
|
404
|
-
} catch (error) {
|
|
405
|
-
console.error('Error deleting session:', error);
|
|
406
|
-
toast.error(t('toast.failed_delete_session'));
|
|
407
|
-
} finally {
|
|
408
|
-
sessionActions.setDeleting(false);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Update project instructions
|
|
413
|
-
export async function updateProjectInstructions(
|
|
414
|
-
apiClient: ApiClient,
|
|
415
|
-
projectState: ProjectState,
|
|
416
|
-
projectActions: {
|
|
417
|
-
setSavingInstructions: (saving: boolean) => void;
|
|
418
|
-
stopEditingInstructions: () => void;
|
|
419
|
-
updateProject: (project: Project) => void;
|
|
420
|
-
},
|
|
421
|
-
refreshProjects: () => void,
|
|
422
|
-
t: TranslationFn
|
|
423
|
-
) {
|
|
424
|
-
if (!projectState.selectedProject) return;
|
|
425
|
-
|
|
426
|
-
projectActions.setSavingInstructions(true);
|
|
427
|
-
try {
|
|
428
|
-
const response = (await apiClient.patch(`/ai/projects/${projectState.selectedProject.id}`, {
|
|
429
|
-
instructions: projectState.instructions.trim() || null
|
|
430
|
-
})) as ApiResponse<any>;
|
|
431
|
-
|
|
432
|
-
if (response.success) {
|
|
433
|
-
projectActions.stopEditingInstructions();
|
|
434
|
-
projectActions.updateProject({
|
|
435
|
-
...projectState.selectedProject,
|
|
436
|
-
instructions: projectState.instructions.trim() || undefined
|
|
437
|
-
});
|
|
438
|
-
refreshProjects();
|
|
439
|
-
toast.success(t('toast.instructions_updated_success'));
|
|
440
|
-
} else {
|
|
441
|
-
toast.error(t('toast.failed_update_instructions'));
|
|
442
|
-
}
|
|
443
|
-
} catch (error) {
|
|
444
|
-
console.error('Error updating instructions:', error);
|
|
445
|
-
toast.error(t('toast.failed_update_instructions'));
|
|
446
|
-
} finally {
|
|
447
|
-
projectActions.setSavingInstructions(false);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// Create new thread
|
|
452
|
-
export async function createThread(
|
|
453
|
-
apiClient: ApiClient,
|
|
454
|
-
data: {
|
|
455
|
-
subject: string;
|
|
456
|
-
body_text: string;
|
|
457
|
-
sender_name: string;
|
|
458
|
-
deploymentId?: string;
|
|
459
|
-
tenantAiAgentId: string;
|
|
460
|
-
projectId?: string | null;
|
|
461
|
-
}
|
|
462
|
-
): Promise<{
|
|
463
|
-
id: string; subject: string; created_on: string; last_modified_on: string;
|
|
464
|
-
} | null> {
|
|
465
|
-
try {
|
|
466
|
-
const response = (await apiClient.post('/apps/base/data-sources/thread/items', {
|
|
467
|
-
subject: data.subject,
|
|
468
|
-
body_text: data.body_text,
|
|
469
|
-
sender_name: data.sender_name,
|
|
470
|
-
thread_type: 'assistant',
|
|
471
|
-
tenant_ai_agent_deployment_id: data.deploymentId ? String(data.deploymentId) : null,
|
|
472
|
-
tenant_ai_agent_id: String(data.tenantAiAgentId),
|
|
473
|
-
tenant_ai_project_id: data.projectId || null
|
|
474
|
-
})) as ApiResponse<any>;
|
|
475
|
-
|
|
476
|
-
if (response && response.success && response.data) {
|
|
477
|
-
return response.data;
|
|
478
|
-
} else {
|
|
479
|
-
console.error('Failed to create thread:', response?.error || 'Unknown error');
|
|
480
|
-
|
|
481
|
-
return null;
|
|
482
|
-
}
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.error('Failed to create thread:', error);
|
|
485
|
-
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Upload file to thread via REST API
|
|
491
|
-
export async function uploadThreadFile(
|
|
492
|
-
apiClient: ApiClient,
|
|
493
|
-
threadId: string,
|
|
494
|
-
file: File
|
|
495
|
-
): Promise<string | null> {
|
|
496
|
-
try {
|
|
497
|
-
const formData = new FormData();
|
|
498
|
-
|
|
499
|
-
formData.append('file', file);
|
|
500
|
-
|
|
501
|
-
const response = (await apiClient.post(
|
|
502
|
-
`/apps/base/data-sources/thread/items/${threadId}/files/upload`,
|
|
503
|
-
formData
|
|
504
|
-
)) as ApiResponse<any>;
|
|
505
|
-
|
|
506
|
-
if (response.success && response.data) {
|
|
507
|
-
// Return the storage path (file_name field)
|
|
508
|
-
const fileData = Array.isArray(response.data) ? response.data[0] : response.data;
|
|
509
|
-
|
|
510
|
-
return fileData?.file_name || fileData?.path || null;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
console.error('Failed to upload file:', response.error);
|
|
514
|
-
|
|
515
|
-
return null;
|
|
516
|
-
} catch (error) {
|
|
517
|
-
console.error('Failed to upload file:', error);
|
|
518
|
-
|
|
519
|
-
return null;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// Create new project
|
|
524
|
-
export async function createProject(
|
|
525
|
-
apiClient: ApiClient,
|
|
526
|
-
data: {
|
|
527
|
-
name: string;
|
|
528
|
-
description?: string;
|
|
529
|
-
tenantAiAgentId: string;
|
|
530
|
-
},
|
|
531
|
-
onSuccess: (project: any) => void,
|
|
532
|
-
onComplete: () => void
|
|
533
|
-
) {
|
|
534
|
-
try {
|
|
535
|
-
const response: any = await apiClient.post('/ai/projects', {
|
|
536
|
-
name: data.name,
|
|
537
|
-
tenant_ai_agent_id: data.tenantAiAgentId,
|
|
538
|
-
description: data.description || undefined
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
if (response.success && response.data) {
|
|
542
|
-
onSuccess(response.data);
|
|
543
|
-
}
|
|
544
|
-
} catch (error) {
|
|
545
|
-
console.error('Failed to create project:', error);
|
|
546
|
-
} finally {
|
|
547
|
-
onComplete();
|
|
548
|
-
}
|
|
549
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext, type ReactNode, use, useMemo
|
|
5
|
-
} from 'react';
|
|
6
|
-
|
|
7
|
-
import { Toaster } from 'sonner';
|
|
8
|
-
|
|
9
|
-
import { TooltipProvider } from '@docyrus/ui-pro-shared/components/tooltip';
|
|
10
|
-
|
|
11
|
-
import { AssistantI18nProvider } from '../i18n';
|
|
12
|
-
|
|
13
|
-
// User interface for assistant
|
|
14
|
-
export interface AssistantUser {
|
|
15
|
-
id: string;
|
|
16
|
-
email?: string;
|
|
17
|
-
firstname?: string;
|
|
18
|
-
lastname?: string;
|
|
19
|
-
photo?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface DataSourceField {
|
|
23
|
-
id: string;
|
|
24
|
-
name: string;
|
|
25
|
-
slug: string;
|
|
26
|
-
type: string;
|
|
27
|
-
read_only?: boolean;
|
|
28
|
-
sort_order?: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface DataSourceSchema {
|
|
32
|
-
id: string;
|
|
33
|
-
name: string;
|
|
34
|
-
slug: string;
|
|
35
|
-
app: { id: string; name: string; slug: string };
|
|
36
|
-
fields: DataSourceField[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface AssistantConfig {
|
|
40
|
-
apiBaseUrl: string;
|
|
41
|
-
getAuthToken: () => Promise<string>;
|
|
42
|
-
user?: AssistantUser | null;
|
|
43
|
-
getDataSourceSchema?: (id: string) => Promise<DataSourceSchema | null>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const AssistantConfigContext = createContext<AssistantConfig | null>(null);
|
|
47
|
-
|
|
48
|
-
export interface AssistantProviderProps {
|
|
49
|
-
config: AssistantConfig;
|
|
50
|
-
children: ReactNode;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function AssistantProvider({ config, children }: AssistantProviderProps) {
|
|
54
|
-
// Stabilize context value so consumers only re-render when config actually changes
|
|
55
|
-
const value = useMemo(() => config, [config]);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<AssistantConfigContext value={value}>
|
|
59
|
-
<TooltipProvider>
|
|
60
|
-
<AssistantI18nProvider>{children}</AssistantI18nProvider>
|
|
61
|
-
<Toaster />
|
|
62
|
-
</TooltipProvider>
|
|
63
|
-
</AssistantConfigContext>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function useAssistantConfig(): AssistantConfig {
|
|
68
|
-
const config = use(AssistantConfigContext);
|
|
69
|
-
|
|
70
|
-
if (!config) {
|
|
71
|
-
throw new Error('useAssistantConfig must be used within an AssistantProvider');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return config;
|
|
75
|
-
}
|