import { z } from "zod"; import { guarded, body, sse, json } from "@/lib/api"; import { runResearch } from "@/lib/research/engine"; import { sql } from "@/lib/db"; export const maxDuration = 900; export const POST = guarded(async (req) => { const b = await body(req, z.object({ question: z.string().min(5).max(5000), modelId: z.string(), projectId: z.string().nullable().optional(), depth: z.enum(["quick", "standard", "deep"]).optional() })); return sse(async (emit, signal) => { await runResearch({ ...b, emit, signal }); }, req.signal); }); export const GET = guarded(async () => { const runs = await sql`SELECT id, conversation_id, question, model_id, status, cost_usd, created_at, completed_at, jsonb_array_length(sources) AS source_count FROM research_runs ORDER BY created_at DESC LIMIT 100`; return json({ runs }); });