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 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/browser/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgGH,kFAAkF;AAClF,MAAM,MAAM,GAAG,CAAC,CAAC;AAEjB;;;;;;;;;;GAUG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAoOlC,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,OAAuB;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC;IAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;IAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC9C,MAAM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CAAC;IACxC,OAAO,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * driverkit/browser — the page side.\n *\n * One function. It holds an `EventSource` open, answers `call` frames by\n * handing them to the driver `mount()` returned, and POSTs the `Result` back.\n * It makes no decisions: it does not validate args, does not check `rev`, does\n * not refuse. The driver owns all of that, and PROTOCOL.md's reason is the one\n * that matters -- a second place that validates is a second set of rules, and\n * the in-page chatbot calling `driver.call()` directly would get the other one.\n *\n * No dependencies and no framework. `EventSource` and `fetch` are built in,\n * which is half of why the protocol is SSE in the first place.\n */\n\nimport type { Driver, Result, TabFocus } from \"./frames.ts\";\nimport type { CallFrame, HelloFrame, ResultFrame, SnapshotFrame } from \"./frames.ts\";\n\n/**\n * The browser pieces, as structural types.\n *\n * Narrow on purpose: these describe only what `connect` actually touches, so\n * the real `EventSource` satisfies them and so does a thirty-line fake. That\n * is the point -- see `ConnectOptions.EventSource`.\n */\nexport interface EventSourceLike {\n readonly readyState: number;\n addEventListener(type: string, listener: (event: { data?: string }) => void): void;\n close(): void;\n}\n\nexport interface EventSourceCtor {\n new (url: string): EventSourceLike;\n}\n\n/**\n * The part of a `Response` the page side reads: the status, and nothing else.\n *\n * Narrow for the same reason `EventSourceLike` is -- the real `Response`\n * satisfies it, and so does `{ status: 409 }` in a test. The body is never\n * read: PROTOCOL.md pins `POST /dk/result` to `202 {\"ok\":true}` on acceptance\n * and says a payload there \"would be an invitation to build a second,\n * divergent return path\". The answer to a call travels to the agent, not back\n * up this POST.\n */\nexport interface ResponseLike {\n /**\n * Optional only so an injected stub that returns nothing still typechecks.\n * An absent status is read as acceptance: there is nothing to read it as\n * instead, and the real `fetch` always carries one.\n */\n readonly status?: number;\n}\n\nexport interface FetchLike {\n (url: string, init: { method: string; headers: Record<string, string>; body: string }): Promise<ResponseLike>;\n}\n\nexport interface StorageLike {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n}\n\n/**\n * The part of `document` this file reads: the title, and where the attention is.\n *\n * Injectable for the reason `EventSourceLike` is injectable, and this one is\n * the more important of the two: focus reporting is a thing that happens when\n * a person alt-tabs, and \"alt-tab and see whether the right frame went out\" is\n * not a test anybody runs twice. Every method is optional so that a partial\n * stub -- `{ visibilityState: \"visible\" }` -- is a usable one, and so that a\n * real `document` from an older engine with no `hasFocus` still satisfies it.\n *\n * Note that `titleFromPage` and `urlFromPage` used to read `globalThis`\n * directly and were therefore the two things in here that could not be\n * exercised in process. They take these now.\n */\nexport interface PageLike {\n readonly title?: string;\n readonly visibilityState?: string;\n hasFocus?: () => boolean;\n addEventListener?(type: string, listener: () => void): void;\n removeEventListener?(type: string, listener: () => void): void;\n}\n\n/**\n * Where `focus` and `blur` are listened for: the window, or anything shaped\n * like it.\n *\n * SEPARATE FROM `PageLike` because the two events are not on the same object.\n * `visibilitychange` fires on `document`; `focus` and `blur` do not bubble and\n * are delivered to the window. Listening for all three on `document` is the\n * mistake that makes a focus change in a visible tab -- the person clicking\n * from another application into this window, which is the whole case this\n * exists for -- go unnoticed.\n */\nexport interface FocusEventsLike {\n addEventListener(type: string, listener: () => void): void;\n removeEventListener?(type: string, listener: () => void): void;\n}\n\n/** The part of `location` the url is built from. `hash` is in here on purpose;\n * see `urlFromPage`. */\nexport interface LocationLike {\n readonly pathname?: string;\n readonly search?: string;\n readonly hash?: string;\n}\n\n/** `EventSource.CLOSED`. Spelled out because the fake need not define statics. */\nconst CLOSED = 2;\n\n/**\n * How many times one `result` is re-sent after a 409 before it is given up on.\n *\n * Bounded, because the failure this guards against is symmetrical. A result\n * dropped on the floor costs the agent the relay's whole deadline waiting for\n * an answer that already exists; a result re-sent forever costs it a tab that\n * reconnects in a loop and never answers anything. Two is enough for the case\n * this is for -- the relay dropped the tab between the `call` going out and the\n * `result` coming back, and one reconnect fixes that -- and anything more is a\n * relay that is not coming back.\n */\nconst RESULT_RETRIES = 2;\n\n/**\n * How long a 409 retry waits for the new stream to open before going anyway.\n *\n * It has to be bounded. Everything queued behind the retried result waits on\n * this, so an unbounded wait on a stream that never opens is a tab that never\n * answers anything again -- a worse failure than the dropped result this is\n * fixing. On expiry the retry goes out regardless, takes another 409, and\n * spends one of its `RESULT_RETRIES`.\n */\nconst RECONNECT_WAIT_MS = 3_000;\n\n/**\n * How many times one frame is re-sent after a 401 with a fresh credential.\n *\n * One, because the case this is for is a token that lapsed between the stream\n * opening and this POST, and one refresh fixes that. A second attempt would\n * only help if the FIRST refresh also produced a dead token, which is a\n * misconfiguration -- a wrong audience, a key the relay does not have -- and a\n * misconfiguration retried in a loop is a page making a request per attempt\n * and never answering anything.\n */\nconst AUTH_RETRIES = 1;\n\n/**\n * The `sessionStorage` key the anonymous secret lives under.\n *\n * Separate from the tab id's key: an explicitly passed `tab` is deliberately\n * NOT written back, and an anonymous credential still has to be remembered\n * across the page's own reconnects or every reconnect would be a new visitor.\n */\nconst ANON_KEY = \"driverkit:anon\";\n\nexport interface ConnectOptions {\n /** Where the relay lives: an origin, or \"\" for same-origin. No trailing slash. */\n relay: string;\n /**\n * This tab's id. Omit and one is minted and remembered.\n *\n * PROTOCOL.md: minted by the tab, not the relay, so a reconnect resumes the\n * same identity. An agent mid-task holds this id; if a dropped stream came\n * back under a new one, every call it had queued up would answer\n * `no-such-tab` and the agent would conclude the window had closed.\n */\n tab?: string;\n app?: string;\n /** Only so a human can tell two tabs apart when asked \"which one?\". */\n title?: string;\n url?: string;\n /**\n * How long to coalesce `changed()` calls. PROTOCOL.md: \"sent on a debounce,\n * not on every keystroke\". A snapshot push is a courtesy to an agent that is\n * mid-task -- it says \"the human moved, re-read\" -- and one per keystroke\n * would cost more than the information is worth.\n */\n debounceMs?: number;\n /**\n * Poll `driver.snapshot().rev` this often and push when it moves.\n *\n * Off unless asked for: an app that calls `changed()` where it changes needs\n * no polling, and that is the better shape. This is the escape hatch for a\n * codebase where the mutations are too scattered to instrument, and it is\n * floored at 500ms because `visible()` runs on every tick and the core\n * documents it as \"must be cheap\", not free.\n */\n watchMs?: number;\n /** First reconnect delay; doubles up to `maxBackoffMs`. */\n backoffMs?: number;\n maxBackoffMs?: number;\n\n /**\n * Injected transports, defaulting to the globals.\n *\n * These are a design requirement, not a testing shim. A page side that can\n * only run inside a browser can only be verified inside a browser, which in\n * practice means it is verified by hand, which means the reconnect path --\n * the one that matters and the one nobody clicks through -- is the untested\n * one. Taking both as options costs two lines and makes `hello` on reconnect\n * and snapshot debouncing assertable in-process.\n */\n EventSource?: EventSourceCtor;\n fetch?: FetchLike;\n /**\n * The tab token this page presents, or a function that produces one.\n *\n * A relay serving more than one person needs to know which person this tab\n * belongs to, and the only thing that knows is the app's own backend. So the\n * backend mints a short-lived signed token (see `TabAuth` in\n * `driverkit/relay`) and the page hands it over. The relay reads the\n * principal out of it and scopes everything to that person: `/dk/tabs` lists\n * their tabs and nobody else's, and another person's tab id is\n * indistinguishable from one that was never minted.\n *\n * PASS A FUNCTION, NOT A STRING, unless the page is short-lived. A token\n * expires -- deliberately, because a stateless token's short life is what\n * substitutes for the revocation it cannot have -- and a string captured at\n * page load is the one shape that cannot survive that. The function is\n * called before every `hello`, which means before every reconnect, and again\n * when a `POST /dk/result` comes back 401. That is the whole of the\n * mid-session expiry handling and it is why the option is a getter.\n *\n * It may be async: a getter that fetches `/api/dk-token` is the expected\n * implementation. The first stream then opens a tick later than it otherwise\n * would, which nothing depends on.\n *\n * Omit it against an unconfigured relay -- a loopback dev relay with no auth\n * -- which needs no credential at all.\n */\n token?: string | (() => string | Promise<string>);\n /**\n * Mint an anonymous credential when there is no `token`.\n *\n * For an app whose visitors are not logged in. The page mints 256 random\n * bits, keeps them in `sessionStorage` beside the tab id, and presents them;\n * the relay derives a principal from them, so two anonymous visitors are two\n * principals and are isolated from each other. \"Anonymous\" is not one\n * bucket.\n *\n * OFF by default, and the default is the interesting part. On, a page whose\n * author forgot to wire `token` would quietly work: every user would become\n * their own anonymous stranger, everything would look fine, and their agent\n * -- which has a real token -- would see zero tabs. Off, that author gets a\n * 401 and an answer. An app that really is anonymous says so in one flag.\n *\n * The credential is a bearer capability and not an identity: whoever holds\n * the string is that visitor. It dies with the tab, by design.\n */\n anonymous?: boolean;\n /**\n * Where the tab token rides on the `/dk/events` URL.\n *\n * `EventSource` cannot set a header, so a page's only two options for the\n * stream are a cookie the app set (same-origin: nothing in any URL, and the\n * best choice available) or a query parameter.\n *\n * `\"query\"` is the default because it works cross-origin, and it is a\n * liability: A QUERY PARAMETER ENDS UP IN EVERY REVERSE PROXY'S ACCESS LOG.\n * Pass `\"cookie\"` when the app sets a `__Host-dk_token` cookie and the relay\n * is same-origin, and no token appears in a URL at all. The `/dk/result`\n * POSTs always use a header regardless, because `fetch` can set one.\n */\n tokenIn?: \"query\" | \"cookie\";\n /** Where the tab id is remembered. Pass null to not remember it. */\n storage?: StorageLike | null;\n randomUUID?: () => string;\n /** A failed POST or a malformed frame lands here. Default: ignore it. */\n onError?: (err: unknown) => void;\n /**\n * Report where this tab stands in the person's attention. On by default.\n *\n * WHAT IT FIXES. `driverkit-mcp --tab <id>` works and \"omit it when exactly\n * one tab is connected\" stops working at two, and nothing in the protocol\n * expressed *\"the one I am looking at\"* -- which is what a person means when\n * they are asked which tab. The only process that can answer is the\n * document: `document.hasFocus()` is not visible to a relay, to a server or\n * to another tab. So the page says, in `hello` and in every snapshot push,\n * and `GET /dk/tabs` carries it. See `TabFocus` for the three states and\n * PROTOCOL.md for what a client does when more than one tab qualifies.\n *\n * On by default and in the same category as `title` and `url`, which are\n * read off the page without being asked for: an app that wrote no new code\n * gets this, because a field only the careful adopters send is a field no\n * client can rely on. It costs one short string per push and one listener\n * each on `visibilitychange`, `focus` and `blur`.\n *\n * `false` opts out entirely -- no listeners, no field, and the frames are\n * exactly the bytes they were. An environment with no `document` reports\n * nothing either way, which is why the Node-side tests of this file see no\n * change at all.\n */\n focus?: boolean;\n /**\n * Report how long this tab's own work took, on every `result` frame. On by\n * default.\n *\n * WHAT IT FIXES. An agent in the page measures a verb by bracketing\n * `driver.call()` and nothing else, which is why `took: ~2s` means the app\n * there. An agent on the far side of the relay can measure only its own round\n * trip -- network out, this tab's work, any question this page put to a\n * person, network back -- and three of those four are not the app. So the\n * figure is taken HERE, where the bracket can be the same one, and carried in\n * the frame; see PROTOCOL.md on the `result` frame, and `renderDuration` for\n * what is then rendered from it.\n *\n * Not `DriveOptions.timing`'s three words, because there is nothing to render\n * on this side: this decides only whether the tab measures and says. A client\n * decides what reaches a model, and an absent figure renders as nothing at\n * all rather than as zero.\n *\n * On by default and in the same category as `focus`, `title` and `url`: a\n * field only the careful adopters send is a field no client can rely on. It\n * costs two clock reads and about fifteen bytes per call. `false` opts out\n * entirely and the frames are exactly the bytes they were.\n *\n * It does NOT make this tab report a figure it cannot vouch for. A call that\n * may have had a person inside it -- a gated `commit`, the `ask` verb -- is\n * sent with no `tookMs` unless `waited` is wired up to say how long they\n * took. See `canTime`.\n */\n timing?: boolean;\n /**\n * Total milliseconds this page has spent waiting on a PERSON, ever.\n *\n * The same contract as `DriveOptions.waited`, deliberately: monotonic,\n * cumulative, and read before and after the call so the difference is what\n * this one call spent on somebody. A counter that is diffed cannot be got\n * wrong by a dialog that opens twice, and nothing here has to be told when a\n * question was asked. A host that already passes a `waited` to `drive` or\n * `mountWidget` passes the same function here.\n *\n * It buys two things. The person's time is subtracted from `tookMs`, so a\n * 38-second confirmation around a 400ms commit reports the 400ms; and it is\n * reported as `waitedMs`, so the gap between an agent's round trip and\n * `tookMs` is accounted for rather than guessed at.\n *\n * Absent means the two calls this page cannot see inside -- a gated `commit`\n * and `ask` -- report no duration at all rather than one with a person in it.\n * That is the honest trade: silence says nobody measured, which is true,\n * where a figure would make a false claim about the app's speed.\n *\n * WHAT IS STILL MISSING, stated rather than left to be discovered: a page\n * that mounts the panel AND connects gets the panel's dialog as the core's\n * approver, and `mountWidget` keeps that counter to itself -- it passes its\n * own `waited` to `drive` and publishes it nowhere. So commits driven from\n * OUTSIDE such a page report no duration until the widget hands its counter\n * out, which is a change in `widget.ts` and not here. Until then the honest\n * answer over the relay for those calls is the silence above, and a host that\n * gates with its own dialog can wire this option today.\n */\n waited?: () => number;\n /** The clock `timing` reads, defaulting to `Date.now`. Injectable for the\n * reason `DriveOptions.clock` is: a suite that pins it gets an exact figure\n * out of a timed call instead of whatever the machine was doing. */\n now?: () => number;\n /**\n * The document, defaulting to the global. Where `title`, `visibilityState`,\n * `hasFocus()` and `visibilitychange` come from.\n */\n document?: PageLike;\n /**\n * Where `focus` and `blur` are listened for, defaulting to `globalThis` --\n * which in a browser IS the window. Separate from `document` because those\n * two events are not delivered to the document; see `FocusEventsLike`.\n */\n window?: FocusEventsLike;\n /** The location, defaulting to the global. See `urlFromPage` for what is\n * taken from it and why the hash is now part of it. */\n location?: LocationLike;\n}\n\nexport interface Connection {\n /** The id the relay knows this tab by. A capability: do not log it. */\n readonly tab: string;\n /** Tell the relay the page moved on its own. Debounced; cheap to over-call. */\n changed: () => void;\n /** Stop. Idempotent. Does not unmount the driver. */\n disconnect: () => void;\n}\n\nexport function connect(driver: Driver, options: ConnectOptions): Connection {\n const relay = options.relay.replace(/\\/+$/, \"\");\n const debounceMs = options.debounceMs ?? 250;\n const backoffMs = options.backoffMs ?? 500;\n const maxBackoffMs = options.maxBackoffMs ?? 10_000;\n const onError = options.onError ?? (() => {});\n const ES = options.EventSource ?? (globalThis as { EventSource?: EventSourceCtor }).EventSource;\n const post = options.fetch ?? ((globalThis.fetch?.bind(globalThis) as FetchLike | undefined));\n const storage =\n options.storage === null\n ? null\n : (options.storage ?? (globalThis as { sessionStorage?: StorageLike }).sessionStorage ?? null);\n const page = options.document ?? (globalThis as { document?: PageLike }).document;\n const place = options.location ?? (globalThis as { location?: LocationLike }).location;\n // `globalThis` IS the window in a page, and in Node it is a global with an\n // `addEventListener` that exists and never fires either of these -- which is\n // harmless and is why this needs no environment check.\n const focusEvents: FocusEventsLike | undefined =\n options.window ??\n (typeof (globalThis as { addEventListener?: unknown }).addEventListener === \"function\"\n ? (globalThis as unknown as FocusEventsLike)\n : undefined);\n const wantsFocus = options.focus !== false;\n const wantsTiming = options.timing !== false;\n /** `options.now?.()` and never a detached `options.now ?? Date.now`, the rule\n * the loop's clock already follows: a method pulled off an object and called\n * bare loses its receiver, and a fake clock reading a private field throws. */\n const nowMs = (): number => options.now?.() ?? Date.now();\n\n if (!ES) throw new Error(\"driverkit: no EventSource. Pass options.EventSource.\");\n if (!post) throw new Error(\"driverkit: no fetch. Pass options.fetch.\");\n\n // Before anything is opened, for the reason a relay with remote access and\n // no way to identify callers refuses to start rather than serving: this is\n // the moment the app becomes drivable by something that is not in the room.\n //\n // Kinds first, and the order is an argument rather than a style: the commit\n // check reads `kind`, so a manifest with silent verbs cannot be assessed by\n // it at all. \"Declare your kinds\" and then \"now say who approves these\n // three commits\" is two true sentences in the order they can be acted on;\n // the other order asks about a list that is not yet known to be complete.\n requireDeclaredKinds(driver);\n requireApprovalPolicy(driver);\n\n const tab = options.tab ?? remembered(storage, options.app, options.randomUUID, onError);\n const tokenIn = options.tokenIn ?? \"query\";\n const mintToken =\n typeof options.token === \"function\"\n ? options.token\n : options.token !== undefined\n ? () => options.token as string\n : options.anonymous\n ? () => anonCredential(storage, options.app, onError)\n : null;\n\n let live = true;\n /**\n * The credential in hand, refreshed by `refresh()`.\n *\n * Kept rather than fetched per request so that the common case -- a static\n * string, or no credential at all -- opens its stream synchronously inside\n * the `connect()` call that asked for it, exactly as it did before tokens\n * existed.\n */\n let credential: string | undefined =\n // Synchronous only: an async getter is awaited by `open()` instead. The\n // cast is safe because the two synchronous branches of `mintToken` above\n // are the only ones reachable here.\n mintToken && typeof options.token !== \"function\" ? (mintToken() as string) : undefined;\n let opening = false;\n let source: EventSourceLike | null = null;\n let delay = backoffMs;\n let debounce: ReturnType<typeof setTimeout> | null = null;\n let reopen: ReturnType<typeof setTimeout> | null = null;\n let watch: ReturnType<typeof setInterval> | null = null;\n /** The focus state the relay was last told, so an event that does not move\n * it costs nothing. `undefined` before the first push and in an environment\n * that reports no focus at all. */\n let pushedFocus: TabFocus | undefined;\n /** How to drop the three focus listeners, set only when they were added. */\n let stopFocus: (() => void) | null = null;\n\n const url = (path: string) => `${relay}${path}?tab=${encodeURIComponent(tab)}`;\n\n /**\n * The `/dk/events` URL, with the credential if it travels in the query.\n *\n * Only the stream URL ever carries it. The `/dk/result` POSTs put it in\n * `X-DK-Token`, where no access log will write it down.\n */\n const streamUrl = () =>\n credential !== undefined && tokenIn === \"query\"\n ? `${url(\"/dk/events\")}&dk_token=${encodeURIComponent(credential)}`\n : url(\"/dk/events\");\n\n /** Fetch a fresh credential. Resolves even on failure; see the comment. */\n async function refresh(): Promise<void> {\n if (!mintToken) return;\n try {\n credential = await mintToken();\n } catch (err) {\n // Reported and then ignored, keeping whatever we had. A token endpoint\n // that is briefly down must not take the tab down with it: the stream we\n // already hold is still bound to this principal in the relay, and a\n // slightly stale token is a better bet than no attempt at all. The relay\n // answers 401 if it has really lapsed, and that path retries.\n onError(err);\n }\n }\n\n /**\n * The frames waiting to go up, oldest first, one POST in flight at a time.\n *\n * A queue rather than a POST per frame, and the reason is ordering under\n * retry. The moment one `result` can be re-sent, two results can be in\n * flight at once with the second one's POST started first, and an agent that\n * reads a `c-18` answer before a `c-17` answer is an agent acting on a screen\n * that has already moved. Serialising also makes \"never twice\" structural:\n * there is one entry per frame and it is removed when the relay has taken it,\n * so a retry cannot race a first attempt that was still in the air.\n *\n * The cost is that a slow POST holds up the next frame. That is the right\n * way round -- this is a handful of frames a minute, and PROTOCOL.md's \"no\n * queue\" rule is about the relay not holding CALLS for a tab that is gone,\n * not about a tab pipelining its own answers.\n */\n interface Outbound {\n frame: HelloFrame | ResultFrame | SnapshotFrame;\n tries: number;\n /** 401 retries spent on this frame. See `AUTH_RETRIES`. */\n stale: number;\n }\n const outbox: Outbound[] = [];\n let draining = false;\n /** Resolved by the stream's `open` listener. See `reconnect`. */\n let openWaiters: Array<() => void> = [];\n\n function up(frame: HelloFrame | ResultFrame | SnapshotFrame): void {\n if (!live) return;\n const entry: Outbound = { frame, tries: 0, stale: 0 };\n // `hello` jumps the queue, and only `hello` does. It is the frame that\n // makes this tab exist in the relay's registry -- `ingest` 409s every frame\n // for a tab it has no stream for, `hello` included -- so everything already\n // waiting needs it to have landed first. Appending it would mean a `result`\n // that took a 409 gets re-sent against the same empty registry it was just\n // refused by, which is a retry that cannot succeed.\n if (frame.t === \"hello\") outbox.unshift(entry);\n else outbox.push(entry);\n if (!draining) void drain();\n }\n\n /**\n * Send what is queued, oldest first, until it is empty.\n *\n * `drain` runs synchronously as far as the first POST, so the common case --\n * an idle outbox -- still issues its request inside the `up()` call that\n * queued it, exactly as the old one-POST-per-frame code did.\n */\n async function drain(): Promise<void> {\n draining = true;\n try {\n while (live && outbox.length) {\n const entry = outbox[0]!;\n // Removal is by identity, not `shift()`. A `hello` may have been\n // unshifted ahead of this entry while its POST was in the air, and\n // `shift()` would then drop the wrong frame.\n const forget = () => {\n const at = outbox.indexOf(entry);\n if (at !== -1) outbox.splice(at, 1);\n };\n\n let status: number | undefined;\n try {\n // `?tab=` as well as the body field: PROTOCOL.md's frame shapes name\n // the tab only in `hello`, so a relay that reads one and not the\n // other still works. Belt and braces on the field the whole\n // correlation depends on.\n const answer = await post!(url(\"/dk/result\"), {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n // A HEADER, never the query string. `fetch` can set one, so\n // there is no reason for a token to be written into an access\n // log here -- unlike the `EventSource` URL, which has no choice.\n ...(credential === undefined ? {} : { \"x-dk-token\": credential }),\n },\n body: JSON.stringify(entry.frame),\n });\n status = answer?.status;\n } catch (err) {\n // The POST never completed: offline, DNS, a relay that is not\n // listening. Not retried here -- there is no status to tell a\n // transient failure from a permanent one, and `EventSource` is about\n // to notice the same outage and run the reconnect path anyway.\n forget();\n onError(err);\n continue;\n }\n\n if (status === undefined || status < 400) {\n forget();\n continue;\n }\n\n if (status === 401) {\n // THE MID-SESSION EXPIRY PATH, and the reason `token` is a getter.\n //\n // The relay authenticates the stream once, at open, and the binding\n // it made lasts as long as the stream -- so a lapsed token does not\n // disconnect this tab and does not lose the calls in flight. But\n // `/dk/result` is a new request and carries its own credential, so\n // the symptom of expiry is exactly this: a tab that still receives\n // `call` frames and cannot answer them.\n //\n // Mint a fresh one and send the same bytes again. Bounded, because a\n // token endpoint answering with a credential the relay will not\n // accept -- a wrong audience, a key the relay does not have -- is a\n // misconfiguration, and retrying it forever is a page that never\n // answers anything while making a request per attempt.\n if (!mintToken || entry.stale >= AUTH_RETRIES) {\n forget();\n onError(\n new Error(\n `driverkit: the relay rejected this tab's credential on a \\`${entry.frame.t}\\` ` +\n (mintToken\n ? `frame after ${entry.stale} refreshes. Check the token's audience and key.`\n : \"frame, and no `token` option was given to refresh it.\"),\n ),\n );\n continue;\n }\n entry.stale += 1;\n await refresh();\n continue;\n }\n\n if (status === 409) {\n // PROTOCOL.md: \"409 means the frame was fine and the relay's state is\n // what made it unacceptable. A tab that gets 409 may reasonably\n // reconnect and retry.\" The relay has dropped this tab -- its stream\n // closed and the registry entry went with it -- so reconnecting is\n // the whole of the fix, and it is the one status where re-sending the\n // same bytes can work.\n //\n // `fetch` resolves on 409, which is why ignoring the status was not a\n // missing nicety: the answer the agent is holding a request open for\n // was lost here silently, and the agent waited out the relay's full\n // 15-second deadline for a result that already existed.\n const again = entry.frame.t === \"result\" && entry.tries < RESULT_RETRIES;\n if (again) {\n entry.tries += 1;\n } else {\n forget();\n // Only a `result` is worth a noise. A `hello` or a `snapshot` is\n // superseded by the `hello` the reconnect below sends, which\n // carries a newer snapshot than the one that just 409'd -- re-\n // sending the stale one would push an older `rev` after a newer\n // one, which is the one thing a watcher cannot recover from.\n if (entry.frame.t === \"result\") {\n onError(\n new Error(\n `driverkit: relay still 409s result \\`${entry.frame.id}\\` after ${entry.tries} reconnects; ` +\n `the agent will see it as a timeout`,\n ),\n );\n }\n }\n await reconnect();\n continue;\n }\n\n // 400 and anything else. PROTOCOL.md: \"400 means the frame could never\n // have been accepted by anyone... a tab that gets 400 has a bug.\" So it\n // is loud and it is never retried: re-sending a frame the relay has\n // already judged malformed is a loop with no exit, and the bug is here.\n forget();\n onError(\n new Error(\n `driverkit: relay answered ${status} to a \\`${entry.frame.t}\\` frame. ` +\n `A 4xx on /dk/result that is not a 409 is a bug in this tab, not in the relay.`,\n ),\n );\n }\n } finally {\n draining = false;\n }\n }\n\n /**\n * Drop this stream and bring up a new one, resolving once `hello` is queued.\n *\n * Not just `open()`: the registry entry the 409 is about belongs to a stream\n * the relay has already forgotten, and a tab that kept holding it would wait\n * for a `call` frame down a pipe nothing is writing to.\n *\n * It resolves on the new stream's `open` rather than on a timer because the\n * `open` listener is what sends `hello`, and the retried result must go out\n * behind that `hello`. The queue does the rest: `hello` is unshifted ahead of\n * the retry, and the loop above awaits each POST, so the ordering is\n * structural rather than a guessed delay.\n */\n function reconnect(): Promise<void> {\n if (!live) return Promise.resolve();\n if (source) {\n const old = source;\n source = null;\n try {\n old.close();\n } catch (err) {\n onError(err);\n }\n if (reopen) {\n clearTimeout(reopen);\n reopen = null;\n }\n open();\n } else if (!reopen) {\n // No stream and nothing scheduled: the error path has already given up,\n // or two 409s arrived and the first one's reconnect is what closed this.\n open();\n }\n // Otherwise a reopen is already on a timer -- the backoff path's. Waiting\n // for it rather than racing it, because two streams for one tab id is a\n // supersede, and superseding the stream we are waiting on is a loop.\n return new Promise<void>((resolve) => {\n let settled = false;\n const finish = () => {\n if (settled) return;\n settled = true;\n resolve();\n };\n openWaiters.push(finish);\n const timer = setTimeout(finish, RECONNECT_WAIT_MS);\n (timer as { unref?: () => void }).unref?.();\n });\n }\n\n /** The url as it is NOW, or an explicit one the app passed. Spelled once\n * because `hello` and every push must agree about it; two copies is how the\n * reconnect path comes to report something the push path does not. */\n function whereNow(): { url?: string } {\n return options.url === undefined ? urlFromPage(place) : { url: options.url };\n }\n\n /** The focus as it is NOW, or nothing at all when the app opted out or the\n * environment is not a page. An absent field means \"did not say\"; see\n * `TabFocus`. */\n function focusNow(): { focus?: TabFocus } {\n if (!wantsFocus) return {};\n const focus = focusOf(page);\n return focus === undefined ? {} : { focus };\n }\n\n function hello(): void {\n const frame: HelloFrame = {\n t: \"hello\",\n tab,\n ...(options.app === undefined ? {} : { app: options.app }),\n manifest: driver.manifest(),\n snapshot: driver.snapshot(),\n ...(options.title === undefined ? { ...titleFromPage(page) } : { title: options.title }),\n ...whereNow(),\n // In `hello` as well as in the pushes, because `hello` is the only frame\n // a tab that never moves ever sends. A tab opened and left alone would\n // otherwise have no focus at all in `/dk/tabs`, which is the listing a\n // client reads before it has seen a single push.\n ...focusNow(),\n };\n up(frame);\n }\n\n /**\n * The verb kinds this app declared, read off the manifest once.\n *\n * The manifest is the static half and is guaranteed not to vary between two\n * calls, so this is cached rather than rebuilt per call -- but keyed on\n * `version`, because a hand-written driver is free to be stranger than the\n * core's and a stale map would decide `canTime` with yesterday's kinds.\n */\n let kinds: { version: string; of: Map<string, string | undefined> } | null = null;\n function kindOf(name: string): string | undefined {\n const manifest = driver.manifest();\n if (kinds === null || kinds.version !== manifest.version) {\n kinds = {\n version: manifest.version,\n of: new Map(manifest.verbs.map((v) => [v.name, v.kind])),\n };\n }\n return kinds.of.get(name);\n }\n\n /**\n * Whether this tab can state this call's duration without a person in it.\n *\n * THE WHOLE HONESTY ARGUMENT, and it is about WHERE the measurement is taken\n * rather than about arithmetic afterwards. The clock brackets\n * `driver.call()`, which is the same bracket the in-page loop uses -- so\n * everything the page does outside that call is outside the figure for free.\n * What is INSIDE it, and invisible from here, is a person:\n *\n * `ask` IS a question put to somebody. Its whole duration is a human\n * reading and typing, so a `tookMs` for one would be a false\n * claim about the app with no true part to it at all.\n * `commit` may be held by the core's approval gate, which is the\n * configuration `mountWidget` creates through\n * `DriverApproval.adopt`. `policy` is a LIVE read for exactly\n * this reason: the same driver answers `none` before a panel\n * mounts and `adopted` after, and only `hook` and `adopted` can\n * put a question in front of anybody -- `unattended` answers\n * itself and `none` is no gate.\n *\n * Everything else -- a `read`, a `describe`, a commit nobody is asked about,\n * a verb that declared no `kind` at all and so is never gated by the core --\n * is the app's own work and is reported.\n *\n * `waited` settles all of it: a host that counts its own person-time has the\n * figure this cannot see, so it is subtracted and the call is timed whatever\n * its kind. Without one, the answer here is silence, which PROTOCOL.md pins\n * as UNKNOWN rather than zero. A tab that waits on a person inside a verb\n * BODY is beyond anything this can know and must report it through `waited`\n * or pass `timing: false`; that is stated in PROTOCOL.md as a must and is the\n * one case left where a wrong figure is reachable.\n */\n function canTime(name: string): boolean {\n if (options.waited !== undefined) return true;\n const kind = kindOf(name);\n if (kind === \"ask\") return false;\n if (kind !== \"commit\") return true;\n const policy = driver.approval?.policy;\n return policy !== \"hook\" && policy !== \"adopted\";\n }\n\n /**\n * The two fields a `result` frame carries about its own elapsed time, or\n * nothing at all.\n *\n * Both figures are whole milliseconds and both are floored at zero.\n * `Math.max(0, ...)` twice, because `waited` is reported by a host and a host\n * that reports more wait than the call took is a host with a bug -- in which\n * case the honest figure is the floor and not a negative number on the wire.\n * A clock that went backwards lands in the same place; `renderDuration`\n * refuses to print a negative duration either way, and this refuses to send\n * one.\n *\n * `waitedMs` is sent only when somebody actually waited. Zero is the normal\n * case and a key that says \"no person, this time\" on every call in every\n * session is rent paid forever for a fact the absence already carries -- the\n * same argument `renderDuration` makes for saying nothing about a fast call.\n */\n function timing(timed: boolean, started: number, waitedBefore: number): {\n tookMs?: number;\n waitedMs?: number;\n } {\n if (!timed) return {};\n const waited = Math.max(0, (options.waited?.() ?? 0) - waitedBefore);\n const took = Math.max(0, Math.floor(nowMs() - started - waited));\n // A broken clock, or a `waited` that returned something that is not a\n // number, is a measurement that did not happen -- and the honest rendering\n // of one of those is silence, not `null` on the wire for a relay to throw\n // away at the other end.\n if (!Number.isFinite(took)) return {};\n return { tookMs: took, ...(waited > 0 ? { waitedMs: Math.floor(waited) } : {}) };\n }\n\n async function onCall(frame: CallFrame): Promise<void> {\n // Read before the call and again after, with nothing of this function's own\n // between the two reads: the pace of the loop, the POST that carries the\n // answer and this tab's own error handling are all outside the bracket by\n // construction. `timed` is null for a call this tab cannot speak for, and\n // then no clock is read at all -- an app that opts out, or a question put to\n // a person, costs exactly the bytes and the cycles it did before.\n const timed = wantsTiming && canTime(frame.name);\n const started = timed ? nowMs() : 0;\n const waitedBefore = timed ? (options.waited?.() ?? 0) : 0;\n let result: Result;\n try {\n result = await driver.call(\n frame.name,\n frame.args ?? {},\n // Only when the agent sent one. The core treats a present `rev` or\n // `screen` as a check and an absent one as opting out of it, so passing\n // `{ rev: undefined }` would be fine today and a trap the day somebody\n // tightens that. `screen` is the agent's claim about which screen it\n // read, checked by the core before `rev`; this hop is where it would\n // otherwise be dropped, which would leave the field working in-page and\n // silently doing nothing over the relay. `plan` is here for the same\n // reason and with the most to lose by being missed: a commit that\n // requires a token and is reached by a path that drops it is refused\n // forever, and one reached by a path that invents one would be worse.\n {\n ...(frame.rev === undefined ? {} : { rev: frame.rev }),\n ...(frame.screen === undefined ? {} : { screen: frame.screen }),\n ...(frame.plan === undefined ? {} : { plan: frame.plan }),\n },\n );\n } catch (err) {\n // `mount()`'s driver turns a throwing verb into `refused: \"threw\"`, so\n // this is only reachable for a hand-written driver. Still answered\n // rather than dropped: the agent is holding a request open on this id,\n // and silence costs it the relay's full timeout.\n onError(err);\n result = {\n ok: false,\n refused: \"threw\",\n hint: err instanceof Error ? err.message : String(err),\n snapshot: driver.snapshot(),\n };\n }\n up({ t: \"result\", id: frame.id, result, tab, ...timing(timed, started, waitedBefore) });\n }\n\n /**\n * Bring up a stream, fetching a credential first when that takes a tick.\n *\n * Split from `start` so the common cases -- a static token, an anonymous\n * secret out of `sessionStorage`, or no credential at all -- still open the\n * stream synchronously inside the `connect()` call. Only an async `token`\n * getter defers, and `opening` is what stops a `reconnect()` arriving in that\n * window from opening a second stream for one tab id.\n */\n function open(): void {\n if (!live || opening) return;\n if (typeof options.token !== \"function\") {\n start();\n return;\n }\n opening = true;\n void (async () => {\n await refresh();\n opening = false;\n start();\n })();\n }\n\n function start(): void {\n if (!live) return;\n const es = new ES!(streamUrl());\n source = es;\n\n es.addEventListener(\"open\", () => {\n // Every open, not just the first. `EventSource` reconnects by itself and\n // the relay has forgotten the tab by then -- the registry entry dropped\n // when the stream closed -- so a `hello` that were sent once would leave\n // a tab that is connected and unidentifiable. This re-send is the\n // reconnect handling; the rest is the browser's.\n delay = backoffMs;\n // Before `hello`, so a reconnect presents a live credential. `/dk/events`\n // was authenticated with whatever we had a moment ago; the POST that\n // follows is a separate request and may be the one the old token no\n // longer covers. Awaiting here is not an option -- this is an\n // `EventSource` listener -- so the refresh runs beside the `hello`, and\n // the 401 path above is what catches the race on the rare occasion the\n // old token was already dead.\n if (typeof options.token === \"function\") void refresh();\n hello();\n // After `hello()`, never before. A 409 retry waiting here resumes on the\n // next microtask and must find the `hello` already at the head of the\n // outbox, or it goes out first and 409s again.\n const waiting = openWaiters;\n openWaiters = [];\n for (const waiter of waiting) waiter();\n });\n\n es.addEventListener(\"call\", (event) => {\n try {\n const frame = JSON.parse(String(event.data)) as CallFrame;\n if (frame?.t !== \"call\" || typeof frame.id !== \"string\") throw new Error(\"not a call frame\");\n void onCall(frame);\n } catch (err) {\n // Dropped, not crashed. A frame this page cannot parse is a relay from\n // a newer version of the protocol, and taking the stream down over it\n // would turn a forward-compatible addition into an outage.\n onError(err);\n }\n });\n\n es.addEventListener(\"error\", () => {\n // `error` fires on every blip, including the ones `EventSource` is about\n // to retry by itself. Only a CLOSED stream is ours to restart; racing the\n // browser's own retry would open two streams for one tab.\n if (!live || es.readyState !== CLOSED) return;\n if (source === es) source = null;\n if (reopen) return;\n reopen = setTimeout(() => {\n reopen = null;\n open();\n }, delay);\n (reopen as { unref?: () => void }).unref?.();\n delay = Math.min(delay * 2, maxBackoffMs);\n });\n }\n\n function changed(): void {\n if (!live) return;\n if (debounce) return; // Already coalescing; the flush reads the latest state.\n debounce = setTimeout(() => {\n debounce = null;\n if (!live) return;\n // Read at flush time, not at call time. Ten `changed()` calls in one\n // frame must produce one push of the FINAL state, not the first.\n //\n // The url and the focus ride along, and that is the cheap half of two\n // fixes. `TabInfo.url` came from `hello` ALONE, so it was stale the\n // moment the tab navigated -- and a single-page app navigates without\n // reconnecting, so `hello` may never come again. A push is already going\n // out whenever the page moves; carrying the current url on it costs one\n // short string and makes the listing true. `focus` is the same shape of\n // saving: the frame it needs was already there.\n pushedFocus = focusNow().focus;\n up({ t: \"snapshot\", snapshot: driver.snapshot(), tab, ...whereNow(), ...focusNow() });\n }, debounceMs);\n (debounce as { unref?: () => void }).unref?.();\n }\n\n /**\n * Watch the three events that move the focus state and push when it changes.\n *\n * ON A CHANGE AND NOT ON AN EVENT. `focus` fires on a window that was\n * already focused, `visibilitychange` fires on its way to a state it was\n * already in, and a person alt-tabbing between two applications would\n * otherwise generate a push per keystroke -- each of which the relay\n * force-forwards to every watcher, because a `snapshot` frame is the tab\n * SAYING the page moved and the relay does not second-guess that. So the\n * last pushed value is remembered and an event that does not move it is\n * dropped here, before the debounce, where it costs nothing.\n *\n * It goes out through `changed()` rather than through its own frame, which is\n * the decision worth naming: the protocol gains a field, not a frame. A tab\n * that has focus news has a snapshot to send with it, the debounce\n * coalesces the two, and a relay or a client written before this reads the\n * same `snapshot` frame it always read and ignores one field.\n */\n // Gated on the page actually REPORTING a focus state, not merely on there\n // being somewhere to listen. `globalThis` has an `addEventListener` in Node\n // too, so without this every `connect()` in a test suite -- and in a server\n // -- would register three listeners that can never fire.\n if (wantsFocus && focusOf(page) !== undefined && (page?.addEventListener || focusEvents)) {\n pushedFocus = focusOf(page);\n const onFocusEvent = (): void => {\n if (!live) return;\n if (focusOf(page) === pushedFocus) return;\n changed();\n };\n // `visibilitychange` is the document's; `focus` and `blur` are the\n // window's and do not bubble to it. See `FocusEventsLike`.\n page?.addEventListener?.(\"visibilitychange\", onFocusEvent);\n focusEvents?.addEventListener(\"focus\", onFocusEvent);\n focusEvents?.addEventListener(\"blur\", onFocusEvent);\n stopFocus = () => {\n page?.removeEventListener?.(\"visibilitychange\", onFocusEvent);\n focusEvents?.removeEventListener?.(\"focus\", onFocusEvent);\n focusEvents?.removeEventListener?.(\"blur\", onFocusEvent);\n };\n }\n\n if (options.watchMs !== undefined) {\n const every = Math.max(500, options.watchMs);\n let seen = driver.snapshot().rev;\n watch = setInterval(() => {\n if (!live) return;\n try {\n const rev = driver.snapshot().rev;\n if (rev === seen) return;\n seen = rev;\n changed();\n } catch (err) {\n onError(err);\n }\n }, every);\n (watch as { unref?: () => void }).unref?.();\n }\n\n open();\n\n return {\n tab,\n changed,\n disconnect() {\n live = false;\n // Dropped rather than flushed. `disconnect` is the page saying it is done\n // driving; POSTing answers to a relay nobody is listening to would be\n // writing into the void, and a `drain` still awaiting a reconnect has to\n // be let go or it holds a timer open past the teardown.\n outbox.length = 0;\n const waiting = openWaiters;\n openWaiters = [];\n for (const waiter of waiting) waiter();\n if (debounce) clearTimeout(debounce);\n if (reopen) clearTimeout(reopen);\n if (watch) clearInterval(watch);\n debounce = reopen = null;\n watch = null;\n // Removed, not left. These are on `document` and on the window, both of\n // which outlive this connection, so a page that connects and disconnects\n // -- a client-side route change, a React effect re-running -- would\n // otherwise accumulate one set per connection and push through a closure\n // whose stream is gone.\n try {\n stopFocus?.();\n } catch (err) {\n onError(err);\n }\n stopFocus = null;\n try {\n source?.close();\n } catch (err) {\n onError(err);\n }\n source = null;\n },\n };\n}\n\n/**\n * Refuse to publish a driver that has not said what its verbs do.\n *\n * THE GAP THIS CLOSES. The core's gate fires on `kind === \"commit\"`, and the\n * publish check below counts only DECLARED commits. So a verb with no `kind`\n * that changes data went out to an outside agent with no gate in front of it\n * and nobody complaining — the whole guarantee resting on the app having\n * declared its kinds, which is the one thing nothing checked.\n *\n * WHY HERE AND NOT IN `mount()`. In-page leniency is deliberate and\n * documented: `Verb.kind` is optional, an absent one makes no safety claim in\n * either direction, and a half-written app with three undeclared verbs must\n * still mount and still work. Nothing is published by mounting. Publishing to\n * a relay is the act that hands an agent in another process the ability to\n * change data, and it is already the place this library demands an explicit\n * declaration rather than inferring one. So the demand is the same demand, one\n * field over: say what your verbs do before strangers can call them.\n *\n * THE RULE: every verb in a published manifest declares a `kind`, unless the\n * driver declared `approve: \"unattended\"`.\n *\n * Total, rather than the narrower rules that were available:\n *\n * \"Only verbs that look like they change data.\" There is no such predicate.\n * It would have to be a guess from the name — `delete-*`, `set-*` — which is\n * the exact inference the controls layer refuses to make, for the exact\n * reason: a near miss is how `set-view` gets gated and `finalize` does not.\n * A rule that is wrong in both directions teaches an author to distrust it.\n *\n * \"Only when no approver was declared at all.\" This is the tempting one and\n * it is unsound. A declared hook does NOT cover an undeclared verb: the core\n * asks only about `kind === \"commit\"`, so a driver with a perfectly good\n * approval hook and one silent verb publishes that verb ungated. The narrow\n * rule would accept precisely the configuration that is unsafe. Which is\n * also why a `hook` policy does not satisfy this check.\n *\n * \"Warn instead of throw.\" A warning on publish is a warning the author of\n * the app is not reading, because the app works. The precedent in PROTOCOL.md\n * is a refusal to start, and that is what a configuration which must not be\n * reachable by accident looks like.\n *\n * WHY `\"unattended\"` SATISFIES IT. Because it is the same claim, said louder.\n * A driver declaring `\"unattended\"` runs its declared commits with nobody in\n * front of them; a silent verb on that driver is treated no differently from a\n * verb that declared `commit`, so there is nothing left for this check to\n * protect. Refusing it anyway would be demanding paperwork after the risk has\n * already been accepted out loud — and it would leave an author who really does\n * run unattended with no way to connect at all, which is how a safety check\n * gets deleted rather than satisfied. `\"unattended\"` is the typed opt-out the\n * core already defines for this exact decision; this reuses it rather than\n * inventing a second one.\n */\n/**\n * What the APP said at `mount()`, which is the only thing either check below\n * accepts as a declaration.\n *\n * Not `policy`, which is who is asked right now and can be `adopted` — a\n * dialog installed in the page after mount, by `mountWidget` in the ordinary\n * case. That is a real gate while the panel is mounted and it is not a\n * sentence anybody wrote in the app: it is gone when the panel unmounts, and\n * it would make publishing a driver to the outside depend on whether a chat\n * panel happened to be mounted first. The whole argument for these checks is\n * three deliberate acts, so they read the declaration and nothing else.\n *\n * `declared` is absent on a hand-written `approval` from before it existed, and\n * then `policy` IS the declaration — that driver has no `adopt` and nothing can\n * have moved it. See `Driver.approval`.\n */\nfunction declaredPolicy(driver: Driver): \"none\" | \"hook\" | \"unattended\" | \"adopted\" {\n return driver.approval?.declared ?? driver.approval?.policy ?? \"none\";\n}\n\nfunction requireDeclaredKinds(driver: Driver): void {\n if (declaredPolicy(driver) === \"unattended\") return;\n const manifest = driver.manifest();\n const silent = manifest.verbs.filter((v) => v.kind === undefined).map((v) => v.name);\n if (silent.length === 0) return;\n throw new Error(\n `driverkit: refusing to connect \\`${manifest.app}\\` to a relay. ` +\n `${silent.length} of its ${manifest.verbs.length} verb(s) declare no \\`kind\\` — ` +\n `${silent.slice(0, 6).join(\", \")}${silent.length > 6 ? \", …\" : \"\"} — so the core's ` +\n `approval gate, which fires on \\`kind: \"commit\"\\`, cannot see them. A verb that changes ` +\n `data and never said so is published to an agent in another process with nothing in ` +\n `front of it. In-page this is allowed on purpose (an absent \\`kind\\` makes no claim); ` +\n `publishing is where the claim has to be made. Pass ONE of these: ` +\n `\\`kind: \"read\" | \"describe\" | \"commit\"\\` on each verb above — the honest answer, and it ` +\n `is also what tells an agent which calls are free to try; or \\`approve: \"unattended\"\\` to ` +\n `\\`mount()\\`, which says out loud that commits on this driver run with nobody watching ` +\n `and takes every verb off this list. See Verb.kind and MountOptions.approve.`,\n );\n}\n\n/**\n * Refuse to publish a driver whose commits nobody has said who approves.\n *\n * THE GAP THIS CLOSES. The confirmation used to live in the agent loop's\n * `onBeforeCommit`, which `mountWidget` defaults on, so the in-page panel\n * asked a person and an agent arriving over this stream called\n * `accept-selected` and it simply ran. A live tab was driven from a shell and\n * 425 rows could have been committed with nothing in the way. The gate now\n * lives in `mount()`'s `call`, where both paths converge — but a gate the app\n * never installed is still no gate, so the declaration is required HERE, at\n * the one act that makes the app reachable from outside the page.\n *\n * WHY A THROW. The precedent is PROTOCOL.md's: a relay with remote access\n * turned on and no way to identify callers **refuses to start** rather than\n * serving every connected tab to anyone who asks. Three deliberate acts to\n * publish a relay, and by the same argument three to let an outside agent\n * change data: write a `commit` verb, connect to a relay, and say who\n * approves. The unsafe answer is still available — `approve: \"unattended\"` —\n * and it is now a sentence somebody wrote rather than a field they left out.\n *\n * WHICH VERBS COUNT. Only a `commit` that has not declared `reversible`, which\n * is the same line the widget's dialog draws and for the same reason: an\n * absent `reversible` makes no claim, and a commit that has not said there is\n * a way back is treated as one that has not got one. An app whose every commit\n * declares `reversible` connects exactly as it did before. So does an app with\n * no commit verbs at all, and so does a hand-written driver that declares\n * `approval` itself.\n *\n * AND WHY A PANEL CANNOT SATISFY IT. `mountWidget` installs its dialog as the\n * core's approver (`DriverApproval.adopt`), which makes the driver's live\n * `policy` read `adopted` — a real gate, asked on this stream's calls too. It\n * still does not satisfy this check, and that is deliberate twice over. It is\n * not a declaration: it exists only while that panel is mounted, so a\n * `connect()` that accepted it would publish commits that become ungated when\n * somebody closes the assistant. And it would be ORDER-DEPENDENT — the same\n * app starting or throwing according to whether `connect()` ran before or\n * after `mountWidget` — which is the worst property a startup check can have.\n * So an app that mounts the panel and connects to a relay declares the gate\n * itself, and the documented wiring makes the panel that gate:\n * `approve: (req) => panel.approve(req)`.\n */\nfunction requireApprovalPolicy(driver: Driver): void {\n if (declaredPolicy(driver) !== \"none\") return;\n const exposed = driver\n .manifest()\n .verbs.filter((v) => v.kind === \"commit\" && v.reversible !== true)\n .map((v) => v.name);\n if (exposed.length === 0) return;\n throw new Error(\n `driverkit: refusing to connect \\`${driver.manifest().app}\\` to a relay. It publishes ` +\n `${exposed.length} commit verb(s) that have not declared \\`reversible\\` — ` +\n `${exposed.slice(0, 6).join(\", \")}${exposed.length > 6 ? \", …\" : \"\"} — and \\`mount()\\` was ` +\n `given no \\`approve\\`, so an agent on the other end of this stream would change data with ` +\n `nothing in front of it. Pass ONE of these to \\`mount()\\`: ` +\n `\\`approve: (req) => …\\`, an async hook that asks a person and returns true, false or a ` +\n `reason; or \\`approve: \"unattended\"\\`, which says out loud that commits here run with ` +\n `nobody watching. Declaring \\`reversible: true\\` on the commits the app really can undo ` +\n `also takes them off this list. See MountOptions.approve.`,\n );\n}\n\n/**\n * The remembered tab id, or a fresh one.\n *\n * `sessionStorage`, not `localStorage`: the id names one open tab, and\n * `localStorage` is shared across every tab on the origin, so two windows\n * would claim one identity and the second `hello` would steal the first's\n * stream. Keyed by app so two drivers in one page do not collide.\n */\nfunction remembered(\n storage: StorageLike | null,\n app: string | undefined,\n randomUUID: (() => string) | undefined,\n onError: (err: unknown) => void,\n): string {\n const key = `driverkit:tab:${app ?? \"-\"}`;\n try {\n const found = storage?.getItem(key);\n if (found) return found;\n } catch (err) {\n onError(err); // Private-mode storage throws on access rather than returning null.\n }\n const mint =\n randomUUID ??\n (globalThis.crypto?.randomUUID ? () => globalThis.crypto.randomUUID() : null) ??\n // A tab id is a capability, so the fallback still has to be unguessable;\n // it is only here for an insecure origin, where `crypto` is absent.\n (() => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`);\n const id = mint();\n try {\n storage?.setItem(key, id);\n } catch (err) {\n onError(err);\n }\n return id;\n}\n\n/**\n * The remembered anonymous credential, or a fresh one.\n *\n * `sessionStorage`, like the tab id, and for the same reason plus one more: an\n * anonymous session should not outlive the window, and `localStorage` would\n * make one anonymous principal shared by every tab on the origin -- which is\n * the single shared \"anonymous\" bucket this whole design exists to avoid.\n *\n * 256 bits from `crypto.getRandomValues`, because this string is the whole of\n * an anonymous visitor's isolation: anybody who can guess it is that visitor.\n * The fallback for an insecure origin with no `crypto` is deliberately loud\n * rather than silent -- a guessable anonymous secret is worse than none, so a\n * page served over plain HTTP is told rather than quietly weakened.\n */\nfunction anonCredential(\n storage: StorageLike | null,\n app: string | undefined,\n onError: (err: unknown) => void,\n): string {\n const key = `${ANON_KEY}:${app ?? \"-\"}`;\n try {\n const found = storage?.getItem(key);\n if (found) return found;\n } catch (err) {\n onError(err); // Private-mode storage throws on access rather than returning null.\n }\n const random = globalThis.crypto?.getRandomValues;\n if (!random) {\n throw new Error(\n \"driverkit: anonymous credentials need `crypto.getRandomValues`, which this origin \" +\n \"does not have (an insecure origin, most likely). A guessable anonymous secret is \" +\n \"one anonymous visitor able to drive another's screen, so this refuses rather than \" +\n \"falling back to Math.random. Serve the page over HTTPS, or pass `token`.\",\n );\n }\n const bytes = globalThis.crypto.getRandomValues(new Uint8Array(32));\n let base64 = \"\";\n for (const byte of bytes) base64 += String.fromCharCode(byte);\n // base64url, unpadded, matching the relay's `anon1.` reader on both sides.\n const secret = btoa(base64).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n const credential = `anon1.${secret}`;\n try {\n storage?.setItem(key, credential);\n } catch (err) {\n onError(err);\n }\n return credential;\n}\n\nfunction titleFromPage(page: PageLike | undefined): { title?: string } {\n const title = page?.title;\n return title ? { title } : {};\n}\n\n/**\n * The url, path and query AND HASH.\n *\n * THE HASH USED TO BE DROPPED, and for a hash-routed app the hash is the\n * entire route: every tab of such an app reported the same `/` in `/dk/tabs`,\n * so the one field a person is shown to tell two tabs apart told them nothing.\n * It was dropped to keep a fragment out of a listing, which is a real concern\n * about the wrong field -- the token is the capability here, and it travels in\n * a header or a query parameter, never in `location`.\n *\n * Still path-relative and never the origin, which is the part that was right:\n * the relay knows the origin, and a full url in a listing is an inventory of\n * where somebody has been.\n */\nexport function urlFromPage(place: LocationLike | undefined): { url?: string } {\n if (!place?.pathname) return {};\n return { url: `${place.pathname}${place.search ?? \"\"}${place.hash ?? \"\"}` };\n}\n\n/**\n * The three focus states, from the two things a document can be asked.\n *\n * ```\n * visibilityState hasFocus() answer\n * \"hidden\" anything \"hidden\" a background tab\n * \"visible\" true \"focused\" the person is looking at this\n * \"visible\" false \"visible\" active tab, window not frontmost\n * \"visible\" absent \"visible\" an engine with no hasFocus:\n * the strongest honest answer\n * absent absent undefined not a page; say nothing\n * ```\n *\n * `undefined` rather than a guess in the last row, and `TabFocus` says why it\n * must stay distinguishable from `\"hidden\"`: a client that read \"I cannot\n * tell\" as \"not that one\" would quietly become unable to drive a tab whose\n * page does not report.\n *\n * `hasFocus()` is called in a `try`, because this runs on a timer in a page\n * that may be mid-teardown and a throwing getter must not take the push with\n * it. A throw is read as \"cannot tell\", never as focused.\n */\nexport function focusOf(page: PageLike | undefined): TabFocus | undefined {\n if (!page) return undefined;\n const visibility = page.visibilityState;\n const asks = typeof page.hasFocus === \"function\";\n if (visibility === undefined && !asks) return undefined;\n // Anything that is not the string `\"visible\"` is treated as hidden. The spec\n // has two values and has had others (\"prerender\", \"unloaded\"); none of them\n // is a tab a person is looking at, and a new one must not read as focused.\n if (visibility !== undefined && visibility !== \"visible\") return \"hidden\";\n if (!asks) return \"visible\";\n let focused: boolean | undefined;\n try {\n focused = page.hasFocus!();\n } catch {\n focused = undefined;\n }\n if (focused === true) return \"focused\";\n if (focused === false) return \"visible\";\n return visibility === \"visible\" ? \"visible\" : undefined;\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* driverkit/browser — the cross-tab commit channel.
|
|
3
|
+
*
|
|
4
|
+
* One function, and it is twenty lines over a browser primitive. What it is
|
|
5
|
+
* FOR is the interesting part, and the argument is on `ElsewhereChannel` in
|
|
6
|
+
* core: two tabs of one app over one backend, an agent commits in tab A, and
|
|
7
|
+
* tab B goes on reporting stale rows at an unmoved `rev` — so B's `stale`
|
|
8
|
+
* check passes, B's plan token verifies, and the staleness machinery passes in
|
|
9
|
+
* exactly the situation it exists to catch.
|
|
10
|
+
*
|
|
11
|
+
* WHY `BroadcastChannel` AND NOT THE RELAY. The relay sees both tabs and knows
|
|
12
|
+
* they belong to one principal, so it looks like the natural place. It is not,
|
|
13
|
+
* for two reasons that are both about what a relay is. It is a dumb pipe that
|
|
14
|
+
* grants no authority and knows nothing about verbs — to decide that a call
|
|
15
|
+
* was a commit it would have to read `kind` out of a manifest, which makes it
|
|
16
|
+
* a second place that decides what a commit is, and the first thing to drift.
|
|
17
|
+
* And it cannot help the case that needs help most: an app driven by its own
|
|
18
|
+
* in-page panel has no relay at all, and that configuration is the library's
|
|
19
|
+
* own worked example. `BroadcastChannel` is same-origin, server-free, and
|
|
20
|
+
* reaches exactly the tabs that mounted driverkit — which is precisely the
|
|
21
|
+
* hazard, since a tab with no driver has no `rev` to be wrong about.
|
|
22
|
+
*
|
|
23
|
+
* WHAT IT IS NOT. It is not replication and it is not invalidation. Nothing on
|
|
24
|
+
* this channel carries a row, a count or a user; see `ElsewhereNotice`. An app
|
|
25
|
+
* that wants tab B to be CORRECT rather than merely honest listens on the same
|
|
26
|
+
* channel itself and refetches — and then `rev` moves, the notice clears, and
|
|
27
|
+
* none of the core's checks ever fire. That app is the destination. This is
|
|
28
|
+
* what keeps the gap visible on the way there.
|
|
29
|
+
*/
|
|
30
|
+
import type { ElsewhereChannel } from "../core/index.ts";
|
|
31
|
+
/**
|
|
32
|
+
* The part of `BroadcastChannel` this uses, as a structural type.
|
|
33
|
+
*
|
|
34
|
+
* Narrow for the same reason `EventSourceLike` in `connect.ts` is narrow, and
|
|
35
|
+
* it is a design requirement rather than a testing shim: a cross-tab mechanism
|
|
36
|
+
* that can only be exercised by opening two real tabs is a mechanism whose
|
|
37
|
+
* tests nobody runs. The real `BroadcastChannel` satisfies this and so does a
|
|
38
|
+
* ten-line in-process fake, which is what makes "two drivers sharing a store,
|
|
39
|
+
* a commit through one, and an assertion about what the other now reports"
|
|
40
|
+
* an ordinary unit test.
|
|
41
|
+
*/
|
|
42
|
+
export interface BroadcastChannelLike {
|
|
43
|
+
postMessage(data: unknown): void;
|
|
44
|
+
addEventListener(type: "message", listener: (event: {
|
|
45
|
+
data?: unknown;
|
|
46
|
+
}) => void): void;
|
|
47
|
+
removeEventListener?(type: "message", listener: (event: {
|
|
48
|
+
data?: unknown;
|
|
49
|
+
}) => void): void;
|
|
50
|
+
close(): void;
|
|
51
|
+
}
|
|
52
|
+
export interface BroadcastChannelCtor {
|
|
53
|
+
new (name: string): BroadcastChannelLike;
|
|
54
|
+
}
|
|
55
|
+
export interface BroadcastElsewhereOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The channel name. Defaults to `driverkit:elsewhere`.
|
|
58
|
+
*
|
|
59
|
+
* PASS ONE PER APP if two different driverkit apps are served from one
|
|
60
|
+
* origin. They would otherwise share a channel, and a commit in the admin
|
|
61
|
+
* console would mark the customer portal's tabs behind — true of nothing,
|
|
62
|
+
* and it would refuse commits there until that tab's own `rev` moved.
|
|
63
|
+
*/
|
|
64
|
+
name?: string;
|
|
65
|
+
/** The constructor, defaulting to the global. Injected in tests, and the
|
|
66
|
+
* reason `BroadcastChannelLike` is as narrow as it is. */
|
|
67
|
+
BroadcastChannel?: BroadcastChannelCtor;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* An `ElsewhereChannel` over `BroadcastChannel`. Pass it to `mount()`.
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* const driver = mount({ app: "CRM", verbs, visible, elsewhere: broadcastElsewhere() });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* THROWS rather than returning a channel that does nothing when there is no
|
|
77
|
+
* `BroadcastChannel` — the same rule as `driverkit/relay` having no browser
|
|
78
|
+
* shim, and for the same reason stated there: "a `createRelay` that silently
|
|
79
|
+
* did nothing would be worse than a build error". A no-op here would be worse
|
|
80
|
+
* still, because the app would believe it had a cross-tab check and the whole
|
|
81
|
+
* point of the check is that the failure it guards is silent.
|
|
82
|
+
*
|
|
83
|
+
* Supported everywhere that matters (Chrome 54, Firefox 38, Safari 15.4). An
|
|
84
|
+
* app that must run below Safari 15.4 should pass its own channel over
|
|
85
|
+
* whatever it already has — a websocket, a service worker, `localStorage`
|
|
86
|
+
* events — rather than get a quiet nothing from here.
|
|
87
|
+
*/
|
|
88
|
+
export declare function broadcastElsewhere(options?: BroadcastElsewhereOptions): ElsewhereChannel;
|
|
89
|
+
//# sourceMappingURL=elsewhere.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elsewhere.d.ts","sourceRoot":"","sources":["../../src/browser/elsewhere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IACvF,mBAAmB,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3F,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAAC;CAC1C;AAED,MAAM,WAAW,yBAAyB;IACxC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;+DAC2D;IAC3D,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,yBAA8B,GAAG,gBAAgB,CA4C5F"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* driverkit/browser — the cross-tab commit channel.
|
|
3
|
+
*
|
|
4
|
+
* One function, and it is twenty lines over a browser primitive. What it is
|
|
5
|
+
* FOR is the interesting part, and the argument is on `ElsewhereChannel` in
|
|
6
|
+
* core: two tabs of one app over one backend, an agent commits in tab A, and
|
|
7
|
+
* tab B goes on reporting stale rows at an unmoved `rev` — so B's `stale`
|
|
8
|
+
* check passes, B's plan token verifies, and the staleness machinery passes in
|
|
9
|
+
* exactly the situation it exists to catch.
|
|
10
|
+
*
|
|
11
|
+
* WHY `BroadcastChannel` AND NOT THE RELAY. The relay sees both tabs and knows
|
|
12
|
+
* they belong to one principal, so it looks like the natural place. It is not,
|
|
13
|
+
* for two reasons that are both about what a relay is. It is a dumb pipe that
|
|
14
|
+
* grants no authority and knows nothing about verbs — to decide that a call
|
|
15
|
+
* was a commit it would have to read `kind` out of a manifest, which makes it
|
|
16
|
+
* a second place that decides what a commit is, and the first thing to drift.
|
|
17
|
+
* And it cannot help the case that needs help most: an app driven by its own
|
|
18
|
+
* in-page panel has no relay at all, and that configuration is the library's
|
|
19
|
+
* own worked example. `BroadcastChannel` is same-origin, server-free, and
|
|
20
|
+
* reaches exactly the tabs that mounted driverkit — which is precisely the
|
|
21
|
+
* hazard, since a tab with no driver has no `rev` to be wrong about.
|
|
22
|
+
*
|
|
23
|
+
* WHAT IT IS NOT. It is not replication and it is not invalidation. Nothing on
|
|
24
|
+
* this channel carries a row, a count or a user; see `ElsewhereNotice`. An app
|
|
25
|
+
* that wants tab B to be CORRECT rather than merely honest listens on the same
|
|
26
|
+
* channel itself and refetches — and then `rev` moves, the notice clears, and
|
|
27
|
+
* none of the core's checks ever fire. That app is the destination. This is
|
|
28
|
+
* what keeps the gap visible on the way there.
|
|
29
|
+
*/
|
|
30
|
+
const DEFAULT_NAME = "driverkit:elsewhere";
|
|
31
|
+
/**
|
|
32
|
+
* An `ElsewhereChannel` over `BroadcastChannel`. Pass it to `mount()`.
|
|
33
|
+
*
|
|
34
|
+
* ```js
|
|
35
|
+
* const driver = mount({ app: "CRM", verbs, visible, elsewhere: broadcastElsewhere() });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* THROWS rather than returning a channel that does nothing when there is no
|
|
39
|
+
* `BroadcastChannel` — the same rule as `driverkit/relay` having no browser
|
|
40
|
+
* shim, and for the same reason stated there: "a `createRelay` that silently
|
|
41
|
+
* did nothing would be worse than a build error". A no-op here would be worse
|
|
42
|
+
* still, because the app would believe it had a cross-tab check and the whole
|
|
43
|
+
* point of the check is that the failure it guards is silent.
|
|
44
|
+
*
|
|
45
|
+
* Supported everywhere that matters (Chrome 54, Firefox 38, Safari 15.4). An
|
|
46
|
+
* app that must run below Safari 15.4 should pass its own channel over
|
|
47
|
+
* whatever it already has — a websocket, a service worker, `localStorage`
|
|
48
|
+
* events — rather than get a quiet nothing from here.
|
|
49
|
+
*/
|
|
50
|
+
export function broadcastElsewhere(options = {}) {
|
|
51
|
+
const Ctor = options.BroadcastChannel ??
|
|
52
|
+
globalThis.BroadcastChannel;
|
|
53
|
+
if (!Ctor) {
|
|
54
|
+
throw new Error("driverkit: no BroadcastChannel. Pass options.BroadcastChannel, or give `mount()` an " +
|
|
55
|
+
"`elsewhere` channel over a transport this environment has. A channel that silently " +
|
|
56
|
+
"did nothing would leave the app believing it had a cross-tab check.");
|
|
57
|
+
}
|
|
58
|
+
const bus = new Ctor(options.name ?? DEFAULT_NAME);
|
|
59
|
+
return {
|
|
60
|
+
post(notice) {
|
|
61
|
+
// Sent as the plain object. `BroadcastChannel` structured-clones it and
|
|
62
|
+
// does NOT deliver it to the sender, so a driver's own notice never
|
|
63
|
+
// comes back — but the core checks `from` anyway, because a channel
|
|
64
|
+
// written over a websocket does echo and the core must behave the same
|
|
65
|
+
// over either.
|
|
66
|
+
bus.postMessage({ ...notice });
|
|
67
|
+
},
|
|
68
|
+
listen(heard) {
|
|
69
|
+
const onMessage = (event) => {
|
|
70
|
+
const data = event?.data;
|
|
71
|
+
// Shape-checked here as well as in the core. Anything else on this
|
|
72
|
+
// channel name — another library, a newer driverkit, a page's own
|
|
73
|
+
// messages — is dropped rather than passed on as a notice, because a
|
|
74
|
+
// notice with no `verb` would put the word `undefined` into a refusal
|
|
75
|
+
// a model reads.
|
|
76
|
+
if (!data || typeof data.verb !== "string" || typeof data.from !== "string")
|
|
77
|
+
return;
|
|
78
|
+
heard({ verb: data.verb, from: data.from });
|
|
79
|
+
};
|
|
80
|
+
bus.addEventListener("message", onMessage);
|
|
81
|
+
return () => {
|
|
82
|
+
bus.removeEventListener?.("message", onMessage);
|
|
83
|
+
// Closed on unmount, so a hot-reloading dev server does not leave one
|
|
84
|
+
// open channel per save. A `BroadcastChannel` is per-page, not
|
|
85
|
+
// per-driver, but this function created it, so this function owns it.
|
|
86
|
+
bus.close();
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=elsewhere.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elsewhere.js","sourceRoot":"","sources":["../../src/browser/elsewhere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAyCH,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAqC,EAAE;IACxE,MAAM,IAAI,GACR,OAAO,CAAC,gBAAgB;QACvB,UAA0D,CAAC,gBAAgB,CAAC;IAC/E,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,sFAAsF;YACpF,qFAAqF;YACrF,qEAAqE,CACxE,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC,CAAC;IAEnD,OAAO;QACL,IAAI,CAAC,MAAuB;YAC1B,wEAAwE;YACxE,oEAAoE;YACpE,oEAAoE;YACpE,uEAAuE;YACvE,eAAe;YACf,GAAG,CAAC,WAAW,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,CAAC,KAAwC;YAC7C,MAAM,SAAS,GAAG,CAAC,KAAyB,EAAQ,EAAE;gBACpD,MAAM,IAAI,GAAG,KAAK,EAAE,IAA4C,CAAC;gBACjE,mEAAmE;gBACnE,kEAAkE;gBAClE,qEAAqE;gBACrE,sEAAsE;gBACtE,iBAAiB;gBACjB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;oBAAE,OAAO;gBACpF,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9C,CAAC,CAAC;YACF,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAC3C,OAAO,GAAG,EAAE;gBACV,GAAG,CAAC,mBAAmB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBAChD,sEAAsE;gBACtE,+DAA+D;gBAC/D,sEAAsE;gBACtE,GAAG,CAAC,KAAK,EAAE,CAAC;YACd,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * driverkit/browser — the cross-tab commit channel.\n *\n * One function, and it is twenty lines over a browser primitive. What it is\n * FOR is the interesting part, and the argument is on `ElsewhereChannel` in\n * core: two tabs of one app over one backend, an agent commits in tab A, and\n * tab B goes on reporting stale rows at an unmoved `rev` — so B's `stale`\n * check passes, B's plan token verifies, and the staleness machinery passes in\n * exactly the situation it exists to catch.\n *\n * WHY `BroadcastChannel` AND NOT THE RELAY. The relay sees both tabs and knows\n * they belong to one principal, so it looks like the natural place. It is not,\n * for two reasons that are both about what a relay is. It is a dumb pipe that\n * grants no authority and knows nothing about verbs — to decide that a call\n * was a commit it would have to read `kind` out of a manifest, which makes it\n * a second place that decides what a commit is, and the first thing to drift.\n * And it cannot help the case that needs help most: an app driven by its own\n * in-page panel has no relay at all, and that configuration is the library's\n * own worked example. `BroadcastChannel` is same-origin, server-free, and\n * reaches exactly the tabs that mounted driverkit — which is precisely the\n * hazard, since a tab with no driver has no `rev` to be wrong about.\n *\n * WHAT IT IS NOT. It is not replication and it is not invalidation. Nothing on\n * this channel carries a row, a count or a user; see `ElsewhereNotice`. An app\n * that wants tab B to be CORRECT rather than merely honest listens on the same\n * channel itself and refetches — and then `rev` moves, the notice clears, and\n * none of the core's checks ever fire. That app is the destination. This is\n * what keeps the gap visible on the way there.\n */\n\nimport type { ElsewhereChannel, ElsewhereNotice } from \"../core/index.ts\";\n\n/**\n * The part of `BroadcastChannel` this uses, as a structural type.\n *\n * Narrow for the same reason `EventSourceLike` in `connect.ts` is narrow, and\n * it is a design requirement rather than a testing shim: a cross-tab mechanism\n * that can only be exercised by opening two real tabs is a mechanism whose\n * tests nobody runs. The real `BroadcastChannel` satisfies this and so does a\n * ten-line in-process fake, which is what makes \"two drivers sharing a store,\n * a commit through one, and an assertion about what the other now reports\"\n * an ordinary unit test.\n */\nexport interface BroadcastChannelLike {\n postMessage(data: unknown): void;\n addEventListener(type: \"message\", listener: (event: { data?: unknown }) => void): void;\n removeEventListener?(type: \"message\", listener: (event: { data?: unknown }) => void): void;\n close(): void;\n}\n\nexport interface BroadcastChannelCtor {\n new (name: string): BroadcastChannelLike;\n}\n\nexport interface BroadcastElsewhereOptions {\n /**\n * The channel name. Defaults to `driverkit:elsewhere`.\n *\n * PASS ONE PER APP if two different driverkit apps are served from one\n * origin. They would otherwise share a channel, and a commit in the admin\n * console would mark the customer portal's tabs behind — true of nothing,\n * and it would refuse commits there until that tab's own `rev` moved.\n */\n name?: string;\n /** The constructor, defaulting to the global. Injected in tests, and the\n * reason `BroadcastChannelLike` is as narrow as it is. */\n BroadcastChannel?: BroadcastChannelCtor;\n}\n\nconst DEFAULT_NAME = \"driverkit:elsewhere\";\n\n/**\n * An `ElsewhereChannel` over `BroadcastChannel`. Pass it to `mount()`.\n *\n * ```js\n * const driver = mount({ app: \"CRM\", verbs, visible, elsewhere: broadcastElsewhere() });\n * ```\n *\n * THROWS rather than returning a channel that does nothing when there is no\n * `BroadcastChannel` — the same rule as `driverkit/relay` having no browser\n * shim, and for the same reason stated there: \"a `createRelay` that silently\n * did nothing would be worse than a build error\". A no-op here would be worse\n * still, because the app would believe it had a cross-tab check and the whole\n * point of the check is that the failure it guards is silent.\n *\n * Supported everywhere that matters (Chrome 54, Firefox 38, Safari 15.4). An\n * app that must run below Safari 15.4 should pass its own channel over\n * whatever it already has — a websocket, a service worker, `localStorage`\n * events — rather than get a quiet nothing from here.\n */\nexport function broadcastElsewhere(options: BroadcastElsewhereOptions = {}): ElsewhereChannel {\n const Ctor =\n options.BroadcastChannel ??\n (globalThis as { BroadcastChannel?: BroadcastChannelCtor }).BroadcastChannel;\n if (!Ctor) {\n throw new Error(\n \"driverkit: no BroadcastChannel. Pass options.BroadcastChannel, or give `mount()` an \" +\n \"`elsewhere` channel over a transport this environment has. A channel that silently \" +\n \"did nothing would leave the app believing it had a cross-tab check.\",\n );\n }\n\n const bus = new Ctor(options.name ?? DEFAULT_NAME);\n\n return {\n post(notice: ElsewhereNotice) {\n // Sent as the plain object. `BroadcastChannel` structured-clones it and\n // does NOT deliver it to the sender, so a driver's own notice never\n // comes back — but the core checks `from` anyway, because a channel\n // written over a websocket does echo and the core must behave the same\n // over either.\n bus.postMessage({ ...notice });\n },\n listen(heard: (notice: ElsewhereNotice) => void) {\n const onMessage = (event: { data?: unknown }): void => {\n const data = event?.data as Partial<ElsewhereNotice> | undefined;\n // Shape-checked here as well as in the core. Anything else on this\n // channel name — another library, a newer driverkit, a page's own\n // messages — is dropped rather than passed on as a notice, because a\n // notice with no `verb` would put the word `undefined` into a refusal\n // a model reads.\n if (!data || typeof data.verb !== \"string\" || typeof data.from !== \"string\") return;\n heard({ verb: data.verb, from: data.from });\n };\n bus.addEventListener(\"message\", onMessage);\n return () => {\n bus.removeEventListener?.(\"message\", onMessage);\n // Closed on unmount, so a hot-reloading dev server does not leave one\n // open channel per save. A `BroadcastChannel` is per-page, not\n // per-driver, but this function created it, so this function owns it.\n bus.close();\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire frames, as PROTOCOL.md defines them.
|
|
3
|
+
*
|
|
4
|
+
* Declared here as well as in `driverkit/relay` on purpose: see the note at
|
|
5
|
+
* the top of that file. The protocol document is the contract between the two
|
|
6
|
+
* sides; a shared module would quietly become the contract instead, and then
|
|
7
|
+
* the Rust relay and the hand-written page loop PROTOCOL.md promises are
|
|
8
|
+
* possible would be second-class.
|
|
9
|
+
*/
|
|
10
|
+
import type { Driver, Manifest, Result, Scalar, Snapshot, TabFocus } from "../core/index.ts";
|
|
11
|
+
export type { Driver, Manifest, Result, Scalar, Snapshot, TabFocus };
|
|
12
|
+
export interface HelloFrame {
|
|
13
|
+
t: "hello";
|
|
14
|
+
tab: string;
|
|
15
|
+
app?: string;
|
|
16
|
+
manifest?: Manifest;
|
|
17
|
+
snapshot?: Snapshot;
|
|
18
|
+
title?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
/** Where this tab stands in the person's attention; see `TabFocus`. In
|
|
21
|
+
* `hello` as well as in `snapshot` because `hello` is the only frame a tab
|
|
22
|
+
* that is opened and left alone ever sends. */
|
|
23
|
+
focus?: TabFocus;
|
|
24
|
+
}
|
|
25
|
+
export interface ResultFrame {
|
|
26
|
+
t: "result";
|
|
27
|
+
id: string;
|
|
28
|
+
result: Result;
|
|
29
|
+
/**
|
|
30
|
+
* How long the TAB's own work took, in whole milliseconds, with any person's
|
|
31
|
+
* time already taken out of it. Absent means the tab did not measure, which
|
|
32
|
+
* is UNKNOWN and not zero; see PROTOCOL.md.
|
|
33
|
+
*
|
|
34
|
+
* On the frame and NOT inside `result`, which is the one placement decision
|
|
35
|
+
* here that matters. `result` is what the APP returned, so a duration in
|
|
36
|
+
* there would be an app's claim about its own speed; this is the measurement
|
|
37
|
+
* the page-side harness takes around the single call it makes into the
|
|
38
|
+
* driver, which is the same bracket `drive` puts around `driver.call()` and
|
|
39
|
+
* is the only reason either number means anything. See `renderDuration`.
|
|
40
|
+
*/
|
|
41
|
+
tookMs?: number;
|
|
42
|
+
/** How much of the wall clock was a PERSON, as the amount already subtracted
|
|
43
|
+
* from `tookMs`. Here so the gap between an agent's round trip and `tookMs`
|
|
44
|
+
* is accounted for rather than guessed at; never added back by a client.
|
|
45
|
+
* See `DriveOptions.waited`, which is the same quantity in the in-page loop. */
|
|
46
|
+
waitedMs?: number;
|
|
47
|
+
/** Which tab is answering. PROTOCOL.md's frame listing omits this; the page
|
|
48
|
+
* sends it in the body AND as `?tab=` so a relay reading either one works. */
|
|
49
|
+
tab?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface SnapshotFrame {
|
|
52
|
+
t: "snapshot";
|
|
53
|
+
snapshot: Snapshot;
|
|
54
|
+
tab?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The tab's url as it is NOW.
|
|
57
|
+
*
|
|
58
|
+
* Here as well as in `hello` because `hello` is sent once per stream and a
|
|
59
|
+
* single-page app navigates without reconnecting -- so `TabInfo.url`, which
|
|
60
|
+
* came from `hello` alone, was stale from the first client-side route change
|
|
61
|
+
* and had no way back. A push is already going out whenever the page moves.
|
|
62
|
+
*/
|
|
63
|
+
url?: string;
|
|
64
|
+
/** The tab's focus as it is NOW. A change of focus is pushed on this frame
|
|
65
|
+
* rather than on a frame of its own: the protocol gains a field, and a relay
|
|
66
|
+
* written before it goes on reading the frame it always read. */
|
|
67
|
+
focus?: TabFocus;
|
|
68
|
+
}
|
|
69
|
+
export interface CallFrame {
|
|
70
|
+
t: "call";
|
|
71
|
+
id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
args?: Record<string, Scalar>;
|
|
74
|
+
rev?: number;
|
|
75
|
+
/** The agent's claim about which screen it read, handed to the driver as
|
|
76
|
+
* `CallOptions.screen` and checked there before `rev`. */
|
|
77
|
+
screen?: string;
|
|
78
|
+
/** The plan token the agent is presenting, handed to the driver as
|
|
79
|
+
* `CallOptions.plan` and checked there before `rev`. Carried here because
|
|
80
|
+
* this hop is where it would otherwise be dropped — which would leave the
|
|
81
|
+
* field working in-page and silently doing nothing over the relay, and a
|
|
82
|
+
* commit guarantee that holds on one of two paths is not a guarantee. */
|
|
83
|
+
plan?: string;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../../src/browser/frames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7F,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAErE,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,OAAO,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;oDAEgD;IAChD,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,QAAQ,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;qFAGiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;mFAC+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,UAAU,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;sEAEkE;IAClE,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;+DAC2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;8EAI0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire frames, as PROTOCOL.md defines them.
|
|
3
|
+
*
|
|
4
|
+
* Declared here as well as in `driverkit/relay` on purpose: see the note at
|
|
5
|
+
* the top of that file. The protocol document is the contract between the two
|
|
6
|
+
* sides; a shared module would quietly become the contract instead, and then
|
|
7
|
+
* the Rust relay and the hand-written page loop PROTOCOL.md promises are
|
|
8
|
+
* possible would be second-class.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=frames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.js","sourceRoot":"","sources":["../../src/browser/frames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * The wire frames, as PROTOCOL.md defines them.\n *\n * Declared here as well as in `driverkit/relay` on purpose: see the note at\n * the top of that file. The protocol document is the contract between the two\n * sides; a shared module would quietly become the contract instead, and then\n * the Rust relay and the hand-written page loop PROTOCOL.md promises are\n * possible would be second-class.\n */\n\nimport type { Driver, Manifest, Result, Scalar, Snapshot, TabFocus } from \"../core/index.ts\";\n\nexport type { Driver, Manifest, Result, Scalar, Snapshot, TabFocus };\n\nexport interface HelloFrame {\n t: \"hello\";\n tab: string;\n app?: string;\n manifest?: Manifest;\n snapshot?: Snapshot;\n title?: string;\n url?: string;\n /** Where this tab stands in the person's attention; see `TabFocus`. In\n * `hello` as well as in `snapshot` because `hello` is the only frame a tab\n * that is opened and left alone ever sends. */\n focus?: TabFocus;\n}\n\nexport interface ResultFrame {\n t: \"result\";\n id: string;\n result: Result;\n /**\n * How long the TAB's own work took, in whole milliseconds, with any person's\n * time already taken out of it. Absent means the tab did not measure, which\n * is UNKNOWN and not zero; see PROTOCOL.md.\n *\n * On the frame and NOT inside `result`, which is the one placement decision\n * here that matters. `result` is what the APP returned, so a duration in\n * there would be an app's claim about its own speed; this is the measurement\n * the page-side harness takes around the single call it makes into the\n * driver, which is the same bracket `drive` puts around `driver.call()` and\n * is the only reason either number means anything. See `renderDuration`.\n */\n tookMs?: number;\n /** How much of the wall clock was a PERSON, as the amount already subtracted\n * from `tookMs`. Here so the gap between an agent's round trip and `tookMs`\n * is accounted for rather than guessed at; never added back by a client.\n * See `DriveOptions.waited`, which is the same quantity in the in-page loop. */\n waitedMs?: number;\n /** Which tab is answering. PROTOCOL.md's frame listing omits this; the page\n * sends it in the body AND as `?tab=` so a relay reading either one works. */\n tab?: string;\n}\n\nexport interface SnapshotFrame {\n t: \"snapshot\";\n snapshot: Snapshot;\n tab?: string;\n /**\n * The tab's url as it is NOW.\n *\n * Here as well as in `hello` because `hello` is sent once per stream and a\n * single-page app navigates without reconnecting -- so `TabInfo.url`, which\n * came from `hello` alone, was stale from the first client-side route change\n * and had no way back. A push is already going out whenever the page moves.\n */\n url?: string;\n /** The tab's focus as it is NOW. A change of focus is pushed on this frame\n * rather than on a frame of its own: the protocol gains a field, and a relay\n * written before it goes on reading the frame it always read. */\n focus?: TabFocus;\n}\n\nexport interface CallFrame {\n t: \"call\";\n id: string;\n name: string;\n args?: Record<string, Scalar>;\n rev?: number;\n /** The agent's claim about which screen it read, handed to the driver as\n * `CallOptions.screen` and checked there before `rev`. */\n screen?: string;\n /** The plan token the agent is presenting, handed to the driver as\n * `CallOptions.plan` and checked there before `rev`. Carried here because\n * this hop is where it would otherwise be dropped — which would leave the\n * field working in-page and silently doing nothing over the relay, and a\n * commit guarantee that holds on one of two paths is not a guarantee. */\n plan?: string;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { connect } from "./connect.ts";
|
|
2
|
+
export type { Connection, ConnectOptions, EventSourceCtor, EventSourceLike, FetchLike, FocusEventsLike, LocationLike, PageLike, ResponseLike, StorageLike, } from "./connect.ts";
|
|
3
|
+
export { broadcastElsewhere } from "./elsewhere.ts";
|
|
4
|
+
export type { BroadcastChannelCtor, BroadcastChannelLike, BroadcastElsewhereOptions, } from "./elsewhere.ts";
|
|
5
|
+
export type { CallFrame, HelloFrame, ResultFrame, SnapshotFrame } from "./frames.ts";
|
|
6
|
+
export { budgetKey, localBudgetStore } from "./budget.ts";
|
|
7
|
+
export type { LocalBudgetStore, LocalBudgetStoreOptions } from "./budget.ts";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EACV,UAAU,EAAE,cAAc,EAAE,eAAe,EAC3C,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EACnE,YAAY,EAAE,WAAW,GAC1B,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EACV,oBAAoB,EAAE,oBAAoB,EAAE,yBAAyB,GACtE,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGrF,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { connect } from "./connect.js";
|
|
2
|
+
// The cross-tab commit channel, and the only `ElsewhereChannel` the library
|
|
3
|
+
// ships. See `elsewhere.ts` for why it is a `BroadcastChannel` and not the
|
|
4
|
+
// relay.
|
|
5
|
+
export { broadcastElsewhere } from "./elsewhere.js";
|
|
6
|
+
// Keeping a spend ceiling across a page load. See `budget.ts`: without it an
|
|
7
|
+
// agent that can navigate can refresh its way past `MountOptions.budget`.
|
|
8
|
+
export { budgetKey, localBudgetStore } from "./budget.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAMvC,4EAA4E;AAC5E,2EAA2E;AAC3E,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKpD,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { connect } from \"./connect.ts\";\nexport type {\n Connection, ConnectOptions, EventSourceCtor,\n EventSourceLike, FetchLike, FocusEventsLike, LocationLike, PageLike,\n ResponseLike, StorageLike,\n} from \"./connect.ts\";\n// The cross-tab commit channel, and the only `ElsewhereChannel` the library\n// ships. See `elsewhere.ts` for why it is a `BroadcastChannel` and not the\n// relay.\nexport { broadcastElsewhere } from \"./elsewhere.ts\";\nexport type {\n BroadcastChannelCtor, BroadcastChannelLike, BroadcastElsewhereOptions,\n} from \"./elsewhere.ts\";\nexport type { CallFrame, HelloFrame, ResultFrame, SnapshotFrame } from \"./frames.ts\";\n// Keeping a spend ceiling across a page load. See `budget.ts`: without it an\n// agent that can navigate can refresh its way past `MountOptions.budget`.\nexport { budgetKey, localBudgetStore } from \"./budget.ts\";\nexport type { LocalBudgetStore, LocalBudgetStoreOptions } from \"./budget.ts\";\n"]}
|