@@ -52,6 +52,7 @@ import {
5252 DEFAULT_THINKING_MODE ,
5353 isPreviewModel ,
5454 PREVIEW_GEMINI_MODEL ,
55+ PREVIEW_GEMINI_MODEL_AUTO ,
5556} from './models.js' ;
5657import { shouldAttemptBrowserLaunch } from '../utils/browser.js' ;
5758import 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