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(realtime): GET/PUT /api/settings/voice-mode with in-app persist

Ruben Lütke8dd6d17c4b75
diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.py
index eb44471f7b..0f86d34929 100644
--- a/jarvis/ui/web/settings_routes.py
+++ b/jarvis/ui/web/settings_routes.py
@@ -34,6 +34,7 @@ from fastapi import APIRouter, HTTPException, Request
from pydantic import BaseModel, Field, model_validator
from jarvis.brain.manager import SUPPORTED_REPLY_LANGUAGES
+from jarvis.core.config import get_provider_secret
from jarvis.memory.wiki.integration import get_running_curator
if TYPE_CHECKING:
@@ -106,6 +107,61 @@ async def put_reply_language(body: ReplyLanguageBody, request: Request) -> dict[
return {"ok": True, "language": lang, "persisted": persisted}
+# ---------------------------------------------------------------------------
+# Voice mode: pipeline (the classic STT→Brain→TTS pipeline) vs realtime (the
+# browser-based OpenAI/Gemini full-duplex realtime engine). GET current mode +
+# whether realtime is actually reachable (needs an OpenAI key); PUT to switch.
+# Persisted to jarvis.toml [voice].mode via config_writer.set_voice_mode
+# (Task 1); the persist is best-effort so a locked/read-only toml never blocks
+# the live in-memory switch that already succeeded. See
+# docs/realtime-voice/PLAN-phase-0-1.md Task 8.
+# ---------------------------------------------------------------------------
+
+_VOICE_MODES = ("pipeline", "realtime")
+
+
+class VoiceModeBody(BaseModel):
+ mode: str = Field(..., min_length=1)
+ persist: bool = Field(default=True, description="Persist as boot default in jarvis.toml")
+
+
[email protected]("/voice-mode")
+async def get_voice_mode(request: Request) -> dict[str, object]:
+ cfg = getattr(request.app.state, "config", None) or getattr(request.app.state, "cfg", None)
+ mode = getattr(getattr(cfg, "voice", None), "mode", "pipeline")
+ available = bool(get_provider_secret("openai"))
+ return {
+ "mode": mode,
+ "realtime_available": available,
+ "active_provider": "openai-realtime" if available else None,
+ }
+
+
[email protected]("/voice-mode")
+async def put_voice_mode(body: VoiceModeBody, request: Request) -> dict[str, object]:
+ if body.mode not in _VOICE_MODES:
+ raise HTTPException(status_code=400, detail=f"mode must be one of {_VOICE_MODES}")
+
+ cfg = getattr(request.app.state, "config", None) or getattr(request.app.state, "cfg", None)
+ if cfg is not None and getattr(cfg, "voice", None) is not None:
+ try:
+ cfg.voice.mode = body.mode # type: ignore[attr-defined]
+ except Exception as exc: # noqa: BLE001 — frozen model is not an error
+ log.debug("in-memory cfg.voice.mode update skipped: %s", exc)
+
+ persisted = False
+ if body.persist:
+ try:
+ from jarvis.core import config_writer
+
+ config_writer.set_voice_mode(body.mode)
+ persisted = True
+ except Exception as exc: # noqa: BLE001
+ log.warning("voice-mode persist failed (live switch still applied): %s", exc)
+
+ return {"ok": True, "mode": body.mode, "persisted": persisted}
+
+
# ----------------------------------------------------------------------
# Team / hosted-proxy mode ([team_proxy]) — 2026-06-20 team-proxy spec §4.
# One global switch: when enabled with a url, every provider not in
diff --git a/tests/unit/web/test_voice_mode_route.py b/tests/unit/web/test_voice_mode_route.py
index 84215311bd..eb616fff3d 100644
--- a/tests/unit/web/test_voice_mode_route.py
+++ b/tests/unit/web/test_voice_mode_route.py
@@ -13,7 +13,11 @@ from __future__ import annotations
from types import SimpleNamespace
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
from jarvis.browser_voice.route import _browser_voice_enabled
+from jarvis.ui.web.settings_routes import router
def test_gate_default_off_when_pipeline_and_no_browser_voice():
@@ -31,3 +35,51 @@ def test_gate_on_for_explicit_classic_browser_voice():
voice=SimpleNamespace(mode="pipeline"), browser_voice=SimpleNamespace(enabled=True)
)
assert _browser_voice_enabled(cfg) is True
+
+
+# ---------------------------------------------------------------------------
+# Task 8 — GET/PUT /api/settings/voice-mode route handlers.
+# ---------------------------------------------------------------------------
+
+
+def _app(mode="pipeline", key="sk-x", monkeypatch=None):
+ app = FastAPI()
+ app.include_router(router)
+ app.state.config = SimpleNamespace(voice=SimpleNamespace(mode=mode))
+ return app
+
+
+def test_get_voice_mode(monkeypatch):
+ import jarvis.ui.web.settings_routes as sr
+ monkeypatch.setattr(sr, "get_provider_secret", lambda _p: "sk-x")
+ client = TestClient(_app(mode="realtime"))
+ r = client.get("/api/settings/voice-mode")
+ assert r.status_code == 200
+ body = r.json()
+ assert body["mode"] == "realtime"
+ assert body["realtime_available"] is True
+
+
+def test_put_voice_mode_invalid_is_400():
+ client = TestClient(_app())
+ r = client.put("/api/settings/voice-mode", json={"mode": "bogus", "persist": False})
+ assert r.status_code == 400
+
+
+def test_put_voice_mode_updates_live_and_persists(monkeypatch):
+ import jarvis.ui.web.settings_routes as sr
+ persisted = {"called": False}
+ monkeypatch.setattr(sr, "get_provider_secret", lambda _p: "sk-x")
+
+ def fake_set(mode, **kw):
+ persisted["called"] = True
+
+ import jarvis.core.config_writer as cw
+ monkeypatch.setattr(cw, "set_voice_mode", fake_set)
+ app = _app()
+ client = TestClient(app)
+ r = client.put("/api/settings/voice-mode", json={"mode": "realtime", "persist": True})
+ assert r.status_code == 200
+ assert r.json() == {"ok": True, "mode": "realtime", "persisted": True}
+ assert app.state.config.voice.mode == "realtime"
+ assert persisted["called"] is True