summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/grep.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/tools/grep.ts')
-rw-r--r--packages/core/src/tools/grep.ts20
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 {