Skip to content

Commit 47562fe

Browse files
committed
fix: scope dictation shortcuts and preserve draft feedback
1 parent 606400e commit 47562fe

8 files changed

Lines changed: 42 additions & 20 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import {
136136
import { attachmentUploadBlockReason } from "../../lib/attachmentUploadState";
137137
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
138138
import { isCommandPaletteOpen } from "../../commandPaletteBus";
139+
import { isInSideChatPane } from "../../lib/sideChatPane";
139140
import { getTerminalFocusOwner } from "../../lib/terminalFocus";
140141
import { resolveShortcutCommand, shortcutLabelForCommand } from "../../keybindings";
141142
import {
@@ -1232,10 +1233,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
12321233
activePendingProgress?.activeQuestion?.allowCustomAnswer === false;
12331234
/** The editor refuses text for these reasons; dictation also freezes it while active. */
12341235
const composerTextUnavailable =
1235-
isComposerApprovalState ||
1236-
projectSelectionRequired ||
1237-
isChoiceOnlyPendingQuestion ||
1238-
activePendingIsResponding;
1236+
projectSelectionRequired || isChoiceOnlyPendingQuestion || activePendingIsResponding;
12391237
const showComposerTopDrawer =
12401238
pendingUserInputs.length > 0 ||
12411239
(!isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan !== null);
@@ -2420,6 +2418,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
24202418
enabled: !composerTextUnavailable,
24212419
isDictateShortcut: (event) =>
24222420
!isCommandPaletteOpen() &&
2421+
(backgroundThread
2422+
? event.target instanceof Node && composerFormRef.current?.contains(event.target) === true
2423+
: !isInSideChatPane(event.target)) &&
24232424
resolveShortcutCommand(event, keybindings, {
24242425
context: {
24252426
terminalFocus: getTerminalFocusOwner() !== null,

‎apps/web/src/components/settings/DictationSettings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export function DictationRoutingSettings({
388388
<p className="px-3 py-2.5 text-xs text-muted-foreground sm:px-4">
389389
The machine that turns this device's dictation into text. Automatic uses the machine that
390390
owns the thread when its dictation is ready, otherwise another ready machine. Download
391-
models in Integrations. This applies only to this device.
391+
models in Devices. This applies only to this device.
392392
</p>
393393
{environments.map((environment) => (
394394
<EnvironmentRow

‎apps/web/src/dictation/streamingDictation.ts‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
type VoiceRecorder,
1212
type VoiceTranscriber,
1313
} from "@t3tools/client-runtime/voice-input";
14-
import type { DictationSessionId, EnvironmentId } from "@t3tools/contracts";
14+
import {
15+
DICTATION_MAX_SECONDS,
16+
DICTATION_SAMPLE_RATE,
17+
type DictationSessionId,
18+
type EnvironmentId,
19+
} from "@t3tools/contracts";
1520
import * as Base64 from "effect/encoding/Base64";
1621
import type { AtomRegistry } from "effect/reactivity";
1722

@@ -77,6 +82,7 @@ export function createStreamingDictation(input: {
7782
const capture = new PcmCapture();
7883
const level = createDictationLevel();
7984
let session: DictationSession | null = null;
85+
let captureStartedAt = 0;
8086
let limitTimer: ReturnType<typeof setTimeout> | null = null;
8187

8288
const run = <W, A, E>(command: AtomCommand<W, A, E>, value: W) =>
@@ -202,10 +208,13 @@ export function createStreamingDictation(input: {
202208
const current = session;
203209
if (current === null) throw new Error("No dictation session is open.");
204210
clearLimit();
205-
limitTimer = setTimeout(() => {
206-
limitTimer = null;
207-
void capture.stop().then(() => input.finishedAtLimit(sessionUri(current)));
208-
}, forDuration * 1_000);
211+
limitTimer = setTimeout(
212+
() => {
213+
limitTimer = null;
214+
void capture.stop().then(() => input.finishedAtLimit(sessionUri(current)));
215+
},
216+
Math.max(0, forDuration * 1_000 - (Date.now() - captureStartedAt)),
217+
);
209218
},
210219
stop: async () => {
211220
clearLimit();
@@ -231,8 +240,19 @@ export function createStreamingDictation(input: {
231240
}
232241
await capture.prepare();
233242
const current = session;
243+
captureStartedAt = Date.now();
244+
let capturedBytes = 0;
245+
const maxBytes = DICTATION_MAX_SECONDS * DICTATION_SAMPLE_RATE * 2;
234246
capture.start((frame) => {
235-
if (current !== null) sendChunk(current, frame);
247+
const remaining = maxBytes - capturedBytes;
248+
if (current === null || remaining <= 0) return;
249+
const chunk = frame.byteLength > remaining ? frame.slice(0, remaining) : frame;
250+
capturedBytes += chunk.byteLength;
251+
sendChunk(current, chunk);
252+
if (capturedBytes === maxBytes) {
253+
clearLimit();
254+
void capture.stop().then(() => input.finishedAtLimit(sessionUri(current)));
255+
}
236256
}, level.set);
237257
return { granted: true, canAskAgain: true };
238258
},

‎apps/web/src/dictation/useComposerDictation.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ function createComposerDictationController(input: {
4141
resolveEnvironmentId: () => readLatest().environmentId,
4242
interrupt: (message) => void controller?.interruptRecording(message),
4343
rewriteTranscript: (text) => readLatest().rewriteTranscript(text),
44-
finishedAtLimit: (uri) =>
45-
void controller?.handleRecorderStatus({
46-
isFinished: true,
47-
hasError: false,
48-
error: null,
49-
url: uri,
50-
}),
44+
finishedAtLimit: () => void controller?.stop(),
5145
});
5246
const created = new VoiceInputController({
5347
...streaming.dependencies,

‎apps/web/src/dictation/useDictationHoldShortcut.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function useDictationHoldShortcut(input: {
3434
};
3535

3636
const onKeyDown = (event: KeyboardEvent) => {
37+
if (event.defaultPrevented) return;
3738
const { dictation, enabled, isDictateShortcut } = latest.current;
3839
const phase = dictation.readPhase();
3940
const active = phase === "preparing" || phase === "recording" || phase === "transcribing";

‎docs/user/composer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ transcription or cancellation; only the message text is sent when you submit.
199199
## Dictation on web and desktop
200200

201201
Dictation turns speech into text with a speech model that runs on one of your T3 Code
202-
machines. Set it up for that machine in **Settings → Integrations → Dictation**: turn it on and
202+
machines. Set it up for that machine in **Settings → Devices → Dictation**: turn it on and
203203
pick a model. Parakeet v3 covers 25 European languages, Whisper turbo covers 99, and Moonshine
204204
base is a small English-only model. Nothing downloads until dictation is on; then the machine
205205
downloads the model you picked and the status line shows the progress. **Language** can pin

‎packages/client-runtime/src/voice-input/controller.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ describe("resolveTranscriptCommit", () => {
173173
expect(
174174
resolveTranscriptCommit(continuing, continuing, "Und die Tests.", "de-DE"),
175175
).toMatchObject({ text: "Fix the bugUnd die Tests before release." });
176+
const beforeName = at("ask ", 4);
177+
expect(
178+
resolveTranscriptCommit(beforeName, beforeName, "Maria to review.", "en-US"),
179+
).toMatchObject({
180+
text: "ask Maria to review.",
181+
});
176182
const midSentence = at("Fix the bug before release.", 11);
177183
expect(resolveTranscriptCommit(midSentence, midSentence, "and tests", "en-US")).toMatchObject({
178184
text: "Fix the bug and tests before release.",

‎packages/client-runtime/src/voice-input/controller.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function resolveTranscriptCommit(
121121
if (atSentenceStart) {
122122
if (!/\p{Lu}/u.test(firstWord)) insertion = withFirstLetterCase(insertion, locale, true);
123123
} else {
124-
const plainCapitalized = /^\p{Lu}\p{Ll}*\P{L}*$/u.test(firstWord) && !/^I\b/u.test(firstWord);
124+
const plainCapitalized = /^(?:And|Also|Then|But|Or|So)\b/u.test(firstWord);
125125
if (usesEnglishSpacing && plainCapitalized) {
126126
insertion = withFirstLetterCase(insertion, locale, false);
127127
}

0 commit comments

Comments
 (0)