openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 2.2 kB
JavaScript
import"./session-key-BPgKfU2m.mjs";import{n as normalizeAccountId}from"./account-id-3yqrEsRn.mjs";import{n as getGlobalHookRunner}from"./hook-runner-global-DNCi6wD6.mjs";import{t as buildPairingReply}from"./pairing-messages-C-1R3y1_.mjs";import"./pairing-store-DdrlMdAt.mjs";
//!src/pairing/pairing-challenge.ts
async function issuePairingChallenge(e){const{code:t,created:n}=await e.upsertPairingRequest({id:e.senderId,meta:e.meta});if(!n)return{created:false};e.onCreated?.({code:t});const r=e.accountId?normalizeAccountId(e.accountId):void 0;async function runPairingRequestedHook(){const n=getGlobalHookRunner();if(!n?.hasHooks(`channel_pairing_requested`))return;await n.runChannelPairingRequested({channel:e.channel,accountId:r,senderId:e.senderId,code:t,metadata:e.meta},{channelId:e.channel,accountId:r,senderId:e.senderId})}runPairingRequestedHook().catch(()=>void 0);const i=e.buildReplyText?.({code:t,senderIdLine:e.senderIdLine})??buildPairingReply({channel:e.channel,idLine:e.senderIdLine,code:t});try{await e.sendPairingReply(i)}catch(t){e.onReplyError?.(t)}return{created:true,code:t}}
//!src/plugin-sdk/pairing-access.ts
function createScopedPairingAccess(e){const t=normalizeAccountId(e.accountId);return{accountId:t,readAllowFromStore:()=>e.core.channel.pairing.readAllowFromStore({channel:e.channel,accountId:t}),removeAllowFromStoreEntry:n=>e.core.channel.pairing.removeAllowFromStoreEntry({channel:e.channel,accountId:t,entry:n}),readStoreForDmPolicy:(t,n)=>e.core.channel.pairing.readAllowFromStore({channel:t,accountId:normalizeAccountId(n)}),upsertPairingRequest:n=>e.core.channel.pairing.upsertPairingRequest({...n,channel:e.channel,accountId:t})}}
//!src/plugin-sdk/channel-pairing.ts
function createChannelPairingChallengeIssuer(e){return t=>issuePairingChallenge({...t,channel:e.channel,accountId:e.accountId,upsertPairingRequest:e.upsertPairingRequest})}function createChannelPairingController(e){const t=createScopedPairingAccess(e);return{...t,issueChallenge:createChannelPairingChallengeIssuer({channel:e.channel,accountId:t.accountId,upsertPairingRequest:t.upsertPairingRequest})}}export{createChannelPairingController as n,createChannelPairingChallengeIssuer as t};