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).
129 lines
4.6 KiB
TypeScript
129 lines
4.6 KiB
TypeScript
import { Data } from '../types/data';
|
|
import { consolidateSourceAndImageBlocks } from './consolidateBlocks';
|
|
|
|
export const preprocessOrderedData = (data: Data[]) => {
|
|
let groupedData: any[] = [];
|
|
let currentAccordionGroup: any = null;
|
|
let currentSourceGroup: any = null;
|
|
let currentReportGroup: any = null;
|
|
let finalReportGroup: any = null;
|
|
let sourceBlockEncountered = false;
|
|
let lastSubqueriesIndex = -1;
|
|
const seenUrls = new Set<string>();
|
|
// console.log('websocket data before its processed',data)
|
|
|
|
data.forEach((item: any) => {
|
|
const { type, content, metadata, output, link } = item;
|
|
|
|
if (type === 'question') {
|
|
groupedData.push({ type: 'question', content });
|
|
} else if (type === 'report') {
|
|
// Start a new report group if we don't have one
|
|
if (!currentReportGroup) {
|
|
currentReportGroup = { type: 'reportBlock', content: '' };
|
|
groupedData.push(currentReportGroup);
|
|
}
|
|
currentReportGroup.content += output;
|
|
} else if (type === 'report_complete') {
|
|
// Replace entire report content with the complete version (includes images)
|
|
if (currentReportGroup) {
|
|
currentReportGroup.content = output;
|
|
} else {
|
|
currentReportGroup = { type: 'reportBlock', content: output };
|
|
groupedData.push(currentReportGroup);
|
|
}
|
|
} else if (content === 'selected_images') {
|
|
groupedData.push({ type: 'imagesBlock', metadata });
|
|
} else if (type === 'logs' && content === 'research_report') {
|
|
if (!finalReportGroup) {
|
|
finalReportGroup = { type: 'reportBlock', content: '' };
|
|
groupedData.push(finalReportGroup);
|
|
}
|
|
finalReportGroup.content += output.report;
|
|
} else if (type === 'langgraphButton') {
|
|
groupedData.push({ type: 'langgraphButton', link });
|
|
} else if (type === 'chat') {
|
|
groupedData.push({ type: 'chat', content: content });
|
|
} else {
|
|
if (currentReportGroup) {
|
|
currentReportGroup = null;
|
|
}
|
|
|
|
if (content === 'subqueries') {
|
|
if (currentAccordionGroup) {
|
|
currentAccordionGroup = null;
|
|
}
|
|
if (currentSourceGroup) {
|
|
groupedData.push(currentSourceGroup);
|
|
currentSourceGroup = null;
|
|
}
|
|
groupedData.push(item);
|
|
lastSubqueriesIndex = groupedData.length - 1;
|
|
} else if (type === 'sourceBlock') {
|
|
currentSourceGroup = item;
|
|
if (lastSubqueriesIndex !== -1) {
|
|
groupedData.splice(lastSubqueriesIndex + 1, 0, currentSourceGroup);
|
|
lastSubqueriesIndex = -1;
|
|
} else {
|
|
groupedData.push(currentSourceGroup);
|
|
}
|
|
sourceBlockEncountered = true;
|
|
currentSourceGroup = null;
|
|
} else if (content === 'added_source_url') {
|
|
if (!currentSourceGroup) {
|
|
currentSourceGroup = { type: 'sourceBlock', items: [] };
|
|
}
|
|
|
|
if (!seenUrls.has(metadata)) {
|
|
seenUrls.add(metadata);
|
|
let hostname = "";
|
|
try {
|
|
if (typeof metadata === 'string') {
|
|
hostname = new URL(metadata).hostname.replace('www.', '');
|
|
}
|
|
} catch (e) {
|
|
hostname = "unknown";
|
|
}
|
|
currentSourceGroup.items.push({ name: hostname, url: metadata });
|
|
}
|
|
|
|
// Add this block to ensure the source group is added to groupedData
|
|
if (currentSourceGroup.items.length > 0 && !groupedData.includes(currentSourceGroup)) {
|
|
groupedData.push(currentSourceGroup);
|
|
sourceBlockEncountered = true;
|
|
}
|
|
} else if (type !== 'path' && content !== '') {
|
|
if (sourceBlockEncountered) {
|
|
if (!currentAccordionGroup) {
|
|
currentAccordionGroup = { type: 'accordionBlock', items: [] };
|
|
groupedData.push(currentAccordionGroup);
|
|
}
|
|
currentAccordionGroup.items.push(item);
|
|
} else {
|
|
groupedData.push(item);
|
|
}
|
|
} else {
|
|
if (currentAccordionGroup) {
|
|
currentAccordionGroup = null;
|
|
}
|
|
if (currentSourceGroup) {
|
|
currentSourceGroup = null;
|
|
}
|
|
if (currentReportGroup) {
|
|
// Find and remove the previous reportBlock
|
|
const reportBlockIndex = groupedData.findIndex(
|
|
item => item === currentReportGroup
|
|
);
|
|
if (reportBlockIndex !== -1) {
|
|
groupedData.splice(reportBlockIndex, 1);
|
|
}
|
|
currentReportGroup = null; // Reset the current report group
|
|
}
|
|
groupedData.push(item);
|
|
}
|
|
}
|
|
});
|
|
|
|
groupedData = consolidateSourceAndImageBlocks(groupedData);
|
|
return groupedData;
|
|
};
|