@tangle-network/agent-app 4.0.47 → 4.0.49

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.
@@ -9,14 +9,14 @@ import "../chunk-3HUFJ5LO.js";
9
9
  import "../chunk-7PULOECS.js";
10
10
  import "../chunk-E4AY62T2.js";
11
11
  import "../chunk-ELPNBEXJ.js";
12
- import "../chunk-4ZCUGJ6O.js";
12
+ import "../chunk-44RPVT2G.js";
13
13
  import "../chunk-Y6PRDUFJ.js";
14
14
  import "../chunk-GEYACSFW.js";
15
15
  import {
16
16
  ChatComposer
17
- } from "../chunk-S7GZ7XPC.js";
17
+ } from "../chunk-BQOS6XU3.js";
18
18
  import "../chunk-L7MB2LLM.js";
19
- import "../chunk-HHMELPDN.js";
19
+ import "../chunk-C3EGV2WQ.js";
20
20
  import "../chunk-5XGMMFF5.js";
21
21
  import "../chunk-2HQP2CTA.js";
22
22
  import "../chunk-CZVO2SPE.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  ComposerModeControls,
3
3
  EntryComposer
4
- } from "../chunk-S7GZ7XPC.js";
4
+ } from "../chunk-BQOS6XU3.js";
5
5
  import "../chunk-L7MB2LLM.js";
6
- import "../chunk-HHMELPDN.js";
6
+ import "../chunk-C3EGV2WQ.js";
7
7
  import "../chunk-2HQP2CTA.js";
8
8
  import "../chunk-CZVO2SPE.js";
9
9
  import "../chunk-E43PMYHD.js";
@@ -74,14 +74,14 @@ import {
74
74
  turnPromptText,
75
75
  valueRedactor,
76
76
  withProducerStream
77
- } from "../chunk-Y7FTBDFZ.js";
77
+ } from "../chunk-7JR5WWAP.js";
78
78
  import "../chunk-SBHFMDR7.js";
79
79
  import "../chunk-H6BRJU5M.js";
80
80
  import "../chunk-4DBHC63F.js";
81
81
  import "../chunk-RN4WPTBH.js";
82
82
  import "../chunk-MM6RLOXF.js";
83
83
  import "../chunk-M4QITAQV.js";
84
- import "../chunk-YLRH77J3.js";
84
+ import "../chunk-EHUSCRLY.js";
85
85
  import "../chunk-F4TUZYMX.js";
86
86
  import {
87
87
  redactErrorMessage
@@ -113,7 +113,7 @@ import "../chunk-QUV5M7SZ.js";
113
113
  import {
114
114
  assistantRowIdForTurn
115
115
  } from "../chunk-QM5TPZQY.js";
116
- import "../chunk-P6NVRUW6.js";
116
+ import "../chunk-OV4X4P6U.js";
117
117
  import "../chunk-YG66IHDU.js";
118
118
  import {
119
119
  attachmentInputToPart,
@@ -136,7 +136,7 @@ import {
136
136
  import {
137
137
  coalesceDeltas,
138
138
  createBufferedTurnTap
139
- } from "../chunk-FIH4MI6S.js";
139
+ } from "../chunk-YY3D7LYV.js";
140
140
  import {
141
141
  AGENT_HANDLE_PATTERN,
142
142
  ChatTurnInputError,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HarnessPicker,
3
3
  filterAcceptedFiles
4
- } from "./chunk-HHMELPDN.js";
4
+ } from "./chunk-C3EGV2WQ.js";
5
5
  import {
6
6
  EffortPicker,
7
7
  ModelPicker,
@@ -2382,4 +2382,4 @@ export {
2382
2382
  AGENT_PROFILE_EDITOR_SECTIONS,
2383
2383
  AgentProfileEditor
2384
2384
  };
2385
- //# sourceMappingURL=chunk-4ZCUGJ6O.js.map
2385
+ //# sourceMappingURL=chunk-44RPVT2G.js.map
@@ -30,7 +30,7 @@ import {
30
30
  sandboxRunFailureDetail,
31
31
  streamSandboxPrompt,
32
32
  turnStorageBindings
33
- } from "./chunk-YLRH77J3.js";
33
+ } from "./chunk-EHUSCRLY.js";
34
34
  import {
35
35
  redactErrorMessage
36
36
  } from "./chunk-MH74DY2I.js";
@@ -116,7 +116,7 @@ import {
116
116
  createBufferedTurnTap,
117
117
  replayTurnEvents,
118
118
  stampReplaySeq
119
- } from "./chunk-FIH4MI6S.js";
119
+ } from "./chunk-YY3D7LYV.js";
120
120
  import {
121
121
  ChatTurnInputError,
122
122
  DISPATCH_MAX_PARTS,
@@ -3814,4 +3814,4 @@ export {
3814
3814
  createChatTurnRoutes,
3815
3815
  streamChatRouteAsSandboxEvents
3816
3816
  };
3817
- //# sourceMappingURL=chunk-Y7FTBDFZ.js.map
3817
+ //# sourceMappingURL=chunk-7JR5WWAP.js.map
@@ -7,7 +7,7 @@ import {
7
7
  filterAcceptedFiles,
8
8
  isAcceptedFileType,
9
9
  renamePastedImages
10
- } from "./chunk-HHMELPDN.js";
10
+ } from "./chunk-C3EGV2WQ.js";
11
11
  import {
12
12
  useWorkspacePrewarmHandle
13
13
  } from "./chunk-2HQP2CTA.js";
@@ -1858,4 +1858,4 @@ export {
1858
1858
  ComposerModeControls,
1859
1859
  EntryComposer
1860
1860
  };
1861
- //# sourceMappingURL=chunk-S7GZ7XPC.js.map
1861
+ //# sourceMappingURL=chunk-BQOS6XU3.js.map
@@ -410,7 +410,7 @@ function HarnessPicker({ value, onChange, available, optionsOverride, defaultOpt
410
410
  ...defaultOption ? [{ value: "", label: defaultOption.label, icon: /* @__PURE__ */ jsx3(GearGlyph, { className: "h-4 w-4 shrink-0 text-muted-foreground" }) }] : [],
411
411
  ...(isHarness(value) && !ids.includes(value) ? [value, ...ids] : ids).map((h) => ({ value: h, label: harnessLabel(h), description: HARNESS_LABELS[h]?.[1], icon: glyph(h), ...optionsOverride?.[h] }))
412
412
  ];
413
- return /* @__PURE__ */ jsx3(ChoicePicker, { ...rest, variant, value, onChange: (v) => onChange(v), options, placeholder: "Select harness", title: "Harness" });
413
+ return /* @__PURE__ */ jsx3(ChoicePicker, { ...rest, variant, value, onChange: (v) => onChange(v), options, placeholder: rest.lockReason !== void 0 && value ? harnessLabel(value) : "Select harness", title: "Harness" });
414
414
  }
