// Analyze endpoint. POST with optional ?section= to run one section, or no // query param (or ?section=all) to run the full pipeline. // // Legacy section names "taxonomy" and "glossary" are accepted and mapped to // the unified "concepts" pass (T3 of the integration plan). This keeps older // clients and any external scripts working through one release. import { NextResponse } from "next/server"; import { runAnalyze, type RunSection } from "../../../../../lib/llm/analyze/runAll"; import { normalizeAnalysisSection } from "../../../../../lib/db/repo"; interface RouteContext { params: Promise<{ projectId: string }>; } export async function POST(req: Request, ctx: RouteContext) { const { projectId } = await ctx.params; const url = new URL(req.url); const sectionRaw = (url.searchParams.get("section") ?? "all").toLowerCase(); let section: RunSection; try { section = normalizeAnalysisSection(sectionRaw) as RunSection; } catch { return NextResponse.json({ error: `Invalid section: ${sectionRaw}` }, { status: 400 }); } try { const result = await runAnalyze(projectId, section); return NextResponse.json(result); } catch (err) { console.error("[analyze] route failed:", err); return NextResponse.json({ error: (err as Error).message }, { status: 500 }); } }