blaxel 0.2.1rc71__py3-none-any.whl → 0.2.1rc73__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.
@@ -10,6 +10,21 @@ from .client.models.process_request import ProcessRequest
10
10
  from .types import SandboxConfiguration
11
11
 
12
12
 
13
+ class ProcessResponseWithLogs(ProcessResponse):
14
+ """Extended ProcessResponse that adds a logs property."""
15
+
16
+ logs: Optional[str] = None
17
+
18
+ @classmethod
19
+ def from_process_response(cls, process_response: ProcessResponse, logs: Optional[str] = None):
20
+ """Create ProcessResponseWithLogs from an existing ProcessResponse."""
21
+ # Create a new instance from the dict representation
22
+ instance = cls.from_dict(process_response.to_dict())
23
+ # Add the logs
24
+ instance.logs = logs
25
+ return instance
26
+
27
+
13
28
  class SandboxProcess(SandboxAction):
14
29
  def __init__(self, sandbox_config: SandboxConfiguration):
15
30
  super().__init__(sandbox_config)
@@ -75,16 +90,56 @@ class SandboxProcess(SandboxAction):
75
90
 
76
91
  return {"close": close}
77
92
 
78
- async def exec(self, process: Union[ProcessRequest, Dict[str, Any]]) -> ProcessResponse:
93
+ async def exec(
94
+ self,
95
+ process: Union[ProcessRequest, Dict[str, Any]],
96
+ on_log: Optional[Callable[[str], None]] = None,
97
+ ) -> ProcessResponseWithLogs:
79
98
  if isinstance(process, dict):
80
99
  process = ProcessRequest.from_dict(process)
81
100
 
82
101
  async with self.get_client() as client_instance:
83
102
  response = await client_instance.post("/process", json=process.to_dict())
84
- self.handle_response_error(
85
- response, response.json() if response.content else None, None
86
- )
87
- return ProcessResponse.from_dict(response.json())
103
+
104
+ # Parse JSON response only once, with better error handling
105
+ response_data = None
106
+ if response.content:
107
+ try:
108
+ response_data = response.json()
109
+ except Exception:
110
+ # If JSON parsing fails, check the response first
111
+ self.handle_response_error(response, None, None)
112
+ raise
113
+
114
+ self.handle_response_error(response, response_data, None)
115
+ result = ProcessResponse.from_dict(response_data)
116
+
117
+ # Setup log streaming if on_log is provided
118
+ stream_control = None
119
+ if on_log is not None:
120
+ stream_control = self.stream_logs(result.pid, {"on_log": on_log})
121
+
122
+ # Wait for completion if requested
123
+ logs = None
124
+ if process.wait_for_completion:
125
+ try:
126
+ # Wait for process to complete
127
+ result = await self.wait(result.pid)
128
+
129
+ # Get the logs
130
+ logs = await self.logs(result.pid, "all")
131
+ except Exception as e:
132
+ # If waiting fails, still try to return what we have
133
+ if stream_control:
134
+ stream_control["close"]()
135
+ raise e
136
+
137
+ # Close stream if it was opened and we're done
138
+ if stream_control and process.wait_for_completion:
139
+ stream_control["close"]()
140
+
141
+ # Return wrapped response with logs
142
+ return ProcessResponseWithLogs.from_process_response(result, logs)
88
143
 
