@agentforge/core 0.16.34 → 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.js CHANGED
@@ -666,29 +666,6 @@ function toolBuilder() {
666
666
  return new ToolBuilder();
667
667
  }
668
668
 
669
- // src/tools/registry-collection.ts
670
- function getAllRegistryTools(tools) {
671
- return Array.from(tools.values());
672
- }
673
- function getRegistryToolNames(tools) {
674
- return Array.from(tools.keys());
675
- }
676
- function getRegistryToolsByCategory(tools, category) {
677
- return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
678
- }
679
- function getRegistryToolsByTag(tools, tag) {
680
- return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
681
- }
682
- function searchRegistryTools(tools, query) {
683
- const lowerQuery = query.toLowerCase();
684
- return getAllRegistryTools(tools).filter((tool) => {
685
- const name = tool.metadata.name.toLowerCase();
686
- const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
687
- const description = tool.metadata.description.toLowerCase();
688
- return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
689
- });
690
- }
691
-
692
669
  // src/langgraph/observability/logger.ts
693
670
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
694
671
  LogLevel2["DEBUG"] = "debug";
@@ -889,6 +866,40 @@ function clearRegistryTools(tools, emit, events) {
889
866
  emit(events.cleared, null);
890
867
  }
891
868
 
869
+ // src/tools/registry-mutation-api.ts
870
+ function createRegistryMutationApi(tools, emit, events) {
871
+ return {
872
+ register: (tool) => registerRegistryTool(tools, tool, emit, events),
873
+ remove: (name) => removeRegistryTool(tools, name, emit, events),
874
+ update: (name, tool) => updateRegistryTool(tools, name, tool, emit, events),
875
+ registerMany: (toolsToRegister) => registerManyRegistryTools(tools, toolsToRegister, emit, events),
876
+ clear: () => clearRegistryTools(tools, emit, events)
877
+ };
878
+ }
879
+
880
+ // src/tools/registry-collection.ts
881
+ function getAllRegistryTools(tools) {
882
+ return Array.from(tools.values());
883
+ }
884
+ function getRegistryToolNames(tools) {
885
+ return Array.from(tools.keys());
886
+ }
887
+ function getRegistryToolsByCategory(tools, category) {
888
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
889
+ }
890
+ function getRegistryToolsByTag(tools, tag) {
891
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
892
+ }
893
+ function searchRegistryTools(tools, query) {
894
+ const lowerQuery = query.toLowerCase();
895
+ return getAllRegistryTools(tools).filter((tool) => {
896
+ const name = tool.metadata.name.toLowerCase();
897
+ const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
898
+ const description = tool.metadata.description.toLowerCase();
899
+ return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
900
+ });
901
+ }
902
+
892
903
  // src/tools/registry-prompt.ts
893
904
  import { z as z3 } from "zod";
894
905
 
@@ -1151,7 +1162,23 @@ function getSchemaShape(schema) {
1151
1162
  return void 0;
1152
1163
  }
1153
1164
 
1154
- // src/tools/registry.ts
1165
+ // src/tools/registry-query-api.ts
1166
+ function createRegistryQueryApi(tools) {
1167
+ return {
1168
+ get: (name) => tools.get(name),
1169
+ has: (name) => tools.has(name),
1170
+ getAll: () => getAllRegistryTools(tools),
1171
+ getByCategory: (category) => getRegistryToolsByCategory(tools, category),
1172
+ getByTag: (tag) => getRegistryToolsByTag(tools, tag),
1173
+ search: (query) => searchRegistryTools(tools, query),
1174
+ size: () => tools.size,
1175
+ getNames: () => getRegistryToolNames(tools),
1176
+ toLangChainTools: () => convertRegistryToolsToLangChain(getAllRegistryTools(tools)),
1177
+ generatePrompt: (options = {}) => generateRegistryPrompt(getAllRegistryTools(tools), options)
1178
+ };
1179
+ }
1180
+
1181
+ // src/tools/registry-types.ts
1155
1182
  var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1156
1183
  RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
1157
1184
  RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
@@ -1159,6 +1186,8 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1159
1186
  RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
1160
1187
  return RegistryEvent2;
1161
1188
  })(RegistryEvent || {});
