@agentforge/core 0.16.17 → 0.16.18
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/index.cjs +104 -80
- package/dist/index.d.cts +19 -17
- package/dist/index.d.ts +19 -17
- package/dist/index.js +104 -80
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -991,6 +991,79 @@ function emitRegistryEvent(eventHandlers, event, data) {
|
|
|
991
991
|
});
|
|
992
992
|
}
|
|
993
993
|
|
|
994
|
+
// src/tools/registry-mutations.ts
|
|
995
|
+
function eraseToolType(tool) {
|
|
996
|
+
return tool;
|
|
997
|
+
}
|
|
998
|
+
function registerRegistryTool(tools, tool, emit, events) {
|
|
999
|
+
const name = tool.metadata.name;
|
|
1000
|
+
if (tools.has(name)) {
|
|
1001
|
+
throw new Error(
|
|
1002
|
+
`Tool with name "${name}" is already registered. Use update() to modify it.`
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
tools.set(name, eraseToolType(tool));
|
|
1006
|
+
emit(events.registered, tool);
|
|
1007
|
+
}
|
|
1008
|
+
function removeRegistryTool(tools, name, emit, events) {
|
|
1009
|
+
const tool = tools.get(name);
|
|
1010
|
+
if (!tool) {
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
tools.delete(name);
|
|
1014
|
+
emit(events.removed, tool);
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
function updateRegistryTool(tools, name, tool, emit, events) {
|
|
1018
|
+
if (!tools.has(name)) {
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
if (tool.metadata.name !== name) {
|
|
1022
|
+
throw new Error(
|
|
1023
|
+
`Cannot update tool: metadata.name "${tool.metadata.name}" does not match registry key "${name}". To rename a tool, remove it and register it again with the new name.`
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
tools.set(name, eraseToolType(tool));
|
|
1027
|
+
emit(events.updated, { name, tool });
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
function registerManyRegistryTools(tools, toolsToRegister, emit, events) {
|
|
1031
|
+
const pendingTools = Array.from(toolsToRegister);
|
|
1032
|
+
const inputNames = /* @__PURE__ */ new Set();
|
|
1033
|
+
const duplicatesInInput = [];
|
|
1034
|
+
for (const tool of pendingTools) {
|
|
1035
|
+
const name = tool.metadata.name;
|
|
1036
|
+
if (inputNames.has(name)) {
|
|
1037
|
+
duplicatesInInput.push(name);
|
|
1038
|
+
} else {
|
|
1039
|
+
inputNames.add(name);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (duplicatesInInput.length > 0) {
|
|
1043
|
+
throw new Error(
|
|
1044
|
+
`Cannot register tools: duplicate names in input list: ${duplicatesInInput.join(", ")}`
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
const conflicts = [];
|
|
1048
|
+
for (const tool of pendingTools) {
|
|
1049
|
+
if (tools.has(tool.metadata.name)) {
|
|
1050
|
+
conflicts.push(tool.metadata.name);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
if (conflicts.length > 0) {
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
`Cannot register tools: the following names already exist: ${conflicts.join(", ")}`
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
for (const tool of pendingTools) {
|
|
1059
|
+
registerRegistryTool(tools, tool, emit, events);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
function clearRegistryTools(tools, emit, events) {
|
|
1063
|
+
tools.clear();
|
|
1064
|
+
emit(events.cleared, null);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
994
1067
|
// src/tools/registry-prompt.ts
|
|
995
1068
|
var import_zod3 = require("zod");
|
|
996
1069
|
|
|
@@ -1261,33 +1334,31 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
|
|
|
1261
1334
|
RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
|
|
1262
1335
|
return RegistryEvent2;
|
|
1263
1336
|
})(RegistryEvent || {});
|
|
1264
|
-
function eraseToolType(tool) {
|
|
1265
|
-
return tool;
|
|
1266
|
-
}
|
|
1267
1337
|
var ToolRegistry = class {
|
|
1268
1338
|
tools = /* @__PURE__ */ new Map();
|
|
1269
1339
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
1340
|
+
mutationEvents = {
|
|
1341
|
+
registered: "tool:registered" /* TOOL_REGISTERED */,
|
|
1342
|
+
removed: "tool:removed" /* TOOL_REMOVED */,
|
|
1343
|
+
updated: "tool:updated" /* TOOL_UPDATED */,
|
|
1344
|
+
cleared: "registry:cleared" /* REGISTRY_CLEARED */
|
|
1345
|
+
};
|
|
1346
|
+
emitMutation = (event, data) => {
|
|
1347
|
+
this.emit(event, data);
|
|
1348
|
+
};
|
|
1270
1349
|
/**
|
|
1271
1350
|
* Register a tool in the registry
|
|
1272
1351
|
*
|
|
1273
1352
|
* @param tool - The tool to register
|
|
1274
1353
|
* @throws Error if a tool with the same name already exists
|
|
1275
1354
|
*
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```ts
|
|
1357
|
+
* registry.register(readFileTool);
|
|
1279
1358
|
* ```
|
|
1280
1359
|
*/
|
|
1281
1360
|
register(tool) {
|
|
1282
|
-
|
|
1283
|
-
const name = tool.metadata.name;
|
|
1284
|
-
if (this.tools.has(name)) {
|
|
1285
|
-
throw new Error(
|
|
1286
|
-
`Tool with name "${name}" is already registered. Use update() to modify it.`
|
|
1287
|
-
);
|
|
1288
|
-
}
|
|
1289
|
-
this.tools.set(name, erasedTool);
|
|
1290
|
-
this.emit("tool:registered" /* TOOL_REGISTERED */, tool);
|
|
1361
|
+
registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
|
|
1291
1362
|
}
|
|
1292
1363
|
/**
|
|
1293
1364
|
* Get a tool by name
|
|
@@ -1328,20 +1399,14 @@ var ToolRegistry = class {
|
|
|
1328
1399
|
* @param name - The tool name
|
|
1329
1400
|
* @returns True if the tool was removed, false if it didn't exist
|
|
1330
1401
|
*
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* const removed = registry.remove('read-file');
|
|
1405
|
+
* console.log(removed ? 'Removed' : 'Not found');
|
|
1335
1406
|
* ```
|
|
1336
1407
|
*/
|
|
1337
1408
|
remove(name) {
|
|
1338
|
-
|
|
1339
|
-
if (!tool) {
|
|
1340
|
-
return false;
|
|
1341
|
-
}
|
|
1342
|
-
this.tools.delete(name);
|
|
1343
|
-
this.emit("tool:removed" /* TOOL_REMOVED */, tool);
|
|
1344
|
-
return true;
|
|
1409
|
+
return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
|
|
1345
1410
|
}
|
|
1346
1411
|
/**
|
|
1347
1412
|
* Update an existing tool
|
|
@@ -1351,24 +1416,13 @@ var ToolRegistry = class {
|
|
|
1351
1416
|
* @returns True if updated, false if the tool didn't exist
|
|
1352
1417
|
* @throws Error if the tool's metadata.name doesn't match the name parameter
|
|
1353
1418
|
*
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1419
|
+
* @example
|
|
1420
|
+
* ```ts
|
|
1421
|
+
* const updated = registry.update('read-file', newReadFileTool);
|
|
1357
1422
|
* ```
|
|
1358
1423
|
*/
|
|
1359
1424
|
update(name, tool) {
|
|
1360
|
-
|
|
1361
|
-
if (!this.tools.has(name)) {
|
|
1362
|
-
return false;
|
|
1363
|
-
}
|
|
1364
|
-
if (tool.metadata.name !== name) {
|
|
1365
|
-
throw new Error(
|
|
1366
|
-
`Cannot update tool: metadata.name "${tool.metadata.name}" does not match registry key "${name}". To rename a tool, remove it and register it again with the new name.`
|
|
1367
|
-
);
|
|
1368
|
-
}
|
|
1369
|
-
this.tools.set(name, erasedTool);
|
|
1370
|
-
this.emit("tool:updated" /* TOOL_UPDATED */, { name, tool });
|
|
1371
|
-
return true;
|
|
1425
|
+
return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
|
|
1372
1426
|
}
|
|
1373
1427
|
/**
|
|
1374
1428
|
* Get all registered tools
|
|
@@ -1435,55 +1489,25 @@ var ToolRegistry = class {
|
|
|
1435
1489
|
* @param tools - Iterable of tools to register
|
|
1436
1490
|
* @throws Error if any tool name conflicts with existing tools
|
|
1437
1491
|
*
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1492
|
+
* @example
|
|
1493
|
+
* ```ts
|
|
1494
|
+
* registry.registerMany([tool1, tool2, tool3]);
|
|
1441
1495
|
* ```
|
|
1442
1496
|
*/
|
|
1443
1497
|
registerMany(tools) {
|
|
1444
|
-
|
|
1445
|
-
const inputNames = /* @__PURE__ */ new Set();
|
|
1446
|
-
const duplicatesInInput = [];
|
|
1447
|
-
for (const tool of toolsToRegister) {
|
|
1448
|
-
const name = tool.metadata.name;
|
|
1449
|
-
if (inputNames.has(name)) {
|
|
1450
|
-
duplicatesInInput.push(name);
|
|
1451
|
-
} else {
|
|
1452
|
-
inputNames.add(name);
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
if (duplicatesInInput.length > 0) {
|
|
1456
|
-
throw new Error(
|
|
1457
|
-
`Cannot register tools: duplicate names in input list: ${duplicatesInInput.join(", ")}`
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
const conflicts = [];
|
|
1461
|
-
for (const tool of toolsToRegister) {
|
|
1462
|
-
if (this.tools.has(tool.metadata.name)) {
|
|
1463
|
-
conflicts.push(tool.metadata.name);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
if (conflicts.length > 0) {
|
|
1467
|
-
throw new Error(
|
|
1468
|
-
`Cannot register tools: the following names already exist: ${conflicts.join(", ")}`
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
for (const tool of toolsToRegister) {
|
|
1472
|
-
this.register(tool);
|
|
1473
|
-
}
|
|
1498
|
+
registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
|
|
1474
1499
|
}
|
|
1475
1500
|
/**
|
|
1476
1501
|
* Clear all tools from the registry
|
|
1477
1502
|
*
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1503
|
+
* @example
|
|
1504
|
+
* ```ts
|
|
1505
|
+
* registry.clear();
|
|
1506
|
+
* console.log(registry.size()); // 0
|
|
1482
1507
|
* ```
|
|
1483
1508
|
*/
|
|
1484
1509
|
clear() {
|
|
1485
|
-
this.tools.
|
|
1486
|
-
this.emit("registry:cleared" /* REGISTRY_CLEARED */, null);
|
|
1510
|
+
clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
|
|
1487
1511
|
}
|
|
1488
1512
|
/**
|
|
1489
1513
|
* Get the number of registered tools
|
package/dist/index.d.cts
CHANGED
|
@@ -1257,15 +1257,17 @@ interface PromptOptions extends RegistryPromptOptions {
|
|
|
1257
1257
|
declare class ToolRegistry {
|
|
1258
1258
|
private tools;
|
|
1259
1259
|
private eventHandlers;
|
|
1260
|
+
private readonly mutationEvents;
|
|
1261
|
+
private readonly emitMutation;
|
|
1260
1262
|
/**
|
|
1261
1263
|
* Register a tool in the registry
|
|
1262
1264
|
*
|
|
1263
1265
|
* @param tool - The tool to register
|
|
1264
1266
|
* @throws Error if a tool with the same name already exists
|
|
1265
1267
|
*
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```ts
|
|
1270
|
+
* registry.register(readFileTool);
|
|
1269
1271
|
* ```
|
|
1270
1272
|
*/
|
|
1271
1273
|
register<TInput, TOutput>(tool: Tool<TInput, TOutput>): void;
|
|
@@ -1304,10 +1306,10 @@ declare class ToolRegistry {
|
|
|
1304
1306
|
* @param name - The tool name
|
|
1305
1307
|
* @returns True if the tool was removed, false if it didn't exist
|
|
1306
1308
|
*
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1309
|
+
* @example
|
|
1310
|
+
* ```ts
|
|
1311
|
+
* const removed = registry.remove('read-file');
|
|
1312
|
+
* console.log(removed ? 'Removed' : 'Not found');
|
|
1311
1313
|
* ```
|
|
1312
1314
|
*/
|
|
1313
1315
|
remove(name: string): boolean;
|
|
@@ -1319,9 +1321,9 @@ declare class ToolRegistry {
|
|
|
1319
1321
|
* @returns True if updated, false if the tool didn't exist
|
|
1320
1322
|
* @throws Error if the tool's metadata.name doesn't match the name parameter
|
|
1321
1323
|
*
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* const updated = registry.update('read-file', newReadFileTool);
|
|
1325
1327
|
* ```
|
|
1326
1328
|
*/
|
|
1327
1329
|
update<TInput, TOutput>(name: string, tool: Tool<TInput, TOutput>): boolean;
|
|
@@ -1382,19 +1384,19 @@ declare class ToolRegistry {
|
|
|
1382
1384
|
* @param tools - Iterable of tools to register
|
|
1383
1385
|
* @throws Error if any tool name conflicts with existing tools
|
|
1384
1386
|
*
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```ts
|
|
1389
|
+
* registry.registerMany([tool1, tool2, tool3]);
|
|
1388
1390
|
* ```
|
|
1389
1391
|
*/
|
|
1390
1392
|
registerMany(tools: Iterable<RegisterManyTool>): void;
|
|
1391
1393
|
/**
|
|
1392
1394
|
* Clear all tools from the registry
|
|
1393
1395
|
*
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* registry.clear();
|
|
1399
|
+
* console.log(registry.size()); // 0
|
|
1398
1400
|
* ```
|
|
1399
1401
|
*/
|
|
1400
1402
|
clear(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1257,15 +1257,17 @@ interface PromptOptions extends RegistryPromptOptions {
|
|
|
1257
1257
|
declare class ToolRegistry {
|
|
1258
1258
|
private tools;
|
|
1259
1259
|
private eventHandlers;
|
|
1260
|
+
private readonly mutationEvents;
|
|
1261
|
+
private readonly emitMutation;
|
|
1260
1262
|
/**
|
|
1261
1263
|
* Register a tool in the registry
|
|
1262
1264
|
*
|
|
1263
1265
|
* @param tool - The tool to register
|
|
1264
1266
|
* @throws Error if a tool with the same name already exists
|
|
1265
1267
|
*
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```ts
|
|
1270
|
+
* registry.register(readFileTool);
|
|
1269
1271
|
* ```
|
|
1270
1272
|
*/
|
|
1271
1273
|
register<TInput, TOutput>(tool: Tool<TInput, TOutput>): void;
|
|
@@ -1304,10 +1306,10 @@ declare class ToolRegistry {
|
|
|
1304
1306
|
* @param name - The tool name
|
|
1305
1307
|
* @returns True if the tool was removed, false if it didn't exist
|
|
1306
1308
|
*
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1309
|
+
* @example
|
|
1310
|
+
* ```ts
|
|
1311
|
+
* const removed = registry.remove('read-file');
|
|
1312
|
+
* console.log(removed ? 'Removed' : 'Not found');
|
|
1311
1313
|
* ```
|
|
1312
1314
|
*/
|
|
1313
1315
|
remove(name: string): boolean;
|
|
@@ -1319,9 +1321,9 @@ declare class ToolRegistry {
|
|
|
1319
1321
|
* @returns True if updated, false if the tool didn't exist
|
|
1320
1322
|
* @throws Error if the tool's metadata.name doesn't match the name parameter
|
|
1321
1323
|
*
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* const updated = registry.update('read-file', newReadFileTool);
|
|
1325
1327
|
* ```
|
|
1326
1328
|
*/
|
|
1327
1329
|
update<TInput, TOutput>(name: string, tool: Tool<TInput, TOutput>): boolean;
|
|
@@ -1382,19 +1384,19 @@ declare class ToolRegistry {
|
|
|
1382
1384
|
* @param tools - Iterable of tools to register
|
|
1383
1385
|
* @throws Error if any tool name conflicts with existing tools
|
|
1384
1386
|
*
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```ts
|
|
1389
|
+
* registry.registerMany([tool1, tool2, tool3]);
|
|
1388
1390
|
* ```
|
|
1389
1391
|
*/
|
|
1390
1392
|
registerMany(tools: Iterable<RegisterManyTool>): void;
|
|
1391
1393
|
/**
|
|
1392
1394
|
* Clear all tools from the registry
|
|
1393
1395
|
*
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* registry.clear();
|
|
1399
|
+
* console.log(registry.size()); // 0
|
|
1398
1400
|
* ```
|
|
1399
1401
|
*/
|
|
1400
1402
|
clear(): void;
|
package/dist/index.js
CHANGED
|
@@ -816,6 +816,79 @@ function emitRegistryEvent(eventHandlers, event, data) {
|
|
|
816
816
|
});
|
|
817
817
|
}
|
|
818
818
|
|
|
819
|
+
// src/tools/registry-mutations.ts
|
|
820
|
+
function eraseToolType(tool) {
|
|
821
|
+
return tool;
|
|
822
|
+
}
|
|
823
|
+
function registerRegistryTool(tools, tool, emit, events) {
|
|
824
|
+
const name = tool.metadata.name;
|
|
825
|
+
if (tools.has(name)) {
|
|
826
|
+
throw new Error(
|
|
827
|
+
`Tool with name "${name}" is already registered. Use update() to modify it.`
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
tools.set(name, eraseToolType(tool));
|
|
831
|
+
emit(events.registered, tool);
|
|
832
|
+
}
|
|
833
|
+
function removeRegistryTool(tools, name, emit, events) {
|
|
834
|
+
const tool = tools.get(name);
|
|
835
|
+
if (!tool) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
tools.delete(name);
|
|
839
|
+
emit(events.removed, tool);
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
function updateRegistryTool(tools, name, tool, emit, events) {
|
|
843
|
+
if (!tools.has(name)) {
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
if (tool.metadata.name !== name) {
|
|
847
|
+
throw new Error(
|
|
848
|
+
`Cannot update tool: metadata.name "${tool.metadata.name}" does not match registry key "${name}". To rename a tool, remove it and register it again with the new name.`
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
tools.set(name, eraseToolType(tool));
|
|
852
|
+
emit(events.updated, { name, tool });
|
|
853
|
+
return true;
|
|
854
|
+
}
|
|
855
|
+
function registerManyRegistryTools(tools, toolsToRegister, emit, events) {
|
|
856
|
+
const pendingTools = Array.from(toolsToRegister);
|
|
857
|
+
const inputNames = /* @__PURE__ */ new Set();
|
|
858
|
+
const duplicatesInInput = [];
|
|
859
|
+
for (const tool of pendingTools) {
|
|
860
|
+
const name = tool.metadata.name;
|
|
861
|
+
if (inputNames.has(name)) {
|
|
862
|
+
duplicatesInInput.push(name);
|
|
863
|
+
} else {
|
|
864
|
+
inputNames.add(name);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if (duplicatesInInput.length > 0) {
|
|
868
|
+
throw new Error(
|
|
869
|
+
`Cannot register tools: duplicate names in input list: ${duplicatesInInput.join(", ")}`
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
const conflicts = [];
|
|
873
|
+
for (const tool of pendingTools) {
|
|
874
|
+
if (tools.has(tool.metadata.name)) {
|
|
875
|
+
conflicts.push(tool.metadata.name);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (conflicts.length > 0) {
|
|
879
|
+
throw new Error(
|
|
880
|
+
`Cannot register tools: the following names already exist: ${conflicts.join(", ")}`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
for (const tool of pendingTools) {
|
|
884
|
+
registerRegistryTool(tools, tool, emit, events);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
function clearRegistryTools(tools, emit, events) {
|
|
888
|
+
tools.clear();
|
|
889
|
+
emit(events.cleared, null);
|
|
890
|
+
}
|
|
891
|
+
|
|
819
892
|
// src/tools/registry-prompt.ts
|
|
820
893
|
import { z as z3 } from "zod";
|
|
821
894
|
|
|
@@ -1086,33 +1159,31 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
|
|
|
1086
1159
|
RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
|
|
1087
1160
|
return RegistryEvent2;
|
|
1088
1161
|
})(RegistryEvent || {});
|
|
1089
|
-
function eraseToolType(tool) {
|
|
1090
|
-
return tool;
|
|
1091
|
-
}
|
|
1092
1162
|
var ToolRegistry = class {
|
|
1093
1163
|
tools = /* @__PURE__ */ new Map();
|
|
1094
1164
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
1165
|
+
mutationEvents = {
|
|
1166
|
+
registered: "tool:registered" /* TOOL_REGISTERED */,
|
|
1167
|
+
removed: "tool:removed" /* TOOL_REMOVED */,
|
|
1168
|
+
updated: "tool:updated" /* TOOL_UPDATED */,
|
|
1169
|
+
cleared: "registry:cleared" /* REGISTRY_CLEARED */
|
|
1170
|
+
};
|
|
1171
|
+
emitMutation = (event, data) => {
|
|
1172
|
+
this.emit(event, data);
|
|
1173
|
+
};
|
|
1095
1174
|
/**
|
|
1096
1175
|
* Register a tool in the registry
|
|
1097
1176
|
*
|
|
1098
1177
|
* @param tool - The tool to register
|
|
1099
1178
|
* @throws Error if a tool with the same name already exists
|
|
1100
1179
|
*
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1180
|
+
* @example
|
|
1181
|
+
* ```ts
|
|
1182
|
+
* registry.register(readFileTool);
|
|
1104
1183
|
* ```
|
|
1105
1184
|
*/
|
|
1106
1185
|
register(tool) {
|
|
1107
|
-
|
|
1108
|
-
const name = tool.metadata.name;
|
|
1109
|
-
if (this.tools.has(name)) {
|
|
1110
|
-
throw new Error(
|
|
1111
|
-
`Tool with name "${name}" is already registered. Use update() to modify it.`
|
|
1112
|
-
);
|
|
1113
|
-
}
|
|
1114
|
-
this.tools.set(name, erasedTool);
|
|
1115
|
-
this.emit("tool:registered" /* TOOL_REGISTERED */, tool);
|
|
1186
|
+
registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
|
|
1116
1187
|
}
|
|
1117
1188
|
/**
|
|
1118
1189
|
* Get a tool by name
|
|
@@ -1153,20 +1224,14 @@ var ToolRegistry = class {
|
|
|
1153
1224
|
* @param name - The tool name
|
|
1154
1225
|
* @returns True if the tool was removed, false if it didn't exist
|
|
1155
1226
|
*
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* const removed = registry.remove('read-file');
|
|
1230
|
+
* console.log(removed ? 'Removed' : 'Not found');
|
|
1160
1231
|
* ```
|
|
1161
1232
|
*/
|
|
1162
1233
|
remove(name) {
|
|
1163
|
-
|
|
1164
|
-
if (!tool) {
|
|
1165
|
-
return false;
|
|
1166
|
-
}
|
|
1167
|
-
this.tools.delete(name);
|
|
1168
|
-
this.emit("tool:removed" /* TOOL_REMOVED */, tool);
|
|
1169
|
-
return true;
|
|
1234
|
+
return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
|
|
1170
1235
|
}
|
|
1171
1236
|
/**
|
|
1172
1237
|
* Update an existing tool
|
|
@@ -1176,24 +1241,13 @@ var ToolRegistry = class {
|
|
|
1176
1241
|
* @returns True if updated, false if the tool didn't exist
|
|
1177
1242
|
* @throws Error if the tool's metadata.name doesn't match the name parameter
|
|
1178
1243
|
*
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```ts
|
|
1246
|
+
* const updated = registry.update('read-file', newReadFileTool);
|
|
1182
1247
|
* ```
|
|
1183
1248
|
*/
|
|
1184
1249
|
update(name, tool) {
|
|
1185
|
-
|
|
1186
|
-
if (!this.tools.has(name)) {
|
|
1187
|
-
return false;
|
|
1188
|
-
}
|
|
1189
|
-
if (tool.metadata.name !== name) {
|
|
1190
|
-
throw new Error(
|
|
1191
|
-
`Cannot update tool: metadata.name "${tool.metadata.name}" does not match registry key "${name}". To rename a tool, remove it and register it again with the new name.`
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
this.tools.set(name, erasedTool);
|
|
1195
|
-
this.emit("tool:updated" /* TOOL_UPDATED */, { name, tool });
|
|
1196
|
-
return true;
|
|
1250
|
+
return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
|
|
1197
1251
|
}
|
|
1198
1252
|
/**
|
|
1199
1253
|
* Get all registered tools
|
|
@@ -1260,55 +1314,25 @@ var ToolRegistry = class {
|
|
|
1260
1314
|
* @param tools - Iterable of tools to register
|
|
1261
1315
|
* @throws Error if any tool name conflicts with existing tools
|
|
1262
1316
|
*
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1317
|
+
* @example
|
|
1318
|
+
* ```ts
|
|
1319
|
+
* registry.registerMany([tool1, tool2, tool3]);
|
|
1266
1320
|
* ```
|
|
1267
1321
|
*/
|
|
1268
1322
|
registerMany(tools) {
|
|
1269
|
-
|
|
1270
|
-
const inputNames = /* @__PURE__ */ new Set();
|
|
1271
|
-
const duplicatesInInput = [];
|
|
1272
|
-
for (const tool of toolsToRegister) {
|
|
1273
|
-
const name = tool.metadata.name;
|
|
1274
|
-
if (inputNames.has(name)) {
|
|
1275
|
-
duplicatesInInput.push(name);
|
|
1276
|
-
} else {
|
|
1277
|
-
inputNames.add(name);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
if (duplicatesInInput.length > 0) {
|
|
1281
|
-
throw new Error(
|
|
1282
|
-
`Cannot register tools: duplicate names in input list: ${duplicatesInInput.join(", ")}`
|
|
1283
|
-
);
|
|
1284
|
-
}
|
|
1285
|
-
const conflicts = [];
|
|
1286
|
-
for (const tool of toolsToRegister) {
|
|
1287
|
-
if (this.tools.has(tool.metadata.name)) {
|
|
1288
|
-
conflicts.push(tool.metadata.name);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
if (conflicts.length > 0) {
|
|
1292
|
-
throw new Error(
|
|
1293
|
-
`Cannot register tools: the following names already exist: ${conflicts.join(", ")}`
|
|
1294
|
-
);
|
|
1295
|
-
}
|
|
1296
|
-
for (const tool of toolsToRegister) {
|
|
1297
|
-
this.register(tool);
|
|
1298
|
-
}
|
|
1323
|
+
registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
|
|
1299
1324
|
}
|
|
1300
1325
|
/**
|
|
1301
1326
|
* Clear all tools from the registry
|
|
1302
1327
|
*
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1328
|
+
* @example
|
|
1329
|
+
* ```ts
|
|
1330
|
+
* registry.clear();
|
|
1331
|
+
* console.log(registry.size()); // 0
|
|
1307
1332
|
* ```
|
|
1308
1333
|
*/
|
|
1309
1334
|
clear() {
|
|
1310
|
-
this.tools.
|
|
1311
|
-
this.emit("registry:cleared" /* REGISTRY_CLEARED */, null);
|
|
1335
|
+
clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
|
|
1312
1336
|
}
|
|
1313
1337
|
/**
|
|
1314
1338
|
* Get the number of registered tools
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.18",
|
|
4
4
|
"description": "Production-ready TypeScript agent framework built on LangGraph with orchestration, middleware, and typed abstractions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|