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:
@@ -18,6 +18,15 @@ import type { ProberToolContext } from "../src/agent/tools.ts";
|
||||
import { jobStore } from "../src/store/jobs.ts";
|
||||
import { parseAgentSettingsBody } from "../src/server/settings-body.ts";
|
||||
import { chatStore } from "../src/store/chats.ts";
|
||||
import { createFauxCore } from "@earendil-works/pi-ai";
|
||||
import type { PiEngine } from "../src/agent/models.ts";
|
||||
|
||||
/** A scripted pi engine — the agent builds need an injected engine since
|
||||
* BYOK removed the factory pins (owner, 2026-09-22). */
|
||||
function fauxEngine(): PiEngine {
|
||||
const faux = createFauxCore({});
|
||||
return { model: faux.getModel(), streamFn: faux.streamSimple };
|
||||
}
|
||||
import type { AgentSettings } from "../src/core/settings.ts";
|
||||
|
||||
describe("AgentBuildOptions.toolToggles (the P2 bridge)", () => {
|
||||
@@ -27,14 +36,14 @@ describe("AgentBuildOptions.toolToggles (the P2 bridge)", () => {
|
||||
it("flows into the teacher's registry: a job-tool delta is a no-op on the bare set", () => {
|
||||
// No ctx → bare agent: quiz/ask only. A job-tool delta names tools
|
||||
// that don't exist there — the bridge must not crash on it.
|
||||
const bare = createTeacherAgent(undefined, { toolToggles: { research: false } });
|
||||
const bare = createTeacherAgent(undefined, { engine: fauxEngine(), toolToggles: { research: false } });
|
||||
assert.deepEqual(toolNames(bare), ["ask_user_question", "quiz"]);
|
||||
});
|
||||
|
||||
it("flows into the prober's registry; probe_done survives everything", () => {
|
||||
const chatId = chatStore.createChat("Toggle bridge test").id;
|
||||
const ctx: ProberToolContext = { chatId, chatStore, deliver: () => {}, jobStore, spawn: () => {} };
|
||||
const prober = createProberAgent(ctx, { toolToggles: { ask_user_question: false } });
|
||||
const prober = createProberAgent(ctx, { engine: fauxEngine(), toolToggles: { ask_user_question: false } });
|
||||
const names = toolNames(prober);
|
||||
assert.ok(!names.includes("ask_user_question"), "the delta dropped the tool");
|
||||
assert.ok(names.includes("probe_done"), "probe_done always-on");
|
||||
@@ -42,6 +51,7 @@ describe("AgentBuildOptions.toolToggles (the P2 bridge)", () => {
|
||||
|
||||
it("an explicitly injected opts.tools registry is NEVER toggle-filtered", () => {
|
||||
const teacher = createTeacherAgent(undefined, {
|
||||
engine: fauxEngine(),
|
||||
tools: {
|
||||
quiz: { name: "quiz", description: "test", clientQuestion: true, schema: z.object({}) },
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user