@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.cjs CHANGED
@@ -493,7 +493,54 @@ function validateTool(tool) {
493
493
  };
494
494
  }
495
495
 
496
- // src/tools/builder.ts
496
+ // src/tools/builder-finalize.ts
497
+ function assertBuildable(metadata, schema, invoke) {
498
+ if (!metadata.name) {
499
+ throw new Error("Tool name is required. Use .name() to set it.");
500
+ }
501
+ if (!metadata.description) {
502
+ throw new Error("Tool description is required. Use .description() to set it.");
503
+ }
504
+ if (!metadata.category) {
505
+ throw new Error("Tool category is required. Use .category() to set it.");
506
+ }
507
+ if (!schema) {
508
+ throw new Error("Tool schema is required. Use .schema() to set it.");
509
+ }
510
+ if (!invoke) {
511
+ throw new Error("Tool implementation is required. Use .implement() to set it.");
512
+ }
513
+ }
514
+ function buildTool(metadata, schema, invoke) {
515
+ assertBuildable(metadata, schema, invoke);
516
+ const finalSchema = schema;
517
+ const finalInvoke = invoke;
518
+ return createTool(metadata, finalSchema, async function(input) {
519
+ return finalInvoke.call(this, input);
520
+ });
521
+ }
522
+
523
+ // src/tools/builder-implementation.ts
524
+ function wrapInvoke(invoke) {
525
+ return async function(input) {
526
+ return invoke.call(this, input);
527
+ };
528
+ }
529
+ function wrapSafeInvoke(invoke) {
530
+ return wrapInvoke(async function(input) {
531
+ try {
532
+ const data = await invoke.call(this, input);
533
+ return { success: true, data };
534
+ } catch (error) {
535
+ return {
536
+ success: false,
537
+ error: error instanceof Error ? error.message : String(error)
538
+ };
539
+ }
540
+ });
541
+ }
542
+
543
+ // src/tools/builder-metadata.ts
497
544
  function cloneRelations(relations) {
498
545
  if (!relations) {
499
546
  return void 0;
@@ -532,338 +579,121 @@ function cloneMetadata(metadata) {
532
579
  relations: cloneRelations(metadata.relations)
533
580
  };
534
581
  }
582
+ function appendMetadataList(metadata, key, value) {
583
+ if (!metadata[key]) {
584
+ metadata[key] = [];
585
+ }
586
+ metadata[key].push(value);
587
+ }
588
+ function appendExample(metadata, example) {
589
+ if (!metadata.examples) {
590
+ metadata.examples = [];
591
+ }
592
+ metadata.examples.push(example);
593
+ }
594
+ function setRelation(metadata, relation, tools) {
595
+ metadata.relations = {
596
+ ...metadata.relations ?? {},
597
+ [relation]: tools
598
+ };
599
+ }
600
+
601
+ // src/tools/builder.ts
535
602
  var ToolBuilder = class _ToolBuilder {
536
603
  constructor(metadata = {}, _schema, _invoke) {
537
604
  this.metadata = metadata;
538
605
  this._schema = _schema;
539
606
  this._invoke = _invoke;
540
607
  }
541
- /**
542
- * Set the tool name (required)
543
- *
544
- * @param name - Tool name in kebab-case (e.g., 'read-file')
545
- */
546
608
  name(name) {
547
609
  this.metadata.name = name;
548
610
  return this;
549
611
  }
550
- /**
551
- * Set the tool description (required)
552
- *
553
- * @param description - Clear description of what the tool does
554
- */
555
612
  description(description) {
556
613
  this.metadata.description = description;
557
614
  return this;
558
615
  }
559
- /**
560
- * Set the tool category (required)
561
- *
562
- * @param category - Tool category for organization
563
- */
564
616
  category(category) {
565
617
  this.metadata.category = category;
566
618
  return this;
567
619
  }
568
- /**
569
- * Set the display name (optional)
570
- *
571
- * @param displayName - Human-friendly name for UI display
572
- */
573
620
  displayName(displayName) {
574
621
  this.metadata.displayName = displayName;
575
622
  return this;
576
623
  }
577
- /**
578
- * Set tags for searchability (optional)
579
- *
580
- * @param tags - Array of tags for categorization and search
581
- */
582
624
  tags(tags) {
583
625
  this.metadata.tags = tags;
584
626
  return this;
585
627
  }
586
- /**
587
- * Add a single tag (optional)
588
- *
589
- * @param tag - Tag to add
590
- */
591
628
  tag(tag) {
592
- if (!this.metadata.tags) {
593
- this.metadata.tags = [];
594
- }
595
- this.metadata.tags.push(tag);
629
+ appendMetadataList(this.metadata, "tags", tag);
596
630
  return this;
597
631
  }
598
- /**
599
- * Add an example (optional)
600
- *
601
- * @param example - Usage example for the tool
602
- */
603
632
  example(example) {
604
- if (!this.metadata.examples) {
605
- this.metadata.examples = [];
606
- }
607
- this.metadata.examples.push(example);
633
+ appendExample(this.metadata, example);
608
634
  return this;
609
635
  }
610
- /**
611
- * Set usage notes (optional)
612
- *
613
- * @param notes - Important usage information
614
- */
615
636
  usageNotes(notes) {
616
637
  this.metadata.usageNotes = notes;
617
638
  return this;
618
639
  }
619
- /**
620
- * Set limitations (optional)
621
- *
622
- * @param limitations - Array of known limitations
623
- */
624
640
  limitations(limitations) {
625
641
  this.metadata.limitations = limitations;
626
642
  return this;
627
643
  }
628
- /**
629
- * Add a single limitation (optional)
630
- *
631
- * @param limitation - Limitation to add
632
- */
633
644
  limitation(limitation) {
634
- if (!this.metadata.limitations) {
635
- this.metadata.limitations = [];
636
- }
637
- this.metadata.limitations.push(limitation);
645
+ appendMetadataList(this.metadata, "limitations", limitation);
638
646
  return this;
639
647
  }
640
- /**
641
- * Set version (optional)
642
- *
643
- * @param version - Semantic version string
644
- */
645
648
  version(version) {
646
649
  this.metadata.version = version;
647
650
  return this;
648
651
  }
649
- /**
650
- * Set author (optional)
651
- *
652
- * @param author - Tool author name
653
- */
654
652
  author(author) {
655
653
  this.metadata.author = author;
656
654
  return this;
657
655
  }
658
- /**
659
- * Set tools that must be called before this tool (optional)
660
- *
661
- * @param tools - Array of tool names that are required
662
- * @example
663
- * ```ts
664
- * .requires(['view-file', 'search-codebase'])
665
- * ```
666
- */
667
656
  requires(tools) {
668
- if (!this.metadata.relations) {
669
- this.metadata.relations = {};
670
- }
671
- this.metadata.relations.requires = tools;
657
+ setRelation(this.metadata, "requires", tools);
672
658
  return this;
673
659
  }
674
- /**
675
- * Set tools that work well with this tool (optional)
676
- *
677
- * @param tools - Array of tool names that are suggested
678
- * @example
679
- * ```ts
680
- * .suggests(['run-tests', 'format-code'])
681
- * ```
682
- */
683
660
  suggests(tools) {
684
- if (!this.metadata.relations) {
685
- this.metadata.relations = {};
686
- }
687
- this.metadata.relations.suggests = tools;
661
+ setRelation(this.metadata, "suggests", tools);
688
662
  return this;
689
663
  }
690
- /**
691
- * Set tools that conflict with this tool (optional)
692
- *
693
- * @param tools - Array of tool names that conflict
694
- * @example
695
- * ```ts
696
- * .conflicts(['delete-file'])
697
- * ```
698
- */
699
664
  conflicts(tools) {
700
- if (!this.metadata.relations) {
701
- this.metadata.relations = {};
702
- }
703
- this.metadata.relations.conflicts = tools;
665
+ setRelation(this.metadata, "conflicts", tools);
704
666
  return this;
705
667
  }
706
- /**
707
- * Set tools this typically follows in a workflow (optional)
708
- *
709
- * @param tools - Array of tool names this follows
710
- * @example
711
- * ```ts
712
- * .follows(['search-codebase', 'view-file'])
713
- * ```
714
- */
715
668
  follows(tools) {
716
- if (!this.metadata.relations) {
717
- this.metadata.relations = {};
718
- }
719
- this.metadata.relations.follows = tools;
669
+ setRelation(this.metadata, "follows", tools);
720
670
  return this;
721
671
  }
722
- /**
723
- * Set tools this typically precedes in a workflow (optional)
724
- *
725
- * @param tools - Array of tool names this precedes
726
- * @example
727
- * ```ts
728
- * .precedes(['run-tests'])
729
- * ```
730
- */
731
672
  precedes(tools) {
732
- if (!this.metadata.relations) {
733
- this.metadata.relations = {};
734
- }
735
- this.metadata.relations.precedes = tools;
673
+ setRelation(this.metadata, "precedes", tools);
736
674
  return this;
737
675
  }
738
- /**
739
- * Set the input schema (required)
740
- *
741
- * All fields MUST have .describe() for LLM understanding!
742
- *
743
- * @param schema - Zod schema for input validation
744
- */
745
676
  schema(schema) {
746
677
  return new _ToolBuilder(cloneMetadata(this.metadata), schema, this._invoke);
747
678
  }
748
- /**
749
- * Set the implementation function (required)
750
- *
751
- * @param invoke - Async function that implements the tool
752
- */
753
679
  implement(invoke) {
754
- const wrappedInvoke = async function(input) {
755
- return invoke.call(this, input);
756
- };
757
- return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrappedInvoke);
680
+ return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrapInvoke(invoke));
758
681
  }
