INNER CODE UNIT · Python

_register_optional_kg_router

TianGzlab/OmicsClaw · omicsclaw/surfaces/desktop/server.py:417

def _register_optional_kg_router(app: FastAPI) -> None:
    """Mount OmicsClaw-KG under `/kg` when the optional package is available.

    Also records availability in the module-level ``_KG_AVAILABLE`` /
    ``_KG_IMPORT_ERROR`` flags (Bench Phase 3.2) so ``/health`` can tell the
    frontend whether KG-dependent UI should be shown.
    """
    global _KG_AVAILABLE, _KG_IMPORT_ERROR

    kg_source_dir = str(os.getenv("OMICSCLAW_KG_SOURCE_DIR", "") or "").strip()
    if kg_source_dir and kg_source_dir not in sys.path:
        sys.path.insert(0, kg_source_dir)

    if importlib.util.find_spec("omicsclaw_kg") is None:
        _KG_AVAILABLE = False
        _KG_IMPORT_ERROR = "omicsclaw_kg package not found on the import path"
        logger.info("OmicsClaw-KG package not available; skipping embedded KG routes")
        return

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…