feat(modelAvailabilityService): integrate model availability service into backend logic (#14470)

This commit is contained in:
Adam Weidman
2025-12-08 06:44:34 -08:00
committed by GitHub
parent 7a72037572
commit 8f4f8baa81
20 changed files with 1611 additions and 119 deletions
+39
View File
@@ -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();
});
});
+19
View File
@@ -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;
}