agent-swarm-kit 1.0.66 → 1.0.68
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 +40 -15
- package/build/index.mjs +40 -15
- package/package.json +1 -1
- package/types.d.ts +12 -0
package/build/index.cjs
CHANGED
|
@@ -4319,7 +4319,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4319
4319
|
return __generator(this, function (_a) {
|
|
4320
4320
|
switch (_a.label) {
|
|
4321
4321
|
case 0:
|
|
4322
|
-
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"), {
|
|
4323
4323
|
id: item.id,
|
|
4324
4324
|
});
|
|
4325
4325
|
return [4 /*yield*/, this.params.createIndex(item)];
|
|
@@ -4344,7 +4344,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4344
4344
|
return __generator(this, function (_a) {
|
|
4345
4345
|
switch (_a.label) {
|
|
4346
4346
|
case 0:
|
|
4347
|
-
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"));
|
|
4348
4348
|
if (!this.params.getData) {
|
|
4349
4349
|
return [2 /*return*/];
|
|
4350
4350
|
}
|
|
@@ -4382,7 +4382,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4382
4382
|
return __generator(this, function (_c) {
|
|
4383
4383
|
switch (_c.label) {
|
|
4384
4384
|
case 0:
|
|
4385
|
-
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"), {
|
|
4386
4386
|
search: search,
|
|
4387
4387
|
total: total,
|
|
4388
4388
|
});
|
|
@@ -4416,7 +4416,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4416
4416
|
})))];
|
|
4417
4417
|
case 2:
|
|
4418
4418
|
_c.sent();
|
|
4419
|
-
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"), {
|
|
4420
4420
|
indexed: indexed.getEntries(),
|
|
4421
4421
|
});
|
|
4422
4422
|
if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onSearch) {
|
|
@@ -4437,7 +4437,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4437
4437
|
return __generator(this, function (_c) {
|
|
4438
4438
|
switch (_c.label) {
|
|
4439
4439
|
case 0:
|
|
4440
|
-
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"), {
|
|
4441
4441
|
item: item,
|
|
4442
4442
|
});
|
|
4443
4443
|
this._itemMap.set(item.id, item);
|
|
@@ -4460,7 +4460,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4460
4460
|
this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
4461
4461
|
var _a, _b;
|
|
4462
4462
|
return __generator(this, function (_c) {
|
|
4463
|
-
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"), {
|
|
4464
4464
|
id: itemId,
|
|
4465
4465
|
});
|
|
4466
4466
|
this._itemMap.delete(itemId);
|
|
@@ -4477,7 +4477,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4477
4477
|
*/
|
|
4478
4478
|
this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4479
4479
|
return __generator(this, function (_a) {
|
|
4480
|
-
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"));
|
|
4481
4481
|
this._itemMap.clear();
|
|
4482
4482
|
this._createEmbedding.clear();
|
|
4483
4483
|
return [2 /*return*/];
|
|
@@ -4491,7 +4491,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4491
4491
|
this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
4492
4492
|
var _a;
|
|
4493
4493
|
return __generator(this, function (_b) {
|
|
4494
|
-
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"), {
|
|
4495
4495
|
id: itemId,
|
|
4496
4496
|
});
|
|
4497
4497
|
return [2 /*return*/, (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null];
|
|
@@ -4506,7 +4506,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4506
4506
|
var result, _a, _b, item;
|
|
4507
4507
|
var e_1, _c;
|
|
4508
4508
|
return __generator(this, function (_d) {
|
|
4509
|
-
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"));
|
|
4510
4510
|
if (!filter) {
|
|
4511
4511
|
return [2 /*return*/, __spreadArray([], __read(this._itemMap.values()), false)];
|
|
4512
4512
|
}
|
|
@@ -4529,7 +4529,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4529
4529
|
return [2 /*return*/, result];
|
|
4530
4530
|
});
|
|
4531
4531
|
}); };
|
|
4532
|
-
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"), {
|
|
4533
4533
|
params: params,
|
|
4534
4534
|
});
|
|
4535
4535
|
}
|
|
@@ -4548,6 +4548,23 @@ var StorageConnectionService = /** @class */ (function () {
|
|
|
4548
4548
|
this.storageSchemaService = inject(TYPES.storageSchemaService);
|
|
4549
4549
|
this.sessionValidationService = inject(TYPES.sessionValidationService);
|
|
4550
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
|
+
if (!shared) {
|
|
4564
|
+
throw new Error("agent-swarm storage not shared storageName=".concat(storageName));
|
|
4565
|
+
}
|
|
4566
|
+
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 }));
|
|
4567
|
+
});
|
|
4551
4568
|
/**
|
|
4552
4569
|
* Retrieves a storage instance based on client ID and storage name.
|
|
4553
4570
|
* @param {string} clientId - The client ID.
|
|
@@ -4559,9 +4576,12 @@ var StorageConnectionService = /** @class */ (function () {
|
|
|
4559
4576
|
return "".concat(clientId, "-").concat(storageName);
|
|
4560
4577
|
}, function (clientId, storageName) {
|
|
4561
4578
|
_this.sessionValidationService.addStorageUsage(clientId, storageName);
|
|
4562
|
-
var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, callbacks = _a.callbacks;
|
|
4563
|
-
|
|
4564
|
-
|
|
4579
|
+
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;
|
|
4580
|
+
if (shared) {
|
|
4581
|
+
return _this.getSharedStorage(clientId, storageName);
|
|
4582
|
+
}
|
|
4583
|
+
var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
|
|
4584
|
+
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 }));
|
|
4565
4585
|
});
|
|
4566
4586
|
/**
|
|
4567
4587
|
* Retrieves a list of storage data based on a search query and total number of items.
|
|
@@ -5221,11 +5241,16 @@ var addEmbedding = function (embeddingSchema) {
|
|
|
5221
5241
|
* @returns {string} The name of the added storage.
|
|
5222
5242
|
*/
|
|
5223
5243
|
var addStorage = function (storageSchema) {
|
|
5224
|
-
swarm.loggerService.log(
|
|
5225
|
-
storageSchema: storageSchema
|
|
5244
|
+
swarm.loggerService.log("function addStorage", {
|
|
5245
|
+
storageSchema: storageSchema,
|
|
5226
5246
|
});
|
|
5227
5247
|
swarm.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
|
|
5228
5248
|
swarm.storageSchemaService.register(storageSchema.storageName, storageSchema);
|
|
5249
|
+
if (storageSchema.shared) {
|
|
5250
|
+
swarm.storageConnectionService
|
|
5251
|
+
.getSharedStorage("shared", storageSchema.storageName)
|
|
5252
|
+
.waitForInit();
|
|
5253
|
+
}
|
|
5229
5254
|
return storageSchema.storageName;
|
|
5230
5255
|
};
|
|
5231
5256
|
|
package/build/index.mjs
CHANGED
|
@@ -4317,7 +4317,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4317
4317
|
return __generator(this, function (_a) {
|
|
4318
4318
|
switch (_a.label) {
|
|
4319
4319
|
case 0:
|
|
4320
|
-
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"), {
|
|
4321
4321
|
id: item.id,
|
|
4322
4322
|
});
|
|
4323
4323
|
return [4 /*yield*/, this.params.createIndex(item)];
|
|
@@ -4342,7 +4342,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4342
4342
|
return __generator(this, function (_a) {
|
|
4343
4343
|
switch (_a.label) {
|
|
4344
4344
|
case 0:
|
|
4345
|
-
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"));
|
|
4346
4346
|
if (!this.params.getData) {
|
|
4347
4347
|
return [2 /*return*/];
|
|
4348
4348
|
}
|
|
@@ -4380,7 +4380,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4380
4380
|
return __generator(this, function (_c) {
|
|
4381
4381
|
switch (_c.label) {
|
|
4382
4382
|
case 0:
|
|
4383
|
-
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"), {
|
|
4384
4384
|
search: search,
|
|
4385
4385
|
total: total,
|
|
4386
4386
|
});
|
|
@@ -4414,7 +4414,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4414
4414
|
})))];
|
|
4415
4415
|
case 2:
|
|
4416
4416
|
_c.sent();
|
|
4417
|
-
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"), {
|
|
4418
4418
|
indexed: indexed.getEntries(),
|
|
4419
4419
|
});
|
|
4420
4420
|
if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onSearch) {
|
|
@@ -4435,7 +4435,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4435
4435
|
return __generator(this, function (_c) {
|
|
4436
4436
|
switch (_c.label) {
|
|
4437
4437
|
case 0:
|
|
4438
|
-
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"), {
|
|
4439
4439
|
item: item,
|
|
4440
4440
|
});
|
|
4441
4441
|
this._itemMap.set(item.id, item);
|
|
@@ -4458,7 +4458,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4458
4458
|
this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
4459
4459
|
var _a, _b;
|
|
4460
4460
|
return __generator(this, function (_c) {
|
|
4461
|
-
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"), {
|
|
4462
4462
|
id: itemId,
|
|
4463
4463
|
});
|
|
4464
4464
|
this._itemMap.delete(itemId);
|
|
@@ -4475,7 +4475,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4475
4475
|
*/
|
|
4476
4476
|
this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4477
4477
|
return __generator(this, function (_a) {
|
|
4478
|
-
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"));
|
|
4479
4479
|
this._itemMap.clear();
|
|
4480
4480
|
this._createEmbedding.clear();
|
|
4481
4481
|
return [2 /*return*/];
|
|
@@ -4489,7 +4489,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4489
4489
|
this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
4490
4490
|
var _a;
|
|
4491
4491
|
return __generator(this, function (_b) {
|
|
4492
|
-
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"), {
|
|
4493
4493
|
id: itemId,
|
|
4494
4494
|
});
|
|
4495
4495
|
return [2 /*return*/, (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null];
|
|
@@ -4504,7 +4504,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4504
4504
|
var result, _a, _b, item;
|
|
4505
4505
|
var e_1, _c;
|
|
4506
4506
|
return __generator(this, function (_d) {
|
|
4507
|
-
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"));
|
|
4508
4508
|
if (!filter) {
|
|
4509
4509
|
return [2 /*return*/, __spreadArray([], __read(this._itemMap.values()), false)];
|
|
4510
4510
|
}
|
|
@@ -4527,7 +4527,7 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4527
4527
|
return [2 /*return*/, result];
|
|
4528
4528
|
});
|
|
4529
4529
|
}); };
|
|
4530
|
-
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"), {
|
|
4531
4531
|
params: params,
|
|
4532
4532
|
});
|
|
4533
4533
|
}
|
|
@@ -4546,6 +4546,23 @@ var StorageConnectionService = /** @class */ (function () {
|
|
|
4546
4546
|
this.storageSchemaService = inject(TYPES.storageSchemaService);
|
|
4547
4547
|
this.sessionValidationService = inject(TYPES.sessionValidationService);
|
|
4548
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
|
+
if (!shared) {
|
|
4562
|
+
throw new Error("agent-swarm storage not shared storageName=".concat(storageName));
|
|
4563
|
+
}
|
|
4564
|
+
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 }));
|
|
4565
|
+
});
|
|
4549
4566
|
/**
|
|
4550
4567
|
* Retrieves a storage instance based on client ID and storage name.
|
|
4551
4568
|
* @param {string} clientId - The client ID.
|
|
@@ -4557,9 +4574,12 @@ var StorageConnectionService = /** @class */ (function () {
|
|
|
4557
4574
|
return "".concat(clientId, "-").concat(storageName);
|
|
4558
4575
|
}, function (clientId, storageName) {
|
|
4559
4576
|
_this.sessionValidationService.addStorageUsage(clientId, storageName);
|
|
4560
|
-
var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, callbacks = _a.callbacks;
|
|
4561
|
-
|
|
4562
|
-
|
|
4577
|
+
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;
|
|
4578
|
+
if (shared) {
|
|
4579
|
+
return _this.getSharedStorage(clientId, storageName);
|
|
4580
|
+
}
|
|
4581
|
+
var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
|
|
4582
|
+
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 }));
|
|
4563
4583
|
});
|
|
4564
4584
|
/**
|
|
4565
4585
|
* Retrieves a list of storage data based on a search query and total number of items.
|
|
@@ -5219,11 +5239,16 @@ var addEmbedding = function (embeddingSchema) {
|
|
|
5219
5239
|
* @returns {string} The name of the added storage.
|
|
5220
5240
|
*/
|
|
5221
5241
|
var addStorage = function (storageSchema) {
|
|
5222
|
-
swarm.loggerService.log(
|
|
5223
|
-
storageSchema: storageSchema
|
|
5242
|
+
swarm.loggerService.log("function addStorage", {
|
|
5243
|
+
storageSchema: storageSchema,
|
|
5224
5244
|
});
|
|
5225
5245
|
swarm.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
|
|
5226
5246
|
swarm.storageSchemaService.register(storageSchema.storageName, storageSchema);
|
|
5247
|
+
if (storageSchema.shared) {
|
|
5248
|
+
swarm.storageConnectionService
|
|
5249
|
+
.getSharedStorage("shared", storageSchema.storageName)
|
|
5250
|
+
.waitForInit();
|
|
5251
|
+
}
|
|
5227
5252
|
return storageSchema.storageName;
|
|
5228
5253
|
};
|
|
5229
5254
|
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -749,6 +749,10 @@ interface IStorageData {
|
|
|
749
749
|
* @template T - Type of the storage data.
|
|
750
750
|
*/
|
|
751
751
|
interface IStorageSchema<T extends IStorageData = IStorageData> {
|
|
752
|
+
/**
|
|
753
|
+
* All agents will share the same ClientStorage instance
|
|
754
|
+
*/
|
|
755
|
+
shared?: boolean;
|
|
752
756
|
/**
|
|
753
757
|
* Function to get data from the storage.
|
|
754
758
|
* @param clientId - The client ID.
|
|
@@ -2299,6 +2303,13 @@ declare class StorageConnectionService implements IStorage {
|
|
|
2299
2303
|
private readonly storageSchemaService;
|
|
2300
2304
|
private readonly sessionValidationService;
|
|
2301
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
|
+
getSharedStorage: ((clientId: string, storageName: StorageName) => ClientStorage<IStorageData>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientStorage<IStorageData>>;
|
|
2302
2313
|
/**
|
|
2303
2314
|
* Retrieves a storage instance based on client ID and storage name.
|
|
2304
2315
|
* @param {string} clientId - The client ID.
|
|
@@ -2353,6 +2364,7 @@ interface IStorageConnectionService extends StorageConnectionService {
|
|
|
2353
2364
|
}
|
|
2354
2365
|
type InternalKeys = keyof {
|
|
2355
2366
|
getStorage: never;
|
|
2367
|
+
getSharedStorage: never;
|
|
2356
2368
|
};
|
|
2357
2369
|
type TStorageConnectionService = {
|
|
2358
2370
|
[key in Exclude<keyof IStorageConnectionService, InternalKeys>]: unknown;
|