415
415
  function useCoherentHandlers(props) {
416
416
  const { model, models, harness, onModelChange, onHarnessChange, harnessLockReason } = props;
@@ -572,4 +572,4 @@ export {
572
572
  HarnessPicker,
573
573
  AgentSessionControls
574
574
  };
575
- //# sourceMappingURL=chunk-HHMELPDN.js.map
575
+ //# sourceMappingURL=chunk-C3EGV2WQ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/web-react/composer-file-accept.ts","../src/web-react/harness-glyphs.tsx","../src/web-react/agent-settings-popover.tsx","../src/web-react/agent-session-controls.tsx"],"sourcesContent":["/**\n * The composer's file-ingress filter, and the clipboard rename that goes with\n * it.\n *\n * A file reaches a composer by three routes — the picker dialog, a drag-and-drop,\n * and a clipboard paste — and only the picker gets a native `accept` filter (one\n * the user can defeat with \"All Files\"). Every route therefore funnels through\n * {@link filterAcceptedFiles}, so a type the picker will not offer cannot arrive\n * by another route instead.\n *\n * One route can still reach a different verdict, and it does so deliberately.\n * Paste is the only route that RENAMES, and {@link renamePastedImages} names a\n * file after the type it declares. So a clipboard bitmap called `image.png` that\n * declares `image/heic` is judged as `.heic` on paste, while the picker and a\n * drop judge the name they were handed and admit it under `accept=\".png\"`. The\n * filter is the same on all three; what differs is the name it is given, and\n * paste is stricter precisely because a rename that kept the contradicting name\n * would let the composer manufacture its own way past the filter.\n *\n * ONE accept matcher serves the package: `ChatComposer` gates its ingress on it\n * and `useComposerAttachments` gates `addFiles` on it. A second implementation\n * of the `accept` grammar is how the two ends of the same staging path start\n * disagreeing about what a file is.\n *\n * Pure data in, pure data out — nothing here throws, logs, or touches the DOM,\n * so a caller decides how a rejection is surfaced. Import-free beyond the\n * browser's own `File`, which keeps it usable from `/web-react`'s client bundle.\n */\n\n/** A file the `accept` list refused, with the reason to show for it. */\nexport interface ComposerFileRejection {\n file: File\n reason: string\n}\n\n/**\n * Checks one file against a comma-separated `accept` list, using the grammar of\n * the native `<input accept>` attribute: extensions (`.png`), exact MIME types\n * (`image/png`), and MIME wildcards (`image/*`). An absent or empty list accepts\n * everything, which is what an unset `accept` prop means.\n */\nexport function isAcceptedFileType(file: File, accept?: string): boolean {\n if (!accept || accept.trim().length === 0) return true\n\n const patterns = accept\n .split(',')\n .map((pattern) => pattern.trim())\n .filter((pattern) => pattern.length > 0)\n if (patterns.length === 0) return true\n\n const name = file.name.toLowerCase()\n const type = (file.type || '').toLowerCase()\n\n return patterns.some((pattern) => {\n const lower = pattern.toLowerCase()\n if (lower.startsWith('.')) return name.endsWith(lower)\n if (lower.endsWith('/*')) {\n // Keep the trailing \"/\" so `image/*` cannot match `imagex/png`, and\n // require a real subtype after it: `image/` and `image//png` are\n // malformed types, and a `File.type` can carry either.\n const prefix = lower.slice(0, -1)\n if (!type.startsWith(prefix)) return false\n const subtype = type.slice(prefix.length)\n return subtype.length > 0 && !subtype.includes('/')\n }\n return type === lower\n })\n}\n\n/** The reason an `accept` list refused a file. One wording for every ingress\n * route, so the same file reads the same whether it was picked or dropped. */\nexport function acceptRejectionReason(file: File, accept: string): string {\n return `\"${file.name}\" is not an accepted file type (${accept}).`\n}\n\n/**\n * Splits a batch into what the `accept` list admits and what it refuses. Size\n * and count limits are NOT applied here: they belong to the staging queue, which\n * knows what is already staged (`useComposerAttachments`), while this runs at the\n * composer's edge where that is unknown.\n */\nexport function filterAcceptedFiles(\n files: File[] | FileList,\n accept?: string,\n): { accepted: File[]; rejected: ComposerFileRejection[] } {\n const list = Array.isArray(files) ? files : Array.from(files)\n const accepted: File[] = []\n const rejected: ComposerFileRejection[] = []\n for (const file of list) {\n if (isAcceptedFileType(file, accept)) accepted.push(file)\n else rejected.push({ file, reason: acceptRejectionReason(file, accept ?? '') })\n }\n return { accepted, rejected }\n}\n\n/**\n * Extensions that truthfully name each image type, most canonical first. A type\n * with more than one is the reason this is a LIST and not a single name: `.jpeg`\n * and `.jpg` are the same claim, so a rename that swapped one for the other\n * would make a paste fail an `accept=\".jpeg\"` list that the very same file\n * passes through the picker.\n *\n * A type absent from here derives its single extension from the MIME subtype.\n */\nconst IMAGE_EXTENSIONS_BY_MIME: Record<string, readonly string[]> = {\n 'image/png': ['png'],\n 'image/jpeg': ['jpg', 'jpeg', 'jpe'],\n 'image/jpg': ['jpg', 'jpeg'],\n 'image/gif': ['gif'],\n 'image/webp': ['webp'],\n 'image/bmp': ['bmp'],\n 'image/svg+xml': ['svg'],\n 'image/tiff': ['tiff', 'tif'],\n 'image/x-icon': ['ico'],\n 'image/vnd.microsoft.icon': ['ico'],\n}\n\n/**\n * Matches EXACTLY the generic names browsers give a clipboard bitmap: an empty\n * name, `image`, or `image.<ext>`. Those are the names that collide across\n * pastes. A name that is only an extension (`.png`) is a real, if unusual,\n * filename and is left alone.\n */\nfunction isGenericImageName(name: string): boolean {\n return /^(?:image(?:\\.[a-z0-9]+)?)?$/i.test(name.trim())\n}\n\n/**\n * The extension a renamed clipboard image should carry, or null when none can\n * be derived truthfully.\n *\n * It must never name a format the bytes are not. A rename that hands an\n * `accept=\".png\"` list a file satisfying it by its new name alone turns the\n * rename into a way around the very gate it is filtered by.\n *\n * So the DECLARED TYPE decides which extensions are truthful, and the filename\n * may only pick among those. A clipboard file can carry a name whose extension\n * contradicts its type — a bitmap named `image.png` that is really `image/heic`\n * — and letting the name win there is exactly the hole this order closes. But\n * when the name's extension is one the type itself allows, it is kept: an\n * `image.jpeg` of type `image/jpeg` stays `.jpeg`, because rewriting it to the\n * canonical `.jpg` would make the paste fail an `accept=\".jpeg\"` list that the\n * same file passes through the picker.\n *\n * A subtype only stands in for an extension when it is already shaped like one.\n * `image/heic` is; `image/vnd.microsoft.icon` is not, and squeezing the\n * punctuation out of it would yield `vndmicrosofticon` — a name no accept list\n * will ever match, so a perfectly good `.ico` would be admitted through the\n * picker and refused on paste. An unrecognised compound type therefore names\n * nothing, and the filename is consulted instead.\n *\n * The filename is consulted on its own ONLY when the type names nothing usable\n * — either no subtype at all (`image/`) or a compound one. That is not an\n * exception to the rule above: the only named files this function ever sees are\n * `image.<ext>` (see {@link isGenericImageName}), so the fallback can only ever\n * preserve an extension the name already carried — it cannot manufacture one,\n * and an accept list therefore decides the same way it would have without the\n * rename. When nothing yields an extension, the caller skips the rename rather\n * than guessing.\n */\nfunction imageExtension(file: File): string | null {\n const type = file.type.toLowerCase()\n const fromName = /\\.([a-z0-9]+)$/i.exec(file.name)?.[1]?.toLowerCase()\n\n const mapped = IMAGE_EXTENSIONS_BY_MIME[type]\n const subtype = type.startsWith('image/') ? type.slice('image/'.length) : ''\n const bare = subtype.split('+')[0] ?? ''\n const truthful = mapped ?? (/^[a-z0-9]+$/.test(bare) ? [bare] : [])\n\n if (truthful.length === 0) return fromName ?? null\n if (fromName !== undefined && truthful.includes(fromName)) return fromName\n return truthful[0] ?? null\n}\n\n/** The `pasted-image-<n>` numbers these names already occupy. */\nfunction takenPastedImageIndexes(names: Iterable<string>): Set<number> {\n const taken = new Set<number>()\n for (const name of names) {\n const digits = /^pasted-image-(\\d+)(?:\\.[a-z0-9]+)?$/i.exec(name.trim())?.[1]\n if (digits === undefined) continue\n const parsed = Number.parseInt(digits, 10)\n if (Number.isSafeInteger(parsed)) taken.add(parsed)\n }\n return taken\n}\n\n/**\n * The lowest number above `after` that no name has claimed.\n *\n * Searching upward from the caller's own count — rather than from the highest\n * number any staged name happens to carry — is what keeps the usual case cheap:\n * staged numbers are avoided, never followed, so the walk advances at most once\n * per number already claimed.\n *\n * Termination does not rest on that, though, because `after` can be pushed near\n * the safe-integer ceiling and `+ 1` stops moving there — a walk that only\n * tested membership would spin on one value forever. The upward walk therefore\n * ends the moment a candidate leaves the safe range, and the search restarts\n * from the bottom, where a free number is guaranteed: `taken` is finite, so one\n * of the first `taken.size + 1` positive integers is always free. Every number\n * this returns is a safe integer, which is also what keeps an unsafe staged\n * name — invisible to {@link takenPastedImageIndexes} — impossible to collide\n * with.\n */\nfunction nextFreeIndex(taken: Set<number>, after: number): number {\n const start = Number.isSafeInteger(after) && after >= 0 ? after + 1 : 1\n for (let candidate = start; Number.isSafeInteger(candidate); candidate += 1) {\n if (!taken.has(candidate)) return candidate\n }\n for (let candidate = 1; ; candidate += 1) {\n if (!taken.has(candidate)) return candidate\n }\n}\n\n/**\n * Gives every generically-named clipboard image a distinct\n * `pasted-image-<n>.<ext>` name. Two pastes of the same bitmap otherwise arrive\n * as `image.png` twice, and a staging queue that keys on the name treats the\n * second as a duplicate of the first.\n *\n * A number is never reused. The search avoids every `pasted-image-<n>` already\n * present in `stagedNames` (the queue the host still holds, which outlives this\n * composer's own count) and in the batch itself (one paste can carry a file\n * already named that way beside a raw bitmap), so a collision is not reachable\n * rather than merely unlikely. `startIndex` is the caller's running count, and\n * `nextIndex` is the count to hand the next paste.\n *\n * Files that already carry a real name pass through untouched, so a copied\n * `report.pdf` keeps being `report.pdf`. So does an image whose extension\n * cannot be derived from what it declares — a renamed file must never claim a\n * format it is not. Only the name changes: the bytes, the type and the\n * modification time travel with it, so downstream fingerprinting still sees\n * the file the user pasted.\n */\nexport function renamePastedImages(\n files: File[],\n startIndex: number,\n stagedNames: Iterable<string> = [],\n): { files: File[]; nextIndex: number } {\n const taken = takenPastedImageIndexes([...stagedNames, ...files.map((file) => file.name)])\n // Whatever the caller's count is — a negative, a fraction, NaN, or a value at\n // the ceiling — `nextFreeIndex` normalises it and always answers with a safe\n // integer, so nothing here has to pre-screen it.\n let nextIndex = startIndex\n const renamed = files.map((file) => {\n const typed = file.type.startsWith('image/')\n // A clipboard file can arrive with no MIME type at all, and one named\n // `image.png` still collides across pastes exactly as a typed one does.\n // Its extension then comes from its own name, which cannot manufacture a\n // claim it did not already carry.\n if (!isGenericImageName(file.name) || (!typed && file.type !== '')) return file\n const extension = imageExtension(file)\n if (extension === null) return file\n nextIndex = nextFreeIndex(taken, nextIndex)\n taken.add(nextIndex)\n return new File([file], `pasted-image-${nextIndex}.${extension}`, {\n type: file.type,\n lastModified: file.lastModified,\n })\n })\n return { files: renamed, nextIndex }\n}\n","/**\n * Per-harness brand marks for the canonical pickers — the same marks the\n * legacy sandbox-ui harness picker (`dashboard/harness-logo.tsx`) shipped,\n * vendored as inline SVG so `/web-react` stays dependency-free beyond React:\n * sandbox-ui (and its `@lobehub/icons-static-svg` bundle) is an OPTIONAL peer\n * the canonical pickers must not force on a consumer. Geometry is the lobehub\n * single-color artwork, rendered in `currentColor` exactly as the legacy\n * component painted it (a foreground-filled CSS mask), so every mark tracks\n * the theme. Harnesses with no published brand mark get an honest inline\n * lucide glyph — bot / plug / terminal, the same fallbacks the legacy picker\n * used — and an unknown id falls back to the neutral bot. Data-record\n * structure mirrors `./provider-logo`.\n */\n\nimport type { ReactNode } from 'react'\nimport type { Harness } from '../harness'\n\nexport interface HarnessGlyphProps {\n /** Harness to mark. Typed as the canonical union; an out-of-union runtime\n * value still renders — it gets the neutral fallback glyph. */\n harness: Harness\n className?: string\n}\n\n// ── brand marks (single-color lobehub artwork, fill) ──────────────────────\n\nconst BRAND_PATHS: Partial<Record<Harness, readonly string[]>> = {\n opencode: [\n 'M16 6H8v12h8V6zm4 16H4V2h16v20z',\n ],\n 'claude-code': [\n 'M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z',\n ],\n codex: [\n 'M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z',\n ],\n amp: [\n 'M15.087 23.18L12.03 24l-2.097-7.823-5.738 5.738-2.251-2.251 5.718-5.719-7.769-2.082.82-3.057 11.294 3.08 3.08 11.295z',\n 'M19.505 18.762l-3.057.82-2.564-9.573-9.572-2.564.819-3.057 11.295 3.079 3.08 11.295z',\n 'M23.893 14.374l-3.057.82-2.565-9.572L8.7 3.057 9.52 0l11.295 3.08 3.079 11.294z',\n ],\n 'kimi-code': [\n 'M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z',\n ],\n openclaw: [\n 'M9.046 7.104a.527.527 0 110 1.055.527.527 0 010-1.055z',\n 'M15.376 7.104a.528.528 0 110 1.056.528.528 0 010-1.056z',\n 'M16.877 1.912c.58-.27 1.14-.323 1.616-.037a.317.317 0 01-.326.542c-.227-.136-.547-.153-1.022.068-.352.165-.765.45-1.234.866 2.683 1.17 4.4 3.5 5.148 5.921a6.421 6.421 0 00-.704.184c-.578.016-1.174.204-1.502.735-.338.55-.268 1.276.072 2.069l.005.012.007.014c.523 1.045 1.318 1.91 2.2 2.284-.912 3.274-3.44 6.144-5.972 6.988v2.109h-2.11v-2.11c-1.043.417-2.086.01-2.11 0v2.11h-2.11v-2.11c-2.531-.843-5.061-3.713-5.973-6.987.882-.373 1.678-1.238 2.2-2.284l.007-.014.006-.012c.34-.793.41-1.518.071-2.069-.327-.531-.923-.719-1.503-.735a6.409 6.409 0 00-.704-.183c.749-2.421 2.466-4.751 5.149-5.922-.47-.416-.88-.701-1.234-.866-.474-.221-.794-.204-1.021-.068a.318.318 0 01-.435-.109.317.317 0 01.109-.433c.476-.286 1.036-.233 1.615.037.49.229 1.031.628 1.621 1.182A9.924 9.924 0 0112 2.568c1.199 0 2.284.19 3.256.526.59-.554 1.13-.953 1.62-1.182zM8.835 6.577a1.266 1.266 0 100 2.532 1.266 1.266 0 000-2.532zm6.33 0a1.267 1.267 0 100 2.533 1.267 1.267 0 000-2.533z',\n 'M.395 13.118c-.966-1.932-.163-3.863 2.41-3.365v-.001l.05.01c.084.018.17.038.26.06.033.009.067.017.1.027.084.022.168.048.255.076l.09.027c.528 0 .95.158 1.16.501.212.343.212.87-.105 1.61-.085.17-.178.333-.276.489l-.01.017a4.967 4.967 0 01-.62.791l-.019.02c-1.092 1.117-2.496 1.336-3.295-.262z',\n 'M21.193 9.753c2.574-.5 3.378 1.433 2.411 3.365-.58 1.159-1.476 1.361-2.342.96l-.011-.005a2.419 2.419 0 01-.114-.056l-.019-.01a2.751 2.751 0 01-.115-.067l-.023-.014c-.035-.022-.071-.044-.106-.068l-.05-.035c-.55-.388-1.062-1.007-1.44-1.76-.276-.647-.311-1.132-.174-1.472.176-.439.636-.639 1.23-.639.032-.011.066-.02.099-.03.08-.026.16-.05.238-.072l.117-.03a5.502 5.502 0 01.3-.067z',\n ],\n hermes: [\n 'M5.938 12.835c.127-.039.285.02.373.143.028.038.036.092.046.14.003.014-.02.033-.04.05-.124-.098-.24-.194-.354-.291-.011-.01-.016-.027-.025-.042zM8.396 9.412c.195-.032.39-.06.588-.05a.54.54 0 01.148.026c.202.071.402.147.601.224.028.01.05.036.075.055l-.013.027a9.203 9.203 0 01-.26-.089c-.115-.038-.213-.077-.315-.098-.25-.05-.25-.046-.292-.014l.574.144c.275.139.55.276.823.417.042.022.09.057.107.098.026.06.063.076.117.072.066-.006.132-.017.213-.027l-.04.086c.051.08.142.02.216.064-.074.13-.247.09-.334.199l.061.074-.12.087c0 .106-.038.168-.306.243l.026.085-.196.042.07.124h-.25l-.007.137c-.081-.01-.161-.018-.244-.027l-.053.123c-.027-.008-.052-.011-.073-.023-.067-.038-.128-.056-.195.006-.019.017-.063.014-.093.008-.026-.006-.05-.029-.07-.042-.11.095-.11.095-.208.003-.057.046-.12.074-.186.011-.063.027-.123-.02-.178-.014-.07.007-.097-.035-.133-.07l-.13.033c-.013-.236-.194-.19-.34-.203.005-.072.05-.092.095-.094a.474.474 0 01.159.022c.164.05.32.12.496.138.203.021.405.029.601-.015.265-.059.52-.149.707-.365.049-.056.083-.127.117-.195.019-.038.02-.084-.02-.116a1.397 1.397 0 00-.382-.217c.024.12-.031.182-.115.221 0 .014-.004.025 0 .03.08.115.084.16-.007.267a1.39 1.39 0 01-.218.211.477.477 0 01-.641-.05 1.36 1.36 0 01-.133-.152c-.078-.107-.076-.108-.033-.236-.165-.08-.128-.226-.104-.364.008-.05.028-.096.049-.163-.04.014-.067.017-.087.032a.897.897 0 00-.316.357c-.007.016-.01.034-.02.047-.012.015-.034.038-.045.035-.02-.006-.037-.027-.05-.045-.008-.012-.007-.032-.012-.057h-.126l.053-.172a14.82 14.82 0 00-.039-.049l.11-.284c-.06.026-.091.044-.124.051-.03.007-.064 0-.095 0 0-.031-.01-.07.004-.092.149-.22.305-.428.593-.476z',\n 'M8.06 10.788c-.003-.038-.004-.075.037-.062.016.006.034.048.028.067-.01.04-.038.032-.064-.005z',\n 'M11.981.009c.226-.012.453-.011.679 0 .247.01.495.024.74.062.401.064.798.157 1.19.273.463.138.92.299 1.356.511a7.31 7.31 0 012.948 2.642c.292.469.536.963.739 1.479.219.556.446 1.11.623 1.683.204.654.329 1.326.458 1.997.097.504.182 1.01.29 1.511.156.722.329 1.44.494 2.16.186.812.4 1.615.63 2.415.102.355.193.713.282 1.072.11.436.202.876.254 1.323.031.278.066.557.073.837a7.56 7.56 0 01-.017.88c-.037.413-.1.818-.226 1.212a5.017 5.017 0 01-.915 1.649l-.13.156.018.023c.043-.023.088-.041.127-.068.2-.138.373-.307.531-.49.4-.46.721-.973.975-1.529a3.59 3.59 0 00.325-1.72c-.024-.424-.097-.834-.3-1.213-.013-.027-.015-.06-.03-.121.05.035.082.048.101.072.107.13.22.258.315.398.33.494.46 1.052.486 1.64a3.75 3.75 0 01-.47 1.97c-.36.655-.887 1.14-1.526 1.506-.193.111-.394.21-.595.308-.157.078-.248.211-.318.365a.522.522 0 00-.033.406.359.359 0 01.013.139c-.005.077-.077.155-.14.162-.054.006-.125-.043-.15-.116a1.206 1.206 0 01-.06-.233c-.04-.314-.155-.6-.308-.87a3.906 3.906 0 00-.73-.91 2.129 2.129 0 00-.897-.524 4.093 4.093 0 00-.692-.131c-.075-.008-.15-.04-.22.01.18.06.363.11.538.18.434.173.82.43 1.18.728.308.255.58.543.794.884.098.155.186.315.227.496.027.123.042.25.067.375.013.062-.002.109-.053.144-.047.033-.122.034-.163-.01a.455.455 0 01-.08-.14c-.03-.073-.038-.159-.078-.225a7.314 7.314 0 00-1.423-1.664c-.16-.137-.329-.26-.537-.323-.376-.114-.753-.203-1.15-.154-.213.025-.427.032-.64.053a1.6 1.6 0 00-.736.278 5.14 5.14 0 00-.834.72c-.329.342-.642.699-.955 1.055-.136.155-.264.319-.314.531a5.227 5.227 0 00-.012.051.096.096 0 01-.09.076h-.31c-.046 0-.082-.048-.072-.094.023-.108.045-.216.07-.324.075-.325.19-.635.368-.917.024-.039.04-.088.104-.08l.01.049.027.077c.28-.435.571-.834.996-1.135.283-.204.584-.378.89-.55a.196.196 0 00-.098-.002c-.162.043-.325.084-.485.134-.402.124-.764.33-1.11.566-.147.1-.298.193-.414.333a7.314 7.314 0 00-1.07 1.767.845.845 0 00-.04.12.075.075 0 01-.072.056h-.494c-.04 0-.062-.051-.036-.082.123-.14.246-.282.377-.415.275-.281.58-.532.777-.884.027-.048.063-.09.095-.135.238-.333.54-.607.818-.902.082-.086.175-.16.26-.24.029-.027.053-.057.079-.085l-.018-.025-.135.041c-.034.017-.07.031-.102.05-.248.144-.494.292-.743.433-.408.23-.825.439-1.209.711-.281.2-.591.358-.889.533-.02.012-.044.015-.08.028-.015-.135.143-.201.108-.336-.033.014-.064.02-.085.038-.111.096-.227.19-.328.296-.148.157-.284.325-.425.488-.125.143-.25.286-.373.431A.153.153 0 019.89 24H8.762a.316.316 0 00.016-.042c.028-.09.085-.172.083-.28-.091-.018-.162.001-.212.077a4.45 4.45 0 00-.136.215c-.01.016-.024.03-.042.03h-.093c-.019 0-.029-.022-.017-.037.071-.088.14-.178.209-.268.001-.002-.006-.012-.012-.024-.014.004-.03.006-.045.013-.176.09-.352.181-.527.274a.363.363 0 01-.168.042H5.202c-.026 0-.039-.036-.019-.053.21-.178.402-.374.558-.605.335-.496.538-1.047.667-1.629.004-.02-.003-.043-.006-.091-.037.048-.059.072-.076.1a1.943 1.943 0 01-.334.415c-.28.258-.59.448-.983.464-.297.012-.588 0-.865-.127-.46-.21-.722-.57-.794-1.072-.025-.17-.017-.171-.182-.219A3.513 3.513 0 011.97 20.6a2.286 2.286 0 01-.808-1.13 3.569 3.569 0 01-.16-1.245c.002-.034.016-.067.024-.1.032.023.046.043.05.066.033.153.059.308.096.46.086.355.257.664.516.92.258.256.571.419.91.532.358.118.717.138 1.07-.016a1.89 1.89 0 00.621-.452c.328-.348.533-.76.648-1.223.009-.034.005-.071.007-.11-.015.006-.026.006-.03.011-.031.05-.064.1-.093.152-.284.502-.679.887-1.196 1.135-.351.17-.718.255-1.11.159a1.607 1.607 0 01-.971-.64 2.006 2.006 0 01-.368-.924 2.903 2.903 0 01.02-.886c.05-.439.466-1.17.742-1.271-.02.063-.035.112-.053.16-.043.116-.097.227-.13.345a1.901 1.901 0 00-.05.82c.033.212.09.416.204.6.147.236.346.407.62.465.11.023.225.014.338.018a.576.576 0 00.386-.131c.164-.128.282-.292.366-.481.168-.375.24-.777.309-1.179.05-.296.093-.594.133-.893.039-.281.071-.563.104-.845.026-.232.048-.464.074-.696.024-.228.052-.455.076-.683.024-.227.047-.455.069-.683.013-.14.022-.28.034-.42l.037-.417c.022-.25.041-.5.065-.748.008-.082-.02-.132-.09-.177a2.46 2.46 0 01-.492-.418c-.1-.109-.188-.228-.282-.342-.035-.042-.056-.097-.116-.118a2.084 2.084 0 00.275.597c.06.092.131.176.196.265.063.086.182.115.234.226-.028.003-.046.01-.06.006a4.74 4.74 0 01-.22-.057 2.71 2.71 0 01-1.287-.819c-.435-.487-.656-1.076-.71-1.723a5.206 5.206 0 01.014-1.06c.072-.602.22-1.186.45-1.745.155-.376.338-.741.526-1.102.205-.393.466-.75.765-1.076.512-.559 1.104-1.024 1.726-1.448.717-.49 1.478-.898 2.277-1.233C8.244.828 8.767.632 9.31.494c.655-.166 1.31-.33 1.982-.415.229-.03.458-.058.688-.07zm-1.847 22.82c-.07.06-.147.111-.207.18-.238.27-.464.549-.668.869l-.044.108a.177.177 0 00.093-.057c.174-.19.351-.378.519-.574.104-.122.195-.255.288-.386.024-.034.03-.08.046-.12l-.027-.02zm1.65-3.695a5.51 5.51 0 00-.653.593l-.37.386a.963.963 0 01-.377.25 1.372 1.372 0 01-.467.09c-.044 0-.087.006-.151.012.028.058.043.097.064.131.15.242.301.482.45.724.136.22.276.438.399.666.068.125.105.267.156.404.077.027.14-.018.202-.048.29-.135.579-.274.867-.412.213-.101.437-.186.636-.31.347-.215.68-.455 1.018-.685.015-.01.026-.028.042-.046-.023-.019-.038-.037-.056-.044-.287-.111-.527-.3-.77-.482a5.319 5.319 0 01-.506-.42 1.757 1.757 0 01-.41-.653c-.019-.049-.045-.095-.075-.156zm-5.847.264c-.06.096-.097.194-.132.293a3.38 3.38 0 01-.555 1.01c-.2.25-.455.412-.762.493-.23.06-.464.076-.7.07-.048-.002-.097.002-.158.005.016.04.021.066.035.085.1.145.23.246.4.295.157.046.316.034.498.023.181-.037.343-.115.485-.234.238-.199.402-.454.536-.732.175-.363.264-.751.342-1.144.01-.053.008-.11.011-.164zm14.945-4.586c.008.029.016.057.027.107.024.155.051.31.072.464.03.219.067.437.078.657.017.344.027.689-.014 1.033-.037.315-.063.633-.116.946a6.153 6.153 0 01-.46 1.518c-.008.018-.01.039-.02.082.047-.03.077-.042.098-.064.085-.083.17-.167.248-.255.271-.305.458-.66.596-1.043.18-.498.228-1.011.145-1.531-.103-.65-.33-1.263-.597-1.881a9.055 9.055 0 00-.024-.055l-.033.022zM5.797 8.29a.26.26 0 00.018.153c.124.251.25.501.379.75.025.049.066.09.03.163-.284.06-.578.119-.88.255.059.038.097.06.132.087.042.032.112.058.09.12-.01.033-.075.048-.117.072.017.01.043.021.067.036.166.102.33.207.447.368.138.192.229.404.188.644-.079.469-.306.85-.69 1.132-.054.04-.106.083-.161.122a.243.243 0 00-.103.245.77.77 0 00.055.195c.083.196.22.35.375.492.083.076.159.164.222.257a.37.37 0 01.025.377c-.023.05-.05.099-.076.148-.03.06-.028.111.022.162.041.042.08.089.112.138.038.058.078.079.147.05a.486.486 0 01.333-.006c.16.046.302.126.444.21.13.077.264.149.4.219.067.035.14.05.219.026.071-.022.124.01.145.076.02.064-.003.108-.074.139-.07.03-.137.063-.209.088-.1.035-.201.073-.314.077-.013-.107.11-.088.127-.159-.206-.126-.643-.145-.801-.034.063.112.035.21-.096.313-.13-.1-.025-.202.002-.3a.209.209 0 00-.249.17c-.015.101.067.216.178.224.108.007.218-.005.326-.012.06-.005.12-.027.199 0-.103.123-.248.127-.357.19.002.05.07.086.019.131-.053.048-.095-.001-.132-.03-.08-.063-.16-.126-.231-.197a.474.474 0 01-.157-.311.52.52 0 00-.043-.172c-.032-.074-.032-.137.033-.19-.018-.03-.028-.053-.045-.072a1.222 1.222 0 01-.196-.369c-.053-.137-.046-.264.048-.381.024-.03.05-.06.064-.095a.664.664 0 00.047-.168c.017-.165-.064-.287-.182-.387-.186-.156-.36-.322-.46-.551-.005-.011-.024-.017-.037-.026-.011.017-.024.027-.025.038-.019.185-.045.37-.052.557-.014.377.058.743.162 1.104.118.41.289.798.488 1.173.267.502.537 1.002.812 1.5.055.098.13.189.208.27.198.202.452.272.724.273.202 0 .404-.006.605-.026.295-.03.59-.073.884-.113.183-.025.365-.057.548-.08.21-.026.38.073.522.21.16.156.305.327.447.5.22.265.397.56.554.867.05.098.07.1.147.03.13-.121.26-.242.394-.36.067-.059.088-.12.067-.213a3.535 3.535 0 01-.085-.796c.002-.157.006-.314.018-.471.015-.224.03-.45.06-.672a59.114 59.114 0 01.362-2.298c.087-.493.182-.984.268-1.477.06-.347.118-.694.162-1.043.034-.273.055-.55.063-.825.011-.332.003-.665.002-.998 0-.077.004-.155-.01-.23-.028-.142-.01-.155-.162-.19a5.826 5.826 0 00-.607-.107c-.146-.018-.207-.053-.221-.19-.006-.049-.025-.098-.041-.146-.009-.025-.024-.048-.046-.09l-.025.264c-.009.096-.029.116-.127.115-.055 0-.11-.008-.164-.008-.476 0-.952-.008-1.426.032-.095.008-.173-.015-.226-.103-.04-.066-.088-.126-.134-.186-.063-.084-.086-.093-.182-.06-.195.068-.388.138-.582.21a2.71 2.71 0 00-.675.394.986.986 0 01-.323.168c-.033.01-.07.008-.127.013.02-.066.024-.114.047-.15.064-.105.135-.205.205-.306.023-.033.049-.063.073-.095l-.015-.023-.201.037c-.146.04-.296.07-.437.122-.148.053-.266.023-.386-.072a3.623 3.623 0 01-.733-.786l-.093-.132zm8.592 8.963l-.147.09c-.22.134-.44.266-.659.402-.093.058-.184.12-.27.188-.085.07-.124.161-.072.272.047.1.093.2.147.294.047.08.124.138.213.147.11.01.228.012.336-.012.217-.05.372-.205.528-.357a.291.291 0 00.087-.308c-.046-.18-.079-.365-.118-.547-.011-.052-.027-.103-.045-.169zm-.257-2.409c-.12.291-.205.597-.325.91-.151.433-.294.87-.435 1.323.036-.01.054-.01.067-.018.261-.16.522-.324.785-.484.054-.033.071-.078.065-.138-.012-.13-.024-.262-.034-.393l-.068-.886c-.008-.103-.02-.206-.029-.31-.009 0-.017-.002-.026-.004zm3.081-8.13l.099.285c.08.231.159.463.24.714l.58 1.952c.187.63.372 1.262.558 1.893.114.382.235.762.343 1.146.072.257.126.519.186.799.044.206.087.413.127.64.034.106.023.226.077.325l.025-.006-.068-.362c-.038-.206-.077-.412-.113-.638-.015-.07-.029-.141-.046-.211-.095-.396-.177-.796-.29-1.187-.196-.685-.413-1.364-.618-2.046-.165-.549-.322-1.1-.488-1.648-.069-.227-.15-.45-.226-.695l-.117-.336c-.037-.107-.075-.216-.115-.322-.04-.106-.084-.21-.127-.314a7.558 7.558 0 01-.027.01zM6.225 14.304c-.063-.001-.115.014-.134.083a.35.35 0 00.41.012 4.533 4.533 0 00-.276-.095zM5.23 11.98c-.026-.027-.057-.048-.075.002-.012.032-.007.07-.01.113.082-.037.082-.037.085-.115zm.062-1.189a.135.135 0 00-.088.056.197.197 0 00-.025.11c.005.152.01.306.026.457a.751.751 0 00.066.218c.061.136.157.167.288.101.055-.027.06-.054.025-.11a4.52 4.52 0 01-.129-.211c-.015-.068-.066-.131-.033-.207.04-.09-.076-.116-.074-.19V10.874c-.003-.038-.006-.087-.056-.083zm-.017-.968a.867.867 0 00-.467.127c-.076.045-.084.07-.05.158.034.087.07.173.115.254.064.117.09.125.21.077a.657.657 0 01.336-.053c.202.022.357.136.504.264l.092.077c.007-.006.014-.013.022-.018-.019-.105-.035-.226-.149-.264-.157-.053-.324-.075-.508-.117l-.24-.005c.24-.169.452-.044.687.009-.063-.115-.153-.147-.23-.193-.082-.05-.17-.092-.25-.144-.06-.037-.12-.08-.072-.172zm10.233.325c-.23-.01-.427.08-.608.211-.034.026-.06.065-.105.117.087.026.15.046.232.065.044-.015.088-.03.13-.046.306-.114.61-.115.904.031.126.063.237.04.366-.005-.02-.031-.03-.054-.045-.071a.986.986 0 00-.448-.273c-.14-.044-.284-.024-.426-.03zM7.99 6.483a.308.308 0 00.002.133c.08.321.156.643.242.962.104.387.27.75.456 1.103.02.037.061.08.098.087a.404.404 0 00.253-.051l-.472-.84c-.23-.448-.405-.92-.579-1.394zM10.397.497c-.2-.008-.405.004-.603.034-.236.035-.47.087-.7.152-.287.08-.569.18-.852.273-.04.013-.074.038-.11.058.028.014.05.018.07.014.287-.068.58-.085.873-.09.134-.002.269.009.402.025.19.024.382.048.57.09.456.104.874.3 1.265.556.464.306.888.66 1.257 1.078.205.232.395.475.56.739.17.274.315.561.449.856.273.601.456 1.232.6 1.876.04.173.07.348.1.524.017.104.065.167.17.19.122.028.2.105.22.251-.003.102-.06.174-.129.24a1.065 1.065 0 00-.268.358.164.164 0 00.083-.039c.08-.086.162-.172.235-.265a.56.56 0 00.13-.333c.009-.05.022-.1.024-.15.007-.124-.017-.15-.143-.168-.025-.004-.049-.014-.073-.015-.082-.007-.125-.063-.137-.131-.033-.198-.004-.355.247-.408.086-.018.174-.03.26-.042.158-.023.315-.053.473-.067.14-.012.19.033.226.167.008.029.018.057.021.087.019.179-.008.225-.141.288-.027.013-.055.024-.078.042a.148.148 0 00-.051.067c-.039.144.073.382.206.445l.673.32c.023.011.05.015.075.023l.018-.026c-.015-.008-.032-.013-.044-.024a2.27 2.27 0 00-.544-.32 4.898 4.898 0 00-.173-.075.203.203 0 01-.126-.191c-.003-.085.045-.154.128-.187l.059-.025c.099-.044.118-.076.112-.187a.384.384 0 00-.008-.063c-.067-.294-.123-.59-.205-.88a9.478 9.478 0 00-.826-2.036 7.465 7.465 0 00-1.39-1.805 4.536 4.536 0 00-1.177-.824 3.656 3.656 0 00-1.016-.328 6.155 6.155 0 00-.712-.074zm6.719 5.955c.01.014.018.028.038.034l-.022-.044-.016.01zM4.103 3.917a.062.062 0 01-.03.012.455.455 0 01-.04.039c-.01.01-.02.02-.045.04l-.363.354c-.088.085-.17.178-.266.253-.284.22-.425.53-.544.855a.132.132 0 00-.007.071c.013.055.033.108.052.168l.074.026c-.017.056-.03.105-.047.152-.058.164-.118.327-.175.491-.005.015.008.036.019.077.08-.175.158-.33.225-.489.228-.544.484-1.074.819-1.561.09-.133.182-.266.283-.401.004-.006.007-.013.022-.03.001-.016.003-.032.015-.04l.008-.017zm12.976 2.408a.023.023 0 01.009.019.073.073 0 00-.006.01.188.188 0 00.007.02l.018.022c.002-.007.007-.016.005-.021-.003-.01-.012-.018-.02-.038a1.331 1.331 0 01-.013-.012zM4.199 4.48c-.003.004-.008.008-.027.014-.005.013-.011.025-.031.047a2.085 2.085 0 01-.124.167c-.048.07-.116.055-.181.041-.134-.028-.228.016-.287.143-.089.187-.187.37-.273.56-.049.108-.11.216-.118.36.081.003.154.007.228.008h.228a2.563 2.563 0 01-.079.264c-.01.052-.022.103-.033.155l.02.004c.018-.046.037-.092.067-.153.066-.142.13-.285.2-.426.02-.04.034-.1.116-.092 0 .043.004.084 0 .124-.005.045-.017.09-.028.143.141.043.086.174.115.269.102-.022.104-.195.248-.144v.205l.017.002.439-1.059c-.13 0-.246-.02-.358.033-.024.011-.058-.001-.108-.004.075-.15.139-.278.211-.417a.128.128 0 01.025-.036c0-.015-.001-.03.008-.038l.006-.02c-.005.006-.01.011-.028.017-.004.012-.009.024-.026.045a.085.085 0 01-.032.033c-.123.157-.09.164-.258.106-.079-.027-.078-.028-.047-.144.028-.046.056-.093.098-.15 0-.016-.001-.032.007-.042L4.2 4.48zm2.073-.67c-.003.006-.007.011-.027.016-.094.125-.194.246-.28.377-.155.238-.301.481-.451.723-.14.224-.345.368-.575.481-.017.008-.04.006-.079.011.012-.059.016-.109.033-.153a6.076 6.076 0 01.229-.518l-.007-.02a.138.138 0 01-.035.025c-.028.05-.055.1-.093.164-.26.424-.443.817-.442.95.024.004.048.011.073.013.177.013.188.007.26-.165.03-.07.077-.12.147-.15l.175-.07c.044-.018.085-.057.146-.032.003.05-.01.11.014.145.042.062.044.125.047.193.002.049.017.098.026.147.029-.034.039-.065.05-.097.142-.39.277-.782.428-1.17.1-.256.22-.504.33-.756.013-.03.013-.067.03-.092V3.81zm3.987-.34c0 .045.01.084.021.123.042.16.094.318.124.48.024.133.023.27.028.406 0 .033-.019.067-.032.11-.094-.058-.047-.158-.106-.215h-.125c-.015.072-.01.152-.046.2-.066.085-.155.154-.236.227-.043.038-.078.018-.103-.025l-.046-.087c-.065.035-.117.069-.172.093-.116.051-.235.095-.35.147-.085.038-.09.053-.07.147.014.075.034.148.047.223.013.072.05.109.123.124.233.05.462.115.657.265.058-.102.058-.102.168-.151.03-.014.06-.03.092-.042.08-.03.115-.017.15.06.023.048.041.098.066.158.06-.14-.042-.267.017-.416.157.18.24.39.375.567a.235.235 0 00.022-.098c.002-.124 0-.247.002-.371 0-.034.013-.067.02-.1l.032-.003c.11.155.13.354.226.52a3.036 3.036 0 00-.01-.392c-.004-.045 0-.074.05-.088.08.036.116.14.215.158-.03-.275-.423-1.137-.798-1.635-.114-.127-.2-.28-.34-.386zm-2.667.696c-.019.034-.03.05-.037.067-.061.185-.125.37-.18.556-.031.105-.087.169-.195.19-.09.019-.178.052-.268.073-.038.009-.089.015-.118-.003-.024-.016-.025-.069-.036-.106-.064.076-.082.087-.17.047-.133-.062-.262-.135-.393-.201-.048-.025-.093-.063-.17-.03-.043.12-.091.25-.137.382-.099.28-.087.242.095.453.046.048.102.03.154.023.054-.009.106-.03.16-.036.13-.013.26-.08.367-.015.204-.064.387-.122.571-.178.05-.015.089.005.114.054.022.042.034.093.082.121.038-.056-.013-.128.063-.178l.14.241-.042-1.46zm.278.358c-.096-.01-.107.01-.11.108-.002.038-.003.078.002.115.03.2.099.386.174.57.002.006.012.01.022.015l.078-.05c.052.036.081.088.153.088.205-.002.41.014.616.012.099-.001.158.042.205.12.018.03.024.077.088.066l-.08-.394c-.05-.195-.085-.395-.172-.589-.057.057-.114.068-.18.046a.72.72 0 00-.135-.028c-.22-.028-.44-.059-.66-.08zm10.254-1.727c.089.163.155.316.139.491-.016.168.026.342-.044.516-.047-.033-.088-.082-.112-.075-.117.035-.164-.057-.227-.115a4.772 4.772 0 01-.286-.29l-.104-.113a4.856 4.856 0 01-.023.019c.035.046.07.093.11.156.04.064.084.127.122.193.034.058.065.118.031.205-.082-.01-.164-.019-.246-.032-.06-.01-.101 0-.124.07-.031.098-.037.096-.15.09.02.042.036.08.057.116.041.074.03.138-.03.196-.06.06-.118.122-.178.181a.175.175 0 01-.185.046c-.222-.061-.447-.113-.67-.174-.032-.009-.063-.04-.086-.068-.03-.04-.052-.087-.08-.13-.044-.07-.09-.138-.136-.207a.18.18 0 00-.014.105c.012.127.03.253.035.38.005.1-.024.12-.121.104-.104-.017-.206-.04-.31-.058-.064-.012-.131-.028-.202.03l.081.208c.09 0 .166-.01.237.002a.819.819 0 01.458.251c.078.083.154.168.241.26l.018-.005c-.004-.006-.008-.013-.01-.04.014-.056-.062-.118.018-.178.031.03.064.057.088.09.058.078.111.159.169.257l.089.141.024-.013a2093.819 2093.819 0 01-.427-.934c.055.007.083.007.108.016.193.07.385.142.577.216.074.028.147.06.219.094.062.028.112.018.157-.033.05-.056.102-.112.154-.167.05-.051.095-.046.132.014.016.025.026.053.04.08.071.138.143.277.217.433l.159.308.025-.011c-.044-.106-.07-.218-.138-.334-.057-.182-.168-.346-.206-.545.136.034.362.326.567.732l.057.074.018-.011a1.563 1.563 0 01-.052-.127c-.046-.145-.097-.29-.136-.436-.022-.083-.036-.173.022-.26l.109.058-.026-.207.027-.016c.022.02.05.036.065.06.073.108.143.22.215.33.01.016.029.029.043.043-.036-.217-.2-.38-.229-.626l.155.112c.014-.166.012-.319.042-.465.032-.158-.023-.297-.063-.445.024.004.036.006.055.025.092.124.183.249.277.371.02.027.05.047.069.087l.04.063.019-.015a.293.293 0 01-.053-.082 27.922 27.922 0 01-.332-.49c-.221-.311-.363-.467-.485-.521zm-6.57.327c-.003.161.092.275.069.415l-.368.087c.09.139.032.237-.052.331-.05.057-.092.122-.143.178-.037.04-.046.078-.018.126l.16.275c.029.048.072.066.128.064.076-.003.152 0 .228-.001.116-.003.216.022.275.137.006.014.02.024.044.052.004-.059-.003-.098.01-.13.016-.04.04-.099.072-.108.084-.023.173-.024.26-.03.013-.001.027.018.04.029l.071.065c.019-.11-.082-.198-.024-.31l.126.04c-.026-.123-.07-.245-.071-.366 0-.123.051-.243.115-.36.107.062.16.156.234.253.183.265.36.533.494.834.165-.078.27.068.407.088-.003-.106-.133-.441-.197-.492a.142.142 0 00-.102-.028c-.06.011-.119.039-.191.063-.025-.039-.056-.078-.077-.122a3.936 3.936 0 00-.473-.783c-.076-.094-.16-.182-.228-.26l-.391.285c-.049.035-.094.03-.132-.017l-.169-.207c-.025-.03-.053-.059-.097-.108z',\n ],}\n\n// ── honest fallbacks for harnesses with no published brand mark ───────────\n// Inline lucide paths (v1.27, ISC) — `/web-react` ships no icon-library\n// dependency, so the stroke glyphs here match the set in `./controls`.\n\nfunction BotGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 8V4H8\" />\n <rect width=\"16\" height=\"12\" x=\"4\" y=\"8\" rx=\"2\" />\n <path d=\"M2 14h2\" />\n <path d=\"M20 14h2\" />\n <path d=\"M15 13v2\" />\n <path d=\"M9 13v2\" />\n </svg>\n )\n}\n\nfunction PlugGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 22v-5\" />\n <path d=\"M15 8V2\" />\n <path d=\"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z\" />\n <path d=\"M9 8V2\" />\n </svg>\n )\n}\n\nfunction TerminalGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 19h8\" />\n <path d=\"m4 17 6-6-6-6\" />\n </svg>\n )\n}\n\n/** Lucide fallback per harness without a brand mark — the same assignments\n * the legacy picker shipped (`factory-droids`→bot, `nanoclaw`→plug,\n * `cli-base`→terminal). */\nconst FALLBACK_GLYPHS: Partial<Record<Harness, (props: { className?: string }) => ReactNode>> = {\n 'factory-droids': BotGlyph,\n nanoclaw: PlugGlyph,\n 'cli-base': TerminalGlyph,\n}\n\n/**\n * Brand mark for a harness — size it from the call site (`className=\"h-4\n * w-4\"`). Unknown ids render the neutral bot, never an invented logo.\n * `data-glyph` names the resolved mark so tests and stories can assert\n * brand-vs-fallback without snapshotting path data.\n */\nexport function HarnessGlyph({ harness, className }: HarnessGlyphProps): ReactNode {\n const brand = BRAND_PATHS[harness]\n if (brand) {\n return (\n <svg\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n role=\"img\"\n aria-label={harness}\n data-glyph={harness}\n >\n {brand.map((d) => (\n <path key={d.slice(0, 32)} d={d} />\n ))}\n </svg>\n )\n }\n const Fallback = FALLBACK_GLYPHS[harness] ?? BotGlyph\n const kind = Fallback === BotGlyph ? 'bot' : Fallback === PlugGlyph ? 'plug' : 'terminal'\n return (\n <span role=\"img\" aria-label={harness} data-glyph={kind} className=\"inline-flex\">\n <Fallback className={className} />\n </span>\n )\n}\n","import { useCallback, useEffect, useState, type ReactNode } from 'react'\nimport { OVERLAY_SHADOW, PopoverSurface } from './controls'\nimport { usePopoverDialog } from './popover-dialog'\n\nexport interface AgentSettingsPopoverProps {\n /** Accessible name of the trigger and its non-modal dialog. */\n label?: string\n /** Current profile or model, kept visible without opening the panel. */\n summary?: ReactNode\n children: ReactNode\n open?: boolean\n onOpenChange?: (open: boolean) => void\n disabled?: boolean\n className?: string\n panelClassName?: string\n}\n\n/** One settings surface for entry, docked and embedded composers. No selection policy. */\nexport function AgentSettingsPopover({\n label = 'Agent settings', summary, children, open: controlledOpen,\n onOpenChange, disabled = false, className, panelClassName,\n}: AgentSettingsPopoverProps) {\n const [localOpen, setLocalOpen] = useState(false)\n const open = !disabled && (controlledOpen ?? localOpen)\n const changeOpen = useCallback((next: boolean) => {\n setLocalOpen(next)\n onOpenChange?.(next)\n }, [onOpenChange])\n useEffect(() => { if (disabled) changeOpen(false) }, [disabled, changeOpen])\n const { containerRef, triggerRef, panelRef, triggerProps, id } = usePopoverDialog(open, changeOpen)\n return (\n <div ref={containerRef} className={`inline-flex min-w-0 max-w-full ${className ?? ''}`}>\n <button\n type=\"button\" {...triggerProps} disabled={disabled}\n aria-label={label} title={label} data-agent-settings-trigger=\"\"\n onClick={() => changeOpen(!open)} data-state={open ? 'open' : 'closed'}\n className=\"inline-flex h-[var(--control-height-sm,2rem)] max-w-[15rem] items-center gap-1.5 rounded-full border border-border bg-transparent px-2.5 text-sm font-normal text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=open]:text-foreground disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <svg className=\"h-4 w-4 shrink-0\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" aria-hidden>\n <rect x=\"4\" y=\"7\" width=\"16\" height=\"14\" rx=\"3\" /><path d=\"M12 7V3M9 3h6M1 12v4m22-4v4m-15-3h.01M16 13h.01M9 17h6\" />\n </svg>\n <span className=\"min-w-0 truncate\">{summary ?? label}</span>\n <svg className=\"h-3 w-3 shrink-0\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" aria-hidden><path d=\"m6 9 6 6 6-6\" /></svg>\n </button>\n <PopoverSurface\n open={open} id={id} role=\"dialog\" aria-label={label}\n triggerRef={triggerRef} panelRef={panelRef}\n className={`w-80 max-w-[calc(100vw-2rem)] space-y-4 overflow-y-auto rounded-xl border border-card-edge bg-popover p-4 text-foreground ${OVERLAY_SHADOW} ${panelClassName ?? ''}`}\n >\n {children}\n </PopoverSurface>\n </div>\n )\n}\n","/**\n * `AgentSessionControls` — the CANONICAL model + harness + reasoning-effort\n * cluster a chat composer docks (see \"UI chrome ownership (picker canon)\" in\n * AGENTS.md). One component so every product's two composers (and every\n * product) share the same control surface and harness↔model coherence policy.\n *\n * PICKER CANON. The model menu below IS `/web-react`'s `ModelPicker` and the\n * thinking-budget pill IS `EffortPicker` — the canonical ecosystem pickers.\n * sandbox-ui's `dashboard/ModelPicker` and the model menu inside sandbox-ui's\n * `chat/AgentSessionControls` are legacy (deprecated, frozen, removed at\n * sandbox-ui's next major), and the `/chat-react` `ComposerAgentControls`\n * adapter that rendered sandbox-ui's strip is REMOVED — a surface that still\n * renders the sandbox-ui strip is showing the old design; migrate it\n * (props mapping in `docs/ui-picker-canon.md`).\n *\n * Dependency-free beyond React by design: `/web-react` must not force the\n * optional sandbox-ui peer, so this component — the canonical one — can never\n * require it.\n *\n * Two layouts, additive — the default preserves the prior hand-rolled behavior:\n * - `layout=\"inline\"` (default): model, harness, and effort sit side by side as\n * pills. This is the original arrangement; existing call sites that mounted\n * `ModelPicker` + a harness picker + `EffortPicker` in a row get the same UI.\n * - `layout=\"compact\"`: the model picker stays inline and visible; the\n * harness and reasoning-effort controls — settings a user rarely needs —\n * tuck behind a single gear popover with plain-English copy.\n *\n * Two trigger treatments, also additive (`variant`, see `PickerVariant` in\n * `./controls`): `chip` (default) is the bordered pill every child draws\n * today; `quiet` is the borderless text button, for a composer whose card\n * already draws the border. The variant reaches every child in both layouts.\n *\n * Harness ↔ model coherence is identical in both layouts, via the substrate's\n * snap helpers (`@tangle-network/agent-app/harness`): changing the harness snaps\n * an incompatible model to that harness's best catalog option; changing the\n * model switches to the model's native harness. Catalog model ids are canonical\n * (\"provider/model\"), which is exactly what the snap helpers expect — no id\n * translation is needed here.\n */\n\nimport { useId, useMemo, useRef, useState, type ReactNode } from 'react'\nimport {\n isHarness,\n isModelCompatibleWithHarness,\n snapHarnessToModel,\n snapModelToHarness,\n type Harness,\n} from '../harness'\nimport type { CatalogModel } from '../runtime/model-catalog'\nimport { ModelPicker, EffortPicker, CheckGlyph, fieldPickerTriggerClass, OVERLAY_SHADOW, pickerRootClass, PopoverSurface, quietPickerTriggerClass, usePopover } from './controls'\nimport type { EffortLevel, PickerVariant } from './controls'\nimport { PickerTrigger } from './picker-presentation'\nimport { HarnessGlyph } from './harness-glyphs'\nimport { AgentSettingsPopover } from './agent-settings-popover'\n\n/** Each harness's name, which the trigger shows, and the qualifier its menu row\n * adds beneath it. Unknown ids fall back to the raw value so a new backend\n * still renders a usable label. */\nconst HARNESS_LABELS: Partial<Record<Harness, readonly [name: string, description?: string]>> = {\n opencode: ['OpenCode', 'Any model'],\n 'claude-code': ['Claude Code', 'Anthropic models'],\n codex: ['Codex', 'OpenAI models'],\n 'kimi-code': ['Kimi', 'Moonshot models'],\n amp: ['Amp'],\n 'factory-droids': ['Factory Droids'],\n cursor: ['Cursor'],\n hermes: ['Hermes'],\n pi: ['Pi'],\n openclaw: ['OpenClaw'],\n acp: ['ACP'],\n 'cli-base': ['CLI'],\n}\n\nconst harnessLabel = (h: Harness): string => HARNESS_LABELS[h]?.[0] ?? h\n\n/** lucide `lock` — the closed padlock on a pinned harness trigger. */\nfunction LockGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <rect width=\"18\" height=\"11\" x=\"3\" y=\"11\" rx=\"2\" ry=\"2\" />\n <path d=\"M7 11V7a5 5 0 0 1 10 0v4\" />\n </svg>\n )\n}\n\nfunction GearGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n <path d=\"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z\" />\n </svg>\n )\n}\n\n/**\n * A single-choice picker: the shared `PickerTrigger` and a menu of rows, each a\n * label over an optional one-line muted description that ends in an ellipsis\n * when it does not fit (the row's `title` carries the full text). `HarnessPicker`\n * is this picker over the harness set.\n *\n * The chip is the shared `PickerTrigger` (a `Chip`), not `rounded-lg` at whatever\n * height the padding gives: this pill sits beside `ModelPicker` and\n * `EffortPicker` in both layouts, all three the same Chip. A single odd-shaped control\n * is what made the compact popover read as a pile of unrelated widgets rather\n * than one selector stack. The `quiet` variant holds the same rule the other\n * way: its 28px text-button geometry comes from the one\n * `quietPickerTriggerClass` the other two triggers use.\n *\n * `fullWidth` is opt-in and means what it means on `EffortPicker` — see\n * {@link pickerRootClass}.\n *\n * `lockReason` PINS the control: it keeps its selector shape and keeps\n * reporting the harness the thread is on, opens nothing, and explains itself\n * on hover AND on keyboard focus. Three deliberate choices there:\n *\n * - `aria-disabled`, never the native `disabled` attribute. A disabled button\n * is removed from the tab order and fires no pointer events in most\n * browsers, so the one control that has something to explain would become\n * the one control that can never be asked.\n * - the reason rides a permanent visually-hidden node that `aria-describedby`\n * points at, so assistive tech has it whether or not the floating hint is\n * up; the floating copy is `aria-hidden` so nothing is announced twice.\n * - the hint is a {@link PopoverSurface}, not an absolutely-positioned div —\n * the compact panel is an `overflow-y-auto` box, which clips a positioned\n * descendant, and that surface is this package's answer to exactly that.\n */\n/** `description` is one muted line under the label, truncated with an ellipsis; the row's title carries the full text. */\nexport interface ChoiceOption { value: string; label: string; description?: string; icon?: ReactNode; /** A row that cannot be chosen; its description says why. */ disabled?: boolean }\n\nexport interface ChoicePickerProps {\n value: string\n onChange: (value: string) => void\n options: readonly ChoiceOption[]\n /** The trigger's text when `value` matches no option. */\n placeholder?: string\n fullWidth?: boolean\n /** Pin the control and say why; see the component notes. */\n lockReason?: string\n variant?: PickerVariant\n /** Disable the trigger; unlike `lockReason` it explains nothing. */\n disabled?: boolean\n id?: string\n title?: string\n 'aria-label'?: string\n 'aria-describedby'?: string\n}\n\nexport function ChoicePicker({ value, onChange, options, placeholder = '', fullWidth = false, lockReason, variant = 'chip', disabled = false,\n id, title, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy }: ChoicePickerProps) {\n const [requestedOpen, setOpen] = useState(false)\n const open = requestedOpen && !disabled\n const [hintOpen, setHintOpen] = useState(false)\n const { containerRef, triggerRef, panelRef, triggerProps } = usePopover(open, setOpen)\n const hintPanelRef = useRef<HTMLDivElement>(null)\n const panelId = useId()\n const reasonId = useId()\n const locked = lockReason !== undefined\n const field = variant === 'field'\n const showHint = () => setHintOpen(true)\n const hideHint = () => setHintOpen(false)\n const selected = options.find((o) => o.value === value)\n const choose = (next: string) => {\n onChange(next)\n setOpen(false)\n }\n return (\n <div ref={containerRef} className={pickerRootClass(fullWidth || field)}>\n <PickerTrigger variant={variant} icon={selected?.icon} trailing={locked ? <LockGlyph className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" /> : undefined}\n {...triggerProps}\n id={id}\n disabled={disabled}\n aria-label={ariaLabel}\n aria-haspopup={locked ? undefined : true}\n aria-expanded={locked ? undefined : open}\n aria-controls={!locked && open ? panelId : undefined}\n aria-disabled={locked || undefined}\n aria-describedby={[locked ? reasonId : undefined, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n onClick={locked ? undefined : () => setOpen(!open)}\n onMouseEnter={locked ? showHint : undefined}\n onMouseLeave={locked ? hideHint : undefined}\n onFocus={locked ? showHint : undefined}\n onBlur={locked ? hideHint : undefined}\n title={title}\n data-state={!locked && open ? 'open' : 'closed'}\n className={\n field\n ? fieldPickerTriggerClass({ interactive: !locked && !disabled })\n : variant === 'quiet'\n ? `${quietPickerTriggerClass({ interactive: !locked })} w-full justify-between`\n : `w-full ${locked ? 'cursor-default hover:bg-transparent' : ''}`\n }\n >\n <span className={`flex min-w-0 items-center ${field ? 'flex-1 gap-2' : 'gap-1.5'}`}>\n {variant !== 'chip' && selected?.icon}\n <span className={`truncate ${value ? '' : 'text-muted-foreground'}`}>{selected?.label ?? placeholder}</span>\n </span>\n </PickerTrigger>\n {locked && (\n <>\n <span id={reasonId} className=\"sr-only\">\n {lockReason}\n </span>\n <PopoverSurface\n open={hintOpen}\n role=\"tooltip\"\n triggerRef={triggerRef}\n panelRef={hintPanelRef}\n matchTriggerWidth={fullWidth || field}\n className={`max-w-[248px] rounded-lg border border-card-edge bg-popover px-2.5 py-1.5 text-sm leading-snug text-muted-foreground ${OVERLAY_SHADOW}`}\n >\n <span aria-hidden>{lockReason}</span>\n </PopoverSurface>\n </>\n )}\n <PopoverSurface\n open={!locked && open}\n id={panelId}\n role=\"menu\"\n triggerRef={triggerRef}\n panelRef={panelRef}\n matchTriggerWidth\n side={field ? 'below' : undefined}\n className={`max-h-64 min-w-[248px] max-w-[min(24rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-card-edge bg-popover p-1 ${OVERLAY_SHADOW}`}\n >\n {options.map((o) => (\n <button\n key={o.value}\n type=\"button\" disabled={o.disabled}\n role=\"menuitemradio\"\n aria-checked={o.value === value}\n title={o.description ? `${o.label} — ${o.description}` : o.label}\n onClick={() => choose(o.value)}\n className={`flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-left text-sm transition disabled:cursor-not-allowed disabled:opacity-60 ${\n o.value === value ? 'bg-primary/10 font-medium' : o.disabled ? '' : 'hover:bg-accent'\n }`}\n >\n {o.icon}\n <span className=\"min-w-0 flex-1\"><span className=\"block truncate\">{o.label}</span>{o.description && <span className=\"block truncate text-xs font-normal text-muted-foreground\">{o.description}</span>}</span>\n {o.value === value && <CheckGlyph className=\"h-3.5 w-3.5 shrink-0 text-primary\" />}\n </button>\n ))}\n </PopoverSurface>\n </div>\n )\n}\n\nexport type HarnessPickerProps = Omit<ChoicePickerProps, 'value' | 'onChange' | 'options' | 'placeholder' | 'title'> & {\n /** The selected harness, or `''` for none when {@link HarnessPickerProps.defaultOption} is offered. */\n value: Harness | ''\n onChange: (h: Harness | '') => void\n /** Harnesses to offer; defaults to the labeled set. */\n available?: ReadonlyArray<Harness>\n /** A harness's own label, description or disabled state, such as its seat's room or why it cannot run now. */\n optionsOverride?: Partial<Record<string, Partial<Pick<ChoiceOption, 'label' | 'description' | 'disabled'>>>>\n /** Offer \"no selection\" as the first row; choosing it calls `onChange('')`. */\n defaultOption?: { label: string }\n}\n\n/** {@link ChoicePicker} over the harness set, each row its brand mark (from `./harness-glyphs`), name and qualifier. */\nexport function HarnessPicker({ value, onChange, available, optionsOverride, defaultOption, variant = 'chip', ...rest }: HarnessPickerProps) {\n // Quiet inherits the trigger's tone, so the mark lifts with the label on hover.\n const glyph = (h: Harness) => <HarnessGlyph harness={h} className={variant === 'quiet' ? 'h-4 w-4 shrink-0' : 'h-4 w-4 shrink-0 text-foreground'} />\n const ids = (available ?? (Object.keys(HARNESS_LABELS) as Harness[])).filter(isHarness)\n const options = [\n ...(defaultOption ? [{ value: '', label: defaultOption.label, icon: <GearGlyph className=\"h-4 w-4 shrink-0 text-muted-foreground\" /> }] : []),\n ...(isHarness(value) && !ids.includes(value) ? [value, ...ids] : ids).map((h) => ({ value: h, label: harnessLabel(h), description: HARNESS_LABELS[h]?.[1], icon: glyph(h), ...optionsOverride?.[h] })),\n ]\n return <ChoicePicker {...rest} variant={variant} value={value} onChange={(v) => onChange(v as Harness | '')} options={options} placeholder=\"Select harness\" title=\"Harness\" />\n}\n\nexport interface AgentSessionControlsProps {\n /** Catalog models — canonical provider-prefixed ids. */\n models: CatalogModel[]\n modelsLoading?: boolean\n /** Selected canonical model id. */\n model: string\n onModelChange(modelId: string): void\n /** Current harness; harness↔model coherence is enforced on every change. */\n harness: Harness\n onHarnessChange(harness: Harness): void\n /** Harnesses to offer; defaults to the labeled set. Intersected with the\n * harnesses the capability table allows for the selected model — the\n * current harness always stays listed. */\n availableHarnesses?: ReadonlyArray<Harness>\n /** Reasoning-effort value + setter. Shown only when the selected model\n * `supportsReasoning`, matching `EffortPicker`'s guidance. */\n effort: string\n onEffortChange(effort: string): void\n /**\n * Levels to offer, forwarded verbatim to {@link EffortPicker}. Omit for the\n * default vocabulary.\n *\n * A product whose backend applies only a SUBSET of the levels for the\n * selected harness/model passes that subset here. Without it the strip\n * offers every level and the backend silently ignores the ones it does not\n * apply — a control that reports a choice the system never made.\n *\n * This is the COMPLETE renderable set, not an allow-list layered over a\n * default one — the removed `ComposerAgentControls`' `available` list was the\n * latter, and its picker injected the `auto` sentinel itself. A list that\n * omits the current {@link effort} is still safe: `EffortPicker` reconciles\n * the selected value into the rendered list under its own name rather than\n * resolving it to a different entry (`reconcileEffortLevels`). Build the list\n * from engine ids with `effortLevelsFromIds`; the migration is in\n * `docs/ui-picker-canon.md`.\n */\n effortLevels?: readonly EffortLevel[]\n /**\n * `inline` (default): model, harness, effort side by side — the prior\n * behavior. `compact`: model inline, harness + effort behind a gear popover.\n * `grouped`: one named settings dialog containing the same controlled pickers.\n */\n layout?: 'inline' | 'compact' | 'grouped'\n /** Optional host-owned profile selector inside the grouped settings surface. */\n profileControl?: ReactNode\n /** Profile name or other current identity shown on the grouped trigger. */\n settingsSummary?: ReactNode\n /** Hide the harness control entirely (single-harness products). */\n showHarness?: boolean\n /**\n * PIN the harness and say why, in the user's words (\"This thread already has\n * messages — start a new chat to switch backend\"). Presence IS the lock:\n * there is no separate boolean, because a lock a user cannot read is the\n * thing this prop exists to replace.\n *\n * The control stays VISIBLE and reports the harness the thread is on — the\n * shape a locked selector has to keep, since a thread whose backend is fixed\n * is exactly when a user wants to know what it is. Hiding it (`showHarness:\n * false`) is what pushed products into rendering their own lock label\n * outside the panel.\n *\n * While locked, `onHarnessChange` is never called — not from the picker, and\n * not from the model↔harness coherence policy either. See\n * {@link useCoherentHandlers}.\n */\n harnessLockReason?: string\n /**\n * Trigger treatment for every child — `chip` (default) is the bordered pill,\n * `quiet` the borderless text button. See `PickerVariant` in `./controls`.\n */\n variant?: PickerVariant\n renderProviderBadge?: (provider: string) => ReactNode\n className?: string\n}\n\n/**\n * Apply the harness↔model coherence policy and emit the resulting change(s).\n * Returned from a hook-free helper so both layouts share one implementation.\n *\n * A LOCKED harness ({@link AgentSessionControlsProps.harnessLockReason}) is\n * authoritative over the snap: picking a model whose native backend differs\n * still changes the model, and leaves the harness alone. The alternative —\n * snapping a harness the UI has just told the user cannot change — is the one\n * behaviour a lock must not have.\n */\nfunction useCoherentHandlers(props: AgentSessionControlsProps) {\n const { model, models, harness, onModelChange, onHarnessChange, harnessLockReason } = props\n const canonicalIds = useMemo(() => models.map((m) => m.id), [models])\n const harnessLocked = harnessLockReason !== undefined\n\n const onModel = (next: string) => {\n onModelChange(next)\n if (harnessLocked) return\n const nextHarness = snapHarnessToModel(harness, next)\n if (nextHarness !== harness) onHarnessChange(nextHarness)\n }\n\n const onHarness = (next: Harness) => {\n onHarnessChange(next)\n const snapped = snapModelToHarness(next, model, canonicalIds)\n if (snapped !== model) onModelChange(snapped)\n }\n\n return { onModel, onHarness }\n}\n\nexport function AgentSessionControls(props: AgentSessionControlsProps) {\n const {\n models,\n modelsLoading,\n model,\n harness,\n availableHarnesses,\n effort,\n onEffortChange,\n effortLevels,\n layout = 'inline',\n showHarness = true,\n harnessLockReason,\n variant = 'chip',\n renderProviderBadge,\n className,\n profileControl,\n settingsSummary,\n } = props\n const { onModel, onHarness } = useCoherentHandlers(props)\n const [open, setOpen] = useState(false)\n const { containerRef: popoverRef, triggerRef, panelRef, triggerProps } = usePopover(open, setOpen)\n const panelId = useId()\n\n // Offer only harnesses the capability table allows for the selected model\n // (#802); the current harness stays listed so a pinned pair never loses its\n // own row.\n const offeredHarnesses = (availableHarnesses ?? (Object.keys(HARNESS_LABELS) as Harness[]))\n .filter((h) => isHarness(h) && (h === harness || isModelCompatibleWithHarness(h, model)))\n\n const selectedModel = models.find((m) => m.id === model)\n const showEffort = selectedModel?.supportsReasoning ?? true\n\n const modelPicker = (\n <ModelPicker\n value={model}\n onChange={onModel}\n models={models}\n loading={modelsLoading}\n renderProviderBadge={renderProviderBadge}\n variant={variant}\n />\n )\n\n if (layout === 'grouped') {\n return (\n <AgentSettingsPopover summary={settingsSummary ?? selectedModel?.name ?? model} className={className}>\n {profileControl != null && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Profile</p>{profileControl}</div>}\n <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Model</p>{modelPicker}</div>\n {showHarness && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Harness</p><HarnessPicker value={harness} onChange={(next) => { if (next) onHarness(next) }} available={offeredHarnesses} lockReason={harnessLockReason} fullWidth variant={variant} /></div>}\n {showEffort && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Reasoning effort</p><EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} fullWidth variant={variant} /></div>}\n </AgentSettingsPopover>\n )\n }\n\n if (layout === 'inline') {\n // The composer's controls slot wraps its children; this row must be able\n // to wrap too, or three pickers at a narrow width run under the Send\n // button instead of dropping to a second line.\n return (\n <div className={`flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 ${className ?? ''}`}>\n {modelPicker}\n {showHarness && (\n <HarnessPicker\n value={harness}\n onChange={(next) => { if (next) onHarness(next) }}\n available={offeredHarnesses}\n lockReason={harnessLockReason}\n variant={variant}\n />\n )}\n {showEffort && <EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} variant={variant} />}\n </div>\n )\n }\n\n // compact: model inline; harness + effort behind a gear popover.\n const hasAdvanced = showHarness || showEffort\n return (\n <div className={`flex items-center gap-1.5 ${className ?? ''}`}>\n {modelPicker}\n {hasAdvanced && (\n <div ref={popoverRef} className=\"relative inline-flex\">\n <button\n type=\"button\"\n {...triggerProps}\n aria-controls={open ? panelId : undefined}\n onClick={() => setOpen(!open)}\n title=\"Model settings — pick the harness and how hard it thinks\"\n className=\"flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=open]:bg-muted\"\n data-state={open ? 'open' : 'closed'}\n >\n <GearGlyph className=\"h-4 w-4\" />\n </button>\n <PopoverSurface\n open={open}\n id={panelId}\n triggerRef={triggerRef}\n panelRef={panelRef}\n className={`w-72 space-y-3 overflow-y-auto rounded-xl border border-card-edge bg-popover p-3 ${OVERLAY_SHADOW}`}\n >\n {showHarness && (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-foreground\">Harness</p>\n <HarnessPicker\n value={harness}\n onChange={(next) => { if (next) onHarness(next) }}\n available={offeredHarnesses}\n fullWidth\n lockReason={harnessLockReason}\n variant={variant}\n />\n <p className=\"text-xs leading-snug text-muted-foreground\">\n The engine that runs the agent. Switching it keeps your model choice compatible.\n </p>\n </div>\n )}\n {showEffort && (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-foreground\">Reasoning effort</p>\n <EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} label=\"\" fullWidth variant={variant} />\n <p className=\"text-xs leading-snug text-muted-foreground\">\n How hard the agent thinks before answering. Higher is slower but more thorough.\n </p>\n </div>\n )}\n </PopoverSurface>\n </div>\n )}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyCO,SAAS,mBAAmB,MAAY,QAA0B;AACvE,MAAI,CAAC,UAAU,OAAO,KAAK,EAAE,WAAW,EAAG,QAAO;AAElD,QAAM,WAAW,OACd,MAAM,GAAG,EACT,IAAI,CAAC,YAAY,QAAQ,KAAK,CAAC,EAC/B,OAAO,CAAC,YAAY,QAAQ,SAAS,CAAC;AACzC,MAAI,SAAS,WAAW,EAAG,QAAO;AAElC,QAAM,OAAO,KAAK,KAAK,YAAY;AACnC,QAAM,QAAQ,KAAK,QAAQ,IAAI,YAAY;AAE3C,SAAO,SAAS,KAAK,CAAC,YAAY;AAChC,UAAM,QAAQ,QAAQ,YAAY;AAClC,QAAI,MAAM,WAAW,GAAG,EAAG,QAAO,KAAK,SAAS,KAAK;AACrD,QAAI,MAAM,SAAS,IAAI,GAAG;AAIxB,YAAM,SAAS,MAAM,MAAM,GAAG,EAAE;AAChC,UAAI,CAAC,KAAK,WAAW,MAAM,EAAG,QAAO;AACrC,YAAM,UAAU,KAAK,MAAM,OAAO,MAAM;AACxC,aAAO,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAAS,GAAG;AAAA,IACpD;AACA,WAAO,SAAS;AAAA,EAClB,CAAC;AACH;AAIO,SAAS,sBAAsB,MAAY,QAAwB;AACxE,SAAO,IAAI,KAAK,IAAI,mCAAmC,MAAM;AAC/D;AAQO,SAAS,oBACd,OACA,QACyD;AACzD,QAAM,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK;AAC5D,QAAM,WAAmB,CAAC;AAC1B,QAAM,WAAoC,CAAC;AAC3C,aAAW,QAAQ,MAAM;AACvB,QAAI,mBAAmB,MAAM,MAAM,EAA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CAA6C,8FAE1D;AAAA,eACF;AAAA,YAED,cACC,gBAAAC,MAAC,SAAI,WAAU,eACb;AAAA,8BAAAD,KAAC,OAAE,WAAU,uCAAsC,8BAAgB;AAAA,cACnE,gBAAAA,KAAC,gBAAa,OAAO,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,OAAM,IAAG,WAAS,MAAC,SAAkB;AAAA,cAClH,gBAAAA,KAAC,OAAE,WAAU,8CAA6C,6FAE1D;AAAA,eACF;AAAA;AAAA;AAAA,MAEN;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":["jsx","jsxs","useState","jsx","jsxs","useState"]}
1
+ {"version":3,"sources":["../src/web-react/composer-file-accept.ts","../src/web-react/harness-glyphs.tsx","../src/web-react/agent-settings-popover.tsx","../src/web-react/agent-session-controls.tsx"],"sourcesContent":["/**\n * The composer's file-ingress filter, and the clipboard rename that goes with\n * it.\n *\n * A file reaches a composer by three routes — the picker dialog, a drag-and-drop,\n * and a clipboard paste — and only the picker gets a native `accept` filter (one\n * the user can defeat with \"All Files\"). Every route therefore funnels through\n * {@link filterAcceptedFiles}, so a type the picker will not offer cannot arrive\n * by another route instead.\n *\n * One route can still reach a different verdict, and it does so deliberately.\n * Paste is the only route that RENAMES, and {@link renamePastedImages} names a\n * file after the type it declares. So a clipboard bitmap called `image.png` that\n * declares `image/heic` is judged as `.heic` on paste, while the picker and a\n * drop judge the name they were handed and admit it under `accept=\".png\"`. The\n * filter is the same on all three; what differs is the name it is given, and\n * paste is stricter precisely because a rename that kept the contradicting name\n * would let the composer manufacture its own way past the filter.\n *\n * ONE accept matcher serves the package: `ChatComposer` gates its ingress on it\n * and `useComposerAttachments` gates `addFiles` on it. A second implementation\n * of the `accept` grammar is how the two ends of the same staging path start\n * disagreeing about what a file is.\n *\n * Pure data in, pure data out — nothing here throws, logs, or touches the DOM,\n * so a caller decides how a rejection is surfaced. Import-free beyond the\n * browser's own `File`, which keeps it usable from `/web-react`'s client bundle.\n */\n\n/** A file the `accept` list refused, with the reason to show for it. */\nexport interface ComposerFileRejection {\n file: File\n reason: string\n}\n\n/**\n * Checks one file against a comma-separated `accept` list, using the grammar of\n * the native `<input accept>` attribute: extensions (`.png`), exact MIME types\n * (`image/png`), and MIME wildcards (`image/*`). An absent or empty list accepts\n * everything, which is what an unset `accept` prop means.\n */\nexport function isAcceptedFileType(file: File, accept?: string): boolean {\n if (!accept || accept.trim().length === 0) return true\n\n const patterns = accept\n .split(',')\n .map((pattern) => pattern.trim())\n .filter((pattern) => pattern.length > 0)\n if (patterns.length === 0) return true\n\n const name = file.name.toLowerCase()\n const type = (file.type || '').toLowerCase()\n\n return patterns.some((pattern) => {\n const lower = pattern.toLowerCase()\n if (lower.startsWith('.')) return name.endsWith(lower)\n if (lower.endsWith('/*')) {\n // Keep the trailing \"/\" so `image/*` cannot match `imagex/png`, and\n // require a real subtype after it: `image/` and `image//png` are\n // malformed types, and a `File.type` can carry either.\n const prefix = lower.slice(0, -1)\n if (!type.startsWith(prefix)) return false\n const subtype = type.slice(prefix.length)\n return subtype.length > 0 && !subtype.includes('/')\n }\n return type === lower\n })\n}\n\n/** The reason an `accept` list refused a file. One wording for every ingress\n * route, so the same file reads the same whether it was picked or dropped. */\nexport function acceptRejectionReason(file: File, accept: string): string {\n return `\"${file.name}\" is not an accepted file type (${accept}).`\n}\n\n/**\n * Splits a batch into what the `accept` list admits and what it refuses. Size\n * and count limits are NOT applied here: they belong to the staging queue, which\n * knows what is already staged (`useComposerAttachments`), while this runs at the\n * composer's edge where that is unknown.\n */\nexport function filterAcceptedFiles(\n files: File[] | FileList,\n accept?: string,\n): { accepted: File[]; rejected: ComposerFileRejection[] } {\n const list = Array.isArray(files) ? files : Array.from(files)\n const accepted: File[] = []\n const rejected: ComposerFileRejection[] = []\n for (const file of list) {\n if (isAcceptedFileType(file, accept)) accepted.push(file)\n else rejected.push({ file, reason: acceptRejectionReason(file, accept ?? '') })\n }\n return { accepted, rejected }\n}\n\n/**\n * Extensions that truthfully name each image type, most canonical first. A type\n * with more than one is the reason this is a LIST and not a single name: `.jpeg`\n * and `.jpg` are the same claim, so a rename that swapped one for the other\n * would make a paste fail an `accept=\".jpeg\"` list that the very same file\n * passes through the picker.\n *\n * A type absent from here derives its single extension from the MIME subtype.\n */\nconst IMAGE_EXTENSIONS_BY_MIME: Record<string, readonly string[]> = {\n 'image/png': ['png'],\n 'image/jpeg': ['jpg', 'jpeg', 'jpe'],\n 'image/jpg': ['jpg', 'jpeg'],\n 'image/gif': ['gif'],\n 'image/webp': ['webp'],\n 'image/bmp': ['bmp'],\n 'image/svg+xml': ['svg'],\n 'image/tiff': ['tiff', 'tif'],\n 'image/x-icon': ['ico'],\n 'image/vnd.microsoft.icon': ['ico'],\n}\n\n/**\n * Matches EXACTLY the generic names browsers give a clipboard bitmap: an empty\n * name, `image`, or `image.<ext>`. Those are the names that collide across\n * pastes. A name that is only an extension (`.png`) is a real, if unusual,\n * filename and is left alone.\n */\nfunction isGenericImageName(name: string): boolean {\n return /^(?:image(?:\\.[a-z0-9]+)?)?$/i.test(name.trim())\n}\n\n/**\n * The extension a renamed clipboard image should carry, or null when none can\n * be derived truthfully.\n *\n * It must never name a format the bytes are not. A rename that hands an\n * `accept=\".png\"` list a file satisfying it by its new name alone turns the\n * rename into a way around the very gate it is filtered by.\n *\n * So the DECLARED TYPE decides which extensions are truthful, and the filename\n * may only pick among those. A clipboard file can carry a name whose extension\n * contradicts its type — a bitmap named `image.png` that is really `image/heic`\n * — and letting the name win there is exactly the hole this order closes. But\n * when the name's extension is one the type itself allows, it is kept: an\n * `image.jpeg` of type `image/jpeg` stays `.jpeg`, because rewriting it to the\n * canonical `.jpg` would make the paste fail an `accept=\".jpeg\"` list that the\n * same file passes through the picker.\n *\n * A subtype only stands in for an extension when it is already shaped like one.\n * `image/heic` is; `image/vnd.microsoft.icon` is not, and squeezing the\n * punctuation out of it would yield `vndmicrosofticon` — a name no accept list\n * will ever match, so a perfectly good `.ico` would be admitted through the\n * picker and refused on paste. An unrecognised compound type therefore names\n * nothing, and the filename is consulted instead.\n *\n * The filename is consulted on its own ONLY when the type names nothing usable\n * — either no subtype at all (`image/`) or a compound one. That is not an\n * exception to the rule above: the only named files this function ever sees are\n * `image.<ext>` (see {@link isGenericImageName}), so the fallback can only ever\n * preserve an extension the name already carried — it cannot manufacture one,\n * and an accept list therefore decides the same way it would have without the\n * rename. When nothing yields an extension, the caller skips the rename rather\n * than guessing.\n */\nfunction imageExtension(file: File): string | null {\n const type = file.type.toLowerCase()\n const fromName = /\\.([a-z0-9]+)$/i.exec(file.name)?.[1]?.toLowerCase()\n\n const mapped = IMAGE_EXTENSIONS_BY_MIME[type]\n const subtype = type.startsWith('image/') ? type.slice('image/'.length) : ''\n const bare = subtype.split('+')[0] ?? ''\n const truthful = mapped ?? (/^[a-z0-9]+$/.test(bare) ? [bare] : [])\n\n if (truthful.length === 0) return fromName ?? null\n if (fromName !== undefined && truthful.includes(fromName)) return fromName\n return truthful[0] ?? null\n}\n\n/** The `pasted-image-<n>` numbers these names already occupy. */\nfunction takenPastedImageIndexes(names: Iterable<string>): Set<number> {\n const taken = new Set<number>()\n for (const name of names) {\n const digits = /^pasted-image-(\\d+)(?:\\.[a-z0-9]+)?$/i.exec(name.trim())?.[1]\n if (digits === undefined) continue\n const parsed = Number.parseInt(digits, 10)\n if (Number.isSafeInteger(parsed)) taken.add(parsed)\n }\n return taken\n}\n\n/**\n * The lowest number above `after` that no name has claimed.\n *\n * Searching upward from the caller's own count — rather than from the highest\n * number any staged name happens to carry — is what keeps the usual case cheap:\n * staged numbers are avoided, never followed, so the walk advances at most once\n * per number already claimed.\n *\n * Termination does not rest on that, though, because `after` can be pushed near\n * the safe-integer ceiling and `+ 1` stops moving there — a walk that only\n * tested membership would spin on one value forever. The upward walk therefore\n * ends the moment a candidate leaves the safe range, and the search restarts\n * from the bottom, where a free number is guaranteed: `taken` is finite, so one\n * of the first `taken.size + 1` positive integers is always free. Every number\n * this returns is a safe integer, which is also what keeps an unsafe staged\n * name — invisible to {@link takenPastedImageIndexes} — impossible to collide\n * with.\n */\nfunction nextFreeIndex(taken: Set<number>, after: number): number {\n const start = Number.isSafeInteger(after) && after >= 0 ? after + 1 : 1\n for (let candidate = start; Number.isSafeInteger(candidate); candidate += 1) {\n if (!taken.has(candidate)) return candidate\n }\n for (let candidate = 1; ; candidate += 1) {\n if (!taken.has(candidate)) return candidate\n }\n}\n\n/**\n * Gives every generically-named clipboard image a distinct\n * `pasted-image-<n>.<ext>` name. Two pastes of the same bitmap otherwise arrive\n * as `image.png` twice, and a staging queue that keys on the name treats the\n * second as a duplicate of the first.\n *\n * A number is never reused. The search avoids every `pasted-image-<n>` already\n * present in `stagedNames` (the queue the host still holds, which outlives this\n * composer's own count) and in the batch itself (one paste can carry a file\n * already named that way beside a raw bitmap), so a collision is not reachable\n * rather than merely unlikely. `startIndex` is the caller's running count, and\n * `nextIndex` is the count to hand the next paste.\n *\n * Files that already carry a real name pass through untouched, so a copied\n * `report.pdf` keeps being `report.pdf`. So does an image whose extension\n * cannot be derived from what it declares — a renamed file must never claim a\n * format it is not. Only the name changes: the bytes, the type and the\n * modification time travel with it, so downstream fingerprinting still sees\n * the file the user pasted.\n */\nexport function renamePastedImages(\n files: File[],\n startIndex: number,\n stagedNames: Iterable<string> = [],\n): { files: File[]; nextIndex: number } {\n const taken = takenPastedImageIndexes([...stagedNames, ...files.map((file) => file.name)])\n // Whatever the caller's count is — a negative, a fraction, NaN, or a value at\n // the ceiling — `nextFreeIndex` normalises it and always answers with a safe\n // integer, so nothing here has to pre-screen it.\n let nextIndex = startIndex\n const renamed = files.map((file) => {\n const typed = file.type.startsWith('image/')\n // A clipboard file can arrive with no MIME type at all, and one named\n // `image.png` still collides across pastes exactly as a typed one does.\n // Its extension then comes from its own name, which cannot manufacture a\n // claim it did not already carry.\n if (!isGenericImageName(file.name) || (!typed && file.type !== '')) return file\n const extension = imageExtension(file)\n if (extension === null) return file\n nextIndex = nextFreeIndex(taken, nextIndex)\n taken.add(nextIndex)\n return new File([file], `pasted-image-${nextIndex}.${extension}`, {\n type: file.type,\n lastModified: file.lastModified,\n })\n })\n return { files: renamed, nextIndex }\n}\n","/**\n * Per-harness brand marks for the canonical pickers — the same marks the\n * legacy sandbox-ui harness picker (`dashboard/harness-logo.tsx`) shipped,\n * vendored as inline SVG so `/web-react` stays dependency-free beyond React:\n * sandbox-ui (and its `@lobehub/icons-static-svg` bundle) is an OPTIONAL peer\n * the canonical pickers must not force on a consumer. Geometry is the lobehub\n * single-color artwork, rendered in `currentColor` exactly as the legacy\n * component painted it (a foreground-filled CSS mask), so every mark tracks\n * the theme. Harnesses with no published brand mark get an honest inline\n * lucide glyph — bot / plug / terminal, the same fallbacks the legacy picker\n * used — and an unknown id falls back to the neutral bot. Data-record\n * structure mirrors `./provider-logo`.\n */\n\nimport type { ReactNode } from 'react'\nimport type { Harness } from '../harness'\n\nexport interface HarnessGlyphProps {\n /** Harness to mark. Typed as the canonical union; an out-of-union runtime\n * value still renders — it gets the neutral fallback glyph. */\n harness: Harness\n className?: string\n}\n\n// ── brand marks (single-color lobehub artwork, fill) ──────────────────────\n\nconst BRAND_PATHS: Partial<Record<Harness, readonly string[]>> = {\n opencode: [\n 'M16 6H8v12h8V6zm4 16H4V2h16v20z',\n ],\n 'claude-code': [\n 'M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z',\n ],\n codex: [\n 'M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z',\n ],\n amp: [\n 'M15.087 23.18L12.03 24l-2.097-7.823-5.738 5.738-2.251-2.251 5.718-5.719-7.769-2.082.82-3.057 11.294 3.08 3.08 11.295z',\n 'M19.505 18.762l-3.057.82-2.564-9.573-9.572-2.564.819-3.057 11.295 3.079 3.08 11.295z',\n 'M23.893 14.374l-3.057.82-2.565-9.572L8.7 3.057 9.52 0l11.295 3.08 3.079 11.294z',\n ],\n 'kimi-code': [\n 'M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z',\n ],\n openclaw: [\n 'M9.046 7.104a.527.527 0 110 1.055.527.527 0 010-1.055z',\n 'M15.376 7.104a.528.528 0 110 1.056.528.528 0 010-1.056z',\n 'M16.877 1.912c.58-.27 1.14-.323 1.616-.037a.317.317 0 01-.326.542c-.227-.136-.547-.153-1.022.068-.352.165-.765.45-1.234.866 2.683 1.17 4.4 3.5 5.148 5.921a6.421 6.421 0 00-.704.184c-.578.016-1.174.204-1.502.735-.338.55-.268 1.276.072 2.069l.005.012.007.014c.523 1.045 1.318 1.91 2.2 2.284-.912 3.274-3.44 6.144-5.972 6.988v2.109h-2.11v-2.11c-1.043.417-2.086.01-2.11 0v2.11h-2.11v-2.11c-2.531-.843-5.061-3.713-5.973-6.987.882-.373 1.678-1.238 2.2-2.284l.007-.014.006-.012c.34-.793.41-1.518.071-2.069-.327-.531-.923-.719-1.503-.735a6.409 6.409 0 00-.704-.183c.749-2.421 2.466-4.751 5.149-5.922-.47-.416-.88-.701-1.234-.866-.474-.221-.794-.204-1.021-.068a.318.318 0 01-.435-.109.317.317 0 01.109-.433c.476-.286 1.036-.233 1.615.037.49.229 1.031.628 1.621 1.182A9.924 9.924 0 0112 2.568c1.199 0 2.284.19 3.256.526.59-.554 1.13-.953 1.62-1.182zM8.835 6.577a1.266 1.266 0 100 2.532 1.266 1.266 0 000-2.532zm6.33 0a1.267 1.267 0 100 2.533 1.267 1.267 0 000-2.533z',\n 'M.395 13.118c-.966-1.932-.163-3.863 2.41-3.365v-.001l.05.01c.084.018.17.038.26.06.033.009.067.017.1.027.084.022.168.048.255.076l.09.027c.528 0 .95.158 1.16.501.212.343.212.87-.105 1.61-.085.17-.178.333-.276.489l-.01.017a4.967 4.967 0 01-.62.791l-.019.02c-1.092 1.117-2.496 1.336-3.295-.262z',\n 'M21.193 9.753c2.574-.5 3.378 1.433 2.411 3.365-.58 1.159-1.476 1.361-2.342.96l-.011-.005a2.419 2.419 0 01-.114-.056l-.019-.01a2.751 2.751 0 01-.115-.067l-.023-.014c-.035-.022-.071-.044-.106-.068l-.05-.035c-.55-.388-1.062-1.007-1.44-1.76-.276-.647-.311-1.132-.174-1.472.176-.439.636-.639 1.23-.639.032-.011.066-.02.099-.03.08-.026.16-.05.238-.072l.117-.03a5.502 5.502 0 01.3-.067z',\n ],\n hermes: [\n 'M5.938 12.835c.127-.039.285.02.373.143.028.038.036.092.046.14.003.014-.02.033-.04.05-.124-.098-.24-.194-.354-.291-.011-.01-.016-.027-.025-.042zM8.396 9.412c.195-.032.39-.06.588-.05a.54.54 0 01.148.026c.202.071.402.147.601.224.028.01.05.036.075.055l-.013.027a9.203 9.203 0 01-.26-.089c-.115-.038-.213-.077-.315-.098-.25-.05-.25-.046-.292-.014l.574.144c.275.139.55.276.823.417.042.022.09.057.107.098.026.06.063.076.117.072.066-.006.132-.017.213-.027l-.04.086c.051.08.142.02.216.064-.074.13-.247.09-.334.199l.061.074-.12.087c0 .106-.038.168-.306.243l.026.085-.196.042.07.124h-.25l-.007.137c-.081-.01-.161-.018-.244-.027l-.053.123c-.027-.008-.052-.011-.073-.023-.067-.038-.128-.056-.195.006-.019.017-.063.014-.093.008-.026-.006-.05-.029-.07-.042-.11.095-.11.095-.208.003-.057.046-.12.074-.186.011-.063.027-.123-.02-.178-.014-.07.007-.097-.035-.133-.07l-.13.033c-.013-.236-.194-.19-.34-.203.005-.072.05-.092.095-.094a.474.474 0 01.159.022c.164.05.32.12.496.138.203.021.405.029.601-.015.265-.059.52-.149.707-.365.049-.056.083-.127.117-.195.019-.038.02-.084-.02-.116a1.397 1.397 0 00-.382-.217c.024.12-.031.182-.115.221 0 .014-.004.025 0 .03.08.115.084.16-.007.267a1.39 1.39 0 01-.218.211.477.477 0 01-.641-.05 1.36 1.36 0 01-.133-.152c-.078-.107-.076-.108-.033-.236-.165-.08-.128-.226-.104-.364.008-.05.028-.096.049-.163-.04.014-.067.017-.087.032a.897.897 0 00-.316.357c-.007.016-.01.034-.02.047-.012.015-.034.038-.045.035-.02-.006-.037-.027-.05-.045-.008-.012-.007-.032-.012-.057h-.126l.053-.172a14.82 14.82 0 00-.039-.049l.11-.284c-.06.026-.091.044-.124.051-.03.007-.064 0-.095 0 0-.031-.01-.07.004-.092.149-.22.305-.428.593-.476z',\n 'M8.06 10.788c-.003-.038-.004-.075.037-.062.016.006.034.048.028.067-.01.04-.038.032-.064-.005z',\n 'M11.981.009c.226-.012.453-.011.679 0 .247.01.495.024.74.062.401.064.798.157 1.19.273.463.138.92.299 1.356.511a7.31 7.31 0 012.948 2.642c.292.469.536.963.739 1.479.219.556.446 1.11.623 1.683.204.654.329 1.326.458 1.997.097.504.182 1.01.29 1.511.156.722.329 1.44.494 2.16.186.812.4 1.615.63 2.415.102.355.193.713.282 1.072.11.436.202.876.254 1.323.031.278.066.557.073.837a7.56 7.56 0 01-.017.88c-.037.413-.1.818-.226 1.212a5.017 5.017 0 01-.915 1.649l-.13.156.018.023c.043-.023.088-.041.127-.068.2-.138.373-.307.531-.49.4-.46.721-.973.975-1.529a3.59 3.59 0 00.325-1.72c-.024-.424-.097-.834-.3-1.213-.013-.027-.015-.06-.03-.121.05.035.082.048.101.072.107.13.22.258.315.398.33.494.46 1.052.486 1.64a3.75 3.75 0 01-.47 1.97c-.36.655-.887 1.14-1.526 1.506-.193.111-.394.21-.595.308-.157.078-.248.211-.318.365a.522.522 0 00-.033.406.359.359 0 01.013.139c-.005.077-.077.155-.14.162-.054.006-.125-.043-.15-.116a1.206 1.206 0 01-.06-.233c-.04-.314-.155-.6-.308-.87a3.906 3.906 0 00-.73-.91 2.129 2.129 0 00-.897-.524 4.093 4.093 0 00-.692-.131c-.075-.008-.15-.04-.22.01.18.06.363.11.538.18.434.173.82.43 1.18.728.308.255.58.543.794.884.098.155.186.315.227.496.027.123.042.25.067.375.013.062-.002.109-.053.144-.047.033-.122.034-.163-.01a.455.455 0 01-.08-.14c-.03-.073-.038-.159-.078-.225a7.314 7.314 0 00-1.423-1.664c-.16-.137-.329-.26-.537-.323-.376-.114-.753-.203-1.15-.154-.213.025-.427.032-.64.053a1.6 1.6 0 00-.736.278 5.14 5.14 0 00-.834.72c-.329.342-.642.699-.955 1.055-.136.155-.264.319-.314.531a5.227 5.227 0 00-.012.051.096.096 0 01-.09.076h-.31c-.046 0-.082-.048-.072-.094.023-.108.045-.216.07-.324.075-.325.19-.635.368-.917.024-.039.04-.088.104-.08l.01.049.027.077c.28-.435.571-.834.996-1.135.283-.204.584-.378.89-.55a.196.196 0 00-.098-.002c-.162.043-.325.084-.485.134-.402.124-.764.33-1.11.566-.147.1-.298.193-.414.333a7.314 7.314 0 00-1.07 1.767.845.845 0 00-.04.12.075.075 0 01-.072.056h-.494c-.04 0-.062-.051-.036-.082.123-.14.246-.282.377-.415.275-.281.58-.532.777-.884.027-.048.063-.09.095-.135.238-.333.54-.607.818-.902.082-.086.175-.16.26-.24.029-.027.053-.057.079-.085l-.018-.025-.135.041c-.034.017-.07.031-.102.05-.248.144-.494.292-.743.433-.408.23-.825.439-1.209.711-.281.2-.591.358-.889.533-.02.012-.044.015-.08.028-.015-.135.143-.201.108-.336-.033.014-.064.02-.085.038-.111.096-.227.19-.328.296-.148.157-.284.325-.425.488-.125.143-.25.286-.373.431A.153.153 0 019.89 24H8.762a.316.316 0 00.016-.042c.028-.09.085-.172.083-.28-.091-.018-.162.001-.212.077a4.45 4.45 0 00-.136.215c-.01.016-.024.03-.042.03h-.093c-.019 0-.029-.022-.017-.037.071-.088.14-.178.209-.268.001-.002-.006-.012-.012-.024-.014.004-.03.006-.045.013-.176.09-.352.181-.527.274a.363.363 0 01-.168.042H5.202c-.026 0-.039-.036-.019-.053.21-.178.402-.374.558-.605.335-.496.538-1.047.667-1.629.004-.02-.003-.043-.006-.091-.037.048-.059.072-.076.1a1.943 1.943 0 01-.334.415c-.28.258-.59.448-.983.464-.297.012-.588 0-.865-.127-.46-.21-.722-.57-.794-1.072-.025-.17-.017-.171-.182-.219A3.513 3.513 0 011.97 20.6a2.286 2.286 0 01-.808-1.13 3.569 3.569 0 01-.16-1.245c.002-.034.016-.067.024-.1.032.023.046.043.05.066.033.153.059.308.096.46.086.355.257.664.516.92.258.256.571.419.91.532.358.118.717.138 1.07-.016a1.89 1.89 0 00.621-.452c.328-.348.533-.76.648-1.223.009-.034.005-.071.007-.11-.015.006-.026.006-.03.011-.031.05-.064.1-.093.152-.284.502-.679.887-1.196 1.135-.351.17-.718.255-1.11.159a1.607 1.607 0 01-.971-.64 2.006 2.006 0 01-.368-.924 2.903 2.903 0 01.02-.886c.05-.439.466-1.17.742-1.271-.02.063-.035.112-.053.16-.043.116-.097.227-.13.345a1.901 1.901 0 00-.05.82c.033.212.09.416.204.6.147.236.346.407.62.465.11.023.225.014.338.018a.576.576 0 00.386-.131c.164-.128.282-.292.366-.481.168-.375.24-.777.309-1.179.05-.296.093-.594.133-.893.039-.281.071-.563.104-.845.026-.232.048-.464.074-.696.024-.228.052-.455.076-.683.024-.227.047-.455.069-.683.013-.14.022-.28.034-.42l.037-.417c.022-.25.041-.5.065-.748.008-.082-.02-.132-.09-.177a2.46 2.46 0 01-.492-.418c-.1-.109-.188-.228-.282-.342-.035-.042-.056-.097-.116-.118a2.084 2.084 0 00.275.597c.06.092.131.176.196.265.063.086.182.115.234.226-.028.003-.046.01-.06.006a4.74 4.74 0 01-.22-.057 2.71 2.71 0 01-1.287-.819c-.435-.487-.656-1.076-.71-1.723a5.206 5.206 0 01.014-1.06c.072-.602.22-1.186.45-1.745.155-.376.338-.741.526-1.102.205-.393.466-.75.765-1.076.512-.559 1.104-1.024 1.726-1.448.717-.49 1.478-.898 2.277-1.233C8.244.828 8.767.632 9.31.494c.655-.166 1.31-.33 1.982-.415.229-.03.458-.058.688-.07zm-1.847 22.82c-.07.06-.147.111-.207.18-.238.27-.464.549-.668.869l-.044.108a.177.177 0 00.093-.057c.174-.19.351-.378.519-.574.104-.122.195-.255.288-.386.024-.034.03-.08.046-.12l-.027-.02zm1.65-3.695a5.51 5.51 0 00-.653.593l-.37.386a.963.963 0 01-.377.25 1.372 1.372 0 01-.467.09c-.044 0-.087.006-.151.012.028.058.043.097.064.131.15.242.301.482.45.724.136.22.276.438.399.666.068.125.105.267.156.404.077.027.14-.018.202-.048.29-.135.579-.274.867-.412.213-.101.437-.186.636-.31.347-.215.68-.455 1.018-.685.015-.01.026-.028.042-.046-.023-.019-.038-.037-.056-.044-.287-.111-.527-.3-.77-.482a5.319 5.319 0 01-.506-.42 1.757 1.757 0 01-.41-.653c-.019-.049-.045-.095-.075-.156zm-5.847.264c-.06.096-.097.194-.132.293a3.38 3.38 0 01-.555 1.01c-.2.25-.455.412-.762.493-.23.06-.464.076-.7.07-.048-.002-.097.002-.158.005.016.04.021.066.035.085.1.145.23.246.4.295.157.046.316.034.498.023.181-.037.343-.115.485-.234.238-.199.402-.454.536-.732.175-.363.264-.751.342-1.144.01-.053.008-.11.011-.164zm14.945-4.586c.008.029.016.057.027.107.024.155.051.31.072.464.03.219.067.437.078.657.017.344.027.689-.014 1.033-.037.315-.063.633-.116.946a6.153 6.153 0 01-.46 1.518c-.008.018-.01.039-.02.082.047-.03.077-.042.098-.064.085-.083.17-.167.248-.255.271-.305.458-.66.596-1.043.18-.498.228-1.011.145-1.531-.103-.65-.33-1.263-.597-1.881a9.055 9.055 0 00-.024-.055l-.033.022zM5.797 8.29a.26.26 0 00.018.153c.124.251.25.501.379.75.025.049.066.09.03.163-.284.06-.578.119-.88.255.059.038.097.06.132.087.042.032.112.058.09.12-.01.033-.075.048-.117.072.017.01.043.021.067.036.166.102.33.207.447.368.138.192.229.404.188.644-.079.469-.306.85-.69 1.132-.054.04-.106.083-.161.122a.243.243 0 00-.103.245.77.77 0 00.055.195c.083.196.22.35.375.492.083.076.159.164.222.257a.37.37 0 01.025.377c-.023.05-.05.099-.076.148-.03.06-.028.111.022.162.041.042.08.089.112.138.038.058.078.079.147.05a.486.486 0 01.333-.006c.16.046.302.126.444.21.13.077.264.149.4.219.067.035.14.05.219.026.071-.022.124.01.145.076.02.064-.003.108-.074.139-.07.03-.137.063-.209.088-.1.035-.201.073-.314.077-.013-.107.11-.088.127-.159-.206-.126-.643-.145-.801-.034.063.112.035.21-.096.313-.13-.1-.025-.202.002-.3a.209.209 0 00-.249.17c-.015.101.067.216.178.224.108.007.218-.005.326-.012.06-.005.12-.027.199 0-.103.123-.248.127-.357.19.002.05.07.086.019.131-.053.048-.095-.001-.132-.03-.08-.063-.16-.126-.231-.197a.474.474 0 01-.157-.311.52.52 0 00-.043-.172c-.032-.074-.032-.137.033-.19-.018-.03-.028-.053-.045-.072a1.222 1.222 0 01-.196-.369c-.053-.137-.046-.264.048-.381.024-.03.05-.06.064-.095a.664.664 0 00.047-.168c.017-.165-.064-.287-.182-.387-.186-.156-.36-.322-.46-.551-.005-.011-.024-.017-.037-.026-.011.017-.024.027-.025.038-.019.185-.045.37-.052.557-.014.377.058.743.162 1.104.118.41.289.798.488 1.173.267.502.537 1.002.812 1.5.055.098.13.189.208.27.198.202.452.272.724.273.202 0 .404-.006.605-.026.295-.03.59-.073.884-.113.183-.025.365-.057.548-.08.21-.026.38.073.522.21.16.156.305.327.447.5.22.265.397.56.554.867.05.098.07.1.147.03.13-.121.26-.242.394-.36.067-.059.088-.12.067-.213a3.535 3.535 0 01-.085-.796c.002-.157.006-.314.018-.471.015-.224.03-.45.06-.672a59.114 59.114 0 01.362-2.298c.087-.493.182-.984.268-1.477.06-.347.118-.694.162-1.043.034-.273.055-.55.063-.825.011-.332.003-.665.002-.998 0-.077.004-.155-.01-.23-.028-.142-.01-.155-.162-.19a5.826 5.826 0 00-.607-.107c-.146-.018-.207-.053-.221-.19-.006-.049-.025-.098-.041-.146-.009-.025-.024-.048-.046-.09l-.025.264c-.009.096-.029.116-.127.115-.055 0-.11-.008-.164-.008-.476 0-.952-.008-1.426.032-.095.008-.173-.015-.226-.103-.04-.066-.088-.126-.134-.186-.063-.084-.086-.093-.182-.06-.195.068-.388.138-.582.21a2.71 2.71 0 00-.675.394.986.986 0 01-.323.168c-.033.01-.07.008-.127.013.02-.066.024-.114.047-.15.064-.105.135-.205.205-.306.023-.033.049-.063.073-.095l-.015-.023-.201.037c-.146.04-.296.07-.437.122-.148.053-.266.023-.386-.072a3.623 3.623 0 01-.733-.786l-.093-.132zm8.592 8.963l-.147.09c-.22.134-.44.266-.659.402-.093.058-.184.12-.27.188-.085.07-.124.161-.072.272.047.1.093.2.147.294.047.08.124.138.213.147.11.01.228.012.336-.012.217-.05.372-.205.528-.357a.291.291 0 00.087-.308c-.046-.18-.079-.365-.118-.547-.011-.052-.027-.103-.045-.169zm-.257-2.409c-.12.291-.205.597-.325.91-.151.433-.294.87-.435 1.323.036-.01.054-.01.067-.018.261-.16.522-.324.785-.484.054-.033.071-.078.065-.138-.012-.13-.024-.262-.034-.393l-.068-.886c-.008-.103-.02-.206-.029-.31-.009 0-.017-.002-.026-.004zm3.081-8.13l.099.285c.08.231.159.463.24.714l.58 1.952c.187.63.372 1.262.558 1.893.114.382.235.762.343 1.146.072.257.126.519.186.799.044.206.087.413.127.64.034.106.023.226.077.325l.025-.006-.068-.362c-.038-.206-.077-.412-.113-.638-.015-.07-.029-.141-.046-.211-.095-.396-.177-.796-.29-1.187-.196-.685-.413-1.364-.618-2.046-.165-.549-.322-1.1-.488-1.648-.069-.227-.15-.45-.226-.695l-.117-.336c-.037-.107-.075-.216-.115-.322-.04-.106-.084-.21-.127-.314a7.558 7.558 0 01-.027.01zM6.225 14.304c-.063-.001-.115.014-.134.083a.35.35 0 00.41.012 4.533 4.533 0 00-.276-.095zM5.23 11.98c-.026-.027-.057-.048-.075.002-.012.032-.007.07-.01.113.082-.037.082-.037.085-.115zm.062-1.189a.135.135 0 00-.088.056.197.197 0 00-.025.11c.005.152.01.306.026.457a.751.751 0 00.066.218c.061.136.157.167.288.101.055-.027.06-.054.025-.11a4.52 4.52 0 01-.129-.211c-.015-.068-.066-.131-.033-.207.04-.09-.076-.116-.074-.19V10.874c-.003-.038-.006-.087-.056-.083zm-.017-.968a.867.867 0 00-.467.127c-.076.045-.084.07-.05.158.034.087.07.173.115.254.064.117.09.125.21.077a.657.657 0 01.336-.053c.202.022.357.136.504.264l.092.077c.007-.006.014-.013.022-.018-.019-.105-.035-.226-.149-.264-.157-.053-.324-.075-.508-.117l-.24-.005c.24-.169.452-.044.687.009-.063-.115-.153-.147-.23-.193-.082-.05-.17-.092-.25-.144-.06-.037-.12-.08-.072-.172zm10.233.325c-.23-.01-.427.08-.608.211-.034.026-.06.065-.105.117.087.026.15.046.232.065.044-.015.088-.03.13-.046.306-.114.61-.115.904.031.126.063.237.04.366-.005-.02-.031-.03-.054-.045-.071a.986.986 0 00-.448-.273c-.14-.044-.284-.024-.426-.03zM7.99 6.483a.308.308 0 00.002.133c.08.321.156.643.242.962.104.387.27.75.456 1.103.02.037.061.08.098.087a.404.404 0 00.253-.051l-.472-.84c-.23-.448-.405-.92-.579-1.394zM10.397.497c-.2-.008-.405.004-.603.034-.236.035-.47.087-.7.152-.287.08-.569.18-.852.273-.04.013-.074.038-.11.058.028.014.05.018.07.014.287-.068.58-.085.873-.09.134-.002.269.009.402.025.19.024.382.048.57.09.456.104.874.3 1.265.556.464.306.888.66 1.257 1.078.205.232.395.475.56.739.17.274.315.561.449.856.273.601.456 1.232.6 1.876.04.173.07.348.1.524.017.104.065.167.17.19.122.028.2.105.22.251-.003.102-.06.174-.129.24a1.065 1.065 0 00-.268.358.164.164 0 00.083-.039c.08-.086.162-.172.235-.265a.56.56 0 00.13-.333c.009-.05.022-.1.024-.15.007-.124-.017-.15-.143-.168-.025-.004-.049-.014-.073-.015-.082-.007-.125-.063-.137-.131-.033-.198-.004-.355.247-.408.086-.018.174-.03.26-.042.158-.023.315-.053.473-.067.14-.012.19.033.226.167.008.029.018.057.021.087.019.179-.008.225-.141.288-.027.013-.055.024-.078.042a.148.148 0 00-.051.067c-.039.144.073.382.206.445l.673.32c.023.011.05.015.075.023l.018-.026c-.015-.008-.032-.013-.044-.024a2.27 2.27 0 00-.544-.32 4.898 4.898 0 00-.173-.075.203.203 0 01-.126-.191c-.003-.085.045-.154.128-.187l.059-.025c.099-.044.118-.076.112-.187a.384.384 0 00-.008-.063c-.067-.294-.123-.59-.205-.88a9.478 9.478 0 00-.826-2.036 7.465 7.465 0 00-1.39-1.805 4.536 4.536 0 00-1.177-.824 3.656 3.656 0 00-1.016-.328 6.155 6.155 0 00-.712-.074zm6.719 5.955c.01.014.018.028.038.034l-.022-.044-.016.01zM4.103 3.917a.062.062 0 01-.03.012.455.455 0 01-.04.039c-.01.01-.02.02-.045.04l-.363.354c-.088.085-.17.178-.266.253-.284.22-.425.53-.544.855a.132.132 0 00-.007.071c.013.055.033.108.052.168l.074.026c-.017.056-.03.105-.047.152-.058.164-.118.327-.175.491-.005.015.008.036.019.077.08-.175.158-.33.225-.489.228-.544.484-1.074.819-1.561.09-.133.182-.266.283-.401.004-.006.007-.013.022-.03.001-.016.003-.032.015-.04l.008-.017zm12.976 2.408a.023.023 0 01.009.019.073.073 0 00-.006.01.188.188 0 00.007.02l.018.022c.002-.007.007-.016.005-.021-.003-.01-.012-.018-.02-.038a1.331 1.331 0 01-.013-.012zM4.199 4.48c-.003.004-.008.008-.027.014-.005.013-.011.025-.031.047a2.085 2.085 0 01-.124.167c-.048.07-.116.055-.181.041-.134-.028-.228.016-.287.143-.089.187-.187.37-.273.56-.049.108-.11.216-.118.36.081.003.154.007.228.008h.228a2.563 2.563 0 01-.079.264c-.01.052-.022.103-.033.155l.02.004c.018-.046.037-.092.067-.153.066-.142.13-.285.2-.426.02-.04.034-.1.116-.092 0 .043.004.084 0 .124-.005.045-.017.09-.028.143.141.043.086.174.115.269.102-.022.104-.195.248-.144v.205l.017.002.439-1.059c-.13 0-.246-.02-.358.033-.024.011-.058-.001-.108-.004.075-.15.139-.278.211-.417a.128.128 0 01.025-.036c0-.015-.001-.03.008-.038l.006-.02c-.005.006-.01.011-.028.017-.004.012-.009.024-.026.045a.085.085 0 01-.032.033c-.123.157-.09.164-.258.106-.079-.027-.078-.028-.047-.144.028-.046.056-.093.098-.15 0-.016-.001-.032.007-.042L4.2 4.48zm2.073-.67c-.003.006-.007.011-.027.016-.094.125-.194.246-.28.377-.155.238-.301.481-.451.723-.14.224-.345.368-.575.481-.017.008-.04.006-.079.011.012-.059.016-.109.033-.153a6.076 6.076 0 01.229-.518l-.007-.02a.138.138 0 01-.035.025c-.028.05-.055.1-.093.164-.26.424-.443.817-.442.95.024.004.048.011.073.013.177.013.188.007.26-.165.03-.07.077-.12.147-.15l.175-.07c.044-.018.085-.057.146-.032.003.05-.01.11.014.145.042.062.044.125.047.193.002.049.017.098.026.147.029-.034.039-.065.05-.097.142-.39.277-.782.428-1.17.1-.256.22-.504.33-.756.013-.03.013-.067.03-.092V3.81zm3.987-.34c0 .045.01.084.021.123.042.16.094.318.124.48.024.133.023.27.028.406 0 .033-.019.067-.032.11-.094-.058-.047-.158-.106-.215h-.125c-.015.072-.01.152-.046.2-.066.085-.155.154-.236.227-.043.038-.078.018-.103-.025l-.046-.087c-.065.035-.117.069-.172.093-.116.051-.235.095-.35.147-.085.038-.09.053-.07.147.014.075.034.148.047.223.013.072.05.109.123.124.233.05.462.115.657.265.058-.102.058-.102.168-.151.03-.014.06-.03.092-.042.08-.03.115-.017.15.06.023.048.041.098.066.158.06-.14-.042-.267.017-.416.157.18.24.39.375.567a.235.235 0 00.022-.098c.002-.124 0-.247.002-.371 0-.034.013-.067.02-.1l.032-.003c.11.155.13.354.226.52a3.036 3.036 0 00-.01-.392c-.004-.045 0-.074.05-.088.08.036.116.14.215.158-.03-.275-.423-1.137-.798-1.635-.114-.127-.2-.28-.34-.386zm-2.667.696c-.019.034-.03.05-.037.067-.061.185-.125.37-.18.556-.031.105-.087.169-.195.19-.09.019-.178.052-.268.073-.038.009-.089.015-.118-.003-.024-.016-.025-.069-.036-.106-.064.076-.082.087-.17.047-.133-.062-.262-.135-.393-.201-.048-.025-.093-.063-.17-.03-.043.12-.091.25-.137.382-.099.28-.087.242.095.453.046.048.102.03.154.023.054-.009.106-.03.16-.036.13-.013.26-.08.367-.015.204-.064.387-.122.571-.178.05-.015.089.005.114.054.022.042.034.093.082.121.038-.056-.013-.128.063-.178l.14.241-.042-1.46zm.278.358c-.096-.01-.107.01-.11.108-.002.038-.003.078.002.115.03.2.099.386.174.57.002.006.012.01.022.015l.078-.05c.052.036.081.088.153.088.205-.002.41.014.616.012.099-.001.158.042.205.12.018.03.024.077.088.066l-.08-.394c-.05-.195-.085-.395-.172-.589-.057.057-.114.068-.18.046a.72.72 0 00-.135-.028c-.22-.028-.44-.059-.66-.08zm10.254-1.727c.089.163.155.316.139.491-.016.168.026.342-.044.516-.047-.033-.088-.082-.112-.075-.117.035-.164-.057-.227-.115a4.772 4.772 0 01-.286-.29l-.104-.113a4.856 4.856 0 01-.023.019c.035.046.07.093.11.156.04.064.084.127.122.193.034.058.065.118.031.205-.082-.01-.164-.019-.246-.032-.06-.01-.101 0-.124.07-.031.098-.037.096-.15.09.02.042.036.08.057.116.041.074.03.138-.03.196-.06.06-.118.122-.178.181a.175.175 0 01-.185.046c-.222-.061-.447-.113-.67-.174-.032-.009-.063-.04-.086-.068-.03-.04-.052-.087-.08-.13-.044-.07-.09-.138-.136-.207a.18.18 0 00-.014.105c.012.127.03.253.035.38.005.1-.024.12-.121.104-.104-.017-.206-.04-.31-.058-.064-.012-.131-.028-.202.03l.081.208c.09 0 .166-.01.237.002a.819.819 0 01.458.251c.078.083.154.168.241.26l.018-.005c-.004-.006-.008-.013-.01-.04.014-.056-.062-.118.018-.178.031.03.064.057.088.09.058.078.111.159.169.257l.089.141.024-.013a2093.819 2093.819 0 01-.427-.934c.055.007.083.007.108.016.193.07.385.142.577.216.074.028.147.06.219.094.062.028.112.018.157-.033.05-.056.102-.112.154-.167.05-.051.095-.046.132.014.016.025.026.053.04.08.071.138.143.277.217.433l.159.308.025-.011c-.044-.106-.07-.218-.138-.334-.057-.182-.168-.346-.206-.545.136.034.362.326.567.732l.057.074.018-.011a1.563 1.563 0 01-.052-.127c-.046-.145-.097-.29-.136-.436-.022-.083-.036-.173.022-.26l.109.058-.026-.207.027-.016c.022.02.05.036.065.06.073.108.143.22.215.33.01.016.029.029.043.043-.036-.217-.2-.38-.229-.626l.155.112c.014-.166.012-.319.042-.465.032-.158-.023-.297-.063-.445.024.004.036.006.055.025.092.124.183.249.277.371.02.027.05.047.069.087l.04.063.019-.015a.293.293 0 01-.053-.082 27.922 27.922 0 01-.332-.49c-.221-.311-.363-.467-.485-.521zm-6.57.327c-.003.161.092.275.069.415l-.368.087c.09.139.032.237-.052.331-.05.057-.092.122-.143.178-.037.04-.046.078-.018.126l.16.275c.029.048.072.066.128.064.076-.003.152 0 .228-.001.116-.003.216.022.275.137.006.014.02.024.044.052.004-.059-.003-.098.01-.13.016-.04.04-.099.072-.108.084-.023.173-.024.26-.03.013-.001.027.018.04.029l.071.065c.019-.11-.082-.198-.024-.31l.126.04c-.026-.123-.07-.245-.071-.366 0-.123.051-.243.115-.36.107.062.16.156.234.253.183.265.36.533.494.834.165-.078.27.068.407.088-.003-.106-.133-.441-.197-.492a.142.142 0 00-.102-.028c-.06.011-.119.039-.191.063-.025-.039-.056-.078-.077-.122a3.936 3.936 0 00-.473-.783c-.076-.094-.16-.182-.228-.26l-.391.285c-.049.035-.094.03-.132-.017l-.169-.207c-.025-.03-.053-.059-.097-.108z',\n ],}\n\n// ── honest fallbacks for harnesses with no published brand mark ───────────\n// Inline lucide paths (v1.27, ISC) — `/web-react` ships no icon-library\n// dependency, so the stroke glyphs here match the set in `./controls`.\n\nfunction BotGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 8V4H8\" />\n <rect width=\"16\" height=\"12\" x=\"4\" y=\"8\" rx=\"2\" />\n <path d=\"M2 14h2\" />\n <path d=\"M20 14h2\" />\n <path d=\"M15 13v2\" />\n <path d=\"M9 13v2\" />\n </svg>\n )\n}\n\nfunction PlugGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 22v-5\" />\n <path d=\"M15 8V2\" />\n <path d=\"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z\" />\n <path d=\"M9 8V2\" />\n </svg>\n )\n}\n\nfunction TerminalGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d=\"M12 19h8\" />\n <path d=\"m4 17 6-6-6-6\" />\n </svg>\n )\n}\n\n/** Lucide fallback per harness without a brand mark — the same assignments\n * the legacy picker shipped (`factory-droids`→bot, `nanoclaw`→plug,\n * `cli-base`→terminal). */\nconst FALLBACK_GLYPHS: Partial<Record<Harness, (props: { className?: string }) => ReactNode>> = {\n 'factory-droids': BotGlyph,\n nanoclaw: PlugGlyph,\n 'cli-base': TerminalGlyph,\n}\n\n/**\n * Brand mark for a harness — size it from the call site (`className=\"h-4\n * w-4\"`). Unknown ids render the neutral bot, never an invented logo.\n * `data-glyph` names the resolved mark so tests and stories can assert\n * brand-vs-fallback without snapshotting path data.\n */\nexport function HarnessGlyph({ harness, className }: HarnessGlyphProps): ReactNode {\n const brand = BRAND_PATHS[harness]\n if (brand) {\n return (\n <svg\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n role=\"img\"\n aria-label={harness}\n data-glyph={harness}\n >\n {brand.map((d) => (\n <path key={d.slice(0, 32)} d={d} />\n ))}\n </svg>\n )\n }\n const Fallback = FALLBACK_GLYPHS[harness] ?? BotGlyph\n const kind = Fallback === BotGlyph ? 'bot' : Fallback === PlugGlyph ? 'plug' : 'terminal'\n return (\n <span role=\"img\" aria-label={harness} data-glyph={kind} className=\"inline-flex\">\n <Fallback className={className} />\n </span>\n )\n}\n","import { useCallback, useEffect, useState, type ReactNode } from 'react'\nimport { OVERLAY_SHADOW, PopoverSurface } from './controls'\nimport { usePopoverDialog } from './popover-dialog'\n\nexport interface AgentSettingsPopoverProps {\n /** Accessible name of the trigger and its non-modal dialog. */\n label?: string\n /** Current profile or model, kept visible without opening the panel. */\n summary?: ReactNode\n children: ReactNode\n open?: boolean\n onOpenChange?: (open: boolean) => void\n disabled?: boolean\n className?: string\n panelClassName?: string\n}\n\n/** One settings surface for entry, docked and embedded composers. No selection policy. */\nexport function AgentSettingsPopover({\n label = 'Agent settings', summary, children, open: controlledOpen,\n onOpenChange, disabled = false, className, panelClassName,\n}: AgentSettingsPopoverProps) {\n const [localOpen, setLocalOpen] = useState(false)\n const open = !disabled && (controlledOpen ?? localOpen)\n const changeOpen = useCallback((next: boolean) => {\n setLocalOpen(next)\n onOpenChange?.(next)\n }, [onOpenChange])\n useEffect(() => { if (disabled) changeOpen(false) }, [disabled, changeOpen])\n const { containerRef, triggerRef, panelRef, triggerProps, id } = usePopoverDialog(open, changeOpen)\n return (\n <div ref={containerRef} className={`inline-flex min-w-0 max-w-full ${className ?? ''}`}>\n <button\n type=\"button\" {...triggerProps} disabled={disabled}\n aria-label={label} title={label} data-agent-settings-trigger=\"\"\n onClick={() => changeOpen(!open)} data-state={open ? 'open' : 'closed'}\n className=\"inline-flex h-[var(--control-height-sm,2rem)] max-w-[15rem] items-center gap-1.5 rounded-full border border-border bg-transparent px-2.5 text-sm font-normal text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=open]:text-foreground disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <svg className=\"h-4 w-4 shrink-0\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" aria-hidden>\n <rect x=\"4\" y=\"7\" width=\"16\" height=\"14\" rx=\"3\" /><path d=\"M12 7V3M9 3h6M1 12v4m22-4v4m-15-3h.01M16 13h.01M9 17h6\" />\n </svg>\n <span className=\"min-w-0 truncate\">{summary ?? label}</span>\n <svg className=\"h-3 w-3 shrink-0\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" aria-hidden><path d=\"m6 9 6 6 6-6\" /></svg>\n </button>\n <PopoverSurface\n open={open} id={id} role=\"dialog\" aria-label={label}\n triggerRef={triggerRef} panelRef={panelRef}\n className={`w-80 max-w-[calc(100vw-2rem)] space-y-4 overflow-y-auto rounded-xl border border-card-edge bg-popover p-4 text-foreground ${OVERLAY_SHADOW} ${panelClassName ?? ''}`}\n >\n {children}\n </PopoverSurface>\n </div>\n )\n}\n","/**\n * `AgentSessionControls` — the CANONICAL model + harness + reasoning-effort\n * cluster a chat composer docks (see \"UI chrome ownership (picker canon)\" in\n * AGENTS.md). One component so every product's two composers (and every\n * product) share the same control surface and harness↔model coherence policy.\n *\n * PICKER CANON. The model menu below IS `/web-react`'s `ModelPicker` and the\n * thinking-budget pill IS `EffortPicker` — the canonical ecosystem pickers.\n * sandbox-ui's `dashboard/ModelPicker` and the model menu inside sandbox-ui's\n * `chat/AgentSessionControls` are legacy (deprecated, frozen, removed at\n * sandbox-ui's next major), and the `/chat-react` `ComposerAgentControls`\n * adapter that rendered sandbox-ui's strip is REMOVED — a surface that still\n * renders the sandbox-ui strip is showing the old design; migrate it\n * (props mapping in `docs/ui-picker-canon.md`).\n *\n * Dependency-free beyond React by design: `/web-react` must not force the\n * optional sandbox-ui peer, so this component — the canonical one — can never\n * require it.\n *\n * Two layouts, additive — the default preserves the prior hand-rolled behavior:\n * - `layout=\"inline\"` (default): model, harness, and effort sit side by side as\n * pills. This is the original arrangement; existing call sites that mounted\n * `ModelPicker` + a harness picker + `EffortPicker` in a row get the same UI.\n * - `layout=\"compact\"`: the model picker stays inline and visible; the\n * harness and reasoning-effort controls — settings a user rarely needs —\n * tuck behind a single gear popover with plain-English copy.\n *\n * Two trigger treatments, also additive (`variant`, see `PickerVariant` in\n * `./controls`): `chip` (default) is the bordered pill every child draws\n * today; `quiet` is the borderless text button, for a composer whose card\n * already draws the border. The variant reaches every child in both layouts.\n *\n * Harness ↔ model coherence is identical in both layouts, via the substrate's\n * snap helpers (`@tangle-network/agent-app/harness`): changing the harness snaps\n * an incompatible model to that harness's best catalog option; changing the\n * model switches to the model's native harness. Catalog model ids are canonical\n * (\"provider/model\"), which is exactly what the snap helpers expect — no id\n * translation is needed here.\n */\n\nimport { useId, useMemo, useRef, useState, type ReactNode } from 'react'\nimport {\n isHarness,\n isModelCompatibleWithHarness,\n snapHarnessToModel,\n snapModelToHarness,\n type Harness,\n} from '../harness'\nimport type { CatalogModel } from '../runtime/model-catalog'\nimport { ModelPicker, EffortPicker, CheckGlyph, fieldPickerTriggerClass, OVERLAY_SHADOW, pickerRootClass, PopoverSurface, quietPickerTriggerClass, usePopover } from './controls'\nimport type { EffortLevel, PickerVariant } from './controls'\nimport { PickerTrigger } from './picker-presentation'\nimport { HarnessGlyph } from './harness-glyphs'\nimport { AgentSettingsPopover } from './agent-settings-popover'\n\n/** Each harness's name, which the trigger shows, and the qualifier its menu row\n * adds beneath it. Unknown ids fall back to the raw value so a new backend\n * still renders a usable label. */\nconst HARNESS_LABELS: Partial<Record<Harness, readonly [name: string, description?: string]>> = {\n opencode: ['OpenCode', 'Any model'],\n 'claude-code': ['Claude Code', 'Anthropic models'],\n codex: ['Codex', 'OpenAI models'],\n 'kimi-code': ['Kimi', 'Moonshot models'],\n amp: ['Amp'],\n 'factory-droids': ['Factory Droids'],\n cursor: ['Cursor'],\n hermes: ['Hermes'],\n pi: ['Pi'],\n openclaw: ['OpenClaw'],\n acp: ['ACP'],\n 'cli-base': ['CLI'],\n}\n\nconst harnessLabel = (h: Harness): string => HARNESS_LABELS[h]?.[0] ?? h\n\n/** lucide `lock` — the closed padlock on a pinned harness trigger. */\nfunction LockGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <rect width=\"18\" height=\"11\" x=\"3\" y=\"11\" rx=\"2\" ry=\"2\" />\n <path d=\"M7 11V7a5 5 0 0 1 10 0v4\" />\n </svg>\n )\n}\n\nfunction GearGlyph({ className }: { className?: string }) {\n return (\n <svg className={className} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n <path d=\"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z\" />\n </svg>\n )\n}\n\n/**\n * A single-choice picker: the shared `PickerTrigger` and a menu of rows, each a\n * label over an optional one-line muted description that ends in an ellipsis\n * when it does not fit (the row's `title` carries the full text). `HarnessPicker`\n * is this picker over the harness set.\n *\n * The chip is the shared `PickerTrigger` (a `Chip`), not `rounded-lg` at whatever\n * height the padding gives: this pill sits beside `ModelPicker` and\n * `EffortPicker` in both layouts, all three the same Chip. A single odd-shaped control\n * is what made the compact popover read as a pile of unrelated widgets rather\n * than one selector stack. The `quiet` variant holds the same rule the other\n * way: its 28px text-button geometry comes from the one\n * `quietPickerTriggerClass` the other two triggers use.\n *\n * `fullWidth` is opt-in and means what it means on `EffortPicker` — see\n * {@link pickerRootClass}.\n *\n * `lockReason` PINS the control: it keeps its selector shape and keeps\n * reporting the harness the thread is on, opens nothing, and explains itself\n * on hover AND on keyboard focus. Three deliberate choices there:\n *\n * - `aria-disabled`, never the native `disabled` attribute. A disabled button\n * is removed from the tab order and fires no pointer events in most\n * browsers, so the one control that has something to explain would become\n * the one control that can never be asked.\n * - the reason rides a permanent visually-hidden node that `aria-describedby`\n * points at, so assistive tech has it whether or not the floating hint is\n * up; the floating copy is `aria-hidden` so nothing is announced twice.\n * - the hint is a {@link PopoverSurface}, not an absolutely-positioned div —\n * the compact panel is an `overflow-y-auto` box, which clips a positioned\n * descendant, and that surface is this package's answer to exactly that.\n */\n/** `description` is one muted line under the label, truncated with an ellipsis; the row's title carries the full text. */\nexport interface ChoiceOption { value: string; label: string; description?: string; icon?: ReactNode; /** A row that cannot be chosen; its description says why. */ disabled?: boolean }\n\nexport interface ChoicePickerProps {\n value: string\n onChange: (value: string) => void\n options: readonly ChoiceOption[]\n /** The trigger's text when `value` matches no option. */\n placeholder?: string\n fullWidth?: boolean\n /** Pin the control and say why; see the component notes. */\n lockReason?: string\n variant?: PickerVariant\n /** Disable the trigger; unlike `lockReason` it explains nothing. */\n disabled?: boolean\n id?: string\n title?: string\n 'aria-label'?: string\n 'aria-describedby'?: string\n}\n\nexport function ChoicePicker({ value, onChange, options, placeholder = '', fullWidth = false, lockReason, variant = 'chip', disabled = false,\n id, title, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy }: ChoicePickerProps) {\n const [requestedOpen, setOpen] = useState(false)\n const open = requestedOpen && !disabled\n const [hintOpen, setHintOpen] = useState(false)\n const { containerRef, triggerRef, panelRef, triggerProps } = usePopover(open, setOpen)\n const hintPanelRef = useRef<HTMLDivElement>(null)\n const panelId = useId()\n const reasonId = useId()\n const locked = lockReason !== undefined\n const field = variant === 'field'\n const showHint = () => setHintOpen(true)\n const hideHint = () => setHintOpen(false)\n const selected = options.find((o) => o.value === value)\n const choose = (next: string) => {\n onChange(next)\n setOpen(false)\n }\n return (\n <div ref={containerRef} className={pickerRootClass(fullWidth || field)}>\n <PickerTrigger variant={variant} icon={selected?.icon} trailing={locked ? <LockGlyph className=\"h-3.5 w-3.5 shrink-0 text-muted-foreground\" /> : undefined}\n {...triggerProps}\n id={id}\n disabled={disabled}\n aria-label={ariaLabel}\n aria-haspopup={locked ? undefined : true}\n aria-expanded={locked ? undefined : open}\n aria-controls={!locked && open ? panelId : undefined}\n aria-disabled={locked || undefined}\n aria-describedby={[locked ? reasonId : undefined, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n onClick={locked ? undefined : () => setOpen(!open)}\n onMouseEnter={locked ? showHint : undefined}\n onMouseLeave={locked ? hideHint : undefined}\n onFocus={locked ? showHint : undefined}\n onBlur={locked ? hideHint : undefined}\n title={title}\n data-state={!locked && open ? 'open' : 'closed'}\n className={\n field\n ? fieldPickerTriggerClass({ interactive: !locked && !disabled })\n : variant === 'quiet'\n ? `${quietPickerTriggerClass({ interactive: !locked })} w-full justify-between`\n : `w-full ${locked ? 'cursor-default hover:bg-transparent' : ''}`\n }\n >\n <span className={`flex min-w-0 items-center ${field ? 'flex-1 gap-2' : 'gap-1.5'}`}>\n {variant !== 'chip' && selected?.icon}\n <span className={`truncate ${value ? '' : 'text-muted-foreground'}`}>{selected?.label ?? placeholder}</span>\n </span>\n </PickerTrigger>\n {locked && (\n <>\n <span id={reasonId} className=\"sr-only\">\n {lockReason}\n </span>\n <PopoverSurface\n open={hintOpen}\n role=\"tooltip\"\n triggerRef={triggerRef}\n panelRef={hintPanelRef}\n matchTriggerWidth={fullWidth || field}\n className={`max-w-[248px] rounded-lg border border-card-edge bg-popover px-2.5 py-1.5 text-sm leading-snug text-muted-foreground ${OVERLAY_SHADOW}`}\n >\n <span aria-hidden>{lockReason}</span>\n </PopoverSurface>\n </>\n )}\n <PopoverSurface\n open={!locked && open}\n id={panelId}\n role=\"menu\"\n triggerRef={triggerRef}\n panelRef={panelRef}\n matchTriggerWidth\n side={field ? 'below' : undefined}\n className={`max-h-64 min-w-[248px] max-w-[min(24rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-card-edge bg-popover p-1 ${OVERLAY_SHADOW}`}\n >\n {options.map((o) => (\n <button\n key={o.value}\n type=\"button\" disabled={o.disabled}\n role=\"menuitemradio\"\n aria-checked={o.value === value}\n title={o.description ? `${o.label} — ${o.description}` : o.label}\n onClick={() => choose(o.value)}\n className={`flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-left text-sm transition disabled:cursor-not-allowed disabled:opacity-60 ${\n o.value === value ? 'bg-primary/10 font-medium' : o.disabled ? '' : 'hover:bg-accent'\n }`}\n >\n {o.icon}\n <span className=\"min-w-0 flex-1\"><span className=\"block truncate\">{o.label}</span>{o.description && <span className=\"block truncate text-xs font-normal text-muted-foreground\">{o.description}</span>}</span>\n {o.value === value && <CheckGlyph className=\"h-3.5 w-3.5 shrink-0 text-primary\" />}\n </button>\n ))}\n </PopoverSurface>\n </div>\n )\n}\n\nexport type HarnessPickerProps = Omit<ChoicePickerProps, 'value' | 'onChange' | 'options' | 'placeholder' | 'title'> & {\n /** The selected harness, or `''` for none when {@link HarnessPickerProps.defaultOption} is offered. */\n value: Harness | ''\n onChange: (h: Harness | '') => void\n /** Harnesses to offer; defaults to the labeled set. */\n available?: ReadonlyArray<Harness>\n /** A harness's own label, description or disabled state, such as its seat's room or why it cannot run now. */\n optionsOverride?: Partial<Record<string, Partial<Pick<ChoiceOption, 'label' | 'description' | 'disabled'>>>>\n /** Offer \"no selection\" as the first row; choosing it calls `onChange('')`. */\n defaultOption?: { label: string }\n}\n\n/** {@link ChoicePicker} over the harness set, each row its brand mark (from `./harness-glyphs`), name and qualifier. */\nexport function HarnessPicker({ value, onChange, available, optionsOverride, defaultOption, variant = 'chip', ...rest }: HarnessPickerProps) {\n // Quiet inherits the trigger's tone, so the mark lifts with the label on hover.\n const glyph = (h: Harness) => <HarnessGlyph harness={h} className={variant === 'quiet' ? 'h-4 w-4 shrink-0' : 'h-4 w-4 shrink-0 text-foreground'} />\n const ids = (available ?? (Object.keys(HARNESS_LABELS) as Harness[])).filter(isHarness)\n const options = [\n ...(defaultOption ? [{ value: '', label: defaultOption.label, icon: <GearGlyph className=\"h-4 w-4 shrink-0 text-muted-foreground\" /> }] : []),\n ...(isHarness(value) && !ids.includes(value) ? [value, ...ids] : ids).map((h) => ({ value: h, label: harnessLabel(h), description: HARNESS_LABELS[h]?.[1], icon: glyph(h), ...optionsOverride?.[h] })),\n ]\n return <ChoicePicker {...rest} variant={variant} value={value} onChange={(v) => onChange(v as Harness | '')} options={options} placeholder={rest.lockReason !== undefined && value ? harnessLabel(value) : 'Select harness'} title=\"Harness\" />\n}\n\nexport interface AgentSessionControlsProps {\n /** Catalog models — canonical provider-prefixed ids. */\n models: CatalogModel[]\n modelsLoading?: boolean\n /** Selected canonical model id. */\n model: string\n onModelChange(modelId: string): void\n /** Current harness; harness↔model coherence is enforced on every change. */\n harness: Harness\n onHarnessChange(harness: Harness): void\n /** Harnesses to offer; defaults to the labeled set. Intersected with the\n * harnesses the capability table allows for the selected model — the\n * current harness always stays listed. */\n availableHarnesses?: ReadonlyArray<Harness>\n /** Reasoning-effort value + setter. Shown only when the selected model\n * `supportsReasoning`, matching `EffortPicker`'s guidance. */\n effort: string\n onEffortChange(effort: string): void\n /**\n * Levels to offer, forwarded verbatim to {@link EffortPicker}. Omit for the\n * default vocabulary.\n *\n * A product whose backend applies only a SUBSET of the levels for the\n * selected harness/model passes that subset here. Without it the strip\n * offers every level and the backend silently ignores the ones it does not\n * apply — a control that reports a choice the system never made.\n *\n * This is the COMPLETE renderable set, not an allow-list layered over a\n * default one — the removed `ComposerAgentControls`' `available` list was the\n * latter, and its picker injected the `auto` sentinel itself. A list that\n * omits the current {@link effort} is still safe: `EffortPicker` reconciles\n * the selected value into the rendered list under its own name rather than\n * resolving it to a different entry (`reconcileEffortLevels`). Build the list\n * from engine ids with `effortLevelsFromIds`; the migration is in\n * `docs/ui-picker-canon.md`.\n */\n effortLevels?: readonly EffortLevel[]\n /**\n * `inline` (default): model, harness, effort side by side — the prior\n * behavior. `compact`: model inline, harness + effort behind a gear popover.\n * `grouped`: one named settings dialog containing the same controlled pickers.\n */\n layout?: 'inline' | 'compact' | 'grouped'\n /** Optional host-owned profile selector inside the grouped settings surface. */\n profileControl?: ReactNode\n /** Profile name or other current identity shown on the grouped trigger. */\n settingsSummary?: ReactNode\n /** Hide the harness control entirely (single-harness products). */\n showHarness?: boolean\n /**\n * PIN the harness and say why, in the user's words (\"This thread already has\n * messages — start a new chat to switch backend\"). Presence IS the lock:\n * there is no separate boolean, because a lock a user cannot read is the\n * thing this prop exists to replace.\n *\n * The control stays VISIBLE and reports the harness the thread is on — the\n * shape a locked selector has to keep, since a thread whose backend is fixed\n * is exactly when a user wants to know what it is. Hiding it (`showHarness:\n * false`) is what pushed products into rendering their own lock label\n * outside the panel.\n *\n * While locked, `onHarnessChange` is never called — not from the picker, and\n * not from the model↔harness coherence policy either. See\n * {@link useCoherentHandlers}.\n */\n harnessLockReason?: string\n /**\n * Trigger treatment for every child — `chip` (default) is the bordered pill,\n * `quiet` the borderless text button. See `PickerVariant` in `./controls`.\n */\n variant?: PickerVariant\n renderProviderBadge?: (provider: string) => ReactNode\n className?: string\n}\n\n/**\n * Apply the harness↔model coherence policy and emit the resulting change(s).\n * Returned from a hook-free helper so both layouts share one implementation.\n *\n * A LOCKED harness ({@link AgentSessionControlsProps.harnessLockReason}) is\n * authoritative over the snap: picking a model whose native backend differs\n * still changes the model, and leaves the harness alone. The alternative —\n * snapping a harness the UI has just told the user cannot change — is the one\n * behaviour a lock must not have.\n */\nfunction useCoherentHandlers(props: AgentSessionControlsProps) {\n const { model, models, harness, onModelChange, onHarnessChange, harnessLockReason } = props\n const canonicalIds = useMemo(() => models.map((m) => m.id), [models])\n const harnessLocked = harnessLockReason !== undefined\n\n const onModel = (next: string) => {\n onModelChange(next)\n if (harnessLocked) return\n const nextHarness = snapHarnessToModel(harness, next)\n if (nextHarness !== harness) onHarnessChange(nextHarness)\n }\n\n const onHarness = (next: Harness) => {\n onHarnessChange(next)\n const snapped = snapModelToHarness(next, model, canonicalIds)\n if (snapped !== model) onModelChange(snapped)\n }\n\n return { onModel, onHarness }\n}\n\nexport function AgentSessionControls(props: AgentSessionControlsProps) {\n const {\n models,\n modelsLoading,\n model,\n harness,\n availableHarnesses,\n effort,\n onEffortChange,\n effortLevels,\n layout = 'inline',\n showHarness = true,\n harnessLockReason,\n variant = 'chip',\n renderProviderBadge,\n className,\n profileControl,\n settingsSummary,\n } = props\n const { onModel, onHarness } = useCoherentHandlers(props)\n const [open, setOpen] = useState(false)\n const { containerRef: popoverRef, triggerRef, panelRef, triggerProps } = usePopover(open, setOpen)\n const panelId = useId()\n\n // Offer only harnesses the capability table allows for the selected model\n // (#802); the current harness stays listed so a pinned pair never loses its\n // own row.\n const offeredHarnesses = (availableHarnesses ?? (Object.keys(HARNESS_LABELS) as Harness[]))\n .filter((h) => isHarness(h) && (h === harness || isModelCompatibleWithHarness(h, model)))\n\n const selectedModel = models.find((m) => m.id === model)\n const showEffort = selectedModel?.supportsReasoning ?? true\n\n const modelPicker = (\n <ModelPicker\n value={model}\n onChange={onModel}\n models={models}\n loading={modelsLoading}\n renderProviderBadge={renderProviderBadge}\n variant={variant}\n />\n )\n\n if (layout === 'grouped') {\n return (\n <AgentSettingsPopover summary={settingsSummary ?? selectedModel?.name ?? model} className={className}>\n {profileControl != null && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Profile</p>{profileControl}</div>}\n <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Model</p>{modelPicker}</div>\n {showHarness && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Harness</p><HarnessPicker value={harness} onChange={(next) => { if (next) onHarness(next) }} available={offeredHarnesses} lockReason={harnessLockReason} fullWidth variant={variant} /></div>}\n {showEffort && <div className=\"space-y-1.5\"><p className=\"text-xs font-medium text-muted-foreground\">Reasoning effort</p><EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} fullWidth variant={variant} /></div>}\n </AgentSettingsPopover>\n )\n }\n\n if (layout === 'inline') {\n // The composer's controls slot wraps its children; this row must be able\n // to wrap too, or three pickers at a narrow width run under the Send\n // button instead of dropping to a second line.\n return (\n <div className={`flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 ${className ?? ''}`}>\n {modelPicker}\n {showHarness && (\n <HarnessPicker\n value={harness}\n onChange={(next) => { if (next) onHarness(next) }}\n available={offeredHarnesses}\n lockReason={harnessLockReason}\n variant={variant}\n />\n )}\n {showEffort && <EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} variant={variant} />}\n </div>\n )\n }\n\n // compact: model inline; harness + effort behind a gear popover.\n const hasAdvanced = showHarness || showEffort\n return (\n <div className={`flex items-center gap-1.5 ${className ?? ''}`}>\n {modelPicker}\n {hasAdvanced && (\n <div ref={popoverRef} className=\"relative inline-flex\">\n <button\n type=\"button\"\n {...triggerProps}\n aria-controls={open ? panelId : undefined}\n onClick={() => setOpen(!open)}\n title=\"Model settings — pick the harness and how hard it thinks\"\n className=\"flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=open]:bg-muted\"\n data-state={open ? 'open' : 'closed'}\n >\n <GearGlyph className=\"h-4 w-4\" />\n </button>\n <PopoverSurface\n open={open}\n id={panelId}\n triggerRef={triggerRef}\n panelRef={panelRef}\n className={`w-72 space-y-3 overflow-y-auto rounded-xl border border-card-edge bg-popover p-3 ${OVERLAY_SHADOW}`}\n >\n {showHarness && (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-foreground\">Harness</p>\n <HarnessPicker\n value={harness}\n onChange={(next) => { if (next) onHarness(next) }}\n available={offeredHarnesses}\n fullWidth\n lockReason={harnessLockReason}\n variant={variant}\n />\n <p className=\"text-xs leading-snug text-muted-foreground\">\n The engine that runs the agent. Switching it keeps your model choice compatible.\n </p>\n </div>\n )}\n {showEffort && (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-foreground\">Reasoning effort</p>\n <EffortPicker value={effort} onChange={onEffortChange} levels={effortLevels} label=\"\" fullWidth variant={variant} />\n <p className=\"text-xs leading-snug text-muted-foreground\">\n How hard the agent thinks before answering. Higher is slower but more thorough.\n </p>\n </div>\n )}\n </PopoverSurface>\n </div>\n )}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyCO,SAAS,mBAAmB,MAAY,QAA0B;AACvE,MAAI,CAAC,UAAU,OAAO,KAAK,EAAE,WAAW,EAAG,QAAO;AAElD,QAAM,WAAW,OACd,MAAM,GAAG,EACT,IAAI,CAAC,YAAY,QAAQ,KAAK,CAAC,EAC/B,OAAO,CAAC,YAAY,QAAQ,SAAS,CAAC;AACzC,MAAI,SAAS,WAAW,EAAG,QAAO;AAElC,QAAM,OAAO,KAAK,KAAK,YAAY;AACnC,QAAM,QAAQ,KAAK,QAAQ,IAAI,YAAY;AAE3C,SAAO,SAAS,KAAK,CAAC,YAAY;AAChC,UAAM,QAAQ,QAAQ,YAAY;AAClC,QAAI,MAAM,WAAW,GAAG,EAAG,QAAO,KAAK,SAAS,KAAK;AACrD,QAAI,MAAM,SAAS,IAAI,GAAG;AAIxB,YAAM,SAAS,MAAM,MAAM,GAAG,EAAE;AAChC,UAAI,CAAC,KAAK,WAAW,MAAM,EAAG,QAAO;AACrC,YAAM,UAAU,KAAK,MAAM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;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,IAAI;AAAA,UACJ;AAAA,UACA;AAAA,UACA,WAAW,oFAAoF,cAAc;AAAA,UAE1G;AAAA,2BACC,gBAAAA,MAAC,SAAI,WAAU,eACb;AAAA,8BAAAD,KAAC,OAAE,WAAU,uCAAsC,qBAAO;AAAA,cAC1D,gBAAAA;AAAA,gBAAC;AAAA;AAAA,kBACC,OAAO;AAAA,kBACP,UAAU,CAAC,SAAS;AAAE,wBAAI,KAAM,WAAU,IAAI;AAAA,kBAAE;AAAA,kBAChD,WAAW;AAAA,kBACX,WAAS;AAAA,kBACT,YAAY;AAAA,kBACZ;AAAA;AAAA,cACF;AAAA,cACA,gBAAAA,KAAC,OAAE,WAAU,8CAA6C,8FAE1D;AAAA,eACF;AAAA,YAED,cACC,gBAAAC,MAAC,SAAI,WAAU,eACb;AAAA,8BAAAD,KAAC,OAAE,WAAU,uCAAsC,8BAAgB;AAAA,cACnE,gBAAAA,KAAC,gBAAa,OAAO,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,OAAM,IAAG,WAAS,MAAC,SAAkB;AAAA,cAClH,gBAAAA,KAAC,OAAE,WAAU,8CAA6C,6FAE1D;AAAA,eACF;AAAA;AAAA;AAAA,MAEN;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":["jsx","jsxs","useState","jsx","jsxs","useState"]}
@@ -21,7 +21,7 @@ import {
21
21
  } from "./chunk-AOSQ5JCO.js";
22
22
  import {
23
23
  createD1TurnEventStore
24
- } from "./chunk-FIH4MI6S.js";
24
+ } from "./chunk-YY3D7LYV.js";
25
25
  import {
26
26
  DISPATCH_REQUEST_MAX_BYTES
27
27
  } from "./chunk-6YLVFV3F.js";
@@ -4400,4 +4400,4 @@ export {
4400
4400
  deleteSecret,
4401
4401
  mintSandboxScopedToken
4402
4402
  };
4403
- //# sourceMappingURL=chunk-YLRH77J3.js.map
4403
+ //# sourceMappingURL=chunk-EHUSCRLY.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_RUNNING_TURN_LEASE_MS
3
- } from "./chunk-FIH4MI6S.js";
3
+ } from "./chunk-YY3D7LYV.js";
4
4
 
