This commit is contained in:
george larson 2025-12-23 15:41:59 +08:00 committed by GitHub
commit 02627c45f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,7 +17,25 @@ const MAX_PROJECT_DIAGNOSTICS_FILES = 5
export const WriteTool = Tool.define("write", {
description: DESCRIPTION,
parameters: z.object({
content: z.string().describe("The content to write to the file"),
content: z
.preprocess((val) => {
if (typeof val === "string") {
return val
}
if (Array.isArray(val)) {
// Join array elements with newlines
// Handle edge cases: null/undefined -> "", objects -> JSON.stringify, others -> String
return val
.map((item) => {
if (item === null || item === undefined) return ""
if (typeof item === "object") return JSON.stringify(item)
return String(item)
})
.join("\n")
}
return String(val)
}, z.string())
.describe("The content to write to the file"),
filePath: z.string().describe("The absolute path to the file to write (must be absolute, not relative)"),
}),
async execute(params, ctx) {