Repository navigation
refactor(js/plugins/a2ui)!: carry A2UI messages under the spec's messages key - #7091
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the 'a2ui' plugin to use the spec's '{ messages }' payload wrapper instead of '{ envelopes }' within the Genkit data part, while maintaining backward compatibility to read legacy '{ envelopes }' payloads. A review comment identifies a potential runtime crash in 'a2uiPartMessages' if the 'messages' key is present but 'undefined', and suggests using nullish coalescing to safely fall back to 'envelopes'.
chrisraygill
left a comment
There was a problem hiding this comment.
The { messages } wire-format rename and messagesOf fallback logic look clean and match Dart/Go/Python. Found one missing export in @genkit-ai/a2ui/client, a small deduplication/guard fix in a2uiPartMessages, and a few test coverage gaps inline.
What's new
The a2ui part now carries its A2UI messages under the spec's
messageskey instead of our ownenvelopes:{ "data": { "messages": [ { "version": "v0.9", "createSurface": { "surfaceId": "tokyo-weather", "catalogId": "..." } } ] }, "metadata": { "mimeType": "application/a2ui+json" } }a2uiPartwrites{ messages }.isA2uiPartanda2uiEnvelopesFromPartsaccept either key, so parts written before this change (persisted sessions, older agents) are still read.A2uiPart.datais typed as the union of the two shapes, and a newa2uiPartMessages(part)returns the envelopes whichever key the part uses:Why
The A2UI extension spec puts the message list directly in a data part's
data. Genkit requiresdatato be an object (Dart expects a map), so we wrapped the list, but under a key we made up. The spec already has a wrapper for exactly this, the{ messages: [...] }payload, which renderer SDKs read as-is (for examplea2ui_core'sAgentToRendererMessagePayload.fromJsonin Dart). Using it means one less Genkit-specific shape between an agent and a renderer.This keeps the plugins in step across languages: Genkit Dart made the same change in genkit-ai/genkit-dart#710, and the Go plugin gets it in #7092. Until all three ship, a newer agent and an older client disagree on the key, which is why every reader accepts both.
messagesmessagesorenvelopesmessagesmessagesorenvelopesmessagesmessagesorenvelopesBreaking Changes
The plugin is in preview, but code that reads the part directly needs updating:
Clients that use
a2uiEnvelopesFromPartsorstreamA2uineed no change.Not in this PR
envelopesfallback. Reading it costs nothing and keeps old sessions replaying; it can go once the plugins leave preview.ParseSegment'senvelopes,a2uiEnvelopesFromParts). Only the wire key changes; renaming exported functions would break callers for no gain.