fix(cli): record tool calls in non-interactive mode (#10951)

This commit is contained in:
bl-ue
2025-10-14 09:51:00 -06:00
committed by GitHub
parent 3ba4ba79fa
commit 9e8c767694
8 changed files with 316 additions and 98 deletions
+25 -2
View File
@@ -4,7 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import type { Config, ToolCallRequestInfo } from '@google/gemini-cli-core';
import type {
Config,
ToolCallRequestInfo,
CompletedToolCall,
} from '@google/gemini-cli-core';
import { isSlashCommand } from './ui/utils/commandUtils.js';
import type { LoadedSettings } from './config/settings.js';
import {
@@ -132,12 +136,17 @@ export async function runNonInteractive(
if (toolCallRequests.length > 0) {
const toolResponseParts: Part[] = [];
const completedToolCalls: CompletedToolCall[] = [];
for (const requestInfo of toolCallRequests) {
const toolResponse = await executeToolCall(
const completedToolCall = await executeToolCall(
config,
requestInfo,
abortController.signal,
);
const toolResponse = completedToolCall.response;
completedToolCalls.push(completedToolCall);
if (toolResponse.error) {
handleToolError(
@@ -155,6 +164,20 @@ export async function runNonInteractive(
toolResponseParts.push(...toolResponse.responseParts);
}
}
// Record tool calls with full metadata before sending responses to Gemini
try {
const currentModel =
geminiClient.getCurrentSequenceModel() ?? config.getModel();
geminiClient
.getChat()
.recordCompletedToolCalls(currentModel, completedToolCalls);
} catch (error) {
console.error(
`Error recording completed tool call information: ${error}`,
);
}
currentMessages = [{ role: 'user', parts: toolResponseParts }];
} else {
if (config.getOutputFormat() === OutputFormat.JSON) {