Skip to content

Commit 32b64ba

Browse files
committed
fix(bailian): initialize binary reasoning state, add null guard, fix comments (#420)(#421)
- webview-ui/src/components/settings/ThinkingBudget.tsx — add useEffect to initialize enableReasoningEffort for binary reasoning models so the checkbox reflects the API handler default (thinking enabled) - webview-ui/src/components/ui/hooks/useSelectedModel.ts — add null guard for bailianCustomModelInfo spread; document that custom models inherit supportsReasoningBinary from the default model fallback; replace Chinese comments with English
1 parent 8cc5b2f commit 32b64ba

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
140140
setApiConfigurationField,
141141
])
142142

143+
// Initialize enableReasoningEffort for binary reasoning models so the
144+
// checkbox reflects the API handler's default (thinking enabled).
145+
useEffect(() => {
146+
if (isReasoningSupported && apiConfiguration.enableReasoningEffort === undefined) {
147+
setApiConfigurationField("enableReasoningEffort", true, false)
148+
}
149+
}, [isReasoningSupported, apiConfiguration.enableReasoningEffort, setApiConfigurationField])
150+
143151
const enableReasoningEffort = apiConfiguration.enableReasoningEffort
144152
const customMaxOutputTokens = apiConfiguration.modelMaxTokens || DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS
145153
const customMaxThinkingTokens =

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
moonshotModels,
1111
minimaxModels,
1212
mimoModels,
13+
bailianModels,
14+
bailianDefaultModelId,
1315
geminiModels,
1416
mistralModels,
1517
openAiModelInfoSaneDefaults,
@@ -33,6 +35,7 @@ import {
3335
isDynamicProvider,
3436
isRetiredProvider,
3537
getProviderDefaultModelId,
38+
getBailianPrice,
3639
} from "@roo-code/types"
3740

3841
import { useRouterModels } from "./useRouterModels"
@@ -120,6 +123,40 @@ export const useSelectedModel = (apiConfiguration?: ProviderSettings) => {
120123
}
121124
}
122125

126+
/**
127+
* Per-provider pricing overrides.
128+
*
129+
* Each function receives (modelId, apiConfiguration) and returns a partial
130+
* ModelInfo whose price fields (inputPrice, outputPrice, cacheReadsPrice,
131+
* cacheWritesPrice) are merged OVER the static model definition.
132+
*
133+
* Add an entry here when a provider needs runtime-computed pricing (region-
134+
* specific, volume-tiered, etc.) that cannot be expressed in static model data.
135+
*/
136+
const PROVIDER_PRICING_FNS: Partial<
137+
Record<
138+
ProviderName,
139+
(modelId: string, config: ProviderSettings) => Partial<ModelInfo> | undefined
140+
>
141+
> = {
142+
bailian: (id, config) => {
143+
const region = (config.bailianRegion ?? "beijing") as Parameters<typeof getBailianPrice>[1]
144+
return getBailianPrice(id, region)
145+
},
146+
}
147+
148+
/** Apply per-provider pricing overrides on top of static baseInfo. */
149+
function resolveModelInfo(
150+
baseInfo: ModelInfo | undefined,
151+
provider: ProviderName,
152+
modelId: string,
153+
config: ProviderSettings,
154+
): ModelInfo | undefined {
155+
if (!baseInfo) return undefined
156+
const pricing = PROVIDER_PRICING_FNS[provider]?.(modelId, config)
157+
return pricing ? { ...baseInfo, ...pricing } : baseInfo
158+
}
159+
123160
function getSelectedModel({
124161
provider,
125162
apiConfiguration,
@@ -257,6 +294,22 @@ function getSelectedModel({
257294
const info = mimoModels[id as keyof typeof mimoModels] ?? mimoModels["mimo-v2.5-pro"]
258295
return { id, info }
259296
}
297+
case "bailian": {
298+
const id = apiConfiguration.apiModelId ?? defaultModelId
299+
const baseInfo = bailianModels[id as keyof typeof bailianModels]
300+
// Custom models: merge default model info with bailianCustomModelInfo,
301+
// matching the API handler's getModel() fallback.
302+
// Note: supportsReasoningBinary is inherited from the default model
303+
// (qwen3.6-plus). Custom models that do not support enable_thinking
304+
// should disable reasoning via the UI checkbox.
305+
const effectiveInfo = baseInfo
306+
?? {
307+
...bailianModels[defaultModelId as keyof typeof bailianModels],
308+
...(apiConfiguration.bailianCustomModelInfo || {}),
309+
}
310+
const info = resolveModelInfo(effectiveInfo, provider, id, apiConfiguration)
311+
return { id, info }
312+
}
260313
case "zai": {
261314
const isChina = apiConfiguration.zaiApiLine === "china_coding"
262315
const models = isChina ? mainlandZAiModels : internationalZAiModels

0 commit comments

Comments
 (0)