agent-swarm-kit 1.0.30 → 1.0.32

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
@@ -481,7 +481,7 @@ var ClientAgent = /** @class */ (function () {
481
481
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
482
482
  return [4 /*yield*/, this.params.history.push({
483
483
  role: "resque",
484
- mode: 'tool',
484
+ mode: "tool",
485
485
  agentName: this.params.agentName,
486
486
  content: reason || "Unknown error",
487
487
  })];
@@ -489,7 +489,7 @@ var ClientAgent = /** @class */ (function () {
489
489
  _a.sent();
490
490
  return [4 /*yield*/, this.params.history.push({
491
491
  role: "user",
492
- mode: 'tool',
492
+ mode: "tool",
493
493
  agentName: this.params.agentName,
494
494
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_PROMPT,
495
495
  })];
@@ -508,7 +508,7 @@ var ClientAgent = /** @class */ (function () {
508
508
  return [4 /*yield*/, this.params.history.push({
509
509
  agentName: this.params.agentName,
510
510
  role: "assistant",
511
- mode: 'tool',
511
+ mode: "tool",
512
512
  content: content,
513
513
  })];
514
514
  case 5:
@@ -571,11 +571,11 @@ var ClientAgent = /** @class */ (function () {
571
571
  return __generator(this, function (_a) {
572
572
  switch (_a.label) {
573
573
  case 0:
574
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"));
574
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"), { message: message });
575
575
  return [4 /*yield*/, this.params.history.push({
576
576
  role: "user",
577
577
  agentName: this.params.agentName,
578
- mode: 'user',
578
+ mode: "user",
579
579
  content: message.trim(),
580
580
  })];
581
581
  case 1:
@@ -584,6 +584,27 @@ var ClientAgent = /** @class */ (function () {
584
584
  }
585
585
  });
586
586
  }); };
587
+ /**
588
+ * Commits flush of agent history
589
+ * @returns {Promise<void>}
590
+ */
591
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
592
+ return __generator(this, function (_a) {
593
+ switch (_a.label) {
594
+ case 0:
595
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitFlush"));
596
+ return [4 /*yield*/, this.params.history.push({
597
+ role: "flush",
598
+ agentName: this.params.agentName,
599
+ mode: "tool",
600
+ content: "",
601
+ })];
602
+ case 1:
603
+ _a.sent();
604
+ return [2 /*return*/];
605
+ }
606
+ });
607
+ }); };
587
608
  /**
588
609
  * Commits a system message to the history.
589
610
  * @param {string} message - The system message to commit.
@@ -593,11 +614,11 @@ var ClientAgent = /** @class */ (function () {
593
614
  return __generator(this, function (_a) {
594
615
  switch (_a.label) {
595
616
  case 0:
596
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"));
617
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"), { message: message });
597
618
  return [4 /*yield*/, this.params.history.push({
598
619
  role: "system",
599
620
  agentName: this.params.agentName,
600
- mode: 'tool',
621
+ mode: "tool",
601
622
  content: message.trim(),
602
623
  })];
603
624
  case 1:
@@ -615,11 +636,11 @@ var ClientAgent = /** @class */ (function () {
615
636
  return __generator(this, function (_a) {
616
637
  switch (_a.label) {
617
638
  case 0:
618
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput content=").concat(content));
639
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content });
619
640
  return [4 /*yield*/, this.params.history.push({
620
641
  role: "tool",
621
642
  agentName: this.params.agentName,
622
- mode: 'tool',
643
+ mode: "tool",
623
644
  content: content,
624
645
  })];
625
646
  case 1:
@@ -899,6 +920,22 @@ var AgentConnectionService = /** @class */ (function () {
899
920
  }
900
921
  });
901
922
  }); };
923
+ /**
924
+ * Commits flush of agent history
925
+ * @returns {Promise<any>} The commit result.
926
+ */
927
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
928
+ return __generator(this, function (_a) {
929
+ switch (_a.label) {
930
+ case 0:
931
+ this.loggerService.log("agentConnectionService commitFlush", {
932
+ context: this.contextService.context,
933
+ });
934
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitFlush()];
935
+ case 1: return [2 /*return*/, _a.sent()];
936
+ }
937
+ });
938
+ }); };
902
939
  /**
903
940
  * Disposes of the agent connection.
904
941
  * @returns {Promise<void>} The dispose result.
@@ -1028,6 +1065,11 @@ var ClientHistory = /** @class */ (function () {
1028
1065
  systemMessagesRaw.splice(0, systemMessagesRaw.length);
1029
1066
  return [3 /*break*/, 4];
1030
1067
  }
1068
+ if (message.role === "flush") {
1069
+ commonMessagesRaw.splice(0, commonMessagesRaw.length);
1070
+ systemMessagesRaw.splice(0, systemMessagesRaw.length);
1071
+ return [3 /*break*/, 4];
1072
+ }
1031
1073
  if (message.role === "system") {
1032
1074
  systemMessagesRaw.push(message);
1033
1075
  }
@@ -1650,42 +1692,27 @@ var ClientSession = /** @class */ (function () {
1650
1692
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
1651
1693
  * @returns {Promise<string>} - The output of the execution.
1652
1694
  */
1653
- this.execute = function (message_1, mode_1) {
1654
- var args_1 = [];
1655
- for (var _i = 2; _i < arguments.length; _i++) {
1656
- args_1[_i - 2] = arguments[_i];
1657
- }
1658
- return __awaiter(_this, __spreadArray([message_1, mode_1], __read(args_1), false), void 0, function (message, mode, noEmit) {
1659
- var agent, outputAwaiter, output, _a;
1660
- if (noEmit === void 0) { noEmit = false; }
1661
- return __generator(this, function (_b) {
1662
- switch (_b.label) {
1663
- case 0:
1664
- this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1665
- message: message,
1666
- mode: mode,
1667
- noEmit: noEmit,
1668
- });
1669
- return [4 /*yield*/, this.params.swarm.getAgent()];
1670
- case 1:
1671
- agent = _b.sent();
1672
- outputAwaiter = this.params.swarm.waitForOutput();
1673
- agent.execute(message, mode);
1674
- return [4 /*yield*/, outputAwaiter];
1675
- case 2:
1676
- output = _b.sent();
1677
- _a = !noEmit;
1678
- if (!_a) return [3 /*break*/, 4];
1679
- return [4 /*yield*/, this._emitSubject.next(output)];
1680
- case 3:
1681
- _a = (_b.sent());
1682
- _b.label = 4;
1683
- case 4:
1684
- return [2 /*return*/, output];
1685
- }
1686
- });
1695
+ this.execute = function (message, mode) { return __awaiter(_this, void 0, void 0, function () {
1696
+ var agent, outputAwaiter, output;
1697
+ return __generator(this, function (_a) {
1698
+ switch (_a.label) {
1699
+ case 0:
1700
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1701
+ message: message,
1702
+ mode: mode,
1703
+ });
1704
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1705
+ case 1:
1706
+ agent = _a.sent();
1707
+ outputAwaiter = this.params.swarm.waitForOutput();
1708
+ agent.execute(message, mode);
1709
+ return [4 /*yield*/, outputAwaiter];
1710
+ case 2:
1711
+ output = _a.sent();
1712
+ return [2 /*return*/, output];
1713
+ }
1687
1714
  });
1688
- };
1715
+ }); };
1689
1716
  /**
1690
1717
  * Commits tool output.
1691
1718
  * @param {string} content - The content to commit.
@@ -1728,6 +1755,24 @@ var ClientSession = /** @class */ (function () {
1728
1755
  }
1729
1756
  });
1730
1757
  }); };
1758
+ /**
1759
+ * Commits flush of agent history
1760
+ * @returns {Promise<void>}
1761
+ */
1762
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
1763
+ var agent;
1764
+ return __generator(this, function (_a) {
1765
+ switch (_a.label) {
1766
+ case 0:
1767
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitFlush"));
1768
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1769
+ case 1:
1770
+ agent = _a.sent();
1771
+ return [4 /*yield*/, agent.commitFlush()];
1772
+ case 2: return [2 /*return*/, _a.sent()];
1773
+ }
1774
+ });
1775
+ }); };
1731
1776
  /**
1732
1777
  * Commits a system message.
1733
1778
  * @param {string} message - The system message to commit.
@@ -1783,7 +1828,7 @@ var ClientSession = /** @class */ (function () {
1783
1828
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1784
1829
  _a = connector;
1785
1830
  _b = {};
1786
- return [4 /*yield*/, this.execute(incoming.data, "user", true)];
1831
+ return [4 /*yield*/, this.execute(incoming.data, "user")];
1787
1832
  case 1:
1788
1833
  _b.data = _c.sent();
1789
1834
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1888,6 +1933,7 @@ var SessionConnectionService = /** @class */ (function () {
1888
1933
  case 0:
1889
1934
  this.loggerService.log("sessionConnectionService commitToolOutput", {
1890
1935
  context: this.contextService.context,
1936
+ content: content,
1891
1937
  });
1892
1938
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
1893
1939
  case 1: return [2 /*return*/, _a.sent()];
@@ -1905,6 +1951,7 @@ var SessionConnectionService = /** @class */ (function () {
1905
1951
  case 0:
1906
1952
  this.loggerService.log("sessionConnectionService commitSystemMessage", {
1907
1953
  context: this.contextService.context,
1954
+ message: message,
1908
1955
  });
1909
1956
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
1910
1957
  case 1: return [2 /*return*/, _a.sent()];
@@ -1922,12 +1969,30 @@ var SessionConnectionService = /** @class */ (function () {
1922
1969
  case 0:
1923
1970
  this.loggerService.log("sessionConnectionService commitUserMessage", {
1924
1971
  context: this.contextService.context,
1972
+ message: message,
1925
1973
  });
1926
1974
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
1927
1975
  case 1: return [2 /*return*/, _a.sent()];
1928
1976
  }
1929
1977
  });
1930
1978
  }); };
1979
+ /**
1980
+ * Commits user message to the agent without answer.
1981
+ * @param {string} message - The message to commit.
1982
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
1983
+ */
1984
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
1985
+ return __generator(this, function (_a) {
1986
+ switch (_a.label) {
1987
+ case 0:
1988
+ this.loggerService.log("sessionConnectionService commitFlush", {
1989
+ context: this.contextService.context,
1990
+ });
1991
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitFlush()];
1992
+ case 1: return [2 /*return*/, _a.sent()];
1993
+ }
1994
+ });
1995
+ }); };
1931
1996
  /**
1932
1997
  * Disposes of the session connection service.
1933
1998
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -2148,6 +2213,37 @@ var AgentPublicService = /** @class */ (function () {
2148
2213
  }
2149
2214
  });
