mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-21 23:40:44 -07:00
Enable tools to cancel active execution.
- Plumbed abort signals through to tools - Updated the shell tool to properly cancel active requests by killing the entire child process tree of the underlying shell process and then report that the shell itself was canceled. Fixes https://b.corp.google.com/issues/416829935
This commit is contained in:
committed by
N. Taylor Mullen
parent
90d85820b8
commit
2b1e39db6a
@@ -64,10 +64,13 @@ export class GeminiClient {
|
||||
.getTool('read_many_files') as ReadManyFilesTool;
|
||||
if (readManyFilesTool) {
|
||||
// Read all files in the target directory
|
||||
const result = await readManyFilesTool.execute({
|
||||
paths: ['**/*'], // Read everything recursively
|
||||
useDefaultExcludes: true, // Use default excludes
|
||||
});
|
||||
const result = await readManyFilesTool.execute(
|
||||
{
|
||||
paths: ['**/*'], // Read everything recursively
|
||||
useDefaultExcludes: true, // Use default excludes
|
||||
},
|
||||
AbortSignal.timeout(30000),
|
||||
);
|
||||
if (result.llmContent) {
|
||||
initialParts.push({
|
||||
text: `\n--- Full File Context ---\n${result.llmContent}`,
|
||||
|
||||
@@ -36,7 +36,10 @@ export interface ServerTool {
|
||||
name: string;
|
||||
schema: FunctionDeclaration;
|
||||
// The execute method signature might differ slightly or be wrapped
|
||||
execute(params: Record<string, unknown>): Promise<ToolResult>;
|
||||
execute(
|
||||
params: Record<string, unknown>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<ToolResult>;
|
||||
shouldConfirmExecute(
|
||||
params: Record<string, unknown>,
|
||||
): Promise<ToolCallConfirmationDetails | false>;
|
||||
@@ -153,7 +156,7 @@ export class Turn {
|
||||
if (confirmationDetails) {
|
||||
return { ...pendingToolCall, confirmationDetails };
|
||||
}
|
||||
const result = await tool.execute(pendingToolCall.args);
|
||||
const result = await tool.execute(pendingToolCall.args, signal);
|
||||
return {
|
||||
...pendingToolCall,
|
||||
result,
|
||||
@@ -199,7 +202,11 @@ export class Turn {
|
||||
resultDisplay: outcome.result?.returnDisplay,
|
||||
error: outcome.error,
|
||||
};
|
||||
yield { type: GeminiEventType.ToolCallResponse, value: responseInfo };
|
||||
|
||||
// If aborted we're already yielding the user cancellations elsewhere.
|
||||
if (!signal?.aborted) {
|
||||
yield { type: GeminiEventType.ToolCallResponse, value: responseInfo };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user