diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index efdc7223ea..0bba196e1d 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -89,6 +89,7 @@ import { buildUserSteeringHintPrompt, logBillingEvent, ApiKeyUpdatedEvent, + LegacyAgentProtocol, type InjectionSource, startMemoryService, } from '@google/gemini-cli-core'; @@ -118,6 +119,7 @@ import { computeTerminalTitle } from '../utils/windowTitle.js'; import { useTextBuffer } from './components/shared/text-buffer.js'; import { useLogger } from './hooks/useLogger.js'; import { useGeminiStream } from './hooks/useGeminiStream.js'; +import { useAgentStream } from './hooks/useAgentStream.js'; import { type BackgroundTask } from './hooks/useExecutionLifecycle.js'; import { useVim } from './hooks/vim.js'; import { type LoadableSettingScope, SettingScope } from '../config/settings.js'; @@ -1161,6 +1163,46 @@ Logging in with Google... Restarting Gemini CLI to continue. }; }, [config]); + const streamAgent = useMemo( + () => + config?.getAgentSessionInteractiveEnabled() + ? new LegacyAgentProtocol({ config, getPreferredEditor }) + : undefined, + [config, getPreferredEditor], + ); + + const activeStream = streamAgent + ? // eslint-disable-next-line react-hooks/rules-of-hooks + useAgentStream({ + agent: streamAgent, + addItem: historyManager.addItem, + onCancelSubmit, + isShellFocused: embeddedShellFocused, + logger, + }) + : // eslint-disable-next-line react-hooks/rules-of-hooks + useGeminiStream( + config.getGeminiClient(), + historyManager.history, + historyManager.addItem, + config, + settings, + setDebugMessage, + handleSlashCommand, + shellModeActive, + getPreferredEditor, + onAuthError, + performMemoryRefresh, + modelSwitchedFromQuotaError, + setModelSwitchedFromQuotaError, + onCancelSubmit, + setEmbeddedShellFocused, + terminalWidth, + terminalHeight, + embeddedShellFocused, + consumePendingHints, + ); + const { streamingState, submitQuery, @@ -1180,27 +1222,7 @@ Logging in with Google... Restarting Gemini CLI to continue. backgroundTasks, dismissBackgroundTask, retryStatus, - } = useGeminiStream( - config.getGeminiClient(), - historyManager.history, - historyManager.addItem, - config, - settings, - setDebugMessage, - handleSlashCommand, - shellModeActive, - getPreferredEditor, - onAuthError, - performMemoryRefresh, - modelSwitchedFromQuotaError, - setModelSwitchedFromQuotaError, - onCancelSubmit, - setEmbeddedShellFocused, - terminalWidth, - terminalHeight, - embeddedShellFocused, - consumePendingHints, - ); + } = activeStream; const pendingHistoryItems = useMemo( () => [...pendingSlashCommandHistoryItems, ...pendingGeminiHistoryItems], @@ -1783,7 +1805,7 @@ Logging in with Google... Restarting Gemini CLI to continue. if (keyMatchers[Command.QUIT](key)) { // If the user presses Ctrl+C, we want to cancel any ongoing requests. // This should happen regardless of the count. - cancelOngoingRequest?.(); + void cancelOngoingRequest?.(); handleCtrlCPress(); return true;