89
144
  async def wait(
90
145
  self, identifier: str, max_wait: int = 60000, interval: int = 1000
@@ -82,6 +82,8 @@ class SandboxInstance:
82
82
  if not sandbox.spec.runtime:
83
83
  sandbox.spec.runtime = Runtime(image="blaxel/prod-base:latest")
84
84
 
85
+ sandbox.spec.runtime.image = sandbox.spec.runtime.image or "blaxel/prod-base:latest"
86
+ sandbox.spec.runtime.memory = sandbox.spec.runtime.memory or 4096
85
87
  sandbox.spec.runtime.generation = sandbox.spec.runtime.generation or "mk3"
86
88
 
87
89
  response = await create_sandbox(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blaxel
3
- Version: 0.2.1rc71
3
+ Version: 0.2.1rc73
4
4
  Summary: Blaxel - AI development platform SDK
5
5
  Project-URL: Homepage, https://blaxel.ai
6
6
  Project-URL: Documentation, https://docs.blaxel.ai
@@ -309,8 +309,8 @@ blaxel/core/sandbox/action.py,sha256=9Zjkco7YkLzBThD3N2Hr5SpeEiqU_-Ktk8HlKpkpiAg
309
309
  blaxel/core/sandbox/filesystem.py,sha256=dyIvDdlPZO0ijD6mXXX8Yl0t75VijQ6_uMz_9rJd-_4,11317
310
310
  blaxel/core/sandbox/network.py,sha256=P5jLd4AAg1zgyIK4qGWvZaDZ5BzIcxRx2ffz_JLsLMI,357
311
311
  blaxel/core/sandbox/preview.py,sha256=M6FulOxPghUBpb5fLxu1Rd3ekLeCbZ_dgt4s1X2Cneo,5354
312
- blaxel/core/sandbox/process.py,sha256=FahDx-FOqXPV3ajVI6aKdXqx4Oi4fK3egojHjTGy8ro,6705
313
- blaxel/core/sandbox/sandbox.py,sha256=BRMl74XTY5JQFcwZdEJoCgqcN3tTdRMD4gL7J-1Go1Q,5635
312
+ blaxel/core/sandbox/process.py,sha256=jgOPL5yLzhd98CLO7nBUABIAPFK5S5z34h6L_TyXsuU,8753
313
+ blaxel/core/sandbox/sandbox.py,sha256=tsRGvkb2dnGM5pmOiIxWvOmT42P9BDXWtW3h6_CIffI,5802
314
314
  blaxel/core/sandbox/session.py,sha256=4SH1tyXcQ9UqJx4lMwxAlp7x9Te_anDrdSEG6AlNkvU,4496
315
315
  blaxel/core/sandbox/types.py,sha256=gmNAt8x7PrJZHpw2_2aWWDE5uG6H-uEgdIKTYIw4G0g,2981
316
316
  blaxel/core/sandbox/client/__init__.py,sha256=N26bD5o1jsTb48oExow6Rgivd8ylaU9jaWZfZsVilP8,128
@@ -402,7 +402,7 @@ blaxel/telemetry/instrumentation/map.py,sha256=PCzZJj39yiYVYJrxLBNP-NW-tjjYyTijw
402
402
  blaxel/telemetry/instrumentation/utils.py,sha256=KInMYZH-mu9_wvetmf0EmgrfN3Sw8IWk2Y95v2u90_U,1901
403
403
  blaxel/telemetry/log/log.py,sha256=RvQByRjZMoP_dRaAZu8oK6DTegsHs-xV4W-UIqis6CA,2461
404
404
  blaxel/telemetry/log/logger.py,sha256=NPAS3g82ryROjvc_DEZaTIfrcehoLEZoP-JkLxADxc0,4113
405
- blaxel-0.2.1rc71.dist-info/METADATA,sha256=v0CXAwoZmLommJuFSHXUTdXHRMakSGnzuwrjvYZcKV8,9879
406
- blaxel-0.2.1rc71.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
407
- blaxel-0.2.1rc71.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
408
- blaxel-0.2.1rc71.dist-info/RECORD,,
405
+ blaxel-0.2.1rc73.dist-info/METADATA,sha256=7M9mgqu97Tyk403KOchTBU9BzUlFHr8VXZ6JkuC0riM,9879
406
+ blaxel-0.2.1rc73.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
407
+ blaxel-0.2.1rc73.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
408
+ blaxel-0.2.1rc73.dist-info/RECORD,,