openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.08 kB
JavaScript
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{h as normalizeUniqueSingleOrTrimmedStringList}from"./string-normalization-D_oBUpO3.mjs";
//!src/channels/channel-config.ts
function applyChannelMatchMeta(e,t){if(t.matchKey&&t.matchSource){e.matchKey=t.matchKey;e.matchSource=t.matchSource}return e}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)}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}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}function resolveNestedAllowlistDecision(e){if(!e.outerConfigured)return true;if(!e.outerMatched)return false;if(!e.innerConfigured)return true;return e.innerMatched}export{resolveChannelEntryMatchWithFallback as a,resolveChannelEntryMatch as i,buildChannelKeyCandidates as n,resolveChannelMatchConfig as o,normalizeChannelSlug as r,resolveNestedAllowlistDecision as s,applyChannelMatchMeta as t};