Agent/reports/report-clean.ts
2026-08-06 22:17:39 +08:00

52 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// @ts-nocheck
export function stripReportHints(text) {
return String(text || '')
.replace(/<!--\s*HINT\s*:[\s\S]*?-->/gi, '')
.replace(/\n{3,}/g, '\n\n')
.trim();
}
export function stripReportMarkers(text) {
return stripReportBridgeNarration(
stripReportHints(
String(text || '')
.replace(/\[CONTINUE\]/gi, '')
.replace(/\[DONE\]/gi, '')
.trim()
)
);
}
export function stripReportBridgeNarration(text) {
let raw = String(text || '').trim();
if (!raw) return raw;
raw = raw.replace(/(^|\n)\s*([-*_])\2{2,}\s*(?=\n|$)/g, '\n\n---\n\n');
const parts = raw.split(/\n{2,}/);
let i = 0;
while (i < parts.length && isReportBridgeParagraph(parts[i])) {
i++;
}
if (i >= parts.length) return raw;
return parts.slice(i).join('\n\n').trim();
}
export function isReportBridgeParagraph(p) {
const t = String(p || '').trim();
if (!t) return true;
if (/^([-*_])\1{2,}$/.test(t) || t === '---' || t === '***' || t === '___') return true;
if (/^#{1,6}\s/.test(t)) return false;
if (/^\|/.test(t) || /\|[-:\s|]+\|/.test(t)) return false;
if (/^[-*•]\s+\S/.test(t)) return false;
if (t.length > 400) return false;
return /上一轮|上一段|接上[文轮篇]?|从断点|我接着|接着(?:写|上一|从)|继续写完|本轮继续|下面继续|现在继续(?:写|完成|输出)|未写完|处中断|写完.{0,20}模块|然后进入|接下来进入|开始生成.{0,20}报告|数据已(?:全部)?获取|获取成功|确认该员工|确认员工|现在开始为您|开始为您撰写|为您撰写|开始撰写|撰写.{0,30}报告|现在为您生成|工具已返回|正在为您|我先为您|好的[,]我|似乎遇到|再次尝试|正在拉取/.test(t);
}