@agentforge/core 0.16.35 → 0.16.37

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
@@ -318,7 +318,54 @@ function validateTool(tool) {
318
318
  };
319
319
  }
320
320
 
321
- // src/tools/builder.ts
321
+ // src/tools/builder-finalize.ts
322
+ function assertBuildable(metadata, schema, invoke) {
323
+ if (!metadata.name) {
324
+ throw new Error("Tool name is required. Use .name() to set it.");
325
+ }
326
+ if (!metadata.description) {
327
+ throw new Error("Tool description is required. Use .description() to set it.");
328
+ }
329
+ if (!metadata.category) {
330
+ throw new Error("Tool category is required. Use .category() to set it.");
331
+ }
332
+ if (!schema) {
333
+ throw new Error("Tool schema is required. Use .schema() to set it.");
334
+ }
335
+ if (!invoke) {
336
+ throw new Error("Tool implementation is required. Use .implement() to set it.");
337
+ }
338
+ }
339
+ function buildTool(metadata, schema, invoke) {
340
+ assertBuildable(metadata, schema, invoke);
341
+ const finalSchema = schema;
342
+ const finalInvoke = invoke;
343
+ return createTool(metadata, finalSchema, async function(input) {
344
+ return finalInvoke.call(this, input);
345
+ });
346
+ }
347
+
348
+ // src/tools/builder-implementation.ts
349
+ function wrapInvoke(invoke) {
350
+ return async function(input) {
351
+ return invoke.call(this, input);
352
+ };
353
+ }
354
+ function wrapSafeInvoke(invoke) {
355
+ return wrapInvoke(async function(input) {
356
+ try {
357
+ const data = await invoke.call(this, input);
358
+ return { success: true, data };
359
+ } catch (error) {
360
+ return {
361
+ success: false,
362
+ error: error instanceof Error ? error.message : String(error)
363
+ };
364
+ }
365
+ });
366
+ }
367
+
368
+ // src/tools/builder-metadata.ts
322
369
  function cloneRelations(relations) {
323
370
  if (!relations) {
324
371
  return void 0;
@@ -357,338 +404,121 @@ function cloneMetadata(metadata) {
357
404
  relations: cloneRelations(metadata.relations)
358
405
  };
359
406
  }
407
+ function appendMetadataList(metadata, key, value) {
408
+ if (!metadata[key]) {
409
+ metadata[key] = [];
410
+ }
411
+ metadata[key].push(value);
412
+ }
413
+ function appendExample(metadata, example) {
414
+ if (!metadata.examples) {
415
+ metadata.examples = [];
416
+ }
417
+ metadata.examples.push(example);
418
+ }
419
+ function setRelation(metadata, relation, tools) {
420
+ metadata.relations = {
421
+ ...metadata.relations ?? {},
422
+ [relation]: tools
423
+ };
424
+ }
425
+
426
+ // src/tools/builder.ts
360
427
  var ToolBuilder = class _ToolBuilder {
361
428
  constructor(metadata = {}, _schema, _invoke) {
362
429
  this.metadata = metadata;
363
430
  this._schema = _schema;
364
431
  this._invoke = _invoke;
365
432
  }
366
- /**
367
- * Set the tool name (required)
368
- *
369
- * @param name - Tool name in kebab-case (e.g., 'read-file')
370
- */
371
433
  name(name) {
372
434
  this.metadata.name = name;
373
435
  return this;
374
436
  }
375
- /**
376
- * Set the tool description (required)
377
- *
378
- * @param description - Clear description of what the tool does
379
- */
380
437
  description(description) {
381
438
  this.metadata.description = description;
382
439
  return this;
383
440
  }
384
- /**
385
- * Set the tool category (required)
386
- *
387
- * @param category - Tool category for organization
388
- */
389
441
  category(category) {
390
442
  this.metadata.category = category;
391
443
  return this;
392
444
  }
393
- /**
394
- * Set the display name (optional)
395
- *
396
- * @param displayName - Human-friendly name for UI display
397
- */
398
445
  displayName(displayName) {
399
446
  this.metadata.displayName = displayName;
400
447
  return this;
401
448
  }
402
- /**
403
- * Set tags for searchability (optional)
404
- *
405
- * @param tags - Array of tags for categorization and search
406
- */
407
449
  tags(tags) {
408
450
  this.metadata.tags = tags;
409
451
  return this;
410
452
  }
411
- /**
412
- * Add a single tag (optional)
413
- *
414
- * @param tag - Tag to add
415
- */
416
453
  tag(tag) {
417
- if (!this.metadata.tags) {
418
- this.metadata.tags = [];
419
- }
420
- this.metadata.tags.push(tag);
454
+ appendMetadataList(this.metadata, "tags", tag);
421
455
  return this;
422
456
  }
423
- /**
424
- * Add an example (optional)
425
- *
426
- * @param example - Usage example for the tool
427
- */
428
457
  example(example) {
429
- if (!this.metadata.examples) {
430
- this.metadata.examples = [];
431
- }
432
- this.metadata.examples.push(example);
458
+ appendExample(this.metadata, example);
433
459
  return this;
434
460
  }
435
- /**
436
- * Set usage notes (optional)
437
- *
438
- * @param notes - Important usage information
439
- */
440
461
  usageNotes(notes) {
441
462
  this.metadata.usageNotes = notes;
442
463
  return this;
443
464
  }
444
- /**
445
- * Set limitations (optional)
446
- *
447
- * @param limitations - Array of known limitations
448
- */
449
465
  limitations(limitations) {
450
466
  this.metadata.limitations = limitations;
451
467
  return this;
452
468
  }
453
- /**
454
- * Add a single limitation (optional)
455
- *
456
- * @param limitation - Limitation to add
457
- */
458
469
  limitation(limitation) {
459
- if (!this.metadata.limitations) {
460
- this.metadata.limitations = [];
461
- }
462
- this.metadata.limitations.push(limitation);
470
+ appendMetadataList(this.metadata, "limitations", limitation);
463
471
  return this;
464
472
  }
465
- /**
466
- * Set version (optional)
467
- *
468
- * @param version - Semantic version string
469
- */
470
473
  version(version) {
471
474
  this.metadata.version = version;
472
475
  return this;
473
476
  }
474
- /**
475
- * Set author (optional)
476
- *
477
- * @param author - Tool author name
478
- */
479
477
  author(author) {
480
478
  this.metadata.author = author;
481
479
  return this;
482
480
  }
483
- /**
484
- * Set tools that must be called before this tool (optional)
485
- *
486
- * @param tools - Array of tool names that are required
487
- * @example
488
- * ```ts
489
- * .requires(['view-file', 'search-codebase'])
490
- * ```
491
- */
492
481
  requires(tools) {
493
- if (!this.metadata.relations) {
494
- this.metadata.relations = {};
495
- }
496
- this.metadata.relations.requires = tools;
482
+ setRelation(this.metadata, "requires", tools);
497
483
  return this;
498
484
  }
499
- /**
500
- * Set tools that work well with this tool (optional)
501
- *
502
- * @param tools - Array of tool names that are suggested
503
- * @example
504
- * ```ts
505
- * .suggests(['run-tests', 'format-code'])
506
- * ```
507
- */
508
485
  suggests(tools) {
509
- if (!this.metadata.relations) {
510
- this.metadata.relations = {};
511
- }
512
- this.metadata.relations.suggests = tools;
486
+ setRelation(this.metadata, "suggests", tools);
513
487
  return this;
514
488
  }
515
- /**
516
- * Set tools that conflict with this tool (optional)
517
- *
518
- * @param tools - Array of tool names that conflict
519
- * @example
520
- * ```ts
521
- * .conflicts(['delete-file'])
522
- * ```
523
- */
524
489
  conflicts(tools) {
525
- if (!this.metadata.relations) {
526
- this.metadata.relations = {};
527
- }
528
- this.metadata.relations.conflicts = tools;
490
+ setRelation(this.metadata, "conflicts", tools);
529
491
  return this;
530
492
  }
531
- /**
532
- * Set tools this typically follows in a workflow (optional)
533
- *
534
- * @param tools - Array of tool names this follows
535
- * @example
536
- * ```ts
537
- * .follows(['search-codebase', 'view-file'])
538
- * ```
539
- */
540
493
  follows(tools) {
541
- if (!this.metadata.relations) {
542
- this.metadata.relations = {};
543
- }
544
- this.metadata.relations.follows = tools;
494
+ setRelation(this.metadata, "follows", tools);
545
495
  return this;
546
496
  }
547
- /**
548
- * Set tools this typically precedes in a workflow (optional)
549
- *
550
- * @param tools - Array of tool names this precedes
551
- * @example
552
- * ```ts
553
- * .precedes(['run-tests'])
554
- * ```
555
- */
556
497
  precedes(tools) {
557
- if (!this.metadata.relations) {
558
- this.metadata.relations = {};
559
- }
560
- this.metadata.relations.precedes = tools;
498
+ setRelation(this.metadata, "precedes", tools);
561
499
  return this;
562
500
  }
563
- /**
564
- * Set the input schema (required)
565
- *
566
- * All fields MUST have .describe() for LLM understanding!
567
- *
568
- * @param schema - Zod schema for input validation
569
- */
570
501
  schema(schema) {
571
502
  return new _ToolBuilder(cloneMetadata(this.metadata), schema, this._invoke);
572
503
  }
573
- /**
574
- * Set the implementation function (required)
575
- *
576
- * @param invoke - Async function that implements the tool
577
- */
578
504
  implement(invoke) {
579
- const wrappedInvoke = async function(input) {
580
- return invoke.call(this, input);
581
- };
582
- return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrappedInvoke);
505
+ return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrapInvoke(invoke));
583
506
  }
