@howells/fieldwork-sdk 0.6.0 → 0.6.1

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
 
package/dist/exa.js CHANGED
@@ -1,7 +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
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";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import * as z from "zod/mini";
7
7
  const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/u;
package/dist/firecrawl.js CHANGED
@@ -1,7 +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
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";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import { a as refuseLarger, i as mediaTypeOf, n as documentPart, t as MEDIA_TYPES } from "./document-Clmi51Sf.js";
7
7
  import * as z from "zod/mini";
@@ -2,14 +2,18 @@ import { i as withJob, t as FieldworkError } from "./errors-DROZyb9T.js";
2
2
  import { B as requireJobId, D as sleep, O as stopped } from "./parse-COHKvfH9.js";
3
3
  import * as z from "zod/mini";
4
4
  // src/job.ts
5
+ /** The first wait between checks when `interval` is unset, and the longest. */
6
+ const FIRST_WAIT = 500;
7
+ const LONGEST_WAIT = 2e3;
5
8
  /**
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
9
+ * Checks the job until it has a finished state, waiting `interval` between
10
+ * checks, or 500 ms doubling to 2000 ms when it is unset. Throws
11
+ * `Timeout` when another wait would pass the deadline, and `Aborted` or
8
12
  * `Timeout` (by how the signal stopped) once the signal is aborted. Both carry
9
13
  * `jobId`, because the job may still be running.
10
14
  */
11
15
  const waitFor = async (provider, id, check, settings) => {
12
- const interval = settings.interval ?? 2e3;
16
+ let wait = settings.interval ?? FIRST_WAIT;
13
17
  const deadline = Date.now() + (settings.timeout ?? 6e5);
14
18
  const request = {
15
19
  retries: settings.retries,
@@ -22,11 +26,12 @@ const waitFor = async (provider, id, check, settings) => {
22
26
  });
23
27
  const found = await check(id, request);
24
28
  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`, {
29
+ if (Date.now() + wait > deadline) throw new FieldworkError("Timeout", `${provider} job ${id} did not finish in time; it may still be running`, {
26
30
  jobId: id,
27
31
  provider
28
32
  });
29
- await sleep(interval, settings.signal);
33
+ await sleep(wait, settings.signal);
34
+ if (settings.interval === void 0) wait = Math.min(wait * 2, LONGEST_WAIT);
30
35
  }
31
36
  };
32
37
  /**
package/dist/kernel.js CHANGED
@@ -1,7 +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
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";
4
+ import { r as runJob } from "./job-FE9e6HOI.js";
5
5
  import * as z from "zod/mini";
6
6
  import TurndownService from "turndown";
7
7
  // src/adapters/kernel/response.ts
@@ -50,13 +50,20 @@ const CHROME = /* @__PURE__ */ new Set([
50
50
  ]);
51
51
  /**
52
52
  * 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.
53
+ * then up to 3 seconds for the network to go quiet: pages that poll or
54
+ * stream never do, and their content has rendered by then. It reads the HTML,
55
+ * title and URL in one call into the page, because each call waits its turn
56
+ * behind the page's own scripts, seconds on a busy page.
55
57
  */
56
58
  const readScript = (url) => `
57
59
  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() };
60
+ await page.waitForLoadState("networkidle", { timeout: 3000 }).catch(() => undefined);
61
+ const rendered = await page.evaluate(() => ({
62
+ html: (document.doctype ? new XMLSerializer().serializeToString(document.doctype) : "") + document.documentElement.outerHTML,
63
+ title: document.title,
64
+ url: location.href,
65
+ }));
66
+ return { ...rendered, status: response?.status() ?? null };
60
67
  `;
61
68
  /** Whether the node has a main or article element among its ancestors. */
62
69
  const inContent = (node) => node.parentNode !== null && (CONTENT.has(node.parentNode.nodeName.toLowerCase()) || inContent(node.parentNode));
@@ -159,7 +166,6 @@ const billedTime = async (raw, id, call) => {
159
166
  finish: (body) => body.usage?.uptime_ms,
160
167
  start: async () => id
161
168
  }, {
162
- interval: 500,
163
169
  retries: call.retries,
164
170
  signal: call.signal,
165
171
  timeout: BILLED_TIME_WAIT
@@ -2,7 +2,7 @@ import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { a as refuseLarger, n as documentPart, r as enclosing } from "./document-Clmi51Sf.js";
3
3
  import { t as FieldworkError } from "./errors-DROZyb9T.js";
4
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";
5
+ import { i as startJob, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
6
6
  import * as z from "zod/mini";
7
7
  // src/adapters/llamaparse/response.ts
8
8
  /** A box in page points, from the page's top-left corner. */
package/dist/parallel.js CHANGED
@@ -1,7 +1,7 @@
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
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";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import * as z from "zod/mini";
7
7
  // src/adapters/parallel/parse.ts
@@ -1,7 +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
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";
4
+ import { i as startJob, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import * as z from "zod/mini";
7
7
  // src/adapters/perplexity/parse.ts
package/dist/reducto.js CHANGED
@@ -2,7 +2,7 @@ import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { a as refuseLarger, n as documentPart } from "./document-Clmi51Sf.js";
3
3
  import { t as FieldworkError } from "./errors-DROZyb9T.js";
4
4
  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, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, k as callSettings, 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";
5
+ import { i as startJob, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
6
6
  import * as z from "zod/mini";
7
7
  // src/adapters/reducto/response.ts
8
8
  /** A box in fractions of the page, from its top-left corner. `page` counts the pages parsed; `original_page` the file's. */
package/dist/tavily.js CHANGED
@@ -1,7 +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
3
  import { C as createRawClient, E as segment, M as compact, N as hours, 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 } from "./parse-COHKvfH9.js";
4
- import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-CWHOfhP_.js";
4
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-FE9e6HOI.js";
5
5
  import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import * as z from "zod/mini";
7
7
  // src/adapters/tavily/countries.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howells/fieldwork-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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",