|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import { normalizeProviderSpecificConfig } from "./models-config.providers.policy.js"; |
3 | 3 | import type { ProviderConfig } from "./models-config.providers.secrets.js"; |
4 | 4 | |
| 5 | +vi.mock("../plugins/provider-runtime.js", () => { |
| 6 | +function normalizeGoogleModelIdForProvider(provider: string, modelId: string): string { |
| 7 | +if (provider === "google-antigravity") { |
| 8 | +return /^(gemini-3(?:[.-]1)?-pro)$/.test(modelId) ? `${modelId}-low` : modelId; |
| 9 | +} |
| 10 | +if (provider === "google-vertex" && modelId === "gemini-3.1-flash-lite") { |
| 11 | +return "gemini-3.1-flash-lite-preview"; |
| 12 | +} |
| 13 | +return modelId; |
| 14 | +} |
| 15 | + |
| 16 | +return { |
| 17 | +applyProviderNativeStreamingUsageCompatWithPlugin: () => undefined, |
| 18 | +normalizeProviderConfigWithPlugin: (params: { |
| 19 | +context: { provider: string; providerConfig?: ProviderConfig }; |
| 20 | +}) => { |
| 21 | +const providerConfig = params.context.providerConfig; |
| 22 | +if (!providerConfig?.models) { |
| 23 | +return undefined; |
| 24 | +} |
| 25 | +let changed = false; |
| 26 | +const models = providerConfig.models.map((model) => { |
| 27 | +const normalizedId = normalizeGoogleModelIdForProvider(params.context.provider, model.id); |
| 28 | +if (normalizedId === model.id) { |
| 29 | +return model; |
| 30 | +} |
| 31 | +changed = true; |
| 32 | +return { ...model, id: normalizedId, name: normalizedId }; |
| 33 | +}); |
| 34 | +return changed ? { ...providerConfig, models } : undefined; |
| 35 | +}, |
| 36 | +resolveProviderConfigApiKeyWithPlugin: () => undefined, |
| 37 | +}; |
| 38 | +}); |
| 39 | + |
5 | 40 | function buildModel(id: string): NonNullable<ProviderConfig["models"]>[number] { |
6 | 41 | return { |
7 | 42 | id, |
|