@howells/fieldwork-sdk 0.3.0 → 0.4.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 +33 -3
- package/dist/{adapter-DGehHCMo.d.ts → adapter-CDY8qczv.d.ts} +16 -2
- package/dist/brave.d.ts +6 -4
- package/dist/brave.js +199 -116
- package/dist/browserbase.d.ts +8 -6
- package/dist/browserbase.js +87 -41
- package/dist/exa.d.ts +23 -19
- package/dist/exa.js +300 -160
- package/dist/{fieldwork-B3x3cxDJ.d.ts → fieldwork-DTNVIOzp.d.ts} +3 -3
- package/dist/firecrawl.d.ts +28 -25
- package/dist/firecrawl.js +595 -306
- package/dist/index.d.ts +4 -3
- package/dist/index.js +25 -11
- package/dist/parallel.d.ts +31 -26
- package/dist/parallel.js +407 -203
- package/dist/parse-CxOri73y.js +441 -0
- package/dist/perplexity.d.ts +13 -9
- package/dist/perplexity.js +145 -77
- package/dist/schema-EZlBkY5B.d.ts +90 -0
- package/dist/schema-teOy7Od-.js +45 -0
- package/dist/serpapi.d.ts +7 -4
- package/dist/serpapi.js +264 -162
- package/dist/tavily.d.ts +15 -12
- package/dist/tavily.js +191 -117
- package/dist/tools.d.ts +2 -2
- package/dist/util-DhYr1OS3.d.ts +1 -0
- package/package.json +4 -1
- package/dist/util-CYenIQQT.js +0 -265
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { A as JsonSchema, B as Price, C as Entity, D as GROUP_CAPABILITIES, E as FieldSource, F as MonitorSchedule, G as Research, H as ProductImage, I as Page, J as SearchResult, K as RunStatus, L as PageBatch, M as MonitorEvent, N as MonitorEvents, O as ImageResult, P as MonitorInfo, R as ParsedDocument, S as DocumentPage, T as FailedUrl, U as ProductVariant, V as Product, W as Recency, X as SiteMap, Y as SiteLink, Z as Usage, _ as DecisionAnswer, a as RawClient, b as Discovery, c as ActResult, d as CAPABILITIES, f as CallOptions, g as Crawl, h as Condition, i as defineAdapter, j as Meta, k as ImageSearch, l as Answer, m as Citation, n as AnyAdapter, o as RequestOptions, p as Capability, q as SearchResponse, r as Operations, s as AccountUsage, t as Adapter, u as BrowserSession, v as DecisionQuestion, w as Extraction, x as DocumentInput, y as Decisions, z as Place } from "./adapter-
|
|
2
|
-
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-
|
|
1
|
+
import { A as JsonSchema, B as Price, C as Entity, D as GROUP_CAPABILITIES, E as FieldSource, F as MonitorSchedule, G as Research, H as ProductImage, I as Page, J as SearchResult, K as RunStatus, L as PageBatch, M as MonitorEvent, N as MonitorEvents, O as ImageResult, P as MonitorInfo, R as ParsedDocument, S as DocumentPage, T as FailedUrl, U as ProductVariant, V as Product, W as Recency, X as SiteMap, Y as SiteLink, Z as Usage, _ as DecisionAnswer, a as RawClient, b as Discovery, c as ActResult, d as CAPABILITIES, f as CallOptions, g as Crawl, h as Condition, i as defineAdapter, j as Meta, k as ImageSearch, l as Answer, m as Citation, n as AnyAdapter, o as RequestOptions, p as Capability, q as SearchResponse, r as Operations, s as AccountUsage, t as Adapter, u as BrowserSession, v as DecisionQuestion, w as Extraction, x as DocumentInput, y as Decisions, z as Place } from "./adapter-CDY8qczv.js";
|
|
2
|
+
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-DTNVIOzp.js";
|
|
3
|
+
import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-EZlBkY5B.js";
|
|
3
4
|
type Routes = Partial<Record<Capability, AnyAdapter>>;
|
|
4
5
|
/** Each route must name an adapter whose provider offers that capability. */
|
|
5
6
|
type ValidRoutes<R extends Routes> = { [C in keyof R]: C extends Capability ? R[C] extends {
|
|
@@ -21,4 +22,4 @@ export declare const router: <const R extends Routes>(routes: R & ValidRoutes<R>
|
|
|
21
22
|
* `Unsupported` here instead of failing to compile.
|
|
22
23
|
*/
|
|
23
24
|
export declare const runtimeRouter: (routes: Routes) => AnyAdapter;
|
|
24
|
-
export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentInput, DocumentPage, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, type Routes, RunStatus, SearchResponse, SearchResult, SiteLink, SiteMap, Usage, defineAdapter };
|
|
25
|
+
export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentInput, DocumentPage, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, type OutputSchema, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, type Routes, RunStatus, SearchResponse, SearchResult, SiteLink, SiteMap, type StandardSchemaWithJSON, Usage, defineAdapter };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const bindOperation = (operations, capability) => {
|
|
|
6
6
|
const all = operations;
|
|
7
7
|
const operation = all[capability];
|
|
8
8
|
if (typeof operation === "function") return operation.bind(all);
|
|
9
|
-
if (GROUP_CAPABILITIES.
|
|
9
|
+
if (GROUP_CAPABILITIES.some((group) => group === capability) && typeof operation === "object" && operation !== null) {
|
|
10
10
|
const group = operation;
|
|
11
11
|
return Object.fromEntries(Object.entries(group).map(([name, method]) => [name, typeof method === "function" ? method.bind(group) : method]));
|
|
12
12
|
}
|
|
@@ -28,14 +28,27 @@ var FieldworkClient = class {
|
|
|
28
28
|
this.provider = adapter.name;
|
|
29
29
|
this.raw = adapter.raw;
|
|
30
30
|
this.#providers = adapter.providers ?? {};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const has = (capability) => bindOperation(adapter.operations, capability) !== void 0;
|
|
32
|
+
this.capabilities = Object.freeze({
|
|
33
|
+
act: has("act"),
|
|
34
|
+
answer: has("answer"),
|
|
35
|
+
browser: has("browser"),
|
|
36
|
+
crawl: has("crawl"),
|
|
37
|
+
decide: has("decide"),
|
|
38
|
+
discover: has("discover"),
|
|
39
|
+
extract: has("extract"),
|
|
40
|
+
images: has("images"),
|
|
41
|
+
map: has("map"),
|
|
42
|
+
monitor: has("monitor"),
|
|
43
|
+
parse: has("parse"),
|
|
44
|
+
product: has("product"),
|
|
45
|
+
read: has("read"),
|
|
46
|
+
readMany: has("readMany"),
|
|
47
|
+
research: has("research"),
|
|
48
|
+
search: has("search"),
|
|
49
|
+
usage: has("usage")
|
|
50
|
+
});
|
|
51
|
+
Object.assign(this, Object.fromEntries(CAPABILITIES.map((capability) => [capability, bindOperation(adapter.operations, capability) ?? unsupported(adapter.name, capability)])));
|
|
39
52
|
}
|
|
40
53
|
supports(capability) {
|
|
41
54
|
return this.capabilities[capability];
|
|
@@ -52,11 +65,12 @@ const build = (routes) => {
|
|
|
52
65
|
const raw = {};
|
|
53
66
|
const providers = {};
|
|
54
67
|
for (const [capability, adapter] of Object.entries(routes)) {
|
|
55
|
-
if (
|
|
68
|
+
if (adapter === void 0) continue;
|
|
56
69
|
const operation = bindOperation(adapter.operations, capability);
|
|
57
70
|
if (operation === void 0) throw new FieldworkError("Unsupported", `${adapter.name} does not offer ${capability}`, { provider: adapter.name });
|
|
58
71
|
operations[capability] = operation;
|
|
59
|
-
|
|
72
|
+
const known = CAPABILITIES.find((name) => name === capability);
|
|
73
|
+
if (known !== void 0) providers[known] = adapter.name;
|
|
60
74
|
raw[adapter.name] = adapter.raw;
|
|
61
75
|
}
|
|
62
76
|
return {
|
package/dist/parallel.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as MonitorSchedule, G as Research, I as Page, L as PageBatch, N as MonitorEvents, P as MonitorInfo, a as RawClient, b as Discovery, f as CallOptions, h as Condition, k as ImageSearch, l as Answer, q as SearchResponse, t as Adapter, v as DecisionQuestion, w as Extraction, y as Decisions } from "./adapter-CDY8qczv.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-EZlBkY5B.js";
|
|
3
|
+
import "./util-DhYr1OS3.js";
|
|
2
4
|
interface ParallelConfig {
|
|
3
5
|
/** Defaults to the PARALLEL_API_KEY environment variable. */
|
|
4
6
|
apiKey?: string;
|
|
5
7
|
baseUrl?: string;
|
|
6
8
|
fetch?: typeof fetch;
|
|
9
|
+
/** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
|
|
10
|
+
retries?: number;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* A Task API processor. Parallel documents `processor` as a free string, so any
|
|
@@ -72,13 +76,14 @@ interface ParallelReadOptions extends CallOptions {
|
|
|
72
76
|
sessionId?: string;
|
|
73
77
|
}
|
|
74
78
|
type ParallelReadManyOptions = ParallelReadOptions;
|
|
75
|
-
interface ParallelExtractOptions extends CallOptions {
|
|
79
|
+
interface ParallelExtractOptions<T = unknown> extends CallOptions {
|
|
76
80
|
/**
|
|
77
81
|
* The values to extract. Without one, Parallel picks the fields itself (its
|
|
78
82
|
* `auto` output schema, which gives deep-research style output on `pro` and
|
|
79
|
-
* above).
|
|
83
|
+
* above). A JSON Schema, or a Zod, Valibot or ArkType schema that types and
|
|
84
|
+
* checks `data`.
|
|
80
85
|
*/
|
|
81
|
-
schema?:
|
|
86
|
+
schema?: OutputSchema<T>;
|
|
82
87
|
prompt?: string;
|
|
83
88
|
/** Defaults to "base". */
|
|
84
89
|
processor?: ParallelProcessor;
|
|
@@ -93,9 +98,9 @@ interface ParallelExtractOptions extends CallOptions {
|
|
|
93
98
|
*/
|
|
94
99
|
resume?: string;
|
|
95
100
|
}
|
|
96
|
-
interface ParallelAnswerOptions extends CallOptions {
|
|
101
|
+
interface ParallelAnswerOptions<T = unknown> extends CallOptions {
|
|
97
102
|
/** The answer in the shape of this schema, in `output`. */
|
|
98
|
-
schema?:
|
|
103
|
+
schema?: OutputSchema<T>;
|
|
99
104
|
/** System instructions for the answer. */
|
|
100
105
|
instructions?: string;
|
|
101
106
|
/** How much research the answer does: `low`, `medium` (the default), `high` or `auto`. */
|
|
@@ -108,9 +113,9 @@ interface ParallelAnswerOptions extends CallOptions {
|
|
|
108
113
|
/** Up to 16 keys, keys up to 64 characters, values up to 512. */
|
|
109
114
|
metadata?: Record<string, string>;
|
|
110
115
|
}
|
|
111
|
-
interface ParallelResearchOptions extends CallOptions, ParallelSources {
|
|
116
|
+
interface ParallelResearchOptions<T = unknown> extends CallOptions, ParallelSources {
|
|
112
117
|
/** Structured output in the shape of this schema; without one the output is report text. */
|
|
113
|
-
schema?:
|
|
118
|
+
schema?: OutputSchema<T>;
|
|
114
119
|
/** Defaults to "base". */
|
|
115
120
|
processor?: ParallelProcessor;
|
|
116
121
|
/** The `continuationId` of an earlier run. */
|
|
@@ -126,7 +131,7 @@ interface ParallelResearchOptions extends CallOptions, ParallelSources {
|
|
|
126
131
|
*/
|
|
127
132
|
resume?: string;
|
|
128
133
|
}
|
|
129
|
-
interface ParallelDiscoverOptions extends CallOptions {
|
|
134
|
+
interface ParallelDiscoverOptions<T = unknown> extends CallOptions {
|
|
130
135
|
/** What kind of entity to find, such as "companies" or "people". */
|
|
131
136
|
entityType: string;
|
|
132
137
|
/** Every discovered entity is tested against all of these. */
|
|
@@ -144,7 +149,7 @@ interface ParallelDiscoverOptions extends CallOptions {
|
|
|
144
149
|
* Fills these fields for every match (Parallel's enrichment, run as a Task
|
|
145
150
|
* after the run starts), returned in each entity's `data`.
|
|
146
151
|
*/
|
|
147
|
-
schema?:
|
|
152
|
+
schema?: OutputSchema<T>;
|
|
148
153
|
/** The Task processor that fills `schema`. Parallel defaults to "core". */
|
|
149
154
|
processor?: ParallelProcessor;
|
|
150
155
|
metadata?: ParallelMetadata;
|
|
@@ -178,8 +183,8 @@ interface ParallelMonitorCreateOptions extends CallOptions, ParallelSources {
|
|
|
178
183
|
taskRunId?: string;
|
|
179
184
|
/** Parallel runs at a fixed interval from 1 hour to 30 days; cron is refused. */
|
|
180
185
|
schedule: MonitorSchedule;
|
|
181
|
-
/** Events come back in the shape of this schema. */
|
|
182
|
-
schema?:
|
|
186
|
+
/** Events come back in the shape of this schema. Events are not checked against a Standard Schema. */
|
|
187
|
+
schema?: OutputSchema<unknown>;
|
|
183
188
|
/** The first run returns a sample of recent events (a preview, not exhaustive). */
|
|
184
189
|
includeBackfill?: boolean;
|
|
185
190
|
country?: string;
|
|
@@ -208,22 +213,22 @@ type ParallelDiscovery<T> = Discovery<T> & {
|
|
|
208
213
|
stopReason?: string;
|
|
209
214
|
};
|
|
210
215
|
interface ParallelOperations {
|
|
211
|
-
search(query: string, options?: ParallelSearchOptions)
|
|
212
|
-
images(query: string, options?: ParallelImagesOptions)
|
|
213
|
-
read(url: string, options?: ParallelReadOptions)
|
|
214
|
-
readMany(urls: string[], options?: ParallelReadManyOptions)
|
|
215
|
-
extract<T = unknown>(url: string, options?: ParallelExtractOptions)
|
|
216
|
-
answer<T = unknown>(question: string, options?: ParallelAnswerOptions)
|
|
217
|
-
research<T = unknown>(question: string, options?: ParallelResearchOptions)
|
|
218
|
-
discover<T = Record<string, unknown>>(objective: string, options: ParallelDiscoverOptions)
|
|
219
|
-
decide(context: unknown, questions: Record<string, DecisionQuestion>, options?: ParallelDecideOptions)
|
|
216
|
+
search: (query: string, options?: ParallelSearchOptions) => Promise<SearchResponse>;
|
|
217
|
+
images: (query: string, options?: ParallelImagesOptions) => Promise<ImageSearch>;
|
|
218
|
+
read: (url: string, options?: ParallelReadOptions) => Promise<Page>;
|
|
219
|
+
readMany: (urls: string[], options?: ParallelReadManyOptions) => Promise<PageBatch>;
|
|
220
|
+
extract: <T = unknown>(url: string, options?: ParallelExtractOptions<T>) => Promise<Extraction<T>>;
|
|
221
|
+
answer: <T = unknown>(question: string, options?: ParallelAnswerOptions<T>) => Promise<Answer<T>>;
|
|
222
|
+
research: <T = unknown>(question: string, options?: ParallelResearchOptions<T>) => Promise<Research<T>>;
|
|
223
|
+
discover: <T = Record<string, unknown>>(objective: string, options: ParallelDiscoverOptions<T>) => Promise<ParallelDiscovery<T>>;
|
|
224
|
+
decide: (context: unknown, questions: Record<string, DecisionQuestion>, options?: ParallelDecideOptions) => Promise<Decisions>;
|
|
220
225
|
monitor: {
|
|
221
|
-
create(options: ParallelMonitorCreateOptions)
|
|
222
|
-
get(id: string, options?: CallOptions)
|
|
223
|
-
list(options?: CallOptions)
|
|
226
|
+
create: (options: ParallelMonitorCreateOptions) => Promise<MonitorInfo>;
|
|
227
|
+
get: (id: string, options?: CallOptions) => Promise<MonitorInfo>;
|
|
228
|
+
list: (options?: CallOptions) => Promise<MonitorInfo[]>;
|
|
224
229
|
/** Parallel cancels a monitor for good; it has no delete. */
|
|
225
|
-
delete(id: string, options?: CallOptions)
|
|
226
|
-
events(id: string, options?: ParallelMonitorEventsOptions)
|
|
230
|
+
delete: (id: string, options?: CallOptions) => Promise<void>;
|
|
231
|
+
events: (id: string, options?: ParallelMonitorEventsOptions) => Promise<MonitorEvents>;
|
|
227
232
|
};
|
|
228
233
|
}
|
|
229
234
|
export declare const parallel: (config?: ParallelConfig) => Adapter<"parallel", ParallelOperations, RawClient>;
|