import { askEditor } from "@/lib/articles/generation"; import { fail, ok } from "../_respond"; export const dynamic = "force-dynamic"; // CONNECT AN ARCHIVE from the Source chip (demo epic D1): forwarded to the // editor's `archives` action, which reads the archive's corpus.json and — unless // `dryRun` — saves it in settings.remoteArchives (the one writer). The chip then // lists it (lib/research/sources.ts reads the same list). // // POST { origin, dryRun? } -> the editor's { ok, archive, probe, already } export async function POST(request: Request) { try { const body = (await request.json().catch(() => null)) as { origin?: unknown; dryRun?: unknown } | null; if (!body || typeof body.origin !== "string" || !body.origin.trim()) return Response.json({ error: "send { origin }: the archive's address" }, { status: 400 }); const answer = await askEditor("/api/ops/archives", { method: "POST", body: { connect: body.origin.trim(), ...(body.dryRun === true ? { dryRun: true } : {}) } }); return ok(answer); } catch (e) { return fail(e); } }