@howells/fieldwork-sdk 0.10.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -16
- package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
- package/dist/adapter-J2yatZJ0.d.ts +73 -0
- package/dist/best-CO9liYDa.js +1436 -0
- package/dist/brave.d.ts +7 -6
- package/dist/brave.js +180 -173
- package/dist/browserbase.d.ts +4 -3
- package/dist/browserbase.js +185 -170
- package/dist/{document-DMIUCoDA.js → document-BSCwJgBM.js} +4 -4
- package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
- package/dist/{adapter-DQrBP1tj.d.ts → errors-gMtejKHc.d.ts} +111 -70
- package/dist/exa.d.ts +18 -11
- package/dist/exa.js +306 -275
- package/dist/fieldwork-D7npPoUf.d.ts +35 -0
- package/dist/firecrawl.d.ts +4 -3
- package/dist/firecrawl.js +450 -417
- package/dist/{parse-Q7H4mrnO.js → http-CJcvTPnE.js} +223 -225
- package/dist/image.d.ts +253 -0
- package/dist/image.js +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +67 -82
- package/dist/{job-DnavRq_s.js → job-JLEpszjr.js} +9 -9
- package/dist/kernel.d.ts +20 -2
- package/dist/kernel.js +65 -19
- package/dist/llamaparse.d.ts +3 -2
- package/dist/llamaparse.js +16 -16
- package/dist/parallel.d.ts +9 -9
- package/dist/parallel.js +423 -389
- package/dist/path-DO2llIdp.js +10 -0
- package/dist/perplexity.d.ts +6 -5
- package/dist/perplexity.js +21 -21
- package/dist/reducto.d.ts +3 -2
- package/dist/reducto.js +14 -14
- package/dist/{schema-BFjS6CSz.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
- package/dist/{schema--iU4AXSM.js → schema-CJXFAZ-x.js} +12 -3
- package/dist/serpapi.d.ts +63 -5
- package/dist/serpapi.js +374 -144
- package/dist/tavily.d.ts +4 -3
- package/dist/tavily.js +247 -234
- package/dist/tools.d.ts +76 -15
- package/dist/tools.js +522 -154
- package/dist/{types-rc8bl8Em.js → types-mq6d6YOK.js} +1 -0
- package/dist/{util-DFUXQX6v.js → util-LvME_uOj.js} +35 -11
- package/package.json +7 -2
- package/dist/fieldwork-JCfyw58T.d.ts +0 -113
- package/dist/path-DL5P8XH2.js +0 -17
- package/dist/util-DhYr1OS3.d.ts +0 -1
- package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
package/dist/tools.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
import { t as FieldworkError } from "./errors-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as CAPABILITIES } from "./types-
|
|
5
|
-
import
|
|
1
|
+
import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
|
|
2
|
+
import { _ as isNumber, a as compact, d as refuseTogether, g as isList, h as isJsonObject, m as isFlag, v as isText, y as jsonValue } from "./util-LvME_uOj.js";
|
|
3
|
+
import { n as bestImages, t as RENDERERS } from "./best-CO9liYDa.js";
|
|
4
|
+
import { t as CAPABILITIES } from "./types-mq6d6YOK.js";
|
|
5
|
+
import { t as joinPath } from "./path-DO2llIdp.js";
|
|
6
|
+
import * as z$1 from "zod/mini";
|
|
7
|
+
// src/tools/budget.ts
|
|
8
|
+
const DEFAULT_MAX_CHARACTERS = 2e4;
|
|
9
|
+
/** Checks configured and per-call budgets against the same optional cap. */
|
|
10
|
+
const checkMaxCharacters = (value, limit = Number.MAX_SAFE_INTEGER) => {
|
|
11
|
+
const parsed = z$1.safeParse(z$1.number().check(z$1.int(), z$1.minimum(1), z$1.maximum(limit)), value);
|
|
12
|
+
if (!parsed.success) throw new FieldworkError("InvalidRequest", `maxCharacters must be an integer from 1 to ${limit}`);
|
|
13
|
+
return parsed.data;
|
|
14
|
+
};
|
|
6
15
|
// src/tool-specs/schema.ts
|
|
16
|
+
/** The schema as a JSON object, to advertise it. Keywords that are absent stay absent. */
|
|
17
|
+
const jsonOf = (schema) => compact({
|
|
18
|
+
additionalProperties: schema.additionalProperties instanceof Object ? jsonOf(schema.additionalProperties) : schema.additionalProperties,
|
|
19
|
+
description: schema.description,
|
|
20
|
+
enum: schema.enum,
|
|
21
|
+
format: schema.format,
|
|
22
|
+
items: schema.items === void 0 ? void 0 : jsonOf(schema.items),
|
|
23
|
+
maximum: schema.maximum,
|
|
24
|
+
minItems: schema.minItems,
|
|
25
|
+
minimum: schema.minimum,
|
|
26
|
+
oneOf: schema.oneOf?.map((item) => jsonOf(item)),
|
|
27
|
+
pattern: schema.pattern,
|
|
28
|
+
properties: schema.properties === void 0 ? void 0 : Object.fromEntries(Object.entries(schema.properties).map(([name, item]) => [name, jsonOf(item)])),
|
|
29
|
+
required: schema.required,
|
|
30
|
+
type: schema.type
|
|
31
|
+
});
|
|
7
32
|
const described = (schema, description) => description === void 0 ? schema : {
|
|
8
33
|
...schema,
|
|
9
34
|
description
|
|
@@ -205,6 +230,50 @@ const stealth = (providers) => ({
|
|
|
205
230
|
providers,
|
|
206
231
|
schema: flag("Use a stealth browser that hides automation and solves CAPTCHAs. Use when a site blocks or challenges the plain browser.")
|
|
207
232
|
});
|
|
233
|
+
/** Total passage token budget across all results, split where bounds and prerequisites differ. */
|
|
234
|
+
const maxTokens = () => [{
|
|
235
|
+
name: "maxTokens",
|
|
236
|
+
providers: ["brave"],
|
|
237
|
+
schema: whole("Total token budget for all results' passages, 1024 to 32768. Requires content: true.", 1024, 32768)
|
|
238
|
+
}, {
|
|
239
|
+
name: "maxTokens",
|
|
240
|
+
providers: ["perplexity"],
|
|
241
|
+
schema: whole("Total token budget for page content across all results.", 1)
|
|
242
|
+
}];
|
|
243
|
+
/** Per-result passage token cap, split where bounds and prerequisites differ. */
|
|
244
|
+
const maxTokensPerResult = () => [{
|
|
245
|
+
name: "maxTokensPerResult",
|
|
246
|
+
providers: ["brave"],
|
|
247
|
+
schema: whole("Token cap for one result's passages, 512 to 8192. Requires content: true.", 512, 8192)
|
|
248
|
+
}, {
|
|
249
|
+
name: "maxTokensPerResult",
|
|
250
|
+
providers: ["perplexity"],
|
|
251
|
+
schema: whole("Token cap for each result's page content.", 1)
|
|
252
|
+
}];
|
|
253
|
+
/** Per-result excerpt/passage character cap. */
|
|
254
|
+
const maxCharsPerResult = (providers) => ({
|
|
255
|
+
name: "maxCharsPerResult",
|
|
256
|
+
providers,
|
|
257
|
+
schema: whole("Cap on the characters of passages or excerpts returned for each result.", 1)
|
|
258
|
+
});
|
|
259
|
+
/** Total excerpt/passage character cap across all results. */
|
|
260
|
+
const maxCharsTotal = (providers) => ({
|
|
261
|
+
name: "maxCharsTotal",
|
|
262
|
+
providers,
|
|
263
|
+
schema: whole("Cap on the characters of passages or excerpts returned across all results.", 1)
|
|
264
|
+
});
|
|
265
|
+
/** Per-page full text (`markdown`) character cap. */
|
|
266
|
+
const maxContentChars = (providers) => ({
|
|
267
|
+
name: "maxContentChars",
|
|
268
|
+
providers,
|
|
269
|
+
schema: whole("Cap on the characters of full page text returned as markdown for each page.", 1)
|
|
270
|
+
});
|
|
271
|
+
/** Tavily's passage count cap per source page. */
|
|
272
|
+
const chunksPerSource = (maximum, note = "") => ({
|
|
273
|
+
name: "chunksPerSource",
|
|
274
|
+
providers: ["tavily"],
|
|
275
|
+
schema: whole(`Passages to return per page, 1 to ${maximum}. ${note}`.trim(), 1, maximum)
|
|
276
|
+
});
|
|
208
277
|
const meta = object({
|
|
209
278
|
requestId: str,
|
|
210
279
|
usage: object({
|
|
@@ -261,6 +330,18 @@ const imageResult = object({
|
|
|
261
330
|
url: str,
|
|
262
331
|
width: number()
|
|
263
332
|
}, ["url"]);
|
|
333
|
+
const imageMatch = object({
|
|
334
|
+
description: str,
|
|
335
|
+
height: number(),
|
|
336
|
+
kind: choice("exact for the same image, visual for a similar one; absent when the provider does not say.", ["exact", "visual"]),
|
|
337
|
+
publishedAt: str,
|
|
338
|
+
siteName: str,
|
|
339
|
+
sourceUrl: str,
|
|
340
|
+
thumbnailUrl: str,
|
|
341
|
+
title: str,
|
|
342
|
+
url: str,
|
|
343
|
+
width: number()
|
|
344
|
+
}, ["sourceUrl"]);
|
|
264
345
|
const page = object({
|
|
265
346
|
author: str,
|
|
266
347
|
description: str,
|
|
@@ -338,6 +419,37 @@ const IMAGES_OUTPUT = object({
|
|
|
338
419
|
meta,
|
|
339
420
|
results: list(imageResult)
|
|
340
421
|
}, ["results"]);
|
|
422
|
+
/** The result of `search_by_image`, a `ReverseImageSearch`. */
|
|
423
|
+
const IMAGE_MATCHES_OUTPUT = object({
|
|
424
|
+
meta,
|
|
425
|
+
results: list(imageMatch)
|
|
426
|
+
}, ["results"]);
|
|
427
|
+
/** The result of `find_images`, a `BestImages`. */
|
|
428
|
+
const BEST_IMAGES_OUTPUT = object({
|
|
429
|
+
images: list(object({
|
|
430
|
+
height: number(),
|
|
431
|
+
measured: flag("True when width and height were measured from loaded pixels; false when the page declared them or the CDN's URL names them."),
|
|
432
|
+
score: number("How good the image is; higher is better."),
|
|
433
|
+
sources: texts("Where the page names the image, such as og:image, img or srcset, and lcp when it was the rendered page's largest contentful paint."),
|
|
434
|
+
url: str,
|
|
435
|
+
variants: texts("The image's other URLs, such as the page's own and smaller sizes."),
|
|
436
|
+
verified: flag("False when a CDN pattern built url and nothing loaded it; the page's own URL is then first in variants."),
|
|
437
|
+
width: number()
|
|
438
|
+
}, [
|
|
439
|
+
"url",
|
|
440
|
+
"verified",
|
|
441
|
+
"variants",
|
|
442
|
+
"measured",
|
|
443
|
+
"sources",
|
|
444
|
+
"score"
|
|
445
|
+
]), "The page's images, best first."),
|
|
446
|
+
meta,
|
|
447
|
+
renderError: object({
|
|
448
|
+
code: str,
|
|
449
|
+
message: str
|
|
450
|
+
}, ["code", "message"], "Why the render failed, when render was auto and the images are the read's instead."),
|
|
451
|
+
rendered: flag("Whether the page was rendered in a browser.")
|
|
452
|
+
}, ["images", "rendered"]);
|
|
341
453
|
/** The result of `read_page`, a `Page`. */
|
|
342
454
|
const PAGE_OUTPUT = page;
|
|
343
455
|
/** The result of `read_pages`, a `PageBatch`: the pages read, and `failed` for URLs that could not be. */
|
|
@@ -727,19 +839,23 @@ const BROWSER_SPECS = [
|
|
|
727
839
|
capability: "act",
|
|
728
840
|
description: "Run a script in a new remote browser session and return what it printed and returned; the session closes afterwards. The script can visit sites, click, type and submit forms, and its effects on those sites are real. Use only when a page needs interaction that reading cannot do. Do not use to read or search pages.",
|
|
729
841
|
destructive: true,
|
|
730
|
-
fields: [
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
"
|
|
739
|
-
"
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
842
|
+
fields: [
|
|
843
|
+
{
|
|
844
|
+
name: "code",
|
|
845
|
+
required: true,
|
|
846
|
+
schema: text("The script to run.")
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
name: "language",
|
|
850
|
+
providers: ["firecrawl"],
|
|
851
|
+
schema: choice("The script's language. Defaults to node.", [
|
|
852
|
+
"node",
|
|
853
|
+
"python",
|
|
854
|
+
"bash"
|
|
855
|
+
])
|
|
856
|
+
},
|
|
857
|
+
stealth(["kernel"])
|
|
858
|
+
],
|
|
743
859
|
idempotent: false,
|
|
744
860
|
name: "run_browser_script",
|
|
745
861
|
output: ACT_OUTPUT,
|
|
@@ -1018,6 +1134,43 @@ const MONITOR_SPECS = [
|
|
|
1018
1134
|
title: "Check usage"
|
|
1019
1135
|
}
|
|
1020
1136
|
];
|
|
1137
|
+
// src/tools/images.ts
|
|
1138
|
+
/** Providers whose `read` returns a page's HTML, with `format: "raw"`. */
|
|
1139
|
+
const HTML_READERS = ["browserbase", "kernel"];
|
|
1140
|
+
const Arguments = z$1.tuple([z$1.string(), z$1.object({
|
|
1141
|
+
limit: z$1.optional(z$1.number()),
|
|
1142
|
+
render: z$1.optional(z$1.enum([
|
|
1143
|
+
"auto",
|
|
1144
|
+
"never",
|
|
1145
|
+
"always"
|
|
1146
|
+
])),
|
|
1147
|
+
retries: z$1.optional(z$1.number()),
|
|
1148
|
+
signal: z$1.optional(z$1.instanceof(AbortSignal)),
|
|
1149
|
+
timeout: z$1.optional(z$1.number())
|
|
1150
|
+
})]);
|
|
1151
|
+
const isOneOf = (names, name) => names.some((candidate) => candidate === name);
|
|
1152
|
+
const isImageRouter = (web) => isOneOf(HTML_READERS, web.providerFor("read")) && isOneOf(RENDERERS, web.providerFor("act"));
|
|
1153
|
+
/**
|
|
1154
|
+
* `bestImages` as a tool operation, or undefined unless the instance reads
|
|
1155
|
+
* HTML with a provider in `HTML_READERS` and acts with one in `RENDERERS`.
|
|
1156
|
+
* The tool's input is already checked. The call's `signal` and `retries` go
|
|
1157
|
+
* through, and its `timeout` stops the read and the render as one deadline.
|
|
1158
|
+
*/
|
|
1159
|
+
const findImages = (web) => {
|
|
1160
|
+
if (!isImageRouter(web)) return;
|
|
1161
|
+
const router = web;
|
|
1162
|
+
return async (...args) => {
|
|
1163
|
+
const [url, options] = z$1.parse(Arguments, args);
|
|
1164
|
+
const { raw: _raw, renderError, ...found } = await bestImages(router, url, options);
|
|
1165
|
+
return z$1.parse(jsonValue, {
|
|
1166
|
+
...found,
|
|
1167
|
+
...renderError && { renderError: {
|
|
1168
|
+
code: renderError.code,
|
|
1169
|
+
message: renderError.message
|
|
1170
|
+
} }
|
|
1171
|
+
});
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1021
1174
|
// src/tool-specs/read.ts
|
|
1022
1175
|
const query = {
|
|
1023
1176
|
name: "query",
|
|
@@ -1042,6 +1195,10 @@ const READ_SPECS = [
|
|
|
1042
1195
|
fields: [
|
|
1043
1196
|
urlField(PAGE_URL),
|
|
1044
1197
|
query,
|
|
1198
|
+
maxCharsPerResult(["exa", "parallel"]),
|
|
1199
|
+
maxCharsTotal(["parallel"]),
|
|
1200
|
+
maxContentChars(["exa", "parallel"]),
|
|
1201
|
+
chunksPerSource(5, "Requires query."),
|
|
1045
1202
|
maxAge(["exa", "firecrawl"]),
|
|
1046
1203
|
maxAgeAtLeast600(),
|
|
1047
1204
|
country(["browserbase"], "Fetch the page through a proxy in"),
|
|
@@ -1065,6 +1222,10 @@ const READ_SPECS = [
|
|
|
1065
1222
|
schema: list(url("A page's full URL, including https://."), "The pages' full URLs, including https://.", { minItems: 1 })
|
|
1066
1223
|
},
|
|
1067
1224
|
query,
|
|
1225
|
+
maxCharsPerResult(["exa", "parallel"]),
|
|
1226
|
+
maxCharsTotal(["parallel"]),
|
|
1227
|
+
maxContentChars(["exa", "parallel"]),
|
|
1228
|
+
chunksPerSource(5, "Requires query."),
|
|
1068
1229
|
maxAge(["exa", "firecrawl"]),
|
|
1069
1230
|
maxAgeAtLeast600(),
|
|
1070
1231
|
resume(["firecrawl"])
|
|
@@ -1110,6 +1271,33 @@ const READ_SPECS = [
|
|
|
1110
1271
|
readOnly: true,
|
|
1111
1272
|
title: "Read a product page"
|
|
1112
1273
|
},
|
|
1274
|
+
{
|
|
1275
|
+
capability: "read",
|
|
1276
|
+
description: "Find a page's images, best first: the largest, most prominent content images, each at its largest known original URL, with its size when known. Leaves out SVGs, images in the site's header, nav or footer, and images known to be under 100 pixels on a side, such as icons and tracking pixels. Use when you need a page's main image or its photos. Do not use to find pictures of a subject across the web (use search_images), or for where an image appears (use search_by_image).",
|
|
1277
|
+
destructive: false,
|
|
1278
|
+
fields: [
|
|
1279
|
+
urlField(PAGE_URL),
|
|
1280
|
+
{
|
|
1281
|
+
name: "limit",
|
|
1282
|
+
schema: whole("The most images to return. Leave out for every image found.", 1)
|
|
1283
|
+
},
|
|
1284
|
+
{
|
|
1285
|
+
name: "render",
|
|
1286
|
+
schema: choice("auto (the default) reads the page's HTML and renders it in a browser only when that leaves no image or no clear best one; never only reads the HTML; always renders, which finds images JavaScript loads and measures real sizes, and is slower.", [
|
|
1287
|
+
"auto",
|
|
1288
|
+
"never",
|
|
1289
|
+
"always"
|
|
1290
|
+
])
|
|
1291
|
+
}
|
|
1292
|
+
],
|
|
1293
|
+
idempotent: true,
|
|
1294
|
+
name: "find_images",
|
|
1295
|
+
operation: findImages,
|
|
1296
|
+
output: BEST_IMAGES_OUTPUT,
|
|
1297
|
+
positional: ["url"],
|
|
1298
|
+
readOnly: true,
|
|
1299
|
+
title: "Find a page's images"
|
|
1300
|
+
},
|
|
1113
1301
|
{
|
|
1114
1302
|
capability: "map",
|
|
1115
1303
|
description: "List the URLs of a website without reading the pages. Use to find which pages a site has before reading some of them. Do not use when you need page text (use read_page or crawl_site).",
|
|
@@ -1146,143 +1334,173 @@ const READ_SPECS = [
|
|
|
1146
1334
|
* these into tools, in this order.
|
|
1147
1335
|
*/
|
|
1148
1336
|
const SPECS = [
|
|
1149
|
-
...[
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
"
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
"
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
"
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
"firecrawl",
|
|
1207
|
-
"tavily",
|
|
1208
|
-
"parallel",
|
|
1209
|
-
"perplexity",
|
|
1210
|
-
"brave",
|
|
1211
|
-
"serpapi"
|
|
1212
|
-
], "Localize results to"),
|
|
1213
|
-
language([
|
|
1214
|
-
"tavily",
|
|
1215
|
-
"perplexity",
|
|
1216
|
-
"brave",
|
|
1217
|
-
"serpapi"
|
|
1218
|
-
]),
|
|
1219
|
-
{
|
|
1220
|
-
name: "content",
|
|
1221
|
-
providers: [
|
|
1337
|
+
...[
|
|
1338
|
+
{
|
|
1339
|
+
capability: "search",
|
|
1340
|
+
description: "Search the web and return a ranked list of pages with their titles, URLs and matching snippets. Use when you need pages about a topic, product or fact and do not have a URL yet. Do not use to read a page you already have a URL for (use read_page), for pictures of a subject (use search_images), for where an image appears (use search_by_image), or for a question that needs several sources combined into an answer (use research_question).",
|
|
1341
|
+
destructive: false,
|
|
1342
|
+
fields: [
|
|
1343
|
+
{
|
|
1344
|
+
name: "query",
|
|
1345
|
+
required: true,
|
|
1346
|
+
schema: text("What to search for.")
|
|
1347
|
+
},
|
|
1348
|
+
limit("How many results to return.", 20, [
|
|
1349
|
+
"exa",
|
|
1350
|
+
"firecrawl",
|
|
1351
|
+
"tavily",
|
|
1352
|
+
"parallel",
|
|
1353
|
+
"perplexity",
|
|
1354
|
+
"brave",
|
|
1355
|
+
"browserbase"
|
|
1356
|
+
]),
|
|
1357
|
+
includeDomains("results", [
|
|
1358
|
+
"exa",
|
|
1359
|
+
"firecrawl",
|
|
1360
|
+
"tavily",
|
|
1361
|
+
"parallel",
|
|
1362
|
+
"perplexity"
|
|
1363
|
+
]),
|
|
1364
|
+
excludeDomains("results", [
|
|
1365
|
+
"exa",
|
|
1366
|
+
"firecrawl",
|
|
1367
|
+
"tavily",
|
|
1368
|
+
"parallel",
|
|
1369
|
+
"perplexity"
|
|
1370
|
+
]),
|
|
1371
|
+
publishedAfter([
|
|
1372
|
+
"exa",
|
|
1373
|
+
"firecrawl",
|
|
1374
|
+
"tavily",
|
|
1375
|
+
"parallel",
|
|
1376
|
+
"perplexity",
|
|
1377
|
+
"brave",
|
|
1378
|
+
"serpapi"
|
|
1379
|
+
]),
|
|
1380
|
+
publishedBefore([
|
|
1381
|
+
"exa",
|
|
1382
|
+
"firecrawl",
|
|
1383
|
+
"tavily",
|
|
1384
|
+
"perplexity",
|
|
1385
|
+
"brave",
|
|
1386
|
+
"serpapi"
|
|
1387
|
+
]),
|
|
1388
|
+
...recency([
|
|
1389
|
+
"firecrawl",
|
|
1390
|
+
"perplexity",
|
|
1391
|
+
"serpapi"
|
|
1392
|
+
], ["tavily", "brave"]),
|
|
1393
|
+
country([
|
|
1222
1394
|
"exa",
|
|
1223
1395
|
"firecrawl",
|
|
1224
1396
|
"tavily",
|
|
1397
|
+
"parallel",
|
|
1398
|
+
"perplexity",
|
|
1399
|
+
"brave",
|
|
1400
|
+
"serpapi"
|
|
1401
|
+
], "Localize results to"),
|
|
1402
|
+
language([
|
|
1403
|
+
"tavily",
|
|
1404
|
+
"perplexity",
|
|
1405
|
+
"brave",
|
|
1406
|
+
"serpapi"
|
|
1407
|
+
]),
|
|
1408
|
+
{
|
|
1409
|
+
name: "content",
|
|
1410
|
+
providers: [
|
|
1411
|
+
"exa",
|
|
1412
|
+
"firecrawl",
|
|
1413
|
+
"tavily",
|
|
1414
|
+
"brave"
|
|
1415
|
+
],
|
|
1416
|
+
schema: flag("Include each result's page text. Slower and longer; leave out to get snippets only.")
|
|
1417
|
+
},
|
|
1418
|
+
...maxTokens(),
|
|
1419
|
+
...maxTokensPerResult(),
|
|
1420
|
+
maxCharsPerResult(["exa", "parallel"]),
|
|
1421
|
+
maxCharsTotal(["parallel"]),
|
|
1422
|
+
chunksPerSource(3),
|
|
1423
|
+
maxAge(["exa", "tavily"]),
|
|
1424
|
+
maxAgeAtLeast600()
|
|
1425
|
+
],
|
|
1426
|
+
idempotent: true,
|
|
1427
|
+
name: "search_web",
|
|
1428
|
+
output: SEARCH_OUTPUT,
|
|
1429
|
+
positional: ["query"],
|
|
1430
|
+
readOnly: true,
|
|
1431
|
+
title: "Search the web"
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
capability: "images",
|
|
1435
|
+
description: "Search for images and return each image's URL, thumbnail, the page it appears on, its title and its size. Use when you need pictures of a subject. Do not use to find pages (use search_web) or to learn what is in an image.",
|
|
1436
|
+
destructive: false,
|
|
1437
|
+
fields: [
|
|
1438
|
+
{
|
|
1439
|
+
name: "query",
|
|
1440
|
+
required: true,
|
|
1441
|
+
schema: text("What the images should show.")
|
|
1442
|
+
},
|
|
1443
|
+
limit("How many images to return.", 20, [
|
|
1444
|
+
"firecrawl",
|
|
1445
|
+
"parallel",
|
|
1225
1446
|
"brave"
|
|
1226
|
-
],
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1447
|
+
]),
|
|
1448
|
+
includeDomains("images", ["tavily"]),
|
|
1449
|
+
excludeDomains("images", ["tavily"]),
|
|
1450
|
+
publishedAfter(["serpapi"]),
|
|
1451
|
+
publishedBefore(["serpapi"]),
|
|
1452
|
+
...recency(["serpapi"], []),
|
|
1453
|
+
country([
|
|
1454
|
+
"firecrawl",
|
|
1455
|
+
"parallel",
|
|
1456
|
+
"brave",
|
|
1457
|
+
"serpapi"
|
|
1458
|
+
], "Localize results to"),
|
|
1459
|
+
language(["brave", "serpapi"])
|
|
1460
|
+
],
|
|
1461
|
+
idempotent: true,
|
|
1462
|
+
name: "search_images",
|
|
1463
|
+
output: IMAGES_OUTPUT,
|
|
1464
|
+
positional: ["query"],
|
|
1465
|
+
readOnly: true,
|
|
1466
|
+
title: "Search for images"
|
|
1467
|
+
},
|
|
1468
|
+
{
|
|
1469
|
+
capability: "reverseImage",
|
|
1470
|
+
description: "Find the web pages an image appears on, given the image's URL. Returns each page's URL (sourceUrl), the matched image when the provider gives one, a thumbnail, a title and whether the match is the same image or a similar one. Use when you have an image and need to know where it is published, who uses it or where a larger copy is. Do not use to find pictures of a subject (use search_images), to find pages by text (use search_web) or to learn what is in an image.",
|
|
1471
|
+
destructive: false,
|
|
1472
|
+
fields: [
|
|
1473
|
+
{
|
|
1474
|
+
name: "imageUrl",
|
|
1475
|
+
required: true,
|
|
1476
|
+
schema: url("The image's full URL, including https://. It must be publicly reachable.")
|
|
1477
|
+
},
|
|
1478
|
+
{
|
|
1479
|
+
name: "query",
|
|
1480
|
+
providers: ["serpapi"],
|
|
1481
|
+
schema: text("Words to refine the search with, such as the subject. SerpApi refuses it together with match \"exact\".")
|
|
1482
|
+
},
|
|
1483
|
+
{
|
|
1484
|
+
name: "match",
|
|
1485
|
+
providers: ["serpapi"],
|
|
1486
|
+
schema: choice("exact for pages showing the same image, visual for pages showing a similar one. Leave out for the provider's default, which lists similar images.", ["exact", "visual"])
|
|
1487
|
+
},
|
|
1488
|
+
country(["serpapi"], "Localize results to"),
|
|
1489
|
+
language(["serpapi"])
|
|
1490
|
+
],
|
|
1491
|
+
idempotent: true,
|
|
1492
|
+
name: "search_by_image",
|
|
1493
|
+
output: IMAGE_MATCHES_OUTPUT,
|
|
1494
|
+
positional: ["imageUrl"],
|
|
1495
|
+
readOnly: true,
|
|
1496
|
+
title: "Find where an image appears"
|
|
1497
|
+
}
|
|
1498
|
+
],
|
|
1273
1499
|
...READ_SPECS,
|
|
1274
1500
|
...ANSWER_SPECS,
|
|
1275
1501
|
...BROWSER_SPECS,
|
|
1276
1502
|
...MONITOR_SPECS
|
|
1277
1503
|
];
|
|
1278
|
-
// src/tools/budget.ts
|
|
1279
|
-
const DEFAULT_MAX_CHARACTERS = 2e4;
|
|
1280
|
-
/** Checks configured and per-call budgets against the same optional cap. */
|
|
1281
|
-
const checkMaxCharacters = (value, limit = Number.MAX_SAFE_INTEGER) => {
|
|
1282
|
-
const parsed = z.safeParse(z.number().check(z.int(), z.minimum(1), z.maximum(limit)), value);
|
|
1283
|
-
if (!parsed.success) throw new FieldworkError("InvalidRequest", `maxCharacters must be an integer from 1 to ${limit}`);
|
|
1284
|
-
return parsed.data;
|
|
1285
|
-
};
|
|
1286
1504
|
// src/tools/dispatch.ts
|
|
1287
1505
|
const isOperation = (value) => typeof value === "function";
|
|
1288
1506
|
const isGroup = (value) => isJsonObject(value);
|
|
@@ -1350,10 +1568,12 @@ const VERBATIM = /* @__PURE__ */ new Set([
|
|
|
1350
1568
|
const SPEND_FIRST = [
|
|
1351
1569
|
"answer",
|
|
1352
1570
|
"output",
|
|
1571
|
+
"excerpts",
|
|
1572
|
+
"snippet",
|
|
1573
|
+
"summary",
|
|
1353
1574
|
"markdown",
|
|
1354
1575
|
"content",
|
|
1355
|
-
"text"
|
|
1356
|
-
"summary"
|
|
1576
|
+
"text"
|
|
1357
1577
|
];
|
|
1358
1578
|
const SPEND_LAST = ["html", "rawHtml"];
|
|
1359
1579
|
const rank = (key) => {
|
|
@@ -1471,7 +1691,7 @@ const problem = (schema, value, name) => {
|
|
|
1471
1691
|
}
|
|
1472
1692
|
return typeProblem(schema, value, name, problem);
|
|
1473
1693
|
};
|
|
1474
|
-
// src/tools.ts
|
|
1694
|
+
// src/tools/build.ts
|
|
1475
1695
|
/**
|
|
1476
1696
|
* Capabilities that start remote browsers or create lasting or billed
|
|
1477
1697
|
* resources. `toolsFor` leaves them out unless they are named in `allow` or
|
|
@@ -1527,7 +1747,7 @@ const resultObject = (spec, values, result) => {
|
|
|
1527
1747
|
const inputSchema = (fields, provider, budget, limit) => {
|
|
1528
1748
|
const schema = {
|
|
1529
1749
|
additionalProperties: false,
|
|
1530
|
-
properties: Object.fromEntries([...fields.map((field) => [field.name,
|
|
1750
|
+
properties: Object.fromEntries([...fields.map((field) => [field.name, jsonOf(field.schema)]), ["maxCharacters", jsonOf(whole(`Shared long-text budget for this call; defaults to ${budget}. Never sent to the provider.`, 1, limit))]]),
|
|
1531
1751
|
required: fields.filter((field) => needs(field, provider)).map((field) => field.name),
|
|
1532
1752
|
type: "object"
|
|
1533
1753
|
};
|
|
@@ -1563,7 +1783,7 @@ const toolFor = (spec, provider, operation, budget, limit) => {
|
|
|
1563
1783
|
inputSchema: inputSchema(fields, provider, budget, limit),
|
|
1564
1784
|
method: spec.method,
|
|
1565
1785
|
name: spec.name,
|
|
1566
|
-
outputSchema: {
|
|
1786
|
+
outputSchema: jsonOf({
|
|
1567
1787
|
...spec.output,
|
|
1568
1788
|
properties: {
|
|
1569
1789
|
...spec.output.properties,
|
|
@@ -1577,7 +1797,7 @@ const toolFor = (spec, provider, operation, budget, limit) => {
|
|
|
1577
1797
|
"length"
|
|
1578
1798
|
]), "One entry for each cut text field; absent when nothing was cut.")
|
|
1579
1799
|
}
|
|
1580
|
-
},
|
|
1800
|
+
}),
|
|
1581
1801
|
provider
|
|
1582
1802
|
};
|
|
1583
1803
|
};
|
|
@@ -1593,7 +1813,7 @@ const toolsFor = (web, options = {}) => {
|
|
|
1593
1813
|
const dispatcher = web;
|
|
1594
1814
|
return SPECS.flatMap((spec) => {
|
|
1595
1815
|
const provider = web.providerFor(spec.capability);
|
|
1596
|
-
const operation = operationFor(dispatcher, spec);
|
|
1816
|
+
const operation = spec.operation === void 0 ? operationFor(dispatcher, spec) : spec.operation(web);
|
|
1597
1817
|
return wanted.has(spec.capability) && provider !== void 0 && operation !== void 0 ? [toolFor(spec, provider, operation, budget, limit)] : [];
|
|
1598
1818
|
});
|
|
1599
1819
|
};
|
|
@@ -1612,4 +1832,152 @@ const toolError = (cause) => {
|
|
|
1612
1832
|
retryable: false
|
|
1613
1833
|
};
|
|
1614
1834
|
};
|
|
1615
|
-
|
|
1835
|
+
// src/tools/catalog.ts
|
|
1836
|
+
/** Retrieval-style notes for `search_web` when more than one search provider is offered. */
|
|
1837
|
+
const SEARCH_PROVIDER_ROLES = /* @__PURE__ */ new Map([
|
|
1838
|
+
["brave", "brave for lexical/keyword queries, search operators and token-budgeted passages (content: true)"],
|
|
1839
|
+
["browserbase", "browserbase for managed web search"],
|
|
1840
|
+
["exa", "exa for neural/semantic queries and capped highlights"],
|
|
1841
|
+
["firecrawl", "firecrawl for web search with full-page Markdown"],
|
|
1842
|
+
["parallel", "parallel for objective-driven semantic search and char-budgeted excerpts"],
|
|
1843
|
+
["perplexity", "perplexity for hybrid lexical+semantic search with token-budgeted snippets"],
|
|
1844
|
+
["serpapi", "serpapi for Google/Bing SERPs and exact keyword queries"],
|
|
1845
|
+
["tavily", "tavily for hybrid search with chunked passages"]
|
|
1846
|
+
]);
|
|
1847
|
+
/**
|
|
1848
|
+
* Retrieval-style guidance naming only the search providers present, or an
|
|
1849
|
+
* empty string when fewer than two providers are offered.
|
|
1850
|
+
*/
|
|
1851
|
+
const searchProviderGuidance = (providers) => {
|
|
1852
|
+
if (providers.length < 2) return "";
|
|
1853
|
+
const notes = providers.flatMap((provider) => {
|
|
1854
|
+
const role = SEARCH_PROVIDER_ROLES.get(provider);
|
|
1855
|
+
return role === void 0 ? [] : [role];
|
|
1856
|
+
});
|
|
1857
|
+
return notes.length === 0 ? "" : ` Choose provider by query style: ${notes.join("; ")}.`;
|
|
1858
|
+
};
|
|
1859
|
+
const InputSchema = z$1.object({
|
|
1860
|
+
oneOf: z$1.optional(z$1.array(z$1.json())),
|
|
1861
|
+
properties: z$1.record(z$1.string(), z$1.json()),
|
|
1862
|
+
required: z$1.optional(z$1.array(z$1.string()))
|
|
1863
|
+
});
|
|
1864
|
+
/**
|
|
1865
|
+
* One provider's schema branch for a multi-provider tool. `explicit` fixes and
|
|
1866
|
+
* requires `provider`; `extraProperties` adds transport-level fields such as
|
|
1867
|
+
* the gateway's `timeout`.
|
|
1868
|
+
*/
|
|
1869
|
+
const providerBranchSchema = (tool, explicit, extraProperties = {}) => {
|
|
1870
|
+
const schema = z$1.parse(InputSchema, tool.inputSchema);
|
|
1871
|
+
const properties = {
|
|
1872
|
+
...schema.properties,
|
|
1873
|
+
...extraProperties
|
|
1874
|
+
};
|
|
1875
|
+
if (explicit) properties.provider = {
|
|
1876
|
+
const: tool.provider,
|
|
1877
|
+
type: "string"
|
|
1878
|
+
};
|
|
1879
|
+
const input = {
|
|
1880
|
+
additionalProperties: false,
|
|
1881
|
+
properties,
|
|
1882
|
+
required: [...schema.required ?? [], ...explicit ? ["provider"] : []],
|
|
1883
|
+
type: "object"
|
|
1884
|
+
};
|
|
1885
|
+
if (schema.oneOf !== void 0) input.oneOf = schema.oneOf;
|
|
1886
|
+
return input;
|
|
1887
|
+
};
|
|
1888
|
+
const resolveDefaultTool = (variants, first, configured) => {
|
|
1889
|
+
if (configured === void 0) return variants.size === 1 ? first : void 0;
|
|
1890
|
+
return variants.get(configured);
|
|
1891
|
+
};
|
|
1892
|
+
const multiProviderSchema = (variants, defaultTool, providers) => ({
|
|
1893
|
+
oneOf: [...defaultTool === void 0 ? [] : [providerBranchSchema(defaultTool, false)], ...variants.map((tool) => providerBranchSchema(tool, true))],
|
|
1894
|
+
properties: { provider: {
|
|
1895
|
+
enum: [...providers],
|
|
1896
|
+
type: "string"
|
|
1897
|
+
} },
|
|
1898
|
+
type: "object"
|
|
1899
|
+
});
|
|
1900
|
+
/** Describes a tool across its providers, including search retrieval-style guidance when several serve `search_web`. */
|
|
1901
|
+
const describeMultiProviderTool = (first, providers, defaultProvider) => {
|
|
1902
|
+
const guidance = first.name === "search_web" ? searchProviderGuidance(providers) : "";
|
|
1903
|
+
const routing = defaultProvider === void 0 ? "Name a provider explicitly." : `Defaults to ${defaultProvider}.`;
|
|
1904
|
+
return `${first.description}${guidance} ${routing} Set provider to choose another supported provider; Fieldwork never switches providers after an error.`;
|
|
1905
|
+
};
|
|
1906
|
+
/**
|
|
1907
|
+
* Collects every client's tools grouped by tool name and provider. Throws when
|
|
1908
|
+
* two clients serve the same tool through the same provider.
|
|
1909
|
+
*/
|
|
1910
|
+
const collectToolVariants = (clients, options = {}) => {
|
|
1911
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1912
|
+
for (const client of clients) for (const tool of toolsFor(client, options)) {
|
|
1913
|
+
const variants = entries.get(tool.name) ?? /* @__PURE__ */ new Map();
|
|
1914
|
+
if (variants.has(tool.provider)) throw new Error(`Duplicate provider ${tool.provider} for ${tool.name}`);
|
|
1915
|
+
variants.set(tool.provider, tool);
|
|
1916
|
+
entries.set(tool.name, variants);
|
|
1917
|
+
}
|
|
1918
|
+
return entries;
|
|
1919
|
+
};
|
|
1920
|
+
/**
|
|
1921
|
+
* Builds one tool per capability name across several Fieldwork clients. Each
|
|
1922
|
+
* provider keeps its own input schema branch and executor; no options are
|
|
1923
|
+
* merged and no call falls back to another provider.
|
|
1924
|
+
*
|
|
1925
|
+
* When a tool has one provider and no conflicting default was configured, it
|
|
1926
|
+
* uses that provider's plain schema without a `provider` field. When several
|
|
1927
|
+
* providers serve a tool (such as `search_web` over Brave and Exa), the tool
|
|
1928
|
+
* exposes a `provider` enum with per-provider `oneOf` branches and retrieval
|
|
1929
|
+
* guidance in its description.
|
|
1930
|
+
*/
|
|
1931
|
+
const toolCatalog = (clients, options = {}) => {
|
|
1932
|
+
const { defaults, toolDefaults, ...toolOptions } = options;
|
|
1933
|
+
const entries = collectToolVariants(clients, toolOptions);
|
|
1934
|
+
const defaultByTool = /* @__PURE__ */ new Map();
|
|
1935
|
+
const providersByTool = /* @__PURE__ */ new Map();
|
|
1936
|
+
const select = (name, provider) => {
|
|
1937
|
+
const variants = entries.get(name);
|
|
1938
|
+
if (variants === void 0) throw new FieldworkError("NotFound", `${name} is not a tool in this catalog`);
|
|
1939
|
+
const selected = provider ?? defaultByTool.get(name);
|
|
1940
|
+
const tool = selected === void 0 ? void 0 : variants.get(selected);
|
|
1941
|
+
if (tool === void 0) {
|
|
1942
|
+
const available = providersByTool.get(name)?.join(", ") ?? "none";
|
|
1943
|
+
throw new FieldworkError("Unsupported", `${name} needs a supported provider; available: ${available}`, { provider: selected });
|
|
1944
|
+
}
|
|
1945
|
+
return tool;
|
|
1946
|
+
};
|
|
1947
|
+
const tools = [];
|
|
1948
|
+
for (const variants of entries.values()) {
|
|
1949
|
+
const list = [...variants.values()];
|
|
1950
|
+
const [first] = list;
|
|
1951
|
+
if (first === void 0) continue;
|
|
1952
|
+
const providers = list.map((tool) => tool.provider);
|
|
1953
|
+
const configured = toolDefaults?.[first.name] ?? defaults?.[first.capability];
|
|
1954
|
+
const defaultTool = resolveDefaultTool(variants, first, configured);
|
|
1955
|
+
const defaultProvider = defaultTool?.provider;
|
|
1956
|
+
defaultByTool.set(first.name, defaultProvider);
|
|
1957
|
+
providersByTool.set(first.name, providers);
|
|
1958
|
+
const single = list.length === 1 && defaultTool !== void 0;
|
|
1959
|
+
tools.push({
|
|
1960
|
+
annotations: first.annotations,
|
|
1961
|
+
capability: first.capability,
|
|
1962
|
+
...defaultProvider !== void 0 && { defaultProvider },
|
|
1963
|
+
description: single ? first.description : describeMultiProviderTool(first, providers, defaultProvider),
|
|
1964
|
+
execute: async (input, call = {}) => {
|
|
1965
|
+
if (!isJsonObject(input)) throw new FieldworkError("InvalidRequest", `${first.name}: input must be an object`);
|
|
1966
|
+
if (single) return await defaultTool.execute(input, call);
|
|
1967
|
+
const { provider, ...args } = input;
|
|
1968
|
+
if (provider !== void 0 && !isText(provider)) throw new FieldworkError("InvalidRequest", `${first.name}: provider must be a string`);
|
|
1969
|
+
return await select(first.name, provider).execute(args, call);
|
|
1970
|
+
},
|
|
1971
|
+
inputSchema: single ? first.inputSchema : multiProviderSchema(list, defaultTool, providers),
|
|
1972
|
+
...first.method !== void 0 && { method: first.method },
|
|
1973
|
+
name: first.name,
|
|
1974
|
+
outputSchema: first.outputSchema,
|
|
1975
|
+
providers
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
return {
|
|
1979
|
+
select,
|
|
1980
|
+
tools
|
|
1981
|
+
};
|
|
1982
|
+
};
|
|
1983
|
+
export { DEFAULT_MAX_CHARACTERS, EXCLUDED_BY_DEFAULT, checkMaxCharacters, collectToolVariants, describeMultiProviderTool, providerBranchSchema, searchProviderGuidance, toolCatalog, toolError, toolsFor };
|