Run.resumeStream()
.resumeStream() 方法使用新的数据恢复挂起的工作流运行,使你能够从特定步骤继续执行并观察事件流。
🌐 The .resumeStream() method resumes a suspended workflow run with new data, allowing you to continue execution from a specific step and to observe the stream of events.
使用示例Direct link to 使用示例
🌐 Usage example
const run = await workflow.createRun();
const stream = run.stream({
inputData: {
value: "initial data",
},
});
const result = await stream.result;
if (result!.status === "suspended") {
const resumedStream = await run.resumeStream({
resumeData: {
value: "resume data",
},
});
}
参数Direct link to 参数
🌐 Parameters
resumeData?:
z.infer<TInput>
Input data that matches the workflow's input schema
requestContext?:
RequestContext
Request Context data to use during workflow execution
step?:
Step<string, any, any, any, any, TEngineType>
The step to resume execution from
tracingOptions?:
TracingOptions
Options for Tracing configuration.
metadata?:
Record<string, any>
Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.
requestContextKeys?:
string[]
Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').
traceId?:
string
Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.
parentSpanId?:
string
Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.
tags?:
string[]
Tags to apply to this trace. String labels for categorizing and filtering traces.
返回Direct link to 返回
🌐 Returns
stream:
MastraWorkflowStream<ChunkType>
A custom stream that extends ReadableStream<ChunkType> with additional workflow-specific properties
stream.status:
Promise<RunStatus>
A promise that resolves to the current workflow run status
stream.result:
Promise<WorkflowResult<TState, TOutput, TSteps>>
A promise that resolves to the final workflow result
stream.usage:
Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cacheInputTokens?: number }>
A promise that resolves to token usage statistics
流事件Direct link to 流事件
🌐 Stream Events
在工作流执行过程中,流会发出各种类型的事件。每个事件都有一个 type 字段和一个包含相关数据的 payload:
🌐 The stream emits various event types during workflow execution. Each event has a type field and a payload containing relevant data:
workflow-start:工作流执行开始workflow-step-start:一个步骤开始执行workflow-step-output:步骤的自定义输出workflow-step-result:一个步骤完成并产生结果workflow-finish:工作流执行完成,附带使用统计
相关Direct link to 相关
🌐 Related