The suffix regex matched NO_REPLY at the end of any response, suppressing substantive replies when models (e.g. Gemini 3 Pro) appended NO_REPLY to real content. Replace prefix+suffix regexes with a single whole-string match. Only responses that are entirely the silent token (with optional whitespace) are now suppressed. Add unit tests for the fix. Fixes #19537
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
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);
|
|
// Only match when the entire response (trimmed) is the silent token,
|
|
// optionally surrounded by whitespace/punctuation. This prevents
|
|
// substantive replies ending with NO_REPLY from being suppressed (#19537).
|
|
return new RegExp(`^\\s*${escaped}\\s*$`).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);
|
|
}
|