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

102 lines
3.7 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
MCP Streaming Utilities Module
Handles websocket streaming and logging for MCP operations.
"""
import asyncio
import logging
from typing import Any, Optional
logger = logging.getLogger(__name__)
class MCPStreamer:
"""
Handles streaming output for MCP operations.
Responsible for:
- Streaming logs to websocket
- Synchronous/asynchronous logging
- Error handling in streaming
"""
def __init__(self, websocket=None):
"""
Initialize the MCP streamer.
Args:
websocket: WebSocket for streaming output
"""
self.websocket = websocket
async def stream_log(self, message: str, data: Any = None):
"""Stream a log message to the websocket if available."""
logger.info(message)
if self.websocket:
try:
from ..actions.utils import stream_output
await stream_output(
type="logs",
content="mcp_retriever",
output=message,
websocket=self.websocket,
metadata=data
)
except Exception as e:
logger.error(f"Error streaming log: {e}")
def stream_log_sync(self, message: str, data: Any = None):
"""Synchronous version of stream_log for use in sync contexts."""
logger.info(message)
if self.websocket:
try:
try:
loop = asyncio.get_event_loop()
if loop.is_running():
asyncio.create_task(self.stream_log(message, data))
else:
loop.run_until_complete(self.stream_log(message, data))
except RuntimeError:
logger.debug("Could not stream log: no running event loop")
except Exception as e:
logger.error(f"Error in sync log streaming: {e}")
async def stream_stage_start(self, stage: str, description: str):
"""Stream the start of a research stage."""
await self.stream_log(f"🔧 {stage}: {description}")
async def stream_stage_complete(self, stage: str, result_count: int = None):
"""Stream the completion of a research stage."""
if result_count is not None:
await self.stream_log(f"✅ {stage} completed: {result_count} results")
else:
await self.stream_log(f"✅ {stage} completed")
async def stream_tool_selection(self, selected_count: int, total_count: int):
"""Stream tool selection information."""
await self.stream_log(f"🧠 Using LLM to select {selected_count} most relevant tools from {total_count} available")
async def stream_tool_execution(self, tool_name: str, step: int, total: int):
"""Stream tool execution progress."""
await self.stream_log(f"🔍 Executing tool {step}/{total}: {tool_name}")
async def stream_research_results(self, result_count: int, total_chars: int = None):
"""Stream research results summary."""
if total_chars:
await self.stream_log(f"✅ MCP research completed: {result_count} results obtained ({total_chars:,} chars)")
else:
await self.stream_log(f"✅ MCP research completed: {result_count} results obtained")
async def stream_error(self, error_msg: str):
"""Stream error messages."""
await self.stream_log(f"❌ {error_msg}")
async def stream_warning(self, warning_msg: str):
"""Stream warning messages."""
await self.stream_log(f"⚠️ {warning_msg}")
async def stream_info(self, info_msg: str):
"""Stream informational messages."""
await self.stream_log(f"ℹ️ {info_msg}")