Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/askui/computer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ def mouse_move(
@validate_call
def mouse_scroll(
self,
x: int,
y: int,
dx: int,
dy: int,
) -> None:
"""
Simulates scrolling the mouse wheel by the specified horizontal and vertical amounts.

Args:
x (int): The horizontal scroll amount. Positive values typically scroll right, negative values scroll left.
y (int): The vertical scroll amount. Positive values typically scroll down, negative values scroll up.
dx (int): The horizontal scroll amount. Positive values typically scroll right, negative values scroll left.
dy (int): The vertical scroll amount. Positive values typically scroll down, negative values scroll up.

Note:
The actual scroll direction depends on the operating system's configuration.
Expand All @@ -248,8 +248,8 @@ def mouse_scroll(
agent.mouse_scroll(3, 0) # Usually scrolls right 3 units
```
"""
self._reporter.add_message("User", f'mouse_scroll: "{x}", "{y}"')
self.tools.os.mouse_scroll(x, y)
self._reporter.add_message("User", f'mouse_scroll: "{dx}", "{dy}"')
self.tools.os.mouse_scroll(dx, dy)

@telemetry.record_call(exclude={"text", "locator"})
@validate_call(config=ConfigDict(arbitrary_types_allowed=True))
Expand Down
6 changes: 3 additions & 3 deletions src/askui/tools/agent_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ def mouse_up(self, button: MouseButton = "left") -> None:
raise NotImplementedError

@abstractmethod
def mouse_scroll(self, x: int, y: int) -> None:
def mouse_scroll(self, dx: int, dy: int) -> None:
"""
Simulates scrolling the mouse wheel.

Args:
x (int): The horizontal scroll amount. Positive values scroll right,
dx (int): The horizontal scroll amount. Positive values scroll right,
negative values scroll left.
y (int): The vertical scroll amount. Positive values scroll down,
dy (int): The vertical scroll amount. Positive values scroll down,
negative values scroll up.
"""
raise NotImplementedError
Expand Down
16 changes: 8 additions & 8 deletions src/askui/tools/askui/askui_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,37 +503,37 @@ def mouse_up(self, button: Literal["left", "middle", "right"] = "left") -> None:

@telemetry.record_call()
@override
def mouse_scroll(self, x: int, y: int) -> None:
def mouse_scroll(self, dx: int, dy: int) -> None:
"""
Scroll the mouse wheel.

Args:
x (int): The horizontal scroll amount. Positive values scroll right,
dx (int): The horizontal scroll amount. Positive values scroll right,
negative values scroll left.
y (int): The vertical scroll amount. Positive values scroll down,
dy (int): The vertical scroll amount. Positive values scroll down,
negative values scroll up.
"""
self._reporter.add_message("AgentOS", f"mouse_scroll({x}, {y})")
if x != 0:
self._reporter.add_message("AgentOS", f"mouse_scroll({dx}, {dy})")
if dx != 0:
self._run_recorder_action(
acion_class_id=controller_v1_pbs.ActionClassID_MouseWheelScroll,
action_parameters=controller_v1_pbs.ActionParameters(
mouseWheelScroll=controller_v1_pbs.ActionParameters_MouseWheelScroll(
direction=controller_v1_pbs.MouseWheelScrollDirection.MouseWheelScrollDirection_Horizontal,
deltaType=controller_v1_pbs.MouseWheelDeltaType.MouseWheelDelta_Raw,
delta=x,
delta=dx,
milliseconds=50,
)
),
)
if y != 0:
if dy != 0:
self._run_recorder_action(
acion_class_id=controller_v1_pbs.ActionClassID_MouseWheelScroll,
action_parameters=controller_v1_pbs.ActionParameters(
mouseWheelScroll=controller_v1_pbs.ActionParameters_MouseWheelScroll(
direction=controller_v1_pbs.MouseWheelScrollDirection.MouseWheelScrollDirection_Vertical,
deltaType=controller_v1_pbs.MouseWheelDeltaType.MouseWheelDelta_Raw,
delta=y,
delta=dy,
milliseconds=50,
)
),
Expand Down
21 changes: 16 additions & 5 deletions src/askui/tools/computer/mouse_scroll_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@
def __init__(self, agent_os: ComputerAgentOsFacade | None = None) -> None:
super().__init__(
name="mouse_scroll",
description="Scroll the mouse wheel at the current position.",
description=(
"Scroll the mouse wheel at the current position. "
"The scroll amount is specified in lines. "
"For example, dy=3 scrolls down 3 lines and dy=-3 scrolls up 3 lines. "
"Use small values (1-5) for precise scrolling and larger values (10-20) for fast scrolling. "

Check failure on line 15 in src/askui/tools/computer/mouse_scroll_tool.py

View workflow job for this annotation

GitHub Actions / Run Checks

ruff (E501)

src/askui/tools/computer/mouse_scroll_tool.py:15:89: E501 Line too long (109 > 88)
"Note: The actual scroll direction may vary depending on the OS configuration "

Check failure on line 16 in src/askui/tools/computer/mouse_scroll_tool.py

View workflow job for this annotation

GitHub Actions / Run Checks

ruff (E501)

src/askui/tools/computer/mouse_scroll_tool.py:16:89: E501 Line too long (95 > 88)
"(e.g., natural scrolling on macOS reverses the direction). "
"If you observe that scrolling moves in the opposite direction than expected, "

Check failure on line 18 in src/askui/tools/computer/mouse_scroll_tool.py

View workflow job for this annotation

GitHub Actions / Run Checks

ruff (E501)

src/askui/tools/computer/mouse_scroll_tool.py:18:89: E501 Line too long (95 > 88)
"invert the values (e.g., use negative instead of positive and vice versa)."

Check failure on line 19 in src/askui/tools/computer/mouse_scroll_tool.py

View workflow job for this annotation

GitHub Actions / Run Checks

ruff (E501)

src/askui/tools/computer/mouse_scroll_tool.py:19:89: E501 Line too long (92 > 88)
),
input_schema={
"type": "object",
"properties": {
"dx": {
"type": "integer",
"description": (
"The horizontal scroll amount. "
"Positive values scroll right, negative values scroll left."
"The horizontal scroll amount in lines. "
"Positive values scroll right, negative values scroll left. "

Check failure on line 28 in src/askui/tools/computer/mouse_scroll_tool.py

View workflow job for this annotation

GitHub Actions / Run Checks

ruff (E501)

src/askui/tools/computer/mouse_scroll_tool.py:28:89: E501 Line too long (89 > 88)
"Use 0 if no horizontal scrolling is needed."
),
},
"dy": {
"type": "integer",
"description": (
"The vertical scroll amount. "
"Positive values scroll down, negative values scroll up."
"The vertical scroll amount in lines. "
"Positive values scroll down, negative values scroll up. "
"Use 0 if no vertical scrolling is needed."
),
},
},
Expand Down
7 changes: 2 additions & 5 deletions src/askui/tools/computer_agent_os_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ def mouse_down(self, button: MouseButton = "left") -> None:
def mouse_up(self, button: MouseButton = "left") -> None:
self._agent_os.mouse_up(button)

def mouse_scroll(self, x: int, y: int) -> None:
scaled_x, scaled_y = self._scale_coordinates_back(
x, y, check_coordinates_in_bounds=False
)
self._agent_os.mouse_scroll(scaled_x, scaled_y)
def mouse_scroll(self, dx: int, dy: int) -> None:
self._agent_os.mouse_scroll(dx, dy)

def keyboard_pressed(
self, key: PcKey | ModifierKey, modifier_keys: list[ModifierKey] | None = None
Expand Down
8 changes: 4 additions & 4 deletions src/askui/tools/playwright/agent_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,21 @@ def mouse_up(self, button: Literal["left", "middle", "right"] = "left") -> None:
self._page.mouse.up(button=button)

@override
def mouse_scroll(self, x: int, y: int) -> None:
def mouse_scroll(self, dx: int, dy: int) -> None:
"""
Simulates scrolling the mouse wheel.

Args:
x (int): The horizontal scroll amount. Positive values scroll right,
dx (int): The horizontal scroll amount. Positive values scroll right,
negative values scroll left.
y (int): The vertical scroll amount. Positive values scroll down,
dy (int): The vertical scroll amount. Positive values scroll down,
negative values scroll up.
"""
if not self._page:
error_msg = "No active page. Call connect() first."
raise RuntimeError(error_msg)

self._page.mouse.wheel(delta_x=x, delta_y=y)
self._page.mouse.wheel(delta_x=dx, delta_y=dy)

@override
def keyboard_pressed(
Expand Down
Loading