2026-09-02 02:34:02 +03:00
|
|
|
import { isTurnRunning, listJobs } from "@/src/server";
|
2026-08-22 09:36:15 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Job status polling endpoint (contracts.ts "THE ASYNC PROTOCOL" §4): the
|
2026-09-02 02:34:02 +03:00
|
|
|
* client's ONE central poller fetches this while any job runs (and slowly
|
|
|
|
|
* otherwise) to drive the dispatch cards, the sub-agents panel, and the
|
|
|
|
|
* re-sync when a job settles. `turnInFlight` rides along so the client can
|
|
|
|
|
* adopt a server-side wake turn (busy state + composer gate) — the same
|
|
|
|
|
* machinery as returning to a session mid-turn.
|
2026-08-22 09:36:15 +03:00
|
|
|
*/
|
|
|
|
|
export async function GET(req: Request) {
|
|
|
|
|
const chatId = new URL(req.url).searchParams.get("chatId");
|
|
|
|
|
if (!chatId) {
|
|
|
|
|
return Response.json({ error: "chatId query parameter is required" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
if (!/^[A-Za-z0-9_-]+$/.test(chatId)) {
|
|
|
|
|
return Response.json({ error: "Invalid chatId" }, { status: 400 });
|
|
|
|
|
}
|
2026-09-02 02:34:02 +03:00
|
|
|
return Response.json({ jobs: listJobs(chatId), turnInFlight: isTurnRunning(chatId) });
|
2026-08-22 09:36:15 +03:00
|
|
|
}
|