2150
2215
  }); };
2216
+ /**
2217
+ * Commits flush of agent history
2218
+ * @param {string} clientId - The client ID.
2219
+ * @param {AgentName} agentName - The name of the agent.
2220
+ * @returns {Promise<unknown>} The commit result.
2221
+ */
2222
+ this.commitFlush = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2223
+ var _this = this;
2224
+ return __generator(this, function (_a) {
2225
+ switch (_a.label) {
2226
+ case 0:
2227
+ this.loggerService.log("agentPublicService commitFlush", {
2228
+ clientId: clientId,
2229
+ agentName: agentName,
2230
+ });
2231
+ return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2232
+ return __generator(this, function (_a) {
2233
+ switch (_a.label) {
2234
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitFlush()];
2235
+ case 1: return [2 /*return*/, _a.sent()];
2236
+ }
2237
+ });
2238
+ }); }, {
2239
+ clientId: clientId,
2240
+ agentName: agentName,
2241
+ swarmName: "",
2242
+ })];
2243
+ case 1: return [2 /*return*/, _a.sent()];
2244
+ }
2245
+ });
2246
+ }); };
2151
2247
  /**
2152
2248
  * Disposes of the agent.
2153
2249
  * @param {string} clientId - The client ID.
@@ -2545,6 +2641,37 @@ var SessionPublicService = /** @class */ (function () {
2545
2641
  }
2546
2642
  });
