-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace file editor with openhands-aci (#4782)
- Loading branch information
1 parent
32fdcd5
commit d9c5f11
Showing
7 changed files
with
41 additions
and
648 deletions.
There are no files selected for viewing
62 changes: 5 additions & 57 deletions
62
openhands/runtime/plugins/agent_skills/file_editor/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,8 @@ | ||
"""This file contains a global singleton of the `EditTool` class as well as raw functions that expose its __call__.""" | ||
|
||
from .base import CLIResult, ToolError, ToolResult | ||
from .impl import Command, EditTool | ||
|
||
_GLOBAL_EDITOR = EditTool() | ||
|
||
|
||
def _make_api_tool_result( | ||
result: ToolResult, | ||
) -> str: | ||
"""Convert an agent ToolResult to an API ToolResultBlockParam.""" | ||
tool_result_content: str = '' | ||
is_error = False | ||
if result.error: | ||
is_error = True | ||
tool_result_content = _maybe_prepend_system_tool_result(result, result.error) | ||
else: | ||
assert result.output, 'Expecting output in file_editor' | ||
tool_result_content = _maybe_prepend_system_tool_result(result, result.output) | ||
assert ( | ||
not result.base64_image | ||
), 'Not expecting base64_image as output in file_editor' | ||
if is_error: | ||
return f'ERROR:\n{tool_result_content}' | ||
else: | ||
return tool_result_content | ||
|
||
|
||
def _maybe_prepend_system_tool_result(result: ToolResult, result_text: str) -> str: | ||
if result.system: | ||
result_text = f'<system>{result.system}</system>\n{result_text}' | ||
return result_text | ||
|
||
|
||
def file_editor( | ||
command: Command, | ||
path: str, | ||
file_text: str | None = None, | ||
view_range: list[int] | None = None, | ||
old_str: str | None = None, | ||
new_str: str | None = None, | ||
insert_line: int | None = None, | ||
) -> str: | ||
try: | ||
result: CLIResult = _GLOBAL_EDITOR( | ||
command=command, | ||
path=path, | ||
file_text=file_text, | ||
view_range=view_range, | ||
old_str=old_str, | ||
new_str=new_str, | ||
insert_line=insert_line, | ||
) | ||
except ToolError as e: | ||
return _make_api_tool_result(ToolResult(error=e.message)) | ||
return _make_api_tool_result(result) | ||
"""This file imports a global singleton of the `EditTool` class as well as raw functions that expose | ||
its __call__. | ||
The implementation of the `EditTool` class can be found at: https://github.com/All-Hands-AI/openhands-aci/. | ||
""" | ||
|
||
from openhands_aci.editor import file_editor | ||
|
||
__all__ = ['file_editor'] |
50 changes: 0 additions & 50 deletions
50
openhands/runtime/plugins/agent_skills/file_editor/base.py
This file was deleted.
Oops, something went wrong.
279 changes: 0 additions & 279 deletions
279
openhands/runtime/plugins/agent_skills/file_editor/impl.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.