a2ui library
A2UI (Agent-to-UI) streaming UI protocol support for Genkit Dart.
The whole server-side integration is the a2ui() model middleware; register
A2uiPlugin in Genkit(plugins: [...]), then add a2ui() to an agent's (or
a one-shot generate's) use list. Pair it with basicCatalog (v1.0, the
default), basicCatalogV09 (select with catalog: 'basic-v0.9'), or your
own catalog.
Clients do not depend on this package. A2UI travels as spec-shaped data
parts, so a client needs only package:genkit and a renderer such as
a2ui_flutter; see the README for copy-paste helpers.
Classes
- A2uiCatalog
- A parsed catalog: an id plus the components and client functions it exposes.
- A2uiCatalogComponent
- A component's API: its name and the JSON Schema declaring its props.
- A2uiCatalogFunction
-
A client function's API (
required,regex,openUrl, ...), used for?checkrules and client-side calls. - A2uiMiddleware
- The A2UI model middleware.
- A2uiOptions
- Configuration for the a2ui middleware.
- A2uiParam
- One property of a component authored with A2uiCatalogComponent.simple.
- A2uiPlugin
-
The Genkit plugin that registers the a2ui middleware. Add it to
Genkit(plugins: [A2uiPlugin()]). - A2uiStreamParser
- Incremental A2UI extractor. Create one per model response, push text deltas as they arrive, and flush at the end to drain any trailing block.
- EnvelopeSegment
- The envelopes compiled from one Express block.
- ParseResult
- Result of feeding text to A2uiStreamParser.push.
- ParseSegment
- A single ordered piece of parsed output: either a run of prose or one compiled block. Segments preserve the exact source order, so prose that appears after a block is not reordered ahead of it.
- ProseSegment
- A run of prose text (never contains A2UI blocks).
Enums
- A2uiDynamicType
-
The value type of an A2uiParam.dynamicValue, i.e. which of the spec's
common_types.jsondynamic types it references. - A2uiValidateMode
- How the parser treats a block that fails to compile or validate.
Constants
- a2uiCatalogValueType → const String
-
The registry value type under which A2UI catalogs are stored, so the
a2ui()middleware can look them up by id. Register withregistry.registerValue(...)vialoadCatalog. - a2uiExpressMetadataKey → const String
-
The a2ui part
metadatakey holding the A2UI Express source a part's messages were compiled from. - a2uiMimeType → const String
-
The MIME type that identifies an A2UI payload. This is stamped onto the
metadata.mimeTypeof the Genkitdatapart that carries A2UI envelopes, matching the A2A binding of the A2UI spec exactly. - basicCatalogId → const String
-
The catalog id of the A2UI v1.0 "Basic Catalog". Surfaces created with the
bundled
basicCatalogreference this id, and the client renderer registers a catalog under the same id. - basicCatalogV09Id → const String
-
The catalog id of the A2UI v0.9 "Basic Catalog", used by
basicCatalogV09. - basicCatalogV09LookupId → const String
-
The lookup id that selects basicCatalogV09 (A2UI v0.9) in
a2ui(). -
basicIconNames
→ const List<
String> -
The icon names the bundled basic catalog's
Iconcomponent accepts. It is an enum in the catalog, so the prompt lists the names and a block using any other name fails to compile (and goes to repair, if enabled). - defaultCatalogId → const String
-
The default catalog id used by the
a2ui()middleware when none is given. Resolves to the bundled basicCatalog (A2UI v1.0).
Properties
- basicCatalog → A2uiCatalog
-
The A2UI "Basic Catalog" (v1.0), derived from
a2ui_core's copy of the published catalog. Use this to render standard UI without defining your own design system.final - basicCatalogV09 → A2uiCatalog
-
The A2UI v0.9 "Basic Catalog", kept for clients that still render v0.9.
Select it with
a2ui(catalog: basicCatalogV09LookupId)('basic-v0.9'), or extend it withbasicCatalogV09.extend(...).final
Functions
-
a2ui(
{String? catalog, String? instructions, String? validate, String? version, bool? repair}) → GenerateMiddlewareRef< A2uiOptions> -
Creates a reference to the A2UI middleware for use in a
use: [...]list. -
a2uiEnvelopesFromParts(
List< Part> ? parts) → List<A2uiEnvelope> -
Extracts all A2UI envelopes carried by the given
parts. -
a2uiPart(
List< A2uiEnvelope> envelopes, {String? source}) → DataPart -
Builds an a2ui data part wrapping the given
envelopes. -
isA2uiPart(
Part part) → bool -
Whether the given
partis an a2ui data part. -
loadCatalog(
Genkit ai, {required String id, A2uiCatalog? catalog, String? file}) → Future< A2uiCatalog> -
Registers an A2UI catalog under an
idso thea2ui()middleware can look it up (viaa2ui(catalog: id)). Provide eithercatalogorfile. -
renderCatalogInstructions(
A2uiCatalog catalog) → String -
Renders a catalog into model-facing instructions: when and how to render
UI, then the A2UI Express contract and the catalog's signatures (from
a2ui_agent). Injected into the system prompt by the middleware wheninstructions != 'none'. -
resolveCatalog(
Registry registry, String id) → A2uiCatalog -
Resolves a catalog by id from the registry, falling back to the bundled
basicCatalog for defaultCatalogId (
'basic') or basicCatalogV09 for basicCatalogV09LookupId ('basic-v0.9'). Used by thea2ui()middleware.
Typedefs
-
A2uiEnvelope
= Map<
String, dynamic> - A single agent -> renderer A2UI envelope message, in its raw JSON shape.