Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/core/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
DEFAULT_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL_AUTO,
} from './models.js';

vi.mock('fs', async (importOriginal) => {
Expand Down Expand Up @@ -792,7 +793,7 @@
it('should disable useWriteTodos for preview models', () => {
const params: ConfigParameters = {
...baseParams,
model: 'gemini-3-pro-preview',

Check warning on line 796 in packages/core/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
};
const config = new Config(params);
expect(config.getUseWriteTodos()).toBe(false);
Expand Down Expand Up @@ -1862,6 +1863,15 @@
expect(config.getModel()).toBe(nonPreviewModel);
});

it('should switch to preview auto model if enabling preview features while using default auto model', () => {
config.setPreviewFeatures(false);
config.setModel(DEFAULT_GEMINI_MODEL_AUTO);

config.setPreviewFeatures(true);

expect(config.getModel()).toBe(PREVIEW_GEMINI_MODEL_AUTO);
});

it('should NOT reset model if enabling preview features', () => {
config.setPreviewFeatures(false);
config.setModel(PREVIEW_GEMINI_MODEL); // Just pretending it was set somehow
Expand Down
25 changes: 16 additions & 9 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
DEFAULT_THINKING_MODE,
isPreviewModel,
PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL_AUTO,
} from './models.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
Expand Down Expand Up @@ -738,8 +739,6 @@ export class Config {
// Initialize BaseLlmClient now that the ContentGenerator is available
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);

const previewFeatures = this.getPreviewFeatures();

const codeAssistServer = getCodeAssistServer(this);
if (codeAssistServer) {
if (codeAssistServer.projectId) {
Expand All @@ -751,7 +750,7 @@ export class Config {
this.setExperiments(experiments);

// 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
if (previewFeatures === undefined) {
if (this.getPreviewFeatures() === undefined) {
const remotePreviewFeatures =
experiments.flags[ExperimentFlags.ENABLE_PREVIEW]?.boolValue;
if (remotePreviewFeatures === true) {
Expand Down Expand Up @@ -975,14 +974,22 @@ export class Config {
}

setPreviewFeatures(previewFeatures: boolean) {
// If it's using a preview model and it's turning off previewFeatures,
// switch the model to the default auto mode.
if (this.previewFeatures && !previewFeatures) {
if (isPreviewModel(this.getModel())) {
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
}
// No change in state, no action needed
if (this.previewFeatures === previewFeatures) {
return;
}
this.previewFeatures = previewFeatures;
const currentModel = this.getModel();

// Case 1: Disabling preview features while on a preview model
if (!previewFeatures && isPreviewModel(currentModel)) {
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
}

// Case 2: Enabling preview features while on the default auto model
else if (previewFeatures && currentModel === DEFAULT_GEMINI_MODEL_AUTO) {
this.setModel(PREVIEW_GEMINI_MODEL_AUTO);
}
}

getHasAccessToPreviewModel(): boolean {
Expand Down