mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:47:40 +00:00
fix(heartbeat): bound responsePrefix strip for ack detection
This commit is contained in:
@@ -430,17 +430,31 @@ async function captureTranscriptState(params: {
|
||||
}
|
||||
}
|
||||
|
||||
function stripLeadingHeartbeatResponsePrefix(
|
||||
text: string,
|
||||
responsePrefix: string | undefined,
|
||||
): string {
|
||||
const normalizedPrefix = responsePrefix?.trim();
|
||||
if (!normalizedPrefix) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Require a boundary after the configured prefix so short prefixes like "Hi"
|
||||
// do not strip the beginning of normal words like "History".
|
||||
const prefixPattern = new RegExp(
|
||||
`^${escapeRegExp(normalizedPrefix)}(?=$|\\s|[\\p{P}\\p{S}])\\s*`,
|
||||
"iu",
|
||||
);
|
||||
return text.replace(prefixPattern, "");
|
||||
}
|
||||
|
||||
function normalizeHeartbeatReply(
|
||||
payload: ReplyPayload,
|
||||
responsePrefix: string | undefined,
|
||||
ackMaxChars: number,
|
||||
) {
|
||||
const rawText = typeof payload.text === "string" ? payload.text : "";
|
||||
|
||||
const prefixPattern = responsePrefix?.trim()
|
||||
? new RegExp(`^${escapeRegExp(responsePrefix.trim())}\\s*`, "i")
|
||||
: null;
|
||||
const textForStrip = prefixPattern ? rawText.replace(prefixPattern, "") : rawText;
|
||||
const textForStrip = stripLeadingHeartbeatResponsePrefix(rawText, responsePrefix);
|
||||
const stripped = stripHeartbeatToken(textForStrip, {
|
||||
mode: "heartbeat",
|
||||
maxAckChars: ackMaxChars,
|
||||
|
||||
Reference in New Issue
Block a user