openclaw/src/auto-reply/tokens.ts
2026-01-15 03:55:20 +00:00

19 lines
558 B
TypeScript

export const HEARTBEAT_TOKEN = "HEARTBEAT_OK";
export const SILENT_REPLY_TOKEN = "NO_REPLY";
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
export function isSilentReplyText(
text: string | undefined,
token: string = SILENT_REPLY_TOKEN,
): boolean {
if (!text) return false;
const escaped = escapeRegExp(token);
const prefix = new RegExp(`^\\s*${escaped}(?=$|\\W)`);
if (prefix.test(text)) return true;
const suffix = new RegExp(`\\b${escaped}\\b\\W*$`);
return suffix.test(text);
}