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(chat): swap send for stop while the agent is reasoning

rubenluetke10-beep2b63acfded0c
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index 3cd682f12c..a6f162858c 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -187,6 +187,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
}, fieldRef);
const running = runningTurn(timeline) !== null;
+ const live = running || busy;
async function onSend() {
const sessionAtSend = activeSessionId;
@@ -708,7 +709,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
>
{dictating ? <Square className="h-4 w-4" /> : <Mic className="h-4 w-4" />}
</button>
- {running && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
+ {live && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
<button
type="button"
onClick={() => void cancel()}
diff --git a/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx b/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx
index d2f9f07b54..11baaa05b2 100644
--- a/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx
@@ -542,6 +542,13 @@ describe("ChatStage (agent chat)", () => {
expect(screen.getByTestId("composer-stop")).toBeTruthy();
});
+ it("shows stop while a send is in flight, before the turn stream starts", () => {
+ useAgentChatStore.setState({ activeSessionId: "s1", busy: true, timeline: EMPTY_TIMELINE });
+ render(<ChatStage />);
+ expect(screen.getByTestId("composer-stop")).toBeTruthy();
+ expect(screen.queryByTestId("composer-send")).toBeNull();
+ });
+
it("always shows that the turn is alive: the core, a word, the clock and the tokens", () => {
vi.useFakeTimers();
try {
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 2fe2c70047..2fe1d27846 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
@@ -2,7 +2,7 @@ import { useTranscriptViewStore } from "./useTranscriptView";
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
-import { EMPTY_TIMELINE, type Timeline, type UserItem } from "@/components/agentchat/reduce";
+import { EMPTY_TIMELINE, reduceEvents, type Timeline, type UserItem } from "@/components/agentchat/reduce";
import type { SocietyAgent } from "../data";
import {
AgentChatPanel,
@@ -12,7 +12,7 @@ import {
} from "./AgentChatPanel";
import { useAgentChatStore } from "@/store/agentChat";
import { useEventStore } from "@/store/events";
-import type { AgentChatSession } from "@/lib/agentChatApi";
+import type { AgentChatEvent, AgentChatSession } from "@/lib/agentChatApi";
import { useHomeStore } from "@/store/home";
import { JarvisHistoryRail } from "./JarvisHistoryRail";
@@ -88,10 +88,25 @@ function timelineWith(text: string): Timeline {
return { ...EMPTY_TIMELINE, items: [item], lastSeq: 1 };
}
+let seq = 0;
+function ev(kind: string, payload: Record<string, unknown>): AgentChatEvent {
+ seq += 1;
+ return { seq, ts_ms: seq, kind, payload };
+}
+
+function reasoningTurn(): Timeline {
+ return reduceEvents(EMPTY_TIMELINE, [
+ ev("user_message", { text: "go" }),
+ ev("turn_started", { turn_id: "t-live", provider: "openai", model: "gpt", effort: "", runner: "api" }),
+ ev("reasoning_started", { turn_id: "t-live", message_id: "m1" }),
+ ]);
+}
+
const visual = agent({ agentId: "visual-qa", name: "Visual QA" });
const gmail = agent({ agentId: "gmail-agent", name: "Gmail Agent" });
beforeEach(() => {
+ seq = 0;
useTranscriptViewStore.setState({ boundaries: {} });
useHomeStore.setState({ transcript: [], liveReply: "", jarvisCardMode: "voice", freshVoicePending: false });
useEventStore.setState({ activeKind: "text", activeThreadId: null, messages: [], voiceState: "idle" });
@@ -233,3 +248,35 @@ it.each(["specialist", "lead"] as const)("/clear empties only the %s view and ke
expect(screen.getByText("FIRST_VISIBLE_MESSAGE")).toBeTruthy();
expect(screen.queryByText("PREVIOUS_CONTEXT_TO_KEEP")).toBeNull();
});
+
+it.each(["specialist", "lead"] as const)("turns send into stop while the %s is reasoning, then back when the turn ends", async (tier) => {
+ const current = tier === "lead" ? agent({ agentId: "jarvis", name: "Jarvis", tier }) : gmail;
+ const store = tier === "lead" ? useAgentChatStore : useSocietyChatStore;
+ store.getState().disconnect();
+ store.getState().openSession(current.chatSessionId!);
+ store.setState({ activeSessionId: current.chatSessionId, timeline: reasoningTurn(), busy: false });
+ setJarvisCardMode("chat");
+ render(<AgentChatPanel agent={current} roster={[current]} />);
+ expect(screen.getByTestId("composer-stop")).toBeTruthy();
+ expect(screen.queryByTestId("composer-send")).toBeNull();
+ fireEvent.click(screen.getByTestId("composer-stop"));
+ await waitFor(() => expect(vi.mocked(fetch).mock.calls.some(([url, options]) =>
+ String(url).includes("/cancel") && options?.method === "POST",
+ )).toBe(true));
+ act(() => store.setState({
+ timeline: reduceEvents(store.getState().timeline, [
+ ev("turn_finished", { turn_id: "t-live", status: "done", duration_ms: 12 }),
+ ]),
+ }));
+ expect(screen.getByTestId("composer-send")).toBeTruthy();
+ expect(screen.queryByTestId("composer-stop")).toBeNull();
+});
+
+it("shows stop while the send request is in flight, before the turn stream starts", () => {
+ useSocietyChatStore.getState().disconnect();
+ useSocietyChatStore.getState().openSession(gmail.chatSessionId!);
+ useSocietyChatStore.setState({ activeSessionId: gmail.chatSessionId, timeline: EMPTY_TIMELINE, busy: true });
+ render(<AgentChatPanel agent={gmail} roster={[gmail]} />);
+ expect(screen.getByTestId("composer-stop")).toBeTruthy();
+ expect(screen.queryByTestId("composer-send")).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 b4067afca9..f28dc7addf 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -38,11 +38,12 @@ import { useComposerDictation } from "@/components/agentchat/useComposerDictatio
import { useEventStore } from "@/store/events";
import { useHomeStore } from "@/store/home";
import { startNewVoiceRun } from "@/lib/chatsApi";
-import type {
- NoticeItem,
- TimelineItem,
- TurnItem,
- UserItem,
+import {
+ runningTurn,
+ type NoticeItem,
+ type TimelineItem,
+ type TurnItem,
+ type UserItem,
} from "@/components/agentchat/reduce";
import { TurnTrace } from "@/components/agentchat/WorkTrace";
import { VoiceStage } from "@/components/home/VoiceStage";
@@ -983,6 +984,11 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
setValue(text);
fieldRef.current?.setText(text);
});
+ const timeline = useAgentChat((s) => s.timeline);
+ const sending = useAgentChat((s) => s.busy);
+ // `busy` on this composer also covers "session not open yet". Stop is only
+ // for a live turn: the HTTP send, or the stream after it (reasoning, tools).
+ const live = runningTurn(timeline) !== null || sending;
// "@" completes teammates AND the capability catalog — plugins, MCP
// servers, CLIs, skills, Jarvis tools — on every agent card, including
@@ -1055,7 +1061,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
const selected = selectedTools;
const text = draftText;
if (await commands.execute(text)) return;
- if (!text || busy && !commands.canSteer || modelSaving) return;
+ if (!text || (busy || live) && !commands.canSteer || modelSaving) return;
const chosenIds = new Set((draft?.choices ?? []).map((row) => row.id));
const chosen = [...chosenIds].map((id) => catalog.find((item) => item.key === id));
if (chosen.some((item) => !item || !item.connected)) {
@@ -1254,12 +1260,14 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
>
{dictation.dictating ? <Square className="h-4 w-4" aria-hidden /> : <Mic className="h-4 w-4" aria-hidden />}
</button>
- {busy && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
+ {live && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
<button
type="button"
onClick={() => void onCancel()}
aria-label={t("society.chat.stop")}
- className="flex h-8 w-8 items-center justify-center rounded-full bg-secondary text-foreground hover:bg-popover"
+ title={t("society.chat.stop")}
+ data-testid="composer-stop"
+ className="flex h-8 w-8 items-center justify-center rounded-full bg-foreground text-background transition-colors hover:bg-foreground/90"
>
<Square className="h-3.5 w-3.5" aria-hidden />
</button>
@@ -1269,6 +1277,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
onClick={() => void submit()}
disabled={modelSaving || (!value.trim() && selectedTools.length === 0)}
aria-label={t("society.chat.send")}
+ data-testid="composer-send"
className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground disabled:opacity-40"
>
<Send className="h-3.5 w-3.5" aria-hidden />