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).
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { z } from "zod";
|
|
import { ok, fail } from "@/lib/api/response";
|
|
import { withApiKey, type ApiCtx } from "@/lib/apiv1/gateway";
|
|
import { verifyBiomedicalClaim } from "@/lib/bio/verifyBiomedicalClaim";
|
|
|
|
// POST /api/v1/bio/verify-claim
|
|
//
|
|
// Versioned enterprise API over the biomedical claim verifier. Authenticated by
|
|
// an org API key (Bearer) with per-plan quota enforced by the gateway. Wraps the
|
|
// existing verifyBiomedicalClaim engine — this route adds NO domain logic; it
|
|
// validates input, delegates, and returns a stable v1 envelope.
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
const API_VERSION = "v1" as const;
|
|
|
|
// Local boundary schema — the engine accepts { claim }, but the HTTP boundary
|
|
// still validates shape/length before delegating (fail fast, never trust input).
|
|
const verifyClaimSchema = z.object({
|
|
claim: z.string().trim().min(10).max(2000),
|
|
});
|
|
|
|
export const POST = withApiKey(
|
|
async (req: NextRequest, ctx: ApiCtx): Promise<Response> => {
|
|
const json = await req.json().catch(() => null);
|
|
const parsed = verifyClaimSchema.safeParse(json);
|
|
if (!parsed.success) {
|
|
return fail(
|
|
parsed.error.issues[0]?.message ?? "Invalid request body.",
|
|
400
|
|
);
|
|
}
|
|
|
|
try {
|
|
const verification = await verifyBiomedicalClaim({
|
|
claim: parsed.data.claim,
|
|
});
|
|
return ok({
|
|
version: API_VERSION,
|
|
orgId: ctx.orgId,
|
|
verification,
|
|
});
|
|
} catch {
|
|
return fail("Biomedical claim verification failed. Please retry.", 502);
|
|
}
|
|
},
|
|
{ quotaKind: "verification", routeLabel: "/api/v1/bio/verify-claim" }
|
|
);
|