feat(chat): add cleaning for Gateway-injected conversation (#118)

This commit is contained in:
Haze
2026-02-20 18:45:28 +08:00
committed by GitHub
Unverified
parent 15f3ef1f72
commit b87e676826

View File

@@ -16,6 +16,10 @@ function cleanUserText(text: string): string {
.replace(/\s*\[media attached:[^\]]*\]/g, '') .replace(/\s*\[media attached:[^\]]*\]/g, '')
// Remove [message_id: uuid] // Remove [message_id: uuid]
.replace(/\s*\[message_id:\s*[^\]]+\]/g, '') .replace(/\s*\[message_id:\s*[^\]]+\]/g, '')
// Remove Gateway-injected "Conversation info (untrusted metadata): ```json...```" block
.replace(/^Conversation info\s*\([^)]*\):\s*```[a-z]*\n[\s\S]*?```\s*/i, '')
// Fallback: remove "Conversation info (...): {...}" without code block wrapper
.replace(/^Conversation info\s*\([^)]*\):\s*\{[\s\S]*?\}\s*/i, '')
// Remove Gateway timestamp prefix like [Fri 2026-02-13 22:39 GMT+8] // Remove Gateway timestamp prefix like [Fri 2026-02-13 22:39 GMT+8]
.replace(/^\[(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+[^\]]+\]\s*/i, '') .replace(/^\[(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+[^\]]+\]\s*/i, '')
.trim(); .trim();