openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
42 lines (41 loc) • 1.64 kB
JavaScript
import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
//#region src/channels/allow-from.ts
/**
* Prefix that marks an allowFrom entry as an access-group reference instead of a sender id.
*/
const ACCESS_GROUP_ALLOW_FROM_PREFIX = "accessGroup:";
function parseAccessGroupAllowFromEntry(e) {
const t = e.trim();
if (!t.startsWith("accessGroup:")) return null;
const n = t.slice(12).trim();
return n.length > 0 ? n : null;
}
/**
* Merges configured DM allowFrom entries with pairing-store sender ids when policy allows it.
*/
function mergeDmAllowFromSources(e) {
const t = e.dmPolicy === "allowlist" || e.dmPolicy === "open" ? [] : e.storeAllowFrom ?? [];
return normalizeStringEntries([...e.allowFrom ?? [], ...t]);
}
/**
* Resolves the allowFrom entries used for group chats, optionally falling back to DM policy.
*/
function resolveGroupAllowFromSources(e) {
const t = Array.isArray(e.groupAllowFrom) && e.groupAllowFrom.length > 0 ? e.groupAllowFrom : void 0;
const n = t ? t : e.fallbackToAllowFrom === false ? [] : e.allowFrom ?? [];
return normalizeStringEntries(n);
}
/**
* Returns the first value that is present, preserving falsy values such as false, 0, and "".
*/
function firstDefined(...e) {
return e.find((e) => e !== void 0);
}
function isSenderIdAllowed(e, t, n) {
if (!e.hasEntries) return n;
if (e.hasWildcard) return true;
if (!t) return false;
return e.entries.includes(t);
}
//#endregion
export { parseAccessGroupAllowFromEntry as a, mergeDmAllowFromSources as i, firstDefined as n, resolveGroupAllowFromSources as o, isSenderIdAllowed as r, ACCESS_GROUP_ALLOW_FROM_PREFIX as t };