driverkit 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CONTROLS.md +578 -0
  2. package/REACT.md +477 -0
  3. package/README.md +104 -2
  4. package/dist/agent/backend.d.ts +69 -0
  5. package/dist/agent/backend.d.ts.map +1 -0
  6. package/dist/agent/backend.js +130 -0
  7. package/dist/agent/backend.js.map +1 -0
  8. package/dist/agent/control.d.ts +148 -0
  9. package/dist/agent/control.d.ts.map +1 -0
  10. package/dist/agent/control.js +342 -0
  11. package/dist/agent/control.js.map +1 -0
  12. package/dist/agent/index.d.ts +9 -0
  13. package/dist/agent/index.d.ts.map +1 -0
  14. package/dist/agent/index.js +6 -0
  15. package/dist/agent/index.js.map +1 -0
  16. package/dist/agent/loop.d.ts +136 -0
  17. package/dist/agent/loop.d.ts.map +1 -0
  18. package/dist/agent/loop.js +824 -0
  19. package/dist/agent/loop.js.map +1 -0
  20. package/dist/agent/render.d.ts +173 -0
  21. package/dist/agent/render.d.ts.map +1 -0
  22. package/dist/agent/render.js +425 -0
  23. package/dist/agent/render.js.map +1 -0
  24. package/dist/agent/tools.d.ts +138 -0
  25. package/dist/agent/tools.d.ts.map +1 -0
  26. package/dist/agent/tools.js +622 -0
  27. package/dist/agent/tools.js.map +1 -0
  28. package/dist/agent/types.d.ts +566 -0
  29. package/dist/agent/types.d.ts.map +1 -0
  30. package/dist/agent/types.js +32 -0
  31. package/dist/agent/types.js.map +1 -0
  32. package/dist/browser/budget.d.ts +92 -0
  33. package/dist/browser/budget.d.ts.map +1 -0
  34. package/dist/browser/budget.js +151 -0
  35. package/dist/browser/budget.js.map +1 -0
  36. package/dist/browser/connect.d.ts +368 -0
  37. package/dist/browser/connect.d.ts.map +1 -0
  38. package/dist/browser/connect.js +1038 -0
  39. package/dist/browser/connect.js.map +1 -0
  40. package/dist/browser/elsewhere.d.ts +89 -0
  41. package/dist/browser/elsewhere.d.ts.map +1 -0
  42. package/dist/browser/elsewhere.js +91 -0
  43. package/dist/browser/elsewhere.js.map +1 -0
  44. package/dist/browser/frames.d.ts +85 -0
  45. package/dist/browser/frames.d.ts.map +1 -0
  46. package/dist/browser/frames.js +11 -0
  47. package/dist/browser/frames.js.map +1 -0
  48. package/dist/browser/index.d.ts +8 -0
  49. package/dist/browser/index.d.ts.map +1 -0
  50. package/dist/browser/index.js +9 -0
  51. package/dist/browser/index.js.map +1 -0
  52. package/dist/check/check.d.ts +171 -0
  53. package/dist/check/check.d.ts.map +1 -0
  54. package/dist/check/check.js +666 -0
  55. package/dist/check/check.js.map +1 -0
  56. package/dist/check/index.d.ts +3 -0
  57. package/dist/check/index.d.ts.map +1 -0
  58. package/dist/check/index.js +2 -0
  59. package/dist/check/index.js.map +1 -0
  60. package/dist/check/types.d.ts +149 -0
  61. package/dist/check/types.d.ts.map +1 -0
  62. package/dist/check/types.js +29 -0
  63. package/dist/check/types.js.map +1 -0
  64. package/dist/controls/controls.d.ts +198 -0
  65. package/dist/controls/controls.d.ts.map +1 -0
  66. package/dist/controls/controls.js +742 -0
  67. package/dist/controls/controls.js.map +1 -0
  68. package/dist/controls/dom.d.ts +108 -0
  69. package/dist/controls/dom.d.ts.map +1 -0
  70. package/dist/controls/dom.js +56 -0
  71. package/dist/controls/dom.js.map +1 -0
  72. package/dist/controls/index.d.ts +26 -0
  73. package/dist/controls/index.d.ts.map +1 -0
  74. package/dist/controls/index.js +23 -0
  75. package/dist/controls/index.js.map +1 -0
  76. package/dist/controls/rows.d.ts +66 -0
  77. package/dist/controls/rows.d.ts.map +1 -0
  78. package/dist/controls/rows.js +127 -0
  79. package/dist/controls/rows.js.map +1 -0
  80. package/dist/core/index.d.ts +3 -0
  81. package/dist/core/index.d.ts.map +1 -0
  82. package/dist/core/index.js +15 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/core/registry.d.ts +192 -0
  85. package/dist/core/registry.d.ts.map +1 -0
  86. package/dist/core/registry.js +2799 -0
  87. package/dist/core/registry.js.map +1 -0
  88. package/dist/core/types.d.ts +2468 -0
  89. package/dist/core/types.d.ts.map +1 -0
  90. package/dist/core/types.js +19 -0
  91. package/dist/core/types.js.map +1 -0
  92. package/dist/otel/index.d.ts +122 -0
  93. package/dist/otel/index.d.ts.map +1 -0
  94. package/dist/otel/index.js +157 -0
  95. package/dist/otel/index.js.map +1 -0
  96. package/dist/react/index.d.ts +191 -0
  97. package/dist/react/index.d.ts.map +1 -0
  98. package/dist/react/index.js +547 -0
  99. package/dist/react/index.js.map +1 -0
  100. package/dist/react/runtime.d.ts +95 -0
  101. package/dist/react/runtime.d.ts.map +1 -0
  102. package/dist/react/runtime.js +54 -0
  103. package/dist/react/runtime.js.map +1 -0
  104. package/dist/react/store.d.ts +333 -0
  105. package/dist/react/store.d.ts.map +1 -0
  106. package/dist/react/store.js +695 -0
  107. package/dist/react/store.js.map +1 -0
  108. package/dist/relay/auth.d.ts +244 -0
  109. package/dist/relay/auth.d.ts.map +1 -0
  110. package/dist/relay/auth.js +391 -0
  111. package/dist/relay/auth.js.map +1 -0
  112. package/dist/relay/frames.d.ts +141 -0
  113. package/dist/relay/frames.d.ts.map +1 -0
  114. package/dist/relay/frames.js +20 -0
  115. package/dist/relay/frames.js.map +1 -0
  116. package/dist/relay/index.d.ts +8 -0
  117. package/dist/relay/index.d.ts.map +1 -0
  118. package/dist/relay/index.js +4 -0
  119. package/dist/relay/index.js.map +1 -0
  120. package/dist/relay/relay.d.ts +277 -0
  121. package/dist/relay/relay.d.ts.map +1 -0
  122. package/dist/relay/relay.js +1026 -0
  123. package/dist/relay/relay.js.map +1 -0
  124. package/dist/relay/serve.d.ts +33 -0
  125. package/dist/relay/serve.d.ts.map +1 -0
  126. package/dist/relay/serve.js +86 -0
  127. package/dist/relay/serve.js.map +1 -0
  128. package/dist/widget/chat.d.ts +290 -0
  129. package/dist/widget/chat.d.ts.map +1 -0
  130. package/dist/widget/chat.js +486 -0
  131. package/dist/widget/chat.js.map +1 -0
  132. package/dist/widget/css.d.ts +49 -0
  133. package/dist/widget/css.d.ts.map +1 -0
  134. package/dist/widget/css.js +532 -0
  135. package/dist/widget/css.js.map +1 -0
  136. package/dist/widget/dom.d.ts +143 -0
  137. package/dist/widget/dom.d.ts.map +1 -0
  138. package/dist/widget/dom.js +27 -0
  139. package/dist/widget/dom.js.map +1 -0
  140. package/dist/widget/highlight.d.ts +64 -0
  141. package/dist/widget/highlight.d.ts.map +1 -0
  142. package/dist/widget/highlight.js +136 -0
  143. package/dist/widget/highlight.js.map +1 -0
  144. package/dist/widget/index.d.ts +9 -0
  145. package/dist/widget/index.d.ts.map +1 -0
  146. package/dist/widget/index.js +20 -0
  147. package/dist/widget/index.js.map +1 -0
  148. package/dist/widget/position.d.ts +166 -0
  149. package/dist/widget/position.d.ts.map +1 -0
  150. package/dist/widget/position.js +497 -0
  151. package/dist/widget/position.js.map +1 -0
  152. package/dist/widget/settings.d.ts +116 -0
  153. package/dist/widget/settings.d.ts.map +1 -0
  154. package/dist/widget/settings.js +117 -0
  155. package/dist/widget/settings.js.map +1 -0
  156. package/dist/widget/widget.d.ts +442 -0
  157. package/dist/widget/widget.d.ts.map +1 -0
  158. package/dist/widget/widget.js +2005 -0
  159. package/dist/widget/widget.js.map +1 -0
  160. package/package.json +144 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.js","sourceRoot":"","sources":["../../src/widget/position.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAgBH,MAAM,OAAO,GAA6B;IACxC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;IAC5B,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;IAC7B,aAAa,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;IAC/B,cAAc,EAAE,EAAE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C,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,MAAM,CAAC,CAAU;IACxB,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED;0EAC0E;AAC1E,SAAS,KAAK,CAAC,CAAS;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Where the panel sits, and how it gets out of the way.\n *\n * **This is not decoration.** The widget drives the app underneath itself. A\n * person asks it to select rows and the panel is now sitting on top of the\n * rows they asked about, so moving it is how they see the thing the agent just\n * did. That is the whole design brief for this file: one gesture, one\n * keystroke, and the panel is somewhere else — and it is still there tomorrow.\n *\n * ## The unit is a fraction of the free space, not pixels\n *\n * A position is two numbers in `[0, 1]`: `fx = 0` means flush with the left\n * edge, `fx = 1` flush with the right, `0.5` centred. The pixel position is\n * derived in CSS, not here:\n *\n * ```css\n * left: calc(var(--dk-gap) + var(--dk-x) * (100vw - var(--dk-gap) * 2));\n * translate: calc(var(--dk-x) * -100%) calc(var(--dk-y) * -100%);\n * ```\n *\n * At `fx = 1` the element is pushed to `100vw - gap` and then pulled back by\n * its own full width, so its right edge lands on the gap. Work the algebra\n * through for any `fx` and the left edge is `gap + fx * (vw - 2*gap - w)`,\n * which is inside the viewport for every `fx` in `[0, 1]` and every viewport\n * at least as wide as the panel. **A stored fraction cannot describe an\n * off-screen panel.** Pixels can, and a panel 1,100px from the left of a\n * window that is now 600px wide is unreachable — no header to grab, no corner\n * to snap from — and the only cure is clearing site data, which nobody knows\n * to do. So pixels are accepted as input (`{ x, y }`, which is what a host\n * app has on hand) and converted once, against the viewport they were measured\n * in; after that there are only fractions.\n *\n * The one case the algebra does not cover is a viewport narrower than the\n * panel. There `vw - 2*gap - w` is negative and `fx = 1` would drag the panel\n * off the LEFT edge, so `clamp` collapses that axis to 0 and the panel hugs\n * the near edge where the header is still grabbable. The person's chosen\n * fraction is kept, not overwritten, so widening the window puts it back.\n *\n * ## Nothing is written unless it has to be\n *\n * The default position is a declaration in `css.ts` and nothing else, so a\n * host app can place the panel from its own stylesheet with no JavaScript, the\n * same way it can retheme it. Inline custom properties appear only once\n * somebody has actually chosen a position — an explicit `position` option, a\n * remembered one, a drag, a keypress — because at that point the person\n * outranks the author's stylesheet.\n */\n\nimport type { ElementLike, EventLike, RectLike, StorageLike, WindowLike } from \"./dom.ts\";\n\nexport type Corner = \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n\n/** A corner, or a pixel offset from the viewport's top-left corner. Pixels are\n * converted to a fraction the moment they are applied; see the file header. */\nexport type Position = Corner | { x: number; y: number };\n\n/** Fractions of the free space, both in `[0, 1]`. */\nexport interface Fraction {\n fx: number;\n fy: number;\n}\n\nconst CORNERS: Record<Corner, Fraction> = {\n \"top-left\": { fx: 0, fy: 0 },\n \"top-right\": { fx: 1, fy: 0 },\n \"bottom-left\": { fx: 0, fy: 1 },\n \"bottom-right\": { fx: 1, fy: 1 },\n};\n\n/** The order the keyboard cycles, starting where the panel starts. */\nconst CYCLE: Corner[] = [\"bottom-right\", \"bottom-left\", \"top-left\", \"top-right\"];\n\nexport function isCorner(p: Position): p is Corner {\n return typeof p === \"string\" && p in CORNERS;\n}\n\n/**\n * How far a release can be from a corner and still land in it, in pixels.\n *\n * Corners are where a panel belongs nearly all the time — out of the way of\n * the middle of the screen, which is where the app's content is — so a magnet\n * is cheaper than asking for precision. Far from a corner the drop is honoured\n * exactly, because somebody who dragged the panel to the middle of the screen\n * meant it.\n */\nexport const SNAP = 72;\n\n/**\n * How far a pointer must travel before it is a drag and not a click, in\n * pixels.\n *\n * Distance and not time, because time is wrong in both directions: a slow,\n * deliberate click on the launcher is not a drag, and a fast flick of the\n * panel across the screen is not a click. Fingers and pens also wobble by a\n * pixel or two on a tap that was never meant to move anything, which is the\n * other reason this is not zero.\n */\nexport const SLOP = 4;\n\n/** The keyboard nudge, as a fraction of the free space. Deliberately coarse:\n * the goal is \"off the thing I am reading\", and a 1px-at-a-time nudge would\n * take sixty keystrokes to achieve it. */\nconst STEP = 0.1;\n\nexport interface PositionerOptions {\n /** The element custom properties are written to — the widget's host element,\n * which is what `:host` positions. */\n host: ElementLike;\n /** Namespaces the storage key, so two driverkit apps on one origin do not\n * fight over one remembered position. */\n app: string;\n position?: Position;\n window?: WindowLike;\n storage?: StorageLike;\n /** Default true. */\n persist?: boolean;\n /** Default true. False leaves the panel wherever the option and the\n * stylesheet put it. */\n draggable?: boolean;\n /** Pixels. 0 switches snapping off. */\n snapThreshold?: number;\n /** Must match `--dk-gap`, which is what the arithmetic in `css.ts` insets\n * by. Only worth passing if the host app overrode that property. */\n gap?: number;\n /** Spoken to a screen reader. A panel that moves silently has moved only\n * for the people who can see it. */\n announce?: (text: string) => void;\n}\n\nexport interface Positioner {\n /**\n * Make `el` draggable, and return the predicate its own click handler has to\n * consult first: true means the click that just arrived is the tail of a\n * drag of THIS element and belongs to the drag.\n *\n * Per element rather than one flag for the whole widget, because a drag of\n * the header produces a click on the header — which nothing listens for —\n * and a single shared flag would then still be set when the person's next\n * real click landed on the launcher.\n *\n * `controls: \"ignore\"` refuses to start a drag from a button or input\n * inside `el`, which is what keeps the header's Close button clickable.\n */\n handle: (el: ElementLike, controls?: \"ignore\" | \"allow\") => () => boolean;\n /** Arrow keys. `plain` allows bare arrows, which only the move button does;\n * everywhere else it takes Alt. Returns true if the key was used. */\n key: (event: EventLike, plain?: boolean) => boolean;\n moveTo: (position: Position) => void;\n /** The next corner round, or the nearest one if the panel is between them. */\n cycle: () => void;\n /** The chosen position, or null while the stylesheet is still in charge. */\n chosen: () => Fraction | null;\n dispose: () => void;\n}\n\nexport function storageKey(app: string): string {\n return `driverkit:widget:position:${app}`;\n}\n\n/** The real `localStorage`, if reaching for it does not throw — which it does\n * when site data is blocked, before any read has even been attempted. */\nexport function defaultStorage(): StorageLike | undefined {\n try {\n return (globalThis as { localStorage?: StorageLike }).localStorage;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Read one JSON value out of storage, or null for every way that can fail: no\n * storage, a throwing read, an empty slot, malformed JSON, or a shape `parse`\n * does not recognise.\n *\n * All of them mean the same thing to the caller — use the default — so none is\n * worth distinguishing, and none is worth breaking a chat panel over. A\n * private window and a person who blocked site data both throw on the way IN,\n * before any value has been looked at, which is why the `getItem` call and the\n * parsing are inside one try and not two.\n *\n * This is the only place in the package that reads persisted state. The\n * settings view keeps its own key and its own shape and goes through here, so\n * there is one mechanism to get the try/catch right in rather than two.\n */\nexport function loadJson<T>(\n storage: StorageLike | undefined,\n key: string,\n parse: (value: unknown) => T | null,\n): T | null {\n try {\n const raw = storage?.getItem(key);\n if (!raw) return null;\n return parse(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\n/** Write one JSON value, and swallow every reason it can fail. */\nexport function saveJson(storage: StorageLike | undefined, key: string, value: unknown): void {\n try {\n storage?.setItem(key, JSON.stringify(value));\n } catch {\n // A full quota, a private window, a user who blocked site data. The\n // position is still correct for this session; it just will not be\n // remembered, and that is not worth a thrown error inside a pointerup\n // handler that would leave the drag state wedged.\n }\n}\n\n/** A remembered position, or null if there is not one to be had. */\nexport function read(storage: StorageLike | undefined, app: string): Fraction | null {\n return loadJson(storage, storageKey(app), (value) => {\n const at = value as { fx?: unknown; fy?: unknown } | null;\n const fx = finite(at?.fx);\n const fy = finite(at?.fy);\n if (fx === null || fy === null) return null;\n return { fx: unit(fx), fy: unit(fy) };\n });\n}\n\nexport function write(storage: StorageLike | undefined, app: string, at: Fraction): void {\n saveJson(storage, storageKey(app), at);\n}\n\n/** The corner nearest `at`, and how far away it is in pixels. */\nexport function nearestCorner(at: Fraction, freeW: number, freeH: number): { corner: Corner; away: number } {\n let best: { corner: Corner; away: number } | null = null;\n for (const corner of CYCLE) {\n const c = CORNERS[corner]!;\n const away = Math.hypot((at.fx - c.fx) * Math.max(freeW, 0), (at.fy - c.fy) * Math.max(freeH, 0));\n if (!best || away < best.away) best = { corner, away };\n }\n return best!;\n}\n\n/** What a screen reader is told. Corners get their name; anywhere else gets\n * percentages, because \"0.37\" is not a place. */\nexport function describe(at: Fraction): string {\n for (const corner of CYCLE) {\n const c = CORNERS[corner]!;\n if (c.fx === at.fx && c.fy === at.fy) return corner.replace(\"-\", \" \");\n }\n return `${Math.round(at.fx * 100)}% across, ${Math.round(at.fy * 100)}% down`;\n}\n\nexport function positioner(options: PositionerOptions): Positioner {\n const host = options.host;\n const win = options.window ?? (globalThis as WindowLike);\n const gap = options.gap ?? 16;\n const threshold = options.snapThreshold ?? SNAP;\n const persist = options.persist !== false;\n const storage = persist ? (options.storage ?? defaultStorage()) : undefined;\n\n /** The position somebody chose, unclamped, or null while nobody has — in\n * which case `css.ts` is still in charge. */\n let chosen: Fraction | null = null;\n /** Where the stylesheet put the panel, read back off the layout once at\n * mount. Needed because the clamp has to be able to rescue the DEFAULT\n * position too: `:host` says \"flush right\", a window narrower than the\n * panel makes that mean \"off the left edge\", and no amount of CSS can\n * notice. */\n let fromCss: Fraction | null = null;\n /** Sticky. Once a custom property has been written inline there is no way to\n * un-write it with `StyleLike`, so after the first write this keeps writing\n * — otherwise a clamp applied in a narrow window would survive the window\n * being widened again, which is the bug the clamp exists to prevent. */\n let wrote = false;\n let dragging = false;\n let snapped = false;\n let disposed = false;\n\n {\n const m = measure();\n if (m) fromCss = fromLayout(m);\n }\n\n // Remembered beats the option: the option is the author's idea of where the\n // panel goes and the remembered one is where this particular person put it,\n // and the person was looking at their own screen when they decided.\n const remembered = read(storage, options.app);\n if (remembered) set(remembered, { save: false });\n // Not saved: the option is the author's default and saving it would turn\n // this person's storage into a copy of it, so the day the author changed the\n // option nobody would ever see the new one.\n else if (options.position !== undefined) applyPosition(options.position, false);\n // Mounting into a window that is already too narrow for the panel is the\n // same problem as resizing into one.\n else paint();\n\n const onResize: (event: EventLike) => void = () => {\n // Re-applied rather than recomputed: the chosen position is unchanged, but\n // the clamp it goes through is not, so a panel that was flush right in a\n // wide window and does not fit in a narrow one comes back to the near edge\n // — and returns to the right edge when the window is widened again.\n paint();\n };\n win.addEventListener?.(\"resize\", onResize);\n\n return {\n handle,\n key,\n moveTo,\n cycle,\n chosen: () => (chosen ? { ...chosen } : null),\n dispose: () => {\n disposed = true;\n win.removeEventListener?.(\"resize\", onResize);\n },\n };\n\n // -- applying ------------------------------------------------------------\n\n function set(at: Fraction, opts: { save: boolean; animate?: boolean }): void {\n chosen = { fx: unit(at.fx), fy: unit(at.fy) };\n snapped = opts.animate === true && !reducedMotion();\n paint();\n if (opts.save) write(storage, options.app, chosen);\n }\n\n function paint(): void {\n host.className = `dk-host${dragging ? \" dk-dragging\" : \"\"}${snapped ? \" dk-snap\" : \"\"}`;\n const at = chosen ?? fromCss;\n if (!at || !host.style) return;\n const m = measure();\n // The clamp, and the only place the viewport is allowed to override the\n // person: a panel wider than the window has to give up its fraction on\n // that axis or it ends up off the OPPOSITE edge, header first, with\n // nothing left to grab. The chosen value is not overwritten, so widening\n // the window puts the panel back where the person left it.\n const fx = m && m.freeW <= 0 ? 0 : at.fx;\n const fy = m && m.freeH <= 0 ? 0 : at.fy;\n // Nothing is written while the stylesheet is still in charge and the clamp\n // has nothing to say — that silence is what lets a host app position the\n // panel from its own CSS.\n if (chosen === null && !wrote && fx === at.fx && fy === at.fy) return;\n wrote = true;\n host.style.setProperty(\"--dk-x\", String(round(fx)));\n host.style.setProperty(\"--dk-y\", String(round(fy)));\n }\n\n function moveTo(position: Position): void {\n applyPosition(position, true);\n }\n\n function applyPosition(position: Position, save: boolean): void {\n if (isCorner(position)) {\n set(CORNERS[position], { save, animate: true });\n if (save) options.announce?.(`Panel moved to ${describe(CORNERS[position])}`);\n return;\n }\n const m = measure();\n // Without a measurable box there is no way to turn a pixel offset into a\n // fraction, and guessing would put the panel somewhere nobody asked for.\n // Leaving the stylesheet in charge is the honest failure.\n if (!m) return;\n set(\n {\n fx: m.freeW > 0 ? (position.x - gap) / m.freeW : 0,\n fy: m.freeH > 0 ? (position.y - gap) / m.freeH : 0,\n },\n { save, animate: true },\n );\n if (save) options.announce?.(`Panel moved to ${describe(chosen!)}`);\n }\n\n function cycle(): void {\n const m = measure();\n const at = current(m);\n if (!at || !m) return;\n const near = nearestCorner(at, m.freeW, m.freeH);\n // From between corners, the first press lands on the nearest one rather\n // than jumping across the screen; from a corner it advances.\n const next = near.away === 0 ? CYCLE[(CYCLE.indexOf(near.corner) + 1) % CYCLE.length]! : near.corner;\n set(CORNERS[next], { save: true, animate: true });\n options.announce?.(`Panel moved to ${describe(CORNERS[next])}`);\n }\n\n // -- geometry ------------------------------------------------------------\n\n interface Measurement {\n rect: RectLike;\n freeW: number;\n freeH: number;\n }\n\n function measure(): Measurement | null {\n const rect = host.getBoundingClientRect?.();\n const vw = win.innerWidth;\n const vh = win.innerHeight;\n // Null, rather than a zero-sized viewport, when the window cannot say how\n // big it is — which is what every non-browser host looks like. A clamp\n // against a viewport of 0x0 concludes that nothing fits and drags the\n // panel to the corner, which would be a confident answer derived from no\n // information at all.\n if (!rect || vw === undefined || vh === undefined || vw <= 0 || vh <= 0) return null;\n return { rect, freeW: vw - gap * 2 - rect.width, freeH: vh - gap * 2 - rect.height };\n }\n\n /** Where the panel is now, as a fraction. Derived from the measured box when\n * nobody has chosen a position, because in that case the answer lives in\n * the stylesheet and the layout is the only thing that knows it. */\n function current(m: Measurement | null): Fraction | null {\n if (chosen) return chosen;\n if (!m) return null;\n return fromLayout(m);\n }\n\n /** The fraction that produced this layout — the inverse of the arithmetic in\n * `css.ts`. On an axis with no free space the inverse does not exist, so it\n * falls back to the stylesheet's own default of 1 rather than inventing a\n * position; that is the case where the clamp is about to take over anyway. */\n function fromLayout(m: Measurement): Fraction {\n return {\n fx: m.freeW > 0 ? unit((m.rect.left - gap) / m.freeW) : 1,\n fy: m.freeH > 0 ? unit((m.rect.top - gap) / m.freeH) : 1,\n };\n }\n\n function reducedMotion(): boolean {\n try {\n return win.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n } catch {\n return false;\n }\n }\n\n // -- dragging ------------------------------------------------------------\n\n function handle(el: ElementLike, controls: \"ignore\" | \"allow\" = \"allow\"): () => boolean {\n let swallow = false;\n const swallowsClick = (): boolean => {\n const was = swallow;\n swallow = false;\n return was;\n };\n if (options.draggable === false) return swallowsClick;\n\n let drag: { id?: number; x: number; y: number; left: number; top: number; moved: boolean } | null = null;\n\n el.addEventListener(\"pointerdown\", (e) => {\n // Cleared on every press, not only on the presses that start a drag, so\n // a drag that ended without a click — released outside the handle, which\n // pointer capture makes normal — cannot leave a flag that swallows the\n // person's next real press of this same button.\n swallow = false;\n if (disposed) return;\n if (e.button !== undefined && e.button !== 0) return;\n if (controls === \"ignore\" && isControl(e.target)) return;\n const m = measure();\n if (!m) return;\n drag = {\n ...(e.pointerId === undefined ? {} : { id: e.pointerId }),\n x: e.clientX ?? 0,\n y: e.clientY ?? 0,\n left: m.rect.left,\n top: m.rect.top,\n moved: false,\n };\n // Stops the text selection and the native image-drag that otherwise\n // happen while a person is dragging a panel by its title.\n e.preventDefault?.();\n if (e.pointerId !== undefined) el.setPointerCapture?.(e.pointerId);\n });\n\n el.addEventListener(\"pointermove\", (e) => {\n if (!drag || !mine(e, drag.id)) return;\n const dx = (e.clientX ?? 0) - drag.x;\n const dy = (e.clientY ?? 0) - drag.y;\n // Below the slop NOTHING moves — not by a pixel. A launcher that shifts\n // under a click that was meant to open it reads as a bug.\n if (!drag.moved && Math.hypot(dx, dy) < SLOP) return;\n drag.moved = true;\n dragging = true;\n const m = measure();\n if (!m) return;\n // Clamped here and not only on release, so the panel never spends even\n // one frame with its header under the edge of the window.\n set(\n {\n fx: m.freeW > 0 ? (drag.left + dx - gap) / m.freeW : 0,\n fy: m.freeH > 0 ? (drag.top + dy - gap) / m.freeH : 0,\n },\n { save: false },\n );\n });\n\n const end = (e: EventLike): void => {\n if (!drag || !mine(e, drag.id)) return;\n const moved = drag.moved;\n const id = drag.id;\n drag = null;\n dragging = false;\n if (id !== undefined) el.releasePointerCapture?.(id);\n if (!moved) {\n paint();\n return;\n }\n // The click that follows a drag belongs to the drag. Without this,\n // nudging the collapsed launcher aside opens the panel on top of the\n // thing the person was trying to uncover.\n swallow = true;\n const m = measure();\n const at = current(m);\n if (!at || !m) return;\n const near = nearestCorner(at, m.freeW, m.freeH);\n const snapping = threshold > 0 && near.away <= threshold;\n set(snapping ? CORNERS[near.corner] : at, { save: true, animate: snapping });\n options.announce?.(`Panel moved to ${describe(chosen!)}`);\n };\n\n el.addEventListener(\"pointerup\", end);\n // A cancelled pointer is a pointer that is not coming back — the browser\n // took it for a scroll, the pen left the tablet. Treating it as a release\n // is what keeps the panel from being stuck to a pointer that no longer\n // exists.\n el.addEventListener(\"pointercancel\", end);\n el.addEventListener(\"lostpointercapture\", end);\n return swallowsClick;\n }\n\n function mine(e: EventLike, id: number | undefined): boolean {\n return id === undefined || e.pointerId === undefined || e.pointerId === id;\n }\n\n // -- keyboard ------------------------------------------------------------\n\n /**\n * Alt plus an arrow throws the panel to that edge; a bare arrow, which only\n * the move button sees, nudges it.\n *\n * Alt is the modifier because the bare arrows inside this panel already\n * belong to the text input and the transcript, and a positioning feature\n * that eats the Left arrow in a text field has broken typing to gain a\n * convenience. Alt+Arrow also works from the collapsed launcher, which is\n * the case that matters: the quickest way to see what the agent just did is\n * one keystroke that does not require finding anything first.\n *\n * The edge rather than a nudge, for the modified form, for the same reason\n * the snap exists — \"get out of my way\" is a corner, not an offset.\n */\n function key(event: EventLike, plain = false): boolean {\n const dir = ARROWS[event.key ?? \"\"];\n if (!dir) return false;\n const alt = event.altKey === true;\n if (!alt && !plain) return false;\n const m = measure();\n const at = current(m);\n if (!at) return false;\n const next = alt\n ? { fx: dir.x === 0 ? at.fx : dir.x < 0 ? 0 : 1, fy: dir.y === 0 ? at.fy : dir.y < 0 ? 0 : 1 }\n : { fx: at.fx + dir.x * STEP, fy: at.fy + dir.y * STEP };\n event.preventDefault?.();\n set(next, { save: true, animate: alt });\n options.announce?.(`Panel moved to ${describe(chosen!)}`);\n return true;\n }\n}\n\nconst ARROWS: Record<string, { x: number; y: number }> = {\n ArrowLeft: { x: -1, y: 0 },\n ArrowRight: { x: 1, y: 0 },\n ArrowUp: { x: 0, y: -1 },\n ArrowDown: { x: 0, y: 1 },\n};\n\n/** Something a click belongs to. A header is a drag handle and also the place\n * the Close button lives, and a person who presses Close and twitches two\n * pixels still meant Close. */\nfunction isControl(target: ElementLike | undefined): boolean {\n const tag = target?.tagName;\n return tag === \"BUTTON\" || tag === \"INPUT\" || tag === \"TEXTAREA\" || tag === \"SELECT\" || tag === \"A\";\n}\n\nfunction unit(n: number): number {\n return n < 0 ? 0 : n > 1 ? 1 : n;\n}\n\nfunction finite(n: unknown): number | null {\n return typeof n === \"number\" && Number.isFinite(n) ? n : null;\n}\n\n/** Four places is a tenth of a pixel on a 4K screen, and it keeps the value\n * written into CSS and into storage short enough to read in devtools. */\nfunction round(n: number): number {\n return Math.round(n * 1e4) / 1e4;\n}\n"]}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * What the person watching can change, and where it is kept.
