UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.72 kB
import{n as containsAsciiControlCharacter}from"./string-normalization-D_oBUpO3.mjs";import{n as matchesMentionPatterns,t as buildMentionRegexes}from"./mentions-2eKnPtcO.mjs";import{t as sanitizeChatSendMessageInput}from"./chat-input-sanitize-DesSm-te.mjs"; //!src/gateway/server-methods/chat-human-mentions.ts const INVALID_MENTIONS=`Selected mentions no longer match the message. Select the people again.`;function splitsSurrogate(e,t){const n=e.charCodeAt(t-1);const r=e.charCodeAt(t);return n>=55296&&n<=56319&&r>=56320&&r<=57343}function isHumanAddressedChatMessage(e){const t=e.mentions??[];const n=t[0];if(!n||e.text.slice(0,n.start).trim())return false;let r=``;let i=0;for(const n of t){r+=e.text.slice(i,n.start);i=n.end}r+=e.text.slice(i);return!matchesMentionPatterns(r,buildMentionRegexes(e.cfg,e.agentId))}function normalizeChatHumanMentions(e,t,n){if(!t?.length)return{ok:true,value:void 0};const r=n.length-n.trimStart().length;const i=n.trim();const a=[];let o=0;for(const s of t){const t=e.slice(s.start,s.end);if(s.start<o||s.end>e.length||s.end<=s.start+1||t.length>257||t[0]!==`@`||!t.slice(1).trim()||containsAsciiControlCharacter(t)||splitsSurrogate(e,s.start)||splitsSurrogate(e,s.end))return{ok:false,error:INVALID_MENTIONS};const c=sanitizeChatSendMessageInput(e.slice(0,s.start));const l=sanitizeChatSendMessageInput(e.slice(0,s.end));if(!c.ok||!l.ok||!n.startsWith(l.message))return{ok:false,error:INVALID_MENTIONS};const u=c.message.length-r;const d=l.message.length-r;if(u<0||d>i.length||i[u]!==`@`)return{ok:false,error:INVALID_MENTIONS};a.push({profileId:s.profileId,start:u,end:d});o=s.end}return{ok:true,value:a}}export{normalizeChatHumanMentions as n,isHumanAddressedChatMessage as t};