computer-use-ootb-internal 0.0.121__py3-none-any.whl → 0.0.123__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,40 +1,40 @@
1
- """
2
- Test script to verify cursor animation is working
3
- """
4
- import asyncio
5
- import sys
6
- import time
7
- from pathlib import Path
8
- from computer_use_ootb_internal.computer_use_demo.tools.computer import ComputerTool
9
-
10
- async def test_animations():
11
-
12
- # Initialize the computer tool
13
- computer = ComputerTool()
14
-
15
- # Test mouse move animation
16
- print("Testing mouse move animation...")
17
- await computer(action="mouse_move_windll", coordinate=(500, 500))
18
- print("Waiting 2 seconds...")
19
- await asyncio.sleep(2)
20
-
21
- # Test click animation
22
- print("Testing click animation...")
23
- await computer(action="left_click_windll", coordinate=(700, 300))
24
- print("Waiting 2 seconds...")
25
- await asyncio.sleep(2)
26
-
27
- # Test another move
28
- print("Testing move and click sequence...")
29
- await computer(action="mouse_move_windll", coordinate=(300, 300))
30
- await asyncio.sleep(1)
31
- await computer(action="left_click_windll", coordinate=(300, 300))
32
-
33
- # Wait for animations to complete
34
- print("Waiting for animations to complete...")
35
- await asyncio.sleep(3)
36
-
37
- print("Test completed")
38
-
39
- if __name__ == "__main__":
1
+ """
2
+ Test script to verify cursor animation is working
3
+ """
4
+ import asyncio
5
+ import sys
6
+ import time
7
+ from pathlib import Path
8
+ from computer_use_ootb_internal.computer_use_demo.tools.computer import ComputerTool
9
+
10
+ async def test_animations():
11
+
12
+ # Initialize the computer tool
13
+ computer = ComputerTool()
14
+
15
+ # Test mouse move animation
16
+ print("Testing mouse move animation...")
17
+ await computer(action="mouse_move_windll", coordinate=(500, 500))
18
+ print("Waiting 2 seconds...")
19
+ await asyncio.sleep(2)
20
+
21
+ # Test click animation
22
+ print("Testing click animation...")
23
+ await computer(action="left_click_windll", coordinate=(700, 300))
24
+ print("Waiting 2 seconds...")
25
+ await asyncio.sleep(2)
26
+
27
+ # Test another move
28
+ print("Testing move and click sequence...")
29
+ await computer(action="mouse_move_windll", coordinate=(300, 300))
30
+ await asyncio.sleep(1)
31
+ await computer(action="left_click_windll", coordinate=(300, 300))
32
+
33
+ # Wait for animations to complete
34
+ print("Waiting for animations to complete...")
35
+ await asyncio.sleep(3)
36
+
37
+ print("Test completed")
38
+
39
+ if __name__ == "__main__":
40
40
  asyncio.run(test_animations())
@@ -92,12 +92,12 @@ class TeachmodeExecutor:
92
92
 
93
93
  if isinstance(tool_result, ToolResult):
94
94
  print(f"[teachmode_executor] tool_result: {tool_result}")
95
- tool_result_message = {"role": "assistant", "content": tool_result.output, "type": "action", "action_type": tool_result.base_type}
95
+ tool_result_message = {"role": "assistant", "content": tool_result.output, "type": tool_result.type, "action_type": tool_result.action_base_type}
96
96
  yield tool_result_message
97
97
 
98
98
  elif isinstance(tool_result, ToolError):
99
99
  print(f"[teachmode_executor] tool_error: {tool_result}")
100
- tool_result_message = {"role": "assistant", "content": tool_result.output, "type": "error"}
100
+ tool_result_message = {"role": "assistant", "content": tool_result.output, "type": "error", "action_type": ""}
101
101
  yield tool_result_message
102
102
 
103
103
  return tool_result_message
@@ -197,7 +197,7 @@ class TeachmodeExecutor:
197
197
 
198
198
  except Exception as e:
199
199
  print(f"Error {e} in parsing output: {action_item}")
200
- import pdb; pdb.set_trace()
200
+ # import pdb; pdb.set_trace()
201
201
  return None
202
202
 
203
203
 
@@ -28,7 +28,7 @@ class ToolResult:
28
28
  error: str | None = None
29
29
  base64_image: str | None = None
30
30
  system: str | None = None
31
- base_type: str | None = None
31
+ action_base_type: str | None = None
32
32
 
33
33
  def __bool__(self):
34
34
  return any(getattr(self, field.name) for field in fields(self))
@@ -66,6 +66,6 @@ class ToolFailure(ToolResult):
66
66
  class ToolError(Exception):
