fix(core): propagate BeforeModel hook model override end-to-end (#24784)

Signed-off-by: krishdef7 <gargkrish06@gmail.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
This commit is contained in:
krishdef7
2026-04-07 23:19:26 +05:30
committed by GitHub
parent e432f7c009
commit 68fef8745e
2 changed files with 18 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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,
};