UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.25 kB
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{E as parseRawSessionConversationRef,O as parseThreadSessionSuffix}from"./session-key-BPgKfU2m.mjs";import{t as normalizeChatType}from"./chat-type-BzCV5nTQ.mjs";import{n as normalizeMessageChannel}from"./message-channel-core-D_hPOadj.mjs";import{t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import"./message-channel-514k57tV.mjs";import{n as resolveSessionConversation,r as resolveSessionConversationRef}from"./session-conversation-DT92KniN.mjs";import{a as resolveChannelEntryMatchWithFallback,n as buildChannelKeyCandidates,r as normalizeChannelSlug}from"./channel-config-DyDYcLse.mjs"; //!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)}export{resolveChannelModelOverride as t};