@cloudlet/toast 1.2.0 → 1.4.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +7 -3
  3. package/dist/agent.d.ts +334 -0
  4. package/dist/agent.d.ts.map +1 -0
  5. package/dist/agent.js +494 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/contracts/events.d.ts +14 -0
  8. package/dist/contracts/events.d.ts.map +1 -1
  9. package/dist/contracts/internal.d.ts +16 -2
  10. package/dist/contracts/internal.d.ts.map +1 -1
  11. package/dist/contracts/notifications.d.ts +16 -0
  12. package/dist/contracts/notifications.d.ts.map +1 -1
  13. package/dist/contracts/snapshots.d.ts +8 -0
  14. package/dist/contracts/snapshots.d.ts.map +1 -1
  15. package/dist/core/actions.d.ts +69 -0
  16. package/dist/core/actions.d.ts.map +1 -0
  17. package/dist/core/actions.js +160 -0
  18. package/dist/core/actions.js.map +1 -0
  19. package/dist/core/agent-port.d.ts +116 -0
  20. package/dist/core/agent-port.d.ts.map +1 -0
  21. package/dist/core/agent-port.js +138 -0
  22. package/dist/core/agent-port.js.map +1 -0
  23. package/dist/core/bridge.d.ts.map +1 -1
  24. package/dist/core/bridge.js +120 -231
  25. package/dist/core/bridge.js.map +1 -1
  26. package/dist/core/controller.d.ts +44 -9
  27. package/dist/core/controller.d.ts.map +1 -1
  28. package/dist/core/controller.js +367 -292
  29. package/dist/core/controller.js.map +1 -1
  30. package/dist/core/validation.d.ts.map +1 -1
  31. package/dist/core/validation.js +103 -94
  32. package/dist/core/validation.js.map +1 -1
  33. package/dist/react/card.d.ts.map +1 -1
  34. package/dist/react/card.js +3 -3
  35. package/dist/react/card.js.map +1 -1
  36. package/dist/react/gestures.d.ts +6 -0
  37. package/dist/react/gestures.d.ts.map +1 -1
  38. package/dist/react/gestures.js +28 -15
  39. package/dist/react/gestures.js.map +1 -1
  40. package/dist/react/host.d.ts.map +1 -1
  41. package/dist/react/host.js +290 -270
  42. package/dist/react/host.js.map +1 -1
  43. package/dist/react.d.ts +9 -1
  44. package/dist/react.d.ts.map +1 -1
  45. package/dist/styles.css +1 -1
  46. package/package.json +3 -2
  47. package/src/agent.ts +879 -0
  48. package/src/contracts/events.ts +15 -0
  49. package/src/contracts/internal.ts +14 -1
  50. package/src/contracts/notifications.ts +16 -0
  51. package/src/contracts/snapshots.ts +8 -0
  52. package/src/core/actions.ts +149 -0
  53. package/src/core/agent-port.ts +237 -0
  54. package/src/core/bridge.ts +19 -105
  55. package/src/core/controller.ts +183 -56
  56. package/src/core/validation.ts +6 -3
  57. package/src/react/card.tsx +4 -3
  58. package/src/react/gestures.ts +45 -8
  59. package/src/react/host.tsx +48 -12
  60. package/src/react.ts +9 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,144 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0-rc.1 — 2026-11-28
