UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

57 lines (56 loc) • 2.22 kB
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { a as routeBindingScopeMatches, i as resolveNormalizedRouteBindingMatch, n as normalizeRouteBindingId, r as normalizeRouteBindingRoles, t as normalizeRouteBindingChannelId } from "./binding-scope-C3Xc3l9P.mjs"; import { t as normalizeChatType } from "./chat-type-CL5nBDaO.mjs"; import { r as listConfiguredBindings, t as isRouteBinding } from "./bindings-C2C-UuI7.mjs"; import { c as peerKindMatches } from "./resolve-route-DBnTWpM6.mjs"; //#region src/routing/bound-account-read.ts function resolveNormalizedBoundAccountMatch(e) { const t = resolveNormalizedRouteBindingMatch(e); const n = e.match; if (!t) return null; const r = n.peer && typeof n.peer.id === "string" ? n.peer.id.trim() : void 0; const i = n.peer ? normalizeChatType(n.peer.kind) : void 0; return { ...t, peerId: r || void 0, peerKind: i, guildId: normalizeRouteBindingId(n.guildId) || null, teamId: normalizeRouteBindingId(n.teamId) || null, roles: normalizeRouteBindingRoles(n.roles) }; } function resolveFirstBoundAccountId(e) { const t = normalizeRouteBindingChannelId(e.channelId); if (!t) return; const n = normalizeAgentId(e.agentId); const r = new Set([e.peerId ?? "", ...e.exactPeerIdAliases ?? []].map((e) => e.trim()).filter(Boolean)); const i = r.size > 0; const a = normalizeChatType(e.peerKind); let o; const s = { groupSpace: e.groupSpace, get memberRoleIds() { return e.memberRoleIds ? o ??= new Set(e.memberRoleIds) : void 0; } }; let c; let l; for (const o of listConfiguredBindings(e.cfg)) { if (!isRouteBinding(o)) continue; const e = resolveNormalizedBoundAccountMatch(o); if (!e || e.channelId !== t || e.agentId !== n) continue; if (!routeBindingScopeMatches(e, s)) continue; if (!i) return e.accountId; if (e.peerId === "*") { if (!e.peerKind || !a || !peerKindMatches(e.peerKind, a)) continue; c ??= e.accountId; } else if (e.peerId) { if (e.peerKind && a && !peerKindMatches(e.peerKind, a)) continue; if (r.has(e.peerId)) return e.accountId; } else l ??= e.accountId; } return c ?? l; } //#endregion export { resolveFirstBoundAccountId as t };