Skip to main content

Interface: EnhancedStageContext<TInput, TConfig, TContext>

Defined in: packages/workflow-engine/src/core/stage-factory.ts:83

Enhanced stage context with fluent helpers

Extends​

  • Omit<StageContext<TInput, TConfig, TContext>, "onProgress" | "step">

Type Parameters​

TInput​

TInput

TConfig​

TConfig

TContext​

TContext extends Record<string, unknown>

Properties​

abortSignal​

abortSignal: AbortSignal

Defined in: packages/workflow-engine/src/core/stage.ts:157

Aborted when the run is cancelled while this invocation executes, or when the worker's job lease is lost. Named abortSignal (not signal) so it is not confused with step.waitForSignal. Pass it to fetch, ctx.ai.*, or anything else that can be interrupted; the engine discards the outcome of a cancelled invocation either way, so honouring it only saves the work. abortSignal.reason is a StageAbortedError whose reason is "cancelled" or "lease-lost". Never fires for a context built without a host loop (a direct job.execute dispatch).

Inherited from​

Omit.abortSignal


ai​

readonly ai: AIHelper

Defined in: packages/workflow-engine/src/core/stage.ts:167

AI helper scoped to workflow.${workflowRunId}.stage.${stageId}. It is created lazily when first accessed.

Inherited from​

Omit.ai


aiLogger​

readonly aiLogger: AICallLogger

Defined in: packages/workflow-engine/src/core/stage.ts:169

Logger used by the scoped AI helper for call-cost records.

Inherited from​

Omit.aiLogger


annotate​

annotate: AnnotateFn

Defined in: packages/workflow-engine/src/core/stage.ts:185

Inherited from​

Omit.annotate


config​

config: TConfig

Defined in: packages/workflow-engine/src/core/stage.ts:134

Inherited from​

Omit.config


input​

input: TInput

Defined in: packages/workflow-engine/src/core/stage.ts:133

Inherited from​

Omit.input


log​

log: (level, message, meta?) => void

Defined in: packages/workflow-engine/src/core/stage.ts:177

Convenience alias for onLog; returns void.

Parameters​

level​

LogLevel

message​

string

meta?​

Record<string, unknown>

Returns​

void

Inherited from​

Omit.log


onLog​

onLog: (level, message, meta?) => void

Defined in: packages/workflow-engine/src/core/stage.ts:171

Emit a log entry without waiting for persistence; returns void.

Parameters​

level​

LogLevel

message​

string

meta?​

Record<string, unknown>

Returns​

void

Inherited from​

Omit.onLog


onProgress​

onProgress: (update) => void

Defined in: packages/workflow-engine/src/core/stage-factory.ts:101

Report progress for this stage.

stageId and stageName are auto-filled from the current stage's context, so you only need to pass { progress, message }. You may still pass explicit stageId/stageName to override the auto-filled values.

Parameters​

update​

Omit<ProgressUpdate, "stageId" | "stageName"> & Partial<Pick<ProgressUpdate, "stageId" | "stageName">>

Returns​

void

Example​

ctx.onProgress({ progress: 50, message: "Halfway done" });

optional​

optional: <K>(stageId) => TContext[K] | undefined

Defined in: packages/workflow-engine/src/core/stage-factory.ts:121

Optionally get output from a previous stage (returns undefined if not found)

Type Parameters​

K​

K extends string | number | symbol

Parameters​

stageId​

K

Returns​

TContext[K] | undefined

Example​

const optionalData = ctx.optional("optional-stage");
if (optionalData) { ... }

require​

require: <K>(stageId) => TContext[K]

Defined in: packages/workflow-engine/src/core/stage-factory.ts:112

Require output from a previous stage (throws if not found)

Type Parameters​

K​

K extends string | number | symbol

Parameters​

stageId​

K

Returns​

TContext[K]

Example​

const { extractedData } = ctx.require("data-extraction");

resumeState?​

optional resumeState?: object

Defined in: packages/workflow-engine/src/core/stage.ts:137

batchId​

batchId: string

maxWaitTime?​

optional maxWaitTime?: number

Milliseconds.

Deprecated​

Prefer pollConfig.maxWaitTime. Back-filled by defineStage() for async-batch checkCompletion; goes away with that mode, not before.

metadata?​

optional metadata?: Record<string, unknown>

pollInterval?​

optional pollInterval?: number

Milliseconds.

Deprecated​

Prefer pollConfig.pollInterval. Back-filled by defineStage() for async-batch checkCompletion; goes away with that mode, not before.

statusUrl?​

optional statusUrl?: string

submittedAt?​

optional submittedAt?: string

ISO date string.

Deprecated​

Read timing from pollConfig instead. defineStage() still back-fills this for checkCompletion implementations of the async-batch mode; it goes away with that mode, not before.

Inherited from​

Omit.resumeState


stageId​

stageId: string

Defined in: packages/workflow-engine/src/core/stage.ts:126

Inherited from​

Omit.stageId


stageName​

stageName: string

Defined in: packages/workflow-engine/src/core/stage.ts:128

Inherited from​

Omit.stageName


stageNumber​

stageNumber: number

Defined in: packages/workflow-engine/src/core/stage.ts:127

Inherited from​

Omit.stageNumber


stageRecordId?​

optional stageRecordId?: string

Defined in: packages/workflow-engine/src/core/stage.ts:130

Database record ID for this stage execution (for logging to persistence)

Inherited from​

Omit.stageRecordId


step​

step: StepApi

Defined in: packages/workflow-engine/src/core/stage-factory.ts:89

Durable, replayable side effects and waits.


storage​

storage: StageStorage

Defined in: packages/workflow-engine/src/core/stage.ts:188

Inherited from​

Omit.storage


workflowContext​

workflowContext: Partial<TWorkflowContext>

Defined in: packages/workflow-engine/src/core/stage.ts:191

Inherited from​

Omit.workflowContext


workflowRunId​

workflowRunId: string

Defined in: packages/workflow-engine/src/core/stage.ts:125

Inherited from​

Omit.workflowRunId