1- import { FC , useMemo , useState , useCallback } from "react" ;
1+ import { FC , useMemo , useState , useCallback , useEffect } from "react" ;
22import { useTranslation } from "react-i18next" ;
33import { isArray } from "lodash-es" ;
44import { useAsyncEffect , useMount } from "ahooks" ;
@@ -37,6 +37,13 @@ const SharedAi: FC<SharedAiProps> = (props) => {
3737 const { t } = useTranslation ( ) ;
3838 const [ assistantSearchValue , setAssistantSearchValue ] = useState ( "" ) ;
3939 const [ isLoadingAssistants , setIsLoadingAssistants ] = useState ( false ) ;
40+ const { setCloudSelectService } = useConnectStore ( ) ;
41+
42+ useEffect ( ( ) => {
43+ if ( ! server ) return ;
44+
45+ setCloudSelectService ( server ) ;
46+ } , [ server ] ) ;
4047
4148 const getEnabledServers = useCallback ( ( servers : Server [ ] ) : Server [ ] => {
4249 if ( ! isArray ( servers ) ) return [ ] ;
@@ -56,7 +63,9 @@ const SharedAi: FC<SharedAiProps> = (props) => {
5663 }
5764
5865 if ( server ) {
59- const matchServer = enabledServers . find ( ( item ) => item . id === server . id ) ;
66+ const matchServer = enabledServers . find (
67+ ( item ) => item . id === server . id
68+ ) ;
6069 if ( matchServer ) {
6170 setServer ( matchServer ) ;
6271 return ;
@@ -65,7 +74,7 @@ const SharedAi: FC<SharedAiProps> = (props) => {
6574
6675 setServer ( enabledServers [ 0 ] ) ;
6776 } catch ( error ) {
68- console . error ( ' Failed to load servers:' , error ) ;
77+ console . error ( " Failed to load servers:" , error ) ;
6978 addError ( `Failed to load servers: ${ String ( error ) } ` ) ;
7079 }
7180 } ) ;
@@ -86,7 +95,9 @@ const SharedAi: FC<SharedAiProps> = (props) => {
8695 query : assistantSearchValue ,
8796 } ) ;
8897
89- const assistants : Assistant [ ] = data . list . map ( ( item : any ) => item . _source ) ;
98+ const assistants : Assistant [ ] = data . list . map (
99+ ( item : any ) => item . _source
100+ ) ;
90101 setAssistantList ( assistants ) ;
91102
92103 if ( assistants . length === 0 ) {
@@ -104,7 +115,7 @@ const SharedAi: FC<SharedAiProps> = (props) => {
104115
105116 setAssistant ( assistants [ 0 ] ) ;
106117 } catch ( error ) {
107- console . error ( ' Failed to fetch assistants:' , error ) ;
118+ console . error ( " Failed to fetch assistants:" , error ) ;
108119 addError ( `Failed to fetch assistants: ${ String ( error ) } ` ) ;
109120 setAssistantList ( [ ] ) ;
110121 setAssistant ( undefined ) ;
@@ -181,7 +192,9 @@ const SharedAi: FC<SharedAiProps> = (props) => {
181192 searchable = { searchable }
182193 onChange = { onChange }
183194 onSearch = { onSearch }
184- placeholder = { isLoadingAssistants && searchable ? "Loading..." : undefined }
195+ placeholder = {
196+ isLoadingAssistants && searchable ? "Loading..." : undefined
197+ }
185198 />
186199 </ div >
187200 ) ;
0 commit comments