papertrail/lib/governance/evidenceAudit.schemas.ts
caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
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).
2026-07-10 16:23:13 +03:00

37 lines
1.6 KiB
TypeScript

import { z } from "zod";
// Boundary schemas for the tamper-evident evidence audit chain. The APPEND input
// is validated before it is folded into a hash: a chain is only as trustworthy
// as the shape of what goes into it, so we never hash unvalidated data.
// An evidence action verb. Kept as a constrained string rather than a closed
// enum so new evidence actions can be logged without a migration, but bounded so
// junk (empty strings, essays) can't enter the chain.
export const evidenceActionSchema = z
.string()
.trim()
.min(1, "action is required")
.max(120, "action is too long");
// The append payload. `entityId` is optional (some actions concern the org as a
// whole); `actor` is optional (system/automated actions have no user). `payload`
// is an arbitrary JSON object — the caller's structured record of the action —
// but must be an object so canonicalization is deterministic.
export const appendEvidenceAuditSchema = z.object({
action: evidenceActionSchema,
entityType: z.string().trim().min(1, "entityType is required").max(120),
entityId: z.string().trim().min(1).max(400).nullable().optional(),
actor: z.string().uuid("actor must be a uuid").nullable().optional(),
payload: z.record(z.string(), z.unknown()).default({}),
});
export type AppendEvidenceAuditInput = z.infer<typeof appendEvidenceAuditSchema>;
// Query params for reading a chain page.
export const listEvidenceAuditSchema = z.object({
limit: z.number().int().min(1).max(500).default(100),
offset: z.number().int().min(0).default(0),
});
export type ListEvidenceAuditInput = z.infer<typeof listEvidenceAuditSchema>;