1+ import re
2+
13from askui .models .shared import ComputerBaseTool , ToolTags
24from askui .tools .computer_agent_os_facade import ComputerAgentOsFacade
35
@@ -8,17 +10,20 @@ class ComputerMoveMouseTool(ComputerBaseTool):
810 def __init__ (self , agent_os : ComputerAgentOsFacade | None = None ) -> None :
911 super ().__init__ (
1012 name = "move_mouse" ,
11- description = "Move the mouse to a specific position." ,
13+ description = """Move the mouse to a specific position.
14+ Pass x and y as separate integer values, not as a combined string.""" ,
1215 input_schema = {
1316 "type" : "object" ,
1417 "properties" : {
1518 "x" : {
1619 "type" : "integer" ,
17- "description" : "The x coordinate of the mouse position as int." ,
20+ "description" : """The x (horizontal) pixel coordinate.
21+ Must be a single integer, e.g. 330.""" ,
1822 },
1923 "y" : {
2024 "type" : "integer" ,
21- "description" : "The y coordinate of the mouse position as int." ,
25+ "description" : """The y (vertical) pixel coordinate.
26+ Must be a single integer, e.g. 182.""" ,
2227 },
2328 },
2429 "required" : ["x" , "y" ],
@@ -33,12 +38,18 @@ def __call__(self, x: int, y: int) -> str:
3338 # 1. As strings instead of ints (e.g., x="330", y="182")
3439 # 2. Both coords as a single comma-separated string in x
3540 # (e.g., x="330, 182" or x="330, ")
36- # We handle both cases here.
37- if isinstance (x , str ) and "," in x : # type: ignore[unreachable]
38- parts = [p .strip () for p in x .split ("," ) if p .strip ()] # type: ignore[unreachable]
39- x = parts [0 ]
40- if len (parts ) > 1 :
41- y = parts [1 ]
42- x , y = int (x ), int (y )
41+ # We extract all numbers from the string representations to handle both cases.
42+ if not (isinstance (x , int ) and isinstance (y , int )):
43+ x , y = self ._parse_coordinates (x , y ) # type: ignore[unreachable]
4344 self .agent_os .mouse_move (x , y )
4445 return f"Mouse was moved to position ({ x } , { y } )."
46+
47+ @staticmethod
48+ def _parse_coordinates (x : float | str , y : float | str ) -> tuple [int , int ]:
49+ _NUMBER_PATTERN = re .compile (r"-?\d+" )
50+ combined = f"{ x } ,{ y } "
51+ numbers = _NUMBER_PATTERN .findall (combined )
52+ if len (numbers ) < 2 :
53+ error_msg = f"Could not parse coordinates from x={ x !r} , y={ y !r} "
54+ raise ValueError (error_msg )
55+ return int (numbers [0 ]), int (numbers [1 ])
0 commit comments