@@ -9,6 +9,7 @@ import { useClickAway } from "@/hooks/useClickAway";
99import VisibleKey from "@/components/Common/VisibleKey" ;
1010import { useConnectStore } from "@/stores/connectStore" ;
1111import FontIcon from "@/components/Common/Icons/FontIcon" ;
12+ import { useChatStore } from "@/stores/chatStore" ;
1213import { AI_ASSISTANT_PANEL_ID } from "@/constants" ;
1314import { useShortcutsStore } from "@/stores/shortcutsStore" ;
1415
@@ -18,58 +19,69 @@ interface AssistantListProps {
1819
1920export function AssistantList ( { showChatHistory = true } : AssistantListProps ) {
2021 const { t } = useTranslation ( ) ;
22+ const { connected } = useChatStore ( ) ;
2123 const isTauri = useAppStore ( ( state ) => state . isTauri ) ;
2224 const currentService = useConnectStore ( ( state ) => state . currentService ) ;
2325 const currentAssistant = useConnectStore ( ( state ) => state . currentAssistant ) ;
2426 const setCurrentAssistant = useConnectStore (
2527 ( state ) => state . setCurrentAssistant
2628 ) ;
29+ const aiAssistant = useShortcutsStore ( ( state ) => state . aiAssistant ) ;
2730
2831 const [ isOpen , setIsOpen ] = useState ( false ) ;
2932 const [ isRefreshing , setIsRefreshing ] = useState ( false ) ;
30- const aiAssistant = useShortcutsStore ( ( state ) => {
31- return state . aiAssistant ;
32- } ) ;
3333 const menuRef = useRef < HTMLDivElement > ( null ) ;
3434
3535 useClickAway ( menuRef , ( ) => setIsOpen ( false ) ) ;
3636 const [ assistants , setAssistants ] = useState < any [ ] > ( [ ] ) ;
3737
38- const fetchAssistant = useCallback ( async ( ) => {
38+ const fetchAssistant = useCallback ( async ( serverId : string ) => {
3939 if ( ! isTauri ) return ;
40- if ( ! currentService ?. id ) return ;
40+ if ( ! serverId ) return ;
4141 platformAdapter
4242 . commands ( "assistant_search" , {
43- serverId : currentService ?. id ,
43+ serverId,
4444 } )
4545 . then ( ( res : any ) => {
4646 res = res ? JSON . parse ( res ) : null ;
4747 console . log ( "assistant_search" , res ) ;
4848 const assistantList = res ?. hits ?. hits || [ ] ;
4949 setAssistants ( assistantList ) ;
50- if ( assistantList . length > 0 && ! currentAssistant ) {
51- setCurrentAssistant ( assistantList [ 0 ] ) ;
50+ if ( assistantList . length > 0 ) {
51+ const assistant = assistantList . find (
52+ ( item : any ) => item . _id === currentAssistant ?. _id
53+ ) ;
54+ if ( assistant ) {
55+ setCurrentAssistant ( assistant ) ;
56+ } else {
57+ setCurrentAssistant ( assistantList [ 0 ] ) ;
58+ }
5259 }
60+ } )
61+ . catch ( ( err : any ) => {
62+ setAssistants ( [ ] ) ;
63+ setCurrentAssistant ( null ) ;
64+ console . log ( "assistant_search" , err ) ;
5365 } ) ;
5466 } , [ ] ) ;
5567
5668 useEffect ( ( ) => {
57- fetchAssistant ( ) ;
58- } , [ ] ) ;
69+ connected && fetchAssistant ( currentService ?. id ) ;
70+ } , [ connected , currentService ?. id ] ) ;
5971
60- const handleRefresh = async ( ) => {
72+ const handleRefresh = useCallback ( async ( ) => {
6173 setIsRefreshing ( true ) ;
62- await fetchAssistant ( ) ;
74+ await fetchAssistant ( currentService ?. id ) ;
6375 setTimeout ( ( ) => setIsRefreshing ( false ) , 1000 ) ;
64- } ;
76+ } , [ currentService ?. id ] ) ;
6577
6678 return (
6779 < div className = "relative" ref = { menuRef } >
6880 < button
6981 onClick = { ( ) => setIsOpen ( ! isOpen ) }
7082 className = "h-6 p-1 px-1.5 flex items-center gap-1 rounded-full bg-white dark:bg-[#202126] text-sm/6 font-semibold text-gray-800 dark:text-[#d8d8d8] border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none"
7183 >
72- < div className = "w-4 h-4 flex justify-center items-center rounded-full bg-gray-200 dark:bg-gray-800 " >
84+ < div className = "w-4 h-4 flex justify-center items-center rounded-full bg-white " >
7385 { currentAssistant ?. _source ?. icon ?. startsWith ( "font_" ) ? (
7486 < FontIcon
7587 name = { currentAssistant . _source . icon }
@@ -139,11 +151,16 @@ export function AssistantList({ showChatHistory = true }: AssistantListProps) {
139151 }` }
140152 >
141153 { assistant . _source ?. icon ?. startsWith ( "font_" ) ? (
142- < FontIcon name = { assistant . _source ?. icon } className = "w-4 h-4" />
154+ < div className = "w-7 h-7 flex items-center justify-center rounded-full bg-white" >
155+ < FontIcon
156+ name = { assistant . _source ?. icon }
157+ className = "w-5 h-5"
158+ />
159+ </ div >
143160 ) : (
144161 < img
145162 src = { logoImg }
146- className = "w-4 h-4 rounded-full"
163+ className = "w-5 h-5 rounded-full"
147164 alt = { assistant . name }
148165 />
149166 ) }
0 commit comments