feat(models): BYOK all the way down — factory pins deleted, per-need refusal gates
Owner decision 2026-09-22: 'it doesn't make sense to have any default
model configured anywhere; the application is bring your own keys.'
config.ts: MODELS deleted; ModelRole becomes an explicit 9-role union;
DEFAULT_THINKING_ORDER (medium, low, high, minimal, xhigh, max) bakes
the unset-level default — first entry the model supports; explicitly
set levels keep pi's native nearest-clamp.
core/settings-resolution: the factory layer dissolves — the chain is
role override → slot → NOTHING. resolveSettings(record) takes no
factory. Empty chains resolve to null/undefined; a thinkingLevel-only
slot is inert (stored, never run). resolveConversationSpec: chat.model
override over the strong slot, null when both empty. resolveRoleSpec
spans all nine roles for the job/extraction engines.
Refusal envelope (core/settings.ts): modelsNotConfigured(missing) —
{error, code: 'models_not_configured', missing: [slot tiers]} +
ModelsNotConfiguredError with .envelope. Per-need gates, each honest:
- chat-handler: universal turn gate (new + continuing turns) returns
503 before beginTurn — no liveness, no write-ahead persist, no graph
trigger before the gate fires.
- runner.runJob: unresolvable engine lands the job as error with the
envelope wording; no phantom loop, no result steer.
- extraction: refuseIfStagesUnconfigured throws before any stage
(turn-service info-skips so coverage retries next turn; the import
route surfaces per-file code+missing); labeler-less runs skip
cluster naming with a console line and still merge.
Write side: slot entries must carry a model — level-only slot writes
are 400s (absent slot key = clear). piEngineForSpec resolves unset
thinking levels via DEFAULT_THINKING_ORDER; piEngineFor now throws
honestly; thinkingLevelFor/modelIdFor deleted; teacher-agent, pi-run,
visual-maker, pdf-reader all read engine.level.
model-catalog: defaults/slots/rolePins null when the chain is empty
(contracts nullable) — no phantom ids in payloads. Stores drop
MODEL_PINS entirely.
Tests: pin-leaners converted to explicit injection (per-chat model
pins on scripted chats — exactly what the setup flow writes; faux
engines for agent-construction tests). New coverage: the 503 gate
envelope, the runner refusal, the extraction refusal + labeler skip.
Gates: typecheck, lint, 815/815, build.
This commit is contained in:
@@ -34,56 +34,44 @@ export const PATHS = {
|
||||
} as const;
|
||||
|
||||
// ─── Models ────────────────────────────────────────────────────────────────
|
||||
// THE single place every LLM is chosen and tuned. .env stays for secrets
|
||||
// (API keys) only — model choice and thinking budget are product tuning,
|
||||
// not deployment environment, and this section is the one place they grow.
|
||||
// `effort` is pi's thinking-level scale (off|minimal|low|medium|high|xhigh
|
||||
// |max): the per-model truth lives in pi-ai's catalog (thinkingLevelMap) —
|
||||
// getSupportedThinkingLevels(model) lists what a model actually accepts,
|
||||
// and streamSimple clamps any other value to the nearest supported one
|
||||
// (e.g. GLM-5.3-flash supports exactly low|high|max).
|
||||
// BYOK ALL THE WAY DOWN (owner, 2026-09-22): there are NO factory default
|
||||
// models. Every engine resolves from the user's model slots (settings.json
|
||||
// models section: strong/cheap/vision) over per-role/ChatSettings overrides,
|
||||
// and a chain that ends empty REFUSES honestly (503 models_not_configured).
|
||||
// .env stays for secrets (API keys) only. What remains here are ENGINE
|
||||
// CONSTRUCTION FACTS: the thinking-level scale and the default order.
|
||||
|
||||
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
||||
|
||||
export interface ModelSpec {
|
||||
/** The provider that owns the model (model slots wave, 2026-09-20):
|
||||
* pi-ai provider id. Native ids are plain strings ("glm-5.3-flash" on
|
||||
* zai); OpenRouter ids are vendor slugs ("z-ai/glm-5.3-flash"). The
|
||||
* factory pins stay OpenRouter (the BYOK default provider). */
|
||||
provider: string;
|
||||
/** The model id on that provider — must exist in pi-ai's catalog. */
|
||||
model: string;
|
||||
/** Thinking budget — what the model may spend on reasoning tokens. */
|
||||
effort: ThinkingLevel;
|
||||
}
|
||||
/** Every agent role in the app. The conversation pair (prober/teacher)
|
||||
* resolves chat.model → strong slot; background roles resolve their own
|
||||
* override → tier slot (core/settings-resolution.ts ROLE_SLOT). */
|
||||
export type ModelRole =
|
||||
| "prober"
|
||||
| "teacher"
|
||||
| "researcher"
|
||||
| "demoBuilder"
|
||||
| "visualMaker"
|
||||
| "pdfReader"
|
||||
| "extractor"
|
||||
| "auditor"
|
||||
| "labeler";
|
||||
|
||||
export const MODELS = {
|
||||
/** The prober (agent A) — edge-bracketing questions; keep it lively and adaptive. */
|
||||
prober: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
/** The teacher (agent B) — planning + streaming, lesson-facing: smart, but keep it lively. */
|
||||
teacher: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
/** Background sub-agents: fast and cheap beats deep thought. */
|
||||
researcher: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
demoBuilder: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
/** Must be vision-capable: it looks at rendered SVGs. */
|
||||
visualMaker: { provider: "openrouter", model: "qwen/qwen3.8-flash", effort: "low" },
|
||||
/** SEAM (master-approved 2026-09, revised by the user 2026-09-19): the
|
||||
* pdf-reader sub-agent. Must be vision-capable — it looks at rendered
|
||||
* PDF pages; its briefs are text. The user overrode the initial
|
||||
* glm-5.3-flash pick (catalog says it accepts images, but qwen is
|
||||
* proven for exactly this look-at-renders job — visualMaker's daily
|
||||
* workload). */
|
||||
pdfReader: { provider: "openrouter", model: "qwen/qwen3.8-flash", effort: "low" },
|
||||
/** Extraction is judgment over given evidence — light thinking suffices. */
|
||||
extractor: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
/** The auditor verifies evidence exists; keep it cheap. */
|
||||
auditor: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
/** Names detected communities — one singular call, given member names
|
||||
* + statements. Purely a labeling flourish; keep it cheap. */
|
||||
labeler: { provider: "openrouter", model: "z-ai/glm-5.3-flash", effort: "low" },
|
||||
} satisfies Record<string, ModelSpec>;
|
||||
|
||||
export type ModelRole = keyof typeof MODELS;
|
||||
/** The DEFAULT thinking level for UNSET levels only (owner, 2026-09-22):
|
||||
* a slot/override/chat that names a model but no thinking level resolves
|
||||
* to the FIRST entry in this order that the model supports
|
||||
* (getSupportedThinkingLevels); a non-reasoning model resolves "off"
|
||||
* regardless (pi reports exactly ["off"]). EXPLICITLY set levels never
|
||||
* consult this list — they clamp nearest via pi's native
|
||||
* clampThinkingLevel on model switches. */
|
||||
export const DEFAULT_THINKING_ORDER = [
|
||||
"medium",
|
||||
"low",
|
||||
"high",
|
||||
"minimal",
|
||||
"xhigh",
|
||||
"max",
|
||||
] as const satisfies readonly ThinkingLevel[];
|
||||
|
||||
/**
|
||||
* The extraction pipeline (vision §1 construction): the sole graph writer.
|
||||
|
||||
Reference in New Issue
Block a user