@howells/fieldwork-sdk 0.3.1 → 0.4.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/dist/serpapi.js CHANGED
@@ -1,145 +1,139 @@
1
1
  import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
2
- import { S as requireKey, _ as strings, b as createRawClient, c as num, g as scalar, i as compact, m as refuseTogether, o as list, p as record, s as meta, t as callSettings, v as text } from "./util-YaZYZDSk.js";
3
2
  import { t as FieldworkError } from "./errors-BiIBG9zN.js";
3
+ import { C as createRawClient, E as callSettings, I as refuseTogether, T as requireKey, a as looseObject, f as optionalNumber, h as optionalString, j as meta, k as compact, m as optionalScalar, o as nonEmptyString, r as arrayOf, x as warnings } from "./parse-CxOri73y.js";
4
+ import * as z from "zod/mini";
4
5
  // src/adapters/serpapi/parse.ts
5
6
  const provider = "serpapi";
6
7
  const invalid = (message) => new FieldworkError("InvalidRequest", `${provider} ${message}`, { provider });
7
8
  const priceOf = (item) => {
8
9
  const price = compact({
9
- amount: scalar(item.extracted_price),
10
- formatted: text(item.price)
10
+ amount: item.extracted_price,
11
+ formatted: item.price
11
12
  });
12
13
  return Object.keys(price).length > 0 ? price : void 0;
13
14
  };
