summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/write-file.ts
diff options
context:
space:
mode:
authorTommaso Sciortino <[email protected]>2025-07-07 23:48:44 -0700
committerGitHub <[email protected]>2025-07-08 06:48:44 +0000
commit4dab31f1c8f0f4025c5d6a81c1b64f711e066756 (patch)
tree3db882e191862e4c24e5653167a756145b567759 /packages/core/src/tools/write-file.ts
parent137ffec3f6fe035b7edcb478e6c44e66fa593839 (diff)
Improve Function Call argument validation and typing (#2881)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/core/src/tools/write-file.ts')
-rw-r--r--packages/core/src/tools/write-file.ts19
1 files changed, 8 insertions, 11 deletions
diff --git a/packages/core/src/tools/write-file.ts b/packages/core/src/tools/write-file.ts
index ab30891b..e936ce0b 100644
--- a/packages/core/src/tools/write-file.ts
+++ b/packages/core/src/tools/write-file.ts
@@ -16,6 +16,7 @@ import {
ToolConfirmationOutcome,
ToolCallConfirmationDetails,
} 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';
@@ -79,15 +80,15 @@ export class WriteFileTool
file_path: {
description:
"The absolute path to the file to write to (e.g., '/home/user/project/file.txt'). Relative paths are not supported.",
- type: 'string',
+ type: Type.STRING,
},
content: {
description: 'The content to write to the file.',
- type: 'string',
+ type: Type.STRING,
},
},
required: ['file_path', 'content'],
- type: 'object',
+ type: Type.OBJECT,
},
);
}
@@ -112,15 +113,11 @@ export class WriteFileTool
}
validateToolParams(params: WriteFileToolParams): 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.file_path;
if (!path.isAbsolute(filePath)) {
return `File path must be absolute: ${filePath}`;