@gemboss/ui 0.52.0 → 0.53.0

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.
@@ -1,42 +1,36 @@
1
1
  "use client";
2
2
 
3
3
  /**
4
- * The assistant's ENGINE PICKER — @gemboss/ui (0.25.0, Chris 07/10/2026).
4
+ * The assistant's ENGINE PICKER — @gemboss/ui (0.25.0, Chris 07/10/2026; a door to Settings since 0.52.0, only that since 0.53.0).
5
5
  *
6
6
  * One chip in the composer row: the engine's name, the model when it is not the default, and a dot for the bridge on the
7
- * user's machine (green running, amber outdated, red not connected). A click opens a panel with up to three tabs:
8
- * Engine — which engine answers, its model and its effort;
9
- * Setup — install or update the bridge: the command with a Copy button, the pairing code, a few lines of how;
10
- * Status — the bridge's state, its version against the latest, whether it starts at sign-in.
7
+ * user's machine (green running, amber outdated, red not connected). A click opens the surface's SETTINGS on its
8
+ * "AI & engines" section (`onOpenSettings`), which draws what the chip publishes (`EngineSettingsSection`,
9
+ * engine-settings.tsx): Engine (which engine answers, its model, its effort) and Bridge on your machine (what is wrong, its
10
+ * state, its actions, then Install or update: the command with Copy, the pairing code).
11
11
  *
12
- * Why it exists: content-radar's Radar Assistant spent close to half of its frame on an ENGINE / MODEL / EFFORT row, a
13
- * yellow "The bridge on your machine is outdated…" block, the install command and a "Bridge on your machine: running"
14
- * line, all above the conversation (Chris 07/10: "chèn hết vào không gian chat tốn không gian quá"). The admin already
15
- * had the shape — a chip in the composer that opens a popup to pick Claude Code (apps/admin EnginePicker) — so this is
16
- * that chip, with the setup and the status moved off the chat and into the same popup. A turn that FAILS because of the
17
- * bridge says so in one line in the stream (`BridgeNotice`), whose "Open setup" opens this panel on the Setup tab.
12
+ * Why: content-radar's Radar Assistant once spent close to half of its frame on an ENGINE / MODEL / EFFORT row and the
13
+ * bridge's install block above the conversation (Chris 07/10: "chèn hết vào không gian chat tốn không gian quá"); 0.25.0 put
14
+ * them in a 360px popup of the chip, Engine · Setup · Status tabs over the chat; 0.52.0 moved them into Settings (Chris
15
+ * 24/10: "đưa hết về nằm trong popup settings để có nhiều không gian hơn… bấm vào đó mở settings"), and 0.53.0 removed the
16
+ * popup once every surface had moved (the condition Chris set for the weight of engine-plain.js). A turn that FAILS because
17
+ * of the bridge says so in one line in the stream (`BridgeNotice`), whose "Open setup" opens Settings on Install or update.
18
18
  *
19
19
  * The package knows nothing about any bridge. The surface hands in the engines, the models, the efforts, the bridge's
20
- * status, the command and the code, and hears every change through callbacks.
21
- *
22
- * The panel is a non-modal dialog in the browser's TOP LAYER (`popover="manual"`, placed like the kit's menus by
23
- * `placeFloating`): no scrolling frame cuts it, it stays in the React tree (tokens resolve, events bubble). Escape and an
24
- * outside click close it; Escape and every close from inside it give focus back to the chip. Tabs are a roving tablist
25
- * (←/→/Home/End). Its look is `assistant-engine.css`, imported here: a surface that never draws the picker never loads it.
20
+ * status, the command and the code, and hears every change through callbacks. Its look is `assistant-engine.css`, imported
21
+ * here: a surface that never draws the picker never loads it.
26
22
  */
27
23
  import "../assistant-engine.css"; // its own entry (0.25.0): not in gemboss-ui.css, not in the assistant frame's sheet
