orgo 0.0.31__tar.gz → 0.0.34__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.31
3
+ Version: 0.0.34
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.31"
7
+ version = "0.0.34"
8
8
  description = "Computers for AI agents"
9
9
  authors = [{name = "Orgo Team"}]
10
10
  license = {text = "MIT"}
@@ -3,5 +3,6 @@
3
3
 
4
4
  from .project import Project
5
5
  from .computer import Computer
6
+ from .forge import Forge
6
7
 
7
- __all__ = ["Project", "Computer"]
8
+ __all__ = ["Project", "Computer", "Forge"]
@@ -28,6 +28,11 @@ class ApiClient:
28
28
  else:
29
29
  response = self.session.request(method, url, json=data)
30
30
 
31
+ # Handle 405 specifically for better debugging
32
+ if response.status_code == 405:
33
+ logger.error(f"Method Not Allowed: {method} {url}")
34
+ logger.error(f"Response: {response.text}")
35
+
31
36
  response.raise_for_status()
32
37
  return response.json()
33
38
  except requests.exceptions.RequestException as e:
@@ -75,16 +80,20 @@ class ApiClient:
75
80
  # Computer methods
76
81
  def create_computer(self, project_id: str, computer_name: str,
77
82
  os: str = "linux", ram: int = 2, cpu: int = 2,
78
- gpu: str = "none") -> Dict[str, Any]:
83
+ gpu: str = "none", image: Optional[str] = None) -> Dict[str, Any]:
79
84
  """Create a new computer within a project"""
80
- return self._request("POST", "computers", {
85
+ data = {
81
86
  "project_id": project_id,
82
87
  "name": computer_name,
83
88
  "os": os,
84
89
  "ram": ram,
85
90
  "cpu": cpu,
86
91
  "gpu": gpu
87
- })
92
+ }
93
+ if image:
94
+ data["image"] = image
95
+
96
+ return self._request("POST", "computers", data)
88
97
 
89
98
  def list_computers(self, project_id: str) -> List[Dict[str, Any]]:
90
99
  """List all computers in a project"""
@@ -180,4 +189,39 @@ class ApiClient:
180
189
 
181
190
  def get_stream_status(self, computer_id: str) -> Dict[str, Any]:
182
191
  """Get current stream status"""
183
- return self._request("GET", f"computers/{computer_id}/stream/status")
192
+ return self._request("GET", f"computers/{computer_id}/stream/status")
193
+
194
+ # Build methods
195
+ def create_build(self, org_id: str, project_id: str, name: Optional[str] = None) -> Dict[str, Any]:
196
+ """Register a new build"""
197
+ data = {
198
+ "orgId": org_id,
199
+ "projectId": project_id
200
+ }
201
+ if name:
202
+ data["name"] = name
203
+
204
+ return self._request("POST", "builds/create", data)
205
+
206
+ def get_latest_build(self, org_id: str, project_id: str, name: str) -> Dict[str, Any]:
207
+ """Get latest completed build by name"""
208
+ return self._request("GET", "builds/latest", {
209
+ "orgId": org_id,
210
+ "projectId": project_id,
211
+ "name": name
212
+ })
213
+
214
+ def update_build(self, build_id: str, status: str,
215
+ error_message: Optional[str] = None,
216
+ build_log: Optional[str] = None) -> Dict[str, Any]:
217
+ """Update build status"""
218
+ data = {
219
+ "buildId": build_id,
220
+ "status": status
221
+ }
222
+ if error_message:
223
+ data["errorMessage"] = error_message
224
+ if build_log:
225
+ data["buildLog"] = build_log
226
+
227
+ return self._request("POST", "builds/update", data)
@@ -25,7 +25,8 @@ class Computer:
25
25
  memory: Optional[Literal[1, 2, 4, 8, 16, 32, 64]] = None,
26
26
  cpu: Optional[Literal[1, 2, 4, 8, 16]] = None,
27
27
  os: Optional[Literal["linux", "windows"]] = None,
