Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions apps/web/src/components/chat/TraitsPicker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,48 @@ const CONTEXT_WINDOW = selectDescriptor(

const CODEX = ProviderDriverKind.make("codex");

function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>, fastModeEnabled: boolean) {
function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
return buildTraitsTriggerDisplay({
provider: CODEX,
descriptors,
primarySelectDescriptorId: "reasoningEffort",
ultrathinkPromptControlled: false,
fastModeEnabled,
});
}

describe("buildTraitsTriggerDisplay", () => {
it("omits fast mode from the label entirely when it is off", () => {
expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW], false)).toEqual({
expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW])).toEqual({
label: "High · 1M",
showFastModeIcon: false,
});
});

it("shows the bolt instead of a text label when fast mode is on", () => {
expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW], true)).toEqual({
expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW])).toEqual({
label: "High · 1M",
showFastModeIcon: true,
});
});

it("omits Codex's default Standard tier beside reasoning", () => {
it("renders Codex's Standard and Fast service tiers as fast mode", () => {
const serviceTier = selectDescriptor(
"serviceTier",
[{ id: "default", label: "Standard", isDefault: true }],
[
{ id: "default", label: "Standard", isDefault: true },
{ id: "priority", label: "Fast" },
],
"default",
);

expect(display([EFFORT, serviceTier], false).label).toBe("High");
expect(display([EFFORT, serviceTier])).toEqual({
label: "High",
showFastModeIcon: false,
});
expect(display([EFFORT, { ...serviceTier, currentValue: "priority" }])).toEqual({
label: "High",
showFastModeIcon: true,
});
});

it("keeps non-fastMode booleans as text labels", () => {
Expand All @@ -77,18 +86,18 @@ describe("buildTraitsTriggerDisplay", () => {
type: "boolean",
currentValue: true,
};
expect(display([EFFORT, thinking], false)).toEqual({
expect(display([EFFORT, thinking])).toEqual({
label: "High · Thinking On",
showFastModeIcon: false,
});
});

it("falls back to a text label when fast mode is the only trait", () => {
expect(display([fastModeDescriptor(true)], true)).toEqual({
expect(display([fastModeDescriptor(true)])).toEqual({
label: "Fast",
showFastModeIcon: false,
});
expect(display([fastModeDescriptor(false)], false)).toEqual({
expect(display([fastModeDescriptor(false)])).toEqual({
label: "Normal",
showFastModeIcon: false,
});
Expand All @@ -107,7 +116,7 @@ describe("buildTraitsTriggerDisplay", () => {
{ id: "high", label: "High" },
],
};
expect(display([unresolved], false)).toEqual({ label: "", showFastModeIcon: false });
expect(display([unresolved])).toEqual({ label: "", showFastModeIcon: false });
});

it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
Expand All @@ -117,7 +126,6 @@ describe("buildTraitsTriggerDisplay", () => {
descriptors: [EFFORT, fastModeDescriptor(true)],
primarySelectDescriptorId: "reasoningEffort",
ultrathinkPromptControlled: true,
fastModeEnabled: true,
}),
).toEqual({ label: "Ultrathink", showFastModeIcon: true });
});
Expand Down
22 changes: 10 additions & 12 deletions apps/web/src/components/chat/TraitsPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ function getSelectedTraits(
: getDescriptorStringValue(primarySelectDescriptor)) ?? null;
const thinkingEnabled =
typeof thinkingDescriptor?.currentValue === "boolean" ? thinkingDescriptor.currentValue : null;
const fastModeEnabled =
typeof fastModeDescriptor?.currentValue === "boolean" ? fastModeDescriptor.currentValue : false;
const contextWindow = getDescriptorStringValue(contextWindowDescriptor);
const selectedAgent = getDescriptorStringValue(agentDescriptor);
const selectedAgentLabel = agentDescriptor
Expand All @@ -154,7 +152,6 @@ function getSelectedTraits(
thinkingDescriptor,
effort,
thinkingEnabled,
fastModeEnabled,
contextWindow,
ultrathinkPromptControlled,
ultrathinkInBodyText,
Expand Down Expand Up @@ -392,24 +389,26 @@ export function buildTraitsTriggerDisplay(input: {
descriptors: ReadonlyArray<ProviderOptionDescriptor>;
primarySelectDescriptorId: string | null;
ultrathinkPromptControlled: boolean;
fastModeEnabled: boolean;
}): { label: string; showFastModeIcon: boolean } {
let hasFastMode = false;
let fastModeEnabled = false;
const labels: Array<string> = [];
for (const descriptor of input.descriptors) {
if (descriptor.id === "fastMode" && descriptor.type === "boolean") {
hasFastMode = true;
fastModeEnabled = descriptor.currentValue === true;
continue;
}
if (
input.provider === "codex" &&
descriptor.id === "serviceTier" &&
descriptor.type === "select" &&
input.descriptors.some(({ id }) => id === "reasoningEffort")
descriptor.type === "select"
) {
const currentValue = getProviderOptionCurrentValue(descriptor);
const currentOption = descriptor.options.find((option) => option.id === currentValue);
if (currentOption?.id === "default" && currentOption.isDefault === true) {
Comment thread
t3dotgg marked this conversation as resolved.
const fastTier = descriptor.options.find(({ label }) => label === "Fast");
if (fastTier && (currentValue === "default" || currentValue === fastTier.id)) {
hasFastMode = true;
fastModeEnabled = currentValue === fastTier.id;
continue;
}
}
Expand All @@ -428,9 +427,9 @@ export function buildTraitsTriggerDisplay(input: {
// off an empty label list alone would also catch descriptors that resolved to
// no label at all, printing a bogus "Normal" for a model without fast mode.
if (labels.length === 0 && hasFastMode) {
return { label: input.fastModeEnabled ? "Fast" : "Normal", showFastModeIcon: false };
return { label: fastModeEnabled ? "Fast" : "Normal", showFastModeIcon: false };
}
return { label: labels.join(" · "), showFastModeIcon: input.fastModeEnabled };
return { label: labels.join(" · "), showFastModeIcon: fastModeEnabled };
}

export const TraitsPicker = memo(function TraitsPicker({
Expand All @@ -447,7 +446,7 @@ export const TraitsPicker = memo(function TraitsPicker({
...persistence
}: TraitsMenuContentProps & TraitsPersistence) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const { descriptors, primarySelectDescriptor, ultrathinkPromptControlled, fastModeEnabled } =
const { descriptors, primarySelectDescriptor, ultrathinkPromptControlled } =
getTraitsSectionVisibility({
provider,
models,
Expand All @@ -474,7 +473,6 @@ export const TraitsPicker = memo(function TraitsPicker({
descriptors,
primarySelectDescriptorId: primarySelectDescriptor?.id ?? null,
ultrathinkPromptControlled,
fastModeEnabled,
});
const fastModeIcon = showFastModeIcon ? (
<>
Expand Down
Loading