Skip to content

Commit 1a02ac6

Browse files
committed
fix(web): preserve slider navigation and prompt-controlled effort
1 parent 5f1ab6e commit 1a02ac6

3 files changed

Lines changed: 62 additions & 47 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function ReasoningSlider({
219219
disabled: boolean;
220220
onValueChange: (value: string) => void;
221221
}) {
222-
const options = selectableProviderOptionChoices(descriptor);
222+
const options = disabled ? descriptor.options : selectableProviderOptionChoices(descriptor);
223223
const index = options.findIndex((option) => option.id === value);
224224
const option = options[index];
225225

@@ -270,9 +270,8 @@ function ReasoningSlider({
270270
if (next) onValueChange(next.id);
271271
}}
272272
onKeyDown={(event) => {
273-
if (
274-
["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)
275-
) {
273+
if (["ArrowUp", "ArrowDown"].includes(event.key)) event.preventDefault();
274+
if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) {
276275
event.stopPropagation();
277276
}
278277
}}
@@ -288,7 +287,7 @@ function ReasoningSlider({
288287
);
289288
}
290289

291-
export function EffortLevels(props: { traits: TraitsSelectionInput }) {
290+
function EffortLevels(props: { traits: TraitsSelectionInput }) {
292291
const traits = useTraitsSelection(props.traits);
293292
const { effort, others } = columnControls(
294293
props.traits.provider,
@@ -335,10 +334,13 @@ export function EffortLevels(props: { traits: TraitsSelectionInput }) {
335334
const locked =
336335
descriptor.id === traits.primarySelectDescriptor?.id && traits.ultrathinkInBodyText;
337336
const value = traits.selectValue(control.descriptor);
337+
const choices = locked
338+
? control.descriptor.options
339+
: selectableProviderOptionChoices(control.descriptor);
338340
if (
339341
REASONING_SELECT_DESCRIPTOR_IDS.has(descriptor.id) &&
340-
descriptor.options.length > 1 &&
341-
descriptor.options.some((option) => option.id === value)
342+
choices.length > 1 &&
343+
choices.some((option) => option.id === value)
342344
) {
343345
return (
344346
<div key={descriptor.id}>

‎apps/web/src/components/chat/ComposerPermissionsSection.browser.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ it("marks the current mode as checked and closes on Escape", async () => {
8888
});
8989

9090
it("explains hovered permissions while keeping the selected mode in the header", async () => {
91-
await using screen = await render(<EffortMenu />, { router: false }); // no routes involved
92-
await userEvent.click(screen.getByRole("button", { name: "Effort" }));
91+
await using screen = await render(<OverflowMenu />, { router: false }); // no routes involved
92+
await userEvent.click(screen.getByRole("button", { name: "More" }));
9393
await userEvent.hover(page.getByRole("menuitemradio", { name: "Supervised" }));
9494
await expect
9595
.element(

‎apps/web/src/components/chat/TraitsPicker.browser.test.tsx‎

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { expect, it } from "vite-plus/test";
99
import { page, userEvent } from "vite-plus/test/browser";
1010

1111
import { render } from "../../../test/render";
12-
import { EffortLevels } from "./ComposerModelEffort";
12+
import { ComposerEffortColumn } from "./ComposerModelEffort";
1313
import { readPromptUltrathink } from "./TraitsPicker";
1414

1515
const levels = [
@@ -51,6 +51,20 @@ function EffortMenu({
5151
options,
5252
promptInjectedValues: ["ultrathink"],
5353
},
54+
...(!thinking
55+
? [
56+
{
57+
id: "contextWindow",
58+
label: "Context window",
59+
type: "select" as const,
60+
currentValue: "normal",
61+
options: [
62+
{ id: "normal", label: "Normal" },
63+
{ id: "long", label: "Long" },
64+
],
65+
},
66+
]
67+
: []),
5468
{
5569
id: "serviceTier",
5670
label: "Service Tier",
@@ -73,7 +87,7 @@ function EffortMenu({
7387
];
7488
return (
7589
<>
76-
<EffortLevels
90+
<ComposerEffortColumn
7791
traits={{
7892
provider: ProviderDriverKind.make("codex"),
7993
models,
@@ -89,41 +103,40 @@ function EffortMenu({
89103
);
90104
}
91105

92-
it.each([2, 6])(
93-
"steps through %i model levels and keeps the other traits and menu navigation",
94-
async (count) => {
95-
const options = levels.slice(0, count);
96-
// The menu has no routing behavior.
97-
await using screen = await render(<EffortMenu options={options} />, { router: false });
98-
await userEvent.tab();
99-
const slider = page.getByRole("slider", { name: "Reasoning" });
100-
await expect.element(slider).toHaveFocus();
101-
await expect.element(slider).toHaveAttribute("max", String(count - 1));
102-
await expect.element(slider).toHaveAttribute("aria-valuetext", "Medium (default)");
106+
it.each([2, 6])("steps through %i model levels and keeps the other traits", async (count) => {
107+
const options = levels.slice(0, count);
108+
// The column has no routing behavior.
109+
await using screen = await render(<EffortMenu options={options} />, { router: false });
110+
await userEvent.tab();
111+
const slider = page.getByRole("slider", { name: "Reasoning" });
112+
await expect.element(slider).toHaveFocus();
113+
await expect.element(slider).toHaveAttribute("max", String(count - 1));
114+
await expect.element(slider).toHaveAttribute("aria-valuetext", "Medium (default)");
103115

104-
await userEvent.keyboard("{Home}");
105-
for (const [index, option] of options.entries()) {
106-
if (index > 0) await userEvent.keyboard("{ArrowRight}");
107-
await expect
108-
.element(slider)
109-
.toHaveAttribute(
110-
"aria-valuetext",
111-
`${option.label}${option.isDefault ? " (default)" : ""}`,
112-
);
113-
await expect.element(screen.getByRole("status")).toHaveTextContent(
114-
JSON.stringify([
115-
{ id: "reasoningEffort", value: option.id },
116-
{ id: "serviceTier", value: "fast" },
117-
]),
118-
);
119-
}
120-
await userEvent.keyboard("{ArrowLeft}{End}");
121-
await expect.element(slider).toHaveValue(String(count - 1));
122-
},
123-
);
116+
await userEvent.keyboard("{Home}");
117+
for (const [index, option] of options.entries()) {
118+
if (index > 0) await userEvent.keyboard("{ArrowRight}");
119+
await expect
120+
.element(slider)
121+
.toHaveAttribute("aria-valuetext", `${option.label}${option.isDefault ? " (default)" : ""}`);
122+
await expect.element(screen.getByRole("status")).toHaveTextContent(
123+
JSON.stringify([
124+
{ id: "reasoningEffort", value: option.id },
125+
{ id: "contextWindow", value: "normal" },
126+
{ id: "serviceTier", value: "fast" },
127+
]),
128+
);
129+
}
130+
await userEvent.keyboard("{ArrowLeft}{End}");
131+
await expect.element(slider).toHaveValue(String(count - 1));
132+
await userEvent.keyboard("{ArrowDown}");
133+
await expect.element(page.getByRole("radio", { name: "Normal" })).toHaveFocus();
134+
await userEvent.keyboard("{ArrowUp}");
135+
await expect.element(slider).toHaveFocus();
136+
});
124137

125138
it("toggles boolean Thinking both ways while preserving Service Tier", async () => {
126-
// The menu has no routing behavior.
139+
// The column has no routing behavior.
127140
await using screen = await render(<EffortMenu thinking />, { router: false });
128141
await userEvent.tab();
129142
const toggle = page.getByRole("switch", { name: "Thinking" });
@@ -137,21 +150,21 @@ it("toggles boolean Thinking both ways while preserving Service Tier", async ()
137150
{ id: "serviceTier", value: "fast" },
138151
]),
139152
);
140-
await userEvent.click(toggle);
153+
await userEvent.keyboard(" ");
141154
await expect.element(toggle).toHaveAttribute("aria-checked", "true");
142155
});
143156

144157
it("keeps prompt-controlled Ultrathink disabled", async () => {
145158
const options = [...levels, { id: "ultrathink", label: "Ultrathink" }];
146-
// The menu has no routing behavior.
159+
// The column has no routing behavior.
147160
await using screen = await render(
148161
<EffortMenu options={options} prompt="Please ultrathink about this" />,
149162
{
150163
router: false,
151164
},
152165
);
153-
await expect.element(page.getByRole("slider", { name: "Reasoning" })).toBeDisabled();
166+
await expect.element(screen.getByRole("slider", { name: "Reasoning" })).toBeDisabled();
154167
await expect
155-
.element(page.getByRole("slider", { name: "Reasoning" }))
168+
.element(screen.getByRole("slider", { name: "Reasoning" }))
156169
.toHaveAttribute("aria-valuetext", "Ultrathink");
157170
});

0 commit comments

Comments
 (0)