From 66194d03d325ea35f89698aa32cb39fc60e6c445 Mon Sep 17 00:00:00 2001 From: LE Quoc Dat Date: Mon, 28 Jul 2025 21:49:32 +0200 Subject: [PATCH] AI: How can we stream the edit_file tool when it generating like create_file ? Also the edit_file tool show this """Invalid File Edit Could not extract the file changes from the tool result.""" Check the state of code base and make to sure implement fully --- .../thread/content/ShowToolStream.tsx | 17 +++++++++++++---- .../file-operation/FileEditToolView.tsx | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/thread/content/ShowToolStream.tsx b/frontend/src/components/thread/content/ShowToolStream.tsx index 0decd71d..ce45aad3 100644 --- a/frontend/src/components/thread/content/ShowToolStream.tsx +++ b/frontend/src/components/thread/content/ShowToolStream.tsx @@ -45,11 +45,20 @@ export const ShowToolStream: React.FC = ({ // Extract code_edit content for streaming const codeEditContent = React.useMemo(() => { if (!isEditFile || !content) return ''; - const match = content.match(/([\s\S]*)/); - if (match) { - // Remove closing tag if present - return match[1].replace(/<\/code_edit>[\s\S]*$/, ''); + + // New regex for + const newMatch = content.match(/([\s\S]*)/i); + if (newMatch && newMatch[1]) { + // Remove closing tags if present + return newMatch[1].replace(/<\/parameter>[\s\S]*$/, ''); } + + // Fallback for old format + const oldMatch = content.match(/([\s\S]*)/i); + if (oldMatch && oldMatch[1]) { + return oldMatch[1].replace(/<\/code_edit>[\s\S]*$/, ''); + } + return ''; }, [content, isEditFile]); diff --git a/frontend/src/components/thread/tool-views/file-operation/FileEditToolView.tsx b/frontend/src/components/thread/tool-views/file-operation/FileEditToolView.tsx index f7aab248..f09c30d5 100644 --- a/frontend/src/components/thread/tool-views/file-operation/FileEditToolView.tsx +++ b/frontend/src/components/thread/tool-views/file-operation/FileEditToolView.tsx @@ -142,7 +142,7 @@ export function FileEditToolView({ const lineDiff = originalContent && updatedContent ? generateLineDiff(originalContent, updatedContent) : []; const stats: DiffStats = calculateDiffStats(lineDiff); - const shouldShowError = !isStreaming && (!originalContent || !updatedContent); + const shouldShowError = !isStreaming && !actualIsSuccess; return (