UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 2.98 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { A as normalizeSessionPeerId } from "./session-key-CqAyZeVk.mjs"; import { r as listDeliverableMessageChannels } from "./message-channel-normalize-CFHSufeo.mjs"; import { r as listChannelPlugins } from "./registry-ByqVE5S3.mjs"; import "./message-channel-DTYVLJT1.mjs"; //#region src/config/sessions/group.ts const getGroupSurfaces = () => /* @__PURE__ */ new Set([...listDeliverableMessageChannels(), "webchat"]); function resolveLegacyGroupSessionKey(e) { for (const t of listChannelPlugins()) { const n = t.messaging?.resolveLegacyGroupSessionKey?.(e); if (n) return n; } return null; } function joinOpaqueTail(e, t) { return normalizeOptionalString(e[t]) ? e.slice(t).join(":") : null; } function resolveOriginatingGroupTargetId(e) { const t = normalizeOptionalString(e.ctx.OriginatingTo ?? e.ctx.To) ?? ""; if (!t) return null; const n = t.split(":"); if (n.length < 2) return null; const r = normalizeLowercaseStringOrEmpty(n[0]); const i = normalizeOptionalLowercaseString(n[1]); if ((i === "group" || i === "channel") && (r === e.provider || getGroupSurfaces().has(r))) return joinOpaqueTail(n, 2); if (r === e.provider || [ "chat", "room", "group", "channel" ].includes(r)) return joinOpaqueTail(n, 1); return null; } /** * Resolves channel/group chat context into the persisted group session key. * * Provider-prefixed ids use channel-owned normalization, while legacy plugin resolvers remain a * fallback for older channel surfaces that cannot yet express the generic route shape. */ function resolveGroupSessionKey(e) { const t = normalizeOptionalString(e.From) ?? ""; const n = normalizeOptionalLowercaseString(e.ChatType); const r = n === "channel" ? "channel" : n === "group" ? "group" : void 0; const i = resolveLegacyGroupSessionKey(e); if (!(r === "group" || r === "channel" || t.includes(":group:") || t.includes(":channel:") || i !== null)) return null; const a = normalizeOptionalLowercaseString(e.Provider); const o = t.split(":"); const s = normalizeLowercaseStringOrEmpty(o[0]); const c = s ? getGroupSurfaces().has(s) : false; if (!c && !a && i) return i; const l = c ? s : a ?? i?.channel; if (!l) return null; const u = normalizeOptionalLowercaseString(o[1]); const d = u === "group" || u === "channel"; const f = d ? u : t.includes(":channel:") || r === "channel" ? "channel" : "group"; const p = !d && r ? resolveOriginatingGroupTargetId({ ctx: e, provider: l }) : null; const m = p ? p : c ? d ? joinOpaqueTail(o, 2) : joinOpaqueTail(o, 1) : t; if (!m) return null; const h = normalizeSessionPeerId({ channel: l, peerKind: f, peerId: m }); if (!h) return null; return { key: `${l}:${f}:${h}`, channel: l, id: h, chatType: f === "channel" ? "channel" : "group" }; } //#endregion export { resolveGroupSessionKey as t };