@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/browserbase.js
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { C as createRawClient, E as callSettings, I as refuseTogether, L as requireJobId, N as presentPage, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, j as meta, k as compact, m as optionalScalar, r as arrayOf, s as optionalAnyString } from "./parse-CxOri73y.js";
|
|
4
|
+
import * as z from "zod/mini";
|
|
5
|
+
// src/adapters/browserbase/response.ts
|
|
6
|
+
/** `POST /v1/sessions`. The id keeps the value as it arrived, for the error raised when there is none. */
|
|
7
|
+
const SessionResponse = looseObject({
|
|
8
|
+
connectUrl: optionalString,
|
|
9
|
+
expiresAt: optionalString,
|
|
10
|
+
id: withOriginal(optionalId)
|
|
11
|
+
});
|
|
12
|
+
/** `GET /v1/sessions/{id}/debug`. */
|
|
13
|
+
const DebugResponse = looseObject({
|
|
14
|
+
debuggerFullscreenUrl: optionalString,
|
|
15
|
+
debuggerUrl: optionalString
|
|
16
|
+
});
|
|
17
|
+
/** `POST /v1/fetch`. An empty `content` is kept as it is. */
|
|
18
|
+
const FetchResponse = looseObject({
|
|
19
|
+
content: optionalAnyString,
|
|
20
|
+
contentType: optionalString,
|
|
21
|
+
encoding: optionalString,
|
|
22
|
+
id: optionalScalar,
|
|
23
|
+
statusCode: optionalNumber
|
|
24
|
+
});
|
|
25
|
+
/** `POST /v1/search`. */
|
|
26
|
+
const SearchResponse = looseObject({
|
|
27
|
+
requestId: optionalScalar,
|
|
28
|
+
results: arrayOf(looseObject({
|
|
29
|
+
author: optionalString,
|
|
30
|
+
favicon: optionalString,
|
|
31
|
+
image: optionalString,
|
|
32
|
+
publishedDate: optionalString,
|
|
33
|
+
title: optionalString,
|
|
34
|
+
url: optionalString
|
|
35
|
+
}))
|
|
36
|
+
});
|
|
37
|
+
/** `GET /v1/projects/{id}/usage`. */
|
|
38
|
+
const UsageResponse = looseObject({
|
|
39
|
+
browserMinutes: optionalNumber,
|
|
40
|
+
proxyBytes: optionalNumber
|
|
41
|
+
});
|
|
42
|
+
/** `GET /v1/projects`: an array of projects. */
|
|
43
|
+
const ProjectsResponse = arrayOf(looseObject({ id: withOriginal(optionalId) }));
|
|
4
44
|
// src/adapters/browserbase.ts
|
|
5
45
|
const SEARCH_MODES = {
|
|
6
46
|
exa: [
|
|
@@ -16,7 +56,8 @@ const browserbase = (config = {}) => {
|
|
|
16
56
|
baseUrl: config.baseUrl ?? "https://api.browserbase.com",
|
|
17
57
|
fetch: config.fetch,
|
|
18
58
|
headers: { "x-bb-api-key": requireKey(provider, config.apiKey, "BROWSERBASE_API_KEY") },
|
|
19
|
-
provider
|
|
59
|
+
provider,
|
|
60
|
+
retries: config.retries
|
|
20
61
|
});
|
|
21
62
|
const projectId = config.projectId ?? process.env.BROWSERBASE_PROJECT_ID;
|
|
22
63
|
const invalid = (message) => {
|
|
@@ -27,13 +68,13 @@ const browserbase = (config = {}) => {
|
|
|
27
68
|
const geolocation = o.country === void 0 ? void 0 : { country: o.country.toUpperCase() };
|
|
28
69
|
const proxies = o.proxies ?? (geolocation ? { geolocation } : void 0);
|
|
29
70
|
const place = typeof proxies === "object" ? proxies.geolocation : void 0;
|
|
30
|
-
if (place
|
|
71
|
+
if (place !== void 0 && place.state !== void 0 && place.state !== "" && place.country.toUpperCase() !== "US") invalid("accepts a proxy state only with country US");
|
|
31
72
|
return proxies;
|
|
32
73
|
};
|
|
33
74
|
const liveView = async (id, call) => {
|
|
34
75
|
try {
|
|
35
|
-
const urls =
|
|
36
|
-
return { url:
|
|
76
|
+
const urls = z.parse(DebugResponse, await raw.request("GET", `/v1/sessions/${encodeURIComponent(id)}/debug`, call));
|
|
77
|
+
return { url: urls.debuggerFullscreenUrl ?? urls.debuggerUrl };
|
|
37
78
|
} catch (error) {
|
|
38
79
|
return { warning: `could not get the live view URL: ${error instanceof Error ? error.message : String(error)}` };
|
|
39
80
|
}
|
|
@@ -68,7 +109,8 @@ const browserbase = (config = {}) => {
|
|
|
68
109
|
verified: o.verified,
|
|
69
110
|
viewport: o.viewport
|
|
70
111
|
});
|
|
71
|
-
const
|
|
112
|
+
const response = await raw.request("POST", "/v1/sessions", {
|
|
113
|
+
creates: true,
|
|
72
114
|
...call,
|
|
73
115
|
body: compact({
|
|
74
116
|
browserSettings: Object.keys(browserSettings).length > 0 ? browserSettings : void 0,
|
|
@@ -79,23 +121,24 @@ const browserbase = (config = {}) => {
|
|
|
79
121
|
timeout: o.ttl,
|
|
80
122
|
userMetadata: o.userMetadata
|
|
81
123
|
})
|
|
82
|
-
})
|
|
83
|
-
const
|
|
124
|
+
});
|
|
125
|
+
const session = z.parse(SessionResponse, response);
|
|
126
|
+
const id = requireJobId(provider, session.id);
|
|
84
127
|
const view = await liveView(id, call);
|
|
85
128
|
return compact({
|
|
86
|
-
cdpUrl:
|
|
87
|
-
expiresAt:
|
|
129
|
+
cdpUrl: session.connectUrl,
|
|
130
|
+
expiresAt: session.expiresAt,
|
|
88
131
|
id,
|
|
89
132
|
liveViewUrl: view.url,
|
|
90
133
|
meta: meta({ warnings: view.warning }),
|
|
91
|
-
raw:
|
|
134
|
+
raw: response
|
|
92
135
|
});
|
|
93
136
|
}
|
|
94
137
|
},
|
|
95
138
|
async read(url, options) {
|
|
96
139
|
const { call, rest: o } = callSettings(options);
|
|
97
140
|
const format = o.format ?? "markdown";
|
|
98
|
-
const response =
|
|
141
|
+
const response = await raw.request("POST", "/v1/fetch", {
|
|
99
142
|
...call,
|
|
100
143
|
body: compact({
|
|
101
144
|
allowInsecureSsl: o.allowInsecureSsl,
|
|
@@ -105,21 +148,22 @@ const browserbase = (config = {}) => {
|
|
|
105
148
|
proxies: fetchProxies(o),
|
|
106
149
|
url
|
|
107
150
|
})
|
|
108
|
-
})
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
151
|
+
});
|
|
152
|
+
const body = z.parse(FetchResponse, response);
|
|
153
|
+
const { content } = body;
|
|
154
|
+
const binary = body.encoding === "base64";
|
|
155
|
+
const contentType = body.contentType ?? "";
|
|
156
|
+
return presentPage(provider, compact({
|
|
113
157
|
markdown: format === "markdown" && !binary ? content : void 0,
|
|
114
158
|
meta: meta({
|
|
115
|
-
requestId:
|
|
159
|
+
requestId: body.id,
|
|
116
160
|
warnings: binary ? ["the response is binary; its Base64 content is in raw"] : void 0
|
|
117
161
|
}),
|
|
118
162
|
raw: response,
|
|
119
163
|
rawHtml: format === "raw" && !binary && contentType.includes("html") ? content : void 0,
|
|
120
|
-
statusCode:
|
|
164
|
+
statusCode: body.statusCode,
|
|
121
165
|
url
|
|
122
|
-
});
|
|
166
|
+
}));
|
|
123
167
|
},
|
|
124
168
|
async search(query, options) {
|
|
125
169
|
const { call, rest: o } = callSettings(options);
|
|
@@ -128,7 +172,7 @@ const browserbase = (config = {}) => {
|
|
|
128
172
|
const allowed = SEARCH_MODES[o.provider];
|
|
129
173
|
if (!allowed.includes(o.mode)) invalid(`search provider ${o.provider} has no mode ${o.mode}; use ${allowed.join(", ")}`);
|
|
130
174
|
}
|
|
131
|
-
const response =
|
|
175
|
+
const response = await raw.request("POST", "/v1/search", {
|
|
132
176
|
...call,
|
|
133
177
|
body: compact({
|
|
134
178
|
mode: o.mode,
|
|
@@ -136,40 +180,42 @@ const browserbase = (config = {}) => {
|
|
|
136
180
|
provider: o.provider,
|
|
137
181
|
query
|
|
138
182
|
})
|
|
139
|
-
})
|
|
183
|
+
});
|
|
184
|
+
const body = z.parse(SearchResponse, response);
|
|
140
185
|
return compact({
|
|
141
|
-
meta: meta({ requestId:
|
|
186
|
+
meta: meta({ requestId: body.requestId }),
|
|
142
187
|
raw: response,
|
|
143
|
-
results:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
url: text(result.url) ?? ""
|
|
152
|
-
});
|
|
153
|
-
})
|
|
188
|
+
results: body.results.map((result) => compact({
|
|
189
|
+
author: result.author,
|
|
190
|
+
favicon: result.favicon,
|
|
191
|
+
image: result.image,
|
|
192
|
+
publishedAt: result.publishedDate,
|
|
193
|
+
title: result.title,
|
|
194
|
+
url: result.url ?? ""
|
|
195
|
+
}))
|
|
154
196
|
});
|
|
155
197
|
},
|
|
156
198
|
async usage(options) {
|
|
157
199
|
const { call } = callSettings(options);
|
|
158
200
|
const id = projectId ?? await onlyProject(call);
|
|
159
|
-
const response =
|
|
201
|
+
const response = await raw.request("GET", `/v1/projects/${encodeURIComponent(id)}/usage`, call);
|
|
202
|
+
const body = z.parse(UsageResponse, response);
|
|
160
203
|
return compact({
|
|
161
|
-
breakdown:
|
|
162
|
-
browserMinutes:
|
|
163
|
-
proxyBytes:
|
|
164
|
-
}),
|
|
204
|
+
breakdown: Object.fromEntries(Object.entries({
|
|
205
|
+
browserMinutes: body.browserMinutes,
|
|
206
|
+
proxyBytes: body.proxyBytes
|
|
207
|
+
}).filter((entry) => entry[1] !== void 0)),
|
|
165
208
|
raw: response
|
|
166
209
|
});
|
|
167
210
|
}
|
|
168
211
|
};
|
|
169
212
|
const onlyProject = async (call) => {
|
|
170
|
-
const projects =
|
|
213
|
+
const projects = z.parse(ProjectsResponse, await raw.request("GET", "/v1/projects", call));
|
|
171
214
|
if (projects.length !== 1) invalid(`usage needs a project: pass projectId or set BROWSERBASE_PROJECT_ID (this key has ${projects.length} projects)`);
|
|
172
|
-
return
|
|
215
|
+
return requireJobId(provider, projects[0]?.id ?? {
|
|
216
|
+
original: void 0,
|
|
217
|
+
value: void 0
|
|
218
|
+
});
|
|
173
219
|
};
|
|
174
220
|
return defineAdapter({
|
|
175
221
|
name: provider,
|
package/dist/exa.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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, f as CallOptions, l as Answer, q as SearchResponse, t as Adapter, w as Extraction } from "./adapter-CDY8qczv.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-EZlBkY5B.js";
|
|
2
3
|
interface ExaConfig {
|
|
3
4
|
/** Defaults to the EXA_API_KEY environment variable. */
|
|
4
5
|
apiKey?: string;
|
|
5
6
|
baseUrl?: string;
|
|
6
7
|
fetch?: typeof fetch;
|
|
8
|
+
/** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
|
|
9
|
+
retries?: number;
|
|
7
10
|
}
|
|
8
11
|
/**
|
|
9
12
|
* Exa's `outputSchema` for generated output: free text, or an object schema.
|
|
@@ -100,23 +103,24 @@ interface ExaReadOptions extends CallOptions {
|
|
|
100
103
|
imageLimit?: number;
|
|
101
104
|
}
|
|
102
105
|
type ExaReadManyOptions = ExaReadOptions;
|
|
103
|
-
interface ExaExtractOptions extends CallOptions {
|
|
104
|
-
schema
|
|
106
|
+
interface ExaExtractOptions<T = unknown> extends CallOptions {
|
|
107
|
+
/** A JSON Schema, or a Zod, Valibot or ArkType schema that types and checks `data`. */
|
|
108
|
+
schema: OutputSchema<T>;
|
|
105
109
|
/** What to extract, in plain words. */
|
|
106
110
|
prompt?: string;
|
|
107
111
|
/** Seconds a cached copy may be old; 0 fetches fresh. */
|
|
108
112
|
maxAge?: number;
|
|
109
113
|
}
|
|
110
|
-
interface ExaAnswerOptions extends CallOptions {
|
|
111
|
-
/** JSON Schema (draft 7) for the answer; the answer comes back as an object. */
|
|
112
|
-
schema?:
|
|
114
|
+
interface ExaAnswerOptions<T = unknown> extends CallOptions {
|
|
115
|
+
/** JSON Schema (draft 7) or a Standard Schema for the answer; the answer comes back as an object. */
|
|
116
|
+
schema?: OutputSchema<T>;
|
|
113
117
|
systemPrompt?: string;
|
|
114
118
|
/** Two-letter country code that localizes the search. */
|
|
115
119
|
country?: string;
|
|
116
120
|
model?: "exa" | "exa-pro" | "exa-research" | "exa-fast";
|
|
117
121
|
}
|
|
118
|
-
interface ExaResearchOptions extends CallOptions {
|
|
119
|
-
schema?:
|
|
122
|
+
interface ExaResearchOptions<T = unknown> extends CallOptions {
|
|
123
|
+
schema?: OutputSchema<T>;
|
|
120
124
|
/** Cost and reasoning preference. Defaults to `auto`. */
|
|
121
125
|
effort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "auto" | "ultra";
|
|
122
126
|
/** Spend cap in dollars, 1 to 100. Only `auto` and `ultra` accept it. */
|
|
@@ -172,19 +176,19 @@ interface ExaMonitorEventsOptions extends CallOptions {
|
|
|
172
176
|
limit?: number;
|
|
173
177
|
}
|
|
174
178
|
type ExaMonitor = {
|
|
175
|
-
create(options: ExaMonitorCreateOptions)
|
|
176
|
-
get(id: string, options?: CallOptions)
|
|
177
|
-
list(options?: CallOptions)
|
|
178
|
-
delete(id: string, options?: CallOptions)
|
|
179
|
-
events(id: string, options?: ExaMonitorEventsOptions)
|
|
179
|
+
create: (options: ExaMonitorCreateOptions) => Promise<MonitorInfo>;
|
|
180
|
+
get: (id: string, options?: CallOptions) => Promise<MonitorInfo>;
|
|
181
|
+
list: (options?: CallOptions) => Promise<MonitorInfo[]>;
|
|
182
|
+
delete: (id: string, options?: CallOptions) => Promise<void>;
|
|
183
|
+
events: (id: string, options?: ExaMonitorEventsOptions) => Promise<MonitorEvents>;
|
|
180
184
|
};
|
|
181
185
|
interface ExaOperations {
|
|
182
|
-
search(query: string, options?: ExaSearchOptions)
|
|
183
|
-
read(url: string, options?: ExaReadOptions)
|
|
184
|
-
readMany(urls: string[], options?: ExaReadManyOptions)
|
|
185
|
-
extract<T = unknown>(url: string, options: ExaExtractOptions)
|
|
186
|
-
answer<T = unknown>(question: string, options?: ExaAnswerOptions)
|
|
187
|
-
research<T = unknown>(question: string, options?: ExaResearchOptions)
|
|
186
|
+
search: (query: string, options?: ExaSearchOptions) => Promise<SearchResponse>;
|
|
187
|
+
read: (url: string, options?: ExaReadOptions) => Promise<Page>;
|
|
188
|
+
readMany: (urls: string[], options?: ExaReadManyOptions) => Promise<PageBatch>;
|
|
189
|
+
extract: <T = unknown>(url: string, options: ExaExtractOptions<T>) => Promise<Extraction<T>>;
|
|
190
|
+
answer: <T = unknown>(question: string, options?: ExaAnswerOptions<T>) => Promise<Answer<T>>;
|
|
191
|
+
research: <T = unknown>(question: string, options?: ExaResearchOptions<T>) => Promise<Research<T>>;
|
|
188
192
|
monitor: ExaMonitor;
|
|
189
193
|
}
|
|
190
194
|
export declare const exa: (config?: ExaConfig) => Adapter<"exa", ExaOperations, RawClient>;
|