- Lab Notebook: deterministic reproducibility gaps (antibody dilution, vendor/catalog, controls, sample size, missing readout) - Trial Matcher: 'why this rank' one-line eligibility summary from per-criterion assessments - Verify: copyable citation + full reviewer memo, source quotes verbatim - /console/demo reviewer walkthrough linking the 3 named-user journeys, wired into console nav - All additive, deterministic (no new LLM calls), tsc + build green
239 lines
7.7 KiB
TypeScript
239 lines
7.7 KiB
TypeScript
import type {
|
|
Entity,
|
|
Observation,
|
|
Outcome,
|
|
ProtocolStep,
|
|
Reagent,
|
|
Sample,
|
|
StructuredExperiment,
|
|
} from "./types";
|
|
import { checkReproducibility } from "@/lib/labNotebook/reproducibility";
|
|
import { ReproducibilityHints } from "./ReproducibilityHints";
|
|
|
|
// Renders a structured experiment record. Every field that quotes the raw notes is shown
|
|
// with its verbatim grounded span underneath — the grounding is the whole point, so we
|
|
// surface it, not hide it. Shared by StructuredPreview (before save) and ExperimentDetail
|
|
// (a saved record), so it takes no callbacks and does no fetching.
|
|
//
|
|
// It also runs the deterministic reproducibility check (checkReproducibility) over the
|
|
// same structured fields and surfaces any "add for reproducibility" hints up top. That
|
|
// check makes no LLM call and invents no data — it only flags MISSING details — so it can
|
|
// live purely in render with no extra state or fetch.
|
|
|
|
const ENTITY_LABEL: Record<Entity["type"], string> = {
|
|
gene: "Gene",
|
|
protein: "Protein",
|
|
cell_line: "Cell line",
|
|
reagent: "Reagent",
|
|
organism: "Organism",
|
|
method: "Method",
|
|
other: "Other",
|
|
};
|
|
|
|
function GroundedQuote({ span }: { span: string }) {
|
|
return (
|
|
<p className="mt-1 border-l-2 border-accent/50 bg-ink/[0.03] px-2 py-1 text-xs italic text-ink/50">
|
|
<span className="not-italic font-medium text-ink/40">quoted: </span>
|
|
“{span}”
|
|
</p>
|
|
);
|
|
}
|
|
|
|
// A small badge distinguishing sections that carry verbatim grounded quotes from those
|
|
// that are model-normalized summaries (no per-item source_span). Keeps the trust story
|
|
// legible: a scientist knows at a glance which fields are extracted-and-grounded vs
|
|
// inferred, so they don't wonder why an inferred list isn't quoting the notes.
|
|
function InferredBadge() {
|
|
return (
|
|
<span
|
|
className="rounded-full bg-ink/[0.05] px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink/40"
|
|
title="Model-normalized summary — faithful to the notes but not a verbatim quote (no source_span)."
|
|
>
|
|
Auto-inferred
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function GroundedBadge() {
|
|
return (
|
|
<span
|
|
className="rounded-full bg-emerald-50 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-emerald-700"
|
|
title="Every item carries a verbatim quote from your notes; ungroundable items were dropped."
|
|
>
|
|
Grounded
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function Section({
|
|
title,
|
|
count,
|
|
inferred = false,
|
|
children,
|
|
}: {
|
|
title: string;
|
|
count: number;
|
|
// When true this section is a model-normalized summary (no verbatim source_span), so we
|
|
// label it "Auto-inferred" instead of "Grounded" to keep the trust distinction clear.
|
|
inferred?: boolean;
|
|
children: React.ReactNode;
|
|
}) {
|
|
if (count === 0) return null;
|
|
return (
|
|
<section>
|
|
<div className="mb-2 flex items-center gap-2">
|
|
<h4 className="text-xs font-semibold uppercase tracking-wide text-ink/40">
|
|
{title} ({count})
|
|
</h4>
|
|
{inferred ? <InferredBadge /> : <GroundedBadge />}
|
|
</div>
|
|
{children}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function ProtocolSteps({ steps }: { steps: ProtocolStep[] }) {
|
|
return (
|
|
<ol className="space-y-2">
|
|
{steps.map((step, i) => (
|
|
<li key={`${step.order}-${i}`} className="rounded-md border border-ink/15 p-3">
|
|
<div className="flex gap-2">
|
|
<span className="shrink-0 font-mono text-xs text-accent">{step.order}.</span>
|
|
<div className="min-w-0">
|
|
<p className="text-sm text-ink/80">{step.text}</p>
|
|
<GroundedQuote span={step.source_span} />
|
|
</div>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
);
|
|
}
|
|
|
|
function Reagents({ reagents }: { reagents: Reagent[] }) {
|
|
return (
|
|
<ul className="space-y-2">
|
|
{reagents.map((r, i) => (
|
|
<li key={`${r.name}-${i}`} className="rounded-md border border-ink/15 p-3">
|
|
<p className="text-sm font-medium text-ink/80">{r.name}</p>
|
|
<dl className="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-xs text-ink/50">
|
|
{r.vendor ? (
|
|
<div className="flex gap-1">
|
|
<dt className="font-medium text-ink/40">vendor</dt>
|
|
<dd>{r.vendor}</dd>
|
|
</div>
|
|
) : null}
|
|
{r.catalog ? (
|
|
<div className="flex gap-1">
|
|
<dt className="font-medium text-ink/40">cat#</dt>
|
|
<dd className="font-mono">{r.catalog}</dd>
|
|
</div>
|
|
) : null}
|
|
{r.amount ? (
|
|
<div className="flex gap-1">
|
|
<dt className="font-medium text-ink/40">amount</dt>
|
|
<dd>{r.amount}</dd>
|
|
</div>
|
|
) : null}
|
|
</dl>
|
|
<GroundedQuote span={r.source_span} />
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
function SpannedList({ items }: { items: (Sample | Observation | Outcome)[] }) {
|
|
return (
|
|
<ul className="space-y-2">
|
|
{items.map((item, i) => (
|
|
<li key={i} className="rounded-md border border-ink/15 p-3">
|
|
<p className="text-sm text-ink/80">{item.text}</p>
|
|
<GroundedQuote span={item.source_span} />
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
interface StructuredRecordProps {
|
|
structured: StructuredExperiment;
|
|
}
|
|
|
|
export function StructuredRecord({ structured }: StructuredRecordProps) {
|
|
const reproducibility = checkReproducibility(structured);
|
|
|
|
return (
|
|
<div className="space-y-5">
|
|
<ReproducibilityHints report={reproducibility} />
|
|
|
|
{structured.objective ? (
|
|
<section>
|
|
<div className="mb-1 flex items-center gap-2">
|
|
<h4 className="text-xs font-semibold uppercase tracking-wide text-ink/40">
|
|
Objective
|
|
</h4>
|
|
<InferredBadge />
|
|
</div>
|
|
<p className="text-sm text-ink/80">{structured.objective}</p>
|
|
</section>
|
|
) : null}
|
|
|
|
<Section title="Protocol steps" count={structured.protocol_steps.length}>
|
|
<ProtocolSteps steps={structured.protocol_steps} />
|
|
</Section>
|
|
|
|
<Section title="Reagents" count={structured.reagents.length}>
|
|
<Reagents reagents={structured.reagents} />
|
|
</Section>
|
|
|
|
<Section title="Samples" count={structured.samples.length}>
|
|
<SpannedList items={structured.samples} />
|
|
</Section>
|
|
|
|
<Section title="Equipment" count={structured.equipment.length} inferred>
|
|
<div className="flex flex-wrap gap-2">
|
|
{structured.equipment.map((e, i) => (
|
|
<span
|
|
key={`${e}-${i}`}
|
|
className="rounded-full border border-ink/15 px-2.5 py-0.5 text-xs text-ink/70"
|
|
>
|
|
{e}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="Observations" count={structured.observations.length}>
|
|
<SpannedList items={structured.observations} />
|
|
</Section>
|
|
|
|
<Section title="Outcomes" count={structured.outcomes.length}>
|
|
<SpannedList items={structured.outcomes} />
|
|
</Section>
|
|
|
|
<Section title="Next steps" count={structured.next_steps.length} inferred>
|
|
<ul className="list-disc space-y-1 pl-5 text-sm text-ink/70">
|
|
{structured.next_steps.map((s, i) => (
|
|
<li key={i}>{s}</li>
|
|
))}
|
|
</ul>
|
|
</Section>
|
|
|
|
<Section title="Entities" count={structured.entities.length} inferred>
|
|
<div className="flex flex-wrap gap-2">
|
|
{structured.entities.map((e, i) => (
|
|
<span
|
|
key={`${e.name}-${i}`}
|
|
className="rounded-full bg-accent/10 px-2.5 py-0.5 text-xs text-accent"
|
|
title={ENTITY_LABEL[e.type]}
|
|
>
|
|
<span className="font-medium">{ENTITY_LABEL[e.type]}:</span> {e.name}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</Section>
|
|
</div>
|
|
);
|
|
}
|