@@ -12,12 +12,13 @@ import FontIcon from "@/components/Common/Icons/FontIcon";
1212import { useChatStore } from "@/stores/chatStore" ;
1313import { AI_ASSISTANT_PANEL_ID } from "@/constants" ;
1414import { useShortcutsStore } from "@/stores/shortcutsStore" ;
15+ import { Get } from "@/api/axiosRequest" ;
1516
1617interface AssistantListProps {
17- showChatHistory ?: boolean ;
18+ assistantIDs ?: string [ ] ;
1819}
1920
20- export function AssistantList ( { showChatHistory = true } : AssistantListProps ) {
21+ export function AssistantList ( { assistantIDs = [ ] } : AssistantListProps ) {
2122 const { t } = useTranslation ( ) ;
2223 const { connected } = useChatStore ( ) ;
2324 const isTauri = useAppStore ( ( state ) => state . isTauri ) ;
@@ -35,34 +36,49 @@ export function AssistantList({ showChatHistory = true }: AssistantListProps) {
3536 useClickAway ( menuRef , ( ) => setIsOpen ( false ) ) ;
3637 const [ assistants , setAssistants ] = useState < any [ ] > ( [ ] ) ;
3738
38- const fetchAssistant = useCallback ( async ( serverId : string ) => {
39- if ( ! isTauri ) return ;
40- if ( ! serverId ) return ;
41- platformAdapter
42- . commands ( "assistant_search" , {
43- serverId,
44- } )
45- . then ( ( res : any ) => {
46- res = res ? JSON . parse ( res ) : null ;
47- console . log ( "assistant_search" , res ) ;
48- const assistantList = res ?. hits ?. hits || [ ] ;
49- setAssistants ( assistantList ) ;
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- }
59- }
60- } )
61- . catch ( ( err : any ) => {
39+ const fetchAssistant = useCallback ( async ( serverId ?: string ) => {
40+ let response : any ;
41+ if ( isTauri ) {
42+ if ( ! serverId ) return ;
43+ try {
44+ response = await platformAdapter . commands ( "assistant_search" , {
45+ serverId,
46+ } ) ;
47+ response = response ? JSON . parse ( response ) : null ;
48+ } catch ( err ) {
6249 setAssistants ( [ ] ) ;
6350 setCurrentAssistant ( null ) ;
64- console . log ( "assistant_search" , err ) ;
65- } ) ;
51+ console . error ( "assistant_search" , err ) ;
52+ }
53+ } else {
54+ const [ error , res ] = await Get ( `/assistant/_search` ) ;
55+ if ( error ) {
56+ setAssistants ( [ ] ) ;
57+ setCurrentAssistant ( null ) ;
58+ console . error ( "assistant_search" , error ) ;
59+ return ;
60+ }
61+ console . log ( "/assistant/_search" , res ) ;
62+ response = res ;
63+ }
64+ console . log ( "assistant_search" , response ) ;
65+ let assistantList = response ?. hits ?. hits || [ ] ;
66+
67+ assistantList = assistantIDs . length > 0
68+ ? assistantList . filter ( ( item : any ) => assistantIDs . includes ( item . _id ) )
69+ : assistantList ;
70+
71+ setAssistants ( assistantList ) ;
72+ if ( assistantList . length > 0 ) {
73+ const assistant = assistantList . find (
74+ ( item : any ) => item . _id === currentAssistant ?. _id
75+ ) ;
76+ if ( assistant ) {
77+ setCurrentAssistant ( assistant ) ;
78+ } else {
79+ setCurrentAssistant ( assistantList [ 0 ] ) ;
80+ }
81+ }
6682 } , [ ] ) ;
6783
6884 useEffect ( ( ) => {
@@ -98,24 +114,22 @@ export function AssistantList({ showChatHistory = true }: AssistantListProps) {
98114 < div className = "max-w-[100px] truncate" >
99115 { currentAssistant ?. _source ?. name || "Coco AI" }
100116 </ div >
101- { showChatHistory && isTauri && (
102- < VisibleKey
103- aria-controls = { isOpen ? AI_ASSISTANT_PANEL_ID : "" }
104- shortcut = { aiAssistant }
105- onKeyPress = { ( ) => {
106- setIsOpen ( ! isOpen ) ;
107- } }
108- >
109- < ChevronDownIcon
110- className = { `size-4 text-gray-500 dark:text-gray-400 transition-transform ${
111- isOpen ? "rotate-180" : ""
112- } `}
113- />
114- </ VisibleKey >
115- ) }
117+ < VisibleKey
118+ aria-controls = { isOpen ? AI_ASSISTANT_PANEL_ID : "" }
119+ shortcut = { aiAssistant }
120+ onKeyPress = { ( ) => {
121+ setIsOpen ( ! isOpen ) ;
122+ } }
123+ >
124+ < ChevronDownIcon
125+ className = { `size-4 text-gray-500 dark:text-gray-400 transition-transform ${
126+ isOpen ? "rotate-180" : ""
127+ } `}
128+ />
129+ </ VisibleKey >
116130 </ button >
117131
118- { showChatHistory && isTauri && isOpen && (
132+ { isOpen && (
119133 < div
120134 id = { isOpen ? AI_ASSISTANT_PANEL_ID : "" }
121135 className = "absolute z-50 top-full mt-1 left-0 w-64 rounded-xl bg-white dark:bg-[#202126] p-2 text-sm/6 text-gray-800 dark:text-white shadow-lg border border-gray-200 dark:border-gray-700 focus:outline-none max-h-[calc(100vh-80px)] overflow-y-auto"
@@ -140,6 +154,7 @@ export function AssistantList({ showChatHistory = true }: AssistantListProps) {
140154 < button
141155 key = { assistant . _id }
142156 onClick = { ( ) => {
157+ console . log ( "assistant" , assistant ) ;
143158 setCurrentAssistant ( assistant ) ;
144159 setIsOpen ( false ) ;
145160 } }
0 commit comments