Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/cli/src/ui/hooks/useGeminiStream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('useGeminiStream', () => {
let mockScheduleToolCalls: Mock;
let mockCancelAllToolCalls: Mock;
let mockMarkToolsAsSubmitted: Mock;
let mockBackgroundShellRegistry: { setNotificationCallback: Mock };
let handleAtCommandSpy: MockInstance;

beforeEach(() => {
Expand Down Expand Up @@ -182,6 +183,9 @@ describe('useGeminiStream', () => {
vertexai: false,
authType: AuthType.USE_GEMINI,
};
mockBackgroundShellRegistry = {
setNotificationCallback: vi.fn(),
};

mockConfig = {
apiKey: 'test-api-key',
Expand Down Expand Up @@ -230,6 +234,7 @@ describe('useGeminiStream', () => {
getBackgroundTaskRegistry: vi.fn(() => ({
setNotificationCallback: vi.fn(),
})),
getBackgroundShellRegistry: vi.fn(() => mockBackgroundShellRegistry),
getMonitorRegistry: vi.fn(() => ({
setNotificationCallback: vi.fn(),
})),
Expand Down Expand Up @@ -356,6 +361,44 @@ describe('useGeminiStream', () => {
};
};

it('queues background shell terminal notifications for the model loop', async () => {
const { mockSendMessageStream } = renderTestHook();
const displayText = 'Background shell "npm test" completed.';
const modelText =
'<task-notification>\n<kind>shell</kind>\n<status>completed</status>\n</task-notification>';

await waitFor(() => {
expect(
mockBackgroundShellRegistry.setNotificationCallback,
).toHaveBeenCalledWith(expect.any(Function));
});

const callback = mockBackgroundShellRegistry.setNotificationCallback.mock
.calls[0][0] as (displayText: string, modelText: string) => void;

act(() => {
callback(displayText, modelText);
});

await waitFor(() => {
expect(mockAddItem).toHaveBeenCalledWith(
{ type: 'notification', text: displayText },
expect.any(Number),
);
});
await waitFor(() => {
expect(mockSendMessageStream).toHaveBeenCalledWith(
modelText,
expect.any(AbortSignal),
expect.any(String),
expect.objectContaining({
type: SendMessageType.Notification,
notificationDisplayText: displayText,
}),
);
});
});

it('should not submit tool responses if not all tool calls are completed', () => {
const toolCalls: TrackedToolCall[] = [
{
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/ui/hooks/useGeminiStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,22 @@ export const useGeminiStream = (
};
}, [config]);

// Register background shell terminal notification callback onto the shared queue.
useEffect(() => {
const registry = config.getBackgroundShellRegistry();
registry.setNotificationCallback((displayText, modelText) => {
notificationQueueRef.current.push({
displayText,
modelText,
sendMessageType: SendMessageType.Notification,
});
setNotificationTrigger((n) => n + 1);
});
return () => {
registry.setNotificationCallback(undefined);
};
}, [config]);

// Register monitor notification callback onto the shared queue.
useEffect(() => {
const registry = config.getMonitorRegistry();
Expand Down
Loading
Loading