Skip to content

Commit 7ae85f2

Browse files
committed
fix(cua): handle lowercase modifier keys and unify right-click in Tzafon templates
1 parent 00b5338 commit 7ae85f2

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

pkg/templates/python/tzafon-computer-use/tools/computer.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515

1616
from .base import ToolError
1717

18-
MODIFIER_MAP = {"Control": "Ctrl", "Enter": "Return"}
18+
MODIFIER_MAP = {
19+
"Control": "Ctrl",
20+
"control": "Ctrl",
21+
"ctrl": "Ctrl",
22+
"Enter": "Return",
23+
"enter": "Return",
24+
"Escape": "Escape",
25+
"esc": "Escape",
26+
"Shift": "Shift",
27+
"shift": "Shift",
28+
"Alt": "Alt",
29+
"alt": "Alt",
30+
}
1931
MODIFIER_NAMES = {"Ctrl", "Shift", "Alt", "Meta", "Super"}
2032

2133

@@ -65,7 +77,11 @@ async def execute(self, action: Any) -> None:
6577
"""Map a Tzafon model action to Kernel Computer Controls."""
6678
t = action.type
6779

68-
if t == "click":
80+
if t == "click" and getattr(action, "button", "left") == "right":
81+
self.kernel.browsers.computer.click_mouse(
82+
self.session_id, x=self._x(action), y=self._y(action), button="right",
83+
)
84+
elif t == "click":
6985
self.kernel.browsers.computer.click_mouse(
7086
self.session_id, x=self._x(action), y=self._y(action),
7187
)
@@ -77,10 +93,6 @@ async def execute(self, action: Any) -> None:
7793
self.kernel.browsers.computer.click_mouse(
7894
self.session_id, x=self._x(action), y=self._y(action), num_clicks=3,
7995
)
80-
elif t == "right_click":
81-
self.kernel.browsers.computer.click_mouse(
82-
self.session_id, x=self._x(action), y=self._y(action), button="right",
83-
)
8496
elif t == "type":
8597
self.kernel.browsers.computer.type_text(self.session_id, text=action.text)
8698
elif t in ("key", "keypress"):

pkg/templates/typescript/tzafon-computer-use/tools/computer.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export class ToolError extends Error {
1717

1818
const MODIFIER_MAP: Record<string, string> = {
1919
Control: 'Ctrl',
20+
control: 'Ctrl',
21+
ctrl: 'Ctrl',
2022
Enter: 'Return',
23+
enter: 'Return',
24+
Escape: 'Escape',
25+
esc: 'Escape',
26+
Shift: 'Shift',
27+
shift: 'Shift',
28+
Alt: 'Alt',
29+
alt: 'Alt',
2130
};
2231

2332
const MODIFIER_NAMES = new Set(['Ctrl', 'Shift', 'Alt', 'Meta', 'Super']);
@@ -75,6 +84,13 @@ export class ComputerTool {
7584
}
7685

7786
async execute(action: any): Promise<void> {
87+
if (action.type === 'click' && action.button === 'right') {
88+
await this.kernel.browsers.computer.clickMouse(this.sessionId, {
89+
x: this.x(action), y: this.y(action), button: 'right',
90+
});
91+
return;
92+
}
93+
7894
switch (action.type) {
7995
case 'click':
8096
await this.kernel.browsers.computer.clickMouse(this.sessionId, {
@@ -94,12 +110,6 @@ export class ComputerTool {
94110
});
95111
break;
96112

97-
case 'right_click':
98-
await this.kernel.browsers.computer.clickMouse(this.sessionId, {
99-
x: this.x(action), y: this.y(action), button: 'right',
100-
});
101-
break;
102-
103113
case 'type':
104114
await this.kernel.browsers.computer.typeText(this.sessionId, {
105115
text: action.text,

0 commit comments

Comments
 (0)