fix text editor tool and scroll action in computer tool
This commit is contained in:
@@ -129,11 +129,11 @@ def execute_computer_tool(tool_input):
|
|||||||
return {"type": "text", "text": f"Error pressing key {text}: {str(e)}"}
|
return {"type": "text", "text": f"Error pressing key {text}: {str(e)}"}
|
||||||
|
|
||||||
elif action == "scroll":
|
elif action == "scroll":
|
||||||
# Scroll action
|
# Scroll action (should we really have defaults here?)
|
||||||
direction = tool_input.get("direction", "down")
|
direction = tool_input.get("scroll_direction", "down")
|
||||||
amount = tool_input.get("amount", 3)
|
amount = tool_input.get("scroll_amount", 3)
|
||||||
|
|
||||||
scroll_amount = -amount if direction == "up" else amount
|
scroll_amount = -amount if direction == "down" else amount
|
||||||
pyautogui.scroll(scroll_amount)
|
pyautogui.scroll(scroll_amount)
|
||||||
return {"type": "text", "text": f"Scrolled {direction} by {amount}"}
|
return {"type": "text", "text": f"Scrolled {direction} by {amount}"}
|
||||||
|
|
||||||
@@ -165,23 +165,23 @@ def execute_bash_tool(command):
|
|||||||
return {"type": "text", "text": f"Error executing command: {str(e)}"}
|
return {"type": "text", "text": f"Error executing command: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
def execute_text_editor_tool(command, path, **kwargs):
|
def execute_text_editor_tool(_command, _path, **kwargs):
|
||||||
"""Execute text editor actions."""
|
"""Execute text editor actions."""
|
||||||
|
|
||||||
if command == "view":
|
if _command == "view":
|
||||||
try:
|
try:
|
||||||
with open(path, 'r') as f:
|
with open(_path, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
return {"type": "text", "text": content}
|
return {"type": "text", "text": content}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"type": "text", "text": f"Error reading file: {str(e)}"}
|
return {"type": "text", "text": f"Error reading file: {str(e)}"}
|
||||||
|
|
||||||
elif command == "str_replace":
|
elif _command == "str_replace":
|
||||||
old_str = kwargs.get("old_str", "")
|
old_str = kwargs.get("old_str", "")
|
||||||
new_str = kwargs.get("new_str", "")
|
new_str = kwargs.get("new_str", "")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, 'r') as f:
|
with open(_path, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
if old_str not in content:
|
if old_str not in content:
|
||||||
@@ -191,7 +191,7 @@ def execute_text_editor_tool(command, path, **kwargs):
|
|||||||
new_content = content.replace(old_str, new_str)
|
new_content = content.replace(old_str, new_str)
|
||||||
|
|
||||||
# Write back to file
|
# Write back to file
|
||||||
with open(path, 'w') as f:
|
with open(_path, 'w') as f:
|
||||||
f.write(new_content)
|
f.write(new_content)
|
||||||
|
|
||||||
return {"type": "text", "text": "String replaced successfully"}
|
return {"type": "text", "text": "String replaced successfully"}
|
||||||
@@ -199,17 +199,17 @@ def execute_text_editor_tool(command, path, **kwargs):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"type": "text", "text": f"Error modifying file: {str(e)}"}
|
return {"type": "text", "text": f"Error modifying file: {str(e)}"}
|
||||||
|
|
||||||
elif command == "create":
|
elif _command == "create":
|
||||||
content = kwargs.get("content", "")
|
content = kwargs.get("content", "")
|
||||||
try:
|
try:
|
||||||
with open(path, 'w') as f:
|
with open(_path, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return {"type": "text", "text": f"File created: {path}"}
|
return {"type": "text", "text": f"File created: {_path}"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"type": "text", "text": f"Error creating file: {str(e)}"}
|
return {"type": "text", "text": f"Error creating file: {str(e)}"}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return {"type": "text", "text": f"Unknown text editor command: {command}"}
|
return {"type": "text", "text": f"Unknown text editor command: {_command}"}
|
||||||
|
|
||||||
|
|
||||||
def execute_tool(tool_name, tool_input):
|
def execute_tool(tool_name, tool_input):
|
||||||
|
|||||||
Reference in New Issue
Block a user