2547
2643
  }); };
2644
+ /**
2645
+ * Commits flush of agent history
2646
+ * @param {string} clientId - The client ID.
2647
+ * @param {SwarmName} swarmName - The swarm name.
2648
+ * @returns {Promise<void>}
2649
+ */
2650
+ this.commitFlush = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2651
+ var _this = this;
2652
+ return __generator(this, function (_a) {
2653
+ switch (_a.label) {
2654
+ case 0:
2655
+ this.loggerService.log("sessionPublicService commitFlush", {
2656
+ clientId: clientId,
2657
+ swarmName: swarmName,
2658
+ });
2659
+ return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2660
+ return __generator(this, function (_a) {
2661
+ switch (_a.label) {
2662
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitFlush()];
2663
+ case 1: return [2 /*return*/, _a.sent()];
2664
+ }
2665
+ });
2666
+ }); }, {
2667
+ clientId: clientId,
2668
+ swarmName: swarmName,
2669
+ agentName: "",
2670
+ })];
2671
+ case 1: return [2 /*return*/, _a.sent()];
2672
+ }
2673
+ });
2674
+ }); };
2548
2675
  /**
2549
2676
  * Disposes of the session.
2550
2677
  * @param {string} clientId - The client ID.
@@ -4010,6 +4137,45 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
4010
4137
  });
4011
4138
  }); };
4012
4139
 
4140
+ /**
4141
+ * Commits flush of agent history
4142
+ *
4143
+ * @param {string} clientId - The ID of the client.
4144
+ * @param {string} agentName - The name of the agent.
4145
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
4146
+ */
4147
+ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4148
+ var swarmName, currentAgentName;
4149
+ return __generator(this, function (_a) {
4150
+ switch (_a.label) {
4151
+ case 0:
4152
+ swarm.loggerService.log('function commitFlush', {
4153
+ clientId: clientId,
4154
+ agentName: agentName,
4155
+ });
4156
+ swarm.agentValidationService.validate(agentName, "commitFlush");
4157
+ swarm.sessionValidationService.validate(clientId, "commitFlush");
4158
+ swarmName = swarm.sessionValidationService.getSwarm(clientId);
4159
+ swarm.swarmValidationService.validate(swarmName, "commitFlush");
4160
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
4161
+ case 1:
4162
+ currentAgentName = _a.sent();
4163
+ if (currentAgentName !== agentName) {
4164
+ swarm.loggerService.log('function "commitFlush" skipped due to the agent change', {
4165
+ currentAgentName: currentAgentName,
4166
+ agentName: agentName,
4167
+ clientId: clientId,
4168
+ });
4169
+ return [2 /*return*/];
4170
+ }
4171
+ return [4 /*yield*/, swarm.sessionPublicService.commitFlush(clientId, swarmName)];
4172
+ case 2:
4173
+ _a.sent();
4174
+ return [2 /*return*/];
4175
+ }
4176
+ });
4177
+ }); };
4178
+
4013
4179
  /**
4014
4180
  * Send the message to the active agent in the swarm content like it income from client side
4015
4181
  * Should be used to review tool output and initiate conversation from the model side to client
@@ -4282,6 +4448,7 @@ exports.addCompletion = addCompletion;
4282
4448
  exports.addSwarm = addSwarm;
4283
4449
  exports.addTool = addTool;
4284
4450
  exports.changeAgent = changeAgent;
4451
+ exports.commitFlush = commitFlush;
4285
4452
  exports.commitSystemMessage = commitSystemMessage;
4286
4453
  exports.commitToolOutput = commitToolOutput;
4287
4454
  exports.commitUserMessage = commitUserMessage;
package/build/index.mjs CHANGED
@@ -479,7 +479,7 @@ var ClientAgent = /** @class */ (function () {
479
479
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
480
480
  return [4 /*yield*/, this.params.history.push({
481
481
  role: "resque",
482
- mode: 'tool',
482
+ mode: "tool",
483
483
  agentName: this.params.agentName,
484
484
  content: reason || "Unknown error",
485
485
  })];
@@ -487,7 +487,7 @@ var ClientAgent = /** @class */ (function () {
487
487
  _a.sent();
488
488
  return [4 /*yield*/, this.params.history.push({
489
489
  role: "user",
490
- mode: 'tool',
490
+ mode: "tool",
491
491
  agentName: this.params.agentName,
492
492
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_PROMPT,
493
493
  })];
@@ -506,7 +506,7 @@ var ClientAgent = /** @class */ (function () {
506
506
  return [4 /*yield*/, this.params.history.push({
507
507
  agentName: this.params.agentName,
508
508
  role: "assistant",
509
- mode: 'tool',
509
+ mode: "tool",
510
510
  content: content,
511
511
  })];
512
512
  case 5:
@@ -569,11 +569,11 @@ var ClientAgent = /** @class */ (function () {
569
569
  return __generator(this, function (_a) {
570
570
  switch (_a.label) {
571
571
  case 0:
572
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"));
572
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"), { message: message });
573
573
  return [4 /*yield*/, this.params.history.push({
574
574
  role: "user",
575
575
  agentName: this.params.agentName,
576
- mode: 'user',
576
+ mode: "user",
577
577
  content: message.trim(),
578
578
  })];
579
579
  case 1:
@@ -582,6 +582,27 @@ var ClientAgent = /** @class */ (function () {
582
582
  }
583
583
  });
584
584
  }); };
585
+ /**
586
+ * Commits flush of agent history
587
+ * @returns {Promise<void>}
588
+ */
589
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
590
+ return __generator(this, function (_a) {
591
+ switch (_a.label) {
592
+ case 0:
593
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitFlush"));
594
+ return [4 /*yield*/, this.params.history.push({
595
+ role: "flush",
596
+ agentName: this.params.agentName,
597
+ mode: "tool",
598
+ content: "",
599
+ })];
600
+ case 1:
601
+ _a.sent();
602
+ return [2 /*return*/];
603
+ }
604
+ });
605
+ }); };
585
606
  /**
586
607
  * Commits a system message to the history.
587
608
  * @param {string} message - The system message to commit.
@@ -591,11 +612,11 @@ var ClientAgent = /** @class */ (function () {
591
612
  return __generator(this, function (_a) {
592
613
  switch (_a.label) {
593
614
  case 0:
594
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"));
615
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"), { message: message });
595
616
  return [4 /*yield*/, this.params.history.push({
596
617
  role: "system",
597
618
  agentName: this.params.agentName,
598
- mode: 'tool',
619
+ mode: "tool",
599
620
  content: message.trim(),
600
621
  })];
601
622
  case 1:
@@ -613,11 +634,11 @@ var ClientAgent = /** @class */ (function () {
613
634
  return __generator(this, function (_a) {
614
635
  switch (_a.label) {
615
636
  case 0:
616
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput content=").concat(content));
637
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content });
617
638
  return [4 /*yield*/, this.params.history.push({
618
639
  role: "tool",
619
640
  agentName: this.params.agentName,
620
- mode: 'tool',
641
+ mode: "tool",
621
642
  content: content,
622
643
  })];
623
644
  case 1:
@@ -897,6 +918,22 @@ var AgentConnectionService = /** @class */ (function () {
897
918
  }
898
919
  });
899
920
  }); };
921
+ /**
922
+ * Commits flush of agent history
923
+ * @returns {Promise<any>} The commit result.
924
+ */
925
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
926
+ return __generator(this, function (_a) {
927
+ switch (_a.label) {
928
+ case 0:
929
+ this.loggerService.log("agentConnectionService commitFlush", {
930
+ context: this.contextService.context,
931
+ });
932
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitFlush()];
933
+ case 1: return [2 /*return*/, _a.sent()];
934
+ }
935
+ });
936
+ }); };
900
937
  /**
901
938
  * Disposes of the agent connection.
902
939
  * @returns {Promise<void>} The dispose result.
@@ -1026,6 +1063,11 @@ var ClientHistory = /** @class */ (function () {
1026
1063
  systemMessagesRaw.splice(0, systemMessagesRaw.length);
1027
1064
  return [3 /*break*/, 4];
1028
1065
  }
1066
+ if (message.role === "flush") {
1067
+ commonMessagesRaw.splice(0, commonMessagesRaw.length);
1068
+ systemMessagesRaw.splice(0, systemMessagesRaw.length);
1069
+ return [3 /*break*/, 4];
1070
+ }
1029
1071
  if (message.role === "system") {
1030
1072
  systemMessagesRaw.push(message);
1031
1073
  }
@@ -1648,42 +1690,27 @@ var ClientSession = /** @class */ (function () {
1648
1690
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
1649
1691
  * @returns {Promise<string>} - The output of the execution.
1650
1692
  */
1651
- this.execute = function (message_1, mode_1) {
1652
- var args_1 = [];
1653
- for (var _i = 2; _i < arguments.length; _i++) {
1654
- args_1[_i - 2] = arguments[_i];
1655
- }
1656
- return __awaiter(_this, __spreadArray([message_1, mode_1], __read(args_1), false), void 0, function (message, mode, noEmit) {
1657
- var agent, outputAwaiter, output, _a;
1658
- if (noEmit === void 0) { noEmit = false; }
1659
- return __generator(this, function (_b) {
1660
- switch (_b.label) {
1661
- case 0:
1662
- this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1663
- message: message,
1664
- mode: mode,
1665
- noEmit: noEmit,
1666
- });
1667
- return [4 /*yield*/, this.params.swarm.getAgent()];
1668
- case 1:
1669
- agent = _b.sent();
1670
- outputAwaiter = this.params.swarm.waitForOutput();
1671
- agent.execute(message, mode);
1672
- return [4 /*yield*/, outputAwaiter];
1673
- case 2:
1674
- output = _b.sent();
1675
- _a = !noEmit;
1676
- if (!_a) return [3 /*break*/, 4];
1677
- return [4 /*yield*/, this._emitSubject.next(output)];
1678
- case 3:
1679
- _a = (_b.sent());
1680
- _b.label = 4;
1681
- case 4:
1682
- return [2 /*return*/, output];
1683
- }
1684
- });
1693
+ this.execute = function (message, mode) { return __awaiter(_this, void 0, void 0, function () {
1694
+ var agent, outputAwaiter, output;
1695
+ return __generator(this, function (_a) {
1696
+ switch (_a.label) {
1697
+ case 0:
1698
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1699
+ message: message,
1700
+ mode: mode,
1701
+ });
1702
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1703
+ case 1:
1704
+ agent = _a.sent();
1705
+ outputAwaiter = this.params.swarm.waitForOutput();
1706
+ agent.execute(message, mode);
1707
+ return [4 /*yield*/, outputAwaiter];
1708
+ case 2:
1709
+ output = _a.sent();
1710
+ return [2 /*return*/, output];
1711
+ }
1685
1712
  });
1686
- };
1713
+ }); };
1687
1714
  /**
1688
1715
  * Commits tool output.
1689
1716
  * @param {string} content - The content to commit.
@@ -1726,6 +1753,24 @@ var ClientSession = /** @class */ (function () {
1726
1753
  }
1727
1754
  });
1728
1755
  }); };
1756
+ /**
1757
+ * Commits flush of agent history
1758
+ * @returns {Promise<void>}
1759
+ */
1760
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
1761
+ var agent;
1762
+ return __generator(this, function (_a) {
1763
+ switch (_a.label) {
1764
+ case 0:
1765
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitFlush"));
1766
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1767
+ case 1:
1768
+ agent = _a.sent();
1769
+ return [4 /*yield*/, agent.commitFlush()];
1770
+ case 2: return [2 /*return*/, _a.sent()];
1771
+ }
1772
+ });
1773
+ }); };
1729
1774
  /**
1730
1775
  * Commits a system message.
1731
1776
  * @param {string} message - The system message to commit.
@@ -1781,7 +1826,7 @@ var ClientSession = /** @class */ (function () {
1781
1826
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1782
1827
  _a = connector;
1783
1828
  _b = {};
1784
- return [4 /*yield*/, this.execute(incoming.data, "user", true)];
1829
+ return [4 /*yield*/, this.execute(incoming.data, "user")];
1785
1830
  case 1:
1786
1831
  _b.data = _c.sent();
1787
1832
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1886,6 +1931,7 @@ var SessionConnectionService = /** @class */ (function () {
1886
1931
  case 0:
1887
1932
  this.loggerService.log("sessionConnectionService commitToolOutput", {
1888
1933
  context: this.contextService.context,
1934
+ content: content,
1889
1935
  });
1890
1936
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
1891
1937
  case 1: return [2 /*return*/, _a.sent()];
@@ -1903,6 +1949,7 @@ var SessionConnectionService = /** @class */ (function () {
1903
1949
  case 0:
1904
1950
  this.loggerService.log("sessionConnectionService commitSystemMessage", {
1905
1951
  context: this.contextService.context,
1952
+ message: message,
1906
1953
  });
1907
1954
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
1908
1955
  case 1: return [2 /*return*/, _a.sent()];
@@ -1920,12 +1967,30 @@ var SessionConnectionService = /** @class */ (function () {
1920
1967
  case 0:
1921
1968
  this.loggerService.log("sessionConnectionService commitUserMessage", {
1922
1969
  context: this.contextService.context,
1970
+ message: message,
1923
1971
  });
1924
1972
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
1925
1973
  case 1: return [2 /*return*/, _a.sent()];
1926
1974
  }
1927
1975
  });
1928
1976
  }); };
1977
+ /**
1978
+ * Commits user message to the agent without answer.
1979
+ * @param {string} message - The message to commit.
1980
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
1981
+ */
1982
+ this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
1983
+ return __generator(this, function (_a) {
1984
+ switch (_a.label) {
1985
+ case 0:
1986
+ this.loggerService.log("sessionConnectionService commitFlush", {
1987
+ context: this.contextService.context,
1988
+ });
1989
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitFlush()];
1990
+ case 1: return [2 /*return*/, _a.sent()];
1991
+ }
1992
+ });
1993
+ }); };
1929
1994
  /**
1930
1995
  * Disposes of the session connection service.
1931
1996
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -2146,6 +2211,37 @@ var AgentPublicService = /** @class */ (function () {
2146
2211
  }
2147
2212
  });
