ag-ui-protocol / ag-ui-protocol/ag-ui

[Feature]: [mastra] Export a Mastra → AG-UI message converter (reverse of convertAGUIMessagesToMastra)

Abierto
#2,175 0 comentarios 2 reacciones 0 asignados Ver en GitHub
enhancement Integration
Lenguaje dominante
Python
Estrellas
15.9k
Forks
1.4k
Merge medio
1 d 17 h
PR fusionados (30 d)
163

Descripción

### 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.