output
    Preparing search index...

    Function workflow

    • 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 fn handler function.

      The schema of the input that the function receives as the first argument is defined by inputSchema.

      The output of the fn handler must match outputSchema; otherwise, a validation error is raised.

      Type Parameters

      • InputSchema extends AnyZodSchema = undefined

        Zod schema of the fn's input.

      • OutputSchema extends AnyZodSchema = undefined

        Zod schema of the fn's return.

      Parameters

      • params: {
            aliases?: string[];
            description?: string;
            fn: WorkflowFunction<InputSchema, OutputSchema>;
            inputSchema?: InputSchema;
            name: string;
            options?: WorkflowOptions;
            outputSchema?: OutputSchema;
        }

        Workflow parameters

        • Optionalaliases?: string[]

          Alternative names that resolve to this workflow. Useful when renaming a workflow while maintaining backward compatibility with existing callers.

        • Optionaldescription?: string

          Description of the workflow

        • fn: WorkflowFunction<InputSchema, OutputSchema>

          A function containing the workflow code

        • OptionalinputSchema?: InputSchema

          Zod schema for workflow input

        • name: string

          Human-readable workflow name (must start with a letter or underscore, followed by letters, numbers, or underscores).

        • Optionaloptions?: WorkflowOptions

          Optional workflow options.

        • OptionaloutputSchema?: OutputSchema

          Zod schema for workflow output

      Returns WorkflowFunctionWrapper<WorkflowFunction<InputSchema, OutputSchema>>

      The same handler function set at fn with a different signature

      • Workflows should respect the same limitations as Temporal workflows.
      • Workflows can invoke steps or evaluators and cannot perform I/O directly.
      • The workflow 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;
      }
      } )

      FatalError