-
Notifications
You must be signed in to change notification settings - Fork 54
Add get cursor position to computer tools #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mlikasam-askui
wants to merge
1
commit into
select-window
from
add-get_cursor_position-to-computer-tools
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| from .base import BaseAnthropicTool, ToolError, ToolResult | ||
|
|
||
| from ..utils import image_to_base64, scale_image_with_padding, scale_coordinates_back | ||
| from ..utils import image_to_base64, scale_coordinates_forward, scale_image_with_padding, scale_coordinates_back | ||
|
|
||
|
|
||
| Action = Literal[ | ||
|
|
@@ -180,8 +180,13 @@ def __call__( | |
| if action == "screenshot": | ||
| return self.screenshot() | ||
| elif action == "cursor_position": | ||
| # TODO: Implement in the future | ||
| return ToolError("cursor_position is not implemented by this agent") | ||
| if self.real_screen_height is None or self.real_screen_width is None: | ||
| screenshot = self.controller_client.screenshot(report=False) | ||
| self.real_screen_width = screenshot.width | ||
| self.real_screen_height = screenshot.height | ||
| mouse_x, mouse_y = self.controller_client.get_cursor_position() | ||
| scaled_x, scaled_y = scale_coordinates_forward(mouse_x, mouse_y, self.real_screen_width, self.real_screen_height, self.width, self.height) | ||
| return ToolResult(output=f"Cursor position: x={scaled_x}, y={scaled_y}") | ||
|
Comment on lines
+183
to
+189
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: All translation of coordination system are handeled in the future inside the agent os. |
||
| elif action == "left_click": | ||
| self.controller_client.click("left") | ||
| return ToolResult() | ||
|
|
@@ -202,6 +207,6 @@ def screenshot(self): | |
| screenshot = self.controller_client.screenshot() | ||
| self.real_screen_width = screenshot.width | ||
| self.real_screen_height = screenshot.height | ||
| scaled_screenshot = scale_image_with_padding(screenshot, 1280, 800) | ||
| scaled_screenshot = scale_image_with_padding(screenshot, self.width, self.height) | ||
| base64_image = image_to_base64(scaled_screenshot) | ||
| return ToolResult(base64_image=base64_image) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also check if the display (index) changed?