@@ -22,14 +22,16 @@ export function useChatStream(options: UseChatStreamOptions) {
2222 const startChatPerformanceTrace = useSystemStore ( ( s ) => s . startChatPerformanceTrace ) ;
2323 const markChatFirstToken = useSystemStore ( ( s ) => s . markChatFirstToken ) ;
2424 const finalizeChatPerformanceTrace = useSystemStore ( ( s ) => s . finalizeChatPerformanceTrace ) ;
25+ const setLoading = useSystemStore ( ( s ) => s . setLoading ) ;
26+ const isLoading = useSystemStore ( ( s ) => s . isLoading ) ;
2527 const [ chatInput , setChatInput ] = useState ( '' ) ;
26- const [ isChatLoading , setIsChatLoading ] = useState ( false ) ;
2728 const { sessionId, isMuted, onConnectionChange, onClearError, onError } = options ;
2829
2930 const handleChatSend = useCallback (
3031 async ( text ?: string ) => {
3132 const content = ( text ?? chatInput ) . trim ( ) ;
32- if ( ! content || isChatLoading ) return ;
33+ if ( ! content ) return ;
34+ if ( useSystemStore . getState ( ) . isLoading ) return ;
3335
3436 if ( ! text ) setChatInput ( '' ) ;
3537
@@ -73,7 +75,8 @@ export function useChatStream(options: UseChatStreamOptions) {
7375 meta : { timestamp : Date . now ( ) } ,
7476 isMuted,
7577 speakWith : ( textToSpeak ) => ttsService . speak ( textToSpeak ) ,
76- setLoading : setIsChatLoading ,
78+ setLoading,
79+ onAddAssistantMessage : undefined ,
7780 onAddUserMessage : ( t ) => {
7881 addChatMessage ( 'user' , t ) ;
7982 assistantMessageId = addChatMessage ( 'assistant' , '' , true ) ;
@@ -116,13 +119,13 @@ export function useChatStream(options: UseChatStreamOptions) {
116119 } ,
117120 [
118121 chatInput ,
119- isChatLoading ,
120122 addChatMessage ,
121123 updateChatMessage ,
122124 removeChatMessage ,
123125 startChatPerformanceTrace ,
124126 markChatFirstToken ,
125127 finalizeChatPerformanceTrace ,
128+ setLoading ,
126129 sessionId ,
127130 isMuted ,
128131 onConnectionChange ,
@@ -131,5 +134,5 @@ export function useChatStream(options: UseChatStreamOptions) {
131134 ] ,
132135 ) ;
133136
134- return { chatInput, setChatInput, isChatLoading, handleChatSend } ;
137+ return { chatInput, setChatInput, isChatLoading : isLoading , handleChatSend } ;
135138}
0 commit comments