mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 09:50:23 +00:00
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 26f35f4411
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
41 lines
942 B
TypeScript
41 lines
942 B
TypeScript
import { escapeRegExp } from "../utils.js";
|
|
|
|
export const HEARTBEAT_TOKEN = "HEARTBEAT_OK";
|
|
export const SILENT_REPLY_TOKEN = "NO_REPLY";
|
|
|
|
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);
|
|
}
|
|
|
|
export function isSilentReplyPrefixText(
|
|
text: string | undefined,
|
|
token: string = SILENT_REPLY_TOKEN,
|
|
): boolean {
|
|
if (!text) {
|
|
return false;
|
|
}
|
|
const normalized = text.trimStart().toUpperCase();
|
|
if (!normalized) {
|
|
return false;
|
|
}
|
|
if (!normalized.includes("_")) {
|
|
return false;
|
|
}
|
|
if (/[^A-Z_]/.test(normalized)) {
|
|
return false;
|
|
}
|
|
return token.toUpperCase().startsWith(normalized);
|
|
}
|