@voltagent/core 0.1.57 → 0.1.59

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.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import { Span } from '@opentelemetry/api';
3
+ import * as TF from 'type-fest';
3
4
  import { Simplify, LiteralUnion, MergeDeep } from 'type-fest';
4
5
  import { Context } from 'hono';
5
6
  import { SpanExporter } from '@opentelemetry/sdk-trace-base';
7
+ import { DangerouslyAllowAny, PlainObject } from '@voltagent/internal/types';
6
8
  import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
7
9
  import { EventEmitter } from 'node:events';
8
10
 
@@ -1133,6 +1135,64 @@ interface PromptContent {
1133
1135
  };
1134
1136
  }
1135
1137
 
1138
+ interface OnStartHookArgs {
1139
+ agent: Agent<any>;
1140
+ context: OperationContext;
1141
+ }
1142
+ interface OnEndHookArgs {
1143
+ /**
1144
+ * The conversation ID.
1145
+ */
1146
+ conversationId: string;
1147
+ /**
1148
+ * The agent that generated the output.
1149
+ */
1150
+ agent: Agent<any>;
1151
+ /** The standardized successful output object. Undefined on error. */
1152
+ output: AgentOperationOutput | undefined;
1153
+ /** The VoltAgentError object if the operation failed. Undefined on success. */
1154
+ error: VoltAgentError | undefined;
1155
+ /** The complete conversation messages including user input and assistant responses (Vercel AI SDK compatible) */
1156
+ context: OperationContext;
1157
+ }
1158
+ interface OnHandoffHookArgs {
1159
+ agent: Agent<any>;
1160
+ source: Agent<any>;
1161
+ }
1162
+ interface OnToolStartHookArgs {
1163
+ agent: Agent<any>;
1164
+ tool: AgentTool;
1165
+ context: OperationContext;
1166
+ }
1167
+ interface OnToolEndHookArgs {
1168
+ agent: Agent<any>;
1169
+ tool: AgentTool;
1170
+ /** The successful output from the tool. Undefined on error. */
1171
+ output: unknown | undefined;
1172
+ /** The VoltAgentError if the tool execution failed. Undefined on success. */
1173
+ error: VoltAgentError | undefined;
1174
+ context: OperationContext;
1175
+ }
1176
+ type AgentHookOnStart = (args: OnStartHookArgs) => Promise<void> | void;
1177
+ type AgentHookOnEnd = (args: OnEndHookArgs) => Promise<void> | void;
1178
+ type AgentHookOnHandoff = (args: OnHandoffHookArgs) => Promise<void> | void;
1179
+ type AgentHookOnToolStart = (args: OnToolStartHookArgs) => Promise<void> | void;
1180
+ type AgentHookOnToolEnd = (args: OnToolEndHookArgs) => Promise<void> | void;
1181
+ /**
1182
+ * Type definition for agent hooks using single argument objects.
1183
+ */
1184
+ type AgentHooks = {
1185
+ onStart?: AgentHookOnStart;
1186
+ onEnd?: AgentHookOnEnd;
1187
+ onHandoff?: AgentHookOnHandoff;
1188
+ onToolStart?: AgentHookOnToolStart;
1189
+ onToolEnd?: AgentHookOnToolEnd;
1190
+ };
1191
+ /**
1192
+ * Create hooks from an object literal.
1193
+ */
1194
+ declare function createHooks(hooks?: Partial<AgentHooks>): AgentHooks;
1195
+
1136
1196
  /**
1137
1197
  * Enhanced dynamic value for instructions that supports prompt management
1138
1198
  */
@@ -1231,7 +1291,7 @@ type AgentOptions = {
1231
1291
  /**
1232
1292
  * Optional user-defined context to be passed around
1233
1293
  */
1234
- userContext?: Map<string | symbol, unknown>;
1294
+ userContext?: UserContext;
1235
1295
  /**
1236
1296
  * @deprecated Use `voltOpsClient` instead. Will be removed in a future version.
1237
1297
  *
@@ -1352,7 +1412,8 @@ interface CommonGenerateOptions {
1352
1412
  signal?: AbortSignal;
1353
1413
  historyEntryId?: string;
1354
1414
  operationContext?: OperationContext;
1355
- userContext?: Map<string | symbol, unknown>;
1415
+ userContext?: UserContext;
1416
+ hooks?: AgentHooks;
1356
1417
  }
1357
1418
  /**
1358
1419
  * Public-facing generate options for external users
@@ -1575,6 +1636,7 @@ interface VoltAgentError {
1575
1636
  * Providers must pass an error conforming to the VoltAgentError structure.
1576
1637
  */
1577
1638
  type StreamOnErrorCallback = (error: VoltAgentError) => Promise<void> | void;
1639
+ type UserContext = Map<string | symbol, unknown>;
1578
1640
  /**
1579
1641
  * Standardized object structure passed to the onFinish callback
1580
1642
  * when streamText completes successfully.
@@ -1591,7 +1653,7 @@ interface StreamTextFinishResult {
1591
1653
  /** Any warnings generated during the completion (if available). */
1592
1654
  warnings?: unknown[];
1593
1655
  /** User context containing any custom metadata from the operation. */
1594
- userContext?: Map<string | symbol, unknown>;
1656
+ userContext?: UserContext;
1595
1657
  }
1596
1658
  /**
1597
1659
  * Type for the onFinish callback function for streamText.
@@ -1614,7 +1676,7 @@ interface StreamObjectFinishResult<TObject> {
1614
1676
  /** The reason the stream finished (if available). Although less common for object streams. */
1615
1677
  finishReason?: string;
1616
1678
  /** User context containing any custom metadata from the operation. */
1617
- userContext?: Map<string | symbol, unknown>;
1679
+ userContext?: UserContext;
1618
1680
  }
1619
1681
  /**
1620
1682
  * Type for the onFinish callback function for streamObject.
@@ -1636,7 +1698,7 @@ interface StandardizedTextResult {
1636
1698
  /** Warnings (if available from provider). */
1637
1699
  warnings?: unknown[];
1638
1700
  /** User context containing any custom metadata from the operation. */
1639
- userContext?: Map<string | symbol, unknown>;
1701
+ userContext?: UserContext;
1640
1702
  }
1641
1703
  /**
1642
1704
  * Standardized success result structure for generateObject.
@@ -1654,7 +1716,7 @@ interface StandardizedObjectResult<TObject> {
1654
1716
  /** Warnings (if available from provider). */
1655
1717
  warnings?: unknown[];
1656
1718
  /** User context containing any custom metadata from the operation. */
1657
- userContext?: Map<string | symbol, unknown>;
1719
+ userContext?: UserContext;
1658
1720
  }
