agent-swarm-kit 1.0.11 → 1.0.12
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 +140 -10
- package/build/index.mjs +140 -10
- package/package.json +1 -1
- package/types.d.ts +6 -0
package/build/index.cjs
CHANGED
|
@@ -951,10 +951,12 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
951
951
|
return ToolSchemaService;
|
|
952
952
|
}());
|
|
953
953
|
|
|
954
|
+
var AGENT_REF_CHANGED = Symbol('agent-ref-changed');
|
|
954
955
|
var ClientSwarm = /** @class */ (function () {
|
|
955
956
|
function ClientSwarm(params) {
|
|
956
957
|
var _this = this;
|
|
957
958
|
this.params = params;
|
|
959
|
+
this._agentChangedSubject = new functoolsKit.Subject();
|
|
958
960
|
this.waitForOutput = functoolsKit.queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
959
961
|
var START_TIME, _a, agentName, output, _b;
|
|
960
962
|
var _this = this;
|
|
@@ -968,7 +970,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
968
970
|
if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
|
|
969
971
|
throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
|
|
970
972
|
}
|
|
971
|
-
return [4 /*yield*/, Promise.race(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
973
|
+
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
972
974
|
var _c;
|
|
973
975
|
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
974
976
|
return __generator(this, function (_e) {
|
|
@@ -981,9 +983,14 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
981
983
|
])];
|
|
982
984
|
}
|
|
983
985
|
});
|
|
984
|
-
}); }))
|
|
986
|
+
}); })), false), [
|
|
987
|
+
this._agentChangedSubject.toPromise().then(function () { return [AGENT_REF_CHANGED]; }),
|
|
988
|
+
], false))];
|
|
985
989
|
case 2:
|
|
986
990
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
991
|
+
if (agentName === AGENT_REF_CHANGED) {
|
|
992
|
+
return [3 /*break*/, 1];
|
|
993
|
+
}
|
|
987
994
|
_b = agentName;
|
|
988
995
|
return [4 /*yield*/, this.getAgentName()];
|
|
989
996
|
case 3:
|
|
@@ -1014,6 +1021,22 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1014
1021
|
}
|
|
1015
1022
|
});
|
|
1016
1023
|
}); };
|
|
1024
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1025
|
+
return __generator(this, function (_a) {
|
|
1026
|
+
switch (_a.label) {
|
|
1027
|
+
case 0:
|
|
1028
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentRef agentName=").concat(agentName));
|
|
1029
|
+
if (!this.params.agentMap[agentName]) {
|
|
1030
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1031
|
+
}
|
|
1032
|
+
this.params.agentMap[agentName] = agent;
|
|
1033
|
+
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1034
|
+
case 1:
|
|
1035
|
+
_a.sent();
|
|
1036
|
+
return [2 /*return*/];
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
}); };
|
|
1017
1040
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1018
1041
|
return __generator(this, function (_a) {
|
|
1019
1042
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
@@ -1098,6 +1121,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1098
1121
|
}
|
|
1099
1122
|
});
|
|
1100
1123
|
}); };
|
|
1124
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1125
|
+
return __generator(this, function (_a) {
|
|
1126
|
+
switch (_a.label) {
|
|
1127
|
+
case 0:
|
|
1128
|
+
this.loggerService.log("swarmConnectionService setAgentRef", {
|
|
1129
|
+
context: this.contextService.context,
|
|
1130
|
+
});
|
|
1131
|
+
return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentRef(agentName, agent)];
|
|
1132
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
}); };
|
|
1101
1136
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1102
1137
|
return __generator(this, function (_a) {
|
|
1103
1138
|
switch (_a.label) {
|
|
@@ -1354,6 +1389,31 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
1354
1389
|
var _this = this;
|
|
1355
1390
|
this.loggerService = inject(TYPES.loggerService);
|
|
1356
1391
|
this.agentConnectionService = inject(TYPES.agentConnectionService);
|
|
1392
|
+
this.createAgentRef = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1393
|
+
var _this = this;
|
|
1394
|
+
return __generator(this, function (_a) {
|
|
1395
|
+
switch (_a.label) {
|
|
1396
|
+
case 0:
|
|
1397
|
+
this.loggerService.log("agentPublicService createAgentRef", {
|
|
1398
|
+
clientId: clientId,
|
|
1399
|
+
agentName: agentName,
|
|
1400
|
+
});
|
|
1401
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1402
|
+
return __generator(this, function (_a) {
|
|
1403
|
+
switch (_a.label) {
|
|
1404
|
+
case 0: return [4 /*yield*/, this.agentConnectionService.getAgent(clientId, agentName)];
|
|
1405
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
}); }, {
|
|
1409
|
+
clientId: clientId,
|
|
1410
|
+
agentName: agentName,
|
|
1411
|
+
swarmName: "",
|
|
1412
|
+
})];
|
|
1413
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
}); };
|
|
1357
1417
|
this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1358
1418
|
var _this = this;
|
|
1359
1419
|
return __generator(this, function (_a) {
|
|
@@ -1830,6 +1890,33 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
1830
1890
|
}
|
|
1831
1891
|
});
|
|
1832
1892
|
}); };
|
|
1893
|
+
this.setAgentRef = function (clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1894
|
+
var _this = this;
|
|
1895
|
+
return __generator(this, function (_a) {
|
|
1896
|
+
switch (_a.label) {
|
|
1897
|
+
case 0:
|
|
1898
|
+
this.loggerService.log("swarmPublicService setAgentRef", {
|
|
1899
|
+
agentName: agentName,
|
|
1900
|
+
agent: agent,
|
|
1901
|
+
clientId: clientId,
|
|
1902
|
+
swarmName: swarmName,
|
|
1903
|
+
});
|
|
1904
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1905
|
+
return __generator(this, function (_a) {
|
|
1906
|
+
switch (_a.label) {
|
|
1907
|
+
case 0: return [4 /*yield*/, this.swarmConnectionService.setAgentRef(agentName, agent)];
|
|
1908
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
}); }, {
|
|
1912
|
+
clientId: clientId,
|
|
1913
|
+
swarmName: swarmName,
|
|
1914
|
+
agentName: "",
|
|
1915
|
+
})];
|
|
1916
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
}); };
|
|
1833
1920
|
this.setAgentName = function (agentName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1834
1921
|
var _this = this;
|
|
1835
1922
|
return __generator(this, function (_a) {
|
|
@@ -2279,18 +2366,61 @@ var makeConnection = function (connector, clientId, swarmName) {
|
|
|
2279
2366
|
}); });
|
|
2280
2367
|
};
|
|
2281
2368
|
|
|
2369
|
+
var CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
2370
|
+
var CHANGE_AGENT_GC = 60 * 1000;
|
|
2371
|
+
var createChangeAgent = functoolsKit.ttl(function (clientId) {
|
|
2372
|
+
return functoolsKit.queued(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2373
|
+
var swarmName, _a, _b, _c;
|
|
2374
|
+
return __generator(this, function (_d) {
|
|
2375
|
+
switch (_d.label) {
|
|
2376
|
+
case 0:
|
|
2377
|
+
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2378
|
+
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2379
|
+
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2380
|
+
return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
|
|
2381
|
+
case 1:
|
|
2382
|
+
_d.sent();
|
|
2383
|
+
return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
|
|
2384
|
+
case 2:
|
|
2385
|
+
_d.sent();
|
|
2386
|
+
_b = (_a = swarm.swarmPublicService).setAgentRef;
|
|
2387
|
+
_c = [clientId,
|
|
2388
|
+
swarmName,
|
|
2389
|
+
agentName];
|
|
2390
|
+
return [4 /*yield*/, swarm.agentPublicService.createAgentRef(clientId, agentName)];
|
|
2391
|
+
case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
|
|
2392
|
+
case 4:
|
|
2393
|
+
_d.sent();
|
|
2394
|
+
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2395
|
+
case 5:
|
|
2396
|
+
_d.sent();
|
|
2397
|
+
return [2 /*return*/];
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
}); });
|
|
2401
|
+
}, {
|
|
2402
|
+
key: function (_a) {
|
|
2403
|
+
var _b = __read(_a, 1), clientId = _b[0];
|
|
2404
|
+
return "".concat(clientId);
|
|
2405
|
+
},
|
|
2406
|
+
timeout: CHANGE_AGENT_TTL,
|
|
2407
|
+
});
|
|
2408
|
+
var createGc$1 = functoolsKit.singleshot(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2409
|
+
return __generator(this, function (_a) {
|
|
2410
|
+
setInterval(createChangeAgent.gc, CHANGE_AGENT_GC);
|
|
2411
|
+
return [2 /*return*/];
|
|
2412
|
+
});
|
|
2413
|
+
}); });
|
|
2282
2414
|
var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2283
|
-
var
|
|
2415
|
+
var run;
|
|
2284
2416
|
return __generator(this, function (_a) {
|
|
2285
2417
|
switch (_a.label) {
|
|
2286
|
-
case 0:
|
|
2287
|
-
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2288
|
-
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2289
|
-
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2290
|
-
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2418
|
+
case 0: return [4 /*yield*/, createChangeAgent(clientId)];
|
|
2291
2419
|
case 1:
|
|
2292
|
-
_a.sent();
|
|
2293
|
-
|
|
2420
|
+
run = _a.sent();
|
|
2421
|
+
createGc$1();
|
|
2422
|
+
return [4 /*yield*/, run(agentName)];
|
|
2423
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2294
2424
|
}
|
|
2295
2425
|
});
|
|
2296
2426
|
}); };
|
package/build/index.mjs
CHANGED
|
@@ -949,10 +949,12 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
949
949
|
return ToolSchemaService;
|
|
950
950
|
}());
|
|
951
951
|
|
|
952
|
+
var AGENT_REF_CHANGED = Symbol('agent-ref-changed');
|
|
952
953
|
var ClientSwarm = /** @class */ (function () {
|
|
953
954
|
function ClientSwarm(params) {
|
|
954
955
|
var _this = this;
|
|
955
956
|
this.params = params;
|
|
957
|
+
this._agentChangedSubject = new Subject();
|
|
956
958
|
this.waitForOutput = queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
957
959
|
var START_TIME, _a, agentName, output, _b;
|
|
958
960
|
var _this = this;
|
|
@@ -966,7 +968,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
966
968
|
if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
|
|
967
969
|
throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
|
|
968
970
|
}
|
|
969
|
-
return [4 /*yield*/, Promise.race(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
971
|
+
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
970
972
|
var _c;
|
|
971
973
|
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
972
974
|
return __generator(this, function (_e) {
|
|
@@ -979,9 +981,14 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
979
981
|
])];
|
|
980
982
|
}
|
|
981
983
|
});
|
|
982
|
-
}); }))
|
|
984
|
+
}); })), false), [
|
|
985
|
+
this._agentChangedSubject.toPromise().then(function () { return [AGENT_REF_CHANGED]; }),
|
|
986
|
+
], false))];
|
|
983
987
|
case 2:
|
|
984
988
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
989
|
+
if (agentName === AGENT_REF_CHANGED) {
|
|
990
|
+
return [3 /*break*/, 1];
|
|
991
|
+
}
|
|
985
992
|
_b = agentName;
|
|
986
993
|
return [4 /*yield*/, this.getAgentName()];
|
|
987
994
|
case 3:
|
|
@@ -1012,6 +1019,22 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1012
1019
|
}
|
|
1013
1020
|
});
|
|
1014
1021
|
}); };
|
|
1022
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1023
|
+
return __generator(this, function (_a) {
|
|
1024
|
+
switch (_a.label) {
|
|
1025
|
+
case 0:
|
|
1026
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentRef agentName=").concat(agentName));
|
|
1027
|
+
if (!this.params.agentMap[agentName]) {
|
|
1028
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1029
|
+
}
|
|
1030
|
+
this.params.agentMap[agentName] = agent;
|
|
1031
|
+
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1032
|
+
case 1:
|
|
1033
|
+
_a.sent();
|
|
1034
|
+
return [2 /*return*/];
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
}); };
|
|
1015
1038
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1016
1039
|
return __generator(this, function (_a) {
|
|
1017
1040
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
@@ -1096,6 +1119,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1096
1119
|
}
|
|
1097
1120
|
});
|
|
1098
1121
|
}); };
|
|
1122
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1123
|
+
return __generator(this, function (_a) {
|
|
1124
|
+
switch (_a.label) {
|
|
1125
|
+
case 0:
|
|
1126
|
+
this.loggerService.log("swarmConnectionService setAgentRef", {
|
|
1127
|
+
context: this.contextService.context,
|
|
1128
|
+
});
|
|
1129
|
+
return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentRef(agentName, agent)];
|
|
1130
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
}); };
|
|
1099
1134
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1100
1135
|
return __generator(this, function (_a) {
|
|
1101
1136
|
switch (_a.label) {
|
|
@@ -1352,6 +1387,31 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
1352
1387
|
var _this = this;
|
|
1353
1388
|
this.loggerService = inject(TYPES.loggerService);
|
|
1354
1389
|
this.agentConnectionService = inject(TYPES.agentConnectionService);
|
|
1390
|
+
this.createAgentRef = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1391
|
+
var _this = this;
|
|
1392
|
+
return __generator(this, function (_a) {
|
|
1393
|
+
switch (_a.label) {
|
|
1394
|
+
case 0:
|
|
1395
|
+
this.loggerService.log("agentPublicService createAgentRef", {
|
|
1396
|
+
clientId: clientId,
|
|
1397
|
+
agentName: agentName,
|
|
1398
|
+
});
|
|
1399
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1400
|
+
return __generator(this, function (_a) {
|
|
1401
|
+
switch (_a.label) {
|
|
1402
|
+
case 0: return [4 /*yield*/, this.agentConnectionService.getAgent(clientId, agentName)];
|
|
1403
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
}); }, {
|
|
1407
|
+
clientId: clientId,
|
|
1408
|
+
agentName: agentName,
|
|
1409
|
+
swarmName: "",
|
|
1410
|
+
})];
|
|
1411
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
}); };
|
|
1355
1415
|
this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1356
1416
|
var _this = this;
|
|
1357
1417
|
return __generator(this, function (_a) {
|
|
@@ -1828,6 +1888,33 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
1828
1888
|
}
|
|
1829
1889
|
});
|
|
1830
1890
|
}); };
|
|
1891
|
+
this.setAgentRef = function (clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1892
|
+
var _this = this;
|
|
1893
|
+
return __generator(this, function (_a) {
|
|
1894
|
+
switch (_a.label) {
|
|
1895
|
+
case 0:
|
|
1896
|
+
this.loggerService.log("swarmPublicService setAgentRef", {
|
|
1897
|
+
agentName: agentName,
|
|
1898
|
+
agent: agent,
|
|
1899
|
+
clientId: clientId,
|
|
1900
|
+
swarmName: swarmName,
|
|
1901
|
+
});
|
|
1902
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1903
|
+
return __generator(this, function (_a) {
|
|
1904
|
+
switch (_a.label) {
|
|
1905
|
+
case 0: return [4 /*yield*/, this.swarmConnectionService.setAgentRef(agentName, agent)];
|
|
1906
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
}); }, {
|
|
1910
|
+
clientId: clientId,
|
|
1911
|
+
swarmName: swarmName,
|
|
1912
|
+
agentName: "",
|
|
1913
|
+
})];
|
|
1914
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
}); };
|
|
1831
1918
|
this.setAgentName = function (agentName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1832
1919
|
var _this = this;
|
|
1833
1920
|
return __generator(this, function (_a) {
|
|
@@ -2277,18 +2364,61 @@ var makeConnection = function (connector, clientId, swarmName) {
|
|
|
2277
2364
|
}); });
|
|
2278
2365
|
};
|
|
2279
2366
|
|
|
2367
|
+
var CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
2368
|
+
var CHANGE_AGENT_GC = 60 * 1000;
|
|
2369
|
+
var createChangeAgent = ttl(function (clientId) {
|
|
2370
|
+
return queued(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2371
|
+
var swarmName, _a, _b, _c;
|
|
2372
|
+
return __generator(this, function (_d) {
|
|
2373
|
+
switch (_d.label) {
|
|
2374
|
+
case 0:
|
|
2375
|
+
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2376
|
+
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2377
|
+
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2378
|
+
return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
|
|
2379
|
+
case 1:
|
|
2380
|
+
_d.sent();
|
|
2381
|
+
return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
|
|
2382
|
+
case 2:
|
|
2383
|
+
_d.sent();
|
|
2384
|
+
_b = (_a = swarm.swarmPublicService).setAgentRef;
|
|
2385
|
+
_c = [clientId,
|
|
2386
|
+
swarmName,
|
|
2387
|
+
agentName];
|
|
2388
|
+
return [4 /*yield*/, swarm.agentPublicService.createAgentRef(clientId, agentName)];
|
|
2389
|
+
case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
|
|
2390
|
+
case 4:
|
|
2391
|
+
_d.sent();
|
|
2392
|
+
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2393
|
+
case 5:
|
|
2394
|
+
_d.sent();
|
|
2395
|
+
return [2 /*return*/];
|
|
2396
|
+
}
|
|
2397
|
+
});
|
|
2398
|
+
}); });
|
|
2399
|
+
}, {
|
|
2400
|
+
key: function (_a) {
|
|
2401
|
+
var _b = __read(_a, 1), clientId = _b[0];
|
|
2402
|
+
return "".concat(clientId);
|
|
2403
|
+
},
|
|
2404
|
+
timeout: CHANGE_AGENT_TTL,
|
|
2405
|
+
});
|
|
2406
|
+
var createGc$1 = singleshot(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2407
|
+
return __generator(this, function (_a) {
|
|
2408
|
+
setInterval(createChangeAgent.gc, CHANGE_AGENT_GC);
|
|
2409
|
+
return [2 /*return*/];
|
|
2410
|
+
});
|
|
2411
|
+
}); });
|
|
2280
2412
|
var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2281
|
-
var
|
|
2413
|
+
var run;
|
|
2282
2414
|
return __generator(this, function (_a) {
|
|
2283
2415
|
switch (_a.label) {
|
|
2284
|
-
case 0:
|
|
2285
|
-
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2286
|
-
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2287
|
-
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2288
|
-
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2416
|
+
case 0: return [4 /*yield*/, createChangeAgent(clientId)];
|
|
2289
2417
|
case 1:
|
|
2290
|
-
_a.sent();
|
|
2291
|
-
|
|
2418
|
+
run = _a.sent();
|
|
2419
|
+
createGc$1();
|
|
2420
|
+
return [4 /*yield*/, run(agentName)];
|
|
2421
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2292
2422
|
}
|
|
2293
2423
|
});
|
|
2294
2424
|
}); };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ interface ISwarm {
|
|
|
125
125
|
waitForOutput(): Promise<string>;
|
|
126
126
|
getAgentName(): Promise<AgentName>;
|
|
127
127
|
getAgent(): Promise<IAgent>;
|
|
128
|
+
setAgentRef(agentName: AgentName, agent: IAgent): Promise<void>;
|
|
128
129
|
setAgentName(agentName: AgentName): Promise<void>;
|
|
129
130
|
}
|
|
130
131
|
type SwarmName = string;
|
|
@@ -215,11 +216,13 @@ declare class ToolSchemaService {
|
|
|
215
216
|
|
|
216
217
|
declare class ClientSwarm implements ISwarm {
|
|
217
218
|
readonly params: ISwarmParams;
|
|
219
|
+
private _agentChangedSubject;
|
|
218
220
|
private _activeAgent;
|
|
219
221
|
constructor(params: ISwarmParams);
|
|
220
222
|
waitForOutput: () => Promise<string>;
|
|
221
223
|
getAgentName: () => Promise<AgentName>;
|
|
222
224
|
getAgent: () => Promise<IAgent>;
|
|
225
|
+
setAgentRef: (agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
223
226
|
setAgentName: (agentName: AgentName) => Promise<void>;
|
|
224
227
|
}
|
|
225
228
|
|
|
@@ -232,6 +235,7 @@ declare class SwarmConnectionService implements ISwarm {
|
|
|
232
235
|
waitForOutput: () => Promise<string>;
|
|
233
236
|
getAgentName: () => Promise<string>;
|
|
234
237
|
getAgent: () => Promise<IAgent>;
|
|
238
|
+
setAgentRef: (agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
235
239
|
setAgentName: (agentName: AgentName) => Promise<void>;
|
|
236
240
|
dispose: () => Promise<void>;
|
|
237
241
|
}
|
|
@@ -311,6 +315,7 @@ type TAgentConnectionService = {
|
|
|
311
315
|
declare class AgentPublicService implements TAgentConnectionService {
|
|
312
316
|
private readonly loggerService;
|
|
313
317
|
private readonly agentConnectionService;
|
|
318
|
+
createAgentRef: (clientId: string, agentName: AgentName) => Promise<ClientAgent>;
|
|
314
319
|
execute: (input: string, clientId: string, agentName: AgentName) => Promise<void>;
|
|
315
320
|
waitForOutput: (clientId: string, agentName: AgentName) => Promise<string>;
|
|
316
321
|
commitToolOutput: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
|
|
@@ -368,6 +373,7 @@ declare class SwarmPublicService implements TSwarmConnectionService {
|
|
|
368
373
|
waitForOutput: (clientId: string, swarmName: SwarmName) => Promise<string>;
|
|
369
374
|
getAgentName: (clientId: string, swarmName: SwarmName) => Promise<string>;
|
|
370
375
|
getAgent: (clientId: string, swarmName: SwarmName) => Promise<IAgent>;
|
|
376
|
+
setAgentRef: (clientId: string, swarmName: SwarmName, agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
371
377
|
setAgentName: (agentName: AgentName, clientId: string, swarmName: SwarmName) => Promise<void>;
|
|
372
378
|
dispose: (clientId: string, swarmName: SwarmName) => Promise<void>;
|
|
373
379
|
}
|