2026-09-12 06:02:40 +03:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
2026-09-28 23:30:11 +03:00
|
|
|
import type { ChatSettings, ModelCatalogEntry, ModelCatalogResponse, ModelsSettings, UserSettings } from "@/src/core";
|
2026-09-22 16:40:31 +03:00
|
|
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
2026-09-19 21:59:30 +03:00
|
|
|
import { prettyModel } from "@/components/usage-format";
|
|
|
|
|
import { ModelMenuList, ThinkingMenuList } from "@/components/settings/model-menu";
|
2026-09-22 16:40:31 +03:00
|
|
|
import { composeSlotModel } from "@/components/settings/agent-section";
|
2026-09-22 16:56:44 +03:00
|
|
|
import { MenuShell } from "@/components/menu-shell";
|
2026-09-25 01:52:20 +03:00
|
|
|
import { Hint } from "@/components/ui/hint";
|
2026-10-24 12:17:08 +03:00
|
|
|
import { notifySettingsSaved, onSettingsSaved, useSettingsSaved } from "@/components/settings-signal";
|
2026-09-22 22:05:27 +03:00
|
|
|
import { defaultOrderLevel, populateLevel, THINKING_LABEL } from "@/components/thinking-default";
|
2026-09-12 06:02:40 +03:00
|
|
|
|
2026-09-22 16:40:31 +03:00
|
|
|
/** 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
|
|
|
|
|
* catalog immediately server-side. ModelControl therefore re-fetches on
|
|
|
|
|
* every model-menu open (stale-while-revalidate: the cached list shows
|
|
|
|
|
* instantly, the fresh one swaps in while the menu is open). */
|
2026-09-12 06:02:40 +03:00
|
|
|
let catalogCache: ModelCatalogResponse | undefined;
|
2026-10-24 12:17:08 +03:00
|
|
|
let catalogInflight: Promise<void> | undefined;
|
|
|
|
|
let catalogGeneration = 0;
|
|
|
|
|
let stopCatalogSignals: (() => void) | undefined;
|
|
|
|
|
const catalogReaders = new Set<() => void>();
|
|
|
|
|
const publishCatalog = () => { for (const reader of catalogReaders) reader(); };
|
|
|
|
|
function fetchCatalog(revalidate = false): void {
|
|
|
|
|
if (revalidate) { catalogGeneration++; catalogInflight = undefined; }
|
|
|
|
|
if (catalogInflight) return;
|
|
|
|
|
const generation = catalogGeneration;
|
|
|
|
|
catalogInflight = fetch("/api/models")
|
|
|
|
|
.then((r) => { if (!r.ok) throw new Error(`catalog request failed: ${r.status}`); return r.json() as Promise<ModelCatalogResponse>; })
|
|
|
|
|
.then((c) => { if (generation === catalogGeneration) { catalogCache = c; publishCatalog(); } })
|
|
|
|
|
.catch(() => { /* existing unavailable/usage-only posture, no retry timer */ })
|
|
|
|
|
.finally(() => { if (generation === catalogGeneration) catalogInflight = undefined; });
|
2026-09-12 06:02:40 +03:00
|
|
|
}
|
2026-09-24 02:15:23 +03:00
|
|
|
export function useModelCatalog(): { catalog: ModelCatalogResponse | undefined; refresh: () => void } {
|
2026-09-12 06:02:40 +03:00
|
|
|
const [catalog, setCatalog] = useState(catalogCache);
|
|
|
|
|
useEffect(() => {
|
2026-10-24 12:17:08 +03:00
|
|
|
const first = catalogReaders.size === 0;
|
|
|
|
|
const read = () => setCatalog(catalogCache);
|
|
|
|
|
catalogReaders.add(read);
|
|
|
|
|
if (first) {
|
|
|
|
|
stopCatalogSignals = onSettingsSaved((section) => {
|
|
|
|
|
if (section === "keys") {
|
|
|
|
|
catalogGeneration++; catalogInflight = undefined; catalogCache = undefined;
|
|
|
|
|
publishCatalog(); fetchCatalog();
|
|
|
|
|
} else if (section === "models") fetchCatalog(true);
|
2026-09-22 16:40:31 +03:00
|
|
|
});
|
2026-10-24 12:17:08 +03:00
|
|
|
fetchCatalog(true);
|
|
|
|
|
} else fetchCatalog();
|
|
|
|
|
read();
|
|
|
|
|
return () => { catalogReaders.delete(read); if (!catalogReaders.size) { stopCatalogSignals?.(); stopCatalogSignals = undefined; } };
|
2026-09-22 16:40:31 +03:00
|
|
|
}, []);
|
2026-10-24 12:17:08 +03:00
|
|
|
const refresh = useCallback(() => fetchCatalog(true), []);
|
2026-09-22 16:40:31 +03:00
|
|
|
return { catalog, refresh };
|
2026-09-12 06:02:40 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-24 02:15:23 +03:00
|
|
|
/** provider:id → contextWindow over the cached catalog — the client-side
|
|
|
|
|
* twin of the server's catalogContextLimits join (context-meter
|
|
|
|
|
* amendment, owner 2026-09-23: pi's live catalog is the ONLY limit
|
|
|
|
|
* source — no hardcoded fallback exists anywhere, so a model missing
|
|
|
|
|
* from the index reads limit-null and the meter renders usage-only,
|
|
|
|
|
* the honest-render precedent). Consumed by the stats bar: the same
|
|
|
|
|
* cached /api/models fetch the picker rides feeds the denominator. */
|
|
|
|
|
export function catalogLimits(catalog: Pick<ModelCatalogResponse, "models">): Map<string, number> {
|
|
|
|
|
return new Map(catalog.models.map((m) => [`${m.provider}:${m.id}`, m.contextWindow]));
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 16:40:31 +03:00
|
|
|
/**
|
2026-09-28 23:30:11 +03:00
|
|
|
* THE CONVERSATION MODEL CONTROL — dual-bound (owner, per-session models,
|
|
|
|
|
* 2026-09-28). WITH a chatId (the in-session stats bar): the pills bind
|
|
|
|
|
* THE SESSION'S OWN record — reads GET /api/chats/:id (its settings field;
|
|
|
|
|
* a legacy unstamped record falls back to the strong slot's display,
|
|
|
|
|
* exactly what the engine resolves), writes PUT /api/chats/:id/settings
|
|
|
|
|
* (validated + level-clamped server-side). The session owns its model +
|
|
|
|
|
* thinking level from birth; the strong slot never reaches it again.
|
2026-09-22 16:40:31 +03:00
|
|
|
*
|
2026-09-28 23:30:11 +03:00
|
|
|
* WITHOUT a chatId (the draft surfaces — home + /chat/new): the pills
|
|
|
|
|
* bind the STRONG SLOT (reads the raw models section, GET /api/settings;
|
|
|
|
|
* writes PUT /api/settings/models via composeSlotModel — the same seam
|
|
|
|
|
* the settings Agent section and the SetupDialog write): picking there IS
|
|
|
|
|
* changing the new-session default. Unpicked reads "—" (the
|
|
|
|
|
* no-factory-fallback language: the UI never presents a default model).
|
2026-09-22 16:40:31 +03:00
|
|
|
*/
|
2026-09-28 23:30:11 +03:00
|
|
|
export function ModelControl({ chatId }: { chatId?: string }) {
|
2026-09-22 16:40:31 +03:00
|
|
|
const { catalog, refresh } = useModelCatalog();
|
|
|
|
|
const [models, setModels] = useState<ModelsSettings | undefined>();
|
2026-09-28 23:30:11 +03:00
|
|
|
const [session, setSession] = useState<ChatSettings | undefined>();
|
2026-09-12 06:02:40 +03:00
|
|
|
const [open, setOpen] = useState<"model" | "thinking" | null>(null);
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
2026-09-14 08:10:27 +03:00
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
2026-09-12 06:02:40 +03:00
|
|
|
|
2026-09-22 21:55:18 +03:00
|
|
|
// 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).
|
2026-09-28 23:30:11 +03:00
|
|
|
// Dual-bound: chat mode reads BOTH the session record (the source of
|
|
|
|
|
// truth) and the models section (the display fallback for a legacy
|
|
|
|
|
// unstamped session — exactly what the engine resolves); draft mode
|
|
|
|
|
// reads the models section alone.
|
2026-09-22 21:55:18 +03:00
|
|
|
const readRecord = useCallback(() => {
|
2026-09-28 23:30:11 +03:00
|
|
|
if (chatId) {
|
|
|
|
|
fetch(`/api/chats/${chatId}`)
|
|
|
|
|
.then((r) => r.json() as Promise<{ settings?: ChatSettings }>)
|
|
|
|
|
.then((body) => setSession(body.settings))
|
|
|
|
|
.catch(() => {
|
|
|
|
|
/* same read-only posture as a models-section failure */
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-09-22 16:40:31 +03:00
|
|
|
fetch("/api/settings")
|
|
|
|
|
.then((r) => r.json() as Promise<{ settings: { models?: ModelsSettings } | null }>)
|
2026-09-22 21:55:18 +03:00
|
|
|
.then((body) => setModels(body.settings?.models ?? undefined))
|
2026-09-22 16:40:31 +03:00
|
|
|
.catch(() => {
|
|
|
|
|
/* the record fetch failing leaves the control read-only
|
|
|
|
|
("—" triggers, closed menus) — same posture as a
|
|
|
|
|
catalog failure */
|
|
|
|
|
});
|
2026-09-28 23:30:11 +03:00
|
|
|
}, [chatId]);
|
2026-09-12 06:02:40 +03:00
|
|
|
|
2026-09-22 21:55:18 +03:00
|
|
|
useEffect(() => {
|
|
|
|
|
readRecord();
|
|
|
|
|
}, [readRecord]);
|
|
|
|
|
|
|
|
|
|
useSettingsSaved((section) => {
|
|
|
|
|
if (section === "models") readRecord();
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-28 23:30:11 +03:00
|
|
|
// Dual-bound truth: chat mode displays the session's own record,
|
|
|
|
|
// falling back to the strong slot for legacy unstamped sessions —
|
|
|
|
|
// EXACTLY what resolveConversationSpec runs. Draft mode is the strong
|
|
|
|
|
// slot itself.
|
|
|
|
|
const strong = models?.strong;
|
|
|
|
|
const override: ChatSettings | undefined = chatId
|
|
|
|
|
? {
|
|
|
|
|
model: session?.model ?? strong?.model,
|
|
|
|
|
thinkingLevel: session?.thinkingLevel ?? strong?.thinkingLevel,
|
|
|
|
|
}
|
|
|
|
|
: strong;
|
2026-09-22 16:40:31 +03:00
|
|
|
const effectiveId = override?.model?.id;
|
|
|
|
|
const effectiveProvider = override?.model?.provider;
|
2026-09-22 22:05:27 +03:00
|
|
|
const storedLevel = override?.thinkingLevel;
|
2026-09-22 16:40:31 +03:00
|
|
|
const entry = catalog?.models.find(
|
|
|
|
|
(m) => m.id === effectiveId && m.provider === effectiveProvider,
|
|
|
|
|
);
|
|
|
|
|
const levels = entry?.supportedLevels ?? [];
|
2026-09-22 22:05:27 +03:00
|
|
|
// Legacy display (chunk 2 item 4, owner): a record with a model but no
|
|
|
|
|
// stored level shows the RESOLVED level — the ordering's first supported
|
|
|
|
|
// — because that is exactly what the engine build would run. Display-
|
|
|
|
|
// only: the record stays unset until a fresh pick populates it.
|
|
|
|
|
const effectiveLevel = storedLevel ?? (entry ? defaultOrderLevel(levels) : undefined);
|
2026-09-12 06:02:40 +03:00
|
|
|
|
2026-09-14 08:10:27 +03:00
|
|
|
// The intuitive dropdown contract (owner, stats-control round 1): any
|
2026-09-22 21:55:18 +03:00
|
|
|
// 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).
|
2026-09-14 08:10:27 +03:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (open === null) return;
|
|
|
|
|
const onPointerDown = (e: PointerEvent) => {
|
2026-09-22 21:55:18 +03:00
|
|
|
const t = e.target as Element;
|
|
|
|
|
if (t instanceof Element && t.closest("[data-lh-menu]")) return;
|
|
|
|
|
if (containerRef.current && !containerRef.current.contains(t)) {
|
2026-09-14 08:10:27 +03:00
|
|
|
setOpen(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const onKeyDown = (e: KeyboardEvent) => {
|
2026-09-17 20:47:23 +03:00
|
|
|
if (e.key === "Escape") {
|
|
|
|
|
// Claim the Esc (keyboard wave A): the window-level chain must
|
|
|
|
|
// not ALSO stop dictation / abort the turn under this menu.
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setOpen(null);
|
|
|
|
|
}
|
2026-09-14 08:10:27 +03:00
|
|
|
};
|
|
|
|
|
document.addEventListener("pointerdown", onPointerDown);
|
|
|
|
|
document.addEventListener("keydown", onKeyDown);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("pointerdown", onPointerDown);
|
|
|
|
|
document.removeEventListener("keydown", onKeyDown);
|
|
|
|
|
};
|
|
|
|
|
}, [open]);
|
|
|
|
|
|
2026-09-22 16:40:31 +03:00
|
|
|
// One write seam: composeSlotModel preserves the cheap/vision siblings
|
|
|
|
|
// (replace-whole-section discipline) and the per-field independence of
|
|
|
|
|
// model + thinkingLevel within the strong slot.
|
2026-09-12 06:02:40 +03:00
|
|
|
const save = useCallback(
|
2026-09-22 16:40:31 +03:00
|
|
|
async (next: ModelsSettings) => {
|
2026-09-12 06:02:40 +03:00
|
|
|
setError(null);
|
|
|
|
|
try {
|
2026-09-22 16:40:31 +03:00
|
|
|
const res = await fetch("/api/settings/models", {
|
2026-09-12 06:02:40 +03:00
|
|
|
method: "PUT",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify(next),
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
|
|
|
|
setError(body.error ?? `settings rejected (${res.status})`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-09-22 22:45:11 +03:00
|
|
|
// Server truth, never the request body (fix wave): a pick
|
|
|
|
|
// that rides an unsupported level lands CLAMPED in the record
|
|
|
|
|
// — the pill must show the stored value in this interaction.
|
|
|
|
|
const stored = (
|
|
|
|
|
(await res.json().catch(() => null)) as { settings?: UserSettings } | null
|
|
|
|
|
)?.settings?.models;
|
|
|
|
|
setModels(stored ?? next);
|
2026-09-12 06:02:40 +03:00
|
|
|
setOpen(null);
|
2026-09-22 21:55:18 +03:00
|
|
|
notifySettingsSaved("models");
|
2026-09-12 06:02:40 +03:00
|
|
|
} catch {
|
|
|
|
|
setError("Could not reach the server — try again.");
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-09-22 16:40:31 +03:00
|
|
|
[],
|
2026-09-12 06:02:40 +03:00
|
|
|
);
|
|
|
|
|
|
2026-09-28 23:30:11 +03:00
|
|
|
// The session write seam (chat mode): PUT the per-chat settings route
|
|
|
|
|
// — validated + level-clamped server-side; the response is the stored
|
|
|
|
|
// truth (a pick riding an unsupported level lands CLAMPED — the pill
|
|
|
|
|
// shows the stored value). No notifySettingsSaved: the write touches
|
|
|
|
|
// one session's record, not the slots — no other surface reads it.
|
|
|
|
|
const saveChat = useCallback(
|
|
|
|
|
async (next: ChatSettings) => {
|
|
|
|
|
setError(null);
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/chats/${chatId}/settings`, {
|
|
|
|
|
method: "PUT",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify(next),
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
|
|
|
|
setError(body.error ?? `settings rejected (${res.status})`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const stored = (await res.json().catch(() => null)) as { settings?: ChatSettings } | null;
|
|
|
|
|
setSession(stored?.settings ?? next);
|
|
|
|
|
setOpen(null);
|
|
|
|
|
} catch {
|
|
|
|
|
setError("Could not reach the server — try again.");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[chatId],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// One apply seam over both write paths: a pick names provider + id +
|
|
|
|
|
// level; chat mode writes the session's own record (any pick pins it),
|
|
|
|
|
// draft mode composes the strong slot (siblings preserved,
|
|
|
|
|
// replace-whole-section discipline).
|
|
|
|
|
const apply = useCallback(
|
|
|
|
|
(provider: string, id: string, level: ThinkingLevel | undefined) => {
|
|
|
|
|
if (chatId) {
|
|
|
|
|
void saveChat({ model: { provider, id }, thinkingLevel: level });
|
|
|
|
|
} else {
|
|
|
|
|
// composeSlotModel's empty-string convention: no level = unset.
|
|
|
|
|
void save(composeSlotModel(models, "strong", provider, id, level ?? ""));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[chatId, models, save, saveChat],
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-17 20:47:23 +03:00
|
|
|
// Shortcut seams (keyboard wave A): ⌘K opens the model menu (the
|
|
|
|
|
// universal command convention); Shift+Tab cycles the thinking level
|
|
|
|
|
// up the ladder (wrapping) — the owner's replacement for browser
|
|
|
|
|
// tab-focus. Both work from any focus, including mid-typing.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const onOpenPicker = () => {
|
|
|
|
|
setOpen("model");
|
|
|
|
|
setError(null);
|
2026-09-22 16:40:31 +03:00
|
|
|
refresh(); // mid-session key changes widen the menu (cache fix)
|
2026-09-17 20:47:23 +03:00
|
|
|
};
|
|
|
|
|
window.addEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
|
|
|
|
return () => window.removeEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
2026-09-22 16:40:31 +03:00
|
|
|
}, [refresh]);
|
2026-09-17 20:47:23 +03:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const onCycleThinking = () => {
|
|
|
|
|
if (levels.length === 0) return;
|
|
|
|
|
const idx = effectiveLevel === undefined ? -1 : levels.indexOf(effectiveLevel);
|
2026-09-22 16:40:31 +03:00
|
|
|
const next = levels[(idx + 1) % levels.length];
|
|
|
|
|
if (next === undefined) return;
|
2026-09-28 23:30:11 +03:00
|
|
|
apply(effectiveProvider ?? "", effectiveId ?? "", next);
|
2026-09-17 20:47:23 +03:00
|
|
|
};
|
|
|
|
|
window.addEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
|
|
|
|
return () => window.removeEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
2026-09-28 23:30:11 +03:00
|
|
|
}, [levels, effectiveLevel, effectiveProvider, effectiveId, apply]);
|
2026-09-17 20:47:23 +03:00
|
|
|
|
2026-09-18 08:53:27 +03:00
|
|
|
// Selecting a model (click and Enter share one path): keep the
|
|
|
|
|
// thinking level only when the new model supports it — otherwise
|
2026-09-22 16:40:31 +03:00
|
|
|
// drop it (a carry-over would 400 at the server's catalog gate).
|
2026-09-18 08:53:27 +03:00
|
|
|
const pickModel = (m: ModelCatalogEntry) => {
|
2026-09-22 22:05:27 +03:00
|
|
|
// Auto-populate (chunk 2, owner: "populate everywhere"): a fresh pick
|
|
|
|
|
// ALWAYS writes a level — the STORED one rides as-is (the write clamps
|
|
|
|
|
// server-side when the new model doesn't support it; the signal
|
|
|
|
|
// re-reads and the clamped truth displays), and a record with no
|
|
|
|
|
// stored level populates the ordering's level. The unset state can
|
|
|
|
|
// never re-enter through this door. (The DERIVED display level never
|
|
|
|
|
// rides — it belongs to the OLD model; the fresh pick's level comes
|
|
|
|
|
// from the fresh model's own ladder.)
|
|
|
|
|
const nextLevel = populateLevel(storedLevel, m.supportedLevels);
|
2026-09-28 23:30:11 +03:00
|
|
|
apply(m.provider, m.id, nextLevel);
|
2026-09-18 08:53:27 +03:00
|
|
|
};
|
|
|
|
|
|
2026-09-22 16:40:31 +03:00
|
|
|
// Stale-while-revalidate on manual open too (⌘K covers the keyboard
|
|
|
|
|
// path above): the cached list shows instantly, the fresh federation
|
|
|
|
|
// swaps in when it lands.
|
|
|
|
|
const openMenu = (kind: "model" | "thinking") => {
|
|
|
|
|
setOpen((o) => (o === kind ? null : kind));
|
|
|
|
|
setError(null);
|
|
|
|
|
if (kind === "model") refresh();
|
|
|
|
|
};
|
2026-09-12 06:02:40 +03:00
|
|
|
|
|
|
|
|
return (
|
2026-09-14 08:10:27 +03:00
|
|
|
<div ref={containerRef} className="relative flex items-center gap-1.5" data-testid="model-control">
|
2026-10-24 12:17:08 +03:00
|
|
|
{effectiveProvider === "chatgpt" && <a href="https://chatgpt.com/settings/usage" target="_blank" rel="noreferrer" className="text-xs text-muted-foreground underline-offset-2 hover:underline">Using ChatGPT plan</a>}
|
2026-09-25 01:52:20 +03:00
|
|
|
<Hint
|
2026-09-25 02:26:37 +03:00
|
|
|
// Trimmed (owner, subtlety round 2026-09-25): "Model selector"
|
|
|
|
|
// — the long sentence was way too much. ⌘K opens this same
|
|
|
|
|
// menu (registry, override-aware).
|
|
|
|
|
label="Model selector"
|
2026-09-25 01:52:20 +03:00
|
|
|
action="open-model-picker"
|
|
|
|
|
side="bottom"
|
|
|
|
|
>
|
|
|
|
|
<button
|
2026-09-12 06:02:40 +03:00
|
|
|
type="button"
|
|
|
|
|
data-testid="stats-model"
|
2026-09-22 16:40:31 +03:00
|
|
|
onClick={() => openMenu("model")}
|
2026-09-12 06:02:40 +03:00
|
|
|
aria-expanded={open === "model"}
|
2026-09-23 01:46:15 +03:00
|
|
|
// Chrome look (owner, fix wave round 3): matches the graph
|
|
|
|
|
// view's floating top-right buttons (import notes, gear,
|
|
|
|
|
// coverage) — blurred, fuller opacity, shadowed — so the
|
|
|
|
|
// graph no longer bleeds through these pills.
|
|
|
|
|
className="flex items-center gap-1.5 rounded-full border bg-card/85 px-2.5 py-1 shadow-lg backdrop-blur transition-colors hover:border-border hover:bg-muted"
|
2026-09-12 06:02:40 +03:00
|
|
|
>
|
2026-09-12 06:11:23 +03:00
|
|
|
<span className="text-card-foreground">{effectiveId ? prettyModel(effectiveId) : "—"}</span>
|
2026-09-22 16:40:31 +03:00
|
|
|
<span aria-hidden className="text-xs text-muted-foreground">▾</span>
|
2026-09-12 06:02:40 +03:00
|
|
|
</button>
|
2026-09-25 01:52:20 +03:00
|
|
|
</Hint>
|
|
|
|
|
<Hint
|
2026-09-25 02:39:11 +03:00
|
|
|
// "Thinking" + its real shortcut via the registry (owner interlude
|
|
|
|
|
// 2026-09-25): ⇧⇥ cycles the level, so "Thinking (⇧⇥)" —
|
|
|
|
|
// rebind-live like every Hint suffix.
|
|
|
|
|
label="Thinking"
|
|
|
|
|
action="cycle-thinking"
|
2026-09-25 01:52:20 +03:00
|
|
|
side="bottom"
|
|
|
|
|
>
|
|
|
|
|
<button
|
2026-09-12 06:02:40 +03:00
|
|
|
type="button"
|
|
|
|
|
data-testid="stats-thinking"
|
|
|
|
|
onClick={() => {
|
2026-09-22 16:40:31 +03:00
|
|
|
// No model picked → nothing to set a level FOR: the click
|
|
|
|
|
// is a no-op, never an empty menu.
|
2026-09-18 09:37:20 +03:00
|
|
|
if (entry === undefined) return;
|
2026-09-22 16:40:31 +03:00
|
|
|
openMenu("thinking");
|
2026-09-12 06:02:40 +03:00
|
|
|
}}
|
|
|
|
|
aria-expanded={open === "thinking"}
|
2026-09-23 01:46:15 +03:00
|
|
|
// Chrome look (owner, fix wave round 3): matches the graph
|
|
|
|
|
// view's floating top-right buttons (import notes, gear,
|
|
|
|
|
// coverage) — blurred, fuller opacity, shadowed — so the
|
|
|
|
|
// graph no longer bleeds through these pills.
|
|
|
|
|
className="flex items-center gap-1.5 rounded-full border bg-card/85 px-2.5 py-1 shadow-lg backdrop-blur transition-colors hover:border-border hover:bg-muted"
|
2026-09-12 06:02:40 +03:00
|
|
|
>
|
2026-09-14 08:10:27 +03:00
|
|
|
{/* Just the level — the button reads like the model button reads
|
|
|
|
|
the model name (owner, stats-control round 1). */}
|
2026-09-12 06:11:23 +03:00
|
|
|
<span className="text-card-foreground">
|
2026-09-22 22:05:27 +03:00
|
|
|
{effectiveLevel === undefined ? "—" : (THINKING_LABEL[effectiveLevel] ?? effectiveLevel)}
|
2026-09-12 06:02:40 +03:00
|
|
|
</span>
|
2026-09-17 13:43:26 +03:00
|
|
|
<span aria-hidden className="text-xs text-muted-foreground">▾</span>
|
2026-09-12 06:02:40 +03:00
|
|
|
</button>
|
2026-09-25 01:52:20 +03:00
|
|
|
</Hint>
|
2026-09-12 06:02:40 +03:00
|
|
|
|
2026-09-19 21:59:30 +03:00
|
|
|
{/* The shared dropdown body (extracted 2026-09-20): the agent
|
2026-09-22 16:40:31 +03:00
|
|
|
settings' slot selects and the setup dialog use the exact same
|
|
|
|
|
one. */}
|
2026-09-12 06:02:40 +03:00
|
|
|
{open === "model" && (
|
2026-09-22 16:56:44 +03:00
|
|
|
<MenuShell
|
|
|
|
|
anchorRef={containerRef}
|
|
|
|
|
testid="model-menu"
|
|
|
|
|
preferredSide="up"
|
|
|
|
|
menuClass="flex w-[22rem] flex-col rounded-xl border bg-card p-2 text-xs shadow-xl"
|
2026-09-12 06:02:40 +03:00
|
|
|
>
|
|
|
|
|
{error && <div className="mb-1.5 text-destructive">{error}</div>}
|
2026-09-19 21:59:30 +03:00
|
|
|
<ModelMenuList
|
|
|
|
|
models={catalog?.models}
|
|
|
|
|
effectiveId={effectiveId}
|
2026-09-22 16:40:31 +03:00
|
|
|
effectiveProvider={effectiveProvider}
|
2026-09-19 21:59:30 +03:00
|
|
|
onPick={pickModel}
|
2026-09-22 16:40:31 +03:00
|
|
|
footer={
|
|
|
|
|
catalog && catalog.models.length === 0
|
|
|
|
|
? "No models — add a provider key in Keys"
|
2026-09-28 23:30:11 +03:00
|
|
|
: chatId
|
|
|
|
|
? "This session's model"
|
|
|
|
|
: "Strong tier — the default for new sessions"
|
2026-09-22 16:40:31 +03:00
|
|
|
}
|
2026-09-19 21:59:30 +03:00
|
|
|
/>
|
2026-09-22 16:56:44 +03:00
|
|
|
</MenuShell>
|
2026-09-12 06:02:40 +03:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{open === "thinking" && (
|
2026-09-22 16:56:44 +03:00
|
|
|
<MenuShell
|
|
|
|
|
anchorRef={containerRef}
|
|
|
|
|
testid="thinking-menu"
|
|
|
|
|
preferredSide="up"
|
|
|
|
|
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border bg-card p-2 text-xs shadow-xl"
|
2026-09-12 06:02:40 +03:00
|
|
|
>
|
2026-09-19 21:59:30 +03:00
|
|
|
<ThinkingMenuList
|
|
|
|
|
levels={catalog ? levels : []}
|
|
|
|
|
effectiveLevel={effectiveLevel}
|
2026-09-28 23:30:11 +03:00
|
|
|
onPick={(level) => apply(effectiveProvider ?? "", effectiveId ?? "", level as ThinkingLevel)}
|
2026-09-19 21:59:30 +03:00
|
|
|
empty={catalog ? (effectiveId ? `${prettyModel(effectiveId)} has no thinking levels.` : "Pick a model first.") : "Loading…"}
|
|
|
|
|
footer="Levels this model actually supports"
|
|
|
|
|
/>
|
2026-09-12 06:02:40 +03:00
|
|
|
{error && <div className="mt-1 text-destructive">{error}</div>}
|
2026-09-22 16:56:44 +03:00
|
|
|
</MenuShell>
|
2026-09-12 06:02:40 +03:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|