mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 21:14:35 -07:00
refactor(cli): decouple UI from live tool execution via ToolActionsContext (#17183)
This commit is contained in:
@@ -195,6 +195,33 @@ describe('toolMapping', () => {
|
||||
expect(displayTool.confirmationDetails).toEqual(confirmationDetails);
|
||||
});
|
||||
|
||||
it('maps correlationId and serializable confirmation details', () => {
|
||||
const serializableDetails = {
|
||||
type: 'edit' as const,
|
||||
title: 'Confirm Edit',
|
||||
fileName: 'file.txt',
|
||||
filePath: '/path/file.txt',
|
||||
fileDiff: 'diff',
|
||||
originalContent: 'old',
|
||||
newContent: 'new',
|
||||
};
|
||||
|
||||
const toolCall: WaitingToolCall = {
|
||||
status: 'awaiting_approval',
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
confirmationDetails: serializableDetails,
|
||||
correlationId: 'corr-123',
|
||||
};
|
||||
|
||||
const result = mapToDisplay(toolCall);
|
||||
const displayTool = result.tools[0];
|
||||
|
||||
expect(displayTool.correlationId).toBe('corr-123');
|
||||
expect(displayTool.confirmationDetails).toEqual(serializableDetails);
|
||||
});
|
||||
|
||||
it('maps error tool call missing tool definition', () => {
|
||||
// e.g. "TOOL_NOT_REGISTERED" errors
|
||||
const toolCall: ToolCall = {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type ToolCall,
|
||||
type Status as CoreStatus,
|
||||
type ToolCallConfirmationDetails,
|
||||
type SerializableConfirmationDetails,
|
||||
type ToolResultDisplay,
|
||||
debugLogger,
|
||||
} from '@google/gemini-cli-core';
|
||||
@@ -72,10 +73,13 @@ export function mapToDisplay(
|
||||
};
|
||||
|
||||
let resultDisplay: ToolResultDisplay | undefined = undefined;
|
||||
let confirmationDetails: ToolCallConfirmationDetails | undefined =
|
||||
undefined;
|
||||
let confirmationDetails:
|
||||
| ToolCallConfirmationDetails
|
||||
| SerializableConfirmationDetails
|
||||
| undefined = undefined;
|
||||
let outputFile: string | undefined = undefined;
|
||||
let ptyId: number | undefined = undefined;
|
||||
let correlationId: string | undefined = undefined;
|
||||
|
||||
switch (call.status) {
|
||||
case 'success':
|
||||
@@ -87,16 +91,9 @@ export function mapToDisplay(
|
||||
resultDisplay = call.response.resultDisplay;
|
||||
break;
|
||||
case 'awaiting_approval':
|
||||
// Only map if it's the legacy callback-based details.
|
||||
// Serializable details will be handled in a later milestone.
|
||||
if (
|
||||
call.confirmationDetails &&
|
||||
'onConfirm' in call.confirmationDetails &&
|
||||
typeof call.confirmationDetails.onConfirm === 'function'
|
||||
) {
|
||||
confirmationDetails =
|
||||
call.confirmationDetails as ToolCallConfirmationDetails;
|
||||
}
|
||||
correlationId = call.correlationId;
|
||||
// Pass through details. Context handles dispatch (callback vs bus).
|
||||
confirmationDetails = call.confirmationDetails;
|
||||
break;
|
||||
case 'executing':
|
||||
resultDisplay = call.liveOutput;
|
||||
@@ -123,6 +120,7 @@ export function mapToDisplay(
|
||||
confirmationDetails,
|
||||
outputFile,
|
||||
ptyId,
|
||||
correlationId,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user