mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-14 23:31:13 -07:00
refactor: use CoreToolCallStatus in the the history data model (#19033)
This commit is contained in:
@@ -17,10 +17,10 @@ import {
|
||||
COMMON_IGNORE_PATTERNS,
|
||||
GEMINI_IGNORE_FILE_NAME,
|
||||
// DEFAULT_FILE_EXCLUDES,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import * as core from '@google/gemini-cli-core';
|
||||
import * as os from 'node:os';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
import * as fsPromises from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
@@ -212,7 +212,9 @@ describe('handleAtCommand', () => {
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'tool_group',
|
||||
tools: [expect.objectContaining({ status: ToolCallStatus.Success })],
|
||||
tools: [
|
||||
expect.objectContaining({ status: CoreToolCallStatus.Success }),
|
||||
],
|
||||
}),
|
||||
125,
|
||||
);
|
||||
@@ -314,7 +316,9 @@ describe('handleAtCommand', () => {
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'tool_group',
|
||||
tools: [expect.objectContaining({ status: ToolCallStatus.Success })],
|
||||
tools: [
|
||||
expect.objectContaining({ status: CoreToolCallStatus.Success }),
|
||||
],
|
||||
}),
|
||||
125,
|
||||
);
|
||||
@@ -1431,7 +1435,7 @@ describe('handleAtCommand', () => {
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'tool_group',
|
||||
tools: [expect.objectContaining({ status: ToolCallStatus.Error })],
|
||||
tools: [expect.objectContaining({ status: CoreToolCallStatus.Error })],
|
||||
}),
|
||||
134,
|
||||
);
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
ReadManyFilesTool,
|
||||
REFERENCE_CONTENT_START,
|
||||
REFERENCE_CONTENT_END,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import type { HistoryItem, IndividualToolCallDisplay } from '../types.js';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
|
||||
const REF_CONTENT_HEADER = `\n${REFERENCE_CONTENT_START}`;
|
||||
@@ -409,7 +409,7 @@ async function readMcpResources(
|
||||
callId: `mcp-resource-${resource.serverName}-${resource.uri}`,
|
||||
name: `resources/read (${resource.serverName})`,
|
||||
description: resource.uri,
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
resultDisplay: `Successfully read resource ${resource.uri}`,
|
||||
confirmationDetails: undefined,
|
||||
} as IndividualToolCallDisplay,
|
||||
@@ -423,7 +423,7 @@ async function readMcpResources(
|
||||
callId: `mcp-resource-${resource.serverName}-${resource.uri}`,
|
||||
name: `resources/read (${resource.serverName})`,
|
||||
description: resource.uri,
|
||||
status: ToolCallStatus.Error,
|
||||
status: CoreToolCallStatus.Error,
|
||||
resultDisplay: `Error reading resource ${resource.uri}: ${getErrorMessage(error)}`,
|
||||
confirmationDetails: undefined,
|
||||
} as IndividualToolCallDisplay,
|
||||
@@ -447,7 +447,9 @@ async function readMcpResources(
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
const firstError = displays.find((d) => d.status === ToolCallStatus.Error);
|
||||
const firstError = displays.find(
|
||||
(d) => d.status === CoreToolCallStatus.Error,
|
||||
);
|
||||
return {
|
||||
parts: [],
|
||||
displays,
|
||||
@@ -500,7 +502,7 @@ async function readLocalFiles(
|
||||
callId: `client-read-${userMessageTimestamp}`,
|
||||
name: readManyFilesTool.displayName,
|
||||
description: invocation.getDescription(),
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
resultDisplay:
|
||||
result.returnDisplay ||
|
||||
`Successfully read: ${fileLabelsForDisplay.join(', ')}`,
|
||||
@@ -559,7 +561,7 @@ async function readLocalFiles(
|
||||
description:
|
||||
invocation?.getDescription() ??
|
||||
'Error attempting to execute tool to read files',
|
||||
status: ToolCallStatus.Error,
|
||||
status: CoreToolCallStatus.Error,
|
||||
resultDisplay: `Error reading files (${fileLabelsForDisplay.join(', ')}): ${getErrorMessage(error)}`,
|
||||
confirmationDetails: undefined,
|
||||
};
|
||||
|
||||
@@ -75,12 +75,12 @@ import {
|
||||
type GeminiClient,
|
||||
type ShellExecutionResult,
|
||||
type ShellOutputEvent,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import * as crypto from 'node:crypto';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
|
||||
describe('useShellCommandProcessor', () => {
|
||||
let addItemToHistoryMock: Mock;
|
||||
@@ -201,7 +201,7 @@ describe('useShellCommandProcessor', () => {
|
||||
tools: [
|
||||
expect.objectContaining({
|
||||
name: 'Shell Command',
|
||||
status: ToolCallStatus.Executing,
|
||||
status: CoreToolCallStatus.Executing,
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -240,7 +240,7 @@ describe('useShellCommandProcessor', () => {
|
||||
expect.objectContaining({
|
||||
tools: [
|
||||
expect.objectContaining({
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
resultDisplay: 'ok',
|
||||
}),
|
||||
],
|
||||
@@ -269,7 +269,7 @@ describe('useShellCommandProcessor', () => {
|
||||
await act(async () => await execPromise);
|
||||
|
||||
const finalHistoryItem = addItemToHistoryMock.mock.calls[1][0];
|
||||
expect(finalHistoryItem.tools[0].status).toBe(ToolCallStatus.Error);
|
||||
expect(finalHistoryItem.tools[0].status).toBe(CoreToolCallStatus.Error);
|
||||
expect(finalHistoryItem.tools[0].resultDisplay).toContain(
|
||||
'Command exited with code 127',
|
||||
);
|
||||
@@ -483,7 +483,7 @@ describe('useShellCommandProcessor', () => {
|
||||
await act(async () => await execPromise);
|
||||
|
||||
const finalHistoryItem = addItemToHistoryMock.mock.calls[1][0];
|
||||
expect(finalHistoryItem.tools[0].status).toBe(ToolCallStatus.Success);
|
||||
expect(finalHistoryItem.tools[0].status).toBe(CoreToolCallStatus.Success);
|
||||
expect(finalHistoryItem.tools[0].resultDisplay).toBe(
|
||||
'[Command produced binary output, which is not shown.]',
|
||||
);
|
||||
|
||||
@@ -8,10 +8,13 @@ import type {
|
||||
HistoryItemWithoutId,
|
||||
IndividualToolCallDisplay,
|
||||
} from '../types.js';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
import { useCallback, useReducer, useRef, useEffect } from 'react';
|
||||
import type { AnsiOutput, Config, GeminiClient } from '@google/gemini-cli-core';
|
||||
import { isBinary, ShellExecutionService } from '@google/gemini-cli-core';
|
||||
import {
|
||||
isBinary,
|
||||
ShellExecutionService,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { type PartListUnion } from '@google/genai';
|
||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
import { SHELL_COMMAND_NAME } from '../constants.js';
|
||||
@@ -301,7 +304,7 @@ export const useShellCommandProcessor = (
|
||||
callId,
|
||||
name: SHELL_COMMAND_NAME,
|
||||
description: rawQuery,
|
||||
status: ToolCallStatus.Executing,
|
||||
status: CoreToolCallStatus.Executing,
|
||||
resultDisplay: '',
|
||||
confirmationDetails: undefined,
|
||||
};
|
||||
@@ -447,22 +450,22 @@ export const useShellCommandProcessor = (
|
||||
}
|
||||
|
||||
let finalOutput = mainContent;
|
||||
let finalStatus = ToolCallStatus.Success;
|
||||
let finalStatus = CoreToolCallStatus.Success;
|
||||
|
||||
if (result.error) {
|
||||
finalStatus = ToolCallStatus.Error;
|
||||
finalStatus = CoreToolCallStatus.Error;
|
||||
finalOutput = `${result.error.message}\n${finalOutput}`;
|
||||
} else if (result.aborted) {
|
||||
finalStatus = ToolCallStatus.Canceled;
|
||||
finalStatus = CoreToolCallStatus.Cancelled;
|
||||
finalOutput = `Command was cancelled.\n${finalOutput}`;
|
||||
} else if (result.backgrounded) {
|
||||
finalStatus = ToolCallStatus.Success;
|
||||
finalStatus = CoreToolCallStatus.Success;
|
||||
finalOutput = `Command moved to background (PID: ${result.pid}). Output hidden. Press Ctrl+B to view.`;
|
||||
} else if (result.signal) {
|
||||
finalStatus = ToolCallStatus.Error;
|
||||
finalStatus = CoreToolCallStatus.Error;
|
||||
finalOutput = `Command terminated by signal: ${result.signal}.\n${finalOutput}`;
|
||||
} else if (result.exitCode !== 0) {
|
||||
finalStatus = ToolCallStatus.Error;
|
||||
finalStatus = CoreToolCallStatus.Error;
|
||||
finalOutput = `Command exited with code ${result.exitCode}.\n${finalOutput}`;
|
||||
}
|
||||
|
||||
@@ -480,7 +483,7 @@ export const useShellCommandProcessor = (
|
||||
resultDisplay: finalOutput,
|
||||
};
|
||||
|
||||
if (finalStatus !== ToolCallStatus.Canceled) {
|
||||
if (finalStatus !== CoreToolCallStatus.Cancelled) {
|
||||
addItemToHistory(
|
||||
{
|
||||
type: 'tool_group',
|
||||
|
||||
@@ -1003,7 +1003,7 @@ describe('useSlashCommandProcessor', () => {
|
||||
command: '/fail',
|
||||
expectedLog: {
|
||||
command: 'fail',
|
||||
status: 'error',
|
||||
status: SlashCommandStatus.ERROR,
|
||||
subcommand: undefined,
|
||||
},
|
||||
desc: 'failure event for failed command',
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
addMCPStatusChangeListener,
|
||||
removeMCPStatusChangeListener,
|
||||
MCPDiscoveryState,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { useSessionStats } from '../contexts/SessionContext.js';
|
||||
import type {
|
||||
@@ -44,7 +45,7 @@ import type {
|
||||
ConfirmationRequest,
|
||||
IndividualToolCallDisplay,
|
||||
} from '../types.js';
|
||||
import { MessageType, ToolCallStatus } from '../types.js';
|
||||
import { MessageType } from '../types.js';
|
||||
import type { LoadedSettings } from '../../config/settings.js';
|
||||
import { type CommandContext, type SlashCommand } from '../commands/types.js';
|
||||
import { CommandService } from '../../services/CommandService.js';
|
||||
@@ -554,7 +555,7 @@ export const useSlashCommandProcessor = (
|
||||
callId,
|
||||
name: 'Expansion',
|
||||
description: 'Command expansion needs shell access',
|
||||
status: ToolCallStatus.Confirming,
|
||||
status: CoreToolCallStatus.AwaitingApproval,
|
||||
resultDisplay: undefined,
|
||||
confirmationDetails,
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { mapCoreStatusToDisplayStatus, mapToDisplay } from './toolMapping.js';
|
||||
import { mapToDisplay } from './toolMapping.js';
|
||||
import {
|
||||
type AnyDeclarativeTool,
|
||||
type AnyToolInvocation,
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
type CancelledToolCall,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
import { ToolCallStatus, mapCoreStatusToDisplayStatus } from '../types.js';
|
||||
|
||||
describe('toolMapping', () => {
|
||||
beforeEach(() => {
|
||||
@@ -131,7 +131,7 @@ describe('toolMapping', () => {
|
||||
name: 'Test Tool',
|
||||
description: 'Calling test_tool with args...',
|
||||
renderOutputAsMarkdown: true,
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
resultDisplay: 'Success output',
|
||||
outputFile: '/tmp/output.txt',
|
||||
}),
|
||||
@@ -151,7 +151,7 @@ describe('toolMapping', () => {
|
||||
const result = mapToDisplay(toolCall);
|
||||
const displayTool = result.tools[0];
|
||||
|
||||
expect(displayTool.status).toBe(ToolCallStatus.Executing);
|
||||
expect(displayTool.status).toBe(CoreToolCallStatus.Executing);
|
||||
expect(displayTool.resultDisplay).toBe('Loading...');
|
||||
expect(displayTool.ptyId).toBe(12345);
|
||||
});
|
||||
@@ -178,7 +178,7 @@ describe('toolMapping', () => {
|
||||
const result = mapToDisplay(toolCall);
|
||||
const displayTool = result.tools[0];
|
||||
|
||||
expect(displayTool.status).toBe(ToolCallStatus.Confirming);
|
||||
expect(displayTool.status).toBe(CoreToolCallStatus.AwaitingApproval);
|
||||
expect(displayTool.confirmationDetails).toEqual(confirmationDetails);
|
||||
});
|
||||
|
||||
@@ -221,7 +221,7 @@ describe('toolMapping', () => {
|
||||
const result = mapToDisplay(toolCall);
|
||||
const displayTool = result.tools[0];
|
||||
|
||||
expect(displayTool.status).toBe(ToolCallStatus.Error);
|
||||
expect(displayTool.status).toBe(CoreToolCallStatus.Error);
|
||||
expect(displayTool.name).toBe('test_tool'); // falls back to request.name
|
||||
expect(displayTool.description).toBe('{"arg1":"val1"}'); // falls back to stringified args
|
||||
expect(displayTool.resultDisplay).toBe('Tool not found');
|
||||
@@ -243,7 +243,7 @@ describe('toolMapping', () => {
|
||||
const result = mapToDisplay(toolCall);
|
||||
const displayTool = result.tools[0];
|
||||
|
||||
expect(displayTool.status).toBe(ToolCallStatus.Canceled);
|
||||
expect(displayTool.status).toBe(CoreToolCallStatus.Cancelled);
|
||||
expect(displayTool.resultDisplay).toBe('User cancelled');
|
||||
});
|
||||
|
||||
@@ -273,7 +273,7 @@ describe('toolMapping', () => {
|
||||
|
||||
const result = mapToDisplay(toolCall);
|
||||
expect(result.tools[0].resultDisplay).toBeUndefined();
|
||||
expect(result.tools[0].status).toBe(ToolCallStatus.Pending);
|
||||
expect(result.tools[0].status).toBe(CoreToolCallStatus.Scheduled);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,42 +6,16 @@
|
||||
|
||||
import {
|
||||
type ToolCall,
|
||||
type Status as CoreStatus,
|
||||
type SerializableConfirmationDetails,
|
||||
type ToolResultDisplay,
|
||||
debugLogger,
|
||||
CoreToolCallStatus,
|
||||
checkExhaustive,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
ToolCallStatus,
|
||||
type HistoryItemToolGroup,
|
||||
type IndividualToolCallDisplay,
|
||||
} from '../types.js';
|
||||
|
||||
export function mapCoreStatusToDisplayStatus(
|
||||
coreStatus: CoreStatus,
|
||||
): ToolCallStatus {
|
||||
switch (coreStatus) {
|
||||
case CoreToolCallStatus.Validating:
|
||||
return ToolCallStatus.Pending;
|
||||
case CoreToolCallStatus.AwaitingApproval:
|
||||
return ToolCallStatus.Confirming;
|
||||
case CoreToolCallStatus.Executing:
|
||||
return ToolCallStatus.Executing;
|
||||
case CoreToolCallStatus.Success:
|
||||
return ToolCallStatus.Success;
|
||||
case CoreToolCallStatus.Cancelled:
|
||||
return ToolCallStatus.Canceled;
|
||||
case CoreToolCallStatus.Error:
|
||||
return ToolCallStatus.Error;
|
||||
case CoreToolCallStatus.Scheduled:
|
||||
return ToolCallStatus.Pending;
|
||||
default:
|
||||
return checkExhaustive(coreStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms `ToolCall` objects into `HistoryItemToolGroup` objects for UI
|
||||
* display. This is a pure projection layer and does not track interaction
|
||||
@@ -115,7 +89,7 @@ export function mapToDisplay(
|
||||
|
||||
return {
|
||||
...baseDisplayProperties,
|
||||
status: mapCoreStatusToDisplayStatus(call.status),
|
||||
status: call.status,
|
||||
resultDisplay,
|
||||
confirmationDetails,
|
||||
outputFile,
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useUIState } from '../contexts/UIStateContext.js';
|
||||
import {
|
||||
ToolCallStatus,
|
||||
type IndividualToolCallDisplay,
|
||||
type HistoryItemToolGroup,
|
||||
} from '../types.js';
|
||||
import { CoreToolCallStatus } from '@google/gemini-cli-core';
|
||||
|
||||
export interface ConfirmingToolState {
|
||||
tool: IndividualToolCallDisplay;
|
||||
@@ -37,7 +37,7 @@ export function useConfirmingTool(): ConfirmingToolState | null {
|
||||
|
||||
// 2. Filter for those requiring confirmation
|
||||
const confirmingTools = allPendingTools.filter(
|
||||
(t) => t.status === ToolCallStatus.Confirming,
|
||||
(t) => t.status === CoreToolCallStatus.AwaitingApproval,
|
||||
);
|
||||
|
||||
if (confirmingTools.length === 0) {
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
import type { Part, PartListUnion } from '@google/genai';
|
||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
import type { SlashCommandProcessorResult } from '../types.js';
|
||||
import { MessageType, StreamingState, ToolCallStatus } from '../types.js';
|
||||
import { MessageType, StreamingState } from '../types.js';
|
||||
import type { LoadedSettings } from '../../config/settings.js';
|
||||
|
||||
// --- MOCKS ---
|
||||
@@ -2380,7 +2380,7 @@ describe('useGeminiStream', () => {
|
||||
callId: 'client-read-123',
|
||||
name: 'read_file',
|
||||
description: toolExecutionMessage,
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
resultDisplay: toolExecutionMessage,
|
||||
confirmationDetails: undefined,
|
||||
},
|
||||
@@ -2434,7 +2434,7 @@ describe('useGeminiStream', () => {
|
||||
tools: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: 'read_file',
|
||||
status: ToolCallStatus.Success,
|
||||
status: CoreToolCallStatus.Success,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
ValidationRequiredError,
|
||||
coreEvents,
|
||||
CoreEvent,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type {
|
||||
Config,
|
||||
@@ -58,7 +59,7 @@ import type {
|
||||
SlashCommandProcessorResult,
|
||||
HistoryItemModel,
|
||||
} from '../types.js';
|
||||
import { StreamingState, MessageType, ToolCallStatus } from '../types.js';
|
||||
import { StreamingState, MessageType } from '../types.js';
|
||||
import { isAtCommand, isSlashCommand } from '../utils/commandUtils.js';
|
||||
import { useShellCommandProcessor } from './shellCommandProcessor.js';
|
||||
import { handleAtCommand } from './atCommandProcessor.js';
|
||||
@@ -126,16 +127,18 @@ function calculateStreamingState(
|
||||
isResponding: boolean,
|
||||
toolCalls: TrackedToolCall[],
|
||||
): StreamingState {
|
||||
if (toolCalls.some((tc) => tc.status === 'awaiting_approval')) {
|
||||
if (
|
||||
toolCalls.some((tc) => tc.status === CoreToolCallStatus.AwaitingApproval)
|
||||
) {
|
||||
return StreamingState.WaitingForConfirmation;
|
||||
}
|
||||
|
||||
const isAnyToolActive = toolCalls.some((tc) => {
|
||||
// These statuses indicate active processing
|
||||
if (
|
||||
tc.status === 'executing' ||
|
||||
tc.status === 'scheduled' ||
|
||||
tc.status === 'validating'
|
||||
tc.status === CoreToolCallStatus.Executing ||
|
||||
tc.status === CoreToolCallStatus.Scheduled ||
|
||||
tc.status === CoreToolCallStatus.Validating
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -143,9 +146,9 @@ function calculateStreamingState(
|
||||
// Terminal statuses (success, error, cancelled) still count as "Responding"
|
||||
// if the result hasn't been submitted back to Gemini yet.
|
||||
if (
|
||||
tc.status === 'success' ||
|
||||
tc.status === 'error' ||
|
||||
tc.status === 'cancelled'
|
||||
tc.status === CoreToolCallStatus.Success ||
|
||||
tc.status === CoreToolCallStatus.Error ||
|
||||
tc.status === CoreToolCallStatus.Cancelled
|
||||
) {
|
||||
return !(tc as TrackedCompletedToolCall | TrackedCancelledToolCall)
|
||||
.responseSubmittedToGemini;
|
||||
@@ -562,7 +565,7 @@ export const useGeminiStream = (
|
||||
if (tool.name === SHELL_COMMAND_NAME) {
|
||||
return {
|
||||
...tool,
|
||||
status: ToolCallStatus.Canceled,
|
||||
status: CoreToolCallStatus.Cancelled,
|
||||
resultDisplay: tool.resultDisplay,
|
||||
};
|
||||
}
|
||||
@@ -830,12 +833,14 @@ export const useGeminiStream = (
|
||||
if (pendingHistoryItemRef.current.type === 'tool_group') {
|
||||
const updatedTools = pendingHistoryItemRef.current.tools.map(
|
||||
(tool) =>
|
||||
tool.status === ToolCallStatus.Pending ||
|
||||
tool.status === ToolCallStatus.Confirming ||
|
||||
tool.status === ToolCallStatus.Executing
|
||||
? { ...tool, status: ToolCallStatus.Canceled }
|
||||
tool.status === CoreToolCallStatus.Validating ||
|
||||
tool.status === CoreToolCallStatus.Scheduled ||
|
||||
tool.status === CoreToolCallStatus.AwaitingApproval ||
|
||||
tool.status === CoreToolCallStatus.Executing
|
||||
? { ...tool, status: CoreToolCallStatus.Cancelled }
|
||||
: tool,
|
||||
);
|
||||
|
||||
const pendingItem: HistoryItemToolGroup = {
|
||||
...pendingHistoryItemRef.current,
|
||||
tools: updatedTools,
|
||||
@@ -1530,7 +1535,7 @@ export const useGeminiStream = (
|
||||
|
||||
// If all the tools were cancelled, don't submit a response to Gemini.
|
||||
const allToolsCancelled = geminiTools.every(
|
||||
(tc) => tc.status === 'cancelled',
|
||||
(tc) => tc.status === CoreToolCallStatus.Cancelled,
|
||||
);
|
||||
|
||||
if (allToolsCancelled) {
|
||||
@@ -1618,7 +1623,7 @@ export const useGeminiStream = (
|
||||
const restorableToolCalls = toolCalls.filter(
|
||||
(toolCall) =>
|
||||
EDIT_TOOL_NAMES.has(toolCall.request.name) &&
|
||||
toolCall.status === 'awaiting_approval',
|
||||
toolCall.status === CoreToolCallStatus.AwaitingApproval,
|
||||
);
|
||||
|
||||
if (restorableToolCalls.length > 0) {
|
||||
|
||||
@@ -14,10 +14,11 @@ import {
|
||||
import * as fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { getSessionFiles, type SessionInfo } from '../../utils/sessionUtils.js';
|
||||
import type {
|
||||
Config,
|
||||
ConversationRecord,
|
||||
MessageRecord,
|
||||
import {
|
||||
type Config,
|
||||
type ConversationRecord,
|
||||
type MessageRecord,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { coreEvents } from '@google/gemini-cli-core';
|
||||
|
||||
@@ -238,7 +239,7 @@ describe('convertSessionToHistoryFormats', () => {
|
||||
id: 'call_1',
|
||||
name: 'get_time',
|
||||
args: {},
|
||||
status: 'success',
|
||||
status: CoreToolCallStatus.Success,
|
||||
result: '12:00',
|
||||
},
|
||||
],
|
||||
@@ -258,7 +259,7 @@ describe('convertSessionToHistoryFormats', () => {
|
||||
expect.objectContaining({
|
||||
callId: 'call_1',
|
||||
name: 'get_time',
|
||||
status: 'Success',
|
||||
status: CoreToolCallStatus.Success,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { renderHook } from '../../test-utils/render.js';
|
||||
import { useToolScheduler } from './useToolScheduler.js';
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
type AnyDeclarativeTool,
|
||||
type AnyToolInvocation,
|
||||
ROOT_SCHEDULER_ID,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { createMockMessageBus } from '@google/gemini-cli-core/src/test-utils/mock-message-bus.js';
|
||||
|
||||
@@ -98,7 +99,7 @@ describe('useToolScheduler', () => {
|
||||
);
|
||||
|
||||
const mockToolCall = {
|
||||
status: 'executing' as const,
|
||||
status: CoreToolCallStatus.Executing as const,
|
||||
request: {
|
||||
callId: 'call-1',
|
||||
name: 'test_tool',
|
||||
@@ -124,7 +125,7 @@ describe('useToolScheduler', () => {
|
||||
// Expect Core Object structure, not Display Object
|
||||
expect(toolCalls[0]).toMatchObject({
|
||||
request: { callId: 'call-1', name: 'test_tool' },
|
||||
status: 'executing', // Core status
|
||||
status: CoreToolCallStatus.Executing,
|
||||
liveOutput: 'Loading...',
|
||||
responseSubmittedToGemini: false,
|
||||
});
|
||||
@@ -140,7 +141,7 @@ describe('useToolScheduler', () => {
|
||||
);
|
||||
|
||||
const mockToolCall = {
|
||||
status: 'success' as const,
|
||||
status: CoreToolCallStatus.Success as const,
|
||||
request: {
|
||||
callId: 'call-1',
|
||||
name: 'test',
|
||||
@@ -206,7 +207,7 @@ describe('useToolScheduler', () => {
|
||||
type: MessageBusType.TOOL_CALLS_UPDATE,
|
||||
toolCalls: [
|
||||
{
|
||||
status: 'executing' as const,
|
||||
status: CoreToolCallStatus.Executing as const,
|
||||
request: {
|
||||
callId: 'call-1',
|
||||
name: 'test',
|
||||
@@ -252,7 +253,7 @@ describe('useToolScheduler', () => {
|
||||
const onComplete = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
const completedToolCall = {
|
||||
status: 'success' as const,
|
||||
status: CoreToolCallStatus.Success as const,
|
||||
request: {
|
||||
callId: 'call-1',
|
||||
name: 'test',
|
||||
@@ -316,7 +317,7 @@ describe('useToolScheduler', () => {
|
||||
);
|
||||
|
||||
const callRoot = {
|
||||
status: 'success' as const,
|
||||
status: CoreToolCallStatus.Success as const,
|
||||
request: {
|
||||
callId: 'call-root',
|
||||
name: 'test',
|
||||
@@ -390,7 +391,7 @@ describe('useToolScheduler', () => {
|
||||
act(() => {
|
||||
void mockMessageBus.publish({
|
||||
type: MessageBusType.TOOL_CALLS_UPDATE,
|
||||
toolCalls: [{ ...callRoot, status: 'executing' }],
|
||||
toolCalls: [{ ...callRoot, status: CoreToolCallStatus.Executing }],
|
||||
schedulerId: ROOT_SCHEDULER_ID,
|
||||
} as ToolCallsUpdateMessage);
|
||||
});
|
||||
@@ -399,7 +400,7 @@ describe('useToolScheduler', () => {
|
||||
expect(toolCalls).toHaveLength(2);
|
||||
expect(
|
||||
toolCalls.find((t) => t.request.callId === 'call-root')?.status,
|
||||
).toBe('executing');
|
||||
).toBe(CoreToolCallStatus.Executing);
|
||||
expect(
|
||||
toolCalls.find((t) => t.request.callId === 'call-sub')?.schedulerId,
|
||||
).toBe('subagent-1');
|
||||
|
||||
@@ -8,7 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { renderHook } from '../../test-utils/render.js';
|
||||
import { useTurnActivityMonitor } from './useTurnActivityMonitor.js';
|
||||
import { StreamingState } from '../types.js';
|
||||
import { hasRedirection } from '@google/gemini-cli-core';
|
||||
import { hasRedirection, CoreToolCallStatus } from '@google/gemini-cli-core';
|
||||
import { type TrackedToolCall } from './useToolScheduler.js';
|
||||
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
@@ -93,7 +93,7 @@ describe('useTurnActivityMonitor', () => {
|
||||
name: 'run_shell_command',
|
||||
args: { command: 'ls -la' },
|
||||
},
|
||||
status: 'executing',
|
||||
status: CoreToolCallStatus.Executing,
|
||||
} as unknown as TrackedToolCall,
|
||||
],
|
||||
});
|
||||
@@ -108,7 +108,7 @@ describe('useTurnActivityMonitor', () => {
|
||||
name: 'run_shell_command',
|
||||
args: { command: 'ls > tool_out.txt' },
|
||||
},
|
||||
status: 'executing',
|
||||
status: CoreToolCallStatus.Executing,
|
||||
} as unknown as TrackedToolCall,
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user