@@ -9,6 +9,7 @@ export interface RunOpts {
99 chdir ?: string
1010 subTool ?: string
1111 workspace ?: string
12+ chatState ?: string
1213}
1314
1415function toArgs ( opts : RunOpts ) : string [ ] {
@@ -174,7 +175,7 @@ export class Run {
174175 private req ?: any
175176 private stderr ?: string
176177 private callbacks : Record < string , ( ( f : Frame ) => void ) [ ] > = { }
177- private chatState : string | undefined
178+ private chatState ? : string
178179
179180 constructor ( subCommand : string , path : string , content : string , opts : RunOpts , bin ?: string , gptscriptURL ?: string ) {
180181 this . id = randomId ( "run-" )
@@ -199,13 +200,17 @@ export class Run {
199200 run = new ( this . constructor as any ) ( this . requestPath , this . filePath , this . content , this . opts , this . bin , this . gptscriptURL )
200201 }
201202
202- run . chatState = this . chatState
203+ if ( this . chatState ) {
204+ run . chatState = this . chatState
205+ } else if ( this . opts . chatState ) {
206+ run . chatState = this . opts . chatState
207+ }
203208 run . opts . input = input
204209 if ( run . gptscriptURL ) {
205210 if ( run . content !== "" ) {
206- run . request ( { content : this . content , chatState : JSON . stringify ( run . chatState ) } )
211+ run . request ( { content : this . content , chatState : run . chatState } )
207212 } else {
208- run . request ( { file : this . filePath , chatState : JSON . stringify ( run . chatState ) } )
213+ run . request ( { file : this . filePath , chatState : run . chatState } )
209214 }
210215 } else {
211216 run . exec ( )
@@ -216,7 +221,7 @@ export class Run {
216221
217222 exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
218223 extraArgs . push ( ...toArgs ( this . opts ) )
219- extraArgs . push ( "--chat-state=" + ( this . chatState ? JSON . stringify ( this . chatState ) : "null" ) )
224+ extraArgs . push ( "--chat-state=" + ( this . chatState ? this . chatState : "null" ) )
220225 this . chatState = undefined
221226
222227 if ( this . filePath ) {
@@ -353,7 +358,7 @@ export class Run {
353358
354359 const out = data as ChatState
355360 if ( out . done !== undefined && ! out . done ) {
356- this . chatState = out . state
361+ this . chatState = JSON . stringify ( out . state )
357362 this . state = RunState . Continue
358363 } else {
359364 this . state = RunState . Finished
@@ -637,6 +642,10 @@ export class Run {
637642 return JSON . parse ( await this . text ( ) )
638643 }
639644
645+ public currentChatState ( ) : string | undefined {
646+ return this . chatState
647+ }
648+
640649 public close ( ) : void {
641650 if ( this . process ) {
642651 if ( this . process . exitCode === null ) {
0 commit comments