Add ModelChain support to ModelConfigService and make ModelDialog dynamic (#22914)

This commit is contained in:
kevinjwang1
2026-03-19 15:22:26 -07:00
committed by GitHub
parent 0e66f545ca
commit 06a7873c51
11 changed files with 1014 additions and 18 deletions
@@ -5,6 +5,7 @@
*/
import type { GenerateContentConfig } from '@google/genai';
import type { ModelPolicy } from '../availability/modelPolicy.js';
// The primary key for the ModelConfig is the model string. However, we also
// support a secondary key to limit the override scope, typically an agent name.
@@ -111,6 +112,7 @@ export interface ModelConfigServiceConfig {
modelDefinitions?: Record<string, ModelDefinition>;
modelIdResolutions?: Record<string, ModelResolution>;
classifierIdResolutions?: Record<string, ModelResolution>;
modelChains?: Record<string, ModelPolicy[]>;
}
const MAX_ALIAS_CHAIN_DEPTH = 100;
@@ -221,6 +223,29 @@ export class ModelConfigService {
return resolution.default;
}
getModelChain(chainName: string): ModelPolicy[] | undefined {
return this.config.modelChains?.[chainName];
}
/**
* Fetches a chain template and resolves all model IDs within it
* based on the provided context.
*/
resolveChain(
chainName: string,
context: ResolutionContext = {},
): ModelPolicy[] | undefined {
const template = this.config.modelChains?.[chainName];
if (!template) {
return undefined;
}
// Map through the template and resolve each model ID
return template.map((policy) => ({
...policy,
model: this.resolveModelId(policy.model, context),
}));
}
registerRuntimeModelConfig(aliasName: string, alias: ModelConfigAlias): void {
this.runtimeAliases[aliasName] = alias;
}