67
67
  """Raised when a tool encounters an error."""
68
68
 
69
- def __init__(self, output: str, base_type: str):
69
+ def __init__(self, output: str, action_base_type: str):
70
70
  self.output = output
71
- self.base_type = base_type
71
+ self.action_base_type = action_base_type
@@ -217,13 +217,13 @@ class ComputerTool(BaseAnthropicTool):
217
217
 
218
218
  if action in ("mouse_move", "left_click_drag"):
219
219
  if coordinate is None:
220
- raise ToolError(output=f"coordinate is required for {action}", base_type="error")
220
+ raise ToolError(output=f"coordinate is required for {action}", action_base_type="error")
221
221
  if text is not None:
222
- raise ToolError(output=f"text is not accepted for {action}", base_type="error")
222
+ raise ToolError(output=f"text is not accepted for {action}", action_base_type="error")
223
223
  if not isinstance(coordinate, (list, tuple)) or len(coordinate) != 2:
224
- raise ToolError(output=f"{coordinate} must be a tuple of length 2", base_type="error")
224
+ raise ToolError(output=f"{coordinate} must be a tuple of length 2", action_base_type="error")
225
225
  if not all(isinstance(i, int) for i in coordinate):
226
- raise ToolError(output=f"{coordinate} must be a tuple of non-negative ints", base_type="error")
226
+ raise ToolError(output=f"{coordinate} must be a tuple of non-negative ints", action_base_type="error")
227
227
 
228
228
  if self.is_scaling:
229
229
  x, y = self.scale_coordinates(
@@ -237,22 +237,22 @@ class ComputerTool(BaseAnthropicTool):
237
237
 
238
238
  if action == "mouse_move":
239
239
  pyautogui.moveTo(x, y)
240
- return ToolResult(output=f"Mouse move", base_type="move")
240
+ return ToolResult(output=f"Mouse move", action_base_type="move")
241
241
 
242
242
  elif action == "left_click_drag":
243
243
  current_x, current_y = pyautogui.position()
244
244
  pyautogui.dragTo(x, y, duration=0.5) # Adjust duration as needed
245
- return ToolResult(output=f"Mouse drag", base_type="move")
245
+ return ToolResult(output=f"Mouse drag", action_base_type="move")
246
246
 
247
247
  # Action Type 2: Required text (keynames)
248
248
  # Actions: key, type, key_down, key_up
249
249
  if action in ("key", "type", "key_down", "key_up"):
250
250
  if text is None:
251
- raise ToolError(output=f"text is required for {action}", base_type="error")
251
+ raise ToolError(output=f"text is required for {action}", action_base_type="error")
252
252
  if coordinate is not None:
253
- raise ToolError(output=f"coordinate is not accepted for {action}", base_type="error")
253
+ raise ToolError(output=f"coordinate is not accepted for {action}", action_base_type="error")
254
254
  if not isinstance(text, str):
255
- raise ToolError(output=f"{text} must be a string", base_type="error")
255
+ raise ToolError(output=f"{text} must be a string", action_base_type="error")
256
256
 
257
257
  if action == "key":
258
258
  # Handle key combinations
@@ -265,19 +265,19 @@ class ComputerTool(BaseAnthropicTool):
265
265
  key = self.key_conversion.get(key.strip(), key.strip())
266
266
  key = key.lower()
267
267
  pyautogui.keyUp(key) # Release each key in reverse order
268
- return ToolResult(output=f"Press key '{text}'", base_type="key")
268
+ return ToolResult(output=f"Press key '{text}'", action_base_type="key")
269
269
 
270
270
  elif action == "key_down":
271
271
  pyautogui.keyDown(text)
272
- return ToolResult(output=f"Press key '{text}'", base_type="key")
272
+ return ToolResult(output=f"Press key '{text}'", action_base_type="key")
273
273
  elif action == "key_up":
274
274
  pyautogui.keyUp(text)
275
- return ToolResult(output=f"Release key '{text}'", base_type="key")
275
+ return ToolResult(output=f"Release key '{text}'", action_base_type="key")
276
276
 
277
277
  elif action == "type":
278
278
  pyautogui.typewrite(text, interval=TYPING_DELAY_MS / 1000) # Convert ms to seconds
279
279
  # screenshot_base64 = (await self.screenshot()).base64_image
280
- return ToolResult(output=f"Type '{text}'", base_type="type") # base64_image=screenshot_base64)
280
+ return ToolResult(output=f"Type '{text}'", action_base_type="type") # base64_image=screenshot_base64)
281
281
 
282
282
  # Action Type 3: No required text or coordinates
283
283
  # Actions: left_click, right_click, double_click, middle_click, left_press, scroll_down, scroll_up
@@ -292,9 +292,9 @@ class ComputerTool(BaseAnthropicTool):
292
292
  "wait",
293
293
  ):