2148
2213
  }); };
2214
+ /**
2215
+ * Commits flush of agent history
2216
+ * @param {string} clientId - The client ID.
2217
+ * @param {AgentName} agentName - The name of the agent.
2218
+ * @returns {Promise<unknown>} The commit result.
2219
+ */
2220
+ this.commitFlush = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2221
+ var _this = this;
2222
+ return __generator(this, function (_a) {
2223
+ switch (_a.label) {
2224
+ case 0:
2225
+ this.loggerService.log("agentPublicService commitFlush", {
2226
+ clientId: clientId,
2227
+ agentName: agentName,
2228
+ });
2229
+ return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2230
+ return __generator(this, function (_a) {
2231
+ switch (_a.label) {
2232
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitFlush()];
2233
+ case 1: return [2 /*return*/, _a.sent()];
2234
+ }
2235
+ });
2236
+ }); }, {
2237
+ clientId: clientId,
2238
+ agentName: agentName,
2239
+ swarmName: "",
2240
+ })];
2241
+ case 1: return [2 /*return*/, _a.sent()];
2242
+ }
2243
+ });
2244
+ }); };
2149
2245
  /**
2150
2246
  * Disposes of the agent.
2151
2247
  * @param {string} clientId - The client ID.
@@ -2543,6 +2639,37 @@ var SessionPublicService = /** @class */ (function () {
2543
2639
  }
2544
2640
  });
