browsa 0.3.0__tar.gz → 0.3.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.
- {browsa-0.3.0 → browsa-0.3.1}/PKG-INFO +32 -7
- {browsa-0.3.0 → browsa-0.3.1}/README.md +30 -6
- {browsa-0.3.0 → browsa-0.3.1}/browsa/__init__.py +6 -8
- browsa-0.3.1/browsa/_version.py +1 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa/client.py +57 -0
- browsa-0.3.1/browsa/py.typed +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa.egg-info/PKG-INFO +32 -7
- {browsa-0.3.0 → browsa-0.3.1}/browsa.egg-info/SOURCES.txt +1 -0
- {browsa-0.3.0 → browsa-0.3.1}/pyproject.toml +4 -0
- {browsa-0.3.0 → browsa-0.3.1}/tests/test_unit.py +95 -0
- browsa-0.3.0/browsa/_version.py +0 -1
- {browsa-0.3.0 → browsa-0.3.1}/LICENSE +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa/errors.py +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa/types.py +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa/webhooks.py +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa.egg-info/dependency_links.txt +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa.egg-info/requires.txt +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/browsa.egg-info/top_level.txt +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/setup.cfg +0 -0
- {browsa-0.3.0 → browsa-0.3.1}/tests/test_live.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: browsa
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Official Python SDK for Browsa: real cloud browsers for AI agents (browsa.io)
|
|
5
5
|
Author-email: Browsa <support@browsa.io>
|
|
6
6
|
License: MIT
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Typing :: Typed
|
|
21
22
|
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
22
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
24
|
Requires-Python: >=3.9
|
|
@@ -56,14 +57,17 @@ from browsa import Client
|
|
|
56
57
|
c = Client(api_key="agt_live_...")
|
|
57
58
|
job = c.run_task(
|
|
58
59
|
task="Go to news.ycombinator.com and return the top story title.",
|
|
59
|
-
llm="
|
|
60
|
-
|
|
60
|
+
llm="browsa",
|
|
61
|
+
on_progress=lambda j: j.live_url and print("watch live:", j.live_url),
|
|
61
62
|
)
|
|
62
|
-
print(job.final_result)
|
|
63
|
-
print("watch live:", job.live_url)
|
|
63
|
+
print(job.outcome, job.final_result)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
That runs
|
|
66
|
+
That runs Phantom, our Chromium build, in a temporary cloud browser, driven by Browsa's hosted model: no LLM key needed. To use your own model instead, pass `llm="anthropic:claude-sonnet-5-5"` with `llm_api_key`, or save the key once (below).
|
|
67
|
+
|
|
68
|
+
`job.status` says the run ended; `job.outcome` says how. `outcome == "failed"` with `status == "completed"` means the agent finished but could not do the task, and `final_result` says what stopped it.
|
|
69
|
+
|
|
70
|
+
`live_url` is a Phantom Live link to watch the browser. It exists only while the task runs (so read it in `on_progress` or from `create_task`), and each link opens once.
|
|
67
71
|
|
|
68
72
|
## Saved LLM keys
|
|
69
73
|
|
|
@@ -178,7 +182,8 @@ if not ok:
|
|
|
178
182
|
| Long-poll waits | `wait_for_job(timeout=...)` uses server-side `?wait=30` |
|
|
179
183
|
| Live step events | `for ev in client.stream_job_events(job_id, after=0)`; resume with `after=<last n>` |
|
|
180
184
|
| Webhook signature verify | HMAC-SHA256, constant-time compare, skew check |
|
|
181
|
-
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, etc
|
|
185
|
+
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, `TimeoutError`, etc.; every one is a `BrowsaError` |
|
|
186
|
+
| Typed | Ships `py.typed`; works with `mypy --strict` and pyright |
|
|
182
187
|
| `X-Request-Id` propagation | Every error carries the server's request id |
|
|
183
188
|
| Zero deps | Single wheel, audit-friendly, no transitive surface |
|
|
184
189
|
|
|
@@ -259,6 +264,26 @@ c.act(b["id"], "click", role="button", name="Sign in")
|
|
|
259
264
|
|
|
260
265
|
`status` is `ok`, `failed`, `blocked`, `challenge` or `stale`; none of them raises. `stale` means the ids came from a view the server no longer has (`ids_reset` is true): nothing was done and `text` carries a new view. Both calls are free. Format and actions: <https://browsa.io/docs#agents-observe>.
|
|
261
266
|
|
|
267
|
+
### Downloads and Phantom Live
|
|
268
|
+
|
|
269
|
+
Files a browser downloads are kept with the browser, not on your machine, so Playwright's `download.save_as()` cannot reach them. List and fetch them through the API before you stop the browser:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
files = c.list_downloads(b["id"]) # [{"name", "size", "modified_at"}]
|
|
273
|
+
data = c.download_file(b["id"], files[0]["name"]) # bytes
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
With Playwright the name is the last part of `download.path()`.
|
|
277
|
+
|
|
278
|
+
`create_live_link` gives a link that shows a running browser in any web browser, to watch or to take over:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
link = c.create_live_link(b["id"], scope="control", ttl_seconds=600)
|
|
282
|
+
print(link["live_url"]) # opens once; make one per person
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`scope` is `"view"` (default) or `"control"`. Both calls are free.
|
|
286
|
+
|
|
262
287
|
## Docs
|
|
263
288
|
|
|
264
289
|
- API reference: <https://browsa.io/docs>
|
|
@@ -25,14 +25,17 @@ from browsa import Client
|
|
|
25
25
|
c = Client(api_key="agt_live_...")
|
|
26
26
|
job = c.run_task(
|
|
27
27
|
task="Go to news.ycombinator.com and return the top story title.",
|
|
28
|
-
llm="
|
|
29
|
-
|
|
28
|
+
llm="browsa",
|
|
29
|
+
on_progress=lambda j: j.live_url and print("watch live:", j.live_url),
|
|
30
30
|
)
|
|
31
|
-
print(job.final_result)
|
|
32
|
-
print("watch live:", job.live_url)
|
|
31
|
+
print(job.outcome, job.final_result)
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
That runs
|
|
34
|
+
That runs Phantom, our Chromium build, in a temporary cloud browser, driven by Browsa's hosted model: no LLM key needed. To use your own model instead, pass `llm="anthropic:claude-sonnet-5-5"` with `llm_api_key`, or save the key once (below).
|
|
35
|
+
|
|
36
|
+
`job.status` says the run ended; `job.outcome` says how. `outcome == "failed"` with `status == "completed"` means the agent finished but could not do the task, and `final_result` says what stopped it.
|
|
37
|
+
|
|
38
|
+
`live_url` is a Phantom Live link to watch the browser. It exists only while the task runs (so read it in `on_progress` or from `create_task`), and each link opens once.
|
|
36
39
|
|
|
37
40
|
## Saved LLM keys
|
|
38
41
|
|
|
@@ -147,7 +150,8 @@ if not ok:
|
|
|
147
150
|
| Long-poll waits | `wait_for_job(timeout=...)` uses server-side `?wait=30` |
|
|
148
151
|
| Live step events | `for ev in client.stream_job_events(job_id, after=0)`; resume with `after=<last n>` |
|
|
149
152
|
| Webhook signature verify | HMAC-SHA256, constant-time compare, skew check |
|
|
150
|
-
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, etc
|
|
153
|
+
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, `TimeoutError`, etc.; every one is a `BrowsaError` |
|
|
154
|
+
| Typed | Ships `py.typed`; works with `mypy --strict` and pyright |
|
|
151
155
|
| `X-Request-Id` propagation | Every error carries the server's request id |
|
|
152
156
|
| Zero deps | Single wheel, audit-friendly, no transitive surface |
|
|
153
157
|
|
|
@@ -228,6 +232,26 @@ c.act(b["id"], "click", role="button", name="Sign in")
|
|
|
228
232
|
|
|
229
233
|
`status` is `ok`, `failed`, `blocked`, `challenge` or `stale`; none of them raises. `stale` means the ids came from a view the server no longer has (`ids_reset` is true): nothing was done and `text` carries a new view. Both calls are free. Format and actions: <https://browsa.io/docs#agents-observe>.
|
|
230
234
|
|
|
235
|
+
### Downloads and Phantom Live
|
|
236
|
+
|
|
237
|
+
Files a browser downloads are kept with the browser, not on your machine, so Playwright's `download.save_as()` cannot reach them. List and fetch them through the API before you stop the browser:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
files = c.list_downloads(b["id"]) # [{"name", "size", "modified_at"}]
|
|
241
|
+
data = c.download_file(b["id"], files[0]["name"]) # bytes
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
With Playwright the name is the last part of `download.path()`.
|
|
245
|
+
|
|
246
|
+
`create_live_link` gives a link that shows a running browser in any web browser, to watch or to take over:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
link = c.create_live_link(b["id"], scope="control", ttl_seconds=600)
|
|
250
|
+
print(link["live_url"]) # opens once; make one per person
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`scope` is `"view"` (default) or `"control"`. Both calls are free.
|
|
254
|
+
|
|
231
255
|
## Docs
|
|
232
256
|
|
|
233
257
|
- API reference: <https://browsa.io/docs>
|
|
@@ -7,24 +7,22 @@ Quickstart:
|
|
|
7
7
|
|
|
8
8
|
client = Client(api_key="agt_live_...")
|
|
9
9
|
|
|
10
|
-
# Run a task
|
|
10
|
+
# Run a task and wait for it (hosted model: no LLM key needed)
|
|
11
11
|
job = client.run_task(
|
|
12
12
|
task="Go to news.ycombinator.com and return the top story title.",
|
|
13
|
-
llm="
|
|
14
|
-
llm_api_key="sk-ant-...",
|
|
13
|
+
llm="browsa",
|
|
15
14
|
)
|
|
16
|
-
print(job.final_result)
|
|
17
|
-
print(f"Live stream: {job.live_url}")
|
|
15
|
+
print(job.outcome, job.final_result)
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
job.status says the run ended; job.outcome says how ("failed" with status
|
|
18
|
+
"completed": the agent finished but could not do the task).
|
|
21
19
|
|
|
22
20
|
For async usage:
|
|
23
21
|
|
|
24
22
|
from browsa import AsyncClient
|
|
25
23
|
|
|
26
24
|
async with AsyncClient(api_key="agt_live_...") as c:
|
|
27
|
-
job = await c.run_task(task="...", llm="
|
|
25
|
+
job = await c.run_task(task="...", llm="browsa")
|
|
28
26
|
|
|
29
27
|
For webhooks see browsa.webhooks.verify_signature.
|
|
30
28
|
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.1"
|
|
@@ -11,7 +11,9 @@ this stays pure-stdlib until then.
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
13
|
import asyncio
|
|
14
|
+
import http.client
|
|
14
15
|
import json
|
|
16
|
+
import socket
|
|
15
17
|
import time
|
|
16
18
|
import urllib.error
|
|
17
19
|
import urllib.parse
|
|
@@ -114,6 +116,16 @@ class _Transport:
|
|
|
114
116
|
)
|
|
115
117
|
raise errors.from_response(e.code, err_body)
|
|
116
118
|
except urllib.error.URLError as e:
|
|
119
|
+
# A connect timeout arrives wrapped in URLError.
|
|
120
|
+
if isinstance(e.reason, (socket.timeout, TimeoutError)):
|
|
121
|
+
raise errors.TimeoutError(f"request timed out after {eff_timeout}s") from e
|
|
122
|
+
raise errors.BrowsaError(f"network error: {e}") from e
|
|
123
|
+
except (socket.timeout, TimeoutError) as e:
|
|
124
|
+
# A read timeout is raised bare by http.client, not as URLError.
|
|
125
|
+
# (socket.timeout is TimeoutError itself from Python 3.10.)
|
|
126
|
+
raise errors.TimeoutError(f"request timed out after {eff_timeout}s") from e
|
|
127
|
+
except (http.client.HTTPException, OSError) as e:
|
|
128
|
+
# Connection reset or closed mid-response.
|
|
117
129
|
raise errors.BrowsaError(f"network error: {e}") from e
|
|
118
130
|
|
|
119
131
|
|
|
@@ -992,6 +1004,42 @@ class Client:
|
|
|
992
1004
|
The empirical proof behind the trust score number."""
|
|
993
1005
|
return self._t.request("GET", f"/v1/agents/{agent_id}/detection-signal")
|
|
994
1006
|
|
|
1007
|
+
# ── Downloads and Phantom Live ───────────────────────────────────────
|
|
1008
|
+
|
|
1009
|
+
def list_downloads(self, agent_id: str) -> list[dict]:
|
|
1010
|
+
"""GET /v1/agents/:id/downloads: the files a running browser has
|
|
1011
|
+
downloaded, newest first. Each row: name, size (bytes), modified_at.
|
|
1012
|
+
With Playwright a file's name is the last part of
|
|
1013
|
+
`await download.path()`. The folder is removed when the browser
|
|
1014
|
+
stops, so fetch files first. Free."""
|
|
1015
|
+
body = self._t.request("GET", f"/v1/agents/{agent_id}/downloads") or {}
|
|
1016
|
+
return list(body.get("files") or [])
|
|
1017
|
+
|
|
1018
|
+
def download_file(self, agent_id: str, name: str) -> bytes:
|
|
1019
|
+
"""GET /v1/agents/:id/downloads/:name: one downloaded file's bytes.
|
|
1020
|
+
`name` comes from list_downloads(). Free."""
|
|
1021
|
+
path = f"/v1/agents/{agent_id}/downloads/{urllib.parse.quote(name, safe='')}"
|
|
1022
|
+
return self._t.request("GET", path, raw=True, timeout=max(self._t.timeout, 120.0))
|
|
1023
|
+
|
|
1024
|
+
def create_live_link(self, agent_id: str, *, scope: Optional[str] = None,
|
|
1025
|
+
ttl_seconds: Optional[int] = None, job_id: Optional[str] = None) -> dict:
|
|
1026
|
+
"""POST /v1/agents/:id/live: a Phantom Live link to a running
|
|
1027
|
+
browser. scope is "view" (watch only, the default) or "control"
|
|
1028
|
+
(click and type). ttl_seconds is 60 to 86400. job_id ties the link
|
|
1029
|
+
to one task on that browser and shows its steps.
|
|
1030
|
+
|
|
1031
|
+
Returns {live_url, expires_at, scope, agent_id, job_id?}. A link
|
|
1032
|
+
opens once: make one per person or tab, and call this again for
|
|
1033
|
+
another. Free."""
|
|
1034
|
+
body: dict = {}
|
|
1035
|
+
if scope is not None:
|
|
1036
|
+
body["scope"] = scope
|
|
1037
|
+
if ttl_seconds is not None:
|
|
1038
|
+
body["ttl_seconds"] = ttl_seconds
|
|
1039
|
+
if job_id is not None:
|
|
1040
|
+
body["job_id"] = job_id
|
|
1041
|
+
return self._t.request("POST", f"/v1/agents/{agent_id}/live", body=body)
|
|
1042
|
+
|
|
995
1043
|
# ── Page view: observe and act without CDP ───────────────────────────
|
|
996
1044
|
|
|
997
1045
|
def _page_session(self, agent_id: str, tab: Optional[str], session: Optional[str]) -> Optional[str]:
|
|
@@ -1450,6 +1498,15 @@ class AsyncClient:
|
|
|
1450
1498
|
async def detection_signal(self, agent_id: str) -> dict:
|
|
1451
1499
|
return await asyncio.to_thread(self._sync.detection_signal, agent_id)
|
|
1452
1500
|
|
|
1501
|
+
async def list_downloads(self, agent_id: str) -> list[dict]:
|
|
1502
|
+
return await asyncio.to_thread(self._sync.list_downloads, agent_id)
|
|
1503
|
+
|
|
1504
|
+
async def download_file(self, agent_id: str, name: str) -> bytes:
|
|
1505
|
+
return await asyncio.to_thread(self._sync.download_file, agent_id, name)
|
|
1506
|
+
|
|
1507
|
+
async def create_live_link(self, agent_id: str, **kw: Any) -> dict:
|
|
1508
|
+
return await asyncio.to_thread(self._sync.create_live_link, agent_id, **kw)
|
|
1509
|
+
|
|
1453
1510
|
async def observe(self, agent_id: str, **kw: Any) -> dict:
|
|
1454
1511
|
return await asyncio.to_thread(self._sync.observe, agent_id, **kw)
|
|
1455
1512
|
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: browsa
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Official Python SDK for Browsa: real cloud browsers for AI agents (browsa.io)
|
|
5
5
|
Author-email: Browsa <support@browsa.io>
|
|
6
6
|
License: MIT
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Typing :: Typed
|
|
21
22
|
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
22
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
24
|
Requires-Python: >=3.9
|
|
@@ -56,14 +57,17 @@ from browsa import Client
|
|
|
56
57
|
c = Client(api_key="agt_live_...")
|
|
57
58
|
job = c.run_task(
|
|
58
59
|
task="Go to news.ycombinator.com and return the top story title.",
|
|
59
|
-
llm="
|
|
60
|
-
|
|
60
|
+
llm="browsa",
|
|
61
|
+
on_progress=lambda j: j.live_url and print("watch live:", j.live_url),
|
|
61
62
|
)
|
|
62
|
-
print(job.final_result)
|
|
63
|
-
print("watch live:", job.live_url)
|
|
63
|
+
print(job.outcome, job.final_result)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
That runs
|
|
66
|
+
That runs Phantom, our Chromium build, in a temporary cloud browser, driven by Browsa's hosted model: no LLM key needed. To use your own model instead, pass `llm="anthropic:claude-sonnet-5-5"` with `llm_api_key`, or save the key once (below).
|
|
67
|
+
|
|
68
|
+
`job.status` says the run ended; `job.outcome` says how. `outcome == "failed"` with `status == "completed"` means the agent finished but could not do the task, and `final_result` says what stopped it.
|
|
69
|
+
|
|
70
|
+
`live_url` is a Phantom Live link to watch the browser. It exists only while the task runs (so read it in `on_progress` or from `create_task`), and each link opens once.
|
|
67
71
|
|
|
68
72
|
## Saved LLM keys
|
|
69
73
|
|
|
@@ -178,7 +182,8 @@ if not ok:
|
|
|
178
182
|
| Long-poll waits | `wait_for_job(timeout=...)` uses server-side `?wait=30` |
|
|
179
183
|
| Live step events | `for ev in client.stream_job_events(job_id, after=0)`; resume with `after=<last n>` |
|
|
180
184
|
| Webhook signature verify | HMAC-SHA256, constant-time compare, skew check |
|
|
181
|
-
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, etc
|
|
185
|
+
| Canonical error envelope | `AuthError`, `InvalidIDError`, `RateLimitError`, `TimeoutError`, etc.; every one is a `BrowsaError` |
|
|
186
|
+
| Typed | Ships `py.typed`; works with `mypy --strict` and pyright |
|
|
182
187
|
| `X-Request-Id` propagation | Every error carries the server's request id |
|
|
183
188
|
| Zero deps | Single wheel, audit-friendly, no transitive surface |
|
|
184
189
|
|
|
@@ -259,6 +264,26 @@ c.act(b["id"], "click", role="button", name="Sign in")
|
|
|
259
264
|
|
|
260
265
|
`status` is `ok`, `failed`, `blocked`, `challenge` or `stale`; none of them raises. `stale` means the ids came from a view the server no longer has (`ids_reset` is true): nothing was done and `text` carries a new view. Both calls are free. Format and actions: <https://browsa.io/docs#agents-observe>.
|
|
261
266
|
|
|
267
|
+
### Downloads and Phantom Live
|
|
268
|
+
|
|
269
|
+
Files a browser downloads are kept with the browser, not on your machine, so Playwright's `download.save_as()` cannot reach them. List and fetch them through the API before you stop the browser:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
files = c.list_downloads(b["id"]) # [{"name", "size", "modified_at"}]
|
|
273
|
+
data = c.download_file(b["id"], files[0]["name"]) # bytes
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
With Playwright the name is the last part of `download.path()`.
|
|
277
|
+
|
|
278
|
+
`create_live_link` gives a link that shows a running browser in any web browser, to watch or to take over:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
link = c.create_live_link(b["id"], scope="control", ttl_seconds=600)
|
|
282
|
+
print(link["live_url"]) # opens once; make one per person
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`scope` is `"view"` (default) or `"control"`. Both calls are free.
|
|
286
|
+
|
|
262
287
|
## Docs
|
|
263
288
|
|
|
264
289
|
- API reference: <https://browsa.io/docs>
|
|
@@ -20,6 +20,7 @@ classifiers = [
|
|
|
20
20
|
"Programming Language :: Python :: 3.10",
|
|
21
21
|
"Programming Language :: Python :: 3.11",
|
|
22
22
|
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Typing :: Typed",
|
|
23
24
|
"Topic :: Internet :: WWW/HTTP :: Browsers",
|
|
24
25
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
26
|
]
|
|
@@ -39,5 +40,8 @@ Changelog = "https://github.com/browsa-io/browsa/releases"
|
|
|
39
40
|
include = ["browsa*"]
|
|
40
41
|
exclude = ["tests*", "examples*"]
|
|
41
42
|
|
|
43
|
+
[tool.setuptools.package-data]
|
|
44
|
+
browsa = ["py.typed"]
|
|
45
|
+
|
|
42
46
|
[tool.setuptools.dynamic]
|
|
43
47
|
version = {attr = "browsa._version.__version__"}
|
|
@@ -147,6 +147,8 @@ def test_client_requires_agt_prefix():
|
|
|
147
147
|
|
|
148
148
|
|
|
149
149
|
class _RecordingTransport:
|
|
150
|
+
timeout = 30.0
|
|
151
|
+
|
|
150
152
|
def __init__(self, reply):
|
|
151
153
|
self.calls = []
|
|
152
154
|
self.reply = reply
|
|
@@ -965,3 +967,96 @@ def test_async_observe_and_act():
|
|
|
965
967
|
("POST", "/v1/agents/agt_1/observe", {"scope": "page"}),
|
|
966
968
|
("POST", "/v1/agents/agt_1/act", {"action": "click", "role": "button", "name": "Continue", "session": "pv_a"}),
|
|
967
969
|
]
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
# ─── 0.3.1: timeouts and dropped connections are BrowsaError ─────────────
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
def _silent_server(mode):
|
|
976
|
+
"""A raw socket server. mode "hang": accepts and never answers.
|
|
977
|
+
mode "drop": reads the request and closes without a response."""
|
|
978
|
+
import socket
|
|
979
|
+
import threading
|
|
980
|
+
|
|
981
|
+
srv = socket.socket()
|
|
982
|
+
srv.bind(("127.0.0.1", 0))
|
|
983
|
+
srv.listen(5)
|
|
984
|
+
conns = []
|
|
985
|
+
|
|
986
|
+
def loop():
|
|
987
|
+
while True:
|
|
988
|
+
try:
|
|
989
|
+
conn, _ = srv.accept()
|
|
990
|
+
except OSError:
|
|
991
|
+
return
|
|
992
|
+
if mode == "drop":
|
|
993
|
+
conn.recv(4096)
|
|
994
|
+
conn.close()
|
|
995
|
+
else:
|
|
996
|
+
conns.append(conn)
|
|
997
|
+
|
|
998
|
+
threading.Thread(target=loop, daemon=True).start()
|
|
999
|
+
return srv, f"http://127.0.0.1:{srv.getsockname()[1]}"
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
def test_read_timeout_raises_the_sdk_timeout_error():
|
|
1003
|
+
from browsa import BrowsaError, Client, TimeoutError as SdkTimeout
|
|
1004
|
+
srv, url = _silent_server("hang")
|
|
1005
|
+
try:
|
|
1006
|
+
with pytest.raises(SdkTimeout) as ei:
|
|
1007
|
+
Client("agt_test_x", base_url=url, timeout=0.3).credits()
|
|
1008
|
+
finally:
|
|
1009
|
+
srv.close()
|
|
1010
|
+
assert isinstance(ei.value, BrowsaError)
|
|
1011
|
+
assert "timed out" in str(ei.value)
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
def test_dropped_connection_raises_browsa_error():
|
|
1015
|
+
from browsa import BrowsaError, Client
|
|
1016
|
+
srv, url = _silent_server("drop")
|
|
1017
|
+
try:
|
|
1018
|
+
with pytest.raises(BrowsaError):
|
|
1019
|
+
Client("agt_test_x", base_url=url, timeout=2).credits()
|
|
1020
|
+
finally:
|
|
1021
|
+
srv.close()
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
def test_py_typed_marker_is_in_the_package():
|
|
1025
|
+
import os
|
|
1026
|
+
import browsa
|
|
1027
|
+
assert os.path.exists(os.path.join(os.path.dirname(browsa.__file__), "py.typed"))
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
# ─── 0.3.1: downloads and Phantom Live ───────────────────────────────────
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
def test_downloads_and_live_link_requests():
|
|
1034
|
+
from browsa import Client
|
|
1035
|
+
c = Client("agt_test_x")
|
|
1036
|
+
c._t = _RecordingTransport({"files": [{"name": "a b.pdf", "size": 3, "modified_at": "2026-11-16T00:00:00Z"}]})
|
|
1037
|
+
assert c.list_downloads("agt_1") == [{"name": "a b.pdf", "size": 3, "modified_at": "2026-11-16T00:00:00Z"}]
|
|
1038
|
+
assert c._t.calls[0][:2] == ("GET", "/v1/agents/agt_1/downloads")
|
|
1039
|
+
c._t.reply = b"%PDF"
|
|
1040
|
+
assert c.download_file("agt_1", "a b/..pdf") == b"%PDF"
|
|
1041
|
+
assert c._t.calls[1][:2] == ("GET", "/v1/agents/agt_1/downloads/a%20b%2F..pdf")
|
|
1042
|
+
c._t.reply = {"live_url": "https://browsa.io/live?agent=agt_1#c=lc_x", "scope": "control"}
|
|
1043
|
+
r = c.create_live_link("agt_1", scope="control", ttl_seconds=600, job_id="j1")
|
|
1044
|
+
assert r["scope"] == "control"
|
|
1045
|
+
assert c._t.calls[2] == ("POST", "/v1/agents/agt_1/live", {"scope": "control", "ttl_seconds": 600, "job_id": "j1"})
|
|
1046
|
+
c.create_live_link("agt_1")
|
|
1047
|
+
assert c._t.calls[3] == ("POST", "/v1/agents/agt_1/live", {})
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
def test_async_downloads_and_live_link():
|
|
1051
|
+
import asyncio
|
|
1052
|
+
from browsa import AsyncClient
|
|
1053
|
+
c = AsyncClient("agt_test_x")
|
|
1054
|
+
c._sync._t = _RecordingTransport({"files": []})
|
|
1055
|
+
|
|
1056
|
+
async def run():
|
|
1057
|
+
files = await c.list_downloads("agt_1")
|
|
1058
|
+
await c.create_live_link("agt_1", scope="view")
|
|
1059
|
+
return files
|
|
1060
|
+
|
|
1061
|
+
assert asyncio.run(run()) == []
|
|
1062
|
+
assert c._sync._t.calls[1] == ("POST", "/v1/agents/agt_1/live", {"scope": "view"})
|
browsa-0.3.0/browsa/_version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|