gl-browser-use 0.0.0b7__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.
- gl_browser_use-0.0.0b7/MANIFEST.in +5 -0
- gl_browser_use-0.0.0b7/PKG-INFO +236 -0
- gl_browser_use-0.0.0b7/README.md +214 -0
- gl_browser_use-0.0.0b7/gl_browser_use/__init__.py +60 -0
- gl_browser_use-0.0.0b7/gl_browser_use/client.py +639 -0
- gl_browser_use-0.0.0b7/gl_browser_use/config.py +169 -0
- gl_browser_use-0.0.0b7/gl_browser_use/errors.py +119 -0
- gl_browser_use-0.0.0b7/gl_browser_use/events.py +147 -0
- gl_browser_use-0.0.0b7/gl_browser_use/infrastructure/__init__.py +39 -0
- gl_browser_use-0.0.0b7/gl_browser_use/infrastructure/base.py +103 -0
- gl_browser_use-0.0.0b7/gl_browser_use/infrastructure/steel.py +296 -0
- gl_browser_use-0.0.0b7/gl_browser_use/models.py +45 -0
- gl_browser_use-0.0.0b7/gl_browser_use/parsing.py +264 -0
- gl_browser_use-0.0.0b7/gl_browser_use/parsing_recovery.py +204 -0
- gl_browser_use-0.0.0b7/gl_browser_use/session_errors.py +72 -0
- gl_browser_use-0.0.0b7/gl_browser_use/storage/__init__.py +39 -0
- gl_browser_use-0.0.0b7/gl_browser_use/storage/base.py +125 -0
- gl_browser_use-0.0.0b7/gl_browser_use/storage/minio_compatible.py +84 -0
- gl_browser_use-0.0.0b7/gl_browser_use.egg-info/PKG-INFO +236 -0
- gl_browser_use-0.0.0b7/gl_browser_use.egg-info/SOURCES.txt +24 -0
- gl_browser_use-0.0.0b7/gl_browser_use.egg-info/dependency_links.txt +1 -0
- gl_browser_use-0.0.0b7/gl_browser_use.egg-info/requires.txt +19 -0
- gl_browser_use-0.0.0b7/gl_browser_use.egg-info/top_level.txt +1 -0
- gl_browser_use-0.0.0b7/pyproject.toml +67 -0
- gl_browser_use-0.0.0b7/setup.cfg +4 -0
- gl_browser_use-0.0.0b7/setup.py +10 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gl-browser-use
|
|
3
|
+
Version: 0.0.0b7
|
|
4
|
+
Summary: A typed Python SDK for running browser automation tasks through `browser-use`
|
|
5
|
+
Author-email: Reinhart Linanda <reinhart.linanda@gdplabs.id>
|
|
6
|
+
Requires-Python: <3.13,>=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: browser-use<0.12.0,>=0.11.13
|
|
9
|
+
Requires-Dist: json-repair<0.47.0,>=0.46.0
|
|
10
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
|
11
|
+
Requires-Dist: requests<3.0.0,>=2.32.4
|
|
12
|
+
Provides-Extra: steel
|
|
13
|
+
Requires-Dist: steel-sdk<0.17.0,>=0.16.0; extra == "steel"
|
|
14
|
+
Provides-Extra: infrastructure
|
|
15
|
+
Requires-Dist: gl-browser-use[steel]; extra == "infrastructure"
|
|
16
|
+
Provides-Extra: minio
|
|
17
|
+
Requires-Dist: minio<8.0.0,>=7.2.20; extra == "minio"
|
|
18
|
+
Provides-Extra: storage
|
|
19
|
+
Requires-Dist: gl-browser-use[minio]; extra == "storage"
|
|
20
|
+
Provides-Extra: full
|
|
21
|
+
Requires-Dist: gl-browser-use[infrastructure,storage]; extra == "full"
|
|
22
|
+
|
|
23
|
+
# GL Browser Use
|
|
24
|
+
|
|
25
|
+
GL Browser Use is a typed Python SDK for running browser automation tasks through `browser-use`. It provides a stable client facade, structured stream events, explicit result objects, optional Steel browser infrastructure, optional MinIO/S3-compatible recording storage, and bounded retries for recoverable browser-session failures.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Install the core SDK:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install gl-browser-use
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Install optional providers only when you need them:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install "gl-browser-use[steel]" # Steel browser infrastructure
|
|
39
|
+
pip install "gl-browser-use[infrastructure]" # All browser infrastructure providers
|
|
40
|
+
pip install "gl-browser-use[minio]" # MinIO/S3-compatible object storage
|
|
41
|
+
pip install "gl-browser-use[storage]" # All object storage providers
|
|
42
|
+
pip install "gl-browser-use[full]" # Infrastructure + storage providers
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use the concrete extras (`steel`, `minio`) in application dependency files when you want to pin exactly which provider you depend on. The slot extras (`infrastructure`, `storage`, `full`) are convenience aliases and may include more providers later.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
`BrowserUseClient` supports streaming and non-streaming execution. API keys can be passed directly or read from environment variables.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import asyncio
|
|
53
|
+
|
|
54
|
+
from gl_browser_use import BrowserUseClient, BrowserUseClientConfig
|
|
55
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
56
|
+
from gl_browser_use.storage import MinIOS3CompatibleStorage
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def main() -> None:
|
|
60
|
+
client = BrowserUseClient(
|
|
61
|
+
config=BrowserUseClientConfig(
|
|
62
|
+
llm_openai_api_key="...",
|
|
63
|
+
page_extraction_llm_openai_api_key="...",
|
|
64
|
+
max_session_retries=2,
|
|
65
|
+
session_retry_delay_in_s=3.0,
|
|
66
|
+
),
|
|
67
|
+
infrastructure=SteelBrowserInfrastructure(), # reads STEEL_API_KEY by default
|
|
68
|
+
storage=MinIOS3CompatibleStorage.from_environment(),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
async for event in client.run("Open Hacker News and list five article titles"):
|
|
72
|
+
print(event.content)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
asyncio.run(main())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For a single aggregated result:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from gl_browser_use import BrowserUseClient, BrowserUseClientConfig
|
|
82
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
83
|
+
|
|
84
|
+
client = BrowserUseClient(
|
|
85
|
+
config=BrowserUseClientConfig(
|
|
86
|
+
llm_openai_api_key="...",
|
|
87
|
+
page_extraction_llm_openai_api_key="...",
|
|
88
|
+
),
|
|
89
|
+
infrastructure=SteelBrowserInfrastructure(),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
result = client.run_sync("Open Hacker News and list five article titles")
|
|
93
|
+
|
|
94
|
+
print(result.status)
|
|
95
|
+
print(result.final_output)
|
|
96
|
+
print(result.session_id)
|
|
97
|
+
print(result.streaming_url)
|
|
98
|
+
print(result.recording_url)
|
|
99
|
+
print(result.metadata)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
`BrowserUseClientConfig` validates required values when the client is created. If `llm_openai_api_key` or `page_extraction_llm_openai_api_key` is not passed, both default to `OPENAI_API_KEY`.
|
|
105
|
+
|
|
106
|
+
Common client options:
|
|
107
|
+
|
|
108
|
+
1. `llm_openai_model`: primary browser-control model. Default: `o3`.
|
|
109
|
+
2. `page_extraction_llm_openai_model`: page extraction model. Default: `gpt-5-mini`.
|
|
110
|
+
3. `extend_system_message`: optional system prompt extension.
|
|
111
|
+
4. `vision_detail_level`: `auto`, `low`, or `high`. Default: `auto`.
|
|
112
|
+
5. `llm_timeout_in_s`: optional LLM timeout.
|
|
113
|
+
6. `step_timeout_in_s`: per-step browser timeout. Default: `180`.
|
|
114
|
+
7. `enable_cloud_sync`: controls `browser-use` cloud sync. Default: `False`.
|
|
115
|
+
8. `logging_level`: `debug`, `info`, `warning`, `error`, or `result`. Default: `info`.
|
|
116
|
+
9. `max_session_retries`: recoverable session retries. Default: `2`.
|
|
117
|
+
10. `session_retry_delay_in_s`: delay between retries. Default: `3.0`.
|
|
118
|
+
|
|
119
|
+
Optional provider environment variables:
|
|
120
|
+
|
|
121
|
+
1. `STEEL_API_KEY`: used by `SteelBrowserInfrastructure()` when `api_key` is not passed.
|
|
122
|
+
2. `OBJECT_STORAGE_URL`: MinIO/S3 endpoint, for example `localhost:9001` or `https://storage.example`.
|
|
123
|
+
3. `OBJECT_STORAGE_USERNAME`: object storage access key.
|
|
124
|
+
4. `OBJECT_STORAGE_PASSWORD`: object storage secret key.
|
|
125
|
+
5. `OBJECT_STORAGE_BUCKET_NAME`: target bucket name.
|
|
126
|
+
6. `OBJECT_STORAGE_DIRECTORY_PREFIX`: optional object key prefix.
|
|
127
|
+
7. `OBJECT_STORAGE_SECURE`: `true` for HTTPS when the endpoint has no scheme.
|
|
128
|
+
|
|
129
|
+
Copy `.env.example` to `.env` for local development, then load it with your application environment manager.
|
|
130
|
+
|
|
131
|
+
## Runtime API
|
|
132
|
+
|
|
133
|
+
The client exposes three run methods:
|
|
134
|
+
|
|
135
|
+
1. `run(task)`: async generator that yields `BrowserUseStreamEvent` values as work progresses.
|
|
136
|
+
2. `run_once(task)`: async method that returns one `BrowserUseRunResult` and includes emitted events in `result.events`.
|
|
137
|
+
3. `run_sync(task)`: blocking wrapper around `run_once()` using `asyncio.run()`.
|
|
138
|
+
|
|
139
|
+
Do not call `run_sync()` from an already running event loop. Use `await run_once()` or `async for event in run()` in async applications.
|
|
140
|
+
|
|
141
|
+
Cancelling the stream by breaking from `async for` or calling `await stream.aclose()` cancels the underlying run task. Browser sessions and infrastructure sessions are released in cleanup.
|
|
142
|
+
|
|
143
|
+
## Result Contract
|
|
144
|
+
|
|
145
|
+
`BrowserUseRunResult` contains:
|
|
146
|
+
|
|
147
|
+
1. `status`: `success`, `error`, or `cancelled`.
|
|
148
|
+
2. `task`: normalized task string.
|
|
149
|
+
3. `final_output`: final text extracted from the underlying agent, or `Task completed` when no final text is available.
|
|
150
|
+
4. `session_id`: infrastructure session ID when an external browser session was used.
|
|
151
|
+
5. `streaming_url`: browser debug or streaming URL when available.
|
|
152
|
+
6. `recording_url`: expected recording URL when recording is configured.
|
|
153
|
+
7. `steps`: number of browser-use steps executed.
|
|
154
|
+
8. `error`: terminal error message for error results.
|
|
155
|
+
9. `events`: collected stream events for `run_once()`.
|
|
156
|
+
10. `metadata`: attempt, retry, and recording metadata.
|
|
157
|
+
|
|
158
|
+
Recording metadata uses these statuses:
|
|
159
|
+
|
|
160
|
+
1. `disabled`: infrastructure, storage, or browser context is not available.
|
|
161
|
+
2. `unsupported`: the selected infrastructure does not support recording.
|
|
162
|
+
3. `unavailable`: storage is configured but not available.
|
|
163
|
+
4. `scheduled`: a background recording upload has been scheduled.
|
|
164
|
+
5. `unknown`: recording may have started, but the terminal error did not include enough context to determine the final state.
|
|
165
|
+
|
|
166
|
+
## Streaming Contract
|
|
167
|
+
|
|
168
|
+
`BrowserUseStreamEvent` contains:
|
|
169
|
+
|
|
170
|
+
1. `event_type`
|
|
171
|
+
2. `content`
|
|
172
|
+
3. `thinking_and_activity_info`
|
|
173
|
+
4. `is_final`
|
|
174
|
+
5. `tool_info`
|
|
175
|
+
6. `metadata`
|
|
176
|
+
|
|
177
|
+
Important event content values:
|
|
178
|
+
|
|
179
|
+
1. `Receive streaming URL`: emitted when a browser debug or streaming URL is available.
|
|
180
|
+
2. `Receive recording URL`: emitted when a recording URL can be resolved.
|
|
181
|
+
3. `Task completed`: emitted for the final successful step.
|
|
182
|
+
|
|
183
|
+
Activity events encode iframe URLs in `thinking_and_activity_info["data_value"]` as a JSON string:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{"type": "iframe", "message": "<url>"}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Step events include serialized tool calls in `tool_info["tool_calls"]`.
|
|
190
|
+
|
|
191
|
+
## Retries And Errors
|
|
192
|
+
|
|
193
|
+
The client retries only classified recoverable browser-session failures, such as browser closure or websocket disconnect messages. Before each retry, it emits a retry status event. Retries are bounded by `max_session_retries`, so total attempts are `max_session_retries + 1`.
|
|
194
|
+
|
|
195
|
+
Non-recoverable task failures return `BrowserUseRunResult(status="error")`. Recoverable failures that exhaust all attempts raise `BrowserUseRetryExhaustedError`.
|
|
196
|
+
|
|
197
|
+
SDK error types:
|
|
198
|
+
|
|
199
|
+
1. `BrowserUseConfigurationError`: missing or invalid runtime configuration.
|
|
200
|
+
2. `BrowserUseDependencyError`: optional provider dependency problem.
|
|
201
|
+
3. `BrowserUseMissingDependencyError`: optional provider extra is not installed.
|
|
202
|
+
4. `BrowserUseExecutionError`: execution-time failure.
|
|
203
|
+
5. `BrowserUseRetryExhaustedError`: recoverable session retries were exhausted.
|
|
204
|
+
|
|
205
|
+
## Optional Providers
|
|
206
|
+
|
|
207
|
+
Optional providers are lazy-loaded. Importing `gl_browser_use` does not require Steel or MinIO to be installed.
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
211
|
+
from gl_browser_use.storage import MinIOS3CompatibleStorage
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`SteelBrowserInfrastructure` creates Steel browser sessions and provides CDP/streaming URLs. `MinIOS3CompatibleStorage` uploads session recordings to MinIO or an S3-compatible service and returns presigned URLs.
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
From `libs/gl-browser-use`:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
make install-dev
|
|
222
|
+
make test-unit
|
|
223
|
+
make test-integration
|
|
224
|
+
make lint
|
|
225
|
+
make build-check
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Useful targets:
|
|
229
|
+
|
|
230
|
+
1. `make test`: run all tests.
|
|
231
|
+
2. `make test-unit`: run unit tests with coverage.
|
|
232
|
+
3. `make test-integration`: run integration-marked contract tests.
|
|
233
|
+
4. `make lint`: run Ruff checks.
|
|
234
|
+
5. `make format`: run Ruff fixes and formatter.
|
|
235
|
+
6. `make pre-commit`: run pre-commit hooks.
|
|
236
|
+
7. `make build-check`: build the package and validate artifacts with Twine.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# GL Browser Use
|
|
2
|
+
|
|
3
|
+
GL Browser Use is a typed Python SDK for running browser automation tasks through `browser-use`. It provides a stable client facade, structured stream events, explicit result objects, optional Steel browser infrastructure, optional MinIO/S3-compatible recording storage, and bounded retries for recoverable browser-session failures.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the core SDK:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install gl-browser-use
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Install optional providers only when you need them:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install "gl-browser-use[steel]" # Steel browser infrastructure
|
|
17
|
+
pip install "gl-browser-use[infrastructure]" # All browser infrastructure providers
|
|
18
|
+
pip install "gl-browser-use[minio]" # MinIO/S3-compatible object storage
|
|
19
|
+
pip install "gl-browser-use[storage]" # All object storage providers
|
|
20
|
+
pip install "gl-browser-use[full]" # Infrastructure + storage providers
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use the concrete extras (`steel`, `minio`) in application dependency files when you want to pin exactly which provider you depend on. The slot extras (`infrastructure`, `storage`, `full`) are convenience aliases and may include more providers later.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
`BrowserUseClient` supports streaming and non-streaming execution. API keys can be passed directly or read from environment variables.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import asyncio
|
|
31
|
+
|
|
32
|
+
from gl_browser_use import BrowserUseClient, BrowserUseClientConfig
|
|
33
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
34
|
+
from gl_browser_use.storage import MinIOS3CompatibleStorage
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def main() -> None:
|
|
38
|
+
client = BrowserUseClient(
|
|
39
|
+
config=BrowserUseClientConfig(
|
|
40
|
+
llm_openai_api_key="...",
|
|
41
|
+
page_extraction_llm_openai_api_key="...",
|
|
42
|
+
max_session_retries=2,
|
|
43
|
+
session_retry_delay_in_s=3.0,
|
|
44
|
+
),
|
|
45
|
+
infrastructure=SteelBrowserInfrastructure(), # reads STEEL_API_KEY by default
|
|
46
|
+
storage=MinIOS3CompatibleStorage.from_environment(),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
async for event in client.run("Open Hacker News and list five article titles"):
|
|
50
|
+
print(event.content)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
asyncio.run(main())
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For a single aggregated result:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from gl_browser_use import BrowserUseClient, BrowserUseClientConfig
|
|
60
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
61
|
+
|
|
62
|
+
client = BrowserUseClient(
|
|
63
|
+
config=BrowserUseClientConfig(
|
|
64
|
+
llm_openai_api_key="...",
|
|
65
|
+
page_extraction_llm_openai_api_key="...",
|
|
66
|
+
),
|
|
67
|
+
infrastructure=SteelBrowserInfrastructure(),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
result = client.run_sync("Open Hacker News and list five article titles")
|
|
71
|
+
|
|
72
|
+
print(result.status)
|
|
73
|
+
print(result.final_output)
|
|
74
|
+
print(result.session_id)
|
|
75
|
+
print(result.streaming_url)
|
|
76
|
+
print(result.recording_url)
|
|
77
|
+
print(result.metadata)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Configuration
|
|
81
|
+
|
|
82
|
+
`BrowserUseClientConfig` validates required values when the client is created. If `llm_openai_api_key` or `page_extraction_llm_openai_api_key` is not passed, both default to `OPENAI_API_KEY`.
|
|
83
|
+
|
|
84
|
+
Common client options:
|
|
85
|
+
|
|
86
|
+
1. `llm_openai_model`: primary browser-control model. Default: `o3`.
|
|
87
|
+
2. `page_extraction_llm_openai_model`: page extraction model. Default: `gpt-5-mini`.
|
|
88
|
+
3. `extend_system_message`: optional system prompt extension.
|
|
89
|
+
4. `vision_detail_level`: `auto`, `low`, or `high`. Default: `auto`.
|
|
90
|
+
5. `llm_timeout_in_s`: optional LLM timeout.
|
|
91
|
+
6. `step_timeout_in_s`: per-step browser timeout. Default: `180`.
|
|
92
|
+
7. `enable_cloud_sync`: controls `browser-use` cloud sync. Default: `False`.
|
|
93
|
+
8. `logging_level`: `debug`, `info`, `warning`, `error`, or `result`. Default: `info`.
|
|
94
|
+
9. `max_session_retries`: recoverable session retries. Default: `2`.
|
|
95
|
+
10. `session_retry_delay_in_s`: delay between retries. Default: `3.0`.
|
|
96
|
+
|
|
97
|
+
Optional provider environment variables:
|
|
98
|
+
|
|
99
|
+
1. `STEEL_API_KEY`: used by `SteelBrowserInfrastructure()` when `api_key` is not passed.
|
|
100
|
+
2. `OBJECT_STORAGE_URL`: MinIO/S3 endpoint, for example `localhost:9001` or `https://storage.example`.
|
|
101
|
+
3. `OBJECT_STORAGE_USERNAME`: object storage access key.
|
|
102
|
+
4. `OBJECT_STORAGE_PASSWORD`: object storage secret key.
|
|
103
|
+
5. `OBJECT_STORAGE_BUCKET_NAME`: target bucket name.
|
|
104
|
+
6. `OBJECT_STORAGE_DIRECTORY_PREFIX`: optional object key prefix.
|
|
105
|
+
7. `OBJECT_STORAGE_SECURE`: `true` for HTTPS when the endpoint has no scheme.
|
|
106
|
+
|
|
107
|
+
Copy `.env.example` to `.env` for local development, then load it with your application environment manager.
|
|
108
|
+
|
|
109
|
+
## Runtime API
|
|
110
|
+
|
|
111
|
+
The client exposes three run methods:
|
|
112
|
+
|
|
113
|
+
1. `run(task)`: async generator that yields `BrowserUseStreamEvent` values as work progresses.
|
|
114
|
+
2. `run_once(task)`: async method that returns one `BrowserUseRunResult` and includes emitted events in `result.events`.
|
|
115
|
+
3. `run_sync(task)`: blocking wrapper around `run_once()` using `asyncio.run()`.
|
|
116
|
+
|
|
117
|
+
Do not call `run_sync()` from an already running event loop. Use `await run_once()` or `async for event in run()` in async applications.
|
|
118
|
+
|
|
119
|
+
Cancelling the stream by breaking from `async for` or calling `await stream.aclose()` cancels the underlying run task. Browser sessions and infrastructure sessions are released in cleanup.
|
|
120
|
+
|
|
121
|
+
## Result Contract
|
|
122
|
+
|
|
123
|
+
`BrowserUseRunResult` contains:
|
|
124
|
+
|
|
125
|
+
1. `status`: `success`, `error`, or `cancelled`.
|
|
126
|
+
2. `task`: normalized task string.
|
|
127
|
+
3. `final_output`: final text extracted from the underlying agent, or `Task completed` when no final text is available.
|
|
128
|
+
4. `session_id`: infrastructure session ID when an external browser session was used.
|
|
129
|
+
5. `streaming_url`: browser debug or streaming URL when available.
|
|
130
|
+
6. `recording_url`: expected recording URL when recording is configured.
|
|
131
|
+
7. `steps`: number of browser-use steps executed.
|
|
132
|
+
8. `error`: terminal error message for error results.
|
|
133
|
+
9. `events`: collected stream events for `run_once()`.
|
|
134
|
+
10. `metadata`: attempt, retry, and recording metadata.
|
|
135
|
+
|
|
136
|
+
Recording metadata uses these statuses:
|
|
137
|
+
|
|
138
|
+
1. `disabled`: infrastructure, storage, or browser context is not available.
|
|
139
|
+
2. `unsupported`: the selected infrastructure does not support recording.
|
|
140
|
+
3. `unavailable`: storage is configured but not available.
|
|
141
|
+
4. `scheduled`: a background recording upload has been scheduled.
|
|
142
|
+
5. `unknown`: recording may have started, but the terminal error did not include enough context to determine the final state.
|
|
143
|
+
|
|
144
|
+
## Streaming Contract
|
|
145
|
+
|
|
146
|
+
`BrowserUseStreamEvent` contains:
|
|
147
|
+
|
|
148
|
+
1. `event_type`
|
|
149
|
+
2. `content`
|
|
150
|
+
3. `thinking_and_activity_info`
|
|
151
|
+
4. `is_final`
|
|
152
|
+
5. `tool_info`
|
|
153
|
+
6. `metadata`
|
|
154
|
+
|
|
155
|
+
Important event content values:
|
|
156
|
+
|
|
157
|
+
1. `Receive streaming URL`: emitted when a browser debug or streaming URL is available.
|
|
158
|
+
2. `Receive recording URL`: emitted when a recording URL can be resolved.
|
|
159
|
+
3. `Task completed`: emitted for the final successful step.
|
|
160
|
+
|
|
161
|
+
Activity events encode iframe URLs in `thinking_and_activity_info["data_value"]` as a JSON string:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{"type": "iframe", "message": "<url>"}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Step events include serialized tool calls in `tool_info["tool_calls"]`.
|
|
168
|
+
|
|
169
|
+
## Retries And Errors
|
|
170
|
+
|
|
171
|
+
The client retries only classified recoverable browser-session failures, such as browser closure or websocket disconnect messages. Before each retry, it emits a retry status event. Retries are bounded by `max_session_retries`, so total attempts are `max_session_retries + 1`.
|
|
172
|
+
|
|
173
|
+
Non-recoverable task failures return `BrowserUseRunResult(status="error")`. Recoverable failures that exhaust all attempts raise `BrowserUseRetryExhaustedError`.
|
|
174
|
+
|
|
175
|
+
SDK error types:
|
|
176
|
+
|
|
177
|
+
1. `BrowserUseConfigurationError`: missing or invalid runtime configuration.
|
|
178
|
+
2. `BrowserUseDependencyError`: optional provider dependency problem.
|
|
179
|
+
3. `BrowserUseMissingDependencyError`: optional provider extra is not installed.
|
|
180
|
+
4. `BrowserUseExecutionError`: execution-time failure.
|
|
181
|
+
5. `BrowserUseRetryExhaustedError`: recoverable session retries were exhausted.
|
|
182
|
+
|
|
183
|
+
## Optional Providers
|
|
184
|
+
|
|
185
|
+
Optional providers are lazy-loaded. Importing `gl_browser_use` does not require Steel or MinIO to be installed.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from gl_browser_use.infrastructure import SteelBrowserInfrastructure
|
|
189
|
+
from gl_browser_use.storage import MinIOS3CompatibleStorage
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`SteelBrowserInfrastructure` creates Steel browser sessions and provides CDP/streaming URLs. `MinIOS3CompatibleStorage` uploads session recordings to MinIO or an S3-compatible service and returns presigned URLs.
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
From `libs/gl-browser-use`:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
make install-dev
|
|
200
|
+
make test-unit
|
|
201
|
+
make test-integration
|
|
202
|
+
make lint
|
|
203
|
+
make build-check
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Useful targets:
|
|
207
|
+
|
|
208
|
+
1. `make test`: run all tests.
|
|
209
|
+
2. `make test-unit`: run unit tests with coverage.
|
|
210
|
+
3. `make test-integration`: run integration-marked contract tests.
|
|
211
|
+
4. `make lint`: run Ruff checks.
|
|
212
|
+
5. `make format`: run Ruff fixes and formatter.
|
|
213
|
+
6. `make pre-commit`: run pre-commit hooks.
|
|
214
|
+
7. `make build-check`: build the package and validate artifacts with Twine.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""GL Browser Use SDK.
|
|
2
|
+
|
|
3
|
+
Public namespace for :class:`BrowserUseClient` and supporting models,
|
|
4
|
+
errors, infrastructure, and storage abstractions.
|
|
5
|
+
|
|
6
|
+
Authors:
|
|
7
|
+
Reinhart Linanda (reinhart.linanda@gdplabs.id)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from gl_browser_use.client import BrowserUseClient
|
|
13
|
+
from gl_browser_use.config import BrowserUseClientConfig
|
|
14
|
+
from gl_browser_use.errors import (
|
|
15
|
+
BrowserUseConfigurationError,
|
|
16
|
+
BrowserUseDependencyError,
|
|
17
|
+
BrowserUseExecutionError,
|
|
18
|
+
BrowserUseMissingDependencyError,
|
|
19
|
+
BrowserUseRetryExhaustedError,
|
|
20
|
+
BrowserUseSDKError,
|
|
21
|
+
)
|
|
22
|
+
from gl_browser_use.infrastructure import __getattr__ as _infrastructure_getattr
|
|
23
|
+
from gl_browser_use.infrastructure.base import BrowserInfrastructure, BrowserInfrastructureContext
|
|
24
|
+
from gl_browser_use.models import BrowserUseRunResult, BrowserUseStreamEvent
|
|
25
|
+
from gl_browser_use.storage import __getattr__ as _storage_getattr
|
|
26
|
+
from gl_browser_use.storage.base import ObjectStorage
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"BrowserUseClient",
|
|
30
|
+
"BrowserUseClientConfig",
|
|
31
|
+
"BrowserUseConfigurationError",
|
|
32
|
+
"BrowserUseDependencyError",
|
|
33
|
+
"BrowserUseExecutionError",
|
|
34
|
+
"BrowserUseMissingDependencyError",
|
|
35
|
+
"BrowserUseRetryExhaustedError",
|
|
36
|
+
"BrowserUseSDKError",
|
|
37
|
+
"BrowserUseRunResult",
|
|
38
|
+
"BrowserUseStreamEvent",
|
|
39
|
+
"BrowserInfrastructure",
|
|
40
|
+
"BrowserInfrastructureContext",
|
|
41
|
+
"SteelBrowserInfrastructure",
|
|
42
|
+
"ObjectStorage",
|
|
43
|
+
"MinIOS3CompatibleStorage",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def __getattr__(name: str):
|
|
48
|
+
"""Expose optional classes lazily to avoid import-time dependency failures."""
|
|
49
|
+
if name == "SteelBrowserInfrastructure":
|
|
50
|
+
return _infrastructure_getattr(name)
|
|
51
|
+
if name == "MinIOS3CompatibleStorage":
|
|
52
|
+
return _storage_getattr(name)
|
|
53
|
+
raise AttributeError(f"module 'gl_browser_use' has no attribute {name!r}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def __dir__() -> list[str]:
|
|
57
|
+
return sorted(__all__)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
__version__ = "0.1.0"
|