mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Merge e782208840 into 83397ebde2
This commit is contained in:
commit
02627c45f7
1 changed files with 19 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue