@howells/fieldwork-sdk 0.7.0 → 0.9.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. 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.
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
 
@@ -392,6 +392,10 @@ interface DocumentPage {
392
392
  markdown: string;
393
393
  /** An address for a picture of the page, when the parse asked for page images. It expires. */
394
394
  image?: string;
395
+ /** The page's width in points (1/72 inch), when the provider gives it with the blocks. */
396
+ width?: number;
397
+ /** The page's height in points (1/72 inch), when the provider gives it with the blocks. */
398
+ height?: number;
395
399
  }
396
400
  /**
397
401
  * Where something sits on its page, as fractions of the page's width and
@@ -408,6 +412,12 @@ interface WordBox {
408
412
  text: string;
409
413
  box: Box;
410
414
  }
415
+ /** A line of text as the page lays it out, and where it sits. */
416
+ interface LineBox {
417
+ /** 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. */
418
+ text: string;
419
+ box: Box;
420
+ }
411
421
  /** A table cell and where it sits. Rows and columns count from 0. */
412
422
  interface TableCell {
413
423
  row: number;
@@ -417,7 +427,12 @@ interface TableCell {
417
427
  /** Columns the cell spans, when more than one. */
418
428
  columnSpan?: number;
419
429
  text: string;
430
+ /** Encloses every box of the cell. */
420
431
  box?: Box;
432
+ /** Each box the provider gives for the cell, in its order, when it gives them one by one: a cell can sit in several. */
433
+ boxes?: Box[];
434
+ /** Where each line of the cell sits, when the provider places lines. */
435
+ lines?: LineBox[];
421
436
  }
422
437
  /** One piece of a page's layout: a heading, a paragraph, a table, a figure. */
423
438
  interface DocumentBlock {
@@ -428,8 +443,12 @@ interface DocumentBlock {
428
443
  /** The block's content as the provider gave it: Markdown, or HTML for some tables. */
429
444
  text: string;
430
445
  box?: Box;
446
+ /** The page header or footer the provider read this block out of, when it was in one. */
447
+ container?: "header" | "footer";
431
448
  /** Where each word sits, when the parse asked for word boxes. */
432
449
  words?: WordBox[];
450
+ /** Where each line sits, a table's cell lines included, when the parse asked for word boxes and the provider places lines. */
451
+ lines?: LineBox[];
433
452
  /** A table's cells, when the parse asked for word boxes. */
434
453
  cells?: TableCell[];
435
454
  }
@@ -584,4 +603,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
584
603
  * It returns its argument unchanged; write a custom adapter with it.
585
604
  */
586
605
  declare const defineAdapter: <Name extends string, Ops extends Operations, Raw = RawClient>(adapter: Adapter<Name, Ops, Raw>) => Adapter<Name, Ops, Raw>;
587
- export { SiteMap as $, GROUP_CAPABILITIES as A, PageBatch as B, DocumentInput as C, Extraction as D, Entity as E, MonitorEvent as F, ProductImage as G, Place as H, MonitorEvents as I, Research as J, ProductVariant as K, MonitorInfo as L, ImageSearch as M, JsonSchema as N, FailedUrl as O, Meta as P, SiteLink as Q, MonitorSchedule as R, DocumentBlock as S, DocumentUrl as T, Price as U, ParsedDocument as V, Product as W, SearchResponse as X, RunStatus as Y, SearchResult as Z, Crawl as _, RawClient as a, Decisions as b, ActResult as c, BrowserSession as d, TableCell 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, WordBox as nt, RequestOptions as o, CallOptions as p, Recency as q, Operations as r, AccountUsage as s, Adapter as t, Usage as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, Page as z };
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 };
package/dist/brave.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ImageSearch, X as SearchResponse, a as RawClient, l as Answer, p as CallOptions, q as Recency, t as Adapter } from "./adapter-C1mzXyKH.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-DuJkoVWY.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 { X as SearchResponse, a as RawClient, d as BrowserSession, p as CallOptions, s as AccountUsage, t as Adapter, z as Page } from "./adapter-C1mzXyKH.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-DuJkoVWY.js";
2
2
  /** Settings for `browserbase()`. */