28
- gpu: Optional[Literal["none", "a10", "l40s", "a100-40gb", "a100-80gb"]] = None):
28
+ gpu: Optional[Literal["none", "a10", "l40s", "a100-40gb", "a100-80gb"]] = None,
29
+ image: Optional[Union[str, Any]] = None):
29
30
  """
30
31
  Initialize an Orgo virtual computer.
31
32
 
@@ -39,16 +40,21 @@ class Computer:
39
40
  cpu: CPU cores (1, 2, 4, 8, or 16) - only used when creating
40
41
  os: Operating system ("linux" or "windows") - only used when creating
41
42
  gpu: GPU type - only used when creating
43
+ image: Custom image reference (str) or Forge object - only used when creating
42
44
 
43
45
  Examples:
44
46
  # Create computer in new project
45
47
  computer = Computer(ram=4, cpu=2)
46
48
 
49
+ # Create computer with custom image
50
+ forge = Forge(org_id="myorg", project_id="myproj").base("ubuntu").run("echo hello")
51
+ computer = Computer(image=forge)
52
+
47
53
  # Create computer in existing project
48
54
  computer = Computer(project="manus", ram=4, cpu=2)
49
55
 
50
- # Connect to existing computer in project
51
- computer = Computer(project="manus")
56
+ # Connect to existing computer by ID
57
+ computer = Computer(computer_id="11c4fd46-e069-4c32-be65-f82d9f87b9b8")
52
58
  """
53
59
  self.api_key = api_key or operating_system.environ.get("ORGO_API_KEY")
54
60
  self.base_api_url = base_api_url
@@ -64,9 +70,20 @@ class Computer:
64
70
  self.cpu = cpu or 2
65
71
  self.gpu = gpu or "none"
66
72
 
73
+ # Handle image
74
+ self.image = image
75
+ if hasattr(self.image, 'build') and callable(self.image.build):
76
+ logger.info("Building image from Forge object...")
77
+ self.image = self.image.build()
78
+
67
79
  if computer_id:
68
- # Connect to existing computer by ID
69
- self._connect_by_id(computer_id)
80
+
81
+ # Just store the computer ID, no API call needed
82
+ self.computer_id = computer_id
83
+ self.name = name
84
+ self.project_id = None
85
+ self.project_name = None
86
+ logger.info(f"Connected to computer ID: {self.computer_id}")
70
87
  elif project:
71
88
  # Work with specified project
72
89
  if isinstance(project, str):
@@ -86,17 +103,6 @@ class Computer:
86
103
  # No project specified, create a new one
87
104
  self._create_new_project_and_computer(name)
88
105
 
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
106
  def _initialize_with_project_name(self, project_name: str, computer_name: Optional[str]):
101
107
  """Initialize with a project name (create project if needed)"""
102
108
  try:
@@ -165,7 +171,6 @@ class Computer:
165
171
  """Connect to an existing computer"""
166
172
  self.computer_id = computer_info.get("id")
167
173
  self.name = computer_info.get("name")
168
- self._info = computer_info
169
174
  logger.info(f"Connected to existing computer {self.name} (ID: {self.computer_id})")
170
175
 
171
176
  def _create_computer(self, project_id: str, computer_name: Optional[str]):
@@ -185,6 +190,28 @@ class Computer:
185
190
  raise ValueError("os must be either 'linux' or 'windows'")
186
191
  if self.gpu not in ["none", "a10", "l40s", "a100-40gb", "a100-80gb"]:
187
192
  raise ValueError("gpu must be one of: 'none', 'a10', 'l40s', 'a100-40gb', 'a100-80gb'")
193
+
194
+ # Resolve image name if needed
195
+ image_ref = self.image
196
+ if image_ref and isinstance(image_ref, str) and not image_ref.startswith("registry.fly.io"):
197
+ logger.info(f"Resolving image name '{image_ref}'...")
198
+ try:
199
+ # Try to get org_id from project info
200
+ project_info = self.api.get_project(project_id)
201
+ org_id = project_info.get("org_id", "orgo") # Default to 'orgo'
202
+
203
+ response = self.api.get_latest_build(org_id, project_id, image_ref)
204
+ if response and response.get("build"):
205
+ resolved_ref = response.get("build", {}).get("imageRef")
206
+ if resolved_ref:
207
+ logger.info(f"Resolved '{image_ref}' to '{resolved_ref}'")
208
+ image_ref = resolved_ref
209
+ else:
210
+ logger.warning(f"Build found for '{image_ref}' but no imageRef present.")
211
+ else:
212
+ logger.warning(f"Could not resolve image name '{self.image}'. Using as is.")
213
+ except Exception as e:
214
+ logger.warning(f"Failed to resolve image name: {e}")
188
215
 
189
216
  computer = self.api.create_computer(
190
217
  project_id=project_id,
@@ -192,10 +219,10 @@ class Computer:
192
219
  os=self.os,
193
220
  ram=self.ram,
194
221
  cpu=self.cpu,
195
- gpu=self.gpu
222
+ gpu=self.gpu,
223
+ image=image_ref
196
224
  )
197
225
  self.computer_id = computer.get("id")
