Skip to content

Commit 38beb94

Browse files
feat(mobile): pick a voice environment once, then its method
The Voice settings listed every environment twice: once under "Transcribe on" and again as a "Cloud via <env>" section for each cloud-capable environment, plus a model section named after the environment. Now "Transcribe on" lists This device and each environment once. The selected environment gets one "Method on <env>" section choosing its local model or a cloud provider, and the model picker shows only while the local model is in use. An environment that only offers cloud transcription opens the provider sheet directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d290c1f commit 38beb94

3 files changed

Lines changed: 125 additions & 58 deletions

File tree

‎apps/mobile/src/features/settings/CloudVoiceSection.tsx‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,45 @@ import {
4040
cloudVoiceModelsAtom,
4141
runSpeech,
4242
} from "../voice-input/voiceDestination";
43-
import { SettingsSection } from "./components/SettingsSection";
4443

4544
type CloudDestination = Extract<VoiceTranscriptionDestination, { kind: "cloud" }>;
4645
type Props = { environment: EnvironmentPresentation; active: CloudDestination | null };
4746
const isApiKey = Schema.is(CloudSpeechApiKey);
4847
const isModelId = Schema.is(CloudSpeechModelId);
4948
const MODEL_ROWS = 6;
5049

51-
export function CloudVoiceSection({ environment, active }: Props) {
52-
const [open, setOpen] = useState(false);
50+
/** The cloud method row for one environment; opens the provider sheet. */
51+
export function CloudVoiceChoice({
52+
environment,
53+
active,
54+
open,
55+
onOpenChange,
56+
}: Props & { open: boolean; onOpenChange: (open: boolean) => void }) {
57+
const usable = useAtomValue(cloudVoiceConnectionAtom(environment.environmentId)) !== null;
5358
return (
54-
<SettingsSection title={`Cloud via ${environment.label}`}>
55-
<ListActionRow
56-
label="Cloud providers"
59+
<>
60+
<ListChoiceRow
61+
label="Cloud provider"
5762
description={
5863
active
59-
? `Using ${CLOUD_SPEECH_LABELS[active.provider]}`
60-
: "Optional · use your own API key"
64+
? `${CLOUD_SPEECH_LABELS[active.provider]}${active.provider === "openrouter" ? ` · ${active.model}` : ""}`
65+
: usable
66+
? "Use your own API key"
67+
: "Not connected"
6168
}
62-
onPress={() => setOpen(true)}
69+
selected={active !== null}
70+
disabled={!usable}
71+
separated
72+
onPress={() => onOpenChange(true)}
6373
/>
6474
{open && (
65-
<CloudChoices environment={environment} active={active} onClose={() => setOpen(false)} />
75+
<CloudChoices
76+
environment={environment}
77+
active={active}
78+
onClose={() => onOpenChange(false)}
79+
/>
6680
)}
67-
</SettingsSection>
81+
</>
6882
);
6983
}
7084

‎apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx‎

Lines changed: 99 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import * as Dialog from "../../components/ui/Dialog";
2424
import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";
2525
import {
2626
chooseVoiceDestination,
27+
cloudVoiceConnectionAtom,
2728
voiceConnectionAtom,
2829
voiceGrantAtom,
2930
voiceSpeechStatusAtom,
3031
hasEnvironmentVoiceCapture,
3132
} from "../voice-input/voiceDestination";
3233
import { VoiceModelSection } from "./VoiceModelSection";
33-
import { CloudVoiceSection } from "./CloudVoiceSection";
34+
import { CloudVoiceChoice } from "./CloudVoiceSection";
35+
import type { VoiceGrant } from "../voice-input/voiceGrantStorage";
3436
import type { EnvironmentId } from "@t3tools/contracts";
3537
import { ThreadSwipeable } from "../home/thread-swipe-actions";
3638
import { ListActionRow as SettingsActionRow } from "../../components/ui/ListActionRow";
@@ -127,45 +129,96 @@ function saveDestination(id: EnvironmentId | null) {
127129
function EnvironmentChoice({
128130
environment,
129131
selected,
132+
onCloudOnly,
130133
}: {
131134
environment: EnvironmentPresentation;
132135
selected: boolean;
136+
/** Called instead of a local grant when the environment only offers cloud transcription. */
137+
onCloudOnly: () => void;
133138
}) {
134-
const usable = useAtomValue(voiceConnectionAtom(environment.environmentId)) !== null;
135-
const status = AsyncResult.getOrElse(
136-
useAtomValue(voiceSpeechStatusAtom(environment.environmentId)),
137-
() => null,
138-
);
139+
const local = useAtomValue(voiceConnectionAtom(environment.environmentId)) !== null;
140+
const cloud = useAtomValue(cloudVoiceConnectionAtom(environment.environmentId)) !== null;
141+
const usable = local || cloud;
139142
return (
140143
<ListChoiceRow
141144
label={environment.label}
142145
selected={selected}
143146
disabled={!usable}
144147
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.")
148+
environment.connection.phase !== "connected"
149+
? "Not connected"
150+
: !usable
151+
? "Transcription unavailable"
152+
: (environment.displayUrl ?? "Send finished recordings to this environment.")
154153
}
155154
separated
156155
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-
});
156+
if (selected) return;
157+
if (!local) return onCloudOnly();
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+
});
164164
}}
165165
/>
166166
);
167167
}
168168