1659
1721
  /**
1660
1722
  * Unified output type for the onEnd hook, representing the successful result
@@ -1677,7 +1739,7 @@ type GenerateTextResponse<TProvider extends {
1677
1739
  type StreamTextResponse<TProvider extends {
1678
1740
  llm: LLMProvider<any>;
1679
1741
  }> = InferStreamTextResponseFromProvider<TProvider> & {
1680
- userContext?: Map<string | symbol, unknown>;
1742
+ userContext?: UserContext;
1681
1743
  };
1682
1744
  type GenerateObjectResponse<TProvider extends {
1683
1745
  llm: LLMProvider<any>;
@@ -1687,7 +1749,7 @@ type GenerateObjectResponse<TProvider extends {
1687
1749
  type StreamObjectResponse<TProvider extends {
1688
1750
  llm: LLMProvider<any>;
1689
1751
  }, TSchema extends z.ZodType> = InferStreamObjectResponseFromProvider<TProvider, TSchema> & {
1690
- userContext?: Map<string | symbol, unknown>;
1752
+ userContext?: UserContext;
1691
1753
  };
1692
1754
 
1693
1755
  /**
@@ -3088,65 +3150,6 @@ declare abstract class BaseRetriever {
3088
3150
  abstract retrieve(input: string | BaseMessage[], options: RetrieveOptions): Promise<string>;
3089
3151
  }
3090
3152
 
3091
- /**
3092
- * Main VoltOps client class that provides unified access to both
3093
- * telemetry export and prompt management functionality.
3094
- */
3095
- declare class VoltOpsClient implements VoltOpsClient$1 {
3096
- readonly options: VoltOpsClientOptions & {
3097
- baseUrl: string;
3098
- };
3099
- readonly observability?: VoltAgentExporter;
3100
- readonly prompts?: VoltOpsPromptManager;
3101
- constructor(options: VoltOpsClientOptions);
3102
- /**
3103
- * Create a prompt helper for agent instructions
3104
- */
3105
- createPromptHelper(_agentId: string): PromptHelper;
3106
- get exportHistoryEntry(): ((historyEntryData: ExportAgentHistoryPayload) => Promise<{
3107
- historyEntryId: string;
3108
- }>) | undefined;
3109
- get exportHistoryEntryAsync(): ((historyEntryData: ExportAgentHistoryPayload) => void) | undefined;
3110
- get exportTimelineEvent(): ((timelineEventData: ExportTimelineEventPayload) => Promise<{
3111
- timelineEventId: string;
3112
- }>) | undefined;
3113
- get exportTimelineEventAsync(): ((timelineEventData: ExportTimelineEventPayload) => void) | undefined;
3114
- /**
3115
- * Check if observability is enabled and configured
3116
- */
3117
- isObservabilityEnabled(): boolean;
3118
- /**
3119
- * Check if prompt management is enabled and configured
3120
- */
3121
- isPromptManagementEnabled(): boolean;
3122
- /**
3123
- * Get observability exporter for backward compatibility
3124
- * @deprecated Use observability property directly
3125
- */
3126
- getObservabilityExporter(): VoltAgentExporter | undefined;
3127
- /**
3128
- * Get prompt manager for direct access
3129
- */
3130
- getPromptManager(): VoltOpsPromptManager | undefined;
3131
- /**
3132
- * Static method to create prompt helper with priority-based fallback
3133
- * Priority: Agent VoltOpsClient > Global VoltOpsClient > Fallback instructions
3134
- */
3135
- static createPromptHelperWithFallback(agentId: string, agentName: string, fallbackInstructions: string, agentVoltOpsClient?: VoltOpsClient): PromptHelper;
3136
- /**
3137
- * Validate API keys and provide helpful error messages
3138
- */
3139
- private validateApiKeys;
3140
- /**
3141
- * Cleanup resources when client is no longer needed
3142
- */
3143
- dispose(): Promise<void>;
3144
- }
3145
- /**
3146
- * Factory function to create VoltOps client
3147
- */
3148
- declare const createVoltOpsClient: (options: VoltOpsClientOptions) => VoltOpsClient;
3149
-
3150
3153
  /**
3151
3154
  * ReadableStream type for voice responses
3152
3155
  */
@@ -3255,63 +3258,64 @@ type Voice = {
3255
3258
  getVoices(): Promise<VoiceMetadata[]>;
3256
3259
  };
3257
3260
 
