orgo 0.0.29__tar.gz → 0.0.30__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orgo
3
- Version: 0.0.29
3
+ Version: 0.0.30
4
4
  Summary: Computers for AI agents
5
5
  Author: Orgo Team
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "orgo"
7
- version = "0.0.29"
7
+ version = "0.0.30"
8
8
  description = "Computers for AI agents"
9
9
  authors = [{name = "Orgo Team"}]
10
10
  license = {text = "MIT"}
@@ -0,0 +1,183 @@
1
+ """API client for Orgo service"""
2
+
3
+ import requests
4
+ from typing import Dict, Any, Optional, List
5
+ import logging
6
+
7
+ from orgo.utils.auth import get_api_key
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ class ApiClient:
12
+ def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None):
13
+ self.api_key = get_api_key(api_key)
14
+ self.base_url = base_url or "https://www.orgo.ai/api"
15
+ self.session = requests.Session()
16
+ self.session.headers.update({
17
+ "Authorization": f"Bearer {self.api_key}",
18
+ "Content-Type": "application/json",
19
+ "Accept": "application/json"
20
+ })
21
+
22
+ def _request(self, method: str, endpoint: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
23
+ url = f"{self.base_url}/{endpoint}"
24
+
25
+ try:
26
+ if method.upper() == "GET":
27
+ response = self.session.get(url, params=data)
28
+ else:
29
+ response = self.session.request(method, url, json=data)
30
+
31
+ response.raise_for_status()
32
+ return response.json()
33
+ except requests.exceptions.RequestException as e:
34
+ # Log the full error for debugging
35
+ logger.debug(f"API request failed: {method} {url}", exc_info=True)
36
+
37
+ if hasattr(e, 'response') and e.response is not None:
38
+ try:
39
+ error_data = e.response.json()
40
+ if 'error' in error_data:
41
+ raise Exception(error_data['error']) from None
42
+ except (ValueError, KeyError):
43
+ pass
44
+ raise Exception(f"Request failed with status {e.response.status_code}") from None
45
+
46
+ # Generic error message without exposing internal details
47
+ raise Exception("Failed to connect to Orgo service. Please check your connection and try again.") from None
48
+
49
+ # Project methods
50
+ def create_project(self, name: str) -> Dict[str, Any]:
51
+ """Create a new named project"""
52
+ return self._request("POST", "projects", {"name": name})
53
+
54
+ def get_project_by_name(self, name: str) -> Dict[str, Any]:
55
+ """Get project details by name"""
56
+ projects = self.list_projects()
57
+ for project in projects:
58
+ if project.get("name") == name:
59
+ return project
60
+ raise Exception(f"Project '{name}' not found") from None
61
+
62
+ def get_project(self, project_id: str) -> Dict[str, Any]:
63
+ """Get project details by ID"""
64
+ return self._request("GET", f"projects/{project_id}")
65
+
66
+ def list_projects(self) -> List[Dict[str, Any]]:
67
+ """List all projects"""
68
+ response = self._request("GET", "projects")
69
+ return response.get("projects", [])
70
+
71
+ def delete_project(self, project_id: str) -> Dict[str, Any]:
72
+ """Delete a project and all its computers"""
73
+ return self._request("DELETE", f"projects/{project_id}")
74
+
75
+ # Computer methods
76
+ def create_computer(self, project_id: str, computer_name: str,
77
+ os: str = "linux", ram: int = 2, cpu: int = 2,
78
+ gpu: str = "none") -> Dict[str, Any]:
79
+ """Create a new computer within a project"""
80
+ return self._request("POST", "computers", {
81
+ "project_id": project_id,
82
+ "name": computer_name,
83
+ "os": os,
84
+ "ram": ram,
85
+ "cpu": cpu,
86
+ "gpu": gpu
87
+ })
88
+
89
+ def list_computers(self, project_id: str) -> List[Dict[str, Any]]:
90
+ """List all computers in a project"""
91
+ project = self.get_project(project_id)
92
+ return project.get("desktops", [])
93
+
94
+ def get_computer(self, computer_id: str) -> Dict[str, Any]:
95
+ """Get computer details"""
96
+ return self._request("GET", f"computers/{computer_id}")
97
+
98
+ def delete_computer(self, computer_id: str) -> Dict[str, Any]:
99
+ """Delete a computer"""
100
+ return self._request("DELETE", f"computers/{computer_id}")
101
+
102
+ def restart_computer(self, computer_id: str) -> Dict[str, Any]:
103
+ """Restart a computer"""
104
+ return self._request("POST", f"computers/{computer_id}/restart")
105
+
106
+ # Computer control methods
107
+ def left_click(self, computer_id: str, x: int, y: int) -> Dict[str, Any]:
108
+ return self._request("POST", f"computers/{computer_id}/click", {
109
+ "button": "left", "x": x, "y": y
110
+ })
111
+
112
+ def right_click(self, computer_id: str, x: int, y: int) -> Dict[str, Any]:
113
+ return self._request("POST", f"computers/{computer_id}/click", {
114
+ "button": "right", "x": x, "y": y
115
+ })
116
+
117
+ def double_click(self, computer_id: str, x: int, y: int) -> Dict[str, Any]:
118
+ return self._request("POST", f"computers/{computer_id}/click", {
119
+ "button": "left", "x": x, "y": y, "double": True
120
+ })
121
+
122
+ def drag(self, computer_id: str, start_x: int, start_y: int,
123
+ end_x: int, end_y: int, button: str = "left",
124
+ duration: float = 0.5) -> Dict[str, Any]:
125
+ """Perform a drag operation from start to end coordinates"""
126
+ return self._request("POST", f"computers/{computer_id}/drag", {
127
+ "start_x": start_x,
128
+ "start_y": start_y,
129
+ "end_x": end_x,
130
+ "end_y": end_y,
131
+ "button": button,
132
+ "duration": duration
133
+ })
134
+
135
+ def scroll(self, computer_id: str, direction: str, amount: int = 3) -> Dict[str, Any]:
136
+ return self._request("POST", f"computers/{computer_id}/scroll", {
137
+ "direction": direction, "amount": amount
138
+ })
139
+
140
+ def type_text(self, computer_id: str, text: str) -> Dict[str, Any]:
141
+ return self._request("POST", f"computers/{computer_id}/type", {
142
+ "text": text
143
+ })
144
+
145
+ def key_press(self, computer_id: str, key: str) -> Dict[str, Any]:
146
+ return self._request("POST", f"computers/{computer_id}/key", {
147
+ "key": key
148
+ })
149
+
150
+ def get_screenshot(self, computer_id: str) -> Dict[str, Any]:
151
+ return self._request("GET", f"computers/{computer_id}/screenshot")
152
+
153
+ def execute_bash(self, computer_id: str, command: str) -> Dict[str, Any]:
154
+ return self._request("POST", f"computers/{computer_id}/bash", {
155
+ "command": command
156
+ })
157
+
158
+ def execute_python(self, computer_id: str, code: str, timeout: int = 10) -> Dict[str, Any]:
159
+ """Execute Python code on the computer"""
160
+ return self._request("POST", f"computers/{computer_id}/exec", {
161
+ "code": code,
162
+ "timeout": timeout
163
+ })
164
+
165
+ def wait(self, computer_id: str, duration: float) -> Dict[str, Any]:
166
+ return self._request("POST", f"computers/{computer_id}/wait", {
167
+ "duration": duration
168
+ })
169
+
170
+ # Streaming methods
171
+ def start_stream(self, computer_id: str, connection_name: str) -> Dict[str, Any]:
172
+ """Start streaming to a configured RTMP connection"""
173
+ return self._request("POST", f"computers/{computer_id}/stream/start", {
174
+ "connection_name": connection_name
175
+ })
176
+
177
+ def stop_stream(self, computer_id: str) -> Dict[str, Any]:
178
+ """Stop the active stream"""
179
+ return self._request("POST", f"computers/{computer_id}/stream/stop")
180
+
181
+ def get_stream_status(self, computer_id: str) -> Dict[str, Any]:
182
+ """Get current stream status"""
183
+ return self._request("GET", f"computers/{computer_id}/stream/status")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orgo
3
- Version: 0.0.29
3
+ Version: 0.0.30
4
4
  Summary: Computers for AI agents
5
5
  Author: Orgo Team
6
6
  License: MIT
@@ -1,333 +0,0 @@
1
- """Computer class for interacting with Orgo virtual environments"""
2
- import os as operating_system
3
- import base64
4
- import logging
5
- import uuid
6
- import io
7
- from typing import Dict, List, Any, Optional, Callable, Literal, Union
8
- from PIL import Image
9
- import requests
10
- from requests.exceptions import RequestException
11
-
12
- from .api.client import ApiClient
13
- from .prompt import get_provider
14
-
15
- logger = logging.getLogger(__name__)
16
-
17
- class Computer:
18
- def __init__(self,
19
- project: Optional[Union[str, 'Project']] = None,
20
- name: Optional[str] = None,
21
- computer_id: Optional[str] = None,
22
- api_key: Optional[str] = None,
23
- base_api_url: Optional[str] = None,
24
- ram: Optional[Literal[1, 2, 4, 8, 16, 32, 64]] = None,
25
- memory: Optional[Literal[1, 2, 4, 8, 16, 32, 64]] = None,
26
- cpu: Optional[Literal[1, 2, 4, 8, 16]] = None,
27
- os: Optional[Literal["linux", "windows"]] = None,
28
- gpu: Optional[Literal["none", "a10", "l40s", "a100-40gb", "a100-80gb"]] = None):
29
- """
30
- Initialize an Orgo virtual computer.
31
-
32
- Args:
33
- project: Project name (str) or Project instance. If not provided, creates a new project.
34
- name: Computer name within the project (optional, auto-generated if not provided)
35
- computer_id: Existing computer ID to connect to (optional)
36
- api_key: Orgo API key (defaults to ORGO_API_KEY env var)
37
- base_api_url: Custom API URL (optional)
38
- ram/memory: RAM in GB (1, 2, 4, 8, 16, 32, or 64) - only used when creating
39
- cpu: CPU cores (1, 2, 4, 8, or 16) - only used when creating
40
- os: Operating system ("linux" or "windows") - only used when creating
41
- gpu: GPU type - only used when creating
42
-
43
- Examples:
44
- # Create computer in new project
45
- computer = Computer(ram=4, cpu=2)
46
-
47
- # Create computer in existing project
48
- computer = Computer(project="manus", ram=4, cpu=2)
49
-
50
- # Connect to existing computer in project
51
- computer = Computer(project="manus")
52
- """
53
- self.api_key = api_key or operating_system.environ.get("ORGO_API_KEY")
54
- self.base_api_url = base_api_url
55
- self.api = ApiClient(self.api_key, self.base_api_url)
56
-
57
- # Handle memory parameter as an alias for ram
58
- if ram is None and memory is not None:
59
- ram = memory
60
-
61
- # Store configuration
62
- self.os = os or "linux"
63
- self.ram = ram or 2
64
- self.cpu = cpu or 2
65
- self.gpu = gpu or "none"
66
-
67
- if computer_id:
68
- # Connect to existing computer by ID
69
- self._connect_by_id(computer_id)
70
- elif project:
71
- # Work with specified project
72
- if isinstance(project, str):
73
- # Project name provided
74
- self.project_name = project
75
- self._initialize_with_project_name(project, name)
76
- else:
77
- # Project instance provided
78
- from .project import Project as ProjectClass
79
- if isinstance(project, ProjectClass):
80
- self.project_name = project.name
81
- self.project_id = project.id
82
- self._initialize_with_project_instance(project, name)
83
- else:
84
- raise ValueError("project must be a string (project name) or Project instance")
85
- else:
86
- # No project specified, create a new one
87
- self._create_new_project_and_computer(name)
88
-
89
- def _connect_by_id(self, computer_id: str):
90
- """Connect to existing computer by ID"""
91
- self.computer_id = computer_id
92
- self._info = self.api.get_computer(computer_id)
93
- self.project_id = self._info.get("project_id")
94
- self.name = self._info.get("name")
95
- # Get project name
96
- if self.project_id:
97
- project = self.api.get_project(self.project_id)
98
- self.project_name = project.get("name")
99
-
100
- def _initialize_with_project_name(self, project_name: str, computer_name: Optional[str]):
101
- """Initialize with a project name (create project if needed)"""
102
- try:
103
- # Try to get existing project
104
- project = self.api.get_project_by_name(project_name)
105
- self.project_id = project.get("id")
106
-
107
- # Check for existing computers
108
- computers = self.api.list_computers(self.project_id)
109
-
110
- if computer_name:
111
- # Look for specific computer
112
- existing = next((c for c in computers if c.get("name") == computer_name), None)
113
- if existing:
114
- self._connect_to_existing_computer(existing)
115
- else:
116
- # Create new computer with specified name
117
- self._create_computer(self.project_id, computer_name)
118
- elif computers:
119
- # No name specified, use first available computer
120
- self._connect_to_existing_computer(computers[0])
121
- else:
122
- # No computers exist, create new one
123
- self._create_computer(self.project_id, computer_name)
124
-
125
- except Exception:
126
- # Project doesn't exist, create it
127
- logger.info(f"Project {project_name} not found, creating new project")
128
- project = self.api.create_project(project_name)
129
- self.project_id = project.get("id")
130
- self._create_computer(self.project_id, computer_name)
131
-
132
- def _initialize_with_project_instance(self, project: 'Project', computer_name: Optional[str]):
133
- """Initialize with a Project instance"""
134
- computers = project.list_computers()
135
-
136
- if computer_name:
137
- # Look for specific computer
138
- existing = next((c for c in computers if c.get("name") == computer_name), None)
139
- if existing:
140
- self._connect_to_existing_computer(existing)
141
- else:
142
- # Create new computer with specified name
143
- self._create_computer(project.id, computer_name)
144
- elif computers:
145
- # No name specified, use first available computer
146
- self._connect_to_existing_computer(computers[0])
147
- else:
148
- # No computers exist, create new one
149
- self._create_computer(project.id, computer_name)
150
-
151
- def _create_new_project_and_computer(self, computer_name: Optional[str]):
152
- """Create a new project and computer"""
153
- # Generate a unique project name
154
- project_name = f"project-{uuid.uuid4().hex[:8]}"
155
-
156
- # Create the project
157
- project = self.api.create_project(project_name)
158
- self.project_id = project.get("id")
159
- self.project_name = project_name
160
-
161
- # Create a computer in the new project
162
- self._create_computer(self.project_id, computer_name)
163
-
164
- def _connect_to_existing_computer(self, computer_info: Dict[str, Any]):
165
- """Connect to an existing computer"""
166
- self.computer_id = computer_info.get("id")
167
- self.name = computer_info.get("name")
168
- self._info = computer_info
169
- logger.info(f"Connected to existing computer {self.name} (ID: {self.computer_id})")
170
-
171
- def _create_computer(self, project_id: str, computer_name: Optional[str]):
172
- """Create a new computer in the project"""
173
- # Generate name if not provided
174
- if not computer_name:
175
- computer_name = f"desktop-{uuid.uuid4().hex[:8]}"
176
-
177
- self.name = computer_name
178
-
179
- # Validate parameters
180
- if self.ram not in [1, 2, 4, 8, 16, 32, 64]:
181
- raise ValueError("ram must be one of: 1, 2, 4, 8, 16, 32, 64 GB")
182
- if self.cpu not in [1, 2, 4, 8, 16]:
183
- raise ValueError("cpu must be one of: 1, 2, 4, 8, 16 cores")
184
- if self.os not in ["linux", "windows"]:
185
- raise ValueError("os must be either 'linux' or 'windows'")
186
- if self.gpu not in ["none", "a10", "l40s", "a100-40gb", "a100-80gb"]:
187
- raise ValueError("gpu must be one of: 'none', 'a10', 'l40s', 'a100-40gb', 'a100-80gb'")
188
-
189
- computer = self.api.create_computer(
190
- project_id=project_id,
191
- computer_name=computer_name,
192
- os=self.os,
193
- ram=self.ram,
194
- cpu=self.cpu,
195
- gpu=self.gpu
196
- )
197
- self.computer_id = computer.get("id")
198
- self._info = computer
199
- logger.info(f"Created new computer {self.name} (ID: {self.computer_id})")
200
-
201
- def status(self) -> Dict[str, Any]:
202
- """Get current computer status"""
203
- return self.api.get_computer(self.computer_id)
204
-
205
- def restart(self) -> Dict[str, Any]:
206
- """Restart the computer"""
207
- return self.api.restart_computer(self.computer_id)
208
-
209
- def destroy(self) -> Dict[str, Any]:
210
- """Terminate and delete the computer instance"""
211
- return self.api.delete_computer(self.computer_id)
212
-
213
- # Navigation methods
214
- def left_click(self, x: int, y: int) -> Dict[str, Any]:
215
- """Perform left mouse click at specified coordinates"""
216
- return self.api.left_click(self.computer_id, x, y)
217
-
218
- def right_click(self, x: int, y: int) -> Dict[str, Any]:
219
- """Perform right mouse click at specified coordinates"""
220
- return self.api.right_click(self.computer_id, x, y)
221
-
222
- def double_click(self, x: int, y: int) -> Dict[str, Any]:
223
- """Perform double click at specified coordinates"""
224
- return self.api.double_click(self.computer_id, x, y)
225
-
226
- def drag(self, start_x: int, start_y: int, end_x: int, end_y: int,
227
- button: str = "left", duration: float = 0.5) -> Dict[str, Any]:
228
- """Perform a smooth drag operation from start to end coordinates"""
229
- return self.api.drag(self.computer_id, start_x, start_y, end_x, end_y, button, duration)
230
-
231
- def scroll(self, direction: str = "down", amount: int = 3) -> Dict[str, Any]:
232
- """Scroll in specified direction and amount"""
233
- return self.api.scroll(self.computer_id, direction, amount)
234
-
235
- # Input methods
236
- def type(self, text: str) -> Dict[str, Any]:
237
- """Type the specified text"""
238
- return self.api.type_text(self.computer_id, text)
239
-
240
- def key(self, key: str) -> Dict[str, Any]:
241
- """Press a key or key combination (e.g., "Enter", "ctrl+c")"""
242
- return self.api.key_press(self.computer_id, key)
243
-
244
- # View methods
245
- def screenshot(self) -> Image.Image:
246
- """Capture screenshot and return as PIL Image"""
247
- response = self.api.get_screenshot(self.computer_id)
248
- image_data = response.get("image", "")
249
-
250
- if image_data.startswith(('http://', 'https://')):
251
- img_response = requests.get(image_data)
252
- img_response.raise_for_status()
253
- return Image.open(io.BytesIO(img_response.content))
254
- else:
255
- img_data = base64.b64decode(image_data)
256
- return Image.open(io.BytesIO(img_data))
257
-
258
- def screenshot_base64(self) -> str:
259
- """Capture screenshot and return as base64 string"""
260
- response = self.api.get_screenshot(self.computer_id)
261
- image_data = response.get("image", "")
262
-
263
- if image_data.startswith(('http://', 'https://')):
264
- img_response = requests.get(image_data)
265
- img_response.raise_for_status()
266
- return base64.b64encode(img_response.content).decode('utf-8')
267
- else:
268
- return image_data
269
-
270
- # Execution methods
271
- def bash(self, command: str) -> str:
272
- """Execute a bash command and return output"""
273
- response = self.api.execute_bash(self.computer_id, command)
274
- return response.get("output", "")
275
-
276
- def exec(self, code: str, timeout: int = 10) -> Dict[str, Any]:
277
- """Execute Python code on the remote computer"""
278
- response = self.api.execute_python(self.computer_id, code, timeout)
279
- return response
280
-
281
- def wait(self, seconds: float) -> Dict[str, Any]:
282
- """Wait for specified number of seconds"""
283
- return self.api.wait(self.computer_id, seconds)
284
-
285
- # Streaming methods
286
- def start_stream(self, connection: str) -> Dict[str, Any]:
287
- """Start streaming the computer screen to an RTMP server"""
288
- return self.api.start_stream(self.computer_id, connection)
289
-
290
- def stop_stream(self) -> Dict[str, Any]:
291
- """Stop the active stream"""
292
- return self.api.stop_stream(self.computer_id)
293
-
294
- def stream_status(self) -> Dict[str, Any]:
295
- """Get the current streaming status"""
296
- return self.api.get_stream_status(self.computer_id)
297
-
298
- # AI control method
299
- def prompt(self,
300
- instruction: str,
301
- provider: str = "anthropic",
302
- model: str = "claude-3-7-sonnet-20250219",
303
- display_width: int = 1024,
304
- display_height: int = 768,
305
- callback: Optional[Callable[[str, Any], None]] = None,
306
- thinking_enabled: bool = False,
307
- thinking_budget: int = 1024,
308
- max_tokens: int = 4096,
309
- max_iterations: int = 20,
310
- max_saved_screenshots: int = 5,
311
- api_key: Optional[str] = None) -> List[Dict[str, Any]]:
312
- """Control the computer with natural language instructions using an AI assistant"""
313
- provider_instance = get_provider(provider)
314
-
315
- return provider_instance.execute(
316
- computer_id=self.computer_id,
317
- instruction=instruction,
318
- callback=callback,
319
- api_key=api_key,
320
- model=model,
321
- display_width=display_width,
322
- display_height=display_height,
323
- thinking_enabled=thinking_enabled,
324
- thinking_budget=thinking_budget,
325
- max_tokens=max_tokens,
326
- max_iterations=max_iterations,
327
- max_saved_screenshots=max_saved_screenshots,
328
- orgo_api_key=self.api_key,
329
- orgo_base_url=self.base_api_url
330
- )
331
-
332
- def __repr__(self):
333
- return f"Computer(name='{self.name}', project='{self.project_name}', id='{self.computer_id}')"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes