Skip to content

Commit a3947a8

Browse files
gemini-cli-robotmrcabbage972mattKorwel
authored
fix(patch): cherry-pick 601a639 to release/v0.11.0-preview.0-pr-11889 to patch version v0.11.0-preview.0 and create version 0.11.0-preview.1 (#12188)
Co-authored-by: Victor May <mayvic@google.com> Co-authored-by: matt korwel <matt.korwel@gmail.com>
1 parent 9cf8b40 commit a3947a8

2 files changed

Lines changed: 86 additions & 13 deletions

File tree

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

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,29 +574,84 @@ describe('Server Config (config.ts)', () => {
574574
});
575575
});
576576

577-
describe('UseModelRouter Configuration', () => {
578-
it('should default useModelRouter to false when not provided', () => {
579-
const config = new Config(baseParams);
577+
describe('Model Router with Auth', () => {
578+
it('should disable model router by default for oauth-personal', async () => {
579+
const config = new Config({
580+
...baseParams,
581+
useModelRouter: true,
582+
});
583+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
580584
expect(config.getUseModelRouter()).toBe(false);
581585
});
582586

583-
it('should set useModelRouter to true when provided as true', () => {
584-
const paramsWithModelRouter: ConfigParameters = {
587+
it('should enable model router by default for other auth types', async () => {
588+
const config = new Config({
585589
...baseParams,
586590
useModelRouter: true,
587-
};
588-
const config = new Config(paramsWithModelRouter);
591+
});
592+
await config.refreshAuth(AuthType.USE_GEMINI);
593+
expect(config.getUseModelRouter()).toBe(true);
594+
});
595+
596+
it('should disable model router for specified auth type', async () => {
597+
const config = new Config({
598+
...baseParams,
599+
useModelRouter: true,
600+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
601+
});
602+
await config.refreshAuth(AuthType.USE_GEMINI);
603+
expect(config.getUseModelRouter()).toBe(false);
604+
});
605+
606+
it('should enable model router for other auth type', async () => {
607+
const config = new Config({
608+
...baseParams,
609+
useModelRouter: true,
610+
disableModelRouterForAuth: [],
611+
});
612+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
589613
expect(config.getUseModelRouter()).toBe(true);
590614
});
591615

592-
it('should set useModelRouter to false when explicitly provided as false', () => {
593-
const paramsWithModelRouter: ConfigParameters = {
616+
it('should keep model router disabled when useModelRouter is false', async () => {
617+
const config = new Config({
594618
...baseParams,
595619
useModelRouter: false,
596-
};
597-
const config = new Config(paramsWithModelRouter);
620+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
621+
});
622+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
598623
expect(config.getUseModelRouter()).toBe(false);
599624
});
625+
626+
it('should keep the user-chosen model after refreshAuth, even when model router is disabled for the auth type', async () => {
627+
const config = new Config({
628+
...baseParams,
629+
useModelRouter: true,
630+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
631+
});
632+
const chosenModel = 'gemini-1.5-pro-latest';
633+
config.setModel(chosenModel);
634+
635+
await config.refreshAuth(AuthType.USE_GEMINI);
636+
637+
expect(config.getUseModelRouter()).toBe(false);
638+
expect(config.getModel()).toBe(chosenModel);
639+
});
640+
641+
it('should keep the user-chosen model after refreshAuth, when model router is enabled for the auth type', async () => {
642+
const config = new Config({
643+
...baseParams,
644+
useModelRouter: true,
645+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
646+
});
647+
const chosenModel = 'gemini-1.5-pro-latest';
648+
config.setModel(chosenModel);
649+
650+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
651+
652+
expect(config.getUseModelRouter()).toBe(true);
653+
expect(config.getModel()).toBe(chosenModel);
654+
});
600655
});
601656

602657
describe('ContinueOnFailedApiCall Configuration', () => {

packages/core/src/config/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
DEFAULT_GEMINI_EMBEDDING_MODEL,
4848
DEFAULT_GEMINI_FLASH_MODEL,
4949
DEFAULT_GEMINI_MODEL,
50+
DEFAULT_GEMINI_MODEL_AUTO,
5051
DEFAULT_THINKING_MODE,
5152
} from './models.js';
5253
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
@@ -279,6 +280,7 @@ export interface ConfigParameters {
279280
output?: OutputSettings;
280281
useModelRouter?: boolean;
281282
enableMessageBusIntegration?: boolean;
283+
disableModelRouterForAuth?: AuthType[];
282284
codebaseInvestigatorSettings?: CodebaseInvestigatorSettings;
283285
continueOnFailedApiCall?: boolean;
284286
retryFetchErrors?: boolean;
@@ -374,7 +376,9 @@ export class Config {
374376
private readonly messageBus: MessageBus;
375377
private readonly policyEngine: PolicyEngine;
376378
private readonly outputSettings: OutputSettings;
377-
private readonly useModelRouter: boolean;
379+
private useModelRouter: boolean;
380+
private readonly initialUseModelRouter: boolean;
381+
private readonly disableModelRouterForAuth?: AuthType[];
378382
private readonly enableMessageBusIntegration: boolean;
379383
private readonly codebaseInvestigatorSettings: CodebaseInvestigatorSettings;
380384
private readonly continueOnFailedApiCall: boolean;
@@ -470,7 +474,11 @@ export class Config {
470474
this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true;
471475
this.useSmartEdit = params.useSmartEdit ?? true;
472476
this.useWriteTodos = params.useWriteTodos ?? false;
473-
this.useModelRouter = params.useModelRouter ?? false;
477+
this.initialUseModelRouter = params.useModelRouter ?? false;
478+
this.useModelRouter = this.initialUseModelRouter;
479+
this.disableModelRouterForAuth = params.disableModelRouterForAuth ?? [
480+
AuthType.LOGIN_WITH_GOOGLE,
481+
];
474482
this.enableMessageBusIntegration =
475483
params.enableMessageBusIntegration ?? false;
476484
this.codebaseInvestigatorSettings = {
@@ -541,6 +549,16 @@ export class Config {
541549
}
542550

543551
async refreshAuth(authMethod: AuthType) {
552+
this.useModelRouter = this.initialUseModelRouter;
553+
if (this.disableModelRouterForAuth?.includes(authMethod)) {
554+
this.useModelRouter = false;
555+
if (this.model === DEFAULT_GEMINI_MODEL_AUTO) {
556+
this.model = DEFAULT_GEMINI_MODEL;
557+
}
558+
} else if (this.useModelRouter && this.model === DEFAULT_GEMINI_MODEL) {
559+
this.model = DEFAULT_GEMINI_MODEL_AUTO;
560+
}
561+
544562
// Vertex and Genai have incompatible encryption and sending history with
545563
// thoughtSignature from Genai to Vertex will fail, we need to strip them
546564
if (

0 commit comments

Comments
 (0)