@voltagent/core 2.3.0 → 2.3.1

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
@@ -8697,6 +8697,230 @@ declare class Agent {
8697
8697
  private createWorkingMemoryTools;
8698
8698
  }
8699
8699
 
8700
+ /**
8701
+ * WorkflowTraceContext - Manages trace hierarchy and common attributes for workflows
8702
+ *
8703
+ * Similar to AgentTraceContext but tailored for workflow execution:
8704
+ * 1. Common attributes (workflowId, executionId, userId, etc.) are set once and inherited
8705
+ * 2. Parent-child span relationships for workflow steps
8706
+ * 3. Support for parallel step execution
8707
+ * 4. Suspend/resume state tracking
8708
+ * 5. Clean integration with VoltAgentObservability
8709
+ */
8710
+
8711
+ interface WorkflowTraceContextOptions {
8712
+ workflowId: string;
8713
+ workflowName: string;
8714
+ executionId: string;
8715
+ userId?: string;
8716
+ conversationId?: string;
8717
+ parentSpan?: Span;
8718
+ input?: any;
8719
+ context?: Map<string | symbol, unknown>;
8720
+ resumedFrom?: {
8721
+ traceId: string;
8722
+ spanId: string;
8723
+ };
8724
+ }
8725
+ declare class WorkflowTraceContext {
8726
+ private rootSpan;
8727
+ private tracer;
8728
+ private commonAttributes;
8729
+ private activeContext;
8730
+ private stepSpans;
8731
+ constructor(observability: VoltAgentObservability, operationName: string, options: WorkflowTraceContextOptions);
8732
+ /**
8733
+ * Create a child span for a workflow step
8734
+ */
8735
+ createStepSpan(stepIndex: number, stepType: string, stepName: string, options?: {
8736
+ stepId?: string;
8737
+ parentStepId?: string;
8738
+ parallelIndex?: number;
8739
+ input?: any;
8740
+ attributes?: Record<string, any>;
8741
+ }): Span;
8742
+ /**
8743
+ * Create spans for parallel steps
8744
+ */
8745
+ createParallelStepSpans(parentStepIndex: number, parentStepType: string, parentStepName: string, parallelSteps: Array<{
8746
+ index: number;
8747
+ type: string;
8748
+ name: string;
8749
+ id?: string;
8750
+ }>): {
8751
+ parentSpan: Span;
8752
+ childSpans: Span[];
8753
+ };
8754
+ /**
8755
+ * Create a generic child span under the workflow root or an optional parent span
8756
+ */
8757
+ createChildSpan(name: string, type: string, options?: {
8758
+ label?: string;
8759
+ attributes?: Record<string, any>;
8760
+ kind?: SpanKind$1;
8761
+ parentSpan?: Span;
8762
+ }): Span;
8763
+ /**
8764
+ * Record a suspension event on the workflow
8765
+ */
8766
+ recordSuspension(stepIndex: number, reason: string, suspendData?: any, checkpoint?: any): void;
8767
+ /**
8768
+ * Record a cancellation event on the workflow
8769
+ */
8770
+ recordCancellation(reason?: string): void;
8771
+ /**
8772
+ * Record a resume event on the workflow
8773
+ */
8774
+ recordResume(stepIndex: number, resumeData?: any): void;
8775
+ /**
8776
+ * Execute a function within a span's context
8777
+ */
8778
+ withSpan<T>(span: Span, fn: () => T | Promise<T>): Promise<T>;
8779
+ /**
8780
+ * Get the root span
8781
+ */
8782
+ getRootSpan(): Span;
8783
+ /**
8784
+ * Set input on the root span
8785
+ */
8786
+ setInput(input: any): void;
8787
+ /**
8788
+ * Set output on the root span
8789
+ */
8790
+ setOutput(output: any): void;
8791
+ /**
8792
+ * Set usage information on the root span
8793
+ */
8794
+ setUsage(usage: any): void;
8795
+ /**
8796
+ * End the root span with a status
8797
+ */
8798
+ end(status: "completed" | "suspended" | "cancelled" | "error", error?: Error | any): void;
8799
+ /**
8800
+ * End a step span with proper status
8801
+ */
8802
+ endStepSpan(span: Span, status: "completed" | "skipped" | "suspended" | "cancelled" | "error", options?: {
8803
+ output?: any;
8804
+ error?: Error | any;
8805
+ attributes?: Record<string, any>;
8806
+ skippedReason?: string;
8807
+ suspensionReason?: string;
8808
+ cancellationReason?: string;
8809
+ }): void;
8810
+ /**
8811
+ * Get the active context for manual context propagation
8812
+ */
8813
+ getActiveContext(): Context;
8814
+ /**
8815
+ * Update active context with a new span
8816
+ */
8817
+ updateActiveContext(span: Span): void;
8818
+ /**
8819
+ * Clear step spans (useful for cleanup after parallel execution)
8820
+ */
8821
+ clearStepSpans(): void;
8822
+ }
8823
+
8824
+ /**
8825
+ * Context information for a workflow execution
8826
+ * Contains all the runtime information about a workflow execution
8827
+ */
8828
+ interface WorkflowExecutionContext {
8829
+ /**
8830
+ * Unique identifier for the workflow definition
8831
+ */
8832
+ workflowId: string;
8833
+ /**
8834
+ * Unique identifier for this specific execution
8835
+ */
8836
+ executionId: string;
8837
+ /**
8838
+ * Human-readable name of the workflow
8839
+ */
8840
+ workflowName: string;
8841
+ /**
8842
+ * User-defined context passed around during execution
8843
+ */
8844
+ context: Map<string | symbol, unknown>;
8845
+ /**
8846
+ * Shared workflow state available to all steps
8847
+ */
8848
+ workflowState: WorkflowStateStore;
8849
+ /**
8850
+ * Whether the workflow is still actively running
8851
+ */
8852
+ isActive: boolean;
8853
+ /**
8854
+ * When the workflow execution started
8855
+ */
8856
+ startTime: Date;
8857
+ /**
8858
+ * Current step index being executed
8859
+ */
8860
+ currentStepIndex: number;
8861
+ /**
8862
+ * Array of completed steps (for tracking)
8863
+ */
8864
+ steps: any[];
8865
+ /**
8866
+ * AbortSignal for cancelling the workflow
8867
+ */
8868
+ signal?: AbortSignal;
8869
+ /**
8870
+ * Memory storage instance for this workflow execution
8871
+ * Can be workflow-specific or global
8872
+ */
8873
+ memory?: Memory;
8874
+ /**
8875
+ * Map of executed step data (input and output) by step ID
8876
+ * Used for accessing previous step results
8877
+ */
8878
+ stepData: Map<string, WorkflowStepData>;
8879
+ /**
8880
+ * Current event sequence number for this workflow execution
8881
+ * Used to maintain event ordering even after server restarts
8882
+ */
8883
+ eventSequence: number;
8884
+ /**
8885
+ * Logger instance for this workflow execution
8886
+ * Provides execution-scoped logging with full context (userId, conversationId, executionId)
8887
+ */
8888
+ logger: Logger;
8889
+ /**
8890
+ * Stream writer for emitting events during streaming execution
8891
+ * Always available - uses NoOpWorkflowStreamWriter when not streaming
8892
+ */
8893
+ streamWriter: WorkflowStreamWriter;
8894
+ /**
8895
+ * OpenTelemetry trace context for observability
8896
+ * Manages span hierarchy and attributes for the workflow execution
8897
+ */
8898
+ traceContext?: WorkflowTraceContext;
8899
+ /**
8900
+ * Optional agent instance supplied to workflow guardrails
8901
+ */
8902
+ guardrailAgent?: Agent;
8903
+ /**
8904
+ * Current step span for passing to agents called within workflow steps
8905
+ * This enables agent spans to appear as children of workflow step spans
8906
+ */
8907
+ currentStepSpan?: Span;
8908
+ }
8909
+ /**
8910
+ * Workflow step context for individual step tracking
8911
+ */
8912
+ interface WorkflowStepContext {
8913
+ stepId: string;
8914
+ stepIndex: number;
8915
+ stepType: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow" | "guardrail" | "sleep" | "sleep-until" | "foreach" | "loop" | "branch" | "map";
8916
+ stepName: string;
8917
+ workflowId: string;
8918
+ executionId: string;
8919
+ parentStepId?: string;
8920
+ parallelIndex?: number;
8921
+ startTime: Date;
8922
+ }
8923
+
8700
8924
  type WorkflowStateStatus = "pending" | "running" | "completed" | "failed" | "suspended" | "cancelled";
