Opt-in to persist model from /model (#15820)

This commit is contained in:
Sehoon Shon
2026-01-05 15:31:13 -05:00
committed by GitHub
parent b13c6b57ae
commit e5d183031a
4 changed files with 49 additions and 16 deletions
+3 -3
View File
@@ -1630,19 +1630,19 @@ describe('Config getHooks', () => {
expect(config.getActiveModel()).toBe(originalModel);
});
it('should call onModelChange when a new model is set', () => {
it('should call onModelChange when a new model is set and should persist', () => {
const onModelChange = vi.fn();
const config = new Config({
...baseParams,
onModelChange,
});
config.setModel(DEFAULT_GEMINI_MODEL);
config.setModel(DEFAULT_GEMINI_MODEL, false);
expect(onModelChange).toHaveBeenCalledWith(DEFAULT_GEMINI_MODEL);
});
it('should NOT call onModelChange when a new model is set as a fallback', () => {
it('should NOT call onModelChange when a new model is temporary', () => {
const onModelChange = vi.fn();
const config = new Config({
...baseParams,
+2 -2
View File
@@ -909,13 +909,13 @@ export class Config {
return this.model;
}
setModel(newModel: string, isFallbackModel: boolean = false): void {
setModel(newModel: string, isTemporary: boolean = true): void {
if (this.model !== newModel || this._activeModel !== newModel) {
this.model = newModel;
// When the user explicitly sets a model, that becomes the active model.
this._activeModel = newModel;
coreEvents.emitModelChanged(newModel);
if (this.onModelChange && !isFallbackModel) {
if (this.onModelChange && !isTemporary) {
this.onModelChange(newModel);
}
}