Procházet zdrojové kódy

Request with the selected aiAssistantId

Shun Miyazawa před 1 rokem
rodič
revize
6a9f1ce93e

+ 5 - 6
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/AiAssistantDropdown.tsx

@@ -14,12 +14,11 @@ import { useSWRxAiAssistants } from '../../../stores/ai-assistant';
 import { getShareScopeIcon } from '../../../utils/get-share-scope-Icon';
 import { getShareScopeIcon } from '../../../utils/get-share-scope-Icon';
 
 
 type Props = {
 type Props = {
-  //
+  selectedAiAssistant?: AiAssistantHasId;
+  onSelect(aiAssistant?: AiAssistantHasId): void
 }
 }
 
 
-export const AiAssistantDropdown = (props: Props): JSX.Element => {
-  const [selectedAiAssistant, setSelectedAiAssistant] = useState<AiAssistantHasId>();
-
+export const AiAssistantDropdown = ({ selectedAiAssistant, onSelect }: Props): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { data: aiAssistantData } = useSWRxAiAssistants();
   const { data: aiAssistantData } = useSWRxAiAssistants();
 
 
@@ -42,8 +41,8 @@ export const AiAssistantDropdown = (props: Props): JSX.Element => {
   }, []);
   }, []);
 
 
   const selectAiAssistantHandler = useCallback((aiAssistant?: AiAssistantHasId) => {
   const selectAiAssistantHandler = useCallback((aiAssistant?: AiAssistantHasId) => {
-    setSelectedAiAssistant(aiAssistant);
-  }, []);
+    onSelect(aiAssistant);
+  }, [onSelect]);
 
 
   return (
   return (
     <UncontrolledDropdown>
     <UncontrolledDropdown>

+ 10 - 2
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/AiAssistantSidebar.tsx

@@ -66,6 +66,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
   const [generatingAnswerMessage, setGeneratingAnswerMessage] = useState<Message>();
   const [generatingAnswerMessage, setGeneratingAnswerMessage] = useState<Message>();
   const [errorMessage, setErrorMessage] = useState<string | undefined>();
   const [errorMessage, setErrorMessage] = useState<string | undefined>();
   const [isErrorDetailCollapsed, setIsErrorDetailCollapsed] = useState<boolean>(false);
   const [isErrorDetailCollapsed, setIsErrorDetailCollapsed] = useState<boolean>(false);
+  const [selectedAiAssistant, setSelectedAiAssistant] = useState<AiAssistantHasId>();
 
 
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { data: growiCloudUri } = useGrowiCloudUri();
   const { data: growiCloudUri } = useGrowiCloudUri();
@@ -189,7 +190,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
 
 
       const response = await (async() => {
       const response = await (async() => {
         if (isEditorAssistant) {
         if (isEditorAssistant) {
-          return postMessageForEditorAssistant(currentThreadId_, data.input, '# markdown');
+          return postMessageForEditorAssistant(currentThreadId_, data.input, '# markdown', selectedAiAssistant?._id);
         }
         }
         if (aiAssistantData?._id != null) {
         if (aiAssistantData?._id != null) {
           return postMessageForKnowledgeAssistant(aiAssistantData._id, currentThreadId_, data.input, data.summaryMode);
           return postMessageForKnowledgeAssistant(aiAssistantData._id, currentThreadId_, data.input, data.summaryMode);
@@ -312,6 +313,10 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
     // todo: implement
     // todo: implement
   }, []);
   }, []);
 
 
+  const selectAiAssistantHandler = useCallback((aiAssistant?: AiAssistantHasId) => {
+    setSelectedAiAssistant(aiAssistant);
+  }, []);
+
   return (
   return (
     <>
     <>
       <div className="d-flex flex-column vh-100">
       <div className="d-flex flex-column vh-100">
@@ -361,7 +366,10 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
                 ? (
                 ? (
                   <>
                   <>
                     <div className="py-2">
                     <div className="py-2">
-                      <AiAssistantDropdown />
+                      <AiAssistantDropdown
+                        selectedAiAssistant={selectedAiAssistant}
+                        onSelect={selectAiAssistantHandler}
+                      />
                     </div>
                     </div>
                     <QuickMenuList
                     <QuickMenuList
                       onClick={clickQuickMenuHandler}
                       onClick={clickQuickMenuHandler}