5
5
  // src/stream/turn-observation.ts
6
6
  function parseTurnObservation(value) {
@@ -162,4 +162,4 @@ export {
162
162
  FOLLOW_UP_CLAIM_STALE_AFTER_MS,
163
163
  settleOrphanedTurns
164
164
  };
165
- //# sourceMappingURL=chunk-P6NVRUW6.js.map
165
+ //# sourceMappingURL=chunk-OV4X4P6U.js.map
@@ -98,6 +98,7 @@ function createBufferedTurnTap(opts) {
98
98
  const startedAt = Date.now();
99
99
  let seq = 0;
100
100
  let clientGone = false;
101
+ let firstTextCommitted = false;
101
102
  let pending = [];
102
103
  let lastFlush = Date.now();
103
104
  let started = false;
@@ -163,7 +164,11 @@ function createBufferedTurnTap(opts) {
163
164
  const line = JSON.stringify(ev);
164
165
  pending.push(ev);
165
166
  pendingChars += line?.length ?? 0;
166
- if (innerOf(ev)?.type === "execution.started") await flush();
167
+ const firstText = !firstTextCommitted && deltaTypeOf(ev) === "text" && innerOf(ev).text.trim().length > 0;
168
+ if (innerOf(ev)?.type === "execution.started" || firstText) {
169
+ await flush();
170
+ if (firstText) firstTextCommitted = true;
171
+ }
167
172
  if (!clientGone && opts.write) {
168
173
  try {
169
174
  await opts.write(line);
@@ -477,4 +482,4 @@ export {
477
482
  createD1TurnEventStore,
478
483
  createMemoryTurnEventStore
479
484
  };
480
- //# sourceMappingURL=chunk-FIH4MI6S.js.map
485
+ //# sourceMappingURL=chunk-YY3D7LYV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stream/turn-buffer.ts"],"sourcesContent":["/**\n * Resumable chat turns — the router-path answer to \"streams resume on\n * disconnect\" (issue #27). A turn's loop events are teed into a store as they\n * stream; the turn keeps running under `ctx.waitUntil` when the client drops;\n * a reconnecting client replays the buffered tail by sequence number and\n * keeps following until the turn completes.\n *\n * POST /chat/stream → pumpBufferedTurn(...) + live NDJSON\n * GET /chat/stream/:turnId → replayTurnEvents({ fromSeq }) → NDJSON\n *\n * Storage is a structural seam ({@link TurnEventStore}); a D1 implementation\n * ships here because that's what Cloudflare products have (KV is unsuitable:\n * eventually consistent cross-isolate). Per-token deltas would mean hundreds\n * of rows per turn, so consecutive text/reasoning deltas are coalesced within\n * a flush window before they are persisted — replay yields slightly chunkier\n * deltas with identical concatenation.\n */\n\nexport type TurnStatus = 'running' | 'complete' | 'error'\n\n/** A running row is a renewable lease, not permanent truth. If the process\n * driving a turn dies before writing a terminal status, reconnect discovery\n * must eventually stop returning that abandoned row. */\nexport const DEFAULT_RUNNING_TURN_LEASE_MS = 5 * 60_000\n\n/** Keep a healthy turn's lease comfortably ahead of expiry without turning\n * per-token streaming into status-write traffic. */\nexport const DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS = 30_000\n\n/** Represent a buffered turn event with a sequence number and serialized event data */\nexport interface BufferedTurnEvent {\n seq: number\n /** The serialized event line (JSON string, no trailing newline). */\n event: string\n}\n\n/** Manage and query turn events and their lifecycle statuses within a scoped event store */\nexport interface TurnEventStore {\n /**\n * Append rows while the turn is live. Implementations must ignore rows that\n * arrive after `setStatus` publishes `complete` or `error`; the terminal\n * status is the replay fence for a detached live projection.\n */\n append(turnId: string, events: BufferedTurnEvent[]): Promise<void>\n read(turnId: string, fromSeq: number): Promise<BufferedTurnEvent[]>\n /** Record turn lifecycle. `scopeId` (a thread/session id) is optional and lets\n * {@link TurnEventStore.listRunning} rediscover this turn after a client reload\n * loses the turnId; stores that don't track scope ignore it. */\n setStatus(turnId: string, status: TurnStatus, scopeId?: string, options?: TurnStatusWriteOptions): Promise<void>\n getStatus(turnId: string): Promise<TurnStatus | null>\n /** Unexpired running turnIds for a scope, newest first — so a reloaded client\n * (clientRunId lost) can find and resume the in-flight turn without reviving\n * a row abandoned by a dead process. Optional: a store records it only if\n * `setStatus` was given a `scopeId`. */\n listRunning?(scopeId: string): Promise<string[]>\n /** Remove one turn's buffered events and keep its status, so a genuine\n * re-stream after a crash starts at seq 0 without interleaving orphaned\n * rows. `runDetachedTurn` requires it to recover a `running` turn. */\n resetEvents?(turnId: string): Promise<void>\n /** Explicitly remove one turn's events and status. Optional so existing\n * custom stores remain source-compatible; the built-in D1 and memory stores\n * provide it. */\n deleteTurn?(turnId: string): Promise<void>\n /** Remove terminal turns whose status was updated before `before` (Unix\n * milliseconds or a Date). Running turns are never eligible. */\n pruneTerminalTurns?(before: number | Date): Promise<number>\n /** Running turns last renewed before `before` (Unix ms), oldest first, at most\n * `limit`: the candidates {@link settleOrphanedTurns} settles. */\n listStaleRunning?(before: number, limit: number): Promise<StaleRunningTurn[]>\n /** The last `count` events of a turn, newest first; a bounded read of the tail. */\n readTail?(turnId: string, count: number): Promise<BufferedTurnEvent[]>\n}\n\n/** A running turn nothing has renewed since `updatedAt`. */\nexport interface StaleRunningTurn {\n turnId: string\n scopeId: string | null\n /** Unix ms of the last status write. */\n updatedAt: number\n /** Set on a plan follow-up claim (`createD1PlanFollowUpGate`), which keeps its own staleness and does not renew. */\n leaseToken?: string | null\n}\n\n/**\n * Settling a stream nothing produces any more. A sweep that ends an orphaned\n * stream must not move it in time, since reports place a stream by its update\n * time, and must not end one whose producer came back meanwhile.\n */\nexport interface TurnStatusWriteOptions {\n /** Keep the row's update time; a new row still takes the current time. */\n preserveUpdatedAt?: boolean\n /** Write only when the row is still `running` and was last updated before this time (Unix ms). */\n onlyIfRunningBefore?: number\n}\n\n/** Configure running-turn lease evaluation. The clock is injectable so store\n * contract tests do not sleep. Keep the default in production unless a\n * deployment also tunes the buffer's renewal interval. */\nexport interface TurnEventStoreOptions {\n runningTurnLeaseMs?: number\n now?: () => number\n}\n\n// ── coalescing ────────────────────────────────────────────────────────────\n\ntype AnyRecord = Record<string, unknown>\n\nfunction deltaTypeOf(ev: unknown): 'text' | 'reasoning' | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object') return null\n const inner = (e.kind === 'event' ? (e.event as AnyRecord | undefined) : e) as AnyRecord | undefined\n if (!inner || typeof inner !== 'object') return null\n if ((inner.type === 'text' || inner.type === 'reasoning') && typeof inner.text === 'string') {\n return inner.type\n }\n return null\n}\n\nfunction innerOf(ev: unknown): AnyRecord | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object') return null\n const inner = (e.kind === 'event' ? e.event : e) as AnyRecord | undefined\n return inner && typeof inner === 'object' ? inner : null\n}\n\n/**\n * The key of a live-state event whose latest value supersedes earlier ones:\n * the model-processing heartbeat, and a harness's raw update of a text or\n * reasoning part (it carries the part's whole state, keyed by part id). Null\n * for every other event.\n */\nfunction liveStateKeyOf(ev: unknown): string | null {\n const inner = innerOf(ev)\n if (!inner) return null\n if (inner.type === 'model-processing') return 'model-processing'\n if (inner.type !== 'raw') return null\n const raw = (inner.data as AnyRecord | undefined)?.event as AnyRecord | undefined\n const part = raw?.part as AnyRecord | undefined\n if ((raw?.type === 'text' || raw?.type === 'reasoning') && typeof part?.id === 'string') return `raw:${part.id}`\n return null\n}\n\n/** Whether an event only projects live progress, so it may wait for the flush window and be coalesced. */\nexport function isLiveProgressEvent(ev: unknown): boolean {\n return deltaTypeOf(ev) !== null || liveStateKeyOf(ev) !== null\n}\n\n/**\n * Merge text and reasoning deltas of the same type into one event, across the\n * live-state events a harness interleaves with them, and keep only the latest\n * of each live-state event. A reasoning model streams three events per token\n * (its raw part update, a model-processing heartbeat and the delta); merging\n * only adjacent deltas wrote all three as rows (1.63 M rows in a\n * day, 59,659 in one turn). Any other event is a boundary nothing merges\n * across. Concatenation-preserving: replaying the coalesced stream produces\n * the same accumulated text, and the latest state of every part.\n */\nexport function coalesceDeltas(events: unknown[]): unknown[] {\n const out: unknown[] = []\n let run: { type: 'text' | 'reasoning'; index: number } | null = null\n let stateSlots = new Map<string, number>()\n for (const ev of events) {\n const type = deltaTypeOf(ev)\n if (type) {\n if (run && run.type === type) {\n const merged = JSON.parse(JSON.stringify(out[run.index])) as AnyRecord\n innerOf(merged)!.text = String(innerOf(out[run.index])!.text) + String(innerOf(ev)!.text)\n out[run.index] = merged\n } else {\n out.push(ev)\n run = { type, index: out.length - 1 }\n }\n continue\n }\n const key = liveStateKeyOf(ev)\n if (key) {\n const slot = stateSlots.get(key)\n if (slot === undefined) {\n out.push(ev)\n stateSlots.set(key, out.length - 1)\n } else {\n out[slot] = ev\n }\n continue\n }\n out.push(ev)\n run = null\n stateSlots = new Map()\n }\n return out\n}\n\nfunction asPartUpdate(ev: unknown): { partId: unknown; delta: unknown } | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object' || e.type !== 'message.part.updated') return null\n const data = e.data as AnyRecord | undefined\n if (!data || typeof data !== 'object') return null\n const part = data.part as AnyRecord | undefined\n const partId = part?.id ?? data.partId ?? part?.partId ?? null\n return { partId, delta: data.delta }\n}\n\n/**\n * Coalesce consecutive `message.part.updated` deltas for the SAME part into one\n * event. agent-runtime products stream `ChatStreamEvent` NDJSON\n * (`{type:'message.part.updated', data:{part, delta}}`); pumped through the\n * buffer with the default tool-loop coalescer, every per-token delta persists as\n * its own row because that coalescer never recognizes the shape. Pass this as\n * {@link PumpBufferedTurnOptions.coalesce} instead.\n *\n * Concatenation-preserving for BOTH consumer styles: the merged event keeps the\n * LATEST event's `data.part` (already the cumulative accumulation) and sets\n * `data.delta` to the concatenation of the merged deltas, so a client that\n * appends `delta` and one that reads the cumulative `part` both reconstruct the\n * identical final text.\n */\nexport function coalesceChatStreamEvents(events: unknown[]): unknown[] {\n const out: unknown[] = []\n for (const ev of events) {\n const cur = asPartUpdate(ev)\n const prevEv = out[out.length - 1]\n const prev = prevEv ? asPartUpdate(prevEv) : null\n if (cur && prev && cur.partId != null && cur.partId === prev.partId) {\n // Base the merged row on the latest event (its `part` is the most complete\n // accumulation); carry forward the summed delta.\n const merged = JSON.parse(JSON.stringify(ev)) as AnyRecord\n ;(merged.data as AnyRecord).delta = String(prev.delta ?? '') + String(cur.delta ?? '')\n out[out.length - 1] = merged\n continue\n }\n out.push(ev)\n }\n return out\n}\n\n// ── buffering core (the tap) ────────────────────────────────────────────────\n\n/** Define options for buffering and flushing turn events with optional live client delivery and event coalescing */\nexport interface BufferedTurnOptions {\n store: TurnEventStore\n turnId: string\n /** Deliver one serialized line to the live client. Throwing here (client\n * disconnected) does NOT stop buffering — events keep persisting. */\n write?: (line: string) => Promise<void> | void\n /** Flush buffered events to the store at most this often. Default 400ms. */\n flushIntervalMs?: number\n /** Flush window once a durable owner has taken the turn ({@link BufferedTurnTap.detach}). Live-progress events\n * wait for it; any other event flushes at once, after them. Default 2000ms. */\n detachedFlushIntervalMs?: number\n /** Per-flush coalescer. Default {@link coalesceDeltas} (tool-loop text/reasoning\n * deltas). agent-runtime products streaming `ChatStreamEvent` pass\n * {@link coalesceChatStreamEvents} so per-token deltas don't each persist as a\n * row. Must be concatenation-preserving. */\n coalesce?: (events: unknown[]) => unknown[]\n /** Optional scope (thread/session id) recorded with the turn status, so\n * {@link TurnEventStore.listRunning} can find this turn after a reload. */\n scopeId?: string\n /** How often to renew the running-turn lease while a producer is alive.\n * The timer is backed up by event-driven renewal when a runtime freezes\n * unreferenced timers during remote I/O. Default\n * {@link DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS}. */\n runningTurnRenewIntervalMs?: number\n}\n\n/** A push-driven buffer for a turn whose producer the caller does NOT own. */\nexport interface BufferedTurnTap {\n /** Buffer one event: persist (coalesced, on the flush window) + best-effort\n * live-deliver. Wire to a push source's per-event hook (e.g. agent-runtime\n * `handleChatTurn`'s `hooks.onEvent`). Marks the turn 'running' on first call.\n * `execution.started` commits its ordered prefix before this tap's live write. */\n onEvent(raw: unknown): Promise<void>\n /** Settle the turn: final flush + set status. Call after the producer resolves\n * ('complete') or rejects ('error'). 'error' flushes what was produced first. */\n done(status?: Extract<TurnStatus, 'complete' | 'error'>): Promise<void>\n /**\n * Give terminal-status ownership to an external durable runner. Stops this\n * tap's running-lease renewal and flushes its current projection, but keeps\n * `onEvent` available as an append-only live-observation path. After the\n * handoff, an event that is not live progress (a marker, interaction, tool\n * event, error or terminal event) flushes before `onEvent` returns, so a\n * durable owner cannot publish terminal status ahead of it; live progress\n * (deltas, heartbeats, raw part updates) is coalesced over\n * `detachedFlushIntervalMs`. Call it again when observation ends to flush any\n * final event.\n *\n * A caller MUST have registered that durable owner before detaching: this\n * method intentionally writes no replacement status.\n */\n detach(): Promise<void>\n}\n\n/**\n * The buffering core. Sequence-numbers every event, delivers it to `write`\n * (best-effort — a disconnected client never stops buffering), and flushes to\n * the store in coalesced batches. Drives both transports:\n *\n * • {@link pumpBufferedTurn} — when you OWN an `AsyncIterable` producer.\n * • this tap (`onEvent`/`done`) — when the producer owns iteration and only\n * hands you a push callback (agent-runtime `handleChatTurn`'s `hooks.onEvent`\n * + the finished body). Durability stays here in the shell; the engine needs\n * no `TurnEventStore` seam.\n */\n/** Serialized characters of pending events that force a flush before the window ends. */\nconst MAX_PENDING_CHARS = 64 * 1024\n\nexport function createBufferedTurnTap(opts: BufferedTurnOptions): BufferedTurnTap {\n const flushIntervalMs = opts.flushIntervalMs ?? 400\n const detachedFlushIntervalMs = opts.detachedFlushIntervalMs ?? 2000\n let pendingChars = 0\n const coalesce = opts.coalesce ?? coalesceDeltas\n const startedAt = Date.now()\n let seq = 0\n let clientGone = false\n let firstTextCommitted = false\n let pending: unknown[] = []\n let lastFlush = Date.now()\n let started = false\n let settled = false\n let detached = false\n let renewalTimer: ReturnType<typeof setTimeout> | undefined\n let renewal: Promise<void> = Promise.resolve()\n let lastRenewedAt = 0\n const runningTurnRenewIntervalMs = Math.max(\n 1,\n opts.runningTurnRenewIntervalMs ?? DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,\n )\n\n function clearRenewalTimer(): void {\n if (renewalTimer !== undefined) clearTimeout(renewalTimer)\n renewalTimer = undefined\n }\n\n function scheduleRenewal(): void {\n if (settled || detached || !opts.scopeId) return\n clearRenewalTimer()\n const elapsedMs = Math.max(0, Date.now() - lastRenewedAt)\n const delayMs = Math.max(1, runningTurnRenewIntervalMs - elapsedMs)\n renewalTimer = setTimeout(() => {\n renewalTimer = undefined\n void renewLease()\n }, delayMs)\n // A deliberately abandoned tap in a Node test must not keep the process\n // alive until the production renewal interval elapses.\n if (typeof renewalTimer === 'object' && 'unref' in renewalTimer) {\n renewalTimer.unref()\n }\n }\n\n async function renewLease(): Promise<void> {\n if (settled || detached || !opts.scopeId) return\n clearRenewalTimer()\n lastRenewedAt = Date.now()\n renewal = renewal\n .then(() => opts.store.setStatus(opts.turnId, 'running', opts.scopeId))\n .catch(() => {})\n await renewal\n scheduleRenewal()\n }\n\n async function flush(): Promise<void> {\n if (pending.length === 0) return\n const batch = coalesce(pending)\n pending = []\n pendingChars = 0\n const rows = batch.map((ev) => ({ seq: ++seq, event: JSON.stringify(ev) }))\n await opts.store.append(opts.turnId, rows)\n lastFlush = Date.now()\n }\n\n async function ensureStarted(): Promise<void> {\n if (started) return\n started = true\n // An external durable owner may have detached before the first observed\n // event. It owns status from that point, so this tap must never resurrect\n // its running lease.\n if (detached) return\n await opts.store.setStatus(opts.turnId, 'running', opts.scopeId)\n lastRenewedAt = Date.now()\n scheduleRenewal()\n }\n\n return {\n async onEvent(raw) {\n await ensureStarted()\n // Cloudflare may freeze an unreferenced timer while a producer is\n // awaiting remote I/O. A real event (including the route heartbeat)\n // therefore also renews any lease whose interval has elapsed.\n if (\n !detached &&\n opts.scopeId &&\n Date.now() - lastRenewedAt >= runningTurnRenewIntervalMs\n ) {\n await renewLease()\n }\n // Stamp ms-since-turn-start so any stored turn is replayable AND traceable\n // (see ../trace) from the same buffered rows.\n const ev = raw && typeof raw === 'object' ? { ...(raw as Record<string, unknown>), _t: Date.now() - startedAt } : raw\n const line = JSON.stringify(ev)\n pending.push(ev)\n pendingChars += line?.length ?? 0\n // Commit native identity or the first visible text and its ordered prefix.\n const firstText = !firstTextCommitted && deltaTypeOf(ev) === 'text' &&\n (innerOf(ev)!.text as string).trim().length > 0\n if (innerOf(ev)?.type === 'execution.started' || firstText) {\n await flush()\n if (firstText) firstTextCommitted = true\n }\n if (!clientGone && opts.write) {\n try {\n // Live delivery carries a provisional ordering hint, not the persisted\n // seq (coalescing changes seq assignment); clients resume with the\n // seqs from replay, or 0 for \"everything\".\n await opts.write(line)\n } catch {\n clientGone = true\n }\n }\n // Once detached, a turn marker, interaction, tool event, error or terminal event persists at once (with the\n // progress before it), and live progress waits for the window, so a reasoning model's per-token events do\n // not each become a row. An external owner's terminal status can fence at most the last window of progress.\n const due = detached\n ? !isLiveProgressEvent(ev) || Date.now() - lastFlush >= detachedFlushIntervalMs\n : Date.now() - lastFlush >= flushIntervalMs\n if (due || pendingChars >= MAX_PENDING_CHARS) await flush()\n },\n async done(status = 'complete') {\n await ensureStarted()\n if (detached) {\n await flush()\n return\n }\n settled = true\n clearRenewalTimer()\n await renewal\n if (status === 'error') {\n await flush().catch(() => {})\n await opts.store.setStatus(opts.turnId, 'error', opts.scopeId).catch(() => {})\n return\n }\n await flush()\n await opts.store.setStatus(opts.turnId, 'complete', opts.scopeId)\n },\n async detach() {\n detached = true\n clearRenewalTimer()\n // A renewal already queued before detach may be writing `running`. Wait\n // for it before returning so the durable owner can safely publish a\n // terminal status after the awaited handoff.\n await renewal\n await flush()\n },\n }\n}\n\n// ── pump (producer side) ──────────────────────────────────────────────────\n\n/** Define options to pump data from an asynchronous iterable source with buffered turn control */\nexport interface PumpBufferedTurnOptions extends BufferedTurnOptions {\n source: AsyncIterable<unknown>\n}\n\n/**\n * Drive a turn to completion regardless of the live client, when you OWN the\n * producer as an `AsyncIterable`. A thin driver over {@link createBufferedTurnTap}.\n * Returns a promise that resolves when the turn finishes — hand it to\n * `ctx.waitUntil` so a disconnect can't kill the turn. Never rejects on\n * client-write failure; a source error marks the turn 'error' (after flushing\n * what was produced) and rethrows.\n */\nexport async function pumpBufferedTurn(opts: PumpBufferedTurnOptions): Promise<void> {\n const tap = createBufferedTurnTap(opts)\n try {\n for await (const raw of opts.source) await tap.onEvent(raw)\n await tap.done('complete')\n } catch (err) {\n await tap.done('error')\n throw err\n }\n}\n\n// ── replay (consumer side) ────────────────────────────────────────────────\n\n/** Define options for replaying turn events with control over sequence, polling, and timeout */\nexport interface ReplayTurnEventsOptions {\n store: TurnEventStore\n turnId: string\n /** Replay strictly after this sequence number (0 = from the beginning). */\n fromSeq?: number\n /** Poll cadence while the turn is still running. Default 500ms. */\n pollMs?: number\n /** Give up following a 'running' turn after this long. Default 120s. */\n timeoutMs?: number\n}\n\n/**\n * Yield buffered events after `fromSeq`, then keep polling while the turn is\n * still 'running' until it completes, errors, or times out. Terminates with a\n * final `{seq: -1, event: '{\"type\":\"turn_status\",...}'}` marker so clients\n * know why the replay ended.\n */\nexport async function* replayTurnEvents(opts: ReplayTurnEventsOptions): AsyncGenerator<BufferedTurnEvent> {\n const pollMs = opts.pollMs ?? 500\n const timeoutMs = opts.timeoutMs ?? 120_000\n let cursor = opts.fromSeq ?? 0\n const deadline = Date.now() + timeoutMs\n\n for (;;) {\n const batch = await opts.store.read(opts.turnId, cursor)\n for (const row of batch) {\n cursor = Math.max(cursor, row.seq)\n yield row\n }\n const status = await opts.store.getStatus(opts.turnId)\n if (status !== 'running') {\n // Writers flush before publishing terminal status; include rows committed after the first read.\n yield* await opts.store.read(opts.turnId, cursor)\n yield { seq: -1, event: JSON.stringify({ type: 'turn_status', status: status ?? 'unknown' }) }\n return\n }\n if (Date.now() >= deadline) {\n yield { seq: -1, event: JSON.stringify({ type: 'turn_status', status: 'timeout' }) }\n return\n }\n await new Promise((r) => setTimeout(r, pollMs))\n }\n}\n\n/**\n * Serialize a replayed row for the wire, stamping the buffer ordinal ONTO the\n * line so a reconnecting client can continue from `?fromSeq=<lastSeq>`.\n *\n * The seq lives on the {@link BufferedTurnEvent} row wrapper, not inside the\n * serialized event — `flush()` builds `{seq: ++seq, event: JSON.stringify(ev)}`.\n * A route that enqueues `row.event` alone therefore emits lines with no seq at\n * all, and every client cursor silently pins to 0: each reconnect refetches the\n * whole turn and re-applies every delta onto already-rendered state. This\n * restores the contract `web-react/chat-stream` already documents (\"replayed\n * lines carry an extra `seq` — transparently ignored\").\n *\n * The `{seq: -1}` `turn_status` sentinel is passed through unstamped: it is a\n * terminator, not a cursor position, and stamping it would move a client's\n * cursor to -1.\n *\n * Fail-soft by construction — a line that is not a JSON object passes through\n * verbatim. A stamping bug must degrade to today's behaviour, never break a\n * replay.\n */\nexport function stampReplaySeq(row: BufferedTurnEvent): string {\n if (row.seq <= 0) return row.event\n const line = row.event\n // Cheap splice instead of parse+stringify: these rows are already canonical\n // JSON objects from `JSON.stringify`, and replay is a hot per-event path.\n if (line.charCodeAt(0) !== 0x7b /* { */) return line\n const rest = line.slice(1)\n return rest.trimStart().startsWith('}')\n ? `{\"seq\":${row.seq}${rest}`\n : `{\"seq\":${row.seq},${rest}`\n}\n\n// ── D1 store ──────────────────────────────────────────────────────────────\n\n/** A bound D1 statement used by the turn store. */\nexport interface D1BoundForTurns {\n run(): Promise<unknown>\n all<T = Record<string, unknown>>(): Promise<{ results: T[] }>\n first<T = Record<string, unknown>>(): Promise<T | null>\n}\n\n/** Minimal structural D1 contract (Cloudflare `D1Database` satisfies it). */\nexport interface D1LikeForTurns {\n prepare(sql: string): {\n bind(...values: unknown[]): D1BoundForTurns\n }\n /** D1's only atomic primitive. Retention refuses a driver without it rather\n * than deleting events and status in separate, reorderable requests. */\n batch?(statements: D1BoundForTurns[]): Promise<unknown[]>\n}\n\nfunction normalizeTurnCutoff(before: number | Date): { milliseconds: number; iso: string } {\n const milliseconds = before instanceof Date ? before.getTime() : before\n if (!Number.isFinite(milliseconds)) {\n throw new RangeError('turn retention cutoff must be a finite Unix-millisecond timestamp or a valid Date')\n }\n const date = new Date(milliseconds)\n if (!Number.isFinite(date.getTime())) {\n throw new RangeError('turn retention cutoff is outside the supported Date range')\n }\n return { milliseconds, iso: date.toISOString() }\n}\n\nasync function runAtomicTurnBatch(\n db: D1LikeForTurns,\n statements: D1BoundForTurns[],\n): Promise<unknown[]> {\n if (typeof db.batch !== 'function') {\n throw new Error('turn retention requires D1 batch() for atomic deletion')\n }\n return db.batch(statements)\n}\n\nfunction changesFromD1Result(result: unknown): number {\n if (!result || typeof result !== 'object') return 0\n const meta = (result as { meta?: unknown }).meta\n if (meta && typeof meta === 'object') {\n const changes = (meta as { changes?: unknown }).changes\n if (typeof changes === 'number' && Number.isFinite(changes)) return changes\n }\n const changes = (result as { changes?: unknown }).changes\n return typeof changes === 'number' && Number.isFinite(changes) ? changes : 0\n}\n\n/** Schema for the D1 store — append to the product's migrations. */\nexport const TURN_EVENTS_MIGRATION_SQL = `\nCREATE TABLE IF NOT EXISTS turn_events (\n turnId TEXT NOT NULL,\n seq INTEGER NOT NULL,\n event TEXT NOT NULL,\n PRIMARY KEY (turnId, seq)\n);\nCREATE TABLE IF NOT EXISTS turn_status (\n turnId TEXT PRIMARY KEY,\n status TEXT NOT NULL,\n scopeId TEXT,\n updatedAt TEXT NOT NULL\n);\nCREATE INDEX IF NOT EXISTS idx_turn_status_scope ON turn_status (scopeId, status);\nCREATE INDEX IF NOT EXISTS idx_turn_status_retention ON turn_status (status, updatedAt);\n`\n\n/** For deployments whose `turn_status` table predates `scopeId`/`listRunning` —\n * run once to add the column (the CREATE above already includes it for new\n * deployments). SQLite ignores a duplicate-add error if already applied. */\nexport const TURN_STATUS_SCOPE_MIGRATION_SQL = `ALTER TABLE turn_status ADD COLUMN scopeId TEXT;`\n\n/** Run once before using `createD1PlanFollowUpGate`: it adds the lease column\n * the gate fences its claims on. Stores that never take follow-up claims do\n * not need it, so the base turn tables leave it out. */\nexport const TURN_STATUS_LEASE_MIGRATION_SQL = 'ALTER TABLE turn_status ADD COLUMN leaseToken TEXT;'\n\n/** For deployments that already have the turn tables, add the index used by\n * terminal-turn retention without rerunning the table migration. */\nexport const TURN_STATUS_RETENTION_MIGRATION_SQL = 'CREATE INDEX IF NOT EXISTS idx_turn_status_retention ON turn_status (status, updatedAt);'\n\n/** Resolve a TurnEventStore that appends and reads turn events using a D1-like database interface */\n/** A store that lists running turns by scope, as the turn lock's default reclaim needs. */\nexport type ListingTurnEventStore = TurnEventStore & Required<Pick<TurnEventStore, 'listRunning'>>\n\n/** 100 D1 variables per statement, three per row. */\nconst D1_APPEND_CHUNK = 33\n\nexport function createD1TurnEventStore(\n db: D1LikeForTurns,\n options: TurnEventStoreOptions = {},\n): ListingTurnEventStore {\n const now = options.now ?? Date.now\n const runningTurnLeaseMs = Math.max(\n 1,\n options.runningTurnLeaseMs ?? DEFAULT_RUNNING_TURN_LEASE_MS,\n )\n return {\n async append(turnId, events) {\n if (!events.length) return\n // One multi-row insert per flush window keeps write volume bounded, but\n // D1 caps a statement at 100 bound variables, so a burst of more than 33\n // events (a subagent finishing, a long tool result) failed the whole\n // flush with `D1_ERROR: too many SQL variables` and killed the turn.\n // Rows are appended in order across chunks; a partial failure leaves a\n // prefix, which the ordered `seq` column already tolerates on replay.\n for (let start = 0; start < events.length; start += D1_APPEND_CHUNK) {\n const chunk = events.slice(start, start + D1_APPEND_CHUNK)\n const placeholders = chunk.map(() => '(?, ?, ?)').join(', ')\n const values = chunk.flatMap((e) => [turnId, e.seq, e.event])\n await db\n .prepare(\n `WITH pending(turnId, seq, event) AS (VALUES ${placeholders})\n INSERT OR IGNORE INTO turn_events (turnId, seq, event)\n SELECT pending.turnId, pending.seq, pending.event\n FROM pending\n WHERE NOT EXISTS (\n SELECT 1 FROM turn_status\n WHERE turn_status.turnId = pending.turnId\n AND turn_status.status IN ('complete', 'error')\n )`,\n )\n .bind(...values)\n .run()\n }\n },\n async read(turnId, fromSeq) {\n const { results } = await db\n .prepare('SELECT seq, event FROM turn_events WHERE turnId = ? AND seq > ? ORDER BY seq ASC')\n .bind(turnId, fromSeq)\n .all<{ seq: number; event: string }>()\n return results\n },\n async setStatus(turnId, status, scopeId, options = {}) {\n const at = new Date(now()).toISOString()\n if (options.onlyIfRunningBefore !== undefined) {\n // A guarded write never creates a row: it settles one that exists, is running and is stale.\n await db\n .prepare(\n `UPDATE turn_status SET status = ?, scopeId = COALESCE(?, scopeId)${options.preserveUpdatedAt ? '' : ', updatedAt = ?'} WHERE turnId = ? AND status = 'running' AND updatedAt < ?`,\n )\n .bind(...[status, scopeId ?? null, ...(options.preserveUpdatedAt ? [] : [at]), turnId, new Date(options.onlyIfRunningBefore).toISOString()])\n .run()\n return\n }\n // COALESCE preserves a scopeId set on the initial 'running' write when a\n // later 'complete'/'error' write passes none.\n await db\n .prepare(\n `INSERT INTO turn_status (turnId, status, scopeId, updatedAt) VALUES (?, ?, ?, ?) ON CONFLICT(turnId) DO UPDATE SET status = excluded.status, scopeId = COALESCE(excluded.scopeId, turn_status.scopeId)${options.preserveUpdatedAt ? '' : ', updatedAt = excluded.updatedAt'}`,\n )\n .bind(turnId, status, scopeId ?? null, at)\n .run()\n },\n async getStatus(turnId) {\n const row = await db.prepare('SELECT status FROM turn_status WHERE turnId = ?').bind(turnId).first<{ status: TurnStatus }>()\n return row?.status ?? null\n },\n async listRunning(scopeId) {\n const { results } = await db\n .prepare(\n \"SELECT turnId FROM turn_status WHERE scopeId = ? AND status = 'running' AND updatedAt >= ? ORDER BY updatedAt DESC, rowid DESC\",\n )\n .bind(scopeId, new Date(now() - runningTurnLeaseMs).toISOString())\n .all<{ turnId: string }>()\n return results.map((r) => r.turnId)\n },\n async resetEvents(turnId) {\n await db.prepare('DELETE FROM turn_events WHERE turnId = ?').bind(turnId).run()\n },\n async deleteTurn(turnId) {\n await runAtomicTurnBatch(db, [\n db.prepare('DELETE FROM turn_events WHERE turnId = ?').bind(turnId),\n db.prepare('DELETE FROM turn_status WHERE turnId = ?').bind(turnId),\n ])\n },\n async listStaleRunning(before, limit) {\n const { results } = await db\n // `*` so a deployment that applied TURN_STATUS_LEASE_MIGRATION_SQL also returns its follow-up claims' leaseToken.\n .prepare(\"SELECT * FROM turn_status WHERE status = 'running' AND updatedAt < ? ORDER BY updatedAt ASC LIMIT ?\")\n .bind(new Date(before).toISOString(), Math.max(1, Math.floor(limit)))\n .all<{ turnId: string; scopeId: string | null; updatedAt: string; leaseToken?: string | null }>()\n return results.map((row) => ({\n turnId: row.turnId,\n scopeId: row.scopeId ?? null,\n updatedAt: Date.parse(row.updatedAt),\n ...(row.leaseToken ? { leaseToken: row.leaseToken } : {}),\n }))\n },\n async readTail(turnId, count) {\n const { results } = await db\n .prepare('SELECT seq, event FROM turn_events WHERE turnId = ? ORDER BY seq DESC LIMIT ?')\n .bind(turnId, Math.max(1, Math.floor(count)))\n .all<{ seq: number; event: string }>()\n return results\n },\n async pruneTerminalTurns(before) {\n const cutoff = normalizeTurnCutoff(before)\n const terminalBefore = \"status IN ('complete', 'error') AND updatedAt < ?\"\n const results = await runAtomicTurnBatch(db, [\n db\n .prepare(\n `DELETE FROM turn_events WHERE turnId IN (SELECT turnId FROM turn_status WHERE ${terminalBefore})`,\n )\n .bind(cutoff.iso),\n db.prepare(`DELETE FROM turn_status WHERE ${terminalBefore}`).bind(cutoff.iso),\n ])\n return changesFromD1Result(results[1])\n },\n }\n}\n\n/** In-memory store for tests and keyless local dev. */\nexport function createMemoryTurnEventStore(\n options: TurnEventStoreOptions = {},\n): ListingTurnEventStore {\n const events = new Map<string, BufferedTurnEvent[]>()\n const status = new Map<string, TurnStatus>()\n const scopes = new Map<string, string>()\n const order: string[] = []\n const updatedAt = new Map<string, number>()\n const now = options.now ?? Date.now\n const runningTurnLeaseMs = Math.max(\n 1,\n options.runningTurnLeaseMs ?? DEFAULT_RUNNING_TURN_LEASE_MS,\n )\n return {\n async append(turnId, rows) {\n if (status.get(turnId) === 'complete' || status.get(turnId) === 'error') return\n const list = events.get(turnId) ?? []\n list.push(...rows)\n events.set(turnId, list)\n },\n async read(turnId, fromSeq) {\n return (events.get(turnId) ?? []).filter((e) => e.seq > fromSeq)\n },\n async setStatus(turnId, s, scopeId, options = {}) {\n if (options.onlyIfRunningBefore !== undefined) {\n const stale = status.get(turnId) === 'running' && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < options.onlyIfRunningBefore\n if (!stale) return\n }\n const existed = status.has(turnId)\n status.set(turnId, s)\n if (scopeId) scopes.set(turnId, scopeId)\n if (!order.includes(turnId)) order.push(turnId)\n if (!(options.preserveUpdatedAt && existed)) updatedAt.set(turnId, now())\n },\n async getStatus(turnId) {\n return status.get(turnId) ?? null\n },\n async listRunning(scopeId) {\n const cutoff = now() - runningTurnLeaseMs\n return order\n .filter(\n (turnId) =>\n status.get(turnId) === 'running' &&\n scopes.get(turnId) === scopeId &&\n (updatedAt.get(turnId) ?? Number.NEGATIVE_INFINITY) >= cutoff,\n )\n .sort((left, right) => {\n const updatedDelta = (updatedAt.get(right) ?? 0) - (updatedAt.get(left) ?? 0)\n return updatedDelta || order.indexOf(right) - order.indexOf(left)\n })\n },\n async resetEvents(turnId) {\n events.delete(turnId)\n },\n async deleteTurn(turnId) {\n events.delete(turnId)\n status.delete(turnId)\n scopes.delete(turnId)\n updatedAt.delete(turnId)\n const index = order.indexOf(turnId)\n if (index >= 0) order.splice(index, 1)\n },\n async listStaleRunning(before, limit) {\n return order\n .filter((turnId) => status.get(turnId) === 'running' && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < before)\n .sort((left, right) => (updatedAt.get(left) ?? 0) - (updatedAt.get(right) ?? 0))\n .slice(0, Math.max(1, Math.floor(limit)))\n .map((turnId) => ({ turnId, scopeId: scopes.get(turnId) ?? null, updatedAt: updatedAt.get(turnId)! }))\n },\n async readTail(turnId, count) {\n return (events.get(turnId) ?? []).slice(-Math.max(1, Math.floor(count))).reverse()\n },\n async pruneTerminalTurns(before) {\n const cutoff = normalizeTurnCutoff(before).milliseconds\n const removable = order.filter((turnId) => {\n const s = status.get(turnId)\n return (s === 'complete' || s === 'error') && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < cutoff\n })\n for (const turnId of removable) {\n events.delete(turnId)\n status.delete(turnId)\n scopes.delete(turnId)\n updatedAt.delete(turnId)\n }\n if (removable.length) {\n const removed = new Set(removable)\n for (let i = order.length - 1;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EACvC,IAAI,CAAC,YAAY,EAAE,QAAQ,SAAS,OAAO,IAAI,MAAM,KAAK,MAAM,WAAW,UAAU,IAAI,MAAM,EAAG,EAAE;AAAA,IACzG;AAAA,IACA,MAAM,SAAS,QAAQ,OAAO;AAC5B,cAAQ,OAAO,IAAI,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC,EAAE,QAAQ;AAAA,IACnF;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAC/B,YAAM,SAAS,oBAAoB,MAAM,EAAE;AAC3C,YAAM,YAAY,MAAM,OAAO,CAAC,WAAW;AACzC,cAAM,IAAI,OAAO,IAAI,MAAM;AAC3B,gBAAQ,MAAM,cAAc,MAAM,aAAa,UAAU,IAAI,MAAM,KAAK,OAAO,qBAAqB;AAAA,MACtG,CAAC;AACD,iBAAW,UAAU,WAAW;AAC9B,eAAO,OAAO,MAAM;AACpB,eAAO,OAAO,MAAM;AACpB,eAAO,OAAO,MAAM;AACpB,kBAAU,OAAO,MAAM;AAAA,MACzB;AACA,UAAI,UAAU,QAAQ;AACpB,cAAM,UAAU,IAAI,IAAI,SAAS;AACjC,iBAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC1C,cAAI,QAAQ,IAAI,MAAM,CAAC,CAAE,EAAG,OAAM,OAAO,GAAG,CAAC;AAAA,QAC/C;AAAA,MACF;AACA,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AACF;","names":["changes","options"]}
@@ -17,7 +17,7 @@ import "../chunk-QUV5M7SZ.js";
17
17
  import {
18
18
  assistantRowIdForTurn
19
19
  } from "../chunk-QM5TPZQY.js";
20
- import "../chunk-P6NVRUW6.js";
20
+ import "../chunk-OV4X4P6U.js";
21
21
  import "../chunk-YG66IHDU.js";
22
22
  import "../chunk-SADNHPAY.js";
23
23
  import "../chunk-ZVEEWGDK.js";
@@ -35,7 +35,7 @@ import {
35
35
  } from "../chunk-AOSQ5JCO.js";
36
36
  import {
37
37
  createD1TurnEventStore
38
- } from "../chunk-FIH4MI6S.js";
38
+ } from "../chunk-YY3D7LYV.js";
39
39
  import "../chunk-6YLVFV3F.js";
40
40
  import "../chunk-L3QR274L.js";
41
41
  import "../chunk-XELWWXJJ.js";
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  createChatTurnRoutes,
3
3
  streamChatRouteAsSandboxEvents
4
- } from "../chunk-Y7FTBDFZ.js";
4
+ } from "../chunk-7JR5WWAP.js";
5
5
  import "../chunk-SBHFMDR7.js";
6
6
  import "../chunk-H6BRJU5M.js";
7
7
  import "../chunk-4DBHC63F.js";
8
8
  import "../chunk-RN4WPTBH.js";
9
9
  import "../chunk-MM6RLOXF.js";
10
10
  import "../chunk-M4QITAQV.js";
11
- import "../chunk-YLRH77J3.js";
11
+ import "../chunk-EHUSCRLY.js";
12
12
  import "../chunk-F4TUZYMX.js";
13
13
  import "../chunk-MH74DY2I.js";
14
14
  import "../chunk-ORC66WNJ.js";
15
15
  import "../chunk-QUV5M7SZ.js";
16
16
  import "../chunk-QM5TPZQY.js";
17
- import "../chunk-P6NVRUW6.js";
17
+ import "../chunk-OV4X4P6U.js";
18
18
  import "../chunk-YG66IHDU.js";
19
19
  import "../chunk-SADNHPAY.js";
20
20
  import "../chunk-ZVEEWGDK.js";
@@ -23,7 +23,7 @@ import "../chunk-TB6KNPFI.js";
23
23
  import "../chunk-2IGXFHUO.js";
24
24
  import "../chunk-ALIWB2P3.js";
25
25
  import "../chunk-AOSQ5JCO.js";
26
- import "../chunk-FIH4MI6S.js";
26
+ import "../chunk-YY3D7LYV.js";
27
27
  import "../chunk-6YLVFV3F.js";
28
28
  import "../chunk-L3QR274L.js";
29
29
  import "../chunk-XELWWXJJ.js";
@@ -114,7 +114,7 @@ import {
114
114
  warmKey,
115
115
  warmReceiptId,
116
116
  warmWeekdayOf
117
- } from "../chunk-YLRH77J3.js";
117
+ } from "../chunk-EHUSCRLY.js";
118
118
  import {
119
119
  createWarmCache
120
120
  } from "../chunk-F4TUZYMX.js";
@@ -163,7 +163,7 @@ import {
163
163
  } from "../chunk-2IGXFHUO.js";
164
164
  import "../chunk-ALIWB2P3.js";
165
165
  import "../chunk-AOSQ5JCO.js";
166
- import "../chunk-FIH4MI6S.js";
166
+ import "../chunk-YY3D7LYV.js";
167
167
  import "../chunk-6YLVFV3F.js";
168
168
  import "../chunk-L3QR274L.js";
169
169
  import "../chunk-XELWWXJJ.js";
@@ -5,7 +5,7 @@ import {
5
5
  observeTurnEvent,
6
6
  parseTurnObservation,
7
7
  settleOrphanedTurns
8
- } from "../chunk-P6NVRUW6.js";
8
+ } from "../chunk-OV4X4P6U.js";
9
9
  import {
10
10
  buildUserTextParts,
11
11
  messageHasTurnId,
@@ -51,7 +51,7 @@ import {
51
51
  pumpBufferedTurn,
52
52
  replayTurnEvents,
53
53
  stampReplaySeq
54
- } from "../chunk-FIH4MI6S.js";
54
+ } from "../chunk-YY3D7LYV.js";
55
55
  import "../chunk-T3C2BX7N.js";
