ag-ui-protocol / ag-ui-protocol/ag-ui
[Feature]: [mastra] Export a Mastra → AG-UI message converter (reverse of convertAGUIMessagesToMastra)
- Lingua principale
- Python
- Stelle
- 15.9k
- Fork
- 1.4k
- Merge medio
- 1g 17h
- PR unite (30g)
- 163
Descrizione
### Pre-flight Checklist
- [x] I have searched [existing issues](https://github.com/ag-ui-protocol/ag-ui/issues) and this hasn't been requested yet.
- [x] I am using the **latest** version AG-UI.
### 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 https://github.com/CopilotKit/CopilotKit/issues/1881#issuecomment-4951024485 for a working but hand-rolled restore flow that would collapse to one call with this utility.
### Proposed shape
```ts
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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.