2545
2641
  }); };
2642
+ /**
2643
+ * Commits flush of agent history
2644
+ * @param {string} clientId - The client ID.
2645
+ * @param {SwarmName} swarmName - The swarm name.
2646
+ * @returns {Promise<void>}
2647
+ */
2648
+ this.commitFlush = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2649
+ var _this = this;
2650
+ return __generator(this, function (_a) {
2651
+ switch (_a.label) {
2652
+ case 0:
2653
+ this.loggerService.log("sessionPublicService commitFlush", {
2654
+ clientId: clientId,
2655
+ swarmName: swarmName,
2656
+ });
2657
+ return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2658
+ return __generator(this, function (_a) {
2659
+ switch (_a.label) {
2660
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitFlush()];
2661
+ case 1: return [2 /*return*/, _a.sent()];
2662
+ }
2663
+ });
2664
+ }); }, {
2665
+ clientId: clientId,
2666
+ swarmName: swarmName,
2667
+ agentName: "",
2668
+ })];
2669
+ case 1: return [2 /*return*/, _a.sent()];
2670
+ }
2671
+ });
2672
+ }); };
2546
2673
  /**
2547
2674
  * Disposes of the session.
2548
2675
  * @param {string} clientId - The client ID.
@@ -4008,6 +4135,45 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
4008
4135
  });
4009
4136
  }); };
4010
4137
 
4138
+ /**
4139
+ * Commits flush of agent history
4140
+ *
4141
+ * @param {string} clientId - The ID of the client.
4142
+ * @param {string} agentName - The name of the agent.
4143
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
4144
+ */
4145
+ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4146
+ var swarmName, currentAgentName;
4147
+ return __generator(this, function (_a) {
4148
+ switch (_a.label) {
4149
+ case 0:
4150
+ swarm.loggerService.log('function commitFlush', {
4151
+ clientId: clientId,
4152
+ agentName: agentName,
4153
+ });
4154
+ swarm.agentValidationService.validate(agentName, "commitFlush");
4155
+ swarm.sessionValidationService.validate(clientId, "commitFlush");
4156
+ swarmName = swarm.sessionValidationService.getSwarm(clientId);
4157
+ swarm.swarmValidationService.validate(swarmName, "commitFlush");
4158
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
4159
+ case 1:
4160
+ currentAgentName = _a.sent();
4161
+ if (currentAgentName !== agentName) {
4162
+ swarm.loggerService.log('function "commitFlush" skipped due to the agent change', {
4163
+ currentAgentName: currentAgentName,
4164
+ agentName: agentName,
4165
+ clientId: clientId,
4166
+ });
4167
+ return [2 /*return*/];
4168
+ }
4169
+ return [4 /*yield*/, swarm.sessionPublicService.commitFlush(clientId, swarmName)];
4170
+ case 2:
4171
+ _a.sent();
4172
+ return [2 /*return*/];
4173
+ }
4174
+ });
4175
+ }); };
4176
+
4011
4177
  /**
4012
4178
  * Send the message to the active agent in the swarm content like it income from client side
4013
4179
  * Should be used to review tool output and initiate conversation from the model side to client
@@ -4274,4 +4440,4 @@ var makeAutoDispose = function (clientId, swarmName, _a) {
4274
4440
  };
4275
4441
  };
4276
4442
 
4277
- export { ContextService, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };
4443
+ export { ContextService, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitFlush, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, 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.30",
3
+ "version": "1.0.32",
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
@@ -9,9 +9,9 @@ import { IPubsubArray, Subject } from 'functools-kit';
9
9
  interface IModelMessage {
10
10
  /**
11
11
  * The role of the message sender.
12
- * @type {'assistant' | 'system' | 'tool' | 'user' | 'resque'}
12
+ * @type {'assistant' | 'system' | 'tool' | 'user' | 'resque' | 'flush'}
13
13
  */
