output-sdk
    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

      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