From b2d09c3248582e1b70bddd8c229025745b443529 Mon Sep 17 00:00:00 2001 From: Aishanee Shah Date: Wed, 4 Feb 2026 20:48:46 +0000 Subject: [PATCH] refactor: extract tool definitions and prepare architecture for model-dependent descriptions --- .../core/src/tools/definitions/coreTools.ts | 24 --------- .../core/src/tools/definitions/resolver.ts | 49 +++---------------- packages/core/src/tools/definitions/types.ts | 14 +----- 3 files changed, 8 insertions(+), 79 deletions(-) diff --git a/packages/core/src/tools/definitions/coreTools.ts b/packages/core/src/tools/definitions/coreTools.ts index 828b0c90d8..68445efcb6 100644 --- a/packages/core/src/tools/definitions/coreTools.ts +++ b/packages/core/src/tools/definitions/coreTools.ts @@ -32,22 +32,8 @@ export const READ_FILE_DEFINITION: ToolDefinition = { required: ['file_path'], }, }, - variants: { - flash: { - description: - 'Reads a file from the local filesystem. Fast and efficient for checking file content.', - }, - pro: { - description: - 'Reads and returns the content of a specified file. Use this for comprehensive analysis of source code, configuration, or documentation.', - }, - }, }; -/** - * Note: Shell tool has platform-specific and dynamic parts. - * The base here contains the core schema. - */ export const SHELL_DEFINITION: ToolDefinition = { base: { name: SHELL_TOOL_NAME, @@ -78,14 +64,4 @@ export const SHELL_DEFINITION: ToolDefinition = { required: ['command'], }, }, - variants: { - flash: { - description: - 'Executes a single shell command. Use for simple operations like listing files or moving data.', - }, - pro: { - description: - 'Executes a shell command. Can be used for complex workflows, multi-step installations, or deep system investigations.', - }, - }, }; diff --git a/packages/core/src/tools/definitions/resolver.ts b/packages/core/src/tools/definitions/resolver.ts index 2883b66c58..8176e48104 100644 --- a/packages/core/src/tools/definitions/resolver.ts +++ b/packages/core/src/tools/definitions/resolver.ts @@ -8,52 +8,15 @@ import { type FunctionDeclaration } from '@google/genai'; import type { ToolDefinition } from './types.js'; /** - * Resolves a model-specific declaration for a tool. + * Resolves the declaration for a tool. * - * @param definition The tool definition containing base and variants. - * @param modelId The concrete model ID (e.g., 'gemini-1.5-flash'). - * @returns The final FunctionDeclaration to be sent to the API. + * @param definition The tool definition containing the base declaration. + * @param _modelId Optional model identifier (ignored in this plain refactor). + * @returns The FunctionDeclaration to be sent to the API. */ export function resolveToolDeclaration( definition: ToolDefinition, - modelId: string, + _modelId?: string, ): FunctionDeclaration { - const { base, variants } = definition; - - if (!variants) { - return base; - } - - // Simplified mapping logic: check if the modelId contains 'flash' or 'pro'. - // This can be made more robust as needed. - let variantKey: 'flash' | 'pro' | undefined; - if (modelId.toLowerCase().includes('flash')) { - variantKey = 'flash'; - } else if (modelId.toLowerCase().includes('pro')) { - variantKey = 'pro'; - } - - const variant = variantKey ? variants[variantKey] : undefined; - - if (!variant) { - return base; - } - - // Deep merge strategy for the declaration. - return { - ...base, - ...variant, - parameters: - variant.parameters && base.parameters - ? { - ...base.parameters, - ...variant.parameters, - properties: { - ...(base.parameters.properties || {}), - ...(variant.parameters.properties || {}), - }, - required: variant.parameters.required || base.parameters.required, - } - : (variant.parameters ?? base.parameters), - }; + return definition.base; } diff --git a/packages/core/src/tools/definitions/types.ts b/packages/core/src/tools/definitions/types.ts index 428d224ec9..dc928e0a66 100644 --- a/packages/core/src/tools/definitions/types.ts +++ b/packages/core/src/tools/definitions/types.ts @@ -7,19 +7,9 @@ import { type FunctionDeclaration } from '@google/genai'; /** - * Defines a tool's identity with potential model-specific flavor variants. + * Defines a tool's identity using a structured declaration. */ export interface ToolDefinition { - /** The base declaration used by default. */ + /** The base declaration for the tool. */ base: FunctionDeclaration; - - /** - * Model-specific overrides for the tool declaration. - * Can override description, parameters, or any other field. - */ - variants?: { - flash?: Partial; - pro?: Partial; - [modelKey: string]: Partial | undefined; - }; }