UNPKG

@gguf/claw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (50 loc) 2.14 kB
import { c as normalizeAccountId, l as normalizeAgentId } from "./session-key-9yEYlIQe.js"; import { s as normalizeChatChannelId } from "./registry-C8pj8ctW.js"; import { c as resolveDefaultAgentId } from "./agent-scope-OWMdRegz.js"; //#region src/routing/bindings.ts function normalizeBindingChannelId(raw) { const normalized = normalizeChatChannelId(raw); if (normalized) return normalized; return (raw ?? "").trim().toLowerCase() || null; } function listBindings(cfg) { return Array.isArray(cfg.bindings) ? cfg.bindings : []; } function resolveNormalizedBindingMatch(binding) { if (!binding || typeof binding !== "object") return null; const match = binding.match; if (!match || typeof match !== "object") return null; const channelId = normalizeBindingChannelId(match.channel); if (!channelId) return null; const accountId = typeof match.accountId === "string" ? match.accountId.trim() : ""; if (!accountId || accountId === "*") return null; return { agentId: normalizeAgentId(binding.agentId), accountId: normalizeAccountId(accountId), channelId }; } function listBoundAccountIds(cfg, channelId) { const normalizedChannel = normalizeBindingChannelId(channelId); if (!normalizedChannel) return []; const ids = /* @__PURE__ */ new Set(); for (const binding of listBindings(cfg)) { const resolved = resolveNormalizedBindingMatch(binding); if (!resolved || resolved.channelId !== normalizedChannel) continue; ids.add(resolved.accountId); } return Array.from(ids).toSorted((a, b) => a.localeCompare(b)); } function resolveDefaultAgentBoundAccountId(cfg, channelId) { const normalizedChannel = normalizeBindingChannelId(channelId); if (!normalizedChannel) return null; const defaultAgentId = normalizeAgentId(resolveDefaultAgentId(cfg)); for (const binding of listBindings(cfg)) { const resolved = resolveNormalizedBindingMatch(binding); if (!resolved || resolved.channelId !== normalizedChannel || resolved.agentId !== defaultAgentId) continue; return resolved.accountId; } return null; } //#endregion export { listBoundAccountIds as n, resolveDefaultAgentBoundAccountId as r, listBindings as t };