4
+
5
+ A trial prerelease under the npm `next` dist-tag (`npm install @cloudlet/toast@next`); `latest` stays
6
+ at 1.3.0. New: the `reducedMotion` prop, `source` on every event and close notice, and the
7
+ experimental `@cloudlet/toast/agent` subpath that connects a controller to the kit's agent bridge
8
+ `@cloudlet/agent`; the root entry does not load it. Two things to check when you upgrade: an
9
+ ancestor with `data-reduced-motion` now calms the Toaster, and code that builds an event, a close
10
+ notice or an Island snapshot by hand now adds `source` (see API).
11
+
12
+ ### Features
13
+
14
+ - `Toaster` takes the app's own reduced-motion setting: the `reducedMotion` prop and
15
+ `data-reduced-motion` on any ancestor of the Toaster (by presence, with any value, as the kit's
16
+ registry components read it). Either one gives the same calm mode as the system's
17
+ `prefers-reduced-motion: reduce`, live and without a remount; neither can turn motion on against
18
+ the system, so `reducedMotion={false}` means "follow the system and the attribute". The host's own
19
+ `data-reduced-motion` still reports the result. An app that already sets `data-reduced-motion` on
20
+ an ancestor for another reason now gets a calm Toaster.
21
+ - Experimental: `@cloudlet/toast/agent` exports `toasterAgent(controller, { name? })`, which lets an
22
+ agent read a controller through the kit's agent bridge (`@cloudlet/agent`). Its snapshot lists the
23
+ Toaster (Island, count, overflow, whether a `Toaster` is mounted) and every notification in
24
+ presentation order: title, text, kind, time left, operation state and the action, with the verbs
25
+ that apply. Form fields say whether they hold text; their values never leave Cloudlet. The subpath
26
+ reads the controller without the host lease, DOM or timers, and the root entry does not load it.
27
+ - Experimental: a command or a form action takes `agent: 'allow' | 'confirm' | 'deny'`, which says
28
+ what an agent may do with it through `@cloudlet/toast/agent`; omitted means `confirm`. The agent
29
+ snapshot shows it as `action.agent`, and under `deny` it lists no `press` or `submit` (an agent can
30
+ still fill a form's fields). A link rejects the field with `invalid-input`. A person presses and
31
+ submits as before, whatever the marker.
32
+ - Experimental: `toasterAgent` runs steps sent through `agent.act` of `@cloudlet/agent`: `open`,
33
+ `close`, `clear` and `acknowledge` on the Toaster record; `show`, `dismiss`, `press`, `cancel` and
34
+ `retry` on a notification. A step changes the controller the way the matching call does
35
+ (`dismiss` closes as `programmatic`, `clear` as `clear`, `open` and `show` open the Island for
36
+ attention). `press` follows the action's `agent` marker and reads it again right before the
37
+ command runs, so a marker made stricter while the step waited for approval stops it, and so does an
38
+ action the app replaced in the meantime: an approval covers the action it was asked about, and a form whose own `validate` replaces
39
+ its action is not sent, by an agent or by a person; it waits for
40
+ the command and, when it fails, returns the message the person sees. `cancel` and `retry` return at
41
+ once (`requested`, `started`). `open` and `show` need a mounted `Toaster` and are listed only while
42
+ one is. No step moves focus or takes the host from a `Toaster`.
43
+ - Experimental: when a `press` needs a person (no `allow`, or `allow` said no or did not answer),
44
+ `toasterAgent` opens the Island on that notification for them, for attention and without moving
45
+ focus, even if the notification asks for no auto-open. If the person is using the Toaster at that
46
+ moment (hover, focus, a gesture, or a draft in the open Island), the Island waits until they stop
47
+ and then opens after the attention delay, and the agent is told so; a notification closed in the
48
+ meantime is not shown. The app's own auto-open keeps working alongside. While the person uses the
49
+ Toaster, `open` and `show` answer "The person is using the Island. Try again later." and change
50
+ nothing; `close` does the same over a draft in the open Island.
51
+ - Experimental: `toasterAgent` fills and submits forms. `fill` with `args: [name, value]` writes a
52
+ field as the agent: it refuses an unknown field (and lists the field names), a value that is not a
53
+ string or longer than the field's `maxLength`, a running submit, and any field the person typed in,
54
+ even one they cleared again, naming the field but never a value. An agent's value makes a draft as
55
+ typing does (the `draft` pause, the open Island stays open), and a person who submits sends it.
56
+ `submit` follows the form's `agent` marker like `press`, and a submit that needs a person opens the
57
+ Island on the form for them; a form that fails its checks is not sent, the person sees the
58
+ messages, and the agent gets the built-in ones by field label (`"Send" was not sent. "Reply": This
59
+ field is required.`). What the form's own `validate` and `errorMessage` say may quote what the
60
+ person typed, so the agent never gets that text, in a result or in the snapshot: it reads which
61
+ fields were not accepted (`The form's own check did not accept "Reply".`) or `"Send" failed:
62
+ Action failed`; a `validate` that throws answers `Action failed` too. Each field in the agent snapshot now has `kind`, `maxLength`, `inputMode` and
63
+ `filledBy` (`app` for the default, `user`, `agent` or null); values, defaults and placeholders
64
+ still never leave Cloudlet.
65
+ - Experimental: `toasterAgent` tells the bridge what changed and who changed it. A listener of
66
+ `agent.subscribe` receives records `{ ref, component, label?, key, value, previous, reason?,
67
+ source }` together with the new snapshot. On a notification: `present` (`true` when it appears,
68
+ `false` when it closes, with the close reason in `reason`), `content` (the app updated it),
69
+ `action` (`idle`, `pending`, `failed`), `operation` (`pending`, `cancel-requested`, `fulfilled`,
70
+ `rejected`, `cancelled`) and `field:<name>` (who wrote a form field last: `app`, `user`, `agent`
71
+ or null). On the Toaster record: `island` (the `ref` of the notification it shows, or null) and
72
+ `overflow` (after the missed count was acknowledged). `source` is who did it, so an agent's
73
+ `dismiss` step arrives as `present: false`, `reason: 'programmatic'`, `source: 'agent'`, and the
74
+ close button as `user`. `label` is the notification's title, since a closed one is no longer in
75
+ the snapshot. A field reports only a change of author, once however much is typed, and never its
76
+ text. A notification's `ref` is now issued when it appears, so one that is shown and closed
77
+ between two reads still has its number in both records; an adapter that nobody subscribed to
78
+ numbers on reading, as before.
79
+ - Experimental: `toasterAgent` tells the bridge what its verbs do. The component it returns carries
80
+ `verbs`: for the `toaster` and `notification` records, one or two English lines per verb on its
81
+ arguments in order (`fill [field name, text]` takes the field's name, not its label), what it does
82
+ and when `press` or `submit` may need a person; a link action has no verb, and its address is
83
+ `action.href`. The bridge passes these to a model next to the snapshot.
84
+ - Every event, `onClose` and the Island snapshot say who caused the change. `event.source`,
85
+ `CloseNotice.source` and `getSnapshot().island.source` are a `ChangeSource`: `user` (a person,
86
+ through the `Toaster`), `agent` (a step taken through `@cloudlet/toast/agent`), `app` (your code,
87
+ through the controller or an operation handle) or `system` (a timer, the outcome of an operation,
88
+ `dispose()`). A notification closed by the close button, by `dismiss(handle)`, by an agent's
89
+ `dismiss` step and by its timer reports `user`, `app`, `agent` and `system`; the close reasons are
90
+ unchanged, so an agent's `dismiss` is `programmatic` with `source: 'agent'`. An action remembers
91
+ who pressed it: `action-started`, `action-failed` and the `action-success` close carry that source
92
+ however long the action runs. A retry and a cancellation name who asked; `operation-settled` is
93
+ always `system`. `island.source` is who opened the Island or changed its slide last (`system` when
94
+ it opened for attention on its own, `agent` for an agent's step or its request for a person) and
95
+ `null` while it is closed. No event type, `CloseReason` or `IslandReason` was added.
96
+
97
+ ### API
98
+
99
+ - `ChangeSource` is exported. `EventBase.source`, `CloseNotice.source` and `IslandSnapshot.source`
100
+ are required fields that Cloudlet always sets, so reading code needs no change.
101
+ - Code that builds a `SemanticEvent`, a `CloseNotice` or an `IslandSnapshot` by hand, in a test or
102
+ a mock, now adds `source`; TypeScript points the places out.
103
+
104
+ ### Fixes
105
+
106
+ - A command or a form is not run when a listener of its `action-started` event dismissed or
107
+ replaced the notification: the attempt ended before it began. An app that closes a notification
108
+ from that event and still wants the action to run closes it from `run` instead.
109
+ - A form field named like an `Object` method (`constructor`, `toString`, …) no longer opens as
110
+ invalid. The form used to read such a name from `Object.prototype`, so the field was marked
111
+ `aria-invalid` and showed a function as its message before any submit. Messages and values are now
112
+ read by the field's own name only; typing, the `validate` message and the submit work as for any
113
+ field, and a required field named `__proto__` keeps its message.
114
+
115
+ ## 1.3.0 — 2026-11-24
116
+
117
+ The stack can sit in a corner. Nothing is removed or changed in behaviour; the new positions are
118
+ additive (see API).
119
+
120
+ ### Features
121
+
122
+ - `<Toaster position>` takes `top-left`, `top-right`, `bottom-left` and `bottom-right` besides the
123
+ centre. The pill, its tails and the badge keep to that side, and the Island grows away from it: the
124
+ morph, the enter and the exit stay against the edge. The side is physical, so `dir="rtl"` keeps it.
125
+
126
+ ### API
127
+
128
+ - `ToasterProps['position']` widens to `'auto' | 'top-left' | 'top-center' | 'top-right' |
129
+ 'bottom-left' | 'bottom-center' | 'bottom-right'`. Code that narrows it with a `switch` now needs the
130
+ four new values; TypeScript points them out.
131
+ - The host carries `data-align="left|center|right"` beside `data-edge`.
132
+
133
+ ### Fixes
134
+
135
+ - A trackpad swipe over the open Island goes to the next or previous slide even when its first delta
136
+ leans vertical (a finger landing diagonally). The axis is now decided by the first 8 px of travel, as
137
+ for a finger, instead of by the first wheel event, which used to hand the whole swipe to the browser
138
+ and start its back/forward gesture. Over the open Island no sideways wheel event reaches the browser,
139
+ also at either end of the slider and under reduced motion; vertical scrolling and the page outside
140
+ stay native.
141
+
3
142
  ## 1.2.0 — 2026-11-01
4
143
 
5
144
  Clear all in the Island. Nothing is removed or changed in behaviour; the new texts, prop and close
package/README.md CHANGED
@@ -8,7 +8,6 @@
8
8
  # Cloudlet — React notifications and operations
9
9
 
10
10
  [![npm](https://img.shields.io/npm/v/@cloudlet/toast?color=245cdb)](https://www.npmjs.com/package/@cloudlet/toast)
11
- [![min+gzip](https://img.shields.io/badge/min%2Bgzip-9.3%20KB%20first%20load-245cdb)](https://cloudlet.dev/toaster#faq)
12
11
  [![CI](https://github.com/Meerzus/cloudlet/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Meerzus/cloudlet/actions/workflows/ci.yml)
13
12
  [![types](https://img.shields.io/npm/types/@cloudlet/toast)](https://www.npmjs.com/package/@cloudlet/toast)
14
13
  [![license](https://img.shields.io/npm/l/@cloudlet/toast)](https://github.com/Meerzus/cloudlet/blob/main/LICENSE)
@@ -23,7 +22,7 @@ can carry a command, a link, or a short form of up to three text fields that is
23
22
  **Status.** Stable since `1.0.0`; the API follows semantic versioning.
24
23
  Screen readers, physical phones and the minimum browser versions are checked by hand on top of the
25
24
  automated suite; see
26
- [What is tested](https://cloudlet.dev/toaster/docs/accessibility#what-is-tested).
25
+ [What is tested](https://cloudlet.dev/docs/components/toaster/accessibility#what-is-tested).
27
26
 
28
27
  ## Installation
29
28
 
@@ -65,12 +64,17 @@ is permanently finished: in a React effect, clean up exactly the instance that e
65
64
 
66
65
  ## Documentation
67
66
 
68
- Full documentation: **https://cloudlet.dev/toaster/docs**
67
+ Full documentation: **https://cloudlet.dev/docs/components/toaster**
69
68
 
70
69
  - Getting started: Introduction, Installation (npm and the shadcn registry item), Quick start.
71
70
  - Guides: Notifications & time, Operations & cancellation, Forms, Positioning & offsets, Styling,
72
71
  SSR & Next.js, Content Security Policy, Accessibility (including what is and is not tested).
73
72
  - Reference: `createCloudlet`, the controller, Toaster props, labels & announcements, types.
73
+ - Experimental: `@cloudlet/toast/agent` exports `toasterAgent(controller)`, which lets the kit's agent
74
+ bridge, `@cloudlet/agent`, read the controller and run steps on it under the app's permission. It
75
+ may change in any minor release. The adapter speaks agent protocol 1, and the bridge refuses an
76
+ adapter with another protocol number with a `TypeError` at `connect`, so neither package depends on
77
+ the other: any `@cloudlet/agent` 0.x that understands protocol 1 works with it.
74
78
  - The [changelog](CHANGELOG.md) lists every change, including migration from `1.0.0-rc.0`.
75
79
 
76
80
  ## Contributing and security
@@ -0,0 +1,334 @@
1
+ import type { CloudletController } from './contracts/controller.js';
2
+ import type { FormFieldKind, FormInputMode, NotificationKind, Priority } from './contracts/notifications.js';
3
+ import type { CancellationSignal, OperationStatus } from './contracts/operations.js';
4
+ import type { NotificationLocation, PauseReason } from './contracts/snapshots.js';
5
+ /**
6
+ * One record of an agent snapshot, as the bridge reads it.
7
+ *
8
+ * @experimental The protocol may change before the bridge reaches 1.0.
9
+ */
10
+ export type AgentEntryShape = {
11
+ readonly ref: string;
12
+ readonly component: string;
13
+ readonly actions: readonly string[];
14
+ readonly [key: string]: unknown;
15
+ };
16
+ /**
17
+ * A cancellation signal as the bridge hands it out; an `AbortSignal` at runtime.
18
+ *
19
+ * @experimental The protocol may change before the bridge reaches 1.0.
20
+ */
21
+ export interface AgentSignalShape {
22
+ readonly aborted: boolean;
23
+ readonly reason: unknown;
24
+ readonly throwIfAborted: () => void;
25
+ readonly addEventListener: (type: 'abort', listener: () => void, options?: {
26
+ readonly once?: boolean;
27
+ }) => void;
28
+ readonly removeEventListener: (type: 'abort', listener: () => void) => void;
29
+ }
30
+ /**
31
+ * A value a step may return to the agent.
32
+ *
33
+ * @experimental The protocol may change before the bridge reaches 1.0.
34
+ */
35
+ export type AgentValueShape = string | number | boolean | null | readonly AgentValueShape[] | {
36
+ readonly [key: string]: AgentValueShape;
37
+ };
38
+ /**
39
+ * What a step may do: on its own, with approval, or never.
40
+ *
41
+ * @experimental The protocol may change before the bridge reaches 1.0.
42
+ */
43
+ export type AgentPermissionShape = 'allow' | 'confirm' | 'deny';
44
+ /**
45
+ * A step as the bridge hands it to a component.
46
+ *
47
+ * @experimental The protocol may change before the bridge reaches 1.0.
48
+ */
49
+ export interface AgentStepCallShape {
50
+ readonly ref: string;
51
+ readonly action: string;
52
+ readonly args: readonly unknown[];
53
+ }
54
+ /**
55
+ * How a person names what a step acts on, for the bridge's messages.
56
+ *
57
+ * @experimental The protocol may change before the bridge reaches 1.0.
58
+ */
59
+ export interface AgentStepNamesShape {
60
+ readonly target: string;
61
+ readonly within?: string;
62
+ }
63
+ /**
64
+ * A component's answer to the bridge's `check`.
65
+ *
66
+ * @experimental The protocol may change before the bridge reaches 1.0.
67
+ */
68
+ export type AgentStepCheckShape = {
69
+ readonly available: true;
70
+ readonly permission: AgentPermissionShape;
71
+ readonly names?: AgentStepNamesShape;
72
+ } | {
73
+ readonly available: false;
74
+ readonly message?: string;
75
+ };
76
+ /**
77
+ * What the bridge's `run` receives besides the step.
78
+ *
79
+ * @experimental The protocol may change before the bridge reaches 1.0.
80
+ */
81
+ export interface AgentRunContextShape {
82
+ readonly signal: AgentSignalShape;
83
+ readonly approved: 'allow' | 'confirm';
84
+ }
85
+ /**
86
+ * A component's answer to the bridge's `run`.
87
+ *
88
+ * @experimental The protocol may change before the bridge reaches 1.0.
89
+ */
90
+ export type AgentRunOutcomeShape = {
91
+ readonly status: 'done';
92
+ readonly result?: AgentValueShape;
93
+ readonly gone?: boolean;
94
+ } | {
95
+ readonly status: 'failed';
96
+ readonly message: string;
97
+ } | {
98
+ readonly status: 'unavailable';
99
+ readonly message?: string;
100
+ } | {
101
+ readonly status: 'stale';
102
+ };
103
+ /**
104
+ * A component's answer to the bridge's `summon`.
105
+ *
106
+ * @experimental The protocol may change before the bridge reaches 1.0.
107
+ */
108
+ export type AgentSummonOutcomeShape = boolean | {
109
+ readonly reached: boolean;
110
+ readonly note: string;
111
+ };
112
+ /**
113
+ * One change a component reports to the bridge's subscribers: what changed on which record and who
114
+ * changed it.
115
+ *
116
+ * @experimental The protocol may change before the bridge reaches 1.0.
117
+ */
118
+ export interface AgentChangeShape {
119
+ readonly ref: string;
120
+ readonly component: string;
121
+ readonly label?: string;
122
+ readonly key: string;
123
+ readonly value: AgentValueShape;
124
+ readonly previous: AgentValueShape;
125
+ readonly reason?: string;
126
+ readonly source: 'user' | 'agent' | 'app' | 'system';
127
+ }
128
+ /**
129
+ * What a component's verbs do, by kind of record: each verb with a line or two for an agent.
130
+ *
131
+ * @experimental The protocol may change before the bridge reaches 1.0.
132
+ */
133
+ export interface AgentVerbsShape {
134
+ readonly [component: string]: {
135
+ readonly [verb: string]: string;
136
+ };
137
+ }
138
+ /**
139
+ * What a component hands to the bridge's `connect`. `check` and `run` come together, `summon` is
140
+ * optional, and a read-only component leaves all three out.
141
+ *
142
+ * @experimental The protocol may change before the bridge reaches 1.0.
143
+ */
144
+ export interface AgentComponentShape<Entry extends AgentEntryShape = AgentEntryShape> {
145
+ readonly protocol: 1;
146
+ readonly name: string;
147
+ snapshot(): readonly Entry[];
148
+ subscribe(listener: (changes?: readonly AgentChangeShape[]) => void): () => void;
149
+ readonly check?: (step: AgentStepCallShape) => AgentStepCheckShape;
150
+ readonly run?: (step: AgentStepCallShape, context: AgentRunContextShape) => AgentRunOutcomeShape | PromiseLike<AgentRunOutcomeShape>;
151
+ readonly summon?: (step: AgentStepCallShape) => AgentSummonOutcomeShape;
152
+ readonly verbs?: AgentVerbsShape;
153
+ }
154
+ /**
155
+ * The Toaster's own record: the Island, the count and the overflow.
156
+ *
157
+ * @experimental The protocol may change before the bridge reaches 1.0.
158
+ */
159
+ export type ToasterEntry = {
160
+ readonly ref: string;
161
+ readonly component: 'toaster';
162
+ /** `open`, `close`, `clear`, `acknowledge`, by state. */
163
+ readonly actions: readonly string[];
164
+ readonly island: {
165
+ readonly open: boolean;
166
+ /** `ref` of the notification the open Island shows; null while closed. */
167
+ readonly current: string | null;
168
+ };
169
+ readonly count: number;
170
+ readonly overflow: {
171
+ readonly count: number;
172
+ readonly pending: boolean;
173
+ };
174
+ /** A mounted `Toaster` renders this controller. */
175
+ readonly mounted: boolean;
176
+ };
177
+ /**
178
+ * A form field as a reader sees it. Its value, default and placeholder stay inside Cloudlet.
179
+ *
180
+ * @experimental The protocol may change before the bridge reaches 1.0.
181
+ */
182
+ export type FormFieldEntry = {
183
+ readonly name: string;
184
+ readonly label: string;
185
+ readonly kind: FormFieldKind;
186
+ readonly required: boolean;
187
+ /** null when the field sets no limit. */
188
+ readonly maxLength: number | null;
189
+ /** null when the field sets no input mode. */
190
+ readonly inputMode: FormInputMode | null;
191
+ /** The field holds non-blank text. */
192
+ readonly filled: boolean;
193
+ /**
194
+ * Who wrote the value last: `app` (the field's default), `user` (the person) or `agent`; null
195
+ * while nobody has and there is no default. An agent can't `fill` a field the person wrote.
196
+ */
197
+ readonly filledBy: 'app' | 'user' | 'agent' | null;
198
+ /**
199
+ * Why the last submit stopped at this field, if it did: the built-in message for a required or
200
+ * too long field, and a fixed phrase when the form's own `validate` did not accept it, because
201
+ * that text may quote what the person typed.
202
+ */
203
+ readonly error: string | null;
204
+ };
205
+ /**
206
+ * A notification's primary action.
207
+ *
208
+ * @experimental The protocol may change before the bridge reaches 1.0.
209
+ */
210
+ export type ActionEntry = {
211
+ readonly kind: 'command' | 'link' | 'form';
212
+ /** The label the application gave the action. */
213
+ readonly label: string;
214
+ readonly status: 'idle' | 'pending' | 'failed';
215
+ /**
216
+ * Why the last attempt failed; null unless `status` is `failed`. For a form it is always
217
+ * `Action failed`: the app's own text may quote what the person typed.
218
+ */
219
+ readonly message: string | null;
220
+ /**
221
+ * What the app lets an agent do with a command or a form: `allow`, `confirm` (a person approves)
222
+ * or `deny`. `confirm` when the app set nothing; absent for a link.
223
+ */
224
+ readonly agent?: 'allow' | 'confirm' | 'deny';
225
+ /** Only for a link. */
226
+ readonly href?: string;
227
+ /** Only for a form. */
228
+ readonly fields?: readonly FormFieldEntry[];
229
+ /**
230
+ * Set when the last submit stopped on the form as a whole; only for a form. A fixed phrase when
231
+ * the form's own `validate` said so, for the same reason as a field's `error`.
232
+ */
233
+ readonly error?: string | null;
234
+ };
235
+ /**
236
+ * A notification's operation, without its attempt token.
237
+ *
238
+ * @experimental The protocol may change before the bridge reaches 1.0.
239
+ */
240
+ export type OperationEntry = {
241
+ readonly status: OperationStatus;
242
+ readonly attempt: number;
243
+ readonly canCancel: boolean;
244
+ readonly canRetry: boolean;
245
+ readonly cancelRequested: boolean;
246
+ };
247
+ /**
248
+ * One notification, in presentation order.
249
+ *
250
+ * @experimental The protocol may change before the bridge reaches 1.0.
251
+ */
252
+ export type NotificationEntry = {
253
+ readonly ref: string;
254
+ readonly component: 'notification';
255
+ /** `dismiss`, `show` (with a mounted `Toaster`), `press`, `fill`, `submit`, `cancel`, `retry`, by state. */
256
+ readonly actions: readonly string[];
257
+ /** The title. */
258
+ readonly label: string;
259
+ /** The description as text; for rich content, its announcement. */
260
+ readonly text: string | null;
261
+ readonly kind: NotificationKind;
262
+ readonly priority: Priority;
263
+ readonly occurrences: number;
264
+ readonly location: NotificationLocation;
265
+ readonly remainingMs: number | null;
266
+ readonly pauseReasons: readonly PauseReason[];
267
+ readonly progress: {
268
+ readonly kind: 'indeterminate' | 'determinate';
269
+ readonly value: number | null;
270
+ readonly label: string | null;
271
+ } | null;
272
+ readonly draft: boolean;
273
+ readonly operation: OperationEntry | null;
274
+ readonly action: ActionEntry | null;
275
+ };
276
+ /** @experimental The protocol may change before the bridge reaches 1.0. */
277
+ export type ToasterAgentEntry = ToasterEntry | NotificationEntry;
278
+ /**
279
+ * What {@link toasterAgent} returns: pass it to the bridge's `connect`.
280
+ *
281
+ * @experimental The protocol may change before the bridge reaches 1.0.
282
+ */
283
+ export interface ToasterAgent extends AgentComponentShape<ToasterAgentEntry> {
284
+ /** The same frozen array until the controller changes; empty after `dispose`. */
285
+ snapshot(): readonly ToasterAgentEntry[];
286
+ /**
287
+ * Calls `listener` after every change of the controller with what changed and who changed it.
288
+ * On a notification's record: `present` (`true` when it appears, `false` when it closes, with
289
+ * the close reason in `reason`), `content` (the app updated it; both values are null), `action`
290
+ * (`idle`, `pending`, `failed`), `operation` (`pending`, `cancel-requested`, `fulfilled`,
291
+ * `rejected`, `cancelled`) and `field:<name>` (who wrote the form field last: `app`, `user`,
292
+ * `agent` or null; only when the author changes, and never the text). On the Toaster's record:
293
+ * `island` (the `ref` of the notification it shows, or null) and `overflow` (the missed count
294
+ * after it was acknowledged). `label` is the notification's title. The array is empty when the
295
+ * snapshot changed with no author, such as a pause.
296
+ */
297
+ subscribe(listener: (changes?: readonly AgentChangeShape[]) => void): () => void;
298
+ /** Whether a step is available now and the class it needs; no side effects. */
299
+ readonly check: (step: AgentStepCallShape) => AgentStepCheckShape;
300
+ /** Reads the controller again and runs the step, unless it changed since it was approved. */
301
+ readonly run: (step: AgentStepCallShape, context: AgentRunContextShape) => AgentRunOutcomeShape | PromiseLike<AgentRunOutcomeShape>;
302
+ /**
303
+ * Opens the Island on the step's notification for a person, at once or once they stop using the
304
+ * Toaster, without moving focus, and says which in `note`.
305
+ */
306
+ readonly summon: (step: AgentStepCallShape) => AgentSummonOutcomeShape;
307
+ /** What each verb of the `toaster` and `notification` records does, for an agent. */
308
+ readonly verbs: AgentVerbsShape;
309
+ }
310
+ /** @experimental The protocol may change before the bridge reaches 1.0. */
311
+ export interface ToasterAgentOptions {
312
+ /** The component's name and the prefix of its refs; matches `[a-z][a-z0-9-]*`. Default `toaster`. */
313
+ readonly name?: string;
314
+ }
315
+ /**
316
+ * Lets an agent read and drive a controller through the kit's agent bridge:
317
+ * `agent.connect(toasterAgent(controller))`. It touches no DOM, starts no timers, never takes the
318
+ * host from a `Toaster` and never moves focus. Form values never reach the snapshot.
319
+ *
320
+ * Steps: `open`, `close`, `clear` and `acknowledge` on the Toaster record; `show`, `dismiss`,
321
+ * `press`, `fill`, `submit`, `cancel` and `retry` on a notification. `open` and `show` need a
322
+ * mounted `Toaster`. `press` and `submit` follow the action's `agent` marker; every other step is
323
+ * allowed unless the bridge's `allow` says no. `fill` (`args: [name, value]`) writes a form field
324
+ * as the agent, never over what the person typed, and makes a draft as typing does; the snapshot
325
+ * says who wrote each field (`filledBy`), never what. A press or submit that needs a person opens
326
+ * the Island on its notification for them: at once, or after the attention delay once they stop
327
+ * using the Toaster. While they use it (hover, focus, a gesture, a draft in the open Island, the
328
+ * agent's own included), `open` and `show` are refused, and so is `close` over a draft.
329
+ *
330
+ * @throws TypeError for a controller that this copy of `@cloudlet/toast` did not create.
331
+ * @experimental The protocol may change before the bridge reaches 1.0.
332
+ */
333
+ export declare function toasterAgent<Slot, Signal extends CancellationSignal>(controller: Omit<CloudletController<Slot, Signal>, 'track'>, options?: ToasterAgentOptions): ToasterAgent;
334
+ //# sourceMappingURL=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