feat: remove saved Ollama connection configs

This commit is contained in:
Hermes Agent
2026-08-24 22:35:42 +10:00
parent a9e8c63791
commit f45fbf0b1b
6 changed files with 34 additions and 9 deletions
+22 -4
View File
@@ -310,8 +310,7 @@ def _apply_saved_connection() -> None:
LOCAL_OLLAMA = saved
return
configured = os.environ.get("OLLAMA_HOST", "").strip()
if configured:
LOCAL_OLLAMA = configured.rstrip("/")
LOCAL_OLLAMA = configured.rstrip("/") if configured else _ollama_base_url()
def _target_endpoint(target: str = "local") -> str:
@@ -362,9 +361,9 @@ def _connection_snapshot() -> list[dict[str, Any]]:
seen.add(key)
try:
result = _probe_endpoint(normalized, timeout=3)
result.update({"kind": kind, "label": label})
result.update({"kind": kind, "label": label, "saved": saved.get(f"{kind}_url") == normalized})
except Exception as exc:
result = {"available": False, "kind": kind, "label": label, "url": normalized, "error": str(exc)[:240]}
result = {"available": False, "kind": kind, "label": label, "url": normalized, "saved": saved.get(f"{kind}_url") == normalized, "error": str(exc)[:240]}
results.append(result)
local_urls = {row.get("url") for row in results if row.get("kind") == "local" and row.get("available")}
for row in results:
@@ -1512,6 +1511,25 @@ def connections_configure(body: ConnectionRequest) -> dict[str, Any]:
return result
@router.delete("/connections/{role}")
def connections_delete(role: str) -> dict[str, Any]:
role = str(role or "").strip().lower()
if role not in {"local", "remote"}:
raise HTTPException(400, "Connection role must be local or remote")
saved = _read_connections()
key = f"{role}_url"
removed = saved.get(key, "")
if not removed:
raise HTTPException(404, f"No saved {role} Ollama endpoint")
saved[key] = ""
if role == "local":
saved["active_url"] = ""
_write_connections(saved)
if role == "local":
_apply_saved_connection()
return {"ok": True, "role": role, "removed_url": removed, "message": f"Removed saved {role} Ollama endpoint"}
@router.get("/status")
def status() -> dict[str, Any]:
tags = _local_tags()