56
56
  export {
57
57
  DEFAULT_RUNNING_TURN_LEASE_MS,
@@ -46,7 +46,7 @@ import {
46
46
  } from "../chunk-AOSQ5JCO.js";
47
47
  import {
48
48
  DEFAULT_RUNNING_TURN_LEASE_MS
49
- } from "../chunk-FIH4MI6S.js";
49
+ } from "../chunk-YY3D7LYV.js";
50
50
  import "../chunk-S5SRJJQG.js";
51
51
 
52
52
  // src/turn-stream/cancellation-do.ts
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  AGENT_PROFILE_EDITOR_SECTIONS,
3
3
  AgentProfileEditor
4
- } from "../chunk-4ZCUGJ6O.js";
5
- import "../chunk-HHMELPDN.js";
4
+ } from "../chunk-44RPVT2G.js";
5
+ import "../chunk-C3EGV2WQ.js";
6
6
  import "../chunk-CZVO2SPE.js";
7
7
  import "../chunk-E43PMYHD.js";
8
8
  import "../chunk-ZAMHLXNS.js";
@@ -174,7 +174,7 @@ import {
174
174
  AGENT_PROFILE_EDITOR_SECTIONS,
175
175
  AgentProfileEditor,
176
176
  AgentProfileRegistryError
177
- } from "../chunk-4ZCUGJ6O.js";
177
+ } from "../chunk-44RPVT2G.js";
178
178
  import {
179
179
  EvidenceLineageTable,
180
180
  ExceptionList,
@@ -203,7 +203,7 @@ import {
203
203
  preloadWhenIdle,
204
204
  useComposerAttachments,
205
205
  useDictation
206
- } from "../chunk-S7GZ7XPC.js";
206
+ } from "../chunk-BQOS6XU3.js";
207
207
  import "../chunk-L7MB2LLM.js";
