Sync upstream Gemini-CLI v0.8.2 (#838)

This commit is contained in:
tanzhenxin
2025-10-23 09:27:04 +08:00
committed by GitHub
parent 096fabb5d6
commit eb95c131be
644 changed files with 70389 additions and 23709 deletions

View File

@@ -19,6 +19,7 @@ import {
} from './tools.js';
import type { CallableTool, FunctionCall, Part } from '@google/genai';
import { ToolErrorType } from './tool-error.js';
import type { Config } from '../config/config.js';
type ToolParams = Record<string, unknown>;
@@ -67,9 +68,9 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
readonly serverName: string,
readonly serverToolName: string,
readonly displayName: string,
readonly timeout?: number,
readonly trust?: boolean,
params: ToolParams = {},
private readonly cliConfig?: Config,
) {
super(params);
}
@@ -80,7 +81,7 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
const serverAllowListKey = this.serverName;
const toolAllowListKey = `${this.serverName}.${this.serverToolName}`;
if (this.trust) {
if (this.cliConfig?.isTrustedFolder() && this.trust) {
return false; // server is trusted, no confirmation needed
}
@@ -130,7 +131,7 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
return false;
}
async execute(): Promise<ToolResult> {
async execute(signal: AbortSignal): Promise<ToolResult> {
const functionCalls: FunctionCall[] = [
{
name: this.serverToolName,
@@ -138,7 +139,36 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
},
];
const rawResponseParts = await this.mcpTool.callTool(functionCalls);
// Race MCP tool call with abort signal to respect cancellation
const rawResponseParts = await new Promise<Part[]>((resolve, reject) => {
if (signal.aborted) {
const error = new Error('Tool call aborted');
error.name = 'AbortError';
reject(error);
return;
}
const onAbort = () => {
cleanup();
const error = new Error('Tool call aborted');
error.name = 'AbortError';
reject(error);
};
const cleanup = () => {
signal.removeEventListener('abort', onAbort);
};
signal.addEventListener('abort', onAbort, { once: true });
this.mcpTool
.callTool(functionCalls)
.then((res) => {
cleanup();
resolve(res);
})
.catch((err) => {
cleanup();
reject(err);
});
});
// Ensure the response is not an error
if (this.isMCPToolError(rawResponseParts)) {
@@ -180,9 +210,9 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
readonly serverToolName: string,
description: string,
override readonly parameterSchema: unknown,
readonly timeout?: number,
readonly trust?: boolean,
nameOverride?: string,
private readonly cliConfig?: Config,
) {
super(
nameOverride ?? generateValidName(serverToolName),
@@ -202,9 +232,9 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
this.serverToolName,
this.description,
this.parameterSchema,
this.timeout,
this.trust,
`${this.serverName}__${this.serverToolName}`,
this.cliConfig,
);
}
@@ -216,9 +246,9 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
this.serverName,
this.serverToolName,
this.displayName,
this.timeout,
this.trust,
params,
this.cliConfig,
);
}
}