Skip to content

API reference

Every public export, grouped by entry point. Types are marked (type); everything else is a value you can call or read.

No heavy dependencies — importing this pulls in neither pg, pg-boss, nor the AI SDK.

Export
createWorkflowEngine the engine factory
createStepHandlerRegistry type → handler + policy registry
WorkflowEngine (type) the object createWorkflowEngine returns
WorkflowEngineDeps, WorkflowEngineConfig (type) constructor arguments

Engine methods: validateDefinition, startWorkflow, start, executeStep, resumeStep, handleStepExhausted, recoverStuckWorkflows, cancelWorkflow, getWorkflowStatus, listWorkflows.

defineStep, defineSleepStep, defineWaitStep, defineMapStep, defineSubWorkflowStep, buildWorkflow

(type) TypedStep, TypedStepContext, TypedWorkflow, StepOutput, WorkflowOutput, StepDefinition, WorkflowDefinition, RetryPolicy, StartOptions

retryableError, nonRetryableError, markRetryable, isRetryableError, explicitRetryability

ok, err

(type) Result, FlowError, FlowErrorShape, StepError, WorkflowNotFoundError, InvalidWorkflowDefinitionError, StepHandlerNotFoundError

createInMemoryWorkflowStore

(type) WorkflowStore, TransactionalScope, CreateWorkflowParams, CreateWorkflowStep, CreatedWorkflow, WorkflowCreatedResult, CompleteStepParams, FailStepParams, FinishWorkflowParams, AddChildStep, ListWorkflowsFilters, WorkflowRecord, StepRecord, WorkflowWithSteps, WorkflowStatus, StepStatus, WorkflowId, StepId

(type) Dispatcher, DispatchStepPayload, EnqueueOptions

createInMemoryStepGate

(type) StepGate, StepGateRequest, StepGateDecision, ConcurrencyRule, RateRule, InMemoryStepGateConfig

(type) StepHandler, StepExecutionContext, StepHandlerRegistry, StepRegistration, StepCompensateHandler, StepCompensationContext

(type) WorkflowHooks, BeforeStartArgs, BeforeStartResult, BuildStepContextArgs, AfterStepArgs, WorkflowCompletedArgs

createRecordingObserver, createRecordingTracer, noopObserver, noopTracer, noopLogger

(type) FlowObserver, FlowTracer, FlowEvent, FlowEventType, FlowSpan, RecordedSpan, RecordingObserver, RecordingTracer, Logger, LogAttributes

toPublicWorkflow, toPublicStep, toDisplayStepStatus, STEP_DISPLAY_STATUS, PUBLIC_WORKFLOW_SCHEMA, PUBLIC_WORKFLOW_STEP_SCHEMA, WORKFLOW_STATUS_SCHEMA, STEP_DISPLAY_STATUS_SCHEMA

(type) PublicWorkflow, PublicWorkflowStep, StepDisplayStatus

Requires pg.

createPgWorkflowStore — batteries-included, owns its pool and transactions createWorkflowStore — inject your own SqlExecutor (e.g. RLS-scoped) applySchema — dev/test convenience for running DDL

(type) PgWorkflowStoreDeps, WorkflowStoreDeps

poolExecutor, toExecutor

(type) SqlExecutor, SqlResult

createPgStepGate (pool) · createStepGate (injected executor) · flowGateDdl, FLOW_GATE_DDL

(type) PgStepGateConfig, StepGateConfig

createPgEventSink (pool) · createEventSink (injected executor) · readFlowEvents · flowEventDdl, FLOW_EVENT_DDL

(type) PgEventSink, PgEventSinkDeps, EventSinkDeps

flowStoreDdl(schema?), FLOW_STORE_DDL, flowGateDdl({ schema?, rateBucketTable?, leaseTable? }), FLOW_GATE_DDL, flowEventDdl(schema?), FLOW_EVENT_DDL, createSchemaDdl(schema)

Requires pg-boss.

createPgBossDispatcher, ensureStepQueue createPgBossStepWorker, createPgBossDlqWorker createPgBossScheduler, createPgBossStartWorker, ensureStartQueue DEFAULT_STEP_QUEUE_CONFIG, WIRE_STEP_PAYLOAD_SCHEMA, WIRE_START_PAYLOAD_SCHEMA resolveStartIdempotencyKey

(type) PgBossDispatcherDeps, PgBossStepWorkerDeps, PgBossStepWorkerOptions, PgBossDlqWorkerDeps, PgBossSchedulerDeps, PgBossStartWorkerDeps, StepQueueConfig, ScheduleStartInput, StepJobProcessor, DlqProcessor, StartJobProcessor, WireStepPayload, WireStartPayload, StartJobContext

The two WIRE_* schemas are the cross-process contract: a worker parses the job body with them before routing to a partition’s engine.

StartJobContext is what a start worker hands its processor — the wire payload plus jobId and a per-delivery idempotencyKey, computed by resolveStartIdempotencyKey (exported so you can reproduce it). See cron idempotency.

Requires ai and @ai-sdk/provider.

defineAiStep, buildAiWorkflow, createAiWorkflowHooks

(type) AiContext, AiTypedStep, CreateAiWorkflowHooksDeps, AiModelResolver, AiUsageRecorder, AiQuotaPolicy

AiModelResolver, AiUsageRecorder and AiQuotaPolicy are the three seams you implement.

createInstrumentedModel, createUsageAccumulator createInstrumentedEmbeddingModel, createEmbeddingUsageAccumulator

(type) UsageAccumulator, AccumulatedUsage, EmbeddingUsageAccumulator, EmbeddingAccumulatedUsage

createCostEstimator, estimateCostMicros, DEFAULT_MODEL_PRICING

(type) CostEstimator, CostEstimatorOptions, ModelPricing, TokenUsage

createAiQuotaService, DEFAULT_AI_QUOTA

(type) AiQuotaService, AiQuotaStore, AiQuotaConfig, AiQuotaConfigResolver, AiQuotaExceededError, AiQuotaExceededReason, AiUsageCountQuery, CreateAiQuotaServiceDeps

createAiUsageAggregationService, toIsoDate, monthStartOf

(type) AiUsageAggregationService, AiUsageStore, UsageSummaryRow, UsageByTypeRow, CurrentQuotaUsage, DailyUsageDelta, WorkflowUsageInput, EmbeddingUsageInput, AiUsageRangeQuery, AiUsageError, CreateAiUsageAggregationServiceDeps