Improve Function Call argument validation and typing (#2881)

Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
Tommaso Sciortino
2025-07-07 23:48:44 -07:00
committed by GitHub
parent 137ffec3f6
commit 4dab31f1c8
22 changed files with 239 additions and 246 deletions

View File

@@ -7,6 +7,7 @@
import fs from 'fs';
import path from 'path';
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 { Config } from '../config/config.js';
@@ -84,23 +85,23 @@ export class LSTool extends BaseTool<LSToolParams, ToolResult> {
path: {
description:
'The absolute path to the directory to list (must be absolute, not relative)',
type: 'string',
type: Type.STRING,
},
ignore: {
description: 'List of glob patterns to ignore',
items: {
type: 'string',
type: Type.STRING,
},
type: 'array',
type: Type.ARRAY,
},
respect_git_ignore: {
description:
'Optional: Whether to respect .gitignore patterns when listing files. Only available in git repositories. Defaults to true.',
type: 'boolean',
type: Type.BOOLEAN,
},
},
required: ['path'],
type: 'object',
type: Type.OBJECT,
},
);
@@ -132,14 +133,9 @@ export class LSTool extends BaseTool<LSToolParams, ToolResult> {
* @returns An error message string if invalid, null otherwise
*/
validateToolParams(params: LSToolParams): 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;
}
if (!path.isAbsolute(params.path)) {
return `Path must be absolute: ${params.path}`;