- core/phases.ts: Phase3 (probe/plan/teach) + pure derivations — phaseOfTree (point-in-time, from the stored plan tree: no nodes → probe, no occupied node → plan, occupied → teach) and phaseAt3 (monotonic transcript fold for the dividers: failed plan_init never marks a seam; phase only advances). - contracts.ts: ChatSummary gains record-derived phase + pendingQuestion; ChatListItem adds liveness-merged busy. - store/chats.ts listChats computes the record-derived fields (tree + pending question scan). - api/chats route merges busy = turn running || running background job. Lane crossing granted by master: contracts/store/api (schema arbitration). Data-only inference: pre-plan planning reads as probe until the plan lands.
22 lines
946 B
TypeScript
22 lines
946 B
TypeScript
import { createChat, isTurnRunning, listChats, listJobs, 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 OR a background job marks
|
|
* the session busy (contracts.ts ChatListItem; the store can't see
|
|
* liveness, the route is the merge point). */
|
|
export async function GET() {
|
|
const chats: ChatListItem[] = listChats().map((c) => ({
|
|
...c,
|
|
busy: isTurnRunning(c.id) || listJobs(c.id).some((j) => j.status === "running"),
|
|
}));
|
|
return Response.json({ chats });
|
|
}
|
|
|
|
export async function POST(req: Request) {
|
|
const body = (await req.json().catch(() => ({}))) as { title?: unknown };
|
|
const title = typeof body.title === "string" ? body.title : "";
|
|
const chat = createChat(titleFromPrompt(title || "Untitled session"));
|
|
return Response.json({ id: chat.id, title: chat.title });
|
|
}
|