UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

54 lines (53 loc) 1.95 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js"; import { r as createLazyRuntimeModule } from "./lazy-runtime-CgCh8H_K.js"; import { E as normalizeSessionKeyPreservingOpaquePeerIds } from "./session-key-BnWWjqNc.js"; //#region src/channels/session.ts const loadInboundSessionRuntime = createLazyRuntimeModule(() => import("./inbound.runtime.js")); function shouldSkipPinnedMainDmRouteUpdate(pin) { if (!pin) return false; const owner = normalizeLowercaseStringOrEmpty(pin.ownerRecipient); const sender = normalizeLowercaseStringOrEmpty(pin.senderRecipient); if (!owner || !sender || owner === sender) return false; pin.onSkip?.({ ownerRecipient: pin.ownerRecipient, senderRecipient: pin.senderRecipient }); return true; } async function recordInboundSession(params) { const { storePath, sessionKey, ctx, groupResolution, createIfMissing } = params; const canonicalSessionKey = normalizeSessionKeyPreservingOpaquePeerIds(sessionKey); const runtime = await loadInboundSessionRuntime(); const metaTask = runtime.recordInboundSessionMeta({ storePath, sessionKey: canonicalSessionKey, ctx, groupResolution, createIfMissing }).catch(async (err) => { try { await Promise.resolve(params.onRecordError(err)); } catch {} }); params.trackSessionMetaTask?.(metaTask); const update = params.updateLastRoute; if (!update) return; if (shouldSkipPinnedMainDmRouteUpdate(update.mainDmOwnerPin)) return; const targetSessionKey = normalizeSessionKeyPreservingOpaquePeerIds(update.sessionKey); await runtime.updateSessionLastRoute({ storePath, sessionKey: targetSessionKey, route: update.route, deliveryContext: { channel: update.channel, to: update.to, accountId: update.accountId, threadId: update.threadId }, ctx: targetSessionKey === canonicalSessionKey ? ctx : void 0, groupResolution, createIfMissing }); } //#endregion export { recordInboundSession as t };