Skip to content

Commit 278258c

Browse files
fix(voice): allow transcript cleanup on cloud-only environments
1 parent eb4f0f5 commit 278258c

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const mocks = vi.hoisted(() => ({
2828
settings: {} as Record<string, unknown>,
2929
connected: new Set<string>(),
3030
voiceCapable: new Set<string>(),
31+
cloudVoiceCapable: new Set<string>(),
3132
canDictate: new Set<string>(),
3233
prepared: new Map<string, unknown>(),
3334
primaryEnvironmentId: "primary-env",
@@ -68,7 +69,10 @@ vi.mock("../state/environments", () => ({
6869
environmentId,
6970
serverConfig: {
7071
environment: {
71-
capabilities: { voiceTranscription: mocks.voiceCapable.has(environmentId) },
72+
capabilities: {
73+
voiceTranscription: mocks.voiceCapable.has(environmentId),
74+
cloudVoiceTranscription: mocks.cloudVoiceCapable.has(environmentId),
75+
},
7276
},
7377
},
7478
}
@@ -176,6 +180,7 @@ function setup(options: { readonly destination?: string | null } = {}) {
176180
mocks.primaryEnvironmentId = "primary-env";
177181
mocks.connected = new Set(["primary-env", THREAD_ENV, "env-a", "env-b"]);
178182
mocks.voiceCapable = new Set(["primary-env", THREAD_ENV, "env-a", "env-b"]);
183+
mocks.cloudVoiceCapable.clear();
179184
mocks.canDictate = new Set(mocks.voiceCapable);
180185
mocks.prepared.clear();
181186
mocks.statusRequests = [];
@@ -435,15 +440,18 @@ it("uses neither destination when the cloud save marker cannot be read", async (
435440
expectNoAudioSent();
436441
});
437442

438-
it("cleans the transcript only after cleanup is separately enabled", async () => {
443+
it("cleans text on a cloud-only draft environment only while cleanup is separately enabled", async () => {
439444
setup({ destination: "env-a" });
445+
mocks.voiceCapable.delete(THREAD_ENV);
446+
mocks.cloudVoiceCapable.add(THREAD_ENV);
440447
chooseTranscriptCleanup(true);
441448
const nearby = "x".repeat(1_024);
442449
mocks.draft = "unrelated private paragraph " + nearby;
443450
await using screen = await render(<Probe />);
444451
await act(() => mocks.voice.start());
445452
await act(() => mocks.voice.stop());
446-
expect(mocks.cleanupCalls).toHaveLength(1);
453+
expect(mocks.transcribeCalls).toEqual(["env-a"]);
454+
expect(mocks.cleanupCalls).toEqual([THREAD_ENV]);
447455
expect(mocks.cleanupDraft).toHaveBeenCalledExactlyOnceWith({
448456
text: nearby,
449457
selection: { start: nearby.length, end: nearby.length },
@@ -468,6 +476,7 @@ it.each([
468476
"keeps a recording without authorized cleanup off the provider: $cleanup / $authorized",
469477
async ({ cleanup, authorized }) => {
470478
setup({ destination: "env-a" });
479+
mocks.cloudVoiceCapable.add(THREAD_ENV);
471480
chooseTranscriptCleanup(true);
472481
mocks.settings.speechCorrectionWord = "sorry";
473482
if (!authorized) mocks.canDictate.delete(THREAD_ENV);

‎apps/web/src/speech/useEnvironmentSpeechInput.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,13 @@ export function useEnvironmentSpeechInput(input: HookInput) {
131131
const prepared = destination.prepared;
132132
const grantId = destination.grantId;
133133
const cloudProvider = destination.cloudProvider;
134-
const originatingEnvironment = useEnvironment(input.environmentId);
134+
const draftCapabilities = useEnvironment(input.environmentId)?.serverConfig?.environment
135+
.capabilities;
135136
const originatingConnection = Option.getOrNull(usePreparedConnection(input.environmentId));
136137
const canCleanUp = useEnvironmentScope(input.environmentId, AuthOrchestrationOperateScope);
137138
const cleanupPrepared =
138139
canCleanUp &&
139-
originatingEnvironment?.serverConfig?.environment.capabilities.voiceTranscription === true
140+
(draftCapabilities?.voiceTranscription || draftCapabilities?.cloudVoiceTranscription)
140141
? originatingConnection
141142
: null;
142143
const clientSettings = useClientSettings();

0 commit comments

Comments
 (0)