1189
+
1190
+ // src/tools/registry.ts
1162
1191
  var ToolRegistry = class {
1163
1192
  tools = /* @__PURE__ */ new Map();
1164
1193
  eventHandlers = /* @__PURE__ */ new Map();
@@ -1171,291 +1200,65 @@ var ToolRegistry = class {
1171
1200
  emitMutation = (event, data) => {
1172
1201
  this.emit(event, data);
1173
1202
  };
1174
- /**
1175
- * Register a tool in the registry
1176
- *
1177
- * @param tool - The tool to register
1178
- * @throws Error if a tool with the same name already exists
1179
- *
1180
- * @example
1181
- * ```ts
1182
- * registry.register(readFileTool);
1183
- * ```
1184
- */
1203
+ mutations;
1204
+ queries;
1205
+ constructor() {
1206
+ this.mutations = createRegistryMutationApi(this.tools, this.emitMutation, this.mutationEvents);
1207
+ this.queries = createRegistryQueryApi(this.tools);
1208
+ }
1185
1209
  register(tool) {
1186
- registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
1210
+ this.mutations.register(tool);
1187
1211
  }
1188
- /**
1189
- * Get a tool by name
1190
- *
1191
- * @param name - The tool name
1192
- * @returns The tool, or undefined if not found
1193
- *
1194
- * @example
1195
- * ```ts
1196
- * const tool = registry.get('read-file');
1197
- * if (tool) {
1198
- * const result = await tool.execute({ path: './file.txt' });
1199
- * }
1200
- * ```
1201
- */
1202
1212
  get(name) {
1203
- return this.tools.get(name);
1213
+ return this.queries.get(name);
1204
1214
  }
1205
- /**
1206
- * Check if a tool exists in the registry
1207
- *
1208
- * @param name - The tool name
1209
- * @returns True if the tool exists
1210
- *
1211
- * @example
1212
- * ```ts
1213
- * if (registry.has('read-file')) {
1214
- * console.log('Tool exists!');
1215
- * }
1216
- * ```
1217
- */
1218
1215
  has(name) {
1219
- return this.tools.has(name);
1216
+ return this.queries.has(name);
1220
1217
  }
1221
- /**
1222
- * Remove a tool from the registry
1223
- *
1224
- * @param name - The tool name
1225
- * @returns True if the tool was removed, false if it didn't exist
1226
- *
1227
- * @example
1228
- * ```ts
1229
- * const removed = registry.remove('read-file');
1230
- * console.log(removed ? 'Removed' : 'Not found');
1231
- * ```
1232
- */
1233
1218
  remove(name) {
1234
- return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
1219
+ return this.mutations.remove(name);
1235
1220
  }
1236
- /**
1237
- * Update an existing tool
1238
- *
1239
- * @param name - The tool name
1240
- * @param tool - The new tool definition
1241
- * @returns True if updated, false if the tool didn't exist
1242
- * @throws Error if the tool's metadata.name doesn't match the name parameter
1243
- *
1244
- * @example
1245
- * ```ts
1246
- * const updated = registry.update('read-file', newReadFileTool);
1247
- * ```
1248
- */
1249
1221
  update(name, tool) {
1250
- return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
1222
+ return this.mutations.update(name, tool);
1251
1223
  }
1252
- /**
1253
- * Get all registered tools
1254
- *
1255
- * @returns Array of all tools
1256
- *
1257
- * @example
1258
- * ```ts
1259
- * const allTools = registry.getAll();
1260
- * console.log(`Total tools: ${allTools.length}`);
1261
- * ```
1262
- */
1263
1224
  getAll() {
1264
- return getAllRegistryTools(this.tools);
1225
+ return this.queries.getAll();
1265
1226
  }
1266
- /**
1267
- * Get tools by category
1268
- *
1269
- * @param category - The tool category
1270
- * @returns Array of tools in the category
1271
- *
1272
- * @example
1273
- * ```ts
1274
- * const fileTools = registry.getByCategory(ToolCategory.FILE_SYSTEM);
1275
- * ```
1276
- */
1277
1227
  getByCategory(category) {
1278
- return getRegistryToolsByCategory(this.tools, category);
1228
+ return this.queries.getByCategory(category);
1279
1229
  }
1280
- /**
1281
- * Get tools by tag
1282
- *
1283
- * @param tag - The tag to search for
1284
- * @returns Array of tools with the tag
1285
- *
1286
- * @example
1287
- * ```ts
1288
- * const fileTools = registry.getByTag('file');
1289
- * ```
1290
- */
1291
1230
  getByTag(tag) {
1292
- return getRegistryToolsByTag(this.tools, tag);
1231
+ return this.queries.getByTag(tag);
1293
1232
  }
1294
- /**
1295
- * Search tools by name or description
1296
- *
1297
- * Case-insensitive search across tool names, display names, and descriptions.
1298
- *
1299
- * @param query - The search query
1300
- * @returns Array of matching tools
1301
- *
1302
- * @example
1303
- * ```ts
1304
- * const results = registry.search('file');
1305
- * // Returns tools with 'file' in name or description
1306
- * ```
1307
- */
1308
1233
  search(query) {
1309
- return searchRegistryTools(this.tools, query);
1234
+ return this.queries.search(query);
1310
1235
  }
1311
- /**
1312
- * Register multiple tools at once
1313
- *
1314
- * @param tools - Iterable of tools to register
1315
- * @throws Error if any tool name conflicts with existing tools
1316
- *
1317
- * @example
1318
- * ```ts
1319
- * registry.registerMany([tool1, tool2, tool3]);
1320
- * ```
1321
- */
1322
1236
  registerMany(tools) {
1323
- registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
1237
+ this.mutations.registerMany(tools);
1324
1238
  }
1325
- /**
1326
- * Clear all tools from the registry
1327
- *
1328
- * @example
1329
- * ```ts
1330
- * registry.clear();
1331
- * console.log(registry.size()); // 0
1332
- * ```
1333
- */
1334
1239
  clear() {
1335
- clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
1240
+ this.mutations.clear();
1336
1241
  }
1337
- /**
1338
- * Get the number of registered tools
1339
- *
1340
- * @returns Number of tools in the registry
1341
- *
1342
- * @example
1343
- * ```ts
1344
- * console.log(`Registry has ${registry.size()} tools`);
1345
- * ```
1346
- */
1347
1242
  size() {
1348
- return this.tools.size;
1243
+ return this.queries.size();
1349
1244
  }
1350
- /**
1351
- * Get all tool names
1352
- *
1353
- * @returns Array of tool names
1354
- *
1355
- * @example
1356
- * ```ts
1357
- * const names = registry.getNames();
1358
- * console.log('Available tools:', names.join(', '));
1359
- * ```
1360
- */
1361
1245
  getNames() {
1362
- return getRegistryToolNames(this.tools);
1246
+ return this.queries.getNames();
1363
1247
  }
1364
- /**
1365
- * Register an event handler
1366
- *
1367
- * @param event - The event to listen for
1368
- * @param handler - The handler function
1369
- *
1370
- * @example
1371
- * ```ts
1372
- * registry.on(RegistryEvent.TOOL_REGISTERED, (tool) => {
1373
- * console.log('New tool:', tool.metadata.name);
1374
- * });
1375
- * ```
1376
- */
1377
1248
  on(event, handler) {
1378
1249
  addRegistryEventHandler(this.eventHandlers, event, handler);
1379
1250
  }
1380
- /**
1381
- * Unregister an event handler
1382
- *
1383
- * @param event - The event to stop listening for
1384
- * @param handler - The handler function to remove
1385
- *
1386
- * @example
1387
- * ```ts
1388
- * const handler = (tool) => console.log(tool);
1389
- * registry.on(RegistryEvent.TOOL_REGISTERED, handler);
1390
- * registry.off(RegistryEvent.TOOL_REGISTERED, handler);
1391
- * ```
1392
- */
1393
1251
  off(event, handler) {
1394
1252
  removeRegistryEventHandler(this.eventHandlers, event, handler);
1395
1253
  }
1396
- /**
1397
- * Emit an event to all registered handlers
1398
- *
1399
- * @param event - The event to emit
1400
- * @param data - The event data
1401
- * @private
1402
- */
1403
1254
  emit(event, data) {
1404
1255
  emitRegistryEvent(this.eventHandlers, event, data);
1405
1256
  }
1406
- /**
1407
- * Convert all registered tools to LangChain format
1408
- *
1409
- * This allows the entire registry to be used with LangChain agents.
1410
- *
1411
- * @returns Array of LangChain DynamicStructuredTools
1412
- *
1413
- * @example
1414
- * ```ts
1415
- * const registry = new ToolRegistry();
1416
- * registry.registerMany([tool1, tool2, tool3]);
1417
- *
1418
- * const langchainTools = registry.toLangChainTools();
1419
- *
1420
- * const agent = createAgent({
1421
- * model: new ChatOpenAI(),
1422
- * tools: langchainTools,
1423
- * });
1424
- * ```
1425
- */
1426
1257
  toLangChainTools() {
1427
- return convertRegistryToolsToLangChain(this.getAll());
1258
+ return this.queries.toLangChainTools();
1428
1259
  }
1429
- /**
1430
- * Generate a formatted prompt describing all tools
1431
- *
1432
- * Creates a human-readable description of all tools in the registry,
1433
- * suitable for inclusion in LLM prompts.
1434
- *
1435
- * @param options - Options for customizing the prompt
1436
- * @returns Formatted prompt string
1437
- *
1438
- * @example
1439
- * ```ts
1440
- * const prompt = registry.generatePrompt({
1441
- * includeExamples: true,
1442
- * groupByCategory: true,
1443
- * maxExamplesPerTool: 2,
1444
- * });
1445
- *
1446
- * console.log(prompt);
1447
- * // Available Tools:
1448
- * //
1449
- * // FILE SYSTEM TOOLS:
1450
- * // - read-file: Read a file from the file system
1451
- * // Parameters: path (string)
1452
- * // Example: Read a text file
1453
- * // Input: { "path": "./README.md" }
1454
- * // ...
1455
- * ```
1456
- */
1457
1260
  generatePrompt(options = {}) {
1458
- return generateRegistryPrompt(this.getAll(), options);
1261
+ return this.queries.generatePrompt(options);
1459
1262
  }
1460
1263
  };
1461
1264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/core",
3
- "version": "0.16.34",
3
+ "version": "0.16.36",
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",