UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

49 lines (48 loc) • 2.13 kB
//#region src/config/dangerous-name-matching.ts function asObjectRecord(value) { if (!value || typeof value !== "object" || Array.isArray(value)) return null; return value; } function asOptionalBoolean(value) { return typeof value === "boolean" ? value : void 0; } function isDangerousNameMatchingEnabled(config) { return config?.dangerouslyAllowNameMatching === true; } function resolveDangerousNameMatchingEnabled(input) { if (typeof input.accountConfig?.dangerouslyAllowNameMatching === "boolean") return input.accountConfig.dangerouslyAllowNameMatching; return isDangerousNameMatchingEnabled(input.providerConfig); } 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 = asOptionalBoolean(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 };