Question: How to Stream Text from Mastra Workflows to AI SDK Frontend?
Context
I'm using Mastra workflows with AI SDK 5.0 on the frontend. My workflow contains agent steps that stream text, and I need that text to appear in the UI.Current Situation
- Frontend: Using
useChatfrom@ai-sdk/reactwhich expects AI SDK formatted events (
, etc.)text-delta - Backend: Fastify endpoint that streams a Mastra workflow
- Problem: Using
toAISdkFormat(workflowStream, { from: 'workflow' })only emits workflow metadata (data-workflowparts), not the actual text content from agent steps
The workflow stream emits
workflow-step-output events that contain the text from agent steps, but toAISdkFormat with from: 'workflow' doesn't extract this text—it only provides workflow structure metadata.I see that
workflowRoute() exists in @mastra/ai-sdk, but it's designed for Mastra's built-in Hono server, not Fastify.My Question
What's the recommended way to stream text content from Mastra workflow agent steps to an AI SDK frontend?Options I'm considering:
- Manually transform the workflow stream to extract text from
workflow-step-outputevents - Use
workflowRoute()handler somehow with Fastify - Change the workflow structure to return agent output directly
- Something else I'm missing?