Skip to content

Commit 8df6104

Browse files
sehoon38jacob314
authored andcommitted
Respect previewFeatures value from the remote flag if undefined (#15214)
1 parent 4b61405 commit 8df6104

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

packages/core/src/config/config.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
DEFAULT_GEMINI_MODEL,
3939
DEFAULT_GEMINI_MODEL_AUTO,
4040
PREVIEW_GEMINI_MODEL,
41+
PREVIEW_GEMINI_MODEL_AUTO,
4142
} from './models.js';
4243

4344
vi.mock('fs', async (importOriginal) => {
@@ -1862,6 +1863,15 @@ describe('Config Quota & Preview Model Access', () => {
18621863
expect(config.getModel()).toBe(nonPreviewModel);
18631864
});
18641865

1866+
it('should switch to preview auto model if enabling preview features while using default auto model', () => {
1867+
config.setPreviewFeatures(false);
1868+
config.setModel(DEFAULT_GEMINI_MODEL_AUTO);
1869+
1870+
config.setPreviewFeatures(true);
1871+
1872+
expect(config.getModel()).toBe(PREVIEW_GEMINI_MODEL_AUTO);
1873+
});
1874+
18651875
it('should NOT reset model if enabling preview features', () => {
18661876
config.setPreviewFeatures(false);
18671877
config.setModel(PREVIEW_GEMINI_MODEL); // Just pretending it was set somehow

packages/core/src/config/config.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
DEFAULT_THINKING_MODE,
5353
isPreviewModel,
5454
PREVIEW_GEMINI_MODEL,
55+
PREVIEW_GEMINI_MODEL_AUTO,
5556
} from './models.js';
5657
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
5758
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
@@ -738,8 +739,6 @@ export class Config {
738739
// Initialize BaseLlmClient now that the ContentGenerator is available
739740
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
740741

741-
const previewFeatures = this.getPreviewFeatures();
742-
743742
const codeAssistServer = getCodeAssistServer(this);
744743
if (codeAssistServer) {
745744
if (codeAssistServer.projectId) {
@@ -751,7 +750,7 @@ export class Config {
751750
this.setExperiments(experiments);
752751

753752
// If preview features have not been set and the user authenticated through Google, we enable preview based on remote config only if it's true
754-
if (previewFeatures === undefined) {
753+
if (this.getPreviewFeatures() === undefined) {
755754
const remotePreviewFeatures =
756755
experiments.flags[ExperimentFlags.ENABLE_PREVIEW]?.boolValue;
757756
if (remotePreviewFeatures === true) {
@@ -975,14 +974,22 @@ export class Config {
975974
}
976975

977976
setPreviewFeatures(previewFeatures: boolean) {
978-
// If it's using a preview model and it's turning off previewFeatures,
979-
// switch the model to the default auto mode.
980-
if (this.previewFeatures && !previewFeatures) {
981-
if (isPreviewModel(this.getModel())) {
982-
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
983-
}
977+
// No change in state, no action needed
978+
if (this.previewFeatures === previewFeatures) {
979+
return;
984980
}
985981
this.previewFeatures = previewFeatures;
982+
const currentModel = this.getModel();
983+
984+
// Case 1: Disabling preview features while on a preview model
985+
if (!previewFeatures && isPreviewModel(currentModel)) {
986+
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
987+
}
988+
989+
// Case 2: Enabling preview features while on the default auto model
990+
else if (previewFeatures && currentModel === DEFAULT_GEMINI_MODEL_AUTO) {
991+
this.setModel(PREVIEW_GEMINI_MODEL_AUTO);
992+
}
986993
}
987994

988995
getHasAccessToPreviewModel(): boolean {

0 commit comments

Comments
 (0)