web: filter leaked NO_REPLY tokens in chat message display

This commit is contained in:
kumarabhirup 2026-02-21 12:32:10 -08:00
parent a2845a321e
commit f3ae8127da
No known key found for this signature in database
GPG Key ID: DB7CA2289CAB0167

View File

@ -31,6 +31,18 @@ const ReportCard = dynamic(
},
);
/* ─── Silent-reply leak filter ─── */
const _SILENT_TOKEN = "NO_REPLY";
function isLeakedSilentToken(text: string): boolean {
const t = text.trim();
if (!t) {return false;}
if (new RegExp(`^${_SILENT_TOKEN}\\W*$`).test(t)) {return true;}
if (_SILENT_TOKEN.startsWith(t) && t.length >= 2 && t.length < _SILENT_TOKEN.length) {return true;}
return false;
}
/* ─── Part grouping ─── */
type MessageSegment =
@ -77,8 +89,9 @@ function groupParts(parts: UIMessage["parts"]): MessageSegment[] {
for (const part of parts) {
if (part.type === "text") {
flush(true);
const text = (part as { type: "text"; text: string }).text;
if (isLeakedSilentToken(text)) { continue; }
flush(true);
if (hasReportBlocks(text)) {
segments.push(
...(splitReportBlocks(text) as MessageSegment[]),