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.

fix(society): start fresh Jarvis voice conversations

rubenluetke10-beepf223049e34a8
diff --git a/jarvis/ui/web/frontend/src/components/home/VoiceThreadStage.tsx b/jarvis/ui/web/frontend/src/components/home/VoiceThreadStage.tsx
index 3b3096fb1a..e576777353 100644
--- a/jarvis/ui/web/frontend/src/components/home/VoiceThreadStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/home/VoiceThreadStage.tsx
@@ -26,7 +26,7 @@ import { cn } from "@/lib/utils";
* already in the lane — the same seeding the sidebar does when you open a
* voice session while standing on that stage.
*/
-export function VoiceThreadStage() {
+export function VoiceThreadStage({ onContinueByVoice }: { onContinueByVoice?: () => void } = {}) {
const t = useT();
const messages = useEventStore((s) => s.messages);
const activeThreadId = useEventStore((s) => s.activeThreadId);
@@ -46,6 +46,13 @@ export function VoiceThreadStage() {
useLayoutEffect(follow, [follow, activeThreadId, messages.length]);
const continueByVoice = () => {
+ // Inside the Jarvis agent card the caller owns the Voice | Chat half, so
+ // it takes over (seeding the lane and showing the voice stage itself);
+ // everywhere else this is the front page's own surface switch.
+ if (onContinueByVoice) {
+ onContinueByVoice();
+ return;
+ }
seedTranscript(transcriptFromMessages(messages));
setSurface("voice");
};
diff --git a/jarvis/ui/web/frontend/src/components/society/card/OptionsRail.tsx b/jarvis/ui/web/frontend/src/components/society/card/OptionsRail.tsx
index fa6bcd23af..2342a87d8e 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/OptionsRail.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/OptionsRail.tsx
@@ -1,7 +1,9 @@
/**
* The chat-face right column: this agent's browser screen, its routines, and
- * a tucked-away Retire control. Extracted from AgentCardOverlay so the overlay
- * stays the layout and this file owns what you can do to the agent.
+ * a tucked-away Retire control. On the lead's card only, the typed chats and
+ * the voice sessions join in, so a hung-up call is one click away. Extracted
+ * from AgentCardOverlay so the overlay stays the layout and this file owns
+ * what you can do to the agent.
*/
import { useEffect, useRef, useState } from "react";
import { MoreHorizontal } from "lucide-react";
@@ -11,6 +13,7 @@ import { useT } from "@/i18n";
import type { SocietyAgent } from "../data";
import { AgentBrowserPreview } from "./AgentBrowserPreview";
import { AgentRoutinesList } from "./AgentRoutinesList";
+import { JarvisHistoryRail } from "../chat/JarvisHistoryRail";
import { RetireButton } from "./RetireButton";
export interface OptionsRailProps {
@@ -79,6 +82,7 @@ export function OptionsRail({ agent, onRetired, sample = false }: OptionsRailPro
</header>
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-3 pb-3 pt-2">
<AgentBrowserPreview agent={agent} />
+ {agent.tier === "lead" ? <JarvisHistoryRail /> : null}
<AgentRoutinesList
agentId={agent.agentId}
sampleRoutines={sample ? agent.routines : undefined}
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx
index e8821f0197..824243a3f0 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx
@@ -1,4 +1,4 @@
-import { act, cleanup, render, screen } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { EMPTY_TIMELINE, type Timeline, type UserItem } from "@/components/agentchat/reduce";
@@ -7,10 +7,15 @@ import {
AgentChatPanel,
itemsForOpenSession,
useSocietyChatStore,
+ setJarvisCardMode,
} from "./AgentChatPanel";
+import { useAgentChatStore } from "@/store/agentChat";
+import { useEventStore } from "@/store/events";
+import type { AgentChatSession } from "@/lib/agentChatApi";
vi.mock("@/i18n", () => ({ useT: () => (key: string) => key }));
vi.mock("./AgentModelPicker", () => ({ AgentModelPicker: () => null }));
+vi.mock("@/components/home/VoiceStage", () => ({ VoiceStage: () => <div data-testid="voice-stage" /> }));
vi.mock("../data", async (original) => ({
...(await original<typeof import("../data")>()),
useSocietyCapabilities: () => ({ isLoading: false, data: [] }),
@@ -133,3 +138,24 @@ it("shows the previous specialist's own chat again the moment you switch back",
expect(screen.getByText("UNIQUE_VISUAL_QA_FLOWCHART")).toBeTruthy();
expect(screen.getByTestId("society-chat").getAttribute("data-session-id")).toBe(visual.chatSessionId);
});
+
+it("keeps Jarvis on a fresh chat when history refreshes or the card is reopened", () => {
+ const jarvis = agent({ agentId: "jarvis", name: "Jarvis", tier: "lead" });
+ const session: AgentChatSession = {
+ session_id: "previous-chat", title: "Previous chat", provider: "openai", model: "m",
+ effort: "low", cwd: "", permission_mode: "ask", surface: "jarvis", vendor_session: null,
+ created_ms: 1, updated_ms: 2, message_count: 1, preview: "Previous chat",
+ };
+ useAgentChatStore.getState().disconnect();
+ useAgentChatStore.setState({ activeSessionId: session.session_id, activeSession: session, sessions: [session], timeline: EMPTY_TIMELINE, busy: false });
+ useEventStore.setState({ activeKind: "text", activeThreadId: null });
+ setJarvisCardMode("chat");
+ const view = render(<AgentChatPanel agent={jarvis} roster={[jarvis]} />);
+ fireEvent.click(screen.getByRole("button", { name: "society.chat.new_chat" }));
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+ act(() => useAgentChatStore.setState({ sessions: [{ ...session }] }));
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+ view.unmount();
+ render(<AgentChatPanel agent={jarvis} roster={[jarvis]} />);
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
index a65774e2b9..3ecf75c76b 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -20,7 +20,7 @@ import { InternalMessageBubble } from "@/components/agentchat/InternalMessageBub
* the voice runs on the realtime tier (`[brain.realtime]`), which no text
* runner can drive. The header says so while voice is showing.
*/
-import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
import { MessageSquare, Mic, Paperclip, Plus, RotateCcw, Send, Square } from "lucide-react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
@@ -35,6 +35,10 @@ import { choiceToken } from "@/components/agentchat/composerChips";
import { useChatAttachments } from "@/components/agentchat/useChatAttachments";
import { DictationStatus } from "@/components/agentchat/DictationStatus";
import { useComposerDictation } from "@/components/agentchat/useComposerDictation";
+import { useEventStore } from "@/store/events";
+import { useHomeStore } from "@/store/home";
+import { VoiceThreadStage } from "@/components/home/VoiceThreadStage";
+import { transcriptFromMessages } from "@/lib/homeTranscript";
import type {
NoticeItem,
TimelineItem,
@@ -96,6 +100,40 @@ export interface AgentChatPanelProps {
*/
export const useSocietyChatStore = createAgentChatStore("society");
+type JarvisCardMode = "chat" | "voice";
+
+/** Remembered for the app session, so a card reopened stays on the half you last used. */
+let lastJarvisCardMode: JarvisCardMode = "chat";
+const modeListeners = new Set<() => void>();
+
+export function getJarvisCardMode(): JarvisCardMode {
+ return lastJarvisCardMode;
+}
+
+/**
+ * Switch the lead card's Voice | Chat half from anywhere — the column's own
+ * switch and the history rail in the Options column share this, so opening a
+ * row there lands on the half that shows it.
+ */
+export function setJarvisCardMode(next: JarvisCardMode): void {
+ if (lastJarvisCardMode === next) return;
+ lastJarvisCardMode = next;
+ for (const notify of [...modeListeners]) notify();
+}
+
+/** The lead card's Voice | Chat half. */
+export function useJarvisCardMode(): JarvisCardMode {
+ return useSyncExternalStore(
+ (notify) => {
+ modeListeners.add(notify);
+ return () => {
+ modeListeners.delete(notify);
+ };
+ },
+ getJarvisCardMode,
+ );
+}
+
/**
* The transcript a specialist column may paint. One store serves every
* specialist, so the chrome (name, rail, composer) can already show the
@@ -240,14 +278,12 @@ function SpecialistChat({ agent, roster }: AgentChatPanelProps) {
function JarvisChat({ agent, roster }: AgentChatPanelProps) {
const t = useT();
const items = useAgentChat((s) => s.timeline.items);
- const sessions = useAgentChat((s) => s.sessions);
const activeSessionId = useAgentChat((s) => s.activeSessionId);
const busy = useAgentChat((s) => s.busy);
const lastError = useAgentChat((s) => s.lastError);
const draft = useAgentChat((s) => s.draft);
const loadCatalog = useAgentChat((s) => s.loadCatalog);
const loadSessions = useAgentChat((s) => s.loadSessions);
- const openSession = useAgentChat((s) => s.openSession);
const newChat = useAgentChat((s) => s.newChat);
const send = useAgentChat((s) => s.send);
const cancel = useAgentChat((s) => s.cancel);
@@ -269,53 +305,92 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {
.catch(() => undefined);
}, [loadSessions]);
- // The front page's current conversation, or the latest one when the card
- // opens before the front page ever did.
- useEffect(() => {
- if (activeSessionId || sessions.length === 0) return;
- openSession(sessions[0].session_id);
- }, [activeSessionId, sessions, openSession]);
+ // A spoken thread opened from the history rail: read here, in the column
+ // the composer would otherwise own — the same sharing the front page's
+ // chat stage does (components/home/ChatStage).
+ const voiceThreadId = useEventStore((s) => (s.activeKind === "voice" ? s.activeThreadId : null));
+ const voiceMessages = useEventStore((s) => s.messages);
+ const setActiveConversation = useEventStore((s) => s.setActiveConversation);
+ const setMessages = useEventStore((s) => s.setMessages);
+ const seedTranscript = useHomeStore((s) => s.seedTranscript);
+
+ // A null session is an intentional fresh chat. Only an explicit history
+ // selection may open an older session; polling must not undo New chat.
const mentionable = useMemo(() => roster.filter((a) => a.tier !== "lead"), [roster]);
// Voice or typed — Jarvis' card only. The other agents have no voice: the
// wake word, the realtime brain and the microphone belong to the lead.
- const [mode, setMode] = useState<JarvisCardMode>(lastJarvisCardMode);
- const pickMode = (next: JarvisCardMode) => {
- lastJarvisCardMode = next;
- setMode(next);
- };
+ const mode = useJarvisCardMode();
+ const pickMode = setJarvisCardMode;
+
+ // A fresh page: no chat, no spoken thread — the composer below starts it.
+ const startFresh = useCallback(() => {
+ setActiveConversation("text", null);
+ setMessages([]);
+ newChat();
+ }, [newChat, setActiveConversation, setMessages]);
+
+ const continueByVoice = useCallback(() => {
+ seedTranscript(transcriptFromMessages(voiceMessages));
+ pickMode("voice");
+ }, [seedTranscript, voiceMessages]);
if (mode === "voice") {
return (
<div className="flex h-full min-h-0 flex-col" data-testid="society-chat" data-mode="voice">
- <div className="flex shrink-0 items-center gap-2 border-b border-border px-3 py-2">
- <JarvisModeSwitch mode={mode} onPick={pickMode} />
+ <div className="grid shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2 border-b border-border px-3 py-2">
<span className="min-w-0 truncate text-xs text-muted-foreground" title={t("society.chat.voice_note")}>
{t("society.chat.voice_note")}
</span>
+ <JarvisModeSwitch mode={mode} onPick={pickMode} />
+ <span aria-hidden />
</div>
<VoiceStage />
</div>
);
}
- return (
- <div className="flex h-full min-h-0 flex-col" data-testid="society-chat" data-mode="chat">
- <div className="flex shrink-0 items-center gap-2 border-b border-border px-3 py-2">
- <JarvisModeSwitch mode={mode} onPick={pickMode} />
+ const header = (
+ <div className="grid shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2 border-b border-border px-3 py-2">
+ <div className="flex min-w-0 items-center gap-2">
<ModelPicker />
<EffortPicker />
+ </div>
+ <JarvisModeSwitch mode={mode} onPick={pickMode} />
+ <div className="flex items-center justify-end">
<button
type="button"
- onClick={newChat}
+ onClick={startFresh}
title={t("society.chat.new_chat")}
aria-label={t("society.chat.new_chat")}
- className="ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-secondary hover:text-foreground"
+ className="rounded-md p-1.5 text-muted-foreground hover:bg-secondary hover:text-foreground"
>
<RotateCcw className="h-3.5 w-3.5" aria-hidden />
</button>
</div>
+ </div>
+ );
+
+ // A spoken thread from the history rail, read in place — no composer, like
+ // the front page: a recording is continued by speaking.
+ if (voiceThreadId && !activeSessionId) {
+ return (
+ <div
+ className="flex h-full min-h-0 flex-col"
+ data-testid="society-chat"
+ data-mode="chat"
+ data-thread={voiceThreadId}
+ >
+ {header}
+ <VoiceThreadStage onContinueByVoice={continueByVoice} />
+ </div>
+ );
+ }
+
+ return (
+ <div className="flex h-full min-h-0 flex-col" data-testid="society-chat" data-mode="chat">
+ {header}
<Transcript items={items} agent={agent} roster={roster} onDecide={decide} />
{lastError ? (
<p role="alert" className="px-4 pb-1 text-xs text-destructive">
@@ -340,11 +415,6 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {
// voice | chat — the lead's card only
// ---------------------------------------------------------------------------
-type JarvisCardMode = "chat" | "voice";
-
-/** Remembered for the app session, so a card reopened stays on the half you last used. */
-let lastJarvisCardMode: JarvisCardMode = "chat";
-
/**
* The same `Voice | Chat` idea as the sidebar's switch, scoped to the card:
* it changes what THIS column shows and leaves the front page's own choice
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx
new file mode 100644
index 0000000000..83091695b4
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx
@@ -0,0 +1,172 @@
+/**
+ * The lead card's history rail: typed chats and voice sessions as two lists,
+ * opening in place — never navigating away from the card.
+ */
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import { JarvisHistoryRail } from "@/components/society/chat/JarvisHistoryRail";
+import { useAgentChatStore } from "@/store/agentChat";
+import { useEventStore } from "@/store/events";
+import { useHomeStore } from "@/store/home";
+import { setJarvisCardMode } from "./AgentChatPanel";
+import type { AgentChatSession } from "@/lib/agentChatApi";
+import type { ConversationSummary } from "@/store/events";
+
+vi.mock("@/i18n", () => ({ useT: () => (key: string) => key }));
+vi.mock("./AgentChatPanel", () => ({ setJarvisCardMode: vi.fn() }));
+
+class FakeSocket {
+ onopen: (() => void) | null = null;
+ onmessage: ((msg: { data: string }) => void) | null = null;
+ onclose: (() => void) | null = null;
+ onerror: (() => void) | null = null;
+ close() {}
+}
+
+function chatSession(over: Partial<AgentChatSession> = {}): AgentChatSession {
+ return {
+ session_id: "chat-1",
+ title: "Typed questions",
+ provider: "openai",
+ model: "m",
+ effort: "low",
+ cwd: "",
+ permission_mode: "ask",
+ surface: "jarvis",
+ vendor_session: null,
+ created_ms: 1,
+ updated_ms: 2,
+ message_count: 3,
+ preview: "typed preview",
+ ...over,
+ };
+}
+
+function voiceSummary(over: Partial<ConversationSummary> = {}): ConversationSummary {
+ return {
+ kind: "voice",
+ id: "voice-1",
+ title: "Evening call",
+ preview: "spoken preview",
+ created_ms: 1,
+ updated_ms: 3,
+ message_count: 4,
+ ...over,
+ };
+}
+
+function json(body: unknown, status = 200) {
+ return {
+ ok: status >= 200 && status < 300,
+ status,
+ json: async () => body,
+ } as Response;
+}
+
+describe("JarvisHistoryRail", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ useHomeStore.getState().resetTranscript();
+ Element.prototype.scrollIntoView = vi.fn();
+ vi.stubGlobal("WebSocket", FakeSocket);
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async (url: string, init?: RequestInit) => {
+ const path = String(url);
+ if (path.includes("/api/chats/voice/")) {
+ return json({ kind: "voice", id: "voice-1", title: "Evening call", messages: [] });
+ }
+ if (path.includes("/api/chats?")) {
+ return json([voiceSummary()]);
+ }
+ if (path.includes("/api/agent-chat/sessions")) {
+ if (init?.method === "DELETE") return json({});
+ return json({ sessions: [chatSession()] });
+ }
+ return json({});
+ }),
+ );
+ useAgentChatStore.getState().disconnect();
+ useAgentChatStore.setState({
+ activeSessionId: null,
+ activeSession: null,
+ timeline: { items: [], pendingApprovals: [], lastSeq: 0, sessionPatch: null },
+ busy: false,
+ lastError: null,
+ sessions: [],
+ socketState: "idle",
+ });
+ useEventStore.setState({
+ conversations: [],
+ messages: [],
+ activeThreadId: null,
+ activeKind: "text",
+ });
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ });
+
+ test("lists typed chats and voice sessions in two sections", async () => {
+ render(<JarvisHistoryRail />);
+ expect(await screen.findByTestId("jarvis-history-chat-row")).toBeTruthy();
+ expect(await screen.findByTestId("jarvis-history-voice-row")).toBeTruthy();
+ expect(screen.getByTestId("jarvis-history-chat-row").textContent).toContain("Typed questions");
+ expect(screen.getByTestId("jarvis-history-voice-row").textContent).toContain("Evening call");
+ });
+
+ test("opening a chat row shows that session in the column", async () => {
+ render(<JarvisHistoryRail />);
+ fireEvent.click(await screen.findByTestId("jarvis-history-chat-row"));
+ expect(useAgentChatStore.getState().activeSessionId).toBe("chat-1");
+ });
+
+ test("opening a voice row clears the chat and marks the thread", async () => {
+ useAgentChatStore.setState({ activeSessionId: "chat-1" });
+ render(<JarvisHistoryRail />);
+ fireEvent.click(await screen.findByTestId("jarvis-history-voice-row"));
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+ expect(useEventStore.getState().activeThreadId).toBe("voice-1");
+ });
+
+ test("the new button clears whatever is open", async () => {
+ useAgentChatStore.setState({ activeSessionId: "chat-1" });
+ useEventStore.setState({ activeKind: "voice", activeThreadId: "voice-1" });
+ render(<JarvisHistoryRail />);
+ fireEvent.click(await screen.findByTestId("jarvis-history-new"));
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+ expect(useEventStore.getState().activeThreadId).toBeNull();
+ });
+
+ test("new voice resets the backend and opens a blank voice lane without deleting history", async () => {
+ useAgentChatStore.setState({ activeSessionId: "chat-1" });
+ useEventStore.setState({ activeKind: "voice", activeThreadId: "voice-1", transcription: "unfinished", transcriptionFinal: false });
+ useHomeStore.getState().seedTranscript([{ id: "old", who: "user", text: "Previous call", ts: 1 }]);
+ render(<JarvisHistoryRail />);
+ await screen.findByTestId("jarvis-history-voice-row");
+ fireEvent.click(screen.getByTestId("jarvis-history-new-voice"));
+ await waitFor(() => expect(setJarvisCardMode).toHaveBeenCalledWith("voice"));
+ expect(fetch).toHaveBeenCalledWith("/api/chats/voice/new", { method: "POST" });
+ expect(useHomeStore.getState().transcript).toEqual([]);
+ expect(useAgentChatStore.getState().activeSessionId).toBeNull();
+ expect(useEventStore.getState().activeKind).toBe("voice");
+ expect(useEventStore.getState().activeThreadId).toBeNull();
+ expect(useEventStore.getState().transcription).toBe("");
+ expect(screen.getByTestId("jarvis-history-voice-row").textContent).toContain("Evening call");
+ });
+
+ test("a failed voice reset preserves the conversation and offers a retry", async () => {
+ useHomeStore.getState().seedTranscript([{ id: "old", who: "user", text: "Previous call", ts: 1 }]);
+ render(<JarvisHistoryRail />);
+ await screen.findByTestId("jarvis-history-voice-row");
+ vi.mocked(fetch).mockResolvedValueOnce(json({}, 500));
+ fireEvent.click(screen.getByTestId("jarvis-history-new-voice"));
+ expect(await screen.findByRole("alert")).toBeTruthy();
+ expect(useHomeStore.getState().transcript[0].text).toBe("Previous call");
+ expect(setJarvisCardMode).not.toHaveBeenCalled();
+ expect((screen.getByTestId("jarvis-history-new-voice") as HTMLButtonElement).disabled).toBe(false);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx
new file mode 100644
index 0000000000..e9c456cc2b
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx
@@ -0,0 +1,240 @@
+import { useEffect, useRef, useState } from "react";
+import { MessageSquare, Mic, Plus, Trash2 } from "lucide-react";
+
+import { useT } from "@/i18n";
+import { cn } from "@/lib/utils";
+import { useAgentChatStore } from "@/store/agentChat";
+import { useEventStore } from "@/store/events";
+import { useHomeStore } from "@/store/home";
+import { startNewVoiceRun } from "@/lib/chatsApi";
+import { CONVERSATIONS_REFRESH_MS, useConversations } from "@/hooks/useConversations";
+import { formatChatWhen } from "@/components/home/chatRows";
+import { setJarvisCardMode } from "./AgentChatPanel";
+
+/**
+ * The lead's own history, in the Options column: typed chats and spoken
+ * sessions as two lists. Specialists keep the rail they have — only Jarvis
+ * is reached by voice, so only his card lists voice sessions.
+ *
+ * A click never leaves the card: a chat opens in the middle column's
+ * timeline, a voice session is read there as an archive (continued by
+ * speaking, like the front page). Opening either kind closes the other, so
+ * the two can never claim the column at once. "+" starts a blank page.
+ */
+export function JarvisHistoryRail() {
+ const t = useT();
+ const [startingVoice, setStartingVoice] = useState(false);
+ const startingVoiceRef = useRef(false);
+ const [voiceError, setVoiceError] = useState(false);
+ const sessions = useAgentChatStore((s) => s.sessions);
+ const activeSessionId = useAgentChatStore((s) => s.activeSessionId);
+ const loadSessions = useAgentChatStore((s) => s.loadSessions);
+ const { conversations, openConversation, refresh } = useConversations();
+ const setActiveConversation = useEventStore((s) => s.setActiveConversation);
+ const setMessages = useEventStore((s) => s.setMessages);
+ const voiceThreadId = useEventStore((s) => (s.activeKind === "voice" ? s.activeThreadId : null));
+
+ // The dialog is transient, so it polls while open: a session that ends
+ // with a hang-up appears without reopening the card.
+ useEffect(() => {
+ void loadSessions();
+ void refresh();
+ const id = window.setInterval(() => {
+ void loadSessions();
+ void refresh();
+ }, CONVERSATIONS_REFRESH_MS);
+ return () => window.clearInterval(id);
+ }, [loadSessions, refresh]);
+
+ const voiceRows = conversations.filter((c) => c.kind === "voice");
+
+ const openChat = (sessionId: string) => {
+ setActiveConversation("text", null);
+ setMessages([]);
+ useAgentChatStore.getState().openSession(sessionId);
+ setJarvisCardMode("chat");
+ };
+
+ const openVoice = (voiceId: string) => {
+ useAgentChatStore.getState().newChat();
+ setJarvisCardMode("chat");
+ void openConversation("voice", voiceId);
+ };
+
+ const startNew = () => {
+ setActiveConversation("text", null);
+ setMessages([]);
+ useAgentChatStore.getState().newChat();
+ setJarvisCardMode("chat");
+ };
+
+ const removeChat = (sessionId: string) => {
+ void useAgentChatStore.getState().removeSession(sessionId);
+ };
+
+ const startVoice = async () => {
+ if (startingVoiceRef.current) return;
+ startingVoiceRef.current = true;
+ setStartingVoice(true);
+ setVoiceError(false);
+ try {
+ await startNewVoiceRun();
+ useAgentChatStore.getState().newChat();
+ setActiveConversation("voice", null);
+ setMessages([]);
+ useEventStore.getState().seedThinkingTraces({});
+ useEventStore.getState().setTranscription("", true);
+ useHomeStore.getState().resetTranscript();
+ setJarvisCardMode("voice");
+ void refresh();
+ } catch {
+ // Keep the current conversation visible if the backend could not reset it.
+ setVoiceError(true);
+ } finally {
+ startingVoiceRef.current = false;
+ setStartingVoice(false);
+ }
+ };
+
+ return (
+ <section className="flex min-h-0 shrink-0 flex-col gap-3" data-testid="jarvis-history">
+ <div className="flex min-h-0 flex-col">
+ <div className="mb-1 flex shrink-0 items-center justify-between gap-2">
+ <h3 className="font-display text-[13px] font-semibold tracking-tight text-foreground">
+ {t("society.chat.history_chats")}
+ {sessions.length > 0 ? (
+ <span className="ml-1.5 tabular-nums text-muted-foreground">{sessions.length}</span>
+ ) : null}
+ </h3>
+ <button
+ type="button"
+ onClick={startNew}
+ title={t("society.chat.new_chat")}
+ aria-label={t("society.chat.new_chat")}
+ data-testid="jarvis-history-new"
+ className="rounded p-0.5 text-muted-foreground hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
+ >
+ <Plus size={14} aria-hidden />
+ </button>
+ </div>
+ {sessions.length === 0 ? (
+ <p className="px-1 py-0.5 text-xs text-muted-foreground">{t("society.chat.history_empty")}</p>
+ ) : (
+ <ul className="max-h-36 space-y-px overflow-y-auto">
+ {sessions.map((s) => (
+ <HistoryRow
+ key={s.session_id}
+ icon={<MessageSquare aria-hidden className="h-3 w-3 shrink-0" />}
+ title={s.title || s.preview || t("society.chat.new_chat")}
+ when={formatChatWhen(s.updated_ms)}
+ active={s.session_id === activeSessionId && voiceThreadId === null}
+ onOpen={() => openChat(s.session_id)}
+ onDelete={() => removeChat(s.session_id)}
+ deleteLabel={t("society.chat.history_delete")}
+ testId="jarvis-history-chat-row"
+ />
+ ))}
+ </ul>
+ )}
+ </div>
+ <div className="flex min-h-0 flex-col">
+ <div className="mb-1 flex shrink-0 items-center justify-between gap-2">
+ <h3 className="font-display text-[13px] font-semibold tracking-tight text-foreground">
+ {t("society.chat.history_voice")}
+ {voiceRows.length > 0 ? (
+ <span className="ml-1.5 tabular-nums text-muted-foreground">{voiceRows.length}</span>
+ ) : null}
+ </h3>
+ <button
+ type="button"
+ onClick={() => void startVoice()}
+ disabled={startingVoice}
+ title={t("sidebar.new_voice_chat")}
+ aria-label={t("sidebar.new_voice_chat")}
+ data-testid="jarvis-history-new-voice"
+ className="rounded p-0.5 text-muted-foreground hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50"
+ >
+ <Plus size={14} aria-hidden />
+ </button>
+ </div>
+ {voiceError ? (
+ <p role="alert" className="px-1 py-0.5 text-xs text-destructive">
+ {t("sidebar.new_voice_chat")}: {t("voice_state.error")}
+ </p>
+ ) : null}
+ {voiceRows.length === 0 ? (
+ <p className="px-1 py-0.5 text-xs text-muted-foreground">{t("society.chat.history_empty")}</p>
+ ) : (
+ <ul className="max-h-36 space-y-px overflow-y-auto">
+ {voiceRows.map((c) => (
+ <HistoryRow
+ key={c.id}
+ icon={<Mic aria-hidden className="h-3 w-3 shrink-0" />}
+ title={c.title || c.preview || t("society.chat.new_chat")}
+ when={formatChatWhen(c.updated_ms)}
+ active={c.id === voiceThreadId}
+ onOpen={() => openVoice(c.id)}
+ testId="jarvis-history-voice-row"
+ />
+ ))}
+ </ul>
+ )}
+ </div>
+ </section>
+ );
+}
+
+function HistoryRow({
+ icon,
+ title,
+ when,
+ active,
+ onOpen,
+ onDelete,
+ deleteLabel,
+ testId,
+}: {
+ icon: React.ReactNode;
+ title: string;
+ when: string;
+ active: boolean;
+ onOpen: () => void;
+ onDelete?: () => void;
+ deleteLabel?: string;
+ testId: string;
+}) {
+ return (
+ <li className="group relative">
+ <button
+ type="button"
+ onClick={onOpen}
+ title={title}
+ data-testid={testId}
+ data-active={active ? "true" : undefined}
+ className={cn(
+ "flex h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left transition-colors",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ active ? "bg-secondary text-foreground" : "text-muted-foreground hover:bg-secondary hover:text-foreground",
+ )}
+ >
+ <span className={cn("shrink-0", active ? "text-foreground" : "text-muted-foreground")}>{icon}</span>
+ <span className="min-w-0 flex-1 truncate text-xs">{title}</span>
+ {when ? <span className="shrink-0 text-micro tabular-nums text-foreground-faint">{when}</span> : null}
+ </button>
+ {onDelete ? (
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete();
+ }}
+ title={deleteLabel}
+ aria-label={deleteLabel}
+ className="absolute right-1 top-1/2 hidden -translate-y-1/2 rounded-md bg-card p-1 text-muted-foreground transition-colors hover:bg-destructive/15 hover:text-destructive group-hover:block"
+ >
+ <Trash2 className="h-3 w-3" aria-hidden />
+ </button>
+ ) : null}
+ </li>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index b1b7978ac2..cd4c1c3e81 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -5123,7 +5123,11 @@
"proposal_kind_approval_rule": "Freigaberegeln",
"proposal_kind_focus": "Werkzeuge, die zuerst genutzt werden",
"proposal_kind_team": "Teammitglieder",
- "allow_always": "Immer erlauben"
+ "allow_always": "Immer erlauben",
+ "history_chats": "Chats",
+ "history_voice": "Sprache",
+ "history_empty": "Noch nichts hier",
+ "history_delete": "Löschen"
},
"world": {
"minimap_label": "Inselkarte",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 5f22b515fd..36f38fd5e0 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -5156,7 +5156,11 @@
"proposal_kind_approval_rule": "Approval rules",
"proposal_kind_focus": "Tools to reach for first",
"proposal_kind_team": "Teammates",
- "allow_always": "Always allow"
+ "allow_always": "Always allow",
+ "history_chats": "Chats",
+ "history_voice": "Voice",
+ "history_empty": "Nothing here yet",
+ "history_delete": "Delete"
},
"world": {
"minimap_label": "Island map",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index dd0bce15d5..facbe3924b 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -5123,7 +5123,11 @@
"proposal_kind_approval_rule": "Reglas de aprobación",
"proposal_kind_focus": "Herramientas a usar primero",
"proposal_kind_team": "Compañeros de equipo",
- "allow_always": "Permitir siempre"
+ "allow_always": "Permitir siempre",
+ "history_chats": "Chats",
+ "history_voice": "Voz",
+ "history_empty": "Nada aquí todavía",
+ "history_delete": "Eliminar"
},
"world": {
"minimap_label": "Mapa de la isla",
diff --git a/jarvis/ui/web/frontend/src/store/home.test.ts b/jarvis/ui/web/frontend/src/store/home.test.ts
index e7b19685ac..bfa736b944 100644
--- a/jarvis/ui/web/frontend/src/store/home.test.ts
+++ b/jarvis/ui/web/frontend/src/store/home.test.ts
@@ -1,6 +1,33 @@
-import { describe, expect, it } from "vitest";
+import { beforeEach, describe, expect, it } from "vitest";
-import { reduceLiveReply } from "@/store/home";
+import { reduceLiveReply, useHomeStore } from "@/store/home";
+
+describe("voice conversation boundaries", () => {
+ beforeEach(() => useHomeStore.getState().resetTranscript());
+
+ it.each(["hotkey", "voice_pattern", "client_stop", "idle_timeout"])("starts a fresh lane after %s", (hangup_reason) => {
+ const home = useHomeStore.getState();
+ home.ingest("TranscriptFinal", { transcript: { text: "Old conversation" } }, 1);
+ home.ingest("AssistantTextDelta", { channel: "voice", text: "Partial reply" }, 2);
+ expect(useHomeStore.getState().transcript.length).toBeGreaterThan(0);
+ home.ingest("VoiceSessionEnded", { session_id: "first", hangup_reason }, 3);
+ expect(useHomeStore.getState().transcript).toEqual([]);
+ expect(useHomeStore.getState().liveReply).toBe("");
+ home.ingest("VoiceSessionStarted", { session_id: "second" }, 4);
+ home.ingest("TranscriptFinal", { transcript: { text: "New conversation" } }, 5);
+ expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual(["New conversation"]);
+ });
+
+ it("keeps the conversation between turns and during provider fallback", () => {
+ const home = useHomeStore.getState();
+ home.ingest("TranscriptFinal", { transcript: { text: "Keep this turn" } }, 1);
+ home.ingest("VoiceTurnCompleted", {}, 2);
+ home.ingest("SystemStateChanged", { new_state: "LISTENING" }, 3);
+ home.ingest("VoiceSessionEnded", { hangup_reason: "realtime_fallback" }, 4);
+ home.ingest("VoiceSessionEnded", { hangup_reason: "desktop_fallback" }, 5);
+ expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual(["Keep this turn"]);
+ });
+});
describe("reduceLiveReply — the voice lane's answer as it forms", () => {
it("grows with voice/realtime snapshots and ignores the typed chat's", () => {
diff --git a/jarvis/ui/web/frontend/src/store/home.ts b/jarvis/ui/web/frontend/src/store/home.ts
index d64aeb9ac7..824a64ecf6 100644
--- a/jarvis/ui/web/frontend/src/store/home.ts
+++ b/jarvis/ui/web/frontend/src/store/home.ts
@@ -80,6 +80,15 @@ export const useHomeStore = create<HomeStore>((set, get) => ({
transcript: [],
liveReply: "",
ingest: (name, payload, tsMs) => {
+ if (name === "VoiceSessionEnded") {
+ const reason = (payload as { hangup_reason?: string } | null)?.hangup_reason;
+ // A provider handover continues the same call. A real hangup opens an
+ // empty lane; the completed conversation remains in the history rail.
+ if (reason !== "realtime_fallback" && reason !== "desktop_fallback") {
+ set({ transcript: [], liveReply: "" });
+ return;
+ }
+ }
const before = get().transcript;
const after = reduceTranscript(before, name, payload, tsMs);
const live = reduceLiveReply(get().liveReply, name, payload);