mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-10 19:37:17 -07:00
fix(core): Refactor tool invocation constructors to take config and geminiClient directly
This commit is contained in:
@@ -46,6 +46,7 @@ import { getShellDefinition } from './definitions/coreTools.js';
|
||||
import { resolveToolDeclaration } from './definitions/resolver.js';
|
||||
import type { AgentLoopContext } from '../config/agent-loop-context.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { GeminiClient } from '../core/client.js';
|
||||
|
||||
export const OUTPUT_UPDATE_INTERVAL_MS = 1000;
|
||||
|
||||
@@ -63,23 +64,15 @@ export class ShellToolInvocation extends BaseToolInvocation<
|
||||
ShellToolParams,
|
||||
ToolResult
|
||||
> {
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
private readonly config: Config,
|
||||
params: ShellToolParams,
|
||||
messageBus: MessageBus,
|
||||
_toolName?: string,
|
||||
_toolDisplayName?: string,
|
||||
private readonly geminiClient?: GeminiClient,
|
||||
) {
|
||||
super(params, messageBus, _toolName, _toolDisplayName);
|
||||
if ('config' in context) {
|
||||
this.config = context.config;
|
||||
this.geminiClient = context.geminiClient;
|
||||
} else {
|
||||
this.config = context;
|
||||
}
|
||||
}
|
||||
|
||||
getDescription(): string {
|
||||
@@ -473,10 +466,7 @@ export class ShellTool extends BaseDeclarativeTool<
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
messageBus: MessageBus,
|
||||
) {
|
||||
constructor(context: Config | AgentLoopContext, messageBus: MessageBus) {
|
||||
void initializeShellParsers().catch(() => {
|
||||
// Errors are surfaced when parsing commands.
|
||||
});
|
||||
@@ -489,7 +479,7 @@ export class ShellTool extends BaseDeclarativeTool<
|
||||
ShellTool.Name,
|
||||
'Shell',
|
||||
definition.base.description!,
|
||||
Kind.Shell,
|
||||
Kind.Execute,
|
||||
definition.base.parametersJsonSchema,
|
||||
messageBus,
|
||||
false, // isOutputMarkdown
|
||||
@@ -501,7 +491,6 @@ export class ShellTool extends BaseDeclarativeTool<
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override validateToolParamValues(
|
||||
params: ShellToolParams,
|
||||
): string | null {
|
||||
@@ -526,11 +515,12 @@ export class ShellTool extends BaseDeclarativeTool<
|
||||
_toolDisplayName?: string,
|
||||
): ToolInvocation<ShellToolParams, ToolResult> {
|
||||
return new ShellToolInvocation(
|
||||
{ config: this.config, geminiClient: this.geminiClient } as any,
|
||||
this.config,
|
||||
params,
|
||||
messageBus,
|
||||
_toolName,
|
||||
_toolDisplayName,
|
||||
this.geminiClient,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -226,23 +226,15 @@ class WebFetchToolInvocation extends BaseToolInvocation<
|
||||
WebFetchToolParams,
|
||||
ToolResult
|
||||
> {
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
private readonly config: Config,
|
||||
params: WebFetchToolParams,
|
||||
messageBus: MessageBus,
|
||||
_toolName?: string,
|
||||
_toolDisplayName?: string,
|
||||
private readonly geminiClient?: GeminiClient,
|
||||
) {
|
||||
super(params, messageBus, _toolName, _toolDisplayName);
|
||||
if ('config' in context) {
|
||||
this.config = context.config;
|
||||
this.geminiClient = context.geminiClient;
|
||||
} else {
|
||||
this.config = context;
|
||||
}
|
||||
}
|
||||
|
||||
private handleRetry(attempt: number, error: unknown, delayMs: number): void {
|
||||
@@ -318,7 +310,7 @@ class WebFetchToolInvocation extends BaseToolInvocation<
|
||||
this.handleRetry(attempt, error, delayMs),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
);
|
||||
const bodyBuffer = await this.readResponseWithLimit(
|
||||
response,
|
||||
MAX_EXPERIMENTAL_FETCH_SIZE,
|
||||
@@ -897,10 +889,7 @@ export class WebFetchTool extends BaseDeclarativeTool<
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
messageBus: MessageBus,
|
||||
) {
|
||||
constructor(context: Config | AgentLoopContext, messageBus: MessageBus) {
|
||||
const config = 'config' in context ? context.config : context;
|
||||
super(
|
||||
WebFetchTool.Name,
|
||||
@@ -957,11 +946,12 @@ export class WebFetchTool extends BaseDeclarativeTool<
|
||||
_toolDisplayName?: string,
|
||||
): ToolInvocation<WebFetchToolParams, ToolResult> {
|
||||
return new WebFetchToolInvocation(
|
||||
{ config: this.config, geminiClient: this.geminiClient } as any,
|
||||
this.config,
|
||||
params,
|
||||
messageBus,
|
||||
_toolName,
|
||||
_toolDisplayName,
|
||||
this.geminiClient,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,23 +72,15 @@ class WebSearchToolInvocation extends BaseToolInvocation<
|
||||
WebSearchToolParams,
|
||||
WebSearchToolResult
|
||||
> {
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
private readonly config: Config,
|
||||
params: WebSearchToolParams,
|
||||
messageBus: MessageBus,
|
||||
_toolName?: string,
|
||||
_toolDisplayName?: string,
|
||||
private readonly geminiClient?: GeminiClient,
|
||||
) {
|
||||
super(params, messageBus, _toolName, _toolDisplayName);
|
||||
if ('config' in context) {
|
||||
this.config = context.config;
|
||||
this.geminiClient = context.geminiClient;
|
||||
} else {
|
||||
this.config = context;
|
||||
}
|
||||
}
|
||||
|
||||
override getDescription(): string {
|
||||
@@ -219,10 +211,7 @@ export class WebSearchTool extends BaseDeclarativeTool<
|
||||
private readonly config: Config;
|
||||
private readonly geminiClient?: GeminiClient;
|
||||
|
||||
constructor(
|
||||
context: Config | AgentLoopContext,
|
||||
messageBus: MessageBus,
|
||||
) {
|
||||
constructor(context: Config | AgentLoopContext, messageBus: MessageBus) {
|
||||
const config = 'config' in context ? context.config : context;
|
||||
super(
|
||||
WebSearchTool.Name,
|
||||
@@ -261,11 +250,12 @@ export class WebSearchTool extends BaseDeclarativeTool<
|
||||
_toolDisplayName?: string,
|
||||
): ToolInvocation<WebSearchToolParams, WebSearchToolResult> {
|
||||
return new WebSearchToolInvocation(
|
||||
{ config: this.config, geminiClient: this.geminiClient } as any,
|
||||
this.config,
|
||||
params,
|
||||
messageBus ?? this.messageBus,
|
||||
_toolName,
|
||||
_toolDisplayName,
|
||||
this.geminiClient,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user