openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
54 lines (53 loc) • 2.17 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs";
import "./session-key-CqAyZeVk.mjs";
import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs";
import { i as normalizeChatChannelId } from "./ids-BRSWrLzE.mjs";
//#region src/routing/binding-scope.ts
function normalizeRouteBindingId(e) {
if (typeof e === "string") return e.trim();
if (typeof e === "number" || typeof e === "bigint") return String(e).trim();
return "";
}
function normalizeRouteBindingRoles(e) {
return Array.isArray(e) && e.length > 0 ? e : null;
}
function normalizeRouteBindingChannelId(e) {
return normalizeChatChannelId(e) || normalizeLowercaseStringOrEmpty(e) || null;
}
function resolveNormalizedRouteBindingMatch(e, t) {
if (!e || typeof e !== "object") return null;
const n = e.match;
if (!n || typeof n !== "object") return null;
const r = normalizeRouteBindingChannelId(n.channel);
if (!r) return null;
if (n.accountId !== void 0 && typeof n.accountId !== "string") return null;
const i = n.accountId?.trim();
if (i === "*" || !i && !t?.includeImplicitDefaultAccount) return null;
return {
agentId: normalizeAgentId(e.agentId),
accountId: normalizeAccountId(i),
channelId: r
};
}
function hasRoleLookup(e) {
return typeof e.has === "function";
}
function hasAnyRouteBindingRole(e, t) {
if (!t) return false;
if (hasRoleLookup(t)) return e.some((e) => t.has(e));
const n = new Set(t);
return e.some((e) => n.has(e));
}
function routeBindingScopeMatches(e, t) {
const n = normalizeRouteBindingId(t.guildId);
const r = normalizeRouteBindingId(t.teamId);
const i = normalizeRouteBindingId(t.groupSpace);
if (e.guildId && e.guildId !== n && e.guildId !== i) return false;
if (e.teamId && e.teamId !== r && e.teamId !== i) return false;
const a = normalizeRouteBindingRoles(e.roles);
if (!a) return true;
return hasAnyRouteBindingRole(a, t.memberRoleIds);
}
//#endregion
export { routeBindingScopeMatches as a, resolveNormalizedRouteBindingMatch as i, normalizeRouteBindingId as n, normalizeRouteBindingRoles as r, normalizeRouteBindingChannelId as t };