agent-swarm-kit 1.0.72 → 1.0.74

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.mjs CHANGED
@@ -971,7 +971,7 @@ var ClientAgent = /** @class */ (function () {
971
971
  _a.sent();
972
972
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
973
973
  type: "emit-output",
974
- source: "agent",
974
+ source: "agent-bus",
975
975
  input: {
976
976
  mode: mode,
977
977
  rawResult: rawResult_1,
@@ -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();
@@ -994,7 +995,7 @@ var ClientAgent = /** @class */ (function () {
994
995
  _a.sent();
995
996
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
996
997
  type: "emit-output",
997
- source: "agent",
998
+ source: "agent-bus",
998
999
  input: {
999
1000
  mode: mode,
1000
1001
  rawResult: rawResult,
@@ -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();
@@ -1141,14 +1143,15 @@ var ClientAgent = /** @class */ (function () {
1141
1143
  _a.sent();
1142
1144
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1143
1145
  type: "commit-user-message",
1144
- source: "agent",
1146
+ source: "agent-bus",
1145
1147
  input: {
1146
1148
  message: message,
1147
1149
  },
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();
@@ -1177,12 +1180,13 @@ var ClientAgent = /** @class */ (function () {
1177
1180
  _a.sent();
1178
1181
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1179
1182
  type: "commit-flush",
1180
- source: "agent",
1183
+ source: "agent-bus",
1181
1184
  input: {},
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();
@@ -1204,12 +1208,13 @@ var ClientAgent = /** @class */ (function () {
1204
1208
  _a.sent();
1205
1209
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1206
1210
  type: "commit-agent-change",
1207
- source: "agent",
1211
+ source: "agent-bus",
1208
1212
  input: {},
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();
@@ -1239,14 +1244,15 @@ var ClientAgent = /** @class */ (function () {
1239
1244
  _a.sent();
1240
1245
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1241
1246
  type: "commit-system-message",
1242
- source: "agent",
1247
+ source: "agent-bus",
1243
1248
  input: {
1244
1249
  message: message,
1245
1250
  },
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();
@@ -1280,7 +1286,7 @@ var ClientAgent = /** @class */ (function () {
1280
1286
  _a.sent();
1281
1287
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1282
1288
  type: "commit-tool-output",
1283
- source: "agent",
1289
+ source: "agent-bus",
1284
1290
  input: {
1285
1291
  toolId: toolId,
1286
1292
  content: content,
@@ -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();
@@ -1716,14 +1723,15 @@ var ClientHistory = /** @class */ (function () {
1716
1723
  _a.sent();
1717
1724
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
1718
1725
  type: "push",
1719
- source: "history",
1726
+ source: "history-bus",
1720
1727
  input: {
1721
1728
  message: message
1722
1729
  },
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();
@@ -2126,12 +2134,13 @@ var ClientSwarm = /** @class */ (function () {
2126
2134
  _d.sent();
2127
2135
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2128
2136
  type: "cancel-output",
2129
- source: "swarm",
2137
+ source: "swarm-bus",
2130
2138
  input: {},
2131
2139
  output: {},
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();
@@ -2198,7 +2207,7 @@ var ClientSwarm = /** @class */ (function () {
2198
2207
  this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " waitForAgent agent miss"), { agentName: agentName, expectAgent: expectAgent });
2199
2208
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2200
2209
  type: "wait-for-output",
2201
- source: "swarm",
2210
+ source: "swarm-bus",
2202
2211
  input: {},
2203
2212
  output: {
2204
2213
  result: output,
@@ -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();
@@ -2231,7 +2241,7 @@ var ClientSwarm = /** @class */ (function () {
2231
2241
  _b.label = 2;
2232
2242
  case 2: return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2233
2243
  type: "get-agent-name",
2234
- source: "swarm",
2244
+ source: "swarm-bus",
2235
2245
  input: {},
2236
2246
  output: {
2237
2247
  activeAgent: this._activeAgent,
@@ -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();
@@ -2262,7 +2273,7 @@ var ClientSwarm = /** @class */ (function () {
2262
2273
  result = this.params.agentMap[agent];
2263
2274
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2264
2275
  type: "get-agent",
2265
- source: "swarm",
2276
+ source: "swarm-bus",
2266
2277
  input: {
2267
2278
  result: result,
2268
2279
  },
@@ -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();
@@ -2294,7 +2306,7 @@ var ClientSwarm = /** @class */ (function () {
2294
2306
  this.params.agentMap[agentName] = agent;
2295
2307
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2296
2308
  type: "set-agent-ref",
2297
- source: "swarm",
2309
+ source: "swarm-bus",
2298
2310
  input: {
2299
2311
  agentName: agentName,
2300
2312
  agent: agent,
@@ -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();
@@ -2328,7 +2341,7 @@ var ClientSwarm = /** @class */ (function () {
2328
2341
  _a.sent();
2329
2342
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2330
2343
  type: "set-agent-name",
2331
- source: "swarm",
2344
+ source: "swarm-bus",
2332
2345
  input: {
2333
2346
  agentName: agentName,
2334
2347
  },
@@ -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();
@@ -2634,14 +2648,15 @@ var ClientSession = /** @class */ (function () {
2634
2648
  _a.sent();
2635
2649
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2636
2650
  type: "emit",
2637
- source: "session",
2651
+ source: "session-bus",
2638
2652
  input: {
2639
2653
  message: message
2640
2654
  },
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();
@@ -2676,7 +2691,7 @@ var ClientSession = /** @class */ (function () {
2676
2691
  output = _a.sent();
2677
2692
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2678
2693
  type: "execute",
2679
- source: "session",
2694
+ source: "session-bus",
2680
2695
  input: {
2681
2696
  message: message,
2682
2697
  mode: mode,
@@ -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();
@@ -2717,7 +2733,7 @@ var ClientSession = /** @class */ (function () {
2717
2733
  result = _a.sent();
2718
2734
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2719
2735
  type: "commit-tool-output",
2720
- source: "session",
2736
+ source: "session-bus",
2721
2737
  input: {
2722
2738
  toolId: toolId,
2723
2739
  content: content,
@@ -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();
@@ -2754,14 +2771,15 @@ var ClientSession = /** @class */ (function () {
2754
2771
  result = _a.sent();
2755
2772
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2756
2773
  type: "commit-user-message",
2757
- source: "session",
2774
+ source: "session-bus",
2758
2775
  input: {
2759
2776
  message: message,
2760
2777
  },
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();
@@ -2787,12 +2805,13 @@ var ClientSession = /** @class */ (function () {
2787
2805
  result = _a.sent();
2788
2806
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2789
2807
  type: "commit-flush",
2790
- source: "session",
2808
+ source: "session-bus",
2791
2809
  input: {},
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();
@@ -2821,14 +2840,15 @@ var ClientSession = /** @class */ (function () {
2821
2840
  result = _a.sent();
2822
2841
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2823
2842
  type: "commit-system-message",
2824
- source: "session",
2843
+ source: "session-bus",
2825
2844
  input: {
2826
2845
  message: message
2827
2846
  },
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();
@@ -2865,12 +2885,13 @@ var ClientSession = /** @class */ (function () {
2865
2885
  }); });
2866
2886
  _this.params.bus.emit(_this.params.clientId, {
2867
2887
  type: "connect",
2868
- source: "session",
2888
+ source: "session-bus",
2869
2889
  input: {},
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;
@@ -4902,7 +4923,7 @@ var ClientStorage = /** @class */ (function () {
4902
4923
  }
4903
4924
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
4904
4925
  type: "take",
4905
- source: "storage",
4926
+ source: "storage-bus",
4906
4927
  input: {
4907
4928
  search: search,
4908
4929
  total: total,
@@ -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();
@@ -4945,14 +4967,15 @@ var ClientStorage = /** @class */ (function () {
4945
4967
  }
4946
4968
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
4947
4969
  type: "upsert",
4948
- source: "storage",
4970
+ source: "storage-bus",
4949
4971
  input: {
4950
4972
  item: item,
4951
4973
  },
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();
@@ -4980,14 +5003,15 @@ var ClientStorage = /** @class */ (function () {
4980
5003
  }
4981
5004
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
4982
5005
  type: "remove",
4983
- source: "storage",
5006
+ source: "storage-bus",
4984
5007
  input: {
4985
5008
  itemId: itemId,
4986
5009
  },
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();
@@ -5008,12 +5032,13 @@ var ClientStorage = /** @class */ (function () {
5008
5032
  this._createEmbedding.clear();
5009
5033
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
5010
5034
  type: "clear",
5011
- source: "storage",
5035
+ source: "storage-bus",
5012
5036
  input: {},
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();
@@ -5038,7 +5063,7 @@ var ClientStorage = /** @class */ (function () {
5038
5063
  result = (_a = this._itemMap.get(itemId)) !== null && _a !== void 0 ? _a : null;
5039
5064
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
5040
5065
  type: "get",
5041
- source: "storage",
5066
+ source: "storage-bus",
5042
5067
  input: {
5043
5068
  itemId: itemId,
5044
5069
  },
@@ -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();
@@ -5088,14 +5114,15 @@ var ClientStorage = /** @class */ (function () {
5088
5114
  }
5089
5115
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
5090
5116
  type: "list",
5091
- source: "storage",
5117
+ source: "storage-bus",
5092
5118
  input: {},
5093
5119
  output: {
5094
5120
  result: result,
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();
@@ -5831,14 +5858,15 @@ var ClientState = /** @class */ (function () {
5831
5858
  }
5832
5859
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
5833
5860
  type: "set-state",
5834
- source: "state",
5861
+ source: "state-bus",
5835
5862
  input: {},
5836
5863
  output: {
5837
5864
  state: this._state,
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();
@@ -5864,14 +5892,15 @@ var ClientState = /** @class */ (function () {
5864
5892
  }
5865
5893
  return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
5866
5894
  type: "get-state",
5867
- source: "state",
5895
+ source: "state-bus",
5868
5896
  input: {},
5869
5897
  output: {
5870
5898
  state: this._state,
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
- return _this.getEventSubject(clientId, source).subscribe(fn);
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.getEventSubject.has("".concat(clientId, "-").concat(event.source))) {
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
- return [2 /*return*/];
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
  }); };
@@ -7508,20 +7552,27 @@ var executeForce = function (content, clientId) { return __awaiter(void 0, void
7508
7552
  }); };
7509
7553
 
7510
7554
  var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
7511
- "agent",
7512
- "history",
7513
- "session",
7514
- "state",
7515
- "storage",
7516
- "swarm",
7555
+ "agent-bus",
7556
+ "history-bus",
7557
+ "session-bus",
7558
+ "state-bus",
7559
+ "storage-bus",
7560
+ "swarm-bus",
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);
@@ -7719,12 +7771,12 @@ var makeAutoDispose = function (clientId, swarmName, _a) {
7719
7771
  };
7720
7772
 
7721
7773
  var DISALLOWED_EVENT_SOURCE_LIST = new Set([
7722
- "agent",
7723
- "history",
7724
- "session",
7725
- "state",
7726
- "storage",
7727
- "swarm",
7774
+ "agent-bus",
7775
+ "history-bus",
7776
+ "session-bus",
7777
+ "state-bus",
7778
+ "storage-bus",
7779
+ "swarm-bus",
7728
7780
  ]);
7729
7781
  /**
7730
7782
  * Emits an event to the swarm bus service.
@@ -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
- return swarm.busService.subscribe(clientId, "agent", fn);
7886
+ validateClientId$5(clientId);
7887
+ swarm.busService.subscribe(clientId, "agent-bus", 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
7902
  * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
7834
- * @returns {Function} - The unsubscribe function.
7835
7903
  */
7836
7904
  var listenHistoryEvent = function (clientId, fn) {
7837
7905
  swarm.loggerService.log("middleware listenHistoryEvent", {
7838
7906
  clientId: clientId,
7839
7907
  });
7840
- return swarm.busService.subscribe(clientId, "history", fn);
7908
+ validateClientId$4(clientId);
7909
+ swarm.busService.subscribe(clientId, "history-bus", 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
- return swarm.busService.subscribe(clientId, "session", fn);
7930
+ validateClientId$3(clientId);
7931
+ swarm.busService.subscribe(clientId, "session-bus", 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
- return swarm.busService.subscribe(clientId, "state", fn);
7952
+ validateClientId$2(clientId);
7953
+ swarm.busService.subscribe(clientId, "state-bus", 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
- return swarm.busService.subscribe(clientId, "storage", fn);
7974
+ validateClientId$1(clientId);
7975
+ swarm.busService.subscribe(clientId, "storage-bus", 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
7990
  * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
7890
- * @returns {Function} - A function to unsubscribe from 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
- return swarm.busService.subscribe(clientId, "swarm", fn);
7996
+ validateClientId(clientId);
7997
+ swarm.busService.subscribe(clientId, "swarm-bus", fn);
7897
7998
  };
7898
7999
 
7899
8000
  var StorageUtils = /** @class */ (function () {