@howells/fieldwork-sdk 0.10.1 → 0.11.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 +36 -4
- package/dist/{adapter-DQrBP1tj.d.ts → adapter-B8kAAAgF.d.ts} +25 -2
- package/dist/brave.d.ts +1 -1
- package/dist/brave.js +3 -3
- package/dist/browserbase.d.ts +1 -1
- package/dist/browserbase.js +4 -4
- package/dist/{document-DOzhDFFt.js → document-DMIUCoDA.js} +2 -2
- package/dist/{download-gyAym9vL.js → download-CP8noBdX.js} +18 -8
- package/dist/{errors-DROZyb9T.js → errors-DkFJysIM.js} +9 -0
- package/dist/exa.d.ts +2 -2
- package/dist/exa.js +5 -5
- package/dist/{fieldwork-DNwEf0Mo.d.ts → fieldwork-BrfoehvG.d.ts} +10 -1
- package/dist/firecrawl.d.ts +2 -2
- package/dist/firecrawl.js +10 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -2
- package/dist/{job-DBhGs7Ha.js → job-DnavRq_s.js} +3 -3
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +29 -13
- package/dist/llamaparse.d.ts +1 -1
- package/dist/llamaparse.js +5 -5
- package/dist/parallel.d.ts +3 -3
- package/dist/parallel.js +5 -5
- package/dist/{parse-lMLcxUsG.js → parse-Q7H4mrnO.js} +2 -2
- package/dist/perplexity.d.ts +2 -2
- package/dist/perplexity.js +5 -5
- package/dist/reducto.d.ts +1 -1
- package/dist/reducto.js +5 -5
- package/dist/{schema-COAaWnZB.js → schema--iU4AXSM.js} +1 -1
- package/dist/{schema-BFjS6CSz.d.ts → schema-CAPSX7yQ.d.ts} +1 -1
- package/dist/serpapi.d.ts +62 -4
- package/dist/serpapi.js +230 -5
- package/dist/tavily.d.ts +2 -2
- package/dist/tavily.js +5 -5
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +173 -123
- package/dist/{types-rc8bl8Em.js → types-mq6d6YOK.js} +1 -0
- package/dist/{util-BqeRYF2b.js → util-DFUXQX6v.js} +1 -1
- package/package.json +2 -2
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, parsing documents and downloading files, across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.
|
|
3
|
+
One API for searching the web, finding where an image appears, 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
|
|
@@ -28,6 +28,7 @@ Each instance has only the methods its provider offers, so a call the provider c
|
|
|
28
28
|
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
29
29
|
| `search(query)` | yes | yes | yes | yes | yes | yes | yes | yes | | | |
|
|
30
30
|
| `images(query)` | | yes | yes | yes | | yes | yes | | | | |
|
|
31
|
+
| `reverseImage(imageUrl)` | | | | | | | yes | | | | |
|
|
31
32
|
| `read(url)` | yes | yes | yes | yes | | | | yes | yes | | |
|
|
32
33
|
| `readMany(urls)` | yes | yes | yes | yes | | | | | | | |
|
|
33
34
|
| `extract(url, { schema })` | yes | yes | | yes | | | | | | | |
|
|
@@ -52,6 +53,7 @@ Each instance has only the methods its provider offers, so a call the provider c
|
|
|
52
53
|
- `decide` answers closed questions about a context: yes or no, a choice, or a score on a rubric, each with a probability.
|
|
53
54
|
- `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
55
|
- `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).
|
|
56
|
+
- `reverseImage` takes an image's URL and returns the pages it appears on. Only SerpApi offers it, because it is the only provider that accepts an image as input. `engine` chooses where it looks: `"google_lens"` (the default), `"google_reverse_image"`, `"bing_reverse_image"` or `"yandex_images"`. Each match has `sourceUrl`, the page, on every engine; `url` is the matched image, and is absent from a Lens exact match, which names only the page. `kind` is `"exact"` for the same image and `"visual"` for a similar one, and is left out where the engine does not say. See [Reverse image search](#reverse-image-search).
|
|
55
57
|
- `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`).
|
|
56
58
|
|
|
57
59
|
### Options
|
|
@@ -68,7 +70,8 @@ Options are typed per provider. An option means the same thing under the same na
|
|
|
68
70
|
| `country` | An ISO 3166-1 code such as `"GB"`. |
|
|
69
71
|
| `language` | An ISO 639-1 code such as `"de"`. |
|
|
70
72
|
| `schema`, `prompt` | A JSON Schema or a Standard Schema such as Zod for structured output, and extraction instructions in plain words. |
|
|
71
|
-
| `query` | On `read`: return the passages that answer it as `excerpts`. |
|
|
73
|
+
| `query` | On `read`: return the passages that answer it as `excerpts`. On `reverseImage`: text to refine the search with. |
|
|
74
|
+
| `match` | On `reverseImage`: `"exact"` for pages showing the same image, `"visual"` for similar ones. |
|
|
72
75
|
| `content` | On `search`: include each result's page text. |
|
|
73
76
|
| `continueFrom` | On `answer` and `research`: the `continuationId` of an earlier result, to ask a follow-up. |
|
|
74
77
|
| `maxBytes` | On `download`: the largest file accepted, in bytes. Defaults to, and may not exceed, the provider's ceiling. |
|
|
@@ -100,6 +103,7 @@ Providers differ in which keywords they accept; Exa reads draft 7 and the others
|
|
|
100
103
|
Every result is normalized and keeps the provider's response in `raw`. Most also carry `meta`: the provider's `requestId`, `usage` (credits, US dollars, or counted units such as tokens) and `warnings`, when the provider returns them.
|
|
101
104
|
|
|
102
105
|
- `search` returns `{ results, answer, images, meta, raw }`. Each result has `url`, `title`, `snippet` and, when the provider has them, `content`, `publishedAt`, `author`, `image`, `favicon` and `score`. Shopping, place, news, scholar and patent results set `kind` and carry `price`, `rating`, `reviewCount` and `place`.
|
|
106
|
+
- `reverseImage` returns `{ results, meta, raw }`. Each match has `sourceUrl` and, when the provider has them, `url` (the matched image), `thumbnailUrl`, `title`, `description`, `width`, `height` and `kind`.
|
|
103
107
|
- `read` returns a `Page`: `url`, `title`, `description`, `markdown`, `html`, `links`, `images`, `image` (the page's main image), `excerpts`, `summary`, `publishedAt`, `author`, `language`, `statusCode` and `screenshot`, as the provider has them. A page that answered 404 or 410 is not returned: `read` throws `NotFound` on every provider, and `readMany` lists the URL in `failed`.
|
|
104
108
|
- `readMany` returns `{ pages, failed }`. A URL that could not be read is listed in `failed` with the reason; it does not throw.
|
|
105
109
|
- `extract` returns `{ data, fields }`. `data` follows your schema; `fields` lists each field's citations when the provider returns them.
|
|
@@ -170,6 +174,33 @@ const digest = await crypto.subtle.digest("SHA-256", file.bytes);
|
|
|
170
174
|
|
|
171
175
|
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
176
|
|
|
177
|
+
### Reverse image search
|
|
178
|
+
|
|
179
|
+
`reverseImage(imageUrl, options)` is SerpApi's. The image must be at a public `http` or `https` URL.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const web = new Fieldwork({ adapter: serpapi() });
|
|
183
|
+
|
|
184
|
+
const { results } = await web.reverseImage("https://example.com/chair.jpg", {
|
|
185
|
+
match: "exact",
|
|
186
|
+
});
|
|
187
|
+
results[0].sourceUrl; // the page the image appears on
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
| `engine` | Reads | `kind` | Options |
|
|
191
|
+
| --- | --- | --- | --- |
|
|
192
|
+
| `google_lens` (default) | `exact_matches` and `visual_matches` | `"exact"` and `"visual"` | `match`, `query`, `country`, `language`, `noCache` |
|
|
193
|
+
| `google_reverse_image` | `image_results` and `visual_matches` | `"visual"` for `visual_matches`; absent for pages | `query`, `country`, `language`, `noCache` |
|
|
194
|
+
| `bing_reverse_image` | `pages_with_this_image` | `"exact"` | `limit` (sent as `count`, 1 to 150), `market`, `noCache` |
|
|
195
|
+
| `yandex_images` | "About the image" `image_results` | absent | `noCache` |
|
|
196
|
+
|
|
197
|
+
- `match` is Lens's `type`: `"exact"` is `exact_matches` and `"visual"` is `visual_matches`. Left out, Lens answers its default, which lists visual matches only, so ask for `"exact"` to get exact ones. The other engines cannot narrow by kind, so they refuse `match`.
|
|
198
|
+
- Lens applies `query` only to visual matches, so `query` with `match: "exact"` throws `InvalidRequest`.
|
|
199
|
+
- Only Bing has a result count. Lens, Google reverse image and Yandex refuse `limit` rather than cut the list after paying for it, as `images` does.
|
|
200
|
+
- Bing's `related_content` (similar images) is left out of `results`; it stays in `raw`. Yandex's "Similar images" tab names no source page, so it is not offered.
|
|
201
|
+
- Lens returns most exact matches' pages as Google redirect links (`google.com/goto?url=…`), whether or not `noCache` is set. The link is kept as received, and `meta.warnings` says how many there are; a GET on the link answers with a redirect to the page.
|
|
202
|
+
- `siteName` is the site's name as the engine shows it ("Mark D. Sikes", "Architectural Digest") and `publishedAt` the page's date, where Lens gives one. Both help tell an original source from a copy.
|
|
203
|
+
|
|
173
204
|
## Choosing a provider per capability
|
|
174
205
|
|
|
175
206
|
`router` sends each capability to exactly one adapter:
|
|
@@ -203,9 +234,10 @@ Every failure is a `FieldworkError`. It carries:
|
|
|
203
234
|
- `retryable`: whether repeating the same call can succeed;
|
|
204
235
|
- `retryAfter`, in seconds, when the provider sent one;
|
|
205
236
|
- `jobId`, when a job had already started;
|
|
237
|
+
- `meta`, when the provider billed the call before it failed: the usage it reported, in the shape a result's `meta` has, such as `meta.usage.credits` for a Firecrawl download that reached a web page;
|
|
206
238
|
- the provider's response, as `cause`.
|
|
207
239
|
|
|
208
|
-
`error.toJSON()` returns these fields without the provider's response
|
|
240
|
+
`error.toJSON()` returns these fields without the provider's response or `meta`.
|
|
209
241
|
|
|
210
242
|
| Code | What happened | What to do |
|
|
211
243
|
| --- | --- | --- |
|
|
@@ -236,7 +268,7 @@ await web.search("tiles", { retries: 0 }); // this call only
|
|
|
236
268
|
|
|
237
269
|
## Agent tools
|
|
238
270
|
|
|
239
|
-
`@howells/fieldwork-sdk/tools` turns an instance into tool definitions for a model, one per capability or group method: `search_web`, `search_images`, `read_page`, `read_pages`, `extract_values`, `read_product`, `map_site`, `crawl_site`, `answer_question`, `research_question`, `find_entities`, `make_decisions`, `parse_document`, `check_usage`, `run_browser_script`, `open_browser`, `close_browser`, `create_monitor`, `get_monitor`, `list_monitors`, `delete_monitor` and `list_monitor_events`. Each tool has:
|
|
271
|
+
`@howells/fieldwork-sdk/tools` turns an instance into tool definitions for a model, one per capability or group method: `search_web`, `search_images`, `search_by_image`, `read_page`, `read_pages`, `extract_values`, `read_product`, `map_site`, `crawl_site`, `answer_question`, `research_question`, `find_entities`, `make_decisions`, `parse_document`, `check_usage`, `run_browser_script`, `open_browser`, `close_browser`, `create_monitor`, `get_monitor`, `list_monitors`, `delete_monitor` and `list_monitor_events`. Each tool has:
|
|
240
272
|
|
|
241
273
|
- a description that says when to use it and which tool to use instead;
|
|
242
274
|
- a JSON Schema input that lists only the options its provider supports;
|
|
@@ -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", "download", "monitor", "usage"];
|
|
4
|
+
declare const CAPABILITIES: readonly ["search", "images", "reverseImage", "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
|
/**
|
|
@@ -133,6 +133,29 @@ interface ImageSearch {
|
|
|
133
133
|
meta?: Meta;
|
|
134
134
|
raw: unknown;
|
|
135
135
|
}
|
|
136
|
+
/** Whether a reverse image match is the same image or only a similar one. */
|
|
137
|
+
type MatchKind = "exact" | "visual";
|
|
138
|
+
/**
|
|
139
|
+
* One match from `reverseImage`. `sourceUrl` is the page the image appears on
|
|
140
|
+
* and is always there. `url` is the matched image itself, and is absent when the
|
|
141
|
+
* provider names only the page (Google Lens exact matches).
|
|
142
|
+
*/
|
|
143
|
+
interface ImageMatch extends Omit<ImageResult, "sourceUrl" | "url"> {
|
|
144
|
+
sourceUrl: string;
|
|
145
|
+
url?: string;
|
|
146
|
+
/** "exact" for the same image, "visual" for a similar one; absent when the provider does not say. */
|
|
147
|
+
kind?: MatchKind;
|
|
148
|
+
/** The name of the site the page belongs to, as the provider shows it, such as "Mark D. Sikes". */
|
|
149
|
+
siteName?: string;
|
|
150
|
+
/** When the page was published, as the provider reports it. */
|
|
151
|
+
publishedAt?: string;
|
|
152
|
+
}
|
|
153
|
+
/** What `reverseImage` returns. */
|
|
154
|
+
interface ReverseImageSearch {
|
|
155
|
+
results: ImageMatch[];
|
|
156
|
+
meta?: Meta;
|
|
157
|
+
raw: unknown;
|
|
158
|
+
}
|
|
136
159
|
/** What `read` returns: one page, in the formats the call asked for. */
|
|
137
160
|
interface Page {
|
|
138
161
|
url: string;
|
|
@@ -631,4 +654,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
|
|
|
631
654
|
* It returns its argument unchanged; write a custom adapter with it.
|
|
632
655
|
*/
|
|
633
656
|
declare const defineAdapter: <Name extends string, Ops extends Operations, Raw = RawClient>(adapter: Adapter<Name, Ops, Raw>) => Adapter<Name, Ops, Raw>;
|
|
634
|
-
export {
|
|
657
|
+
export { Research as $, FailedUrl as A, MonitorEvent as B, DocumentInput as C, DownloadedFile as D, DownloadOptions as E, ImageSearch as F, PageBatch as G, MonitorInfo as H, JsonSchema as I, Price as J, ParsedDocument as K, LineBox as L, GROUP_CAPABILITIES as M, ImageMatch as N, Entity as O, ImageResult as P, Recency as Q, MatchKind as R, DocumentBlock as S, DocumentUrl as T, MonitorSchedule as U, MonitorEvents as V, Page as W, ProductImage as X, Product as Y, ProductVariant as Z, Crawl as _, RawClient as a, SiteMap as at, Decisions as b, ActResult as c, WordBox as ct, BrowserSession as d, ReverseImageSearch as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, SiteLink as it, FieldSource as j, Extraction as k, Answer as l, Capability as m, AnyAdapter as n, SearchResponse as nt, RequestOptions as o, TableCell as ot, CallOptions as p, Place as q, Operations as r, SearchResult as rt, AccountUsage as s, Usage as st, Adapter as t, RunStatus as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, Meta as z };
|
package/dist/brave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as ImageSearch, Q as Recency, a as RawClient, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
/** Settings for `brave()`. */
|
|
3
3
|
interface BraveConfig {
|
|
4
4
|
/** Defaults to the BRAVE_API_KEY environment variable. */
|
package/dist/brave.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, l as optionalBoolean, o as nonEmptyString, r as arrayOf, v as recordOf } from "./parse-
|
|
4
|
-
import { a as compact, c as parseJson, f as refuseTogether, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, l as optionalBoolean, o as nonEmptyString, r as arrayOf, v as recordOf } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { a as compact, c as parseJson, f as refuseTogether, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
5
5
|
import * as z from "zod/mini";
|
|
6
6
|
// src/adapters/brave/response.ts
|
|
7
7
|
/** The `query` block every search response carries. */
|
package/dist/browserbase.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as DownloadedFile, E as DownloadOptions, W as Page, a as RawClient, d as BrowserSession, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
/** Settings for `browserbase()`. */
|
|
3
3
|
export interface BrowserbaseConfig {
|
|
4
4
|
/** Defaults to the BROWSERBASE_API_KEY environment variable. */
|
package/dist/browserbase.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
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-
|
|
4
|
-
import { a as compact, f as refuseTogether, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-
|
|
5
|
-
import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.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-Q7H4mrnO.js";
|
|
4
|
+
import { a as compact, f as refuseTogether, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
5
|
+
import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-CP8noBdX.js";
|
|
6
6
|
import * as z from "zod/mini";
|
|
7
7
|
// src/adapters/browserbase/response.ts
|
|
8
8
|
/** `POST /v1/sessions`. The id keeps the value as it arrived, for the error raised when there is none. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
2
|
-
import { f as refuseTogether } from "./util-
|
|
1
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
2
|
+
import { f as refuseTogether } from "./util-DFUXQX6v.js";
|
|
3
3
|
import * as z from "zod/mini";
|
|
4
4
|
// src/document.ts
|
|
5
5
|
/** Content types of the document files parsers commonly take, by extension. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
1
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
2
2
|
// src/download.ts
|
|
3
3
|
/** One mebibyte, the unit the providers' ceilings are stated in. */
|
|
4
4
|
const MIB = 1048576;
|
|
@@ -22,8 +22,11 @@ const byteLimit = (provider, ceiling, maxBytes) => {
|
|
|
22
22
|
if (maxBytes > ceiling) throw invalidRequest(provider, `downloads at most ${ceiling} bytes; maxBytes ${maxBytes} is larger`);
|
|
23
23
|
return maxBytes;
|
|
24
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`, {
|
|
25
|
+
/** The error for a file over the limit, with what the provider billed for the fetch when it billed one. */
|
|
26
|
+
const tooLarge = (provider, url, size, limit, meta) => new FieldworkError("TooLarge", `${provider} could not download ${url}: the file is ${size === void 0 ? "larger than" : `${size} bytes, over`} the limit of ${limit} bytes`, {
|
|
27
|
+
meta,
|
|
28
|
+
provider
|
|
29
|
+
});
|
|
27
30
|
/** Content types that are web pages rather than files. */
|
|
28
31
|
const PAGE_TYPES = /* @__PURE__ */ new Set(["text/html", "application/xhtml+xml"]);
|
|
29
32
|
/** Statuses that mean the file is not there. */
|
|
@@ -32,14 +35,16 @@ const GONE = /* @__PURE__ */ new Set([404, 410]);
|
|
|
32
35
|
const header = (headers, name) => Object.entries(headers ?? {}).find(([key]) => key.toLowerCase() === name)?.[1];
|
|
33
36
|
/** Throws `NotFound` for a 404 or 410 and `ProviderError` for any other status that is not 2xx. */
|
|
34
37
|
const checkStatus = (provider, fetched) => {
|
|
35
|
-
const { requested, statusCode } = fetched;
|
|
38
|
+
const { meta, requested, statusCode } = fetched;
|
|
36
39
|
if (statusCode === void 0) return;
|
|
37
40
|
if (GONE.has(statusCode)) throw new FieldworkError("NotFound", `${provider} could not download ${requested}: it answered ${statusCode}`, {
|
|
41
|
+
meta,
|
|
38
42
|
provider,
|
|
39
43
|
status: statusCode
|
|
40
44
|
});
|
|
41
45
|
if (statusCode < 200 || statusCode > 299) throw new FieldworkError("ProviderError", `${provider} could not download ${requested}: it answered ${statusCode}`, {
|
|
42
46
|
cause: fetched.raw,
|
|
47
|
+
meta,
|
|
43
48
|
provider,
|
|
44
49
|
status: statusCode
|
|
45
50
|
});
|
|
@@ -48,19 +53,24 @@ const checkStatus = (provider, fetched) => {
|
|
|
48
53
|
* The checked file. Throws `NotFound` for a 404 or 410, `ProviderError` for
|
|
49
54
|
* any other status that is not 2xx or a reply with no content type,
|
|
50
55
|
* `NotAFile` for an HTML page, and `TooLarge` for more bytes than `limit`.
|
|
56
|
+
* Each error carries the fetch's `meta`: the provider billed it.
|
|
51
57
|
*/
|
|
52
58
|
const presentFile = (provider, fetched, limit) => {
|
|
53
|
-
const { requested, statusCode } = fetched;
|
|
59
|
+
const { meta, requested, statusCode } = fetched;
|
|
54
60
|
checkStatus(provider, fetched);
|
|
55
61
|
const { contentType } = fetched;
|
|
56
62
|
if (contentType === void 0 || contentType === "") throw new FieldworkError("ProviderError", `${provider} downloaded ${requested} but reported no content type`, {
|
|
57
63
|
cause: fetched.raw,
|
|
64
|
+
meta,
|
|
58
65
|
provider
|
|
59
66
|
});
|
|
60
67
|
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`, {
|
|
68
|
+
if (PAGE_TYPES.has(mediaType)) throw new FieldworkError("NotAFile", `${provider} could not download ${requested}: it is a web page (${contentType}), not a file`, {
|
|
69
|
+
meta,
|
|
70
|
+
provider
|
|
71
|
+
});
|
|
62
72
|
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);
|
|
73
|
+
if (bytes.byteLength > limit) throw tooLarge(provider, requested, bytes.byteLength, limit, meta);
|
|
64
74
|
return {
|
|
65
75
|
bytes,
|
|
66
76
|
contentType,
|
|
@@ -68,7 +78,7 @@ const presentFile = (provider, fetched, limit) => {
|
|
|
68
78
|
etag: header(fetched.headers, "etag"),
|
|
69
79
|
lastModified: header(fetched.headers, "last-modified")
|
|
70
80
|
},
|
|
71
|
-
...
|
|
81
|
+
...meta && { meta },
|
|
72
82
|
raw: fetched.raw,
|
|
73
83
|
size: bytes.byteLength,
|
|
74
84
|
...statusCode !== void 0 && { statusCode },
|
|
@@ -20,6 +20,13 @@ var FieldworkError = class extends Error {
|
|
|
20
20
|
* set, because repeating the call would start a second job; resume it.
|
|
21
21
|
*/
|
|
22
22
|
retryable;
|
|
23
|
+
/**
|
|
24
|
+
* What the provider reported for a call it billed before the failure, in
|
|
25
|
+
* the shape a result's `meta` has: `meta.usage.credits` for Firecrawl's
|
|
26
|
+
* scrape, `meta.usage.units.uptime_ms` for a Kernel session. Absent when
|
|
27
|
+
* the call failed before the provider billed anything.
|
|
28
|
+
*/
|
|
29
|
+
meta;
|
|
23
30
|
constructor(code, message, options = {}) {
|
|
24
31
|
super(message, { cause: options.cause });
|
|
25
32
|
this.code = code;
|
|
@@ -27,6 +34,7 @@ var FieldworkError = class extends Error {
|
|
|
27
34
|
this.status = options.status;
|
|
28
35
|
this.retryAfter = options.retryAfter;
|
|
29
36
|
this.jobId = options.jobId;
|
|
37
|
+
this.meta = options.meta;
|
|
30
38
|
this.retryable = options.jobId === void 0 && (options.retryable ?? isRetryable(code, options.status));
|
|
31
39
|
}
|
|
32
40
|
/** The fields an agent or a log needs, without the provider's response. */
|
|
@@ -58,6 +66,7 @@ const withJob = (error, jobId) => {
|
|
|
58
66
|
return new FieldworkError(error.code, error.message, {
|
|
59
67
|
cause: error.cause,
|
|
60
68
|
jobId,
|
|
69
|
+
meta: error.meta,
|
|
61
70
|
provider: error.provider,
|
|
62
71
|
retryAfter: error.retryAfter,
|
|
63
72
|
status: error.status
|
package/dist/exa.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, G as PageBatch, H as MonitorInfo, U as MonitorSchedule, V as MonitorEvents, W as Page, a as RawClient, k as Extraction, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
|
|
3
3
|
/** Settings for the Exa adapter. */
|
|
4
4
|
interface ExaConfig {
|
|
5
5
|
/** Defaults to the EXA_API_KEY environment variable. */
|
package/dist/exa.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, _ as optionalStructure, a as looseObject, b as warningEntry, d as optionalId, f as optionalNumber, g as optionalStringOrNumber, h as optionalString, i as both, l as optionalBoolean, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source } from "./parse-
|
|
4
|
-
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-
|
|
5
|
-
import { n as jsonSchemaOf, t as checkOutput } from "./schema
|
|
6
|
-
import { a as compact, c as parseJson, d as record, i as citationsOf, m as uniqueCitations, o as hours, p as requireJobId, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, _ as optionalStructure, a as looseObject, b as warningEntry, d as optionalId, f as optionalNumber, g as optionalStringOrNumber, h as optionalString, i as both, l as optionalBoolean, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
5
|
+
import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
|
|
6
|
+
import { a as compact, c as parseJson, d as record, i as citationsOf, m as uniqueCitations, o as hours, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/u;
|
|
9
9
|
/** The search types that take `additionalQueries`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as Capability, n as AnyAdapter } from "./adapter-
|
|
1
|
+
import { m as Capability, n as AnyAdapter, z as Meta } from "./adapter-B8kAAAgF.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. */
|
|
@@ -37,6 +37,8 @@ interface FieldworkErrorOptions {
|
|
|
37
37
|
retryable?: boolean;
|
|
38
38
|
/** What the failure came from, such as the provider's parsed error body or the underlying fetch error. */
|
|
39
39
|
cause?: unknown;
|
|
40
|
+
/** What the provider reported for a call it billed before the failure. */
|
|
41
|
+
meta?: Meta;
|
|
40
42
|
}
|
|
41
43
|
/** The one error type every adapter throws, with a normalized code. */
|
|
42
44
|
declare class FieldworkError extends Error {
|
|
@@ -59,6 +61,13 @@ declare class FieldworkError extends Error {
|
|
|
59
61
|
* set, because repeating the call would start a second job; resume it.
|
|
60
62
|
*/
|
|
61
63
|
readonly retryable: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* What the provider reported for a call it billed before the failure, in
|
|
66
|
+
* the shape a result's `meta` has: `meta.usage.credits` for Firecrawl's
|
|
67
|
+
* scrape, `meta.usage.units.uptime_ms` for a Kernel session. Absent when
|
|
68
|
+
* the call failed before the provider billed anything.
|
|
69
|
+
*/
|
|
70
|
+
readonly meta?: Meta;
|
|
62
71
|
constructor(code: FieldworkErrorCode, message: string, options?: FieldworkErrorOptions);
|
|
63
72
|
/** The fields an agent or a log needs, without the provider's response. */
|
|
64
73
|
toJSON(): {
|
package/dist/firecrawl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as ImageSearch, G as PageBatch, H as MonitorInfo, K as ParsedDocument, Q as Recency, U as MonitorSchedule, V as MonitorEvents, W as Page, Y as Product, _ as Crawl, a as RawClient, at as SiteMap, c as ActResult, d as BrowserSession, k as Extraction, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
|
|
3
3
|
/** Settings for the Firecrawl adapter. */
|
|
4
4
|
interface FirecrawlConfig {
|
|
5
5
|
/** Defaults to the FIRECRAWL_API_KEY environment variable. */
|
package/dist/firecrawl.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, b as warningEntry, c as optionalArrayOf, d as optionalId, f as optionalNumber, h as optionalString, i as both, l as optionalBoolean, m as optionalScalar, n as anything, p as optionalObject, r as arrayOf, s as optionalAnyString, u as optionalFirstString, v as recordOf } from "./parse-
|
|
4
|
-
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-
|
|
5
|
-
import { n as jsonSchemaOf, t as checkOutput } from "./schema
|
|
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-
|
|
7
|
-
import { a as presentFile, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-
|
|
8
|
-
import { a as mediaTypeOf, n as documentPart, o as refuseLarger, t as MEDIA_TYPES } from "./document-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, b as warningEntry, c as optionalArrayOf, d as optionalId, f as optionalNumber, h as optionalString, i as both, l as optionalBoolean, m as optionalScalar, n as anything, p as optionalObject, r as arrayOf, s as optionalAnyString, u as optionalFirstString, v as recordOf } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
5
|
+
import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
|
|
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-DFUXQX6v.js";
|
|
7
|
+
import { a as presentFile, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-CP8noBdX.js";
|
|
8
|
+
import { a as mediaTypeOf, n as documentPart, o as refuseLarger, t as MEDIA_TYPES } from "./document-DMIUCoDA.js";
|
|
9
9
|
import * as z from "zod/mini";
|
|
10
10
|
// src/adapters/firecrawl/shared.ts
|
|
11
11
|
const provider = "firecrawl";
|
|
@@ -1035,14 +1035,16 @@ const downloadFile = async (raw, url, options) => {
|
|
|
1035
1035
|
}
|
|
1036
1036
|
const { data, warning } = z.parse(ScrapeResponse, response);
|
|
1037
1037
|
const { metadata } = data;
|
|
1038
|
+
const meta = pageMeta(data, warning.notes);
|
|
1038
1039
|
if (data.rawBase64 === void 0) throw new FieldworkError("ProviderError", `firecrawl downloaded ${url} but returned no rawBase64 content`, {
|
|
1039
1040
|
cause: response,
|
|
1041
|
+
meta,
|
|
1040
1042
|
provider
|
|
1041
1043
|
});
|
|
1042
1044
|
return presentFile(provider, {
|
|
1043
1045
|
body: { base64: data.rawBase64 },
|
|
1044
1046
|
contentType: metadata.contentType,
|
|
1045
|
-
meta
|
|
1047
|
+
meta,
|
|
1046
1048
|
raw: response,
|
|
1047
1049
|
requested: url,
|
|
1048
1050
|
statusCode: metadata.statusCode,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-
|
|
3
|
-
import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, A as FailedUrl, B as MonitorEvent, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as ImageSearch, G as PageBatch, H as MonitorInfo, I as JsonSchema, J as Price, K as ParsedDocument, L as LineBox, M as GROUP_CAPABILITIES, N as ImageMatch, O as Entity, P as ImageResult, Q as Recency, R as MatchKind, S as DocumentBlock, T as DocumentUrl, U as MonitorSchedule, V as MonitorEvents, W as Page, X as ProductImage, Y as Product, Z as ProductVariant, _ as Crawl, a as RawClient, at as SiteMap, b as Decisions, c as ActResult, ct as WordBox, d as BrowserSession, et as ReverseImageSearch, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, it as SiteLink, j as FieldSource, k as Extraction, l as Answer, m as Capability, n as AnyAdapter, nt as SearchResponse, o as RequestOptions, ot as TableCell, p as CallOptions, q as Place, r as Operations, rt as SearchResult, s as AccountUsage, st as Usage, t as Adapter, tt as RunStatus, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as Meta } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-BrfoehvG.js";
|
|
3
|
+
import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-CAPSX7yQ.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, 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 };
|
|
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, ImageMatch, ImageResult, ImageSearch, JsonSchema, LineBox, MatchKind, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, type OutputSchema, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, ReverseImageSearch, 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
|
-
import { t as FieldworkError } from "./errors-
|
|
3
|
-
import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-
|
|
2
|
+
import { t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-mq6d6YOK.js";
|
|
4
4
|
// src/fieldwork.ts
|
|
5
5
|
/**
|
|
6
6
|
* The adapter's operation for a capability, bound to its `operations` object
|
|
@@ -59,6 +59,7 @@ var FieldworkClient = class {
|
|
|
59
59
|
read: has("read"),
|
|
60
60
|
readMany: has("readMany"),
|
|
61
61
|
research: has("research"),
|
|
62
|
+
reverseImage: has("reverseImage"),
|
|
62
63
|
search: has("search"),
|
|
63
64
|
usage: has("usage")
|
|
64
65
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as withJob, t as FieldworkError } from "./errors-
|
|
2
|
-
import { D as sleep, O as stopped } from "./parse-
|
|
3
|
-
import { p as requireJobId } from "./util-
|
|
1
|
+
import { i as withJob, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
2
|
+
import { D as sleep, O as stopped } from "./parse-Q7H4mrnO.js";
|
|
3
|
+
import { p as requireJobId } from "./util-DFUXQX6v.js";
|
|
4
4
|
import * as z from "zod/mini";
|
|
5
5
|
// src/job.ts
|
|
6
6
|
/** The first wait between checks when `interval` is unset, and the longest. */
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DownloadedFile, E as DownloadOptions,
|
|
1
|
+
import { D as DownloadedFile, E as DownloadOptions, W as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
/** Settings for `kernel()`. */
|
|
3
3
|
export interface KernelConfig {
|
|
4
4
|
/** Defaults to the KERNEL_API_KEY environment variable. */
|
package/dist/kernel.js
CHANGED
|
@@ -1,9 +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-
|
|
3
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
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-
|
|
5
|
-
import { a as compact, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-
|
|
6
|
-
import { r as runJob } from "./job-
|
|
2
|
+
import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-CP8noBdX.js";
|
|
3
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.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-Q7H4mrnO.js";
|
|
5
|
+
import { a as compact, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
6
|
+
import { r as runJob } from "./job-DnavRq_s.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
import TurndownService from "turndown";
|
|
9
9
|
// src/adapters/kernel/response.ts
|
|
@@ -122,10 +122,17 @@ const billedTime = async (raw, id, call) => {
|
|
|
122
122
|
return { warning: error instanceof FieldworkError && error.code === "Timeout" && error.status === void 0 && call.signal?.aborted !== true ? `kernel did not report the session's billed time within ${BILLED_TIME_WAIT / 1e3} seconds` : `could not get the session's billed time: ${error instanceof Error ? error.message : String(error)}` };
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
|
+
/** A session's billed time as `meta`: `usage.units.uptime_ms`, or a warning saying why it is missing. */
|
|
126
|
+
const sessionMeta = (id, billed) => meta({
|
|
127
|
+
requestId: id,
|
|
128
|
+
units: { uptime_ms: billed.uptimeMs },
|
|
129
|
+
warnings: billed.warning
|
|
130
|
+
});
|
|
125
131
|
/**
|
|
126
132
|
* Runs `work` in a new headless session and deletes the session whether or
|
|
127
133
|
* not the work succeeded. A failure whose session could not be deleted fails
|
|
128
|
-
* with its own error, naming the session that still bills
|
|
134
|
+
* with its own error, naming the session that still bills; one whose session
|
|
135
|
+
* was deleted carries the session's billed time as `meta`.
|
|
129
136
|
*/
|
|
130
137
|
const inSession = async (raw, o, call, work) => {
|
|
131
138
|
const { provider } = raw;
|
|
@@ -147,7 +154,18 @@ const inSession = async (raw, o, call, work) => {
|
|
|
147
154
|
const unreleased = await release(raw, id, call.retries);
|
|
148
155
|
if (!done.ok) {
|
|
149
156
|
const { error } = done;
|
|
150
|
-
if (unreleased === void 0)
|
|
157
|
+
if (unreleased === void 0) {
|
|
158
|
+
if (!(error instanceof FieldworkError)) throw error;
|
|
159
|
+
throw new FieldworkError(error.code, error.message, {
|
|
160
|
+
cause: error.cause,
|
|
161
|
+
jobId: error.jobId,
|
|
162
|
+
meta: sessionMeta(id, await billedTime(raw, id, call)),
|
|
163
|
+
provider: error.provider,
|
|
164
|
+
retryAfter: error.retryAfter,
|
|
165
|
+
retryable: error.retryable,
|
|
166
|
+
status: error.status
|
|
167
|
+
});
|
|
168
|
+
}
|
|
151
169
|
const message = `${error instanceof Error ? error.message : String(error)}; also ${leakText(id, unreleased)}`;
|
|
152
170
|
throw error instanceof FieldworkError ? new FieldworkError(error.code, message, {
|
|
153
171
|
cause: error,
|
|
@@ -332,9 +350,11 @@ const downloadFile = async (raw, url, options) => {
|
|
|
332
350
|
};
|
|
333
351
|
});
|
|
334
352
|
const { file, response } = value;
|
|
335
|
-
|
|
353
|
+
const billedMeta = sessionMeta(id, billed);
|
|
354
|
+
if (file.tooLarge !== void 0) throw tooLarge(provider, url, file.tooLarge, limit, billedMeta);
|
|
336
355
|
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
356
|
cause: response,
|
|
357
|
+
meta: billedMeta,
|
|
338
358
|
provider
|
|
339
359
|
});
|
|
340
360
|
const { headers } = file;
|
|
@@ -342,11 +362,7 @@ const downloadFile = async (raw, url, options) => {
|
|
|
342
362
|
body: { base64: file.data ?? "" },
|
|
343
363
|
contentType: header(headers, "content-type"),
|
|
344
364
|
headers,
|
|
345
|
-
meta:
|
|
346
|
-
requestId: id,
|
|
347
|
-
units: { uptime_ms: billed.uptimeMs },
|
|
348
|
-
warnings: billed.warning
|
|
349
|
-
}),
|
|
365
|
+
meta: billedMeta,
|
|
350
366
|
raw: {
|
|
351
367
|
browser: created,
|
|
352
368
|
execute: response
|
package/dist/llamaparse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as DocumentInput,
|
|
1
|
+
import { C as DocumentInput, K as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
/** Settings for `llamaparse()`. */
|
|
3
3
|
export interface LlamaParseConfig {
|
|
4
4
|
/** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
|
package/dist/llamaparse.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { i as enclosing, n as documentPart, o as refuseLarger, r as documentUrl } from "./document-
|
|
3
|
-
import { t as FieldworkError } from "./errors-
|
|
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, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-
|
|
5
|
-
import { i as startJob, r as runJob, t as jobState } from "./job-
|
|
6
|
-
import { a as compact, c as parseJson, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { i as enclosing, n as documentPart, o as refuseLarger, r as documentUrl } from "./document-DMIUCoDA.js";
|
|
3
|
+
import { t as FieldworkError } from "./errors-DkFJysIM.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, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-Q7H4mrnO.js";
|
|
5
|
+
import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
6
|
+
import { a as compact, c as parseJson, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
// src/adapters/llamaparse/response.ts
|
|
9
9
|
/** A box in page points, from the page's top-left corner. */
|
package/dist/parallel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, F as ImageSearch, G as PageBatch, H as MonitorInfo, U as MonitorSchedule, V as MonitorEvents, W as Page, a as RawClient, b as Decisions, g as Condition, k as Extraction, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
|
|
3
3
|
import "./util-DhYr1OS3.js";
|
|
4
4
|
/** Settings for `parallel()`. */
|
|
5
5
|
interface ParallelConfig {
|
|
@@ -63,7 +63,7 @@ interface ParallelSearchOptions extends CallOptions, ParallelSources {
|
|
|
63
63
|
interface ParallelImagesOptions extends CallOptions {
|
|
64
64
|
/** The images wanted, in plain words, up to 5,000 characters. Defaults to the query. */
|
|
65
65
|
objective?: string;
|
|
66
|
-
/** Up to
|
|
66
|
+
/** Up to 3 image queries (Parallel uses only the first 3); defaults to the query alone. */
|
|
67
67
|
queries?: string[];
|
|
68
68
|
mode?: "fast" | "advanced";
|
|
69
69
|
/** Sent as `max_results`. */
|
package/dist/parallel.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { i as withJob, r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, _ as optionalStructure, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source, v as recordOf, x as warnings, y as sourceShape } from "./parse-
|
|
4
|
-
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-
|
|
5
|
-
import { n as jsonSchemaOf, t as checkOutput } from "./schema
|
|
6
|
-
import { a as compact, c as parseJson, f as refuseTogether, i as citationsOf, m as uniqueCitations, p as requireJobId, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { i as withJob, r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, _ as optionalStructure, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source, v as recordOf, x as warnings, y as sourceShape } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
5
|
+
import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
|
|
6
|
+
import { a as compact, c as parseJson, f as refuseTogether, i as citationsOf, m as uniqueCitations, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
// src/adapters/parallel/parse.ts
|
|
9
9
|
/** The name this adapter reports in errors and results. */
|