208
208
  import {
209
209
  AgentSessionControls,
@@ -215,7 +215,7 @@ import {
215
215
  filterAcceptedFiles,
216
216
  isAcceptedFileType,
217
217
  renamePastedImages
218
- } from "../chunk-HHMELPDN.js";
218
+ } from "../chunk-C3EGV2WQ.js";
219
219
  import {
220
220
  WorkspaceInitial,
221
221
  WorkspaceSwitcher
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "4.0.47",
3
+ "version": "4.0.49",
4
4
  "packageManager": "pnpm@11.28.8",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/stream/turn-buffer.ts"],"sourcesContent":["/**\n * Resumable chat turns — the router-path answer to \"streams resume on\n * disconnect\" (issue #27). A turn's loop events are teed into a store as they\n * stream; the turn keeps running under `ctx.waitUntil` when the client drops;\n * a reconnecting client replays the buffered tail by sequence number and\n * keeps following until the turn completes.\n *\n * POST /chat/stream → pumpBufferedTurn(...) + live NDJSON\n * GET /chat/stream/:turnId → replayTurnEvents({ fromSeq }) → NDJSON\n *\n * Storage is a structural seam ({@link TurnEventStore}); a D1 implementation\n * ships here because that's what Cloudflare products have (KV is unsuitable:\n * eventually consistent cross-isolate). Per-token deltas would mean hundreds\n * of rows per turn, so consecutive text/reasoning deltas are coalesced within\n * a flush window before they are persisted — replay yields slightly chunkier\n * deltas with identical concatenation.\n */\n\nexport type TurnStatus = 'running' | 'complete' | 'error'\n\n/** A running row is a renewable lease, not permanent truth. If the process\n * driving a turn dies before writing a terminal status, reconnect discovery\n * must eventually stop returning that abandoned row. */\nexport const DEFAULT_RUNNING_TURN_LEASE_MS = 5 * 60_000\n\n/** Keep a healthy turn's lease comfortably ahead of expiry without turning\n * per-token streaming into status-write traffic. */\nexport const DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS = 30_000\n\n/** Represent a buffered turn event with a sequence number and serialized event data */\nexport interface BufferedTurnEvent {\n seq: number\n /** The serialized event line (JSON string, no trailing newline). */\n event: string\n}\n\n/** Manage and query turn events and their lifecycle statuses within a scoped event store */\nexport interface TurnEventStore {\n /**\n * Append rows while the turn is live. Implementations must ignore rows that\n * arrive after `setStatus` publishes `complete` or `error`; the terminal\n * status is the replay fence for a detached live projection.\n */\n append(turnId: string, events: BufferedTurnEvent[]): Promise<void>\n read(turnId: string, fromSeq: number): Promise<BufferedTurnEvent[]>\n /** Record turn lifecycle. `scopeId` (a thread/session id) is optional and lets\n * {@link TurnEventStore.listRunning} rediscover this turn after a client reload\n * loses the turnId; stores that don't track scope ignore it. */\n setStatus(turnId: string, status: TurnStatus, scopeId?: string, options?: TurnStatusWriteOptions): Promise<void>\n getStatus(turnId: string): Promise<TurnStatus | null>\n /** Unexpired running turnIds for a scope, newest first — so a reloaded client\n * (clientRunId lost) can find and resume the in-flight turn without reviving\n * a row abandoned by a dead process. Optional: a store records it only if\n * `setStatus` was given a `scopeId`. */\n listRunning?(scopeId: string): Promise<string[]>\n /** Remove one turn's buffered events and keep its status, so a genuine\n * re-stream after a crash starts at seq 0 without interleaving orphaned\n * rows. `runDetachedTurn` requires it to recover a `running` turn. */\n resetEvents?(turnId: string): Promise<void>\n /** Explicitly remove one turn's events and status. Optional so existing\n * custom stores remain source-compatible; the built-in D1 and memory stores\n * provide it. */\n deleteTurn?(turnId: string): Promise<void>\n /** Remove terminal turns whose status was updated before `before` (Unix\n * milliseconds or a Date). Running turns are never eligible. */\n pruneTerminalTurns?(before: number | Date): Promise<number>\n /** Running turns last renewed before `before` (Unix ms), oldest first, at most\n * `limit`: the candidates {@link settleOrphanedTurns} settles. */\n listStaleRunning?(before: number, limit: number): Promise<StaleRunningTurn[]>\n /** The last `count` events of a turn, newest first; a bounded read of the tail. */\n readTail?(turnId: string, count: number): Promise<BufferedTurnEvent[]>\n}\n\n/** A running turn nothing has renewed since `updatedAt`. */\nexport interface StaleRunningTurn {\n turnId: string\n scopeId: string | null\n /** Unix ms of the last status write. */\n updatedAt: number\n /** Set on a plan follow-up claim (`createD1PlanFollowUpGate`), which keeps its own staleness and does not renew. */\n leaseToken?: string | null\n}\n\n/**\n * Settling a stream nothing produces any more. A sweep that ends an orphaned\n * stream must not move it in time, since reports place a stream by its update\n * time, and must not end one whose producer came back meanwhile.\n */\nexport interface TurnStatusWriteOptions {\n /** Keep the row's update time; a new row still takes the current time. */\n preserveUpdatedAt?: boolean\n /** Write only when the row is still `running` and was last updated before this time (Unix ms). */\n onlyIfRunningBefore?: number\n}\n\n/** Configure running-turn lease evaluation. The clock is injectable so store\n * contract tests do not sleep. Keep the default in production unless a\n * deployment also tunes the buffer's renewal interval. */\nexport interface TurnEventStoreOptions {\n runningTurnLeaseMs?: number\n now?: () => number\n}\n\n// ── coalescing ────────────────────────────────────────────────────────────\n\ntype AnyRecord = Record<string, unknown>\n\nfunction deltaTypeOf(ev: unknown): 'text' | 'reasoning' | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object') return null\n const inner = (e.kind === 'event' ? (e.event as AnyRecord | undefined) : e) as AnyRecord | undefined\n if (!inner || typeof inner !== 'object') return null\n if ((inner.type === 'text' || inner.type === 'reasoning') && typeof inner.text === 'string') {\n return inner.type\n }\n return null\n}\n\nfunction innerOf(ev: unknown): AnyRecord | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object') return null\n const inner = (e.kind === 'event' ? e.event : e) as AnyRecord | undefined\n return inner && typeof inner === 'object' ? inner : null\n}\n\n/**\n * The key of a live-state event whose latest value supersedes earlier ones:\n * the model-processing heartbeat, and a harness's raw update of a text or\n * reasoning part (it carries the part's whole state, keyed by part id). Null\n * for every other event.\n */\nfunction liveStateKeyOf(ev: unknown): string | null {\n const inner = innerOf(ev)\n if (!inner) return null\n if (inner.type === 'model-processing') return 'model-processing'\n if (inner.type !== 'raw') return null\n const raw = (inner.data as AnyRecord | undefined)?.event as AnyRecord | undefined\n const part = raw?.part as AnyRecord | undefined\n if ((raw?.type === 'text' || raw?.type === 'reasoning') && typeof part?.id === 'string') return `raw:${part.id}`\n return null\n}\n\n/** Whether an event only projects live progress, so it may wait for the flush window and be coalesced. */\nexport function isLiveProgressEvent(ev: unknown): boolean {\n return deltaTypeOf(ev) !== null || liveStateKeyOf(ev) !== null\n}\n\n/**\n * Merge text and reasoning deltas of the same type into one event, across the\n * live-state events a harness interleaves with them, and keep only the latest\n * of each live-state event. A reasoning model streams three events per token\n * (its raw part update, a model-processing heartbeat and the delta); merging\n * only adjacent deltas wrote all three as rows (1.63 M rows in a\n * day, 59,659 in one turn). Any other event is a boundary nothing merges\n * across. Concatenation-preserving: replaying the coalesced stream produces\n * the same accumulated text, and the latest state of every part.\n */\nexport function coalesceDeltas(events: unknown[]): unknown[] {\n const out: unknown[] = []\n let run: { type: 'text' | 'reasoning'; index: number } | null = null\n let stateSlots = new Map<string, number>()\n for (const ev of events) {\n const type = deltaTypeOf(ev)\n if (type) {\n if (run && run.type === type) {\n const merged = JSON.parse(JSON.stringify(out[run.index])) as AnyRecord\n innerOf(merged)!.text = String(innerOf(out[run.index])!.text) + String(innerOf(ev)!.text)\n out[run.index] = merged\n } else {\n out.push(ev)\n run = { type, index: out.length - 1 }\n }\n continue\n }\n const key = liveStateKeyOf(ev)\n if (key) {\n const slot = stateSlots.get(key)\n if (slot === undefined) {\n out.push(ev)\n stateSlots.set(key, out.length - 1)\n } else {\n out[slot] = ev\n }\n continue\n }\n out.push(ev)\n run = null\n stateSlots = new Map()\n }\n return out\n}\n\nfunction asPartUpdate(ev: unknown): { partId: unknown; delta: unknown } | null {\n const e = ev as AnyRecord | null\n if (!e || typeof e !== 'object' || e.type !== 'message.part.updated') return null\n const data = e.data as AnyRecord | undefined\n if (!data || typeof data !== 'object') return null\n const part = data.part as AnyRecord | undefined\n const partId = part?.id ?? data.partId ?? part?.partId ?? null\n return { partId, delta: data.delta }\n}\n\n/**\n * Coalesce consecutive `message.part.updated` deltas for the SAME part into one\n * event. agent-runtime products stream `ChatStreamEvent` NDJSON\n * (`{type:'message.part.updated', data:{part, delta}}`); pumped through the\n * buffer with the default tool-loop coalescer, every per-token delta persists as\n * its own row because that coalescer never recognizes the shape. Pass this as\n * {@link PumpBufferedTurnOptions.coalesce} instead.\n *\n * Concatenation-preserving for BOTH consumer styles: the merged event keeps the\n * LATEST event's `data.part` (already the cumulative accumulation) and sets\n * `data.delta` to the concatenation of the merged deltas, so a client that\n * appends `delta` and one that reads the cumulative `part` both reconstruct the\n * identical final text.\n */\nexport function coalesceChatStreamEvents(events: unknown[]): unknown[] {\n const out: unknown[] = []\n for (const ev of events) {\n const cur = asPartUpdate(ev)\n const prevEv = out[out.length - 1]\n const prev = prevEv ? asPartUpdate(prevEv) : null\n if (cur && prev && cur.partId != null && cur.partId === prev.partId) {\n // Base the merged row on the latest event (its `part` is the most complete\n // accumulation); carry forward the summed delta.\n const merged = JSON.parse(JSON.stringify(ev)) as AnyRecord\n ;(merged.data as AnyRecord).delta = String(prev.delta ?? '') + String(cur.delta ?? '')\n out[out.length - 1] = merged\n continue\n }\n out.push(ev)\n }\n return out\n}\n\n// ── buffering core (the tap) ────────────────────────────────────────────────\n\n/** Define options for buffering and flushing turn events with optional live client delivery and event coalescing */\nexport interface BufferedTurnOptions {\n store: TurnEventStore\n turnId: string\n /** Deliver one serialized line to the live client. Throwing here (client\n * disconnected) does NOT stop buffering — events keep persisting. */\n write?: (line: string) => Promise<void> | void\n /** Flush buffered events to the store at most this often. Default 400ms. */\n flushIntervalMs?: number\n /** Flush window once a durable owner has taken the turn ({@link BufferedTurnTap.detach}). Live-progress events\n * wait for it; any other event flushes at once, after them. Default 2000ms. */\n detachedFlushIntervalMs?: number\n /** Per-flush coalescer. Default {@link coalesceDeltas} (tool-loop text/reasoning\n * deltas). agent-runtime products streaming `ChatStreamEvent` pass\n * {@link coalesceChatStreamEvents} so per-token deltas don't each persist as a\n * row. Must be concatenation-preserving. */\n coalesce?: (events: unknown[]) => unknown[]\n /** Optional scope (thread/session id) recorded with the turn status, so\n * {@link TurnEventStore.listRunning} can find this turn after a reload. */\n scopeId?: string\n /** How often to renew the running-turn lease while a producer is alive.\n * The timer is backed up by event-driven renewal when a runtime freezes\n * unreferenced timers during remote I/O. Default\n * {@link DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS}. */\n runningTurnRenewIntervalMs?: number\n}\n\n/** A push-driven buffer for a turn whose producer the caller does NOT own. */\nexport interface BufferedTurnTap {\n /** Buffer one event: persist (coalesced, on the flush window) + best-effort\n * live-deliver. Wire to a push source's per-event hook (e.g. agent-runtime\n * `handleChatTurn`'s `hooks.onEvent`). Marks the turn 'running' on first call.\n * `execution.started` commits its ordered prefix before this tap's live write. */\n onEvent(raw: unknown): Promise<void>\n /** Settle the turn: final flush + set status. Call after the producer resolves\n * ('complete') or rejects ('error'). 'error' flushes what was produced first. */\n done(status?: Extract<TurnStatus, 'complete' | 'error'>): Promise<void>\n /**\n * Give terminal-status ownership to an external durable runner. Stops this\n * tap's running-lease renewal and flushes its current projection, but keeps\n * `onEvent` available as an append-only live-observation path. After the\n * handoff, an event that is not live progress (a marker, interaction, tool\n * event, error or terminal event) flushes before `onEvent` returns, so a\n * durable owner cannot publish terminal status ahead of it; live progress\n * (deltas, heartbeats, raw part updates) is coalesced over\n * `detachedFlushIntervalMs`. Call it again when observation ends to flush any\n * final event.\n *\n * A caller MUST have registered that durable owner before detaching: this\n * method intentionally writes no replacement status.\n */\n detach(): Promise<void>\n}\n\n/**\n * The buffering core. Sequence-numbers every event, delivers it to `write`\n * (best-effort — a disconnected client never stops buffering), and flushes to\n * the store in coalesced batches. Drives both transports:\n *\n * • {@link pumpBufferedTurn} — when you OWN an `AsyncIterable` producer.\n * • this tap (`onEvent`/`done`) — when the producer owns iteration and only\n * hands you a push callback (agent-runtime `handleChatTurn`'s `hooks.onEvent`\n * + the finished body). Durability stays here in the shell; the engine needs\n * no `TurnEventStore` seam.\n */\n/** Serialized characters of pending events that force a flush before the window ends. */\nconst MAX_PENDING_CHARS = 64 * 1024\n\nexport function createBufferedTurnTap(opts: BufferedTurnOptions): BufferedTurnTap {\n const flushIntervalMs = opts.flushIntervalMs ?? 400\n const detachedFlushIntervalMs = opts.detachedFlushIntervalMs ?? 2000\n let pendingChars = 0\n const coalesce = opts.coalesce ?? coalesceDeltas\n const startedAt = Date.now()\n let seq = 0\n let clientGone = false\n let pending: unknown[] = []\n let lastFlush = Date.now()\n let started = false\n let settled = false\n let detached = false\n let renewalTimer: ReturnType<typeof setTimeout> | undefined\n let renewal: Promise<void> = Promise.resolve()\n let lastRenewedAt = 0\n const runningTurnRenewIntervalMs = Math.max(\n 1,\n opts.runningTurnRenewIntervalMs ?? DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,\n )\n\n function clearRenewalTimer(): void {\n if (renewalTimer !== undefined) clearTimeout(renewalTimer)\n renewalTimer = undefined\n }\n\n function scheduleRenewal(): void {\n if (settled || detached || !opts.scopeId) return\n clearRenewalTimer()\n const elapsedMs = Math.max(0, Date.now() - lastRenewedAt)\n const delayMs = Math.max(1, runningTurnRenewIntervalMs - elapsedMs)\n renewalTimer = setTimeout(() => {\n renewalTimer = undefined\n void renewLease()\n }, delayMs)\n // A deliberately abandoned tap in a Node test must not keep the process\n // alive until the production renewal interval elapses.\n if (typeof renewalTimer === 'object' && 'unref' in renewalTimer) {\n renewalTimer.unref()\n }\n }\n\n async function renewLease(): Promise<void> {\n if (settled || detached || !opts.scopeId) return\n clearRenewalTimer()\n lastRenewedAt = Date.now()\n renewal = renewal\n .then(() => opts.store.setStatus(opts.turnId, 'running', opts.scopeId))\n .catch(() => {})\n await renewal\n scheduleRenewal()\n }\n\n async function flush(): Promise<void> {\n if (pending.length === 0) return\n const batch = coalesce(pending)\n pending = []\n pendingChars = 0\n const rows = batch.map((ev) => ({ seq: ++seq, event: JSON.stringify(ev) }))\n await opts.store.append(opts.turnId, rows)\n lastFlush = Date.now()\n }\n\n async function ensureStarted(): Promise<void> {\n if (started) return\n started = true\n // An external durable owner may have detached before the first observed\n // event. It owns status from that point, so this tap must never resurrect\n // its running lease.\n if (detached) return\n await opts.store.setStatus(opts.turnId, 'running', opts.scopeId)\n lastRenewedAt = Date.now()\n scheduleRenewal()\n }\n\n return {\n async onEvent(raw) {\n await ensureStarted()\n // Cloudflare may freeze an unreferenced timer while a producer is\n // awaiting remote I/O. A real event (including the route heartbeat)\n // therefore also renews any lease whose interval has elapsed.\n if (\n !detached &&\n opts.scopeId &&\n Date.now() - lastRenewedAt >= runningTurnRenewIntervalMs\n ) {\n await renewLease()\n }\n // Stamp ms-since-turn-start so any stored turn is replayable AND traceable\n // (see ../trace) from the same buffered rows.\n const ev = raw && typeof raw === 'object' ? { ...(raw as Record<string, unknown>), _t: Date.now() - startedAt } : raw\n const line = JSON.stringify(ev)\n pending.push(ev)\n pendingChars += line?.length ?? 0\n // Commit the native identity and its ordered prefix before our live write.\n if (innerOf(ev)?.type === 'execution.started') await flush()\n if (!clientGone && opts.write) {\n try {\n // Live delivery carries a provisional ordering hint, not the persisted\n // seq (coalescing changes seq assignment); clients resume with the\n // seqs from replay, or 0 for \"everything\".\n await opts.write(line)\n } catch {\n clientGone = true\n }\n }\n // Once detached, a turn marker, interaction, tool event, error or terminal event persists at once (with the\n // progress before it), and live progress waits for the window, so a reasoning model's per-token events do\n // not each become a row. An external owner's terminal status can fence at most the last window of progress.\n const due = detached\n ? !isLiveProgressEvent(ev) || Date.now() - lastFlush >= detachedFlushIntervalMs\n : Date.now() - lastFlush >= flushIntervalMs\n if (due || pendingChars >= MAX_PENDING_CHARS) await flush()\n },\n async done(status = 'complete') {\n await ensureStarted()\n if (detached) {\n await flush()\n return\n }\n settled = true\n clearRenewalTimer()\n await renewal\n if (status === 'error') {\n await flush().catch(() => {})\n await opts.store.setStatus(opts.turnId, 'error', opts.scopeId).catch(() => {})\n return\n }\n await flush()\n await opts.store.setStatus(opts.turnId, 'complete', opts.scopeId)\n },\n async detach() {\n detached = true\n clearRenewalTimer()\n // A renewal already queued before detach may be writing `running`. Wait\n // for it before returning so the durable owner can safely publish a\n // terminal status after the awaited handoff.\n await renewal\n await flush()\n },\n }\n}\n\n// ── pump (producer side) ──────────────────────────────────────────────────\n\n/** Define options to pump data from an asynchronous iterable source with buffered turn control */\nexport interface PumpBufferedTurnOptions extends BufferedTurnOptions {\n source: AsyncIterable<unknown>\n}\n\n/**\n * Drive a turn to completion regardless of the live client, when you OWN the\n * producer as an `AsyncIterable`. A thin driver over {@link createBufferedTurnTap}.\n * Returns a promise that resolves when the turn finishes — hand it to\n * `ctx.waitUntil` so a disconnect can't kill the turn. Never rejects on\n * client-write failure; a source error marks the turn 'error' (after flushing\n * what was produced) and rethrows.\n */\nexport async function pumpBufferedTurn(opts: PumpBufferedTurnOptions): Promise<void> {\n const tap = createBufferedTurnTap(opts)\n try {\n for await (const raw of opts.source) await tap.onEvent(raw)\n await tap.done('complete')\n } catch (err) {\n await tap.done('error')\n throw err\n }\n}\n\n// ── replay (consumer side) ────────────────────────────────────────────────\n\n/** Define options for replaying turn events with control over sequence, polling, and timeout */\nexport interface ReplayTurnEventsOptions {\n store: TurnEventStore\n turnId: string\n /** Replay strictly after this sequence number (0 = from the beginning). */\n fromSeq?: number\n /** Poll cadence while the turn is still running. Default 500ms. */\n pollMs?: number\n /** Give up following a 'running' turn after this long. Default 120s. */\n timeoutMs?: number\n}\n\n/**\n * Yield buffered events after `fromSeq`, then keep polling while the turn is\n * still 'running' until it completes, errors, or times out. Terminates with a\n * final `{seq: -1, event: '{\"type\":\"turn_status\",...}'}` marker so clients\n * know why the replay ended.\n */\nexport async function* replayTurnEvents(opts: ReplayTurnEventsOptions): AsyncGenerator<BufferedTurnEvent> {\n const pollMs = opts.pollMs ?? 500\n const timeoutMs = opts.timeoutMs ?? 120_000\n let cursor = opts.fromSeq ?? 0\n const deadline = Date.now() + timeoutMs\n\n for (;;) {\n const batch = await opts.store.read(opts.turnId, cursor)\n for (const row of batch) {\n cursor = Math.max(cursor, row.seq)\n yield row\n }\n const status = await opts.store.getStatus(opts.turnId)\n if (status !== 'running') {\n // Writers flush before publishing terminal status; include rows committed after the first read.\n yield* await opts.store.read(opts.turnId, cursor)\n yield { seq: -1, event: JSON.stringify({ type: 'turn_status', status: status ?? 'unknown' }) }\n return\n }\n if (Date.now() >= deadline) {\n yield { seq: -1, event: JSON.stringify({ type: 'turn_status', status: 'timeout' }) }\n return\n }\n await new Promise((r) => setTimeout(r, pollMs))\n }\n}\n\n/**\n * Serialize a replayed row for the wire, stamping the buffer ordinal ONTO the\n * line so a reconnecting client can continue from `?fromSeq=<lastSeq>`.\n *\n * The seq lives on the {@link BufferedTurnEvent} row wrapper, not inside the\n * serialized event — `flush()` builds `{seq: ++seq, event: JSON.stringify(ev)}`.\n * A route that enqueues `row.event` alone therefore emits lines with no seq at\n * all, and every client cursor silently pins to 0: each reconnect refetches the\n * whole turn and re-applies every delta onto already-rendered state. This\n * restores the contract `web-react/chat-stream` already documents (\"replayed\n * lines carry an extra `seq` — transparently ignored\").\n *\n * The `{seq: -1}` `turn_status` sentinel is passed through unstamped: it is a\n * terminator, not a cursor position, and stamping it would move a client's\n * cursor to -1.\n *\n * Fail-soft by construction — a line that is not a JSON object passes through\n * verbatim. A stamping bug must degrade to today's behaviour, never break a\n * replay.\n */\nexport function stampReplaySeq(row: BufferedTurnEvent): string {\n if (row.seq <= 0) return row.event\n const line = row.event\n // Cheap splice instead of parse+stringify: these rows are already canonical\n // JSON objects from `JSON.stringify`, and replay is a hot per-event path.\n if (line.charCodeAt(0) !== 0x7b /* { */) return line\n const rest = line.slice(1)\n return rest.trimStart().startsWith('}')\n ? `{\"seq\":${row.seq}${rest}`\n : `{\"seq\":${row.seq},${rest}`\n}\n\n// ── D1 store ──────────────────────────────────────────────────────────────\n\n/** A bound D1 statement used by the turn store. */\nexport interface D1BoundForTurns {\n run(): Promise<unknown>\n all<T = Record<string, unknown>>(): Promise<{ results: T[] }>\n first<T = Record<string, unknown>>(): Promise<T | null>\n}\n\n/** Minimal structural D1 contract (Cloudflare `D1Database` satisfies it). */\nexport interface D1LikeForTurns {\n prepare(sql: string): {\n bind(...values: unknown[]): D1BoundForTurns\n }\n /** D1's only atomic primitive. Retention refuses a driver without it rather\n * than deleting events and status in separate, reorderable requests. */\n batch?(statements: D1BoundForTurns[]): Promise<unknown[]>\n}\n\nfunction normalizeTurnCutoff(before: number | Date): { milliseconds: number; iso: string } {\n const milliseconds = before instanceof Date ? before.getTime() : before\n if (!Number.isFinite(milliseconds)) {\n throw new RangeError('turn retention cutoff must be a finite Unix-millisecond timestamp or a valid Date')\n }\n const date = new Date(milliseconds)\n if (!Number.isFinite(date.getTime())) {\n throw new RangeError('turn retention cutoff is outside the supported Date range')\n }\n return { milliseconds, iso: date.toISOString() }\n}\n\nasync function runAtomicTurnBatch(\n db: D1LikeForTurns,\n statements: D1BoundForTurns[],\n): Promise<unknown[]> {\n if (typeof db.batch !== 'function') {\n throw new Error('turn retention requires D1 batch() for atomic deletion')\n }\n return db.batch(statements)\n}\n\nfunction changesFromD1Result(result: unknown): number {\n if (!result || typeof result !== 'object') return 0\n const meta = (result as { meta?: unknown }).meta\n if (meta && typeof meta === 'object') {\n const changes = (meta as { changes?: unknown }).changes\n if (typeof changes === 'number' && Number.isFinite(changes)) return changes\n }\n const changes = (result as { changes?: unknown }).changes\n return typeof changes === 'number' && Number.isFinite(changes) ? changes : 0\n}\n\n/** Schema for the D1 store — append to the product's migrations. */\nexport const TURN_EVENTS_MIGRATION_SQL = `\nCREATE TABLE IF NOT EXISTS turn_events (\n turnId TEXT NOT NULL,\n seq INTEGER NOT NULL,\n event TEXT NOT NULL,\n PRIMARY KEY (turnId, seq)\n);\nCREATE TABLE IF NOT EXISTS turn_status (\n turnId TEXT PRIMARY KEY,\n status TEXT NOT NULL,\n scopeId TEXT,\n updatedAt TEXT NOT NULL\n);\nCREATE INDEX IF NOT EXISTS idx_turn_status_scope ON turn_status (scopeId, status);\nCREATE INDEX IF NOT EXISTS idx_turn_status_retention ON turn_status (status, updatedAt);\n`\n\n/** For deployments whose `turn_status` table predates `scopeId`/`listRunning` —\n * run once to add the column (the CREATE above already includes it for new\n * deployments). SQLite ignores a duplicate-add error if already applied. */\nexport const TURN_STATUS_SCOPE_MIGRATION_SQL = `ALTER TABLE turn_status ADD COLUMN scopeId TEXT;`\n\n/** Run once before using `createD1PlanFollowUpGate`: it adds the lease column\n * the gate fences its claims on. Stores that never take follow-up claims do\n * not need it, so the base turn tables leave it out. */\nexport const TURN_STATUS_LEASE_MIGRATION_SQL = 'ALTER TABLE turn_status ADD COLUMN leaseToken TEXT;'\n\n/** For deployments that already have the turn tables, add the index used by\n * terminal-turn retention without rerunning the table migration. */\nexport const TURN_STATUS_RETENTION_MIGRATION_SQL = 'CREATE INDEX IF NOT EXISTS idx_turn_status_retention ON turn_status (status, updatedAt);'\n\n/** Resolve a TurnEventStore that appends and reads turn events using a D1-like database interface */\n/** A store that lists running turns by scope, as the turn lock's default reclaim needs. */\nexport type ListingTurnEventStore = TurnEventStore & Required<Pick<TurnEventStore, 'listRunning'>>\n\n/** 100 D1 variables per statement, three per row. */\nconst D1_APPEND_CHUNK = 33\n\nexport function createD1TurnEventStore(\n db: D1LikeForTurns,\n options: TurnEventStoreOptions = {},\n): ListingTurnEventStore {\n const now = options.now ?? Date.now\n const runningTurnLeaseMs = Math.max(\n 1,\n options.runningTurnLeaseMs ?? DEFAULT_RUNNING_TURN_LEASE_MS,\n )\n return {\n async append(turnId, events) {\n if (!events.length) return\n // One multi-row insert per flush window keeps write volume bounded, but\n // D1 caps a statement at 100 bound variables, so a burst of more than 33\n // events (a subagent finishing, a long tool result) failed the whole\n // flush with `D1_ERROR: too many SQL variables` and killed the turn.\n // Rows are appended in order across chunks; a partial failure leaves a\n // prefix, which the ordered `seq` column already tolerates on replay.\n for (let start = 0; start < events.length; start += D1_APPEND_CHUNK) {\n const chunk = events.slice(start, start + D1_APPEND_CHUNK)\n const placeholders = chunk.map(() => '(?, ?, ?)').join(', ')\n const values = chunk.flatMap((e) => [turnId, e.seq, e.event])\n await db\n .prepare(\n `WITH pending(turnId, seq, event) AS (VALUES ${placeholders})\n INSERT OR IGNORE INTO turn_events (turnId, seq, event)\n SELECT pending.turnId, pending.seq, pending.event\n FROM pending\n WHERE NOT EXISTS (\n SELECT 1 FROM turn_status\n WHERE turn_status.turnId = pending.turnId\n AND turn_status.status IN ('complete', 'error')\n )`,\n )\n .bind(...values)\n .run()\n }\n },\n async read(turnId, fromSeq) {\n const { results } = await db\n .prepare('SELECT seq, event FROM turn_events WHERE turnId = ? AND seq > ? ORDER BY seq ASC')\n .bind(turnId, fromSeq)\n .all<{ seq: number; event: string }>()\n return results\n },\n async setStatus(turnId, status, scopeId, options = {}) {\n const at = new Date(now()).toISOString()\n if (options.onlyIfRunningBefore !== undefined) {\n // A guarded write never creates a row: it settles one that exists, is running and is stale.\n await db\n .prepare(\n `UPDATE turn_status SET status = ?, scopeId = COALESCE(?, scopeId)${options.preserveUpdatedAt ? '' : ', updatedAt = ?'} WHERE turnId = ? AND status = 'running' AND updatedAt < ?`,\n )\n .bind(...[status, scopeId ?? null, ...(options.preserveUpdatedAt ? [] : [at]), turnId, new Date(options.onlyIfRunningBefore).toISOString()])\n .run()\n return\n }\n // COALESCE preserves a scopeId set on the initial 'running' write when a\n // later 'complete'/'error' write passes none.\n await db\n .prepare(\n `INSERT INTO turn_status (turnId, status, scopeId, updatedAt) VALUES (?, ?, ?, ?) ON CONFLICT(turnId) DO UPDATE SET status = excluded.status, scopeId = COALESCE(excluded.scopeId, turn_status.scopeId)${options.preserveUpdatedAt ? '' : ', updatedAt = excluded.updatedAt'}`,\n )\n .bind(turnId, status, scopeId ?? null, at)\n .run()\n },\n async getStatus(turnId) {\n const row = await db.prepare('SELECT status FROM turn_status WHERE turnId = ?').bind(turnId).first<{ status: TurnStatus }>()\n return row?.status ?? null\n },\n async listRunning(scopeId) {\n const { results } = await db\n .prepare(\n \"SELECT turnId FROM turn_status WHERE scopeId = ? AND status = 'running' AND updatedAt >= ? ORDER BY updatedAt DESC, rowid DESC\",\n )\n .bind(scopeId, new Date(now() - runningTurnLeaseMs).toISOString())\n .all<{ turnId: string }>()\n return results.map((r) => r.turnId)\n },\n async resetEvents(turnId) {\n await db.prepare('DELETE FROM turn_events WHERE turnId = ?').bind(turnId).run()\n },\n async deleteTurn(turnId) {\n await runAtomicTurnBatch(db, [\n db.prepare('DELETE FROM turn_events WHERE turnId = ?').bind(turnId),\n db.prepare('DELETE FROM turn_status WHERE turnId = ?').bind(turnId),\n ])\n },\n async listStaleRunning(before, limit) {\n const { results } = await db\n // `*` so a deployment that applied TURN_STATUS_LEASE_MIGRATION_SQL also returns its follow-up claims' leaseToken.\n .prepare(\"SELECT * FROM turn_status WHERE status = 'running' AND updatedAt < ? ORDER BY updatedAt ASC LIMIT ?\")\n .bind(new Date(before).toISOString(), Math.max(1, Math.floor(limit)))\n .all<{ turnId: string; scopeId: string | null; updatedAt: string; leaseToken?: string | null }>()\n return results.map((row) => ({\n turnId: row.turnId,\n scopeId: row.scopeId ?? null,\n updatedAt: Date.parse(row.updatedAt),\n ...(row.leaseToken ? { leaseToken: row.leaseToken } : {}),\n }))\n },\n async readTail(turnId, count) {\n const { results } = await db\n .prepare('SELECT seq, event FROM turn_events WHERE turnId = ? ORDER BY seq DESC LIMIT ?')\n .bind(turnId, Math.max(1, Math.floor(count)))\n .all<{ seq: number; event: string }>()\n return results\n },\n async pruneTerminalTurns(before) {\n const cutoff = normalizeTurnCutoff(before)\n const terminalBefore = \"status IN ('complete', 'error') AND updatedAt < ?\"\n const results = await runAtomicTurnBatch(db, [\n db\n .prepare(\n `DELETE FROM turn_events WHERE turnId IN (SELECT turnId FROM turn_status WHERE ${terminalBefore})`,\n )\n .bind(cutoff.iso),\n db.prepare(`DELETE FROM turn_status WHERE ${terminalBefore}`).bind(cutoff.iso),\n ])\n return changesFromD1Result(results[1])\n },\n }\n}\n\n/** In-memory store for tests and keyless local dev. */\nexport function createMemoryTurnEventStore(\n options: TurnEventStoreOptions = {},\n): ListingTurnEventStore {\n const events = new Map<string, BufferedTurnEvent[]>()\n const status = new Map<string, TurnStatus>()\n const scopes = new Map<string, string>()\n const order: string[] = []\n const updatedAt = new Map<string, number>()\n const now = options.now ?? Date.now\n const runningTurnLeaseMs = Math.max(\n 1,\n options.runningTurnLeaseMs ?? DEFAULT_RUNNING_TURN_LEASE_MS,\n )\n return {\n async append(turnId, rows) {\n if (status.get(turnId) === 'complete' || status.get(turnId) === 'error') return\n const list = events.get(turnId) ?? []\n list.push(...rows)\n events.set(turnId, list)\n },\n async read(turnId, fromSeq) {\n return (events.get(turnId) ?? []).filter((e) => e.seq > fromSeq)\n },\n async setStatus(turnId, s, scopeId, options = {}) {\n if (options.onlyIfRunningBefore !== undefined) {\n const stale = status.get(turnId) === 'running' && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < options.onlyIfRunningBefore\n if (!stale) return\n }\n const existed = status.has(turnId)\n status.set(turnId, s)\n if (scopeId) scopes.set(turnId, scopeId)\n if (!order.includes(turnId)) order.push(turnId)\n if (!(options.preserveUpdatedAt && existed)) updatedAt.set(turnId, now())\n },\n async getStatus(turnId) {\n return status.get(turnId) ?? null\n },\n async listRunning(scopeId) {\n const cutoff = now() - runningTurnLeaseMs\n return order\n .filter(\n (turnId) =>\n status.get(turnId) === 'running' &&\n scopes.get(turnId) === scopeId &&\n (updatedAt.get(turnId) ?? Number.NEGATIVE_INFINITY) >= cutoff,\n )\n .sort((left, right) => {\n const updatedDelta = (updatedAt.get(right) ?? 0) - (updatedAt.get(left) ?? 0)\n return updatedDelta || order.indexOf(right) - order.indexOf(left)\n })\n },\n async resetEvents(turnId) {\n events.delete(turnId)\n },\n async deleteTurn(turnId) {\n events.delete(turnId)\n status.delete(turnId)\n scopes.delete(turnId)\n updatedAt.delete(turnId)\n const index = order.indexOf(turnId)\n if (index >= 0) order.splice(index, 1)\n },\n async listStaleRunning(before, limit) {\n return order\n .filter((turnId) => status.get(turnId) === 'running' && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < before)\n .sort((left, right) => (updatedAt.get(left) ?? 0) - (updatedAt.get(right) ?? 0))\n .slice(0, Math.max(1, Math.floor(limit)))\n .map((turnId) => ({ turnId, scopeId: scopes.get(turnId) ?? null, updatedAt: updatedAt.get(turnId)! }))\n },\n async readTail(turnId, count) {\n return (events.get(turnId) ?? []).slice(-Math.max(1, Math.floor(count))).reverse()\n },\n async pruneTerminalTurns(before) {\n const cutoff = normalizeTurnCutoff(before).milliseconds\n const removable = order.filter((turnId) => {\n const s = status.get(turnId)\n return (s === 'complete' || s === 'error') && (updatedAt.get(turnId) ?? Number.POSITIVE_INFINITY) < cutoff\n })\n for (const turnId of removable) {\n events.delete(turnId)\n status.delete(turnId)\n scopes.delete(turnId)\n updatedAt.delete(turnId)\n }\n if (removable.length) {\n const removed = new Set(removable)\n for (let i = order.length - 1; i >= 0; i--) {\n if (removed.has(order[i]!)) order.splice(i, 1)\n }\n }\n return removable.length\n },\n }\n}\n"],"mappings":";AAuBO,IAAM,gCAAgC,IAAI;AAI1C,IAAM,yCAAyC;AAgFtD,SAAS,YAAY,IAA0C;AAC7D,QAAM,IAAI;AACV,MAAI,CAAC,KAAK,OAAO,MAAM,SAAU,QAAO;AACxC,QAAM,QAAS,EAAE,SAAS,UAAW,EAAE,QAAkC;AACzE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,OAAK,MAAM,SAAS,UAAU,MAAM,SAAS,gBAAgB,OA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