Fix wave chunk 1: cross-surface settings signal, dialog scroll-lock, noneRow retired

- lh:settings-saved CustomEvent (the lh:chat-renamed pattern, owner
  ruling): every writer (composer save, SetupDialog save, the settings
  write seam — one dispatch point carrying the section) notifies after a
  successful PUT; every reader re-reads its own seam: ModelControl's
  record read, the Agent section's slots/catalog, and chat.tsx's
  configured state (clearing slots mid-session now surfaces the setup
  CTA without a reload). Self-notifications re-read idempotently.
- MenuShell now announces lh:menu-open/lh:menu-close (still placement-
  only); the settings dialog's content column locks (overflow-hidden,
  count-based) while any menu is open — wheel-scrolling with a dropdown
  down is dead; the re-place-on-scroll fallback stays for un-lockable
  surfaces.
- The settings thinking menus' 'Default' noneRow is retired (owner:
  the unset state can't re-enter once chunk 2's auto-populate lands; no
  unpin is needed).
- Live-caught regression from the MenuShell migration fixed: the
  composer's outside-click handler never learned the portaled menu body
  isn't a container descendant — menu-row pointerdowns counted as
  outside and ATE THE PICK (composer picks have been dead for pointer
  users since 221c99d); rows now carve out via [data-lh-menu], the
  settings sections' discipline.
- Item 4 (resolved-level display for legacy records) deferred to chunk 2
  per owner ruling — the payload omits the level for legacy no-level
  records and DEFAULT_THINKING_ORDER was server-only (now in the core
  barrel via bd68486, exactly the seam chunk 2 needs).
This commit is contained in:
amosblomqvist
2026-09-22 21:55:33 +03:00
parent 9387418864
commit e766a13eb1
8 changed files with 207 additions and 44 deletions
+25 -10
View File
@@ -7,6 +7,7 @@ import { prettyModel } from "@/components/usage-format";
import { ModelMenuList, ThinkingMenuList } from "@/components/settings/model-menu";
import { composeSlotModel } from "@/components/settings/agent-section";
import { MenuShell } from "@/components/menu-shell";
import { notifySettingsSaved, useSettingsSaved } from "@/components/settings-signal";
/** GET /api/models is cached per page load for instant menu opens, but
* the federation is LIVE per call — keys saved mid-session widen the
@@ -94,21 +95,28 @@ export function ModelControl() {
const [error, setError] = useState<string | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
let alive = true;
// The record read — BOTH mount and the cross-surface signal land
// here (fix wave: another surface's models write re-reads into the
// pill live; own writes also notify, and the refetch is idempotent).
const readRecord = useCallback(() => {
fetch("/api/settings")
.then((r) => r.json() as Promise<{ settings: { models?: ModelsSettings } | null }>)
.then((body) => alive && setModels(body.settings?.models ?? undefined))
.then((body) => setModels(body.settings?.models ?? undefined))
.catch(() => {
/* the record fetch failing leaves the control read-only
("—" triggers, closed menus) — same posture as a
catalog failure */
});
return () => {
alive = false;
};
}, []);
useEffect(() => {
readRecord();
}, [readRecord]);
useSettingsSaved((section) => {
if (section === "models") readRecord();
});
const override = models?.strong;
const effectiveId = override?.model?.id;
const effectiveProvider = override?.model?.provider;
@@ -119,13 +127,19 @@ export function ModelControl() {
const levels = entry?.supportedLevels ?? [];
// The intuitive dropdown contract (owner, stats-control round 1): any
// click outside the open menu — or an Esc keypress — closes it. Only the
// menu's own surface keeps it open (the toggle buttons live inside the
// same container and handle their own toggling in onClick).
// click outside the open menu — or an Esc keypress — closes it. The
// menu's own surface keeps it open: the toggle buttons live inside the
// container, and the menu BODY lives in a portal on document.body
// (MenuShell) — never a container descendant, so its rows are carved
// out via [data-lh-menu] (the settings sections' discipline; without
// it a row's pointerdown counts as outside and eats the pick —
// live-caught in the fix wave, broken since the MenuShell migration).
useEffect(() => {
if (open === null) return;
const onPointerDown = (e: PointerEvent) => {
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
const t = e.target as Element;
if (t instanceof Element && t.closest("[data-lh-menu]")) return;
if (containerRef.current && !containerRef.current.contains(t)) {
setOpen(null);
}
};
@@ -164,6 +178,7 @@ export function ModelControl() {
}
setModels(next);
setOpen(null);
notifySettingsSaved("models");
} catch {
setError("Could not reach the server — try again.");
}