ДОМЕНЫ - ВОПРОСЫ - кто должен нам
This commit is contained in:
@@ -665,7 +665,7 @@ function scrubRawTechnicalRefs(value: string): string {
|
||||
.replace(RAW_REF_TOKEN_PATTERN, "reference")
|
||||
.replace(/\(\s*\[id\]\s*\)/g, "")
|
||||
.replace(/\[\s*id\s*\](?:\s*,\s*\[\s*id\s*\])+/g, "[id]")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.replace(/[ \t]{2,}/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -681,23 +681,50 @@ function stripSyntheticPlaceholders(value: string): string {
|
||||
|
||||
function sanitizeUserFacingReply(value: string): string {
|
||||
const raw = String(value ?? "");
|
||||
const hardCutMatch = raw.match(/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json)\b/i);
|
||||
const hardCutMatch = raw.match(
|
||||
/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json|technical_debug_payload_json)\b/i
|
||||
);
|
||||
const preCut = hardCutMatch ? raw.slice(0, hardCutMatch.index) : raw;
|
||||
const withoutDebugBlocks = preCut
|
||||
.replace(/###\s*debug_payload_json[\s\S]*?(?:```[\s\S]*?```|$)/gi, "")
|
||||
.replace(/###\s*technical_debug_payload_json[\s\S]*?(?:```[\s\S]*?```|$)/gi, "")
|
||||
.replace(/###\s*technical_breakdown_json[\s\S]*?(?:```[\s\S]*?```|$)/gi, "")
|
||||
.replace(/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json)\b[\s\S]*$/gi, "")
|
||||
.replace(/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json|technical_debug_payload_json)\b[\s\S]*$/gi, "")
|
||||
.replace(/```json[\s\S]*?```/gi, "");
|
||||
const normalized = scrubRawTechnicalRefs(withoutDebugBlocks).replace(/[ \t]+\n/g, "\n");
|
||||
const cleanedLines = normalized
|
||||
const preparedLines = normalized
|
||||
.split(/\r?\n/g)
|
||||
.map((line) => stripSyntheticPlaceholders(line))
|
||||
.map((line) => stripMojibakeFragments(line))
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
.filter((line) => !/^(?:-\s*)?(?:action|clarify|open|limit|note):\s*$/i.test(line))
|
||||
.filter((line) => !hasUserFacingLeakage(line))
|
||||
.filter((line) => !looksLikeMojibake(line));
|
||||
.map((line) => line.trim());
|
||||
const cleanedLines: string[] = [];
|
||||
let previousWasBlank = false;
|
||||
for (const line of preparedLines) {
|
||||
if (line.length === 0) {
|
||||
if (!previousWasBlank && cleanedLines.length > 0) {
|
||||
cleanedLines.push("");
|
||||
}
|
||||
previousWasBlank = true;
|
||||
continue;
|
||||
}
|
||||
if (/^(?:-\s*)?(?:action|clarify|open|limit|note):\s*$/i.test(line)) {
|
||||
continue;
|
||||
}
|
||||
if (hasUserFacingLeakage(line)) {
|
||||
continue;
|
||||
}
|
||||
if (looksLikeMojibake(line)) {
|
||||
continue;
|
||||
}
|
||||
cleanedLines.push(line);
|
||||
previousWasBlank = false;
|
||||
}
|
||||
while (cleanedLines.length > 0 && cleanedLines[0] === "") {
|
||||
cleanedLines.shift();
|
||||
}
|
||||
while (cleanedLines.length > 0 && cleanedLines[cleanedLines.length - 1] === "") {
|
||||
cleanedLines.pop();
|
||||
}
|
||||
const cleaned = cleanedLines.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
||||
return cleaned || "Available data requires clarification for a reliable user-facing answer.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user