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/web-search.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/web-search.ts')
| -rw-r--r-- | packages/core/src/tools/web-search.ts | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/packages/core/src/tools/web-search.ts b/packages/core/src/tools/web-search.ts index 5ee8e85c..98be1f30 100644 --- a/packages/core/src/tools/web-search.ts +++ b/packages/core/src/tools/web-search.ts @@ -6,6 +6,7 @@ import { GroundingMetadata } from '@google/genai'; import { BaseTool, ToolResult } from './tools.js'; +import { Type } from '@google/genai'; import { SchemaValidator } from '../utils/schemaValidator.js'; import { getErrorMessage } from '../utils/errors.js'; @@ -69,10 +70,10 @@ export class WebSearchTool extends BaseTool< 'GoogleSearch', 'Performs a web search using Google Search (via the Gemini API) and returns the results. This tool is useful for finding information on the internet based on a query.', { - type: 'object', + type: Type.OBJECT, properties: { query: { - type: 'string', + type: Type.STRING, description: 'The search query to find information on the web.', }, }, @@ -86,16 +87,12 @@ export class WebSearchTool extends BaseTool< * @param params The parameters to validate * @returns An error message string if validation fails, null if valid */ - validateToolParams(params: WebSearchToolParams): string | null { - if ( - this.schema.parameters && - !SchemaValidator.validate( - this.schema.parameters as Record<string, unknown>, - params, - ) - ) { - return "Parameters failed schema validation. Ensure 'query' is a string."; + validateParams(params: WebSearchToolParams): string | null { + const errors = SchemaValidator.validate(this.schema.parameters, params); + if (errors) { + return errors; } + if (!params.query || params.query.trim() === '') { return "The 'query' parameter cannot be empty."; } |
