@howells/fieldwork-sdk 0.2.0 → 0.3.1

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/tavily.js CHANGED
@@ -1,98 +1,265 @@
1
- import { t as defineAdapter } from "./adapter-D-6-GFhJ.js";
2
- import { t as FieldworkError } from "./errors-pzPMh82H.js";
3
- import { a as list, c as record, d as strings, f as text, g as requireKey, h as poll, i as compact, l as requireId, m as createRawClient, o as num, r as citations, t as callSettings } from "./util-DgcIZI2K.js";
4
- // src/adapters/tavily.ts
5
- function traversal(o) {
1
+ import { t as defineAdapter } from "./adapter-CEAQuT7F.js";
2
+ import { t as FieldworkError } from "./errors-BiIBG9zN.js";
3
+ import { S as requireKey, _ as strings, a as hours, b as createRawClient, c as num, h as requireId, i as compact, o as list, p as record, s as meta, t as callSettings, v as text, x as poll } from "./util-YaZYZDSk.js";
4
+ // src/adapters/tavily/countries.ts
5
+ /** Tavily's country names, by ISO 3166-1 alpha-2 code. */
6
+ const COUNTRIES = new Map(`
7
+ AD andorra,AE united arab emirates,AF afghanistan,AL albania,
8
+ AM armenia,AO angola,AR argentina,AT austria,AU australia,
9
+ AZ azerbaijan,BA bosnia and herzegovina,BB barbados,BD bangladesh,
10
+ BE belgium,BF burkina faso,BG bulgaria,BH bahrain,BI burundi,BJ benin,
11
+ BN brunei,BO bolivia,BR brazil,BS bahamas,BT bhutan,BW botswana,
12
+ BY belarus,BZ belize,CA canada,CF central african republic,CG congo,
13
+ CH switzerland,CL chile,CM cameroon,CN china,CO colombia,
14
+ CR costa rica,CU cuba,CV cape verde,CY cyprus,CZ czech republic,
15
+ DE germany,DJ djibouti,DK denmark,DO dominican republic,DZ algeria,
16
+ EC ecuador,EE estonia,EG egypt,ER eritrea,ES spain,ET ethiopia,
17
+ FI finland,FJ fiji,FR france,GA gabon,GB united kingdom,GE georgia,
18
+ GH ghana,GM gambia,GN guinea,GQ equatorial guinea,GR greece,
19
+ GT guatemala,HN honduras,HR croatia,HT haiti,HU hungary,ID indonesia,
20
+ IE ireland,IL israel,IN india,IQ iraq,IR iran,IS iceland,IT italy,
21
+ JM jamaica,JO jordan,JP japan,KE kenya,KG kyrgyzstan,KH cambodia,
22
+ KM comoros,KP north korea,KR south korea,KW kuwait,KZ kazakhstan,
23
+ LB lebanon,LI liechtenstein,LK sri lanka,LR liberia,LS lesotho,
24
+ LT lithuania,LU luxembourg,LV latvia,LY libya,MA morocco,MC monaco,
25
+ MD moldova,ME montenegro,MG madagascar,MK north macedonia,ML mali,
26
+ MM myanmar,MN mongolia,MR mauritania,MT malta,MU mauritius,
27
+ MV maldives,MW malawi,MX mexico,MY malaysia,MZ mozambique,NA namibia,
28
+ NE niger,NG nigeria,NI nicaragua,NL netherlands,NO norway,NP nepal,
29
+ NZ new zealand,OM oman,PA panama,PE peru,PG papua new guinea,
30
+ PH philippines,PK pakistan,PL poland,PT portugal,PY paraguay,QA qatar,
31
+ RO romania,RS serbia,RU russia,RW rwanda,SA saudi arabia,SD sudan,
32
+ SE sweden,SG singapore,SI slovenia,SK slovakia,SN senegal,SO somalia,
33
+ SS south sudan,SV el salvador,SY syria,TD chad,TG togo,TH thailand,
34
+ TJ tajikistan,TM turkmenistan,TN tunisia,TR turkey,
35
+ TT trinidad and tobago,TW taiwan,TZ tanzania,UA ukraine,UG uganda,
36
+ US united states,UY uruguay,UZ uzbekistan,VE venezuela,VN vietnam,
37
+ YE yemen,ZA south africa,ZM zambia,ZW zimbabwe
38
+ `.split(",").map((entry) => entry.trim()).map((entry) => [entry.slice(0, 2), entry.slice(3)]));
39
+ // src/adapters/tavily/parse.ts
40
+ const RESEARCH_FILE = /\.(?:txt|md|json)$/iu;
41
+ const invalid = (message) => new FieldworkError("InvalidRequest", message, { provider: "tavily" });
42
+ const chunks = (value) => {
43
+ const content = text(value);
44
+ if (!content) return;
45
+ const parts = content.split(/\s*\[\.\.\.\]\s*/u).map((part) => part.trim()).filter((part) => part !== "");
46
+ return parts.length > 0 ? parts : void 0;
47
+ };
48
+ const countryName = (code, topic) => {
49
+ if (topic !== void 0 && topic !== "general") throw invalid(`tavily country only works with topic "general", not "${topic}"`);
50
+ const name = COUNTRIES.get(code.toUpperCase());
51
+ if (!name) throw invalid(`tavily has no country for "${code}"; pass an ISO 3166-1 alpha-2 code from its supported list`);
52
+ return name;
53
+ };
54
+ const imageResults = (value) => {
55
+ const items = list(value).map((item) => {
56
+ if (typeof item === "string") return item === "" ? void 0 : { url: item };
57
+ const image = record(item);
58
+ const url = text(image.url);
59
+ return url ? compact({
60
+ description: text(image.description),
61
+ url
62
+ }) : void 0;
63
+ }).filter((item) => item !== void 0);
64
+ return items.length > 0 ? items : void 0;
65
+ };
66
+ const responseMeta = (response) => meta({
67
+ credits: record(response.usage).credits,
68
+ requestId: response.request_id,
69
+ units: { responseTimeSeconds: response.response_time }
70
+ });
71
+ const checkSearch = (o) => {
72
+ if (o.includeDomainsMode !== void 0 && !o.includeDomains?.length) throw invalid("tavily includeDomainsMode needs includeDomains");
73
+ if (o.filterByLanguage && o.language === void 0) throw invalid("tavily filterByLanguage needs language");
74
+ if (o.safeSearch && (o.searchDepth === "fast" || o.searchDepth === "ultra-fast")) throw invalid(`tavily safeSearch is not available with searchDepth "${o.searchDepth}"`);
75
+ if (o.chunksPerSource !== void 0 && o.searchDepth === "ultra-fast") throw invalid("tavily chunksPerSource is not available with searchDepth \"ultra-fast\"");
76
+ if (o.imageDescriptions && !o.includeImages) throw invalid("tavily imageDescriptions needs includeImages");
77
+ const maxAgeHours = hours(o.maxAge);
78
+ if (maxAgeHours !== void 0 && maxAgeHours > 720) throw invalid("tavily keeps cached copies for at most 30 days (2,592,000 seconds)");
79
+ return maxAgeHours;
80
+ };
81
+ const rawContent = (content) => {
82
+ if (content === true) return "markdown";
83
+ return content === false ? void 0 : content;
84
+ };
85
+ const searchBody = (query, o) => {
86
+ const maxAgeHours = checkSearch(o);
87
+ const dated = o.recency !== void 0 || o.publishedAfter !== void 0 || o.publishedBefore !== void 0;
6
88
  return compact({
7
- instructions: o.instructions,
8
- max_depth: o.maxDepth,
9
- max_breadth: o.maxBreadth,
10
- limit: o.limit,
11
- select_paths: o.selectPaths,
12
- exclude_paths: o.excludePaths,
13
- select_domains: o.selectDomains,
89
+ auto_parameters: o.autoParameters,
90
+ chunks_per_source: o.chunksPerSource,
91
+ country: o.country === void 0 ? void 0 : countryName(o.country, o.topic),
92
+ end_date: o.publishedBefore,
93
+ exact_match: o.exactMatch,
14
94
  exclude_domains: o.excludeDomains,
15
- allow_external: o.allowExternal
95
+ filter_by_language: o.filterByLanguage,
96
+ filter_by_published_date: o.filterByPublishedDate,
97
+ include_domains: o.includeDomains,
98
+ include_domains_mode: o.includeDomainsMode,
99
+ include_favicon: o.favicon,
100
+ include_image_descriptions: o.imageDescriptions,
101
+ include_images: o.includeImages,
102
+ include_published_date: dated ? true : void 0,
103
+ include_raw_content: rawContent(o.content),
104
+ include_usage: true,
105
+ language: o.language,
106
+ max_age_hours: maxAgeHours,
107
+ max_results: o.limit,
108
+ query,
109
+ safe_search: o.safeSearch,
110
+ search_depth: o.searchDepth,
111
+ start_date: o.publishedAfter,
112
+ time_range: o.recency,
113
+ topic: o.topic
114
+ });
115
+ };
116
+ const searchResults = (response) => list(response.results).map((item) => {
117
+ const result = record(item);
118
+ return compact({
119
+ content: text(result.raw_content),
120
+ favicon: text(result.favicon),
121
+ publishedAt: text(result.published_date),
122
+ score: num(result.score),
123
+ snippet: text(result.content),
124
+ title: text(result.title),
125
+ url: text(result.url) ?? ""
16
126
  });
17
- }
18
- function tavily(config = {}) {
127
+ });
128
+ const failures = (response) => list(response.failed_results).flatMap((item) => {
129
+ const failure = record(item);
130
+ const url = text(failure.url);
131
+ return url ? [{
132
+ error: text(failure.error) ?? "no content returned",
133
+ url
134
+ }] : [];
135
+ });
136
+ const page = (item, query) => {
137
+ const result = record(item);
138
+ const passages = query ? chunks(result.raw_content) : void 0;
139
+ return compact({
140
+ excerpts: passages,
141
+ favicon: text(result.favicon),
142
+ images: strings(result.images),
143
+ markdown: query ? void 0 : text(result.raw_content),
144
+ raw: item,
145
+ url: text(result.url) ?? ""
146
+ });
147
+ };
148
+ const extractBody = (urls, o) => {
149
+ if (o.chunksPerSource !== void 0 && o.query === void 0) throw invalid("tavily chunksPerSource needs query");
150
+ return compact({
151
+ chunks_per_source: o.chunksPerSource,
152
+ extract_depth: o.extractDepth,
153
+ format: o.format,
154
+ include_favicon: o.favicon,
155
+ include_images: o.includeImages,
156
+ include_usage: true,
157
+ query: o.query,
158
+ timeout: o.serverTimeout,
159
+ urls
160
+ });
161
+ };
162
+ const traversal = (o) => compact({
163
+ allow_external: o.allowExternal,
164
+ exclude_domains: o.excludeDomainPatterns,
165
+ exclude_paths: o.excludePathPatterns,
166
+ include_usage: true,
167
+ instructions: o.instructions,
168
+ limit: o.limit,
169
+ max_breadth: o.maxBreadth,
170
+ max_depth: o.maxDepth,
171
+ select_domains: o.selectDomainPatterns,
172
+ select_paths: o.selectPathPatterns,
173
+ timeout: o.serverTimeout
174
+ });
175
+ const base64 = (bytes) => {
176
+ let binary = "";
177
+ for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCodePoint(...bytes.subarray(index, index + 32768));
178
+ return btoa(binary);
179
+ };
180
+ // src/adapters/tavily.ts
181
+ const tavily = (config = {}) => {
19
182
  const provider = "tavily";
20
183
  const raw = createRawClient({
21
- provider,
22
184
  baseUrl: config.baseUrl ?? "https://api.tavily.com",
23
- headers: { authorization: `Bearer ${requireKey(provider, config.apiKey, "TAVILY_API_KEY")}` },
24
- fetch: config.fetch
185
+ fetch: config.fetch,
186
+ headers: compact({
187
+ authorization: `Bearer ${requireKey(provider, config.apiKey, "TAVILY_API_KEY")}`,
188
+ "x-project-id": config.projectId
189
+ }),
190
+ provider
25
191
  });
26
192
  return defineAdapter({
27
193
  name: provider,
28
194
  operations: {
29
- async search(query, options) {
30
- const { call, rest: o } = callSettings(options);
195
+ async answer(question, options) {
196
+ const { call, rest } = callSettings(options);
197
+ const { answerDepth, ...o } = rest;
31
198
  const response = record(await raw.request("POST", "/search", {
32
199
  ...call,
33
- body: compact({
34
- query,
35
- max_results: o.limit,
36
- search_depth: o.depth,
37
- topic: o.topic,
38
- time_range: o.timeRange,
39
- start_date: o.publishedAfter,
40
- end_date: o.publishedBefore,
41
- include_domains: o.includeDomains,
42
- exclude_domains: o.excludeDomains,
43
- include_domains_mode: o.includeDomainsMode,
44
- country: o.country,
45
- include_answer: o.answer,
46
- include_raw_content: o.content ? "markdown" : void 0,
47
- exact_match: o.exactMatch,
48
- max_age_hours: o.maxAgeHours
49
- })
200
+ body: {
201
+ ...searchBody(question, o),
202
+ include_answer: answerDepth ?? "basic"
203
+ }
204
+ }));
205
+ const answer = text(response.answer);
206
+ if (answer === void 0) throw new FieldworkError("ProviderError", "tavily returned no answer", {
207
+ cause: response,
208
+ provider
209
+ });
210
+ const sources = searchResults(response).filter((result) => result.url !== "").map((result) => compact({
211
+ excerpts: chunks(result.snippet),
212
+ title: result.title,
213
+ url: result.url
50
214
  }));
51
215
  return compact({
52
- results: list(response.results).map((item) => {
53
- const result = record(item);
54
- return compact({
55
- url: text(result.url) ?? "",
56
- title: text(result.title),
57
- snippet: text(result.content),
58
- content: text(result.raw_content),
59
- publishedAt: text(result.published_date),
60
- score: num(result.score)
61
- });
62
- }),
63
- answer: text(response.answer),
216
+ answer,
217
+ citations: sources,
218
+ meta: responseMeta(response),
64
219
  raw: response
65
220
  });
66
221
  },
67
- async read(url, options) {
222
+ async crawl(url, options) {
68
223
  const { call, rest: o } = callSettings(options);
69
- const response = record(await raw.request("POST", "/extract", {
224
+ if (o.chunksPerSource !== void 0 && o.instructions === void 0) throw invalid("tavily chunksPerSource needs instructions");
225
+ const response = record(await raw.request("POST", "/crawl", {
70
226
  ...call,
71
227
  body: compact({
72
- urls: [url],
73
- extract_depth: o.depth,
74
- query: o.query,
228
+ url,
229
+ ...traversal(o),
75
230
  chunks_per_source: o.chunksPerSource,
231
+ extract_depth: o.extractDepth,
76
232
  format: o.format,
77
- include_images: o.includeImages
233
+ include_images: o.includeImages,
234
+ include_favicon: o.favicon
78
235
  })
79
236
  }));
80
- const result = record(list(response.results)[0]);
81
- if (!result.url) {
82
- const failure = record(list(response.failed_results)[0]);
83
- throw new FieldworkError("ProviderError", `tavily could not read ${url}: ${text(failure.error) ?? "no content returned"}`, {
84
- provider,
85
- cause: response
86
- });
87
- }
88
237
  return compact({
89
- url: text(result.url) ?? "",
90
- title: text(result.title),
91
- markdown: text(result.raw_content),
92
- images: strings(result.images),
238
+ meta: responseMeta(response),
239
+ pages: list(response.results).map((item) => page(item, o.instructions !== void 0)),
93
240
  raw: response
94
241
  });
95
242
  },
243
+ async images(query, options) {
244
+ const { call, rest: o } = callSettings(options);
245
+ const response = record(await raw.request("POST", "/search", {
246
+ ...call,
247
+ body: searchBody(query, {
248
+ excludeDomains: o.excludeDomains,
249
+ imageDescriptions: o.descriptions ?? true,
250
+ includeDomains: o.includeDomains,
251
+ includeImages: true,
252
+ safeSearch: o.safeSearch,
253
+ searchDepth: o.searchDepth,
254
+ topic: o.topic
255
+ })
256
+ }));
257
+ return compact({
258
+ meta: responseMeta(response),
259
+ raw: response,
260
+ results: imageResults(response.images) ?? []
261
+ });
262
+ },
96
263
  async map(url, options) {
97
264
  const { call, rest: o } = callSettings(options);
98
265
  const response = record(await raw.request("POST", "/map", {
@@ -102,71 +269,149 @@ function tavily(config = {}) {
102
269
  ...traversal(o)
103
270
  }
104
271
  }));
105
- return {
272
+ return compact({
106
273
  links: list(response.results).flatMap((item) => typeof item === "string" ? [{ url: item }] : []),
274
+ meta: responseMeta(response),
107
275
  raw: response
108
- };
276
+ });
109
277
  },
110
- async crawl(url, options) {
278
+ async read(url, options) {
111
279
  const { call, rest: o } = callSettings(options);
112
- const response = record(await raw.request("POST", "/crawl", {
280
+ const response = record(await raw.request("POST", "/extract", {
113
281
  ...call,
114
- body: compact({
115
- url,
116
- ...traversal(o),
117
- extract_depth: o.extractDepth,
118
- format: o.format,
119
- include_images: o.includeImages
120
- })
282
+ body: extractBody([url], o)
121
283
  }));
122
- return {
123
- pages: list(response.results).map((item) => {
124
- const page = record(item);
125
- return compact({
126
- url: text(page.url) ?? "",
127
- markdown: text(page.raw_content),
128
- images: strings(page.images),
129
- raw: item
130
- });
131
- }),
284
+ const [result] = list(response.results);
285
+ if (!text(record(result).url)) {
286
+ const [failure] = failures(response);
287
+ const reason = failure?.error ?? "no content returned";
288
+ throw new FieldworkError(/\b404\b|not found/iu.test(reason) ? "NotFound" : "ProviderError", `tavily could not read ${url}: ${reason}`, {
289
+ cause: response,
290
+ provider
291
+ });
292
+ }
293
+ return compact({
294
+ ...page(result, o.query !== void 0),
295
+ meta: responseMeta(response),
296
+ raw: response
297
+ });
298
+ },
299
+ async readMany(urls, options) {
300
+ const { call, rest: o } = callSettings(options);
301
+ if (urls.length === 0 || urls.length > 20) throw invalid("tavily reads 1 to 20 URLs in one call");
302
+ const response = record(await raw.request("POST", "/extract", {
303
+ ...call,
304
+ body: extractBody(urls, o)
305
+ }));
306
+ return compact({
307
+ failed: failures(response),
308
+ meta: responseMeta(response),
309
+ pages: list(response.results).map((item) => page(item, o.query !== void 0)),
132
310
  raw: response
133
- };
311
+ });
134
312
  },
135
313
  async research(question, options) {
136
314
  const { call, rest: o } = callSettings(options);
315
+ const files = o.files?.map((file) => {
316
+ if (!RESEARCH_FILE.test(file.name)) throw invalid(`tavily reads .txt, .md and .json files, not ${file.name}`);
317
+ return {
318
+ data: base64(typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data),
319
+ name: file.name,
320
+ type: "base64"
321
+ };
322
+ });
323
+ if (files && files.length > 5) throw invalid("tavily research takes up to 5 files");
137
324
  const id = o.resume ?? requireId(provider, record(await raw.request("POST", "/research", {
138
325
  ...call,
139
326
  body: compact({
327
+ citation_format: o.citationFormat,
328
+ exclude_domains: o.excludeDomains,
329
+ files,
330
+ include_domains: o.includeDomains,
140
331
  input: question,
141
332
  model: o.model,
142
- output_schema: o.schema,
143
- citation_format: o.citationFormat,
144
333
  output_length: o.outputLength,
145
- include_domains: o.includeDomains,
146
- exclude_domains: o.excludeDomains,
334
+ output_schema: o.schema,
147
335
  stream: false
148
336
  })
149
337
  })).request_id);
150
338
  const run = await poll(provider, id, async () => {
151
- const current = record(await raw.request("GET", `/research/${id}`, { signal: call.signal }));
339
+ const current = record(await raw.request("GET", `/research/${id}`, {
340
+ query: { include_usage: true },
341
+ signal: call.signal
342
+ }));
152
343
  if (current.status === "failed") throw new FieldworkError("JobFailed", `tavily research ${id} failed`, {
153
- provider,
154
- cause: current
344
+ cause: current,
345
+ provider
155
346
  });
156
347
  return current.status === "completed" ? current : void 0;
157
348
  }, {
158
349
  ...call,
159
350
  interval: o.interval
160
351
  });
161
- return {
352
+ const { content } = run;
353
+ if (content === void 0 || content === null || content === "") throw new FieldworkError("JobFailed", `tavily research ${id} finished without output`, {
354
+ cause: run,
355
+ jobId: id,
356
+ provider
357
+ });
358
+ return compact({
162
359
  id,
163
- output: run.content,
164
- sources: citations(run.sources),
165
- raw: run
166
- };
360
+ meta: meta({
361
+ credits: record(run.usage).credits,
362
+ requestId: run.request_id,
363
+ units: { responseTimeSeconds: run.response_time }
364
+ }),
365
+ output: content,
366
+ raw: run,
367
+ sources: list(run.sources).flatMap((item) => {
368
+ const source = record(item);
369
+ const url = text(source.url);
370
+ return url ? [compact({
371
+ title: text(source.title),
372
+ url
373
+ })] : [];
374
+ }),
375
+ status: "completed"
376
+ });
377
+ },
378
+ async search(query, options) {
379
+ const { call, rest: o } = callSettings(options);
380
+ const response = record(await raw.request("POST", "/search", {
381
+ ...call,
382
+ body: searchBody(query, o)
383
+ }));
384
+ return compact({
385
+ answer: text(response.answer),
386
+ images: imageResults(response.images),
387
+ meta: responseMeta(response),
388
+ raw: response,
389
+ results: searchResults(response)
390
+ });
391
+ },
392
+ async usage(options) {
393
+ const { call } = callSettings(options);
394
+ const response = record(await raw.request("GET", "/usage", call));
395
+ const key = record(response.key);
396
+ const account = record(response.account);
397
+ const breakdown = Object.fromEntries(Object.entries({
398
+ crawl: account.crawl_usage,
399
+ extract: account.extract_usage,
400
+ keyTotal: key.usage,
401
+ map: account.map_usage,
402
+ paygo: account.paygo_usage,
403
+ research: account.research_usage,
404
+ search: account.search_usage
405
+ }).filter((entry) => num(entry[1]) !== void 0));
406
+ return compact({
407
+ breakdown: Object.keys(breakdown).length > 0 ? breakdown : void 0,
408
+ limit: num(account.plan_limit),
409
+ raw: response,
410
+ used: num(account.plan_usage)
411
+ });
167
412
  }
168
413
  },
169
414
  raw
170
415
  });
171
- }
416
+ };
172
417
  export { tavily };
package/dist/tools.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-nPzWEelg.js";
2
- import { _ as JsonSchema, l as CallOptions, n as AnyAdapter, u as Capability } from "./adapter-C_kRm6TT.js";
1
+ import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-B3x3cxDJ.js";
2
+ import { A as JsonSchema, f as CallOptions, n as AnyAdapter, p as Capability } from "./adapter-DGehHCMo.js";
3
+ /**
4
+ * The JSON values that cross the tool boundary: what a model sends in, what a
5
+ * tool sends back. Tools take and return these types, and the guards below are
6
+ * the one place untyped data becomes one of them.
7
+ */
8
+ type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
9
+ interface JsonObject {
10
+ [key: string]: JsonValue | undefined;
11
+ }
3
12
  /**
4
13
  * Tool definitions for agents, built from a Fieldwork instance. Each tool's
5
14
  * input schema lists only the options its provider supports, so a model is
@@ -7,6 +16,12 @@ import { _ as JsonSchema, l as CallOptions, n as AnyAdapter, u as Capability } f
7
16
  * JSON Schema with MCP-style annotations, so they work with the AI SDK, MCP
8
17
  * servers and any framework that accepts JSON Schema tools.
9
18
  */
19
+ /** What a model sends a tool: a parsed JSON value, which must be an object. */
20
+ export type ToolInput = JsonValue;
21
+ /** The arguments a tool accepts, once they are known to be an object. */
22
+ export type ToolArguments = JsonObject;
23
+ /** What a tool returns: a JSON object, shaped for a model. */
24
+ export type ToolOutput = JsonObject;
10
25
  export interface ToolAnnotations {
11
26
  title: string;
12
27
  /** True when the tool changes nothing outside Fieldwork. */
@@ -22,6 +37,8 @@ export interface FieldworkTool {
22
37
  /** A verb_noun name, such as `search_web`. */
23
38
  name: string;
24
39
  capability: Capability;
40
+ /** For a group capability, the method this tool calls, such as `create` for `monitor`. */
41
+ method?: string;
25
42
  /** The provider that serves this tool, such as "firecrawl". */
26
43
  provider: string;
27
44
  /** What the tool does, when to use it and when to use another tool. */
@@ -37,15 +54,25 @@ export interface FieldworkTool {
37
54
  * with long text cut to the `maxCharacters` budget. Throws a
38
55
  * `FieldworkError`; bad input is `InvalidRequest`.
39
56
  */
40
- execute(input: unknown, options?: CallOptions): Promise<unknown>;
57
+ execute: (input: ToolInput, options?: CallOptions) => Promise<ToolOutput>;
41
58
  }
59
+ /**
60
+ * Capabilities that start remote browsers or create lasting or billed
61
+ * resources. `toolsFor` leaves them out unless they are named in `allow` or
62
+ * `capabilities`.
63
+ */
64
+ export declare const EXCLUDED_BY_DEFAULT: readonly Capability[];
42
65
  export interface ToolsOptions {
43
66
  /**
44
67
  * Capabilities to make tools for. Defaults to every capability the instance
45
- * supports except `act`, which runs code in a browser and is included only
46
- * when named here.
68
+ * supports except those in `EXCLUDED_BY_DEFAULT`.
47
69
  */
48
70
  capabilities?: Capability[];
71
+ /**
72
+ * Capabilities left out by default to include as well, such as `act`,
73
+ * `browser` and `monitor`.
74
+ */
75
+ allow?: Capability[];
49
76
  /**
50
77
  * The most characters of long text (page Markdown, reports, document text)
51
78
  * one result returns, shared across its fields. Text of 500 characters or
@@ -53,24 +80,25 @@ export interface ToolsOptions {
53
80
  */
54
81
  maxCharacters?: number;
55
82
  }
56
- /** Makes one tool per capability the instance supports. */
57
- export declare function toolsFor(web: Fieldwork<AnyAdapter>, options?: ToolsOptions): FieldworkTool[];
83
+ /** Makes one tool per capability, or per method of a group, the instance supports. */
84
+ export declare const toolsFor: (web: Fieldwork<AnyAdapter>, options?: ToolsOptions) => FieldworkTool[];
58
85
  /**
59
86
  * An error as a model or an MCP client should see it: the code, the message
60
87
  * and what to do next, without the provider's response.
61
88
  */
62
- export declare function toolError(error: unknown): {
63
- name: string;
89
+ export declare const toolError: (cause: unknown) => {
64
90
  code: FieldworkErrorCode;
91
+ jobId: string | undefined;
65
92
  message: string;
93
+ name: string;
66
94
  provider: string | undefined;
67
- status: number | undefined;
68
- retryable: boolean;
69
95
  retryAfter: number | undefined;
70
- jobId: string | undefined;
96
+ retryable: boolean;
97
+ status: number | undefined;
71
98
  } | {
72
- name: string;
73
99
  code: "ProviderError";
74
100
  message: string;
101
+ name: string;
75
102
  retryable: boolean;
76
- };
103
+ };
104
+ export {};