toasterAgent

The Toaster's adapter for the agent bridge, @cloudlet/toast/agent — its records, verbs, permissions, refusals and the changes it reports.

On this page

toasterAgent connects a Toaster controller to @cloudlet/agent. It lives in the package as the subpath @cloudlet/toast/agent, from 1.4.0; the main entry never loads it. Like the bridge it is experimental: its records may change before the bridge reaches 1.0. The guide is Agents.

signature
import type { CancellationSignal, CloudletController } from '@cloudlet/toast';
import type { ToasterAgent, ToasterAgentOptions } from '@cloudlet/toast/agent';

declare function toasterAgent<Slot, Signal extends CancellationSignal>(
  controller: Omit<CloudletController<Slot, Signal>, 'track'>,
  options?: ToasterAgentOptions,
): ToasterAgent;
NameTypeDescription
controllerCloudletControllerA controller of this copy of @cloudlet/toast; any other throws a TypeError.
options.namestringOptional. The component's name and the prefix of its refs, [a-z][a-z0-9-]*; default toaster. Two controllers on one agent need two names.
returnsToasterAgentThe object to pass to agent.connect.

The adapter touches no DOM, starts no timers, never takes the host from a Toaster and never moves focus. It speaks protocol 1, so any @cloudlet/agent 0.x that understands protocol 1 works with it; the two packages do not depend on each other.

Records

The snapshot holds a ToasterEntry for the Toaster, then a NotificationEntry per notification in presentation order; together they are ToasterAgentEntry. The Toaster's ref is its name (toaster), a notification's is the name and a number (toaster:3). A number is never reused; a new adapter starts counting again.

ToasterEntry:

FieldTypeDescription
component'toaster'
actionsreadonly string[]open, close, clear, acknowledge, by state.
island{ open, current }Whether the Island is open, and the ref of the notification it shows (null while closed).
guest{ ref } | nullThe app's own content holding the Island instead of notifications, such as a tour in the Island; ref is the record to steer it through (IslandGuideContent.ref, else its label), when it named one. Meanwhile open and show are refused with "A tour is in progress in the Island" and new notifications wait. Null when notifications have the Island.
countnumberNotifications in the stack.
overflow{ count, pending }Notifications that did not fit, and whether that is still unacknowledged.
mountedbooleanA Toaster renders this controller.

NotificationEntry:

FieldTypeDescription
component'notification'
actionsreadonly string[]dismiss, show (with a mounted Toaster), press, fill, submit, cancel, retry, by state.
labelstringThe title.
textstring | nullThe description as text; for rich content, its announcement.
kind, priority, occurrences, locationas in NotificationSnapshot
remainingMs, pauseReasonsnumber | null, readonly PauseReason[]Time left, and why it is paused.
progress{ kind, value, label } | null
draftbooleanIts form holds text that was not sent.
operationOperationEntry | null{ status, attempt, canCancel, canRetry, cancelRequested }, without the attempt token.
actionActionEntry | nullThe primary action, below.

