Skip to content

Commit 43d8693

Browse files
author
Zoo (VP)
committed
feat(webview): merge dynamic Gemini/Vertex catalogs into model picker
The generic model picker for gemini and vertex now merges the host-fetched router-models catalog over the static maps, so newly released models are selectable without an extension update. useSelectedModel validates the configured apiModelId against the merged set (router info preferred, static specs as fallback) while preserving the vertex 1M-context tier expansion; invalid IDs fall back to the provider default instead of passing through with undefined info. The automatic-fetch hint is suppressed for both providers like MiMo.
1 parent 3d4aed8 commit 43d8693

6 files changed

Lines changed: 422 additions & 66 deletions

File tree

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ export interface ApiOptionsProps {
115115
setErrorMessage: React.Dispatch<React.SetStateAction<string | undefined>>
116116
}
117117

118+
// Providers whose picker catalog merges the host-fetched dynamic model
119+
// catalog into the static fallback (fetched entries win), so models newer
120+
// than the shipped catalog are selectable without an extension update.
121+
const DYNAMIC_CATALOG_PROVIDERS = [providerIdentifiers.gemini, providerIdentifiers.vertex] as const
122+
123+
type DynamicCatalogProvider = (typeof DYNAMIC_CATALOG_PROVIDERS)[number]
124+
125+
const isDynamicCatalogProvider = (provider: ProviderName): provider is DynamicCatalogProvider =>
126+
(DYNAMIC_CATALOG_PROVIDERS as ReadonlyArray<ProviderName>).includes(provider)
127+
118128
const ApiOptions = ({
119129
uriScheme,
120130
apiConfiguration,
@@ -745,11 +755,22 @@ const ApiOptions = ({
745755
apiConfiguration={apiConfiguration}
746756
setApiConfigurationField={setApiConfigurationField}
747757
defaultModelId={getDefaultModelIdForProvider(activeSelectedProvider, apiConfiguration)}
748-
models={getStaticModelsForProvider(
749-
activeSelectedProvider,
750-
t("settings:labels.useCustomArn"),
751-
apiConfiguration,
752-
)}
758+
models={
759+
isDynamicCatalogProvider(activeSelectedProvider)
760+
? {
761+
...getStaticModelsForProvider(
762+
activeSelectedProvider,
763+
t("settings:labels.useCustomArn"),
764+
apiConfiguration,
765+
),
766+
...routerModels?.[activeSelectedProvider],
767+
}
768+
: getStaticModelsForProvider(
769+
activeSelectedProvider,
770+
t("settings:labels.useCustomArn"),
771+
apiConfiguration,
772+
)
773+
}
753774
modelIdKey="apiModelId"
754775
serviceName={getProviderServiceConfig(activeSelectedProvider).serviceName}
755776
serviceUrl={getProviderServiceConfig(activeSelectedProvider).serviceUrl}

‎webview-ui/src/components/settings/ModelPicker.tsx‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,25 @@ export const ModelPicker = ({
312312
hidePricing={hidePricing}
313313
/>
314314
)}
315-
{!hidePricing && apiConfiguration.apiProvider !== providerIdentifiers.mimo && (
316-
<div className="text-sm text-vscode-descriptionForeground" data-testid="automatic-fetch-hint">
317-
<Trans
318-
i18nKey="settings:modelPicker.automaticFetch"
319-
components={{
320-
serviceLink: <VSCodeLink href={serviceUrl} className="text-sm" />,
321-
defaultModelLink: (
322-
<VSCodeLink onClick={() => onSelect(defaultModelId)} className="text-sm" />
323-
),
324-
}}
325-
values={{ serviceName, defaultModelId }}
326-
/>
327-
</div>
328-
)}
315+
{!hidePricing &&
316+
apiConfiguration.apiProvider !== providerIdentifiers.mimo &&
317+
apiConfiguration.apiProvider !== providerIdentifiers.gemini &&
318+
apiConfiguration.apiProvider !== providerIdentifiers.vertex && (
319+
<div
320+
className="text-sm text-vscode-descriptionForeground"
321+
data-testid="automatic-fetch-hint">
322+
<Trans
323+
i18nKey="settings:modelPicker.automaticFetch"
324+
components={{
325+
serviceLink: <VSCodeLink href={serviceUrl} className="text-sm" />,
326+
defaultModelLink: (
327+
<VSCodeLink onClick={() => onSelect(defaultModelId)} className="text-sm" />
328+
),
329+
}}
330+
values={{ serviceName, defaultModelId }}
331+
/>
332+
</div>
333+
)}
329334
</div>
330335
)}
331336
</>

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

Lines changed: 135 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { screen } from "@testing-library/react"
22

33
import { renderWithExtensionState } from "@/utils/test-utils"
44

5-
import { providerIdentifiers, type ProviderSettings, type OrganizationAllowList } from "@roo-code/types"
5+
import {
6+
providerIdentifiers,
7+
geminiDefaultModelId,
8+
vertexDefaultModelId,
9+
type ModelInfo,
10+
type ProviderSettings,
11+
type OrganizationAllowList,
12+
} from "@roo-code/types"
613

714
import { useExtensionState } from "@src/context/ExtensionStateContext"
815
import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
@@ -11,13 +18,26 @@ import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel"
1118
import ApiOptions from "../ApiOptions"
1219
import { MODELS_BY_PROVIDER, PROVIDERS } from "../constants"
1320

14-
// Mock the extension state context
21+
// Mock the extension state context. The hoisted state holder lets the dynamic
22+
// catalog suite reset the allow list to the unfiltered default without
23+
// re-typing the full ExtensionStateContextType (previous suites pin
24+
// mockReturnValue via `as any`, and vi.clearAllMocks() does not undo that).
25+
const { useExtensionStateMock, setOrganizationAllowList } = vi.hoisted(() => {
26+
const mock = vi.fn(() => ({
27+
organizationAllowList: undefined as OrganizationAllowList | undefined,
28+
cloudIsAuthenticated: false,
29+
}))
30+
return {
31+
useExtensionStateMock: mock,
32+
setOrganizationAllowList: (list: OrganizationAllowList | undefined) => {
33+
mock.mockReturnValue({ organizationAllowList: list, cloudIsAuthenticated: false })
34+
},
35+
}
36+
})
37+
1538
vi.mock("@src/context/ExtensionStateContext", () => ({
1639
ExtensionStateContextProvider: ({ children }: any) => children,
17-
useExtensionState: vi.fn(() => ({
18-
organizationAllowList: undefined,
19-
cloudIsAuthenticated: false,
20-
})),
40+
useExtensionState: useExtensionStateMock,
2141
}))
2242

2343
// Mock the translation hook
@@ -34,12 +54,20 @@ vi.mock("@src/utils/vscode", () => ({
3454
},
3555
}))
3656

37-
// Mock the router models hook
57+
// Mock the router models hook. The hoisted state holder lets tests drive `data`
58+
// without re-typing the full react-query UseQueryResult at each call site.
59+
const { useRouterModelsMock, setRouterModelsData } = vi.hoisted(() => {
60+
const state = { data: undefined as Record<string, Record<string, unknown>> | undefined }
61+
return {
62+
useRouterModelsMock: vi.fn(() => ({ data: state.data, refetch: vi.fn() })),
63+
setRouterModelsData: (data: typeof state.data) => {
64+
state.data = data
65+
},
66+
}
67+
})
68+
3869
vi.mock("@src/components/ui/hooks/useRouterModels", () => ({
39-
useRouterModels: vi.fn(() => ({
40-
data: null,
41-
refetch: vi.fn(),
42-
})),
70+
useRouterModels: useRouterModelsMock,
4371
}))
4472

4573
// Mock the selected model hook
@@ -147,6 +175,29 @@ describe("ApiOptions Provider Filtering", () => {
147175
expect(useRouterModels).toHaveBeenCalledWith({ enabled: true, provider: providerIdentifiers.kenari })
148176
})
149177

178+
it.each([providerIdentifiers.gemini, providerIdentifiers.vertex])(
179+
"requests router models for the dynamic catalog provider %s",
180+
(provider) => {
181+
vi.mocked(useSelectedModel).mockReturnValue({
182+
provider,
183+
id: "model",
184+
info: undefined,
185+
isLoading: false,
186+
isError: false,
187+
})
188+
189+
renderWithProviders({
190+
...defaultProps,
191+
apiConfiguration: { apiProvider: provider } as ProviderSettings,
192+
})
193+
194+
// Both the automatic fetch gate and the readiness gate in useSelectedModel
195+
// key off isDynamicProvider, so no wiring change is needed here; this pins
196+
// the gating now that these providers are dynamic.
197+
expect(useRouterModels).toHaveBeenCalledWith({ enabled: true, provider })
198+
},
199+
)
200+
150201
it.each([providerIdentifiers.ollama, providerIdentifiers.lmstudio])(
151202
"does not make an aggregate router request for local provider %s",
152203
(provider) => {
@@ -343,4 +394,77 @@ describe("ApiOptions Provider Filtering", () => {
343394
delete (MODELS_BY_PROVIDER as any).testEmptyProvider
344395
PROVIDERS.pop()
345396
})
397+
398+
describe.each([
399+
[providerIdentifiers.gemini, geminiDefaultModelId],
400+
[providerIdentifiers.vertex, vertexDefaultModelId],
401+
] as const)("dynamic model catalog (ApiOptions -> ModelPicker wiring) for %s", (provider, defaultModelId) => {
402+
// Regression guard: the generic ModelPicker must receive the host-fetched router
403+
// catalog for this provider merged on top of the static MODELS_BY_PROVIDER fallback
404+
// in ApiOptions. ModelPicker itself performs no router merging, so if the merge in
405+
// ApiOptions regressed to static-only, router-only models newer than the shipped
406+
// catalog would silently become unselectable and no other suite would catch it.
407+
const routerOnlyModelId = `${provider}-router-only-preview`
408+
409+
const routerOnlyModelInfo: ModelInfo = {
410+
maxTokens: 131_072,
411+
contextWindow: 262_144,
412+
supportsPromptCache: false,
413+
}
414+
415+
const renderWithProviderSelected = (routerData: Record<string, Record<string, ModelInfo>> | undefined) => {
416+
// Earlier allow-list suites leave a restrictive organizationAllowList on this
417+
// mock (clearAllMocks keeps mockReturnValue); reset to the unfiltered default
418+
// so the catalog reaches the picker in full.
419+
setOrganizationAllowList(undefined)
420+
setRouterModelsData(routerData)
421+
vi.mocked(useSelectedModel).mockReturnValue({
422+
provider,
423+
id: defaultModelId,
424+
info: undefined,
425+
isLoading: false,
426+
isError: false,
427+
})
428+
429+
return renderWithProviders({
430+
...defaultProps,
431+
apiConfiguration: {
432+
apiProvider: provider,
433+
apiModelId: defaultModelId,
434+
} as ProviderSettings,
435+
})
436+
}
437+
438+
afterEach(() => {
439+
// Restore the default (no fetched models) for any suites that run later.
440+
setRouterModelsData(undefined)
441+
})
442+
443+
it("passes both static and router-fetched models to the generic ModelPicker", () => {
444+
// The router payload contains ONLY a model id that does not exist in the
445+
// shipped static catalog; it can reach the picker solely via the merge.
446+
renderWithProviderSelected({ [provider]: { [routerOnlyModelId]: routerOnlyModelInfo } })
447+
448+
// Static default from getStaticModelsForProvider(provider) / MODELS_BY_PROVIDER.
449+
expect(screen.getByTestId(`model-option-${defaultModelId}`)).toBeInTheDocument()
450+
// Router-only model: present in the picker only if ApiOptions merged routerModels[provider].
451+
expect(screen.getByTestId(`model-option-${routerOnlyModelId}`)).toBeInTheDocument()
452+
})
453+
454+
it("keeps the static catalog selectable when no router models are available", () => {
455+
// useRouterModels data is undefined while the fetch is pending/failed; the
456+
// spread of routerModels?.[provider] must not crash or drop the static defaults.
457+
renderWithProviderSelected(undefined)
458+
459+
expect(screen.getByTestId(`model-option-${defaultModelId}`)).toBeInTheDocument()
460+
expect(screen.queryByTestId(`model-option-${routerOnlyModelId}`)).not.toBeInTheDocument()
461+
})
462+
463+
it("keeps the static catalog selectable when the router catalog is empty", () => {
464+
renderWithProviderSelected({})
465+
466+
expect(screen.getByTestId(`model-option-${defaultModelId}`)).toBeInTheDocument()
467+
expect(screen.queryByTestId(`model-option-${routerOnlyModelId}`)).not.toBeInTheDocument()
468+
})
469+
})
346470
})

‎webview-ui/src/components/settings/__tests__/ModelPicker.spec.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ describe("ModelPicker", () => {
268268
expect(screen.queryByTestId("automatic-fetch-hint")).not.toBeInTheDocument()
269269
})
270270

271+
it.each([providerIdentifiers.gemini, providerIdentifiers.vertex])(
272+
"hides the automatic fetch hint for %s provider",
273+
async (provider) => {
274+
await act(async () => {
275+
renderWithExtensionState(
276+
<ModelPicker {...defaultProps} apiConfiguration={{ apiProvider: provider }} />,
277+
{ queryClient },
278+
)
279+
})
280+
281+
expect(screen.queryByTestId("automatic-fetch-hint")).not.toBeInTheDocument()
282+
},
283+
)
284+
271285
it("shows the automatic fetch hint for non-MiMo providers", async () => {
272286
await act(async () => {
273287
renderWithExtensionState(

0 commit comments

Comments
 (0)