@@ -250,6 +250,9 @@ export function ChatInterface() {
250250 const handleSend = async ( ) => {
251251 if ( ! input . trim ( ) && attachments . length === 0 ) return ; // Allow sending attachments only, without text content
252252
253+ // Flag to track if we should reset button states in finally block
254+ let shouldResetButtonStates = true ;
255+
253256 // If in new conversation state, switch to conversation state after sending message
254257 if ( isNewConversation ) {
255258 setIsNewConversation ( false ) ;
@@ -373,6 +376,10 @@ export function ChatInterface() {
373376 t ( "chatInterface.createDialogFailedButContinue" ) ,
374377 error
375378 ) ;
379+ // Reset button states when conversation creation fails
380+ setIsLoading ( false ) ;
381+ setIsStreaming ( false ) ;
382+ return ;
376383 }
377384 }
378385
@@ -594,20 +601,47 @@ export function ChatInterface() {
594601
595602 // Handle preprocessing result
596603 if ( ! result . success ) {
604+ // Reset button states immediately when preprocessing fails
605+ setIsLoading ( false ) ;
606+ setIsStreaming ( false ) ;
607+
608+ // Remove from streaming conversations (both new and existing conversations)
609+ if ( currentConversationId ) {
610+ setStreamingConversations ( ( prev ) => {
611+ const newSet = new Set ( prev ) ;
612+ newSet . delete ( currentConversationId ) ;
613+ return newSet ;
614+ } ) ;
615+ }
616+
597617 setSessionMessages ( ( prev ) => {
598618 const newMessages = { ...prev } ;
599619 const lastMsg =
600620 newMessages [ currentConversationId ] ?. [
601621 newMessages [ currentConversationId ] . length - 1
602622 ] ;
623+
603624 if ( lastMsg && lastMsg . role === ROLE_ASSISTANT ) {
604- lastMsg . error = t ( "chatInterface.fileProcessingFailed" , {
605- error : result . error ,
606- } ) ;
625+ // Handle error codes with internationalization
626+ let errorMessage ;
627+ if ( result . error === 'REQUEST_ENTITY_TOO_LARGE' ) {
628+ errorMessage = t ( "chatInterface.fileSizeExceeded" ) ;
629+ } else if ( result . error === 'FILE_PARSING_FAILED' ) {
630+ errorMessage = t ( "chatInterface.fileParsingFailed" ) ;
631+ } else {
632+ // For any other error, show a generic message without exposing technical details
633+ errorMessage = t ( "chatInterface.fileProcessingFailed" , {
634+ error : "Unknown error"
635+ } ) ;
636+ }
637+
638+ lastMsg . content = errorMessage ;
607639 lastMsg . isComplete = true ;
608640 }
641+
609642 return newMessages ;
610643 } ) ;
644+ shouldResetButtonStates = false ; // Don't reset again in finally block
611645 return ;
612646 }
613647
@@ -810,10 +844,8 @@ export function ChatInterface() {
810844 } ) ;
811845 } else {
812846 log . error ( t ( "chatInterface.errorLabel" ) , error ) ;
813- const errorMessage =
814- error instanceof Error
815- ? error . message
816- : t ( "chatInterface.errorProcessingRequest" ) ;
847+ // Show user-friendly error message instead of technical error details
848+ const errorMessage = t ( "chatInterface.errorProcessingRequest" ) ;
817849 setSessionMessages ( ( prev ) => {
818850 const newMessages = { ...prev } ;
819851 const lastMsg =
@@ -862,6 +894,12 @@ export function ChatInterface() {
862894 } ) ;
863895 }
864896 }
897+ } finally {
898+ // Only reset button states if we should (not when preprocessing fails)
899+ if ( shouldResetButtonStates ) {
900+ setIsLoading ( false ) ;
901+ setIsStreaming ( false ) ;
902+ }
865903 }
866904 } ;
867905
@@ -1085,10 +1123,7 @@ export function ChatInterface() {
10851123
10861124 setConversationLoadError ( ( prev ) => ( {
10871125 ...prev ,
1088- [ dialog . conversation_id ] :
1089- error instanceof Error
1090- ? error . message
1091- : "Failed to load conversation" ,
1126+ [ dialog . conversation_id ] : "Failed to load conversation" ,
10921127 } ) ) ;
10931128 } finally {
10941129 // ensure loading state is cleared
@@ -1228,10 +1263,7 @@ export function ChatInterface() {
12281263
12291264 setConversationLoadError ( ( prev ) => ( {
12301265 ...prev ,
1231- [ dialog . conversation_id ] :
1232- error instanceof Error
1233- ? error . message
1234- : "Failed to load conversation" ,
1266+ [ dialog . conversation_id ] : "Failed to load conversation" ,
12351267 } ) ) ;
12361268 } finally {
12371269 // ensure loading state is cleared
0 commit comments