From cb424d8fe77a942d954a82c2c34685c63fa37002 Mon Sep 17 00:00:00 2001 From: LE Quoc Dat Date: Mon, 28 Jul 2025 21:55:45 +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/agentpress/response_processor.py | 6 +++--- frontend/src/components/thread/utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/agentpress/response_processor.py b/backend/agentpress/response_processor.py index 3f3b4b17..90fcea63 100644 --- a/backend/agentpress/response_processor.py +++ b/backend/agentpress/response_processor.py @@ -1727,10 +1727,10 @@ class ResponseProcessor: # If parsing fails, keep the original string pass + output_to_use = output # If this is for the LLM and it's an edit_file tool, create a concise output if for_llm and function_name == 'edit_file' and isinstance(output, dict): - output_for_llm = {"message": output.get("message", "File edited successfully.")} - output = output_for_llm + output_to_use = {"message": output.get("message", "File edited successfully.")} # Create the structured result structured_result_v1 = { @@ -1741,7 +1741,7 @@ class ResponseProcessor: "arguments": arguments, "result": { "success": result.success if hasattr(result, 'success') else True, - "output": output, # This will be either rich or concise based on `for_llm` + "output": output_to_use, # This will be either rich or concise based on `for_llm` "error": getattr(result, 'error', None) if hasattr(result, 'error') else None }, } diff --git a/frontend/src/components/thread/utils.ts b/frontend/src/components/thread/utils.ts index 7db580ad..b0f1fdb8 100644 --- a/frontend/src/components/thread/utils.ts +++ b/frontend/src/components/thread/utils.ts @@ -246,9 +246,9 @@ export const extractPrimaryParam = ( return match ? match[1].split('/').pop() || match[1] : null; case 'edit-file': // Try to match target_file attribute for edit-file - match = content.match(/target_file=(?:"|')([^"|']+)(?:"|')/); + match = content.match(/target_file=(?:"|')([^"|']+)(?:"|')/) || content.match(/([^<]+)/i); // Return just the filename part - return match ? match[1].split('/').pop() || match[1] : null; + return match ? (match[1].split('/').pop() || match[1]).trim() : null; // Shell commands case 'execute-command':