@howells/fieldwork-sdk 0.11.0 → 0.13.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 (47) hide show
  1. package/README.md +73 -15
  2. package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
  3. package/dist/adapter-J2yatZJ0.d.ts +73 -0
  4. package/dist/best-DiKYwLdC.js +1436 -0
  5. package/dist/brave.d.ts +7 -6
  6. package/dist/brave.js +175 -168
  7. package/dist/browserbase.d.ts +4 -3
  8. package/dist/browserbase.js +182 -167
  9. package/dist/{document-DMIUCoDA.js → document-x9fWsQ1W.js} +2 -2
  10. package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
  11. package/dist/{adapter-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
  12. package/dist/exa.d.ts +18 -11
  13. package/dist/exa.js +301 -267
  14. package/dist/fieldwork-D7npPoUf.d.ts +35 -0
  15. package/dist/firecrawl.d.ts +4 -3
  16. package/dist/firecrawl.js +432 -399
  17. package/dist/{parse-Q7H4mrnO.js → http-Bg0h3D-t.js} +222 -224
  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 +66 -82
  22. package/dist/{job-DnavRq_s.js → job-BsrOrrO1.js} +7 -7
  23. package/dist/kernel.d.ts +20 -2
  24. package/dist/kernel.js +58 -12
  25. package/dist/llamaparse.d.ts +3 -2
  26. package/dist/llamaparse.js +8 -8
  27. package/dist/parallel.d.ts +10 -10
  28. package/dist/parallel.js +432 -391
  29. package/dist/path-tDCyAKK9.js +10 -0
  30. package/dist/perplexity.d.ts +6 -5
  31. package/dist/perplexity.js +16 -16
  32. package/dist/reducto.d.ts +3 -2
  33. package/dist/reducto.js +8 -8
  34. package/dist/{schema--iU4AXSM.js → schema-Bfd2E8u2.js} +12 -3
  35. package/dist/{schema-CAPSX7yQ.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
  36. package/dist/serpapi.d.ts +3 -3
  37. package/dist/serpapi.js +170 -165
  38. package/dist/tavily.d.ts +4 -3
  39. package/dist/tavily.js +242 -229
  40. package/dist/tools.d.ts +79 -15
  41. package/dist/tools.js +431 -77
  42. package/dist/{util-DFUXQX6v.js → util-BOqd71Om.js} +44 -12
  43. package/package.json +11 -6
  44. package/dist/fieldwork-BrfoehvG.d.ts +0 -113
  45. package/dist/path-DL5P8XH2.js +0 -17
  46. package/dist/util-DhYr1OS3.d.ts +0 -1
  47. package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
package/dist/tavily.js CHANGED
@@ -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, m as optionalScalar, n as anything, r as arrayOf } from "./parse-Q7H4mrnO.js";
4
- import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-DnavRq_s.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
6
- import { a as compact, o as hours, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
7
1
  import * as z from "zod/mini";
2
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
3
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
4
+ import { O as withOriginal, _ as optionalId, b as optionalScalar, c as anything, d as looseObject, i as segment, l as arrayOf, r as requireKey, t as createRawClient, v as optionalNumber, x as optionalString } from "./http-Bg0h3D-t.js";
5
+ import { i as startJob, n as requireOutput, r as runJob, t as jobState } from "./job-BsrOrrO1.js";
6
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-Bfd2E8u2.js";
7
+ import { a as compact, o as hours, s as meta, t as callSettings } from "./util-BOqd71Om.js";
8
8
  // src/adapters/tavily/countries.ts
9
9
  /** Tavily's country names, by ISO 3166-1 alpha-2 code. */
10
10
  const COUNTRIES = new Map(`
@@ -194,7 +194,7 @@ const researchFiles = (input) => {
194
194
  const files = input?.map((file) => {
195
195
  if (!RESEARCH_FILE.test(file.name)) throw invalidRequest(provider, `reads .txt, .md and .json files, not ${file.name}`);
196
196
  return {
197
- data: base64(typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data),
197
+ data: base64(file.data instanceof Uint8Array ? file.data : new TextEncoder().encode(file.data)),
198
198
  name: file.name,
199
199
  type: "base64"
200
200
  };
@@ -290,8 +290,235 @@ const RESEARCH_STATES = {
290
290
  failed: ["failed"],
291
291
  running: ["pending", "in_progress"]
292
292
  };
293
+ /** `search`, `images` and `answer`: one search request each. */
294
+ const searching = (raw) => ({
295
+ async answer(question, options = {}) {
296
+ const { call, rest } = callSettings(options);
297
+ const { answerDepth, ...o } = rest;
298
+ const response = await raw.request("POST", "/search", {
299
+ ...call,
300
+ body: {
301
+ ...searchBody(question, o),
302
+ include_answer: answerDepth ?? "basic"
303
+ }
304
+ });
305
+ const body = z.parse(SearchResponse, response);
306
+ const { answer } = body;
307
+ if (answer === void 0) throw new FieldworkError("ProviderError", "tavily returned no answer", {
308
+ cause: response,
309
+ provider
310
+ });
311
+ const sources = searchResults(body).filter((result) => result.url !== "").map((result) => compact({
312
+ excerpts: chunks(result.snippet),
313
+ title: result.title,
314
+ url: result.url
315
+ }));
316
+ return compact({
317
+ answer,
318
+ citations: sources,
319
+ meta: responseMeta(body),
320
+ raw: response
321
+ });
322
+ },
323
+ async images(query, options = {}) {
324
+ const { call, rest: o } = callSettings(options);
325
+ const response = await raw.request("POST", "/search", {
326
+ ...call,
327
+ body: searchBody(query, {
328
+ excludeDomains: o.excludeDomains,
329
+ imageDescriptions: o.descriptions ?? true,
330
+ includeDomains: o.includeDomains,
331
+ includeImages: true,
332
+ safeSearch: o.safeSearch,
333
+ searchDepth: o.searchDepth,
334
+ topic: o.topic
335
+ })
336
+ });
337
+ const body = z.parse(SearchResponse, response);
338
+ return compact({
339
+ meta: responseMeta(body),
340
+ raw: response,
341
+ results: imageResults(body.images) ?? []
342
+ });
343
+ },
344
+ async search(query, options = {}) {
345
+ const { call, rest: o } = callSettings(options);
346
+ const response = await raw.request("POST", "/search", {
347
+ ...call,
348
+ body: searchBody(query, o)
349
+ });
350
+ const body = z.parse(SearchResponse, response);
351
+ return compact({
352
+ answer: body.answer,
353
+ images: imageResults(body.images),
354
+ meta: responseMeta(body),
355
+ raw: response,
356
+ results: searchResults(body)
357
+ });
358
+ }
359
+ });
360
+ /** `read`, `readMany`, `map` and `crawl`: pages fetched from given URLs. */
361
+ const reading = (raw) => ({
362
+ async crawl(url, options = {}) {
363
+ const { call, rest: o } = callSettings(options);
364
+ if (o.chunksPerSource !== void 0 && o.instructions === void 0) throw invalidRequest(provider, "chunksPerSource needs instructions");
365
+ const response = await raw.request("POST", "/crawl", {
366
+ ...call,
367
+ body: compact({
368
+ url,
369
+ ...traversal(o),
370
+ chunks_per_source: o.chunksPerSource,
371
+ extract_depth: o.extractDepth,
372
+ format: o.format,
373
+ include_favicon: o.favicon,
374
+ include_images: o.includeImages
375
+ })
376
+ });
377
+ const body = z.parse(PagesResponse, response);
378
+ return compact({
379
+ meta: responseMeta(body),
380
+ pages: body.results.map((entry) => page(entry, o.instructions !== void 0)),
381
+ raw: response
382
+ });
383
+ },
384
+ async map(url, options = {}) {
385
+ const { call, rest: o } = callSettings(options);
386
+ const response = await raw.request("POST", "/map", {
387
+ ...call,
388
+ body: {
389
+ url,
390
+ ...traversal(o)
391
+ }
392
+ });
393
+ const body = z.parse(MapResponse, response);
394
+ return compact({
395
+ links: body.results.map((link) => ({ url: link })),
396
+ meta: responseMeta(body),
397
+ raw: response
398
+ });
399
+ },
400
+ async read(url, options = {}) {
401
+ const { call, rest: o } = callSettings(options);
402
+ const response = await raw.request("POST", "/extract", {
403
+ ...call,
404
+ body: extractBody([url], o)
405
+ });
406
+ const body = z.parse(PagesResponse, response);
407
+ const [result] = body.results;
408
+ if (result?.value.url === void 0) {
409
+ const [failure] = failures(body.failed_results);
410
+ const reason = failure?.error ?? "no content returned";
411
+ throw new FieldworkError(/\b404\b|not found/iu.test(reason) ? "NotFound" : "ProviderError", `tavily could not read ${url}: ${reason}`, {
412
+ cause: response,
413
+ provider
414
+ });
415
+ }
416
+ return compact({
417
+ ...page(result, o.query !== void 0),
418
+ meta: responseMeta(body),
419
+ raw: response
420
+ });
421
+ },
422
+ async readMany(urls, options = {}) {
423
+ const { call, rest: o } = callSettings(options);
424
+ if (urls.length === 0 || urls.length > 20) throw invalidRequest(provider, "reads 1 to 20 URLs in one call");
425
+ const response = await raw.request("POST", "/extract", {
426
+ ...call,
427
+ body: extractBody(urls, o)
428
+ });
429
+ const body = z.parse(PagesResponse, response);
430
+ return compact({
431
+ failed: failures(body.failed_results),
432
+ meta: responseMeta(body),
433
+ pages: body.results.map((entry) => page(entry, o.query !== void 0)),
434
+ raw: response
435
+ });
436
+ }
437
+ });
438
+ /** `research`: a run Tavily works through, polled to its result. */
439
+ const researching = (raw) => ({ async research(question, options = {}) {
440
+ const { call, rest: o } = callSettings(options);
441
+ const files = researchFiles(o.files);
442
+ return await runJob(provider, {
443
+ check: async (id, request) => {
444
+ const current = await raw.request("GET", `/research/${segment(id)}`, {
445
+ ...request,
446
+ query: { include_usage: true }
447
+ });
448
+ const parsed = z.parse(ResearchRun, current);
449
+ const state = jobState(provider, id, RESEARCH_STATES, {
450
+ original: current,
451
+ value: parsed.status
452
+ });
453
+ if (state === "failed") throw new FieldworkError("JobFailed", `tavily research ${id} failed`, {
454
+ cause: current,
455
+ provider
456
+ });
457
+ return state === "done" ? {
458
+ body: parsed,
459
+ response: current
460
+ } : void 0;
461
+ },
462
+ finish: async ({ body: run, response }, id) => {
463
+ const content = requireOutput(provider, id, {
464
+ original: response,
465
+ value: run.content
466
+ });
467
+ return compact({
468
+ id,
469
+ meta: responseMeta(run),
470
+ output: await checkOutput(o.schema, content, { provider }),
471
+ raw: response,
472
+ sources: run.sources.flatMap((source) => source.url === void 0 ? [] : [compact({
473
+ title: source.title,
474
+ url: source.url
475
+ })]),
476
+ status: "completed"
477
+ });
478
+ },
479
+ start: async () => await startJob(raw, "/research", {
480
+ ...call,
481
+ body: compact({
482
+ citation_format: o.citationFormat,
483
+ exclude_domains: o.excludeDomains,
484
+ files,
485
+ include_domains: o.includeDomains,
486
+ input: question,
487
+ model: o.model,
488
+ output_length: o.outputLength,
489
+ output_schema: o.schema === void 0 ? void 0 : jsonSchemaOf(o.schema, "draft-2020-12", "tavily"),
490
+ stream: false
491
+ })
492
+ }, ResearchStart, (reply) => reply.request_id)
493
+ }, {
494
+ ...call,
495
+ interval: o.interval,
496
+ resume: o.resume
497
+ });
498
+ } });
499
+ /** `usage`: the account's and the key's credit use. */
500
+ const accounting = (raw) => ({ async usage(options = {}) {
501
+ const { call } = callSettings(options);
502
+ const response = await raw.request("GET", "/usage", call);
503
+ const { account, key } = z.parse(UsageResponse, response);
504
+ const breakdown = Object.fromEntries(Object.entries({
505
+ crawl: account.crawl_usage,
506
+ extract: account.extract_usage,
507
+ keyTotal: key.usage,
508
+ map: account.map_usage,
509
+ paygo: account.paygo_usage,
510
+ research: account.research_usage,
511
+ search: account.search_usage
512
+ }).filter((entry) => entry[1] !== void 0));
513
+ return compact({
514
+ breakdown: Object.keys(breakdown).length > 0 ? breakdown : void 0,
515
+ limit: account.plan_limit,
516
+ raw: response,
517
+ used: account.plan_usage
518
+ });
519
+ } });
293
520
  /**
294
- * An adapter for Tavily: search, images, read, readMany, map, crawl, answer, research and usage. Pass it to `new Fieldwork({ adapter })`.
521
+ * An adapter for Tavily: search, images, read, readMany, map, crawl, answer, research and usage. Pass it to `fieldwork({ adapter })`.
295
522
  *
296
523
  * Throws `Unauthorized` when neither `apiKey` nor `TAVILY_API_KEY` is set.
297
524
  */
@@ -306,229 +533,15 @@ const tavily = (config = {}) => {
306
533
  provider,
307
534
  retries: config.retries
308
535
  });
536
+ const operations = {
537
+ ...accounting(raw),
538
+ ...reading(raw),
539
+ ...researching(raw),
540
+ ...searching(raw)
541
+ };
309
542
  return defineAdapter({
310
543
  name: provider,
311
- operations: {
312
- async answer(question, options) {
313
- const { call, rest } = callSettings(options);
314
- const { answerDepth, ...o } = rest;
315
- const response = await raw.request("POST", "/search", {
316
- ...call,
317
- body: {
318
- ...searchBody(question, o),
319
- include_answer: answerDepth ?? "basic"
320
- }
321
- });
322
- const body = z.parse(SearchResponse, response);
323
- const { answer } = body;
324
- if (answer === void 0) throw new FieldworkError("ProviderError", "tavily returned no answer", {
325
- cause: response,
326
- provider
327
- });
328
- const sources = searchResults(body).filter((result) => result.url !== "").map((result) => compact({
329
- excerpts: chunks(result.snippet),
330
- title: result.title,
331
- url: result.url
332
- }));
333
- return compact({
334
- answer,
335
- citations: sources,
336
- meta: responseMeta(body),
337
- raw: response
338
- });
339
- },
340
- async crawl(url, options) {
341
- const { call, rest: o } = callSettings(options);
342
- if (o.chunksPerSource !== void 0 && o.instructions === void 0) throw invalidRequest(provider, "chunksPerSource needs instructions");
343
- const response = await raw.request("POST", "/crawl", {
344
- ...call,
345
- body: compact({
346
- url,
347
- ...traversal(o),
348
- chunks_per_source: o.chunksPerSource,
349
- extract_depth: o.extractDepth,
350
- format: o.format,
351
- include_images: o.includeImages,
352
- include_favicon: o.favicon
353
- })
354
- });
355
- const body = z.parse(PagesResponse, response);
356
- return compact({
357
- meta: responseMeta(body),
358
- pages: body.results.map((entry) => page(entry, o.instructions !== void 0)),
359
- raw: response
360
- });
361
- },
362
- async images(query, options) {
363
- const { call, rest: o } = callSettings(options);
364
- const response = await raw.request("POST", "/search", {
365
- ...call,
366
- body: searchBody(query, {
367
- excludeDomains: o.excludeDomains,
368
- imageDescriptions: o.descriptions ?? true,
369
- includeDomains: o.includeDomains,
370
- includeImages: true,
371
- safeSearch: o.safeSearch,
372
- searchDepth: o.searchDepth,
373
- topic: o.topic
374
- })
375
- });
376
- const body = z.parse(SearchResponse, response);
377
- return compact({
378
- meta: responseMeta(body),
379
- raw: response,
380
- results: imageResults(body.images) ?? []
381
- });
382
- },
383
- async map(url, options) {
384
- const { call, rest: o } = callSettings(options);
385
- const response = await raw.request("POST", "/map", {
386
- ...call,
387
- body: {
388
- url,
389
- ...traversal(o)
390
- }
391
- });
392
- const body = z.parse(MapResponse, response);
393
- return compact({
394
- links: body.results.map((link) => ({ url: link })),
395
- meta: responseMeta(body),
396
- raw: response
397
- });
398
- },
399
- async read(url, options) {
400
- const { call, rest: o } = callSettings(options);
401
- const response = await raw.request("POST", "/extract", {
402
- ...call,
403
- body: extractBody([url], o)
404
- });
405
- const body = z.parse(PagesResponse, response);
406
- const [result] = body.results;
407
- if (result?.value.url === void 0) {
408
- const [failure] = failures(body.failed_results);
409
- const reason = failure?.error ?? "no content returned";
410
- throw new FieldworkError(/\b404\b|not found/iu.test(reason) ? "NotFound" : "ProviderError", `tavily could not read ${url}: ${reason}`, {
411
- cause: response,
412
- provider
413
- });
414
- }
415
- return compact({
416
- ...page(result, o.query !== void 0),
417
- meta: responseMeta(body),
418
- raw: response
419
- });
420
- },
421
- async readMany(urls, options) {
422
- const { call, rest: o } = callSettings(options);
423
- if (urls.length === 0 || urls.length > 20) throw invalidRequest(provider, "reads 1 to 20 URLs in one call");
424
- const response = await raw.request("POST", "/extract", {
425
- ...call,
426
- body: extractBody(urls, o)
427
- });
428
- const body = z.parse(PagesResponse, response);
429
- return compact({
430
- failed: failures(body.failed_results),
431
- meta: responseMeta(body),
432
- pages: body.results.map((entry) => page(entry, o.query !== void 0)),
433
- raw: response
434
- });
435
- },
436
- async research(question, options) {
437
- const { call, rest: o } = callSettings(options);
438
- const files = researchFiles(o.files);
439
- return await runJob(provider, {
440
- check: async (id, request) => {
441
- const current = await raw.request("GET", `/research/${segment(id)}`, {
442
- ...request,
443
- query: { include_usage: true }
444
- });
445
- const parsed = z.parse(ResearchRun, current);
446
- const state = jobState(provider, id, RESEARCH_STATES, {
447
- original: current,
448
- value: parsed.status
449
- });
450
- if (state === "failed") throw new FieldworkError("JobFailed", `tavily research ${id} failed`, {
451
- cause: current,
452
- provider
453
- });
454
- return state === "done" ? {
455
- body: parsed,
456
- response: current
457
- } : void 0;
458
- },
459
- finish: async ({ body: run, response }, id) => {
460
- const content = requireOutput(provider, id, {
461
- original: response,
462
- value: run.content
463
- });
464
- return compact({
465
- id,
466
- meta: responseMeta(run),
467
- output: await checkOutput(o.schema, content, { provider }),
468
- raw: response,
469
- sources: run.sources.flatMap((source) => source.url === void 0 ? [] : [compact({
470
- title: source.title,
471
- url: source.url
472
- })]),
473
- status: "completed"
474
- });
475
- },
476
- start: async () => await startJob(raw, "/research", {
477
- ...call,
478
- body: compact({
479
- citation_format: o.citationFormat,
480
- exclude_domains: o.excludeDomains,
481
- files,
482
- include_domains: o.includeDomains,
483
- input: question,
484
- model: o.model,
485
- output_length: o.outputLength,
486
- output_schema: o.schema === void 0 ? void 0 : jsonSchemaOf(o.schema, "draft-2020-12", "tavily"),
487
- stream: false
488
- })
489
- }, ResearchStart, (reply) => reply.request_id)
490
- }, {
491
- ...call,
492
- interval: o.interval,
493
- resume: o.resume
494
- });
495
- },
496
- async search(query, options) {
497
- const { call, rest: o } = callSettings(options);
498
- const response = await raw.request("POST", "/search", {
499
- ...call,
500
- body: searchBody(query, o)
501
- });
502
- const body = z.parse(SearchResponse, response);
503
- return compact({
504
- answer: body.answer,
505
- images: imageResults(body.images),
506
- meta: responseMeta(body),
507
- raw: response,
508
- results: searchResults(body)
509
- });
510
- },
511
- async usage(options) {
512
- const { call } = callSettings(options);
513
- const response = await raw.request("GET", "/usage", call);
514
- const { account, key } = z.parse(UsageResponse, response);
515
- const breakdown = Object.fromEntries(Object.entries({
516
- crawl: account.crawl_usage,
517
- extract: account.extract_usage,
518
- keyTotal: key.usage,
519
- map: account.map_usage,
520
- paygo: account.paygo_usage,
521
- research: account.research_usage,
522
- search: account.search_usage
523
- }).filter((entry) => entry[1] !== void 0));
524
- return compact({
525
- breakdown: Object.keys(breakdown).length > 0 ? breakdown : void 0,
526
- limit: account.plan_limit,
527
- raw: response,
528
- used: account.plan_usage
529
- });
530
- }
531
- },
544
+ operations,
532
545
  raw
533
546
  });
534
547
  };
package/dist/tools.d.ts CHANGED
@@ -1,22 +1,17 @@
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
- /** Any JSON value. */
4
- type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
5
- /** A JSON object. A key may be undefined, which reads as absent and is not serialized. */
6
- interface JsonObject {
7
- [key: string]: JsonValue | undefined;
8
- }
1
+ import { M as JsonSchema, at as JsonObject, l as CallOptions, n as FieldworkErrorCode, ot as JsonValue, u as Capability } from "./errors-gMtejKHc.js";
2
+ import { n as AnyAdapter } from "./adapter-J2yatZJ0.js";
3
+ import { t as Fieldwork } from "./fieldwork-D7npPoUf.js";
9
4
  export declare const DEFAULT_MAX_CHARACTERS = 20000;
10
5
  /** Checks configured and per-call budgets against the same optional cap. */
11
6
  export declare const checkMaxCharacters: (value: JsonValue | undefined, limit?: number) => number;
12
7
  /** What a model sends a tool: a parsed JSON value, which must be an object. */
13
- export type ToolInput = JsonValue;
8
+ type ToolInput = JsonValue;
14
9
  /** The arguments a tool accepts, once they are known to be an object. */
15
- export type ToolArguments = JsonObject;
10
+ type ToolArguments = JsonObject;
16
11
  /** What a tool returns: a JSON object, shaped for a model. */
17
- export type ToolOutput = JsonObject;
12
+ type ToolOutput = JsonObject;
18
13
  /** MCP tool annotations, which clients use to decide when to ask before calling. */
19
- export interface ToolAnnotations {
14
+ interface ToolAnnotations {
20
15
  title: string;
21
16
  /** True when the tool changes nothing outside Fieldwork. */
22
17
  readOnlyHint: boolean;
@@ -28,7 +23,7 @@ export interface ToolAnnotations {
28
23
  openWorldHint: boolean;
29
24
  }
30
25
  /** One agent tool, ready to register with an MCP server or a model's tool API. */
31
- export interface FieldworkTool {
26
+ interface FieldworkTool {
32
27
  /** A verb_noun name, such as `search_web`. */
33
28
  name: string;
34
29
  /** The capability this tool calls on the instance. */
@@ -60,7 +55,7 @@ export interface FieldworkTool {
60
55
  */
61
56
  export declare const EXCLUDED_BY_DEFAULT: readonly Capability[];
62
57
  /** Which tools `toolsFor` makes, and how much text each result may return. */
63
- export interface ToolsOptions {
58
+ interface ToolsOptions {
64
59
  /**
65
60
  * Capabilities to make tools for. Defaults to every capability the instance
66
61
  * supports except those in `EXCLUDED_BY_DEFAULT`.
@@ -107,4 +102,73 @@ export declare const toolError: (cause: unknown) => {
107
102
  name: string;
108
103
  retryable: boolean;
109
104
  };
110
- export {};
105
+ /**
106
+ * Default provider choice: one provider name (strict — never substitutes
107
+ * another if absent) or an ordered preference list fixed at catalog build time
108
+ * (first listed provider that serves the tool wins).
109
+ */
110
+ type DefaultProvider = string | readonly string[];
111
+ /** The provider (or ordered preference list) each capability uses when a call names none. */
112
+ type ProviderDefaults = Partial<Record<Capability, DefaultProvider>>;
113
+ /** The provider (or ordered preference list) a tool uses when a call names none, by tool name. */
114
+ type ToolDefaults = Readonly<Record<string, DefaultProvider>>;
115
+ /** Settings for `toolCatalog`: `ToolsOptions` plus defaults and optional transport schema extensions. */
116
+ interface ToolCatalogOptions extends ToolsOptions {
117
+ /** Default provider (or ordered preference list) per capability. */
118
+ defaults?: ProviderDefaults;
119
+ /** Default provider (or ordered preference list) per tool name, overriding `defaults` for that tool only. */
120
+ toolDefaults?: ToolDefaults;
121
+ /**
122
+ * Extra transport-level properties (such as the gateway's `timeout`) to add
123
+ * to the advertised schema of each branch and the top-level object. Callers
124
+ * are responsible for stripping and validating them before calling `execute`.
125
+ */
126
+ extraProperties?: JsonSchema;
127
+ /**
128
+ * `"multi"` (default): a single-provider tool with a default keeps its plain
129
+ * schema (`single: true`, no `provider` field). `"always"` (used by the HTTP
130
+ * gateway): every tool advertises the `provider`-switched `oneOf` schema and
131
+ * requires an explicit `defaults`/`toolDefaults` entry to have a default.
132
+ */
133
+ providerSelection?: "multi" | "always";
134
+ }
135
+ /**
136
+ * One tool across one or more providers. When `single` is true, `inputSchema`
137
+ * is that provider's plain schema without a `provider` field; otherwise it is a
138
+ * `oneOf` keyed by `provider`, keeping each provider's options in its own
139
+ * branch.
140
+ */
141
+ interface CatalogTool {
142
+ annotations: ToolAnnotations;
143
+ capability: Capability;
144
+ /** Absent when every call must set `provider`. */
145
+ defaultProvider?: string;
146
+ description: string;
147
+ execute: (input: ToolInput, options?: CallOptions) => Promise<ToolOutput>;
148
+ inputSchema: JsonSchema;
149
+ method?: string;
150
+ name: string;
151
+ outputSchema: JsonSchema;
152
+ /** The providers that serve this tool, in client order. */
153
+ providers: string[];
154
+ /** True when one provider serves the tool as its default and `inputSchema` omits `provider`. */
155
+ single: boolean;
156
+ }
157
+ /** A multi-provider tool list and the selector that resolves a tool by name and provider. */
158
+ interface ToolCatalog {
159
+ select: (name: string, provider?: string) => FieldworkTool;
160
+ tools: CatalogTool[];
161
+ }
162
+ /**
163
+ * Builds one tool per capability name across several Fieldwork clients. Each
164
+ * provider keeps its own input schema branch and executor; no options are
165
+ * merged and no call falls back to another provider after an error.
166
+ *
167
+ * Under the default `providerSelection: "multi"`, a single-provider tool with
168
+ * a default keeps its plain schema (`single: true`, no `provider` field). When
169
+ * several providers serve a tool (such as `search_web` over Brave and Exa), the
170
+ * tool exposes a `provider` enum with per-provider `oneOf` branches and
171
+ * query-style guidance in `search_web`'s description.
172
+ */
173
+ export declare const toolCatalog: (clients: readonly Fieldwork<AnyAdapter>[], options?: ToolCatalogOptions) => ToolCatalog;
174
+ export type { CatalogTool, DefaultProvider, FieldworkTool, ProviderDefaults, ToolAnnotations, ToolArguments, ToolCatalog, ToolCatalogOptions, ToolDefaults, ToolInput, ToolOutput, ToolsOptions };