3258
- interface OnStartHookArgs {
3259
- agent: Agent<any>;
3260
- context: OperationContext;
3261
- }
3262
- interface OnEndHookArgs {
3261
+ /**
3262
+ * Main VoltOps client class that provides unified access to both
3263
+ * telemetry export and prompt management functionality.
3264
+ */
3265
+ declare class VoltOpsClient implements VoltOpsClient$1 {
3266
+ readonly options: VoltOpsClientOptions & {
3267
+ baseUrl: string;
3268
+ };
3269
+ readonly observability?: VoltAgentExporter;
3270
+ readonly prompts?: VoltOpsPromptManager;
3271
+ constructor(options: VoltOpsClientOptions);
3263
3272
  /**
3264
- * The conversation ID.
3273
+ * Create a prompt helper for agent instructions
3265
3274
  */
3266
- conversationId: string;
3275
+ createPromptHelper(_agentId: string): PromptHelper;
3276
+ get exportHistoryEntry(): ((historyEntryData: ExportAgentHistoryPayload) => Promise<{
3277
+ historyEntryId: string;
3278
+ }>) | undefined;
3279
+ get exportHistoryEntryAsync(): ((historyEntryData: ExportAgentHistoryPayload) => void) | undefined;
3280
+ get exportTimelineEvent(): ((timelineEventData: ExportTimelineEventPayload) => Promise<{
3281
+ timelineEventId: string;
3282
+ }>) | undefined;
3283
+ get exportTimelineEventAsync(): ((timelineEventData: ExportTimelineEventPayload) => void) | undefined;
3267
3284
  /**
3268
- * The agent that generated the output.
3285
+ * Check if observability is enabled and configured
3269
3286
  */
3270
- agent: Agent<any>;
3271
- /** The standardized successful output object. Undefined on error. */
3272
- output: AgentOperationOutput | undefined;
3273
- /** The VoltAgentError object if the operation failed. Undefined on success. */
3274
- error: VoltAgentError | undefined;
3275
- /** The complete conversation messages including user input and assistant responses (Vercel AI SDK compatible) */
3276
- context: OperationContext;
3277
- }
3278
- interface OnHandoffHookArgs {
3279
- agent: Agent<any>;
3280
- source: Agent<any>;
3281
- }
3282
- interface OnToolStartHookArgs {
3283
- agent: Agent<any>;
3284
- tool: AgentTool;
3285
- context: OperationContext;
3286
- }
3287
- interface OnToolEndHookArgs {
3288
- agent: Agent<any>;
3289
- tool: AgentTool;
3290
- /** The successful output from the tool. Undefined on error. */
3291
- output: unknown | undefined;
3292
- /** The VoltAgentError if the tool execution failed. Undefined on success. */
3293
- error: VoltAgentError | undefined;
3294
- context: OperationContext;
3287
+ isObservabilityEnabled(): boolean;
3288
+ /**
3289
+ * Check if prompt management is enabled and configured
3290
+ */
3291
+ isPromptManagementEnabled(): boolean;
3292
+ /**
3293
+ * Get observability exporter for backward compatibility
3294
+ * @deprecated Use observability property directly
3295
+ */
3296
+ getObservabilityExporter(): VoltAgentExporter | undefined;
3297
+ /**
3298
+ * Get prompt manager for direct access
3299
+ */
3300
+ getPromptManager(): VoltOpsPromptManager | undefined;
3301
+ /**
3302
+ * Static method to create prompt helper with priority-based fallback
3303
+ * Priority: Agent VoltOpsClient > Global VoltOpsClient > Fallback instructions
3304
+ */
3305
+ static createPromptHelperWithFallback(agentId: string, agentName: string, fallbackInstructions: string, agentVoltOpsClient?: VoltOpsClient): PromptHelper;
3306
+ /**
3307
+ * Validate API keys and provide helpful error messages
3308
+ */
3309
+ private validateApiKeys;
3310
+ /**
3311
+ * Cleanup resources when client is no longer needed
3312
+ */
3313
+ dispose(): Promise<void>;
3295
3314
  }
3296
- type AgentHookOnStart = (args: OnStartHookArgs) => Promise<void> | void;
3297
- type AgentHookOnEnd = (args: OnEndHookArgs) => Promise<void> | void;
3298
- type AgentHookOnHandoff = (args: OnHandoffHookArgs) => Promise<void> | void;
3299
- type AgentHookOnToolStart = (args: OnToolStartHookArgs) => Promise<void> | void;
3300
- type AgentHookOnToolEnd = (args: OnToolEndHookArgs) => Promise<void> | void;
3301
3315
  /**
3302
- * Type definition for agent hooks using single argument objects.
3303
- */
3304
- type AgentHooks = {
3305
- onStart?: AgentHookOnStart;
3306
- onEnd?: AgentHookOnEnd;
3307
- onHandoff?: AgentHookOnHandoff;
3308
- onToolStart?: AgentHookOnToolStart;
3309
- onToolEnd?: AgentHookOnToolEnd;
3310
- };
3311
- /**
3312
- * Create hooks from an object literal.
3316
+ * Factory function to create VoltOps client
3313
3317
  */
3314
- declare function createHooks(hooks?: Partial<AgentHooks>): AgentHooks;
3318
+ declare const createVoltOpsClient: (options: VoltOpsClientOptions) => VoltOpsClient;
3315
3319
 
3316
3320
  /**
3317
3321
  * SubAgentManager - Manages sub-agents and delegation functionality for an Agent
@@ -3707,6 +3711,12 @@ declare class Agent<TProvider extends {
3707
3711
  * This is typically called by the main VoltAgent instance after it has initialized its exporter.
3708
3712
  */
3709
3713
  _INTERNAL_setVoltAgentExporter(exporter: VoltAgentExporter): void;
3714
+ /**
3715
+ * Helper method to merge the agent's hooks with the ones passed in the options
3716
+ * @param options - The options passed to the generate method
3717
+ * @returns The merged hooks
3718
+ */
3719
+ private getMergedHooks;
3710
3720
  /**
3711
3721
  * Helper method to get retriever context with event handling
3712
3722
  */
@@ -3822,6 +3832,771 @@ type VoltAgentOptions = {
3822
3832
  enableSwaggerUI?: boolean;
3823
3833
  };
3824
3834
 
3835
+ interface WorkflowRunOptions {
3836
+ /**
3837
+ * The active step, this can be used to track the current step in a workflow
3838
+ * @default 0
3839
+ */
3840
+ active?: number;
3841
+ /**
3842
+ * The execution ID, this can be used to track the current execution in a workflow
3843
+ * @default uuidv4
3844
+ */
3845
+ executionId?: string;
3846
+ /**
3847
+ * The conversation ID, this can be used to track the current conversation in a workflow
3848
+ */
3849
+ conversationId?: string;
3850
+ /**
3851
+ * The user ID, this can be used to track the current user in a workflow
3852
+ */
3853
+ userId?: string;
3854
+ /**
3855
+ * The user context, this can be used to track the current user context in a workflow
3856
+ */
3857
+ userContext?: UserContext;
3858
+ }
3859
+ /**
3860
+ * Hooks for the workflow
3861
+ * @param DATA - The type of the data
3862
+ * @param RESULT - The type of the result
3863
+ */
3864
+ type WorkflowHooks<DATA, RESULT> = {
3865
+ /**
3866
+ * Called when the workflow starts
3867
+ * @param state - The current state of the workflow
3868
+ * @returns void
3869
+ */
3870
+ onStart?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
3871
+ /**
3872
+ * Called when a step starts
3873
+ * @param state - The current state of the workflow
3874
+ * @returns void
3875
+ */
3876
+ onStepStart?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
3877
+ /**
3878
+ * Called when a step ends
3879
+ * @param state - The current state of the workflow
3880
+ * @returns void
3881
+ */
3882
+ onStepEnd?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
3883
+ /**
3884
+ * Called when the workflow ends
3885
+ * @param state - The current state of the workflow
3886
+ * @returns void
3887
+ */
3888
+ onEnd?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
3889
+ };
3890
+ type WorkflowInput<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema> = TF.IsUnknown<INPUT_SCHEMA> extends true ? BaseMessage | BaseMessage[] | string : INPUT_SCHEMA extends z.ZodTypeAny ? z.infer<INPUT_SCHEMA> : undefined;
3891
+ type WorkflowResult<RESULT_SCHEMA extends z.ZodTypeAny> = RESULT_SCHEMA extends z.ZodTypeAny ? z.infer<RESULT_SCHEMA> : RESULT_SCHEMA;
3892
+ type WorkflowConfig<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny> = {
3893
+ /**
3894
+ * Unique identifier for the workflow
3895
+ */
3896
+ id: string;
3897
+ /**
3898
+ * Human-readable name for the workflow
3899
+ */
3900
+ name: string;
3901
+ /**
3902
+ * Description of what the workflow does
3903
+ */
3904
+ purpose?: string;
3905
+ /**
3906
+ * Schema for the input data
3907
+ */
3908
+ input?: INPUT_SCHEMA;
3909
+ /**
3910
+ * Schema for the result data
3911
+ */
3912
+ result: RESULT_SCHEMA;
3913
+ /**
3914
+ * Hooks for the workflow
3915
+ */
3916
+ hooks?: WorkflowHooks<WorkflowInput<INPUT_SCHEMA>, WorkflowResult<RESULT_SCHEMA>>;
3917
+ };
3918
+ /**
3919
+ * A workflow instance that can be executed
3920
+ */
3921
+ type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny> = {
3922
+ /**
3923
+ * Unique identifier for the workflow
3924
+ */
3925
+ id: string;
3926
+ /**
3927
+ * Human-readable name for the workflow
3928
+ */
3929
+ name: string;
3930
+ /**
3931
+ * Description of what the workflow does
3932
+ * @default "No purpose provided"
3933
+ */
3934
+ purpose: string;
3935
+ /**
3936
+ * Array of steps to execute in order
3937
+ */
3938
+ steps: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, DangerouslyAllowAny, DangerouslyAllowAny>[];
3939
+ /**
3940
+ * Execute the workflow with the given input
3941
+ * @param input - The input to the workflow
3942
+ * @returns The result of the workflow
3943
+ */
3944
+ run: (input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions) => Promise<{
3945
+ executionId: string;
3946
+ startAt: Date;
3947
+ endAt: Date;
3948
+ status: "completed";
3949
+ result: z.infer<RESULT_SCHEMA>;
3950
+ }>;
3951
+ };
3952
+
3953
+ type WorkflowStateStatus = "pending" | "running" | "completed" | "failed";
3954
+ type WorkflowState<INPUT, RESULT> = {
3955
+ executionId: string;
3956
+ conversationId?: string;
3957
+ userId?: string;
3958
+ userContext?: UserContext;
3959
+ active: number;
3960
+ startAt: Date;
3961
+ endAt: Date | null;
3962
+ status: WorkflowStateStatus;
3963
+ /** the initial input data to the workflow */
3964
+ input: InternalExtractWorkflowInputData<INPUT>;
3965
+ /** current data being processed */
3966
+ data: DangerouslyAllowAny;
3967
+ /** the result of workflow execution, null until execution is complete */
3968
+ result: RESULT | null;
3969
+ error: Error | null;
3970
+ };
3971
+
3972
+ /**
3973
+ * The base input type for the workflow
3974
+ * @private - INTERNAL USE ONLY
3975
+ */
3976
+ type InternalBaseWorkflowInputSchema = z.ZodTypeAny | BaseMessage | BaseMessage[] | string;
3977
+ /**
3978
+ * The state parameter for the workflow, used to pass the state to a step or other function (i.e. hooks)
3979
+ * @private - INTERNAL USE ONLY
3980
+ */
3981
+ type InternalWorkflowStateParam<INPUT> = Omit<WorkflowState<INPUT, DangerouslyAllowAny>, "data" | "result">;
3982
+ /**
3983
+ * A function that can be executed by the workflow
3984
+ * @private - INTERNAL USE ONLY
3985
+ */
3986
+ type InternalWorkflowFunc<INPUT, DATA, RESULT> = (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT>;
3987
+ type InternalWorkflowStepConfig<T extends PlainObject = PlainObject> = {
3988
+ /**
3989
+ * Unique identifier for the step
3990
+ * @default uuidv4
3991
+ */
3992
+ id?: string;
3993
+ /**
3994
+ * Human-readable name for the step
3995
+ */
3996
+ name?: string;
3997
+ /**
3998
+ * Description of what the step does
3999
+ */
4000
+ purpose?: string;
4001
+ } & T;
4002
+ /**
4003
+ * Base step interface for building new steps
4004
+ * @private - INTERNAL USE ONLY
4005
+ */
4006
+ interface InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
4007
+ /**
4008
+ * Unique identifier for the step
4009
+ */
4010
+ id: string;
4011
+ /**
4012
+ * Human-readable name for the step
4013
+ */
4014
+ name: string | null;
4015
+ /**
4016
+ * Description of what the step does
4017
+ */
4018
+ purpose: string | null;
4019
+ /**
4020
+ * Type identifier for the step
4021
+ */
4022
+ type: string;
4023
+ /**
4024
+ * Execute the step with the given data
4025
+ * @param data - The data to execute the step with
4026
+ * @param state - The state of the workflow
4027
+ * @returns The result of the step
4028
+ */
4029
+ execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT>;
4030
+ }
4031
+ /**
4032
+ * Any step that can be accepted by the workflow
4033
+ * @private - INTERNAL USE ONLY
4034
+ */
4035
+ type InternalAnyWorkflowStep<INPUT, DATA = DangerouslyAllowAny, RESULT = DangerouslyAllowAny> = InternalBaseWorkflowStep<INPUT, DATA, RESULT> | Omit<InternalBaseWorkflowStep<INPUT, DATA, RESULT>, "type">;
4036
+ /**
4037
+ * Infer the result type from a list of steps
4038
+ * @private - INTERNAL USE ONLY
4039
+ */
4040
+ type InternalInferWorkflowStepsResult<STEPS extends ReadonlyArray<InternalAnyWorkflowStep<DangerouslyAllowAny, DangerouslyAllowAny, DangerouslyAllowAny>>> = {
4041
+ [K in keyof STEPS]: Awaited<ReturnType<STEPS[K]["execute"]>>;
4042
+ };
4043
+ type InternalExtractWorkflowInputData<T> = TF.IsUnknown<T> extends true ? BaseMessage | BaseMessage[] | string : TF.IsAny<T> extends true ? BaseMessage | BaseMessage[] | string : T extends z.ZodType ? z.infer<T> : T;
4044
+
4045
+ type AgentConfig$1<SCHEMA extends z.ZodTypeAny> = PublicGenerateOptions & {
4046
+ schema: SCHEMA;
4047
+ };
4048
+ /**
4049
+ * Creates an agent step for a workflow
4050
+ *
4051
+ * @example
4052
+ * ```ts
4053
+ * const w = createWorkflow(
4054
+ * andAgent(
4055
+ * (data) => `Generate a greeting for the user ${data.name}`,
4056
+ * agent,
4057
+ * { schema: z.object({ greeting: z.string() }) }
4058
+ * ),
4059
+ * andThen(async (data) => data.greeting)
4060
+ * );
4061
+ * ```
4062
+ *
4063
+ * @param task - The task (prompt) to execute for the agent, can be a string or a function that returns a string
4064
+ * @param agent - The agent to execute the task using `generateObject`
4065
+ * @param config - The config for the agent (schema) `generateObject` call
4066
+ * @returns A workflow step that executes the agent with the task
4067
+ */
4068
+ declare function andAgent<INPUT, DATA, SCHEMA extends z.ZodTypeAny>(task: BaseMessage[] | string | InternalWorkflowFunc<INPUT, DATA, BaseMessage[] | string>, agent: Agent<{
4069
+ llm: DangerouslyAllowAny;
4070
+ }>, config: AgentConfig$1<SCHEMA>): {
4071
+ type: "agent";
4072
+ id: string;
4073
+ name: string;
4074
+ purpose: string | null;
4075
+ agent: Agent<{
4076
+ llm: DangerouslyAllowAny;
4077
+ }>;
4078
+ execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<z.TypeOf<SCHEMA>>;
4079
+ };
4080
+
4081
+ interface WorkflowStepAgent<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
4082
+ type: "agent";
4083
+ agent: Agent<{
4084
+ llm: DangerouslyAllowAny;
4085
+ }>;
4086
+ }
4087
+ type WorkflowStepFuncConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
4088
+ execute: InternalWorkflowFunc<INPUT, DATA, RESULT>;
4089
+ }>;
4090
+ interface WorkflowStepFunc<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
4091
+ type: "func";
4092
+ }
4093
+ type WorkflowStepTapConfig<INPUT, DATA, _RESULT> = InternalWorkflowStepConfig<{
4094
+ execute: InternalWorkflowFunc<INPUT, DATA, DangerouslyAllowAny>;
4095
+ }>;
4096
+ interface WorkflowStepTap<INPUT, DATA, _RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, DATA> {
4097
+ type: "tap";
4098
+ }
4099
+ type WorkflowStepConditionalWhenConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
4100
+ condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
4101
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
4102
+ }>;
4103
+ interface WorkflowStepConditionalWhen<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, InternalExtractWorkflowInputData<DATA> | RESULT> {
4104
+ type: "conditional-when";
4105
+ condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
4106
+ }
4107
+ type WorkflowStepParallelRaceConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
4108
+ steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
4109
+ }>;
4110
+ interface WorkflowStepParallelRace<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
4111
+ type: "parallel-race";
4112
+ steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
4113
+ }
4114
+ type WorkflowStepParallelAllConfig<STEPS extends ReadonlyArray<InternalAnyWorkflowStep<DangerouslyAllowAny, DangerouslyAllowAny>>> = InternalWorkflowStepConfig<{
4115
+ steps: STEPS;
4116
+ }>;
4117
+ interface WorkflowStepParallelAll<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
4118
+ type: "parallel-all";
4119
+ steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
4120
+ }
4121
+ type WorkflowStep<INPUT, DATA, RESULT> = WorkflowStepAgent<INPUT, DATA, RESULT> | WorkflowStepFunc<INPUT, DATA, RESULT> | WorkflowStepConditionalWhen<INPUT, DATA, RESULT> | WorkflowStepParallelAll<INPUT, DATA, RESULT> | WorkflowStepTap<INPUT, DATA, RESULT> | WorkflowStepParallelRace<INPUT, DATA, RESULT>;
4122
+
4123
+ /**
4124
+ * Creates an async function step for the workflow
4125
+ *
4126
+ * @example
4127
+ * ```ts
4128
+ * const w = createWorkflow(
4129
+ * andThen(async (data) => {
4130
+ * const processed = await someAsyncOperation(data.value);
4131
+ * return { ...data, processed };
4132
+ * }),
4133
+ * andThen(async (data) => {
4134
+ * return { result: `Processed: ${data.processed}` };
4135
+ * })
4136
+ * );
4137
+ * ```
4138
+ *
4139
+ * @param fn - The async function to execute with the workflow data
4140
+ * @returns A workflow step that executes the function and returns the result
4141
+ */
4142
+ declare function andThen<INPUT, DATA, RESULT>({ execute, ...config }: WorkflowStepFuncConfig<INPUT, DATA, RESULT>): {
4143
+ type: "func";
4144
+ execute: InternalWorkflowFunc<INPUT, DATA, RESULT>;
4145
+ id: string;
4146
+ name: string;
4147
+ purpose: string;
4148
+ };
4149
+
4150
+ /**
4151
+ * Creates a conditional step for the workflow that executes only when a condition is met
4152
+ *
4153
+ * @example
4154
+ * ```ts
4155
+ * const w = createWorkflow(
4156
+ * andWhen({
4157
+ * condition: (data) => data.userType === "admin",
4158
+ * stepOrFunc: andThen(async (data) => {
4159
+ * return { ...data, permissions: ["read", "write", "delete"] };
4160
+ * })
4161
+ * }),
4162
+ * andWhen({
4163
+ * condition: (data) => data.value > 100,
4164
+ * andAgent(
4165
+ * (data) => `Process high value transaction: ${data.value}`,
4166
+ * agent,
4167
+ * { schema: z.object({ processed: z.boolean() }) }
4168
+ * )
4169
+ * )
4170
+ * );
4171
+ * ```
4172
+ *
4173
+ * @param condition - Function that determines if the step should execute based on the input data
4174
+ * @param stepOrFunc - Either a workflow step or an agent to execute when the condition is true
4175
+ * @returns A conditional workflow step that executes the step only when the condition evaluates to true
4176
+ */
4177
+ declare function andWhen<INPUT, DATA, RESULT>({ condition, step, ...config }: WorkflowStepConditionalWhenConfig<INPUT, DATA, RESULT>): {
4178
+ type: "conditional-when";
4179
+ condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
4180
+ execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT | InternalExtractWorkflowInputData<DATA>>;
4181
+ id: string;
4182
+ name: string;
4183
+ purpose: string;
4184
+ };
4185
+
4186
+ /**
4187
+ * Creates a parallel execution step that runs multiple steps simultaneously and waits for all to complete
4188
+ *
4189
+ * @example
4190
+ * ```ts
4191
+ * const w = createWorkflow(
4192
+ * andAll([
4193
+ * andThen(async (data) => {
4194
+ * const userInfo = await fetchUserInfo(data.userId);
4195
+ * return { userInfo };
4196
+ * }),
4197
+ * andThen(async (data) => {
4198
+ * const permissions = await fetchPermissions(data.userId);
4199
+ * return { permissions };
4200
+ * }),
4201
+ * andAgent(
4202
+ * (data) => `Generate recommendations for user ${data.userId}`,
4203
+ * agent,
4204
+ * { schema: z.object({ recommendations: z.array(z.string()) }) }
4205
+ * )
4206
+ * ]),
4207
+ * andThen(async (data) => {
4208
+ * // data is now an array: [{ userInfo }, { permissions }, { recommendations }]
4209
+ * return { combined: data.flat() };
4210
+ * })
4211
+ * );
4212
+ * ```
4213
+ *
4214
+ * @param steps - Array of workflow steps to execute in parallel
4215
+ * @returns A workflow step that executes all steps simultaneously and returns their results as an array
4216
+ */
4217
+ declare function andAll<INPUT, DATA, RESULT, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>>({ steps, ...config }: WorkflowStepParallelAllConfig<STEPS>): {
4218
+ type: "parallel-all";
4219
+ steps: InternalAnyWorkflowStep<INPUT, DATA, INFERRED_RESULT>[];
4220
+ execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<INFERRED_RESULT>;
4221
+ id: string;
4222
+ name: string;
4223
+ purpose: string;
4224
+ };
4225
+
4226
+ /**
4227
+ * Creates a race execution step that runs multiple steps simultaneously and returns the first completed result
4228
+ *
4229
+ * @example
4230
+ * ```ts
4231
+ * const w = createWorkflow(
4232
+ * andRace([
4233
+ * andThen(async (data) => {
4234
+ * // Fast operation
4235
+ * const cacheResult = await checkCache(data.query);
4236
+ * return { source: "cache", result: cacheResult };
4237
+ * }),
4238
+ * andThen(async (data) => {
4239
+ * // Slower operation
4240
+ * const dbResult = await queryDatabase(data.query);
4241
+ * return { source: "database", result: dbResult };
4242
+ * }),
4243
+ * andAgent(
4244
+ * (data) => `Generate fallback response for: ${data.query}`,
4245
+ * agent,
4246
+ * { schema: z.object({ source: z.literal("ai"), result: z.string() }) }
4247
+ * )
4248
+ * ]),
4249
+ * andThen(async (data) => {
4250
+ * // data is the result from whichever step completed first
4251
+ * return { finalResult: data.result, source: data.source };
4252
+ * })
4253
+ * );
4254
+ * ```
4255
+ *
4256
+ * @param steps - Array of workflow steps to execute in parallel
4257
+ * @returns A workflow step that executes all steps simultaneously and returns the result from the first step to complete
4258
+ */
4259
+ declare function andRace<INPUT, DATA, RESULT, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>[number]>({ steps, ...config }: InternalWorkflowStepConfig<{
4260
+ steps: STEPS;
4261
+ }>): {
4262
+ type: "parallel-race";
4263
+ steps: InternalAnyWorkflowStep<INPUT, DATA, INFERRED_RESULT>[];
4264
+ execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<INFERRED_RESULT>;
4265
+ id: string;
4266
+ name: string;
4267
+ purpose: string;
4268
+ };
4269
+
4270
+ /**
4271
+ * A safe way to tap into the workflow state without affecting the result.
4272
+ * @param fn - The async function to execute
4273
+ * @returns A workflow step that executes the function
4274
+ */
4275
+ declare function andTap<INPUT, DATA, RESULT>({ execute, ...config }: WorkflowStepTapConfig<INPUT, DATA, RESULT>): {
4276
+ type: "tap";
4277
+ execute: (data: InternalExtractWorkflowInputData<DATA>, context: InternalWorkflowStateParam<INPUT>) => Promise<DATA>;
4278
+ id: string;
4279
+ name: string;
4280
+ purpose: string;
4281
+ };
4282
+
4283
+ /**
4284
+ * Creates a workflow from multiple and* functions
4285
+ * @param config - The workflow configuration
4286
+ * @param steps - Variable number of and* functions to execute
4287
+ * @returns A configured workflow instance
4288
+ */
4289
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4290
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4291
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4292
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4293
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4294
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4295
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4296
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4297
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4298
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4299
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4300
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4301
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4302
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4303
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4304
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, S15>, s16: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S15, WorkflowResult<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4305
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, S15>, s16: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S15, S16>, s17: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S16, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4306
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16, S17>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, S15>, s16: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S15, S16>, s17: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S16, S17>, s18: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S17, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4307
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16, S17, S18>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, S15>, s16: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S15, S16>, s17: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S16, S17>, s18: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S17, S18>, s19: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S18, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4308
+ declare function createWorkflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16, S17, S18, S19>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>, s1: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, WorkflowInput<INPUT_SCHEMA>, S1>, s2: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S1, S2>, s3: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S2, S3>, s4: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S3, S4>, s5: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S4, S5>, s6: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S5, S6>, s7: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S6, S7>, s8: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S7, S8>, s9: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S8, S9>, s10: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S9, S10>, s11: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S10, S11>, s12: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S11, S12>, s13: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S12, S13>, s14: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S13, S14>, s15: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S14, S15>, s16: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S15, S16>, s17: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S16, S17>, s18: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S17, S18>, s19: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S18, S19>, s20: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, S19, z.infer<RESULT_SCHEMA>>): Workflow<INPUT_SCHEMA, RESULT_SCHEMA>;
4309
+
4310
+ /**
4311
+ * Agent configuration for the chain
4312
+ */
4313
+ type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
4314
+ schema: SCHEMA;
4315
+ };
4316
+ /**
4317
+ * A workflow chain that provides a fluent API for building workflows
4318
+ *
4319
+ * @example
4320
+ * ```ts
4321
+ * const workflow = createWorkflowChain({
4322
+ * id: "user-processing",
4323
+ * name: "User Processing Workflow",
4324
+ * purpose: "Process user data and generate personalized content",
4325
+ * input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
4326
+ * result: z.object({ processed: z.boolean(), content: z.string() })
4327
+ * })
4328
+ * .andThen(async (data) => {
4329
+ * const userInfo = await fetchUserInfo(data.userId);
4330
+ * return { ...data, userInfo };
4331
+ * })
4332
+ * .andWhen(
4333
+ * (data) => data.userType === "admin",
4334
+ * async (data) => ({ ...data, permissions: ["read", "write", "delete"] })
4335
+ * )
4336
+ * .andAgent(
4337
+ * (data) => `Generate personalized content for ${data.userInfo.name}`,
4338
+ * agent,
4339
+ * { schema: z.object({ content: z.string() }) }
4340
+ * )
4341
+ * .andThen(async (data) => ({
4342
+ * processed: true,
4343
+ * content: data.content
4344
+ * }));
4345
+ *
4346
+ * const result = await workflow.run({ userId: "123", userType: "admin" });
4347
+ * ```
4348
+ */
4349
+ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, CURRENT_DATA = WorkflowInput<INPUT_SCHEMA>> {
4350
+ private steps;
4351
+ private config;
4352
+ constructor(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>);
4353
+ /**
4354
+ * Creates an agent step for a workflow
4355
+ *
4356
+ * @example
4357
+ * ```ts
4358
+ * const w = createWorkflowChain<{ name: string }>()
4359
+ * .andAgent(
4360
+ * (data) => `Generate a greeting for the user ${data.name}`,
4361
+ * agent,
4362
+ * { schema: z.object({ greeting: z.string() }) }
4363
+ * )
4364
+ * .andThen(async (data) => data.greeting)
4365
+ * ```
4366
+ *
4367
+ * @param task - The task (prompt) to execute for the agent, can be a string or a function that returns a string
4368
+ * @param agent - The agent to execute the task using `generateObject`
4369
+ * @param config - The config for the agent (schema) `generateObject` call
4370
+ * @returns A workflow step that executes the agent with the task
4371
+ */
4372
+ andAgent<SCHEMA extends z.ZodTypeAny>(task: string | InternalWorkflowFunc<INPUT_SCHEMA, CURRENT_DATA, string>, agent: Agent<{
4373
+ llm: DangerouslyAllowAny;
4374
+ }>, config: AgentConfig<SCHEMA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<SCHEMA>>;
4375
+ /**
4376
+ * Add a function step to the workflow
4377
+ *
4378
+ * @example
4379
+ * ```ts
4380
+ * const workflow = createWorkflowChain(config)
4381
+ * .andThen(async (data) => {
4382
+ * const processed = await someAsyncOperation(data.value);
4383
+ * return { ...data, processed };
4384
+ * })
4385
+ * .andThen(async (data) => {
4386
+ * const enriched = await enrichData(data.processed);
4387
+ * return { ...data, enriched };
4388
+ * });
4389
+ * ```
4390
+ *
4391
+ * @param fn - The async function to execute with the current workflow data
4392
+ * @returns A new chain with the function step added
4393
+ */
4394
+ andThen<NEW_DATA>({ execute, ...config }: WorkflowStepFuncConfig<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, NEW_DATA>;
4395
+ /**
4396
+ * Add a conditional step that executes when a condition is true
4397
+ *
4398
+ * @example
4399
+ * ```ts
4400
+ * const workflow = createWorkflowChain(config)
4401
+ * .andWhen(
4402
+ * (data) => data.userType === "admin",
4403
+ * async (data) => ({ ...data, permissions: ["read", "write", "delete"] })
4404
+ * )
4405
+ * .andWhen(
4406
+ * (data) => data.value > 1000,
4407
+ * async (data) => ({ ...data, flagged: true, requiresReview: true })
4408
+ * )
4409
+ * .andWhen(
4410
+ * (data) => data.status === "pending",
4411
+ * (data) => andAgent(
4412
+ * `Process pending request for ${data.userId}`,
4413
+ * agent,
4414
+ * { schema: z.object({ processed: z.boolean() }) }
4415
+ * )
4416
+ * );
4417
+ * ```
4418
+ *
4419
+ * @param condition - Function that determines if the step should execute based on the current data
4420
+ * @param stepInput - Either a workflow step or an agent to execute when the condition is true
4421
+ * @returns A new chain with the conditional step added
4422
+ */
4423
+ andWhen<NEW_DATA>({ condition, step, ...config }: WorkflowStepConditionalWhenConfig<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, NEW_DATA | CURRENT_DATA>;
4424
+ /**
4425
+ * Add a tap step to the workflow
4426
+ *
4427
+ * @example
4428
+ * ```ts
4429
+ * const workflow = createWorkflowChain(config)
4430
+ * .andTap({
4431
+ * execute: async (data) => {
4432
+ * console.log("🔄 Translating text:", data);
4433
+ * }
4434
+ * })
4435
+ * .andThen({
4436
+ * // the input data is still the same as the andTap ONLY executes, it doesn't return anything
4437
+ * execute: async (data) => {
4438
+ * return { ...data, translatedText: data.translatedText };
4439
+ * }
4440
+ * });
4441
+ * ```
4442
+ *
4443
+ * @param fn - The async function to execute with the current workflow data
4444
+ * @returns A new chain with the tap step added
4445
+ */
4446
+ andTap<NEW_DATA>({ execute, ...config }: WorkflowStepTapConfig<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, CURRENT_DATA>;
4447
+ /**
4448
+ * Add a parallel execution step that runs multiple steps simultaneously and waits for all to complete
4449
+ *
4450
+ * @example
4451
+ * ```ts
4452
+ * const workflow = createWorkflowChain(config)
4453
+ * .andAll([
4454
+ * async (data) => {
4455
+ * const userInfo = await fetchUserInfo(data.userId);
4456
+ * return { userInfo };
4457
+ * },
4458
+ * async (data) => {
4459
+ * const permissions = await fetchPermissions(data.userId);
4460
+ * return { permissions };
4461
+ * },
4462
+ * (data) => andAgent(
4463
+ * `Generate recommendations for user ${data.userId}`,
4464
+ * agent,
4465
+ * { schema: z.object({ recommendations: z.array(z.string()) }) }
4466
+ * )
4467
+ * ])
4468
+ * .andThen(async (data) => {
4469
+ * // data is now an array: [{ userInfo }, { permissions }, { recommendations }]
4470
+ * return { combined: data.flat() };
4471
+ * });
4472
+ * ```
4473
+ *
4474
+ * @param steps - Array of workflow steps to execute in parallel
4475
+ * @returns A new chain with the parallel step added
4476
+ */
4477
+ andAll<NEW_DATA, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>>({ steps, ...config }: WorkflowStepParallelAllConfig<STEPS>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, INFERRED_RESULT>;
4478
+ /**
4479
+ * Add a race execution step that runs multiple steps simultaneously and returns the first completed result
4480
+ *
4481
+ * @example
4482
+ * ```ts
4483
+ * const workflow = createWorkflowChain(config)
4484
+ * .andRace([
4485
+ * async (data) => {
4486
+ * // Fast operation
4487
+ * const cacheResult = await checkCache(data.query);
4488
+ * return { source: "cache", result: cacheResult };
4489
+ * },
4490
+ * async (data) => {
4491
+ * // Slower operation
4492
+ * const dbResult = await queryDatabase(data.query);
4493
+ * return { source: "database", result: dbResult };
4494
+ * },
4495
+ * (data) => andAgent(
4496
+ * `Generate fallback response for: ${data.query}`,
4497
+ * agent,
4498
+ * { schema: z.object({ source: z.literal("ai"), result: z.string() }) }
4499
+ * )
4500
+ * ])
4501
+ * .andThen(async (data) => {
4502
+ * // data is the result from whichever step completed first
4503
+ * return { finalResult: data.result, source: data.source };
4504
+ * });
4505
+ * ```
4506
+ *
4507
+ * @param steps - Array of workflow steps to execute in parallel
4508
+ * @returns A new chain with the race step added
4509
+ */
4510
+ andRace<NEW_DATA, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>[number]>({ steps, ...config }: WorkflowStepParallelRaceConfig<STEPS, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, INFERRED_RESULT>;
4511
+ /**
4512
+ * Execute the workflow with the given input
4513
+ *
4514
+ * @example
4515
+ * ```ts
4516
+ * const workflow = createWorkflowChain({
4517
+ * id: "user-processing",
4518
+ * name: "User Processing Workflow",
4519
+ * purpose: "Process user data and generate personalized content",
4520
+ * input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
4521
+ * result: z.object({ processed: z.boolean(), content: z.string() })
4522
+ * })
4523
+ * .andThen(async (data) => {
4524
+ * const userInfo = await fetchUserInfo(data.userId);
4525
+ * return { ...data, userInfo };
4526
+ * })
4527
+ * .andAgent(
4528
+ * (data) => `Generate personalized content for ${data.userInfo.name}`,
4529
+ * agent,
4530
+ * { schema: z.object({ content: z.string() }) }
4531
+ * )
4532
+ * .andThen(async (data) => ({
4533
+ * processed: true,
4534
+ * content: data.content
4535
+ * }));
4536
+ *
4537
+ * const result = await workflow.run({ userId: "123", userType: "admin" });
4538
+ * console.log(result); // { processed: true, content: "Hello John, here's your personalized content..." }
4539
+ * ```
4540
+ *
4541
+ * @param input - The input data for the workflow that matches the input schema
4542
+ * @returns The workflow execution result that matches the result schema
4543
+ */
4544
+ run(input: WorkflowInput<INPUT_SCHEMA>, options?: WorkflowRunOptions): Promise<{
4545
+ executionId: string;
4546
+ startAt: Date;
4547
+ endAt: Date;
4548
+ status: "completed";
4549
+ result: z.TypeOf<RESULT_SCHEMA>;
4550
+ }>;
4551
+ }
4552
+ /**
4553
+ * Creates a new workflow chain with the given configuration
4554
+ *
4555
+ * @example
4556
+ * ```ts
4557
+ * const workflow = createWorkflowChain({
4558
+ * id: "data-processing",
4559
+ * name: "Data Processing Pipeline",
4560
+ * purpose: "Process and analyze user data with AI insights",
4561
+ * input: z.object({
4562
+ * userId: z.string(),
4563
+ * data: z.array(z.number()),
4564
+ * options: z.object({
4565
+ * includeAnalysis: z.boolean().default(true)
4566
+ * }).optional()
4567
+ * }),
4568
+ * result: z.object({
4569
+ * processed: z.boolean(),
4570
+ * summary: z.string(),
4571
+ * insights: z.array(z.string()).optional()
4572
+ * })
4573
+ * })
4574
+ * .andThen(async (data) => {
4575
+ * const processed = await processData(data.data);
4576
+ * return { ...data, processed };
4577
+ * })
4578
+ * .andWhen(
4579
+ * (data) => data.options?.includeAnalysis ?? true,
4580
+ * (data) => andAgent(
4581
+ * `Analyze the processed data: ${JSON.stringify(data.processed)}`,
4582
+ * agent,
4583
+ * { schema: z.object({ insights: z.array(z.string()) }) }
4584
+ * )
4585
+ * )
4586
+ * .andThen(async (data) => ({
4587
+ * processed: true,
4588
+ * summary: `Processed ${data.data.length} items for user ${data.userId}`,
4589
+ * insights: data.insights
4590
+ * }));
4591
+ *
4592
+ * const result = await workflow.run(...);
4593
+ * ```
4594
+ *
4595
+ * @param config - The workflow configuration including schemas and metadata
4596
+ * @returns A new workflow chain instance ready for building steps
4597
+ */
4598
+ declare function createWorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny>(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, WorkflowInput<INPUT_SCHEMA>>;
4599
+
3825
4600
  /**
3826
4601
  * Enum defining the next action to take after a reasoning step.
3827
4602
  */
@@ -4151,6 +4926,11 @@ type HTTPServerConfig = {
4151
4926
  * Event source initialization options (used for SSE fallback)
4152
4927
  */
4153
4928
  eventSourceInit?: EventSourceInit;
4929
+ /**
4930
+ * Optional maximum request timeout in milliseconds.
4931
+ * If provided, passed to MCPClient as the per-request timeout.
4932
+ */
4933
+ timeout?: number;
4154
4934
  };
4155
4935
  /**
4156
4936
  * SSE-based MCP server configuration (explicit SSE transport)
@@ -4172,6 +4952,11 @@ type SSEServerConfig = {
4172
4952
  * Event source initialization options
4173
4953
  */
4174
4954
  eventSourceInit?: EventSourceInit;
4955
+ /**
4956
+ * Optional maximum request timeout in milliseconds.
4957
+ * If provided, passed to MCPClient as the per-request timeout.
4958
+ */
4959
+ timeout?: number;
4175
4960
  };
4176
4961
  /**
4177
4962
  * Streamable HTTP-based MCP server configuration (no fallback)
@@ -4193,6 +4978,11 @@ type StreamableHTTPServerConfig = {
4193
4978
  * Session ID for the connection
4194
4979
  */
4195
4980
  sessionId?: string;
4981
+ /**
4982
+ * Optional maximum request timeout in milliseconds.
4983
+ * If provided, passed to MCPClient as the per-request timeout.
4984
+ */
4985
+ timeout?: number;
4196
4986
  };
4197
4987
  /**
4198
4988
  * Stdio-based MCP server configuration
@@ -4218,6 +5008,11 @@ type StdioServerConfig = {
4218
5008
  * Working directory for the MCP server process
4219
5009
  */
4220
5010
  cwd?: string;
5011
+ /**
5012
+ * Optional maximum request timeout in milliseconds.
5013
+ * If provided, passed to MCPClient as the per-request timeout.
5014
+ */
5015
+ timeout?: number;
4221
5016
  };
4222
5017
  /**
4223
5018
  * Tool call request
@@ -4746,4 +5541,4 @@ declare class VoltAgent {
4746
5541
  shutdownTelemetry(): Promise<void>;
4747
5542
  }
4748
5543
 
4749
- export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, AsyncIterableStream, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, CachedPrompt, ChatMessage, ClientInfo, Conversation, ConversationQueryOptions, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, DynamicValue, DynamicValueOptions, ErrorStreamPart, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, FinishStreamPart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, VoltOpsClient$1 as IVoltOpsClient, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, ObjectSubAgentConfig, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptApiClient, PromptApiResponse, PromptContent, PromptCreator, PromptHelper, PromptReference, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningStreamPart, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, SSEServerConfig, ServerOptions, SourceStreamPart, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamEventForwarderOptions, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamPart, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, StreamableHTTPServerConfig, SubAgentConfig, SubAgentConfigObject, SubAgentMethod, TemplateVariables, TextDeltaStreamPart, TextPart, TextSubAgentConfig, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolCallStreamPart, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolResultStreamPart, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, VoltAgentOptions, VoltOpsClient, VoltOpsClientOptions, VoltOpsPromptApiClient, VoltOpsPromptManager, VoltOpsPromptManagerImpl, checkForUpdates, createAsyncIterableStream, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createSimpleTemplateEngine, createStreamEventForwarder, createSubagent, createTool, createToolkit, createVoltOpsClient, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, streamEventForwarder, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
5544
+ export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, AsyncIterableStream, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, CachedPrompt, ChatMessage, ClientInfo, Conversation, ConversationQueryOptions, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, DynamicValue, DynamicValueOptions, ErrorStreamPart, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, FinishStreamPart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, VoltOpsClient$1 as IVoltOpsClient, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, ObjectSubAgentConfig, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptApiClient, PromptApiResponse, PromptContent, PromptCreator, PromptHelper, PromptReference, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningStreamPart, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, SSEServerConfig, ServerOptions, SourceStreamPart, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamEventForwarderOptions, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamPart, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, StreamableHTTPServerConfig, SubAgentConfig, SubAgentConfigObject, SubAgentMethod, TemplateVariables, TextDeltaStreamPart, TextPart, TextSubAgentConfig, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolCallStreamPart, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolResultStreamPart, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, VoltAgentOptions, VoltOpsClient, VoltOpsClientOptions, VoltOpsPromptApiClient, VoltOpsPromptManager, VoltOpsPromptManagerImpl, Workflow, WorkflowConfig, andAgent, andAll, andRace, andTap, andThen, andWhen, checkForUpdates, createAsyncIterableStream, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createSimpleTemplateEngine, createStreamEventForwarder, createSubagent, createTool, createToolkit, createVoltOpsClient, createWorkflow, createWorkflowChain, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, streamEventForwarder, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };