|
4 | 4 | from dataclasses import dataclass |
5 | 5 | from typing import Annotated, Literal, TypedDict, cast, get_args |
6 | 6 |
|
7 | | -from anthropic.types.beta import (BetaToolComputerUse20241022Param, |
8 | | - BetaToolComputerUse20250124Param) |
| 7 | +from anthropic.types.beta import ( |
| 8 | + BetaToolComputerUse20241022Param, |
| 9 | + BetaToolComputerUse20250124Param, |
| 10 | +) |
9 | 11 | from PIL import Image |
10 | 12 | from pydantic import Field, validate_call |
11 | 13 | from typing_extensions import Self, override |
12 | 14 |
|
13 | 15 | from askui.tools.agent_os import AgentOs, Coordinate, ModifierKey, PcKey |
14 | | -from askui.utils.image_utils import (scale_coordinates_back, |
15 | | - scale_coordinates_with_padding, |
16 | | - scale_image_with_padding) |
| 16 | +from askui.utils.image_utils import ( |
| 17 | + scale_coordinates_back, |
| 18 | + scale_coordinates_with_padding, |
| 19 | + scale_image_with_padding, |
| 20 | +) |
17 | 21 |
|
18 | 22 | from ..models.shared.tools import InputSchema, Tool |
19 | 23 |
|
@@ -325,11 +329,17 @@ def _screenshot(self) -> Image.Image: |
325 | 329 | self._real_screen_height = screenshot.height |
326 | 330 | return scale_image_with_padding(screenshot, self._width, self._height) |
327 | 331 |
|
328 | | - |
329 | 332 | def _get_mouse_position_scaled(self) -> Coordinate: |
330 | 333 | mouse_position: Coordinate = self._agent_os.get_mouse_position() |
331 | 334 | real_screen_width, real_screen_height = self._get_real_screen_resolution() |
332 | | - x, y = scale_coordinates_with_padding(mouse_position.x, mouse_position.y, real_screen_width, real_screen_height, self._width, self._height) |
| 335 | + x, y = scale_coordinates_with_padding( |
| 336 | + mouse_position.x, |
| 337 | + mouse_position.y, |
| 338 | + real_screen_width, |
| 339 | + real_screen_height, |
| 340 | + self._width, |
| 341 | + self._height, |
| 342 | + ) |
333 | 343 | return Coordinate(x=int(x), y=int(y)) |
334 | 344 |
|
335 | 345 |
|
@@ -433,7 +443,7 @@ def __call__( # noqa: C901 |
433 | 443 | scroll_amount: Annotated[int, Field(ge=0)] | None = None, |
434 | 444 | duration: Annotated[float, Field(ge=0.0, le=100.0)] | None = None, |
435 | 445 | key: str | None = None, # maybe not all keys supported |
436 | | - ) -> Image.Image | None: |
| 446 | + ) -> Image.Image | None | Coordinate: |
437 | 447 | match action: |
438 | 448 | case "hold_key": |
439 | 449 | self._hold_key(keystroke=text, duration=duration) # type: ignore[arg-type] |
|
0 commit comments