fleet-python 0.2.46__tar.gz → 0.2.47__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.

Potentially problematic release.


This version of fleet-python might be problematic. Click here for more details.

Files changed (81) hide show
  1. {fleet_python-0.2.46 → fleet_python-0.2.47}/PKG-INFO +1 -1
  2. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/models.py +6 -0
  3. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/tasks.py +68 -6
  4. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/verifiers/verifier.py +78 -66
  5. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/models.py +6 -0
  6. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/tasks.py +55 -1
  7. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/verifier.py +78 -66
  8. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet_python.egg-info/PKG-INFO +1 -1
  9. {fleet_python-0.2.46 → fleet_python-0.2.47}/pyproject.toml +1 -1
  10. {fleet_python-0.2.46 → fleet_python-0.2.47}/LICENSE +0 -0
  11. {fleet_python-0.2.46 → fleet_python-0.2.47}/README.md +0 -0
  12. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/diff_example.py +0 -0
  13. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/dsl_example.py +0 -0
  14. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example.py +0 -0
  15. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/exampleResume.py +0 -0
  16. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_account.py +0 -0
  17. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_action_log.py +0 -0
  18. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_client.py +0 -0
  19. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_mcp_anthropic.py +0 -0
  20. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_mcp_openai.py +0 -0
  21. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_sync.py +0 -0
  22. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_task.py +0 -0
  23. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_tasks.py +0 -0
  24. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/example_verifier.py +0 -0
  25. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/gemini_example.py +0 -0
  26. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/json_tasks_example.py +0 -0
  27. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/nova_act_example.py +0 -0
  28. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/openai_example.py +0 -0
  29. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/openai_simple_example.py +0 -0
  30. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/query_builder_example.py +0 -0
  31. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/quickstart.py +0 -0
  32. {fleet_python-0.2.46 → fleet_python-0.2.47}/examples/test_cdp_logging.py +0 -0
  33. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/__init__.py +0 -0
  34. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/__init__.py +0 -0
  35. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/base.py +0 -0
  36. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/client.py +0 -0
  37. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/env/__init__.py +0 -0
  38. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/env/client.py +0 -0
  39. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/exceptions.py +0 -0
  40. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/global_client.py +0 -0
  41. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/instance/__init__.py +0 -0
  42. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/instance/base.py +0 -0
  43. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/instance/client.py +0 -0
  44. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/resources/__init__.py +0 -0
  45. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/resources/base.py +0 -0
  46. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/resources/browser.py +0 -0
  47. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/resources/mcp.py +0 -0
  48. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/resources/sqlite.py +0 -0
  49. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/verifiers/__init__.py +0 -0
  50. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/_async/verifiers/bundler.py +0 -0
  51. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/base.py +0 -0
  52. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/client.py +0 -0
  53. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/config.py +0 -0
  54. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/env/__init__.py +0 -0
  55. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/env/client.py +0 -0
  56. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/exceptions.py +0 -0
  57. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/global_client.py +0 -0
  58. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/instance/__init__.py +0 -0
  59. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/instance/base.py +0 -0
  60. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/instance/client.py +0 -0
  61. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/instance/models.py +0 -0
  62. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/resources/__init__.py +0 -0
  63. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/resources/base.py +0 -0
  64. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/resources/browser.py +0 -0
  65. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/resources/mcp.py +0 -0
  66. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/resources/sqlite.py +0 -0
  67. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/types.py +0 -0
  68. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/__init__.py +0 -0
  69. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/bundler.py +0 -0
  70. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/code.py +0 -0
  71. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/db.py +0 -0
  72. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/decorator.py +0 -0
  73. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/parse.py +0 -0
  74. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet/verifiers/sql_differ.py +0 -0
  75. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet_python.egg-info/SOURCES.txt +0 -0
  76. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet_python.egg-info/dependency_links.txt +0 -0
  77. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet_python.egg-info/requires.txt +0 -0
  78. {fleet_python-0.2.46 → fleet_python-0.2.47}/fleet_python.egg-info/top_level.txt +0 -0
  79. {fleet_python-0.2.46 → fleet_python-0.2.47}/scripts/fix_sync_imports.py +0 -0
  80. {fleet_python-0.2.46 → fleet_python-0.2.47}/scripts/unasync.py +0 -0
  81. {fleet_python-0.2.46 → fleet_python-0.2.47}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fleet-python
