import type { APIRoute } from "astro"; import { getAllThreads, getLogLines } from "../../lib/thread-store"; export const GET: APIRoute = async ({ url }) => { const headers = { "Content-Type": "application/json" }; try { const since = url.searchParams.get("since"); const sinceMs = since ? Number(since) : Date.now() - 24 * 60 * 60 * 1000; const threads = await getAllThreads(sinceMs); const enriched = await Promise.all( threads.map(async (t) => ({ ...t, logLines: await getLogLines(t.threadId), })) ); return new Response( JSON.stringify({ threads: enriched, ts: Date.now() }), { headers } ); } catch (err: any) { return new Response( JSON.stringify({ error: err.message }), { status: 500, headers } ); } };