294
294
  if text is not None:
295
- raise ToolError(output=f"text is not accepted for {action}", base_type="error")
295
+ raise ToolError(output=f"text is not accepted for {action}", action_base_type="error")
296
296
  # if coordinate is not None:
297
- # raise ToolError(output=f"coordinate is not accepted for {action}", base_type="error")
297
+ # raise ToolError(output=f"coordinate is not accepted for {action}", action_base_type="error")
298
298
 
299
299
  if coordinate is not None:
300
300
  x, y = coordinate
@@ -304,70 +304,71 @@ class ComputerTool(BaseAnthropicTool):
304
304
  if action == "left_click":
305
305
  show_click(x, y)
306
306
  pyautogui.click(x=x, y=y)
307
- return ToolResult(output="Left click", base_type="click")
307
+ return ToolResult(output="Left click", action_base_type="click")
308
308
  elif action == "right_click":
309
309
  show_click(x, y)
310
310
  pyautogui.rightClick(x=x, y=y)
311
- return ToolResult(output="Right click", base_type="click")
311
+ return ToolResult(output="Right click", action_base_type="click")
312
312
  elif action == "middle_click":
313
313
  show_click(x, y)
314
314
  pyautogui.middleClick(x=x, y=y)
315
- return ToolResult(output="Middle click", base_type="click")
315
+ return ToolResult(output="Middle click", action_base_type="click")
316
316
  elif action == "double_click":
317
317
  show_click(x, y)
318
318
  pyautogui.doubleClick(x=x, y=y)
319
- return ToolResult(output="Double click", base_type="click")
319
+ return ToolResult(output="Double click", action_base_type="click")
320
320
  elif action == "left_press":
321
321
  show_click(x, y)
322
322
  pyautogui.mouseDown(x=x, y=y)
323
323
  time.sleep(1)
324
324
  pyautogui.mouseUp(x=x, y=y)
325
- return ToolResult(output="Left press", base_type="click")
325
+ return ToolResult(output="Left press", action_base_type="click")
326
326
 
327
327
  elif action == "scroll_down":
328
328
  pyautogui.scroll(-200) # Adjust scroll amount as needed
329
- return ToolResult(output="Scrolled down", base_type="scroll")
329
+ return ToolResult(output="Scrolled down", action_base_type="scroll")
330
330
 
331
331
  elif action == "scroll_up":
332
332
  pyautogui.scroll(200) # Adjust scroll amount as needed
333
- return ToolResult(output="Scrolled up", base_type="scroll")
333
+ return ToolResult(output="Scrolled up", action_base_type="scroll")
334
334
 
335
335
  elif action == "wait":
336
336
  time.sleep(15)
337
- return ToolResult(output="Wait for next event", base_type="wait")
337
+ return ToolResult(output="Wait for next event", action_base_type="wait")
338
338
 
339
- return ToolResult(output=f"Performed {action}", base_type="unknown")
339
+ return ToolResult(output=f"Performed {action}", action_base_type="unknown")
340
340
 
341
341
  # Action Type 4: Miscs. No required text or coordinates
342
342
  # Actions: screenshot, cursor_position
343
343
  if action in ("screenshot", "cursor_position"):
344
344
  if text is not None:
345
- raise ToolError(output=f"text is not accepted for {action}", base_type="error")
345
+ raise ToolError(output=f"text is not accepted for {action}", action_base_type="error")
346
346
  if coordinate is not None:
347
- raise ToolError(output=f"coordinate is not accepted for {action}", base_type="error")
347
+ raise ToolError(output=f"coordinate is not accepted for {action}", action_base_type="error")
348
+
348
349
  if action == "screenshot":
349
350
  return await self.screenshot()
350
351
  elif action == "cursor_position":
351
352
  x, y = pyautogui.position()
352
353
  # x, y = self.scale_coordinates(ScalingSource.COMPUTER, x, y)
353
- return ToolResult(output=f"Cursor position ({x},{y})", base_type="unknown")
354
+ return ToolResult(output=f"Cursor position ({x},{y})", action_base_type="unknown")
354
355
 
355
356
  # Action Type 5: StarRail Mode
356
357
  # Actions: sr_scroll_down, sr_scroll_up
357
358
  if action in ("sr_scroll_down", "sr_scroll_up"):
358
359
  if text is not None:
359
- raise ToolError(output=f"text is not accepted for {action}", base_type="error")
360
+ raise ToolError(output=f"text is not accepted for {action}", action_base_type="error")
360
361
 
361
362
  if action == "sr_scroll_down":
