ViteHub

Observe a workflow run

Read normalized workflow status and result metadata from a route.

Use getWorkflowRun() when a caller has a workflow name and run id.

const run = await getWorkflowRun('welcome', id)

Add a status route

Every status route follows the same shape:

  1. Read the workflow run id from the request path.
  2. Return getWorkflowRun(name, id).
  3. Map missing ids to the framework's normal error response.
src/server.ts
import { createError, H3 } from 'h3'
import { getWorkflowRun } from '@vitehub/workflow'

const app = new H3()

app.get('/api/workflow/:id', async (event) => {
  const id = event.context.params?.id
  if (!id) {
    throw createError({
      statusCode: 400,
      statusMessage: 'Missing workflow run id.',
    })
  }

  return await getWorkflowRun('welcome', id)
})

export default app

Handle status values

Workflow status is normalized across providers:

StatusMeaning
queuedThe provider accepted the start.
runningThe provider reports active work.
completedThe workflow finished successfully.
failedThe workflow failed.
unknownThe provider cannot resolve that run id from this runtime.

Persist what the app owns

Provider status is useful for infrastructure state. Application state still belongs in your app data model when users need durable history.

Store the workflow run id with the domain record that started the workflow:

await saveSignup({
  email: payload.email,
  workflowRunId: run.id,
})

Then use the stored id in your status route.

Copyright © 2026