|
|
@@ -8,8 +8,6 @@ import { useTranslation } from 'react-i18next';
|
|
|
import { Collapse, UncontrolledTooltip } from 'reactstrap';
|
|
|
import SimpleBar from 'simplebar-react';
|
|
|
|
|
|
-
|
|
|
-import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
import { toastError } from '~/client/util/toastr';
|
|
|
import { useGrowiCloudUri, useIsEnableUnifiedMergeView } from '~/stores-universal/context';
|
|
|
import { useEditorMode, EditorMode } from '~/stores-universal/ui';
|
|
|
@@ -17,7 +15,6 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import type { AiAssistantHasId } from '../../../../interfaces/ai-assistant';
|
|
|
import { MessageErrorCode, StreamErrorCode } from '../../../../interfaces/message-error';
|
|
|
-import { ThreadType } from '../../../../interfaces/thread-relation';
|
|
|
import type { IThreadRelationHasId } from '../../../../interfaces/thread-relation';
|
|
|
import { useEditorAssistant } from '../../../services/editor-assistant';
|
|
|
import { useKnowledgeAssistant } from '../../../services/knowledge-assistant';
|
|
|
@@ -76,8 +73,14 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
const { trigger: mutateThreadData } = useSWRMUTxThreads(aiAssistantData?._id);
|
|
|
const { trigger: mutateMessageData } = useSWRMUTxMessages(aiAssistantData?._id, threadData?.threadId);
|
|
|
|
|
|
- const { postMessage: postMessageForKnowledgeAssistant, processMessage: processMessageForKnowledgeAssistant } = useKnowledgeAssistant();
|
|
|
const {
|
|
|
+ createThread: createThreadForKnowledgeAssistant,
|
|
|
+ postMessage: postMessageForKnowledgeAssistant,
|
|
|
+ processMessage: processMessageForKnowledgeAssistant,
|
|
|
+ } = useKnowledgeAssistant();
|
|
|
+
|
|
|
+ const {
|
|
|
+ createThread: createThreadForEditorAssistant,
|
|
|
postMessage: postMessageForEditorAssistant,
|
|
|
processMessage: processMessageForEditorAssistant,
|
|
|
accept,
|
|
|
@@ -116,6 +119,19 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
}
|
|
|
}, [mutateMessageData, threadData]);
|
|
|
|
|
|
+ const createThread = useCallback(async(initialUserMessage: string) => {
|
|
|
+ if (isEditorAssistant) {
|
|
|
+ const thread = await createThreadForEditorAssistant(selectedAiAssistant?._id);
|
|
|
+ return thread;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (aiAssistantData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const thread = await createThreadForKnowledgeAssistant(aiAssistantData._id, initialUserMessage);
|
|
|
+ return thread;
|
|
|
+ }, [aiAssistantData, createThreadForEditorAssistant, createThreadForKnowledgeAssistant, isEditorAssistant, selectedAiAssistant?._id]);
|
|
|
+
|
|
|
const isActionButtonShown = useCallback((messageId: string) => {
|
|
|
if (!isEditorAssistant) {
|
|
|
return false;
|
|
|
@@ -187,13 +203,18 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
let currentThreadId_ = currentThreadId;
|
|
|
if (currentThreadId_ == null) {
|
|
|
try {
|
|
|
- const res = await apiv3Post<IThreadRelationHasId>('/openai/thread', {
|
|
|
- type: isEditorAssistant ? ThreadType.EDITOR : ThreadType.KNOWLEDGE,
|
|
|
- aiAssistantId: isEditorAssistant ? selectedAiAssistant?._id : aiAssistantData?._id,
|
|
|
- initialUserMessage: isEditorAssistant ? undefined : newUserMessage.content,
|
|
|
- });
|
|
|
+ // const res = await apiv3Post<IThreadRelationHasId>('/openai/thread', {
|
|
|
+ // type: isEditorAssistant ? ThreadType.EDITOR : ThreadType.KNOWLEDGE,
|
|
|
+ // aiAssistantId: isEditorAssistant ? selectedAiAssistant?._id : aiAssistantData?._id,
|
|
|
+ // initialUserMessage: isEditorAssistant ? undefined : newUserMessage.content,
|
|
|
+ // });
|
|
|
+
|
|
|
+ const thread = await createThread(newUserMessage.content);
|
|
|
+ if (thread == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- const thread = res.data;
|
|
|
+ // const thread = res.data;
|
|
|
|
|
|
setCurrentThreadId(thread.threadId);
|
|
|
setCurrentThreadTitle(thread.title);
|