driverkit 0.0.0-stage → 0.1.0
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.
- package/CONTROLS.md +578 -0
- package/README.md +104 -2
- package/dist/agent/backend.d.ts +69 -0
- package/dist/agent/backend.d.ts.map +1 -0
- package/dist/agent/backend.js +130 -0
- package/dist/agent/backend.js.map +1 -0
- package/dist/agent/control.d.ts +148 -0
- package/dist/agent/control.d.ts.map +1 -0
- package/dist/agent/control.js +342 -0
- package/dist/agent/control.js.map +1 -0
- package/dist/agent/index.d.ts +9 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.d.ts.map +1 -0
- package/dist/agent/loop.js +824 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/render.d.ts +173 -0
- package/dist/agent/render.d.ts.map +1 -0
- package/dist/agent/render.js +425 -0
- package/dist/agent/render.js.map +1 -0
- package/dist/agent/tools.d.ts +138 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +622 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/types.d.ts +566 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +32 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/browser/budget.d.ts +92 -0
- package/dist/browser/budget.d.ts.map +1 -0
- package/dist/browser/budget.js +151 -0
- package/dist/browser/budget.js.map +1 -0
- package/dist/browser/connect.d.ts +368 -0
- package/dist/browser/connect.d.ts.map +1 -0
- package/dist/browser/connect.js +1038 -0
- package/dist/browser/connect.js.map +1 -0
- package/dist/browser/elsewhere.d.ts +89 -0
- package/dist/browser/elsewhere.d.ts.map +1 -0
- package/dist/browser/elsewhere.js +91 -0
- package/dist/browser/elsewhere.js.map +1 -0
- package/dist/browser/frames.d.ts +85 -0
- package/dist/browser/frames.d.ts.map +1 -0
- package/dist/browser/frames.js +11 -0
- package/dist/browser/frames.js.map +1 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +9 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/check/check.d.ts +171 -0
- package/dist/check/check.d.ts.map +1 -0
- package/dist/check/check.js +666 -0
- package/dist/check/check.js.map +1 -0
- package/dist/check/index.d.ts +3 -0
- package/dist/check/index.d.ts.map +1 -0
- package/dist/check/index.js +2 -0
- package/dist/check/index.js.map +1 -0
- package/dist/check/types.d.ts +149 -0
- package/dist/check/types.d.ts.map +1 -0
- package/dist/check/types.js +29 -0
- package/dist/check/types.js.map +1 -0
- package/dist/controls/controls.d.ts +198 -0
- package/dist/controls/controls.d.ts.map +1 -0
- package/dist/controls/controls.js +742 -0
- package/dist/controls/controls.js.map +1 -0
- package/dist/controls/dom.d.ts +108 -0
- package/dist/controls/dom.d.ts.map +1 -0
- package/dist/controls/dom.js +56 -0
- package/dist/controls/dom.js.map +1 -0
- package/dist/controls/index.d.ts +26 -0
- package/dist/controls/index.d.ts.map +1 -0
- package/dist/controls/index.js +23 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/controls/rows.d.ts +66 -0
- package/dist/controls/rows.d.ts.map +1 -0
- package/dist/controls/rows.js +127 -0
- package/dist/controls/rows.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry.d.ts +192 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +2799 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/types.d.ts +2468 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/otel/index.d.ts +122 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +157 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/react/index.d.ts +191 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +547 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/runtime.d.ts +95 -0
- package/dist/react/runtime.d.ts.map +1 -0
- package/dist/react/runtime.js +54 -0
- package/dist/react/runtime.js.map +1 -0
- package/dist/react/store.d.ts +333 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +695 -0
- package/dist/react/store.js.map +1 -0
- package/dist/relay/auth.d.ts +244 -0
- package/dist/relay/auth.d.ts.map +1 -0
- package/dist/relay/auth.js +391 -0
- package/dist/relay/auth.js.map +1 -0
- package/dist/relay/frames.d.ts +141 -0
- package/dist/relay/frames.d.ts.map +1 -0
- package/dist/relay/frames.js +20 -0
- package/dist/relay/frames.js.map +1 -0
- package/dist/relay/index.d.ts +8 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/index.js +4 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/relay.d.ts +277 -0
- package/dist/relay/relay.d.ts.map +1 -0
- package/dist/relay/relay.js +1026 -0
- package/dist/relay/relay.js.map +1 -0
- package/dist/relay/serve.d.ts +33 -0
- package/dist/relay/serve.d.ts.map +1 -0
- package/dist/relay/serve.js +86 -0
- package/dist/relay/serve.js.map +1 -0
- package/dist/widget/chat.d.ts +290 -0
- package/dist/widget/chat.d.ts.map +1 -0
- package/dist/widget/chat.js +486 -0
- package/dist/widget/chat.js.map +1 -0
- package/dist/widget/css.d.ts +49 -0
- package/dist/widget/css.d.ts.map +1 -0
- package/dist/widget/css.js +532 -0
- package/dist/widget/css.js.map +1 -0
- package/dist/widget/dom.d.ts +143 -0
- package/dist/widget/dom.d.ts.map +1 -0
- package/dist/widget/dom.js +27 -0
- package/dist/widget/dom.js.map +1 -0
- package/dist/widget/highlight.d.ts +64 -0
- package/dist/widget/highlight.d.ts.map +1 -0
- package/dist/widget/highlight.js +136 -0
- package/dist/widget/highlight.js.map +1 -0
- package/dist/widget/index.d.ts +9 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +20 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/position.d.ts +166 -0
- package/dist/widget/position.d.ts.map +1 -0
- package/dist/widget/position.js +497 -0
- package/dist/widget/position.js.map +1 -0
- package/dist/widget/settings.d.ts +116 -0
- package/dist/widget/settings.d.ts.map +1 -0
- package/dist/widget/settings.js +117 -0
- package/dist/widget/settings.js.map +1 -0
- package/dist/widget/widget.d.ts +442 -0
- package/dist/widget/widget.d.ts.map +1 -0
- package/dist/widget/widget.js +2005 -0
- package/dist/widget/widget.js.map +1 -0
- package/package.json +153 -4
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* driverkit/browser — the page side.
|
|
3
|
+
*
|
|
4
|
+
* One function. It holds an `EventSource` open, answers `call` frames by
|
|
5
|
+
* handing them to the driver `mount()` returned, and POSTs the `Result` back.
|
|
6
|
+
* It makes no decisions: it does not validate args, does not check `rev`, does
|
|
7
|
+
* not refuse. The driver owns all of that, and PROTOCOL.md's reason is the one
|
|
8
|
+
* that matters -- a second place that validates is a second set of rules, and
|
|
9
|
+
* the in-page chatbot calling `driver.call()` directly would get the other one.
|
|
10
|
+
*
|
|
11
|
+
* No dependencies and no framework. `EventSource` and `fetch` are built in,
|
|
12
|
+
* which is half of why the protocol is SSE in the first place.
|
|
13
|
+
*/
|
|
14
|
+
import type { Driver, TabFocus } from "./frames.ts";
|
|
15
|
+
/**
|
|
16
|
+
* The browser pieces, as structural types.
|
|
17
|
+
*
|
|
18
|
+
* Narrow on purpose: these describe only what `connect` actually touches, so
|
|
19
|
+
* the real `EventSource` satisfies them and so does a thirty-line fake. That
|
|
20
|
+
* is the point -- see `ConnectOptions.EventSource`.
|
|
21
|
+
*/
|
|
22
|
+
export interface EventSourceLike {
|
|
23
|
+
readonly readyState: number;
|
|
24
|
+
addEventListener(type: string, listener: (event: {
|
|
25
|
+
data?: string;
|
|
26
|
+
}) => void): void;
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
export interface EventSourceCtor {
|
|
30
|
+
new (url: string): EventSourceLike;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The part of a `Response` the page side reads: the status, and nothing else.
|
|
34
|
+
*
|
|
35
|
+
* Narrow for the same reason `EventSourceLike` is -- the real `Response`
|
|
36
|
+
* satisfies it, and so does `{ status: 409 }` in a test. The body is never
|
|
37
|
+
* read: PROTOCOL.md pins `POST /dk/result` to `202 {"ok":true}` on acceptance
|
|
38
|
+
* and says a payload there "would be an invitation to build a second,
|
|
39
|
+
* divergent return path". The answer to a call travels to the agent, not back
|
|
40
|
+
* up this POST.
|
|
41
|
+
*/
|
|
42
|
+
export interface ResponseLike {
|
|
43
|
+
/**
|
|
44
|
+
* Optional only so an injected stub that returns nothing still typechecks.
|
|
45
|
+
* An absent status is read as acceptance: there is nothing to read it as
|
|
46
|
+
* instead, and the real `fetch` always carries one.
|
|
47
|
+
*/
|
|
48
|
+
readonly status?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface FetchLike {
|
|
51
|
+
(url: string, init: {
|
|
52
|
+
method: string;
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
body: string;
|
|
55
|
+
}): Promise<ResponseLike>;
|
|
56
|
+
}
|
|
57
|
+
export interface StorageLike {
|
|
58
|
+
getItem(key: string): string | null;
|
|
59
|
+
setItem(key: string, value: string): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The part of `document` this file reads: the title, and where the attention is.
|
|
63
|
+
*
|
|
64
|
+
* Injectable for the reason `EventSourceLike` is injectable, and this one is
|
|
65
|
+
* the more important of the two: focus reporting is a thing that happens when
|
|
66
|
+
* a person alt-tabs, and "alt-tab and see whether the right frame went out" is
|
|
67
|
+
* not a test anybody runs twice. Every method is optional so that a partial
|
|
68
|
+
* stub -- `{ visibilityState: "visible" }` -- is a usable one, and so that a
|
|
69
|
+
* real `document` from an older engine with no `hasFocus` still satisfies it.
|
|
70
|
+
*
|
|
71
|
+
* Note that `titleFromPage` and `urlFromPage` used to read `globalThis`
|
|
72
|
+
* directly and were therefore the two things in here that could not be
|
|
73
|
+
* exercised in process. They take these now.
|
|
74
|
+
*/
|
|
75
|
+
export interface PageLike {
|
|
76
|
+
readonly title?: string;
|
|
77
|
+
readonly visibilityState?: string;
|
|
78
|
+
hasFocus?: () => boolean;
|
|
79
|
+
addEventListener?(type: string, listener: () => void): void;
|
|
80
|
+
removeEventListener?(type: string, listener: () => void): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Where `focus` and `blur` are listened for: the window, or anything shaped
|
|
84
|
+
* like it.
|
|
85
|
+
*
|
|
86
|
+
* SEPARATE FROM `PageLike` because the two events are not on the same object.
|
|
87
|
+
* `visibilitychange` fires on `document`; `focus` and `blur` do not bubble and
|
|
88
|
+
* are delivered to the window. Listening for all three on `document` is the
|
|
89
|
+
* mistake that makes a focus change in a visible tab -- the person clicking
|
|
90
|
+
* from another application into this window, which is the whole case this
|
|
91
|
+
* exists for -- go unnoticed.
|
|
92
|
+
*/
|
|
93
|
+
export interface FocusEventsLike {
|
|
94
|
+
addEventListener(type: string, listener: () => void): void;
|
|
95
|
+
removeEventListener?(type: string, listener: () => void): void;
|
|
96
|
+
}
|
|
97
|
+
/** The part of `location` the url is built from. `hash` is in here on purpose;
|
|
98
|
+
* see `urlFromPage`. */
|
|
99
|
+
export interface LocationLike {
|
|
100
|
+
readonly pathname?: string;
|
|
101
|
+
readonly search?: string;
|
|
102
|
+
readonly hash?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface ConnectOptions {
|
|
105
|
+
/** Where the relay lives: an origin, or "" for same-origin. No trailing slash. */
|
|
106
|
+
relay: string;
|
|
107
|
+
/**
|
|
108
|
+
* This tab's id. Omit and one is minted and remembered.
|
|
109
|
+
*
|
|
110
|
+
* PROTOCOL.md: minted by the tab, not the relay, so a reconnect resumes the
|
|
111
|
+
* same identity. An agent mid-task holds this id; if a dropped stream came
|
|
112
|
+
* back under a new one, every call it had queued up would answer
|
|
113
|
+
* `no-such-tab` and the agent would conclude the window had closed.
|
|
114
|
+
*/
|
|
115
|
+
tab?: string;
|
|
116
|
+
app?: string;
|
|
117
|
+
/** Only so a human can tell two tabs apart when asked "which one?". */
|
|
118
|
+
title?: string;
|
|
119
|
+
url?: string;
|
|
120
|
+
/**
|
|
121
|
+
* How long to coalesce `changed()` calls. PROTOCOL.md: "sent on a debounce,
|
|
122
|
+
* not on every keystroke". A snapshot push is a courtesy to an agent that is
|
|
123
|
+
* mid-task -- it says "the human moved, re-read" -- and one per keystroke
|
|
124
|
+
* would cost more than the information is worth.
|
|
125
|
+
*/
|
|
126
|
+
debounceMs?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Poll `driver.snapshot().rev` this often and push when it moves.
|
|
129
|
+
*
|
|
130
|
+
* Off unless asked for: an app that calls `changed()` where it changes needs
|
|
131
|
+
* no polling, and that is the better shape. This is the escape hatch for a
|
|
132
|
+
* codebase where the mutations are too scattered to instrument, and it is
|
|
133
|
+
* floored at 500ms because `visible()` runs on every tick and the core
|
|
134
|
+
* documents it as "must be cheap", not free.
|
|
135
|
+
*/
|
|
136
|
+
watchMs?: number;
|
|
137
|
+
/** First reconnect delay; doubles up to `maxBackoffMs`. */
|
|
138
|
+
backoffMs?: number;
|
|
139
|
+
maxBackoffMs?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Injected transports, defaulting to the globals.
|
|
142
|
+
*
|
|
143
|
+
* These are a design requirement, not a testing shim. A page side that can
|
|
144
|
+
* only run inside a browser can only be verified inside a browser, which in
|
|
145
|
+
* practice means it is verified by hand, which means the reconnect path --
|
|
146
|
+
* the one that matters and the one nobody clicks through -- is the untested
|
|
147
|
+
* one. Taking both as options costs two lines and makes `hello` on reconnect
|
|
148
|
+
* and snapshot debouncing assertable in-process.
|
|
149
|
+
*/
|
|
150
|
+
EventSource?: EventSourceCtor;
|
|
151
|
+
fetch?: FetchLike;
|
|
152
|
+
/**
|
|
153
|
+
* The tab token this page presents, or a function that produces one.
|
|
154
|
+
*
|
|
155
|
+
* A relay serving more than one person needs to know which person this tab
|
|
156
|
+
* belongs to, and the only thing that knows is the app's own backend. So the
|
|
157
|
+
* backend mints a short-lived signed token (see `TabAuth` in
|
|
158
|
+
* `driverkit/relay`) and the page hands it over. The relay reads the
|
|
159
|
+
* principal out of it and scopes everything to that person: `/dk/tabs` lists
|
|
160
|
+
* their tabs and nobody else's, and another person's tab id is
|
|
161
|
+
* indistinguishable from one that was never minted.
|
|
162
|
+
*
|
|
163
|
+
* PASS A FUNCTION, NOT A STRING, unless the page is short-lived. A token
|
|
164
|
+
* expires -- deliberately, because a stateless token's short life is what
|
|
165
|
+
* substitutes for the revocation it cannot have -- and a string captured at
|
|
166
|
+
* page load is the one shape that cannot survive that. The function is
|
|
167
|
+
* called before every `hello`, which means before every reconnect, and again
|
|
168
|
+
* when a `POST /dk/result` comes back 401. That is the whole of the
|
|
169
|
+
* mid-session expiry handling and it is why the option is a getter.
|
|
170
|
+
*
|
|
171
|
+
* It may be async: a getter that fetches `/api/dk-token` is the expected
|
|
172
|
+
* implementation. The first stream then opens a tick later than it otherwise
|
|
173
|
+
* would, which nothing depends on.
|
|
174
|
+
*
|
|
175
|
+
* Omit it against an unconfigured relay -- a loopback dev relay with no auth
|
|
176
|
+
* -- which needs no credential at all.
|
|
177
|
+
*/
|
|
178
|
+
token?: string | (() => string | Promise<string>);
|
|
179
|
+
/**
|
|
180
|
+
* Mint an anonymous credential when there is no `token`.
|
|
181
|
+
*
|
|
182
|
+
* For an app whose visitors are not logged in. The page mints 256 random
|
|
183
|
+
* bits, keeps them in `sessionStorage` beside the tab id, and presents them;
|
|
184
|
+
* the relay derives a principal from them, so two anonymous visitors are two
|
|
185
|
+
* principals and are isolated from each other. "Anonymous" is not one
|
|
186
|
+
* bucket.
|
|
187
|
+
*
|
|
188
|
+
* OFF by default, and the default is the interesting part. On, a page whose
|
|
189
|
+
* author forgot to wire `token` would quietly work: every user would become
|
|
190
|
+
* their own anonymous stranger, everything would look fine, and their agent
|
|
191
|
+
* -- which has a real token -- would see zero tabs. Off, that author gets a
|
|
192
|
+
* 401 and an answer. An app that really is anonymous says so in one flag.
|
|
193
|
+
*
|
|
194
|
+
* The credential is a bearer capability and not an identity: whoever holds
|
|
195
|
+
* the string is that visitor. It dies with the tab, by design.
|
|
196
|
+
*/
|
|
197
|
+
anonymous?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Where the tab token rides on the `/dk/events` URL.
|
|
200
|
+
*
|
|
201
|
+
* `EventSource` cannot set a header, so a page's only two options for the
|
|
202
|
+
* stream are a cookie the app set (same-origin: nothing in any URL, and the
|
|
203
|
+
* best choice available) or a query parameter.
|
|
204
|
+
*
|
|
205
|
+
* `"query"` is the default because it works cross-origin, and it is a
|
|
206
|
+
* liability: A QUERY PARAMETER ENDS UP IN EVERY REVERSE PROXY'S ACCESS LOG.
|
|
207
|
+
* Pass `"cookie"` when the app sets a `__Host-dk_token` cookie and the relay
|
|
208
|
+
* is same-origin, and no token appears in a URL at all. The `/dk/result`
|
|
209
|
+
* POSTs always use a header regardless, because `fetch` can set one.
|
|
210
|
+
*/
|
|
211
|
+
tokenIn?: "query" | "cookie";
|
|
212
|
+
/** Where the tab id is remembered. Pass null to not remember it. */
|
|
213
|
+
storage?: StorageLike | null;
|
|
214
|
+
randomUUID?: () => string;
|
|
215
|
+
/** A failed POST or a malformed frame lands here. Default: ignore it. */
|
|
216
|
+
onError?: (err: unknown) => void;
|
|
217
|
+
/**
|
|
218
|
+
* Report where this tab stands in the person's attention. On by default.
|
|
219
|
+
*
|
|
220
|
+
* WHAT IT FIXES. `driverkit-mcp --tab <id>` works and "omit it when exactly
|
|
221
|
+
* one tab is connected" stops working at two, and nothing in the protocol
|
|
222
|
+
* expressed *"the one I am looking at"* -- which is what a person means when
|
|
223
|
+
* they are asked which tab. The only process that can answer is the
|
|
224
|
+
* document: `document.hasFocus()` is not visible to a relay, to a server or
|
|
225
|
+
* to another tab. So the page says, in `hello` and in every snapshot push,
|
|
226
|
+
* and `GET /dk/tabs` carries it. See `TabFocus` for the three states and
|
|
227
|
+
* PROTOCOL.md for what a client does when more than one tab qualifies.
|
|
228
|
+
*
|
|
229
|
+
* On by default and in the same category as `title` and `url`, which are
|
|
230
|
+
* read off the page without being asked for: an app that wrote no new code
|
|
231
|
+
* gets this, because a field only the careful adopters send is a field no
|
|
232
|
+
* client can rely on. It costs one short string per push and one listener
|
|
233
|
+
* each on `visibilitychange`, `focus` and `blur`.
|
|
234
|
+
*
|
|
235
|
+
* `false` opts out entirely -- no listeners, no field, and the frames are
|
|
236
|
+
* exactly the bytes they were. An environment with no `document` reports
|
|
237
|
+
* nothing either way, which is why the Node-side tests of this file see no
|
|
238
|
+
* change at all.
|
|
239
|
+
*/
|
|
240
|
+
focus?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Report how long this tab's own work took, on every `result` frame. On by
|
|
243
|
+
* default.
|
|
244
|
+
*
|
|
245
|
+
* WHAT IT FIXES. An agent in the page measures a verb by bracketing
|
|
246
|
+
* `driver.call()` and nothing else, which is why `took: ~2s` means the app
|
|
247
|
+
* there. An agent on the far side of the relay can measure only its own round
|
|
248
|
+
* trip -- network out, this tab's work, any question this page put to a
|
|
249
|
+
* person, network back -- and three of those four are not the app. So the
|
|
250
|
+
* figure is taken HERE, where the bracket can be the same one, and carried in
|
|
251
|
+
* the frame; see PROTOCOL.md on the `result` frame, and `renderDuration` for
|
|
252
|
+
* what is then rendered from it.
|
|
253
|
+
*
|
|
254
|
+
* Not `DriveOptions.timing`'s three words, because there is nothing to render
|
|
255
|
+
* on this side: this decides only whether the tab measures and says. A client
|
|
256
|
+
* decides what reaches a model, and an absent figure renders as nothing at
|
|
257
|
+
* all rather than as zero.
|
|
258
|
+
*
|
|
259
|
+
* On by default and in the same category as `focus`, `title` and `url`: a
|
|
260
|
+
* field only the careful adopters send is a field no client can rely on. It
|
|
261
|
+
* costs two clock reads and about fifteen bytes per call. `false` opts out
|
|
262
|
+
* entirely and the frames are exactly the bytes they were.
|
|
263
|
+
*
|
|
264
|
+
* It does NOT make this tab report a figure it cannot vouch for. A call that
|
|
265
|
+
* may have had a person inside it -- a gated `commit`, the `ask` verb -- is
|
|
266
|
+
* sent with no `tookMs` unless `waited` is wired up to say how long they
|
|
267
|
+
* took. See `canTime`.
|
|
268
|
+
*/
|
|
269
|
+
timing?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Total milliseconds this page has spent waiting on a PERSON, ever.
|
|
272
|
+
*
|
|
273
|
+
* The same contract as `DriveOptions.waited`, deliberately: monotonic,
|
|
274
|
+
* cumulative, and read before and after the call so the difference is what
|
|
275
|
+
* this one call spent on somebody. A counter that is diffed cannot be got
|
|
276
|
+
* wrong by a dialog that opens twice, and nothing here has to be told when a
|
|
277
|
+
* question was asked. A host that already passes a `waited` to `drive` or
|
|
278
|
+
* `mountWidget` passes the same function here.
|
|
279
|
+
*
|
|
280
|
+
* It buys two things. The person's time is subtracted from `tookMs`, so a
|
|
281
|
+
* 38-second confirmation around a 400ms commit reports the 400ms; and it is
|
|
282
|
+
* reported as `waitedMs`, so the gap between an agent's round trip and
|
|
283
|
+
* `tookMs` is accounted for rather than guessed at.
|
|
284
|
+
*
|
|
285
|
+
* Absent means the two calls this page cannot see inside -- a gated `commit`
|
|
286
|
+
* and `ask` -- report no duration at all rather than one with a person in it.
|
|
287
|
+
* That is the honest trade: silence says nobody measured, which is true,
|
|
288
|
+
* where a figure would make a false claim about the app's speed.
|
|
289
|
+
*
|
|
290
|
+
* WHAT IS STILL MISSING, stated rather than left to be discovered: a page
|
|
291
|
+
* that mounts the panel AND connects gets the panel's dialog as the core's
|
|
292
|
+
* approver, and `mountWidget` keeps that counter to itself -- it passes its
|
|
293
|
+
* own `waited` to `drive` and publishes it nowhere. So commits driven from
|
|
294
|
+
* OUTSIDE such a page report no duration until the widget hands its counter
|
|
295
|
+
* out, which is a change in `widget.ts` and not here. Until then the honest
|
|
296
|
+
* answer over the relay for those calls is the silence above, and a host that
|
|
297
|
+
* gates with its own dialog can wire this option today.
|
|
298
|
+
*/
|
|
299
|
+
waited?: () => number;
|
|
300
|
+
/** The clock `timing` reads, defaulting to `Date.now`. Injectable for the
|
|
301
|
+
* reason `DriveOptions.clock` is: a suite that pins it gets an exact figure
|
|
302
|
+
* out of a timed call instead of whatever the machine was doing. */
|
|
303
|
+
now?: () => number;
|
|
304
|
+
/**
|
|
305
|
+
* The document, defaulting to the global. Where `title`, `visibilityState`,
|
|
306
|
+
* `hasFocus()` and `visibilitychange` come from.
|
|
307
|
+
*/
|
|
308
|
+
document?: PageLike;
|
|
309
|
+
/**
|
|
310
|
+
* Where `focus` and `blur` are listened for, defaulting to `globalThis` --
|
|
311
|
+
* which in a browser IS the window. Separate from `document` because those
|
|
312
|
+
* two events are not delivered to the document; see `FocusEventsLike`.
|
|
313
|
+
*/
|
|
314
|
+
window?: FocusEventsLike;
|
|
315
|
+
/** The location, defaulting to the global. See `urlFromPage` for what is
|
|
316
|
+
* taken from it and why the hash is now part of it. */
|
|
317
|
+
location?: LocationLike;
|
|
318
|
+
}
|
|
319
|
+
export interface Connection {
|
|
320
|
+
/** The id the relay knows this tab by. A capability: do not log it. */
|
|
321
|
+
readonly tab: string;
|
|
322
|
+
/** Tell the relay the page moved on its own. Debounced; cheap to over-call. */
|
|
323
|
+
changed: () => void;
|
|
324
|
+
/** Stop. Idempotent. Does not unmount the driver. */
|
|
325
|
+
disconnect: () => void;
|
|
326
|
+
}
|
|
327
|
+
export declare function connect(driver: Driver, options: ConnectOptions): Connection;
|
|
328
|
+
/**
|
|
329
|
+
* The url, path and query AND HASH.
|
|
330
|
+
*
|
|
331
|
+
* THE HASH USED TO BE DROPPED, and for a hash-routed app the hash is the
|
|
332
|
+
* entire route: every tab of such an app reported the same `/` in `/dk/tabs`,
|
|
333
|
+
* so the one field a person is shown to tell two tabs apart told them nothing.
|
|
334
|
+
* It was dropped to keep a fragment out of a listing, which is a real concern
|
|
335
|
+
* about the wrong field -- the token is the capability here, and it travels in
|
|
336
|
+
* a header or a query parameter, never in `location`.
|
|
337
|
+
*
|
|
338
|
+
* Still path-relative and never the origin, which is the part that was right:
|
|
339
|
+
* the relay knows the origin, and a full url in a listing is an inventory of
|
|
340
|
+
* where somebody has been.
|
|
341
|
+
*/
|
|
342
|
+
export declare function urlFromPage(place: LocationLike | undefined): {
|
|
343
|
+
url?: string;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* The three focus states, from the two things a document can be asked.
|
|
347
|
+
*
|
|
348
|
+
* ```
|
|
349
|
+
* visibilityState hasFocus() answer
|
|
350
|
+
* "hidden" anything "hidden" a background tab
|
|
351
|
+
* "visible" true "focused" the person is looking at this
|
|
352
|
+
* "visible" false "visible" active tab, window not frontmost
|
|
353
|
+
* "visible" absent "visible" an engine with no hasFocus:
|
|
354
|
+
* the strongest honest answer
|
|
355
|
+
* absent absent undefined not a page; say nothing
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* `undefined` rather than a guess in the last row, and `TabFocus` says why it
|
|
359
|
+
* must stay distinguishable from `"hidden"`: a client that read "I cannot
|
|
360
|
+
* tell" as "not that one" would quietly become unable to drive a tab whose
|
|
361
|
+
* page does not report.
|
|
362
|
+
*
|
|
363
|
+
* `hasFocus()` is called in a `try`, because this runs on a timer in a page
|
|
364
|
+
* that may be mid-teardown and a throwing getter must not take the push with
|
|
365
|
+
* it. A throw is read as "cannot tell", never as focused.
|
|
366
|
+
*/
|
|
367
|
+
export declare function focusOf(page: PageLike | undefined): TabFocus | undefined;
|
|
368
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/browser/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,aAAa,CAAC;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