agent-swarm-kit 1.0.65 → 1.0.67

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
@@ -478,6 +478,9 @@ var HistoryInstance = /** @class */ (function () {
478
478
  if (callbacks.onInit) {
479
479
  callbacks.onInit(clientId);
480
480
  }
481
+ if (callbacks.onRef) {
482
+ callbacks.onRef(this);
483
+ }
481
484
  if (callbacks.filterCondition) {
482
485
  this.iterate = function (agentName) {
483
486
  return __asyncGenerator(this, arguments, function () {
@@ -4316,7 +4319,7 @@ var ClientStorage = /** @class */ (function () {
4316
4319
  return __generator(this, function (_a) {
4317
4320
  switch (_a.label) {
4318
4321
  case 0:
4319
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " _createEmbedding"), {
4322
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " _createEmbedding"), {
4320
4323
  id: item.id,
4321
4324
  });
4322
4325
  return [4 /*yield*/, this.params.createIndex(item)];
@@ -4341,7 +4344,7 @@ var ClientStorage = /** @class */ (function () {
4341
4344
  return __generator(this, function (_a) {
4342
4345
  switch (_a.label) {
4343
4346
  case 0:
4344
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " waitForInit"));
4347
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " waitForInit"));
4345
4348
  if (!this.params.getData) {
4346
4349
  return [2 /*return*/];
4347
4350
  }
@@ -4379,7 +4382,7 @@ var ClientStorage = /** @class */ (function () {
4379
4382
  return __generator(this, function (_c) {
4380
4383
  switch (_c.label) {
4381
4384
  case 0:
4382
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
4385
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " take"), {
4383
4386
  search: search,
4384
4387
  total: total,
4385
4388
  });
@@ -4413,7 +4416,7 @@ var ClientStorage = /** @class */ (function () {
4413
4416
  })))];
4414
4417
  case 2:
4415
4418
  _c.sent();
4416
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
4419
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " take indexed"), {
4417
4420
  indexed: indexed.getEntries(),
4418
4421
  });
4419
4422
  if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onSearch) {
@@ -4434,7 +4437,7 @@ var ClientStorage = /** @class */ (function () {
4434
4437
  return __generator(this, function (_c) {
4435
4438
  switch (_c.label) {
4436
4439
  case 0:
4437
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " upsert"), {
4440
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " upsert"), {
4438
4441
  item: item,
4439
4442
  });
4440
4443
  this._itemMap.set(item.id, item);
@@ -4457,7 +4460,7 @@ var ClientStorage = /** @class */ (function () {
4457
4460
  this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
4458
4461
  var _a, _b;
4459
4462
  return __generator(this, function (_c) {
4460
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " remove"), {
4463
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " remove"), {
4461
4464
  id: itemId,
4462
4465
  });
4463
4466
  this._itemMap.delete(itemId);
@@ -4474,7 +4477,7 @@ var ClientStorage = /** @class */ (function () {
4474
4477
  */
4475
4478
  this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
4476
4479
  return __generator(this, function (_a) {
4477
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " clear"));
4480
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " clear"));
4478
4481
  this._itemMap.clear();
4479
4482
  this._createEmbedding.clear();
4480
4483
  return [2 /*return*/];
@@ -4488,7 +4491,7 @@ var ClientStorage = /** @class */ (function () {
4488
4491
  this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
4489
4492
  var _a;
4490
4493
  return __generator(this, function (_b) {
4491
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " get"), {
4494
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " get"), {
4492
4495
  id: itemId,
4493
4496
  });
4494
4497
  return [2 /*return*/, (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null];
@@ -4503,7 +4506,7 @@ var ClientStorage = /** @class */ (function () {
4503
4506
  var result, _a, _b, item;
4504
4507
  var e_1, _c;
4505
4508
  return __generator(this, function (_d) {
4506
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " list"));
4509
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " list"));
4507
4510
  if (!filter) {
4508
4511
  return [2 /*return*/, __spreadArray([], __read(this._itemMap.values()), false)];
4509
4512
  }
@@ -4526,7 +4529,7 @@ var ClientStorage = /** @class */ (function () {
4526
4529
  return [2 /*return*/, result];
4527
4530
  });
4528
4531
  }); };
4529
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " CTOR"), {
4532
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " CTOR"), {
4530
4533
  params: params,
4531
4534
  });
4532
4535
  }
@@ -4545,6 +4548,20 @@ var StorageConnectionService = /** @class */ (function () {
4545
4548
  this.storageSchemaService = inject(TYPES.storageSchemaService);
4546
4549
  this.sessionValidationService = inject(TYPES.sessionValidationService);
4547
4550
  this.embeddingSchemaService = inject(TYPES.embeddingSchemaService);
4551
+ /**
4552
+ * Retrieves a shared storage instance based on storage name.
4553
+ * @param {string} clientId - The client ID.
4554
+ * @param {string} storageName - The storage name.
4555
+ * @returns {ClientStorage} The client storage instance.
4556
+ */
4557
+ this.getSharedStorage = functoolsKit.memoize(function (_a) {
4558
+ var _b = __read(_a, 2), storageName = _b[1];
4559
+ return "".concat(storageName);
4560
+ }, function (clientId, storageName) {
4561
+ var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, shared = _a.shared, callbacks = _a.callbacks;
4562
+ var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
4563
+ return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4564
+ });
4548
4565
  /**
4549
4566
  * Retrieves a storage instance based on client ID and storage name.
4550
4567
  * @param {string} clientId - The client ID.
@@ -4556,9 +4573,12 @@ var StorageConnectionService = /** @class */ (function () {
4556
4573
  return "".concat(clientId, "-").concat(storageName);
4557
4574
  }, function (clientId, storageName) {
4558
4575
  _this.sessionValidationService.addStorageUsage(clientId, storageName);
4559
- var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, callbacks = _a.callbacks;
4560
- var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
4561
- return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4576
+ var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, _b = _a.shared, shared = _b === void 0 ? false : _b, callbacks = _a.callbacks;
4577
+ if (shared) {
4578
+ return _this.getSharedStorage(clientId, storageName);
4579
+ }
4580
+ var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
4581
+ return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4562
4582
  });
4563
4583
  /**
4564
4584
  * Retrieves a list of storage data based on a search query and total number of items.
package/build/index.mjs CHANGED
@@ -476,6 +476,9 @@ var HistoryInstance = /** @class */ (function () {
476
476
  if (callbacks.onInit) {
477
477
  callbacks.onInit(clientId);
478
478
  }
479
+ if (callbacks.onRef) {
480
+ callbacks.onRef(this);
481
+ }
479
482
  if (callbacks.filterCondition) {
480
483
  this.iterate = function (agentName) {
481
484
  return __asyncGenerator(this, arguments, function () {
@@ -4314,7 +4317,7 @@ var ClientStorage = /** @class */ (function () {
4314
4317
  return __generator(this, function (_a) {
4315
4318
  switch (_a.label) {
4316
4319
  case 0:
4317
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " _createEmbedding"), {
4320
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " _createEmbedding"), {
4318
4321
  id: item.id,
4319
4322
  });
4320
4323
  return [4 /*yield*/, this.params.createIndex(item)];
@@ -4339,7 +4342,7 @@ var ClientStorage = /** @class */ (function () {
4339
4342
  return __generator(this, function (_a) {
4340
4343
  switch (_a.label) {
4341
4344
  case 0:
4342
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " waitForInit"));
4345
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " waitForInit"));
4343
4346
  if (!this.params.getData) {
4344
4347
  return [2 /*return*/];
4345
4348
  }
@@ -4377,7 +4380,7 @@ var ClientStorage = /** @class */ (function () {
4377
4380
  return __generator(this, function (_c) {
4378
4381
  switch (_c.label) {
4379
4382
  case 0:
4380
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
4383
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " take"), {
4381
4384
  search: search,
4382
4385
  total: total,
4383
4386
  });
@@ -4411,7 +4414,7 @@ var ClientStorage = /** @class */ (function () {
4411
4414
  })))];
4412
4415
  case 2:
4413
4416
  _c.sent();
4414
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
4417
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " take indexed"), {
4415
4418
  indexed: indexed.getEntries(),
4416
4419
  });
4417
4420
  if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onSearch) {
@@ -4432,7 +4435,7 @@ var ClientStorage = /** @class */ (function () {
4432
4435
  return __generator(this, function (_c) {
4433
4436
  switch (_c.label) {
4434
4437
  case 0:
4435
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " upsert"), {
4438
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " upsert"), {
4436
4439
  item: item,
4437
4440
  });
4438
4441
  this._itemMap.set(item.id, item);
@@ -4455,7 +4458,7 @@ var ClientStorage = /** @class */ (function () {
4455
4458
  this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
4456
4459
  var _a, _b;
4457
4460
  return __generator(this, function (_c) {
4458
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " remove"), {
4461
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " remove"), {
4459
4462
  id: itemId,
4460
4463
  });
4461
4464
  this._itemMap.delete(itemId);
@@ -4472,7 +4475,7 @@ var ClientStorage = /** @class */ (function () {
4472
4475
  */
4473
4476
  this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
4474
4477
  return __generator(this, function (_a) {
4475
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " clear"));
4478
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " clear"));
4476
4479
  this._itemMap.clear();
4477
4480
  this._createEmbedding.clear();
4478
4481
  return [2 /*return*/];
@@ -4486,7 +4489,7 @@ var ClientStorage = /** @class */ (function () {
4486
4489
  this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
4487
4490
  var _a;
4488
4491
  return __generator(this, function (_b) {
4489
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " get"), {
4492
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " get"), {
4490
4493
  id: itemId,
4491
4494
  });
4492
4495
  return [2 /*return*/, (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null];
@@ -4501,7 +4504,7 @@ var ClientStorage = /** @class */ (function () {
4501
4504
  var result, _a, _b, item;
4502
4505
  var e_1, _c;
4503
4506
  return __generator(this, function (_d) {
4504
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " list"));
4507
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " list"));
4505
4508
  if (!filter) {
4506
4509
  return [2 /*return*/, __spreadArray([], __read(this._itemMap.values()), false)];
4507
4510
  }
@@ -4524,7 +4527,7 @@ var ClientStorage = /** @class */ (function () {
4524
4527
  return [2 /*return*/, result];
4525
4528
  });
4526
4529
  }); };
4527
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " CTOR"), {
4530
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " CTOR"), {
4528
4531
  params: params,
4529
4532
  });
4530
4533
  }
@@ -4543,6 +4546,20 @@ var StorageConnectionService = /** @class */ (function () {
4543
4546
  this.storageSchemaService = inject(TYPES.storageSchemaService);
4544
4547
  this.sessionValidationService = inject(TYPES.sessionValidationService);
4545
4548
  this.embeddingSchemaService = inject(TYPES.embeddingSchemaService);
4549
+ /**
4550
+ * Retrieves a shared storage instance based on storage name.
4551
+ * @param {string} clientId - The client ID.
4552
+ * @param {string} storageName - The storage name.
4553
+ * @returns {ClientStorage} The client storage instance.
4554
+ */
4555
+ this.getSharedStorage = memoize(function (_a) {
4556
+ var _b = __read(_a, 2), storageName = _b[1];
4557
+ return "".concat(storageName);
4558
+ }, function (clientId, storageName) {
4559
+ var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, shared = _a.shared, callbacks = _a.callbacks;
4560
+ var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
4561
+ return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4562
+ });
4546
4563
  /**
4547
4564
  * Retrieves a storage instance based on client ID and storage name.
4548
4565
  * @param {string} clientId - The client ID.
@@ -4554,9 +4571,12 @@ var StorageConnectionService = /** @class */ (function () {
4554
4571
  return "".concat(clientId, "-").concat(storageName);
4555
4572
  }, function (clientId, storageName) {
4556
4573
  _this.sessionValidationService.addStorageUsage(clientId, storageName);
4557
- var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, callbacks = _a.callbacks;
4558
- var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
4559
- return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4574
+ var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, _b = _a.shared, shared = _b === void 0 ? false : _b, callbacks = _a.callbacks;
4575
+ if (shared) {
4576
+ return _this.getSharedStorage(clientId, storageName);
4577
+ }
4578
+ var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
4579
+ return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService }, embedding), { callbacks: callbacks }));
4560
4580
  });
4561
4581
  /**
4562
4582
  * Retrieves a list of storage data based on a search query and total number of items.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -436,6 +436,11 @@ interface IHistoryInstanceCallbacks {
436
436
  * @param clientId - The client ID.
437
437
  */
438
438
  onInit: (clientId: string) => void;
439
+ /**
440
+ * Callback to obtain history ref
441
+ * @param clientId - The client ID.
442
+ */
443
+ onRef: (history: HistoryInstance) => void;
439
444
  }
440
445
  /**
441
446
  * Interface for History Adapter
@@ -744,6 +749,10 @@ interface IStorageData {
744
749
  * @template T - Type of the storage data.
745
750
  */
746
751
  interface IStorageSchema<T extends IStorageData = IStorageData> {
752
+ /**
753
+ * All agents will share the same ClientStorage instance
754
+ */
755
+ shared?: boolean;
747
756
  /**
748
757
  * Function to get data from the storage.
749
758
  * @param clientId - The client ID.
@@ -2294,6 +2303,13 @@ declare class StorageConnectionService implements IStorage {
2294
2303
  private readonly storageSchemaService;
2295
2304
  private readonly sessionValidationService;
2296
2305
  private readonly embeddingSchemaService;
2306
+ /**
2307
+ * Retrieves a shared storage instance based on storage name.
2308
+ * @param {string} clientId - The client ID.
2309
+ * @param {string} storageName - The storage name.
2310
+ * @returns {ClientStorage} The client storage instance.
2311
+ */
2312
+ private getSharedStorage;
2297
2313
  /**
2298
2314
  * Retrieves a storage instance based on client ID and storage name.
2299
2315
  * @param {string} clientId - The client ID.