@@ -80,7 +80,7 @@ export class Client {
80
80
* @return {Run } The Run object representing the running tool.
81
81
*/
82
82
run ( toolName : string , opts : RunOpts = { } ) : Run {
83
- return ( new Run ( "run-file-stream-with-events " , toolName , "" , opts , this . gptscriptBin , this . gptscriptURL ) ) . nextChat ( opts . input )
83
+ return ( new Run ( "run" , toolName , "" , opts , this . gptscriptBin , this . gptscriptURL ) ) . nextChat ( opts . input )
84
84
}
85
85
86
86
/**
@@ -101,7 +101,7 @@ export class Client {
101
101
toolString = toolDefToString ( tool )
102
102
}
103
103
104
- return ( new Run ( "run-tool-stream-with-event " , "" , toolString , opts , this . gptscriptBin , this . gptscriptURL ) ) . nextChat ( opts . input )
104
+ return ( new Run ( "evaluate " , "" , toolString , opts , this . gptscriptBin , this . gptscriptURL ) ) . nextChat ( opts . input )
105
105
}
106
106
107
107
async parse ( fileName : string ) : Promise < Block [ ] > {
@@ -117,7 +117,7 @@ export class Client {
117
117
async parseTool ( toolContent : string ) : Promise < Block [ ] > {
118
118
const r : Run = new RunSubcommand ( "parse" , "" , toolContent , { } , this . gptscriptBin , this . gptscriptURL )
119
119
if ( this . gptscriptURL ) {
120
- r . request ( { input : toolContent } )
120
+ r . request ( { content : toolContent } )
121
121
} else {
122
122
await r . exec ( [ "parse" ] )
123
123
}
@@ -196,29 +196,25 @@ export class Run {
196
196
197
197
let run = this
198
198
if ( run . state !== RunState . Creating ) {
199
- run = new ( this . constructor as any ) ( run . requestPath , run . filePath , run . content , run . opts , run . gptscriptURL )
199
+ run = new ( this . constructor as any ) ( this . requestPath , this . filePath , this . content , this . opts , this . bin , this . gptscriptURL )
200
200
}
201
201
202
202
run . chatState = this . chatState
203
203
run . opts . input = input
204
204
if ( run . gptscriptURL ) {
205
205
if ( run . content !== "" ) {
206
- run . request ( { content : this . content } )
206
+ run . request ( { content : this . content , chatState : JSON . stringify ( run . chatState ) } )
207
207
} else {
208
- run . request ( { file : this . filePath } )
208
+ run . request ( { file : this . filePath , chatState : JSON . stringify ( run . chatState ) } )
209
209
}
210
210
} else {
211
- run . exec ( ) . catch ( ( e ) => {
212
- run . err = e . toString ( )
213
- run . state = RunState . Error
214
- }
215
- )
211
+ run . exec ( )
216
212
}
217
213
218
214
return run
219
215
}
220
216
221
- async exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
217
+ exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
222
218
extraArgs . push ( ...toArgs ( this . opts ) )
223
219
extraArgs . push ( "--chat-state=" + ( this . chatState ? JSON . stringify ( this . chatState ) : "null" ) )
224
220
this . chatState = undefined
@@ -406,9 +402,16 @@ export class Run {
406
402
} )
407
403
408
404
this . sse . addEventListener ( "close" , ( ) => {
409
- if ( this . state === RunState . Running || this . state === RunState . Finished ) {
410
- this . state = RunState . Finished
411
- resolve ( this . stdout || "" )
405
+ if ( this . state === RunState . Running || this . state === RunState . Finished || this . state === RunState . Continue ) {
406
+ if ( this . stdout ) {
407
+ if ( this . state !== RunState . Continue ) {
408
+ this . state = RunState . Finished
409
+ }
410
+ resolve ( this . stdout )
411
+ } else {
412
+ this . state = RunState . Error
413
+ reject ( this . stderr )
414
+ }
412
415
} else if ( this . state === RunState . Error ) {
413
416
reject ( this . err )
414
417
}
@@ -458,9 +461,16 @@ export class Run {
458
461
} )
459
462
460
463
res . on ( "end" , ( ) => {
461
- if ( this . state === RunState . Running || this . state === RunState . Finished ) {
462
- this . state = RunState . Finished
463
- resolve ( this . stdout || "" )
464
+ if ( this . state === RunState . Running || this . state === RunState . Finished || this . state === RunState . Continue ) {
465
+ if ( this . stdout ) {
466
+ if ( this . state !== RunState . Continue ) {
467
+ this . state = RunState . Finished
468
+ }
469
+ resolve ( this . stdout )
470
+ } else {
471
+ this . state = RunState . Error
472
+ reject ( this . stderr )
473
+ }
464
474
} else if ( this . state === RunState . Error ) {
465
475
reject ( this . err )
466
476
}
0 commit comments