198
- self._info = computer
199
226
  logger.info(f"Created new computer {self.name} (ID: {self.computer_id})")
200
227
 
201
228
  def status(self) -> Dict[str, Any]:
@@ -299,7 +326,7 @@ class Computer:
299
326
  def prompt(self,
300
327
  instruction: str,
301
328
  provider: str = "anthropic",
302
- model: str = "claude-3-7-sonnet-20250219",
329
+ model: str = "claude-sonnet-4-5-20250929",
303
330
  display_width: int = 1024,
304
331
  display_height: int = 768,
305
332
  callback: Optional[Callable[[str, Any], None]] = None,
@@ -330,4 +357,6 @@ class Computer:
330
357
  )
331
358
 
332
359
  def __repr__(self):
333
- return f"Computer(name='{self.name}', project='{self.project_name}', id='{self.computer_id}')"
360
+ project_str = f", project='{self.project_name}'" if hasattr(self, 'project_name') and self.project_name else ""
361
+ name_str = f"name='{self.name}'" if hasattr(self, 'name') and self.name else f"id='{self.computer_id}'"
362
+ return f"Computer({name_str}{project_str})"
@@ -0,0 +1,176 @@
1
+ import os
2
+ import subprocess
3
+ import logging
4
+ from typing import Optional, List, Union
5
+ import uuid
6
+
7
+ from .api.client import ApiClient
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ class Forge:
12
+ def __init__(self,
13
+ org_id: str,
14
+ project_id: str,
15
+ name: Optional[str] = None,
16
+ api_key: Optional[str] = None,
17
+ base_api_url: Optional[str] = None):
18
+ """
19
+ Initialize Orgo Forge for building images.
20
+
21
+ Args:
22
+ org_id: Organization ID
23
+ project_id: Project ID
24
+ name: Optional friendly name for the image (not used for registry tag currently, but for reference)
25
+ api_key: Orgo API key
26
+ base_api_url: Custom API URL
27
+ """
28
+ self.org_id = org_id
29
+ self.project_id = project_id
30
+ self.name = name
31
+ self.api_key = api_key or os.environ.get("ORGO_API_KEY")
32
+ self.base_api_url = base_api_url
33
+ self.api = ApiClient(self.api_key, self.base_api_url)
34
+
35
+ # Enforce base image
36
+ self.steps: List[str] = ["FROM registry.fly.io/orgo-image-repo:latest"]
37
+
38
+ def base(self, image: str) -> 'Forge':
39
+ """
40
+ DEPRECATED: Base image is now enforced to ensure CUA functionality.
41
+ This method will log a warning and ignore the provided image.
42
+ """
43
+ logger.warning("Forge.base() is deprecated. The base image is enforced to 'registry.fly.io/orgo-image-repo:latest'. Ignoring provided image.")
44
+ return self
45
+
46
+ def run(self, command: str) -> 'Forge':
47
+ """Run a command (RUN instruction)"""
48
+ self.steps.append(f"RUN {command}")
49
+ return self
50
+
51
+ def copy(self, src: str, dest: str) -> 'Forge':
52
+ """Copy files (COPY instruction)"""
53
+ self.steps.append(f"COPY {src} {dest}")
54
+ return self
55
+
56
+ def git_clone(self, url: str, dest: str) -> 'Forge':
57
+ """Clone a git repository"""
58
+ # Ensure git is installed or use a base image with git
59
+ self.steps.append(f"RUN git clone {url} {dest}")
60
+ return self
61
+
62
+ def env(self, key: str, value: str) -> 'Forge':
63
+ """Set environment variable (ENV instruction)"""
64
+ self.steps.append(f"ENV {key}={value}")
65
+ return self
66
+
67
+ def workdir(self, path: str) -> 'Forge':
68
+ """Set working directory (WORKDIR instruction)"""
69
+ self.steps.append(f"WORKDIR {path}")
70
+ return self
71
+
72
+ def build(self, context_path: str = ".", push: bool = True) -> str:
73
+ """
74
+ Execute the build.
75
+
76
+ 1. Registers build with Orgo API to get unique tag.
77
+ 2. Generates Dockerfile.
78
+ 3. Runs docker build (requires docker CLI installed).
79
+ 4. Pushes to registry.
80
+ 5. Updates build status.
81
+
82
+ Returns:
83
+ str: The full image reference (e.g. registry.fly.io/app:tag)
84
+ """
85
+ if not self.steps:
86
+ raise ValueError("No build steps defined. Use .base() to start.")
87
+
88
+ # 1. Register build
89
+ logger.info("Registering build with Orgo API...")
90
+ try:
91
+ build_info = self.api.create_build(self.org_id, self.project_id, self.name)
92
+ build_data = build_info.get('build', {})
93
+
94
+ build_id = build_data.get('id')
95
+ tag = build_data.get('tag')
96
+ image_ref = build_data.get('imageRef')
97
+ # buildkit_url = build_data.get('buildkitUrl') # Not used for local docker build yet
98
+
99
+ if not build_id or not image_ref:
100
+ raise ValueError("Failed to get build ID or image ref from API")
101
+
102
+ logger.info(f"Build registered. ID: {build_id}, Tag: {tag}")
103
+ logger.info(f"Target Image: {image_ref}")
104
+
105
+ except Exception as e:
106
+ logger.error(f"Failed to register build: {e}")
107
+ raise e
108
+
109
+ # 2. Generate Dockerfile
110
+ dockerfile_path = f"Dockerfile.{tag}"
111
+ try:
112
+ with open(dockerfile_path, "w") as f:
113
+ f.write("\n".join(self.steps))
114
+
115
+ # 3. Execute Build
116
+ logger.info("Starting build...")
117
+ self.api.update_build(build_id, "building")
118
+
119
+ # Use remote builder
120
+ builder_name = "orgo-remote"
121
+ remote_url = "tcp://orgoforge.fly.dev:1234"
122
+
123
+ # Check if builder exists
124
+ try:
125
+ subprocess.run(["docker", "buildx", "inspect", builder_name], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
126
+ except subprocess.CalledProcessError:
127
+ logger.info(f"Creating remote builder '{builder_name}' pointing to {remote_url}...")
128
+ subprocess.run(["docker", "buildx", "create", "--name", builder_name, "--driver", "remote", remote_url, "--use"], check=True)
129
+ subprocess.run(["docker", "buildx", "inspect", "--bootstrap"], check=True)
130
+
131
+ cmd = ["docker", "buildx", "build", "--builder", builder_name, "-t", image_ref, "-f", dockerfile_path, context_path]
132
+ if push:
133
+ cmd.append("--push")
134
+
135
+ # Run build
136
+ process = subprocess.Popen(
137
+ cmd,
138
+ stdout=subprocess.PIPE,
139
+ stderr=subprocess.STDOUT,
140
+ text=True,
141
+ bufsize=1,
142
+ universal_newlines=True
143
+ )
144
+
145
+ logs = []
146
+ while True:
147
+ line = process.stdout.readline()
148
+ if not line and process.poll() is not None:
149
+ break
150
+ if line:
151
+ print(line, end="") # Stream to console
152
+ logs.append(line)
153
+
154
+ if process.returncode != 0:
155
+ raise Exception(f"Docker build failed with exit code {process.returncode}")
156
+
157
+ # 5. Report Success
158
+ full_log = "".join(logs)
159
+ self.api.update_build(build_id, "completed", build_log=full_log)
160
+ logger.info("Build completed successfully!")
161
+
162
+ return image_ref
163
+
164
+ except Exception as e:
165
+ logger.error(f"Build failed: {e}")
166
+ full_log = "".join(logs) if 'logs' in locals() else str(e)
167
+ try:
168
+ self.api.update_build(build_id, "failed", error_message=str(e), build_log=full_log)
169
+ except:
170
+ pass # Ignore error reporting failure
171
+ raise e
172
+
173
+ finally:
174
+ if os.path.exists(dockerfile_path):
175
+ os.remove(dockerfile_path)
176
+
@@ -66,7 +66,7 @@ class Project:
66
66
 
67
67
  def list_computers(self) -> List[Dict[str, Any]]:
68
68
  """List all computers in this project"""
69
- return self.api.list_computers(self.name)
69
+ return self.api.list_computers(self.id)
70
70
 
71
71
  def get_computer(self, computer_name: str = None) -> Optional[Dict[str, Any]]:
72
72
  """Get a specific computer in this project by name, or the first one if no name specified"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orgo
3
- Version: 0.0.31
3
+ Version: 0.0.34
4
4
  Summary: Computers for AI agents
5
5
  Author: Orgo Team
6
6
  License: MIT
@@ -2,6 +2,7 @@ README.md
2
2
  pyproject.toml
3
3
  src/orgo/__init__.py
4
4
  src/orgo/computer.py
5
+ src/orgo/forge.py
5
6
  src/orgo/project.py
6
7
  src/orgo/prompt.py
7
8
  src/orgo.egg-info/PKG-INFO
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes