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(home): "+ New" starts a run of the kind you are looking at

rubenluetke10-beep736b06cf305a
diff --git a/jarvis/ui/web/chats_routes.py b/jarvis/ui/web/chats_routes.py
index c075557288..c93ccdf52b 100644
--- a/jarvis/ui/web/chats_routes.py
+++ b/jarvis/ui/web/chats_routes.py
@@ -112,6 +112,16 @@ class SpeakResponse(BaseModel):
seeded_turns: int = 0
+class NewVoiceRunResponse(BaseModel):
+ """What "+ New voice chat" actually changed on the backend."""
+
+ #: The brain's conversation buffer was emptied, so the next spoken turn
+ #: starts a thread of its own.
+ cleared: bool = False
+ #: A voice session was still live and has been ended.
+ ended: bool = False
+
+
# ----------------------------------------------------------------------
# DI helpers
# ----------------------------------------------------------------------
@@ -315,6 +325,41 @@ async def create_chat(request: Request, body: NewChatRequest | None = None) -> N
return NewChatResponse(id=str(created["thread_id"]), title=created["title"])
[email protected]("/voice/new", response_model=NewVoiceRunResponse)
+async def new_voice_run(request: Request) -> NewVoiceRunResponse:
+ """Begin a fresh voice run.
+
+ A voice thread lives in two places: the brain's in-memory conversation
+ buffer (which a re-opened chat seeds via ``.../resume``) and the session
+ the pipeline is currently recording under. "+ New voice chat" must reset
+ both, or the "new" run answers out of the old thread and its turns are
+ appended to the session already on disk.
+
+ Declared above ``GET /{kind}/{cid}`` only for readability — the literal
+ path and the parameterized one differ in method, so they never compete.
+
+ Purely in-memory: no LLM call, no I/O, nothing on the voice critical path
+ (AP-9/AP-11). The microphone is deliberately NOT re-armed; the next wake
+ word or orb click opens the new session.
+ """
+ cleared = False
+ brain = _optional_brain(request)
+ if brain is not None and hasattr(brain, "seed_history"):
+ # An empty seed is the documented equivalent of clear_history() and
+ # works on every brain that can be seeded at all.
+ brain.seed_history([])
+ cleared = True
+
+ ended = False
+ pipeline = _optional_pipeline(request)
+ if pipeline is not None and hasattr(pipeline, "request_voice_hangup"):
+ # Same contract as the hangup key / POST /api/voice/hangup: False
+ # simply means nothing was running, which is the common case.
+ ended = bool(pipeline.request_voice_hangup())
+
+ return NewVoiceRunResponse(cleared=cleared, ended=ended)
+
+
@router.get("/{kind}/{cid}", response_model=ConversationDetail)
async def get_conversation(
kind: ConversationKind, cid: str, request: Request
diff --git a/jarvis/ui/web/frontend/src/components/layout/Sidebar.test.tsx b/jarvis/ui/web/frontend/src/components/layout/Sidebar.test.tsx
index 97181ba40a..74e29eecb0 100644
--- a/jarvis/ui/web/frontend/src/components/layout/Sidebar.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/layout/Sidebar.test.tsx
@@ -9,6 +9,7 @@ import {
SIDEBAR_RAIL_WIDTH,
} from "@/components/layout/Sidebar";
import { useEventStore } from "@/store/events";
+import { useHomeStore } from "@/store/home";
// The sidebar header avatar must mirror the chosen on-screen display style:
// the ghost mascot ONLY when the user explicitly picked "mascot"; the slim bar
@@ -137,6 +138,83 @@ describe("Sidebar voice header", () => {
});
});
+/*
+ * "+ New" starts a conversation of the KIND on screen. Standing on the voice
+ * stage and being thrown onto the chat page was the reported bug: the button
+ * looked like it did nothing you asked for.
+ */
+describe("Sidebar new-conversation button", () => {
+ beforeEach(() => {
+ vi.stubGlobal(
+ "fetch",
+ // GET /api/chats answers with a list, the agent-chat sessions probe with
+ // an empty roster; every other call the mounted sidebar fires gets a
+ // harmless object. An undefined list here crashes the recent-chats block.
+ vi.fn(async (url: string) =>
+ String(url).startsWith("/api/chats")
+ ? new Response(JSON.stringify([]), { status: 200 })
+ : new Response(JSON.stringify({ sessions: [] }), { status: 200 }),
+ ),
+ );
+ useEventStore.setState({
+ connected: true,
+ activeSection: "board",
+ conversations: [],
+ messages: [],
+ activeThreadId: "old-voice-thread",
+ });
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ // The event store is module-global: leaving a fetched-in list behind
+ // would break whichever test file runs next.
+ useEventStore.setState({ conversations: [], messages: [], activeThreadId: null });
+ });
+
+ test("on the voice stage it starts a voice run and stays on Voice", async () => {
+ useHomeStore.setState({
+ surface: "voice",
+ transcript: [{ id: "l1", who: "user", text: "hello", ts: 1 }],
+ });
+
+ renderSidebar();
+ const button = screen.getByTestId("sidebar-new-chat");
+ expect(button.textContent).toContain("New voice chat");
+
+ await act(async () => {
+ button.click();
+ await Promise.resolve();
+ });
+
+ expect(useHomeStore.getState().surface).toBe("voice");
+ expect(useHomeStore.getState().transcript).toEqual([]);
+ // The open voice thread is dropped so the next spoken turn is its own.
+ expect(useEventStore.getState().activeThreadId).toBeNull();
+ const calls = (globalThis.fetch as unknown as { mock: { calls: unknown[][] } }).mock.calls;
+ expect(calls.some((c) => String(c[0]) === "/api/chats/voice/new")).toBe(true);
+ });
+
+ test("on the chat surface it still opens an empty chat", async () => {
+ useHomeStore.setState({ surface: "chat", transcript: [] });
+
+ renderSidebar();
+ const button = screen.getByTestId("sidebar-new-chat");
+ expect(button.textContent).toContain("New chat");
+ expect(button.textContent).not.toContain("voice");
+
+ await act(async () => {
+ button.click();
+ await Promise.resolve();
+ });
+
+ expect(useHomeStore.getState().surface).toBe("chat");
+ const calls = (globalThis.fetch as unknown as { mock: { calls: unknown[][] } }).mock.calls;
+ expect(calls.some((c) => String(c[0]) === "/api/chats/voice/new")).toBe(false);
+ });
+});
+
describe("Sidebar header avatar", () => {
beforeEach(() => {
useEventStore.setState({
diff --git a/jarvis/ui/web/frontend/src/components/layout/Sidebar.tsx b/jarvis/ui/web/frontend/src/components/layout/Sidebar.tsx
index 9cf62a0555..1c665c80d1 100644
--- a/jarvis/ui/web/frontend/src/components/layout/Sidebar.tsx
+++ b/jarvis/ui/web/frontend/src/components/layout/Sidebar.tsx
@@ -114,22 +114,34 @@ export function Sidebar({
// confused; the default app shows nothing here.
const appInstance = useAppInstance();
const devTag = appInstance?.isDev ? appInstance.name.toUpperCase() : null;
- // "+ New chat" lands on the chat surface of the front page with an empty
- // agent chat — the sidebar owns the history now, so it owns this too. The
- // voice thread is cleared as well so a reopened voice session does not
- // linger behind the fresh page.
- const { newChat } = useConversations();
+ // "+ New" starts a conversation of the KIND you are looking at: on the chat
+ // surface an empty agent chat, on the voice stage a fresh voice run. Sending
+ // someone standing in Voice to the chat page is what the one button used to
+ // do, and it read as the button being broken.
+ const { newChat, newVoiceRun } = useConversations();
const newAgentChat = useAgentChatStore((s) => s.newChat);
const setSurface = useHomeStore((s) => s.setSurface);
// The front page's nav row names the face the switch picked (Voice / Chat),
// see `presentNavItem`.
const surface = useHomeStore((s) => s.surface);
+ const resetTranscript = useHomeStore((s) => s.resetTranscript);
+ // On the voice stage: clear the lane, drop the open voice thread and let the
+ // backend forget the one it was seeded with. We stay on Voice and the mic
+ // stays shut — the next wake word (or orb click) opens the new session.
+ const startNewVoice = () => {
+ resetTranscript();
+ void newVoiceRun();
+ setActive("chats");
+ };
+ // On the chat surface: an empty agent chat. The voice thread is cleared as
+ // well so a reopened voice session does not linger behind the fresh page.
const startNewChat = () => {
newChat();
newAgentChat();
setSurface("chat");
setActive("chats");
};
+ const onVoiceSurface = surface === "voice";
// Shared readiness derivation (same source the banner + chat empty-state use).
const { connected, voiceWarming, bootWarming, warming } = useVoiceReadiness();
@@ -342,14 +354,14 @@ export function Sidebar({
<SurfaceSwitch className="mt-3" />
<button
type="button"
- onClick={startNewChat}
+ onClick={onVoiceSurface ? startNewVoice : startNewChat}
data-testid="sidebar-new-chat"
className="mt-2 flex w-full items-center gap-2 rounded-lg border border-border bg-card px-2.5 py-1.5 text-xs font-medium text-foreground transition-colors hover:border-primary/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
>
<span className="flex h-4 w-4 items-center justify-center rounded bg-primary text-primary-foreground">
<Plus aria-hidden className="h-3 w-3" />
</span>
- {t("sidebar.new_chat")}
+ {onVoiceSurface ? t("sidebar.new_voice_chat") : t("sidebar.new_chat")}
</button>
<BrowserRealtimeControl />
</>
diff --git a/jarvis/ui/web/frontend/src/hooks/useConversations.ts b/jarvis/ui/web/frontend/src/hooks/useConversations.ts
index 5d5ce24714..d061b8570e 100644
--- a/jarvis/ui/web/frontend/src/hooks/useConversations.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useConversations.ts
@@ -7,6 +7,7 @@ import {
detailToTraces,
fetchConversations,
resumeConversation,
+ startNewVoiceRun,
} from "@/lib/chatsApi";
/** How often the history list is re-read while a poller is mounted. */
@@ -80,6 +81,27 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {
setMessages([]);
}, [seedThinkingTraces, setActiveConversation, setMessages]);
+ /**
+ * Start a fresh voice run: drop the open voice thread here and tell the
+ * backend to forget the one it was seeded with (and to end a session that
+ * is still live). The lane on the voice stage is cleared by the caller —
+ * it belongs to the home store, not to the history.
+ *
+ * Separate from `newChat` on purpose: that one lands on the chat surface,
+ * which is exactly what someone standing on the voice stage did not ask for.
+ */
+ const newVoiceRun = useCallback(async () => {
+ setActiveConversation("voice", null);
+ seedThinkingTraces({});
+ setMessages([]);
+ try {
+ await startNewVoiceRun();
+ } catch {
+ /* headless / offline: the local reset above already happened, and the
+ backend has no seeded thread to forget when it is not running */
+ }
+ }, [seedThinkingTraces, setActiveConversation, setMessages]);
+
const removeConversation = useCallback(
async (id: string) => {
try {
@@ -100,6 +122,7 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {
refresh,
openConversation,
newChat,
+ newVoiceRun,
removeConversation,
};
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 9c2d4a1b12..4519cbd40e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -457,6 +457,7 @@
"surface_chat": "Chat",
"surface_hint": "Startseite zwischen Sprache und getipptem Chat umschalten",
"new_chat": "Neuer Chat",
+ "new_voice_chat": "Neuer Voice-Chat",
"recent_chats": "Letzte Chats",
"show_all": "Alle anzeigen",
"show_less": "Weniger anzeigen",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index bec1a2ccd3..8fe43e98ac 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -457,6 +457,7 @@
"surface_chat": "Chat",
"surface_hint": "Switch the front page between voice and typed chat",
"new_chat": "New chat",
+ "new_voice_chat": "New voice chat",
"recent_chats": "Recent chats",
"show_all": "Show all",
"show_less": "Show less",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index b0de5d47e9..e8262bf7eb 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -457,6 +457,7 @@
"surface_chat": "Chat",
"surface_hint": "Cambiar la página de inicio entre voz y chat escrito",
"new_chat": "Nuevo chat",
+ "new_voice_chat": "Nuevo chat de voz",
"recent_chats": "Chats recientes",
"show_all": "Mostrar todo",
"show_less": "Mostrar menos",
diff --git a/jarvis/ui/web/frontend/src/lib/chatsApi.ts b/jarvis/ui/web/frontend/src/lib/chatsApi.ts
index 393c87e206..be9a07a6b3 100644
--- a/jarvis/ui/web/frontend/src/lib/chatsApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/chatsApi.ts
@@ -59,6 +59,20 @@ export async function speakInConversation(
return (await res.json()) as { armed: boolean; seeded_turns: number };
}
+/**
+ * Begin a fresh voice run: the brain forgets the thread it was seeded with,
+ * and a session that is still live is ended so the next wake word opens a new
+ * one. The microphone is not re-armed — starting to talk stays the user's move.
+ */
+export async function startNewVoiceRun(): Promise<{
+ cleared: boolean;
+ ended: boolean;
+}> {
+ const res = await fetch("/api/chats/voice/new", { method: "POST" });
+ if (!res.ok) throw new ChatsApiError("new-voice-run-failed", res.status);
+ return (await res.json()) as { cleared: boolean; ended: boolean };
+}
+
export async function deleteTextConversation(id: string): Promise<void> {
const res = await fetch(`/api/chats/text/${encodeURIComponent(id)}`, {
method: "DELETE",
diff --git a/tests/unit/state/test_chats_routes.py b/tests/unit/state/test_chats_routes.py
index f097698efe..1a764ceded 100644
--- a/tests/unit/state/test_chats_routes.py
+++ b/tests/unit/state/test_chats_routes.py
@@ -24,14 +24,22 @@ class _FakeBrain:
class _FakePipeline:
- def __init__(self, armed: bool = True) -> None:
+ def __init__(self, armed: bool = True, live: bool = False) -> None:
self.armed = armed
self.seed_messages = None
+ # Whether a voice session is running — what the hangup contract reports.
+ self.live = live
+ self.hangups = 0
def request_voice_session(self, *, seed_messages) -> bool:
self.seed_messages = list(seed_messages)
return self.armed
+ def request_voice_hangup(self) -> bool:
+ self.hangups += 1
+ was_live, self.live = self.live, False
+ return was_live
+
def _fake_session_store():
"""One voice session 'v1' with a single user+assistant turn."""
@@ -60,14 +68,18 @@ def _fake_session_store():
)
-async def _make_app(*, with_session=False, with_brain=False, with_pipeline=False):
+async def _make_app(
+ *, with_session=False, with_brain=False, with_pipeline=False, voice_live=False
+):
app = FastAPI()
app.include_router(chats_router)
store = ChatStore(bus=EventBus()) # in-memory
app.state.chat_store = store
app.state.session_store = _fake_session_store() if with_session else None
app.state.brain = _FakeBrain() if with_brain else None
- app.state.speech_pipeline = _FakePipeline() if with_pipeline else None
+ app.state.speech_pipeline = (
+ _FakePipeline(live=voice_live) if with_pipeline else None
+ )
return app, store
@@ -207,3 +219,33 @@ async def test_days_filter_excludes_old() -> None:
r = await c.get("/api/chats", params={"days": 10})
ids = [row["id"] for row in r.json()]
assert ids == ["fresh"]
+
+
+async def test_new_voice_run_ends_a_live_session() -> None:
+ """ "+ New voice chat": the brain drops the thread it was seeded with and a
+ session still running is ended, so the next wake word opens a new one."""
+ app, _ = await _make_app(with_brain=True, with_pipeline=True, voice_live=True)
+ async with _client(app) as c:
+ r = await c.post("/api/chats/voice/new")
+ assert r.status_code == 200
+ assert r.json() == {"cleared": True, "ended": True}
+ assert app.state.brain.seeded == []
+ assert app.state.speech_pipeline.hangups == 1
+
+
+async def test_new_voice_run_reports_no_session_to_end() -> None:
+ """Nothing running is the common case — an honest False, not an error."""
+ app, _ = await _make_app(with_brain=True, with_pipeline=True, voice_live=False)
+ async with _client(app) as c:
+ r = await c.post("/api/chats/voice/new")
+ assert r.status_code == 200
+ assert r.json() == {"cleared": True, "ended": False}
+
+
+async def test_new_voice_run_without_brain_or_pipeline() -> None:
+ """Headless / voice-less installs answer instead of failing."""
+ app, _ = await _make_app()
+ async with _client(app) as c:
+ r = await c.post("/api/chats/voice/new")
+ assert r.status_code == 200
+ assert r.json() == {"cleared": False, "ended": False}