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