@@ -22,13 +22,26 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
22
22
private prompt : PromptBuilder < I , O , T > ;
23
23
private started = false ;
24
24
private promptId ?: string ;
25
- private output : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > = { } as any ;
25
+ private output : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > = { } as any ;
26
26
27
27
private onPreviewFn ?: ( ev : Blob , promptId ?: string ) => void ;
28
28
private onPendingFn ?: ( promptId ?: string ) => void ;
29
29
private onStartFn ?: ( promptId ?: string ) => void ;
30
- private onOutputFn ?: ( key : keyof PromptBuilder < I , string , T > [ "mapOutputKeys" ] , data : any , promptId ?: string ) => void ;
31
- private onFinishedFn ?: ( data : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > , promptId ?: string ) => void ;
30
+ private onOutputFn ?: (
31
+ key : keyof PromptBuilder < I , string , T > [ "mapOutputKeys" ] | "_raw" ,
32
+ data : any ,
33
+ promptId ?: string
34
+ ) => void ;
35
+ private onFinishedFn ?: (
36
+ data : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > & {
37
+ /**
38
+ * The raw output data from the workflow execution.
39
+ * Key is node_id, value is node output.
40
+ */
41
+ _raw ?: Record < string , any > ;
42
+ } ,
43
+ promptId ?: string
44
+ ) => void ;
32
45
private onFailedFn ?: ( err : Error , promptId ?: string ) => void ;
33
46
private onProgressFn ?: ( info : NodeProgress , promptId ?: string ) => void ;
34
47
@@ -95,7 +108,7 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
95
108
* @param fn - The callback function to handle the output.
96
109
* @returns The current instance of the class.
97
110
*/
98
- onOutput ( fn : ( key : keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , data : any , promptId ?: string ) => void ) {
111
+ onOutput ( fn : ( key : keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , data : any , promptId ?: string ) => void ) {
99
112
this . onOutputFn = fn ;
100
113
return this ;
101
114
}
@@ -107,7 +120,18 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
107
120
* and an optional promptId parameter.
108
121
* @returns The current instance of the CallWrapper.
109
122
*/
110
- onFinished ( fn : ( data : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > , promptId ?: string ) => void ) {
123
+ onFinished (
124
+ fn : (
125
+ data : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > & {
126
+ /**
127
+ * The raw output data from the workflow execution.
128
+ * Key is node_id, value is node output.
129
+ */
130
+ _raw ?: Record < string , any > ;
131
+ } ,
132
+ promptId ?: string
133
+ ) => void
134
+ ) {
111
135
this . onFinishedFn = fn ;
112
136
return this ;
113
137
}
@@ -143,7 +167,7 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
143
167
* or `undefined` if the job is not found,
144
168
* or `false` if the job execution fails.
145
169
*/
146
- async run ( ) : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | undefined | false > {
170
+ async run ( ) : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | undefined | false > {
147
171
/**
148
172
* Start the job execution.
149
173
*/
@@ -158,12 +182,11 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
158
182
promptLoadTrigger = resolve ;
159
183
} ) ;
160
184
161
- let jobDoneTrigger ! : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | false ) => void ;
162
- const jobDonePromise : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | false > = new Promise (
163
- ( resolve ) => {
185
+ let jobDoneTrigger ! : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | false ) => void ;
186
+ const jobDonePromise : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | false > =
187
+ new Promise ( ( resolve ) => {
164
188
jobDoneTrigger = resolve ;
165
- }
166
- ) ;
189
+ } ) ;
167
190
168
191
/**
169
192
* Declare the function to check if the job is executing.
@@ -195,8 +218,9 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
195
218
// race condition handling
196
219
let wentMissing = false ;
197
220
let cachedOutputDone = false ;
198
- let cachedOutputPromise : Promise < false | Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | null > =
199
- Promise . resolve ( null ) ;
221
+ let cachedOutputPromise : Promise <
222
+ false | Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | null
223
+ > = Promise . resolve ( null ) ;
200
224
201
225
const statusHandler = async ( ) => {
202
226
const queue = await this . client . getQueue ( ) ;
@@ -358,7 +382,7 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
358
382
359
383
private async handleCachedOutput (
360
384
promptId : string
361
- ) : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | false | null > {
385
+ ) : Promise < Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | false | null > {
362
386
const hisData = await this . client . getHistory ( promptId ) ;
363
387
if ( hisData ?. status ?. completed ) {
364
388
const output = this . mapOutput ( hisData . outputs ) ;
@@ -372,14 +396,19 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
372
396
return null ;
373
397
}
374
398
375
- private mapOutput ( outputNodes : any ) : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > {
399
+ private mapOutput ( outputNodes : any ) : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > {
376
400
const outputMapped = this . prompt . mapOutputKeys ;
377
- const output : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > = { } as any ;
401
+ const output : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > = { } as any ;
378
402
379
403
for ( const key in outputMapped ) {
380
404
const node = outputMapped [ key ] ;
381
405
if ( node ) {
382
406
output [ key as keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] ] = outputNodes [ node ] ;
407
+ } else {
408
+ if ( ! output . _raw ) {
409
+ output . _raw = { } ;
410
+ }
411
+ output . _raw [ key ] = outputNodes [ key ] ;
383
412
}
384
413
}
385
414
@@ -388,7 +417,7 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
388
417
389
418
private handleJobExecution (
390
419
promptId : string ,
391
- jobDoneTrigger : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | false ) => void
420
+ jobDoneTrigger : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | false ) => void
392
421
) : void {
393
422
const reverseOutputMapped = this . reverseMapOutputKeys ( ) ;
394
423
@@ -406,6 +435,10 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
406
435
this . output [ outputKey as keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] ] = ev . detail . output ;
407
436
this . onOutputFn ?.( outputKey , ev . detail . output , this . promptId ) ;
408
437
remainingOutput -- ;
438
+ } else {
439
+ this . output . _raw = this . output . _raw || { } ;
440
+ this . output . _raw [ ev . detail . node as string ] = ev . detail . output ;
441
+ this . onOutputFn ?.( ev . detail . node as string , ev . detail . output , this . promptId ) ;
409
442
}
410
443
411
444
if ( remainingOutput === 0 ) {
@@ -467,7 +500,7 @@ export class CallWrapper<I extends string, O extends string, T extends NodeData>
467
500
private handleError (
468
501
ev : CustomEvent ,
469
502
promptId : string ,
470
- resolve : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] , any > | false ) => void
503
+ resolve : ( value : Record < keyof PromptBuilder < I , O , T > [ "mapOutputKeys" ] | "_raw" , any > | false ) => void
471
504
) {
472
505
if ( ev . detail . prompt_id !== promptId ) return ;
473
506
this . onFailedFn ?.( new CustomEventError ( ev . detail . exception_type , { cause : ev . detail } ) , ev . detail . prompt_id ) ;
0 commit comments