UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

92 lines (91 loc) • 2.88 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { h as normalizeUniqueSingleOrTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs"; //#region src/channels/channel-config.ts function applyChannelMatchMeta(e, t) { if (t.matchKey && t.matchSource) { e.matchKey = t.matchKey; e.matchSource = t.matchSource; } return e; } /** Resolves a matched entry and preserves the config key that selected it. */ function resolveChannelMatchConfig(e, t) { if (!e.entry) return null; return applyChannelMatchMeta(t(e.entry), e); } function normalizeChannelSlug(e) { return normalizeLowercaseStringOrEmpty(e).replace(/^#/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""); } function buildChannelKeyCandidates(...e) { return normalizeUniqueSingleOrTrimmedStringList(e); } /** Finds a direct channel entry and separately carries a wildcard fallback candidate. */ function resolveChannelEntryMatch(e) { const t = e.entries ?? {}; const n = {}; for (const r of e.keys) { if (!Object.hasOwn(t, r)) continue; n.entry = t[r]; n.key = r; break; } if (e.wildcardKey && Object.hasOwn(t, e.wildcardKey)) { n.wildcardEntry = t[e.wildcardKey]; n.wildcardKey = e.wildcardKey; } return n; } /** Resolves config entry precedence: direct, normalized direct, parent, normalized parent, wildcard. */ function resolveChannelEntryMatchWithFallback(e) { const t = resolveChannelEntryMatch(e); for (const n of ["direct", "parent"]) { const r = n === "direct" ? e.keys : e.parentKeys ?? []; const i = n === "direct" ? t : resolveChannelEntryMatch({ entries: e.entries, keys: r }); let a = i.entry && i.key ? i : void 0; const o = e.normalizeKey; if (!a && o) { const t = r.map((e) => o(e)).filter(Boolean); if (t.length > 0) for (const [n, r] of Object.entries(e.entries ?? {})) { const e = o(n); if (e && t.includes(e)) { a = { entry: r, key: n }; break; } } } if (a) return { ...t, entry: a.entry, key: a.key, ...n === "parent" ? { parentEntry: a.entry, parentKey: a.key } : {}, matchKey: a.key, matchSource: n }; } if (t.wildcardEntry && t.wildcardKey) return { ...t, entry: t.wildcardEntry, key: t.wildcardKey, matchKey: t.wildcardKey, matchSource: "wildcard" }; return t; } /** Resolves nested allowlists where an inner list only applies after the outer list matches. */ function resolveNestedAllowlistDecision(e) { if (!e.outerConfigured) return true; if (!e.outerMatched) return false; if (!e.innerConfigured) return true; return e.innerMatched; } //#endregion export { resolveChannelEntryMatchWithFallback as a, resolveChannelEntryMatch as i, buildChannelKeyCandidates as n, resolveChannelMatchConfig as o, normalizeChannelSlug as r, resolveNestedAllowlistDecision as s, applyChannelMatchMeta as t };