@songsid/agend 2.4.0-beta.16 → 2.4.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/auth-api.js +2 -0
  2. package/dist/auth-api.js.map +1 -1
  3. package/dist/backend/claude-code.d.ts +10 -1
  4. package/dist/backend/claude-code.js +7 -2
  5. package/dist/backend/claude-code.js.map +1 -1
  6. package/dist/backend/claude-transcript-errors.d.ts +4 -0
  7. package/dist/backend/claude-transcript-errors.js +5 -1
  8. package/dist/backend/claude-transcript-errors.js.map +1 -1
  9. package/dist/backend/types.d.ts +6 -0
  10. package/dist/backend/types.js.map +1 -1
  11. package/dist/build-provenance.json +1 -1
  12. package/dist/claude-credential-launch.d.ts +1 -0
  13. package/dist/claude-credential-launch.js +13 -2
  14. package/dist/claude-credential-launch.js.map +1 -1
  15. package/dist/claude-credential-vault.d.ts +7 -1
  16. package/dist/claude-credential-vault.js +26 -1
  17. package/dist/claude-credential-vault.js.map +1 -1
  18. package/dist/claude-request-observation.d.ts +7 -0
  19. package/dist/claude-request-observation.js +26 -0
  20. package/dist/claude-request-observation.js.map +1 -0
  21. package/dist/cli-audited.js +11 -8
  22. package/dist/cli-audited.js.map +1 -1
  23. package/dist/daemon.d.ts +8 -0
  24. package/dist/daemon.js +68 -13
  25. package/dist/daemon.js.map +1 -1
  26. package/dist/fleet-context.d.ts +1 -0
  27. package/dist/fleet-manager.d.ts +28 -0
  28. package/dist/fleet-manager.js +222 -10
  29. package/dist/fleet-manager.js.map +1 -1
  30. package/dist/fleet-windows-runtime.d.ts +1 -1
  31. package/dist/fleet-windows-runtime.js +1 -1
  32. package/dist/fleet-windows-runtime.js.map +1 -1
  33. package/dist/fleet-yaml-stringify.d.ts +3 -0
  34. package/dist/fleet-yaml-stringify.js +79 -0
  35. package/dist/fleet-yaml-stringify.js.map +1 -0
  36. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +17 -3
  37. package/dist/host-monitoring-alert-policy.d.ts +71 -0
  38. package/dist/host-monitoring-alert-policy.js +150 -0
  39. package/dist/host-monitoring-alert-policy.js.map +1 -0
  40. package/dist/host-monitoring-alert-resources.d.ts +11 -0
  41. package/dist/host-monitoring-alert-resources.js +16 -0
  42. package/dist/host-monitoring-alert-resources.js.map +1 -0
  43. package/dist/host-monitoring-alert-settings.d.ts +14 -0
  44. package/dist/host-monitoring-alert-settings.js +63 -0
  45. package/dist/host-monitoring-alert-settings.js.map +1 -0
  46. package/dist/host-monitoring-alert-store.d.ts +49 -0
  47. package/dist/host-monitoring-alert-store.js +228 -0
  48. package/dist/host-monitoring-alert-store.js.map +1 -0
  49. package/dist/host-monitoring-alert-text.d.ts +7 -0
  50. package/dist/host-monitoring-alert-text.js +10 -0
  51. package/dist/host-monitoring-alert-text.js.map +1 -0
  52. package/dist/host-monitoring-alerts.d.ts +76 -0
  53. package/dist/host-monitoring-alerts.js +261 -0
  54. package/dist/host-monitoring-alerts.js.map +1 -0
  55. package/dist/host-monitoring-config.d.ts +2 -1
  56. package/dist/host-monitoring-config.js +8 -3
  57. package/dist/host-monitoring-config.js.map +1 -1
  58. package/dist/host-monitoring-footprint-policy.d.ts +45 -0
  59. package/dist/host-monitoring-footprint-policy.js +150 -0
  60. package/dist/host-monitoring-footprint-policy.js.map +1 -0
  61. package/dist/host-monitoring-footprint.d.ts +42 -0
  62. package/dist/host-monitoring-footprint.js +169 -0
  63. package/dist/host-monitoring-footprint.js.map +1 -0
  64. package/dist/host-monitoring-history-files.d.ts +2 -0
  65. package/dist/host-monitoring-history-files.js +16 -0
  66. package/dist/host-monitoring-history-files.js.map +1 -0
  67. package/dist/host-monitoring-history-policy.d.ts +57 -0
  68. package/dist/host-monitoring-history-policy.js +107 -0
  69. package/dist/host-monitoring-history-policy.js.map +1 -0
  70. package/dist/host-monitoring-history-store.d.ts +52 -0
  71. package/dist/host-monitoring-history-store.js +178 -0
  72. package/dist/host-monitoring-history-store.js.map +1 -0
  73. package/dist/host-monitoring-history-worker.d.ts +1 -0
  74. package/dist/host-monitoring-history-worker.js +66 -0
  75. package/dist/host-monitoring-history-worker.js.map +1 -0
  76. package/dist/host-monitoring-history.d.ts +80 -0
  77. package/dist/host-monitoring-history.js +301 -0
  78. package/dist/host-monitoring-history.js.map +1 -0
  79. package/dist/host-monitoring-platform.d.ts +73 -0
  80. package/dist/host-monitoring-platform.js +273 -0
  81. package/dist/host-monitoring-platform.js.map +1 -0
  82. package/dist/host-monitoring-process-identity.d.ts +8 -0
  83. package/dist/host-monitoring-process-identity.js +81 -0
  84. package/dist/host-monitoring-process-identity.js.map +1 -0
  85. package/dist/host-monitoring-runtime.d.ts +42 -0
  86. package/dist/host-monitoring-runtime.js +95 -0
  87. package/dist/host-monitoring-runtime.js.map +1 -0
  88. package/dist/host-monitoring-settings-store.d.ts +5 -0
  89. package/dist/host-monitoring-settings-store.js +49 -0
  90. package/dist/host-monitoring-settings-store.js.map +1 -0
  91. package/dist/host-monitoring.d.ts +108 -0
  92. package/dist/host-monitoring.js +157 -0
  93. package/dist/host-monitoring.js.map +1 -0
  94. package/dist/instance-lifecycle.js +2 -2
  95. package/dist/instance-lifecycle.js.map +1 -1
  96. package/dist/needs-you-hub.d.ts +1 -0
  97. package/dist/needs-you-hub.js +1 -0
  98. package/dist/needs-you-hub.js.map +1 -1
  99. package/dist/needs-you.d.ts +3 -2
  100. package/dist/needs-you.js +1 -0
  101. package/dist/needs-you.js.map +1 -1
  102. package/dist/public-web-gateway.js +11 -1
  103. package/dist/public-web-gateway.js.map +1 -1
  104. package/dist/runtime-cli-install.js +17 -16
  105. package/dist/runtime-cli-install.js.map +1 -1
  106. package/dist/settings-api.d.ts +5 -0
  107. package/dist/settings-api.js +70 -7
  108. package/dist/settings-api.js.map +1 -1
  109. package/dist/settings-baseline.d.ts +1 -0
  110. package/dist/settings-baseline.js +6 -4
  111. package/dist/settings-baseline.js.map +1 -1
  112. package/dist/settings-change.js +8 -0
  113. package/dist/settings-change.js.map +1 -1
  114. package/dist/settings-effect.d.ts +4 -0
  115. package/dist/settings-effect.js +25 -4
  116. package/dist/settings-effect.js.map +1 -1
  117. package/dist/topic-commands.js +4 -0
  118. package/dist/topic-commands.js.map +1 -1
  119. package/dist/transcript-monitor.d.ts +1 -0
  120. package/dist/transcript-monitor.js +18 -0
  121. package/dist/transcript-monitor.js.map +1 -1
  122. package/dist/ui/accounts-view.js +7 -5
  123. package/dist/ui/chat-store.js +21 -4
  124. package/dist/ui/claude-credentials.js +12 -1
  125. package/dist/ui/fleet-office-pack.js +2 -2
  126. package/dist/ui/fleet-office-play.js +142 -3
  127. package/dist/ui/fleet-office-skin.js +67 -2
  128. package/dist/ui/fleet-office-store.js +41 -0
  129. package/dist/ui/fleet-office-zones.js +15 -8
  130. package/dist/ui/fleet-office.js +126 -21
  131. package/dist/ui/host-alerts.js +23 -0
  132. package/dist/ui/host-footprint.js +17 -0
  133. package/dist/ui/host-health-model.js +42 -0
  134. package/dist/ui/host-health.js +79 -0
  135. package/dist/ui/host-time.js +5 -0
  136. package/dist/ui/panel-chat.js +101 -43
  137. package/dist/ui/panel-fleet.js +24 -11
  138. package/dist/ui/panel-hub.js +5 -1
  139. package/dist/ui/panel-needs.js +27 -16
  140. package/dist/ui/panel-settings.js +4 -3
  141. package/dist/ui/search-dialog.js +8 -1
  142. package/dist/ui/settings-capabilities.js +2 -0
  143. package/dist/ui/settings-host-alerts.js +22 -0
  144. package/dist/ui/settings-host-monitoring.js +37 -18
  145. package/dist/ui/settings-registry.js +4 -1
  146. package/dist/ui/shared/accounts.css +8 -4
  147. package/dist/ui/shared/agent-sheet.js +5 -2
  148. package/dist/ui/shared/app-i18n.js +2 -2
  149. package/dist/ui/shared/app-route.js +1 -1
  150. package/dist/ui/shared/app.css +87 -9
  151. package/dist/ui/shared/app.js +1 -0
  152. package/dist/ui/shared/chat-render.js +24 -9
  153. package/dist/ui/shared/chat-strings.js +4 -4
  154. package/dist/ui/shared/chat-thread.js +45 -11
  155. package/dist/ui/shared/instance-nav.js +47 -5
  156. package/dist/ui/shared/jump-idle.js +36 -0
  157. package/dist/ui/shared/theme.js +6 -2
  158. package/dist/ui/shared/ui-menu.js +17 -11
  159. package/dist/web-api.d.ts +3 -0
  160. package/dist/web-api.js +249 -4
  161. package/dist/web-api.js.map +1 -1
  162. package/dist/web-chat-history.d.ts +47 -2
  163. package/dist/web-chat-history.js +149 -11
  164. package/dist/web-chat-history.js.map +1 -1
  165. package/dist/web-guest-access.js +4 -4
  166. package/dist/web-guest-access.js.map +1 -1
  167. package/dist/web-shell-routes.d.ts +1 -1
  168. package/dist/web-shell-routes.js +1 -1
  169. package/dist/web-shell-routes.js.map +1 -1
  170. package/dist/web-upload.d.ts +1 -1
  171. package/dist/web-upload.js.map +1 -1
  172. package/package.json +1 -1
