@howells/fieldwork-sdk 0.9.0 → 0.10.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fieldwork
2
2
 
3
- One API for searching the web, reading pages, extracting values, walking sites, answering and researching questions, finding entities, watching for changes, driving a browser and parsing documents, across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.
3
+ One API for searching the web, reading pages, extracting values, walking sites, answering and researching questions, finding entities, watching for changes, driving a browser, parsing documents and downloading files, across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.
4
4
 
5
5
  ```sh
6
6
  npm i @howells/fieldwork-sdk
@@ -41,6 +41,7 @@ Each instance has only the methods its provider offers, so a call the provider c
41
41
  | `act(code)` | | yes | | | | | | | | | |
42
42
  | `browser.open()`, `browser.close(id)` | | yes | | | | | | yes | yes | | |
43
43
  | `parse(document)` | | yes | | | | | | | | yes | yes |
44
+ | `download(url)` | | yes | | | | | | yes | yes | | |
44
45
  | `monitor.create()`, `.get`, `.list`, `.delete`, `.events` | yes | yes | | yes | | | | | | | |
45
46
  | `usage()` | | yes | yes | | | | yes | yes | | | |
46
47
 
@@ -50,6 +51,7 @@ Each instance has only the methods its provider offers, so a call the provider c
50
51
  - `discover` returns a list of entities, such as companies or products, that meet every condition you give.
51
52
  - `decide` answers closed questions about a context: yes or no, a choice, or a score on a rubric, each with a probability.
52
53
  - `browser.open()` starts a remote browser and returns its CDP URL for Playwright or Puppeteer; `act(code)` runs one script in a fresh session.
54
+ - `download` returns a file's bytes, its content type and the final URL after redirects, fetched through the provider's network. See [Downloading files](#downloading-files).
53
55
  - `monitor` repeats a search or a page check on a schedule and reports what changed. Exa and Parallel monitors watch a query; Firecrawl monitors also watch specific pages (`urls`).
54
56
 
55
57
  ### Options
@@ -69,6 +71,7 @@ Options are typed per provider. An option means the same thing under the same na
69
71
  | `query` | On `read`: return the passages that answer it as `excerpts`. |
70
72
  | `content` | On `search`: include each result's page text. |
71
73
  | `continueFrom` | On `answer` and `research`: the `continuationId` of an earlier result, to ask a follow-up. |
74
+ | `maxBytes` | On `download`: the largest file accepted, in bytes. Defaults to, and may not exceed, the provider's ceiling. |
72
75
  | `resume`, `interval` | On jobs: collect an earlier job by its id, and the milliseconds between status checks (unset: 500, doubling to 2000). |
73
76
 
74
77
  Options only one provider has keep that provider's meaning and values, such as Tavily's `topic`, Exa's `category`, SerpApi's `engine` or Firecrawl's `proxy`. A combination a provider would reject or silently ignore, such as `includeDomains` with `excludeDomains` on Parallel, throws `InvalidRequest` before anything is sent.
@@ -104,7 +107,8 @@ Every result is normalized and keeps the provider's response in `raw`. Most also
104
107
  - `answer` returns `{ answer, output, citations, continuationId }`.
105
108
  - `research` returns `{ id, status, output, sources, fields, continuationId }`. `output` follows your schema when you pass one, otherwise it is the report text.
106
109
  - `crawl` returns `{ pages, failed, robotsBlocked, total }`.
107
- - `parse` returns `{ id, markdown, pages, blocks, pageCount }`. With `blocks: true`, `blocks` lists the layout in reading order: each block's `page`, `type` (the provider's own word), `text` and `box`. With `wordBoxes: true` (LlamaParse and Reducto), blocks also carry `words` and table `cells`, each with its own box. LlamaParse also places each line: a block's `lines` and a cell's `lines` are `{ text, box }`, the text being the line's part of the block's or cell's text, Markdown included. A table's `words` and `lines` are its cells', in reading order. Reducto places no lines. LlamaParse also gives a cell that sits in several boxes each of them as `boxes`, with `box` enclosing them; marks a block read out of a page header or footer with `container: "header"` or `"footer"`; and, with `blocks` or `wordBoxes`, gives each page its `width` and `height` in points. With `pageImages: true` (LlamaParse), each page carries `image`, an address for a picture of the page that expires after about an hour; `parse({ resume: id, pageImages: true })` collects fresh addresses without the file. Every box is `{ left, top, width, height }` in fractions of the page from its top-left corner, whatever units the provider used, so boxes from different providers line up.
110
+ - `download` returns `{ url, bytes, contentType, size, statusCode, etag, lastModified }`: `url` is the final URL, `bytes` a `Uint8Array` exactly as served, `contentType` the server's header unchanged. `etag` and `lastModified` come back from Browserbase and Kernel, which pass headers through.
111
+ - `parse` returns `{ id, markdown, pages, blocks, pageCount }`. With `blocks: true`, `blocks` lists the layout in reading order: each block's `page`, `type` (the provider's own word), `text` and `box`. With `wordBoxes: true` (LlamaParse and Reducto), blocks also carry `words` and table `cells`, each with its own box. LlamaParse also places each line: a block's `lines` and a cell's `lines` are `{ text, box }`, the text being the line's part of the block's or cell's text, Markdown included. A table's `words` and `lines` are its cells', in reading order. Reducto places no lines. LlamaParse also gives a cell that sits in several boxes each of them as `boxes`, with `box` enclosing them; marks a block read out of a page header or footer with `container: "header"` or `"footer"`; and, with `blocks` or `wordBoxes`, gives each page its `width` and `height` in points. With `pageImages: true` (LlamaParse), each page carries `image`, an address for a picture of the page that expires after about an hour; `parse({ resume: id, pageImages: true })` collects fresh addresses without the file: one request that reads the finished job, in under a second, with no new parse and no credits charged. LlamaParse does not publish how long it keeps a job's result; plan for 48 hours (its retention for parse caches and uploaded files) and treat `NotFound` on resume as a job that must be parsed again. Every box is `{ left, top, width, height }` in fractions of the page from its top-left corner, whatever units the provider used, so boxes from different providers line up.
108
112
 
109
113
  A job that stopped early but produced output, for example on a credit or step limit, returns `status: "partial"` with `stopReason`. A job with no usable output throws `JobFailed`.
110
114
 
@@ -146,6 +150,26 @@ await web.browser.close(session.id);
146
150
 
147
151
  A schedule is `{ every: "day" }`, `{ every: "6h" }` or `{ cron: "0 9 * * 1" }`. A schedule the provider cannot express throws `InvalidRequest`.
148
152
 
153
+ ### Downloading files
154
+
155
+ `download(url)` returns the file the URL serves, fetched through the provider's own network: the provider makes the request, and Fieldwork only decodes what it returns. Nothing fetches the file directly, not even a redirect.
156
+
157
+ ```ts
158
+ const file = await web.download(
159
+ "https://www.tilebar.com/media/wysiwyg/Certificates/EPD/EPD-Treveso-V3.pdf"
160
+ );
161
+ file.contentType; // "application/pdf"
162
+ const digest = await crypto.subtle.digest("SHA-256", file.bytes);
163
+ ```
164
+
165
+ | Adapter | Ceiling | How | Cost |
166
+ | --- | --- | --- | --- |
167
+ | `firecrawl()` | 50 MiB | One scrape with `formats: ["rawBase64"]` and no parser. `maxAge: 0` skips Firecrawl's cache, which otherwise serves copies up to 2 days old. | 1 credit per file. |
168
+ | `kernel()` | 50 MiB | Playwright's request client in a new headless browser, which is then deleted. A file over the limit never leaves Kernel. | Browser seconds, as `meta.usage.units.uptime_ms`; 2 to 17 seconds observed. |
169
+ | `browserbase()` | 5 MB | Browserbase Fetch, one call per redirect, so the final URL is known. | One Fetch call per hop. |
170
+
171
+ A response that is not 2xx throws (`NotFound` for 404 and 410), a web page throws `NotAFile`, and a file over the limit throws `TooLarge`. Check `contentType` for anything narrower, such as "is this link really a PDF?". `download` is not an agent tool or MCP tool: a tool result cannot usefully carry tens of megabytes.
172
+
149
173
  ## Choosing a provider per capability
150
174
 
151
175
  `router` sends each capability to exactly one adapter:
@@ -193,6 +217,8 @@ Every failure is a `FieldworkError`. It carries:
193
217
  | `JobFailed` | The job ended without a result. | Start a new job if needed; resuming fails again. |
194
218
  | `Timeout` | The call or job outlasted its time. | With `jobId`, pass it as `resume`. Without one, repeat when `retryable` is true. |
195
219
  | `Aborted` | `signal` cancelled the call. | With `jobId`, the job may still be running; pass it as `resume`. |
220
+ | `TooLarge` | A downloaded file is larger than `maxBytes` or the provider's ceiling. | Raise `maxBytes`, up to the ceiling, or use a provider with a higher one. |
221
+ | `NotAFile` | A download reached a web page (HTML), not a file. | Use `read` for pages; the link is not the file it looked like. |
196
222
  | `ProviderError` | Any other provider failure. | Repeat when `retryable` is true (5xx and network failures). |
197
223
 
198
224
  An error with a `jobId` is never `retryable`, because repeating the call would start and charge for a second job. Nor is a failure, other than a rate limit, of the request that starts a job, session or monitor: the provider may already have started it, so check before repeating.
@@ -1,7 +1,7 @@
1
1
  /** A JSON Schema object describing the values to extract. */
2
2
  type JsonSchema = Record<string, unknown>;
3
3
  /** Every capability Fieldwork knows. An adapter implements a subset. */
4
- declare const CAPABILITIES: readonly ["search", "images", "read", "readMany", "extract", "product", "map", "crawl", "answer", "research", "discover", "decide", "act", "browser", "parse", "monitor", "usage"];
4
+ declare const CAPABILITIES: readonly ["search", "images", "read", "readMany", "extract", "product", "map", "crawl", "answer", "research", "discover", "decide", "act", "browser", "parse", "download", "monitor", "usage"];
5
5
  /** A capability's name, such as `search` or `monitor`. */
6
6
  type Capability = (typeof CAPABILITIES)[number];
7
7
  /**
@@ -532,6 +532,34 @@ interface AccountUsage {
532
532
  periodEnd?: string;
533
533
  raw: unknown;
534
534
  }
535
+ /** Settings every `download` accepts, whatever the provider. */
536
+ interface DownloadOptions extends CallOptions {
537
+ /**
538
+ * The largest file accepted, in bytes. Defaults to, and may not exceed,
539
+ * the adapter's ceiling; a larger value throws `InvalidRequest` before
540
+ * anything is sent. A larger file throws `TooLarge`.
541
+ */
542
+ maxBytes?: number;
543
+ }
544
+ /** What `download` returns: one file's bytes, exactly as the provider fetched them. */
545
+ interface DownloadedFile {
546
+ /** The final URL, after every redirect. */
547
+ url: string;
548
+ /** The file's bytes, exactly as served. */
549
+ bytes: Uint8Array;
550
+ /** The Content-Type the server sent, unchanged, such as "application/pdf". */
551
+ contentType: string;
552
+ /** `bytes.byteLength`. */
553
+ size: number;
554
+ /** The HTTP status of the final response. */
555
+ statusCode?: number;
556
+ /** The server's ETag, when the provider passes headers through. */
557
+ etag?: string;
558
+ /** The server's Last-Modified, when the provider passes headers through. */
559
+ lastModified?: string;
560
+ meta?: Meta;
561
+ raw: unknown;
562
+ }
535
563
  /** Options for one request through an adapter's `raw` client. */
536
564
  interface RequestOptions extends CallOptions {
537
565
  /** A JSON body. */
@@ -603,4 +631,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
603
631
  * It returns its argument unchanged; write a custom adapter with it.
604
632
  */
605
633
  declare const defineAdapter: <Name extends string, Ops extends Operations, Raw = RawClient>(adapter: Adapter<Name, Ops, Raw>) => Adapter<Name, Ops, Raw>;
606
- export { SiteLink as $, GROUP_CAPABILITIES as A, Page as B, DocumentInput as C, Extraction as D, Entity as E, Meta as F, Product as G, ParsedDocument as H, MonitorEvent as I, Recency as J, ProductImage as K, MonitorEvents as L, ImageSearch as M, JsonSchema as N, FailedUrl as O, LineBox as P, SearchResult as Q, MonitorInfo as R, DocumentBlock as S, DocumentUrl as T, Place as U, PageBatch as V, Price as W, RunStatus as X, Research as Y, SearchResponse as Z, Crawl as _, RawClient as a, Decisions as b, ActResult as c, BrowserSession as d, SiteMap as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, ImageResult as j, FieldSource as k, Answer as l, Capability as m, AnyAdapter as n, Usage as nt, RequestOptions as o, CallOptions as p, ProductVariant as q, Operations as r, WordBox as rt, AccountUsage as s, Adapter as t, TableCell as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, MonitorSchedule as z };
634
+ export { SearchResponse as $, FailedUrl as A, MonitorInfo as B, DocumentInput as C, DownloadedFile as D, DownloadOptions as E, JsonSchema as F, Place as G, Page as H, LineBox as I, ProductImage as J, Price as K, Meta as L, GROUP_CAPABILITIES as M, ImageResult as N, Entity as O, ImageSearch as P, RunStatus as Q, MonitorEvent as R, DocumentBlock as S, DocumentUrl as T, PageBatch as U, MonitorSchedule as V, ParsedDocument as W, Recency as X, ProductVariant as Y, Research as Z, Crawl as _, RawClient as a, WordBox as at, Decisions as b, ActResult as c, BrowserSession as d, SearchResult as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, Usage as it, FieldSource as j, Extraction as k, Answer as l, Capability as m, AnyAdapter as n, SiteMap as nt, RequestOptions as o, CallOptions as p, Product as q, Operations as r, TableCell as rt, AccountUsage as s, Adapter as t, SiteLink as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, MonitorEvents as z };
package/dist/brave.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { J as Recency, M as ImageSearch, Z as SearchResponse, a as RawClient, l as Answer, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { $ as SearchResponse, P as ImageSearch, X as Recency, a as RawClient, l as Answer, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Settings for `brave()`. */
3
3
  interface BraveConfig {
4
4
  /** Defaults to the BRAVE_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { B as Page, Z as SearchResponse, a as RawClient, d as BrowserSession, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { $ as SearchResponse, D as DownloadedFile, E as DownloadOptions, H as Page, a as RawClient, d as BrowserSession, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Settings for `browserbase()`. */
3
3
  export interface BrowserbaseConfig {
4
4
  /** Defaults to the BROWSERBASE_API_KEY environment variable. */
@@ -55,6 +55,23 @@ export interface BrowserbaseReadOptions extends CallOptions {
55
55
  /** A context whose saved cookies are sent with the request. */
56
56
  contextId?: string;
57
57
  }
58
+ /**
59
+ * Options for `download`, which fetches the file with Browserbase Fetch,
60
+ * without a browser. Fetch returns at most 5 MB. Redirects are followed one
61
+ * hop at a time, each hop a Fetch call, so the final URL is known.
62
+ */
63
+ export interface BrowserbaseDownloadOptions extends DownloadOptions {
64
+ /** Skip TLS certificate verification, for self-signed or expired certificates. */
65
+ allowInsecureSsl?: boolean;
66
+ /** `true` for Browserbase's default proxy exit, or a geolocation. Not combinable with `country`. */
67
+ proxies?: boolean | {
68
+ geolocation?: BrowserbaseGeolocation;
69
+ };
70
+ /** ISO 3166-1 alpha-2 code; sends the request through a proxy in that country. */
71
+ country?: string;
72
+ /** A context whose saved cookies are sent with the request. */
73
+ contextId?: string;
74
+ }
58
75
  interface BrowserbaseSearchBase extends CallOptions {
59
76
  /** Results to return, 1 to 25. */
60
77
  limit?: number;
@@ -138,6 +155,8 @@ export interface BrowserbaseOpenOptions extends CallOptions {
138
155
  export interface BrowserbaseOperations {
139
156
  search: (query: string, options?: BrowserbaseSearchOptions) => Promise<SearchResponse>;
140
157
  read: (url: string, options?: BrowserbaseReadOptions) => Promise<Page>;
158
+ /** Fetches a file's bytes through Browserbase Fetch, up to 5 MB. */
159
+ download: (url: string, options?: BrowserbaseDownloadOptions) => Promise<DownloadedFile>;
141
160
  browser: {
142
161
  /**
143
162
  * Creates a session. A failure to get its live view URL does not fail the
@@ -151,7 +170,7 @@ export interface BrowserbaseOperations {
151
170
  usage: (options?: CallOptions) => Promise<AccountUsage>;
152
171
  }
153
172
  /**
154
- * An adapter for Browserbase: search, read, browser and usage. Pass it to `new Fieldwork({ adapter })`.
173
+ * An adapter for Browserbase: search, read, download, browser and usage. Pass it to `new Fieldwork({ adapter })`.
155
174
  *
156
175
  * Throws `Unauthorized` when neither `apiKey` nor `BROWSERBASE_API_KEY` is set.
157
176
  */
@@ -1,7 +1,8 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { r as invalidRequest } from "./errors-DROZyb9T.js";
3
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, m as optionalScalar, r as arrayOf, s as optionalAnyString } from "./parse-lMLcxUsG.js";
2
+ import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
+ import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, m as optionalScalar, r as arrayOf, s as optionalAnyString, v as recordOf } from "./parse-lMLcxUsG.js";
4
4
  import { a as compact, f as refuseTogether, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
5
+ import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-gyAym9vL.js";
5
6
  import * as z from "zod/mini";
6
7
  // src/adapters/browserbase/response.ts
7
8
  /** `POST /v1/sessions`. The id keeps the value as it arrived, for the error raised when there is none. */
@@ -20,6 +21,7 @@ const FetchResponse = looseObject({
20
21
  content: optionalAnyString,
21
22
  contentType: optionalString,
22
23
  encoding: optionalString,
24
+ headers: recordOf(optionalAnyString),
23
25
  id: optionalScalar,
24
26
  statusCode: optionalNumber
25
27
  });
@@ -42,6 +44,90 @@ const UsageResponse = looseObject({
42
44
  });
43
45
  /** `GET /v1/projects`: an array of projects. */
44
46
  const ProjectsResponse = arrayOf(looseObject({ id: withOriginal(optionalId) }));
47
+ // src/adapters/browserbase/download.ts
48
+ /** The largest body Browserbase Fetch returns: 5 MB. */
49
+ const DOWNLOAD_CEILING = 5 * MIB;
50
+ /** Redirects `download` follows before it gives up. */
51
+ const MAX_HOPS = 10;
52
+ /** The part of Browserbase's error body that says why. */
53
+ const ErrorBody = looseObject({ message: optionalString });
54
+ /** Whether Browserbase refused the response for exceeding its size limit. */
55
+ const overCeiling = (error) => error.status === 502 && (z.parse(ErrorBody, error.cause).message ?? "").includes("maximum allowed size");
56
+ /**
57
+ * The body as Fetch returned it: Base64 for a binary file, or text Fetch
58
+ * decoded as UTF-8. Throws `ProviderError` for text in any other encoding,
59
+ * whose exact bytes cannot be recovered.
60
+ */
61
+ const contentOf = (provider, url, body) => {
62
+ const content = body.content ?? "";
63
+ if (body.encoding === "base64") return { base64: content };
64
+ if (body.encoding?.toLowerCase() === "utf-8") return { utf8: content };
65
+ throw new FieldworkError("ProviderError", `browserbase downloaded ${url} as ${body.encoding ?? "an unknown encoding"} text, which cannot be turned back into the exact bytes`, {
66
+ cause: body,
67
+ provider
68
+ });
69
+ };
70
+ /** Fetches `current` through Browserbase, following a redirect with another Fetch. */
71
+ const hop = async (download, current, hops) => {
72
+ const { raw, url, limit, call } = download;
73
+ const { provider } = raw;
74
+ if (hops.length > MAX_HOPS) throw new FieldworkError("ProviderError", `browserbase could not download ${url}: more than ${MAX_HOPS} redirects`, {
75
+ cause: hops,
76
+ provider
77
+ });
78
+ const { options: o, proxies } = download;
79
+ let response;
80
+ try {
81
+ response = await raw.request("POST", "/v1/fetch", {
82
+ ...call,
83
+ body: compact({
84
+ allowInsecureSsl: o.allowInsecureSsl,
85
+ allowRedirects: false,
86
+ contextId: o.contextId,
87
+ format: "raw",
88
+ proxies,
89
+ url: current
90
+ })
91
+ });
92
+ } catch (error) {
93
+ throw error instanceof FieldworkError && overCeiling(error) ? tooLarge(provider, url, void 0, limit) : error;
94
+ }
95
+ const seen = [...hops, response];
96
+ const body = z.parse(FetchResponse, response);
97
+ const status = body.statusCode;
98
+ if (status !== void 0 && status >= 300 && status < 400) {
99
+ const location = header(body.headers, "location");
100
+ if (location === void 0) throw new FieldworkError("ProviderError", `browserbase could not download ${url}: ${current} answered ${status} without a Location`, {
101
+ cause: response,
102
+ provider,
103
+ status
104
+ });
105
+ return await hop(download, new URL(location, current).href, seen);
106
+ }
107
+ return presentFile(provider, {
108
+ body: contentOf(provider, url, body),
109
+ contentType: body.contentType,
110
+ headers: body.headers,
111
+ meta: meta({ requestId: body.id }),
112
+ raw: seen.length === 1 ? response : seen,
113
+ requested: url,
114
+ statusCode: status,
115
+ url: current
116
+ }, limit);
117
+ };
118
+ /** Fetches the file through Browserbase Fetch and checks it. */
119
+ const downloadFile = async (raw, url, o, proxies, call) => {
120
+ checkFileUrl(raw.provider, url);
121
+ const limit = byteLimit(raw.provider, DOWNLOAD_CEILING, o.maxBytes);
122
+ return await hop({
123
+ call,
124
+ limit,
125
+ options: o,
126
+ proxies,
127
+ raw,
128
+ url
129
+ }, url, []);
130
+ };
45
131
  // src/adapters/browserbase.ts
46
132
  /** The modes each search provider takes; `search` refuses any other. */
47
133
  const SEARCH_MODES = {
@@ -53,7 +139,7 @@ const SEARCH_MODES = {
53
139
  parallel: ["fast", "advanced"]
54
140
  };
55
141
  /**
56
- * An adapter for Browserbase: search, read, browser and usage. Pass it to `new Fieldwork({ adapter })`.
142
+ * An adapter for Browserbase: search, read, download, browser and usage. Pass it to `new Fieldwork({ adapter })`.
57
143
  *
58
144
  * Throws `Unauthorized` when neither `apiKey` nor `BROWSERBASE_API_KEY` is set.
59
145
  */
@@ -140,6 +226,10 @@ const browserbase = (config = {}) => {
140
226
  });
141
227
  }
142
228
  },
229
+ async download(url, options) {
230
+ const { call, rest: o } = callSettings(options);
231
+ return await downloadFile(raw, url, o, fetchProxies(o), call);
232
+ },
143
233
  async read(url, options) {
144
234
  const { call, rest: o } = callSettings(options);
145
235
  const format = o.format ?? "markdown";
@@ -0,0 +1,78 @@
1
+ import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
2
+ // src/download.ts
3
+ /** One mebibyte, the unit the providers' ceilings are stated in. */
4
+ const MIB = 1048576;
5
+ /**
6
+ * Throws `InvalidRequest` unless the URL parses and is http or https, so
7
+ * nothing is sent for a URL no provider can download.
8
+ */
9
+ const checkFileUrl = (provider, url) => {
10
+ const parsed = URL.parse(url);
11
+ if (parsed === null) throw invalidRequest(provider, `cannot download ${url}: it is not a URL`);
12
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw invalidRequest(provider, `downloads only http and https URLs, not ${parsed.protocol} (${url})`);
13
+ };
14
+ /**
15
+ * The byte limit for a download: `maxBytes`, or the provider's ceiling when
16
+ * it is unset. Throws `InvalidRequest` for a limit that is not a positive
17
+ * whole number or exceeds the ceiling.
18
+ */
19
+ const byteLimit = (provider, ceiling, maxBytes) => {
20
+ if (maxBytes === void 0) return ceiling;
21
+ if (!Number.isInteger(maxBytes) || maxBytes < 1) throw invalidRequest(provider, `needs maxBytes as a positive whole number, got ${maxBytes}`);
22
+ if (maxBytes > ceiling) throw invalidRequest(provider, `downloads at most ${ceiling} bytes; maxBytes ${maxBytes} is larger`);
23
+ return maxBytes;
24
+ };
25
+ /** The error for a file over the limit. */
26
+ const tooLarge = (provider, url, size, limit) => new FieldworkError("TooLarge", `${provider} could not download ${url}: the file is ${size === void 0 ? "larger than" : `${size} bytes, over`} the limit of ${limit} bytes`, { provider });
27
+ /** Content types that are web pages rather than files. */
28
+ const PAGE_TYPES = /* @__PURE__ */ new Set(["text/html", "application/xhtml+xml"]);
29
+ /** Statuses that mean the file is not there. */
30
+ const GONE = /* @__PURE__ */ new Set([404, 410]);
31
+ /** A header's value by name (lower-case) in any case, or undefined. */
32
+ const header = (headers, name) => Object.entries(headers ?? {}).find(([key]) => key.toLowerCase() === name)?.[1];
33
+ /** Throws `NotFound` for a 404 or 410 and `ProviderError` for any other status that is not 2xx. */
34
+ const checkStatus = (provider, fetched) => {
35
+ const { requested, statusCode } = fetched;
36
+ if (statusCode === void 0) return;
37
+ if (GONE.has(statusCode)) throw new FieldworkError("NotFound", `${provider} could not download ${requested}: it answered ${statusCode}`, {
38
+ provider,
39
+ status: statusCode
40
+ });
41
+ if (statusCode < 200 || statusCode > 299) throw new FieldworkError("ProviderError", `${provider} could not download ${requested}: it answered ${statusCode}`, {
42
+ cause: fetched.raw,
43
+ provider,
44
+ status: statusCode
45
+ });
46
+ };
47
+ /**
48
+ * The checked file. Throws `NotFound` for a 404 or 410, `ProviderError` for
49
+ * any other status that is not 2xx or a reply with no content type,
50
+ * `NotAFile` for an HTML page, and `TooLarge` for more bytes than `limit`.
51
+ */
52
+ const presentFile = (provider, fetched, limit) => {
53
+ const { requested, statusCode } = fetched;
54
+ checkStatus(provider, fetched);
55
+ const { contentType } = fetched;
56
+ if (contentType === void 0 || contentType === "") throw new FieldworkError("ProviderError", `${provider} downloaded ${requested} but reported no content type`, {
57
+ cause: fetched.raw,
58
+ provider
59
+ });
60
+ const mediaType = contentType.split(";")[0]?.trim().toLowerCase() ?? "";
61
+ if (PAGE_TYPES.has(mediaType)) throw new FieldworkError("NotAFile", `${provider} could not download ${requested}: it is a web page (${contentType}), not a file`, { provider });
62
+ const bytes = "base64" in fetched.body ? new Uint8Array(Buffer.from(fetched.body.base64, "base64")) : new TextEncoder().encode(fetched.body.utf8);
63
+ if (bytes.byteLength > limit) throw tooLarge(provider, requested, bytes.byteLength, limit);
64
+ return {
65
+ bytes,
66
+ contentType,
67
+ ...fetched.headers && {
68
+ etag: header(fetched.headers, "etag"),
69
+ lastModified: header(fetched.headers, "last-modified")
70
+ },
71
+ ...fetched.meta && { meta: fetched.meta },
72
+ raw: fetched.raw,
73
+ size: bytes.byteLength,
74
+ ...statusCode !== void 0 && { statusCode },
75
+ url: fetched.url
76
+ };
77
+ };
78
+ export { presentFile as a, header as i, byteLimit as n, tooLarge as o, checkFileUrl as r, MIB as t };
package/dist/exa.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as Page, D as Extraction, L as MonitorEvents, R as MonitorInfo, V as PageBatch, Y as Research, Z as SearchResponse, a as RawClient, l as Answer, p as CallOptions, t as Adapter, z as MonitorSchedule } from "./adapter-DuJkoVWY.js";
2
- import { t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, B as MonitorInfo, H as Page, U as PageBatch, V as MonitorSchedule, Z as Research, a as RawClient, k as Extraction, l as Answer, p as CallOptions, t as Adapter, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
+ import { t as OutputSchema } from "./schema-BFjS6CSz.js";
3
3
  /** Settings for the Exa adapter. */
4
4
  interface ExaConfig {
5
5
  /** Defaults to the EXA_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { m as Capability, n as AnyAdapter } from "./adapter-DuJkoVWY.js";
1
+ import { m as Capability, n as AnyAdapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Why a call failed. Branch on this, not on the message, which can change. */
3
3
  type FieldworkErrorCode =
4
4
  /** The adapter's provider does not offer this capability. */
@@ -17,6 +17,10 @@ type FieldworkErrorCode =
17
17
  "Timeout" |
18
18
  /** The caller's `signal` cancelled the call. */
19
19
  "Aborted" |
20
+ /** A downloaded file is larger than `maxBytes` or the provider's ceiling. */
21
+ "TooLarge" |
22
+ /** A download reached a web page (HTML), not a file. */
23
+ "NotAFile" |
20
24
  /** Any other provider failure. */
21
25
  "ProviderError";
22
26
  /** What a `FieldworkError` carries besides its code and message. */
@@ -1,5 +1,5 @@
1
- import { B as Page, C as DocumentInput, D as Extraction, G as Product, H as ParsedDocument, J as Recency, L as MonitorEvents, M as ImageSearch, R as MonitorInfo, V as PageBatch, Y as Research, Z as SearchResponse, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, et as SiteMap, p as CallOptions, s as AccountUsage, t as Adapter, z as MonitorSchedule } from "./adapter-DuJkoVWY.js";
2
- import { t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, B as MonitorInfo, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, H as Page, P as ImageSearch, U as PageBatch, V as MonitorSchedule, W as ParsedDocument, X as Recency, Z as Research, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, k as Extraction, nt as SiteMap, p as CallOptions, q as Product, s as AccountUsage, t as Adapter, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
+ import { t as OutputSchema } from "./schema-BFjS6CSz.js";
3
3
  /** Settings for the Firecrawl adapter. */
4
4
  interface FirecrawlConfig {
5
5
  /** Defaults to the FIRECRAWL_API_KEY environment variable. */
@@ -349,6 +349,22 @@ interface FirecrawlMonitorOptions extends CallOptions {
349
349
  * map, crawl, research, act, browser, parse, monitor and usage. `readMany`,
350
350
  * `crawl` and `research` are asynchronous jobs and accept `resume`.
351
351
  */
352
+ /**
353
+ * Options for `download`, which fetches the file through Firecrawl's scrape
354
+ * (`formats: ["rawBase64"]`, no parsers) for 1 credit, whatever its size.
355
+ * Firecrawl's ceiling is 50 MiB.
356
+ */
357
+ interface FirecrawlDownloadOptions extends DownloadOptions {
358
+ /** Which proxies fetch the file; see `FirecrawlPageSettings.proxy`. */
359
+ proxy?: "basic" | "enhanced" | "auto";
360
+ /**
361
+ * Seconds a cached copy may be old; 0 always fetches fresh. Firecrawl
362
+ * serves copies up to 2 days old unless told otherwise.
363
+ */
364
+ maxAge?: number;
365
+ /** ISO 3166-1 alpha-2 code of the country the request comes from. */
366
+ country?: string;
367
+ }
352
368
  interface FirecrawlOperations {
353
369
  search: (query: string, options?: FirecrawlSearchOptions) => Promise<SearchResponse>;
354
370
  images: (query: string, options?: FirecrawlImagesOptions) => Promise<ImageSearch>;
@@ -369,6 +385,8 @@ interface FirecrawlOperations {
369
385
  close: (id: string, options?: CallOptions) => Promise<void>;
370
386
  };
371
387
  parse: (document: DocumentInput, options?: FirecrawlParseOptions) => Promise<ParsedDocument>;
388
+ /** Fetches a file's bytes through Firecrawl, up to 50 MiB. */
389
+ download: (url: string, options?: FirecrawlDownloadOptions) => Promise<DownloadedFile>;
372
390
  monitor: {
373
391
  create: (options: FirecrawlMonitorOptions) => Promise<MonitorInfo>;
374
392
  get: (id: string, options?: CallOptions) => Promise<MonitorInfo>;
@@ -382,7 +400,7 @@ interface FirecrawlOperations {
382
400
  usage: (options?: CallOptions) => Promise<AccountUsage>;
383
401
  }
384
402
  /**
385
- * An adapter for Firecrawl: search, images, read, readMany, extract, product, map, crawl, research, act, browser, parse, monitor and usage. Pass it to `new Fieldwork({ adapter })`.
403
+ * An adapter for Firecrawl: search, images, read, readMany, extract, product, map, crawl, research, act, browser, parse, download, monitor and usage. Pass it to `new Fieldwork({ adapter })`.
386
404
  *
387
405
  * Throws `Unauthorized` when neither `apiKey` nor `FIRECRAWL_API_KEY` is set.
388
406
  */
package/dist/firecrawl.js CHANGED
@@ -4,6 +4,7 @@ import { C as createRawClient, E as segment, S as withOriginal, T as requireKey,
4
4
  import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DBhGs7Ha.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-COAaWnZB.js";
6
6
  import { a as compact, f as refuseTogether, l as presentPage, p as requireJobId, s as meta, t as callSettings, u as presentPages } from "./util-BqeRYF2b.js";
7
+ import { a as presentFile, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-gyAym9vL.js";
7
8
  import { a as mediaTypeOf, n as documentPart, o as refuseLarger, t as MEDIA_TYPES } from "./document-DOzhDFFt.js";
8
9
  import * as z from "zod/mini";
9
10
  // src/adapters/firecrawl/shared.ts
@@ -772,6 +773,7 @@ const Variant = looseObject({
772
773
  const metadataShape = {
773
774
  "article:published_time": optionalString,
774
775
  author: optionalFirstString,
776
+ contentType: optionalString,
775
777
  creditsUsed: optionalNumber,
776
778
  description: optionalFirstString,
777
779
  favicon: optionalString,
@@ -809,6 +811,7 @@ const PageData = looseObject({
809
811
  url: optionalString,
810
812
  variants: arrayOf(Variant)
811
813
  }),
814
+ rawBase64: optionalAnyString,
812
815
  rawHtml: optionalString,
813
816
  screenshot: optionalString,
814
817
  summary: optionalString,
@@ -999,11 +1002,58 @@ const UsageResponse = looseObject({ data: looseObject({
999
1002
  planCredits: optionalNumber,
1000
1003
  remainingCredits: optionalNumber
1001
1004
  }) });
1005
+ // src/adapters/firecrawl/download.ts
1006
+ /** The largest file Firecrawl's scrape returns: 50 MiB. */
1007
+ const DOWNLOAD_CEILING = 50 * MIB;
1008
+ /** The part of Firecrawl's error body that names the failure. */
1009
+ const ErrorBody = looseObject({ code: optionalString });
1010
+ /** Whether Firecrawl refused the file for exceeding its size limit. */
1011
+ const overCeiling = (error) => z.parse(ErrorBody, error.cause).code === "SCRAPE_UNSUPPORTED_FILE_ERROR" && error.message.includes("size limit");
1012
+ /** Fetches the file through Firecrawl's scrape and checks it. */
1013
+ const downloadFile = async (raw, url, options) => {
1014
+ const { provider } = raw;
1015
+ const { call, rest: o } = callSettings(options);
1016
+ checkFileUrl(provider, url);
1017
+ const limit = byteLimit(provider, DOWNLOAD_CEILING, o.maxBytes);
1018
+ let response;
1019
+ try {
1020
+ response = await raw.request("POST", "/scrape", {
1021
+ ...call,
1022
+ body: {
1023
+ formats: ["rawBase64"],
1024
+ url,
1025
+ ...pageBody({
1026
+ location: o.country === void 0 ? void 0 : { country: o.country.toUpperCase() },
1027
+ maxAge: o.maxAge,
1028
+ parsers: [],
1029
+ proxy: o.proxy
1030
+ })
1031
+ }
1032
+ });
1033
+ } catch (error) {
1034
+ throw error instanceof FieldworkError && overCeiling(error) ? tooLarge(provider, url, void 0, limit) : error;
1035
+ }
1036
+ const { data, warning } = z.parse(ScrapeResponse, response);
1037
+ const { metadata } = data;
1038
+ if (data.rawBase64 === void 0) throw new FieldworkError("ProviderError", `firecrawl downloaded ${url} but returned no rawBase64 content`, {
1039
+ cause: response,
1040
+ provider
1041
+ });
1042
+ return presentFile(provider, {
1043
+ body: { base64: data.rawBase64 },
1044
+ contentType: metadata.contentType,
1045
+ meta: pageMeta(data, warning.notes),
1046
+ raw: response,
1047
+ requested: url,
1048
+ statusCode: metadata.statusCode,
1049
+ url: metadata.url ?? url
1050
+ }, limit);
1051
+ };
1002
1052
  // src/adapters/firecrawl.ts
1003
1053
  /** How long closing a session may take, apart from the call's own deadline. */
1004
1054
  const CLOSE_TIMEOUT = 15e3;
1005
1055
  /**
1006
- * An adapter for Firecrawl: search, images, read, readMany, extract, product, map, crawl, research, act, browser, parse, monitor and usage. Pass it to `new Fieldwork({ adapter })`.
1056
+ * An adapter for Firecrawl: search, images, read, readMany, extract, product, map, crawl, research, act, browser, parse, download, monitor and usage. Pass it to `new Fieldwork({ adapter })`.
1007
1057
  *
1008
1058
  * Throws `Unauthorized` when neither `apiKey` nor `FIRECRAWL_API_KEY` is set.
1009
1059
  */
@@ -1174,6 +1224,7 @@ const firecrawl = (config = {}) => {
1174
1224
  });
1175
1225
  });
1176
1226
  },
1227
+ download: async (url, options) => await downloadFile(raw, url, options),
1177
1228
  async extract(url, options) {
1178
1229
  const { call, rest: o } = callSettings(options);
1179
1230
  const { schema, prompt, ...page } = o;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as SiteLink, A as GROUP_CAPABILITIES, B as Page, C as DocumentInput, D as Extraction, E as Entity, F as Meta, G as Product, H as ParsedDocument, I as MonitorEvent, J as Recency, K as ProductImage, L as MonitorEvents, M as ImageSearch, N as JsonSchema, O as FailedUrl, P as LineBox, Q as SearchResult, R as MonitorInfo, S as DocumentBlock, T as DocumentUrl, U as Place, V as PageBatch, W as Price, X as RunStatus, Y as Research, Z as SearchResponse, _ as Crawl, a as RawClient, b as Decisions, c as ActResult, d as BrowserSession, et as SiteMap, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, j as ImageResult, k as FieldSource, l as Answer, m as Capability, n as AnyAdapter, nt as Usage, o as RequestOptions, p as CallOptions, q as ProductVariant, r as Operations, rt as WordBox, s as AccountUsage, t as Adapter, tt as TableCell, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as MonitorSchedule } from "./adapter-DuJkoVWY.js";
2
- import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-Bhl4401B.js";
3
- import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, A as FailedUrl, B as MonitorInfo, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as JsonSchema, G as Place, H as Page, I as LineBox, J as ProductImage, K as Price, L as Meta, M as GROUP_CAPABILITIES, N as ImageResult, O as Entity, P as ImageSearch, Q as RunStatus, R as MonitorEvent, S as DocumentBlock, T as DocumentUrl, U as PageBatch, V as MonitorSchedule, W as ParsedDocument, X as Recency, Y as ProductVariant, Z as Research, _ as Crawl, a as RawClient, at as WordBox, b as Decisions, c as ActResult, d as BrowserSession, et as SearchResult, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, it as Usage, j as FieldSource, k as Extraction, l as Answer, m as Capability, n as AnyAdapter, nt as SiteMap, o as RequestOptions, p as CallOptions, q as Product, r as Operations, rt as TableCell, s as AccountUsage, t as Adapter, tt as SiteLink, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
+ import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-DNwEf0Mo.js";
3
+ import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-BFjS6CSz.js";
4
4
  /** Which adapter serves each capability, for `router`. */
5
5
  type Routes = Partial<Record<Capability, AnyAdapter>>;
6
6
  /** Each route must name an adapter whose provider offers that capability. */
@@ -23,4 +23,4 @@ export declare const router: <const R extends Routes>(routes: R & ValidRoutes<R>
23
23
  * `Unsupported` here instead of failing to compile.
24
24
  */
25
25
  export declare const runtimeRouter: (routes: Routes) => AnyAdapter;
26
- export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, Box, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentBlock, DocumentInput, DocumentPage, DocumentUrl, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, LineBox, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, type OutputSchema, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, type Routes, RunStatus, SearchResponse, SearchResult, SiteLink, SiteMap, type StandardSchemaWithJSON, TableCell, Usage, WordBox, defineAdapter };
26
+ export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, Box, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentBlock, DocumentInput, DocumentPage, DocumentUrl, DownloadOptions, DownloadedFile, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, LineBox, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, type OutputSchema, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, type Routes, RunStatus, SearchResponse, SearchResult, SiteLink, SiteMap, type StandardSchemaWithJSON, TableCell, Usage, WordBox, defineAdapter };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-CnomnF-6.js";
3
+ import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-rc8bl8Em.js";
4
4
  // src/fieldwork.ts
5
5
  /**
6
6
  * The adapter's operation for a capability, bound to its `operations` object
@@ -49,6 +49,7 @@ var FieldworkClient = class {
49
49
  crawl: has("crawl"),
50
50
  decide: has("decide"),
51
51
  discover: has("discover"),
52
+ download: has("download"),
52
53
  extract: has("extract"),
53
54
  images: has("images"),
54
55
  map: has("map"),
package/dist/kernel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { D as DownloadedFile, E as DownloadOptions, H as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Settings for `kernel()`. */
3
3
  export interface KernelConfig {
4
4
  /** Defaults to the KERNEL_API_KEY environment variable. */
@@ -82,9 +82,22 @@ export interface KernelOpenOptions extends CallOptions {
82
82
  /** Start-Up and Enterprise plans only. Kernel defaults to us-east. */
83
83
  region?: "us-east" | "us-west" | "eu-west" | "ap-southeast";
84
84
  }
85
+ /**
86
+ * Options for `download`, which fetches the file with Playwright's request
87
+ * client inside a new headless Kernel browser, without rendering a page, and
88
+ * deletes the browser. The bytes never leave Kernel when the file is over
89
+ * the limit. The session bills for the seconds it ran, reported as
90
+ * `meta.usage.units.uptime_ms`. Kernel's ceiling here is 50 MiB.
91
+ */
92
+ export interface KernelDownloadOptions extends DownloadOptions {
93
+ /** Send a saved profile's cookies with the request. The download never saves to it. */
94
+ profile?: KernelProfile;
95
+ }
85
96
  /** What the Kernel adapter offers. */
86
97
  export interface KernelOperations {
87
98
  read: (url: string, options?: KernelReadOptions) => Promise<Page>;
99
+ /** Fetches a file's bytes inside a Kernel browser, up to 50 MiB. */
100
+ download: (url: string, options?: KernelDownloadOptions) => Promise<DownloadedFile>;
88
101
  browser: {
89
102
  open: (options?: KernelOpenOptions) => Promise<BrowserSession>;
90
103
  /** Deletes the session, so it stops billing. */
@@ -92,7 +105,7 @@ export interface KernelOperations {
92
105
  };
93
106
  }
94
107
  /**
95
- * An adapter for Kernel: read and browser. Pass it to `new Fieldwork({ adapter })`.
108
+ * An adapter for Kernel: read, download and browser. Pass it to `new Fieldwork({ adapter })`.
96
109
  *
97
110
  * Throws `Unauthorized` when neither `apiKey` nor `KERNEL_API_KEY` is set.
98
111
  */
package/dist/kernel.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
+ import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-gyAym9vL.js";
2
3
  import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, l as optionalBoolean, n as anything, p as optionalObject, s as optionalAnyString } from "./parse-lMLcxUsG.js";
4
- import { r as runJob } from "./job-DBhGs7Ha.js";
4
+ import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, l as optionalBoolean, n as anything, p as optionalObject, s as optionalAnyString, v as recordOf } from "./parse-lMLcxUsG.js";
5
5
  import { a as compact, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
6
+ import { r as runJob } from "./job-DBhGs7Ha.js";
6
7
  import * as z from "zod/mini";
7
8
  import TurndownService from "turndown";
8
9
  // src/adapters/kernel/response.ts
@@ -31,66 +32,21 @@ const RenderedPage = looseObject({
31
32
  title: optionalString,
32
33
  url: optionalString
33
34
  });
34
- // src/adapters/kernel.ts
35
- /** Seconds Kernel gives the read script, within its 300-second limit. */
36
- const READ_SCRIPT_SECONDS = 120;
35
+ /** What the download script returns: the response, and its body as Base64 unless it was over the limit or not 2xx. */
36
+ const FetchedFile = looseObject({
37
+ data: optionalAnyString,
38
+ headers: recordOf(optionalAnyString),
39
+ status: optionalNumber,
40
+ tooLarge: optionalNumber,
41
+ url: optionalString
42
+ });
43
+ // src/adapters/kernel/session.ts
37
44
  /** Seconds a read's session may sit idle before Kernel deletes it. */
38
45
  const READ_IDLE_SECONDS = 60;
39
46
  /** Milliseconds a read waits for Kernel to delete its session, apart from the call's own deadline. */
40
47
  const RELEASE_TIMEOUT = 1e4;
41
48
  /** Milliseconds a read waits for the deleted session's billed time. */
42
49
  const BILLED_TIME_WAIT = 15e3;
43
- /** The elements that hold a page's content, inside which site chrome is kept. */
44
- const CONTENT = /* @__PURE__ */ new Set(["main", "article"]);
45
- /** Site chrome: removed from the Markdown unless it is inside a main or article element. */
46
- const CHROME = /* @__PURE__ */ new Set([
47
- "nav",
48
- "header",
49
- "footer",
50
- "aside"
51
- ]);
52
- /**
53
- * The Playwright script `read` runs in the browser. It waits for the DOM and
54
- * then up to 3 seconds for the network to go quiet: pages that poll or
55
- * stream never do, and their content has rendered by then. It reads the HTML,
56
- * title and URL in one call into the page, because each call waits its turn
57
- * behind the page's own scripts, seconds on a busy page.
58
- */
59
- const readScript = (url) => `
60
- const response = await page.goto(${JSON.stringify(url)}, { waitUntil: "domcontentloaded", timeout: 90000 });
61
- await page.waitForLoadState("networkidle", { timeout: 3000 }).catch(() => undefined);
62
- const rendered = await page.evaluate(() => ({
63
- html: (document.doctype ? new XMLSerializer().serializeToString(document.doctype) : "") + document.documentElement.outerHTML,
64
- title: document.title,
65
- url: location.href,
66
- }));
67
- return { ...rendered, status: response?.status() ?? null };
68
- `;
69
- /** Whether the node has a main or article element among its ancestors. */
70
- const inContent = (node) => node.parentNode !== null && (CONTENT.has(node.parentNode.nodeName.toLowerCase()) || inContent(node.parentNode));
71
- /**
72
- * The rendered page as Markdown, without the site's navigation, header,
73
- * footer and sidebars, which on a retailer's page can be most of the text.
74
- * Those elements are kept inside a main or article element, where they are
75
- * the content's own; a page with neither loses all of them.
76
- */
77
- const markdownOf = (html) => {
78
- const service = new TurndownService({
79
- bulletListMarker: "-",
80
- codeBlockStyle: "fenced",
81
- headingStyle: "atx"
82
- });
83
- service.remove([
84
- "title",
85
- "script",
86
- "style",
87
- "noscript",
88
- "template",
89
- "iframe"
90
- ]);
91
- service.remove((node) => CHROME.has(node.nodeName.toLowerCase()) && !inContent(node));
92
- return service.turndown(html).trim();
93
- };
94
50
  /** The session's profile and proxy as Kernel's create body spells them. */
95
51
  const sessionBody = (o) => ({
96
52
  profile: o.profile ? compact({
@@ -106,15 +62,6 @@ const sessionBody = (o) => ({
106
62
  });
107
63
  /** Why a session still bills, for a warning or an error. */
108
64
  const leakText = (id, failure) => `could not delete browser ${id}, which bills until its ${READ_IDLE_SECONDS}-second idle timeout: ${failure.message}`;
109
- /**
110
- * Throws `InvalidRequest` unless the URL parses and is http or https, so no
111
- * session is created for a URL the browser should not open.
112
- */
113
- const checkUrl = (provider, url) => {
114
- const parsed = URL.parse(url);
115
- if (parsed === null) throw invalidRequest(provider, `cannot read ${url}: it is not a URL`);
116
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw invalidRequest(provider, `reads only http and https URLs, not ${parsed.protocol} (${url})`);
117
- };
118
65
  /** What the work returned, or what it threw. */
119
66
  const settle = async (work) => {
120
67
  try {
@@ -176,6 +123,135 @@ const billedTime = async (raw, id, call) => {
176
123
  }
177
124
  };
178
125
  /**
126
+ * Runs `work` in a new headless session and deletes the session whether or
127
+ * not the work succeeded. A failure whose session could not be deleted fails
128
+ * with its own error, naming the session that still bills.
129
+ */
130
+ const inSession = async (raw, o, call, work) => {
131
+ const { provider } = raw;
132
+ const created = await raw.request("POST", "/browsers", {
133
+ creates: true,
134
+ ...call,
135
+ body: compact({
136
+ headless: true,
137
+ stealth: o.stealth,
138
+ timeout_seconds: READ_IDLE_SECONDS,
139
+ ...sessionBody({
140
+ profile: o.profile,
141
+ proxy: o.proxy
142
+ })
143
+ })
144
+ });
145
+ const id = requireJobId(provider, z.parse(BrowserResponse, created).session_id);
146
+ const done = await settle(work(id));
147
+ const unreleased = await release(raw, id, call.retries);
148
+ if (!done.ok) {
149
+ const { error } = done;
150
+ if (unreleased === void 0) throw error;
151
+ const message = `${error instanceof Error ? error.message : String(error)}; also ${leakText(id, unreleased)}`;
152
+ throw error instanceof FieldworkError ? new FieldworkError(error.code, message, {
153
+ cause: error,
154
+ jobId: error.jobId,
155
+ provider: error.provider,
156
+ retryAfter: error.retryAfter,
157
+ retryable: error.retryable,
158
+ status: error.status
159
+ }) : new FieldworkError("ProviderError", message, {
160
+ cause: error,
161
+ provider
162
+ });
163
+ }
164
+ return {
165
+ billed: unreleased === void 0 ? await billedTime(raw, id, call) : { warning: leakText(id, unreleased) },
166
+ created,
167
+ id,
168
+ value: done.value
169
+ };
170
+ };
171
+ // src/adapters/kernel.ts
172
+ /** Seconds Kernel gives the read script, within its 300-second limit. */
173
+ const READ_SCRIPT_SECONDS = 120;
174
+ /** The largest file `download` returns: what Kernel's script results carry reliably. */
175
+ const DOWNLOAD_CEILING = 50 * MIB;
176
+ /** Seconds Kernel gives the download script, within its 300-second limit. */
177
+ const DOWNLOAD_SCRIPT_SECONDS = 240;
178
+ /**
179
+ * The Playwright script `download` runs in the browser's VM. It fetches with
180
+ * the context's request client (the profile's cookies, no page), follows
181
+ * redirects, and returns the body as Base64 only when the response is 2xx
182
+ * and within the limit, so an oversized file never leaves Kernel.
183
+ */
184
+ const downloadScript = (url, limit) => `
185
+ const response = await context.request.get(${JSON.stringify(url)}, { failOnStatusCode: false, maxRedirects: 20, timeout: 200000 });
186
+ const result = { headers: response.headers(), status: response.status(), url: response.url() };
187
+ if (!response.ok()) return result;
188
+ const declared = Number(result.headers["content-length"]);
189
+ if (Number.isFinite(declared) && declared > ${limit}) return { ...result, tooLarge: declared };
190
+ const body = await response.body();
191
+ if (body.length > ${limit}) return { ...result, tooLarge: body.length };
192
+ return { ...result, data: body.toString("base64") };
193
+ `;
194
+ /** The elements that hold a page's content, inside which site chrome is kept. */
195
+ const CONTENT = /* @__PURE__ */ new Set(["main", "article"]);
196
+ /** Site chrome: removed from the Markdown unless it is inside a main or article element. */
197
+ const CHROME = /* @__PURE__ */ new Set([
198
+ "nav",
199
+ "header",
200
+ "footer",
201
+ "aside"
202
+ ]);
203
+ /**
204
+ * The Playwright script `read` runs in the browser. It waits for the DOM and
205
+ * then up to 3 seconds for the network to go quiet: pages that poll or
206
+ * stream never do, and their content has rendered by then. It reads the HTML,
207
+ * title and URL in one call into the page, because each call waits its turn
208
+ * behind the page's own scripts, seconds on a busy page.
209
+ */
210
+ const readScript = (url) => `
211
+ const response = await page.goto(${JSON.stringify(url)}, { waitUntil: "domcontentloaded", timeout: 90000 });
212
+ await page.waitForLoadState("networkidle", { timeout: 3000 }).catch(() => undefined);
213
+ const rendered = await page.evaluate(() => ({
214
+ html: (document.doctype ? new XMLSerializer().serializeToString(document.doctype) : "") + document.documentElement.outerHTML,
215
+ title: document.title,
216
+ url: location.href,
217
+ }));
218
+ return { ...rendered, status: response?.status() ?? null };
219
+ `;
220
+ /** Whether the node has a main or article element among its ancestors. */
221
+ const inContent = (node) => node.parentNode !== null && (CONTENT.has(node.parentNode.nodeName.toLowerCase()) || inContent(node.parentNode));
222
+ /**
223
+ * The rendered page as Markdown, without the site's navigation, header,
224
+ * footer and sidebars, which on a retailer's page can be most of the text.
225
+ * Those elements are kept inside a main or article element, where they are
226
+ * the content's own; a page with neither loses all of them.
227
+ */
228
+ const markdownOf = (html) => {
229
+ const service = new TurndownService({
230
+ bulletListMarker: "-",
231
+ codeBlockStyle: "fenced",
232
+ headingStyle: "atx"
233
+ });
234
+ service.remove([
235
+ "title",
236
+ "script",
237
+ "style",
238
+ "noscript",
239
+ "template",
240
+ "iframe"
241
+ ]);
242
+ service.remove((node) => CHROME.has(node.nodeName.toLowerCase()) && !inContent(node));
243
+ return service.turndown(html).trim();
244
+ };
245
+ /**
246
+ * Throws `InvalidRequest` unless the URL parses and is http or https, so no
247
+ * session is created for a URL the browser should not open.
248
+ */
249
+ const checkUrl = (provider, url) => {
250
+ const parsed = URL.parse(url);
251
+ if (parsed === null) throw invalidRequest(provider, `cannot read ${url}: it is not a URL`);
252
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw invalidRequest(provider, `reads only http and https URLs, not ${parsed.protocol} (${url})`);
253
+ };
254
+ /**
179
255
  * Runs the read script in the session and returns the rendered page with its
180
256
  * HTML and Kernel's reply. Throws `ProviderError` when the script failed or
181
257
  * returned no HTML.
@@ -205,50 +281,14 @@ const render = async (raw, id, url, call) => {
205
281
  response
206
282
  };
207
283
  };
208
- /**
209
- * Loads the page in a new session, deletes the session whether or not the
210
- * script succeeded, and builds the result. A failed read whose session could
211
- * not be deleted fails with its own error, naming the session that still bills.
212
- */
284
+ /** Loads the page in a new session and builds the result. */
213
285
  const readPage = async (raw, url, options) => {
214
286
  const { provider } = raw;
215
287
  const { call, rest: o } = callSettings(options);
216
288
  checkUrl(provider, url);
217
289
  const format = o.format ?? "markdown";
218
- const created = await raw.request("POST", "/browsers", {
219
- creates: true,
220
- ...call,
221
- body: compact({
222
- headless: true,
223
- stealth: o.stealth,
224
- timeout_seconds: READ_IDLE_SECONDS,
225
- ...sessionBody({
226
- profile: o.profile,
227
- proxy: o.proxy
228
- })
229
- })
230
- });
231
- const id = requireJobId(provider, z.parse(BrowserResponse, created).session_id);
232
- const rendered = await settle(render(raw, id, url, call));
233
- const unreleased = await release(raw, id, call.retries);
234
- if (!rendered.ok) {
235
- const { error } = rendered;
236
- if (unreleased === void 0) throw error;
237
- const message = `${error instanceof Error ? error.message : String(error)}; also ${leakText(id, unreleased)}`;
238
- throw error instanceof FieldworkError ? new FieldworkError(error.code, message, {
239
- cause: error,
240
- jobId: error.jobId,
241
- provider: error.provider,
242
- retryAfter: error.retryAfter,
243
- retryable: error.retryable,
244
- status: error.status
245
- }) : new FieldworkError("ProviderError", message, {
246
- cause: error,
247
- provider
248
- });
249
- }
250
- const { html, page, response } = rendered.value;
251
- const billed = unreleased === void 0 ? await billedTime(raw, id, call) : { warning: leakText(id, unreleased) };
290
+ const { billed, created, id, value } = await inSession(raw, o, call, async (session) => await render(raw, session, url, call));
291
+ const { html, page, response } = value;
252
292
  const markdown = format === "markdown" ? markdownOf(html) : void 0;
253
293
  return presentPage(provider, compact({
254
294
  markdown,
@@ -267,8 +307,57 @@ const readPage = async (raw, url, options) => {
267
307
  url: page.url ?? url
268
308
  }));
269
309
  };
310
+ /** Fetches the file in a new session and checks it. */
311
+ const downloadFile = async (raw, url, options) => {
312
+ const { provider } = raw;
313
+ const { call, rest: o } = callSettings(options);
314
+ checkFileUrl(provider, url);
315
+ const limit = byteLimit(provider, DOWNLOAD_CEILING, o.maxBytes);
316
+ const { billed, created, id, value } = await inSession(raw, { profile: o.profile }, call, async (session) => {
317
+ const response = await raw.request("POST", `/browsers/${segment(session)}/playwright/execute`, {
318
+ ...call,
319
+ body: {
320
+ code: downloadScript(url, limit),
321
+ timeout_sec: DOWNLOAD_SCRIPT_SECONDS
322
+ }
323
+ });
324
+ const body = z.parse(ExecuteResponse, response);
325
+ if (body.success !== true) throw new FieldworkError("ProviderError", `kernel could not download ${url}: ${body.error ?? "the script failed without an error"}`, {
326
+ cause: response,
327
+ provider
328
+ });
329
+ return {
330
+ file: z.parse(FetchedFile, body.result),
331
+ response
332
+ };
333
+ });
334
+ const { file, response } = value;
335
+ if (file.tooLarge !== void 0) throw tooLarge(provider, url, file.tooLarge, limit);
336
+ if (file.status !== void 0 && file.status >= 200 && file.status <= 299 && file.data === void 0) throw new FieldworkError("ProviderError", `kernel downloaded ${url} but the script returned no bytes`, {
337
+ cause: response,
338
+ provider
339
+ });
340
+ const { headers } = file;
341
+ return presentFile(provider, {
342
+ body: { base64: file.data ?? "" },
343
+ contentType: header(headers, "content-type"),
344
+ headers,
345
+ meta: meta({
346
+ requestId: id,
347
+ units: { uptime_ms: billed.uptimeMs },
348
+ warnings: billed.warning
349
+ }),
350
+ raw: {
351
+ browser: created,
352
+ execute: response
353
+ },
354
+ requested: url,
355
+ statusCode: file.status,
356
+ url: file.url ?? url
357
+ }, limit);
358
+ };
270
359
  /**
271
- * An adapter for Kernel: read and browser. Pass it to `new Fieldwork({ adapter })`.
360
+ * An adapter for Kernel: read, download and browser. Pass it to `new Fieldwork({ adapter })`.
272
361
  *
273
362
  * Throws `Unauthorized` when neither `apiKey` nor `KERNEL_API_KEY` is set.
274
363
  */
@@ -312,6 +401,7 @@ const kernel = (config = {}) => {
312
401
  });
313
402
  }
314
403
  },
404
+ download: async (url, options) => await downloadFile(raw, url, options),
315
405
  read: async (url, options) => await readPage(raw, url, options)
316
406
  },
317
407
  raw
@@ -1,4 +1,4 @@
1
- import { C as DocumentInput, H as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { C as DocumentInput, T as DocumentUrl, W as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Settings for `llamaparse()`. */
3
3
  export interface LlamaParseConfig {
4
4
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -1,5 +1,5 @@
1
- import { B as Page, D as Extraction, L as MonitorEvents, M as ImageSearch, R as MonitorInfo, V as PageBatch, Y as Research, Z as SearchResponse, a as RawClient, b as Decisions, g as Condition, l as Answer, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion, z as MonitorSchedule } from "./adapter-DuJkoVWY.js";
2
- import { t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, B as MonitorInfo, H as Page, P as ImageSearch, U as PageBatch, V as MonitorSchedule, Z as Research, a as RawClient, b as Decisions, g as Condition, k as Extraction, l as Answer, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
+ import { t as OutputSchema } from "./schema-BFjS6CSz.js";
3
3
  import "./util-DhYr1OS3.js";
4
4
  /** Settings for `parallel()`. */
5
5
  interface ParallelConfig {
@@ -1,5 +1,5 @@
1
- import { J as Recency, Y as Research, Z as SearchResponse, a as RawClient, b as Decisions, l as Answer, p as CallOptions, t as Adapter, y as DecisionQuestion } from "./adapter-DuJkoVWY.js";
2
- import { t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, X as Recency, Z as Research, a as RawClient, b as Decisions, l as Answer, p as CallOptions, t as Adapter, y as DecisionQuestion } from "./adapter-DQrBP1tj.js";
2
+ import { t as OutputSchema } from "./schema-BFjS6CSz.js";
3
3
  /** Settings for `perplexity()`. */
4
4
  interface PerplexityConfig {
5
5
  /** Defaults to the PERPLEXITY_API_KEY environment variable. */
package/dist/reducto.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as DocumentInput, H as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { C as DocumentInput, T as DocumentUrl, W as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  /** Settings for `reducto()`. */
3
3
  export interface ReductoConfig {
4
4
  /** Defaults to the REDUCTO_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { N as JsonSchema } from "./adapter-DuJkoVWY.js";
1
+ import { F as JsonSchema } from "./adapter-DQrBP1tj.js";
2
2
  /** Vendor-specific parameters a schema library may accept. */
3
3
  type LibraryOptions = JsonSchema;
4
4
  /** The path segment interface of an issue. */
package/dist/serpapi.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { J as Recency, M as ImageSearch, Z as SearchResponse, a as RawClient, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DuJkoVWY.js";
1
+ import { $ as SearchResponse, P as ImageSearch, X as Recency, a as RawClient, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
2
2
  import "./util-DhYr1OS3.js";
3
3
  /** Settings for `serpapi()`. */
4
4
  interface SerpApiConfig {
package/dist/tavily.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as Page, J as Recency, M as ImageSearch, V as PageBatch, Y as Research, Z as SearchResponse, _ as Crawl, a as RawClient, et as SiteMap, l as Answer, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DuJkoVWY.js";
2
- import { t as OutputSchema } from "./schema-_iwQlBZE.js";
1
+ import { $ as SearchResponse, H as Page, P as ImageSearch, U as PageBatch, X as Recency, Z as Research, _ as Crawl, a as RawClient, l as Answer, nt as SiteMap, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
2
+ import { t as OutputSchema } from "./schema-BFjS6CSz.js";
3
3
  /** Settings for the Tavily adapter. */
4
4
  interface TavilyConfig {
5
5
  /** Defaults to the TAVILY_API_KEY environment variable. */
package/dist/tools.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-Bhl4401B.js";
2
- import { N as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-DuJkoVWY.js";
1
+ import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-DNwEf0Mo.js";
2
+ import { F as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-DQrBP1tj.js";
3
3
  /** Any JSON value. */
4
4
  type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
5
5
  /** A JSON object. A key may be undefined, which reads as absent and is not serialized. */
package/dist/tools.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as FieldworkError } from "./errors-DROZyb9T.js";
2
2
  import { f as refuseTogether } from "./util-BqeRYF2b.js";
3
3
  import { a as isNumber, i as isList, n as isFlag, o as isText, r as isJsonObject, t as joinPath } from "./path-DL5P8XH2.js";
4
- import { t as CAPABILITIES } from "./types-CnomnF-6.js";
4
+ import { t as CAPABILITIES } from "./types-rc8bl8Em.js";
5
5
  import * as z from "zod/mini";
6
6
  // src/tool-specs/schema.ts
7
7
  const described = (schema, description) => description === void 0 ? schema : {
@@ -16,6 +16,7 @@ const CAPABILITIES = [
16
16
  "act",
17
17
  "browser",
18
18
  "parse",
19
+ "download",
19
20
  "monitor",
20
21
  "usage"
21
22
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howells/fieldwork-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "One API for web search, page reading, extraction, crawling, answers, research, browser sessions, monitoring and document parsing across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.",
5
5
  "keywords": [
6
6
  "agents",