mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 16:41:11 -07:00
refactor: extract tool definitions and prepare architecture for model-dependent descriptions
This commit is contained in:
@@ -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.',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<FunctionDeclaration>;
|
||||
pro?: Partial<FunctionDeclaration>;
|
||||
[modelKey: string]: Partial<FunctionDeclaration> | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user