oneshot-python 0.7.2__tar.gz → 0.8.1__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: oneshot-python
3
- Version: 0.7.2
3
+ Version: 0.8.1
4
4
  Summary: Core Python SDK for the OneShot API — HTTP client with x402 payment handling
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -25,7 +25,7 @@ from oneshot._errors import (
25
25
  )
26
26
  from oneshot.x402 import sign_payment_authorization, encode_payment_header, parse_payment_required
27
27
 
28
- SDK_VERSION = "0.6.0"
28
+ SDK_VERSION = "0.8.1"
29
29
 
30
30
  # ---------------------------------------------------------------------------
31
31
  # Environment configuration
@@ -157,29 +157,37 @@ class OneShotClient:
157
157
 
158
158
  self._log(f"Payment required: {payment_request['amount']} USDC")
159
159
 
160
- # Step 3 — Sign x402 payment (v2 format with accepted requirements + Bazaar metadata)
161
- auth = sign_payment_authorization(
162
- private_key=self._private_key,
163
- from_address=self.address,
164
- to_address=payment_request["recipient"],
165
- amount=payment_request["amount"],
166
- token_address=payment_request["token_address"],
167
- chain_id=payment_request["chain_id"],
168
- network=f"eip155:{payment_request['chain_id']}",
169
- accepted=accepted,
170
- resource=parsed_req.get("resource"),
171
- extensions=parsed_req.get("extensions"),
172
- )
160
+ # Step 3 — Sign x402 payment (skip if credits cover full cost)
161
+ amount = float(payment_request["amount"])
162
+ if amount == 0:
163
+ self._log("Credits cover full cost — skipping payment signature")
164
+ headers = {**self._headers()}
165
+ if quote_id:
166
+ headers["x-quote-id"] = quote_id
167
+ resp2 = await client.post(url, headers=headers, json=payload)
168
+ else:
169
+ auth = sign_payment_authorization(
170
+ private_key=self._private_key,
171
+ from_address=self.address,
172
+ to_address=payment_request["recipient"],
173
+ amount=payment_request["amount"],
174
+ token_address=payment_request["token_address"],
175
+ chain_id=payment_request["chain_id"],
176
+ network=f"eip155:{payment_request['chain_id']}",
177
+ accepted=accepted,
178
+ resource=parsed_req.get("resource"),
179
+ extensions=parsed_req.get("extensions"),
180
+ )
173
181
 
174
- # Step 4 — Re-POST with payment headers (x402 format)
175
- headers = {
176
- **self._headers(),
177
- "payment-signature": encode_payment_header(auth),
178
- }
179
- if quote_id:
180
- headers["x-quote-id"] = quote_id
182
+ # Step 4 — Re-POST with payment headers (x402 format)
183
+ headers = {
184
+ **self._headers(),
185
+ "payment-signature": encode_payment_header(auth),
186
+ }
187
+ if quote_id:
188
+ headers["x-quote-id"] = quote_id
181
189
 
182
- resp2 = await client.post(url, headers=headers, json=payload)
190
+ resp2 = await client.post(url, headers=headers, json=payload)
183
191
 
184
192
  if resp2.status_code not in (200, 201, 202):
