Skip to content

Commit 9d04ec3

Browse files
committed
fix(mobile): show reasoning and fast mode in the composer
1 parent 8e018ff commit 9d04ec3

6 files changed

Lines changed: 335 additions & 35 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { ModelSelection } from "@t3tools/contracts";
2+
3+
import type { ModelOption } from "../lib/modelOptions";
4+
import {
5+
composerModelOptionSummary,
6+
resolveProviderOptionDescriptors,
7+
} from "../lib/providerOptions";
8+
import { AppText as Text } from "./AppText";
9+
import { SymbolView } from "./AppSymbol";
10+
import { ComposerInlineControl } from "./ComposerToolbar";
11+
import { ProviderIcon } from "./ProviderIcon";
12+
import { useAndroidControlSizing } from "./useAndroidControlSizing";
13+
14+
/** Keeps option indicators fixed while the model name yields space in a narrow toolbar. */
15+
export function ComposerModelControl(props: {
16+
readonly modelOption: ModelOption | null | undefined;
17+
readonly selection: ModelSelection | null;
18+
readonly reportedSelection?: ModelSelection | null | undefined;
19+
readonly disabled?: boolean;
20+
readonly onPress: () => void;
21+
}) {
22+
const { scale } = useAndroidControlSizing();
23+
const label = props.modelOption?.label ?? props.selection?.model ?? "Choose model";
24+
const { reasoningLabel, speedLabel } = composerModelOptionSummary({
25+
provider: props.modelOption?.providerDriver,
26+
descriptors: resolveProviderOptionDescriptors({
27+
capabilities: props.modelOption?.capabilities,
28+
selections: props.selection?.options,
29+
}),
30+
selection: props.selection,
31+
reportedSelection: props.reportedSelection,
32+
});
33+
return (
34+
<ComposerInlineControl
35+
accessibilityLabel={[
36+
"Model and reasoning settings",
37+
label,
38+
reasoningLabel ? `Reasoning: ${reasoningLabel}` : null,
39+
speedLabel ? `${speedLabel} mode on` : null,
40+
]
41+
.filter(Boolean)
42+
.join(", ")}
43+
disabled={props.disabled}
44+
emphasized
45+
renderIcon={(size) => (
46+
<ProviderIcon
47+
iconUrl={props.modelOption?.providerIconUrl}
48+
provider={props.modelOption?.providerDriver}
49+
size={size}
50+
/>
51+
)}
52+
label={label}
53+
suffix={
54+
reasoningLabel || speedLabel ? (
55+
<>
56+
{reasoningLabel ? (
57+
<Text className="text-2xs text-foreground-muted" numberOfLines={1}>
58+
{reasoningLabel}
59+
</Text>
60+
) : null}
61+
{speedLabel ? (
62+
<SymbolView
63+
name={{ ios: "bolt", android: "bolt" }}
64+
size={Math.round(12 * scale)}
65+
tintColorClassName="accent-icon"
66+
type="monochrome"
67+
/>
68+
) : null}
69+
</>
70+
) : undefined
71+
}
72+
maxWidth="100%"
73+
onPress={props.onPress}
74+
/>
75+
);
76+
}

