UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (51 loc) • 1.68 kB
import { n as containsAsciiControlCharacter } from "./string-normalization-DLmfYZXI.mjs"; import { t as sanitizeChatSendMessageInput } from "./chat-input-sanitize-DHq_OB9Y.mjs"; //#region 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; } /** Normalize raw selected spans against the request boundary's sanitized message. */ 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 }; } //#endregion export { normalizeChatHumanMentions as t };