14
- const webResults = (response) => list(response.organic_results).flatMap((entry) => {
15
- const item = record(entry);
16
- const url = text(item.link);
17
- return url ? [compact({
18
- author: text(item.author),
19
- favicon: text(item.favicon),
20
- image: text(item.thumbnail),
15
+ const webResults = (body) => body.organic_results.flatMap((item) => {
16
+ const url = item.link;
17
+ return url === void 0 ? [] : [compact({
18
+ author: item.author,
19
+ favicon: item.favicon,
20
+ image: item.thumbnail,
21
21
  kind: "web",
22
- publishedAt: text(item.date),
23
- snippet: text(item.snippet),
24
- title: text(item.title),
22
+ publishedAt: item.date,
23
+ snippet: item.snippet,
24
+ title: item.title,
25
25
  url
26
- })] : [];
26
+ })];
27
+ });
28
+ const imageResults = (body) => body.images_results.flatMap((item) => {
29
+ const url = item.original;
30
+ return url === void 0 ? [] : [compact({
31
+ height: item.original_height,
32
+ sourceUrl: item.link,
33
+ thumbnailUrl: item.thumbnail,
34
+ title: item.title,
35
+ url,
36
+ width: item.original_width
37
+ })];
27
38
  });
28
- const newsItem = (entry) => {
29
- const item = record(entry);
30
- const url = text(item.link);
31
- if (!url) return [];
32
- const source = record(item.source);
33
- const authors = strings(source.authors);
39
+ const newsItem = (item) => {
40
+ const url = item.link;
41
+ if (url === void 0) return [];
42
+ const { authors } = item.source;
34
43
  return [compact({
35
- author: authors?.join(", "),
36
- favicon: text(source.icon),
37
- image: text(item.thumbnail),
44
+ author: authors.length > 0 ? authors.join(", ") : void 0,
45
+ favicon: item.source.icon,
46
+ image: item.thumbnail,
38
47
  kind: "news",
39
- publishedAt: text(item.iso_date) ?? text(item.date),
40
- title: text(item.title),
48
+ publishedAt: item.iso_date ?? item.date,
49
+ title: item.title,
41
50
  url
42
51
  })];
43
52
  };
44
- const newsResults = (response) => list(response.news_results).flatMap((entry) => {
45
- const item = record(entry);
46
- return [
47
- ...newsItem(item),
48
- ...newsItem(item.highlight),
49
- ...list(item.stories).flatMap((story) => newsItem(story))
50
- ];
51
- });
52
- const shoppingResults = (response) => {
53
- const categorized = list(response.categorized_shopping_results).flatMap((group) => list(record(group).shopping_results));
53
+ const newsResults = (body) => body.news_results.flatMap((item) => [
54
+ ...newsItem(item),
55
+ ...newsItem(item.highlight),
56
+ ...item.stories.flatMap((story) => newsItem(story))
57
+ ]);
58
+ const shoppingResults = (body) => {
59
+ const categorized = body.categorized_shopping_results.flatMap((group) => group.shopping_results);
54
60
  return ([
55
- list(response.shopping_results),
61
+ body.shopping_results,
56
62
  categorized,
57
- list(response.inline_shopping_results)
58
- ].find((group) => group.length > 0) ?? []).flatMap((entry) => {
59
- const item = record(entry);
60
- const url = text(item.link) ?? text(item.product_link);
61
- return url ? [compact({
62
- image: text(item.thumbnail),
63
+ body.inline_shopping_results
64
+ ].find((group) => group.length > 0) ?? []).flatMap((item) => {
65
+ const url = item.link ?? item.product_link;
66
+ return url === void 0 ? [] : [compact({
67
+ image: item.thumbnail,
63
68
  kind: "shopping",
64
69
  price: priceOf(item),
65
- rating: num(item.rating),
66
- reviewCount: num(item.reviews),
67
- snippet: text(item.snippet),
68
- title: text(item.title),
70
+ rating: item.rating,
71
+ reviewCount: item.reviews,
72
+ snippet: item.snippet,
73
+ title: item.title,
69
74
  url
70
- })] : [];
75
+ })];
71
76
  });
72
77
  };
73
78
  const mapsUrl = (item) => {
74
- const website = text(item.website);
75
- if (website) return website;
76
- const id = text(item.place_id);
77
- const title = text(item.title);
78
- return id && title ? `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(title)}&query_place_id=${encodeURIComponent(id)}` : void 0;
79
+ if (item.website !== void 0) return item.website;
80
+ const id = item.place_id;
81
+ const { title } = item;
82
+ return id === void 0 || title === void 0 ? void 0 : `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(title)}&query_place_id=${encodeURIComponent(id)}`;
79
83
  };
80
- const placeResults = (response) => {
81
- const single = record(response.place_results);
82
- const places = list(response.local_results);
83
- return (places.length === 0 && Object.keys(single).length > 0 ? [single] : places).flatMap((entry) => {
84
- const item = record(entry);
84
+ const placeResults = (body) => {
85
+ const single = body.place_results;
86
+ const places = body.local_results;
87
+ return (places.length === 0 && Object.keys(single).length > 0 ? [single] : places).flatMap((item) => {
85
88
  const url = mapsUrl(item);
86
- if (!url) return [];
87
- const coordinates = record(item.gps_coordinates);
89
+ if (url === void 0) return [];
90
+ const coordinates = item.gps_coordinates;
88
91
  const place = compact({
89
- address: text(item.address),
90
- latitude: num(coordinates.latitude),
91
- longitude: num(coordinates.longitude)
92
+ address: item.address,
93
+ latitude: coordinates.latitude,
94
+ longitude: coordinates.longitude
92
95
  });
93
96
  return [compact({
94
- image: text(item.thumbnail),
97
+ image: item.thumbnail,
95
98
  kind: "place",
96
99
  place: Object.keys(place).length > 0 ? place : void 0,
97
- rating: num(item.rating),
98
- reviewCount: num(item.reviews),
99
- snippet: text(item.description),
100
- title: text(item.title),
100
+ rating: item.rating,
101
+ reviewCount: item.reviews,
102
+ snippet: item.description,
103
+ title: item.title,
101
104
  url
102
105
  })];
103
106
  });
104
107
  };
105
- const scholarResults = (response) => list(response.organic_results).flatMap((entry) => {
106
- const item = record(entry);
107
- const url = text(item.link) ?? text(record(list(item.resources)[0]).link);
108
- return url ? [compact({
108
+ const scholarResults = (body) => body.organic_results.flatMap((item) => {
109
+ const url = item.link ?? item.resources[0]?.link;
110
+ return url === void 0 ? [] : [compact({
109
111
  kind: "scholar",
110
- snippet: text(item.snippet),
111
- title: text(item.title),
112
+ snippet: item.snippet,
113
+ title: item.title,
112
114
  url
113
- })] : [];
115
+ })];
114
116
  });
115
- const patentResults = (response) => list(response.organic_results).flatMap((entry) => {
116
- const item = record(entry);
117
- const url = text(item.patent_link);
118
- return url ? [compact({
119
- author: text(item.inventor),
120
- image: text(item.thumbnail),
117
+ const patentResults = (body) => body.organic_results.flatMap((item) => {
118
+ const url = item.patent_link;
119
+ return url === void 0 ? [] : [compact({
120
+ author: item.inventor,
121
+ image: item.thumbnail,
121
122
  kind: "patent",
122
- publishedAt: text(item.publication_date),
123
- snippet: text(item.snippet),
124
- title: text(item.title),
123
+ publishedAt: item.publication_date,
124
+ snippet: item.snippet,
125
+ title: item.title,
125
126
  url
126
- })] : [];
127
+ })];
127
128
  });
128
- const answerText = (response) => {
129
- const box = record(response.answer_box ?? list(response.answer_box_list)[0]);
130
- return text(box.answer) ?? text(scalar(box.result)) ?? text(box.snippet);
131
- };
132
- const searchMeta = (response) => meta({
133
- requestId: record(response.search_metadata).id,
134
- warnings: response.error
129
+ const answerOf = (box) => box?.answer ?? (box?.result === "" ? void 0 : box?.result) ?? box?.snippet;
130
+ const answerText = (body) => answerOf(body.answer_box ?? body.answer_box_list[0]);
131
+ const searchMeta = (body) => meta({
132
+ requestId: body.search_metadata.id,
133
+ warnings: body.error.warnings
135
134
  });
136
- const failIfError = (response) => {
137
- if (record(response.search_metadata).status === "Error") throw new FieldworkError("ProviderError", `serpapi search failed: ${text(response.error) ?? "no reason given"}`, {
138
- cause: response,
139
- provider,
140
- retryable: true
141
- });
142
- };
135
+ /** The reason a search failed, or undefined when it did not. */
136
+ const searchFailure = (body) => body.search_metadata.status === "Error" ? `serpapi search failed: ${body.error.message ?? "no reason given"}` : void 0;
143
137
  // src/adapters/serpapi/options.ts
144
138
  const RECENCY_CODE = {
145
139
  day: "d",
@@ -169,10 +163,12 @@ const bounded = (engine, value, min, max) => {
169
163
  if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) throw invalid(`${engine} limit must be a whole number from ${min} to ${max}`);
170
164
  return value;
171
165
  };
166
+ /** The code for the recency window the caller set; undefined when it names none. */
167
+ const recencyCode = (o) => Object.entries(RECENCY_CODE).find(([name]) => name === o.recency)?.[1];
172
168
  const googleTbs = (o) => {
173
169
  refuseTogether(provider, o, "recency", "publishedAfter");
174
170
  refuseTogether(provider, o, "recency", "publishedBefore");
175
- if (o.recency !== void 0) return `qdr:${RECENCY_CODE[o.recency]}`;
171
+ if (o.recency !== void 0) return `qdr:${recencyCode(o)}`;
176
172
  const after = usDate("publishedAfter", o.publishedAfter);
177
173
  const before = usDate("publishedBefore", o.publishedBefore);
178
174
  if (after === void 0 && before === void 0) return;
@@ -186,7 +182,7 @@ const duckDuckGoFilter = (o) => {
186
182
  refuseTogether(provider, o, "recency", "publishedAfter");
187
183
  refuseTogether(provider, o, "recency", "publishedBefore");
188
184
  if (o.recency === "hour") throw invalid("duckduckgo has no hour window; use day, week, month or year");
189
- if (o.recency !== void 0) return RECENCY_CODE[o.recency];
185
+ if (o.recency !== void 0) return recencyCode(o);
190
186
  if (o.publishedAfter === void 0 && o.publishedBefore === void 0) return;
191
187
  if (o.publishedAfter === void 0 || o.publishedBefore === void 0) throw invalid("duckduckgo filters a date range by both ends: pass publishedAfter and publishedBefore together");
192
188
  return `${isoDate("publishedAfter", o.publishedAfter)}..${isoDate("publishedBefore", o.publishedBefore)}`;
@@ -405,20 +401,146 @@ const onlyAllowed = (engine, options, allowed) => {
405
401
  const refused = Object.keys(options).filter((name) => options[name] !== void 0 && !allowed.includes(name));
406
402
  if (refused.length > 0) throw invalid(`${engine} does not accept ${refused.join(", ")}`);
407
403
  };
404
+ // src/adapters/serpapi/response.ts
405
+ /** SerpApi's `error` note: its text when it is a non-empty string, and the warnings it amounts to. */
406
+ const ErrorNote = z.union([z.pipe(nonEmptyString, z.transform((message) => ({
407
+ message,
408
+ warnings: [message]
409
+ }))), z.pipe(warnings, z.transform((entries) => ({
410
+ message: void 0,
411
+ warnings: entries
412
+ })))]);
413
+ /** An organic result: a web result, a scholar citation or a patent. */
414
+ const Organic = looseObject({
415
+ author: optionalString,
416
+ date: optionalString,
417
+ favicon: optionalString,
418
+ inventor: optionalString,
419
+ link: optionalString,
420
+ patent_link: optionalString,
421
+ publication_date: optionalString,
422
+ resources: arrayOf(looseObject({ link: optionalString })),
423
+ snippet: optionalString,
424
+ thumbnail: optionalString,
425
+ title: optionalString
426
+ });
427
+ const storyShape = {
428
+ date: optionalString,
429
+ iso_date: optionalString,
430
+ link: optionalString,
431
+ source: looseObject({
432
+ authors: arrayOf(z.string()),
433
+ icon: optionalString
434
+ }),
435
+ thumbnail: optionalString,
436
+ title: optionalString
437
+ };
438
+ const Story = looseObject(storyShape);
439
+ /** A news result: a story, or a group with a `highlight` and `stories`. */
440
+ const NewsResult = looseObject({
441
+ ...storyShape,
442
+ highlight: Story,
443
+ stories: arrayOf(Story)
444
+ });
445
+ const ShoppingItem = looseObject({
446
+ extracted_price: optionalScalar,
447
+ link: optionalString,
448
+ price: optionalString,
449
+ product_link: optionalString,
450
+ rating: optionalNumber,
451
+ reviews: optionalNumber,
452
+ snippet: optionalString,
453
+ thumbnail: optionalString,
454
+ title: optionalString
455
+ });
456
+ const Place = looseObject({
457
+ address: optionalString,
458
+ description: optionalString,
459
+ gps_coordinates: looseObject({
460
+ latitude: optionalNumber,
461
+ longitude: optionalNumber
462
+ }),
463
+ place_id: optionalString,
464
+ rating: optionalNumber,
465
+ reviews: optionalNumber,
466
+ thumbnail: optionalString,
467
+ title: optionalString,
468
+ website: optionalString
469
+ });
470
+ /** An answer box. An absent or null one reads as undefined; any other value that is not an object has every field absent. */
471
+ const AnswerBox = looseObject({
472
+ answer: optionalString,
473
+ result: optionalScalar,
474
+ snippet: optionalString
475
+ });
476
+ const ImageItem = looseObject({
477
+ link: optionalString,
478
+ original: optionalString,
479
+ original_height: optionalNumber,
480
+ original_width: optionalNumber,
481
+ thumbnail: optionalString,
482
+ title: optionalString
483
+ });
484
+ /** A `/search` response for any engine; each engine reads only its own sections. */
485
+ const SearchResponse = looseObject({
486
+ answer_box: z.union([z.pipe(z.optional(z.null()), z.transform(() => void 0)), AnswerBox]),
487
+ answer_box_list: arrayOf(AnswerBox),
488
+ categorized_shopping_results: arrayOf(looseObject({ shopping_results: arrayOf(ShoppingItem) })),
489
+ error: ErrorNote,
490
+ images_results: arrayOf(ImageItem),
491
+ inline_shopping_results: arrayOf(ShoppingItem),
492
+ local_results: arrayOf(Place),
493
+ news_results: arrayOf(NewsResult),
494
+ organic_results: arrayOf(Organic),
495
+ place_results: Place,
496
+ search_metadata: looseObject({
497
+ id: optionalScalar,
498
+ status: optionalString
499
+ }),
500
+ shopping_results: arrayOf(ShoppingItem)
501
+ });
502
+ /** `/account`: the plan and its usage. */
503
+ const AccountResponse = looseObject({
504
+ last_hour_searches: optionalNumber,
505
+ plan_renewal_date: optionalString,
506
+ plan_searches_left: optionalNumber,
507
+ searches_per_month: optionalNumber,
508
+ this_hour_searches: optionalNumber,
509
+ this_month_usage: optionalNumber
510
+ });
408
511
  // src/adapters/serpapi.ts
409
512
  const serpapi = (config = {}) => {
410
513
  const key = requireKey(provider, config.apiKey, "SERPAPI_API_KEY");
411
- const authenticated = (async (input, init) => {
412
- const url = new URL(input);
514
+ const authenticated = async (input, init) => {
515
+ const url = new URL(input instanceof Request ? input.url : input);
413
516
  url.searchParams.set("api_key", key);
414
517
  return await (config.fetch ?? globalThis.fetch)(url, init);
415
- });
518
+ };
416
519
  const raw = createRawClient({
417
520
  baseUrl: config.baseUrl ?? "https://serpapi.com",
418
521
  fetch: authenticated,
419
522
  headers: {},
420
- provider
523
+ provider,
524
+ retries: config.retries
421
525
  });
526
+ /** One `/search` call: the response as received, and its parsed body. A failed search throws. */
527
+ const searchCall = async (call, query) => {
528
+ const response = await raw.request("GET", "/search", {
529
+ ...call,
530
+ query
531
+ });
532
+ const body = z.parse(SearchResponse, response);
533
+ const failure = searchFailure(body);
534
+ if (failure !== void 0) throw new FieldworkError("ProviderError", failure, {
535
+ cause: response,
536
+ provider,
537
+ retryable: true
538
+ });
539
+ return {
540
+ body,
541
+ response
542
+ };
543
+ };
422
544
  return defineAdapter({
423
545
  name: provider,
424
546
  operations: {
@@ -427,45 +549,29 @@ const serpapi = (config = {}) => {
427
549
  onlyAllowed("google_images", o, IMAGE_OPTIONS);
428
550
  refuseTogether(provider, o, "recency", "publishedAfter");
429
551
  refuseTogether(provider, o, "recency", "publishedBefore");
430
- const response = record(await raw.request("GET", "/search", {
431
- ...call,
432
- query: compact({
433
- device: o.device,
434
- end_date: compactDate("publishedBefore", o.publishedBefore),
435
- engine: "google_images",
436
- gl: googleCountry(o.country),
437
- hl: o.language,
438
- ijn: o.page,
439
- image_color: o.color,
440
- image_type: o.imageType,
441
- imgar: o.aspectRatio,
442
- imgsz: o.size,
443
- licenses: o.license,
444
- location: o.location,
445
- no_cache: o.noCache === true ? true : void 0,
446
- period_unit: o.recency === void 0 ? void 0 : RECENCY_CODE[o.recency],
447
- q: query,
448
- safe: o.safe,
449
- start_date: compactDate("publishedAfter", o.publishedAfter)
450
- })
552
+ const { body, response } = await searchCall(call, compact({
553
+ device: o.device,
554
+ end_date: compactDate("publishedBefore", o.publishedBefore),
555
+ engine: "google_images",
556
+ gl: googleCountry(o.country),
557
+ hl: o.language,
558
+ ijn: o.page,
559
+ image_color: o.color,
560
+ image_type: o.imageType,
561
+ imgar: o.aspectRatio,
562
+ imgsz: o.size,
563
+ licenses: o.license,
564
+ location: o.location,
565
+ no_cache: o.noCache === true ? true : void 0,
566
+ period_unit: o.recency === void 0 ? void 0 : RECENCY_CODE[o.recency],
567
+ q: query,
568
+ safe: o.safe,
569
+ start_date: compactDate("publishedAfter", o.publishedAfter)
451
570
  }));
452
- failIfError(response);
453
- const results = list(response.images_results).flatMap((entry) => {
454
- const item = record(entry);
455
- const url = text(item.original);
456
- return url ? [compact({
457
- height: num(item.original_height),
458
- sourceUrl: text(item.link),
459
- thumbnailUrl: text(item.thumbnail),
460
- title: text(item.title),
461
- url,
462
- width: num(item.original_width)
463
- })] : [];
464
- });
465
571
  return compact({
466
- meta: searchMeta(response),
572
+ meta: searchMeta(body),
467
573
  raw: response,
468
- results
574
+ results: imageResults(body)
469
575
  });
470
576
  },
471
577
  async search(query, options) {
@@ -475,39 +581,35 @@ const serpapi = (config = {}) => {
475
581
  if (!Object.hasOwn(ENGINES, engine)) throw invalid(`does not offer the engine "${engine}"`);
476
582
  const spec = ENGINES[engine];
477
583
  onlyAllowed(engine, o, spec.allowed);
478
- const response = record(await raw.request("GET", "/search", {
479
- ...call,
480
- query: compact({
481
- engine,
482
- q: query,
483
- ...spec.params(o),
484
- no_cache: o.noCache === true ? true : void 0
485
- })
584
+ const { body, response } = await searchCall(call, compact({
585
+ engine,
586
+ q: query,
587
+ ...spec.params(o),
588
+ no_cache: o.noCache === true ? true : void 0
486
589
  }));
487
- failIfError(response);
488
590
  return compact({
489
- answer: engine === "google" ? answerText(response) : void 0,
490
- meta: searchMeta(response),
591
+ answer: engine === "google" ? answerText(body) : void 0,
592
+ meta: searchMeta(body),
491
593
  raw: response,
492
- results: spec.results(response)
594
+ results: spec.results(body)
493
595
  });
494
596
  },
495
597
  async usage(options) {
496
598
  const { call } = callSettings(options);
497
- const response = record(await raw.request("GET", "/account", call));
498
- const safe = Object.fromEntries(Object.entries(response).filter(([name]) => name !== "api_key"));
599
+ const response = await raw.request("GET", "/account", call);
600
+ const body = z.parse(AccountResponse, response);
601
+ const fields = z.safeParse(z.record(z.string(), z.unknown()), response);
602
+ const safe = fields.success ? Object.fromEntries(Object.entries(fields.data).filter(([name]) => name !== "api_key")) : response;
499
603
  const breakdown = {};
500
- for (const name of ["this_hour_searches", "last_hour_searches"]) {
501
- const value = num(response[name]);
502
- if (value !== void 0) breakdown[name] = value;
503
- }
604
+ if (body.this_hour_searches !== void 0) breakdown.this_hour_searches = body.this_hour_searches;
605
+ if (body.last_hour_searches !== void 0) breakdown.last_hour_searches = body.last_hour_searches;
504
606
  return compact({
505
607
  breakdown: Object.keys(breakdown).length > 0 ? breakdown : void 0,
506
- limit: num(response.searches_per_month),
507
- periodEnd: text(response.plan_renewal_date),
608
+ limit: body.searches_per_month,
609
+ periodEnd: body.plan_renewal_date,
508
610
  raw: safe,
509
- remaining: num(response.plan_searches_left),
510
- used: num(response.this_month_usage)
611
+ remaining: body.plan_searches_left,
612
+ used: body.this_month_usage
511
613
  });
512
614
  }
513
615
  },
package/dist/tavily.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { A as JsonSchema, G as Research, I as Page, L as PageBatch, W as Recency, X as SiteMap, a as RawClient, f as CallOptions, g as Crawl, k as ImageSearch, l as Answer, q as SearchResponse, s as AccountUsage, t as Adapter } from "./adapter-DGehHCMo.js";
1
+ import { G as Research, I as Page, L as PageBatch, W as Recency, X as SiteMap, a as RawClient, f as CallOptions, g as Crawl, k as ImageSearch, l as Answer, q as SearchResponse, s as AccountUsage, t as Adapter } from "./adapter-CDY8qczv.js";
2
+ import { t as OutputSchema } from "./schema-EZlBkY5B.js";
2
3
  interface TavilyConfig {
3
4
  /** Defaults to the TAVILY_API_KEY environment variable. */
4
5
  apiKey?: string;
@@ -6,6 +7,8 @@ interface TavilyConfig {
6
7
  projectId?: string;
7
8
  baseUrl?: string;
8
9
  fetch?: typeof fetch;
10
+ /** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
11
+ retries?: number;
9
12
  }
10
13
  type TavilySearchDepth = "ultra-fast" | "fast" | "basic" | "advanced";
11
14
  interface TavilySearchOptions extends CallOptions {
@@ -122,9 +125,9 @@ interface TavilyResearchFile {
122
125
  /** The file's text, or its bytes. Sent base64-encoded. */
123
126
  data: string | Uint8Array;
124
127
  }
125
- interface TavilyResearchOptions extends CallOptions {
128
+ interface TavilyResearchOptions<T = unknown> extends CallOptions {
126
129
  /** Tavily accepts object, string, integer, number and array types only, and each property needs a description. */
127
- schema?: JsonSchema;
130
+ schema?: OutputSchema<T>;
128
131
  model?: "mini" | "pro" | "auto";
129
132
  citationFormat?: "numbered" | "mla" | "apa" | "chicago";
130
133
  outputLength?: "short" | "standard" | "long";
@@ -143,15 +146,15 @@ interface TavilyResearchOptions extends CallOptions {
143
146
  resume?: string;
144
147
  }
145
148
  interface TavilyOperations {
146
- search(query: string, options?: TavilySearchOptions): Promise<SearchResponse>;
147
- images(query: string, options?: TavilyImagesOptions): Promise<ImageSearch>;
148
- read(url: string, options?: TavilyReadOptions): Promise<Page>;
149
- readMany(urls: string[], options?: TavilyReadManyOptions): Promise<PageBatch>;
150
- map(url: string, options?: TavilyMapOptions): Promise<SiteMap>;
151
- crawl(url: string, options?: TavilyCrawlOptions): Promise<Crawl>;
152
- answer(question: string, options?: TavilyAnswerOptions): Promise<Answer<unknown>>;
153
- research<T = unknown>(question: string, options?: TavilyResearchOptions): Promise<Research<T>>;
154
- usage(options?: CallOptions): Promise<AccountUsage>;
149
+ search: (query: string, options?: TavilySearchOptions) => Promise<SearchResponse>;
150
+ images: (query: string, options?: TavilyImagesOptions) => Promise<ImageSearch>;
151
+ read: (url: string, options?: TavilyReadOptions) => Promise<Page>;
152
+ readMany: (urls: string[], options?: TavilyReadManyOptions) => Promise<PageBatch>;
153
+ map: (url: string, options?: TavilyMapOptions) => Promise<SiteMap>;
154
+ crawl: (url: string, options?: TavilyCrawlOptions) => Promise<Crawl>;
155
+ answer: (question: string, options?: TavilyAnswerOptions) => Promise<Answer<unknown>>;
156
+ research: <T = unknown>(question: string, options?: TavilyResearchOptions<T>) => Promise<Research<T>>;
157
+ usage: (options?: CallOptions) => Promise<AccountUsage>;
155
158
  }
156
159
  export declare const tavily: (config?: TavilyConfig) => Adapter<"tavily", TavilyOperations, RawClient>;
157
160
  export type { TavilyAnswerOptions, TavilyConfig, TavilyCrawlOptions, TavilyImagesOptions, TavilyMapOptions, TavilyOperations, TavilyReadManyOptions, TavilyReadOptions, TavilyResearchFile, TavilyResearchOptions, TavilySearchDepth, TavilySearchOptions };