driverkit 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTROLS.md +578 -0
- package/REACT.md +477 -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 +144 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/react/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuB/D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAuRnC,MAAM,SAAS,GAAsC;IACnD,sEAAsE;IACtE,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,mEAAmE;IAC3E,WAAW,EAAE,2EAA2E;IACxF,KAAK,EAAE,+EAA+E;IACtF,aAAa,EACX,wFAAwF;QACxF,2DAA2D;IAC7D,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,QAAQ,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,4BAA4B,CAAC;QACtC,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,yBAAyB,KAAK,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC3F,KAAK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EAAE,CAAC;YACpB,IAAI,EAAE,CAAC;QACT,CAAC;QACD,MAAM;QACN,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAC/C,IAAI,EAAE,CAAC;QACT,CAAC;QACD,OAAO;QACP,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI;QACtB,OAAO,EAAE,GAAG,EAAE;YACZ,IAAI,GAAG,KAAK,CAAC;YACb,yEAAyE;YACzE,wEAAwE;YACxE,qEAAqE;YACrE,sEAAsE;YACtE,qEAAqE;YACrE,uEAAuE;YACvE,kEAAkE;YAClE,qEAAqE;YACrE,oEAAoE;YACpE,iCAAiC;YACjC,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;gBAAE,KAAK,EAAE,CAAC;YACrD,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,EAAE,KAAK,EAAE,CAAC;YACjB,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * The React panel's state, with no React in it.\n *\n * WHY THE STATE IS NOT IN REACT. Everything the panel knows — the transcript,\n * the step list, the run's control state, the approval state machine — lives in\n * a plain object with `subscribe`/`getSnapshot`, and the React layer is a\n * `useSyncExternalStore` call over it. Three reasons, in the order they\n * mattered while writing it:\n *\n * 1. **It is the half that has to be tested, and this repository has no\n * React.** The published package depends on nothing and there is no\n * network install here, so a state machine expressed as `useReducer`\n * plus eight `useEffect`s would be a state machine nothing in the suite\n * could drive. The approval receipt — the one behaviour this area exists\n * to get right — is asserted in `test/react.test.ts` against this file,\n * with no renderer involved.\n *\n * 2. **`drive` is not a React citizen.** It is an async loop that fires\n * callbacks from inside awaits, and callbacks that land after an unmount\n * or after a Clear are the normal case rather than the exception. A store\n * can be written once to be correct about that — see `era` — where a\n * component tree would have to be correct about it at every subscription\n * point.\n *\n * 3. **It is what makes the components replaceable.** A host with a design\n * system wants our behaviour and its own markup. If the behaviour is in\n * the components, \"restyle it\" means \"fork it\". Here a host can take\n * `useDriver()` and render none of our components at all, and nothing\n * about the gate, the pacing or the receipt changes.\n *\n * The parts of the vanilla widget's reasoning that still apply are applied\n * here and marked; the ones that do not are listed in `REACT.md` with why.\n */\n\nimport { commas, drive, runControls } from \"../agent/index.ts\";\nimport type {\n CallEvent,\n Clock,\n CommitDecision,\n CommitRequest,\n DriveOptions,\n RunControls,\n RunControlsOptions,\n RunState,\n StopReason,\n Turn,\n} from \"../agent/index.ts\";\nimport type {\n Approval,\n ApprovalRequest,\n BudgetState,\n Driver,\n Scalar,\n Snapshot,\n VerbKind,\n} from \"../core/index.ts\";\n\n/**\n * The selection size past which a commit is confirmed even though the app\n * called it reversible.\n *\n * **Deliberately the same number as `COMMIT_ASK_ABOVE` in\n * `src/widget/widget.ts`, and deliberately not imported from it.** Importing it\n * would make this area's module graph include the vanilla widget's, and\n * therefore its hand-written DOM, its stylesheet, its drag positioner and its\n * `localStorage` access — in a React app's bundle, to read one integer. The\n * whole promise of this entry point is that the two panels are independent, and\n * a constant is not worth breaking it for.\n *\n * Two copies of a number drift, so the drift is a test failure rather than a\n * hope: `test/react.test.ts` pins that these two agree. The reasoning behind\n * the value — why a screenful rather than the thousands where an app's undo\n * actually stops being credible — is written once, over there, and is not\n * restated here so that there is still only one place it can be argued with.\n */\nexport const COMMIT_ASK_ABOVE = 25;\n\n/** How the panel gets a control surface. `runControls` by default; an interface\n * rather than only a factory, exactly as the agent area says. */\nexport type RunControlsFactory = (options: RunControlsOptions) => RunControls;\n\nexport type StepStatus = \"pending\" | \"running\" | \"done\" | \"refused\" | \"skipped\";\n\n/**\n * Where an approval has got to. **One entry moves through these; it is never\n * replaced and never removed.**\n *\n * This is the behaviour the area exists for, so it is worth saying what the\n * states are for rather than only what they are. A gate whose card disappears\n * when you answer it leaves a transcript in which the question and its answer\n * are two unrelated lines, and scrollback is the only place an auditor can\n * stand. So the card becomes its own receipt, in place, and the phases are the\n * phases a reader of that receipt needs distinguished:\n *\n * `asking` the buttons are live and nothing has happened.\n * `allowed` a person said yes and the verb is now running. Also the\n * resting state for a commit that arrived from outside a\n * run, where there is no result event to wait for and\n * claiming \"finished\" would be making it up.\n * `allowed-ok` the verb ran and the app said ok.\n * `allowed-refused` the verb ran and **the app refused it anyway**. A\n * separate phase because \"you approved this\" and \"this\n * happened\" are different facts and a receipt that only\n * recorded the first would be the more flattering of the\n * two. A stale rev, a spent budget and a plan token that\n * no longer matches all land here.\n * `denied` a person said no.\n * `stopped` the run was stopped before the verb ran. Not a denial:\n * nobody refused it.\n * `lapsed` the panel went away with the question still open, so\n * nobody answered. Distinct from `denied` for the same\n * reason the core keeps `timed-out` apart from `declined`.\n */\nexport type ApprovalPhase =\n | \"asking\"\n | \"allowed\"\n | \"allowed-ok\"\n | \"allowed-refused\"\n | \"denied\"\n | \"stopped\"\n | \"lapsed\";\n\n/** Something said: by the person, by the model, or by the panel about itself. */\nexport interface SaidEntry {\n kind: \"you\" | \"assistant\" | \"note\";\n id: string;\n text: string;\n}\n\n/** One call, as three states of one entry. */\nexport interface StepEntry {\n kind: \"step\";\n id: string;\n callId: string;\n verb: string;\n verbKind?: VerbKind;\n args: Record<string, Scalar>;\n /** The verb's `at` selector, straight from the manifest and used by nothing\n * in here. See `onAim` for the seam a host outlines it through. */\n at?: string;\n commit: boolean;\n status: StepStatus;\n /** What happened, as a phrase appended to the row. Absent while pending. */\n outcome?: string;\n /** From a `describe` verb's `Report.count`, when it reported one. */\n count?: number;\n}\n\n/** A standing permission a person installed from a card. See `PanelOptions.grants`. */\nexport interface Grant {\n verb: string;\n /** The rule, in the words that were shown before the click. */\n rule: string;\n /** Allow, or always refuse. Both are rules worth being able to install, and\n * a standing refusal is the one a person reaches for when a model keeps\n * asking about something it is never going to be allowed to do. */\n allow: boolean;\n}\n\n/** A question, and then the receipt it becomes. */\nexport interface ApprovalEntry {\n kind: \"approval\";\n id: string;\n verb: string;\n /** The verb's own `describe` from the manifest — the app's words, not ours. */\n describe: string;\n args: Record<string, Scalar>;\n count?: number;\n reversible: boolean;\n /** Whether the count alone is why this is being asked about. */\n large: boolean;\n phase: ApprovalPhase;\n /**\n * The rule a person would install by pressing \"always\", **in the words it is\n * shown in before the click.** The same string is stored on the `Grant`, so\n * what was agreed to and what was installed cannot differ.\n */\n grantOffer?: string;\n /** The rule that answered this without asking, when one did. */\n via?: string;\n /** A free-text note typed beside the decision. See `decide`. */\n note?: string;\n /** The app's refusal slug, when the approved verb was refused anyway. */\n refused?: string;\n}\n\nexport type Entry = SaidEntry | StepEntry | ApprovalEntry;\n\nexport interface PanelSnapshot {\n entries: readonly Entry[];\n /** A run is in flight. */\n busy: boolean;\n runState: RunState;\n paceMs: number;\n /** Unspent `step()` permits, for a button that wants to show one is owed. */\n permits: number;\n stepMode: boolean;\n confirmCommits: boolean;\n /** What this driver has spent, re-read on every change. Absent when the\n * driver does not account for itself. */\n budget?: BudgetState;\n grants: readonly Grant[];\n /** The open question, if there is one. Also in `entries`, in its place. */\n pending?: ApprovalEntry;\n /** Which conversation this is. Bumped by `clear`. */\n era: number;\n}\n\nexport interface PanelOptions\n extends Pick<DriveOptions, \"think\" | \"instructions\" | \"maxSteps\" | \"refusalLimit\"> {\n /** The first line in the transcript. Omit it for an empty panel. */\n greeting?: string;\n /**\n * Ask before a `commit` the app cannot undo. Default true, as in the vanilla\n * widget and for the same reason: a person watching a panel move their own\n * app should not learn about a thousand accepted rows afterwards.\n */\n confirmCommits?: boolean;\n /** Ask above this selection size even when the commit declared itself\n * reversible. Default `COMMIT_ASK_ABOVE`. */\n commitAskAbove?: number;\n /** Ask before every commit, reversible or not. Default false. */\n confirmEveryCommit?: boolean;\n /**\n * Your own gate for the in-page run, replacing this one. Overrides rather\n * than stacks — see the vanilla widget's `onBeforeCommit`, which this\n * mirrors exactly.\n */\n onBeforeCommit?: DriveOptions[\"onBeforeCommit\"];\n /**\n * Offer \"always allow\" / \"always refuse\" beside the once-only answer.\n * **Default false.**\n *\n * Off by default because a standing permission on a data-changing verb is a\n * larger thing to hand somebody than a button that says yes once, and an\n * app should decide to offer it rather than find that it did. When it is on,\n * two rules hold and both are load-bearing:\n *\n * The rule is shown in full on the card **before** the click, in the same\n * string that is then stored, so nobody installs a rule whose text they\n * have not read.\n *\n * Grants live for this panel and this page load only. Nothing is written\n * to storage, deliberately: a standing approval for a commit that came\n * back after a reload, in a session nobody remembers granting it in, is\n * worse than asking again. `revoke` takes one away sooner, and\n * `PanelSnapshot.grants` is there so a host can render the list — a grant\n * nobody can see is a grant nobody can revoke.\n */\n grants?: boolean;\n /**\n * Offer a free-text note beside the decision. Default false.\n *\n * On a denial the note becomes the hint the model is told, which is a real\n * feature of the gate rather than decoration: `CommitDecision` takes a\n * string, and \"not until finance signs off\" is something a model can act on\n * where \"declined\" is not.\n *\n * **Typing in it never approves anything.** The note is read only when a\n * decision button is pressed, Enter in the field does not submit, and a\n * note with no decision leaves the question exactly as open as it was. A\n * gate that inferred consent from a typed explanation would let the\n * explanation authorize the call.\n */\n notes?: boolean;\n /** Starting pace in ms. Default `WATCHABLE_PACE` via `runControls`. A person\n * can change it live; see `setPace`. */\n pace?: number;\n /** Start every run paused, one `step()` per call. Default false. */\n stepMode?: boolean;\n /** Where Pause, Resume and Step are sent. Default `runControls`, built once\n * per run because \"paused\" is a statement about a run. */\n controls?: RunControlsFactory;\n /** The timer the pace waits on. Injectable so a suite need not sleep. */\n clock?: Clock;\n /**\n * Told which element the next call is about, from the verb's `at`.\n *\n * The seam the vanilla widget's spotlight would plug into. It is a callback\n * rather than a built-in outline because the outline is DOM written outside\n * React's tree, into a page whose stacking and transforms belong to the\n * host; a React app that wants it can draw it with the tools it already has.\n * `at` is presentational here as it is everywhere: never resolved, never\n * clicked, never read for a value.\n */\n onAim?: (at: string | undefined) => void;\n /** A failed `think` lands here as well as in the transcript. */\n onError?: (err: unknown) => void;\n AbortController?: { new (): { signal: AbortSignal; abort: () => void } };\n}\n\nexport interface PanelStore {\n subscribe: (listener: () => void) => () => void;\n /** Referentially stable until something changes, which is what\n * `useSyncExternalStore` requires of it. */\n getSnapshot: () => PanelSnapshot;\n /** Ask something. Resolves when the run ends. */\n ask: (text: string) => Promise<void>;\n /** Abort the run. Stop is the abort signal and is not on `RunControls`: an\n * abort outranks a pause, so a held run is still stoppable. */\n stop: () => void;\n /** Throw away the transcript and the history, and stop whatever is running. */\n clear: () => void;\n pause: () => void;\n resume: () => void;\n step: () => void;\n setPace: (ms: number) => void;\n setStepMode: (on: boolean) => void;\n setConfirmCommits: (on: boolean) => void;\n /** Answer an open question. A no-op for an id that is not open, which is what\n * makes a double click harmless. */\n decide: (id: string, decision: Decision) => void;\n revoke: (verb: string) => void;\n /**\n * This panel's question, in the shape of `MountOptions.approve`.\n *\n * The same function behind the in-page gate and the relay path, exactly as\n * the vanilla widget does it, so a commit arriving over MCP renders the same\n * card under the same rules:\n *\n * ```ts\n * let panel: PanelStore;\n * const driver = mount({ …, approve: (req) => panel.approve(req) });\n * panel = createPanelStore(driver, { think });\n * ```\n */\n approve: (req: ApprovalRequest) => Promise<Approval>;\n /** Stop the run, answer any open question as lapsed, and release the\n * listeners. Called from the hook's unmount effect. It is FINAL: a\n * destroyed store answers no further `ask`, which is what `destroyed`\n * below exists to let a caller find out before it tries. */\n destroy: () => void;\n /**\n * Whether `destroy` has already run.\n *\n * For a caller that did not do the destroying and cannot be sure it did not\n * happen — which is `useDriver` on a remount, because React can run an\n * effect's cleanup and then mount the same effect again. A store that has\n * been closed cannot be reopened, so the hook asks rather than assuming, and\n * builds a new one when the answer is yes.\n */\n destroyed: () => boolean;\n}\n\nexport interface Decision {\n allow: boolean;\n /** Install the rule that was offered on the card. Ignored when `grants` is\n * off or the card offered none. */\n always?: boolean;\n /** What was typed beside the decision. On a denial it becomes the model's\n * hint. It is never what authorized anything. */\n note?: string;\n}\n\nconst STOP_NOTE: Record<StopReason, string | null> = {\n // Nothing to add: the model's own prose is already in the transcript.\n answered: null,\n silent: \"The model replied with nothing. That is usually a bug in `think`.\",\n \"max-steps\": \"Stopped: this took more steps than allowed. Ask again, more specifically.\",\n stuck: \"Stopped: the same call kept being refused, so going on would not have helped.\",\n \"over-budget\":\n \"Stopped: this app's limit on what one session may spend is reached. Asking again will \" +\n \"not help — the limit is set by the app, not by the panel.\",\n aborted: \"Stopped.\",\n};\n\n/**\n * What a receipt says, as one short line of plain text.\n *\n * A pure function and exported, for two reasons. It is what the card renders\n * into its `role=\"status\"`, and a status line is the one piece of this that a\n * screen reader user gets instead of the layout, so it is asserted directly in\n * the suite rather than through a renderer. And a host replacing the card keeps\n * the wording without having to re-derive it from the phase — the phases are a\n * state machine and the sentences are a product decision, and a host should be\n * able to take the second without reimplementing the first.\n */\nexport function receiptLine(entry: ApprovalEntry): string {\n switch (entry.phase) {\n case \"asking\":\n return \"Waiting for your decision.\";\n case \"allowed\":\n return entry.via ? `Allowed by your rule: ${entry.via}. Running.` : \"Approved, running.\";\n case \"allowed-ok\":\n return \"Approved. Finished.\";\n // Approved and then refused by the app anyway. The receipt says both,\n // because a reader who is told only the first has been told the half that\n // flatters us.\n case \"allowed-refused\":\n return `Approved, but the app refused it: ${entry.refused ?? \"refused\"}.`;\n case \"denied\":\n return entry.via ? `Refused by your rule: ${entry.via}.` : \"Denied. Nothing was changed.\";\n case \"stopped\":\n return \"The run was stopped before this ran. Nothing was changed.\";\n case \"lapsed\":\n return \"The panel closed before anybody answered. Nothing was changed.\";\n }\n}\n\n/** The step list's outcome phrase, given a result. Pure, so the suite can read\n * it without a renderer, and so a host's own row renders the same words. */\nexport function stepOutcome(ok: boolean, refused?: string, count?: number): string {\n if (!ok) return `refused: ${refused ?? \"refused\"}`;\n return count === undefined ? \"ok\" : `ok · ${commas(count)} matched`;\n}\n\nexport function createPanelStore(driver: Driver, options: PanelOptions): PanelStore {\n const Abort = options.AbortController ?? globalThis.AbortController;\n const askAbove = options.commitAskAbove ?? COMMIT_ASK_ABOVE;\n\n let entries: Entry[] = [];\n let messages: Turn[] = [];\n let running: { signal: AbortSignal; abort: () => void } | null = null;\n let active: RunControls | null = null;\n let runState: RunState = \"running\";\n let paceMs = options.pace ?? 600;\n let permits = 0;\n let stepMode = options.stepMode === true;\n let confirmCommits = options.confirmCommits !== false;\n let grants: Grant[] = [];\n let live = true;\n let ids = 0;\n\n /**\n * Which conversation we are in. Kept for exactly the reason the vanilla\n * widget keeps it, and the reason survives the move to React unchanged: an\n * abort stops `drive` at its next await, so a call it had already announced\n * can still arrive afterwards, and a step row about it would appear in a\n * transcript the person has just emptied. React does not help with this —\n * a `setState` from a stale async callback is exactly as wrong as an\n * `appendChild` from one.\n */\n let era = 0;\n\n /**\n * The run's last `describe` count, which is the number the model just put on\n * the screen. Cleared when a question is asked, because that is when it has\n * been put in front of somebody and spoken for.\n */\n let lastCount: number | undefined;\n\n const listeners = new Set<() => void>();\n /** Open questions, by entry id. */\n const open = new Map<string, Open>();\n /** Allowed questions waiting for the app's verdict, oldest first per verb. */\n const awaiting: ApprovalEntry[] = [];\n\n interface Open {\n entry: ApprovalEntry;\n answer: (approval: Approval, phase: ApprovalPhase, note?: string) => void;\n }\n\n let snapshot: PanelSnapshot = build();\n\n function build(): PanelSnapshot {\n const pending = entries.find(\n (e): e is ApprovalEntry => e.kind === \"approval\" && e.phase === \"asking\",\n );\n return {\n entries,\n busy: running !== null,\n runState,\n paceMs,\n permits,\n stepMode,\n confirmCommits,\n ...(driver.budget ? { budget: driver.budget() } : {}),\n grants,\n ...(pending ? { pending } : {}),\n era,\n };\n }\n\n /** One new snapshot per change, and one notification. A fresh `entries`\n * array every time, because a mutated array is a snapshot React cannot tell\n * from the last one. */\n function bump(): void {\n entries = entries.slice();\n snapshot = build();\n for (const listener of [...listeners]) listener();\n }\n\n function id(): string {\n return `dk${++ids}`;\n }\n\n function say(kind: SaidEntry[\"kind\"], text: string): void {\n entries.push({ kind, id: id(), text });\n bump();\n }\n\n function patch<E extends Entry>(entry: E, changes: Partial<E>): void {\n const at = entries.indexOf(entry);\n if (at < 0) return;\n entries[at] = { ...entry, ...changes };\n bump();\n }\n\n // ---- the gate ----------------------------------------------------------\n //\n // The rules below are the vanilla widget's, restated because they have to be\n // the same rules: one of the two panels being laxer about a commit than the\n // other would make \"which panel is this app using\" a security question.\n\n /** How many rows the question is about, from the screen alone. */\n function countFor(shot: Snapshot): number | undefined {\n return shot.selectedCount ?? shot.selected?.length;\n }\n\n /** Whether this commit gets a question. The three options' whole meaning. */\n function shouldAsk(req: ApprovalRequest, count: number | undefined): boolean {\n if (!confirmCommits) return false;\n // Absent means the app made no claim, which is gated: a commit that has not\n // said there is a way back is treated as one that has not got one.\n const reversible = req.verb.reversible === true;\n const large = count !== undefined && count > askAbove;\n return !reversible || options.confirmEveryCommit === true || large;\n }\n\n /** Whether `driver.call()` already asks, so this panel must not. */\n function coreAsks(): boolean {\n const policy = driver.approval?.policy;\n return policy === \"hook\" || policy === \"adopted\";\n }\n\n /** Hold the core's no-other-calls lock while a question is open, so a second\n * agent over the relay cannot press an approve button while the card sits\n * there unanswered. */\n function withLock<T>(verb: string, ask: () => Promise<T>): Promise<T> {\n const hold = driver.approval?.hold;\n return hold ? hold(verb, ask) : ask();\n }\n\n /** The rule a person would install from this card, in the words they read. */\n function grantRule(verb: string, allow: boolean): string {\n return allow\n ? `Always allow “${verb}” for the rest of this session, without asking`\n : `Always refuse “${verb}” for the rest of this session, without asking`;\n }\n\n function grantFor(verb: string): Grant | undefined {\n return grants.find((g) => g.verb === verb);\n }\n\n /**\n * Render the question and wait for an answer.\n *\n * `teardown` is the answer to give if the panel goes away with the question\n * still on screen, and it is a parameter rather than a constant because the\n * two callers are owed different answers — a veto for the in-page run that is\n * being torn down with it, and `{ timedOut: true }` for a call that arrived\n * from outside and has somebody waiting on an approval nobody will now give.\n * Confusing those two is what the core's `timedOut` exists to stop.\n */\n function askPerson(\n req: ApprovalRequest,\n count: number | undefined,\n signal: AbortSignal | undefined,\n teardown: Approval,\n ): Promise<Approval> {\n const entry: ApprovalEntry = {\n kind: \"approval\",\n id: id(),\n verb: req.name,\n describe: req.verb.describe,\n args: req.args,\n ...(count === undefined ? {} : { count }),\n reversible: req.verb.reversible === true,\n large: count !== undefined && count > askAbove,\n phase: \"asking\",\n ...(options.grants ? { grantOffer: grantRule(req.name, true) } : {}),\n };\n entries.push(entry);\n bump();\n\n return new Promise<Approval>((resolve) => {\n let answered = false;\n /**\n * The buttons go and the receipt stays, in the same entry.\n *\n * This is the whole point of the area. The question keeps its id, its\n * place in the transcript and its own words; only `phase` moves. A card\n * that unmounted on decision and left a separate outcome line behind\n * would break the question/answer link in scrollback, which is the one\n * link the only auditable feature in the library depends on.\n */\n const answer = (approval: Approval, phase: ApprovalPhase, note?: string): void => {\n if (answered) return;\n answered = true;\n open.delete(entry.id);\n const found = entries.find((e) => e.id === entry.id) as ApprovalEntry | undefined;\n const row = found ?? entry;\n patch(row, {\n phase,\n ...(note === undefined || note === \"\" ? {} : { note }),\n } as Partial<ApprovalEntry>);\n // Allowed and inside a run: the app has still to have its say, and the\n // receipt is not finished until it has. Parked by verb name, oldest\n // first, which is how `onResult` finds it again.\n if (phase === \"allowed\" && running) {\n const settled = entries.find((e) => e.id === entry.id) as ApprovalEntry | undefined;\n if (settled) awaiting.push(settled);\n }\n resolve(approval);\n };\n\n open.set(entry.id, { entry, answer });\n\n // An abort answers the question, and the only safe answer is no. Without\n // this a stop would leave the loop waiting on a promise nobody resolves\n // and the panel busy forever.\n signal?.addEventListener(\"abort\", () =>\n answer(\"the run was stopped before this ran\", \"stopped\"),\n );\n if (signal?.aborted) answer(\"the run was stopped before this ran\", \"stopped\");\n // Registered after the signal check, so the map only holds genuinely open\n // questions.\n if (answered) return;\n open.set(entry.id, {\n entry,\n answer,\n });\n teardowns.set(entry.id, () => answer(teardown, \"lapsed\"));\n });\n }\n\n const teardowns = new Map<string, () => void>();\n\n function decide(entryId: string, decision: Decision): void {\n const slot = open.get(entryId);\n if (!slot) return;\n teardowns.delete(entryId);\n const note = decision.note?.trim() ?? \"\";\n\n // The rule is installed from the text that was on the card, not from a\n // string built again here, so what was agreed to and what was stored\n // cannot differ.\n if (decision.always === true && options.grants) {\n grants = [\n ...grants.filter((g) => g.verb !== slot.entry.verb),\n {\n verb: slot.entry.verb,\n rule: grantRule(slot.entry.verb, decision.allow),\n allow: decision.allow,\n },\n ];\n }\n\n if (decision.allow) {\n // `true` and never the note. The decision is the authorization; a note\n // beside it is a comment on the record. Reading consent out of typed text\n // would let the text authorize the call.\n slot.answer(true, \"allowed\", note);\n } else {\n // A denial's note IS load-bearing, in the other direction: the core turns\n // a string into the hint the model is told, so \"not until finance signs\n // off\" reaches the model where \"declined\" would not.\n slot.answer(note === \"\" ? false : note, \"denied\", note);\n }\n }\n\n /** This panel's dialog, as a `MountOptions.approve` hook. */\n async function approve(req: ApprovalRequest): Promise<Approval> {\n const standing = options.grants ? grantFor(req.name) : undefined;\n if (standing) return receipt(req, standing);\n // `lastCount` only while a run is in flight, and then first: a commit that\n // arrived between runs has no run to have counted anything.\n const count = (running ? lastCount : undefined) ?? countFor(req.snapshot);\n // Not `true`. A gate that let this through without asking must not be\n // recorded as a person saying yes — `{ asked: false }` is the core's word\n // for this answer.\n if (!shouldAsk(req, count)) return { asked: false };\n lastCount = undefined;\n const was = runState;\n if (active) show(\"awaiting-approval\");\n try {\n // No `withLock`: the core takes its lock before calling an approver, and\n // a second take would assert what is already true.\n return await askPerson(req, count, running?.signal, CLOSED_LAPSE);\n } finally {\n if (active) show(was);\n }\n }\n\n /**\n * A commit answered by a standing rule. Posted as a receipt all the same.\n *\n * A rule that silenced the question must not also silence the record: the\n * entry says which rule answered, so scrollback shows both that the commit\n * happened and why nobody was asked. The answer handed back is\n * `{ asked: false }` rather than `true`, because nobody WAS asked this time —\n * which is exactly the distinction the core added that answer for. An app\n * that needs every allowed commit to carry a person's yes in the audit record\n * should leave `grants` off.\n */\n function receipt(req: ApprovalRequest, rule: Grant): Approval {\n const count = (running ? lastCount : undefined) ?? countFor(req.snapshot);\n const entry: ApprovalEntry = {\n kind: \"approval\",\n id: id(),\n verb: req.name,\n describe: req.verb.describe,\n args: req.args,\n ...(count === undefined ? {} : { count }),\n reversible: req.verb.reversible === true,\n large: count !== undefined && count > askAbove,\n phase: rule.allow ? \"allowed\" : \"denied\",\n via: rule.rule,\n };\n entries.push(entry);\n bump();\n if (rule.allow) {\n if (running) awaiting.push(entries[entries.length - 1] as ApprovalEntry);\n return { asked: false };\n }\n return rule.rule;\n }\n\n const CLOSED_VETO = \"the panel was closed before this was approved\";\n const CLOSED_LAPSE: Approval = {\n timedOut: true,\n hint:\n \"the approval panel was closed while this was waiting to be approved, so nobody \" +\n \"answered. **The verb did not run and nothing changed.** Ask the person to reopen the \" +\n \"assistant, then call it again.\",\n };\n\n // ---- the run -----------------------------------------------------------\n\n function show(state: RunState): void {\n runState = state;\n bump();\n }\n\n async function ask(text: string): Promise<void> {\n if (!live || running) return;\n say(\"you\", text);\n const mine = era;\n\n const controller = new Abort();\n running = controller;\n\n const control = (options.controls ?? runControls)({\n pace: paceMs,\n stepMode,\n });\n active = control;\n // The controls have more than one owner — this panel's buttons move them\n // and `drive` moves them too — so the panel reads them rather than\n // remembering what it last asked for.\n const unsubscribe = control.subscribe(() => {\n paceMs = control.paceMs;\n permits = control.permits;\n bump();\n });\n paceMs = control.paceMs;\n permits = control.permits;\n show(\"running\");\n\n const steps = new Map<string, StepEntry>();\n lastCount = undefined;\n\n /** The built-in gate, per run. Not installed when the core already asks. */\n function confirmCommit(req: CommitRequest): Promise<CommitDecision> {\n const standing = options.grants ? grantFor(req.name) : undefined;\n if (standing) {\n // `CommitDecision` has no `{ asked: false }`: it is `drive`'s option,\n // not the core's hook, so a grant on this path can only say yes. The\n // entry still records the rule, which is the half the panel owns.\n const answer = receipt(req as ApprovalRequest, standing);\n return Promise.resolve(standing.allow ? true : (answer as CommitDecision));\n }\n const count = lastCount ?? countFor(req.snapshot);\n if (!shouldAsk(req, count)) return Promise.resolve(true);\n lastCount = undefined;\n return withLock(\n req.name,\n async () =>\n (await askPerson(req, count, controller.signal, CLOSED_VETO)) as CommitDecision,\n );\n }\n\n const gate = options.onBeforeCommit ?? (coreAsks() ? undefined : confirmCommit);\n\n function row(e: CallEvent): StepEntry {\n const found = steps.get(e.call.id);\n if (found) return found;\n const entry: StepEntry = {\n kind: \"step\",\n id: id(),\n callId: e.call.id,\n verb: e.call.name,\n ...(e.kind === undefined ? {} : { verbKind: e.kind }),\n args: e.call.args,\n ...(e.at === undefined ? {} : { at: e.at }),\n commit: e.kind === \"commit\",\n status: \"pending\",\n };\n entries.push(entry);\n steps.set(e.call.id, entry);\n bump();\n return entry;\n }\n\n function current(e: StepEntry): StepEntry {\n const found = entries.find((x) => x.id === e.id) as StepEntry | undefined;\n return found ?? e;\n }\n\n const paced: DriveOptions = {\n think: options.think,\n task: text,\n history: messages,\n ...(options.instructions === undefined ? {} : { instructions: options.instructions }),\n ...(options.maxSteps === undefined ? {} : { maxSteps: options.maxSteps }),\n ...(options.refusalLimit === undefined ? {} : { refusalLimit: options.refusalLimit }),\n ...(gate ? { onBeforeCommit: gate } : {}),\n signal: controller.signal,\n controls: control,\n pace: paceMs,\n ...(options.clock === undefined ? {} : { clock: options.clock }),\n\n // A row appears on `onBeforeCall`, which fires before the pace wait and\n // before any hold — the only way \"you can see it coming and stop it\" is\n // true rather than aspirational.\n onBeforeCall: (e) => {\n if (era !== mine) return;\n const entry = row(e);\n const now = current(entry);\n steps.set(e.call.id, now);\n patch(now, { status: \"pending\" });\n options.onAim?.(e.at);\n },\n onCall: (e) => {\n if (era !== mine) return;\n const entry = steps.get(e.call.id) ?? row(e);\n patch(current(entry), { status: \"running\" });\n options.onAim?.(e.at);\n },\n onControl: ({ state }) => {\n if (era !== mine) return;\n show(state);\n },\n onResult: ({ call, kind, result }) => {\n if (era !== mine) return;\n if (kind === \"describe\" && result?.ok) lastCount = result.count;\n options.onAim?.(undefined);\n settleReceipt(call.name, result);\n const entry = steps.get(call.id);\n if (!entry) return;\n const now = current(entry);\n if (result === null) {\n patch(now, { status: \"done\", outcome: \"looked\" });\n return;\n }\n if (result.ok) {\n // The count is repeated on the row on purpose. It is the number a\n // commit decision turns on, and the person watching should be able to\n // see \"1,000 matched\" without reading the model's summary of it.\n patch(now, {\n status: \"done\",\n outcome: stepOutcome(true, undefined, result.count),\n ...(result.count === undefined ? {} : { count: result.count }),\n });\n } else {\n // A refusal is an OUTCOME and not an error. The app said no, on\n // purpose, in its own vocabulary, and the model is about to adapt to\n // it; rendering it as a failure would teach the person to read a\n // working app as a broken one.\n patch(now, { status: \"refused\", outcome: stepOutcome(false, result.refused) });\n }\n },\n onSay: ({ text: prose }) => {\n if (era !== mine) return;\n say(\"assistant\", prose);\n },\n };\n\n try {\n const out = await drive(driver, paced);\n if (era !== mine) return;\n messages = out.messages;\n const note = STOP_NOTE[out.stop];\n if (note) say(\"note\", note);\n } catch (err) {\n // Handed to `onError` whichever conversation it belonged to, and said in\n // the transcript only if that transcript is still the one it is about.\n options.onError?.(err);\n if (era === mine) {\n say(\"note\", `Something went wrong talking to the model: ${message(err)}`);\n }\n } finally {\n unsubscribe();\n running = null;\n active = null;\n lastCount = undefined;\n runState = \"running\";\n options.onAim?.(undefined);\n if (era === mine) {\n // Rows for calls that never ran. A stop during a pace wait or a hold\n // abandons them unrun and no `onResult` is coming, so leaving them\n // pending would be a panel saying something is about to happen when the\n // run is already over.\n for (const entry of steps.values()) {\n const now = current(entry);\n if (now.status === \"pending\" || now.status === \"running\") {\n patch(now, { status: \"skipped\", outcome: \"not run\" });\n }\n }\n // And receipts for commits that were approved and then abandoned. The\n // card must not be left reading \"running\" for something that never ran.\n for (const entry of awaiting.slice()) {\n const now = entries.find((x) => x.id === entry.id) as ApprovalEntry | undefined;\n if (now && now.phase === \"allowed\") patch(now, { phase: \"stopped\" });\n }\n }\n awaiting.length = 0;\n bump();\n }\n }\n\n /**\n * Move an approved receipt on to its final phase, from the app's own verdict.\n *\n * Correlated by verb name, oldest first. The gate is handed a\n * `CommitRequest` carrying a name and arguments and no call id — the id\n * exists one layer out, on the `ToolCall` — so a name is what there is to\n * match on. It is sound for the case that exists: the core holds its\n * no-other-calls lock across an approval, so a second commit of the same verb\n * cannot be in flight while the first is still being asked about.\n */\n function settleReceipt(verb: string, result: { ok: boolean; refused?: string } | null): void {\n const at = awaiting.findIndex((e) => e.verb === verb);\n if (at < 0 || result === null) return;\n const [entry] = awaiting.splice(at, 1);\n if (!entry) return;\n const now = entries.find((x) => x.id === entry.id) as ApprovalEntry | undefined;\n if (!now || now.phase !== \"allowed\") return;\n patch(\n now,\n result.ok\n ? { phase: \"allowed-ok\" }\n : {\n phase: \"allowed-refused\",\n ...(result.refused === undefined ? {} : { refused: result.refused }),\n },\n );\n }\n\n function clear(): void {\n // First, and through the run's own controller: the loop must not be left\n // holding `messages` the panel has just thrown away.\n running?.abort();\n era++;\n entries = [];\n messages = [];\n awaiting.length = 0;\n if (options.greeting !== undefined) {\n entries.push({ kind: \"note\", id: id(), text: options.greeting });\n }\n bump();\n }\n\n if (options.greeting !== undefined) {\n entries.push({ kind: \"note\", id: id(), text: options.greeting });\n snapshot = build();\n }\n\n return {\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n getSnapshot: () => snapshot,\n ask,\n stop: () => running?.abort(),\n clear,\n pause: () => active?.pause(),\n resume: () => active?.resume(),\n step: () => active?.step(),\n setPace: (ms) => {\n if (!Number.isFinite(ms) || ms < 0) return;\n paceMs = ms;\n // Live, which is the whole reason the controls have a setter: the moment\n // somebody wants the agent slowed down is while it is going.\n active?.pace(ms);\n bump();\n },\n setStepMode: (on) => {\n stepMode = on;\n bump();\n },\n setConfirmCommits: (on) => {\n // Read per commit rather than per run, so turning confirmations off — or\n // back on — in the middle of a run takes effect on the next commit. That\n // is what somebody who has just watched a commit go past expects of the\n // switch they reached for.\n confirmCommits = on;\n bump();\n },\n decide,\n revoke: (verb) => {\n grants = grants.filter((g) => g.verb !== verb);\n bump();\n },\n approve,\n destroyed: () => !live,\n destroy: () => {\n live = false;\n // The open questions are lapsed BEFORE the run is aborted, and the order\n // is the whole difference between two records. An abort answers an open\n // question `stopped` through the signal listener in `ask`, and on an\n // unmount that would be the less true of the two available facts: the\n // run was stopped because the panel went away, and \"the panel closed\n // before anybody answered\" is what somebody reading the receipt needs.\n // Lapsing first is safe — a lapse answers the core with a refusal\n // string, never an allow — and the abort still lands before the loop\n // resumes, because it runs synchronously here and the loop can only\n // continue on a later microtask.\n for (const lapse of [...teardowns.values()]) lapse();\n teardowns.clear();\n running?.abort();\n listeners.clear();\n },\n };\n}\n\nfunction message(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n"]}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* driverkit/relay — who the caller is, and nothing more than that.
|
|
3
|
+
*
|
|
4
|
+
* A port of `python/src/driverkit/auth.py`, claim for claim and refusal for
|
|
5
|
+
* refusal. The long-form argument lives in that file's docstring and in
|
|
6
|
+
* PROTOCOL.md's "Who is allowed to do this"; what follows here is the summary
|
|
7
|
+
* and the places this half could plausibly drift.
|
|
8
|
+
*
|
|
9
|
+
* This module answers one question: WHICH PERSON is on the other end of this
|
|
10
|
+
* request? It never answers "may they do this", because PROTOCOL.md's core
|
|
11
|
+
* property is untouched by any of it:
|
|
12
|
+
*
|
|
13
|
+
* THE RELAY GRANTS NO AUTHORITY. It forwards a verb to a tab that is already
|
|
14
|
+
* logged in as a person, and that tab's own session is what the app checks.
|
|
15
|
+
*
|
|
16
|
+
* A credential here buys its holder nothing they could not already do in their
|
|
17
|
+
* own browser. What it buys the RELAY is the ability to keep a hundred people's
|
|
18
|
+
* tabs apart. Isolation, not authorisation.
|
|
19
|
+
*
|
|
20
|
+
* The token:
|
|
21
|
+
*
|
|
22
|
+
* dkt1.<base64url(payload JSON)>.<base64url(HMAC-SHA256(key, "dkt1." + payload))>
|
|
23
|
+
*
|
|
24
|
+
* The algorithm is in the PREFIX, not in the payload, which is the deliberate
|
|
25
|
+
* departure from JWT: a JWT names its own algorithm in a header the verifier
|
|
26
|
+
* has not authenticated yet, and that is the root of both the `alg: none`
|
|
27
|
+
* family of bugs and the HMAC/RSA confusion family. Here there is nothing to
|
|
28
|
+
* negotiate. A future `dkt2` is a new prefix -- a greppable change rather than
|
|
29
|
+
* a field an attacker can set.
|
|
30
|
+
*
|
|
31
|
+
* Claims: `sub` (the principal), `aud` (which relay this is for), `iat`/`exp`
|
|
32
|
+
* (Unix seconds, honoured with `DEFAULT_SKEW_S` of slack), `kid` (which key
|
|
33
|
+
* signed it; read before verification, used only to SELECT the key, so an
|
|
34
|
+
* attacker who edits it fails the MAC), and an optional `tab` binding the
|
|
35
|
+
* credential to one tab id.
|
|
36
|
+
*
|
|
37
|
+
* Anonymous: `anon1.<base64url(32 random bytes)>`, minted by the page, keyless
|
|
38
|
+
* in the relay, resolving to `anon:<sha256("driverkit-anon-v1." + secret)[:16]>`.
|
|
39
|
+
* Independent per visitor -- "anonymous" is never one bucket. It is a bearer
|
|
40
|
+
* capability and not an identity, it dies with the tab, and it confers nothing
|
|
41
|
+
* at the app.
|
|
42
|
+
*
|
|
43
|
+
* Zero dependencies: `node:crypto` only.
|
|
44
|
+
*/
|
|
45
|
+
/** The version prefix that IS the algorithm. */
|
|
46
|
+
export declare const TOKEN_PREFIX = "dkt1";
|
|
47
|
+
/** The anonymous credential's prefix. */
|
|
48
|
+
export declare const ANON_PREFIX = "anon1";
|
|
49
|
+
/** What an anonymous principal id starts with. */
|
|
50
|
+
export declare const ANON_ID_PREFIX = "anon:";
|
|
51
|
+
/**
|
|
52
|
+
* The principal every request resolves to when auth is off.
|
|
53
|
+
*
|
|
54
|
+
* One principal means the scoping in `relay.ts` is a no-op and the
|
|
55
|
+
* unconfigured loopback relay a single developer runs is byte-for-byte what it
|
|
56
|
+
* was before any of this existed.
|
|
57
|
+
*/
|
|
58
|
+
export declare const LOCAL_PRINCIPAL = "local";
|
|
59
|
+
/**
|
|
60
|
+
* Shortest key accepted. A 16-character shared secret makes the HMAC theatre,
|
|
61
|
+
* and the moment to say so is at construction rather than in a post-mortem.
|
|
62
|
+
*/
|
|
63
|
+
export declare const MIN_SECRET_BYTES = 32;
|
|
64
|
+
/**
|
|
65
|
+
* How long a freshly minted token lasts, in ms.
|
|
66
|
+
*
|
|
67
|
+
* Short, because a short lifetime is what substitutes for the revocation a
|
|
68
|
+
* stateless token cannot have. The page asks for a new one on every reconnect,
|
|
69
|
+
* so this does not need to cover a session.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DEFAULT_TTL_MS = 120000;
|
|
72
|
+
/**
|
|
73
|
+
* Clock slack on `exp`, and the window by which an `iat` may lead now.
|
|
74
|
+
*
|
|
75
|
+
* Sixty seconds, not five minutes. Skew tolerance is a direct extension of
|
|
76
|
+
* every token's lifetime, so a five-minute window on a two-minute token would
|
|
77
|
+
* more than treble the time a leaked one stays useful. Sixty covers two hosts
|
|
78
|
+
* with working NTP, which is the case this is for; a fleet whose clocks are
|
|
79
|
+
* minutes apart has a problem a wider window hides rather than solves.
|
|
80
|
+
*/
|
|
81
|
+
export declare const DEFAULT_SKEW_MS = 60000;
|
|
82
|
+
/**
|
|
83
|
+
* A credential did not check out.
|
|
84
|
+
*
|
|
85
|
+
* Deliberately carries no machine-readable reason. The relay answers every
|
|
86
|
+
* instance with one slug -- `bad-credential` -- because the distinctions a
|
|
87
|
+
* caller might want are exactly the distinctions an attacker wants: "the
|
|
88
|
+
* signature verified but the audience was wrong" tells a forger the forgery
|
|
89
|
+
* worked. A legitimate client's move is the same in every case (mint a fresh
|
|
90
|
+
* token, retry once), so the split buys it nothing.
|
|
91
|
+
*/
|
|
92
|
+
export declare class AuthError extends Error {
|
|
93
|
+
readonly name = "AuthError";
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Who a request is from.
|
|
97
|
+
*
|
|
98
|
+
* `id` is the registry key half that makes isolation structural: a tab is
|
|
99
|
+
* stored under `(principal, tab id)`, so one principal cannot reach another's
|
|
100
|
+
* tab by any code path, including one somebody adds later and forgets to
|
|
101
|
+
* guard.
|
|
102
|
+
*
|
|
103
|
+
* `tab` is the optional binding from the credential. When it is set the caller
|
|
104
|
+
* may address that tab and no other.
|
|
105
|
+
*/
|
|
106
|
+
export interface Principal {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly tab?: string;
|
|
109
|
+
readonly anonymous?: boolean;
|
|
110
|
+
}
|
|
111
|
+
export interface TabAuthOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Which relay these tokens are for. No default: a default audience is an
|
|
114
|
+
* audience nobody chose, and two relays that both accept "driverkit" are one
|
|
115
|
+
* relay as far as a stolen token is concerned.
|
|
116
|
+
*/
|
|
117
|
+
audience: string;
|
|
118
|
+
/** Key id to secret. Rotation is additive; see `TabAuth`. */
|
|
119
|
+
keys?: Record<string, string | Buffer>;
|
|
120
|
+
/** Sugar for the single-key case. Mutually exclusive with `keys`. */
|
|
121
|
+
secret?: string | Buffer;
|
|
122
|
+
/** Which key `mint` signs with. Defaults to the first in `keys`. */
|
|
123
|
+
activeKid?: string;
|
|
124
|
+
ttlMs?: number;
|
|
125
|
+
skewMs?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Accept `anon1.` credentials. On by default so an unauthenticated visitor
|
|
128
|
+
* is not an error; turn it off in an app where every user is logged in,
|
|
129
|
+
* because an anonymous credential there can only be somebody probing.
|
|
130
|
+
*/
|
|
131
|
+
anonymous?: boolean;
|
|
132
|
+
/** Refuse any `dkt1` token without a `tab` claim. See `mint`. */
|
|
133
|
+
requireTabBinding?: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** The principal id an `anon1.` credential resolves to. Pure and keyless. */
|
|
136
|
+
export declare function anonPrincipalId(credential: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* A fresh anonymous credential. For a page, or a test; never the relay.
|
|
139
|
+
*
|
|
140
|
+
* 256 bits, because this string is the whole of an anonymous visitor's
|
|
141
|
+
* isolation: anybody who can guess it is that visitor.
|
|
142
|
+
*/
|
|
143
|
+
export declare function mintAnonCredential(): string;
|
|
144
|
+
/**
|
|
145
|
+
* Verification, and the minter the app's backend uses.
|
|
146
|
+
*
|
|
147
|
+
* The app's backend is the only thing that knows who a browser is, so it is
|
|
148
|
+
* the only thing that may mint. Give it the same `keys` and `audience` the
|
|
149
|
+
* relay has and it needs nothing else -- no relay client, no callback, no
|
|
150
|
+
* shared database.
|
|
151
|
+
*
|
|
152
|
+
* Rotation is additive and ordered:
|
|
153
|
+
*
|
|
154
|
+
* 1. Add the new key to the RELAY's `keys`. Deploy. It accepts both; nothing
|
|
155
|
+
* mints with the new one yet.
|
|
156
|
+
* 2. Point the minter at it (`activeKid`). Deploy.
|
|
157
|
+
* 3. After `ttlMs + skewMs`, drop the old key from the relay.
|
|
158
|
+
*
|
|
159
|
+
* The order is the whole of it. A key the relay does not know yet refuses
|
|
160
|
+
* every token signed with it, and a key dropped before the last token signed
|
|
161
|
+
* with it expires logs a hundred people out at once.
|
|
162
|
+
*/
|
|
163
|
+
export declare class TabAuth {
|
|
164
|
+
#private;
|
|
165
|
+
readonly audience: string;
|
|
166
|
+
readonly ttlMs: number;
|
|
167
|
+
readonly skewMs: number;
|
|
168
|
+
readonly anonymous: boolean;
|
|
169
|
+
readonly requireTabBinding: boolean;
|
|
170
|
+
readonly activeKid: string;
|
|
171
|
+
constructor(options: TabAuthOptions);
|
|
172
|
+
/**
|
|
173
|
+
* A token saying `principal` is who the bearer is.
|
|
174
|
+
*
|
|
175
|
+
* `tab` binds it to one tab id, and whether to use it is the one real
|
|
176
|
+
* judgement call here.
|
|
177
|
+
*
|
|
178
|
+
* It costs a round trip. The tab mints its own id -- PROTOCOL.md requires
|
|
179
|
+
* that, so a reconnect resumes identity -- which means the backend cannot
|
|
180
|
+
* know the id at page-render time. Binding turns one template variable into
|
|
181
|
+
* "the page asks the backend for a token AFTER the JS has picked an id", and
|
|
182
|
+
* re-asks on every reconnect that changes it.
|
|
183
|
+
*
|
|
184
|
+
* IT IS NOT STRICTLY SAFER, and the asymmetry is worth understanding before
|
|
185
|
+
* choosing. Both cases assume a stolen token, which is the only case either
|
|
186
|
+
* addresses.
|
|
187
|
+
*
|
|
188
|
+
* Unbound: the thief cannot read or drive the victim's tabs. They can
|
|
189
|
+
* register a tab THEY control under the victim's principal. It runs in their
|
|
190
|
+
* browser, where their own session is what the app checks, so they gain no
|
|
191
|
+
* authority -- but the victim's agent now sees a tab that is not the
|
|
192
|
+
* victim's and may drive it, typing the victim's data onto the attacker's
|
|
193
|
+
* screen. An extra tab; the real ones untouched.
|
|
194
|
+
*
|
|
195
|
+
* Bound to tab T: the thief cannot do that. What they can do is open a stream
|
|
196
|
+
* for T -- and a second stream for a known (principal, tab) is a RECONNECT,
|
|
197
|
+
* which supersedes the first. The victim's own page is hung up on and the
|
|
198
|
+
* thief's becomes that tab, until the victim's `EventSource` reconnects and
|
|
199
|
+
* supersedes back. That is a takeover of the exact tab the agent is already
|
|
200
|
+
* driving, which is worse than an extra tab in the list.
|
|
201
|
+
*
|
|
202
|
+
* What bounds both is the token not leaking: deliver it in a `__Host-`
|
|
203
|
+
* cookie rather than a query parameter, and keep the lifetime short.
|
|
204
|
+
*
|
|
205
|
+
* A credential for an AGENT should be bound whenever the agent drives one
|
|
206
|
+
* known tab. There it is free -- the agent has the tab id already -- and the
|
|
207
|
+
* supersede hazard does not apply, because an agent never opens a tab stream.
|
|
208
|
+
*/
|
|
209
|
+
mint(principal: string, options?: {
|
|
210
|
+
tab?: string;
|
|
211
|
+
ttlMs?: number;
|
|
212
|
+
now?: number;
|
|
213
|
+
}): string;
|
|
214
|
+
/**
|
|
215
|
+
* The principal a credential proves, or `AuthError`.
|
|
216
|
+
*
|
|
217
|
+
* Anonymous first, because it needs no key and cannot be confused with a
|
|
218
|
+
* token: the prefixes are disjoint and both are checked exactly.
|
|
219
|
+
*/
|
|
220
|
+
principal(credential: string, now?: number): Principal;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The caller's credential, from the four places it can arrive.
|
|
224
|
+
*
|
|
225
|
+
* In order, and the order is the order of preference:
|
|
226
|
+
*
|
|
227
|
+
* 1. `Authorization: Bearer` -- what an agent, an MCP server or any HTTP
|
|
228
|
+
* client should use. Standard, and not logged by anything by default.
|
|
229
|
+
* 2. `X-DK-Token` -- for a client whose `Authorization` is already spoken for
|
|
230
|
+
* by the app the relay is embedded in.
|
|
231
|
+
* 3. The `dk_token` cookie (`__Host-` prefixed or not) -- the one that works
|
|
232
|
+
* for `EventSource`, which cannot set a header at all. In the deployment
|
|
233
|
+
* PROTOCOL.md recommends, where the relay is same-origin with the app, this
|
|
234
|
+
* is the best option a page has: the app sets the cookie and the browser
|
|
235
|
+
* attaches it to the stream request with no token anywhere in a URL.
|
|
236
|
+
* 4. `?dk_token=` -- the last resort, for a cross-origin `EventSource` where
|
|
237
|
+
* no cookie will be sent. A QUERY PARAMETER ENDS UP IN EVERY REVERSE
|
|
238
|
+
* PROXY'S ACCESS LOG, which is the one place a token must not be. It is
|
|
239
|
+
* accepted because refusing it would mean cross-origin pages could not
|
|
240
|
+
* connect at all, and it is last and documented as a liability. Short token
|
|
241
|
+
* lifetimes are what make a logged one survivable.
|
|
242
|
+
*/
|
|
243
|
+
export declare function credentialFrom(headers: Record<string, string | string[] | undefined>, query: URLSearchParams): string | undefined;
|
|
244
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/relay/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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