File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -49,16 +49,23 @@ export const writeFileTool: Tool = {
4949 readonly : false ,
5050 isBuiltIn : true ,
5151 preprocess : async ( args ) => {
52+ const filepath = args ?. filepath ;
53+ const content = args ?. content ?? "" ;
54+ if ( typeof filepath !== "string" ) {
55+ throw new Error ( "Filepath must be a string" ) ;
56+ }
57+ if ( typeof content !== "string" ) {
58+ throw new Error ( "New file content must be a string" ) ;
59+ }
5260 try {
53- if ( fs . existsSync ( args . filepath ) ) {
54- const oldContent = fs . readFileSync ( args . filepath , "utf-8" ) ;
55- const newContent = args . content ;
61+ if ( fs . existsSync ( filepath ) ) {
62+ const oldContent = fs . readFileSync ( filepath , "utf-8" ) ;
5663
5764 const diff = createTwoFilesPatch (
5865 args . filepath ,
5966 args . filepath ,
6067 oldContent ,
61- newContent ,
68+ content ,
6269 undefined ,
6370 undefined ,
6471 { context : 2 } ,
@@ -81,7 +88,7 @@ export const writeFileTool: Tool = {
8188 } catch {
8289 // do nothing
8390 }
84- const lines : string [ ] = args . content . split ( "\n" ) ;
91+ const lines : string [ ] = content . split ( "\n" ) ;
8592 const previewLines = lines . slice ( 0 , 3 ) ;
8693
8794 const preview : ToolCallPreview [ ] = [
@@ -103,7 +110,10 @@ export const writeFileTool: Tool = {
103110 }
104111
105112 return {
106- args,
113+ args : {
114+ filepath,
115+ content,
116+ } ,
107117 preview,
108118 } ;
109119 } ,
You can’t perform that action at this time.
0 commit comments