362
363
  for _ in range(20):
363
364
  pyautogui.scroll(-100) # Adjust scroll amount as needed
364
365
  time.sleep(0.001)
365
- return ToolResult(output="Scroll down", base_type="scroll")
366
+ return ToolResult(output="Scroll down", action_base_type="scroll")
366
367
  elif action == "sr_scroll_up":
367
368
  for _ in range(20):
368
369
  pyautogui.scroll(100) # Adjust scroll amount as needed
369
370
  time.sleep(0.001)
370
- return ToolResult(output="Scroll up", base_type="scroll")
371
+ return ToolResult(output="Scroll up", action_base_type="scroll")
371
372
 
372
373
  # starrail browser mode
373
374
  if action in ("left_click_windll", "mouse_move_windll", "right_click_windll", "key_down_windll", "key_up_windll"):
@@ -381,11 +382,11 @@ class ComputerTool(BaseAnthropicTool):
381
382
  y = coordinate[1]+self.offset_y
382
383
  show_click(x, y)
383
384
  self.marbot_auto_gui.click(x=x, y=y)
384
- return ToolResult(output=f"Left click", base_type="click")
385
+ return ToolResult(output=f"Left click", action_base_type="click")
385
386
 
386
387
  elif action == "mouse_move_windll":
387
388
  if coordinate is None:
388
- raise ToolError(output=f"coordinate is required for {action}", base_type="error")
389
+ raise ToolError(output=f"coordinate is required for {action}", action_base_type="error")
389
390
 
390
391
  x0, y0 = pyautogui.position()
391
392
  # x0, y0 = self.scale_coordinates(ScalingSource.COMPUTER, x0, y0)
@@ -395,20 +396,21 @@ class ComputerTool(BaseAnthropicTool):
395
396
  show_move_to(x0, y0, x1, y1)
396
397
  self.marbot_auto_gui.moveTo(x=x1, y=y1)
397
398
 
398
- return ToolResult(output=f"Mouse move", base_type="move")
399
+ return ToolResult(output=f"Mouse move", action_base_type="move")
399
400
 
400
401
  # elif action == "right_click_windll":
401
402
  # self.marbot_auto_gui.rightClick(x=coordinate[0], y=coordinate[1])
402
403
  elif action == "key_down_windll":
403
404
  self.marbot_auto_gui.keyDown(text)
404
- return ToolResult(output=f"Key down '{text}'", base_type="key")
405
+ return ToolResult(output=f"Key down '{text}'", type="hidden", action_base_type="key")
406
+
405
407
  elif action == "key_up_windll":
406
408
  self.marbot_auto_gui.keyUp(text)
407
- return ToolResult(output=f"Key up '{text}'", base_type="key")
409
+ return ToolResult(output=f"Key up '{text}'", type="hidden", action_base_type="key")
408
410
 
409
- return ToolResult(output=f"Performed dll action:{action}", base_type="unknown")
411
+ return ToolResult(output=f"Performed dll action:{action}", action_base_type="unknown")
410
412
 
411
- raise ToolError(output=f"Invalid action: {action}", base_type="error")
413
+ raise ToolError(output=f"Invalid action: {action}", type="hidden", action_base_type="error")
412
414
 
413
415
 
414
416
  async def screenshot(self):
@@ -499,9 +501,9 @@ class ComputerTool(BaseAnthropicTool):
499
501
 
500
502
  if path.exists():
501
503
  # Return a ToolResult instance instead of a dictionary
502
- return ToolResult(base64_image=base64.b64encode(path.read_bytes()).decode(), base_type="screenshot")
504
+ return ToolResult(base64_image=base64.b64encode(path.read_bytes()).decode(), action_base_type="screenshot")
503
505
 
504
- raise ToolError(output=f"Failed to take screenshot: {path} does not exist.", base_type="error")
506
+ raise ToolError(output=f"Failed to take screenshot: {path} does not exist.", action_base_type="error")
505
507
 
506
508
  def padding_image(self, screenshot):
507
509
  """Pad the screenshot to 16:10 aspect ratio, when the aspect ratio is not 16:10."""
@@ -551,7 +553,7 @@ class ComputerTool(BaseAnthropicTool):
551
553
  y_scaling_factor = target_dimension["height"] / self.height
552
554
  if source == ScalingSource.API:
553
555
  if x > self.width or y > self.height:
554
- raise ToolError(output=f"Coordinates {x}, {y} are out of bounds", base_type="error")
556
+ raise ToolError(output=f"Coordinates {x}, {y} are out of bounds", action_base_type="error")
555
557
  # scale up
556
558
  return round(x / x_scaling_factor), round(y / y_scaling_factor)
557
559
  # scale down