agent-swarm-kit 1.0.34 → 1.0.35
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 +48 -38
- package/build/index.mjs +49 -39
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/build/index.cjs
CHANGED
|
@@ -397,13 +397,11 @@ var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
|
397
397
|
"}",
|
|
398
398
|
];
|
|
399
399
|
var CC_KEEP_MESSAGES = 5;
|
|
400
|
-
var CC_ANSWER_TIMEOUT = 120000;
|
|
401
400
|
var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
|
|
402
401
|
var GLOBAL_CONFIG = {
|
|
403
402
|
CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
404
403
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
405
404
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
406
|
-
CC_ANSWER_TIMEOUT: CC_ANSWER_TIMEOUT,
|
|
407
405
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
408
406
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
409
407
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
@@ -1325,7 +1323,6 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
1325
1323
|
return ToolSchemaService;
|
|
1326
1324
|
}());
|
|
1327
1325
|
|
|
1328
|
-
var AGENT_REF_CHANGED = Symbol("agent-ref-changed");
|
|
1329
1326
|
var AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
1330
1327
|
/**
|
|
1331
1328
|
* ClientSwarm class implements the ISwarm interface and manages agents within a swarm.
|
|
@@ -1346,47 +1343,53 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1346
1343
|
* @throws {Error} - If the timeout is reached.
|
|
1347
1344
|
*/
|
|
1348
1345
|
this.waitForOutput = functoolsKit.queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1349
|
-
var
|
|
1346
|
+
var _a, awaiter, resolve, getOutput, handleOutput, un, _b, agentName, output, expectAgent;
|
|
1350
1347
|
var _this = this;
|
|
1351
1348
|
return __generator(this, function (_c) {
|
|
1352
1349
|
switch (_c.label) {
|
|
1353
1350
|
case 0:
|
|
1354
1351
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForOutput"));
|
|
1355
|
-
|
|
1356
|
-
|
|
1352
|
+
_a = __read(functoolsKit.createAwaiter(), 2), awaiter = _a[0], resolve = _a[1].resolve;
|
|
1353
|
+
getOutput = functoolsKit.cancelable(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1354
|
+
var _this = this;
|
|
1355
|
+
return __generator(this, function (_a) {
|
|
1356
|
+
switch (_a.label) {
|
|
1357
|
+
case 0: return [4 /*yield*/, Promise.race(this._agentList.map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
1358
|
+
var _c;
|
|
1359
|
+
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
1360
|
+
return __generator(this, function (_e) {
|
|
1361
|
+
switch (_e.label) {
|
|
1362
|
+
case 0:
|
|
1363
|
+
_c = { agentName: agentName };
|
|
1364
|
+
return [4 /*yield*/, agent.waitForOutput()];
|
|
1365
|
+
case 1: return [2 /*return*/, (_c.output = _e.sent(), _c)];
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}); }))];
|
|
1369
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
}); });
|
|
1373
|
+
handleOutput = function () {
|
|
1374
|
+
getOutput.cancel();
|
|
1375
|
+
getOutput().then(function (value) {
|
|
1376
|
+
if (value === functoolsKit.CANCELED_PROMISE_SYMBOL) {
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
resolve(value);
|
|
1380
|
+
});
|
|
1381
|
+
};
|
|
1382
|
+
un = this._agentChangedSubject.subscribe(handleOutput);
|
|
1383
|
+
handleOutput();
|
|
1384
|
+
return [4 /*yield*/, awaiter];
|
|
1357
1385
|
case 1:
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1361
|
-
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
1362
|
-
var _c;
|
|
1363
|
-
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
1364
|
-
return __generator(this, function (_e) {
|
|
1365
|
-
switch (_e.label) {
|
|
1366
|
-
case 0:
|
|
1367
|
-
_c = [agentName];
|
|
1368
|
-
return [4 /*yield*/, agent.waitForOutput()];
|
|
1369
|
-
case 1: return [2 /*return*/, _c.concat([_e.sent()])];
|
|
1370
|
-
}
|
|
1371
|
-
});
|
|
1372
|
-
}); })), false), [
|
|
1373
|
-
this._agentChangedSubject
|
|
1374
|
-
.toPromise()
|
|
1375
|
-
.then(function () { return [AGENT_REF_CHANGED]; }),
|
|
1376
|
-
], false))];
|
|
1377
|
-
case 2:
|
|
1378
|
-
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
1379
|
-
if (agentName === AGENT_REF_CHANGED) {
|
|
1380
|
-
return [3 /*break*/, 1];
|
|
1381
|
-
}
|
|
1382
|
-
_b = agentName;
|
|
1386
|
+
_b = _c.sent(), agentName = _b.agentName, output = _b.output;
|
|
1387
|
+
un();
|
|
1383
1388
|
return [4 /*yield*/, this.getAgentName()];
|
|
1384
|
-
case
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return [3 /*break*/, 1];
|
|
1389
|
-
case 4: return [2 /*return*/];
|
|
1389
|
+
case 2:
|
|
1390
|
+
expectAgent = _c.sent();
|
|
1391
|
+
agentName !== expectAgent && this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForAgent agent miss"), { agentName: agentName, expectAgent: expectAgent });
|
|
1392
|
+
return [2 /*return*/, output];
|
|
1390
1393
|
}
|
|
1391
1394
|
});
|
|
1392
1395
|
}); });
|
|
@@ -1442,7 +1445,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1442
1445
|
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1443
1446
|
}
|
|
1444
1447
|
this.params.agentMap[agentName] = agent;
|
|
1445
|
-
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1448
|
+
return [4 /*yield*/, this._agentChangedSubject.next([agentName, agent])];
|
|
1446
1449
|
case 1:
|
|
1447
1450
|
_a.sent();
|
|
1448
1451
|
return [2 /*return*/];
|
|
@@ -1470,6 +1473,13 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1470
1473
|
params: params,
|
|
1471
1474
|
});
|
|
1472
1475
|
}
|
|
1476
|
+
Object.defineProperty(ClientSwarm.prototype, "_agentList", {
|
|
1477
|
+
get: function () {
|
|
1478
|
+
return Object.entries(this.params.agentMap);
|
|
1479
|
+
},
|
|
1480
|
+
enumerable: false,
|
|
1481
|
+
configurable: true
|
|
1482
|
+
});
|
|
1473
1483
|
return ClientSwarm;
|
|
1474
1484
|
}());
|
|
1475
1485
|
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scoped } from 'di-scoped';
|
|
2
|
-
import { ToolRegistry, trycatch, sleep, PubsubArrayAdapter, Subject, queued, not, memoize, schedule, ttl, singleshot, Source } from 'functools-kit';
|
|
2
|
+
import { ToolRegistry, trycatch, sleep, PubsubArrayAdapter, Subject, queued, not, memoize, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, schedule, ttl, singleshot, Source } from 'functools-kit';
|
|
3
3
|
import { createActivator } from 'di-kit';
|
|
4
4
|
import { omit } from 'lodash-es';
|
|
5
5
|
import xml2js from 'xml2js';
|
|
@@ -395,13 +395,11 @@ var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
|
395
395
|
"}",
|
|
396
396
|
];
|
|
397
397
|
var CC_KEEP_MESSAGES = 5;
|
|
398
|
-
var CC_ANSWER_TIMEOUT = 120000;
|
|
399
398
|
var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
|
|
400
399
|
var GLOBAL_CONFIG = {
|
|
401
400
|
CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
402
401
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
403
402
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
404
|
-
CC_ANSWER_TIMEOUT: CC_ANSWER_TIMEOUT,
|
|
405
403
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
406
404
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
407
405
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
@@ -1323,7 +1321,6 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
1323
1321
|
return ToolSchemaService;
|
|
1324
1322
|
}());
|
|
1325
1323
|
|
|
1326
|
-
var AGENT_REF_CHANGED = Symbol("agent-ref-changed");
|
|
1327
1324
|
var AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
1328
1325
|
/**
|
|
1329
1326
|
* ClientSwarm class implements the ISwarm interface and manages agents within a swarm.
|
|
@@ -1344,47 +1341,53 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1344
1341
|
* @throws {Error} - If the timeout is reached.
|
|
1345
1342
|
*/
|
|
1346
1343
|
this.waitForOutput = queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1347
|
-
var
|
|
1344
|
+
var _a, awaiter, resolve, getOutput, handleOutput, un, _b, agentName, output, expectAgent;
|
|
1348
1345
|
var _this = this;
|
|
1349
1346
|
return __generator(this, function (_c) {
|
|
1350
1347
|
switch (_c.label) {
|
|
1351
1348
|
case 0:
|
|
1352
1349
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForOutput"));
|
|
1353
|
-
|
|
1354
|
-
|
|
1350
|
+
_a = __read(createAwaiter(), 2), awaiter = _a[0], resolve = _a[1].resolve;
|
|
1351
|
+
getOutput = cancelable(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1352
|
+
var _this = this;
|
|
1353
|
+
return __generator(this, function (_a) {
|
|
1354
|
+
switch (_a.label) {
|
|
1355
|
+
case 0: return [4 /*yield*/, Promise.race(this._agentList.map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
1356
|
+
var _c;
|
|
1357
|
+
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
1358
|
+
return __generator(this, function (_e) {
|
|
1359
|
+
switch (_e.label) {
|
|
1360
|
+
case 0:
|
|
1361
|
+
_c = { agentName: agentName };
|
|
1362
|
+
return [4 /*yield*/, agent.waitForOutput()];
|
|
1363
|
+
case 1: return [2 /*return*/, (_c.output = _e.sent(), _c)];
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
}); }))];
|
|
1367
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
}); });
|
|
1371
|
+
handleOutput = function () {
|
|
1372
|
+
getOutput.cancel();
|
|
1373
|
+
getOutput().then(function (value) {
|
|
1374
|
+
if (value === CANCELED_PROMISE_SYMBOL) {
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
resolve(value);
|
|
1378
|
+
});
|
|
1379
|
+
};
|
|
1380
|
+
un = this._agentChangedSubject.subscribe(handleOutput);
|
|
1381
|
+
handleOutput();
|
|
1382
|
+
return [4 /*yield*/, awaiter];
|
|
1355
1383
|
case 1:
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
1360
|
-
var _c;
|
|
1361
|
-
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
1362
|
-
return __generator(this, function (_e) {
|
|
1363
|
-
switch (_e.label) {
|
|
1364
|
-
case 0:
|
|
1365
|
-
_c = [agentName];
|
|
1366
|
-
return [4 /*yield*/, agent.waitForOutput()];
|
|
1367
|
-
case 1: return [2 /*return*/, _c.concat([_e.sent()])];
|
|
1368
|
-
}
|
|
1369
|
-
});
|
|
1370
|
-
}); })), false), [
|
|
1371
|
-
this._agentChangedSubject
|
|
1372
|
-
.toPromise()
|
|
1373
|
-
.then(function () { return [AGENT_REF_CHANGED]; }),
|
|
1374
|
-
], false))];
|
|
1375
|
-
case 2:
|
|
1376
|
-
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
1377
|
-
if (agentName === AGENT_REF_CHANGED) {
|
|
1378
|
-
return [3 /*break*/, 1];
|
|
1379
|
-
}
|
|
1380
|
-
_b = agentName;
|
|
1384
|
+
_b = _c.sent(), agentName = _b.agentName, output = _b.output;
|
|
1385
|
+
un();
|
|
1381
1386
|
return [4 /*yield*/, this.getAgentName()];
|
|
1382
|
-
case
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
return [3 /*break*/, 1];
|
|
1387
|
-
case 4: return [2 /*return*/];
|
|
1387
|
+
case 2:
|
|
1388
|
+
expectAgent = _c.sent();
|
|
1389
|
+
agentName !== expectAgent && this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForAgent agent miss"), { agentName: agentName, expectAgent: expectAgent });
|
|
1390
|
+
return [2 /*return*/, output];
|
|
1388
1391
|
}
|
|
1389
1392
|
});
|
|
1390
1393
|
}); });
|
|
@@ -1440,7 +1443,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1440
1443
|
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1441
1444
|
}
|
|
1442
1445
|
this.params.agentMap[agentName] = agent;
|
|
1443
|
-
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1446
|
+
return [4 /*yield*/, this._agentChangedSubject.next([agentName, agent])];
|
|
1444
1447
|
case 1:
|
|
1445
1448
|
_a.sent();
|
|
1446
1449
|
return [2 /*return*/];
|
|
@@ -1468,6 +1471,13 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1468
1471
|
params: params,
|
|
1469
1472
|
});
|
|
1470
1473
|
}
|
|
1474
|
+
Object.defineProperty(ClientSwarm.prototype, "_agentList", {
|
|
1475
|
+
get: function () {
|
|
1476
|
+
return Object.entries(this.params.agentMap);
|
|
1477
|
+
},
|
|
1478
|
+
enumerable: false,
|
|
1479
|
+
configurable: true
|
|
1480
|
+
});
|
|
1471
1481
|
return ClientSwarm;
|
|
1472
1482
|
}());
|
|
1473
1483
|
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -989,6 +989,7 @@ declare class ClientSwarm implements ISwarm {
|
|
|
989
989
|
readonly params: ISwarmParams;
|
|
990
990
|
private _agentChangedSubject;
|
|
991
991
|
private _activeAgent;
|
|
992
|
+
get _agentList(): [string, IAgent][];
|
|
992
993
|
/**
|
|
993
994
|
* Creates an instance of ClientSwarm.
|
|
994
995
|
* @param {ISwarmParams} params - The parameters for the swarm.
|
|
@@ -2039,7 +2040,6 @@ declare const GLOBAL_CONFIG: {
|
|
|
2039
2040
|
CC_TOOL_CALL_EXCEPTION_PROMPT: string;
|
|
2040
2041
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
|
|
2041
2042
|
CC_KEEP_MESSAGES: number;
|
|
2042
|
-
CC_ANSWER_TIMEOUT: number;
|
|
2043
2043
|
CC_GET_AGENT_HISTORY: (clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>;
|
|
2044
2044
|
CC_SWARM_AGENT_CHANGED: (clientId: string, agentName: AgentName, swarmName: SwarmName) => Promise<void>;
|
|
2045
2045
|
CC_SWARM_DEFAULT_AGENT: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName>;
|