What writing an A2UI renderer in vanilla JavaScript taught me

'A flat list of ids makes agent UI easy to check.' above three A2UI components joined by id, with the id stack the validator keeps, where inner points back at card and the playground reports a cycle.

A2UI sends a whole interface as a flat list of components joined by id, and writing a renderer for it by hand showed me what that buys a renderer. Checking an agent’s JSON before drawing it comes down to a few lookups in one map: every reference, every cycle and the one root.

The short version: an A2UI response is plain JSON, a flat list of components plus a data model, and the renderer decides what it will draw. My playground validates and renders 13 of the 18 basic catalog components in about 1,400 lines of vanilla JavaScript, with no build step, no backend and no SDK.

I built it on November 26, 2026 to see how far a browser-only page can go with AI providers. I wrote the renderer myself instead of using one of the official ones, because I wanted to learn the protocol by implementing it. You can try it at lab.ivankristianto.com/experiments/a2ui-playground. The code is on GitHub.1

One preset, from JSON to a form

A2UI is an open protocol for agents to describe a user interface as JSON messages that a client renders. Version 1.0 is the current spec.2 The agent never sends HTML or JavaScript; it names components, and the renderer only draws the ones it knows.

Components point at each other by id

The spec calls this an adjacency list: “The A2UI protocol defines the UI as a flat list of components. The tree structure is built implicitly using ID references.”2 One component must have the id root. Containers point at their children by id, so a Card names its child and a Column lists its children. The spec’s own reason is streaming: the agent can send components in any order, and rendering starts once root arrives.2

Here is part of the contact form preset, trimmed to one field and the button:

{ "version": "1.0", "createSurface": { "surfaceId": "contact_form",
  "catalogId": "https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json",
  "dataModel": { "contact": { "name": "Ayu", "email": "ayu@" } },
  "components": [
    { "id": "root", "component": "Card", "child": "form" },
    { "id": "form", "component": "Column", "children": ["email", "send"] },
    { "id": "email", "component": "TextField", "label": "Email",
      "value": { "@path": "/contact/email" },
      "@checks": [{ "condition": { "@call": "email", "args": { "value": { "@path": "/contact/email" } } },
                    "message": "Enter an email address like you@example.com." }] },
    { "id": "send", "component": "Button", "child": "send_label", "variant": "primary",
      "action": { "event": { "name": "submitContact", "context": { "email": { "@path": "/contact/email" } } } } },
    { "id": "send_label", "component": "Text", "text": "Send message" }
  ] } }

{"@path": "/contact/email"} binds the field to the data model with a JSON Pointer, @call runs one of the catalog’s functions, and @checks holds the validation rules the renderer evaluates.2 The data model starts with ayu@, so the preset opens with the email check failing and Send disabled.

Nothing reaches the agent until a button fires

Typing in a field only updates the local data model. When a button fires its action, the renderer sends a message with the action’s name, the surface, the component and a timestamp.3 With the form filled in, the playground logs this instead of sending it anywhere:

{ "version": "1.0", "action": { "name": "submitContact", "surfaceId": "contact_form",
  "sourceComponentId": "send", "timestamp": "2026-11-26T12:57:18Z",
  "context": { "name": "Ayu", "email": "ayu@example.com", "topic": ["talk"] } } }

The booking preset goes one step further. Pressing Confirm swaps in a scripted updateComponents reply that sends a new root and its children, and the renderer replaces the old ones by id. The page labels that reply as scripted, since no agent is on the other end.

Why A2UI’s flat list makes validation simple

This is what writing the renderer taught me. Every component sits at the top level with its id, so the validator can index them all in one pass before it follows a single reference. After that, every check is a lookup.

Three checks on one map

The validator puts each component that passes its own checks into a Map keyed by id.4 Then checkTree, under 40 lines, checks the shape:5

  • Is there a component with the id root? If not, there’s nothing to draw.
  • Does every child, children entry and tab point at an id in the map? A miss is one Map.has call.
  • Starting from root and keeping a stack of the ids on the way down, does a child point back at one already on the stack? Then it’s a cycle.

Two small responses through the same load() function show the messages:

cycle    /0/createSurface/components/2/children/0  "card" contains itself through this reference, which would never end.
no root  /0/createSurface  Surface main has no component with the id root, so there is nothing to draw.

Every validation problem carries a JSON Pointer into the response, so a model’s mistake can be found in the JSON field next to the preview.

What the validator refuses

The A2UI site says “Agents place only components you registered.”6 In live mode the JSON comes from a model, so the playground checks every response against that list and draws nothing while any problem stands.

