Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(api): managed local-realtime server routes (preflight/install/status/uninstall)

rubenluetke10-beepb4962238e32b
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index 50f91b68a4..43b40831b3 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -391,6 +391,24 @@ def _local_runtime_payload(
}
+def _managed_server_payload(spec: ProviderSpec) -> dict[str, Any] | None:
+ """Fail-closed state of the managed local realtime server; None elsewhere.
+
+ Same doctrine as ``_local_runtime_payload``: the card renders the
+ server-side sentence verbatim and never guesses readiness client-side.
+ Only the self-hosted realtime card carries a managed install.
+ """
+ if spec.id != "local-realtime":
+ return None
+ try:
+ from jarvis.realtime.local_server.install import server_status
+
+ return server_status()
+ except Exception as exc: # noqa: BLE001 — the provider list must never 500
+ log.debug("Managed-server probe failed (%s); reporting none.", exc)
+ return None
+
+
def _installed_local_models(provider_id: str, models: list[Any]) -> list[Any]:
"""Drop catalog entries whose files are not on this machine.
@@ -600,6 +618,9 @@ def _spec_to_payload(
"local_runtime": _local_runtime_payload(
spec, model_override=local_model_override
),
+ # Self-hosted realtime card only: state of the one-click managed
+ # server install (fail-closed, server sentence rendered verbatim).
+ "managed_server": _managed_server_payload(spec),
# Gemini's AI-Studio-vs-Vertex split; None for single-path providers.
"alt_credential": (
{
@@ -2643,6 +2664,74 @@ async def get_local_install_status(provider_id: str) -> dict[str, Any]:
return result
[email protected]("/providers/local-realtime/managed-server/preflight")
+async def managed_server_preflight() -> dict[str, Any]:
+ """Honest go/no-go for the one-click local realtime install (AD-5/AD-10).
+
+ Reports usable accelerator memory, the picked tier with download size and
+ expected latency, disk headroom, and the resolved brain — or the blocker
+ (12 GB floor, full disk, no brain) with the exact fixing actions. Runs
+ read-only probes only; nothing downloads here.
+ """
+ from jarvis.realtime.local_server.install import install_root
+ from jarvis.realtime.local_server.preflight import report_payload, run_preflight
+
+ report = await asyncio.to_thread(run_preflight, install_root())
+ return report_payload(report)
+
+
[email protected]("/providers/local-realtime/managed-server/install")
+async def managed_server_install() -> dict[str, Any]:
+ """Start (or join) the one-click managed server install.
+
+ Returns immediately with the poll-shaped progress snapshot; the heavy
+ lifting (venv, pinned packages, vendored patch, first smoke boot that
+ downloads the models) runs in a background thread. A second call while
+ a run is in flight joins it instead of starting a duplicate.
+ """
+ from jarvis.realtime.local_server.install import snapshot, start_install
+
+ started, message = await asyncio.to_thread(start_install)
+ payload = snapshot()
+ payload["started"] = started
+ payload["message"] = message
+ return payload
+
+
[email protected]("/providers/local-realtime/managed-server/status")
+async def managed_server_status() -> dict[str, Any]:
+ """Install progress AND the independent fail-closed readiness probe.
+
+ The on-disk probe is the authority (same doctrine as the on-device
+ speech installs): a tree installed by an earlier app run reads as ready,
+ and a finished install with a missing component reads as incomplete.
+ """
+ from jarvis.realtime.local_server.install import server_status, snapshot
+
+ progress = snapshot()
+ status = await asyncio.to_thread(server_status)
+ return {"progress": progress, "server": status}
+
+
+ "/providers/local-realtime/managed-server",
+ openapi_extra={"x-jarvis-dangerous": True},
+)
+async def managed_server_uninstall() -> dict[str, Any]:
+ """Remove the managed install tree (venv, markers, logs).
+
+ Deliberately dangerous-flagged: this deletes gigabytes that took a long
+ download to assemble. The shared HF model cache is NOT touched — other
+ local features may use the same checkpoints.
+ """
+ from jarvis.realtime.local_server.install import uninstall
+
+ ok, message = await asyncio.to_thread(uninstall)
+ if not ok:
+ raise HTTPException(status_code=409, detail=message)
+ return {"ok": True, "message": message}
+
+
def _require_pull_capable(provider_id: str) -> None:
"""404 for an unknown card, 400 for one whose server cannot be told to pull.
diff --git a/pyproject.toml b/pyproject.toml
index 6bc2276fa8..cd1e5c559a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -789,9 +789,11 @@ jarvis = [
# In-repo C source for the macOS stub launcher, compiled at install time
# by jarvis/setup/macos_app_bundle.py (BUG-060 stable TCC identity).
"setup/*.c",
- # Vendored upstream patch for the managed local-realtime server install
- # (realtime/local_server/patching.py reads it via Path(__file__)).
+ # Vendored upstream patch + pinned package set for the managed
+ # local-realtime server install (realtime/local_server/patching.py and
+ # install.py read them via Path(__file__)).
"realtime/local_server/patches/*.patch",
+ "realtime/local_server/pins/*.txt",
]
[tool.setuptools.data-files]
diff --git a/tests/unit/ui/web/test_managed_local_realtime_routes.py b/tests/unit/ui/web/test_managed_local_realtime_routes.py
new file mode 100644
index 0000000000..2528905629
--- /dev/null
+++ b/tests/unit/ui/web/test_managed_local_realtime_routes.py
@@ -0,0 +1,117 @@
+"""Routes for the one-click managed local realtime server install.
+
+Pins: the preflight surfaces the honest blocker payload untouched, install
+returns immediately with the poll snapshot, status pairs progress with the
+fail-closed on-disk probe, uninstall refuses while a run is live (409), and
+the local-realtime card carries the managed_server payload while cloud
+cards carry None.
+"""
+
+from __future__ import annotations
+
+import pytest
+from fastapi.testclient import TestClient
+
+from jarvis.core.bus import EventBus
+from jarvis.core.config import JarvisConfig
+from jarvis.realtime.local_server import brain_link, install, preflight
+from jarvis.ui.web.server import WebServer
+
+
+def server(tmp_path, monkeypatch: pytest.MonkeyPatch) -> WebServer:
+ monkeypatch.setenv("JARVIS_DATA_DIR", str(tmp_path))
+ cfg = JarvisConfig()
+ cfg.ui.dev_mode = True
+ srv = WebServer(cfg, bus=EventBus())
+ srv.app.state.config = cfg
+ return srv
+
+
+def test_preflight_reports_the_floor_blocker(
+ server: WebServer, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(preflight, "_usable_accelerator_gb", lambda: (4.0, "nvidia-smi"))
+ with TestClient(server.app) as client:
+ resp = client.get("/api/providers/local-realtime/managed-server/preflight")
+ assert resp.status_code == 200
+ body = resp.json()
+ assert body["ok"] is False
+ assert "minimum" in body["blocker"]
+ assert body["tier"] is None
+ assert body["actions"]
+
+
+def test_preflight_reports_tier_and_brain_when_ok(
+ server: WebServer, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(preflight, "_usable_accelerator_gb", lambda: (16.0, "nvidia-smi"))
+ monkeypatch.setattr(preflight, "_disk_free_gb", lambda root: 200.0)
+ monkeypatch.setattr(
+ preflight,
+ "resolve_brain",
+ lambda: brain_link.BrainResolution(
+ kind="ollama", base_url="http://127.0.0.1:11434/v1", model="qwen2.5:7b"
+ ),
+ )
+ with TestClient(server.app) as client:
+ resp = client.get("/api/providers/local-realtime/managed-server/preflight")
+ body = resp.json()
+ assert body["ok"] is True
+ assert body["tier"]["key"] == "t1-16gb"
+ assert body["tier"]["download_gb"] > 0
+ assert body["brain"]["kind"] == "ollama"
+
+
+def test_install_returns_immediately_with_snapshot(
+ server: WebServer, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(install, "start_install", lambda: (True, "install started"))
+ with TestClient(server.app) as client:
+ resp = client.post("/api/providers/local-realtime/managed-server/install")
+ body = resp.json()
+ assert resp.status_code == 200
+ assert body["started"] is True
+ assert body["message"] == "install started"
+ assert "phase" in body and "percent" in body
+
+
+def test_status_pairs_progress_with_failclosed_probe(server: WebServer) -> None:
+ with TestClient(server.app) as client:
+ resp = client.get("/api/providers/local-realtime/managed-server/status")
+ body = resp.json()
+ assert set(body) == {"progress", "server"}
+ # Nothing is installed under the tmp data dir: readiness must be False
+ # with the exact not-installed sentence, never a guess.
+ assert body["server"]["ready"] is False
+ assert body["server"]["sentence"] == "Managed server not installed."
+
+
+def test_uninstall_refuses_while_running(
+ server: WebServer, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(install, "uninstall", lambda: (False, "an install is running"))
+ with TestClient(server.app) as client:
+ resp = client.delete("/api/providers/local-realtime/managed-server")
+ assert resp.status_code == 409
+
+
+def test_uninstall_reports_success(server: WebServer, monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(install, "uninstall", lambda: (True, "nothing installed"))
+ with TestClient(server.app) as client:
+ resp = client.delete("/api/providers/local-realtime/managed-server")
+ assert resp.status_code == 200
+ assert resp.json()["ok"] is True
+
+
+def test_card_payload_carries_managed_server_only_on_local_realtime(
+ server: WebServer,
+) -> None:
+ with TestClient(server.app) as client:
+ resp = client.get("/api/providers")
+ assert resp.status_code == 200
+ providers = {p["id"]: p for p in resp.json()["providers"]}
+ assert providers["local-realtime"]["managed_server"] is not None
+ assert "sentence" in providers["local-realtime"]["managed_server"]
+ cloud = next(p for pid, p in providers.items() if pid != "local-realtime")
+ assert cloud["managed_server"] is None