@voltagent/core 0.1.79 → 0.1.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +162 -7
- package/dist/index.d.ts +162 -7
- package/dist/index.js +1071 -490
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1071 -490
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -269,6 +269,11 @@ interface WorkflowExecuteContext<INPUT, DATA, SUSPEND_DATA, RESUME_DATA> {
|
|
|
269
269
|
* Provides execution-scoped logging with full context (userId, conversationId, executionId).
|
|
270
270
|
*/
|
|
271
271
|
logger: Logger;
|
|
272
|
+
/**
|
|
273
|
+
* Stream writer for emitting events during streaming execution.
|
|
274
|
+
* Always available - uses NoOpWorkflowStreamWriter when not streaming
|
|
275
|
+
*/
|
|
276
|
+
writer: WorkflowStreamWriter;
|
|
272
277
|
}
|
|
273
278
|
/**
|
|
274
279
|
* A function that can be executed by the workflow
|
|
@@ -371,6 +376,8 @@ type WorkflowState<INPUT, RESULT> = {
|
|
|
371
376
|
error: Error | null;
|
|
372
377
|
/** suspension metadata when workflow is suspended */
|
|
373
378
|
suspension?: WorkflowSuspensionMetadata;
|
|
379
|
+
/** accumulated usage from andAgent calls */
|
|
380
|
+
usage: UsageInfo;
|
|
374
381
|
};
|
|
375
382
|
|
|
376
383
|
interface WorkflowSuspensionMetadata<SUSPEND_DATA = DangerouslyAllowAny> {
|
|
@@ -414,9 +421,9 @@ interface WorkflowSuspendController {
|
|
|
414
421
|
getReason: () => string | undefined;
|
|
415
422
|
}
|
|
416
423
|
/**
|
|
417
|
-
*
|
|
424
|
+
* Base result interface shared by all workflow execution results
|
|
418
425
|
*/
|
|
419
|
-
interface
|
|
426
|
+
interface WorkflowExecutionResultBase<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> {
|
|
420
427
|
/**
|
|
421
428
|
* Unique execution ID for this workflow run
|
|
422
429
|
*/
|
|
@@ -432,23 +439,38 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
|
|
|
432
439
|
/**
|
|
433
440
|
* When the workflow execution ended (completed, suspended, or errored)
|
|
434
441
|
*/
|
|
435
|
-
endAt: Date
|
|
442
|
+
endAt: Date | Promise<Date>;
|
|
436
443
|
/**
|
|
437
444
|
* Current status of the workflow execution
|
|
438
445
|
*/
|
|
439
|
-
status: "completed" | "suspended" | "error"
|
|
446
|
+
status: "completed" | "suspended" | "error" | Promise<"completed" | "suspended" | "error">;
|
|
440
447
|
/**
|
|
441
448
|
* The result data if workflow completed successfully
|
|
442
449
|
*/
|
|
443
|
-
result: z.infer<RESULT_SCHEMA> | null
|
|
450
|
+
result: z.infer<RESULT_SCHEMA> | null | Promise<z.infer<RESULT_SCHEMA> | null>;
|
|
444
451
|
/**
|
|
445
452
|
* Suspension metadata if workflow was suspended
|
|
446
453
|
*/
|
|
447
|
-
suspension?: WorkflowSuspensionMetadata
|
|
454
|
+
suspension?: WorkflowSuspensionMetadata | Promise<WorkflowSuspensionMetadata | undefined>;
|
|
448
455
|
/**
|
|
449
456
|
* Error information if workflow failed
|
|
450
457
|
*/
|
|
458
|
+
error?: unknown | Promise<unknown | undefined>;
|
|
459
|
+
/**
|
|
460
|
+
* Total token usage from all andAgent steps in the workflow
|
|
461
|
+
*/
|
|
462
|
+
usage: UsageInfo | Promise<UsageInfo>;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Result returned from workflow execution with suspend/resume capabilities
|
|
466
|
+
*/
|
|
467
|
+
interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> extends WorkflowExecutionResultBase<RESULT_SCHEMA, RESUME_SCHEMA> {
|
|
468
|
+
endAt: Date;
|
|
469
|
+
status: "completed" | "suspended" | "error";
|
|
470
|
+
result: z.infer<RESULT_SCHEMA> | null;
|
|
471
|
+
suspension?: WorkflowSuspensionMetadata;
|
|
451
472
|
error?: unknown;
|
|
473
|
+
usage: UsageInfo;
|
|
452
474
|
/**
|
|
453
475
|
* Resume a suspended workflow execution
|
|
454
476
|
* @param input - Optional new input data for resuming (validated against resumeSchema if provided)
|
|
@@ -459,6 +481,31 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
|
|
|
459
481
|
stepId?: string;
|
|
460
482
|
}) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
461
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* Result returned from workflow stream execution
|
|
486
|
+
* Extends base with streaming capabilities and promise-based fields
|
|
487
|
+
*/
|
|
488
|
+
interface WorkflowStreamResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> extends WorkflowExecutionResultBase<RESULT_SCHEMA, RESUME_SCHEMA>, AsyncIterable<WorkflowStreamEvent> {
|
|
489
|
+
endAt: Promise<Date>;
|
|
490
|
+
status: Promise<"completed" | "suspended" | "error">;
|
|
491
|
+
result: Promise<z.infer<RESULT_SCHEMA> | null>;
|
|
492
|
+
suspension: Promise<WorkflowSuspensionMetadata | undefined>;
|
|
493
|
+
error: Promise<unknown | undefined>;
|
|
494
|
+
usage: Promise<UsageInfo>;
|
|
495
|
+
/**
|
|
496
|
+
* Resume a suspended workflow execution
|
|
497
|
+
* @param input - Optional new input data for resuming (validated against resumeSchema if provided)
|
|
498
|
+
* @param options - Optional options for resuming, including stepId to resume from a specific step
|
|
499
|
+
* @returns A new stream result that can also be resumed if suspended again
|
|
500
|
+
*/
|
|
501
|
+
resume: (input: z.infer<RESUME_SCHEMA>, options?: {
|
|
502
|
+
stepId?: string;
|
|
503
|
+
}) => Promise<WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
504
|
+
/**
|
|
505
|
+
* Abort the workflow execution
|
|
506
|
+
*/
|
|
507
|
+
abort: () => void;
|
|
508
|
+
}
|
|
462
509
|
interface WorkflowRunOptions {
|
|
463
510
|
/**
|
|
464
511
|
* The active step, this can be used to track the current step in a workflow
|
|
@@ -650,9 +697,17 @@ type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEM
|
|
|
650
697
|
/**
|
|
651
698
|
* Execute the workflow with the given input
|
|
652
699
|
* @param input - The input to the workflow
|
|
653
|
-
* @
|
|
700
|
+
* @param options - Options for the workflow execution
|
|
701
|
+
* @returns Execution result with final result
|
|
654
702
|
*/
|
|
655
703
|
run: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
704
|
+
/**
|
|
705
|
+
* Execute the workflow with streaming support
|
|
706
|
+
* @param input - The input to the workflow
|
|
707
|
+
* @param options - Options for the workflow execution
|
|
708
|
+
* @returns Stream result with real-time events and promise-based fields
|
|
709
|
+
*/
|
|
710
|
+
stream: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>;
|
|
656
711
|
/**
|
|
657
712
|
* Create a WorkflowSuspendController that can be used to suspend the workflow
|
|
658
713
|
* @returns A WorkflowSuspendController instance
|
|
@@ -744,6 +799,80 @@ interface WorkflowStats {
|
|
|
744
799
|
averageExecutionTime: number;
|
|
745
800
|
lastExecutionTime?: Date;
|
|
746
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Event emitted during workflow streaming
|
|
804
|
+
*/
|
|
805
|
+
interface WorkflowStreamEvent {
|
|
806
|
+
/**
|
|
807
|
+
* Type of the event (e.g., "step-start", "step-complete", "custom", "agent-stream")
|
|
808
|
+
*/
|
|
809
|
+
type: string;
|
|
810
|
+
/**
|
|
811
|
+
* Unique execution ID for this workflow run
|
|
812
|
+
*/
|
|
813
|
+
executionId: string;
|
|
814
|
+
/**
|
|
815
|
+
* Source of the event (step ID or name)
|
|
816
|
+
*/
|
|
817
|
+
from: string;
|
|
818
|
+
/**
|
|
819
|
+
* Input data for the step/event
|
|
820
|
+
*/
|
|
821
|
+
input?: Record<string, DangerouslyAllowAny>;
|
|
822
|
+
/**
|
|
823
|
+
* Output data from the step/event
|
|
824
|
+
*/
|
|
825
|
+
output?: Record<string, DangerouslyAllowAny>;
|
|
826
|
+
/**
|
|
827
|
+
* Current status of the step/event
|
|
828
|
+
*/
|
|
829
|
+
status: "pending" | "running" | "success" | "error" | "suspended";
|
|
830
|
+
/**
|
|
831
|
+
* User context passed through the workflow
|
|
832
|
+
*/
|
|
833
|
+
userContext?: UserContext;
|
|
834
|
+
/**
|
|
835
|
+
* Timestamp of the event
|
|
836
|
+
*/
|
|
837
|
+
timestamp: string;
|
|
838
|
+
/**
|
|
839
|
+
* Current step index in the workflow
|
|
840
|
+
*/
|
|
841
|
+
stepIndex?: number;
|
|
842
|
+
/**
|
|
843
|
+
* Step type for step events
|
|
844
|
+
*/
|
|
845
|
+
stepType?: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow";
|
|
846
|
+
/**
|
|
847
|
+
* Additional metadata
|
|
848
|
+
*/
|
|
849
|
+
metadata?: Record<string, DangerouslyAllowAny>;
|
|
850
|
+
/**
|
|
851
|
+
* Error information if status is "error"
|
|
852
|
+
*/
|
|
853
|
+
error?: DangerouslyAllowAny;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Writer interface for emitting stream events from workflow steps
|
|
857
|
+
*/
|
|
858
|
+
interface WorkflowStreamWriter {
|
|
859
|
+
/**
|
|
860
|
+
* Write a custom event to the stream
|
|
861
|
+
*/
|
|
862
|
+
write(event: Partial<WorkflowStreamEvent> & {
|
|
863
|
+
type: string;
|
|
864
|
+
}): void;
|
|
865
|
+
/**
|
|
866
|
+
* Pipe events from an agent's fullStream to the workflow stream
|
|
867
|
+
* @param fullStream - The agent's fullStream async iterable
|
|
868
|
+
* @param options - Optional configuration for piping
|
|
869
|
+
*/
|
|
870
|
+
pipeFrom(fullStream: AsyncIterable<DangerouslyAllowAny>, options?: {
|
|
871
|
+
prefix?: string;
|
|
872
|
+
agentId?: string;
|
|
873
|
+
filter?: (part: DangerouslyAllowAny) => boolean;
|
|
874
|
+
}): Promise<void>;
|
|
875
|
+
}
|
|
747
876
|
/**
|
|
748
877
|
* Options for creating workflow execution
|
|
749
878
|
*/
|
|
@@ -842,6 +971,11 @@ interface WorkflowExecutionContext {
|
|
|
842
971
|
* Provides execution-scoped logging with full context (userId, conversationId, executionId)
|
|
843
972
|
*/
|
|
844
973
|
logger: Logger;
|
|
974
|
+
/**
|
|
975
|
+
* Stream writer for emitting events during streaming execution
|
|
976
|
+
* Always available - uses NoOpWorkflowStreamWriter when not streaming
|
|
977
|
+
*/
|
|
978
|
+
streamWriter: WorkflowStreamWriter;
|
|
845
979
|
}
|
|
846
980
|
/**
|
|
847
981
|
* Workflow step context for individual step tracking
|
|
@@ -5464,6 +5598,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5464
5598
|
} | undefined;
|
|
5465
5599
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5466
5600
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5601
|
+
logger: Logger;
|
|
5602
|
+
writer: WorkflowStreamWriter;
|
|
5467
5603
|
}) => Promise<z.infer<OS>>;
|
|
5468
5604
|
id: string;
|
|
5469
5605
|
name?: string;
|
|
@@ -5488,6 +5624,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5488
5624
|
} | undefined;
|
|
5489
5625
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5490
5626
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5627
|
+
logger: Logger;
|
|
5628
|
+
writer: WorkflowStreamWriter;
|
|
5491
5629
|
}) => Promise<NEW_DATA>;
|
|
5492
5630
|
id: string;
|
|
5493
5631
|
name?: string;
|
|
@@ -5512,6 +5650,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5512
5650
|
} | undefined;
|
|
5513
5651
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5514
5652
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5653
|
+
logger: Logger;
|
|
5654
|
+
writer: WorkflowStreamWriter;
|
|
5515
5655
|
}) => Promise<z.infer<OS>>;
|
|
5516
5656
|
id: string;
|
|
5517
5657
|
name?: string;
|
|
@@ -5536,6 +5676,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5536
5676
|
} | undefined;
|
|
5537
5677
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5538
5678
|
resumeData?: z.infer<RS>;
|
|
5679
|
+
logger: Logger;
|
|
5680
|
+
writer: WorkflowStreamWriter;
|
|
5539
5681
|
}) => Promise<NEW_DATA>;
|
|
5540
5682
|
id: string;
|
|
5541
5683
|
name?: string;
|
|
@@ -5576,6 +5718,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5576
5718
|
} | undefined;
|
|
5577
5719
|
suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5578
5720
|
resumeData?: z.infer<RESUME_SCHEMA>;
|
|
5721
|
+
logger: Logger;
|
|
5722
|
+
writer: WorkflowStreamWriter;
|
|
5579
5723
|
}) => Promise<NEW_DATA>;
|
|
5580
5724
|
id: string;
|
|
5581
5725
|
name?: string;
|
|
@@ -5604,6 +5748,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5604
5748
|
} | undefined;
|
|
5605
5749
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5606
5750
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5751
|
+
logger: Logger;
|
|
5752
|
+
writer: WorkflowStreamWriter;
|
|
5607
5753
|
}) => Promise<boolean>;
|
|
5608
5754
|
}): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<OS> | z.infer<IS>, SUSPEND_SCHEMA, RESUME_SCHEMA>;
|
|
5609
5755
|
/**
|
|
@@ -5663,6 +5809,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5663
5809
|
} | undefined;
|
|
5664
5810
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5665
5811
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5812
|
+
logger: Logger;
|
|
5813
|
+
writer: WorkflowStreamWriter;
|
|
5666
5814
|
}) => Promise<void>;
|
|
5667
5815
|
id: string;
|
|
5668
5816
|
name?: string;
|
|
@@ -5702,6 +5850,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5702
5850
|
} | undefined;
|
|
5703
5851
|
suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5704
5852
|
resumeData?: z.infer<RESUME_SCHEMA>;
|
|
5853
|
+
logger: Logger;
|
|
5854
|
+
writer: WorkflowStreamWriter;
|
|
5705
5855
|
}) => Promise<void>;
|
|
5706
5856
|
id: string;
|
|
5707
5857
|
name?: string;
|
|
@@ -5835,6 +5985,10 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5835
5985
|
* Execute the workflow with the given input
|
|
5836
5986
|
*/
|
|
5837
5987
|
run(input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions): Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
5988
|
+
/**
|
|
5989
|
+
* Execute the workflow with streaming support
|
|
5990
|
+
*/
|
|
5991
|
+
stream(input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions): WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>;
|
|
5838
5992
|
}
|
|
5839
5993
|
/**
|
|
5840
5994
|
* Creates a new workflow chain with the given configuration
|
|
@@ -6130,6 +6284,7 @@ declare class WorkflowRegistry extends EventEmitter {
|
|
|
6130
6284
|
endAt: Date;
|
|
6131
6285
|
status: "completed" | "suspended" | "error";
|
|
6132
6286
|
result: any;
|
|
6287
|
+
usage: UsageInfo;
|
|
6133
6288
|
suspension?: any;
|
|
6134
6289
|
error?: unknown;
|
|
6135
6290
|
} | null>;
|
package/dist/index.d.ts
CHANGED
|
@@ -269,6 +269,11 @@ interface WorkflowExecuteContext<INPUT, DATA, SUSPEND_DATA, RESUME_DATA> {
|
|
|
269
269
|
* Provides execution-scoped logging with full context (userId, conversationId, executionId).
|
|
270
270
|
*/
|
|
271
271
|
logger: Logger;
|
|
272
|
+
/**
|
|
273
|
+
* Stream writer for emitting events during streaming execution.
|
|
274
|
+
* Always available - uses NoOpWorkflowStreamWriter when not streaming
|
|
275
|
+
*/
|
|
276
|
+
writer: WorkflowStreamWriter;
|
|
272
277
|
}
|
|
273
278
|
/**
|
|
274
279
|
* A function that can be executed by the workflow
|
|
@@ -371,6 +376,8 @@ type WorkflowState<INPUT, RESULT> = {
|
|
|
371
376
|
error: Error | null;
|
|
372
377
|
/** suspension metadata when workflow is suspended */
|
|
373
378
|
suspension?: WorkflowSuspensionMetadata;
|
|
379
|
+
/** accumulated usage from andAgent calls */
|
|
380
|
+
usage: UsageInfo;
|
|
374
381
|
};
|
|
375
382
|
|
|
376
383
|
interface WorkflowSuspensionMetadata<SUSPEND_DATA = DangerouslyAllowAny> {
|
|
@@ -414,9 +421,9 @@ interface WorkflowSuspendController {
|
|
|
414
421
|
getReason: () => string | undefined;
|
|
415
422
|
}
|
|
416
423
|
/**
|
|
417
|
-
*
|
|
424
|
+
* Base result interface shared by all workflow execution results
|
|
418
425
|
*/
|
|
419
|
-
interface
|
|
426
|
+
interface WorkflowExecutionResultBase<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> {
|
|
420
427
|
/**
|
|
421
428
|
* Unique execution ID for this workflow run
|
|
422
429
|
*/
|
|
@@ -432,23 +439,38 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
|
|
|
432
439
|
/**
|
|
433
440
|
* When the workflow execution ended (completed, suspended, or errored)
|
|
434
441
|
*/
|
|
435
|
-
endAt: Date
|
|
442
|
+
endAt: Date | Promise<Date>;
|
|
436
443
|
/**
|
|
437
444
|
* Current status of the workflow execution
|
|
438
445
|
*/
|
|
439
|
-
status: "completed" | "suspended" | "error"
|
|
446
|
+
status: "completed" | "suspended" | "error" | Promise<"completed" | "suspended" | "error">;
|
|
440
447
|
/**
|
|
441
448
|
* The result data if workflow completed successfully
|
|
442
449
|
*/
|
|
443
|
-
result: z.infer<RESULT_SCHEMA> | null
|
|
450
|
+
result: z.infer<RESULT_SCHEMA> | null | Promise<z.infer<RESULT_SCHEMA> | null>;
|
|
444
451
|
/**
|
|
445
452
|
* Suspension metadata if workflow was suspended
|
|
446
453
|
*/
|
|
447
|
-
suspension?: WorkflowSuspensionMetadata
|
|
454
|
+
suspension?: WorkflowSuspensionMetadata | Promise<WorkflowSuspensionMetadata | undefined>;
|
|
448
455
|
/**
|
|
449
456
|
* Error information if workflow failed
|
|
450
457
|
*/
|
|
458
|
+
error?: unknown | Promise<unknown | undefined>;
|
|
459
|
+
/**
|
|
460
|
+
* Total token usage from all andAgent steps in the workflow
|
|
461
|
+
*/
|
|
462
|
+
usage: UsageInfo | Promise<UsageInfo>;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Result returned from workflow execution with suspend/resume capabilities
|
|
466
|
+
*/
|
|
467
|
+
interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> extends WorkflowExecutionResultBase<RESULT_SCHEMA, RESUME_SCHEMA> {
|
|
468
|
+
endAt: Date;
|
|
469
|
+
status: "completed" | "suspended" | "error";
|
|
470
|
+
result: z.infer<RESULT_SCHEMA> | null;
|
|
471
|
+
suspension?: WorkflowSuspensionMetadata;
|
|
451
472
|
error?: unknown;
|
|
473
|
+
usage: UsageInfo;
|
|
452
474
|
/**
|
|
453
475
|
* Resume a suspended workflow execution
|
|
454
476
|
* @param input - Optional new input data for resuming (validated against resumeSchema if provided)
|
|
@@ -459,6 +481,31 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
|
|
|
459
481
|
stepId?: string;
|
|
460
482
|
}) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
461
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* Result returned from workflow stream execution
|
|
486
|
+
* Extends base with streaming capabilities and promise-based fields
|
|
487
|
+
*/
|
|
488
|
+
interface WorkflowStreamResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCHEMA extends z.ZodTypeAny = z.ZodAny> extends WorkflowExecutionResultBase<RESULT_SCHEMA, RESUME_SCHEMA>, AsyncIterable<WorkflowStreamEvent> {
|
|
489
|
+
endAt: Promise<Date>;
|
|
490
|
+
status: Promise<"completed" | "suspended" | "error">;
|
|
491
|
+
result: Promise<z.infer<RESULT_SCHEMA> | null>;
|
|
492
|
+
suspension: Promise<WorkflowSuspensionMetadata | undefined>;
|
|
493
|
+
error: Promise<unknown | undefined>;
|
|
494
|
+
usage: Promise<UsageInfo>;
|
|
495
|
+
/**
|
|
496
|
+
* Resume a suspended workflow execution
|
|
497
|
+
* @param input - Optional new input data for resuming (validated against resumeSchema if provided)
|
|
498
|
+
* @param options - Optional options for resuming, including stepId to resume from a specific step
|
|
499
|
+
* @returns A new stream result that can also be resumed if suspended again
|
|
500
|
+
*/
|
|
501
|
+
resume: (input: z.infer<RESUME_SCHEMA>, options?: {
|
|
502
|
+
stepId?: string;
|
|
503
|
+
}) => Promise<WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
504
|
+
/**
|
|
505
|
+
* Abort the workflow execution
|
|
506
|
+
*/
|
|
507
|
+
abort: () => void;
|
|
508
|
+
}
|
|
462
509
|
interface WorkflowRunOptions {
|
|
463
510
|
/**
|
|
464
511
|
* The active step, this can be used to track the current step in a workflow
|
|
@@ -650,9 +697,17 @@ type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEM
|
|
|
650
697
|
/**
|
|
651
698
|
* Execute the workflow with the given input
|
|
652
699
|
* @param input - The input to the workflow
|
|
653
|
-
* @
|
|
700
|
+
* @param options - Options for the workflow execution
|
|
701
|
+
* @returns Execution result with final result
|
|
654
702
|
*/
|
|
655
703
|
run: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
704
|
+
/**
|
|
705
|
+
* Execute the workflow with streaming support
|
|
706
|
+
* @param input - The input to the workflow
|
|
707
|
+
* @param options - Options for the workflow execution
|
|
708
|
+
* @returns Stream result with real-time events and promise-based fields
|
|
709
|
+
*/
|
|
710
|
+
stream: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>;
|
|
656
711
|
/**
|
|
657
712
|
* Create a WorkflowSuspendController that can be used to suspend the workflow
|
|
658
713
|
* @returns A WorkflowSuspendController instance
|
|
@@ -744,6 +799,80 @@ interface WorkflowStats {
|
|
|
744
799
|
averageExecutionTime: number;
|
|
745
800
|
lastExecutionTime?: Date;
|
|
746
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Event emitted during workflow streaming
|
|
804
|
+
*/
|
|
805
|
+
interface WorkflowStreamEvent {
|
|
806
|
+
/**
|
|
807
|
+
* Type of the event (e.g., "step-start", "step-complete", "custom", "agent-stream")
|
|
808
|
+
*/
|
|
809
|
+
type: string;
|
|
810
|
+
/**
|
|
811
|
+
* Unique execution ID for this workflow run
|
|
812
|
+
*/
|
|
813
|
+
executionId: string;
|
|
814
|
+
/**
|
|
815
|
+
* Source of the event (step ID or name)
|
|
816
|
+
*/
|
|
817
|
+
from: string;
|
|
818
|
+
/**
|
|
819
|
+
* Input data for the step/event
|
|
820
|
+
*/
|
|
821
|
+
input?: Record<string, DangerouslyAllowAny>;
|
|
822
|
+
/**
|
|
823
|
+
* Output data from the step/event
|
|
824
|
+
*/
|
|
825
|
+
output?: Record<string, DangerouslyAllowAny>;
|
|
826
|
+
/**
|
|
827
|
+
* Current status of the step/event
|
|
828
|
+
*/
|
|
829
|
+
status: "pending" | "running" | "success" | "error" | "suspended";
|
|
830
|
+
/**
|
|
831
|
+
* User context passed through the workflow
|
|
832
|
+
*/
|
|
833
|
+
userContext?: UserContext;
|
|
834
|
+
/**
|
|
835
|
+
* Timestamp of the event
|
|
836
|
+
*/
|
|
837
|
+
timestamp: string;
|
|
838
|
+
/**
|
|
839
|
+
* Current step index in the workflow
|
|
840
|
+
*/
|
|
841
|
+
stepIndex?: number;
|
|
842
|
+
/**
|
|
843
|
+
* Step type for step events
|
|
844
|
+
*/
|
|
845
|
+
stepType?: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow";
|
|
846
|
+
/**
|
|
847
|
+
* Additional metadata
|
|
848
|
+
*/
|
|
849
|
+
metadata?: Record<string, DangerouslyAllowAny>;
|
|
850
|
+
/**
|
|
851
|
+
* Error information if status is "error"
|
|
852
|
+
*/
|
|
853
|
+
error?: DangerouslyAllowAny;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Writer interface for emitting stream events from workflow steps
|
|
857
|
+
*/
|
|
858
|
+
interface WorkflowStreamWriter {
|
|
859
|
+
/**
|
|
860
|
+
* Write a custom event to the stream
|
|
861
|
+
*/
|
|
862
|
+
write(event: Partial<WorkflowStreamEvent> & {
|
|
863
|
+
type: string;
|
|
864
|
+
}): void;
|
|
865
|
+
/**
|
|
866
|
+
* Pipe events from an agent's fullStream to the workflow stream
|
|
867
|
+
* @param fullStream - The agent's fullStream async iterable
|
|
868
|
+
* @param options - Optional configuration for piping
|
|
869
|
+
*/
|
|
870
|
+
pipeFrom(fullStream: AsyncIterable<DangerouslyAllowAny>, options?: {
|
|
871
|
+
prefix?: string;
|
|
872
|
+
agentId?: string;
|
|
873
|
+
filter?: (part: DangerouslyAllowAny) => boolean;
|
|
874
|
+
}): Promise<void>;
|
|
875
|
+
}
|
|
747
876
|
/**
|
|
748
877
|
* Options for creating workflow execution
|
|
749
878
|
*/
|
|
@@ -842,6 +971,11 @@ interface WorkflowExecutionContext {
|
|
|
842
971
|
* Provides execution-scoped logging with full context (userId, conversationId, executionId)
|
|
843
972
|
*/
|
|
844
973
|
logger: Logger;
|
|
974
|
+
/**
|
|
975
|
+
* Stream writer for emitting events during streaming execution
|
|
976
|
+
* Always available - uses NoOpWorkflowStreamWriter when not streaming
|
|
977
|
+
*/
|
|
978
|
+
streamWriter: WorkflowStreamWriter;
|
|
845
979
|
}
|
|
846
980
|
/**
|
|
847
981
|
* Workflow step context for individual step tracking
|
|
@@ -5464,6 +5598,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5464
5598
|
} | undefined;
|
|
5465
5599
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5466
5600
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5601
|
+
logger: Logger;
|
|
5602
|
+
writer: WorkflowStreamWriter;
|
|
5467
5603
|
}) => Promise<z.infer<OS>>;
|
|
5468
5604
|
id: string;
|
|
5469
5605
|
name?: string;
|
|
@@ -5488,6 +5624,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5488
5624
|
} | undefined;
|
|
5489
5625
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5490
5626
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5627
|
+
logger: Logger;
|
|
5628
|
+
writer: WorkflowStreamWriter;
|
|
5491
5629
|
}) => Promise<NEW_DATA>;
|
|
5492
5630
|
id: string;
|
|
5493
5631
|
name?: string;
|
|
@@ -5512,6 +5650,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5512
5650
|
} | undefined;
|
|
5513
5651
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5514
5652
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5653
|
+
logger: Logger;
|
|
5654
|
+
writer: WorkflowStreamWriter;
|
|
5515
5655
|
}) => Promise<z.infer<OS>>;
|
|
5516
5656
|
id: string;
|
|
5517
5657
|
name?: string;
|
|
@@ -5536,6 +5676,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5536
5676
|
} | undefined;
|
|
5537
5677
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5538
5678
|
resumeData?: z.infer<RS>;
|
|
5679
|
+
logger: Logger;
|
|
5680
|
+
writer: WorkflowStreamWriter;
|
|
5539
5681
|
}) => Promise<NEW_DATA>;
|
|
5540
5682
|
id: string;
|
|
5541
5683
|
name?: string;
|
|
@@ -5576,6 +5718,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5576
5718
|
} | undefined;
|
|
5577
5719
|
suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5578
5720
|
resumeData?: z.infer<RESUME_SCHEMA>;
|
|
5721
|
+
logger: Logger;
|
|
5722
|
+
writer: WorkflowStreamWriter;
|
|
5579
5723
|
}) => Promise<NEW_DATA>;
|
|
5580
5724
|
id: string;
|
|
5581
5725
|
name?: string;
|
|
@@ -5604,6 +5748,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5604
5748
|
} | undefined;
|
|
5605
5749
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5606
5750
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5751
|
+
logger: Logger;
|
|
5752
|
+
writer: WorkflowStreamWriter;
|
|
5607
5753
|
}) => Promise<boolean>;
|
|
5608
5754
|
}): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<OS> | z.infer<IS>, SUSPEND_SCHEMA, RESUME_SCHEMA>;
|
|
5609
5755
|
/**
|
|
@@ -5663,6 +5809,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5663
5809
|
} | undefined;
|
|
5664
5810
|
suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5665
5811
|
resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
|
|
5812
|
+
logger: Logger;
|
|
5813
|
+
writer: WorkflowStreamWriter;
|
|
5666
5814
|
}) => Promise<void>;
|
|
5667
5815
|
id: string;
|
|
5668
5816
|
name?: string;
|
|
@@ -5702,6 +5850,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5702
5850
|
} | undefined;
|
|
5703
5851
|
suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
|
|
5704
5852
|
resumeData?: z.infer<RESUME_SCHEMA>;
|
|
5853
|
+
logger: Logger;
|
|
5854
|
+
writer: WorkflowStreamWriter;
|
|
5705
5855
|
}) => Promise<void>;
|
|
5706
5856
|
id: string;
|
|
5707
5857
|
name?: string;
|
|
@@ -5835,6 +5985,10 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5835
5985
|
* Execute the workflow with the given input
|
|
5836
5986
|
*/
|
|
5837
5987
|
run(input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions): Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
|
|
5988
|
+
/**
|
|
5989
|
+
* Execute the workflow with streaming support
|
|
5990
|
+
*/
|
|
5991
|
+
stream(input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions): WorkflowStreamResult<RESULT_SCHEMA, RESUME_SCHEMA>;
|
|
5838
5992
|
}
|
|
5839
5993
|
/**
|
|
5840
5994
|
* Creates a new workflow chain with the given configuration
|
|
@@ -6130,6 +6284,7 @@ declare class WorkflowRegistry extends EventEmitter {
|
|
|
6130
6284
|
endAt: Date;
|
|
6131
6285
|
status: "completed" | "suspended" | "error";
|
|
6132
6286
|
result: any;
|
|
6287
|
+
usage: UsageInfo;
|
|
6133
6288
|
suspension?: any;
|
|
6134
6289
|
error?: unknown;
|
|
6135
6290
|
} | null>;
|