From 1df8194de1373e5c7521bb0e12abb6e9ddffe140 Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Tue, 29 Apr 2025 12:00:09 -0700 Subject: [PATCH] fix hotkeys on uitars and openai provider --- libs/agent/agent/providers/openai/tools/computer.py | 6 +----- libs/agent/agent/providers/uitars/tools/computer.py | 8 ++++++-- libs/computer/computer/interface/models.py | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/agent/agent/providers/openai/tools/computer.py b/libs/agent/agent/providers/openai/tools/computer.py index 5ec9460a..90ef5935 100644 --- a/libs/agent/agent/providers/openai/tools/computer.py +++ b/libs/agent/agent/providers/openai/tools/computer.py @@ -240,11 +240,7 @@ class ComputerTool(BaseComputerTool, BaseOpenAITool): if len(mapped_keys) > 1: # For key combinations (like Ctrl+C) - for k in mapped_keys: - await self.computer.interface.press_key(k) - await asyncio.sleep(0.1) - for k in reversed(mapped_keys): - await self.computer.interface.press_key(k) + await self.computer.interface.hotkey(*mapped_keys) else: # Single key press await self.computer.interface.press_key(mapped_keys[0]) diff --git a/libs/agent/agent/providers/uitars/tools/computer.py b/libs/agent/agent/providers/uitars/tools/computer.py index 5cf7f67a..4d5f2ce3 100644 --- a/libs/agent/agent/providers/uitars/tools/computer.py +++ b/libs/agent/agent/providers/uitars/tools/computer.py @@ -173,9 +173,13 @@ class ComputerTool(BaseComputerTool): elif action == "hotkey": if "keys" in kwargs: keys = kwargs["keys"] - for key in keys: - await self.computer.interface.press_key(key) + if len(keys) > 1: + await self.computer.interface.hotkey(*keys) + else: + # Single key press + await self.computer.interface.press_key(keys[0]) + # Wait for UI to update await asyncio.sleep(0.3) diff --git a/libs/computer/computer/interface/models.py b/libs/computer/computer/interface/models.py index 9a90acb4..e8ec1b47 100644 --- a/libs/computer/computer/interface/models.py +++ b/libs/computer/computer/interface/models.py @@ -8,7 +8,7 @@ NavigationKey = Literal['pagedown', 'pageup', 'home', 'end', 'left', 'right', 'u SpecialKey = Literal['enter', 'esc', 'tab', 'space', 'backspace', 'del'] # Modifier key literals -ModifierKey = Literal['ctrl', 'shift', 'win', 'command', 'option'] +ModifierKey = Literal['ctrl', 'alt', 'shift', 'win', 'command', 'option'] # Function key literals FunctionKey = Literal['f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12'] @@ -39,6 +39,7 @@ class Key(Enum): DELETE = 'del' # Modifier keys + ALT = 'alt' CTRL = 'ctrl' SHIFT = 'shift' WIN = 'win' @@ -85,6 +86,7 @@ class Key(Enum): 'delete': cls.DELETE, 'del': cls.DELETE, # Modifier key mappings + 'alt': cls.ALT, 'ctrl': cls.CTRL, 'control': cls.CTRL, 'shift': cls.SHIFT, @@ -95,7 +97,6 @@ class Key(Enum): 'cmd': cls.COMMAND, '⌘': cls.COMMAND, 'option': cls.OPTION, - 'alt': cls.OPTION, '⌥': cls.OPTION, }