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
This commit is contained in:
LE Quoc Dat 2025-07-28 21:49:32 +02:00
parent 2def96efc9
commit 66194d03d3
2 changed files with 14 additions and 5 deletions

View File

@ -45,11 +45,20 @@ export const ShowToolStream: React.FC<ShowToolStreamProps> = ({
// Extract code_edit content for streaming // Extract code_edit content for streaming
const codeEditContent = React.useMemo(() => { const codeEditContent = React.useMemo(() => {
if (!isEditFile || !content) return ''; if (!isEditFile || !content) return '';
const match = content.match(/<code_edit>([\s\S]*)/);
if (match) { // New regex for <parameter name="code_edit">
// Remove closing tag if present const newMatch = content.match(/<parameter\s+name=["']code_edit["']>([\s\S]*)/i);
return match[1].replace(/<\/code_edit>[\s\S]*$/, ''); if (newMatch && newMatch[1]) {
// Remove closing tags if present
return newMatch[1].replace(/<\/parameter>[\s\S]*$/, '');
} }
// Fallback for old format <code_edit>
const oldMatch = content.match(/<code_edit>([\s\S]*)/i);
if (oldMatch && oldMatch[1]) {
return oldMatch[1].replace(/<\/code_edit>[\s\S]*$/, '');
}
return ''; return '';
}, [content, isEditFile]); }, [content, isEditFile]);

View File

@ -142,7 +142,7 @@ export function FileEditToolView({
const lineDiff = originalContent && updatedContent ? generateLineDiff(originalContent, updatedContent) : []; const lineDiff = originalContent && updatedContent ? generateLineDiff(originalContent, updatedContent) : [];
const stats: DiffStats = calculateDiffStats(lineDiff); const stats: DiffStats = calculateDiffStats(lineDiff);
const shouldShowError = !isStreaming && (!originalContent || !updatedContent); const shouldShowError = !isStreaming && !actualIsSuccess;
return ( return (
<Card className="gap-0 flex border shadow-none border-t border-b-0 border-x-0 p-0 rounded-none flex-col h-full overflow-hidden bg-card"> <Card className="gap-0 flex border shadow-none border-t border-b-0 border-x-0 p-0 rounded-none flex-col h-full overflow-hidden bg-card">