genui library

The core library for the Flutter GenUI framework.

This library provides the necessary components to build generative user interfaces in Flutter applications. It includes models for UI components, data handling, and communication with a generative AI service.

Classes

A2UiClientCapabilities
Describes the client's UI rendering capabilities to the server.
A2uiMessage
A sealed class representing a message in the A2UI stream.
A2uiMessageEvent
An event containing a parsed A2uiMessage.
A2uiMessageSink
An interface for a message sink that accepts A2uiMessages.
A2uiParserTransformer
Transforms a stream of text chunks into a stream of logical GenerationEvents.
A2uiSchemas
Provides a set of pre-defined, reusable schema objects for common A2UI patterns, simplifying the creation of CatalogItem definitions.
A2uiTransportAdapter
The primary high-level API for typical Flutter application development.
ActionDelegate
A delegate for handling UI actions in Surface.
BasicCatalogItems
A collection of basic catalog items that can be used to build simple interactive UIs.
BoundBool
Binds to a bool value.
BoundList
Binds to a List of objects.
BoundNumber
Binds to a num value.
BoundObject
Binds to any Object value.
BoundString
Binds to a String value.
BoundValue<T>
A widget that binds to a value in the DataContext and rebuilds when it changes.
BoundValueState<T, W extends BoundValue<T>>
State class for BoundValue.
CancellationSignal
A signal that can be used to cancel an operation.
Catalog
Represents a collection of UI components that a generative AI model can use to construct a user interface.
CatalogItem
Defines a UI layout type, its schema, and how to build its widget.
CatalogItemContext
Context provided to a CatalogItem's widget builder.
ChatMessage
A chat message.
ChatMessageView
A widget to display a chat message.
Component
A component in the UI.
ComponentsUpdated
Fired when an existing surface is modified.
Conversation
Facade for managing a GenUI conversation.
ConversationComponentsUpdated
Fired when components are updated on a surface.
ConversationContentReceived
Fired when new content (text) is received from the LLM.
ConversationError
Fired when an error occurs during the conversation.
ConversationEvent
Events emitted by Conversation to notify listeners of changes.
ConversationState
State of the conversation.
ConversationSurfaceAdded
Fired when a new surface is added.
ConversationSurfaceRemoved
Fired when a surface is removed.
ConversationWaiting
Fired when a request is sent to the LLM and the conversation is waiting for an AI response.
CreateSurface
An A2UI message that signals the client to create and show a new surface.
DataContext
A contextual view of the main DataModel, used by widgets to resolve relative and absolute paths.
DataModel
Manages the application's data model and provides a subscription-based mechanism for reactive UI updates.
DataPart
A data part containing binary data (e.g., images).
DataPath
Represents a path in the data model, either absolute or relative.
DebugCatalogView
A widget that displays a catalog of GenUI components.
DefaultActionDelegate
The default action delegate that handles standard actions like 'showModal'.
DeleteSurface
An A2UI message that deletes a surface.
FallbackWidget
A widget that displays a fallback UI for error or loading states.
GenerationEvent
A base class for events related to the GenUI generation process.
InMemoryDataModel
Standard in-memory implementation of DataModel.
InternalMessageView
A widget to display an internal message in the chat.
LinkPart
A link part referencing external content.
OptionalValueBuilder<T>
A builder widget that simplifies handling of nullable ValueListenables.
Part
Base class for message content parts.
PartConverter<T extends Part>
A converter that converts a JSON map to a Part.
Parts
A collection of parts.
PromptBuilder
A builder for a prompt to generate UI.
PromptFragments
Common fragments for prompts, to explain agent behavior.
RegistryEvent
Events emitted by the SurfaceRegistry.
StandardPart
Base class for parts that became de-facto standard for AI messages.
Surface
A widget that renders a dynamic UI surface generated by the AI.
SurfaceAdded
Fired when a new surface is created.
SurfaceContext
An interface for a specific UI surface context.
SurfaceController
The runtime controller for the GenUI system.
SurfaceDefinition
A data object that represents the entire UI definition.
SurfaceHost
An interface for a host that manages UI surfaces.
SurfaceOperations
Pieces of prompt that defines allowed surface operations.
SurfaceRemoved
Fired when a surface is deleted.
SurfaceUpdate
A sealed class representing an update to the UI managed by the system.
TechnicalPossibilities
TextEvent
An event containing a text chunk from the LLM.
TextPart
A text part of a message.
ThinkingPart
A "thinking" part of a message, used by some models to show reasoning.
ToolDefinition<TInput extends Object>
A tool that can be called by the LLM.
ToolPart
A tool interaction part of a message.
Transport
An interface for transporting messages between GenUI and an AI service.
UiInteractionPart
A view over a DataPart representing a UI interaction.
UiPart
A view over a DataPart representing a UI definition.
UiPartConstants
Constants for UI related parts.
UpdateComponents
An A2UI message that updates a surface with new components.
UpdateDataModel
An A2UI message that updates the data model.
ValidationError
A validation error with a message.
ValidationHelper
A helper class for handling reactive validation logic.

Enums

ChatMessageRole
The role of a message author.
InlineCatalogHandling
Defines how catalogs should be handled when generating client capabilities.
ProtocolMessages
ToolPartKind
The kind of tool interaction.

Extension Types

UiEvent
A data object that represents a user interaction event in the UI.
UserActionEvent
A UI event that represents a user action.

Extensions

ChatMessageFactories on ChatMessage
Extension to help with UserMessage usages if needed, or just helper factories.
UiPartExtension on StandardPart
Helper extension to interact with UI parts.
UiPartListExtension on Iterable<StandardPart>

Constants

basicCatalogId → const String
The catalog ID for the basic catalog.
defaultPartConverterRegistry → const Map<String, JsonToPartConverter<Part>>
Converter registry for parts in this package.
surfaceIdKey → const String
Key used in schema definition to specify the component ID.

Properties

genUiLogger → Logger
The logger for the GenUI package.
final

Functions

configureLogging({Level level = Level.INFO, void logCallback(Level, String)?, bool enableHierarchicalLogging = true}) → Logger
Configures the logging for the GenUI package.
generateId() String
Generates a unique ID (UUID v4).
resolveContext(DataContext dataContext, JsonMap? contextDefinition) Future<JsonMap>
Resolves a context map definition against a DataContext.

Typedefs

CatalogWidgetBuilder = Widget Function(CatalogItemContext itemContext)
A callback that builds a widget for a catalog item.
ChildBuilderCallback = Widget Function(String id, [DataContext? dataContext])
A callback that builds a child widget for a catalog item.
DispatchEventCallback = void Function(UiEvent event)
A callback that is called when an event is dispatched.
ExampleBuilderCallback = String Function()
A callback that builds an example of a catalog item.
GetComponentCallback = Component? Function(String componentId)
A callback to get a component definition by its ID.
JsonMap = Map<String, Object?>
A map of key-value pairs representing a JSON object.
JsonToPartConverter<T extends Part> = Converter<Map<String, Object?>, T>
ManualSendCallback = Future<void> Function(ChatMessage message)
A manual sender callback.
SendEventsCallback = void Function(String surfaceId, List<UiEvent> events)
A callback that is called when events are sent.
UiEventCallback = void Function(UiEvent event)
A callback for when a user interacts with a widget.

Exceptions / Errors

A2uiValidationException
Exception thrown when validation fails.
CancellationException
An exception thrown when an operation is cancelled.
CatalogItemNotFoundException
An exception thrown when a requested item is not found in the Catalog.
DataModelTypeException
Exception thrown when a value in the DataModel is not of the expected type.