759
- /**
760
- * Set the implementation function with automatic error handling
761
- *
762
- * Wraps the implementation in a try-catch block and returns a standardized
763
- * result object with success/error information.
764
- *
765
- * @param invoke - Async function that implements the tool
766
- * @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
767
- *
768
- * @example
769
- * ```ts
770
- * const tool = toolBuilder()
771
- * .name('read-file')
772
- * .schema(z.object({ path: z.string() }))
773
- * .implementSafe(async ({ path }) => {
774
- * return await fs.readFile(path, 'utf-8');
775
- * })
776
- * .build();
777
- *
778
- * // Result will be: { success: true, data: "file content" }
779
- * // Or on error: { success: false, error: "ENOENT: no such file..." }
780
- * ```
781
- */
782
682
  implementSafe(invoke) {
783
- const safeInvoke = async function(input) {
784
- try {
785
- const data = await invoke.call(this, input);
786
- return { success: true, data };
787
- } catch (error) {
788
- return {
789
- success: false,
790
- error: error instanceof Error ? error.message : String(error)
791
- };
792
- }
793
- };
794
- const wrappedInvoke = async function(input) {
795
- return safeInvoke.call(this, input);
796
- };
797
683
  return new _ToolBuilder(
798
684
  cloneMetadata(this.metadata),
799
685
  this._schema,
800
- wrappedInvoke
686
+ wrapSafeInvoke(invoke)
801
687
  );
802
688
  }
