2026-09-15 17:01:01 +03:00
|
|
|
import { createChat, isTurnRunning, listChats, titleFromPrompt } from "@/src/server";
|
2026-09-01 18:24:13 +03:00
|
|
|
import type { ChatListItem } from "@/src/core";
|
2026-08-22 02:18:27 +03:00
|
|
|
|
2026-09-01 18:24:13 +03:00
|
|
|
/** The session picker's list: record-derived summaries (phase, pending
|
2026-09-15 17:01:01 +03:00
|
|
|
* 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". */
|
2026-08-22 02:18:27 +03:00
|
|
|
export async function GET() {
|
2026-09-01 18:24:13 +03:00
|
|
|
const chats: ChatListItem[] = listChats().map((c) => ({
|
|
|
|
|
...c,
|
2026-09-15 17:01:01 +03:00
|
|
|
busy: isTurnRunning(c.id),
|
2026-09-01 18:24:13 +03:00
|
|
|
}));
|
|
|
|
|
return Response.json({ chats });
|
2026-08-22 02:18:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 });
|
|
|
|
|
}
|