refactor: migrate src/tool/write.ts from Bun.file() to Filesystem module (#14119)
This commit is contained in:
@@ -26,9 +26,8 @@ export const WriteTool = Tool.define("write", {
|
|||||||
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
|
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
|
||||||
await assertExternalDirectory(ctx, filepath)
|
await assertExternalDirectory(ctx, filepath)
|
||||||
|
|
||||||
const file = Bun.file(filepath)
|
const exists = await Filesystem.exists(filepath)
|
||||||
const exists = await file.exists()
|
const contentOld = exists ? await Filesystem.readText(filepath) : ""
|
||||||
const contentOld = exists ? await file.text() : ""
|
|
||||||
if (exists) await FileTime.assert(ctx.sessionID, filepath)
|
if (exists) await FileTime.assert(ctx.sessionID, filepath)
|
||||||
|
|
||||||
const diff = trimDiff(createTwoFilesPatch(filepath, filepath, contentOld, params.content))
|
const diff = trimDiff(createTwoFilesPatch(filepath, filepath, contentOld, params.content))
|
||||||
@@ -42,7 +41,7 @@ export const WriteTool = Tool.define("write", {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await Bun.write(filepath, params.content)
|
await Filesystem.write(filepath, params.content)
|
||||||
await Bus.publish(File.Event.Edited, {
|
await Bus.publish(File.Event.Edited, {
|
||||||
file: filepath,
|
file: filepath,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user