Files
openclaw/src/auto-reply/reply/inbound-text.ts
2026-03-02 06:19:16 +00:00

19 lines
815 B
TypeScript

export function normalizeInboundTextNewlines(input: string): string {
// Normalize actual newline characters (CR+LF and CR to LF).
// Do NOT replace literal backslash-n sequences (\\n) as they may be part of
// Windows paths like C:\Work\nxxx\README.md or user-intended escape sequences.
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
}
const BRACKETED_SYSTEM_TAG_RE = /\[\s*(System\s*Message|System|Assistant|Internal)\s*\]/gi;
const LINE_SYSTEM_PREFIX_RE = /^(\s*)System:(?=\s|$)/gim;
/**
* Neutralize user-controlled strings that spoof internal system markers.
*/
export function sanitizeInboundSystemTags(input: string): string {
return input
.replace(BRACKETED_SYSTEM_TAG_RE, (_match, tag: string) => `(${tag})`)
.replace(LINE_SYSTEM_PREFIX_RE, "$1System (untrusted):");
}