@@ -25,8 +25,8 @@ import { identityClasses, identityOf, paintIdentity, useIdentityColors } from ".
25
25
 
26
26
  // Keep new copy beside its caller: a retained view-strings.js still links and renders the menu.
27
27
  register("agentRow", {
28
- en: { actions: "Actions for {0}", add: "Add to favorites", remove: "Remove from favorites" },
29
- "zh-TW": { actions: "{0} 的操作", add: "加入最愛", remove: "移出最愛" },
28
+ en: { actions: "Actions for {0}", add: "Add to favorites", remove: "Remove from favorites", contextAdd: "Add to favorites", contextRemove: "Remove from favorites" },
29
+ "zh-TW": { actions: "{0} 的操作", add: "加入最愛", remove: "移出最愛", contextAdd: "加到我的最愛", contextRemove: "從我的最愛移除" },
30
30
  });
31
31
 
32
32
  /** view.* text with named values. */
@@ -36,6 +36,7 @@ function tn(key, values = {}) {
36
36
  return s;
37
37
  }
38
38
  const stored = (k) => { try { return localStorage.getItem(k); } catch { return null; } };
39
+ const contextNow = () => globalThis.performance?.now?.() ?? Date.now();
39
40
  /** A row's instance name: `name` (status frames) or `instance_name` (View's roster). */
40
41
  const nameOf = (it) => (it && (it.name != null ? it.name : it.instance_name)) || "";
41
42
 
