diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 1271c86a..75de2cf2 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -125,6 +125,7 @@ vi.mock('@gemini-cli/core', async (importOriginal) => { getGeminiClient: vi.fn(() => ({})), getCheckpointingEnabled: vi.fn(() => opts.checkpointing ?? true), getAllGeminiMdFilenames: vi.fn(() => ['GEMINI.md']), + setFlashFallbackHandler: vi.fn(), }; }); return { diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index c25d74e2..7824f0f7 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -115,6 +115,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { const [editorError, setEditorError] = useState(null); const [footerHeight, setFooterHeight] = useState(0); const [corgiMode, setCorgiMode] = useState(false); + const [currentModel, setCurrentModel] = useState(config.getModel()); const [shellModeActive, setShellModeActive] = useState(false); const [showErrorDetails, setShowErrorDetails] = useState(false); const [showToolDescriptions, setShowToolDescriptions] = @@ -214,6 +215,42 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { } }, [config, addItem]); + // Watch for model changes (e.g., from Flash fallback) + useEffect(() => { + const checkModelChange = () => { + const configModel = config.getModel(); + if (configModel !== currentModel) { + setCurrentModel(configModel); + } + }; + + // Check immediately and then periodically + checkModelChange(); + const interval = setInterval(checkModelChange, 1000); // Check every second + + return () => clearInterval(interval); + }, [config, currentModel]); + + // Set up Flash fallback handler + useEffect(() => { + const flashFallbackHandler = async ( + currentModel: string, + fallbackModel: string, + ): Promise => { + // Add message to UI history + addItem( + { + type: MessageType.INFO, + text: `⚡ Rate limiting detected. Automatically switching from ${currentModel} to ${fallbackModel} for faster responses for the remainder of this session.`, + }, + Date.now(), + ); + return true; // Always accept the fallback + }; + + config.setFlashFallbackHandler(flashFallbackHandler); + }, [config, addItem]); + const { handleSlashCommand, slashCommands, @@ -787,7 +824,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { )}