BYOK universal gate rendered honestly: mid-chat setup flow, refusal-aware cards

- existing sessions: a send that lands the 503 models_not_configured envelope
  renders as the SETUP FLOW, never the error banner — the record refetch drops
  the refused orphan (the gate refuses before the write-ahead persist), the
  draft goes home to the composer, and Save auto-replays it (owner ruling);
  parseModelsRefusal reads the envelope from the transport's verbatim error
  text (exported pure, tested)
- persistent 'Set up your models' CTA above the chat composer while
  slotsConfigured is false (server-read seed via app/chat/[id]/page.tsx) —
  legacy per-chat overrides may still send with the pill present; the server
  gate stays the truth
- SetupDialog prefill + 'needed' marks (owner ruling): pinned tiers open with
  their pick (matched in the federated catalog — lapsed keys don't prefill),
  unpinned tiers carry the mark; Save still requires all three;
  prefillFromSlots exported pure, tested
- refused jobs read as INFO: dispatch card shows a quiet 'needs model setup'
  line + 'Set up models' deep-link (ChatActionsContext.openSetup); dock blobs'
  activity reads 'needs model setup' instead of 'failed'; real failures keep
  the red tone; isModelsRefusal added to the envelope's home module
- agent-section ModelsBody.slots type honest to the nullable contract
This commit is contained in:
amosblomqvist
2026-09-22 18:12:57 +03:00
parent bb7804bd7f
commit 5ab52f07f6
10 changed files with 397 additions and 13 deletions
+52
View File
@@ -18,6 +18,10 @@ import { renderToStaticMarkup } from "react-dom/server";
import { MessageResponse } from "../components/ai-elements/message.tsx";
import { QuestionDock } from "../components/question-dock.tsx";
import { ProbeDoneCard } from "../components/artifacts/probe-done-card.tsx";
import { DispatchCard } from "../components/artifacts/dispatch-card.tsx";
import { JobsContext } from "../components/jobs-context.ts";
import { ChatActionsContext } from "../components/chat.tsx";
import type { JobRecord } from "../src/core/contracts.ts";
import { AnsweredCard } from "../components/answered-card.tsx";
import { buildAnswer, coerceCorrectAnswer, normalizeOptions, resolveCorrect, type QuestionData } from "../src/core/question-core.ts";
@@ -63,6 +67,54 @@ function renderDock(props: { toolName: "quiz" | "ask_user_question"; toolCallId:
);
}
describe("DispatchCard — the BYOK refusal tone (owner, 2026-09-22)", () => {
const job = (over: Partial<JobRecord>): JobRecord => ({
id: "j1",
kind: "research",
chatId: "c1",
toolCallId: "t1",
status: "error",
activity: "",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
...over,
});
const inJobs = (jobs: JobRecord[]) => (
<JobsContext.Provider value={jobs}>
<ChatActionsContext.Provider
value={{ chatId: "c1", syncFromServer: async () => {}, sendText: () => {}, openSetup: () => {} }}
>
<DispatchCard toolCallId="t1" kind="research" />
</ChatActionsContext.Provider>
</JobsContext.Provider>
);
it("a models-refused job is INFO: quiet card, 'needs model setup', deep-link to the dialog", () => {
const html = renderToStaticMarkup(
inJobs([job({ error: "No model configured — set up your models first (missing: cheap)" })]),
);
assert.ok(html.includes('data-testid="dispatch-refused"'));
assert.ok(html.includes("needs model setup"));
assert.ok(html.includes('data-testid="dispatch-setup-link"'));
assert.ok(html.includes("Set up models"));
assert.ok(!html.includes("failed"));
assert.ok(!html.includes("text-red-500"));
});
it("a real failure keeps the honest red failure", () => {
const html = renderToStaticMarkup(inJobs([job({ error: "FAILED: headless crashed" })]));
assert.ok(html.includes('data-testid="dispatch-settled"'));
assert.ok(html.includes("failed"));
assert.ok(html.includes("text-red-500"));
assert.ok(!html.includes("dispatch-refused"));
});
it("a delivered job reads delivered, untouched by the wave", () => {
const html = renderToStaticMarkup(inJobs([job({ status: "done", error: undefined })]));
assert.ok(html.includes("delivered"));
});
});
describe("render smoke tests", () => {
it("QuizCard renders question, options, and the automatic 'I don't know'", () => {
const html = renderDock({ toolName: "quiz", toolCallId: "q1", input: quizInput as never });