Skip to content

fix(shell): render an inline A2UI surface above the message text when the agent sent it first - #256

Merged
mikzat merged 2 commits into
a2ui-project:mainfrom
mikzat:fix/inline-surface-before-text
Oct 8, 2026
Merged

mikzat merged 2 commits into
a2ui-project:mainfrom
mikzat:fix/inline-surface-before-text

Conversation

@mikzat

@mikzat mikzat commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

An agent can lead a message with a small UI header (for example an avatar-and-name row) followed by its prose, relying on the order of the A2A parts. The chat view accumulates text and A2UI payloads into separate fields and the message template always rendered the text before the inline surface, so the header ended up below the paragraph it was meant to introduce.

A2aStreamEventParser now records whether an event's A2UI items all preceded its text parts (a2uiPrecedesText). A2aChatView latches that onto the message (inlineSurfaceLeadsText) the first time visible content arrives, so prose streamed afterwards cannot demote a header that already rendered above it, and the message template places the inline surface before or after the text accordingly. Messages whose text comes first, or whose surfaces surround the text, render exactly as before.

Scope: a message still accumulates into one text block and one inline surface frame, so the fix decides only which of the two comes first. An agent that interleaves A2UI and text more than once (a2ui, text, a2ui, text, ...) keeps rendering as before, text above the merged surfaces (the flag is only true while every A2UI part preceded any text). Reproducing a finer interleaving in the bubble would need the message model to hold an ordered list of text and surface blocks, which is a separate change.

Verification

  • a2a-stream-event-parser.service.spec.ts: a2uiPrecedesText is true when the A2UI items precede the text parts, false when they follow the text or surround it.
  • a2a-chat-view.spec.ts: the message keeps the inline surface above the text when the agent sent it first and below it when the text came first, across streamed chunks.
  • chat-message.spec.ts: the inline surface renders above the text when the surface led the message.
  • New Playwright journey e2e/a2a-inline-surface-order.e2e.ts drives the A2A chat against a mock agent whose first turn sends the surface part before the text and whose second turn sends the text first, and checks that the real inline frame renders in each bubble above or below the text to match. It fails on main's template with the surface below the text.
  • prettier --check, eslint, and tsc -p tsconfig.json --noEmit clean in shell/.

@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 introduces changes to preserve the order of inline surfaces and text in agent chat messages. It adds an inlineSurfaceLeadsText property to track whether an inline surface arrived before any text, allowing the UI to render the surface above or below the text accordingly. This behavior is supported by updates to the stream event parser, chat message component, and corresponding unit tests. I have no feedback to provide as there are no review comments.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

⚡ A2UI Composer PR Preview

Your automated preview is successfully live (commit 0bd327a):
👉 Launch PR Preview

Note: This environment will be wiped automatically when the PR is merged or closed.

mikzat added 2 commits October 8, 2026 10:10
… the agent sent it first

An agent can lead a message with a small UI header (for example an avatar-and-name row) followed by its prose, relying on the order of the A2A parts. The chat view accumulates text and A2UI payloads into separate fields and the message template always rendered the text before the inline surface, so the header ended up below the paragraph it was meant to introduce.

`A2aStreamEventParser` now records whether an event's A2UI items all preceded its text parts (`a2uiPrecedesText`). `A2aChatView` latches that onto the message (`inlineSurfaceLeadsText`) the first time visible content arrives, so prose streamed afterwards cannot demote a header that already rendered above it, and the message template places the inline surface before or after the text accordingly. Messages whose text comes first, or whose surfaces surround the text, render exactly as before.
A Playwright journey drives the A2A chat against a mock agent that answers
one turn with the surface part before the text and another with the text
first, and checks the real inline frame renders in each bubble above or
below the text to match the wire order.

Also states the a2uiPrecedesText update as "held so far and no text yet"
rather than through a negated comparison.
@mikzat
mikzat force-pushed the fix/inline-surface-before-text branch from be2224a to 0bd327a Compare October 8, 2026 17:20
@mikzat
mikzat marked this pull request as ready for review October 8, 2026 17:35

@jgindin jgindin 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.

Seems like this would be a good candidate for a visual

@mikzat
mikzat merged commit 1b04e57 into a2ui-project:main Oct 8, 2026
13 checks passed
mikzat added a commit to mikzat/a2uicomposer that referenced this pull request Oct 12, 2026
…ve the message text

a2ui-project#256 made the inline surface card follow the order the agent sent its
parts, so a surface that arrives before the text now renders above it.
The unit specs cover the ordering, but nothing checks what the bubble
actually looks like, and jgindin flagged it as a good candidate for a
visual test.

The new test drives the mock agent through two turns, surface-then-text
and text-then-surface, waits for both guest frames to draw, and
snapshots each agent bubble on its own so the first one is not cropped
by the history's scroll-to-bottom.
mikzat added a commit that referenced this pull request Oct 12, 2026
…ve the message text (#261)

* test(shell): add a visual baseline for an inline surface rendered above the message text

#256 made the inline surface card follow the order the agent sent its
parts, so a surface that arrives before the text now renders above it.
The unit specs cover the ordering, but nothing checks what the bubble
actually looks like, and jgindin flagged it as a good candidate for a
visual test.

The new test drives the mock agent through two turns, surface-then-text
and text-then-surface, waits for both guest frames to draw, and
snapshots each agent bubble on its own so the first one is not cropped
by the history's scroll-to-bottom.

* test(shell): commit the workflow-generated visual baselines

Adds the two new baselines from the visual_baselines workflow run and
takes the six existing ones it regenerated along with them. Five of
those differ only in wall-clock timestamps and antialiasing (well under
the 2% threshold). a2a-full-chat-view.png also drops the New Session
and share buttons from the toolbar: #232 hides them on non-workspace
routes such as /a2a, and that baseline had not been regenerated since,
so this catches it up with what the shell renders today.

* test(shell): send the inline surface with the canonical A2UI MIME type

* test(shell): fix the clock in the visual specs that show inspector timestamps

The inspector drawer baseline and the full chat view baseline both
contain the inspector's event timestamps, so they changed on every
regeneration. The validation-errors spec already pins the clock with
page.clock.setFixedTime, which keeps timers and the stream running;
do the same in the other two.

* test(shell): keep the baselines that only differed by antialiasing

Four regenerated baselines differed from main by at most 0.05% of
pixels with nothing above the antialiasing noise floor, well under the
2% threshold, so leave them as they are on main.

* test(shell): regenerate the two inspector baselines with the fixed clock

Workflow output; both now show 11:24:22 AM and will stay that way.

* test(shell): regenerate the inspector baselines after the rebase onto main

Only the two baselines whose specs pin the clock change; the rest came
back different by antialiasing noise alone and stay as they are on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants