driverkit 0.0.0-stage → 0.0.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 (160) hide show
  1. package/CONTROLS.md +578 -0
  2. package/REACT.md +477 -0
  3. package/README.md +104 -2
  4. package/dist/agent/backend.d.ts +69 -0
  5. package/dist/agent/backend.d.ts.map +1 -0
  6. package/dist/agent/backend.js +130 -0
  7. package/dist/agent/backend.js.map +1 -0
  8. package/dist/agent/control.d.ts +148 -0
  9. package/dist/agent/control.d.ts.map +1 -0
  10. package/dist/agent/control.js +342 -0
  11. package/dist/agent/control.js.map +1 -0
  12. package/dist/agent/index.d.ts +9 -0
  13. package/dist/agent/index.d.ts.map +1 -0
  14. package/dist/agent/index.js +6 -0
  15. package/dist/agent/index.js.map +1 -0
  16. package/dist/agent/loop.d.ts +136 -0
  17. package/dist/agent/loop.d.ts.map +1 -0
  18. package/dist/agent/loop.js +824 -0
  19. package/dist/agent/loop.js.map +1 -0
  20. package/dist/agent/render.d.ts +173 -0
  21. package/dist/agent/render.d.ts.map +1 -0
  22. package/dist/agent/render.js +425 -0
  23. package/dist/agent/render.js.map +1 -0
  24. package/dist/agent/tools.d.ts +138 -0
  25. package/dist/agent/tools.d.ts.map +1 -0
  26. package/dist/agent/tools.js +622 -0
  27. package/dist/agent/tools.js.map +1 -0
  28. package/dist/agent/types.d.ts +566 -0
  29. package/dist/agent/types.d.ts.map +1 -0
  30. package/dist/agent/types.js +32 -0
  31. package/dist/agent/types.js.map +1 -0
  32. package/dist/browser/budget.d.ts +92 -0
  33. package/dist/browser/budget.d.ts.map +1 -0
  34. package/dist/browser/budget.js +151 -0
  35. package/dist/browser/budget.js.map +1 -0
  36. package/dist/browser/connect.d.ts +368 -0
  37. package/dist/browser/connect.d.ts.map +1 -0
  38. package/dist/browser/connect.js +1038 -0
  39. package/dist/browser/connect.js.map +1 -0
  40. package/dist/browser/elsewhere.d.ts +89 -0
  41. package/dist/browser/elsewhere.d.ts.map +1 -0
  42. package/dist/browser/elsewhere.js +91 -0
  43. package/dist/browser/elsewhere.js.map +1 -0
  44. package/dist/browser/frames.d.ts +85 -0
  45. package/dist/browser/frames.d.ts.map +1 -0
  46. package/dist/browser/frames.js +11 -0
  47. package/dist/browser/frames.js.map +1 -0
  48. package/dist/browser/index.d.ts +8 -0
  49. package/dist/browser/index.d.ts.map +1 -0
  50. package/dist/browser/index.js +9 -0
  51. package/dist/browser/index.js.map +1 -0
  52. package/dist/check/check.d.ts +171 -0
  53. package/dist/check/check.d.ts.map +1 -0
  54. package/dist/check/check.js +666 -0
  55. package/dist/check/check.js.map +1 -0
  56. package/dist/check/index.d.ts +3 -0
  57. package/dist/check/index.d.ts.map +1 -0
  58. package/dist/check/index.js +2 -0
  59. package/dist/check/index.js.map +1 -0
  60. package/dist/check/types.d.ts +149 -0
  61. package/dist/check/types.d.ts.map +1 -0
  62. package/dist/check/types.js +29 -0
  63. package/dist/check/types.js.map +1 -0
  64. package/dist/controls/controls.d.ts +198 -0
  65. package/dist/controls/controls.d.ts.map +1 -0
  66. package/dist/controls/controls.js +742 -0
  67. package/dist/controls/controls.js.map +1 -0
  68. package/dist/controls/dom.d.ts +108 -0
  69. package/dist/controls/dom.d.ts.map +1 -0
  70. package/dist/controls/dom.js +56 -0
  71. package/dist/controls/dom.js.map +1 -0
  72. package/dist/controls/index.d.ts +26 -0
  73. package/dist/controls/index.d.ts.map +1 -0
  74. package/dist/controls/index.js +23 -0
  75. package/dist/controls/index.js.map +1 -0
  76. package/dist/controls/rows.d.ts +66 -0
  77. package/dist/controls/rows.d.ts.map +1 -0
  78. package/dist/controls/rows.js +127 -0
  79. package/dist/controls/rows.js.map +1 -0
  80. package/dist/core/index.d.ts +3 -0
  81. package/dist/core/index.d.ts.map +1 -0
  82. package/dist/core/index.js +15 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/core/registry.d.ts +192 -0
  85. package/dist/core/registry.d.ts.map +1 -0
  86. package/dist/core/registry.js +2799 -0
  87. package/dist/core/registry.js.map +1 -0
  88. package/dist/core/types.d.ts +2468 -0
  89. package/dist/core/types.d.ts.map +1 -0
  90. package/dist/core/types.js +19 -0
  91. package/dist/core/types.js.map +1 -0
  92. package/dist/otel/index.d.ts +122 -0
  93. package/dist/otel/index.d.ts.map +1 -0
  94. package/dist/otel/index.js +157 -0
  95. package/dist/otel/index.js.map +1 -0
  96. package/dist/react/index.d.ts +191 -0
  97. package/dist/react/index.d.ts.map +1 -0
  98. package/dist/react/index.js +547 -0
  99. package/dist/react/index.js.map +1 -0
  100. package/dist/react/runtime.d.ts +95 -0
  101. package/dist/react/runtime.d.ts.map +1 -0
  102. package/dist/react/runtime.js +54 -0
  103. package/dist/react/runtime.js.map +1 -0
  104. package/dist/react/store.d.ts +333 -0
  105. package/dist/react/store.d.ts.map +1 -0
  106. package/dist/react/store.js +695 -0
  107. package/dist/react/store.js.map +1 -0
  108. package/dist/relay/auth.d.ts +244 -0
  109. package/dist/relay/auth.d.ts.map +1 -0
  110. package/dist/relay/auth.js +391 -0
  111. package/dist/relay/auth.js.map +1 -0
  112. package/dist/relay/frames.d.ts +141 -0
  113. package/dist/relay/frames.d.ts.map +1 -0
  114. package/dist/relay/frames.js +20 -0
  115. package/dist/relay/frames.js.map +1 -0
  116. package/dist/relay/index.d.ts +8 -0
  117. package/dist/relay/index.d.ts.map +1 -0
  118. package/dist/relay/index.js +4 -0
  119. package/dist/relay/index.js.map +1 -0
  120. package/dist/relay/relay.d.ts +277 -0
  121. package/dist/relay/relay.d.ts.map +1 -0
  122. package/dist/relay/relay.js +1026 -0
  123. package/dist/relay/relay.js.map +1 -0
  124. package/dist/relay/serve.d.ts +33 -0
  125. package/dist/relay/serve.d.ts.map +1 -0
  126. package/dist/relay/serve.js +86 -0
  127. package/dist/relay/serve.js.map +1 -0
  128. package/dist/widget/chat.d.ts +290 -0
  129. package/dist/widget/chat.d.ts.map +1 -0
  130. package/dist/widget/chat.js +486 -0
  131. package/dist/widget/chat.js.map +1 -0
  132. package/dist/widget/css.d.ts +49 -0
  133. package/dist/widget/css.d.ts.map +1 -0
  134. package/dist/widget/css.js +532 -0
  135. package/dist/widget/css.js.map +1 -0
  136. package/dist/widget/dom.d.ts +143 -0
  137. package/dist/widget/dom.d.ts.map +1 -0
  138. package/dist/widget/dom.js +27 -0
  139. package/dist/widget/dom.js.map +1 -0
  140. package/dist/widget/highlight.d.ts +64 -0
  141. package/dist/widget/highlight.d.ts.map +1 -0
  142. package/dist/widget/highlight.js +136 -0
  143. package/dist/widget/highlight.js.map +1 -0
  144. package/dist/widget/index.d.ts +9 -0
  145. package/dist/widget/index.d.ts.map +1 -0
  146. package/dist/widget/index.js +20 -0
  147. package/dist/widget/index.js.map +1 -0
  148. package/dist/widget/position.d.ts +166 -0
  149. package/dist/widget/position.d.ts.map +1 -0
  150. package/dist/widget/position.js +497 -0
  151. package/dist/widget/position.js.map +1 -0
  152. package/dist/widget/settings.d.ts +116 -0
  153. package/dist/widget/settings.d.ts.map +1 -0
  154. package/dist/widget/settings.js +117 -0
  155. package/dist/widget/settings.js.map +1 -0
  156. package/dist/widget/widget.d.ts +442 -0
  157. package/dist/widget/widget.d.ts.map +1 -0
  158. package/dist/widget/widget.js +2005 -0
  159. package/dist/widget/widget.js.map +1 -0
  160. package/package.json +144 -4
@@ -0,0 +1,442 @@
1
+ /**
2
+ * driverkit/widget — the corner panel.
3
+ *
4
+ * Plain DOM. No React, no framework, no dependencies, because the whole point
5
+ * is that it drops into an app somebody else built with tools nobody here
6
+ * chose. A React widget is unusable in a Vue app and a Vue widget is unusable
7
+ * in a Rails app, and either way the host now owns a version of a framework it
8
+ * did not pick.
9
+ *
10
+ * It is also the file people will read to decide whether to trust the library,
11
+ * so it is kept short and literal: one function, one tree of elements built by
12
+ * hand, and every decision that is not obvious written down beside it.
13
+ *
14
+ * **What it adds over `drive` alone is visibility.** The loop is headless and
15
+ * correct and would happily move a person's screen without saying a word. A
16
+ * person watching their own app change under them needs to see what changed
17
+ * it; silent mutation is alarming even when it is right, and it is the
18
+ * difference between "the agent accepted two hundred rows" and "something
19
+ * accepted two hundred rows". So every verb that runs appears in the
20
+ * transcript, labelled with what it did to the world and what it answered.
21
+ *
22
+ * **And what it adds over visibility is time.** Seeing a verb after it ran is
23
+ * not the same as being able to stop it. So the panel renders the run as a
24
+ * step list — one row per call, appearing while the call is still pending —
25
+ * paces the run slowly enough to follow, and puts Pause, Step and Stop beside
26
+ * it. The pace, the step-every-call mode, the outlining of the element a call
27
+ * is about, and the commit confirmation are all the person's to change in a
28
+ * settings view under the ⚙, remembered per viewer. Everything about that
29
+ * surface is one judgement: the person watching their own screen move is the
30
+ * one who should be deciding how fast it moves.
31
+ *
32
+ * **What it does not do is hold a key.** `think` is the host app's function,
33
+ * exactly as in `driverkit/agent`; see that area's `types.ts` for why, and
34
+ * `backendThink` for the thirty lines that make the realistic deployment work.
35
+ */
36
+ import type { Approval, ApprovalRequest, AskAnswer, AskQuestion, Driver } from "../core/index.ts";
37
+ import type { Clock, DriveOptions, RunControls, RunControlsOptions } from "../agent/index.ts";
38
+ import type { AbortControllerCtor, DocumentLike, ElementLike, StorageLike, WindowLike } from "./dom.ts";
39
+ import type { Fraction, Position } from "./position.ts";
40
+ /**
41
+ * How the panel gets a control surface, which is `runControls` by default.
42
+ *
43
+ * An option because `RunControls` is an interface and not only a factory: the
44
+ * agent package says in as many words that a host with its own control surface
45
+ * — a queue, a remote operator, a test — may implement it and `drive` will
46
+ * drive it. The panel's buttons then drive that instead, and nothing here
47
+ * needs to know the difference.
48
+ */
49
+ export type RunControlsFactory = (options: RunControlsOptions) => RunControls;
50
+ /**
51
+ * The selection size at which a commit is confirmed even though the app said
52
+ * it could be undone. A commit acting on MORE than this many rows is asked
53
+ * about; `commitAskAbove` overrides it.
54
+ *
55
+ * **This number is a judgement and not a fact**, so here is the judgement. Two
56
+ * lines could have been drawn and they are drawn in different places:
57
+ *
58
+ * - Where can a person still check the claim themselves? A screenful. This
59
+ * library's premise is that an agent sees exactly what the person sees, and
60
+ * its own demo puts twenty rows on a screen; past a screenful the person
61
+ * cannot look at what is about to change, so "the app can undo it" is a
62
+ * promise they have no way to weigh.
63
+ * - Where does an app's undo stop being credible? Much higher — somewhere in
64
+ * the thousands, where a batch half-applies, a buffer sized for one row
65
+ * runs out, or a server gives up at row 1,800.
66
+ *
67
+ * The lower line is taken, and 25 rather than 20 because the first is the point
68
+ * where the gate stops being able to help and the second is a page size that
69
+ * differs per app: a selection a few rows past one screenful is an ordinary
70
+ * thing a person was probably looking at, and tripping the dialog on it would
71
+ * put us back to asking about the trivial. Anything that cannot be seen at once
72
+ * is asked about, which is the side of the line to err on — the cost of a
73
+ * needless question here is one click, and the cost of a missed one is an
74
+ * "undo" that turns out to be partial.
75
+ *
76
+ * It is one number for every app and therefore wrong for some of them, which is
77
+ * exactly why it is an option.
78
+ */
79
+ export declare const COMMIT_ASK_ABOVE = 25;
80
+ /**
81
+ * The word in the panel header when the host has not supplied one.
82
+ *
83
+ * It used to be the app's own name, and the app's own name is the one thing
84
+ * that must not size this strip. "Northwind CRM" is a header full before the
85
+ * three controls beside it get a place; "Mail" leaves it two thirds empty; and
86
+ * neither of them tells the person anything they do not already know, because
87
+ * the app they are looking at is the whole screen behind the panel. A chat
88
+ * panel's title is only there to say what the panel IS.
89
+ *
90
+ * "Assistant" and not "Ask", which is the launcher's word, because the two are
91
+ * different parts of speech doing different jobs: a button says what pressing
92
+ * it does, and a title names the thing it is on top of. "Ask" as a header
93
+ * would read as an instruction with nothing to instruct. It is also already
94
+ * the word in the panel's `aria-label` — `"<app> assistant"` — so the visible
95
+ * title and the announced one now agree instead of being two different names
96
+ * for one surface.
97
+ *
98
+ * The app's name is NOT gone: it is in that `aria-label`, in the launcher's
99
+ * and the input's accessible names, in the input's placeholder, in the
100
+ * greeting, and on the title's own `title` tooltip. Those are the places where
101
+ * naming the app answers a question somebody actually has — "what is this
102
+ * thing reading my screen" — and none of them is a box whose width the name
103
+ * gets to decide.
104
+ */
105
+ export declare const PANEL_TITLE = "Assistant";
106
+ export interface WidgetOptions extends Pick<DriveOptions, "think" | "instructions" | "maxSteps" | "refusalLimit"> {
107
+ /**
108
+ * Your own confirmation, replacing the built-in one.
109
+ *
110
+ * It overrides rather than stacks: a host that supplies this has said how it
111
+ * wants to ask, and showing its dialog and then the panel's own row would be
112
+ * two questions about one commit, which is how people learn to click yes
113
+ * without reading. Supplying this also means `confirmCommits` is moot — your
114
+ * function is called for every commit either way.
115
+ *
116
+ * This gates THE IN-PAGE RUN ONLY, which is the thing to know about it: it is
117
+ * `drive`'s option, so a commit arriving over the relay or MCP never reaches
118
+ * it, and its answer is not in the audit record — the core was never asked,
119
+ * so `onAudit` reports `approval: "not-asked"`. The gate that covers every
120
+ * path, and the one that lands in the record, is `MountOptions.approve`, and
121
+ * `Widget.approve` is this panel's dialog in that shape.
122
+ *
123
+ * Passing this also stops the panel installing its own dialog as the core's
124
+ * approver, which it otherwise does: you have said how you want to ask, and
125
+ * two gates for one commit is two dialogs. One exception, and it is yours to
126
+ * pick deliberately or not at all — when the APP declared `approve` as well,
127
+ * that hook is asked inside `call()` whatever this option says, so an
128
+ * in-page commit is asked about twice: once by you here and once by it.
129
+ */
130
+ onBeforeCommit?: DriveOptions["onBeforeCommit"];
131
+ /** Shown in the header and on the launcher. Defaults to `PANEL_TITLE` in the
132
+ * header and "Ask" on the launcher — see `PANEL_TITLE` for why the app's own
133
+ * name is not either of them. The app name is still in every accessible
134
+ * name, in the placeholder and in the greeting. */
135
+ title?: string;
136
+ /** The first line in the transcript. Defaults to a line naming the app. */
137
+ greeting?: string;
138
+ placeholder?: string;
139
+ /** Start open. Default closed: a panel that opens itself is a panel over
140
+ * something the person was reading. */
141
+ open?: boolean;
142
+ /** Where to put the host element. Default `document.body`. */
143
+ container?: ElementLike;
144
+ /** Injected browser, defaulting to the real one. See `dom.ts` — this is a
145
+ * design requirement, not a testing shim. */
146
+ document?: DocumentLike;
147
+ /** The viewport, for the clamp and for `prefers-reduced-motion`. Default
148
+ * `globalThis`. */
149
+ window?: WindowLike;
150
+ /** Where a remembered position and the settings are kept. Default
151
+ * `localStorage`, if reaching for it does not throw. */
152
+ storage?: StorageLike;
153
+ /**
154
+ * Where a remembered CONVERSATION is kept. Default `sessionStorage`.
155
+ *
156
+ * A second storage and not `storage`, because the two want different
157
+ * lifetimes and the difference is the design rather than an accident. A pace
158
+ * and a pane position are per viewer and belong in `localStorage`, where they
159
+ * outlive the tab. A transcript is per TAB — two tabs of one app are two
160
+ * conversations and must not stomp each other — and holds the person's
161
+ * instructions and the model's prose about their records, which is a
162
+ * different privacy class on a machine that may be shared. `sessionStorage`
163
+ * survives a reload and dies with the tab, which is exactly the lifetime a
164
+ * conversation should have. See `chat.ts`.
165
+ */
166
+ session?: StorageLike;
167
+ /**
168
+ * Bring the conversation back after a page reload. **Default off.**
169
+ *
170
+ * Off by default on purpose: a library must not start writing its users'
171
+ * business prose to disk because somebody upgraded. Once an app has opted in,
172
+ * the VIEWER's switch in the settings view defaults on, and turning it off
173
+ * forgets what is already stored. This option is the harder of the two — an
174
+ * app handling records that must not be written down sets `false` and no
175
+ * viewer can undo it.
176
+ *
177
+ * What comes back is the conversation, not the run: see `chat.ts` on "restore
178
+ * everything, resume nothing". A reload mid-commit comes back with the panel
179
+ * saying which verb was in flight and that it cannot tell whether it landed.
180
+ */
181
+ rememberChat?: boolean;
182
+ /**
183
+ * Whether a call's elapsed time reaches the model. See `DriveOptions.timing`.
184
+ *
185
+ * **Defaults to `"slow"` here, where `drive` defaults to `"off"`**, and the
186
+ * split is the same judgement `onBeforeCommit` gets one level up: `drive` is
187
+ * a primitive whose existing callers must get byte-identical transcripts, and
188
+ * this is a panel somebody is watching work on a live app, where "that verb
189
+ * took twenty seconds" is a fact about the app worth a line. Nothing is
190
+ * rendered below a second, so a snappy app pays nothing for it.
191
+ *
192
+ * Pass `"always"` for the run that was asked to compare two fast verbs, and
193
+ * `"off"` to go back to a transcript with no durations in it at all.
194
+ */
195
+ timing?: DriveOptions["timing"];
196
+ AbortController?: AbortControllerCtor;
197
+ /**
198
+ * Where the panel starts: one of the four corners, or `{ x, y }` pixels from
199
+ * the top-left of the viewport.
200
+ *
201
+ * Leave it out and the stylesheet decides — `--dk-x` and `--dk-y` on
202
+ * `:host`, bottom-right by default — which is the only way a host app can
203
+ * place the panel from its own CSS without JavaScript. Passing anything here
204
+ * writes those properties inline and takes that away, so it is worth not
205
+ * passing it unless you mean it.
206
+ *
207
+ * A remembered position beats this one, because this is the author's idea of
208
+ * where the panel goes and that is where this particular person put it.
209
+ * `{ x, y }` is converted to a fraction of the free space against the
210
+ * viewport it was measured in; see `position.ts` for why nothing is kept in
211
+ * pixels.
212
+ */
213
+ position?: Position;
214
+ /** Default true. False nails the panel to wherever the option and the
215
+ * stylesheet put it — for an app that has its own idea about chrome. */
216
+ draggable?: boolean;
217
+ /** How close to a corner a drop has to be to land in it, in pixels. Default
218
+ * 72. 0 switches snapping off. */
219
+ snapThreshold?: number;
220
+ /** Remember the position and the settings in `localStorage`, per app and per
221
+ * viewer. Default true. Every read and write is wrapped: storage throws in a private window
222
+ * and with site data blocked, and a chat panel that fails to render because
223
+ * it could not remember where it was is a much worse bug than one that
224
+ * opens in the default corner. */
225
+ persist?: boolean;
226
+ /** Must match `--dk-gap`, the inset the CSS arithmetic uses. Only worth
227
+ * passing if the host app overrode that property. */
228
+ gap?: number;
229
+ /**
230
+ * Ask the person before a `commit` verb the app cannot undo. **Default
231
+ * true.**
232
+ *
233
+ * This is the one place where the widget's default differs from `drive`'s,
234
+ * and the difference is deliberate. `drive` is a library primitive and a
235
+ * headless caller may have its own policy, so it gates nothing unless asked.
236
+ * The widget is a chatbot in the corner of somebody's screen, and a person
237
+ * watching a chatbot move their own app should not find out about a thousand
238
+ * accepted rows afterwards.
239
+ *
240
+ * The cost of the gate is one question, not one per row: a `commit` verb
241
+ * takes no predicate and acts on the whole current selection, so accepting a
242
+ * thousand contacts is one call and therefore one prompt. That makes this
243
+ * the cheapest possible place to put a human in front of the expensive
244
+ * failure.
245
+ *
246
+ * **A commit that declares `Verb.reversible` runs without a question**,
247
+ * which is what that flag was added to buy. `set-setting("dense-rows",
248
+ * "true")` and accepting 3,412 contacts were both getting the same dialog,
249
+ * and a modal on a page-size change is how people learn to click Yes without
250
+ * reading — the next one they skip is the bulk accept. An absent
251
+ * `reversible` still makes no claim in either direction and is still gated:
252
+ * a commit that has not said there is a way back is treated as one that has
253
+ * not got one. See `commitAskAbove` for the selection size that overrides
254
+ * the flag, and `confirmEveryCommit` for an app that wants the old
255
+ * behaviour.
256
+ *
257
+ * Set it false to opt out entirely — for an app whose commits are all small,
258
+ * where a question even on the irreversible ones is noise that teaches
259
+ * people to click through questions.
260
+ *
261
+ * This, `commitAskAbove` and `confirmEveryCommit` decide whether the dialog
262
+ * appears whichever path asked for it, because there is one dialog: see
263
+ * `Widget.approve`. Switching confirmations off therefore switches them off
264
+ * for an agent over the relay too, which is the honest reading of a switch
265
+ * labelled "ask before changing data" and is also a thing to think about
266
+ * before offering the switch at all.
267
+ */
268
+ confirmCommits?: boolean;
269
+ /**
270
+ * The selection size past which a commit is confirmed **even when it
271
+ * declared itself reversible**. Default `COMMIT_ASK_ABOVE`.
272
+ *
273
+ * "Undo" over three thousand rows is a promise an app may not be able to
274
+ * keep at that size, whatever it declared — an undo buffer sized for one
275
+ * row, a half-applied batch, a server that gave up at row 1,800.
276
+ * `reversible` is a claim about the KIND of change and not about its volume,
277
+ * so the volume is checked separately and the flag does not get to answer
278
+ * for it.
279
+ *
280
+ * The size is the count the run's last `describe` verb reported, or
281
+ * `Snapshot.selectedCount`, or `Snapshot.selected.length` when the whole
282
+ * selection is on screen. A commit with no count at all is never "large" by
283
+ * this test; an irreversible one is gated anyway by the absence of a claim,
284
+ * which is the stronger of the two reasons.
285
+ */
286
+ commitAskAbove?: number;
287
+ /**
288
+ * Ask before **every** `commit`, reversible or not. Default false.
289
+ *
290
+ * The behaviour the widget had before it read `Verb.reversible`, kept as an
291
+ * option rather than as the default. An app that genuinely wants it exists:
292
+ * one whose "undo" is a toast that vanishes in five seconds, or one under a
293
+ * rule that a person signs for every write. Those are decisions about the
294
+ * app and the app gets to make them; what they are not is the right default
295
+ * for everybody, because a dialog on a page-size change teaches people to
296
+ * click through dialogs.
297
+ *
298
+ * Moot when `confirmCommits` is false — nothing is asked either way — and
299
+ * moot when the host supplies `onBeforeCommit`, which replaces the built-in
300
+ * row outright.
301
+ */
302
+ confirmEveryCommit?: boolean;
303
+ /**
304
+ * Where Pause, Resume and Step are sent. Default `runControls`.
305
+ *
306
+ * Built once per run, because "paused" is a statement about a run: a surface
307
+ * that remembered a pause from the last one would silently hold the next.
308
+ * Stop is not on it — stopping is the abort signal, which it always was.
309
+ */
310
+ controls?: RunControlsFactory;
311
+ /** The timer the pace waits on. Default `setTimeout`, via the agent
312
+ * package's `realClock`. Injectable for the same reason every other global
313
+ * here is: a suite that actually slept its paces would be a slow suite, and
314
+ * a slow suite is a suite nobody runs. */
315
+ clock?: Clock;
316
+ /**
317
+ * The starting delay between steps, in milliseconds. Default
318
+ * `WATCHABLE_PACE`.
319
+ *
320
+ * It is a starting value and not a setting: this is the person's to change,
321
+ * in the settings view, and once they have changed it their choice is
322
+ * remembered and outranks this. See `SPEEDS` in `settings.ts` for why the
323
+ * offered range is 250ms to 3s.
324
+ *
325
+ * Note which way the default falls. `drive` paces nothing by default,
326
+ * because it is also driven by backend jobs with nobody watching; the widget
327
+ * paces by default, because a panel in a page has a person in front of it
328
+ * and the whole reason it exists is that they should be able to see what is
329
+ * being done to their screen in time to stop it.
330
+ */
331
+ pace?: number;
332
+ /** A failed `think` lands here as well as in the transcript. Default:
333
+ * ignore it. */
334
+ onError?: (err: unknown) => void;
335
+ }
336
+ export interface Widget {
337
+ unmount: () => void;
338
+ open: () => void;
339
+ close: () => void;
340
+ /** Ask something as if it had been typed. Returns when the run ends. */
341
+ ask: (text: string) => Promise<void>;
342
+ /**
343
+ * The panel's confirmation dialog, as a `MountOptions.approve` hook.
344
+ *
345
+ * This is how the one working confirmation UI in the repository comes to
346
+ * cover the relay path as well as the in-page one.
347
+ *
348
+ * YOU DO NOT HAVE TO WIRE THIS UP for the record to be true: a panel on a
349
+ * driver that declared no `approve` installs this function as the core's
350
+ * approver itself (`DriverApproval.adopt`), so a commit on any path renders
351
+ * this dialog and `onAudit` says what the person clicked. Wire it up when the
352
+ * app ALSO publishes the driver to a relay — `connect()` requires a
353
+ * declaration in the app's own source, and a panel's gate is not one, because
354
+ * it is gone when the panel is. Use a forward reference, because `mount()`
355
+ * has to happen before the panel that will answer for it exists:
356
+ *
357
+ * ```ts
358
+ * let panel: Widget;
359
+ * const driver = mount({ …, approve: (req) => panel.approve(req) });
360
+ * panel = mountWidget(driver, { think });
361
+ * ```
362
+ *
363
+ * Then a commit arriving over the relay or MCP renders the same question,
364
+ * with the same count, obeying the same `confirmCommits`, `commitAskAbove`
365
+ * and `confirmEveryCommit`, and a "No" becomes the same `declined-by-user`
366
+ * refusal that the in-page loop produces. The core holds its lock for the
367
+ * duration, so the agent that is being asked cannot call anything else —
368
+ * including `press` on an approve button — while the question is open.
369
+ *
370
+ * The count comes from the run's last `describe` when there is a run in
371
+ * flight, and from the screen otherwise (`Snapshot.selectedCount`, then the
372
+ * visible `selected`). An app whose selection size is only knowable from a
373
+ * verb's `Report.count`, asked about a commit that arrived between runs, will
374
+ * show "No count was reported" here — which is the honest answer and is
375
+ * itself a reason to say no.
376
+ */
377
+ approve: (req: ApprovalRequest) => Promise<Approval>;
378
+ /**
379
+ * The panel's question box, as a `MountOptions.ask` hook.
380
+ *
381
+ * The other half of `approve`, and deliberately not symmetrical with it in
382
+ * one way: **you do have to wire this one up.** A panel cannot adopt an ask
383
+ * hook the way it adopts the approval gate, and the reason is the constraint
384
+ * the whole library is priced on — `system` and `tools` are byte-identical on
385
+ * every turn so the prompt prefix stays cached, so the `ask` verb has to be
386
+ * in the manifest from `mount()` or not at all. A verb that appeared when a
387
+ * panel mounted would be a tool list changing underneath a running
388
+ * conversation. So:
389
+ *
390
+ * ```ts
391
+ * let panel: Widget;
392
+ * const driver = mount({ …, ask: (q) => panel.question(q) });
393
+ * panel = mountWidget(driver, { think });
394
+ * ```
395
+ *
396
+ * The same forward reference `approve` documents, for the same reason:
397
+ * `mount()` has to happen before the panel that will answer for it exists.
398
+ *
399
+ * Then an agent that cannot act without guessing asks, and the person types
400
+ * an answer into the transcript. It works on both paths for nothing extra:
401
+ * an agent arriving over the relay or MCP asks through the same hook and the
402
+ * question appears in the same panel, with the core holding its lock for the
403
+ * duration so that agent can call nothing else while the question is open.
404
+ *
405
+ * **NAMED `question` AND NOT `ask` BECAUSE `Widget.ask` IS TAKEN**, and by
406
+ * the opposite direction of the same conversation: `ask(text)` types a
407
+ * sentence into the panel as if the person had, which is the person asking
408
+ * the agent. This is the agent asking the person. Two methods called `ask`
409
+ * meaning opposite directions would be the worst possible naming in this
410
+ * file.
411
+ *
412
+ * It answers `{ answered: false }` when the panel is unmounted or the run is
413
+ * stopped with a question still on screen, and never a string: nobody spoke,
414
+ * and a panel that invented an answer would be putting words in a person's
415
+ * mouth. It never answers `{ nobody: true }` — a mounted panel is a place a
416
+ * question can be seen, so "there is nobody here" is not this panel's claim
417
+ * to make. An app that knows better (a cron run, a tab with no panel) says
418
+ * so from its own hook.
419
+ */
420
+ question: (q: AskQuestion) => Promise<AskAnswer>;
421
+ /** Move the panel, as `WidgetOptions.position`. Persisted like a drag. */
422
+ moveTo: (position: Position) => void;
423
+ /** Where the panel is, as fractions of the free space in `[0, 1]`, or null
424
+ * while nobody has moved it and the stylesheet is still in charge. */
425
+ position: () => Fraction | null;
426
+ }
427
+ /**
428
+ * Put a chat panel in the corner of the app and let it drive the app.
429
+ *
430
+ * ```ts
431
+ * const panel = mountWidget(driver, { think: backendThink("/api/chat") });
432
+ * // later
433
+ * panel.unmount();
434
+ * ```
435
+ *
436
+ * A `commit` verb the app cannot undo is confirmed with the person by default,
437
+ * in the panel, with the count the preceding `describe` reported. One that
438
+ * declares `Verb.reversible` runs without a question unless it acts on a large
439
+ * selection. See `confirmCommits`, `commitAskAbove` and `confirmEveryCommit`.
440
+ */
441
+ export declare function mountWidget(driver: Driver, options: WidgetOptions): Widget;
442
+ //# sourceMappingURL=widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/widget/widget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,SAAS,EACT,WAAW,EACX,MAAM,EAEP,MAAM,kBAAkB,CAAC;AAU1B,OAAO,KAAK,EAEV,KAAK,EAGL,YAAY,EACZ,WAAW,EACX,kBAAkB,EAInB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,WAAW,EAEX,WAAW,EACX,UAAU,EACX,MAAM,UAAU,CAAC;AAelB,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAWxD;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,WAAW,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,cAAc,CAAC;AAGvC,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc,CAAC;IAClF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,cAAc,CAAC,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAChD;;;wDAGoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;I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