584
- /**
585
- * Set the implementation function with automatic error handling
586
- *
587
- * Wraps the implementation in a try-catch block and returns a standardized
588
- * result object with success/error information.
589
- *
590
- * @param invoke - Async function that implements the tool
591
- * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
592
- *
593
- * @example
594
- * ```ts
595
- * const tool = toolBuilder()
596
- * .name('read-file')
597
- * .schema(z.object({ path: z.string() }))
598
- * .implementSafe(async ({ path }) => {
599
- * return await fs.readFile(path, 'utf-8');
600
- * })
601
- * .build();
602
- *
603
- * // Result will be: { success: true, data: "file content" }
604
- * // Or on error: { success: false, error: "ENOENT: no such file..." }
605
- * ```
606
- */
607
507
  implementSafe(invoke) {
608
- const safeInvoke = async function(input) {
609
- try {
610
- const data = await invoke.call(this, input);
611
- return { success: true, data };
612
- } catch (error) {
613
- return {
614
- success: false,
615
- error: error instanceof Error ? error.message : String(error)
616
- };
617
- }
618
- };
619
- const wrappedInvoke = async function(input) {
620
- return safeInvoke.call(this, input);
621
- };
622
508
  return new _ToolBuilder(
623
509
  cloneMetadata(this.metadata),
624
510
  this._schema,
625
- wrappedInvoke
511
+ wrapSafeInvoke(invoke)
626
512
  );
627
513
  }
