Intelligence

Artifacts

Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.

Repository
globals.csslayout.tsxnot-found.tsxpage.tsx
.gitignoreDockerfilenext-env.d.tsnext.config.mjspackage-lock.jsonpackage.jsonpostcss.config.mjsREADME.mdtailwind.config.tstsconfig.jsontsconfig.tsbuildinfo
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/app/api/assets/register/route.ts
1.4 KB
import { NextResponse } from "next/server";
import { registerAssetFromReport, AssetError } from "@/lib/assets/ledger";
import type { RegisterAssetInput } from "@/lib/assets/types";

/**
 * Register a report's produced artifact into the Asset Ledger. The origin
 * lineage is taken from the report and is immutable.
 *
 *   POST /api/assets/register
 *     { mission_id, assignment_id, report_id, relative_path, name?, type?, tags?, description? }
 */

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

export async function POST(request: Request) {
  let body: RegisterAssetInput;
  try {
    body = (await request.json()) as RegisterAssetInput;
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  if (!body.mission_id || !body.assignment_id || !body.report_id || !body.relative_path) {
    return NextResponse.json(
      { error: "mission_id, assignment_id, report_id and relative_path are required." },
      { status: 400 },
    );
  }
  try {
    const asset = registerAssetFromReport(body);
    return NextResponse.json({ asset }, { status: 201 });
  } catch (err) {
    if (err instanceof AssetError) {
      return NextResponse.json({ error: err.message }, { status: err.status });
    }
    const message = err instanceof Error ? err.message : "Registration failed.";
    return NextResponse.json({ error: message }, { status: 500 });
  }
}

root · /srv/aaf