From 8fcc204f28830fdb390967d7df65454ba808881f Mon Sep 17 00:00:00 2001 From: Lily Delalande <119957291+lily-de@users.noreply.github.com> Date: Tue, 6 May 2025 12:23:56 -0400 Subject: [PATCH] cxt-mgmt: only two retries for summarization and move to prod (#2440) --- ui/desktop/src/components/ChatView.tsx | 26 ++--- .../ContextLengthExceededHandler.tsx | 104 ++++++++++++++---- 2 files changed, 92 insertions(+), 38 deletions(-) diff --git a/ui/desktop/src/components/ChatView.tsx b/ui/desktop/src/components/ChatView.tsx index 6ae0ffbe..4d7636f4 100644 --- a/ui/desktop/src/components/ChatView.tsx +++ b/ui/desktop/src/components/ChatView.tsx @@ -524,9 +524,8 @@ function ChatContent({ ) : ( <> - {/* Only render GooseMessage if it's not a CLE message (and we are not in alpha mode) */} - {process.env.NODE_ENV === 'development' && - hasContextLengthExceededContent(message) ? ( + {/* Only render GooseMessage if it's not a CLE message */} + {hasContextLengthExceededContent(message) ? ( {showGame && setShowGame(false)} />} - {process.env.NODE_ENV === 'development' && ( - { - updateSummary(editedContent); - closeSummaryModal(); - }} - summaryContent={summaryContent} - /> - )} + + { + updateSummary(editedContent); + closeSummaryModal(); + }} + summaryContent={summaryContent} + /> ); } diff --git a/ui/desktop/src/components/context_management/ContextLengthExceededHandler.tsx b/ui/desktop/src/components/context_management/ContextLengthExceededHandler.tsx index 1681c86c..484192a9 100644 --- a/ui/desktop/src/components/context_management/ContextLengthExceededHandler.tsx +++ b/ui/desktop/src/components/context_management/ContextLengthExceededHandler.tsx @@ -24,6 +24,7 @@ export const ContextLengthExceededHandler: React.FC { if (!shouldAllowSummaryInteraction) return; + // Only increment retry counter if there's an error + if (errorLoadingSummary) { + setRetryCount((prevCount) => prevCount + 1); + } + // Reset states for retry setHasFetchStarted(false); fetchStartedRef.current = false; @@ -79,7 +85,78 @@ export const ContextLengthExceededHandler: React.FC { + try { + // Use the workingDir from props directly without reassignment to avoid TypeScript error + const sessionWorkingDir = window.appConfig?.get('GOOSE_WORKING_DIR') || workingDir; + console.log(`Creating new chat window with working dir: ${sessionWorkingDir}`); + window.electron.createChatWindow(undefined, sessionWorkingDir as string); + } catch (error) { + console.error('Error creating new window:', error); + // Fallback to basic window.open if the electron API fails + window.open('/', '_blank'); + } + }; + // Render the notification UI + const renderLoadingState = () => ( +
+ Preparing summary... + +
+ ); + + const renderFailedState = () => ( + <> + {`Your conversation has exceeded the model's context capacity`} + {`This conversation has too much information to continue. Extension data often takes up significant space.`} + + + ); + + const renderRetryState = () => ( + <> + {`Your conversation has exceeded the model's context capacity`} + + + ); + + const renderSuccessState = () => ( + <> + {`Your conversation has exceeded the model's context capacity and a summary was prepared.`} + {`Messages above this line remain viewable but specific details are not included in active context.`} + + + ); + + const renderContentState = () => { + if (!shouldAllowSummaryInteraction) { + return null; + } + + if (errorLoadingSummary) { + return retryCount >= 2 ? renderFailedState() : renderRetryState(); + } + + return renderSuccessState(); + }; + return (
{/* Horizontal line with text in the middle - shown regardless of loading state */} @@ -88,30 +165,9 @@ export const ContextLengthExceededHandler: React.FC
- {isLoadingSummary && shouldAllowSummaryInteraction ? ( - // Show loading indicator during loading state -
- Preparing summary... - -
- ) : ( - // Show different UI based on whether it's already handled - <> - {`Your conversation has exceeded the model's context capacity`} - {`Messages above this line remain viewable but are not included in the active context`} - {/* Only show the button if its last message */} - {shouldAllowSummaryInteraction && ( - - )} - - )} + {isLoadingSummary && shouldAllowSummaryInteraction + ? renderLoadingState() + : renderContentState()} ); };