3
- Version: 0.2.46
3
+ Version: 0.2.47
4
4
  Summary: Python SDK for Fleet environments
5
5
  Author-email: Fleet AI <nic@fleet.so>
6
6
  License: Apache-2.0
@@ -273,6 +273,12 @@ class VerifiersExecuteResponse(BaseModel):
273
273
  result: Optional[Any] = Field(
274
274
  None, description="The return value of the function", title="Result"
275
275
  )
276
+ verifier_id: Optional[str] = Field(
277
+ None, description="ID of the verifier", title="Verifier Id"
278
+ )
279
+ execution_id: Optional[str] = Field(
280
+ None, description="ID of the execution record", title="Execution Id"
281
+ )
276
282
  error: Optional[Dict[str, Any]] = Field(
277
283
  None, description="Error details if verification failed", title="Error"
278
284
  )
@@ -3,13 +3,16 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from datetime import datetime
6
- from typing import Any, Dict, Optional, List
6
+ from typing import Any, Dict, Optional, List, TYPE_CHECKING
7
7
 
8
8
  from pydantic import BaseModel, Field, validator
9
9
 
10
10
  # Import the shared VerifierFunction type that works for both async and sync
11
11
  from fleet.types import VerifierFunction
12
12
 
13
+ if TYPE_CHECKING:
14
+ from fleet._async.models import VerifiersExecuteResponse
15
+
13
16
 
14
17
  class Task(BaseModel):
15
18
  """A task model representing a single task in the Fleet system."""
@@ -24,9 +27,9 @@ class Task(BaseModel):
24
27
  version: Optional[str] = Field(None, description="Task version")
25
28
  verifier_func: Optional[str] = Field(None, description="Verifier function code")
26
29
  verifier: Optional[Any] = Field(
27
- None,
30
+ None,
28
31
  description="Verifier function with decorator (async or sync)",
29
- exclude=True # Exclude from JSON serialization
32
+ exclude=True, # Exclude from JSON serialization
30
33
  )
31
34
  verifier_id: Optional[str] = Field(None, description="Verifier identifier")
32
35
  verifier_sha: Optional[str] = Field(None, description="Verifier SHA256 hash")
@@ -68,7 +71,7 @@ class Task(BaseModel):
68
71
  # If verifier doesn't exist but verifier_func does, rebuild it
69
72
  if not self.verifier and self.verifier_func:
70
73
  self._rebuild_verifier()
71
-
74
+
72
75
  if self.verifier:
73
76
  import asyncio
74
77
  import inspect
@@ -102,7 +105,7 @@ class Task(BaseModel):
102
105
  # If verifier doesn't exist but verifier_func does, rebuild it
103
106
  if not self.verifier and self.verifier_func:
104
107
  self._rebuild_verifier()
105
-
108
+
106
109
  if self.verifier:
107
110
  result = self.verifier.remote(*args, **kwargs)
108
111
  # If it's a coroutine, await it
@@ -115,6 +118,65 @@ class Task(BaseModel):
115
118
  else:
116
119
  raise ValueError("No verifier function found for this task")
117
120
 
