From bdf980044a66395c62d35b002eefd510fdf0cf36 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Feb 2026 23:13:14 +0800 Subject: [PATCH] fix(canvas): hide raw anchor/html text in video assistant messages --- components/canvas/CanvasChatPanel.tsx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index a4201c376..3b0b11935 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -134,6 +134,16 @@ function extractVideoUrls(text: string): string[] { return Array.from(urls); } +function stripMediaMarkup(text: string): string { + return String(text || "") + .replace(/!\[(?:thumb)?\|\|\|[^|]+\|\|\|[^\]]*\]\([^)]+\)/g, "") + .replace(//gi, "") + .replace(//gi, "") + .replace(/\[[^\]]*]\((https?:\/\/[^)\s]+\.mp4(?:\?[^)\s]*)?)\)/gi, "") + .replace(/https?:\/\/[^\s"'<>]+\.mp4(?:\?[^\s"'<>]+)?/gi, "") + .trim(); +} + function normalizeVideoParamsForProvider( params: VideoGenerationParams | null | undefined, providerType?: string @@ -3277,13 +3287,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF extractVideoUrls(part.text || "").length > 0 ); const hasAssistantText = assistantTextParts.some((part: any) => { - const textWithoutImages = (part.text || "") - .replace(/!\[(?:thumb)?\|\|\|[^|]+\|\|\|[^\]]*\]\([^)]+\)/g, "") - .replace(//gi, "") - .replace(/\[[^\]]*]\((https?:\/\/[^)\s]+\.mp4(?:\?[^)\s]*)?)\)/gi, "") - .replace(/https?:\/\/[^\s"'<>]+\.mp4(?:\?[^\s"'<>]+)?/gi, "") - .trim(); - return textWithoutImages.length > 0; + return stripMediaMarkup(part.text).length > 0; }); const isImageOnlyAssistant = message.role === "assistant" && @@ -3422,12 +3426,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF const rawText = part.text || ''; const imageUrls = extractImageUrls(rawText); const videoUrls = extractVideoUrls(rawText); - const textWithoutImages = rawText - .replace(/!\[(?:thumb)?\|\|\|[^|]+\|\|\|[^\]]*\]\([^)]+\)/g, '') - .replace(//gi, '') - .replace(/\[[^\]]*]\((https?:\/\/[^)\s]+\.mp4(?:\?[^)\s]*)?)\)/gi, '') - .replace(/https?:\/\/[^\s"'<>]+\.mp4(?:\?[^\s"'<>]+)?/gi, '') - .trim(); + const textWithoutImages = stripMediaMarkup(rawText); return (