3
3
  export interface BrowserbaseConfig {
4
4
  /** Defaults to the BROWSERBASE_API_KEY environment variable. */
package/dist/exa.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as PageBatch, D as Extraction, I as MonitorEvents, J as Research, L as MonitorInfo, R as MonitorSchedule, X as SearchResponse, a as RawClient, l as Answer, p as CallOptions, t as Adapter, z as Page } from "./adapter-C1mzXyKH.js";
2
- import { t as OutputSchema } from "./schema-DNYyDTlM.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-DuJkoVWY.js";
2
+ import { t as OutputSchema } from "./schema-_iwQlBZE.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-C1mzXyKH.js";
1
+ import { m as Capability, n as AnyAdapter } from "./adapter-DuJkoVWY.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 { $ as SiteMap, B as PageBatch, C as DocumentInput, D as Extraction, I as MonitorEvents, J as Research, L as MonitorInfo, M as ImageSearch, R as MonitorSchedule, V as ParsedDocument, W as Product, X as SearchResponse, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, p as CallOptions, q as Recency, s as AccountUsage, t as Adapter, z as Page } from "./adapter-C1mzXyKH.js";
2
- import { t as OutputSchema } from "./schema-DNYyDTlM.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-DuJkoVWY.js";
2
+ import { t as OutputSchema } from "./schema-_iwQlBZE.js";
3
3
  /** Settings for the Firecrawl adapter. */
4
4
  interface FirecrawlConfig {
5
5
  /** Defaults to the FIRECRAWL_API_KEY environment variable. */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as SiteMap, A as GROUP_CAPABILITIES, B as PageBatch, C as DocumentInput, D as Extraction, E as Entity, F as MonitorEvent, G as ProductImage, H as Place, I as MonitorEvents, J as Research, K as ProductVariant, L as MonitorInfo, M as ImageSearch, N as JsonSchema, O as FailedUrl, P as Meta, Q as SiteLink, R as MonitorSchedule, S as DocumentBlock, T as DocumentUrl, U as Price, V as ParsedDocument, W as Product, X as SearchResponse, Y as RunStatus, Z as SearchResult, _ as Crawl, a as RawClient, b as Decisions, c as ActResult, d as BrowserSession, et as TableCell, 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 WordBox, o as RequestOptions, p as CallOptions, q as Recency, r as Operations, s as AccountUsage, t as Adapter, tt as Usage, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as Page } from "./adapter-C1mzXyKH.js";