The basic catalog has 18 components.7 The playground draws 13. I left out five, and the validator says why for each: Image, Video and AudioPlayer, because a URL in the response would make your browser fetch it; Icon, because my lab’s design has no icon font; and Modal, because the lab doesn’t use modals.

I kept a broken response preset to show what a refusal looks like. It has an Image and a Button whose label id doesn’t exist:

{ "id": "hero", "component": "Image", "url": "https://example.com/a.jpg" },
{ "id": "cta", "component": "Button", "child": "cta_label", "action": { "event": { "name": "buy" } } }
/0/createSurface/components/1/component  Image: This playground doesn't load images from a response, because the URL would be fetched by your browser. Use Text or a Card instead.
/0/createSurface/components/2/child      This points at "cta_label", but no component has that id.

Where the map stops helping

The map catches a reference that points nowhere. It can’t tell how much a valid reference will cost to draw. List templates multiply: a 200-item list whose template holds another 200-item list, three levels deep, asks for 8 million components. So I set limits at the top of protocol.js:8

export const LIMITS = { bytes: 200_000, components: 500, depth: 32, items: 200, drawn: 2000 };

drawn came last. The renderer now stops after 2,000 components, and that test case stopped in 14 ms instead of hanging the tab. Response text only reaches the page through textContent and attributes, and there’s no innerHTML anywhere in the tool.

Calling three providers from a browser

Live mode asks a model for the same kind of JSON and sends it through the same validator. The open question was whether a static page can call these APIs with a key the visitor pastes in.

What the APIs answered on November 26

On November 26 a fetch() POST with a fake key went to each provider from a Chrome 158 page, after a curl preflight to each. OpenAI’s Responses API and Gemini’s generateContent both returned a readable 401 or 400. Anthropic blocked it until the request carried one extra header:

curl -s -D - -o /dev/null -X POST https://api.anthropic.com/v1/messages \
  -H 'Origin: https://lab.ivankristianto.com' -H 'x-api-key: invalid-test-key' \
  -H 'anthropic-version: 2023-06-01' -H 'content-type: application/json' \
  -H 'anthropic-dangerous-direct-browser-access: true' -d '{}' | grep -i access-control-allow-origin
# access-control-allow-origin: *
# without the last -H, there's no Access-Control-Allow-Origin, so the browser hides the 401

Anthropic’s API docs describe browser access, with that opt-in header.9 OpenAI’s Node SDK has a similar switch, dangerouslyAllowBrowser, off by default,10 but neither OpenAI’s nor Google’s API docs say the API answers browser requests.

Shipping all three behind one notice

All three tell developers to keep keys out of browser code.9,11,12 Their reasons are about a key shipped in the page: OpenAI says it lets “malicious users” make requests on your behalf, and Google says keys in client-side code “can be extracted by users”. None of them addresses a visitor pasting their own.

The cautious option was Anthropic only. I shipped all three behind one notice above the key field, because it’s the visitor’s own key and their call, and a plain notice is enough. The notice says the key goes from this browser straight to the provider, sits in memory until a reload, is never saved or logged, and that all three providers advise against browser keys, so use a low-limit or throwaway one.

The key input has no name and sits outside any form, so a stray submit can’t put it in a URL. Gemini’s key goes in the x-goog-api-key header, never in ?key=. Provider error bodies are never shown, since OpenAI’s echoes part of the key.13 Live mode defaults to claude-haiku-5-5, gpt-6-luna and gemini-3.5-flash-lite, checked against each provider’s models page on November 26, and the model field takes any ID your key can use.

Live mode hasn’t seen a real key yet

No provider has been called with a real key yet. Gemini’s request body passed Google’s schema check with a fake key; OpenAI and Anthropic check the key before the body, so their request shapes are confirmed only against their docs. The browser checks ran in Chrome only.

The validator and the provider requests have 38 tests that run with Node’s built-in test runner (Node 22 or later). The renderer has no automated tests yet, only the browser runs from November 26. To run it yourself, serve the repo root, since the page links shared stylesheets:

git clone https://github.com/ivankristianto/ik2-lab.git && cd ik2-lab
python3 -m http.server 8787   # then open http://localhost:8787/experiments/a2ui-playground/
cd experiments/a2ui-playground && node --test tests/*.test.js

If you want to see A2UI before installing a renderer, open the playground, pick the broken response preset and press Render. If you’re writing your own, A2UI’s TypeScript Core SDK, @a2ui/web_core, already parses the messages and evaluates bindings, templates and checks,14 and the 18-component catalog is a short read.7

Sources