refactor(cli): remove config dependency from useAgentStream

This commit is contained in:
Michael Bleigh
2026-03-30 12:35:31 -07:00
parent 6020551d1f
commit cd7d91f35e
5 changed files with 32 additions and 28 deletions
+1
View File
@@ -1108,6 +1108,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
addItem: historyManager.addItem,
onCancelSubmit,
isShellFocused: embeddedShellFocused,
logger,
})
: // eslint-disable-next-line react-hooks/rules-of-hooks
useGeminiStream(
@@ -17,12 +17,6 @@ const mockLegacyAgentProtocol = vi.hoisted(() => ({
abort: vi.fn().mockResolvedValue(undefined),
}));
vi.mock('./useLogger.js', () => ({
useLogger: vi.fn().mockReturnValue({
logMessage: vi.fn().mockResolvedValue(undefined),
}),
}));
vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return {
@@ -74,7 +68,7 @@ describe('useAgentStream', () => {
});
expect(mockLegacyAgentProtocol.send).toHaveBeenCalledWith({
message: [{ type: 'text', text: 'hello' }],
message: { content: [{ type: 'text', text: 'hello' }] },
});
expect(mockAddItem).toHaveBeenCalledWith(
expect.objectContaining({ type: MessageType.USER, text: 'hello' }),
+4 -5
View File
@@ -20,6 +20,7 @@ import {
type RetryAttemptPayload,
type AgentEvent,
type AgentProtocol,
type Logger,
} from '@google/gemini-cli-core';
import type {
HistoryItemWithoutId,
@@ -32,10 +33,8 @@ import { findLastSafeSplitPoint } from '../utils/markdownUtilities.js';
import { getToolGroupBorderAppearance } from '../utils/borderStyles.js';
import { type BackgroundShell } from './shellCommandProcessor.js';
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
import { useLogger } from './useLogger.js';
import { useSessionStats } from '../contexts/SessionContext.js';
import { useStateAndRef } from './useStateAndRef.js';
import { useConfig } from '../contexts/ConfigContext.js';
import { type MinimalTrackedToolCall } from './useTurnActivityMonitor.js';
export interface UseAgentStreamOptions {
@@ -43,6 +42,7 @@ export interface UseAgentStreamOptions {
addItem: UseHistoryManagerReturn['addItem'];
onCancelSubmit: (shouldRestorePrompt?: boolean) => void;
isShellFocused?: boolean;
logger?: Logger | null;
}
/**
@@ -54,8 +54,8 @@ export const useAgentStream = ({
addItem,
onCancelSubmit,
isShellFocused,
logger,
}: UseAgentStreamOptions) => {
const config = useConfig();
const [initError] = useState<string | null>(null);
const [retryStatus] = useState<RetryAttemptPayload | null>(null);
const [streamingState, setStreamingState] = useState<StreamingState>(
@@ -78,7 +78,6 @@ export const useAgentStream = ({
useStateAndRef<boolean>(true);
const { startNewPrompt } = useSessionStats();
const logger = useLogger(config?.storage);
const activePtyId = undefined;
const backgroundShellCount = 0;
@@ -320,7 +319,7 @@ export const useAgentStream = ({
try {
const { streamId } = await agent.send({
message: parts,
message: { content: parts },
});
currentStreamIdRef.current = streamId;
} catch (err) {