mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Fix the speed button's unknown, Flex and chat-options Escape cases (#40173)
* Fix the speed button's unknown, Flex and composer Escape cases
Follow-up to #40052 from its review:
- An unknown speed names no tier instead of claiming Standard.
- Escape in the speed list inside the chat options popover closes only the
list, not the whole popover.
- Only Codex's Fast tier gets the on/off chip, bolt and pressed fill; Flex
and other tiers are picked from the list. The Fast test is shared with
the main process.
- The list trigger takes the chip's pressed fill from the shared variant,
and the list has an accessible name.
* Show every agent's speed as the same Speed button in every picker
Claude's and Cursor's Fast mode now use the ⚡ Fast button under a Speed
label in the chat options popover and the select-mode pickers too, instead
of a Fast mode switch, matching Codex: one button for two modes, a list for
more.
(cherry picked from commit 3ad9b7c44f)
This commit is contained in:
@@ -8,6 +8,7 @@ import type { CodexOpenedThread } from '../threads/codex-structured-thread-open'
|
||||
import type { CodexSession } from '../session-lifecycle/codex-structured-session-state'
|
||||
import { codexSessionCapabilities } from './codex-structured-catalog-entry'
|
||||
import { effectiveServiceTier } from '../../../../shared/agent-session/options/structured-agent-session-effective-tier'
|
||||
import { isFastServiceTier } from '../../../../shared/agent-session/options/structured-agent-session-discovered-model'
|
||||
|
||||
export const CODEX_DEFAULT_SERVICE_TIER = 'default'
|
||||
|
||||
@@ -41,9 +42,7 @@ export function readCodexServiceTiers(
|
||||
export function codexFastServiceTier(
|
||||
model: Pick<AgentSessionModelOption, 'serviceTiers'> | undefined
|
||||
): string | undefined {
|
||||
return model?.serviceTiers?.find(
|
||||
(tier) => tier.label.toLowerCase() === 'fast' || tier.value.toLowerCase() === 'fast'
|
||||
)?.value
|
||||
return model?.serviceTiers?.find(isFastServiceTier)?.value
|
||||
}
|
||||
|
||||
/** Nonstandard tiers other than Fast have no legacy toggle value. */
|
||||
|
||||
+7
-1
@@ -261,8 +261,14 @@ function SessionOptionPopover(props: {
|
||||
onInteractOutside={focusReturn.onInteractOutside}
|
||||
onCloseAutoFocus={focusReturn.onCloseAutoFocus}
|
||||
// Close through a level tooltip’s first Escape; let Radix handle search Escape after IME.
|
||||
// Escape from a portaled child (the speed list) closes only that child.
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Escape' && !(event.target instanceof HTMLInputElement)) {
|
||||
if (
|
||||
event.key === 'Escape' &&
|
||||
!(event.target instanceof HTMLInputElement) &&
|
||||
event.target instanceof Node &&
|
||||
event.currentTarget.contains(event.target)
|
||||
) {
|
||||
setOpen(false)
|
||||
}
|
||||
}}
|
||||
|
||||
+12
-13
@@ -125,8 +125,10 @@ function OptionRow(props: {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (descriptor.kind.type === 'boolean' && layout === 'inline' && descriptor.id === 'fastMode') {
|
||||
return (
|
||||
// Every agent's speed is one button: Fast on/off for two modes, a list for more.
|
||||
const speed = speedButtonTiers(descriptor)
|
||||
const speedButton =
|
||||
descriptor.kind.type === 'boolean' && descriptor.id === 'fastMode' ? (
|
||||
<Toggle
|
||||
variant="chip"
|
||||
size="xs"
|
||||
@@ -137,22 +139,19 @@ function OptionRow(props: {
|
||||
<Zap className="size-3" />
|
||||
{say('fast')}
|
||||
</Toggle>
|
||||
)
|
||||
}
|
||||
const speed = speedButtonTiers(descriptor)
|
||||
if (speed && descriptor.kind.type === 'select') {
|
||||
const button = (
|
||||
) : speed && descriptor.kind.type === 'select' ? (
|
||||
<NativeChatSessionSpeedButton
|
||||
label={label}
|
||||
label={say('speed')}
|
||||
standard={speed.standard}
|
||||
faster={speed.faster}
|
||||
tiers={speed.tiers}
|
||||
current={gone ? undefined : descriptor.kind.currentValue}
|
||||
disabled={off}
|
||||
onSet={onSet}
|
||||
/>
|
||||
)
|
||||
) : null
|
||||
if (speedButton) {
|
||||
return layout === 'inline' ? (
|
||||
button
|
||||
speedButton
|
||||
) : (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -160,8 +159,8 @@ function OptionRow(props: {
|
||||
layout === 'menu' && 'px-2'
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{button}
|
||||
{say('speed')}
|
||||
{speedButton}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { fireEvent, getAllByRole, getByRole } from '@testing-library/react'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import { NativeChatSessionSpeedButton } from './NativeChatSessionSpeedButton'
|
||||
|
||||
const STANDARD = { value: 'default', label: 'Standard' }
|
||||
const TIERS = [
|
||||
{ value: 'priority', label: 'Fast' },
|
||||
{ value: 'ultrafast', label: 'Ultrafast' }
|
||||
]
|
||||
|
||||
let unmount: (() => void) | undefined
|
||||
afterEach(() => {
|
||||
act(() => unmount?.())
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
function renderSpeed(
|
||||
current: string | undefined,
|
||||
tiers: { value: string; label: string }[] = TIERS
|
||||
): HTMLElement {
|
||||
const host = document.body.appendChild(document.createElement('div'))
|
||||
const root = createRoot(host)
|
||||
act(() =>
|
||||
root.render(
|
||||
<NativeChatSessionSpeedButton
|
||||
label="Speed"
|
||||
standard={STANDARD}
|
||||
tiers={tiers}
|
||||
current={current}
|
||||
disabled={false}
|
||||
onSet={() => {}}
|
||||
/>
|
||||
)
|
||||
)
|
||||
unmount = () => root.unmount()
|
||||
return getByRole(host, 'button')
|
||||
}
|
||||
|
||||
function checkedTiers(trigger: HTMLElement): string[] {
|
||||
act(() => {
|
||||
fireEvent.keyDown(trigger, { key: 'Enter' })
|
||||
})
|
||||
return getAllByRole(document.body, 'menuitemradio')
|
||||
.filter((item) => item.getAttribute('aria-checked') === 'true')
|
||||
.map((item) => item.textContent ?? '')
|
||||
}
|
||||
|
||||
it('names no tier when the current speed is unknown', () => {
|
||||
const trigger = renderSpeed(undefined)
|
||||
expect(trigger.getAttribute('aria-label')).toBe('Speed')
|
||||
expect(checkedTiers(trigger)).toEqual([])
|
||||
})
|
||||
|
||||
it('opens a list for a lone Flex tier instead of a Fast toggle', () => {
|
||||
const trigger = renderSpeed('flex', [{ value: 'flex', label: 'flex' }])
|
||||
expect(trigger.getAttribute('aria-pressed')).toBeNull()
|
||||
expect(trigger.getAttribute('aria-label')).toBe('Speed: flex')
|
||||
})
|
||||
+22
-22
@@ -1,5 +1,4 @@
|
||||
import { ChevronDown, Zap } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Toggle, toggleVariants } from '@/components/ui/toggle'
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -14,37 +13,41 @@ import type {
|
||||
SessionOptionValue
|
||||
} from '../../../../../../../shared/native-chat/input/native-chat-session-options'
|
||||
import { nativeChatSessionChoiceLabel } from '../../../../../../../shared/native-chat/input/native-chat-session-option-labels'
|
||||
import { isFastServiceTier } from '../../../../../../../shared/agent-session/options/structured-agent-session-discovered-model'
|
||||
import { sayNativeChatSessionOptionTranslated as say } from './native-chat-session-option-labels-text'
|
||||
|
||||
const STANDARD_TIER = 'default'
|
||||
|
||||
/** Standard plus the faster tiers, or null when the select is not a speed choice with any. */
|
||||
/** Standard plus the other tiers, or null when the select is not a speed choice with any. */
|
||||
export function speedButtonTiers(
|
||||
descriptor: SessionOptionDescriptor
|
||||
): { standard: SessionOptionSelectChoice; faster: SessionOptionSelectChoice[] } | null {
|
||||
): { standard: SessionOptionSelectChoice; tiers: SessionOptionSelectChoice[] } | null {
|
||||
if (descriptor.id !== 'serviceTier' || descriptor.kind.type !== 'select') {
|
||||
return null
|
||||
}
|
||||
const standard = descriptor.kind.choices.find((choice) => choice.value === STANDARD_TIER)
|
||||
const faster = descriptor.kind.choices.filter((choice) => choice.value !== STANDARD_TIER)
|
||||
return standard && faster.length > 0 ? { standard, faster } : null
|
||||
const tiers = descriptor.kind.choices.filter((choice) => choice.value !== STANDARD_TIER)
|
||||
return standard && tiers.length > 0 ? { standard, tiers } : null
|
||||
}
|
||||
|
||||
/** One faster tier toggles like Claude's Fast; several open a list instead of a segmented switcher. */
|
||||
/** A lone Fast tier toggles like Claude's Fast; anything else opens a list instead of a segmented switcher. */
|
||||
export function NativeChatSessionSpeedButton(props: {
|
||||
label: string
|
||||
standard: SessionOptionSelectChoice
|
||||
faster: SessionOptionSelectChoice[]
|
||||
tiers: SessionOptionSelectChoice[]
|
||||
current: string | undefined
|
||||
disabled: boolean
|
||||
onSet: (value: SessionOptionValue) => void
|
||||
}): React.JSX.Element {
|
||||
const { label, standard, faster, current, disabled, onSet } = props
|
||||
const picked = faster.find((choice) => choice.value === current)
|
||||
const { label, standard, tiers, current, disabled, onSet } = props
|
||||
const picked = tiers.find((choice) => choice.value === current)
|
||||
// An unknown tier names no choice, rather than claiming Standard.
|
||||
const shown = picked ?? (current === standard.value ? standard : undefined)
|
||||
const nameOf = (choice: SessionOptionSelectChoice) =>
|
||||
nativeChatSessionChoiceLabel(choice, say, 'serviceTier')
|
||||
if (faster.length === 1) {
|
||||
const only = faster[0]
|
||||
// Only Fast takes the toggle and bolt; Flex and other tiers are picked from the list.
|
||||
if (tiers.length === 1 && isFastServiceTier(tiers[0])) {
|
||||
const only = tiers[0]
|
||||
return (
|
||||
<Toggle
|
||||
variant="chip"
|
||||
@@ -63,22 +66,19 @@ export function NativeChatSessionSpeedButton(props: {
|
||||
<DropdownMenuTrigger asChild disabled={disabled}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`${label}: ${nameOf(picked ?? standard)}`}
|
||||
// Mirrors the chip's pressed fill; a menu trigger's data-state names open, not on.
|
||||
className={cn(
|
||||
toggleVariants({ variant: 'chip', size: 'xs' }),
|
||||
'gap-1',
|
||||
picked && 'border-transparent bg-foreground/12 text-foreground dark:bg-accent'
|
||||
)}
|
||||
aria-label={shown ? `${label}: ${nameOf(shown)}` : label}
|
||||
// A menu trigger's data-state names open, not on, so pressed rides on data-pressed.
|
||||
data-pressed={Boolean(picked && isFastServiceTier(picked))}
|
||||
className={toggleVariants({ variant: 'chip', size: 'xs' })}
|
||||
>
|
||||
<Zap className="size-3" />
|
||||
{nameOf(picked ?? standard)}
|
||||
{picked && isFastServiceTier(picked) ? <Zap className="size-3" /> : null}
|
||||
{shown ? nameOf(shown) : label}
|
||||
<ChevronDown className="size-3 opacity-70" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" collisionPadding={8} className="min-w-56">
|
||||
<DropdownMenuRadioGroup value={picked?.value ?? standard.value} onValueChange={onSet}>
|
||||
{[standard, ...faster].map((choice) => (
|
||||
<DropdownMenuRadioGroup aria-label={label} value={shown?.value ?? ''} onValueChange={onSet}>
|
||||
{[standard, ...tiers].map((choice) => (
|
||||
<DropdownMenuRadioItem key={choice.value} value={choice.value}>
|
||||
<span className="flex min-w-0 flex-col gap-0.5">
|
||||
<span>{nameOf(choice)}</span>
|
||||
|
||||
@@ -16,7 +16,8 @@ const toggleVariants = cva(
|
||||
segmented:
|
||||
'bg-transparent text-muted-foreground transition-[color,background-color,box-shadow] hover:bg-foreground/6 hover:text-foreground data-[state=on]:bg-foreground/12 data-[state=on]:text-foreground dark:hover:bg-accent/50 dark:data-[state=on]:bg-accent',
|
||||
// An outlined segmented toggle that stands alone; pressed trades its border for the fill.
|
||||
chip: 'border border-input bg-transparent text-muted-foreground transition-[color,background-color,box-shadow] hover:bg-foreground/6 hover:text-foreground data-[state=on]:border-transparent data-[state=on]:bg-foreground/12 data-[state=on]:text-foreground dark:hover:bg-accent/50 dark:data-[state=on]:bg-accent'
|
||||
// data-pressed lets a menu trigger, whose data-state names open, show the same pressed fill.
|
||||
chip: 'border border-input bg-transparent text-muted-foreground transition-[color,background-color,box-shadow] hover:bg-foreground/6 hover:text-foreground data-[pressed=true]:border-transparent data-[pressed=true]:bg-foreground/12 data-[pressed=true]:text-foreground data-[state=on]:border-transparent data-[state=on]:bg-foreground/12 data-[state=on]:text-foreground dark:hover:bg-accent/50 dark:data-[pressed=true]:bg-accent dark:data-[state=on]:bg-accent'
|
||||
},
|
||||
size: {
|
||||
default: 'h-9 min-w-9 px-2',
|
||||
|
||||
@@ -42,6 +42,13 @@ function fastModeOption(): CatalogOption {
|
||||
}
|
||||
}
|
||||
|
||||
/** The tier Codex names Fast, by label or id; the only one the single Fast toggle stands for. */
|
||||
export function isFastServiceTier(
|
||||
tier: Pick<AgentSessionOptionChoice, 'label' | 'value'>
|
||||
): boolean {
|
||||
return tier.label.toLowerCase() === 'fast' || tier.value.toLowerCase() === 'fast'
|
||||
}
|
||||
|
||||
/** Standard plus the tiers the model lists, valued by tier id; one choice in place of Fast. */
|
||||
export function serviceTierOption(tiers: readonly AgentSessionOptionChoice[]): CatalogOption {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user