803
- /**
804
- * Build the tool with validation
805
- *
806
- * Validates:
807
- * - All required fields are present
808
- * - Metadata is valid
809
- * - Schema has descriptions on all fields
810
- *
811
- * @returns The validated tool
812
- * @throws {Error} If validation fails
813
- */
814
689
  build() {
815
- if (!this.metadata.name) {
816
- throw new Error("Tool name is required. Use .name() to set it.");
817
- }
818
- if (!this.metadata.description) {
819
- throw new Error("Tool description is required. Use .description() to set it.");
820
- }
821
- if (!this.metadata.category) {
822
- throw new Error("Tool category is required. Use .category() to set it.");
823
- }
824
- if (!this._schema) {
825
- throw new Error("Tool schema is required. Use .schema() to set it.");
826
- }
827
- if (!this._invoke) {
828
- throw new Error("Tool implementation is required. Use .implement() to set it.");
829
- }
830
- const invoke = this._invoke;
831
- return createTool(
832
- this.metadata,
833
- this._schema,
834
- async function(input) {
835
- return invoke.call(this, input);
836
- }
837
- );
690
+ return buildTool(this.metadata, this._schema, this._invoke);
838
691
  }
839
692
  };
840
693
  function toolBuilder() {
841
694
  return new ToolBuilder();
842
695
  }
