@howells/fieldwork-sdk 0.5.2 → 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 +26 -25
- package/dist/{adapter-BhTK51Yj.d.ts → adapter-Bh8EIrNe.d.ts} +1 -1
- package/dist/brave.d.ts +1 -1
- package/dist/brave.js +3 -1
- package/dist/browserbase.d.ts +7 -2
- package/dist/browserbase.js +5 -3
- package/dist/{document-CjMeBtV5.js → document-Clmi51Sf.js} +4 -1
- package/dist/exa.d.ts +2 -2
- package/dist/exa.js +21 -12
- package/dist/{fieldwork-CseCD_-H.d.ts → fieldwork-BaWqUNI3.d.ts} +1 -1
- package/dist/firecrawl.d.ts +2 -2
- package/dist/firecrawl.js +76 -52
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/job-FE9e6HOI.js +107 -0
- package/dist/kernel.d.ts +99 -0
- package/dist/kernel.js +319 -0
- package/dist/llamaparse.d.ts +1 -1
- package/dist/llamaparse.js +18 -11
- package/dist/parallel.d.ts +8 -4
- package/dist/parallel.js +72 -27
- package/dist/{parse-BY3R0oWO.js → parse-COHKvfH9.js} +61 -8
- package/dist/perplexity.d.ts +2 -2
- package/dist/perplexity.js +58 -38
- package/dist/reducto.d.ts +1 -1
- package/dist/reducto.js +18 -11
- package/dist/{schema-CNd51xdD.d.ts → schema-BWWiMvkg.d.ts} +1 -1
- package/dist/serpapi.d.ts +1 -1
- package/dist/serpapi.js +1 -1
- package/dist/tavily.d.ts +2 -2
- package/dist/tavily.js +18 -11
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +22 -3
- package/package.json +9 -2
- package/dist/job-DVsmQMKP.js +0 -47
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
|
-
import {
|
|
4
|
-
import {
|
|
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-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
|
|
@@ -271,6 +271,11 @@ const UsageResponse = looseObject({
|
|
|
271
271
|
key: looseObject({ usage: optionalNumber })
|
|
272
272
|
});
|
|
273
273
|
// src/adapters/tavily.ts
|
|
274
|
+
const RESEARCH_STATES = {
|
|
275
|
+
done: ["completed"],
|
|
276
|
+
failed: ["failed"],
|
|
277
|
+
running: ["pending", "in_progress"]
|
|
278
|
+
};
|
|
274
279
|
/**
|
|
275
280
|
* An adapter for Tavily: search, images, read, readMany, map, crawl, answer, research and usage. Pass it to `new Fieldwork({ adapter })`.
|
|
276
281
|
*
|
|
@@ -432,20 +437,23 @@ const tavily = (config = {}) => {
|
|
|
432
437
|
query: { include_usage: true }
|
|
433
438
|
});
|
|
434
439
|
const parsed = z.parse(ResearchRun, current);
|
|
435
|
-
|
|
440
|
+
const state = jobState(provider, id, RESEARCH_STATES, {
|
|
441
|
+
original: current,
|
|
442
|
+
value: parsed.status
|
|
443
|
+
});
|
|
444
|
+
if (state === "failed") throw new FieldworkError("JobFailed", `tavily research ${id} failed`, {
|
|
436
445
|
cause: current,
|
|
437
446
|
provider
|
|
438
447
|
});
|
|
439
|
-
return
|
|
448
|
+
return state === "done" ? {
|
|
440
449
|
body: parsed,
|
|
441
450
|
response: current
|
|
442
451
|
} : void 0;
|
|
443
452
|
},
|
|
444
453
|
finish: async ({ body: run, response }, id) => {
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
provider
|
|
454
|
+
const content = requireOutput(provider, id, {
|
|
455
|
+
original: response,
|
|
456
|
+
value: run.content
|
|
449
457
|
});
|
|
450
458
|
return compact({
|
|
451
459
|
id,
|
|
@@ -459,8 +467,7 @@ const tavily = (config = {}) => {
|
|
|
459
467
|
status: "completed"
|
|
460
468
|
});
|
|
461
469
|
},
|
|
462
|
-
start: async () =>
|
|
463
|
-
creates: true,
|
|
470
|
+
start: async () => await startJob(raw, "/research", {
|
|
464
471
|
...call,
|
|
465
472
|
body: compact({
|
|
466
473
|
citation_format: o.citationFormat,
|
|
@@ -473,7 +480,7 @@ const tavily = (config = {}) => {
|
|
|
473
480
|
output_schema: o.schema === void 0 ? void 0 : jsonSchemaOf(o.schema),
|
|
474
481
|
stream: false
|
|
475
482
|
})
|
|
476
|
-
})
|
|
483
|
+
}, ResearchStart, (reply) => reply.request_id)
|
|
477
484
|
}, {
|
|
478
485
|
...call,
|
|
479
486
|
interval: o.interval,
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-
|
|
2
|
-
import { M as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-
|
|
1
|
+
import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-BaWqUNI3.js";
|
|
2
|
+
import { M as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-Bh8EIrNe.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
|
@@ -196,6 +196,12 @@ const condition = object({
|
|
|
196
196
|
description: text("The condition in plain words."),
|
|
197
197
|
name: text("A short name for the condition.")
|
|
198
198
|
}, ["name", "description"]);
|
|
199
|
+
/** The `stealth` input: a browser that hides automation and solves CAPTCHAs, for sites that block bots. */
|
|
200
|
+
const stealth = (providers) => ({
|
|
201
|
+
name: "stealth",
|
|
202
|
+
providers,
|
|
203
|
+
schema: flag("Use a stealth browser that hides automation and solves CAPTCHAs. Use when a site blocks or challenges the plain browser.")
|
|
204
|
+
});
|
|
199
205
|
const meta = object({
|
|
200
206
|
requestId: str,
|
|
201
207
|
usage: object({
|
|
@@ -745,6 +751,12 @@ const BROWSER_SPECS = [
|
|
|
745
751
|
providers: ["browserbase"],
|
|
746
752
|
schema: whole("Seconds the session may live, 60 to 21600. It closes by itself after that.", 60, 21600)
|
|
747
753
|
},
|
|
754
|
+
{
|
|
755
|
+
name: "idleTimeout",
|
|
756
|
+
providers: ["kernel"],
|
|
757
|
+
schema: whole("Seconds without a CDP or live-view connection before the session closes by itself, 10 to 259200. Defaults to 60.", 10, 259200)
|
|
758
|
+
},
|
|
759
|
+
stealth(["kernel"]),
|
|
748
760
|
country(["firecrawl"], "Browse from")
|
|
749
761
|
],
|
|
750
762
|
idempotent: false,
|
|
@@ -1012,7 +1024,8 @@ const READ_SPECS = [
|
|
|
1012
1024
|
query,
|
|
1013
1025
|
maxAge(["exa", "firecrawl"]),
|
|
1014
1026
|
maxAgeAtLeast600(),
|
|
1015
|
-
country(["browserbase"], "Fetch the page through a proxy in")
|
|
1027
|
+
country(["browserbase"], "Fetch the page through a proxy in"),
|
|
1028
|
+
stealth(["kernel"])
|
|
1016
1029
|
],
|
|
1017
1030
|
idempotent: true,
|
|
1018
1031
|
name: "read_page",
|
|
@@ -1259,13 +1272,17 @@ const operationFor = (web, spec) => {
|
|
|
1259
1272
|
if (spec.method === void 0) return isOperation(entry) ? entry : void 0;
|
|
1260
1273
|
return isGroup(entry) ? entry[spec.method] : void 0;
|
|
1261
1274
|
};
|
|
1275
|
+
/** Standard-alphabet base64: no backtracking, so it is linear in the input. */
|
|
1276
|
+
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/u;
|
|
1262
1277
|
/**
|
|
1263
1278
|
* The `parse` file from the tool's `name` and base64 `contentBase64`.
|
|
1264
1279
|
*
|
|
1265
|
-
* Throws `InvalidRequest` when either is not a string
|
|
1280
|
+
* Throws `InvalidRequest` when either is not a string or the content is not
|
|
1281
|
+
* well-formed base64 (standard alphabet, padded to a multiple of 4).
|
|
1266
1282
|
*/
|
|
1267
1283
|
const documentFrom = (name, content) => {
|
|
1268
1284
|
if (!isText(name) || !isText(content)) throw new FieldworkError("InvalidRequest", "parse_document needs name and contentBase64");
|
|
1285
|
+
if (content.length % 4 !== 0 || !BASE64.test(content)) throw new FieldworkError("InvalidRequest", `parse_document: contentBase64 must be standard base64 padded to a multiple of 4 characters${content.startsWith("data:") ? "; remove the data: prefix" : ""}`);
|
|
1269
1286
|
return {
|
|
1270
1287
|
data: new Uint8Array(Buffer.from(content, "base64")),
|
|
1271
1288
|
name
|
|
@@ -1354,10 +1371,12 @@ const forModel = (result, budget) => {
|
|
|
1354
1371
|
// src/tools/validate.ts
|
|
1355
1372
|
/** The shape only: 2026-02-31 passes and is the provider's to refuse. */
|
|
1356
1373
|
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
1374
|
+
/** Only http and https: "file:///x", "localhost:3000" and "a.com:80/p" parse as URLs with other schemes. */
|
|
1375
|
+
const isWebUrl = (value) => URL.canParse(value) && ["http:", "https:"].includes(new URL(value).protocol);
|
|
1357
1376
|
const textProblem = (schema, value, name) => {
|
|
1358
1377
|
if (value === "") return `${name} must not be empty`;
|
|
1359
1378
|
if (schema.enum !== void 0 && !schema.enum.includes(value)) return `${name} must be one of ${schema.enum.join(", ")}`;
|
|
1360
|
-
if (schema.format === "uri" && !
|
|
1379
|
+
if (schema.format === "uri" && !isWebUrl(value)) return `${name} must be a full URL, including https://`;
|
|
1361
1380
|
if (schema.format === "date" && !DATE.test(value)) return `${name} must be a date as YYYY-MM-DD`;
|
|
1362
1381
|
if (schema.pattern !== void 0 && !new RegExp(schema.pattern, "u").test(value)) return `${name} must match the pattern ${schema.pattern}`;
|
|
1363
1382
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/fieldwork-sdk",
|
|
3
|
-
"version": "0.
|
|
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, LlamaParse and Reducto.",
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
7
7
|
"brave",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"exa",
|
|
11
11
|
"extraction",
|
|
12
12
|
"firecrawl",
|
|
13
|
+
"kernel",
|
|
13
14
|
"llamaparse",
|
|
14
15
|
"monitoring",
|
|
15
16
|
"parallel",
|
|
@@ -75,6 +76,10 @@
|
|
|
75
76
|
"types": "./dist/browserbase.d.ts",
|
|
76
77
|
"import": "./dist/browserbase.js"
|
|
77
78
|
},
|
|
79
|
+
"./kernel": {
|
|
80
|
+
"types": "./dist/kernel.d.ts",
|
|
81
|
+
"import": "./dist/kernel.js"
|
|
82
|
+
},
|
|
78
83
|
"./llamaparse": {
|
|
79
84
|
"types": "./dist/llamaparse.d.ts",
|
|
80
85
|
"import": "./dist/llamaparse.js"
|
|
@@ -92,12 +97,14 @@
|
|
|
92
97
|
"access": "public"
|
|
93
98
|
},
|
|
94
99
|
"dependencies": {
|
|
100
|
+
"turndown": "7.2.5",
|
|
95
101
|
"zod": "^4.6.7"
|
|
96
102
|
},
|
|
97
103
|
"devDependencies": {
|
|
98
104
|
"@howells/lint": "^3.9.1",
|
|
99
105
|
"@howells/typescript-config": "^0.1.8",
|
|
100
106
|
"@types/node": "^26.6.2",
|
|
107
|
+
"@types/turndown": "5.0.6",
|
|
101
108
|
"tsdown": "^0.23.0",
|
|
102
109
|
"typescript": "7.0.2",
|
|
103
110
|
"vitest": "^5.0.1"
|
package/dist/job-DVsmQMKP.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { i as withJob, t as FieldworkError } from "./errors-DROZyb9T.js";
|
|
2
|
-
import { D as sleep, O as stopped } from "./parse-BY3R0oWO.js";
|
|
3
|
-
// src/job.ts
|
|
4
|
-
/**
|
|
5
|
-
* Checks the job every `interval` until it has a finished state. Throws
|
|
6
|
-
* `Timeout` when another interval would pass the deadline, and `Aborted` or
|
|
7
|
-
* `Timeout` (by how the signal stopped) once the signal is aborted. Both carry
|
|
8
|
-
* `jobId`, because the job may still be running.
|
|
9
|
-
*/
|
|
10
|
-
const waitFor = async (provider, id, check, settings) => {
|
|
11
|
-
const interval = settings.interval ?? 2e3;
|
|
12
|
-
const deadline = Date.now() + (settings.timeout ?? 6e5);
|
|
13
|
-
const request = {
|
|
14
|
-
retries: settings.retries,
|
|
15
|
-
signal: settings.signal
|
|
16
|
-
};
|
|
17
|
-
for (;;) {
|
|
18
|
-
if (settings.signal?.aborted === true) throw stopped(settings.signal, `stopped waiting for ${provider} job ${id}; it may still be running`, {
|
|
19
|
-
jobId: id,
|
|
20
|
-
provider
|
|
21
|
-
});
|
|
22
|
-
const found = await check(id, request);
|
|
23
|
-
if (found !== void 0) return found;
|
|
24
|
-
if (Date.now() + interval > deadline) throw new FieldworkError("Timeout", `${provider} job ${id} did not finish in time; it may still be running`, {
|
|
25
|
-
jobId: id,
|
|
26
|
-
provider
|
|
27
|
-
});
|
|
28
|
-
await sleep(interval, settings.signal);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Runs an asynchronous job to its result: resumes the job named by `resume`
|
|
33
|
-
* or starts one, checks it until it finishes, then builds the result.
|
|
34
|
-
*
|
|
35
|
-
* Every error after the job has an id carries it as `jobId`, including a
|
|
36
|
-
* timeout or cancellation while waiting, so the caller can resume rather than
|
|
37
|
-
* start a second job.
|
|
38
|
-
*/
|
|
39
|
-
const runJob = async (provider, job, settings) => {
|
|
40
|
-
const id = settings.resume ?? await job.start();
|
|
41
|
-
try {
|
|
42
|
-
return await job.finish(await waitFor(provider, id, job.check, settings), id);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
throw withJob(error, id);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
export { runJob as t };
|