"use client"; import { useCallback, useEffect, useState } from "react"; import { BookOpenIcon } from "lucide-react"; import { GRAPH_CONTEXT_TOKENS_DEFAULT, GRAPH_CONTEXT_TOKENS_STOPS, type ChatSettings, } from "@/src/core"; import { useSettingsSaved } from "@/components/settings-signal"; import { useSettingsDialog } from "./settings/settings-dialog.tsx"; /** * The knowledge-context budget control (vision-context-injection.md) — the * "session data" section's one input, shown where sessions START: the home * (graph) view's new-session dock and the /chat/new draft. It renders in * the StatsBar's LEFT slot — the very place session data (context/cost) * lives once a session exists, which pre-chat is free real estate (just * "—"). Input before output: the panel that will later show what the * session contributed to the graph asks first what the graph will * contribute to the session. * * A DISCRETE 6-position slider (owner, 2026-09-15): off, then powers of four * from 64 — a continuous 0–4096 dial was precision theater (a 128-token * budget is ~2 propositions). The native range input walks positions 0–5 * and maps through GRAPH_CONTEXT_TOKENS_STOPS; every stop is a real * decision. Non-stop values from a stale client snap to the nearest stop * for display. The readout shows the FULL number (no k-rounding). The * value rides ChatSettings (the same lifted settings the model picker * uses), so it persists pre-chat via the same deferred PUT. Sessions * never show this control — the injection is one-shot at session start. */ export function GraphContextControl({ value, onChange, testId = "graph-context-control", }: { value: number; onChange: (tokens: number) => void; testId?: string; }) { // Wave 6: context injection rides the embedding model — with none // configured (graph.embeddingModel null) the control is inert, so it // grays out and its hint deep-links to the Graph section's picker. // Loading renders the normal control (the searchStatus precedent: // never gray on null/unknown). Every settings save re-reads. const { open: openSettingsSection } = useSettingsDialog(); const [modelUnset, setModelUnset] = useState(false); const [known, setKnown] = useState(false); const readModel = useCallback(async () => { try { const resp = await fetch("/api/settings"); if (!resp.ok) return; const body = (await resp.json()) as { settings?: { graph?: { embeddingModel?: string | null } } }; setModelUnset(!body.settings?.graph?.embeddingModel); setKnown(true); } catch { // leave the last known state } }, []); useEffect(() => { void readModel(); }, [readModel]); useSettingsSaved(() => { void readModel(); }); if (known && modelUnset) { return (