843
696
 
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
697
  // src/langgraph/observability/logger.ts
868
698
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
869
699
  LogLevel2["DEBUG"] = "debug";
@@ -1064,6 +894,40 @@ function clearRegistryTools(tools, emit, events) {
1064
894
  emit(events.cleared, null);
1065
895
  }
1066
896
 
897
+ // src/tools/registry-mutation-api.ts
898
+ function createRegistryMutationApi(tools, emit, events) {
899
+ return {
900
+ register: (tool) => registerRegistryTool(tools, tool, emit, events),
901
+ remove: (name) => removeRegistryTool(tools, name, emit, events),
902
+ update: (name, tool) => updateRegistryTool(tools, name, tool, emit, events),
903
+ registerMany: (toolsToRegister) => registerManyRegistryTools(tools, toolsToRegister, emit, events),
904
+ clear: () => clearRegistryTools(tools, emit, events)
905
+ };
906
+ }
907
+
908
+ // src/tools/registry-collection.ts
909
+ function getAllRegistryTools(tools) {
910
+ return Array.from(tools.values());
911
+ }
912
+ function getRegistryToolNames(tools) {
913
+ return Array.from(tools.keys());
914
+ }
915
+ function getRegistryToolsByCategory(tools, category) {
916
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.category === category);
917
+ }
918
+ function getRegistryToolsByTag(tools, tag) {
919
+ return getAllRegistryTools(tools).filter((tool) => tool.metadata.tags?.includes(tag));
920
+ }
921
+ function searchRegistryTools(tools, query) {
922
+ const lowerQuery = query.toLowerCase();
923
+ return getAllRegistryTools(tools).filter((tool) => {
924
+ const name = tool.metadata.name.toLowerCase();
925
+ const displayName = tool.metadata.displayName?.toLowerCase() ?? "";
926
+ const description = tool.metadata.description.toLowerCase();
927
+ return name.includes(lowerQuery) || displayName.includes(lowerQuery) || description.includes(lowerQuery);
928
+ });
929
+ }
930
+
1067
931
  // src/tools/registry-prompt.ts
1068
932
  var import_zod3 = require("zod");
1069
933
 
@@ -1326,7 +1190,23 @@ function getSchemaShape(schema) {
1326
1190
  return void 0;
1327
1191
  }
1328
1192
 
1329
- // src/tools/registry.ts
1193
+ // src/tools/registry-query-api.ts
1194
+ function createRegistryQueryApi(tools) {
1195
+ return {
1196
+ get: (name) => tools.get(name),
1197
+ has: (name) => tools.has(name),
1198
+ getAll: () => getAllRegistryTools(tools),
1199
+ getByCategory: (category) => getRegistryToolsByCategory(tools, category),
1200
+ getByTag: (tag) => getRegistryToolsByTag(tools, tag),
1201
+ search: (query) => searchRegistryTools(tools, query),
1202
+ size: () => tools.size,
1203
+ getNames: () => getRegistryToolNames(tools),
1204
+ toLangChainTools: () => convertRegistryToolsToLangChain(getAllRegistryTools(tools)),
1205
+ generatePrompt: (options = {}) => generateRegistryPrompt(getAllRegistryTools(tools), options)
1206
+ };
1207
+ }
1208
+
1209
+ // src/tools/registry-types.ts
1330
1210
  var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1331
1211
  RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
1332
1212
  RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
