Get ToolRegistry from config instead of passing it (#6592)
This commit is contained in:
parent
f1575f6d8d
commit
a01d411c5a
|
@ -137,7 +137,6 @@ describe('runNonInteractive', () => {
|
|||
expect(mockCoreExecuteToolCall).toHaveBeenCalledWith(
|
||||
mockConfig,
|
||||
expect.objectContaining({ name: 'testTool' }),
|
||||
mockToolRegistry,
|
||||
expect.any(AbortSignal),
|
||||
);
|
||||
expect(mockGeminiClient.sendMessageStream).toHaveBeenNthCalledWith(
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
Config,
|
||||
ToolCallRequestInfo,
|
||||
executeToolCall,
|
||||
ToolRegistry,
|
||||
shutdownTelemetry,
|
||||
isTelemetrySdkInitialized,
|
||||
GeminiEventType,
|
||||
|
@ -39,7 +38,6 @@ export async function runNonInteractive(
|
|||
});
|
||||
|
||||
const geminiClient = config.getGeminiClient();
|
||||
const toolRegistry: ToolRegistry = config.getToolRegistry();
|
||||
|
||||
const abortController = new AbortController();
|
||||
let currentMessages: Content[] = [
|
||||
|
@ -100,7 +98,6 @@ export async function runNonInteractive(
|
|||
const toolResponse = await executeToolCall(
|
||||
config,
|
||||
requestInfo,
|
||||
toolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
|
||||
|
|
|
@ -16,20 +16,11 @@ import {
|
|||
import { Part } from '@google/genai';
|
||||
import { MockTool } from '../test-utils/tools.js';
|
||||
|
||||
const mockConfig = {
|
||||
getSessionId: () => 'test-session-id',
|
||||
getUsageStatisticsEnabled: () => true,
|
||||
getDebugMode: () => false,
|
||||
getContentGeneratorConfig: () => ({
|
||||
model: 'test-model',
|
||||
authType: 'oauth-personal',
|
||||
}),
|
||||
} as unknown as Config;
|
||||
|
||||
describe('executeToolCall', () => {
|
||||
let mockToolRegistry: ToolRegistry;
|
||||
let mockTool: MockTool;
|
||||
let abortController: AbortController;
|
||||
let mockConfig: Config;
|
||||
|
||||
beforeEach(() => {
|
||||
mockTool = new MockTool();
|
||||
|
@ -39,6 +30,17 @@ describe('executeToolCall', () => {
|
|||
// Add other ToolRegistry methods if needed, or use a more complete mock
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
mockConfig = {
|
||||
getSessionId: () => 'test-session-id',
|
||||
getUsageStatisticsEnabled: () => true,
|
||||
getDebugMode: () => false,
|
||||
getContentGeneratorConfig: () => ({
|
||||
model: 'test-model',
|
||||
authType: 'oauth-personal',
|
||||
}),
|
||||
getToolRegistry: () => mockToolRegistry,
|
||||
} as unknown as Config;
|
||||
|
||||
abortController = new AbortController();
|
||||
});
|
||||
|
||||
|
@ -60,7 +62,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
|
||||
|
@ -94,7 +95,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
|
||||
|
@ -141,7 +141,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
expect(response).toStrictEqual({
|
||||
|
@ -185,7 +184,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
expect(response).toStrictEqual({
|
||||
|
@ -222,7 +220,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
|
||||
|
@ -262,7 +259,6 @@ describe('executeToolCall', () => {
|
|||
const response = await executeToolCall(
|
||||
mockConfig,
|
||||
request,
|
||||
mockToolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
ToolCallRequestInfo,
|
||||
ToolCallResponseInfo,
|
||||
ToolErrorType,
|
||||
ToolRegistry,
|
||||
ToolResult,
|
||||
} from '../index.js';
|
||||
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
|
||||
|
@ -25,10 +24,9 @@ import { ToolCallDecision } from '../telemetry/tool-call-decision.js';
|
|||
export async function executeToolCall(
|
||||
config: Config,
|
||||
toolCallRequest: ToolCallRequestInfo,
|
||||
toolRegistry: ToolRegistry,
|
||||
abortSignal?: AbortSignal,
|
||||
): Promise<ToolCallResponseInfo> {
|
||||
const tool = toolRegistry.getTool(toolCallRequest.name);
|
||||
const tool = config.getToolRegistry().getTool(toolCallRequest.name);
|
||||
|
||||
const startTime = Date.now();
|
||||
if (!tool) {
|
||||
|
|
|
@ -534,7 +534,7 @@ describe('subagent.ts', () => {
|
|||
parameters: { type: Type.OBJECT, properties: {} },
|
||||
};
|
||||
|
||||
const { config, toolRegistry } = await createMockConfig({
|
||||
const { config } = await createMockConfig({
|
||||
getFunctionDeclarationsFiltered: vi
|
||||
.fn()
|
||||
.mockReturnValue([listFilesToolDef]),
|
||||
|
@ -580,7 +580,6 @@ describe('subagent.ts', () => {
|
|||
expect(executeToolCall).toHaveBeenCalledWith(
|
||||
config,
|
||||
expect.objectContaining({ name: 'list_files', args: { path: '.' } }),
|
||||
toolRegistry,
|
||||
expect.any(AbortSignal),
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
import { reportError } from '../utils/errorReporting.js';
|
||||
import { ToolRegistry } from '../tools/tool-registry.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { ToolCallRequestInfo } from './turn.js';
|
||||
import { executeToolCall } from './nonInteractiveToolExecutor.js';
|
||||
|
@ -422,7 +421,6 @@ export class SubAgentScope {
|
|||
if (functionCalls.length > 0) {
|
||||
currentMessages = await this.processFunctionCalls(
|
||||
functionCalls,
|
||||
toolRegistry,
|
||||
abortController,
|
||||
promptId,
|
||||
);
|
||||
|
@ -479,7 +477,6 @@ export class SubAgentScope {
|
|||
*/
|
||||
private async processFunctionCalls(
|
||||
functionCalls: FunctionCall[],
|
||||
toolRegistry: ToolRegistry,
|
||||
abortController: AbortController,
|
||||
promptId: string,
|
||||
): Promise<Content[]> {
|
||||
|
@ -513,7 +510,6 @@ export class SubAgentScope {
|
|||
toolResponse = await executeToolCall(
|
||||
this.runtimeContext,
|
||||
requestInfo,
|
||||
toolRegistry,
|
||||
abortController.signal,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue