ViteHub

Workflow

Run durable, provider-backed workflows from Vite and Nitro with one portable API.

@vitehub/workflow gives Vite and Nitro apps one way to define long-running work, start a named workflow from request code, and observe the run through Cloudflare Workflows or Vercel.

Use Workflow when background work has multiple steps, needs a stable run id, or should be visible after the request that started it has already returned.

import { runWorkflow } from '@vitehub/workflow'
import type { WelcomePayload } from '../workflows/welcome'

export default defineEventHandler(async (event) => {
  const payload = await readBody<WelcomePayload>(event)
  const run = await runWorkflow('welcome', payload)

  return { ok: true, run }
})

What Workflow solves

Queues are a good fit for one handler. Workflows are better when the operation has an identity and the caller may need to ask what happened later.

Workflow keeps that boundary explicit:

Named flows

Put multi-step work behind a discovered defineWorkflow() definition instead of scattering logic across request handlers.

Portable starts

Call runWorkflow() or deferWorkflow() the same way on Cloudflare and Vercel.

Run observation

Use a normalized run id, provider, status, result, and metadata shape in app code.

Generated registry

Let ViteHub discover workflow files and generate the runtime registry for the active framework.

One portable flow

The same application shape works across providers:

  1. Register the Vite plugin or Nitro module.
  2. Choose cloudflare or vercel in workflow.provider.
  3. Define a named workflow with defineWorkflow().
  4. Start it with runWorkflow(name, payload).
  5. Check it later with getWorkflowRun(name, id) when the provider can report status.
Provider setup belongs in app config and generated deployment output. Workflow definitions and start calls should stay provider-neutral whenever possible.

Discovery model

Vite discovers workflow definitions from *.workflow.ts files and server/workflows/**.

The workflow name comes from the path without the .workflow suffix. src/email/welcome.workflow.ts becomes email/welcome. server/workflows/welcome.ts becomes welcome.

Supported providers

Cloudflare
Use Cloudflare Workflows with generated Wrangler bindings and workflow entrypoint classes.
Vercel
Use Vercel deployment output while keeping the ViteHub workflow runtime API in app code.

Start here

Start with Quickstart for the smallest complete setup. Use the primitive comparison when you are deciding between KV, Blob, Queue, Sandbox, Workflow, or inline request code.

Next steps

Quickstart
Define a welcome workflow and start it from a route.
Usage
Use typed payloads, deferred starts, stable run ids, and status checks.
Runtime API
Review exports, signatures, options, status values, and helper functions.
Troubleshooting
Fix unknown workflows, missing bindings, disabled config, and provider mismatches.
Copyright © 2026