agent-swarm-kit 1.0.31 → 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
  }
@@ -1713,6 +1755,24 @@ var ClientSession = /** @class */ (function () {
1713
1755
  }
1714
1756
  });
1715
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
+ }); };
1716
1776
  /**
1717
1777
  * Commits a system message.
1718
1778
  * @param {string} message - The system message to commit.
@@ -1873,6 +1933,7 @@ var SessionConnectionService = /** @class */ (function () {
1873
1933
  case 0:
1874
1934
  this.loggerService.log("sessionConnectionService commitToolOutput", {
1875
1935
  context: this.contextService.context,
1936
+ content: content,
1876
1937
  });
1877
1938
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
1878
1939
  case 1: return [2 /*return*/, _a.sent()];
@@ -1890,6 +1951,7 @@ var SessionConnectionService = /** @class */ (function () {
1890
1951
  case 0:
1891
1952
  this.loggerService.log("sessionConnectionService commitSystemMessage", {
1892
1953
  context: this.contextService.context,
1954
+ message: message,
1893
1955
  });
1894
1956
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
1895
1957
  case 1: return [2 /*return*/, _a.sent()];
@@ -1907,12 +1969,30 @@ var SessionConnectionService = /** @class */ (function () {
1907
1969
  case 0:
1908
1970
  this.loggerService.log("sessionConnectionService commitUserMessage", {
1909
1971
  context: this.contextService.context,
1972
+ message: message,
1910
1973
  });
1911
1974
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
1912
1975
  case 1: return [2 /*return*/, _a.sent()];
1913
1976
  }
1914
1977
  });
1915
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
+ }); };
1916
1996
  /**
1917
1997
  * Disposes of the session connection service.
1918
1998
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -2133,6 +2213,37 @@ var AgentPublicService = /** @class */ (function () {
2133
2213
  }
2134
2214
  });
2135
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
+ }); };
2136
2247
  /**
2137
2248
  * Disposes of the agent.
2138
2249
  * @param {string} clientId - The client ID.
@@ -2530,6 +2641,37 @@ var SessionPublicService = /** @class */ (function () {
2530
2641
  }
2531
2642
  });
2532
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
+ }); };
2533
2675
  /**
2534
2676
  * Disposes of the session.
2535
2677
  * @param {string} clientId - The client ID.
@@ -3995,6 +4137,45 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
3995
4137
  });
3996
4138
  }); };
3997
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
+
3998
4179
  /**
3999
4180
  * Send the message to the active agent in the swarm content like it income from client side
4000
4181
  * Should be used to review tool output and initiate conversation from the model side to client
@@ -4267,6 +4448,7 @@ exports.addCompletion = addCompletion;
4267
4448
  exports.addSwarm = addSwarm;
4268
4449
  exports.addTool = addTool;
4269
4450
  exports.changeAgent = changeAgent;
4451
+ exports.commitFlush = commitFlush;
4270
4452
  exports.commitSystemMessage = commitSystemMessage;
4271
4453
  exports.commitToolOutput = commitToolOutput;
4272
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
  }
@@ -1711,6 +1753,24 @@ var ClientSession = /** @class */ (function () {
1711
1753
  }
1712
1754
  });
1713
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
+ }); };
1714
1774
  /**
1715
1775
  * Commits a system message.
1716
1776
  * @param {string} message - The system message to commit.
@@ -1871,6 +1931,7 @@ var SessionConnectionService = /** @class */ (function () {
1871
1931
  case 0:
1872
1932
  this.loggerService.log("sessionConnectionService commitToolOutput", {
1873
1933
  context: this.contextService.context,
1934
+ content: content,
1874
1935
  });
1875
1936
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
1876
1937
  case 1: return [2 /*return*/, _a.sent()];
@@ -1888,6 +1949,7 @@ var SessionConnectionService = /** @class */ (function () {
1888
1949
  case 0:
1889
1950
  this.loggerService.log("sessionConnectionService commitSystemMessage", {
1890
1951
  context: this.contextService.context,
1952
+ message: message,
1891
1953
  });
1892
1954
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
1893
1955
  case 1: return [2 /*return*/, _a.sent()];
@@ -1905,12 +1967,30 @@ var SessionConnectionService = /** @class */ (function () {
1905
1967
  case 0:
1906
1968
  this.loggerService.log("sessionConnectionService commitUserMessage", {
1907
1969
  context: this.contextService.context,
1970
+ message: message,
1908
1971
  });
1909
1972
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
1910
1973
  case 1: return [2 /*return*/, _a.sent()];
1911
1974
  }
1912
1975
  });
1913
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
+ }); };
1914
1994
  /**
1915
1995
  * Disposes of the session connection service.
1916
1996
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -2131,6 +2211,37 @@ var AgentPublicService = /** @class */ (function () {
2131
2211
  }
2132
2212
  });
2133
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
+ }); };
2134
2245
  /**
2135
2246
  * Disposes of the agent.
2136
2247
  * @param {string} clientId - The client ID.
@@ -2528,6 +2639,37 @@ var SessionPublicService = /** @class */ (function () {
2528
2639
  }
2529
2640
  });
2530
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
+ }); };
2531
2673
  /**
2532
2674
  * Disposes of the session.
2533
2675
  * @param {string} clientId - The client ID.
@@ -3993,6 +4135,45 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
3993
4135
  });
3994
4136
  }); };
3995
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
+
3996
4177
  /**
3997
4178
  * Send the message to the active agent in the swarm content like it income from client side
3998
4179
  * Should be used to review tool output and initiate conversation from the model side to client
@@ -4259,4 +4440,4 @@ var makeAutoDispose = function (clientId, swarmName, _a) {
4259
4440
  };
4260
4441
  };
4261
4442
 
4262
- 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.31",
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.
@@ -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 };