2026-09-01 18:24:13 +03:00
|
|
|
import { createChat, isTurnRunning, listChats, listJobs, titleFromPrompt } from "@/src/server";
|
|
|
|
|
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
|
|
|
|
|
* 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). */
|
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,
|
|
|
|
|
busy: isTurnRunning(c.id) || listJobs(c.id).some((j) => j.status === "running"),
|
|
|
|
|
}));
|
|
|
|
|
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 });
|
|
|
|
|
}
|