@voltagent/core 0.1.79 → 0.1.80

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 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 for writing custom events.
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> {
@@ -441,6 +448,10 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
441
448
  * The result data if workflow completed successfully
442
449
  */
443
450
  result: z.infer<RESULT_SCHEMA> | null;
451
+ /**
452
+ * Stream of workflow events for real-time monitoring
453
+ */
454
+ stream: AsyncIterableIterator<WorkflowStreamEvent>;
444
455
  /**
445
456
  * Suspension metadata if workflow was suspended
446
457
  */
@@ -449,6 +460,10 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
449
460
  * Error information if workflow failed
450
461
  */
451
462
  error?: unknown;
463
+ /**
464
+ * Total token usage from all andAgent steps in the workflow
465
+ */
466
+ usage: UsageInfo;
452
467
  /**
453
468
  * Resume a suspended workflow execution
454
469
  * @param input - Optional new input data for resuming (validated against resumeSchema if provided)
@@ -650,7 +665,8 @@ type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEM
650
665
  /**
651
666
  * Execute the workflow with the given input
652
667
  * @param input - The input to the workflow
653
- * @returns The result of the workflow
668
+ * @param options - Options for the workflow execution
669
+ * @returns Execution result with stream and final result
654
670
  */
655
671
  run: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
656
672
  /**
@@ -744,6 +760,80 @@ interface WorkflowStats {
744
760
  averageExecutionTime: number;
745
761
  lastExecutionTime?: Date;
746
762
  }
763
+ /**
764
+ * Event emitted during workflow streaming
765
+ */
766
+ interface WorkflowStreamEvent {
767
+ /**
768
+ * Type of the event (e.g., "step-start", "step-complete", "custom", "agent-stream")
769
+ */
770
+ type: string;
771
+ /**
772
+ * Unique execution ID for this workflow run
773
+ */
774
+ executionId: string;
775
+ /**
776
+ * Source of the event (step ID or name)
777
+ */
778
+ from: string;
779
+ /**
780
+ * Input data for the step/event
781
+ */
782
+ input?: Record<string, DangerouslyAllowAny>;
783
+ /**
784
+ * Output data from the step/event
785
+ */
786
+ output?: Record<string, DangerouslyAllowAny>;
787
+ /**
788
+ * Current status of the step/event
789
+ */
790
+ status: "pending" | "running" | "success" | "error" | "suspended";
791
+ /**
792
+ * User context passed through the workflow
793
+ */
794
+ userContext?: UserContext;
795
+ /**
796
+ * Timestamp of the event
797
+ */
798
+ timestamp: string;
799
+ /**
800
+ * Current step index in the workflow
801
+ */
802
+ stepIndex?: number;
803
+ /**
804
+ * Step type for step events
805
+ */
806
+ stepType?: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow";
807
+ /**
808
+ * Additional metadata
809
+ */
810
+ metadata?: Record<string, DangerouslyAllowAny>;
811
+ /**
812
+ * Error information if status is "error"
813
+ */
814
+ error?: DangerouslyAllowAny;
815
+ }
816
+ /**
817
+ * Writer interface for emitting stream events from workflow steps
818
+ */
819
+ interface WorkflowStreamWriter {
820
+ /**
821
+ * Write a custom event to the stream
822
+ */
823
+ write(event: Partial<WorkflowStreamEvent> & {
824
+ type: string;
825
+ }): void;
826
+ /**
827
+ * Pipe events from an agent's fullStream to the workflow stream
828
+ * @param fullStream - The agent's fullStream async iterable
829
+ * @param options - Optional configuration for piping
830
+ */
831
+ pipeFrom(fullStream: AsyncIterable<DangerouslyAllowAny>, options?: {
832
+ prefix?: string;
833
+ agentId?: string;
834
+ filter?: (part: DangerouslyAllowAny) => boolean;
835
+ }): Promise<void>;
836
+ }
747
837
  /**
748
838
  * Options for creating workflow execution
749
839
  */
@@ -842,6 +932,11 @@ interface WorkflowExecutionContext {
842
932
  * Provides execution-scoped logging with full context (userId, conversationId, executionId)
843
933
  */
844
934
  logger: Logger;
935
+ /**
936
+ * Stream writer for emitting events during streaming execution
937
+ * Always available for writing custom events
938
+ */
939
+ streamWriter: WorkflowStreamWriter;
845
940
  }
846
941
  /**
847
942
  * Workflow step context for individual step tracking
@@ -5464,6 +5559,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5464
5559
  } | undefined;
5465
5560
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5466
5561
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5562
+ logger: Logger;
5563
+ writer: WorkflowStreamWriter;
5467
5564
  }) => Promise<z.infer<OS>>;
5468
5565
  id: string;
5469
5566
  name?: string;
@@ -5488,6 +5585,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5488
5585
  } | undefined;
5489
5586
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5490
5587
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5588
+ logger: Logger;
5589
+ writer: WorkflowStreamWriter;
5491
5590
  }) => Promise<NEW_DATA>;
5492
5591
  id: string;
5493
5592
  name?: string;
@@ -5512,6 +5611,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5512
5611
  } | undefined;
5513
5612
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5514
5613
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5614
+ logger: Logger;
5615
+ writer: WorkflowStreamWriter;
5515
5616
  }) => Promise<z.infer<OS>>;
5516
5617
  id: string;
5517
5618
  name?: string;
@@ -5536,6 +5637,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5536
5637
  } | undefined;
5537
5638
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5538
5639
  resumeData?: z.infer<RS>;
5640
+ logger: Logger;
5641
+ writer: WorkflowStreamWriter;
5539
5642
  }) => Promise<NEW_DATA>;
5540
5643
  id: string;
5541
5644
  name?: string;
@@ -5576,6 +5679,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5576
5679
  } | undefined;
5577
5680
  suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5578
5681
  resumeData?: z.infer<RESUME_SCHEMA>;
5682
+ logger: Logger;
5683
+ writer: WorkflowStreamWriter;
5579
5684
  }) => Promise<NEW_DATA>;
5580
5685
  id: string;
5581
5686
  name?: string;
@@ -5604,6 +5709,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5604
5709
  } | undefined;
5605
5710
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5606
5711
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5712
+ logger: Logger;
5713
+ writer: WorkflowStreamWriter;
5607
5714
  }) => Promise<boolean>;
5608
5715
  }): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<OS> | z.infer<IS>, SUSPEND_SCHEMA, RESUME_SCHEMA>;
5609
5716
  /**
@@ -5663,6 +5770,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5663
5770
  } | undefined;
5664
5771
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5665
5772
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5773
+ logger: Logger;
5774
+ writer: WorkflowStreamWriter;
5666
5775
  }) => Promise<void>;
5667
5776
  id: string;
5668
5777
  name?: string;
@@ -5702,6 +5811,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5702
5811
  } | undefined;
5703
5812
  suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5704
5813
  resumeData?: z.infer<RESUME_SCHEMA>;
5814
+ logger: Logger;
5815
+ writer: WorkflowStreamWriter;
5705
5816
  }) => Promise<void>;
5706
5817
  id: string;
5707
5818
  name?: string;
@@ -6130,6 +6241,8 @@ declare class WorkflowRegistry extends EventEmitter {
6130
6241
  endAt: Date;
6131
6242
  status: "completed" | "suspended" | "error";
6132
6243
  result: any;
6244
+ stream: AsyncIterableIterator<WorkflowStreamEvent>;
6245
+ usage: UsageInfo;
6133
6246
  suspension?: any;
6134
6247
  error?: unknown;
6135
6248
  } | 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 for writing custom events.
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> {
@@ -441,6 +448,10 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
441
448
  * The result data if workflow completed successfully
442
449
  */
443
450
  result: z.infer<RESULT_SCHEMA> | null;
451
+ /**
452
+ * Stream of workflow events for real-time monitoring
453
+ */
454
+ stream: AsyncIterableIterator<WorkflowStreamEvent>;
444
455
  /**
445
456
  * Suspension metadata if workflow was suspended
446
457
  */
@@ -449,6 +460,10 @@ interface WorkflowExecutionResult<RESULT_SCHEMA extends z.ZodTypeAny, RESUME_SCH
449
460
  * Error information if workflow failed
450
461
  */
451
462
  error?: unknown;
463
+ /**
464
+ * Total token usage from all andAgent steps in the workflow
465
+ */
466
+ usage: UsageInfo;
452
467
  /**
453
468
  * Resume a suspended workflow execution
454
469
  * @param input - Optional new input data for resuming (validated against resumeSchema if provided)
@@ -650,7 +665,8 @@ type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEM
650
665
  /**
651
666
  * Execute the workflow with the given input
652
667
  * @param input - The input to the workflow
653
- * @returns The result of the workflow
668
+ * @param options - Options for the workflow execution
669
+ * @returns Execution result with stream and final result
654
670
  */
655
671
  run: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => Promise<WorkflowExecutionResult<RESULT_SCHEMA, RESUME_SCHEMA>>;
656
672
  /**
@@ -744,6 +760,80 @@ interface WorkflowStats {
744
760
  averageExecutionTime: number;
745
761
  lastExecutionTime?: Date;
746
762
  }
763
+ /**
764
+ * Event emitted during workflow streaming
765
+ */
766
+ interface WorkflowStreamEvent {
767
+ /**
768
+ * Type of the event (e.g., "step-start", "step-complete", "custom", "agent-stream")
769
+ */
770
+ type: string;
771
+ /**
772
+ * Unique execution ID for this workflow run
773
+ */
774
+ executionId: string;
775
+ /**
776
+ * Source of the event (step ID or name)
777
+ */
778
+ from: string;
779
+ /**
780
+ * Input data for the step/event
781
+ */
782
+ input?: Record<string, DangerouslyAllowAny>;
783
+ /**
784
+ * Output data from the step/event
785
+ */
786
+ output?: Record<string, DangerouslyAllowAny>;
787
+ /**
788
+ * Current status of the step/event
789
+ */
790
+ status: "pending" | "running" | "success" | "error" | "suspended";
791
+ /**
792
+ * User context passed through the workflow
793
+ */
794
+ userContext?: UserContext;
795
+ /**
796
+ * Timestamp of the event
797
+ */
798
+ timestamp: string;
799
+ /**
800
+ * Current step index in the workflow
801
+ */
802
+ stepIndex?: number;
803
+ /**
804
+ * Step type for step events
805
+ */
806
+ stepType?: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow";
807
+ /**
808
+ * Additional metadata
809
+ */
810
+ metadata?: Record<string, DangerouslyAllowAny>;
811
+ /**
812
+ * Error information if status is "error"
813
+ */
814
+ error?: DangerouslyAllowAny;
815
+ }
816
+ /**
817
+ * Writer interface for emitting stream events from workflow steps
818
+ */
819
+ interface WorkflowStreamWriter {
820
+ /**
821
+ * Write a custom event to the stream
822
+ */
823
+ write(event: Partial<WorkflowStreamEvent> & {
824
+ type: string;
825
+ }): void;
826
+ /**
827
+ * Pipe events from an agent's fullStream to the workflow stream
828
+ * @param fullStream - The agent's fullStream async iterable
829
+ * @param options - Optional configuration for piping
830
+ */
831
+ pipeFrom(fullStream: AsyncIterable<DangerouslyAllowAny>, options?: {
832
+ prefix?: string;
833
+ agentId?: string;
834
+ filter?: (part: DangerouslyAllowAny) => boolean;
835
+ }): Promise<void>;
836
+ }
747
837
  /**
748
838
  * Options for creating workflow execution
749
839
  */
@@ -842,6 +932,11 @@ interface WorkflowExecutionContext {
842
932
  * Provides execution-scoped logging with full context (userId, conversationId, executionId)
843
933
  */
844
934
  logger: Logger;
935
+ /**
936
+ * Stream writer for emitting events during streaming execution
937
+ * Always available for writing custom events
938
+ */
939
+ streamWriter: WorkflowStreamWriter;
845
940
  }
846
941
  /**
847
942
  * Workflow step context for individual step tracking
@@ -5464,6 +5559,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5464
5559
  } | undefined;
5465
5560
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5466
5561
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5562
+ logger: Logger;
5563
+ writer: WorkflowStreamWriter;
5467
5564
  }) => Promise<z.infer<OS>>;
5468
5565
  id: string;
5469
5566
  name?: string;
@@ -5488,6 +5585,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5488
5585
  } | undefined;
5489
5586
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5490
5587
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5588
+ logger: Logger;
5589
+ writer: WorkflowStreamWriter;
5491
5590
  }) => Promise<NEW_DATA>;
5492
5591
  id: string;
5493
5592
  name?: string;
@@ -5512,6 +5611,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5512
5611
  } | undefined;
5513
5612
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5514
5613
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5614
+ logger: Logger;
5615
+ writer: WorkflowStreamWriter;
5515
5616
  }) => Promise<z.infer<OS>>;
5516
5617
  id: string;
5517
5618
  name?: string;
@@ -5536,6 +5637,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5536
5637
  } | undefined;
5537
5638
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5538
5639
  resumeData?: z.infer<RS>;
5640
+ logger: Logger;
5641
+ writer: WorkflowStreamWriter;
5539
5642
  }) => Promise<NEW_DATA>;
5540
5643
  id: string;
5541
5644
  name?: string;
@@ -5576,6 +5679,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5576
5679
  } | undefined;
5577
5680
  suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5578
5681
  resumeData?: z.infer<RESUME_SCHEMA>;
5682
+ logger: Logger;
5683
+ writer: WorkflowStreamWriter;
5579
5684
  }) => Promise<NEW_DATA>;
5580
5685
  id: string;
5581
5686
  name?: string;
@@ -5604,6 +5709,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5604
5709
  } | undefined;
5605
5710
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5606
5711
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5712
+ logger: Logger;
5713
+ writer: WorkflowStreamWriter;
5607
5714
  }) => Promise<boolean>;
5608
5715
  }): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<OS> | z.infer<IS>, SUSPEND_SCHEMA, RESUME_SCHEMA>;
5609
5716
  /**
@@ -5663,6 +5770,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5663
5770
  } | undefined;
5664
5771
  suspend: (reason?: string, suspendData?: SS extends z.ZodTypeAny ? z.infer<SS> : z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5665
5772
  resumeData?: RS extends z.ZodTypeAny ? z.infer<RS> : z.infer<RESUME_SCHEMA>;
5773
+ logger: Logger;
5774
+ writer: WorkflowStreamWriter;
5666
5775
  }) => Promise<void>;
5667
5776
  id: string;
5668
5777
  name?: string;
@@ -5702,6 +5811,8 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
5702
5811
  } | undefined;
5703
5812
  suspend: (reason?: string, suspendData?: z.infer<SUSPEND_SCHEMA>) => Promise<never>;
5704
5813
  resumeData?: z.infer<RESUME_SCHEMA>;
5814
+ logger: Logger;
5815
+ writer: WorkflowStreamWriter;
5705
5816
  }) => Promise<void>;
5706
5817
  id: string;
5707
5818
  name?: string;
@@ -6130,6 +6241,8 @@ declare class WorkflowRegistry extends EventEmitter {
6130
6241
  endAt: Date;
6131
6242
  status: "completed" | "suspended" | "error";
6132
6243
  result: any;
6244
+ stream: AsyncIterableIterator<WorkflowStreamEvent>;
6245
+ usage: UsageInfo;
6133
6246
  suspension?: any;
6134
6247
  error?: unknown;
6135
6248
  } | null>;