@agentforge/core 0.16.35 → 0.16.36

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 CHANGED
@@ -841,29 +841,6 @@ function toolBuilder() {
841
841
  return new ToolBuilder();
842
842
  }
843
843
 
844
- // src/tools/registry-collection.ts
845
- function getAllRegistryTools(tools) {
846
- return Array.from(tools.values());
847
- }
848
- function getRegistryToolNames(tools) {
849
- return Array.from(tools.keys());
850
- }
851
- function getRegistryToolsByCategory(tools, category) {
852
- return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
853
- }
854
- function getRegistryToolsByTag(tools, tag) {
855
- return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
856
- }
857
- function searchRegistryTools(tools, query) {
858
- const lowerQuery = query.toLowerCase();
859
- return getAllRegistryTools(tools).filter((tool) => {
860
- const name = tool.metadata.name.toLowerCase();
861
- const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
862
- const description = tool.metadata.description.toLowerCase();
863
- return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
864
- });
865
- }
866
-
867
844
  // src/langgraph/observability/logger.ts
868
845
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
869
846
  LogLevel2["DEBUG"] = "debug";
@@ -1064,6 +1041,40 @@ function clearRegistryTools(tools, emit, events) {
1064
1041
  emit(events.cleared, null);
1065
1042
  }
1066
1043
 
1044
+ // src/tools/registry-mutation-api.ts
1045
+ function createRegistryMutationApi(tools, emit, events) {
1046
+ return {
1047
+ register: (tool) => registerRegistryTool(tools, tool, emit, events),
1048
+ remove: (name) => removeRegistryTool(tools, name, emit, events),
1049
+ update: (name, tool) => updateRegistryTool(tools, name, tool, emit, events),
1050
+ registerMany: (toolsToRegister) => registerManyRegistryTools(tools, toolsToRegister, emit, events),
1051
+ clear: () => clearRegistryTools(tools, emit, events)
1052
+ };
1053
+ }
1054
+
1055
+ // src/tools/registry-collection.ts
1056
+ function getAllRegistryTools(tools) {
1057
+ return Array.from(tools.values());
1058
+ }
1059
+ function getRegistryToolNames(tools) {
1060
+ return Array.from(tools.keys());
1061
+ }
1062
+ function getRegistryToolsByCategory(tools, category) {
1063
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
1064
+ }
1065
+ function getRegistryToolsByTag(tools, tag) {
1066
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
1067
+ }
1068
+ function searchRegistryTools(tools, query) {
1069
+ const lowerQuery = query.toLowerCase();
1070
+ return getAllRegistryTools(tools).filter((tool) => {
1071
+ const name = tool.metadata.name.toLowerCase();
1072
+ const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
1073
+ const description = tool.metadata.description.toLowerCase();
1074
+ return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
1075
+ });
1076
+ }
1077
+
1067
1078
  // src/tools/registry-prompt.ts
1068
1079
  var import_zod3 = require("zod");
1069
1080
 
@@ -1326,7 +1337,23 @@ function getSchemaShape(schema) {
1326
1337
  return void 0;
1327
1338
  }
1328
1339
 
1329
- // src/tools/registry.ts
1340
+ // src/tools/registry-query-api.ts
1341
+ function createRegistryQueryApi(tools) {
1342
+ return {
1343
+ get: (name) => tools.get(name),
1344
+ has: (name) => tools.has(name),
1345
+ getAll: () => getAllRegistryTools(tools),
1346
+ getByCategory: (category) => getRegistryToolsByCategory(tools, category),
1347
+ getByTag: (tag) => getRegistryToolsByTag(tools, tag),
1348
+ search: (query) => searchRegistryTools(tools, query),
1349
+ size: () => tools.size,
1350
+ getNames: () => getRegistryToolNames(tools),
1351
+ toLangChainTools: () => convertRegistryToolsToLangChain(getAllRegistryTools(tools)),
1352
+ generatePrompt: (options = {}) => generateRegistryPrompt(getAllRegistryTools(tools), options)
1353
+ };
1354
+ }
1355
+
1356
+ // src/tools/registry-types.ts
1330
1357
  var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1331
1358
  RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
1332
1359
  RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
@@ -1334,6 +1361,8 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1334
1361
  RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
1335
1362
  return RegistryEvent2;
1336
1363
  })(RegistryEvent || {});
