@voltagent/core 0.1.57 → 0.1.58
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 +711 -9
- package/dist/index.js +499 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +486 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
|
@@ -1231,7 +1233,7 @@ type AgentOptions = {
|
|
|
1231
1233
|
/**
|
|
1232
1234
|
* Optional user-defined context to be passed around
|
|
1233
1235
|
*/
|
|
1234
|
-
userContext?:
|
|
1236
|
+
userContext?: UserContext;
|
|
1235
1237
|
/**
|
|
1236
1238
|
* @deprecated Use `voltOpsClient` instead. Will be removed in a future version.
|
|
1237
1239
|
*
|
|
@@ -1352,7 +1354,7 @@ interface CommonGenerateOptions {
|
|
|
1352
1354
|
signal?: AbortSignal;
|
|
1353
1355
|
historyEntryId?: string;
|
|
1354
1356
|
operationContext?: OperationContext;
|
|
1355
|
-
userContext?:
|
|
1357
|
+
userContext?: UserContext;
|
|
1356
1358
|
}
|
|
1357
1359
|
/**
|
|
1358
1360
|
* Public-facing generate options for external users
|
|
@@ -1575,6 +1577,7 @@ interface VoltAgentError {
|
|
|
1575
1577
|
* Providers must pass an error conforming to the VoltAgentError structure.
|
|
1576
1578
|
*/
|
|
1577
1579
|
type StreamOnErrorCallback = (error: VoltAgentError) => Promise<void> | void;
|
|
1580
|
+
type UserContext = Map<string | symbol, unknown>;
|
|
1578
1581
|
/**
|
|
1579
1582
|
* Standardized object structure passed to the onFinish callback
|
|
1580
1583
|
* when streamText completes successfully.
|
|
@@ -1591,7 +1594,7 @@ interface StreamTextFinishResult {
|
|
|
1591
1594
|
/** Any warnings generated during the completion (if available). */
|
|
1592
1595
|
warnings?: unknown[];
|
|
1593
1596
|
/** User context containing any custom metadata from the operation. */
|
|
1594
|
-
userContext?:
|
|
1597
|
+
userContext?: UserContext;
|
|
1595
1598
|
}
|
|
1596
1599
|
/**
|
|
1597
1600
|
* Type for the onFinish callback function for streamText.
|
|
@@ -1614,7 +1617,7 @@ interface StreamObjectFinishResult<TObject> {
|
|
|
1614
1617
|
/** The reason the stream finished (if available). Although less common for object streams. */
|
|
1615
1618
|
finishReason?: string;
|
|
1616
1619
|
/** User context containing any custom metadata from the operation. */
|
|
1617
|
-
userContext?:
|
|
1620
|
+
userContext?: UserContext;
|
|
1618
1621
|
}
|
|
1619
1622
|
/**
|
|
1620
1623
|
* Type for the onFinish callback function for streamObject.
|
|
@@ -1636,7 +1639,7 @@ interface StandardizedTextResult {
|
|
|
1636
1639
|
/** Warnings (if available from provider). */
|
|
1637
1640
|
warnings?: unknown[];
|
|
1638
1641
|
/** User context containing any custom metadata from the operation. */
|
|
1639
|
-
userContext?:
|
|
1642
|
+
userContext?: UserContext;
|
|
1640
1643
|
}
|
|
1641
1644
|
/**
|
|
1642
1645
|
* Standardized success result structure for generateObject.
|
|
@@ -1654,7 +1657,7 @@ interface StandardizedObjectResult<TObject> {
|
|
|
1654
1657
|
/** Warnings (if available from provider). */
|
|
1655
1658
|
warnings?: unknown[];
|
|
1656
1659
|
/** User context containing any custom metadata from the operation. */
|
|
1657
|
-
userContext?:
|
|
1660
|
+
userContext?: UserContext;
|
|
1658
1661
|
}
|
|
1659
1662
|
/**
|
|
1660
1663
|
* Unified output type for the onEnd hook, representing the successful result
|
|
@@ -1677,7 +1680,7 @@ type GenerateTextResponse<TProvider extends {
|
|
|
1677
1680
|
type StreamTextResponse<TProvider extends {
|
|
1678
1681
|
llm: LLMProvider<any>;
|
|
1679
1682
|
}> = InferStreamTextResponseFromProvider<TProvider> & {
|
|
1680
|
-
userContext?:
|
|
1683
|
+
userContext?: UserContext;
|
|
1681
1684
|
};
|
|
1682
1685
|
type GenerateObjectResponse<TProvider extends {
|
|
1683
1686
|
llm: LLMProvider<any>;
|
|
@@ -1687,7 +1690,7 @@ type GenerateObjectResponse<TProvider extends {
|
|
|
1687
1690
|
type StreamObjectResponse<TProvider extends {
|
|
1688
1691
|
llm: LLMProvider<any>;
|
|
1689
1692
|
}, TSchema extends z.ZodType> = InferStreamObjectResponseFromProvider<TProvider, TSchema> & {
|
|
1690
|
-
userContext?:
|
|
1693
|
+
userContext?: UserContext;
|
|
1691
1694
|
};
|
|
1692
1695
|
|
|
1693
1696
|
/**
|
|
@@ -3822,6 +3825,705 @@ type VoltAgentOptions = {
|
|
|
3822
3825
|
enableSwaggerUI?: boolean;
|
|
3823
3826
|
};
|
|
3824
3827
|
|
|
3828
|
+
/**
|
|
3829
|
+
* Hooks for the workflow
|
|
3830
|
+
* @param DATA - The type of the data
|
|
3831
|
+
* @param RESULT - The type of the result
|
|
3832
|
+
*/
|
|
3833
|
+
type WorkflowHooks<DATA, RESULT> = {
|
|
3834
|
+
/**
|
|
3835
|
+
* Called when the workflow starts
|
|
3836
|
+
* @param state - The current state of the workflow
|
|
3837
|
+
* @returns void
|
|
3838
|
+
*/
|
|
3839
|
+
onStart?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
|
|
3840
|
+
/**
|
|
3841
|
+
* Called when a step starts
|
|
3842
|
+
* @param state - The current state of the workflow
|
|
3843
|
+
* @returns void
|
|
3844
|
+
*/
|
|
3845
|
+
onStepStart?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
|
|
3846
|
+
/**
|
|
3847
|
+
* Called when a step ends
|
|
3848
|
+
* @param state - The current state of the workflow
|
|
3849
|
+
* @returns void
|
|
3850
|
+
*/
|
|
3851
|
+
onStepEnd?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
|
|
3852
|
+
/**
|
|
3853
|
+
* Called when the workflow ends
|
|
3854
|
+
* @param state - The current state of the workflow
|
|
3855
|
+
* @returns void
|
|
3856
|
+
*/
|
|
3857
|
+
onEnd?: (state: WorkflowState<DATA, RESULT>) => Promise<void>;
|
|
3858
|
+
};
|
|
3859
|
+
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;
|
|
3860
|
+
type WorkflowResult<RESULT_SCHEMA extends z.ZodTypeAny> = RESULT_SCHEMA extends z.ZodTypeAny ? z.infer<RESULT_SCHEMA> : RESULT_SCHEMA;
|
|
3861
|
+
type WorkflowConfig<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny> = {
|
|
3862
|
+
/**
|
|
3863
|
+
* Unique identifier for the workflow
|
|
3864
|
+
*/
|
|
3865
|
+
id: string;
|
|
3866
|
+
/**
|
|
3867
|
+
* Human-readable name for the workflow
|
|
3868
|
+
*/
|
|
3869
|
+
name: string;
|
|
3870
|
+
/**
|
|
3871
|
+
* Description of what the workflow does
|
|
3872
|
+
*/
|
|
3873
|
+
purpose?: string;
|
|
3874
|
+
/**
|
|
3875
|
+
* Schema for the input data
|
|
3876
|
+
*/
|
|
3877
|
+
input?: INPUT_SCHEMA;
|
|
3878
|
+
/**
|
|
3879
|
+
* Schema for the result data
|
|
3880
|
+
*/
|
|
3881
|
+
result: RESULT_SCHEMA;
|
|
3882
|
+
/**
|
|
3883
|
+
* Hooks for the workflow
|
|
3884
|
+
*/
|
|
3885
|
+
hooks?: WorkflowHooks<WorkflowInput<INPUT_SCHEMA>, WorkflowResult<RESULT_SCHEMA>>;
|
|
3886
|
+
};
|
|
3887
|
+
/**
|
|
3888
|
+
* A workflow instance that can be executed
|
|
3889
|
+
*/
|
|
3890
|
+
type Workflow<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny> = {
|
|
3891
|
+
/**
|
|
3892
|
+
* Unique identifier for the workflow
|
|
3893
|
+
*/
|
|
3894
|
+
id: string;
|
|
3895
|
+
/**
|
|
3896
|
+
* Human-readable name for the workflow
|
|
3897
|
+
*/
|
|
3898
|
+
name: string;
|
|
3899
|
+
/**
|
|
3900
|
+
* Description of what the workflow does
|
|
3901
|
+
* @default "No purpose provided"
|
|
3902
|
+
*/
|
|
3903
|
+
purpose: string;
|
|
3904
|
+
/**
|
|
3905
|
+
* Array of steps to execute in order
|
|
3906
|
+
*/
|
|
3907
|
+
steps: WorkflowStep<WorkflowInput<INPUT_SCHEMA>, DangerouslyAllowAny, DangerouslyAllowAny>[];
|
|
3908
|
+
/**
|
|
3909
|
+
* Execute the workflow with the given input
|
|
3910
|
+
* @param input - The input to the workflow
|
|
3911
|
+
* @returns The result of the workflow
|
|
3912
|
+
*/
|
|
3913
|
+
run: (input: WorkflowInput<INPUT_SCHEMA>) => Promise<{
|
|
3914
|
+
executionId: string;
|
|
3915
|
+
startAt: Date;
|
|
3916
|
+
endAt: Date;
|
|
3917
|
+
status: "completed";
|
|
3918
|
+
result: z.infer<RESULT_SCHEMA>;
|
|
3919
|
+
}>;
|
|
3920
|
+
};
|
|
3921
|
+
|
|
3922
|
+
type WorkflowStateStatus = "pending" | "running" | "completed" | "failed";
|
|
3923
|
+
type WorkflowState<INPUT, RESULT> = {
|
|
3924
|
+
executionId: string;
|
|
3925
|
+
conversationId?: string;
|
|
3926
|
+
userId?: string;
|
|
3927
|
+
userContext?: UserContext;
|
|
3928
|
+
active: number;
|
|
3929
|
+
startAt: Date;
|
|
3930
|
+
endAt: Date | null;
|
|
3931
|
+
status: WorkflowStateStatus;
|
|
3932
|
+
/** the initial input data to the workflow */
|
|
3933
|
+
input: InternalExtractWorkflowInputData<INPUT>;
|
|
3934
|
+
/** current data being processed */
|
|
3935
|
+
data: DangerouslyAllowAny;
|
|
3936
|
+
/** the result of workflow execution, null until execution is complete */
|
|
3937
|
+
result: RESULT | null;
|
|
3938
|
+
error: Error | null;
|
|
3939
|
+
};
|
|
3940
|
+
|
|
3941
|
+
/**
|
|
3942
|
+
* The base input type for the workflow
|
|
3943
|
+
* @private - INTERNAL USE ONLY
|
|
3944
|
+
*/
|
|
3945
|
+
type InternalBaseWorkflowInputSchema = z.ZodTypeAny | BaseMessage | BaseMessage[] | string;
|
|
3946
|
+
/**
|
|
3947
|
+
* The state parameter for the workflow, used to pass the state to a step or other function (i.e. hooks)
|
|
3948
|
+
* @private - INTERNAL USE ONLY
|
|
3949
|
+
*/
|
|
3950
|
+
type InternalWorkflowStateParam<INPUT> = Omit<WorkflowState<INPUT, DangerouslyAllowAny>, "data" | "result">;
|
|
3951
|
+
/**
|
|
3952
|
+
* A function that can be executed by the workflow
|
|
3953
|
+
* @private - INTERNAL USE ONLY
|
|
3954
|
+
*/
|
|
3955
|
+
type InternalWorkflowFunc<INPUT, DATA, RESULT> = (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT>;
|
|
3956
|
+
type InternalWorkflowStepConfig<T extends PlainObject = PlainObject> = {
|
|
3957
|
+
/**
|
|
3958
|
+
* Unique identifier for the step
|
|
3959
|
+
* @default uuidv4
|
|
3960
|
+
*/
|
|
3961
|
+
id?: string;
|
|
3962
|
+
/**
|
|
3963
|
+
* Human-readable name for the step
|
|
3964
|
+
*/
|
|
3965
|
+
name?: string;
|
|
3966
|
+
/**
|
|
3967
|
+
* Description of what the step does
|
|
3968
|
+
*/
|
|
3969
|
+
purpose?: string;
|
|
3970
|
+
} & T;
|
|
3971
|
+
/**
|
|
3972
|
+
* Base step interface for building new steps
|
|
3973
|
+
* @private - INTERNAL USE ONLY
|
|
3974
|
+
*/
|
|
3975
|
+
interface InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
|
|
3976
|
+
/**
|
|
3977
|
+
* Unique identifier for the step
|
|
3978
|
+
*/
|
|
3979
|
+
id: string;
|
|
3980
|
+
/**
|
|
3981
|
+
* Human-readable name for the step
|
|
3982
|
+
*/
|
|
3983
|
+
name: string | null;
|
|
3984
|
+
/**
|
|
3985
|
+
* Description of what the step does
|
|
3986
|
+
*/
|
|
3987
|
+
purpose: string | null;
|
|
3988
|
+
/**
|
|
3989
|
+
* Type identifier for the step
|
|
3990
|
+
*/
|
|
3991
|
+
type: string;
|
|
3992
|
+
/**
|
|
3993
|
+
* Execute the step with the given data
|
|
3994
|
+
* @param data - The data to execute the step with
|
|
3995
|
+
* @param state - The state of the workflow
|
|
3996
|
+
* @returns The result of the step
|
|
3997
|
+
*/
|
|
3998
|
+
execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT>;
|
|
3999
|
+
}
|
|
4000
|
+
/**
|
|
4001
|
+
* Any step that can be accepted by the workflow
|
|
4002
|
+
* @private - INTERNAL USE ONLY
|
|
4003
|
+
*/
|
|
4004
|
+
type InternalAnyWorkflowStep<INPUT, DATA = DangerouslyAllowAny, RESULT = DangerouslyAllowAny> = InternalBaseWorkflowStep<INPUT, DATA, RESULT> | Omit<InternalBaseWorkflowStep<INPUT, DATA, RESULT>, "type">;
|
|
4005
|
+
/**
|
|
4006
|
+
* Infer the result type from a list of steps
|
|
4007
|
+
* @private - INTERNAL USE ONLY
|
|
4008
|
+
*/
|
|
4009
|
+
type InternalInferWorkflowStepsResult<STEPS extends ReadonlyArray<InternalAnyWorkflowStep<DangerouslyAllowAny, DangerouslyAllowAny, DangerouslyAllowAny>>> = {
|
|
4010
|
+
[K in keyof STEPS]: Awaited<ReturnType<STEPS[K]["execute"]>>;
|
|
4011
|
+
};
|
|
4012
|
+
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;
|
|
4013
|
+
|
|
4014
|
+
type AgentConfig$1<SCHEMA extends z.ZodTypeAny> = PublicGenerateOptions & {
|
|
4015
|
+
schema: SCHEMA;
|
|
4016
|
+
};
|
|
4017
|
+
/**
|
|
4018
|
+
* Creates an agent step for a workflow
|
|
4019
|
+
*
|
|
4020
|
+
* @example
|
|
4021
|
+
* ```ts
|
|
4022
|
+
* const w = createWorkflow(
|
|
4023
|
+
* andAgent(
|
|
4024
|
+
* (data) => `Generate a greeting for the user ${data.name}`,
|
|
4025
|
+
* agent,
|
|
4026
|
+
* { schema: z.object({ greeting: z.string() }) }
|
|
4027
|
+
* ),
|
|
4028
|
+
* andThen(async (data) => data.greeting)
|
|
4029
|
+
* );
|
|
4030
|
+
* ```
|
|
4031
|
+
*
|
|
4032
|
+
* @param task - The task (prompt) to execute for the agent, can be a string or a function that returns a string
|
|
4033
|
+
* @param agent - The agent to execute the task using `generateObject`
|
|
4034
|
+
* @param config - The config for the agent (schema) `generateObject` call
|
|
4035
|
+
* @returns A workflow step that executes the agent with the task
|
|
4036
|
+
*/
|
|
4037
|
+
declare function andAgent<INPUT, DATA, SCHEMA extends z.ZodTypeAny>(task: BaseMessage[] | string | InternalWorkflowFunc<INPUT, DATA, BaseMessage[] | string>, agent: Agent<{
|
|
4038
|
+
llm: DangerouslyAllowAny;
|
|
4039
|
+
}>, config: AgentConfig$1<SCHEMA>): {
|
|
4040
|
+
type: "agent";
|
|
4041
|
+
id: string;
|
|
4042
|
+
name: string;
|
|
4043
|
+
purpose: string | null;
|
|
4044
|
+
agent: Agent<{
|
|
4045
|
+
llm: DangerouslyAllowAny;
|
|
4046
|
+
}>;
|
|
4047
|
+
execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<z.TypeOf<SCHEMA>>;
|
|
4048
|
+
};
|
|
4049
|
+
|
|
4050
|
+
interface WorkflowStepAgent<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
|
|
4051
|
+
type: "agent";
|
|
4052
|
+
agent: Agent<{
|
|
4053
|
+
llm: DangerouslyAllowAny;
|
|
4054
|
+
}>;
|
|
4055
|
+
}
|
|
4056
|
+
type WorkflowStepFuncConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
|
|
4057
|
+
execute: InternalWorkflowFunc<INPUT, DATA, RESULT>;
|
|
4058
|
+
}>;
|
|
4059
|
+
interface WorkflowStepFunc<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
|
|
4060
|
+
type: "func";
|
|
4061
|
+
}
|
|
4062
|
+
type WorkflowStepConditionalWhenConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
|
|
4063
|
+
condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
|
|
4064
|
+
step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
|
|
4065
|
+
}>;
|
|
4066
|
+
interface WorkflowStepConditionalWhen<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, InternalExtractWorkflowInputData<DATA> | RESULT> {
|
|
4067
|
+
type: "conditional-when";
|
|
4068
|
+
condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
|
|
4069
|
+
}
|
|
4070
|
+
type WorkflowStepParallelRaceConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
|
|
4071
|
+
steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
|
|
4072
|
+
}>;
|
|
4073
|
+
interface WorkflowStepParallelRace<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
|
|
4074
|
+
type: "parallel-race";
|
|
4075
|
+
steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
|
|
4076
|
+
}
|
|
4077
|
+
type WorkflowStepParallelAllConfig<STEPS extends ReadonlyArray<InternalAnyWorkflowStep<DangerouslyAllowAny, DangerouslyAllowAny>>> = InternalWorkflowStepConfig<{
|
|
4078
|
+
steps: STEPS;
|
|
4079
|
+
}>;
|
|
4080
|
+
interface WorkflowStepParallelAll<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT> {
|
|
4081
|
+
type: "parallel-all";
|
|
4082
|
+
steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
|
|
4083
|
+
}
|
|
4084
|
+
type WorkflowStep<INPUT, DATA, RESULT> = WorkflowStepAgent<INPUT, DATA, RESULT> | WorkflowStepFunc<INPUT, DATA, RESULT> | WorkflowStepConditionalWhen<INPUT, DATA, RESULT> | WorkflowStepParallelAll<INPUT, DATA, RESULT> | WorkflowStepParallelRace<INPUT, DATA, RESULT>;
|
|
4085
|
+
|
|
4086
|
+
/**
|
|
4087
|
+
* Creates an async function step for the workflow
|
|
4088
|
+
*
|
|
4089
|
+
* @example
|
|
4090
|
+
* ```ts
|
|
4091
|
+
* const w = createWorkflow(
|
|
4092
|
+
* andThen(async (data) => {
|
|
4093
|
+
* const processed = await someAsyncOperation(data.value);
|
|
4094
|
+
* return { ...data, processed };
|
|
4095
|
+
* }),
|
|
4096
|
+
* andThen(async (data) => {
|
|
4097
|
+
* return { result: `Processed: ${data.processed}` };
|
|
4098
|
+
* })
|
|
4099
|
+
* );
|
|
4100
|
+
* ```
|
|
4101
|
+
*
|
|
4102
|
+
* @param fn - The async function to execute with the workflow data
|
|
4103
|
+
* @returns A workflow step that executes the function and returns the result
|
|
4104
|
+
*/
|
|
4105
|
+
declare function andThen<INPUT, DATA, RESULT>({ execute, ...config }: WorkflowStepFuncConfig<INPUT, DATA, RESULT>): {
|
|
4106
|
+
type: "func";
|
|
4107
|
+
execute: InternalWorkflowFunc<INPUT, DATA, RESULT>;
|
|
4108
|
+
id: string;
|
|
4109
|
+
name: string;
|
|
4110
|
+
purpose: string;
|
|
4111
|
+
};
|
|
4112
|
+
|
|
4113
|
+
/**
|
|
4114
|
+
* Creates a conditional step for the workflow that executes only when a condition is met
|
|
4115
|
+
*
|
|
4116
|
+
* @example
|
|
4117
|
+
* ```ts
|
|
4118
|
+
* const w = createWorkflow(
|
|
4119
|
+
* andWhen({
|
|
4120
|
+
* condition: (data) => data.userType === "admin",
|
|
4121
|
+
* stepOrFunc: andThen(async (data) => {
|
|
4122
|
+
* return { ...data, permissions: ["read", "write", "delete"] };
|
|
4123
|
+
* })
|
|
4124
|
+
* }),
|
|
4125
|
+
* andWhen({
|
|
4126
|
+
* condition: (data) => data.value > 100,
|
|
4127
|
+
* andAgent(
|
|
4128
|
+
* (data) => `Process high value transaction: ${data.value}`,
|
|
4129
|
+
* agent,
|
|
4130
|
+
* { schema: z.object({ processed: z.boolean() }) }
|
|
4131
|
+
* )
|
|
4132
|
+
* )
|
|
4133
|
+
* );
|
|
4134
|
+
* ```
|
|
4135
|
+
*
|
|
4136
|
+
* @param condition - Function that determines if the step should execute based on the input data
|
|
4137
|
+
* @param stepOrFunc - Either a workflow step or an agent to execute when the condition is true
|
|
4138
|
+
* @returns A conditional workflow step that executes the step only when the condition evaluates to true
|
|
4139
|
+
*/
|
|
4140
|
+
declare function andWhen<INPUT, DATA, RESULT>({ condition, step, ...config }: WorkflowStepConditionalWhenConfig<INPUT, DATA, RESULT>): {
|
|
4141
|
+
type: "conditional-when";
|
|
4142
|
+
condition: InternalWorkflowFunc<INPUT, DATA, boolean>;
|
|
4143
|
+
execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<RESULT | InternalExtractWorkflowInputData<DATA>>;
|
|
4144
|
+
id: string;
|
|
4145
|
+
name: string;
|
|
4146
|
+
purpose: string;
|
|
4147
|
+
};
|
|
4148
|
+
|
|
4149
|
+
/**
|
|
4150
|
+
* Creates a parallel execution step that runs multiple steps simultaneously and waits for all to complete
|
|
4151
|
+
*
|
|
4152
|
+
* @example
|
|
4153
|
+
* ```ts
|
|
4154
|
+
* const w = createWorkflow(
|
|
4155
|
+
* andAll([
|
|
4156
|
+
* andThen(async (data) => {
|
|
4157
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
4158
|
+
* return { userInfo };
|
|
4159
|
+
* }),
|
|
4160
|
+
* andThen(async (data) => {
|
|
4161
|
+
* const permissions = await fetchPermissions(data.userId);
|
|
4162
|
+
* return { permissions };
|
|
4163
|
+
* }),
|
|
4164
|
+
* andAgent(
|
|
4165
|
+
* (data) => `Generate recommendations for user ${data.userId}`,
|
|
4166
|
+
* agent,
|
|
4167
|
+
* { schema: z.object({ recommendations: z.array(z.string()) }) }
|
|
4168
|
+
* )
|
|
4169
|
+
* ]),
|
|
4170
|
+
* andThen(async (data) => {
|
|
4171
|
+
* // data is now an array: [{ userInfo }, { permissions }, { recommendations }]
|
|
4172
|
+
* return { combined: data.flat() };
|
|
4173
|
+
* })
|
|
4174
|
+
* );
|
|
4175
|
+
* ```
|
|
4176
|
+
*
|
|
4177
|
+
* @param steps - Array of workflow steps to execute in parallel
|
|
4178
|
+
* @returns A workflow step that executes all steps simultaneously and returns their results as an array
|
|
4179
|
+
*/
|
|
4180
|
+
declare function andAll<INPUT, DATA, RESULT, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>>({ steps, ...config }: WorkflowStepParallelAllConfig<STEPS>): {
|
|
4181
|
+
type: "parallel-all";
|
|
4182
|
+
steps: InternalAnyWorkflowStep<INPUT, DATA, INFERRED_RESULT>[];
|
|
4183
|
+
execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<INFERRED_RESULT>;
|
|
4184
|
+
id: string;
|
|
4185
|
+
name: string;
|
|
4186
|
+
purpose: string;
|
|
4187
|
+
};
|
|
4188
|
+
|
|
4189
|
+
/**
|
|
4190
|
+
* Creates a race execution step that runs multiple steps simultaneously and returns the first completed result
|
|
4191
|
+
*
|
|
4192
|
+
* @example
|
|
4193
|
+
* ```ts
|
|
4194
|
+
* const w = createWorkflow(
|
|
4195
|
+
* andRace([
|
|
4196
|
+
* andThen(async (data) => {
|
|
4197
|
+
* // Fast operation
|
|
4198
|
+
* const cacheResult = await checkCache(data.query);
|
|
4199
|
+
* return { source: "cache", result: cacheResult };
|
|
4200
|
+
* }),
|
|
4201
|
+
* andThen(async (data) => {
|
|
4202
|
+
* // Slower operation
|
|
4203
|
+
* const dbResult = await queryDatabase(data.query);
|
|
4204
|
+
* return { source: "database", result: dbResult };
|
|
4205
|
+
* }),
|
|
4206
|
+
* andAgent(
|
|
4207
|
+
* (data) => `Generate fallback response for: ${data.query}`,
|
|
4208
|
+
* agent,
|
|
4209
|
+
* { schema: z.object({ source: z.literal("ai"), result: z.string() }) }
|
|
4210
|
+
* )
|
|
4211
|
+
* ]),
|
|
4212
|
+
* andThen(async (data) => {
|
|
4213
|
+
* // data is the result from whichever step completed first
|
|
4214
|
+
* return { finalResult: data.result, source: data.source };
|
|
4215
|
+
* })
|
|
4216
|
+
* );
|
|
4217
|
+
* ```
|
|
4218
|
+
*
|
|
4219
|
+
* @param steps - Array of workflow steps to execute in parallel
|
|
4220
|
+
* @returns A workflow step that executes all steps simultaneously and returns the result from the first step to complete
|
|
4221
|
+
*/
|
|
4222
|
+
declare function andRace<INPUT, DATA, RESULT, STEPS extends ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>, INFERRED_RESULT = InternalInferWorkflowStepsResult<STEPS>[number]>({ steps, ...config }: InternalWorkflowStepConfig<{
|
|
4223
|
+
steps: STEPS;
|
|
4224
|
+
}>): {
|
|
4225
|
+
type: "parallel-race";
|
|
4226
|
+
steps: InternalAnyWorkflowStep<INPUT, DATA, INFERRED_RESULT>[];
|
|
4227
|
+
execute: (data: InternalExtractWorkflowInputData<DATA>, state: InternalWorkflowStateParam<INPUT>) => Promise<INFERRED_RESULT>;
|
|
4228
|
+
id: string;
|
|
4229
|
+
name: string;
|
|
4230
|
+
purpose: string;
|
|
4231
|
+
};
|
|
4232
|
+
|
|
4233
|
+
/**
|
|
4234
|
+
* Creates a workflow from multiple and* functions
|
|
4235
|
+
* @param config - The workflow configuration
|
|
4236
|
+
* @param steps - Variable number of and* functions to execute
|
|
4237
|
+
* @returns A configured workflow instance
|
|
4238
|
+
*/
|
|
4239
|
+
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>;
|
|
4240
|
+
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>;
|
|
4241
|
+
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>;
|
|
4242
|
+
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>;
|
|
4243
|
+
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>;
|
|
4244
|
+
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>;
|
|
4245
|
+
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>;
|
|
4246
|
+
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>;
|
|
4247
|
+
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>;
|
|
4248
|
+
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>;
|
|
4249
|
+
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>;
|
|
4250
|
+
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>;
|
|
4251
|
+
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>;
|
|
4252
|
+
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>;
|
|
4253
|
+
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>;
|
|
4254
|
+
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>;
|
|
4255
|
+
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>;
|
|
4256
|
+
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>;
|
|
4257
|
+
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>;
|
|
4258
|
+
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>;
|
|
4259
|
+
|
|
4260
|
+
/**
|
|
4261
|
+
* Agent configuration for the chain
|
|
4262
|
+
*/
|
|
4263
|
+
type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
|
|
4264
|
+
schema: SCHEMA;
|
|
4265
|
+
};
|
|
4266
|
+
/**
|
|
4267
|
+
* A workflow chain that provides a fluent API for building workflows
|
|
4268
|
+
*
|
|
4269
|
+
* @example
|
|
4270
|
+
* ```ts
|
|
4271
|
+
* const workflow = createWorkflowChain({
|
|
4272
|
+
* id: "user-processing",
|
|
4273
|
+
* name: "User Processing Workflow",
|
|
4274
|
+
* purpose: "Process user data and generate personalized content",
|
|
4275
|
+
* input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
|
|
4276
|
+
* result: z.object({ processed: z.boolean(), content: z.string() })
|
|
4277
|
+
* })
|
|
4278
|
+
* .andThen(async (data) => {
|
|
4279
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
4280
|
+
* return { ...data, userInfo };
|
|
4281
|
+
* })
|
|
4282
|
+
* .andWhen(
|
|
4283
|
+
* (data) => data.userType === "admin",
|
|
4284
|
+
* async (data) => ({ ...data, permissions: ["read", "write", "delete"] })
|
|
4285
|
+
* )
|
|
4286
|
+
* .andAgent(
|
|
4287
|
+
* (data) => `Generate personalized content for ${data.userInfo.name}`,
|
|
4288
|
+
* agent,
|
|
4289
|
+
* { schema: z.object({ content: z.string() }) }
|
|
4290
|
+
* )
|
|
4291
|
+
* .andThen(async (data) => ({
|
|
4292
|
+
* processed: true,
|
|
4293
|
+
* content: data.content
|
|
4294
|
+
* }));
|
|
4295
|
+
*
|
|
4296
|
+
* const result = await workflow.run({ userId: "123", userType: "admin" });
|
|
4297
|
+
* ```
|
|
4298
|
+
*/
|
|
4299
|
+
declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema, RESULT_SCHEMA extends z.ZodTypeAny, CURRENT_DATA = WorkflowInput<INPUT_SCHEMA>> {
|
|
4300
|
+
private steps;
|
|
4301
|
+
private config;
|
|
4302
|
+
constructor(config: WorkflowConfig<INPUT_SCHEMA, RESULT_SCHEMA>);
|
|
4303
|
+
/**
|
|
4304
|
+
* Creates an agent step for a workflow
|
|
4305
|
+
*
|
|
4306
|
+
* @example
|
|
4307
|
+
* ```ts
|
|
4308
|
+
* const w = createWorkflowChain<{ name: string }>()
|
|
4309
|
+
* .andAgent(
|
|
4310
|
+
* (data) => `Generate a greeting for the user ${data.name}`,
|
|
4311
|
+
* agent,
|
|
4312
|
+
* { schema: z.object({ greeting: z.string() }) }
|
|
4313
|
+
* )
|
|
4314
|
+
* .andThen(async (data) => data.greeting)
|
|
4315
|
+
* ```
|
|
4316
|
+
*
|
|
4317
|
+
* @param task - The task (prompt) to execute for the agent, can be a string or a function that returns a string
|
|
4318
|
+
* @param agent - The agent to execute the task using `generateObject`
|
|
4319
|
+
* @param config - The config for the agent (schema) `generateObject` call
|
|
4320
|
+
* @returns A workflow step that executes the agent with the task
|
|
4321
|
+
*/
|
|
4322
|
+
andAgent<SCHEMA extends z.ZodTypeAny>(task: string | InternalWorkflowFunc<INPUT_SCHEMA, CURRENT_DATA, string>, agent: Agent<{
|
|
4323
|
+
llm: DangerouslyAllowAny;
|
|
4324
|
+
}>, config: AgentConfig<SCHEMA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, z.infer<SCHEMA>>;
|
|
4325
|
+
/**
|
|
4326
|
+
* Add a function step to the workflow
|
|
4327
|
+
*
|
|
4328
|
+
* @example
|
|
4329
|
+
* ```ts
|
|
4330
|
+
* const workflow = createWorkflowChain(config)
|
|
4331
|
+
* .andThen(async (data) => {
|
|
4332
|
+
* const processed = await someAsyncOperation(data.value);
|
|
4333
|
+
* return { ...data, processed };
|
|
4334
|
+
* })
|
|
4335
|
+
* .andThen(async (data) => {
|
|
4336
|
+
* const enriched = await enrichData(data.processed);
|
|
4337
|
+
* return { ...data, enriched };
|
|
4338
|
+
* });
|
|
4339
|
+
* ```
|
|
4340
|
+
*
|
|
4341
|
+
* @param fn - The async function to execute with the current workflow data
|
|
4342
|
+
* @returns A new chain with the function step added
|
|
4343
|
+
*/
|
|
4344
|
+
andThen<NEW_DATA>({ execute, ...config }: WorkflowStepFuncConfig<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, NEW_DATA>;
|
|
4345
|
+
/**
|
|
4346
|
+
* Add a conditional step that executes when a condition is true
|
|
4347
|
+
*
|
|
4348
|
+
* @example
|
|
4349
|
+
* ```ts
|
|
4350
|
+
* const workflow = createWorkflowChain(config)
|
|
4351
|
+
* .andWhen(
|
|
4352
|
+
* (data) => data.userType === "admin",
|
|
4353
|
+
* async (data) => ({ ...data, permissions: ["read", "write", "delete"] })
|
|
4354
|
+
* )
|
|
4355
|
+
* .andWhen(
|
|
4356
|
+
* (data) => data.value > 1000,
|
|
4357
|
+
* async (data) => ({ ...data, flagged: true, requiresReview: true })
|
|
4358
|
+
* )
|
|
4359
|
+
* .andWhen(
|
|
4360
|
+
* (data) => data.status === "pending",
|
|
4361
|
+
* (data) => andAgent(
|
|
4362
|
+
* `Process pending request for ${data.userId}`,
|
|
4363
|
+
* agent,
|
|
4364
|
+
* { schema: z.object({ processed: z.boolean() }) }
|
|
4365
|
+
* )
|
|
4366
|
+
* );
|
|
4367
|
+
* ```
|
|
4368
|
+
*
|
|
4369
|
+
* @param condition - Function that determines if the step should execute based on the current data
|
|
4370
|
+
* @param stepInput - Either a workflow step or an agent to execute when the condition is true
|
|
4371
|
+
* @returns A new chain with the conditional step added
|
|
4372
|
+
*/
|
|
4373
|
+
andWhen<NEW_DATA>({ condition, step, ...config }: WorkflowStepConditionalWhenConfig<WorkflowInput<INPUT_SCHEMA>, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, NEW_DATA | CURRENT_DATA>;
|
|
4374
|
+
/**
|
|
4375
|
+
* Add a parallel execution step that runs multiple steps simultaneously and waits for all to complete
|
|
4376
|
+
*
|
|
4377
|
+
* @example
|
|
4378
|
+
* ```ts
|
|
4379
|
+
* const workflow = createWorkflowChain(config)
|
|
4380
|
+
* .andAll([
|
|
4381
|
+
* async (data) => {
|
|
4382
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
4383
|
+
* return { userInfo };
|
|
4384
|
+
* },
|
|
4385
|
+
* async (data) => {
|
|
4386
|
+
* const permissions = await fetchPermissions(data.userId);
|
|
4387
|
+
* return { permissions };
|
|
4388
|
+
* },
|
|
4389
|
+
* (data) => andAgent(
|
|
4390
|
+
* `Generate recommendations for user ${data.userId}`,
|
|
4391
|
+
* agent,
|
|
4392
|
+
* { schema: z.object({ recommendations: z.array(z.string()) }) }
|
|
4393
|
+
* )
|
|
4394
|
+
* ])
|
|
4395
|
+
* .andThen(async (data) => {
|
|
4396
|
+
* // data is now an array: [{ userInfo }, { permissions }, { recommendations }]
|
|
4397
|
+
* return { combined: data.flat() };
|
|
4398
|
+
* });
|
|
4399
|
+
* ```
|
|
4400
|
+
*
|
|
4401
|
+
* @param steps - Array of workflow steps to execute in parallel
|
|
4402
|
+
* @returns A new chain with the parallel step added
|
|
4403
|
+
*/
|
|
4404
|
+
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>;
|
|
4405
|
+
/**
|
|
4406
|
+
* Add a race execution step that runs multiple steps simultaneously and returns the first completed result
|
|
4407
|
+
*
|
|
4408
|
+
* @example
|
|
4409
|
+
* ```ts
|
|
4410
|
+
* const workflow = createWorkflowChain(config)
|
|
4411
|
+
* .andRace([
|
|
4412
|
+
* async (data) => {
|
|
4413
|
+
* // Fast operation
|
|
4414
|
+
* const cacheResult = await checkCache(data.query);
|
|
4415
|
+
* return { source: "cache", result: cacheResult };
|
|
4416
|
+
* },
|
|
4417
|
+
* async (data) => {
|
|
4418
|
+
* // Slower operation
|
|
4419
|
+
* const dbResult = await queryDatabase(data.query);
|
|
4420
|
+
* return { source: "database", result: dbResult };
|
|
4421
|
+
* },
|
|
4422
|
+
* (data) => andAgent(
|
|
4423
|
+
* `Generate fallback response for: ${data.query}`,
|
|
4424
|
+
* agent,
|
|
4425
|
+
* { schema: z.object({ source: z.literal("ai"), result: z.string() }) }
|
|
4426
|
+
* )
|
|
4427
|
+
* ])
|
|
4428
|
+
* .andThen(async (data) => {
|
|
4429
|
+
* // data is the result from whichever step completed first
|
|
4430
|
+
* return { finalResult: data.result, source: data.source };
|
|
4431
|
+
* });
|
|
4432
|
+
* ```
|
|
4433
|
+
*
|
|
4434
|
+
* @param steps - Array of workflow steps to execute in parallel
|
|
4435
|
+
* @returns A new chain with the race step added
|
|
4436
|
+
*/
|
|
4437
|
+
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>;
|
|
4438
|
+
/**
|
|
4439
|
+
* Execute the workflow with the given input
|
|
4440
|
+
*
|
|
4441
|
+
* @example
|
|
4442
|
+
* ```ts
|
|
4443
|
+
* const workflow = createWorkflowChain({
|
|
4444
|
+
* id: "user-processing",
|
|
4445
|
+
* name: "User Processing Workflow",
|
|
4446
|
+
* purpose: "Process user data and generate personalized content",
|
|
4447
|
+
* input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
|
|
4448
|
+
* result: z.object({ processed: z.boolean(), content: z.string() })
|
|
4449
|
+
* })
|
|
4450
|
+
* .andThen(async (data) => {
|
|
4451
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
4452
|
+
* return { ...data, userInfo };
|
|
4453
|
+
* })
|
|
4454
|
+
* .andAgent(
|
|
4455
|
+
* (data) => `Generate personalized content for ${data.userInfo.name}`,
|
|
4456
|
+
* agent,
|
|
4457
|
+
* { schema: z.object({ content: z.string() }) }
|
|
4458
|
+
* )
|
|
4459
|
+
* .andThen(async (data) => ({
|
|
4460
|
+
* processed: true,
|
|
4461
|
+
* content: data.content
|
|
4462
|
+
* }));
|
|
4463
|
+
*
|
|
4464
|
+
* const result = await workflow.run({ userId: "123", userType: "admin" });
|
|
4465
|
+
* console.log(result); // { processed: true, content: "Hello John, here's your personalized content..." }
|
|
4466
|
+
* ```
|
|
4467
|
+
*
|
|
4468
|
+
* @param input - The input data for the workflow that matches the input schema
|
|
4469
|
+
* @returns The workflow execution result that matches the result schema
|
|
4470
|
+
*/
|
|
4471
|
+
run(input: WorkflowInput<INPUT_SCHEMA>): Promise<{
|
|
4472
|
+
executionId: string;
|
|
4473
|
+
startAt: Date;
|
|
4474
|
+
endAt: Date;
|
|
4475
|
+
status: "completed";
|
|
4476
|
+
result: z.TypeOf<RESULT_SCHEMA>;
|
|
4477
|
+
}>;
|
|
4478
|
+
}
|
|
4479
|
+
/**
|
|
4480
|
+
* Creates a new workflow chain with the given configuration
|
|
4481
|
+
*
|
|
4482
|
+
* @example
|
|
4483
|
+
* ```ts
|
|
4484
|
+
* const workflow = createWorkflowChain({
|
|
4485
|
+
* id: "data-processing",
|
|
4486
|
+
* name: "Data Processing Pipeline",
|
|
4487
|
+
* purpose: "Process and analyze user data with AI insights",
|
|
4488
|
+
* input: z.object({
|
|
4489
|
+
* userId: z.string(),
|
|
4490
|
+
* data: z.array(z.number()),
|
|
4491
|
+
* options: z.object({
|
|
4492
|
+
* includeAnalysis: z.boolean().default(true)
|
|
4493
|
+
* }).optional()
|
|
4494
|
+
* }),
|
|
4495
|
+
* result: z.object({
|
|
4496
|
+
* processed: z.boolean(),
|
|
4497
|
+
* summary: z.string(),
|
|
4498
|
+
* insights: z.array(z.string()).optional()
|
|
4499
|
+
* })
|
|
4500
|
+
* })
|
|
4501
|
+
* .andThen(async (data) => {
|
|
4502
|
+
* const processed = await processData(data.data);
|
|
4503
|
+
* return { ...data, processed };
|
|
4504
|
+
* })
|
|
4505
|
+
* .andWhen(
|
|
4506
|
+
* (data) => data.options?.includeAnalysis ?? true,
|
|
4507
|
+
* (data) => andAgent(
|
|
4508
|
+
* `Analyze the processed data: ${JSON.stringify(data.processed)}`,
|
|
4509
|
+
* agent,
|
|
4510
|
+
* { schema: z.object({ insights: z.array(z.string()) }) }
|
|
4511
|
+
* )
|
|
4512
|
+
* )
|
|
4513
|
+
* .andThen(async (data) => ({
|
|
4514
|
+
* processed: true,
|
|
4515
|
+
* summary: `Processed ${data.data.length} items for user ${data.userId}`,
|
|
4516
|
+
* insights: data.insights
|
|
4517
|
+
* }));
|
|
4518
|
+
*
|
|
4519
|
+
* const result = await workflow.run(...);
|
|
4520
|
+
* ```
|
|
4521
|
+
*
|
|
4522
|
+
* @param config - The workflow configuration including schemas and metadata
|
|
4523
|
+
* @returns A new workflow chain instance ready for building steps
|
|
4524
|
+
*/
|
|
4525
|
+
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>>;
|
|
4526
|
+
|
|
3825
4527
|
/**
|
|
3826
4528
|
* Enum defining the next action to take after a reasoning step.
|
|
3827
4529
|
*/
|
|
@@ -4746,4 +5448,4 @@ declare class VoltAgent {
|
|
|
4746
5448
|
shutdownTelemetry(): Promise<void>;
|
|
4747
5449
|
}
|
|
4748
5450
|
|
|
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 };
|
|
5451
|
+
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, 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 };
|