UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

86 lines (85 loc) • 2.71 kB
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { a as parseAccessGroupAllowFromEntry, t as ACCESS_GROUP_ALLOW_FROM_PREFIX } from "./allow-from-BGE4RL6B.mjs"; //#region src/plugin-sdk/access-groups.ts /** Resolves `accessGroup:<name>` allowlist entries without changing the original allowlist. */ async function resolveAccessGroupAllowFromState(e) { const t = uniqueStrings((e.allowFrom ?? []).map((e) => parseAccessGroupAllowFromEntry(String(e))).filter((e) => e != null)); const n = { referenced: t, matched: [], missing: [], unsupported: [], failed: [], matchedAllowFromEntries: [], hasReferences: t.length > 0, hasMatch: false }; const r = e.accessGroups; for (const i of t) { const t = r?.[i]; if (!t) { n.missing.push(i); continue; } const a = t.type === "message.senders" ? [...t.members["*"] ?? [], ...t.members[e.channel] ?? []] : []; if (a.length > 0 && e.isSenderAllowed?.(e.senderId, a) === true) { n.matched.push(i); continue; } if (!e.resolveMembership) { if (t.type !== "message.senders") n.unsupported.push(i); continue; } let o; try { o = await e.resolveMembership({ name: i, group: t, channel: e.channel, accountId: e.accountId, senderId: e.senderId }); } catch { n.failed.push(i); continue; } if (o) n.matched.push(i); } n.matchedAllowFromEntries = n.matched.map((e) => `${ACCESS_GROUP_ALLOW_FROM_PREFIX}${e}`); n.hasMatch = n.matchedAllowFromEntries.length > 0; return n; } /** Returns the matched `accessGroup:<name>` allowlist entries for a sender. */ async function resolveAccessGroupAllowFromMatches(e) { const t = e.cfg; const n = e.resolveMembership; return (await resolveAccessGroupAllowFromState({ accessGroups: t?.accessGroups, allowFrom: e.allowFrom, channel: e.channel, accountId: e.accountId, senderId: e.senderId, isSenderAllowed: e.isSenderAllowed, resolveMembership: n && t ? async (e) => await n({ cfg: t, ...e }) : void 0 })).matchedAllowFromEntries; } /** Expands a matching access-group allowlist with the concrete sender entry. */ async function expandAllowFromWithAccessGroups(e) { const t = (e.allowFrom ?? []).map(String); if ((await resolveAccessGroupAllowFromMatches({ cfg: e.cfg, allowFrom: t, channel: e.channel, accountId: e.accountId, senderId: e.senderId, isSenderAllowed: e.isSenderAllowed, resolveMembership: e.resolveMembership })).length === 0) return t; const n = e.senderAllowEntry ?? e.senderId; return uniqueStrings([...t, n]); } //#endregion export { resolveAccessGroupAllowFromMatches as n, resolveAccessGroupAllowFromState as r, expandAllowFromWithAccessGroups as t };