8701
8925
  type WorkflowState<INPUT, RESULT> = {
8702
8926
  executionId: string;
@@ -9367,252 +9591,18 @@ type WorkflowStepState<INPUT> = Omit<WorkflowState<INPUT, DangerouslyAllowAny>,
9367
9591
  signal?: AbortSignal;
9368
9592
  };
9369
9593
 
9370
- /**
9371
- * WorkflowTraceContext - Manages trace hierarchy and common attributes for workflows
9372
- *
9373
- * Similar to AgentTraceContext but tailored for workflow execution:
9374
- * 1. Common attributes (workflowId, executionId, userId, etc.) are set once and inherited
9375
- * 2. Parent-child span relationships for workflow steps
9376
- * 3. Support for parallel step execution
9377
- * 4. Suspend/resume state tracking
9378
- * 5. Clean integration with VoltAgentObservability
9379
- */
9380
-
9381
- interface WorkflowTraceContextOptions {
9382
- workflowId: string;
9383
- workflowName: string;
9384
- executionId: string;
9385
- userId?: string;
9386
- conversationId?: string;
9387
- parentSpan?: Span;
9388
- input?: any;
9389
- context?: Map<string | symbol, unknown>;
9390
- resumedFrom?: {
9391
- traceId: string;
9392
- spanId: string;
9393
- };
9394
- }
9395
- declare class WorkflowTraceContext {
9396
- private rootSpan;
9397
- private tracer;
9398
- private commonAttributes;
9399
- private activeContext;
9400
- private stepSpans;
9401
- constructor(observability: VoltAgentObservability, operationName: string, options: WorkflowTraceContextOptions);
9402
- /**
9403
- * Create a child span for a workflow step
9404
- */
9405
- createStepSpan(stepIndex: number, stepType: string, stepName: string, options?: {
9406
- stepId?: string;
9407
- parentStepId?: string;
9408
- parallelIndex?: number;
9409
- input?: any;
9410
- attributes?: Record<string, any>;
9411
- }): Span;
9412
- /**
9413
- * Create spans for parallel steps
9414
- */
9415
- createParallelStepSpans(parentStepIndex: number, parentStepType: string, parentStepName: string, parallelSteps: Array<{
9416
- index: number;
9417
- type: string;
9418
- name: string;
9419
- id?: string;
9420
- }>): {
9421
- parentSpan: Span;
9422
- childSpans: Span[];
9423
- };
9424
- /**
9425
- * Create a generic child span under the workflow root or an optional parent span
9426
- */
9427
- createChildSpan(name: string, type: string, options?: {
9428
- label?: string;
9429
- attributes?: Record<string, any>;
9430
- kind?: SpanKind$1;
9431
- parentSpan?: Span;
9432
- }): Span;
9433
- /**
9434
- * Record a suspension event on the workflow
9435
- */
9436
- recordSuspension(stepIndex: number, reason: string, suspendData?: any, checkpoint?: any): void;
9437
- /**
9438
- * Record a cancellation event on the workflow
9439
- */
9440
- recordCancellation(reason?: string): void;
9441
- /**
9442
- * Record a resume event on the workflow
9443
- */
9444
- recordResume(stepIndex: number, resumeData?: any): void;
9445
- /**
9446
- * Execute a function within a span's context
9447
- */
9448
- withSpan<T>(span: Span, fn: () => T | Promise<T>): Promise<T>;
9449
- /**
9450
- * Get the root span
9451
- */
9452
- getRootSpan(): Span;
9453
- /**
9454
- * Set input on the root span
9455
- */
9456
- setInput(input: any): void;
9457
- /**
9458
- * Set output on the root span
9459
- */
9460
- setOutput(output: any): void;
9461
- /**
9462
- * Set usage information on the root span
9463
- */
9464
- setUsage(usage: any): void;
9465
- /**
9466
- * End the root span with a status
9467
- */
9468
- end(status: "completed" | "suspended" | "cancelled" | "error", error?: Error | any): void;
9469
- /**
9470
- * End a step span with proper status
9471
- */
9472
- endStepSpan(span: Span, status: "completed" | "skipped" | "suspended" | "cancelled" | "error", options?: {
9473
- output?: any;
9474
- error?: Error | any;
9475
- attributes?: Record<string, any>;
9476
- skippedReason?: string;
9477
- suspensionReason?: string;
9478
- cancellationReason?: string;
9479
- }): void;
9480
- /**
9481
- * Get the active context for manual context propagation
9482
- */
9483
- getActiveContext(): Context;
9484
- /**
9485
- * Update active context with a new span
9486
- */
9487
- updateActiveContext(span: Span): void;
9488
- /**
9489
- * Clear step spans (useful for cleanup after parallel execution)
9490
- */
9491
- clearStepSpans(): void;
9492
- }
9493
-
9494
- /**
9495
- * Context information for a workflow execution
9496
- * Contains all the runtime information about a workflow execution
9497
- */
9498
- interface WorkflowExecutionContext {
9499
- /**
9500
- * Unique identifier for the workflow definition
9501
- */
9502
- workflowId: string;
9503
- /**
9504
- * Unique identifier for this specific execution
9505
- */
9506
- executionId: string;
9507
- /**
9508
- * Human-readable name of the workflow
9509
- */
9510
- workflowName: string;
9511
- /**
9512
- * User-defined context passed around during execution
9513
- */
9514
- context: Map<string | symbol, unknown>;
9515
- /**
9516
- * Shared workflow state available to all steps
9517
- */
9518
- workflowState: WorkflowStateStore;
9519
- /**
9520
- * Whether the workflow is still actively running
9521
- */
9522
- isActive: boolean;
9523
- /**
9524
- * When the workflow execution started
9525
- */
9526
- startTime: Date;
9527
- /**
9528
- * Current step index being executed
9529
- */
9530
- currentStepIndex: number;
9531
- /**
9532
- * Array of completed steps (for tracking)
9533
- */
9534
- steps: any[];
9535
- /**
9536
- * AbortSignal for cancelling the workflow
9537
- */
9538
- signal?: AbortSignal;
9539
- /**
9540
- * Memory storage instance for this workflow execution
9541
- * Can be workflow-specific or global
9542
- */
9543
- memory?: Memory;
9544
- /**
9545
- * Map of executed step data (input and output) by step ID
9546
- * Used for accessing previous step results
9547
- */
9548
- stepData: Map<string, WorkflowStepData>;
9549
- /**
9550
- * Current event sequence number for this workflow execution
9551
- * Used to maintain event ordering even after server restarts
9552
- */
9553
- eventSequence: number;
9554
- /**
9555
- * Logger instance for this workflow execution
9556
- * Provides execution-scoped logging with full context (userId, conversationId, executionId)
9557
- */
9558
- logger: Logger;
9559
- /**
9560
- * Stream writer for emitting events during streaming execution
9561
- * Always available - uses NoOpWorkflowStreamWriter when not streaming
9562
- */
9563
- streamWriter: WorkflowStreamWriter;
9564
- /**
9565
- * OpenTelemetry trace context for observability
9566
- * Manages span hierarchy and attributes for the workflow execution
9567
- */
9568
- traceContext?: WorkflowTraceContext;
9569
- /**
9570
- * Optional agent instance supplied to workflow guardrails
9571
- */
9572
- guardrailAgent?: Agent;
9573
- /**
9574
- * Current step span for passing to agents called within workflow steps
9575
- * This enables agent spans to appear as children of workflow step spans
9576
- */
9577
- currentStepSpan?: Span;
9578
- }
9579
- /**
9580
- * Workflow step context for individual step tracking
9581
- */
9582
- interface WorkflowStepContext {
9583
- stepId: string;
9584
- stepIndex: number;
9585
- stepType: "agent" | "func" | "conditional-when" | "parallel-all" | "parallel-race" | "tap" | "workflow" | "guardrail" | "sleep" | "sleep-until" | "foreach" | "loop" | "branch" | "map";
9586
- stepName: string;
9587
- workflowId: string;
9588
- executionId: string;
9589
- parentStepId?: string;
9590
- parallelIndex?: number;
9591
- startTime: Date;
9592
- }
9593
-
9594
9594
  /**
9595
9595
  * The base input type for the workflow
9596
9596
  * @private - INTERNAL USE ONLY
9597
9597
  */
