Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { getPool } from "@/lib/db";
|
|
import { ok, fail } from "@/lib/api/response";
|
|
import { withApiKey, type ApiCtx } from "@/lib/apiv1/gateway";
|
|
import {
|
|
runEvidencePipeline,
|
|
EvidencePipelineInputSchema,
|
|
} from "@/lib/evidencePipeline";
|
|
|
|
// POST /api/v1/evidence/verify
|
|
//
|
|
// Versioned enterprise API over the evidence-synthesis engine. Authenticated by
|
|
// an org API key (Bearer) with per-plan quota enforced by the gateway. Wraps the
|
|
// existing runEvidencePipeline — this route adds NO scientific logic of its own;
|
|
// it only validates input, delegates, and shapes a stable v1 envelope.
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
const API_VERSION = "v1" as const;
|
|
|
|
export const POST = withApiKey(
|
|
async (req: NextRequest, ctx: ApiCtx): Promise<Response> => {
|
|
// Validate at the boundary — never trust the request body.
|
|
const json = await req.json().catch(() => null);
|
|
const parsed = EvidencePipelineInputSchema.safeParse(json);
|
|
if (!parsed.success) {
|
|
return fail(
|
|
parsed.error.issues[0]?.message ?? "Invalid request body.",
|
|
400
|
|
);
|
|
}
|
|
|
|
try {
|
|
const result = await runEvidencePipeline(getPool(), parsed.data);
|
|
// Stable versioned envelope: version + org echo + engine result. orgId is
|
|
// the gateway-resolved id, never a client-supplied value.
|
|
return ok({
|
|
version: API_VERSION,
|
|
orgId: ctx.orgId,
|
|
claim: result.claim,
|
|
report: result.report,
|
|
usedSources: result.usedSources,
|
|
skipped: result.skipped,
|
|
});
|
|
} catch {
|
|
return fail("Evidence verification failed. Please retry.", 502);
|
|
}
|
|
},
|
|
{ quotaKind: "verification", routeLabel: "/api/v1/evidence/verify" }
|
|
);
|