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).
92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
// gptr-webhook.js
|
|
const WebSocket = require('ws');
|
|
|
|
let socket = null;
|
|
const responseCallbacks = new Map(); // Using Map for multiple callbacks
|
|
|
|
async function initializeWebSocket() {
|
|
if (!socket) {
|
|
const host = 'gpt-researcher:8000';
|
|
const ws_uri = `ws://${host}/ws`;
|
|
|
|
socket = new WebSocket(ws_uri);
|
|
|
|
socket.onopen = () => {
|
|
console.log('WebSocket connection established');
|
|
};
|
|
|
|
socket.onmessage = (event) => {
|
|
const data = JSON.parse(event.data);
|
|
console.log('WebSocket data received:', data);
|
|
|
|
// Get the callback for this request
|
|
const callback = responseCallbacks.get('current');
|
|
|
|
if (data.type === 'report') {
|
|
// Send progress updates
|
|
if (callback && callback.onProgress) {
|
|
callback.onProgress(data.output);
|
|
}
|
|
} else if (data.content === 'dev_team_result') {
|
|
// Send final result
|
|
if (callback && callback.onComplete) {
|
|
callback.onComplete(data.output);
|
|
responseCallbacks.delete('current'); // Clean up after completion
|
|
}
|
|
}
|
|
};
|
|
|
|
socket.onclose = () => {
|
|
console.log('WebSocket connection closed');
|
|
socket = null;
|
|
};
|
|
|
|
socket.onerror = (error) => {
|
|
console.error('WebSocket error:', error);
|
|
};
|
|
}
|
|
}
|
|
|
|
async function sendWebhookMessage({query, moreContext}) {
|
|
return new Promise((resolve, reject) => {
|
|
if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
initializeWebSocket();
|
|
}
|
|
|
|
const data = {
|
|
task: `${query}. Additional context: ${moreContext}`,
|
|
report_type: 'research_report',
|
|
report_source: 'web',
|
|
tone: 'Objective',
|
|
headers: {},
|
|
repo_name: typeof repoName === 'undefined' || repoName === '' ? 'assafelovic/gpt-researcher' : repoName,
|
|
branch_name: typeof branchName === 'undefined' || branchName === '' ? 'master' : branchName
|
|
};
|
|
|
|
const payload = "start " + JSON.stringify(data);
|
|
|
|
// Store both progress and completion callbacks
|
|
responseCallbacks.set('current', {
|
|
onProgress: (progressData) => {
|
|
resolve({ type: 'progress', data: progressData });
|
|
},
|
|
onComplete: (finalData) => {
|
|
resolve({ type: 'complete', data: finalData });
|
|
}
|
|
});
|
|
|
|
if (socket.readyState === WebSocket.OPEN) {
|
|
socket.send(payload);
|
|
console.log('Message sent:', payload);
|
|
} else {
|
|
socket.onopen = () => {
|
|
socket.send(payload);
|
|
console.log('Message sent after connection:', payload);
|
|
};
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
sendWebhookMessage
|
|
}; |