The best way to control Claude Code, Codex and more from any computer or phone
feat(mobile): pick a voice environment once, then its method (#34073)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 14:35 UTC
17a6a01d84e3adf9f29df2639d6b6079a434e1b2
4 files changed
+439
-317
apps/mobile/src/components/ui/ListRow.tsx
+41
-10
@@ -1,17 +1,27 @@
1
-import { Platform } from "react-native";
1
+import { Platform, View } from "react-native";
2
3
import { useResolveClassNames } from "uniwind";
4
import { SymbolView } from "./AppSymbol";
5
import { ListRowLayout, type ListRowContentProps } from "./ListRowLayout";
6
+import { RadioIndicator } from "./RadioIndicator";
7
import { RowPressable } from "./RowPressable";
8
8
-export function ListRow(props: ListRowContentProps & { readonly onPress: () => void }) {
9
+export function ListRow(
10
+ props: ListRowContentProps & {
11
+ readonly onPress: () => void;
12
+ /** Marks the row as the chosen option while it still navigates. */
13
+ readonly selected?: boolean;
14
+ },
15
+) {
16
const rippleStyle = useResolveClassNames("bg-subtle-strong");
17
return (
18
<RowPressable
19
accessibilityRole="button"
20
accessibilityLabel={[props.label, props.description, props.detail].filter(Boolean).join(", ")}
14
- accessibilityState={{ disabled: Boolean(props.disabled) }}
21
+ accessibilityState={{
22
+ disabled: Boolean(props.disabled),
23
+ ...(props.selected === undefined ? {} : { checked: props.selected }),
24
+ }}
25
disabled={props.disabled}
26
onPress={props.onPress}
27
android_ripple={{ color: rippleStyle.backgroundColor }}
@@ -21,13 +31,34 @@ export function ListRow(props: ListRowContentProps & { readonly onPress: () => v
31
<ListRowLayout
32
{...props}
33
accessory={
24
- <SymbolView
25
- name="chevron.right"
26
- size={16}
27
- tintColorClassName="accent-chevron"
28
- type="monochrome"
29
- weight="semibold"
30
- />
34
+ <View className="flex-row items-center gap-3">
35
+ {props.selected === undefined ? null : (
36
+ <View
37
+ accessibilityElementsHidden
38
+ importantForAccessibility="no-hide-descendants"
39
+ className="size-6 items-center justify-center"
40
+ >
41
+ {Platform.OS === "android" ? (
42
+ <RadioIndicator selected={props.selected} />
43
+ ) : props.selected ? (
44
+ <SymbolView
45
+ name="checkmark"
46
+ size={18}
47
+ tintColorClassName="accent-primary-text"
48
+ type="monochrome"
49
+ weight="semibold"
50
+ />
51
+ ) : null}
52
+ </View>
53
+ )}
54
+ <SymbolView
55
+ name="chevron.right"
56
+ size={16}
57
+ tintColorClassName="accent-chevron"
58
+ type="monochrome"
59
+ weight="semibold"
60
+ />
61
+ </View>
62
}
63
/>
64
</RowPressable>
apps/mobile/src/features/settings/CloudVoiceSection.tsx
+272
-223
@@ -21,7 +21,7 @@ import {
21
import * as Schema from "effect/Schema";
22
import Constants from "expo-constants";
23
import { AsyncResult } from "effect/reactivity";
24
-import { useState } from "react";
24
+import { type ReactNode, useState } from "react";
25
import { ScrollView, TextInput, View } from "react-native";
26
import { Sheet } from "../../components/ui/Sheet";
27
import * as Dialog from "../../components/ui/Dialog";
@@ -30,6 +30,7 @@ import { AppText as Text } from "../../components/ui/AppText";
30
import { ListActionRow } from "../../components/ui/ListActionRow";
31
import { ListChoiceRow } from "../../components/ui/ListChoiceRow";
32
import { Chip } from "../../components/ui/Chip";
33
+import { ListSection } from "../../components/ui/ListSection";
34
import type { EnvironmentPresentation } from "../../state/environments";
35
import { useEnvironmentScope } from "../../state/session";
36
import {
@@ -40,7 +41,6 @@ import {
41
cloudVoiceModelsAtom,
42
runSpeech,
43
} from "../voice-input/voiceDestination";
43
-import { SettingsSection } from "./components/SettingsSection";
44
45
type CloudDestination = Extract<VoiceTranscriptionDestination, { kind: "cloud" }>;
46
type Props = { environment: EnvironmentPresentation; active: CloudDestination | null };
@@ -48,23 +48,38 @@ const isApiKey = Schema.is(CloudSpeechApiKey);
48
const isModelId = Schema.is(CloudSpeechModelId);
49
const MODEL_ROWS = 6;
50
51
-export function CloudVoiceSection({ environment, active }: Props) {
52
- const [open, setOpen] = useState(false);
51
+/** The cloud method row for one environment; opens the provider sheet. */
52
+export function CloudVoiceChoice({
53
+ environment,
54
+ active,
55
+ open,
56
+ onOpenChange,
57
+}: Props & { open: boolean; onOpenChange: (open: boolean) => void }) {
58
+ const usable = useAtomValue(cloudVoiceConnectionAtom(environment.environmentId)) !== null;
59
return (
54
- <SettingsSection title={`Cloud via ${environment.label}`}>
55
- <ListActionRow
56
- label="Cloud providers"
60
+ <>
61
+ <ListChoiceRow
62
+ label="Cloud provider"
63
description={
64
active
59
- ? `Using ${CLOUD_SPEECH_LABELS[active.provider]}`
60
- : "Optional · use your own API key"
65
+ ? `${CLOUD_SPEECH_LABELS[active.provider]}${active.provider === "openrouter" ? ` · ${active.model}` : ""}`
66
+ : usable
67
+ ? "Use your own API key"
68
+ : "Not connected"
69
}
62
- onPress={() => setOpen(true)}
70
+ selected={active !== null}
71
+ disabled={!usable}
72
+ separated
73
+ onPress={() => onOpenChange(true)}
74
/>
75
{open && (
65
- <CloudChoices environment={environment} active={active} onClose={() => setOpen(false)} />
76
+ <CloudChoices
77
+ environment={environment}
78
+ active={active}
79
+ onClose={() => onOpenChange(false)}
80
+ />
81
)}
67
- </SettingsSection>
82
+ </>
83
);
84
}
85
@@ -92,54 +107,70 @@ function ModelPicker({
107
const shown = showAll ? matches : matches.slice(0, MODEL_ROWS);
108
const delisted = current !== undefined && !models.some((model) => model.id === current);
109
return (
95
- <>
96
- <TextInput
97
- accessibilityLabel="Search OpenRouter models"
98
- placeholder="Search transcription models"
99
- autoCapitalize="none"
100
- autoCorrect={false}
101
- editable={!disabled}
102
- value={query}
103
- onChangeText={setQuery}
104
- className="mx-4 rounded-lg bg-background px-3 py-2 text-foreground"
105
- />
106
- {delisted ? (
107
- <Text className="mx-4 text-sm text-destructive">
108
- OpenRouter no longer lists {current}. Dictation stays off until you choose another model.
109
- </Text>
110
- ) : null}
110
+ <ListSection
111
+ title="Model"
112
+ footer={
113
+ delisted
114
+ ? `OpenRouter no longer lists ${current}. Dictation stays off until you choose another model.`
115
+ : undefined
116
+ }
117
+ >
118
+ <View className="px-4 py-3">
119
+ <TextInput
120
+ accessibilityLabel="Search OpenRouter models"
121
+ placeholder="Search transcription models"
122
+ autoCapitalize="none"
123
+ autoCorrect={false}
124
+ editable={!disabled}
125
+ value={query}
126
+ onChangeText={setQuery}
127
+ className="rounded-lg bg-background px-3 py-2 text-foreground"
128
+ />
129
+ </View>
130
{selected && !shown.some((model) => model.id === selected.id) ? (
131
<ListChoiceRow
132
label={selected.name}
133
description={selected.id}
134
selected
135
+ separated
136
disabled={disabled}
137
onPress={() => {}}
138
/>
139
) : null}
120
- {shown.map((model, index) => (
140
+ {shown.map((model) => (
141
<ListChoiceRow
142
key={model.id}
143
label={model.name}
144
description={model.id}
145
selected={model.id === value}
126
- separated={index > 0}
146
+ separated
147
disabled={disabled}
148
onPress={() => onChange(model.id)}
149
/>
150
))}
151
{matches.length === 0 ? (
132
- <Text className="mx-4 text-sm text-foreground-muted">No transcription model matches.</Text>
152
+ <Separated>
153
+ <Text className="px-4 py-3 text-sm text-foreground-muted">
154
+ No transcription model matches.
155
+ </Text>
156
+ </Separated>
157
) : matches.length > shown.length ? (
134
- <ListActionRow
135
- label={`Show all ${matches.length} models`}
136
- onPress={() => setShowAll(true)}
137
- />
158
+ <Separated>
159
+ <ListActionRow
160
+ label={`Show all ${matches.length} models`}
161
+ onPress={() => setShowAll(true)}
162
+ />
163
+ </Separated>
164
) : null}
139
- </>
165
+ </ListSection>
166
);
167
}
168
169
+/** A hairline above a row that has no `separated` prop of its own. */
170
+function Separated({ children }: { children: ReactNode }) {
171
+ return <View className="border-t border-border-subtle">{children}</View>;
172
+}
173
+
174
function CloudChoices({ environment, active, onClose }: Props & { onClose: () => void }) {
175
const id = environment.environmentId;
176
const connection = useAtomValue(cloudVoiceConnectionAtom(id));
@@ -223,58 +254,35 @@ function CloudChoices({ environment, active, onClose }: Props & { onClose: () =>
254
onClose();
255
};
256
const catalog = AsyncResult.isSuccess(models) ? (models.value?.models ?? null) : null;
226
- const content =
227
- !AsyncResult.isSuccess(keys) || !keys.value || !connection ? (
228
- <ListActionRow
229
- label={
230
- !connection
231
- ? "Environment not connected"
232
- : keys._tag === "Failure"
233
- ? "Could not load keys · Retry"
234
- : "Checking API keys…"
235
- }
236
- disabled={!connection || keys._tag !== "Failure"}
237
- onPress={reload}
238
- />
239
- ) : (
240
- CloudSpeechProvider.literals.map((provider) => {
241
- if (editing && provider !== editing.provider) return null;
242
- const label = CLOUD_SPEECH_LABELS[provider];
243
- const company = CLOUD_SPEECH_PROVIDER_NAMES[provider];
244
- const routed = provider === "openrouter";
245
- const disclosure = cloudSpeechDisclosure(provider, environment.label);
246
- const saved = keys.value![provider];
247
- const isActive = active?.provider === provider;
248
- const isEditing = editing?.provider === provider;
249
- const modelChosen =
250
- isModelId(model) && (catalog?.some((entry) => entry.id === model) ?? false);
251
- const modelChanged = model !== (activeModel ?? "");
252
- const original = environment.serverConfig?.settings.cloudSpeechCredentials?.[provider];
253
- const keyChanged =
254
- credential !== undefined &&
255
- !(
256
- isSecretReference(credential) &&
257
- isSecretReference(original) &&
258
- original.provider === credential.provider &&
259
- original.reference === credential.reference
260
- );
261
- const routedReady =
262
- modelChosen &&
263
- (draft.trim() ? credential !== undefined : Boolean(saved)) &&
264
- (!isActive || modelChanged || keyChanged);
265
- const saveRouted = () => {
266
- if (!routedReady || !isModelId(model)) return;
267
- const grantChanges = !isActive || modelChanged;
268
- if (credential !== undefined && keyChanged)
269
- return void changeKey(provider, credential, model);
270
- // Model-only changes never write to the environment.
271
- if (grantChanges) enable(() => chooseVoiceDestination(id, provider, model));
272
- onClose();
273
- };
274
- return (
275
- <View key={provider}>
276
- {!isEditing && (
257
+ const content = (() => {
258
+ if (!AsyncResult.isSuccess(keys) || !keys.value || !connection)
259
+ return (
260
+ <ListSection>
261
+ <ListActionRow
262
+ label={
263
+ !connection
264
+ ? "Environment not connected"
265
+ : keys._tag === "Failure"
266
+ ? "Could not load keys · Retry"
267
+ : "Checking API keys…"
268
+ }
269
+ disabled={!connection || keys._tag !== "Failure"}
270
+ onPress={reload}
271
+ />
272
+ </ListSection>
273
+ );
274
+ const saved = keys.value;
275
+ if (!editing)
276
+ return (
277
+ <ListSection footer={`Audio is sent through ${environment.label} using its API key.`}>
278
+ {CloudSpeechProvider.literals.map((provider, index) => {
279
+ const label = CLOUD_SPEECH_LABELS[provider];
280
+ const routed = provider === "openrouter";
281
+ const key = saved[provider];
282
+ const isActive = active?.provider === provider;
283
+ return (
284
<ListChoiceRow
285
+ key={provider}
286
label={label}
287
leading={
288
<ProviderIcon
@@ -285,176 +293,217 @@ function CloudChoices({ environment, active, onClose }: Props & { onClose: () =>
293
/>
294
}
295
selected={isActive}
288
- disabled={saved === undefined || (!saved && !canManage) || saving}
296
+ separated={index > 0}
297
+ disabled={key === undefined || (!key && !canManage) || saving}
298
description={
290
- saved === undefined
299
+ key === undefined
300
? "Update the environment to use this provider"
301
: isActive && routed
302
? `${activeModel} · Tap to change model${canManage ? " or key" : ""}`
294
- : isActive && saved && canManage
303
+ : isActive && key && canManage
304
? "Tap to manage key"
296
- : saved
305
+ : key
306
? routed
307
? "API key saved · choose a model to use it"
299
- : "API key saved on this environment"
308
+ : "API key saved"
309
: canManage
310
? "Add an API key to use this provider"
311
: "Ask an environment administrator to add an API key"
312
}
313
onPress={() => {
314
if (routed) return edit(provider, !isActive);
306
- if (!saved) return edit(provider, true);
315
+ if (!key) return edit(provider, true);
316
if (isActive) {
317
if (canManage) edit(provider, false);
318
return;
319
}
320
Dialog.confirm({
321
title: `Use ${label} for dictation?`,
313
- message: `${disclosure} Select This device to stop sharing.`,
322
+ message: `${cloudSpeechDisclosure(provider, environment.label)} Select This device to stop sharing.`,
323
confirmText: `Use ${label}`,
324
onConfirm: () => enable(pendingCloudVoiceChoice(id, provider)),
325
});
326
}}
327
/>
319
- )}
320
- {isEditing && routed && (
321
- <>
322
- <Text className="mx-4 text-sm text-foreground-muted">{disclosure}</Text>
323
- {catalog ? (
324
- <ModelPicker
325
- models={catalog}
326
- value={model}
327
- current={activeModel}
328
+ );
329
+ })}
330
+ </ListSection>
331
+ );
332
+
333
+ const provider = editing.provider;
334
+ const label = CLOUD_SPEECH_LABELS[provider];
335
+ const company = CLOUD_SPEECH_PROVIDER_NAMES[provider];
336
+ const routed = provider === "openrouter";
337
+ const disclosure = cloudSpeechDisclosure(provider, environment.label);
338
+ const key = saved[provider];
339
+ const isActive = active?.provider === provider;
340
+ const modelChosen = isModelId(model) && (catalog?.some((entry) => entry.id === model) ?? false);
341
+ const modelChanged = model !== (activeModel ?? "");
342
+ const original = environment.serverConfig?.settings.cloudSpeechCredentials?.[provider];
343
+ const keyChanged =
344
+ credential !== undefined &&
345
+ !(
346
+ isSecretReference(credential) &&
347
+ isSecretReference(original) &&
348
+ original.provider === credential.provider &&
349
+ original.reference === credential.reference
350
+ );
351
+ const routedReady =
352
+ modelChosen &&
353
+ (draft.trim() ? credential !== undefined : Boolean(key)) &&
354
+ (!isActive || modelChanged || keyChanged);
355
+ const saveRouted = () => {
356
+ if (!routedReady || !isModelId(model)) return;
357
+ const grantChanges = !isActive || modelChanged;
358
+ if (credential !== undefined && keyChanged)
359
+ return void changeKey(provider, credential, model);
360
+ // Model-only changes never write to the environment.
361
+ if (grantChanges) enable(() => chooseVoiceDestination(id, provider, model));
362
+ onClose();
363
+ };
364
+ const submit = () => {
365
+ if (routed) saveRouted();
366
+ else if (credential) void changeKey(provider, credential);
367
+ };
368
+ const keyFooter =
369
+ draft && !credential
370
+ ? (source?.invalidReferenceMessage ?? "Enter a valid API key.")
371
+ : routed
372
+ ? key && !credential
373
+ ? "Uses the API key saved on this environment. The model choice applies only to this device."
374
+ : `Anyone with dictation access to ${environment.label} can bill this key.`
375
+ : editing.enable
376
+ ? `Anyone with dictation access to ${environment.label} can bill this key.`
377
+ : `Updates the ${company} key on ${environment.label}. Your dictation destination stays the same.`;
378
+ return (
379
+ <>
380
+ <Text className="px-2 text-sm text-foreground-muted">{disclosure}</Text>
381
+ {routed ? (
382
+ catalog ? (
383
+ <ModelPicker
384
+ models={catalog}
385
+ value={model}
386
+ current={activeModel}
387
+ disabled={saving}
388
+ onChange={setModel}
389
+ />
390
+ ) : (
391
+ <ListSection title="Model">
392
+ <ListActionRow
393
+ label={
394
+ AsyncResult.isFailure(models)
395
+ ? "Could not load models · Retry"
396
+ : "Loading transcription models…"
397
+ }
398
+ disabled={!AsyncResult.isFailure(models)}
399
+ onPress={reloadModels}
400
+ />
401
+ </ListSection>
402
+ )
403
+ ) : null}
404
+ {canManage ? (
405
+ <ListSection title="API key" footer={keyFooter}>
406
+ <View className="gap-3 px-4 py-3">
407
+ {sources.length > 0 && (
408
+ <View className="flex-row flex-wrap gap-2">
409
+ <Chip
410
+ label="Value"
411
+ size="small"
412
+ selected={sourceId === null}
413
disabled={saving}
329
- onChange={setModel}
330
- />
331
- ) : (
332
- <ListActionRow
333
- label={
334
- AsyncResult.isFailure(models)
335
- ? "Could not load models · Retry"
336
- : "Loading transcription models…"
337
- }
338
- disabled={!AsyncResult.isFailure(models)}
339
- onPress={reloadModels}
414
+ onPress={() => {
415
+ setDraft("");
416
+ setSourceId(null);
417
+ }}
418
/>
341
- )}
342
- </>
343
- )}
344
- {isEditing && (canManage || routed) && (
345
- <>
346
- {canManage && sources.length > 0 && (
347
- <View className="mx-4 flex-row flex-wrap gap-2">
419
+ {sources.map((candidate) => (
420
<Chip
349
- label="Value"
421
+ key={candidate.id}
422
+ label={candidate.label}
423
size="small"
351
- selected={sourceId === null}
424
+ selected={sourceId === candidate.id}
425
disabled={saving}
426
onPress={() => {
427
setDraft("");
355
- setSourceId(null);
428
+ setSourceId(candidate.id);
429
}}
430
/>
358
- {sources.map((candidate) => (
359
- <Chip
360
- key={candidate.id}
361
- label={candidate.label}
362
- size="small"
363
- selected={sourceId === candidate.id}
364
- disabled={saving}
365
- onPress={() => {
366
- setDraft("");
367
- setSourceId(candidate.id);
368
- }}
369
- />
370
- ))}
371
- </View>
372
- )}
373
- {canManage && (
374
- <TextInput
375
- key={sourceId ?? "literal"}
376
- accessibilityLabel={
377
- sourceId ? `${label} API key reference` : `${label} API key`
378
- }
379
- placeholder={
380
- source?.referencePlaceholder ??
381
- (routed && saved ? "Saved key · enter a new one to replace" : "API key")
382
- }
383
- secureTextEntry={sourceId === null}
384
- autoCapitalize="none"
385
- autoCorrect={false}
386
- autoComplete="off"
387
- importantForAutofill="no"
388
- maxLength={4096}
389
- editable={!saving}
390
- returnKeyType="done"
391
- onSubmitEditing={() => {
392
- if (routed) saveRouted();
393
- else if (credential) void changeKey(provider, credential);
394
- }}
395
- value={draft}
396
- onChangeText={setDraft}
397
- className="mx-4 rounded-lg bg-background px-3 py-2 text-foreground"
398
- />
399
- )}
400
- {routed && !saved && !canManage ? (
401
- <ListActionRow
402
- label="Ask an administrator to add an OpenRouter key"
403
- disabled
404
- onPress={() => {}}
405
- />
406
- ) : (
407
- <ListActionRow
408
- label={
409
- routed
410
- ? isActive
411
- ? "Save"
412
- : "Save and enable"
413
- : editing.enable
414
- ? "Save and enable"
415
- : "Save key"
416
- }
417
- description={
418
- draft && !credential
419
- ? (source?.invalidReferenceMessage ?? "Enter a valid API key.")
420
- : routed
421
- ? saved && !credential
422
- ? "Uses the API key saved on this environment. The model choice applies only to this device."
423
- : `Anyone with dictation access to ${environment.label} can bill this key.`
424
- : editing.enable
425
- ? `${disclosure} Anyone with dictation access to ${environment.label} can bill this key.`
426
- : `Updates the ${company} key on ${environment.label}. Your dictation destination stays the same.`
427
- }
428
- disabled={(routed ? !routedReady : !credential) || saving}
429
- onPress={() => {
430
- if (routed) saveRouted();
431
- else if (credential) void changeKey(provider, credential);
432
- }}
433
- />
434
- )}
435
- {saved && canManage && (
436
- <ListActionRow
437
- tone="danger"
438
- label="Remove key from environment"
439
- disabled={saving}
440
- onPress={() =>
441
- Dialog.confirm({
442
- title: `Remove the ${label} key from ${environment.label}?`,
443
- message: "Everyone using it for dictation will lose access.",
444
- confirmText: "Remove key",
445
- destructive: true,
446
- onConfirm: () => void changeKey(provider, null),
447
- })
448
- }
449
- />
450
- )}
451
- <ListActionRow label="Back to providers" disabled={saving} onPress={reset} />
452
- </>
431
+ ))}
432
+ </View>
433
+ )}
434
+ <TextInput
435
+ key={sourceId ?? "literal"}
436
+ accessibilityLabel={sourceId ? `${label} API key reference` : `${label} API key`}
437
+ placeholder={
438
+ source?.referencePlaceholder ??
439
+ (key ? "Saved key · enter a new one to replace" : "API key")
440
+ }
441
+ secureTextEntry={sourceId === null}
442
+ autoCapitalize="none"
443
+ autoCorrect={false}
444
+ autoComplete="off"
445
+ importantForAutofill="no"
446
+ maxLength={4096}
447
+ editable={!saving}
448
+ returnKeyType="done"
449
+ onSubmitEditing={submit}
450
+ value={draft}
451
+ onChangeText={setDraft}
452
+ className="rounded-lg bg-background px-3 py-2 text-foreground"
453
+ />
454
+ </View>
455
+ </ListSection>
456
+ ) : null}
457
+ {canManage || routed ? (
458
+ <ListSection>
459
+ {routed && !key && !canManage ? (
460
+ <ListActionRow
461
+ label="Ask an administrator to add an OpenRouter key"
462
+ disabled
463
+ onPress={() => {}}
464
+ />
465
+ ) : (
466
+ <ListActionRow
467
+ label={
468
+ routed
469
+ ? isActive
470
+ ? "Save"
471
+ : "Save and enable"
472
+ : editing.enable
473
+ ? "Save and enable"
474
+ : "Save key"
475
+ }
476
+ loading={saving}
477
+ disabled={routed ? !routedReady : !credential}
478
+ onPress={submit}
479
+ />
480
)}
454
- </View>
455
- );
456
- })
481
+ {key && canManage ? (
482
+ <Separated>
483
+ <ListActionRow
484
+ tone="danger"
485
+ label="Remove key from environment"
486
+ disabled={saving}
487
+ onPress={() =>
488
+ Dialog.confirm({
489
+ title: `Remove the ${label} key from ${environment.label}?`,
490
+ message: "Everyone using it for dictation will lose access.",
491
+ confirmText: "Remove key",
492
+ destructive: true,
493
+ onConfirm: () => void changeKey(provider, null),
494
+ })
495
+ }
496
+ />
497
+ </Separated>
498
+ ) : null}
499
+ </ListSection>
500
+ ) : null}
501
+ <ListSection>
502
+ <ListActionRow label="Back to providers" disabled={saving} onPress={reset} />
503
+ </ListSection>
504
+ </>
505
);
506
+ })();
507
return (
508
<Sheet
509
title={editing ? CLOUD_SPEECH_LABELS[editing.provider] : "Cloud providers"}
@@ -464,7 +513,7 @@ function CloudChoices({ environment, active, onClose }: Props & { onClose: () =>
513
<ScrollView
514
contentInsetAdjustmentBehavior="automatic"
515
keyboardShouldPersistTaps="handled"
467
- contentContainerClassName="gap-2 pb-8"
516
+ contentContainerClassName="gap-4 px-5 pt-2 pb-8"
517
>
518
{content}
519
</ScrollView>
apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx
+87
-52
@@ -24,13 +24,14 @@ import * as Dialog from "../../components/ui/Dialog";
24
import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";
25
import {
26
chooseVoiceDestination,
27
+ cloudVoiceConnectionAtom,
28
voiceConnectionAtom,
29
voiceGrantAtom,
29
- voiceSpeechStatusAtom,
30
hasEnvironmentVoiceCapture,
31
} from "../voice-input/voiceDestination";
32
-import { VoiceModelSection } from "./VoiceModelSection";
33
-import { CloudVoiceSection } from "./CloudVoiceSection";
32
+import { LocalModelChoice } from "./VoiceModelSection";
33
+import { CloudVoiceChoice } from "./CloudVoiceSection";
34
+import type { VoiceGrant } from "../voice-input/voiceGrantStorage";
35
import type { EnvironmentId } from "@t3tools/contracts";
36
import { ThreadSwipeable } from "../home/thread-swipe-actions";
37
import { ListActionRow as SettingsActionRow } from "../../components/ui/ListActionRow";
@@ -127,45 +128,81 @@ function saveDestination(id: EnvironmentId | null) {
128
function EnvironmentChoice({
129
environment,
130
selected,
131
+ onCloudOnly,
132
}: {
133
environment: EnvironmentPresentation;
134
selected: boolean;
135
+ /** Called instead of a local grant when the environment only offers cloud transcription. */
136
+ onCloudOnly: () => void;
137
}) {
134
- const usable = useAtomValue(voiceConnectionAtom(environment.environmentId)) !== null;
135
- const status = AsyncResult.getOrElse(
136
- useAtomValue(voiceSpeechStatusAtom(environment.environmentId)),
137
- () => null,
138
- );
138
+ const local = useAtomValue(voiceConnectionAtom(environment.environmentId)) !== null;
139
+ const cloud = useAtomValue(cloudVoiceConnectionAtom(environment.environmentId)) !== null;
140
+ const usable = local || cloud;
141
return (
142
<ListChoiceRow
143
label={environment.label}
144
selected={selected}
145
disabled={!usable}
146
description={
145
- !usable
146
- ? environment.connection.phase !== "connected"
147
- ? "Not connected"
148
- : "Transcription unavailable"
149
- : status?.supported === false
150
- ? status.reason
151
- : status?.state === "missing-model"
152
- ? "No transcription model installed"
153
- : (environment.displayUrl ?? "Send finished recordings to this environment.")
147
+ environment.connection.phase !== "connected"
148
+ ? "Not connected"
149
+ : !usable
150
+ ? "Transcription unavailable"
151
+ : (environment.displayUrl ?? "Send finished recordings to this environment.")
152
}
153
separated
154
onPress={() => {
157
- if (!selected)
158
- Dialog.confirm({
159
- title: `Send microphone audio to ${environment.label}?`,
160
- message: `Finished recordings will be sent to ${environment.displayUrl ?? environment.label} for transcription. You can switch back to This device at any time.`,
161
- confirmText: "Use environment",
162
- onConfirm: () => saveDestination(environment.environmentId),
163
- });
155
+ if (selected) return;
156
+ if (!local) return onCloudOnly();
157
+ Dialog.confirm({
158
+ title: `Send microphone audio to ${environment.label}?`,
159
+ message: `Finished recordings will be sent to ${environment.displayUrl ?? environment.label} for transcription. You can switch back to This device at any time.`,
160
+ confirmText: "Use environment",
161
+ onConfirm: () => saveDestination(environment.environmentId),
162
+ });
163
}}
164
/>
165
);
166
}
167
168
+/** How the selected environment transcribes: its own model or a cloud provider. */
169
+function EnvironmentMethodSection({
170
+ environment,
171
+ grant,
172
+ cloudOpen,
173
+ onCloudOpenChange,
174
+}: {
175
+ environment: EnvironmentPresentation;
176
+ grant: VoiceGrant | null;
177
+ cloudOpen: boolean;
178
+ onCloudOpenChange: (open: boolean) => void;
179
+}) {
180
+ const id = environment.environmentId;
181
+ const destination = grant?.destination.environmentId === id ? grant.destination : null;
182
+ const cloudCapable =
183
+ environment.serverConfig?.environment.capabilities.cloudVoiceTranscription === true ||
184
+ destination?.kind === "cloud";
185
+ return (
186
+ <SettingsSection title={`Method on ${environment.label}`}>
187
+ <LocalModelChoice
188
+ environmentId={id}
189
+ label={environment.label}
190
+ selected={destination?.kind === "environment"}
191
+ // The user already agreed to send audio to this environment.
192
+ onSelect={() => saveDestination(id)}
193
+ />
194
+ {cloudCapable ? (
195
+ <CloudVoiceChoice
196
+ environment={environment}
197
+ active={destination?.kind === "cloud" ? destination : null}
198
+ open={cloudOpen}
199
+ onOpenChange={onCloudOpenChange}
200
+ />
201
+ ) : null}
202
+ </SettingsSection>
203
+ );
204
+}
205
+
206
export function SettingsVoiceRouteScreen() {
207
const transcriber = useAtomValue(localVoiceTranscriberAtom);
208
const grant = useAtomValue(voiceGrantAtom);
@@ -175,6 +212,15 @@ export function SettingsVoiceRouteScreen() {
212
(environment) => environment.environmentId === grant.destination.environmentId,
213
)
214
: undefined;
215
+ // An environment whose cloud sheet is open; it may not hold the grant yet.
216
+ const [cloudSheet, setCloudSheet] = useState<EnvironmentId | null>(null);
217
+ // A sheet whose environment lost cloud transcription is gone, so its pending choice is too.
218
+ const sheetEnvironment = environments.find(
219
+ (environment) =>
220
+ environment.environmentId === cloudSheet &&
221
+ environment.serverConfig?.environment.capabilities.cloudVoiceTranscription === true,
222
+ );
223
+ const methodEnvironment = sheetEnvironment ?? grantEnvironment;
224
const insets = useSafeAreaInsets();
225
const preferencesResult = useAtomValue(mobilePreferencesAtom);
226
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
@@ -234,8 +280,11 @@ export function SettingsVoiceRouteScreen() {
280
<ListChoiceRow
281
label="This device"
282
description="Audio stays on this device and is transcribed here."
237
- selected={!grant}
238
- onPress={() => saveDestination(null)}
283
+ selected={!grant && !sheetEnvironment}
284
+ onPress={() => {
285
+ setCloudSheet(null);
286
+ saveDestination(null);
287
+ }}
288
/>
289
{hasEnvironmentVoiceCapture &&
290
environments.map((environment) => (
@@ -243,9 +292,11 @@ export function SettingsVoiceRouteScreen() {
292
key={environment.environmentId}
293
environment={environment}
294
selected={
246
- grant?.destination.kind === "environment" &&
247
- grant.destination.environmentId === environment.environmentId
295
+ sheetEnvironment
296
+ ? sheetEnvironment.environmentId === environment.environmentId
297
+ : grant?.destination.environmentId === environment.environmentId
298
}
299
+ onCloudOnly={() => setCloudSheet(environment.environmentId)}
300
/>
301
))}
302
{isReady && grant && !grantEnvironment ? (
@@ -259,30 +310,14 @@ export function SettingsVoiceRouteScreen() {
310
/>
311
) : null}
312
</SettingsSection>
262
- {hasEnvironmentVoiceCapture &&
263
- environments
264
- .filter(
265
- (env) =>
266
- env.serverConfig?.environment.capabilities.cloudVoiceTranscription ||
267
- (grant?.destination.kind === "cloud" &&
268
- grant.destination.environmentId === env.environmentId),
269
- )
270
- .map((environment) => (
271
- <CloudVoiceSection
272
- key={environment.environmentId}
273
- environment={environment}
274
- active={
275
- grant?.destination.kind === "cloud" &&
276
- grant.destination.environmentId === environment.environmentId
277
- ? grant.destination
278
- : null
279
- }
280
- />
281
- ))}
282
- {grantEnvironment && grant?.destination.kind === "environment" ? (
283
- <VoiceModelSection
284
- environmentId={grantEnvironment.environmentId}
285
- label={grantEnvironment.label}
313
+ {hasEnvironmentVoiceCapture && methodEnvironment ? (
314
+ <EnvironmentMethodSection
315
+ environment={methodEnvironment}
316
+ grant={grant}
317
+ cloudOpen={cloudSheet === methodEnvironment.environmentId}
318
+ onCloudOpenChange={(open) =>
319
+ setCloudSheet(open ? methodEnvironment.environmentId : null)
320
+ }
321
/>
322
) : null}
323
{!grant && transcriber === null ? (
apps/mobile/src/features/settings/VoiceModelSection.tsx
+39
-32
@@ -29,7 +29,6 @@ import {
29
voiceSpeechModelsAtom,
30
voiceSpeechStatusAtom,
31
} from "../voice-input/voiceDestination";
32
-import { SettingsSection } from "./components/SettingsSection";
32
33
const isDownloading = (model: EnvironmentSpeechModel) =>
34
model.state === "downloading" || model.state === "verifying";
@@ -272,51 +271,59 @@ export function VoiceModelRow(props: {
271
);
272
}
273
275
-export function VoiceModelSection(props: {
274
+/** The environment's local-model method: chosen by its mark, opens the model list. */
275
+export function LocalModelChoice(props: {
276
readonly environmentId: EnvironmentId;
277
readonly label: string;
278
+ readonly selected: boolean;
279
+ readonly onSelect: () => void;
280
}) {
281
const navigation = useNavigation();
282
const voice = useVoiceModels(props.environmentId, props.label);
283
const { status } = voice;
282
- if (!voice.connection || !status) return null;
283
- const title = `Transcription model on ${props.label}`;
284
- if (!status.supported) {
284
+ const open = () =>
285
+ navigation.navigate("SettingsVoiceModels", { environmentId: props.environmentId });
286
+ if (!voice.connection || !status || !status.supported)
287
return (
286
- <SettingsSection title={title} footer={status.reason}>
287
- {null}
288
- </SettingsSection>
288
+ <ListChoiceRow
289
+ label="Local model"
290
+ description={
291
+ !voice.connection
292
+ ? "Not available on this environment"
293
+ : status?.supported === false
294
+ ? status.reason
295
+ : "Checking…"
296
+ }
297
+ selected={props.selected}
298
+ disabled
299
+ onPress={() => {}}
300
+ />
301
);
290
- }
302
303
const active = status.state === "missing-model" ? null : status;
304
const pending = voice.models.find(isDownloading);
305
const progress =
306
pending?.downloaded === undefined ? undefined : pending.downloaded / pending.size;
307
return (
297
- <SettingsSection
298
- title={title}
299
- footer={
300
- voice.canManage
301
- ? undefined
302
- : `This connection can’t change settings on ${props.label}. Add a transcription model using T3 Code on that machine.`
308
+ <ListRow
309
+ label={active?.model ?? "Local model"}
310
+ description={
311
+ pending
312
+ ? pending.state === "verifying"
313
+ ? `Verifying ${pending.name}…`
314
+ : `Downloading ${pending.name} · ${Math.round((progress ?? 0) * 100)}%`
315
+ : active
316
+ ? `Local model · ${formatBytes(active.size)}`
317
+ : voice.canManage
318
+ ? "No model installed · Choose one to download"
319
+ : `No model installed · Add one using T3 Code on ${props.label}`
320
}
304
- >
305
- <ListRow
306
- label={active?.model ?? "No model selected"}
307
- description={
308
- pending
309
- ? pending.state === "verifying"
310
- ? `Verifying ${pending.name}…`
311
- : `Downloading ${pending.name} · ${Math.round((progress ?? 0) * 100)}%`
312
- : active
313
- ? formatBytes(active.size)
314
- : "Choose a transcription model to dictate on this environment."
315
- }
316
- onPress={() =>
317
- navigation.navigate("SettingsVoiceModels", { environmentId: props.environmentId })
318
- }
319
- />
320
- </SettingsSection>
321
+ selected={props.selected}
322
+ onPress={() => {
323
+ if (!props.selected) props.onSelect();
324
+ // Switching to an installed model needs no further step.
325
+ if (props.selected || !active) open();
326
+ }}
327
+ />
328
);
329
}