@howells/fieldwork-sdk 0.10.2 → 0.12.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 +104 -16
- package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
- package/dist/adapter-J2yatZJ0.d.ts +73 -0
- package/dist/best-CO9liYDa.js +1436 -0
- package/dist/brave.d.ts +7 -6
- package/dist/brave.js +180 -173
- package/dist/browserbase.d.ts +4 -3
- package/dist/browserbase.js +185 -170
- package/dist/{document-DMIUCoDA.js → document-BSCwJgBM.js} +4 -4
- package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
- package/dist/{adapter-DQrBP1tj.d.ts → errors-gMtejKHc.d.ts} +111 -70
- package/dist/exa.d.ts +18 -11
- package/dist/exa.js +306 -275
- package/dist/fieldwork-D7npPoUf.d.ts +35 -0
- package/dist/firecrawl.d.ts +4 -3
- package/dist/firecrawl.js +450 -417
- package/dist/{parse-Q7H4mrnO.js → http-CJcvTPnE.js} +223 -225
- package/dist/image.d.ts +253 -0
- package/dist/image.js +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +67 -82
- package/dist/{job-DnavRq_s.js → job-JLEpszjr.js} +9 -9
- package/dist/kernel.d.ts +20 -2
- package/dist/kernel.js +65 -19
- package/dist/llamaparse.d.ts +3 -2
- package/dist/llamaparse.js +16 -16
- package/dist/parallel.d.ts +9 -9
- package/dist/parallel.js +423 -389
- package/dist/path-DO2llIdp.js +10 -0
- package/dist/perplexity.d.ts +6 -5
- package/dist/perplexity.js +21 -21
- package/dist/reducto.d.ts +3 -2
- package/dist/reducto.js +14 -14
- package/dist/{schema-BFjS6CSz.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
- package/dist/{schema--iU4AXSM.js → schema-CJXFAZ-x.js} +12 -3
- package/dist/serpapi.d.ts +63 -5
- package/dist/serpapi.js +374 -144
- package/dist/tavily.d.ts +4 -3
- package/dist/tavily.js +247 -234
- package/dist/tools.d.ts +76 -15
- package/dist/tools.js +522 -154
- package/dist/{types-rc8bl8Em.js → types-mq6d6YOK.js} +1 -0
- package/dist/{util-DFUXQX6v.js → util-LvME_uOj.js} +35 -11
- package/package.json +7 -2
- package/dist/fieldwork-JCfyw58T.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,10 +1,31 @@
|
|
|
1
|
-
import { t as FieldworkError } from "./errors-
|
|
1
|
+
import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
|
|
2
|
+
import * as z$1 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$1.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$1.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
30
|
const MAX_TIMEOUT = 2147483647;
|
|
10
31
|
/**
|
|
@@ -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,
|
|
@@ -122,7 +143,10 @@ const refuseTogether = (provider, options, ...names) => {
|
|
|
122
143
|
* up, so 1 second is 1 hour and 0 stays 0 (always fetch fresh). A negative age
|
|
123
144
|
* (read only the cache) becomes -1. Undefined stays undefined.
|
|
124
145
|
*/
|
|
125
|
-
const hours = (seconds) =>
|
|
146
|
+
const hours = (seconds) => {
|
|
147
|
+
if (seconds === void 0) return;
|
|
148
|
+
return seconds < 0 ? -1 : Math.ceil(seconds / 3600);
|
|
149
|
+
};
|
|
126
150
|
/** Statuses that mean the page is not there, so a read of it has no page to return. */
|
|
127
151
|
const GONE = /* @__PURE__ */ new Set([404, 410]);
|
|
128
152
|
/**
|
|
@@ -145,4 +169,4 @@ const presentPages = (pages) => ({
|
|
|
145
169
|
})),
|
|
146
170
|
pages: pages.filter((page) => page.statusCode === void 0 || !GONE.has(page.statusCode))
|
|
147
171
|
});
|
|
148
|
-
export { compact as a, parseJson as c,
|
|
172
|
+
export { isNumber as _, compact as a, parseJsonText as b, parseJson as c, refuseTogether as d, requireJobId as f, isList as g, isJsonObject as h, citationsOf as i, presentPage as l, isFlag as m, checkCallSettings as n, hours as o, uniqueCitations as p, citationOf as r, meta as s, callSettings as t, presentPages as u, isText as v, jsonValue as y };
|
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, Kernel, LlamaParse and Reducto.",
|
|
3
|
+
"version": "0.12.0",
|
|
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",
|
|
7
7
|
"brave",
|
|
@@ -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,6 +101,7 @@
|
|
|
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
|
},
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { L as Meta, m as Capability, n as AnyAdapter } from "./adapter-DQrBP1tj.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.
|