UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.61 kB
import{l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{b as uniqueStrings}from"./string-normalization-D_oBUpO3.mjs"; //!src/channels/plugins/directory-config-helpers.ts function applyDirectoryQueryAndLimit(e,t){const n=normalizeLowercaseStringOrEmpty(t.query);const r=typeof t.limit===`number`&&t.limit>0?t.limit:void 0;const i=[];for(const t of e){if(n&&!normalizeLowercaseStringOrEmpty(t).includes(n))continue;i.push(t);if(typeof r===`number`&&i.length>=r)break}return i}function toDirectoryEntries(e,t){return Array.from(t,t=>({kind:e,id:t}))}function collectDirectoryIds(e,t,n=String){const r=[];for(const i of e){const e=normalizeOptionalString(n(i))??``;if(!e||e===`*`)continue;const a=t?t(e):e;const o=normalizeOptionalString(a)??``;if(o)r.push(o)}return r}function collectNormalizedDirectoryIds(e){return uniqueStrings(e.sources.flatMap(t=>collectDirectoryIds(t,e.normalizeId,normalizeOptionalString)))}function listDirectoryEntriesFromSources(e){const t=collectNormalizedDirectoryIds(e);return toDirectoryEntries(e.kind,applyDirectoryQueryAndLimit(t,e))}function listInspectedDirectoryEntriesFromSources(e){const t=e.inspectAccount(e.cfg,e.accountId);if(!t)return[];return listDirectoryEntriesFromSources({...e,sources:e.resolveSources(t)})}function createInspectedDirectoryEntriesLister(e){return async t=>listInspectedDirectoryEntriesFromSources({...t,...e})}function listResolvedDirectoryEntriesFromSources(e){const t=e.resolveAccount(e.cfg,e.accountId);return listDirectoryEntriesFromSources({...e,sources:e.resolveSources(t)})}function createResolvedDirectoryEntriesLister(e){return async t=>listResolvedDirectoryEntriesFromSources({...t,...e})}function listDirectoryUserEntriesFromAllowFrom(e){return toDirectoryEntries(`user`,applyDirectoryQueryAndLimit(uniqueStrings(collectDirectoryIds(e.allowFrom??[],e.normalizeId)),e))}function listDirectoryUserEntriesFromAllowFromAndMapKeys(e){return toDirectoryEntries(`user`,applyDirectoryQueryAndLimit(uniqueStrings([...collectDirectoryIds(e.allowFrom??[],e.normalizeAllowFromId),...collectDirectoryIds(Object.keys(e.map??{}),e.normalizeMapKeyId)]),e))}function listDirectoryGroupEntriesFromMapKeys(e){return toDirectoryEntries(`group`,applyDirectoryQueryAndLimit(uniqueStrings(collectDirectoryIds(Object.keys(e.groups??{}),e.normalizeId)),e))}function listDirectoryGroupEntriesFromMapKeysAndAllowFrom(e){return toDirectoryEntries(`group`,applyDirectoryQueryAndLimit(uniqueStrings([...collectDirectoryIds(Object.keys(e.groups??{}),e.normalizeMapKeyId),...collectDirectoryIds(e.allowFrom??[],e.normalizeAllowFromId)]),e))}function listResolvedDirectoryUserEntriesFromAllowFrom(e){const t=e.resolveAccount(e.cfg,e.accountId);return listDirectoryUserEntriesFromAllowFrom({...e,allowFrom:e.resolveAllowFrom(t)})}function listResolvedDirectoryGroupEntriesFromMapKeys(e){const t=e.resolveAccount(e.cfg,e.accountId);return listDirectoryGroupEntriesFromMapKeys({...e,groups:e.resolveGroups(t)})}export{listDirectoryEntriesFromSources as a,listDirectoryUserEntriesFromAllowFrom as c,listResolvedDirectoryEntriesFromSources as d,listResolvedDirectoryGroupEntriesFromMapKeys as f,createResolvedDirectoryEntriesLister as i,listDirectoryUserEntriesFromAllowFromAndMapKeys as l,toDirectoryEntries as m,collectNormalizedDirectoryIds as n,listDirectoryGroupEntriesFromMapKeys as o,listResolvedDirectoryUserEntriesFromAllowFrom as p,createInspectedDirectoryEntriesLister as r,listDirectoryGroupEntriesFromMapKeysAndAllowFrom as s,applyDirectoryQueryAndLimit as t,listInspectedDirectoryEntriesFromSources as u};