Skip to content

Commit 83522e2

Browse files
committed
fix: replace MaxTokensControl input with MaxTokensSlider
- Replaced the input field with a slider component as requested by Daniel - Moved Max Output Tokens control to Advanced Settings for all models - Kept the existing slider behavior from reasoning models - Updated tests to match the new implementation - Removed the old MaxTokensControl component and its tests This addresses the issue where changing custom tokens affected the reasoning slider value and provides a more consistent UX by using sliders for both max output tokens and max thinking tokens.
1 parent ca0fb2d commit 83522e2

File tree

7 files changed

+171
-286
lines changed

7 files changed

+171
-286
lines changed

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import { DiffSettingsControl } from "./DiffSettingsControl"
8181
import { TemperatureControl } from "./TemperatureControl"
8282
import { RateLimitSecondsControl } from "./RateLimitSecondsControl"
8383
import { ConsecutiveMistakeLimitControl } from "./ConsecutiveMistakeLimitControl"
84-
import { MaxTokensControl } from "./MaxTokensControl"
84+
import { MaxTokensSlider } from "./MaxTokensSlider"
8585
import { BedrockCustomArn } from "./providers/BedrockCustomArn"
8686
import { buildDocLink } from "@src/utils/docLinks"
8787

@@ -575,12 +575,10 @@ const ApiOptions = ({
575575
onChange={handleInputChange("modelTemperature", noTransform)}
576576
maxValue={2}
577577
/>
578-
<MaxTokensControl
578+
<MaxTokensSlider
579579
value={apiConfiguration.modelMaxTokens}
580580
onChange={(value) => setApiConfigurationField("modelMaxTokens", value)}
581581
modelInfo={selectedModelInfo}
582-
minValue={2048}
583-
maxValue={selectedModelInfo?.maxTokens || 200000}
584582
/>
585583
<RateLimitSecondsControl
586584
value={apiConfiguration.rateLimitSeconds || 0}

webview-ui/src/components/settings/MaxTokensControl.tsx

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from "react"
2+
import { useAppTranslation } from "@/i18n/TranslationContext"
3+
import { ModelInfo } from "@roo-code/types"
4+
import { Slider } from "@/components/ui"
5+
import { DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS } from "@roo/api"
6+
7+
interface MaxTokensSliderProps {
8+
value?: number
9+
onChange: (value: number | undefined) => void
10+
modelInfo?: ModelInfo
11+
className?: string
12+
}
13+
14+
export const MaxTokensSlider: React.FC<MaxTokensSliderProps> = ({ value, onChange, modelInfo, className }) => {
15+
const { t } = useAppTranslation()
16+
17+
// Use the same logic as the original ThinkingBudget component
18+
const customMaxOutputTokens = value || DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS
19+
const maxValue = modelInfo?.maxTokens
20+
? Math.max(modelInfo.maxTokens, customMaxOutputTokens, DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS)
21+
: Math.max(customMaxOutputTokens, DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS)
22+
23+
return (
24+
<div className={`flex flex-col gap-1 ${className || ""}`}>
25+
<div className="font-medium">{t("settings:providers.maxOutputTokens.label")}</div>
26+
<div className="flex items-center gap-1">
27+
<Slider
28+
min={8192}
29+
max={maxValue}
30+
step={1024}
31+
value={[customMaxOutputTokens]}
32+
onValueChange={([value]) => onChange(value)}
33+
/>
34+
<div className="w-12 text-sm text-center">{customMaxOutputTokens}</div>
35+
</div>
36+
<div className="text-sm text-vscode-descriptionForeground">
37+
{t("settings:providers.maxOutputTokens.description")}
38+
</div>
39+
{modelInfo && (
40+
<div className="text-sm text-vscode-descriptionForeground">
41+
{t("settings:providers.maxOutputTokens.modelSupports", { max: modelInfo.maxTokens })}
42+
</div>
43+
)}
44+
</div>
45+
)
46+
}

webview-ui/src/components/settings/ThinkingBudget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
6565
<Slider
6666
min={1024}
6767
max={modelMaxThinkingTokens}
68-
step={256}
68+
step={1024}
6969
value={[Math.min(customMaxThinkingTokens, modelMaxThinkingTokens)]}
7070
onValueChange={([value]) => setApiConfigurationField("modelMaxThinkingTokens", value)}
7171
/>

webview-ui/src/components/settings/__tests__/ApiOptions.spec.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,21 @@ vi.mock("@/components/ui", () => ({
8383
Popover: ({ children, _open, _onOpenChange }: any) => <div className="popover-mock">{children}</div>,
8484
PopoverContent: ({ children, _className }: any) => <div className="popover-content-mock">{children}</div>,
8585
PopoverTrigger: ({ children, _asChild }: any) => <div className="popover-trigger-mock">{children}</div>,
86-
Slider: ({ value, onChange }: any) => (
86+
Slider: ({ value, onChange, onValueChange, min, max, step }: any) => (
8787
<div data-testid="slider">
88-
<input type="range" value={value || 0} onChange={(e) => onChange(parseFloat(e.target.value))} />
88+
<input
89+
type="range"
90+
min={min}
91+
max={max}
92+
step={step}
93+
value={value?.[0] || value || 0}
94+
onChange={(e) => {
95+
const val = parseFloat(e.target.value)
96+
if (onChange) onChange(val)
97+
if (onValueChange) onValueChange([val])
98+
}}
99+
data-testid="slider-input"
100+
/>
89101
</div>
90102
),
91103
SearchableSelect: ({ value, onValueChange, options, placeholder, "data-testid": dataTestId }: any) => (
@@ -114,7 +126,7 @@ vi.mock("@/components/ui", () => ({
114126
CollapsibleContent: ({ children, className }: any) => (
115127
<div className={`collapsible-content-mock ${className || ""}`}>{children}</div>
116128
),
117-
// Add Input component for MaxTokensControl
129+
// Add Input component for other controls
118130
Input: ({ id, type, value, onChange, min, max, className, ...props }: any) => (
119131
<input
120132
id={id}

webview-ui/src/components/settings/__tests__/MaxTokensControl.spec.tsx

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)