@howells/fieldwork-sdk 0.6.0 → 0.7.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
@@ -69,7 +69,7 @@ Options are typed per provider. An option means the same thing under the same na
69
69
  | `query` | On `read`: return the passages that answer it as `excerpts`. |
70
70
  | `content` | On `search`: include each result's page text. |
71
71
  | `continueFrom` | On `answer` and `research`: the `continuationId` of an earlier result, to ask a follow-up. |
72
- | `resume`, `interval` | On jobs: collect an earlier job by its id, and the milliseconds between status checks. |
72
+ | `resume`, `interval` | On jobs: collect an earlier job by its id, and the milliseconds between status checks (unset: 500, doubling to 2000). |
73
73
 
74
74
  Options only one provider has keep that provider's meaning and values, such as Tavily's `topic`, Exa's `category`, SerpApi's `engine` or Firecrawl's `proxy`. A combination a provider would reject or silently ignore, such as `includeDomains` with `excludeDomains` on Parallel, throws `InvalidRequest` before anything is sent.
75
75
 
@@ -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.
@@ -448,9 +448,16 @@ interface ParsedDocument {
448
448
  }
449
449
  /** A file to parse: its bytes and its name, which tells the provider the type. */
450
450
  interface DocumentInput {
451
+ url?: never;
451
452
  data: Blob | Uint8Array | ArrayBuffer;
452
453
  name: string;
453
454
  }
455
+ /** A public document URL the provider fetches itself; never downloaded by Fieldwork. */
456
+ interface DocumentUrl {
457
+ url: string;
458
+ data?: never;
459
+ name?: never;
460
+ }
454
461
  /** How often a monitor checks: a cron expression or a named interval. */
