Fix wave chunk A: no Default option, composer = strong slot, catalog revalidation
Item 1 — no Default in the slot selectors (owner, fix wave): a "default" model is not a thing in this app. Picking Default used to delete the slot and re-arm the first-run gate — incoherent. Now the model menus carry NO clear row at all (a slot holds a pick or reads "—"), the thinking menus carry a "—" row (menu-none) that clears only the thinking pin, and the hint line is the roster only — the resolved factory pin is never named. Master's amendment confirmed: the factory-pin hint is SUPERSEDED entirely (Platform removes the pins). Item 2 — the composer control IS the strong slot (owner: "one and the same"): ModelControl (model-picker.tsx) reads the raw models section (GET /api/settings) and the federated catalog, and writes PUT /api/settings/models via composeSlotModel — the same seam the settings Agent section and SetupDialog use. Props retired: chatId, settings, onSaved, fallbackModelId, noDefaultModel — the control is self-sufficient and identical on every surface (composer, home dock, /chat/new). The per-chat model PUT is gone from the UI; legacy per-chat overrides keep resolving server-side. StatsBar/DockOverlay plumbing slimmed accordingly; chat.tsx drops its per-chat settings state and initialSettings prop. Item 3 — the composer catalog cache no longer freezes per page load: fetchCatalog(force) invalidates, and every model-menu open revalidates in the background (stale-while-revalidate — cached list shows instantly, the fresh federation swaps in). Owner's repro verified live: a key saved mid-session widens the menu without a reload. Item 4 — stale doc comments fixed: model-catalog.ts's "OpenRouter catalog"/"multi-provider future" (Platform's file — mechanical, flagged for review) and model-picker's retired "config-pinned"/ per-chat-PUT narrative. Live-verified on 3001: unpicked slots read "—" everywhere; model menus have no clear row; the "—" thinking row clears the pin but keeps the model; composer pick writes strong and preserves cheap/ vision siblings; thinking pill writes strong.thinkingLevel; groq key added mid-session appears in the open menu without reload. Caught in live verification: the record fetch was mapping the WHOLE settings record into the models section (picks never wrote) — fixed to read body.settings.models. Gates: typecheck, lint, 807/807, build.
This commit is contained in:
@@ -25,7 +25,6 @@ export default async function ChatPage({
|
|||||||
// A teacher turn that outlived its client: the remounted view must
|
// A teacher turn that outlived its client: the remounted view must
|
||||||
// attach (busy shimmer + poll), never resurrect the stale record.
|
// attach (busy shimmer + poll), never resurrect the stale record.
|
||||||
initiallyInFlight={isTurnRunning(chat.id)}
|
initiallyInFlight={isTurnRunning(chat.id)}
|
||||||
initialSettings={chat.settings}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ export function Chat({
|
|||||||
initialMessages,
|
initialMessages,
|
||||||
initialPrompt,
|
initialPrompt,
|
||||||
initiallyInFlight,
|
initiallyInFlight,
|
||||||
initialSettings,
|
|
||||||
}: {
|
}: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -127,8 +126,6 @@ export function Chat({
|
|||||||
/** A teacher turn is running server-side but attached to no client
|
/** A teacher turn is running server-side but attached to no client
|
||||||
* (navigated away mid-turn, returned while in flight). */
|
* (navigated away mid-turn, returned while in flight). */
|
||||||
initiallyInFlight?: boolean;
|
initiallyInFlight?: boolean;
|
||||||
/** The record's per-chat model/thinking settings (the picker's seed). */
|
|
||||||
initialSettings?: ChatSettings;
|
|
||||||
}) {
|
}) {
|
||||||
const { messages, sendMessage, addToolOutput, setMessages, status, error, stop } =
|
const { messages, sendMessage, addToolOutput, setMessages, status, error, stop } =
|
||||||
useChat<TeacherUIMessage>({
|
useChat<TeacherUIMessage>({
|
||||||
@@ -445,7 +442,6 @@ export function Chat({
|
|||||||
const [turns, setTurns] = useState<TurnUsage[]>([]);
|
const [turns, setTurns] = useState<TurnUsage[]>([]);
|
||||||
// The per-chat model control state (model-picker writes via PUT; the
|
// The per-chat model control state (model-picker writes via PUT; the
|
||||||
// record is the source of truth, lifted here so the stats bar re-renders).
|
// record is the source of truth, lifted here so the stats bar re-renders).
|
||||||
const [settings, setSettings] = useState<ChatSettings | undefined>(initialSettings);
|
|
||||||
// The dock's reserved tail height (DockOverlay reports it; the spacer at
|
// The dock's reserved tail height (DockOverlay reports it; the spacer at
|
||||||
// the end of the transcript renders it). Lives here because the spacer is
|
// the end of the transcript renders it). Lives here because the spacer is
|
||||||
// inside the scroller while the dock overlays OUTSIDE it — two parents.
|
// inside the scroller while the dock overlays OUTSIDE it — two parents.
|
||||||
@@ -963,8 +959,6 @@ export function Chat({
|
|||||||
<DockOverlay
|
<DockOverlay
|
||||||
pending={pending}
|
pending={pending}
|
||||||
chatId={chatId}
|
chatId={chatId}
|
||||||
settings={settings}
|
|
||||||
onSettingsSaved={setSettings}
|
|
||||||
plan={<PlanMarginalia messages={messages} />}
|
plan={<PlanMarginalia messages={messages} />}
|
||||||
onOpenPlan={() => setPlanOpen(true)}
|
onOpenPlan={() => setPlanOpen(true)}
|
||||||
requiresReveal={requiresReveal}
|
requiresReveal={requiresReveal}
|
||||||
@@ -1054,8 +1048,6 @@ function DockOverlay({
|
|||||||
composer,
|
composer,
|
||||||
onSubmitAnswer,
|
onSubmitAnswer,
|
||||||
chatId,
|
chatId,
|
||||||
settings,
|
|
||||||
onSettingsSaved,
|
|
||||||
onReserve,
|
onReserve,
|
||||||
plan,
|
plan,
|
||||||
onOpenPlan,
|
onOpenPlan,
|
||||||
@@ -1073,8 +1065,6 @@ function DockOverlay({
|
|||||||
onSubmitAnswer: (output: QuestionAnswerData) => void;
|
onSubmitAnswer: (output: QuestionAnswerData) => void;
|
||||||
/** The model control's pass-through (the stats bar hosts it). */
|
/** The model control's pass-through (the stats bar hosts it). */
|
||||||
chatId: string;
|
chatId: string;
|
||||||
settings?: ChatSettings;
|
|
||||||
onSettingsSaved: (settings: ChatSettings) => void;
|
|
||||||
/** Reports the dock's settled height (block + gradient) — ChatView's
|
/** Reports the dock's settled height (block + gradient) — ChatView's
|
||||||
* dockReserve state feeds the transcript's spacer from it. */
|
* dockReserve state feeds the transcript's spacer from it. */
|
||||||
onReserve: (h: number) => void;
|
onReserve: (h: number) => void;
|
||||||
@@ -1351,9 +1341,6 @@ function DockOverlay({
|
|||||||
morphing shell so it never joins a height animation. */}
|
morphing shell so it never joins a height animation. */}
|
||||||
<StatsBar
|
<StatsBar
|
||||||
turns={turns}
|
turns={turns}
|
||||||
chatId={chatId}
|
|
||||||
settings={settings}
|
|
||||||
onSettingsSaved={onSettingsSaved}
|
|
||||||
dictationSlot={dictationSlot}
|
dictationSlot={dictationSlot}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+2
-6
@@ -167,15 +167,11 @@ export function Home({ initialSettings, initialConfigured }: { initialSettings:
|
|||||||
</form>
|
</form>
|
||||||
{/* Same as the chat view's under-composer stats bar (owner) — no
|
{/* Same as the chat view's under-composer stats bar (owner) — no
|
||||||
session yet, so the free LEFT side carries the knowledge-context
|
session yet, so the free LEFT side carries the knowledge-context
|
||||||
budget (session-data slot), while the RIGHT keeps the model +
|
budget (session-data slot), while the RIGHT keeps the strong-
|
||||||
thinking control (deferred save). */}
|
slot control (fix wave: the pills write /api/settings/models). */}
|
||||||
<StatsBar
|
<StatsBar
|
||||||
dictationSlot={<DictationBar dictation={dictation} />}
|
dictationSlot={<DictationBar dictation={dictation} />}
|
||||||
turns={[] as TurnUsage[]}
|
turns={[] as TurnUsage[]}
|
||||||
chatId=""
|
|
||||||
noDefaultModel
|
|
||||||
settings={settings}
|
|
||||||
onSettingsSaved={saveDraft}
|
|
||||||
leftSlot={
|
leftSlot={
|
||||||
<GraphContextControl
|
<GraphContextControl
|
||||||
value={effectiveContextTokens(settings)}
|
value={effectiveContextTokens(settings)}
|
||||||
|
|||||||
+107
-93
@@ -1,32 +1,25 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
/**
|
|
||||||
* The model + thinking control (model-control wave, 2026-09-12) — the stats
|
|
||||||
* bar's right side. ONE controller for the conversation agents (prober +
|
|
||||||
* teacher are functionally one agent); background sub-agents stay
|
|
||||||
* config-pinned. Writes go to PUT /api/chats/[id]/settings (validated
|
|
||||||
* server-side against pi-ai's catalog) and take effect on the next turn by
|
|
||||||
* construction — the agents are stateless per turn.
|
|
||||||
*
|
|
||||||
* The data is pi-ai's catalog (GET /api/models): the model menu is a fuzzy
|
|
||||||
* search over "provider id name" (core/fuzzy.ts — pi's /model pattern), and
|
|
||||||
* the thinking menu lists EXACTLY the chosen model's supported levels
|
|
||||||
* (getSupportedThinkingLevels — GLM-5.3-flash shows low|high|max, never a
|
|
||||||
* level it would silently clamp). Menus open ABOVE the buttons (the
|
|
||||||
* composer owns everything below).
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import type { ChatSettings, ModelCatalogEntry, ModelCatalogResponse } from "@/src/core";
|
import type { ModelCatalogEntry, ModelCatalogResponse, ModelsSettings } from "@/src/core";
|
||||||
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
||||||
import { prettyModel } from "@/components/usage-format";
|
import { prettyModel } from "@/components/usage-format";
|
||||||
import { ModelMenuList, ThinkingMenuList } from "@/components/settings/model-menu";
|
import { ModelMenuList, ThinkingMenuList } from "@/components/settings/model-menu";
|
||||||
|
import { composeSlotModel } from "@/components/settings/agent-section";
|
||||||
|
|
||||||
/** GET /api/models is fetched once per page load and shared by every
|
/** GET /api/models is cached per page load for instant menu opens, but
|
||||||
* picker instance (the catalog is static within a pi-ai version). */
|
* 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). */
|
||||||
let catalogCache: ModelCatalogResponse | undefined;
|
let catalogCache: ModelCatalogResponse | undefined;
|
||||||
let catalogInflight: Promise<ModelCatalogResponse> | undefined;
|
let catalogInflight: Promise<ModelCatalogResponse> | undefined;
|
||||||
|
|
||||||
function fetchCatalog(): Promise<ModelCatalogResponse> {
|
function fetchCatalog(force = false): Promise<ModelCatalogResponse> {
|
||||||
|
if (force) {
|
||||||
|
catalogCache = undefined;
|
||||||
|
catalogInflight = undefined;
|
||||||
|
}
|
||||||
catalogInflight ??= fetch("/api/models")
|
catalogInflight ??= fetch("/api/models")
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
if (!r.ok) throw new Error(`catalog request failed: ${r.status}`);
|
if (!r.ok) throw new Error(`catalog request failed: ${r.status}`);
|
||||||
@@ -37,13 +30,13 @@ function fetchCatalog(): Promise<ModelCatalogResponse> {
|
|||||||
return c;
|
return c;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
catalogInflight = undefined; // retry on next mount
|
catalogInflight = undefined; // retry on next mount/open
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
return catalogInflight;
|
return catalogInflight;
|
||||||
}
|
}
|
||||||
|
|
||||||
function useModelCatalog(): ModelCatalogResponse | undefined {
|
function useModelCatalog(): { catalog: ModelCatalogResponse | undefined; refresh: () => void } {
|
||||||
const [catalog, setCatalog] = useState(catalogCache);
|
const [catalog, setCatalog] = useState(catalogCache);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (catalogCache) return;
|
if (catalogCache) return;
|
||||||
@@ -51,14 +44,21 @@ function useModelCatalog(): ModelCatalogResponse | undefined {
|
|||||||
fetchCatalog()
|
fetchCatalog()
|
||||||
.then((c) => alive && setCatalog(c))
|
.then((c) => alive && setCatalog(c))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
/* the picker stays closed on failure; the buttons still display
|
/* the picker stays closed on failure; the buttons still
|
||||||
the effective model from props */
|
display the strong slot from the record fetch */
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
alive = false;
|
alive = false;
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
return catalog;
|
const refresh = useCallback(() => {
|
||||||
|
fetchCatalog(true)
|
||||||
|
.then(setCatalog)
|
||||||
|
.catch(() => {
|
||||||
|
/* refresh is best-effort: the cached list stays on failure */
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
return { catalog, refresh };
|
||||||
}
|
}
|
||||||
|
|
||||||
const LEVEL_LABEL: Record<string, string> = {
|
const LEVEL_LABEL: Record<string, string> = {
|
||||||
@@ -71,43 +71,51 @@ const LEVEL_LABEL: Record<string, string> = {
|
|||||||
max: "Max",
|
max: "Max",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
export function ModelControl({
|
* THE STRONG-SLOT CONTROL (fix wave, owner ruling: "one and the same").
|
||||||
chatId,
|
* The composer's model + thinking pills ARE the strong slot — the tier
|
||||||
settings,
|
* that runs prober + teacher. Reads: the raw models section (GET
|
||||||
onSaved,
|
* /api/settings) for the user's pick, plus the federated catalog for the
|
||||||
fallbackModelId,
|
* menus. Writes: PUT /api/settings/models via composeSlotModel — the same
|
||||||
noDefaultModel,
|
* seam the settings Agent section and the SetupDialog write, so there is
|
||||||
}: {
|
* exactly one strong slot in the world and every surface edits it.
|
||||||
chatId: string;
|
*
|
||||||
/** The record's current settings (undefined = config pin). */
|
* Unpicked reads "—" (the no-factory-fallback language: the UI never
|
||||||
settings?: ChatSettings;
|
* presents a default model; the engine-side pin still resolves, the UI
|
||||||
/** Lifts the persisted settings into the chat view's state. */
|
* never claims it). Legacy per-chat model overrides on old records keep
|
||||||
onSaved: (settings: ChatSettings) => void;
|
* resolving server-side — the UI simply no longer writes that field
|
||||||
/** The last turn's actual model (from the turns log) — the label until
|
* anywhere.
|
||||||
* the catalog (with config's defaults) finishes loading. */
|
*/
|
||||||
fallbackModelId?: string;
|
export function ModelControl() {
|
||||||
/** Default-surfaces only (owner, 2026-09-18): NO baked-in default —
|
const { catalog, refresh } = useModelCatalog();
|
||||||
* unset settings render "no model"/"—" (BYOK first boot), never the
|
const [models, setModels] = useState<ModelsSettings | undefined>();
|
||||||
* config pin. Chat surfaces keep the catalog-default fallback (the
|
|
||||||
* engine runs the pin, so the control shows what will run). */
|
|
||||||
noDefaultModel?: boolean;
|
|
||||||
}) {
|
|
||||||
const catalog = useModelCatalog();
|
|
||||||
const [open, setOpen] = useState<"model" | "thinking" | null>(null);
|
const [open, setOpen] = useState<"model" | "thinking" | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const defaults = catalog?.defaults;
|
useEffect(() => {
|
||||||
const effectiveId = noDefaultModel
|
let alive = true;
|
||||||
? settings?.model?.id
|
fetch("/api/settings")
|
||||||
: (settings?.model?.id ?? defaults?.model.id ?? fallbackModelId);
|
.then((r) => r.json() as Promise<{ settings: { models?: ModelsSettings } | null }>)
|
||||||
const effectiveLevel = noDefaultModel
|
.then((body) => alive && setModels(body.settings?.models ?? undefined))
|
||||||
? settings?.thinkingLevel
|
.catch(() => {
|
||||||
: (settings?.thinkingLevel ?? defaults?.thinkingLevel);
|
/* the record fetch failing leaves the control read-only
|
||||||
const entry = catalog?.models.find((m) => m.id === effectiveId);
|
("—" triggers, closed menus) — same posture as a
|
||||||
const levels = entry?.supportedLevels ?? [];
|
catalog failure */
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
alive = false;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const override = models?.strong;
|
||||||
|
const effectiveId = override?.model?.id;
|
||||||
|
const effectiveProvider = override?.model?.provider;
|
||||||
|
const effectiveLevel = override?.thinkingLevel;
|
||||||
|
const entry = catalog?.models.find(
|
||||||
|
(m) => m.id === effectiveId && m.provider === effectiveProvider,
|
||||||
|
);
|
||||||
|
const levels = entry?.supportedLevels ?? [];
|
||||||
|
|
||||||
// The intuitive dropdown contract (owner, stats-control round 1): any
|
// The intuitive dropdown contract (owner, stats-control round 1): any
|
||||||
// click outside the open menu — or an Esc keypress — closes it. Only the
|
// click outside the open menu — or an Esc keypress — closes it. Only the
|
||||||
@@ -136,18 +144,14 @@ export function ModelControl({
|
|||||||
};
|
};
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
|
// 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.
|
||||||
const save = useCallback(
|
const save = useCallback(
|
||||||
async (next: ChatSettings) => {
|
async (next: ModelsSettings) => {
|
||||||
setError(null);
|
setError(null);
|
||||||
// Home view (pre-chat): defer — the selection rides along on the
|
|
||||||
// chat POST and is PUT after creation (onSaved is still lifted).
|
|
||||||
if (!chatId) {
|
|
||||||
onSaved(next);
|
|
||||||
setOpen(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/chats/${chatId}/settings`, {
|
const res = await fetch("/api/settings/models", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(next),
|
body: JSON.stringify(next),
|
||||||
@@ -157,14 +161,13 @@ export function ModelControl({
|
|||||||
setError(body.error ?? `settings rejected (${res.status})`);
|
setError(body.error ?? `settings rejected (${res.status})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { settings: saved } = (await res.json()) as { settings: ChatSettings };
|
setModels(next);
|
||||||
onSaved(saved);
|
|
||||||
setOpen(null);
|
setOpen(null);
|
||||||
} catch {
|
} catch {
|
||||||
setError("Could not reach the server — try again.");
|
setError("Could not reach the server — try again.");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[chatId, onSaved],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Shortcut seams (keyboard wave A): ⌘K opens the model menu (the
|
// Shortcut seams (keyboard wave A): ⌘K opens the model menu (the
|
||||||
@@ -175,63 +178,66 @@ export function ModelControl({
|
|||||||
const onOpenPicker = () => {
|
const onOpenPicker = () => {
|
||||||
setOpen("model");
|
setOpen("model");
|
||||||
setError(null);
|
setError(null);
|
||||||
|
refresh(); // mid-session key changes widen the menu (cache fix)
|
||||||
};
|
};
|
||||||
window.addEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
window.addEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
||||||
return () => window.removeEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
return () => window.removeEventListener("lh:kbd-open-model-picker", onOpenPicker);
|
||||||
}, []);
|
}, [refresh]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onCycleThinking = () => {
|
const onCycleThinking = () => {
|
||||||
if (levels.length === 0) return;
|
if (levels.length === 0) return;
|
||||||
const idx = effectiveLevel === undefined ? -1 : levels.indexOf(effectiveLevel);
|
const idx = effectiveLevel === undefined ? -1 : levels.indexOf(effectiveLevel);
|
||||||
void save({ ...(settings ?? {}), thinkingLevel: levels[(idx + 1) % levels.length] });
|
const next = levels[(idx + 1) % levels.length];
|
||||||
|
if (next === undefined) return;
|
||||||
|
void save(composeSlotModel(models, "strong", effectiveProvider ?? "", effectiveId ?? "", next));
|
||||||
};
|
};
|
||||||
window.addEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
window.addEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
||||||
return () => window.removeEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
return () => window.removeEventListener("lh:kbd-cycle-thinking", onCycleThinking);
|
||||||
}, [levels, effectiveLevel, save, settings]);
|
}, [levels, effectiveLevel, effectiveProvider, effectiveId, models, save]);
|
||||||
|
|
||||||
// Selecting a model (click and Enter share one path): keep the
|
// Selecting a model (click and Enter share one path): keep the
|
||||||
// thinking level only when the new model supports it — otherwise
|
// thinking level only when the new model supports it — otherwise
|
||||||
// drop it (config fallback clamps honestly; a carry-over would 400).
|
// drop it (a carry-over would 400 at the server's catalog gate).
|
||||||
// Replace-whole discipline: spread the current settings — a model pick
|
|
||||||
// must not silently clear a sibling override (graphContextTokens).
|
|
||||||
const pickModel = (m: ModelCatalogEntry) => {
|
const pickModel = (m: ModelCatalogEntry) => {
|
||||||
const nextLevel =
|
const nextLevel =
|
||||||
effectiveLevel !== undefined && m.supportedLevels.includes(effectiveLevel)
|
effectiveLevel !== undefined && m.supportedLevels.includes(effectiveLevel) ? effectiveLevel : undefined;
|
||||||
? effectiveLevel
|
void save(composeSlotModel(models, "strong", m.provider, m.id, nextLevel ?? ""));
|
||||||
: undefined;
|
|
||||||
void save({ ...(settings ?? {}), model: { provider: m.provider, id: m.id }, thinkingLevel: nextLevel });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef} className="relative flex items-center gap-1.5" data-testid="model-control">
|
<div ref={containerRef} className="relative flex items-center gap-1.5" data-testid="model-control">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-testid="stats-model"
|
data-testid="stats-model"
|
||||||
onClick={() => {
|
onClick={() => openMenu("model")}
|
||||||
setOpen((o) => (o === "model" ? null : "model"));
|
|
||||||
setError(null);
|
|
||||||
}}
|
|
||||||
aria-expanded={open === "model"}
|
aria-expanded={open === "model"}
|
||||||
title="Conversation model — applies next turn"
|
title="Strong tier model (prober + teacher) — set app-wide"
|
||||||
className="flex items-center gap-1.5 rounded-full border border-border/60 bg-card/70 px-2.5 py-1 transition-colors hover:border-border hover:bg-muted"
|
className="flex items-center gap-1.5 rounded-full border border-border/60 bg-card/70 px-2.5 py-1 transition-colors hover:border-border hover:bg-muted"
|
||||||
>
|
>
|
||||||
<span className="text-card-foreground">{effectiveId ? prettyModel(effectiveId) : "—"}</span>
|
<span className="text-card-foreground">{effectiveId ? prettyModel(effectiveId) : "—"}</span>
|
||||||
<span aria-hidden className="text-xs text-muted-foreground">▾</span>
|
<span aria-hidden className="text-xs text-muted-foreground">▾</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-testid="stats-thinking"
|
data-testid="stats-thinking"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// No model yet (noDefaultModel first boot) → nothing to set a
|
// No model picked → nothing to set a level FOR: the click
|
||||||
// level FOR: the click is a no-op, never an empty menu.
|
// is a no-op, never an empty menu.
|
||||||
if (entry === undefined) return;
|
if (entry === undefined) return;
|
||||||
setOpen((o) => (o === "thinking" ? null : "thinking"));
|
openMenu("thinking");
|
||||||
setError(null);
|
|
||||||
}}
|
}}
|
||||||
aria-expanded={open === "thinking"}
|
aria-expanded={open === "thinking"}
|
||||||
title="Thinking level — applies next turn"
|
title="Strong tier thinking level — set app-wide"
|
||||||
className="flex items-center gap-1.5 rounded-full border border-border/60 bg-card/70 px-2.5 py-1 transition-colors hover:border-border hover:bg-muted"
|
className="flex items-center gap-1.5 rounded-full border border-border/60 bg-card/70 px-2.5 py-1 transition-colors hover:border-border hover:bg-muted"
|
||||||
>
|
>
|
||||||
{/* Just the level — the button reads like the model button reads
|
{/* Just the level — the button reads like the model button reads
|
||||||
@@ -243,7 +249,8 @@ export function ModelControl({
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* The shared dropdown body (extracted 2026-09-20): the agent
|
{/* The shared dropdown body (extracted 2026-09-20): the agent
|
||||||
settings' role selects use the exact same one. */}
|
settings' slot selects and the setup dialog use the exact same
|
||||||
|
one. */}
|
||||||
{open === "model" && (
|
{open === "model" && (
|
||||||
<div
|
<div
|
||||||
data-testid="model-menu"
|
data-testid="model-menu"
|
||||||
@@ -253,8 +260,13 @@ export function ModelControl({
|
|||||||
<ModelMenuList
|
<ModelMenuList
|
||||||
models={catalog?.models}
|
models={catalog?.models}
|
||||||
effectiveId={effectiveId}
|
effectiveId={effectiveId}
|
||||||
|
effectiveProvider={effectiveProvider}
|
||||||
onPick={pickModel}
|
onPick={pickModel}
|
||||||
footer="Applies to the next turn · background agents stay config-pinned"
|
footer={
|
||||||
|
catalog && catalog.models.length === 0
|
||||||
|
? "No models — add a provider key in Keys"
|
||||||
|
: "Strong tier — runs prober + teacher, app-wide"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -267,7 +279,9 @@ export function ModelControl({
|
|||||||
<ThinkingMenuList
|
<ThinkingMenuList
|
||||||
levels={catalog ? levels : []}
|
levels={catalog ? levels : []}
|
||||||
effectiveLevel={effectiveLevel}
|
effectiveLevel={effectiveLevel}
|
||||||
onPick={(level) => void save({ ...(settings ?? {}), thinkingLevel: level as ChatSettings["thinkingLevel"] })}
|
onPick={(level) =>
|
||||||
|
void save(composeSlotModel(models, "strong", effectiveProvider ?? "", effectiveId ?? "", level as ThinkingLevel))
|
||||||
|
}
|
||||||
empty={catalog ? (effectiveId ? `${prettyModel(effectiveId)} has no thinking levels.` : "Pick a model first.") : "Loading…"}
|
empty={catalog ? (effectiveId ? `${prettyModel(effectiveId)} has no thinking levels.` : "Pick a model first.") : "Loading…"}
|
||||||
footer="Levels this model actually supports"
|
footer="Levels this model actually supports"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -125,10 +125,6 @@ export function DraftShell({
|
|||||||
<StatsBar
|
<StatsBar
|
||||||
dictationSlot={<DictationBar dictation={dictation} />}
|
dictationSlot={<DictationBar dictation={dictation} />}
|
||||||
turns={[]}
|
turns={[]}
|
||||||
chatId=""
|
|
||||||
noDefaultModel
|
|
||||||
settings={settings}
|
|
||||||
onSettingsSaved={onSettingsSaved}
|
|
||||||
// The session-data slot (owner, 2026-09-15): pre-chat the left
|
// The session-data slot (owner, 2026-09-15): pre-chat the left
|
||||||
// side is free — the knowledge-context budget lives exactly
|
// side is free — the knowledge-context budget lives exactly
|
||||||
// where session data will sit once a session exists.
|
// where session data will sit once a session exists.
|
||||||
@@ -161,11 +157,10 @@ export function NewSession({
|
|||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
// THE default settings (owner, 2026-09-18): this surface and the home
|
// THE default settings (owner, 2026-09-18): this surface and the home
|
||||||
// topic dock ARE the settings page for the default model — no baked-in
|
// topic dock carries only the knowledge-context budget now (fix
|
||||||
// default exists; the user's last choice (server-rendered in via
|
// wave): the model pills ARE the strong slot (PUT /api/settings/models,
|
||||||
// initialSettings, shared with home through data/default-settings.json)
|
// app-wide) — the per-chat model pick is retired. saveDraft still
|
||||||
// IS the default. ModelControl with an empty chatId never PUTs — it
|
// lifts the context budget so it rides the session POST.
|
||||||
// hands the choice up; it still rides the session POST then PUT-on-create.
|
|
||||||
const { settings, save: saveDraft } = useDefaultSettings(initialSettings);
|
const { settings, save: saveDraft } = useDefaultSettings(initialSettings);
|
||||||
|
|
||||||
// First-run gate (model-slots wave, owner 2026-09-20): the send
|
// First-run gate (model-slots wave, owner 2026-09-20): the send
|
||||||
|
|||||||
@@ -388,12 +388,16 @@ export function AgentSection({
|
|||||||
.then((body: { prober: SegmentInfo[]; teacher: SegmentInfo[] }) => setPrompts(body));
|
.then((body: { prober: SegmentInfo[]; teacher: SegmentInfo[] }) => setPrompts(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The pinned Default row — clears this control's override (absent key
|
/** The "—" row — THINKING menus only: clears the thinking pin (the
|
||||||
* = the factory pin). Same row language as the shared menu's list rows. */
|
* slot keeps its model; the tier's resolved budget takes over). Model
|
||||||
const defaultRow = (active: boolean, onPick: () => void) => (
|
* menus carry no such row — unpicking a model would re-arm the
|
||||||
|
* first-run gate, and a "default" model is not a thing in this app
|
||||||
|
* (owner, fix wave: no factory fallback is ever presented as a
|
||||||
|
* choice; an unpicked slot just reads "—"). */
|
||||||
|
const noneRow = (active: boolean, onPick: () => void) => (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-testid="menu-default"
|
data-testid="menu-none"
|
||||||
onClick={onPick}
|
onClick={onPick}
|
||||||
className={`flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-muted ${
|
className={`flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-muted ${
|
||||||
active ? "bg-muted/60 text-card-foreground" : "text-card-foreground"
|
active ? "bg-muted/60 text-card-foreground" : "text-card-foreground"
|
||||||
@@ -514,10 +518,12 @@ export function AgentSection({
|
|||||||
const modelId = override?.model?.id ?? "";
|
const modelId = override?.model?.id ?? "";
|
||||||
const provider = override?.model?.provider ?? "";
|
const provider = override?.model?.provider ?? "";
|
||||||
const thinking = override?.thinkingLevel ?? "";
|
const thinking = override?.thinkingLevel ?? "";
|
||||||
// The tier's resolved pin (override → factory): the Default
|
// The tier's resolved pin is machinery only now (owner, fix
|
||||||
// hint names it; the thinking list resolves from its levels.
|
// wave): the UI never names the factory fallback — the hint
|
||||||
|
// carries the roster, the triggers read "—" when unpicked — but
|
||||||
|
// the pin still governs the thinking level LIST when no override
|
||||||
|
// names a model to read levels from.
|
||||||
const pin = slots?.[slot];
|
const pin = slots?.[slot];
|
||||||
const defaultName = pin ? prettyModel(pin.model.id) : "config pin";
|
|
||||||
// The model whose levels govern the thinking list: the
|
// The model whose levels govern the thinking list: the
|
||||||
// override, else the resolved pin (when it's in the federated
|
// override, else the resolved pin (when it's in the federated
|
||||||
// catalog); the standard ladder as the last fallback.
|
// catalog); the standard ladder as the last fallback.
|
||||||
@@ -532,7 +538,7 @@ export function AgentSection({
|
|||||||
<SettingsRow
|
<SettingsRow
|
||||||
key={slot}
|
key={slot}
|
||||||
label={SLOT_META[slot].label}
|
label={SLOT_META[slot].label}
|
||||||
hint={`${SLOT_META[slot].roster} · default: ${defaultName}`}
|
hint={SLOT_META[slot].roster}
|
||||||
testid={`slot-row-${slot}`}
|
testid={`slot-row-${slot}`}
|
||||||
>
|
>
|
||||||
{/* The anchor for the outside-click contract is the
|
{/* The anchor for the outside-click contract is the
|
||||||
@@ -543,7 +549,7 @@ export function AgentSection({
|
|||||||
>
|
>
|
||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
value={modelId ? prettyModel(modelId) : ""}
|
value={modelId ? prettyModel(modelId) : ""}
|
||||||
emptyLabel="Default"
|
emptyLabel="—"
|
||||||
ariaLabel={`${SLOT_META[slot].label} model`}
|
ariaLabel={`${SLOT_META[slot].label} model`}
|
||||||
testid={`slot-model-${slot}`}
|
testid={`slot-model-${slot}`}
|
||||||
open={thisMenuOpen === "model"}
|
open={thisMenuOpen === "model"}
|
||||||
@@ -552,7 +558,7 @@ export function AgentSection({
|
|||||||
/>
|
/>
|
||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
value={thinking}
|
value={thinking}
|
||||||
emptyLabel="Default"
|
emptyLabel="—"
|
||||||
ariaLabel={`${SLOT_META[slot].label} thinking`}
|
ariaLabel={`${SLOT_META[slot].label} thinking`}
|
||||||
testid={`slot-thinking-${slot}`}
|
testid={`slot-thinking-${slot}`}
|
||||||
open={thisMenuOpen === "thinking"}
|
open={thisMenuOpen === "thinking"}
|
||||||
@@ -565,17 +571,10 @@ export function AgentSection({
|
|||||||
testid={`slot-model-menu-${slot}`}
|
testid={`slot-model-menu-${slot}`}
|
||||||
menuClass="flex w-[22rem] flex-col rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
menuClass="flex w-[22rem] flex-col rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
||||||
>
|
>
|
||||||
{defaultRow(
|
|
||||||
modelId === "",
|
|
||||||
() => {
|
|
||||||
onModelsChange(composeSlotModel(models, slot, "", "", thinking));
|
|
||||||
setOpenMenu(null);
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
<ModelMenuList
|
<ModelMenuList
|
||||||
models={slotCatalog ?? undefined}
|
models={slotCatalog ?? undefined}
|
||||||
effectiveId={modelId || pin?.model.id}
|
effectiveId={modelId}
|
||||||
effectiveProvider={provider || pin?.model.provider}
|
effectiveProvider={provider}
|
||||||
onPick={(entry) => {
|
onPick={(entry) => {
|
||||||
onModelsChange(composeSlotModel(models, slot, entry.provider, entry.id, thinking));
|
onModelsChange(composeSlotModel(models, slot, entry.provider, entry.id, thinking));
|
||||||
setOpenMenu(null);
|
setOpenMenu(null);
|
||||||
@@ -594,7 +593,7 @@ export function AgentSection({
|
|||||||
testid={`slot-thinking-menu-${slot}`}
|
testid={`slot-thinking-menu-${slot}`}
|
||||||
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
||||||
>
|
>
|
||||||
{defaultRow(
|
{noneRow(
|
||||||
thinking === "",
|
thinking === "",
|
||||||
() => {
|
() => {
|
||||||
onModelsChange(composeSlotModel(models, slot, provider, modelId, ""));
|
onModelsChange(composeSlotModel(models, slot, provider, modelId, ""));
|
||||||
|
|||||||
@@ -29,24 +29,10 @@ import { ModelControl } from "@/components/model-picker";
|
|||||||
*/
|
*/
|
||||||
export function StatsBar({
|
export function StatsBar({
|
||||||
turns,
|
turns,
|
||||||
chatId,
|
|
||||||
settings,
|
|
||||||
onSettingsSaved,
|
|
||||||
leftSlot,
|
leftSlot,
|
||||||
dictationSlot,
|
dictationSlot,
|
||||||
noDefaultModel,
|
|
||||||
}: {
|
}: {
|
||||||
turns: TurnUsage[];
|
turns: TurnUsage[];
|
||||||
chatId: string;
|
|
||||||
settings?: ChatSettings;
|
|
||||||
onSettingsSaved: (settings: ChatSettings) => void;
|
|
||||||
/** Default-surfaces only (owner, 2026-09-18): there is NO baked-in
|
|
||||||
* default model — BYOK first boot shows "no model" until the user
|
|
||||||
* picks one, and that pick IS the default from then on. Chat surfaces
|
|
||||||
* keep the catalog-default fallback (the engine runs the config pin
|
|
||||||
* when a session record has no override — the control shows what will
|
|
||||||
* actually run). */
|
|
||||||
noDefaultModel?: boolean;
|
|
||||||
/** Pre-chat only: replaces the (empty) session-data summary — home and
|
/** Pre-chat only: replaces the (empty) session-data summary — home and
|
||||||
* the /chat/new draft mount the knowledge-context slider here. */
|
* the /chat/new draft mount the knowledge-context slider here. */
|
||||||
leftSlot?: ReactNode;
|
leftSlot?: ReactNode;
|
||||||
@@ -178,13 +164,7 @@ export function StatsBar({
|
|||||||
{/* The model + thinking control — one controller for the conversation
|
{/* The model + thinking control — one controller for the conversation
|
||||||
agents (prober/teacher); the record's `turns` above still folds
|
agents (prober/teacher); the record's `turns` above still folds
|
||||||
the ACTUAL models billed, regardless of what the picker says. */}
|
the ACTUAL models billed, regardless of what the picker says. */}
|
||||||
<ModelControl
|
<ModelControl />
|
||||||
chatId={chatId}
|
|
||||||
settings={settings}
|
|
||||||
onSaved={onSettingsSaved}
|
|
||||||
fallbackModelId={lastModel}
|
|
||||||
noDefaultModel={noDefaultModel}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
* The model catalog's server surface (model-control wave, 2026-09-12):
|
* The model catalog's server surface (model-control wave, 2026-09-12;
|
||||||
* pi-ai's shipped OpenRouter catalog projected to client-safe DTOs for the
|
* federated since the model-slots wave, 2026-09-20): pi-ai's catalog for
|
||||||
* picker (GET /api/models), plus the validation gate for per-chat settings
|
* every KEYED provider, projected to client-safe DTOs for the picker (GET
|
||||||
* (PUT /api/chats/[id]/settings).
|
* /api/models), plus the validation gate for settings writes (PUT
|
||||||
|
* /api/settings/* — the per-chat settings PUT is retired from the UI;
|
||||||
|
* legacy records' per-chat overrides still resolve server-side).
|
||||||
*
|
*
|
||||||
* pi-ai owns ALL the data: the catalog (id/name/cost/context/modality/
|
* pi-ai owns ALL the data: the catalog (id/name/cost/context/modality/
|
||||||
* thinkingLevelMap) and the per-model thinking truth
|
* thinkingLevelMap) and the per-model thinking truth
|
||||||
* (getSupportedThinkingLevels / clampThinkingLevel). This module only
|
* (getSupportedThinkingLevels / clampThinkingLevel). This module only
|
||||||
* projects and validates — no second registry to drift out of sync.
|
* projects and validates — no second registry to drift out of sync.
|
||||||
*
|
*
|
||||||
* Multi-provider future: `getModels()` is called per configured provider,
|
* Federation: `getModels()` is called per keyed provider (federated, the
|
||||||
* so a second provider (pi-ai ships ~30) appears in the picker by adding
|
* model-slots wave), so a provider appears in the picker exactly when its
|
||||||
* it to piModels() in src/agent/models.ts — nothing here changes.
|
* key is present — piModels() in src/agent/models.ts owns the provider
|
||||||
|
* set; nothing here changes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getSupportedThinkingLevels, type Api, type Model } from "@earendil-works/pi-ai";
|
import { getSupportedThinkingLevels, type Api, type Model } from "@earendil-works/pi-ai";
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ describe("SettingsDialog (the designed surface, SSR)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("AgentSection (thin SSR)", () => {
|
describe("AgentSection (thin SSR)", () => {
|
||||||
it("renders the three model SLOT rows (slots-only, owner ruling 2026-09-20), Default-triggered dropdowns", () => {
|
it("renders the three model SLOT rows (slots-only, fix wave: unpicked reads —, no Default option)", () => {
|
||||||
const html = renderToStaticMarkup(<AgentSection agent={undefined} models={undefined} onSectionChange={() => {}} onModelsChange={() => {}} />);
|
const html = renderToStaticMarkup(<AgentSection agent={undefined} models={undefined} onSectionChange={() => {}} onModelsChange={() => {}} />);
|
||||||
for (const slot of ["strong", "cheap", "vision"]) {
|
for (const slot of ["strong", "cheap", "vision"]) {
|
||||||
assert.ok(html.includes(`data-testid="slot-row-${slot}"`), slot);
|
assert.ok(html.includes(`data-testid="slot-row-${slot}"`), slot);
|
||||||
@@ -70,7 +70,12 @@ describe("AgentSection (thin SSR)", () => {
|
|||||||
// the roster hint rides every row
|
// the roster hint rides every row
|
||||||
assert.ok(html.includes("Prober + Teacher") || slot !== "strong", "strong roster");
|
assert.ok(html.includes("Prober + Teacher") || slot !== "strong", "strong roster");
|
||||||
}
|
}
|
||||||
assert.equal((html.match(/>Default<\/span>/g) ?? []).length, 6, "three slots × two Default triggers");
|
// Fix wave: no Default anywhere — an unpicked slot reads "—"
|
||||||
|
// (the owner's no-factory-fallback language), and no menu
|
||||||
|
// carries a Default row (menu-default testid is retired).
|
||||||
|
assert.equal((html.match(/>Default<\/span>/g) ?? []).length, 0, "no Default trigger");
|
||||||
|
assert.ok(!html.includes('data-testid="menu-default"'), "no Default row");
|
||||||
|
assert.equal((html.match(/>—<\/span>/g) ?? []).length, 6, "three slots × two — triggers");
|
||||||
// the per-role rows are GONE (slots-only)
|
// the per-role rows are GONE (slots-only)
|
||||||
for (const role of ["researcher", "demoBuilder", "visualMaker"]) {
|
for (const role of ["researcher", "demoBuilder", "visualMaker"]) {
|
||||||
assert.ok(!html.includes(`data-testid="role-row-${role}"`), `${role} retired`);
|
assert.ok(!html.includes(`data-testid="role-row-${role}"`), `${role} retired`);
|
||||||
|
|||||||
@@ -24,12 +24,10 @@ function turn(over: Partial<TurnUsage> = {}): TurnUsage {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const SETTINGS_STUB = (_s: ChatSettings) => {};
|
|
||||||
|
|
||||||
describe("stats bar", () => {
|
describe("stats bar", () => {
|
||||||
it("renders — everywhere when the record has no turns yet (doctrine)", () => {
|
it("renders — everywhere when the record has no turns yet (doctrine)", () => {
|
||||||
const html = renderToStaticMarkup(
|
const html = renderToStaticMarkup(
|
||||||
<StatsBar turns={[]} chatId="chat_x" onSettingsSaved={SETTINGS_STUB} />,
|
<StatsBar turns={[]} />,
|
||||||
);
|
);
|
||||||
assert.match(html, /data-testid="stats-bar"/);
|
assert.match(html, /data-testid="stats-bar"/);
|
||||||
assert.match(html, /data-testid="stats-context">—</);
|
assert.match(html, /data-testid="stats-context">—</);
|
||||||
@@ -47,7 +45,7 @@ describe("stats bar", () => {
|
|||||||
|
|
||||||
it("folds context + cost from the turns log (core/prices, no local math)", () => {
|
it("folds context + cost from the turns log (core/prices, no local math)", () => {
|
||||||
const html = renderToStaticMarkup(
|
const html = renderToStaticMarkup(
|
||||||
<StatsBar turns={[turn(), turn()]} chatId="chat_x" onSettingsSaved={SETTINGS_STUB} />,
|
<StatsBar turns={[turn(), turn()]} />,
|
||||||
);
|
);
|
||||||
// last turn's last call: 10k in + 1k out = 11k; pi catalog limit
|
// last turn's last call: 10k in + 1k out = 11k; pi catalog limit
|
||||||
// 1_048_576 → "1M" (tables regenerated from pi-ai's catalog)
|
// 1_048_576 → "1M" (tables regenerated from pi-ai's catalog)
|
||||||
@@ -55,14 +53,15 @@ describe("stats bar", () => {
|
|||||||
// pi catalog price 0.075/0.25 per 1M: each turn 10k×0.075 + 1k×0.25
|
// pi catalog price 0.075/0.25 per 1M: each turn 10k×0.075 + 1k×0.25
|
||||||
// = $0.001 → two = $0.0020
|
// = $0.001 → two = $0.0020
|
||||||
assert.match(html, /data-testid="stats-cost">\$0\.0020</);
|
assert.match(html, /data-testid="stats-cost">\$0\.0020</);
|
||||||
// model button label falls back to the last turn's actual model
|
// model button label: SSR (record fetch not run yet) reads "—" —
|
||||||
// (the catalog + settings are what drive it once loaded)
|
// the strong slot arrives client-side via GET /api/settings; the
|
||||||
assert.match(html, /data-testid="stats-model"[^>]*>\s*<span[^>]*>Glm 5\.3 Flash<\/span>/);
|
// turn log below still folds the ACTUAL models billed
|
||||||
|
assert.match(html, /data-testid="stats-model"[^>]*>\s*<span[^>]*>—<\/span>/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows — for cost when every turn is unpriceable, never a fake $0", () => {
|
it("shows — for cost when every turn is unpriceable, never a fake $0", () => {
|
||||||
const html = renderToStaticMarkup(
|
const html = renderToStaticMarkup(
|
||||||
<StatsBar turns={[turn({ model: "nope/unknown" })]} chatId="chat_x" onSettingsSaved={SETTINGS_STUB} />,
|
<StatsBar turns={[turn({ model: "nope/unknown" })]} />,
|
||||||
);
|
);
|
||||||
assert.match(html, /data-testid="stats-cost">—</);
|
assert.match(html, /data-testid="stats-cost">—</);
|
||||||
// unknown model also kills the context limit
|
// unknown model also kills the context limit
|
||||||
|
|||||||
Reference in New Issue
Block a user