openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.53 kB
JavaScript
import"./session-key-BPgKfU2m.mjs";import{t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{b as patchChannelConfigForAccount,t as addWildcardAllowFrom}from"./setup-wizard-helpers-k68PnsC_.mjs";
//!src/plugin-sdk/channel-dm-policy.ts
function createChannelDmPolicy(e){const t=e.policyPath??`dmPolicy`;const n=e.allowFromPath??`allowFrom`;const r=`channels.${e.channel}`;const resolveContext=(t,n)=>({cfg:t,requestedAccountId:n,account:e.resolveAccount(t,n)});const resolveDefaultConfigKeys=e=>{const i=e.account.accountId==="default"?r:`${r}.accounts.${e.account.accountId}`;return{policyKey:`${i}.${t}`,allowFromKey:`${i}.${n}`}};return{label:e.label,channel:e.channel,policyKey:e.policyKey??`${r}.${t}`,allowFromKey:e.allowFromKey??`${r}.${n}`,resolveConfigKeys:(t,n)=>{const r=resolveContext(t,n);return(e.resolveConfigKeys??resolveDefaultConfigKeys)(r)},getCurrent:(e,t)=>resolveContext(e,t).account.config.dmPolicy??`pairing`,setPolicy:(t,n,r)=>{const i=resolveContext(t,r);const a={...i,policy:n,allowFrom:e.resolveAllowFrom?e.resolveAllowFrom({...i,policy:n}):n===`open`?addWildcardAllowFrom(i.account.config.allowFrom):void 0};const o=e.buildPatch?.(a)??{dmPolicy:n,...a.allowFrom===void 0?{}:{allowFrom:a.allowFrom}};return e.applyPatch?e.applyPatch({...i,patch:o}):patchChannelConfigForAccount({cfg:t,channel:e.channel,accountId:i.account.accountId,patch:o,setupSurface:typeof e.setupSurface===`function`?e.setupSurface():e.setupSurface})},promptAllowFrom:e.promptAllowFrom}}export{createChannelDmPolicy as t};