refactor: centralize model override validation

This commit is contained in:
Peter Steinberger
2026-01-09 20:07:20 +01:00
parent f0a909f6dd
commit 7e81980747
7 changed files with 204 additions and 59 deletions

View File

@@ -10,8 +10,7 @@ import {
resetModelCatalogCacheForTest,
} from "../agents/model-catalog.js";
import {
buildAllowedModelSet,
modelKey,
getModelRefStatus,
resolveConfiguredModelRef,
resolveHooksGmailModel,
} from "../agents/model-selection.js";
@@ -1782,22 +1781,21 @@ export async function startGatewayServer(
defaultModel: DEFAULT_MODEL,
});
const catalog = await loadModelCatalog({ config: cfgAtStart });
const key = modelKey(hooksModelRef.provider, hooksModelRef.model);
const allowed = buildAllowedModelSet({
const status = getModelRefStatus({
cfg: cfgAtStart,
catalog,
ref: hooksModelRef,
defaultProvider,
defaultModel,
});
if (!allowed.allowAny && !allowed.allowedKeys.has(key)) {
if (!status.allowed) {
logHooks.warn(
`hooks.gmail.model "${key}" not in agents.defaults.models allowlist (will use primary instead)`,
`hooks.gmail.model "${status.key}" not in agents.defaults.models allowlist (will use primary instead)`,
);
}
const inCatalog = catalog.some((e) => modelKey(e.provider, e.id) === key);
if (!inCatalog) {
if (!status.inCatalog) {
logHooks.warn(
`hooks.gmail.model "${key}" not in the model catalog (may fail at runtime)`,
`hooks.gmail.model "${status.key}" not in the model catalog (may fail at runtime)`,
);
}
}