Skip to content

Commit d505694

Browse files
t3dotggclaude
andcommitted
feat(web): show fast mode as a bolt instead of a "Normal" label
The traits trigger spelled out the fast-mode state as text, so the near-universal off case burned horizontal space on the word "Normal". Drop fastMode from the trigger's text label entirely and render a lightning bolt only when it's on, matching how Codex presents it. The label-building logic moves into an exported pure function so it can be tested without mounting the menu. When fast mode is the only trait, fall back to the old Fast/Normal text so the trigger doesn't render as a bare bolt or bare chevron. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 38cfc25 commit d505694

2 files changed

Lines changed: 147 additions & 21 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
import type { ProviderOptionDescriptor } from "@t3tools/contracts";
3+
import { buildTraitsTriggerDisplay } from "./TraitsPicker";
4+
5+
function selectDescriptor(
6+
id: string,
7+
options: ReadonlyArray<{ id: string; label: string }>,
8+
currentValue: string,
9+
): Extract<ProviderOptionDescriptor, { type: "select" }> {
10+
return { id, label: id, type: "select", options: [...options], currentValue };
11+
}
12+
13+
function fastModeDescriptor(
14+
currentValue: boolean,
15+
): Extract<ProviderOptionDescriptor, { type: "boolean" }> {
16+
return { id: "fastMode", label: "Fast Mode", type: "boolean", currentValue };
17+
}
18+
19+
const EFFORT = selectDescriptor(
20+
"effort",
21+
[
22+
{ id: "high", label: "High" },
23+
{ id: "max", label: "Max" },
24+
],
25+
"high",
26+
);
27+
const CONTEXT_WINDOW = selectDescriptor(
28+
"contextWindow",
29+
[
30+
{ id: "200k", label: "200k" },
31+
{ id: "1m", label: "1M" },
32+
],
33+
"1m",
34+
);
35+
36+
function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>, fastModeEnabled: boolean) {
37+
return buildTraitsTriggerDisplay({
38+
descriptors,
39+
primarySelectDescriptorId: "effort",
40+
ultrathinkPromptControlled: false,
41+
fastModeEnabled,
42+
});
43+
}
44+
45+
describe("buildTraitsTriggerDisplay", () => {
46+
it("omits fast mode from the label entirely when it is off", () => {
47+
expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW], false)).toEqual({
48+
label: "High · 1M",
49+
showFastModeIcon: false,
50+
});
51+
});
52+
53+
it("shows the bolt instead of a text label when fast mode is on", () => {
54+
expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW], true)).toEqual({
55+
label: "High · 1M",
56+
showFastModeIcon: true,
57+
});
58+
});
59+
60+
it("keeps non-fastMode booleans as text labels", () => {
61+
const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
62+
id: "thinking",
63+
label: "Thinking",
64+
type: "boolean",
65+
currentValue: true,
66+
};
67+
expect(display([EFFORT, thinking], false)).toEqual({
68+
label: "High · Thinking On",
69+
showFastModeIcon: false,
70+
});
71+
});
72+
73+
it("falls back to a text label when fast mode is the only trait", () => {
74+
expect(display([fastModeDescriptor(true)], true)).toEqual({
75+
label: "Fast",
76+
showFastModeIcon: false,
77+
});
78+
expect(display([fastModeDescriptor(false)], false)).toEqual({
79+
label: "Normal",
80+
showFastModeIcon: false,
81+
});
82+
});
83+
84+
it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
85+
expect(
86+
buildTraitsTriggerDisplay({
87+
descriptors: [EFFORT, fastModeDescriptor(true)],
88+
primarySelectDescriptorId: "effort",
89+
ultrathinkPromptControlled: true,
90+
fastModeEnabled: true,
91+
}),
92+
).toEqual({ label: "Ultrathink", showFastModeIcon: true });
93+
});
94+
});

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

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "@t3tools/shared/model";
1717
import { memo, useCallback, useState } from "react";
1818
import type { VariantProps } from "class-variance-authority";
19-
import { ChevronDownIcon } from "lucide-react";
19+
import { ChevronDownIcon, ZapIcon } from "lucide-react";
2020
import { Button, buttonVariants } from "../ui/button";
2121
import {
2222
Menu,
@@ -379,6 +379,41 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
379379
);
380380
});
381381

