Skip to content

refactor(js/plugins/a2ui)!: carry A2UI messages under the spec's messages key - #7091

Merged
pavelgj merged 3 commits into
mainfrom
pj/js-a2ui-messages-key-5l38renjb9
Nov 19, 2026
Merged

pavelgj merged 3 commits into
mainfrom
pj/js-a2ui-messages-key-5l38renjb9

Conversation

@pavelgj

@pavelgj pavelgj commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What's new

The a2ui part now carries its A2UI messages under the spec's messages key instead of our own envelopes:

{
  "data": { "messages": [ { "version": "v0.9", "createSurface": { "surfaceId": "tokyo-weather", "catalogId": "..." } } ] },
  "metadata": { "mimeType": "application/a2ui+json" }
}

a2uiPart writes { messages }. isA2uiPart and a2uiEnvelopesFromParts accept either key, so parts written before this change (persisted sessions, older agents) are still read. A2uiPart.data is typed as the union of the two shapes, and a new a2uiPartMessages(part) returns the envelopes whichever key the part uses:

import { a2uiPartMessages, isA2uiPart } from '@genkit-ai/a2ui';

if (isA2uiPart(part)) {
  for (const envelope of a2uiPartMessages(part)) { /* ... */ }
}

Why

The A2UI extension spec puts the message list directly in a data part's data. Genkit requires data to 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 example a2ui_core's AgentToRendererMessagePayload.fromJson in 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.

Writes Reads
JS (this PR) messages messages or envelopes
Go (#7092) messages messages or envelopes
Dart (genkit-ai/genkit-dart#710) messages messages or envelopes

Breaking Changes

The plugin is in preview, but code that reads the part directly needs updating:

// before
const envelopes = part.data.envelopes;

// after
const envelopes = a2uiPartMessages(part); // or a2uiEnvelopesFromParts(content)

Clients that use a2uiEnvelopesFromParts or streamA2ui need no change.

Not in this PR

  • Dropping the envelopes fallback. Reading it costs nothing and keeps old sessions replaying; it can go once the plugins leave preview.
  • Renaming internal identifiers (ParseSegment's envelopes, a2uiEnvelopesFromParts). Only the wire key changes; renaming exported functions would break callers for no gain.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread js/plugins/a2ui/src/part.ts Resolved

@chrisraygill chrisraygill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread js/plugins/a2ui/src/index.ts Resolved
Comment thread js/plugins/a2ui/src/part.ts Resolved
Comment thread js/plugins/a2ui/tests/part_test.ts Resolved
@pavelgj
pavelgj merged commit 9ee3569 into main Nov 19, 2026
21 checks passed
@pavelgj
pavelgj deleted the pj/js-a2ui-messages-key-5l38renjb9 branch November 19, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants