OpenWorkflow Workflow

Connect OpenWorkflow and use your own workflow backend behind the ViteHub API.

Use OpenWorkflow when you want to bring your own workflow backend while keeping the same ViteHub workflow files and runWorkflow() API.

Before you start

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/workflow@main openworkflow

Configure OpenWorkflow

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/workflow/nuxt'],
  workflow: {
    provider: 'openworkflow',
  },
})

Add workflow.ow when you want ViteHub to use an OpenWorkflow client directly.

Define a workflow

Create a workflow file for the job you want to run.

server/workflows/publish-draft.ts
export default defineWorkflow(async (input?: { title?: string }) => {
  return {
    title: input?.title?.trim() || 'Untitled draft',
  }
})

Start a workflow run

const run = await runWorkflow('publish-draft', {
  title: 'Ship weekly digest',
})

ViteHub still starts the workflow by the name of the file you created. OpenWorkflow changes where the run executes, not how you name or call it.

Add run lookup

getWorkflowRun(id) returns null unless you tell ViteHub how to fetch a run from your backend.

nuxt.config.ts
export default defineNuxtConfig({
  workflow: {
    provider: 'openworkflow',
    ow,
    getRun: async (id) => {
      return await ow.backend.getWorkflowRun({ workflowRunId: id })
    },
  },
})

What changes on OpenWorkflow

ConcernBehavior
Backend clientworkflow.ow passes the OpenWorkflow client to ViteHub so it can start runs for your workflow files.
Run lookupworkflow.getRun(id) teaches ViteHub how to fetch a run later when you call getWorkflowRun(id).
OpenWorkflow-only methodsrun.openworkflow.result() reads the result when your backend exposes it. run.native gives you the raw OpenWorkflow run object.
Choose OpenWorkflow when you want to keep ViteHub workflow files in your app but supply the execution backend yourself.