28
- import React, { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode } from "react";
29
- import { createPortal } from "react-dom";
30
- import { canFloatMenus, placeFloating } from "../menu-layer";
24
+ import React, { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react";
31
25
  import { EngineMark, isEngineMarkId } from "./engine-mark";
32
26
  import { requestEngineSettingsFocus, usePublishEngineSettings } from "./engine-settings-store";
33
27
 
34
28
  const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
35
- const useBeforePaint = typeof window === "undefined" ? useEffect : useLayoutEffect;
36
29
 
37
30
  /** running = answers now · outdated = answers, but an update is due · offline = paired, not reachable · unpaired = never
38
31
  * set up on this account · checking = not known yet (first poll in flight). */
39
32
  export type BridgeState = "running" | "outdated" | "offline" | "unpaired" | "checking";
33
+ /** The part of Settings › AI & engines to bring into view: the top (engine), the bridge's state, its install or update. */
40
34
  export type EnginePickerTab = "engine" | "setup" | "status";
41
35
 
42
36
  export interface EngineChoice {
@@ -52,8 +46,8 @@ export interface EngineChoice {
52
46
  /** The engine's mark ("claude", "codex": `ENGINE_MARK_ART`). The chip shows it in place of the name when the composer row
53
47
  * is too narrow for the name (`ChatComposer` density "icon"); an engine without one keeps its (cut) name. 0.29.0. */
54
48
  mark?: string;
55
- /** THIS engine's models. Give them on every engine and the Engine tab lists each engine with its own models, all at
56
- * once, and one click picks the engine and the model together (`onPick`): the admin's popup. 0.29.0. */
49
+ /** THIS engine's models. Give them on every engine and the Engine card lists each engine with its own models, all at
50
+ * once, and one click picks the engine and the model together (`onPick`): the admin's shape. 0.29.0. */
57
51
  models?: readonly Choice[];
58
52
  }
59
53
 
@@ -88,35 +82,30 @@ export interface BridgeSetup {
88
82
  pairingCode?: string;
89
83
  /** A few lines of how (an <ol>, a sentence). Default: "Paste the command into Terminal, then press Enter." */
90
84
  steps?: ReactNode;
91
- /** Quiet text under the command ("The pairing code stays the same: the panel reconnects in a few seconds."). */
85
+ /** Quiet text under the command ("The pairing code stays the same: the assistant reconnects in a few seconds."). */
92
86
  note?: ReactNode;
93
87
  }
94
88
 
95
89
  /** Every word the picker says. English, like every surface's chrome (Chris 03/10/2026). */
96
90
  export interface EnginePickerLabels {
97
- chip: string; dialog: string; tabs: string;
98
- engineTab: string; setupTab: string; statusTab: string;
91
+ chip: string;
99
92
  engine: string; model: string; effort: string;
100
93
  defaultChoice: string;
101
94
  copy: string; copied: string; copyFailed: string; pairingCode: string; steps: string;
102
95
  bridge: string; version: string; latest: string; startsAtSignIn: string; machine: string; lastSeen: string;
103
96
  yes: string; no: string; unknown: string;
104
97
  running: string; outdated: string; offline: string; unpaired: string; checking: string;
105
- updateDue: string; close: string;
106
- /** In Settings (`EngineSettings`, 0.52.0): the bridge's first row, under a card already titled `bridge`, and the heading
107
- * of its install / update part. Optional so a surface's own label set from before 0.52.0 still type-checks. */
108
- state?: string; setupTitle?: string;
98
+ /** The bridge card's first row (the card is titled `bridge`) and the heading of its install / update part. */
99
+ state: string; setupTitle: string;
109
100
  }
110
101
  export const ENGINE_PICKER_EN: EnginePickerLabels = {
111
- chip: "Engine", dialog: "Assistant engine", tabs: "Engine, setup and status",
112
- engineTab: "Engine", setupTab: "Setup", statusTab: "Status",
102
+ chip: "Engine",
113
103
  engine: "Engine", model: "Model", effort: "Effort",
114
104
  defaultChoice: "Default",
115
105
  copy: "Copy command", copied: "Copied", copyFailed: "Select the command and copy it", pairingCode: "Pairing code", steps: "Paste the command into Terminal, then press Enter.",
116
106
  bridge: "Bridge on your machine", version: "Version", latest: "Latest", startsAtSignIn: "Starts at sign-in", machine: "Machine", lastSeen: "Last seen",
117
107
  yes: "Yes", no: "No", unknown: "Not known",
118
108
  running: "Running", outdated: "Outdated", offline: "Not connected", unpaired: "Not set up", checking: "Checking",
119
- updateDue: "Update available", close: "Close",
120
109
  state: "State", setupTitle: "Install or update",
121
110
  };
122
111
 
@@ -149,102 +138,63 @@ export interface EnginePickerProps {
149
138
  onEffortChange?: (id: string) => void;
150
139
  /** Effort cannot be set right now; a string says why (its tooltip). */
151
140
  effortDisabled?: boolean | string;
152
- /** Quiet lines under the Engine tab's fields: who pays, what this bridge version cannot do yet. */
141
+ /** Quiet lines under the Engine card's fields: who pays, what this bridge version cannot do yet. */
153
142
  notes?: ReactNode;
154
- /** With models per engine (`EngineChoice.models`): one click on a model picks both, and closes the panel. Without it the
155
- * picker calls `onEngineChange` (when the engine changes) then `onModelChange`. 0.29.0. */
143
+ /** With models per engine (`EngineChoice.models`): one click on a model picks both. Without it the picker calls
144
+ * `onEngineChange` (when the engine changes) then `onModelChange`. 0.29.0. */
156
145
  onPick?: (engine: string, model: string) => void;
157
- /** A switch that did not go through ("Wait for the current answer to finish"): one red line on the Engine tab. 0.29.0. */
146
+ /** A switch that did not go through ("Wait for the current answer to finish"): one red line on the Engine card. 0.29.0. */
158
147
  problem?: ReactNode;
159
148
  /** The chip itself is disabled (a switch in flight). `locked` keeps the chip and disables the choices. 0.29.0. */
160
149
  disabled?: boolean;
161
- /** The bridge on the user's machine. Omit for an engine set that runs on the server only: no dot, no Status tab. */
150
+ /** The bridge on the user's machine. Omit for an engine set that runs on the server only: no dot, no bridge card. */
162
151
  bridge?: BridgeStatus;
163
152
  /** The dot on the chip (default true when `bridge` is given). False when the current engine does not go through the
164
153
  * bridge (a server engine): a red dot would say "broken" about something this engine does not use. */
165
154
  showBridgeDot?: boolean;
166
- /** Omit and there is no Setup tab. */
155
+ /** Omit and the bridge card has no Install or update part. */
167
156
  setup?: BridgeSetup;
168
157
  /** Buttons under the status rows ("Forget this machine", "Restart"). */
169
158
  statusActions?: ReactNode;
170
- /** Controlled open state and tab (a `BridgeNotice` opens Setup through these: see `useEnginePicker`). */
171
- open?: boolean;
159
+ /** Called with true while Settings › AI & engines is SEEN, false when it goes: a surface polls its bridge on it. */
172
160
  onOpenChange?: (open: boolean) => void;
173
- tab?: EnginePickerTab;
174
- onTabChange?: (tab: EnginePickerTab) => void;
175
161
  /** While a turn runs the surface may refuse a switch: the chip stays readable, the choices are disabled. */
176
162
  locked?: boolean;
177
- /** Align the panel's right edge with the chip's (a chip near the right edge of a narrow frame). */
178
- end?: boolean;
179
- /** The chip button, for the surface (`useEnginePicker` passes its own: `close()` puts focus back on it). 0.32.0. */
163
+ /** The chip button, for the surface. 0.32.0. */
180
164
  chipRef?: React.Ref<HTMLButtonElement>;
181
- /** 0.52.0: the chip opens the surface's SETTINGS on its "AI & engines" section, which draws everything the panel held
182
- * (`EngineSettingsSection`), and there is no panel of its own. Called with "engine" from the chip, with "setup" from
183
- * `useEnginePicker().openTab("setup")` (a failed turn's Open setup). While that section is on screen, `onOpenChange(true)`:
184
- * a surface that polls the bridge while the picker is open keeps doing so. See engine-settings.tsx. */
185
- onOpenSettings?: (tab: EnginePickerTab) => void;
165
+ /** The chip opens the surface's SETTINGS on its "AI & engines" section (0.52.0; the only way since 0.53.0, which removed
166
+ * the chip's own popup). Called with "engine" from the chip, with "setup" from `useEnginePicker().openTab("setup")` (a
167
+ * failed turn's Open setup). See engine-settings.tsx. */
168
+ onOpenSettings: (tab: EnginePickerTab) => void;
186
169
  labels?: Partial<EnginePickerLabels>;
187
170
  className?: string;
188
171
  }
189
172
 
190
- /** The open state and tab of one picker, for a surface that also renders a `BridgeNotice`:
191
- * `const p = useEnginePicker(); <EnginePicker {...p.props} …/> <BridgeNotice onOpenSetup={() => p.openTab("setup")} …/>`
192
- *
193
- * `close()` (0.32.0) is the surface's close: a button inside the panel that acts and then shuts it (Stop bridge, Remove
194
- * from this machine, before a confirm opens). The button that had focus goes away with the panel, so focus would fall to
195
- * <body> and the confirm would record <body> as where to return; `close()` puts it on the chip first. Every surface
196
- * wrote that by hand (`querySelector(".gb-engine-chip").focus()`: partner-radar, search-radar, gemwatcher #922). An
197
- * outside click still closes without moving focus (`props.onOpenChange(false)`).
173
+ /** One picker's door and its "on screen" state, for a surface that also renders a `BridgeNotice`:
174
+ * `const p = useEnginePicker({ onOpenSettings: () => openSettings("ai") });`
175
+ * `<EnginePicker {...p.props} …/> <BridgeNotice onOpenSetup={() => p.openTab("setup")} …/>`
198
176
  *
199
- * 0.52.0, `{ onOpenSettings }`: the engine lives in the surface's Settings (see `EnginePickerProps.onOpenSettings`).
200
- * `openTab("setup")` then opens Settings on that section and brings its install / update part into view; `open` is true
201
- * while the section is on screen; `close()` does nothing (there is no panel, and the chip sits behind the Settings popup:
202
- * focus stays on the button in Settings, where a confirm it opens comes back to). */
203
- export function useEnginePicker(options: EnginePickerTab | { initial?: EnginePickerTab; onOpenSettings?: (tab: EnginePickerTab) => void } = "engine") {
204
- const initial = typeof options === "string" ? options : options.initial ?? "engine";
205
- const toSettings = typeof options === "string" ? undefined : options.onOpenSettings;
177
+ * `openTab("setup")` opens Settings with Install or update in view; `open` is true while Settings › AI & engines is SEEN
178
+ * (what a surface polls its bridge on); `close()` does nothing and stays for the surfaces that called it before a confirm
179
+ * (0.32.0, when the chip had a popup): the button is in Settings now, and focus stays on it. */
180
+ export function useEnginePicker(options: { onOpenSettings: (tab: EnginePickerTab) => void }) {
206
181
  // The latest opener (a surface passes a new arrow each render), behind one stable function.
207
- const toSettingsRef = useRef(toSettings);
208
- toSettingsRef.current = toSettings;
209
- const inSettings = Boolean(toSettings);
182
+ const toSettingsRef = useRef(options.onOpenSettings);
183
+ toSettingsRef.current = options.onOpenSettings;
210
184
  const [open, setOpen] = useState(false);
211
- const [tab, setTab] = useState<EnginePickerTab>(initial);
212
185
  const chipRef = useRef<HTMLButtonElement | null>(null);
213
- const openSettings = useCallback((t: EnginePickerTab) => {
186
+ const openTab = useCallback((t: EnginePickerTab) => {
214
187
  requestEngineSettingsFocus(t);
215
- toSettingsRef.current?.(t);
188
+ toSettingsRef.current(t);
216
189
  }, []);
217
- const openTab = useCallback((t: EnginePickerTab) => {
218
- if (toSettingsRef.current) { openSettings(t); return; }
219
- setTab(t); setOpen(true);
220
- }, [openSettings]);
221
- // Closing goes back to Engine: after "Open setup" the next click on the chip is about the engine again (review #3885).
222
- const onOpenChange = useCallback((v: boolean) => { setOpen(v); if (!v) setTab(initial); }, [initial]);
190
+ /** @deprecated 0.53.0: does nothing (the chip has no popup to close); kept so a Stop / Remove handler from 0.32.0 still runs. */
191
+ const close = useCallback(() => {}, []);
223
192
  const focusChip = useCallback(() => { chipRef.current?.focus(); }, []);
224
- const close = useCallback(() => { if (toSettingsRef.current) return; onOpenChange(false); focusChip(); }, [onOpenChange, focusChip]);
225
- return {
226
- open, tab, setOpen, setTab, openTab, close, focusChip, chipRef,
227
- props: { open, onOpenChange, tab, onTabChange: setTab, chipRef, onOpenSettings: inSettings ? openSettings : undefined },
228
- };
229
- }
230
-
231
- function availableTabs(p: Pick<EnginePickerProps, "bridge" | "setup">): EnginePickerTab[] {
232
- return ["engine", ...(p.setup ? ["setup" as const] : []), ...(p.bridge ? ["status" as const] : [])];
193
+ return { open, openTab, close, focusChip, chipRef, props: { onOpenChange: setOpen, chipRef, onOpenSettings: openTab } };
233
194
  }
234
195
 
235
- /** The tab shown (controlled by `tab` or held here) among the tabs the props offer; one copy for the picker and the panel. */
236
- function useTabs(p: Pick<EnginePickerProps, "bridge" | "setup" | "tab" | "onTabChange">) {
237
- const tabs = availableTabs(p);
238
- const [own, setOwn] = useState<EnginePickerTab>("engine");
239
- const wanted = p.tab ?? own;
240
- const tab = tabs.includes(wanted) ? wanted : "engine";
241
- const { tab: controlled, onTabChange } = p;
242
- const setTab = useCallback((t: EnginePickerTab) => {
243
- if (controlled === undefined) setOwn(t);
244
- onTabChange?.(t);
245
- }, [controlled, onTabChange]);
246
- return { tabs, tab, setTab, resetOwn: () => setOwn("engine") };
247
- }
196
+ /** What the Settings section's cards take: the chip's props without its door (`onOpenSettings`), which they never call. */
197
+ export type EngineCardProps = Omit<EnginePickerProps, "onOpenSettings"> & { onOpenSettings?: EnginePickerProps["onOpenSettings"] };
248
198
 
249
199
  /** What the chip says out loud: the engine, the model, and the bridge when it is not fine. */
250
200
  export function engineChipName(p: Pick<EnginePickerProps, "engines" | "engine" | "models" | "model" | "bridge">, L: EnginePickerLabels = ENGINE_PICKER_EN): string {
@@ -256,267 +206,35 @@ export function engineChipName(p: Pick<EnginePickerProps, "engines" | "engine" |
256
206
  }
257
207
 
258
208
  export function EnginePicker(props: EnginePickerProps) {
259
- const { engines, engine, models, model, bridge, end = false, className } = props;
209
+ const { engines, engine, models, model, bridge, className, onOpenSettings } = props;
260
210
  const L = { ...ENGINE_PICKER_EN, ...props.labels };
261
- const toSettings = props.onOpenSettings;
262
- // In Settings (0.52.0) the chip hands its props to the "AI & engines" section and hears when that section is on screen.
263
- usePublishEngineSettings(toSettings ? props : null);
264
- const [ownOpen, setOwnOpen] = useState(false);
265
- // No panel in Settings: `open` there means "the section is on screen" (useEnginePicker), not a popup to draw.
266
- const open = toSettings ? false : props.open ?? ownOpen;
267
- const { tabs, tab, setTab, resetOwn } = useTabs(props);
268
- // Without the popover API (Safari < 17) a fixed layer inside the assistant's frame is cut by it (overflow, and in the
269
- // popup and mini modes the frame's backdrop-filter makes it the containing block; full and side have none since
270
- // 21/10/2026): there the panel goes to <body> through a portal instead.
271
- // Decided after mount, so the server and the first client render agree.
272
- const [portal, setPortal] = useState(false);
273
- useEffect(() => { setPortal(!canFloatMenus()); }, []);
274
- const chipRef = useRef<HTMLButtonElement | null>(null);
275
- const outerChipRef = props.chipRef;
276
- const setChip = useCallback((el: HTMLButtonElement | null) => {
277
- chipRef.current = el;
278
- if (typeof outerChipRef === "function") outerChipRef(el);
279
- else if (outerChipRef) (outerChipRef as { current: HTMLButtonElement | null }).current = el;
280
- }, [outerChipRef]);
281
- const panelRef = useRef<HTMLDivElement>(null);
282
- const panelId = useId();
283
-
284
- const setOpen = useCallback((v: boolean) => {
285
- if (props.open === undefined) setOwnOpen(v);
286
- if (!v) resetOwn();
287
- props.onOpenChange?.(v);
288
- // eslint-disable-next-line react-hooks/exhaustive-deps
289
- }, [props.open, props.onOpenChange]);
290
- /** Close and put focus back on the chip: Escape, a pick, the close button. An outside click closes without it (the
291
- * click already moved focus where the user wanted it). */
292
- const closeToChip = useCallback(() => { setOpen(false); chipRef.current?.focus(); }, [setOpen]);
293
-
294
- // Float / sink with `open`, before paint, so the panel is never drawn unplaced.
295
- useBeforePaint(() => {
296
- const panel = panelRef.current, chip = chipRef.current;
297
- if (!panel || !chip) return;
298
- if (!open) {
299
- if (canFloatMenus() && panel.matches(":popover-open")) panel.hidePopover();
300
- return;
301
- }
302
- if (canFloatMenus() && !panel.matches(":popover-open")) panel.showPopover();
303
- placeFloating(panel, chip, end);
304
- }, [open, end, tab]);
305
-
306
- // While open: Escape, outside pointer, and keep it against the chip when the window or a frame around the chip moves.
307
- useEffect(() => {
308
- if (!open) return undefined;
309
- const panel = panelRef.current, chip = chipRef.current;
310
- if (!panel || !chip) return undefined;
311
- // Escape with focus in the panel or on the chip closes the panel only: captured first and stopped, so the surface's
312
- // own Escape (hide the assistant) does not fire on the same key. With focus elsewhere (the composer), it closes the
313
- // panel and leaves focus alone, and marks the key handled (0.27.0): a surface whose "Escape hides the assistant"
314
- // checks `defaultPrevented` waits for the next Escape. Before 0.27.0 the key went on unmarked, and React re-renders
315
- // between this listener and the surface's, so every surface (gemlabs #922, gemfeedback #66) needed a window-capture
316
- // marker to tell "this Escape closed the picker" from "this one is mine".
317
- const onKey = (e: KeyboardEvent) => {
318
- if (e.key !== "Escape" || e.defaultPrevented) return;
319
- // Not ours: an IME composition (Escape cancels it; the kit's rule, kit-plain.js), or a modal opened from the panel.
320
- if (e.isComposing || e.keyCode === 229) return;
321
- const a = document.activeElement;
322
- const modal = a?.closest?.('dialog[open], [aria-modal="true"]');
323
- if (modal && !panel.contains(modal)) return;
324
- e.preventDefault();
325
- if (a && (panel.contains(a) || chip.contains(a))) { e.stopPropagation(); closeToChip(); }
326
- else setOpen(false);
327
- };
328
- const onDown = (e: PointerEvent) => {
329
- const t = e.target as Node;
330
- if (!panel.contains(t) && !chip.contains(t)) setOpen(false);
331
- };
332
- // A modal opened from the panel (a confirm behind a Status action) takes the screen: the panel would stay above it in
333
- // the top layer, over its buttons (review #3903). Close the panel when focus enters a modal that is not the panel.
334
- const onFocusIn = (e: FocusEvent) => {
335
- const m = (e.target as Element | null)?.closest?.('dialog[open], [aria-modal="true"]');
336
- if (m && !panel.contains(m)) setOpen(false);
337
- };
338
- const replace = () => placeFloating(panel, chip, end);
339
- // A scroll moves the panel's anchor only when it scrolls something that holds the chip (the page, a frame around the
340
- // composer): a chat log streaming beside it does not. One placement per frame at most.
341
- let frame = 0;
342
- const onScroll = (e: Event) => {
343
- const t = e.target as Node | null;
344
- if (!t || panel.contains(t)) return;
345
- if (t !== document && (t as Node).nodeType !== 9 && !t.contains(chip)) return;
346
- if (!frame) frame = requestAnimationFrame(() => { frame = 0; replace(); });
347
- };
348
- // Its content changes while open (a poll turns "Allow connection" into the command): re-place on its own resize, or a
349
- // taller panel runs off the bottom of the screen. placeFloating writes max-height, which the observer ignores (it
350
- // only fires when the box changes size, and a clamp to the same room settles at once).
351
- let lastH = -1;
352
- const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
353
- if (panel.scrollHeight === lastH) return;
354
- lastH = panel.scrollHeight;
355
- replace();
356
- });
357
- // The panel (it grows while it fits) and its pane (content that grows past a clamped panel).
358
- ro?.observe(panel);
359
- const pane = panel.querySelector(".gb-engine-pane");
360
- if (pane) ro?.observe(pane);
361
- document.addEventListener("keydown", onKey, true);
362
- document.addEventListener("pointerdown", onDown, true);
363
- document.addEventListener("focusin", onFocusIn, true);
364
- document.addEventListener("scroll", onScroll, true);
365
- window.addEventListener("resize", replace);
366
- return () => {
367
- document.removeEventListener("keydown", onKey, true);
368
- cancelAnimationFrame(frame);
369
- document.removeEventListener("pointerdown", onDown, true);
370
- document.removeEventListener("focusin", onFocusIn, true);
371
- document.removeEventListener("scroll", onScroll, true);
372
- window.removeEventListener("resize", replace);
373
- ro?.disconnect();
374
- };
375
- }, [open, end, closeToChip, setOpen]);
376
-
377
- // Focus goes INTO the panel on open (the selected tab), so a keyboard user lands where the choices are.
378
- useEffect(() => {
379
- if (!open) return;
380
- const t = panelRef.current?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
381
- ?? panelRef.current?.querySelector<HTMLElement>("button:not([disabled])");
382
- t?.focus();
383
- // Only on opening: a tab change moves focus by itself (the roving keys), a pick closes.
384
- // eslint-disable-next-line react-hooks/exhaustive-deps
385
- }, [open]);
386
-
211
+ // The chip hands its props to the "AI & engines" section and hears when that section is on screen (engine-settings-store).
212
+ usePublishEngineSettings(props);
387
213
  const current = engines.find((e) => e.id === engine);
388
214
  const modelLabel = model ? (current?.models ?? models)?.find((m) => m.id === model)?.label : undefined;
389
215
  const mark = current?.mark && isEngineMarkId(current.mark) ? current.mark : null;
390
216
  const tone = bridge && props.showBridgeDot !== false ? BRIDGE_TONE[bridge.state] : null;
391
217
  const name = engineChipName(props.showBridgeDot === false ? { ...props, bridge: undefined } : props, L);
392
- const chipFace = (
393
- <>
394
- {tone ? <span className={DOT_CLASS[tone]} aria-hidden /> : null}
395
- <span className="gb-engine-chiplabel">
396
- {current?.label ?? engine}
397
- {modelLabel ? <span className="gb-engine-chipsub"> · {modelLabel}</span> : null}
398
- </span>
399
- {/* Shown instead of the name when the composer is too narrow for it (assistant-engine.css, ChatComposer density). */}
400
- {mark ? <span className="gb-engine-chipmark"><EngineMark engine={mark} decorative /></span> : null}
401
- </>
402
- );
403
-
404
- if (toSettings) {
405
- // The same chip, a door to Settings: it opens a dialog (the surface's), so no expanded state or panel id of its own.
406
- return (
407
- <span className={cx("gb-engine", className)}>
408
- <button ref={setChip} type="button" className={mark ? "gb-engine-chip has-mark" : "gb-engine-chip"}
409
- disabled={props.disabled || undefined} aria-haspopup="dialog" aria-label={name} title={name}
410
- onClick={() => { requestEngineSettingsFocus("engine"); toSettings("engine"); }}>
411
- {chipFace}
412
- </button>
413
- </span>
414
- );
415
- }
416
-
218
+ // A door to the surface's Settings: it opens a dialog (the surface's), so no expanded state or panel id of its own.
417
219
  return (
418
220
  <span className={cx("gb-engine", className)}>
419
- <button
420
- ref={setChip}
421
- type="button"
422
- className={mark ? "gb-engine-chip has-mark" : "gb-engine-chip"}
423
- disabled={props.disabled || undefined}
424
- aria-haspopup="dialog"
425
- aria-expanded={open}
426
- aria-controls={panelId}
427
- aria-label={name}
428
- title={name}
429
- onClick={() => setOpen(!open)}
430
- >
431
- {chipFace}
221
+ <button ref={props.chipRef} type="button" className={mark ? "gb-engine-chip has-mark" : "gb-engine-chip"}
222
+ disabled={props.disabled || undefined} aria-haspopup="dialog" aria-label={name} title={name}
223
+ onClick={() => onOpenSettings("engine")}>
224
+ {tone ? <span className={DOT_CLASS[tone]} aria-hidden /> : null}
225
+ <span className="gb-engine-chiplabel">
226
+ {current?.label ?? engine}
227
+ {modelLabel ? <span className="gb-engine-chipsub"> · {modelLabel}</span> : null}
228
+ </span>
229
+ {/* Shown instead of the name when the composer is too narrow for it (assistant-engine.css, ChatComposer density). */}
230
+ {mark ? <span className="gb-engine-chipmark"><EngineMark engine={mark} decorative /></span> : null}
432
231
  </button>
433
- {(() => { const panelEl = (<div
434
- ref={panelRef}
435
- id={panelId}
436
- className="gb-engine-panel gemboss-popover-surface"
437
- role="dialog"
438
- aria-label={L.dialog}
439
- // The top layer where the browser has one; otherwise a fixed layer in the tree (assistant-engine.css).
440
- {...(portal ? {} : { popover: "manual" })}
441
- hidden={!open}
442
- data-open={open ? "" : undefined}
443
- >
444
- {open ? <PanelBody {...props} L={L} tab={tab} tabs={tabs} setTab={setTab} onPicked={closeToChip} /> : null}
445
- </div>);
446
- return portal && typeof document !== "undefined" ? createPortal(panelEl, document.body) : panelEl; })()}
447
232
  </span>
448
233
  );
449
234
  }
450
235
 
451
- /** The panel's content, also exported on its own (`EnginePanel`) for the catalog and for a settings page that shows it
452
- * in place, without a chip. */
453
- function PanelBody({ L, tab, tabs, setTab, onPicked, ...p }: EnginePickerProps & {
454
- L: EnginePickerLabels; tab: EnginePickerTab; tabs: EnginePickerTab[]; setTab: (t: EnginePickerTab) => void; onPicked?: () => void;
455
- }) {
456
- const base = useId();
457
- const tabRefs = useRef<Partial<Record<EnginePickerTab, HTMLButtonElement | null>>>({});
458
- const tabLabel: Record<EnginePickerTab, string> = { engine: L.engineTab, setup: L.setupTab, status: L.statusTab };
459
- const needsUpdate = p.bridge?.state === "outdated";
460
- const onTabKey = (e: React.KeyboardEvent) => {
461
- const i = tabs.indexOf(tab);
462
- const to = e.key === "ArrowRight" ? tabs[(i + 1) % tabs.length]
463
- : e.key === "ArrowLeft" ? tabs[(i - 1 + tabs.length) % tabs.length]
464
- : e.key === "Home" ? tabs[0] : e.key === "End" ? tabs[tabs.length - 1] : null;
465
- if (!to) return;
466
- e.preventDefault();
467
- setTab(to);
468
- tabRefs.current[to]?.focus();
469
- };
470
- return (
471
- <>
472
- {tabs.length > 1 ? (
473
- <div className="ui-tabs gb-engine-tabs" role="tablist" aria-label={L.tabs} onKeyDown={onTabKey}>
474
- {tabs.map((t) => (
475
- <button
476
- key={t}
477
- ref={(el) => { tabRefs.current[t] = el; }}
478
- type="button"
479
- role="tab"
480
- id={`${base}-tab-${t}`}
481
- aria-controls={`${base}-pane-${t}`}
482
- aria-selected={tab === t}
483
- tabIndex={tab === t ? 0 : -1}
484
- onClick={() => setTab(t)}
485
- >
486
- {tabLabel[t]}
487
- {/* The same warning the chip's dot gives, on the tab that fixes it. */}
488
- {t === "setup" && needsUpdate ? <span className="gb-engine-dot gb-engine-dot--warn" role="img" aria-label={L.updateDue} /> : null}
489
- </button>
490
- ))}
491
- </div>
492
- ) : null}
493
- <div
494
- className="gb-engine-pane"
495
- role={tabs.length > 1 ? "tabpanel" : undefined}
496
- id={`${base}-pane-${tab}`}
497
- aria-labelledby={tabs.length > 1 ? `${base}-tab-${tab}` : undefined}
498
- >
499
- {tab === "engine" ? <EngineTab {...p} L={L} onPicked={onPicked} /> : null}
500
- {tab === "setup" ? <SetupTab setup={p.setup!} bridge={p.bridge} L={L} /> : null}
501
- {tab === "status" ? <StatusTab bridge={p.bridge!} actions={p.statusActions} L={L} /> : null}
502
- </div>
503
- </>
504
- );
505
- }
506
-
507
- /** The panel without the chip: the catalog, or a settings page that shows the same three tabs in place. */
508
- export function EnginePanel(props: EnginePickerProps) {
509
- const L = { ...ENGINE_PICKER_EN, ...props.labels };
510
- const { tabs, tab, setTab } = useTabs(props);
511
- return (
512
- <div className={cx("gb-engine-panel gb-engine-panel--inline gemboss-popover-surface", props.className)} role="group" aria-label={L.dialog}>
513
- <PanelBody {...props} L={L} tab={tab} tabs={tabs} setTab={setTab} />
514
- </div>
515
- );
516
- }
517
-
518
- function Options({ label, items, value, onChange, locked, onPicked, disabledReason }: {
519
- label: string; items: readonly Choice[]; value: string | undefined; onChange?: (id: string) => void; locked?: boolean; onPicked?: () => void;
236
+ function Options({ label, items, value, onChange, locked, disabledReason }: {
237
+ label: string; items: readonly Choice[]; value: string | undefined; onChange?: (id: string) => void; locked?: boolean;
520
238
  disabledReason?: boolean | string;
521
239
  }) {
522
240
  const id = useId();
@@ -552,7 +270,7 @@ function Options({ label, items, value, onChange, locked, onPicked, disabledReas
552
270
  aria-pressed={(value ?? "") === m.id}
553
271
  disabled={off}
554
272
  title={why ?? m.title}
555
- onClick={() => { if ((value ?? "") !== m.id) onChange?.(m.id); onPicked?.(); }}
273
+ onClick={() => { if ((value ?? "") !== m.id) onChange?.(m.id); }}
556
274
  >
557
275
  {m.label}
558
276
  </button>
@@ -562,22 +280,18 @@ function Options({ label, items, value, onChange, locked, onPicked, disabledReas
562
280
  );
563
281
  }
564
282
 
565
- /** Every engine with its own models, all at once; one click picks both (the admin's popup, 0.29.0). */
566
- function EngineGroups({ engines, engine, model, onPick, onEngineChange, onModelChange, locked, L, onPicked, labelledBy }: EnginePickerProps & { L: EnginePickerLabels; onPicked?: () => void; labelledBy?: string }) {
567
- const ownId = useId();
568
- const id = labelledBy ?? ownId;
283
+ /** Every engine with its own models, all at once; one click picks both (the admin's shape, 0.29.0). */
284
+ function EngineGroups({ engines, engine, model, onPick, onEngineChange, onModelChange, locked, L, labelledBy }: EngineCardProps & { L: EnginePickerLabels; labelledBy: string }) {
569
285
  const choose = (e: EngineChoice, m: Choice) => {
570
- // The pick already in force: close, change nothing (a surface that starts a new conversation on a switch must not).
571
- if (e.id === engine && (model ?? "") === m.id) { onPicked?.(); return; }
286
+ // The pick already in force: change nothing (a surface that starts a new conversation on a switch must not).
287
+ if (e.id === engine && (model ?? "") === m.id) return;
572
288
  if (onPick) onPick(e.id, m.id);
573
289
  else { if (e.id !== engine) onEngineChange?.(e.id); onModelChange?.(m.id); }
574
- onPicked?.();
575
290
  };
576
291
  const canChoose = Boolean(onPick || onEngineChange || onModelChange);
577
292
  return (
578
293
  <div className="gb-engine-field">
579
- {labelledBy ? null : <span className="gb-engine-label" id={id}>{L.engine}</span>}
580
- <div className="gb-engine-groups" role="group" aria-labelledby={id}>
294
+ <div className="gb-engine-groups" role="group" aria-labelledby={labelledBy}>
581
295
  {engines.map((e) => {
582
296
  const chosen = e.id === engine;
583
297
  const items = e.models && e.models.length ? e.models : [{ id: "", label: L.defaultChoice }];
@@ -606,17 +320,15 @@ function EngineGroups({ engines, engine, model, onPick, onEngineChange, onModelC
606
320
  );
607
321
  }
608
322
 
609
- /** The Engine tab's content. `labelledBy` (0.52.0, Settings): a heading outside names the engine list, so its own "Engine"
610
- * label is not drawn a second time under it. */
611
- export function EngineTab(props: EnginePickerProps & { L: EnginePickerLabels; onPicked?: () => void; labelledBy?: string }) {
612
- const { engines, engine, onEngineChange, models, model, onModelChange, modelControl, efforts, effort, onEffortChange, effortDisabled, notes, locked, L, onPicked, labelledBy } = props;
613
- const ownId = useId();
614
- const id = labelledBy ?? ownId;
323
+ /** The Engine card's content. `labelledBy`: the card's heading names the engine list, so its own "Engine" label is not
324
+ * drawn a second time under it. */
325
+ export function EngineTab(props: EngineCardProps & { L: EnginePickerLabels; labelledBy: string }) {
326
+ const { engines, engine, onEngineChange, models, model, onModelChange, modelControl, efforts, effort, onEffortChange, effortDisabled, notes, locked, L, labelledBy } = props;
615
327
  if (engines.some((e) => e.models && e.models.length)) {
616
328
  return (
617
329
  <>
618
330
  <EngineGroups {...props} />
619
- {efforts && efforts.length ? <Options label={L.effort} items={efforts} value={effort} onChange={onEffortChange} locked={locked} onPicked={onPicked} disabledReason={effortDisabled} /> : null}
331
+ {efforts && efforts.length ? <Options label={L.effort} items={efforts} value={effort} onChange={onEffortChange} locked={locked} disabledReason={effortDisabled} /> : null}
620
332
  {props.problem ? <p className="gb-engine-problem" role="alert">{props.problem}</p> : null}
621
333
  {notes ? <div className="gb-engine-notes">{notes}</div> : null}
622
334
  </>
@@ -639,8 +351,7 @@ export function EngineTab(props: EnginePickerProps & { L: EnginePickerLabels; on
639
351
  return (
640
352
  <>
641
353
  <div className="gb-engine-field">
642
- {labelledBy ? null : <span className="gb-engine-label" id={id}>{L.engine}</span>}
643
- <div className="gb-engine-list" role="radiogroup" aria-labelledby={id} onKeyDown={onKey}>
354
+ <div className="gb-engine-list" role="radiogroup" aria-labelledby={labelledBy} onKeyDown={onKey}>
644
355
  {engines.map((e) => (
645
356
  <button
646
357
  key={e.id}
@@ -651,7 +362,6 @@ export function EngineTab(props: EnginePickerProps & { L: EnginePickerLabels; on
651
362
  tabIndex={e.id === stop ? 0 : -1}
652
363
  className="gb-engine-row"
653
364
  disabled={!can(e)}
654
- // A new engine keeps the panel open: its models and efforts are the next thing to look at.
655
365
  onClick={() => { if (e.id !== engine) onEngineChange?.(e.id); }}
656
366
  >
657
367
  <span className="gb-engine-rowhead">
@@ -665,8 +375,8 @@ export function EngineTab(props: EnginePickerProps & { L: EnginePickerLabels; on
665
375
  </div>
666
376
  {modelControl ? (
667
377
  <div className="gb-engine-field"><span className="gb-engine-label">{L.model}</span>{modelControl}</div>
668
- ) : models && models.length ? <Options label={L.model} items={models} value={model} onChange={onModelChange} locked={locked} onPicked={onPicked} /> : null}
669
- {efforts && efforts.length ? <Options label={L.effort} items={efforts} value={effort} onChange={onEffortChange} locked={locked} onPicked={onPicked} disabledReason={effortDisabled} /> : null}
378
+ ) : models && models.length ? <Options label={L.model} items={models} value={model} onChange={onModelChange} locked={locked} /> : null}
379
+ {efforts && efforts.length ? <Options label={L.effort} items={efforts} value={effort} onChange={onEffortChange} locked={locked} disabledReason={effortDisabled} /> : null}
670
380
  {props.problem ? <p className="gb-engine-problem" role="alert">{props.problem}</p> : null}
671
381
  {notes ? <div className="gb-engine-notes">{notes}</div> : null}
672
382
  </>
@@ -692,7 +402,7 @@ export async function copyText(text: string): Promise<boolean> {
692
402
  } catch { return false; }
693
403
  }
694
404
 
695
- /** What is wrong with the bridge, in one callout: on Setup, and at the top of the bridge card in Settings. */
405
+ /** What is wrong with the bridge, in one callout at the top of the bridge card. */
696
406
  export function BridgeCallout({ bridge, L }: { bridge?: BridgeStatus; L: EnginePickerLabels }) {
697
407
  if (!(bridge?.state === "outdated" || bridge?.state === "offline" || bridge?.state === "unpaired")) return null;
698
408
  return (
@@ -703,8 +413,9 @@ export function BridgeCallout({ bridge, L }: { bridge?: BridgeStatus; L: EngineP
703
413
  );
704
414
  }
705
415
 
706
- /** The Setup tab's content. `noCallout` (Settings): the bridge card already says what is wrong above it. */
707
- export function SetupTab({ setup, bridge, L, noCallout = false }: { setup: BridgeSetup; bridge?: BridgeStatus; L: EnginePickerLabels; noCallout?: boolean }) {
416
+ /** The bridge card's Install or update part: the steps, the command with Copy, the pairing code. (What is wrong is the
417
+ * card's callout, above it.) */
418
+ export function SetupTab({ setup, L }: { setup: BridgeSetup; L: EnginePickerLabels }) {
708
419
  const [said, setSaid] = useState<"" | "copied" | "failed">("");
709
420
  const timer = useRef<number | undefined>(undefined);
710
421
  useEffect(() => () => window.clearTimeout(timer.current), []);
@@ -717,7 +428,6 @@ export function SetupTab({ setup, bridge, L, noCallout = false }: { setup: Bridg
717
428
  };
718
429
  return (
719
430
  <>
720
- {noCallout ? null : <BridgeCallout bridge={bridge} L={L} />}
721
431
  {setup.steps || setup.command ?<div className="gb-engine-steps">{setup.steps ?? <p>{L.steps}</p>}</div> : null}
722
432
  {setup.command ? (
723
433
  <>
@@ -738,16 +448,16 @@ export function SetupTab({ setup, bridge, L, noCallout = false }: { setup: Bridg
738
448
  );
739
449
  }
740
450
 
741
- /** The Status tab's content. `inSettings`: the card is titled with the bridge, so the first row says "State", and the
451
+ /** The bridge card's state rows and actions. The card is titled with the bridge, so the first row says "State", and the
742
452
  * callout above it already carries `detail`. */
743
- export function StatusTab({ bridge, actions, L, inSettings = false }: { bridge: BridgeStatus; actions?: ReactNode; L: EnginePickerLabels; inSettings?: boolean }) {
453
+ export function StatusTab({ bridge, actions, L }: { bridge: BridgeStatus; actions?: ReactNode; L: EnginePickerLabels }) {
744
454
  const tone = BRIDGE_TONE[bridge.state];
745
455
  const yesNo = (v: boolean | undefined) => (v === undefined ? L.unknown : v ? L.yes : L.no);
746
- const calledOut = inSettings && (bridge.state === "outdated" || bridge.state === "offline" || bridge.state === "unpaired");
456
+ const calledOut = bridge.state === "outdated" || bridge.state === "offline" || bridge.state === "unpaired";
747
457
  return (
748
458
  <>
749
459
  <dl className="gb-engine-rows">
750
- <dt>{inSettings ? L.state ?? ENGINE_PICKER_EN.state : L.bridge}</dt>
460
+ <dt>{L.state}</dt>
751
461
  <dd><span className={DOT_CLASS[tone]} aria-hidden /> {L[STATE_LABEL[bridge.state]]}</dd>
752
462
  {bridge.version ? <><dt>{L.version}</dt><dd>{bridge.version}{bridge.latest && bridge.latest !== bridge.version ? ` · ${L.latest} ${bridge.latest}` : ""}</dd></> : null}
753
463
  <dt>{L.startsAtSignIn}</dt><dd>{yesNo(bridge.autostart)}</dd>
@@ -762,8 +472,8 @@ export function StatusTab({ bridge, actions, L, inSettings = false }: { bridge:
762
472
 
763
473
  /**
764
474
  * ONE line in the chat stream, for a turn that actually failed because of the bridge ("The bridge on your machine is
765
- * not connected."), with "Open setup" that opens the picker on its Setup tab. Never a standing block: the chip's dot says
766
- * "outdated" all the time, this says "this turn failed, here is why" once.
475
+ * not connected."), with "Open setup" that opens Settings › AI & engines on Install or update (`useEnginePicker().openTab`).
476
+ * Never a standing block: the chip's dot says "outdated" all the time, this says "this turn failed, here is why" once.
767
477
  */
768
478
  export function BridgeNotice({ children, onOpenSetup, action = "Open setup", tone = "down", className }: {
769
479
  children: ReactNode;