From 6e3b1c2f00c059705b11d2a7cf7b47bf14220552 Mon Sep 17 00:00:00 2001
From: eyeveil <64274427+eyeveil@users.noreply.github.com>
Date: Mon, 9 Nov 2026 16:45:27 +0100
Subject: [PATCH 1/4] Test that the composer shows one microphone
---
.../src/components/ChatView.browser.test.tsx | 45 ++++++++++++++++++-
apps/web/test/fakeEnvironment.ts | 2 +-
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx
index 96eb837db4d69..97cef3e129251 100644
--- a/apps/web/src/components/ChatView.browser.test.tsx
+++ b/apps/web/src/components/ChatView.browser.test.tsx
@@ -1,6 +1,6 @@
import { createMemoryHistory } from "@tanstack/react-router";
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
-import { ThreadId } from "@t3tools/contracts";
+import { ThreadId, type VoiceTranscriptionDestination } from "@t3tools/contracts";
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
import type * as Context from "effect/Context";
import { expect, it, vi } from "vite-plus/test";
@@ -13,6 +13,7 @@ import "~/components/ChatView";
import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
import { __setClientSettingsForTests } from "~/hooks/useSettings";
import { getRouter } from "~/router";
+import { chooseAudioDestination } from "~/speech/voiceConsent";
import {
ENVIRONMENT_ID,
PROJECT_ID,
@@ -65,3 +66,45 @@ it("a new draft does not load its reserved thread before the server lists it", a
// A 404 here marks the thread deleted, and the view never loads it once the send creates it.
expect(threadRequests).toEqual([]);
});
+
+const MICROPHONE_BUTTONS = /^(Dictate|Set up dictation|Start voice input)$/;
+
+it.each<{
+ readonly state: string;
+ readonly destination: VoiceTranscriptionDestination | null;
+ readonly microphone: string;
+}>([
+ { state: "no Voice destination", destination: null, microphone: "Set up dictation" },
+ {
+ state: "a chosen Voice destination",
+ destination: { kind: "cloud", environmentId: ENVIRONMENT_ID, provider: "openai" },
+ microphone: "Start voice input",
+ },
+])("the composer shows one microphone with $state", async ({ destination, microphone }) => {
+ using _environment = installFakeEnvironment([]);
+ using _voiceChoice = {
+ [Symbol.dispose]: () => window.localStorage.removeItem("t3code:voice-audio-grant:v1"),
+ };
+ if (destination) chooseAudioDestination(destination);
+ __setClientSettingsForTests({
+ ...DEFAULT_CLIENT_SETTINGS,
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
+ });
+ const draftId = DraftId.make(`draft-microphone-${destination?.kind ?? "none"}`);
+ useComposerDraftStore
+ .getState()
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
+ threadId: ThreadId.make(`thread-microphone-${destination?.kind ?? "none"}`),
+ });
+
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
+ await router.load();
+ await using _app = await render(, {
+ // AppRoot brings its own router.
+ router: false,
+ });
+ await expect.element(page.getByRole("button", { name: microphone, exact: true })).toBeVisible();
+
+ const microphones = page.getByRole("button", { name: MICROPHONE_BUTTONS }).elements();
+ expect(microphones.map((button) => button.getAttribute("aria-label"))).toEqual([microphone]);
+});
diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts
index 44cd45d127e11..e5348fb698d18 100644
--- a/apps/web/test/fakeEnvironment.ts
+++ b/apps/web/test/fakeEnvironment.ts
@@ -58,7 +58,7 @@ const descriptor = {
// A matching version, since a mismatch adds an update banner a typical user never sees.
serverVersion: APP_VERSION,
orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION,
- capabilities: { repositoryIdentity: true },
+ capabilities: { repositoryIdentity: true, cloudVoiceTranscription: true },
};
const auth = {
policy: "loopback-browser",
From 182b22b1d39a7b370b42d5bd6b8fba2e65aab06e Mon Sep 17 00:00:00 2001
From: eyeveil <64274427+eyeveil@users.noreply.github.com>
Date: Mon, 9 Nov 2026 16:45:37 +0100
Subject: [PATCH 2/4] Show one microphone in the composer
---
apps/web/src/components/chat/ChatComposer.tsx | 17 +++++++++++------
docs/user/composer.md | 3 +++
docs/user/voice-input.md | 3 ++-
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 8cdb50ef6a256..e7acef4eeec86 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -1941,6 +1941,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
ownerKey: questionAttachmentTarget ?? composerDraftTargetKey,
draftText: prompt,
disabled: dictationDisabled,
+ offerSetup: false,
readDraft: () => {
const snapshot = readComposerSnapshot();
return {
@@ -1963,6 +1964,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
window.requestAnimationFrame(() => composerEditorRef.current?.focusAt(cursor));
},
});
+ // Dictation and Voice input are separate systems that share one composer microphone.
+ const voiceInputOwnsMicrophone = speechInput.available && !dictation.active;
const { blocksSubmission: voiceInputActive, submitAfterDictation } = speechInput;
const voiceSendDisabledReason =
sendDisabledReason ?? (speechInput.preparing ? "Preparing voice input" : null);
@@ -3718,11 +3721,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
>
{composerControls}
-
+ {voiceInputOwnsMicrophone ? null : (
+
+ )}
- {speechInput.available ? (
+ {voiceInputOwnsMicrophone ? (
<>
Date: Mon, 9 Nov 2026 16:51:08 +0100
Subject: [PATCH 3/4] Test that one recording blocks the other shortcut
---
.../src/components/ChatView.browser.test.tsx | 89 +++++++++++++++----
1 file changed, 72 insertions(+), 17 deletions(-)
diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx
index 97cef3e129251..8a39fa8c7cec5 100644
--- a/apps/web/src/components/ChatView.browser.test.tsx
+++ b/apps/web/src/components/ChatView.browser.test.tsx
@@ -21,6 +21,8 @@ import {
type FakeDriver,
} from "../../test/fakeEnvironment";
import { render } from "../../test/render";
+import { useComposerDictation } from "~/dictation/useComposerDictation";
+import { useEnvironmentSpeechInput } from "~/speech/useEnvironmentSpeechInput";
// The socket is the only fake layer; see test/appScenarios.renders.tsx.
vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
@@ -32,6 +34,8 @@ vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (i
return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
});
+vi.mock(import("~/dictation/useComposerDictation"), { spy: true });
+vi.mock(import("~/speech/useEnvironmentSpeechInput"), { spy: true });
vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
...(await original()),
trackRpcRequestSent: () => {},
@@ -69,6 +73,23 @@ it("a new draft does not load its reserved thread before the server lists it", a
const MICROPHONE_BUTTONS = /^(Dictate|Set up dictation|Start voice input)$/;
+async function renderDraftComposer(name: string) {
+ __setClientSettingsForTests({
+ ...DEFAULT_CLIENT_SETTINGS,
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
+ });
+ const draftId = DraftId.make(`draft-microphone-${name}`);
+ useComposerDraftStore
+ .getState()
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
+ threadId: ThreadId.make(`thread-microphone-${name}`),
+ });
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
+ await router.load();
+ // AppRoot brings its own router.
+ return render(, { router: false });
+}
+
it.each<{
readonly state: string;
readonly destination: VoiceTranscriptionDestination | null;
@@ -86,25 +107,59 @@ it.each<{
[Symbol.dispose]: () => window.localStorage.removeItem("t3code:voice-audio-grant:v1"),
};
if (destination) chooseAudioDestination(destination);
- __setClientSettingsForTests({
- ...DEFAULT_CLIENT_SETTINGS,
- onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
- });
- const draftId = DraftId.make(`draft-microphone-${destination?.kind ?? "none"}`);
- useComposerDraftStore
- .getState()
- .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
- threadId: ThreadId.make(`thread-microphone-${destination?.kind ?? "none"}`),
- });
-
- const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
- await router.load();
- await using _app = await render(, {
- // AppRoot brings its own router.
- router: false,
- });
+ await using _app = await renderDraftComposer(destination?.kind ?? "none");
await expect.element(page.getByRole("button", { name: microphone, exact: true })).toBeVisible();
const microphones = page.getByRole("button", { name: MICROPHONE_BUTTONS }).elements();
expect(microphones.map((button) => button.getAttribute("aria-label"))).toEqual([microphone]);
});
+
+const isMac = /Mac/.test(navigator.platform);
+
+it.each([
+ {
+ running: "Voice input",
+ chord: { key: " ", code: "Space", altKey: isMac, ctrlKey: !isMac, shiftKey: !isMac },
+ visibleControl: "Finish voice input",
+ },
+ {
+ running: "Dictation",
+ chord: { key: "d", code: "KeyD", metaKey: isMac, ctrlKey: !isMac, shiftKey: true },
+ visibleControl: "Stop and insert dictation",
+ },
+])("a running $running recording blocks the other shortcut", async (row) => {
+ const { useEnvironmentSpeechInput: realVoice } = await vi.importActual<
+ typeof import("~/speech/useEnvironmentSpeechInput")
+ >("~/speech/useEnvironmentSpeechInput");
+ const { useComposerDictation: realDictation } = await vi.importActual<
+ typeof import("~/dictation/useComposerDictation")
+ >("~/dictation/useComposerDictation");
+ const recording = { phase: "recording", error: null, errorAction: null } as const;
+ const voiceRunning = row.running === "Voice input";
+ const startVoice = vi.fn(async () => {});
+ const startDictation = vi.fn();
+ using _environment = installFakeEnvironment([]);
+ using _voice = vi.mocked(useEnvironmentSpeechInput).mockImplementation((input) => ({
+ ...realVoice(input),
+ available: true,
+ start: startVoice,
+ ...(voiceRunning ? { state: recording, blocksSubmission: true } : {}),
+ }));
+ using _dictation = vi.mocked(useComposerDictation).mockImplementation((input) => ({
+ ...realDictation(input),
+ start: startDictation,
+ ...(voiceRunning ? {} : { state: recording, active: true, readPhase: () => "recording" }),
+ }));
+ await using _app = await renderDraftComposer(`busy-${row.running}`);
+ await expect
+ .element(page.getByRole("button", { name: row.visibleControl, exact: true }))
+ .toBeVisible();
+
+ window.dispatchEvent(new KeyboardEvent("keydown", { ...row.chord, cancelable: true }));
+
+ expect(startVoice).not.toHaveBeenCalled();
+ expect(startDictation).not.toHaveBeenCalled();
+ await expect
+ .element(page.getByRole("button", { name: row.visibleControl, exact: true }))
+ .toBeVisible();
+});
From 398671db199e242af79f38911f7a7cff3b013da8 Mon Sep 17 00:00:00 2001
From: eyeveil <64274427+eyeveil@users.noreply.github.com>
Date: Mon, 9 Nov 2026 16:51:17 +0100
Subject: [PATCH 4/4] Block a second recording from either voice shortcut
---
apps/web/src/components/chat/ChatComposer.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index e7acef4eeec86..e47a652892d1a 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -1972,7 +1972,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const dictationShortcutLabel = useDictationShortcut({
keybindings,
speech: speechInput,
- disabled: dictationDisabled,
+ disabled: dictationDisabled || dictation.active,
terminalOpen,
modelPickerOpen: isComposerModelPickerOpen,
...(backgroundThread ? { targetRef: composerFormRef } : {}),
@@ -2698,7 +2698,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
useDictationHoldShortcut({
dictation,
- enabled: !composerTextUnavailable,
+ enabled: !composerTextUnavailable && !voiceInputActive,
isDictateShortcut: (event) =>
!isCommandPaletteOpen() &&
(backgroundThread