UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.86 kB
import{pn as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{a as t,r as n}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import"./openclaw-state-read-openclaw-state-db-B3dGXm7m.mjs";import"./openclaw-state-read-session-key-H2_GWFw8.mjs";import"./openclaw-state-read-account-id-DDW1ANTo.mjs";function describePairingKeyInput(e){if(e===null)return`null`;if(Array.isArray(e))return`array`;if(typeof e==`string`){let t=e.trim();return t?`string length ${t.length}`:`empty string`}return typeof e==`number`&&!Number.isFinite(e)?`non-finite number`:typeof e}function invalidPairingKeyError(e,t,n){return/* @__PURE__ */ Error(`invalid pairing ${e}: ${t}; got ${describePairingKeyInput(n)}`)}function normalizePairingKey(t,n){if(typeof t!=`string`)throw invalidPairingKeyError(n,`expected non-empty string`,t);let r=e(t);if(!r)throw invalidPairingKeyError(n,`expected non-empty string`,t);let i=r.replace(/[\\/:*?"<>|]/g,`_`).replace(/\.\./g,`_`);if(!i||i===`_`)throw invalidPairingKeyError(n,`sanitized key is empty`,t);return i}function safeChannelKey(e){return normalizePairingKey(e,`channel`)}function resolveAllowFromAccountId(t){if(t!=null&&typeof t!=`string`)throw invalidPairingKeyError(`account id`,`expected non-empty string`,t);return e(t)||`default`}function readChannelAllowRows(e,r){let i=t(e);return n(e,i.selectFrom(`channel_pairing_allow_entries`).selectAll().where(`channel_key`,`=`,safeChannelKey(r)).orderBy(`account_id`,`asc`).orderBy(`sort_order`,`asc`).orderBy(`entry`,`asc`)).rows}function readChannelAllowEntries(e,t){let n=readChannelAllowRows(e,t),r={};for(let e of n){let t=resolveAllowFromAccountId(e.account_id);(r[t]??=[]).push(e.entry)}return r}const r={"pairing.allowFrom":(e,t)=>({type:`pairing.allowFrom`,entries:(readChannelAllowEntries(t,e.channel)[e.accountId]??[]).slice()})};export{r as pairingReadOperations};