Pre-flight Checklist
Describe the Feature
@ag-ui/mastra exports convertAGUIMessagesToMastra (AG-UI → Mastra), but nothing for the reverse direction: converting stored Mastra messages (MastraDBMessage, the parts-based format returned by Mastra's memory API GET /api/memory/threads/:threadId/messages) into AG-UI Message[].
Use case
Restoring thread history into an AG-UI client (e.g. CopilotKit's CopilotChat) from Mastra Memory. Mastra persists full conversation history in its storage, but any frontend that wants to rehydrate a past thread has to hand-roll the MastraDBMessage → AG-UI conversion — mapping content.parts text parts, tool-invocation parts to toolCalls + tool result messages, reasoning parts, etc. That format is non-trivial and an internal detail of Mastra, so every consumer reimplements a lossy subset (typically text-only).
Context: this is the missing piece in CopilotKit/CopilotKit#1881 (Mastra message history support) — see CopilotKit/CopilotKit#1881 (comment) for a working but hand-rolled restore flow that would collapse to one call with this utility.
Proposed shape
export function convertMastraMessagesToAGUI(messages: MastraDBMessage[]): Message[]
covering text, tool calls/results (so restored transcripts keep their tool-call rendering), and reasoning parts — mirroring how the ai-sdk integration ships converters for both directions.
Happy to contribute a PR if the shape is agreed on.
Pre-flight Checklist
Describe the Feature
@ag-ui/mastraexportsconvertAGUIMessagesToMastra(AG-UI → Mastra), but nothing for the reverse direction: converting stored Mastra messages (MastraDBMessage, the parts-based format returned by Mastra's memory APIGET /api/memory/threads/:threadId/messages) into AG-UIMessage[].Use case
Restoring thread history into an AG-UI client (e.g. CopilotKit's
CopilotChat) from Mastra Memory. Mastra persists full conversation history in its storage, but any frontend that wants to rehydrate a past thread has to hand-roll theMastraDBMessage→ AG-UI conversion — mappingcontent.partstext parts,tool-invocationparts totoolCalls+ tool result messages, reasoning parts, etc. That format is non-trivial and an internal detail of Mastra, so every consumer reimplements a lossy subset (typically text-only).Context: this is the missing piece in CopilotKit/CopilotKit#1881 (Mastra message history support) — see CopilotKit/CopilotKit#1881 (comment) for a working but hand-rolled restore flow that would collapse to one call with this utility.
Proposed shape
covering text, tool calls/results (so restored transcripts keep their tool-call rendering), and reasoning parts — mirroring how the ai-sdk integration ships converters for both directions.
Happy to contribute a PR if the shape is agreed on.