455
462
  type MonitorSchedule = {
456
463
  cron: string;
@@ -577,4 +584,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
577
584
  * It returns its argument unchanged; write a custom adapter with it.
578
585
  */
579
586
  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 };
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 };
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 { 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";
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 { 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";
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 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";
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-CWHOfhP_.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-C1mzXyKH.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 { $ 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";
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-CWHOfhP_.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 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";
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, 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,15 +1,20 @@
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
6
+ /** The first wait between checks when `interval` is unset, and the longest. */
7
+ const FIRST_WAIT = 500;
8
+ const LONGEST_WAIT = 2e3;
5
9
  /**
6
- * Checks the job every `interval` until it has a finished state. Throws
7
- * `Timeout` when another interval would pass the deadline, and `Aborted` or
10
+ * Checks the job until it has a finished state, waiting `interval` between
11
+ * checks, or 500 ms doubling to 2000 ms when it is unset. Throws
12
+ * `Timeout` when another wait would pass the deadline, and `Aborted` or
8
13
  * `Timeout` (by how the signal stopped) once the signal is aborted. Both carry
9
14
  * `jobId`, because the job may still be running.
10
15
  */
11
16
  const waitFor = async (provider, id, check, settings) => {
12
- const interval = settings.interval ?? 2e3;
17
+ let wait = settings.interval ?? FIRST_WAIT;
13
18
  const deadline = Date.now() + (settings.timeout ?? 6e5);
14
19
  const request = {
15
20
  retries: settings.retries,
@@ -22,11 +27,12 @@ const waitFor = async (provider, id, check, settings) => {
22
27
  });
23
28
  const found = await check(id, request);
24
29
  if (found !== void 0) return found;
25
- if (Date.now() + interval > deadline) throw new FieldworkError("Timeout", `${provider} job ${id} did not finish in time; it may still be running`, {
30
+ if (Date.now() + wait > deadline) throw new FieldworkError("Timeout", `${provider} job ${id} did not finish in time; it may still be running`, {
26
31
  jobId: id,
27
32
  provider
28
33
  });
29
- await sleep(interval, settings.signal);
34
+ await sleep(wait, settings.signal);
35
+ if (settings.interval === void 0) wait = Math.min(wait * 2, LONGEST_WAIT);
30
36
  }
31
37
  };
32
38
  /**
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 { a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter, z as Page } from "./adapter-C1mzXyKH.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-CWHOfhP_.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
@@ -50,13 +51,20 @@ const CHROME = /* @__PURE__ */ new Set([
50
51
  ]);
51
52
  /**
52
53
  * The Playwright script `read` runs in the browser. It waits for the DOM and
53
- * then up to 10 seconds for the network to go quiet: pages that poll or
54
- * stream never do, and their content has rendered by then.
54
+ * then up to 3 seconds for the network to go quiet: pages that poll or
55
+ * stream never do, and their content has rendered by then. It reads the HTML,
56
+ * title and URL in one call into the page, because each call waits its turn
57
+ * behind the page's own scripts, seconds on a busy page.
55
58
  */
56
59
  const readScript = (url) => `
57
60
  const response = await page.goto(${JSON.stringify(url)}, { waitUntil: "domcontentloaded", timeout: 90000 });
58
- await page.waitForLoadState("networkidle", { timeout: 10000 }).catch(() => undefined);
59
- return { html: await page.content(), status: response?.status() ?? null, title: await page.title(), url: page.url() };
61
+ await page.waitForLoadState("networkidle", { timeout: 3000 }).catch(() => undefined);
62
+ const rendered = await page.evaluate(() => ({
63
+ html: (document.doctype ? new XMLSerializer().serializeToString(document.doctype) : "") + document.documentElement.outerHTML,
64
+ title: document.title,
65
+ url: location.href,
66
+ }));
67
+ return { ...rendered, status: response?.status() ?? null };
60
68
  `;
61
69
  /** Whether the node has a main or article element among its ancestors. */
62
70
  const inContent = (node) => node.parentNode !== null && (CONTENT.has(node.parentNode.nodeName.toLowerCase()) || inContent(node.parentNode));
@@ -159,7 +167,6 @@ const billedTime = async (raw, id, call) => {
159
167
  finish: (body) => body.usage?.uptime_ms,
160
168
  start: async () => id
161
169
  }, {
162
- interval: 500,
163
170
  retries: call.retries,
164
171
  signal: call.signal,
165
172
  timeout: BILLED_TIME_WAIT
@@ -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, T as DocumentUrl, V as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-C1mzXyKH.js";
2
2
  /** Settings for `llamaparse()`. */
3
3
  export interface LlamaParseConfig {
4
4
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -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-CWHOfhP_.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. */
@@ -160,6 +161,13 @@ const configuration = (o) => compact({
160
161
  /** Uploads the file and returns the job id. Refuses a missing document, or a file over the size limit, before sending. */
161
162
  const startParse = async (raw, document, o, call) => {
162
163
  if (document === void 0) throw new FieldworkError("InvalidRequest", "parse needs a document, or resume with the id of an earlier parse", { provider });
164
+ if (document.url !== void 0) return await startJob(raw, "/api/v2/parse", {
165
+ ...call,
166
+ body: {
167
+ ...configuration(o),
168
+ source_url: documentUrl(provider, document)
169
+ }
170
+ }, JobStart, (reply) => reply.id);
163
171
  refuseLarger(provider, document, MAX_PARSE_MB);
164
172
  const form = new FormData();
165
173
  form.set("configuration", JSON.stringify(configuration(o)));
@@ -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 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";
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-CWHOfhP_.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. */
@@ -1,151 +1,6 @@
1
1
  import { n as codeForStatus, t as FieldworkError } from "./errors-DROZyb9T.js";
2
+ import { d as record, n as checkCallSettings } from "./util-BqeRYF2b.js";
2
3
  import * as z from "zod/mini";
3
- // src/util.ts
4
- const isJson = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
- /** The value as an object, or an empty one when it is null, an array or not an object, so a read of a missing body needs no guard. */
6
- const record = (value) => isJson(value) ? value : {};
7
- /** Drops the keys whose value is undefined, so a request body or result carries only what was set. Shallow: nested objects are not touched. */
8
- const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
9
- /** The longest `timeout` a timer holds, in milliseconds: about 24.8 days. */
10
- const MAX_TIMEOUT = 2147483647;
11
- /**
12
- * Refuses a `timeout` or `retries` that no timer or retry count can hold,
13
- * before anything is sent.
14
- *
15
- * Throws `InvalidRequest` naming the accepted range.
16
- */
17
- const checkCallSettings = (settings) => {
18
- const { retries, timeout } = settings;
19
- if (timeout !== void 0 && !(Number.isInteger(timeout) && timeout >= 0 && timeout <= MAX_TIMEOUT)) throw new FieldworkError("InvalidRequest", `timeout is ${timeout}: pass a whole number of milliseconds from 0 to ${MAX_TIMEOUT}`);
20
- if (retries !== void 0 && !(Number.isInteger(retries) && retries >= 0)) throw new FieldworkError("InvalidRequest", `retries is ${retries}: pass a whole number from 0 up`);
21
- };
22
- /**
23
- * Splits an operation's options into the provider's own and the call's
24
- * settings. The call's `signal` also carries its `timeout` as a deadline, set
25
- * now, so every request the operation makes (a start, each poll, a result
26
- * download) shares one budget instead of restarting it. An empty `resume`
27
- * names no job, and a `timeout` or `retries` out of range holds no deadline or
28
- * count, so both are refused here, once for every adapter.
29
- *
30
- * `grace` extends the deadline past `timeout` for an operation that sends the
31
- * timeout to the provider and needs a moment more to hear its report.
32
- */
33
- const callSettings = (options, grace = 0) => {
34
- const { retries, signal, timeout, ...rest } = options ?? {};
35
- if ("resume" in rest && rest.resume === "") throw new FieldworkError("InvalidRequest", "resume is empty: pass the jobId an earlier call returned, or leave resume out to start a job");
36
- checkCallSettings({
37
- retries,
38
- timeout
39
- });
40
- return {
41
- call: {
42
- retries,
43
- signal: timeout === void 0 ? signal : AbortSignal.any([...signal === void 0 ? [] : [signal], AbortSignal.timeout(Math.min(timeout + grace, MAX_TIMEOUT))]),
44
- timeout
45
- },
46
- rest
47
- };
48
- };
49
- /**
50
- * Reads a provider field that holds JSON text. A value that is not a string
51
- * is returned as it is, already parsed.
52
- *
53
- * Throws `ProviderError` carrying the parse error as `cause` when the text is
54
- * not valid JSON.
55
- */
56
- const parseJson = (provider, value) => {
57
- if (typeof value !== "string") return value;
58
- try {
59
- return JSON.parse(value);
60
- } catch (error) {
61
- throw new FieldworkError("ProviderError", `${provider} returned output that is not valid JSON`, {
62
- cause: error,
63
- provider
64
- });
65
- }
66
- };
67
- /** The citations with repeated URLs removed: the first of each URL stays, in order. */
68
- const uniqueCitations = (all) => {
69
- const seen = /* @__PURE__ */ new Map();
70
- for (const item of all) if (!seen.has(item.url)) seen.set(item.url, item);
71
- return [...seen.values()];
72
- };
73
- /** The citation a parsed source amounts to, or undefined when it has no URL. */
74
- const citationOf = (source) => source.url === void 0 ? void 0 : compact({
75
- excerpts: source.excerpts,
76
- title: source.title,
77
- url: source.url
78
- });
79
- /** The citations the parsed sources amount to; a source without a URL is left out. */
80
- const citationsOf = (sources) => sources.map((source) => citationOf(source)).filter((item) => item !== void 0);
81
- /** The job id a start call returned, or a ProviderError carrying the value as it arrived. */
82
- const requireJobId = (provider, id) => {
83
- if (id.value === void 0) throw new FieldworkError("ProviderError", `${provider} did not return a job id`, {
84
- cause: id.original,
85
- provider
86
- });
87
- return id.value;
88
- };
89
- /**
90
- * Builds a result's `meta`, leaving out whatever is absent: `units` with an
91
- * undefined count, an empty `usage`, no `warnings`. A single warning string
92
- * becomes a one-item list. Returns undefined when nothing is left, so a result
93
- * has no `meta` at all rather than an empty one.
94
- */
95
- const meta = (parts) => {
96
- const units = Object.fromEntries(Object.entries(parts.units ?? {}).filter((entry) => entry[1] !== void 0));
97
- const usage = compact({
98
- costUsd: parts.costUsd,
99
- credits: parts.credits,
100
- units: Object.keys(units).length > 0 ? units : void 0
101
- });
102
- const warnings = [parts.warnings ?? []].flat();
103
- const result = compact({
104
- requestId: parts.requestId,
105
- usage: Object.keys(usage).length > 0 ? usage : void 0,
106
- warnings: warnings.length > 0 ? warnings : void 0
107
- });
108
- return Object.keys(result).length > 0 ? result : void 0;
109
- };
110
- /**
111
- * Refuses a request that sets more than one of `names` (a name counts as set
112
- * unless its value is undefined), for options the provider rejects or ignores
113
- * when combined. Throws before anything is sent.
114
- *
115
- * Throws `InvalidRequest` naming the options that were set.
116
- */
117
- const refuseTogether = (provider, options, ...names) => {
118
- const set = names.filter((name) => options[name] !== void 0);
119
- if (set.length > 1) throw new FieldworkError("InvalidRequest", `${provider} does not accept ${set.join(" and ")} together; pass one`, { provider });
120
- };
121
- /**
122
- * A `maxAge` in seconds as the whole hours Exa and Tavily count in, rounded
123
- * up, so 1 second is 1 hour and 0 stays 0 (always fetch fresh). A negative age
124
- * (read only the cache) becomes -1. Undefined stays undefined.
125
- */
126
- const hours = (seconds) => seconds === void 0 ? void 0 : seconds < 0 ? -1 : Math.ceil(seconds / 3600);
127
- /** Statuses that mean the page is not there, so a read of it has no page to return. */
128
- const GONE = /* @__PURE__ */ new Set([404, 410]);
129
- /**
130
- * A read whose page answered 404 or 410 fails as NotFound, as it does on
131
- * providers that return no page at all, instead of returning the error page
132
- * as if it were the content.
133
- */
134
- const presentPage = (provider, page) => {
135
- if (page.statusCode !== void 0 && GONE.has(page.statusCode)) throw new FieldworkError("NotFound", `${provider} could not read ${page.url}: the page returned ${page.statusCode}`, {
136
- provider,
137
- status: page.statusCode
138
- });
139
- return page;
140
- };
141
- /** Splits a batch's pages into those present and those that answered 404 or 410. */
142
- const presentPages = (pages) => ({
143
- gone: pages.filter((page) => page.statusCode !== void 0 && GONE.has(page.statusCode)).map((page) => ({
144
- error: `the page returned ${page.statusCode}`,
145
- url: page.url
146
- })),
147
- pages: pages.filter((page) => page.statusCode === void 0 || !GONE.has(page.statusCode))
148
- });
149
4
  /**
150
5
  * Waits `ms`. When `signal` aborts it resolves early rather than rejecting, so
151
6
  * the caller checks the signal afterwards. A signal already aborted on entry
@@ -573,4 +428,4 @@ const optionalArrayOf = (item) => z.optional(z.union([z.pipe(z.array(z.unknown()
573
428
  const parsed = z.safeParse(item, entry);
574
429
  return parsed.success ? [parsed.data] : [];
575
430
  }))), absent]));
576
- export { citationOf as A, requireJobId as B, createRawClient as C, sleep as D, segment as E, parseJson as F, presentPage as I, presentPages as L, compact as M, hours as N, stopped as O, meta as P, record as R, withOriginal as S, requireKey as T, uniqueCitations as V, optionalStructure as _, looseObject as a, warningEntry as b, optionalArrayOf as c, optionalId as d, optionalNumber as f, optionalStringOrNumber as g, optionalString as h, both as i, citationsOf as j, callSettings as k, optionalBoolean as l, optionalScalar as m, anything as n, nonEmptyString as o, optionalObject as p, arrayOf as r, optionalAnyString as s, Source as t, optionalFirstString as u, recordOf as v, readSigned as w, warnings as x, sourceShape as y, refuseTogether as z };
431
+ export { createRawClient as C, sleep as D, segment as E, stopped as O, withOriginal as S, requireKey as T, optionalStructure as _, looseObject as a, warningEntry as b, optionalArrayOf as c, optionalId as d, optionalNumber as f, optionalStringOrNumber as g, optionalString as h, both as i, optionalBoolean as l, optionalScalar as m, anything as n, nonEmptyString as o, optionalObject as p, arrayOf as r, optionalAnyString as s, Source as t, optionalFirstString as u, recordOf as v, readSigned as w, warnings as x, sourceShape as y };
@@ -0,0 +1,17 @@
1
+ // src/tools/json.ts
2
+ const isText = (value) => typeof value === "string";
3
+ /** A finite number: JSON has no NaN or Infinity. */
4
+ const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
5
+ const isFlag = (value) => typeof value === "boolean";
6
+ const isList = (value) => Array.isArray(value);
7
+ /** Narrows anything, such as a value a transport hands over, to a JSON object. */
8
+ const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9
+ // src/path.ts
10
+ /** A JSON path, with brackets for indices and keys that are not identifiers. */
11
+ const joinPath = (segments) => {
12
+ let path = "";
13
+ for (const key of segments) if (isNumber(key)) path += `[${key}]`;
14
+ else path += /^[A-Za-z_$][\w$]*$/u.test(key) ? `${path ? "." : ""}${key}` : `[${JSON.stringify(key)}]`;
15
+ return path;
16
+ };
17
+ export { isNumber as a, isList as i, isFlag as n, isText as o, isJsonObject as r, joinPath as t };
@@ -1,5 +1,5 @@
1
- import { K as Recency, Y as SearchResponse, a as RawClient, b as Decisions, l as Answer, p as CallOptions, q as Research, t as Adapter, y as DecisionQuestion } from "./adapter-Bh8EIrNe.js";
2
- import { t as OutputSchema } from "./schema-BWWiMvkg.js";
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";
3
3
  /** Settings for `perplexity()`. */
4
4
  interface PerplexityConfig {
5
5
  /** Defaults to the PERPLEXITY_API_KEY environment variable. */
@@ -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 { A as citationOf, C as createRawClient, E as segment, F as parseJson, M as compact, P as meta, S as withOriginal, T as requireKey, V as uniqueCitations, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, k as callSettings, m as optionalScalar, n as anything, r as arrayOf, t as Source, v as recordOf, y as sourceShape, z as refuseTogether } from "./parse-COHKvfH9.js";
4
- import { i as startJob, r as runJob, t as jobState } from "./job-CWHOfhP_.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, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, t as Source, v as recordOf, y as sourceShape } from "./parse-lMLcxUsG.js";
4
+ import { i as startJob, 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, m as uniqueCitations, r as citationOf, s as meta, t as callSettings } from "./util-BqeRYF2b.js";
6
7
  import * as z from "zod/mini";
7
8
  // src/adapters/perplexity/parse.ts
8
9
  /** The name this adapter reports in errors and results. */
package/dist/reducto.d.ts CHANGED
@@ -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, T as DocumentUrl, V as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-C1mzXyKH.js";
2
2
  /** Settings for `reducto()`. */
3
3
  export interface ReductoConfig {
4
4
  /** Defaults to the REDUCTO_API_KEY environment variable. */
@@ -32,7 +32,7 @@ export type ReductoResumeOptions = Omit<ReductoParseOptions, "resume"> & {
32
32
  export interface ReductoOperations {
33
33
  parse: {
34
34
  /** Uploads the file, starts the parse and waits for it. An error after the parse starts carries `jobId`. */
35
- (document: DocumentInput, options?: ReductoParseOptions): Promise<ParsedDocument>;
35
+ (document: DocumentInput | DocumentUrl, options?: ReductoParseOptions): Promise<ParsedDocument>;
36
36
  /** Collects an earlier parse by its id, without sending the file again. */
37
37
  (options: ReductoResumeOptions): Promise<ParsedDocument>;
38
38
  };