Skip to content

Commit a78a0e1

Browse files
authored
Merge pull request #333 from trycua/fix/passthrough-tool-errors
[Agent] Implement left_mouse_down, left_mouse_up, and tool errors
2 parents 889d32d + 4b0b072 commit a78a0e1

File tree

4 files changed

+662
-510
lines changed

4 files changed

+662
-510
lines changed

libs/python/agent/agent/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ def print_action(action_type: str, details: Dict[str, Any], total_cost: float):
9494
# Format action details
9595
args_str = ""
9696
if action_type == "click" and "x" in details and "y" in details:
97-
args_str = f"({details['x']}, {details['y']})"
97+
args_str = f"_{details['button']}({details['x']}, {details['y']})"
9898
elif action_type == "type" and "text" in details:
9999
text = details["text"]
100100
if len(text) > 50:
101101
text = text[:47] + "..."
102-
args_str = f'"{text}"'
103-
elif action_type == "key" and "key" in details:
104-
args_str = f"'{details['key']}'"
102+
args_str = f'("{text}")'
103+
elif action_type == "key" and "text" in details:
104+
args_str = f"('{details['text']}')"
105105
elif action_type == "scroll" and "x" in details and "y" in details:
106106
args_str = f"({details['x']}, {details['y']})"
107107

libs/python/agent/agent/computer_handler.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import base64
6-
from typing import Dict, List, Any, Literal, Union
6+
from typing import Dict, List, Any, Literal, Union, Optional
77
from .types import Computer
88

99

@@ -14,11 +14,13 @@ def __init__(self, computer_interface):
1414
"""Initialize with a computer interface (from tool schema)."""
1515
self.interface = computer_interface
1616

17+
# ==== Computer-Use-Preview Action Space ====
18+
1719
async def get_environment(self) -> Literal["windows", "mac", "linux", "browser"]:
1820
"""Get the current environment type."""
1921
# For now, return a default - this could be enhanced to detect actual environment
2022
return "windows"
21-
23+
2224
async def get_dimensions(self) -> tuple[int, int]:
2325
"""Get screen dimensions as (width, height)."""
2426
screen_size = await self.interface.get_screen_size()
@@ -94,6 +96,14 @@ async def get_current_url(self) -> str:
9496
# For now, return empty string
9597
return ""
9698

99+
# ==== Anthropic Computer Action Space ====
100+
async def left_mouse_down(self, x: Optional[int] = None, y: Optional[int] = None) -> None:
101+
"""Left mouse down at coordinates."""
102+
await self.interface.mouse_down(x, y, button="left")
103+
104+
async def left_mouse_up(self, x: Optional[int] = None, y: Optional[int] = None) -> None:
105+
"""Left mouse up at coordinates."""
106+
await self.interface.mouse_up(x, y, button="left")
97107

98108
def acknowledge_safety_check_callback(message: str, allow_always: bool = False) -> bool:
99109
"""Safety check callback for user acknowledgment."""

0 commit comments

Comments
 (0)