agent-swarm-kit 1.0.53 → 1.0.54

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
@@ -3746,57 +3746,64 @@ var ClientStorage = /** @class */ (function () {
3746
3746
  }
3747
3747
  });
3748
3748
  }); });
3749
- this.take = function (search, total) { return __awaiter(_this, void 0, void 0, function () {
3750
- var indexed, searchEmbeddings, filtered;
3751
- var _this = this;
3752
- return __generator(this, function (_a) {
3753
- switch (_a.label) {
3754
- case 0:
3755
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
3756
- search: search,
3757
- total: total,
3758
- });
3759
- indexed = new functoolsKit.SortedArray();
3760
- return [4 /*yield*/, this.params.createEmbedding(search)];
3761
- case 1:
3762
- searchEmbeddings = _a.sent();
3763
- if (this.params.onCreate) {
3764
- this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
3765
- }
3766
- return [4 /*yield*/, Promise.all(Array.from(this._itemMap.values()).map(functoolsKit.execpool(function (item) { return __awaiter(_this, void 0, void 0, function () {
3767
- var _a, targetEmbeddings, index, score;
3768
- return __generator(this, function (_b) {
3769
- switch (_b.label) {
3770
- case 0: return [4 /*yield*/, this._createEmbedding(item)];
3771
- case 1:
3772
- _a = __read.apply(void 0, [_b.sent(), 2]), targetEmbeddings = _a[0], index = _a[1];
3773
- return [4 /*yield*/, this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings)];
3774
- case 2:
3775
- score = _b.sent();
3776
- if (this.params.onCompare) {
3777
- this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
3778
- }
3779
- indexed.push({ id: item.id }, score);
3780
- return [2 /*return*/];
3781
- }
3782
- });
3783
- }); }, {
3784
- delay: 10,
3785
- maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
3786
- })))];
3787
- case 2:
3788
- _a.sent();
3789
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
3790
- indexed: indexed.getEntries(),
3791
- });
3792
- filtered = indexed.take(total, GLOBAL_CONFIG.CC_STORAGE_SEARCH_SIMILARITY);
3793
- return [2 /*return*/, filtered.map(function (_a) {
3794
- var id = _a.id;
3795
- return _this._itemMap.get(id);
3796
- })];
3797
- }
3749
+ this.take = function (search_1, total_1) {
3750
+ var args_1 = [];
3751
+ for (var _i = 2; _i < arguments.length; _i++) {
3752
+ args_1[_i - 2] = arguments[_i];
3753
+ }
3754
+ return __awaiter(_this, __spreadArray([search_1, total_1], __read(args_1), false), void 0, function (search, total, score) {
3755
+ var indexed, searchEmbeddings, filtered;
3756
+ var _this = this;
3757
+ if (score === void 0) { score = GLOBAL_CONFIG.CC_STORAGE_SEARCH_SIMILARITY; }
3758
+ return __generator(this, function (_a) {
3759
+ switch (_a.label) {
3760
+ case 0:
3761
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
3762
+ search: search,
3763
+ total: total,
3764
+ });
3765
+ indexed = new functoolsKit.SortedArray();
3766
+ return [4 /*yield*/, this.params.createEmbedding(search)];
3767
+ case 1:
3768
+ searchEmbeddings = _a.sent();
3769
+ if (this.params.onCreate) {
3770
+ this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
3771
+ }
3772
+ return [4 /*yield*/, Promise.all(Array.from(this._itemMap.values()).map(functoolsKit.execpool(function (item) { return __awaiter(_this, void 0, void 0, function () {
3773
+ var _a, targetEmbeddings, index, score;
3774
+ return __generator(this, function (_b) {
3775
+ switch (_b.label) {
3776
+ case 0: return [4 /*yield*/, this._createEmbedding(item)];
3777
+ case 1:
3778
+ _a = __read.apply(void 0, [_b.sent(), 2]), targetEmbeddings = _a[0], index = _a[1];
3779
+ return [4 /*yield*/, this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings)];
3780
+ case 2:
3781
+ score = _b.sent();
3782
+ if (this.params.onCompare) {
3783
+ this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
3784
+ }
3785
+ indexed.push({ id: item.id }, score);
3786
+ return [2 /*return*/];
3787
+ }
3788
+ });
3789
+ }); }, {
3790
+ delay: 10,
3791
+ maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
3792
+ })))];
3793
+ case 2:
3794
+ _a.sent();
3795
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
3796
+ indexed: indexed.getEntries(),
3797
+ });
3798
+ filtered = indexed.take(total, score);
3799
+ return [2 /*return*/, filtered.map(function (_a) {
3800
+ var id = _a.id;
3801
+ return _this._itemMap.get(id);
3802
+ })];
3803
+ }
3804
+ });
3798
3805
  });