@@ -593,7 +594,44 @@ function SortMenu({ sort, phone = false }) {
593
594
  */
594
595
  export function InstanceNav({ route, items, loaded = true, exec = {}, awaiting = {}, viewOnly = false, onPick, onNew = null }) {
595
596
  const nav = useStore(navStore);
596
- const workspace = useStore(appStore).chatWorkspace;
597
+ const app = useStore(appStore), workspace = app.chatWorkspace;
598
+ const [context, setContext] = useState(null);
599
+ const hold = useRef(null), heldClick = useRef(null), contextId = useRef(0);
600
+ const cancelHold = () => { if (hold.current) clearTimeout(hold.current.timer); hold.current = null; };
601
+ useLayoutEffect(() => {
602
+ const scroll = () => cancelHold();
603
+ window.addEventListener("scroll", scroll, true);
604
+ return () => { cancelHold(); window.removeEventListener("scroll", scroll, true); };
605
+ }, []);
606
+ useLayoutEffect(() => { cancelHold(); setContext(null); }, [route?.panel, route?.instance, viewOnly]);
607
+ const contextAllowed = () => !viewOnly && !guestPage() && typeof app.sidebarChatMenu === "function";
608
+ const openContext = (name, event) => {
609
+ if (!contextAllowed()) return false;
610
+ event.preventDefault(); event.stopPropagation(); cancelHold();
611
+ const row = event.currentTarget.closest?.("[data-agent-row]") || event.currentTarget;
612
+ const anchor = row.querySelector("a.inst");
613
+ if (!anchor) return false;
614
+ anchor.focus({ preventScroll: true });
615
+ setContext({name, anchor, id: ++contextId.current}); return true;
616
+ };
617
+ const contextEvents = name => ({
618
+ onContextMenu: event => openContext(name, event),
619
+ onKeyDown: event => { if (event.key === "Escape" && event.target.closest?.("dialog[open]")) { event.stopPropagation(); return; } if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) openContext(name, event); },
620
+ onPointerDown: event => {
621
+ cancelHold();
622
+ if (!contextAllowed() || event.pointerType !== "touch" || (event.button != null && event.button !== 0) || event.target.closest?.("button")) return;
623
+ const currentTarget = event.currentTarget, x = event.clientX, y = event.clientY;
624
+ hold.current = {name, x, y, pointerId:event.pointerId, timer:setTimeout(() => {
625
+ hold.current = null;
626
+ if (!currentTarget.isConnected || !contextAllowed()) return;
627
+ heldClick.current = {name, pointerId:event.pointerId, until:contextNow()+1000};
628
+ openContext(name, {currentTarget, preventDefault(){}, stopPropagation(){}});
629
+ }, 500)};
630
+ },
631
+ onPointerMove: event => { const h = hold.current; if (h && (Math.abs(event.clientX-h.x)>8 || Math.abs(event.clientY-h.y)>8)) cancelHold(); },
632
+ onPointerUp: cancelHold, onPointerCancel: cancelHold, onDragStart: cancelHold,
633
+ onClickCapture: event => { if (heldClick.current?.name === name && contextNow() < heldClick.current.until && (!event.target.closest?.("[role=menu],dialog") || event.pointerId === heldClick.current.pointerId)) { heldClick.current=null; event.preventDefault(); event.stopPropagation(); } },
634
+ });
597
635
  const styledMenus = typeof getComputedStyle === "function" && getComputedStyle(document.documentElement).getPropertyValue?.("--agent-menu-version")?.trim() === "1";
598
636
  const names = useStore(namesStore); // #1722: which name leads
599
637
  const compact = useStore(sidebarDensityStore).value === "compact";
@@ -771,7 +809,10 @@ export function InstanceNav({ route, items, loaded = true, exec = {}, awaiting =
771
809
  onSelect: () => { if (!shown.active && !favsSorted) { focusRow.current = name; moveFavorite(name, 1, known); } } },
772
810
  ] : []),
773
811
  ].filter(Boolean);
774
- return html`<li key=${name} data-agent-row=${name} class=${`v-li${!compact && two ? " two-line" : ""}`}><a class=${`inst v-inst${on ? " active" : ""}${starred ? " inst-favorite" : ""}${fade > 0 ? " replied" : ""}${mins != null && mins < 1 ? " just" : ""} ${identityClasses(id)}`}
812
+ const favorite = menuItems.find(item => item.key === "favorite");
813
+ const contextFavorite = favorite ? { ...favorite, label: t(`agentRow.${starred ? "contextRemove" : "contextAdd"}`),
814
+ onSelect: () => { setContext(null); favorite.onSelect(); } } : null;
815
+ return html`<li key=${name} data-agent-row=${name} class=${`v-li${!compact && two ? " two-line" : ""}`} ...${contextEvents(name)}><a class=${`inst v-inst${on ? " active" : ""}${starred ? " inst-favorite" : ""}${fade > 0 ? " replied" : ""}${mins != null && mins < 1 ? " just" : ""} ${identityClasses(id)}`}
775
816
  ref=${(el) => { paintIdentity(el, id); paintReply(el, fade); }} href=${rowPath(name)} title=${instanceTooltip(it)}
776
817
  aria-label=${compact ? [...new Set([label, name, labelOf(it)])].join(" · ") : undefined}
777
818
  aria-current=${on ? "page" : undefined} onClick=${onPick} ...${dragProps({ type: "instance", name, group: g }, !fav)}>
