openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
50 lines (49 loc) • 2.35 kB
JavaScript
import { t as asBoolean } from "./boolean-By0bZpFH.js";
//#region src/config/dangerous-name-matching.ts
function asObjectRecord(value) {
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
return value;
}
/** Returns true only for the explicit dangerous name-matching opt-in flag. */
function isDangerousNameMatchingEnabled(config) {
return config?.dangerouslyAllowNameMatching === true;
}
/** Resolves account-level dangerous name matching, inheriting the provider flag when unset. */
function resolveDangerousNameMatchingEnabled(input) {
if (typeof input.accountConfig?.dangerouslyAllowNameMatching === "boolean") return input.accountConfig.dangerouslyAllowNameMatching;
return isDangerousNameMatchingEnabled(input.providerConfig);
}
/** Collects provider/account scopes that policy and doctor surfaces can audit. */
function collectProviderDangerousNameMatchingScopes(cfg, provider) {
const scopes = [];
const channels = asObjectRecord(cfg.channels);
if (!channels) return scopes;
const providerCfg = asObjectRecord(channels[provider]);
if (!providerCfg) return scopes;
const providerPrefix = `channels.${provider}`;
const providerDangerousFlagPath = `${providerPrefix}.dangerouslyAllowNameMatching`;
const providerDangerousNameMatchingEnabled = isDangerousNameMatchingEnabled(providerCfg);
scopes.push({
prefix: providerPrefix,
account: providerCfg,
dangerousNameMatchingEnabled: providerDangerousNameMatchingEnabled,
dangerousFlagPath: providerDangerousFlagPath
});
const accounts = asObjectRecord(providerCfg.accounts);
if (!accounts) return scopes;
for (const key of Object.keys(accounts)) {
const account = asObjectRecord(accounts[key]);
if (!account) continue;
const accountPrefix = `${providerPrefix}.accounts.${key}`;
const accountDangerousNameMatching = asBoolean(account.dangerouslyAllowNameMatching);
scopes.push({
prefix: accountPrefix,
account,
dangerousNameMatchingEnabled: accountDangerousNameMatching ?? providerDangerousNameMatchingEnabled,
dangerousFlagPath: accountDangerousNameMatching == null ? providerDangerousFlagPath : `${accountPrefix}.dangerouslyAllowNameMatching`
});
}
return scopes;
}
//#endregion
export { isDangerousNameMatchingEnabled as n, resolveDangerousNameMatchingEnabled as r, collectProviderDangerousNameMatchingScopes as t };