agent-swarm-kit 1.0.92 → 1.0.93

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/build/index.cjs CHANGED
@@ -5,6 +5,8 @@ var diKit = require('di-kit');
5
5
  var functoolsKit = require('functools-kit');
6
6
  var xml2js = require('xml2js');
7
7
  var lodashEs = require('lodash-es');
8
+ var path = require('path');
9
+ var fs = require('fs');
8
10
 
9
11
  /******************************************************************************
10
12
  Copyright (c) Microsoft Corporation.
@@ -172,6 +174,7 @@ var init = (_a$2 = diKit.createActivator("agent-swarm"), _a$2.init), inject = _a
172
174
 
173
175
  var baseServices$1 = {
174
176
  busService: Symbol('busService'),
177
+ docService: Symbol('docService'),
175
178
  loggerService: Symbol('loggerService'),
176
179
  };
177
180
  var contextServices$1 = {
@@ -1428,6 +1431,7 @@ var CC_LOGGER_ENABLE_DEBUG = false;
1428
1431
  var CC_LOGGER_ENABLE_LOG = true;
1429
1432
  var CC_LOGGER_ENABLE_CONSOLE = false;
1430
1433
  var CC_NAME_TO_TITLE = nameToTitle;
1434
+ var CC_FN_PLANTUML = function () { return Promise.resolve(""); };
1431
1435
  var GLOBAL_CONFIG = {
1432
1436
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
1433
1437
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
@@ -1450,6 +1454,7 @@ var GLOBAL_CONFIG = {
1450
1454
  CC_LOGGER_ENABLE_LOG: CC_LOGGER_ENABLE_LOG,
1451
1455
  CC_LOGGER_ENABLE_CONSOLE: CC_LOGGER_ENABLE_CONSOLE,
1452
1456
  CC_NAME_TO_TITLE: CC_NAME_TO_TITLE,
1457
+ CC_FN_PLANTUML: CC_FN_PLANTUML,
1453
1458
  };
1454
1459
  var setConfig = function (config) {
1455
1460
  Object.assign(GLOBAL_CONFIG, config);
@@ -1803,7 +1808,7 @@ var ClientAgent = /** @class */ (function () {
1803
1808
  messages: messages,
1804
1809
  mode: mode,
1805
1810
  tools: (_a = this.params.tools) === null || _a === void 0 ? void 0 : _a.map(function (t) {
1806
- return lodashEs.omit(t, "toolName", "call", "validate", "callbacks");
1811
+ return lodashEs.omit(t, "toolName", "docNote", "call", "validate", "callbacks");
1807
1812
  }),
1808
1813
  };
1809
1814
  return [4 /*yield*/, this.params.completion.getCompletion(args)];
@@ -4938,6 +4943,11 @@ var AgentValidationService = /** @class */ (function () {
4938
4943
  this.storageValidationService = inject(TYPES.storageValidationService);
4939
4944
  this._agentMap = new Map();
4940
4945
  this._agentDepsMap = new Map();
4946
+ this.getAgentList = function () {
4947
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4948
+ _this.loggerService.info("agentValidationService getAgentList");
4949
+ return __spreadArray([], __read(_this._agentMap.keys()), false);
4950
+ };
4941
4951
  /**
4942
4952
  * Retrieves the storages used by the agent
4943
4953
  * @param {agentName} agentName - The name of the swarm.
@@ -4945,6 +4955,10 @@ var AgentValidationService = /** @class */ (function () {
4945
4955
  * @throws Will throw an error if the swarm is not found.
4946
4956
  */
4947
4957
  this.getStorageList = function (agentName) {
4958
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4959
+ _this.loggerService.info("agentValidationService getStorageList", {
4960
+ agentName: agentName,
4961
+ });
4948
4962
  if (!_this._agentMap.has(agentName)) {
4949
4963
  throw new Error("agent-swarm agent ".concat(agentName, " not exist (getStorageList)"));
4950
4964
  }
@@ -4957,6 +4971,10 @@ var AgentValidationService = /** @class */ (function () {
4957
4971
  * @throws Will throw an error if the swarm is not found.
4958
4972
  */
4959
4973
  this.getStateList = function (agentName) {
4974
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4975
+ _this.loggerService.info("agentValidationService getStateList", {
4976
+ agentName: agentName,
4977
+ });
4960
4978
  if (!_this._agentMap.has(agentName)) {
4961
4979
  throw new Error("agent-swarm agent ".concat(agentName, " not exist (getStateList)"));
4962
4980
  }
@@ -5492,6 +5510,15 @@ var SwarmValidationService = /** @class */ (function () {
5492
5510
  }
5493
5511
  return swarm.agentList;
5494
5512
  };
5513
+ /**
5514
+ * Retrieves the list of swarms
5515
+ * @returns {string[]} The list of swarm names
5516
+ */
5517
+ this.getSwarmList = function () {
5518
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5519
+ _this.loggerService.info("swarmValidationService getSwarmList");
5520
+ return __spreadArray([], __read(_this._swarmMap.keys()), false);
5521
+ };
5495
5522
  /**
5496
5523
  * Validates a swarm and its agents.
5497
5524
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -7417,7 +7444,384 @@ var SwarmMetaService = /** @class */ (function () {
7417
7444
  return SwarmMetaService;
7418
7445
  }());
7419
7446
 
7447
+ var THREAD_POOL_SIZE = 5;
7448
+ var SUBDIR_LIST = ["agent", "image"];
7449
+ var DocService = /** @class */ (function () {
7450
+ function DocService() {
7451
+ var _this = this;
7452
+ this.loggerService = inject(TYPES.loggerService);
7453
+ this.swarmValidationService = inject(TYPES.swarmValidationService);
7454
+ this.agentValidationService = inject(TYPES.agentValidationService);
7455
+ this.swarmSchemaService = inject(TYPES.swarmSchemaService);
7456
+ this.agentSchemaService = inject(TYPES.agentSchemaService);
7457
+ this.toolSchemaService = inject(TYPES.toolSchemaService);
7458
+ this.storageSchemaService = inject(TYPES.storageSchemaService);
7459
+ this.stateSchemaService = inject(TYPES.stateSchemaService);
7460
+ this.agentMetaService = inject(TYPES.agentMetaService);
7461
+ this.swarmMetaService = inject(TYPES.swarmMetaService);
7462
+ this.writeSwarmDoc = functoolsKit.execpool(function (swarmSchema, dirName) { return __awaiter(_this, void 0, void 0, function () {
7463
+ var result, umlSchema, umlName, umlSvg, docDescription, i, docDescription, callbackList, i;
7464
+ return __generator(this, function (_a) {
7465
+ switch (_a.label) {
7466
+ case 0:
7467
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7468
+ this.loggerService.info("docService writeSwarmDoc", {
7469
+ swarmSchema: swarmSchema,
7470
+ });
7471
+ result = [];
7472
+ {
7473
+ result.push("# ".concat(swarmSchema.swarmName));
7474
+ if (swarmSchema.docDescription) {
7475
+ result.push("");
7476
+ result.push("> ".concat(swarmSchema.docDescription));
7477
+ }
7478
+ result.push("");
7479
+ }
7480
+ umlSchema = this.swarmMetaService.toUML(swarmSchema.swarmName);
7481
+ umlName = "swarm_schema_".concat(swarmSchema.swarmName, ".svg");
7482
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema)];
7483
+ case 1:
7484
+ umlSvg = _a.sent();
7485
+ if (umlSvg) {
7486
+ fs.writeFileSync(path.join(dirName, "image", umlName), umlSvg);
7487
+ result.push("![schema](./image/".concat(umlName, ")"));
7488
+ result.push("");
7489
+ }
7490
+ if (swarmSchema.defaultAgent) {
7491
+ result.push("## Default agent");
7492
+ result.push("");
7493
+ result.push(" - [".concat(swarmSchema.defaultAgent, "](./agent/").concat(swarmSchema.defaultAgent, ".md)"));
7494
+ docDescription = this.agentSchemaService.get(swarmSchema.defaultAgent).docDescription;
7495
+ if (docDescription) {
7496
+ result.push("");
7497
+ result.push(docDescription);
7498
+ }
7499
+ result.push("");
7500
+ }
7501
+ if (swarmSchema.agentList) {
7502
+ result.push("## Used agents");
7503
+ result.push("");
7504
+ for (i = 0; i !== swarmSchema.agentList.length; i++) {
7505
+ if (!swarmSchema.agentList[i]) {
7506
+ continue;
7507
+ }
7508
+ result.push("".concat(i + 1, ". [").concat(swarmSchema.agentList[i], "](./agent/").concat(swarmSchema.agentList[i], ".md)"));
7509
+ docDescription = this.agentSchemaService.get(swarmSchema.agentList[i]).docDescription;
7510
+ if (docDescription) {
7511
+ result.push("");
7512
+ result.push(docDescription);
7513
+ }
7514
+ result.push("");
7515
+ }
7516
+ }
7517
+ if (swarmSchema.callbacks) {
7518
+ result.push("## Used callbacks");
7519
+ result.push("");
7520
+ callbackList = Object.keys(swarmSchema.callbacks);
7521
+ for (i = 0; i !== callbackList.length; i++) {
7522
+ result.push("".concat(i + 1, ". ").concat(callbackList[i]));
7523
+ }
7524
+ result.push("");
7525
+ }
7526
+ fs.writeFileSync(path.join(dirName, "./".concat(swarmSchema.swarmName, ".md")), result.join("\n"));
7527
+ return [2 /*return*/];
7528
+ }
7529
+ });
7530
+ }); }, {
7531
+ maxExec: THREAD_POOL_SIZE,
7532
+ });
7533
+ this.writeAgentDoc = functoolsKit.execpool(function (agentSchema, dirName) { return __awaiter(_this, void 0, void 0, function () {
7534
+ var result, umlSchema, umlName, umlSvg, i, i, docDescription, _loop_1, this_1, i, i, _a, docDescription, embedding, shared, callbacks, callbackList, i_1, i, _b, docDescription, shared, callbacks, callbackList, i_2, callbackList, i;
7535
+ var _c;
7536
+ return __generator(this, function (_d) {
7537
+ switch (_d.label) {
7538
+ case 0:
7539
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7540
+ this.loggerService.info("docService writeAgentDoc", {
7541
+ agentSchema: agentSchema,
7542
+ });
7543
+ result = [];
7544
+ {
7545
+ result.push("# ".concat(agentSchema.agentName));
7546
+ if (agentSchema.docDescription) {
7547
+ result.push("");
7548
+ result.push("> ".concat(agentSchema.docDescription));
7549
+ }
7550
+ result.push("");
7551
+ }
7552
+ umlSchema = this.agentMetaService.toUML(agentSchema.agentName);
7553
+ umlName = "agent_schema_".concat(agentSchema.agentName, ".svg");
7554
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema)];
7555
+ case 1:
7556
+ umlSvg = _d.sent();
7557
+ if (umlSvg) {
7558
+ fs.writeFileSync(path.join(dirName, "image", umlName), umlSvg);
7559
+ result.push("![schema](./image/".concat(umlName, ")"));
7560
+ result.push("");
7561
+ }
7562
+ if (agentSchema.prompt) {
7563
+ result.push("## Main prompt");
7564
+ result.push("");
7565
+ result.push("```");
7566
+ result.push(agentSchema.prompt);
7567
+ result.push("```");
7568
+ result.push("");
7569
+ }
7570
+ if (agentSchema.system) {
7571
+ result.push("## System prompt");
7572
+ result.push("");
7573
+ for (i = 0; i !== agentSchema.system.length; i++) {
7574
+ if (!agentSchema.system[i]) {
7575
+ continue;
7576
+ }
7577
+ result.push("".concat(i + 1, ". `").concat(agentSchema.system[i], "`"));
7578
+ result.push("");
7579
+ }
7580
+ }
7581
+ if (agentSchema.dependsOn) {
7582
+ result.push("## Depends on");
7583
+ result.push("");
7584
+ for (i = 0; i !== agentSchema.dependsOn.length; i++) {
7585
+ if (!agentSchema.dependsOn[i]) {
7586
+ continue;
7587
+ }
7588
+ result.push("".concat(i + 1, ". [").concat(agentSchema.dependsOn[i], "](./").concat(agentSchema.dependsOn[i], ".md)"));
7589
+ docDescription = this.agentSchemaService.get(agentSchema.dependsOn[i]).docDescription;
7590
+ if (docDescription) {
7591
+ result.push("");
7592
+ result.push(docDescription);
7593
+ }
7594
+ result.push("");
7595
+ }
7596
+ }
7597
+ if (agentSchema.tools) {
7598
+ result.push("## Used tools");
7599
+ result.push("");
7600
+ _loop_1 = function (i) {
7601
+ if (!agentSchema.tools[i]) {
7602
+ return "continue";
7603
+ }
7604
+ result.push("> ".concat(i + 1, ". ").concat(agentSchema.tools[i]));
7605
+ var _e = this_1.toolSchemaService.get(agentSchema.tools[i]), fn = _e.function, docNote = _e.docNote, callbacks = _e.callbacks;
7606
+ if (fn.name) {
7607
+ result.push("");
7608
+ result.push("### Name for model");
7609
+ result.push("");
7610
+ result.push(fn.name);
7611
+ }
7612
+ if (fn.description) {
7613
+ result.push("");
7614
+ result.push("### Description for model");
7615
+ result.push("");
7616
+ result.push(fn.description);
7617
+ }
7618
+ if ((_c = fn.parameters) === null || _c === void 0 ? void 0 : _c.properties) {
7619
+ result.push("");
7620
+ result.push("### Parameters for model");
7621
+ Object.entries(fn.parameters.properties).forEach(function (_a) {
7622
+ var _b = __read(_a, 2), key = _b[0], _c = _b[1], type = _c.type, description = _c.description, e = _c.enum;
7623
+ result.push("");
7624
+ result.push(" - ".concat(key));
7625
+ {
7626
+ result.push("");
7627
+ result.push("**Type:** ".concat(type));
7628
+ }
7629
+ {
7630
+ result.push("");
7631
+ result.push("**Description:** ".concat(description));
7632
+ }
7633
+ if (e) {
7634
+ result.push("");
7635
+ result.push("**Enum:** ".concat(e.join(", ")));
7636
+ }
7637
+ {
7638
+ result.push("");
7639
+ result.push("**Required:** [".concat(fn.parameters.required.includes(key) ? "x" : " ", "]"));
7640
+ }
7641
+ });
7642
+ }
7643
+ if (callbacks) {
7644
+ result.push("");
7645
+ result.push("### Tool callbacks");
7646
+ result.push("");
7647
+ var callbackList = Object.keys(callbacks);
7648
+ for (var i_3 = 0; i_3 !== callbackList.length; i_3++) {
7649
+ result.push(" - ".concat(callbackList[i_3]));
7650
+ }
7651
+ }
7652
+ if (docNote) {
7653
+ result.push("");
7654
+ result.push("### Note for developer");
7655
+ result.push("");
7656
+ result.push(docNote);
7657
+ }
7658
+ result.push("");
7659
+ };
7660
+ this_1 = this;
7661
+ for (i = 0; i !== agentSchema.tools.length; i++) {
7662
+ _loop_1(i);
7663
+ }
7664
+ }
7665
+ if (agentSchema.storages) {
7666
+ result.push("## Used storages");
7667
+ result.push("");
7668
+ for (i = 0; i !== agentSchema.storages.length; i++) {
7669
+ if (!agentSchema.storages[i]) {
7670
+ continue;
7671
+ }
7672
+ result.push("".concat(i + 1, ". ").concat(agentSchema.storages[i]));
7673
+ _a = this.storageSchemaService.get(agentSchema.storages[i]), docDescription = _a.docDescription, embedding = _a.embedding, shared = _a.shared, callbacks = _a.callbacks;
7674
+ if (docDescription) {
7675
+ result.push("");
7676
+ result.push("### Storage description");
7677
+ result.push("");
7678
+ result.push(docDescription);
7679
+ }
7680
+ if (embedding) {
7681
+ result.push("");
7682
+ result.push("**Embedding:** ".concat(embedding));
7683
+ }
7684
+ {
7685
+ result.push("");
7686
+ result.push("**Shared:** [".concat(shared ? "x" : " ", "]"));
7687
+ }
7688
+ if (callbacks) {
7689
+ result.push("");
7690
+ result.push("### Storage callbacks");
7691
+ result.push("");
7692
+ callbackList = Object.keys(callbacks);
7693
+ for (i_1 = 0; i_1 !== callbackList.length; i_1++) {
7694
+ result.push(" - ".concat(callbackList[i_1]));
7695
+ }
7696
+ }
7697
+ result.push("");
7698
+ }
7699
+ }
7700
+ if (agentSchema.states) {
7701
+ result.push("## Used states");
7702
+ result.push("");
7703
+ for (i = 0; i !== agentSchema.states.length; i++) {
7704
+ if (!agentSchema.states[i]) {
7705
+ continue;
7706
+ }
7707
+ result.push("".concat(i + 1, ". ").concat(agentSchema.states[i]));
7708
+ _b = this.stateSchemaService.get(agentSchema.states[i]), docDescription = _b.docDescription, shared = _b.shared, callbacks = _b.callbacks;
7709
+ if (docDescription) {
7710
+ result.push("");
7711
+ result.push("### State description");
7712
+ result.push("");
7713
+ result.push(docDescription);
7714
+ }
7715
+ {
7716
+ result.push("");
7717
+ result.push("**Shared:** [".concat(shared ? "x" : " ", "]"));
7718
+ }
7719
+ if (callbacks) {
7720
+ result.push("");
7721
+ result.push("### State callbacks");
7722
+ result.push("");
7723
+ callbackList = Object.keys(callbacks);
7724
+ for (i_2 = 0; i_2 !== callbackList.length; i_2++) {
7725
+ result.push(" - ".concat(callbackList[i_2]));
7726
+ }
7727
+ }
7728
+ result.push("");
7729
+ }
7730
+ }
7731
+ if (agentSchema.callbacks) {
7732
+ result.push("## Used callbacks");
7733
+ result.push("");
7734
+ callbackList = Object.keys(agentSchema.callbacks);
7735
+ for (i = 0; i !== callbackList.length; i++) {
7736
+ result.push("".concat(i + 1, ". ").concat(callbackList[i]));
7737
+ }
7738
+ result.push("");
7739
+ }
7740
+ fs.writeFileSync(path.join(dirName, "./agent/".concat(agentSchema.agentName, ".md")), result.join("\n"));
7741
+ return [2 /*return*/];
7742
+ }
7743
+ });
7744
+ }); }, {
7745
+ maxExec: THREAD_POOL_SIZE,
7746
+ });
7747
+ this.dumpDocs = function () {
7748
+ var args_1 = [];
7749
+ for (var _i = 0; _i < arguments.length; _i++) {
7750
+ args_1[_i] = arguments[_i];
7751
+ }
7752
+ return __awaiter(_this, __spreadArray([], __read(args_1), false), void 0, function (dirName) {
7753
+ var SUBDIR_LIST_1, SUBDIR_LIST_1_1, subDir, path$1;
7754
+ var e_1, _a;
7755
+ var _this = this;
7756
+ if (dirName === void 0) { dirName = path.join(process.cwd(), "docs/chat"); }
7757
+ return __generator(this, function (_b) {
7758
+ switch (_b.label) {
7759
+ case 0:
7760
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7761
+ this.loggerService.info("docService dumpDocs", {
7762
+ dirName: dirName,
7763
+ });
7764
+ try {
7765
+ for (SUBDIR_LIST_1 = __values(SUBDIR_LIST), SUBDIR_LIST_1_1 = SUBDIR_LIST_1.next(); !SUBDIR_LIST_1_1.done; SUBDIR_LIST_1_1 = SUBDIR_LIST_1.next()) {
7766
+ subDir = SUBDIR_LIST_1_1.value;
7767
+ path$1 = path.join(dirName, subDir);
7768
+ if (!fs.existsSync(path$1)) {
7769
+ fs.mkdirSync(path$1, { recursive: true });
7770
+ }
7771
+ }
7772
+ }
7773
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
7774
+ finally {
7775
+ try {
7776
+ if (SUBDIR_LIST_1_1 && !SUBDIR_LIST_1_1.done && (_a = SUBDIR_LIST_1.return)) _a.call(SUBDIR_LIST_1);
7777
+ }
7778
+ finally { if (e_1) throw e_1.error; }
7779
+ }
7780
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7781
+ this.loggerService.info("docService dumpDocs building swarm docs");
7782
+ return [4 /*yield*/, Promise.all(this.swarmValidationService.getSwarmList().map(function (swarmName) { return __awaiter(_this, void 0, void 0, function () {
7783
+ var swarmSchema;
7784
+ return __generator(this, function (_a) {
7785
+ switch (_a.label) {
7786
+ case 0:
7787
+ swarmSchema = this.swarmSchemaService.get(swarmName);
7788
+ return [4 /*yield*/, this.writeSwarmDoc(swarmSchema, dirName)];
7789
+ case 1:
7790
+ _a.sent();
7791
+ return [2 /*return*/];
7792
+ }
7793
+ });
7794
+ }); }))];
7795
+ case 1:
7796
+ _b.sent();
7797
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7798
+ this.loggerService.info("docService dumpDocs building agent docs");
7799
+ return [4 /*yield*/, Promise.all(this.agentValidationService.getAgentList().map(function (agentName) { return __awaiter(_this, void 0, void 0, function () {
7800
+ var agentSchema;
7801
+ return __generator(this, function (_a) {
7802
+ switch (_a.label) {
7803
+ case 0:
7804
+ agentSchema = this.agentSchemaService.get(agentName);
7805
+ return [4 /*yield*/, this.writeAgentDoc(agentSchema, dirName)];
7806
+ case 1:
7807
+ _a.sent();
7808
+ return [2 /*return*/];
7809
+ }
7810
+ });
7811
+ }); }))];
7812
+ case 2:
7813
+ _b.sent();
7814
+ return [2 /*return*/];
7815
+ }
7816
+ });
7817
+ });
7818
+ };
7819
+ }
7820
+ return DocService;
7821
+ }());
7822
+
7420
7823
  {
7824
+ provide(TYPES.docService, function () { return new DocService(); });
7421
7825
  provide(TYPES.busService, function () { return new BusService(); });
7422
7826
  provide(TYPES.loggerService, function () { return new LoggerService(); });
7423
7827
  }
@@ -7471,6 +7875,7 @@ var SwarmMetaService = /** @class */ (function () {
7471
7875
  }
7472
7876
 
7473
7877
  var baseServices = {
7878
+ docService: inject(TYPES.docService),
7474
7879
  busService: inject(TYPES.busService),
7475
7880
  loggerService: inject(TYPES.loggerService),
7476
7881
  };
@@ -7520,7 +7925,17 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
7520
7925
  init();
7521
7926
  var swarm$1 = swarm;
7522
7927
 
7523
- var METHOD_NAME$E = "function.dumpAgent";
7928
+ var METHOD_NAME$F = "cli.dumpDocs";
7929
+ var dumpDocs = function (dirName) {
7930
+ if (dirName === void 0) { dirName = "./docs/chat"; }
7931
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
7932
+ swarm$1.loggerService.log(METHOD_NAME$F, {
7933
+ dirName: dirName,
7934
+ });
7935
+ return swarm$1.docService.dumpDocs(dirName);
7936
+ };
7937
+
7938
+ var METHOD_NAME$E = "cli.dumpAgent";
7524
7939
  /**
7525
7940
  * Dumps the agent information into PlantUML format.
7526
7941
  *
@@ -7537,7 +7952,7 @@ var dumpAgent = function (agentName, _a) {
7537
7952
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
7538
7953
  };
7539
7954
 
7540
- var METHOD_NAME$D = "function.dumpSwarm";
7955
+ var METHOD_NAME$D = "cli.dumpSwarm";
7541
7956
  /**
7542
7957
  * Dumps the swarm information into PlantUML format.
7543
7958
  *
@@ -9842,6 +10257,7 @@ exports.commitUserMessageForce = commitUserMessageForce;
9842
10257
  exports.complete = complete;
9843
10258
  exports.disposeConnection = disposeConnection;
9844
10259
  exports.dumpAgent = dumpAgent;
10260
+ exports.dumpDocs = dumpDocs;
9845
10261
  exports.dumpSwarm = dumpSwarm;
9846
10262
  exports.emit = emit;
9847
10263
  exports.emitForce = emitForce;
package/build/index.mjs CHANGED
@@ -3,6 +3,8 @@ import { createActivator } from 'di-kit';
3
3
  import { trycatch, singleshot, memoize, ToolRegistry, Subject, queued, getErrorMessage, errorData, not, randomString, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, execpool, SortedArray, schedule, ttl, Source, isObject } from 'functools-kit';
4
4
  import xml2js from 'xml2js';
5
5
  import { omit } from 'lodash-es';
6
+ import { join } from 'path';
7
+ import { writeFileSync, existsSync, mkdirSync } from 'fs';
6
8
 
7
9
  /******************************************************************************
8
10
  Copyright (c) Microsoft Corporation.
@@ -170,6 +172,7 @@ var init = (_a$2 = createActivator("agent-swarm"), _a$2.init), inject = _a$2.inj
170
172
 
171
173
  var baseServices$1 = {
172
174
  busService: Symbol('busService'),
175
+ docService: Symbol('docService'),
173
176
  loggerService: Symbol('loggerService'),
174
177
  };
175
178
  var contextServices$1 = {
@@ -1426,6 +1429,7 @@ var CC_LOGGER_ENABLE_DEBUG = false;
1426
1429
  var CC_LOGGER_ENABLE_LOG = true;
1427
1430
  var CC_LOGGER_ENABLE_CONSOLE = false;
1428
1431
  var CC_NAME_TO_TITLE = nameToTitle;
1432
+ var CC_FN_PLANTUML = function () { return Promise.resolve(""); };
1429
1433
  var GLOBAL_CONFIG = {
1430
1434
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
1431
1435
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
@@ -1448,6 +1452,7 @@ var GLOBAL_CONFIG = {
1448
1452
  CC_LOGGER_ENABLE_LOG: CC_LOGGER_ENABLE_LOG,
1449
1453
  CC_LOGGER_ENABLE_CONSOLE: CC_LOGGER_ENABLE_CONSOLE,
1450
1454
  CC_NAME_TO_TITLE: CC_NAME_TO_TITLE,
1455
+ CC_FN_PLANTUML: CC_FN_PLANTUML,
1451
1456
  };
1452
1457
  var setConfig = function (config) {
1453
1458
  Object.assign(GLOBAL_CONFIG, config);
@@ -1801,7 +1806,7 @@ var ClientAgent = /** @class */ (function () {
1801
1806
  messages: messages,
1802
1807
  mode: mode,
1803
1808
  tools: (_a = this.params.tools) === null || _a === void 0 ? void 0 : _a.map(function (t) {
1804
- return omit(t, "toolName", "call", "validate", "callbacks");
1809
+ return omit(t, "toolName", "docNote", "call", "validate", "callbacks");
1805
1810
  }),
1806
1811
  };
1807
1812
  return [4 /*yield*/, this.params.completion.getCompletion(args)];
@@ -4936,6 +4941,11 @@ var AgentValidationService = /** @class */ (function () {
4936
4941
  this.storageValidationService = inject(TYPES.storageValidationService);
4937
4942
  this._agentMap = new Map();
4938
4943
  this._agentDepsMap = new Map();
4944
+ this.getAgentList = function () {
4945
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4946
+ _this.loggerService.info("agentValidationService getAgentList");
4947
+ return __spreadArray([], __read(_this._agentMap.keys()), false);
4948
+ };
4939
4949
  /**
4940
4950
  * Retrieves the storages used by the agent
4941
4951
  * @param {agentName} agentName - The name of the swarm.
@@ -4943,6 +4953,10 @@ var AgentValidationService = /** @class */ (function () {
4943
4953
  * @throws Will throw an error if the swarm is not found.
4944
4954
  */
4945
4955
  this.getStorageList = function (agentName) {
4956
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4957
+ _this.loggerService.info("agentValidationService getStorageList", {
4958
+ agentName: agentName,
4959
+ });
4946
4960
  if (!_this._agentMap.has(agentName)) {
4947
4961
  throw new Error("agent-swarm agent ".concat(agentName, " not exist (getStorageList)"));
4948
4962
  }
@@ -4955,6 +4969,10 @@ var AgentValidationService = /** @class */ (function () {
4955
4969
  * @throws Will throw an error if the swarm is not found.
4956
4970
  */
4957
4971
  this.getStateList = function (agentName) {
4972
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4973
+ _this.loggerService.info("agentValidationService getStateList", {
4974
+ agentName: agentName,
4975
+ });
4958
4976
  if (!_this._agentMap.has(agentName)) {
4959
4977
  throw new Error("agent-swarm agent ".concat(agentName, " not exist (getStateList)"));
4960
4978
  }
@@ -5490,6 +5508,15 @@ var SwarmValidationService = /** @class */ (function () {
5490
5508
  }
5491
5509
  return swarm.agentList;
5492
5510
  };
5511
+ /**
5512
+ * Retrieves the list of swarms
5513
+ * @returns {string[]} The list of swarm names
5514
+ */
5515
+ this.getSwarmList = function () {
5516
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5517
+ _this.loggerService.info("swarmValidationService getSwarmList");
5518
+ return __spreadArray([], __read(_this._swarmMap.keys()), false);
5519
+ };
5493
5520
  /**
5494
5521
  * Validates a swarm and its agents.
5495
5522
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -7415,7 +7442,384 @@ var SwarmMetaService = /** @class */ (function () {
7415
7442
  return SwarmMetaService;
7416
7443
  }());
7417
7444
 
7445
+ var THREAD_POOL_SIZE = 5;
7446
+ var SUBDIR_LIST = ["agent", "image"];
7447
+ var DocService = /** @class */ (function () {
7448
+ function DocService() {
7449
+ var _this = this;
7450
+ this.loggerService = inject(TYPES.loggerService);
7451
+ this.swarmValidationService = inject(TYPES.swarmValidationService);
7452
+ this.agentValidationService = inject(TYPES.agentValidationService);
7453
+ this.swarmSchemaService = inject(TYPES.swarmSchemaService);
7454
+ this.agentSchemaService = inject(TYPES.agentSchemaService);
7455
+ this.toolSchemaService = inject(TYPES.toolSchemaService);
7456
+ this.storageSchemaService = inject(TYPES.storageSchemaService);
7457
+ this.stateSchemaService = inject(TYPES.stateSchemaService);
7458
+ this.agentMetaService = inject(TYPES.agentMetaService);
7459
+ this.swarmMetaService = inject(TYPES.swarmMetaService);
7460
+ this.writeSwarmDoc = execpool(function (swarmSchema, dirName) { return __awaiter(_this, void 0, void 0, function () {
7461
+ var result, umlSchema, umlName, umlSvg, docDescription, i, docDescription, callbackList, i;
7462
+ return __generator(this, function (_a) {
7463
+ switch (_a.label) {
7464
+ case 0:
7465
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7466
+ this.loggerService.info("docService writeSwarmDoc", {
7467
+ swarmSchema: swarmSchema,
7468
+ });
7469
+ result = [];
7470
+ {
7471
+ result.push("# ".concat(swarmSchema.swarmName));
7472
+ if (swarmSchema.docDescription) {
7473
+ result.push("");
7474
+ result.push("> ".concat(swarmSchema.docDescription));
7475
+ }
7476
+ result.push("");
7477
+ }
7478
+ umlSchema = this.swarmMetaService.toUML(swarmSchema.swarmName);
7479
+ umlName = "swarm_schema_".concat(swarmSchema.swarmName, ".svg");
7480
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema)];
7481
+ case 1:
7482
+ umlSvg = _a.sent();
7483
+ if (umlSvg) {
7484
+ writeFileSync(join(dirName, "image", umlName), umlSvg);
7485
+ result.push("![schema](./image/".concat(umlName, ")"));
7486
+ result.push("");
7487
+ }
7488
+ if (swarmSchema.defaultAgent) {
7489
+ result.push("## Default agent");
7490
+ result.push("");
7491
+ result.push(" - [".concat(swarmSchema.defaultAgent, "](./agent/").concat(swarmSchema.defaultAgent, ".md)"));
7492
+ docDescription = this.agentSchemaService.get(swarmSchema.defaultAgent).docDescription;
7493
+ if (docDescription) {
7494
+ result.push("");
7495
+ result.push(docDescription);
7496
+ }
7497
+ result.push("");
7498
+ }
7499
+ if (swarmSchema.agentList) {
7500
+ result.push("## Used agents");
7501
+ result.push("");
7502
+ for (i = 0; i !== swarmSchema.agentList.length; i++) {
7503
+ if (!swarmSchema.agentList[i]) {
7504
+ continue;
7505
+ }
7506
+ result.push("".concat(i + 1, ". [").concat(swarmSchema.agentList[i], "](./agent/").concat(swarmSchema.agentList[i], ".md)"));
7507
+ docDescription = this.agentSchemaService.get(swarmSchema.agentList[i]).docDescription;
7508
+ if (docDescription) {
7509
+ result.push("");
7510
+ result.push(docDescription);
7511
+ }
7512
+ result.push("");
7513
+ }
7514
+ }
7515
+ if (swarmSchema.callbacks) {
7516
+ result.push("## Used callbacks");
7517
+ result.push("");
7518
+ callbackList = Object.keys(swarmSchema.callbacks);
7519
+ for (i = 0; i !== callbackList.length; i++) {
7520
+ result.push("".concat(i + 1, ". ").concat(callbackList[i]));
7521
+ }
7522
+ result.push("");
7523
+ }
7524
+ writeFileSync(join(dirName, "./".concat(swarmSchema.swarmName, ".md")), result.join("\n"));
7525
+ return [2 /*return*/];
7526
+ }
7527
+ });
7528
+ }); }, {
7529
+ maxExec: THREAD_POOL_SIZE,
7530
+ });
7531
+ this.writeAgentDoc = execpool(function (agentSchema, dirName) { return __awaiter(_this, void 0, void 0, function () {
7532
+ var result, umlSchema, umlName, umlSvg, i, i, docDescription, _loop_1, this_1, i, i, _a, docDescription, embedding, shared, callbacks, callbackList, i_1, i, _b, docDescription, shared, callbacks, callbackList, i_2, callbackList, i;
7533
+ var _c;
7534
+ return __generator(this, function (_d) {
7535
+ switch (_d.label) {
7536
+ case 0:
7537
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7538
+ this.loggerService.info("docService writeAgentDoc", {
7539
+ agentSchema: agentSchema,
7540
+ });
7541
+ result = [];
7542
+ {
7543
+ result.push("# ".concat(agentSchema.agentName));
7544
+ if (agentSchema.docDescription) {
7545
+ result.push("");
7546
+ result.push("> ".concat(agentSchema.docDescription));
7547
+ }
7548
+ result.push("");
7549
+ }
7550
+ umlSchema = this.agentMetaService.toUML(agentSchema.agentName);
7551
+ umlName = "agent_schema_".concat(agentSchema.agentName, ".svg");
7552
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema)];
7553
+ case 1:
7554
+ umlSvg = _d.sent();
7555
+ if (umlSvg) {
7556
+ writeFileSync(join(dirName, "image", umlName), umlSvg);
7557
+ result.push("![schema](./image/".concat(umlName, ")"));
7558
+ result.push("");
7559
+ }
7560
+ if (agentSchema.prompt) {
7561
+ result.push("## Main prompt");
7562
+ result.push("");
7563
+ result.push("```");
7564
+ result.push(agentSchema.prompt);
7565
+ result.push("```");
7566
+ result.push("");
7567
+ }
7568
+ if (agentSchema.system) {
7569
+ result.push("## System prompt");
7570
+ result.push("");
7571
+ for (i = 0; i !== agentSchema.system.length; i++) {
7572
+ if (!agentSchema.system[i]) {
7573
+ continue;
7574
+ }
7575
+ result.push("".concat(i + 1, ". `").concat(agentSchema.system[i], "`"));
7576
+ result.push("");
7577
+ }
7578
+ }
7579
+ if (agentSchema.dependsOn) {
7580
+ result.push("## Depends on");
7581
+ result.push("");
7582
+ for (i = 0; i !== agentSchema.dependsOn.length; i++) {
7583
+ if (!agentSchema.dependsOn[i]) {
7584
+ continue;
7585
+ }
7586
+ result.push("".concat(i + 1, ". [").concat(agentSchema.dependsOn[i], "](./").concat(agentSchema.dependsOn[i], ".md)"));
7587
+ docDescription = this.agentSchemaService.get(agentSchema.dependsOn[i]).docDescription;
7588
+ if (docDescription) {
7589
+ result.push("");
7590
+ result.push(docDescription);
7591
+ }
7592
+ result.push("");
7593
+ }
7594
+ }
7595
+ if (agentSchema.tools) {
7596
+ result.push("## Used tools");
7597
+ result.push("");
7598
+ _loop_1 = function (i) {
7599
+ if (!agentSchema.tools[i]) {
7600
+ return "continue";
7601
+ }
7602
+ result.push("> ".concat(i + 1, ". ").concat(agentSchema.tools[i]));
7603
+ var _e = this_1.toolSchemaService.get(agentSchema.tools[i]), fn = _e.function, docNote = _e.docNote, callbacks = _e.callbacks;
7604
+ if (fn.name) {
7605
+ result.push("");
7606
+ result.push("### Name for model");
7607
+ result.push("");
7608
+ result.push(fn.name);
7609
+ }
7610
+ if (fn.description) {
7611
+ result.push("");
7612
+ result.push("### Description for model");
7613
+ result.push("");
7614
+ result.push(fn.description);
7615
+ }
7616
+ if ((_c = fn.parameters) === null || _c === void 0 ? void 0 : _c.properties) {
7617
+ result.push("");
7618
+ result.push("### Parameters for model");
7619
+ Object.entries(fn.parameters.properties).forEach(function (_a) {
7620
+ var _b = __read(_a, 2), key = _b[0], _c = _b[1], type = _c.type, description = _c.description, e = _c.enum;
7621
+ result.push("");
7622
+ result.push(" - ".concat(key));
7623
+ {
7624
+ result.push("");
7625
+ result.push("**Type:** ".concat(type));
7626
+ }
7627
+ {
7628
+ result.push("");
7629
+ result.push("**Description:** ".concat(description));
7630
+ }
7631
+ if (e) {
7632
+ result.push("");
7633
+ result.push("**Enum:** ".concat(e.join(", ")));
7634
+ }
7635
+ {
7636
+ result.push("");
7637
+ result.push("**Required:** [".concat(fn.parameters.required.includes(key) ? "x" : " ", "]"));
7638
+ }
7639
+ });
7640
+ }
7641
+ if (callbacks) {
7642
+ result.push("");
7643
+ result.push("### Tool callbacks");
7644
+ result.push("");
7645
+ var callbackList = Object.keys(callbacks);
7646
+ for (var i_3 = 0; i_3 !== callbackList.length; i_3++) {
7647
+ result.push(" - ".concat(callbackList[i_3]));
7648
+ }
7649
+ }
7650
+ if (docNote) {
7651
+ result.push("");
7652
+ result.push("### Note for developer");
7653
+ result.push("");
7654
+ result.push(docNote);
7655
+ }
7656
+ result.push("");
7657
+ };
7658
+ this_1 = this;
7659
+ for (i = 0; i !== agentSchema.tools.length; i++) {
7660
+ _loop_1(i);
7661
+ }
7662
+ }
7663
+ if (agentSchema.storages) {
7664
+ result.push("## Used storages");
7665
+ result.push("");
7666
+ for (i = 0; i !== agentSchema.storages.length; i++) {
7667
+ if (!agentSchema.storages[i]) {
7668
+ continue;
7669
+ }
7670
+ result.push("".concat(i + 1, ". ").concat(agentSchema.storages[i]));
7671
+ _a = this.storageSchemaService.get(agentSchema.storages[i]), docDescription = _a.docDescription, embedding = _a.embedding, shared = _a.shared, callbacks = _a.callbacks;
7672
+ if (docDescription) {
7673
+ result.push("");
7674
+ result.push("### Storage description");
7675
+ result.push("");
7676
+ result.push(docDescription);
7677
+ }
7678
+ if (embedding) {
7679
+ result.push("");
7680
+ result.push("**Embedding:** ".concat(embedding));
7681
+ }
7682
+ {
7683
+ result.push("");
7684
+ result.push("**Shared:** [".concat(shared ? "x" : " ", "]"));
7685
+ }
7686
+ if (callbacks) {
7687
+ result.push("");
7688
+ result.push("### Storage callbacks");
7689
+ result.push("");
7690
+ callbackList = Object.keys(callbacks);
7691
+ for (i_1 = 0; i_1 !== callbackList.length; i_1++) {
7692
+ result.push(" - ".concat(callbackList[i_1]));
7693
+ }
7694
+ }
7695
+ result.push("");
7696
+ }
7697
+ }
7698
+ if (agentSchema.states) {
7699
+ result.push("## Used states");
7700
+ result.push("");
7701
+ for (i = 0; i !== agentSchema.states.length; i++) {
7702
+ if (!agentSchema.states[i]) {
7703
+ continue;
7704
+ }
7705
+ result.push("".concat(i + 1, ". ").concat(agentSchema.states[i]));
7706
+ _b = this.stateSchemaService.get(agentSchema.states[i]), docDescription = _b.docDescription, shared = _b.shared, callbacks = _b.callbacks;
7707
+ if (docDescription) {
7708
+ result.push("");
7709
+ result.push("### State description");
7710
+ result.push("");
7711
+ result.push(docDescription);
7712
+ }
7713
+ {
7714
+ result.push("");
7715
+ result.push("**Shared:** [".concat(shared ? "x" : " ", "]"));
7716
+ }
7717
+ if (callbacks) {
7718
+ result.push("");
7719
+ result.push("### State callbacks");
7720
+ result.push("");
7721
+ callbackList = Object.keys(callbacks);
7722
+ for (i_2 = 0; i_2 !== callbackList.length; i_2++) {
7723
+ result.push(" - ".concat(callbackList[i_2]));
7724
+ }
7725
+ }
7726
+ result.push("");
7727
+ }
7728
+ }
7729
+ if (agentSchema.callbacks) {
7730
+ result.push("## Used callbacks");
7731
+ result.push("");
7732
+ callbackList = Object.keys(agentSchema.callbacks);
7733
+ for (i = 0; i !== callbackList.length; i++) {
7734
+ result.push("".concat(i + 1, ". ").concat(callbackList[i]));
7735
+ }
7736
+ result.push("");
7737
+ }
7738
+ writeFileSync(join(dirName, "./agent/".concat(agentSchema.agentName, ".md")), result.join("\n"));
7739
+ return [2 /*return*/];
7740
+ }
7741
+ });
7742
+ }); }, {
7743
+ maxExec: THREAD_POOL_SIZE,
7744
+ });
7745
+ this.dumpDocs = function () {
7746
+ var args_1 = [];
7747
+ for (var _i = 0; _i < arguments.length; _i++) {
7748
+ args_1[_i] = arguments[_i];
7749
+ }
7750
+ return __awaiter(_this, __spreadArray([], __read(args_1), false), void 0, function (dirName) {
7751
+ var SUBDIR_LIST_1, SUBDIR_LIST_1_1, subDir, path;
7752
+ var e_1, _a;
7753
+ var _this = this;
7754
+ if (dirName === void 0) { dirName = join(process.cwd(), "docs/chat"); }
7755
+ return __generator(this, function (_b) {
7756
+ switch (_b.label) {
7757
+ case 0:
7758
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7759
+ this.loggerService.info("docService dumpDocs", {
7760
+ dirName: dirName,
7761
+ });
7762
+ try {
7763
+ for (SUBDIR_LIST_1 = __values(SUBDIR_LIST), SUBDIR_LIST_1_1 = SUBDIR_LIST_1.next(); !SUBDIR_LIST_1_1.done; SUBDIR_LIST_1_1 = SUBDIR_LIST_1.next()) {
7764
+ subDir = SUBDIR_LIST_1_1.value;
7765
+ path = join(dirName, subDir);
7766
+ if (!existsSync(path)) {
7767
+ mkdirSync(path, { recursive: true });
7768
+ }
7769
+ }
7770
+ }
7771
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
7772
+ finally {
7773
+ try {
7774
+ if (SUBDIR_LIST_1_1 && !SUBDIR_LIST_1_1.done && (_a = SUBDIR_LIST_1.return)) _a.call(SUBDIR_LIST_1);
7775
+ }
7776
+ finally { if (e_1) throw e_1.error; }
7777
+ }
7778
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7779
+ this.loggerService.info("docService dumpDocs building swarm docs");
7780
+ return [4 /*yield*/, Promise.all(this.swarmValidationService.getSwarmList().map(function (swarmName) { return __awaiter(_this, void 0, void 0, function () {
7781
+ var swarmSchema;
7782
+ return __generator(this, function (_a) {
7783
+ switch (_a.label) {
7784
+ case 0:
7785
+ swarmSchema = this.swarmSchemaService.get(swarmName);
7786
+ return [4 /*yield*/, this.writeSwarmDoc(swarmSchema, dirName)];
7787
+ case 1:
7788
+ _a.sent();
7789
+ return [2 /*return*/];
7790
+ }
7791
+ });
7792
+ }); }))];
7793
+ case 1:
7794
+ _b.sent();
7795
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7796
+ this.loggerService.info("docService dumpDocs building agent docs");
7797
+ return [4 /*yield*/, Promise.all(this.agentValidationService.getAgentList().map(function (agentName) { return __awaiter(_this, void 0, void 0, function () {
7798
+ var agentSchema;
7799
+ return __generator(this, function (_a) {
7800
+ switch (_a.label) {
7801
+ case 0:
7802
+ agentSchema = this.agentSchemaService.get(agentName);
7803
+ return [4 /*yield*/, this.writeAgentDoc(agentSchema, dirName)];
7804
+ case 1:
7805
+ _a.sent();
7806
+ return [2 /*return*/];
7807
+ }
7808
+ });
7809
+ }); }))];
7810
+ case 2:
7811
+ _b.sent();
7812
+ return [2 /*return*/];
7813
+ }
7814
+ });
7815
+ });
7816
+ };
7817
+ }
7818
+ return DocService;
7819
+ }());
7820
+
7418
7821
  {
7822
+ provide(TYPES.docService, function () { return new DocService(); });
7419
7823
  provide(TYPES.busService, function () { return new BusService(); });
7420
7824
  provide(TYPES.loggerService, function () { return new LoggerService(); });
7421
7825
  }
@@ -7469,6 +7873,7 @@ var SwarmMetaService = /** @class */ (function () {
7469
7873
  }
7470
7874
 
7471
7875
  var baseServices = {
7876
+ docService: inject(TYPES.docService),
7472
7877
  busService: inject(TYPES.busService),
7473
7878
  loggerService: inject(TYPES.loggerService),
7474
7879
  };
@@ -7518,7 +7923,17 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
7518
7923
  init();
7519
7924
  var swarm$1 = swarm;
7520
7925
 
7521
- var METHOD_NAME$E = "function.dumpAgent";
7926
+ var METHOD_NAME$F = "cli.dumpDocs";
7927
+ var dumpDocs = function (dirName) {
7928
+ if (dirName === void 0) { dirName = "./docs/chat"; }
7929
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
7930
+ swarm$1.loggerService.log(METHOD_NAME$F, {
7931
+ dirName: dirName,
7932
+ });
7933
+ return swarm$1.docService.dumpDocs(dirName);
7934
+ };
7935
+
7936
+ var METHOD_NAME$E = "cli.dumpAgent";
7522
7937
  /**
7523
7938
  * Dumps the agent information into PlantUML format.
7524
7939
  *
@@ -7535,7 +7950,7 @@ var dumpAgent = function (agentName, _a) {
7535
7950
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
7536
7951
  };
7537
7952
 
7538
- var METHOD_NAME$D = "function.dumpSwarm";
7953
+ var METHOD_NAME$D = "cli.dumpSwarm";
7539
7954
  /**
7540
7955
  * Dumps the swarm information into PlantUML format.
7541
7956
  *
@@ -9808,4 +10223,4 @@ var SchemaUtils = /** @class */ (function () {
9808
10223
  */
9809
10224
  var Schema = new SchemaUtils();
9810
10225
 
9811
- export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
10226
+ export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.92",
3
+ "version": "1.0.93",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -145,6 +145,8 @@ interface IStorageData {
145
145
  * @template T - Type of the storage data.
146
146
  */
147
147
  interface IStorageSchema<T extends IStorageData = IStorageData> {
148
+ /** The description for documentation */
149
+ docDescription?: string;
148
150
  /**
149
151
  * All agents will share the same ClientStorage instance
150
152
  */
@@ -340,6 +342,8 @@ interface IStateCallbacks<T extends IStateData = IStateData> {
340
342
  * @template T - The type of the state data.
341
343
  */
342
344
  interface IStateSchema<T extends IStateData = IStateData> {
345
+ /** The description for documentation */
346
+ docDescription?: string;
343
347
  /**
344
348
  * The agents can share the state
345
349
  */
@@ -563,6 +567,8 @@ interface ISwarmParams extends Omit<ISwarmSchema, keyof {
563
567
  * @interface
564
568
  */
565
569
  interface ISwarmSchema {
570
+ /** The description for documentation */
571
+ docDescription?: string;
566
572
  /** Fetch the active agent on init */
567
573
  getActiveAgent?: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName> | AgentName;
568
574
  /** Update the active agent after navigation */
@@ -1240,6 +1246,8 @@ interface IAgentToolCallbacks<T = Record<string, unknown>> {
1240
1246
  * @template T - The type of the parameters for the tool.
1241
1247
  */
1242
1248
  interface IAgentTool<T = Record<string, unknown>> extends ITool {
1249
+ /** The description for documentation */
1250
+ docNote?: string;
1243
1251
  /** The name of the tool. */
1244
1252
  toolName: ToolName;
1245
1253
  /**
@@ -1380,6 +1388,8 @@ interface IAgentSchemaCallbacks {
1380
1388
  * Interface representing the schema for an agent.
1381
1389
  */
1382
1390
  interface IAgentSchema {
1391
+ /** The description for documentation */
1392
+ docDescription?: string;
1383
1393
  /** The name of the agent. */
1384
1394
  agentName: AgentName;
1385
1395
  /** The name of the completion. */
@@ -2346,6 +2356,7 @@ declare class AgentValidationService {
2346
2356
  private readonly storageValidationService;
2347
2357
  private _agentMap;
2348
2358
  private _agentDepsMap;
2359
+ getAgentList: () => string[];
2349
2360
  /**
2350
2361
  * Retrieves the storages used by the agent
2351
2362
  * @param {agentName} agentName - The name of the swarm.
@@ -2552,6 +2563,11 @@ declare class SwarmValidationService {
2552
2563
  * @throws Will throw an error if the swarm is not found.
2553
2564
  */
2554
2565
  getAgentList: (swarmName: SwarmName) => string[];
2566
+ /**
2567
+ * Retrieves the list of swarms
2568
+ * @returns {string[]} The list of swarm names
2569
+ */
2570
+ getSwarmList: () => string[];
2555
2571
  /**
2556
2572
  * Validates a swarm and its agents.
2557
2573
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -3091,6 +3107,22 @@ declare class SwarmMetaService {
3091
3107
  toUML: (swarmName: SwarmName) => string;
3092
3108
  }
3093
3109
 
3110
+ declare class DocService {
3111
+ private readonly loggerService;
3112
+ private readonly swarmValidationService;
3113
+ private readonly agentValidationService;
3114
+ private readonly swarmSchemaService;
3115
+ private readonly agentSchemaService;
3116
+ private readonly toolSchemaService;
3117
+ private readonly storageSchemaService;
3118
+ private readonly stateSchemaService;
3119
+ private readonly agentMetaService;
3120
+ private readonly swarmMetaService;
3121
+ private writeSwarmDoc;
3122
+ private writeAgentDoc;
3123
+ dumpDocs: (dirName?: string) => Promise<void>;
3124
+ }
3125
+
3094
3126
  declare const swarm: {
3095
3127
  agentValidationService: AgentValidationService;
3096
3128
  toolValidationService: ToolValidationService;
@@ -3126,10 +3158,13 @@ declare const swarm: {
3126
3158
  executionContextService: {
3127
3159
  readonly context: IExecutionContext;
3128
3160
  };
3161
+ docService: DocService;
3129
3162
  busService: BusService;
3130
3163
  loggerService: LoggerService;
3131
3164
  };
3132
3165
 
3166
+ declare const dumpDocs: (dirName?: string) => Promise<void>;
3167
+
3133
3168
  /**
3134
3169
  * The config for UML generation
3135
3170
  */
@@ -3912,6 +3947,7 @@ declare const GLOBAL_CONFIG: {
3912
3947
  CC_LOGGER_ENABLE_LOG: boolean;
3913
3948
  CC_LOGGER_ENABLE_CONSOLE: boolean;
3914
3949
  CC_NAME_TO_TITLE: (name: string) => string;
3950
+ CC_FN_PLANTUML: (uml: string) => Promise<string>;
3915
3951
  };
3916
3952
  declare const setConfig: (config: Partial<typeof GLOBAL_CONFIG>) => void;
3917
3953
 
@@ -4075,4 +4111,4 @@ declare class SchemaUtils {
4075
4111
  */
4076
4112
  declare const Schema: SchemaUtils;
4077
4113
 
4078
- export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
4114
+ export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };