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(chat): let Send end a running dictation and send the transcript

rubenluetke10-beepca71f365eb4d
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index 4cef5202e5..67bbcb0eaf 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -146,7 +146,8 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
dictating,
stop: stopDictation,
toggle: toggleDictation,
- } = useComposerDictation(setValue);
+ stopAndSend: stopDictationAndSend,
+ } = useComposerDictation(setValue, () => void onSend());
// Files going in with this message. Held here rather than in the store: they
// belong to the sentence being typed, and a chat opened elsewhere must not
@@ -441,6 +442,9 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
(!running || commands.canSteer) &&
(!busy || commands.canSteer) &&
Boolean(provider?.connected);
+ // Send while the mic is open ends the dictation and sends once the words
+ // land, so it is live even before the box holds any text.
+ const canFinishDictation = dictating && connected && !live && Boolean(provider?.connected);
const placeholder = dictating
? t("chats_view.dictation_listening")
: connected
@@ -494,7 +498,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
placeholder={placeholder}
disabled={!connected && !commands.enabled}
autoFocus={autoFocus}
- onSubmit={() => void onSend()}
+ onSubmit={() => (dictating ? stopDictationAndSend() : void onSend())}
onDraftChange={(draft) => {
setValueState(draft.text);
setSelectedTools(draft.choices);
@@ -715,13 +719,13 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
) : (
<button
type="button"
- onClick={() => void onSend()}
- disabled={!canSend}
+ onClick={() => (dictating ? stopDictationAndSend() : void onSend())}
+ disabled={!canSend && !canFinishDictation}
aria-label={t("agent_chat.send")}
data-testid="composer-send"
className={cn(
"inline-flex h-8 w-8 items-center justify-center rounded-lg transition-colors",
- canSend
+ canSend || canFinishDictation
? "bg-foreground/70 text-primary-foreground hover:bg-primary/90"
: "bg-secondary text-muted-foreground",
)}
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.test.ts b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.test.ts
new file mode 100644
index 0000000000..acfd09003a
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.test.ts
@@ -0,0 +1,61 @@
+import { act, renderHook } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import { useEventStore } from "@/store/events";
+
+import { useComposerDictation } from "./useComposerDictation";
+
+describe("useComposerDictation", () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ useEventStore.setState({ dictating: false, dictationText: "" });
+ });
+ afterEach(() => vi.useRealTimers());
+
+ it("does not mirror interim text into the box", () => {
+ const setValue = vi.fn();
+ const { result } = renderHook(() => useComposerDictation(setValue));
+ act(() => result.current.start());
+ act(() => useEventStore.getState().setDictationInterim("hello wor"));
+ expect(setValue).not.toHaveBeenCalled();
+ });
+
+ it("appends the final transcript once", () => {
+ let box = "Fix";
+ const setValue = (next: string | ((current: string) => string)) => {
+ box = typeof next === "function" ? next(box) : next;
+ };
+ renderHook(() => useComposerDictation(setValue));
+ act(() => useEventStore.getState().commitDictation("the login bug"));
+ expect(box).toBe("Fix the login bug");
+ });
+
+ it("sends after the final transcript when Send ended the dictation", () => {
+ const onSend = vi.fn();
+ const { result } = renderHook(() => useComposerDictation(vi.fn(), onSend));
+ act(() => result.current.start());
+ act(() => result.current.stopAndSend());
+ expect(onSend).not.toHaveBeenCalled();
+ act(() => {
+ useEventStore.getState().commitDictation("ship it");
+ useEventStore.getState().noteDictationFinal();
+ });
+ act(() => vi.runOnlyPendingTimers());
+ expect(onSend).toHaveBeenCalledTimes(1);
+ // The fallback timer was cleared: no second send.
+ act(() => vi.advanceTimersByTime(10_000));
+ expect(onSend).toHaveBeenCalledTimes(1);
+ });
+
+ it("still sends when no final transcript arrives", () => {
+ const onSend = vi.fn();
+ const { result } = renderHook(() => useComposerDictation(vi.fn(), onSend));
+ act(() => result.current.start());
+ act(() => result.current.stopAndSend());
+ act(() => vi.advanceTimersByTime(7_999));
+ expect(onSend).not.toHaveBeenCalled();
+ act(() => vi.advanceTimersByTime(1));
+ act(() => vi.runOnlyPendingTimers());
+ expect(onSend).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
index 57b6e743d4..a1237bc75f 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
+++ b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
@@ -21,16 +21,51 @@ import { useEventStore } from "@/store/events";
* The setter is read through a ref: callers pass an inline wrapper (the
* society composer mirrors into its chip field), and with that wrapper in the
* effect deps the commit effect would re-run on every render of the composer.
+ *
+ * `stopAndSend` lets Send end a running dictation: the mic stops, and the
+ * composer's `onSend` runs once the final transcript has landed in the box
+ * (or after FINAL_WAIT_MS, so a transcript that never comes cannot strand
+ * the message). `onSend` is also read through a ref, so the call made after
+ * the transcript lands sees the box as it is then, not as it was at click.
*/
+const FINAL_WAIT_MS = 8000;
+
export function useComposerDictation(
setValue: (next: string | ((current: string) => string)) => void,
+ onSend?: () => void,
) {
const dictating = useEventStore((s) => s.dictating);
const dictationCommitSeq = useEventStore((s) => s.dictationCommitSeq);
+ const dictationFinalSeq = useEventStore((s) => s.dictationFinalSeq);
const setDictating = useEventStore((s) => s.setDictating);
const lastCommitSeqRef = useRef(dictationCommitSeq);
const setValueRef = useRef(setValue);
setValueRef.current = setValue;
+ const onSendRef = useRef(onSend);
+ onSendRef.current = onSend;
+ const sendTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const lastFinalSeqRef = useRef(dictationFinalSeq);
+
+ const flushSend = useCallback(() => {
+ if (sendTimerRef.current === null) return;
+ clearTimeout(sendTimerRef.current);
+ sendTimerRef.current = null;
+ // A tick later, so the box has re-rendered with the transcript first.
+ setTimeout(() => onSendRef.current?.(), 0);
+ }, []);
+
+ useEffect(() => {
+ if (dictationFinalSeq === lastFinalSeqRef.current) return;
+ lastFinalSeqRef.current = dictationFinalSeq;
+ flushSend();
+ }, [dictationFinalSeq, flushSend]);
+
+ useEffect(
+ () => () => {
+ if (sendTimerRef.current !== null) clearTimeout(sendTimerRef.current);
+ },
+ [],
+ );
useEffect(() => {
if (dictationCommitSeq === lastCommitSeqRef.current) return;
@@ -58,5 +93,11 @@ export function useComposerDictation(
else start();
}, [dictating, start, stop]);
- return { dictating, start, stop, toggle };
+ const stopAndSend = useCallback(() => {
+ if (sendTimerRef.current !== null) return;
+ sendTimerRef.current = setTimeout(flushSend, FINAL_WAIT_MS);
+ stop();
+ }, [flushSend, stop]);
+
+ return { dictating, start, stop, toggle, stopAndSend };
}
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 f9a17dbb5f..5468cfffb1 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -1024,7 +1024,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
const text = typeof next === "function" ? next(value) : next;
setValue(text);
fieldRef.current?.setText(text);
- });
+ }, () => void submit());
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
@@ -1254,7 +1254,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
: t("society.chat.placeholder").replace("{0}", agent.name)
}
disabled={false}
- onSubmit={() => void submit()}
+ onSubmit={() => (dictation.dictating ? dictation.stopAndSend() : void submit())}
onDraftChange={onDraftChange}
onPasteFiles={attachments.onPaste}
onKeyDown={(e) => {
@@ -1314,8 +1314,10 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
) : (
<button
type="button"
- onClick={() => void submit()}
- disabled={modelSaving || (!value.trim() && selectedTools.length === 0)}
+ // While recording, Send ends the dictation and sends once the
+ // words land, so it is live before the box holds any text.
+ onClick={() => (dictation.dictating ? dictation.stopAndSend() : void submit())}
+ disabled={modelSaving || (!value.trim() && selectedTools.length === 0 && !dictation.dictating)}
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"
diff --git a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
index 20418bbdc0..35b3d499fd 100644
--- a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
@@ -360,6 +360,9 @@ export function useWebSocket(): void {
} else {
const store = useEventStore.getState();
const forThisWindow = isForThisWindow(p, store.dictating);
+ // Signalled after the text has landed (below), so a composer
+ // sending on it reads the finished box.
+ queueMicrotask(() => useEventStore.getState().noteDictationFinal());
const delivered = forThisWindow
? deliverDictationText(text)
: "none";
diff --git a/jarvis/ui/web/frontend/src/store/events.ts b/jarvis/ui/web/frontend/src/store/events.ts
index 71ccf5f2ce..8b5f645e66 100644
--- a/jarvis/ui/web/frontend/src/store/events.ts
+++ b/jarvis/ui/web/frontend/src/store/events.ts
@@ -504,6 +504,10 @@ interface EventStore {
dictationText: string;
dictationCommitSeq: number;
dictationCommitText: string;
+ // Bumped on EVERY final transcript this window owns, whichever route it
+ // took (pasted into the focused field, or committed to the composer). A
+ // composer that ended a dictation with "send" waits on it.
+ dictationFinalSeq: number;
pendingTerminalCommand: PendingTerminalCommand | null;
cliConnectCoach: CliConnectCoach | null;
// When the user installs a CLI from within ClisView (clicking
@@ -559,6 +563,7 @@ interface EventStore {
setDictating: (b: boolean) => void;
setDictationInterim: (text: string) => void;
commitDictation: (text: string) => void;
+ noteDictationFinal: () => void;
setPendingTerminalCommand: (cmd: PendingTerminalCommand | null) => void;
setCliConnectCoach: (coach: CliConnectCoach | null) => void;
setPendingInstallCliName: (name: string | null) => void;
@@ -631,6 +636,7 @@ export const useEventStore = create<EventStore>((set, get) => ({
dictationText: "",
dictationCommitSeq: 0,
dictationCommitText: "",
+ dictationFinalSeq: 0,
pendingTerminalCommand: null,
cliConnectCoach: null,
pendingInstallCliName: null,
@@ -843,6 +849,8 @@ export const useEventStore = create<EventStore>((set, get) => ({
setDictating: (b) =>
set(b ? { dictating: true, dictationText: "" } : { dictating: false }),
setDictationInterim: (text) => set({ dictationText: text }),
+ noteDictationFinal: () =>
+ set((s) => ({ dictationFinalSeq: s.dictationFinalSeq + 1 })),
commitDictation: (text) =>
set((s) => ({
dictationCommitText: text,