@@ -9,6 +9,7 @@ export interface RunOpts {
9
9
chdir ?: string
10
10
subTool ?: string
11
11
workspace ?: string
12
+ chatState ?: string
12
13
}
13
14
14
15
function toArgs ( opts : RunOpts ) : string [ ] {
@@ -174,7 +175,7 @@ export class Run {
174
175
private req ?: any
175
176
private stderr ?: string
176
177
private callbacks : Record < string , ( ( f : Frame ) => void ) [ ] > = { }
177
- private chatState : string | undefined
178
+ private chatState ? : string
178
179
179
180
constructor ( subCommand : string , path : string , content : string , opts : RunOpts , bin ?: string , gptscriptURL ?: string ) {
180
181
this . id = randomId ( "run-" )
@@ -199,13 +200,17 @@ export class Run {
199
200
run = new ( this . constructor as any ) ( this . requestPath , this . filePath , this . content , this . opts , this . bin , this . gptscriptURL )
200
201
}
201
202
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
+ }
203
208
run . opts . input = input
204
209
if ( run . gptscriptURL ) {
205
210
if ( run . content !== "" ) {
206
- run . request ( { content : this . content , chatState : JSON . stringify ( run . chatState ) } )
211
+ run . request ( { content : this . content , chatState : run . chatState } )
207
212
} else {
208
- run . request ( { file : this . filePath , chatState : JSON . stringify ( run . chatState ) } )
213
+ run . request ( { file : this . filePath , chatState : run . chatState } )
209
214
}
210
215
} else {
211
216
run . exec ( )
@@ -216,7 +221,7 @@ export class Run {
216
221
217
222
exec ( extraArgs : string [ ] = [ ] , env : NodeJS . Dict < string > = process . env ) {
218
223
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" ) )
220
225
this . chatState = undefined
221
226
222
227
if ( this . filePath ) {
@@ -353,7 +358,7 @@ export class Run {
353
358
354
359
const out = data as ChatState
355
360
if ( out . done !== undefined && ! out . done ) {
356
- this . chatState = out . state
361
+ this . chatState = JSON . stringify ( out . state )
357
362
this . state = RunState . Continue
358
363
} else {
359
364
this . state = RunState . Finished
@@ -637,6 +642,10 @@ export class Run {
637
642
return JSON . parse ( await this . text ( ) )
638
643
}
639
644
645
+ public currentChatState ( ) : string | undefined {
646
+ return this . chatState
647
+ }
648
+
640
649
public close ( ) : void {
641
650
if ( this . process ) {
642
651
if ( this . process . exitCode === null ) {
0 commit comments