185
193
  raise ToolError(
@@ -276,6 +284,111 @@ class OneShotClient:
276
284
  return {"success": True}
277
285
  return resp.json()
278
286
 
287
+ def call_free_delete(
288
+ self,
289
+ endpoint: str,
290
+ ) -> Any:
291
+ """DELETE a free endpoint (blocking)."""
292
+ return asyncio.get_event_loop().run_until_complete(
293
+ self.acall_free_delete(endpoint)
294
+ )
295
+
296
+ async def acall_free_delete(
297
+ self,
298
+ endpoint: str,
299
+ ) -> Any:
300
+ """DELETE a free endpoint (async)."""
301
+ url = f"{self.base_url}{endpoint}"
302
+ async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
303
+ resp = await client.delete(url, headers=self._headers())
304
+ if not resp.is_success:
305
+ raise ToolError(f"DELETE {endpoint} failed", resp.status_code, resp.text)
306
+ if resp.status_code == 204 or not resp.text:
307
+ return {"success": True}
308
+ return resp.json()
309
+
310
+ # ------------------------------------------------------------------
311
+ # Browser
312
+ # ------------------------------------------------------------------
313
+
314
+ def browser(
315
+ self,
316
+ task: str,
317
+ *,
318
+ output_schema: Optional[dict[str, Any]] = None,
319
+ start_url: Optional[str] = None,
320
+ allowed_domains: Optional[list[str]] = None,
321
+ profile_id: Optional[str] = None,
322
+ secrets: Optional[dict[str, str]] = None,
323
+ max_steps: Optional[int] = None,
324
+ max_cost: Optional[float] = None,
325
+ timeout_sec: int = 300,
326
+ ) -> Any:
327
+ """Run a browser automation task. Blocking."""
328
+ return asyncio.get_event_loop().run_until_complete(
329
+ self.abrowser(
330
+ task, output_schema=output_schema, start_url=start_url,
331
+ allowed_domains=allowed_domains, profile_id=profile_id,
332
+ secrets=secrets, max_steps=max_steps, max_cost=max_cost,
333
+ timeout_sec=timeout_sec,
334
+ )
335
+ )
336
+
337
+ async def abrowser(
338
+ self,
339
+ task: str,
340
+ *,
341
+ output_schema: Optional[dict[str, Any]] = None,
342
+ start_url: Optional[str] = None,
343
+ allowed_domains: Optional[list[str]] = None,
344
+ profile_id: Optional[str] = None,
345
+ secrets: Optional[dict[str, str]] = None,
346
+ max_steps: Optional[int] = None,
347
+ max_cost: Optional[float] = None,
348
+ timeout_sec: int = 300,
349
+ ) -> Any:
350
+ """Run a browser automation task. Async."""
351
+ payload: dict[str, Any] = {"task": task}
352
+ if output_schema is not None:
353
+ payload["output_schema"] = output_schema
354
+ if start_url is not None:
355
+ payload["start_url"] = start_url
356
+ if allowed_domains is not None:
357
+ payload["allowed_domains"] = allowed_domains
358
+ if profile_id is not None:
359
+ payload["profile_id"] = profile_id
360
+ if secrets is not None:
361
+ payload["secrets"] = secrets
362
+ if max_steps is not None:
363
+ payload["max_steps"] = max_steps
364
+ return await self.acall_tool(
365
+ "/v1/tools/browser", payload, max_cost=max_cost, timeout_sec=timeout_sec,
366
+ )
367
+
368
+ def create_browser_profile(self, name: str) -> dict:
369
+ """Create a persistent browser profile. Blocking."""
370
+ return self.call_free_post("/v1/tools/browser/profiles", {"name": name})
371
+
372
+ async def acreate_browser_profile(self, name: str) -> dict:
373
+ """Create a persistent browser profile. Async."""
374
+ return await self.acall_free_post("/v1/tools/browser/profiles", {"name": name})
375
+
376
+ def list_browser_profiles(self) -> list:
377
+ """List all browser profiles. Blocking."""
378
+ return self.call_free_get("/v1/tools/browser/profiles")
379
+
380
+ async def alist_browser_profiles(self) -> list:
381
+ """List all browser profiles. Async."""
382
+ return await self.acall_free_get("/v1/tools/browser/profiles")
383
+
384
+ def delete_browser_profile(self, profile_id: str) -> dict:
385
+ """Delete a browser profile. Blocking."""
386
+ return self.call_free_delete(f"/v1/tools/browser/profiles/{profile_id}")
387
+
388
+ async def adelete_browser_profile(self, profile_id: str) -> dict:
389
+ """Delete a browser profile. Async."""
390
+ return await self.acall_free_delete(f"/v1/tools/browser/profiles/{profile_id}")
391
+
279
392
  # ------------------------------------------------------------------
280
393
  # Balance
281
394
  # ------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "oneshot-python"
3
- version = "0.7.2"
3
+ version = "0.8.1"
4
4
  description = "Core Python SDK for the OneShot API — HTTP client with x402 payment handling"
5
5
  readme = {text = "Core Python SDK for the OneShot API", content-type = "text/plain"}
6
6
  license = "MIT"
File without changes
File without changes