@@ -80,7 +80,7 @@ export class Client {
8080 * @return {Run } The Run object representing the running tool.
8181 */
8282 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 )
8484 }
8585
8686 /**
@@ -101,7 +101,7 @@ export class Client {
101101 toolString = toolDefToString ( tool )
102102 }
103103
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 )
105105 }
106106
107107 async parse ( fileName : string ) : Promise < Block [ ] > {
@@ -117,7 +117,7 @@ export class Client {
117117 async parseTool ( toolContent : string ) : Promise < Block [ ] > {
118118 const r : Run = new RunSubcommand ( "parse" , "" , toolContent , { } , this . gptscriptBin , this . gptscriptURL )
119119 if ( this . gptscriptURL ) {
120- r . request ( { input : toolContent } )
120+ r . request ( { content : toolContent } )
121121 } else {
122122 await r . exec ( [ "parse" ] )
123123 }
@@ -196,29 +196,25 @@ export class Run {
196196
197197 let run = this
198198 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 )
200200 }
201201
202202 run . chatState = this . chatState
203203 run . opts . input = input
204204 if ( run . gptscriptURL ) {
205205 if ( run . content !== "" ) {
206- run . request ( { content : this . content } )
206+ run . request ( { content : this . content , chatState : JSON . stringify ( run . chatState ) } )
207207 } else {
208- run . request ( { file : this . filePath } )
208+ run . request ( { file : this . filePath , chatState : JSON . stringify ( run . chatState ) } )
209209 }
210210 } else {
211- run . exec ( ) . catch ( ( e ) => {
212- run . err = e . toString ( )
213- run . state = RunState . Error
214- }
215- )
211+ run . exec ( )
216212 }
217213
218214 return run
219215 }
220216
221- async exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
217+ exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
222218 extraArgs . push ( ...toArgs ( this . opts ) )
223219 extraArgs . push ( "--chat-state=" + ( this . chatState ? JSON . stringify ( this . chatState ) : "null" ) )
224220 this . chatState = undefined
@@ -406,9 +402,16 @@ export class Run {
406402 } )
407403
408404 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+ }
412415 } else if ( this . state === RunState . Error ) {
413416 reject ( this . err )
414417 }
@@ -458,9 +461,16 @@ export class Run {
458461 } )
459462
460463 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+ }
464474 } else if ( this . state === RunState . Error ) {
465475 reject ( this . err )
466476 }
0 commit comments