agent-swarm-kit 1.0.50 → 1.0.52
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 +1255 -127
- package/build/index.mjs +1254 -129
- package/package.json +2 -2
- package/types.d.ts +387 -13
package/build/index.cjs
CHANGED
|
@@ -218,18 +218,22 @@ var connectionServices$1 = {
|
|
|
218
218
|
historyConnectionService: Symbol('historyConnectionService'),
|
|
219
219
|
swarmConnectionService: Symbol('swarmConnectionService'),
|
|
220
220
|
sessionConnectionService: Symbol('sessionConnectionService'),
|
|
221
|
+
storageConnectionService: Symbol('storageConnectionService'),
|
|
221
222
|
};
|
|
222
|
-
var
|
|
223
|
+
var schemaServices$1 = {
|
|
223
224
|
completionSchemaService: Symbol('completionSchemaService'),
|
|
224
225
|
agentSchemaService: Symbol('agentSchemaService'),
|
|
225
226
|
swarmSchemaService: Symbol('swarmSchemaService'),
|
|
226
227
|
toolSchemaService: Symbol('toolSchemaService'),
|
|
228
|
+
embeddingSchemaService: Symbol('embeddingSchemaService'),
|
|
229
|
+
storageSchemaService: Symbol('storageSchemaService'),
|
|
227
230
|
};
|
|
228
231
|
var publicServices$1 = {
|
|
229
232
|
agentPublicService: Symbol('agentPublicService'),
|
|
230
233
|
historyPublicService: Symbol('historyPublicService'),
|
|
231
234
|
sessionPublicService: Symbol('sessionPublicService'),
|
|
232
235
|
swarmPublicService: Symbol('swarmPublicService'),
|
|
236
|
+
storagePublicService: Symbol('storagePublicService'),
|
|
233
237
|
};
|
|
234
238
|
var validationServices$1 = {
|
|
235
239
|
agentValidationService: Symbol('agentValidationService'),
|
|
@@ -237,8 +241,10 @@ var validationServices$1 = {
|
|
|
237
241
|
sessionValidationService: Symbol('sessionValidationService'),
|
|
238
242
|
swarmValidationService: Symbol('swarmValidationService'),
|
|
239
243
|
completionValidationService: Symbol('completionValidationService'),
|
|
244
|
+
embeddingValidationService: Symbol('embeddingValidationService'),
|
|
245
|
+
storageValidationService: Symbol('storageValidationService'),
|
|
240
246
|
};
|
|
241
|
-
var TYPES = __assign(__assign(__assign(__assign(__assign({}, baseServices$1),
|
|
247
|
+
var TYPES = __assign(__assign(__assign(__assign(__assign({}, baseServices$1), schemaServices$1), connectionServices$1), publicServices$1), validationServices$1);
|
|
242
248
|
|
|
243
249
|
/**
|
|
244
250
|
* Service for managing agent schemas.
|
|
@@ -430,6 +436,8 @@ var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdap
|
|
|
430
436
|
var CC_AGENT_OUTPUT_MAP = function (message) { return message; };
|
|
431
437
|
var CC_AGENT_SEPARATE_HISTORY = false;
|
|
432
438
|
var CC_AGENT_SYSTEM_PROMPT = undefined;
|
|
439
|
+
var CC_STORAGE_SEARCH_SIMILARITY = 0.65;
|
|
440
|
+
var CC_STORAGE_SEARCH_POOL = 5;
|
|
433
441
|
var GLOBAL_CONFIG = {
|
|
434
442
|
CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
435
443
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
@@ -445,6 +453,8 @@ var GLOBAL_CONFIG = {
|
|
|
445
453
|
CC_AGENT_SEPARATE_HISTORY: CC_AGENT_SEPARATE_HISTORY,
|
|
446
454
|
CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
|
|
447
455
|
CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
|
|
456
|
+
CC_STORAGE_SEARCH_SIMILARITY: CC_STORAGE_SEARCH_SIMILARITY,
|
|
457
|
+
CC_STORAGE_SEARCH_POOL: CC_STORAGE_SEARCH_POOL,
|
|
448
458
|
};
|
|
449
459
|
var setConfig = function (config) {
|
|
450
460
|
Object.assign(GLOBAL_CONFIG, config);
|
|
@@ -465,6 +475,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
465
475
|
function ClientAgent(params) {
|
|
466
476
|
var _this = this;
|
|
467
477
|
this.params = params;
|
|
478
|
+
this._toolErrorSubject = new functoolsKit.Subject();
|
|
468
479
|
this._toolCommitSubject = new functoolsKit.Subject();
|
|
469
480
|
this._outputSubject = new functoolsKit.Subject();
|
|
470
481
|
/**
|
|
@@ -810,14 +821,22 @@ var ClientAgent = /** @class */ (function () {
|
|
|
810
821
|
params: tool.function.arguments,
|
|
811
822
|
isLast: idx === toolCalls.length - 1,
|
|
812
823
|
toolCalls: toolCalls,
|
|
813
|
-
}))
|
|
824
|
+
}))
|
|
825
|
+
.then(function () {
|
|
814
826
|
var _a, _b;
|
|
815
827
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
816
828
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
|
|
829
|
+
})
|
|
830
|
+
.catch(function (error) {
|
|
831
|
+
var _a, _b;
|
|
832
|
+
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onCallError) &&
|
|
833
|
+
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onCallError(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments, error));
|
|
834
|
+
_this._toolErrorSubject.next();
|
|
817
835
|
});
|
|
818
836
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
|
|
819
837
|
return [4 /*yield*/, Promise.race([
|
|
820
838
|
this_1._toolCommitSubject.toPromise(),
|
|
839
|
+
this_1._toolErrorSubject.toPromise(),
|
|
821
840
|
this_1._outputSubject.toPromise(),
|
|
822
841
|
])];
|
|
823
842
|
case 8:
|
|
@@ -1037,16 +1056,21 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
1037
1056
|
* @returns {Promise<void>} The dispose result.
|
|
1038
1057
|
*/
|
|
1039
1058
|
this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1059
|
+
var key;
|
|
1040
1060
|
return __generator(this, function (_a) {
|
|
1041
1061
|
switch (_a.label) {
|
|
1042
1062
|
case 0:
|
|
1043
1063
|
this.loggerService.log("agentConnectionService dispose", {
|
|
1044
1064
|
context: this.contextService.context,
|
|
1045
1065
|
});
|
|
1066
|
+
key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName);
|
|
1067
|
+
if (!this.getAgent.has(key)) {
|
|
1068
|
+
return [2 /*return*/];
|
|
1069
|
+
}
|
|
1046
1070
|
return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).dispose()];
|
|
1047
1071
|
case 1:
|
|
1048
1072
|
_a.sent();
|
|
1049
|
-
this.getAgent.clear(
|
|
1073
|
+
this.getAgent.clear(key);
|
|
1050
1074
|
this.sessionValidationService.removeAgentUsage(this.contextService.context.clientId, this.contextService.context.agentName);
|
|
1051
1075
|
return [2 /*return*/];
|
|
1052
1076
|
}
|
|
@@ -1141,7 +1165,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1141
1165
|
* @returns {Promise<IModelMessage[]>} - The array of messages for the agent.
|
|
1142
1166
|
*/
|
|
1143
1167
|
this.toArrayForAgent = function (prompt, system) { return __awaiter(_this, void 0, void 0, function () {
|
|
1144
|
-
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, assistantToolCallSet, assistantMessages, promptMessages;
|
|
1168
|
+
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, assistantToolOutputCallSet, assistantRawMessages, assistantToolCallSet, assistantMessages, promptMessages;
|
|
1145
1169
|
var _this = this;
|
|
1146
1170
|
var _d, e_2, _e, _f;
|
|
1147
1171
|
var _g;
|
|
@@ -1208,22 +1232,41 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1208
1232
|
commonMessages = commonMessagesRaw
|
|
1209
1233
|
.filter(this._filterCondition)
|
|
1210
1234
|
.slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
|
|
1211
|
-
|
|
1235
|
+
assistantToolOutputCallSet = new Set(commonMessages.map(function (_a) {
|
|
1212
1236
|
var tool_call_id = _a.tool_call_id;
|
|
1213
1237
|
return tool_call_id;
|
|
1214
1238
|
}));
|
|
1215
|
-
|
|
1239
|
+
assistantRawMessages = commonMessages
|
|
1216
1240
|
.map(function (_a) {
|
|
1217
1241
|
var tool_calls = _a.tool_calls, message = __rest(_a, ["tool_calls"]);
|
|
1218
1242
|
return (__assign(__assign({}, message), { tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.filter(function (_a) {
|
|
1219
1243
|
var id = _a.id;
|
|
1220
|
-
return
|
|
1244
|
+
return assistantToolOutputCallSet.has(id);
|
|
1221
1245
|
}) }));
|
|
1222
1246
|
})
|
|
1223
1247
|
.filter(function (_a) {
|
|
1224
1248
|
var content = _a.content, tool_calls = _a.tool_calls;
|
|
1225
1249
|
return !!content || !!(tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.length);
|
|
1226
1250
|
});
|
|
1251
|
+
assistantToolCallSet = new Set(assistantRawMessages
|
|
1252
|
+
.filter(function (_a) {
|
|
1253
|
+
var role = _a.role;
|
|
1254
|
+
return role === "tool";
|
|
1255
|
+
})
|
|
1256
|
+
.flatMap(function (_a) {
|
|
1257
|
+
var tool_calls = _a.tool_calls;
|
|
1258
|
+
return tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.map(function (_a) {
|
|
1259
|
+
var id = _a.id;
|
|
1260
|
+
return id;
|
|
1261
|
+
});
|
|
1262
|
+
}));
|
|
1263
|
+
assistantMessages = assistantRawMessages.filter(function (_a) {
|
|
1264
|
+
var role = _a.role, tool_call_id = _a.tool_call_id;
|
|
1265
|
+
if (role === "tool") {
|
|
1266
|
+
return assistantToolCallSet.has(tool_call_id);
|
|
1267
|
+
}
|
|
1268
|
+
return true;
|
|
1269
|
+
});
|
|
1227
1270
|
promptMessages = [];
|
|
1228
1271
|
{
|
|
1229
1272
|
promptMessages.push({
|
|
@@ -1356,12 +1399,17 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
1356
1399
|
* @returns {Promise<void>} A promise that resolves when the service is disposed.
|
|
1357
1400
|
*/
|
|
1358
1401
|
this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1402
|
+
var key;
|
|
1359
1403
|
return __generator(this, function (_a) {
|
|
1360
1404
|
switch (_a.label) {
|
|
1361
1405
|
case 0:
|
|
1362
1406
|
this.loggerService.log("historyConnectionService dispose", {
|
|
1363
1407
|
context: this.contextService.context,
|
|
1364
1408
|
});
|
|
1409
|
+
key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName);
|
|
1410
|
+
if (!this.getHistory.has(key)) {
|
|
1411
|
+
return [2 /*return*/];
|
|
1412
|
+
}
|
|
1365
1413
|
if (!GLOBAL_CONFIG.CC_AGENT_SEPARATE_HISTORY) return [3 /*break*/, 2];
|
|
1366
1414
|
return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
|
|
1367
1415
|
case 1:
|
|
@@ -1369,7 +1417,7 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
1369
1417
|
this.getItems.clear(this.contextService.context.clientId);
|
|
1370
1418
|
_a.label = 2;
|
|
1371
1419
|
case 2:
|
|
1372
|
-
this.getHistory.clear(
|
|
1420
|
+
this.getHistory.clear(key);
|
|
1373
1421
|
this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
|
|
1374
1422
|
return [2 /*return*/];
|
|
1375
1423
|
}
|
|
@@ -1628,6 +1676,7 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1628
1676
|
});
|
|
1629
1677
|
});
|
|
1630
1678
|
},
|
|
1679
|
+
callbacks: callbacks,
|
|
1631
1680
|
});
|
|
1632
1681
|
});
|
|
1633
1682
|
/**
|
|
@@ -1719,11 +1768,16 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1719
1768
|
* @returns {Promise<void>}
|
|
1720
1769
|
*/
|
|
1721
1770
|
this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1771
|
+
var key;
|
|
1722
1772
|
return __generator(this, function (_a) {
|
|
1723
1773
|
this.loggerService.log("swarmConnectionService dispose", {
|
|
1724
1774
|
context: this.contextService.context,
|
|
1725
1775
|
});
|
|
1726
|
-
|
|
1776
|
+
key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.swarmName);
|
|
1777
|
+
if (!this.getSwarm.has(key)) {
|
|
1778
|
+
return [2 /*return*/];
|
|
1779
|
+
}
|
|
1780
|
+
this.getSwarm.clear(key);
|
|
1727
1781
|
return [2 /*return*/];
|
|
1728
1782
|
});
|
|
1729
1783
|
}); };
|
|
@@ -1771,7 +1825,7 @@ var CompletionSchemaService = /** @class */ (function () {
|
|
|
1771
1825
|
this.registry = new functoolsKit.ToolRegistry("completionSchemaService");
|
|
1772
1826
|
/**
|
|
1773
1827
|
* Registers a new completion schema.
|
|
1774
|
-
* @param {
|
|
1828
|
+
* @param {CompletionName} key - The key for the schema.
|
|
1775
1829
|
* @param {ICompletionSchema} value - The schema to register.
|
|
1776
1830
|
*/
|
|
1777
1831
|
this.register = function (key, value) {
|
|
@@ -1780,7 +1834,7 @@ var CompletionSchemaService = /** @class */ (function () {
|
|
|
1780
1834
|
};
|
|
1781
1835
|
/**
|
|
1782
1836
|
* Retrieves a completion schema by key.
|
|
1783
|
-
* @param {
|
|
1837
|
+
* @param {CompletionName} key - The key of the schema to retrieve.
|
|
1784
1838
|
* @returns {ICompletionSchema} The retrieved schema.
|
|
1785
1839
|
*/
|
|
1786
1840
|
this.get = function (key) {
|
|
@@ -2155,16 +2209,21 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
2155
2209
|
* @returns {Promise<void>} A promise that resolves when the service is disposed.
|
|
2156
2210
|
*/
|
|
2157
2211
|
this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2212
|
+
var key;
|
|
2158
2213
|
return __generator(this, function (_a) {
|
|
2159
2214
|
switch (_a.label) {
|
|
2160
2215
|
case 0:
|
|
2161
2216
|
this.loggerService.log("sessionConnectionService dispose", {
|
|
2162
2217
|
context: this.contextService.context,
|
|
2163
2218
|
});
|
|
2219
|
+
key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.swarmName);
|
|
2220
|
+
if (!this.getSession.has(key)) {
|
|
2221
|
+
return [2 /*return*/];
|
|
2222
|
+
}
|
|
2164
2223
|
return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).dispose()];
|
|
2165
2224
|
case 1:
|
|
2166
2225
|
_a.sent();
|
|
2167
|
-
this.getSession.clear(
|
|
2226
|
+
this.getSession.clear(key);
|
|
2168
2227
|
return [2 /*return*/];
|
|
2169
2228
|
}
|
|
2170
2229
|
});
|
|
@@ -2207,6 +2266,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2207
2266
|
clientId: clientId,
|
|
2208
2267
|
agentName: agentName,
|
|
2209
2268
|
swarmName: "",
|
|
2269
|
+
storageName: "",
|
|
2210
2270
|
})];
|
|
2211
2271
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2212
2272
|
}
|
|
@@ -2241,6 +2301,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2241
2301
|
clientId: clientId,
|
|
2242
2302
|
agentName: agentName,
|
|
2243
2303
|
swarmName: "",
|
|
2304
|
+
storageName: "",
|
|
2244
2305
|
})];
|
|
2245
2306
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2246
2307
|
}
|
|
@@ -2272,6 +2333,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2272
2333
|
clientId: clientId,
|
|
2273
2334
|
agentName: agentName,
|
|
2274
2335
|
swarmName: "",
|
|
2336
|
+
storageName: "",
|
|
2275
2337
|
})];
|
|
2276
2338
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2277
2339
|
}
|
|
@@ -2307,6 +2369,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2307
2369
|
clientId: clientId,
|
|
2308
2370
|
agentName: agentName,
|
|
2309
2371
|
swarmName: "",
|
|
2372
|
+
storageName: "",
|
|
2310
2373
|
})];
|
|
2311
2374
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2312
2375
|
}
|
|
@@ -2340,6 +2403,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2340
2403
|
clientId: clientId,
|
|
2341
2404
|
agentName: agentName,
|
|
2342
2405
|
swarmName: "",
|
|
2406
|
+
storageName: "",
|
|
2343
2407
|
})];
|
|
2344
2408
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2345
2409
|
}
|
|
@@ -2373,6 +2437,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2373
2437
|
clientId: clientId,
|
|
2374
2438
|
agentName: agentName,
|
|
2375
2439
|
swarmName: "",
|
|
2440
|
+
storageName: "",
|
|
2376
2441
|
})];
|
|
2377
2442
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2378
2443
|
}
|
|
@@ -2404,6 +2469,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2404
2469
|
clientId: clientId,
|
|
2405
2470
|
agentName: agentName,
|
|
2406
2471
|
swarmName: "",
|
|
2472
|
+
storageName: "",
|
|
2407
2473
|
})];
|
|
2408
2474
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2409
2475
|
}
|
|
@@ -2435,6 +2501,7 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2435
2501
|
clientId: clientId,
|
|
2436
2502
|
agentName: agentName,
|
|
2437
2503
|
swarmName: "",
|
|
2504
|
+
storageName: "",
|
|
2438
2505
|
})];
|
|
2439
2506
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2440
2507
|
}
|
|
@@ -2480,6 +2547,7 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
2480
2547
|
clientId: clientId,
|
|
2481
2548
|
agentName: agentName,
|
|
2482
2549
|
swarmName: "",
|
|
2550
|
+
storageName: "",
|
|
2483
2551
|
})];
|
|
2484
2552
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2485
2553
|
}
|
|
@@ -2513,6 +2581,7 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
2513
2581
|
clientId: clientId,
|
|
2514
2582
|
agentName: agentName,
|
|
2515
2583
|
swarmName: "",
|
|
2584
|
+
storageName: "",
|
|
2516
2585
|
})];
|
|
2517
2586
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2518
2587
|
}
|
|
@@ -2544,6 +2613,7 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
2544
2613
|
clientId: clientId,
|
|
2545
2614
|
agentName: agentName,
|
|
2546
2615
|
swarmName: "",
|
|
2616
|
+
storageName: "",
|
|
2547
2617
|
})];
|
|
2548
2618
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2549
2619
|
}
|
|
@@ -2575,6 +2645,7 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
2575
2645
|
clientId: clientId,
|
|
2576
2646
|
agentName: agentName,
|
|
2577
2647
|
swarmName: "",
|
|
2648
|
+
storageName: "",
|
|
2578
2649
|
})];
|
|
2579
2650
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2580
2651
|
}
|
|
@@ -2620,6 +2691,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2620
2691
|
clientId: clientId,
|
|
2621
2692
|
swarmName: swarmName,
|
|
2622
2693
|
agentName: "",
|
|
2694
|
+
storageName: "",
|
|
2623
2695
|
})];
|
|
2624
2696
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2625
2697
|
}
|
|
@@ -2654,6 +2726,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2654
2726
|
clientId: clientId,
|
|
2655
2727
|
swarmName: swarmName,
|
|
2656
2728
|
agentName: "",
|
|
2729
|
+
storageName: "",
|
|
2657
2730
|
})];
|
|
2658
2731
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2659
2732
|
}
|
|
@@ -2687,6 +2760,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2687
2760
|
clientId: clientId,
|
|
2688
2761
|
swarmName: swarmName,
|
|
2689
2762
|
agentName: "",
|
|
2763
|
+
storageName: "",
|
|
2690
2764
|
})];
|
|
2691
2765
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2692
2766
|
}
|
|
@@ -2699,12 +2773,14 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2699
2773
|
clientId: clientId,
|
|
2700
2774
|
swarmName: swarmName,
|
|
2701
2775
|
agentName: "",
|
|
2776
|
+
storageName: "",
|
|
2702
2777
|
});
|
|
2703
2778
|
};
|
|
2704
2779
|
}, {
|
|
2705
2780
|
clientId: clientId,
|
|
2706
2781
|
swarmName: swarmName,
|
|
2707
2782
|
agentName: "",
|
|
2783
|
+
storageName: "",
|
|
2708
2784
|
});
|
|
2709
2785
|
};
|
|
2710
2786
|
/**
|
|
@@ -2737,6 +2813,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2737
2813
|
clientId: clientId,
|
|
2738
2814
|
swarmName: swarmName,
|
|
2739
2815
|
agentName: "",
|
|
2816
|
+
storageName: "",
|
|
2740
2817
|
})];
|
|
2741
2818
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2742
2819
|
}
|
|
@@ -2770,6 +2847,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2770
2847
|
clientId: clientId,
|
|
2771
2848
|
swarmName: swarmName,
|
|
2772
2849
|
agentName: "",
|
|
2850
|
+
storageName: "",
|
|
2773
2851
|
})];
|
|
2774
2852
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2775
2853
|
}
|
|
@@ -2803,6 +2881,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2803
2881
|
clientId: clientId,
|
|
2804
2882
|
swarmName: swarmName,
|
|
2805
2883
|
agentName: "",
|
|
2884
|
+
storageName: "",
|
|
2806
2885
|
})];
|
|
2807
2886
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2808
2887
|
}
|
|
@@ -2834,6 +2913,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2834
2913
|
clientId: clientId,
|
|
2835
2914
|
swarmName: swarmName,
|
|
2836
2915
|
agentName: "",
|
|
2916
|
+
storageName: "",
|
|
2837
2917
|
})];
|
|
2838
2918
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2839
2919
|
}
|
|
@@ -2865,6 +2945,7 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2865
2945
|
clientId: clientId,
|
|
2866
2946
|
swarmName: swarmName,
|
|
2867
2947
|
agentName: "",
|
|
2948
|
+
storageName: "",
|
|
2868
2949
|
})];
|
|
2869
2950
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2870
2951
|
}
|
|
@@ -2908,6 +2989,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
2908
2989
|
clientId: clientId,
|
|
2909
2990
|
swarmName: swarmName,
|
|
2910
2991
|
agentName: "",
|
|
2992
|
+
storageName: "",
|
|
2911
2993
|
})];
|
|
2912
2994
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2913
2995
|
}
|
|
@@ -2939,6 +3021,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
2939
3021
|
clientId: clientId,
|
|
2940
3022
|
swarmName: swarmName,
|
|
2941
3023
|
agentName: "",
|
|
3024
|
+
storageName: "",
|
|
2942
3025
|
})];
|
|
2943
3026
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2944
3027
|
}
|
|
@@ -2970,6 +3053,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
2970
3053
|
clientId: clientId,
|
|
2971
3054
|
swarmName: swarmName,
|
|
2972
3055
|
agentName: "",
|
|
3056
|
+
storageName: "",
|
|
2973
3057
|
})];
|
|
2974
3058
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2975
3059
|
}
|
|
@@ -3005,6 +3089,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
3005
3089
|
clientId: clientId,
|
|
3006
3090
|
swarmName: swarmName,
|
|
3007
3091
|
agentName: "",
|
|
3092
|
+
storageName: "",
|
|
3008
3093
|
})];
|
|
3009
3094
|
case 1: return [2 /*return*/, _a.sent()];
|
|
3010
3095
|
}
|
|
@@ -3038,6 +3123,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
3038
3123
|
clientId: clientId,
|
|
3039
3124
|
swarmName: swarmName,
|
|
3040
3125
|
agentName: "",
|
|
3126
|
+
storageName: "",
|
|
3041
3127
|
})];
|
|
3042
3128
|
case 1: return [2 /*return*/, _a.sent()];
|
|
3043
3129
|
}
|
|
@@ -3069,6 +3155,7 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
3069
3155
|
clientId: clientId,
|
|
3070
3156
|
swarmName: swarmName,
|
|
3071
3157
|
agentName: "",
|
|
3158
|
+
storageName: "",
|
|
3072
3159
|
})];
|
|
3073
3160
|
case 1: return [2 /*return*/, _a.sent()];
|
|
3074
3161
|
}
|
|
@@ -3087,7 +3174,20 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
3087
3174
|
this.loggerService = inject(TYPES.loggerService);
|
|
3088
3175
|
this.toolValidationService = inject(TYPES.toolValidationService);
|
|
3089
3176
|
this.completionValidationService = inject(TYPES.completionValidationService);
|
|
3177
|
+
this.storageValidationService = inject(TYPES.storageValidationService);
|
|
3090
3178
|
this._agentMap = new Map();
|
|
3179
|
+
/**
|
|
3180
|
+
* Retrieves the storages used by the agent
|
|
3181
|
+
* @param {agentName} agentName - The name of the swarm.
|
|
3182
|
+
* @returns {string[]} The list of storage names.
|
|
3183
|
+
* @throws Will throw an error if the swarm is not found.
|
|
3184
|
+
*/
|
|
3185
|
+
this.getStorageList = function (agentName) {
|
|
3186
|
+
if (!_this._agentMap.has(agentName)) {
|
|
3187
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not exist (getStorageList)"));
|
|
3188
|
+
}
|
|
3189
|
+
return _this._agentMap.get(agentName).storages;
|
|
3190
|
+
};
|
|
3091
3191
|
/**
|
|
3092
3192
|
* Adds a new agent to the validation service.
|
|
3093
3193
|
* @param {AgentName} agentName - The name of the agent.
|
|
@@ -3104,6 +3204,23 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
3104
3204
|
}
|
|
3105
3205
|
_this._agentMap.set(agentName, agentSchema);
|
|
3106
3206
|
};
|
|
3207
|
+
/**
|
|
3208
|
+
* Check if agent got registered storage
|
|
3209
|
+
*/
|
|
3210
|
+
this.hasStorage = functoolsKit.memoize(function (_a) {
|
|
3211
|
+
var _b = __read(_a, 2), agentName = _b[0], storageName = _b[1];
|
|
3212
|
+
return "".concat(agentName, "-").concat(storageName);
|
|
3213
|
+
}, function (agentName, storageName) {
|
|
3214
|
+
_this.loggerService.log("agentValidationService hasStorage", {
|
|
3215
|
+
agentName: agentName,
|
|
3216
|
+
storageName: storageName,
|
|
3217
|
+
});
|
|
3218
|
+
if (!_this._agentMap.has(agentName)) {
|
|
3219
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not exist (hasStorage)"));
|
|
3220
|
+
}
|
|
3221
|
+
var _a = _this._agentMap.get(agentName).storages, storages = _a === void 0 ? [] : _a;
|
|
3222
|
+
return storages.includes(storageName);
|
|
3223
|
+
});
|
|
3107
3224
|
/**
|
|
3108
3225
|
* Validates an agent by its name and source.
|
|
3109
3226
|
* @param {AgentName} agentName - The name of the agent.
|
|
@@ -3114,7 +3231,7 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
3114
3231
|
var _b = __read(_a, 1), agentName = _b[0];
|
|
3115
3232
|
return agentName;
|
|
3116
3233
|
}, function (agentName, source) {
|
|
3117
|
-
var _a;
|
|
3234
|
+
var _a, _b;
|
|
3118
3235
|
_this.loggerService.log("agentValidationService validate", {
|
|
3119
3236
|
agentName: agentName,
|
|
3120
3237
|
source: source,
|
|
@@ -3130,6 +3247,12 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
3130
3247
|
}
|
|
3131
3248
|
_this.toolValidationService.validate(toolName, source);
|
|
3132
3249
|
});
|
|
3250
|
+
(_b = agent.storages) === null || _b === void 0 ? void 0 : _b.forEach(function (storageName) {
|
|
3251
|
+
if (typeof storageName !== "string") {
|
|
3252
|
+
throw new Error("agent-swarm agent ".concat(agentName, " storage list is invalid (storageName=").concat(String(storageName), ") source=").concat(source));
|
|
3253
|
+
}
|
|
3254
|
+
_this.storageValidationService.validate(storageName, source);
|
|
3255
|
+
});
|
|
3133
3256
|
});
|
|
3134
3257
|
}
|
|
3135
3258
|
return AgentValidationService;
|
|
@@ -3511,128 +3634,914 @@ var ToolValidationService = /** @class */ (function () {
|
|
|
3511
3634
|
return ToolValidationService;
|
|
3512
3635
|
}());
|
|
3513
3636
|
|
|
3514
|
-
{
|
|
3515
|
-
provide(TYPES.loggerService, function () { return new LoggerService(); });
|
|
3516
|
-
provide(TYPES.contextService, function () { return new ContextService(); });
|
|
3517
|
-
}
|
|
3518
|
-
{
|
|
3519
|
-
provide(TYPES.agentConnectionService, function () { return new AgentConnectionService(); });
|
|
3520
|
-
provide(TYPES.historyConnectionService, function () { return new HistoryConnectionService(); });
|
|
3521
|
-
provide(TYPES.swarmConnectionService, function () { return new SwarmConnectionService(); });
|
|
3522
|
-
provide(TYPES.sessionConnectionService, function () { return new SessionConnectionService(); });
|
|
3523
|
-
}
|
|
3524
|
-
{
|
|
3525
|
-
provide(TYPES.agentSchemaService, function () { return new AgentSchemaService(); });
|
|
3526
|
-
provide(TYPES.toolSchemaService, function () { return new ToolSchemaService(); });
|
|
3527
|
-
provide(TYPES.swarmSchemaService, function () { return new SwarmSchemaService(); });
|
|
3528
|
-
provide(TYPES.completionSchemaService, function () { return new CompletionSchemaService(); });
|
|
3529
|
-
}
|
|
3530
|
-
{
|
|
3531
|
-
provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
|
|
3532
|
-
provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
|
|
3533
|
-
provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
|
|
3534
|
-
provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
|
|
3535
|
-
}
|
|
3536
|
-
{
|
|
3537
|
-
provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
|
|
3538
|
-
provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
|
|
3539
|
-
provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
|
|
3540
|
-
provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
|
|
3541
|
-
}
|
|
3542
|
-
{
|
|
3543
|
-
provide(TYPES.agentValidationService, function () { return new AgentValidationService(); });
|
|
3544
|
-
provide(TYPES.completionValidationService, function () { return new CompletionValidationService(); });
|
|
3545
|
-
provide(TYPES.sessionValidationService, function () { return new SessionValidationService(); });
|
|
3546
|
-
provide(TYPES.swarmValidationService, function () { return new SwarmValidationService(); });
|
|
3547
|
-
provide(TYPES.toolValidationService, function () { return new ToolValidationService(); });
|
|
3548
|
-
}
|
|
3549
|
-
|
|
3550
|
-
var baseServices = {
|
|
3551
|
-
loggerService: inject(TYPES.loggerService),
|
|
3552
|
-
contextService: inject(TYPES.contextService),
|
|
3553
|
-
};
|
|
3554
|
-
var connectionServices = {
|
|
3555
|
-
agentConnectionService: inject(TYPES.agentConnectionService),
|
|
3556
|
-
historyConnectionService: inject(TYPES.historyConnectionService),
|
|
3557
|
-
swarmConnectionService: inject(TYPES.swarmConnectionService),
|
|
3558
|
-
sessionConnectionService: inject(TYPES.sessionConnectionService),
|
|
3559
|
-
};
|
|
3560
|
-
var specServices = {
|
|
3561
|
-
agentSchemaService: inject(TYPES.agentSchemaService),
|
|
3562
|
-
toolSchemaService: inject(TYPES.toolSchemaService),
|
|
3563
|
-
swarmSchemaService: inject(TYPES.swarmSchemaService),
|
|
3564
|
-
completionSchemaService: inject(TYPES.completionSchemaService),
|
|
3565
|
-
};
|
|
3566
|
-
var publicServices = {
|
|
3567
|
-
agentPublicService: inject(TYPES.agentPublicService),
|
|
3568
|
-
historyPublicService: inject(TYPES.historyPublicService),
|
|
3569
|
-
sessionPublicService: inject(TYPES.sessionPublicService),
|
|
3570
|
-
swarmPublicService: inject(TYPES.swarmPublicService),
|
|
3571
|
-
};
|
|
3572
|
-
var validationServices = {
|
|
3573
|
-
agentValidationService: inject(TYPES.agentValidationService),
|
|
3574
|
-
toolValidationService: inject(TYPES.toolValidationService),
|
|
3575
|
-
sessionValidationService: inject(TYPES.sessionValidationService),
|
|
3576
|
-
swarmValidationService: inject(TYPES.swarmValidationService),
|
|
3577
|
-
completionValidationService: inject(TYPES.completionValidationService),
|
|
3578
|
-
};
|
|
3579
|
-
var swarm = __assign(__assign(__assign(__assign(__assign({}, baseServices), connectionServices), specServices), publicServices), validationServices);
|
|
3580
|
-
init();
|
|
3581
|
-
|
|
3582
3637
|
/**
|
|
3583
|
-
*
|
|
3584
|
-
*
|
|
3585
|
-
* @param {IAgentSchema} agentSchema - The schema of the agent to be added.
|
|
3586
|
-
* @returns {string} The name of the added agent.
|
|
3638
|
+
* Service for managing embedding schemas.
|
|
3587
3639
|
*/
|
|
3588
|
-
var
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
}
|
|
3640
|
+
var EmbeddingSchemaService = /** @class */ (function () {
|
|
3641
|
+
function EmbeddingSchemaService() {
|
|
3642
|
+
var _this = this;
|
|
3643
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
3644
|
+
this.registry = new functoolsKit.ToolRegistry("embeddingSchemaService");
|
|
3645
|
+
/**
|
|
3646
|
+
* Registers a embedding with the given key and value.
|
|
3647
|
+
* @param {EmbeddingName} key - The name of the embedding.
|
|
3648
|
+
* @param {IAgentTool} value - The embedding to register.
|
|
3649
|
+
*/
|
|
3650
|
+
this.register = function (key, value) {
|
|
3651
|
+
_this.loggerService.log('embeddingSchemaService register');
|
|
3652
|
+
_this.registry = _this.registry.register(key, value);
|
|
3653
|
+
};
|
|
3654
|
+
/**
|
|
3655
|
+
* Retrieves a embedding by its key.
|
|
3656
|
+
* @param {EmbeddingName} key - The name of the embedding.
|
|
3657
|
+
* @returns {IAgentTool} The embedding associated with the given key.
|
|
3658
|
+
*/
|
|
3659
|
+
this.get = function (key) {
|
|
3660
|
+
_this.loggerService.log('embeddingSchemaService get', { key: key });
|
|
3661
|
+
return _this.registry.get(key);
|
|
3662
|
+
};
|
|
3663
|
+
}
|
|
3664
|
+
return EmbeddingSchemaService;
|
|
3665
|
+
}());
|
|
3596
3666
|
|
|
3597
3667
|
/**
|
|
3598
|
-
*
|
|
3599
|
-
* framewords for completion like: mock, gpt4all, ollama, openai
|
|
3600
|
-
*
|
|
3601
|
-
* @param {ICompletionSchema} completionSchema - The completion schema to be added.
|
|
3602
|
-
* @returns {string} The name of the completion that was added.
|
|
3668
|
+
* Service for managing storage schemas.
|
|
3603
3669
|
*/
|
|
3604
|
-
var
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
}
|
|
3670
|
+
var StorageSchemaService = /** @class */ (function () {
|
|
3671
|
+
function StorageSchemaService() {
|
|
3672
|
+
var _this = this;
|
|
3673
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
3674
|
+
this.registry = new functoolsKit.ToolRegistry("storageSchemaService");
|
|
3675
|
+
/**
|
|
3676
|
+
* Registers a new storage schema.
|
|
3677
|
+
* @param {StorageName} key - The key for the schema.
|
|
3678
|
+
* @param {IStorageSchema} value - The schema to register.
|
|
3679
|
+
*/
|
|
3680
|
+
this.register = function (key, value) {
|
|
3681
|
+
_this.loggerService.log("storageSchemaService register", { key: key });
|
|
3682
|
+
_this.registry = _this.registry.register(key, value);
|
|
3683
|
+
};
|
|
3684
|
+
/**
|
|
3685
|
+
* Retrieves a storage schema by key.
|
|
3686
|
+
* @param {StorageName} key - The key of the schema to retrieve.
|
|
3687
|
+
* @returns {IStorageSchema} The retrieved schema.
|
|
3688
|
+
*/
|
|
3689
|
+
this.get = function (key) {
|
|
3690
|
+
_this.loggerService.log("storageSchemaService get", { key: key });
|
|
3691
|
+
return _this.registry.get(key);
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
return StorageSchemaService;
|
|
3695
|
+
}());
|
|
3612
3696
|
|
|
3613
|
-
/**
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
var
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3697
|
+
var ClientStorage = /** @class */ (function () {
|
|
3698
|
+
function ClientStorage(params) {
|
|
3699
|
+
var _this = this;
|
|
3700
|
+
this.params = params;
|
|
3701
|
+
this._itemMap = new Map();
|
|
3702
|
+
this._createEmbedding = functoolsKit.memoize(function (_a) {
|
|
3703
|
+
var _b = __read(_a, 1), id = _b[0].id;
|
|
3704
|
+
return id;
|
|
3705
|
+
}, function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
3706
|
+
var index, embeddings;
|
|
3707
|
+
return __generator(this, function (_a) {
|
|
3708
|
+
switch (_a.label) {
|
|
3709
|
+
case 0:
|
|
3710
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " _createEmbedding"), {
|
|
3711
|
+
id: item.id,
|
|
3712
|
+
});
|
|
3713
|
+
return [4 /*yield*/, this.params.createIndex(item)];
|
|
3714
|
+
case 1:
|
|
3715
|
+
index = _a.sent();
|
|
3716
|
+
return [4 /*yield*/, this.params.createEmbedding(index)];
|
|
3717
|
+
case 2:
|
|
3718
|
+
embeddings = _a.sent();
|
|
3719
|
+
if (this.params.onCreate) {
|
|
3720
|
+
this.params.onCreate(index, embeddings, this.params.clientId, this.params.embedding);
|
|
3721
|
+
}
|
|
3722
|
+
return [2 /*return*/, [embeddings, index]];
|
|
3723
|
+
}
|
|
3724
|
+
});
|
|
3725
|
+
}); });
|
|
3726
|
+
this.waitForInit = functoolsKit.singleshot(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3727
|
+
var data;
|
|
3728
|
+
return __generator(this, function (_a) {
|
|
3729
|
+
switch (_a.label) {
|
|
3730
|
+
case 0:
|
|
3731
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " waitForInit"));
|
|
3732
|
+
if (!this.params.getData) {
|
|
3733
|
+
return [2 /*return*/];
|
|
3734
|
+
}
|
|
3735
|
+
return [4 /*yield*/, this.params.getData(this.params.clientId, this.params.storageName)];
|
|
3736
|
+
case 1:
|
|
3737
|
+
data = _a.sent();
|
|
3738
|
+
return [4 /*yield*/, Promise.all(data.map(functoolsKit.execpool(this._createEmbedding, {
|
|
3739
|
+
delay: 10,
|
|
3740
|
+
maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
|
|
3741
|
+
})))];
|
|
3742
|
+
case 2:
|
|
3743
|
+
_a.sent();
|
|
3744
|
+
this._itemMap = new Map(data.map(function (item) { return [item.id, item]; }));
|
|
3745
|
+
return [2 /*return*/];
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
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 = [];
|
|
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({ data: item, score: 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
|
+
filtered = indexed
|
|
3790
|
+
.filter(function (_a) {
|
|
3791
|
+
var score = _a.score;
|
|
3792
|
+
return score > GLOBAL_CONFIG.CC_STORAGE_SEARCH_SIMILARITY;
|
|
3793
|
+
})
|
|
3794
|
+
.sort(function (_a, _b) {
|
|
3795
|
+
var a = _a.score;
|
|
3796
|
+
var b = _b.score;
|
|
3797
|
+
return b - a;
|
|
3798
|
+
});
|
|
3799
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " take filtered"), {
|
|
3800
|
+
filtered: filtered.map(function (_a) {
|
|
3801
|
+
var data = _a.data, score = _a.score;
|
|
3802
|
+
return ({ id: data.id, score: score });
|
|
3803
|
+
}),
|
|
3804
|
+
});
|
|
3805
|
+
return [2 /*return*/, filtered.map(function (_a) {
|
|
3806
|
+
var data = _a.data;
|
|
3807
|
+
return data;
|
|
3808
|
+
})];
|
|
3809
|
+
}
|
|
3810
|
+
});
|
|
3811
|
+
}); };
|
|
3812
|
+
this.upsert = function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
3813
|
+
var _a, _b;
|
|
3814
|
+
return __generator(this, function (_c) {
|
|
3815
|
+
switch (_c.label) {
|
|
3816
|
+
case 0:
|
|
3817
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " upsert"), {
|
|
3818
|
+
item: item,
|
|
3819
|
+
});
|
|
3820
|
+
this._itemMap.set(item.id, item);
|
|
3821
|
+
this._createEmbedding.clear(item.id);
|
|
3822
|
+
return [4 /*yield*/, this._createEmbedding(item)];
|
|
3823
|
+
case 1:
|
|
3824
|
+
_c.sent();
|
|
3825
|
+
if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onUpdate) {
|
|
3826
|
+
(_b = this.params.callbacks) === null || _b === void 0 ? void 0 : _b.onUpdate(__spreadArray([], __read(this._itemMap.values()), false), this.params.clientId, this.params.storageName);
|
|
3827
|
+
}
|
|
3828
|
+
return [2 /*return*/];
|
|
3829
|
+
}
|
|
3830
|
+
});
|
|
3831
|
+
}); };
|
|
3832
|
+
this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
3833
|
+
var _a, _b;
|
|
3834
|
+
return __generator(this, function (_c) {
|
|
3835
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " remove"), {
|
|
3836
|
+
id: itemId,
|
|
3837
|
+
});
|
|
3838
|
+
this._itemMap.delete(itemId);
|
|
3839
|
+
this._createEmbedding.clear(itemId);
|
|
3840
|
+
if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onUpdate) {
|
|
3841
|
+
(_b = this.params.callbacks) === null || _b === void 0 ? void 0 : _b.onUpdate(__spreadArray([], __read(this._itemMap.values()), false), this.params.clientId, this.params.storageName);
|
|
3842
|
+
}
|
|
3843
|
+
return [2 /*return*/];
|
|
3844
|
+
});
|
|
3845
|
+
}); };
|
|
3846
|
+
this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3847
|
+
return __generator(this, function (_a) {
|
|
3848
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " clear"));
|
|
3849
|
+
this._itemMap.clear();
|
|
3850
|
+
this._createEmbedding.clear();
|
|
3851
|
+
return [2 /*return*/];
|
|
3852
|
+
});
|
|
3853
|
+
}); };
|
|
3854
|
+
this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
3855
|
+
var _a;
|
|
3856
|
+
return __generator(this, function (_b) {
|
|
3857
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " get"), {
|
|
3858
|
+
id: itemId,
|
|
3859
|
+
});
|
|
3860
|
+
return [2 /*return*/, (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null];
|
|
3861
|
+
});
|
|
3862
|
+
}); };
|
|
3863
|
+
this.list = function (filter) { return __awaiter(_this, void 0, void 0, function () {
|
|
3864
|
+
var result, _a, _b, item;
|
|
3865
|
+
var e_1, _c;
|
|
3866
|
+
return __generator(this, function (_d) {
|
|
3867
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " list"));
|
|
3868
|
+
if (!filter) {
|
|
3869
|
+
return [2 /*return*/, __spreadArray([], __read(this._itemMap.values()), false)];
|
|
3870
|
+
}
|
|
3871
|
+
result = [];
|
|
3872
|
+
try {
|
|
3873
|
+
for (_a = __values(this._itemMap.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3874
|
+
item = _b.value;
|
|
3875
|
+
if (filter(item)) {
|
|
3876
|
+
result.push(item);
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3881
|
+
finally {
|
|
3882
|
+
try {
|
|
3883
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3884
|
+
}
|
|
3885
|
+
finally { if (e_1) throw e_1.error; }
|
|
3886
|
+
}
|
|
3887
|
+
return [2 /*return*/, result];
|
|
3888
|
+
});
|
|
3889
|
+
}); };
|
|
3890
|
+
this.params.logger.debug("ClientStorage storageName=".concat(this.params.storageName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
3891
|
+
params: params,
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
return ClientStorage;
|
|
3895
|
+
}());
|
|
3627
3896
|
|
|
3628
3897
|
/**
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
*
|
|
3632
|
-
* @param {IAgentTool} toolSchema - The schema of the tool to be added.
|
|
3633
|
-
* @returns {string} The name of the tool that was added.
|
|
3898
|
+
* Service for managing storage connections.
|
|
3899
|
+
* @implements {IStorage}
|
|
3634
3900
|
*/
|
|
3635
|
-
var
|
|
3901
|
+
var StorageConnectionService = /** @class */ (function () {
|
|
3902
|
+
function StorageConnectionService() {
|
|
3903
|
+
var _this = this;
|
|
3904
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
3905
|
+
this.contextService = inject(TYPES.contextService);
|
|
3906
|
+
this.storageSchemaService = inject(TYPES.storageSchemaService);
|
|
3907
|
+
this.embeddingSchemaService = inject(TYPES.embeddingSchemaService);
|
|
3908
|
+
/**
|
|
3909
|
+
* Retrieves a storage instance based on client ID and storage name.
|
|
3910
|
+
* @param {string} clientId - The client ID.
|
|
3911
|
+
* @param {string} storageName - The storage name.
|
|
3912
|
+
* @returns {ClientStorage} The client storage instance.
|
|
3913
|
+
*/
|
|
3914
|
+
this.getStorage = functoolsKit.memoize(function (_a) {
|
|
3915
|
+
var _b = __read(_a, 2), clientId = _b[0], storageName = _b[1];
|
|
3916
|
+
return "".concat(clientId, "-").concat(storageName);
|
|
3917
|
+
}, function (clientId, storageName) {
|
|
3918
|
+
var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, callbacks = _a.callbacks;
|
|
3919
|
+
var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
|
|
3920
|
+
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 }));
|
|
3921
|
+
});
|
|
3922
|
+
/**
|
|
3923
|
+
* Retrieves a list of storage data based on a search query and total number of items.
|
|
3924
|
+
* @param {string} search - The search query.
|
|
3925
|
+
* @param {number} total - The total number of items to retrieve.
|
|
3926
|
+
* @returns {Promise<IStorageData[]>} The list of storage data.
|
|
3927
|
+
*/
|
|
3928
|
+
this.take = function (search, total) { return __awaiter(_this, void 0, void 0, function () {
|
|
3929
|
+
var storage;
|
|
3930
|
+
return __generator(this, function (_a) {
|
|
3931
|
+
switch (_a.label) {
|
|
3932
|
+
case 0:
|
|
3933
|
+
this.loggerService.log("storageConnectionService take", {
|
|
3934
|
+
context: this.contextService.context,
|
|
3935
|
+
search: search,
|
|
3936
|
+
total: total,
|
|
3937
|
+
});
|
|
3938
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
3939
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
3940
|
+
case 1:
|
|
3941
|
+
_a.sent();
|
|
3942
|
+
return [4 /*yield*/, storage.take(search, total)];
|
|
3943
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
3944
|
+
}
|
|
3945
|
+
});
|
|
3946
|
+
}); };
|
|
3947
|
+
/**
|
|
3948
|
+
* Upserts an item in the storage.
|
|
3949
|
+
* @param {IStorageData} item - The item to upsert.
|
|
3950
|
+
* @returns {Promise<void>}
|
|
3951
|
+
*/
|
|
3952
|
+
this.upsert = function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
3953
|
+
var storage;
|
|
3954
|
+
return __generator(this, function (_a) {
|
|
3955
|
+
switch (_a.label) {
|
|
3956
|
+
case 0:
|
|
3957
|
+
this.loggerService.log("storageConnectionService upsert", {
|
|
3958
|
+
context: this.contextService.context,
|
|
3959
|
+
item: item,
|
|
3960
|
+
});
|
|
3961
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
3962
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
3963
|
+
case 1:
|
|
3964
|
+
_a.sent();
|
|
3965
|
+
return [4 /*yield*/, storage.upsert(item)];
|
|
3966
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
3967
|
+
}
|
|
3968
|
+
});
|
|
3969
|
+
}); };
|
|
3970
|
+
/**
|
|
3971
|
+
* Removes an item from the storage.
|
|
3972
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to remove.
|
|
3973
|
+
* @returns {Promise<void>}
|
|
3974
|
+
*/
|
|
3975
|
+
this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
3976
|
+
var storage;
|
|
3977
|
+
return __generator(this, function (_a) {
|
|
3978
|
+
switch (_a.label) {
|
|
3979
|
+
case 0:
|
|
3980
|
+
this.loggerService.log("storageConnectionService remove", {
|
|
3981
|
+
context: this.contextService.context,
|
|
3982
|
+
itemId: itemId,
|
|
3983
|
+
});
|
|
3984
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
3985
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
3986
|
+
case 1:
|
|
3987
|
+
_a.sent();
|
|
3988
|
+
return [4 /*yield*/, storage.remove(itemId)];
|
|
3989
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
3990
|
+
}
|
|
3991
|
+
});
|
|
3992
|
+
}); };
|
|
3993
|
+
/**
|
|
3994
|
+
* Retrieves an item from the storage by its ID.
|
|
3995
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to retrieve.
|
|
3996
|
+
* @returns {Promise<IStorageData>} The retrieved item.
|
|
3997
|
+
*/
|
|
3998
|
+
this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
|
|
3999
|
+
var storage;
|
|
4000
|
+
return __generator(this, function (_a) {
|
|
4001
|
+
switch (_a.label) {
|
|
4002
|
+
case 0:
|
|
4003
|
+
this.loggerService.log("storageConnectionService get", {
|
|
4004
|
+
context: this.contextService.context,
|
|
4005
|
+
itemId: itemId,
|
|
4006
|
+
});
|
|
4007
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
4008
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
4009
|
+
case 1:
|
|
4010
|
+
_a.sent();
|
|
4011
|
+
return [4 /*yield*/, storage.get(itemId)];
|
|
4012
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
4013
|
+
}
|
|
4014
|
+
});
|
|
4015
|
+
}); };
|
|
4016
|
+
/**
|
|
4017
|
+
* Retrieves a list of items from the storage, optionally filtered by a predicate function.
|
|
4018
|
+
* @param {function(IStorageData): boolean} [filter] - The optional filter function.
|
|
4019
|
+
* @returns {Promise<IStorageData[]>} The list of items.
|
|
4020
|
+
*/
|
|
4021
|
+
this.list = function (filter) { return __awaiter(_this, void 0, void 0, function () {
|
|
4022
|
+
var storage;
|
|
4023
|
+
return __generator(this, function (_a) {
|
|
4024
|
+
switch (_a.label) {
|
|
4025
|
+
case 0:
|
|
4026
|
+
this.loggerService.log("storageConnectionService list", {
|
|
4027
|
+
context: this.contextService.context,
|
|
4028
|
+
});
|
|
4029
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
4030
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
4031
|
+
case 1:
|
|
4032
|
+
_a.sent();
|
|
4033
|
+
return [4 /*yield*/, storage.list(filter)];
|
|
4034
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
4035
|
+
}
|
|
4036
|
+
});
|
|
4037
|
+
}); };
|
|
4038
|
+
/**
|
|
4039
|
+
* Clears all items from the storage.
|
|
4040
|
+
* @returns {Promise<void>}
|
|
4041
|
+
*/
|
|
4042
|
+
this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4043
|
+
var storage;
|
|
4044
|
+
return __generator(this, function (_a) {
|
|
4045
|
+
switch (_a.label) {
|
|
4046
|
+
case 0:
|
|
4047
|
+
this.loggerService.log("storageConnectionService clear", {
|
|
4048
|
+
context: this.contextService.context,
|
|
4049
|
+
});
|
|
4050
|
+
storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
|
|
4051
|
+
return [4 /*yield*/, storage.waitForInit()];
|
|
4052
|
+
case 1:
|
|
4053
|
+
_a.sent();
|
|
4054
|
+
return [4 /*yield*/, storage.clear()];
|
|
4055
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
4056
|
+
}
|
|
4057
|
+
});
|
|
4058
|
+
}); };
|
|
4059
|
+
/**
|
|
4060
|
+
* Disposes of the storage connection.
|
|
4061
|
+
* @returns {Promise<void>}
|
|
4062
|
+
*/
|
|
4063
|
+
this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4064
|
+
var key;
|
|
4065
|
+
return __generator(this, function (_a) {
|
|
4066
|
+
this.loggerService.log("storageConnectionService dispose", {
|
|
4067
|
+
context: this.contextService.context,
|
|
4068
|
+
});
|
|
4069
|
+
key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.storageName);
|
|
4070
|
+
if (!this.getStorage.has(key)) {
|
|
4071
|
+
return [2 /*return*/];
|
|
4072
|
+
}
|
|
4073
|
+
this.getStorage.clear(key);
|
|
4074
|
+
return [2 /*return*/];
|
|
4075
|
+
});
|
|
4076
|
+
}); };
|
|
4077
|
+
}
|
|
4078
|
+
return StorageConnectionService;
|
|
4079
|
+
}());
|
|
4080
|
+
|
|
4081
|
+
/**
|
|
4082
|
+
* Service for managing public storage interactions.
|
|
4083
|
+
*/
|
|
4084
|
+
var StoragePublicService = /** @class */ (function () {
|
|
4085
|
+
function StoragePublicService() {
|
|
4086
|
+
var _this = this;
|
|
4087
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
4088
|
+
this.storageConnectionService = inject(TYPES.storageConnectionService);
|
|
4089
|
+
/**
|
|
4090
|
+
* Retrieves a list of storage data based on a search query and total number of items.
|
|
4091
|
+
* @param {string} search - The search query.
|
|
4092
|
+
* @param {number} total - The total number of items to retrieve.
|
|
4093
|
+
* @returns {Promise<IStorageData[]>} The list of storage data.
|
|
4094
|
+
*/
|
|
4095
|
+
this.take = function (search, total, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4096
|
+
var _this = this;
|
|
4097
|
+
return __generator(this, function (_a) {
|
|
4098
|
+
switch (_a.label) {
|
|
4099
|
+
case 0:
|
|
4100
|
+
this.loggerService.log("storagePublicService take", {
|
|
4101
|
+
search: search,
|
|
4102
|
+
total: total,
|
|
4103
|
+
clientId: clientId,
|
|
4104
|
+
storageName: storageName,
|
|
4105
|
+
});
|
|
4106
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4107
|
+
return __generator(this, function (_a) {
|
|
4108
|
+
switch (_a.label) {
|
|
4109
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.take(search, total)];
|
|
4110
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4111
|
+
}
|
|
4112
|
+
});
|
|
4113
|
+
}); }, {
|
|
4114
|
+
clientId: clientId,
|
|
4115
|
+
storageName: storageName,
|
|
4116
|
+
agentName: "",
|
|
4117
|
+
swarmName: "",
|
|
4118
|
+
})];
|
|
4119
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4120
|
+
}
|
|
4121
|
+
});
|
|
4122
|
+
}); };
|
|
4123
|
+
/**
|
|
4124
|
+
* Upserts an item in the storage.
|
|
4125
|
+
* @param {IStorageData} item - The item to upsert.
|
|
4126
|
+
* @returns {Promise<void>}
|
|
4127
|
+
*/
|
|
4128
|
+
this.upsert = function (item, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4129
|
+
var _this = this;
|
|
4130
|
+
return __generator(this, function (_a) {
|
|
4131
|
+
switch (_a.label) {
|
|
4132
|
+
case 0:
|
|
4133
|
+
this.loggerService.log("storagePublicService upsert", {
|
|
4134
|
+
item: item,
|
|
4135
|
+
clientId: clientId,
|
|
4136
|
+
storageName: storageName,
|
|
4137
|
+
});
|
|
4138
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4139
|
+
return __generator(this, function (_a) {
|
|
4140
|
+
switch (_a.label) {
|
|
4141
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.upsert(item)];
|
|
4142
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4143
|
+
}
|
|
4144
|
+
});
|
|
4145
|
+
}); }, {
|
|
4146
|
+
clientId: clientId,
|
|
4147
|
+
storageName: storageName,
|
|
4148
|
+
agentName: "",
|
|
4149
|
+
swarmName: "",
|
|
4150
|
+
})];
|
|
4151
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4152
|
+
}
|
|
4153
|
+
});
|
|
4154
|
+
}); };
|
|
4155
|
+
/**
|
|
4156
|
+
* Removes an item from the storage.
|
|
4157
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to remove.
|
|
4158
|
+
* @returns {Promise<void>}
|
|
4159
|
+
*/
|
|
4160
|
+
this.remove = function (itemId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4161
|
+
var _this = this;
|
|
4162
|
+
return __generator(this, function (_a) {
|
|
4163
|
+
switch (_a.label) {
|
|
4164
|
+
case 0:
|
|
4165
|
+
this.loggerService.log("storagePublicService remove", {
|
|
4166
|
+
itemId: itemId,
|
|
4167
|
+
clientId: clientId,
|
|
4168
|
+
storageName: storageName,
|
|
4169
|
+
});
|
|
4170
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4171
|
+
return __generator(this, function (_a) {
|
|
4172
|
+
switch (_a.label) {
|
|
4173
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.remove(itemId)];
|
|
4174
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4175
|
+
}
|
|
4176
|
+
});
|
|
4177
|
+
}); }, {
|
|
4178
|
+
clientId: clientId,
|
|
4179
|
+
storageName: storageName,
|
|
4180
|
+
agentName: "",
|
|
4181
|
+
swarmName: "",
|
|
4182
|
+
})];
|
|
4183
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4184
|
+
}
|
|
4185
|
+
});
|
|
4186
|
+
}); };
|
|
4187
|
+
/**
|
|
4188
|
+
* Retrieves an item from the storage by its ID.
|
|
4189
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to retrieve.
|
|
4190
|
+
* @returns {Promise<IStorageData>} The retrieved item.
|
|
4191
|
+
*/
|
|
4192
|
+
this.get = function (itemId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4193
|
+
var _this = this;
|
|
4194
|
+
return __generator(this, function (_a) {
|
|
4195
|
+
switch (_a.label) {
|
|
4196
|
+
case 0:
|
|
4197
|
+
this.loggerService.log("storagePublicService get", {
|
|
4198
|
+
itemId: itemId,
|
|
4199
|
+
clientId: clientId,
|
|
4200
|
+
storageName: storageName,
|
|
4201
|
+
});
|
|
4202
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4203
|
+
return __generator(this, function (_a) {
|
|
4204
|
+
switch (_a.label) {
|
|
4205
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.get(itemId)];
|
|
4206
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4207
|
+
}
|
|
4208
|
+
});
|
|
4209
|
+
}); }, {
|
|
4210
|
+
clientId: clientId,
|
|
4211
|
+
storageName: storageName,
|
|
4212
|
+
agentName: "",
|
|
4213
|
+
swarmName: "",
|
|
4214
|
+
})];
|
|
4215
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4216
|
+
}
|
|
4217
|
+
});
|
|
4218
|
+
}); };
|
|
4219
|
+
/**
|
|
4220
|
+
* Retrieves a list of items from the storage, optionally filtered by a predicate function.
|
|
4221
|
+
* @param {function(IStorageData): boolean} [filter] - The optional filter function.
|
|
4222
|
+
* @returns {Promise<IStorageData[]>} The list of items.
|
|
4223
|
+
*/
|
|
4224
|
+
this.list = function (clientId, storageName, filter) { return __awaiter(_this, void 0, void 0, function () {
|
|
4225
|
+
var _this = this;
|
|
4226
|
+
return __generator(this, function (_a) {
|
|
4227
|
+
switch (_a.label) {
|
|
4228
|
+
case 0:
|
|
4229
|
+
this.loggerService.log("storagePublicService list", {
|
|
4230
|
+
clientId: clientId,
|
|
4231
|
+
storageName: storageName,
|
|
4232
|
+
});
|
|
4233
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4234
|
+
return __generator(this, function (_a) {
|
|
4235
|
+
switch (_a.label) {
|
|
4236
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.list(filter)];
|
|
4237
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4238
|
+
}
|
|
4239
|
+
});
|
|
4240
|
+
}); }, {
|
|
4241
|
+
clientId: clientId,
|
|
4242
|
+
storageName: storageName,
|
|
4243
|
+
agentName: "",
|
|
4244
|
+
swarmName: "",
|
|
4245
|
+
})];
|
|
4246
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4247
|
+
}
|
|
4248
|
+
});
|
|
4249
|
+
}); };
|
|
4250
|
+
/**
|
|
4251
|
+
* Clears all items from the storage.
|
|
4252
|
+
* @returns {Promise<void>}
|
|
4253
|
+
*/
|
|
4254
|
+
this.clear = function (clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4255
|
+
var _this = this;
|
|
4256
|
+
return __generator(this, function (_a) {
|
|
4257
|
+
switch (_a.label) {
|
|
4258
|
+
case 0:
|
|
4259
|
+
this.loggerService.log("storagePublicService clear", {
|
|
4260
|
+
clientId: clientId,
|
|
4261
|
+
storageName: storageName,
|
|
4262
|
+
});
|
|
4263
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4264
|
+
return __generator(this, function (_a) {
|
|
4265
|
+
switch (_a.label) {
|
|
4266
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.clear()];
|
|
4267
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4268
|
+
}
|
|
4269
|
+
});
|
|
4270
|
+
}); }, {
|
|
4271
|
+
clientId: clientId,
|
|
4272
|
+
storageName: storageName,
|
|
4273
|
+
agentName: "",
|
|
4274
|
+
swarmName: "",
|
|
4275
|
+
})];
|
|
4276
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4277
|
+
}
|
|
4278
|
+
});
|
|
4279
|
+
}); };
|
|
4280
|
+
/**
|
|
4281
|
+
* Disposes of the storage.
|
|
4282
|
+
* @param {string} clientId - The client ID.
|
|
4283
|
+
* @param {StorageName} storageName - The storage name.
|
|
4284
|
+
* @returns {Promise<void>}
|
|
4285
|
+
*/
|
|
4286
|
+
this.dispose = function (clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
4287
|
+
var _this = this;
|
|
4288
|
+
return __generator(this, function (_a) {
|
|
4289
|
+
switch (_a.label) {
|
|
4290
|
+
case 0:
|
|
4291
|
+
this.loggerService.log("storagePublicService dispose", {
|
|
4292
|
+
clientId: clientId,
|
|
4293
|
+
storageName: storageName,
|
|
4294
|
+
});
|
|
4295
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
4296
|
+
return __generator(this, function (_a) {
|
|
4297
|
+
switch (_a.label) {
|
|
4298
|
+
case 0: return [4 /*yield*/, this.storageConnectionService.dispose()];
|
|
4299
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4300
|
+
}
|
|
4301
|
+
});
|
|
4302
|
+
}); }, {
|
|
4303
|
+
clientId: clientId,
|
|
4304
|
+
storageName: storageName,
|
|
4305
|
+
agentName: "",
|
|
4306
|
+
swarmName: "",
|
|
4307
|
+
})];
|
|
4308
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4309
|
+
}
|
|
4310
|
+
});
|
|
4311
|
+
}); };
|
|
4312
|
+
}
|
|
4313
|
+
return StoragePublicService;
|
|
4314
|
+
}());
|
|
4315
|
+
|
|
4316
|
+
/**
|
|
4317
|
+
* Service for validating storages within the storage swarm.
|
|
4318
|
+
*/
|
|
4319
|
+
var StorageValidationService = /** @class */ (function () {
|
|
4320
|
+
function StorageValidationService() {
|
|
4321
|
+
var _this = this;
|
|
4322
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
4323
|
+
this.embeddingValidationService = inject(TYPES.embeddingValidationService);
|
|
4324
|
+
this._storageMap = new Map();
|
|
4325
|
+
/**
|
|
4326
|
+
* Adds a new storage to the validation service.
|
|
4327
|
+
* @param {StorageName} storageName - The name of the storage.
|
|
4328
|
+
* @param {IStorageSchema} storageSchema - The schema of the storage.
|
|
4329
|
+
* @throws {Error} If the storage already exists.
|
|
4330
|
+
*/
|
|
4331
|
+
this.addStorage = function (storageName, storageSchema) {
|
|
4332
|
+
_this.loggerService.log("storageValidationService addStorage", {
|
|
4333
|
+
storageName: storageName,
|
|
4334
|
+
storageSchema: storageSchema,
|
|
4335
|
+
});
|
|
4336
|
+
if (_this._storageMap.has(storageName)) {
|
|
4337
|
+
throw new Error("storage-swarm storage ".concat(storageName, " already exist"));
|
|
4338
|
+
}
|
|
4339
|
+
_this._storageMap.set(storageName, storageSchema);
|
|
4340
|
+
};
|
|
4341
|
+
/**
|
|
4342
|
+
* Validates an storage by its name and source.
|
|
4343
|
+
* @param {StorageName} storageName - The name of the storage.
|
|
4344
|
+
* @param {string} source - The source of the validation request.
|
|
4345
|
+
* @throws {Error} If the storage is not found.
|
|
4346
|
+
*/
|
|
4347
|
+
this.validate = functoolsKit.memoize(function (_a) {
|
|
4348
|
+
var _b = __read(_a, 1), storageName = _b[0];
|
|
4349
|
+
return storageName;
|
|
4350
|
+
}, function (storageName, source) {
|
|
4351
|
+
_this.loggerService.log("storageValidationService validate", {
|
|
4352
|
+
storageName: storageName,
|
|
4353
|
+
source: source,
|
|
4354
|
+
});
|
|
4355
|
+
var storage = _this._storageMap.get(storageName);
|
|
4356
|
+
if (!storage) {
|
|
4357
|
+
throw new Error("storage-swarm storage ".concat(storageName, " not found source=").concat(source));
|
|
4358
|
+
}
|
|
4359
|
+
_this.embeddingValidationService.validate(storage.embedding, source);
|
|
4360
|
+
});
|
|
4361
|
+
}
|
|
4362
|
+
return StorageValidationService;
|
|
4363
|
+
}());
|
|
4364
|
+
|
|
4365
|
+
/**
|
|
4366
|
+
* Service for validating embeddings within the agent-swarm.
|
|
4367
|
+
*/
|
|
4368
|
+
var EmbeddingValidationService = /** @class */ (function () {
|
|
4369
|
+
function EmbeddingValidationService() {
|
|
4370
|
+
var _this = this;
|
|
4371
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
4372
|
+
this._embeddingMap = new Map();
|
|
4373
|
+
/**
|
|
4374
|
+
* Adds a new embedding to the validation service.
|
|
4375
|
+
* @param {EmbeddingName} embeddingName - The name of the embedding to add.
|
|
4376
|
+
* @param {IAgentEmbedding} embeddingSchema - The schema of the embedding to add.
|
|
4377
|
+
* @throws Will throw an error if the embedding already exists.
|
|
4378
|
+
*/
|
|
4379
|
+
this.addEmbedding = function (embeddingName, embeddingSchema) {
|
|
4380
|
+
_this.loggerService.log("embeddingValidationService addEmbedding", {
|
|
4381
|
+
embeddingName: embeddingName,
|
|
4382
|
+
embeddingSchema: embeddingSchema,
|
|
4383
|
+
});
|
|
4384
|
+
if (_this._embeddingMap.has(embeddingName)) {
|
|
4385
|
+
throw new Error("agent-swarm embedding ".concat(embeddingName, " already exist"));
|
|
4386
|
+
}
|
|
4387
|
+
_this._embeddingMap.set(embeddingName, embeddingSchema);
|
|
4388
|
+
};
|
|
4389
|
+
/**
|
|
4390
|
+
* Validates if a embedding exists in the validation service.
|
|
4391
|
+
* @param {EmbeddingName} embeddingName - The name of the embedding to validate.
|
|
4392
|
+
* @param {string} source - The source of the validation request.
|
|
4393
|
+
* @throws Will throw an error if the embedding is not found.
|
|
4394
|
+
*/
|
|
4395
|
+
this.validate = functoolsKit.memoize(function (_a) {
|
|
4396
|
+
var _b = __read(_a, 1), embeddingName = _b[0];
|
|
4397
|
+
return embeddingName;
|
|
4398
|
+
}, function (embeddingName, source) {
|
|
4399
|
+
_this.loggerService.log("embeddingValidationService validate", {
|
|
4400
|
+
embeddingName: embeddingName,
|
|
4401
|
+
source: source,
|
|
4402
|
+
});
|
|
4403
|
+
if (!_this._embeddingMap.has(embeddingName)) {
|
|
4404
|
+
throw new Error("agent-swarm embedding ".concat(embeddingName, " not found source=").concat(source));
|
|
4405
|
+
}
|
|
4406
|
+
});
|
|
4407
|
+
}
|
|
4408
|
+
return EmbeddingValidationService;
|
|
4409
|
+
}());
|
|
4410
|
+
|
|
4411
|
+
{
|
|
4412
|
+
provide(TYPES.loggerService, function () { return new LoggerService(); });
|
|
4413
|
+
provide(TYPES.contextService, function () { return new ContextService(); });
|
|
4414
|
+
}
|
|
4415
|
+
{
|
|
4416
|
+
provide(TYPES.agentConnectionService, function () { return new AgentConnectionService(); });
|
|
4417
|
+
provide(TYPES.historyConnectionService, function () { return new HistoryConnectionService(); });
|
|
4418
|
+
provide(TYPES.swarmConnectionService, function () { return new SwarmConnectionService(); });
|
|
4419
|
+
provide(TYPES.sessionConnectionService, function () { return new SessionConnectionService(); });
|
|
4420
|
+
provide(TYPES.storageConnectionService, function () { return new StorageConnectionService(); });
|
|
4421
|
+
}
|
|
4422
|
+
{
|
|
4423
|
+
provide(TYPES.agentSchemaService, function () { return new AgentSchemaService(); });
|
|
4424
|
+
provide(TYPES.toolSchemaService, function () { return new ToolSchemaService(); });
|
|
4425
|
+
provide(TYPES.swarmSchemaService, function () { return new SwarmSchemaService(); });
|
|
4426
|
+
provide(TYPES.completionSchemaService, function () { return new CompletionSchemaService(); });
|
|
4427
|
+
provide(TYPES.embeddingSchemaService, function () { return new EmbeddingSchemaService(); });
|
|
4428
|
+
provide(TYPES.storageSchemaService, function () { return new StorageSchemaService(); });
|
|
4429
|
+
}
|
|
4430
|
+
{
|
|
4431
|
+
provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
|
|
4432
|
+
provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
|
|
4433
|
+
provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
|
|
4434
|
+
provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
|
|
4435
|
+
provide(TYPES.storagePublicService, function () { return new StoragePublicService(); });
|
|
4436
|
+
}
|
|
4437
|
+
{
|
|
4438
|
+
provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
|
|
4439
|
+
provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
|
|
4440
|
+
provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
|
|
4441
|
+
provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
|
|
4442
|
+
}
|
|
4443
|
+
{
|
|
4444
|
+
provide(TYPES.agentValidationService, function () { return new AgentValidationService(); });
|
|
4445
|
+
provide(TYPES.completionValidationService, function () { return new CompletionValidationService(); });
|
|
4446
|
+
provide(TYPES.sessionValidationService, function () { return new SessionValidationService(); });
|
|
4447
|
+
provide(TYPES.swarmValidationService, function () { return new SwarmValidationService(); });
|
|
4448
|
+
provide(TYPES.toolValidationService, function () { return new ToolValidationService(); });
|
|
4449
|
+
provide(TYPES.storageValidationService, function () { return new StorageValidationService(); });
|
|
4450
|
+
provide(TYPES.embeddingValidationService, function () { return new EmbeddingValidationService(); });
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
var baseServices = {
|
|
4454
|
+
loggerService: inject(TYPES.loggerService),
|
|
4455
|
+
contextService: inject(TYPES.contextService),
|
|
4456
|
+
};
|
|
4457
|
+
var connectionServices = {
|
|
4458
|
+
agentConnectionService: inject(TYPES.agentConnectionService),
|
|
4459
|
+
historyConnectionService: inject(TYPES.historyConnectionService),
|
|
4460
|
+
swarmConnectionService: inject(TYPES.swarmConnectionService),
|
|
4461
|
+
sessionConnectionService: inject(TYPES.sessionConnectionService),
|
|
4462
|
+
storageConnectionService: inject(TYPES.storageConnectionService),
|
|
4463
|
+
};
|
|
4464
|
+
var schemaServices = {
|
|
4465
|
+
agentSchemaService: inject(TYPES.agentSchemaService),
|
|
4466
|
+
toolSchemaService: inject(TYPES.toolSchemaService),
|
|
4467
|
+
swarmSchemaService: inject(TYPES.swarmSchemaService),
|
|
4468
|
+
completionSchemaService: inject(TYPES.completionSchemaService),
|
|
4469
|
+
embeddingSchemaService: inject(TYPES.embeddingSchemaService),
|
|
4470
|
+
storageSchemaService: inject(TYPES.storageSchemaService),
|
|
4471
|
+
};
|
|
4472
|
+
var publicServices = {
|
|
4473
|
+
agentPublicService: inject(TYPES.agentPublicService),
|
|
4474
|
+
historyPublicService: inject(TYPES.historyPublicService),
|
|
4475
|
+
sessionPublicService: inject(TYPES.sessionPublicService),
|
|
4476
|
+
swarmPublicService: inject(TYPES.swarmPublicService),
|
|
4477
|
+
storagePublicService: inject(TYPES.storagePublicService),
|
|
4478
|
+
};
|
|
4479
|
+
var validationServices = {
|
|
4480
|
+
agentValidationService: inject(TYPES.agentValidationService),
|
|
4481
|
+
toolValidationService: inject(TYPES.toolValidationService),
|
|
4482
|
+
sessionValidationService: inject(TYPES.sessionValidationService),
|
|
4483
|
+
swarmValidationService: inject(TYPES.swarmValidationService),
|
|
4484
|
+
completionValidationService: inject(TYPES.completionValidationService),
|
|
4485
|
+
storageValidationService: inject(TYPES.storageValidationService),
|
|
4486
|
+
embeddingValidationService: inject(TYPES.embeddingValidationService),
|
|
4487
|
+
};
|
|
4488
|
+
var swarm = __assign(__assign(__assign(__assign(__assign({}, baseServices), connectionServices), schemaServices), publicServices), validationServices);
|
|
4489
|
+
init();
|
|
4490
|
+
|
|
4491
|
+
/**
|
|
4492
|
+
* Adds a new agent to the agent registry. The swarm takes only those agents which was registered
|
|
4493
|
+
*
|
|
4494
|
+
* @param {IAgentSchema} agentSchema - The schema of the agent to be added.
|
|
4495
|
+
* @returns {string} The name of the added agent.
|
|
4496
|
+
*/
|
|
4497
|
+
var addAgent = function (agentSchema) {
|
|
4498
|
+
swarm.loggerService.log('function addAgent', {
|
|
4499
|
+
agentSchema: agentSchema
|
|
4500
|
+
});
|
|
4501
|
+
swarm.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
|
|
4502
|
+
swarm.agentSchemaService.register(agentSchema.agentName, agentSchema);
|
|
4503
|
+
return agentSchema.agentName;
|
|
4504
|
+
};
|
|
4505
|
+
|
|
4506
|
+
/**
|
|
4507
|
+
* Adds a completion engine for agents. Agents could use different models and
|
|
4508
|
+
* framewords for completion like: mock, gpt4all, ollama, openai
|
|
4509
|
+
*
|
|
4510
|
+
* @param {ICompletionSchema} completionSchema - The completion schema to be added.
|
|
4511
|
+
* @returns {string} The name of the completion that was added.
|
|
4512
|
+
*/
|
|
4513
|
+
var addCompletion = function (completionSchema) {
|
|
4514
|
+
swarm.loggerService.log('function addCompletion', {
|
|
4515
|
+
completionSchema: completionSchema,
|
|
4516
|
+
});
|
|
4517
|
+
swarm.completionValidationService.addCompletion(completionSchema.completionName);
|
|
4518
|
+
swarm.completionSchemaService.register(completionSchema.completionName, completionSchema);
|
|
4519
|
+
return completionSchema.completionName;
|
|
4520
|
+
};
|
|
4521
|
+
|
|
4522
|
+
/**
|
|
4523
|
+
* Adds a new swarm to the system. The swarm is a root for starting client session
|
|
4524
|
+
*
|
|
4525
|
+
* @param {ISwarmSchema} swarmSchema - The schema of the swarm to be added.
|
|
4526
|
+
* @returns {string} The name of the added swarm.
|
|
4527
|
+
*/
|
|
4528
|
+
var addSwarm = function (swarmSchema) {
|
|
4529
|
+
swarm.loggerService.log('function addSwarm', {
|
|
4530
|
+
swarmSchema: swarmSchema,
|
|
4531
|
+
});
|
|
4532
|
+
swarm.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
|
|
4533
|
+
swarm.swarmSchemaService.register(swarmSchema.swarmName, swarmSchema);
|
|
4534
|
+
return swarmSchema.swarmName;
|
|
4535
|
+
};
|
|
4536
|
+
|
|
4537
|
+
/**
|
|
4538
|
+
* Adds a new tool for agents in a swarm. Tool should be registered in `addAgent`
|
|
4539
|
+
* declaration
|
|
4540
|
+
*
|
|
4541
|
+
* @param {IAgentTool} toolSchema - The schema of the tool to be added.
|
|
4542
|
+
* @returns {string} The name of the tool that was added.
|
|
4543
|
+
*/
|
|
4544
|
+
var addTool = function (toolSchema) {
|
|
3636
4545
|
swarm.loggerService.log('function addTool', {
|
|
3637
4546
|
toolSchema: toolSchema,
|
|
3638
4547
|
});
|
|
@@ -3641,6 +4550,36 @@ var addTool = function (toolSchema) {
|
|
|
3641
4550
|
return toolSchema.toolName;
|
|
3642
4551
|
};
|
|
3643
4552
|
|
|
4553
|
+
/**
|
|
4554
|
+
* Adds a new embedding to the embedding registry. The swarm takes only those embeddings which was registered
|
|
4555
|
+
*
|
|
4556
|
+
* @param {IEmbeddingSchema} embeddingSchema - The schema of the embedding to be added.
|
|
4557
|
+
* @returns {string} The name of the added embedding.
|
|
4558
|
+
*/
|
|
4559
|
+
var addEmbedding = function (embeddingSchema) {
|
|
4560
|
+
swarm.loggerService.log('function addEmbedding', {
|
|
4561
|
+
embeddingSchema: embeddingSchema
|
|
4562
|
+
});
|
|
4563
|
+
swarm.embeddingValidationService.addEmbedding(embeddingSchema.embeddingName, embeddingSchema);
|
|
4564
|
+
swarm.embeddingSchemaService.register(embeddingSchema.embeddingName, embeddingSchema);
|
|
4565
|
+
return embeddingSchema.embeddingName;
|
|
4566
|
+
};
|
|
4567
|
+
|
|
4568
|
+
/**
|
|
4569
|
+
* Adds a new storage to the storage registry. The swarm takes only those storages which was registered
|
|
4570
|
+
*
|
|
4571
|
+
* @param {IStorageSchema} storageSchema - The schema of the storage to be added.
|
|
4572
|
+
* @returns {string} The name of the added storage.
|
|
4573
|
+
*/
|
|
4574
|
+
var addStorage = function (storageSchema) {
|
|
4575
|
+
swarm.loggerService.log('function addStorage', {
|
|
4576
|
+
storageSchema: storageSchema
|
|
4577
|
+
});
|
|
4578
|
+
swarm.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
|
|
4579
|
+
swarm.storageSchemaService.register(storageSchema.storageName, storageSchema);
|
|
4580
|
+
return storageSchema.storageName;
|
|
4581
|
+
};
|
|
4582
|
+
|
|
3644
4583
|
/**
|
|
3645
4584
|
* Commits a user message to the active agent history in as swarm without answer.
|
|
3646
4585
|
*
|
|
@@ -3952,6 +4891,25 @@ var disposeConnection = function (clientId, swarmName) { return __awaiter(void 0
|
|
|
3952
4891
|
}); }),
|
|
3953
4892
|
])];
|
|
3954
4893
|
case 3:
|
|
4894
|
+
_a.sent();
|
|
4895
|
+
return [4 /*yield*/, Promise.all([
|
|
4896
|
+
swarm.swarmValidationService
|
|
4897
|
+
.getAgentList(swarmName)
|
|
4898
|
+
.flatMap(function (agentName) {
|
|
4899
|
+
return swarm.agentValidationService.getStorageList(agentName);
|
|
4900
|
+
})
|
|
4901
|
+
.map(function (storageName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4902
|
+
return __generator(this, function (_a) {
|
|
4903
|
+
switch (_a.label) {
|
|
4904
|
+
case 0: return [4 /*yield*/, swarm.storagePublicService.dispose(clientId, storageName)];
|
|
4905
|
+
case 1:
|
|
4906
|
+
_a.sent();
|
|
4907
|
+
return [2 /*return*/];
|
|
4908
|
+
}
|
|
4909
|
+
});
|
|
4910
|
+
}); }),
|
|
4911
|
+
])];
|
|
4912
|
+
case 4:
|
|
3955
4913
|
_a.sent();
|
|
3956
4914
|
return [2 /*return*/];
|
|
3957
4915
|
}
|
|
@@ -4797,9 +5755,179 @@ var makeAutoDispose = function (clientId, swarmName, _a) {
|
|
|
4797
5755
|
};
|
|
4798
5756
|
};
|
|
4799
5757
|
|
|
5758
|
+
var StorageUtils = /** @class */ (function () {
|
|
5759
|
+
function StorageUtils() {
|
|
5760
|
+
var _this = this;
|
|
5761
|
+
/**
|
|
5762
|
+
* Takes items from the storage.
|
|
5763
|
+
* @param {string} search - The search query.
|
|
5764
|
+
* @param {number} total - The total number of items to take.
|
|
5765
|
+
* @param {string} clientId - The client ID.
|
|
5766
|
+
* @param {AgentName} agentName - The agent name.
|
|
5767
|
+
* @param {StorageName} storageName - The storage name.
|
|
5768
|
+
* @returns {Promise<T[]>} - A promise that resolves to an array of items.
|
|
5769
|
+
* @template T
|
|
5770
|
+
*/
|
|
5771
|
+
this.take = function (search, total, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5772
|
+
return __generator(this, function (_a) {
|
|
5773
|
+
switch (_a.label) {
|
|
5774
|
+
case 0:
|
|
5775
|
+
swarm.loggerService.log("StorageStatic take", {
|
|
5776
|
+
search: search,
|
|
5777
|
+
total: total,
|
|
5778
|
+
clientId: clientId,
|
|
5779
|
+
storageName: storageName,
|
|
5780
|
+
});
|
|
5781
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5782
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5783
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (take)"));
|
|
5784
|
+
}
|
|
5785
|
+
return [4 /*yield*/, swarm.storagePublicService.take(search, total, clientId, storageName)];
|
|
5786
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
5787
|
+
}
|
|
5788
|
+
});
|
|
5789
|
+
}); };
|
|
5790
|
+
/**
|
|
5791
|
+
* Upserts an item in the storage.
|
|
5792
|
+
* @param {T} item - The item to upsert.
|
|
5793
|
+
* @param {string} clientId - The client ID.
|
|
5794
|
+
* @param {AgentName} agentName - The agent name.
|
|
5795
|
+
* @param {StorageName} storageName - The storage name.
|
|
5796
|
+
* @returns {Promise<void>} - A promise that resolves when the operation is complete.
|
|
5797
|
+
* @template T
|
|
5798
|
+
*/
|
|
5799
|
+
this.upsert = function (item, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5800
|
+
return __generator(this, function (_a) {
|
|
5801
|
+
switch (_a.label) {
|
|
5802
|
+
case 0:
|
|
5803
|
+
swarm.loggerService.log("StorageStatic upsert", {
|
|
5804
|
+
item: item,
|
|
5805
|
+
clientId: clientId,
|
|
5806
|
+
storageName: storageName,
|
|
5807
|
+
});
|
|
5808
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5809
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5810
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (upsert)"));
|
|
5811
|
+
}
|
|
5812
|
+
return [4 /*yield*/, swarm.storagePublicService.upsert(item, clientId, storageName)];
|
|
5813
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5814
|
+
}
|
|
5815
|
+
});
|
|
5816
|
+
}); };
|
|
5817
|
+
/**
|
|
5818
|
+
* Removes an item from the storage.
|
|
5819
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to remove.
|
|
5820
|
+
* @param {string} clientId - The client ID.
|
|
5821
|
+
* @param {AgentName} agentName - The agent name.
|
|
5822
|
+
* @param {StorageName} storageName - The storage name.
|
|
5823
|
+
* @returns {Promise<void>} - A promise that resolves when the operation is complete.
|
|
5824
|
+
*/
|
|
5825
|
+
this.remove = function (itemId, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5826
|
+
return __generator(this, function (_a) {
|
|
5827
|
+
switch (_a.label) {
|
|
5828
|
+
case 0:
|
|
5829
|
+
swarm.loggerService.log("StorageStatic remove", {
|
|
5830
|
+
itemId: itemId,
|
|
5831
|
+
clientId: clientId,
|
|
5832
|
+
storageName: storageName,
|
|
5833
|
+
});
|
|
5834
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5835
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5836
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (remove)"));
|
|
5837
|
+
}
|
|
5838
|
+
return [4 /*yield*/, swarm.storagePublicService.remove(itemId, clientId, storageName)];
|
|
5839
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5840
|
+
}
|
|
5841
|
+
});
|
|
5842
|
+
}); };
|
|
5843
|
+
/**
|
|
5844
|
+
* Gets an item from the storage.
|
|
5845
|
+
* @param {IStorageData["id"]} itemId - The ID of the item to get.
|
|
5846
|
+
* @param {string} clientId - The client ID.
|
|
5847
|
+
* @param {AgentName} agentName - The agent name.
|
|
5848
|
+
* @param {StorageName} storageName - The storage name.
|
|
5849
|
+
* @returns {Promise<T | null>} - A promise that resolves to the item or null if not found.
|
|
5850
|
+
* @template T
|
|
5851
|
+
*/
|
|
5852
|
+
this.get = function (itemId, clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5853
|
+
return __generator(this, function (_a) {
|
|
5854
|
+
switch (_a.label) {
|
|
5855
|
+
case 0:
|
|
5856
|
+
swarm.loggerService.log("StorageStatic get", {
|
|
5857
|
+
itemId: itemId,
|
|
5858
|
+
clientId: clientId,
|
|
5859
|
+
storageName: storageName,
|
|
5860
|
+
});
|
|
5861
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5862
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5863
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (get)"));
|
|
5864
|
+
}
|
|
5865
|
+
return [4 /*yield*/, swarm.storagePublicService.get(itemId, clientId, storageName)];
|
|
5866
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
5867
|
+
}
|
|
5868
|
+
});
|
|
5869
|
+
}); };
|
|
5870
|
+
/**
|
|
5871
|
+
* Lists items from the storage.
|
|
5872
|
+
* @param {string} clientId - The client ID.
|
|
5873
|
+
* @param {AgentName} agentName - The agent name.
|
|
5874
|
+
* @param {StorageName} storageName - The storage name.
|
|
5875
|
+
* @param {(item: T) => boolean} [filter] - Optional filter function.
|
|
5876
|
+
* @returns {Promise<T[]>} - A promise that resolves to an array of items.
|
|
5877
|
+
* @template T
|
|
5878
|
+
*/
|
|
5879
|
+
this.list = function (clientId, agentName, storageName, filter) { return __awaiter(_this, void 0, void 0, function () {
|
|
5880
|
+
return __generator(this, function (_a) {
|
|
5881
|
+
switch (_a.label) {
|
|
5882
|
+
case 0:
|
|
5883
|
+
swarm.loggerService.log("StorageStatic list", {
|
|
5884
|
+
clientId: clientId,
|
|
5885
|
+
storageName: storageName,
|
|
5886
|
+
});
|
|
5887
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5888
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5889
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (list)"));
|
|
5890
|
+
}
|
|
5891
|
+
return [4 /*yield*/, swarm.storagePublicService.list(clientId, storageName, filter)];
|
|
5892
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
5893
|
+
}
|
|
5894
|
+
});
|
|
5895
|
+
}); };
|
|
5896
|
+
/**
|
|
5897
|
+
* Clears the storage.
|
|
5898
|
+
* @param {string} clientId - The client ID.
|
|
5899
|
+
* @param {AgentName} agentName - The agent name.
|
|
5900
|
+
* @param {StorageName} storageName - The storage name.
|
|
5901
|
+
* @returns {Promise<void>} - A promise that resolves when the operation is complete.
|
|
5902
|
+
*/
|
|
5903
|
+
this.clear = function (clientId, agentName, storageName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5904
|
+
return __generator(this, function (_a) {
|
|
5905
|
+
switch (_a.label) {
|
|
5906
|
+
case 0:
|
|
5907
|
+
swarm.loggerService.log("StorageStatic clear", {
|
|
5908
|
+
clientId: clientId,
|
|
5909
|
+
storageName: storageName,
|
|
5910
|
+
});
|
|
5911
|
+
swarm.storageValidationService.validate(storageName, "StorageStatic");
|
|
5912
|
+
if (!swarm.agentValidationService.hasStorage(agentName, storageName)) {
|
|
5913
|
+
throw new Error("agent-swarm StorageUtils ".concat(storageName, " not registered in ").concat(agentName, " (clear)"));
|
|
5914
|
+
}
|
|
5915
|
+
return [4 /*yield*/, swarm.storagePublicService.clear(clientId, storageName)];
|
|
5916
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5917
|
+
}
|
|
5918
|
+
});
|
|
5919
|
+
}); };
|
|
5920
|
+
}
|
|
5921
|
+
return StorageUtils;
|
|
5922
|
+
}());
|
|
5923
|
+
var Storage = new StorageUtils();
|
|
5924
|
+
|
|
4800
5925
|
exports.ContextService = ContextService;
|
|
5926
|
+
exports.Storage = Storage;
|
|
4801
5927
|
exports.addAgent = addAgent;
|
|
4802
5928
|
exports.addCompletion = addCompletion;
|
|
5929
|
+
exports.addEmbedding = addEmbedding;
|
|
5930
|
+
exports.addStorage = addStorage;
|
|
4803
5931
|
exports.addSwarm = addSwarm;
|
|
4804
5932
|
exports.addTool = addTool;
|
|
4805
5933
|
exports.changeAgent = changeAgent;
|