import { NextRequest, NextResponse } from "next/server"; import { getCollector, listCollectorNames } from "@pipeline/collect"; import { loadConfig } from "@/lib/config"; export async function POST(request: NextRequest) { const body = await request.json(); const { source, args } = body as { source: string; args?: Record }; if (!source) { return NextResponse.json({ error: "source is required" }, { status: 400 }); } const available = listCollectorNames(); if (!available.includes(source)) { return NextResponse.json( { error: `Unknown source: ${source}. Available: ${available.join(", ")}` }, { status: 400 } ); } const config = loadConfig(); const collectorConfig = config?.collect?.[source]; const collector = getCollector(source, collectorConfig); try { const result = await collector.collect(args ? { args } : undefined); const content = result.type === "json" ? JSON.stringify(result.content, null, 2) : result.content; return NextResponse.json({ content, type: result.type }); } catch (err: any) { return NextResponse.json({ error: err.message }, { status: 500 }); } }