ActionEntry is { kind, label, status, message, agent?, href?, fields?, error? }: kind is command, link or form; status is idle, pending or failed; agent is the action's marker (confirm when the app set none; a link has none); href only for a link. A form's fields are FormFieldEntry records, { name, label, kind, required, maxLength, inputMode, filled, filledBy, error }: filled says whether a field holds non-blank text and filledBy who wrote it last (app for its default, user, agent, or null), never what. Form values, defaults and placeholders never reach the snapshot. A failed form's message, and a field or form error that came from the form's own validate, are fixed phrases (Action failed, Not accepted by the form's own check), because the app's text may quote what the person typed; the built-in required and maxLength messages come as they are.

Verbs and permissions

RecordVerbArgsNeedsWhat it does
Toasteropen—allowOpens the Island on the notification it shows first. Needs a mounted Toaster; refused while the person is using it.
Toasterclose—allowCloses the open Island; refused over a form someone started filling.
Toasterclear—allowCloses every notification.
Toasteracknowledge—allowMarks the overflow as seen: overflow.pending turns false.
Notificationdismiss—allowCloses it; the record leaves the snapshot (gone).
Notificationshow—allowOpens the Island on it, like open.
Notificationpress—the markerRuns the command and waits: success closes the notification, pending means it is still working.
Notificationfill[name, text]allowWrites a form field as the agent, by the field's name, never over text the person typed.
Notificationsubmit—the markerSends the form and waits, like press; a refusal names the fields that were not accepted.
Notificationcancel—allowAsks the operation to stop; result requested.
Notificationretry—allowStarts the failed operation again; result started.

allow means the step runs unless the bridge's allow says no. press and submit follow the agent marker of the command or form (agent: 'allow' | 'confirm' | 'deny' on CommandAction and FormAction): confirm, the default, needs a person's approval; deny removes the verb from actions, while fill stays. A link has no verb at all: the bridge never opens one, its address is href.

Needs a person. A press or submit that nobody approved is brought to the person: summon opens the Island on that notification at once, or after the attention delay once they stop using the Toaster, and never moves focus. The agent reads Needs a person: … with one of The Island is open on it., The Island will open on it once they stop using it. or No Toaster is on screen, so tell them what it does.

The person comes first. While they use the Toaster (hover, focus, a gesture, a draft in the open Island, the agent's own included), open and show answer The person is using the Island. Try again later., and close over a draft is refused.

Refusals

The adapter words these itself; the bridge words the rest from the record's actions. Labels and titles are quoted with JSON quotes.

WhenMessage
open or show without a mounted ToasterNo Toaster is on screen: "open" needs one.
Arguments where none are taken"dismiss" on "toaster:3" takes no arguments.
fill without a name and a value"fill" on "toaster:3" takes a field name and a value.
An unknown fieldNo field "x" on "toaster:3". Fields: "reply".
A value that is not a stringThe value for "reply" must be a string.
Too long"reply" takes at most 80 characters.
The person typed thereThe person typed in "reply". An agent can't overwrite it.
The form refused"Send" was not sent. … with the fields' messages
Already running"Send" is already running.
The action failed"Send" failed: …
OperationsThis operation has already finished., Cancelling this operation was already requested., This operation can't be cancelled., This operation is still running, so it can't be retried yet., This operation can't be retried.

Changes

subscribe reports what changed after every change of the controller, with source from the Toaster's own ChangeSource. label is the notification's title.

RecordKeyValues
Notificationpresenttrue when it appears, false when it closes, with the CloseReason in reason.
NotificationcontentThe app updated it; both values are null.
Notificationactionidle, pending, failed.
Notificationoperationpending, cancel-requested, fulfilled, rejected, cancelled.
Notificationfield:<name>Who wrote the field last: app, user, agent or null; only when the author changes, never the text.
ToasterislandThe ref of the notification the Island shows, or null.
ToasteroverflowThe missed count, after it was acknowledged.

Two sources follow from the rule rather than from a hand: action going back to idle because an operation's outcome replaced the content is system, and field:<name> turning null because the app replaced the form is app. A report never holds more than 1000 changes, which is the bridge's limit; a pause or a timer tick changes the snapshot with an empty report.

ToasterAgent

ToasterAgent is the AgentComponent the adapter returns: protocol, name, snapshot (the same frozen array until the controller changes, empty after dispose), subscribe, check, run, summon and verbs, the text of each verb above for a model.

The subpath also exports the shapes of the bridge's protocol it implements, so that @cloudlet/toast needs no dependency on @cloudlet/agent, even for types: AgentEntryShape, AgentSignalShape, AgentValueShape, AgentPermissionShape, AgentStepCallShape, AgentStepNamesShape, AgentStepCheckShape, AgentRunContextShape, AgentRunOutcomeShape, AgentSummonOutcomeShape, AgentChangeShape, AgentVerbsShape and AgentComponentShape. They match AgentEntry, AgentSignal and the rest of the bridge's types one for one; you never write them yourself.