628
- /**
629
- * Build the tool with validation
630
- *
631
- * Validates:
632
- * - All required fields are present
633
- * - Metadata is valid
634
- * - Schema has descriptions on all fields
635
- *
636
- * @returns The validated tool
637
- * @throws {Error} If validation fails
638
- */
639
514
  build() {
640
- if (!this.metadata.name) {
641
- throw new Error("Tool name is required. Use .name() to set it.");
642
- }
643
- if (!this.metadata.description) {
644
- throw new Error("Tool description is required. Use .description() to set it.");
645
- }
646
- if (!this.metadata.category) {
647
- throw new Error("Tool category is required. Use .category() to set it.");
648
- }
649
- if (!this._schema) {
650
- throw new Error("Tool schema is required. Use .schema() to set it.");
651
- }
652
- if (!this._invoke) {
653
- throw new Error("Tool implementation is required. Use .implement() to set it.");
654
- }
655
- const invoke = this._invoke;
656
- return createTool(
657
- this.metadata,
658
- this._schema,
659
- async function(input) {
660
- return invoke.call(this, input);
661
- }
662
- );
515
+ return buildTool(this.metadata, this._schema, this._invoke);
663
516
  }
664
517
  };
665
518
  function toolBuilder() {
666
519
  return new ToolBuilder();
667
520
  }
668
521
 
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
522
  // src/langgraph/observability/logger.ts
693
523
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
694
524
  LogLevel2["DEBUG"] = "debug";
@@ -889,6 +719,40 @@ function clearRegistryTools(tools, emit, events) {
889
719
  emit(events.cleared, null);
890
720
  }
891
721
 
722
+ // src/tools/registry-mutation-api.ts
723
+ function createRegistryMutationApi(tools, emit, events) {
724
+ return {
725
+ register: (tool) => registerRegistryTool(tools, tool, emit, events),
726
+ remove: (name) => removeRegistryTool(tools, name, emit, events),
727
+ update: (name, tool) => updateRegistryTool(tools, name, tool, emit, events),
728
+ registerMany: (toolsToRegister) => registerManyRegistryTools(tools, toolsToRegister, emit, events),
729
+ clear: () => clearRegistryTools(tools, emit, events)
730
+ };
731
+ }
732
+
733
+ // src/tools/registry-collection.ts
734
+ function getAllRegistryTools(tools) {
735
+ return Array.from(tools.values());
736
+ }
737
+ function getRegistryToolNames(tools) {
738
+ return Array.from(tools.keys());
739
+ }
740
+ function getRegistryToolsByCategory(tools, category) {
741
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
742
+ }
743
+ function getRegistryToolsByTag(tools, tag) {
744
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
745
+ }
746
+ function searchRegistryTools(tools, query) {
747
+ const lowerQuery = query.toLowerCase();
748
+ return getAllRegistryTools(tools).filter((tool) => {
749
+ const name = tool.metadata.name.toLowerCase();
750
+ const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
751
+ const description = tool.metadata.description.toLowerCase();
752
+ return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
753
+ });
754
+ }
755
+
892
756
  // src/tools/registry-prompt.ts
