createA2uiSurfaceStore()
Factory function that creates an A2uiSurfaceStore โ a reactive store that accumulates A2UI messages into a live Map of surfaces.
Import:
Signature
Returns: A2uiSurfaceStore โ a stateful store backed by Angular signals. Can be created outside an injection context.
A2uiSurfaceStore Interface
apply(message)
Processes one A2uiMessage and updates the internal surfaces signal. All four message types are handled:
| Message type | Behavior |
|---|---|
createSurface | Creates a new A2uiSurface entry with an empty component map and data model |
updateComponents | Merges the provided components into the surface's component map by id โ existing components are replaced, others are kept |
updateDataModel | Applies a JSON Pointer patch to the surface's data model (see below) |
deleteSurface | Removes the surface from the map entirely |
Messages for unknown surface IDs are silently ignored (except createSurface, which registers the surface).
surfaces
A readonly Signal<Map<string, A2uiSurface>> containing all active surfaces. Each map operation produces a new Map reference so that Angular's change detection triggers correctly.
surface(surfaceId)
Returns a computed signal for a single surface. The signal emits undefined until a createSurface message registers it, and undefined again after deleteSurface removes it.
Data Model and Render-Lib State Sync
The surface's dataModel is synchronized into the render-lib StateStore when surfaceToSpec() converts the surface to a spec. The conversion sets state: surface.dataModel on the produced Spec, which initializes the render-lib's internal StateStore with the surface data. When components with _bindings update values (e.g., a text field changing), those updates flow through the render-lib StateStore, and each mutation emits a RenderStateChangeEvent through the render-lib event system. This means consumers observing the events output on A2uiSurfaceComponent see all data model changes as typed RenderStateChangeEvent objects with path, value, and snapshot fields.
updateDataModel Semantics
The updateDataModel message uses JSON Pointer (RFC 6901) paths to address values in the data model.
path | value | Effect |
|---|---|---|
undefined or '/' | Object | Replaces the entire data model |
/some/path | Any value | Sets dataModel[some][path] to value |
/some/path | undefined | Deletes the value at that path |
Usage with createA2uiMessageParser
The surface store is designed to work with createA2uiMessageParser, which parses raw JSONL chunks into typed A2uiMessage objects.
The parser expects each line to be wrapped in an envelope object: {"createSurface": {...}}, {"updateComponents": {...}}, etc. The envelope key determines the message type; its value is the message payload.
A2uiSurface Shape
Each surface stored in the map has the following structure:
The components map is keyed by component ID. The dataModel is a plain object that components reference via JSON Pointer paths in their props.