@howells/fieldwork-sdk 0.10.2 → 0.12.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.
Files changed (48) hide show
  1. package/README.md +104 -16
  2. package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
  3. package/dist/adapter-J2yatZJ0.d.ts +73 -0
  4. package/dist/best-CO9liYDa.js +1436 -0
  5. package/dist/brave.d.ts +7 -6
  6. package/dist/brave.js +180 -173
  7. package/dist/browserbase.d.ts +4 -3
  8. package/dist/browserbase.js +185 -170
  9. package/dist/{document-DMIUCoDA.js → document-BSCwJgBM.js} +4 -4
  10. package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
  11. package/dist/{adapter-DQrBP1tj.d.ts → errors-gMtejKHc.d.ts} +111 -70
  12. package/dist/exa.d.ts +18 -11
  13. package/dist/exa.js +306 -275
  14. package/dist/fieldwork-D7npPoUf.d.ts +35 -0
  15. package/dist/firecrawl.d.ts +4 -3
  16. package/dist/firecrawl.js +450 -417
  17. package/dist/{parse-Q7H4mrnO.js → http-CJcvTPnE.js} +223 -225
  18. package/dist/image.d.ts +253 -0
  19. package/dist/image.js +1 -0
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +67 -82
  22. package/dist/{job-DnavRq_s.js → job-JLEpszjr.js} +9 -9
  23. package/dist/kernel.d.ts +20 -2
  24. package/dist/kernel.js +65 -19
  25. package/dist/llamaparse.d.ts +3 -2
  26. package/dist/llamaparse.js +16 -16
  27. package/dist/parallel.d.ts +9 -9
  28. package/dist/parallel.js +423 -389
  29. package/dist/path-DO2llIdp.js +10 -0
  30. package/dist/perplexity.d.ts +6 -5
  31. package/dist/perplexity.js +21 -21
  32. package/dist/reducto.d.ts +3 -2
  33. package/dist/reducto.js +14 -14
  34. package/dist/{schema-BFjS6CSz.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
  35. package/dist/{schema--iU4AXSM.js → schema-CJXFAZ-x.js} +12 -3
  36. package/dist/serpapi.d.ts +63 -5
  37. package/dist/serpapi.js +374 -144
  38. package/dist/tavily.d.ts +4 -3
  39. package/dist/tavily.js +247 -234
  40. package/dist/tools.d.ts +76 -15
  41. package/dist/tools.js +522 -154
  42. package/dist/{types-rc8bl8Em.js → types-mq6d6YOK.js} +1 -0
  43. package/dist/{util-DFUXQX6v.js → util-LvME_uOj.js} +35 -11
  44. package/package.json +7 -2
  45. package/dist/fieldwork-JCfyw58T.d.ts +0 -113
  46. package/dist/path-DL5P8XH2.js +0 -17
  47. package/dist/util-DhYr1OS3.d.ts +0 -1
  48. package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
@@ -0,0 +1,10 @@
1
+ import { _ as isNumber } from "./util-LvME_uOj.js";
2
+ // src/path.ts
3
+ /** A JSON path, with brackets for indices and keys that are not identifiers. */
4
+ const joinPath = (segments) => {
5
+ let path = "";
6
+ for (const key of segments) if (isNumber(key)) path += `[${key}]`;
7
+ else path += /^[A-Za-z_$][\w$]*$/u.test(key) ? `${path ? "." : ""}${key}` : `[${JSON.stringify(key)}]`;
8
+ return path;
9
+ };
10
+ export { joinPath as t };
@@ -1,5 +1,6 @@
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 { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { J as Recency, Q as SearchResponse, Y as Research, a as Answer, g as Decisions, h as DecisionQuestion, l as CallOptions, ot as JsonValue } from "./errors-gMtejKHc.js";
3
+ import { t as OutputSchema } from "./schema-C9xzRkKJ.js";
3
4
  /** Settings for `perplexity()`. */
4
5
  interface PerplexityConfig {
5
6
  /** Defaults to the PERPLEXITY_API_KEY environment variable. */
@@ -54,7 +55,7 @@ interface PerplexitySearchOptions extends CallOptions, PerplexityFilters {
54
55
  /** Page-content tokens across all results. */
55
56
  maxTokens?: number;
56
57
  /** Page-content tokens for each result. */
57
- maxTokensPerPage?: number;
58
+ maxTokensPerResult?: number;
58
59
  }
59
60
  /** An effort level, or a name pinned to a version such as `fast@2026-10-16.0`. */
60
61
  type Pinned<Name extends string> = Name | `${Name}@${string}`;
@@ -131,10 +132,10 @@ interface PerplexityOperations {
131
132
  search: (query: string, options?: PerplexitySearchOptions) => Promise<SearchResponse>;
132
133
  answer: <T = unknown>(question: string, options?: PerplexityAnswerOptions<T>) => Promise<Answer<T>>;
133
134
  research: <T = unknown>(question: string, options?: PerplexityResearchOptions<T>) => Promise<Research<T>>;
134
- decide: (context: unknown, questions: Record<string, DecisionQuestion>, options?: PerplexityDecideOptions) => Promise<Decisions>;
135
+ decide: (context: JsonValue, questions: Record<string, DecisionQuestion>, options?: PerplexityDecideOptions) => Promise<Decisions>;
135
136
  }
136
137
  /**
137
- * An adapter for Perplexity: search, answer, research and decide. Pass it to `new Fieldwork({ adapter })`.
138
+ * An adapter for Perplexity: search, answer, research and decide. Pass it to `fieldwork({ adapter })`.
138
139
  *
139
140
  * Throws `Unauthorized` when neither `apiKey` nor `PERPLEXITY_API_KEY` is set.
140
141
  */
@@ -1,10 +1,10 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
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
- import * as z from "zod/mini";
1
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
2
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
3
+ import { O as withOriginal, T as sourceShape, _ as optionalId, b as optionalScalar, c as anything, d as looseObject, i as segment, l as arrayOf, r as requireKey, s as Source, t as createRawClient, u as both, v as optionalNumber, w as recordOf, x as optionalString } from "./http-CJcvTPnE.js";
4
+ import { i as startJob, r as runJob, t as jobState } from "./job-JLEpszjr.js";
5
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-CJXFAZ-x.js";
6
+ import { _ as isNumber, a as compact, c as parseJson, d as refuseTogether, m as isFlag, p as uniqueCitations, r as citationOf, s as meta, t as callSettings } from "./util-LvME_uOj.js";
7
+ import * as z$1 from "zod/mini";
8
8
  // src/adapters/perplexity/parse.ts
9
9
  /** The name this adapter reports in errors and results. */
10
10
  const provider = "perplexity";
@@ -141,12 +141,12 @@ const responseFormat = (schema) => schema ? {
141
141
  } : void 0;
142
142
  /**
143
143
  * The decision `state`. A string, object or array goes through as it is; a number
144
- * or boolean is sent as text; anything else is refused.
144
+ * or boolean is sent as text; null is refused.
145
145
  */
146
146
  const decisionState = (context) => {
147
- if (typeof context === "string" || typeof context === "object" && context) return context;
148
- if (typeof context === "number" || typeof context === "boolean") return String(context);
149
- throw invalidRequest(provider, "decide needs a context: a string, object or array");
147
+ if (isNumber(context) || isFlag(context)) return String(context);
148
+ if (context === null) throw invalidRequest(provider, "decide needs a context: a string, object or array");
149
+ return context;
150
150
  };
151
151
  /**
152
152
  * The effort, model, step and tool fields of a research run. Refuses `models`
@@ -315,7 +315,7 @@ const DecisionsResponse = looseObject({
315
315
  * flat list. Refuses more than five queries in all, and a `limit` over 20, or
316
316
  * over 50 when `searchType` is "people".
317
317
  */
318
- const search = async (raw, query, options) => {
318
+ const search = async (raw, query, options = {}) => {
319
319
  const { call, rest: o } = callSettings(options);
320
320
  const queries = [query, ...o.queries ?? []];
321
321
  if (queries.length > 5) throw invalidRequest(provider, `search takes at most 5 queries in one request, got ${queries.length}`);
@@ -327,14 +327,14 @@ const search = async (raw, query, options) => {
327
327
  country: o.country,
328
328
  max_results: o.limit,
329
329
  max_tokens: o.maxTokens,
330
- max_tokens_per_page: o.maxTokensPerPage,
330
+ max_tokens_per_page: o.maxTokensPerResult,
331
331
  query: queries.length > 1 ? queries : query,
332
332
  search_language_filter: languageCodes(o.language),
333
333
  search_type: o.searchType,
334
334
  ...filterFields(o)
335
335
  })
336
336
  });
337
- const body = z.parse(SearchResponse, response);
337
+ const body = z$1.parse(SearchResponse, response);
338
338
  return {
339
339
  meta: meta({ requestId: body.id }),
340
340
  raw: response,
@@ -352,9 +352,9 @@ const search = async (raw, query, options) => {
352
352
  * otherwise. An `incomplete` response returns its text with a warning; a failed or
353
353
  * cancelled one, or one with no text, throws.
354
354
  */
355
- const answer = async (raw, question, options) => {
355
+ const answer = async (raw, question, options = {}) => {
356
356
  const { call, rest: o } = callSettings(options);
357
- const run = z.parse(AgentRun, await raw.request("POST", "/v1/agent", {
357
+ const run = z$1.parse(AgentRun, await raw.request("POST", "/v1/agent", {
358
358
  ...call,
359
359
  body: compact({
360
360
  effort: o.effort ?? "fast",
@@ -410,11 +410,11 @@ const startResearch = async (raw, question, o, call) => await startJob(raw, "/v1
410
410
  * `partial` with that status as `stopReason`. A `failed` run, or one with no text,
411
411
  * throws `JobFailed`. The run's id is also its `continuationId`.
412
412
  */
413
- const research = async (raw, question, options) => {
413
+ const research = async (raw, question, options = {}) => {
414
414
  const { call, rest: o } = callSettings(options);
415
415
  return await runJob(provider, {
416
416
  check: async (id, request) => {
417
- const found = z.parse(AgentRun, await raw.request("GET", `/v1/agent/${segment(id)}`, request));
417
+ const found = z$1.parse(AgentRun, await raw.request("GET", `/v1/agent/${segment(id)}`, request));
418
418
  return jobState("perplexity", id, RESEARCH_STATES, {
419
419
  original: found.original,
420
420
  value: found.value.status
@@ -447,7 +447,7 @@ const research = async (raw, question, options) => {
447
447
  * `/v1/decisions`. Perplexity returns no citations, so `citations` is always empty.
448
448
  * Score answers are keyed by the caller's scale keys.
449
449
  */
450
- const decide = async (raw, context, questions, options) => {
450
+ const decide = async (raw, context, questions, options = {}) => {
451
451
  const { call, rest: o } = callSettings(options);
452
452
  const response = await raw.request("POST", "/v1/decisions", {
453
453
  ...call,
@@ -457,7 +457,7 @@ const decide = async (raw, context, questions, options) => {
457
457
  state: decisionState(context)
458
458
  }
459
459
  });
460
- const body = z.parse(DecisionsResponse, response);
460
+ const body = z$1.parse(DecisionsResponse, response);
461
461
  const answers = {};
462
462
  const unanswered = [];
463
463
  for (const [name, question] of Object.entries(questions)) {
@@ -482,7 +482,7 @@ const decide = async (raw, context, questions, options) => {
482
482
  };
483
483
  };
484
484
  /**
485
- * An adapter for Perplexity: search, answer, research and decide. Pass it to `new Fieldwork({ adapter })`.
485
+ * An adapter for Perplexity: search, answer, research and decide. Pass it to `fieldwork({ adapter })`.
486
486
  *
487
487
  * Throws `Unauthorized` when neither `apiKey` nor `PERPLEXITY_API_KEY` is set.
488
488
  */
package/dist/reducto.d.ts CHANGED
@@ -1,4 +1,5 @@
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 { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { H as ParsedDocument, l as CallOptions, x as DocumentUrl, y as DocumentInput } from "./errors-gMtejKHc.js";
2
3
  /** Settings for `reducto()`. */
3
4
  export interface ReductoConfig {
4
5
  /** Defaults to the REDUCTO_API_KEY environment variable. */
@@ -38,7 +39,7 @@ export interface ReductoOperations {
38
39
  };
39
40
  }
40
41
  /**
41
- * An adapter for Reducto: parse. Pass it to `new Fieldwork({ adapter })`.
42
+ * An adapter for Reducto: parse. Pass it to `fieldwork({ adapter })`.
42
43
  *
43
44
  * Throws `Unauthorized` when neither `apiKey` nor `REDUCTO_API_KEY` is set.
44
45
  */
package/dist/reducto.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
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
- import * as z from "zod/mini";
1
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
2
+ import { n as documentPart, o as refuseLarger, r as documentUrl } from "./document-BSCwJgBM.js";
3
+ import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
4
+ import { O as withOriginal, _ as optionalId, d as looseObject, i as segment, l as arrayOf, n as readSigned, p as optionalAnyString, r as requireKey, t as createRawClient, v as optionalNumber, x as optionalString } from "./http-CJcvTPnE.js";
5
+ import { i as startJob, r as runJob, t as jobState } from "./job-JLEpszjr.js";
6
+ import { a as compact, c as parseJson, f as requireJobId, s as meta, t as callSettings } from "./util-LvME_uOj.js";
7
+ import * as z$1 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. */
10
10
  const FractionBox = looseObject({
@@ -22,8 +22,8 @@ const Block = looseObject({
22
22
  extra: looseObject({
23
23
  cell_citations: arrayOf(looseObject({
24
24
  bbox: FractionBox,
25
- col_idx: arrayOf(z.number()),
26
- row_idx: arrayOf(z.number()),
25
+ col_idx: arrayOf(z$1.number()),
26
+ row_idx: arrayOf(z$1.number()),
27
27
  text: optionalAnyString
28
28
  })),
29
29
  word_citations: arrayOf(looseObject({
@@ -115,7 +115,7 @@ const startParse = async (raw, document, o, call) => {
115
115
  refuseLarger(provider, document, MAX_UPLOAD_MB);
116
116
  const form = new FormData();
117
117
  form.set("file", documentPart(document), document.name);
118
- const uploaded = z.parse(UploadResponse, await raw.request("POST", "/upload", {
118
+ const uploaded = z$1.parse(UploadResponse, await raw.request("POST", "/upload", {
119
119
  creates: true,
120
120
  ...call,
121
121
  form
@@ -168,14 +168,14 @@ const outputOf = async (found, options) => {
168
168
  });
169
169
  const stored = parseJson(provider, await readSigned(provider, output.url, options));
170
170
  return {
171
- output: z.parse(ParseOutput, stored),
171
+ output: z$1.parse(ParseOutput, stored),
172
172
  stored
173
173
  };
174
174
  };
175
175
  const parse = async (raw, document, options, fetchImpl) => {
176
176
  const { call, rest: o } = callSettings(options);
177
177
  return await runJob(provider, {
178
- check: async (id, request) => finished(id, z.parse(JobResponse, await raw.request("GET", `/job/${segment(id)}`, request))),
178
+ check: async (id, request) => finished(id, z$1.parse(JobResponse, await raw.request("GET", `/job/${segment(id)}`, request))),
179
179
  finish: async (found, id) => {
180
180
  const { output, stored } = await outputOf(found, {
181
181
  fetch: fetchImpl,
@@ -212,7 +212,7 @@ const parse = async (raw, document, options, fetchImpl) => {
212
212
  });
213
213
  };
214
214
  /**
215
- * An adapter for Reducto: parse. Pass it to `new Fieldwork({ adapter })`.
215
+ * An adapter for Reducto: parse. Pass it to `fieldwork({ adapter })`.
216
216
  *
217
217
  * Throws `Unauthorized` when neither `apiKey` nor `REDUCTO_API_KEY` is set.
218
218
  */
@@ -226,7 +226,7 @@ const reducto = (config = {}) => {
226
226
  });
227
227
  return defineAdapter({
228
228
  name: provider,
229
- operations: { async parse(first, options) {
229
+ operations: { async parse(first, options = {}) {
230
230
  return "resume" in first ? await parse(raw, void 0, first, config.fetch) : await parse(raw, first, options, config.fetch);
231
231
  } },
232
232
  raw
@@ -1,4 +1,4 @@
1
- import { F as JsonSchema } from "./adapter-DQrBP1tj.js";
1
+ import { M as JsonSchema, ot as JsonValue } from "./errors-gMtejKHc.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. */
@@ -65,12 +65,16 @@ interface StandardJSONSchemaOptions {
65
65
  /** Implicit support for additional vendor-specific parameters, if needed. */
66
66
  readonly libraryOptions?: LibraryOptions;
67
67
  }
68
- /** The Standard JSON Schema converter interface. */
68
+ /**
69
+ * The Standard JSON Schema converter interface. The spec types the schema a
70
+ * library writes as an object of unknown values; `jsonSchemaOf` checks it is
71
+ * an object before reading it as JSON.
72
+ */
69
73
  interface StandardJSONSchemaConverter {
70
74
  /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
71
- readonly input: (options: StandardJSONSchemaOptions) => JsonSchema;
75
+ readonly input: (options: StandardJSONSchemaOptions) => object;
72
76
  /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
73
- readonly output: (options: StandardJSONSchemaOptions) => JsonSchema;
77
+ readonly output: (options: StandardJSONSchemaOptions) => object;
74
78
  }
75
79
  /** The Standard JSON Schema properties interface. */
76
80
  interface StandardJSONSchemaProps<Input = unknown, Output = Input> extends StandardTypedProps<Input, Output> {
@@ -81,10 +85,17 @@ interface StandardJSONSchemaProps<Input = unknown, Output = Input> extends Stand
81
85
  interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
82
86
  readonly "~standard": StandardSchemaProps<Input, Output> & StandardJSONSchemaProps<Input, Output>;
83
87
  }
88
+ /**
89
+ * The output a plain JSON Schema, or no schema, leaves unchecked: the
90
+ * provider's JSON as it arrived.
91
+ */
92
+ type UncheckedOutput = JsonValue | undefined;
84
93
  /**
85
94
  * The shape of a structured output: a plain JSON Schema, or a Standard Schema
86
95
  * with JSON Schema support. A Standard Schema gives the result its type and
87
- * checks the provider's output against it; a plain JSON Schema does neither.
96
+ * checks the provider's output against it; a plain JSON Schema does neither,
97
+ * so it is accepted only where the result's type `T` admits whatever the
98
+ * provider can send unchecked (`Unchecked`), as the default `unknown` does.
88
99
  */
89
- type OutputSchema<T> = JsonSchema | StandardSchemaWithJSON<unknown, T>;
100
+ type OutputSchema<T, Unchecked = UncheckedOutput> = StandardSchemaWithJSON<unknown, T> | ([Unchecked] extends [T] ? JsonSchema : never);
90
101
  export { StandardSchemaWithJSON as n, OutputSchema as t };
@@ -1,5 +1,6 @@
1
- import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
2
- import { o as isText, r as isJsonObject, t as joinPath } from "./path-DL5P8XH2.js";
1
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
2
+ import { h as isJsonObject, v as isText } from "./util-LvME_uOj.js";
3
+ import { t as joinPath } from "./path-DO2llIdp.js";
3
4
  // src/schema-subset.ts
4
5
  const MAPS = /* @__PURE__ */ new Set([
5
6
  "properties",
@@ -87,6 +88,12 @@ const checkSchemaSubset = (schema, provider) => {
87
88
  // src/schema.ts
88
89
  const isStandard = (schema) => "~standard" in schema;
89
90
  /**
91
+ * Whether the provider's output stands as the result unchecked: there is no
92
+ * schema, or a plain JSON Schema, which `OutputSchema` admits only for a
93
+ * result type that holds the unchecked value.
94
+ */
95
+ const isUnchecked = (schema, _value) => schema === void 0 || !isStandard(schema);
96
+ /**
90
97
  * The JSON Schema to send to a provider. A plain JSON Schema passes through as
91
98
  * given; a Standard Schema is converted to `target`, without its `$schema` key,
92
99
  * because the provider's docs, not the library, say which dialect it reads.
@@ -99,6 +106,7 @@ const jsonSchemaOf = (schema, target = "draft-2020-12", subset) => {
99
106
  let result;
100
107
  try {
101
108
  const converted = schema["~standard"].jsonSchema.input({ target });
109
+ if (!isJsonObject(converted)) throw new TypeError("the library returned a JSON Schema that is not an object");
102
110
  result = Object.fromEntries(Object.entries(converted).filter(([key]) => key !== "$schema"));
103
111
  } catch (error) {
104
112
  throw new FieldworkError("InvalidRequest", `the ${schema["~standard"].vendor} schema cannot be written as ${target} JSON Schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
@@ -123,7 +131,8 @@ const describeIssues = (issues) => {
123
131
  * plain JSON Schema, or no schema, leaves it unchecked.
124
132
  */
125
133
  const checkOutput = async (schema, value, context) => {
126
- if (schema === void 0 || !isStandard(schema)) return value;
134
+ if (isUnchecked(schema, value)) return value;
135
+ if (schema === void 0 || !isStandard(schema)) throw new TypeError("a schema that is not a Standard Schema leaves output unchecked");
127
136
  const result = await schema["~standard"].validate(value);
128
137
  if (result.issues !== void 0) throw new FieldworkError("ProviderError", `${context.provider} returned output that does not match the schema: ${describeIssues(result.issues)}`, {
129
138
  cause: result.issues,
package/dist/serpapi.d.ts CHANGED
@@ -1,5 +1,5 @@
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";
2
- import "./util-DhYr1OS3.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { J as Recency, P as MatchKind, Q as SearchResponse, X as ReverseImageSearch, j as ImageSearch, l as CallOptions, r as AccountUsage } from "./errors-gMtejKHc.js";
3
3
  /** Settings for `serpapi()`. */
4
4
  interface SerpApiConfig {
5
5
  /** Defaults to the SERPAPI_API_KEY environment variable. */
@@ -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 `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 };