Files
learnharness/app/api/jobs/route.ts
T

19 lines
704 B
TypeScript
Raw Normal View History

2026-08-22 09:36:15 +03:00
import { listJobs } from "@/src/store/jobs";
/**
* Job status polling endpoint (contracts.ts "THE ASYNC PROTOCOL" §4): the
* client polls GET /api/jobs?chatId=… while any job tool part is pending,
* finds the job by toolCallId, renders its activity line, and re-syncs the
* chat when the job flips to done/error.
*/
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 });
}
return Response.json({ jobs: listJobs(chatId) });
}