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).
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import type { NextRequest } from "next/server";
|
|
import { withOrg, parsePagination, type Ctx } from "@/lib/api/handler";
|
|
import { ok, created, fail } from "@/lib/api/response";
|
|
import { getPool } from "@/lib/db";
|
|
import { requireRole } from "@/lib/authz/rbac";
|
|
import { CreateExperimentInputSchema } from "@/lib/labNotebook/schemas";
|
|
import { createExperiment, listExperiments } from "@/lib/labNotebook/repository";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// GET /api/lab-notebook — paginated, org-scoped list of saved experiments. Optional
|
|
// ?q full-text search (websearch_to_tsquery over title + raw_notes). Any member may read.
|
|
export const GET = withOrg(async (req: NextRequest, ctx: Ctx) => {
|
|
try {
|
|
requireRole(ctx, "viewer");
|
|
const { limit, offset, page } = parsePagination(req);
|
|
const url = new URL(req.url);
|
|
const q = url.searchParams.get("q")?.trim() || undefined;
|
|
|
|
const { items, total } = await listExperiments(getPool(), ctx.org.id, {
|
|
q,
|
|
limit,
|
|
offset,
|
|
});
|
|
return ok(items, { total, page, limit });
|
|
} catch (err) {
|
|
console.error("[/api/lab-notebook] list failed:", err);
|
|
return fail("Failed to load experiments.", 500);
|
|
}
|
|
});
|
|
|
|
// POST /api/lab-notebook — persist a reviewed, grounded experiment record. Editor+.
|
|
// The `structured` payload is re-validated against StructuredExperimentSchema by the
|
|
// input schema. NEVER logs the raw notes — only the created id.
|
|
export const POST = withOrg(async (req: NextRequest, ctx: Ctx) => {
|
|
requireRole(ctx, "editor");
|
|
|
|
const body = await req.json().catch(() => null);
|
|
const parsed = CreateExperimentInputSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return fail(parsed.error.issues[0]?.message ?? "Invalid experiment record.", 400);
|
|
}
|
|
|
|
try {
|
|
const record = await createExperiment(
|
|
getPool(),
|
|
ctx.org.id,
|
|
ctx.user.id,
|
|
parsed.data
|
|
);
|
|
return created(record);
|
|
} catch (err) {
|
|
console.error("[/api/lab-notebook] create failed:", err);
|
|
return fail("Couldn't save this experiment. Please try again.", 500);
|
|
}
|
|
});
|