Skip to content

Commit eaa60dd

Browse files
authored
Add a renderer development guide (#305)
1 parent 2781faa commit eaa60dd

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# A2UI Renderer Implementation Guide
2+
3+
This document outlines the required features for a new renderer implementation of the A2UI protocol, based on the version 0.8 specification. It is intended for developers building new renderers (e.g., for React, Flutter, iOS, etc.).
4+
5+
## I. Core Protocol Implementation Checklist
6+
7+
This section details the fundamental mechanics of the A2UI protocol. A compliant renderer must implement these systems to successfully parse the server stream, manage state, and handle user interactions.
8+
9+
### Message Processing & State Management
10+
11+
- **JSONL Stream Parsing**: Implement a parser that can read a streaming response line by line, decoding each line as a distinct JSON object.
12+
- **Message Dispatcher**: Create a dispatcher to identify the message type (`beginRendering`, `surfaceUpdate`, `dataModelUpdate`, `deleteSurface`) and route it to the correct handler.
13+
- **Surface Management**:
14+
- Implement a data structure to manage multiple UI surfaces, each keyed by its `surfaceId`.
15+
- Handle `surfaceUpdate`: Add or update components in the specified surface's component buffer.
16+
- Handle `deleteSurface`: Remove the specified surface and all its associated data and components.
17+
- **Component Buffering (Adjacency List)**:
18+
- For each surface, maintain a component buffer (e.g., a `Map<String, Component>`) to store all component definitions by their `id`.
19+
- Be able to reconstruct the UI tree at render time by resolving `id` references in container components (`children.explicitList`, `child`, `contentChild`, etc.).
20+
- **Data Model Store**:
21+
- For each surface, maintain a separate data model store (e.g., a JSON object or a `Map<String, any>`).
22+
- Handle `dataModelUpdate`: Update the data model at the specified `path`. The `contents` will be in an adjacency list format (e.g., `[{ "key": "name", "valueString": "Bob" }]`).
23+
24+
### Rendering Logic
25+
26+
- **Progressive Rendering Control**:
27+
- Buffer all incoming `surfaceUpdate` and `dataModelUpdate` messages without rendering immediately.
28+
- Handle `beginRendering`: This message acts as the explicit signal to perform the initial render of a surface and set the root component ID.
29+
- Start rendering from the specified `root` component ID.
30+
- If a `catalogId` is provided, ensure the corresponding component catalog is used (defaulting to the standard catalog if omitted).
31+
- Apply any global `styles` (e.g., `font`, `primaryColor`) provided in this message.
32+
- **Data Binding Resolution**:
33+
- Implement a resolver for `BoundValue` objects found in component properties.
34+
- If only a `literal*` value is present (`literalString`, `literalNumber`, etc.), use it directly.
35+
- If only a `path` is present, resolve it against the surface's data model.
36+
- If both `path` and `literal*` are present, first update the data model at `path` with the literal value, then bind the component property to that `path`.
37+
- **Dynamic List Rendering**:
38+
- For containers with a `children.template`, iterate over the data list found at `template.dataBinding` (which resolves to a list in the data model).
39+
- For each item in the data list, render the component specified by `template.componentId`, making the item's data available for relative data binding within the template.
40+
41+
### Client-to-Server Communication
42+
43+
- **Event Handling**:
44+
- When a user interacts with a component that has an `action` defined, construct a `userAction` payload.
45+
- Resolve all data bindings within the `action.context` against the data model.
46+
- Send the complete `userAction` object to the server's event handling endpoint.
47+
- **Client Capabilities Reporting**:
48+
- In **every** A2A message sent to the server (as part of the metadata), include an `a2uiClientCapabilities` object.
49+
- This object should declare the component catalog your client supports via `supportedCatalogIds` (e.g., including the URI for the standard 0.8 catalog).
50+
- Optionally, if the server supports it, provide `inlineCatalogs` for custom, on-the-fly component definitions.
51+
- **Error Reporting**: Implement a mechanism to send an `error` message to the server to report any client-side errors (e.g., failed data binding, unknown component type).
52+
53+
## II. Standard Component Catalog Checklist
54+
55+
To ensure a consistent user experience across platforms, A2UI defines a standard set of components. Your client should map these abstract definitions to their corresponding native UI widgets.
56+
57+
### Basic Content
58+
59+
- **Text**: Render text content. Must support data binding on `text` and a `usageHint` for styling (h1-h5, body, caption).
60+
- **Image**: Render an image from a URL. Must support `fit` (cover, contain, etc.) and `usageHint` (avatar, hero, etc.) properties.
61+
- **Icon**: Render a predefined icon from the standard set specified in the catalog.
62+
- **Video**: Render a video player for a given URL.
63+
- **AudioPlayer**: Render an audio player for a given URL, optionally with a description.
64+
- **Divider**: Render a visual separator, supporting both `horizontal` and `vertical` axes.
65+
66+
### Layout & Containers
67+
68+
- **Row**: Arrange children horizontally. Must support `distribution` (justify-content) and `alignment` (align-items). Children can have a `weight` property to control flex-grow behavior.
69+
- **Column**: Arrange children vertically. Must support `distribution` and `alignment`. Children can have a `weight` property to control flex-grow behavior.
70+
- **List**: Render a scrollable list of items. Must support `direction` (`horizontal`/`vertical`) and `alignment`.
71+
- **Card**: A container that visually groups its child content, typically with a border, rounded corners, and/or shadow. Has a single `child`.
72+
- **Tabs**: A container that displays a set of tabs. Includes `tabItems`, where each item has a `title` and a `child`.
73+
- **Modal**: A dialog that appears on top of the main content. It is triggered by an `entryPointChild` (e.g. a button) and displays the `contentChild` when activated.
74+
75+
### Interactive & Input Components
76+
77+
- **Button**: A clickable element that triggers a `userAction`. Must be able to contain a `child` component (typically Text or Icon) and may vary in style based on the `primary` boolean.
78+
- **CheckBox**: A checkbox that can be toggled, reflecting a boolean value.
79+
- **TextField**: An input field for text. Must support a `label`, `text` (value), `textFieldType` (`shortText`, `longText`, `number`, `obscured`, `date`), and `validationRegexp`.
80+
- **DateTimeInput**: A dedicated input for selecting a date and/or time. Must support `enableDate`, `enableTime`, and an `outputFormat`.
81+
- **MultipleChoice**: A component for selecting one or more options from a list (`options`). Must support `maxAllowedSelections` and bind `selections` to a list or single value.
82+
- **Slider**: A slider for selecting a numeric value (`value`) from a defined range (`minValue`, `maxValue`).

docs/renderers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Renderers convert A2UI JSON messages into native UI components for different platforms.
44

5-
The [agents](agents.md) are responsible for generating the A2UI messages,
5+
The [agents](agents.md) are responsible for generating the A2UI messages,
66
and the [transports](transports.md) are responsible for delivering the messages to the client.
77
The client renderer library must buffer and handle A2UI messages, implement the A2UI lifecycle, and render surfaces (widgets).
88

@@ -66,10 +66,11 @@ TODO: Add a guide
6666

6767
## Building a Renderer
6868

69-
Want to build a renderer for your platform?
69+
Want to build a renderer for your platform?
7070

7171
- See the [Roadmap](roadmap.md) for planned frameworks.
7272
- Review existing renderers for patterns.
73+
- Check out our [Renderer Development Guide](guides/renderer-development.md) for details on implementing a renderer.
7374

7475
### Key requirements:
7576

0 commit comments

Comments
 (0)