mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 19:30:23 +00:00
fix(tui): strip inbound metadata blocks from user messages (clean rewrite) (#22345)
* fix(tui): strip inbound metadata blocks from user text * chore: clean up metadata-strip format and changelog credit * chore: format tui metadata-strip tests * test: align metadata-strip regression expectations * refactor: reuse canonical inbound metadata stripper * test: allow tmp media fixture paths in media-understanding tests * refactor: reuse canonical inbound metadata stripper * format: fix changelog blank line after headings * test: fix unrelated check typing regressions * test: align memory async mock embedding signatures * test: avoid tsgo mock typing pitfall * test: restore async search mock typings in merge tree * test: trigger ci rerun without behavior change * chore: dedupe todays changelog entries * fix: dedupe sqlite mock keys in qmd manager test * Update qmd-manager.test.ts * test: align chat metadata sanitization expectation
This commit is contained in:
@@ -16,21 +16,6 @@ const ENVELOPE_CHANNELS = [
|
||||
];
|
||||
|
||||
const MESSAGE_ID_LINE = /^\s*\[message_id:\s*[^\]]+\]\s*$/i;
|
||||
const INBOUND_METADATA_HEADERS = [
|
||||
"Conversation info (untrusted metadata):",
|
||||
"Sender (untrusted metadata):",
|
||||
"Thread starter (untrusted, for context):",
|
||||
"Replied message (untrusted, for context):",
|
||||
"Forwarded message context (untrusted metadata):",
|
||||
"Chat history since last reply (untrusted, for context):",
|
||||
];
|
||||
const REGEX_ESCAPE_RE = /[.*+?^${}()|[\]\\-]/g;
|
||||
const INBOUND_METADATA_PREFIX_RE = new RegExp(
|
||||
"^\\s*(?:" +
|
||||
INBOUND_METADATA_HEADERS.map((header) => header.replace(REGEX_ESCAPE_RE, "\\$&")).join("|") +
|
||||
")\\r?\\n```json\\r?\\n[\\s\\S]*?\\r?\\n```(?:\\r?\\n)*",
|
||||
);
|
||||
|
||||
function looksLikeEnvelopeHeader(header: string): boolean {
|
||||
if (/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}Z\b/.test(header)) {
|
||||
return true;
|
||||
@@ -61,15 +46,3 @@ export function stripMessageIdHints(text: string): string {
|
||||
const filtered = lines.filter((line) => !MESSAGE_ID_LINE.test(line));
|
||||
return filtered.length === lines.length ? text : filtered.join("\n");
|
||||
}
|
||||
|
||||
export function stripInboundMetadataBlocks(text: string): string {
|
||||
let remaining = text;
|
||||
for (;;) {
|
||||
const match = INBOUND_METADATA_PREFIX_RE.exec(remaining);
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
remaining = remaining.slice(match[0].length).replace(/^\r?\n+/, "");
|
||||
}
|
||||
return remaining.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user