@howells/fieldwork-sdk 0.6.1 → 0.8.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
@@ -104,7 +104,7 @@ Every result is normalized and keeps the provider's response in `raw`. Most also
104
104
  - `answer` returns `{ answer, output, citations, continuationId }`.
105
105
  - `research` returns `{ id, status, output, sources, fields, continuationId }`. `output` follows your schema when you pass one, otherwise it is the report text.
106
106
  - `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. 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.
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. 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.
108
108
 
109
109
  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
110
 
@@ -217,7 +217,11 @@ await web.search("tiles", { retries: 0 }); // this call only
217
217
  - an output schema;
218
218
  - MCP annotations.
219
219
 
220
- `execute(input)` checks the input, calls the capability, and returns the result without `raw`, with long text cut to a shared budget of 20,000 characters (`maxCharacters`).
220
+ `execute(input)` checks the input, calls the capability, and returns the result without `raw`, with long text cut to a shared budget of 20,000 characters. Set `toolsFor(web, { maxCharacters })` for a different default, or pass a positive integer `maxCharacters` in any tool call to override it. This is a tool-shaping option and never reaches the provider. Stdio uses `--max-characters` for its default. The HTTP gateway and remote MCP default to 20,000 and accept at most 200,000 per call; larger values fail with `InvalidRequest` before a provider is called. This cap leaves room for JSON escaping and MCP's two copies of the result under Vercel's 4.5 MB response limit; oversized encoded results are also refused with `InvalidRequest`.
221
+
222
+ For large public PDFs, call `parse_document({ url, provider: "llamaparse" })` or select `reducto`. The SDK takes `web.parse({ url })` with either adapter; each provider fetches the document directly. Use `name` and `contentBase64` for inline tool input, or `name` and `data` in the SDK; combine neither with `url`. Firecrawl's parse endpoint accepts uploaded bytes only: use `read_page` (SDK `read`) for public document URLs. The gateway limits JSON bodies to 2 MiB, below Vercel's 4.5 MB request limit; base64 inflates files by about one third, leaving less than 1.5 MiB for an inline file. Oversized requests return HTTP 413 with `InvalidRequest` and the URL alternative.
223
+
224
+ Every cut keeps the inline `[cut: N of M characters shown]` note and adds top-level `truncated: [{ path, shown, length }]`, with one entry per cut field (for example `markdown` or `results[2].text`). `shown` excludes the note; `length` is the original JavaScript string length. `truncated` is absent when nothing was cut. Text of 500 characters or fewer is never cut and spends none of the budget. Check `truncated` before treating a page or extracted value as complete.
221
225
 
222
226
  ```ts
223
227
  import { jsonSchema, tool } from "ai";
@@ -236,6 +240,8 @@ const tools = Object.fromEntries(
236
240
  );
