@howells/fieldwork-sdk 0.3.0 → 0.3.1
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 +1 -1
- package/dist/brave.js +1 -1
- package/dist/browserbase.js +3 -3
- package/dist/exa.js +1 -1
- package/dist/firecrawl.js +9 -4
- package/dist/parallel.js +1 -1
- package/dist/perplexity.js +1 -1
- package/dist/serpapi.js +1 -1
- package/dist/tavily.js +1 -1
- package/dist/{util-CYenIQQT.js → util-YaZYZDSk.js} +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ Options only one provider has keep that provider's meaning and values, such as T
|
|
|
78
78
|
Every result is normalized and keeps the provider's response in `raw`. Most also carry `meta`: the provider's `requestId`, `usage` (credits, US dollars, or counted units such as tokens) and `warnings`, when the provider returns them.
|
|
79
79
|
|
|
80
80
|
- `search` returns `{ results, answer, images, meta, raw }`. Each result has `url`, `title`, `snippet` and, when the provider has them, `content`, `publishedAt`, `author`, `image`, `favicon` and `score`. Shopping, place, news, scholar and patent results set `kind` and carry `price`, `rating`, `reviewCount` and `place`.
|
|
81
|
-
- `read` returns a `Page`: `url`, `title`, `description`, `markdown`, `html`, `links`, `images`, `image` (the page's main image), `excerpts`, `summary`, `publishedAt`, `author`, `language`, `statusCode` and `screenshot`, as the provider has them.
|
|
81
|
+
- `read` returns a `Page`: `url`, `title`, `description`, `markdown`, `html`, `links`, `images`, `image` (the page's main image), `excerpts`, `summary`, `publishedAt`, `author`, `language`, `statusCode` and `screenshot`, as the provider has them. A page that answered 404 or 410 is not returned: `read` throws `NotFound` on every provider, and `readMany` lists the URL in `failed`.
|
|
82
82
|
- `readMany` returns `{ pages, failed }`. A URL that could not be read is listed in `failed` with the reason; it does not throw.
|
|
83
83
|
- `extract` returns `{ data, fields }`. `data` follows your schema; `fields` lists each field's citations when the provider returns them.
|
|
84
84
|
- `product` returns the product and its `variants`, each with `sku`, option `values`, `price` (`amount`, `currency`, `formatted`), `originalPrice`, `availability`, `gtin` and `images` (`{ url, alt }`).
|
package/dist/brave.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, b as createRawClient, c as num, i as compact, m as refuseTogether, o as list, p as record, s as meta, t as callSettings, v as text } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/brave/parse.ts
|
|
5
5
|
const provider = "brave";
|
|
6
6
|
const FRESHNESS = {
|
package/dist/browserbase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, b as createRawClient, c as num, h as requireId, i as compact, m as refuseTogether, o as list, p as record, s as meta, t as callSettings, u as presentPage, v as text } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/browserbase.ts
|
|
5
5
|
const SEARCH_MODES = {
|
|
6
6
|
exa: [
|
|
@@ -109,7 +109,7 @@ const browserbase = (config = {}) => {
|
|
|
109
109
|
const content = typeof response.content === "string" ? response.content : void 0;
|
|
110
110
|
const binary = response.encoding === "base64";
|
|
111
111
|
const contentType = text(response.contentType) ?? "";
|
|
112
|
-
return compact({
|
|
112
|
+
return presentPage(provider, compact({
|
|
113
113
|
markdown: format === "markdown" && !binary ? content : void 0,
|
|
114
114
|
meta: meta({
|
|
115
115
|
requestId: response.id,
|
|
@@ -119,7 +119,7 @@ const browserbase = (config = {}) => {
|
|
|
119
119
|
rawHtml: format === "raw" && !binary && contentType.includes("html") ? content : void 0,
|
|
120
120
|
statusCode: num(response.statusCode),
|
|
121
121
|
url
|
|
122
|
-
});
|
|
122
|
+
}));
|
|
123
123
|
},
|
|
124
124
|
async search(query, options) {
|
|
125
125
|
const { call, rest: o } = callSettings(options);
|
package/dist/exa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import { _ as
|
|
3
|
+
import { S as requireKey, _ as strings, a as hours, b as createRawClient, c as num, h as requireId, i as compact, l as parseJson, o as list, p as record, r as citations, s as meta, t as callSettings, v as text, x as poll, y as uniqueCitations } from "./util-YaZYZDSk.js";
|
|
4
4
|
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/u;
|
|
5
5
|
const DEEP_TYPES = /* @__PURE__ */ new Set([
|
|
6
6
|
"deep-lite",
|
package/dist/firecrawl.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { r as withJob, t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, _ as strings, b as createRawClient, c as num, d as presentPages, f as productImages, g as scalar, h as requireId, i as compact, m as refuseTogether, o as list, p as record, s as meta, t as callSettings, u as presentPage, v as text, x as poll } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/firecrawl/shared.ts
|
|
5
5
|
const provider = "firecrawl";
|
|
6
6
|
const invalid = (message) => new FieldworkError("InvalidRequest", message, { provider });
|
|
@@ -865,7 +865,7 @@ const firecrawl = (config = {}) => {
|
|
|
865
865
|
async read(url, options) {
|
|
866
866
|
const { call, rest: o } = callSettings(options);
|
|
867
867
|
const { response, data } = await scrape(url, readFormats(o), o, call);
|
|
868
|
-
return toPage(data, url, response, response);
|
|
868
|
+
return presentPage(provider, toPage(data, url, response, response));
|
|
869
869
|
},
|
|
870
870
|
async readMany(urls, options) {
|
|
871
871
|
const { call, rest: o } = callSettings(options);
|
|
@@ -885,14 +885,19 @@ const firecrawl = (config = {}) => {
|
|
|
885
885
|
error: "invalid URL",
|
|
886
886
|
url
|
|
887
887
|
}));
|
|
888
|
+
const { pages, gone } = presentPages(job.batches.flatMap((batch) => list(batch.data).map((item) => toPage(record(item), "", item))));
|
|
888
889
|
return compact({
|
|
889
|
-
failed: [
|
|
890
|
+
failed: [
|
|
891
|
+
...job.failed,
|
|
892
|
+
...rejected,
|
|
893
|
+
...gone
|
|
894
|
+
],
|
|
890
895
|
id,
|
|
891
896
|
meta: meta({
|
|
892
897
|
credits: job.first.creditsUsed,
|
|
893
898
|
requestId: id
|
|
894
899
|
}),
|
|
895
|
-
pages
|
|
900
|
+
pages,
|
|
896
901
|
raw: {
|
|
897
902
|
batches: job.batches,
|
|
898
903
|
errors: job.errors,
|
package/dist/parallel.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { r as withJob, t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, _ as strings, b as createRawClient, c as num, h as requireId, i as compact, l as parseJson, m as refuseTogether, o as list, p as record, r as citations, s as meta, t as callSettings, v as text, x as poll, y as uniqueCitations } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/parallel/parse.ts
|
|
5
5
|
const provider = "parallel";
|
|
6
6
|
const invalid = (message) => new FieldworkError("InvalidRequest", message, { provider });
|
package/dist/perplexity.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, b as createRawClient, c as num, h as requireId, i as compact, l as parseJson, m as refuseTogether, n as citation, o as list, p as record, s as meta, t as callSettings, v as text, x as poll, y as uniqueCitations } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/perplexity.ts
|
|
5
5
|
const provider = "perplexity";
|
|
6
6
|
const MAX_QUERIES = 5;
|
package/dist/serpapi.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
|
-
import {
|
|
2
|
+
import { S as requireKey, _ as strings, b as createRawClient, c as num, g as scalar, i as compact, m as refuseTogether, o as list, p as record, s as meta, t as callSettings, v as text } from "./util-YaZYZDSk.js";
|
|
3
3
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
4
4
|
// src/adapters/serpapi/parse.ts
|
|
5
5
|
const provider = "serpapi";
|
package/dist/tavily.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
|
|
2
2
|
import { t as FieldworkError } from "./errors-BiIBG9zN.js";
|
|
3
|
-
import {
|
|
3
|
+
import { S as requireKey, _ as strings, a as hours, b as createRawClient, c as num, h as requireId, i as compact, o as list, p as record, s as meta, t as callSettings, v as text, x as poll } from "./util-YaZYZDSk.js";
|
|
4
4
|
// src/adapters/tavily/countries.ts
|
|
5
5
|
/** Tavily's country names, by ISO 3166-1 alpha-2 code. */
|
|
6
6
|
const COUNTRIES = new Map(`
|
|
@@ -262,4 +262,26 @@ const refuseTogether = (provider, options, ...names) => {
|
|
|
262
262
|
if (set.length > 1) throw new FieldworkError("InvalidRequest", `${provider} does not accept ${set.join(" and ")} together; pass one`, { provider });
|
|
263
263
|
};
|
|
264
264
|
const hours = (seconds) => seconds === void 0 ? void 0 : seconds < 0 ? -1 : Math.ceil(seconds / 3600);
|
|
265
|
-
|
|
265
|
+
/** Statuses that mean the page is not there, so a read of it has no page to return. */
|
|
266
|
+
const GONE = /* @__PURE__ */ new Set([404, 410]);
|
|
267
|
+
/**
|
|
268
|
+
* A read whose page answered 404 or 410 fails as NotFound, as it does on
|
|
269
|
+
* providers that return no page at all, instead of returning the error page
|
|
270
|
+
* as if it were the content.
|
|
271
|
+
*/
|
|
272
|
+
const presentPage = (provider, page) => {
|
|
273
|
+
if (page.statusCode !== void 0 && GONE.has(page.statusCode)) throw new FieldworkError("NotFound", `${provider} could not read ${page.url}: the page returned ${page.statusCode}`, {
|
|
274
|
+
provider,
|
|
275
|
+
status: page.statusCode
|
|
276
|
+
});
|
|
277
|
+
return page;
|
|
278
|
+
};
|
|
279
|
+
/** Splits a batch's pages into those present and those that answered 404 or 410. */
|
|
280
|
+
const presentPages = (pages) => ({
|
|
281
|
+
gone: pages.filter((page) => page.statusCode !== void 0 && GONE.has(page.statusCode)).map((page) => ({
|
|
282
|
+
error: `the page returned ${page.statusCode}`,
|
|
283
|
+
url: page.url
|
|
284
|
+
})),
|
|
285
|
+
pages: pages.filter((page) => page.statusCode === void 0 || !GONE.has(page.statusCode))
|
|
286
|
+
});
|
|
287
|
+
export { requireKey as S, strings as _, hours as a, createRawClient as b, num as c, presentPages as d, productImages as f, scalar as g, requireId as h, compact as i, parseJson as l, refuseTogether as m, citation as n, list as o, record as p, citations as r, meta as s, callSettings as t, presentPage as u, text as v, poll as x, uniqueCitations as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/fieldwork-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
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 and Browserbase.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|