diff --git a/ui/desktop/src/components/BaseChat.tsx b/ui/desktop/src/components/BaseChat.tsx index e075897c25f8..076be0dbf016 100644 --- a/ui/desktop/src/components/BaseChat.tsx +++ b/ui/desktop/src/components/BaseChat.tsx @@ -119,7 +119,7 @@ function BaseChatContent({ const [hasStartedUsingRecipe, setHasStartedUsingRecipe] = React.useState(false); const [currentRecipeTitle, setCurrentRecipeTitle] = React.useState(null); - const { isCompacting } = useContextManager(); + const { isCompacting, handleManualCompaction } = useContextManager(); // Use shared chat engine const { @@ -383,67 +383,50 @@ function BaseChatContent({ )} - {error && - !(error as Error & { isTokenLimitError?: boolean }).isTokenLimitError && ( - <> -
-
- {error.message || 'Honk! Goose experienced an error while responding'} -
+ {error && ( + <> +
+
+ {error.message || 'Honk! Goose experienced an error while responding'} +
- {/* Action buttons for non-token-limit errors */} -
-
{ - // Create a contextLengthExceeded message similar to token limit errors - const contextMessage: Message = { - id: `context-${Date.now()}`, - role: 'assistant', - created: Math.floor(Date.now() / 1000), - content: [ - { - type: 'contextLengthExceeded', - msg: 'Summarization requested due to error. Creating summary to help resolve the issue.', - }, - ], - display: true, - sendToLLM: false, - }; - - // Add the context message to trigger ContextHandler - const updatedMessages = [...messages, contextMessage]; - setMessages(updatedMessages); - - // Clear the error state since we're handling it with summarization - clearError(); - }} - > - Summarize Conversation -
-
{ - // Find the last user message - const lastUserMessage = messages.reduceRight( - (found, m) => found || (m.role === 'user' ? m : null), - null as Message | null - ); - if (lastUserMessage) { - append(lastUserMessage); - } - }} - > - Retry Last Message -
+ {/* Action buttons for all errors including token limit errors */} +
+
{ + clearError(); + + await handleManualCompaction( + messages, + setMessages, + append, + undefined, // clearAlerts - not needed here since we don't have alerts to clear + setAncestorMessages + ); + }} + > + Summarize Conversation +
+
{ + // Find the last user message + const lastUserMessage = messages.reduceRight( + (found, m) => found || (m.role === 'user' ? m : null), + null as Message | null + ); + if (lastUserMessage) { + append(lastUserMessage); + } + }} + > + Retry Last Message
- - )} - - {/* Token limit errors should be handled by ContextHandler, not shown here */} - {error && - (error as Error & { isTokenLimitError?: boolean }).isTokenLimitError && <>} +
+ + )}
) : showPopularTopics ? (