Wave 6 chunk B: the embeddings surfaces — picker, re-embed gate, gray-outs, cost pill

- Settings ▸ Graph grows the embedding-model picker (graph-row-embedding-model):
  GET /api/models/embeddings' live-federated BYOK catalog (re-fetched on mount
  and every settings save), rows priced from EMBEDDING_PRICES ("$x.xx/1M in",
  honestly "—" when unlisted), ids shown AND stored as full colon-safe slugs
  (openrouter:liquid/…:free is never split), plus an Unset row writing null.
  Empty catalog = nothing keyed: the trigger BECOMES the deep link to Keys
  ("Add a provider key first…") — and deep-links fired while the dialog is
  open now actually switch sections (initialSection was read once at mount;
  the body follows it now — pre-existing gap, first exercised by this link).
- Re-embed gate (owner design): picking a model that differs from the stored
  one holds the write behind a confirm strip carrying the honest node count
  from GET /api/graph; zero propositions skip the strip (nothing to re-embed)
  and land directly. Unset never confirms — the port just stops resolving.
  The copy says the re-embed runs with the next background pass (the staleness
  machinery — a settings PUT alone never triggers it; no server endpoints
  were added).
- Gray-out, the searchStatus precedent: with no model configured, the ladder
  rungs Embedding/Clustering/Labeling dim + disable with a "Needs an
  embedding model" hint (master switch stays lit), and the stats-bar
  GraphContextControl swaps its slider for a dimmed deep-link button to the
  Graph section. Loading never grays; every settings save re-reads (signal).
- Cost chrome: the pipeline popover grows the Embeddings stage row
  (costs.stages.embedding, wave 6's folded stage — "— · 0 in / 0 out" until
  runs exist, same as its siblings).
- Master's ride-along: the core-barrel ChatDeleteMode comment now says two
  type-only things (it always exported both).

Gates: tsc clean, 912/912 (8 new: price lines, model-dependency predicate,
unset/set SSR dimming; 2 ladder fixtures updated to the new no-model
semantics), lint 0, build ok. Live-verified on :3001: unset deep-link →
graph section, menu pricing + colon-safety (37 options), confirm strip with
"20 propositions", Cancel keeps the record, Unset writes immediately,
in-dialog empty-catalog deep-link lands Keys, Embeddings row in the popover.
This commit is contained in:
amosblomqvist
2026-09-23 12:50:59 +03:00
parent 1c27694dbc
commit fb66606555
7 changed files with 436 additions and 10 deletions
+47
View File
@@ -1,11 +1,14 @@
"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
@@ -36,6 +39,50 @@ export function GraphContextControl({
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 (
<div
data-testid={`${testId}-needs-model`}
className="flex items-center gap-2 text-xs text-muted-foreground opacity-40"
>
<BookOpenIcon className="size-3 shrink-0" />
<button
type="button"
onClick={() => openSettingsSection("graph")}
className="underline underline-offset-2 transition-colors hover:text-foreground"
>
Graph context needs an embedding model
</button>
</div>
);
}
// Snap for display only: a legacy non-stop value shows its nearest stop
// and the next drag lands on a real one.
const stop = nearestStop(value);