From ef980353ba154fdbb14fd22cd850723e2a9bf26f Mon Sep 17 00:00:00 2001 From: LE Quoc Dat Date: Mon, 28 Jul 2025 22:22:38 +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 --- backend/agent/tools/sb_files_tool.py | 4 ++-- .../src/components/thread/tool-views/file-operation/_utils.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/agent/tools/sb_files_tool.py b/backend/agent/tools/sb_files_tool.py index 590df309..7e192c8a 100644 --- a/backend/agent/tools/sb_files_tool.py +++ b/backend/agent/tools/sb_files_tool.py @@ -540,12 +540,12 @@ def authenticate_user(username, password): await self.sandbox.fs.upload_file(new_content.encode(), full_path) # Return rich data for frontend diff view - return self.success_response({ + return ToolResult(success=True, output=json.dumps({ "message": f"File '{target_file}' edited successfully.", "file_path": target_file, "original_content": original_content, "updated_content": new_content - }) + })) except Exception as e: logger.error(f"Unhandled error in edit_file: {str(e)}", exc_info=True) diff --git a/frontend/src/components/thread/tool-views/file-operation/_utils.ts b/frontend/src/components/thread/tool-views/file-operation/_utils.ts index af6ebf31..a762a347 100644 --- a/frontend/src/components/thread/tool-views/file-operation/_utils.ts +++ b/frontend/src/components/thread/tool-views/file-operation/_utils.ts @@ -289,7 +289,7 @@ export const extractFileEditData = ( filePath: parsed.file_path || null, originalContent: parsed.original_content ?? null, updatedContent: parsed.updated_content ?? null, - success: true, // Assume success if we have content + success: parsed.updated_content !== null, // Success is false if updated_content is null timestamp: null, errorMessage: parsed.message, };