169+
/** How the selected environment transcribes: its own model or a cloud provider. */
170+
function EnvironmentMethodSection({
171+
environment,
172+
grant,
173+
cloudOpen,
174+
onCloudOpenChange,
175+
}: {
176+
environment: EnvironmentPresentation;
177+
grant: VoiceGrant | null;
178+
cloudOpen: boolean;
179+
onCloudOpenChange: (open: boolean) => void;
180+
}) {
181+
const id = environment.environmentId;
182+
const local = useAtomValue(voiceConnectionAtom(id)) !== null;
183+
const status = AsyncResult.getOrElse(useAtomValue(voiceSpeechStatusAtom(id)), () => null);
184+
const destination = grant?.destination.environmentId === id ? grant.destination : null;
185+
const cloudCapable =
186+
environment.serverConfig?.environment.capabilities.cloudVoiceTranscription === true ||
187+
destination?.kind === "cloud";
188+
return (
189+
<SettingsSection title={`Method on ${environment.label}`}>
190+
<ListChoiceRow
191+
label="Local model"
192+
description={
193+
!local
194+
? "Not available on this environment"
195+
: status?.supported === false
196+
? status.reason
197+
: status?.state === "missing-model"
198+
? "No model installed"
199+
: status
200+
? status.model
201+
: "Runs on the environment"
202+
}
203+
selected={destination?.kind === "environment"}
204+
disabled={!local}
205+
onPress={() => {
206+
// The user already agreed to send audio to this environment.
207+
if (destination?.kind !== "environment") saveDestination(id);
208+
}}
209+
/>
210+
{cloudCapable ? (
211+
<CloudVoiceChoice
212+
environment={environment}
213+
active={destination?.kind === "cloud" ? destination : null}
214+
open={cloudOpen}
215+
onOpenChange={onCloudOpenChange}
216+
/>
217+
) : null}
218+
</SettingsSection>
219+
);
220+
}
221+
169222
export function SettingsVoiceRouteScreen() {
170223
const transcriber = useAtomValue(localVoiceTranscriberAtom);
171224
const grant = useAtomValue(voiceGrantAtom);
@@ -175,6 +228,12 @@ export function SettingsVoiceRouteScreen() {
175228
(environment) => environment.environmentId === grant.destination.environmentId,
176229
)
177230
: undefined;
231+
// An environment whose cloud sheet is open; it may not hold the grant yet.
232+
const [cloudSheet, setCloudSheet] = useState<EnvironmentId | null>(null);
233+
const sheetEnvironment = environments.find(
234+
(environment) => environment.environmentId === cloudSheet,
235+
);
236+
const methodEnvironment = sheetEnvironment ?? grantEnvironment;
178237
const insets = useSafeAreaInsets();
179238
const preferencesResult = useAtomValue(mobilePreferencesAtom);
180239
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
@@ -234,7 +293,7 @@ export function SettingsVoiceRouteScreen() {
234293
<ListChoiceRow
235294
label="This device"
236295
description="Audio stays on this device and is transcribed here."
237-
selected={!grant}
296+
selected={!grant && !sheetEnvironment}
238297
onPress={() => saveDestination(null)}
239298
/>
240299
{hasEnvironmentVoiceCapture &&
@@ -243,9 +302,11 @@ export function SettingsVoiceRouteScreen() {
243302
key={environment.environmentId}
244303
environment={environment}
245304
selected={
246-
grant?.destination.kind === "environment" &&
247-
grant.destination.environmentId === environment.environmentId
305+
sheetEnvironment
306+
? sheetEnvironment.environmentId === environment.environmentId
307+
: grant?.destination.environmentId === environment.environmentId
248308
}
309+
onCloudOnly={() => setCloudSheet(environment.environmentId)}
249310
/>
250311
))}
251312
{isReady && grant && !grantEnvironment ? (
@@ -259,27 +320,19 @@ export function SettingsVoiceRouteScreen() {
259320
/>
260321
) : null}
261322
</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" ? (
323+
{hasEnvironmentVoiceCapture && methodEnvironment ? (
324+
<EnvironmentMethodSection
325+
environment={methodEnvironment}
326+
grant={grant}
327+
cloudOpen={cloudSheet === methodEnvironment.environmentId}
328+
onCloudOpenChange={(open) =>
329+
setCloudSheet(open ? methodEnvironment.environmentId : null)
330+
}
331+
/>
332+
) : null}
333+
{grantEnvironment &&
334+
methodEnvironment === grantEnvironment &&
335+
grant?.destination.kind === "environment" ? (
283336
<VoiceModelSection
284337
environmentId={grantEnvironment.environmentId}
285338
label={grantEnvironment.label}

‎apps/mobile/src/features/settings/VoiceModelSection.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export function VoiceModelSection(props: {
280280
const voice = useVoiceModels(props.environmentId, props.label);
281281
const { status } = voice;
282282
if (!voice.connection || !status) return null;
283-
const title = `Transcription model on ${props.label}`;
283+
const title = "Model";
284284
if (!status.supported) {
285285
return (
286286
<SettingsSection title={title} footer={status.reason}>

0 commit comments

Comments
 (0)