docs/src/content/en/reference/streaming/workflows/timeTravelStream.mdx
The .timeTravelStream() method re-executes a workflow starting from any specific step with streaming events. This allows you to receive real-time updates during time travel execution while maintaining full visibility into each step's progress.
const run = await workflow.createRun()
const output = run.timeTravelStream({
step: 'step2',
inputData: { value: 10 },
})
// Process events as they arrive
for await (const event of output.fullStream) {
console.log(event.type, event.payload)
}
// Get the final result
const result = await output.result
All parameters are the same as Run.timeTravel(). See the timeTravel reference for detailed parameter documentation.
<PropertiesTable content={[ { name: 'output', type: 'WorkflowRunOutput<WorkflowResult<TState, TInput, TOutput, TSteps>>', description: 'An object containing both the stream and result promise', }, { name: 'output.fullStream', type: 'ReadableStream<WorkflowStreamEvent>', description: 'A readable stream that emits workflow events as execution progresses', }, { name: 'output.result', type: 'Promise<WorkflowResult<TState, TInput, TOutput, TSteps>>', description: 'A promise that resolves to the final workflow execution result', }, { name: 'output.traceId', type: 'string', isOptional: true, description: 'The trace ID associated with this execution when Tracing is enabled', }, ]} />
The stream emits various workflow events during execution:
workflow-step-start: Emitted when a step begins executionworkflow-step-finish: Emitted when a step completes successfullyworkflow-step-error: Emitted when a step encounters an errorworkflow-step-suspended: Emitted when a step suspendsconst run = await workflow.createRun()
const output = run.timeTravelStream({
step: 'step2',
inputData: { value: 10 },
})
for await (const event of output.fullStream) {
switch (event.type) {
case 'workflow-step-start':
console.log(`Starting step: ${event.payload.stepName}`)
break
case 'workflow-step-finish':
console.log(`Completed step: ${event.payload.stepName}`)
break
case 'workflow-step-error':
console.error(`Error in step: ${event.payload.stepName}`, event.payload.error)
break
}
}
const result = await output.result
console.log('Time travel completed:', result)
const output = run.timeTravelStream({
step: 'step2',
context: {
step1: {
status: 'success',
payload: { value: 0 },
output: { step1Result: 2 },
startedAt: Date.now(),
endedAt: Date.now(),
},
},
})
for await (const event of output.fullStream) {
// Handle events
console.log(event)
}
const result = await output.result
const output = run.timeTravelStream({
step: ['nestedWorkflow', 'step3'],
inputData: { value: 10 },
nestedStepsContext: {
nestedWorkflow: {
step2: {
status: 'success',
payload: { step1Result: 2 },
output: { step2Result: 3 },
startedAt: Date.now(),
endedAt: Date.now(),
},
},
},
})
for await (const event of output.fullStream) {
console.log(event.type, event.payload)
}
const result = await output.result
result promise resolves only after all steps have completed