Step Configuration
Steps are the building blocks of a workflow. Each step defines an action to execute and how to handle its data.
We are adding explicit OpenTelemetry tracing to each step, so that you can see the inputs and outputs of each step in your observability platform.
API Reference
addStep()
workflow.addStep('stepId', {
action: async (data) => { /* ... */ },
inputSchema: z.object({ /* ... */ }),
variables: { /* ... */ },
payload: { /* ... */ }
});
action:
(data: TInput) => Promise<TOutput>
Async function that executes the step logic. Receives combined data from variables and payload.
inputSchema?:
z.ZodType
Zod schema to validate input data before execution
variables?:
Record<string, VariableReference>
Maps data from previous steps or trigger data
payload?:
Record<string, any>
Static data to merge with variables
Examples
Basic Step
workflow.addStep('processOrder', {
action: async (data) => {
return {
status: 'processed',
orderId: data.id
};
}
});
With Input Validation
workflow.addStep('validateUser', {
inputSchema: z.object({
userId: z.string(),
email: z.string().email()
}),
action: async (data) => {
const { userId, email } = data;
// Process validated data
return { isValid: true };
}
});
With Variables
workflow.addStep('sendEmail', {
variables: {
userId: { stepId: 'trigger', path: 'user.id' },
orderDetails: { stepId: 'processOrder', path: 'result' }
},
action: async (data) => {
const { userId, orderDetails } = data;
// Send email using data from previous steps
return { sent: true };
}
});
With Static Payload
workflow.addStep('createInvoice', {
variables: {
orderId: { stepId: 'processOrder', path: 'orderId' }
},
payload: {
currency: 'USD',
taxRate: 0.2
},
action: async (data) => {
const { orderId, currency, taxRate } = data;
// Create invoice with combined data
return { invoiceId: 'INV-123' };
}
});