‎apps/mobile/src/components/ComposerToolbar.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function ComposerInlineControl(props: {
3535
readonly icon?: ComponentProps<typeof SymbolView>["name"];
3636
readonly renderIcon?: (size: number) => ReactNode;
3737
readonly label: string;
38+
readonly suffix?: ReactNode;
3839
readonly maxWidth?: ViewStyle["maxWidth"];
3940
readonly onPress?: () => void;
4041
readonly selected?: boolean;
@@ -82,6 +83,9 @@ export function ComposerInlineControl(props: {
8283
>
8384
{props.label}
8485
</Text>
86+
{props.suffix ? (
87+
<View className="shrink-0 flex-row items-center gap-1">{props.suffix}</View>
88+
) : null}
8589
{props.showChevron === false ? null : (
8690
<SymbolView
8791
name={props.chevronDirection === "right" ? "chevron.right" : "chevron.down"}

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
} from "../../state/composer-attachment-uploads";
6464
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
6565
import { VideoPreviewModal, type VideoPreviewSource } from "../../components/VideoPreviewModal";
66-
import { ProviderIcon } from "../../components/ProviderIcon";
66+
import { ComposerModelControl } from "../../components/ComposerModelControl";
6767
import { SymbolView } from "../../components/AppSymbol";
6868
import { AppText as Text } from "../../components/AppText";
6969
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
@@ -1783,21 +1783,12 @@ export function NewTaskDraftScreen(props: {
17831783
onPickMedia={handlePickMedia}
17841784
onPickFiles={handlePickFiles}
17851785
/>
1786-
<View className="min-w-0 flex-1 flex-row items-center justify-end gap-2">
1787-
<View className="min-w-0 shrink">
1788-
<ComposerInlineControl
1789-
accessibilityLabel="Model and reasoning settings"
1786+
<View className="min-w-0 flex-1 flex-row flex-wrap items-center justify-end gap-2">
1787+
<View className="min-w-0 shrink" style={{ flexBasis: 190 }}>
1788+
<ComposerModelControl
17901789
disabled={isComposerInteractionLocked}
1791-
emphasized
1792-
renderIcon={(size) => (
1793-
<ProviderIcon
1794-
iconUrl={flow.selectedModelOption?.providerIconUrl}
1795-
provider={flow.selectedModelOption?.providerDriver}
1796-
size={size}
1797-
/>
1798-
)}
1799-
label={flow.selectedModelOption?.label ?? "Choose model"}
1800-
maxWidth="100%"
1790+
modelOption={flow.selectedModelOption}
1791+
selection={flow.selectedModel}
18011792
onPress={settingsSheetPresentation.open}
18021793
/>
18031794
</View>

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ import { VideoPreviewModal, type VideoPreviewSource } from "../../components/Vid
7777
import { GlassSurface } from "../../components/GlassSurface";
7878
import { ComposerEditor, type ComposerEditorHandle } from "../../components/ComposerEditor";
7979
import { fileRoutePathSegments } from "../files/filePath";
80-
import {
81-
ComposerActionButton,
82-
ComposerInlineControl,
83-
ComposerToolbarRow,
84-
} from "../../components/ComposerToolbar";
85-
import { ProviderIcon } from "../../components/ProviderIcon";
80+
import { ComposerActionButton, ComposerToolbarRow } from "../../components/ComposerToolbar";
81+
import { ComposerModelControl } from "../../components/ComposerModelControl";
8682
import {
8783
composerStripAttachments,
8884
type DraftComposerAttachment,
@@ -1151,18 +1147,10 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
11511147
onPickFiles={props.onPickDraftFiles}
11521148
/>
11531149
<View className="min-w-0 shrink">
1154-
<ComposerInlineControl
1155-
accessibilityLabel="Model and reasoning settings"
1156-
emphasized
1157-
renderIcon={(size) => (
1158-
<ProviderIcon
1159-
iconUrl={currentModelOption?.providerIconUrl}
1160-
provider={currentModelOption?.providerDriver}
1161-
size={size}
1162-
/>
1163-
)}
1164-
label={currentModelOption?.label ?? currentModelSelection.model}
1165-
maxWidth="100%"
1150+
<ComposerModelControl
1151+
modelOption={currentModelOption}
1152+
selection={currentModelSelection}
1153+
reportedSelection={props.reportedModelSelection}
11661154
onPress={openSettings}
11671155
/>
11681156
</View>

‎apps/mobile/src/lib/providerOptions.test.ts‎

Lines changed: 192 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import type { ModelCapabilities } from "@t3tools/contracts";
3+
import {
4+
ProviderInstanceId,
5+
type ModelCapabilities,
6+
type ModelSelection,
7+
} from "@t3tools/contracts";
48

5-
import { applyProviderOptionSelection, resolveProviderOptionDescriptors } from "./providerOptions";
9+
import {
10+
applyProviderOptionSelection,
11+
composerModelOptionSummary,
12+
resolveProviderOptionDescriptors,
13+
} from "./providerOptions";
614

715
const CODEX_CAPABILITIES: ModelCapabilities = {
816
optionDescriptors: [
@@ -62,3 +70,185 @@ describe("mobile provider options", () => {
6270
]);
6371
});
6472
});
73+
74+
describe("composer model option summary", () => {
75+
const selection: ModelSelection = {
76+
instanceId: ProviderInstanceId.make("test-provider"),
77+
model: "custom-model-with-a-long-name",
78+
};
79+
function summary(
80+
capabilities: ModelCapabilities | null = CODEX_CAPABILITIES,
81+
selected = selection,
82+
reported?: ModelSelection,
83+
provider = "codex",
84+
) {
85+
return composerModelOptionSummary({
86+
provider,
87+
descriptors: resolveProviderOptionDescriptors({
88+
capabilities,
89+
selections: selected.options,
90+
}),
91+
selection: selected,
92+
reportedSelection: reported,
93+
});
94+
}
95+
96+
it("shows the effective default reasoning and hides standard speed", () => {
97+
expect(summary()).toEqual({ reasoningLabel: "Medium", speedLabel: undefined });
98+
});
99+
100+
it("shows a selected reasoning label and Codex fast tier", () => {
101+
expect(
102+
summary(CODEX_CAPABILITIES, {
103+
...selection,
104+
options: [
105+
{ id: "reasoningEffort", value: "high" },
106+
{ id: "serviceTier", value: "priority" },
107+
],
108+
}),
109+
).toEqual({ reasoningLabel: "High", speedLabel: "Fast" });
110+
});
111+
112+
it.each(["reasoningEffort", "reasoning", "effort", "variant", "thinking"])(
113+
"uses advertised reasoning labels for %s",
114+
(id) => {
115+
const capabilities: ModelCapabilities = {
116+
optionDescriptors: [
117+
{
118+
id,
119+
label: "Reasoning",
120+
type: "select",
121+
options: [{ id: "xhigh", label: "Extra High", isDefault: true }],
122+
},
123+
],
124+
};
125+
const selected = { ...selection, options: [{ id, value: "xhigh" }] };
126+
expect(summary(capabilities, selected)).toEqual({
127+
reasoningLabel: "Extra High",
128+
speedLabel: undefined,
129+
});
130+
},
131+
);
132+
133+
it.each(["claudeAgent", "cursor", "opencode"])(
134+
"shows and clears boolean fast mode for %s",
135+
(provider) => {
136+
const capabilities: ModelCapabilities = {
137+
optionDescriptors: [{ id: "fastMode", label: "Fast Mode", type: "boolean" }],
138+
};
139+
for (const value of [true, false]) {
140+
expect(
141+
summary(
142+
capabilities,
143+
{ ...selection, options: [{ id: "fastMode", value }] },
144+
undefined,
145+
provider,
146+
),
147+
).toEqual({ reasoningLabel: undefined, speedLabel: value ? "Fast" : undefined });
148+
}
149+
},
150+
);
151+
152+
it("uses matching provider-reported options when no explicit override exists", () => {
153+
const reported: ModelSelection = {
154+
...selection,
155+
options: [
156+
{ id: "reasoningEffort", value: "high" },
157+
{ id: "serviceTier", value: "priority" },
158+
],
159+
};
160+
expect(summary(CODEX_CAPABILITIES, selection, reported)).toEqual({
161+
reasoningLabel: "High",
162+
speedLabel: "Fast",
163+
});
164+
expect(
165+
summary(
166+
CODEX_CAPABILITIES,
167+
{
168+
...selection,
169+
options: [
170+
{ id: "reasoningEffort", value: "medium" },
171+
{ id: "serviceTier", value: "default" },
172+
],
173+
},
174+
reported,
175+
),
176+
).toEqual({ reasoningLabel: "Medium", speedLabel: undefined });
177+
for (const other of [
178+
{ ...reported, model: "other-model" },
179+
{ ...reported, instanceId: ProviderInstanceId.make("other-provider") },
180+
]) {
181+
expect(summary(CODEX_CAPABILITIES, selection, other)).toEqual({
182+
reasoningLabel: "Medium",
183+
speedLabel: undefined,
184+
});
185+
}
186+
});
187+
188+
it("does not turn unsupported or unrelated options into indicators", () => {
189+
const selected: ModelSelection = {
190+
...selection,
191+
options: [
192+
{ id: "reasoningEffort", value: "high" },
193+
{ id: "fastMode", value: true },
194+
],
195+
};
196+
expect(summary(null, selected)).toEqual({ reasoningLabel: undefined, speedLabel: undefined });
197+
expect(summary({ optionDescriptors: [] }, selected)).toEqual({
198+
reasoningLabel: undefined,
199+
speedLabel: undefined,
200+
});
201+
expect(
202+
summary({
203+
optionDescriptors: [
204+
{
205+
id: "contextWindow",
206+
label: "Context Window",
207+
type: "select",
208+
options: [{ id: "expanded", label: "Expanded", isDefault: true }],
209+
},
210+
],
211+
}),
212+
).toEqual({ reasoningLabel: undefined, speedLabel: undefined });
213+
});
214+
215+
it("recognizes only advertised Codex fast and ultrafast tiers", () => {
216+
const capabilities: ModelCapabilities = {
217+
optionDescriptors: [
218+
{
219+
id: "serviceTier",
220+
label: "Service Tier",
221+
type: "select",
222+
options: [
223+
{ id: "default", label: "Standard", isDefault: true },
224+
{ id: "priority", label: "Fast" },
225+
{ id: "ultrafast", label: "Ultrafast" },
226+
{ id: "flex", label: "Flex" },
227+
],
228+
},
229+
],
230+
};
231+
for (const [value, expected] of [
232+
["default", undefined],
233+
["priority", "Fast"],
234+
["ultrafast", "Ultrafast"],
235+
["flex", undefined],
236+
["unknown", undefined],
237+
] as const) {
238+
const selected = { ...selection, options: [{ id: "serviceTier", value }] };
239+
expect(summary(capabilities, selected).speedLabel).toBe(expected);
240+
expect(summary(capabilities, selected, undefined, "cursor").speedLabel).toBeUndefined();
241+
}
242+
});
243+
244+
it("shows boolean thinking independently of speed", () => {
245+
const capabilities: ModelCapabilities = {
246+
optionDescriptors: [{ id: "thinking", label: "Thinking", type: "boolean" }],
247+
};
248+
for (const value of [true, false]) {
249+
expect(summary(capabilities, { ...selection, options: [{ id: "thinking", value }] })).toEqual(
250+
{ reasoningLabel: value ? "Thinking" : "No thinking", speedLabel: undefined },
251+
);
252+
}
253+
});
254+
});

0 commit comments

Comments
 (0)