Skip to content

Commit bedd9a7

Browse files
committed
fix(webview): show sane defaults for custom OpenAI-compatible models
Custom model IDs for Fireworks, Baseten and SambaNova resolved to undefined model info in the webview, so the task header fell back to a context window of 1. Mirror the backend BaseOpenAiCompatibleProvider getModel(): honor the configured custom ID with openAiModelInfoSaneDefaults, use catalog metadata for known models, and fall back to the provider default only when no model is configured.
1 parent 8bec7c1 commit bedd9a7

2 files changed

Lines changed: 69 additions & 15 deletions

File tree

‎webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
minimaxModels,
2525
friendliDefaultModelId,
2626
friendliModels,
27+
fireworksDefaultModelId,
28+
fireworksModels,
2729
deepSeekDefaultModelId,
2830
deepSeekModels,
2931
openRouterDefaultModelId,
@@ -1372,6 +1374,49 @@ describe("useSelectedModel", () => {
13721374
})
13731375
})
13741376

1377+
describe("OpenAI-compatible static catalog providers (fireworks, baseten, sambanova)", () => {
1378+
beforeEach(() => {
1379+
mockUseRouterModels.mockReturnValue(createRouterModelsResult({ openrouter: {}, requesty: {}, litellm: {} }))
1380+
mockUseOpenRouterModelProviders.mockReturnValue(createOpenRouterModelProvidersResult({}))
1381+
})
1382+
1383+
it("returns the default Fireworks model when no model is configured", () => {
1384+
const { result } = renderHook(() => useSelectedModel({ apiProvider: providerIdentifiers.fireworks }), {
1385+
wrapper: createWrapper(),
1386+
})
1387+
1388+
expect(result.current.id).toBe(fireworksDefaultModelId)
1389+
expect(result.current.info).toEqual(fireworksModels[fireworksDefaultModelId])
1390+
})
1391+
1392+
it("returns known Fireworks model metadata", () => {
1393+
const id = "accounts/fireworks/models/kimi-k2-instruct"
1394+
const { result } = renderHook(
1395+
() => useSelectedModel({ apiProvider: providerIdentifiers.fireworks, apiModelId: id }),
1396+
{ wrapper: createWrapper() },
1397+
)
1398+
1399+
expect(result.current.id).toBe(id)
1400+
expect(result.current.info).toEqual(fireworksModels[id])
1401+
})
1402+
1403+
it.each([providerIdentifiers.fireworks, providerIdentifiers.baseten, providerIdentifiers.sambanova])(
1404+
"honors a custom %s model ID with sane default metadata (not undefined info)",
1405+
(apiProvider) => {
1406+
// Regression: custom models had undefined info, so the task header fell back to a
1407+
// context window of 1. The backend uses openAiModelInfoSaneDefaults, so the UI must too.
1408+
const { result } = renderHook(
1409+
() => useSelectedModel({ apiProvider, apiModelId: "some/custom-model-not-in-list" }),
1410+
{ wrapper: createWrapper() },
1411+
)
1412+
1413+
expect(result.current.id).toBe("some/custom-model-not-in-list")
1414+
expect(result.current.info).toEqual(openAiModelInfoSaneDefaults)
1415+
expect(result.current.info?.contextWindow).toBeGreaterThan(1)
1416+
},
1417+
)
1418+
})
1419+
13751420
describe("Z AI provider", () => {
13761421
it("uses the International Coding catalog when no API line is configured", () => {
13771422
const apiConfiguration: ProviderSettings = {

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ function getValidatedModelId(
5757
return configuredId && availableModels?.[configuredId] ? configuredId : defaultModelId
5858
}
5959

60+
/**
61+
* Resolves a static-catalog model for providers backed by `BaseOpenAiCompatibleProvider`
62+
* (Fireworks, Baseten, SambaNova). Mirrors the backend `getModel()`: a user-supplied custom
63+
* model ID that isn't in the static list is honored with `openAiModelInfoSaneDefaults`, so the
64+
* UI shows sensible limits (e.g. context window) instead of treating the selection as unknown.
65+
*/
66+
function getStaticCatalogModel(
67+
configuredId: string | undefined,
68+
models: Record<string, ModelInfo>,
69+
defaultModelId: string,
70+
): { id: string; info: ModelInfo | undefined } {
71+
if (configuredId && !(configuredId in models)) {
72+
return { id: configuredId, info: { ...openAiModelInfoSaneDefaults } }
73+
}
74+
const id = configuredId ?? defaultModelId
75+
return { id, info: models[id] }
76+
}
77+
6078
/**
6179
* Resolves the model currently selected for the active API provider.
6280
*
@@ -230,11 +248,8 @@ function getSelectedModel({
230248
const info = xaiModels[id as keyof typeof xaiModels]
231249
return info ? { id, info } : { id, info: undefined }
232250
}
233-
case providerIdentifiers.baseten: {
234-
const id = apiConfiguration.apiModelId ?? defaultModelId
235-
const info = basetenModels[id as keyof typeof basetenModels]
236-
return { id, info }
237-
}
251+
case providerIdentifiers.baseten:
252+
return getStaticCatalogModel(apiConfiguration.apiModelId, basetenModels, defaultModelId)
238253
case providerIdentifiers.bedrock: {
239254
const id = apiConfiguration.apiModelId ?? defaultModelId
240255
const baseInfo = bedrockModels[id as keyof typeof bedrockModels]
@@ -390,16 +405,10 @@ function getSelectedModel({
390405
}
391406
return { id, info }
392407
}
393-
case providerIdentifiers.sambanova: {
394-
const id = apiConfiguration.apiModelId ?? defaultModelId
395-
const info = sambaNovaModels[id as keyof typeof sambaNovaModels]
396-
return { id, info }
397-
}
398-
case providerIdentifiers.fireworks: {
399-
const id = apiConfiguration.apiModelId ?? defaultModelId
400-
const info = fireworksModels[id as keyof typeof fireworksModels]
401-
return { id, info }
402-
}
408+
case providerIdentifiers.sambanova:
409+
return getStaticCatalogModel(apiConfiguration.apiModelId, sambaNovaModels, defaultModelId)
410+
case providerIdentifiers.fireworks:
411+
return getStaticCatalogModel(apiConfiguration.apiModelId, fireworksModels, defaultModelId)
403412
case providerIdentifiers.friendli: {
404413
const id = apiConfiguration.apiModelId ?? defaultModelId
405414
const info = friendliModels[id as keyof typeof friendliModels]

0 commit comments

Comments
 (0)