Skip to content

Commit f3c8191

Browse files
committed
Merge upstream/main into feat/ionet-provider
2 parents 44739b6 + 839fd6c commit f3c8191

46 files changed

Lines changed: 1773 additions & 753 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/api/__tests__/index.spec.ts‎

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,42 @@ vitest.mock("vscode", () => ({
99
},
1010
}))
1111

12-
// Handler constructors can require credentials or initialize SDK clients. Replace them
13-
// with inert classes so these tests exercise only the factory's routing behavior.
12+
// Replace handlers with inert classes (no-op constructors) that keep the real prototype
13+
// chain, so tests exercise routing and can still inspect methods such as fetchModels.
14+
const { inertClass } = vitest.hoisted(() => ({
15+
inertClass: (actual: unknown): unknown => {
16+
if (typeof actual !== "function" || !actual.prototype) {
17+
return actual
18+
}
19+
const Inert = class {}
20+
Object.setPrototypeOf(Inert.prototype, actual.prototype)
21+
return Inert
22+
},
23+
}))
24+
1425
vitest.mock("../providers", async () => {
1526
const providers = await vitest.importActual<Record<string, unknown>>("../providers")
1627

17-
return Object.fromEntries(Object.keys(providers).map((name) => [name, class {}]))
28+
return Object.fromEntries(Object.entries(providers).map(([name, actual]) => [name, inertClass(actual)]))
1829
})
1930

20-
vitest.mock("../providers/native-ollama", () => ({
21-
NativeOllamaHandler: class {},
22-
}))
31+
vitest.mock("../providers/native-ollama", async () => {
32+
const actual = await vitest.importActual<typeof import("../providers/native-ollama")>("../providers/native-ollama")
33+
34+
return { NativeOllamaHandler: inertClass(actual.NativeOllamaHandler) }
35+
})
2336

2437
import {
38+
dynamicProviders,
39+
localProviders,
2540
providerIdentifiers,
2641
retiredProviderIdentifiers,
2742
type ProviderName,
2843
type ProviderNameWithRetired,
2944
} from "@roo-code/types"
3045

46+
import type { RouterName } from "../../shared/api"
47+
3148
import { buildApiHandler } from "../index"
3249
import {
3350
AnthropicHandler,
@@ -157,3 +174,29 @@ describe("buildApiHandler", () => {
157174
expect(handler).toBeInstanceOf(AnthropicHandler)
158175
})
159176
})
177+
178+
// fetchModels is optional on ApiHandler, so this replaces the old fetcher switch's
179+
// exhaustiveness check: every RouterName must build a handler that implements it.
180+
describe("buildApiHandler model catalog coverage", () => {
181+
const routerNames: RouterName[] = [...dynamicProviders, ...localProviders]
182+
183+
it("covers at least one router", () => {
184+
expect(routerNames.length).toBeGreaterThan(0)
185+
})
186+
187+
it.each(routerNames)("returns a handler implementing fetchModels for %s", (apiProvider) => {
188+
const handler = buildApiHandler({ apiProvider })
189+
190+
expect(handler).not.toBeInstanceOf(AnthropicHandler)
191+
expect(typeof handler.fetchModels).toBe("function")
192+
expect(typeof handler.getModelCacheScope).toBe("function")
193+
})
194+
195+
it("does not expose fetchModels on the default fallback handler", () => {
196+
const handler = buildApiHandler({
197+
apiProvider: "unsupported-provider" as ProviderNameWithRetired,
198+
})
199+
200+
expect(handler.fetchModels).toBeUndefined()
201+
})
202+
})

‎src/api/index.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {
77
retiredProviderIdentifiers,
88
type ProviderSettings,
99
type ModelInfo,
10+
type ModelRecord,
1011
} from "@roo-code/types"
1112

1213
import { getRouterRemovalMessage } from "../core/config/routerRemoval"
14+
import type { GetModelsOptions } from "../shared/api"
1315
import { ApiStream } from "./transform/stream"
1416

1517
import {
@@ -118,6 +120,18 @@ export interface ApiHandlerCreateMessageMetadata {
118120
abortSignal?: AbortSignal
119121
}
120122

123+
/**
124+
* Describes how the model cache must key and persist a provider's catalog.
125+
*/
126+
export interface ModelCacheScope {
127+
/** Cache key must include the normalized baseUrl. */
128+
urlScoped: boolean
129+
/** Cache key must include a short, irreversible API-key discriminator. */
130+
keyScoped: boolean
131+
/** Never persist to disk/memory; results are per signed-in user. */
132+
authScoped: boolean
133+
}
134+
121135
export interface ApiHandler {
122136
createMessage(
123137
systemPrompt: string,
@@ -157,6 +171,18 @@ export interface ApiHandler {
157171
* @returns A promise resolving to the token count
158172
*/
159173
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number>
174+
175+
/**
176+
* Fetch this provider's live model catalog. Only dynamic-catalog providers
177+
* implement it; others leave it undefined and the model cache rejects.
178+
*/
179+
fetchModels?(options: GetModelsOptions, signal?: AbortSignal): Promise<ModelRecord>
180+
181+
/**
182+
* How the model cache must key and persist this provider's catalog.
183+
* Defaults to all-false in BaseProvider.
184+
*/
185+
getModelCacheScope(): ModelCacheScope
160186
}
161187

162188
export function buildApiHandler(configuration: ProviderSettings): ApiHandler {

‎src/api/providers/__tests__/kenari.spec.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ vitest.mock("../fetchers/modelCache", () => ({
3434
},
3535
}),
3636
),
37-
refreshModels: vitest.fn(async (options) => {
37+
refreshModels: vitest.fn(async (options, handler) => {
3838
const { getModels } = await import("../fetchers/modelCache")
39-
return getModels(options)
39+
return getModels(options, handler)
4040
}),
4141
getModelsFromCache: vitest.fn().mockReturnValue(undefined),
4242
}))
@@ -371,4 +371,11 @@ describe("KenariHandler", () => {
371371
expect("temperature" in callArgs).toBe(false)
372372
})
373373
})
374+
375+
describe("model catalog", () => {
376+
it("reports its cache scope", () => {
377+
const handler = new KenariHandler(mockOptions)
378+
expect(handler.getModelCacheScope()).toEqual({ urlScoped: false, keyScoped: false, authScoped: false })
379+
})
380+
})
374381
})

‎src/api/providers/__tests__/lite-llm.spec.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ vi.mock("../fetchers/modelCache", () => ({
6868
"vertex_ai/gemini-3-pro": { ...litellmDefaultModelInfo, maxTokens: 8192 },
6969
})
7070
}),
71-
refreshModels: vi.fn(async (options) => {
71+
refreshModels: vi.fn(async (options, handler) => {
7272
const { getModels } = await import("../fetchers/modelCache")
73-
return getModels(options)
73+
return getModels(options, handler)
7474
}),
7575
getModelsFromCache: vi.fn().mockReturnValue(undefined),
7676
}))
@@ -1380,4 +1380,11 @@ describe("LiteLLMHandler", () => {
13801380
expect(requestHeaders).not.toHaveProperty("X-Zoo-Session-ID")
13811381
})
13821382
})
1383+
1384+
describe("model catalog", () => {
1385+
it("reports its cache scope", () => {
1386+
const handler = new LiteLLMHandler(mockOptions)
1387+
expect(handler.getModelCacheScope()).toEqual({ urlScoped: true, keyScoped: true, authScoped: false })
1388+
})
1389+
})
13831390
})

0 commit comments

Comments
 (0)