diff options
| author | Tommaso Sciortino <[email protected]> | 2025-07-07 23:48:44 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-08 06:48:44 +0000 |
| commit | 4dab31f1c8f0f4025c5d6a81c1b64f711e066756 (patch) | |
| tree | 3db882e191862e4c24e5653167a756145b567759 /packages/core/src/tools/grep.ts | |
| parent | 137ffec3f6fe035b7edcb478e6c44e66fa593839 (diff) | |
Improve Function Call argument validation and typing (#2881)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/core/src/tools/grep.ts')
| -rw-r--r-- | packages/core/src/tools/grep.ts | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/packages/core/src/tools/grep.ts b/packages/core/src/tools/grep.ts index 612291d5..b3c7a17b 100644 --- a/packages/core/src/tools/grep.ts +++ b/packages/core/src/tools/grep.ts @@ -11,6 +11,7 @@ import { EOL } from 'os'; import { spawn } from 'child_process'; import { globStream } from 'glob'; import { BaseTool, ToolResult } from './tools.js'; +import { Type } from '@google/genai'; import { SchemaValidator } from '../utils/schemaValidator.js'; import { makeRelative, shortenPath } from '../utils/paths.js'; import { getErrorMessage, isNodeError } from '../utils/errors.js'; @@ -69,21 +70,21 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> { pattern: { description: "The regular expression (regex) pattern to search for within file contents (e.g., 'function\\s+myFunction', 'import\\s+\\{.*\\}\\s+from\\s+.*').", - type: 'string', + type: Type.STRING, }, path: { description: 'Optional: The absolute path to the directory to search within. If omitted, searches the current working directory.', - type: 'string', + type: Type.STRING, }, include: { description: "Optional: A glob pattern to filter which files are searched (e.g., '*.js', '*.{ts,tsx}', 'src/**'). If omitted, searches all files (respecting potential global ignores).", - type: 'string', + type: Type.STRING, }, }, required: ['pattern'], - type: 'object', + type: Type.OBJECT, }, ); // Ensure rootDirectory is absolute and normalized @@ -135,14 +136,9 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> { * @returns An error message string if invalid, null otherwise */ validateToolParams(params: GrepToolParams): string | null { - if ( - this.schema.parameters && - !SchemaValidator.validate( - this.schema.parameters as Record<string, unknown>, - params, - ) - ) { - return 'Parameters failed schema validation.'; + const errors = SchemaValidator.validate(this.schema.parameters, params); + if (errors) { + return errors; } try { |
