@howells/fieldwork-sdk 0.10.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fieldwork
2
2
 
3
- One API for searching the web, reading pages, extracting values, walking sites, answering and researching questions, finding entities, watching for changes, driving a browser, parsing documents and downloading files, across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.
3
+ One API for searching the web, finding where an image appears, reading pages, extracting values, walking sites, answering and researching questions, finding entities, watching for changes, driving a browser, parsing documents and downloading files, across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.
4
4
 
5
5
  ```sh
6
6
  npm i @howells/fieldwork-sdk
@@ -28,6 +28,7 @@ Each instance has only the methods its provider offers, so a call the provider c
28
28
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
29
29
  | `search(query)` | yes | yes | yes | yes | yes | yes | yes | yes | | | |
30
30
  | `images(query)` | | yes | yes | yes | | yes | yes | | | | |
31
+ | `reverseImage(imageUrl)` | | | | | | | yes | | | | |
31
32
  | `read(url)` | yes | yes | yes | yes | | | | yes | yes | | |
32
33
  | `readMany(urls)` | yes | yes | yes | yes | | | | | | | |
33
34
  | `extract(url, { schema })` | yes | yes | | yes | | | | | | | |
@@ -52,6 +53,7 @@ Each instance has only the methods its provider offers, so a call the provider c
52
53
  - `decide` answers closed questions about a context: yes or no, a choice, or a score on a rubric, each with a probability.
53
54
  - `browser.open()` starts a remote browser and returns its CDP URL for Playwright or Puppeteer; `act(code)` runs one script in a fresh session.
54
55
  - `download` returns a file's bytes, its content type and the final URL after redirects, fetched through the provider's network. See [Downloading files](#downloading-files).
56
+ - `reverseImage` takes an image's URL and returns the pages it appears on. Only SerpApi offers it, because it is the only provider that accepts an image as input. `engine` chooses where it looks: `"google_lens"` (the default), `"google_reverse_image"`, `"bing_reverse_image"` or `"yandex_images"`. Each match has `sourceUrl`, the page, on every engine; `url` is the matched image, and is absent from a Lens exact match, which names only the page. `kind` is `"exact"` for the same image and `"visual"` for a similar one, and is left out where the engine does not say. See [Reverse image search](#reverse-image-search).
55
57
  - `monitor` repeats a search or a page check on a schedule and reports what changed. Exa and Parallel monitors watch a query; Firecrawl monitors also watch specific pages (`urls`).
56
58
 
57
59
  ### Options
@@ -68,7 +70,8 @@ Options are typed per provider. An option means the same thing under the same na
68
70
  | `country` | An ISO 3166-1 code such as `"GB"`. |
69
71
  | `language` | An ISO 639-1 code such as `"de"`. |
70
72
  | `schema`, `prompt` | A JSON Schema or a Standard Schema such as Zod for structured output, and extraction instructions in plain words. |
71
- | `query` | On `read`: return the passages that answer it as `excerpts`. |
73
+ | `query` | On `read`: return the passages that answer it as `excerpts`. On `reverseImage`: text to refine the search with. |
74
+ | `match` | On `reverseImage`: `"exact"` for pages showing the same image, `"visual"` for similar ones. |
72
75
  | `content` | On `search`: include each result's page text. |
73
76
  | `continueFrom` | On `answer` and `research`: the `continuationId` of an earlier result, to ask a follow-up. |
74
77
  | `maxBytes` | On `download`: the largest file accepted, in bytes. Defaults to, and may not exceed, the provider's ceiling. |
@@ -100,6 +103,7 @@ Providers differ in which keywords they accept; Exa reads draft 7 and the others
100
103
  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.
101
104
 
102
105
  - `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`.
106
+ - `reverseImage` returns `{ results, meta, raw }`. Each match has `sourceUrl` and, when the provider has them, `url` (the matched image), `thumbnailUrl`, `title`, `description`, `width`, `height` and `kind`.
103
107
  - `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`.
104
108
  - `readMany` returns `{ pages, failed }`. A URL that could not be read is listed in `failed` with the reason; it does not throw.
105
109
  - `extract` returns `{ data, fields }`. `data` follows your schema; `fields` lists each field's citations when the provider returns them.
@@ -170,6 +174,33 @@ const digest = await crypto.subtle.digest("SHA-256", file.bytes);
170
174
 
171
175
  A response that is not 2xx throws (`NotFound` for 404 and 410), a web page throws `NotAFile`, and a file over the limit throws `TooLarge`. Check `contentType` for anything narrower, such as "is this link really a PDF?". `download` is not an agent tool or MCP tool: a tool result cannot usefully carry tens of megabytes.
172
176
 
177
+ ### Reverse image search
178
+
179
+ `reverseImage(imageUrl, options)` is SerpApi's. The image must be at a public `http` or `https` URL.
180
+
181
+ ```ts
182
+ const web = new Fieldwork({ adapter: serpapi() });
183
+
184
+ const { results } = await web.reverseImage("https://example.com/chair.jpg", {
185
+ match: "exact",
186
+ });
187
+ results[0].sourceUrl; // the page the image appears on
188
+ ```
189
+
190
+ | `engine` | Reads | `kind` | Options |
191
+ | --- | --- | --- | --- |
192
+ | `google_lens` (default) | `exact_matches` and `visual_matches` | `"exact"` and `"visual"` | `match`, `query`, `country`, `language`, `noCache` |
193
+ | `google_reverse_image` | `image_results` and `visual_matches` | `"visual"` for `visual_matches`; absent for pages | `query`, `country`, `language`, `noCache` |
194
+ | `bing_reverse_image` | `pages_with_this_image` | `"exact"` | `limit` (sent as `count`, 1 to 150), `market`, `noCache` |
195
+ | `yandex_images` | "About the image" `image_results` | absent | `noCache` |
196
+
197
+ - `match` is Lens's `type`: `"exact"` is `exact_matches` and `"visual"` is `visual_matches`. Left out, Lens answers its default, which lists visual matches only, so ask for `"exact"` to get exact ones. The other engines cannot narrow by kind, so they refuse `match`.
198
+ - Lens applies `query` only to visual matches, so `query` with `match: "exact"` throws `InvalidRequest`.
199
+ - Only Bing has a result count. Lens, Google reverse image and Yandex refuse `limit` rather than cut the list after paying for it, as `images` does.
200
+ - Bing's `related_content` (similar images) is left out of `results`; it stays in `raw`. Yandex's "Similar images" tab names no source page, so it is not offered.
201
+ - Lens returns most exact matches' pages as Google redirect links (`google.com/goto?url=…`), whether or not `noCache` is set. The link is kept as received, and `meta.warnings` says how many there are; a GET on the link answers with a redirect to the page.
202
+ - `siteName` is the site's name as the engine shows it ("Mark D. Sikes", "Architectural Digest") and `publishedAt` the page's date, where Lens gives one. Both help tell an original source from a copy.
203
+
173
204
  ## Choosing a provider per capability
174
205
 
175
206
  `router` sends each capability to exactly one adapter:
@@ -237,7 +268,7 @@ await web.search("tiles", { retries: 0 }); // this call only
237
268
 
238
269
  ## Agent tools
239
270
 
240
- `@howells/fieldwork-sdk/tools` turns an instance into tool definitions for a model, one per capability or group method: `search_web`, `search_images`, `read_page`, `read_pages`, `extract_values`, `read_product`, `map_site`, `crawl_site`, `answer_question`, `research_question`, `find_entities`, `make_decisions`, `parse_document`, `check_usage`, `run_browser_script`, `open_browser`, `close_browser`, `create_monitor`, `get_monitor`, `list_monitors`, `delete_monitor` and `list_monitor_events`. Each tool has:
271
+ `@howells/fieldwork-sdk/tools` turns an instance into tool definitions for a model, one per capability or group method: `search_web`, `search_images`, `search_by_image`, `read_page`, `read_pages`, `extract_values`, `read_product`, `map_site`, `crawl_site`, `answer_question`, `research_question`, `find_entities`, `make_decisions`, `parse_document`, `check_usage`, `run_browser_script`, `open_browser`, `close_browser`, `create_monitor`, `get_monitor`, `list_monitors`, `delete_monitor` and `list_monitor_events`. Each tool has:
241
272
 
242
273
  - a description that says when to use it and which tool to use instead;
243
274
  - a JSON Schema input that lists only the options its provider supports;
@@ -1,7 +1,7 @@
1
1
  /** A JSON Schema object describing the values to extract. */
2
2
  type JsonSchema = Record<string, unknown>;
3
3
  /** Every capability Fieldwork knows. An adapter implements a subset. */
4
- declare const CAPABILITIES: readonly ["search", "images", "read", "readMany", "extract", "product", "map", "crawl", "answer", "research", "discover", "decide", "act", "browser", "parse", "download", "monitor", "usage"];
4
+ declare const CAPABILITIES: readonly ["search", "images", "reverseImage", "read", "readMany", "extract", "product", "map", "crawl", "answer", "research", "discover", "decide", "act", "browser", "parse", "download", "monitor", "usage"];
5
5
  /** A capability's name, such as `search` or `monitor`. */
6
6
  type Capability = (typeof CAPABILITIES)[number];
7
7
  /**
@@ -133,6 +133,29 @@ interface ImageSearch {
133
133
  meta?: Meta;
134
134
  raw: unknown;
135
135
  }
136
+ /** Whether a reverse image match is the same image or only a similar one. */
137
+ type MatchKind = "exact" | "visual";
138
+ /**
139
+ * One match from `reverseImage`. `sourceUrl` is the page the image appears on
140
+ * and is always there. `url` is the matched image itself, and is absent when the
141
+ * provider names only the page (Google Lens exact matches).
142
+ */
143
+ interface ImageMatch extends Omit<ImageResult, "sourceUrl" | "url"> {
144
+ sourceUrl: string;
145
+ url?: string;
146
+ /** "exact" for the same image, "visual" for a similar one; absent when the provider does not say. */
147
+ kind?: MatchKind;
148
+ /** The name of the site the page belongs to, as the provider shows it, such as "Mark D. Sikes". */
149
+ siteName?: string;
150
+ /** When the page was published, as the provider reports it. */
151
+ publishedAt?: string;
152
+ }
153
+ /** What `reverseImage` returns. */
154
+ interface ReverseImageSearch {
155
+ results: ImageMatch[];
156
+ meta?: Meta;
157
+ raw: unknown;
158
+ }
136
159
  /** What `read` returns: one page, in the formats the call asked for. */
137
160
  interface Page {
138
161
  url: string;
@@ -631,4 +654,4 @@ type AnyAdapter = Adapter<string, any, unknown>;
631
654
  * It returns its argument unchanged; write a custom adapter with it.
632
655
  */
633
656
  declare const defineAdapter: <Name extends string, Ops extends Operations, Raw = RawClient>(adapter: Adapter<Name, Ops, Raw>) => Adapter<Name, Ops, Raw>;
634
- export { SearchResponse as $, FailedUrl as A, MonitorInfo as B, DocumentInput as C, DownloadedFile as D, DownloadOptions as E, JsonSchema as F, Place as G, Page as H, LineBox as I, ProductImage as J, Price as K, Meta as L, GROUP_CAPABILITIES as M, ImageResult as N, Entity as O, ImageSearch as P, RunStatus as Q, MonitorEvent as R, DocumentBlock as S, DocumentUrl as T, PageBatch as U, MonitorSchedule as V, ParsedDocument as W, Recency as X, ProductVariant as Y, Research as Z, Crawl as _, RawClient as a, WordBox as at, Decisions as b, ActResult as c, BrowserSession as d, SearchResult as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, Usage as it, FieldSource as j, Extraction as k, Answer as l, Capability as m, AnyAdapter as n, SiteMap as nt, RequestOptions as o, CallOptions as p, Product as q, Operations as r, TableCell as rt, AccountUsage as s, Adapter as t, SiteLink as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, MonitorEvents as z };
657
+ export { Research as $, FailedUrl as A, MonitorEvent as B, DocumentInput as C, DownloadedFile as D, DownloadOptions as E, ImageSearch as F, PageBatch as G, MonitorInfo as H, JsonSchema as I, Price as J, ParsedDocument as K, LineBox as L, GROUP_CAPABILITIES as M, ImageMatch as N, Entity as O, ImageResult as P, Recency as Q, MatchKind as R, DocumentBlock as S, DocumentUrl as T, MonitorSchedule as U, MonitorEvents as V, Page as W, ProductImage as X, Product as Y, ProductVariant as Z, Crawl as _, RawClient as a, SiteMap as at, Decisions as b, ActResult as c, WordBox as ct, BrowserSession as d, ReverseImageSearch as et, CAPABILITIES as f, Condition as g, Citation as h, defineAdapter as i, SiteLink as it, FieldSource as j, Extraction as k, Answer as l, Capability as m, AnyAdapter as n, SearchResponse as nt, RequestOptions as o, TableCell as ot, CallOptions as p, Place as q, Operations as r, SearchResult as rt, AccountUsage as s, Usage as st, Adapter as t, RunStatus as tt, Box as u, DecisionAnswer as v, DocumentPage as w, Discovery as x, DecisionQuestion as y, Meta as z };
package/dist/brave.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as SearchResponse, P as ImageSearch, X as Recency, a as RawClient, l as Answer, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
1
+ import { F as ImageSearch, Q as Recency, a as RawClient, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
2
2
  /** Settings for `brave()`. */
3
3
  interface BraveConfig {
4
4
  /** Defaults to the BRAVE_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { $ as SearchResponse, D as DownloadedFile, E as DownloadOptions, H as Page, a as RawClient, d as BrowserSession, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
1
+ import { D as DownloadedFile, E as DownloadOptions, W as Page, a as RawClient, d as BrowserSession, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
2
2
  /** Settings for `browserbase()`. */
3
3
  export interface BrowserbaseConfig {
4
4
  /** Defaults to the BROWSERBASE_API_KEY environment variable. */
package/dist/exa.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as SearchResponse, B as MonitorInfo, H as Page, U as PageBatch, V as MonitorSchedule, Z as Research, a as RawClient, k as Extraction, l as Answer, p as CallOptions, t as Adapter, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
- import { t as OutputSchema } from "./schema-BFjS6CSz.js";
1
+ import { $ as Research, G as PageBatch, H as MonitorInfo, U as MonitorSchedule, V as MonitorEvents, W as Page, a as RawClient, k as Extraction, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
2
+ import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
3
3
  /** Settings for the Exa adapter. */
4
4
  interface ExaConfig {
5
5
  /** Defaults to the EXA_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { L as Meta, m as Capability, n as AnyAdapter } from "./adapter-DQrBP1tj.js";
1
+ import { m as Capability, n as AnyAdapter, z as Meta } from "./adapter-B8kAAAgF.js";
2
2
  /** Why a call failed. Branch on this, not on the message, which can change. */
3
3
  type FieldworkErrorCode =
4
4
  /** The adapter's provider does not offer this capability. */
@@ -1,5 +1,5 @@
1
- import { $ as SearchResponse, B as MonitorInfo, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, H as Page, P as ImageSearch, U as PageBatch, V as MonitorSchedule, W as ParsedDocument, X as Recency, Z as Research, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, k as Extraction, nt as SiteMap, p as CallOptions, q as Product, s as AccountUsage, t as Adapter, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
- import { t as OutputSchema } from "./schema-BFjS6CSz.js";
1
+ import { $ as Research, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as ImageSearch, G as PageBatch, H as MonitorInfo, K as ParsedDocument, Q as Recency, U as MonitorSchedule, V as MonitorEvents, W as Page, Y as Product, _ as Crawl, a as RawClient, at as SiteMap, c as ActResult, d as BrowserSession, k as Extraction, 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 Firecrawl adapter. */
4
4
  interface FirecrawlConfig {
5
5
  /** Defaults to the FIRECRAWL_API_KEY environment variable. */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as SearchResponse, A as FailedUrl, B as MonitorInfo, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as JsonSchema, G as Place, H as Page, I as LineBox, J as ProductImage, K as Price, L as Meta, M as GROUP_CAPABILITIES, N as ImageResult, O as Entity, P as ImageSearch, Q as RunStatus, R as MonitorEvent, S as DocumentBlock, T as DocumentUrl, U as PageBatch, V as MonitorSchedule, W as ParsedDocument, X as Recency, Y as ProductVariant, Z as Research, _ as Crawl, a as RawClient, at as WordBox, b as Decisions, c as ActResult, d as BrowserSession, et as SearchResult, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, it as Usage, j as FieldSource, k as Extraction, l as Answer, m as Capability, n as AnyAdapter, nt as SiteMap, o as RequestOptions, p as CallOptions, q as Product, r as Operations, rt as TableCell, s as AccountUsage, t as Adapter, tt as SiteLink, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
- import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-JCfyw58T.js";
3
- import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-BFjS6CSz.js";
1
+ import { $ as Research, A as FailedUrl, B as MonitorEvent, C as DocumentInput, D as DownloadedFile, E as DownloadOptions, F as ImageSearch, G as PageBatch, H as MonitorInfo, I as JsonSchema, J as Price, K as ParsedDocument, L as LineBox, M as GROUP_CAPABILITIES, N as ImageMatch, O as Entity, P as ImageResult, Q as Recency, R as MatchKind, S as DocumentBlock, T as DocumentUrl, U as MonitorSchedule, V as MonitorEvents, W as Page, X as ProductImage, Y as Product, Z as ProductVariant, _ as Crawl, a as RawClient, at as SiteMap, b as Decisions, c as ActResult, ct as WordBox, d as BrowserSession, et as ReverseImageSearch, f as CAPABILITIES, g as Condition, h as Citation, i as defineAdapter, it as SiteLink, j as FieldSource, k as Extraction, l as Answer, m as Capability, n as AnyAdapter, nt as SearchResponse, o as RequestOptions, ot as TableCell, p as CallOptions, q as Place, r as Operations, rt as SearchResult, s as AccountUsage, st as Usage, t as Adapter, tt as RunStatus, u as Box, v as DecisionAnswer, w as DocumentPage, x as Discovery, y as DecisionQuestion, z as Meta } from "./adapter-B8kAAAgF.js";
2
+ import { i as FieldworkErrorCode, n as FieldworkOptions, r as FieldworkError, t as Fieldwork } from "./fieldwork-BrfoehvG.js";
3
+ import { n as StandardSchemaWithJSON, t as OutputSchema } from "./schema-CAPSX7yQ.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. */
@@ -23,4 +23,4 @@ export declare const router: <const R extends Routes>(routes: R & ValidRoutes<R>
23
23
  * `Unsupported` here instead of failing to compile.
24
24
  */
25
25
  export declare const runtimeRouter: (routes: Routes) => AnyAdapter;
26
- export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, Box, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentBlock, DocumentInput, DocumentPage, DocumentUrl, DownloadOptions, DownloadedFile, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageResult, ImageSearch, JsonSchema, LineBox, 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, TableCell, Usage, WordBox, defineAdapter };
26
+ export { AccountUsage, ActResult, type Adapter, Answer, type AnyAdapter, Box, BrowserSession, CAPABILITIES, CallOptions, Capability, Citation, Condition, Crawl, DecisionAnswer, DecisionQuestion, Decisions, Discovery, DocumentBlock, DocumentInput, DocumentPage, DocumentUrl, DownloadOptions, DownloadedFile, Entity, Extraction, FailedUrl, FieldSource, Fieldwork, FieldworkError, type FieldworkErrorCode, type FieldworkOptions, GROUP_CAPABILITIES, ImageMatch, ImageResult, ImageSearch, JsonSchema, LineBox, MatchKind, Meta, MonitorEvent, MonitorEvents, MonitorInfo, MonitorSchedule, type Operations, type OutputSchema, Page, PageBatch, ParsedDocument, Place, Price, Product, ProductImage, ProductVariant, type RawClient, Recency, type RequestOptions, Research, ReverseImageSearch, type Routes, RunStatus, SearchResponse, SearchResult, SiteLink, SiteMap, type StandardSchemaWithJSON, TableCell, Usage, WordBox, defineAdapter };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
2
  import { t as FieldworkError } from "./errors-DkFJysIM.js";
3
- import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-rc8bl8Em.js";
3
+ import { n as GROUP_CAPABILITIES, t as CAPABILITIES } from "./types-mq6d6YOK.js";
4
4
  // src/fieldwork.ts
5
5
  /**
6
6
  * The adapter's operation for a capability, bound to its `operations` object
@@ -59,6 +59,7 @@ var FieldworkClient = class {
59
59
  read: has("read"),
60
60
  readMany: has("readMany"),
61
61
  research: has("research"),
62
+ reverseImage: has("reverseImage"),
62
63
  search: has("search"),
63
64
  usage: has("usage")
64
65
  });
package/dist/kernel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { D as DownloadedFile, E as DownloadOptions, H as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
1
+ import { D as DownloadedFile, E as DownloadOptions, W as Page, a as RawClient, d as BrowserSession, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
2
2
  /** Settings for `kernel()`. */
3
3
  export interface KernelConfig {
4
4
  /** Defaults to the KERNEL_API_KEY environment variable. */
@@ -1,4 +1,4 @@
1
- import { C as DocumentInput, T as DocumentUrl, W as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
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 `llamaparse()`. */
3
3
  export interface LlamaParseConfig {
4
4
  /** Defaults to the LLAMA_CLOUD_API_KEY environment variable. */
@@ -1,5 +1,5 @@
1
- import { $ as SearchResponse, B as MonitorInfo, H as Page, P as ImageSearch, U as PageBatch, V as MonitorSchedule, Z as Research, a as RawClient, b as Decisions, g as Condition, k as Extraction, l as Answer, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion, z as MonitorEvents } from "./adapter-DQrBP1tj.js";
2
- import { t as OutputSchema } from "./schema-BFjS6CSz.js";
1
+ import { $ as Research, F as ImageSearch, G as PageBatch, H as MonitorInfo, U as MonitorSchedule, V as MonitorEvents, W as Page, a as RawClient, b as Decisions, g as Condition, k as Extraction, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter, x as Discovery, y as DecisionQuestion } from "./adapter-B8kAAAgF.js";
2
+ import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
3
3
  import "./util-DhYr1OS3.js";
4
4
  /** Settings for `parallel()`. */
5
5
  interface ParallelConfig {
@@ -63,7 +63,7 @@ interface ParallelSearchOptions extends CallOptions, ParallelSources {
63
63
  interface ParallelImagesOptions extends CallOptions {
64
64
  /** The images wanted, in plain words, up to 5,000 characters. Defaults to the query. */
65
65
  objective?: string;
66
- /** Up to 5 image queries; defaults to the query alone. */
66
+ /** Up to 3 image queries (Parallel uses only the first 3); defaults to the query alone. */
67
67
  queries?: string[];
68
68
  mode?: "fast" | "advanced";
69
69
  /** Sent as `max_results`. */
@@ -1,5 +1,5 @@
1
- import { $ as SearchResponse, X as Recency, Z as Research, a as RawClient, b as Decisions, l as Answer, p as CallOptions, t as Adapter, y as DecisionQuestion } from "./adapter-DQrBP1tj.js";
2
- import { t as OutputSchema } from "./schema-BFjS6CSz.js";
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/reducto.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as DocumentInput, T as DocumentUrl, W as ParsedDocument, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-DQrBP1tj.js";
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. */
@@ -1,4 +1,4 @@
1
- import { F as JsonSchema } from "./adapter-DQrBP1tj.js";
1
+ import { I as JsonSchema } from "./adapter-B8kAAAgF.js";
2
2
  /** Vendor-specific parameters a schema library may accept. */
3
3
  type LibraryOptions = JsonSchema;
4
4
  /** The path segment interface of an issue. */
package/dist/serpapi.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as SearchResponse, P as ImageSearch, X as Recency, a as RawClient, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
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
- /** What SerpApi offers: search, images and usage. */
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
@@ -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 SearchResponse, H as Page, P as ImageSearch, U as PageBatch, X as Recency, Z as Research, _ as Crawl, a as RawClient, l as Answer, nt as SiteMap, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-DQrBP1tj.js";
2
- import { t as OutputSchema } from "./schema-BFjS6CSz.js";
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/tools.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-JCfyw58T.js";
2
- import { F as JsonSchema, m as Capability, n as AnyAdapter, p as CallOptions } from "./adapter-DQrBP1tj.js";
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. */
package/dist/tools.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as FieldworkError } from "./errors-DkFJysIM.js";
2
2
  import { f as refuseTogether } from "./util-DFUXQX6v.js";
3
3
  import { a as isNumber, i as isList, n as isFlag, o as isText, r as isJsonObject, t as joinPath } from "./path-DL5P8XH2.js";
4
- import { t as CAPABILITIES } from "./types-rc8bl8Em.js";
4
+ import { t as CAPABILITIES } from "./types-mq6d6YOK.js";
5
5
  import * as z from "zod/mini";
6
6
  // src/tool-specs/schema.ts
7
7
  const described = (schema, description) => description === void 0 ? schema : {
@@ -261,6 +261,18 @@ const imageResult = object({
261
261
  url: str,
262
262
  width: number()
263
263
  }, ["url"]);
264
+ const imageMatch = object({
265
+ description: str,
266
+ height: number(),
267
+ kind: choice("exact for the same image, visual for a similar one; absent when the provider does not say.", ["exact", "visual"]),
268
+ publishedAt: str,
269
+ siteName: str,
270
+ sourceUrl: str,
271
+ thumbnailUrl: str,
272
+ title: str,
273
+ url: str,
274
+ width: number()
275
+ }, ["sourceUrl"]);
264
276
  const page = object({
265
277
  author: str,
266
278
  description: str,
@@ -338,6 +350,11 @@ const IMAGES_OUTPUT = object({
338
350
  meta,
339
351
  results: list(imageResult)
340
352
  }, ["results"]);
353
+ /** The result of `search_by_image`, a `ReverseImageSearch`. */
354
+ const IMAGE_MATCHES_OUTPUT = object({
355
+ meta,
356
+ results: list(imageMatch)
357
+ }, ["results"]);
341
358
  /** The result of `read_page`, a `Page`. */
342
359
  const PAGE_OUTPUT = page;
343
360
  /** The result of `read_pages`, a `PageBatch`: the pages read, and `failed` for URLs that could not be. */
@@ -1146,130 +1163,163 @@ const READ_SPECS = [
1146
1163
  * these into tools, in this order.
1147
1164
  */
1148
1165
  const SPECS = [
1149
- ...[{
1150
- capability: "search",
1151
- description: "Search the web and return a ranked list of pages with their titles, URLs and matching snippets. Use when you need pages about a topic, product or fact and do not have a URL yet. Do not use to read a page you already have a URL for (use read_page), for pictures (use search_images), or for a question that needs several sources combined into an answer (use research_question).",
1152
- destructive: false,
1153
- fields: [
1154
- {
1155
- name: "query",
1156
- required: true,
1157
- schema: text("What to search for.")
1158
- },
1159
- limit("How many results to return.", 20, [
1160
- "exa",
1161
- "firecrawl",
1162
- "tavily",
1163
- "parallel",
1164
- "perplexity",
1165
- "brave",
1166
- "browserbase"
1167
- ]),
1168
- includeDomains("results", [
1169
- "exa",
1170
- "firecrawl",
1171
- "tavily",
1172
- "parallel",
1173
- "perplexity"
1174
- ]),
1175
- excludeDomains("results", [
1176
- "exa",
1177
- "firecrawl",
1178
- "tavily",
1179
- "parallel",
1180
- "perplexity"
1181
- ]),
1182
- publishedAfter([
1183
- "exa",
1184
- "firecrawl",
1185
- "tavily",
1186
- "parallel",
1187
- "perplexity",
1188
- "brave",
1189
- "serpapi"
1190
- ]),
1191
- publishedBefore([
1192
- "exa",
1193
- "firecrawl",
1194
- "tavily",
1195
- "perplexity",
1196
- "brave",
1197
- "serpapi"
1198
- ]),
1199
- ...recency([
1200
- "firecrawl",
1201
- "perplexity",
1202
- "serpapi"
1203
- ], ["tavily", "brave"]),
1204
- country([
1205
- "exa",
1206
- "firecrawl",
1207
- "tavily",
1208
- "parallel",
1209
- "perplexity",
1210
- "brave",
1211
- "serpapi"
1212
- ], "Localize results to"),
1213
- language([
1214
- "tavily",
1215
- "perplexity",
1216
- "brave",
1217
- "serpapi"
1218
- ]),
1219
- {
1220
- name: "content",
1221
- providers: [
1166
+ ...[
1167
+ {
1168
+ capability: "search",
1169
+ description: "Search the web and return a ranked list of pages with their titles, URLs and matching snippets. Use when you need pages about a topic, product or fact and do not have a URL yet. Do not use to read a page you already have a URL for (use read_page), for pictures of a subject (use search_images), for where an image appears (use search_by_image), or for a question that needs several sources combined into an answer (use research_question).",
1170
+ destructive: false,
1171
+ fields: [
1172
+ {
1173
+ name: "query",
1174
+ required: true,
1175
+ schema: text("What to search for.")
1176
+ },
1177
+ limit("How many results to return.", 20, [
1178
+ "exa",
1179
+ "firecrawl",
1180
+ "tavily",
1181
+ "parallel",
1182
+ "perplexity",
1183
+ "brave",
1184
+ "browserbase"
1185
+ ]),
1186
+ includeDomains("results", [
1187
+ "exa",
1188
+ "firecrawl",
1189
+ "tavily",
1190
+ "parallel",
1191
+ "perplexity"
1192
+ ]),
1193
+ excludeDomains("results", [
1194
+ "exa",
1195
+ "firecrawl",
1196
+ "tavily",
1197
+ "parallel",
1198
+ "perplexity"
1199
+ ]),
1200
+ publishedAfter([
1201
+ "exa",
1202
+ "firecrawl",
1203
+ "tavily",
1204
+ "parallel",
1205
+ "perplexity",
1206
+ "brave",
1207
+ "serpapi"
1208
+ ]),
1209
+ publishedBefore([
1210
+ "exa",
1211
+ "firecrawl",
1212
+ "tavily",
1213
+ "perplexity",
1214
+ "brave",
1215
+ "serpapi"
1216
+ ]),
1217
+ ...recency([
1218
+ "firecrawl",
1219
+ "perplexity",
1220
+ "serpapi"
1221
+ ], ["tavily", "brave"]),
1222
+ country([
1222
1223
  "exa",
1223
1224
  "firecrawl",
1224
1225
  "tavily",
1226
+ "parallel",
1227
+ "perplexity",
1228
+ "brave",
1229
+ "serpapi"
1230
+ ], "Localize results to"),
1231
+ language([
1232
+ "tavily",
1233
+ "perplexity",
1234
+ "brave",
1235
+ "serpapi"
1236
+ ]),
1237
+ {
1238
+ name: "content",
1239
+ providers: [
1240
+ "exa",
1241
+ "firecrawl",
1242
+ "tavily",
1243
+ "brave"
1244
+ ],
1245
+ schema: flag("Include each result's page text. Slower and longer; leave out to get snippets only.")
1246
+ },
1247
+ maxAge(["exa", "tavily"]),
1248
+ maxAgeAtLeast600()
1249
+ ],
1250
+ idempotent: true,
1251
+ name: "search_web",
1252
+ output: SEARCH_OUTPUT,
1253
+ positional: ["query"],
1254
+ readOnly: true,
1255
+ title: "Search the web"
1256
+ },
1257
+ {
1258
+ capability: "images",
1259
+ description: "Search for images and return each image's URL, thumbnail, the page it appears on, its title and its size. Use when you need pictures of a subject. Do not use to find pages (use search_web) or to learn what is in an image.",
1260
+ destructive: false,
1261
+ fields: [
1262
+ {
1263
+ name: "query",
1264
+ required: true,
1265
+ schema: text("What the images should show.")
1266
+ },
1267
+ limit("How many images to return.", 20, [
1268
+ "firecrawl",
1269
+ "parallel",
1225
1270
  "brave"
1226
- ],
1227
- schema: flag("Include each result's page text. Slower and longer; leave out to get snippets only.")
1228
- },
1229
- maxAge(["exa", "tavily"]),
1230
- maxAgeAtLeast600()
1231
- ],
1232
- idempotent: true,
1233
- name: "search_web",
1234
- output: SEARCH_OUTPUT,
1235
- positional: ["query"],
1236
- readOnly: true,
1237
- title: "Search the web"
1238
- }, {
1239
- capability: "images",
1240
- description: "Search for images and return each image's URL, thumbnail, the page it appears on, its title and its size. Use when you need pictures of a subject. Do not use to find pages (use search_web) or to learn what is in an image.",
1241
- destructive: false,
1242
- fields: [
1243
- {
1244
- name: "query",
1245
- required: true,
1246
- schema: text("What the images should show.")
1247
- },
1248
- limit("How many images to return.", 20, [
1249
- "firecrawl",
1250
- "parallel",
1251
- "brave"
1252
- ]),
1253
- includeDomains("images", ["tavily"]),
1254
- excludeDomains("images", ["tavily"]),
1255
- publishedAfter(["serpapi"]),
1256
- publishedBefore(["serpapi"]),
1257
- ...recency(["serpapi"], []),
1258
- country([
1259
- "firecrawl",
1260
- "parallel",
1261
- "brave",
1262
- "serpapi"
1263
- ], "Localize results to"),
1264
- language(["brave", "serpapi"])
1265
- ],
1266
- idempotent: true,
1267
- name: "search_images",
1268
- output: IMAGES_OUTPUT,
1269
- positional: ["query"],
1270
- readOnly: true,
1271
- title: "Search for images"
1272
- }],
1271
+ ]),
1272
+ includeDomains("images", ["tavily"]),
1273
+ excludeDomains("images", ["tavily"]),
1274
+ publishedAfter(["serpapi"]),
1275
+ publishedBefore(["serpapi"]),
1276
+ ...recency(["serpapi"], []),
1277
+ country([
1278
+ "firecrawl",
1279
+ "parallel",
1280
+ "brave",
1281
+ "serpapi"
1282
+ ], "Localize results to"),
1283
+ language(["brave", "serpapi"])
1284
+ ],
1285
+ idempotent: true,
1286
+ name: "search_images",
1287
+ output: IMAGES_OUTPUT,
1288
+ positional: ["query"],
1289
+ readOnly: true,
1290
+ title: "Search for images"
1291
+ },
1292
+ {
1293
+ capability: "reverseImage",
1294
+ description: "Find the web pages an image appears on, given the image's URL. Returns each page's URL (sourceUrl), the matched image when the provider gives one, a thumbnail, a title and whether the match is the same image or a similar one. Use when you have an image and need to know where it is published, who uses it or where a larger copy is. Do not use to find pictures of a subject (use search_images), to find pages by text (use search_web) or to learn what is in an image.",
1295
+ destructive: false,
1296
+ fields: [
1297
+ {
1298
+ name: "imageUrl",
1299
+ required: true,
1300
+ schema: url("The image's full URL, including https://. It must be publicly reachable.")
1301
+ },
1302
+ {
1303
+ name: "query",
1304
+ providers: ["serpapi"],
1305
+ schema: text("Words to refine the search with, such as the subject. SerpApi refuses it together with match \"exact\".")
1306
+ },
1307
+ {
1308
+ name: "match",
1309
+ providers: ["serpapi"],
1310
+ schema: choice("exact for pages showing the same image, visual for pages showing a similar one. Leave out for the provider's default, which lists similar images.", ["exact", "visual"])
1311
+ },
1312
+ country(["serpapi"], "Localize results to"),
1313
+ language(["serpapi"])
1314
+ ],
1315
+ idempotent: true,
1316
+ name: "search_by_image",
1317
+ output: IMAGE_MATCHES_OUTPUT,
1318
+ positional: ["imageUrl"],
1319
+ readOnly: true,
1320
+ title: "Find where an image appears"
1321
+ }
1322
+ ],
1273
1323
  ...READ_SPECS,
1274
1324
  ...ANSWER_SPECS,
1275
1325
  ...BROWSER_SPECS,
@@ -3,6 +3,7 @@
3
3
  const CAPABILITIES = [
4
4
  "search",
5
5
  "images",
6
+ "reverseImage",
6
7
  "read",
7
8
  "readMany",
8
9
  "extract",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@howells/fieldwork-sdk",
3
- "version": "0.10.2",
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, Browserbase, Kernel, LlamaParse and Reducto.",
3
+ "version": "0.11.0",
4
+ "description": "One API for web search, reverse image search, page reading, extraction, crawling, answers, research, browser sessions, monitoring and document parsing across Exa, Firecrawl, Tavily, Parallel, Perplexity, Brave, SerpApi, Browserbase, Kernel, LlamaParse and Reducto.",
5
5
  "keywords": [
6
6
  "agents",
7
7
  "brave",