3
+ *
4
+ * The requirement these exist for is one sentence: the agent drives the screen
5
+ * the person is looking at, so it should walk the UI slowly enough to watch,
6
+ * and the person should be able to see each step, slow it down, pause it, or
7
+ * stop it. Three of the four settings here are that sentence — a pace, a
8
+ * highlight, a step-every-call mode — and the fourth is `confirmCommits`,
9
+ * which already existed as a mount option and is surfaced here because this is
10
+ * where a person goes looking for it.
11
+ *
12
+ * They are per VIEWER, not per app. A pace is a statement about how fast this
13
+ * particular person reads, and `rememberChat` is a statement about what this
14
+ * person is willing to have written down on this machine, which is why they are
15
+ * remembered the way the panel's position is remembered — in `localStorage`, namespaced by app, with
16
+ * every read and write wrapped. See `loadJson` in `position.ts`: that is
17
+ * deliberately the only storage mechanism in this package, because two of them
18
+ * would be two places to get the try/catch wrong. Storage throws in a private
19
+ * window and with site data blocked, and a panel that fails to render because
20
+ * it could not remember a slider position would be a far worse bug than one
21
+ * that opens at the default speed.
22
+ */
23
+ import type { StorageLike } from "./dom.ts";
24
+ export interface Settings {
25
+ /** Milliseconds the agent waits between steps. See `SPEEDS`. */
26
+ pace: number;
27
+ /** Outline the element a verb is about to touch, when the verb names one.
28
+ * Default on: it costs nothing when a verb has no `at`, which is most of
29
+ * them, and when a verb does have one it is the difference between "the
30
+ * agent did something" and "the agent is about to touch THAT". */
31
+ highlight: boolean;
32
+ /** Require a press of Step for every single call, not just the first.
33
+ * Default off: it turns a run into a conversation, which is right when you
34
+ * are watching something you do not trust yet and tedious otherwise. */
35
+ stepMode: boolean;
36
+ /** Ask before every `commit` verb. Default on, matching `WidgetOptions`. */
37
+ confirmCommits: boolean;
38
+ /**
39
+ * Bring the conversation back after a page reload.
40
+ *
41
+ * The VIEWER's half of a two-key switch, and the weaker half. `WidgetOptions
42
+ * .rememberChat` decides whether a conversation is ever written down at all;
43
+ * this decides whether this particular person wants theirs kept, and it is
44
+ * read only where the app already said yes. So an app that must not write
45
+ * transcripts cannot be overruled from here, and a person on a shared machine
46
+ * can still say no to an app that would.
47
+ *
48
+ * It belongs beside the other four because this is where somebody goes
49
+ * looking for it — the same argument `confirmCommits` is surfaced here for.
50
+ * It is per viewer, so like the rest it lives in `localStorage` even though
51
+ * the thing it governs lives in `sessionStorage`: the preference outlives the
52
+ * tab and the conversation does not.
53
+ *
54
+ * Default on. Within an app that opted in, a panel that forgets the
55
+ * conversation it was told to remember is the surprising behaviour; the
56
+ * cautious default is one level up, where the app decides.
57
+ */
58
+ rememberChat: boolean;
59
+ }
60
+ /**
61
+ * The named speeds, slowest last.
62
+ *
63
+ * Named rather than a free slider, for two reasons. A number of milliseconds
64
+ * is not a thing anybody has an opinion about, and a radio group of four
65
+ * labelled buttons is reachable with a keyboard and announces itself, which a
66
+ * custom-styled `input[type=range]` in a shadow root manages only if somebody
67
+ * is careful about it forever.
68
+ *
69
+ * The range is chosen against what a person can actually follow:
70
+ *
71
+ * - 250ms is the floor. Below roughly two tenths of a second two consecutive
72
+ * changes to a screen read as one change, so a faster pace does not buy
73
+ * visibility, it only buys the feeling of it.
74
+ * - `WATCHABLE_PACE`, 600ms, is the middle and the default. It is the
75
+ * agent package's own judgement of a pace a person can follow, and it is
76
+ * reused rather than re-decided here: two files with two numbers for the
77
+ * same idea is how they drift.
78
+ * - 1.5s is for watching something you do not trust yet, where the question
79
+ * is not "what is it doing" but "is this the row I meant".
80
+ * - 3s is the ceiling. Twenty steps is the length of run this panel is built
81
+ * for, and twenty steps at three seconds is a minute of watching, which is
82
+ * already at the edge of what somebody will sit through. Slower than this
83
+ * and the honest answer is step mode, not a bigger number.
84
+ */
85
+ export declare const SPEEDS: ReadonlyArray<{
86
+ id: string;
87
+ label: string;
88
+ ms: number;
89
+ }>;
90
+ export declare const DEFAULT_PACE = 600;
91
+ export declare function defaults(confirmCommits: boolean): Settings;
92
+ /** The speed whose `ms` is nearest, so a stored or host-supplied pace that is
93
+ * not one of the four still lights up the button a person would recognise. */
94
+ export declare function nearestSpeed(ms: number): {
95
+ id: string;
96
+ label: string;
97
+ ms: number;
98
+ };
99
+ export declare function settingsKey(app: string): string;
100
+ /**
101
+ * The remembered settings, folded over the defaults.
102
+ *
103
+ * Field by field rather than whole-object, because a stored blob written by an
104
+ * older version of the widget is the normal case, not the exceptional one: a
105
+ * person has the panel open in a tab from last month. A missing field takes
106
+ * the default and a field of the wrong type is ignored, so neither can reach
107
+ * the UI as `undefined` and neither is a reason to throw away the three
108
+ * settings that were readable.
109
+ */
110
+ export declare function load(storage: StorageLike | undefined, app: string, base: Settings): Settings;
111
+ export declare function save(storage: StorageLike | undefined, app: string, settings: Settings): void;
112
+ /** A pace that is a real wait. Zero is allowed — a host that wants the old
113
+ * behaviour back should be able to ask for it — and the ceiling is there so a
114
+ * corrupt stored value cannot leave the panel apparently frozen. */
115
+ export declare function pace(ms: number): number;
116
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/widget/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,WAAW,QAAQ;IACvB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb;;;uEAGmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB;;6EAEyE;IACzE,QAAQ,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,cAAc,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,MAAM,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAK3E,CAAC;AAKF,eAAO,MAAM,YAAY,MAAiB,CAAC;AAE3C,wBAAgB,QAAQ,CAAC,cAAc,EAAE,OAAO,GAAG,QAAQ,CAQ1D;AAED;+EAC+E;AAC/E,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAMlF;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,WAAW,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,QAAQ,GACb,QAAQ,CAaV;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAE5F;AAED;;qEAEqE;AACrE,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGvC"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * What the person watching can change, and where it is kept.
3
+ *
4
+ * The requirement these exist for is one sentence: the agent drives the screen
5
+ * the person is looking at, so it should walk the UI slowly enough to watch,
6
+ * and the person should be able to see each step, slow it down, pause it, or
7
+ * stop it. Three of the four settings here are that sentence — a pace, a
8
+ * highlight, a step-every-call mode — and the fourth is `confirmCommits`,
9
+ * which already existed as a mount option and is surfaced here because this is
10
+ * where a person goes looking for it.
11
+ *
12
+ * They are per VIEWER, not per app. A pace is a statement about how fast this
13
+ * particular person reads, and `rememberChat` is a statement about what this
14
+ * person is willing to have written down on this machine, which is why they are
15
+ * remembered the way the panel's position is remembered — in `localStorage`, namespaced by app, with
16
+ * every read and write wrapped. See `loadJson` in `position.ts`: that is
17
+ * deliberately the only storage mechanism in this package, because two of them
18
+ * would be two places to get the try/catch wrong. Storage throws in a private
19
+ * window and with site data blocked, and a panel that fails to render because
20
+ * it could not remember a slider position would be a far worse bug than one
21
+ * that opens at the default speed.
22
+ */
23
+ import { WATCHABLE_PACE } from "../agent/control.js";
24
+ import { loadJson, saveJson } from "./position.js";
25
+ /**
26
+ * The named speeds, slowest last.
27
+ *
28
+ * Named rather than a free slider, for two reasons. A number of milliseconds
29
+ * is not a thing anybody has an opinion about, and a radio group of four
30
+ * labelled buttons is reachable with a keyboard and announces itself, which a
31
+ * custom-styled `input[type=range]` in a shadow root manages only if somebody
32
+ * is careful about it forever.
33
+ *
34
+ * The range is chosen against what a person can actually follow:
35
+ *
36
+ * - 250ms is the floor. Below roughly two tenths of a second two consecutive
37
+ * changes to a screen read as one change, so a faster pace does not buy
38
+ * visibility, it only buys the feeling of it.
39
+ * - `WATCHABLE_PACE`, 600ms, is the middle and the default. It is the
40
+ * agent package's own judgement of a pace a person can follow, and it is
41
+ * reused rather than re-decided here: two files with two numbers for the
42
+ * same idea is how they drift.
43
+ * - 1.5s is for watching something you do not trust yet, where the question
44
+ * is not "what is it doing" but "is this the row I meant".
45
+ * - 3s is the ceiling. Twenty steps is the length of run this panel is built
46
+ * for, and twenty steps at three seconds is a minute of watching, which is
47
+ * already at the edge of what somebody will sit through. Slower than this
48
+ * and the honest answer is step mode, not a bigger number.
49
+ */
50
+ export const SPEEDS = [
51
+ { id: "fast", label: "Fast", ms: 250 },
52
+ { id: "steady", label: "Steady", ms: WATCHABLE_PACE },
53
+ { id: "slow", label: "Slow", ms: 1500 },
54
+ { id: "crawl", label: "Crawl", ms: 3000 },
55
+ ];
56
+ /** The slowest pace worth offering, and the clamp for anything handed in. */
57
+ const MAX_PACE = 3000;
58
+ export const DEFAULT_PACE = WATCHABLE_PACE;
59
+ export function defaults(confirmCommits) {
60
+ return {
61
+ pace: DEFAULT_PACE,
62
+ highlight: true,
63
+ stepMode: false,
64
+ confirmCommits,
65
+ rememberChat: true,
66
+ };
67
+ }
68
+ /** The speed whose `ms` is nearest, so a stored or host-supplied pace that is
69
+ * not one of the four still lights up the button a person would recognise. */
70
+ export function nearestSpeed(ms) {
71
+ let best = SPEEDS[0];
72
+ for (const speed of SPEEDS) {
73
+ if (Math.abs(speed.ms - ms) < Math.abs(best.ms - ms))
74
+ best = speed;
75
+ }
76
+ return best;
77
+ }
78
+ export function settingsKey(app) {
79
+ return `driverkit:widget:settings:${app}`;
80
+ }
81
+ /**
82
+ * The remembered settings, folded over the defaults.
83
+ *
84
+ * Field by field rather than whole-object, because a stored blob written by an
85
+ * older version of the widget is the normal case, not the exceptional one: a
86
+ * person has the panel open in a tab from last month. A missing field takes
87
+ * the default and a field of the wrong type is ignored, so neither can reach
88
+ * the UI as `undefined` and neither is a reason to throw away the three
89
+ * settings that were readable.
90
+ */
91
+ export function load(storage, app, base) {
92
+ const stored = loadJson(storage, settingsKey(app), (value) => {
93
+ const s = value;
94
+ if (!s || typeof s !== "object")
95
+ return null;
96
+ return {
97
+ ...(typeof s.pace === "number" && Number.isFinite(s.pace) ? { pace: pace(s.pace) } : {}),
98
+ ...(typeof s.highlight === "boolean" ? { highlight: s.highlight } : {}),
99
+ ...(typeof s.stepMode === "boolean" ? { stepMode: s.stepMode } : {}),
100
+ ...(typeof s.confirmCommits === "boolean" ? { confirmCommits: s.confirmCommits } : {}),
101
+ ...(typeof s.rememberChat === "boolean" ? { rememberChat: s.rememberChat } : {}),
102
+ };
103
+ });
104
+ return { ...base, ...(stored ?? {}) };
105
+ }
106
+ export function save(storage, app, settings) {
107
+ saveJson(storage, settingsKey(app), settings);
108
+ }
109
+ /** A pace that is a real wait. Zero is allowed — a host that wants the old
110
+ * behaviour back should be able to ask for it — and the ceiling is there so a
111
+ * corrupt stored value cannot leave the panel apparently frozen. */
112
+ export function pace(ms) {
113
+ if (!Number.isFinite(ms) || ms < 0)
114
+ return DEFAULT_PACE;
115
+ return ms > MAX_PACE ? MAX_PACE : ms;
116
+ }
117
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/widget/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAuCnD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,MAAM,GAA6D;IAC9E,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE;IACtC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE;IACrD,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM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AAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACvC,CAAC","sourcesContent":["/**\n * What the person watching can change, and where it is kept.\n *\n * The requirement these exist for is one sentence: the agent drives the screen\n * the person is looking at, so it should walk the UI slowly enough to watch,\n * and the person should be able to see each step, slow it down, pause it, or\n * stop it. Three of the four settings here are that sentence — a pace, a\n * highlight, a step-every-call mode — and the fourth is `confirmCommits`,\n * which already existed as a mount option and is surfaced here because this is\n * where a person goes looking for it.\n *\n * They are per VIEWER, not per app. A pace is a statement about how fast this\n * particular person reads, and `rememberChat` is a statement about what this\n * person is willing to have written down on this machine, which is why they are\n * remembered the way the panel's position is remembered — in `localStorage`, namespaced by app, with\n * every read and write wrapped. See `loadJson` in `position.ts`: that is\n * deliberately the only storage mechanism in this package, because two of them\n * would be two places to get the try/catch wrong. Storage throws in a private\n * window and with site data blocked, and a panel that fails to render because\n * it could not remember a slider position would be a far worse bug than one\n * that opens at the default speed.\n */\n\nimport { WATCHABLE_PACE } from \"../agent/control.ts\";\n\nimport type { StorageLike } from \"./dom.ts\";\nimport { loadJson, saveJson } from \"./position.ts\";\n\nexport interface Settings {\n /** Milliseconds the agent waits between steps. See `SPEEDS`. */\n pace: number;\n /** Outline the element a verb is about to touch, when the verb names one.\n * Default on: it costs nothing when a verb has no `at`, which is most of\n * them, and when a verb does have one it is the difference between \"the\n * agent did something\" and \"the agent is about to touch THAT\". */\n highlight: boolean;\n /** Require a press of Step for every single call, not just the first.\n * Default off: it turns a run into a conversation, which is right when you\n * are watching something you do not trust yet and tedious otherwise. */\n stepMode: boolean;\n /** Ask before every `commit` verb. Default on, matching `WidgetOptions`. */\n confirmCommits: boolean;\n /**\n * Bring the conversation back after a page reload.\n *\n * The VIEWER's half of a two-key switch, and the weaker half. `WidgetOptions\n * .rememberChat` decides whether a conversation is ever written down at all;\n * this decides whether this particular person wants theirs kept, and it is\n * read only where the app already said yes. So an app that must not write\n * transcripts cannot be overruled from here, and a person on a shared machine\n * can still say no to an app that would.\n *\n * It belongs beside the other four because this is where somebody goes\n * looking for it — the same argument `confirmCommits` is surfaced here for.\n * It is per viewer, so like the rest it lives in `localStorage` even though\n * the thing it governs lives in `sessionStorage`: the preference outlives the\n * tab and the conversation does not.\n *\n * Default on. Within an app that opted in, a panel that forgets the\n * conversation it was told to remember is the surprising behaviour; the\n * cautious default is one level up, where the app decides.\n */\n rememberChat: boolean;\n}\n\n/**\n * The named speeds, slowest last.\n *\n * Named rather than a free slider, for two reasons. A number of milliseconds\n * is not a thing anybody has an opinion about, and a radio group of four\n * labelled buttons is reachable with a keyboard and announces itself, which a\n * custom-styled `input[type=range]` in a shadow root manages only if somebody\n * is careful about it forever.\n *\n * The range is chosen against what a person can actually follow:\n *\n * - 250ms is the floor. Below roughly two tenths of a second two consecutive\n * changes to a screen read as one change, so a faster pace does not buy\n * visibility, it only buys the feeling of it.\n * - `WATCHABLE_PACE`, 600ms, is the middle and the default. It is the\n * agent package's own judgement of a pace a person can follow, and it is\n * reused rather than re-decided here: two files with two numbers for the\n * same idea is how they drift.\n * - 1.5s is for watching something you do not trust yet, where the question\n * is not \"what is it doing\" but \"is this the row I meant\".\n * - 3s is the ceiling. Twenty steps is the length of run this panel is built\n * for, and twenty steps at three seconds is a minute of watching, which is\n * already at the edge of what somebody will sit through. Slower than this\n * and the honest answer is step mode, not a bigger number.\n */\nexport const SPEEDS: ReadonlyArray<{ id: string; label: string; ms: number }> = [\n { id: \"fast\", label: \"Fast\", ms: 250 },\n { id: \"steady\", label: \"Steady\", ms: WATCHABLE_PACE },\n { id: \"slow\", label: \"Slow\", ms: 1500 },\n { id: \"crawl\", label: \"Crawl\", ms: 3000 },\n];\n\n/** The slowest pace worth offering, and the clamp for anything handed in. */\nconst MAX_PACE = 3000;\n\nexport const DEFAULT_PACE = WATCHABLE_PACE;\n\nexport function defaults(confirmCommits: boolean): Settings {\n return {\n pace: DEFAULT_PACE,\n highlight: true,\n stepMode: false,\n confirmCommits,\n rememberChat: true,\n };\n}\n\n/** The speed whose `ms` is nearest, so a stored or host-supplied pace that is\n * not one of the four still lights up the button a person would recognise. */\nexport function nearestSpeed(ms: number): { id: string; label: string; ms: number } {\n let best = SPEEDS[0]!;\n for (const speed of SPEEDS) {\n if (Math.abs(speed.ms - ms) < Math.abs(best.ms - ms)) best = speed;\n }\n return best;\n}\n\nexport function settingsKey(app: string): string {\n return `driverkit:widget:settings:${app}`;\n}\n\n/**\n * The remembered settings, folded over the defaults.\n *\n * Field by field rather than whole-object, because a stored blob written by an\n * older version of the widget is the normal case, not the exceptional one: a\n * person has the panel open in a tab from last month. A missing field takes\n * the default and a field of the wrong type is ignored, so neither can reach\n * the UI as `undefined` and neither is a reason to throw away the three\n * settings that were readable.\n */\nexport function load(\n storage: StorageLike | undefined,\n app: string,\n base: Settings,\n): Settings {\n const stored = loadJson(storage, settingsKey(app), (value) => {\n const s = value as Record<string, unknown> | null;\n if (!s || typeof s !== \"object\") return null;\n return {\n ...(typeof s.pace === \"number\" && Number.isFinite(s.pace) ? { pace: pace(s.pace) } : {}),\n ...(typeof s.highlight === \"boolean\" ? { highlight: s.highlight } : {}),\n ...(typeof s.stepMode === \"boolean\" ? { stepMode: s.stepMode } : {}),\n ...(typeof s.confirmCommits === \"boolean\" ? { confirmCommits: s.confirmCommits } : {}),\n ...(typeof s.rememberChat === \"boolean\" ? { rememberChat: s.rememberChat } : {}),\n } satisfies Partial<Settings>;\n });\n return { ...base, ...(stored ?? {}) };\n}\n\nexport function save(storage: StorageLike | undefined, app: string, settings: Settings): void {\n saveJson(storage, settingsKey(app), settings);\n}\n\n/** A pace that is a real wait. Zero is allowed — a host that wants the old\n * behaviour back should be able to ask for it — and the ceiling is there so a\n * corrupt stored value cannot leave the panel apparently frozen. */\nexport function pace(ms: number): number {\n if (!Number.isFinite(ms) || ms < 0) return DEFAULT_PACE;\n return ms > MAX_PACE ? MAX_PACE : ms;\n}\n"]}