openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.05 kB
JavaScript
import{b as uniqueStrings}from"./string-normalization-D_oBUpO3.mjs";import{a as parseAccessGroupAllowFromEntry,t as ACCESS_GROUP_ALLOW_FROM_PREFIX}from"./allow-from-DWjUTXyB.mjs";
//!src/plugin-sdk/access-groups.ts
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}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}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])}export{resolveAccessGroupAllowFromMatches as n,resolveAccessGroupAllowFromState as r,expandAllowFromWithAccessGroups as t};