@@ -1334,6 +1214,8 @@ var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
1334
1214
  RegistryEvent2["REGISTRY_CLEARED"] = "registry:cleared";
1335
1215
  return RegistryEvent2;
1336
1216
  })(RegistryEvent || {});
1217
+
1218
+ // src/tools/registry.ts
1337
1219
  var ToolRegistry = class {
1338
1220
  tools = /* @__PURE__ */ new Map();
1339
1221
  eventHandlers = /* @__PURE__ */ new Map();
@@ -1346,291 +1228,65 @@ var ToolRegistry = class {
1346
1228
  emitMutation = (event, data) => {
1347
1229
  this.emit(event, data);
1348
1230
  };
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
- */
1231
+ mutations;
1232
+ queries;
1233
+ constructor() {
1234
+ this.mutations = createRegistryMutationApi(this.tools, this.emitMutation, this.mutationEvents);
1235
+ this.queries = createRegistryQueryApi(this.tools);
1236
+ }
1360
1237
  register(tool) {
1361
- registerRegistryTool(this.tools, tool, this.emitMutation, this.mutationEvents);
1238
+ this.mutations.register(tool);
1362
1239
  }
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
1240
  get(name) {
1378
- return this.tools.get(name);
1241
+ return this.queries.get(name);
1379
1242
  }
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
1243
  has(name) {
1394
- return this.tools.has(name);
1244
+ return this.queries.has(name);
1395
1245
  }
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
1246
  remove(name) {
1409
- return removeRegistryTool(this.tools, name, this.emitMutation, this.mutationEvents);
1247
+ return this.mutations.remove(name);
1410
1248
  }
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
1249
  update(name, tool) {
1425
- return updateRegistryTool(this.tools, name, tool, this.emitMutation, this.mutationEvents);
1250
+ return this.mutations.update(name, tool);
1426
1251
  }
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
1252
  getAll() {
1439
- return getAllRegistryTools(this.tools);
1253
+ return this.queries.getAll();
1440
1254
  }
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
1255
  getByCategory(category) {
1453
- return getRegistryToolsByCategory(this.tools, category);
1256
+ return this.queries.getByCategory(category);
1454
1257
  }
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
1258
  getByTag(tag) {
1467
- return getRegistryToolsByTag(this.tools, tag);
1259
+ return this.queries.getByTag(tag);
1468
1260
  }
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
1261
  search(query) {
1484
- return searchRegistryTools(this.tools, query);
1262
+ return this.queries.search(query);
1485
1263
  }
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
1264
  registerMany(tools) {
1498
- registerManyRegistryTools(this.tools, tools, this.emitMutation, this.mutationEvents);
1265
+ this.mutations.registerMany(tools);
1499
1266
  }
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
1267
  clear() {
1510
- clearRegistryTools(this.tools, this.emitMutation, this.mutationEvents);
1268
+ this.mutations.clear();
1511
1269
  }
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
1270
  size() {
1523
- return this.tools.size;
1271
+ return this.queries.size();
1524
1272
  }
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
1273
  getNames() {
1537
- return getRegistryToolNames(this.tools);
1274
+ return this.queries.getNames();
1538
1275
  }
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
1276
  on(event, handler) {
1553
1277
  addRegistryEventHandler(this.eventHandlers, event, handler);
1554
1278
  }
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
1279
  off(event, handler) {
1569
1280
  removeRegistryEventHandler(this.eventHandlers, event, handler);
1570
1281
  }
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
1282
  emit(event, data) {
1579
1283
  emitRegistryEvent(this.eventHandlers, event, data);
1580
1284
  }
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
1285
  toLangChainTools() {
1602
- return convertRegistryToolsToLangChain(this.getAll());
1286
+ return this.queries.toLangChainTools();
1603
1287
  }
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
1288
  generatePrompt(options = {}) {
1633
- return generateRegistryPrompt(this.getAll(), options);
1289
+ return this.queries.generatePrompt(options);
1634
1290
  }
1635
1291
  };
1636
1292