@@ -13,6 +13,7 @@ export interface RunOpts {
13
13
chatState ?: string
14
14
confirm ?: boolean
15
15
prompt ?: boolean
16
+ env ?: string [ ]
16
17
}
17
18
18
19
export enum RunEventType {
@@ -238,25 +239,25 @@ export class Run {
238
239
}
239
240
240
241
nextChat ( input : string = "" ) : Run {
241
- if ( this . state === RunState . Finished || this . state = == RunState . Error ) {
242
- throw ( new Error ( " Run already finished" ) )
242
+ if ( this . state !== RunState . Continue && this . state !== RunState . Creating && this . state ! == RunState . Error ) {
243
+ throw ( new Error ( ` Run must in creating, continue or error state, not ${ this . state } ` ) )
243
244
}
244
245
245
246
let run = this
246
247
if ( run . state !== RunState . Creating ) {
247
248
run = new ( this . constructor as any ) ( this . requestPath , this . filePath , this . content , this . opts , this . gptscriptURL )
248
249
}
249
250
250
- if ( this . chatState ) {
251
- run . chatState = this . chatState
252
- } else if ( this . opts . chatState ) {
253
- run . chatState = this . opts . chatState
251
+ if ( this . chatState && this . state === RunState . Continue ) {
252
+ // Only update the chat state if the previous run didn't error.
253
+ // The chat state on opts will be the chat state for the last successful run.
254
+ this . opts . chatState = this . chatState
254
255
}
255
256
run . opts . input = input
256
257
if ( run . content !== "" ) {
257
- run . request ( { content : this . content , chatState : run . chatState } )
258
+ run . request ( { content : this . content , ... this . opts } )
258
259
} else {
259
- run . request ( { file : this . filePath , chatState : run . chatState } )
260
+ run . request ( { file : this . filePath , ... this . opts } )
260
261
}
261
262
262
263
return run
0 commit comments