@howells/fieldwork-sdk 0.11.0 → 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 +72 -15
- 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-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
- 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 +66 -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 +8 -8
- 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-CAPSX7yQ.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
- package/dist/{schema--iU4AXSM.js → schema-CJXFAZ-x.js} +12 -3
- package/dist/serpapi.d.ts +3 -3
- package/dist/serpapi.js +176 -171
- package/dist/tavily.d.ts +4 -3
- package/dist/tavily.js +247 -234
- package/dist/tools.d.ts +76 -15
- package/dist/tools.js +351 -33
- package/dist/{util-DFUXQX6v.js → util-LvME_uOj.js} +35 -11
- package/package.json +6 -1
- 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,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.
|