2
- import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-Dtlhkzf2.js";
3
- import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-DNYyDTlM.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-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";
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, 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 };
package/dist/kernel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter, z as Page } from "./adapter-C1mzXyKH.js";
1
+ import { B as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
2
2
  /** Settings for `kernel()`. */
3
3
  export interface KernelConfig {
4
4
  /** Defaults to the KERNEL_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { C as DocumentInput, T as DocumentUrl, V as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-C1mzXyKH.js";
1
+ import { C as DocumentInput, H as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.js";
2
2
  /** Settings for `llamaparse()`. */
3
3
  export interface LlamaParseConfig {
4
4
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -21,11 +21,11 @@ export interface LlamaParseParseOptions extends CallOptions {
21
21
  tier?: LlamaParseTier;
22
22
  /** The parser version: "latest" (the default) or a date such as "2026-09-28". */
23
23
  version?: string;
24
- /** Return layout blocks with positions. */
24
+ /** Return layout blocks with positions, and each page's size in points. */
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. */
@@ -13,14 +13,22 @@ const PointBox = looseObject({
13
13
  x: optionalNumber,
14
14
  y: optionalNumber
15
15
  });
16
- /** 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. */
17
17
  const Word = looseObject({
18
18
  bbox: PointBox,
19
19
  span: arrayOf(z.number())
20
20
  });
21
- const Line = looseObject({ words: arrayOf(Word) });
21
+ const Line = looseObject({
22
+ bbox: PointBox,
23
+ span: arrayOf(z.number()),
24
+ words: arrayOf(Word)
25
+ });
26
+ const OneBox = z.record(z.string(), z.unknown());
27
+ const BoxList = arrayOf(PointBox);
28
+ /** A list of boxes; one box on its own reads as a list of one, and anything else as none. */
29
+ const PointBoxes = z.prefault(z.pipe(z.unknown(), z.transform((value) => z.parse(BoxList, z.safeParse(OneBox, value).success ? [value] : value))), []);
22
30
  const Cell = looseObject({
23
- bbox: arrayOf(PointBox),
31
+ bbox: PointBoxes,
24
32
  lines: arrayOf(Line)
25
33
  });
26
34
  /** An item of a page. Its own `items` (a header's, a list's) are read one level at a time. */
@@ -77,65 +85,96 @@ const fraction = (box, size) => {
77
85
  };
78
86
  };
79
87
  const around = (boxes, size) => enclosing(boxes.map((box) => fraction(box, size)).filter((box) => box !== void 0));
80
- const wordsOf = (lines, text, size) => {
88
+ /** Each word or line that has a box and a span, with the text its span covers. */
89
+ const placed = (spans, bytes, size) => spans.flatMap((each) => {
90
+ const box = fraction(each.bbox, size);
91
+ const [start, end] = each.span;
92
+ if (box === void 0 || start === void 0 || end === void 0) return [];
93
+ return [{
94
+ box,
95
+ text: decoder.decode(bytes.slice(start, end))
96
+ }];
97
+ });
98
+ /** The words and the lines of `lines`, whose spans count bytes of `text`. */
99
+ const grounded = (lines, text, size) => {
81
100
  const bytes = encoder.encode(text);
82
- return lines.flatMap((line) => line.words.flatMap((word) => {
83
- const box = fraction(word.bbox, size);
84
- const [start, end] = word.span;
85
- if (box === void 0 || start === void 0 || end === void 0) return [];
86
- return [{
87
- box,
88
- text: decoder.decode(bytes.slice(start, end))
89
- }];
90
- }));
101
+ return {
102
+ lines: placed(lines, bytes, size),
103
+ words: lines.flatMap((line) => placed(line.words, bytes, size))
104
+ };
91
105
  };
92
106
  const tableOf = (item, size) => {
93
107
  const cells = [];
108
+ const lines = [];
94
109
  const words = [];
95
- for (const [row, grounded] of item.grounding.rows.entries()) for (const [column, cell] of grounded.entries()) {
110
+ for (const [row, groundedRow] of item.grounding.rows.entries()) for (const [column, cell] of groundedRow.entries()) {
96
111
  const text = item.rows[row]?.[column];
97
112
  if (text !== void 0) {
113
+ const inCell = grounded(cell.lines, text, size);
114
+ const boxes = cell.bbox.map((box) => fraction(box, size)).filter((box) => box !== void 0);
98
115
  cells.push(compact({
99
- box: around(cell.bbox, size),
116
+ box: enclosing(boxes),
117
+ boxes: boxes.length > 0 ? boxes : void 0,
100
118
  column,
119
+ lines: inCell.lines.length > 0 ? inCell.lines : void 0,
101
120
  row,
102
121
  text
103
122
  }));
104
- words.push(...wordsOf(cell.lines, text, size));
123
+ lines.push(...inCell.lines);
124
+ words.push(...inCell.words);
105
125
  }
106
126
  }
107
127
  return {
108
128
  cells,
129
+ lines,
109
130
  words
110
131
  };
111
132
  };
112
- const blocksOfItem = (item, page, size) => {
113
- if (item.items.length > 0) return item.items.flatMap((child) => blocksOfItem(z.parse(Item, child), page, size));
133
+ /** The page header or footer an item is, if it is one. */
134
+ const containerOf = (item) => item.type === "header" || item.type === "footer" ? item.type : void 0;
135
+ const blocksOfItem = (item, page, size, container) => {
136
+ if (item.items.length > 0) return item.items.flatMap((child) => blocksOfItem(z.parse(Item, child), page, size, container ?? containerOf(item)));
114
137
  const text = item.md ?? item.value ?? "";
115
- if (size === void 0) return [{
138
+ if (size === void 0) return [compact({
139
+ container,
116
140
  page,
117
141
  text,
118
142
  type: item.type ?? "unknown"
119
- }];
143
+ })];
120
144
  const table = tableOf(item, size);
121
- const words = [...wordsOf(item.grounding.lines, text, size), ...table.words];
145
+ const own = grounded(item.grounding.lines, text, size);
146
+ const lines = [...own.lines, ...table.lines];
147
+ const words = [...own.words, ...table.words];
122
148
  return [compact({
123
149
  box: around(item.bbox, size),
124
150
  cells: table.cells.length > 0 ? table.cells : void 0,
151
+ container,
152
+ lines: lines.length > 0 ? lines : void 0,
125
153
  page,
126
154
  text,
127
155
  type: item.type ?? "unknown",
128
156
  words: words.length > 0 ? words : void 0
129
157
  })];
130
158
  };
159
+ /** A page's size in points, when LlamaParse gave a usable one. */
160
+ const sizeOf = (entry) => entry.page_width !== void 0 && entry.page_height !== void 0 && entry.page_width > 0 && entry.page_height > 0 ? {
161
+ height: entry.page_height,
162
+ width: entry.page_width
163
+ } : void 0;
164
+ /** Each page's size in points, by page number. */
165
+ const pageSizes = (pages) => {
166
+ const sizes = /* @__PURE__ */ new Map();
167
+ for (const entry of pages) {
168
+ const size = sizeOf(entry);
169
+ if (entry.page_number !== void 0 && size !== void 0) sizes.set(entry.page_number, size);
170
+ }
171
+ return sizes;
172
+ };
131
173
  /** The blocks of each page, its boxes turned from points into fractions of the page. */
132
174
  const documentBlocks = (pages) => pages.flatMap((entry) => {
133
175
  const page = entry.page_number;
134
176
  if (page === void 0) return [];
135
- const size = entry.page_width !== void 0 && entry.page_height !== void 0 && entry.page_width > 0 && entry.page_height > 0 ? {
136
- height: entry.page_height,
137
- width: entry.page_width
138
- } : void 0;
177
+ const size = sizeOf(entry);
139
178
  return entry.items.flatMap((item) => blocksOfItem(item, page, size));
140
179
  });
141
180
  // src/adapters/llamaparse.ts
@@ -195,7 +234,7 @@ const finished = (id, found) => {
195
234
  });
196
235
  return state === "done" ? found : void 0;
197
236
  };
198
- /** The grounded items: one JSON line per page, each page's items with word and cell boxes. */
237
+ /** The grounded items: one JSON line per page, each page's items with word, line and cell boxes. */
199
238
  const groundedPages = async (found, options) => {
200
239
  const url = found.value.result_content_metadata.grounded_items.presigned_url;
201
240
  if (url === void 0) throw new FieldworkError("ProviderError", "llamaparse finished without the word boxes it was asked for", {
@@ -225,6 +264,10 @@ const parsedDocument = async (found, id, o, read) => {
225
264
  });
226
265
  const grounded = o.wordBoxes === true ? await groundedPages(found, read) : void 0;
227
266
  const images = o.pageImages === true ? pageImageAddresses(found, id) : void 0;
267
+ let laidOut;
268
+ if (grounded !== void 0) laidOut = grounded.map((row) => z.parse(ItemsPage, row));
269
+ else if (o.blocks === true) laidOut = found.value.items.pages;
270
+ const sizes = laidOut === void 0 ? void 0 : pageSizes(laidOut);
228
271
  const pages = found.value.markdown.pages.flatMap((page) => {
229
272
  if (page.page_number === void 0) return [];
230
273
  const image = images?.get(page.page_number);
@@ -232,17 +275,17 @@ const parsedDocument = async (found, id, o, read) => {
232
275
  cause: found.original,
233
276
  provider
234
277
  });
278
+ const size = sizes?.get(page.page_number);
235
279
  return [compact({
280
+ height: size?.height,
236
281
  image,
237
282
  markdown: page.markdown ?? "",
238
- pageNumber: page.page_number
283
+ pageNumber: page.page_number,
284
+ width: size?.width
239
285
  })];
240
286
  });
241
- let laidOut;
242
- if (grounded !== void 0) laidOut = documentBlocks(grounded.map((row) => z.parse(ItemsPage, row)));
243
- else if (o.blocks === true) laidOut = documentBlocks(found.value.items.pages);
244
287
  return compact({
245
- blocks: laidOut,
288
+ blocks: laidOut === void 0 ? void 0 : documentBlocks(laidOut),
246
289
  id,
247
290
  markdown: pages.map((page) => page.markdown).join("\n\n"),
248
291
  meta: meta({ credits: found.value.job.usage.credits }),
@@ -1,5 +1,5 @@
1
- import { B as PageBatch, D as Extraction, I as MonitorEvents, J as Research, L as MonitorInfo, M as ImageSearch, R as MonitorSchedule, X 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 Page } from "./adapter-C1mzXyKH.js";
2
- import { t as OutputSchema } from "./schema-DNYyDTlM.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-DuJkoVWY.js";
2
+ import { t as OutputSchema } from "./schema-_iwQlBZE.js";
3
3
  import "./util-DhYr1OS3.js";
4
4
  /** Settings for `parallel()`. */
5
5
  interface ParallelConfig {
@@ -1,5 +1,5 @@
1
- import { J as Research, X as SearchResponse, a as RawClient, b as Decisions, l as Answer, p as CallOptions, q as Recency, t as Adapter, y as DecisionQuestion } from "./adapter-C1mzXyKH.js";
2
- import { t as OutputSchema } from "./schema-DNYyDTlM.js";
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";
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, T as DocumentUrl, V as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-C1mzXyKH.js";
1
+ import { C as DocumentInput, H as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DuJkoVWY.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-C1mzXyKH.js";
1
+ import { N as JsonSchema } from "./adapter-DuJkoVWY.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 { M as ImageSearch, X as SearchResponse, a as RawClient, p as CallOptions, q as Recency, s as AccountUsage, t as Adapter } from "./adapter-C1mzXyKH.js";
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";
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 { $ as SiteMap, B as PageBatch, J as Research, M as ImageSearch, X as SearchResponse, _ as Crawl, a as RawClient, l as Answer, p as CallOptions, q as Recency, s as AccountUsage, t as Adapter, z as Page } from "./adapter-C1mzXyKH.js";
2
- import { t as OutputSchema } from "./schema-DNYyDTlM.js";
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";
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-Dtlhkzf2.js";
2
- import { N as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-C1mzXyKH.js";
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";
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
@@ -461,14 +461,21 @@ const box = object({
461
461
  "width",
462
462
  "height"
463
463
  ], "Where it sits on the page, as fractions of the page's width and height from its top-left corner.");
464
+ /** A word or a line: its text and where it sits. */
465
+ const placedText = object({
466
+ box,
467
+ text: str
468
+ }, ["text", "box"]);
464
469
  /** The result of `parse_document`, a `ParsedDocument`. */
465
470
  const PARSE_OUTPUT = object({
466
471
  blocks: list(object({
467
472
  box,
468
473
  cells: list(object({
469
474
  box,
475
+ boxes: list(box, "Each box the cell sits in, when the provider gives them one by one; box encloses them."),
470
476
  column: whole("The column, from 0.", 0),
471
477
  columnSpan: whole("Columns the cell spans.", 1),
478
+ lines: list(placedText),
472
479
  row: whole("The row, from 0.", 0),
473
480
  rowSpan: whole("Rows the cell spans.", 1),
474
481
  text: str
@@ -477,13 +484,12 @@ const PARSE_OUTPUT = object({
477
484
  "column",
478
485
  "text"
479
486
  ])),
487
+ container: choice("The page header or footer the block was read out of.", ["header", "footer"]),
488
+ lines: list(placedText),
480
489
  page: whole("The physical page number, starting at 1.", 1),
481
490
  text: str,
482
491
  type: str,
483
- words: list(object({
484
- box,
485
- text: str
486
- }, ["text", "box"]))
492
+ words: list(placedText)
487
493
  }, [
488
494
  "page",
489
495
  "type",
@@ -494,8 +500,10 @@ const PARSE_OUTPUT = object({
494
500
  meta,
495
501
  pageCount: whole("Pages in the file.", 0),
496
502
  pages: list(object({
503
+ height: number("The page's height in points."),
497
504
  markdown: str,
498
- pageNumber: whole("The physical page number, starting at 1.", 1)
505
+ pageNumber: whole("The physical page number, starting at 1.", 1),
506
+ width: number("The page's width in points.")
499
507
  }, ["pageNumber", "markdown"]))
500
508
  }, ["markdown"]);
501
509
  /** The result of `create_monitor` and `get_monitor`, a `MonitorInfo`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howells/fieldwork-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.9.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",