382+
/**
383+
* Build the traits trigger's text label plus whether the fast-mode bolt should
384+
* render. Fast mode is a lightning bolt when on and nothing at all when off —
385+
* "Normal" is the near-universal case and isn't worth the horizontal space. The
386+
* one exception is when fast mode is the only trait, where a bare bolt (or bare
387+
* chevron) would leave the trigger unreadable.
388+
*/
389+
export function buildTraitsTriggerDisplay(input: {
390+
descriptors: ReadonlyArray<ProviderOptionDescriptor>;
391+
primarySelectDescriptorId: string | null;
392+
ultrathinkPromptControlled: boolean;
393+
fastModeEnabled: boolean;
394+
}): { label: string; showFastModeIcon: boolean } {
395+
const labels: Array<string> = [];
396+
for (const descriptor of input.descriptors) {
397+
if (descriptor.id === "fastMode" && descriptor.type === "boolean") {
398+
continue;
399+
}
400+
const label =
401+
input.ultrathinkPromptControlled && descriptor.id === input.primarySelectDescriptorId
402+
? "Ultrathink"
403+
: descriptor.type === "boolean"
404+
? `${descriptor.label} ${descriptor.currentValue === true ? "On" : "Off"}`
405+
: getProviderOptionCurrentLabel(descriptor);
406+
if (typeof label === "string" && label.length > 0) {
407+
labels.push(label);
408+
}
409+
}
410+
411+
if (labels.length === 0) {
412+
return { label: input.fastModeEnabled ? "Fast" : "Normal", showFastModeIcon: false };
413+
}
414+
return { label: labels.join(" · "), showFastModeIcon: input.fastModeEnabled };
415+
}
416+
382417
export const TraitsPicker = memo(function TraitsPicker({
383418
provider,
384419
instanceId,
@@ -393,7 +428,7 @@ export const TraitsPicker = memo(function TraitsPicker({
393428
...persistence
394429
}: TraitsMenuContentProps & TraitsPersistence) {
395430
const [isMenuOpen, setIsMenuOpen] = useState(false);
396-
const { descriptors, primarySelectDescriptor, ultrathinkPromptControlled } =
431+
const { descriptors, primarySelectDescriptor, ultrathinkPromptControlled, fastModeEnabled } =
397432
getTraitsSectionVisibility({
398433
provider,
399434
models,
@@ -415,23 +450,18 @@ export const TraitsPicker = memo(function TraitsPicker({
415450
return null;
416451
}
417452

418-
const triggerLabels: Array<string> = [];
419-
for (const descriptor of descriptors) {
420-
const label =
421-
ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id
422-
? "Ultrathink"
423-
: descriptor.type === "boolean"
424-
? descriptor.id === "fastMode"
425-
? descriptor.currentValue === true
426-
? "Fast"
427-
: "Normal"
428-
: `${descriptor.label} ${descriptor.currentValue === true ? "On" : "Off"}`
429-
: getProviderOptionCurrentLabel(descriptor);
430-
if (typeof label === "string" && label.length > 0) {
431-
triggerLabels.push(label);
432-
}
433-
}
434-
const triggerLabel = triggerLabels.join(" · ");
453+
const { label: triggerLabel, showFastModeIcon } = buildTraitsTriggerDisplay({
454+
descriptors,
455+
primarySelectDescriptorId: primarySelectDescriptor?.id ?? null,
456+
ultrathinkPromptControlled,
457+
fastModeEnabled,
458+
});
459+
const fastModeIcon = showFastModeIcon ? (
460+
<>
461+
<ZapIcon aria-hidden="true" className="size-3 shrink-0 text-foreground/80 opacity-100" />
462+
<span className="sr-only">Fast mode on</span>
463+
</>
464+
) : null;
435465

436466
const isCodexStyle = provider === "codex";
437467

@@ -457,12 +487,14 @@ export const TraitsPicker = memo(function TraitsPicker({
457487
}
458488
>
459489
{isCodexStyle ? (
460-
<span className="flex min-w-0 w-full items-center gap-2 overflow-hidden">
461-
{triggerLabel}
490+
<span className="flex min-w-0 w-full items-center gap-1.5 overflow-hidden">
491+
{fastModeIcon}
492+
<span className="min-w-0 truncate">{triggerLabel}</span>
462493
<ChevronDownIcon aria-hidden="true" className="size-3 shrink-0 opacity-60" />
463494
</span>
464495
) : (
465496
<>
497+
{fastModeIcon}
466498
<span>{triggerLabel}</span>
467499
<ChevronDownIcon aria-hidden="true" className="size-3 opacity-60" />
468500
</>

0 commit comments

Comments
 (0)