@@ -25,6 +25,8 @@ export enum RunEventType {
25
25
CallConfirm = "callConfirm" ,
26
26
CallContinue = "callContinue" ,
27
27
CallFinish = "callFinish" ,
28
+
29
+ Prompt = "prompt"
28
30
}
29
31
30
32
let serverProcess : child_process . ChildProcess
@@ -177,6 +179,20 @@ export class Client {
177
179
}
178
180
}
179
181
182
+ async promptResponse ( response : PromptResponse ) : Promise < void > {
183
+ if ( ! this . clientReady ) {
184
+ this . clientReady = await this . testGPTScriptURL ( 20 )
185
+ }
186
+ const resp = await fetch ( `${ this . gptscriptURL } /prompt-response/${ response . id } ` , {
187
+ method : "POST" ,
188
+ body : JSON . stringify ( response . responses )
189
+ } )
190
+
191
+ if ( resp . status < 200 || resp . status >= 400 ) {
192
+ throw new Error ( `Failed to respond to prompt ${ response . id } : ${ await resp . text ( ) } ` )
193
+ }
194
+ }
195
+
180
196
private async testGPTScriptURL ( count : number ) : Promise < boolean > {
181
197
try {
182
198
await fetch ( `${ this . gptscriptURL } /healthz` )
@@ -405,6 +421,8 @@ export class Run {
405
421
f = obj . run as Frame
406
422
} else if ( obj . call ) {
407
423
f = obj . call as Frame
424
+ } else if ( obj . prompt ) {
425
+ f = obj . prompt as Frame
408
426
} else {
409
427
return event
410
428
}
@@ -426,8 +444,7 @@ export class Run {
426
444
this . state = RunState . Finished
427
445
this . stdout = f . output || ""
428
446
}
429
- } else {
430
- if ( ! ( f . type as string ) . startsWith ( "call" ) ) continue
447
+ } else if ( ( f . type as string ) . startsWith ( "call" ) ) {
431
448
f = ( f as CallFrame )
432
449
const idx = this . calls ?. findIndex ( ( x ) => x . id === f . id )
433
450
@@ -447,6 +464,7 @@ export class Run {
447
464
448
465
public on ( event : RunEventType . RunStart | RunEventType . RunFinish , listener : ( data : RunFrame ) => void ) : this;
449
466
public on ( event : RunEventType . CallStart | RunEventType . CallProgress | RunEventType . CallContinue | RunEventType . CallChat | RunEventType . CallConfirm | RunEventType . CallFinish , listener : ( data : CallFrame ) => void ) : this;
467
+ public on ( event : RunEventType . Prompt , listener : ( data : PromptFrame ) => void ) : this;
450
468
public on ( event : RunEventType . Event , listener : ( data : Frame ) => void ) : this;
451
469
public on ( event : RunEventType , listener : ( data : any ) => void ) : this {
452
470
if ( ! this . callbacks [ event ] ) {
@@ -656,14 +674,28 @@ export interface CallFrame {
656
674
llmResponse ?: any
657
675
}
658
676
659
- export type Frame = RunFrame | CallFrame
677
+ export interface PromptFrame {
678
+ id : string
679
+ type : RunEventType . Prompt
680
+ time : string
681
+ message : string
682
+ fields : string [ ]
683
+ sensitive : boolean
684
+ }
685
+
686
+ export type Frame = RunFrame | CallFrame | PromptFrame
660
687
661
688
export interface AuthResponse {
662
689
id : string
663
690
accept : boolean
664
691
message ?: string
665
692
}
666
693
694
+ export interface PromptResponse {
695
+ id : string
696
+ responses : Record < string , string >
697
+ }
698
+
667
699
function getCmdPath ( ) : string {
668
700
if ( process . env . GPTSCRIPT_BIN ) {
669
701
return process . env . GPTSCRIPT_BIN
0 commit comments