2026-09-19 18:26:25 +03:00
|
|
|
"use client";
|
|
|
|
|
/**
|
2026-09-22 13:54:28 +03:00
|
|
|
* The Agent section (settings-app wave): the THREE MODEL SLOTS, the tool
|
|
|
|
|
* toggles + the search-engine preference, and the prompt override
|
|
|
|
|
* switches — three GROUPS (owner, 2026-09-20: clear separation — Models /
|
|
|
|
|
* Tools / System prompts).
|
2026-09-19 21:59:30 +03:00
|
|
|
*
|
2026-09-22 13:54:28 +03:00
|
|
|
* Model slots (model-slots wave, 2026-09-20, owner ruling: SLOTS ONLY —
|
|
|
|
|
* the six per-role rows disappeared; per-role overrides remain in the
|
|
|
|
|
* schema for a future advanced surface): Strong = Prober + Teacher, Cheap
|
|
|
|
|
* = the five workhorse roles, Vision = Visual maker + PDF reader. Each
|
|
|
|
|
* slot row carries the shared dropdown (fuzzy search, arrow-walk, Enter
|
|
|
|
|
* pick — ModelMenuList/ThinkingMenuList from ./model-menu.tsx) over the
|
|
|
|
|
* FEDERATED catalog (/api/models serves only keyed providers, fresh per
|
|
|
|
|
* call — saving a key in Keys immediately widens this picker). The
|
|
|
|
|
* vision slot filters to image-capable models (Model.input). The slots
|
|
|
|
|
* live in the `models` settings section (PUT /api/settings/models — slot
|
|
|
|
|
* pins are engine-level, not per-chat); the rest of the section writes
|
|
|
|
|
* the `agent` section as before. Resolution per tier: slot override →
|
|
|
|
|
* factory pin (GET /api/models' `slots` — resolved, cannot drift from
|
|
|
|
|
* what runs). The Default row clears the slot override; a stored id stays
|
|
|
|
|
* VISIBLE even when its provider's key lapsed out of the catalog — a
|
|
|
|
|
* trigger showing "Default" over a live override would lie about the
|
|
|
|
|
* record.
|
|
|
|
|
*
|
|
|
|
|
* Search engine (search wave, 2026-09-20, owner: no default — an engine
|
|
|
|
|
* is live iff its key is present; with a key the engine AUTO-activates,
|
|
|
|
|
* the explicit choice is only a preference between live engines): a row
|
|
|
|
|
* in the Tools group, Tavily / Brave via the same shared-menu look, with
|
|
|
|
|
* the live reason line from /api/search. No engine key at all → the row
|
|
|
|
|
* grays whole-row (a choice without a key would only BLOCK the other
|
|
|
|
|
* engine's auto-activation).
|
2026-09-19 18:26:25 +03:00
|
|
|
*
|
|
|
|
|
* Tools — the owner's final list (2026-09-19): research, demo, visual, pdf.
|
|
|
|
|
* Absent key = enabled in the schema; the UI writes explicit booleans for
|
|
|
|
|
* all four (simpler to reason about, sanitize-equivalent).
|
|
|
|
|
*
|
2026-09-25 19:00:11 +03:00
|
|
|
* Prompts: GET /api/settings/prompts segments — THREE SECTIONS in the
|
|
|
|
|
* owner's ruled order (2026-09-26 overhaul): Teacher first, Prober, then
|
|
|
|
|
* Shared LAST. The server returns per-agent lists that each INCLUDE the
|
|
|
|
|
* shared segments; sectionedSegments deduplicates them (shared chunks
|
|
|
|
|
* once, in prompt-assembly order). The row rulings: only the TOGGLE
|
|
|
|
|
* grays when there's no override file (the file name is always
|
|
|
|
|
* full-contrast); NO description line when there's no override (the empty
|
|
|
|
|
* state is clean — toggle + name); the indicator ("Your version is
|
|
|
|
|
* saved") appears ONLY when an override exists. The switch requires an
|
|
|
|
|
* override FILE (route-enforced), so a file-less toggle is disabled.
|
|
|
|
|
* The segments view re-reads on the 'lh:settings-saved' signal for the
|
|
|
|
|
* agent section — the view's enabled flags derive from the record's
|
|
|
|
|
* switches, and the 2026-09-26 state-echo bug was exactly this reader
|
|
|
|
|
* missing (the toggle painted its old state until a remount re-fetched).
|
2026-09-19 18:26:25 +03:00
|
|
|
*/
|
|
|
|
|
|
2026-09-22 21:55:18 +03:00
|
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
2026-09-22 16:56:44 +03:00
|
|
|
import { MenuShell } from "@/components/menu-shell";
|
2026-09-22 21:55:18 +03:00
|
|
|
import { useSettingsSaved } from "@/components/settings-signal";
|
2026-09-22 22:05:27 +03:00
|
|
|
import { defaultOrderLevel, populateLevel } from "@/components/thinking-default";
|
2026-09-19 22:28:57 +03:00
|
|
|
import type React from "react";
|
2026-09-22 13:54:28 +03:00
|
|
|
import {
|
|
|
|
|
MODEL_SLOTS,
|
|
|
|
|
type AgentSettings,
|
2026-09-23 15:57:59 +03:00
|
|
|
type GraphSettings,
|
2026-09-22 13:54:28 +03:00
|
|
|
type ModelCatalogEntry,
|
|
|
|
|
type ModelSlotName,
|
|
|
|
|
type ModelsSettings,
|
|
|
|
|
} from "@/src/core";
|
2026-09-19 18:26:25 +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 { SettingsGroup, SettingsRow, Toggle } from "./controls.tsx";
|
|
|
|
|
import { ModelMenuList, ThinkingMenuList } from "./model-menu";
|
2026-09-19 18:26:25 +03:00
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
/** One slot's display identity — the tier's roster as the row hint rides
|
|
|
|
|
* with the resolved default (owner: the hint ALWAYS names the default). */
|
|
|
|
|
const SLOT_META: Record<ModelSlotName, { label: string; roster: string }> = {
|
2026-09-25 01:52:20 +03:00
|
|
|
strong: { label: "Strong", roster: "The main model for your sessions" },
|
|
|
|
|
cheap: { label: "Cheap", roster: "The assistants that research, build demos, and grade your work" },
|
|
|
|
|
vision: { label: "Vision", roster: "The assistants that draw and read PDFs" },
|
2026-09-19 18:26:25 +03:00
|
|
|
};
|
|
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
/** The search engines this wave ships (src/core/search.ts) + their labels. */
|
|
|
|
|
const SEARCH_ENGINES = ["tavily", "brave"] as const;
|
|
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
/** The owner's final toggleable-tool list (confirm with the user before
|
|
|
|
|
* changing — the Teacher stream settled this 2026-09-19). */
|
|
|
|
|
export const TOGGLE_TOOLS = ["research", "demo", "visual", "pdf"] as const;
|
|
|
|
|
|
|
|
|
|
const THINKING_LEVELS: readonly ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
|
|
|
|
|
|
|
|
/** SegmentInfo as GET /api/settings/prompts returns it. */
|
|
|
|
|
interface SegmentInfo {
|
|
|
|
|
path: string;
|
|
|
|
|
sourceText: string;
|
|
|
|
|
overrideText: string | null;
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
shared: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
/** The GET /api/models response fields this section consumes. */
|
|
|
|
|
interface ModelsBody {
|
|
|
|
|
models: ModelCatalogEntry[];
|
2026-09-22 18:12:57 +03:00
|
|
|
/** The three tiers' RESOLVED pins (BYOK: NULL per unset tier — no
|
|
|
|
|
* factory floor) — machinery only (the thinking list fallback); the
|
|
|
|
|
* rows' displays read the record override, never a phantom pin. */
|
|
|
|
|
slots: Record<ModelSlotName, { model: { provider: string; id: string }; thinkingLevel?: string } | null>;
|
2026-09-22 13:54:28 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
/** Compose: one tool toggled, the rest of the section carried verbatim.
|
|
|
|
|
* Pure — exported for tests. */
|
|
|
|
|
export function composeTool(agent: AgentSettings | undefined, id: string, on: boolean): AgentSettings {
|
|
|
|
|
return { ...agent, tools: { ...agent?.tools, [id]: on } };
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-23 15:57:59 +03:00
|
|
|
/** Compose the prober graph-tools toggle (wave 7): its own key in the
|
|
|
|
|
* agent section — never in the tool-toggles map (owner ruling). Absent =
|
|
|
|
|
* ON (the toggle discipline); the write is explicit either way, so an
|
|
|
|
|
* explicit-off record stays visible as stored. Pure — exported for tests. */
|
|
|
|
|
export function composeGraphTools(agent: AgentSettings | undefined, on: boolean): AgentSettings {
|
|
|
|
|
return { ...agent, graphTools: { enabled: on } };
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 14:04:15 +03:00
|
|
|
/** The research tool runs on the search port — the teacher registry DROPS
|
|
|
|
|
* it when no engine is live (chat-handler's searchAvailable, the same
|
|
|
|
|
* /api/search signal the section fetches). Pure — exported for tests.
|
|
|
|
|
* Teacher-stream flag 2026-09-22: the settings row grays on the SAME
|
|
|
|
|
* signal, so the row and the actual registry availability can never
|
|
|
|
|
* disagree. `search === null` (loading/failed) grays NOTHING. */
|
|
|
|
|
export function researchToolUnavailable(
|
|
|
|
|
toolId: string,
|
|
|
|
|
search: { available: boolean } | null,
|
|
|
|
|
): boolean {
|
|
|
|
|
return toolId === "research" && search !== null && !search.available;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
/** Compose: one slot's model/thinking override. Empty model = absent
|
|
|
|
|
* override (Default — falls to the factory pin); empty thinking = the
|
|
|
|
|
* tier keeps its resolved thinking budget. Per-field independence, same
|
|
|
|
|
* as the schema's ModelSlot. Pure — exported for tests. */
|
|
|
|
|
export function composeSlotModel(
|
|
|
|
|
models: ModelsSettings | undefined,
|
|
|
|
|
slot: ModelSlotName,
|
|
|
|
|
provider: string,
|
|
|
|
|
id: string,
|
2026-09-19 18:26:25 +03:00
|
|
|
thinking: string,
|
2026-09-22 13:54:28 +03:00
|
|
|
): ModelsSettings {
|
|
|
|
|
const prev = models?.[slot];
|
|
|
|
|
const next = { ...models };
|
|
|
|
|
if (!provider && !id && !thinking) {
|
|
|
|
|
delete next[slot];
|
|
|
|
|
return next;
|
2026-09-19 18:26:25 +03:00
|
|
|
}
|
2026-09-22 13:54:28 +03:00
|
|
|
next[slot] = {
|
|
|
|
|
...(provider && id ? { model: { provider, id } } : prev?.model ? { model: prev.model } : {}),
|
|
|
|
|
...(thinking ? { thinkingLevel: thinking as ThinkingLevel } : {}),
|
|
|
|
|
};
|
|
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Compose: the search-engine preference. null = the explicit pin is
|
|
|
|
|
* REMOVED (auto-activation takes over — the schema's resting state).
|
|
|
|
|
* Pure — exported for tests. */
|
|
|
|
|
export function composeSearchEngine(
|
|
|
|
|
agent: AgentSettings | undefined,
|
|
|
|
|
engine: (typeof SEARCH_ENGINES)[number] | null,
|
|
|
|
|
): AgentSettings {
|
|
|
|
|
if (engine === null) {
|
|
|
|
|
if (!agent?.search) return { ...agent };
|
|
|
|
|
const { search: _drop, ...rest } = agent;
|
|
|
|
|
return { ...rest } as AgentSettings;
|
|
|
|
|
}
|
|
|
|
|
return { ...agent, search: { engine } };
|
2026-09-19 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-25 19:18:57 +03:00
|
|
|
/** The indicator under a row whose override IS the version in use (owner
|
|
|
|
|
* ruling, refined 2026-09-26: the small text states WHICH VERSION IS
|
|
|
|
|
* IN USE — "Your version is in use" when the switch is on, and NOTHING
|
|
|
|
|
* when the default composes, even if a saved override sits on disk
|
|
|
|
|
* unused. The switch's meaning becomes legible: it visibly controls
|
|
|
|
|
* this line). Exported for the pin. */
|
|
|
|
|
export const PROMPT_IN_USE_HINT = "Your version is in use";
|
2026-09-25 19:00:11 +03:00
|
|
|
|
|
|
|
|
/** One section of the prompt view — the owner's ruled order: Teacher,
|
|
|
|
|
* Prober, then Shared last. */
|
|
|
|
|
export interface PromptSection {
|
|
|
|
|
id: "teacher" | "prober" | "shared";
|
|
|
|
|
label: string;
|
|
|
|
|
/** The one header that earns a hint: "Shared" alone is not
|
|
|
|
|
* self-evident. Teacher/Prober are. */
|
|
|
|
|
hint?: string;
|
|
|
|
|
segments: SegmentInfo[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Split the server's per-agent segment lists into the owner's three
|
|
|
|
|
* sections. The server contract returns the shared segments in BOTH
|
|
|
|
|
* lists (same paths, same content) — the shared chunks are listed ONCE
|
|
|
|
|
* here (taken from the teacher list; identical by construction), in
|
|
|
|
|
* assembly order: the base file, then the shared fragments sorted. The
|
|
|
|
|
* agents' own chunks keep their lists' order — which IS the prompt
|
|
|
|
|
* assembly order (numeric-prefix filename sort). Pure — exported for
|
|
|
|
|
* tests. */
|
|
|
|
|
export function sectionedSegments(view: { prober: SegmentInfo[]; teacher: SegmentInfo[] }): PromptSection[] {
|
|
|
|
|
const own = (who: "prober" | "teacher") => view[who].filter((s) => !s.shared);
|
|
|
|
|
return [
|
|
|
|
|
{ id: "teacher", label: "Teacher", segments: own("teacher") },
|
|
|
|
|
{ id: "prober", label: "Prober", segments: own("prober") },
|
|
|
|
|
{
|
|
|
|
|
id: "shared",
|
|
|
|
|
label: "Shared",
|
|
|
|
|
hint: "Used by both agents",
|
|
|
|
|
segments: view.teacher.filter((s) => s.shared),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
/** Compose: one prompt switch. on = explicit true; off = key REMOVED
|
|
|
|
|
* (absent = off is the schema's resting state; explicit false is the
|
|
|
|
|
* same thing but noisier). Pure — tests. */
|
|
|
|
|
export function composePromptSwitch(agent: AgentSettings | undefined, path: string, on: boolean): AgentSettings {
|
|
|
|
|
const prompts = { ...agent?.prompts };
|
|
|
|
|
if (on) prompts[path] = true;
|
|
|
|
|
else delete prompts[path];
|
|
|
|
|
return { ...agent, prompts };
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 21:59:30 +03:00
|
|
|
/** The collapsed select look (owner: "the look of the collapsed menu is
|
|
|
|
|
* good") — now a button that opens the shared model-picker dropdown. */
|
|
|
|
|
function MenuTrigger({
|
|
|
|
|
value,
|
|
|
|
|
emptyLabel,
|
|
|
|
|
ariaLabel,
|
|
|
|
|
testid,
|
|
|
|
|
open,
|
|
|
|
|
onClick,
|
2026-09-19 22:28:57 +03:00
|
|
|
widthClass,
|
2026-09-22 13:54:28 +03:00
|
|
|
disabled,
|
2026-09-19 21:59:30 +03:00
|
|
|
}: {
|
|
|
|
|
value: string;
|
|
|
|
|
/** What the trigger shows when there is no override ("Default"). */
|
|
|
|
|
emptyLabel: string;
|
|
|
|
|
ariaLabel: string;
|
|
|
|
|
testid: string;
|
|
|
|
|
open: boolean;
|
|
|
|
|
onClick: () => void;
|
2026-09-19 22:28:57 +03:00
|
|
|
/** Owner (2026-09-20): the thinking trigger is FIXED at the width the
|
|
|
|
|
* Default state needs (values shifting it mid-edit shifted the row);
|
|
|
|
|
* the model trigger takes the same width as a MINIMUM — its values
|
|
|
|
|
* genuinely vary in length. */
|
|
|
|
|
widthClass: string;
|
2026-09-22 13:54:28 +03:00
|
|
|
/** The no-key search state grays the whole row; the trigger follows. */
|
|
|
|
|
disabled?: boolean;
|
2026-09-19 21:59:30 +03:00
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
aria-expanded={open}
|
|
|
|
|
data-testid={testid}
|
2026-09-22 13:54:28 +03:00
|
|
|
onClick={() => {
|
|
|
|
|
if (!disabled) onClick();
|
|
|
|
|
}}
|
|
|
|
|
className={`flex h-7 items-center gap-1 rounded-sm border border-border bg-background px-1.5 font-ui text-xs text-foreground transition-colors ${
|
|
|
|
|
disabled ? "cursor-not-allowed" : "hover:border-muted-foreground/50"
|
|
|
|
|
} ${widthClass}`}
|
2026-09-19 21:59:30 +03:00
|
|
|
>
|
2026-09-19 22:28:57 +03:00
|
|
|
<span className="min-w-0 flex-1 truncate">{value || emptyLabel}</span>
|
2026-09-19 21:59:30 +03:00
|
|
|
<span aria-hidden className="text-muted-foreground">
|
|
|
|
|
▾
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 16:56:44 +03:00
|
|
|
/* The section's dropdowns all mount the shared MenuShell (fix wave chunk
|
|
|
|
|
* B): portaled to document.body, fixed-anchored to the open trigger by
|
|
|
|
|
* testid (the section's one-ref pattern), opening DOWN with the shell's
|
|
|
|
|
* viewport cap and auto-flip. data-lh-menu rides the shell — the
|
|
|
|
|
* outside-click contract's exemption mark. */
|
2026-09-19 22:28:57 +03:00
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
export function AgentSection({
|
|
|
|
|
agent,
|
2026-09-22 13:54:28 +03:00
|
|
|
models,
|
2026-09-23 15:57:59 +03:00
|
|
|
graph,
|
2026-09-19 18:26:25 +03:00
|
|
|
onSectionChange,
|
2026-09-22 13:54:28 +03:00
|
|
|
onModelsChange,
|
2026-09-19 18:26:25 +03:00
|
|
|
}: {
|
|
|
|
|
agent: AgentSettings | undefined;
|
2026-09-22 13:54:28 +03:00
|
|
|
/** The `models` section (slot pins — engine-level, PUT /api/settings/models). */
|
|
|
|
|
models: ModelsSettings | undefined;
|
2026-09-23 15:57:59 +03:00
|
|
|
/** The `graph` section — READ ONLY here: the graphTools row composes its
|
|
|
|
|
* master switch (graph.enabled off dims + disables the row; the
|
|
|
|
|
* effective gate is server-side, per-turn fresh). */
|
|
|
|
|
graph: GraphSettings | undefined;
|
2026-09-19 18:26:25 +03:00
|
|
|
/** Writes the composed WHOLE agent section (replace-PUT discipline). */
|
|
|
|
|
onSectionChange: (next: AgentSettings) => void;
|
2026-09-22 13:54:28 +03:00
|
|
|
/** Writes the composed models section (slots — replace-PUT discipline). */
|
|
|
|
|
onModelsChange: (next: ModelsSettings) => void;
|
2026-09-19 18:26:25 +03:00
|
|
|
}) {
|
|
|
|
|
const [catalog, setCatalog] = useState<ModelCatalogEntry[] | null>(null);
|
2026-09-22 13:54:28 +03:00
|
|
|
/** The three tiers' resolved pins — GET /api/models `slots`. The rows'
|
|
|
|
|
* Default hints and thinking lists resolve from it. */
|
|
|
|
|
const [slots, setSlots] = useState<ModelsBody["slots"] | null>(null);
|
|
|
|
|
/** The live search state (/api/search) — the row's reason line. */
|
|
|
|
|
const [search, setSearch] = useState<{ available: boolean; engine: string | null; reason: string } | null>(null);
|
|
|
|
|
/** Which search engines have a key (/api/keys) — the no-keys-anywhere
|
|
|
|
|
* state grays the row; per-engine marks ride the menu rows. */
|
|
|
|
|
const [engineKeys, setEngineKeys] = useState<Partial<Record<(typeof SEARCH_ENGINES)[number], boolean>>>({});
|
2026-09-19 18:26:25 +03:00
|
|
|
const [prompts, setPrompts] = useState<{ prober: SegmentInfo[]; teacher: SegmentInfo[] } | null>(null);
|
|
|
|
|
const [openSegment, setOpenSegment] = useState<string | null>(null);
|
|
|
|
|
const [segmentDraft, setSegmentDraft] = useState<Record<string, string>>({});
|
|
|
|
|
const [segmentStatus, setSegmentStatus] = useState<string | null>(null);
|
2026-09-22 13:54:28 +03:00
|
|
|
/** One open dropdown for the whole section: which slot (or the search
|
|
|
|
|
* row), which kind. */
|
|
|
|
|
const [openMenu, setOpenMenu] = useState<{ target: ModelSlotName | "search"; kind: "model" | "thinking" | "engine" } | null>(null);
|
2026-09-19 21:59:30 +03:00
|
|
|
const menuAnchorRef = useRef<HTMLSpanElement>(null);
|
2026-09-19 18:26:25 +03:00
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
const refreshSearch = () =>
|
|
|
|
|
fetch("/api/search")
|
|
|
|
|
.then((r) => r.json())
|
|
|
|
|
.then((body: { available: boolean; engine: string | null; reason: string }) => setSearch(body))
|
|
|
|
|
.catch(() => setSearch(null));
|
|
|
|
|
|
2026-09-25 19:00:11 +03:00
|
|
|
/** Re-read the prompt-segment view — the signal seam for the
|
|
|
|
|
* 2026-09-26 state-echo fix: the view's `enabled` flags DERIVE from
|
|
|
|
|
* the settings record's agent switches (the toggle's truth lives
|
|
|
|
|
* here, not in the `agent` prop), so an agent-section write must
|
|
|
|
|
* re-read it or the toggle keeps painting its pre-write state until
|
|
|
|
|
* a remount. Keeps the last-good view on a failed re-read (the
|
|
|
|
|
* initial mount fetch below owns the loading/null state). */
|
|
|
|
|
const readPrompts = useCallback(() => {
|
|
|
|
|
fetch("/api/settings/prompts")
|
|
|
|
|
.then((r) => r.json())
|
|
|
|
|
.then((body: { prober: SegmentInfo[]; teacher: SegmentInfo[] }) => setPrompts(body))
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
// The catalog (federated: keyed providers only), the resolved slots,
|
|
|
|
|
// the prompt segments, and the search engines' key presence — one
|
2026-09-22 21:55:18 +03:00
|
|
|
// fetch each per section mount. The models read ALSO re-runs on the
|
|
|
|
|
// cross-surface signal (fix wave: another surface's write re-reads
|
|
|
|
|
// into the slot rows live).
|
|
|
|
|
const readModels = useCallback(() => {
|
2026-09-19 18:26:25 +03:00
|
|
|
fetch("/api/models")
|
|
|
|
|
.then((r) => r.json())
|
2026-09-22 13:54:28 +03:00
|
|
|
.then((body: ModelsBody) => {
|
2026-09-19 22:28:57 +03:00
|
|
|
setCatalog(body.models);
|
2026-09-22 13:54:28 +03:00
|
|
|
setSlots(body.slots);
|
2026-09-19 22:28:57 +03:00
|
|
|
})
|
2026-09-19 18:26:25 +03:00
|
|
|
.catch(() => setCatalog(null));
|
2026-09-22 21:55:18 +03:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useSettingsSaved((section) => {
|
|
|
|
|
if (section === "models") readModels();
|
2026-09-25 19:00:11 +03:00
|
|
|
// THE state-echo root cause: the prompt switches write through the
|
|
|
|
|
// agent section, but this view (the toggles' truth) never re-read —
|
|
|
|
|
// the settings-saved law (every reader re-reads) was missing this
|
|
|
|
|
// one reader.
|
|
|
|
|
if (section === "agent") readPrompts();
|
2026-09-22 21:55:18 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
readModels();
|
2026-09-19 18:26:25 +03:00
|
|
|
fetch("/api/settings/prompts")
|
|
|
|
|
.then((r) => r.json())
|
|
|
|
|
.then((body: { prober: SegmentInfo[]; teacher: SegmentInfo[] }) => setPrompts(body))
|
|
|
|
|
.catch(() => setPrompts(null));
|
2026-09-22 13:54:28 +03:00
|
|
|
fetch("/api/keys")
|
|
|
|
|
.then((r) => r.json())
|
|
|
|
|
.then((body: { keys: { id: string; present: boolean }[] }) => {
|
|
|
|
|
const present: Partial<Record<(typeof SEARCH_ENGINES)[number], boolean>> = {};
|
|
|
|
|
for (const id of SEARCH_ENGINES) {
|
|
|
|
|
const envVar = id === "tavily" ? "TAVILY_API_KEY" : "BRAVE_API_KEY";
|
|
|
|
|
present[id] = body.keys.some((k) => k.id === envVar && k.present);
|
|
|
|
|
}
|
|
|
|
|
setEngineKeys(present);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {});
|
2026-09-19 18:26:25 +03:00
|
|
|
}, []);
|
|
|
|
|
|
2026-09-22 14:04:15 +03:00
|
|
|
// The reason line re-reads /api/search AFTER an engine write lands —
|
|
|
|
|
// the write updates the `agent` prop (the dialog's record mirror), so
|
|
|
|
|
// keying on the pin avoids the race where the fetch beat the PUT and
|
|
|
|
|
// the hint contradicted the trigger it sits under.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
refreshSearch();
|
|
|
|
|
}, [agent?.search?.engine]);
|
|
|
|
|
|
2026-09-19 21:59:30 +03:00
|
|
|
// The dropdown contract (the chat model selector's, mirrored): any
|
|
|
|
|
// click outside the open menu — or an Esc — closes it. Esc is CLAIMED
|
|
|
|
|
// with stopPropagation so the settings dialog behind does NOT also
|
|
|
|
|
// close. A pointerdown on the backdrop is left for the dialog (its own
|
|
|
|
|
// click closes everything); a click inside the dialog just closes us.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (openMenu === null) return;
|
|
|
|
|
const onPointerDown = (e: PointerEvent) => {
|
|
|
|
|
const target = e.target as Node;
|
|
|
|
|
if (menuAnchorRef.current?.contains(target)) return;
|
2026-09-19 22:28:57 +03:00
|
|
|
if (target instanceof Element && target.closest("[data-lh-menu]")) return;
|
2026-09-19 21:59:30 +03:00
|
|
|
if (target instanceof Element && target.closest('[role="dialog"]')) {
|
|
|
|
|
setOpenMenu(null);
|
|
|
|
|
}
|
|
|
|
|
// else: outside the dialog — the dialog's own close handles it.
|
|
|
|
|
};
|
|
|
|
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setOpenMenu(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener("pointerdown", onPointerDown);
|
|
|
|
|
document.addEventListener("keydown", onKeyDown);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("pointerdown", onPointerDown);
|
|
|
|
|
document.removeEventListener("keydown", onKeyDown);
|
|
|
|
|
};
|
|
|
|
|
}, [openMenu]);
|
|
|
|
|
|
2026-09-25 19:18:57 +03:00
|
|
|
async function saveSegment(path: string, text: string) {
|
|
|
|
|
setSegmentStatus(null);
|
2026-09-19 18:26:25 +03:00
|
|
|
const res = await fetch(`/api/settings/prompts/${path}`, {
|
|
|
|
|
method: "PUT",
|
|
|
|
|
headers: { "content-type": "application/json" },
|
|
|
|
|
body: JSON.stringify({ text }),
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
setSegmentStatus(`Save failed: ${(await res.json().catch(() => ({}))).error ?? res.status}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-09-25 19:00:11 +03:00
|
|
|
readPrompts();
|
2026-09-25 19:18:57 +03:00
|
|
|
setSegmentStatus("Saved");
|
|
|
|
|
// Auto-on (owner ruling, refined 2026-09-26): writing an override and
|
|
|
|
|
// putting it to work are ONE action — a save with the switch off was
|
|
|
|
|
// the "did something, changed nothing" trap (the composed prompt
|
|
|
|
|
// stayed the default). The file exists now, so the ON switch the
|
|
|
|
|
// agent-section validation requires is legal; the order (file, then
|
|
|
|
|
// switch) is the safe one. Saving an edit while already on rides
|
|
|
|
|
// through — the switch write is idempotent at the record level.
|
|
|
|
|
if (agent?.prompts?.[path] !== true) {
|
|
|
|
|
onSectionChange(composePromptSwitch(agent, path, true));
|
|
|
|
|
}
|
2026-09-19 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteSegment(path: string) {
|
|
|
|
|
setSegmentStatus(null);
|
|
|
|
|
const res = await fetch(`/api/settings/prompts/${path}`, { method: "DELETE" });
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
setSegmentStatus(`Delete failed: ${res.status}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-09-25 19:18:57 +03:00
|
|
|
// Auto-off — the mirror of save's auto-on: deleting the file while
|
|
|
|
|
// the switch is on would orphan an ON record switch (the agent-section
|
|
|
|
|
// validation 400s every later write while the UI's toggle can no
|
|
|
|
|
// longer reach the OFF escape hatch — the trap found in live verify
|
|
|
|
|
// 2026-09-26). Composing the OFF here keeps the record clean.
|
|
|
|
|
if (agent?.prompts?.[path] === true) {
|
|
|
|
|
onSectionChange(composePromptSwitch(agent, path, false));
|
|
|
|
|
}
|
2026-09-25 19:00:11 +03:00
|
|
|
readPrompts();
|
2026-09-25 19:18:57 +03:00
|
|
|
setSegmentStatus("Deleted");
|
2026-09-19 18:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-22 21:55:18 +03:00
|
|
|
/** The search-engine menu row — label + the quiet live-key mark. */
|
2026-09-22 13:54:28 +03:00
|
|
|
const engineOption = (
|
|
|
|
|
id: (typeof SEARCH_ENGINES)[number] | "auto",
|
|
|
|
|
label: string,
|
|
|
|
|
active: boolean,
|
|
|
|
|
live: boolean | null,
|
|
|
|
|
onPick: () => void,
|
|
|
|
|
) => (
|
|
|
|
|
<button
|
2026-09-22 14:04:15 +03:00
|
|
|
key={id}
|
2026-09-22 13:54:28 +03:00
|
|
|
type="button"
|
|
|
|
|
data-testid={`engine-option-${id}`}
|
|
|
|
|
onClick={onPick}
|
|
|
|
|
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"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<span>{label}</span>
|
|
|
|
|
<span className="text-muted-foreground">
|
|
|
|
|
{live === null ? (active && <span aria-hidden>✓</span>) : live ? <span aria-hidden>✓ key</span> : <span aria-hidden>· no key</span>}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
const segmentRow = (info: SegmentInfo) => {
|
|
|
|
|
const fileExists = info.overrideText !== null;
|
|
|
|
|
const open = openSegment === info.path;
|
2026-09-25 19:18:57 +03:00
|
|
|
// The Save affordance (owner ruling, refined 2026-09-26): clickable
|
|
|
|
|
// only when there's something to save — the draft differs from
|
|
|
|
|
// what's on disk. An unchanged editor shows a grayed, inert Save
|
|
|
|
|
// (the always-active button was the "doesn't feel like it does
|
|
|
|
|
// anything" half of the report).
|
|
|
|
|
const draft = segmentDraft[info.path] ?? info.overrideText ?? "";
|
|
|
|
|
const dirty = draft !== (info.overrideText ?? "");
|
2026-09-19 18:26:25 +03:00
|
|
|
return (
|
|
|
|
|
<div key={info.path} data-testid={`prompt-segment-${info.path}`}>
|
|
|
|
|
<SettingsRow
|
|
|
|
|
label={info.path}
|
2026-09-25 19:18:57 +03:00
|
|
|
// Overhaul rulings (2026-09-26, refined): the small text
|
|
|
|
|
// states WHICH VERSION IS IN USE — nothing when the
|
|
|
|
|
// default composes (even with a saved override sitting
|
|
|
|
|
// on disk unused), "Your version is in use" when the
|
|
|
|
|
// switch is on. The switch's meaning becomes legible
|
|
|
|
|
// through this line.
|
|
|
|
|
hint={info.enabled ? PROMPT_IN_USE_HINT : undefined}
|
2026-09-19 18:26:25 +03:00
|
|
|
testid={`prompt-row-${info.path}`}
|
|
|
|
|
>
|
2026-09-25 19:00:11 +03:00
|
|
|
{/* Graying ruling: ONLY the toggle dims without an
|
|
|
|
|
override file — the file name above stays
|
|
|
|
|
full-contrast (the whole-row dim is dead). */}
|
|
|
|
|
<span className={fileExists ? undefined : "opacity-40"}>
|
|
|
|
|
<Toggle
|
|
|
|
|
checked={info.enabled}
|
|
|
|
|
disabled={!fileExists}
|
|
|
|
|
label={`prompt ${info.path}`}
|
|
|
|
|
onChange={(on) => onSectionChange(composePromptSwitch(agent, info.path, on))}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
2026-09-19 18:26:25 +03:00
|
|
|
</SettingsRow>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setOpenSegment(open ? null : info.path);
|
|
|
|
|
setSegmentStatus(null);
|
|
|
|
|
}}
|
|
|
|
|
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
|
|
|
|
|
>
|
|
|
|
|
{open ? "Hide text" : "Show text"}
|
|
|
|
|
</button>
|
|
|
|
|
{open && (
|
|
|
|
|
<div className="mt-1 flex flex-col gap-2">
|
|
|
|
|
<div>
|
|
|
|
|
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">Source</p>
|
|
|
|
|
<textarea
|
|
|
|
|
readOnly
|
|
|
|
|
value={info.sourceText}
|
2026-09-25 01:52:20 +03:00
|
|
|
aria-label="The original instructions"
|
2026-09-19 18:26:25 +03:00
|
|
|
className="h-24 w-full resize-y rounded-sm border border-border bg-muted p-2 font-ui text-xs text-muted-foreground"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">Override</p>
|
|
|
|
|
<textarea
|
|
|
|
|
value={segmentDraft[info.path] ?? info.overrideText ?? ""}
|
|
|
|
|
onChange={(e) => setSegmentDraft({ ...segmentDraft, [info.path]: e.target.value })}
|
2026-09-25 01:52:20 +03:00
|
|
|
aria-label="Your version of the instructions"
|
|
|
|
|
placeholder="Add your own instructions…"
|
2026-09-19 18:26:25 +03:00
|
|
|
className="h-24 w-full resize-y rounded-sm border border-border bg-background p-2 font-ui text-xs text-foreground outline-none"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-09-25 19:18:57 +03:00
|
|
|
disabled={!dirty}
|
2026-09-19 18:26:25 +03:00
|
|
|
onClick={() => void saveSegment(info.path, segmentDraft[info.path] ?? "")}
|
2026-09-25 19:18:57 +03:00
|
|
|
className={
|
|
|
|
|
dirty
|
|
|
|
|
? "text-xs text-foreground underline-offset-2 hover:underline"
|
|
|
|
|
: "cursor-not-allowed text-xs text-muted-foreground/40 underline-offset-2"
|
|
|
|
|
}
|
2026-09-19 18:26:25 +03:00
|
|
|
>
|
2026-09-25 01:52:20 +03:00
|
|
|
Save
|
2026-09-19 18:26:25 +03:00
|
|
|
</button>
|
|
|
|
|
{fileExists && (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => void deleteSegment(info.path)}
|
|
|
|
|
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-red-500 hover:underline"
|
|
|
|
|
>
|
2026-09-25 01:52:20 +03:00
|
|
|
Delete
|
2026-09-19 18:26:25 +03:00
|
|
|
</button>
|
|
|
|
|
)}
|
2026-09-25 19:18:57 +03:00
|
|
|
{/* The quiet inline confirmation — next to the
|
|
|
|
|
action, not the old path-echoing line at the
|
|
|
|
|
section's bottom (production-copy: no file
|
|
|
|
|
paths in user-facing status). One editor is
|
|
|
|
|
open at a time (openSegment), so one shared
|
|
|
|
|
status reads unambiguously. */}
|
|
|
|
|
{segmentStatus && (
|
|
|
|
|
<p className="text-xs text-muted-foreground/70" data-testid="segment-status">
|
|
|
|
|
{segmentStatus}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2026-09-19 18:26:25 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-09-22 13:54:28 +03:00
|
|
|
|
|
|
|
|
|
2026-09-19 18:26:25 +03:00
|
|
|
return (
|
|
|
|
|
<>
|
2026-09-19 21:59:30 +03:00
|
|
|
<SettingsGroup label="Models" testid="group-models">
|
2026-09-22 13:54:28 +03:00
|
|
|
{MODEL_SLOTS.map((slot) => {
|
|
|
|
|
const override = models?.[slot];
|
2026-09-19 21:59:30 +03:00
|
|
|
const modelId = override?.model?.id ?? "";
|
2026-09-22 13:54:28 +03:00
|
|
|
const provider = override?.model?.provider ?? "";
|
2026-09-19 21:59:30 +03:00
|
|
|
const thinking = override?.thinkingLevel ?? "";
|
2026-09-22 16:40:31 +03:00
|
|
|
// The tier's resolved pin is machinery only now (owner, fix
|
|
|
|
|
// 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.
|
2026-09-22 13:54:28 +03:00
|
|
|
const pin = slots?.[slot];
|
2026-09-19 22:28:57 +03:00
|
|
|
// The model whose levels govern the thinking list: the
|
2026-09-22 13:54:28 +03:00
|
|
|
// override, else the resolved pin (when it's in the federated
|
|
|
|
|
// catalog); the standard ladder as the last fallback.
|
|
|
|
|
const coord = override?.model ?? pin?.model;
|
|
|
|
|
const chosen = coord ? catalog?.find((m) => m.id === coord.id && m.provider === coord.provider) : undefined;
|
2026-09-19 21:59:30 +03:00
|
|
|
const levels = chosen ? chosen.supportedLevels : THINKING_LEVELS;
|
2026-09-22 13:54:28 +03:00
|
|
|
const thisMenuOpen = openMenu?.target === slot ? openMenu.kind : null;
|
|
|
|
|
// Vision slots pick from image-capable models only.
|
|
|
|
|
const slotCatalog =
|
|
|
|
|
slot === "vision" ? catalog?.filter((m) => m.input.includes("image")) : catalog;
|
2026-09-19 21:59:30 +03:00
|
|
|
return (
|
|
|
|
|
<SettingsRow
|
2026-09-22 13:54:28 +03:00
|
|
|
key={slot}
|
|
|
|
|
label={SLOT_META[slot].label}
|
2026-09-22 16:40:31 +03:00
|
|
|
hint={SLOT_META[slot].roster}
|
2026-09-22 13:54:28 +03:00
|
|
|
testid={`slot-row-${slot}`}
|
2026-09-19 21:59:30 +03:00
|
|
|
>
|
|
|
|
|
{/* The anchor for the outside-click contract is the
|
|
|
|
|
span holding BOTH triggers of the open menu. */}
|
|
|
|
|
<span
|
|
|
|
|
ref={thisMenuOpen ? menuAnchorRef : undefined}
|
2026-09-19 22:28:57 +03:00
|
|
|
className="relative flex items-center gap-2"
|
2026-09-19 18:26:25 +03:00
|
|
|
>
|
2026-09-19 21:59:30 +03:00
|
|
|
<MenuTrigger
|
|
|
|
|
value={modelId ? prettyModel(modelId) : ""}
|
2026-09-22 16:40:31 +03:00
|
|
|
emptyLabel="—"
|
2026-09-22 13:54:28 +03:00
|
|
|
ariaLabel={`${SLOT_META[slot].label} model`}
|
|
|
|
|
testid={`slot-model-${slot}`}
|
2026-09-19 21:59:30 +03:00
|
|
|
open={thisMenuOpen === "model"}
|
2026-09-22 13:54:28 +03:00
|
|
|
onClick={() => setOpenMenu(thisMenuOpen === "model" ? null : { target: slot, kind: "model" })}
|
2026-09-19 22:28:57 +03:00
|
|
|
widthClass="min-w-20"
|
2026-09-19 21:59:30 +03:00
|
|
|
/>
|
|
|
|
|
<MenuTrigger
|
2026-09-22 22:05:27 +03:00
|
|
|
// Legacy display (chunk 2 item 4): no stored level + a known
|
|
|
|
|
// model → the RESOLVED level (the ordering's first supported —
|
|
|
|
|
// what the engine build runs). Display-only until a pick writes.
|
|
|
|
|
value={thinking || (chosen ? defaultOrderLevel(levels) : "")}
|
2026-09-22 16:40:31 +03:00
|
|
|
emptyLabel="—"
|
2026-09-22 13:54:28 +03:00
|
|
|
ariaLabel={`${SLOT_META[slot].label} thinking`}
|
|
|
|
|
testid={`slot-thinking-${slot}`}
|
2026-09-19 21:59:30 +03:00
|
|
|
open={thisMenuOpen === "thinking"}
|
2026-09-22 13:54:28 +03:00
|
|
|
onClick={() => setOpenMenu(thisMenuOpen === "thinking" ? null : { target: slot, kind: "thinking" })}
|
2026-09-19 22:28:57 +03:00
|
|
|
widthClass="w-20"
|
2026-09-19 21:59:30 +03:00
|
|
|
/>
|
|
|
|
|
{thisMenuOpen === "model" && (
|
2026-09-22 16:56:44 +03:00
|
|
|
<MenuShell
|
|
|
|
|
preferredSide="down"
|
|
|
|
|
anchorTestid={`slot-model-${slot}`}
|
2026-09-22 13:54:28 +03:00
|
|
|
testid={`slot-model-menu-${slot}`}
|
2026-09-19 22:28:57 +03:00
|
|
|
menuClass="flex w-[22rem] flex-col rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
2026-09-19 21:59:30 +03:00
|
|
|
>
|
|
|
|
|
<ModelMenuList
|
2026-09-22 13:54:28 +03:00
|
|
|
models={slotCatalog ?? undefined}
|
2026-09-22 16:40:31 +03:00
|
|
|
effectiveId={modelId}
|
|
|
|
|
effectiveProvider={provider}
|
2026-09-19 21:59:30 +03:00
|
|
|
onPick={(entry) => {
|
2026-09-22 22:05:27 +03:00
|
|
|
// Auto-populate (chunk 2, owner: "populate everywhere"): the
|
|
|
|
|
// fresh pick writes a level — the stored one rides as-is
|
|
|
|
|
// (the write clamps server-side), else the ordering's level.
|
|
|
|
|
const next = populateLevel(thinking || undefined, entry.supportedLevels);
|
|
|
|
|
onModelsChange(composeSlotModel(models, slot, entry.provider, entry.id, next));
|
2026-09-19 21:59:30 +03:00
|
|
|
setOpenMenu(null);
|
|
|
|
|
}}
|
2026-09-22 13:54:28 +03:00
|
|
|
footer={
|
|
|
|
|
catalog && catalog.length === 0
|
|
|
|
|
? "No models — add a provider key in Keys"
|
|
|
|
|
: "Runs every agent of this tier"
|
|
|
|
|
}
|
2026-09-19 21:59:30 +03:00
|
|
|
/>
|
2026-09-22 16:56:44 +03:00
|
|
|
</MenuShell>
|
2026-09-19 18:26:25 +03:00
|
|
|
)}
|
2026-09-19 21:59:30 +03:00
|
|
|
{thisMenuOpen === "thinking" && (
|
2026-09-22 16:56:44 +03:00
|
|
|
<MenuShell
|
|
|
|
|
preferredSide="down"
|
|
|
|
|
anchorTestid={`slot-thinking-${slot}`}
|
2026-09-22 13:54:28 +03:00
|
|
|
testid={`slot-thinking-menu-${slot}`}
|
2026-09-19 22:28:57 +03:00
|
|
|
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
2026-09-19 21:59:30 +03:00
|
|
|
>
|
|
|
|
|
<ThinkingMenuList
|
|
|
|
|
levels={levels.map(String)}
|
2026-09-22 22:05:27 +03:00
|
|
|
// The ✓ sits on the RESOLVED level for legacy unset records —
|
|
|
|
|
// the same one the trigger shows.
|
|
|
|
|
effectiveLevel={thinking || (chosen ? defaultOrderLevel(levels) : undefined)}
|
2026-09-19 21:59:30 +03:00
|
|
|
onPick={(level) => {
|
2026-09-22 13:54:28 +03:00
|
|
|
onModelsChange(composeSlotModel(models, slot, provider, modelId, level));
|
2026-09-19 21:59:30 +03:00
|
|
|
setOpenMenu(null);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2026-09-22 16:56:44 +03:00
|
|
|
</MenuShell>
|
2026-09-19 21:59:30 +03:00
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</SettingsRow>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</SettingsGroup>
|
|
|
|
|
|
|
|
|
|
<SettingsGroup label="Tools" testid="group-tools">
|
2026-09-23 15:57:59 +03:00
|
|
|
{/* The prober's graph tools (wave 7, owner ruling 2026-09-23):
|
|
|
|
|
FIRST row of the group — its subject is the map, its
|
|
|
|
|
mechanism is agent capability, so it lives in Tools but
|
|
|
|
|
NOT in the tool-toggles list. Its own agent-section key
|
|
|
|
|
(agent.graphTools), the search-row hint discipline: a
|
|
|
|
|
smaller line under it explaining what it is — this
|
|
|
|
|
connects prior sessions' knowledge into new ones. */}
|
|
|
|
|
{(() => {
|
|
|
|
|
const graphOn = graph?.enabled ?? true;
|
|
|
|
|
return (
|
|
|
|
|
<SettingsRow
|
|
|
|
|
label="Graph tools"
|
2026-09-25 01:52:20 +03:00
|
|
|
hint={graphOn ? "Lets the tutor consult your knowledge map between sessions" : "Graph is disabled"}
|
2026-09-23 15:57:59 +03:00
|
|
|
testid="graph-tools-row"
|
|
|
|
|
dimmed={!graphOn}
|
|
|
|
|
>
|
|
|
|
|
<Toggle
|
|
|
|
|
checked={agent?.graphTools?.enabled ?? true}
|
|
|
|
|
disabled={!graphOn}
|
|
|
|
|
label="graph tools"
|
|
|
|
|
onChange={(on) => onSectionChange(composeGraphTools(agent, on))}
|
|
|
|
|
/>
|
|
|
|
|
</SettingsRow>
|
|
|
|
|
);
|
|
|
|
|
})()}
|
2026-09-22 14:04:15 +03:00
|
|
|
{TOGGLE_TOOLS.map((id) => {
|
|
|
|
|
// Research needs a live search engine; the row + toggle gray
|
|
|
|
|
// on the same signal the registry drops the tool on (see
|
|
|
|
|
// researchToolUnavailable). The reason rides as the hint.
|
|
|
|
|
const searchDown = researchToolUnavailable(id, search);
|
|
|
|
|
return (
|
|
|
|
|
<SettingsRow
|
|
|
|
|
key={id}
|
|
|
|
|
label={`Tool · ${id}`}
|
|
|
|
|
hint={searchDown ? search?.reason : undefined}
|
|
|
|
|
testid={`tool-row-${id}`}
|
|
|
|
|
dimmed={searchDown}
|
|
|
|
|
>
|
|
|
|
|
<Toggle
|
|
|
|
|
checked={agent?.tools?.[id] ?? true}
|
|
|
|
|
disabled={searchDown}
|
|
|
|
|
label={`tool ${id}`}
|
|
|
|
|
onChange={(on) => onSectionChange(composeTool(agent, id, on))}
|
|
|
|
|
/>
|
|
|
|
|
</SettingsRow>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2026-09-22 13:54:28 +03:00
|
|
|
{(() => {
|
|
|
|
|
const engine = agent?.search?.engine ?? null;
|
|
|
|
|
const anyKey = engineKeys.tavily === true || engineKeys.brave === true;
|
|
|
|
|
const open = openMenu?.target === "search";
|
|
|
|
|
return (
|
|
|
|
|
<SettingsRow
|
|
|
|
|
label="Search engine"
|
|
|
|
|
hint={search?.reason ?? undefined}
|
|
|
|
|
testid="search-engine-row"
|
|
|
|
|
dimmed={!anyKey}
|
|
|
|
|
>
|
|
|
|
|
<span ref={open ? menuAnchorRef : undefined} className="relative flex items-center gap-2">
|
|
|
|
|
<MenuTrigger
|
|
|
|
|
value={engine === "tavily" ? "Tavily" : engine === "brave" ? "Brave" : ""}
|
|
|
|
|
emptyLabel="Automatic"
|
|
|
|
|
ariaLabel="Search engine"
|
|
|
|
|
testid="search-engine-trigger"
|
|
|
|
|
open={open}
|
|
|
|
|
onClick={() => setOpenMenu(open ? null : { target: "search", kind: "engine" })}
|
|
|
|
|
widthClass="min-w-20"
|
|
|
|
|
disabled={!anyKey}
|
|
|
|
|
/>
|
|
|
|
|
{open && (
|
2026-09-22 16:56:44 +03:00
|
|
|
<MenuShell
|
|
|
|
|
preferredSide="down"
|
|
|
|
|
anchorTestid="search-engine-trigger"
|
2026-09-22 13:54:28 +03:00
|
|
|
testid="search-engine-menu"
|
|
|
|
|
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
|
|
|
|
|
>
|
|
|
|
|
{engineOption("auto", "Automatic", engine === null, null, () => {
|
|
|
|
|
onSectionChange(composeSearchEngine(agent, null));
|
|
|
|
|
setOpenMenu(null);
|
|
|
|
|
})}
|
|
|
|
|
{SEARCH_ENGINES.map((id) =>
|
|
|
|
|
engineOption(id, id === "tavily" ? "Tavily" : "Brave", engine === id, engineKeys[id] ?? false, () => {
|
|
|
|
|
onSectionChange(composeSearchEngine(agent, id));
|
|
|
|
|
setOpenMenu(null);
|
|
|
|
|
}),
|
|
|
|
|
)}
|
2026-09-22 16:56:44 +03:00
|
|
|
</MenuShell>
|
2026-09-22 13:54:28 +03:00
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</SettingsRow>
|
|
|
|
|
);
|
|
|
|
|
})()}
|
2026-09-19 21:59:30 +03:00
|
|
|
</SettingsGroup>
|
2026-09-19 18:26:25 +03:00
|
|
|
|
2026-09-19 21:59:30 +03:00
|
|
|
<SettingsGroup label="System prompts" testid="group-prompts">
|
|
|
|
|
{prompts === null ? (
|
|
|
|
|
<p className="text-xs text-muted-foreground/70">Loading prompt segments…</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col gap-4">
|
2026-09-25 19:00:11 +03:00
|
|
|
{/* The owner's ruled order (2026-09-26): Teacher first,
|
|
|
|
|
then Prober, then Shared LAST — shared chunks once
|
|
|
|
|
(deduplicated), each section in prompt-assembly
|
|
|
|
|
order. */}
|
|
|
|
|
{sectionedSegments(prompts).map((section) => (
|
|
|
|
|
<div key={section.id} data-testid={`prompt-section-${section.id}`}>
|
|
|
|
|
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">
|
|
|
|
|
{section.label}
|
|
|
|
|
</p>
|
|
|
|
|
{section.hint && (
|
|
|
|
|
<p className="mb-1 text-xs text-muted-foreground/60">{section.hint}</p>
|
|
|
|
|
)}
|
2026-09-19 21:59:30 +03:00
|
|
|
<div className="flex flex-col gap-2">
|
2026-09-25 19:00:11 +03:00
|
|
|
{section.segments.map((info) => segmentRow(info))}
|
2026-09-19 21:59:30 +03:00
|
|
|
</div>
|
2026-09-19 18:26:25 +03:00
|
|
|
</div>
|
2026-09-19 21:59:30 +03:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</SettingsGroup>
|
2026-09-19 18:26:25 +03:00
|
|
|
</>
|
|
|
|
|
);
|
2026-09-22 13:54:28 +03:00
|
|
|
}
|