893
757
  import { z as z3 } from "zod";
894
758
 
@@ -1151,7 +1015,23 @@ function getSchemaShape(schema) {
1151
1015
  return void 0;
1152
1016
  }
1153
1017
 
1154
- // src/tools/registry.ts
1018
+ // src/tools/registry-query-api.ts
1019
+ function createRegistryQueryApi(tools) {
1020
+ return {
1021
+ get: (name) => tools.get(name),
1022
+ has: (name) => tools.has(name),
1023
+ getAll: () => getAllRegistryTools(tools),
1024
+ getByCategory: (category) => getRegistryToolsByCategory(tools, category),
1025
+ getByTag: (tag) => getRegistryToolsByTag(tools, tag),
1026
+ search: (query) => searchRegistryTools(tools, query),
1027
+ size: () => tools.size,
1028
+ getNames: () => getRegistryToolNames(tools),
1029
+ toLangChainTools: () => convertRegistryToolsToLangChain(getAllRegistryTools(tools)),
1030
+ generatePrompt: (options = {}) => generateRegistryPrompt(getAllRegistryTools(tools), options)
1031
+ };
1032
+ }
1033
+
1034
+ // src/tools/registry-types.ts
1155
1035
  var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1156
1036
  RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
1157
1037
  RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
@@ -1159,6 +1039,8 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1159
1039
  RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
1160
1040
  return RegistryEvent2;
1161
1041
  })(RegistryEvent || {});
1042
+
1043
+ // src/tools/registry.ts
1162
1044
  var ToolRegistry = class {
1163
1045
  tools = /* @__PURE__ */ new Map();
1164
1046
  eventHandlers = /* @__PURE__ */ new Map();
@@ -1171,291 +1053,65 @@ var ToolRegistry = class {
1171
1053
  emitMutation = (event, data) => {
1172
1054
  this.emit(event, data);
1173
1055
  };
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
- */
1056
+ mutations;
1057
+ queries;
1058
+ constructor() {
1059
+ this.mutations = createRegistryMutationApi(this.tools, this.emitMutation, this.mutationEvents);
1060
+ this.queries = createRegistryQueryApi(this.tools);
1061
+ }
1185
1062
  register(tool) {
1186
- registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
1063
+ this.mutations.register(tool);
1187
1064
  }
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
1065
  get(name) {
1203
- return this.tools.get(name);
1066
+ return this.queries.get(name);
1204
1067
  }
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
1068
  has(name) {
1219
- return this.tools.has(name);
1069
+ return this.queries.has(name);
1220
1070
  }
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
1071
  remove(name) {
1234
- return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
1072
+ return this.mutations.remove(name);
1235
1073
  }
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
1074
  update(name, tool) {
1250
- return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
1075
+ return this.mutations.update(name, tool);
1251
1076
  }
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
1077
  getAll() {
1264
- return getAllRegistryTools(this.tools);
1078
+ return this.queries.getAll();
1265
1079
  }
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
1080
  getByCategory(category) {
1278
- return getRegistryToolsByCategory(this.tools, category);
1081
+ return this.queries.getByCategory(category);
1279
1082
  }
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
1083
  getByTag(tag) {
1292
- return getRegistryToolsByTag(this.tools, tag);
1084
+ return this.queries.getByTag(tag);
1293
1085
  }
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
1086
  search(query) {
1309
- return searchRegistryTools(this.tools, query);
1087
+ return this.queries.search(query);
1310
1088
  }
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
1089
  registerMany(tools) {
1323
- registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
1090
+ this.mutations.registerMany(tools);
1324
1091
  }
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
1092
  clear() {
1335
- clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
1093
+ this.mutations.clear();
1336
1094
  }
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
1095
  size() {
1348
- return this.tools.size;
1096
+ return this.queries.size();
1349
1097
  }
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
1098
  getNames() {
1362
- return getRegistryToolNames(this.tools);
1099
+ return this.queries.getNames();
1363
1100
  }
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
1101
  on(event, handler) {
1378
1102
  addRegistryEventHandler(this.eventHandlers, event, handler);
1379
1103
  }
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
1104
  off(event, handler) {
1394
1105
  removeRegistryEventHandler(this.eventHandlers, event, handler);
1395
1106
  }
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
1107
  emit(event, data) {
1404
1108
  emitRegistryEvent(this.eventHandlers, event, data);
1405
1109
  }
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
1110
  toLangChainTools() {
1427
- return convertRegistryToolsToLangChain(this.getAll());
1111
+ return this.queries.toLangChainTools();
1428
1112
  }
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
1113
  generatePrompt(options = {}) {
1458
- return generateRegistryPrompt(this.getAll(), options);
1114
+ return this.queries.generatePrompt(options);
1459
1115
  }
1460
1116
  };
1461
1117