惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
有赞技术团队
有赞技术团队
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
The Cloudflare Blog
B
Blog
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
U
Unit 42
D
Docker
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
A
About on SuperTechFans

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Workflow Globals Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors
Storage
2026-06-12 · via Workflow SDK Documentation

Query workflow runs, steps, hooks, and the underlying event log via the World storage interface.

The World storage interface exposes four sub-interfaces for querying workflow data:

  • world.events — The append-only event log. This is the source of truth for all workflow state. See Event Sourcing for background.
  • world.runs, world.steps, world.hooks — Materialized views derived from the event log, provided as convenience accessors for the most common query patterns.
import { getWorld } from "workflow/runtime";

const world = await getWorld(); 

The event log drives all workflow state. Use it for audit trails, debugging, and programmatic run cancellation.

events.create()

Create a new event for a workflow run. Most commonly used to cancel a run.

await world.events.create(runId, { 
  eventType: "run_cancelled", 
}); 
ParameterTypeDescription
runIdstring | nullThe workflow run ID (null only for run_created events, where the server generates an ID)
dataCreateEventRequestEvent data including eventType
paramsobjectOptional parameters

Returns: EventResult — The created event and the affected entity (run/step/hook)

events.get()

Retrieve a single event by run ID and event ID.

const event = await world.events.get(runId, eventId); 
ParameterTypeDescription
runIdstringThe workflow run ID
eventIdstringThe event ID

Returns: Event

events.list()

List events for a run with cursor pagination.

const result = await world.events.list({ runId, pagination: { cursor } }); 
ParameterTypeDescription
params.runIdstringFilter events by run ID
params.pagination.cursorstringCursor for the next page

Returns: { data: Event[], cursor?: string }

events.listByCorrelationId()

List events that share a correlation ID, useful for tracing related events across runs.

const result = await world.events.listByCorrelationId({ 
  correlationId: "order-123",
}); 
ParameterTypeDescription
params.correlationIdstringThe correlation ID to filter by
params.pagination.cursorstringCursor for the next page

Returns: { data: Event[], cursor?: string }

Event Types

CategoryTypes
Runrun_created, run_started, run_completed, run_failed, run_cancelled
Stepstep_created, step_started, step_completed, step_failed, step_retrying
Hookhook_created, hook_received, hook_disposed, hook_conflict
Waitwait_created, wait_completed

Materialized from run events. Use it to list and inspect workflow runs.

runs.get()

const run = await world.runs.get(runId); 
ParameterTypeDescription
runIdstringThe workflow run ID
params.resolveData'all' | 'none'Whether to include input/output data. Default: 'all'

Returns: WorkflowRun (or WorkflowRunWithoutData when resolveData: 'none')

runs.list()

const result = await world.runs.list({ 
  pagination: { cursor },
}); 
ParameterTypeDescription
params.pagination.cursorstringCursor for the next page
params.resolveData'all' | 'none'Whether to include input/output data

Returns: { data: WorkflowRun[], cursor?: string }

Cancelling Runs

To cancel a run, create a run_cancelled event via world.events.create() (see world.events above), or use the CLI or Web UI helpers.

WorkflowRun Type

FieldTypeDescription
runIdstringUnique run identifier
statusstring'running', 'completed', 'failed', 'cancelled'
workflowNamestringMachine-readable workflow identifier
inputanyWorkflow input data (when resolveData: 'all')
outputanyWorkflow output data (when resolveData: 'all')
erroranyError data if the run failed
startedAtstringISO timestamp when the run started
completedAtstring | nullISO timestamp when the run completed

workflowName is a machine-readable identifier like workflow//./src/workflows/order//processOrder. Use parseWorkflowName() from workflow/observability to extract a display-friendly name.


Materialized from step events. Use it to list steps, inspect their input/output, and build progress dashboards.

steps.get()

const step = await world.steps.get(runId, stepId); 
ParameterTypeDescription
runIdstring | undefinedThe workflow run ID
stepIdstringThe step ID
params.resolveData'all' | 'none'Whether to include input/output data. Default: 'all'

Returns: Step (or StepWithoutData when resolveData: 'none')

