agent-swarm-kit 1.0.71 → 1.0.73
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 +143 -42
- package/build/index.mjs +143 -42
- package/package.json +1 -1
- package/types.d.ts +42 -20
package/build/index.cjs
CHANGED
|
@@ -983,7 +983,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
983
983
|
},
|
|
984
984
|
context: {
|
|
985
985
|
agentName: this.params.agentName,
|
|
986
|
-
}
|
|
986
|
+
},
|
|
987
|
+
clientId: this.params.clientId,
|
|
987
988
|
})];
|
|
988
989
|
case 7:
|
|
989
990
|
_a.sent();
|
|
@@ -1006,7 +1007,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1006
1007
|
},
|
|
1007
1008
|
context: {
|
|
1008
1009
|
agentName: this.params.agentName,
|
|
1009
|
-
}
|
|
1010
|
+
},
|
|
1011
|
+
clientId: this.params.clientId,
|
|
1010
1012
|
})];
|
|
1011
1013
|
case 10:
|
|
1012
1014
|
_a.sent();
|
|
@@ -1150,7 +1152,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1150
1152
|
output: {},
|
|
1151
1153
|
context: {
|
|
1152
1154
|
agentName: this.params.agentName,
|
|
1153
|
-
}
|
|
1155
|
+
},
|
|
1156
|
+
clientId: this.params.clientId,
|
|
1154
1157
|
})];
|
|
1155
1158
|
case 2:
|
|
1156
1159
|
_a.sent();
|
|
@@ -1184,7 +1187,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1184
1187
|
output: {},
|
|
1185
1188
|
context: {
|
|
1186
1189
|
agentName: this.params.agentName,
|
|
1187
|
-
}
|
|
1190
|
+
},
|
|
1191
|
+
clientId: this.params.clientId,
|
|
1188
1192
|
})];
|
|
1189
1193
|
case 2:
|
|
1190
1194
|
_a.sent();
|
|
@@ -1211,7 +1215,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1211
1215
|
output: {},
|
|
1212
1216
|
context: {
|
|
1213
1217
|
agentName: this.params.agentName,
|
|
1214
|
-
}
|
|
1218
|
+
},
|
|
1219
|
+
clientId: this.params.clientId,
|
|
1215
1220
|
})];
|
|
1216
1221
|
case 2:
|
|
1217
1222
|
_a.sent();
|
|
@@ -1248,7 +1253,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1248
1253
|
output: {},
|
|
1249
1254
|
context: {
|
|
1250
1255
|
agentName: this.params.agentName,
|
|
1251
|
-
}
|
|
1256
|
+
},
|
|
1257
|
+
clientId: this.params.clientId,
|
|
1252
1258
|
})];
|
|
1253
1259
|
case 2:
|
|
1254
1260
|
_a.sent();
|
|
@@ -1290,7 +1296,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1290
1296
|
output: {},
|
|
1291
1297
|
context: {
|
|
1292
1298
|
agentName: this.params.agentName,
|
|
1293
|
-
}
|
|
1299
|
+
},
|
|
1300
|
+
clientId: this.params.clientId,
|
|
1294
1301
|
})];
|
|
1295
1302
|
case 3:
|
|
1296
1303
|
_a.sent();
|
|
@@ -1725,7 +1732,8 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1725
1732
|
output: {},
|
|
1726
1733
|
context: {
|
|
1727
1734
|
agentName: this.params.agentName,
|
|
1728
|
-
}
|
|
1735
|
+
},
|
|
1736
|
+
clientId: this.params.clientId,
|
|
1729
1737
|
})];
|
|
1730
1738
|
case 2:
|
|
1731
1739
|
_a.sent();
|
|
@@ -2134,6 +2142,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2134
2142
|
context: {
|
|
2135
2143
|
swarmName: this.params.swarmName,
|
|
2136
2144
|
},
|
|
2145
|
+
clientId: this.params.clientId,
|
|
2137
2146
|
})];
|
|
2138
2147
|
case 3:
|
|
2139
2148
|
_d.sent();
|
|
@@ -2208,6 +2217,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2208
2217
|
context: {
|
|
2209
2218
|
swarmName: this.params.swarmName,
|
|
2210
2219
|
},
|
|
2220
|
+
clientId: this.params.clientId,
|
|
2211
2221
|
})];
|
|
2212
2222
|
case 3:
|
|
2213
2223
|
_c.sent();
|
|
@@ -2241,6 +2251,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2241
2251
|
context: {
|
|
2242
2252
|
swarmName: this.params.swarmName,
|
|
2243
2253
|
},
|
|
2254
|
+
clientId: this.params.clientId,
|
|
2244
2255
|
})];
|
|
2245
2256
|
case 3:
|
|
2246
2257
|
_b.sent();
|
|
@@ -2272,6 +2283,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2272
2283
|
context: {
|
|
2273
2284
|
swarmName: this.params.swarmName,
|
|
2274
2285
|
},
|
|
2286
|
+
clientId: this.params.clientId,
|
|
2275
2287
|
})];
|
|
2276
2288
|
case 2:
|
|
2277
2289
|
_a.sent();
|
|
@@ -2305,6 +2317,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2305
2317
|
context: {
|
|
2306
2318
|
swarmName: this.params.swarmName,
|
|
2307
2319
|
},
|
|
2320
|
+
clientId: this.params.clientId,
|
|
2308
2321
|
})];
|
|
2309
2322
|
case 1:
|
|
2310
2323
|
_a.sent();
|
|
@@ -2338,6 +2351,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2338
2351
|
context: {
|
|
2339
2352
|
swarmName: this.params.swarmName,
|
|
2340
2353
|
},
|
|
2354
|
+
clientId: this.params.clientId,
|
|
2341
2355
|
})];
|
|
2342
2356
|
case 2:
|
|
2343
2357
|
_a.sent();
|
|
@@ -2643,7 +2657,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2643
2657
|
output: {},
|
|
2644
2658
|
context: {
|
|
2645
2659
|
swarmName: this.params.swarmName,
|
|
2646
|
-
}
|
|
2660
|
+
},
|
|
2661
|
+
clientId: this.params.clientId,
|
|
2647
2662
|
})];
|
|
2648
2663
|
case 2:
|
|
2649
2664
|
_a.sent();
|
|
@@ -2688,7 +2703,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2688
2703
|
},
|
|
2689
2704
|
context: {
|
|
2690
2705
|
swarmName: this.params.swarmName,
|
|
2691
|
-
}
|
|
2706
|
+
},
|
|
2707
|
+
clientId: this.params.clientId,
|
|
2692
2708
|
})];
|
|
2693
2709
|
case 3:
|
|
2694
2710
|
_a.sent();
|
|
@@ -2727,7 +2743,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2727
2743
|
output: {},
|
|
2728
2744
|
context: {
|
|
2729
2745
|
swarmName: this.params.swarmName,
|
|
2730
|
-
}
|
|
2746
|
+
},
|
|
2747
|
+
clientId: this.params.clientId,
|
|
2731
2748
|
})];
|
|
2732
2749
|
case 3:
|
|
2733
2750
|
_a.sent();
|
|
@@ -2763,7 +2780,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2763
2780
|
output: {},
|
|
2764
2781
|
context: {
|
|
2765
2782
|
swarmName: this.params.swarmName,
|
|
2766
|
-
}
|
|
2783
|
+
},
|
|
2784
|
+
clientId: this.params.clientId,
|
|
2767
2785
|
})];
|
|
2768
2786
|
case 3:
|
|
2769
2787
|
_a.sent();
|
|
@@ -2794,7 +2812,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2794
2812
|
output: {},
|
|
2795
2813
|
context: {
|
|
2796
2814
|
swarmName: this.params.swarmName,
|
|
2797
|
-
}
|
|
2815
|
+
},
|
|
2816
|
+
clientId: this.params.clientId,
|
|
2798
2817
|
})];
|
|
2799
2818
|
case 3:
|
|
2800
2819
|
_a.sent();
|
|
@@ -2830,7 +2849,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2830
2849
|
output: {},
|
|
2831
2850
|
context: {
|
|
2832
2851
|
swarmName: this.params.swarmName,
|
|
2833
|
-
}
|
|
2852
|
+
},
|
|
2853
|
+
clientId: this.params.clientId,
|
|
2834
2854
|
})];
|
|
2835
2855
|
case 3:
|
|
2836
2856
|
_a.sent();
|
|
@@ -2872,7 +2892,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2872
2892
|
output: {},
|
|
2873
2893
|
context: {
|
|
2874
2894
|
swarmName: _this.params.swarmName,
|
|
2875
|
-
}
|
|
2895
|
+
},
|
|
2896
|
+
clientId: _this.params.clientId,
|
|
2876
2897
|
});
|
|
2877
2898
|
return function (incoming) { return __awaiter(_this, void 0, void 0, function () {
|
|
2878
2899
|
var _a;
|
|
@@ -4915,7 +4936,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4915
4936
|
},
|
|
4916
4937
|
context: {
|
|
4917
4938
|
storageName: this.params.storageName,
|
|
4918
|
-
}
|
|
4939
|
+
},
|
|
4940
|
+
clientId: this.params.clientId,
|
|
4919
4941
|
})];
|
|
4920
4942
|
case 3:
|
|
4921
4943
|
_c.sent();
|
|
@@ -4954,7 +4976,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4954
4976
|
output: {},
|
|
4955
4977
|
context: {
|
|
4956
4978
|
storageName: this.params.storageName,
|
|
4957
|
-
}
|
|
4979
|
+
},
|
|
4980
|
+
clientId: this.params.clientId,
|
|
4958
4981
|
})];
|
|
4959
4982
|
case 2:
|
|
4960
4983
|
_c.sent();
|
|
@@ -4989,7 +5012,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4989
5012
|
output: {},
|
|
4990
5013
|
context: {
|
|
4991
5014
|
storageName: this.params.storageName,
|
|
4992
|
-
}
|
|
5015
|
+
},
|
|
5016
|
+
clientId: this.params.clientId,
|
|
4993
5017
|
})];
|
|
4994
5018
|
case 1:
|
|
4995
5019
|
_c.sent();
|
|
@@ -5015,7 +5039,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5015
5039
|
output: {},
|
|
5016
5040
|
context: {
|
|
5017
5041
|
storageName: this.params.storageName,
|
|
5018
|
-
}
|
|
5042
|
+
},
|
|
5043
|
+
clientId: this.params.clientId,
|
|
5019
5044
|
})];
|
|
5020
5045
|
case 1:
|
|
5021
5046
|
_a.sent();
|
|
@@ -5049,7 +5074,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5049
5074
|
},
|
|
5050
5075
|
context: {
|
|
5051
5076
|
storageName: this.params.storageName,
|
|
5052
|
-
}
|
|
5077
|
+
},
|
|
5078
|
+
clientId: this.params.clientId,
|
|
5053
5079
|
})];
|
|
5054
5080
|
case 1:
|
|
5055
5081
|
_b.sent();
|
|
@@ -5097,7 +5123,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5097
5123
|
},
|
|
5098
5124
|
context: {
|
|
5099
5125
|
storageName: this.params.storageName,
|
|
5100
|
-
}
|
|
5126
|
+
},
|
|
5127
|
+
clientId: this.params.clientId,
|
|
5101
5128
|
})];
|
|
5102
5129
|
case 1:
|
|
5103
5130
|
_d.sent();
|
|
@@ -5840,7 +5867,8 @@ var ClientState = /** @class */ (function () {
|
|
|
5840
5867
|
},
|
|
5841
5868
|
context: {
|
|
5842
5869
|
stateName: this.params.stateName,
|
|
5843
|
-
}
|
|
5870
|
+
},
|
|
5871
|
+
clientId: this.params.clientId,
|
|
5844
5872
|
})];
|
|
5845
5873
|
case 2:
|
|
5846
5874
|
_b.sent();
|
|
@@ -5873,7 +5901,8 @@ var ClientState = /** @class */ (function () {
|
|
|
5873
5901
|
},
|
|
5874
5902
|
context: {
|
|
5875
5903
|
stateName: this.params.stateName,
|
|
5876
|
-
}
|
|
5904
|
+
},
|
|
5905
|
+
clientId: this.params.clientId,
|
|
5877
5906
|
})];
|
|
5878
5907
|
case 2:
|
|
5879
5908
|
_b.sent();
|
|
@@ -6188,7 +6217,9 @@ var BusService = /** @class */ (function () {
|
|
|
6188
6217
|
function BusService() {
|
|
6189
6218
|
var _this = this;
|
|
6190
6219
|
this.loggerService = inject(TYPES.loggerService);
|
|
6220
|
+
this.sessionValidationService = inject(TYPES.sessionValidationService);
|
|
6191
6221
|
this._eventSourceSet = new Set();
|
|
6222
|
+
this._eventWildcardMap = new Map();
|
|
6192
6223
|
this.getEventSubject = functoolsKit.memoize(function (_a) {
|
|
6193
6224
|
var _b = __read(_a, 2), clientId = _b[0], source = _b[1];
|
|
6194
6225
|
return "".concat(clientId, "-").concat(source);
|
|
@@ -6198,15 +6229,17 @@ var BusService = /** @class */ (function () {
|
|
|
6198
6229
|
* @param {string} clientId - The client ID.
|
|
6199
6230
|
* @param {EventSource} source - The event source.
|
|
6200
6231
|
* @param {(event: T) => void} fn - The callback function to handle the event.
|
|
6201
|
-
* @returns {Subscription} The subscription object.
|
|
6202
6232
|
*/
|
|
6203
6233
|
this.subscribe = function (clientId, source, fn) {
|
|
6204
6234
|
_this.loggerService.log("busService subscribe", {
|
|
6205
6235
|
clientId: clientId,
|
|
6206
6236
|
source: source,
|
|
6207
6237
|
});
|
|
6238
|
+
if (clientId === "*") {
|
|
6239
|
+
_this._eventWildcardMap.set(source, true);
|
|
6240
|
+
}
|
|
6208
6241
|
_this._eventSourceSet.add(source);
|
|
6209
|
-
|
|
6242
|
+
_this.getEventSubject(clientId, source).subscribe(fn);
|
|
6210
6243
|
};
|
|
6211
6244
|
/**
|
|
6212
6245
|
* Subscribes to a single event for a specific client and source.
|
|
@@ -6221,6 +6254,9 @@ var BusService = /** @class */ (function () {
|
|
|
6221
6254
|
clientId: clientId,
|
|
6222
6255
|
source: source,
|
|
6223
6256
|
});
|
|
6257
|
+
if (clientId === "*") {
|
|
6258
|
+
_this._eventWildcardMap.set(source, true);
|
|
6259
|
+
}
|
|
6224
6260
|
_this._eventSourceSet.add(source);
|
|
6225
6261
|
return _this.getEventSubject(clientId, source).filter(filterFn).once(fn);
|
|
6226
6262
|
};
|
|
@@ -6238,13 +6274,21 @@ var BusService = /** @class */ (function () {
|
|
|
6238
6274
|
clientId: clientId,
|
|
6239
6275
|
event: event,
|
|
6240
6276
|
});
|
|
6241
|
-
if (!this.
|
|
6277
|
+
if (!this.sessionValidationService.hasSession(clientId)) {
|
|
6242
6278
|
return [2 /*return*/];
|
|
6243
6279
|
}
|
|
6280
|
+
if (!this.getEventSubject.has("".concat(clientId, "-").concat(event.source))) return [3 /*break*/, 2];
|
|
6244
6281
|
return [4 /*yield*/, this.getEventSubject(clientId, event.source).next(event)];
|
|
6245
6282
|
case 1:
|
|
6246
6283
|
_a.sent();
|
|
6247
|
-
|
|
6284
|
+
_a.label = 2;
|
|
6285
|
+
case 2:
|
|
6286
|
+
if (!this._eventWildcardMap.has(event.source)) return [3 /*break*/, 4];
|
|
6287
|
+
return [4 /*yield*/, this.getEventSubject("*", event.source).next(event)];
|
|
6288
|
+
case 3:
|
|
6289
|
+
_a.sent();
|
|
6290
|
+
_a.label = 4;
|
|
6291
|
+
case 4: return [2 /*return*/];
|
|
6248
6292
|
}
|
|
6249
6293
|
});
|
|
6250
6294
|
}); };
|
|
@@ -7517,13 +7561,20 @@ var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
|
|
|
7517
7561
|
"storage",
|
|
7518
7562
|
"swarm",
|
|
7519
7563
|
]);
|
|
7564
|
+
var validateClientId$6 = function (clientId) {
|
|
7565
|
+
if (clientId === "*") {
|
|
7566
|
+
return;
|
|
7567
|
+
}
|
|
7568
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7569
|
+
throw new Error("agent-swarm listenEvent session not found for clientId=".concat(clientId));
|
|
7570
|
+
}
|
|
7571
|
+
};
|
|
7520
7572
|
/**
|
|
7521
7573
|
* Listens for an event on the swarm bus service and executes a callback function when the event is received.
|
|
7522
7574
|
*
|
|
7523
7575
|
* @template T - The type of the data payload.
|
|
7524
7576
|
* @param {string} clientId - The ID of the client to listen for events from.
|
|
7525
7577
|
* @param {(data: T) => void} fn - The callback function to execute when the event is received. The data payload is passed as an argument to this function.
|
|
7526
|
-
* @returns {void} - Returns nothing.
|
|
7527
7578
|
*/
|
|
7528
7579
|
var listenEvent = function (clientId, topicName, fn) {
|
|
7529
7580
|
swarm.loggerService.log("function listenEvent", {
|
|
@@ -7532,6 +7583,7 @@ var listenEvent = function (clientId, topicName, fn) {
|
|
|
7532
7583
|
if (DISALLOWED_EVENT_SOURCE_LIST$1.has(topicName)) {
|
|
7533
7584
|
throw new Error("agent-swarm listenEvent topic is reserved topicName=".concat(topicName));
|
|
7534
7585
|
}
|
|
7586
|
+
validateClientId$6(clientId);
|
|
7535
7587
|
return swarm.busService.subscribe(clientId, topicName, function (_a) {
|
|
7536
7588
|
var payload = _a.payload;
|
|
7537
7589
|
return fn(payload);
|
|
@@ -7746,6 +7798,7 @@ var event = function (clientId, topicName, payload) {
|
|
|
7746
7798
|
return swarm.busService.emit(clientId, {
|
|
7747
7799
|
source: topicName,
|
|
7748
7800
|
payload: payload,
|
|
7801
|
+
clientId: clientId,
|
|
7749
7802
|
});
|
|
7750
7803
|
};
|
|
7751
7804
|
|
|
@@ -7814,88 +7867,136 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
|
|
|
7814
7867
|
});
|
|
7815
7868
|
}); };
|
|
7816
7869
|
|
|
7870
|
+
var validateClientId$5 = function (clientId) {
|
|
7871
|
+
if (clientId === "*") {
|
|
7872
|
+
return;
|
|
7873
|
+
}
|
|
7874
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7875
|
+
throw new Error("agent-swarm listenAgentEvent session not found for clientId=".concat(clientId));
|
|
7876
|
+
}
|
|
7877
|
+
};
|
|
7817
7878
|
/**
|
|
7818
7879
|
* Hook to subscribe to agent events for a specific client.
|
|
7819
7880
|
*
|
|
7820
7881
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
7821
7882
|
* @param {function} fn - The callback function to handle the event.
|
|
7822
|
-
* @returns {function} - A function to unsubscribe from the event.
|
|
7823
7883
|
*/
|
|
7824
7884
|
var listenAgentEvent = function (clientId, fn) {
|
|
7825
7885
|
swarm.loggerService.log("middleware listenAgentEvent", {
|
|
7826
7886
|
clientId: clientId,
|
|
7827
7887
|
});
|
|
7828
|
-
|
|
7888
|
+
validateClientId$5(clientId);
|
|
7889
|
+
swarm.busService.subscribe(clientId, "agent", fn);
|
|
7829
7890
|
};
|
|
7830
7891
|
|
|
7892
|
+
var validateClientId$4 = function (clientId) {
|
|
7893
|
+
if (clientId === "*") {
|
|
7894
|
+
return;
|
|
7895
|
+
}
|
|
7896
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7897
|
+
throw new Error("agent-swarm listenHistoryEvent session not found for clientId=".concat(clientId));
|
|
7898
|
+
}
|
|
7899
|
+
};
|
|
7831
7900
|
/**
|
|
7832
7901
|
* Hook to subscribe to history events for a specific client.
|
|
7833
7902
|
*
|
|
7834
7903
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
7835
|
-
* @param {(event:
|
|
7836
|
-
* @returns {Function} - The unsubscribe function.
|
|
7904
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
7837
7905
|
*/
|
|
7838
7906
|
var listenHistoryEvent = function (clientId, fn) {
|
|
7839
7907
|
swarm.loggerService.log("middleware listenHistoryEvent", {
|
|
7840
7908
|
clientId: clientId,
|
|
7841
7909
|
});
|
|
7842
|
-
|
|
7910
|
+
validateClientId$4(clientId);
|
|
7911
|
+
swarm.busService.subscribe(clientId, "history", fn);
|
|
7843
7912
|
};
|
|
7844
7913
|
|
|
7914
|
+
var validateClientId$3 = function (clientId) {
|
|
7915
|
+
if (clientId === "*") {
|
|
7916
|
+
return;
|
|
7917
|
+
}
|
|
7918
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7919
|
+
throw new Error("agent-swarm listenSessionEvent session not found for clientId=".concat(clientId));
|
|
7920
|
+
}
|
|
7921
|
+
};
|
|
7845
7922
|
/**
|
|
7846
7923
|
* Hook to subscribe to session events for a specific client.
|
|
7847
7924
|
*
|
|
7848
7925
|
* @param {string} clientId - The ID of the client to subscribe to session events for.
|
|
7849
7926
|
* @param {function} fn - The callback function to handle the session events.
|
|
7850
|
-
* @returns {function} - The unsubscribe function to stop listening to session events.
|
|
7851
7927
|
*/
|
|
7852
7928
|
var listenSessionEvent = function (clientId, fn) {
|
|
7853
7929
|
swarm.loggerService.log("middleware listenSessionEvent", {
|
|
7854
7930
|
clientId: clientId,
|
|
7855
7931
|
});
|
|
7856
|
-
|
|
7932
|
+
validateClientId$3(clientId);
|
|
7933
|
+
swarm.busService.subscribe(clientId, "session", fn);
|
|
7857
7934
|
};
|
|
7858
7935
|
|
|
7936
|
+
var validateClientId$2 = function (clientId) {
|
|
7937
|
+
if (clientId === "*") {
|
|
7938
|
+
return;
|
|
7939
|
+
}
|
|
7940
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7941
|
+
throw new Error("agent-swarm listenStateEvent session not found for clientId=".concat(clientId));
|
|
7942
|
+
}
|
|
7943
|
+
};
|
|
7859
7944
|
/**
|
|
7860
7945
|
* Hook to subscribe to state events for a specific client.
|
|
7861
7946
|
*
|
|
7862
7947
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
7863
7948
|
* @param {function} fn - The callback function to handle the event.
|
|
7864
|
-
* @returns {function} - The unsubscribe function to stop listening to the events.
|
|
7865
7949
|
*/
|
|
7866
7950
|
var listenStateEvent = function (clientId, fn) {
|
|
7867
7951
|
swarm.loggerService.log("middleware listenStateEvent", {
|
|
7868
7952
|
clientId: clientId,
|
|
7869
7953
|
});
|
|
7870
|
-
|
|
7954
|
+
validateClientId$2(clientId);
|
|
7955
|
+
swarm.busService.subscribe(clientId, "state", fn);
|
|
7871
7956
|
};
|
|
7872
7957
|
|
|
7958
|
+
var validateClientId$1 = function (clientId) {
|
|
7959
|
+
if (clientId === "*") {
|
|
7960
|
+
return;
|
|
7961
|
+
}
|
|
7962
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7963
|
+
throw new Error("agent-swarm listenStorageEvent session not found for clientId=".concat(clientId));
|
|
7964
|
+
}
|
|
7965
|
+
};
|
|
7873
7966
|
/**
|
|
7874
7967
|
* Hook to subscribe to storage events for a specific client.
|
|
7875
7968
|
*
|
|
7876
7969
|
* @param {string} clientId - The ID of the client to subscribe to storage events for.
|
|
7877
7970
|
* @param {function} fn - The callback function to handle the storage event.
|
|
7878
|
-
* @returns {function} - A function to unsubscribe from the storage events.
|
|
7879
7971
|
*/
|
|
7880
7972
|
var listenStorageEvent = function (clientId, fn) {
|
|
7881
7973
|
swarm.loggerService.log("middleware listenStorageEvent", {
|
|
7882
7974
|
clientId: clientId,
|
|
7883
7975
|
});
|
|
7884
|
-
|
|
7976
|
+
validateClientId$1(clientId);
|
|
7977
|
+
swarm.busService.subscribe(clientId, "storage", fn);
|
|
7885
7978
|
};
|
|
7886
7979
|
|
|
7980
|
+
var validateClientId = function (clientId) {
|
|
7981
|
+
if (clientId === "*") {
|
|
7982
|
+
return;
|
|
7983
|
+
}
|
|
7984
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7985
|
+
throw new Error("agent-swarm listenSwarmEvent session not found for clientId=".concat(clientId));
|
|
7986
|
+
}
|
|
7987
|
+
};
|
|
7887
7988
|
/**
|
|
7888
7989
|
* Hook to subscribe to swarm events for a specific client.
|
|
7889
7990
|
*
|
|
7890
7991
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
7891
|
-
* @param {(event:
|
|
7892
|
-
* @returns {Function} - A function to unsubscribe from the event.
|
|
7992
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
7893
7993
|
*/
|
|
7894
7994
|
var listenSwarmEvent = function (clientId, fn) {
|
|
7895
7995
|
swarm.loggerService.log("middleware listenSwarmEvent", {
|
|
7896
7996
|
clientId: clientId,
|
|
7897
7997
|
});
|
|
7898
|
-
|
|
7998
|
+
validateClientId(clientId);
|
|
7999
|
+
swarm.busService.subscribe(clientId, "swarm", fn);
|
|
7899
8000
|
};
|
|
7900
8001
|
|
|
7901
8002
|
var StorageUtils = /** @class */ (function () {
|
package/build/index.mjs
CHANGED
|
@@ -981,7 +981,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
981
981
|
},
|
|
982
982
|
context: {
|
|
983
983
|
agentName: this.params.agentName,
|
|
984
|
-
}
|
|
984
|
+
},
|
|
985
|
+
clientId: this.params.clientId,
|
|
985
986
|
})];
|
|
986
987
|
case 7:
|
|
987
988
|
_a.sent();
|
|
@@ -1004,7 +1005,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1004
1005
|
},
|
|
1005
1006
|
context: {
|
|
1006
1007
|
agentName: this.params.agentName,
|
|
1007
|
-
}
|
|
1008
|
+
},
|
|
1009
|
+
clientId: this.params.clientId,
|
|
1008
1010
|
})];
|
|
1009
1011
|
case 10:
|
|
1010
1012
|
_a.sent();
|
|
@@ -1148,7 +1150,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1148
1150
|
output: {},
|
|
1149
1151
|
context: {
|
|
1150
1152
|
agentName: this.params.agentName,
|
|
1151
|
-
}
|
|
1153
|
+
},
|
|
1154
|
+
clientId: this.params.clientId,
|
|
1152
1155
|
})];
|
|
1153
1156
|
case 2:
|
|
1154
1157
|
_a.sent();
|
|
@@ -1182,7 +1185,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1182
1185
|
output: {},
|
|
1183
1186
|
context: {
|
|
1184
1187
|
agentName: this.params.agentName,
|
|
1185
|
-
}
|
|
1188
|
+
},
|
|
1189
|
+
clientId: this.params.clientId,
|
|
1186
1190
|
})];
|
|
1187
1191
|
case 2:
|
|
1188
1192
|
_a.sent();
|
|
@@ -1209,7 +1213,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1209
1213
|
output: {},
|
|
1210
1214
|
context: {
|
|
1211
1215
|
agentName: this.params.agentName,
|
|
1212
|
-
}
|
|
1216
|
+
},
|
|
1217
|
+
clientId: this.params.clientId,
|
|
1213
1218
|
})];
|
|
1214
1219
|
case 2:
|
|
1215
1220
|
_a.sent();
|
|
@@ -1246,7 +1251,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1246
1251
|
output: {},
|
|
1247
1252
|
context: {
|
|
1248
1253
|
agentName: this.params.agentName,
|
|
1249
|
-
}
|
|
1254
|
+
},
|
|
1255
|
+
clientId: this.params.clientId,
|
|
1250
1256
|
})];
|
|
1251
1257
|
case 2:
|
|
1252
1258
|
_a.sent();
|
|
@@ -1288,7 +1294,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1288
1294
|
output: {},
|
|
1289
1295
|
context: {
|
|
1290
1296
|
agentName: this.params.agentName,
|
|
1291
|
-
}
|
|
1297
|
+
},
|
|
1298
|
+
clientId: this.params.clientId,
|
|
1292
1299
|
})];
|
|
1293
1300
|
case 3:
|
|
1294
1301
|
_a.sent();
|
|
@@ -1723,7 +1730,8 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1723
1730
|
output: {},
|
|
1724
1731
|
context: {
|
|
1725
1732
|
agentName: this.params.agentName,
|
|
1726
|
-
}
|
|
1733
|
+
},
|
|
1734
|
+
clientId: this.params.clientId,
|
|
1727
1735
|
})];
|
|
1728
1736
|
case 2:
|
|
1729
1737
|
_a.sent();
|
|
@@ -2132,6 +2140,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2132
2140
|
context: {
|
|
2133
2141
|
swarmName: this.params.swarmName,
|
|
2134
2142
|
},
|
|
2143
|
+
clientId: this.params.clientId,
|
|
2135
2144
|
})];
|
|
2136
2145
|
case 3:
|
|
2137
2146
|
_d.sent();
|
|
@@ -2206,6 +2215,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2206
2215
|
context: {
|
|
2207
2216
|
swarmName: this.params.swarmName,
|
|
2208
2217
|
},
|
|
2218
|
+
clientId: this.params.clientId,
|
|
2209
2219
|
})];
|
|
2210
2220
|
case 3:
|
|
2211
2221
|
_c.sent();
|
|
@@ -2239,6 +2249,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2239
2249
|
context: {
|
|
2240
2250
|
swarmName: this.params.swarmName,
|
|
2241
2251
|
},
|
|
2252
|
+
clientId: this.params.clientId,
|
|
2242
2253
|
})];
|
|
2243
2254
|
case 3:
|
|
2244
2255
|
_b.sent();
|
|
@@ -2270,6 +2281,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2270
2281
|
context: {
|
|
2271
2282
|
swarmName: this.params.swarmName,
|
|
2272
2283
|
},
|
|
2284
|
+
clientId: this.params.clientId,
|
|
2273
2285
|
})];
|
|
2274
2286
|
case 2:
|
|
2275
2287
|
_a.sent();
|
|
@@ -2303,6 +2315,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2303
2315
|
context: {
|
|
2304
2316
|
swarmName: this.params.swarmName,
|
|
2305
2317
|
},
|
|
2318
|
+
clientId: this.params.clientId,
|
|
2306
2319
|
})];
|
|
2307
2320
|
case 1:
|
|
2308
2321
|
_a.sent();
|
|
@@ -2336,6 +2349,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
2336
2349
|
context: {
|
|
2337
2350
|
swarmName: this.params.swarmName,
|
|
2338
2351
|
},
|
|
2352
|
+
clientId: this.params.clientId,
|
|
2339
2353
|
})];
|
|
2340
2354
|
case 2:
|
|
2341
2355
|
_a.sent();
|
|
@@ -2641,7 +2655,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2641
2655
|
output: {},
|
|
2642
2656
|
context: {
|
|
2643
2657
|
swarmName: this.params.swarmName,
|
|
2644
|
-
}
|
|
2658
|
+
},
|
|
2659
|
+
clientId: this.params.clientId,
|
|
2645
2660
|
})];
|
|
2646
2661
|
case 2:
|
|
2647
2662
|
_a.sent();
|
|
@@ -2686,7 +2701,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2686
2701
|
},
|
|
2687
2702
|
context: {
|
|
2688
2703
|
swarmName: this.params.swarmName,
|
|
2689
|
-
}
|
|
2704
|
+
},
|
|
2705
|
+
clientId: this.params.clientId,
|
|
2690
2706
|
})];
|
|
2691
2707
|
case 3:
|
|
2692
2708
|
_a.sent();
|
|
@@ -2725,7 +2741,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2725
2741
|
output: {},
|
|
2726
2742
|
context: {
|
|
2727
2743
|
swarmName: this.params.swarmName,
|
|
2728
|
-
}
|
|
2744
|
+
},
|
|
2745
|
+
clientId: this.params.clientId,
|
|
2729
2746
|
})];
|
|
2730
2747
|
case 3:
|
|
2731
2748
|
_a.sent();
|
|
@@ -2761,7 +2778,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2761
2778
|
output: {},
|
|
2762
2779
|
context: {
|
|
2763
2780
|
swarmName: this.params.swarmName,
|
|
2764
|
-
}
|
|
2781
|
+
},
|
|
2782
|
+
clientId: this.params.clientId,
|
|
2765
2783
|
})];
|
|
2766
2784
|
case 3:
|
|
2767
2785
|
_a.sent();
|
|
@@ -2792,7 +2810,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2792
2810
|
output: {},
|
|
2793
2811
|
context: {
|
|
2794
2812
|
swarmName: this.params.swarmName,
|
|
2795
|
-
}
|
|
2813
|
+
},
|
|
2814
|
+
clientId: this.params.clientId,
|
|
2796
2815
|
})];
|
|
2797
2816
|
case 3:
|
|
2798
2817
|
_a.sent();
|
|
@@ -2828,7 +2847,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2828
2847
|
output: {},
|
|
2829
2848
|
context: {
|
|
2830
2849
|
swarmName: this.params.swarmName,
|
|
2831
|
-
}
|
|
2850
|
+
},
|
|
2851
|
+
clientId: this.params.clientId,
|
|
2832
2852
|
})];
|
|
2833
2853
|
case 3:
|
|
2834
2854
|
_a.sent();
|
|
@@ -2870,7 +2890,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
2870
2890
|
output: {},
|
|
2871
2891
|
context: {
|
|
2872
2892
|
swarmName: _this.params.swarmName,
|
|
2873
|
-
}
|
|
2893
|
+
},
|
|
2894
|
+
clientId: _this.params.clientId,
|
|
2874
2895
|
});
|
|
2875
2896
|
return function (incoming) { return __awaiter(_this, void 0, void 0, function () {
|
|
2876
2897
|
var _a;
|
|
@@ -4913,7 +4934,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4913
4934
|
},
|
|
4914
4935
|
context: {
|
|
4915
4936
|
storageName: this.params.storageName,
|
|
4916
|
-
}
|
|
4937
|
+
},
|
|
4938
|
+
clientId: this.params.clientId,
|
|
4917
4939
|
})];
|
|
4918
4940
|
case 3:
|
|
4919
4941
|
_c.sent();
|
|
@@ -4952,7 +4974,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4952
4974
|
output: {},
|
|
4953
4975
|
context: {
|
|
4954
4976
|
storageName: this.params.storageName,
|
|
4955
|
-
}
|
|
4977
|
+
},
|
|
4978
|
+
clientId: this.params.clientId,
|
|
4956
4979
|
})];
|
|
4957
4980
|
case 2:
|
|
4958
4981
|
_c.sent();
|
|
@@ -4987,7 +5010,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
4987
5010
|
output: {},
|
|
4988
5011
|
context: {
|
|
4989
5012
|
storageName: this.params.storageName,
|
|
4990
|
-
}
|
|
5013
|
+
},
|
|
5014
|
+
clientId: this.params.clientId,
|
|
4991
5015
|
})];
|
|
4992
5016
|
case 1:
|
|
4993
5017
|
_c.sent();
|
|
@@ -5013,7 +5037,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5013
5037
|
output: {},
|
|
5014
5038
|
context: {
|
|
5015
5039
|
storageName: this.params.storageName,
|
|
5016
|
-
}
|
|
5040
|
+
},
|
|
5041
|
+
clientId: this.params.clientId,
|
|
5017
5042
|
})];
|
|
5018
5043
|
case 1:
|
|
5019
5044
|
_a.sent();
|
|
@@ -5047,7 +5072,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5047
5072
|
},
|
|
5048
5073
|
context: {
|
|
5049
5074
|
storageName: this.params.storageName,
|
|
5050
|
-
}
|
|
5075
|
+
},
|
|
5076
|
+
clientId: this.params.clientId,
|
|
5051
5077
|
})];
|
|
5052
5078
|
case 1:
|
|
5053
5079
|
_b.sent();
|
|
@@ -5095,7 +5121,8 @@ var ClientStorage = /** @class */ (function () {
|
|
|
5095
5121
|
},
|
|
5096
5122
|
context: {
|
|
5097
5123
|
storageName: this.params.storageName,
|
|
5098
|
-
}
|
|
5124
|
+
},
|
|
5125
|
+
clientId: this.params.clientId,
|
|
5099
5126
|
})];
|
|
5100
5127
|
case 1:
|
|
5101
5128
|
_d.sent();
|
|
@@ -5838,7 +5865,8 @@ var ClientState = /** @class */ (function () {
|
|
|
5838
5865
|
},
|
|
5839
5866
|
context: {
|
|
5840
5867
|
stateName: this.params.stateName,
|
|
5841
|
-
}
|
|
5868
|
+
},
|
|
5869
|
+
clientId: this.params.clientId,
|
|
5842
5870
|
})];
|
|
5843
5871
|
case 2:
|
|
5844
5872
|
_b.sent();
|
|
@@ -5871,7 +5899,8 @@ var ClientState = /** @class */ (function () {
|
|
|
5871
5899
|
},
|
|
5872
5900
|
context: {
|
|
5873
5901
|
stateName: this.params.stateName,
|
|
5874
|
-
}
|
|
5902
|
+
},
|
|
5903
|
+
clientId: this.params.clientId,
|
|
5875
5904
|
})];
|
|
5876
5905
|
case 2:
|
|
5877
5906
|
_b.sent();
|
|
@@ -6186,7 +6215,9 @@ var BusService = /** @class */ (function () {
|
|
|
6186
6215
|
function BusService() {
|
|
6187
6216
|
var _this = this;
|
|
6188
6217
|
this.loggerService = inject(TYPES.loggerService);
|
|
6218
|
+
this.sessionValidationService = inject(TYPES.sessionValidationService);
|
|
6189
6219
|
this._eventSourceSet = new Set();
|
|
6220
|
+
this._eventWildcardMap = new Map();
|
|
6190
6221
|
this.getEventSubject = memoize(function (_a) {
|
|
6191
6222
|
var _b = __read(_a, 2), clientId = _b[0], source = _b[1];
|
|
6192
6223
|
return "".concat(clientId, "-").concat(source);
|
|
@@ -6196,15 +6227,17 @@ var BusService = /** @class */ (function () {
|
|
|
6196
6227
|
* @param {string} clientId - The client ID.
|
|
6197
6228
|
* @param {EventSource} source - The event source.
|
|
6198
6229
|
* @param {(event: T) => void} fn - The callback function to handle the event.
|
|
6199
|
-
* @returns {Subscription} The subscription object.
|
|
6200
6230
|
*/
|
|
6201
6231
|
this.subscribe = function (clientId, source, fn) {
|
|
6202
6232
|
_this.loggerService.log("busService subscribe", {
|
|
6203
6233
|
clientId: clientId,
|
|
6204
6234
|
source: source,
|
|
6205
6235
|
});
|
|
6236
|
+
if (clientId === "*") {
|
|
6237
|
+
_this._eventWildcardMap.set(source, true);
|
|
6238
|
+
}
|
|
6206
6239
|
_this._eventSourceSet.add(source);
|
|
6207
|
-
|
|
6240
|
+
_this.getEventSubject(clientId, source).subscribe(fn);
|
|
6208
6241
|
};
|
|
6209
6242
|
/**
|
|
6210
6243
|
* Subscribes to a single event for a specific client and source.
|
|
@@ -6219,6 +6252,9 @@ var BusService = /** @class */ (function () {
|
|
|
6219
6252
|
clientId: clientId,
|
|
6220
6253
|
source: source,
|
|
6221
6254
|
});
|
|
6255
|
+
if (clientId === "*") {
|
|
6256
|
+
_this._eventWildcardMap.set(source, true);
|
|
6257
|
+
}
|
|
6222
6258
|
_this._eventSourceSet.add(source);
|
|
6223
6259
|
return _this.getEventSubject(clientId, source).filter(filterFn).once(fn);
|
|
6224
6260
|
};
|
|
@@ -6236,13 +6272,21 @@ var BusService = /** @class */ (function () {
|
|
|
6236
6272
|
clientId: clientId,
|
|
6237
6273
|
event: event,
|
|
6238
6274
|
});
|
|
6239
|
-
if (!this.
|
|
6275
|
+
if (!this.sessionValidationService.hasSession(clientId)) {
|
|
6240
6276
|
return [2 /*return*/];
|
|
6241
6277
|
}
|
|
6278
|
+
if (!this.getEventSubject.has("".concat(clientId, "-").concat(event.source))) return [3 /*break*/, 2];
|
|
6242
6279
|
return [4 /*yield*/, this.getEventSubject(clientId, event.source).next(event)];
|
|
6243
6280
|
case 1:
|
|
6244
6281
|
_a.sent();
|
|
6245
|
-
|
|
6282
|
+
_a.label = 2;
|
|
6283
|
+
case 2:
|
|
6284
|
+
if (!this._eventWildcardMap.has(event.source)) return [3 /*break*/, 4];
|
|
6285
|
+
return [4 /*yield*/, this.getEventSubject("*", event.source).next(event)];
|
|
6286
|
+
case 3:
|
|
6287
|
+
_a.sent();
|
|
6288
|
+
_a.label = 4;
|
|
6289
|
+
case 4: return [2 /*return*/];
|
|
6246
6290
|
}
|
|
6247
6291
|
});
|
|
6248
6292
|
}); };
|
|
@@ -7515,13 +7559,20 @@ var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
|
|
|
7515
7559
|
"storage",
|
|
7516
7560
|
"swarm",
|
|
7517
7561
|
]);
|
|
7562
|
+
var validateClientId$6 = function (clientId) {
|
|
7563
|
+
if (clientId === "*") {
|
|
7564
|
+
return;
|
|
7565
|
+
}
|
|
7566
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7567
|
+
throw new Error("agent-swarm listenEvent session not found for clientId=".concat(clientId));
|
|
7568
|
+
}
|
|
7569
|
+
};
|
|
7518
7570
|
/**
|
|
7519
7571
|
* Listens for an event on the swarm bus service and executes a callback function when the event is received.
|
|
7520
7572
|
*
|
|
7521
7573
|
* @template T - The type of the data payload.
|
|
7522
7574
|
* @param {string} clientId - The ID of the client to listen for events from.
|
|
7523
7575
|
* @param {(data: T) => void} fn - The callback function to execute when the event is received. The data payload is passed as an argument to this function.
|
|
7524
|
-
* @returns {void} - Returns nothing.
|
|
7525
7576
|
*/
|
|
7526
7577
|
var listenEvent = function (clientId, topicName, fn) {
|
|
7527
7578
|
swarm.loggerService.log("function listenEvent", {
|
|
@@ -7530,6 +7581,7 @@ var listenEvent = function (clientId, topicName, fn) {
|
|
|
7530
7581
|
if (DISALLOWED_EVENT_SOURCE_LIST$1.has(topicName)) {
|
|
7531
7582
|
throw new Error("agent-swarm listenEvent topic is reserved topicName=".concat(topicName));
|
|
7532
7583
|
}
|
|
7584
|
+
validateClientId$6(clientId);
|
|
7533
7585
|
return swarm.busService.subscribe(clientId, topicName, function (_a) {
|
|
7534
7586
|
var payload = _a.payload;
|
|
7535
7587
|
return fn(payload);
|
|
@@ -7744,6 +7796,7 @@ var event = function (clientId, topicName, payload) {
|
|
|
7744
7796
|
return swarm.busService.emit(clientId, {
|
|
7745
7797
|
source: topicName,
|
|
7746
7798
|
payload: payload,
|
|
7799
|
+
clientId: clientId,
|
|
7747
7800
|
});
|
|
7748
7801
|
};
|
|
7749
7802
|
|
|
@@ -7812,88 +7865,136 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
|
|
|
7812
7865
|
});
|
|
7813
7866
|
}); };
|
|
7814
7867
|
|
|
7868
|
+
var validateClientId$5 = function (clientId) {
|
|
7869
|
+
if (clientId === "*") {
|
|
7870
|
+
return;
|
|
7871
|
+
}
|
|
7872
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7873
|
+
throw new Error("agent-swarm listenAgentEvent session not found for clientId=".concat(clientId));
|
|
7874
|
+
}
|
|
7875
|
+
};
|
|
7815
7876
|
/**
|
|
7816
7877
|
* Hook to subscribe to agent events for a specific client.
|
|
7817
7878
|
*
|
|
7818
7879
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
7819
7880
|
* @param {function} fn - The callback function to handle the event.
|
|
7820
|
-
* @returns {function} - A function to unsubscribe from the event.
|
|
7821
7881
|
*/
|
|
7822
7882
|
var listenAgentEvent = function (clientId, fn) {
|
|
7823
7883
|
swarm.loggerService.log("middleware listenAgentEvent", {
|
|
7824
7884
|
clientId: clientId,
|
|
7825
7885
|
});
|
|
7826
|
-
|
|
7886
|
+
validateClientId$5(clientId);
|
|
7887
|
+
swarm.busService.subscribe(clientId, "agent", fn);
|
|
7827
7888
|
};
|
|
7828
7889
|
|
|
7890
|
+
var validateClientId$4 = function (clientId) {
|
|
7891
|
+
if (clientId === "*") {
|
|
7892
|
+
return;
|
|
7893
|
+
}
|
|
7894
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7895
|
+
throw new Error("agent-swarm listenHistoryEvent session not found for clientId=".concat(clientId));
|
|
7896
|
+
}
|
|
7897
|
+
};
|
|
7829
7898
|
/**
|
|
7830
7899
|
* Hook to subscribe to history events for a specific client.
|
|
7831
7900
|
*
|
|
7832
7901
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
7833
|
-
* @param {(event:
|
|
7834
|
-
* @returns {Function} - The unsubscribe function.
|
|
7902
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
7835
7903
|
*/
|
|
7836
7904
|
var listenHistoryEvent = function (clientId, fn) {
|
|
7837
7905
|
swarm.loggerService.log("middleware listenHistoryEvent", {
|
|
7838
7906
|
clientId: clientId,
|
|
7839
7907
|
});
|
|
7840
|
-
|
|
7908
|
+
validateClientId$4(clientId);
|
|
7909
|
+
swarm.busService.subscribe(clientId, "history", fn);
|
|
7841
7910
|
};
|
|
7842
7911
|
|
|
7912
|
+
var validateClientId$3 = function (clientId) {
|
|
7913
|
+
if (clientId === "*") {
|
|
7914
|
+
return;
|
|
7915
|
+
}
|
|
7916
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7917
|
+
throw new Error("agent-swarm listenSessionEvent session not found for clientId=".concat(clientId));
|
|
7918
|
+
}
|
|
7919
|
+
};
|
|
7843
7920
|
/**
|
|
7844
7921
|
* Hook to subscribe to session events for a specific client.
|
|
7845
7922
|
*
|
|
7846
7923
|
* @param {string} clientId - The ID of the client to subscribe to session events for.
|
|
7847
7924
|
* @param {function} fn - The callback function to handle the session events.
|
|
7848
|
-
* @returns {function} - The unsubscribe function to stop listening to session events.
|
|
7849
7925
|
*/
|
|
7850
7926
|
var listenSessionEvent = function (clientId, fn) {
|
|
7851
7927
|
swarm.loggerService.log("middleware listenSessionEvent", {
|
|
7852
7928
|
clientId: clientId,
|
|
7853
7929
|
});
|
|
7854
|
-
|
|
7930
|
+
validateClientId$3(clientId);
|
|
7931
|
+
swarm.busService.subscribe(clientId, "session", fn);
|
|
7855
7932
|
};
|
|
7856
7933
|
|
|
7934
|
+
var validateClientId$2 = function (clientId) {
|
|
7935
|
+
if (clientId === "*") {
|
|
7936
|
+
return;
|
|
7937
|
+
}
|
|
7938
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7939
|
+
throw new Error("agent-swarm listenStateEvent session not found for clientId=".concat(clientId));
|
|
7940
|
+
}
|
|
7941
|
+
};
|
|
7857
7942
|
/**
|
|
7858
7943
|
* Hook to subscribe to state events for a specific client.
|
|
7859
7944
|
*
|
|
7860
7945
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
7861
7946
|
* @param {function} fn - The callback function to handle the event.
|
|
7862
|
-
* @returns {function} - The unsubscribe function to stop listening to the events.
|
|
7863
7947
|
*/
|
|
7864
7948
|
var listenStateEvent = function (clientId, fn) {
|
|
7865
7949
|
swarm.loggerService.log("middleware listenStateEvent", {
|
|
7866
7950
|
clientId: clientId,
|
|
7867
7951
|
});
|
|
7868
|
-
|
|
7952
|
+
validateClientId$2(clientId);
|
|
7953
|
+
swarm.busService.subscribe(clientId, "state", fn);
|
|
7869
7954
|
};
|
|
7870
7955
|
|
|
7956
|
+
var validateClientId$1 = function (clientId) {
|
|
7957
|
+
if (clientId === "*") {
|
|
7958
|
+
return;
|
|
7959
|
+
}
|
|
7960
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7961
|
+
throw new Error("agent-swarm listenStorageEvent session not found for clientId=".concat(clientId));
|
|
7962
|
+
}
|
|
7963
|
+
};
|
|
7871
7964
|
/**
|
|
7872
7965
|
* Hook to subscribe to storage events for a specific client.
|
|
7873
7966
|
*
|
|
7874
7967
|
* @param {string} clientId - The ID of the client to subscribe to storage events for.
|
|
7875
7968
|
* @param {function} fn - The callback function to handle the storage event.
|
|
7876
|
-
* @returns {function} - A function to unsubscribe from the storage events.
|
|
7877
7969
|
*/
|
|
7878
7970
|
var listenStorageEvent = function (clientId, fn) {
|
|
7879
7971
|
swarm.loggerService.log("middleware listenStorageEvent", {
|
|
7880
7972
|
clientId: clientId,
|
|
7881
7973
|
});
|
|
7882
|
-
|
|
7974
|
+
validateClientId$1(clientId);
|
|
7975
|
+
swarm.busService.subscribe(clientId, "storage", fn);
|
|
7883
7976
|
};
|
|
7884
7977
|
|
|
7978
|
+
var validateClientId = function (clientId) {
|
|
7979
|
+
if (clientId === "*") {
|
|
7980
|
+
return;
|
|
7981
|
+
}
|
|
7982
|
+
if (!swarm.sessionValidationService.hasSession(clientId)) {
|
|
7983
|
+
throw new Error("agent-swarm listenSwarmEvent session not found for clientId=".concat(clientId));
|
|
7984
|
+
}
|
|
7985
|
+
};
|
|
7885
7986
|
/**
|
|
7886
7987
|
* Hook to subscribe to swarm events for a specific client.
|
|
7887
7988
|
*
|
|
7888
7989
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
7889
|
-
* @param {(event:
|
|
7890
|
-
* @returns {Function} - A function to unsubscribe from the event.
|
|
7990
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
7891
7991
|
*/
|
|
7892
7992
|
var listenSwarmEvent = function (clientId, fn) {
|
|
7893
7993
|
swarm.loggerService.log("middleware listenSwarmEvent", {
|
|
7894
7994
|
clientId: clientId,
|
|
7895
7995
|
});
|
|
7896
|
-
|
|
7996
|
+
validateClientId(clientId);
|
|
7997
|
+
swarm.busService.subscribe(clientId, "swarm", fn);
|
|
7897
7998
|
};
|
|
7898
7999
|
|
|
7899
8000
|
var StorageUtils = /** @class */ (function () {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -390,7 +390,7 @@ type StateName = string;
|
|
|
390
390
|
/**
|
|
391
391
|
* Interface representing the base context for an event.
|
|
392
392
|
*/
|
|
393
|
-
interface
|
|
393
|
+
interface IBusEventContext {
|
|
394
394
|
/**
|
|
395
395
|
* The name of the agent.
|
|
396
396
|
*/
|
|
@@ -420,6 +420,34 @@ interface IBaseEvent {
|
|
|
420
420
|
* The source of the event.
|
|
421
421
|
*/
|
|
422
422
|
source: EventSource;
|
|
423
|
+
/**
|
|
424
|
+
* The client id
|
|
425
|
+
*/
|
|
426
|
+
clientId: string;
|
|
427
|
+
}
|
|
428
|
+
interface IBusEvent extends IBaseEvent {
|
|
429
|
+
/**
|
|
430
|
+
* The type of the event.
|
|
431
|
+
*/
|
|
432
|
+
type: string;
|
|
433
|
+
/**
|
|
434
|
+
* The input data for the event.
|
|
435
|
+
*/
|
|
436
|
+
input: Record<string, any>;
|
|
437
|
+
/**
|
|
438
|
+
* The output data for the event.
|
|
439
|
+
*/
|
|
440
|
+
output: Record<string, any>;
|
|
441
|
+
/**
|
|
442
|
+
* The context of the event.
|
|
443
|
+
*/
|
|
444
|
+
context: Partial<IBusEventContext>;
|
|
445
|
+
}
|
|
446
|
+
interface ICustomEvent<T extends any = any> extends IBaseEvent {
|
|
447
|
+
/**
|
|
448
|
+
* The payload of the event, if any.
|
|
449
|
+
*/
|
|
450
|
+
payload?: T;
|
|
423
451
|
}
|
|
424
452
|
|
|
425
453
|
interface IBus {
|
|
@@ -2893,16 +2921,17 @@ declare class StateSchemaService {
|
|
|
2893
2921
|
|
|
2894
2922
|
declare class BusService implements IBus {
|
|
2895
2923
|
private readonly loggerService;
|
|
2924
|
+
private readonly sessionValidationService;
|
|
2896
2925
|
private _eventSourceSet;
|
|
2926
|
+
private _eventWildcardMap;
|
|
2897
2927
|
private getEventSubject;
|
|
2898
2928
|
/**
|
|
2899
2929
|
* Subscribes to events for a specific client and source.
|
|
2900
2930
|
* @param {string} clientId - The client ID.
|
|
2901
2931
|
* @param {EventSource} source - The event source.
|
|
2902
2932
|
* @param {(event: T) => void} fn - The callback function to handle the event.
|
|
2903
|
-
* @returns {Subscription} The subscription object.
|
|
2904
2933
|
*/
|
|
2905
|
-
subscribe: <T extends IBaseEvent>(clientId: string, source: EventSource, fn: (event: T) => void) =>
|
|
2934
|
+
subscribe: <T extends IBaseEvent>(clientId: string, source: EventSource, fn: (event: T) => void) => void;
|
|
2906
2935
|
/**
|
|
2907
2936
|
* Subscribes to a single event for a specific client and source.
|
|
2908
2937
|
* @param {string} clientId - The client ID.
|
|
@@ -3294,9 +3323,8 @@ declare const executeForce: (content: string, clientId: string) => Promise<strin
|
|
|
3294
3323
|
* @template T - The type of the data payload.
|
|
3295
3324
|
* @param {string} clientId - The ID of the client to listen for events from.
|
|
3296
3325
|
* @param {(data: T) => void} fn - The callback function to execute when the event is received. The data payload is passed as an argument to this function.
|
|
3297
|
-
* @returns {void} - Returns nothing.
|
|
3298
3326
|
*/
|
|
3299
|
-
declare const listenEvent: <T extends unknown = any>(clientId: string, topicName: string, fn: (data: T) => void) =>
|
|
3327
|
+
declare const listenEvent: <T extends unknown = any>(clientId: string, topicName: string, fn: (data: T) => void) => void;
|
|
3300
3328
|
|
|
3301
3329
|
/**
|
|
3302
3330
|
* Retrieves the last message sent by the user from the client's message history.
|
|
@@ -3412,54 +3440,48 @@ declare const cancelOutputForce: (clientId: string) => Promise<void>;
|
|
|
3412
3440
|
*
|
|
3413
3441
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
3414
3442
|
* @param {function} fn - The callback function to handle the event.
|
|
3415
|
-
* @returns {function} - A function to unsubscribe from the event.
|
|
3416
3443
|
*/
|
|
3417
|
-
declare const listenAgentEvent: (clientId: string, fn: (event:
|
|
3444
|
+
declare const listenAgentEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3418
3445
|
|
|
3419
3446
|
/**
|
|
3420
3447
|
* Hook to subscribe to history events for a specific client.
|
|
3421
3448
|
*
|
|
3422
3449
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
3423
|
-
* @param {(event:
|
|
3424
|
-
* @returns {Function} - The unsubscribe function.
|
|
3450
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
3425
3451
|
*/
|
|
3426
|
-
declare const listenHistoryEvent: (clientId: string, fn: (event:
|
|
3452
|
+
declare const listenHistoryEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3427
3453
|
|
|
3428
3454
|
/**
|
|
3429
3455
|
* Hook to subscribe to session events for a specific client.
|
|
3430
3456
|
*
|
|
3431
3457
|
* @param {string} clientId - The ID of the client to subscribe to session events for.
|
|
3432
3458
|
* @param {function} fn - The callback function to handle the session events.
|
|
3433
|
-
* @returns {function} - The unsubscribe function to stop listening to session events.
|
|
3434
3459
|
*/
|
|
3435
|
-
declare const listenSessionEvent: (clientId: string, fn: (event:
|
|
3460
|
+
declare const listenSessionEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3436
3461
|
|
|
3437
3462
|
/**
|
|
3438
3463
|
* Hook to subscribe to state events for a specific client.
|
|
3439
3464
|
*
|
|
3440
3465
|
* @param {string} clientId - The ID of the client to subscribe to.
|
|
3441
3466
|
* @param {function} fn - The callback function to handle the event.
|
|
3442
|
-
* @returns {function} - The unsubscribe function to stop listening to the events.
|
|
3443
3467
|
*/
|
|
3444
|
-
declare const listenStateEvent: (clientId: string, fn: (event:
|
|
3468
|
+
declare const listenStateEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3445
3469
|
|
|
3446
3470
|
/**
|
|
3447
3471
|
* Hook to subscribe to storage events for a specific client.
|
|
3448
3472
|
*
|
|
3449
3473
|
* @param {string} clientId - The ID of the client to subscribe to storage events for.
|
|
3450
3474
|
* @param {function} fn - The callback function to handle the storage event.
|
|
3451
|
-
* @returns {function} - A function to unsubscribe from the storage events.
|
|
3452
3475
|
*/
|
|
3453
|
-
declare const listenStorageEvent: (clientId: string, fn: (event:
|
|
3476
|
+
declare const listenStorageEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3454
3477
|
|
|
3455
3478
|
/**
|
|
3456
3479
|
* Hook to subscribe to swarm events for a specific client.
|
|
3457
3480
|
*
|
|
3458
3481
|
* @param {string} clientId - The ID of the client to subscribe to events for.
|
|
3459
|
-
* @param {(event:
|
|
3460
|
-
* @returns {Function} - A function to unsubscribe from the event.
|
|
3482
|
+
* @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
|
|
3461
3483
|
*/
|
|
3462
|
-
declare const listenSwarmEvent: (clientId: string, fn: (event:
|
|
3484
|
+
declare const listenSwarmEvent: (clientId: string, fn: (event: IBusEvent) => void) => void;
|
|
3463
3485
|
|
|
3464
3486
|
declare const GLOBAL_CONFIG: {
|
|
3465
3487
|
CC_TOOL_CALL_EXCEPTION_PROMPT: string;
|
|
@@ -3622,4 +3644,4 @@ declare class StateUtils implements TState {
|
|
|
3622
3644
|
*/
|
|
3623
3645
|
declare const State: StateUtils;
|
|
3624
3646
|
|
|
3625
|
-
export { ContextService, type EventSource, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type
|
|
3647
|
+
export { ContextService, type EventSource, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenEvent, listenHistoryEvent, listenSessionEvent, listenStateEvent, listenStorageEvent, listenSwarmEvent, makeAutoDispose, makeConnection, session, setConfig, swarm };
|