9598
9598
  type InternalBaseWorkflowInputSchema = z.ZodTypeAny | BaseMessage | BaseMessage[] | UIMessage | UIMessage[] | string;
9599
- /**
9600
- * The state parameter for the workflow, used to pass the state to a step or other function (i.e. hooks)
9601
- * @private - INTERNAL USE ONLY
9602
- */
9603
- type InternalWorkflowStateParam<INPUT> = Omit<WorkflowState<INPUT, DangerouslyAllowAny>, "data" | "result"> & {
9604
- /** Workflow execution context for event tracking */
9605
- workflowContext?: WorkflowExecutionContext;
9606
- /** AbortSignal for checking suspension during step execution */
9607
- signal?: AbortSignal;
9608
- };
9609
9599
  /**
9610
9600
  * Context object for new execute API with helper functions
9611
9601
  * @private - INTERNAL USE ONLY
9612
9602
  */
9613
9603
  interface WorkflowExecuteContext<INPUT, DATA, SUSPEND_DATA, RESUME_DATA> {
9614
9604
  data: DATA;
9615
- state: InternalWorkflowStateParam<INPUT>;
9605
+ state: WorkflowStepState<INPUT>;
9616
9606
  getStepData: (stepId: string) => WorkflowStepData | undefined;
9617
9607
  suspend: (reason?: string, suspendData?: SUSPEND_DATA) => Promise<never>;
9618
9608
  resumeData?: RESUME_DATA;