@b3os/cli 0.2.0 → 0.2.2
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.
- package/README.md +87 -7
- package/assets/b3os-run.py +137 -0
- package/assets/skill/b3os/SKILL.md +111 -0
- package/dist/commands/_agents.d.ts +14 -0
- package/dist/commands/_agents.js +33 -0
- package/dist/commands/_agents.js.map +1 -0
- package/dist/commands/_common.js +6 -2
- package/dist/commands/_common.js.map +1 -1
- package/dist/commands/_context.d.ts +49 -0
- package/dist/commands/_context.js +260 -0
- package/dist/commands/_context.js.map +1 -0
- package/dist/commands/_next.d.ts +39 -0
- package/dist/commands/_next.js +77 -0
- package/dist/commands/_next.js.map +1 -0
- package/dist/commands/agent.d.ts +42 -0
- package/dist/commands/agent.js +218 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/app.d.ts +2 -0
- package/dist/commands/app.js +559 -54
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/auth.d.ts +88 -2
- package/dist/commands/auth.js +354 -44
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/docs.d.ts +54 -0
- package/dist/commands/docs.js +202 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/commands/doctor.d.ts +23 -0
- package/dist/commands/doctor.js +313 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts +38 -1
- package/dist/commands/init.js +259 -60
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/listen.d.ts +30 -0
- package/dist/commands/listen.js +194 -0
- package/dist/commands/listen.js.map +1 -0
- package/dist/commands/manifest.d.ts +13 -1
- package/dist/commands/manifest.js +81 -18
- package/dist/commands/manifest.js.map +1 -1
- package/dist/commands/mcp.d.ts +25 -2
- package/dist/commands/mcp.js +120 -11
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/sandbox.d.ts +35 -6
- package/dist/commands/sandbox.js +208 -9
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/setup.d.ts +39 -0
- package/dist/commands/setup.js +203 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/tool.d.ts +154 -0
- package/dist/commands/tool.js +785 -0
- package/dist/commands/tool.js.map +1 -0
- package/dist/config.d.ts +30 -6
- package/dist/config.js +39 -8
- package/dist/config.js.map +1 -1
- package/dist/ctx.d.ts +5 -45
- package/dist/ctx.js +25 -160
- package/dist/ctx.js.map +1 -1
- package/dist/docs/index.json +1 -0
- package/dist/docs/pages/actions/call.md +300 -0
- package/dist/docs/pages/actions/catalog/airtable.md +737 -0
- package/dist/docs/pages/actions/catalog/arxiv.md +166 -0
- package/dist/docs/pages/actions/catalog/chainalysis-sanctions.md +125 -0
- package/dist/docs/pages/actions/catalog/coingecko.md +1558 -0
- package/dist/docs/pages/actions/catalog/deps-dev.md +465 -0
- package/dist/docs/pages/actions/catalog/dexscreener.md +568 -0
- package/dist/docs/pages/actions/catalog/discord.md +784 -0
- package/dist/docs/pages/actions/catalog/finnhub.md +776 -0
- package/dist/docs/pages/actions/catalog/frankfurter.md +438 -0
- package/dist/docs/pages/actions/catalog/github.md +1853 -0
- package/dist/docs/pages/actions/catalog/gmail.md +575 -0
- package/dist/docs/pages/actions/catalog/google-calendar.md +654 -0
- package/dist/docs/pages/actions/catalog/google-drive.md +502 -0
- package/dist/docs/pages/actions/catalog/google-sheets.md +700 -0
- package/dist/docs/pages/actions/catalog/hacker-news.md +542 -0
- package/dist/docs/pages/actions/catalog/http.md +824 -0
- package/dist/docs/pages/actions/catalog/hyperliquid.md +942 -0
- package/dist/docs/pages/actions/catalog/jira.md +920 -0
- package/dist/docs/pages/actions/catalog/kalshi.md +917 -0
- package/dist/docs/pages/actions/catalog/linear.md +1030 -0
- package/dist/docs/pages/actions/catalog/markets.md +21 -0
- package/dist/docs/pages/actions/catalog/morpho.md +247 -0
- package/dist/docs/pages/actions/catalog/notion.md +1077 -0
- package/dist/docs/pages/actions/catalog/nws.md +485 -0
- package/dist/docs/pages/actions/catalog/open-meteo.md +559 -0
- package/dist/docs/pages/actions/catalog/polymarket.md +1523 -0
- package/dist/docs/pages/actions/catalog/pushbullet.md +220 -0
- package/dist/docs/pages/actions/catalog/resend.md +307 -0
- package/dist/docs/pages/actions/catalog/s3.md +513 -0
- package/dist/docs/pages/actions/catalog/sec-edgar.md +487 -0
- package/dist/docs/pages/actions/catalog/slack.md +2629 -0
- package/dist/docs/pages/actions/catalog/stripe.md +1405 -0
- package/dist/docs/pages/actions/catalog/wikipedia.md +379 -0
- package/dist/docs/pages/actions/catalog.md +46 -0
- package/dist/docs/pages/actions/limits.md +50 -0
- package/dist/docs/pages/actions/model-tools.md +225 -0
- package/dist/docs/pages/actions/packs.md +148 -0
- package/dist/docs/pages/actions/settings.md +69 -0
- package/dist/docs/pages/actions/tools.md +244 -0
- package/dist/docs/pages/actions/triggers.md +149 -0
- package/dist/docs/pages/actions.md +88 -0
- package/dist/docs/pages/compat/anthropic.md +168 -0
- package/dist/docs/pages/compat/e2b.md +194 -0
- package/dist/docs/pages/compat/firecrawl.md +138 -0
- package/dist/docs/pages/compat/openai.md +168 -0
- package/dist/docs/pages/concepts/auth.md +151 -0
- package/dist/docs/pages/concepts/beta.md +55 -0
- package/dist/docs/pages/concepts/glossary.md +71 -0
- package/dist/docs/pages/concepts/ids.md +98 -0
- package/dist/docs/pages/concepts/jobs.md +229 -0
- package/dist/docs/pages/concepts/latency.md +138 -0
- package/dist/docs/pages/concepts/limits.md +191 -0
- package/dist/docs/pages/concepts/stack.md +59 -0
- package/dist/docs/pages/concepts/timing.md +86 -0
- package/dist/docs/pages/concepts/usage.md +110 -0
- package/dist/docs/pages/design/b3os-yaml.md +370 -0
- package/dist/docs/pages/design/deploy-from-github.md +122 -0
- package/dist/docs/pages/design/observability.md +134 -0
- package/dist/docs/pages/errors.md +1824 -0
- package/dist/docs/pages/infer/chat.md +570 -0
- package/dist/docs/pages/infer/limits.md +55 -0
- package/dist/docs/pages/infer/messages.md +185 -0
- package/dist/docs/pages/infer/responses.md +173 -0
- package/dist/docs/pages/infer/settings.md +154 -0
- package/dist/docs/pages/infer/speech.md +323 -0
- package/dist/docs/pages/infer.md +154 -0
- package/dist/docs/pages/introduction.md +162 -0
- package/dist/docs/pages/platform/addresses.md +174 -0
- package/dist/docs/pages/platform/call-log.md +99 -0
- package/dist/docs/pages/platform/custom-domains.md +104 -0
- package/dist/docs/pages/platform/keys.md +79 -0
- package/dist/docs/pages/platform/limits.md +57 -0
- package/dist/docs/pages/platform/members.md +101 -0
- package/dist/docs/pages/platform/requests.md +116 -0
- package/dist/docs/pages/platform/settings.md +129 -0
- package/dist/docs/pages/platform/webhooks.md +68 -0
- package/dist/docs/pages/platform.md +67 -0
- package/dist/docs/pages/quickstart/mcp.md +94 -0
- package/dist/docs/pages/quickstart/sandbox-agent.md +205 -0
- package/dist/docs/pages/quickstart/scrape.md +134 -0
- package/dist/docs/pages/quickstart.md +45 -0
- package/dist/docs/pages/render/inspections.md +162 -0
- package/dist/docs/pages/render/limits.md +72 -0
- package/dist/docs/pages/render/screenshots.md +179 -0
- package/dist/docs/pages/render/settings.md +431 -0
- package/dist/docs/pages/render/styles.md +342 -0
- package/dist/docs/pages/render/videos.md +272 -0
- package/dist/docs/pages/render.md +118 -0
- package/dist/docs/pages/routines/callables.md +174 -0
- package/dist/docs/pages/routines/definitions.md +361 -0
- package/dist/docs/pages/routines/limits.md +117 -0
- package/dist/docs/pages/routines/runs.md +328 -0
- package/dist/docs/pages/routines/settings.md +104 -0
- package/dist/docs/pages/routines/triggers.md +339 -0
- package/dist/docs/pages/routines.md +216 -0
- package/dist/docs/pages/sandboxes/agents.md +217 -0
- package/dist/docs/pages/sandboxes/commands.md +272 -0
- package/dist/docs/pages/sandboxes/images.md +166 -0
- package/dist/docs/pages/sandboxes/limits.md +143 -0
- package/dist/docs/pages/sandboxes/ports.md +260 -0
- package/dist/docs/pages/sandboxes/settings.md +358 -0
- package/dist/docs/pages/sandboxes/snapshots.md +423 -0
- package/dist/docs/pages/sandboxes/swarms.md +146 -0
- package/dist/docs/pages/sandboxes/volumes.md +131 -0
- package/dist/docs/pages/sandboxes.md +231 -0
- package/dist/docs/pages/sdks/cli.md +121 -0
- package/dist/docs/pages/sdks/mcp.md +169 -0
- package/dist/docs/pages/sdks/python.md +146 -0
- package/dist/docs/pages/sdks/typescript.md +202 -0
- package/dist/docs/pages/sdks.md +282 -0
- package/dist/docs/pages/settings.md +33 -0
- package/dist/docs/pages/vault/limits.md +46 -0
- package/dist/docs/pages/vault.md +133 -0
- package/dist/docs/pages/vision/agent-browser.md +115 -0
- package/dist/docs/pages/vision/crawl.md +333 -0
- package/dist/docs/pages/vision/extract.md +152 -0
- package/dist/docs/pages/vision/fetcher.md +15 -0
- package/dist/docs/pages/vision/limits.md +79 -0
- package/dist/docs/pages/vision/profiles.md +111 -0
- package/dist/docs/pages/vision/proxy.md +131 -0
- package/dist/docs/pages/vision/scrape.md +356 -0
- package/dist/docs/pages/vision/sessions.md +311 -0
- package/dist/docs/pages/vision/settings.md +656 -0
- package/dist/docs/pages/vision.md +175 -0
- package/dist/errors.d.ts +129 -0
- package/dist/errors.js +326 -0
- package/dist/errors.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +26 -13
- package/dist/main.js.map +1 -1
- package/dist/manifest/apply.d.ts +4 -0
- package/dist/manifest/apply.js +2 -0
- package/dist/manifest/apply.js.map +1 -1
- package/dist/manifest/domains.d.ts +50 -0
- package/dist/manifest/domains.js +159 -0
- package/dist/manifest/domains.js.map +1 -0
- package/dist/manifest/link.d.ts +20 -0
- package/dist/manifest/link.js +24 -0
- package/dist/manifest/link.js.map +1 -0
- package/dist/manifest/record.d.ts +1 -1
- package/dist/tool/archive.d.ts +33 -0
- package/dist/tool/archive.js +174 -0
- package/dist/tool/archive.js.map +1 -0
- package/dist/tool/calls.d.ts +46 -0
- package/dist/tool/calls.js +274 -0
- package/dist/tool/calls.js.map +1 -0
- package/dist/tool/checks.d.ts +21 -0
- package/dist/tool/checks.js +145 -0
- package/dist/tool/checks.js.map +1 -0
- package/dist/tool/elf.d.ts +19 -0
- package/dist/tool/elf.js +107 -0
- package/dist/tool/elf.js.map +1 -0
- package/dist/tool/predict.d.ts +8 -0
- package/dist/tool/predict.js +38 -0
- package/dist/tool/predict.js.map +1 -0
- package/dist/tool/ustar.d.ts +5 -0
- package/dist/tool/ustar.js +220 -0
- package/dist/tool/ustar.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# Scrape a page
|
|
2
|
+
|
|
3
|
+
> Fetch one URL as Markdown, HTML, text, links, metadata or a screenshot, with main-content extraction, browser actions, profiles and caching.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/vision/scrape.md
|
|
6
|
+
|
|
7
|
+
`POST /v1/vision/scrape` fetches one URL and returns the formats you ask for. It is synchronous: the response arrives when the page is done, within `timeout_ms` (30 seconds by default, 60 at most).
|
|
8
|
+
|
|
9
|
+
## Scrape one page
|
|
10
|
+
|
|
11
|
+
**curl**
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
curl -s https://beta-api.b3os.org/v1/vision/scrape \
|
|
15
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
16
|
+
-H "Content-Type: application/json" \
|
|
17
|
+
-d '{"url": "https://example.com", "formats": ["markdown", "links"]}'
|
|
18
|
+
```
|
|
19
|
+
**TypeScript**
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { B3OS } from "@b3os/sdk";
|
|
23
|
+
|
|
24
|
+
const b3os = new B3OS(); // reads B3OS_API_KEY
|
|
25
|
+
const page = await b3os.vision.scrape({
|
|
26
|
+
url: "https://example.com",
|
|
27
|
+
formats: ["markdown", "links"],
|
|
28
|
+
});
|
|
29
|
+
console.log(page.tier, page.cache.state);
|
|
30
|
+
console.log(page.markdown);
|
|
31
|
+
```
|
|
32
|
+
**Python**
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from b3os import B3OS
|
|
36
|
+
|
|
37
|
+
b3os = B3OS() # reads B3OS_API_KEY
|
|
38
|
+
page = b3os.vision.scrape({"url": "https://example.com", "formats": ["markdown", "links"]})
|
|
39
|
+
print(page["tier"], page["cache"]["state"])
|
|
40
|
+
print(page["markdown"])
|
|
41
|
+
```
|
|
42
|
+
**MCP**
|
|
43
|
+
|
|
44
|
+
With the [B3OS MCP server](https://docs.beta.b3os.org/sdks/mcp) connected, ask your agent:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
Scrape https://example.com and give me the page as Markdown, plus its links.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The agent calls the `vision_scrape` tool with `url` and `formats`, the same fields as the API body.
|
|
51
|
+
|
|
52
|
+
The response holds each format you asked for, plus what served the page and how long it took:
|
|
53
|
+
|
|
54
|
+
| Field | Meaning |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `url`, `final_url` | The URL you asked for, and the URL of the page the answer was read from: the URL after redirects or, for a page the browser rendered, the page the browser read. When a script moved the browser to another host or path after the load, or changed the address to another path with `history.pushState` or `replaceState`, `final_url` is that address (an http or https one). A change of query or fragment alone after the load leaves it at the URL after redirects. |
|
|
57
|
+
| `status_code` | The site's HTTP status. A 404 page is still a successful scrape. For a page the browser rendered, it is the status the browser got when it loaded the page, so when a script moved the browser to another page after the load (see `final_url`), it can be the status of the page before the move. |
|
|
58
|
+
| `tier` | `cache`, `fetch` or `browser` |
|
|
59
|
+
| `cache` | `state` (`hit`, `miss` or `bypass`) and `age_s` |
|
|
60
|
+
| `markdown`, `html`, `raw_html`, `text`, `links`, `screenshot`, `json` | The formats you asked for |
|
|
61
|
+
| `metadata` | Title, description, language, canonical URL, favicon, Open Graph fields, dates and the robots meta tag; always included |
|
|
62
|
+
| `warnings` | Problems that did not stop the scrape, such as a format that could not be produced |
|
|
63
|
+
| `timing` | Server-side phase durations in milliseconds |
|
|
64
|
+
|
|
65
|
+
## Formats
|
|
66
|
+
|
|
67
|
+
| Format | What you get |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `markdown` | The main content as Markdown (the default) |
|
|
70
|
+
| `html` | Cleaned HTML |
|
|
71
|
+
| `raw_html` | The HTML as the site sent it |
|
|
72
|
+
| `text` | Plain text |
|
|
73
|
+
| `links` | Every link on the page, as absolute URLs |
|
|
74
|
+
| `metadata` | Always included; listed for compatibility |
|
|
75
|
+
| `screenshot` | An image of the page; needs the browser tier. `screenshot: {"full_page": true}` captures the whole page up to 16,384 px tall and wide (the screenshot limit); a larger page is cut there and `warnings` starts with `screenshot_truncated:` and gives its real size |
|
|
76
|
+
| `json` | Data shaped by your JSON Schema in `json.schema`, filled in by the model on the node |
|
|
77
|
+
|
|
78
|
+
Markdown keeps what an agent reads code and data from: every `<pre>` is a fenced code block, tagged with its language when the page's classes name one, and tables keep row headers in their row, one space either side of each cell and no column padding. Layout tables (no header cells) come back as text. An underscore inside a word stays as it is (`DEFAULT_DOT_MAX`, `snake_case`), since it cannot start emphasis there; one next to a space or punctuation is escaped (`\_`).
|
|
79
|
+
|
|
80
|
+
## What comes back
|
|
81
|
+
|
|
82
|
+
A scrape of a documentation page with formats `markdown` and `screenshot`, as recorded. The page is a pinned copy of this one, with a header, two sidebars, tabbed code samples, a lazily loaded diagram and a table:
|
|
83
|
+
|
|
84
|
+
**Response 200**
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"object": "scrape",
|
|
89
|
+
"url": "https://beta.b3os.org/fixtures/vision/docs-page.html",
|
|
90
|
+
"final_url": "https://beta.b3os.org/fixtures/vision/docs-page",
|
|
91
|
+
"status_code": 200,
|
|
92
|
+
"content_type": "text/html",
|
|
93
|
+
"tier": "browser",
|
|
94
|
+
"cache": {
|
|
95
|
+
"state": "miss",
|
|
96
|
+
"age_s": 0
|
|
97
|
+
},
|
|
98
|
+
"markdown": "# Scrape a page\n\nFetch one URL and get it back as Markdown, HTML, text, links, metadata or a screenshot, in one synchronous call.\n\n## Scrape one page\n\nSend the URL and the formats you want. The response arrives when the page is done, within `timeout_ms` (30 seconds by default).\n\n```shell\ncurl -s https://beta-api.b3os.org/v1/vision/scrape \\\n -H \"Authorization: Bearer $B3OS_API_KEY\" \\\n -H \"Content…",
|
|
99
|
+
"screenshot": {
|
|
100
|
+
"format": "jpeg",
|
|
101
|
+
"width": 1280,
|
|
102
|
+
"height": 800,
|
|
103
|
+
"data_base64": "https://beta.b3os.org/gallery/vision/scrape-docs-fixture/c2984e3a80f92ba1.jpg"
|
|
104
|
+
},
|
|
105
|
+
"metadata": {
|
|
106
|
+
"title": "Scrape a page · B3OS docs",
|
|
107
|
+
"description": "Fetch one URL as Markdown, HTML, text, links, metadata or a screenshot.",
|
|
108
|
+
"language": "en",
|
|
109
|
+
"canonical_url": "https://docs.beta.b3os.org/vision/scrape",
|
|
110
|
+
"robots": "noindex"
|
|
111
|
+
},
|
|
112
|
+
"page_state": {
|
|
113
|
+
"state": "ok"
|
|
114
|
+
},
|
|
115
|
+
"warnings": [],
|
|
116
|
+
"timing": {
|
|
117
|
+
"acquire_ms": 0.01,
|
|
118
|
+
"admit_ms": 0.084,
|
|
119
|
+
"claim_ms": 0.007,
|
|
120
|
+
"extract_ms": 2.255,
|
|
121
|
+
"nav_dcl_ms": 105.8,
|
|
122
|
+
"nav_load_ms": 137.245,
|
|
123
|
+
"nav_response_ms": 54.109,
|
|
124
|
+
"navigate_ms": 238.051,
|
|
125
|
+
"queue_ms": 0.001,
|
|
126
|
+
"read_ms": 6.235,
|
|
127
|
+
"screenshot_ms": 27.993,
|
|
128
|
+
"setup_ms": 1.594,
|
|
129
|
+
"total_ms": 276.564
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Request**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
curl -s -X POST 'https://beta-api.b3os.org/v1/vision/scrape' \
|
|
138
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
139
|
+
-H 'Content-Type: application/json' \
|
|
140
|
+
-d '{"url":"https://beta.b3os.org/fixtures/vision/docs-page.html","formats":["markdown","screenshot"],"max_age_ms":0}'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Server-Timing**
|
|
144
|
+
|
|
145
|
+
```http
|
|
146
|
+
server-timing: edge_auth;dur=0.000, edge_upstream;dur=287.000, admit;dur=0.084, queue;dur=0.001, claim;dur=0.007, acquire;dur=0.010, setup;dur=1.594, navigate;dur=238.051, nav_response;dur=54.109, nav_dcl;dur=105.800, nav_load;dur=137.245, read;dur=6.235, screenshot;dur=27.993, extract;dur=2.255, total;dur=276.697
|
|
147
|
+
x-request-id: req_01m6y0bb7pw8xtt660bhn07nbx
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
<img src="https://beta.b3os.org/gallery/vision/scrape-docs-fixture/c2984e3a80f92ba1.jpg" alt="The jpeg the call returned (vision/scrape-docs-fixture)" width="1280" height="800" loading="lazy" />
|
|
151
|
+
|
|
152
|
+
<sub>Captured 2026-11-08 from commit `48c174d9` on the host the node runs on (colo PDX), warm: median of 5 calls after 3 warm-up calls, label `fixture` (recorded against a pinned fixture); long values abridged. Case `vision/scrape-docs-fixture`.</sub>
|
|
153
|
+
|
|
154
|
+
## Main content only
|
|
155
|
+
|
|
156
|
+
By default vision drops headers, navigation, footers, sidebars, skip links, language menus and lazy-load placeholder images (`only_main_content: true`). When what is left is short (under 1,000 characters of text) and under a quarter of the page's text, the content was most likely inside something that looked like a sidebar, so vision returns the whole page instead and `warnings` says so. Turn it off to keep the whole page, or steer it with CSS selectors:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"url": "https://docs.example.com/guides/keys",
|
|
161
|
+
"formats": ["markdown"],
|
|
162
|
+
"include_tags": ["main", "article"],
|
|
163
|
+
"exclude_tags": [".cookie-banner", "#feedback"]
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`include_tags` keeps only matching elements; `exclude_tags` drops matching ones. Up to 100 selectors each.
|
|
168
|
+
|
|
169
|
+
## Choose the engine
|
|
170
|
+
|
|
171
|
+
| `engine` | Behavior |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `auto` (default) | Cache, then a plain fetch, then a browser when the page needs JavaScript, when the fetch came back thin, or when the fetch failed in a way a browser may not |
|
|
174
|
+
| `fetch` | Never starts a browser. Use it for pages rendered on the server. |
|
|
175
|
+
| `browser` | Always renders in Chrome. Implied by `actions`, `screenshot` and `profile`. |
|
|
176
|
+
|
|
177
|
+
Either tier can leave through your own proxy, or read the page from a residential address, when the request sets `proxy`: see [Proxies](https://docs.beta.b3os.org/vision/proxy).
|
|
178
|
+
|
|
179
|
+
With `auto`, the browser tier runs after the fetch in three cases. `warnings` names the case, except for an app shell, a challenge or a block page, which render with no warning that says why:
|
|
180
|
+
|
|
181
|
+
- **The page needs JavaScript.** The fetched HTML is an app shell, a challenge or block page, or a page that comes out empty.
|
|
182
|
+
- **The fetch came back thin.** Under 500 characters of text (link targets and images not counted), or a page that is mostly script: under 2,000 bytes of page text, with over a third of its HTML inline script, whatever the length of the Markdown. If the node's browser tier is up and at least 5 seconds of `timeout_ms` are left after the fetch, Vision renders the page as well and returns whichever answer has more text, so a short page that really is short still comes back from the fetch. With less time left you get the fetch's answer and no render, and while the host is paused after a 429 or 503 answer, the fetch's answer comes back unrendered with a warning that says so. The fetch's answer also stands when the browser's is a wall or an error page the fetch was not. And when the fetch has 500 or more characters of text and the page the browser read is a different page, you get the fetch's answer and that answer is the one cached. A different page is another host or path, a same-site locale path included, or one where a query parameter of the URL you asked for, kept by the fetch, has another value or is gone (`?id=1` to `?page=chooser`). A parameter the browser's page adds does not count. When the browser's page would otherwise have won (more text, and not a wall or an error page the fetch was not), `warnings` says where the browser went, with any query shown as `?...`. Otherwise `warnings` says the browser's was no richer and does not name the page. That covers a script that redirects to a country chooser during the load or before the page is read (a timer that fires within `wait_for_ms`), and one that changes the address to another path with `history.replaceState`. A change to the fragment alone (`#...`, as a hash route makes) does not count as a different page, and neither does a change to the query alone that a script makes after the load. Such a page takes the time of a render as well as the fetch. Tested in crates/b3os-vision/tests/e2e.rs.
|
|
183
|
+
- **The fetch failed in a way a browser may not.** A TLS handshake, a connection, an HTTP/2 stream error, a redirect loop, or a fetch timeout with at least 5 seconds of `timeout_ms` left. If the browser fails too, you get the fetch's error (Chrome's certificate error, for TLS). A name that does not resolve, a refused destination and a PDF are not retried.
|
|
184
|
+
|
|
185
|
+
One case skips the fetch. Once at least two of your organization's recent pages on a host needed a browser, and at least two thirds of its pages there did, its `auto` scrapes of that host go straight to the browser for up to an hour, with no warning about it. Those scrapes have no fetch answer to fall back on, so the different-page rule above does not apply to them: you get the page the browser read, and `final_url` names it as the `final_url` row above describes (a script that changes only the query or the fragment after the load leaves `final_url` at the document's URL). A page the fetch found thin does not count as needing a browser when its render ended on a different page. Tested in crates/b3os-vision/tests/e2e.rs.
|
|
186
|
+
|
|
187
|
+
A rendered page is read once it is ready: after `load`, when its network has been quiet for a moment. A page that is still drawing then gets up to 5 more seconds, within `timeout_ms` and leaving 2 seconds to read it: one whose document was still loading (as when a script sent the browser to another page after `load`) with under 1,000,000 characters of text so far, or one with under 300 characters of text that shows a progress bar, a region marked busy, a spinner, loader or skeleton, or an app root with no text yet. A progress bar, region, spinner, loader or skeleton the page does not show (hidden with `display: none`, `visibility: hidden` or `opacity: 0`) does not count. Vision reads it again once it has 300 characters of text or no such sign, and its elements have stopped changing, and answers with the second read when it has more text, however much the first read had. That answer carries the status and URL of the page it read, so when a script sent the browser to another page, before the first read or during the wait, you get that page's. When a script sends the browser during the wait to a page that answers an error status and the page read first did not, the first read stands. A page that never draws is answered as it was after the 5 seconds, usually with `page_state` `loading`. A challenge the browser is passing is not waited out this way, and neither is a request with `actions` or `wait_for_ms`, which says itself when to read. Anubis's proof-of-work page is one when an element on it loads from Anubis's path (`/.within.website/x/cmd/anubis/`), not when a page only links to that path or names it. Tested in crates/b3os-vision/tests/e2e.rs.
|
|
188
|
+
|
|
189
|
+
A page's Markdown can still come back empty: `engine: "fetch"` never renders, and a browser can find nothing either. The scrape succeeds with an empty `markdown` and bills as a page, and `warnings` holds `empty_page: the page came back with no text in its Markdown (status <code>, page_state <state>)`. `page_state` can be `ok` on such a page, so check `warnings` or the Markdown. With `engine: "fetch"` the warning adds that `auto` or `browser` may get more. Markdown that holds only an image or a link is not empty and gets no such warning. A wall whose content is withheld says that instead, and a scrape that does not ask for Markdown gets no such warning. Tested by `an_empty_page_says_so_and_bills_as_a_page` (crates/b3os-vision/tests/e2e_search.rs).
|
|
190
|
+
|
|
191
|
+
`browser` picks which browser the browser tier runs: `headless-shell` (the default, chrome-headless-shell from the scrape pool) or `chrome` (full Chrome, which also has `window.chrome` and plugins). A `chrome` page renders in a browser of its own that counts toward `vision.sessions.concurrent` while it runs, like a page that loads a profile. A page in a browser of its own has WebGL (on SwiftShader); a page in the scrape pool has none, since a pool browser renders pages of several organizations at once. `browser` with `engine: fetch` is a 400. Tested by `browser_engine_is_selectable` (crates/b3os-vision/tests/e2e_policy.rs).
|
|
192
|
+
|
|
193
|
+
With the browser tier you can also set `wait_for_ms` (extra settle time after the page is ready, up to 30 seconds), `viewport`, `mobile: true` to emulate a phone, `locale` and `timezone`. Without them a page presents the node's egress location: `en-US` and `America/Los_Angeles` (tested by `timezone_and_locale_follow_egress`). `block_ads` (on by default) blocks ads, trackers and cookie banners, and `block_resources` lists resource types not to download: images, media and fonts by default unless you ask for a screenshot. [Vision settings](https://docs.beta.b3os.org/vision/settings) gives each one's default, values and an example.
|
|
194
|
+
|
|
195
|
+
## Act before you capture
|
|
196
|
+
|
|
197
|
+
`actions` runs browser actions before the page is captured, up to 50 of them. Use them to dismiss a dialog, switch a tab or wait for content:
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"url": "https://beta.b3os.org/demo/billing/",
|
|
202
|
+
"formats": ["markdown", "screenshot"],
|
|
203
|
+
"actions": [
|
|
204
|
+
{ "kind": "click", "target": { "role": "button", "name": "Annual" } },
|
|
205
|
+
{ "kind": "wait", "for": { "text": "billed yearly" } }
|
|
206
|
+
],
|
|
207
|
+
"screenshot": { "format": "jpeg", "quality": 80 }
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
A target finds its element by CSS `selector`, visible `text` (a case-insensitive substring unless `exact`), or ARIA `role` plus accessible `name`, optionally `within` a scope and picking the `nth` match. If no element matches in time, the scrape fails with [`target_not_found`](https://docs.beta.b3os.org/errors#target_not_found). The action kinds are listed on [browser sessions](https://docs.beta.b3os.org/vision/sessions#browser-actions); scrapes accept all of them.
|
|
212
|
+
|
|
213
|
+
## Use a profile
|
|
214
|
+
|
|
215
|
+
Pass a profile ID or name to load its cookies and storage before navigating, so the scrape sees the page as a signed-in user:
|
|
216
|
+
|
|
217
|
+
```json
|
|
218
|
+
{ "url": "https://beta.b3os.org/demo/", "profile": "demo-signed-in", "formats": ["markdown"] }
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
With the `demo-signed-in` profile from [profiles](https://docs.beta.b3os.org/vision/profiles#create-one-from-playwright), the demo app's board renders signed in, with a "Signed in" label next to its Sign out button.
|
|
222
|
+
|
|
223
|
+
A profile implies the browser tier and keeps the result out of the cache. The page renders in a browser of its own, never one shared with another organization, which counts toward your `vision.sessions.concurrent` limit while it runs. A profile that does not exist fails with [`profile_not_found`](https://docs.beta.b3os.org/errors#profile_not_found). See [profiles](https://docs.beta.b3os.org/vision/profiles).
|
|
224
|
+
|
|
225
|
+
## The cache
|
|
226
|
+
|
|
227
|
+
| Field | Default | Effect |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| `max_age_ms` | 172800000 (two days) | Accept a cached copy up to this old. `0` always fetches. |
|
|
230
|
+
| `store_in_cache` | `true` | Store this result for later scrapes |
|
|
231
|
+
| `headers` | none | Extra request headers. Any custom header keeps the result out of the shared cache. In a browser, a `Cookie` header becomes cookies for the page's own host (path `/`), so it reaches the site as it would on a plain fetch and is not sent to the other hosts the page loads from. |
|
|
232
|
+
|
|
233
|
+
Results of requests with custom headers, a profile or actions are never shared with other organizations.
|
|
234
|
+
|
|
235
|
+
### Cache only
|
|
236
|
+
|
|
237
|
+
`cache_only: true` answers from the cache and never contacts the target: you get a cached copy (within `max_age_ms` when you set it) or [`scrape_no_cached_data`](https://docs.beta.b3os.org/errors#scrape_no_cached_data) (`404`, not billed). It cannot be combined with `headers`, `profile`, `actions` or a screenshot, which never use the cache. The Firecrawl surface's `lockdown` works the same way, and a miss there is `scrape_lockdown_cache_miss`. Tested in crates/b3os-vision/tests/e2e_policy.rs.
|
|
238
|
+
|
|
239
|
+
## Page state
|
|
240
|
+
|
|
241
|
+
Every result has `page_state`: what kind of page came back, judged from the HTML, the status and the amount of text, with no model call. The judgement is a heuristic; when the signals are unclear the state is `ok`.
|
|
242
|
+
|
|
243
|
+
| `state` | Means | `signal` examples |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| `ok` | The page | none |
|
|
246
|
+
| `blocked` | A bot-management interstitial or refusal | `status_403`, `status_429`, `access_denied`, `challenge`, `cloudflare_block`, `cloudflare_challenge`, `kasada` |
|
|
247
|
+
| `captcha` | A challenge for a person | `recaptcha`, `hcaptcha`, `turnstile`, `datadome` |
|
|
248
|
+
| `cookie_wall` | Consent before content | the consent manager found, or `consent_title` |
|
|
249
|
+
| `login` | A sign-in form instead of content | `password_form` |
|
|
250
|
+
| `error` | An error status, or a page whose title says it is missing | `status`, `title` |
|
|
251
|
+
| `loading` | An unfinished shell | `empty_spa_root`, `loading_text` |
|
|
252
|
+
|
|
253
|
+
Tested by `page_state_in_scrape_results` and `words_in_the_url_do_not_make_a_wall` (crates/b3os-vision/tests/e2e_policy.rs). Vision does not solve challenges: a blocked page is reported as such.
|
|
254
|
+
|
|
255
|
+
### Walls are free
|
|
256
|
+
|
|
257
|
+
`blocked` and `captcha` are walls. A wall's scrape is free and carries no page content: `content_withheld: true`, with only `page_state`, `status_code` and `final_url`, and a warning that says so. Set `walls: "bill"` to get its content as a billed page. A scrape whose `actions` ran bills and keeps everything whatever the page is. Batches, crawls and maps follow the same rule. Tested in crates/b3os-vision/tests/e2e_policy.rs.
|
|
258
|
+
|
|
259
|
+
## Prepare a scrape
|
|
260
|
+
|
|
261
|
+
`POST /v1/vision/prepare` with a `url` warms what a scrape of it will need, so it is off the scrape's critical path: the destination is resolved and checked by the egress guard, and a keep-alive connection to the origin is opened (with a `HEAD` carrying the headers the scrape will send) for the scrape to reuse. It bills nothing and sends the target at most one `HEAD` per origin per minute for your organization. With `respect_robots: true` it fetches robots.txt instead and says whether the URL is allowed. Routines call it for the next step while the current one runs. Tested in crates/b3os-vision/tests/e2e_policy.rs.
|
|
262
|
+
|
|
263
|
+
## Read a PDF
|
|
264
|
+
|
|
265
|
+
A URL that serves a PDF comes back as Markdown, read from the PDF's text layer by the fetch tier, never in a browser. Vision takes a response for a PDF when its type says so (`application/pdf`), or when it has no type or `application/octet-stream` and starts with `%PDF-`. The Markdown has the text in reading order (a two-column page left column first), headings from the PDF's outline or else its font sizes, lists, tables where the columns line up, and links. Running headers, footers and page numbers are dropped with `only_main_content` (the default) on documents of 3 or more pages. Pages are joined by Firecrawl's page marker:
|
|
266
|
+
|
|
267
|
+
```markdown
|
|
268
|
+
# Attention Is All You Need
|
|
269
|
+
|
|
270
|
+
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks...
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
<!-- page 2 -->
|
|
275
|
+
|
|
276
|
+
## 1 Introduction
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The `pdf` option tunes it:
|
|
280
|
+
|
|
281
|
+
```json
|
|
282
|
+
{
|
|
283
|
+
"url": "https://arxiv.org/pdf/1706.03762",
|
|
284
|
+
"formats": ["markdown"],
|
|
285
|
+
"pdf": { "max_pages": 20, "page_markers": true, "pages": false }
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
| Field | Default | Meaning |
|
|
290
|
+
|---|---|---|
|
|
291
|
+
| `pdf.mode` | `text` | `text` reads the text layer; `off` answers a PDF with `422 content_type_unsupported`, as before PDFs were read |
|
|
292
|
+
| `pdf.max_pages` | 500 | Read at most this many pages, from the first. Above the node's cap (`vision.pdf.pages_max`, 500) it answers `422 limit_exceeded` |
|
|
293
|
+
| `pdf.page_markers` | `true` | Join pages with the marker above; `false` joins them with a blank line |
|
|
294
|
+
| `pdf.pages` | `false` | Also return each page's Markdown in `pdf.page_markdown` |
|
|
295
|
+
|
|
296
|
+
The answer carries `pdf`: `pages` (in the file), `pages_read`, `pages_billed`, `truncated` (`null`, or why fewer pages were read: `max_pages`, `max_chars`, `deadline` or `allowance`, each with a warning), the document's `title`, `author`, `subject`, `keywords`, `creator`, `producer`, `created_at` and `modified_at` when it has them, `tagged`, and `no_text_pages`. `metadata.title` is the PDF's title (unless it is a file name), else its first heading; `content_type` is `application/pdf` and `tier` is `fetch`. `markdown`, `text`, `html` (rendered from the same blocks) and `links` (the PDF's link annotations) are produced; `json` reads the Markdown as for any page. `raw_html` and screenshots are not, and `include_tags` and `exclude_tags` do not apply; each says so in a warning.
|
|
297
|
+
|
|
298
|
+
Limits and billing:
|
|
299
|
+
|
|
300
|
+
- A PDF may be up to 50 MiB (`vision.pdf.bytes_max`; other bodies stop at 20 MiB). A larger one answers `502 upstream_too_large` and bills nothing.
|
|
301
|
+
- Reading stops after 2,000,000 characters or at a page too dense to pass on whole, which is cut there (`truncated: max_chars`), or after 30 seconds (`truncated: deadline`, with the pages read by then; none read answers `504 scrape_timeout`).
|
|
302
|
+
- It bills one `vision.page` per page read, in one usage record, so a 300-page report uses 300 pages of your monthly allowance. When the allowance runs out partway, the pages up to it are read and billed (`truncated: allowance`). A PDF that cannot be read bills nothing.
|
|
303
|
+
- PDFs are not cached (`cache.state: bypass`): every scrape reads, and bills, the file again.
|
|
304
|
+
|
|
305
|
+
Batches bill each PDF by its pages read, and crawls follow links to PDFs unless their page options set `pdf.mode: off` (a PDF's own links are not followed). A scrape with `engine: "browser"` that lands on a PDF reads it through the fetch tier instead, with a warning; with a `profile` or `actions` it answers `422 content_type_unsupported`, because the profile's cookies and the actions do not reach the fetch tier yet.
|
|
306
|
+
|
|
307
|
+
Not done yet: pages without a text layer (scans) come back empty with the warning `pdf: page N has no text layer (scanned); OCR is not available yet`, and pages whose fonts have no Unicode map get a warning that their text could not be decoded. Each PDF is read by a helper process of its own with no network and no file access, under memory and CPU limits.
|
|
308
|
+
|
|
309
|
+
## Structured data
|
|
310
|
+
|
|
311
|
+
The `json` format asks the model on the node to fill a JSON Schema from the page:
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"url": "https://example.com/pricing",
|
|
316
|
+
"formats": ["json"],
|
|
317
|
+
"json": {
|
|
318
|
+
"schema": {
|
|
319
|
+
"type": "object",
|
|
320
|
+
"properties": { "plans": { "type": "array", "items": { "type": "string" } } },
|
|
321
|
+
"required": ["plans"]
|
|
322
|
+
},
|
|
323
|
+
"prompt": "The name of each plan."
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
The result is in `json`. The model call runs as you, through [infer](https://docs.beta.b3os.org/infer): it needs the `infer:run` scope (without it the scrape answers `403` before any work), it counts against your organization's per-minute token limit, and its tokens are billed as `infer.input_tokens` and `infer.output_tokens` beside the page. When infer refuses the call for your limits (`429`, `402`), the scrape answers that error and the page is not billed; if the model is unavailable, the page comes back without `json` and with a warning. A wall whose content is withheld gets no model call. The same holds for batch and crawl pages with the `json` format and for the Firecrawl surface's `json` format. Tested by `json_goes_through_infer_as_the_caller` (crates/b3os-vision/tests/e2e.rs). To fill one schema from up to 10 pages as one job, validated against the schema, see [extract](https://docs.beta.b3os.org/vision/extract).
|
|
329
|
+
|
|
330
|
+
## One-line reads
|
|
331
|
+
|
|
332
|
+
For a quick read from a shell or a prompt, put the URL after `/v1/vision/r/`, unencoded. The answer is the page itself, Markdown by default:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
curl -s "https://beta-api.b3os.org/v1/vision/r/https://example.com/pricing?plan=team" \
|
|
336
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
337
|
+
-H "X-B3OS-Engine: fetch"
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The target keeps its own path and query (`?plan=team` here belongs to example.com). It returns `text/markdown` by default. Options go in headers so the target URL stays untouched: `X-B3OS-Format` (`markdown`, `html`, `text` or `json`), `X-B3OS-Engine`, `X-B3OS-Timeout-Ms`, `X-B3OS-Max-Age-Ms`, `X-B3OS-Only-Main-Content` and `X-B3OS-Wait-For-Ms`. It uses the same tiers, cache and billing as a scrape.
|
|
341
|
+
|
|
342
|
+
## When it fails
|
|
343
|
+
|
|
344
|
+
| Code | Status | Meaning |
|
|
345
|
+
|---|---|---|
|
|
346
|
+
| [`scrape_timeout`](https://docs.beta.b3os.org/errors#scrape_timeout) | 504 | The page did not load and convert within `timeout_ms`. Raise it, or use `engine: "fetch"`. |
|
|
347
|
+
| [`navigation_failed`](https://docs.beta.b3os.org/errors#navigation_failed) | 502 | The browser could not load the page; `reason` carries the browser's error. |
|
|
348
|
+
| [`robots_disallowed`](https://docs.beta.b3os.org/errors#robots_disallowed) | 403 | robots.txt or Content Signals disallow the URL. |
|
|
349
|
+
| [`content_type_unsupported`](https://docs.beta.b3os.org/errors#content_type_unsupported) | 422 | The URL returned something vision can't convert, such as a video, an image or an archive; `reason` names its type. [PDFs are read](#read-a-pdf) unless `pdf.mode` is `off`. |
|
|
350
|
+
| [`pdf_unreadable`](https://docs.beta.b3os.org/errors#pdf_unreadable) | 422 | The URL served a PDF that could not be read; `reason` is `damaged`, `unsupported`, `too_complex` or `helper_crashed`. Free. |
|
|
351
|
+
| [`pdf_encrypted`](https://docs.beta.b3os.org/errors#pdf_encrypted) | 422 | The PDF needs a password to open. Free. |
|
|
352
|
+
| [`target_not_found`](https://docs.beta.b3os.org/errors#target_not_found) | 422 | A browser action's target never appeared. |
|
|
353
|
+
| [`egress_denied`](https://docs.beta.b3os.org/errors#egress_denied) | 403 | The URL resolves to an address the egress guard refuses. |
|
|
354
|
+
| [`rate_limited`](https://docs.beta.b3os.org/errors#rate_limited) | 429 | More than your scrapes per minute. |
|
|
355
|
+
|
|
356
|
+
The full list is on the [errors page](https://docs.beta.b3os.org/errors#vision).
|