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

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

Offen
#2,175 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement Integration
Vorherrschende Sprache
Python
Sterne
15.9k
Forks
1.4k
Ø Merge
1 T. 17 Std.
Gemergte PRs (30 T.)
163

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.