agent-swarm-kit 1.0.124 → 1.0.126

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
@@ -4387,6 +4387,7 @@ var ClientSession = /** @class */ (function () {
4387
4387
 
4388
4388
  var METHOD_NAME_BAN_CLIENT = "PolicyUtils.banClient";
4389
4389
  var METHOD_NAME_UNBAN_CLIENT = "PolicyUtils.unbanClient";
4390
+ var METHOD_NAME_HAS_BAN = "PolicyUtils.hasBan";
4390
4391
  /**
4391
4392
  * NoopPolicy class implements the IPolicy interface with no-op methods.
4392
4393
  */
@@ -4400,6 +4401,15 @@ var NoopPolicy = /** @class */ (function () {
4400
4401
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4401
4402
  swarm$1.loggerService.debug("NoopPolicy CTOR swarmName=".concat(swarmName));
4402
4403
  }
4404
+ /**
4405
+ * Check if has ban in any policy
4406
+ * @returns {Promise<boolean>}
4407
+ */
4408
+ NoopPolicy.prototype.hasBan = function () {
4409
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4410
+ swarm$1.loggerService.debug("NoopPolicy hasBan swarmName=".concat(this.swarmName));
4411
+ return Promise.resolve(false);
4412
+ };
4403
4413
  /**
4404
4414
  * Gets the ban message.
4405
4415
  * @returns {Promise<string>} The ban message.
@@ -4465,6 +4475,56 @@ var MergePolicy = /** @class */ (function () {
4465
4475
  policies: policies,
4466
4476
  });
4467
4477
  }
4478
+ /**
4479
+ * Check if has ban in any policy
4480
+ * @param {SessionId} clientId - The client ID.
4481
+ * @param {SwarmName} swarmName - The name of the swarm.
4482
+ * @returns {Promise<boolean>}
4483
+ */
4484
+ MergePolicy.prototype.hasBan = function (clientId, swarmName) {
4485
+ return __awaiter(this, void 0, void 0, function () {
4486
+ var _a, _b, policy, e_1_1;
4487
+ var e_1, _c;
4488
+ return __generator(this, function (_d) {
4489
+ switch (_d.label) {
4490
+ case 0:
4491
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4492
+ swarm$1.loggerService.debug("MergePolicy hasBan swarmName=".concat(swarmName), {
4493
+ clientId: clientId,
4494
+ });
4495
+ _d.label = 1;
4496
+ case 1:
4497
+ _d.trys.push([1, 6, 7, 8]);
4498
+ _a = __values(this.policies), _b = _a.next();
4499
+ _d.label = 2;
4500
+ case 2:
4501
+ if (!!_b.done) return [3 /*break*/, 5];
4502
+ policy = _b.value;
4503
+ return [4 /*yield*/, policy.hasBan(clientId, swarmName)];
4504
+ case 3:
4505
+ if (_d.sent()) {
4506
+ return [2 /*return*/, true];
4507
+ }
4508
+ _d.label = 4;
4509
+ case 4:
4510
+ _b = _a.next();
4511
+ return [3 /*break*/, 2];
4512
+ case 5: return [3 /*break*/, 8];
4513
+ case 6:
4514
+ e_1_1 = _d.sent();
4515
+ e_1 = { error: e_1_1 };
4516
+ return [3 /*break*/, 8];
4517
+ case 7:
4518
+ try {
4519
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4520
+ }
4521
+ finally { if (e_1) throw e_1.error; }
4522
+ return [7 /*endfinally*/];
4523
+ case 8: return [2 /*return*/, false];
4524
+ }
4525
+ });
4526
+ });
4527
+ };
4468
4528
  /**
4469
4529
  * Gets the ban message.
4470
4530
  * @param {SessionId} clientId - The client ID.
@@ -4500,8 +4560,8 @@ var MergePolicy = /** @class */ (function () {
4500
4560
  */
4501
4561
  MergePolicy.prototype.validateInput = function (incoming, clientId, swarmName) {
4502
4562
  return __awaiter(this, void 0, void 0, function () {
4503
- var _a, _b, policy, e_1_1;
4504
- var e_1, _c;
4563
+ var _a, _b, policy, e_2_1;
4564
+ var e_2, _c;
4505
4565
  return __generator(this, function (_d) {
4506
4566
  switch (_d.label) {
4507
4567
  case 0:
@@ -4529,14 +4589,14 @@ var MergePolicy = /** @class */ (function () {
4529
4589
  return [3 /*break*/, 2];
4530
4590
  case 5: return [3 /*break*/, 8];
4531
4591
  case 6:
4532
- e_1_1 = _d.sent();
4533
- e_1 = { error: e_1_1 };
4592
+ e_2_1 = _d.sent();
4593
+ e_2 = { error: e_2_1 };
4534
4594
  return [3 /*break*/, 8];
4535
4595
  case 7:
4536
4596
  try {
4537
4597
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4538
4598
  }
4539
- finally { if (e_1) throw e_1.error; }
4599
+ finally { if (e_2) throw e_2.error; }
4540
4600
  return [7 /*endfinally*/];
4541
4601
  case 8:
4542
4602
  this._targetPolicy = null;
@@ -4554,8 +4614,8 @@ var MergePolicy = /** @class */ (function () {
4554
4614
  */
4555
4615
  MergePolicy.prototype.validateOutput = function (outgoing, clientId, swarmName) {
4556
4616
  return __awaiter(this, void 0, void 0, function () {
4557
- var _a, _b, policy, e_2_1;
4558
- var e_2, _c;
4617
+ var _a, _b, policy, e_3_1;
4618
+ var e_3, _c;
4559
4619
  return __generator(this, function (_d) {
4560
4620
  switch (_d.label) {
4561
4621
  case 0:
@@ -4583,14 +4643,14 @@ var MergePolicy = /** @class */ (function () {
4583
4643
  return [3 /*break*/, 2];
4584
4644
  case 5: return [3 /*break*/, 8];
4585
4645
  case 6:
4586
- e_2_1 = _d.sent();
4587
- e_2 = { error: e_2_1 };
4646
+ e_3_1 = _d.sent();
4647
+ e_3 = { error: e_3_1 };
4588
4648
  return [3 /*break*/, 8];
4589
4649
  case 7:
4590
4650
  try {
4591
4651
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4592
4652
  }
4593
- finally { if (e_2) throw e_2.error; }
4653
+ finally { if (e_3) throw e_3.error; }
4594
4654
  return [7 /*endfinally*/];
4595
4655
  case 8:
4596
4656
  this._targetPolicy = null;
@@ -4717,6 +4777,28 @@ var PolicyUtils = /** @class */ (function () {
4717
4777
  }
4718
4778
  });
4719
4779
  }); });
4780
+ /**
4781
+ * Check if client is banned
4782
+ * @param {Object} payload - The payload containing clientId, swarmName, and policyName.
4783
+ * @param {string} payload.clientId - The client ID.
4784
+ * @param {SwarmName} payload.swarmName - The name of the swarm.
4785
+ * @param {PolicyName} payload.policyName - The name of the policy.
4786
+ * @returns {Promise<boolean>}
4787
+ */
4788
+ this.hasBan = beginContext(function (payload) { return __awaiter(_this, void 0, void 0, function () {
4789
+ return __generator(this, function (_a) {
4790
+ switch (_a.label) {
4791
+ case 0:
4792
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
4793
+ swarm$1.loggerService.log(METHOD_NAME_HAS_BAN, payload);
4794
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_HAS_BAN);
4795
+ swarm$1.swarmValidationService.validate(payload.swarmName, METHOD_NAME_HAS_BAN);
4796
+ swarm$1.policyValidationService.validate(payload.policyName, METHOD_NAME_HAS_BAN);
4797
+ return [4 /*yield*/, swarm$1.policyPublicService.hasBan(payload.swarmName, METHOD_NAME_HAS_BAN, payload.clientId, payload.policyName)];
4798
+ case 1: return [2 /*return*/, _a.sent()];
4799
+ }
4800
+ });
4801
+ }); });
4720
4802
  }
4721
4803
  return PolicyUtils;
4722
4804
  }());
@@ -6952,6 +7034,24 @@ var SwarmValidationService = /** @class */ (function () {
6952
7034
  }
6953
7035
  return swarm.agentList;
6954
7036
  };
7037
+ /**
7038
+ * Retrieves the list of ban policies for a given swarm.
7039
+ * @param {SwarmName} swarmName - The name of the swarm.
7040
+ * @returns {string[]} The list of policy names.
7041
+ * @throws Will throw an error if the swarm is not found.
7042
+ */
7043
+ this.getPolicyList = function (swarmName) {
7044
+ var _a;
7045
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7046
+ _this.loggerService.info("swarmValidationService getAgentList", {
7047
+ swarmName: swarmName,
7048
+ });
7049
+ var swarm = _this._swarmMap.get(swarmName);
7050
+ if (!swarm) {
7051
+ throw new Error("agent-swarm swarm ".concat(swarmName, " not found"));
7052
+ }
7053
+ return (_a = swarm.policies) !== null && _a !== void 0 ? _a : [];
7054
+ };
6955
7055
  /**
6956
7056
  * Retrieves the list of swarms
6957
7057
  * @returns {string[]} The list of swarm names
@@ -10368,6 +10468,7 @@ var PerfService = /** @class */ (function () {
10368
10468
  this.agentValidationService = inject(TYPES.agentValidationService);
10369
10469
  this.statePublicService = inject(TYPES.statePublicService);
10370
10470
  this.swarmPublicService = inject(TYPES.swarmPublicService);
10471
+ this.policyPublicService = inject(TYPES.policyPublicService);
10371
10472
  this.stateConnectionService = inject(TYPES.stateConnectionService);
10372
10473
  this.executionScheduleMap = new Map();
10373
10474
  this.executionOutputLenMap = new Map();
@@ -10382,7 +10483,7 @@ var PerfService = /** @class */ (function () {
10382
10483
  * @returns {Promise<Record<string, unknown>>} A promise that resolves to an object containing the aggregated state of the client.
10383
10484
  */
10384
10485
  this.computeClientState = function (clientId) { return __awaiter(_this, void 0, void 0, function () {
10385
- var swarmName, agentName, result, stateFetchSet_1;
10486
+ var swarmName, agentName, policyBans, result, stateFetchSet_1;
10386
10487
  var _this = this;
10387
10488
  return __generator(this, function (_a) {
10388
10489
  switch (_a.label) {
@@ -10395,11 +10496,29 @@ var PerfService = /** @class */ (function () {
10395
10496
  return [4 /*yield*/, this.swarmPublicService.getAgentName(METHOD_NAME_COMPUTE_STATE, clientId, swarmName)];
10396
10497
  case 1:
10397
10498
  agentName = _a.sent();
10499
+ return [4 /*yield*/, Promise.all(this.swarmValidationService
10500
+ .getPolicyList(swarmName)
10501
+ .map(function (policyName) { return __awaiter(_this, void 0, void 0, function () {
10502
+ var _a;
10503
+ return __generator(this, function (_b) {
10504
+ switch (_b.label) {
10505
+ case 0:
10506
+ _a = [policyName];
10507
+ return [4 /*yield*/, this.policyPublicService.hasBan(swarmName, METHOD_NAME_COMPUTE_STATE, clientId, policyName)];
10508
+ case 1: return [2 /*return*/, _a.concat([
10509
+ _b.sent()
10510
+ ])];
10511
+ }
10512
+ });
10513
+ }); }))];
10514
+ case 2:
10515
+ policyBans = _a.sent();
10398
10516
  result = {
10399
10517
  swarmStatus: {
10400
10518
  swarmName: swarmName,
10401
10519
  agentName: agentName,
10402
- }
10520
+ },
10521
+ policyBans: Object.fromEntries(policyBans),
10403
10522
  };
10404
10523
  stateFetchSet_1 = new Set();
10405
10524
  return [4 /*yield*/, Promise.all(this.swarmValidationService
@@ -10432,7 +10551,7 @@ var PerfService = /** @class */ (function () {
10432
10551
  }
10433
10552
  });
10434
10553
  }); }))];
10435
- case 2:
10554
+ case 3:
10436
10555
  _a.sent();
10437
10556
  return [2 /*return*/, result];
10438
10557
  }
@@ -10855,6 +10974,46 @@ var PolicyPublicService = /** @class */ (function () {
10855
10974
  var _this = this;
10856
10975
  this.loggerService = inject(TYPES.loggerService);
10857
10976
  this.policyConnectionService = inject(TYPES.policyConnectionService);
10977
+ /**
10978
+ * Check if has ban message
10979
+ * @param {SwarmName} swarmName - The name of the swarm.
10980
+ * @param {string} methodName - The name of the method.
10981
+ * @param {string} clientId - The ID of the client.
10982
+ * @param {PolicyName} policyName - The name of the policy.
10983
+ * @returns {Promise<boolean>}
10984
+ */
10985
+ this.hasBan = function (swarmName, methodName, clientId, policyName) { return __awaiter(_this, void 0, void 0, function () {
10986
+ var _this = this;
10987
+ return __generator(this, function (_a) {
10988
+ switch (_a.label) {
10989
+ case 0:
10990
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
10991
+ this.loggerService.info("policyPublicService hasBan", {
10992
+ methodName: methodName,
10993
+ clientId: clientId,
10994
+ swarmName: swarmName,
10995
+ policyName: policyName,
10996
+ });
10997
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
10998
+ return __generator(this, function (_a) {
10999
+ switch (_a.label) {
11000
+ case 0: return [4 /*yield*/, this.policyConnectionService.hasBan(clientId, swarmName)];
11001
+ case 1: return [2 /*return*/, _a.sent()];
11002
+ }
11003
+ });
11004
+ }); }, {
11005
+ methodName: methodName,
11006
+ clientId: clientId,
11007
+ agentName: "",
11008
+ swarmName: swarmName,
11009
+ policyName: policyName,
11010
+ storageName: "",
11011
+ stateName: "",
11012
+ })];
11013
+ case 1: return [2 /*return*/, _a.sent()];
11014
+ }
11015
+ });
11016
+ }); };
10858
11017
  /**
10859
11018
  * Retrieves the ban message for a client in a specific swarm.
10860
11019
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -11085,6 +11244,35 @@ var ClientPolicy = /** @class */ (function () {
11085
11244
  this.params.callbacks.onInit(params.policyName);
11086
11245
  }
11087
11246
  }
11247
+ /**
11248
+ * Check if client is banned
11249
+ * @param {SessionId} clientId - The client ID.
11250
+ * @param {SwarmName} swarmName - The swarm name.
11251
+ * @returns {Promise<boolean>}
11252
+ */
11253
+ ClientPolicy.prototype.hasBan = function (clientId, swarmName) {
11254
+ return __awaiter(this, void 0, void 0, function () {
11255
+ var _a, _b;
11256
+ return __generator(this, function (_c) {
11257
+ switch (_c.label) {
11258
+ case 0:
11259
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
11260
+ this.params.logger.debug("ClientPolicy policyName=".concat(this.params.policyName, " hasBan"), {
11261
+ clientId: clientId,
11262
+ swarmName: swarmName,
11263
+ });
11264
+ if (!(this._banSet === BAN_NEED_FETCH)) return [3 /*break*/, 2];
11265
+ _a = this;
11266
+ _b = Set.bind;
11267
+ return [4 /*yield*/, this.params.getBannedClients(this.params.policyName, swarmName)];
11268
+ case 1:
11269
+ _a._banSet = new (_b.apply(Set, [void 0, _c.sent()]))();
11270
+ _c.label = 2;
11271
+ case 2: return [2 /*return*/, this._banSet.has(clientId)];
11272
+ }
11273
+ });
11274
+ });
11275
+ };
11088
11276
  /**
11089
11277
  * Gets the ban message for a client.
11090
11278
  * @param {SessionId} clientId - The client ID.
@@ -11388,6 +11576,26 @@ var PolicyConnectionService = /** @class */ (function () {
11388
11576
  var schema = _this.policySchemaService.get(policyName);
11389
11577
  return new ClientPolicy(__assign({ policyName: policyName, bus: _this.busService, logger: _this.loggerService }, schema));
11390
11578
  });
11579
+ /**
11580
+ * Check if got ban flag
11581
+ * @param {SessionId} clientId - The ID of the client.
11582
+ * @param {SwarmName} swarmName - The name of the swarm.
11583
+ * @returns {Promise<boolean>}
11584
+ */
11585
+ this.hasBan = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
11586
+ return __generator(this, function (_a) {
11587
+ switch (_a.label) {
11588
+ case 0:
11589
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
11590
+ this.loggerService.info("policyConnectionService hasBan", {
11591
+ clientId: clientId,
11592
+ swarmName: swarmName,
11593
+ });
11594
+ return [4 /*yield*/, this.getPolicy(this.methodContextService.context.policyName).hasBan(clientId, swarmName)];
11595
+ case 1: return [2 /*return*/, _a.sent()];
11596
+ }
11597
+ });
11598
+ }); };
11391
11599
  /**
11392
11600
  * Retrieves the ban message for a client in a swarm.
11393
11601
  * @param {SessionId} clientId - The ID of the client.
package/build/index.mjs CHANGED
@@ -4385,6 +4385,7 @@ var ClientSession = /** @class */ (function () {
4385
4385
 
4386
4386
  var METHOD_NAME_BAN_CLIENT = "PolicyUtils.banClient";
4387
4387
  var METHOD_NAME_UNBAN_CLIENT = "PolicyUtils.unbanClient";
4388
+ var METHOD_NAME_HAS_BAN = "PolicyUtils.hasBan";
4388
4389
  /**
4389
4390
  * NoopPolicy class implements the IPolicy interface with no-op methods.
4390
4391
  */
@@ -4398,6 +4399,15 @@ var NoopPolicy = /** @class */ (function () {
4398
4399
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4399
4400
  swarm$1.loggerService.debug("NoopPolicy CTOR swarmName=".concat(swarmName));
4400
4401
  }
4402
+ /**
4403
+ * Check if has ban in any policy
4404
+ * @returns {Promise<boolean>}
4405
+ */
4406
+ NoopPolicy.prototype.hasBan = function () {
4407
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4408
+ swarm$1.loggerService.debug("NoopPolicy hasBan swarmName=".concat(this.swarmName));
4409
+ return Promise.resolve(false);
4410
+ };
4401
4411
  /**
4402
4412
  * Gets the ban message.
4403
4413
  * @returns {Promise<string>} The ban message.
@@ -4463,6 +4473,56 @@ var MergePolicy = /** @class */ (function () {
4463
4473
  policies: policies,
4464
4474
  });
4465
4475
  }
4476
+ /**
4477
+ * Check if has ban in any policy
4478
+ * @param {SessionId} clientId - The client ID.
4479
+ * @param {SwarmName} swarmName - The name of the swarm.
4480
+ * @returns {Promise<boolean>}
4481
+ */
4482
+ MergePolicy.prototype.hasBan = function (clientId, swarmName) {
4483
+ return __awaiter(this, void 0, void 0, function () {
4484
+ var _a, _b, policy, e_1_1;
4485
+ var e_1, _c;
4486
+ return __generator(this, function (_d) {
4487
+ switch (_d.label) {
4488
+ case 0:
4489
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4490
+ swarm$1.loggerService.debug("MergePolicy hasBan swarmName=".concat(swarmName), {
4491
+ clientId: clientId,
4492
+ });
4493
+ _d.label = 1;
4494
+ case 1:
4495
+ _d.trys.push([1, 6, 7, 8]);
4496
+ _a = __values(this.policies), _b = _a.next();
4497
+ _d.label = 2;
4498
+ case 2:
4499
+ if (!!_b.done) return [3 /*break*/, 5];
4500
+ policy = _b.value;
4501
+ return [4 /*yield*/, policy.hasBan(clientId, swarmName)];
4502
+ case 3:
4503
+ if (_d.sent()) {
4504
+ return [2 /*return*/, true];
4505
+ }
4506
+ _d.label = 4;
4507
+ case 4:
4508
+ _b = _a.next();
4509
+ return [3 /*break*/, 2];
4510
+ case 5: return [3 /*break*/, 8];
4511
+ case 6:
4512
+ e_1_1 = _d.sent();
4513
+ e_1 = { error: e_1_1 };
4514
+ return [3 /*break*/, 8];
4515
+ case 7:
4516
+ try {
4517
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4518
+ }
4519
+ finally { if (e_1) throw e_1.error; }
4520
+ return [7 /*endfinally*/];
4521
+ case 8: return [2 /*return*/, false];
4522
+ }
4523
+ });
4524
+ });
4525
+ };
4466
4526
  /**
4467
4527
  * Gets the ban message.
4468
4528
  * @param {SessionId} clientId - The client ID.
@@ -4498,8 +4558,8 @@ var MergePolicy = /** @class */ (function () {
4498
4558
  */
4499
4559
  MergePolicy.prototype.validateInput = function (incoming, clientId, swarmName) {
4500
4560
  return __awaiter(this, void 0, void 0, function () {
4501
- var _a, _b, policy, e_1_1;
4502
- var e_1, _c;
4561
+ var _a, _b, policy, e_2_1;
4562
+ var e_2, _c;
4503
4563
  return __generator(this, function (_d) {
4504
4564
  switch (_d.label) {
4505
4565
  case 0:
@@ -4527,14 +4587,14 @@ var MergePolicy = /** @class */ (function () {
4527
4587
  return [3 /*break*/, 2];
4528
4588
  case 5: return [3 /*break*/, 8];
4529
4589
  case 6:
4530
- e_1_1 = _d.sent();
4531
- e_1 = { error: e_1_1 };
4590
+ e_2_1 = _d.sent();
4591
+ e_2 = { error: e_2_1 };
4532
4592
  return [3 /*break*/, 8];
4533
4593
  case 7:
4534
4594
  try {
4535
4595
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4536
4596
  }
4537
- finally { if (e_1) throw e_1.error; }
4597
+ finally { if (e_2) throw e_2.error; }
4538
4598
  return [7 /*endfinally*/];
4539
4599
  case 8:
4540
4600
  this._targetPolicy = null;
@@ -4552,8 +4612,8 @@ var MergePolicy = /** @class */ (function () {
4552
4612
  */
4553
4613
  MergePolicy.prototype.validateOutput = function (outgoing, clientId, swarmName) {
4554
4614
  return __awaiter(this, void 0, void 0, function () {
4555
- var _a, _b, policy, e_2_1;
4556
- var e_2, _c;
4615
+ var _a, _b, policy, e_3_1;
4616
+ var e_3, _c;
4557
4617
  return __generator(this, function (_d) {
4558
4618
  switch (_d.label) {
4559
4619
  case 0:
@@ -4581,14 +4641,14 @@ var MergePolicy = /** @class */ (function () {
4581
4641
  return [3 /*break*/, 2];
4582
4642
  case 5: return [3 /*break*/, 8];
4583
4643
  case 6:
4584
- e_2_1 = _d.sent();
4585
- e_2 = { error: e_2_1 };
4644
+ e_3_1 = _d.sent();
4645
+ e_3 = { error: e_3_1 };
4586
4646
  return [3 /*break*/, 8];
4587
4647
  case 7:
4588
4648
  try {
4589
4649
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
4590
4650
  }
4591
- finally { if (e_2) throw e_2.error; }
4651
+ finally { if (e_3) throw e_3.error; }
4592
4652
  return [7 /*endfinally*/];
4593
4653
  case 8:
4594
4654
  this._targetPolicy = null;
@@ -4715,6 +4775,28 @@ var PolicyUtils = /** @class */ (function () {
4715
4775
  }
4716
4776
  });
4717
4777
  }); });
4778
+ /**
4779
+ * Check if client is banned
4780
+ * @param {Object} payload - The payload containing clientId, swarmName, and policyName.
4781
+ * @param {string} payload.clientId - The client ID.
4782
+ * @param {SwarmName} payload.swarmName - The name of the swarm.
4783
+ * @param {PolicyName} payload.policyName - The name of the policy.
4784
+ * @returns {Promise<boolean>}
4785
+ */
4786
+ this.hasBan = beginContext(function (payload) { return __awaiter(_this, void 0, void 0, function () {
4787
+ return __generator(this, function (_a) {
4788
+ switch (_a.label) {
4789
+ case 0:
4790
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
4791
+ swarm$1.loggerService.log(METHOD_NAME_HAS_BAN, payload);
4792
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_HAS_BAN);
4793
+ swarm$1.swarmValidationService.validate(payload.swarmName, METHOD_NAME_HAS_BAN);
4794
+ swarm$1.policyValidationService.validate(payload.policyName, METHOD_NAME_HAS_BAN);
4795
+ return [4 /*yield*/, swarm$1.policyPublicService.hasBan(payload.swarmName, METHOD_NAME_HAS_BAN, payload.clientId, payload.policyName)];
4796
+ case 1: return [2 /*return*/, _a.sent()];
4797
+ }
4798
+ });
4799
+ }); });
4718
4800
  }
4719
4801
  return PolicyUtils;
4720
4802
  }());
@@ -6950,6 +7032,24 @@ var SwarmValidationService = /** @class */ (function () {
6950
7032
  }
6951
7033
  return swarm.agentList;
6952
7034
  };
7035
+ /**
7036
+ * Retrieves the list of ban policies for a given swarm.
7037
+ * @param {SwarmName} swarmName - The name of the swarm.
7038
+ * @returns {string[]} The list of policy names.
7039
+ * @throws Will throw an error if the swarm is not found.
7040
+ */
7041
+ this.getPolicyList = function (swarmName) {
7042
+ var _a;
7043
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7044
+ _this.loggerService.info("swarmValidationService getAgentList", {
7045
+ swarmName: swarmName,
7046
+ });
7047
+ var swarm = _this._swarmMap.get(swarmName);
7048
+ if (!swarm) {
7049
+ throw new Error("agent-swarm swarm ".concat(swarmName, " not found"));
7050
+ }
7051
+ return (_a = swarm.policies) !== null && _a !== void 0 ? _a : [];
7052
+ };
6953
7053
  /**
6954
7054
  * Retrieves the list of swarms
6955
7055
  * @returns {string[]} The list of swarm names
@@ -10366,6 +10466,7 @@ var PerfService = /** @class */ (function () {
10366
10466
  this.agentValidationService = inject(TYPES.agentValidationService);
10367
10467
  this.statePublicService = inject(TYPES.statePublicService);
10368
10468
  this.swarmPublicService = inject(TYPES.swarmPublicService);
10469
+ this.policyPublicService = inject(TYPES.policyPublicService);
10369
10470
  this.stateConnectionService = inject(TYPES.stateConnectionService);
10370
10471
  this.executionScheduleMap = new Map();
10371
10472
  this.executionOutputLenMap = new Map();
@@ -10380,7 +10481,7 @@ var PerfService = /** @class */ (function () {
10380
10481
  * @returns {Promise<Record<string, unknown>>} A promise that resolves to an object containing the aggregated state of the client.
10381
10482
  */
10382
10483
  this.computeClientState = function (clientId) { return __awaiter(_this, void 0, void 0, function () {
10383
- var swarmName, agentName, result, stateFetchSet_1;
10484
+ var swarmName, agentName, policyBans, result, stateFetchSet_1;
10384
10485
  var _this = this;
10385
10486
  return __generator(this, function (_a) {
10386
10487
  switch (_a.label) {
@@ -10393,11 +10494,29 @@ var PerfService = /** @class */ (function () {
10393
10494
  return [4 /*yield*/, this.swarmPublicService.getAgentName(METHOD_NAME_COMPUTE_STATE, clientId, swarmName)];
10394
10495
  case 1:
10395
10496
  agentName = _a.sent();
10497
+ return [4 /*yield*/, Promise.all(this.swarmValidationService
10498
+ .getPolicyList(swarmName)
10499
+ .map(function (policyName) { return __awaiter(_this, void 0, void 0, function () {
10500
+ var _a;
10501
+ return __generator(this, function (_b) {
10502
+ switch (_b.label) {
10503
+ case 0:
10504
+ _a = [policyName];
10505
+ return [4 /*yield*/, this.policyPublicService.hasBan(swarmName, METHOD_NAME_COMPUTE_STATE, clientId, policyName)];
10506
+ case 1: return [2 /*return*/, _a.concat([
10507
+ _b.sent()
10508
+ ])];
10509
+ }
10510
+ });
10511
+ }); }))];
10512
+ case 2:
10513
+ policyBans = _a.sent();
10396
10514
  result = {
10397
10515
  swarmStatus: {
10398
10516
  swarmName: swarmName,
10399
10517
  agentName: agentName,
10400
- }
10518
+ },
10519
+ policyBans: Object.fromEntries(policyBans),
10401
10520
  };
10402
10521
  stateFetchSet_1 = new Set();
10403
10522
  return [4 /*yield*/, Promise.all(this.swarmValidationService
@@ -10430,7 +10549,7 @@ var PerfService = /** @class */ (function () {
10430
10549
  }
10431
10550
  });
10432
10551
  }); }))];
10433
- case 2:
10552
+ case 3:
10434
10553
  _a.sent();
10435
10554
  return [2 /*return*/, result];
10436
10555
  }
@@ -10853,6 +10972,46 @@ var PolicyPublicService = /** @class */ (function () {
10853
10972
  var _this = this;
10854
10973
  this.loggerService = inject(TYPES.loggerService);
10855
10974
  this.policyConnectionService = inject(TYPES.policyConnectionService);
10975
+ /**
10976
+ * Check if has ban message
10977
+ * @param {SwarmName} swarmName - The name of the swarm.
10978
+ * @param {string} methodName - The name of the method.
10979
+ * @param {string} clientId - The ID of the client.
10980
+ * @param {PolicyName} policyName - The name of the policy.
10981
+ * @returns {Promise<boolean>}
10982
+ */
10983
+ this.hasBan = function (swarmName, methodName, clientId, policyName) { return __awaiter(_this, void 0, void 0, function () {
10984
+ var _this = this;
10985
+ return __generator(this, function (_a) {
10986
+ switch (_a.label) {
10987
+ case 0:
10988
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
10989
+ this.loggerService.info("policyPublicService hasBan", {
10990
+ methodName: methodName,
10991
+ clientId: clientId,
10992
+ swarmName: swarmName,
10993
+ policyName: policyName,
10994
+ });
10995
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
10996
+ return __generator(this, function (_a) {
10997
+ switch (_a.label) {
10998
+ case 0: return [4 /*yield*/, this.policyConnectionService.hasBan(clientId, swarmName)];
10999
+ case 1: return [2 /*return*/, _a.sent()];
11000
+ }
11001
+ });
11002
+ }); }, {
11003
+ methodName: methodName,
11004
+ clientId: clientId,
11005
+ agentName: "",
11006
+ swarmName: swarmName,
11007
+ policyName: policyName,
11008
+ storageName: "",
11009
+ stateName: "",
11010
+ })];
11011
+ case 1: return [2 /*return*/, _a.sent()];
11012
+ }
11013
+ });
11014
+ }); };
10856
11015
  /**
10857
11016
  * Retrieves the ban message for a client in a specific swarm.
10858
11017
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -11083,6 +11242,35 @@ var ClientPolicy = /** @class */ (function () {
11083
11242
  this.params.callbacks.onInit(params.policyName);
11084
11243
  }
11085
11244
  }
11245
+ /**
11246
+ * Check if client is banned
11247
+ * @param {SessionId} clientId - The client ID.
11248
+ * @param {SwarmName} swarmName - The swarm name.
11249
+ * @returns {Promise<boolean>}
11250
+ */
11251
+ ClientPolicy.prototype.hasBan = function (clientId, swarmName) {
11252
+ return __awaiter(this, void 0, void 0, function () {
11253
+ var _a, _b;
11254
+ return __generator(this, function (_c) {
11255
+ switch (_c.label) {
11256
+ case 0:
11257
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
11258
+ this.params.logger.debug("ClientPolicy policyName=".concat(this.params.policyName, " hasBan"), {
11259
+ clientId: clientId,
11260
+ swarmName: swarmName,
11261
+ });
11262
+ if (!(this._banSet === BAN_NEED_FETCH)) return [3 /*break*/, 2];
11263
+ _a = this;
11264
+ _b = Set.bind;
11265
+ return [4 /*yield*/, this.params.getBannedClients(this.params.policyName, swarmName)];
11266
+ case 1:
11267
+ _a._banSet = new (_b.apply(Set, [void 0, _c.sent()]))();
11268
+ _c.label = 2;
11269
+ case 2: return [2 /*return*/, this._banSet.has(clientId)];
11270
+ }
11271
+ });
11272
+ });
11273
+ };
11086
11274
  /**
11087
11275
  * Gets the ban message for a client.
11088
11276
  * @param {SessionId} clientId - The client ID.
@@ -11386,6 +11574,26 @@ var PolicyConnectionService = /** @class */ (function () {
11386
11574
  var schema = _this.policySchemaService.get(policyName);
11387
11575
  return new ClientPolicy(__assign({ policyName: policyName, bus: _this.busService, logger: _this.loggerService }, schema));
11388
11576
  });
11577
+ /**
11578
+ * Check if got ban flag
11579
+ * @param {SessionId} clientId - The ID of the client.
11580
+ * @param {SwarmName} swarmName - The name of the swarm.
11581
+ * @returns {Promise<boolean>}
11582
+ */
11583
+ this.hasBan = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
11584
+ return __generator(this, function (_a) {
11585
+ switch (_a.label) {
11586
+ case 0:
11587
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
11588
+ this.loggerService.info("policyConnectionService hasBan", {
11589
+ clientId: clientId,
11590
+ swarmName: swarmName,
11591
+ });
11592
+ return [4 /*yield*/, this.getPolicy(this.methodContextService.context.policyName).hasBan(clientId, swarmName)];
11593
+ case 1: return [2 /*return*/, _a.sent()];
11594
+ }
11595
+ });
11596
+ }); };
11389
11597
  /**
11390
11598
  * Retrieves the ban message for a client in a swarm.
11391
11599
  * @param {SessionId} clientId - The ID of the client.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.124",
3
+ "version": "1.0.126",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -12,7 +12,7 @@
12
12
  "url": "http://paypal.me/tripolskypetr"
13
13
  },
14
14
  "license": "MIT",
15
- "homepage": "https://react-declarative-playground.github.io",
15
+ "homepage": "https://agent-swarm.github.io",
16
16
  "keywords": [
17
17
  "NVIDIA NIM",
18
18
  "OpenAI",
@@ -43,6 +43,7 @@
43
43
  "build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
44
44
  "docs:gpt": "npm run build && node ./scripts/gpt-docs.mjs",
45
45
  "docs:uml": "npm run build && node ./scripts/uml.mjs",
46
+ "docs:www": "typedoc",
46
47
  "repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
47
48
  },
48
49
  "main": "build/index.cjs",
@@ -67,7 +68,8 @@
67
68
  "rollup-plugin-dts": "6.1.1",
68
69
  "rollup-plugin-peer-deps-external": "2.2.4",
69
70
  "tslib": "2.7.0",
70
- "worker-testbed": "1.0.10"
71
+ "worker-testbed": "1.0.10",
72
+ "typedoc": "0.27.9"
71
73
  },
72
74
  "peerDependencies": {
73
75
  "typescript": "^5.0.0"
package/types.d.ts CHANGED
@@ -463,6 +463,12 @@ interface IPolicyCallbacks {
463
463
  * Interface for a policy.
464
464
  */
465
465
  interface IPolicy {
466
+ /**
467
+ * Check if got banhammer flag
468
+ * @param clientId - The session ID of the client.
469
+ * @param swarmName - The name of the swarm.
470
+ */
471
+ hasBan(clientId: SessionId, swarmName: SwarmName): Promise<boolean>;
466
472
  /**
467
473
  * Gets the ban message for a client.
468
474
  * @param clientId - The session ID of the client.
@@ -2958,6 +2964,13 @@ declare class SwarmValidationService {
2958
2964
  * @throws Will throw an error if the swarm is not found.
2959
2965
  */
2960
2966
  getAgentList: (swarmName: SwarmName) => string[];
2967
+ /**
2968
+ * Retrieves the list of ban policies for a given swarm.
2969
+ * @param {SwarmName} swarmName - The name of the swarm.
2970
+ * @returns {string[]} The list of policy names.
2971
+ * @throws Will throw an error if the swarm is not found.
2972
+ */
2973
+ getPolicyList: (swarmName: SwarmName) => string[];
2961
2974
  /**
2962
2975
  * Retrieves the list of swarms
2963
2976
  * @returns {string[]} The list of swarm names
@@ -3882,6 +3895,7 @@ declare class PerfService {
3882
3895
  private readonly agentValidationService;
3883
3896
  private readonly statePublicService;
3884
3897
  private readonly swarmPublicService;
3898
+ private readonly policyPublicService;
3885
3899
  private readonly stateConnectionService;
3886
3900
  private executionScheduleMap;
3887
3901
  private executionOutputLenMap;
@@ -4050,6 +4064,13 @@ declare class ClientPolicy implements IPolicy {
4050
4064
  * @param {IPolicyParams} params - The policy parameters.
4051
4065
  */
4052
4066
  constructor(params: IPolicyParams);
4067
+ /**
4068
+ * Check if client is banned
4069
+ * @param {SessionId} clientId - The client ID.
4070
+ * @param {SwarmName} swarmName - The swarm name.
4071
+ * @returns {Promise<boolean>}
4072
+ */
4073
+ hasBan(clientId: SessionId, swarmName: SwarmName): Promise<boolean>;
4053
4074
  /**
4054
4075
  * Gets the ban message for a client.
4055
4076
  * @param {SessionId} clientId - The client ID.
@@ -4104,6 +4125,13 @@ declare class PolicyConnectionService implements IPolicy {
4104
4125
  * @returns {ClientPolicy} The client policy.
4105
4126
  */
4106
4127
  getPolicy: ((policyName: PolicyName) => ClientPolicy) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientPolicy>;
4128
+ /**
4129
+ * Check if got ban flag
4130
+ * @param {SessionId} clientId - The ID of the client.
4131
+ * @param {SwarmName} swarmName - The name of the swarm.
4132
+ * @returns {Promise<boolean>}
4133
+ */
4134
+ hasBan: (clientId: SessionId, swarmName: SwarmName) => Promise<boolean>;
4107
4135
  /**
4108
4136
  * Retrieves the ban message for a client in a swarm.
4109
4137
  * @param {SessionId} clientId - The ID of the client.
@@ -4157,6 +4185,15 @@ type TPolicyConnectionService = {
4157
4185
  declare class PolicyPublicService implements TPolicyConnectionService {
4158
4186
  private readonly loggerService;
4159
4187
  private readonly policyConnectionService;
4188
+ /**
4189
+ * Check if has ban message
4190
+ * @param {SwarmName} swarmName - The name of the swarm.
4191
+ * @param {string} methodName - The name of the method.
4192
+ * @param {string} clientId - The ID of the client.
4193
+ * @param {PolicyName} policyName - The name of the policy.
4194
+ * @returns {Promise<boolean>}
4195
+ */
4196
+ hasBan: (swarmName: SwarmName, methodName: string, clientId: string, policyName: PolicyName) => Promise<boolean>;
4160
4197
  /**
4161
4198
  * Retrieves the ban message for a client in a specific swarm.
4162
4199
  * @param {SwarmName} swarmName - The name of the swarm.
@@ -5297,6 +5334,19 @@ declare class PolicyUtils {
5297
5334
  swarmName: SwarmName;
5298
5335
  policyName: PolicyName;
5299
5336
  }) => Promise<void>;
5337
+ /**
5338
+ * Check if client is banned
5339
+ * @param {Object} payload - The payload containing clientId, swarmName, and policyName.
5340
+ * @param {string} payload.clientId - The client ID.
5341
+ * @param {SwarmName} payload.swarmName - The name of the swarm.
5342
+ * @param {PolicyName} payload.policyName - The name of the policy.
5343
+ * @returns {Promise<boolean>}
5344
+ */
5345
+ hasBan: (payload: {
5346
+ clientId: string;
5347
+ swarmName: SwarmName;
5348
+ policyName: PolicyName;
5349
+ }) => Promise<boolean>;
5300
5350
  }
5301
5351
  /**
5302
5352
  * An instance of PolicyUtils.
@@ -5614,4 +5664,4 @@ declare const Schema: SchemaUtils;
5614
5664
  */
5615
5665
  declare const beginContext: <T extends (...args: any[]) => any>(run: T) => ((...args: Parameters<T>) => ReturnType<T>);
5616
5666
 
5617
- export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Policy, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, runStateless, runStatelessForce, session, setConfig, swarm };
5667
+ export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Policy, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, runStateless, runStatelessForce, session, setConfig, swarm };