mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 05:42:54 -07:00
feat(modelAvailabilityService): integrate model availability service into backend logic (#14470)
This commit is contained in:
@@ -1632,3 +1632,42 @@ describe('Config setExperiments logging', () => {
|
||||
debugSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Availability Service Integration', () => {
|
||||
const baseModel = 'test-model';
|
||||
const baseParams: ConfigParameters = {
|
||||
sessionId: 'test',
|
||||
targetDir: '.',
|
||||
debugMode: false,
|
||||
model: baseModel,
|
||||
cwd: '.',
|
||||
};
|
||||
|
||||
it('setActiveModel updates active model and emits event', async () => {
|
||||
const config = new Config(baseParams);
|
||||
const model1 = 'model1';
|
||||
const model2 = 'model2';
|
||||
|
||||
config.setActiveModel(model1);
|
||||
expect(config.getActiveModel()).toBe(model1);
|
||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith(model1);
|
||||
|
||||
config.setActiveModel(model2);
|
||||
expect(config.getActiveModel()).toBe(model2);
|
||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith(model2);
|
||||
});
|
||||
|
||||
it('getActiveModel defaults to configured model if not set', () => {
|
||||
const config = new Config(baseParams);
|
||||
expect(config.getActiveModel()).toBe(baseModel);
|
||||
});
|
||||
|
||||
it('resetTurn delegates to availability service', () => {
|
||||
const config = new Config(baseParams);
|
||||
const service = config.getModelAvailabilityService();
|
||||
const spy = vi.spyOn(service, 'resetTurn');
|
||||
|
||||
config.resetTurn();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -382,6 +382,7 @@ export class Config {
|
||||
private ideMode: boolean;
|
||||
|
||||
private inFallbackMode = false;
|
||||
private _activeModel: string;
|
||||
private readonly maxSessionTurns: number;
|
||||
private readonly listSessions: boolean;
|
||||
private readonly deleteSession: string | undefined;
|
||||
@@ -504,6 +505,7 @@ export class Config {
|
||||
this.fileDiscoveryService = params.fileDiscoveryService ?? null;
|
||||
this.bugCommand = params.bugCommand;
|
||||
this.model = params.model;
|
||||
this._activeModel = params.model;
|
||||
this.enableModelAvailabilityService =
|
||||
params.enableModelAvailabilityService ?? false;
|
||||
this.enableAgents = params.enableAgents ?? false;
|
||||
@@ -810,11 +812,28 @@ export class Config {
|
||||
setModel(newModel: string): void {
|
||||
if (this.model !== newModel || this.inFallbackMode) {
|
||||
this.model = newModel;
|
||||
// When the user explicitly sets a model, that becomes the active model.
|
||||
this._activeModel = newModel;
|
||||
coreEvents.emitModelChanged(newModel);
|
||||
}
|
||||
this.setFallbackMode(false);
|
||||
}
|
||||
|
||||
getActiveModel(): string {
|
||||
return this._activeModel ?? this.model;
|
||||
}
|
||||
|
||||
setActiveModel(model: string): void {
|
||||
if (this._activeModel !== model) {
|
||||
this._activeModel = model;
|
||||
coreEvents.emitModelChanged(model);
|
||||
}
|
||||
}
|
||||
|
||||
resetTurn(): void {
|
||||
this.modelAvailabilityService.resetTurn();
|
||||
}
|
||||
|
||||
isInFallbackMode(): boolean {
|
||||
return this.inFallbackMode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user