1364
+
1365
+ // src/tools/registry.ts
1337
1366
  var ToolRegistry = class {
1338
1367
  tools = /* @__PURE__ */ new Map();
1339
1368
  eventHandlers = /* @__PURE__ */ new Map();
@@ -1346,291 +1375,65 @@ var ToolRegistry = class {
1346
1375
  emitMutation = (event, data) => {
1347
1376
  this.emit(event, data);
1348
1377
  };
1349
- /**
1350
- * Register a tool in the registry
1351
- *
1352
- * @param tool - The tool to register
1353
- * @throws Error if a tool with the same name already exists
1354
- *
1355
- * @example
1356
- * ```ts
1357
- * registry.register(readFileTool);
1358
- * ```
1359
- */
1378
+ mutations;
1379
+ queries;
1380
+ constructor() {
1381
+ this.mutations = createRegistryMutationApi(this.tools, this.emitMutation, this.mutationEvents);
1382
+ this.queries = createRegistryQueryApi(this.tools);
1383
+ }
1360
1384
  register(tool) {
1361
- registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
1385
+ this.mutations.register(tool);
1362
1386
  }
1363
- /**
1364
- * Get a tool by name
1365
- *
1366
- * @param name - The tool name
1367
- * @returns The tool, or undefined if not found
1368
- *
1369
- * @example
1370
- * ```ts
1371
- * const tool = registry.get('read-file');
1372
- * if (tool) {
1373
- * const result = await tool.execute({ path: './file.txt' });
1374
- * }
1375
- * ```
1376
- */
1377
1387
  get(name) {
1378
- return this.tools.get(name);
1388
+ return this.queries.get(name);
1379
1389
  }
1380
- /**
1381
- * Check if a tool exists in the registry
1382
- *
1383
- * @param name - The tool name
1384
- * @returns True if the tool exists
1385
- *
1386
- * @example
1387
- * ```ts
1388
- * if (registry.has('read-file')) {
1389
- * console.log('Tool exists!');
1390
- * }
1391
- * ```
1392
- */
1393
1390
  has(name) {
1394
- return this.tools.has(name);
1391
+ return this.queries.has(name);
1395
1392
  }
1396
- /**
1397
- * Remove a tool from the registry
1398
- *
1399
- * @param name - The tool name
1400
- * @returns True if the tool was removed, false if it didn't exist
1401
- *
1402
- * @example
1403
- * ```ts
1404
- * const removed = registry.remove('read-file');
1405
- * console.log(removed ? 'Removed' : 'Not found');
1406
- * ```
1407
- */
1408
1393
  remove(name) {
1409
- return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
1394
+ return this.mutations.remove(name);
1410
1395
  }
1411
- /**
1412
- * Update an existing tool
1413
- *
1414
- * @param name - The tool name
1415
- * @param tool - The new tool definition
1416
- * @returns True if updated, false if the tool didn't exist
1417
- * @throws Error if the tool's metadata.name doesn't match the name parameter
1418
- *
1419
- * @example
1420
- * ```ts
1421
- * const updated = registry.update('read-file', newReadFileTool);
1422
- * ```
1423
- */
1424
1396
  update(name, tool) {
1425
- return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
1397
+ return this.mutations.update(name, tool);
1426
1398
  }
1427
- /**
1428
- * Get all registered tools
1429
- *
1430
- * @returns Array of all tools
1431
- *
1432
- * @example
1433
- * ```ts
1434
- * const allTools = registry.getAll();
1435
- * console.log(`Total tools: ${allTools.length}`);
1436
- * ```
1437
- */
1438
1399
  getAll() {
1439
- return getAllRegistryTools(this.tools);
1400
+ return this.queries.getAll();
1440
1401
  }
1441
- /**
1442
- * Get tools by category
1443
- *
1444
- * @param category - The tool category
1445
- * @returns Array of tools in the category
1446
- *
1447
- * @example
1448
- * ```ts
1449
- * const fileTools = registry.getByCategory(ToolCategory.FILE_SYSTEM);
1450
- * ```
1451
- */
1452
1402
  getByCategory(category) {
1453
- return getRegistryToolsByCategory(this.tools, category);
1403
+ return this.queries.getByCategory(category);
1454
1404
  }
1455
- /**
1456
- * Get tools by tag
1457
- *
1458
- * @param tag - The tag to search for
1459
- * @returns Array of tools with the tag
1460
- *
1461
- * @example
1462
- * ```ts
1463
- * const fileTools = registry.getByTag('file');
1464
- * ```
1465
- */
1466
1405
  getByTag(tag) {
1467
- return getRegistryToolsByTag(this.tools, tag);
1406
+ return this.queries.getByTag(tag);
1468
1407
  }
1469
- /**
1470
- * Search tools by name or description
1471
- *
1472
- * Case-insensitive search across tool names, display names, and descriptions.
1473
- *
1474
- * @param query - The search query
1475
- * @returns Array of matching tools
1476
- *
1477
- * @example
1478
- * ```ts
1479
- * const results = registry.search('file');
1480
- * // Returns tools with 'file' in name or description
1481
- * ```
1482
- */
1483
1408
  search(query) {
1484
- return searchRegistryTools(this.tools, query);
1409
+ return this.queries.search(query);
1485
1410
  }
1486
- /**
1487
- * Register multiple tools at once
1488
- *
1489
- * @param tools - Iterable of tools to register
1490
- * @throws Error if any tool name conflicts with existing tools
1491
- *
1492
- * @example
1493
- * ```ts
1494
- * registry.registerMany([tool1, tool2, tool3]);
1495
- * ```
1496
- */
1497
1411
  registerMany(tools) {
1498
- registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
1412
+ this.mutations.registerMany(tools);
1499
1413
  }
1500
- /**
1501
- * Clear all tools from the registry
1502
- *
1503
- * @example
1504
- * ```ts
1505
- * registry.clear();
1506
- * console.log(registry.size()); // 0
1507
- * ```
1508
- */
1509
1414
  clear() {
1510
- clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
1415
+ this.mutations.clear();
1511
1416
  }
1512
- /**
1513
- * Get the number of registered tools
1514
- *
1515
- * @returns Number of tools in the registry
1516
- *
1517
- * @example
1518
- * ```ts
1519
- * console.log(`Registry has ${registry.size()} tools`);
1520
- * ```
1521
- */
1522
1417
  size() {
1523
- return this.tools.size;
1418
+ return this.queries.size();
1524
1419
  }
1525
- /**
1526
- * Get all tool names
1527
- *
1528
- * @returns Array of tool names
1529
- *
1530
- * @example
1531
- * ```ts
1532
- * const names = registry.getNames();
1533
- * console.log('Available tools:', names.join(', '));
1534
- * ```
1535
- */
1536
1420
  getNames() {
1537
- return getRegistryToolNames(this.tools);
1421
+ return this.queries.getNames();
1538
1422
  }
1539
- /**
1540
- * Register an event handler
1541
- *
1542
- * @param event - The event to listen for
1543
- * @param handler - The handler function
1544
- *
1545
- * @example
1546
- * ```ts
1547
- * registry.on(RegistryEvent.TOOL_REGISTERED, (tool) => {
1548
- * console.log('New tool:', tool.metadata.name);
1549
- * });
1550
- * ```
1551
- */
1552
1423
  on(event, handler) {
1553
1424
  addRegistryEventHandler(this.eventHandlers, event, handler);
1554
1425
  }
1555
- /**
1556
- * Unregister an event handler
1557
- *
1558
- * @param event - The event to stop listening for
1559
- * @param handler - The handler function to remove
1560
- *
1561
- * @example
1562
- * ```ts
1563
- * const handler = (tool) => console.log(tool);
1564
- * registry.on(RegistryEvent.TOOL_REGISTERED, handler);
1565
- * registry.off(RegistryEvent.TOOL_REGISTERED, handler);
1566
- * ```
1567
- */
1568
1426
  off(event, handler) {
1569
1427
  removeRegistryEventHandler(this.eventHandlers, event, handler);
1570
1428
  }
1571
- /**
1572
- * Emit an event to all registered handlers
1573
- *
1574
- * @param event - The event to emit
1575
- * @param data - The event data
1576
- * @private
1577
- */
1578
1429
  emit(event, data) {
1579
1430
  emitRegistryEvent(this.eventHandlers, event, data);
1580
1431
  }
1581
- /**
1582
- * Convert all registered tools to LangChain format
1583
- *
1584
- * This allows the entire registry to be used with LangChain agents.
1585
- *
1586
- * @returns Array of LangChain DynamicStructuredTools
1587
- *
1588
- * @example
1589
- * ```ts
1590
- * const registry = new ToolRegistry();
1591
- * registry.registerMany([tool1, tool2, tool3]);
1592
- *
1593
- * const langchainTools = registry.toLangChainTools();
1594
- *
1595
- * const agent = createAgent({
1596
- * model: new ChatOpenAI(),
1597
- * tools: langchainTools,
1598
- * });
1599
- * ```
1600
- */
1601
1432
  toLangChainTools() {
1602
- return convertRegistryToolsToLangChain(this.getAll());
1433
+ return this.queries.toLangChainTools();
1603
1434
  }
1604
- /**
1605
- * Generate a formatted prompt describing all tools
1606
- *
1607
- * Creates a human-readable description of all tools in the registry,
1608
- * suitable for inclusion in LLM prompts.
1609
- *
1610
- * @param options - Options for customizing the prompt
1611
- * @returns Formatted prompt string
1612
- *
1613
- * @example
1614
- * ```ts
1615
- * const prompt = registry.generatePrompt({
1616
- * includeExamples: true,
1617
- * groupByCategory: true,
1618
- * maxExamplesPerTool: 2,
1619
- * });
1620
- *
1621
- * console.log(prompt);
1622
- * // Available Tools:
1623
- * //
1624
- * // FILE SYSTEM TOOLS:
1625
- * // - read-file: Read a file from the file system
1626
- * // Parameters: path (string)
1627
- * // Example: Read a text file
1628
- * // Input: { "path": "./README.md" }
1629
- * // ...
1630
- * ```
1631
- */
1632
1435
  generatePrompt(options = {}) {
1633
- return generateRegistryPrompt(this.getAll(), options);
1436
+ return this.queries.generatePrompt(options);
1634
1437
  }
1635
1438
  };
1636
1439