@howells/fieldwork-sdk 0.11.0 → 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 (47) hide show
  1. package/README.md +72 -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-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-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
  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 +66 -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 +8 -8
  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-CAPSX7yQ.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 +3 -3
  37. package/dist/serpapi.js +176 -171
  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 +351 -33
  42. package/dist/{util-DFUXQX6v.js → util-LvME_uOj.js} +35 -11
  43. package/package.json +6 -1
  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
- 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, _ 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-CJcvTPnE.js";
4
+ import { i as startJob, n as requireOutput, 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 { a as compact, o as hours, s as meta, t as callSettings } from "./util-LvME_uOj.js";
7
+ import * as z$1 from "zod/mini";
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
  };
@@ -211,10 +211,10 @@ const usageShape = {
211
211
  };
212
212
  looseObject(usageShape);
213
213
  /** An image: a bare URL, or an object with a URL and a description. Anything else, or one without a URL, reads as undefined. */
214
- const Image = z.union([z.pipe(z.string(), z.transform((url) => url === "" ? void 0 : { url })), z.pipe(looseObject({
214
+ const Image = z$1.union([z$1.pipe(z$1.string(), z$1.transform((url) => url === "" ? void 0 : { url })), z$1.pipe(looseObject({
215
215
  description: optionalString,
216
216
  url: optionalString
217
- }), z.transform((image) => image.url === void 0 ? void 0 : compact({
217
+ }), z$1.transform((image) => image.url === void 0 ? void 0 : compact({
218
218
  description: image.description,
219
219
  url: image.url
220
220
  })))]);
@@ -238,7 +238,7 @@ const SearchResponse = looseObject({
238
238
  /** A page from `/extract` or `/crawl`. `raw_content` is the page text, or passages when a query or instructions were given. */
239
239
  const PageResult = looseObject({
240
240
  favicon: optionalString,
241
- images: arrayOf(z.string()),
241
+ images: arrayOf(z$1.string()),
242
242
  raw_content: optionalString,
243
243
  url: optionalString
244
244
  });
@@ -256,7 +256,7 @@ const PagesResponse = looseObject({
256
256
  /** `/map`: the links are bare strings. */
257
257
  const MapResponse = looseObject({
258
258
  ...usageShape,
259
- results: arrayOf(z.string())
259
+ results: arrayOf(z$1.string())
260
260
  });
261
261
  /** The reply to starting a research task. */
262
262
  const ResearchStart = looseObject({ request_id: withOriginal(optionalId) });
@@ -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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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,70 @@ export declare const toolError: (cause: unknown) => {
107
102
  name: string;
108
103
  retryable: boolean;
109
104
  };
110
- export {};
105
+ /** The provider each capability uses when a call names none. */
106
+ type ProviderDefaults = Partial<Record<Capability, string>>;
107
+ /** The provider a tool uses when a call names none, by tool name. */
108
+ type ToolDefaults = Readonly<Record<string, string>>;
109
+ /** Settings for `toolCatalog`: `ToolsOptions` plus optional per-capability and per-tool defaults. */
110
+ interface ToolCatalogOptions extends ToolsOptions {
111
+ /** Default provider per capability. Never substitutes another provider when the named one is absent. */
112
+ defaults?: ProviderDefaults;
113
+ /** Default provider per tool name, overriding `defaults` for that tool only. */
114
+ toolDefaults?: ToolDefaults;
115
+ }
116
+ /**
117
+ * One tool across one or more providers. When one provider serves the tool as
118
+ * its default, `inputSchema` is that provider's plain schema; otherwise it is a
119
+ * `oneOf` keyed by `provider`, keeping each provider's options in its own
120
+ * branch.
121
+ */
122
+ interface CatalogTool {
123
+ annotations: ToolAnnotations;
124
+ capability: Capability;
125
+ /** Absent when every call must set `provider`. */
126
+ defaultProvider?: string;
127
+ description: string;
128
+ execute: (input: ToolInput, options?: CallOptions) => Promise<ToolOutput>;
129
+ inputSchema: JsonSchema;
130
+ method?: string;
131
+ name: string;
132
+ outputSchema: JsonSchema;
133
+ /** The providers that serve this tool, in client order. */
134
+ providers: string[];
135
+ }
136
+ /** A multi-provider tool list and the selector that resolves a tool by name and provider. */
137
+ interface ToolCatalog {
138
+ select: (name: string, provider?: string) => FieldworkTool;
139
+ tools: CatalogTool[];
140
+ }
141
+ /**
142
+ * Retrieval-style guidance naming only the search providers present, or an
143
+ * empty string when fewer than two providers are offered.
144
+ */
145
+ export declare const searchProviderGuidance: (providers: readonly string[]) => string;
146
+ /**
147
+ * One provider's schema branch for a multi-provider tool. `explicit` fixes and
148
+ * requires `provider`; `extraProperties` adds transport-level fields such as
149
+ * the gateway's `timeout`.
150
+ */
151
+ export declare const providerBranchSchema: (tool: FieldworkTool, explicit: boolean, extraProperties?: JsonSchema) => JsonSchema;
152
+ /** Describes a tool across its providers, including search retrieval-style guidance when several serve `search_web`. */
153
+ export declare const describeMultiProviderTool: (first: FieldworkTool, providers: readonly string[], defaultProvider: string | undefined) => string;
154
+ /**
155
+ * Collects every client's tools grouped by tool name and provider. Throws when
156
+ * two clients serve the same tool through the same provider.
157
+ */
158
+ export declare const collectToolVariants: (clients: readonly Fieldwork<AnyAdapter>[], options?: ToolsOptions) => Map<string, Map<string, FieldworkTool>>;
159
+ /**
160
+ * Builds one tool per capability name across several Fieldwork clients. Each
161
+ * provider keeps its own input schema branch and executor; no options are
162
+ * merged and no call falls back to another provider.
163
+ *
164
+ * When a tool has one provider and no conflicting default was configured, it
165
+ * uses that provider's plain schema without a `provider` field. When several
166
+ * providers serve a tool (such as `search_web` over Brave and Exa), the tool
167
+ * exposes a `provider` enum with per-provider `oneOf` branches and retrieval
168
+ * guidance in its description.
169
+ */
170
+ export declare const toolCatalog: (clients: readonly Fieldwork<AnyAdapter>[], options?: ToolCatalogOptions) => ToolCatalog;
171
+ export type { CatalogTool, FieldworkTool, ProviderDefaults, ToolAnnotations, ToolArguments, ToolCatalog, ToolCatalogOptions, ToolDefaults, ToolInput, ToolOutput, ToolsOptions };