fix: harden Gmail hook model defaults (#472) (thanks @koala73)
This commit is contained in:
@@ -9,7 +9,12 @@ import {
|
||||
type ModelCatalogEntry,
|
||||
resetModelCatalogCacheForTest,
|
||||
} from "../agents/model-catalog.js";
|
||||
import { resolveConfiguredModelRef } from "../agents/model-selection.js";
|
||||
import {
|
||||
buildAllowedModelSet,
|
||||
modelKey,
|
||||
resolveConfiguredModelRef,
|
||||
resolveHooksGmailModel,
|
||||
} from "../agents/model-selection.js";
|
||||
import { resolveAnnounceTargetFromKey } from "../agents/tools/sessions-send-helpers.js";
|
||||
import { CANVAS_HOST_PATH } from "../canvas-host/a2ui.js";
|
||||
import {
|
||||
@@ -1763,6 +1768,41 @@ export async function startGatewayServer(
|
||||
}
|
||||
}
|
||||
|
||||
// Validate hooks.gmail.model if configured.
|
||||
if (cfgAtStart.hooks?.gmail?.model) {
|
||||
const hooksModelRef = resolveHooksGmailModel({
|
||||
cfg: cfgAtStart,
|
||||
defaultProvider: DEFAULT_PROVIDER,
|
||||
});
|
||||
if (hooksModelRef) {
|
||||
const { provider: defaultProvider, model: defaultModel } =
|
||||
resolveConfiguredModelRef({
|
||||
cfg: cfgAtStart,
|
||||
defaultProvider: DEFAULT_PROVIDER,
|
||||
defaultModel: DEFAULT_MODEL,
|
||||
});
|
||||
const catalog = await loadModelCatalog({ config: cfgAtStart });
|
||||
const key = modelKey(hooksModelRef.provider, hooksModelRef.model);
|
||||
const allowed = buildAllowedModelSet({
|
||||
cfg: cfgAtStart,
|
||||
catalog,
|
||||
defaultProvider,
|
||||
defaultModel,
|
||||
});
|
||||
if (!allowed.allowAny && !allowed.allowedKeys.has(key)) {
|
||||
logHooks.warn(
|
||||
`hooks.gmail.model "${key}" not in agents.defaults.models allowlist (will use primary instead)`,
|
||||
);
|
||||
}
|
||||
const inCatalog = catalog.some((e) => modelKey(e.provider, e.id) === key);
|
||||
if (!inCatalog) {
|
||||
logHooks.warn(
|
||||
`hooks.gmail.model "${key}" not in the model catalog (may fail at runtime)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Launch configured providers (WhatsApp Web, Discord, Slack, Telegram) so gateway replies via the
|
||||
// surface the message came from. Tests can opt out via CLAWDBOT_SKIP_PROVIDERS.
|
||||
if (process.env.CLAWDBOT_SKIP_PROVIDERS !== "1") {
|
||||
|
||||
Reference in New Issue
Block a user