UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

42 lines (41 loc) • 1.91 kB
import { d as normalizeStringEntries } from "./string-normalization-D6DKCpwE.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(entry) { const trimmed = entry.trim(); if (!trimmed.startsWith("accessGroup:")) return null; const name = trimmed.slice(12).trim(); return name.length > 0 ? name : null; } /** * Merges configured DM allowFrom entries with pairing-store sender ids when policy allows it. */ function mergeDmAllowFromSources(params) { const storeEntries = params.dmPolicy === "allowlist" || params.dmPolicy === "open" ? [] : params.storeAllowFrom ?? []; return normalizeStringEntries([...params.allowFrom ?? [], ...storeEntries]); } /** * Resolves the allowFrom entries used for group chats, optionally falling back to DM policy. */ function resolveGroupAllowFromSources(params) { const explicitGroupAllowFrom = Array.isArray(params.groupAllowFrom) && params.groupAllowFrom.length > 0 ? params.groupAllowFrom : void 0; const scoped = explicitGroupAllowFrom ? explicitGroupAllowFrom : params.fallbackToAllowFrom === false ? [] : params.allowFrom ?? []; return normalizeStringEntries(scoped); } /** * Returns the first value that is present, preserving falsy values such as false, 0, and "". */ function firstDefined(...values) { return values.find((value) => value !== void 0); } function isSenderIdAllowed(allow, senderId, allowWhenEmpty) { if (!allow.hasEntries) return allowWhenEmpty; if (allow.hasWildcard) return true; if (!senderId) return false; return allow.entries.includes(senderId); } //#endregion export { parseAccessGroupAllowFromEntry as a, mergeDmAllowFromSources as i, firstDefined as n, resolveGroupAllowFromSources as o, isSenderIdAllowed as r, ACCESS_GROUP_ALLOW_FROM_PREFIX as t };