@howells/fieldwork-sdk 0.11.0 → 0.13.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.
Files changed (47) hide show
  1. package/README.md +73 -15
  2. package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
  3. package/dist/adapter-J2yatZJ0.d.ts +73 -0
  4. package/dist/best-DiKYwLdC.js +1436 -0
  5. package/dist/brave.d.ts +7 -6
  6. package/dist/brave.js +175 -168
  7. package/dist/browserbase.d.ts +4 -3
  8. package/dist/browserbase.js +182 -167
  9. package/dist/{document-DMIUCoDA.js → document-x9fWsQ1W.js} +2 -2
  10. package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
  11. package/dist/{adapter-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
  12. package/dist/exa.d.ts +18 -11
  13. package/dist/exa.js +301 -267
  14. package/dist/fieldwork-D7npPoUf.d.ts +35 -0
  15. package/dist/firecrawl.d.ts +4 -3
  16. package/dist/firecrawl.js +432 -399
  17. package/dist/{parse-Q7H4mrnO.js → http-Bg0h3D-t.js} +222 -224
  18. package/dist/image.d.ts +253 -0
  19. package/dist/image.js +1 -0
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +66 -82
  22. package/dist/{job-DnavRq_s.js → job-BsrOrrO1.js} +7 -7
  23. package/dist/kernel.d.ts +20 -2
  24. package/dist/kernel.js +58 -12
  25. package/dist/llamaparse.d.ts +3 -2
  26. package/dist/llamaparse.js +8 -8
  27. package/dist/parallel.d.ts +10 -10
  28. package/dist/parallel.js +432 -391
  29. package/dist/path-tDCyAKK9.js +10 -0
  30. package/dist/perplexity.d.ts +6 -5
  31. package/dist/perplexity.js +16 -16
  32. package/dist/reducto.d.ts +3 -2
  33. package/dist/reducto.js +8 -8
  34. package/dist/{schema--iU4AXSM.js → schema-Bfd2E8u2.js} +12 -3
  35. package/dist/{schema-CAPSX7yQ.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
  36. package/dist/serpapi.d.ts +3 -3
  37. package/dist/serpapi.js +170 -165
  38. package/dist/tavily.d.ts +4 -3
  39. package/dist/tavily.js +242 -229
  40. package/dist/tools.d.ts +79 -15
  41. package/dist/tools.js +431 -77
  42. package/dist/{util-DFUXQX6v.js → util-BOqd71Om.js} +44 -12
  43. package/package.json +11 -6
  44. package/dist/fieldwork-BrfoehvG.d.ts +0 -113
  45. package/dist/path-DL5P8XH2.js +0 -17
  46. package/dist/util-DhYr1OS3.d.ts +0 -1
  47. package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
package/dist/kernel.js CHANGED
@@ -1,11 +1,11 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-CP8noBdX.js";
3
- import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
4
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, l as optionalBoolean, n as anything, p as optionalObject, s as optionalAnyString, v as recordOf } from "./parse-Q7H4mrnO.js";
5
- import { a as compact, l as presentPage, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
6
- import { r as runJob } from "./job-DnavRq_s.js";
7
- import * as z from "zod/mini";
8
1
  import TurndownService from "turndown";
2
+ import * as z from "zod/mini";
3
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
4
+ import { a as presentFile, i as header, n as byteLimit, o as tooLarge, r as checkFileUrl, t as MIB } from "./download-kuTqNnuZ.js";
5
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
6
+ import { O as withOriginal, _ as optionalId, c as anything, d as looseObject, h as optionalBoolean, i as segment, p as optionalAnyString, r as requireKey, t as createRawClient, v as optionalNumber, w as recordOf, x as optionalString, y as optionalObject } from "./http-Bg0h3D-t.js";
7
+ import { a as compact, p as requireJobId, s as meta, t as callSettings, u as presentPage } from "./util-BOqd71Om.js";
8
+ import { r as runJob } from "./job-BsrOrrO1.js";
9
9
  // src/adapters/kernel/response.ts
10
10
  /** `POST /browsers`. The id keeps the value as it arrived, for the error raised when there is none. */
11
11
  const BrowserResponse = looseObject({
@@ -23,6 +23,7 @@ const ExecuteResponse = looseObject({
23
23
  error: optionalString,
24
24
  result: anything,
25
25
  stderr: optionalAnyString,
26
+ stdout: optionalAnyString,
26
27
  success: optionalBoolean
27
28
  });
28
29
  /** What the read script returns: the page after it rendered. */
@@ -189,6 +190,10 @@ const inSession = async (raw, o, call, work) => {
189
190
  // src/adapters/kernel.ts
190
191
  /** Seconds Kernel gives the read script, within its 300-second limit. */
191
192
  const READ_SCRIPT_SECONDS = 120;
193
+ /** Seconds Kernel gives an `act` script when the call sets no timeout. */
194
+ const ACT_SCRIPT_SECONDS = 120;
195
+ /** The longest Kernel runs a script. */
196
+ const MAX_SCRIPT_SECONDS = 300;
192
197
  /** The largest file `download` returns: what Kernel's script results carry reliably. */
193
198
  const DOWNLOAD_CEILING = 50 * MIB;
194
199
  /** Seconds Kernel gives the download script, within its 300-second limit. */
@@ -300,7 +305,7 @@ const render = async (raw, id, url, call) => {
300
305
  };
301
306
  };
302
307
  /** Loads the page in a new session and builds the result. */
303
- const readPage = async (raw, url, options) => {
308
+ const readPage = async (raw, url, options = {}) => {
304
309
  const { provider } = raw;
305
310
  const { call, rest: o } = callSettings(options);
306
311
  checkUrl(provider, url);
@@ -326,7 +331,7 @@ const readPage = async (raw, url, options) => {
326
331
  }));
327
332
  };
328
333
  /** Fetches the file in a new session and checks it. */
329
- const downloadFile = async (raw, url, options) => {
334
+ const downloadFile = async (raw, url, options = {}) => {
330
335
  const { provider } = raw;
331
336
  const { call, rest: o } = callSettings(options);
332
337
  checkFileUrl(provider, url);
@@ -373,7 +378,47 @@ const downloadFile = async (raw, url, options) => {
373
378
  }, limit);
374
379
  };
375
380
  /**
376
- * An adapter for Kernel: read, download and browser. Pass it to `new Fieldwork({ adapter })`.
381
+ * The script's limit in seconds: the call's timeout (at least 1), or 120
382
+ * without one. Throws `InvalidRequest` for one over 300 seconds.
383
+ */
384
+ const scriptSeconds = (provider, timeout) => {
385
+ if (timeout === void 0) return ACT_SCRIPT_SECONDS;
386
+ const seconds = Math.max(1, Math.ceil(timeout / 1e3));
387
+ if (seconds > MAX_SCRIPT_SECONDS) throw invalidRequest(provider, `runs a script for at most ${MAX_SCRIPT_SECONDS} seconds`);
388
+ return seconds;
389
+ };
390
+ /**
391
+ * Runs the caller's script in a new session. A script that fails comes back
392
+ * with Kernel's message as `error`, not thrown, with the billed time.
393
+ */
394
+ const runScript = async (raw, code, options = {}) => {
395
+ const { provider } = raw;
396
+ const { call, rest: o } = callSettings(options);
397
+ const seconds = scriptSeconds(provider, call.timeout);
398
+ const { billed, created, id, value } = await inSession(raw, o, call, async (session) => await raw.request("POST", `/browsers/${segment(session)}/playwright/execute`, {
399
+ ...call,
400
+ body: {
401
+ code,
402
+ timeout_sec: seconds
403
+ },
404
+ creates: true
405
+ }));
406
+ const body = z.parse(ExecuteResponse, value);
407
+ const failed = body.success !== true;
408
+ return compact({
409
+ error: failed ? body.error ?? "kernel reported that the script did not succeed" : void 0,
410
+ meta: sessionMeta(id, billed),
411
+ raw: {
412
+ browser: created,
413
+ execute: value
414
+ },
415
+ result: failed ? void 0 : body.result,
416
+ stderr: body.stderr ?? "",
417
+ stdout: body.stdout ?? ""
418
+ });
419
+ };
420
+ /**
421
+ * An adapter for Kernel: read, download, act and browser. Pass it to `fieldwork({ adapter })`.
377
422
  *
378
423
  * Throws `Unauthorized` when neither `apiKey` nor `KERNEL_API_KEY` is set.
379
424
  */
@@ -389,12 +434,13 @@ const kernel = (config = {}) => {
389
434
  return defineAdapter({
390
435
  name: provider,
391
436
  operations: {
437
+ act: async (code, options) => await runScript(raw, code, options),
392
438
  browser: {
393
- async close(id, options) {
439
+ async close(id, options = {}) {
394
440
  const { call } = callSettings(options);
395
441
  await raw.request("DELETE", `/browsers/${segment(id)}`, call);
396
442
  },
397
- async open(options) {
443
+ async open(options = {}) {
398
444
  const { call, rest: o } = callSettings(options);
399
445
  const response = await raw.request("POST", "/browsers", {
400
446
  creates: true,
@@ -1,4 +1,5 @@
1
- import { C as DocumentInput, K as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { H as ParsedDocument, l as CallOptions, x as DocumentUrl, y as DocumentInput } from "./errors-gMtejKHc.js";
2
3
  /** Settings for `llamaparse()`. */
3
4
  export interface LlamaParseConfig {
4
5
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -58,7 +59,7 @@ export interface LlamaParseOperations {
58
59
  };
59
60
  }
60
61
  /**
61
- * An adapter for LlamaParse: parse. Pass it to `new Fieldwork({ adapter })`.
62
+ * An adapter for LlamaParse: parse. Pass it to `fieldwork({ adapter })`.
62
63
  *
63
64
  * Throws `Unauthorized` when neither `apiKey` nor `LLAMA_CLOUD_API_KEY` is set.
64
65
  */
@@ -1,10 +1,10 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { i as enclosing, n as documentPart, o as refuseLarger, r as documentUrl } from "./document-DMIUCoDA.js";
3
- import { t as FieldworkError } from "./errors-DkFJysIM.js";
4
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-Q7H4mrnO.js";
5
- import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
6
- import { a as compact, c as parseJson, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
7
1
  import * as z from "zod/mini";
2
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
3
+ import { i as enclosing, n as documentPart, o as refuseLarger, r as documentUrl } from "./document-x9fWsQ1W.js";
4
+ import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
5
+ import { O as withOriginal, _ as optionalId, b as optionalScalar, c as anything, d as looseObject, i as segment, l as arrayOf, n as readSigned, p as optionalAnyString, r as requireKey, t as createRawClient, v as optionalNumber, x as optionalString } from "./http-Bg0h3D-t.js";
6
+ import { i as startJob, r as runJob, t as jobState } from "./job-BsrOrrO1.js";
7
+ import { a as compact, c as parseJson, s as meta, t as callSettings } from "./util-BOqd71Om.js";
8
8
  // src/adapters/llamaparse/response.ts
9
9
  /** A box in page points, from the page's top-left corner. */
10
10
  const PointBox = looseObject({
@@ -343,7 +343,7 @@ const parse = async (raw, document, options, fetchImpl) => {
343
343
  });
344
344
  };
345
345
  /**
346
- * An adapter for LlamaParse: parse. Pass it to `new Fieldwork({ adapter })`.
346
+ * An adapter for LlamaParse: parse. Pass it to `fieldwork({ adapter })`.
347
347
  *
348
348
  * Throws `Unauthorized` when neither `apiKey` nor `LLAMA_CLOUD_API_KEY` is set.
349
349
  */
@@ -357,7 +357,7 @@ const llamaparse = (config = {}) => {
357
357
  });
358
358
  return defineAdapter({
359
359
  name: provider,
360
- operations: { async parse(first, options) {
360
+ operations: { async parse(first, options = {}) {
361
361
  return "resume" in first ? await parse(raw, void 0, first, config.fetch) : await parse(raw, first, options, config.fetch);
362
362
  } },
363
363
  raw
@@ -1,6 +1,6 @@
1
- import { $ as Research, F as ImageSearch, G as PageBatch, H as MonitorInfo, U as MonitorSchedule, V as MonitorEvents, W as Page, a as RawClient, b as Decisions, g as Condition, k as Extraction, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion } from "./adapter-B8kAAAgF.js";
2
- import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
3
- import "./util-DhYr1OS3.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { B as Page, L as MonitorEvents, Q as SearchResponse, R as MonitorInfo, T as Extraction, V as PageBatch, Y as Research, _ as Discovery, a as Answer, at as JsonObject, f as Condition, g as Decisions, h as DecisionQuestion, j as ImageSearch, l as CallOptions, ot as JsonValue, z as MonitorSchedule } from "./errors-gMtejKHc.js";
3
+ import { t as OutputSchema } from "./schema-C9xzRkKJ.js";
4
4
  /** Settings for `parallel()`. */
5
5
  interface ParallelConfig {
6
6
  /** Defaults to the PARALLEL_API_KEY environment variable. */
@@ -84,8 +84,8 @@ interface ParallelReadOptions extends CallOptions {
84
84
  /** Seconds a cached copy may be old. Parallel's minimum is 600; lower values are refused. */
85
85
  maxAge?: number;
86
86
  /**
87
- * Cap on the characters of the page text returned for each URL. Without it,
88
- * or at 0, the full content is requested with no cap.
87
+ * Cap on the characters of the page text returned for each URL, at least 1.
88
+ * Without it, the full content is requested with no cap.
89
89
  */
90
90
  maxContentChars?: number;
91
91
  /** Cap on the characters of excerpts returned for each URL. */
@@ -181,7 +181,7 @@ interface ParallelResearchOptions<T = unknown> extends CallOptions, ParallelSour
181
181
  * least one match returns `status: "partial"`; one that ends with no match throws
182
182
  * `JobFailed`.
183
183
  */
184
- interface ParallelDiscoverOptions<T = unknown> extends CallOptions {
184
+ interface ParallelDiscoverOptions<T = JsonObject> extends CallOptions {
185
185
  /** What kind of entity to find, such as "companies" or "people". */
186
186
  entityType: string;
187
187
  /** Every discovered entity is tested against all of these. */
@@ -199,7 +199,7 @@ interface ParallelDiscoverOptions<T = unknown> extends CallOptions {
199
199
  * Fills these fields for every match (Parallel's enrichment, run as a Task
200
200
  * after the run starts), returned in each entity's `data`.
201
201
  */
202
- schema?: OutputSchema<T>;
202
+ schema?: OutputSchema<T, JsonObject>;
203
203
  /** The Task processor that fills `schema`. Parallel defaults to "core". */
204
204
  processor?: ParallelProcessor;
205
205
  metadata?: ParallelMetadata;
@@ -296,8 +296,8 @@ interface ParallelOperations {
296
296
  extract: <T = unknown>(url: string, options?: ParallelExtractOptions<T>) => Promise<Extraction<T>>;
297
297
  answer: <T = unknown>(question: string, options?: ParallelAnswerOptions<T>) => Promise<Answer<T>>;
298
298
  research: <T = unknown>(question: string, options?: ParallelResearchOptions<T>) => Promise<Research<T>>;
299
- discover: <T = Record<string, unknown>>(objective: string, options: ParallelDiscoverOptions<T>) => Promise<ParallelDiscovery<T>>;
300
- decide: (context: unknown, questions: Record<string, DecisionQuestion>, options?: ParallelDecideOptions) => Promise<Decisions>;
299
+ discover: <T = JsonObject>(objective: string, options: ParallelDiscoverOptions<T>) => Promise<ParallelDiscovery<T>>;
300
+ decide: (context: JsonValue, questions: Record<string, DecisionQuestion>, options?: ParallelDecideOptions) => Promise<Decisions>;
301
301
  monitor: {
302
302
  create: (options: ParallelMonitorCreateOptions) => Promise<MonitorInfo>;
303
303
  get: (id: string, options?: CallOptions) => Promise<MonitorInfo>;
@@ -308,7 +308,7 @@ interface ParallelOperations {
308
308
  };
309
309
  }
310
310
  /**
311
- * An adapter for Parallel: search, images, read, readMany, extract, answer, research, discover, decide and monitor. Pass it to `new Fieldwork({ adapter })`.
311
+ * An adapter for Parallel: search, images, read, readMany, extract, answer, research, discover, decide and monitor. Pass it to `fieldwork({ adapter })`.
312
312
  *
313
313
  * Throws `Unauthorized` when neither `apiKey` nor `PARALLEL_API_KEY` is set.
314
314
  */