Step
The Step class defines individual units of work within a workflow, encapsulating execution logic, data validation, and input/output handling.
Usage
const processOrder = new Step({
id: "processOrder",
inputSchema: z.object({
orderId: z.string(),
userId: z.string()
}),
outputSchema: z.object({
status: z.string(),
orderId: z.string()
}),
execute: async ({ context, runId }) => {
return {
status: "processed",
orderId: context.orderId
};
}
});
Constructor Parameters
id:
string
Unique identifier for the step
inputSchema:
z.ZodSchema
Zod schema to validate input data before execution
outputSchema:
z.ZodSchema
Zod schema to validate step output data
payload:
Record<string, any>
Static data to be merged with variables
execute:
(params: ExecuteParams) => Promise<any>
Async function containing step logic
ExecuteParams
context:
StepContext
Access to workflow context and step results
runId:
string
Unique identifier for current workflow run
suspend:
() => Promise<void>
Function to suspend step execution
Related