@@ -787,7 +828,8 @@ export function InstanceNav({ route, items, loaded = true, exec = {}, awaiting =
787
828
  </a>${menuItems.length ? html`<${Menu} cls=${`inst-workspace inst-row-menu agent-menu${starred ? " is-favorite" : ""}`} fit=${true} topLayer=${true}
788
829
  ownerKey=${name} label=${t("agentRow.actions", label)} items=${menuItems}
789
830
  trigger=${styledMenus ? html`<span class="inst-menu-star" aria-hidden="true">${starred ? html`<${Icon} name="star" size=${14} />` : null}</span><span class="inst-menu-more" aria-hidden="true"><${Icon} name="more" size=${16} /></span>` : undefined} />`
790
- : starred ? html`<span class="inst-favorite-mark" aria-hidden="true"><${Icon} name="star" size=${14} /></span>` : null}</li>`;
831
+ : starred ? html`<span class="inst-favorite-mark" aria-hidden="true"><${Icon} name="star" size=${14} /></span>` : null}
832
+ ${contextAllowed() && context?.name === name ? html`<${app.sidebarChatMenu} key=${context.id} inst=${it} context=${context} favorite=${contextFavorite} onClose=${() => setContext(null)} />` : null}</li>`;
791
833
  };
792
834
  // #2401: an open list of two or more lines leaves room under the count for "shown" and Clear (stacked); otherwise compact.
793
835
  const facetSet = f.status.length > 0 || f.cli.length > 0;
@@ -0,0 +1,36 @@
1
+ // M-3492 (the user) / M-3493: 最新 (scroll to latest) shows while the reader scrolls and fades out JUMP_IDLE_MS after
2
+ // the last scroll, so it never sits over a bubble in a still view (a screenshot); the next scroll brings it back. One
3
+ // behaviour for the Fleet chat (panel-chat.js) and every Hub conversation (panel-hub.js): the Hub copies the Fleet chat.
4
+ // Faded (.is-idle in app.css), taps pass through it; it stays in the tab order and the accessibility tree, and keyboard
5
+ // focus shows it again. Whether it has focus is read from the button there when the timer fires, never latched: an
6
+ // activated 最新 goes away without a blur. A timer runs only while it is shown, owned by the conversation too (a thread
7
+ // reused for another one with 最新 still up arms anew).
8
+ import { useEffect, useRef, useState } from "/assets/app-html.js";
9
+
10
+ /** How long 最新 stays after the last scroll before it fades out (the user asked for about 2–3 s). */
11
+ export const JUMP_IDLE_MS = 2500;
12
+
13
+ /**
14
+ * scroller: the thread's scrolling element (a ref); show: whether 最新 is drawn; owner: what the thread shows (a chat's
15
+ * name, a room's store). Returns what the button takes: `idle` (add .is-idle), `ref`, `onFocus`, `onBlur`.
16
+ */
17
+ export function useJumpIdle(scroller, show, owner) {
18
+ const [idle, setIdle] = useState(false);
19
+ const timer = useRef(0), button = useRef(null), shown = useRef(false);
20
+ shown.current = !!show;
21
+ const rest = () => {
22
+ clearTimeout(timer.current);
23
+ timer.current = setTimeout(() => { const b = button.current; if (!b || b.ownerDocument.activeElement !== b) setIdle(true); }, JUMP_IDLE_MS);
24
+ };
25
+ useEffect(() => {
26
+ const sc = scroller.current; if (!sc) return undefined;
27
+ const wake = () => { setIdle(false); if (shown.current) rest(); };
28
+ sc.addEventListener("scroll", wake, { passive: true });
29
+ setIdle(false);
30
+ return () => { sc.removeEventListener("scroll", wake); clearTimeout(timer.current); };
31
+ }, [owner]);
32
+ useEffect(() => {
33
+ if (show) { setIdle(false); rest(); } else clearTimeout(timer.current);
34
+ }, [!!show, owner]);
35
+ return { idle, ref: button, onFocus: () => { clearTimeout(timer.current); setIdle(false); }, onBlur: rest };
36
+ }
@@ -140,13 +140,17 @@
140
140
  window.addEventListener("pageshow", schedule);
141
141
  // Page palettes are applied to the shell; routes replace headers. Coalesce paints and
142
142
  // ignore content attributes so updating this meta element cannot trigger itself.
143
- // M-3455: the split view's grid (.ws-geometry) changes only its size and drag state on these attributes — never a colour.
143
+ // M-3455: the split view's grid (.ws-geometry) changes only its size and drag state on these attributes — never a colour;
144
+ // M-3486: nor does a text box's height.
144
145
  // A divider drag writes them every frame; re-reading the header colours then forced a layout and style walk per frame.
145
146
  function relevant(records) {
146
147
  if (!records || !records.length) return true;
147
148
  for (var i = 0; i < records.length; i++) {
148
149
  var r = records[i];
149
- if (r.type !== "attributes" || !r.target.classList || !r.target.classList.contains("ws-geometry")) return true;
150
+ if (r.type !== "attributes") return true;
151
+ // M-3486: a text box's own height (the composer grows with its text: a style write each time it is measured).
152
+ if (r.attributeName === "style" && r.target.tagName === "TEXTAREA") continue;
153
+ if (!r.target.classList || !r.target.classList.contains("ws-geometry")) return true;
150
154
  }
151
155
  return false;
152
156
  }
@@ -8,24 +8,28 @@ import { t } from "./app-i18n.js";
8
8
  * items: [{ key, label, icon?, onSelect, danger?, disabled? }] (falsy entries are skipped). `checked` makes a radio item;
9
9
  * `checkbox: true` with `checked` a checkbox item (#2217 hotfix: the chat's card menu), which toggles and keeps the menu
10
10
  * open. `active`: the button shows a pressed look (what it controls is on), without changing its role.
11
+ * `context`: optional {id, anchor, onClose}; opens without a second button and returns focus to that row.
11
12
  * Optional `trigger` and `triggerClass` customize the button content and styling; `label` remains its accessible name.
12
13
  */
13
- export function Menu({ items, label, icon = "more", cls = "", active = false, trigger, triggerClass = "icon-btn", disabled = false, fit = false, topLayer = false, ownerKey, inactive = false, onOpen, leading }) {
14
+ export function Menu({ items, label, icon = "more", cls = "", active = false, trigger, triggerClass = "icon-btn", disabled = false, fit = false, topLayer = false, ownerKey, inactive = false, onOpen, leading, context }) {
14
15
  const [open, setOpen] = useState(false);
15
16
  const [placement,setPlacement] = useState("");
16
17
  const btn = useRef(null), list = useRef(null);
17
18
  const shown = (items || []).filter(Boolean);
19
+ const anchor = () => context?.anchor || btn.current;
20
+ const close = () => { setOpen(false); context?.onClose?.(); };
18
21
  const anchored = topLayer && open && typeof getComputedStyle === "function" && getComputedStyle(document.documentElement).getPropertyValue?.("--agent-menu-version")?.trim() === "1";
19
22
  useLayoutEffect(() => { setOpen(false); }, [ownerKey]);
23
+ useLayoutEffect(() => { if (context) setOpen(true); }, [context?.id]);
20
24
  useLayoutEffect(() => { if (inactive) setOpen(false); }, [inactive]);
21
25
  useLayoutEffect(() => {
22
- if (!open || !fit || !btn.current?.getBoundingClientRect || !list.current) return;
26
+ if (!open || !fit || !anchor()?.getBoundingClientRect || !list.current) return;
23
27
  const menu = list.current;
24
28
  if (anchored) menu.showPopover?.(); // escape the sidebar's scrolling clip; the same Menu keeps focus/ownership
25
29
  const place = () => {
26
- if (!btn.current || !list.current) return;
27
- const rect = btn.current.getBoundingClientRect();
28
- const boundary = btn.current.closest?.(".dlg-body")?.getBoundingClientRect();
30
+ if (!anchor() || !list.current) return;
31
+ const rect = anchor().getBoundingClientRect();
32
+ const boundary = anchor().closest?.(".dlg-body")?.getBoundingClientRect();
29
33
  const top = Math.max(0,boundary?.top || 0), bottom = Math.min(window.innerHeight,boundary?.bottom || window.innerHeight);
30
34
  const above = rect.top-top-8, below = bottom-rect.bottom-8;
31
35
  const up = below < Math.min(list.current.scrollHeight || 280,280) && above > below;
@@ -52,7 +56,7 @@ export function Menu({ items, label, icon = "more", cls = "", active = false, tr
52
56
  if (!open || disabled) { if (open && disabled) setOpen(false); return undefined; }
53
57
  const first = list.current && list.current.querySelector("[role=menuitem]:not([disabled]), [role=menuitemradio]:not([disabled]), [role=menuitemcheckbox]:not([disabled])");
54
58
  if (first) first.focus({ preventScroll: true });
55
- const outside = (e) => { if (list.current && !list.current.contains(e.target) && btn.current && !btn.current.contains(e.target)) setOpen(false); };
59
+ const outside = (e) => { if (list.current && !list.current.contains(e.target) && anchor() && !anchor().contains(e.target)) close(); };
56
60
  document.addEventListener("pointerdown", outside, true);
57
61
  return () => document.removeEventListener("pointerdown", outside, true);
58
62
  }, [open, disabled]);
@@ -61,19 +65,19 @@ export function Menu({ items, label, icon = "more", cls = "", active = false, tr
61
65
  if (e.target.closest?.("[role=menu]") !== list.current) return; // a nested card menu owns its own keys
62
66
  const all = [...list.current.querySelectorAll("[role=menuitem]:not([disabled]), [role=menuitemradio]:not([disabled]), [role=menuitemcheckbox]:not([disabled])")];
63
67
  const i = all.indexOf(document.activeElement);
64
- if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); setOpen(false); btn.current && btn.current.focus({ preventScroll: true }); }
68
+ if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); anchor()?.focus({ preventScroll: true }); close(); }
65
69
  else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); document.activeElement?.click(); }
66
70
  else if (e.key === "ArrowDown") { e.preventDefault(); (all[(i + 1) % all.length] || all[0])?.focus(); }
67
71
  else if (e.key === "ArrowUp") { e.preventDefault(); (all[(i - 1 + all.length) % all.length] || all[0])?.focus(); }
68
72
  else if (e.key === "Home") { e.preventDefault(); all[0]?.focus(); }
69
73
  else if (e.key === "End") { e.preventDefault(); all[all.length - 1]?.focus(); }
70
- else if (e.key === "Tab") setOpen(false);
74
+ else if (e.key === "Tab") close();
71
75
  }
72
- function choose(item) { if (disabled || item.disabled) return; setOpen(false); btn.current && btn.current.focus({ preventScroll: true }); item.onSelect(); }
76
+ function choose(item) { if (disabled || item.disabled) return; anchor()?.focus({ preventScroll: true }); close(); item.onSelect(); }
73
77
  return html`<div class=${`menu ${cls}`}>
74
- <button ref=${btn} type="button" class=${`${triggerClass}${active ? " active" : ""}`} aria-haspopup="menu" aria-expanded=${open ? "true" : "false"} disabled=${disabled}
78
+ ${context ? null : html`<button ref=${btn} type="button" class=${`${triggerClass}${active ? " active" : ""}`} aria-haspopup="menu" aria-expanded=${open ? "true" : "false"} disabled=${disabled}
75
79
  aria-label=${label || t("app.more")} title=${label || t("app.more")} onClick=${() => { if (!disabled) { if (!open) onOpen?.(); setOpen(!open); } }}
76
- onKeyDown=${(e) => { if (!disabled && (e.key === "ArrowDown" || e.key === "ArrowUp")) { e.preventDefault(); onOpen?.(); setOpen(true); } }}>${trigger === undefined ? html`<${Icon} name=${icon} />` : trigger}</button>
80
+ onKeyDown=${(e) => { if (!disabled && (e.key === "ArrowDown" || e.key === "ArrowUp")) { e.preventDefault(); onOpen?.(); setOpen(true); } }}>${trigger === undefined ? html`<${Icon} name=${icon} />` : trigger}</button>`}
77
81
  ${open && !disabled ? html`<div data-trust="menu" ref=${list} popover=${anchored ? "manual" : undefined} class=${`menu-list${anchored ? " menu-anchored" : ""}${fit ? placement : ""}`} role="menu" aria-label=${label || t("app.more")} onKeyDown=${onKey}>
78
82
  ${leading || null}
79
83
  ${shown.map(item => item.heading
@@ -91,3 +95,5 @@ export function Menu({ items, label, icon = "more", cls = "", active = false, tr
91
95
  </div>`;
92
96
  }
93
97
  Menu.workspaceVersion = 1;
98
+
99
+ Menu.contextVersion = 1;
package/dist/web-api.d.ts CHANGED
@@ -59,6 +59,9 @@ export type AccountWriteResult = {
59
59
  message?: string;
60
60
  };
61
61
  export interface WebApiContext extends ClaudeCredentialApi {
62
+ hostHistoryQuery?(range: unknown, series: unknown): Promise<import('./host-monitoring-history.js').HostHistoryResult>;
63
+ hostHealthSnapshot?(agentOffset?: number): import("./host-monitoring.js").HostHealthSnapshot;
64
+ hostAlertAction?(key: string, revision: number, actor: string, snoozeMs?: number): Promise<boolean>;
62
65
  clearContactOrigin?: ContactApiHost["clearContactOrigin"];
63
66
  contactPermissions?: ContactApiHost["contactPermissions"];
64
67
  writeContactPermissions?: ContactApiHost["writeContactPermissions"];
package/dist/web-api.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { historyQuery } from './host-monitoring-history-policy.js';
1
2
  import { handleClaudeCredentials } from "./web-claude-credentials.js";
2
3
  import { pipeline } from "node:stream/promises";
3
4
  import { handleContactAuthorizationApi } from "./contact-auth-api.js";
@@ -42,7 +43,7 @@ import { MAX_COMMAND_ARGS } from "./web-commands.js";
42
43
  import { ROUTE_WORKER_CSP, ROUTE_WORKER_PATH, sendPanelHtml } from "./web-host-guard.js";
43
44
  import { libavoidFile } from "./web-libavoid.js";
44
45
  import { shellRoute } from "./web-shell-routes.js";
45
- import { createReadStream, createWriteStream, existsSync, readFileSync } from "node:fs";
46
+ import { createReadStream, createWriteStream, existsSync, readFileSync, closeSync } from "node:fs";
46
47
  import { servedAssets } from "./auth-api.js";
47
48
  import { assetIntact, assetsUnchanged, assetVersion, assetVersionMark, answerStaleAsset, buildModuleGraph, staticClosure, versionShell, IMMUTABLE_PRIVATE } from "./web-asset-version.js";
48
49
  import { join, dirname } from "node:path";
@@ -222,6 +223,9 @@ const safeInstanceSegment = (name) => /^[^\\/\x00]+$/.test(name) && name !== "."
222
223
  const streamGuests = new WeakMap();
223
224
  const streamContactProjection = new WeakMap();
224
225
  function contactNeedsFor(req, url, ctx, base) {
226
+ const auth = evaluateWebRequest(req, url, ctx.webToken ?? null, ctx.webSessions, { touch: false });
227
+ const admin = auth.kind === 'allow' && auth.via === 'session' && auth.session.tier === 'admin';
228
+ base = admin ? base : base.filter(item => !item || typeof item !== 'object' || item.type !== 'host');
225
229
  const ordinary = base.filter(item => !item || typeof item !== "object" || item.type !== "contact");
226
230
  const actor = ctx.contactActor?.(req, url);
227
231
  if (actor && ctx.contactNeeds)
@@ -2625,6 +2629,92 @@ function statusTick(ctx, t) {
2625
2629
  export function handleWebRequest(req, res, url, ctx) {
2626
2630
  const path = url.pathname;
2627
2631
  const method = req.method ?? "GET";
2632
+ if (path === "/ui/host-history") {
2633
+ res.setHeader("Cache-Control", "private, no-store");
2634
+ const auth = () => evaluateWebRequest(req, url, ctx.webToken ?? null, ctx.webSessions, { touch: false });
2635
+ const who = auth();
2636
+ if (who.kind !== "allow" || who.via !== "session" || who.session.tier !== "admin") {
2637
+ json(res, 403, { error: "admin_session_required" });
2638
+ return true;
2639
+ }
2640
+ const range = url.searchParams.get('range'), series = url.searchParams.getAll('series');
2641
+ try {
2642
+ if (method !== "GET" || url.search.length > 4096 || url.searchParams.getAll('range').length !== 1 || [...url.searchParams.keys()].some(k => k !== 'range' && k !== 'series'))
2643
+ throw Error();
2644
+ historyQuery(range, series, Date.now());
2645
+ }
2646
+ catch {
2647
+ json(res, 400, { error: "invalid_history_query" });
2648
+ return true;
2649
+ }
2650
+ if (!ctx.hostHistoryQuery) {
2651
+ json(res, 503, { error: "history_unavailable" });
2652
+ return true;
2653
+ }
2654
+ void Promise.resolve().then(() => ctx.hostHistoryQuery(range, series)).then(answer => {
2655
+ if (res.destroyed)
2656
+ return;
2657
+ const current = auth();
2658
+ if (current.kind !== "allow" || current.via !== "session" || current.session.tier !== "admin" || current.session.idHash !== who.session.idHash) {
2659
+ json(res, 403, { error: "admin_session_required" });
2660
+ return;
2661
+ }
2662
+ json(res, 200, answer);
2663
+ }, () => { if (!res.destroyed)
2664
+ json(res, 503, { error: "history_unavailable" }); });
2665
+ return true;
2666
+ }
2667
+ if (path === '/ui/host-alert-action') {
2668
+ res.setHeader('Cache-Control', 'private, no-store');
2669
+ const auth = () => evaluateWebRequest(req, url, ctx.webToken ?? null, ctx.webSessions, { touch: false });
2670
+ const who = auth();
2671
+ if (who.kind !== 'allow' || who.via !== 'session' || who.session.tier !== 'admin') {
2672
+ json(res, 403, { error: 'admin_session_required' });
2673
+ return true;
2674
+ }
2675
+ if (method !== 'POST' || url.search) {
2676
+ json(res, 400, { error: 'invalid_host_alert_action' });
2677
+ return true;
2678
+ }
2679
+ void readBoundedWebBody(req, 2048).then(async (bytes) => {
2680
+ const current = () => { const value = auth(); return value.kind === 'allow' && value.via === 'session' && value.session.tier === 'admin' && value.session.idHash === who.session.idHash; };
2681
+ if (!current())
2682
+ return json(res, 403, { error: 'admin_session_required' });
2683
+ let input;
2684
+ try {
2685
+ input = JSON.parse(bytes.toString('utf8'));
2686
+ }
2687
+ catch {
2688
+ return json(res, 400, { error: 'invalid_host_alert_action' });
2689
+ }
2690
+ if (!input || Array.isArray(input) || Object.keys(input).some(k => !['key', 'revision', 'snoozeMs'].includes(k)) || typeof input.key !== 'string' || !/^[a-zA-Z0-9:_-]{1,128}$/.test(input.key) || !Number.isSafeInteger(input.revision) || input.revision < 1 || (input.snoozeMs !== undefined && (!Number.isSafeInteger(input.snoozeMs) || input.snoozeMs < 60000 || input.snoozeMs > 86400000)))
2691
+ return json(res, 400, { error: 'invalid_host_alert_action' });
2692
+ const ok = await ctx.hostAlertAction?.(input.key, input.revision, 'web:' + who.session.idHash, input.snoozeMs);
2693
+ if (!current())
2694
+ return json(res, 403, { error: 'admin_session_required' });
2695
+ json(res, ok ? 200 : 409, { ok: !!ok, ...(!ok ? { error: 'host_alert_stale' } : {}) });
2696
+ }).catch(() => { if (!res.headersSent)
2697
+ json(res, 503, { error: 'host_alert_unavailable' }); });
2698
+ return true;
2699
+ }
2700
+ if (path === "/ui/host-health") {
2701
+ res.setHeader("Cache-Control", "private, no-store");
2702
+ const who = evaluateWebRequest(req, url, ctx.webToken ?? null, ctx.webSessions, { touch: false });
2703
+ if (who.kind !== "allow" || who.via !== "session" || who.session.tier !== "admin") {
2704
+ json(res, 403, { error: "admin_session_required" });
2705
+ return true;
2706
+ }
2707
+ if (method !== "GET" || [...url.searchParams.keys()].some(k => k !== "agentOffset") || url.searchParams.getAll("agentOffset").length > 1 || !/^(?:0|50|100)$/.test(url.searchParams.get("agentOffset") ?? "0")) {
2708
+ json(res, 400, { error: "invalid_host_health_request" });
2709
+ return true;
2710
+ }
2711
+ if (!ctx.hostHealthSnapshot) {
2712
+ json(res, 503, { error: "host_monitoring_unavailable" });
2713
+ return true;
2714
+ }
2715
+ json(res, 200, ctx.hostHealthSnapshot(Number(url.searchParams.get("agentOffset") ?? 0)));
2716
+ return true;
2717
+ }
2628
2718
  // Auth check for all /ui routes. Defence in depth behind the fleet-manager
2629
2719
  // gate: the same session cookie or header token, and an unset token closes
2630
2720
  // the panel instead of comparing null against a missing credential.
@@ -3056,7 +3146,7 @@ export function handleWebRequest(req, res, url, ctx) {
3056
3146
  streamGuests.set(res, guest);
3057
3147
  guest.streamOpened?.();
3058
3148
  }
3059
- if (!guest && ctx.contactActor)
3149
+ if (!guest)
3060
3150
  streamContactProjection.set(res, (event, value) => {
3061
3151
  if (event === "needs")
3062
3152
  return { items: contactNeedsFor(req, url, ctx, (value && typeof value === "object" && Array.isArray(value.items)) ? value.items : []) };
@@ -3176,7 +3266,7 @@ export function handleWebRequest(req, res, url, ctx) {
3176
3266
  // #2848: the chat has messages, none of them a guest's to see (all between agents, or kept before they were marked):
3177
3267
  // said, so its empty chat is explained rather than blank. Only that there are some — never how many, or what.
3178
3268
  const allHidden = !!guest && messages.length === 0 && (ctx.webChatHistory?.list(instance, 1).length ?? 0) > 0;
3179
- json(res, 200, { messages, boot: ctx.webChatHistory?.boot ?? null, lastId: ctx.webChatHistory?.lastId ?? 0, ...(allHidden ? { allHidden: true } : {}) });
3269
+ json(res, 200, { messages, resendOwner: webPersonOf(req, url, ctx)?.voterKey ?? null, boot: ctx.webChatHistory?.boot ?? null, lastId: ctx.webChatHistory?.lastId ?? 0, ...(allHidden ? { allHidden: true } : {}) });
3180
3270
  return true;
3181
3271
  }
3182
3272
  // ── M-3272: scrolling back past the 500-message window (the archive, web-chat-archive.ts) ──
@@ -3507,6 +3597,11 @@ export function handleWebRequest(req, res, url, ctx) {
3507
3597
  return true;
3508
3598
  }
3509
3599
  // ── Send message ───────────────────────────────────────
3600
+ if (method === "POST" && path === "/ui/resend") {
3601
+ void handleResendMessage(req, res, ctx).catch(() => { if (!res.destroyed && !res.headersSent)
3602
+ json(res, 503, { error: "Resend unavailable" }); });
3603
+ return true;
3604
+ }
3510
3605
  if (method === "POST" && path === "/ui/send") {
3511
3606
  handleSendMessage(req, res, ctx);
3512
3607
  return true;
@@ -5898,6 +5993,156 @@ function webSendDedupeOf(ctx) {
5898
5993
  webSendDedupes.set(ctx, d = new WebSendDedupe());
5899
5994
  return d;
5900
5995
  }
5996
+ /** Resend only retained server content, with one new attempt on the same bubble. */
5997
+ async function handleResendMessage(req, res, ctx) {
5998
+ const url = new URL(req.url ?? "/", "http://localhost"), arrival = webAuthorityOf(req, url, ctx);
5999
+ let raw;
6000
+ try {
6001
+ raw = JSON.parse((await readBoundedWebBody(req, 8192)).toString("utf8"));
6002
+ }
6003
+ catch {
6004
+ json(res, 400, { error: "Invalid resend request" });
6005
+ return;
6006
+ }
6007
+ if (!permitWebContinuation(req, res, ctx))
6008
+ return;
6009
+ const parsed = z.object({ instance: z.string().min(1).max(128), boot: z.string().regex(/^[0-9a-f]{1,32}$/),
6010
+ id: z.number().int().positive().max(Number.MAX_SAFE_INTEGER), attempt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER) }).strict().safeParse(raw);
6011
+ if (!parsed.success) {
6012
+ json(res, 400, { error: "Invalid resend request" });
6013
+ return;
6014
+ }
6015
+ const { instance, boot, id, attempt } = parsed.data, history = ctx.webChatHistory;
6016
+ const person = webPersonOf(req, url, ctx), guest = guestRequestOf(req), refused = guestChatRefusal(guest, instance);
6017
+ if (!person) {
6018
+ json(res, 401, { error: WEB_TOKEN_INVALID_MESSAGE });
6019
+ return;
6020
+ }
6021
+ if (refused) {
6022
+ json(res, refused.status, { error: refused.error });
6023
+ return;
6024
+ }
6025
+ const native = isWindowsInstance(ctx.fleetConfig?.instances[instance]);
6026
+ if (native && !nativeCliAuthorization(req, url, ctx)) {
6027
+ json(res, 403, { error: "Windows runtime requires an administrator on the local dashboard" });
6028
+ return;
6029
+ }
6030
+ const row = history?.find(instance, boot, id);
6031
+ if (!row || row.role !== "user" || row.retry?.owner !== person.voterKey || (guest && !guestSeesMessage(row, guest, guest.scope()))) {
6032
+ json(res, 404, { error: "Message is not available to resend" });
6033
+ return;
6034
+ }
6035
+ if (native && row.attachments?.length) {
6036
+ json(res, 400, { error: "Attachments are not supported by this runtime yet" });
6037
+ return;
6038
+ }
6039
+ if (guest && guestCommandText(row.text)) {
6040
+ json(res, 403, { error: "guest_no_commands" });
6041
+ return;
6042
+ }
6043
+ if (gatewayRequestContext(req) && row.text.startsWith("/raw ") && !adminAdmissionOf(req, url, ctx)) {
6044
+ json(res, 403, { error: t("web.raw_public_refused") });
6045
+ return;
6046
+ }
6047
+ const registered = registeredChatInstance(ctx, instance);
6048
+ if (!registered && !ctx.instanceIpcClients.has(instance)) {
6049
+ json(res, 404, { error: "Instance not found" });
6050
+ return;
6051
+ }
6052
+ const admission = admissionOf(req, url, ctx);
6053
+ const authorityCurrent = () => admission !== null && admissionOf(req, url, ctx) === admission
6054
+ && webPersonOf(req, url, ctx)?.voterKey === person.voterKey
6055
+ && (!guest || (guest.current() && !guestChatRefusal(guest, instance)))
6056
+ && (native ? isWindowsInstance(ctx.fleetConfig?.instances[instance]) && nativeCliAuthorization(req, url, ctx)
6057
+ : registered ? registeredChatInstance(ctx, instance) : ctx.instanceIpcClients.has(instance));
6058
+ const stillCurrent = () => !res.destroyed && authorityCurrent();
6059
+ const update = () => ctx.emitSseEvent("delivery", { instance, boot: row.boot, id: row.id, messageId: row.messageId, delivery: row.delivery, retry: row.retry });
6060
+ if (row.retry.attempt === attempt + 1 && row.delivery !== "failed") {
6061
+ json(res, 200, { sent: true, repeated: true, message: row });
6062
+ return;
6063
+ }
6064
+ if (row.delivery !== "failed" || row.retry.attempt !== attempt) {
6065
+ json(res, 409, { error: "This delivery changed; refresh and try again" });
6066
+ return;
6067
+ }
6068
+ const quoted = row.replyTo ? history.find(instance, row.replyTo.boot, row.replyTo.id) : undefined;
6069
+ if (row.replyTo && (!quoted || (guest && !guestSeesMessage(quoted, guest, guest.scope())))) {
6070
+ json(res, 409, { error: t("web.reply_gone"), reason: "reply_gone" });
6071
+ return;
6072
+ }
6073
+ const files = [];
6074
+ const limits = uploadLimits(ctx.fleetConfig?.web, { publicLink: gatewayRequestContext(req) !== undefined });
6075
+ let totalBytes = 0;
6076
+ if ((row.attachments?.length ?? 0) > limits.maxFiles) {
6077
+ json(res, 409, { error: "The attachments exceed the current file limit", reason: "attachment_gone" });
6078
+ return;
6079
+ }
6080
+ for (const attachment of row.attachments ?? []) {
6081
+ const opened = "id" in attachment ? ctx.webFiles?.open(attachment.id) : null;
6082
+ if (!opened) {
6083
+ json(res, 409, { error: "An attached file is no longer available", reason: "attachment_gone" });
6084
+ return;
6085
+ }
6086
+ try {
6087
+ if (opened.file.instance !== instance) {
6088
+ json(res, 409, { error: "An attached file is no longer available", reason: "attachment_gone" });
6089
+ return;
6090
+ }
6091
+ totalBytes += opened.file.size;
6092
+ if (opened.file.size > limits.maxFileBytes || totalBytes > limits.maxTotalBytes) {
6093
+ json(res, 409, { error: "The attachments exceed the current file limit", reason: "attachment_gone" });
6094
+ return;
6095
+ }
6096
+ files.push({ kind: opened.file.kind, name: opened.file.name, path: opened.file.realPath });
6097
+ }
6098
+ finally {
6099
+ closeSync(opened.fd);
6100
+ }
6101
+ }
6102
+ if (!stillCurrent()) {
6103
+ json(res, 403, { error: "The session or instance changed" });
6104
+ return;
6105
+ }
6106
+ const { authority } = confirmAfterBody(arrival, webAuthorityOf(req, url, ctx, instance));
6107
+ const nativeRequestId = isNativeExecInstance(ctx.fleetConfig?.instances[instance]) ? randomUUID() : undefined;
6108
+ const nativeJournalIds = nativeRequestId ? new Set((ctx.nativeInstanceRuntime?.().get(instance)?.turns ?? []).map(turn => `native:${turn.id}:user`)) : undefined;
6109
+ const messageId = nativeRequestId ? `native:${nativeRequestId}:user` : newWebMessageId(), claimed = history.beginResend(instance, boot, id, attempt, person.voterKey, messageId, nativeJournalIds);
6110
+ if (claimed.kind === "refused") {
6111
+ json(res, 409, { error: "This delivery changed; refresh and try again" });
6112
+ return;
6113
+ }
6114
+ if (claimed.kind === "already") {
6115
+ json(res, 200, { sent: true, repeated: true, message: claimed.message });
6116
+ return;
6117
+ }
6118
+ update();
6119
+ const delivery = attachmentDelivery(row.text, files);
6120
+ const adapter = ctx.getAdapterForInstance ? ctx.getAdapterForInstance(instance) : ctx.adapter;
6121
+ const payload = { type: "fleet_inbound", content: delivery.text, ...(nativeRequestId ? { requestId: nativeRequestId } : {}), targetSession: instance, meta: {
6122
+ chat_id: ctx.getGroupIdForInstance?.(instance) ?? String(ctx.fleetConfig?.channel?.group_id ?? ""),
6123
+ thread_id: String(ctx.fleetConfig?.instances[instance]?.topic_id ?? ""), message_id: messageId,
6124
+ user: person.name, user_id: person.userId, source: "web", ts: new Date().toISOString(), adapter_id: adapter?.id,
6125
+ ...(guest ? { web_guest: "1" } : {}), ...delivery.meta, ...(quoted ? { reply_to_text: webChatReplyText(quoted) } : {}),
6126
+ } };
6127
+ let handedOff = false;
6128
+ try {
6129
+ const delivered = ctx.deliverHumanToInstance ? await ctx.deliverHumanToInstance(instance, payload, webHumanOrigin(false, authority), row.text, { stillCurrent, ...(native ? { authorityCurrent } : {}) })
6130
+ : await ctx.deliverToInstance(instance, payload, { stillCurrent, ...(native ? { authorityCurrent } : {}) });
6131
+ if (delivered === false)
6132
+ throw new Error("delivery changed");
6133
+ handedOff = true;
6134
+ if (!res.destroyed)
6135
+ json(res, 200, { sent: true, message: row });
6136
+ }
6137
+ catch (error) {
6138
+ if (handedOff)
6139
+ return; // a lost HTTP answer does not make the accepted pane handoff fail
6140
+ history.setDelivery(instance, messageId, "failed");
6141
+ update();
6142
+ ctx.logger.error({ instance, err: error }, "Web resend handoff failed");
6143
+ json(res, 503, { ...webDeliveryFailure(error), message: row });
6144
+ }
6145
+ }
5901
6146
  function handleSendMessage(req, res, ctx) {
5902
6147
  const arrival = webAuthorityOf(req, new URL(req.url ?? "/", "http://localhost"), ctx); // #1939 §3: again after the body
5903
6148
  let body = "";
@@ -6166,7 +6411,7 @@ function handleSendMessage(req, res, ctx) {
6166
6411
  ctx.lastInboundUser.set(instance, person.name);
6167
6412
  ctx.eventLog?.logActivity("message", person.name, (message || `[${files.length} file(s)]`).slice(0, 200), instance);
6168
6413
  // #1920: the account that wrote it (a guest sees its own); channel-visible once its copy was sent (above).
6169
- ctx.emitSseEvent("message", { instance, sender: person.name, role: "user", text: message, ts, attachments: files.map(publicAttachment), messageId, ...(person.bound ? { from: person.voterKey } : {}),
6414
+ ctx.emitSseEvent("message", { instance, sender: person.name, role: "user", retryOwner: person.voterKey, text: message, ts, attachments: files.map(publicAttachment), messageId, ...(person.bound ? { from: person.voterKey } : {}),
6170
6415
  ...(quoted ? { replyTo: webChatReplyRef(quoted) } : {}), ...(clientId ? { clientId } : {}) });
6171
6416
  json(res, 200, { sent: true, messageId });
6172
6417
  }