UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

110 lines (109 loc) • 3.4 kB
import "./session-key-CqAyZeVk.mjs"; import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs"; import { n as getGlobalHookRunner } from "./hook-runner-global-DmYyIVDp.mjs"; import { t as buildPairingReply } from "./pairing-messages-DFuL-IRL.mjs"; import "./pairing-store-Dwflz9v8.mjs"; //#region src/pairing/pairing-challenge.ts /** * Shared pairing challenge issuance for DM pairing policy pathways. * Ensures every channel follows the same create-if-missing + reply flow. */ 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 }; } //#endregion //#region src/plugin-sdk/pairing-access.ts /** Scope pairing store operations to one channel/account pair for plugin-facing helpers. */ function createScopedPairingAccess(e) { const t = normalizeAccountId(e.accountId); return { /** Normalized account id used by every channel-scoped pairing store operation. */ accountId: t, /** Read allow-list entries for the scoped channel/account pair. */ readAllowFromStore: () => e.core.channel.pairing.readAllowFromStore({ channel: e.channel, accountId: t }), /** Delete one approval after the owning channel durably consumes it. */ removeAllowFromStoreEntry: (n) => e.core.channel.pairing.removeAllowFromStoreEntry({ channel: e.channel, accountId: t, entry: n }), /** Read another channel/account allow-list for DM policy cross-checks. */ readStoreForDmPolicy: (t, n) => e.core.channel.pairing.readAllowFromStore({ channel: t, accountId: normalizeAccountId(n) }), /** Upsert a pairing request with the scoped channel/account injected. */ upsertPairingRequest: (n) => e.core.channel.pairing.upsertPairingRequest({ ...n, channel: e.channel, accountId: t }) }; } //#endregion //#region src/plugin-sdk/channel-pairing.ts /** Pre-bind the channel id and storage sink for pairing challenges. */ function createChannelPairingChallengeIssuer(e) { return (t) => issuePairingChallenge({ ...t, channel: e.channel, accountId: e.accountId, upsertPairingRequest: e.upsertPairingRequest }); } /** Build the full scoped pairing controller used by channel runtime code. */ function createChannelPairingController(e) { const t = createScopedPairingAccess(e); return { ...t, issueChallenge: createChannelPairingChallengeIssuer({ channel: e.channel, accountId: t.accountId, upsertPairingRequest: t.upsertPairingRequest }) }; } //#endregion export { createChannelPairingController as n, createChannelPairingChallengeIssuer as t };