@polka-codes/core 0.8.22 → 0.8.24
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/_tsup-dts-rollup.d.ts +368 -253
- package/dist/index.d.ts +3 -0
- package/dist/index.js +179 -70
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { defaultModels } from './_tsup-dts-rollup.js';
|
|
|
4
4
|
export { createService } from './_tsup-dts-rollup.js';
|
|
5
5
|
export { UsageMeter } from './_tsup-dts-rollup.js';
|
|
6
6
|
export { AiServiceBase } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { UserContent } from './_tsup-dts-rollup.js';
|
|
7
8
|
export { MessageParam } from './_tsup-dts-rollup.js';
|
|
8
9
|
export { AiServiceOptions } from './_tsup-dts-rollup.js';
|
|
9
10
|
export { ModelInfo } from './_tsup-dts-rollup.js';
|
|
@@ -65,12 +66,14 @@ export { allTools } from './_tsup-dts-rollup.js';
|
|
|
65
66
|
export { FilesystemProvider } from './_tsup-dts-rollup.js';
|
|
66
67
|
export { CommandProvider } from './_tsup-dts-rollup.js';
|
|
67
68
|
export { InteractionProvider } from './_tsup-dts-rollup.js';
|
|
69
|
+
export { WebProvider } from './_tsup-dts-rollup.js';
|
|
68
70
|
export { ToolProvider } from './_tsup-dts-rollup.js';
|
|
69
71
|
export { MockProvider } from './_tsup-dts-rollup.js';
|
|
70
72
|
export { askFollowupQuestion } from './_tsup-dts-rollup.js';
|
|
71
73
|
export { attemptCompletion } from './_tsup-dts-rollup.js';
|
|
72
74
|
export { delegate } from './_tsup-dts-rollup.js';
|
|
73
75
|
export { executeCommand } from './_tsup-dts-rollup.js';
|
|
76
|
+
export { fetchUrl } from './_tsup-dts-rollup.js';
|
|
74
77
|
export { listFiles } from './_tsup-dts-rollup.js';
|
|
75
78
|
export { readFile } from './_tsup-dts-rollup.js';
|
|
76
79
|
export { replaceInFile } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -883,6 +883,7 @@ __export(allTools_exports, {
|
|
|
883
883
|
attemptCompletion: () => attemptCompletion_default,
|
|
884
884
|
delegate: () => delegate_default,
|
|
885
885
|
executeCommand: () => executeCommand_default,
|
|
886
|
+
fetchUrl: () => fetchUrl_default,
|
|
886
887
|
handOver: () => handOver_default,
|
|
887
888
|
listFiles: () => listFiles_default,
|
|
888
889
|
readFile: () => readFile_default,
|
|
@@ -1371,8 +1372,89 @@ var executeCommand_default = {
|
|
|
1371
1372
|
isAvailable: isAvailable4
|
|
1372
1373
|
};
|
|
1373
1374
|
|
|
1374
|
-
// src/tools/
|
|
1375
|
+
// src/tools/fetchUrl.ts
|
|
1375
1376
|
var toolInfo5 = {
|
|
1377
|
+
name: "fetch_url",
|
|
1378
|
+
description: "Fetch the content located at one or more HTTP(S) URLs and return it in Markdown format. This works for standard web pages as well as raw files (e.g. README.md, source code) hosted on platforms like GitHub.",
|
|
1379
|
+
parameters: [
|
|
1380
|
+
{
|
|
1381
|
+
name: "url",
|
|
1382
|
+
description: "One or more URLs to fetch, separated by commas if multiple.",
|
|
1383
|
+
required: true
|
|
1384
|
+
}
|
|
1385
|
+
],
|
|
1386
|
+
examples: [
|
|
1387
|
+
{
|
|
1388
|
+
description: "Fetch a single webpage",
|
|
1389
|
+
parameters: [
|
|
1390
|
+
{
|
|
1391
|
+
name: "url",
|
|
1392
|
+
value: "https://example.com"
|
|
1393
|
+
}
|
|
1394
|
+
]
|
|
1395
|
+
},
|
|
1396
|
+
{
|
|
1397
|
+
description: "Fetch multiple webpages",
|
|
1398
|
+
parameters: [
|
|
1399
|
+
{
|
|
1400
|
+
name: "url",
|
|
1401
|
+
value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
|
|
1402
|
+
}
|
|
1403
|
+
]
|
|
1404
|
+
},
|
|
1405
|
+
{
|
|
1406
|
+
description: "Fetch a raw file from GitHub",
|
|
1407
|
+
parameters: [
|
|
1408
|
+
{
|
|
1409
|
+
name: "url",
|
|
1410
|
+
value: "https://raw.githubusercontent.com/user/repo/main/README.md"
|
|
1411
|
+
}
|
|
1412
|
+
]
|
|
1413
|
+
}
|
|
1414
|
+
],
|
|
1415
|
+
permissionLevel: 1 /* Read */
|
|
1416
|
+
};
|
|
1417
|
+
var handler5 = async (provider, args) => {
|
|
1418
|
+
if (!provider.fetchUrl) {
|
|
1419
|
+
return {
|
|
1420
|
+
type: "Error" /* Error */,
|
|
1421
|
+
message: "Not possible to fetch url. Abort."
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
const urls = getStringArray(args, "url");
|
|
1425
|
+
if (urls.length === 0) {
|
|
1426
|
+
return {
|
|
1427
|
+
type: "Error" /* Error */,
|
|
1428
|
+
message: "No URLs provided. Please provide at least one URL to fetch."
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
const results = [];
|
|
1432
|
+
for (const url of urls) {
|
|
1433
|
+
try {
|
|
1434
|
+
const content = provider.fetchUrl(url).then((res) => `<fetch_url_content url="${url}">${res}</fetch_url_content>`);
|
|
1435
|
+
results.push(content);
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1438
|
+
results.push(Promise.resolve(`<fetch_url_error url="${url}">${errorMessage}</fetch_url_error>`));
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
const resolvedResults = await Promise.all(results);
|
|
1442
|
+
return {
|
|
1443
|
+
type: "Reply" /* Reply */,
|
|
1444
|
+
message: resolvedResults.join("\n")
|
|
1445
|
+
};
|
|
1446
|
+
};
|
|
1447
|
+
var isAvailable5 = (provider) => {
|
|
1448
|
+
return typeof provider.fetchUrl === "function";
|
|
1449
|
+
};
|
|
1450
|
+
var fetchUrl_default = {
|
|
1451
|
+
...toolInfo5,
|
|
1452
|
+
handler: handler5,
|
|
1453
|
+
isAvailable: isAvailable5
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
// src/tools/listFiles.ts
|
|
1457
|
+
var toolInfo6 = {
|
|
1376
1458
|
name: "list_files",
|
|
1377
1459
|
description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
|
1378
1460
|
parameters: [
|
|
@@ -1412,7 +1494,7 @@ var toolInfo5 = {
|
|
|
1412
1494
|
],
|
|
1413
1495
|
permissionLevel: 1 /* Read */
|
|
1414
1496
|
};
|
|
1415
|
-
var
|
|
1497
|
+
var handler6 = async (provider, args) => {
|
|
1416
1498
|
if (!provider.listFiles) {
|
|
1417
1499
|
return {
|
|
1418
1500
|
type: "Error" /* Error */,
|
|
@@ -1432,17 +1514,17 @@ ${files.join("\n")}
|
|
|
1432
1514
|
<list_files_truncated>${limitReached}</list_files_truncated>`
|
|
1433
1515
|
};
|
|
1434
1516
|
};
|
|
1435
|
-
var
|
|
1517
|
+
var isAvailable6 = (provider) => {
|
|
1436
1518
|
return !!provider.listFiles;
|
|
1437
1519
|
};
|
|
1438
1520
|
var listFiles_default = {
|
|
1439
|
-
...
|
|
1440
|
-
handler:
|
|
1441
|
-
isAvailable:
|
|
1521
|
+
...toolInfo6,
|
|
1522
|
+
handler: handler6,
|
|
1523
|
+
isAvailable: isAvailable6
|
|
1442
1524
|
};
|
|
1443
1525
|
|
|
1444
1526
|
// src/tools/readFile.ts
|
|
1445
|
-
var
|
|
1527
|
+
var toolInfo7 = {
|
|
1446
1528
|
name: "read_file",
|
|
1447
1529
|
description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
|
|
1448
1530
|
parameters: [
|
|
@@ -1475,7 +1557,7 @@ var toolInfo6 = {
|
|
|
1475
1557
|
],
|
|
1476
1558
|
permissionLevel: 1 /* Read */
|
|
1477
1559
|
};
|
|
1478
|
-
var
|
|
1560
|
+
var handler7 = async (provider, args) => {
|
|
1479
1561
|
if (!provider.readFile) {
|
|
1480
1562
|
return {
|
|
1481
1563
|
type: "Error" /* Error */,
|
|
@@ -1502,17 +1584,17 @@ var handler6 = async (provider, args) => {
|
|
|
1502
1584
|
message: resp.join("\n")
|
|
1503
1585
|
};
|
|
1504
1586
|
};
|
|
1505
|
-
var
|
|
1587
|
+
var isAvailable7 = (provider) => {
|
|
1506
1588
|
return !!provider.readFile;
|
|
1507
1589
|
};
|
|
1508
1590
|
var readFile_default = {
|
|
1509
|
-
...
|
|
1510
|
-
handler:
|
|
1511
|
-
isAvailable:
|
|
1591
|
+
...toolInfo7,
|
|
1592
|
+
handler: handler7,
|
|
1593
|
+
isAvailable: isAvailable7
|
|
1512
1594
|
};
|
|
1513
1595
|
|
|
1514
1596
|
// src/tools/replaceInFile.ts
|
|
1515
|
-
var
|
|
1597
|
+
var toolInfo8 = {
|
|
1516
1598
|
name: "replace_in_file",
|
|
1517
1599
|
description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
|
1518
1600
|
parameters: [
|
|
@@ -1664,7 +1746,7 @@ function oldFeature() {
|
|
|
1664
1746
|
],
|
|
1665
1747
|
permissionLevel: 2 /* Write */
|
|
1666
1748
|
};
|
|
1667
|
-
var
|
|
1749
|
+
var handler8 = async (provider, args) => {
|
|
1668
1750
|
if (!provider.readFile || !provider.writeFile) {
|
|
1669
1751
|
return {
|
|
1670
1752
|
type: "Error" /* Error */,
|
|
@@ -1687,17 +1769,17 @@ var handler7 = async (provider, args) => {
|
|
|
1687
1769
|
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
1688
1770
|
};
|
|
1689
1771
|
};
|
|
1690
|
-
var
|
|
1772
|
+
var isAvailable8 = (provider) => {
|
|
1691
1773
|
return !!provider.readFile && !!provider.writeFile;
|
|
1692
1774
|
};
|
|
1693
1775
|
var replaceInFile_default = {
|
|
1694
|
-
...
|
|
1695
|
-
handler:
|
|
1696
|
-
isAvailable:
|
|
1776
|
+
...toolInfo8,
|
|
1777
|
+
handler: handler8,
|
|
1778
|
+
isAvailable: isAvailable8
|
|
1697
1779
|
};
|
|
1698
1780
|
|
|
1699
1781
|
// src/tools/searchFiles.ts
|
|
1700
|
-
var
|
|
1782
|
+
var toolInfo9 = {
|
|
1701
1783
|
name: "search_files",
|
|
1702
1784
|
description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
|
1703
1785
|
parameters: [
|
|
@@ -1741,7 +1823,7 @@ var toolInfo8 = {
|
|
|
1741
1823
|
],
|
|
1742
1824
|
permissionLevel: 1 /* Read */
|
|
1743
1825
|
};
|
|
1744
|
-
var
|
|
1826
|
+
var handler9 = async (provider, args) => {
|
|
1745
1827
|
if (!provider.searchFiles) {
|
|
1746
1828
|
return {
|
|
1747
1829
|
type: "Error" /* Error */,
|
|
@@ -1763,13 +1845,13 @@ ${files.join("\n")}
|
|
|
1763
1845
|
`
|
|
1764
1846
|
};
|
|
1765
1847
|
};
|
|
1766
|
-
var
|
|
1848
|
+
var isAvailable9 = (provider) => {
|
|
1767
1849
|
return !!provider.searchFiles;
|
|
1768
1850
|
};
|
|
1769
1851
|
var searchFiles_default = {
|
|
1770
|
-
...
|
|
1771
|
-
handler:
|
|
1772
|
-
isAvailable:
|
|
1852
|
+
...toolInfo9,
|
|
1853
|
+
handler: handler9,
|
|
1854
|
+
isAvailable: isAvailable9
|
|
1773
1855
|
};
|
|
1774
1856
|
|
|
1775
1857
|
// src/tools/updateKnowledge.ts
|
|
@@ -1826,7 +1908,7 @@ function join(...parts) {
|
|
|
1826
1908
|
}
|
|
1827
1909
|
|
|
1828
1910
|
// src/tools/updateKnowledge.ts
|
|
1829
|
-
var
|
|
1911
|
+
var toolInfo10 = {
|
|
1830
1912
|
name: "update_knowledge",
|
|
1831
1913
|
description: "Update knowledge in a knowledge.ai.yml file with smart merging capabilities. This tool lets you add, update, or remove information using path-based updates and special directives.",
|
|
1832
1914
|
parameters: [
|
|
@@ -2000,7 +2082,7 @@ function deepMerge(target, source) {
|
|
|
2000
2082
|
}
|
|
2001
2083
|
return output;
|
|
2002
2084
|
}
|
|
2003
|
-
var
|
|
2085
|
+
var handler10 = async (provider, args) => {
|
|
2004
2086
|
if (!provider.readFile || !provider.writeFile) {
|
|
2005
2087
|
return {
|
|
2006
2088
|
type: "Error" /* Error */,
|
|
@@ -2072,19 +2154,19 @@ var handler9 = async (provider, args) => {
|
|
|
2072
2154
|
};
|
|
2073
2155
|
}
|
|
2074
2156
|
};
|
|
2075
|
-
var
|
|
2157
|
+
var isAvailable10 = (provider) => {
|
|
2076
2158
|
return !!provider.readFile && !!provider.writeFile;
|
|
2077
2159
|
};
|
|
2078
2160
|
var updateKnowledge_default = {
|
|
2079
|
-
...
|
|
2080
|
-
handler:
|
|
2081
|
-
isAvailable:
|
|
2161
|
+
...toolInfo10,
|
|
2162
|
+
handler: handler10,
|
|
2163
|
+
isAvailable: isAvailable10
|
|
2082
2164
|
};
|
|
2083
2165
|
|
|
2084
2166
|
// src/tools/writeToFile.ts
|
|
2085
|
-
var
|
|
2167
|
+
var toolInfo11 = {
|
|
2086
2168
|
name: "write_to_file",
|
|
2087
|
-
description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `<
|
|
2169
|
+
description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `<`, `>`, or `&`. Also ensure there is no unwanted CDATA tags in the content.",
|
|
2088
2170
|
parameters: [
|
|
2089
2171
|
{
|
|
2090
2172
|
name: "path",
|
|
@@ -2127,7 +2209,7 @@ export default App;
|
|
|
2127
2209
|
],
|
|
2128
2210
|
permissionLevel: 2 /* Write */
|
|
2129
2211
|
};
|
|
2130
|
-
var
|
|
2212
|
+
var handler11 = async (provider, args) => {
|
|
2131
2213
|
if (!provider.writeFile) {
|
|
2132
2214
|
return {
|
|
2133
2215
|
type: "Error" /* Error */,
|
|
@@ -2135,24 +2217,26 @@ var handler10 = async (provider, args) => {
|
|
|
2135
2217
|
};
|
|
2136
2218
|
}
|
|
2137
2219
|
const path = getString(args, "path");
|
|
2138
|
-
|
|
2220
|
+
let content = getString(args, "content");
|
|
2221
|
+
const trimmedContent = content.trim();
|
|
2222
|
+
if (trimmedContent.startsWith("<![CDATA[") && content.endsWith("]]>")) content = trimmedContent.slice(9, -3);
|
|
2139
2223
|
await provider.writeFile(path, content);
|
|
2140
2224
|
return {
|
|
2141
2225
|
type: "Reply" /* Reply */,
|
|
2142
2226
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
2143
2227
|
};
|
|
2144
2228
|
};
|
|
2145
|
-
var
|
|
2229
|
+
var isAvailable11 = (provider) => {
|
|
2146
2230
|
return !!provider.writeFile;
|
|
2147
2231
|
};
|
|
2148
2232
|
var writeToFile_default = {
|
|
2149
|
-
...
|
|
2150
|
-
handler:
|
|
2151
|
-
isAvailable:
|
|
2233
|
+
...toolInfo11,
|
|
2234
|
+
handler: handler11,
|
|
2235
|
+
isAvailable: isAvailable11
|
|
2152
2236
|
};
|
|
2153
2237
|
|
|
2154
2238
|
// src/tools/handOver.ts
|
|
2155
|
-
var
|
|
2239
|
+
var toolInfo12 = {
|
|
2156
2240
|
name: "hand_over",
|
|
2157
2241
|
description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
|
|
2158
2242
|
parameters: [
|
|
@@ -2206,7 +2290,7 @@ var toolInfo11 = {
|
|
|
2206
2290
|
],
|
|
2207
2291
|
permissionLevel: 0 /* None */
|
|
2208
2292
|
};
|
|
2209
|
-
var
|
|
2293
|
+
var handler12 = async (_provider, args) => {
|
|
2210
2294
|
const agentName = getString(args, "agent_name");
|
|
2211
2295
|
const task = getString(args, "task");
|
|
2212
2296
|
const context = getString(args, "context", void 0);
|
|
@@ -2219,17 +2303,17 @@ var handler11 = async (_provider, args) => {
|
|
|
2219
2303
|
files
|
|
2220
2304
|
};
|
|
2221
2305
|
};
|
|
2222
|
-
var
|
|
2306
|
+
var isAvailable12 = (_provider) => {
|
|
2223
2307
|
return true;
|
|
2224
2308
|
};
|
|
2225
2309
|
var handOver_default = {
|
|
2226
|
-
...
|
|
2227
|
-
handler:
|
|
2228
|
-
isAvailable:
|
|
2310
|
+
...toolInfo12,
|
|
2311
|
+
handler: handler12,
|
|
2312
|
+
isAvailable: isAvailable12
|
|
2229
2313
|
};
|
|
2230
2314
|
|
|
2231
2315
|
// src/tools/removeFile.ts
|
|
2232
|
-
var
|
|
2316
|
+
var toolInfo13 = {
|
|
2233
2317
|
name: "remove_file",
|
|
2234
2318
|
description: "Request to remove a file at the specified path.",
|
|
2235
2319
|
parameters: [
|
|
@@ -2253,7 +2337,7 @@ var toolInfo12 = {
|
|
|
2253
2337
|
],
|
|
2254
2338
|
permissionLevel: 2 /* Write */
|
|
2255
2339
|
};
|
|
2256
|
-
var
|
|
2340
|
+
var handler13 = async (provider, args) => {
|
|
2257
2341
|
if (!provider.removeFile) {
|
|
2258
2342
|
return {
|
|
2259
2343
|
type: "Error" /* Error */,
|
|
@@ -2267,17 +2351,17 @@ var handler12 = async (provider, args) => {
|
|
|
2267
2351
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
2268
2352
|
};
|
|
2269
2353
|
};
|
|
2270
|
-
var
|
|
2354
|
+
var isAvailable13 = (provider) => {
|
|
2271
2355
|
return !!provider.removeFile;
|
|
2272
2356
|
};
|
|
2273
2357
|
var removeFile_default = {
|
|
2274
|
-
...
|
|
2275
|
-
handler:
|
|
2276
|
-
isAvailable:
|
|
2358
|
+
...toolInfo13,
|
|
2359
|
+
handler: handler13,
|
|
2360
|
+
isAvailable: isAvailable13
|
|
2277
2361
|
};
|
|
2278
2362
|
|
|
2279
2363
|
// src/tools/renameFile.ts
|
|
2280
|
-
var
|
|
2364
|
+
var toolInfo14 = {
|
|
2281
2365
|
name: "rename_file",
|
|
2282
2366
|
description: "Request to rename a file from source path to target path.",
|
|
2283
2367
|
parameters: [
|
|
@@ -2311,7 +2395,7 @@ var toolInfo13 = {
|
|
|
2311
2395
|
],
|
|
2312
2396
|
permissionLevel: 2 /* Write */
|
|
2313
2397
|
};
|
|
2314
|
-
var
|
|
2398
|
+
var handler14 = async (provider, args) => {
|
|
2315
2399
|
if (!provider.renameFile) {
|
|
2316
2400
|
return {
|
|
2317
2401
|
type: "Error" /* Error */,
|
|
@@ -2326,13 +2410,13 @@ var handler13 = async (provider, args) => {
|
|
|
2326
2410
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
2327
2411
|
};
|
|
2328
2412
|
};
|
|
2329
|
-
var
|
|
2413
|
+
var isAvailable14 = (provider) => {
|
|
2330
2414
|
return !!provider.renameFile;
|
|
2331
2415
|
};
|
|
2332
2416
|
var renameFile_default = {
|
|
2333
|
-
...
|
|
2334
|
-
handler:
|
|
2335
|
-
isAvailable:
|
|
2417
|
+
...toolInfo14,
|
|
2418
|
+
handler: handler14,
|
|
2419
|
+
isAvailable: isAvailable14
|
|
2336
2420
|
};
|
|
2337
2421
|
|
|
2338
2422
|
// src/getAvailableTools.ts
|
|
@@ -2684,13 +2768,34 @@ ${joined}`;
|
|
|
2684
2768
|
};
|
|
2685
2769
|
var responsePrompts = {
|
|
2686
2770
|
errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
|
|
2687
|
-
requireUseTool:
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2771
|
+
requireUseTool: `Error: No tool use detected. You MUST use a tool before proceeding.
|
|
2772
|
+
e.g. <tool_tool_name>tool_name</tool_tool_name>
|
|
2773
|
+
|
|
2774
|
+
Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
|
|
2775
|
+
Avoid unnecessary text or symbols before or after the tool use.
|
|
2776
|
+
Avoid unnecessary escape characters or special characters.
|
|
2777
|
+
`,
|
|
2778
|
+
toolResults: (tool, result) => {
|
|
2779
|
+
if (typeof result === "string") {
|
|
2780
|
+
return [
|
|
2781
|
+
{
|
|
2782
|
+
type: "text",
|
|
2783
|
+
text: `<tool_response name=${tool}>${result}</tool_response>`
|
|
2784
|
+
}
|
|
2785
|
+
];
|
|
2786
|
+
}
|
|
2787
|
+
return [
|
|
2788
|
+
{
|
|
2789
|
+
type: "text",
|
|
2790
|
+
text: `<tool_response name=${tool}>`
|
|
2791
|
+
},
|
|
2792
|
+
...result,
|
|
2793
|
+
{
|
|
2794
|
+
type: "text",
|
|
2795
|
+
text: "</tool_response>"
|
|
2796
|
+
}
|
|
2797
|
+
];
|
|
2798
|
+
},
|
|
2694
2799
|
commandResult: (command, exitCode, stdout, stderr) => `<command>${command}</command>
|
|
2695
2800
|
<command_exit_code>${exitCode}</command_exit_code>
|
|
2696
2801
|
<command_stdout>
|
|
@@ -2872,23 +2977,26 @@ ${instance.prompt}`;
|
|
|
2872
2977
|
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
2873
2978
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
2874
2979
|
switch (toolResp.type) {
|
|
2875
|
-
case "Reply" /* Reply */:
|
|
2980
|
+
case "Reply" /* Reply */: {
|
|
2876
2981
|
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
2877
2982
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
2878
2983
|
break;
|
|
2984
|
+
}
|
|
2879
2985
|
case "Exit" /* Exit */:
|
|
2880
2986
|
if (toolResponses.length > 0) {
|
|
2881
2987
|
break outer;
|
|
2882
2988
|
}
|
|
2883
2989
|
return { type: "exit", reason: toolResp };
|
|
2884
|
-
case "Invalid" /* Invalid */:
|
|
2990
|
+
case "Invalid" /* Invalid */: {
|
|
2885
2991
|
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
2886
2992
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
2887
2993
|
break outer;
|
|
2888
|
-
|
|
2994
|
+
}
|
|
2995
|
+
case "Error" /* Error */: {
|
|
2889
2996
|
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
2890
2997
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
2891
2998
|
break outer;
|
|
2999
|
+
}
|
|
2892
3000
|
case "Interrupted" /* Interrupted */:
|
|
2893
3001
|
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
2894
3002
|
return { type: "exit", reason: toolResp };
|
|
@@ -2938,13 +3046,13 @@ ${instance.prompt}`;
|
|
|
2938
3046
|
if (toolResponses.length === 0) {
|
|
2939
3047
|
return { type: "reply", message: responsePrompts.requireUseTool };
|
|
2940
3048
|
}
|
|
2941
|
-
const finalResp = toolResponses.filter((resp) => resp.type === "response").
|
|
3049
|
+
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
|
|
2942
3050
|
return { type: "reply", message: finalResp };
|
|
2943
3051
|
}
|
|
2944
3052
|
async #invokeTool(name, args) {
|
|
2945
3053
|
try {
|
|
2946
|
-
const
|
|
2947
|
-
if (!
|
|
3054
|
+
const handler15 = this.handlers[name]?.handler;
|
|
3055
|
+
if (!handler15) {
|
|
2948
3056
|
return {
|
|
2949
3057
|
type: "Error" /* Error */,
|
|
2950
3058
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -2963,7 +3071,7 @@ ${instance.prompt}`;
|
|
|
2963
3071
|
if (resp) {
|
|
2964
3072
|
return resp;
|
|
2965
3073
|
}
|
|
2966
|
-
return await
|
|
3074
|
+
return await handler15(this.config.provider, args);
|
|
2967
3075
|
} catch (error) {
|
|
2968
3076
|
return {
|
|
2969
3077
|
type: "Error" /* Error */,
|
|
@@ -4290,6 +4398,7 @@ export {
|
|
|
4290
4398
|
executeAgentTool,
|
|
4291
4399
|
executeCommand_default as executeCommand,
|
|
4292
4400
|
executeTool,
|
|
4401
|
+
fetchUrl_default as fetchUrl,
|
|
4293
4402
|
generateGitCommitMessage,
|
|
4294
4403
|
generateGithubPullRequestDetails,
|
|
4295
4404
|
generateProjectConfig,
|