UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

96 lines (95 loc) • 3.85 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { r as normalizeOptionalAccountId } from "./account-id-BqKT3GuY.mjs"; import { t as normalizeChatType } from "./chat-type-CL5nBDaO.mjs"; import { n as normalizeConversationPeerId, t as buildConversationRef } from "./conversation-ref-BiSqlOTe.mjs"; import { r as sessionDeliveryOrigin, t as deliveryContextFromSession } from "./delivery-context.read-BrYAJ7RK.mjs"; //#region src/config/sessions/conversation-identity.ts function normalizeThreadId(e) { if (typeof e === "number" && Number.isFinite(e)) return String(e); return normalizeOptionalString(e); } function normalizeKind(e) { return normalizeChatType(typeof e === "string" ? e : void 0) ?? "direct"; } function resolvePairedOriginPeerId(e) { if (e.kind !== "direct") return; const t = sessionDeliveryOrigin(e.entry); const n = normalizeOptionalString(t?.from); const r = normalizeOptionalString(t?.to); const i = normalizeOptionalLowercaseString(t?.provider); const a = normalizeOptionalLowercaseString(e.deliveryContext?.channel); if (!n || r !== e.deliveryTarget || !i || i !== a || normalizeChatType(t?.chatType) !== e.kind || (normalizeOptionalAccountId(t?.accountId) ?? "default") !== (normalizeOptionalAccountId(e.deliveryContext?.accountId) ?? "default") || normalizeThreadId(t?.threadId) !== normalizeThreadId(e.deliveryContext?.threadId)) return; return n; } /** Builds one stable transport address from authoritative channel route facts. */ function buildConversationIdentity(e) { const t = normalizeOptionalLowercaseString(e.channel); const n = normalizeOptionalString(e.peerId); if (!t || !n) return null; const r = normalizeConversationPeerId(t, n); if (!r) return null; const i = normalizeOptionalString(e.deliveryTarget); if (!i) return null; const a = normalizeOptionalAccountId(e.accountId) ?? "default"; const o = normalizeOptionalString(e.parentConversationRef); const s = o ? o.startsWith("conv_") ? o : buildConversationRef({ channel: t, accountId: a, kind: e.kind, peerId: normalizeConversationPeerId(t, o) }) : void 0; const c = normalizeThreadId(e.threadId); const l = normalizeOptionalString(e.nativeChannelId); const u = normalizeOptionalString(e.nativeDirectUserId); const d = normalizeOptionalString(e.label); return { conversationRef: buildConversationRef({ channel: t, accountId: a, kind: e.kind, peerId: r, parentConversationRef: s, threadId: c }), channel: t, accountId: a, kind: e.kind, peerId: r, deliveryTarget: i, ...s ? { parentConversationRef: s } : {}, ...c ? { threadId: c } : {}, ...l ? { nativeChannelId: l } : {}, ...u ? { nativeDirectUserId: u } : {}, ...d ? { label: d } : {}, ...e.metadata ? { metadata: e.metadata } : {} }; } /** Derives a transport address from the canonical route snapshot persisted on a session. */ function conversationIdentityFromSessionEntry(e, t) { const n = deliveryContextFromSession(e); const r = sessionDeliveryOrigin(e); const i = normalizeKind(e.chatType); const a = normalizeOptionalString(n?.to); const o = a ?? (i === "direct" ? normalizeOptionalString(r?.from) : void 0); const s = Boolean(a); const c = s ? n?.channel : normalizeOptionalString(r?.provider); const l = a ? resolvePairedOriginPeerId({ entry: e, deliveryContext: n, deliveryTarget: a, kind: i }) : void 0; return buildConversationIdentity({ channel: c, accountId: s ? n?.accountId : r?.accountId, kind: i, peerId: t?.peerId ?? l ?? o, deliveryTarget: o, threadId: s ? n?.threadId : r?.threadId, nativeChannelId: r?.nativeChannelId, nativeDirectUserId: r?.nativeDirectUserId, label: e.displayName ?? e.label }); } //#endregion export { conversationIdentityFromSessionEntry as n, buildConversationIdentity as t };