@howells/fieldwork-sdk 0.5.0 → 0.5.2
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/dist/{adapter-BgdfLBs-.d.ts → adapter-BhTK51Yj.d.ts} +19 -5
- package/dist/brave.d.ts +22 -4
- package/dist/brave.js +69 -2
- package/dist/browserbase.d.ts +23 -3
- package/dist/browserbase.js +5 -2
- package/dist/{document-Dpj01mGx.js → document-CjMeBtV5.js} +1 -1
- package/dist/{errors-Yvk42oZH.js → errors-DROZyb9T.js} +13 -0
- package/dist/exa.d.ts +49 -7
- package/dist/exa.js +84 -24
- package/dist/{fieldwork-CXNIcqSN.d.ts → fieldwork-CseCD_-H.d.ts} +20 -4
- package/dist/firecrawl.d.ts +64 -4
- package/dist/firecrawl.js +231 -110
- package/dist/index.d.ts +3 -3
- package/dist/index.js +25 -1
- package/dist/job-DVsmQMKP.js +47 -0
- package/dist/llamaparse.d.ts +7 -2
- package/dist/llamaparse.js +39 -38
- package/dist/parallel.d.ts +79 -7
- package/dist/parallel.js +176 -69
- package/dist/{parse-D4SMt-Ip.js → parse-BY3R0oWO.js} +56 -43
- package/dist/perplexity.d.ts +37 -5
- package/dist/perplexity.js +121 -30
- package/dist/reducto.d.ts +16 -2
- package/dist/reducto.js +50 -47
- package/dist/{schema-DbSIABP0.js → schema-BYcXgfuZ.js} +8 -4
- package/dist/{schema-Cupy7-7q.d.ts → schema-CNd51xdD.d.ts} +1 -1
- package/dist/serpapi.d.ts +25 -5
- package/dist/serpapi.js +99 -2
- package/dist/tavily.d.ts +44 -4
- package/dist/tavily.js +80 -53
- package/dist/tools.d.ts +16 -18
- package/dist/tools.js +129 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as TableCell, A as ImageResult, B as ParsedDocument, C as DocumentInput, D as FailedUrl, E as Extraction, F as MonitorEvents, G as ProductVariant, H as Price, I as MonitorInfo, J as RunStatus, K as Recency, L as MonitorSchedule, M as JsonSchema, N as Meta, O as FieldSource, P as MonitorEvent, Q as SiteMap, R as Page, S as DocumentBlock, T as Entity, U as Product, V as Place, W as ProductImage, X as SearchResult, Y as SearchResponse, Z as SiteLink, _ as Crawl, a as RawClient, b as Decisions, c as ActResult, d as BrowserSession, et as Usage, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, j as ImageSearch, k as GROUP_CAPABILITIES, l as Answer, m as Capability, n as AnyAdapter, o as RequestOptions, p as CallOptions, q as Research, r as Operations, s as AccountUsage, t as Adapter, tt as WordBox, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-
|
|
2
|
-
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-
|
|
3
|
-
import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as TableCell, A as ImageResult, B as ParsedDocument, C as DocumentInput, D as FailedUrl, E as Extraction, F as MonitorEvents, G as ProductVariant, H as Price, I as MonitorInfo, J as RunStatus, K as Recency, L as MonitorSchedule, M as JsonSchema, N as Meta, O as FieldSource, P as MonitorEvent, Q as SiteMap, R as Page, S as DocumentBlock, T as Entity, U as Product, V as Place, W as ProductImage, X as SearchResult, Y as SearchResponse, Z as SiteLink, _ as Crawl, a as RawClient, b as Decisions, c as ActResult, d as BrowserSession, et as Usage, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, j as ImageSearch, k as GROUP_CAPABILITIES, l as Answer, m as Capability, n as AnyAdapter, o as RequestOptions, p as CallOptions, q as Research, r as Operations, s as AccountUsage, t as Adapter, tt as WordBox, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-BhTK51Yj.js";
|
|
2
|
+
import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-CseCD_-H.js";
|
|
3
|
+
import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-CNd51xdD.js";
|
|
4
4
|
/** Which adapter serves each capability, for `router`. */
|
|
5
5
|
type Routes = Partial<Record<Capability, AnyAdapter>>;
|
|
6
6
|
/** Each route must name an adapter whose provider offers that capability. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { t as FieldworkError } from "./errors-
|
|
2
|
+
import { t as FieldworkError } from "./errors-DROZyb9T.js";
|
|
3
3
|
import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-CnomnF-6.js";
|
|
4
4
|
// src/fieldwork.ts
|
|
5
|
+
/**
|
|
6
|
+
* The adapter's operation for a capability, bound to its `operations` object
|
|
7
|
+
* (or, for a group such as `monitor`, each method bound to the group) so it
|
|
8
|
+
* can be called detached. Undefined when the adapter lacks the capability.
|
|
9
|
+
* `Fieldwork` and `router` both bind through this.
|
|
10
|
+
*/
|
|
5
11
|
const bindOperation = (operations, capability) => {
|
|
6
12
|
const all = operations;
|
|
7
13
|
const operation = all[capability];
|
|
@@ -11,6 +17,7 @@ const bindOperation = (operations, capability) => {
|
|
|
11
17
|
return Object.fromEntries(Object.entries(group).map(([name, method]) => [name, typeof method === "function" ? method.bind(group) : method]));
|
|
12
18
|
}
|
|
13
19
|
};
|
|
20
|
+
/** What a capability the provider lacks does when called: throws `Unsupported`, for every method of a group too. */
|
|
14
21
|
const unsupported = (provider, capability) => {
|
|
15
22
|
const refuse = async () => {
|
|
16
23
|
throw new FieldworkError("Unsupported", `${provider} does not offer ${capability}`, { provider });
|
|
@@ -18,6 +25,11 @@ const unsupported = (provider, capability) => {
|
|
|
18
25
|
if (!GROUP_CAPABILITIES.includes(capability)) return refuse;
|
|
19
26
|
return new Proxy({}, { get: () => refuse });
|
|
20
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* The implementation behind `Fieldwork`, typed loosely: each capability name
|
|
30
|
+
* is assigned onto the instance in the constructor, as the adapter's bound
|
|
31
|
+
* operation or a stand-in that throws `Unsupported`.
|
|
32
|
+
*/
|
|
21
33
|
var FieldworkClient = class {
|
|
22
34
|
provider;
|
|
23
35
|
capabilities;
|
|
@@ -66,10 +78,19 @@ var FieldworkClient = class {
|
|
|
66
78
|
*/
|
|
67
79
|
const Fieldwork = FieldworkClient;
|
|
68
80
|
// src/router.ts
|
|
81
|
+
/**
|
|
82
|
+
* Binds each route's operation and records which provider serves it, so
|
|
83
|
+
* `Fieldwork.providerFor` can say. `raw` is keyed by provider name, so every
|
|
84
|
+
* route to one provider must use the same adapter instance.
|
|
85
|
+
*
|
|
86
|
+
* Throws `Unsupported` for a route to an adapter that lacks the capability,
|
|
87
|
+
* and `InvalidRequest` for two instances of one provider.
|
|
88
|
+
*/
|
|
69
89
|
const build = (routes) => {
|
|
70
90
|
const operations = {};
|
|
71
91
|
const raw = {};
|
|
72
92
|
const providers = {};
|
|
93
|
+
const instances = /* @__PURE__ */ new Map();
|
|
73
94
|
for (const [capability, adapter] of Object.entries(routes)) {
|
|
74
95
|
if (adapter === void 0) continue;
|
|
75
96
|
const operation = bindOperation(adapter.operations, capability);
|
|
@@ -77,6 +98,9 @@ const build = (routes) => {
|
|
|
77
98
|
operations[capability] = operation;
|
|
78
99
|
const known = CAPABILITIES.find((name) => name === capability);
|
|
79
100
|
if (known !== void 0) providers[known] = adapter.name;
|
|
101
|
+
const earlier = instances.get(adapter.name);
|
|
102
|
+
if (earlier !== void 0 && earlier !== adapter) throw new FieldworkError("InvalidRequest", `routes use two ${adapter.name} adapters; route every capability to one instance`, { provider: adapter.name });
|
|
103
|
+
instances.set(adapter.name, adapter);
|
|
80
104
|
raw[adapter.name] = adapter.raw;
|
|
81
105
|
}
|
|
82
106
|
return {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { i as withJob, t as FieldworkError } from "./errors-DROZyb9T.js";
|
|
2
|
+
import { D as sleep, O as stopped } from "./parse-BY3R0oWO.js";
|
|
3
|
+
// src/job.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks the job every `interval` until it has a finished state. Throws
|
|
6
|
+
* `Timeout` when another interval would pass the deadline, and `Aborted` or
|
|
7
|
+
* `Timeout` (by how the signal stopped) once the signal is aborted. Both carry
|
|
8
|
+
* `jobId`, because the job may still be running.
|
|
9
|
+
*/
|
|
10
|
+
const waitFor = async (provider, id, check, settings) => {
|
|
11
|
+
const interval = settings.interval ?? 2e3;
|
|
12
|
+
const deadline = Date.now() + (settings.timeout ?? 6e5);
|
|
13
|
+
const request = {
|
|
14
|
+
retries: settings.retries,
|
|
15
|
+
signal: settings.signal
|
|
16
|
+
};
|
|
17
|
+
for (;;) {
|
|
18
|
+
if (settings.signal?.aborted === true) throw stopped(settings.signal, `stopped waiting for ${provider} job ${id}; it may still be running`, {
|
|
19
|
+
jobId: id,
|
|
20
|
+
provider
|
|
21
|
+
});
|
|
22
|
+
const found = await check(id, request);
|
|
23
|
+
if (found !== void 0) return found;
|
|
24
|
+
if (Date.now() + interval > deadline) throw new FieldworkError("Timeout", `${provider} job ${id} did not finish in time; it may still be running`, {
|
|
25
|
+
jobId: id,
|
|
26
|
+
provider
|
|
27
|
+
});
|
|
28
|
+
await sleep(interval, settings.signal);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Runs an asynchronous job to its result: resumes the job named by `resume`
|
|
33
|
+
* or starts one, checks it until it finishes, then builds the result.
|
|
34
|
+
*
|
|
35
|
+
* Every error after the job has an id carries it as `jobId`, including a
|
|
36
|
+
* timeout or cancellation while waiting, so the caller can resume rather than
|
|
37
|
+
* start a second job.
|
|
38
|
+
*/
|
|
39
|
+
const runJob = async (provider, job, settings) => {
|
|
40
|
+
const id = settings.resume ?? await job.start();
|
|
41
|
+
try {
|
|
42
|
+
return await job.finish(await waitFor(provider, id, job.check, settings), id);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw withJob(error, id);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export { runJob as t };
|
package/dist/llamaparse.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { B as ParsedDocument, C as DocumentInput, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-
|
|
1
|
+
import { B as ParsedDocument, C as DocumentInput, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-BhTK51Yj.js";
|
|
2
|
+
/** Settings for `llamaparse()`. */
|
|
2
3
|
export interface LlamaParseConfig {
|
|
3
4
|
/** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
|
|
4
5
|
apiKey?: string;
|
|
5
6
|
/** Defaults to https://api.cloud.llamaindex.ai; the EU region is https://api.cloud.eu.llamaindex.ai. */
|
|
6
7
|
baseUrl?: string;
|
|
8
|
+
/** Defaults to the global `fetch`. It also downloads result files from the presigned URLs LlamaParse returns. A test passes a fake. */
|
|
7
9
|
fetch?: typeof fetch;
|
|
8
10
|
/** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
|
|
9
11
|
retries?: number;
|
|
@@ -13,6 +15,7 @@ export interface LlamaParseConfig {
|
|
|
13
15
|
* no AI model; `agentic` reads tables, scans and multi-column layouts.
|
|
14
16
|
*/
|
|
15
17
|
export type LlamaParseTier = "fast" | "cost_effective" | "agentic" | "agentic_plus";
|
|
18
|
+
/** Options for `parse`. */
|
|
16
19
|
export interface LlamaParseParseOptions extends CallOptions {
|
|
17
20
|
/** Defaults to "agentic". */
|
|
18
21
|
tier?: LlamaParseTier;
|
|
@@ -22,7 +25,7 @@ export interface LlamaParseParseOptions extends CallOptions {
|
|
|
22
25
|
blocks?: boolean;
|
|
23
26
|
/**
|
|
24
27
|
* Also return where each word and table cell sits in each block, from a
|
|
25
|
-
* second download. Returns blocks too.
|
|
28
|
+
* second download. Returns blocks too.
|
|
26
29
|
*/
|
|
27
30
|
wordBoxes?: boolean;
|
|
28
31
|
/** Leave out text a reader cannot see, such as white text on white. */
|
|
@@ -43,8 +46,10 @@ export interface LlamaParseParseOptions extends CallOptions {
|
|
|
43
46
|
export type LlamaParseResumeOptions = Omit<LlamaParseParseOptions, "resume"> & {
|
|
44
47
|
resume: string;
|
|
45
48
|
};
|
|
49
|
+
/** What the LlamaParse adapter offers. */
|
|
46
50
|
export interface LlamaParseOperations {
|
|
47
51
|
parse: {
|
|
52
|
+
/** Uploads the file and waits for the parse. An error after the upload carries `jobId`. */
|
|
48
53
|
(document: DocumentInput, options?: LlamaParseParseOptions): Promise<ParsedDocument>;
|
|
49
54
|
/** Collects an earlier parse by its id, without sending the file again. */
|
|
50
55
|
(options: LlamaParseResumeOptions): Promise<ParsedDocument>;
|
package/dist/llamaparse.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { a as refuseLarger, n as documentPart, r as enclosing } from "./document-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { a as refuseLarger, n as documentPart, r as enclosing } from "./document-CjMeBtV5.js";
|
|
3
|
+
import { t as FieldworkError } from "./errors-DROZyb9T.js";
|
|
4
|
+
import { B as requireJobId, C as createRawClient, E as segment, F as parseJson, M as compact, P as meta, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, k as callSettings, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-BY3R0oWO.js";
|
|
5
|
+
import { t as runJob } from "./job-DVsmQMKP.js";
|
|
5
6
|
import * as z from "zod/mini";
|
|
6
7
|
// src/adapters/llamaparse/response.ts
|
|
7
8
|
/** A box in page points, from the page's top-left corner. */
|
|
@@ -142,6 +143,7 @@ const provider = "llamaparse";
|
|
|
142
143
|
const PAGE_IMAGE = /^page_(?<page>\d+)\.jpg$/u;
|
|
143
144
|
/** The largest file LlamaParse takes, in megabytes. */
|
|
144
145
|
const MAX_PARSE_MB = 512;
|
|
146
|
+
/** The upload's `configuration`. The tier and version are always sent; the rest only when asked for. */
|
|
145
147
|
const configuration = (o) => compact({
|
|
146
148
|
output_options: o.wordBoxes === true || o.pageImages === true ? compact({
|
|
147
149
|
granular_bboxes: o.wordBoxes === true ? [
|
|
@@ -155,8 +157,8 @@ const configuration = (o) => compact({
|
|
|
155
157
|
tier: o.tier ?? "agentic",
|
|
156
158
|
version: o.version ?? "latest"
|
|
157
159
|
});
|
|
160
|
+
/** Uploads the file and returns the job id. Refuses a missing document, or a file over the size limit, before sending. */
|
|
158
161
|
const startParse = async (raw, document, o, call) => {
|
|
159
|
-
if (o.resume !== void 0) return o.resume;
|
|
160
162
|
if (document === void 0) throw new FieldworkError("InvalidRequest", "parse needs a document, or resume with the id of an earlier parse", { provider });
|
|
161
163
|
refuseLarger(provider, document, MAX_PARSE_MB);
|
|
162
164
|
const form = new FormData();
|
|
@@ -169,28 +171,23 @@ const startParse = async (raw, document, o, call) => {
|
|
|
169
171
|
}));
|
|
170
172
|
return requireJobId(provider, created.id);
|
|
171
173
|
};
|
|
172
|
-
|
|
174
|
+
/** The result once the job has completed, undefined while it runs; throws `JobFailed` when LlamaParse failed or cancelled it. */
|
|
175
|
+
const finished = (found) => {
|
|
173
176
|
const { error_message: message, status } = found.value.job;
|
|
174
177
|
if (status === "FAILED" || status === "CANCELLED") throw new FieldworkError("JobFailed", `llamaparse job ${status.toLowerCase()}${message === void 0 ? "" : `: ${message}`}`, {
|
|
175
178
|
cause: found.original,
|
|
176
|
-
jobId: id,
|
|
177
179
|
provider
|
|
178
180
|
});
|
|
179
181
|
return status === "COMPLETED" ? found : void 0;
|
|
180
182
|
};
|
|
181
183
|
/** The grounded items: one JSON line per page, each page's items with word and cell boxes. */
|
|
182
|
-
const groundedPages = async (found,
|
|
184
|
+
const groundedPages = async (found, options) => {
|
|
183
185
|
const url = found.value.result_content_metadata.grounded_items.presigned_url;
|
|
184
186
|
if (url === void 0) throw new FieldworkError("ProviderError", "llamaparse finished without the word boxes it was asked for", {
|
|
185
187
|
cause: found.original,
|
|
186
|
-
jobId: id,
|
|
187
188
|
provider
|
|
188
189
|
});
|
|
189
|
-
|
|
190
|
-
return (await readSigned(provider, url, options)).split("\n").filter((line) => line.trim() !== "").map((line) => parseJson(provider, line));
|
|
191
|
-
} catch (error) {
|
|
192
|
-
throw withJob(error, id);
|
|
193
|
-
}
|
|
190
|
+
return (await readSigned(provider, url, options)).split("\n").filter((line) => line.trim() !== "").map((line) => parseJson(provider, line));
|
|
194
191
|
};
|
|
195
192
|
/** Each page's picture, keyed by page number, from the job's saved screenshots. */
|
|
196
193
|
const pageImageAddresses = (found, id) => {
|
|
@@ -201,44 +198,23 @@ const pageImageAddresses = (found, id) => {
|
|
|
201
198
|
}
|
|
202
199
|
if (addresses.size === 0) throw new FieldworkError("ProviderError", `llamaparse job ${id} has no page pictures; only a parse started with pageImages saves them`, {
|
|
203
200
|
cause: found.original,
|
|
204
|
-
jobId: id,
|
|
205
201
|
provider
|
|
206
202
|
});
|
|
207
203
|
return addresses;
|
|
208
204
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const id = await startParse(raw, document, o, call);
|
|
212
|
-
const blocks = o.blocks === true || o.wordBoxes === true;
|
|
213
|
-
const expand = [
|
|
214
|
-
"markdown",
|
|
215
|
-
"usage",
|
|
216
|
-
...blocks ? ["items"] : [],
|
|
217
|
-
...o.pageImages === true ? ["images_content_metadata"] : []
|
|
218
|
-
].join(",");
|
|
219
|
-
const found = await poll(provider, id, async (request) => finished(z.parse(JobResult, await raw.request("GET", `/api/v2/parse/${segment(id)}`, {
|
|
220
|
-
...request,
|
|
221
|
-
query: { expand }
|
|
222
|
-
})), id), {
|
|
223
|
-
...call,
|
|
224
|
-
interval: o.interval
|
|
225
|
-
});
|
|
205
|
+
/** The finished job as a document, with word boxes and page pictures when they were asked for. */
|
|
206
|
+
const parsedDocument = async (found, id, o, read) => {
|
|
226
207
|
if (found.value.markdown.pages.length === 0) throw new FieldworkError("ProviderError", `llamaparse finished job ${id} without any pages of Markdown`, {
|
|
227
208
|
cause: found.original,
|
|
228
|
-
jobId: id,
|
|
229
209
|
provider
|
|
230
210
|
});
|
|
231
|
-
const grounded = o.wordBoxes === true ? await groundedPages(found,
|
|
232
|
-
fetch: fetchImpl,
|
|
233
|
-
signal: call.signal
|
|
234
|
-
}) : void 0;
|
|
211
|
+
const grounded = o.wordBoxes === true ? await groundedPages(found, read) : void 0;
|
|
235
212
|
const images = o.pageImages === true ? pageImageAddresses(found, id) : void 0;
|
|
236
213
|
const pages = found.value.markdown.pages.flatMap((page) => {
|
|
237
214
|
if (page.page_number === void 0) return [];
|
|
238
215
|
const image = images?.get(page.page_number);
|
|
239
216
|
if (images !== void 0 && image === void 0) throw new FieldworkError("ProviderError", `llamaparse job ${id} has no picture of page ${page.page_number}`, {
|
|
240
217
|
cause: found.original,
|
|
241
|
-
jobId: id,
|
|
242
218
|
provider
|
|
243
219
|
});
|
|
244
220
|
return [compact({
|
|
@@ -249,7 +225,7 @@ const parse = async (raw, document, options, fetchImpl) => {
|
|
|
249
225
|
});
|
|
250
226
|
let laidOut;
|
|
251
227
|
if (grounded !== void 0) laidOut = documentBlocks(grounded.map((row) => z.parse(ItemsPage, row)));
|
|
252
|
-
else if (blocks) laidOut = documentBlocks(found.value.items.pages);
|
|
228
|
+
else if (o.blocks === true) laidOut = documentBlocks(found.value.items.pages);
|
|
253
229
|
return compact({
|
|
254
230
|
blocks: laidOut,
|
|
255
231
|
id,
|
|
@@ -262,6 +238,31 @@ const parse = async (raw, document, options, fetchImpl) => {
|
|
|
262
238
|
}
|
|
263
239
|
});
|
|
264
240
|
};
|
|
241
|
+
/** Runs the job. `expand` names the sections of the result to include; blocks, word boxes and page images each add one. */
|
|
242
|
+
const parse = async (raw, document, options, fetchImpl) => {
|
|
243
|
+
const { call, rest: o } = callSettings(options);
|
|
244
|
+
const expand = [
|
|
245
|
+
"markdown",
|
|
246
|
+
"usage",
|
|
247
|
+
...o.blocks === true || o.wordBoxes === true ? ["items"] : [],
|
|
248
|
+
...o.pageImages === true ? ["images_content_metadata"] : []
|
|
249
|
+
].join(",");
|
|
250
|
+
return await runJob(provider, {
|
|
251
|
+
check: async (id, request) => finished(z.parse(JobResult, await raw.request("GET", `/api/v2/parse/${segment(id)}`, {
|
|
252
|
+
...request,
|
|
253
|
+
query: { expand }
|
|
254
|
+
}))),
|
|
255
|
+
finish: async (found, id) => await parsedDocument(found, id, o, {
|
|
256
|
+
fetch: fetchImpl,
|
|
257
|
+
signal: call.signal
|
|
258
|
+
}),
|
|
259
|
+
start: async () => await startParse(raw, document, o, call)
|
|
260
|
+
}, {
|
|
261
|
+
...call,
|
|
262
|
+
interval: o.interval,
|
|
263
|
+
resume: o.resume
|
|
264
|
+
});
|
|
265
|
+
};
|
|
265
266
|
/**
|
|
266
267
|
* An adapter for LlamaParse: parse. Pass it to `new Fieldwork({ adapter })`.
|
|
267
268
|
*
|
package/dist/parallel.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { E as Extraction, F as MonitorEvents, I as MonitorInfo, L as MonitorSchedule, R as Page, Y as SearchResponse, a as RawClient, b as Decisions, g as Condition, j as ImageSearch, l as Answer, p as CallOptions, q as Research, t as Adapter, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { E as Extraction, F as MonitorEvents, I as MonitorInfo, L as MonitorSchedule, R as Page, Y as SearchResponse, a as RawClient, b as Decisions, g as Condition, j as ImageSearch, l as Answer, p as CallOptions, q as Research, t as Adapter, x as Discovery, y as DecisionQuestion, z as PageBatch } from "./adapter-BhTK51Yj.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CNd51xdD.js";
|
|
3
3
|
import "./util-DhYr1OS3.js";
|
|
4
|
+
/** Settings for `parallel()`. */
|
|
4
5
|
interface ParallelConfig {
|
|
5
6
|
/** Defaults to the PARALLEL_API_KEY environment variable. */
|
|
6
7
|
apiKey?: string;
|
|
8
|
+
/** Defaults to https://api.parallel.ai. */
|
|
7
9
|
baseUrl?: string;
|
|
10
|
+
/** Used in place of the global `fetch`. */
|
|
8
11
|
fetch?: typeof fetch;
|
|
9
12
|
/** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
|
|
10
13
|
retries?: number;
|
|
@@ -22,12 +25,17 @@ interface ParallelSources {
|
|
|
22
25
|
* Parallel ignores `excludeDomains`, so passing both is refused.
|
|
23
26
|
*/
|
|
24
27
|
includeDomains?: string[];
|
|
28
|
+
/** Same forms as `includeDomains`. Not combinable with it. */
|
|
25
29
|
excludeDomains?: string[];
|
|
26
|
-
/** YYYY-MM-DD. */
|
|
30
|
+
/** YYYY-MM-DD. Sent as `after_date`; there is no `publishedBefore`. */
|
|
27
31
|
publishedAfter?: string;
|
|
28
32
|
}
|
|
29
33
|
/** Task metadata: keys up to 16 characters, values up to 512. */
|
|
30
34
|
type ParallelMetadata = Record<string, string | number | boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Options for `search` (`POST /v1/search`). A `maxAge` under 600 is refused. There
|
|
37
|
+
* is no `recency` or `publishedBefore`; use `publishedAfter`.
|
|
38
|
+
*/
|
|
31
39
|
interface ParallelSearchOptions extends CallOptions, ParallelSources {
|
|
32
40
|
/** What the search is for, in plain words. Defaults to the query. */
|
|
33
41
|
objective?: string;
|
|
@@ -38,6 +46,7 @@ interface ParallelSearchOptions extends CallOptions, ParallelSources {
|
|
|
38
46
|
* `basic` or `advanced` (the default, richer retrieval).
|
|
39
47
|
*/
|
|
40
48
|
mode?: "turbo" | "fast" | "basic" | "advanced";
|
|
49
|
+
/** Sent as `max_results`. */
|
|
41
50
|
limit?: number;
|
|
42
51
|
/** ISO 3166-1 alpha-2 code such as "GB", for geo-targeted results. */
|
|
43
52
|
country?: string;
|
|
@@ -50,16 +59,23 @@ interface ParallelSearchOptions extends CallOptions, ParallelSources {
|
|
|
50
59
|
/** Groups calls made for one larger task; Parallel may use it to improve later results. */
|
|
51
60
|
sessionId?: string;
|
|
52
61
|
}
|
|
62
|
+
/** Options for `images` (`POST /v1/images/search`). */
|
|
53
63
|
interface ParallelImagesOptions extends CallOptions {
|
|
54
64
|
/** The images wanted, in plain words, up to 5,000 characters. Defaults to the query. */
|
|
55
65
|
objective?: string;
|
|
56
66
|
/** Up to 5 image queries; defaults to the query alone. */
|
|
57
67
|
queries?: string[];
|
|
58
68
|
mode?: "fast" | "advanced";
|
|
69
|
+
/** Sent as `max_results`. */
|
|
59
70
|
limit?: number;
|
|
71
|
+
/** ISO 3166-1 alpha-2 code such as "GB", for geo-targeted results. */
|
|
60
72
|
country?: string;
|
|
61
73
|
sessionId?: string;
|
|
62
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for `read` (`POST /v1/extract`). The page text comes back as `markdown`;
|
|
77
|
+
* `query` and `queries` add focused `excerpts`. A `maxAge` under 600 is refused.
|
|
78
|
+
*/
|
|
63
79
|
interface ParallelReadOptions extends CallOptions {
|
|
64
80
|
/** Return passages that answer this as `excerpts`. Sent as Parallel's `objective`. */
|
|
65
81
|
query?: string;
|
|
@@ -67,7 +83,10 @@ interface ParallelReadOptions extends CallOptions {
|
|
|
67
83
|
queries?: string[];
|
|
68
84
|
/** Seconds a cached copy may be old. Parallel's minimum is 600; lower values are refused. */
|
|
69
85
|
maxAge?: number;
|
|
70
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Cap on the characters of the page text returned for each URL. Without it,
|
|
88
|
+
* or at 0, the full content is requested with no cap.
|
|
89
|
+
*/
|
|
71
90
|
maxContentChars?: number;
|
|
72
91
|
/** Cap on the characters of excerpts returned for each URL. */
|
|
73
92
|
maxCharsPerResult?: number;
|
|
@@ -75,7 +94,15 @@ interface ParallelReadOptions extends CallOptions {
|
|
|
75
94
|
maxCharsTotal?: number;
|
|
76
95
|
sessionId?: string;
|
|
77
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Options for `readMany`: the same as `read`, applied to every URL. Parallel takes
|
|
99
|
+
* at most 20 URLs in one call.
|
|
100
|
+
*/
|
|
78
101
|
type ParallelReadManyOptions = ParallelReadOptions;
|
|
102
|
+
/**
|
|
103
|
+
* Options for `extract`: a Task run limited to the page's own URL, polled to
|
|
104
|
+
* completion. `resume` waits for an earlier run instead of starting another.
|
|
105
|
+
*/
|
|
79
106
|
interface ParallelExtractOptions<T = unknown> extends CallOptions {
|
|
80
107
|
/**
|
|
81
108
|
* The values to extract. Without one, Parallel picks the fields itself (its
|
|
@@ -84,6 +111,10 @@ interface ParallelExtractOptions<T = unknown> extends CallOptions {
|
|
|
84
111
|
* checks `data`.
|
|
85
112
|
*/
|
|
86
113
|
schema?: OutputSchema<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Instructions for the run. Defaults to one that asks for the values in `schema`
|
|
116
|
+
* from this page only, or for the page's main facts when there is no schema.
|
|
117
|
+
*/
|
|
87
118
|
prompt?: string;
|
|
88
119
|
/** Defaults to "base". */
|
|
89
120
|
processor?: ParallelProcessor;
|
|
@@ -98,6 +129,10 @@ interface ParallelExtractOptions<T = unknown> extends CallOptions {
|
|
|
98
129
|
*/
|
|
99
130
|
resume?: string;
|
|
100
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Options for `answer` (`POST /v1/responses`, synchronous). `includeDomains` and
|
|
134
|
+
* `excludeDomains` are refused together.
|
|
135
|
+
*/
|
|
101
136
|
interface ParallelAnswerOptions<T = unknown> extends CallOptions {
|
|
102
137
|
/** The answer in the shape of this schema, in `output`. */
|
|
103
138
|
schema?: OutputSchema<T>;
|
|
@@ -109,10 +144,15 @@ interface ParallelAnswerOptions<T = unknown> extends CallOptions {
|
|
|
109
144
|
continueFrom?: string;
|
|
110
145
|
/** Only these domains are searched. Parallel allows one of the two lists. */
|
|
111
146
|
includeDomains?: string[];
|
|
147
|
+
/** These domains are not searched. Not combinable with `includeDomains`. */
|
|
112
148
|
excludeDomains?: string[];
|
|
113
149
|
/** Up to 16 keys, keys up to 64 characters, values up to 512. */
|
|
114
150
|
metadata?: Record<string, string>;
|
|
115
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Options for `research`: a Task run polled to completion. `includeDomains` and
|
|
154
|
+
* `excludeDomains` are refused together.
|
|
155
|
+
*/
|
|
116
156
|
interface ParallelResearchOptions<T = unknown> extends CallOptions, ParallelSources {
|
|
117
157
|
/** Structured output in the shape of this schema; without one the output is report text. */
|
|
118
158
|
schema?: OutputSchema<T>;
|
|
@@ -131,6 +171,12 @@ interface ParallelResearchOptions<T = unknown> extends CallOptions, ParallelSour
|
|
|
131
171
|
*/
|
|
132
172
|
resume?: string;
|
|
133
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Options for `discover`: a FindAll run (`/v1beta/findall`) that finds entities
|
|
176
|
+
* matching every condition, polled to completion. A run that stops early with at
|
|
177
|
+
* least one match returns `status: "partial"`; one that ends with no match throws
|
|
178
|
+
* `JobFailed`.
|
|
179
|
+
*/
|
|
134
180
|
interface ParallelDiscoverOptions<T = unknown> extends CallOptions {
|
|
135
181
|
/** What kind of entity to find, such as "companies" or "people". */
|
|
136
182
|
entityType: string;
|
|
@@ -162,13 +208,25 @@ interface ParallelDiscoverOptions<T = unknown> extends CallOptions {
|
|
|
162
208
|
*/
|
|
163
209
|
resume?: string;
|
|
164
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Options for `decide` (`POST /v1/decisions`, synchronous). Parallel takes 1 to 100
|
|
213
|
+
* questions named with letters, numbers, underscores and hyphens. A choice
|
|
214
|
+
* question needs 2 to 255 distinct choices and a score scale 2 to 10 levels. All
|
|
215
|
+
* three are refused before sending.
|
|
216
|
+
*/
|
|
165
217
|
interface ParallelDecideOptions extends CallOptions {
|
|
166
218
|
/** ISO 3166-1 alpha-2 code for geo-targeted search. */
|
|
167
219
|
country?: string;
|
|
168
220
|
/** Keep the passages each citation was taken from. Parallel defaults to true. */
|
|
169
221
|
includeExcerpts?: boolean;
|
|
170
222
|
}
|
|
223
|
+
/** The event types a monitor webhook can subscribe to. */
|
|
171
224
|
type ParallelWebhookEvent = "monitor.event.detected" | "monitor.execution.completed" | "monitor.execution.failed";
|
|
225
|
+
/**
|
|
226
|
+
* Options for `monitor.create`. A `query` makes an event-stream monitor that
|
|
227
|
+
* searches the web on each run; a `taskRunId` makes a snapshot monitor of that
|
|
228
|
+
* Task run's output. Pass one of the two. `webhookEvents` needs a `webhookUrl`.
|
|
229
|
+
*/
|
|
172
230
|
interface ParallelMonitorCreateOptions extends CallOptions, ParallelSources {
|
|
173
231
|
/**
|
|
174
232
|
* What to watch for, in plain words. Parallel searches the web for it on
|
|
@@ -177,17 +235,22 @@ interface ParallelMonitorCreateOptions extends CallOptions, ParallelSources {
|
|
|
177
235
|
query?: string;
|
|
178
236
|
/**
|
|
179
237
|
* Watch the output of an earlier Task run for changes instead of a query.
|
|
180
|
-
* Cannot be combined with `query`, `schema`, `includeBackfill`, `country
|
|
181
|
-
*
|
|
238
|
+
* Cannot be combined with `query`, `schema`, `includeBackfill`, `country`,
|
|
239
|
+
* `includeDomains`, `excludeDomains` or `publishedAfter`.
|
|
182
240
|
*/
|
|
183
241
|
taskRunId?: string;
|
|
184
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Parallel runs at a fixed interval from 1 hour to 30 days; cron is refused.
|
|
244
|
+
* `every` is "hour", "day", "week", or a count such as "6h" (up to 720h) or
|
|
245
|
+
* "3d" (up to 30d).
|
|
246
|
+
*/
|
|
185
247
|
schedule: MonitorSchedule;
|
|
186
248
|
/** Events come back in the shape of this schema. Events are not checked against a Standard Schema. */
|
|
187
249
|
schema?: OutputSchema<unknown>;
|
|
188
250
|
/** The first run returns a sample of recent events (a preview, not exhaustive). */
|
|
189
251
|
includeBackfill?: boolean;
|
|
190
252
|
country?: string;
|
|
253
|
+
/** Where Parallel sends webhook events. */
|
|
191
254
|
webhookUrl?: string;
|
|
192
255
|
/** Needs `webhookUrl`. Parallel sends every event type when omitted. */
|
|
193
256
|
webhookEvents?: ParallelWebhookEvent[];
|
|
@@ -196,6 +259,10 @@ interface ParallelMonitorCreateOptions extends CallOptions, ParallelSources {
|
|
|
196
259
|
/** Keys up to 16 characters, values up to 512. */
|
|
197
260
|
metadata?: Record<string, string>;
|
|
198
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Options for `monitor.events`: one page of a monitor's events. Pass the result's
|
|
264
|
+
* `next` as `cursor` for the following page.
|
|
265
|
+
*/
|
|
199
266
|
interface ParallelMonitorEventsOptions extends CallOptions {
|
|
200
267
|
cursor?: string;
|
|
201
268
|
/** 1 to 100. Parallel defaults to 20. */
|
|
@@ -212,6 +279,11 @@ interface ParallelMonitorEventsOptions extends CallOptions {
|
|
|
212
279
|
type ParallelDiscovery<T> = Discovery<T> & {
|
|
213
280
|
stopReason?: string;
|
|
214
281
|
};
|
|
282
|
+
/**
|
|
283
|
+
* What Parallel offers: search, images, read, readMany, extract, answer, research,
|
|
284
|
+
* discover, decide and monitor. `extract`, `research` and `discover` run as jobs
|
|
285
|
+
* and accept `resume`.
|
|
286
|
+
*/
|
|
215
287
|
interface ParallelOperations {
|
|
216
288
|
search: (query: string, options?: ParallelSearchOptions) => Promise<SearchResponse>;
|
|
217
289
|
images: (query: string, options?: ParallelImagesOptions) => Promise<ImageSearch>;
|