|
1 | | -"""GET /api/molecules/{session_id}.""" |
2 | | - |
3 | | -from fastapi import APIRouter, HTTPException |
4 | | - |
5 | | -router = APIRouter() |
6 | | - |
7 | | - |
8 | | -@router.get("/molecules/{session_id}") |
9 | | -async def get_molecules(session_id: str): |
10 | | - from agents.OrchestratorAgent import _sessions |
11 | | - |
12 | | - state = _sessions.get(session_id) |
13 | | - if not state: |
14 | | - raise HTTPException(status_code=404, detail="Session not found") |
15 | | - return { |
16 | | - "session_id": session_id, |
17 | | - "query": state.get("query"), |
18 | | - "mutation_context": state.get("mutation_context"), |
19 | | - "literature": state.get("literature", []), |
20 | | - "structures": state.get("structures", []), |
21 | | - "pdb_content": state.get("pdb_content", ""), |
22 | | - "binding_pocket": state.get("binding_pocket"), |
23 | | - "pocket_detection_method": state.get("pocket_detection_method"), |
24 | | - "pocket_delta": state.get("pocket_delta"), |
25 | | - "generated_molecules": state.get("generated_molecules", []), |
26 | | - "docking_results": state.get("docking_results", []), |
27 | | - "selectivity_results": state.get("selectivity_results", []), |
28 | | - "admet_profiles": state.get("admet_profiles", []), |
29 | | - "toxicophore_highlights": state.get("toxicophore_highlights", []), |
30 | | - "optimized_leads": state.get("optimized_leads", []), |
31 | | - "evolution_tree": state.get("evolution_tree"), |
32 | | - "similar_compounds": state.get("similar_compounds", []), |
33 | | - "synergy_predictions": state.get("synergy_predictions", []), |
34 | | - "clinical_trials": state.get("clinical_trials", []), |
35 | | - "knowledge_graph": state.get("knowledge_graph"), |
36 | | - "reasoning_trace": state.get("reasoning_trace"), |
37 | | - "summary": state.get("summary"), |
38 | | - "resistance_forecast": state.get("resistance_forecast"), |
39 | | - "resistant_drugs": state.get("resistant_drugs", []), |
40 | | - "recommended_drugs": state.get("recommended_drugs", []), |
41 | | - "final_report": state.get("final_report"), |
42 | | - "status": state.get("status"), |
43 | | - "cancelled": state.get("cancelled", False), |
44 | | - "agent_statuses": state.get("agent_statuses", {}), |
45 | | - "execution_time_ms": state.get("execution_time_ms", 0), |
46 | | - "langsmith_run_id": state.get("langsmith_run_id"), |
47 | | - "llm_provider_used": state.get("llm_provider_used", "unknown"), |
48 | | - } |
| 1 | +"""GET /api/molecules/{session_id}.""" |
| 2 | + |
| 3 | +from fastapi import APIRouter, HTTPException |
| 4 | + |
| 5 | +router = APIRouter() |
| 6 | + |
| 7 | + |
| 8 | +@router.get("/molecules/{session_id}") |
| 9 | +async def get_molecules(session_id: str): |
| 10 | + import agents.OrchestratorAgent # Import module, not variable |
| 11 | + |
| 12 | + state = agents.OrchestratorAgent._sessions.get(session_id) |
| 13 | + |
| 14 | + # Not in memory (backend restarted) — try recovering from Neon |
| 15 | + if not state: |
| 16 | + try: |
| 17 | + from utils.db import get_session_by_session_id |
| 18 | + state = await get_session_by_session_id(session_id) |
| 19 | + except Exception: |
| 20 | + state = None |
| 21 | + |
| 22 | + if not state: |
| 23 | + raise HTTPException(status_code=404, detail="Session not found") |
| 24 | + |
| 25 | + return { |
| 26 | + "session_id": session_id, |
| 27 | + "query": state.get("query"), |
| 28 | + "mutation_context": state.get("mutation_context"), |
| 29 | + "literature": state.get("literature", []), |
| 30 | + "structures": state.get("structures", []), |
| 31 | + "pdb_content": state.get("pdb_content", ""), |
| 32 | + "binding_pocket": state.get("binding_pocket"), |
| 33 | + "pocket_detection_method": state.get("pocket_detection_method"), |
| 34 | + "pocket_delta": state.get("pocket_delta"), |
| 35 | + "generated_molecules": state.get("generated_molecules", []), |
| 36 | + "docking_results": state.get("docking_results", []), |
| 37 | + "selectivity_results": state.get("selectivity_results", []), |
| 38 | + "admet_profiles": state.get("admet_profiles", []), |
| 39 | + "toxicophore_highlights": state.get("toxicophore_highlights", []), |
| 40 | + "optimized_leads": state.get("optimized_leads", []), |
| 41 | + "evolution_tree": state.get("evolution_tree"), |
| 42 | + "similar_compounds": state.get("similar_compounds", []), |
| 43 | + "synergy_predictions": state.get("synergy_predictions", []), |
| 44 | + "clinical_trials": state.get("clinical_trials", []), |
| 45 | + "knowledge_graph": state.get("knowledge_graph"), |
| 46 | + "reasoning_trace": state.get("reasoning_trace"), |
| 47 | + "summary": state.get("summary"), |
| 48 | + "resistance_flags": state.get("resistance_flags", []), |
| 49 | + "resistance_forecast": state.get("resistance_forecast"), |
| 50 | + "resistant_drugs": state.get("resistant_drugs", []), |
| 51 | + "recommended_drugs": state.get("recommended_drugs", []), |
| 52 | + "md_results": state.get("md_results", []), |
| 53 | + "sa_scores": state.get("sa_scores", []), |
| 54 | + "synthesis_routes": state.get("synthesis_routes", []), |
| 55 | + "confidence": state.get("confidence"), |
| 56 | + "confidence_banner": state.get("confidence_banner"), |
| 57 | + "esm1v_score": state.get("esm1v_score"), |
| 58 | + "esm1v_confidence": state.get("esm1v_confidence"), |
| 59 | + "final_report": state.get("final_report"), |
| 60 | + "status": state.get("status"), |
| 61 | + "cancelled": state.get("cancelled", False), |
| 62 | + "agent_statuses": state.get("agent_statuses", {}), |
| 63 | + "execution_time_ms": state.get("execution_time_ms", 0), |
| 64 | + "langsmith_run_id": state.get("langsmith_run_id"), |
| 65 | + "llm_provider_used": state.get("llm_provider_used", "unknown"), |
| 66 | + "discovery_id": state.get("discovery_id"), |
| 67 | + } |
0 commit comments