""" Routing-Gateway-Status. Seit UMBAU v3 P1 bedient der EIGENSTÄNDIGE mc2-gateway- Prozess den /v1-Pfad (MC_V1_UPSTREAM gesetzt, MC2 reicht nur roh durch); ohne V1_UPSTREAM gilt der alte eingebaute Modus (MC2 serviert /v1 selbst). """ import httpx from config import PORT, V1_UPSTREAM from services.llamaswap import engine_reachable from services.routing_policy import load_policy def routing_summary() -> dict: p = load_policy() coding_default = p["coder_lite"] or p["coder"] return { "mode": "gateway (eigener Prozess)" if V1_UPSTREAM else "builtin", "endpoint": f":{PORT}/v1 (OpenAI-kompatibel)", # Virtuelle Lanes, die Clients/IDEs als „Modell" wählen (Router pickt das echte Alias). "lanes": [ { "name": "chat", "aka": "auto", "target": f"{p['fast']} ↔ {p['heavy']} (nach Komplexität)", "threshold_chars": p["heavy_chars"], }, { "name": "coding", "target": f"{coding_default} ↔ {p['coder']} (Eskalation)", "escalate_chars": p["coding_escalate_chars"], }, ], # Rückwärtskompatible Flach-Liste (alte UI/Clients). "routes": [ {"name": "chat", "target": f"{p['fast']} ↔ {p['heavy']} (nach Komplexität)"}, {"name": "coding", "target": f"{coding_default} ↔ {p['coder']} (Eskalation)"}, {"name": "", "target": "llama-swap-Passthrough (lädt bei Bedarf)"}, ], "heavy_threshold_chars": p["heavy_chars"], "fallbacks": [], "context_window_fallbacks": [], } def gateway_reachable() -> bool: """Erreichbarkeit des ECHTEN Denkpfads. Mit V1_UPSTREAM ist das der eigenständige mc2-gateway-Prozess (:9010) — vorher meldete diese Funktion nur die Engine, d. h. ein toter Gateway blieb in Health/Diensten/Cockpit unsichtbar (Review 15.07.).""" if V1_UPSTREAM: try: return httpx.get(f"{V1_UPSTREAM}/v1/models", timeout=2.0).status_code == 200 except Exception: # noqa: BLE001 return False # Eingebauter Modus: der Gateway lebt in MC selbst und proxyt llama-swap. return engine_reachable()