3799
- }); };
3806
+ };
3800
3807
  this.upsert = function (item) { return __awaiter(_this, void 0, void 0, function () {
3801
3808
  var _a, _b;
3802
3809
  return __generator(this, function (_c) {
@@ -3913,7 +3920,7 @@ var StorageConnectionService = /** @class */ (function () {
3913
3920
  * @param {number} total - The total number of items to retrieve.
3914
3921
  * @returns {Promise<IStorageData[]>} The list of storage data.
3915
3922
  */
3916
- this.take = function (search, total) { return __awaiter(_this, void 0, void 0, function () {
3923
+ this.take = function (search, total, score) { return __awaiter(_this, void 0, void 0, function () {
3917
3924
  var storage;
3918
3925
  return __generator(this, function (_a) {
3919
3926
  switch (_a.label) {
@@ -3922,12 +3929,13 @@ var StorageConnectionService = /** @class */ (function () {
3922
3929
  context: this.contextService.context,
3923
3930
  search: search,
3924
3931
  total: total,
3932
+ score: score,
3925
3933
  });
3926
3934
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
3927
3935
  return [4 /*yield*/, storage.waitForInit()];
3928
3936
  case 1:
3929
3937
  _a.sent();
3930
- return [4 /*yield*/, storage.take(search, total)];
3938
+ return [4 /*yield*/, storage.take(search, total, score)];
3931
3939
  case 2: return [2 /*return*/, _a.sent()];
3932
3940
  }
3933
3941
  });
@@ -4080,7 +4088,7 @@ var StoragePublicService = /** @class */ (function () {
4080
4088
  * @param {number} total - The total number of items to retrieve.
4081
4089
  * @returns {Promise<IStorageData[]>} The list of storage data.
4082
4090
  */
4083
- this.take = function (search, total, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
4091
+ this.take = function (search, total, clientId, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
4084
4092
  var _this = this;
4085
4093
  return __generator(this, function (_a) {
4086
4094
  switch (_a.label) {
@@ -4090,11 +4098,12 @@ var StoragePublicService = /** @class */ (function () {
4090
4098
  total: total,
4091
4099
  clientId: clientId,
4092
4100
  storageName: storageName,
4101
+ score: score,
4093
4102
  });
4094
4103
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4095
4104
  return __generator(this, function (_a) {
4096
4105
  switch (_a.label) {
4097
- case 0: return [4 /*yield*/, this.storageConnectionService.take(search, total)];
4106
+ case 0: return [4 /*yield*/, this.storageConnectionService.take(search, total, score)];
4098
4107
  case 1: return [2 /*return*/, _a.sent()];
4099
4108
  }
4100
4109
  });
@@ -5756,7 +5765,7 @@ var StorageUtils = /** @class */ (function () {
5756
5765
  * @returns {Promise<T[]>} - A promise that resolves to an array of items.
5757
5766
  * @template T
5758
5767
  */
5759
- this.take = function (search, total, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
5768
+ this.take = function (search, total, clientId, agentName, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
5760
5769
  return __generator(this, function (_a) {
5761
5770
  switch (_a.label) {
5762
5771
  case 0:
@@ -5765,12 +5774,13 @@ var StorageUtils = /** @class */ (function () {
5765
5774
  total: total,
5766
5775
  clientId: clientId,
5767
5776
  storageName: storageName,
5777
+ score: score,
5768
5778
  });
5769
5779
  swarm.storageValidationService.validate(storageName, "StorageStatic");
5770
5780
  if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
5771
5781
  throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (take)"));
5772
5782
  }
5773
- return [4 /*yield*/, swarm.storagePublicService.take(search, total, clientId, storageName)];
5783
+ return [4 /*yield*/, swarm.storagePublicService.take(search, total, clientId, storageName, score)];
5774
5784
  case 1: return [2 /*return*/, (_a.sent())];
5775
5785
  }
5776
5786
  });
package/build/index.mjs CHANGED
@@ -3744,57 +3744,64 @@ var ClientStorage = /** @class */ (function () {
3744
3744
  }
3745
3745
  });
3746
3746
  }); });
3747
- this.take = function (search, total) { return __awaiter(_this, void 0, void 0, function () {
3748
- var indexed, searchEmbeddings, filtered;
3749
- var _this = this;
3750
- return __generator(this, function (_a) {
3751
- switch (_a.label) {
3752
- case 0:
3753
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
3754
- search: search,
3755
- total: total,
3756
- });
3757
- indexed = new SortedArray();
3758
- return [4 /*yield*/, this.params.createEmbedding(search)];
3759
- case 1:
3760
- searchEmbeddings = _a.sent();
3761
- if (this.params.onCreate) {
3762
- this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
3763
- }
3764
- return [4 /*yield*/, Promise.all(Array.from(this._itemMap.values()).map(execpool(function (item) { return __awaiter(_this, void 0, void 0, function () {
3765
- var _a, targetEmbeddings, index, score;
3766
- return __generator(this, function (_b) {
3767
- switch (_b.label) {
3768
- case 0: return [4 /*yield*/, this._createEmbedding(item)];
3769
- case 1:
3770
- _a = __read.apply(void 0, [_b.sent(), 2]), targetEmbeddings = _a[0], index = _a[1];
3771
- return [4 /*yield*/, this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings)];
3772
- case 2:
3773
- score = _b.sent();
3774
- if (this.params.onCompare) {
3775
- this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
3776
- }
3777
- indexed.push({ id: item.id }, score);
3778
- return [2 /*return*/];
3779
- }
3780
- });
3781
- }); }, {
3782
- delay: 10,
3783
- maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
3784
- })))];
3785
- case 2:
3786
- _a.sent();
3787
- this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
3788
- indexed: indexed.getEntries(),
3789
- });
3790
- filtered = indexed.take(total, GLOBAL_CONFIG.CC_STORAGE_SEARCH_SIMILARITY);
3791
- return [2 /*return*/, filtered.map(function (_a) {
3792
- var id = _a.id;
3793
- return _this._itemMap.get(id);
3794
- })];
3795
- }
3747
+ this.take = function (search_1, total_1) {
3748
+ var args_1 = [];
3749
+ for (var _i = 2; _i < arguments.length; _i++) {
3750
+ args_1[_i - 2] = arguments[_i];
3751
+ }
3752
+ return __awaiter(_this, __spreadArray([search_1, total_1], __read(args_1), false), void 0, function (search, total, score) {
3753
+ var indexed, searchEmbeddings, filtered;
3754
+ var _this = this;
3755
+ if (score === void 0) { score = GLOBAL_CONFIG.CC_STORAGE_SEARCH_SIMILARITY; }
3756
+ return __generator(this, function (_a) {
3757
+ switch (_a.label) {
3758
+ case 0:
3759
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take"), {
3760
+ search: search,
3761
+ total: total,
3762
+ });
3763
+ indexed = new SortedArray();
3764
+ return [4 /*yield*/, this.params.createEmbedding(search)];
3765
+ case 1:
3766
+ searchEmbeddings = _a.sent();
3767
+ if (this.params.onCreate) {
3768
+ this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
3769
+ }
3770
+ return [4 /*yield*/, Promise.all(Array.from(this._itemMap.values()).map(execpool(function (item) { return __awaiter(_this, void 0, void 0, function () {
3771
+ var _a, targetEmbeddings, index, score;
3772
+ return __generator(this, function (_b) {
3773
+ switch (_b.label) {
3774
+ case 0: return [4 /*yield*/, this._createEmbedding(item)];
3775
+ case 1:
3776
+ _a = __read.apply(void 0, [_b.sent(), 2]), targetEmbeddings = _a[0], index = _a[1];
3777
+ return [4 /*yield*/, this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings)];
3778
+ case 2:
3779
+ score = _b.sent();
3780
+ if (this.params.onCompare) {
3781
+ this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
3782
+ }
3783
+ indexed.push({ id: item.id }, score);
3784
+ return [2 /*return*/];
3785
+ }
3786
+ });
3787
+ }); }, {
3788
+ delay: 10,
3789
+ maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
3790
+ })))];
3791
+ case 2:
3792
+ _a.sent();
3793
+ this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take indexed"), {
3794
+ indexed: indexed.getEntries(),
3795
+ });
3796
+ filtered = indexed.take(total, score);
3797
+ return [2 /*return*/, filtered.map(function (_a) {
3798
+ var id = _a.id;
3799
+ return _this._itemMap.get(id);
3800
+ })];
3801
+ }
3802
+ });
3796
3803
  });
3797
- }); };
3804
+ };
3798
3805
  this.upsert = function (item) { return __awaiter(_this, void 0, void 0, function () {
3799
3806
  var _a, _b;
3800
3807
  return __generator(this, function (_c) {
@@ -3911,7 +3918,7 @@ var StorageConnectionService = /** @class */ (function () {
3911
3918
  * @param {number} total - The total number of items to retrieve.
3912
3919
  * @returns {Promise<IStorageData[]>} The list of storage data.
3913
3920
  */
3914
- this.take = function (search, total) { return __awaiter(_this, void 0, void 0, function () {
3921
+ this.take = function (search, total, score) { return __awaiter(_this, void 0, void 0, function () {
3915
3922
  var storage;
3916
3923
  return __generator(this, function (_a) {
3917
3924
  switch (_a.label) {
@@ -3920,12 +3927,13 @@ var StorageConnectionService = /** @class */ (function () {
3920
3927
  context: this.contextService.context,
3921
3928
  search: search,
3922
3929
  total: total,
3930
+ score: score,
3923
3931
  });
3924
3932
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
3925
3933
  return [4 /*yield*/, storage.waitForInit()];
3926
3934
  case 1:
3927
3935
  _a.sent();
3928
- return [4 /*yield*/, storage.take(search, total)];
3936
+ return [4 /*yield*/, storage.take(search, total, score)];
3929
3937
  case 2: return [2 /*return*/, _a.sent()];
3930
3938
  }
3931
3939
  });
@@ -4078,7 +4086,7 @@ var StoragePublicService = /** @class */ (function () {
4078
4086
  * @param {number} total - The total number of items to retrieve.
4079
4087
  * @returns {Promise<IStorageData[]>} The list of storage data.
4080
4088
  */
4081
- this.take = function (search, total, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
4089
+ this.take = function (search, total, clientId, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
4082
4090
  var _this = this;
4083
4091
  return __generator(this, function (_a) {
4084
4092
  switch (_a.label) {
@@ -4088,11 +4096,12 @@ var StoragePublicService = /** @class */ (function () {
4088
4096
  total: total,
4089
4097
  clientId: clientId,
4090
4098
  storageName: storageName,
4099
+ score: score,
4091
4100
  });
4092
4101
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4093
4102
  return __generator(this, function (_a) {
4094
4103
  switch (_a.label) {
4095
- case 0: return [4 /*yield*/, this.storageConnectionService.take(search, total)];
4104
+ case 0: return [4 /*yield*/, this.storageConnectionService.take(search, total, score)];
4096
4105
  case 1: return [2 /*return*/, _a.sent()];
4097
4106
  }
4098
4107
  });
@@ -5754,7 +5763,7 @@ var StorageUtils = /** @class */ (function () {
5754
5763
  * @returns {Promise<T[]>} - A promise that resolves to an array of items.
5755
5764
  * @template T
5756
5765
  */
5757
- this.take = function (search, total, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
5766
+ this.take = function (search, total, clientId, agentName, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
5758
5767
  return __generator(this, function (_a) {
5759
5768
  switch (_a.label) {
5760
5769
  case 0:
@@ -5763,12 +5772,13 @@ var StorageUtils = /** @class */ (function () {
5763
5772
  total: total,
5764
5773
  clientId: clientId,
5765
5774
  storageName: storageName,
5775
+ score: score,
5766
5776
  });
5767
5777
  swarm.storageValidationService.validate(storageName, "StorageStatic");
5768
5778
  if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
5769
5779
  throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (take)"));
5770
5780
  }
5771
- return [4 /*yield*/, swarm.storagePublicService.take(search, total, clientId, storageName)];
5781
+ return [4 /*yield*/, swarm.storagePublicService.take(search, total, clientId, storageName, score)];
5772
5782
  case 1: return [2 /*return*/, (_a.sent())];
5773
5783
  }
5774
5784
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
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
@@ -510,7 +510,7 @@ interface IStorageData {
510
510
  }
511
511
  interface IStorageSchema<T extends IStorageData = IStorageData> {
512
512
  getData?: (clientId: string, storageName: StorageName) => Promise<T[]> | T[];
513
- createIndex(item: T): Promise<string>;
513
+ createIndex(item: T): Promise<string> | string;
514
514
  embedding: EmbeddingName;
515
515
  storageName: StorageName;
516
516
  callbacks?: Partial<IStorageCallbacks<T>>;
@@ -526,7 +526,7 @@ interface IStorageParams<T extends IStorageData = IStorageData> extends IStorage
526
526
  logger: ILogger;
527
527
  }
528
528
  interface IStorage<T extends IStorageData = IStorageData> {
529
- take(search: string, total: number): Promise<T[]>;
529
+ take(search: string, total: number, score?: number): Promise<T[]>;
530
530
  upsert(item: T): Promise<void>;
531
531
  remove(itemId: IStorageData["id"]): Promise<void>;
532
532
  get(itemId: IStorageData["id"]): Promise<T | null>;
@@ -1861,7 +1861,7 @@ declare class ClientStorage<T extends IStorageData = IStorageData> implements IS
1861
1861
  constructor(params: IStorageParams<T>);
1862
1862
  _createEmbedding: ((item: T) => Promise<readonly [Embeddings, string]>) & functools_kit.IClearableMemoize<string | number> & functools_kit.IControlMemoize<string | number, Promise<readonly [Embeddings, string]>>;
1863
1863
  waitForInit: (() => Promise<void>) & functools_kit.ISingleshotClearable;
1864
- take: (search: string, total: number) => Promise<T[]>;
1864
+ take: (search: string, total: number, score?: number) => Promise<T[]>;
1865
1865
  upsert: (item: T) => Promise<void>;
1866
1866
  remove: (itemId: IStorageData["id"]) => Promise<void>;
1867
1867
  clear: () => Promise<void>;
@@ -1891,7 +1891,7 @@ declare class StorageConnectionService implements IStorage {
1891
1891
  * @param {number} total - The total number of items to retrieve.
1892
1892
  * @returns {Promise<IStorageData[]>} The list of storage data.
1893
1893
  */
1894
- take: (search: string, total: number) => Promise<IStorageData[]>;
1894
+ take: (search: string, total: number, score?: number) => Promise<IStorageData[]>;
1895
1895
  /**
1896
1896
  * Upserts an item in the storage.
1897
1897
  * @param {IStorageData} item - The item to upsert.
@@ -1948,7 +1948,7 @@ declare class StoragePublicService implements TStorageConnectionService {
1948
1948
  * @param {number} total - The total number of items to retrieve.
1949
1949
  * @returns {Promise<IStorageData[]>} The list of storage data.
1950
1950
  */
1951
- take: (search: string, total: number, clientId: string, storageName: StorageName) => Promise<IStorageData[]>;
1951
+ take: (search: string, total: number, clientId: string, storageName: StorageName, score?: number) => Promise<IStorageData[]>;
1952
1952
  /**
1953
1953
  * Upserts an item in the storage.
1954
1954
  * @param {IStorageData} item - The item to upsert.
@@ -2497,7 +2497,7 @@ declare class StorageUtils implements TStorage {
2497
2497
  * @returns {Promise<T[]>} - A promise that resolves to an array of items.
2498
2498
  * @template T
2499
2499
  */
2500
- take: <T extends IStorageData = IStorageData>(search: string, total: number, clientId: string, agentName: AgentName, storageName: StorageName) => Promise<T[]>;
2500
+ take: <T extends IStorageData = IStorageData>(search: string, total: number, clientId: string, agentName: AgentName, storageName: StorageName, score?: number) => Promise<T[]>;
2501
2501
  /**
2502
2502
  * Upserts an item in the storage.
2503
2503
  * @param {T} item - The item to upsert.