121
+ async def verify_detailed_async(
122
+ self, *args, **kwargs
123
+ ) -> "VerifiersExecuteResponse":
124
+ """Verify the task and return the full execute response model.
125
+
126
+ For async environments, awaits the async verifier.
127
+ Works with both sync and async verifiers in async contexts.
128
+ """
129
+ # If verifier doesn't exist but verifier_func does, rebuild it
130
+ if not self.verifier and self.verifier_func:
131
+ self._rebuild_verifier()
132
+
133
+ if self.verifier:
134
+ result = self.verifier.remote_with_response(*args, **kwargs)
135
+ # If it's a coroutine, await it
136
+ import inspect
137
+
138
+ if inspect.iscoroutine(result):
139
+ return await result
140
+ else:
141
+ return result
142
+ else:
143
+ raise ValueError("No verifier function found for this task")
144
+
145
+ def verify_detailed(self, env, *args, **kwargs) -> "VerifiersExecuteResponse":
146
+ """Verify the task and return the full execute response model (sync version).
147
+
148
+ For sync environments, calls the sync verifier directly.
149
+ For async verifiers, automatically runs them with asyncio.run().
150
+ """
151
+ # If verifier doesn't exist but verifier_func does, rebuild it
152
+ if not self.verifier and self.verifier_func:
153
+ self._rebuild_verifier()
154
+
155
+ if self.verifier:
156
+ import asyncio
157
+ import inspect
158
+
159
+ # Check if verifier has remote_with_response method (for decorated verifiers)
160
+ result = self.verifier.remote_with_response(env, *args, **kwargs)
161
+
162
+ # If the result is a coroutine, we need to run it
163
+ if inspect.iscoroutine(result):
164
+ # Check if we're already in an event loop
165
+ try:
166
+ asyncio.get_running_loop()
167
+ # We're in an async context, can't use asyncio.run()
168
+ raise RuntimeError(
169
+ "Cannot run async verifier in sync mode while event loop is running. "
170
+ "Use await task.verify_detailed_async() instead."
171
+ )
172
+ except RuntimeError:
173
+ # No event loop running, safe to use asyncio.run()
174
+ return asyncio.run(result)
175
+ else:
176
+ return result
177
+ else:
178
+ raise ValueError("No verifier function found for this task")
179
+
118
180
  def _rebuild_verifier(self):
119
181
  """Rebuild the verifier from verifier_func string if it exists."""
120
182
  if self.verifier_func:
@@ -127,7 +189,7 @@ class Task(BaseModel):
127
189
  sha256=self.verifier_sha or "",
128
190
  )
129
191
  self.verifier = verifier
130
-
192
+
131
193
  async def make_env(self, region: Optional[str] = None):
