UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

87 lines (86 loc) • 3.74 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { D as parseThreadSessionSuffix, T as parseRawSessionConversationRef } from "./session-key-CqAyZeVk.mjs"; import { t as normalizeChatType } from "./chat-type-CL5nBDaO.mjs"; import { n as normalizeMessageChannel } from "./message-channel-core-BbYZT1a-.mjs"; import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs"; import "./message-channel-DTYVLJT1.mjs"; import { n as resolveSessionConversationRef, t as resolveSessionConversation } from "./session-conversation-ANXEVkYh.mjs"; import { a as resolveChannelEntryMatchWithFallback, n as buildChannelKeyCandidates, r as normalizeChannelSlug } from "./channel-config-BaCM1Vmv.mjs"; //#region src/channels/model-overrides.ts function resolveProviderEntry(e, t) { const n = normalizeMessageChannel(t) ?? ""; return e?.[n] ?? e?.[Object.keys(e).find((e) => { return (normalizeMessageChannel(e) ?? "") === n; }) ?? ""]; } function buildChannelCandidates(e) { const t = normalizeMessageChannel(e.channel); const n = normalizeOptionalString(e.groupId); const r = parseRawSessionConversationRef(e.parentSessionKey); const i = (t ? getChannelPlugin(t) : void 0)?.conversationBindings?.buildModelOverrideParentCandidates?.({ parentConversationId: r?.rawId }) ?? []; const a = resolveSessionConversationRef(e.parentSessionKey, { bundledFallback: i.length === 0 }); const o = normalizeChatType(e.groupChatType ?? void 0) === "channel" || a?.kind === "channel" ? "channel" : "group"; const s = resolveSessionConversation({ channel: t ?? "", kind: o, rawId: n ?? "" }); const c = normalizeOptionalString(e.groupChannel); const l = normalizeOptionalString(e.groupSubject); const u = c ? c.replace(/^#/, "") : void 0; const d = l ? l.replace(/^#/, "") : void 0; const f = u ? normalizeChannelSlug(u) : void 0; const p = d ? normalizeChannelSlug(d) : void 0; return { keys: buildChannelKeyCandidates(n, a?.rawId, ...s?.parentConversationCandidates ?? [], ...a?.parentConversationCandidates ?? [], ...i), parentKeys: buildChannelKeyCandidates(c, u, f, l, d, p) }; } function buildGenericParentOverrideCandidates(e) { const t = parseRawSessionConversationRef(e); if (!t) return []; const { baseSessionKey: n, threadId: r } = parseThreadSessionSuffix(t.rawId); return buildChannelKeyCandidates(r ? n : t.rawId); } function expandPeerIds(e, t) { const n = t.toLowerCase() + ":"; const r = []; for (const t of e) if (t != null) { r.push(t); if (t.toLowerCase().startsWith(n)) r.push(t.slice(n.length)); } return r; } function resolveChannelModelOverride(e) { const t = normalizeOptionalString(e.channel); if (!t) return null; const n = e.cfg.channels?.modelByChannel; if (!n) return null; const r = resolveProviderEntry(n, t); if (!r) return null; const resolveMatch = (e, n = []) => { const i = resolveChannelEntryMatchWithFallback({ entries: r, keys: e, parentKeys: n, wildcardKey: "*", normalizeKey: (e) => normalizeOptionalLowercaseString(e) ?? "" }); const a = normalizeOptionalString(i.entry ?? i.wildcardEntry); return a ? { channel: normalizeMessageChannel(t) ?? "", model: a, matchKey: i.matchKey, matchSource: i.matchSource } : null; }; if (normalizeChatType(e.groupChatType ?? void 0) === "direct") { const n = buildChannelKeyCandidates(e.groupId, ...expandPeerIds(e.directUserIds ?? [], t), ...buildGenericParentOverrideCandidates(e.parentSessionKey)); const r = n.length > 0 ? resolveMatch(n) : null; if (r) return r; } const { keys: i, parentKeys: a } = buildChannelCandidates(e); return resolveMatch(i, a); } //#endregion export { resolveChannelModelOverride as t };