@robota-sdk/agent-tools 3.0.0-beta.1 → 3.0.0-beta.2
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/node/index.cjs +136 -0
- package/dist/node/index.d.cts +17 -1
- package/dist/node/index.d.ts +17 -1
- package/dist/node/index.js +134 -0
- package/package.json +3 -3
package/dist/node/index.cjs
CHANGED
|
@@ -41,6 +41,8 @@ __export(index_exports, {
|
|
|
41
41
|
globTool: () => globTool,
|
|
42
42
|
grepTool: () => grepTool,
|
|
43
43
|
readTool: () => readTool,
|
|
44
|
+
webFetchTool: () => webFetchTool,
|
|
45
|
+
webSearchTool: () => webSearchTool,
|
|
44
46
|
writeTool: () => writeTool,
|
|
45
47
|
zodToJsonSchema: () => zodToJsonSchema
|
|
46
48
|
});
|
|
@@ -1334,6 +1336,138 @@ var grepTool = createZodFunctionTool(
|
|
|
1334
1336
|
return grepFileTool(params);
|
|
1335
1337
|
}
|
|
1336
1338
|
);
|
|
1339
|
+
|
|
1340
|
+
// src/builtins/web-fetch-tool.ts
|
|
1341
|
+
var import_zod7 = require("zod");
|
|
1342
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
1343
|
+
var MAX_RESPONSE_BYTES = 5e6;
|
|
1344
|
+
var WebFetchSchema = import_zod7.z.object({
|
|
1345
|
+
url: import_zod7.z.string().describe("The URL to fetch"),
|
|
1346
|
+
headers: import_zod7.z.record(import_zod7.z.string()).optional().describe("Optional HTTP headers as key-value pairs")
|
|
1347
|
+
});
|
|
1348
|
+
function htmlToText(html) {
|
|
1349
|
+
return html.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "").replace(/<[^>]+>/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
|
1350
|
+
}
|
|
1351
|
+
async function runWebFetch(args) {
|
|
1352
|
+
const { url, headers } = args;
|
|
1353
|
+
try {
|
|
1354
|
+
new URL(url);
|
|
1355
|
+
} catch {
|
|
1356
|
+
const result = { success: false, output: "", error: `Invalid URL: ${url}` };
|
|
1357
|
+
return JSON.stringify(result);
|
|
1358
|
+
}
|
|
1359
|
+
try {
|
|
1360
|
+
const controller = new AbortController();
|
|
1361
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS2);
|
|
1362
|
+
const response = await fetch(url, {
|
|
1363
|
+
headers: {
|
|
1364
|
+
"User-Agent": "Robota-CLI/3.0",
|
|
1365
|
+
...headers ?? {}
|
|
1366
|
+
},
|
|
1367
|
+
signal: controller.signal,
|
|
1368
|
+
redirect: "follow"
|
|
1369
|
+
});
|
|
1370
|
+
clearTimeout(timeout);
|
|
1371
|
+
if (!response.ok) {
|
|
1372
|
+
const result2 = {
|
|
1373
|
+
success: false,
|
|
1374
|
+
output: "",
|
|
1375
|
+
error: `HTTP ${response.status} ${response.statusText}`
|
|
1376
|
+
};
|
|
1377
|
+
return JSON.stringify(result2);
|
|
1378
|
+
}
|
|
1379
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1380
|
+
const buffer = await response.arrayBuffer();
|
|
1381
|
+
if (buffer.byteLength > MAX_RESPONSE_BYTES) {
|
|
1382
|
+
const result2 = {
|
|
1383
|
+
success: false,
|
|
1384
|
+
output: "",
|
|
1385
|
+
error: `Response too large: ${buffer.byteLength} bytes (max ${MAX_RESPONSE_BYTES})`
|
|
1386
|
+
};
|
|
1387
|
+
return JSON.stringify(result2);
|
|
1388
|
+
}
|
|
1389
|
+
let text = new TextDecoder().decode(buffer);
|
|
1390
|
+
if (contentType.includes("html")) {
|
|
1391
|
+
text = htmlToText(text);
|
|
1392
|
+
}
|
|
1393
|
+
const result = { success: true, output: text };
|
|
1394
|
+
return JSON.stringify(result);
|
|
1395
|
+
} catch (err) {
|
|
1396
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1397
|
+
const result = { success: false, output: "", error: message };
|
|
1398
|
+
return JSON.stringify(result);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
var webFetchTool = createZodFunctionTool(
|
|
1402
|
+
"WebFetch",
|
|
1403
|
+
"Fetch a URL and return its content as text. HTML pages are converted to plain text.",
|
|
1404
|
+
WebFetchSchema,
|
|
1405
|
+
async (params) => runWebFetch(params)
|
|
1406
|
+
);
|
|
1407
|
+
|
|
1408
|
+
// src/builtins/web-search-tool.ts
|
|
1409
|
+
var import_zod8 = require("zod");
|
|
1410
|
+
var DEFAULT_LIMIT2 = 10;
|
|
1411
|
+
var DEFAULT_TIMEOUT_MS3 = 15e3;
|
|
1412
|
+
var WebSearchSchema = import_zod8.z.object({
|
|
1413
|
+
query: import_zod8.z.string().describe("The search query"),
|
|
1414
|
+
limit: import_zod8.z.number().optional().describe(`Maximum number of results to return (default: ${DEFAULT_LIMIT2})`)
|
|
1415
|
+
});
|
|
1416
|
+
async function runWebSearch(args) {
|
|
1417
|
+
const { query, limit = DEFAULT_LIMIT2 } = args;
|
|
1418
|
+
const apiKey = process.env["BRAVE_API_KEY"];
|
|
1419
|
+
if (!apiKey) {
|
|
1420
|
+
const result = {
|
|
1421
|
+
success: false,
|
|
1422
|
+
output: "",
|
|
1423
|
+
error: "Web search requires BRAVE_API_KEY environment variable. Get a free API key at https://brave.com/search/api/ (2,000 queries/month free)."
|
|
1424
|
+
};
|
|
1425
|
+
return JSON.stringify(result);
|
|
1426
|
+
}
|
|
1427
|
+
try {
|
|
1428
|
+
const controller = new AbortController();
|
|
1429
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS3);
|
|
1430
|
+
const params = new URLSearchParams({
|
|
1431
|
+
q: query,
|
|
1432
|
+
count: String(Math.min(limit, 20))
|
|
1433
|
+
});
|
|
1434
|
+
const response = await fetch(`https://api.search.brave.com/res/v1/web/search?${params}`, {
|
|
1435
|
+
headers: {
|
|
1436
|
+
Accept: "application/json",
|
|
1437
|
+
"Accept-Encoding": "gzip",
|
|
1438
|
+
"X-Subscription-Token": apiKey
|
|
1439
|
+
},
|
|
1440
|
+
signal: controller.signal
|
|
1441
|
+
});
|
|
1442
|
+
clearTimeout(timeout);
|
|
1443
|
+
if (!response.ok) {
|
|
1444
|
+
const result2 = {
|
|
1445
|
+
success: false,
|
|
1446
|
+
output: "",
|
|
1447
|
+
error: `Brave Search API error: HTTP ${response.status} ${response.statusText}`
|
|
1448
|
+
};
|
|
1449
|
+
return JSON.stringify(result2);
|
|
1450
|
+
}
|
|
1451
|
+
const data = await response.json();
|
|
1452
|
+
const results = (data.web?.results ?? []).map((r) => ({
|
|
1453
|
+
title: r.title,
|
|
1454
|
+
url: r.url,
|
|
1455
|
+
snippet: r.description
|
|
1456
|
+
}));
|
|
1457
|
+
const result = { success: true, output: JSON.stringify(results, null, 2) };
|
|
1458
|
+
return JSON.stringify(result);
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1461
|
+
const result = { success: false, output: "", error: message };
|
|
1462
|
+
return JSON.stringify(result);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
var webSearchTool = createZodFunctionTool(
|
|
1466
|
+
"WebSearch",
|
|
1467
|
+
"Search the web and return results with title, URL, and snippet.",
|
|
1468
|
+
WebSearchSchema,
|
|
1469
|
+
async (params) => runWebSearch(params)
|
|
1470
|
+
);
|
|
1337
1471
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1338
1472
|
0 && (module.exports = {
|
|
1339
1473
|
FunctionTool,
|
|
@@ -1347,6 +1481,8 @@ var grepTool = createZodFunctionTool(
|
|
|
1347
1481
|
globTool,
|
|
1348
1482
|
grepTool,
|
|
1349
1483
|
readTool,
|
|
1484
|
+
webFetchTool,
|
|
1485
|
+
webSearchTool,
|
|
1350
1486
|
writeTool,
|
|
1351
1487
|
zodToJsonSchema
|
|
1352
1488
|
});
|
package/dist/node/index.d.cts
CHANGED
|
@@ -350,4 +350,20 @@ declare const globTool: FunctionTool;
|
|
|
350
350
|
*/
|
|
351
351
|
declare const grepTool: FunctionTool;
|
|
352
352
|
|
|
353
|
-
|
|
353
|
+
/**
|
|
354
|
+
* WebFetchTool — fetch a URL and return its content as text.
|
|
355
|
+
*
|
|
356
|
+
* HTML is stripped to plain text for readability. Uses Node.js native fetch.
|
|
357
|
+
* Output is capped at 30K chars (same as other tools).
|
|
358
|
+
*/
|
|
359
|
+
declare const webFetchTool: FunctionTool;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* WebSearchTool — search the web and return results.
|
|
363
|
+
*
|
|
364
|
+
* Uses Brave Search API when BRAVE_API_KEY is set.
|
|
365
|
+
* Returns an error with setup instructions otherwise.
|
|
366
|
+
*/
|
|
367
|
+
declare const webSearchTool: FunctionTool;
|
|
368
|
+
|
|
369
|
+
export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, OpenAPITool, type TToolResult, ToolRegistry, bashTool, createFunctionTool, createOpenAPITool, createZodFunctionTool, editTool, globTool, grepTool, readTool, webFetchTool, webSearchTool, writeTool, zodToJsonSchema };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -350,4 +350,20 @@ declare const globTool: FunctionTool;
|
|
|
350
350
|
*/
|
|
351
351
|
declare const grepTool: FunctionTool;
|
|
352
352
|
|
|
353
|
-
|
|
353
|
+
/**
|
|
354
|
+
* WebFetchTool — fetch a URL and return its content as text.
|
|
355
|
+
*
|
|
356
|
+
* HTML is stripped to plain text for readability. Uses Node.js native fetch.
|
|
357
|
+
* Output is capped at 30K chars (same as other tools).
|
|
358
|
+
*/
|
|
359
|
+
declare const webFetchTool: FunctionTool;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* WebSearchTool — search the web and return results.
|
|
363
|
+
*
|
|
364
|
+
* Uses Brave Search API when BRAVE_API_KEY is set.
|
|
365
|
+
* Returns an error with setup instructions otherwise.
|
|
366
|
+
*/
|
|
367
|
+
declare const webSearchTool: FunctionTool;
|
|
368
|
+
|
|
369
|
+
export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, OpenAPITool, type TToolResult, ToolRegistry, bashTool, createFunctionTool, createOpenAPITool, createZodFunctionTool, editTool, globTool, grepTool, readTool, webFetchTool, webSearchTool, writeTool, zodToJsonSchema };
|
package/dist/node/index.js
CHANGED
|
@@ -1286,6 +1286,138 @@ var grepTool = createZodFunctionTool(
|
|
|
1286
1286
|
return grepFileTool(params);
|
|
1287
1287
|
}
|
|
1288
1288
|
);
|
|
1289
|
+
|
|
1290
|
+
// src/builtins/web-fetch-tool.ts
|
|
1291
|
+
import { z as z7 } from "zod";
|
|
1292
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
1293
|
+
var MAX_RESPONSE_BYTES = 5e6;
|
|
1294
|
+
var WebFetchSchema = z7.object({
|
|
1295
|
+
url: z7.string().describe("The URL to fetch"),
|
|
1296
|
+
headers: z7.record(z7.string()).optional().describe("Optional HTTP headers as key-value pairs")
|
|
1297
|
+
});
|
|
1298
|
+
function htmlToText(html) {
|
|
1299
|
+
return html.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "").replace(/<[^>]+>/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
|
1300
|
+
}
|
|
1301
|
+
async function runWebFetch(args) {
|
|
1302
|
+
const { url, headers } = args;
|
|
1303
|
+
try {
|
|
1304
|
+
new URL(url);
|
|
1305
|
+
} catch {
|
|
1306
|
+
const result = { success: false, output: "", error: `Invalid URL: ${url}` };
|
|
1307
|
+
return JSON.stringify(result);
|
|
1308
|
+
}
|
|
1309
|
+
try {
|
|
1310
|
+
const controller = new AbortController();
|
|
1311
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS2);
|
|
1312
|
+
const response = await fetch(url, {
|
|
1313
|
+
headers: {
|
|
1314
|
+
"User-Agent": "Robota-CLI/3.0",
|
|
1315
|
+
...headers ?? {}
|
|
1316
|
+
},
|
|
1317
|
+
signal: controller.signal,
|
|
1318
|
+
redirect: "follow"
|
|
1319
|
+
});
|
|
1320
|
+
clearTimeout(timeout);
|
|
1321
|
+
if (!response.ok) {
|
|
1322
|
+
const result2 = {
|
|
1323
|
+
success: false,
|
|
1324
|
+
output: "",
|
|
1325
|
+
error: `HTTP ${response.status} ${response.statusText}`
|
|
1326
|
+
};
|
|
1327
|
+
return JSON.stringify(result2);
|
|
1328
|
+
}
|
|
1329
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1330
|
+
const buffer = await response.arrayBuffer();
|
|
1331
|
+
if (buffer.byteLength > MAX_RESPONSE_BYTES) {
|
|
1332
|
+
const result2 = {
|
|
1333
|
+
success: false,
|
|
1334
|
+
output: "",
|
|
1335
|
+
error: `Response too large: ${buffer.byteLength} bytes (max ${MAX_RESPONSE_BYTES})`
|
|
1336
|
+
};
|
|
1337
|
+
return JSON.stringify(result2);
|
|
1338
|
+
}
|
|
1339
|
+
let text = new TextDecoder().decode(buffer);
|
|
1340
|
+
if (contentType.includes("html")) {
|
|
1341
|
+
text = htmlToText(text);
|
|
1342
|
+
}
|
|
1343
|
+
const result = { success: true, output: text };
|
|
1344
|
+
return JSON.stringify(result);
|
|
1345
|
+
} catch (err) {
|
|
1346
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1347
|
+
const result = { success: false, output: "", error: message };
|
|
1348
|
+
return JSON.stringify(result);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
var webFetchTool = createZodFunctionTool(
|
|
1352
|
+
"WebFetch",
|
|
1353
|
+
"Fetch a URL and return its content as text. HTML pages are converted to plain text.",
|
|
1354
|
+
WebFetchSchema,
|
|
1355
|
+
async (params) => runWebFetch(params)
|
|
1356
|
+
);
|
|
1357
|
+
|
|
1358
|
+
// src/builtins/web-search-tool.ts
|
|
1359
|
+
import { z as z8 } from "zod";
|
|
1360
|
+
var DEFAULT_LIMIT2 = 10;
|
|
1361
|
+
var DEFAULT_TIMEOUT_MS3 = 15e3;
|
|
1362
|
+
var WebSearchSchema = z8.object({
|
|
1363
|
+
query: z8.string().describe("The search query"),
|
|
1364
|
+
limit: z8.number().optional().describe(`Maximum number of results to return (default: ${DEFAULT_LIMIT2})`)
|
|
1365
|
+
});
|
|
1366
|
+
async function runWebSearch(args) {
|
|
1367
|
+
const { query, limit = DEFAULT_LIMIT2 } = args;
|
|
1368
|
+
const apiKey = process.env["BRAVE_API_KEY"];
|
|
1369
|
+
if (!apiKey) {
|
|
1370
|
+
const result = {
|
|
1371
|
+
success: false,
|
|
1372
|
+
output: "",
|
|
1373
|
+
error: "Web search requires BRAVE_API_KEY environment variable. Get a free API key at https://brave.com/search/api/ (2,000 queries/month free)."
|
|
1374
|
+
};
|
|
1375
|
+
return JSON.stringify(result);
|
|
1376
|
+
}
|
|
1377
|
+
try {
|
|
1378
|
+
const controller = new AbortController();
|
|
1379
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS3);
|
|
1380
|
+
const params = new URLSearchParams({
|
|
1381
|
+
q: query,
|
|
1382
|
+
count: String(Math.min(limit, 20))
|
|
1383
|
+
});
|
|
1384
|
+
const response = await fetch(`https://api.search.brave.com/res/v1/web/search?${params}`, {
|
|
1385
|
+
headers: {
|
|
1386
|
+
Accept: "application/json",
|
|
1387
|
+
"Accept-Encoding": "gzip",
|
|
1388
|
+
"X-Subscription-Token": apiKey
|
|
1389
|
+
},
|
|
1390
|
+
signal: controller.signal
|
|
1391
|
+
});
|
|
1392
|
+
clearTimeout(timeout);
|
|
1393
|
+
if (!response.ok) {
|
|
1394
|
+
const result2 = {
|
|
1395
|
+
success: false,
|
|
1396
|
+
output: "",
|
|
1397
|
+
error: `Brave Search API error: HTTP ${response.status} ${response.statusText}`
|
|
1398
|
+
};
|
|
1399
|
+
return JSON.stringify(result2);
|
|
1400
|
+
}
|
|
1401
|
+
const data = await response.json();
|
|
1402
|
+
const results = (data.web?.results ?? []).map((r) => ({
|
|
1403
|
+
title: r.title,
|
|
1404
|
+
url: r.url,
|
|
1405
|
+
snippet: r.description
|
|
1406
|
+
}));
|
|
1407
|
+
const result = { success: true, output: JSON.stringify(results, null, 2) };
|
|
1408
|
+
return JSON.stringify(result);
|
|
1409
|
+
} catch (err) {
|
|
1410
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1411
|
+
const result = { success: false, output: "", error: message };
|
|
1412
|
+
return JSON.stringify(result);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
var webSearchTool = createZodFunctionTool(
|
|
1416
|
+
"WebSearch",
|
|
1417
|
+
"Search the web and return results with title, URL, and snippet.",
|
|
1418
|
+
WebSearchSchema,
|
|
1419
|
+
async (params) => runWebSearch(params)
|
|
1420
|
+
);
|
|
1289
1421
|
export {
|
|
1290
1422
|
FunctionTool,
|
|
1291
1423
|
OpenAPITool,
|
|
@@ -1298,6 +1430,8 @@ export {
|
|
|
1298
1430
|
globTool,
|
|
1299
1431
|
grepTool,
|
|
1300
1432
|
readTool,
|
|
1433
|
+
webFetchTool,
|
|
1434
|
+
webSearchTool,
|
|
1301
1435
|
writeTool,
|
|
1302
1436
|
zodToJsonSchema
|
|
1303
1437
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robota-sdk/agent-tools",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "Tool registry and implementations for Robota SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/node/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"zod": "^3.24.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@robota-sdk/agent-core": "3.0.0-beta.
|
|
29
|
+
"@robota-sdk/agent-core": "3.0.0-beta.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"openapi-types": "^12.1.3",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"tsup": "^8.0.1",
|
|
35
35
|
"typescript": "^5.3.3",
|
|
36
36
|
"vitest": "^1.6.1",
|
|
37
|
-
"@robota-sdk/agent-core": "3.0.0-beta.
|
|
37
|
+
"@robota-sdk/agent-core": "3.0.0-beta.2"
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"publishConfig": {
|