@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
42 lines (29 loc) • 1.28 kB
Markdown
# Run.observeStream()
The `.observeStream()` method opens a new `ReadableStream` to a workflow run that's currently running, allowing you to observe the stream of events if the original stream is no longer available.
## Usage example
```typescript
const run = await workflow.createRun()
run.stream({
inputData: {
value: 'initial data',
},
})
const stream = await run.observeStream()
for await (const chunk of stream) {
console.log(chunk)
}
```
## Returns
`ReadableStream<ChunkType>`
## Stream events
The stream emits various event types during workflow execution. Each event has a `type` field and a `payload` containing relevant data:
- **`workflow-start`**: Workflow execution begins
- **`workflow-step-start`**: A step begins execution
- **`workflow-step-output`**: Custom output from a step
- **`workflow-step-result`**: A step completes with results
- **`workflow-finish`**: Workflow execution completes with usage statistics
## Related
- [Workflows overview](https://mastra.ai/docs/workflows/overview)
- [Workflow.createRun()](https://mastra.ai/reference/workflows/workflow-methods/create-run)
- [Run.stream()](https://mastra.ai/reference/streaming/workflows/stream)
- [Run.resumeStream()](https://mastra.ai/reference/streaming/workflows/resumeStream)