UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.06 kB
import{d as normalizeOptionalThreadValue,l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty,u as normalizeOptionalStringifiedId}from"./string-coerce-CpTFcSwY.mjs";import{r as normalizeOptionalAccountId}from"./account-id-3yqrEsRn.mjs"; //!src/plugin-sdk/channel-route.ts function normalizeChannelRouteRef(e){if(!e)return;const t=normalizeLowercaseStringOrEmpty(e.channel);const n=typeof e.accountId===`string`?normalizeOptionalAccountId(e.accountId):void 0;const r=normalizeOptionalString(e.to);const i=normalizeOptionalString(e.rawTo);const a=normalizeOptionalThreadValue(e.threadId);if(!t&&!r&&!n&&a==null)return;return{...t?{channel:t}:{},...n?{accountId:n}:{},...r?{target:{to:r,...i&&i!==r?{rawTo:i}:{},...e.chatType?{chatType:e.chatType}:{}}}:{},...a!=null?{thread:{id:a,...e.threadKind?{kind:e.threadKind}:{},...e.threadSource?{source:e.threadSource}:{}}}:{}}}function channelRouteTarget(e){return e?.target?.to}function channelRouteThreadId(e){return e?.thread?.id}function normalizeChannelRouteTarget(e){return e?normalizeChannelRouteRef(e):void 0}function channelRouteDedupeKey(e){const t=normalizeChannelRouteTarget(e);return JSON.stringify([t?.channel??``,t?.target?.to??``,t?.accountId??``,normalizeOptionalStringifiedId(t?.thread?.id)??``])}function threadIdsEqual(e,t){return normalizeOptionalStringifiedId(e)===normalizeOptionalStringifiedId(t)}function channelRoutesMatchExact(e){const{left:t,right:n}=e;if(!t||!n)return false;return t.channel===n.channel&&t.target?.to===n.target?.to&&(t.accountId??``)===(n.accountId??``)&&threadIdsEqual(t.thread?.id,n.thread?.id)}function channelRoutesShareConversation(e){const{left:t,right:n}=e;if(!t||!n)return false;if(t.channel!==n.channel||t.target?.to!==n.target?.to||t.accountId&&n.accountId&&t.accountId!==n.accountId)return false;if(t.thread?.id==null||n.thread?.id==null)return true;return threadIdsEqual(t.thread.id,n.thread.id)}function channelRouteTargetsMatchExact(e){return channelRoutesMatchExact({left:normalizeChannelRouteTarget(e.left),right:normalizeChannelRouteTarget(e.right)})}function channelRouteTargetsShareConversation(e){return channelRoutesShareConversation({left:normalizeChannelRouteTarget(e.left),right:normalizeChannelRouteTarget(e.right)})}function isChannelRouteRef(e){return`target`in e||`thread`in e}function normalizeChannelRouteKeyInput(e){if(!e)return;return isChannelRouteRef(e)?normalizeChannelRouteRef({channel:e.channel,to:e.target?.to,accountId:e.accountId,threadId:e.thread?.id}):normalizeChannelRouteTarget(e)}function channelRouteCompactKey(e){const t=normalizeChannelRouteKeyInput(e);if(!t?.channel||!t.target?.to)return;return[t.channel,t.target.to,t.accountId??``,normalizeOptionalStringifiedId(t.thread?.id)??``].join(`|`)}export{channelRouteTargetsShareConversation as a,channelRoutesShareConversation as c,channelRouteTargetsMatchExact as i,normalizeChannelRouteRef as l,channelRouteDedupeKey as n,channelRouteThreadId as o,channelRouteTarget as r,channelRoutesMatchExact as s,channelRouteCompactKey as t,normalizeChannelRouteTarget as u};