@howells/fieldwork-sdk 0.10.1 → 0.11.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 +36 -4
- package/dist/{adapter-DQrBP1tj.d.ts → adapter-B8kAAAgF.d.ts} +25 -2
- package/dist/brave.d.ts +1 -1
- package/dist/brave.js +3 -3
- package/dist/browserbase.d.ts +1 -1
- package/dist/browserbase.js +4 -4
- package/dist/{document-DOzhDFFt.js → document-DMIUCoDA.js} +2 -2
- package/dist/{download-gyAym9vL.js → download-CP8noBdX.js} +18 -8
- package/dist/{errors-DROZyb9T.js → errors-DkFJysIM.js} +9 -0
- package/dist/exa.d.ts +2 -2
- package/dist/exa.js +5 -5
- package/dist/{fieldwork-DNwEf0Mo.d.ts → fieldwork-BrfoehvG.d.ts} +10 -1
- package/dist/firecrawl.d.ts +2 -2
- package/dist/firecrawl.js +10 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -2
- package/dist/{job-DBhGs7Ha.js → job-DnavRq_s.js} +3 -3
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +29 -13
- package/dist/llamaparse.d.ts +1 -1
- package/dist/llamaparse.js +5 -5
- package/dist/parallel.d.ts +3 -3
- package/dist/parallel.js +5 -5
- package/dist/{parse-lMLcxUsG.js → parse-Q7H4mrnO.js} +2 -2
- package/dist/perplexity.d.ts +2 -2
- package/dist/perplexity.js +5 -5
- package/dist/reducto.d.ts +1 -1
- package/dist/reducto.js +5 -5
- package/dist/{schema-COAaWnZB.js → schema--iU4AXSM.js} +1 -1
- package/dist/{schema-BFjS6CSz.d.ts → schema-CAPSX7yQ.d.ts} +1 -1
- package/dist/serpapi.d.ts +62 -4
- package/dist/serpapi.js +230 -5
- package/dist/tavily.d.ts +2 -2
- package/dist/tavily.js +5 -5
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +173 -123
- package/dist/{types-rc8bl8Em.js → types-mq6d6YOK.js} +1 -0
- package/dist/{util-BqeRYF2b.js → util-DFUXQX6v.js} +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as codeForStatus, t as FieldworkError } from "./errors-
|
|
2
|
-
import { d as record, n as checkCallSettings } from "./util-
|
|
1
|
+
import { n as codeForStatus, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
2
|
+
import { d as record, n as checkCallSettings } from "./util-DFUXQX6v.js";
|
|
3
3
|
import * as z from "zod/mini";
|
|
4
4
|
/**
|
|
5
5
|
* Waits `ms`. When `signal` aborts it resolves early rather than rejecting, so
|
package/dist/perplexity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, Q as Recency, a as RawClient, b as Decisions, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter, y as DecisionQuestion } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
|
|
3
3
|
/** Settings for `perplexity()`. */
|
|
4
4
|
interface PerplexityConfig {
|
|
5
5
|
/** Defaults to the PERPLEXITY_API_KEY environment variable. */
|
package/dist/perplexity.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, t as Source, v as recordOf, y as sourceShape } from "./parse-
|
|
4
|
-
import { i as startJob, r as runJob, t as jobState } from "./job-
|
|
5
|
-
import { n as jsonSchemaOf, t as checkOutput } from "./schema
|
|
6
|
-
import { a as compact, c as parseJson, f as refuseTogether, m as uniqueCitations, r as citationOf, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, t as Source, v as recordOf, y as sourceShape } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
5
|
+
import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
|
|
6
|
+
import { a as compact, c as parseJson, f as refuseTogether, m as uniqueCitations, r as citationOf, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
// src/adapters/perplexity/parse.ts
|
|
9
9
|
/** The name this adapter reports in errors and results. */
|
package/dist/reducto.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as DocumentInput,
|
|
1
|
+
import { C as DocumentInput, K as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
/** Settings for `reducto()`. */
|
|
3
3
|
export interface ReductoConfig {
|
|
4
4
|
/** Defaults to the REDUCTO_API_KEY environment variable. */
|
package/dist/reducto.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { n as documentPart, o as refuseLarger, r as documentUrl } from "./document-
|
|
3
|
-
import { t as FieldworkError } from "./errors-
|
|
4
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-
|
|
5
|
-
import { i as startJob, r as runJob, t as jobState } from "./job-
|
|
6
|
-
import { a as compact, c as parseJson, p as requireJobId, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { n as documentPart, o as refuseLarger, r as documentUrl } from "./document-DMIUCoDA.js";
|
|
3
|
+
import { t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
4
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-Q7H4mrnO.js";
|
|
5
|
+
import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
6
|
+
import { a as compact, c as parseJson, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
// src/adapters/reducto/response.ts
|
|
9
9
|
/** A box in fractions of the page, from its top-left corner. `page` counts the pages parsed; `original_page` the file's. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
1
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
2
2
|
import { o as isText, r as isJsonObject, t as joinPath } from "./path-DL5P8XH2.js";
|
|
3
3
|
// src/schema-subset.ts
|
|
4
4
|
const MAPS = /* @__PURE__ */ new Set([
|
package/dist/serpapi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as ImageSearch, Q as Recency, R as MatchKind, a as RawClient, et as ReverseImageSearch, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
2
|
import "./util-DhYr1OS3.js";
|
|
3
3
|
/** Settings for `serpapi()`. */
|
|
4
4
|
interface SerpApiConfig {
|
|
@@ -185,16 +185,74 @@ interface SerpApiImagesOptions extends SerpApiBaseOptions {
|
|
|
185
185
|
/** Sent as `licenses`: f, fc, fm, fmc, cl or ol. */
|
|
186
186
|
license?: "f" | "fc" | "fm" | "fmc" | "cl" | "ol";
|
|
187
187
|
}
|
|
188
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* Google Lens: `engine=google_lens`, the default for `reverseImage`. It has no
|
|
190
|
+
* result count, so `limit` is refused.
|
|
191
|
+
*/
|
|
192
|
+
interface SerpApiLensOptions extends SerpApiBaseOptions {
|
|
193
|
+
engine?: "google_lens";
|
|
194
|
+
/** ISO 3166-1 alpha-2 code such as "GB"; sent lower-case as `country`. */
|
|
195
|
+
country?: string;
|
|
196
|
+
/** Sent as `hl`: a language code such as "en", or "en-gb". */
|
|
197
|
+
language?: string;
|
|
198
|
+
/** Text to refine the search with; sent as `q`. Not allowed with `match: "exact"`. */
|
|
199
|
+
query?: string;
|
|
200
|
+
/**
|
|
201
|
+
* Sent as `type`: "exact" is `exact_matches` and "visual" is `visual_matches`.
|
|
202
|
+
* Left out, Lens answers its default `type=all`, which lists visual matches
|
|
203
|
+
* only; ask for "exact" to get exact matches.
|
|
204
|
+
*/
|
|
205
|
+
match?: MatchKind;
|
|
206
|
+
}
|
|
207
|
+
/** Google reverse image: `engine=google_reverse_image`. No `limit` or `match`. */
|
|
208
|
+
interface SerpApiGoogleReverseImageOptions extends SerpApiBaseOptions {
|
|
209
|
+
engine: "google_reverse_image";
|
|
210
|
+
/** ISO 3166-1 alpha-2 code such as "GB"; sent as `gl` ("uk" for GB). */
|
|
211
|
+
country?: string;
|
|
212
|
+
/** Sent as `hl`. */
|
|
213
|
+
language?: string;
|
|
214
|
+
/** Text to refine the search with; sent as `q`. */
|
|
215
|
+
query?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Bing reverse image: `engine=bing_reverse_image`. Its results are the pages with
|
|
219
|
+
* the image, all of kind "exact", so `match` is refused. It has `market` where
|
|
220
|
+
* the other engines have `country` and `language`.
|
|
221
|
+
*/
|
|
222
|
+
interface SerpApiBingReverseImageOptions extends SerpApiBaseOptions {
|
|
223
|
+
engine: "bing_reverse_image";
|
|
224
|
+
/** Results per page, 1 to 150; sent as `count`, which Bing takes as a suggestion. */
|
|
225
|
+
limit?: number;
|
|
226
|
+
/** Bing market code such as "en-US"; sent as `mkt`. */
|
|
227
|
+
market?: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Yandex: `engine=yandex_images`, the "About the image" tab. It takes no options
|
|
231
|
+
* beyond `noCache`. The "Similar images" tab names no source page, so it is not
|
|
232
|
+
* offered.
|
|
233
|
+
*/
|
|
234
|
+
interface SerpApiYandexReverseImageOptions extends SerpApiBaseOptions {
|
|
235
|
+
engine: "yandex_images";
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The options of `reverseImage`, chosen by `engine` (Google Lens when it is left
|
|
239
|
+
* out). Each engine takes only the options it documents; any other set option is
|
|
240
|
+
* refused before sending. The per-engine mapping is in `REVERSE_ENGINES`.
|
|
241
|
+
*/
|
|
242
|
+
type SerpApiReverseImageOptions = SerpApiLensOptions | SerpApiGoogleReverseImageOptions | SerpApiBingReverseImageOptions | SerpApiYandexReverseImageOptions;
|
|
243
|
+
/** The engine names `reverseImage` accepts. */
|
|
244
|
+
type SerpApiReverseImageEngine = NonNullable<SerpApiReverseImageOptions["engine"]>;
|
|
245
|
+
/** What SerpApi offers: search, images, reverse image and usage. */
|
|
189
246
|
interface SerpApiOperations {
|
|
190
247
|
search: (query: string, options?: SerpApiSearchOptions) => Promise<SearchResponse>;
|
|
191
248
|
images: (query: string, options?: SerpApiImagesOptions) => Promise<ImageSearch>;
|
|
249
|
+
reverseImage: (imageUrl: string, options?: SerpApiReverseImageOptions) => Promise<ReverseImageSearch>;
|
|
192
250
|
usage: (options?: CallOptions) => Promise<AccountUsage>;
|
|
193
251
|
}
|
|
194
252
|
/**
|
|
195
|
-
* An adapter for SerpApi: search, images and usage. Pass it to `new Fieldwork({ adapter })`.
|
|
253
|
+
* An adapter for SerpApi: search, images, reverse image and usage. Pass it to `new Fieldwork({ adapter })`.
|
|
196
254
|
*
|
|
197
255
|
* Throws `Unauthorized` when neither `apiKey` nor `SERPAPI_API_KEY` is set.
|
|
198
256
|
*/
|
|
199
257
|
export declare const serpapi: (config?: SerpApiConfig) => Adapter<"serpapi", SerpApiOperations, RawClient>;
|
|
200
|
-
export type { SerpApiBingOptions, SerpApiConfig, SerpApiDuckDuckGoOptions, SerpApiEngine, SerpApiGoogleOptions, SerpApiImagesOptions, SerpApiMapsOptions, SerpApiNewsOptions, SerpApiOperations, SerpApiPatentsOptions, SerpApiScholarOptions, SerpApiSearchOptions, SerpApiShoppingOptions };
|
|
258
|
+
export type { SerpApiBingOptions, SerpApiBingReverseImageOptions, SerpApiConfig, SerpApiDuckDuckGoOptions, SerpApiEngine, SerpApiGoogleOptions, SerpApiGoogleReverseImageOptions, SerpApiImagesOptions, SerpApiLensOptions, SerpApiMapsOptions, SerpApiNewsOptions, SerpApiOperations, SerpApiPatentsOptions, SerpApiReverseImageEngine, SerpApiReverseImageOptions, SerpApiScholarOptions, SerpApiSearchOptions, SerpApiShoppingOptions, SerpApiYandexReverseImageOptions };
|
package/dist/serpapi.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, m as optionalScalar, o as nonEmptyString, r as arrayOf, x as warnings } from "./parse-
|
|
4
|
-
import { a as compact, f as refuseTogether, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, m as optionalScalar, o as nonEmptyString, r as arrayOf, x as warnings } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { a as compact, f as refuseTogether, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
5
5
|
import * as z from "zod/mini";
|
|
6
6
|
// src/adapters/serpapi/parse.ts
|
|
7
7
|
/** The name this adapter reports in errors and results. */
|
|
@@ -164,6 +164,92 @@ const searchMeta = (body) => meta({
|
|
|
164
164
|
});
|
|
165
165
|
/** The reason a search failed, or undefined when it did not. */
|
|
166
166
|
const searchFailure = (body) => body.search_metadata.status === "Error" ? `serpapi search failed: ${body.error.message ?? "no reason given"}` : void 0;
|
|
167
|
+
/** Lens-shaped `visual_matches`, kind "visual": `link` is the page, `image` the matched image. */
|
|
168
|
+
const visualMatches = (body) => body.visual_matches.flatMap((item) => item.link === void 0 ? [] : [compact({
|
|
169
|
+
height: item.image_height,
|
|
170
|
+
kind: "visual",
|
|
171
|
+
siteName: item.source,
|
|
172
|
+
sourceUrl: item.link,
|
|
173
|
+
thumbnailUrl: item.thumbnail,
|
|
174
|
+
title: item.title,
|
|
175
|
+
url: item.image,
|
|
176
|
+
width: item.image_width
|
|
177
|
+
})]);
|
|
178
|
+
/**
|
|
179
|
+
* Google Lens: `exact_matches` (kind "exact"; the response names only the page and
|
|
180
|
+
* a thumbnail) then `visual_matches` (kind "visual", with the matched image).
|
|
181
|
+
* Whichever list the request's `type` did not ask for is empty. The `exact_matches`
|
|
182
|
+
* flag inside a visual match says exact matches of it exist; it does not make the
|
|
183
|
+
* match exact. A match with no `link` is left out.
|
|
184
|
+
*/
|
|
185
|
+
const lensMatches = (body) => [...body.exact_matches.flatMap((item) => item.link === void 0 ? [] : [compact({
|
|
186
|
+
height: item.actual_image_height,
|
|
187
|
+
kind: "exact",
|
|
188
|
+
publishedAt: item.date,
|
|
189
|
+
siteName: item.source,
|
|
190
|
+
sourceUrl: item.link,
|
|
191
|
+
thumbnailUrl: item.thumbnail,
|
|
192
|
+
title: item.title,
|
|
193
|
+
width: item.actual_image_width
|
|
194
|
+
})]), ...visualMatches(body)];
|
|
195
|
+
/**
|
|
196
|
+
* Google reverse image: `image_results`, the pages that show the image (the
|
|
197
|
+
* response does not say how closely, so no kind), then `visual_matches`.
|
|
198
|
+
*/
|
|
199
|
+
const googleReverseMatches = (body) => [...body.image_results.flatMap((item) => item.link === void 0 ? [] : [compact({
|
|
200
|
+
description: item.snippet,
|
|
201
|
+
siteName: item.source,
|
|
202
|
+
sourceUrl: item.link,
|
|
203
|
+
thumbnailUrl: item.thumbnail.link,
|
|
204
|
+
title: item.title
|
|
205
|
+
})]), ...visualMatches(body)];
|
|
206
|
+
/**
|
|
207
|
+
* Bing: `pages_with_this_image`, kind "exact". `source` is the page (the item's
|
|
208
|
+
* `link` is a Bing page) and `original` the image. `related_content`, similar
|
|
209
|
+
* images, is left in `raw`.
|
|
210
|
+
*/
|
|
211
|
+
const bingMatches = (body) => body.pages_with_this_image.flatMap((item) => item.source === void 0 ? [] : [compact({
|
|
212
|
+
height: item.height,
|
|
213
|
+
kind: "exact",
|
|
214
|
+
sourceUrl: item.source,
|
|
215
|
+
thumbnailUrl: item.thumbnail,
|
|
216
|
+
title: item.title,
|
|
217
|
+
url: item.original,
|
|
218
|
+
width: item.width
|
|
219
|
+
})]);
|
|
220
|
+
/** Yandex's "about the image" tab: `link` is the page, `original_image` the image. */
|
|
221
|
+
const yandexMatches = (body) => body.image_results.flatMap((item) => item.link === void 0 ? [] : [compact({
|
|
222
|
+
description: item.snippet,
|
|
223
|
+
height: item.original_image.height,
|
|
224
|
+
siteName: item.source,
|
|
225
|
+
sourceUrl: item.link,
|
|
226
|
+
thumbnailUrl: item.thumbnail.link,
|
|
227
|
+
title: item.title,
|
|
228
|
+
url: item.original_image.link,
|
|
229
|
+
width: item.original_image.width
|
|
230
|
+
})]);
|
|
231
|
+
/**
|
|
232
|
+
* Whether a match's page is a Google redirect instead of the page itself: `/url`,
|
|
233
|
+
* or the opaque `/goto?url=…` links Lens returns for most exact matches. A GET on
|
|
234
|
+
* either answers with a redirect to the page.
|
|
235
|
+
*/
|
|
236
|
+
const isGoogleRedirect = (url) => {
|
|
237
|
+
if (!URL.canParse(url)) return false;
|
|
238
|
+
const { hostname, pathname } = new URL(url);
|
|
239
|
+
return (hostname === "google.com" || hostname.endsWith(".google.com")) && (pathname === "/url" || pathname === "/goto");
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* `searchMeta`, plus a warning when some `sourceUrl` is a Google redirect link,
|
|
243
|
+
* which Lens returns for most exact matches, `noCache` or not. The link is kept
|
|
244
|
+
* as received.
|
|
245
|
+
*/
|
|
246
|
+
const reverseImageMeta = (body, results) => {
|
|
247
|
+
const redirects = results.filter((match) => isGoogleRedirect(match.sourceUrl)).length;
|
|
248
|
+
return meta({
|
|
249
|
+
requestId: body.search_metadata.id,
|
|
250
|
+
warnings: [...body.error.warnings, ...redirects === 0 ? [] : [`${redirects} sourceUrl ${redirects === 1 ? "is a Google redirect link" : "values are Google redirect links"}, not the page itself; a GET on the link redirects to the page`]]
|
|
251
|
+
});
|
|
252
|
+
};
|
|
167
253
|
// src/adapters/serpapi/options.ts
|
|
168
254
|
/**
|
|
169
255
|
* SerpApi's single-letter codes for the recency windows, as Google's `qdr` and
|
|
@@ -465,6 +551,73 @@ const ENGINES = {
|
|
|
465
551
|
results: shoppingResults
|
|
466
552
|
}
|
|
467
553
|
};
|
|
554
|
+
/**
|
|
555
|
+
* Lens's `type` for `match`, or undefined when it is left out. Refuses a value
|
|
556
|
+
* other than "exact" or "visual", and `query` with "exact", which Lens ignores:
|
|
557
|
+
* `q` applies only to `all` and `visual_matches`.
|
|
558
|
+
*/
|
|
559
|
+
const lensType = (o) => {
|
|
560
|
+
if (o.match === void 0) return;
|
|
561
|
+
if (o.match === "visual") return "visual_matches";
|
|
562
|
+
if (o.match !== "exact") throw invalidRequest(provider, "match must be \"exact\" or \"visual\"");
|
|
563
|
+
if (o.query !== void 0) throw invalidRequest(provider, "google_lens does not accept query with match \"exact\"; Lens applies q only to all and visual matches");
|
|
564
|
+
return "exact_matches";
|
|
565
|
+
};
|
|
566
|
+
/** One spec per `SerpApiReverseImageEngine`. None has a result count except Bing's `count`. */
|
|
567
|
+
const REVERSE_ENGINES = {
|
|
568
|
+
/** `limit` is `count`, 0 to 150 as SerpApi documents it, and is only a suggestion. */
|
|
569
|
+
bing_reverse_image: {
|
|
570
|
+
allowed: [
|
|
571
|
+
"limit",
|
|
572
|
+
"market",
|
|
573
|
+
"noCache"
|
|
574
|
+
],
|
|
575
|
+
imageParam: "image_url",
|
|
576
|
+
params: (o) => ({
|
|
577
|
+
count: bounded("bing_reverse_image", o.limit, 1, 150),
|
|
578
|
+
mkt: str(o.market)
|
|
579
|
+
}),
|
|
580
|
+
results: bingMatches
|
|
581
|
+
},
|
|
582
|
+
google_lens: {
|
|
583
|
+
allowed: [
|
|
584
|
+
"country",
|
|
585
|
+
"language",
|
|
586
|
+
"query",
|
|
587
|
+
"match",
|
|
588
|
+
"noCache"
|
|
589
|
+
],
|
|
590
|
+
imageParam: "url",
|
|
591
|
+
params: (o) => ({
|
|
592
|
+
country: str(o.country)?.toLowerCase(),
|
|
593
|
+
hl: str(o.language),
|
|
594
|
+
q: str(o.query),
|
|
595
|
+
type: lensType(o)
|
|
596
|
+
}),
|
|
597
|
+
results: lensMatches
|
|
598
|
+
},
|
|
599
|
+
google_reverse_image: {
|
|
600
|
+
allowed: [
|
|
601
|
+
"country",
|
|
602
|
+
"language",
|
|
603
|
+
"query",
|
|
604
|
+
"noCache"
|
|
605
|
+
],
|
|
606
|
+
imageParam: "image_url",
|
|
607
|
+
params: (o) => ({
|
|
608
|
+
gl: googleCountry(o.country),
|
|
609
|
+
hl: str(o.language),
|
|
610
|
+
q: str(o.query)
|
|
611
|
+
}),
|
|
612
|
+
results: googleReverseMatches
|
|
613
|
+
},
|
|
614
|
+
yandex_images: {
|
|
615
|
+
allowed: ["noCache"],
|
|
616
|
+
imageParam: "url",
|
|
617
|
+
params: () => ({}),
|
|
618
|
+
results: yandexMatches
|
|
619
|
+
}
|
|
620
|
+
};
|
|
468
621
|
/** The options `images` takes. Google Images has no `limit`. */
|
|
469
622
|
const IMAGE_OPTIONS = [
|
|
470
623
|
"country",
|
|
@@ -578,23 +731,74 @@ const ImageItem = looseObject({
|
|
|
578
731
|
thumbnail: optionalString,
|
|
579
732
|
title: optionalString
|
|
580
733
|
});
|
|
734
|
+
/** A Google Lens visual match: `link` is the page, `image` the matched image. */
|
|
735
|
+
const VisualMatch = looseObject({
|
|
736
|
+
image: optionalString,
|
|
737
|
+
image_height: optionalNumber,
|
|
738
|
+
image_width: optionalNumber,
|
|
739
|
+
link: optionalString,
|
|
740
|
+
source: optionalString,
|
|
741
|
+
thumbnail: optionalString,
|
|
742
|
+
title: optionalString
|
|
743
|
+
});
|
|
744
|
+
/** A Google Lens exact match: `link` is the page. It has no image URL, only a thumbnail and the image's size. */
|
|
745
|
+
const ExactMatch = looseObject({
|
|
746
|
+
actual_image_height: optionalNumber,
|
|
747
|
+
actual_image_width: optionalNumber,
|
|
748
|
+
date: optionalString,
|
|
749
|
+
link: optionalString,
|
|
750
|
+
source: optionalString,
|
|
751
|
+
thumbnail: optionalString,
|
|
752
|
+
title: optionalString
|
|
753
|
+
});
|
|
754
|
+
/** A Bing page with the image: `source` is the page, `original` the image. `link` is a Bing page, not the source. */
|
|
755
|
+
const BingPage = looseObject({
|
|
756
|
+
height: optionalNumber,
|
|
757
|
+
original: optionalString,
|
|
758
|
+
source: optionalString,
|
|
759
|
+
thumbnail: optionalString,
|
|
760
|
+
title: optionalString,
|
|
761
|
+
width: optionalNumber
|
|
762
|
+
});
|
|
763
|
+
/** An image given as a URL, or as Yandex gives it: an object with `link` and the size. Either way, an object. */
|
|
764
|
+
const Pictured = z.union([z.pipe(nonEmptyString, z.transform((link) => ({ link }))), looseObject({
|
|
765
|
+
height: optionalNumber,
|
|
766
|
+
link: optionalString,
|
|
767
|
+
width: optionalNumber
|
|
768
|
+
})]);
|
|
769
|
+
/**
|
|
770
|
+
* A reverse image page. Google gives `link`, `snippet`, `title` and a `thumbnail`
|
|
771
|
+
* URL; Yandex gives the same with `thumbnail` and `original_image` as objects.
|
|
772
|
+
*/
|
|
773
|
+
const ImagePage = looseObject({
|
|
774
|
+
link: optionalString,
|
|
775
|
+
original_image: Pictured,
|
|
776
|
+
snippet: optionalString,
|
|
777
|
+
source: optionalString,
|
|
778
|
+
thumbnail: Pictured,
|
|
779
|
+
title: optionalString
|
|
780
|
+
});
|
|
581
781
|
/** A `/search` response for any engine; each engine reads only its own sections. */
|
|
582
782
|
const SearchResponse = looseObject({
|
|
583
783
|
answer_box: z.union([z.pipe(z.optional(z.null()), z.transform(() => void 0)), AnswerBox]),
|
|
584
784
|
answer_box_list: arrayOf(AnswerBox),
|
|
585
785
|
categorized_shopping_results: arrayOf(looseObject({ shopping_results: arrayOf(ShoppingItem) })),
|
|
586
786
|
error: ErrorNote,
|
|
787
|
+
exact_matches: arrayOf(ExactMatch),
|
|
788
|
+
image_results: arrayOf(ImagePage),
|
|
587
789
|
images_results: arrayOf(ImageItem),
|
|
588
790
|
inline_shopping_results: arrayOf(ShoppingItem),
|
|
589
791
|
local_results: arrayOf(Place),
|
|
590
792
|
news_results: arrayOf(NewsResult),
|
|
591
793
|
organic_results: arrayOf(Organic),
|
|
794
|
+
pages_with_this_image: arrayOf(BingPage),
|
|
592
795
|
place_results: Place,
|
|
593
796
|
search_metadata: looseObject({
|
|
594
797
|
id: optionalScalar,
|
|
595
798
|
status: optionalString
|
|
596
799
|
}),
|
|
597
|
-
shopping_results: arrayOf(ShoppingItem)
|
|
800
|
+
shopping_results: arrayOf(ShoppingItem),
|
|
801
|
+
visual_matches: arrayOf(VisualMatch)
|
|
598
802
|
});
|
|
599
803
|
/** `/account`: the plan and its usage. */
|
|
600
804
|
const AccountResponse = looseObject({
|
|
@@ -607,7 +811,7 @@ const AccountResponse = looseObject({
|
|
|
607
811
|
});
|
|
608
812
|
// src/adapters/serpapi.ts
|
|
609
813
|
/**
|
|
610
|
-
* An adapter for SerpApi: search, images and usage. Pass it to `new Fieldwork({ adapter })`.
|
|
814
|
+
* An adapter for SerpApi: search, images, reverse image and usage. Pass it to `new Fieldwork({ adapter })`.
|
|
611
815
|
*
|
|
612
816
|
* Throws `Unauthorized` when neither `apiKey` nor `SERPAPI_API_KEY` is set.
|
|
613
817
|
*/
|
|
@@ -676,6 +880,27 @@ const serpapi = (config = {}) => {
|
|
|
676
880
|
results: imageResults(body)
|
|
677
881
|
});
|
|
678
882
|
},
|
|
883
|
+
async reverseImage(imageUrl, options) {
|
|
884
|
+
const { call, rest } = callSettings(options);
|
|
885
|
+
const { engine = "google_lens", ...chosen } = rest;
|
|
886
|
+
const o = { ...chosen };
|
|
887
|
+
if (!Object.hasOwn(REVERSE_ENGINES, engine)) throw invalidRequest(provider, `does not offer the reverse image engine "${engine}"`);
|
|
888
|
+
if (!URL.canParse(imageUrl) || !/^https?:$/u.test(new URL(imageUrl).protocol)) throw invalidRequest(provider, "imageUrl must be an http or https URL");
|
|
889
|
+
const spec = REVERSE_ENGINES[engine];
|
|
890
|
+
onlyAllowed(engine, o, spec.allowed);
|
|
891
|
+
const { body, response } = await searchCall(call, compact({
|
|
892
|
+
engine,
|
|
893
|
+
[spec.imageParam]: imageUrl,
|
|
894
|
+
...spec.params(o),
|
|
895
|
+
no_cache: o.noCache === true ? true : void 0
|
|
896
|
+
}));
|
|
897
|
+
const results = spec.results(body);
|
|
898
|
+
return compact({
|
|
899
|
+
meta: reverseImageMeta(body, results),
|
|
900
|
+
raw: response,
|
|
901
|
+
results
|
|
902
|
+
});
|
|
903
|
+
},
|
|
679
904
|
async search(query, options) {
|
|
680
905
|
const { call, rest } = callSettings(options);
|
|
681
906
|
const { engine = "google", ...chosen } = rest;
|
package/dist/tavily.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as OutputSchema } from "./schema-
|
|
1
|
+
import { $ as Research, F as ImageSearch, G as PageBatch, Q as Recency, W as Page, _ as Crawl, a as RawClient, at as SiteMap, l as Answer, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
|
|
2
|
+
import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
|
|
3
3
|
/** Settings for the Tavily adapter. */
|
|
4
4
|
interface TavilyConfig {
|
|
5
5
|
/** Defaults to the TAVILY_API_KEY environment variable. */
|
package/dist/tavily.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as defineAdapter } from "./adapter-DWYJys20.js";
|
|
2
|
-
import { r as invalidRequest, t as FieldworkError } from "./errors-
|
|
3
|
-
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, m as optionalScalar, n as anything, r as arrayOf } from "./parse-
|
|
4
|
-
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-
|
|
5
|
-
import { n as jsonSchemaOf, t as checkOutput } from "./schema
|
|
6
|
-
import { a as compact, o as hours, s as meta, t as callSettings } from "./util-
|
|
2
|
+
import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
|
|
3
|
+
import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, m as optionalScalar, n as anything, r as arrayOf } from "./parse-Q7H4mrnO.js";
|
|
4
|
+
import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DnavRq_s.js";
|
|
5
|
+
import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
|
|
6
|
+
import { a as compact, o as hours, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
|
|
7
7
|
import * as z from "zod/mini";
|
|
8
8
|
// src/adapters/tavily/countries.ts
|
|
9
9
|
/** Tavily's country names, by ISO 3166-1 alpha-2 code. */
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-
|
|
2
|
-
import {
|
|
1
|
+
import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-BrfoehvG.js";
|
|
2
|
+
import { I as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-B8kAAAgF.js";
|
|
3
3
|
/** Any JSON value. */
|
|
4
4
|
type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
|
|
5
5
|
/** A JSON object. A key may be undefined, which reads as absent and is not serialized. */
|