agent-swarm-kit 1.0.7 → 1.0.8

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
@@ -235,11 +235,13 @@ var CC_EMPTY_OUTPUT_PLACEHOLDERS = [
235
235
  ];
236
236
  var CC_KEEP_MESSAGES = 5;
237
237
  var CC_ANSWER_TIMEOUT_SECONDS = 120000;
238
+ var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
238
239
  var GLOBAL_CONFIG = {
239
240
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
240
241
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
241
242
  CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
242
243
  CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
244
+ CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
243
245
  };
244
246
  var setConfig = function (config) {
245
247
  Object.assign(GLOBAL_CONFIG, config);
@@ -259,7 +261,7 @@ var ClientAgent = /** @class */ (function () {
259
261
  return __generator(this, function (_a) {
260
262
  switch (_a.label) {
261
263
  case 0:
262
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _emitOuput"));
264
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"));
263
265
  validation = null;
264
266
  return [4 /*yield*/, this.params.validate(result)];
265
267
  case 1:
@@ -270,7 +272,7 @@ var ClientAgent = /** @class */ (function () {
270
272
  return [4 /*yield*/, this.params.validate(result_1)];
271
273
  case 3:
272
274
  if (validation = _a.sent()) {
273
- throw new Error("agent-swarm-kit ClientAgent agentName=".concat(this.params.agentName, " model ressurect failed: ").concat(validation));
275
+ throw new Error("agent-swarm-kit ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " model ressurect failed: ").concat(validation));
274
276
  }
275
277
  return [4 /*yield*/, this._outputSubject.next(result_1)];
276
278
  case 4:
@@ -288,7 +290,7 @@ var ClientAgent = /** @class */ (function () {
288
290
  return __generator(this, function (_a) {
289
291
  switch (_a.label) {
290
292
  case 0:
291
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _resurrectModel"));
293
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
292
294
  return [4 /*yield*/, this.params.history.push({
293
295
  role: "resque",
294
296
  agentName: this.params.agentName,
@@ -311,7 +313,7 @@ var ClientAgent = /** @class */ (function () {
311
313
  return [4 /*yield*/, this.params.validate(result)];
312
314
  case 4:
313
315
  if (!(validation = _a.sent())) return [3 /*break*/, 6];
314
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _resurrectModel validation error: ").concat(validation));
316
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
315
317
  content = getPlaceholder();
316
318
  return [4 /*yield*/, this.params.history.push({
317
319
  agentName: this.params.agentName,
@@ -332,7 +334,7 @@ var ClientAgent = /** @class */ (function () {
332
334
  return __generator(this, function (_a) {
333
335
  switch (_a.label) {
334
336
  case 0:
335
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " waitForOutput"));
337
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " waitForOutput"));
336
338
  return [4 /*yield*/, this._outputSubject.toPromise()];
337
339
  case 1: return [2 /*return*/, _a.sent()];
338
340
  }
@@ -344,7 +346,7 @@ var ClientAgent = /** @class */ (function () {
344
346
  return __generator(this, function (_b) {
345
347
  switch (_b.label) {
346
348
  case 0:
347
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " getCompletion"));
349
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " getCompletion"));
348
350
  return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt)];
349
351
  case 1:
350
352
  messages = _b.sent();
@@ -362,7 +364,7 @@ var ClientAgent = /** @class */ (function () {
362
364
  return __generator(this, function (_a) {
363
365
  switch (_a.label) {
364
366
  case 0:
365
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " commitSystemMessage"));
367
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"));
366
368
  return [4 /*yield*/, this.params.history.push({
367
369
  role: "system",
368
370
  agentName: this.params.agentName,
@@ -378,7 +380,7 @@ var ClientAgent = /** @class */ (function () {
378
380
  return __generator(this, function (_a) {
379
381
  switch (_a.label) {
380
382
  case 0:
381
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " commitToolOutput content=").concat(content));
383
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput content=").concat(content));
382
384
  return [4 /*yield*/, this.params.history.push({
383
385
  role: "tool",
384
386
  agentName: this.params.agentName,
@@ -400,7 +402,7 @@ var ClientAgent = /** @class */ (function () {
400
402
  return __generator(this, function (_e) {
401
403
  switch (_e.label) {
402
404
  case 0:
403
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute begin"), { incoming: incoming });
405
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming });
404
406
  return [4 /*yield*/, this.params.history.push({
405
407
  role: "user",
406
408
  agentName: this.params.agentName,
@@ -412,7 +414,7 @@ var ClientAgent = /** @class */ (function () {
412
414
  case 2:
413
415
  message = _e.sent();
414
416
  if (!message.tool_calls) return [3 /*break*/, 11];
415
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " tool call begin"));
417
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
416
418
  _loop_1 = function (tool) {
417
419
  var targetFn, result_2, result_3;
418
420
  return __generator(this, function (_f) {
@@ -423,11 +425,11 @@ var ClientAgent = /** @class */ (function () {
423
425
  case 1:
424
426
  _f.sent();
425
427
  if (!!targetFn) return [3 /*break*/, 4];
426
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool function not found"));
428
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"));
427
429
  return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
428
430
  case 2:
429
431
  result_2 = _f.sent();
430
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " execute end result=").concat(result_2));
432
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
431
433
  return [4 /*yield*/, this_1._emitOuput(result_2)];
432
434
  case 3:
433
435
  _f.sent();
@@ -435,11 +437,11 @@ var ClientAgent = /** @class */ (function () {
435
437
  case 4: return [4 /*yield*/, functoolsKit.not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
436
438
  case 5:
437
439
  if (!_f.sent()) return [3 /*break*/, 8];
438
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool validation not passed"));
440
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
439
441
  return [4 /*yield*/, this_1._resurrectModel("Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
440
442
  case 6:
441
443
  result_3 = _f.sent();
442
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " execute end result=").concat(result_3));
444
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
443
445
  return [4 /*yield*/, this_1._emitOuput(result_3)];
444
446
  case 7:
445
447
  _f.sent();
@@ -449,14 +451,14 @@ var ClientAgent = /** @class */ (function () {
449
451
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
450
452
  */
451
453
  targetFn.call(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
452
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool call executing"));
454
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
453
455
  return [4 /*yield*/, Promise.race([
454
456
  this_1._toolCommitSubject.toPromise(),
455
457
  this_1._outputSubject.toPromise(),
456
458
  ])];
457
459
  case 9:
458
460
  _f.sent();
459
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool call end"));
461
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
460
462
  return [2 /*return*/];
461
463
  }
462
464
  });
@@ -493,7 +495,7 @@ var ClientAgent = /** @class */ (function () {
493
495
  case 10: return [2 /*return*/];
494
496
  case 11:
495
497
  if (!message.tool_calls) {
496
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute no tool calls detected"));
498
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute no tool calls detected"));
497
499
  }
498
500
  result = message.content;
499
501
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
@@ -503,7 +505,7 @@ var ClientAgent = /** @class */ (function () {
503
505
  return [4 /*yield*/, this.params.validate(result)];
504
506
  case 13:
505
507
  if (!(validation = _e.sent())) return [3 /*break*/, 16];
506
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute invalid tool call detected: ").concat(validation), { result: result });
508
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
507
509
  return [4 /*yield*/, this._resurrectModel("Invalid model output: ".concat(result))];
508
510
  case 14:
509
511
  result1 = _e.sent();
@@ -512,7 +514,7 @@ var ClientAgent = /** @class */ (function () {
512
514
  _e.sent();
513
515
  return [2 /*return*/];
514
516
  case 16:
515
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute end result=").concat(result));
517
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
516
518
  return [4 /*yield*/, this._emitOuput(result)];
517
519
  case 17:
518
520
  _e.sent();
@@ -520,6 +522,7 @@ var ClientAgent = /** @class */ (function () {
520
522
  }
521
523
  });
522
524
  }); });
525
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"));
523
526
  }
524
527
  return ClientAgent;
525
528
  }());
@@ -615,6 +618,7 @@ var AgentConnectionService = /** @class */ (function () {
615
618
  var _this = this;
616
619
  this.loggerService = inject(TYPES.loggerService);
617
620
  this.contextService = inject(TYPES.contextService);
621
+ this.sessionValidationService = inject(TYPES.sessionValidationService);
618
622
  this.historyConnectionService = inject(TYPES.historyConnectionService);
619
623
  this.agentSchemaService = inject(TYPES.agentSchemaService);
620
624
  this.toolSchemaService = inject(TYPES.toolSchemaService);
@@ -625,6 +629,7 @@ var AgentConnectionService = /** @class */ (function () {
625
629
  }, function (clientId, agentName) {
626
630
  var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, tools = _a.tools, completionName = _a.completion, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
627
631
  var completion = _this.completionSchemaService.get(completionName);
632
+ _this.sessionValidationService.addAgentUsage(clientId, agentName);
628
633
  return new ClientAgent({
629
634
  clientId: clientId,
630
635
  agentName: agentName,
@@ -693,6 +698,7 @@ var AgentConnectionService = /** @class */ (function () {
693
698
  context: this.contextService.context,
694
699
  });
695
700
  this.getAgent.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
701
+ this.sessionValidationService.removeAgentUsage(this.contextService.context.clientId, this.contextService.context.agentName);
696
702
  return [2 /*return*/];
697
703
  });
698
704
  }); };
@@ -842,6 +848,7 @@ var ClientHistory = /** @class */ (function () {
842
848
  }
843
849
  });
844
850
  }); };
851
+ this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"));
845
852
  }
846
853
  return ClientHistory;
847
854
  }());
@@ -851,18 +858,22 @@ var HistoryConnectionService = /** @class */ (function () {
851
858
  var _this = this;
852
859
  this.loggerService = inject(TYPES.loggerService);
853
860
  this.contextService = inject(TYPES.contextService);
861
+ this.sessionValidationService = inject(TYPES.sessionValidationService);
854
862
  this.getItems = functoolsKit.memoize(function (_a) {
855
863
  var _b = __read(_a, 1), clientId = _b[0];
856
864
  return clientId;
857
- }, function () { return new functoolsKit.PubsubArrayAdapter(); });
865
+ }, function (clientId, agentName) {
866
+ return GLOBAL_CONFIG.CC_GET_AGENT_HISTORY(clientId, agentName);
867
+ });
858
868
  this.getHistory = functoolsKit.memoize(function (_a) {
859
869
  var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
860
870
  return "".concat(clientId, "-").concat(agentName);
861
871
  }, function (clientId, agentName) {
872
+ _this.sessionValidationService.addHistoryUsage(clientId, agentName);
862
873
  return new ClientHistory({
863
874
  clientId: clientId,
864
875
  agentName: agentName,
865
- items: _this.getItems(clientId),
876
+ items: _this.getItems(clientId, agentName),
866
877
  logger: _this.loggerService,
867
878
  });
868
879
  });
@@ -909,11 +920,12 @@ var HistoryConnectionService = /** @class */ (function () {
909
920
  this.loggerService.log("historyConnectionService dispose", {
910
921
  context: this.contextService.context,
911
922
  });
912
- return [4 /*yield*/, this.getItems(this.contextService.context.clientId).clear()];
923
+ return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
913
924
  case 1:
914
925
  _a.sent();
915
926
  this.getItems.clear(this.contextService.context.clientId);
916
927
  this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
928
+ this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
917
929
  return [2 /*return*/];
918
930
  }
919
931
  });
@@ -943,13 +955,13 @@ var ClientSwarm = /** @class */ (function () {
943
955
  function ClientSwarm(params) {
944
956
  var _this = this;
945
957
  this.params = params;
946
- this.waitForOutput = function () { return __awaiter(_this, void 0, void 0, function () {
958
+ this.waitForOutput = functoolsKit.queued(function () { return __awaiter(_this, void 0, void 0, function () {
947
959
  var START_TIME, _a, agentName, output, _b;
948
960
  var _this = this;
949
961
  return __generator(this, function (_c) {
950
962
  switch (_c.label) {
951
963
  case 0:
952
- this.params.logger.debug("BaseConnection waitForOutput");
964
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForOutput"));
953
965
  START_TIME = Date.now();
954
966
  _c.label = 1;
955
967
  case 1:
@@ -982,10 +994,10 @@ var ClientSwarm = /** @class */ (function () {
982
994
  case 4: return [2 /*return*/];
983
995
  }
984
996
  });
985
- }); };
997
+ }); });
986
998
  this.getAgentName = function () { return __awaiter(_this, void 0, void 0, function () {
987
999
  return __generator(this, function (_a) {
988
- this.params.logger.debug("ClientSwarm getAgentName");
1000
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgentName"));
989
1001
  return [2 /*return*/, this._activeAgent];
990
1002
  });
991
1003
  }); };
@@ -994,7 +1006,7 @@ var ClientSwarm = /** @class */ (function () {
994
1006
  return __generator(this, function (_a) {
995
1007
  switch (_a.label) {
996
1008
  case 0:
997
- this.params.logger.debug("ClientSwarm getAgent");
1009
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgent"));
998
1010
  return [4 /*yield*/, this.getAgentName()];
999
1011
  case 1:
1000
1012
  agent = _a.sent();
@@ -1004,11 +1016,12 @@ var ClientSwarm = /** @class */ (function () {
1004
1016
  }); };
1005
1017
  this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
1006
1018
  return __generator(this, function (_a) {
1007
- this.params.logger.debug("ClientSwarm setAgentName agentName=".concat(agentName));
1019
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
1008
1020
  this._activeAgent = agentName;
1009
1021
  return [2 /*return*/];
1010
1022
  });
1011
1023
  }); };
1024
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"));
1012
1025
  this._activeAgent = params.defaultAgent;
1013
1026
  }
1014
1027
  return ClientSwarm;
@@ -1149,30 +1162,48 @@ var ClientSession = /** @class */ (function () {
1149
1162
  function ClientSession(params) {
1150
1163
  var _this = this;
1151
1164
  this.params = params;
1152
- this.execute = function (message) { return __awaiter(_this, void 0, void 0, function () {
1153
- var agent, output;
1154
- return __generator(this, function (_a) {
1155
- switch (_a.label) {
1156
- case 0:
1157
- this.params.logger.debug("BaseSession execute", {
1158
- message: message,
1159
- });
1160
- return [4 /*yield*/, this.params.swarm.getAgent()];
1161
- case 1:
1162
- agent = _a.sent();
1163
- output = this.params.swarm.waitForOutput();
1164
- agent.execute(message);
1165
- return [4 /*yield*/, output];
1166
- case 2: return [2 /*return*/, _a.sent()];
1167
- }
1165
+ this._emitSubject = new functoolsKit.Subject();
1166
+ this.execute = function (message_1) {
1167
+ var args_1 = [];
1168
+ for (var _i = 1; _i < arguments.length; _i++) {
1169
+ args_1[_i - 1] = arguments[_i];
1170
+ }
1171
+ return __awaiter(_this, __spreadArray([message_1], __read(args_1), false), void 0, function (message, noEmit) {
1172
+ var agent, outputAwaiter, output, _a;
1173
+ if (noEmit === void 0) { noEmit = false; }
1174
+ return __generator(this, function (_b) {
1175
+ switch (_b.label) {
1176
+ case 0:
1177
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1178
+ message: message,
1179
+ noEmit: noEmit,
1180
+ });
1181
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1182
+ case 1:
1183
+ agent = _b.sent();
1184
+ outputAwaiter = this.params.swarm.waitForOutput();
1185
+ agent.execute(message);
1186
+ return [4 /*yield*/, outputAwaiter];
1187
+ case 2:
1188
+ output = _b.sent();
1189
+ _a = !noEmit;
1190
+ if (!_a) return [3 /*break*/, 4];
1191
+ return [4 /*yield*/, this._emitSubject.next(output)];
1192
+ case 3:
1193
+ _a = (_b.sent());
1194
+ _b.label = 4;
1195
+ case 4:
1196
+ return [2 /*return*/, output];
1197
+ }
1198
+ });
1168
1199
  });
1169
- }); };
1200
+ };
1170
1201
  this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
1171
1202
  var agent;
1172
1203
  return __generator(this, function (_a) {
1173
1204
  switch (_a.label) {
1174
1205
  case 0:
1175
- this.params.logger.debug("BaseSession commitToolOutput", {
1206
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitToolOutput"), {
1176
1207
  content: content,
1177
1208
  });
1178
1209
  return [4 /*yield*/, this.params.swarm.getAgent()];
@@ -1188,7 +1219,7 @@ var ClientSession = /** @class */ (function () {
1188
1219
  return __generator(this, function (_a) {
1189
1220
  switch (_a.label) {
1190
1221
  case 0:
1191
- this.params.logger.debug("BaseSession commitSystemMessage", {
1222
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitSystemMessage"), {
1192
1223
  message: message,
1193
1224
  });
1194
1225
  return [4 /*yield*/, this.params.swarm.getAgent()];
@@ -1200,17 +1231,35 @@ var ClientSession = /** @class */ (function () {
1200
1231
  });
1201
1232
  }); };
1202
1233
  this.connect = function (connector) {
1203
- _this.params.logger.debug("BaseSession connect");
1234
+ _this.params.logger.debug("ClientSession clientId=".concat(_this.params.clientId, " connect"));
1235
+ _this._emitSubject.subscribe(function (data) { return __awaiter(_this, void 0, void 0, function () {
1236
+ var _a;
1237
+ var _b;
1238
+ return __generator(this, function (_c) {
1239
+ switch (_c.label) {
1240
+ case 0:
1241
+ _a = connector;
1242
+ _b = {
1243
+ data: data
1244
+ };
1245
+ return [4 /*yield*/, this.params.swarm.getAgentName()];
1246
+ case 1: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
1247
+ _b.clientId = this.params.clientId,
1248
+ _b)])];
1249
+ case 2: return [2 /*return*/, _c.sent()];
1250
+ }
1251
+ });
1252
+ }); });
1204
1253
  return function (incoming) { return __awaiter(_this, void 0, void 0, function () {
1205
1254
  var _a;
1206
1255
  var _b;
1207
1256
  return __generator(this, function (_c) {
1208
1257
  switch (_c.label) {
1209
1258
  case 0:
1210
- this.params.logger.debug("BaseSession connect call");
1259
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1211
1260
  _a = connector;
1212
1261
  _b = {};
1213
- return [4 /*yield*/, this.execute(incoming.data)];
1262
+ return [4 /*yield*/, this.execute(incoming.data, true)];
1214
1263
  case 1:
1215
1264
  _b.data = _c.sent();
1216
1265
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1224,6 +1273,7 @@ var ClientSession = /** @class */ (function () {
1224
1273
  });
1225
1274
  }); };
1226
1275
  };
1276
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR"));
1227
1277
  }
1228
1278
  return ClientSession;
1229
1279
  }());
@@ -1908,25 +1958,109 @@ var SessionValidationService = /** @class */ (function () {
1908
1958
  function SessionValidationService() {
1909
1959
  var _this = this;
1910
1960
  this.loggerService = inject(TYPES.loggerService);
1911
- this._sessionMap = new Map();
1961
+ this._historySwarmMap = new Map();
1962
+ this._sessionSwarmMap = new Map();
1963
+ this._agentSwarmMap = new Map();
1912
1964
  this.addSession = function (clientId, swarmName) {
1913
1965
  _this.loggerService.log("sessionValidationService addSession", {
1914
1966
  clientId: clientId,
1915
1967
  });
1916
- if (_this._sessionMap.has(clientId)) {
1968
+ if (_this._sessionSwarmMap.has(clientId)) {
1917
1969
  throw new Error("agent-swarm session clientId=".concat(clientId, " already exist"));
1918
1970
  }
1919
- _this._sessionMap.set(clientId, swarmName);
1971
+ _this._sessionSwarmMap.set(clientId, swarmName);
1972
+ };
1973
+ this.addAgentUsage = function (sessionId, agentName) {
1974
+ _this.loggerService.log("sessionValidationService addAgentUsage", {
1975
+ sessionId: sessionId,
1976
+ agentName: agentName,
1977
+ });
1978
+ if (_this._agentSwarmMap.has(sessionId)) {
1979
+ var agents = _this._agentSwarmMap.get(sessionId);
1980
+ if (!agents.includes(agentName)) {
1981
+ agents.push(agentName);
1982
+ }
1983
+ }
1984
+ else {
1985
+ _this._agentSwarmMap.set(sessionId, [agentName]);
1986
+ }
1987
+ };
1988
+ this.addHistoryUsage = function (sessionId, agentName) {
1989
+ _this.loggerService.log("sessionValidationService addHistoryUsage", {
1990
+ sessionId: sessionId,
1991
+ agentName: agentName,
1992
+ });
1993
+ if (_this._historySwarmMap.has(sessionId)) {
1994
+ var agents = _this._historySwarmMap.get(sessionId);
1995
+ if (!agents.includes(agentName)) {
1996
+ agents.push(agentName);
1997
+ }
1998
+ }
1999
+ else {
2000
+ _this._historySwarmMap.set(sessionId, [agentName]);
2001
+ }
2002
+ };
2003
+ this.removeAgentUsage = function (sessionId, agentName) {
2004
+ _this.loggerService.log("sessionValidationService removeAgentUsage", {
2005
+ sessionId: sessionId,
2006
+ agentName: agentName,
2007
+ });
2008
+ if (_this._agentSwarmMap.has(sessionId)) {
2009
+ var agents = _this._agentSwarmMap.get(sessionId);
2010
+ var agentIndex = agents.indexOf(agentName);
2011
+ if (agentIndex !== -1) {
2012
+ agents.splice(agentIndex, 1);
2013
+ }
2014
+ if (agents.length === 0) {
2015
+ _this._agentSwarmMap.delete(sessionId);
2016
+ }
2017
+ }
2018
+ else {
2019
+ throw new Error("No agents found for sessionId=".concat(sessionId));
2020
+ }
2021
+ };
2022
+ this.removeHistoryUsage = function (sessionId, agentName) {
2023
+ _this.loggerService.log("sessionValidationService removeHistoryUsage", {
2024
+ sessionId: sessionId,
2025
+ agentName: agentName,
2026
+ });
2027
+ if (_this._historySwarmMap.has(sessionId)) {
2028
+ var agents = _this._historySwarmMap.get(sessionId);
2029
+ var agentIndex = agents.indexOf(agentName);
2030
+ if (agentIndex !== -1) {
2031
+ agents.splice(agentIndex, 1);
2032
+ }
2033
+ if (agents.length === 0) {
2034
+ _this._historySwarmMap.delete(sessionId);
2035
+ }
2036
+ }
2037
+ else {
2038
+ throw new Error("No agents found for sessionId=".concat(sessionId));
2039
+ }
1920
2040
  };
1921
2041
  this.getSessionList = function () {
1922
2042
  _this.loggerService.log("sessionValidationService getSessionList");
1923
- return __spreadArray([], __read(_this._sessionMap.keys()), false);
2043
+ return __spreadArray([], __read(_this._sessionSwarmMap.keys()), false);
2044
+ };
2045
+ this.getSessionAgentList = function (clientId) {
2046
+ var _a;
2047
+ _this.loggerService.log("sessionValidationService getSessionAgentList", {
2048
+ clientId: clientId,
2049
+ });
2050
+ return (_a = _this._agentSwarmMap.get(clientId)) !== null && _a !== void 0 ? _a : [];
2051
+ };
2052
+ this.getSessionHistoryList = function (clientId) {
2053
+ var _a;
2054
+ _this.loggerService.log("sessionValidationService getSessionHistoryList", {
2055
+ clientId: clientId,
2056
+ });
2057
+ return (_a = _this._agentSwarmMap.get(clientId)) !== null && _a !== void 0 ? _a : [];
1924
2058
  };
1925
2059
  this.getSwarm = function (clientId) {
1926
2060
  _this.loggerService.log("sessionValidationService getSwarm", {
1927
2061
  clientId: clientId,
1928
2062
  });
1929
- var session = _this._sessionMap.get(clientId);
2063
+ var session = _this._sessionSwarmMap.get(clientId);
1930
2064
  if (session === undefined) {
1931
2065
  throw new Error("agent-swarm session clientId=".concat(clientId, " not found"));
1932
2066
  }
@@ -1934,7 +2068,7 @@ var SessionValidationService = /** @class */ (function () {
1934
2068
  };
1935
2069
  this.validate = function (clientId, source) {
1936
2070
  _this.loggerService.log("sessionValidationService validate", { clientId: clientId });
1937
- if (!_this._sessionMap.has(clientId)) {
2071
+ if (!_this._sessionSwarmMap.has(clientId)) {
1938
2072
  throw new Error("agent-swarm session clientId=".concat(clientId, " not exist source=").concat(source));
1939
2073
  }
1940
2074
  };
@@ -1942,7 +2076,7 @@ var SessionValidationService = /** @class */ (function () {
1942
2076
  _this.loggerService.log("sessionValidationService addSession", {
1943
2077
  clientId: clientId,
1944
2078
  });
1945
- _this._sessionMap.delete(clientId);
2079
+ _this._sessionSwarmMap.delete(clientId);
1946
2080
  };
1947
2081
  }
1948
2082
  return SessionValidationService;
@@ -2125,12 +2259,21 @@ var makeConnection = function (connector, clientId, swarmName) {
2125
2259
  swarm.sessionValidationService.addSession(clientId, swarmName);
2126
2260
  var send = swarm.sessionPublicService.connect(connector, clientId, swarmName);
2127
2261
  return functoolsKit.queued(function (outgoing) { return __awaiter(void 0, void 0, void 0, function () {
2128
- return __generator(this, function (_a) {
2129
- switch (_a.label) {
2262
+ var _a;
2263
+ var _b;
2264
+ return __generator(this, function (_c) {
2265
+ switch (_c.label) {
2130
2266
  case 0:
2131
2267
  swarm.sessionValidationService.validate(clientId, "makeConnection");
2132
- return [4 /*yield*/, send(outgoing)];
2133
- case 1: return [2 /*return*/, _a.sent()];
2268
+ _a = send;
2269
+ _b = {
2270
+ data: outgoing
2271
+ };
2272
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
2273
+ case 1: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
2274
+ _b.clientId = clientId,
2275
+ _b)])];
2276
+ case 2: return [2 /*return*/, _c.sent()];
2134
2277
  }
2135
2278
  });
2136
2279
  }); });
package/build/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { scoped } from 'di-scoped';
2
- import { ToolRegistry, Subject, queued, not, trycatch, memoize, PubsubArrayAdapter, ttl, singleshot } from 'functools-kit';
2
+ import { ToolRegistry, PubsubArrayAdapter, Subject, queued, not, trycatch, memoize, ttl, singleshot } from 'functools-kit';
3
3
  import { createActivator } from 'di-kit';
4
4
  import { omit } from 'lodash-es';
5
5
  import xml2js from 'xml2js';
@@ -233,11 +233,13 @@ var CC_EMPTY_OUTPUT_PLACEHOLDERS = [
233
233
  ];
234
234
  var CC_KEEP_MESSAGES = 5;
235
235
  var CC_ANSWER_TIMEOUT_SECONDS = 120000;
236
+ var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
236
237
  var GLOBAL_CONFIG = {
237
238
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
238
239
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
239
240
  CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
240
241
  CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
242
+ CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
241
243
  };
242
244
  var setConfig = function (config) {
243
245
  Object.assign(GLOBAL_CONFIG, config);
@@ -257,7 +259,7 @@ var ClientAgent = /** @class */ (function () {
257
259
  return __generator(this, function (_a) {
258
260
  switch (_a.label) {
259
261
  case 0:
260
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _emitOuput"));
262
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"));
261
263
  validation = null;
262
264
  return [4 /*yield*/, this.params.validate(result)];
263
265
  case 1:
@@ -268,7 +270,7 @@ var ClientAgent = /** @class */ (function () {
268
270
  return [4 /*yield*/, this.params.validate(result_1)];
269
271
  case 3:
270
272
  if (validation = _a.sent()) {
271
- throw new Error("agent-swarm-kit ClientAgent agentName=".concat(this.params.agentName, " model ressurect failed: ").concat(validation));
273
+ throw new Error("agent-swarm-kit ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " model ressurect failed: ").concat(validation));
272
274
  }
273
275
  return [4 /*yield*/, this._outputSubject.next(result_1)];
274
276
  case 4:
@@ -286,7 +288,7 @@ var ClientAgent = /** @class */ (function () {
286
288
  return __generator(this, function (_a) {
287
289
  switch (_a.label) {
288
290
  case 0:
289
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _resurrectModel"));
291
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
290
292
  return [4 /*yield*/, this.params.history.push({
291
293
  role: "resque",
292
294
  agentName: this.params.agentName,
@@ -309,7 +311,7 @@ var ClientAgent = /** @class */ (function () {
309
311
  return [4 /*yield*/, this.params.validate(result)];
310
312
  case 4:
311
313
  if (!(validation = _a.sent())) return [3 /*break*/, 6];
312
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " _resurrectModel validation error: ").concat(validation));
314
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
313
315
  content = getPlaceholder();
314
316
  return [4 /*yield*/, this.params.history.push({
315
317
  agentName: this.params.agentName,
@@ -330,7 +332,7 @@ var ClientAgent = /** @class */ (function () {
330
332
  return __generator(this, function (_a) {
331
333
  switch (_a.label) {
332
334
  case 0:
333
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " waitForOutput"));
335
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " waitForOutput"));
334
336
  return [4 /*yield*/, this._outputSubject.toPromise()];
335
337
  case 1: return [2 /*return*/, _a.sent()];
336
338
  }
@@ -342,7 +344,7 @@ var ClientAgent = /** @class */ (function () {
342
344
  return __generator(this, function (_b) {
343
345
  switch (_b.label) {
344
346
  case 0:
345
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " getCompletion"));
347
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " getCompletion"));
346
348
  return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt)];
347
349
  case 1:
348
350
  messages = _b.sent();
@@ -360,7 +362,7 @@ var ClientAgent = /** @class */ (function () {
360
362
  return __generator(this, function (_a) {
361
363
  switch (_a.label) {
362
364
  case 0:
363
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " commitSystemMessage"));
365
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"));
364
366
  return [4 /*yield*/, this.params.history.push({
365
367
  role: "system",
366
368
  agentName: this.params.agentName,
@@ -376,7 +378,7 @@ var ClientAgent = /** @class */ (function () {
376
378
  return __generator(this, function (_a) {
377
379
  switch (_a.label) {
378
380
  case 0:
379
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " commitToolOutput content=").concat(content));
381
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput content=").concat(content));
380
382
  return [4 /*yield*/, this.params.history.push({
381
383
  role: "tool",
382
384
  agentName: this.params.agentName,
@@ -398,7 +400,7 @@ var ClientAgent = /** @class */ (function () {
398
400
  return __generator(this, function (_e) {
399
401
  switch (_e.label) {
400
402
  case 0:
401
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute begin"), { incoming: incoming });
403
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming });
402
404
  return [4 /*yield*/, this.params.history.push({
403
405
  role: "user",
404
406
  agentName: this.params.agentName,
@@ -410,7 +412,7 @@ var ClientAgent = /** @class */ (function () {
410
412
  case 2:
411
413
  message = _e.sent();
412
414
  if (!message.tool_calls) return [3 /*break*/, 11];
413
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " tool call begin"));
415
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
414
416
  _loop_1 = function (tool) {
415
417
  var targetFn, result_2, result_3;
416
418
  return __generator(this, function (_f) {
@@ -421,11 +423,11 @@ var ClientAgent = /** @class */ (function () {
421
423
  case 1:
422
424
  _f.sent();
423
425
  if (!!targetFn) return [3 /*break*/, 4];
424
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool function not found"));
426
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"));
425
427
  return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
426
428
  case 2:
427
429
  result_2 = _f.sent();
428
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " execute end result=").concat(result_2));
430
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
429
431
  return [4 /*yield*/, this_1._emitOuput(result_2)];
430
432
  case 3:
431
433
  _f.sent();
@@ -433,11 +435,11 @@ var ClientAgent = /** @class */ (function () {
433
435
  case 4: return [4 /*yield*/, not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
434
436
  case 5:
435
437
  if (!_f.sent()) return [3 /*break*/, 8];
436
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool validation not passed"));
438
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
437
439
  return [4 /*yield*/, this_1._resurrectModel("Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
438
440
  case 6:
439
441
  result_3 = _f.sent();
440
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " execute end result=").concat(result_3));
442
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
441
443
  return [4 /*yield*/, this_1._emitOuput(result_3)];
442
444
  case 7:
443
445
  _f.sent();
@@ -447,14 +449,14 @@ var ClientAgent = /** @class */ (function () {
447
449
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
448
450
  */
449
451
  targetFn.call(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
450
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool call executing"));
452
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
451
453
  return [4 /*yield*/, Promise.race([
452
454
  this_1._toolCommitSubject.toPromise(),
453
455
  this_1._outputSubject.toPromise(),
454
456
  ])];
455
457
  case 9:
456
458
  _f.sent();
457
- this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " functionName=").concat(tool.function.name, " tool call end"));
459
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
458
460
  return [2 /*return*/];
459
461
  }
460
462
  });
@@ -491,7 +493,7 @@ var ClientAgent = /** @class */ (function () {
491
493
  case 10: return [2 /*return*/];
492
494
  case 11:
493
495
  if (!message.tool_calls) {
494
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute no tool calls detected"));
496
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute no tool calls detected"));
495
497
  }
496
498
  result = message.content;
497
499
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
@@ -501,7 +503,7 @@ var ClientAgent = /** @class */ (function () {
501
503
  return [4 /*yield*/, this.params.validate(result)];
502
504
  case 13:
503
505
  if (!(validation = _e.sent())) return [3 /*break*/, 16];
504
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute invalid tool call detected: ").concat(validation), { result: result });
506
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
505
507
  return [4 /*yield*/, this._resurrectModel("Invalid model output: ".concat(result))];
506
508
  case 14:
507
509
  result1 = _e.sent();
@@ -510,7 +512,7 @@ var ClientAgent = /** @class */ (function () {
510
512
  _e.sent();
511
513
  return [2 /*return*/];
512
514
  case 16:
513
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " execute end result=").concat(result));
515
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
514
516
  return [4 /*yield*/, this._emitOuput(result)];
515
517
  case 17:
516
518
  _e.sent();
@@ -518,6 +520,7 @@ var ClientAgent = /** @class */ (function () {
518
520
  }
519
521
  });
520
522
  }); });
523
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"));
521
524
  }
522
525
  return ClientAgent;
523
526
  }());
@@ -613,6 +616,7 @@ var AgentConnectionService = /** @class */ (function () {
613
616
  var _this = this;
614
617
  this.loggerService = inject(TYPES.loggerService);
615
618
  this.contextService = inject(TYPES.contextService);
619
+ this.sessionValidationService = inject(TYPES.sessionValidationService);
616
620
  this.historyConnectionService = inject(TYPES.historyConnectionService);
617
621
  this.agentSchemaService = inject(TYPES.agentSchemaService);
618
622
  this.toolSchemaService = inject(TYPES.toolSchemaService);
@@ -623,6 +627,7 @@ var AgentConnectionService = /** @class */ (function () {
623
627
  }, function (clientId, agentName) {
624
628
  var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, tools = _a.tools, completionName = _a.completion, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
625
629
  var completion = _this.completionSchemaService.get(completionName);
630
+ _this.sessionValidationService.addAgentUsage(clientId, agentName);
626
631
  return new ClientAgent({
627
632
  clientId: clientId,
628
633
  agentName: agentName,
@@ -691,6 +696,7 @@ var AgentConnectionService = /** @class */ (function () {
691
696
  context: this.contextService.context,
692
697
  });
693
698
  this.getAgent.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
699
+ this.sessionValidationService.removeAgentUsage(this.contextService.context.clientId, this.contextService.context.agentName);
694
700
  return [2 /*return*/];
695
701
  });
696
702
  }); };
@@ -840,6 +846,7 @@ var ClientHistory = /** @class */ (function () {
840
846
  }
841
847
  });
842
848
  }); };
849
+ this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"));
843
850
  }
844
851
  return ClientHistory;
845
852
  }());
@@ -849,18 +856,22 @@ var HistoryConnectionService = /** @class */ (function () {
849
856
  var _this = this;
850
857
  this.loggerService = inject(TYPES.loggerService);
851
858
  this.contextService = inject(TYPES.contextService);
859
+ this.sessionValidationService = inject(TYPES.sessionValidationService);
852
860
  this.getItems = memoize(function (_a) {
853
861
  var _b = __read(_a, 1), clientId = _b[0];
854
862
  return clientId;
855
- }, function () { return new PubsubArrayAdapter(); });
863
+ }, function (clientId, agentName) {
864
+ return GLOBAL_CONFIG.CC_GET_AGENT_HISTORY(clientId, agentName);
865
+ });
856
866
  this.getHistory = memoize(function (_a) {
857
867
  var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
858
868
  return "".concat(clientId, "-").concat(agentName);
859
869
  }, function (clientId, agentName) {
870
+ _this.sessionValidationService.addHistoryUsage(clientId, agentName);
860
871
  return new ClientHistory({
861
872
  clientId: clientId,
862
873
  agentName: agentName,
863
- items: _this.getItems(clientId),
874
+ items: _this.getItems(clientId, agentName),
864
875
  logger: _this.loggerService,
865
876
  });
866
877
  });
@@ -907,11 +918,12 @@ var HistoryConnectionService = /** @class */ (function () {
907
918
  this.loggerService.log("historyConnectionService dispose", {
908
919
  context: this.contextService.context,
909
920
  });
910
- return [4 /*yield*/, this.getItems(this.contextService.context.clientId).clear()];
921
+ return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
911
922
  case 1:
912
923
  _a.sent();
913
924
  this.getItems.clear(this.contextService.context.clientId);
914
925
  this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
926
+ this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
915
927
  return [2 /*return*/];
916
928
  }
917
929
  });
@@ -941,13 +953,13 @@ var ClientSwarm = /** @class */ (function () {
941
953
  function ClientSwarm(params) {
942
954
  var _this = this;
943
955
  this.params = params;
944
- this.waitForOutput = function () { return __awaiter(_this, void 0, void 0, function () {
956
+ this.waitForOutput = queued(function () { return __awaiter(_this, void 0, void 0, function () {
945
957
  var START_TIME, _a, agentName, output, _b;
946
958
  var _this = this;
947
959
  return __generator(this, function (_c) {
948
960
  switch (_c.label) {
949
961
  case 0:
950
- this.params.logger.debug("BaseConnection waitForOutput");
962
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForOutput"));
951
963
  START_TIME = Date.now();
952
964
  _c.label = 1;
953
965
  case 1:
@@ -980,10 +992,10 @@ var ClientSwarm = /** @class */ (function () {
980
992
  case 4: return [2 /*return*/];
981
993
  }
982
994
  });
983
- }); };
995
+ }); });
984
996
  this.getAgentName = function () { return __awaiter(_this, void 0, void 0, function () {
985
997
  return __generator(this, function (_a) {
986
- this.params.logger.debug("ClientSwarm getAgentName");
998
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgentName"));
987
999
  return [2 /*return*/, this._activeAgent];
988
1000
  });
989
1001
  }); };
@@ -992,7 +1004,7 @@ var ClientSwarm = /** @class */ (function () {
992
1004
  return __generator(this, function (_a) {
993
1005
  switch (_a.label) {
994
1006
  case 0:
995
- this.params.logger.debug("ClientSwarm getAgent");
1007
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgent"));
996
1008
  return [4 /*yield*/, this.getAgentName()];
997
1009
  case 1:
998
1010
  agent = _a.sent();
@@ -1002,11 +1014,12 @@ var ClientSwarm = /** @class */ (function () {
1002
1014
  }); };
1003
1015
  this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
1004
1016
  return __generator(this, function (_a) {
1005
- this.params.logger.debug("ClientSwarm setAgentName agentName=".concat(agentName));
1017
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
1006
1018
  this._activeAgent = agentName;
1007
1019
  return [2 /*return*/];
1008
1020
  });
1009
1021
  }); };
1022
+ this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"));
1010
1023
  this._activeAgent = params.defaultAgent;
1011
1024
  }
1012
1025
  return ClientSwarm;
@@ -1147,30 +1160,48 @@ var ClientSession = /** @class */ (function () {
1147
1160
  function ClientSession(params) {
1148
1161
  var _this = this;
1149
1162
  this.params = params;
1150
- this.execute = function (message) { return __awaiter(_this, void 0, void 0, function () {
1151
- var agent, output;
1152
- return __generator(this, function (_a) {
1153
- switch (_a.label) {
1154
- case 0:
1155
- this.params.logger.debug("BaseSession execute", {
1156
- message: message,
1157
- });
1158
- return [4 /*yield*/, this.params.swarm.getAgent()];
1159
- case 1:
1160
- agent = _a.sent();
1161
- output = this.params.swarm.waitForOutput();
1162
- agent.execute(message);
1163
- return [4 /*yield*/, output];
1164
- case 2: return [2 /*return*/, _a.sent()];
1165
- }
1163
+ this._emitSubject = new Subject();
1164
+ this.execute = function (message_1) {
1165
+ var args_1 = [];
1166
+ for (var _i = 1; _i < arguments.length; _i++) {
1167
+ args_1[_i - 1] = arguments[_i];
1168
+ }
1169
+ return __awaiter(_this, __spreadArray([message_1], __read(args_1), false), void 0, function (message, noEmit) {
1170
+ var agent, outputAwaiter, output, _a;
1171
+ if (noEmit === void 0) { noEmit = false; }
1172
+ return __generator(this, function (_b) {
1173
+ switch (_b.label) {
1174
+ case 0:
1175
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1176
+ message: message,
1177
+ noEmit: noEmit,
1178
+ });
1179
+ return [4 /*yield*/, this.params.swarm.getAgent()];
1180
+ case 1:
1181
+ agent = _b.sent();
1182
+ outputAwaiter = this.params.swarm.waitForOutput();
1183
+ agent.execute(message);
1184
+ return [4 /*yield*/, outputAwaiter];
1185
+ case 2:
1186
+ output = _b.sent();
1187
+ _a = !noEmit;
1188
+ if (!_a) return [3 /*break*/, 4];
1189
+ return [4 /*yield*/, this._emitSubject.next(output)];
1190
+ case 3:
1191
+ _a = (_b.sent());
1192
+ _b.label = 4;
1193
+ case 4:
1194
+ return [2 /*return*/, output];
1195
+ }
1196
+ });
1166
1197
  });
1167
- }); };
1198
+ };
1168
1199
  this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
1169
1200
  var agent;
1170
1201
  return __generator(this, function (_a) {
1171
1202
  switch (_a.label) {
1172
1203
  case 0:
1173
- this.params.logger.debug("BaseSession commitToolOutput", {
1204
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitToolOutput"), {
1174
1205
  content: content,
1175
1206
  });
1176
1207
  return [4 /*yield*/, this.params.swarm.getAgent()];
@@ -1186,7 +1217,7 @@ var ClientSession = /** @class */ (function () {
1186
1217
  return __generator(this, function (_a) {
1187
1218
  switch (_a.label) {
1188
1219
  case 0:
1189
- this.params.logger.debug("BaseSession commitSystemMessage", {
1220
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitSystemMessage"), {
1190
1221
  message: message,
1191
1222
  });
1192
1223
  return [4 /*yield*/, this.params.swarm.getAgent()];
@@ -1198,17 +1229,35 @@ var ClientSession = /** @class */ (function () {
1198
1229
  });
1199
1230
  }); };
1200
1231
  this.connect = function (connector) {
1201
- _this.params.logger.debug("BaseSession connect");
1232
+ _this.params.logger.debug("ClientSession clientId=".concat(_this.params.clientId, " connect"));
1233
+ _this._emitSubject.subscribe(function (data) { return __awaiter(_this, void 0, void 0, function () {
1234
+ var _a;
1235
+ var _b;
1236
+ return __generator(this, function (_c) {
1237
+ switch (_c.label) {
1238
+ case 0:
1239
+ _a = connector;
1240
+ _b = {
1241
+ data: data
1242
+ };
1243
+ return [4 /*yield*/, this.params.swarm.getAgentName()];
1244
+ case 1: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
1245
+ _b.clientId = this.params.clientId,
1246
+ _b)])];
1247
+ case 2: return [2 /*return*/, _c.sent()];
1248
+ }
1249
+ });
1250
+ }); });
1202
1251
  return function (incoming) { return __awaiter(_this, void 0, void 0, function () {
1203
1252
  var _a;
1204
1253
  var _b;
1205
1254
  return __generator(this, function (_c) {
1206
1255
  switch (_c.label) {
1207
1256
  case 0:
1208
- this.params.logger.debug("BaseSession connect call");
1257
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1209
1258
  _a = connector;
1210
1259
  _b = {};
1211
- return [4 /*yield*/, this.execute(incoming.data)];
1260
+ return [4 /*yield*/, this.execute(incoming.data, true)];
1212
1261
  case 1:
1213
1262
  _b.data = _c.sent();
1214
1263
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1222,6 +1271,7 @@ var ClientSession = /** @class */ (function () {
1222
1271
  });
1223
1272
  }); };
1224
1273
  };
1274
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR"));
1225
1275
  }
1226
1276
  return ClientSession;
1227
1277
  }());
@@ -1906,25 +1956,109 @@ var SessionValidationService = /** @class */ (function () {
1906
1956
  function SessionValidationService() {
1907
1957
  var _this = this;
1908
1958
  this.loggerService = inject(TYPES.loggerService);
1909
- this._sessionMap = new Map();
1959
+ this._historySwarmMap = new Map();
1960
+ this._sessionSwarmMap = new Map();
1961
+ this._agentSwarmMap = new Map();
1910
1962
  this.addSession = function (clientId, swarmName) {
1911
1963
  _this.loggerService.log("sessionValidationService addSession", {
1912
1964
  clientId: clientId,
1913
1965
  });
1914
- if (_this._sessionMap.has(clientId)) {
1966
+ if (_this._sessionSwarmMap.has(clientId)) {
1915
1967
  throw new Error("agent-swarm session clientId=".concat(clientId, " already exist"));
1916
1968
  }
1917
- _this._sessionMap.set(clientId, swarmName);
1969
+ _this._sessionSwarmMap.set(clientId, swarmName);
1970
+ };
1971
+ this.addAgentUsage = function (sessionId, agentName) {
1972
+ _this.loggerService.log("sessionValidationService addAgentUsage", {
1973
+ sessionId: sessionId,
1974
+ agentName: agentName,
1975
+ });
1976
+ if (_this._agentSwarmMap.has(sessionId)) {
1977
+ var agents = _this._agentSwarmMap.get(sessionId);
1978
+ if (!agents.includes(agentName)) {
1979
+ agents.push(agentName);
1980
+ }
1981
+ }
1982
+ else {
1983
+ _this._agentSwarmMap.set(sessionId, [agentName]);
1984
+ }
1985
+ };
1986
+ this.addHistoryUsage = function (sessionId, agentName) {
1987
+ _this.loggerService.log("sessionValidationService addHistoryUsage", {
1988
+ sessionId: sessionId,
1989
+ agentName: agentName,
1990
+ });
1991
+ if (_this._historySwarmMap.has(sessionId)) {
1992
+ var agents = _this._historySwarmMap.get(sessionId);
1993
+ if (!agents.includes(agentName)) {
1994
+ agents.push(agentName);
1995
+ }
1996
+ }
1997
+ else {
1998
+ _this._historySwarmMap.set(sessionId, [agentName]);
1999
+ }
2000
+ };
2001
+ this.removeAgentUsage = function (sessionId, agentName) {
2002
+ _this.loggerService.log("sessionValidationService removeAgentUsage", {
2003
+ sessionId: sessionId,
2004
+ agentName: agentName,
2005
+ });
2006
+ if (_this._agentSwarmMap.has(sessionId)) {
2007
+ var agents = _this._agentSwarmMap.get(sessionId);
2008
+ var agentIndex = agents.indexOf(agentName);
2009
+ if (agentIndex !== -1) {
2010
+ agents.splice(agentIndex, 1);
2011
+ }
2012
+ if (agents.length === 0) {
2013
+ _this._agentSwarmMap.delete(sessionId);
2014
+ }
2015
+ }
2016
+ else {
2017
+ throw new Error("No agents found for sessionId=".concat(sessionId));
2018
+ }
2019
+ };
2020
+ this.removeHistoryUsage = function (sessionId, agentName) {
2021
+ _this.loggerService.log("sessionValidationService removeHistoryUsage", {
2022
+ sessionId: sessionId,
2023
+ agentName: agentName,
2024
+ });
2025
+ if (_this._historySwarmMap.has(sessionId)) {
2026
+ var agents = _this._historySwarmMap.get(sessionId);
2027
+ var agentIndex = agents.indexOf(agentName);
2028
+ if (agentIndex !== -1) {
2029
+ agents.splice(agentIndex, 1);
2030
+ }
2031
+ if (agents.length === 0) {
2032
+ _this._historySwarmMap.delete(sessionId);
2033
+ }
2034
+ }
2035
+ else {
2036
+ throw new Error("No agents found for sessionId=".concat(sessionId));
2037
+ }
1918
2038
  };
1919
2039
  this.getSessionList = function () {
1920
2040
  _this.loggerService.log("sessionValidationService getSessionList");
1921
- return __spreadArray([], __read(_this._sessionMap.keys()), false);
2041
+ return __spreadArray([], __read(_this._sessionSwarmMap.keys()), false);
2042
+ };
2043
+ this.getSessionAgentList = function (clientId) {
2044
+ var _a;
2045
+ _this.loggerService.log("sessionValidationService getSessionAgentList", {
2046
+ clientId: clientId,
2047
+ });
2048
+ return (_a = _this._agentSwarmMap.get(clientId)) !== null && _a !== void 0 ? _a : [];
2049
+ };
2050
+ this.getSessionHistoryList = function (clientId) {
2051
+ var _a;
2052
+ _this.loggerService.log("sessionValidationService getSessionHistoryList", {
2053
+ clientId: clientId,
2054
+ });
2055
+ return (_a = _this._agentSwarmMap.get(clientId)) !== null && _a !== void 0 ? _a : [];
1922
2056
  };
1923
2057
  this.getSwarm = function (clientId) {
1924
2058
  _this.loggerService.log("sessionValidationService getSwarm", {
1925
2059
  clientId: clientId,
1926
2060
  });
1927
- var session = _this._sessionMap.get(clientId);
2061
+ var session = _this._sessionSwarmMap.get(clientId);
1928
2062
  if (session === undefined) {
1929
2063
  throw new Error("agent-swarm session clientId=".concat(clientId, " not found"));
1930
2064
  }
@@ -1932,7 +2066,7 @@ var SessionValidationService = /** @class */ (function () {
1932
2066
  };
1933
2067
  this.validate = function (clientId, source) {
1934
2068
  _this.loggerService.log("sessionValidationService validate", { clientId: clientId });
1935
- if (!_this._sessionMap.has(clientId)) {
2069
+ if (!_this._sessionSwarmMap.has(clientId)) {
1936
2070
  throw new Error("agent-swarm session clientId=".concat(clientId, " not exist source=").concat(source));
1937
2071
  }
1938
2072
  };
@@ -1940,7 +2074,7 @@ var SessionValidationService = /** @class */ (function () {
1940
2074
  _this.loggerService.log("sessionValidationService addSession", {
1941
2075
  clientId: clientId,
1942
2076
  });
1943
- _this._sessionMap.delete(clientId);
2077
+ _this._sessionSwarmMap.delete(clientId);
1944
2078
  };
1945
2079
  }
1946
2080
  return SessionValidationService;
@@ -2123,12 +2257,21 @@ var makeConnection = function (connector, clientId, swarmName) {
2123
2257
  swarm.sessionValidationService.addSession(clientId, swarmName);
2124
2258
  var send = swarm.sessionPublicService.connect(connector, clientId, swarmName);
2125
2259
  return queued(function (outgoing) { return __awaiter(void 0, void 0, void 0, function () {
2126
- return __generator(this, function (_a) {
2127
- switch (_a.label) {
2260
+ var _a;
2261
+ var _b;
2262
+ return __generator(this, function (_c) {
2263
+ switch (_c.label) {
2128
2264
  case 0:
2129
2265
  swarm.sessionValidationService.validate(clientId, "makeConnection");
2130
- return [4 /*yield*/, send(outgoing)];
2131
- case 1: return [2 /*return*/, _a.sent()];
2266
+ _a = send;
2267
+ _b = {
2268
+ data: outgoing
2269
+ };
2270
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
2271
+ case 1: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
2272
+ _b.clientId = clientId,
2273
+ _b)])];
2274
+ case 2: return [2 /*return*/, _c.sent()];
2132
2275
  }
2133
2276
  });
2134
2277
  }); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -40,7 +40,7 @@
40
40
  "build": "rollup -c",
41
41
  "test": "npm run build && node ./test/index.mjs",
42
42
  "build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
43
- "docs:gpt": "node ./scripts/gpt-docs.mjs",
43
+ "docs:gpt": "npm run build && node ./scripts/gpt-docs.mjs",
44
44
  "repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
45
45
  },
46
46
  "main": "build/index.cjs",
package/types.d.ts CHANGED
@@ -158,6 +158,7 @@ declare class ClientAgent implements IAgent {
158
158
  declare class AgentConnectionService implements IAgent {
159
159
  private readonly loggerService;
160
160
  private readonly contextService;
161
+ private readonly sessionValidationService;
161
162
  private readonly historyConnectionService;
162
163
  private readonly agentSchemaService;
163
164
  private readonly toolSchemaService;
@@ -181,7 +182,8 @@ declare class ClientHistory implements IHistory {
181
182
  declare class HistoryConnectionService implements IHistory {
182
183
  private readonly loggerService;
183
184
  private readonly contextService;
184
- getItems: ((clientId: string) => IPubsubArray<IModelMessage>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, IPubsubArray<IModelMessage>>;
185
+ private readonly sessionValidationService;
186
+ getItems: ((clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, IPubsubArray<IModelMessage>>;
185
187
  getHistory: ((clientId: string, agentName: string) => ClientHistory) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientHistory>;
186
188
  push: (message: IModelMessage) => Promise<void>;
187
189
  toArrayForAgent: (prompt: string) => Promise<IModelMessage[]>;
@@ -258,11 +260,11 @@ interface ISessionParams extends ISessionSchema {
258
260
  }
259
261
  interface ISessionSchema {
260
262
  }
261
- type SendMessageFn = (outgoing: IOutgoingMessage) => Promise<void> | void;
263
+ type SendMessageFn$1 = (outgoing: IOutgoingMessage) => Promise<void> | void;
262
264
  type ReceiveMessageFn = (incoming: IIncomingMessage) => Promise<void> | void;
263
265
  interface ISession {
264
266
  execute(content: string): Promise<string>;
265
- connect(connector: SendMessageFn): ReceiveMessageFn;
267
+ connect(connector: SendMessageFn$1): ReceiveMessageFn;
266
268
  commitToolOutput(content: string): Promise<void>;
267
269
  commitSystemMessage(message: string): Promise<void>;
268
270
  }
@@ -270,11 +272,12 @@ type SessionId = string;
270
272
 
271
273
  declare class ClientSession implements ISession {
272
274
  readonly params: ISessionParams;
275
+ readonly _emitSubject: Subject<string>;
273
276
  constructor(params: ISessionParams);
274
- execute: (message: string) => Promise<string>;
277
+ execute: (message: string, noEmit?: boolean) => Promise<string>;
275
278
  commitToolOutput: (content: string) => Promise<void>;
276
279
  commitSystemMessage: (message: string) => Promise<void>;
277
- connect: (connector: SendMessageFn) => ReceiveMessageFn;
280
+ connect: (connector: SendMessageFn$1) => ReceiveMessageFn;
278
281
  }
279
282
 
280
283
  declare class SessionConnectionService implements ISession {
@@ -283,7 +286,7 @@ declare class SessionConnectionService implements ISession {
283
286
  private readonly swarmConnectionService;
284
287
  getSession: ((clientId: string, swarmName: string) => ClientSession) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientSession>;
285
288
  execute: (content: string) => Promise<string>;
286
- connect: (connector: SendMessageFn) => ReceiveMessageFn;
289
+ connect: (connector: SendMessageFn$1) => ReceiveMessageFn;
287
290
  commitToolOutput: (content: string) => Promise<void>;
288
291
  commitSystemMessage: (message: string) => Promise<void>;
289
292
  dispose: () => Promise<void>;
@@ -337,7 +340,7 @@ declare class SessionPublicService implements TSessionConnectionService {
337
340
  private readonly loggerService;
338
341
  private readonly sessionConnectionService;
339
342
  execute: (content: string, clientId: string, swarmName: SwarmName) => Promise<string>;
340
- connect: (connector: SendMessageFn, clientId: string, swarmName: SwarmName) => ReceiveMessageFn;
343
+ connect: (connector: SendMessageFn$1, clientId: string, swarmName: SwarmName) => ReceiveMessageFn;
341
344
  commitToolOutput: (content: string, clientId: string, swarmName: SwarmName) => Promise<void>;
342
345
  commitSystemMessage: (message: string, clientId: string, swarmName: SwarmName) => Promise<void>;
343
346
  dispose: (clientId: string, swarmName: SwarmName) => Promise<void>;
@@ -379,9 +382,17 @@ declare class ToolValidationService {
379
382
 
380
383
  declare class SessionValidationService {
381
384
  private readonly loggerService;
382
- private _sessionMap;
385
+ private _historySwarmMap;
386
+ private _sessionSwarmMap;
387
+ private _agentSwarmMap;
383
388
  addSession: (clientId: SessionId, swarmName: SwarmName) => void;
389
+ addAgentUsage: (sessionId: SessionId, agentName: AgentName) => void;
390
+ addHistoryUsage: (sessionId: SessionId, agentName: AgentName) => void;
391
+ removeAgentUsage: (sessionId: SessionId, agentName: AgentName) => void;
392
+ removeHistoryUsage: (sessionId: SessionId, agentName: AgentName) => void;
384
393
  getSessionList: () => string[];
394
+ getSessionAgentList: (clientId: string) => string[];
395
+ getSessionHistoryList: (clientId: string) => string[];
385
396
  getSwarm: (clientId: SessionId) => string;
386
397
  validate: (clientId: SessionId, source: string) => void;
387
398
  removeSession: (clientId: SessionId) => void;
@@ -435,6 +446,7 @@ declare const addSwarm: (swarmSchema: ISwarmSchema) => string;
435
446
 
436
447
  declare const addTool: (toolSchema: IAgentTool) => string;
437
448
 
449
+ type SendMessageFn = (outgoing: string) => Promise<void>;
438
450
  declare const makeConnection: (connector: ReceiveMessageFn, clientId: string, swarmName: SwarmName) => SendMessageFn;
439
451
 
440
452
  declare const changeAgent: (agentName: AgentName, clientId: string) => Promise<void>;
@@ -464,7 +476,8 @@ declare const GLOBAL_CONFIG: {
464
476
  CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
465
477
  CC_KEEP_MESSAGES: number;
466
478
  CC_ANSWER_TIMEOUT_SECONDS: number;
479
+ CC_GET_AGENT_HISTORY: (clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>;
467
480
  };
468
481
  declare const setConfig: (config: typeof GLOBAL_CONFIG) => void;
469
482
 
470
- export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type ISwarmSchema, type ReceiveMessageFn, type SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, complete, disposeConnection, execute, getAgentHistory, getRawHistory, makeConnection, session, setConfig, swarm };
483
+ export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type ISwarmSchema, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, complete, disposeConnection, execute, getAgentHistory, getRawHistory, makeConnection, session, setConfig, swarm };