@lynx-js/genui/a2ui
English | 简体中文
@lynx-js/genui/a2ui is the ReactLynx client runtime for A2UI v1.0 only. It
consumes validated A2UI server-to-client JSON messages and renders trusted
ReactLynx components in your app.
Use this package when you already have, or plan to build, an Agent service that returns A2UI messages. The package does not host an Agent, call an LLM, own a backend route, or provide a chat shell. Your app owns the transport layer and pushes messages into the renderer.
If you have never used A2UI before, think of it this way:
- In React, your code chooses components and passes props.
- In A2UI, an Agent chooses from a component catalog that your app publishes.
- The client still renders real ReactLynx components. The model only sends data that says which approved component to render and what props to use.
The result is not arbitrary generated code. It is a ReactLynx UI tree assembled from a trusted catalog.
See the current standard migration audit for wire, RPC, and validation changes.
Protocol versions
The server and client support only A2UI v1.0. Older or versionless protocol
messages are rejected. Send renderer events with version: "1.0"; action
requests use the action envelope. Streams using 0.9 or the earlier 1.0 draft must be regenerated. Dynamic values use @path/@call, and components use @catalogId, @checks, @metadata, and @accessibility.
The client supports inline createSurface.components and dataModel, typed
subtree replacement, null deletion, and structured validation results.
Styling stays in the host app and the Lynx component catalog.
Use onAction for the existing action payload callback. To transport v1.0 wire
events, use onMessage(message, metadata) and push incoming messages into
messageStore. Choose one callback for sending actions to avoid duplicate requests.
Set catalogId when using a custom catalog; it defaults to the Lynx catalog ID.
Renderer functions accept agent calls only when their manifest declares
allowedCallers: 'agentOnly' or 'rendererOrAgent'.
The server accepts v1.0 action envelopes at /a2ui/action and
/a2ui/action/stream, with metadata and the existing conversation fields.
It has no agent-side catalog function implementations and returns a correlated
UNKNOWN_FUNCTION response for those requests. Forward renderer function results
with the current transport surfaceId and conversation to continue generation.
Install
Install the published GenUI package in a ReactLynx app:
Import the optional default theme tokens once if you want to use the built-in light/dark CSS variables:
Quick Start
Create a MessageStore, register the components that generated UI is allowed
to render, and forward generated actions back to your Agent service.
MessageStore stores raw protocol messages in arrival order. <A2UI>
subscribes to it, processes new messages, renders the active surface, and emits
generated UI actions through onAction.
MessageStore
Use push for streaming increments and replace for the final complete response:
Replacement preserves local input on unchanged server fields and reconciles
arrays using the documented identity/index rules. Rejected replacements preserve
the current UI, report errors through onMessage and the console, and block their
appended tail until a corrected replace or clear.
See MessageStore behavior for snapshot and notification
contracts, a complete example, deep comparison, array merging, rejected-replacement
recovery, RPC handling, and the differences between renderEmpty, clear, and
surface deletion.
What You Own
First Things To Know
- Pass only the components you want generated UI to use through
catalogs. - Include
...basicFunctionswhen messages may use A2UI function calls such asformatString,formatDate,required,email, orand. - Pair components with their
catalog.jsonmanifests when you needserializeCatalog(...)to send JSON schemas to an Agent. - There is intentionally no
@lynx-js/genui/a2ui/catalog/allexport. Compose the exact catalog you want at the integration site so bundle cost is visible. - For a new turn or session, mount
<A2UI>with a differentkey; the component owns itsMessageProcessorfor the lifetime of the mount.

