UiSession class

A document an agent writes and edits with ops, shown by CodelesslyView(session: ...).

final session = UiSession(catalog: Catalog.core);
final result = await session.applyStream(toolInputDeltas); // renders as each op arrives
llm.toolResult(result.toModelJson());
session.events.listen((e) => llm.send(e.toModelMessage()));

It is a NodeSource: each applied op notifies only the nodes it changed, so the render tree re-applies only their boxes. A child listed before its node arrives is a box that takes no room (or a placeholder of the size an op gave), so its arrival re-applies only that box.

Implemented types

Constructors

UiSession({LayoutDocument? document, Catalog catalog = Catalog.core, TrustProfile? profile, DesignSystem? designSystem, ThemeTokens? theme, EditCheck? check = catalogCheck, int placeholderColor = 0x14808080, Duration? arrivalFade, bool holdEmptyContainers = true, bool protectRoots = true, GlyphCoverage? glyphCoverage})

Properties

arrivalFade → Duration?
When set, a node that arrives while a stream runs fades in over this long (an enter animation from opacity 0). Off by default.
final
blocksAdded → ValueNotifier<int>
Counts the blocks added while the session runs (addBlock): a view listens and makes each new one drawable.
final
catalog → Catalog
What node and action types decode with.
no setter
changes → Stream<EditResult>
Every batch's result, as it applies (each op of a stream too).
no setter
check → EditCheck?
The check each op's nodes pass (catalogCheck by default); null: structure and the profile only.
final
debugUndoDepth → (int, int)
The undo and redo stack depths (for tests).
no setter
designSystem → DesignSystem?
The design system the UI is made with: its components are node types of catalog (a call is checked against its declaration), its tokens are theme, and a model's prompt is generated from it (runtimeStarter(designSystem: ...)). Null: none; the UI's controls are SSUI's, the bundled default.
no setter
document → LayoutDocument
The document now.
no setter
events → Stream<UiEvent>
Interactions the UI routes to its host (UiEvent).
no setter
glyphCoverage → GlyphCoverage?
Which characters the fonts the app loaded can draw; with it, the end of a stream reports text with characters they cannot (missing_glyph, renderDiagnostics).
final
hashCode → int
The hash code for this object.
no setterinherited
holdEmptyContainers → bool
Whether a node with children, none of which shows yet (each pending, or held the same way), is held back (shown as nothing) until one does, so a stream shows no empty shells. A node without children shows as soon as it arrives.
final
lastStreamEnd ↔ OpStreamEnd?
How the last stream's text ended: repairs of malformed JSON, ops recovered, the truncated tail (OpStreamEnd).
getter/setter pair
notationIssues → List<NotationIssue>
What the last applyNotation could not read, by line.
no setter
pending → Set<String>
The ids referenced but not yet defined.
no setter
placeholderColor → int
The color (ARGB) of a placeholder: the box shown for a pending child an op gave a size for (SetOp.placeholders).
final
profile → TrustProfile
What the document may use (TrustProfile.agent by default), with the designSystem's components allowed when there is one.
no setter
protectRoots → bool
Whether a batch (or stream) applied to a UI that already has roots may not replace them or add a canvas: start_over, so a model fixes the UI by patching it instead of rebuilding it under new ids. A new UI (no roots yet) is never limited.
final
rev → int
The document's revision: the number of batches (calls, streams) that changed it.
no setter
revision → ValueListenable<int>
rev, as it changes.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
streaming → ValueListenable<bool>
Whether a stream is being applied.
no setter
theme → ThemeTokens
The theme the UI is shown in: the design system's tokens with the app's theme over them, else that theme, else none (the controls are SSUI's, the bundled default; plain text takes the platform's font). Nothing comes from the theme of the app around the view.
final
tools → List<Json>
The two tools a model is given (ui_apply, ui_read), for catalog restricted by profile.
no setter
values → Json
The variable values of the views showing this session, as they run (for tools and tests: what an interaction changed).
no setter
wantedBlocks → List<WantedBlock>
The components the last applyNotation asked for because none fitted (see notationInstructions' askForBlocks), in the order written.
no setter

Methods

addBlock(LayoutDocument definition) → void
Adds a block to the session's design system while it runs, or replaces the one of the same type: definition is a component document (its widget declares the type and parameters). From the next answer on it is called by name like the others (notationInstructions lists it), and a view already showing the session draws it. This is how a block designed after the session began (because no block fitted a request) comes into use. Needs a designSystem.
apply(Object? ops, {String author = 'agent', int? baseRev, bool atomic = false}) → EditResult
Applies ops (a list of EditOps, or the ui_apply tool input JSON) as one batch: one revision, one undo step. Rejected ops change nothing; the result says why (EditResult.toModelJson is the tool result).
applyNotation(Stream<String> text, {NotationOptions? options, String prelude = '', String author = 'agent', bool replace = false, void onOp(StreamProgress progress)?}) → Future<EditResult>
Applies a UI written in the compact notation (package:codelessly_api/notation.dart: one node per line, nested by indentation) as it arrives: each completed line becomes its edit operations and is applied at once, so the UI paints line by line. The rest is applyStream: one revision, one undo step, the same checks and result. What the notation could not read is in notationIssues.
applyStream(Stream<String> deltas, {String author = 'agent', int? baseRev, EditOp map(EditOp op)?, void onOp(StreamProgress progress)?, bool? protect}) → Future<EditResult>
Applies a streamed ui_apply tool input: deltas are the raw text chunks as the model's API delivers them. Each op is applied the moment it is complete (a set with nodes, node by node), so the UI paints as the answer arrives; the whole stream is one revision and one undo step. At the end, ids still pending are dangling_child errors in the result, so the model can send them.
attachLayoutProbe(Iterable<(String, double, double)> sizes()) → VoidCallback
Registers a laid-out view of this session (what layoutDiagnostics reads); the returned callback unregisters it.
attachShownProbe(List<EditDiagnostic> check()) → VoidCallback
Registers a laid-out view's check of what it shows (what shownDiagnostics reads); the returned callback unregisters it.
attachValuesProbe(Json values()) → VoidCallback
Registers a view's variable values (what values reads); the returned callback unregisters it.
describeForModel({String starter = ''}) → String
What to tell a model about this UI: starter (the authoring guide it writes from), the node and action types it may use (compact), and the rules of the ops. The tools themselves are tools.
dispose() → void
Closes events and changes.
docs(Object? input) → String
Answers a ui_docs tool call ({"topic": ...}): one topic of the reference, for what profile allows (docsTopic).
emit(UiEvent event) → void
Reports an interaction (what CodelesslyView does for the UI's events).
layoutDiagnostics() → List<EditDiagnostic>
no_size warnings: nodes with content (text, an icon, a fill, children that show) that the views showing this session laid out with no width or no height. Call it after a frame.
node(String id) → Node?
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notationInstructions({Set<String>? blocks, bool askForBlocks = false}) → String
What a model is told so that it writes this session's UI in the compact notation: the grammar, the words, and the designSystem's components. blocks names the only components to list (an app's own screen blocks, not the whole base set), which keeps the instructions short.
outline() → Json
The outline a model reads before it edits (outline).
parentOf(String id) → String?
override
read(Object? input) → Json
Answers a ui_read tool call.
redo({String? author}) → bool
Re-applies the last undone batch.
renderDiagnostics({Iterable<String>? ids}) → List<EditDiagnostic>
What the UI gets wrong that no declaration catches, as warnings in the result's shape (so a host returns them with validation and the model fixes them on its retry): a tappable box with no label (empty_button), text in its background's color (low_contrast), with glyphCoverage characters the fonts cannot draw (missing_glyph), and, once a CodelesslyView has laid it out, nodes with content laid out with no size (no_size, layoutDiagnostics). ids: only these nodes (default: all).
shownDiagnostics() → List<EditDiagnostic>
What the views showing this session show wrong, once they have laid it out (call it after a frame): a document can be valid and show nothing. layoutDiagnostics (no_size), and empty_view (the canvas shows no text, icon, image or control), list_empty (a list with no items while its data is not a list, has no template, or is empty while the list it reads is not), empty_label (a control or component whose label gave nothing), expression_not_evaluated, text_no_color (no color, or a transparent one) and component_empty (a call that rendered nothing). A host adds them to the stream's result before it answers the model (result.withDiagnostics(session.shownDiagnostics())), so a model whose valid UI shows nothing is told, in its retry.
toString() → String
A string representation of this object.
inherited
undo({String? author}) → bool
Undoes the last batch (of author, when given): its inverse ops, applied atomically and checked like any batch (a field someone else changed since is stale_rev). False when there is nothing to undo or the inverse was rejected.
watch(String id) → ValueListenable<Node?>
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited