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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(realtime): make activation reflect Realtime as the active voice mode
Ruben Lütke07bdd31b04e3
diff --git a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.tsindex 4a981ea4e9..a1ac1b941e 100644--- a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts+++ b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts@@ -1,3 +1,4 @@+import { useEffect } from "react";import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";type VoiceModeResp = { mode: string; realtime_available: boolean; active_provider: string | null };@@ -20,6 +21,21 @@ export function useVoiceMode() {},onSuccess: () => qc.invalidateQueries({ queryKey: ["voice-mode"] }),});++ // Activating a realtime provider CARD (ApiKeysView's ProviderCategory, the+ // "Set active" action on a Realtime tier card) flips `[voice].mode`+ // server-side too (provider_routes.py::realtime_switch, Feature A4) — that+ // write bypasses this hook's own mutation, so the "Active" badge would+ // otherwise go stale until an unrelated refetch. Listen for the event the+ // card activation already dispatches and refresh here.+ useEffect(() => {+ function onRealtimeSwitched() {+ qc.invalidateQueries({ queryKey: ["voice-mode"] });+ }+ window.addEventListener("jarvis:realtime-switched", onRealtimeSwitched);+ return () => window.removeEventListener("jarvis:realtime-switched", onRealtimeSwitched);+ }, [qc]);+return {mode: q.data?.mode ?? "pipeline",realtimeAvailable: q.data?.realtime_available ?? false,diff --git a/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx b/jarvis/ui/web/frontend/src/views/ApiKeysView.tsxindex e692fbdaf1..ef48b43aa2 100644--- a/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx+++ b/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx@@ -43,11 +43,12 @@ import { useT } from "@/i18n";// so it never competes with the five core categories.type CategoryKey = ProviderTier | "subagents" | "advanced";-// The top-level engine mode. This is a VIEW-ONLY switch (D1, binding): it only-// decides which tab set is shown, and NEVER writes `[voice].mode` or flips the-// live voice engine — that stays a deliberate, separately-gated action. The-// "Active" badge (seeded from the existing `useVoiceMode` hook) is the only-// place the live engine state is read here, purely for display.+// The top-level engine mode. Feature A supersedes design D1 ("view-only"):+// the switch now decides which tab set is shown AND persists `[voice].mode`+// via `useVoiceMode().setMode` — Pipeline always (it's always reachable),+// Realtime only when a realtime provider actually has a key+// (`realtimeAvailable`), so the switch can never pin the boot default to an+// unreachable engine. See `EngineModeSwitch` below for the exact rule.type VoiceEngineMode = "pipeline" | "realtime";// Realtime replaces STT+Brain+TTS with one full-duplex model, so those three@@ -109,9 +110,10 @@ export function ApiKeysView() {const categories = makeProviderCategories(t);const [active, setActive] = useState<CategoryKey>("brain");const [engineMode, setEngineMode] = useState<VoiceEngineMode>("pipeline");- // Read the LIVE `[voice].mode` for the "Active" badge only — never written- // back to from here. See VoiceEngineMode / EngineModeSwitch above.- const { mode: liveMode } = useVoiceMode();+ // The LIVE `[voice].mode` (+ cross-family availability) for the "Active"+ // badge AND for gating the segment's own persistence (Feature A). See+ // VoiceEngineMode / EngineModeSwitch above.+ const { mode: liveMode, realtimeAvailable, setMode: setVoiceMode } = useVoiceMode();// Reset the selected tab to the mode's first tab whenever the mode changes,// so switching Pipeline→Realtime never leaves `active` pointing at a tab@@ -130,7 +132,13 @@ export function ApiKeysView() {subtitle={t("apikeys_view.subtitle")}/>- <EngineModeSwitch mode={engineMode} liveMode={liveMode} onSelect={setEngineMode} />+ <EngineModeSwitch+ mode={engineMode}+ liveMode={liveMode}+ realtimeAvailable={realtimeAvailable}+ onSelect={setEngineMode}+ onSetVoiceMode={setVoiceMode}+ /><CategoryTabs active={active} onSelect={setActive} health={health} tabs={modeTabs} />@@ -158,22 +166,30 @@ export function ApiKeysView() {}/**- * The Pipeline|Realtime segmented VIEW switch (D1, binding). Clicking a- * segment ONLY calls `onSelect` (local view-state) — it must NEVER write- * `[voice].mode` or call any voice-mode mutation. The segment whose value- * matches the LIVE `[voice].mode` (from `useVoiceMode`, read-only here) shows- * a small "Active" badge, so the user always sees which engine is actually- * running without the switch itself being able to change it.+ * The Pipeline|Realtime segmented switch. Feature A (supersedes D1): clicking+ * a segment still switches the local view (`onSelect`), and ALSO persists+ * `[voice].mode` — Pipeline unconditionally (always reachable), Realtime only+ * when `realtimeAvailable` (a key is present for some realtime family);+ * otherwise the click just switches the view so the user can add a key from+ * the Realtime tab without silently pinning the boot default to a dead+ * engine. The segment whose value matches the LIVE `[voice].mode` (from+ * `useVoiceMode`) shows a small "Active" badge.*/function EngineModeSwitch({mode,liveMode,+ realtimeAvailable,onSelect,+ onSetVoiceMode,}: {mode: VoiceEngineMode;- /** The live `[voice].mode` value, for the "Active" badge only. */+ /** The live `[voice].mode` value, for the "Active" badge. */liveMode: string;+ /** Whether SOME realtime family (OpenAI/Gemini) has a key configured. */+ realtimeAvailable: boolean;onSelect: (mode: VoiceEngineMode) => void;+ /** Persists `[voice].mode` — gated per the rule above. */+ onSetVoiceMode: (mode: string) => void;}) {const t = useT();const segments: { key: VoiceEngineMode; label: string }[] = [@@ -181,6 +197,13 @@ function EngineModeSwitch({{ key: "realtime", label: t("apikeys_view.mode_realtime") },];+ function handleSelect(seg: VoiceEngineMode) {+ onSelect(seg);+ if (seg === "pipeline" || realtimeAvailable) {+ onSetVoiceMode(seg);+ }+ }+return (<div className="border-b border-border px-6 pt-4"><div className="inline-flex items-center gap-1 rounded-xl border border-border bg-card/40 p-1">@@ -188,7 +211,7 @@ function EngineModeSwitch({<buttonkey={seg.key}type="button"- onClick={() => onSelect(seg.key)}+ onClick={() => handleSelect(seg.key)}aria-pressed={mode === seg.key}className={cn("inline-flex items-center gap-2 rounded-lg px-3.5 py-1.5 text-sm font-medium transition-colors",diff --git a/jarvis/ui/web/frontend/src/views/ApiKeysView.two-mode.test.tsx b/jarvis/ui/web/frontend/src/views/ApiKeysView.two-mode.test.tsxindex 3e6885a422..ef5dfc10d0 100644--- a/jarvis/ui/web/frontend/src/views/ApiKeysView.two-mode.test.tsx+++ b/jarvis/ui/web/frontend/src/views/ApiKeysView.two-mode.test.tsx@@ -1,11 +1,13 @@/**- * Component tests for the Pipeline|Realtime segmented VIEW switch on the+ * Component tests for the Pipeline|Realtime segmented switch on the* API-Keys screen.*- * D1 (binding): the switch is VIEW-ONLY. It must never write `[voice].mode`- * or call any voice-mode mutation — only the existing, separately-gated- * activation path does that. These tests pin (1) the mode-derived tab sets- * and (2) that clicking a segment never fires the `useVoiceMode` mutation.+ * Feature A (supersedes D1): the segment is a real mode control. Clicking a+ * segment still switches the local VIEW, but now ALSO persists+ * `[voice].mode` via `useVoiceMode().setMode` — Pipeline always, Realtime+ * only when `realtimeAvailable` is true (a key is actually configured for+ * some realtime family). These tests pin (1) the mode-derived tab sets and+ * (2) the setMode call pattern for both availability states.*/import { afterEach, describe, expect, it, vi } from "vitest";import { cleanup, fireEvent, render, screen } from "@testing-library/react";@@ -25,12 +27,16 @@ vi.mock("@/hooks/useProviders", () => ({// The real `useVoiceMode` hook (jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts)// returns { mode, realtimeAvailable, setMode, isLoading, isSaving } — mock that-// exact shape so the "Active" badge + the D1 no-mutation assertion are real.+// exact shape so the "Active" badge + the setMode assertions below are real.+// `mockRealtimeAvailable` is mutable per-test (declared via `let` above the+// `vi.mock` call, matching this file's existing hoisting pattern) so the+// "realtime unavailable" describe block below can flip it.+let mockRealtimeAvailable = true;const putVoiceMode = vi.fn();vi.mock("@/hooks/useVoiceMode", () => ({useVoiceMode: () => ({mode: "pipeline",- realtimeAvailable: true,+ realtimeAvailable: mockRealtimeAvailable,setMode: putVoiceMode,isLoading: false,isSaving: false,@@ -42,6 +48,7 @@ import { ApiKeysView } from "@/views/ApiKeysView";afterEach(() => {cleanup();vi.clearAllMocks();+ mockRealtimeAvailable = true;});describe("ApiKeysView two-mode", () => {@@ -67,7 +74,7 @@ describe("ApiKeysView two-mode", () => {expect(realtimeSegment.textContent).not.toMatch(/active/i);});- it("switching to Realtime mode shows only Realtime/Subagents/Advanced and NEVER writes voice-mode", () => {+ it("switching to Realtime mode shows only Realtime/Subagents/Advanced and persists voice-mode (available)", () => {render(<ApiKeysView />);fireEvent.click(screen.getByRole("button", { name: /^realtime$/i })); // the segment@@ -78,18 +85,43 @@ describe("ApiKeysView two-mode", () => {expect(screen.queryByRole("tab", { name: /voice output/i })).toBeNull();expect(screen.queryByRole("tab", { name: /voice input/i })).toBeNull();- // D1 (binding): the segment switch is view-only — it must never mutate- // the live voice engine.- expect(putVoiceMode).not.toHaveBeenCalled();+ // Feature A (supersedes D1): with a realtime provider actually reachable+ // (mocked realtimeAvailable=true), the segment now persists the mode.+ expect(putVoiceMode).toHaveBeenCalledWith("realtime");});- it("switching back to Pipeline restores the five pipeline tabs, still without mutating voice-mode", () => {+ it("switching back to Pipeline restores the five pipeline tabs and always persists voice-mode", () => {render(<ApiKeysView />);fireEvent.click(screen.getByRole("button", { name: /^realtime$/i }));+ putVoiceMode.mockClear();fireEvent.click(screen.getByRole("button", { name: /pipeline/i }));expect(screen.getByRole("tab", { name: /brain/i })).toBeTruthy();expect(screen.queryByRole("tab", { name: /realtime/i })).toBeNull();+ // Pipeline always persists — it is always reachable (no key gate needed).+ expect(putVoiceMode).toHaveBeenCalledWith("pipeline");+ });+});++describe("ApiKeysView two-mode — realtime unavailable (no key in any family)", () => {+ it("switching to Realtime still switches the view, but does NOT persist voice-mode", () => {+ mockRealtimeAvailable = false;+ render(<ApiKeysView />);+ fireEvent.click(screen.getByRole("button", { name: /^realtime$/i }));++ // The view still switches, so the user can add a key from the Realtime tab.+ expect(screen.getByRole("tab", { name: /realtime/i })).toBeTruthy();+ // But nothing is reachable yet — never pin [voice].mode to a dead engine.expect(putVoiceMode).not.toHaveBeenCalled();});++ it("switching back to Pipeline still persists voice-mode even when realtime is unavailable", () => {+ mockRealtimeAvailable = false;+ render(<ApiKeysView />);+ fireEvent.click(screen.getByRole("button", { name: /^realtime$/i }));+ putVoiceMode.mockClear();+ fireEvent.click(screen.getByRole("button", { name: /pipeline/i }));++ expect(putVoiceMode).toHaveBeenCalledWith("pipeline");+ });});diff --git a/tests/unit/web/test_voice_mode_route.py b/tests/unit/web/test_voice_mode_route.pyindex 0b4d71c9d7..3a40666bb5 100644--- a/tests/unit/web/test_voice_mode_route.py+++ b/tests/unit/web/test_voice_mode_route.py@@ -65,7 +65,11 @@ def test_get_voice_mode_cross_family_gemini_only(monkeypatch):"""Feature A2: realtime_available must NOT be OpenAI-only — a user withonly a Gemini key gets realtime_available=true, active_provider=gemini-live."""import jarvis.realtime.factory as rf- monkeypatch.setattr(rf, "get_provider_secret", lambda name: "sk-x" if name == "gemini" else None)++ def only_gemini(name: str) -> str | None:+ return "sk-x" if name == "gemini" else None++ monkeypatch.setattr(rf, "get_provider_secret", only_gemini)client = TestClient(_app(mode="pipeline"))r = client.get("/api/settings/voice-mode")assert r.status_code == 200