237
241
  ```
238
242
 
243
+ Exa extraction refuses JSON Schema `type` arrays (including nullable unions) with `InvalidRequest` and the schema path before sending. Tavily research requires `properties`, a single supported type and a description for every property, nested `properties` for objects, and `items` for arrays. Its supported types are object, string, integer, number and array; unsupported shapes fail with `InvalidRequest` before sending. Fieldwork never rewrites the caller's schema. Parallel supports nullable unions.
244
+
239
245
  Tools that start remote browsers or create lasting, billed resources are left out unless you allow them: `toolsFor(web, { allow: ["act", "browser", "monitor"] })`. `toolError(error)` formats an error for a model.
240
246
 
241
247
  For MCP clients such as Claude, Cursor and Codex, [`@howells/fieldwork-mcp`](https://www.npmjs.com/package/@howells/fieldwork-mcp) serves these tools over stdio.
@@ -408,6 +408,12 @@ interface WordBox {
408
408
  text: string;
409
409
  box: Box;
410
410
  }
411
+ /** A line of text as the page lays it out, and where it sits. */
412
+ interface LineBox {
413
+ /** The line's part of its block's or cell's text, as the provider wrote it: Markdown, so it can carry `**` or an escape. */
414
+ text: string;
415
+ box: Box;
416
+ }
411
417
  /** A table cell and where it sits. Rows and columns count from 0. */
412
418
  interface TableCell {
413
419
  row: number;
@@ -418,6 +424,8 @@ interface TableCell {
418
424
  columnSpan?: number;
419
425
  text: string;
420
426
  box?: Box;
427
+ /** Where each line of the cell sits, when the provider places lines. */
428
+ lines?: LineBox[];
421
429
  }
422
430
  /** One piece of a page's layout: a heading, a paragraph, a table, a figure. */
423
431
  interface DocumentBlock {
@@ -430,6 +438,8 @@ interface DocumentBlock {
430
438
  box?: Box;
431
439
  /** Where each word sits, when the parse asked for word boxes. */
432
440
  words?: WordBox[];
441
+ /** Where each line sits, a table's cell lines included, when the parse asked for word boxes and the provider places lines. */
442
+ lines?: LineBox[];
433
443
  /** A table's cells, when the parse asked for word boxes. */
434
444
  cells?: TableCell[];
435
445
  }
@@ -448,9 +458,16 @@ interface ParsedDocument {
448
458
  }
449
459
  /** A file to parse: its bytes and its name, which tells the provider the type. */
450
460
  interface DocumentInput {
461
+ url?: never;
451
462
  data: Blob | Uint8Array | ArrayBuffer;
452
463
  name: string;
453
464
  }
465
+ /** A public document URL the provider fetches itself; never downloaded by Fieldwork. */
466
+ interface DocumentUrl {
467
+ url: string;
468
+ data?: never;
469
+ name?: never;
470
+ }
454
471
  /** How often a monitor checks: a cron expression or a named interval. */
455
472
  type MonitorSchedule = {
456
473
  cron: string;
@@ -577,4 +594,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
577
594
  * It returns its argument unchanged; write a custom adapter with it.
578
595
  */
579
596
  declare const defineAdapter: <Name extends string, Ops extends Operations, Raw = RawClient>(adapter: Adapter<Name, Ops, Raw>) => Adapter<Name, Ops, Raw>;
580
- export { TableCell as $, ImageResult as A, ParsedDocument as B, DocumentInput as C, FailedUrl as D, Extraction as E, MonitorEvents as F, ProductVariant as G, Price as H, MonitorInfo as I, RunStatus as J, Recency as K, MonitorSchedule as L, JsonSchema as M, Meta as N, FieldSource as O, MonitorEvent as P, SiteMap as Q, Page as R, DocumentBlock as S, Entity as T, Product as U, Place as V, ProductImage as W, SearchResult as X, SearchResponse as Y, SiteLink as Z, Crawl as _, RawClient as a, Decisions as b, ActResult as c, BrowserSession as d, Usage as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, ImageSearch as j, GROUP_CAPABILITIES as k, Answer as l, Capability as m, AnyAdapter as n, RequestOptions as o, CallOptions as p, Research as q, Operations as r, AccountUsage as s, Adapter as t, WordBox as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, PageBatch as z };
597
+ 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 };
package/dist/brave.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { K as Recency, Y as SearchResponse, a as RawClient, j as ImageSearch, l as Answer, p as CallOptions, t as Adapter } from "./adapter-Bh8EIrNe.js";
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-Dqy-6BiH.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,6 +1,7 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { C as createRawClient, F as parseJson, M as compact, P as meta, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, k as callSettings, l as optionalBoolean, o as nonEmptyString, r as arrayOf, v as recordOf, z as refuseTogether } from "./parse-COHKvfH9.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-lMLcxUsG.js";
4
+ import { a as compact, c as parseJson, f as refuseTogether, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
4
5
  import * as z from "zod/mini";
5
6
  // src/adapters/brave/response.ts
6
7
  /** The `query` block every search response carries. */
@@ -1,4 +1,4 @@
1
- import { R as Page, Y as SearchResponse, a as RawClient, d as BrowserSession, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-Bh8EIrNe.js";
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-Dqy-6BiH.js";
2
2
  /** Settings for `browserbase()`. */
3
3
  export interface BrowserbaseConfig {
4
4
  /** Defaults to the BROWSERBASE_API_KEY environment variable. */
@@ -1,6 +1,7 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { r as invalidRequest } from "./errors-DROZyb9T.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, I as presentPage, M as compact, P as meta, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, k as callSettings, m as optionalScalar, r as arrayOf, s as optionalAnyString, z as refuseTogether } from "./parse-COHKvfH9.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";
4
+ import { a as compact, f as refuseTogether, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
4
5
  import * as z from "zod/mini";
5
6
  // src/adapters/browserbase/response.ts
6
7
  /** `POST /v1/sessions`. The id keeps the value as it arrived, for the error raised when there is none. */
@@ -1,4 +1,6 @@
1
- import { t as FieldworkError } from "./errors-DROZyb9T.js";
1
+ import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
2
+ import { f as refuseTogether } from "./util-BqeRYF2b.js";
3
+ import * as z from "zod/mini";
2
4
  // src/document.ts
3
5
  /** Content types of the document files parsers commonly take, by extension. */
4
6
  const MEDIA_TYPES = new Map(Object.entries({
@@ -51,4 +53,12 @@ const enclosing = (boxes) => {
51
53
  width: right - left
52
54
  };
53
55
  };
54
- export { refuseLarger as a, mediaTypeOf as i, documentPart as n, enclosing as r, MEDIA_TYPES as t };
56
+ /** Refuses mixed byte/URL inputs and non-HTTP URLs before a provider request. */
57
+ const documentUrl = (provider, document) => {
58
+ refuseTogether(provider, document, "url", "data");
59
+ refuseTogether(provider, document, "url", "name");
60
+ const parsed = z.safeParse(z.url({ protocol: /^https?$/u }), document.url);
61
+ if (!parsed.success) throw invalidRequest(provider, "document url must be a public HTTP or HTTPS URL");
62
+ return parsed.data;
63
+ };
64
+ export { mediaTypeOf as a, enclosing as i, documentPart as n, refuseLarger as o, documentUrl as r, MEDIA_TYPES as t };
package/dist/exa.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as Extraction, F as MonitorEvents, I as MonitorInfo, L as MonitorSchedule, R as Page, Y as SearchResponse, a as RawClient, l as Answer, p as CallOptions, q as Research, t as Adapter, z as PageBatch } from "./adapter-Bh8EIrNe.js";
2
- import { t as OutputSchema } from "./schema-BWWiMvkg.js";
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-Dqy-6BiH.js";
2
+ import { t as OutputSchema } from "./schema-B23Z08Ds.js";
3
3
  /** Settings for the Exa adapter. */
4
4
  interface ExaConfig {
5
5
  /** Defaults to the EXA_API_KEY environment variable. */
@@ -126,7 +126,7 @@ type ExaReadManyOptions = ExaReadOptions;
126
126
  * for a summary of the page in the shape of `schema` and returns it as `data`.
127
127
  */
128
128
  interface ExaExtractOptions<T = unknown> extends CallOptions {
129
- /** A JSON Schema, or a Zod, Valibot or ArkType schema that types and checks `data`. */
129
+ /** A JSON Schema, or a Zod, Valibot or ArkType schema that types and checks `data`. Type arrays, including nullable unions, throw `InvalidRequest` before sending. */
130
130
  schema: OutputSchema<T>;
131
131
  /** What to extract, in plain words. */
132
132
  prompt?: string;
package/dist/exa.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, F as parseJson, M as compact, N as hours, P as meta, R as record, S as withOriginal, T as requireKey, V as uniqueCitations, _ as optionalStructure, a as looseObject, b as warningEntry, d as optionalId, f as optionalNumber, g as optionalStringOrNumber, h as optionalString, i as both, j as citationsOf, k as callSettings, l as optionalBoolean, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source } from "./parse-COHKvfH9.js";
4
- import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.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-lMLcxUsG.js";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DBhGs7Ha.js";
5
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-COAaWnZB.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-BqeRYF2b.js";
6
7
  import * as z from "zod/mini";
7
8
  const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/u;
8
9
  /** The search types that take `additionalQueries`. */
@@ -511,7 +512,7 @@ const exa = (config = {}) => {
511
512
  maxAgeHours: hours(o.maxAge),
512
513
  summary: compact({
513
514
  query: o.prompt,
514
- schema: jsonSchemaOf(o.schema, "draft-07")
515
+ schema: jsonSchemaOf(o.schema, "draft-07", "exa")
515
516
  })
516
517
  }), call);
517
518
  const { value: summary } = result.summary;
@@ -1,4 +1,4 @@
1
- import { m as Capability, n as AnyAdapter } from "./adapter-Bh8EIrNe.js";
1
+ import { m as Capability, n as AnyAdapter } from "./adapter-Dqy-6BiH.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. */
@@ -1,5 +1,5 @@
1
- import { B as ParsedDocument, C as DocumentInput, E as Extraction, F as MonitorEvents, I as MonitorInfo, K as Recency, L as MonitorSchedule, Q as SiteMap, R as Page, U as Product, Y as SearchResponse, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, j as ImageSearch, p as CallOptions, q as Research, s as AccountUsage, t as Adapter, z as PageBatch } from "./adapter-Bh8EIrNe.js";
2
- import { t as OutputSchema } from "./schema-BWWiMvkg.js";
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-Dqy-6BiH.js";
2
+ import { t as OutputSchema } from "./schema-B23Z08Ds.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,9 +1,10 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, I as presentPage, L as presentPages, M as compact, P as meta, 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, k as callSettings, l as optionalBoolean, m as optionalScalar, n as anything, p as optionalObject, r as arrayOf, s as optionalAnyString, u as optionalFirstString, v as recordOf, z as refuseTogether } from "./parse-COHKvfH9.js";
4
- import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
- import { a as refuseLarger, i as mediaTypeOf, n as documentPart, t as MEDIA_TYPES } from "./document-Clmi51Sf.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-lMLcxUsG.js";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DBhGs7Ha.js";
5
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-COAaWnZB.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-BqeRYF2b.js";
7
+ import { a as mediaTypeOf, n as documentPart, o as refuseLarger, t as MEDIA_TYPES } from "./document-DOzhDFFt.js";
7
8
  import * as z from "zod/mini";
8
9
  // src/adapters/firecrawl/shared.ts
9
10
  const provider = "firecrawl";
@@ -273,6 +274,7 @@ const scriptRequest = (code, language, call, seconds) => ({
273
274
  * a file over `MAX_PARSE_MB` and a `timeout` over `MAX_PARSE_MS`.
274
275
  */
275
276
  const parseForm = (document, o, timeout) => {
277
+ if (document.url !== void 0) throw new FieldworkError("Unsupported", "firecrawl parse accepts file bytes only; use read_page (SDK read) for a public document URL, or parse_document with llamaparse or reducto", { provider });
276
278
  if (timeout !== void 0 && timeout > MAX_PARSE_MS) throw invalidRequest(provider, `parses for at most ${MAX_PARSE_MS / 1e3} seconds`);
277
279
  if (mediaTypeOf(document.name) === void 0) throw invalidRequest(provider, `parses ${[...MEDIA_TYPES.keys()].join(", ")} files, not "${document.name}"`);
278
280
  refuseLarger(provider, document, MAX_PARSE_MB);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as TableCell, A as ImageResult, B as ParsedDocument, C as DocumentInput, D as FailedUrl, E as Extraction, F as MonitorEvents, G as ProductVariant, H as Price, I as MonitorInfo, J as RunStatus, K as Recency, L as MonitorSchedule, M as JsonSchema, N as Meta, O as FieldSource, P as MonitorEvent, Q as SiteMap, R as Page, S as DocumentBlock, T as Entity, U as Product, V as Place, W as ProductImage, X as SearchResult, Y as SearchResponse, Z as SiteLink, _ as Crawl, a as RawClient, b as Decisions, c as ActResult, d as BrowserSession, et as Usage, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, j as ImageSearch, k as GROUP_CAPABILITIES, l as Answer, m as Capability, n as AnyAdapter, o as RequestOptions, p as CallOptions, q as Research, r as Operations, s as AccountUsage, t as Adapter, tt as WordBox, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-Bh8EIrNe.js";
2
- import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-BaWqUNI3.js";
3
- import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-BWWiMvkg.js";
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-Dqy-6BiH.js";
2
+ import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-CAGMQ2Cu.js";
3
+ import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-B23Z08Ds.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, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, 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, 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 };
@@ -1,5 +1,6 @@
1
1
  import { i as withJob, t as FieldworkError } from "./errors-DROZyb9T.js";
2
- import { B as requireJobId, D as sleep, O as stopped } from "./parse-COHKvfH9.js";
2
+ import { D as sleep, O as stopped } from "./parse-lMLcxUsG.js";
3
+ import { p as requireJobId } from "./util-BqeRYF2b.js";
3
4
  import * as z from "zod/mini";
4
5
  // src/job.ts
5
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 { R as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-Bh8EIrNe.js";
1
+ import { B as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-Dqy-6BiH.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,7 +1,8 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, I as presentPage, M as compact, P as meta, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, k as callSettings, l as optionalBoolean, n as anything, p as optionalObject, s as optionalAnyString } from "./parse-COHKvfH9.js";
4
- import { r as runJob } from "./job-FE9e6HOI.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";
5
+ import { a as compact, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
5
6
  import * as z from "zod/mini";
6
7
  import TurndownService from "turndown";
7
8
  // src/adapters/kernel/response.ts
@@ -1,4 +1,4 @@
1
- import { B as ParsedDocument, C as DocumentInput, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-Bh8EIrNe.js";
1
+ import { C as DocumentInput, H as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-Dqy-6BiH.js";
2
2
  /** Settings for `llamaparse()`. */
3
3
  export interface LlamaParseConfig {
4
4
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -24,8 +24,8 @@ export interface LlamaParseParseOptions extends CallOptions {
24
24
  /** Return layout blocks with positions. */
25
25
  blocks?: boolean;
26
26
  /**
27
- * Also return where each word and table cell sits in each block, from a
28
- * second download. Returns blocks too.
27
+ * Also return where each word, line and table cell sits in each block, and
28
+ * each line of a cell, from a second download. Returns blocks too.
29
29
  */
30
30
  wordBoxes?: boolean;
31
31
  /** Leave out text a reader cannot see, such as white text on white. */
@@ -50,7 +50,7 @@ export type LlamaParseResumeOptions = Omit<LlamaParseParseOptions, "resume"> & {
50
50
  export interface LlamaParseOperations {
51
51
  parse: {
52
52
  /** Uploads the file and waits for the parse. An error after the upload carries `jobId`. */
53
- (document: DocumentInput, options?: LlamaParseParseOptions): Promise<ParsedDocument>;
53
+ (document: DocumentInput | DocumentUrl, options?: LlamaParseParseOptions): Promise<ParsedDocument>;
54
54
  /** Collects an earlier parse by its id, without sending the file again. */
55
55
  (options: LlamaParseResumeOptions): Promise<ParsedDocument>;
56
56
  };
@@ -1,8 +1,9 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { a as refuseLarger, n as documentPart, r as enclosing } from "./document-Clmi51Sf.js";
2
+ import { i as enclosing, n as documentPart, o as refuseLarger, r as documentUrl } from "./document-DOzhDFFt.js";
3
3
  import { t as FieldworkError } from "./errors-DROZyb9T.js";
4
- import { C as createRawClient, E as segment, F as parseJson, M as compact, P as meta, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, k as callSettings, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-COHKvfH9.js";
5
- import { i as startJob, r as runJob, t as jobState } from "./job-FE9e6HOI.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-lMLcxUsG.js";
5
+ import { i as startJob, r as runJob, t as jobState } from "./job-DBhGs7Ha.js";
6
+ import { a as compact, c as parseJson, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
6
7
  import * as z from "zod/mini";
7
8
  // src/adapters/llamaparse/response.ts
8
9
  /** A box in page points, from the page's top-left corner. */
@@ -12,12 +13,16 @@ const PointBox = looseObject({
12
13
  x: optionalNumber,
13
14
  y: optionalNumber
14
15
  });
15
- /** A word: `span` is `[start, end)` in UTF-8 bytes of its item's text. */
16
+ /** A word or a line: `span` is `[start, end)` in UTF-8 bytes of its item's `md`, or of its cell's text in a table. */
16
17
  const Word = looseObject({
17
18
  bbox: PointBox,
18
19
  span: arrayOf(z.number())
19
20
  });
20
- const Line = looseObject({ words: arrayOf(Word) });
21
+ const Line = looseObject({
22
+ bbox: PointBox,
23
+ span: arrayOf(z.number()),
24
+ words: arrayOf(Word)
25
+ });
21
26
  const Cell = looseObject({
22
27
  bbox: arrayOf(PointBox),
23
28
  lines: arrayOf(Line)
@@ -76,35 +81,46 @@ const fraction = (box, size) => {
76
81
  };
77
82
  };
78
83
  const around = (boxes, size) => enclosing(boxes.map((box) => fraction(box, size)).filter((box) => box !== void 0));
79
- const wordsOf = (lines, text, size) => {
84
+ /** Each word or line that has a box and a span, with the text its span covers. */
85
+ const placed = (spans, bytes, size) => spans.flatMap((each) => {
86
+ const box = fraction(each.bbox, size);
87
+ const [start, end] = each.span;
88
+ if (box === void 0 || start === void 0 || end === void 0) return [];
89
+ return [{
90
+ box,
91
+ text: decoder.decode(bytes.slice(start, end))
92
+ }];
93
+ });
94
+ /** The words and the lines of `lines`, whose spans count bytes of `text`. */
95
+ const grounded = (lines, text, size) => {
80
96
  const bytes = encoder.encode(text);
81
- return lines.flatMap((line) => line.words.flatMap((word) => {
82
- const box = fraction(word.bbox, size);
83
- const [start, end] = word.span;
84
- if (box === void 0 || start === void 0 || end === void 0) return [];
85
- return [{
86
- box,
87
- text: decoder.decode(bytes.slice(start, end))
88
- }];
89
- }));
97
+ return {
98
+ lines: placed(lines, bytes, size),
99
+ words: lines.flatMap((line) => placed(line.words, bytes, size))
100
+ };
90
101
  };
91
102
  const tableOf = (item, size) => {
92
103
  const cells = [];
104
+ const lines = [];
93
105
  const words = [];
94
- for (const [row, grounded] of item.grounding.rows.entries()) for (const [column, cell] of grounded.entries()) {
106
+ for (const [row, groundedRow] of item.grounding.rows.entries()) for (const [column, cell] of groundedRow.entries()) {
95
107
  const text = item.rows[row]?.[column];
96
108
  if (text !== void 0) {
109
+ const inCell = grounded(cell.lines, text, size);
97
110
  cells.push(compact({
98
111
  box: around(cell.bbox, size),
99
112
  column,
113
+ lines: inCell.lines.length > 0 ? inCell.lines : void 0,
100
114
  row,
101
115
  text
102
116
  }));
103
- words.push(...wordsOf(cell.lines, text, size));
117
+ lines.push(...inCell.lines);
118
+ words.push(...inCell.words);
104
119
  }
105
120
  }
106
121
  return {
107
122
  cells,
123
+ lines,
108
124
  words
109
125
  };
110
126
  };
@@ -117,10 +133,13 @@ const blocksOfItem = (item, page, size) => {
117
133
  type: item.type ?? "unknown"
118
134
  }];
119
135
  const table = tableOf(item, size);
120
- const words = [...wordsOf(item.grounding.lines, text, size), ...table.words];
136
+ const own = grounded(item.grounding.lines, text, size);
137
+ const lines = [...own.lines, ...table.lines];
138
+ const words = [...own.words, ...table.words];
121
139
  return [compact({
122
140
  box: around(item.bbox, size),
123
141
  cells: table.cells.length > 0 ? table.cells : void 0,
142
+ lines: lines.length > 0 ? lines : void 0,
124
143
  page,
125
144
  text,
126
145
  type: item.type ?? "unknown",
@@ -160,6 +179,13 @@ const configuration = (o) => compact({
160
179
  /** Uploads the file and returns the job id. Refuses a missing document, or a file over the size limit, before sending. */
161
180
  const startParse = async (raw, document, o, call) => {
162
181
  if (document === void 0) throw new FieldworkError("InvalidRequest", "parse needs a document, or resume with the id of an earlier parse", { provider });
182
+ if (document.url !== void 0) return await startJob(raw, "/api/v2/parse", {
183
+ ...call,
184
+ body: {
185
+ ...configuration(o),
186
+ source_url: documentUrl(provider, document)
187
+ }
188
+ }, JobStart, (reply) => reply.id);
163
189
  refuseLarger(provider, document, MAX_PARSE_MB);
164
190
  const form = new FormData();
165
191
  form.set("configuration", JSON.stringify(configuration(o)));
@@ -187,7 +213,7 @@ const finished = (id, found) => {
187
213
  });
188
214
  return state === "done" ? found : void 0;
189
215
  };
190
- /** The grounded items: one JSON line per page, each page's items with word and cell boxes. */
216
+ /** The grounded items: one JSON line per page, each page's items with word, line and cell boxes. */
191
217
  const groundedPages = async (found, options) => {
192
218
  const url = found.value.result_content_metadata.grounded_items.presigned_url;
193
219
  if (url === void 0) throw new FieldworkError("ProviderError", "llamaparse finished without the word boxes it was asked for", {
@@ -1,5 +1,5 @@
1
- import { E as Extraction, F as MonitorEvents, I as MonitorInfo, L as MonitorSchedule, R as Page, Y as SearchResponse, a as RawClient, b as Decisions, g as Condition, j as ImageSearch, l as Answer, p as CallOptions, q as Research, t as Adapter, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-Bh8EIrNe.js";
2
- import { t as OutputSchema } from "./schema-BWWiMvkg.js";
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-Dqy-6BiH.js";
2
+ import { t as OutputSchema } from "./schema-B23Z08Ds.js";
3
3
  import "./util-DhYr1OS3.js";
4
4
  /** Settings for `parallel()`. */
5
5
  interface ParallelConfig {
package/dist/parallel.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { i as withJob, r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, F as parseJson, M as compact, P as meta, S as withOriginal, T as requireKey, V as uniqueCitations, _ as optionalStructure, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, j as citationsOf, k as callSettings, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source, v as recordOf, x as warnings, y as sourceShape, z as refuseTogether } from "./parse-COHKvfH9.js";
4
- import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.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-lMLcxUsG.js";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DBhGs7Ha.js";
5
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-COAaWnZB.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-BqeRYF2b.js";
6
7
  import * as z from "zod/mini";
7
8
  // src/adapters/parallel/parse.ts
8
9
  /** The name this adapter reports in errors and results. */