132
194
  """Create an environment instance for this task's environment.
133
195
 
@@ -16,6 +16,7 @@ from typing import Any, Callable, Dict, Optional, List, TypeVar, Tuple
16
16
 
17
17
  from .bundler import FunctionBundler
18
18
  from ..client import AsyncEnv
19
+ from ...models import VerifiersExecuteResponse
19
20
 
20
21
  logger = logging.getLogger(__name__)
21
22
 
@@ -152,72 +153,15 @@ class AsyncVerifierFunction:
152
153
 
153
154
  async def remote(self, env: AsyncEnv, *args, **kwargs) -> float:
154
155
  """Remote execution of the verifier function with SHA-based bundle caching."""
155
- # Async verifiers are now supported by the backend
156
- # if self._is_async:
157
- # raise NotImplementedError(
158
- # f"Async verifier '{self.key}' cannot be executed remotely. "
159
- # "The remote execution environment only supports synchronous functions. "
160
- # "Please provide a synchronous version of your verifier."
161
- # )
156
+ response = await self.remote_with_response(env, *args, **kwargs)
162
157
 
163
- args_array = list(args)
164
- args_array.append({"env": env.instance_id})
165
- args = tuple(args_array)
166
-
167
- try:
168
- # Check if bundle needs to be uploaded
169
- bundle_sha, needs_upload = await self._check_bundle_status(env)
170
-
171
- if needs_upload:
172
- # Need to upload bundle to S3
173
- logger.info(f"Uploading bundle {bundle_sha[:8]}... for {self.key}")
174
- bundle_data, _ = self._get_or_create_bundle()
175
-
176
- response = await env.execute_verifier_remote(
177
- bundle_data=bundle_data,
178
- bundle_sha=bundle_sha,
179
- key=self.key,
180
- function_name=self.func.__name__,
181
- args=args,
182
- args_array=args_array,
183
- kwargs=kwargs,
184
- needs_upload=True,
185
- )
186
-
187
- logger.debug(f"Bundle {bundle_sha[:8]}... uploaded successfully")
188
-
189
- else:
190
- # Bundle already available - execute without upload
191
- logger.info(
192
- f"Executing cached bundle {bundle_sha[:8]}... for {self.key}"
193
- )
194
- bundle_data, _ = self._get_or_create_bundle()
195
-
196
- response = await env.execute_verifier_remote(
197
- bundle_data=bundle_data or b"", # Empty if using server-side bundle
198
- bundle_sha=bundle_sha,
199
- key=self.key,
200
- function_name=self.func.__name__,
201
- args=args,
202
- args_array=args_array,
203
- kwargs=kwargs,
204
- needs_upload=False, # Don't upload, just execute
205
- )
206
-
207
- # Handle response
208
- if response.stdout:
209
- print(response.stdout)
210
- if response.success:
211
- return self._process_result(response.result)
212
- else:
213
- self._raise_remote_error(response.error)
214
-
215
- except Exception as e:
216
- logger.error(f"Remote execution failed for {self.key}: {e}")
217
- # If it's an HTTP error, try to get more details
218
- if hasattr(e, "response") and hasattr(e.response, "text"):
219
- logger.error(f"Server response: {e.response.text}")
220
- raise
158
+ # Handle response
159
+ if response.stdout:
160
+ print(response.stdout)
161
+ if response.success:
162
+ return self._process_result(response.result)
163
+ else:
164
+ self._raise_remote_error(response.error)
221
165
 
222
166
  def _process_result(self, result: Any) -> float:
223
167
  """Process remote execution result, handling different return types."""
@@ -257,7 +201,7 @@ Remote traceback:
257
201
  try:
258
202
  exception_class = getattr(__builtins__, error_type, RuntimeError)
259
203
  raise exception_class(full_message)
260
- except:
204
+ except Exception:
261
205
  raise RuntimeError(full_message)
262
206
 
263
207
  def _get_env_id(self, env: AsyncEnv) -> str:
@@ -280,6 +224,74 @@ Remote traceback:
280
224
  or "not found" in error_msg
281
225
  )
282
226
 
227
+ async def remote_with_response(
228
+ self, env: "AsyncEnv", *args, **kwargs
229
+ ) -> "VerifiersExecuteResponse":
230
+ """Remote execution of the verifier function that returns the full response model."""
231
+ args_array = list(args)
232
+ args_array.append({"env": env.instance_id})
233
+ args = tuple(args_array)
234
+
235
+ try:
236
+ # Check if bundle needs to be uploaded
237
+ bundle_sha, needs_upload = await self._check_bundle_status(env)
238
+
239
+ if needs_upload:
240
+ # Need to upload bundle to S3
241
+ logger.info(f"Uploading bundle {bundle_sha[:8]}... for {self.key}")
242
+ bundle_data, _ = self._get_or_create_bundle()
243
+
244
+ response = await env.execute_verifier_remote(
245
+ bundle_data=bundle_data,
246
+ bundle_sha=bundle_sha,
247
+ key=self.key,
248
+ function_name=self.func.__name__,
249
+ args=args,
250
+ args_array=args_array,
251
+ kwargs=kwargs,
252
+ needs_upload=True,
253
+ )
254
+
255
+ logger.debug(f"Bundle {bundle_sha[:8]}... uploaded successfully")
256
+
257
+ else:
258
+ # Bundle already available - execute without upload
259
+ logger.info(f"Bundle {bundle_sha[:8]}... already cached for {self.key}")
260
+ response = await env.execute_verifier_remote(
261
+ bundle_data=b"", # Empty bundle since it's cached
262
+ bundle_sha=bundle_sha,
263
+ key=self.key,
264
+ function_name=self.func.__name__,
265
+ args=args,
266
+ args_array=args_array,
267
+ kwargs=kwargs,
268
+ needs_upload=False,
269
+ )
270
+
271
+ return response
272
+
273
+ except Exception as e:
274
+ # Check if error indicates bundle not found and retry with upload
275
+ if self._is_bundle_not_found_error(e) and not needs_upload:
276
+ logger.info(
277
+ f"Bundle {bundle_sha[:8]}... not found on server, uploading..."
278
+ )
279
+ bundle_data, _ = self._get_or_create_bundle()
280
+ response = await env.execute_verifier_remote(
281
+ bundle_data=bundle_data,
282
+ bundle_sha=bundle_sha,
283
+ key=self.key,
284
+ function_name=self.func.__name__,
285
+ args=args,
286
+ args_array=args_array,
287
+ kwargs=kwargs,
288
+ needs_upload=True,
289
+ )
290
+ return response
291
+ else:
292
+ logger.error(f"Error in remote execution of {self.key}: {e}")
293
+ raise
294
+
283
295
 
284
296
  def verifier(
285
297
  key: Optional[str] = None,
@@ -275,6 +275,12 @@ class VerifiersExecuteResponse(BaseModel):
275
275
  result: Optional[Any] = Field(
276
276
  None, description="The return value of the function", title="Result"
277
277
  )
278
+ verifier_id: Optional[str] = Field(
279
+ None, description="ID of the verifier", title="Verifier Id"
280
+ )
281
+ execution_id: Optional[str] = Field(
282
+ None, description="ID of the execution record", title="Execution Id"
283
+ )
278
284
  error: Optional[Dict[str, Any]] = Field(
279
285
  None, description="Error details if verification failed", title="Error"
280
286
  )
@@ -4,13 +4,16 @@ from __future__ import annotations
4
4
 
5
5
  import asyncio
6
6
  from datetime import datetime
7
- from typing import Any, Dict, Optional, List
7
+ from typing import Any, Dict, Optional, List, TYPE_CHECKING
8
8
 
9
9
  from pydantic import BaseModel, Field, validator
10
10
 
11
11
  # Import the shared VerifierFunction type that works for both async and sync
12
12
  from fleet.types import VerifierFunction
13
13
 
14
+ if TYPE_CHECKING:
15
+ from fleet.models import VerifiersExecuteResponse
16
+
14
17
 
15
18
  class Task(BaseModel):
16
19
  """A task model representing a single task in the Fleet system."""
@@ -116,6 +119,57 @@ class Task(BaseModel):
116
119
  else:
117
120
  raise ValueError("No verifier function found for this task")
118
121
 
122
+ def verify_detailed(self, env, *args, **kwargs) -> "VerifiersExecuteResponse":
123
+ """Verify the task and return the full execute response model.
124
+
125
+ For sync environments, calls the sync verifier directly.
126
+ For async verifiers, automatically runs them with asyncio.run().
127
+ """
128
+ # If verifier doesn't exist but verifier_func does, rebuild it
129
+ if not self.verifier and self.verifier_func:
130
+ self._rebuild_verifier()
131
+
132
+ if self.verifier:
133
+ import inspect
134
+
135
+ # Check if verifier has remote_with_response method (for decorated verifiers)
136
+ result = self.verifier.remote_with_response(env, *args, **kwargs)
137
+
138
+ # If the result is a coroutine, we need to run it
139
+ if inspect.iscoroutine(result):
140
+ # Check if we're already in an event loop
141
+ try:
142
+ asyncio.get_running_loop()
143
+ # We're in an async context, can't use asyncio.run()
144
+ raise RuntimeError(
145
+ "Cannot run async verifier in sync mode while event loop is running. "
146
+ "Use await task.verify_detailed_async() instead."
147
+ )
148
+ except RuntimeError:
149
+ # No event loop running, safe to use asyncio.run()
150
+ return asyncio.run(result)
151
+ else:
152
+ return result
153
+ else:
154
+ raise ValueError("No verifier function found for this task")
155
+
156
+ def verify_detailed_async(self, *args, **kwargs) -> "VerifiersExecuteResponse":
157
+ """Verify the task and return the full execute response model (async version).
158
+
159
+ For async environments, returns a coroutine that when awaited returns the response.
160
+ Works with both sync and async verifiers in async contexts.
161
+ """
162
+ # If verifier doesn't exist but verifier_func does, rebuild it
163
+ if not self.verifier and self.verifier_func:
164
+ self._rebuild_verifier()
165
+
166
+ if self.verifier:
167
+ result = self.verifier.remote_with_response(*args, **kwargs)
168
+ # Return the result (could be a coroutine or a value)
169
+ return result
170
+ else:
171
+ raise ValueError("No verifier function found for this task")
172
+
119
173
  def _rebuild_verifier(self):
120
174
  """Rebuild the verifier from verifier_func string if it exists."""
121
175
  if self.verifier_func:
@@ -27,6 +27,7 @@ from .bundler import FunctionBundler
27
27
 
28
28
  if TYPE_CHECKING:
29
29
  from ..client import SyncEnv
30
+ from ..models import VerifiersExecuteResponse
30
31
 
31
32
  logger = logging.getLogger(__name__)
32
33
 
@@ -163,72 +164,15 @@ class SyncVerifierFunction:
163
164
 
164
165
  def remote(self, env: "SyncEnv", *args, **kwargs) -> float:
165
166
  """Remote execution of the verifier function with SHA-based bundle caching."""
166
- # Async verifiers are now supported by the backend
167
- # if self._is_async:
168
- # raise NotImplementedError(
169
- # f"Async verifier '{self.key}' cannot be executed remotely. "
170
- # "The remote execution environment only supports synchronous functions. "
171
- # "Please provide a synchronous version of your verifier."
172
- # )
167
+ response = self.remote_with_response(env, *args, **kwargs)
173
168
 
174
- args_array = list(args)
175
- args_array.append({"env": env.instance_id})
176
- args = tuple(args_array)
177
-
178
- try:
179
- # Check if bundle needs to be uploaded
180
- bundle_sha, needs_upload = self._check_bundle_status(env)
181
-
182
- if needs_upload:
183
- # Need to upload bundle to S3
184
- logger.info(f"Uploading bundle {bundle_sha[:8]}... for {self.key}")
185
- bundle_data, _ = self._get_or_create_bundle()
186
-
187
- response = env.execute_verifier_remote(
188
- bundle_data=bundle_data,
189
- bundle_sha=bundle_sha,
190
- key=self.key,
191
- function_name=self.func.__name__,
192
- args=args,
193
- args_array=args_array,
194
- kwargs=kwargs,
195
- needs_upload=True,
196
- )
197
-
198
- logger.debug(f"Bundle {bundle_sha[:8]}... uploaded successfully")
199
-
200
- else:
201
- # Bundle already available - execute without upload
202
- logger.info(
203
- f"Executing cached bundle {bundle_sha[:8]}... for {self.key}"
204
- )
205
- bundle_data, _ = self._get_or_create_bundle()
206
-
207
- response = env.execute_verifier_remote(
208
- bundle_data=bundle_data or b"", # Empty if using server-side bundle
209
- bundle_sha=bundle_sha,
210
- key=self.key,
211
- function_name=self.func.__name__,
212
- args=args,
213
- args_array=args_array,
214
- kwargs=kwargs,
215
- needs_upload=False, # Don't upload, just execute
216
- )
217
-
218
- # Handle response
219
- if response.stdout:
220
- print(response.stdout)
221
- if response.success:
222
- return self._process_result(response.result)
223
- else:
224
- self._raise_remote_error(response.error)
225
-
226
- except Exception as e:
227
- logger.error(f"Remote execution failed for {self.key}: {e}")
228
- # If it's an HTTP error, try to get more details
229
- if hasattr(e, "response") and hasattr(e.response, "text"):
230
- logger.error(f"Server response: {e.response.text}")
231
- raise
169
+ # Handle response
170
+ if response.stdout:
171
+ print(response.stdout)
172
+ if response.success:
173
+ return self._process_result(response.result)
174
+ else:
175
+ self._raise_remote_error(response.error)
232
176
 
233
177
  def _process_result(self, result: Any) -> float:
234
178
  """Process remote execution result, handling different return types."""
@@ -268,7 +212,7 @@ Remote traceback:
268
212
  try:
269
213
  exception_class = getattr(__builtins__, error_type, RuntimeError)
270
214
  raise exception_class(full_message)
271
- except:
215
+ except Exception:
272
216
  raise RuntimeError(full_message)
273
217
 
274
218
  def _get_env_id(self, env: "SyncEnv") -> str:
@@ -291,6 +235,74 @@ Remote traceback:
291
235
  or "not found" in error_msg
292
236
  )
293
237
 
238
+ def remote_with_response(
239
+ self, env: "SyncEnv", *args, **kwargs
240
+ ) -> "VerifiersExecuteResponse":
241
+ """Remote execution of the verifier function that returns the full response model."""
242
+ args_array = list(args)
243
+ args_array.append({"env": env.instance_id})
244
+ args = tuple(args_array)
245
+
246
+ try:
247
+ # Check if bundle needs to be uploaded
248
+ bundle_sha, needs_upload = self._check_bundle_status(env)
249
+
250
+ if needs_upload:
251
+ # Need to upload bundle to S3
252
+ logger.info(f"Uploading bundle {bundle_sha[:8]}... for {self.key}")
253
+ bundle_data, _ = self._get_or_create_bundle()
254
+
255
+ response = env.execute_verifier_remote(
256
+ bundle_data=bundle_data,
257
+ bundle_sha=bundle_sha,
258
+ key=self.key,
259
+ function_name=self.func.__name__,
260
+ args=args,
261
+ args_array=args_array,
262
+ kwargs=kwargs,
263
+ needs_upload=True,
264
+ )
265
+
266
+ logger.debug(f"Bundle {bundle_sha[:8]}... uploaded successfully")
267
+ return response
268
+
269
+ else:
270
+ # Bundle already available - execute without upload
271
+ logger.info(f"Bundle {bundle_sha[:8]}... already cached for {self.key}")
272
+ response = env.execute_verifier_remote(
273
+ bundle_data=b"", # Empty bundle since it's cached
274
+ bundle_sha=bundle_sha,
275
+ key=self.key,
276
+ function_name=self.func.__name__,
277
+ args=args,
278
+ args_array=args_array,
279
+ kwargs=kwargs,
280
+ needs_upload=False,
281
+ )
282
+ return response
283
+
284
+ except Exception as e:
285
+ # Check if error indicates bundle not found and retry with upload
286
+ if self._is_bundle_not_found_error(e) and not needs_upload:
287
+ logger.info(
288
+ f"Bundle {bundle_sha[:8]}... not found on server, uploading..."
289
+ )
290
+ bundle_data, _ = self._get_or_create_bundle()
291
+ response = env.execute_verifier_remote(
292
+ bundle_data=bundle_data,
293
+ bundle_sha=bundle_sha,
294
+ key=self.key,
295
+ function_name=self.func.__name__,
296
+ args=args,
297
+ args_array=args_array,
298
+ kwargs=kwargs,
299
+ needs_upload=True,
300
+ )
301
+ return response
302
+ else:
303
+ logger.error(f"Error in remote execution of {self.key}: {e}")
304
+ raise
305
+
294
306
 
295
307
  def verifier(
296
308
  key: Optional[str] = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fleet-python
3
- Version: 0.2.46
3
+ Version: 0.2.47
4
4
  Summary: Python SDK for Fleet environments
5
5
  Author-email: Fleet AI <nic@fleet.so>
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fleet-python"
7
- version = "0.2.46"
7
+ version = "0.2.47"
8
8
  description = "Python SDK for Fleet environments"
9
9
  authors = [
10
10
  {name = "Fleet AI", email = "nic@fleet.so"},
File without changes
File without changes
File without changes