mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
Improve Function Call argument validation and typing (#2881)
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
committed by
GitHub
parent
137ffec3f6
commit
4dab31f1c8
@@ -15,6 +15,7 @@ import {
|
||||
ToolResult,
|
||||
ToolResultDisplay,
|
||||
} from './tools.js';
|
||||
import { Type } from '@google/genai';
|
||||
import { SchemaValidator } from '../utils/schemaValidator.js';
|
||||
import { makeRelative, shortenPath } from '../utils/paths.js';
|
||||
import { isNodeError } from '../utils/errors.js';
|
||||
@@ -97,27 +98,27 @@ Expectation for required parameters:
|
||||
file_path: {
|
||||
description:
|
||||
"The absolute path to the file to modify. Must start with '/'.",
|
||||
type: 'string',
|
||||
type: Type.STRING,
|
||||
},
|
||||
old_string: {
|
||||
description:
|
||||
'The exact literal text to replace, preferably unescaped. For single replacements (default), include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. For multiple replacements, specify expected_replacements parameter. If this string is not the exact literal text (i.e. you escaped it) or does not match exactly, the tool will fail.',
|
||||
type: 'string',
|
||||
type: Type.STRING,
|
||||
},
|
||||
new_string: {
|
||||
description:
|
||||
'The exact literal text to replace `old_string` with, preferably unescaped. Provide the EXACT text. Ensure the resulting code is correct and idiomatic.',
|
||||
type: 'string',
|
||||
type: Type.STRING,
|
||||
},
|
||||
expected_replacements: {
|
||||
type: 'number',
|
||||
type: Type.NUMBER,
|
||||
description:
|
||||
'Number of replacements expected. Defaults to 1 if not specified. Use when you want to replace multiple occurrences.',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
required: ['file_path', 'old_string', 'new_string'],
|
||||
type: 'object',
|
||||
type: Type.OBJECT,
|
||||
},
|
||||
);
|
||||
this.rootDirectory = path.resolve(this.config.getTargetDir());
|
||||
@@ -146,14 +147,9 @@ Expectation for required parameters:
|
||||
* @returns Error message string or null if valid
|
||||
*/
|
||||
validateToolParams(params: EditToolParams): 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.file_path)) {
|
||||
|
||||
Reference in New Issue
Block a user