Practice sessions (owner, 2026-10-04): the marker rides the record and
the normalized summary (absent field reads as teach — pre-practice
records never migrate); POST /api/chats accepts {kind: 'practice'}.
The agent branch, tools, and UI land in the following slices.
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
import { createChat, isTurnRunning, listChats, readSettingsRecord, stores, titleFromPrompt } from "@/src/server";
|
|
import type { ChatListItem } from "@/src/core";
|
|
|
|
/** The session picker's list: record-derived summaries (phase, pending
|
|
* question) + live liveness — a running turn marks the session busy
|
|
* (contracts.ts ChatListItem; the store can't see liveness, the route is
|
|
* the merge point). Owner, minimal-color round: background jobs NO LONGER
|
|
* count — the sidebar's Background agents section is their channel now
|
|
* (a running spinner per row would double-signal them), so busy means
|
|
* exactly "a teach turn is in flight". */
|
|
export async function GET() {
|
|
const chats: ChatListItem[] = listChats().map((c) => ({
|
|
...c,
|
|
busy: isTurnRunning(c.id),
|
|
}));
|
|
return Response.json({ chats });
|
|
}
|
|
|
|
export async function POST(req: Request) {
|
|
const body = (await req.json().catch(() => ({}))) as { title?: unknown; kind?: unknown };
|
|
const title = typeof body.title === "string" ? body.title : "";
|
|
// Practice sessions (owner, 2026-10-04): kind "practice" marks the
|
|
// record — the practice agent + its tools from turn 1, no extraction.
|
|
const kind = body.kind === "practice" ? ("practice" as const) : undefined;
|
|
const chat = createChat(titleFromPrompt(title || "Untitled session"), kind);
|
|
// PER-SESSION MODELS (owner, 2026-09-28): a session owns its model +
|
|
// thinking level from birth — stamped verbatim from the STRONG slot,
|
|
// the new-session default. From here the strong slot never reaches
|
|
// this session again: in-session picks write the session's own record
|
|
// (PUT /api/chats/:id/settings). No strong slot configured (fresh BYOK
|
|
// boot) → no stamp; the turn gate's 503 models_not_configured envelope
|
|
// refuses honestly until the setup flow fills the slot.
|
|
const strong = readSettingsRecord()?.models?.strong;
|
|
if (strong?.model) {
|
|
stores.chatStore.saveSettings(chat.id, {
|
|
model: { provider: strong.model.provider, id: strong.model.id },
|
|
thinkingLevel: strong.thinkingLevel,
|
|
});
|
|
}
|
|
return Response.json({ id: chat.id, title: chat.title });
|
|
}
|