forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer.py
More file actions
133 lines (104 loc) · 4.25 KB
/
Copy pathcomputer.py
File metadata and controls
133 lines (104 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import abc
from typing import Literal
Environment = Literal["mac", "windows", "ubuntu", "browser"]
Button = Literal["left", "right", "wheel", "back", "forward"]
class Computer(abc.ABC):
"""A computer implemented with sync operations.
Subclasses provide the local runtime behind `ComputerTool`. Mouse action methods may
also accept a keyword-only `keys` argument to receive held modifier keys when the
driver supports them.
"""
@property
def environment(self) -> Environment | None:
"""Return preview tool metadata when the preview computer payload is required."""
return None
@property
def dimensions(self) -> tuple[int, int] | None:
"""Return preview display dimensions when the preview computer payload is required."""
return None
@abc.abstractmethod
def screenshot(self) -> str:
"""Return a base64-encoded PNG screenshot of the current display."""
pass
@abc.abstractmethod
def click(self, x: int, y: int, button: Button) -> None:
"""Click `button` at the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
def double_click(self, x: int, y: int) -> None:
"""Double-click at the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
def scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None:
"""Scroll at `(x, y)` by `(scroll_x, scroll_y)` units."""
pass
@abc.abstractmethod
def type(self, text: str) -> None:
"""Type `text` into the currently focused target."""
pass
@abc.abstractmethod
def wait(self) -> None:
"""Wait until the computer is ready for the next action."""
pass
@abc.abstractmethod
def move(self, x: int, y: int) -> None:
"""Move the mouse cursor to the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
def keypress(self, keys: list[str]) -> None:
"""Press the provided keys, such as `["ctrl", "c"]`."""
pass
@abc.abstractmethod
def drag(self, path: list[tuple[int, int]]) -> None:
"""Click-and-drag the mouse along the given sequence of `(x, y)` waypoints."""
pass
class AsyncComputer(abc.ABC):
"""A computer implemented with async operations.
Subclasses provide the local runtime behind `ComputerTool`. Mouse action methods may
also accept a keyword-only `keys` argument to receive held modifier keys when the
driver supports them.
"""
@property
def environment(self) -> Environment | None:
"""Return preview tool metadata when the preview computer payload is required."""
return None
@property
def dimensions(self) -> tuple[int, int] | None:
"""Return preview display dimensions when the preview computer payload is required."""
return None
@abc.abstractmethod
async def screenshot(self) -> str:
"""Return a base64-encoded PNG screenshot of the current display."""
pass
@abc.abstractmethod
async def click(self, x: int, y: int, button: Button) -> None:
"""Click `button` at the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
async def double_click(self, x: int, y: int) -> None:
"""Double-click at the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
async def scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None:
"""Scroll at `(x, y)` by `(scroll_x, scroll_y)` units."""
pass
@abc.abstractmethod
async def type(self, text: str) -> None:
"""Type `text` into the currently focused target."""
pass
@abc.abstractmethod
async def wait(self) -> None:
"""Wait until the computer is ready for the next action."""
pass
@abc.abstractmethod
async def move(self, x: int, y: int) -> None:
"""Move the mouse cursor to the given `(x, y)` screen coordinates."""
pass
@abc.abstractmethod
async def keypress(self, keys: list[str]) -> None:
"""Press the provided keys, such as `["ctrl", "c"]`."""
pass
@abc.abstractmethod
async def drag(self, path: list[tuple[int, int]]) -> None:
"""Click-and-drag the mouse along the given sequence of `(x, y)` waypoints."""
pass