diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index b96baa1c6a9..b0efc9e1e4b 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -597,6 +597,21 @@ export class GeminiChat { ); } + if (beforeModelResult.modifiedModel) { + modelToUse = resolveModel( + beforeModelResult.modifiedModel, + useGemini3_1, + useGemini3_1FlashLite, + false, + hasAccessToPreview, + this.context.config, + ); + lastModelToUse = modelToUse; + // Re-evaluate contentsToUse based on the new model's feature support + contentsToUse = supportsModernFeatures(modelToUse) + ? [...contentsForPreviewModel] + : [...requestContents]; + } if (beforeModelResult.modifiedConfig) { Object.assign(config, beforeModelResult.modifiedConfig); } diff --git a/packages/core/src/hooks/hookSystem.ts b/packages/core/src/hooks/hookSystem.ts index f748665985b..0b943256f38 100644 --- a/packages/core/src/hooks/hookSystem.ts +++ b/packages/core/src/hooks/hookSystem.ts @@ -48,6 +48,8 @@ export interface BeforeModelHookResult { reason?: string; /** Synthetic response to return instead of calling the model (if blocked) */ syntheticResponse?: GenerateContentResponse; + /** Modified model override (if not blocked) */ + modifiedModel?: string; /** Modified config (if not blocked) */ modifiedConfig?: GenerateContentConfig; /** Modified contents (if not blocked) */ @@ -292,6 +294,7 @@ export class HookSystem { beforeModelOutput.applyLLMRequestModifications(llmRequest); return { blocked: false, + modifiedModel: modifiedRequest?.model, modifiedConfig: modifiedRequest?.config, modifiedContents: modifiedRequest?.contents, };