14
- role: "assistant" | "system" | "tool" | "user" | "resque";
14
+ role: "assistant" | "system" | "tool" | "user" | "resque" | "flush";
15
15
  /**
16
16
  * The name of the agent sending the message.
17
17
  * @type {string}
@@ -345,6 +345,11 @@ interface ISession {
345
345
  * @returns {Promise<void>}
346
346
  */
347
347
  commitUserMessage: (message: string) => Promise<void>;
348
+ /**
349
+ * Commit flush of agent history
350
+ * @returns {Promise<void>}
351
+ */
352
+ commitFlush: () => Promise<void>;
348
353
  /**
349
354
  * Commit a system message.
350
355
  * @param {string} message - The message to commit.
@@ -523,6 +528,11 @@ interface IAgent {
523
528
  * @returns A promise that resolves when the message is committed.
524
529
  */
525
530
  commitUserMessage(message: string): Promise<void>;
531
+ /**
532
+ * Clear the history for agent
533
+ * @returns A promise that resolves when the flush is committed.
534
+ */
535
+ commitFlush(): Promise<void>;
526
536
  }
527
537
  /** Type representing the name of an agent. */
528
538
  type AgentName = string;
@@ -614,6 +624,11 @@ declare class ClientAgent implements IAgent {
614
624
  * @returns {Promise<void>}
615
625
  */
616
626
  commitUserMessage: (message: string) => Promise<void>;
627
+ /**
628
+ * Commits flush of agent history
629
+ * @returns {Promise<void>}
630
+ */
631
+ commitFlush: () => Promise<void>;
617
632
  /**
618
633
  * Commits a system message to the history.
619
634
  * @param {string} message - The system message to commit.
@@ -682,6 +697,11 @@ declare class AgentConnectionService implements IAgent {
682
697
  * @returns {Promise<any>} The commit result.
683
698
  */
684
699
  commitUserMessage: (message: string) => Promise<void>;
700
+ /**
701
+ * Commits flush of agent history
702
+ * @returns {Promise<any>} The commit result.
703
+ */
704
+ commitFlush: () => Promise<void>;
685
705
  /**
686
706
  * Disposes of the agent connection.
687
707
  * @returns {Promise<void>} The dispose result.
@@ -962,7 +982,7 @@ declare class ClientSession implements ISession {
962
982
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
963
983
  * @returns {Promise<string>} - The output of the execution.
964
984
  */
965
- execute: (message: string, mode: ExecutionMode, noEmit?: boolean) => Promise<string>;
985
+ execute: (message: string, mode: ExecutionMode) => Promise<string>;
966
986
  /**
967
987
  * Commits tool output.
968
988
  * @param {string} content - The content to commit.
@@ -975,6 +995,11 @@ declare class ClientSession implements ISession {
975
995
  * @returns {Promise<void>}
976
996
  */
977
997
  commitUserMessage: (message: string) => Promise<void>;
998
+ /**
999
+ * Commits flush of agent history
1000
+ * @returns {Promise<void>}
1001
+ */
1002
+ commitFlush: () => Promise<void>;
978
1003
  /**
979
1004
  * Commits a system message.
980
1005
  * @param {string} message - The system message to commit.
@@ -1040,6 +1065,12 @@ declare class SessionConnectionService implements ISession {
1040
1065
  * @returns {Promise<void>} A promise that resolves when the message is committed.
1041
1066
  */
1042
1067
  commitUserMessage: (message: string) => Promise<void>;
1068
+ /**
1069
+ * Commits user message to the agent without answer.
1070
+ * @param {string} message - The message to commit.
1071
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
1072
+ */
1073
+ commitFlush: () => Promise<void>;
1043
1074
  /**
1044
1075
  * Disposes of the session connection service.
1045
1076
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -1107,6 +1138,13 @@ declare class AgentPublicService implements TAgentConnectionService {
1107
1138
  * @returns {Promise<unknown>} The commit result.
1108
1139
  */
1109
1140
  commitUserMessage: (message: string, clientId: string, agentName: AgentName) => Promise<void>;
1141
+ /**
1142
+ * Commits flush of agent history
1143
+ * @param {string} clientId - The client ID.
1144
+ * @param {AgentName} agentName - The name of the agent.
1145
+ * @returns {Promise<unknown>} The commit result.
1146
+ */
1147
+ commitFlush: (clientId: string, agentName: AgentName) => Promise<void>;
1110
1148
  /**
1111
1149
  * Disposes of the agent.
1112
1150
  * @param {string} clientId - The client ID.
@@ -1225,6 +1263,13 @@ declare class SessionPublicService implements TSessionConnectionService {
1225
1263
  * @returns {Promise<void>}
1226
1264
  */
1227
1265
  commitUserMessage: (message: string, clientId: string, swarmName: SwarmName) => Promise<void>;
1266
+ /**
1267
+ * Commits flush of agent history
1268
+ * @param {string} clientId - The client ID.
1269
+ * @param {SwarmName} swarmName - The swarm name.
1270
+ * @returns {Promise<void>}
1271
+ */
1272
+ commitFlush: (clientId: string, swarmName: SwarmName) => Promise<void>;
1228
1273
  /**
1229
1274
  * Disposes of the session.
1230
1275
  * @param {string} clientId - The client ID.
@@ -1705,6 +1750,15 @@ declare const commitToolOutput: (content: string, clientId: string, agentName: A
1705
1750
  */
1706
1751
  declare const commitSystemMessage: (content: string, clientId: string, agentName: string) => Promise<void>;
1707
1752
 
1753
+ /**
1754
+ * Commits flush of agent history
1755
+ *
1756
+ * @param {string} clientId - The ID of the client.
1757
+ * @param {string} agentName - The name of the agent.
1758
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
1759
+ */
1760
+ declare const commitFlush: (clientId: string, agentName: string) => Promise<void>;
1761
+
1708
1762
  /**
1709
1763
  * Send the message to the active agent in the swarm content like it income from client side
1710
1764
  * Should be used to review tool output and initiate conversation from the model side to client
@@ -1833,4 +1887,4 @@ declare const GLOBAL_CONFIG: {
1833
1887
  };
1834
1888
  declare const setConfig: (config: Partial<typeof GLOBAL_CONFIG>) => void;
1835
1889
 
1836
- export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionArgs, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };
1890
+ export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionArgs, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitFlush, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };