fix(agent): strip hallucinated media links from analysis reply
This commit is contained in:
parent
fe5dbfb6ad
commit
e08fb4e4b5
@ -827,9 +827,33 @@ function normalizeAgentReportHeadingLine(line: string): string {
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripAgentFriendlyMediaEmbeds(message: string): string {
|
||||||
|
if (!message) return message;
|
||||||
|
|
||||||
|
const withoutInlineMedia = message
|
||||||
|
.replace(/!\[[^\]]*]\((https?:\/\/[^\s)]+)\)/gi, "")
|
||||||
|
.replace(/<video[\s\S]*?<\/video>/gi, "")
|
||||||
|
.replace(/<img[^>]*>/gi, "");
|
||||||
|
|
||||||
|
const cleanedLines = withoutInlineMedia
|
||||||
|
.split("\n")
|
||||||
|
.filter((line) => {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (!trimmed) return true;
|
||||||
|
if (/^https?:\/\/\S+$/i.test(trimmed)) return false;
|
||||||
|
if (/^\[[^\]]*]\(https?:\/\/[^\s)]+\)$/i.test(trimmed)) return false;
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
return cleanedLines.replace(/\n{3,}/g, "\n\n").trim();
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeAgentReportForDisplay(message?: string): string | undefined {
|
function normalizeAgentReportForDisplay(message?: string): string | undefined {
|
||||||
if (!message?.trim()) return message;
|
if (!message?.trim()) return message;
|
||||||
return message
|
const stripped = stripAgentFriendlyMediaEmbeds(message);
|
||||||
|
if (!stripped) return undefined;
|
||||||
|
return stripped
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map((line) => normalizeAgentReportHeadingLine(line))
|
.map((line) => normalizeAgentReportHeadingLine(line))
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user