Workflow state reader
Workflow state reader helpers inspect the public WorkflowState returned by workflow.getWorkflowRunById(). Use them to recover suspended runs and inspect resume labels. They also read step payloads or outputs without parsing raw workflow snapshots.
Usage exampleUsage example的直接链接
import { createWorkflowStateReader } from '@mastra/core/workflows'
const state = await workflow.getWorkflowRunById('run-123')
if (state) {
const reader = createWorkflowStateReader(state)
const suspendedStep = reader.getSuspendedStep()
const labels = reader.getResumeLabels()
console.log(reader.getStatus())
console.log(reader.getStepOutput('extract-data'))
console.log(suspendedStep?.path)
console.log(labels.approve)
}
FunctionsFunctions的直接链接
createWorkflowStateReader(state)createworkflowstatereaderstate的直接链接
Creates a reader object with methods bound to one WorkflowState.
const reader = createWorkflowStateReader(state)
const suspendedStep = reader.getSuspendedStep()
getWorkflowStepOutput(state, stepId)getworkflowstepoutputstate-stepid的直接链接
Returns the output for a step ID, including nested workflow dot paths such as parent.child. For foreach steps, returns one entry per iteration. Suspended iterations can have undefined output entries.
const output = getWorkflowStepOutput(state, 'extract-data')
getWorkflowStepPayload(state, stepId)getworkflowsteppayloadstate-stepid的直接链接
Returns the payload that was passed to a step. For foreach steps, returns one entry per iteration.
const payload = getWorkflowStepPayload(state, 'extract-data')
getWorkflowSuspendedStep(state)getworkflowsuspendedstepstate的直接链接
Returns the first suspended step from the workflow state. When multiple steps are suspended, ordering follows the order stored in suspendedPaths.
const suspendedStep = getWorkflowSuspendedStep(state)
getWorkflowSuspendedSteps(state)getworkflowsuspendedstepsstate的直接链接
Returns all suspended steps from the workflow state. Each result includes the top-level step ID, resume path, execution path, suspend payload, suspend output, and matching resume labels.
const suspendedSteps = getWorkflowSuspendedSteps(state)
getWorkflowResumeLabel(state, label)getworkflowresumelabelstate-label的直接链接
Returns a resume label by name.
const label = getWorkflowResumeLabel(state, 'approve')
getWorkflowResumeLabels(state)getworkflowresumelabelsstate的直接链接
Returns all resume labels from the workflow state.
const labels = getWorkflowResumeLabels(state)
Reader methodsReader methods的直接链接
createWorkflowStateReader(state) returns the following methods:
getStatus:
getResult:
getError:
getStepOutput:
getStepPayload:
getSuspendedStep:
getSuspendedSteps:
getResumeLabel:
getResumeLabels:
NotesNotes的直接链接
requestContext and tracingContext are only returned by workflow.getWorkflowRunById() when explicitly requested with fields.