UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

251 lines (250 loc) • 9.42 kB
import "./number-coercion-D6u-4YD8.mjs"; import "./types.secrets-BmNLLnHp.mjs"; import "./paths-DAcAg5aV.mjs"; import { D as parseThreadSessionSuffix, f as resolveThreadSessionKeys, k as normalizeSessionKeyPreservingOpaquePeerIds } from "./session-key-CqAyZeVk.mjs"; import "./subsystem-BHJiy01V.mjs"; import "./dedupe-DxT0h2gR.mjs"; import { n as getChatChannelMeta, t as findChatChannelMeta } from "./chat-meta-CsbrDHrF.mjs"; import "./keyed-async-queue-DewLnYvW.mjs"; import "./secure-random-CW5OZnK1.mjs"; import "./net-BgRayX-P.mjs"; import "./common-njQNtpnW.mjs"; import { l as emptyChannelConfigSchema } from "./config-schema-BxWrycwn.mjs"; import "./tailscale-status-9Jtz9JNh.mjs"; import "./typebox-BwU4K8-3.mjs"; import "./secret-file-Cb7D2VFr.mjs"; import "./resolve-route-DBnTWpM6.mjs"; import "./delegate-7xQ3O-I9.mjs"; import { t as buildOutboundBaseSessionKey } from "./base-session-key-Bm9XpYsi.mjs"; import { t as normalizeOutboundThreadId } from "./thread-id-BM81lb20.mjs"; import { t as buildAccountScopedDmSecurityPolicy } from "./helpers-ELZNDAnv.mjs"; import { r as createTextPairingAdapter } from "./pairing-adapters-BBSggHHk.mjs"; import { r as createTopLevelChannelReplyToModeResolver, t as createScopedAccountReplyToModeResolver } from "./threading-helpers-DELk4nUS.mjs"; import { i as createAttachedChannelResultAdapter } from "./channel-send-result-D1BUK7_J.mjs"; import { t as createCachedLazyValueGetter } from "./lazy-value-BV7AkcP3.mjs"; import "./config-schema-BjPebUmU.mjs"; import "./plugin-entry-CiJdaHtx.mjs"; import "./config-helpers-DUK5R_HK.mjs"; import "./setup-helpers-CvNcDZst.mjs"; import "./persistent-bindings.resolve-BGQ5AMbv.mjs"; import "./chat-target-prefixes-f6GGnTH0.mjs"; //#region src/plugin-sdk/core.ts /** Ensure a configured ACP binding has live runtime state before channel delivery uses it. */ async function ensureConfiguredAcpBindingReady(e) { return (await import("./persistent-bindings.lifecycle-Cy56ZC9Z.mjs")).ensureConfiguredAcpBindingReadyCore(e); } function getChatChannelMetaForSdk(e) { return getChatChannelMeta(e); } /** * Build the canonical outbound session route payload returned by channel * message adapters. */ function buildChannelOutboundSessionRoute(e) { const t = buildOutboundBaseSessionKey({ cfg: e.cfg, agentId: e.agentId, channel: e.channel, accountId: e.accountId, peer: e.peer }); return { sessionKey: t, baseSessionKey: t, ...e.recipientSessionExact !== void 0 ? { recipientSessionExact: e.recipientSessionExact } : {}, peer: e.peer, chatType: e.chatType, from: e.from, to: e.to, ...e.threadId !== void 0 ? { threadId: e.threadId } : {} }; } /** Recover the current thread id when the current session belongs to the same base route. */ function recoverCurrentThreadSessionId(e) { const t = parseThreadSessionSuffix(e.currentSessionKey); if (!t.baseSessionKey || !t.threadId) return; if (normalizeSessionKeyPreservingOpaquePeerIds(t.baseSessionKey) !== normalizeSessionKeyPreservingOpaquePeerIds(e.route.baseSessionKey)) return; const n = { route: e.route, currentBaseSessionKey: t.baseSessionKey, currentThreadId: t.threadId }; if (e.canRecover && !e.canRecover(n)) return; return t.threadId; } /** Add thread-aware session keys and route thread ids to an outbound channel route. */ function buildThreadAwareOutboundSessionRoute(e) { const t = recoverCurrentThreadSessionId({ route: e.route, currentSessionKey: e.currentSessionKey, canRecover: e.canRecoverCurrentThread }); const n = { replyToId: resolveThreadAwareOutboundCandidate(e.replyToId), threadId: resolveThreadAwareOutboundCandidate(e.threadId), currentSession: resolveThreadAwareOutboundCandidate(t) }; const r = (e.precedence ?? [ "replyToId", "threadId", "currentSession" ]).map((e) => n[e]).find(Boolean); const i = resolveThreadSessionKeys({ baseSessionKey: e.route.baseSessionKey, threadId: r?.sessionThreadId, parentSessionKey: r ? e.parentSessionKey : void 0, useSuffix: e.useSuffix, normalizeThreadId: e.normalizeThreadId }); return { ...e.route, sessionKey: i.sessionKey, ...r !== void 0 ? { threadId: r.routeThreadId } : {} }; } function resolveThreadAwareOutboundCandidate(e) { const t = normalizeOutboundThreadId(e); if (t === void 0) return; return { routeThreadId: typeof e === "number" ? e : t, sessionThreadId: t }; } /** * Canonical entry helper for channel plugins. * * Registers the channel capability and optionally exposes full-runtime hooks * such as tools or gateway handlers outside setup-only registration modes. */ function defineChannelPluginEntry({ id: e, name: t, description: n, plugin: r, configSchema: i, setRuntime: a, registerCliMetadata: o, registerFull: s, registerCapabilities: c }) { const l = createCachedLazyValueGetter(i ?? emptyChannelConfigSchema); return { id: e, name: t, description: n, get configSchema() { return l(); }, register(e) { if (e.registrationMode === "cli-metadata") { o?.(e); return; } if (e.registrationMode === "tool-discovery") { s?.(e); c?.(e); return; } e.registerChannel({ plugin: r }); a?.(e.runtime); if (e.registrationMode === "discovery") { o?.(e); c?.(e); return; } if (e.registrationMode !== "full") return; o?.(e); s?.(e); c?.(e); }, channelPlugin: r, ...a ? { setChannelRuntime: a } : {} }; } /** * Minimal setup-entry helper for channels that ship a separate `setup-entry.ts`. * * The setup entry only needs to export `{ plugin }`, but using this helper * keeps the shape explicit in examples and generated typings. */ function defineSetupPluginEntry(e) { return { plugin: e }; } function resolveChatChannelSecurity(e) { if (!("dm" in e)) return e; return { resolveDmPolicy: ({ cfg: t, accountId: n, account: r }) => buildAccountScopedDmSecurityPolicy({ cfg: t, channelKey: e.dm.channelKey, accountId: n, fallbackAccountId: e.dm.resolveFallbackAccountId?.(r) ?? r.accountId, policy: e.dm.resolvePolicy(r), allowFrom: e.dm.resolveAllowFrom(r) ?? [], defaultPolicy: e.dm.defaultPolicy, allowFromPathSuffix: e.dm.allowFromPathSuffix, policyPathSuffix: e.dm.policyPathSuffix, approveChannelId: e.dm.approveChannelId, approveHint: e.dm.approveHint, normalizeEntry: e.dm.normalizeEntry, classifyEntryAuthentication: e.dm.classifyEntryAuthentication, inheritSharedDefaultsFromDefaultAccount: e.dm.inheritSharedDefaultsFromDefaultAccount }), ...e.dmRouting ? { dmRouting: e.dmRouting } : {}, ...e.collectWarnings ? { collectWarnings: e.collectWarnings } : {}, ...e.collectAuditFindings ? { collectAuditFindings: e.collectAuditFindings } : {} }; } function resolveChatChannelPairing(e) { return "text" in e ? createTextPairingAdapter(e.text) : e; } function resolveChatChannelThreading(e) { if (!("topLevelReplyToMode" in e) && !("scopedAccountReplyToMode" in e)) return e; const t = "topLevelReplyToMode" in e ? createTopLevelChannelReplyToModeResolver(e.topLevelReplyToMode) : createScopedAccountReplyToModeResolver(e.scopedAccountReplyToMode); return { ...e, resolveReplyToMode: t }; } function resolveChatChannelOutbound(e) { if (!("attachedResults" in e)) return e; return { ...e.base, ...createAttachedChannelResultAdapter(e.attachedResults) }; } /** * Build a chat-style channel plugin by composing common security, pairing, * threading, and outbound adapters around a channel-specific base. */ function createChatChannelPlugin(e) { return { ...e.base, capabilities: e.base.capabilities ?? { chatTypes: ["direct"] }, conversationBindings: { supportsCurrentConversationBinding: true, ...e.base.conversationBindings }, ...e.security ? { security: resolveChatChannelSecurity(e.security) } : {}, ...e.pairing ? { pairing: resolveChatChannelPairing(e.pairing) } : {}, ...e.threading ? { threading: resolveChatChannelThreading(e.threading) } : {}, ...e.outbound ? { outbound: resolveChatChannelOutbound(e.outbound) } : {} }; } /** Create the shared base object for channel plugins that override only selected surfaces. */ function createChannelPluginBase(e) { return { id: e.id, meta: { ...findChatChannelMeta(e.id), ...e.meta, id: e.id }, ...e.setupWizard ? { setupWizard: e.setupWizard } : {}, ...e.capabilities ? { capabilities: e.capabilities } : {}, ...e.commands ? { commands: e.commands } : {}, ...e.doctor ? { doctor: e.doctor } : {}, ...e.agentPrompt ? { agentPrompt: e.agentPrompt } : {}, ...e.streaming ? { streaming: e.streaming } : {}, ...e.reload ? { reload: e.reload } : {}, ...e.gatewayMethods ? { gatewayMethods: e.gatewayMethods } : {}, ...e.gatewayMethodDescriptors ? { gatewayMethodDescriptors: e.gatewayMethodDescriptors } : {}, ...e.configSchema ? { configSchema: e.configSchema } : {}, ...e.config ? { config: e.config } : {}, ...e.security ? { security: e.security } : {}, ...e.groups ? { groups: e.groups } : {}, ...e.setup ? { setup: e.setup } : {}, ...e.setupContract ? { setupContract: e.setupContract } : {} }; } //#endregion export { defineChannelPluginEntry as a, getChatChannelMetaForSdk as c, createChatChannelPlugin as i, recoverCurrentThreadSessionId as l, buildThreadAwareOutboundSessionRoute as n, defineSetupPluginEntry as o, createChannelPluginBase as r, ensureConfiguredAcpBindingReady as s, buildChannelOutboundSessionRoute as t };