@@ -46,6 +46,7 @@ import {
4646 DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS ,
4747 DEFAULT_HYBRID_REASONING_MODEL_THINKING_TOKENS ,
4848 GEMINI_25_PRO_MIN_THINKING_TOKENS ,
49+ getModelMaxOutputTokens ,
4950} from "@roo/api"
5051
5152import { useAppTranslation } from "@src/i18n/TranslationContext"
@@ -75,6 +76,10 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
7576 const isReasoningBudgetSupported = ! ! modelInfo && modelInfo . supportsReasoningBudget
7677 const isReasoningBudgetRequired = ! ! modelInfo && modelInfo . requiredReasoningBudget
7778 const isReasoningEffortSupported = ! ! modelInfo && modelInfo . supportsReasoningEffort
79+ // Models that advertise a user-configurable max output budget (e.g. Z.ai GLM) but do not
80+ // use the reasoning-budget slider. The reasoning-budget branch already renders its own
81+ // max-tokens control, so only surface this standalone slider when that branch is inactive.
82+ const isMaxTokensConfigurable = ! ! modelInfo && modelInfo . supportsMaxTokens && ! isReasoningBudgetSupported
7883
7984 // Build available reasoning efforts list from capability
8085 const supports = modelInfo ?. supportsReasoningEffort
@@ -160,10 +165,40 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
160165 }
161166 } , [ isReasoningBudgetSupported , customMaxThinkingTokens , modelMaxThinkingTokens , setApiConfigurationField ] )
162167
168+ // Default max output budget for models that expose a standalone max-tokens slider.
169+ // When the user hasn't set an explicit `modelMaxTokens`, fall back to the same value
170+ // the runtime would use (the default output clamp) so behavior is unchanged.
171+ const defaultMaxOutputTokens =
172+ ( isMaxTokensConfigurable && selectedModelId && modelInfo
173+ ? getModelMaxOutputTokens ( { modelId : selectedModelId , model : modelInfo , settings : apiConfiguration } )
174+ : undefined ) ??
175+ modelInfo ?. maxTokens ??
176+ DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS
177+ const standaloneMaxOutputTokens = apiConfiguration . modelMaxTokens || defaultMaxOutputTokens
178+
163179 if ( ! modelInfo ) {
164180 return null
165181 }
166182
183+ // Standalone max output tokens slider for models that advertise `supportsMaxTokens`
184+ // (e.g. Z.ai GLM) but do not surface the reasoning-budget control.
185+ const maxOutputTokensControl =
186+ isMaxTokensConfigurable && modelInfo . maxTokens ? (
187+ < div className = "flex flex-col gap-1" data-testid = "max-output-tokens" >
188+ < div className = "font-medium" > { t ( "settings:thinkingBudget.maxTokens" ) } </ div >
189+ < div className = "flex items-center gap-1" >
190+ < Slider
191+ min = { 1024 }
192+ max = { modelInfo . maxTokens }
193+ step = { 1024 }
194+ value = { [ standaloneMaxOutputTokens ] }
195+ onValueChange = { ( [ value ] ) => setApiConfigurationField ( "modelMaxTokens" , value ) }
196+ />
197+ < div className = "w-12 text-sm text-center" > { standaloneMaxOutputTokens } </ div >
198+ </ div >
199+ </ div >
200+ ) : null
201+
167202 // Models with supportsReasoningBinary (binary reasoning) show a simple on/off toggle
168203 if ( isReasoningSupported ) {
169204 return (
@@ -228,44 +263,51 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
228263 ) }
229264 </ >
230265 ) : isReasoningEffortSupported ? (
231- < div className = "flex flex-col gap-1" data-testid = "reasoning-effort" >
232- < div className = "flex justify-between items-center" >
233- < label className = "block font-medium mb-1" > { t ( "settings:providers.reasoningEffort.label" ) } </ label >
234- </ div >
235- < Select
236- value = { currentReasoningEffort }
237- onValueChange = { ( value : ReasoningEffortOption ) => {
238- // "disable" turns off reasoning entirely; "none" is a valid reasoning level
239- if ( value === "disable" ) {
240- setApiConfigurationField ( "enableReasoningEffort" , false )
241- setApiConfigurationField ( "reasoningEffort" , "disable" )
242- } else {
243- // "none", "minimal", "low", "medium", "high" all enable reasoning
244- setApiConfigurationField ( "enableReasoningEffort" , true )
245- setApiConfigurationField ( "reasoningEffort" , value as ReasoningEffortWithMinimal )
246- }
247- } } >
248- < SelectTrigger className = "w-full" >
249- < SelectValue
250- placeholder = {
251- currentReasoningEffort
252- ? currentReasoningEffort === "none" || currentReasoningEffort === "disable"
253- ? t ( "settings:providers.reasoningEffort.none" )
254- : t ( `settings:providers.reasoningEffort.${ currentReasoningEffort } ` )
255- : t ( "settings:common.select" )
266+ < >
267+ { maxOutputTokensControl }
268+ < div className = "flex flex-col gap-1" data-testid = "reasoning-effort" >
269+ < div className = "flex justify-between items-center" >
270+ < label className = "block font-medium mb-1" >
271+ { t ( "settings:providers.reasoningEffort.label" ) }
272+ </ label >
273+ </ div >
274+ < Select
275+ value = { currentReasoningEffort }
276+ onValueChange = { ( value : ReasoningEffortOption ) => {
277+ // "disable" turns off reasoning entirely; "none" is a valid reasoning level
278+ if ( value === "disable" ) {
279+ setApiConfigurationField ( "enableReasoningEffort" , false )
280+ setApiConfigurationField ( "reasoningEffort" , "disable" )
281+ } else {
282+ // "none", "minimal", "low", "medium", "high" all enable reasoning
283+ setApiConfigurationField ( "enableReasoningEffort" , true )
284+ setApiConfigurationField ( "reasoningEffort" , value as ReasoningEffortWithMinimal )
256285 }
257- />
258- </ SelectTrigger >
259- < SelectContent >
260- { availableOptions . map ( ( value ) => (
261- < SelectItem key = { value } value = { value } >
262- { value === "none" || value === "disable"
263- ? t ( "settings:providers.reasoningEffort.none" )
264- : t ( `settings:providers.reasoningEffort.${ value } ` ) }
265- </ SelectItem >
266- ) ) }
267- </ SelectContent >
268- </ Select >
269- </ div >
270- ) : null
286+ } } >
287+ < SelectTrigger className = "w-full" >
288+ < SelectValue
289+ placeholder = {
290+ currentReasoningEffort
291+ ? currentReasoningEffort === "none" || currentReasoningEffort === "disable"
292+ ? t ( "settings:providers.reasoningEffort.none" )
293+ : t ( `settings:providers.reasoningEffort.${ currentReasoningEffort } ` )
294+ : t ( "settings:common.select" )
295+ }
296+ />
297+ </ SelectTrigger >
298+ < SelectContent >
299+ { availableOptions . map ( ( value ) => (
300+ < SelectItem key = { value } value = { value } >
301+ { value === "none" || value === "disable"
302+ ? t ( "settings:providers.reasoningEffort.none" )
303+ : t ( `settings:providers.reasoningEffort.${ value } ` ) }
304+ </ SelectItem >
305+ ) ) }
306+ </ SelectContent >
307+ </ Select >
308+ </ div >
309+ </ >
310+ ) : (
311+ maxOutputTokensControl
312+ )
271313}
0 commit comments