openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
64 lines (63 loc) • 3.54 kB
JavaScript
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { i as resolveDoctorChannelAccountIds, r as getDoctorChannelCapabilities, t as hasAllowFromEntries } from "./allowlist-Su3Ie_Ov.mjs";
//#region src/commands/doctor/shared/empty-allowlist-scan.ts
function resolveDoctorAccountDmAccess(e, t) {
const n = asNullableRecord(e.dm);
const r = asNullableRecord(t?.dm);
return {
dmPolicy: e.dmPolicy ?? n?.policy ?? t?.dmPolicy ?? r?.policy ?? void 0,
effectiveAllowFrom: e.allowFrom ?? t?.allowFrom ?? n?.allowFrom ?? r?.allowFrom
};
}
function isActiveAccount(e) {
return Boolean(e && typeof e === "object" && asNullableRecord(e)?.enabled !== false);
}
/** Scan all configured channels/accounts for empty allowlist policy warnings. */
async function scanEmptyAllowlistPolicyWarnings(e, t) {
const n = e.channels;
if (!n || typeof n !== "object") return [];
const r = [];
const checkAccount = (e, n, i, a, o = {}) => {
const { dmPolicy: s, effectiveAllowFrom: c } = resolveDoctorAccountDmAccess(e, a);
const l = {
account: e,
channelName: i,
dmPolicy: typeof s === "string" ? s : void 0,
effectiveAllowFrom: Array.isArray(c) ? c : void 0,
parent: a,
prefix: n
};
if (s === "allowlist" && !hasAllowFromEntries(c)) r.push(`- ${n}.dmPolicy is "allowlist" but allowFrom is empty — all DMs will be blocked. Add sender IDs to ${n}.allowFrom, or run "${t.doctorFixCommand}" to auto-migrate from pairing store when entries exist.`);
if ((e.groupPolicy ?? a?.groupPolicy) === "allowlist" && getDoctorChannelCapabilities(i).warnOnEmptyGroupSenderAllowlist && !(i && (o.suppressGroupAllowlistWarning || t.shouldSkipDefaultEmptyGroupAllowlistWarning?.({ ...l })))) {
const t = e.groupAllowFrom ?? a?.groupAllowFrom;
const o = hasAllowFromEntries(t) ? t : void 0;
const s = getDoctorChannelCapabilities(i).groupAllowFromFallbackToAllowFrom;
if (!hasAllowFromEntries(o ?? (s ? c : void 0))) r.push(s ? `- ${n}.groupPolicy is "allowlist" but groupAllowFrom (and allowFrom) is empty — all group messages will be silently dropped. Add sender IDs to ${n}.groupAllowFrom or ${n}.allowFrom, or set groupPolicy to "open".` : `- ${n}.groupPolicy is "allowlist" but groupAllowFrom is empty — this channel does not fall back to allowFrom, so all group messages will be silently dropped. Add sender IDs to ${n}.groupAllowFrom, or set groupPolicy to "open".`);
}
r.push(...t.extraWarningsForAccount?.(l) ?? []);
};
for (const [t, r] of Object.entries(n)) {
if (!isActiveAccount(r)) continue;
const n = asNullableRecord(r.accounts);
const i = Object.values(n ?? {}).filter(isActiveAccount);
const a = await resolveDoctorChannelAccountIds(t, e, Object.keys(n ?? {}));
const o = new Set(a?.configured);
const s = a === void 0 || a.runtime.some((e) => !o.has(e));
const c = i.length > 0 && !s && r.groupPolicy === "allowlist" && i.every((e) => {
const n = e.groupAllowFrom ?? r.groupAllowFrom;
if (hasAllowFromEntries(n)) return true;
if (!getDoctorChannelCapabilities(t).groupAllowFromFallbackToAllowFrom) return false;
const { effectiveAllowFrom: i } = resolveDoctorAccountDmAccess(e, r);
return hasAllowFromEntries(i);
});
checkAccount(r, `channels.${t}`, t, void 0, { suppressGroupAllowlistWarning: c });
if (!n) continue;
for (const [e, i] of Object.entries(n)) {
if (!isActiveAccount(i)) continue;
checkAccount(i, `channels.${t}.accounts.${e}`, t, r);
}
}
return r;
}
//#endregion
export { scanEmptyAllowlistPolicyWarnings as t };