mirror of https://github.com/kortix-ai/suna.git
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:
parent
cb424d8fe7
commit
1fbac3bc15
|
@ -513,14 +513,28 @@ def authenticate_user(username, password):
|
|||
new_content, error_message = await self._call_morph_api(original_content, code_edit, instructions, target_file)
|
||||
|
||||
if error_message:
|
||||
return self.fail_response(error_message)
|
||||
return ToolResult(success=False, output=json.dumps({
|
||||
"message": f"AI editing failed: {error_message}",
|
||||
"file_path": target_file,
|
||||
"original_content": original_content,
|
||||
"updated_content": None
|
||||
}))
|
||||
|
||||
if new_content is None:
|
||||
# This case should ideally be covered by error_message, but as a safeguard:
|
||||
return self.fail_response("AI editing failed for an unknown reason. The model returned no content.")
|
||||
return ToolResult(success=False, output=json.dumps({
|
||||
"message": "AI editing failed for an unknown reason. The model returned no content.",
|
||||
"file_path": target_file,
|
||||
"original_content": original_content,
|
||||
"updated_content": None
|
||||
}))
|
||||
|
||||
if new_content == original_content:
|
||||
return self.fail_response(f"AI editing resulted in no changes to the file '{target_file}'.")
|
||||
return ToolResult(success=False, output=json.dumps({
|
||||
"message": f"AI editing resulted in no changes to the file '{target_file}'.",
|
||||
"file_path": target_file,
|
||||
"original_content": original_content,
|
||||
"updated_content": original_content
|
||||
}))
|
||||
|
||||
# AI editing successful
|
||||
await self.sandbox.fs.upload_file(new_content.encode(), full_path)
|
||||
|
@ -535,7 +549,21 @@ def authenticate_user(username, password):
|
|||
|
||||
except Exception as e:
|
||||
logger.error(f"Unhandled error in edit_file: {str(e)}", exc_info=True)
|
||||
return self.fail_response(f"Error editing file: {str(e)}")
|
||||
# Try to get original_content if possible
|
||||
original_content_on_error = None
|
||||
try:
|
||||
full_path_on_error = f"{self.workspace_path}/{self.clean_path(target_file)}"
|
||||
if await self._file_exists(full_path_on_error):
|
||||
original_content_on_error = (await self.sandbox.fs.download_file(full_path_on_error)).decode()
|
||||
except:
|
||||
pass
|
||||
|
||||
return ToolResult(success=False, output=json.dumps({
|
||||
"message": f"Error editing file: {str(e)}",
|
||||
"file_path": target_file,
|
||||
"original_content": original_content_on_error,
|
||||
"updated_content": None
|
||||
}))
|
||||
|
||||
# @openapi_schema({
|
||||
# "type": "function",
|
||||
|
|
|
@ -269,7 +269,7 @@ export const extractFileEditData = (
|
|||
updatedContent: output?.updated_content || null,
|
||||
success: success,
|
||||
timestamp: parsed.tool_execution.execution_details?.timestamp,
|
||||
errorMessage: success === false ? (typeof output === 'string' ? output : JSON.stringify(output)) : undefined,
|
||||
errorMessage: success === false ? (output?.message || (typeof output === 'string' ? output : JSON.stringify(output))) : undefined,
|
||||
};
|
||||
}
|
||||
return {};
|
||||
|
|
|
@ -304,6 +304,7 @@ const TOOL_DISPLAY_NAMES = new Map([
|
|||
['str-replace', 'Editing Text'],
|
||||
['str_replace', 'Editing Text'],
|
||||
['edit_file', 'AI File Edit'],
|
||||
['edit-file', 'AI File Edit'],
|
||||
|
||||
['browser-click-element', 'Clicking Element'],
|
||||
['browser-close-tab', 'Closing Tab'],
|
||||
|
|
Loading…
Reference in New Issue