diff options
Diffstat (limited to 'packages/core/src/tools/read-file.ts')
| -rw-r--r-- | packages/core/src/tools/read-file.ts | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts index 1060ac8d..a26f50ce 100644 --- a/packages/core/src/tools/read-file.ts +++ b/packages/core/src/tools/read-file.ts @@ -8,6 +8,7 @@ import path from 'path'; import { SchemaValidator } from '../utils/schemaValidator.js'; import { makeRelative, shortenPath } from '../utils/paths.js'; import { BaseTool, ToolResult } from './tools.js'; +import { Type } from '@google/genai'; import { isWithinRoot, processSingleFileContent, @@ -58,37 +59,33 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> { absolute_path: { description: "The absolute path to the file to read (e.g., '/home/user/project/file.txt'). Relative paths are not supported. You must provide an absolute path.", - type: 'string', + type: Type.STRING, pattern: '^/', }, offset: { description: "Optional: For text files, the 0-based line number to start reading from. Requires 'limit' to be set. Use for paginating through large files.", - type: 'number', + type: Type.NUMBER, }, limit: { description: "Optional: For text files, maximum number of lines to read. Use with 'offset' to paginate through large files. If omitted, reads the entire file (if feasible, up to a default limit).", - type: 'number', + type: Type.NUMBER, }, }, required: ['absolute_path'], - type: 'object', + type: Type.OBJECT, }, ); this.rootDirectory = path.resolve(rootDirectory); } validateToolParams(params: ReadFileToolParams): 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; } + const filePath = params.absolute_path; if (!path.isAbsolute(filePath)) { return `File path must be absolute, but was relative: ${filePath}. You must provide an absolute path.`; |
