UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

103 lines (102 loc) • 4.55 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { b as isCronRunSessionKey, l as resolveAgentIdFromSessionKey, s as isUnscopedSessionKeySentinel } from "./session-key-CqAyZeVk.mjs"; import { v as isPluginOwnedBindingMetadata } from "./current-conversation-bindings.kernel-Ap5fhzOe.mjs"; //#region src/channels/conversation-binding-route-facts.ts /** The same normalization governs initial projection and later ownership comparison. */ function resolveConversationBindingSelection(e) { const t = e?.targetSessionKey?.trim(); if (!e || !t) return { kind: "none" }; if (isCronRunSessionKey(t)) return { kind: "none", ignoredCronSessionKey: t }; const n = e.metadata; if (isPluginOwnedBindingMetadata(n)) { const t = n.pluginId.trim(); if (t) return { kind: "plugin", binding: e, pluginId: t, pluginRoot: n.pluginRoot }; } return { kind: "agent", binding: e, sessionKey: t }; } function resolveConversationBindingAgentId(e, t) { const n = e.targetSessionKey.trim(); return resolveAgentIdFromSessionKey(n, isUnscopedSessionKeySentinel(n) ? normalizeOptionalString(e.metadata?.agentId) ?? t : void 0); } const BINDING_ROUTE_FACTS = Symbol.for("openclaw.conversationBindingRouteFacts"); function withConversationBindingRouteFacts(e, t, n, r) { const i = readConversationBindingRouteFacts(e); const a = i && i.conversation.channel === r.channel && i.conversation.accountId === r.accountId && i.conversation.conversationId === r.conversationId && i.conversation.parentConversationId === r.parentConversationId; const o = { agentId: e.agentId, observedAgentId: t.kind === "agent" ? resolveConversationBindingAgentId(t.binding, n) : e.agentId, previous: a ? i.previous : i, fallbackAgentId: n, conversation: Object.freeze({ ...r }) }; let s; if (t.kind === "none" || t.kind === "unavailable") s = Object.freeze({ ...o, kind: t.kind }); else { const { binding: e } = t; const n = { ...o, bindingId: e.bindingId, boundAt: e.boundAt, targetSessionKey: e.targetSessionKey, targetKind: e.targetKind, bindingConversation: Object.freeze({ ...e.conversation }) }; s = t.kind === "plugin" ? Object.freeze({ ...n, kind: "plugin", pluginId: t.pluginId, pluginRoot: t.pluginRoot }) : Object.freeze({ ...n, kind: "agent" }); } return Object.assign(e, { [BINDING_ROUTE_FACTS]: s }); } function readConversationBindingRouteFacts(e) { return e[BINDING_ROUTE_FACTS]; } function copyConversationBindingRouteFacts(e, t) { const n = readConversationBindingRouteFacts(e); const r = e.dispatchSessionKey ?? e.sessionKey; if (n && r === t.SessionKey && n.agentId === t.AgentId) Object.assign(t, { [BINDING_ROUTE_FACTS]: n }); } function matchesConversationBindingRouteFacts(e, t) { if (e.kind === "unavailable") return false; const n = resolveConversationBindingSelection(t); if (n.kind === "none") return e.kind === "none"; if (e.kind === "none" || e.kind !== n.kind) return false; const r = n.binding; if (r.bindingId !== e.bindingId || r.boundAt !== e.boundAt || r.targetSessionKey !== e.targetSessionKey || r.targetKind !== e.targetKind || r.conversation.channel !== e.bindingConversation.channel || r.conversation.accountId !== e.bindingConversation.accountId || r.conversation.conversationId !== e.bindingConversation.conversationId || r.conversation.parentConversationId !== e.bindingConversation.parentConversationId) return false; return e.kind === "plugin" ? n.kind === "plugin" && n.pluginId === e.pluginId && n.pluginRoot === e.pluginRoot : n.kind === "agent" && resolveConversationBindingAgentId(n.binding, e.fallbackAgentId) === e.observedAgentId; } /** Configured routing changes the dispatch owner without changing the inspected selection. */ function projectConfiguredConversationBindingRouteFacts(e) { const t = readConversationBindingRouteFacts(e); return t ? Object.assign({ ...e }, { [BINDING_ROUTE_FACTS]: Object.freeze({ ...t, agentId: e.agentId }) }) : e; } function readConversationBindingRouteObservations(e) { const t = []; for (let n = readConversationBindingRouteFacts(e); n; n = n.previous) t.unshift(n); return t; } //#endregion export { readConversationBindingRouteObservations as a, withConversationBindingRouteFacts as c, readConversationBindingRouteFacts as i, matchesConversationBindingRouteFacts as n, resolveConversationBindingAgentId as o, projectConfiguredConversationBindingRouteFacts as r, resolveConversationBindingSelection as s, copyConversationBindingRouteFacts as t };