steps.list()

const result = await world.steps.list({ 
  runId,
  pagination: { cursor },
}); 
ParameterTypeDescription
params.runIdstringFilter steps by run ID
params.pagination.cursorstringCursor for the next page
params.resolveData'all' | 'none'Whether to include input/output data

Returns: { data: Step[], cursor?: string }

Step Type

FieldTypeDescription
runIdstringParent workflow run ID
stepIdstringUnique step identifier
stepNamestringMachine-readable step identifier
statusstring'running', 'completed', 'failed'
inputanyStep input data (when resolveData: 'all')
outputanyStep output data (when resolveData: 'all')
erroranyError data if the step failed
attemptnumberCurrent retry attempt number
startedAtstringISO timestamp when the step started
completedAtstring | nullISO timestamp when the step completed
retryAfterstring | nullISO timestamp for next retry attempt

Step I/O is serialized using the devalue format. Use hydrateResourceIO() from workflow/observability to deserialize it for display. See hydrateResourceIO().

stepName is a machine-readable identifier like step//./src/workflows/order//processPayment. Use parseStepName() from workflow/observability to extract the shortName for UI display.


Materialized from hook events. Hooks are pause points in workflows that wait for external input. Use this interface to look up hooks by ID or token, inspect metadata, and build UIs for pending approvals.

hooks.get()

const hook = await world.hooks.get(hookId); 
ParameterTypeDescription
hookIdstringThe hook ID

Returns: Hook

hooks.getByToken()

Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.

const hook = await world.hooks.getByToken(token); 
ParameterTypeDescription
tokenstringThe hook token

Returns: Hook

hooks.list()

const result = await world.hooks.list({ 
  pagination: { cursor },
}); 
ParameterTypeDescription
params.pagination.cursorstringCursor for the next page

Returns: { data: Hook[], cursor?: string }

Hook Type

FieldTypeDescription
runIdstringParent workflow run ID
hookIdstringUnique hook identifier
tokenstringHook token for resuming
ownerIdstringOwner (team/user) ID
projectIdstringProject ID
environmentstringDeployment environment
metadataobjectCustom metadata attached to the hook
isWebhookbooleanWhether this is a webhook-style hook

import { getWorld } from "workflow/runtime";

const world = await getWorld();
let cursor: string | undefined;

const runs = await world.runs.list({ 
  pagination: { cursor },
}); 

cursor = runs.cursor; // pass to next call for pagination

Get a Run — Full Data vs. Metadata Only

import { getWorld } from "workflow/runtime";

const world = await getWorld();

// Full data (default) — includes serialized input/output
const run = await world.runs.get(runId); 

// Metadata only — lighter, no I/O loaded
const lightweight = await world.runs.get(runId, { 
  resolveData: "none", 
}); 

List Steps for a Progress Dashboard

import { getWorld } from "workflow/runtime";
import { parseStepName } from "workflow/observability"; 

const world = await getWorld();
const steps = await world.steps.list({ 
  runId,
  resolveData: "none",
}); 

const progress = steps.data.map((step) => {
  const parsed = parseStepName(step.stepName); 
  return {
    stepId: step.stepId,
    displayName: parsed?.shortName ?? step.stepName, 
    status: step.status,
  };
});

Hydrate Step I/O

import { getWorld } from "workflow/runtime";
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; 

const world = await getWorld();
const step = await world.steps.get(runId, stepId); 
const hydrated = hydrateResourceIO(step, observabilityRevivers); 
console.log(hydrated.input, hydrated.output);

Cancel a Run

import { getWorld } from "workflow/runtime";

const world = await getWorld();
await world.events.create(runId, { 
  eventType: "run_cancelled", 
}); 

Look Up Hook by Token

import { getWorld } from "workflow/runtime";

const world = await getWorld();
const hook = await world.hooks.getByToken(token); 
console.log(hook.runId, hook.metadata); 

List Events for Audit Trail

import { getWorld } from "workflow/runtime";

const world = await getWorld();
const events = await world.events.list({ runId }); 

for (const event of events.data) {
  console.log(event.eventType, event.createdAt);
}