Zod schema of the fn's input.
Zod schema of the fn's return.
Workflow parameters
Optionaldescription?: stringDescription of the workflow
A function containing the workflow code
OptionalinputSchema?: InputSchemaZod schema for workflow input
Human-readable workflow name (must start with a letter or underscore, followed by letters, numbers, or underscores).
Optionaloptions?: WorkflowOptionsOptional workflow options.
OptionaloutputSchema?: OutputSchemaZod schema for workflow output
The same handler function set at fn with a different signature
name needs to be unique across all workflows in the project.import { step } from './my_steps.ts';
workflow( {
name: 'main',
description: 'A generic workflow',
inputSchema: z.object( {
value: z.number()
} ),
outputSchema: z.string(),
fn: async input => {
const result = await step( input.value );
return result as string;
}
} )
import { step } from './my_steps.ts';
workflow( {
name: 'main',
description: 'A generic workflow',
inputSchema: z.object( {
value: z.number()
} ),
fn: async input => {
await step( input.value );
}
} )
import { step } from './my_steps.ts';
workflow( {
name: 'main',
description: 'A generic workflow',
outputSchema: z.string(),
fn: async () => {
const result = await step();
return result as string;
}
} )
import { step } from './my_steps.ts';
workflow( {
name: 'main',
description: 'A generic workflow',
fn: async () => {
await step();
}
} )
The function continueAsNew (same as Temporal) can be used to create a new workflow with the same ID and pass different input.
import { step } from './my_steps.ts';
workflow( {
name: 'main',
description: 'A generic workflow',
inputSchema: z.object( {
value: z.number()
} ),
outputSchema: z.string(),
fn: async ( input, context ) => {
const result = await step( input.value );
if ( context.control.isContinueAsNewSuggested() ) {
return context.control.continueAsNew( input );
}
return result as string;
}
} )
Creates a workflow.
A workflow is an orchestration of one or more steps. It is translated to a Temporal Workflow.
The workflow logic is defined in the
fnhandler function.The schema of the input that the function receives as the first argument is defined by
inputSchema.The output of the
fnhandler must matchoutputSchema; otherwise, a validation error is raised.