|
|
@@ -1,6 +1,6 @@
|
|
|
import type { KeyboardEvent, JSX } from 'react';
|
|
|
import {
|
|
|
- type FC, memo, useRef, useEffect, useState, useCallback,
|
|
|
+ type FC, memo, useRef, useEffect, useState, useCallback, useMemo,
|
|
|
} from 'react';
|
|
|
|
|
|
import { useForm, Controller } from 'react-hook-form';
|
|
|
@@ -8,60 +8,90 @@ 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 { MessageErrorCode, StreamErrorCode } from '~/features/openai/interfaces/message-error';
|
|
|
-import type { IThreadRelationHasId } from '~/features/openai/interfaces/thread-relation';
|
|
|
-import { useGrowiCloudUri } from '~/stores-universal/context';
|
|
|
+import { useGrowiCloudUri, useIsEnableUnifiedMergeView } from '~/stores-universal/context';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import type { AiAssistantHasId } from '../../../../interfaces/ai-assistant';
|
|
|
-import { useAiAssistantChatSidebar } from '../../../stores/ai-assistant';
|
|
|
-import { useSWRMUTxMessages } from '../../../stores/message';
|
|
|
-import { useSWRMUTxThreads } from '../../../stores/thread';
|
|
|
+import type { MessageLog } from '../../../../interfaces/message';
|
|
|
+import { MessageErrorCode, StreamErrorCode } from '../../../../interfaces/message-error';
|
|
|
+import type { IThreadRelationHasId } from '../../../../interfaces/thread-relation';
|
|
|
+import {
|
|
|
+ useEditorAssistant,
|
|
|
+ useAiAssistantSidebarCloseEffect as useAiAssistantSidebarCloseEffectForEditorAssistant,
|
|
|
+} from '../../../services/editor-assistant';
|
|
|
+import {
|
|
|
+ useKnowledgeAssistant,
|
|
|
+ useFetchAndSetMessageDataEffect,
|
|
|
+ useAiAssistantSidebarCloseEffect as useAiAssistantSidebarCloseEffectForKnowledgeAssistant,
|
|
|
+} from '../../../services/knowledge-assistant';
|
|
|
+import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
|
|
|
|
|
|
-import { MessageCard } from './MessageCard';
|
|
|
+import { MessageCard, type MessageCardRole } from './MessageCard';
|
|
|
import { ResizableTextarea } from './ResizableTextArea';
|
|
|
|
|
|
-import styles from './AiAssistantChatSidebar.module.scss';
|
|
|
+import styles from './AiAssistantSidebar.module.scss';
|
|
|
|
|
|
-const logger = loggerFactory('growi:openai:client:components:AiAssistantChatSidebar');
|
|
|
+const logger = loggerFactory('growi:openai:client:components:AiAssistantSidebar');
|
|
|
|
|
|
-const moduleClass = styles['grw-ai-assistant-chat-sidebar'] ?? '';
|
|
|
-
|
|
|
-type Message = {
|
|
|
- id: string,
|
|
|
- content: string,
|
|
|
- isUserMessage?: boolean,
|
|
|
-}
|
|
|
+const moduleClass = styles['grw-ai-assistant-sidebar'] ?? '';
|
|
|
|
|
|
-type FormData = {
|
|
|
+export type FormData = {
|
|
|
input: string;
|
|
|
summaryMode?: boolean;
|
|
|
};
|
|
|
|
|
|
-type AiAssistantChatSidebarSubstanceProps = {
|
|
|
- aiAssistantData: AiAssistantHasId;
|
|
|
+type AiAssistantSidebarSubstanceProps = {
|
|
|
+ isEditorAssistant: boolean;
|
|
|
+ aiAssistantData?: AiAssistantHasId;
|
|
|
threadData?: IThreadRelationHasId;
|
|
|
- closeAiAssistantChatSidebar: () => void
|
|
|
+ closeAiAssistantSidebar: () => void
|
|
|
}
|
|
|
|
|
|
-const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceProps> = (props: AiAssistantChatSidebarSubstanceProps) => {
|
|
|
+const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> = (props: AiAssistantSidebarSubstanceProps) => {
|
|
|
const {
|
|
|
- aiAssistantData, threadData, closeAiAssistantChatSidebar,
|
|
|
+ isEditorAssistant,
|
|
|
+ aiAssistantData,
|
|
|
+ threadData,
|
|
|
+ closeAiAssistantSidebar,
|
|
|
} = props;
|
|
|
|
|
|
- const [currentThreadTitle, setCurrentThreadTitle] = useState<string | undefined>(threadData?.title);
|
|
|
+ // States
|
|
|
const [currentThreadId, setCurrentThreadId] = useState<string | undefined>(threadData?.threadId);
|
|
|
- const [messageLogs, setMessageLogs] = useState<Message[]>([]);
|
|
|
- const [generatingAnswerMessage, setGeneratingAnswerMessage] = useState<Message>();
|
|
|
+ const [messageLogs, setMessageLogs] = useState<MessageLog[]>([]);
|
|
|
+ const [generatingAnswerMessage, setGeneratingAnswerMessage] = useState<MessageLog>();
|
|
|
const [errorMessage, setErrorMessage] = useState<string | undefined>();
|
|
|
const [isErrorDetailCollapsed, setIsErrorDetailCollapsed] = useState<boolean>(false);
|
|
|
|
|
|
+ // Hooks
|
|
|
const { t } = useTranslation();
|
|
|
const { data: growiCloudUri } = useGrowiCloudUri();
|
|
|
- const { trigger: mutateThreadData } = useSWRMUTxThreads(aiAssistantData._id);
|
|
|
- const { trigger: mutateMessageData } = useSWRMUTxMessages(aiAssistantData._id, threadData?.threadId);
|
|
|
+
|
|
|
+ const {
|
|
|
+ createThread: createThreadForKnowledgeAssistant,
|
|
|
+ postMessage: postMessageForKnowledgeAssistant,
|
|
|
+ processMessage: processMessageForKnowledgeAssistant,
|
|
|
+
|
|
|
+ // Views
|
|
|
+ initialView: initialViewForKnowledgeAssistant,
|
|
|
+ generateMessageCard: generateMessageCardForKnowledgeAssistant,
|
|
|
+ headerIcon: headerIconForKnowledgeAssistant,
|
|
|
+ headerText: headerTextForKnowledgeAssistant,
|
|
|
+ placeHolder: placeHolderForKnowledgeAssistant,
|
|
|
+ } = useKnowledgeAssistant();
|
|
|
+
|
|
|
+ const {
|
|
|
+ createThread: createThreadForEditorAssistant,
|
|
|
+ postMessage: postMessageForEditorAssistant,
|
|
|
+ processMessage: processMessageForEditorAssistant,
|
|
|
+
|
|
|
+ // Views
|
|
|
+ generateInitialView: generateInitialViewForEditorAssistant,
|
|
|
+ generateMessageCard: generateMessageCardForEditorAssistant,
|
|
|
+ headerIcon: headerIconForEditorAssistant,
|
|
|
+ headerText: headerTextForEditorAssistant,
|
|
|
+ placeHolder: placeHolderForEditorAssistant,
|
|
|
+ } = useEditorAssistant();
|
|
|
|
|
|
const form = useForm<FormData>({
|
|
|
defaultValues: {
|
|
|
@@ -70,30 +100,33 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const fetchAndSetMessageData = async() => {
|
|
|
- const messageData = await mutateMessageData();
|
|
|
- if (messageData != null) {
|
|
|
- const normalizedMessageData = messageData.data
|
|
|
- .reverse()
|
|
|
- .filter(message => message.metadata?.shouldHideMessage !== 'true');
|
|
|
-
|
|
|
- setMessageLogs(() => {
|
|
|
- return normalizedMessageData.map((message, index) => (
|
|
|
- {
|
|
|
- id: index.toString(),
|
|
|
- content: message.content[0].type === 'text' ? message.content[0].text.value : '',
|
|
|
- isUserMessage: message.role === 'user',
|
|
|
- }
|
|
|
- ));
|
|
|
- });
|
|
|
- }
|
|
|
- };
|
|
|
+ // Effects
|
|
|
+ useFetchAndSetMessageDataEffect(setMessageLogs, threadData?.threadId);
|
|
|
|
|
|
- if (threadData != null) {
|
|
|
- fetchAndSetMessageData();
|
|
|
+ // Functions
|
|
|
+ const createThread = useCallback(async(initialUserMessage: string) => {
|
|
|
+ if (isEditorAssistant) {
|
|
|
+ const thread = await createThreadForEditorAssistant();
|
|
|
+ return thread;
|
|
|
}
|
|
|
- }, [mutateMessageData, threadData]);
|
|
|
+
|
|
|
+ if (aiAssistantData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const thread = await createThreadForKnowledgeAssistant(aiAssistantData._id, initialUserMessage);
|
|
|
+ return thread;
|
|
|
+ }, [aiAssistantData, createThreadForEditorAssistant, createThreadForKnowledgeAssistant, isEditorAssistant]);
|
|
|
+
|
|
|
+ const postMessage = useCallback(async(currentThreadId: string, input: string, summaryMode?: boolean) => {
|
|
|
+ if (isEditorAssistant) {
|
|
|
+ const response = await postMessageForEditorAssistant(currentThreadId, input);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ if (aiAssistantData?._id != null) {
|
|
|
+ const response = postMessageForKnowledgeAssistant(aiAssistantData._id, currentThreadId, input, summaryMode);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }, [aiAssistantData?._id, isEditorAssistant, postMessageForEditorAssistant, postMessageForKnowledgeAssistant]);
|
|
|
|
|
|
const isGenerating = generatingAnswerMessage != null;
|
|
|
const submit = useCallback(async(data: FormData) => {
|
|
|
@@ -125,36 +158,30 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
let currentThreadId_ = currentThreadId;
|
|
|
if (currentThreadId_ == null) {
|
|
|
try {
|
|
|
- const res = await apiv3Post<IThreadRelationHasId>('/openai/thread', {
|
|
|
- aiAssistantId: aiAssistantData._id,
|
|
|
- initialUserMessage: newUserMessage.content,
|
|
|
- });
|
|
|
-
|
|
|
- const thread = res.data;
|
|
|
+ const thread = await createThread(newUserMessage.content);
|
|
|
+ if (thread == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
setCurrentThreadId(thread.threadId);
|
|
|
- setCurrentThreadTitle(thread.title);
|
|
|
-
|
|
|
currentThreadId_ = thread.threadId;
|
|
|
-
|
|
|
- // No need to await because data is not used
|
|
|
- mutateThreadData();
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err.toString());
|
|
|
- toastError(t('sidebar_aichat.failed_to_create_or_retrieve_thread'));
|
|
|
+ toastError(t('sidebar_ai_assistant.failed_to_create_or_retrieve_thread'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// post message
|
|
|
try {
|
|
|
- const response = await fetch('/_api/v3/openai/message', {
|
|
|
- method: 'POST',
|
|
|
- headers: { 'Content-Type': 'application/json' },
|
|
|
- body: JSON.stringify({
|
|
|
- userMessage: data.input, threadId: currentThreadId_, summaryMode: data.summaryMode, aiAssistantId: aiAssistantData._id,
|
|
|
- }),
|
|
|
- });
|
|
|
+ if (currentThreadId_ == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const response = await postMessage(currentThreadId_, data.input, data.summaryMode);
|
|
|
+ if (response == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if (!response.ok) {
|
|
|
const resJson = await response.json();
|
|
|
@@ -165,7 +192,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
|
|
|
const hasThreadIdNotSetError = resJson.errors.some(err => err.code === MessageErrorCode.THREAD_ID_IS_NOT_SET);
|
|
|
if (hasThreadIdNotSetError) {
|
|
|
- toastError(t('sidebar_aichat.failed_to_create_or_retrieve_thread'));
|
|
|
+ toastError(t('sidebar_ai_assistant.failed_to_create_or_retrieve_thread'));
|
|
|
}
|
|
|
}
|
|
|
setGeneratingAnswerMessage(undefined);
|
|
|
@@ -195,18 +222,35 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
const textValues: string[] = [];
|
|
|
const lines = chunk.split('\n\n');
|
|
|
lines.forEach((line) => {
|
|
|
- const trimedLine = line.trim();
|
|
|
- if (trimedLine.startsWith('data:')) {
|
|
|
+ const trimmedLine = line.trim();
|
|
|
+ if (trimmedLine.startsWith('data:')) {
|
|
|
const data = JSON.parse(line.replace('data: ', ''));
|
|
|
- textValues.push(data.content[0].text.value);
|
|
|
+
|
|
|
+ processMessageForKnowledgeAssistant(data, {
|
|
|
+ onMessage: (data) => {
|
|
|
+ textValues.push(data.content[0].text.value);
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ processMessageForEditorAssistant(data, {
|
|
|
+ onMessage: (data) => {
|
|
|
+ textValues.push(data.appendedMessage);
|
|
|
+ },
|
|
|
+ onDetectedDiff: (data) => {
|
|
|
+ console.log('sse diff', { data });
|
|
|
+ },
|
|
|
+ onFinalized: (data) => {
|
|
|
+ console.log('sse finalized', { data });
|
|
|
+ },
|
|
|
+ });
|
|
|
}
|
|
|
- else if (trimedLine.startsWith('error:')) {
|
|
|
+ else if (trimmedLine.startsWith('error:')) {
|
|
|
const error = JSON.parse(line.replace('error: ', ''));
|
|
|
logger.error(error.errorMessage);
|
|
|
form.setError('input', { type: 'manual', message: error.message });
|
|
|
|
|
|
if (error.code === StreamErrorCode.BUDGET_EXCEEDED) {
|
|
|
- setErrorMessage(growiCloudUri != null ? 'sidebar_aichat.budget_exceeded_for_growi_cloud' : 'sidebar_aichat.budget_exceeded');
|
|
|
+ setErrorMessage(growiCloudUri != null ? 'sidebar_ai_assistant.budget_exceeded_for_growi_cloud' : 'sidebar_ai_assistant.budget_exceeded');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -230,7 +274,8 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
form.setError('input', { type: 'manual', message: err.toString() });
|
|
|
}
|
|
|
|
|
|
- }, [isGenerating, messageLogs, form, currentThreadId, aiAssistantData._id, mutateThreadData, t, growiCloudUri]);
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ }, [isGenerating, messageLogs, form, currentThreadId, createThread, t, postMessage, processMessageForKnowledgeAssistant, processMessageForEditorAssistant, growiCloudUri]);
|
|
|
|
|
|
const keyDownHandler = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
|
@@ -238,28 +283,74 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // Views
|
|
|
+ const headerIcon = useMemo(() => {
|
|
|
+ return isEditorAssistant
|
|
|
+ ? headerIconForEditorAssistant
|
|
|
+ : headerIconForKnowledgeAssistant;
|
|
|
+ }, [headerIconForEditorAssistant, headerIconForKnowledgeAssistant, isEditorAssistant]);
|
|
|
+
|
|
|
+ const headerText = useMemo(() => {
|
|
|
+ return isEditorAssistant
|
|
|
+ ? headerTextForEditorAssistant
|
|
|
+ : headerTextForKnowledgeAssistant;
|
|
|
+ }, [isEditorAssistant, headerTextForEditorAssistant, headerTextForKnowledgeAssistant]);
|
|
|
+
|
|
|
+ const placeHolder = useMemo(() => {
|
|
|
+ if (form.formState.isSubmitting) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return t(isEditorAssistant
|
|
|
+ ? placeHolderForEditorAssistant
|
|
|
+ : placeHolderForKnowledgeAssistant);
|
|
|
+ }, [form.formState.isSubmitting, isEditorAssistant, placeHolderForEditorAssistant, placeHolderForKnowledgeAssistant, t]);
|
|
|
+
|
|
|
+ const initialView = useMemo(() => {
|
|
|
+ if (isEditorAssistant) {
|
|
|
+ return generateInitialViewForEditorAssistant(submit);
|
|
|
+ }
|
|
|
+
|
|
|
+ return initialViewForKnowledgeAssistant;
|
|
|
+ }, [generateInitialViewForEditorAssistant, initialViewForKnowledgeAssistant, isEditorAssistant, submit]);
|
|
|
+
|
|
|
+ const messageCard = useCallback(
|
|
|
+ (role: MessageCardRole, children: string, messageId?: string, messageLogs?: MessageLog[], generatingAnswerMessage?: MessageLog) => {
|
|
|
+ if (isEditorAssistant) {
|
|
|
+ if (messageId == null || messageLogs == null) {
|
|
|
+ return <></>;
|
|
|
+ }
|
|
|
+ return generateMessageCardForEditorAssistant(role, children, messageId, messageLogs, generatingAnswerMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ return generateMessageCardForKnowledgeAssistant(role, children);
|
|
|
+ }, [generateMessageCardForEditorAssistant, generateMessageCardForKnowledgeAssistant, isEditorAssistant],
|
|
|
+ );
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<div className="d-flex flex-column vh-100">
|
|
|
<div className="d-flex align-items-center p-3 border-bottom position-sticky top-0 bg-body z-1">
|
|
|
- <span className="growi-custom-icons growi-ai-chat-icon me-3 fs-4">ai_assistant</span>
|
|
|
- <h5 className="mb-0 fw-bold flex-grow-1 text-truncate">{currentThreadTitle ?? aiAssistantData.name}</h5>
|
|
|
+ {headerIcon}
|
|
|
+ <h5 className="mb-0 fw-bold flex-grow-1 text-truncate">
|
|
|
+ {headerText}
|
|
|
+ </h5>
|
|
|
<button
|
|
|
type="button"
|
|
|
className="btn btn-link p-0 border-0"
|
|
|
- onClick={closeAiAssistantChatSidebar}
|
|
|
+ onClick={closeAiAssistantSidebar}
|
|
|
>
|
|
|
<span className="material-symbols-outlined">close</span>
|
|
|
</button>
|
|
|
</div>
|
|
|
<div className="p-4 d-flex flex-column gap-4 vh-100">
|
|
|
|
|
|
-
|
|
|
{ currentThreadId != null
|
|
|
? (
|
|
|
<div className="vstack gap-4 pb-2">
|
|
|
{ messageLogs.map(message => (
|
|
|
- <MessageCard key={message.id} role={message.isUserMessage ? 'user' : 'assistant'}>{message.content}</MessageCard>
|
|
|
+ <>
|
|
|
+ {messageCard(message.isUserMessage ? 'user' : 'assistant', message.content, message.id, messageLogs, generatingAnswerMessage)}
|
|
|
+ </>
|
|
|
)) }
|
|
|
{ generatingAnswerMessage != null && (
|
|
|
<MessageCard role="assistant">{generatingAnswerMessage.content}</MessageCard>
|
|
|
@@ -267,47 +358,14 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
{ messageLogs.length > 0 && (
|
|
|
<div className="d-flex justify-content-center">
|
|
|
<span className="bg-body-tertiary text-body-secondary rounded-pill px-3 py-1" style={{ fontSize: 'smaller' }}>
|
|
|
- {t('sidebar_aichat.caution_against_hallucination')}
|
|
|
+ {t('sidebar_ai_assistant.caution_against_hallucination')}
|
|
|
</span>
|
|
|
</div>
|
|
|
)}
|
|
|
</div>
|
|
|
)
|
|
|
: (
|
|
|
- <>
|
|
|
- <p className="fs-6 text-body-secondary mb-0">
|
|
|
- {aiAssistantData.description}
|
|
|
- </p>
|
|
|
-
|
|
|
- <div>
|
|
|
- <p className="text-body-secondary">{t('sidebar_aichat.instruction_label')}</p>
|
|
|
- <div className="card bg-body-tertiary border-0">
|
|
|
- <div className="card-body p-3">
|
|
|
- <p className="fs-6 text-body-secondary mb-0">
|
|
|
- {aiAssistantData.additionalInstruction}
|
|
|
- </p>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div>
|
|
|
- <div className="d-flex align-items-center">
|
|
|
- <p className="text-body-secondary mb-0">{t('sidebar_aichat.reference_pages_label')}</p>
|
|
|
- </div>
|
|
|
- <div className="d-flex flex-column gap-1">
|
|
|
- { aiAssistantData.pagePathPatterns.map(pagePathPattern => (
|
|
|
- <a
|
|
|
- key={pagePathPattern}
|
|
|
- href="#"
|
|
|
- className="fs-6 text-body-secondary text-decoration-none"
|
|
|
- >
|
|
|
- {pagePathPattern}
|
|
|
- </a>
|
|
|
- ))}
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- </>
|
|
|
+ <>{ initialView }</>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -324,7 +382,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
className="form-control textarea-ask"
|
|
|
style={{ resize: 'none' }}
|
|
|
rows={1}
|
|
|
- placeholder={!form.formState.isSubmitting ? t('sidebar_aichat.placeholder') : ''}
|
|
|
+ placeholder={placeHolder}
|
|
|
onKeyDown={keyDownHandler}
|
|
|
disabled={form.formState.isSubmitting}
|
|
|
/>
|
|
|
@@ -348,7 +406,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
disabled={form.formState.isSubmitting || isGenerating}
|
|
|
/>
|
|
|
<label className="form-check-label" htmlFor="swSummaryMode">
|
|
|
- {t('sidebar_aichat.summary_mode_label')}
|
|
|
+ {t('sidebar_ai_assistant.summary_mode_label')}
|
|
|
</label>
|
|
|
|
|
|
{/* Help */}
|
|
|
@@ -362,7 +420,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
<UncontrolledTooltip
|
|
|
target="tooltipForHelpOfSummaryMode"
|
|
|
>
|
|
|
- {t('sidebar_aichat.summary_mode_help')}
|
|
|
+ {t('sidebar_ai_assistant.summary_mode_help')}
|
|
|
</UncontrolledTooltip>
|
|
|
</div>
|
|
|
</form>
|
|
|
@@ -371,7 +429,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
<div className="mt-4 bg-danger bg-opacity-10 rounded-3 p-2 w-100">
|
|
|
<div>
|
|
|
<span className="material-symbols-outlined text-danger me-2">error</span>
|
|
|
- <span className="text-danger">{ errorMessage != null ? t(errorMessage) : t('sidebar_aichat.error_message') }</span>
|
|
|
+ <span className="text-danger">{ errorMessage != null ? t(errorMessage) : t('sidebar_ai_assistant.error_message') }</span>
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
@@ -383,7 +441,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
<span className={`material-symbols-outlined mt-2 me-1 ${isErrorDetailCollapsed ? 'rotate-90' : ''}`}>
|
|
|
chevron_right
|
|
|
</span>
|
|
|
- <span className="small">{t('sidebar_aichat.show_error_detail')}</span>
|
|
|
+ <span className="small">{t('sidebar_ai_assistant.show_error_detail')}</span>
|
|
|
</button>
|
|
|
|
|
|
<Collapse isOpen={isErrorDetailCollapsed}>
|
|
|
@@ -406,28 +464,26 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
|
|
|
};
|
|
|
|
|
|
|
|
|
-export const AiAssistantChatSidebar: FC = memo((): JSX.Element => {
|
|
|
+export const AiAssistantSidebar: FC = memo((): JSX.Element => {
|
|
|
const sidebarRef = useRef<HTMLDivElement>(null);
|
|
|
const sidebarScrollerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
- const { data: aiAssistantChatSidebarData, close: closeAiAssistantChatSidebar } = useAiAssistantChatSidebar();
|
|
|
+ const { data: aiAssistantSidebarData, close: closeAiAssistantSidebar } = useAiAssistantSidebar();
|
|
|
+ const { mutate: mutateIsEnableUnifiedMergeView } = useIsEnableUnifiedMergeView();
|
|
|
|
|
|
- const aiAssistantData = aiAssistantChatSidebarData?.aiAssistantData;
|
|
|
- const threadData = aiAssistantChatSidebarData?.threadData;
|
|
|
- const isOpened = aiAssistantChatSidebarData?.isOpened && aiAssistantData != null;
|
|
|
+ const aiAssistantData = aiAssistantSidebarData?.aiAssistantData;
|
|
|
+ const threadData = aiAssistantSidebarData?.threadData;
|
|
|
+ const isOpened = aiAssistantSidebarData?.isOpened;
|
|
|
+ const isEditorAssistant = aiAssistantSidebarData?.isEditorAssistant ?? false;
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const handleClickOutside = (event: MouseEvent) => {
|
|
|
- if (isOpened && sidebarRef.current && !sidebarRef.current.contains(event.target as Node)) {
|
|
|
- closeAiAssistantChatSidebar();
|
|
|
- }
|
|
|
- };
|
|
|
+ useAiAssistantSidebarCloseEffectForEditorAssistant();
|
|
|
+ useAiAssistantSidebarCloseEffectForKnowledgeAssistant(sidebarRef);
|
|
|
|
|
|
- document.addEventListener('mousedown', handleClickOutside);
|
|
|
- return () => {
|
|
|
- document.removeEventListener('mousedown', handleClickOutside);
|
|
|
- };
|
|
|
- }, [closeAiAssistantChatSidebar, isOpened]);
|
|
|
+ useEffect(() => {
|
|
|
+ if (!aiAssistantSidebarData?.isOpened) {
|
|
|
+ mutateIsEnableUnifiedMergeView(false);
|
|
|
+ }
|
|
|
+ }, [aiAssistantSidebarData?.isOpened, mutateIsEnableUnifiedMergeView]);
|
|
|
|
|
|
if (!isOpened) {
|
|
|
return <></>;
|
|
|
@@ -444,10 +500,11 @@ export const AiAssistantChatSidebar: FC = memo((): JSX.Element => {
|
|
|
className="h-100 position-relative"
|
|
|
autoHide
|
|
|
>
|
|
|
- <AiAssistantChatSidebarSubstance
|
|
|
+ <AiAssistantSidebarSubstance
|
|
|
+ isEditorAssistant={isEditorAssistant}
|
|
|
threadData={threadData}
|
|
|
aiAssistantData={aiAssistantData}
|
|
|
- closeAiAssistantChatSidebar={closeAiAssistantChatSidebar}
|
|
|
+ closeAiAssistantSidebar={closeAiAssistantSidebar}
|
|
|
/>
|
|
|
</SimpleBar>
|
|
|
</div>
|