Feat/gemini 3.8 flash 3.5 flash lite (#29443)

This commit is contained in:
David Pierce
2026-09-22 21:52:46 +00:00
committed by GitHub
parent d5b3e3accb
commit 62364cb200
40 changed files with 1346 additions and 349 deletions
+88 -25
View File
@@ -672,12 +672,24 @@ their corresponding top-level category object in your `settings.json` file.
"model": "gemini-3.1-flash-lite" "model": "gemini-3.1-flash-lite"
} }
}, },
"gemini-3.5-flash-lite": {
"extends": "chat-base-3",
"modelConfig": {
"model": "gemini-3.5-flash-lite"
}
},
"gemini-3.5-flash": { "gemini-3.5-flash": {
"extends": "chat-base-3", "extends": "chat-base-3",
"modelConfig": { "modelConfig": {
"model": "gemini-3.5-flash" "model": "gemini-3.5-flash"
} }
}, },
"gemini-3.8-flash": {
"extends": "chat-base-3",
"modelConfig": {
"model": "gemini-3.8-flash"
}
},
"gemma-4-31b-it": { "gemma-4-31b-it": {
"extends": "chat-base-3", "extends": "chat-base-3",
"modelConfig": { "modelConfig": {
@@ -914,6 +926,16 @@ their corresponding top-level category object in your `settings.json` file.
"multimodalToolUse": true "multimodalToolUse": true
} }
}, },
"gemini-3.5-flash-lite": {
"tier": "flash-lite",
"family": "gemini-3",
"isPreview": false,
"isVisible": true,
"features": {
"thinking": false,
"multimodalToolUse": true
}
},
"gemini-3.1-pro-preview": { "gemini-3.1-pro-preview": {
"tier": "pro", "tier": "pro",
"family": "gemini-3", "family": "gemini-3",
@@ -964,6 +986,16 @@ their corresponding top-level category object in your `settings.json` file.
"multimodalToolUse": true "multimodalToolUse": true
} }
}, },
"gemini-3.8-flash": {
"tier": "flash",
"family": "gemini-3",
"isPreview": false,
"isVisible": true,
"features": {
"thinking": false,
"multimodalToolUse": true
}
},
"gemini-2.5-pro": { "gemini-2.5-pro": {
"tier": "pro", "tier": "pro",
"family": "gemini-2.5", "family": "gemini-2.5",
@@ -1118,16 +1150,16 @@ their corresponding top-level category object in your `settings.json` file.
{ {
"condition": { "condition": {
"hasAccessToPreview": false, "hasAccessToPreview": false,
"useGemini3_5Flash": true "useLatestFlash": true
}, },
"target": "gemini-3.5-flash" "target": "gemini-3.8-flash"
}, },
{ {
"condition": { "condition": {
"hasAccessToPreview": false, "hasAccessToPreview": false,
"useGemini3_5Flash": false "useLatestFlash": false
}, },
"target": "gemini-2.5-flash" "target": "gemini-3.5-flash"
} }
] ]
}, },
@@ -1136,16 +1168,20 @@ their corresponding top-level category object in your `settings.json` file.
"contexts": [ "contexts": [
{ {
"condition": { "condition": {
"useGemini3_5Flash": false, "useLatestFlash": true
"hasAccessToPreview": false
}, },
"target": "gemini-2.5-flash" "target": "gemini-3.8-flash"
}, }
]
},
"gemini-3.8-flash": {
"default": "gemini-3.8-flash",
"contexts": [
{ {
"condition": { "condition": {
"useGemini3_5Flash": false "useLatestFlash": false
}, },
"target": "gemini-3-flash-preview" "target": "gemini-3.5-flash"
} }
] ]
}, },
@@ -1154,9 +1190,9 @@ their corresponding top-level category object in your `settings.json` file.
"contexts": [ "contexts": [
{ {
"condition": { "condition": {
"useGemini3_5Flash": true "useLatestFlash": true
}, },
"target": "gemini-3.5-flash" "target": "gemini-3.8-flash"
} }
] ]
}, },
@@ -1233,27 +1269,54 @@ their corresponding top-level category object in your `settings.json` file.
] ]
}, },
"gemini-3.1-flash-lite": { "gemini-3.1-flash-lite": {
"default": "gemini-3.1-flash-lite" "default": "gemini-3.1-flash-lite",
"contexts": [
{
"condition": {
"useLatestFlashLite": true
},
"target": "gemini-3.5-flash-lite"
}
]
},
"gemini-3.5-flash-lite": {
"default": "gemini-3.5-flash-lite",
"contexts": [
{
"condition": {
"useLatestFlashLite": false
},
"target": "gemini-3.1-flash-lite"
}
]
}, },
"flash": { "flash": {
"default": "gemini-3-flash-preview", "default": "gemini-3-flash-preview",
"contexts": [ "contexts": [
{ {
"condition": { "condition": {
"useGemini3_5Flash": true "useLatestFlash": true
}, },
"target": "gemini-3.5-flash" "target": "gemini-3.8-flash"
}, },
{ {
"condition": { "condition": {
"hasAccessToPreview": false "hasAccessToPreview": false
}, },
"target": "gemini-2.5-flash" "target": "gemini-3.5-flash"
} }
] ]
}, },
"flash-lite": { "flash-lite": {
"default": "gemini-3.1-flash-lite" "default": "gemini-3.1-flash-lite",
"contexts": [
{
"condition": {
"useLatestFlashLite": true
},
"target": "gemini-3.5-flash-lite"
}
]
}, },
"auto-gemini-3": { "auto-gemini-3": {
"default": "gemini-3-pro-preview", "default": "gemini-3-pro-preview",
@@ -1300,21 +1363,21 @@ their corresponding top-level category object in your `settings.json` file.
"contexts": [ "contexts": [
{ {
"condition": { "condition": {
"useGemini3_5Flash": true "useLatestFlash": true
}, },
"target": "gemini-3.5-flash" "target": "gemini-3.8-flash"
}, },
{ {
"condition": { "condition": {
"hasAccessToPreview": false "hasAccessToPreview": false
}, },
"target": "gemini-2.5-flash" "target": "gemini-3.5-flash"
}, },
{ {
"condition": { "condition": {
"requestedModels": ["gemini-2.5-pro", "auto-gemini-2.5"] "requestedModels": ["gemini-2.5-pro", "auto-gemini-2.5"]
}, },
"target": "gemini-2.5-flash" "target": "gemini-3.5-flash"
} }
] ]
}, },
@@ -1447,7 +1510,7 @@ their corresponding top-level category object in your `settings.json` file.
} }
}, },
{ {
"model": "gemini-2.5-flash", "model": "gemini-3.5-flash",
"isLastResort": true, "isLastResort": true,
"maxAttempts": 10, "maxAttempts": 10,
"actions": { "actions": {
@@ -1482,7 +1545,7 @@ their corresponding top-level category object in your `settings.json` file.
} }
}, },
{ {
"model": "gemini-2.5-flash", "model": "gemini-3.5-flash",
"isLastResort": true, "isLastResort": true,
"maxAttempts": 10, "maxAttempts": 10,
"actions": { "actions": {
@@ -1501,7 +1564,7 @@ their corresponding top-level category object in your `settings.json` file.
], ],
"lite": [ "lite": [
{ {
"model": "flash-lite", "model": "gemini-3.1-flash-lite",
"actions": { "actions": {
"terminal": "silent", "terminal": "silent",
"transient": "silent", "transient": "silent",
@@ -1516,7 +1579,7 @@ their corresponding top-level category object in your `settings.json` file.
} }
}, },
{ {
"model": "gemini-2.5-flash", "model": "gemini-3.5-flash",
"actions": { "actions": {
"terminal": "silent", "terminal": "silent",
"transient": "silent", "transient": "silent",
+5 -3
View File
@@ -265,7 +265,8 @@ export function buildAvailableModels(
const preferredModel = config.getModel() || GEMINI_MODEL_ALIAS_AUTO; const preferredModel = config.getModel() || GEMINI_MODEL_ALIAS_AUTO;
const shouldShowPreviewModels = config.getHasAccessToPreviewModel(); const shouldShowPreviewModels = config.getHasAccessToPreviewModel();
const useGemini31 = config.getGemini31LaunchedSync?.() ?? false; const useGemini31 = config.getGemini31LaunchedSync?.() ?? false;
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
const selectedAuthType = settings.merged.security.auth.selectedType; const selectedAuthType = settings.merged.security.auth.selectedType;
const useCustomToolModel = const useCustomToolModel =
useGemini31 && selectedAuthType === AuthType.USE_GEMINI; useGemini31 && selectedAuthType === AuthType.USE_GEMINI;
@@ -277,7 +278,8 @@ export function buildAvailableModels(
) { ) {
const options = config.getModelConfigService().getAvailableModelOptions({ const options = config.getModelConfigService().getAvailableModelOptions({
useGemini3_1: useGemini31, useGemini3_1: useGemini31,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
hasAccessToPreview: shouldShowPreviewModels, hasAccessToPreview: shouldShowPreviewModels,
}); });
@@ -296,7 +298,7 @@ export function buildAvailableModels(
description: getAutoModelDescription( description: getAutoModelDescription(
shouldShowPreviewModels, shouldShowPreviewModels,
useGemini31, useGemini31,
useGemini3_5Flash, useLatestFlash,
), ),
}, },
]; ];
+19 -1
View File
@@ -3524,7 +3524,24 @@ export const SETTINGS_SCHEMA_DEFINITIONS: Record<
type: 'object', type: 'object',
properties: { properties: {
useGemini3_1: { type: 'boolean' }, useGemini3_1: { type: 'boolean' },
useGemini3_1FlashLite: { type: 'boolean' }, useLatestFlash: {
type: 'boolean',
description:
'Whether the latest GA Flash model (Gemini 3.8 Flash) is launched and active.',
},
useLatestFlashLite: {
type: 'boolean',
description:
'Whether the latest GA Flash Lite model (Gemini 3.5 Flash Lite) is launched and active.',
},
useGemini3_5Flash: {
type: 'boolean',
description: 'Deprecated alias for useLatestFlash.',
},
useGemini3_1FlashLite: {
type: 'boolean',
description: 'Deprecated alias for useLatestFlashLite.',
},
useCustomTools: { type: 'boolean' }, useCustomTools: { type: 'boolean' },
hasAccessToPreview: { type: 'boolean' }, hasAccessToPreview: { type: 'boolean' },
requestedModels: { requestedModels: {
@@ -3533,6 +3550,7 @@ export const SETTINGS_SCHEMA_DEFINITIONS: Record<
}, },
}, },
}, },
target: { type: 'string' }, target: { type: 'string' },
}, },
}, },
+11 -6
View File
@@ -67,7 +67,8 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
const shouldShowPreviewModels = config?.getHasAccessToPreviewModel() ?? false; const shouldShowPreviewModels = config?.getHasAccessToPreviewModel() ?? false;
const useGemini31 = config?.getGemini31LaunchedSync?.() ?? false; const useGemini31 = config?.getGemini31LaunchedSync?.() ?? false;
const useGemini3_5Flash = config?.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config?.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config?.hasLatestFlashLiteGAAccess?.() ?? false;
const selectedAuthType = settings.merged.security.auth.selectedType; const selectedAuthType = settings.merged.security.auth.selectedType;
const useCustomToolModel = const useCustomToolModel =
useGemini31 && selectedAuthType === AuthType.USE_GEMINI; useGemini31 && selectedAuthType === AuthType.USE_GEMINI;
@@ -130,7 +131,8 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
.getModelConfigService() .getModelConfigService()
.getAvailableModelOptions({ .getAvailableModelOptions({
useGemini3_1: useGemini31, useGemini3_1: useGemini31,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
hasAccessToPreview: shouldShowPreviewModels, hasAccessToPreview: shouldShowPreviewModels,
hasAccessToProModel, hasAccessToProModel,
@@ -164,7 +166,7 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
description: getAutoModelDescription( description: getAutoModelDescription(
shouldShowPreviewModels, shouldShowPreviewModels,
useGemini31, useGemini31,
useGemini3_5Flash, useLatestFlash,
), ),
key: GEMINI_MODEL_ALIAS_AUTO, key: GEMINI_MODEL_ALIAS_AUTO,
}, },
@@ -184,7 +186,8 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
shouldShowPreviewModels, shouldShowPreviewModels,
manualModelSelected, manualModelSelected,
useGemini31, useGemini31,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
useCustomToolModel, useCustomToolModel,
hasAccessToProModel, hasAccessToProModel,
]); ]);
@@ -199,7 +202,8 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
.getModelConfigService() .getModelConfigService()
.getAvailableModelOptions({ .getAvailableModelOptions({
useGemini3_1: useGemini31, useGemini3_1: useGemini31,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
hasAccessToPreview: shouldShowPreviewModels, hasAccessToPreview: shouldShowPreviewModels,
hasAccessToProModel, hasAccessToProModel,
@@ -292,7 +296,8 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
}, [ }, [
shouldShowPreviewModels, shouldShowPreviewModels,
useGemini31, useGemini31,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
useCustomToolModel, useCustomToolModel,
hasAccessToProModel, hasAccessToProModel,
config, config,
@@ -55,6 +55,7 @@ import {
getPlanModeExitMessage, getPlanModeExitMessage,
UPDATE_TOPIC_TOOL_NAME, UPDATE_TOPIC_TOOL_NAME,
TRUE_EMPTY_RESPONSE_MESSAGE, TRUE_EMPTY_RESPONSE_MESSAGE,
DEFAULT_GEMINI_FLASH_MODEL,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import type { Part, PartListUnion } from '@google/genai'; import type { Part, PartListUnion } from '@google/genai';
import type { UseHistoryManagerReturn } from './useHistoryManager.js'; import type { UseHistoryManagerReturn } from './useHistoryManager.js';
@@ -2645,7 +2646,7 @@ describe('useGeminiStream', () => {
mockAuthType, mockAuthType,
undefined, undefined,
'gemini-2.5-pro', 'gemini-2.5-pro',
'gemini-2.5-flash', DEFAULT_GEMINI_FLASH_MODEL,
); );
}); });
}); });
@@ -3882,7 +3883,7 @@ describe('useGeminiStream', () => {
expect.any(String), expect.any(String),
undefined, undefined,
'gemini-2.5-pro', 'gemini-2.5-pro',
'gemini-2.5-flash', DEFAULT_GEMINI_FLASH_MODEL,
); );
}); });
@@ -1245,7 +1245,7 @@ describe('useQuotaAndFallback', () => {
const lastCall = (mockHistoryManager.addItem as Mock).mock.calls[0][0]; const lastCall = (mockHistoryManager.addItem as Mock).mock.calls[0][0];
expect(lastCall.type).toBe(MessageType.INFO); expect(lastCall.type).toBe(MessageType.INFO);
expect(lastCall.text).toContain( expect(lastCall.text).toContain(
`Switched to fallback model gemini-2.5-flash`, `Switched to fallback model ${DEFAULT_GEMINI_FLASH_MODEL}`,
); );
}); });
}); });
@@ -13,12 +13,15 @@ import {
PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
resetModelsForTesting,
} from '../config/models.js'; } from '../config/models.js';
import fs from 'node:fs'; import fs from 'node:fs';
import { AuthType } from '../core/contentGenerator.js'; import { AuthType } from '../core/contentGenerator.js';
import type { FallbackIntent } from '../fallback/types.js'; import type { FallbackIntent } from '../fallback/types.js';
import { LlmRole } from '../telemetry/types.js'; import { LlmRole } from '../telemetry/types.js';
import type { GenerateContentResponse } from '@google/genai'; import type { GenerateContentResponse } from '@google/genai';
import { normalizeModelId } from '../utils/modelUtils.js';
import { ExperimentFlags } from '../code_assist/experiments/flagNames.js';
vi.mock('node:fs'); vi.mock('node:fs');
@@ -28,6 +31,7 @@ describe('Auto Routing Fallback Integration', () => {
let client: BaseLlmClient; let client: BaseLlmClient;
beforeEach(() => { beforeEach(() => {
resetModelsForTesting();
vi.useFakeTimers(); vi.useFakeTimers();
vi.spyOn(Config.prototype, 'getHasAccessToPreviewModel').mockReturnValue( vi.spyOn(Config.prototype, 'getHasAccessToPreviewModel').mockReturnValue(
true, true,
@@ -68,6 +72,7 @@ describe('Auto Routing Fallback Integration', () => {
afterEach(() => { afterEach(() => {
vi.useRealTimers(); vi.useRealTimers();
vi.restoreAllMocks(); vi.restoreAllMocks();
resetModelsForTesting();
}); });
it('should fallback to Flash after 3 tries and try 10 times for Flash in auto mode', async () => { it('should fallback to Flash after 3 tries and try 10 times for Flash in auto mode', async () => {
@@ -101,14 +106,15 @@ describe('Auto Routing Fallback Integration', () => {
// Spy on generateContent to simulate failures // Spy on generateContent to simulate failures
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
attemptsPro++; attemptsPro++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Pro', 'Quota exceeded for Pro',
mockGoogleApiError, mockGoogleApiError,
0, 0,
); );
} else if (params.model === PREVIEW_GEMINI_FLASH_MODEL) { } else if (modelId === PREVIEW_GEMINI_FLASH_MODEL) {
attemptsFlash++; attemptsFlash++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Flash', 'Quota exceeded for Flash',
@@ -123,7 +129,7 @@ describe('Auto Routing Fallback Integration', () => {
// Set a fallback handler that approves the switch (simulating user or auto approval) // Set a fallback handler that approves the switch (simulating user or auto approval)
config.setFallbackModelHandler( config.setFallbackModelHandler(
async (failed, _fallback, _error): Promise<FallbackIntent | null> => { async (failed, _fallback, _error): Promise<FallbackIntent | null> => {
if (failed === PREVIEW_GEMINI_FLASH_MODEL) { if (normalizeModelId(failed) === PREVIEW_GEMINI_FLASH_MODEL) {
return 'stop'; // Stop retrying after Flash fails return 'stop'; // Stop retrying after Flash fails
} }
return 'retry_always'; // Trigger fallback to Flash return 'retry_always'; // Trigger fallback to Flash
@@ -179,7 +185,8 @@ describe('Auto Routing Fallback Integration', () => {
// Spy on generateContent to simulate failures // Spy on generateContent to simulate failures
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === normalizeModelId(PREVIEW_GEMINI_MODEL)) {
attemptsPro++; attemptsPro++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Pro', 'Quota exceeded for Pro',
@@ -218,12 +225,96 @@ describe('Auto Routing Fallback Integration', () => {
// Verify handler was called once after 10 attempts to prompt user // Verify handler was called once after 10 attempts to prompt user
expect(handler).toHaveBeenCalledTimes(1); expect(handler).toHaveBeenCalledTimes(1);
expect(handler).toHaveBeenCalledWith( expect(handler).toHaveBeenCalledWith(
PREVIEW_GEMINI_MODEL, 'gemini-3-pro-preview',
PREVIEW_GEMINI_FLASH_MODEL, 'gemini-3-flash-preview',
expect.any(RetryableQuotaError), expect.any(RetryableQuotaError),
); );
}); });
it('should fallback to gemini-3.8-flash when hasLatestFlashGAAccess is enabled', async () => {
config = new Config({
sessionId: 'test-session-latest-flash',
targetDir: '/test',
debugMode: false,
cwd: '/test',
model: PREVIEW_GEMINI_MODEL_AUTO,
});
vi.spyOn(config, 'isInteractive').mockReturnValue(true);
config.setExperiments({
flags: {
[ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]: {
boolValue: true,
},
},
experimentIds: [],
});
client = new BaseLlmClient(
fakeGenerator,
config,
AuthType.LOGIN_WITH_GOOGLE,
);
let attemptsPro = 0;
let attemptsFlash = 0;
const mockGoogleApiError = {
code: 429,
message: 'Quota exceeded',
details: [],
};
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => {
const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
attemptsPro++;
throw new RetryableQuotaError(
'Quota exceeded for Pro',
mockGoogleApiError,
0,
);
} else if (modelId === 'gemini-3.8-flash') {
attemptsFlash++;
return {
candidates: [
{
content: {
role: 'model',
parts: [{ text: 'Latest flash success' }],
},
},
],
} as unknown as GenerateContentResponse;
}
throw new Error(`Unexpected model: ${params.model}`);
},
);
config.setFallbackModelHandler(
async (_failed, _fallback, _error): Promise<FallbackIntent | null> =>
'retry_always',
);
const promise = client.generateContent({
modelConfigKey: { model: PREVIEW_GEMINI_MODEL, isChatModel: true },
contents: [{ role: 'user', parts: [{ text: 'test query' }] }],
abortSignal: new AbortController().signal,
promptId: 'test-prompt',
role: LlmRole.UTILITY_TOOL,
});
await vi.runAllTimersAsync();
const result = await promise;
expect(result.candidates?.[0]?.content?.parts?.[0]?.text).toBe(
'Latest flash success',
);
expect(attemptsPro).toBe(3);
expect(attemptsFlash).toBe(1);
});
it('should fallback to Flash after 3 tries in experimental dynamic mode', async () => { it('should fallback to Flash after 3 tries in experimental dynamic mode', async () => {
// Instantiate real Config in auto mode // Instantiate real Config in auto mode
const configDynamic = new Config({ const configDynamic = new Config({
@@ -261,14 +352,15 @@ describe('Auto Routing Fallback Integration', () => {
// Spy on generateContent to simulate failures // Spy on generateContent to simulate failures
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
attemptsPro++; attemptsPro++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Pro', 'Quota exceeded for Pro',
mockGoogleApiError, mockGoogleApiError,
0, 0,
); );
} else if (params.model === PREVIEW_GEMINI_FLASH_MODEL) { } else if (modelId === PREVIEW_GEMINI_FLASH_MODEL) {
attemptsFlash++; attemptsFlash++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Flash', 'Quota exceeded for Flash',
@@ -283,7 +375,7 @@ describe('Auto Routing Fallback Integration', () => {
// Set a fallback handler that approves the switch // Set a fallback handler that approves the switch
configDynamic.setFallbackModelHandler( configDynamic.setFallbackModelHandler(
async (failed, _fallback, _error): Promise<FallbackIntent | null> => { async (failed, _fallback, _error): Promise<FallbackIntent | null> => {
if (failed === PREVIEW_GEMINI_FLASH_MODEL) { if (normalizeModelId(failed) === PREVIEW_GEMINI_FLASH_MODEL) {
return 'stop'; return 'stop';
} }
return 'retry_always'; return 'retry_always';
@@ -339,14 +431,15 @@ describe('Auto Routing Fallback Integration', () => {
// Turn 1: Pro fails, Flash succeeds // Turn 1: Pro fails, Flash succeeds
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
attemptsPro++; attemptsPro++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Pro', 'Quota exceeded for Pro',
mockGoogleApiError, mockGoogleApiError,
0, 0,
); );
} else if (params.model === PREVIEW_GEMINI_FLASH_MODEL) { } else if (modelId === PREVIEW_GEMINI_FLASH_MODEL) {
attemptsFlash++; attemptsFlash++;
return { return {
candidates: [ candidates: [
@@ -390,7 +483,8 @@ describe('Auto Routing Fallback Integration', () => {
// Let's make it succeed this time to verify it works! // Let's make it succeed this time to verify it works!
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
return { return {
candidates: [ candidates: [
{ content: { role: 'model', parts: [{ text: 'Pro success' }] } }, { content: { role: 'model', parts: [{ text: 'Pro success' }] } },
@@ -445,14 +539,15 @@ describe('Auto Routing Fallback Integration', () => {
vi.spyOn(fakeGenerator, 'generateContent').mockImplementation( vi.spyOn(fakeGenerator, 'generateContent').mockImplementation(
async (params) => { async (params) => {
if (params.model === PREVIEW_GEMINI_MODEL) { const modelId = normalizeModelId(params.model ?? '');
if (modelId === PREVIEW_GEMINI_MODEL) {
attemptsPro++; attemptsPro++;
throw new RetryableQuotaError( throw new RetryableQuotaError(
'Quota exceeded for Pro', 'Quota exceeded for Pro',
mockGoogleApiError, mockGoogleApiError,
0, 0,
); );
} else if (params.model === PREVIEW_GEMINI_FLASH_MODEL) { } else if (modelId === PREVIEW_GEMINI_FLASH_MODEL) {
attemptsFlash++; attemptsFlash++;
return { return {
candidates: [ candidates: [
@@ -4,10 +4,11 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { describe, it, expect } from 'vitest'; import { describe, it, expect, afterEach } from 'vitest';
import { import {
createDefaultPolicy, createDefaultPolicy,
getModelPolicyChain, getModelPolicyChain,
getFlashLitePolicyChain,
validateModelPolicyChain, validateModelPolicyChain,
} from './policyCatalog.js'; } from './policyCatalog.js';
import { import {
@@ -15,9 +16,16 @@ import {
PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL, PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL,
PREVIEW_GEMINI_3_1_MODEL, PREVIEW_GEMINI_3_1_MODEL,
PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_MODEL,
setFlashLiteModel,
resetModelsForTesting,
LATEST_GEMINI_FLASH_LITE_MODEL,
} from '../config/models.js'; } from '../config/models.js';
describe('policyCatalog', () => { describe('policyCatalog', () => {
afterEach(() => {
resetModelsForTesting();
});
it('returns preview chain when preview enabled', () => { it('returns preview chain when preview enabled', () => {
const chain = getModelPolicyChain({ previewEnabled: true }); const chain = getModelPolicyChain({ previewEnabled: true });
expect(chain[0]?.model).toBe(PREVIEW_GEMINI_MODEL); expect(chain[0]?.model).toBe(PREVIEW_GEMINI_MODEL);
@@ -74,6 +82,12 @@ describe('policyCatalog', () => {
expect(secondCall[0].actions.terminal).toBe('prompt'); expect(secondCall[0].actions.terminal).toBe('prompt');
}); });
it('updates getFlashLitePolicyChain head when setFlashLiteModel is called', () => {
setFlashLiteModel(LATEST_GEMINI_FLASH_LITE_MODEL);
const chain = getFlashLitePolicyChain();
expect(chain[0]?.model).toBe(LATEST_GEMINI_FLASH_LITE_MODEL);
});
it('passes when there is exactly one last-resort policy', () => { it('passes when there is exactly one last-resort policy', () => {
const validChain = [ const validChain = [
createDefaultPolicy('test-model'), createDefaultPolicy('test-model'),
+19 -30
View File
@@ -31,8 +31,10 @@ export interface ModelPolicyOptions {
isAutoSelection?: boolean; isAutoSelection?: boolean;
userTier?: UserTierId; userTier?: UserTierId;
useGemini31?: boolean; useGemini31?: boolean;
useLatestFlashLite?: boolean;
useGemini31FlashLite?: boolean; useGemini31FlashLite?: boolean;
useCustomToolModel?: boolean; useCustomToolModel?: boolean;
useLatestFlash?: boolean;
useGemini3_5Flash?: boolean; useGemini3_5Flash?: boolean;
} }
@@ -66,22 +68,6 @@ const AUTO_ROUTING_OVERRIDES = {
} as ModelPolicyStateMap, } as ModelPolicyStateMap,
}; };
const FLASH_LITE_CHAIN: ModelPolicyChain = [
definePolicy({
model: DEFAULT_GEMINI_FLASH_LITE_MODEL,
actions: SILENT_ACTIONS,
}),
definePolicy({
model: DEFAULT_GEMINI_FLASH_MODEL,
actions: SILENT_ACTIONS,
}),
definePolicy({
model: DEFAULT_GEMINI_MODEL,
isLastResort: true,
actions: SILENT_ACTIONS,
}),
];
/** /**
* Returns the default ordered model policy chain for the user. * Returns the default ordered model policy chain for the user.
*/ */
@@ -97,7 +83,8 @@ export function getModelPolicyChain(
options.useCustomToolModel, options.useCustomToolModel,
true, true,
undefined, undefined,
options.useGemini3_5Flash, options.useLatestFlash,
options.useLatestFlashLite,
); );
return [ return [
definePolicy({ definePolicy({
@@ -136,7 +123,21 @@ export function createSingleModelChain(model: string): ModelPolicyChain {
} }
export function getFlashLitePolicyChain(): ModelPolicyChain { export function getFlashLitePolicyChain(): ModelPolicyChain {
return cloneChain(FLASH_LITE_CHAIN); return [
definePolicy({
model: DEFAULT_GEMINI_FLASH_LITE_MODEL,
actions: SILENT_ACTIONS,
}),
definePolicy({
model: DEFAULT_GEMINI_FLASH_MODEL,
actions: SILENT_ACTIONS,
}),
definePolicy({
model: DEFAULT_GEMINI_MODEL,
isLastResort: true,
actions: SILENT_ACTIONS,
}),
];
} }
/** /**
@@ -178,15 +179,3 @@ function definePolicy(config: PolicyConfig): ModelPolicy {
}, },
}; };
} }
function clonePolicy(policy: ModelPolicy): ModelPolicy {
return {
...policy,
actions: { ...policy.actions },
stateTransitions: { ...policy.stateTransitions },
};
}
function cloneChain(chain: ModelPolicyChain): ModelPolicyChain {
return chain.map(clonePolicy);
}
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { describe, it, expect, vi, beforeEach } from 'vitest'; import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { import {
resolvePolicyChain, resolvePolicyChain,
buildFallbackPolicyContext, buildFallbackPolicyContext,
@@ -16,9 +16,11 @@ import type { RetryAvailabilityContext } from './modelPolicy.js';
import type { Config } from '../config/config.js'; import type { Config } from '../config/config.js';
import { import {
DEFAULT_GEMINI_FLASH_LITE_MODEL, DEFAULT_GEMINI_FLASH_LITE_MODEL,
BASE_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_MODEL_AUTO, DEFAULT_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL, PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL,
PREVIEW_GEMINI_3_1_MODEL, PREVIEW_GEMINI_3_1_MODEL,
resetModelsForTesting,
} from '../config/models.js'; } from '../config/models.js';
import { AuthType } from '../core/contentGenerator.js'; import { AuthType } from '../core/contentGenerator.js';
import { ModelConfigService } from '../services/modelConfigService.js'; import { ModelConfigService } from '../services/modelConfigService.js';
@@ -47,6 +49,14 @@ const createMockConfig = (overrides: Partial<Config> = {}): Config => {
}; };
describe('policyHelpers', () => { describe('policyHelpers', () => {
beforeEach(() => {
resetModelsForTesting();
});
afterEach(() => {
resetModelsForTesting();
});
describe('resolvePolicyChain', () => { describe('resolvePolicyChain', () => {
it('returns a single-model chain for a custom model', () => { it('returns a single-model chain for a custom model', () => {
const config = createMockConfig({ const config = createMockConfig({
@@ -74,7 +84,7 @@ describe('policyHelpers', () => {
// Expect default chain [Pro, Flash] // Expect default chain [Pro, Flash]
expect(chain).toHaveLength(2); expect(chain).toHaveLength(2);
expect(chain[0]?.model).toBe('gemini-2.5-pro'); expect(chain[0]?.model).toBe('gemini-2.5-pro');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
}); });
it('uses auto chain when preferred model is auto', () => { it('uses auto chain when preferred model is auto', () => {
@@ -84,7 +94,7 @@ describe('policyHelpers', () => {
const chain = resolvePolicyChain(config, DEFAULT_GEMINI_MODEL_AUTO); const chain = resolvePolicyChain(config, DEFAULT_GEMINI_MODEL_AUTO);
expect(chain).toHaveLength(2); expect(chain).toHaveLength(2);
expect(chain[0]?.model).toBe('gemini-2.5-pro'); expect(chain[0]?.model).toBe('gemini-2.5-pro');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
}); });
it('uses auto chain when configured model is auto even if preferred is concrete', () => { it('uses auto chain when configured model is auto even if preferred is concrete', () => {
@@ -94,17 +104,17 @@ describe('policyHelpers', () => {
const chain = resolvePolicyChain(config, 'gemini-2.5-pro'); const chain = resolvePolicyChain(config, 'gemini-2.5-pro');
expect(chain).toHaveLength(2); expect(chain).toHaveLength(2);
expect(chain[0]?.model).toBe('gemini-2.5-pro'); expect(chain[0]?.model).toBe('gemini-2.5-pro');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
}); });
it('starts chain from preferredModel when model is "auto"', () => { it('starts chain from preferredModel when model is "auto"', () => {
const config = createMockConfig({ const config = createMockConfig({
getModel: () => 'auto', getModel: () => 'auto',
}); });
const chain = resolvePolicyChain(config, 'gemini-2.5-flash'); const chain = resolvePolicyChain(config, BASE_GEMINI_FLASH_MODEL);
// Due to Gemini 2.x wrapsAround, the chain will contain both flash and pro // Due to Gemini 2.x wrapsAround, the chain will contain both flash and pro
expect(chain.length).toBeGreaterThanOrEqual(1); expect(chain.length).toBeGreaterThanOrEqual(1);
expect(chain[0]?.model).toBe('gemini-2.5-flash'); expect(chain[0]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
}); });
it('returns flash-lite chain when preferred model is flash-lite', () => { it('returns flash-lite chain when preferred model is flash-lite', () => {
@@ -114,7 +124,7 @@ describe('policyHelpers', () => {
const chain = resolvePolicyChain(config, DEFAULT_GEMINI_FLASH_LITE_MODEL); const chain = resolvePolicyChain(config, DEFAULT_GEMINI_FLASH_LITE_MODEL);
expect(chain).toHaveLength(3); expect(chain).toHaveLength(3);
expect(chain[0]?.model).toBe('gemini-3.1-flash-lite'); expect(chain[0]?.model).toBe('gemini-3.1-flash-lite');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
expect(chain[2]?.model).toBe('gemini-2.5-pro'); expect(chain[2]?.model).toBe('gemini-2.5-pro');
}); });
@@ -125,7 +135,7 @@ describe('policyHelpers', () => {
const chain = resolvePolicyChain(config); const chain = resolvePolicyChain(config);
expect(chain).toHaveLength(3); expect(chain).toHaveLength(3);
expect(chain[0]?.model).toBe('gemini-3.1-flash-lite'); expect(chain[0]?.model).toBe('gemini-3.1-flash-lite');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
expect(chain[2]?.model).toBe('gemini-2.5-pro'); expect(chain[2]?.model).toBe('gemini-2.5-pro');
}); });
@@ -133,9 +143,9 @@ describe('policyHelpers', () => {
const config = createMockConfig({ const config = createMockConfig({
getModel: () => DEFAULT_GEMINI_MODEL_AUTO, getModel: () => DEFAULT_GEMINI_MODEL_AUTO,
}); });
const chain = resolvePolicyChain(config, 'gemini-2.5-flash', true); const chain = resolvePolicyChain(config, BASE_GEMINI_FLASH_MODEL, true);
expect(chain).toHaveLength(2); expect(chain).toHaveLength(2);
expect(chain[0]?.model).toBe('gemini-2.5-flash'); expect(chain[0]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
expect(chain[1]?.model).toBe('gemini-2.5-pro'); expect(chain[1]?.model).toBe('gemini-2.5-pro');
}); });
@@ -146,10 +156,10 @@ describe('policyHelpers', () => {
}); });
const chain = resolvePolicyChain(config); const chain = resolvePolicyChain(config);
// Should downgrade to [Pro 2.5, Flash 2.5] // Should downgrade to [Pro 2.5, Flash 3.5]
expect(chain).toHaveLength(2); expect(chain).toHaveLength(2);
expect(chain[0]?.model).toBe('gemini-2.5-pro'); expect(chain[0]?.model).toBe('gemini-2.5-pro');
expect(chain[1]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe(BASE_GEMINI_FLASH_MODEL);
}); });
it('returns Gemini 3.1 Pro chain when launched and auto-gemini-3 requested', () => { it('returns Gemini 3.1 Pro chain when launched and auto-gemini-3 requested', () => {
+19 -11
View File
@@ -23,6 +23,7 @@ import {
import { import {
DEFAULT_GEMINI_FLASH_LITE_MODEL, DEFAULT_GEMINI_FLASH_LITE_MODEL,
DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
isAutoModel, isAutoModel,
isGemini3Model, isGemini3Model,
@@ -54,7 +55,8 @@ export function resolvePolicyChain(
const useGemini31 = config.getGemini31LaunchedSync?.() ?? false; const useGemini31 = config.getGemini31LaunchedSync?.() ?? false;
const useCustomToolModel = config.getUseCustomToolModelSync?.() ?? false; const useCustomToolModel = config.getUseCustomToolModelSync?.() ?? false;
const hasAccessToPreview = config.getHasAccessToPreviewModel?.() ?? false; const hasAccessToPreview = config.getHasAccessToPreviewModel?.() ?? false;
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
// Capture the original family intent before any normalization or early downgrade. // Capture the original family intent before any normalization or early downgrade.
const isOriginallyGemini3 = isGemini3Model(modelFromConfig, config); const isOriginallyGemini3 = isGemini3Model(modelFromConfig, config);
@@ -66,7 +68,8 @@ export function resolvePolicyChain(
useCustomToolModel, useCustomToolModel,
hasAccessToPreview, hasAccessToPreview,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
), ),
); );
const isAutoPreferred = normalizedPreferredModel const isAutoPreferred = normalizedPreferredModel
@@ -84,7 +87,8 @@ export function resolvePolicyChain(
const context = { const context = {
useGemini3_1: useGemini31, useGemini3_1: useGemini31,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
}; };
if (resolvedModel === DEFAULT_GEMINI_FLASH_LITE_MODEL) { if (resolvedModel === DEFAULT_GEMINI_FLASH_LITE_MODEL) {
@@ -105,6 +109,7 @@ export function resolvePolicyChain(
const isAutoSelection = isAutoPreferred || isAutoConfigured; const isAutoSelection = isAutoPreferred || isAutoConfigured;
const previewEnabled = const previewEnabled =
hasAccessToPreview && hasAccessToPreview &&
configuredModel !== DEFAULT_GEMINI_MODEL_AUTO &&
(isGemini3Model(resolvedModel, config) || (isGemini3Model(resolvedModel, config) ||
normalizedPreferredModel === PREVIEW_GEMINI_MODEL_AUTO || normalizedPreferredModel === PREVIEW_GEMINI_MODEL_AUTO ||
configuredModel === PREVIEW_GEMINI_MODEL_AUTO); configuredModel === PREVIEW_GEMINI_MODEL_AUTO);
@@ -130,16 +135,18 @@ export function resolvePolicyChain(
const isAutoSelection = isAutoPreferred || isAutoConfigured; const isAutoSelection = isAutoPreferred || isAutoConfigured;
if (hasAccessToPreview) { if (hasAccessToPreview) {
const previewEnabled = const previewEnabled =
isOriginallyGemini3 || configuredModel !== DEFAULT_GEMINI_MODEL_AUTO &&
normalizedPreferredModel === PREVIEW_GEMINI_MODEL_AUTO || (isOriginallyGemini3 ||
configuredModel === PREVIEW_GEMINI_MODEL_AUTO; normalizedPreferredModel === PREVIEW_GEMINI_MODEL_AUTO ||
configuredModel === PREVIEW_GEMINI_MODEL_AUTO);
chain = getModelPolicyChain({ chain = getModelPolicyChain({
previewEnabled, previewEnabled,
isAutoSelection, isAutoSelection,
userTier: config.getUserTier(), userTier: config.getUserTier(),
useGemini31, useGemini31,
useCustomToolModel, useCustomToolModel,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
}); });
} else { } else {
// User requested Gemini 3 but has no access. Proactively downgrade // User requested Gemini 3 but has no access. Proactively downgrade
@@ -150,7 +157,8 @@ export function resolvePolicyChain(
userTier: config.getUserTier(), userTier: config.getUserTier(),
useGemini31, useGemini31,
useCustomToolModel, useCustomToolModel,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
}); });
} }
} else { } else {
@@ -265,10 +273,10 @@ export function selectModelForAvailability(
): ModelSelectionResult { ): ModelSelectionResult {
const chain = resolvePolicyChain(config, requestedModel); const chain = resolvePolicyChain(config, requestedModel);
const selection = config const selection = config
.getModelAvailabilityService() .getModelAvailabilityService?.()
.selectFirstAvailable(chain.map((p) => p.model)); ?.selectFirstAvailable(chain.map((p) => p.model));
if (selection.selectedModel) return selection; if (selection?.selectedModel) return selection;
const backupModel = const backupModel =
chain.find((p) => p.isLastResort)?.model ?? DEFAULT_GEMINI_MODEL; chain.find((p) => p.isLastResort)?.model ?? DEFAULT_GEMINI_MODEL;
@@ -19,6 +19,9 @@ export const ExperimentFlags = {
GEMINI_3_1_PRO_LAUNCHED: 45760185, GEMINI_3_1_PRO_LAUNCHED: 45760185,
PRO_MODEL_NO_ACCESS: 45768879, PRO_MODEL_NO_ACCESS: 45768879,
DEFAULT_REQUEST_TIMEOUT: 45773134, DEFAULT_REQUEST_TIMEOUT: 45773134,
LATEST_FLASH_GA_LAUNCHED: 45842815,
LATEST_FLASH_LITE_GA_LAUNCHED: 45827489,
/** @deprecated Use LATEST_FLASH_GA_LAUNCHED */
GEMINI_3_5_FLASH_GA_LAUNCHED: 45780819, GEMINI_3_5_FLASH_GA_LAUNCHED: 45780819,
} as const; } as const;
+139 -13
View File
@@ -70,6 +70,8 @@ import {
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_FLASH_LITE_MODEL,
resetModelsForTesting,
} from './models.js'; } from './models.js';
import { Storage } from './storage.js'; import { Storage } from './storage.js';
import type { AgentLoopContext } from './agent-loop-context.js'; import type { AgentLoopContext } from './agent-loop-context.js';
@@ -279,6 +281,7 @@ vi.mock('../code_assist/experiments/experiments.js');
afterEach(() => { afterEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
resetModelsForTesting();
}); });
describe('Server Config (config.ts)', () => { describe('Server Config (config.ts)', () => {
@@ -3280,7 +3283,7 @@ describe('Config Quota & Preview Model Access', () => {
remainingFraction: 0.2, remainingFraction: 0.2,
}, },
{ {
modelId: 'gemini-2.5-flash', modelId: 'gemini-3.5-flash',
remainingAmount: '80', remainingAmount: '80',
remainingFraction: 0.8, remainingFraction: 0.8,
}, },
@@ -4425,7 +4428,7 @@ describe('ADKSettings', () => {
}); });
}); });
describe('hasGemini35FlashGAAccess model setting', () => { describe('hasLatestFlashGAAccess model setting', () => {
const baseParams: ConfigParameters = { const baseParams: ConfigParameters = {
sessionId: 'test', sessionId: 'test',
targetDir: '.', targetDir: '.',
@@ -4434,47 +4437,170 @@ describe('hasGemini35FlashGAAccess model setting', () => {
cwd: '.', cwd: '.',
}; };
it('should set DEFAULT_GEMINI_FLASH_MODEL to gemini-3.5-flash and PREVIEW_GEMINI_FLASH_MODEL to gemini-3-flash-preview if hasGemini35FlashGAAccess returns true and authType is USE_GEMINI', () => { it('should set DEFAULT_GEMINI_FLASH_MODEL to gemini-3.8-flash and PREVIEW_GEMINI_FLASH_MODEL to gemini-3-flash-preview if hasLatestFlashGAAccess returns true and authType is USE_GEMINI', () => {
const config = new Config(baseParams); const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType: AuthType.USE_GEMINI }; config['contentGeneratorConfig'] = { authType: AuthType.USE_GEMINI };
// Set experiment to return true for GEMINI_3_5_FLASH_GA_LAUNCHED // Set experiment to return true for LATEST_FLASH_GA_LAUNCHED
config.setExperiments({ config.setExperiments({
experimentIds: [], experimentIds: [],
flags: { flags: {
[ExperimentFlags.GEMINI_3_5_FLASH_GA_LAUNCHED]: { [ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]: {
boolValue: true, boolValue: true,
}, },
}, },
}); });
// Call the method // Call the method
const result = config.hasGemini35FlashGAAccess(); const result = config.hasLatestFlashGAAccess();
expect(result).toBe(true); expect(result).toBe(true);
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3-flash-preview');
});
it('should set DEFAULT_GEMINI_FLASH_MODEL and PREVIEW_GEMINI_FLASH_MODEL to gemini-3.8-flash if hasLatestFlashGAAccess returns true and authType is not USE_GEMINI', () => {
const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType: AuthType.LOGIN_WITH_GOOGLE };
// Set experiment to return true for LATEST_FLASH_GA_LAUNCHED
config.setExperiments({
experimentIds: [],
flags: {
[ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]: {
boolValue: true,
},
},
});
// Call the method
const result = config.hasLatestFlashGAAccess();
expect(result).toBe(true);
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
});
it.each([AuthType.USE_GEMINI, AuthType.USE_VERTEX_AI, AuthType.GATEWAY])(
'should return true even if experiment flag is false when authType is %s',
(authType) => {
const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType };
config.setExperiments({
experimentIds: [],
flags: {
[ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]: {
boolValue: false,
},
},
});
const result = config.hasLatestFlashGAAccess();
expect(result).toBe(true);
if (authType === AuthType.USE_GEMINI) {
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3-flash-preview');
} else {
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3.8-flash');
}
},
);
it('should return false if experiment flag is false when authType is not in launch list (e.g. LOGIN_WITH_GOOGLE)', () => {
const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType: AuthType.LOGIN_WITH_GOOGLE };
config.setExperiments({
experimentIds: [],
flags: {
[ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]: {
boolValue: false,
},
},
});
const result = config.hasLatestFlashGAAccess();
expect(result).toBe(false);
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.5-flash'); expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.5-flash');
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3-flash-preview'); expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3-flash-preview');
}); });
});
it('should set DEFAULT_GEMINI_FLASH_MODEL and PREVIEW_GEMINI_FLASH_MODEL to gemini-3.5-flash if hasGemini35FlashGAAccess returns true and authType is not USE_GEMINI', () => { describe('hasLatestFlashLiteGAAccess model setting', () => {
const baseParams: ConfigParameters = {
sessionId: 'test',
targetDir: '.',
debugMode: false,
model: 'test-model',
cwd: '.',
};
beforeEach(() => {
resetModelsForTesting();
});
afterEach(() => {
resetModelsForTesting();
});
it.each([AuthType.USE_GEMINI, AuthType.USE_VERTEX_AI, AuthType.GATEWAY])(
'should return true and set DEFAULT_GEMINI_FLASH_LITE_MODEL even if experiment flag is false when authType is %s',
(authType) => {
const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType };
config.setExperiments({
experimentIds: [],
flags: {
[ExperimentFlags.LATEST_FLASH_LITE_GA_LAUNCHED]: {
boolValue: false,
},
},
});
const result = config.hasLatestFlashLiteGAAccess();
expect(result).toBe(true);
expect(DEFAULT_GEMINI_FLASH_LITE_MODEL).toBe('gemini-3.5-flash-lite');
},
);
it('should return true and set DEFAULT_GEMINI_FLASH_LITE_MODEL if experiment flag is true for other auth types', () => {
const config = new Config(baseParams); const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType: AuthType.LOGIN_WITH_GOOGLE }; config['contentGeneratorConfig'] = { authType: AuthType.LOGIN_WITH_GOOGLE };
// Set experiment to return true for GEMINI_3_5_FLASH_GA_LAUNCHED
config.setExperiments({ config.setExperiments({
experimentIds: [], experimentIds: [],
flags: { flags: {
[ExperimentFlags.GEMINI_3_5_FLASH_GA_LAUNCHED]: { [ExperimentFlags.LATEST_FLASH_LITE_GA_LAUNCHED]: {
boolValue: true, boolValue: true,
}, },
}, },
}); });
// Call the method const result = config.hasLatestFlashLiteGAAccess();
const result = config.hasGemini35FlashGAAccess();
expect(result).toBe(true); expect(result).toBe(true);
expect(DEFAULT_GEMINI_FLASH_LITE_MODEL).toBe('gemini-3.5-flash-lite');
});
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe('gemini-3.5-flash'); it('should return false and keep base model if experiment flag is false for other auth types', () => {
expect(PREVIEW_GEMINI_FLASH_MODEL).toBe('gemini-3.5-flash'); const config = new Config(baseParams);
config['contentGeneratorConfig'] = { authType: AuthType.LOGIN_WITH_GOOGLE };
config.setExperiments({
experimentIds: [],
flags: {
[ExperimentFlags.LATEST_FLASH_LITE_GA_LAUNCHED]: {
boolValue: false,
},
},
});
const result = config.hasLatestFlashLiteGAAccess();
expect(result).toBe(false);
expect(DEFAULT_GEMINI_FLASH_LITE_MODEL).toBe('gemini-3.1-flash-lite');
}); });
}); });
+64 -20
View File
@@ -87,8 +87,12 @@ import {
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
resolveModel, resolveModel,
setFlashModels, setFlashModels,
DEFAULT_GEMINI_3_5_FLASH_MODEL, BASE_GEMINI_FLASH_MODEL,
SECONDARY_GEMINI_3_5_FLASH_MODEL, LATEST_GEMINI_FLASH_MODEL,
LEGACY_CCPA_FLASH_MODEL,
BASE_GEMINI_FLASH_LITE_MODEL,
LATEST_GEMINI_FLASH_LITE_MODEL,
setFlashLiteModel,
} from './models.js'; } from './models.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js'; import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js'; import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
@@ -2066,7 +2070,8 @@ export class Config implements McpContext, AgentLoopContext {
this.getUseCustomToolModelSync(), this.getUseCustomToolModelSync(),
this.getHasAccessToPreviewModel(), this.getHasAccessToPreviewModel(),
this, this,
this.hasGemini35FlashGAAccess(), this.hasLatestFlashGAAccess(),
this.hasLatestFlashLiteGAAccess(),
); );
const isPreview = isPreviewModel(primaryModel, this); const isPreview = isPreviewModel(primaryModel, this);
@@ -2106,7 +2111,8 @@ export class Config implements McpContext, AgentLoopContext {
this.getUseCustomToolModelSync(), this.getUseCustomToolModelSync(),
this.getHasAccessToPreviewModel(), this.getHasAccessToPreviewModel(),
this, this,
this.hasGemini35FlashGAAccess(), this.hasLatestFlashGAAccess(),
this.hasLatestFlashLiteGAAccess(),
); );
return this.modelQuotas.get(primaryModel)?.remaining; return this.modelQuotas.get(primaryModel)?.remaining;
} }
@@ -2122,7 +2128,8 @@ export class Config implements McpContext, AgentLoopContext {
this.getUseCustomToolModelSync(), this.getUseCustomToolModelSync(),
this.getHasAccessToPreviewModel(), this.getHasAccessToPreviewModel(),
this, this,
this.hasGemini35FlashGAAccess(), this.hasLatestFlashGAAccess(),
this.hasLatestFlashLiteGAAccess(),
); );
return this.modelQuotas.get(primaryModel)?.limit; return this.modelQuotas.get(primaryModel)?.limit;
} }
@@ -2138,7 +2145,8 @@ export class Config implements McpContext, AgentLoopContext {
this.getUseCustomToolModelSync(), this.getUseCustomToolModelSync(),
this.getHasAccessToPreviewModel(), this.getHasAccessToPreviewModel(),
this, this,
this.hasGemini35FlashGAAccess(), this.hasLatestFlashGAAccess(),
this.hasLatestFlashLiteGAAccess(),
); );
return this.modelQuotas.get(primaryModel)?.resetTime; return this.modelQuotas.get(primaryModel)?.resetTime;
} }
@@ -2322,8 +2330,21 @@ export class Config implements McpContext, AgentLoopContext {
} }
let modelId = bucket.modelId; let modelId = bucket.modelId;
if (modelId === SECONDARY_GEMINI_3_5_FLASH_MODEL) { if (
modelId = DEFAULT_GEMINI_3_5_FLASH_MODEL; modelId === LEGACY_CCPA_FLASH_MODEL ||
modelId === BASE_GEMINI_FLASH_MODEL ||
modelId === LATEST_GEMINI_FLASH_MODEL
) {
modelId = this.hasLatestFlashGAAccess()
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
} else if (
modelId === BASE_GEMINI_FLASH_LITE_MODEL ||
modelId === LATEST_GEMINI_FLASH_LITE_MODEL
) {
modelId = this.hasLatestFlashLiteGAAccess()
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
} }
let remaining: number; let remaining: number;
@@ -3570,37 +3591,58 @@ export class Config implements McpContext, AgentLoopContext {
} }
/** /**
* Returns whether Gemini 3.5 Flash GA has been launched. * Returns whether the latest Flash GA model (currently Gemini 3.8 Flash) has been launched.
*
* Note: This method should only be called after startup, once experiments have been loaded.
*/ */
hasGemini35FlashGAAccess(): boolean { hasLatestFlashGAAccess(): boolean {
const authType = this.contentGeneratorConfig?.authType; const authType = this.contentGeneratorConfig?.authType;
const hasAccess = (() => { const hasAccess = (() => {
if (this.isGemini31LaunchedForAuthType(authType)) { if (this.isGemini31LaunchedForAuthType(authType)) {
return true; return true;
} }
return ( return (
this.experiments?.flags[ExperimentFlags.GEMINI_3_5_FLASH_GA_LAUNCHED] this.experiments?.flags[ExperimentFlags.LATEST_FLASH_GA_LAUNCHED]
?.boolValue ?? false ?.boolValue ?? false
); );
})(); })();
// Used to set default flash models based on access
// TODO: Remove once the experiment for 3_5 flash rollut can be cleaned up.
if (hasAccess) { if (hasAccess) {
// Gemini API key users should have the ability to manually select the
// old preview flash model.
if (authType === AuthType.USE_GEMINI) { if (authType === AuthType.USE_GEMINI) {
setFlashModels('gemini-3-flash-preview', 'gemini-3.5-flash'); setFlashModels('gemini-3-flash-preview', LATEST_GEMINI_FLASH_MODEL);
} else { } else {
setFlashModels('gemini-3.5-flash', 'gemini-3.5-flash'); setFlashModels(LATEST_GEMINI_FLASH_MODEL, LATEST_GEMINI_FLASH_MODEL);
} }
} else { } else {
setFlashModels('gemini-3-flash-preview', 'gemini-2.5-flash'); setFlashModels('gemini-3-flash-preview', BASE_GEMINI_FLASH_MODEL);
} }
return hasAccess; return hasAccess;
} }
/** @deprecated Use hasLatestFlashGAAccess() */
hasGemini35FlashGAAccess(): boolean {
return this.hasLatestFlashGAAccess();
}
/**
* Returns whether the latest Flash Lite GA model (currently Gemini 3.5 Flash Lite) has been launched.
*/
hasLatestFlashLiteGAAccess(): boolean {
const authType = this.contentGeneratorConfig?.authType;
const hasAccess = (() => {
if (this.isGemini31LaunchedForAuthType(authType)) {
return true;
}
return (
this.experiments?.flags[ExperimentFlags.LATEST_FLASH_LITE_GA_LAUNCHED]
?.boolValue ?? false
);
})();
setFlashLiteModel(
hasAccess ? LATEST_GEMINI_FLASH_LITE_MODEL : BASE_GEMINI_FLASH_LITE_MODEL,
);
return hasAccess;
}
/** /**
* Returns whether Gemini 3.1 has been launched. * Returns whether Gemini 3.1 has been launched.
* *
@@ -4173,6 +4215,8 @@ export class Config implements McpContext, AgentLoopContext {
compact: false, compact: false,
}); });
debugLogger.debug('Experiments loaded', summaryString); debugLogger.debug('Experiments loaded', summaryString);
this.hasLatestFlashGAAccess();
this.hasLatestFlashLiteGAAccess();
} }
private onAgentsRefreshed = async () => { private onAgentsRefreshed = async () => {
+95 -27
View File
@@ -6,7 +6,14 @@
import { ThinkingLevel } from '@google/genai'; import { ThinkingLevel } from '@google/genai';
import type { ModelConfigServiceConfig } from '../services/modelConfigService.js'; import type { ModelConfigServiceConfig } from '../services/modelConfigService.js';
import { DEFAULT_THINKING_MODE } from './models.js'; import {
DEFAULT_THINKING_MODE,
BASE_GEMINI_FLASH_MODEL,
LATEST_GEMINI_FLASH_MODEL,
BASE_GEMINI_FLASH_LITE_MODEL,
LATEST_GEMINI_FLASH_LITE_MODEL,
DEFAULT_GEMINI_MODEL,
} from './models.js';
// The default model configs. We use `base` as the parent for all of our model // The default model configs. We use `base` as the parent for all of our model
// configs, while `chat-base`, a child of `base`, is the parent of the models // configs, while `chat-base`, a child of `base`, is the parent of the models
@@ -113,12 +120,24 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
model: 'gemini-3.1-flash-lite', model: 'gemini-3.1-flash-lite',
}, },
}, },
'gemini-3.5-flash-lite': {
extends: 'chat-base-3',
modelConfig: {
model: 'gemini-3.5-flash-lite',
},
},
'gemini-3.5-flash': { 'gemini-3.5-flash': {
extends: 'chat-base-3', extends: 'chat-base-3',
modelConfig: { modelConfig: {
model: 'gemini-3.5-flash', model: 'gemini-3.5-flash',
}, },
}, },
'gemini-3.8-flash': {
extends: 'chat-base-3',
modelConfig: {
model: 'gemini-3.8-flash',
},
},
'gemma-4-31b-it': { 'gemma-4-31b-it': {
extends: 'chat-base-3', extends: 'chat-base-3',
modelConfig: { modelConfig: {
@@ -330,6 +349,13 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
isVisible: true, isVisible: true,
features: { thinking: false, multimodalToolUse: true }, features: { thinking: false, multimodalToolUse: true },
}, },
'gemini-3.5-flash-lite': {
tier: 'flash-lite',
family: 'gemini-3',
isPreview: false,
isVisible: true,
features: { thinking: false, multimodalToolUse: true },
},
'gemini-3.1-pro-preview': { 'gemini-3.1-pro-preview': {
tier: 'pro', tier: 'pro',
family: 'gemini-3', family: 'gemini-3',
@@ -365,6 +391,13 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
isVisible: true, isVisible: true,
features: { thinking: false, multimodalToolUse: true }, features: { thinking: false, multimodalToolUse: true },
}, },
'gemini-3.8-flash': {
tier: 'flash',
family: 'gemini-3',
isPreview: false,
isVisible: true,
features: { thinking: false, multimodalToolUse: true },
},
'gemini-2.5-pro': { 'gemini-2.5-pro': {
tier: 'pro', tier: 'pro',
family: 'gemini-2.5', family: 'gemini-2.5',
@@ -470,32 +503,40 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
default: 'gemini-3-flash-preview', default: 'gemini-3-flash-preview',
contexts: [ contexts: [
{ {
condition: { hasAccessToPreview: false, useGemini3_5Flash: true }, condition: { hasAccessToPreview: false, useLatestFlash: true },
target: 'gemini-3.5-flash', target: LATEST_GEMINI_FLASH_MODEL,
}, },
{ {
condition: { hasAccessToPreview: false, useGemini3_5Flash: false }, condition: { hasAccessToPreview: false, useLatestFlash: false },
target: 'gemini-2.5-flash', target: BASE_GEMINI_FLASH_MODEL,
}, },
], ],
}, },
'gemini-3.5-flash': { [BASE_GEMINI_FLASH_MODEL]: {
default: 'gemini-3.5-flash', default: BASE_GEMINI_FLASH_MODEL,
contexts: [ contexts: [
{ {
condition: { useGemini3_5Flash: false, hasAccessToPreview: false }, condition: { useLatestFlash: true },
target: 'gemini-2.5-flash', target: LATEST_GEMINI_FLASH_MODEL,
}, },
],
},
[LATEST_GEMINI_FLASH_MODEL]: {
default: LATEST_GEMINI_FLASH_MODEL,
contexts: [
{ {
condition: { useGemini3_5Flash: false }, condition: { useLatestFlash: false },
target: 'gemini-3-flash-preview', target: BASE_GEMINI_FLASH_MODEL,
}, },
], ],
}, },
'gemini-2.5-flash': { 'gemini-2.5-flash': {
default: 'gemini-2.5-flash', default: 'gemini-2.5-flash',
contexts: [ contexts: [
{ condition: { useGemini3_5Flash: true }, target: 'gemini-3.5-flash' }, {
condition: { useLatestFlash: true },
target: LATEST_GEMINI_FLASH_MODEL,
},
], ],
}, },
'gemini-3-pro-preview': { 'gemini-3-pro-preview': {
@@ -540,21 +581,45 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
}, },
], ],
}, },
'gemini-3.1-flash-lite': { [BASE_GEMINI_FLASH_LITE_MODEL]: {
default: 'gemini-3.1-flash-lite', default: BASE_GEMINI_FLASH_LITE_MODEL,
contexts: [
{
condition: { useLatestFlashLite: true },
target: LATEST_GEMINI_FLASH_LITE_MODEL,
},
],
},
[LATEST_GEMINI_FLASH_LITE_MODEL]: {
default: LATEST_GEMINI_FLASH_LITE_MODEL,
contexts: [
{
condition: { useLatestFlashLite: false },
target: BASE_GEMINI_FLASH_LITE_MODEL,
},
],
}, },
flash: { flash: {
default: 'gemini-3-flash-preview', default: 'gemini-3-flash-preview',
contexts: [ contexts: [
{ condition: { useGemini3_5Flash: true }, target: 'gemini-3.5-flash' }, {
condition: { useLatestFlash: true },
target: LATEST_GEMINI_FLASH_MODEL,
},
{ {
condition: { hasAccessToPreview: false }, condition: { hasAccessToPreview: false },
target: 'gemini-2.5-flash', target: BASE_GEMINI_FLASH_MODEL,
}, },
], ],
}, },
'flash-lite': { 'flash-lite': {
default: 'gemini-3.1-flash-lite', default: BASE_GEMINI_FLASH_LITE_MODEL,
contexts: [
{
condition: { useLatestFlashLite: true },
target: LATEST_GEMINI_FLASH_LITE_MODEL,
},
],
}, },
'auto-gemini-3': { 'auto-gemini-3': {
default: 'gemini-3-pro-preview', default: 'gemini-3-pro-preview',
@@ -578,14 +643,17 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
flash: { flash: {
default: 'gemini-3-flash-preview', default: 'gemini-3-flash-preview',
contexts: [ contexts: [
{ condition: { useGemini3_5Flash: true }, target: 'gemini-3.5-flash' }, {
condition: { useLatestFlash: true },
target: LATEST_GEMINI_FLASH_MODEL,
},
{ {
condition: { hasAccessToPreview: false }, condition: { hasAccessToPreview: false },
target: 'gemini-2.5-flash', target: BASE_GEMINI_FLASH_MODEL,
}, },
{ {
condition: { requestedModels: ['gemini-2.5-pro', 'auto-gemini-2.5'] }, condition: { requestedModels: ['gemini-2.5-pro', 'auto-gemini-2.5'] },
target: 'gemini-2.5-flash', target: BASE_GEMINI_FLASH_MODEL,
}, },
], ],
}, },
@@ -683,7 +751,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
], ],
default: [ default: [
{ {
model: 'gemini-2.5-pro', model: DEFAULT_GEMINI_MODEL,
actions: { actions: {
terminal: 'prompt', terminal: 'prompt',
transient: 'prompt', transient: 'prompt',
@@ -698,7 +766,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
}, },
}, },
{ {
model: 'gemini-2.5-flash', model: BASE_GEMINI_FLASH_MODEL,
isLastResort: true, isLastResort: true,
maxAttempts: 10, maxAttempts: 10,
actions: { actions: {
@@ -717,7 +785,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
], ],
'auto-default': [ 'auto-default': [
{ {
model: 'gemini-2.5-pro', model: DEFAULT_GEMINI_MODEL,
maxAttempts: 3, maxAttempts: 3,
actions: { actions: {
terminal: 'prompt', terminal: 'prompt',
@@ -733,7 +801,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
}, },
}, },
{ {
model: 'gemini-2.5-flash', model: BASE_GEMINI_FLASH_MODEL,
isLastResort: true, isLastResort: true,
maxAttempts: 10, maxAttempts: 10,
actions: { actions: {
@@ -752,7 +820,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
], ],
lite: [ lite: [
{ {
model: 'flash-lite', model: BASE_GEMINI_FLASH_LITE_MODEL,
actions: { actions: {
terminal: 'silent', terminal: 'silent',
transient: 'silent', transient: 'silent',
@@ -767,7 +835,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
}, },
}, },
{ {
model: 'gemini-2.5-flash', model: BASE_GEMINI_FLASH_MODEL,
actions: { actions: {
terminal: 'silent', terminal: 'silent',
transient: 'silent', transient: 'silent',
@@ -782,7 +850,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = {
}, },
}, },
{ {
model: 'gemini-2.5-pro', model: DEFAULT_GEMINI_MODEL,
isLastResort: true, isLastResort: true,
actions: { actions: {
terminal: 'silent', terminal: 'silent',
+168 -29
View File
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { describe, it, expect } from 'vitest'; import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { import {
resolveModel, resolveModel,
resolveClassifierModel, resolveClassifierModel,
@@ -17,8 +17,12 @@ import {
DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_MODEL,
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_3_5_FLASH_MODEL,
DEFAULT_GEMINI_FLASH_LITE_MODEL, DEFAULT_GEMINI_FLASH_LITE_MODEL,
BASE_GEMINI_FLASH_MODEL,
BASE_GEMINI_FLASH_LITE_MODEL,
setFlashModels,
setFlashLiteModel,
resetModelsForTesting,
supportsMultimodalFunctionResponse, supportsMultimodalFunctionResponse,
GEMINI_MODEL_ALIAS_PRO, GEMINI_MODEL_ALIAS_PRO,
GEMINI_MODEL_ALIAS_FLASH, GEMINI_MODEL_ALIAS_FLASH,
@@ -33,6 +37,8 @@ import {
PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL, PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL,
isPreviewModel, isPreviewModel,
isProModel, isProModel,
LATEST_GEMINI_FLASH_MODEL,
LATEST_GEMINI_FLASH_LITE_MODEL,
GEMMA_4_31B_IT_MODEL, GEMMA_4_31B_IT_MODEL,
GEMMA_4_26B_A4B_IT_MODEL, GEMMA_4_26B_A4B_IT_MODEL,
getAutoModelDescription, getAutoModelDescription,
@@ -43,6 +49,10 @@ import { DEFAULT_MODEL_CONFIGS } from './defaultModelConfigs.js';
const modelConfigService = new ModelConfigService(DEFAULT_MODEL_CONFIGS); const modelConfigService = new ModelConfigService(DEFAULT_MODEL_CONFIGS);
afterEach(() => {
resetModelsForTesting();
});
const dynamicConfig = { const dynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -731,7 +741,7 @@ describe('getAutoModelDescription', () => {
it('should return Gemini 2.5 description when hasAccessToPreview is false', () => { it('should return Gemini 2.5 description when hasAccessToPreview is false', () => {
const desc = getAutoModelDescription(false, false); const desc = getAutoModelDescription(false, false);
expect(desc).toContain('gemini-2.5-pro'); expect(desc).toContain('gemini-2.5-pro');
expect(desc).toContain('gemini-2.5-flash'); expect(desc).toContain('gemini-3.5-flash');
}); });
it('should return Gemini 3.0 description when hasAccessToPreview is true', () => { it('should return Gemini 3.0 description when hasAccessToPreview is true', () => {
@@ -746,15 +756,15 @@ describe('getAutoModelDescription', () => {
expect(desc).toContain('gemini-3-flash-preview'); expect(desc).toContain('gemini-3-flash-preview');
}); });
it('should return Gemini 3.5 Flash description when hasAccessToPreview and useGemini3_5Flash are true', () => { it('should return latest Flash description when hasAccessToPreview and useLatestFlash are true', () => {
const desc = getAutoModelDescription(true, true, true); const desc = getAutoModelDescription(true, true, true);
expect(desc).toContain('gemini-3.1-pro-preview'); expect(desc).toContain('gemini-3.1-pro-preview');
expect(desc).toContain(DEFAULT_GEMINI_3_5_FLASH_MODEL); expect(desc).toContain(LATEST_GEMINI_FLASH_MODEL);
}); });
}); });
describe('resolveModel Gemini 3.5 Flash GA', () => { describe('resolveModel Gemini 3.5 Flash GA', () => {
it('should resolve known non-preview flash models to DEFAULT_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (legacy)', () => { it('should resolve known non-preview flash models to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (legacy)', () => {
expect( expect(
resolveModel( resolveModel(
GEMINI_MODEL_ALIAS_FLASH, GEMINI_MODEL_ALIAS_FLASH,
@@ -764,7 +774,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
expect( expect(
resolveModel( resolveModel(
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
@@ -774,7 +784,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
expect( expect(
resolveModel( resolveModel(
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
@@ -790,7 +800,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
it.each([ it.each([
'gemini-3.6-flash', 'gemini-3.6-flash',
'gemini-3.7-flash', 'gemini-3.7-flash',
'gemini-3.8-flash', 'gemini-3.9-flash',
'gemini-9.9-flash', 'gemini-9.9-flash',
])( ])(
'should preserve the explicit versioned model %s when useGemini3_5Flash is true (legacy)', 'should preserve the explicit versioned model %s when useGemini3_5Flash is true (legacy)',
@@ -801,7 +811,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
}, },
); );
it('should resolve known non-preview flash models to gemini-3.5-flash when useGemini3_5Flash is true (dynamic)', () => { it('should resolve known non-preview flash models to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (dynamic)', () => {
const mockDynamicConfig = { const mockDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -816,7 +826,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
expect( expect(
resolveModel( resolveModel(
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
@@ -826,7 +836,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
expect( expect(
resolveModel( resolveModel(
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
@@ -887,10 +897,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
false, // GA false false, // GA false
), ),
).toBe('gemini-2.5-flash'); ).toBe(DEFAULT_GEMINI_FLASH_MODEL);
}); });
it('should resolve auto to DEFAULT_GEMINI_FLASH_MODEL when useGemini3_5Flash is true and classifier selects flash', () => { it('should resolve auto to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true and classifier selects flash', () => {
expect( expect(
resolveClassifierModel( resolveClassifierModel(
GEMINI_MODEL_ALIAS_AUTO, GEMINI_MODEL_ALIAS_AUTO,
@@ -901,10 +911,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve auto to gemini-3.5-flash when useGemini3_5Flash is true and classifier selects flash (dynamic)', () => { it('should resolve auto to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true and classifier selects flash (dynamic)', () => {
const mockDynamicConfig = { const mockDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -920,11 +930,11 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
describe('Flash model promotion and manual override routing logic', () => { describe('Flash model promotion and manual override routing logic', () => {
it('should resolve flash alias to DEFAULT_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (static)', () => { it('should resolve flash alias to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (static)', () => {
expect( expect(
resolveModel( resolveModel(
GEMINI_MODEL_ALIAS_FLASH, GEMINI_MODEL_ALIAS_FLASH,
@@ -934,10 +944,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve flash alias to gemini-3.5-flash when useGemini3_5Flash is true (dynamic)', () => { it('should resolve flash alias to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (dynamic)', () => {
const mockDynamicConfig = { const mockDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -952,7 +962,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve manual selection of gemini-3-flash-preview to gemini-3-flash-preview when useGemini3_5Flash is true and has preview access (static)', () => { it('should resolve manual selection of gemini-3-flash-preview to gemini-3-flash-preview when useGemini3_5Flash is true and has preview access (static)', () => {
@@ -986,7 +996,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
).toBe('gemini-3-flash-preview'); ).toBe('gemini-3-flash-preview');
}); });
it('should resolve manual selection of gemini-3-flash-preview to DEFAULT_GEMINI_FLASH_MODEL when useGemini3_5Flash is true but lacks preview access (static)', () => { it('should resolve manual selection of gemini-3-flash-preview to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true but lacks preview access (static)', () => {
expect( expect(
resolveModel( resolveModel(
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
@@ -996,10 +1006,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve manual selection of gemini-3-flash-preview to gemini-3.5-flash when useGemini3_5Flash is true but lacks preview access (dynamic)', () => { it('should resolve manual selection of gemini-3-flash-preview to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true but lacks preview access (dynamic)', () => {
const mockDynamicConfig = { const mockDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -1014,10 +1024,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve classifier-selected flash alias to DEFAULT_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (static)', () => { it('should resolve classifier-selected flash alias to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (static)', () => {
expect( expect(
resolveClassifierModel( resolveClassifierModel(
GEMINI_MODEL_ALIAS_AUTO, GEMINI_MODEL_ALIAS_AUTO,
@@ -1028,10 +1038,10 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
undefined, undefined,
true, true,
), ),
).toBe(DEFAULT_GEMINI_FLASH_MODEL); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve classifier-selected flash alias to gemini-3.5-flash when useGemini3_5Flash is true (dynamic)', () => { it('should resolve classifier-selected flash alias to LATEST_GEMINI_FLASH_MODEL when useGemini3_5Flash is true (dynamic)', () => {
const mockDynamicConfig = { const mockDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true, getExperimentalDynamicModelConfiguration: () => true,
modelConfigService, modelConfigService,
@@ -1047,7 +1057,7 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
mockDynamicConfig, mockDynamicConfig,
true, true,
), ),
).toBe('gemini-3.5-flash'); ).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
it('should resolve auto to PREVIEW_GEMINI_MODEL when useGemini3_5Flash is true and has preview access', () => { it('should resolve auto to PREVIEW_GEMINI_MODEL when useGemini3_5Flash is true and has preview access', () => {
@@ -1063,4 +1073,133 @@ describe('resolveModel Gemini 3.5 Flash GA', () => {
).toBe(PREVIEW_GEMINI_MODEL); ).toBe(PREVIEW_GEMINI_MODEL);
}); });
}); });
describe('multi-session isolation and global state leakage prevention', () => {
beforeEach(() => {
resetModelsForTesting();
});
afterEach(() => {
resetModelsForTesting();
});
it('should NOT leak latest flash or flash lite models to sessions without access even if global models are mutated', () => {
// Simulate Session A (which has access) mutating global models via setFlashModels / setFlashLiteModel
setFlashModels('gemini-3-flash-preview', LATEST_GEMINI_FLASH_MODEL);
setFlashLiteModel(LATEST_GEMINI_FLASH_LITE_MODEL);
// Verify global variables were indeed mutated to the latest models
expect(DEFAULT_GEMINI_FLASH_MODEL).toBe(LATEST_GEMINI_FLASH_MODEL);
expect(DEFAULT_GEMINI_FLASH_LITE_MODEL).toBe(
LATEST_GEMINI_FLASH_LITE_MODEL,
);
// Session B has NO access (experiment flags false / hasLatestFlashGAAccess returns false)
const sessionBConfig = {
getExperimentalDynamicModelConfiguration: () => false,
hasLatestFlashGAAccess: () => false,
hasLatestFlashLiteGAAccess: () => false,
getHasAccessToPreviewModel: () => true,
modelConfigService,
} as unknown as Config;
// Session B resolving 'flash' should NOT get LATEST_GEMINI_FLASH_MODEL
expect(
resolveModel(
GEMINI_MODEL_ALIAS_FLASH,
false,
false,
true,
sessionBConfig,
false,
false,
),
).toBe(PREVIEW_GEMINI_FLASH_MODEL);
// Session B resolving 'flash-lite' should NOT get LATEST_GEMINI_FLASH_LITE_MODEL
expect(
resolveModel(
GEMINI_MODEL_ALIAS_FLASH_LITE,
false,
false,
true,
sessionBConfig,
false,
false,
),
).toBe(BASE_GEMINI_FLASH_LITE_MODEL);
// Session B resolving without preview access should get BASE models, NOT LATEST
expect(
resolveModel(
PREVIEW_GEMINI_FLASH_MODEL,
false,
false,
false,
sessionBConfig,
false,
false,
),
).toBe(BASE_GEMINI_FLASH_MODEL);
// Session B classifier resolving flash should NOT get LATEST_GEMINI_FLASH_MODEL
expect(
resolveClassifierModel(
GEMINI_MODEL_ALIAS_AUTO,
GEMINI_MODEL_ALIAS_FLASH,
false,
false,
true,
sessionBConfig,
false,
false,
),
).toBe(PREVIEW_GEMINI_FLASH_MODEL);
// Session B getDisplayString should NOT return latest models
expect(getDisplayString(BASE_GEMINI_FLASH_MODEL, sessionBConfig)).toBe(
BASE_GEMINI_FLASH_MODEL,
);
expect(
getDisplayString(BASE_GEMINI_FLASH_LITE_MODEL, sessionBConfig),
).toBe(BASE_GEMINI_FLASH_LITE_MODEL);
});
it('should NOT leak latest models in dynamic configuration mode when global models are mutated', () => {
setFlashModels('gemini-3-flash-preview', LATEST_GEMINI_FLASH_MODEL);
setFlashLiteModel(LATEST_GEMINI_FLASH_LITE_MODEL);
const sessionBDynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true,
hasLatestFlashGAAccess: () => false,
hasLatestFlashLiteGAAccess: () => false,
getHasAccessToPreviewModel: () => true,
modelConfigService,
} as unknown as Config;
expect(
resolveModel(
GEMINI_MODEL_ALIAS_FLASH,
false,
false,
true,
sessionBDynamicConfig,
false,
false,
),
).toBe(PREVIEW_GEMINI_FLASH_MODEL);
expect(
resolveModel(
GEMINI_MODEL_ALIAS_FLASH_LITE,
false,
false,
true,
sessionBDynamicConfig,
false,
false,
),
).toBe(BASE_GEMINI_FLASH_LITE_MODEL);
});
});
}); });
+183 -47
View File
@@ -6,6 +6,8 @@
export interface ModelResolutionContext { export interface ModelResolutionContext {
useGemini3_1?: boolean; useGemini3_1?: boolean;
useLatestFlashLite?: boolean;
useLatestFlash?: boolean;
useGemini3_5Flash?: boolean; useGemini3_5Flash?: boolean;
useCustomTools?: boolean; useCustomTools?: boolean;
hasAccessToPreview?: boolean; hasAccessToPreview?: boolean;
@@ -49,6 +51,9 @@ export interface IModelConfigService {
export interface ModelCapabilityContext { export interface ModelCapabilityContext {
readonly modelConfigService: IModelConfigService; readonly modelConfigService: IModelConfigService;
getExperimentalDynamicModelConfiguration(): boolean; getExperimentalDynamicModelConfiguration(): boolean;
hasLatestFlashGAAccess?(): boolean;
hasLatestFlashLiteGAAccess?(): boolean;
getHasAccessToPreviewModel?(): boolean;
} }
export const PREVIEW_GEMINI_MODEL = 'gemini-3-pro-preview'; export const PREVIEW_GEMINI_MODEL = 'gemini-3-pro-preview';
@@ -59,26 +64,43 @@ export const PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL =
// cleaned up. // cleaned up.
export let PREVIEW_GEMINI_FLASH_MODEL = 'gemini-3-flash-preview'; export let PREVIEW_GEMINI_FLASH_MODEL = 'gemini-3-flash-preview';
export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro'; export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro';
// TODO: Set to const and update to 'gemini-3.5-flash' once the experiment for
// 3_5 flash rollut can be cleaned up.
// This is set to either the same as the DEFAULT_GEMINI_3_5_FLASH_MODEL const
// OR the SECONDARY_GEMINI_3_5_FLASH_MODEL depending on which is needed for
// the user's backend as determined by hasGemini35FlashGAAccess in
// packages/core/src/config/config.ts
export let DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash';
export const DEFAULT_GEMINI_3_5_FLASH_MODEL = 'gemini-3.5-flash';
// This is resolved to 3.5 flash in backends where it is used,
// however those backends do not expect to see the string gemini-3.5-flash
// so we need to provide this model as an alternative name in certain instances.
export const SECONDARY_GEMINI_3_5_FLASH_MODEL = 'gemini-3-flash';
// Used to set default flash models based on access // Flash Tier: Base (stable GA) vs. Latest (experiment-gated GA)
// TODO: Cleanup once the experiment for 3_5 flash rollut can be cleaned up. export const BASE_GEMINI_FLASH_MODEL = 'gemini-3.5-flash';
export const LATEST_GEMINI_FLASH_MODEL = 'gemini-3.8-flash';
export const LEGACY_CCPA_FLASH_MODEL = 'gemini-3-flash';
// Backward-compatible aliases
export const DEFAULT_GEMINI_3_5_FLASH_MODEL = BASE_GEMINI_FLASH_MODEL;
export const SECONDARY_GEMINI_3_5_FLASH_MODEL = LEGACY_CCPA_FLASH_MODEL;
// Flash Lite Tier: Base (stable GA) vs. Latest (experiment-gated GA)
export const BASE_GEMINI_FLASH_LITE_MODEL = 'gemini-3.1-flash-lite';
export const LATEST_GEMINI_FLASH_LITE_MODEL = 'gemini-3.5-flash-lite';
// Runtime active defaults (mutated when experiment flags are evaluated)
export let DEFAULT_GEMINI_FLASH_MODEL = BASE_GEMINI_FLASH_MODEL;
export let DEFAULT_GEMINI_FLASH_LITE_MODEL = BASE_GEMINI_FLASH_LITE_MODEL;
export function setFlashModels(preview: string, defaultFlash: string) { export function setFlashModels(preview: string, defaultFlash: string) {
PREVIEW_GEMINI_FLASH_MODEL = preview; PREVIEW_GEMINI_FLASH_MODEL = preview;
DEFAULT_GEMINI_FLASH_MODEL = defaultFlash; DEFAULT_GEMINI_FLASH_MODEL = defaultFlash;
} }
export const DEFAULT_GEMINI_FLASH_LITE_MODEL = 'gemini-3.1-flash-lite';
export function setFlashLiteModel(defaultFlashLite: string) {
DEFAULT_GEMINI_FLASH_LITE_MODEL = defaultFlashLite;
}
/**
* Resets the mutated model constants to their baseline defaults.
* For use in test cleanup to prevent cross-test state leakage.
*/
export function resetModelsForTesting() {
PREVIEW_GEMINI_FLASH_MODEL = 'gemini-3-flash-preview';
DEFAULT_GEMINI_FLASH_MODEL = BASE_GEMINI_FLASH_MODEL;
DEFAULT_GEMINI_FLASH_LITE_MODEL = BASE_GEMINI_FLASH_LITE_MODEL;
}
/** @deprecated Gemini 3.1 Flash Lite is now GA. Use DEFAULT_GEMINI_FLASH_LITE_MODEL. */ /** @deprecated Gemini 3.1 Flash Lite is now GA. Use DEFAULT_GEMINI_FLASH_LITE_MODEL. */
export const PREVIEW_GEMINI_FLASH_LITE_MODEL = 'none'; export const PREVIEW_GEMINI_FLASH_LITE_MODEL = 'none';
@@ -96,11 +118,51 @@ export const VALID_GEMINI_MODELS = new Set([
DEFAULT_GEMINI_3_5_FLASH_MODEL, DEFAULT_GEMINI_3_5_FLASH_MODEL,
SECONDARY_GEMINI_3_5_FLASH_MODEL, SECONDARY_GEMINI_3_5_FLASH_MODEL,
DEFAULT_GEMINI_FLASH_LITE_MODEL, DEFAULT_GEMINI_FLASH_LITE_MODEL,
BASE_GEMINI_FLASH_MODEL,
LATEST_GEMINI_FLASH_MODEL,
LEGACY_CCPA_FLASH_MODEL,
BASE_GEMINI_FLASH_LITE_MODEL,
LATEST_GEMINI_FLASH_LITE_MODEL,
GEMMA_4_31B_IT_MODEL, GEMMA_4_31B_IT_MODEL,
GEMMA_4_26B_A4B_IT_MODEL, GEMMA_4_26B_A4B_IT_MODEL,
]); ]);
export interface BackendMappingContext {
hasLatestFlashGAAccess?: () => boolean;
hasLatestFlashLiteGAAccess?: () => boolean;
}
/**
* Dynamically maps model IDs for outbound backend requests:
* - When LATEST_FLASH_GA_LAUNCHED is true: rewrites BASE_GEMINI_FLASH_MODEL ('gemini-3.5-flash')
* and LEGACY_CCPA_FLASH_MODEL ('gemini-3-flash') -> LATEST_GEMINI_FLASH_MODEL ('gemini-3.8-flash').
* - When LATEST_FLASH_GA_LAUNCHED is false on Code Assist (CCPA): maps 'gemini-3.5-flash' -> 'gemini-3-flash'.
* - When LATEST_FLASH_LITE_GA_LAUNCHED is true: rewrites BASE_GEMINI_FLASH_LITE_MODEL ('gemini-3.1-flash-lite')
* -> LATEST_GEMINI_FLASH_LITE_MODEL ('gemini-3.5-flash-lite').
*/
export function getBackendModelMappings(
context?: BackendMappingContext,
isCodeAssistBackend: boolean = true,
): Record<string, string> {
const mappings: Record<string, string> = {};
const useLatestFlash = context?.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = context?.hasLatestFlashLiteGAAccess?.() ?? false;
if (useLatestFlash) {
mappings[BASE_GEMINI_FLASH_MODEL] = LATEST_GEMINI_FLASH_MODEL;
mappings[LEGACY_CCPA_FLASH_MODEL] = LATEST_GEMINI_FLASH_MODEL;
} else if (isCodeAssistBackend) {
mappings[BASE_GEMINI_FLASH_MODEL] = LEGACY_CCPA_FLASH_MODEL;
}
if (useLatestFlashLite) {
mappings[BASE_GEMINI_FLASH_LITE_MODEL] = LATEST_GEMINI_FLASH_LITE_MODEL;
}
return mappings;
}
/** @deprecated Use GEMINI_MODEL_ALIAS_AUTO instead. */ /** @deprecated Use GEMINI_MODEL_ALIAS_AUTO instead. */
export const PREVIEW_GEMINI_MODEL_AUTO = 'auto-gemini-3'; export const PREVIEW_GEMINI_MODEL_AUTO = 'auto-gemini-3';
/** @deprecated Use GEMINI_MODEL_ALIAS_AUTO instead. */ /** @deprecated Use GEMINI_MODEL_ALIAS_AUTO instead. */
@@ -120,7 +182,7 @@ export const DEFAULT_THINKING_MODE = 8192;
export function getAutoModelDescription( export function getAutoModelDescription(
hasAccessToPreview: boolean, hasAccessToPreview: boolean,
useGemini3_1: boolean = false, useGemini3_1: boolean = false,
useGemini3_5Flash: boolean = false, useLatestFlash: boolean = false,
) { ) {
const proModel = hasAccessToPreview const proModel = hasAccessToPreview
? useGemini3_1 ? useGemini3_1
@@ -128,8 +190,8 @@ export function getAutoModelDescription(
: PREVIEW_GEMINI_MODEL : PREVIEW_GEMINI_MODEL
: DEFAULT_GEMINI_MODEL; : DEFAULT_GEMINI_MODEL;
const flashModel = hasAccessToPreview const flashModel = hasAccessToPreview
? useGemini3_5Flash ? useLatestFlash
? DEFAULT_GEMINI_3_5_FLASH_MODEL ? LATEST_GEMINI_FLASH_MODEL
: PREVIEW_GEMINI_FLASH_MODEL : PREVIEW_GEMINI_FLASH_MODEL
: DEFAULT_GEMINI_FLASH_MODEL; : DEFAULT_GEMINI_FLASH_MODEL;
return `Let Gemini CLI decide the best model for the task: ${getDisplayString(proModel)}, ${getDisplayString(flashModel)}`; return `Let Gemini CLI decide the best model for the task: ${getDisplayString(proModel)}, ${getDisplayString(flashModel)}`;
@@ -141,8 +203,11 @@ export function getAutoModelDescription(
* *
* @param requestedModel The model alias or concrete model name requested by the user. * @param requestedModel The model alias or concrete model name requested by the user.
* @param useGemini3_1 Whether to use Gemini 3.1 Pro Preview for auto/pro aliases. * @param useGemini3_1 Whether to use Gemini 3.1 Pro Preview for auto/pro aliases.
* @param useGemini3_5Flash Whether to use Gemini 3.5 Flash GA. * @param useCustomToolModel Whether to use the custom tool model.
* @param hasAccessToPreview Whether the user has access to preview models. * @param hasAccessToPreview Whether the user has access to preview models.
* @param config Optional config object for dynamic model configuration.
* @param useLatestFlash Whether to use the latest Flash GA model.
* @param useLatestFlashLite Whether to use the latest Flash Lite GA model.
* @returns The resolved concrete model name. * @returns The resolved concrete model name.
*/ */
export function resolveModel( export function resolveModel(
@@ -151,7 +216,8 @@ export function resolveModel(
useCustomToolModel: boolean = false, useCustomToolModel: boolean = false,
hasAccessToPreview: boolean = true, hasAccessToPreview: boolean = true,
config?: ModelCapabilityContext, config?: ModelCapabilityContext,
useGemini3_5Flash: boolean = false, useLatestFlash: boolean = false,
useLatestFlashLite: boolean = false,
): string { ): string {
// Defensive check against non-string inputs at runtime // Defensive check against non-string inputs at runtime
const normalizedModel = Array.isArray(requestedModel) const normalizedModel = Array.isArray(requestedModel)
@@ -160,21 +226,31 @@ export function resolveModel(
? String(requestedModel ?? '').trim() || '' ? String(requestedModel ?? '').trim() || ''
: requestedModel.trim() || ''; : requestedModel.trim() || '';
const effectiveUseLatestFlash =
useLatestFlash || (config?.hasLatestFlashGAAccess?.() ?? false);
const effectiveUseLatestFlashLite =
useLatestFlashLite || (config?.hasLatestFlashLiteGAAccess?.() ?? false);
if (config?.getExperimentalDynamicModelConfiguration?.() === true) { if (config?.getExperimentalDynamicModelConfiguration?.() === true) {
const resolved = config.modelConfigService.resolveModelId(normalizedModel, { const resolved = config.modelConfigService.resolveModelId(normalizedModel, {
useGemini3_1, useGemini3_1,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
hasAccessToPreview, hasAccessToPreview,
useGemini3_5Flash, useLatestFlash: effectiveUseLatestFlash,
useLatestFlashLite: effectiveUseLatestFlashLite,
}); });
if (!hasAccessToPreview && isPreviewModel(resolved, config)) { if (!hasAccessToPreview && isPreviewModel(resolved, config)) {
// Fallback for unknown preview models. // Fallback for unknown preview models.
if (resolved.includes('flash-lite')) { if (resolved.includes('flash-lite')) {
return DEFAULT_GEMINI_FLASH_LITE_MODEL; return effectiveUseLatestFlashLite
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
} }
if (resolved.includes('flash')) { if (resolved.includes('flash')) {
return DEFAULT_GEMINI_FLASH_MODEL; return effectiveUseLatestFlash
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
} }
return DEFAULT_GEMINI_MODEL; return DEFAULT_GEMINI_MODEL;
} }
@@ -208,13 +284,15 @@ export function resolveModel(
break; break;
} }
case GEMINI_MODEL_ALIAS_FLASH: { case GEMINI_MODEL_ALIAS_FLASH: {
resolved = useGemini3_5Flash resolved = effectiveUseLatestFlash
? DEFAULT_GEMINI_FLASH_MODEL ? LATEST_GEMINI_FLASH_MODEL
: PREVIEW_GEMINI_FLASH_MODEL; : PREVIEW_GEMINI_FLASH_MODEL;
break; break;
} }
case GEMINI_MODEL_ALIAS_FLASH_LITE: { case GEMINI_MODEL_ALIAS_FLASH_LITE: {
resolved = DEFAULT_GEMINI_FLASH_LITE_MODEL; resolved = effectiveUseLatestFlashLite
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
break; break;
} }
default: { default: {
@@ -224,22 +302,30 @@ export function resolveModel(
} }
if (resolved === 'none') { if (resolved === 'none') {
return DEFAULT_GEMINI_FLASH_LITE_MODEL; return effectiveUseLatestFlashLite
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
} }
if ( if (
useGemini3_5Flash && effectiveUseLatestFlash &&
isPromotableFlashModel(resolved) && isPromotableFlashModel(resolved) &&
normalizedModel !== PREVIEW_GEMINI_FLASH_MODEL normalizedModel !== PREVIEW_GEMINI_FLASH_MODEL
) { ) {
return DEFAULT_GEMINI_FLASH_MODEL; return LATEST_GEMINI_FLASH_MODEL;
}
if (effectiveUseLatestFlashLite && isPromotableFlashLiteModel(resolved)) {
return LATEST_GEMINI_FLASH_LITE_MODEL;
} }
if (!hasAccessToPreview && isPreviewModel(resolved)) { if (!hasAccessToPreview && isPreviewModel(resolved)) {
// Downgrade to stable models if user lacks preview access. // Downgrade to stable models if user lacks preview access.
switch (resolved) { switch (resolved) {
case PREVIEW_GEMINI_FLASH_MODEL: case PREVIEW_GEMINI_FLASH_MODEL:
return DEFAULT_GEMINI_FLASH_MODEL; return effectiveUseLatestFlash
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
case PREVIEW_GEMINI_MODEL: case PREVIEW_GEMINI_MODEL:
case PREVIEW_GEMINI_3_1_MODEL: case PREVIEW_GEMINI_3_1_MODEL:
case PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL: case PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL:
@@ -247,10 +333,14 @@ export function resolveModel(
default: default:
// Fallback for unknown preview models, preserving original logic. // Fallback for unknown preview models, preserving original logic.
if (resolved.includes('flash-lite')) { if (resolved.includes('flash-lite')) {
return DEFAULT_GEMINI_FLASH_LITE_MODEL; return effectiveUseLatestFlashLite
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
} }
if (resolved.includes('flash')) { if (resolved.includes('flash')) {
return DEFAULT_GEMINI_FLASH_MODEL; return effectiveUseLatestFlash
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
} }
return DEFAULT_GEMINI_MODEL; return DEFAULT_GEMINI_MODEL;
} }
@@ -267,7 +357,17 @@ function isPromotableFlashModel(model: string): boolean {
model === PREVIEW_GEMINI_FLASH_MODEL || model === PREVIEW_GEMINI_FLASH_MODEL ||
model === DEFAULT_GEMINI_3_5_FLASH_MODEL || model === DEFAULT_GEMINI_3_5_FLASH_MODEL ||
model === SECONDARY_GEMINI_3_5_FLASH_MODEL || model === SECONDARY_GEMINI_3_5_FLASH_MODEL ||
model === GEMINI_MODEL_ALIAS_FLASH model === GEMINI_MODEL_ALIAS_FLASH ||
model === BASE_GEMINI_FLASH_MODEL ||
model === LEGACY_CCPA_FLASH_MODEL
);
}
function isPromotableFlashLiteModel(model: string): boolean {
return (
model === DEFAULT_GEMINI_FLASH_LITE_MODEL ||
model === BASE_GEMINI_FLASH_LITE_MODEL ||
model === GEMINI_MODEL_ALIAS_FLASH_LITE
); );
} }
@@ -288,8 +388,16 @@ export function resolveClassifierModel(
useCustomToolModel: boolean = false, useCustomToolModel: boolean = false,
hasAccessToPreview: boolean = true, hasAccessToPreview: boolean = true,
config?: ModelCapabilityContext, config?: ModelCapabilityContext,
useGemini3_5Flash: boolean = false, useLatestFlash: boolean = false,
useLatestFlashLite: boolean = false,
): string { ): string {
const effectiveUseLatestFlash =
useLatestFlash || (config?.hasLatestFlashGAAccess?.() ?? false);
const effectiveUseLatestFlashLite =
useLatestFlashLite || (config?.hasLatestFlashLiteGAAccess?.() ?? false);
const effectiveHasAccessToPreview =
hasAccessToPreview || (config?.getHasAccessToPreviewModel?.() ?? false);
if (config?.getExperimentalDynamicModelConfiguration?.() === true) { if (config?.getExperimentalDynamicModelConfiguration?.() === true) {
return config.modelConfigService.resolveClassifierModelId( return config.modelConfigService.resolveClassifierModelId(
modelAlias, modelAlias,
@@ -297,8 +405,9 @@ export function resolveClassifierModel(
{ {
useGemini3_1, useGemini3_1,
useCustomTools: useCustomToolModel, useCustomTools: useCustomToolModel,
hasAccessToPreview, hasAccessToPreview: effectiveHasAccessToPreview,
useGemini3_5Flash, useLatestFlash: effectiveUseLatestFlash,
useLatestFlashLite: effectiveUseLatestFlashLite,
}, },
); );
} }
@@ -308,36 +417,53 @@ export function resolveClassifierModel(
requestedModel === DEFAULT_GEMINI_MODEL_AUTO || requestedModel === DEFAULT_GEMINI_MODEL_AUTO ||
requestedModel === DEFAULT_GEMINI_MODEL requestedModel === DEFAULT_GEMINI_MODEL
) { ) {
return DEFAULT_GEMINI_FLASH_MODEL; return effectiveUseLatestFlash
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
} }
if ( if (
requestedModel === PREVIEW_GEMINI_MODEL_AUTO || requestedModel === PREVIEW_GEMINI_MODEL_AUTO ||
requestedModel === PREVIEW_GEMINI_MODEL || requestedModel === PREVIEW_GEMINI_MODEL ||
requestedModel === GEMINI_MODEL_ALIAS_AUTO requestedModel === GEMINI_MODEL_ALIAS_AUTO
) { ) {
if (useGemini3_5Flash) { if (effectiveUseLatestFlash) {
return DEFAULT_GEMINI_FLASH_MODEL; return LATEST_GEMINI_FLASH_MODEL;
} }
return hasAccessToPreview return effectiveHasAccessToPreview
? PREVIEW_GEMINI_FLASH_MODEL ? PREVIEW_GEMINI_FLASH_MODEL
: DEFAULT_GEMINI_FLASH_MODEL; : BASE_GEMINI_FLASH_MODEL;
} }
return resolveModel( return resolveModel(
GEMINI_MODEL_ALIAS_FLASH, GEMINI_MODEL_ALIAS_FLASH,
false, false,
false, false,
hasAccessToPreview, effectiveHasAccessToPreview,
config, config,
useGemini3_5Flash, effectiveUseLatestFlash,
effectiveUseLatestFlashLite,
); );
} }
if (modelAlias === GEMINI_MODEL_ALIAS_FLASH_LITE) {
return resolveModel(
GEMINI_MODEL_ALIAS_FLASH_LITE,
false,
false,
effectiveHasAccessToPreview,
config,
effectiveUseLatestFlash,
effectiveUseLatestFlashLite,
);
}
return resolveModel( return resolveModel(
requestedModel, requestedModel,
useGemini3_1, useGemini3_1,
useCustomToolModel, useCustomToolModel,
hasAccessToPreview, effectiveHasAccessToPreview,
config, config,
useGemini3_5Flash, effectiveUseLatestFlash,
effectiveUseLatestFlashLite,
); );
} }
@@ -352,9 +478,19 @@ export function getDisplayString(
} }
} }
const useLatestFlash = config?.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config?.hasLatestFlashLiteGAAccess?.() ?? false;
switch (model) { switch (model) {
case 'gemini-3-flash': case LEGACY_CCPA_FLASH_MODEL:
return DEFAULT_GEMINI_3_5_FLASH_MODEL; case BASE_GEMINI_FLASH_MODEL:
return useLatestFlash
? LATEST_GEMINI_FLASH_MODEL
: BASE_GEMINI_FLASH_MODEL;
case BASE_GEMINI_FLASH_LITE_MODEL:
return useLatestFlashLite
? LATEST_GEMINI_FLASH_LITE_MODEL
: BASE_GEMINI_FLASH_LITE_MODEL;
case GEMINI_MODEL_ALIAS_AUTO: case GEMINI_MODEL_ALIAS_AUTO:
return 'Auto'; return 'Auto';
case PREVIEW_GEMINI_MODEL_AUTO: case PREVIEW_GEMINI_MODEL_AUTO:
@@ -129,6 +129,21 @@ describe('modelStringToModelConfigAlias', () => {
expect(modelStringToModelConfigAlias('gemini-2.5-flash-lite')).toBe( expect(modelStringToModelConfigAlias('gemini-2.5-flash-lite')).toBe(
'chat-compression-2.5-flash-lite', 'chat-compression-2.5-flash-lite',
); );
expect(modelStringToModelConfigAlias('gemini-3.5-flash')).toBe(
'chat-compression-3-flash',
);
expect(modelStringToModelConfigAlias('gemini-3.8-flash')).toBe(
'chat-compression-3-flash',
);
expect(modelStringToModelConfigAlias('gemini-3-flash')).toBe(
'chat-compression-3-flash',
);
expect(modelStringToModelConfigAlias('gemini-3.1-flash-lite')).toBe(
'chat-compression-3.1-flash-lite',
);
expect(modelStringToModelConfigAlias('gemini-3.5-flash-lite')).toBe(
'chat-compression-3.1-flash-lite',
);
}); });
}); });
@@ -25,12 +25,16 @@ import {
} from '../utils/tokenCalculation.js'; } from '../utils/tokenCalculation.js';
import { import {
DEFAULT_GEMINI_FLASH_LITE_MODEL, DEFAULT_GEMINI_FLASH_LITE_MODEL,
DEFAULT_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_FLASH_MODEL,
PREVIEW_GEMINI_3_1_MODEL, PREVIEW_GEMINI_3_1_MODEL,
PREVIEW_GEMINI_FLASH_LITE_MODEL, PREVIEW_GEMINI_FLASH_LITE_MODEL,
BASE_GEMINI_FLASH_MODEL,
LATEST_GEMINI_FLASH_MODEL,
LEGACY_CCPA_FLASH_MODEL,
BASE_GEMINI_FLASH_LITE_MODEL,
LATEST_GEMINI_FLASH_LITE_MODEL,
} from '../config/models.js'; } from '../config/models.js';
import { PreCompressTrigger } from '../hooks/types.js'; import { PreCompressTrigger } from '../hooks/types.js';
@@ -105,16 +109,21 @@ export function modelStringToModelConfigAlias(model: string): string {
case PREVIEW_GEMINI_3_1_MODEL: case PREVIEW_GEMINI_3_1_MODEL:
return 'chat-compression-3-pro'; return 'chat-compression-3-pro';
case PREVIEW_GEMINI_FLASH_MODEL: case PREVIEW_GEMINI_FLASH_MODEL:
case BASE_GEMINI_FLASH_MODEL:
case LATEST_GEMINI_FLASH_MODEL:
case LEGACY_CCPA_FLASH_MODEL:
return 'chat-compression-3-flash'; return 'chat-compression-3-flash';
case PREVIEW_GEMINI_FLASH_LITE_MODEL: case PREVIEW_GEMINI_FLASH_LITE_MODEL:
// fallthrough // fallthrough
case BASE_GEMINI_FLASH_LITE_MODEL:
case DEFAULT_GEMINI_FLASH_LITE_MODEL: case DEFAULT_GEMINI_FLASH_LITE_MODEL:
case LATEST_GEMINI_FLASH_LITE_MODEL:
return 'chat-compression-3.1-flash-lite'; return 'chat-compression-3.1-flash-lite';
case 'gemini-2.5-flash-lite': case 'gemini-2.5-flash-lite':
return 'chat-compression-2.5-flash-lite'; return 'chat-compression-2.5-flash-lite';
case DEFAULT_GEMINI_MODEL: case DEFAULT_GEMINI_MODEL:
return 'chat-compression-2.5-pro'; return 'chat-compression-2.5-pro';
case DEFAULT_GEMINI_FLASH_MODEL: case 'gemini-2.5-flash':
return 'chat-compression-2.5-flash'; return 'chat-compression-2.5-flash';
default: default:
return 'chat-compression-default'; return 'chat-compression-default';
@@ -19,7 +19,6 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
import type { Config } from '../config/config.js'; import type { Config } from '../config/config.js';
import { LoggingContentGenerator } from './loggingContentGenerator.js'; import { LoggingContentGenerator } from './loggingContentGenerator.js';
import { ModelMappingContentGenerator } from './modelMappingContentGenerator.js'; import { ModelMappingContentGenerator } from './modelMappingContentGenerator.js';
import { CCPA_AI_MODEL_MAPPINGS } from '../config/models.js';
import { loadApiKey } from './apiKeyCredentialStorage.js'; import { loadApiKey } from './apiKeyCredentialStorage.js';
import { FakeContentGenerator } from './fakeContentGenerator.js'; import { FakeContentGenerator } from './fakeContentGenerator.js';
import { RecordingContentGenerator } from './recordingContentGenerator.js'; import { RecordingContentGenerator } from './recordingContentGenerator.js';
@@ -155,7 +154,7 @@ describe('createContentGenerator', () => {
expect(createCodeAssistContentGenerator).toHaveBeenCalled(); expect(createCodeAssistContentGenerator).toHaveBeenCalled();
expect(generator).toEqual( expect(generator).toEqual(
new LoggingContentGenerator( new LoggingContentGenerator(
new ModelMappingContentGenerator(mockGenerator, CCPA_AI_MODEL_MAPPINGS), new ModelMappingContentGenerator(mockGenerator, expect.any(Function)),
mockConfig, mockConfig,
), ),
); );
@@ -175,7 +174,7 @@ describe('createContentGenerator', () => {
expect(createCodeAssistContentGenerator).toHaveBeenCalled(); expect(createCodeAssistContentGenerator).toHaveBeenCalled();
expect(generator).toEqual( expect(generator).toEqual(
new LoggingContentGenerator( new LoggingContentGenerator(
new ModelMappingContentGenerator(mockGenerator, CCPA_AI_MODEL_MAPPINGS), new ModelMappingContentGenerator(mockGenerator, expect.any(Function)),
mockConfig, mockConfig,
), ),
); );
@@ -219,7 +218,13 @@ describe('createContentGenerator', () => {
}), }),
}); });
expect(generator).toEqual( expect(generator).toEqual(
new LoggingContentGenerator(mockGenerator.models, mockConfig), new LoggingContentGenerator(
new ModelMappingContentGenerator(
mockGenerator.models,
expect.any(Function),
),
mockConfig,
),
); );
}); });
@@ -832,7 +837,13 @@ describe('createContentGenerator', () => {
}), }),
}); });
expect(generator).toEqual( expect(generator).toEqual(
new LoggingContentGenerator(mockGenerator.models, mockConfig), new LoggingContentGenerator(
new ModelMappingContentGenerator(
mockGenerator.models,
expect.any(Function),
),
mockConfig,
),
); );
}); });
+8 -3
View File
@@ -31,7 +31,7 @@ import { RecordingContentGenerator } from './recordingContentGenerator.js';
import { getVersion, resolveModel } from '../../index.js'; import { getVersion, resolveModel } from '../../index.js';
import type { LlmRole } from '../telemetry/llmRole.js'; import type { LlmRole } from '../telemetry/llmRole.js';
import { ModelMappingContentGenerator } from './modelMappingContentGenerator.js'; import { ModelMappingContentGenerator } from './modelMappingContentGenerator.js';
import { CCPA_AI_MODEL_MAPPINGS } from '../config/models.js'; import { getBackendModelMappings } from '../config/models.js';
/** /**
* Interface abstracting the core functionalities for generating content and counting tokens. * Interface abstracting the core functionalities for generating content and counting tokens.
@@ -303,7 +303,7 @@ export async function createContentGenerator(
gcConfig, gcConfig,
sessionId, sessionId,
), ),
CCPA_AI_MODEL_MAPPINGS, () => getBackendModelMappings(gcConfig, true),
), ),
gcConfig, gcConfig,
); );
@@ -407,7 +407,12 @@ export async function createContentGenerator(
}, },
}), }),
}); });
return new LoggingContentGenerator(googleGenAI.models, gcConfig); return new LoggingContentGenerator(
new ModelMappingContentGenerator(googleGenAI.models, () =>
getBackendModelMappings(gcConfig, false),
),
gcConfig,
);
} }
throw new Error( throw new Error(
`Error creating contentGenerator: Unsupported authType: ${config.authType}`, `Error creating contentGenerator: Unsupported authType: ${config.authType}`,
+2 -2
View File
@@ -166,7 +166,7 @@ describe('GeminiChat', () => {
getTelemetryLogPromptsEnabled: () => true, getTelemetryLogPromptsEnabled: () => true,
getTelemetryTracesEnabled: () => false, getTelemetryTracesEnabled: () => false,
getUsageStatisticsEnabled: () => true, getUsageStatisticsEnabled: () => true,
hasGemini35FlashGAAccess: vi.fn().mockReturnValue(false), hasLatestFlashGAAccess: vi.fn().mockReturnValue(false),
getDebugMode: () => false, getDebugMode: () => false,
getContentGeneratorConfig: vi.fn().mockImplementation(() => ({ getContentGeneratorConfig: vi.fn().mockImplementation(() => ({
authType: 'oauth-personal', authType: 'oauth-personal',
@@ -2306,7 +2306,7 @@ describe('GeminiChat', () => {
}); });
it('should send an explicit versioned Flash model unchanged when Gemini 3.5 Flash GA is enabled', async () => { it('should send an explicit versioned Flash model unchanged when Gemini 3.5 Flash GA is enabled', async () => {
vi.mocked(mockConfig.hasGemini35FlashGAAccess).mockReturnValue(true); vi.mocked(mockConfig.hasLatestFlashGAAccess).mockReturnValue(true);
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue( vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(
(async function* () { (async function* () {
yield { yield {
@@ -98,7 +98,7 @@ describe('GeminiChat Network Retries', () => {
getTelemetryLogPromptsEnabled: () => true, getTelemetryLogPromptsEnabled: () => true,
getTelemetryTracesEnabled: () => false, getTelemetryTracesEnabled: () => false,
getUsageStatisticsEnabled: () => true, getUsageStatisticsEnabled: () => true,
hasGemini35FlashGAAccess: vi.fn().mockReturnValue(false), hasLatestFlashGAAccess: vi.fn().mockReturnValue(false),
getDebugMode: () => false, getDebugMode: () => false,
getContentGeneratorConfig: vi.fn().mockReturnValue({ getContentGeneratorConfig: vi.fn().mockReturnValue({
authType: 'oauth-personal', authType: 'oauth-personal',
@@ -20,7 +20,9 @@ import { normalizeModelId } from '../utils/modelUtils.js';
export class ModelMappingContentGenerator implements ContentGenerator { export class ModelMappingContentGenerator implements ContentGenerator {
constructor( constructor(
private readonly wrapped: ContentGenerator, private readonly wrapped: ContentGenerator,
private readonly mappings: Record<string, string>, private readonly mappings:
| Record<string, string>
| (() => Record<string, string>),
) {} ) {}
getWrapped(): ContentGenerator { getWrapped(): ContentGenerator {
@@ -41,13 +43,15 @@ export class ModelMappingContentGenerator implements ContentGenerator {
private mapModel<T extends { model?: string }>(req: T): T { private mapModel<T extends { model?: string }>(req: T): T {
if (req.model) { if (req.model) {
const activeMappings =
typeof this.mappings === 'function' ? this.mappings() : this.mappings;
const normalizedModel = normalizeModelId(req.model); const normalizedModel = normalizeModelId(req.model);
if (this.mappings[normalizedModel]) { if (activeMappings[normalizedModel]) {
return { return {
...req, ...req,
model: req.model.startsWith('models/') model: req.model.startsWith('models/')
? `models/${this.mappings[normalizedModel]}` ? `models/${activeMappings[normalizedModel]}`
: this.mappings[normalizedModel], : activeMappings[normalizedModel],
}; };
} }
} }
@@ -16,6 +16,8 @@ import {
DEFAULT_GEMINI_MODEL_AUTO, DEFAULT_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
GEMINI_MODEL_ALIAS_AUTO, GEMINI_MODEL_ALIAS_AUTO,
LATEST_GEMINI_FLASH_MODEL,
resetModelsForTesting,
} from '../../config/models.js'; } from '../../config/models.js';
import { AuthType } from '../../core/contentGenerator.js'; import { AuthType } from '../../core/contentGenerator.js';
import { ApprovalMode } from '../../policy/types.js'; import { ApprovalMode } from '../../policy/types.js';
@@ -29,6 +31,7 @@ describe('ApprovalModeStrategy', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
resetModelsForTesting();
strategy = new ApprovalModeStrategy(); strategy = new ApprovalModeStrategy();
mockContext = { mockContext = {
@@ -52,6 +55,8 @@ describe('ApprovalModeStrategy', () => {
getContentGeneratorConfig: vi.fn().mockReturnValue({ getContentGeneratorConfig: vi.fn().mockReturnValue({
authType: AuthType.LOGIN_WITH_GOOGLE, authType: AuthType.LOGIN_WITH_GOOGLE,
}), }),
hasLatestFlashGAAccess: vi.fn().mockReturnValue(false),
hasLatestFlashLiteGAAccess: vi.fn().mockReturnValue(false),
} as unknown as Config; } as unknown as Config;
mockBaseLlmClient = {} as BaseLlmClient; mockBaseLlmClient = {} as BaseLlmClient;
@@ -243,9 +248,9 @@ describe('ApprovalModeStrategy', () => {
expect(decision?.model).toBe(PREVIEW_GEMINI_FLASH_MODEL); expect(decision?.model).toBe(PREVIEW_GEMINI_FLASH_MODEL);
}); });
it('should route to DEFAULT_GEMINI_FLASH_MODEL when hasGemini35FlashGAAccess is true and plan is approved', async () => { it('should route to LATEST_GEMINI_FLASH_MODEL when hasLatestFlashGAAccess is true and plan is approved', async () => {
vi.mocked(mockConfig.getModel).mockReturnValue(GEMINI_MODEL_ALIAS_AUTO); vi.mocked(mockConfig.getModel).mockReturnValue(GEMINI_MODEL_ALIAS_AUTO);
mockConfig.hasGemini35FlashGAAccess = vi.fn().mockReturnValue(true); vi.mocked(mockConfig.hasLatestFlashGAAccess).mockReturnValue(true);
vi.mocked(mockConfig.getApprovalMode).mockReturnValue(ApprovalMode.DEFAULT); vi.mocked(mockConfig.getApprovalMode).mockReturnValue(ApprovalMode.DEFAULT);
vi.mocked(mockConfig.getApprovedPlanPath).mockReturnValue( vi.mocked(mockConfig.getApprovedPlanPath).mockReturnValue(
@@ -258,6 +263,6 @@ describe('ApprovalModeStrategy', () => {
mockBaseLlmClient, mockBaseLlmClient,
); );
expect(decision?.model).toBe(DEFAULT_GEMINI_FLASH_MODEL); expect(decision?.model).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
}); });
@@ -54,7 +54,8 @@ export class ApprovalModeStrategy implements RoutingStrategy {
config.getUseCustomToolModel(), config.getUseCustomToolModel(),
config.getHasAccessToPreviewModel(), config.getHasAccessToPreviewModel(),
]); ]);
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
// 1. Planning Phase: If ApprovalMode === PLAN, explicitly route to the Pro model. // 1. Planning Phase: If ApprovalMode === PLAN, explicitly route to the Pro model.
if (approvalMode === ApprovalMode.PLAN) { if (approvalMode === ApprovalMode.PLAN) {
@@ -65,7 +66,8 @@ export class ApprovalModeStrategy implements RoutingStrategy {
useCustomToolModel, useCustomToolModel,
hasAccessToPreview, hasAccessToPreview,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
); );
return { return {
model: proModel, model: proModel,
@@ -84,7 +86,8 @@ export class ApprovalModeStrategy implements RoutingStrategy {
useCustomToolModel, useCustomToolModel,
hasAccessToPreview, hasAccessToPreview,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
); );
return { return {
model: flashModel, model: flashModel,
@@ -21,6 +21,8 @@ import {
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_3_1_MODEL, PREVIEW_GEMINI_3_1_MODEL,
PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL, PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL,
LATEST_GEMINI_FLASH_MODEL,
resetModelsForTesting,
} from '../../config/models.js'; } from '../../config/models.js';
import { promptIdContext } from '../../utils/promptIdContext.js'; import { promptIdContext } from '../../utils/promptIdContext.js';
import type { Content } from '@google/genai'; import type { Content } from '@google/genai';
@@ -41,6 +43,7 @@ describe('ClassifierStrategy', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
resetModelsForTesting();
strategy = new ClassifierStrategy(); strategy = new ClassifierStrategy();
mockContext = { mockContext = {
@@ -71,6 +74,8 @@ describe('ClassifierStrategy', () => {
getModelAvailabilityService: vi getModelAvailabilityService: vi
.fn() .fn()
.mockReturnValue(new ModelAvailabilityService()), .mockReturnValue(new ModelAvailabilityService()),
hasLatestFlashGAAccess: vi.fn().mockReturnValue(false),
hasLatestFlashLiteGAAccess: vi.fn().mockReturnValue(false),
} as unknown as Config; } as unknown as Config;
mockBaseLlmClient = { mockBaseLlmClient = {
generateJson: vi.fn(), generateJson: vi.fn(),
@@ -523,8 +528,8 @@ describe('ClassifierStrategy', () => {
expect(decision?.model).toBe(PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL); expect(decision?.model).toBe(PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL);
}); });
it('should route to DEFAULT_GEMINI_FLASH_MODEL when hasGemini35FlashGAAccess is true', async () => { it('should route to LATEST_GEMINI_FLASH_MODEL when hasLatestFlashGAAccess is true', async () => {
mockConfig.hasGemini35FlashGAAccess = vi.fn().mockReturnValue(true); mockConfig.hasLatestFlashGAAccess = vi.fn().mockReturnValue(true);
vi.mocked(mockConfig.getModel).mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO); vi.mocked(mockConfig.getModel).mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO);
const mockApiResponse = { const mockApiResponse = {
@@ -542,7 +547,7 @@ describe('ClassifierStrategy', () => {
mockLocalLiteRtLmClient, mockLocalLiteRtLmClient,
); );
expect(decision?.model).toBe(DEFAULT_GEMINI_FLASH_MODEL); expect(decision?.model).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
}); });
}); });
@@ -186,7 +186,8 @@ export class ClassifierStrategy implements RoutingStrategy {
config.getGemini31Launched(), config.getGemini31Launched(),
config.getUseCustomToolModel(), config.getUseCustomToolModel(),
]); ]);
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
const selectedModel = normalizeModelId( const selectedModel = normalizeModelId(
resolveClassifierModel( resolveClassifierModel(
normalizeModelId(model), normalizeModelId(model),
@@ -195,7 +196,8 @@ export class ClassifierStrategy implements RoutingStrategy {
useCustomToolModel, useCustomToolModel,
config.getHasAccessToPreviewModel?.() ?? true, config.getHasAccessToPreviewModel?.() ?? true,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
), ),
); );
@@ -29,7 +29,8 @@ export class DefaultStrategy implements TerminalStrategy {
false, false,
config.getHasAccessToPreviewModel?.() ?? true, config.getHasAccessToPreviewModel?.() ?? true,
config, config,
config.hasGemini35FlashGAAccess?.() ?? false, config.hasLatestFlashGAAccess?.() ?? false,
config.hasLatestFlashLiteGAAccess?.() ?? false,
); );
return { return {
model: defaultModel, model: defaultModel,
@@ -31,7 +31,8 @@ export class FallbackStrategy implements RoutingStrategy {
false, false,
config.getHasAccessToPreviewModel?.() ?? true, config.getHasAccessToPreviewModel?.() ?? true,
config, config,
config.hasGemini35FlashGAAccess?.() ?? false, config.hasLatestFlashGAAccess?.() ?? false,
config.hasLatestFlashLiteGAAccess?.() ?? false,
); );
const service = config.getModelAvailabilityService(); const service = config.getModelAvailabilityService();
const snapshot = service.snapshot(resolvedModel); const snapshot = service.snapshot(resolvedModel);
@@ -13,6 +13,8 @@ import {
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
LATEST_GEMINI_FLASH_MODEL,
resetModelsForTesting,
} from '../../config/models.js'; } from '../../config/models.js';
import type { Content } from '@google/genai'; import type { Content } from '@google/genai';
import { debugLogger } from '../../utils/debugLogger.js'; import { debugLogger } from '../../utils/debugLogger.js';
@@ -30,6 +32,7 @@ describe('GemmaClassifierStrategy', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
resetModelsForTesting();
mockGenerateJson = vi.fn(); mockGenerateJson = vi.fn();
mockConfig = { mockConfig = {
@@ -42,6 +45,8 @@ describe('GemmaClassifierStrategy', () => {
getGemini31Launched: vi.fn().mockResolvedValue(false), getGemini31Launched: vi.fn().mockResolvedValue(false),
getUseCustomToolModel: vi.fn().mockResolvedValue(false), getUseCustomToolModel: vi.fn().mockResolvedValue(false),
getHasAccessToPreviewModel: vi.fn().mockReturnValue(true), getHasAccessToPreviewModel: vi.fn().mockReturnValue(true),
hasLatestFlashGAAccess: vi.fn().mockReturnValue(false),
hasLatestFlashLiteGAAccess: vi.fn().mockReturnValue(false),
} as unknown as Config; } as unknown as Config;
strategy = new GemmaClassifierStrategy(); strategy = new GemmaClassifierStrategy();
@@ -325,8 +330,8 @@ second message
expect(lastTurn!.parts!.at(0)!.text).toEqual(expectedLastTurn); expect(lastTurn!.parts!.at(0)!.text).toEqual(expectedLastTurn);
}); });
it('should route to DEFAULT_GEMINI_FLASH_MODEL when hasGemini35FlashGAAccess is true', async () => { it('should route to LATEST_GEMINI_FLASH_MODEL when hasLatestFlashGAAccess is true', async () => {
mockConfig.hasGemini35FlashGAAccess = vi.fn().mockReturnValue(true); mockConfig.hasLatestFlashGAAccess = vi.fn().mockReturnValue(true);
mockConfig.getModel = () => PREVIEW_GEMINI_MODEL_AUTO; mockConfig.getModel = () => PREVIEW_GEMINI_MODEL_AUTO;
const mockApiResponse = { const mockApiResponse = {
@@ -342,6 +347,6 @@ second message
mockLocalLiteRtLmClient, mockLocalLiteRtLmClient,
); );
expect(decision?.model).toBe(DEFAULT_GEMINI_FLASH_MODEL); expect(decision?.model).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
}); });
@@ -216,7 +216,8 @@ ${formattedHistory}
config.getUseCustomToolModel(), config.getUseCustomToolModel(),
config.getHasAccessToPreviewModel(), config.getHasAccessToPreviewModel(),
]); ]);
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
const selectedModel = resolveClassifierModel( const selectedModel = resolveClassifierModel(
context.requestedModel ?? config.getModel(), context.requestedModel ?? config.getModel(),
@@ -225,7 +226,8 @@ ${formattedHistory}
useCustomToolModel, useCustomToolModel,
hasAccessToPreview, hasAccessToPreview,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
); );
return { return {
@@ -20,7 +20,7 @@ import {
PREVIEW_GEMINI_MODEL_AUTO, PREVIEW_GEMINI_MODEL_AUTO,
DEFAULT_GEMINI_MODEL_AUTO, DEFAULT_GEMINI_MODEL_AUTO,
DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL,
DEFAULT_GEMINI_FLASH_MODEL, LATEST_GEMINI_FLASH_MODEL,
} from '../../config/models.js'; } from '../../config/models.js';
import { promptIdContext } from '../../utils/promptIdContext.js'; import { promptIdContext } from '../../utils/promptIdContext.js';
import type { Content } from '@google/genai'; import type { Content } from '@google/genai';
@@ -896,8 +896,8 @@ describe('NumericalClassifierStrategy', () => {
expect(decision?.model).toBe(PREVIEW_GEMINI_3_1_MODEL); expect(decision?.model).toBe(PREVIEW_GEMINI_3_1_MODEL);
}); });
it('should route to DEFAULT_GEMINI_FLASH_MODEL when hasGemini35FlashGAAccess is true', async () => { it('should route to LATEST_GEMINI_FLASH_MODEL when hasLatestFlashGAAccess is true', async () => {
mockConfig.hasGemini35FlashGAAccess = vi.fn().mockReturnValue(true); mockConfig.hasLatestFlashGAAccess = vi.fn().mockReturnValue(true);
vi.mocked(mockConfig.getModel).mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO); vi.mocked(mockConfig.getModel).mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO);
const mockApiResponse = { const mockApiResponse = {
@@ -915,7 +915,7 @@ describe('NumericalClassifierStrategy', () => {
mockLocalLiteRtLmClient, mockLocalLiteRtLmClient,
); );
expect(decision?.model).toBe(DEFAULT_GEMINI_FLASH_MODEL); expect(decision?.model).toBe(LATEST_GEMINI_FLASH_MODEL);
}); });
}); });
}); });
@@ -184,7 +184,8 @@ export class NumericalClassifierStrategy implements RoutingStrategy {
config.getGemini31Launched(), config.getGemini31Launched(),
config.getUseCustomToolModel(), config.getUseCustomToolModel(),
]); ]);
const useGemini3_5Flash = config.hasGemini35FlashGAAccess?.() ?? false; const useLatestFlash = config.hasLatestFlashGAAccess?.() ?? false;
const useLatestFlashLite = config.hasLatestFlashLiteGAAccess?.() ?? false;
const selectedModel = normalizeModelId( const selectedModel = normalizeModelId(
resolveClassifierModel( resolveClassifierModel(
normalizeModelId(model), normalizeModelId(model),
@@ -193,7 +194,8 @@ export class NumericalClassifierStrategy implements RoutingStrategy {
useCustomToolModel, useCustomToolModel,
config.getHasAccessToPreviewModel?.() ?? true, config.getHasAccessToPreviewModel?.() ?? true,
config, config,
useGemini3_5Flash, useLatestFlash,
useLatestFlashLite,
), ),
); );
@@ -41,7 +41,8 @@ export class OverrideStrategy implements RoutingStrategy {
false, false,
config.getHasAccessToPreviewModel?.() ?? true, config.getHasAccessToPreviewModel?.() ?? true,
config, config,
config.hasGemini35FlashGAAccess?.() ?? false, config.hasLatestFlashGAAccess?.() ?? false,
config.hasLatestFlashLiteGAAccess?.() ?? false,
), ),
metadata: { metadata: {
source: this.name, source: this.name,
@@ -100,7 +100,9 @@ export interface ModelResolution {
export interface ResolutionContext { export interface ResolutionContext {
useGemini3_1?: boolean; useGemini3_1?: boolean;
useGemini3_1FlashLite?: boolean; useGemini3_1FlashLite?: boolean;
useLatestFlashLite?: boolean;
useGemini3_5Flash?: boolean; useGemini3_5Flash?: boolean;
useLatestFlash?: boolean;
useCustomTools?: boolean; useCustomTools?: boolean;
hasAccessToPreview?: boolean; hasAccessToPreview?: boolean;
hasAccessToProModel?: boolean; hasAccessToProModel?: boolean;
@@ -111,10 +113,12 @@ export interface ResolutionContext {
export interface ResolutionCondition { export interface ResolutionCondition {
useGemini3_1?: boolean; useGemini3_1?: boolean;
useGemini3_1FlashLite?: boolean; useGemini3_1FlashLite?: boolean;
useLatestFlashLite?: boolean;
useGemini3_5Flash?: boolean; useGemini3_5Flash?: boolean;
useLatestFlash?: boolean;
useCustomTools?: boolean; useCustomTools?: boolean;
hasAccessToPreview?: boolean; hasAccessToPreview?: boolean;
/** Matches if the current model is in this list. */ hasAccessToProModel?: boolean;
requestedModels?: string[]; requestedModels?: string[];
} }
@@ -160,7 +164,7 @@ export class ModelConfigService {
const definitions = this.config.modelDefinitions ?? {}; const definitions = this.config.modelDefinitions ?? {};
const shouldShowPreviewModels = context.hasAccessToPreview ?? false; const shouldShowPreviewModels = context.hasAccessToPreview ?? false;
const useGemini31 = context.useGemini3_1 ?? false; const useGemini31 = context.useGemini3_1 ?? false;
const useGemini3_5Flash = context.useGemini3_5Flash ?? false; const useLatestFlash = context.useLatestFlash ?? false;
const mainOptions = Object.entries(definitions) const mainOptions = Object.entries(definitions)
.filter(([_, m]) => { .filter(([_, m]) => {
@@ -175,7 +179,7 @@ export class ModelConfigService {
description = getAutoModelDescription( description = getAutoModelDescription(
shouldShowPreviewModels, shouldShowPreviewModels,
useGemini31, useGemini31,
useGemini3_5Flash, useLatestFlash,
); );
} else if (id === 'auto-gemini-3' && useGemini31) { } else if (id === 'auto-gemini-3' && useGemini31) {
description = description.replace('gemini-3-pro', 'gemini-3.1-pro'); description = description.replace('gemini-3-pro', 'gemini-3.1-pro');
@@ -255,14 +259,28 @@ export class ModelConfigService {
switch (key) { switch (key) {
case 'useGemini3_1': case 'useGemini3_1':
return value === context.useGemini3_1; return value === context.useGemini3_1;
case 'useGemini3_1FlashLite': case 'useLatestFlashLite':
return value === context.useGemini3_1FlashLite; case 'useGemini3_1FlashLite': {
case 'useGemini3_5Flash': const actualValue =
return value === context.useGemini3_5Flash; key === 'useLatestFlashLite'
? (context.useLatestFlashLite ?? context.useGemini3_1FlashLite)
: (context.useGemini3_1FlashLite ?? context.useLatestFlashLite);
return value === actualValue;
}
case 'useLatestFlash':
case 'useGemini3_5Flash': {
const actualValue =
key === 'useLatestFlash'
? (context.useLatestFlash ?? context.useGemini3_5Flash)
: (context.useGemini3_5Flash ?? context.useLatestFlash);
return value === actualValue;
}
case 'useCustomTools': case 'useCustomTools':
return value === context.useCustomTools; return value === context.useCustomTools;
case 'hasAccessToPreview': case 'hasAccessToPreview':
return value === context.hasAccessToPreview; return value === context.hasAccessToPreview;
case 'hasAccessToProModel':
return value === context.hasAccessToProModel;
case 'requestedModels': case 'requestedModels':
return ( return (
Array.isArray(value) && Array.isArray(value) &&
@@ -145,6 +145,18 @@
"topK": 64 "topK": 64
} }
}, },
"gemini-3.5-flash-lite": {
"model": "gemini-3.5-flash-lite",
"generateContentConfig": {
"temperature": 1,
"topP": 0.95,
"thinkingConfig": {
"includeThoughts": true,
"thinkingLevel": "HIGH"
},
"topK": 64
}
},
"gemini-3.5-flash": { "gemini-3.5-flash": {
"model": "gemini-3.5-flash", "model": "gemini-3.5-flash",
"generateContentConfig": { "generateContentConfig": {
@@ -157,6 +169,18 @@
"topK": 64 "topK": 64
} }
}, },
"gemini-3.8-flash": {
"model": "gemini-3.8-flash",
"generateContentConfig": {
"temperature": 1,
"topP": 0.95,
"thinkingConfig": {
"includeThoughts": true,
"thinkingLevel": "HIGH"
},
"topK": 64
}
},
"gemma-4-31b-it": { "gemma-4-31b-it": {
"model": "gemma-4-31b-it", "model": "gemma-4-31b-it",
"generateContentConfig": { "generateContentConfig": {
@@ -145,6 +145,18 @@
"topK": 64 "topK": 64
} }
}, },
"gemini-3.5-flash-lite": {
"model": "gemini-3.5-flash-lite",
"generateContentConfig": {
"temperature": 1,
"topP": 0.95,
"thinkingConfig": {
"includeThoughts": true,
"thinkingLevel": "HIGH"
},
"topK": 64
}
},
"gemini-3.5-flash": { "gemini-3.5-flash": {
"model": "gemini-3.5-flash", "model": "gemini-3.5-flash",
"generateContentConfig": { "generateContentConfig": {
@@ -157,6 +169,18 @@
"topK": 64 "topK": 64
} }
}, },
"gemini-3.8-flash": {
"model": "gemini-3.8-flash",
"generateContentConfig": {
"temperature": 1,
"topP": 0.95,
"thinkingConfig": {
"includeThoughts": true,
"thinkingLevel": "HIGH"
},
"topK": 64
}
},
"gemma-4-31b-it": { "gemma-4-31b-it": {
"model": "gemma-4-31b-it", "model": "gemma-4-31b-it",
"generateContentConfig": { "generateContentConfig": {
+1 -1
View File
@@ -34,7 +34,7 @@ describe('parseAndFormatApiError', () => {
); );
expect(result).toContain('[API Error: Rate limit exceeded'); expect(result).toContain('[API Error: Rate limit exceeded');
expect(result).toContain( expect(result).toContain(
'Possible quota limitations in place or slow response times detected. Switching to the gemini-2.5-flash model', `Possible quota limitations in place or slow response times detected. Switching to the ${DEFAULT_GEMINI_FLASH_MODEL} model for the rest of this session.`,
); );
}); });
File diff suppressed because one or more lines are too long