@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.
- package/README.md +73 -15
- package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
- package/dist/adapter-J2yatZJ0.d.ts +73 -0
- package/dist/best-DiKYwLdC.js +1436 -0
- package/dist/brave.d.ts +7 -6
- package/dist/brave.js +175 -168
- package/dist/browserbase.d.ts +4 -3
- package/dist/browserbase.js +182 -167
- package/dist/{document-DMIUCoDA.js → document-x9fWsQ1W.js} +2 -2
- package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
- package/dist/{adapter-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
- package/dist/exa.d.ts +18 -11
- package/dist/exa.js +301 -267
- package/dist/fieldwork-D7npPoUf.d.ts +35 -0
- package/dist/firecrawl.d.ts +4 -3
- package/dist/firecrawl.js +432 -399
- package/dist/{parse-Q7H4mrnO.js → http-Bg0h3D-t.js} +222 -224
- package/dist/image.d.ts +253 -0
- package/dist/image.js +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +66 -82
- package/dist/{job-DnavRq_s.js → job-BsrOrrO1.js} +7 -7
- package/dist/kernel.d.ts +20 -2
- package/dist/kernel.js +58 -12
- package/dist/llamaparse.d.ts +3 -2
- package/dist/llamaparse.js +8 -8
- package/dist/parallel.d.ts +10 -10
- package/dist/parallel.js +432 -391
- package/dist/path-tDCyAKK9.js +10 -0
- package/dist/perplexity.d.ts +6 -5
- package/dist/perplexity.js +16 -16
- package/dist/reducto.d.ts +3 -2
- package/dist/reducto.js +8 -8
- package/dist/{schema--iU4AXSM.js → schema-Bfd2E8u2.js} +12 -3
- package/dist/{schema-CAPSX7yQ.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
- package/dist/serpapi.d.ts +3 -3
- package/dist/serpapi.js +170 -165
- package/dist/tavily.d.ts +4 -3
- package/dist/tavily.js +242 -229
- package/dist/tools.d.ts +79 -15
- package/dist/tools.js +431 -77
- package/dist/{util-DFUXQX6v.js → util-BOqd71Om.js} +44 -12
- package/package.json +11 -6
- package/dist/fieldwork-BrfoehvG.d.ts +0 -113
- package/dist/path-DL5P8XH2.js +0 -17
- package/dist/util-DhYr1OS3.d.ts +0 -1
- package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
import { t as FieldworkError } from "./errors-
|
|
1
|
+
import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
|
|
2
|
+
import * as z from "zod/mini";
|
|
3
|
+
// src/json.ts
|
|
4
|
+
const isText = (value) => typeof value === "string";
|
|
5
|
+
/** A finite number: JSON has no NaN or Infinity. */
|
|
6
|
+
const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
7
|
+
const isFlag = (value) => typeof value === "boolean";
|
|
8
|
+
const isList = (value) => Array.isArray(value);
|
|
9
|
+
/** Checks a value is JSON all the way down, for a body or field that arrives untyped. */
|
|
10
|
+
const jsonValue = z.json();
|
|
11
|
+
/** Parses JSON text. Throws `SyntaxError` when the text is not JSON. */
|
|
12
|
+
const parseJsonText = (text) => {
|
|
13
|
+
const parsed = JSON.parse(text);
|
|
14
|
+
return z.parse(jsonValue, parsed);
|
|
15
|
+
};
|
|
16
|
+
/** Narrows anything, such as a value a transport hands over, to a JSON object. */
|
|
17
|
+
const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
18
|
// src/util.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Drops the keys whose value is undefined, so a request body or result carries
|
|
21
|
+
* only what was set. Shallow: nested objects are not touched. Every key left
|
|
22
|
+
* keeps the type T gives it, and a dropped key reads as undefined, as before.
|
|
23
|
+
*/
|
|
24
|
+
const compact = (value) => {
|
|
25
|
+
const result = { ...value };
|
|
26
|
+
for (const [key, item] of Object.entries(result)) if (item === void 0) Reflect.deleteProperty(result, key);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
8
29
|
/** The longest `timeout` a timer holds, in milliseconds: about 24.8 days. */
|
|
9
|
-
const MAX_TIMEOUT =
|
|
30
|
+
const MAX_TIMEOUT = 0x7fffffff;
|
|
10
31
|
/**
|
|
11
32
|
* Refuses a `timeout` or `retries` that no timer or retry count can hold,
|
|
12
33
|
* before anything is sent.
|
|
@@ -30,7 +51,7 @@ const checkCallSettings = (settings) => {
|
|
|
30
51
|
* timeout to the provider and needs a moment more to hear its report.
|
|
31
52
|
*/
|
|
32
53
|
const callSettings = (options, grace = 0) => {
|
|
33
|
-
const { retries, signal, timeout, ...rest } = options
|
|
54
|
+
const { retries, signal, timeout, ...rest } = options;
|
|
34
55
|
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");
|
|
35
56
|
checkCallSettings({
|
|
36
57
|
retries,
|
|
@@ -53,9 +74,9 @@ const callSettings = (options, grace = 0) => {
|
|
|
53
74
|
* not valid JSON.
|
|
54
75
|
*/
|
|
55
76
|
const parseJson = (provider, value) => {
|
|
56
|
-
if (
|
|
77
|
+
if (!isText(value)) return value;
|
|
57
78
|
try {
|
|
58
|
-
return
|
|
79
|
+
return parseJsonText(value);
|
|
59
80
|
} catch (error) {
|
|
60
81
|
throw new FieldworkError("ProviderError", `${provider} returned output that is not valid JSON`, {
|
|
61
82
|
cause: error,
|
|
@@ -107,6 +128,14 @@ const meta = (parts) => {
|
|
|
107
128
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
108
129
|
};
|
|
109
130
|
/**
|
|
131
|
+
* Refuses an option value that is not a positive whole number (`>= 1`),
|
|
132
|
+
* throwing `InvalidRequest` before anything is sent. Undefined passes through.
|
|
133
|
+
*/
|
|
134
|
+
const positiveWhole = (provider, name, value) => {
|
|
135
|
+
if (value !== void 0 && (!Number.isInteger(value) || value < 1)) throw new FieldworkError("InvalidRequest", `${provider}: ${name} must be a whole number of at least 1 (got ${value})`, { provider });
|
|
136
|
+
return value;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
110
139
|
* Refuses a request that sets more than one of `names` (a name counts as set
|
|
111
140
|
* unless its value is undefined), for options the provider rejects or ignores
|
|
112
141
|
* when combined. Throws before anything is sent.
|
|
@@ -122,7 +151,10 @@ const refuseTogether = (provider, options, ...names) => {
|
|
|
122
151
|
* up, so 1 second is 1 hour and 0 stays 0 (always fetch fresh). A negative age
|
|
123
152
|
* (read only the cache) becomes -1. Undefined stays undefined.
|
|
124
153
|
*/
|
|
125
|
-
const hours = (seconds) =>
|
|
154
|
+
const hours = (seconds) => {
|
|
155
|
+
if (seconds === void 0) return;
|
|
156
|
+
return seconds < 0 ? -1 : Math.ceil(seconds / 3600);
|
|
157
|
+
};
|
|
126
158
|
/** Statuses that mean the page is not there, so a read of it has no page to return. */
|
|
127
159
|
const GONE = /* @__PURE__ */ new Set([404, 410]);
|
|
128
160
|
/**
|
|
@@ -145,4 +177,4 @@ const presentPages = (pages) => ({
|
|
|
145
177
|
})),
|
|
146
178
|
pages: pages.filter((page) => page.statusCode === void 0 || !GONE.has(page.statusCode))
|
|
147
179
|
});
|
|
148
|
-
export { compact as a, parseJson as c,
|
|
180
|
+
export { isList as _, compact as a, jsonValue as b, parseJson as c, presentPages as d, refuseTogether as f, isJsonObject as g, isFlag as h, citationsOf as i, positiveWhole as l, uniqueCitations as m, checkCallSettings as n, hours as o, requireJobId as p, citationOf as r, meta as s, callSettings as t, presentPage as u, isNumber as v, parseJsonText as x, isText as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/fieldwork-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "One API for web search, reverse image 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",
|
|
@@ -88,6 +88,10 @@
|
|
|
88
88
|
"types": "./dist/reducto.d.ts",
|
|
89
89
|
"import": "./dist/reducto.js"
|
|
90
90
|
},
|
|
91
|
+
"./image": {
|
|
92
|
+
"types": "./dist/image.d.ts",
|
|
93
|
+
"import": "./dist/image.js"
|
|
94
|
+
},
|
|
91
95
|
"./tools": {
|
|
92
96
|
"types": "./dist/tools.d.ts",
|
|
93
97
|
"import": "./dist/tools.js"
|
|
@@ -97,17 +101,18 @@
|
|
|
97
101
|
"access": "public"
|
|
98
102
|
},
|
|
99
103
|
"dependencies": {
|
|
104
|
+
"@mixmark-io/domino": "2.2.0",
|
|
100
105
|
"turndown": "7.2.5",
|
|
101
106
|
"zod": "^4.6.7"
|
|
102
107
|
},
|
|
103
108
|
"devDependencies": {
|
|
104
|
-
"@howells/lint": "
|
|
105
|
-
"@howells/typescript-config": "^0.1.
|
|
106
|
-
"@types/node": "^26.6.
|
|
109
|
+
"@howells/lint": "3.9.1",
|
|
110
|
+
"@howells/typescript-config": "^0.1.9",
|
|
111
|
+
"@types/node": "^26.6.11",
|
|
107
112
|
"@types/turndown": "5.0.6",
|
|
108
|
-
"tsdown": "^0.23.
|
|
113
|
+
"tsdown": "^0.23.8",
|
|
109
114
|
"typescript": "7.0.2",
|
|
110
|
-
"vitest": "^5.
|
|
115
|
+
"vitest": "^5.1.2"
|
|
111
116
|
},
|
|
112
117
|
"engines": {
|
|
113
118
|
"node": ">=22.12.0"
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { m as Capability, n as AnyAdapter, z as Meta } from "./adapter-B8kAAAgF.js";
|
|
2
|
-
/** Why a call failed. Branch on this, not on the message, which can change. */
|
|
3
|
-
type FieldworkErrorCode =
|
|
4
|
-
/** The adapter's provider does not offer this capability. */
|
|
5
|
-
"Unsupported" |
|
|
6
|
-
/** The API key is missing or the provider rejected it. */
|
|
7
|
-
"Unauthorized" |
|
|
8
|
-
/** The provider refused the request because of a rate or plan limit. */
|
|
9
|
-
"RateLimited" |
|
|
10
|
-
/** A 404, or a page read that answered 404 or 410. */
|
|
11
|
-
"NotFound" |
|
|
12
|
-
/** The request is malformed or combines options the provider rejects: its 400 or 422, or Fieldwork refusing it before sending. */
|
|
13
|
-
"InvalidRequest" |
|
|
14
|
-
/** An asynchronous job finished without a result. */
|
|
15
|
-
"JobFailed" |
|
|
16
|
-
/** The call's `timeout` ran out, a job did not finish within it, or the provider answered 408. */
|
|
17
|
-
"Timeout" |
|
|
18
|
-
/** The caller's `signal` cancelled the call. */
|
|
19
|
-
"Aborted" |
|
|
20
|
-
/** A downloaded file is larger than `maxBytes` or the provider's ceiling. */
|
|
21
|
-
"TooLarge" |
|
|
22
|
-
/** A download reached a web page (HTML), not a file. */
|
|
23
|
-
"NotAFile" |
|
|
24
|
-
/** Any other provider failure. */
|
|
25
|
-
"ProviderError";
|
|
26
|
-
/** What a `FieldworkError` carries besides its code and message. */
|
|
27
|
-
interface FieldworkErrorOptions {
|
|
28
|
-
/** The provider the call was for, such as "exa". */
|
|
29
|
-
provider?: string;
|
|
30
|
-
/** The HTTP status the provider answered with. */
|
|
31
|
-
status?: number;
|
|
32
|
-
/** Seconds the provider asked to wait before retrying. */
|
|
33
|
-
retryAfter?: number;
|
|
34
|
-
/** The provider's id for an asynchronous job that was already created. */
|
|
35
|
-
jobId?: string;
|
|
36
|
-
/** Overrides the default, which follows from the code and status. */
|
|
37
|
-
retryable?: boolean;
|
|
38
|
-
/** What the failure came from, such as the provider's parsed error body or the underlying fetch error. */
|
|
39
|
-
cause?: unknown;
|
|
40
|
-
/** What the provider reported for a call it billed before the failure. */
|
|
41
|
-
meta?: Meta;
|
|
42
|
-
}
|
|
43
|
-
/** The one error type every adapter throws, with a normalized code. */
|
|
44
|
-
declare class FieldworkError extends Error {
|
|
45
|
-
readonly name = "FieldworkError";
|
|
46
|
-
readonly code: FieldworkErrorCode;
|
|
47
|
-
/** The provider the call was for, when the error came from one. */
|
|
48
|
-
readonly provider?: string;
|
|
49
|
-
/** The HTTP status the provider answered with, when there was a response. */
|
|
50
|
-
readonly status?: number;
|
|
51
|
-
/** Seconds the provider asked to wait before retrying, from its `Retry-After` header. */
|
|
52
|
-
readonly retryAfter?: number;
|
|
53
|
-
/**
|
|
54
|
-
* The provider's id for an asynchronous job that was already created when
|
|
55
|
-
* the call failed. The job may still be running and billing: pass this id
|
|
56
|
-
* as `resume` to wait for it again rather than starting another.
|
|
57
|
-
*/
|
|
58
|
-
readonly jobId?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Whether repeating the same call can succeed. False whenever `jobId` is
|
|
61
|
-
* set, because repeating the call would start a second job; resume it.
|
|
62
|
-
*/
|
|
63
|
-
readonly retryable: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* What the provider reported for a call it billed before the failure, in
|
|
66
|
-
* the shape a result's `meta` has: `meta.usage.credits` for Firecrawl's
|
|
67
|
-
* scrape, `meta.usage.units.uptime_ms` for a Kernel session. Absent when
|
|
68
|
-
* the call failed before the provider billed anything.
|
|
69
|
-
*/
|
|
70
|
-
readonly meta?: Meta;
|
|
71
|
-
constructor(code: FieldworkErrorCode, message: string, options?: FieldworkErrorOptions);
|
|
72
|
-
/** The fields an agent or a log needs, without the provider's response. */
|
|
73
|
-
toJSON(): {
|
|
74
|
-
code: FieldworkErrorCode;
|
|
75
|
-
jobId: string | undefined;
|
|
76
|
-
message: string;
|
|
77
|
-
name: string;
|
|
78
|
-
provider: string | undefined;
|
|
79
|
-
retryAfter: number | undefined;
|
|
80
|
-
retryable: boolean;
|
|
81
|
-
status: number | undefined;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/** What `new Fieldwork` takes. */
|
|
85
|
-
interface FieldworkOptions<A extends AnyAdapter> {
|
|
86
|
-
/** The provider to call, such as `exa()`, or a `router` over several. */
|
|
87
|
-
adapter: A;
|
|
88
|
-
}
|
|
89
|
-
interface FieldworkBase<A extends AnyAdapter> {
|
|
90
|
-
/** The adapter's name, such as "firecrawl" or "router". */
|
|
91
|
-
readonly provider: A["name"];
|
|
92
|
-
/** Which capabilities this instance can call. */
|
|
93
|
-
readonly capabilities: Readonly<Record<Capability, boolean>>;
|
|
94
|
-
/** The provider's HTTP API, for anything Fieldwork does not wrap. */
|
|
95
|
-
readonly raw: A["raw"];
|
|
96
|
-
/** Whether the capability can be called. Same as `capabilities[capability]`. */
|
|
97
|
-
supports: (capability: Capability) => boolean;
|
|
98
|
-
/** The provider that serves a capability, or undefined when none does. */
|
|
99
|
-
providerFor: (capability: Capability) => string | undefined;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* A Fieldwork instance has exactly the methods its adapter's provider offers.
|
|
103
|
-
* `new Fieldwork({ adapter: tavily() }).act(...)` does not compile, because
|
|
104
|
-
* Tavily has no browser.
|
|
105
|
-
*/
|
|
106
|
-
type Fieldwork<A extends AnyAdapter> = FieldworkBase<A> & Readonly<A["operations"]>;
|
|
107
|
-
/**
|
|
108
|
-
* The client: `new Fieldwork({ adapter })` has exactly the methods its adapter offers.
|
|
109
|
-
*
|
|
110
|
-
* Check `supports` or `capabilities` before calling dynamically; a capability the provider lacks throws `Unsupported`.
|
|
111
|
-
*/
|
|
112
|
-
declare const Fieldwork: new <A extends AnyAdapter>(options: FieldworkOptions<A>) => Fieldwork<A>;
|
|
113
|
-
export { FieldworkErrorCode as i, FieldworkOptions as n, FieldworkError as r, Fieldwork as t };
|
package/dist/path-DL5P8XH2.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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 };
|
package/dist/util-DhYr1OS3.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "zod/mini";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
+
/** Rate limits, timeouts and 5xx statuses can succeed on repeat. The HTTP client still does not repeat a call whose own deadline ran out. */
|
|
3
|
+
const isRetryable = (code, status) => {
|
|
4
|
+
if (code === "RateLimited" || code === "Timeout") return true;
|
|
5
|
+
return status !== void 0 && status >= 500;
|
|
6
|
+
};
|
|
2
7
|
/** The one error type every adapter throws, with a normalized code. */
|
|
3
8
|
var FieldworkError = class extends Error {
|
|
4
9
|
name = "FieldworkError";
|
|
@@ -51,11 +56,6 @@ var FieldworkError = class extends Error {
|
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
};
|
|
54
|
-
/** Rate limits, timeouts and 5xx statuses can succeed on repeat. The HTTP client still does not repeat a call whose own deadline ran out. */
|
|
55
|
-
const isRetryable = (code, status) => {
|
|
56
|
-
if (code === "RateLimited" || code === "Timeout") return true;
|
|
57
|
-
return status !== void 0 && status >= 500;
|
|
58
|
-
};
|
|
59
59
|
/**
|
|
60
60
|
* The error with the job it belongs to attached. An error that is not a
|
|
61
61
|
* `FieldworkError`, or that already has a `jobId`, comes back as it is.
|