agent-swarm-kit 1.0.74 → 1.0.76

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var diScoped = require('di-scoped');
4
- var functoolsKit = require('functools-kit');
5
4
  var diKit = require('di-kit');
5
+ var functoolsKit = require('functools-kit');
6
6
  var lodashEs = require('lodash-es');
7
7
  var xml2js = require('xml2js');
8
8
 
@@ -167,6 +167,50 @@ var ContextService = diScoped.scoped(/** @class */ (function () {
167
167
  return class_1;
168
168
  }()));
169
169
 
170
+ var _a;
171
+ var init = (_a = diKit.createActivator("agent-swarm"), _a.init), inject = _a.inject, provide = _a.provide;
172
+
173
+ var baseServices$1 = {
174
+ busService: Symbol('busService'),
175
+ loggerService: Symbol('loggerService'),
176
+ contextService: Symbol('contextService'),
177
+ };
178
+ var connectionServices$1 = {
179
+ agentConnectionService: Symbol('agentConnectionService'),
180
+ historyConnectionService: Symbol('historyConnectionService'),
181
+ swarmConnectionService: Symbol('swarmConnectionService'),
182
+ sessionConnectionService: Symbol('sessionConnectionService'),
183
+ storageConnectionService: Symbol('storageConnectionService'),
184
+ stateConnectionService: Symbol('stateConnectionService'),
185
+ };
186
+ var schemaServices$1 = {
187
+ completionSchemaService: Symbol('completionSchemaService'),
188
+ agentSchemaService: Symbol('agentSchemaService'),
189
+ swarmSchemaService: Symbol('swarmSchemaService'),
190
+ toolSchemaService: Symbol('toolSchemaService'),
191
+ embeddingSchemaService: Symbol('embeddingSchemaService'),
192
+ storageSchemaService: Symbol('storageSchemaService'),
193
+ stateSchemaService: Symbol('stateSchemaService'),
194
+ };
195
+ var publicServices$1 = {
196
+ agentPublicService: Symbol('agentPublicService'),
197
+ historyPublicService: Symbol('historyPublicService'),
198
+ sessionPublicService: Symbol('sessionPublicService'),
199
+ swarmPublicService: Symbol('swarmPublicService'),
200
+ storagePublicService: Symbol('storagePublicService'),
201
+ statePublicService: Symbol('statePublicService'),
202
+ };
203
+ var validationServices$1 = {
204
+ agentValidationService: Symbol('agentValidationService'),
205
+ toolValidationService: Symbol('toolValidationService'),
206
+ sessionValidationService: Symbol('sessionValidationService'),
207
+ swarmValidationService: Symbol('swarmValidationService'),
208
+ completionValidationService: Symbol('completionValidationService'),
209
+ embeddingValidationService: Symbol('embeddingValidationService'),
210
+ storageValidationService: Symbol('storageValidationService'),
211
+ };
212
+ var TYPES = __assign(__assign(__assign(__assign(__assign({}, baseServices$1), schemaServices$1), connectionServices$1), publicServices$1), validationServices$1);
213
+
170
214
  /**
171
215
  * LoggerService class that implements the ILogger interface.
172
216
  * Provides methods to log and debug messages.
@@ -174,6 +218,7 @@ var ContextService = diScoped.scoped(/** @class */ (function () {
174
218
  var LoggerService = /** @class */ (function () {
175
219
  function LoggerService() {
176
220
  var _this = this;
221
+ this.contextService = inject(TYPES.contextService);
177
222
  this._logger = {
178
223
  /**
179
224
  * Logs messages.
@@ -193,24 +238,32 @@ var LoggerService = /** @class */ (function () {
193
238
  * @param {...any} args - The messages to log.
194
239
  */
195
240
  this.log = function () {
196
- var _a;
241
+ var _a, _b;
197
242
  var args = [];
198
243
  for (var _i = 0; _i < arguments.length; _i++) {
199
244
  args[_i] = arguments[_i];
200
245
  }
201
- (_a = _this._logger).log.apply(_a, __spreadArray([], __read(args), false));
246
+ if (ContextService.hasContext()) {
247
+ (_a = _this._logger).log.apply(_a, __spreadArray(__spreadArray([], __read(args), false), [_this.contextService.context], false));
248
+ return;
249
+ }
250
+ (_b = _this._logger).log.apply(_b, __spreadArray([], __read(args), false));
202
251
  };
203
252
  /**
204
253
  * Logs debug messages using the current logger.
205
254
  * @param {...any} args - The debug messages to log.
206
255
  */
207
256
  this.debug = function () {
208
- var _a;
257
+ var _a, _b;
209
258
  var args = [];
210
259
  for (var _i = 0; _i < arguments.length; _i++) {
211
260
  args[_i] = arguments[_i];
212
261
  }
213
- (_a = _this._logger).debug.apply(_a, __spreadArray([], __read(args), false));
262
+ if (ContextService.hasContext()) {
263
+ (_a = _this._logger).debug.apply(_a, __spreadArray(__spreadArray([], __read(args), false), [_this.contextService.context], false));
264
+ return;
265
+ }
266
+ (_b = _this._logger).debug.apply(_b, __spreadArray([], __read(args), false));
214
267
  };
215
268
  /**
216
269
  * Sets a new logger.
@@ -223,50 +276,6 @@ var LoggerService = /** @class */ (function () {
223
276
  return LoggerService;
224
277
  }());
225
278
 
226
- var _a;
227
- var init = (_a = diKit.createActivator("agent-swarm"), _a.init), inject = _a.inject, provide = _a.provide;
228
-
229
- var baseServices$1 = {
230
- busService: Symbol('busService'),
231
- loggerService: Symbol('loggerService'),
232
- contextService: Symbol('contextService'),
233
- };
234
- var connectionServices$1 = {
235
- agentConnectionService: Symbol('agentConnectionService'),
236
- historyConnectionService: Symbol('historyConnectionService'),
237
- swarmConnectionService: Symbol('swarmConnectionService'),
238
- sessionConnectionService: Symbol('sessionConnectionService'),
239
- storageConnectionService: Symbol('storageConnectionService'),
240
- stateConnectionService: Symbol('stateConnectionService'),
241
- };
242
- var schemaServices$1 = {
243
- completionSchemaService: Symbol('completionSchemaService'),
244
- agentSchemaService: Symbol('agentSchemaService'),
245
- swarmSchemaService: Symbol('swarmSchemaService'),
246
- toolSchemaService: Symbol('toolSchemaService'),
247
- embeddingSchemaService: Symbol('embeddingSchemaService'),
248
- storageSchemaService: Symbol('storageSchemaService'),
249
- stateSchemaService: Symbol('stateSchemaService'),
250
- };
251
- var publicServices$1 = {
252
- agentPublicService: Symbol('agentPublicService'),
253
- historyPublicService: Symbol('historyPublicService'),
254
- sessionPublicService: Symbol('sessionPublicService'),
255
- swarmPublicService: Symbol('swarmPublicService'),
256
- storagePublicService: Symbol('storagePublicService'),
257
- statePublicService: Symbol('statePublicService'),
258
- };
259
- var validationServices$1 = {
260
- agentValidationService: Symbol('agentValidationService'),
261
- toolValidationService: Symbol('toolValidationService'),
262
- sessionValidationService: Symbol('sessionValidationService'),
263
- swarmValidationService: Symbol('swarmValidationService'),
264
- completionValidationService: Symbol('completionValidationService'),
265
- embeddingValidationService: Symbol('embeddingValidationService'),
266
- storageValidationService: Symbol('storageValidationService'),
267
- };
268
- var TYPES = __assign(__assign(__assign(__assign(__assign({}, baseServices$1), schemaServices$1), connectionServices$1), publicServices$1), validationServices$1);
269
-
270
279
  /**
271
280
  * Service for managing agent schemas.
272
281
  */
@@ -1558,7 +1567,6 @@ var AgentConnectionService = /** @class */ (function () {
1558
1567
  this.loggerService.log("agentConnectionService execute", {
1559
1568
  input: input,
1560
1569
  mode: mode,
1561
- context: this.contextService.context,
1562
1570
  });
1563
1571
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).execute(input, mode)];
1564
1572
  case 1: return [2 /*return*/, _a.sent()];
@@ -1573,9 +1581,7 @@ var AgentConnectionService = /** @class */ (function () {
1573
1581
  return __generator(this, function (_a) {
1574
1582
  switch (_a.label) {
1575
1583
  case 0:
1576
- this.loggerService.log("agentConnectionService waitForOutput", {
1577
- context: this.contextService.context,
1578
- });
1584
+ this.loggerService.log("agentConnectionService waitForOutput");
1579
1585
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).waitForOutput()];
1580
1586
  case 1: return [2 /*return*/, _a.sent()];
1581
1587
  }
@@ -1594,7 +1600,6 @@ var AgentConnectionService = /** @class */ (function () {
1594
1600
  this.loggerService.log("agentConnectionService commitToolOutput", {
1595
1601
  content: content,
1596
1602
  toolId: toolId,
1597
- context: this.contextService.context,
1598
1603
  });
1599
1604
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitToolOutput(toolId, content)];
1600
1605
  case 1: return [2 /*return*/, _a.sent()];
@@ -1612,7 +1617,6 @@ var AgentConnectionService = /** @class */ (function () {
1612
1617
  case 0:
1613
1618
  this.loggerService.log("agentConnectionService commitSystemMessage", {
1614
1619
  message: message,
1615
- context: this.contextService.context,
1616
1620
  });
1617
1621
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitSystemMessage(message)];
1618
1622
  case 1: return [2 /*return*/, _a.sent()];
@@ -1630,7 +1634,6 @@ var AgentConnectionService = /** @class */ (function () {
1630
1634
  case 0:
1631
1635
  this.loggerService.log("agentConnectionService commitUserMessage", {
1632
1636
  message: message,
1633
- context: this.contextService.context,
1634
1637
  });
1635
1638
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitUserMessage(message)];
1636
1639
  case 1: return [2 /*return*/, _a.sent()];
@@ -1645,9 +1648,7 @@ var AgentConnectionService = /** @class */ (function () {
1645
1648
  return __generator(this, function (_a) {
1646
1649
  switch (_a.label) {
1647
1650
  case 0:
1648
- this.loggerService.log("agentConnectionService commitAgentChange", {
1649
- context: this.contextService.context,
1650
- });
1651
+ this.loggerService.log("agentConnectionService commitAgentChange");
1651
1652
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitAgentChange()];
1652
1653
  case 1: return [2 /*return*/, _a.sent()];
1653
1654
  }
@@ -1661,9 +1662,7 @@ var AgentConnectionService = /** @class */ (function () {
1661
1662
  return __generator(this, function (_a) {
1662
1663
  switch (_a.label) {
1663
1664
  case 0:
1664
- this.loggerService.log("agentConnectionService commitFlush", {
1665
- context: this.contextService.context,
1666
- });
1665
+ this.loggerService.log("agentConnectionService commitFlush");
1667
1666
  return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitFlush()];
1668
1667
  case 1: return [2 /*return*/, _a.sent()];
1669
1668
  }
@@ -1678,9 +1677,7 @@ var AgentConnectionService = /** @class */ (function () {
1678
1677
  return __generator(this, function (_a) {
1679
1678
  switch (_a.label) {
1680
1679
  case 0:
1681
- this.loggerService.log("agentConnectionService dispose", {
1682
- context: this.contextService.context,
1683
- });
1680
+ this.loggerService.log("agentConnectionService dispose");
1684
1681
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName);
1685
1682
  if (!this.getAgent.has(key)) {
1686
1683
  return [2 /*return*/];
@@ -2001,7 +1998,7 @@ var HistoryConnectionService = /** @class */ (function () {
2001
1998
  switch (_a.label) {
2002
1999
  case 0:
2003
2000
  this.loggerService.log("historyConnectionService push", {
2004
- context: this.contextService.context,
2001
+ message: message,
2005
2002
  });
2006
2003
  return [4 /*yield*/, this.getHistory(this.contextService.context.clientId, this.contextService.context.agentName).push(message)];
2007
2004
  case 1: return [2 /*return*/, _a.sent()];
@@ -2018,7 +2015,7 @@ var HistoryConnectionService = /** @class */ (function () {
2018
2015
  switch (_a.label) {
2019
2016
  case 0:
2020
2017
  this.loggerService.log("historyConnectionService toArrayForAgent", {
2021
- context: this.contextService.context,
2018
+ prompt: prompt,
2022
2019
  });
2023
2020
  return [4 /*yield*/, this.getHistory(this.contextService.context.clientId, this.contextService.context.agentName).toArrayForAgent(prompt)];
2024
2021
  case 1: return [2 /*return*/, _a.sent()];
@@ -2033,9 +2030,7 @@ var HistoryConnectionService = /** @class */ (function () {
2033
2030
  return __generator(this, function (_a) {
2034
2031
  switch (_a.label) {
2035
2032
  case 0:
2036
- this.loggerService.log("historyConnectionService toArrayForRaw", {
2037
- context: this.contextService.context,
2038
- });
2033
+ this.loggerService.log("historyConnectionService toArrayForRaw");
2039
2034
  return [4 /*yield*/, this.getHistory(this.contextService.context.clientId, this.contextService.context.agentName).toArrayForRaw()];
2040
2035
  case 1: return [2 /*return*/, _a.sent()];
2041
2036
  }
@@ -2050,9 +2045,7 @@ var HistoryConnectionService = /** @class */ (function () {
2050
2045
  return __generator(this, function (_a) {
2051
2046
  switch (_a.label) {
2052
2047
  case 0:
2053
- this.loggerService.log("historyConnectionService dispose", {
2054
- context: this.contextService.context,
2055
- });
2048
+ this.loggerService.log("historyConnectionService dispose");
2056
2049
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName);
2057
2050
  if (!this.getHistory.has(key)) {
2058
2051
  return [2 /*return*/];
@@ -2445,9 +2438,7 @@ var SwarmConnectionService = /** @class */ (function () {
2445
2438
  return __generator(this, function (_a) {
2446
2439
  switch (_a.label) {
2447
2440
  case 0:
2448
- this.loggerService.log("swarmConnectionService cancelOutput", {
2449
- context: this.contextService.context,
2450
- });
2441
+ this.loggerService.log("swarmConnectionService cancelOutput");
2451
2442
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).cancelOutput()];
2452
2443
  case 1: return [2 /*return*/, _a.sent()];
2453
2444
  }
@@ -2461,9 +2452,7 @@ var SwarmConnectionService = /** @class */ (function () {
2461
2452
  return __generator(this, function (_a) {
2462
2453
  switch (_a.label) {
2463
2454
  case 0:
2464
- this.loggerService.log("swarmConnectionService waitForOutput", {
2465
- context: this.contextService.context,
2466
- });
2455
+ this.loggerService.log("swarmConnectionService waitForOutput");
2467
2456
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).waitForOutput()];
2468
2457
  case 1: return [2 /*return*/, _a.sent()];
2469
2458
  }
@@ -2477,9 +2466,7 @@ var SwarmConnectionService = /** @class */ (function () {
2477
2466
  return __generator(this, function (_a) {
2478
2467
  switch (_a.label) {
2479
2468
  case 0:
2480
- this.loggerService.log("swarmConnectionService getAgentName", {
2481
- context: this.contextService.context,
2482
- });
2469
+ this.loggerService.log("swarmConnectionService getAgentName");
2483
2470
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).getAgentName()];
2484
2471
  case 1: return [2 /*return*/, _a.sent()];
2485
2472
  }
@@ -2493,9 +2480,7 @@ var SwarmConnectionService = /** @class */ (function () {
2493
2480
  return __generator(this, function (_a) {
2494
2481
  switch (_a.label) {
2495
2482
  case 0:
2496
- this.loggerService.log("swarmConnectionService getAgent", {
2497
- context: this.contextService.context,
2498
- });
2483
+ this.loggerService.log("swarmConnectionService getAgent");
2499
2484
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).getAgent()];
2500
2485
  case 1: return [2 /*return*/, _a.sent()];
2501
2486
  }
@@ -2512,7 +2497,7 @@ var SwarmConnectionService = /** @class */ (function () {
2512
2497
  switch (_a.label) {
2513
2498
  case 0:
2514
2499
  this.loggerService.log("swarmConnectionService setAgentRef", {
2515
- context: this.contextService.context,
2500
+ agentName: agentName,
2516
2501
  });
2517
2502
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentRef(agentName, agent)];
2518
2503
  case 1: return [2 /*return*/, _a.sent()];
@@ -2530,7 +2515,6 @@ var SwarmConnectionService = /** @class */ (function () {
2530
2515
  case 0:
2531
2516
  this.loggerService.log("swarmConnectionService setAgentName", {
2532
2517
  agentName: agentName,
2533
- context: this.contextService.context,
2534
2518
  });
2535
2519
  return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentName(agentName)];
2536
2520
  case 1: return [2 /*return*/, _a.sent()];
@@ -2544,9 +2528,7 @@ var SwarmConnectionService = /** @class */ (function () {
2544
2528
  this.dispose = function () { return __awaiter(_this, void 0, void 0, function () {
2545
2529
  var key;
2546
2530
  return __generator(this, function (_a) {
2547
- this.loggerService.log("swarmConnectionService dispose", {
2548
- context: this.contextService.context,
2549
- });
2531
+ this.loggerService.log("swarmConnectionService dispose");
2550
2532
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.swarmName);
2551
2533
  if (!this.getSwarm.has(key)) {
2552
2534
  return [2 /*return*/];
@@ -2896,17 +2878,22 @@ var ClientSession = /** @class */ (function () {
2896
2878
  clientId: _this.params.clientId,
2897
2879
  });
2898
2880
  return function (incoming) { return __awaiter(_this, void 0, void 0, function () {
2899
- var _a;
2881
+ var data, _a;
2900
2882
  var _b;
2901
2883
  return __generator(this, function (_c) {
2902
2884
  switch (_c.label) {
2903
2885
  case 0:
2904
2886
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
2905
- _a = connector;
2906
- _b = {};
2907
2887
  return [4 /*yield*/, this.execute(incoming.data, "user")];
2908
2888
  case 1:
2909
- _b.data = _c.sent();
2889
+ data = _c.sent();
2890
+ if (!data) {
2891
+ return [2 /*return*/];
2892
+ }
2893
+ _a = connector;
2894
+ _b = {
2895
+ data: data
2896
+ };
2910
2897
  return [4 /*yield*/, this.params.swarm.getAgentName()];
2911
2898
  case 2: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
2912
2899
  _b.clientId = incoming.clientId,
@@ -2973,7 +2960,7 @@ var SessionConnectionService = /** @class */ (function () {
2973
2960
  switch (_a.label) {
2974
2961
  case 0:
2975
2962
  this.loggerService.log("sessionConnectionService emit", {
2976
- context: this.contextService.context,
2963
+ content: content,
2977
2964
  });
2978
2965
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).emit(content)];
2979
2966
  case 1: return [2 /*return*/, _a.sent()];
@@ -2990,7 +2977,6 @@ var SessionConnectionService = /** @class */ (function () {
2990
2977
  switch (_a.label) {
2991
2978
  case 0:
2992
2979
  this.loggerService.log("sessionConnectionService execute", {
2993
- context: this.contextService.context,
2994
2980
  content: content,
2995
2981
  mode: mode,
2996
2982
  });
@@ -3004,11 +2990,9 @@ var SessionConnectionService = /** @class */ (function () {
3004
2990
  * @param {SendMessageFn} connector - The function to send messages.
3005
2991
  * @returns {ReceiveMessageFn} The function to receive messages.
3006
2992
  */
3007
- this.connect = function (connector) {
3008
- _this.loggerService.log("sessionConnectionService connect", {
3009
- context: _this.contextService.context,
3010
- });
3011
- return _this.getSession(_this.contextService.context.clientId, _this.contextService.context.swarmName).connect(connector);
2993
+ this.connect = function (connector, clientId, swarmName) {
2994
+ _this.loggerService.log("sessionConnectionService connect");
2995
+ return _this.getSession(clientId, swarmName).connect(connector);
3012
2996
  };
3013
2997
  /**
3014
2998
  * Commits tool output to the session.
@@ -3021,7 +3005,6 @@ var SessionConnectionService = /** @class */ (function () {
3021
3005
  switch (_a.label) {
3022
3006
  case 0:
3023
3007
  this.loggerService.log("sessionConnectionService commitToolOutput", {
3024
- context: this.contextService.context,
3025
3008
  content: content,
3026
3009
  toolId: toolId,
3027
3010
  });
@@ -3040,7 +3023,6 @@ var SessionConnectionService = /** @class */ (function () {
3040
3023
  switch (_a.label) {
3041
3024
  case 0:
3042
3025
  this.loggerService.log("sessionConnectionService commitSystemMessage", {
3043
- context: this.contextService.context,
3044
3026
  message: message,
3045
3027
  });
3046
3028
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
@@ -3058,7 +3040,6 @@ var SessionConnectionService = /** @class */ (function () {
3058
3040
  switch (_a.label) {
3059
3041
  case 0:
3060
3042
  this.loggerService.log("sessionConnectionService commitUserMessage", {
3061
- context: this.contextService.context,
3062
3043
  message: message,
3063
3044
  });
3064
3045
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
@@ -3075,9 +3056,7 @@ var SessionConnectionService = /** @class */ (function () {
3075
3056
  return __generator(this, function (_a) {
3076
3057
  switch (_a.label) {
3077
3058
  case 0:
3078
- this.loggerService.log("sessionConnectionService commitFlush", {
3079
- context: this.contextService.context,
3080
- });
3059
+ this.loggerService.log("sessionConnectionService commitFlush");
3081
3060
  return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitFlush()];
3082
3061
  case 1: return [2 /*return*/, _a.sent()];
3083
3062
  }
@@ -3092,9 +3071,7 @@ var SessionConnectionService = /** @class */ (function () {
3092
3071
  return __generator(this, function (_a) {
3093
3072
  switch (_a.label) {
3094
3073
  case 0:
3095
- this.loggerService.log("sessionConnectionService dispose", {
3096
- context: this.contextService.context,
3097
- });
3074
+ this.loggerService.log("sessionConnectionService dispose");
3098
3075
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.swarmName);
3099
3076
  if (!this.getSession.has(key)) {
3100
3077
  return [2 /*return*/];
@@ -3125,12 +3102,13 @@ var AgentPublicService = /** @class */ (function () {
3125
3102
  * @param {AgentName} agentName - The name of the agent.
3126
3103
  * @returns {Promise<unknown>} The agent reference.
3127
3104
  */
3128
- this.createAgentRef = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3105
+ this.createAgentRef = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3129
3106
  var _this = this;
3130
3107
  return __generator(this, function (_a) {
3131
3108
  switch (_a.label) {
3132
3109
  case 0:
3133
3110
  this.loggerService.log("agentPublicService createAgentRef", {
3111
+ requestId: requestId,
3134
3112
  clientId: clientId,
3135
3113
  agentName: agentName,
3136
3114
  });
@@ -3142,6 +3120,7 @@ var AgentPublicService = /** @class */ (function () {
3142
3120
  }
3143
3121
  });
3144
3122
  }); }, {
3123
+ requestId: requestId,
3145
3124
  clientId: clientId,
3146
3125
  agentName: agentName,
3147
3126
  swarmName: "",
@@ -3159,12 +3138,13 @@ var AgentPublicService = /** @class */ (function () {
3159
3138
  * @param {AgentName} agentName - The name of the agent.
3160
3139
  * @returns {Promise<unknown>} The execution result.
3161
3140
  */
3162
- this.execute = function (input, mode, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3141
+ this.execute = function (input, mode, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3163
3142
  var _this = this;
3164
3143
  return __generator(this, function (_a) {
3165
3144
  switch (_a.label) {
3166
3145
  case 0:
3167
3146
  this.loggerService.log("agentPublicService execute", {
3147
+ requestId: requestId,
3168
3148
  input: input,
3169
3149
  clientId: clientId,
3170
3150
  agentName: agentName,
@@ -3178,6 +3158,7 @@ var AgentPublicService = /** @class */ (function () {
3178
3158
  }
3179
3159
  });
3180
3160
  }); }, {
3161
+ requestId: requestId,
3181
3162
  clientId: clientId,
3182
3163
  agentName: agentName,
3183
3164
  swarmName: "",
@@ -3194,12 +3175,13 @@ var AgentPublicService = /** @class */ (function () {
3194
3175
  * @param {AgentName} agentName - The name of the agent.
3195
3176
  * @returns {Promise<unknown>} The output result.
3196
3177
  */
3197
- this.waitForOutput = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3178
+ this.waitForOutput = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3198
3179
  var _this = this;
3199
3180
  return __generator(this, function (_a) {
3200
3181
  switch (_a.label) {
3201
3182
  case 0:
3202
3183
  this.loggerService.log("agentPublicService waitForOutput", {
3184
+ requestId: requestId,
3203
3185
  clientId: clientId,
3204
3186
  agentName: agentName,
3205
3187
  });
@@ -3211,6 +3193,7 @@ var AgentPublicService = /** @class */ (function () {
3211
3193
  }
3212
3194
  });
3213
3195
  }); }, {
3196
+ requestId: requestId,
3214
3197
  clientId: clientId,
3215
3198
  agentName: agentName,
3216
3199
  swarmName: "",
@@ -3229,12 +3212,13 @@ var AgentPublicService = /** @class */ (function () {
3229
3212
  * @param {AgentName} agentName - The name of the agent.
3230
3213
  * @returns {Promise<unknown>} The commit result.
3231
3214
  */
3232
- this.commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3215
+ this.commitToolOutput = function (toolId, content, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3233
3216
  var _this = this;
3234
3217
  return __generator(this, function (_a) {
3235
3218
  switch (_a.label) {
3236
3219
  case 0:
3237
3220
  this.loggerService.log("agentPublicService commitToolOutput", {
3221
+ requestId: requestId,
3238
3222
  content: content,
3239
3223
  clientId: clientId,
3240
3224
  toolId: toolId,
@@ -3248,6 +3232,7 @@ var AgentPublicService = /** @class */ (function () {
3248
3232
  }
3249
3233
  });
3250
3234
  }); }, {
3235
+ requestId: requestId,
3251
3236
  clientId: clientId,
3252
3237
  agentName: agentName,
3253
3238
  swarmName: "",
@@ -3265,12 +3250,13 @@ var AgentPublicService = /** @class */ (function () {
3265
3250
  * @param {AgentName} agentName - The name of the agent.
3266
3251
  * @returns {Promise<unknown>} The commit result.
3267
3252
  */
3268
- this.commitSystemMessage = function (message, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3253
+ this.commitSystemMessage = function (message, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3269
3254
  var _this = this;
3270
3255
  return __generator(this, function (_a) {
3271
3256
  switch (_a.label) {
3272
3257
  case 0:
3273
3258
  this.loggerService.log("agentPublicService commitSystemMessage", {
3259
+ requestId: requestId,
3274
3260
  message: message,
3275
3261
  clientId: clientId,
3276
3262
  agentName: agentName,
@@ -3283,6 +3269,7 @@ var AgentPublicService = /** @class */ (function () {
3283
3269
  }
3284
3270
  });
3285
3271
  }); }, {
3272
+ requestId: requestId,
3286
3273
  clientId: clientId,
3287
3274
  agentName: agentName,
3288
3275
  swarmName: "",
@@ -3300,12 +3287,13 @@ var AgentPublicService = /** @class */ (function () {
3300
3287
  * @param {AgentName} agentName - The name of the agent.
3301
3288
  * @returns {Promise<unknown>} The commit result.
3302
3289
  */
3303
- this.commitUserMessage = function (message, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3290
+ this.commitUserMessage = function (message, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3304
3291
  var _this = this;
3305
3292
  return __generator(this, function (_a) {
3306
3293
  switch (_a.label) {
3307
3294
  case 0:
3308
3295
  this.loggerService.log("agentPublicService commitUserMessage", {
3296
+ requestId: requestId,
3309
3297
  message: message,
3310
3298
  clientId: clientId,
3311
3299
  agentName: agentName,
@@ -3318,6 +3306,7 @@ var AgentPublicService = /** @class */ (function () {
3318
3306
  }
3319
3307
  });
3320
3308
  }); }, {
3309
+ requestId: requestId,
3321
3310
  clientId: clientId,
3322
3311
  agentName: agentName,
3323
3312
  swarmName: "",
@@ -3334,12 +3323,13 @@ var AgentPublicService = /** @class */ (function () {
3334
3323
  * @param {AgentName} agentName - The name of the agent.
3335
3324
  * @returns {Promise<unknown>} The commit result.
3336
3325
  */
3337
- this.commitFlush = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3326
+ this.commitFlush = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3338
3327
  var _this = this;
3339
3328
  return __generator(this, function (_a) {
3340
3329
  switch (_a.label) {
3341
3330
  case 0:
3342
3331
  this.loggerService.log("agentPublicService commitFlush", {
3332
+ requestId: requestId,
3343
3333
  clientId: clientId,
3344
3334
  agentName: agentName,
3345
3335
  });
@@ -3351,6 +3341,7 @@ var AgentPublicService = /** @class */ (function () {
3351
3341
  }
3352
3342
  });
3353
3343
  }); }, {
3344
+ requestId: requestId,
3354
3345
  clientId: clientId,
3355
3346
  agentName: agentName,
3356
3347
  swarmName: "",
@@ -3367,12 +3358,13 @@ var AgentPublicService = /** @class */ (function () {
3367
3358
  * @param {AgentName} agentName - The name of the agent.
3368
3359
  * @returns {Promise<unknown>} The commit result.
3369
3360
  */
3370
- this.commitAgentChange = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3361
+ this.commitAgentChange = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3371
3362
  var _this = this;
3372
3363
  return __generator(this, function (_a) {
3373
3364
  switch (_a.label) {
3374
3365
  case 0:
3375
3366
  this.loggerService.log("agentPublicService commitAgentChange", {
3367
+ requestId: requestId,
3376
3368
  clientId: clientId,
3377
3369
  agentName: agentName,
3378
3370
  });
@@ -3384,6 +3376,7 @@ var AgentPublicService = /** @class */ (function () {
3384
3376
  }
3385
3377
  });
3386
3378
  }); }, {
3379
+ requestId: requestId,
3387
3380
  clientId: clientId,
3388
3381
  agentName: agentName,
3389
3382
  swarmName: "",
@@ -3400,12 +3393,13 @@ var AgentPublicService = /** @class */ (function () {
3400
3393
  * @param {AgentName} agentName - The name of the agent.
3401
3394
  * @returns {Promise<unknown>} The dispose result.
3402
3395
  */
3403
- this.dispose = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3396
+ this.dispose = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3404
3397
  var _this = this;
3405
3398
  return __generator(this, function (_a) {
3406
3399
  switch (_a.label) {
3407
3400
  case 0:
3408
3401
  this.loggerService.log("agentPublicService dispose", {
3402
+ requestId: requestId,
3409
3403
  clientId: clientId,
3410
3404
  agentName: agentName,
3411
3405
  });
@@ -3417,6 +3411,7 @@ var AgentPublicService = /** @class */ (function () {
3417
3411
  }
3418
3412
  });
3419
3413
  }); }, {
3414
+ requestId: requestId,
3420
3415
  clientId: clientId,
3421
3416
  agentName: agentName,
3422
3417
  swarmName: "",
@@ -3446,12 +3441,13 @@ var HistoryPublicService = /** @class */ (function () {
3446
3441
  * @param {AgentName} agentName - The agent name.
3447
3442
  * @returns {Promise<void>} A promise that resolves when the operation is complete.
3448
3443
  */
3449
- this.push = function (message, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3444
+ this.push = function (message, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3450
3445
  var _this = this;
3451
3446
  return __generator(this, function (_a) {
3452
3447
  switch (_a.label) {
3453
3448
  case 0:
3454
3449
  this.loggerService.log("historyPublicService push", {
3450
+ requestId: requestId,
3455
3451
  message: message,
3456
3452
  clientId: clientId,
3457
3453
  agentName: agentName,
@@ -3464,6 +3460,7 @@ var HistoryPublicService = /** @class */ (function () {
3464
3460
  }
3465
3461
  });
3466
3462
  }); }, {
3463
+ requestId: requestId,
3467
3464
  clientId: clientId,
3468
3465
  agentName: agentName,
3469
3466
  swarmName: "",
@@ -3481,7 +3478,7 @@ var HistoryPublicService = /** @class */ (function () {
3481
3478
  * @param {AgentName} agentName - The agent name.
3482
3479
  * @returns {Promise<any[]>} A promise that resolves to an array of history items.
3483
3480
  */
3484
- this.toArrayForAgent = function (prompt, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3481
+ this.toArrayForAgent = function (prompt, requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3485
3482
  var _this = this;
3486
3483
  return __generator(this, function (_a) {
3487
3484
  switch (_a.label) {
@@ -3499,6 +3496,7 @@ var HistoryPublicService = /** @class */ (function () {
3499
3496
  }
3500
3497
  });
3501
3498
  }); }, {
3499
+ requestId: requestId,
3502
3500
  clientId: clientId,
3503
3501
  agentName: agentName,
3504
3502
  swarmName: "",
@@ -3515,12 +3513,13 @@ var HistoryPublicService = /** @class */ (function () {
3515
3513
  * @param {AgentName} agentName - The agent name.
3516
3514
  * @returns {Promise<any[]>} A promise that resolves to a raw array of history items.
3517
3515
  */
3518
- this.toArrayForRaw = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3516
+ this.toArrayForRaw = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3519
3517
  var _this = this;
3520
3518
  return __generator(this, function (_a) {
3521
3519
  switch (_a.label) {
3522
3520
  case 0:
3523
3521
  this.loggerService.log("historyPublicService toArrayForRaw", {
3522
+ requestId: requestId,
3524
3523
  clientId: clientId,
3525
3524
  agentName: agentName,
3526
3525
  });
@@ -3532,6 +3531,7 @@ var HistoryPublicService = /** @class */ (function () {
3532
3531
  }
3533
3532
  });
3534
3533
  }); }, {
3534
+ requestId: requestId,
3535
3535
  clientId: clientId,
3536
3536
  agentName: agentName,
3537
3537
  swarmName: "",
@@ -3548,7 +3548,7 @@ var HistoryPublicService = /** @class */ (function () {
3548
3548
  * @param {AgentName} agentName - The agent name.
3549
3549
  * @returns {Promise<void>} A promise that resolves when the operation is complete.
3550
3550
  */
3551
- this.dispose = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3551
+ this.dispose = function (requestId, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
3552
3552
  var _this = this;
3553
3553
  return __generator(this, function (_a) {
3554
3554
  switch (_a.label) {
@@ -3565,6 +3565,7 @@ var HistoryPublicService = /** @class */ (function () {
3565
3565
  }
3566
3566
  });
3567
3567
  }); }, {
3568
+ requestId: requestId,
3568
3569
  clientId: clientId,
3569
3570
  agentName: agentName,
3570
3571
  swarmName: "",
@@ -3594,7 +3595,7 @@ var SessionPublicService = /** @class */ (function () {
3594
3595
  * @param {SwarmName} swarmName - The swarm name.
3595
3596
  * @returns {Promise<void>}
3596
3597
  */
3597
- this.emit = function (content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3598
+ this.emit = function (content, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3598
3599
  var _this = this;
3599
3600
  return __generator(this, function (_a) {
3600
3601
  switch (_a.label) {
@@ -3602,6 +3603,7 @@ var SessionPublicService = /** @class */ (function () {
3602
3603
  this.loggerService.log("sessionPublicService emit", {
3603
3604
  content: content,
3604
3605
  clientId: clientId,
3606
+ requestId: requestId,
3605
3607
  swarmName: swarmName,
3606
3608
  });
3607
3609
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -3612,6 +3614,7 @@ var SessionPublicService = /** @class */ (function () {
3612
3614
  }
3613
3615
  });
3614
3616
  }); }, {
3617
+ requestId: requestId,
3615
3618
  clientId: clientId,
3616
3619
  swarmName: swarmName,
3617
3620
  agentName: "",
@@ -3629,7 +3632,7 @@ var SessionPublicService = /** @class */ (function () {
3629
3632
  * @param {SwarmName} swarmName - The swarm name.
3630
3633
  * @returns {Promise<void>}
3631
3634
  */
3632
- this.execute = function (content, mode, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3635
+ this.execute = function (content, mode, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3633
3636
  var _this = this;
3634
3637
  return __generator(this, function (_a) {
3635
3638
  switch (_a.label) {
@@ -3648,6 +3651,7 @@ var SessionPublicService = /** @class */ (function () {
3648
3651
  }
3649
3652
  });
3650
3653
  }); }, {
3654
+ requestId: requestId,
3651
3655
  clientId: clientId,
3652
3656
  swarmName: swarmName,
3653
3657
  agentName: "",
@@ -3665,52 +3669,13 @@ var SessionPublicService = /** @class */ (function () {
3665
3669
  * @param {SwarmName} swarmName - The swarm name.
3666
3670
  * @returns {ReceiveMessageFn}
3667
3671
  */
3668
- this.connect = function (connector, clientId, swarmName) {
3672
+ this.connect = function (connector, requestId, clientId, swarmName) {
3669
3673
  _this.loggerService.log("sessionPublicService connect", {
3674
+ requestId: requestId,
3670
3675
  clientId: clientId,
3671
3676
  swarmName: swarmName,
3672
3677
  });
3673
- return ContextService.runInContext(function () {
3674
- var receive = _this.sessionConnectionService.connect(function (outgoing) { return __awaiter(_this, void 0, void 0, function () {
3675
- var _this = this;
3676
- return __generator(this, function (_a) {
3677
- switch (_a.label) {
3678
- case 0: return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
3679
- return __generator(this, function (_a) {
3680
- switch (_a.label) {
3681
- case 0: return [4 /*yield*/, connector(outgoing)];
3682
- case 1: return [2 /*return*/, _a.sent()];
3683
- }
3684
- });
3685
- }); }, {
3686
- clientId: clientId,
3687
- swarmName: swarmName,
3688
- agentName: "",
3689
- storageName: "",
3690
- stateName: "",
3691
- })];
3692
- case 1: return [2 /*return*/, _a.sent()];
3693
- }
3694
- });
3695
- }); });
3696
- return function (incoming) {
3697
- return ContextService.runInContext(function () {
3698
- return receive(incoming);
3699
- }, {
3700
- clientId: clientId,
3701
- swarmName: swarmName,
3702
- agentName: "",
3703
- storageName: "",
3704
- stateName: "",
3705
- });
3706
- };
3707
- }, {
3708
- clientId: clientId,
3709
- swarmName: swarmName,
3710
- agentName: "",
3711
- storageName: "",
3712
- stateName: "",
3713
- });
3678
+ return _this.sessionConnectionService.connect(connector, clientId, swarmName);
3714
3679
  };
3715
3680
  /**
3716
3681
  * Commits tool output to the session.
@@ -3720,12 +3685,13 @@ var SessionPublicService = /** @class */ (function () {
3720
3685
  * @param {SwarmName} swarmName - The swarm name.
3721
3686
  * @returns {Promise<void>}
3722
3687
  */
3723
- this.commitToolOutput = function (toolId, content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3688
+ this.commitToolOutput = function (toolId, content, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3724
3689
  var _this = this;
3725
3690
  return __generator(this, function (_a) {
3726
3691
  switch (_a.label) {
3727
3692
  case 0:
3728
3693
  this.loggerService.log("sessionPublicService commitToolOutput", {
3694
+ requestId: requestId,
3729
3695
  toolId: toolId,
3730
3696
  content: content,
3731
3697
  clientId: clientId,
@@ -3739,6 +3705,7 @@ var SessionPublicService = /** @class */ (function () {
3739
3705
  }
3740
3706
  });
3741
3707
  }); }, {
3708
+ requestId: requestId,
3742
3709
  clientId: clientId,
3743
3710
  swarmName: swarmName,
3744
3711
  agentName: "",
@@ -3756,12 +3723,13 @@ var SessionPublicService = /** @class */ (function () {
3756
3723
  * @param {SwarmName} swarmName - The swarm name.
3757
3724
  * @returns {Promise<void>}
3758
3725
  */
3759
- this.commitSystemMessage = function (message, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3726
+ this.commitSystemMessage = function (message, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3760
3727
  var _this = this;
3761
3728
  return __generator(this, function (_a) {
3762
3729
  switch (_a.label) {
3763
3730
  case 0:
3764
3731
  this.loggerService.log("sessionPublicService commitSystemMessage", {
3732
+ requestId: requestId,
3765
3733
  message: message,
3766
3734
  clientId: clientId,
3767
3735
  swarmName: swarmName,
@@ -3774,6 +3742,7 @@ var SessionPublicService = /** @class */ (function () {
3774
3742
  }
3775
3743
  });
3776
3744
  }); }, {
3745
+ requestId: requestId,
3777
3746
  clientId: clientId,
3778
3747
  swarmName: swarmName,
3779
3748
  agentName: "",
@@ -3791,12 +3760,13 @@ var SessionPublicService = /** @class */ (function () {
3791
3760
  * @param {SwarmName} swarmName - The swarm name.
3792
3761
  * @returns {Promise<void>}
3793
3762
  */
3794
- this.commitUserMessage = function (message, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3763
+ this.commitUserMessage = function (message, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3795
3764
  var _this = this;
3796
3765
  return __generator(this, function (_a) {
3797
3766
  switch (_a.label) {
3798
3767
  case 0:
3799
3768
  this.loggerService.log("sessionPublicService commitUserMessage", {
3769
+ requestId: requestId,
3800
3770
  message: message,
3801
3771
  clientId: clientId,
3802
3772
  swarmName: swarmName,
@@ -3809,6 +3779,7 @@ var SessionPublicService = /** @class */ (function () {
3809
3779
  }
3810
3780
  });
3811
3781
  }); }, {
3782
+ requestId: requestId,
3812
3783
  clientId: clientId,
3813
3784
  swarmName: swarmName,
3814
3785
  agentName: "",
@@ -3825,7 +3796,7 @@ var SessionPublicService = /** @class */ (function () {
3825
3796
  * @param {SwarmName} swarmName - The swarm name.
3826
3797
  * @returns {Promise<void>}
3827
3798
  */
3828
- this.commitFlush = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3799
+ this.commitFlush = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3829
3800
  var _this = this;
3830
3801
  return __generator(this, function (_a) {
3831
3802
  switch (_a.label) {
@@ -3842,6 +3813,7 @@ var SessionPublicService = /** @class */ (function () {
3842
3813
  }
3843
3814
  });
3844
3815
  }); }, {
3816
+ requestId: requestId,
3845
3817
  clientId: clientId,
3846
3818
  swarmName: swarmName,
3847
3819
  agentName: "",
@@ -3858,12 +3830,13 @@ var SessionPublicService = /** @class */ (function () {
3858
3830
  * @param {SwarmName} swarmName - The swarm name.
3859
3831
  * @returns {Promise<void>}
3860
3832
  */
3861
- this.dispose = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3833
+ this.dispose = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3862
3834
  var _this = this;
3863
3835
  return __generator(this, function (_a) {
3864
3836
  switch (_a.label) {
3865
3837
  case 0:
3866
3838
  this.loggerService.log("sessionPublicService dispose", {
3839
+ requestId: requestId,
3867
3840
  clientId: clientId,
3868
3841
  swarmName: swarmName,
3869
3842
  });
@@ -3875,6 +3848,7 @@ var SessionPublicService = /** @class */ (function () {
3875
3848
  }
3876
3849
  });
3877
3850
  }); }, {
3851
+ requestId: requestId,
3878
3852
  clientId: clientId,
3879
3853
  swarmName: swarmName,
3880
3854
  agentName: "",
@@ -3903,7 +3877,7 @@ var SwarmPublicService = /** @class */ (function () {
3903
3877
  * @param {SwarmName} swarmName - The swarm name.
3904
3878
  * @returns {Promise<void>}
3905
3879
  */
3906
- this.cancelOutput = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3880
+ this.cancelOutput = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3907
3881
  var _this = this;
3908
3882
  return __generator(this, function (_a) {
3909
3883
  switch (_a.label) {
@@ -3920,6 +3894,7 @@ var SwarmPublicService = /** @class */ (function () {
3920
3894
  }
3921
3895
  });
3922
3896
  }); }, {
3897
+ requestId: requestId,
3923
3898
  clientId: clientId,
3924
3899
  swarmName: swarmName,
3925
3900
  agentName: "",
@@ -3936,13 +3911,14 @@ var SwarmPublicService = /** @class */ (function () {
3936
3911
  * @param {SwarmName} swarmName - The swarm name.
3937
3912
  * @returns {Promise<void>}
3938
3913
  */
3939
- this.waitForOutput = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3914
+ this.waitForOutput = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3940
3915
  var _this = this;
3941
3916
  return __generator(this, function (_a) {
3942
3917
  switch (_a.label) {
3943
3918
  case 0:
3944
3919
  this.loggerService.log("swarmPublicService waitForOutput", {
3945
3920
  clientId: clientId,
3921
+ requestId: requestId,
3946
3922
  swarmName: swarmName,
3947
3923
  });
3948
3924
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -3953,6 +3929,7 @@ var SwarmPublicService = /** @class */ (function () {
3953
3929
  }
3954
3930
  });
3955
3931
  }); }, {
3932
+ requestId: requestId,
3956
3933
  clientId: clientId,
3957
3934
  swarmName: swarmName,
3958
3935
  agentName: "",
@@ -3969,7 +3946,7 @@ var SwarmPublicService = /** @class */ (function () {
3969
3946
  * @param {SwarmName} swarmName - The swarm name.
3970
3947
  * @returns {Promise<string>}
3971
3948
  */
3972
- this.getAgentName = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3949
+ this.getAgentName = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3973
3950
  var _this = this;
3974
3951
  return __generator(this, function (_a) {
3975
3952
  switch (_a.label) {
@@ -3977,6 +3954,7 @@ var SwarmPublicService = /** @class */ (function () {
3977
3954
  this.loggerService.log("swarmPublicService getAgentName", {
3978
3955
  clientId: clientId,
3979
3956
  swarmName: swarmName,
3957
+ requestId: requestId,
3980
3958
  });
3981
3959
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
3982
3960
  return __generator(this, function (_a) {
@@ -3986,6 +3964,7 @@ var SwarmPublicService = /** @class */ (function () {
3986
3964
  }
3987
3965
  });
3988
3966
  }); }, {
3967
+ requestId: requestId,
3989
3968
  clientId: clientId,
3990
3969
  swarmName: swarmName,
3991
3970
  agentName: "",
@@ -4002,7 +3981,7 @@ var SwarmPublicService = /** @class */ (function () {
4002
3981
  * @param {SwarmName} swarmName - The swarm name.
4003
3982
  * @returns {Promise<IAgent>}
4004
3983
  */
4005
- this.getAgent = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
3984
+ this.getAgent = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4006
3985
  var _this = this;
4007
3986
  return __generator(this, function (_a) {
4008
3987
  switch (_a.label) {
@@ -4019,6 +3998,7 @@ var SwarmPublicService = /** @class */ (function () {
4019
3998
  }
4020
3999
  });
4021
4000
  }); }, {
4001
+ requestId: requestId,
4022
4002
  clientId: clientId,
4023
4003
  swarmName: swarmName,
4024
4004
  agentName: "",
@@ -4037,12 +4017,13 @@ var SwarmPublicService = /** @class */ (function () {
4037
4017
  * @param {IAgent} agent - The agent instance.
4038
4018
  * @returns {Promise<void>}
4039
4019
  */
4040
- this.setAgentRef = function (clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
4020
+ this.setAgentRef = function (requestId, clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
4041
4021
  var _this = this;
4042
4022
  return __generator(this, function (_a) {
4043
4023
  switch (_a.label) {
4044
4024
  case 0:
4045
4025
  this.loggerService.log("swarmPublicService setAgentRef", {
4026
+ requestId: requestId,
4046
4027
  agentName: agentName,
4047
4028
  agent: agent,
4048
4029
  clientId: clientId,
@@ -4056,6 +4037,7 @@ var SwarmPublicService = /** @class */ (function () {
4056
4037
  }
4057
4038
  });
4058
4039
  }); }, {
4040
+ requestId: requestId,
4059
4041
  clientId: clientId,
4060
4042
  swarmName: swarmName,
4061
4043
  agentName: "",
@@ -4073,12 +4055,13 @@ var SwarmPublicService = /** @class */ (function () {
4073
4055
  * @param {SwarmName} swarmName - The swarm name.
4074
4056
  * @returns {Promise<void>}
4075
4057
  */
4076
- this.setAgentName = function (agentName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4058
+ this.setAgentName = function (agentName, requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4077
4059
  var _this = this;
4078
4060
  return __generator(this, function (_a) {
4079
4061
  switch (_a.label) {
4080
4062
  case 0:
4081
4063
  this.loggerService.log("swarmPublicService setAgentName", {
4064
+ requestId: requestId,
4082
4065
  agentName: agentName,
4083
4066
  clientId: clientId,
4084
4067
  swarmName: swarmName,
@@ -4091,6 +4074,7 @@ var SwarmPublicService = /** @class */ (function () {
4091
4074
  }
4092
4075
  });
4093
4076
  }); }, {
4077
+ requestId: requestId,
4094
4078
  clientId: clientId,
4095
4079
  swarmName: swarmName,
4096
4080
  agentName: "",
@@ -4107,12 +4091,13 @@ var SwarmPublicService = /** @class */ (function () {
4107
4091
  * @param {SwarmName} swarmName - The swarm name.
4108
4092
  * @returns {Promise<void>}
4109
4093
  */
4110
- this.dispose = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4094
+ this.dispose = function (requestId, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4111
4095
  var _this = this;
4112
4096
  return __generator(this, function (_a) {
4113
4097
  switch (_a.label) {
4114
4098
  case 0:
4115
4099
  this.loggerService.log("swarmPublicService dispose", {
4100
+ requestId: requestId,
4116
4101
  clientId: clientId,
4117
4102
  swarmName: swarmName,
4118
4103
  });
@@ -4124,6 +4109,7 @@ var SwarmPublicService = /** @class */ (function () {
4124
4109
  }
4125
4110
  });
4126
4111
  }); }, {
4112
+ requestId: requestId,
4127
4113
  clientId: clientId,
4128
4114
  swarmName: swarmName,
4129
4115
  agentName: "",
@@ -5216,7 +5202,6 @@ var StorageConnectionService = /** @class */ (function () {
5216
5202
  switch (_a.label) {
5217
5203
  case 0:
5218
5204
  this.loggerService.log("storageConnectionService take", {
5219
- context: this.contextService.context,
5220
5205
  search: search,
5221
5206
  total: total,
5222
5207
  score: score,
@@ -5241,7 +5226,6 @@ var StorageConnectionService = /** @class */ (function () {
5241
5226
  switch (_a.label) {
5242
5227
  case 0:
5243
5228
  this.loggerService.log("storageConnectionService upsert", {
5244
- context: this.contextService.context,
5245
5229
  item: item,
5246
5230
  });
5247
5231
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
@@ -5264,7 +5248,6 @@ var StorageConnectionService = /** @class */ (function () {
5264
5248
  switch (_a.label) {
5265
5249
  case 0:
5266
5250
  this.loggerService.log("storageConnectionService remove", {
5267
- context: this.contextService.context,
5268
5251
  itemId: itemId,
5269
5252
  });
5270
5253
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
@@ -5287,7 +5270,6 @@ var StorageConnectionService = /** @class */ (function () {
5287
5270
  switch (_a.label) {
5288
5271
  case 0:
5289
5272
  this.loggerService.log("storageConnectionService get", {
5290
- context: this.contextService.context,
5291
5273
  itemId: itemId,
5292
5274
  });
5293
5275
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
@@ -5309,9 +5291,7 @@ var StorageConnectionService = /** @class */ (function () {
5309
5291
  return __generator(this, function (_a) {
5310
5292
  switch (_a.label) {
5311
5293
  case 0:
5312
- this.loggerService.log("storageConnectionService list", {
5313
- context: this.contextService.context,
5314
- });
5294
+ this.loggerService.log("storageConnectionService list");
5315
5295
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
5316
5296
  return [4 /*yield*/, storage.waitForInit()];
5317
5297
  case 1:
@@ -5330,9 +5310,7 @@ var StorageConnectionService = /** @class */ (function () {
5330
5310
  return __generator(this, function (_a) {
5331
5311
  switch (_a.label) {
5332
5312
  case 0:
5333
- this.loggerService.log("storageConnectionService clear", {
5334
- context: this.contextService.context,
5335
- });
5313
+ this.loggerService.log("storageConnectionService clear");
5336
5314
  storage = this.getStorage(this.contextService.context.clientId, this.contextService.context.storageName);
5337
5315
  return [4 /*yield*/, storage.waitForInit()];
5338
5316
  case 1:
@@ -5351,9 +5329,7 @@ var StorageConnectionService = /** @class */ (function () {
5351
5329
  return __generator(this, function (_a) {
5352
5330
  switch (_a.label) {
5353
5331
  case 0:
5354
- this.loggerService.log("storageConnectionService dispose", {
5355
- context: this.contextService.context,
5356
- });
5332
+ this.loggerService.log("storageConnectionService dispose");
5357
5333
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.storageName);
5358
5334
  if (!this.getStorage.has(key)) {
5359
5335
  return [2 /*return*/];
@@ -5392,12 +5368,13 @@ var StoragePublicService = /** @class */ (function () {
5392
5368
  * @param {number} total - The total number of items to retrieve.
5393
5369
  * @returns {Promise<IStorageData[]>} The list of storage data.
5394
5370
  */
5395
- this.take = function (search, total, clientId, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
5371
+ this.take = function (search, total, requestId, clientId, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
5396
5372
  var _this = this;
5397
5373
  return __generator(this, function (_a) {
5398
5374
  switch (_a.label) {
5399
5375
  case 0:
5400
5376
  this.loggerService.log("storagePublicService take", {
5377
+ requestId: requestId,
5401
5378
  search: search,
5402
5379
  total: total,
5403
5380
  clientId: clientId,
@@ -5412,6 +5389,7 @@ var StoragePublicService = /** @class */ (function () {
5412
5389
  }
5413
5390
  });
5414
5391
  }); }, {
5392
+ requestId: requestId,
5415
5393
  clientId: clientId,
5416
5394
  storageName: storageName,
5417
5395
  agentName: "",
@@ -5427,7 +5405,7 @@ var StoragePublicService = /** @class */ (function () {
5427
5405
  * @param {IStorageData} item - The item to upsert.
5428
5406
  * @returns {Promise<void>}
5429
5407
  */
5430
- this.upsert = function (item, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5408
+ this.upsert = function (item, requestId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5431
5409
  var _this = this;
5432
5410
  return __generator(this, function (_a) {
5433
5411
  switch (_a.label) {
@@ -5445,6 +5423,7 @@ var StoragePublicService = /** @class */ (function () {
5445
5423
  }
5446
5424
  });
5447
5425
  }); }, {
5426
+ requestId: requestId,
5448
5427
  clientId: clientId,
5449
5428
  storageName: storageName,
5450
5429
  agentName: "",
@@ -5460,7 +5439,7 @@ var StoragePublicService = /** @class */ (function () {
5460
5439
  * @param {IStorageData["id"]} itemId - The ID of the item to remove.
5461
5440
  * @returns {Promise<void>}
5462
5441
  */
5463
- this.remove = function (itemId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5442
+ this.remove = function (itemId, requestId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5464
5443
  var _this = this;
5465
5444
  return __generator(this, function (_a) {
5466
5445
  switch (_a.label) {
@@ -5478,6 +5457,7 @@ var StoragePublicService = /** @class */ (function () {
5478
5457
  }
5479
5458
  });
5480
5459
  }); }, {
5460
+ requestId: requestId,
5481
5461
  clientId: clientId,
5482
5462
  storageName: storageName,
5483
5463
  agentName: "",
@@ -5493,12 +5473,13 @@ var StoragePublicService = /** @class */ (function () {
5493
5473
  * @param {IStorageData["id"]} itemId - The ID of the item to retrieve.
5494
5474
  * @returns {Promise<IStorageData>} The retrieved item.
5495
5475
  */
5496
- this.get = function (itemId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5476
+ this.get = function (itemId, requestId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5497
5477
  var _this = this;
5498
5478
  return __generator(this, function (_a) {
5499
5479
  switch (_a.label) {
5500
5480
  case 0:
5501
5481
  this.loggerService.log("storagePublicService get", {
5482
+ requestId: requestId,
5502
5483
  itemId: itemId,
5503
5484
  clientId: clientId,
5504
5485
  storageName: storageName,
@@ -5511,6 +5492,7 @@ var StoragePublicService = /** @class */ (function () {
5511
5492
  }
5512
5493
  });
5513
5494
  }); }, {
5495
+ requestId: requestId,
5514
5496
  clientId: clientId,
5515
5497
  storageName: storageName,
5516
5498
  agentName: "",
@@ -5526,12 +5508,13 @@ var StoragePublicService = /** @class */ (function () {
5526
5508
  * @param {function(IStorageData): boolean} [filter] - The optional filter function.
5527
5509
  * @returns {Promise<IStorageData[]>} The list of items.
5528
5510
  */
5529
- this.list = function (clientId, storageName, filter) { return __awaiter(_this, void 0, void 0, function () {
5511
+ this.list = function (requestId, clientId, storageName, filter) { return __awaiter(_this, void 0, void 0, function () {
5530
5512
  var _this = this;
5531
5513
  return __generator(this, function (_a) {
5532
5514
  switch (_a.label) {
5533
5515
  case 0:
5534
5516
  this.loggerService.log("storagePublicService list", {
5517
+ requestId: requestId,
5535
5518
  clientId: clientId,
5536
5519
  storageName: storageName,
5537
5520
  });
@@ -5543,6 +5526,7 @@ var StoragePublicService = /** @class */ (function () {
5543
5526
  }
5544
5527
  });
5545
5528
  }); }, {
5529
+ requestId: requestId,
5546
5530
  clientId: clientId,
5547
5531
  storageName: storageName,
5548
5532
  agentName: "",
@@ -5557,12 +5541,13 @@ var StoragePublicService = /** @class */ (function () {
5557
5541
  * Clears all items from the storage.
5558
5542
  * @returns {Promise<void>}
5559
5543
  */
5560
- this.clear = function (clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5544
+ this.clear = function (requestId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5561
5545
  var _this = this;
5562
5546
  return __generator(this, function (_a) {
5563
5547
  switch (_a.label) {
5564
5548
  case 0:
5565
5549
  this.loggerService.log("storagePublicService clear", {
5550
+ requestId: requestId,
5566
5551
  clientId: clientId,
5567
5552
  storageName: storageName,
5568
5553
  });
@@ -5574,6 +5559,7 @@ var StoragePublicService = /** @class */ (function () {
5574
5559
  }
5575
5560
  });
5576
5561
  }); }, {
5562
+ requestId: requestId,
5577
5563
  clientId: clientId,
5578
5564
  storageName: storageName,
5579
5565
  agentName: "",
@@ -5590,7 +5576,7 @@ var StoragePublicService = /** @class */ (function () {
5590
5576
  * @param {StorageName} storageName - The storage name.
5591
5577
  * @returns {Promise<void>}
5592
5578
  */
5593
- this.dispose = function (clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5579
+ this.dispose = function (requestId, clientId, storageName) { return __awaiter(_this, void 0, void 0, function () {
5594
5580
  var _this = this;
5595
5581
  return __generator(this, function (_a) {
5596
5582
  switch (_a.label) {
@@ -5607,6 +5593,7 @@ var StoragePublicService = /** @class */ (function () {
5607
5593
  }
5608
5594
  });
5609
5595
  }); }, {
5596
+ requestId: requestId,
5610
5597
  clientId: clientId,
5611
5598
  storageName: storageName,
5612
5599
  agentName: "",
@@ -6035,9 +6022,7 @@ var StateConnectionService = /** @class */ (function () {
6035
6022
  return __generator(this, function (_a) {
6036
6023
  switch (_a.label) {
6037
6024
  case 0:
6038
- this.loggerService.log("stateConnectionService setState", {
6039
- context: this.contextService.context,
6040
- });
6025
+ this.loggerService.log("stateConnectionService setState");
6041
6026
  state = this.getStateRef(this.contextService.context.clientId, this.contextService.context.stateName);
6042
6027
  return [4 /*yield*/, state.waitForInit()];
6043
6028
  case 1:
@@ -6056,9 +6041,7 @@ var StateConnectionService = /** @class */ (function () {
6056
6041
  return __generator(this, function (_a) {
6057
6042
  switch (_a.label) {
6058
6043
  case 0:
6059
- this.loggerService.log("stateConnectionService getState", {
6060
- context: this.contextService.context,
6061
- });
6044
+ this.loggerService.log("stateConnectionService getState");
6062
6045
  state = this.getStateRef(this.contextService.context.clientId, this.contextService.context.stateName);
6063
6046
  return [4 /*yield*/, state.waitForInit()];
6064
6047
  case 1:
@@ -6077,9 +6060,7 @@ var StateConnectionService = /** @class */ (function () {
6077
6060
  return __generator(this, function (_a) {
6078
6061
  switch (_a.label) {
6079
6062
  case 0:
6080
- this.loggerService.log("stateConnectionService dispose", {
6081
- context: this.contextService.context,
6082
- });
6063
+ this.loggerService.log("stateConnectionService dispose");
6083
6064
  key = "".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.stateName);
6084
6065
  if (!this.getStateRef.has(key)) {
6085
6066
  return [2 /*return*/];
@@ -6116,12 +6097,13 @@ var StatePublicService = /** @class */ (function () {
6116
6097
  * @param {StateName} stateName - The name of the state.
6117
6098
  * @returns {Promise<T>} - The updated state.
6118
6099
  */
6119
- this.setState = function (dispatchFn, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6100
+ this.setState = function (dispatchFn, requestId, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6120
6101
  var _this = this;
6121
6102
  return __generator(this, function (_a) {
6122
6103
  switch (_a.label) {
6123
6104
  case 0:
6124
6105
  this.loggerService.log("statePublicService setState", {
6106
+ requestId: requestId,
6125
6107
  clientId: clientId,
6126
6108
  stateName: stateName,
6127
6109
  });
@@ -6133,6 +6115,7 @@ var StatePublicService = /** @class */ (function () {
6133
6115
  }
6134
6116
  });
6135
6117
  }); }, {
6118
+ requestId: requestId,
6136
6119
  clientId: clientId,
6137
6120
  stateName: stateName,
6138
6121
  agentName: "",
@@ -6149,7 +6132,7 @@ var StatePublicService = /** @class */ (function () {
6149
6132
  * @param {StateName} stateName - The name of the state.
6150
6133
  * @returns {Promise<T>} - The current state.
6151
6134
  */
6152
- this.getState = function (clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6135
+ this.getState = function (requestId, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6153
6136
  var _this = this;
6154
6137
  return __generator(this, function (_a) {
6155
6138
  switch (_a.label) {
@@ -6166,6 +6149,7 @@ var StatePublicService = /** @class */ (function () {
6166
6149
  }
6167
6150
  });
6168
6151
  }); }, {
6152
+ requestId: requestId,
6169
6153
  clientId: clientId,
6170
6154
  stateName: stateName,
6171
6155
  agentName: "",
@@ -6182,12 +6166,13 @@ var StatePublicService = /** @class */ (function () {
6182
6166
  * @param {StateName} stateName - The name of the state.
6183
6167
  * @returns {Promise<void>} - A promise that resolves when the state is disposed.
6184
6168
  */
6185
- this.dispose = function (clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6169
+ this.dispose = function (requestId, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
6186
6170
  var _this = this;
6187
6171
  return __generator(this, function (_a) {
6188
6172
  switch (_a.label) {
6189
6173
  case 0:
6190
6174
  this.loggerService.log("statePublicService dispose", {
6175
+ requestId: requestId,
6191
6176
  clientId: clientId,
6192
6177
  stateName: stateName,
6193
6178
  });
@@ -6199,6 +6184,7 @@ var StatePublicService = /** @class */ (function () {
6199
6184
  }
6200
6185
  });
6201
6186
  }); }, {
6187
+ requestId: requestId,
6202
6188
  clientId: clientId,
6203
6189
  stateName: stateName,
6204
6190
  agentName: "",
@@ -6239,7 +6225,7 @@ var BusService = /** @class */ (function () {
6239
6225
  _this._eventWildcardMap.set(source, true);
6240
6226
  }
6241
6227
  _this._eventSourceSet.add(source);
6242
- _this.getEventSubject(clientId, source).subscribe(fn);
6228
+ return _this.getEventSubject(clientId, source).subscribe(fn);
6243
6229
  };
6244
6230
  /**
6245
6231
  * Subscribes to a single event for a specific client and source.
@@ -6536,20 +6522,22 @@ var addStorage = function (storageSchema) {
6536
6522
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
6537
6523
  */
6538
6524
  var commitUserMessage = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
6539
- var swarmName, currentAgentName;
6525
+ var requestId, swarmName, currentAgentName;
6540
6526
  return __generator(this, function (_a) {
6541
6527
  switch (_a.label) {
6542
6528
  case 0:
6529
+ requestId = functoolsKit.randomString();
6543
6530
  swarm.loggerService.log('function commitSystemMessage', {
6544
6531
  content: content,
6545
6532
  clientId: clientId,
6546
6533
  agentName: agentName,
6534
+ requestId: requestId,
6547
6535
  });
6548
6536
  swarm.agentValidationService.validate(agentName, "commitUserMessage");
6549
6537
  swarm.sessionValidationService.validate(clientId, "commitUserMessage");
6550
6538
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
6551
6539
  swarm.swarmValidationService.validate(swarmName, "commitUserMessage");
6552
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
6540
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
6553
6541
  case 1:
6554
6542
  currentAgentName = _a.sent();
6555
6543
  if (currentAgentName !== agentName) {
@@ -6560,7 +6548,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
6560
6548
  });
6561
6549
  return [2 /*return*/];
6562
6550
  }
6563
- return [4 /*yield*/, swarm.sessionPublicService.commitUserMessage(content, clientId, swarmName)];
6551
+ return [4 /*yield*/, swarm.sessionPublicService.commitUserMessage(content, requestId, clientId, swarmName)];
6564
6552
  case 2:
6565
6553
  _a.sent();
6566
6554
  return [2 /*return*/];
@@ -6576,17 +6564,19 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
6576
6564
  * @throws Will throw an error if the client ID is invalid or if the swarm validation fails.
6577
6565
  */
6578
6566
  var getAgentName = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
6579
- var swarmName;
6567
+ var requestId, swarmName;
6580
6568
  return __generator(this, function (_a) {
6581
6569
  switch (_a.label) {
6582
6570
  case 0:
6571
+ requestId = functoolsKit.randomString();
6583
6572
  swarm.loggerService.log("function getAgentName", {
6584
6573
  clientId: clientId,
6574
+ requestId: requestId,
6585
6575
  });
6586
6576
  swarm.sessionValidationService.validate(clientId, "getAgentName");
6587
6577
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
6588
6578
  swarm.swarmValidationService.validate(swarmName, "getAgentName");
6589
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
6579
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
6590
6580
  case 1: return [2 /*return*/, _a.sent()];
6591
6581
  }
6592
6582
  });
@@ -6602,13 +6592,15 @@ var SCHEDULED_DELAY$1 = 1000;
6602
6592
  * @returns {SendMessageFn} - A function to send messages to the swarm.
6603
6593
  */
6604
6594
  var makeConnection = function (connector, clientId, swarmName) {
6595
+ var requestId = functoolsKit.randomString();
6605
6596
  swarm.loggerService.log("function makeConnection", {
6606
6597
  clientId: clientId,
6607
6598
  swarmName: swarmName,
6599
+ requestId: requestId,
6608
6600
  });
6609
6601
  swarm.swarmValidationService.validate(swarmName, "makeConnection");
6610
6602
  swarm.sessionValidationService.addSession(clientId, swarmName, "makeConnection");
6611
- var send = swarm.sessionPublicService.connect(connector, clientId, swarmName);
6603
+ var send = swarm.sessionPublicService.connect(connector, requestId, clientId, swarmName);
6612
6604
  return functoolsKit.queued(function (outgoing) { return __awaiter(void 0, void 0, void 0, function () {
6613
6605
  var _a;
6614
6606
  var _b;
@@ -6620,7 +6612,7 @@ var makeConnection = function (connector, clientId, swarmName) {
6620
6612
  _b = {
6621
6613
  data: outgoing
6622
6614
  };
6623
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
6615
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
6624
6616
  case 1: return [4 /*yield*/, _a.apply(void 0, [(_b.agentName = _c.sent(),
6625
6617
  _b.clientId = clientId,
6626
6618
  _b)])];
@@ -6723,7 +6715,7 @@ var CHANGE_AGENT_GC = 60 * 1000;
6723
6715
  * @returns {TChangeAgentRun} - The change agent function.
6724
6716
  */
6725
6717
  var createChangeAgent = functoolsKit.ttl(function (clientId) {
6726
- return functoolsKit.queued(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
6718
+ return functoolsKit.queued(function (requestId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
6727
6719
  var swarmName, _a, _b, _c;
6728
6720
  return __generator(this, function (_d) {
6729
6721
  switch (_d.label) {
@@ -6736,7 +6728,7 @@ var createChangeAgent = functoolsKit.ttl(function (clientId) {
6736
6728
  .map(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
6737
6729
  return __generator(this, function (_a) {
6738
6730
  switch (_a.label) {
6739
- case 0: return [4 /*yield*/, swarm.agentPublicService.commitAgentChange(clientId, agentName)];
6731
+ case 0: return [4 /*yield*/, swarm.agentPublicService.commitAgentChange(requestId, clientId, agentName)];
6740
6732
  case 1:
6741
6733
  _a.sent();
6742
6734
  return [2 /*return*/];
@@ -6745,21 +6737,22 @@ var createChangeAgent = functoolsKit.ttl(function (clientId) {
6745
6737
  }); }))];
6746
6738
  case 1:
6747
6739
  _d.sent();
6748
- return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
6740
+ return [4 /*yield*/, swarm.agentPublicService.dispose(requestId, clientId, agentName)];
6749
6741
  case 2:
6750
6742
  _d.sent();
6751
- return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
6743
+ return [4 /*yield*/, swarm.historyPublicService.dispose(requestId, clientId, agentName)];
6752
6744
  case 3:
6753
6745
  _d.sent();
6754
6746
  _b = (_a = swarm.swarmPublicService).setAgentRef;
6755
- _c = [clientId,
6747
+ _c = [requestId,
6748
+ clientId,
6756
6749
  swarmName,
6757
6750
  agentName];
6758
- return [4 /*yield*/, swarm.agentPublicService.createAgentRef(clientId, agentName)];
6751
+ return [4 /*yield*/, swarm.agentPublicService.createAgentRef(requestId, clientId, agentName)];
6759
6752
  case 4: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
6760
6753
  case 5:
6761
6754
  _d.sent();
6762
- return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
6755
+ return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, requestId, clientId, swarmName)];
6763
6756
  case 6:
6764
6757
  _d.sent();
6765
6758
  return [2 /*return*/];
@@ -6793,10 +6786,11 @@ var createGc$1 = functoolsKit.singleshot(function () { return __awaiter(void 0,
6793
6786
  * @returns {Promise<void>} - A promise that resolves when the agent is changed.
6794
6787
  */
6795
6788
  var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
6796
- var run;
6789
+ var requestId, run;
6797
6790
  return __generator(this, function (_a) {
6798
6791
  switch (_a.label) {
6799
6792
  case 0:
6793
+ requestId = functoolsKit.randomString();
6800
6794
  swarm.loggerService.log("function changeAgent", {
6801
6795
  agentName: agentName,
6802
6796
  clientId: clientId,
@@ -6805,7 +6799,7 @@ var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void
6805
6799
  case 1:
6806
6800
  run = _a.sent();
6807
6801
  createGc$1();
6808
- return [4 /*yield*/, run(agentName)];
6802
+ return [4 /*yield*/, run(requestId, agentName)];
6809
6803
  case 2: return [2 /*return*/, _a.sent()];
6810
6804
  }
6811
6805
  });
@@ -6818,83 +6812,91 @@ var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void
6818
6812
  * @param {SwarmName} swarmName - The name of the swarm.
6819
6813
  * @returns {Promise<void>} A promise that resolves when the connection is disposed.
6820
6814
  */
6821
- var disposeConnection = function (clientId, swarmName) { return __awaiter(void 0, void 0, void 0, function () {
6822
- return __generator(this, function (_a) {
6823
- switch (_a.label) {
6824
- case 0:
6825
- swarm.loggerService.log("function disposeConnection", {
6826
- clientId: clientId,
6827
- swarmName: swarmName,
6828
- });
6829
- swarm.swarmValidationService.validate(swarmName, "disposeConnection");
6830
- swarm.sessionValidationService.removeSession(clientId);
6831
- swarm.busService.dispose(clientId);
6832
- return [4 /*yield*/, swarm.sessionPublicService.dispose(clientId, swarmName)];
6833
- case 1:
6834
- _a.sent();
6835
- return [4 /*yield*/, swarm.swarmPublicService.dispose(clientId, swarmName)];
6836
- case 2:
6837
- _a.sent();
6838
- return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6839
- .getAgentList(swarmName)
6840
- .map(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
6841
- return __generator(this, function (_a) {
6842
- switch (_a.label) {
6843
- case 0: return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
6844
- case 1:
6845
- _a.sent();
6846
- return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
6847
- case 2:
6848
- _a.sent();
6849
- return [2 /*return*/];
6850
- }
6851
- });
6852
- }); }))];
6853
- case 3:
6854
- _a.sent();
6855
- return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6856
- .getAgentList(swarmName)
6857
- .flatMap(function (agentName) {
6858
- return swarm.agentValidationService.getStorageList(agentName);
6859
- })
6860
- .filter(function (storageName) { return !!storageName; })
6861
- .map(function (storageName) { return __awaiter(void 0, void 0, void 0, function () {
6862
- return __generator(this, function (_a) {
6863
- switch (_a.label) {
6864
- case 0: return [4 /*yield*/, swarm.storagePublicService.dispose(clientId, storageName)];
6865
- case 1:
6866
- _a.sent();
6867
- return [2 /*return*/];
6868
- }
6869
- });
6870
- }); }))];
6871
- case 4:
6872
- _a.sent();
6873
- return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6874
- .getAgentList(swarmName)
6875
- .flatMap(function (agentName) {
6876
- return swarm.agentValidationService.getStateList(agentName);
6877
- })
6878
- .filter(function (stateName) { return !!stateName; })
6879
- .map(function (stateName) { return __awaiter(void 0, void 0, void 0, function () {
6880
- return __generator(this, function (_a) {
6881
- switch (_a.label) {
6882
- case 0: return [4 /*yield*/, swarm.statePublicService.dispose(clientId, stateName)];
6883
- case 1:
6884
- _a.sent();
6885
- return [2 /*return*/];
6886
- }
6887
- });
6888
- }); }))];
6889
- case 5:
6890
- _a.sent();
6891
- return [4 /*yield*/, HistoryAdapter.dispose(clientId, null)];
6892
- case 6:
6893
- _a.sent();
6894
- return [2 /*return*/];
6895
- }
6815
+ var disposeConnection = function (clientId_1, swarmName_1) {
6816
+ var args_1 = [];
6817
+ for (var _i = 2; _i < arguments.length; _i++) {
6818
+ args_1[_i - 2] = arguments[_i];
6819
+ }
6820
+ return __awaiter(void 0, __spreadArray([clientId_1, swarmName_1], __read(args_1), false), void 0, function (clientId, swarmName, requestId) {
6821
+ if (requestId === void 0) { requestId = functoolsKit.randomString(); }
6822
+ return __generator(this, function (_a) {
6823
+ switch (_a.label) {
6824
+ case 0:
6825
+ swarm.loggerService.log("function disposeConnection", {
6826
+ clientId: clientId,
6827
+ swarmName: swarmName,
6828
+ requestId: requestId,
6829
+ });
6830
+ swarm.swarmValidationService.validate(swarmName, "disposeConnection");
6831
+ swarm.sessionValidationService.removeSession(clientId);
6832
+ swarm.busService.dispose(clientId);
6833
+ return [4 /*yield*/, swarm.sessionPublicService.dispose(requestId, clientId, swarmName)];
6834
+ case 1:
6835
+ _a.sent();
6836
+ return [4 /*yield*/, swarm.swarmPublicService.dispose(requestId, clientId, swarmName)];
6837
+ case 2:
6838
+ _a.sent();
6839
+ return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6840
+ .getAgentList(swarmName)
6841
+ .map(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
6842
+ return __generator(this, function (_a) {
6843
+ switch (_a.label) {
6844
+ case 0: return [4 /*yield*/, swarm.agentPublicService.dispose(requestId, clientId, agentName)];
6845
+ case 1:
6846
+ _a.sent();
6847
+ return [4 /*yield*/, swarm.historyPublicService.dispose(requestId, clientId, agentName)];
6848
+ case 2:
6849
+ _a.sent();
6850
+ return [2 /*return*/];
6851
+ }
6852
+ });
6853
+ }); }))];
6854
+ case 3:
6855
+ _a.sent();
6856
+ return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6857
+ .getAgentList(swarmName)
6858
+ .flatMap(function (agentName) {
6859
+ return swarm.agentValidationService.getStorageList(agentName);
6860
+ })
6861
+ .filter(function (storageName) { return !!storageName; })
6862
+ .map(function (storageName) { return __awaiter(void 0, void 0, void 0, function () {
6863
+ return __generator(this, function (_a) {
6864
+ switch (_a.label) {
6865
+ case 0: return [4 /*yield*/, swarm.storagePublicService.dispose(requestId, clientId, storageName)];
6866
+ case 1:
6867
+ _a.sent();
6868
+ return [2 /*return*/];
6869
+ }
6870
+ });
6871
+ }); }))];
6872
+ case 4:
6873
+ _a.sent();
6874
+ return [4 /*yield*/, Promise.all(swarm.swarmValidationService
6875
+ .getAgentList(swarmName)
6876
+ .flatMap(function (agentName) {
6877
+ return swarm.agentValidationService.getStateList(agentName);
6878
+ })
6879
+ .filter(function (stateName) { return !!stateName; })
6880
+ .map(function (stateName) { return __awaiter(void 0, void 0, void 0, function () {
6881
+ return __generator(this, function (_a) {
6882
+ switch (_a.label) {
6883
+ case 0: return [4 /*yield*/, swarm.statePublicService.dispose(requestId, clientId, stateName)];
6884
+ case 1:
6885
+ _a.sent();
6886
+ return [2 /*return*/];
6887
+ }
6888
+ });
6889
+ }); }))];
6890
+ case 5:
6891
+ _a.sent();
6892
+ return [4 /*yield*/, HistoryAdapter.dispose(clientId, null)];
6893
+ case 6:
6894
+ _a.sent();
6895
+ return [2 /*return*/];
6896
+ }
6897
+ });
6896
6898
  });
6897
- }); };
6899
+ };
6898
6900
 
6899
6901
  var COMPLETE_TTL = 15 * 60 * 1000;
6900
6902
  var COMPLETE_GC = 60 * 1000;
@@ -6905,17 +6907,17 @@ var COMPLETE_GC = 60 * 1000;
6905
6907
  * @returns {TCompleteRun} The complete run function.
6906
6908
  */
6907
6909
  var createComplete = functoolsKit.ttl(function (clientId, swarmName) {
6908
- return functoolsKit.queued(function (content) { return __awaiter(void 0, void 0, void 0, function () {
6910
+ return functoolsKit.queued(function (requestId, content) { return __awaiter(void 0, void 0, void 0, function () {
6909
6911
  var result;
6910
6912
  return __generator(this, function (_a) {
6911
6913
  switch (_a.label) {
6912
6914
  case 0:
6913
6915
  swarm.swarmValidationService.validate(swarmName, "complete");
6914
6916
  swarm.sessionValidationService.addSession(clientId, swarmName, "complete");
6915
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
6917
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", requestId, clientId, swarmName)];
6916
6918
  case 1:
6917
6919
  result = _a.sent();
6918
- return [4 /*yield*/, disposeConnection(clientId, swarmName)];
6920
+ return [4 /*yield*/, disposeConnection(clientId, swarmName, requestId)];
6919
6921
  case 2:
6920
6922
  _a.sent();
6921
6923
  return [2 /*return*/, result];
@@ -6949,20 +6951,22 @@ var createGc = functoolsKit.singleshot(function () { return __awaiter(void 0, vo
6949
6951
  * @returns {Promise<string>} The result of the complete function.
6950
6952
  */
6951
6953
  var complete = function (content, clientId, swarmName) { return __awaiter(void 0, void 0, void 0, function () {
6952
- var run;
6954
+ var requestId, run;
6953
6955
  return __generator(this, function (_a) {
6954
6956
  switch (_a.label) {
6955
6957
  case 0:
6958
+ requestId = functoolsKit.randomString();
6956
6959
  swarm.loggerService.log("function complete", {
6957
6960
  content: content,
6958
6961
  clientId: clientId,
6959
6962
  swarmName: swarmName,
6963
+ requestId: requestId,
6960
6964
  });
6961
6965
  return [4 /*yield*/, createComplete(clientId, swarmName)];
6962
6966
  case 1:
6963
6967
  run = _a.sent();
6964
6968
  createGc();
6965
- return [4 /*yield*/, run(content)];
6969
+ return [4 /*yield*/, run(requestId, content)];
6966
6970
  case 2: return [2 /*return*/, _a.sent()];
6967
6971
  }
6968
6972
  });
@@ -6979,9 +6983,11 @@ var SCHEDULED_DELAY = 1000;
6979
6983
  * @returns {Function} dispose - A function to dispose of the session.
6980
6984
  */
6981
6985
  var session = function (clientId, swarmName) {
6986
+ var requestId = functoolsKit.randomString();
6982
6987
  swarm.loggerService.log("function session", {
6983
6988
  clientId: clientId,
6984
6989
  swarmName: swarmName,
6990
+ requestId: requestId,
6985
6991
  });
6986
6992
  swarm.swarmValidationService.validate(swarmName, "session");
6987
6993
  swarm.sessionValidationService.addSession(clientId, swarmName, "session");
@@ -6997,7 +7003,7 @@ var session = function (clientId, swarmName) {
6997
7003
  switch (_a.label) {
6998
7004
  case 0:
6999
7005
  swarm.sessionValidationService.validate(clientId, "session");
7000
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
7006
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", requestId, clientId, swarmName)];
7001
7007
  case 1: return [2 /*return*/, _a.sent()];
7002
7008
  }
7003
7009
  });
@@ -7010,7 +7016,7 @@ var session = function (clientId, swarmName) {
7010
7016
  dispose: function () { return __awaiter(void 0, void 0, void 0, function () {
7011
7017
  return __generator(this, function (_a) {
7012
7018
  switch (_a.label) {
7013
- case 0: return [4 /*yield*/, disposeConnection(clientId, swarmName)];
7019
+ case 0: return [4 /*yield*/, disposeConnection(clientId, swarmName, requestId)];
7014
7020
  case 1: return [2 /*return*/, _a.sent()];
7015
7021
  }
7016
7022
  });
@@ -7115,27 +7121,35 @@ session.scheduled = function (clientId, swarmName, _a) {
7115
7121
  * @param {string} clientId - The ID of the client whose history is to be retrieved.
7116
7122
  * @returns {Promise<Array>} A promise that resolves to an array containing the raw history.
7117
7123
  */
7118
- var getRawHistory = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7119
- var swarmName, agentName, history;
7120
- return __generator(this, function (_a) {
7121
- switch (_a.label) {
7122
- case 0:
7123
- swarm.loggerService.log("function getRawHistory", {
7124
- clientId: clientId,
7125
- });
7126
- swarm.sessionValidationService.validate(clientId, "getRawHistory");
7127
- swarmName = swarm.sessionValidationService.getSwarm(clientId);
7128
- swarm.swarmValidationService.validate(swarmName, "getRawHistory");
7129
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7130
- case 1:
7131
- agentName = _a.sent();
7132
- return [4 /*yield*/, swarm.historyPublicService.toArrayForRaw(clientId, agentName)];
7133
- case 2:
7134
- history = _a.sent();
7135
- return [2 /*return*/, __spreadArray([], __read(history), false)];
7136
- }
7124
+ var getRawHistory = function (clientId_1) {
7125
+ var args_1 = [];
7126
+ for (var _i = 1; _i < arguments.length; _i++) {
7127
+ args_1[_i - 1] = arguments[_i];
7128
+ }
7129
+ return __awaiter(void 0, __spreadArray([clientId_1], __read(args_1), false), void 0, function (clientId, requestId) {
7130
+ var swarmName, agentName, history;
7131
+ if (requestId === void 0) { requestId = functoolsKit.randomString(); }
7132
+ return __generator(this, function (_a) {
7133
+ switch (_a.label) {
7134
+ case 0:
7135
+ swarm.loggerService.log("function getRawHistory", {
7136
+ clientId: clientId,
7137
+ requestId: requestId,
7138
+ });
7139
+ swarm.sessionValidationService.validate(clientId, "getRawHistory");
7140
+ swarmName = swarm.sessionValidationService.getSwarm(clientId);
7141
+ swarm.swarmValidationService.validate(swarmName, "getRawHistory");
7142
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7143
+ case 1:
7144
+ agentName = _a.sent();
7145
+ return [4 /*yield*/, swarm.historyPublicService.toArrayForRaw(requestId, clientId, agentName)];
7146
+ case 2:
7147
+ history = _a.sent();
7148
+ return [2 /*return*/, __spreadArray([], __read(history), false)];
7149
+ }
7150
+ });
7137
7151
  });
7138
- }); };
7152
+ };
7139
7153
 
7140
7154
  /**
7141
7155
  * Retrieves the history prepared for a specific agent with resque algorithm tweaks
@@ -7145,17 +7159,19 @@ var getRawHistory = function (clientId) { return __awaiter(void 0, void 0, void
7145
7159
  * @returns {Promise<Array>} - A promise that resolves to an array containing the agent's history.
7146
7160
  */
7147
7161
  var getAgentHistory = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7148
- var prompt, history;
7162
+ var requestId, prompt, history;
7149
7163
  return __generator(this, function (_a) {
7150
7164
  switch (_a.label) {
7151
7165
  case 0:
7166
+ requestId = functoolsKit.randomString();
7152
7167
  swarm.loggerService.log("function getAgentHistory", {
7153
7168
  clientId: clientId,
7154
7169
  agentName: agentName,
7170
+ requestId: requestId,
7155
7171
  });
7156
7172
  swarm.agentValidationService.validate(agentName, "getAgentHistory");
7157
7173
  prompt = swarm.agentSchemaService.get(agentName).prompt;
7158
- return [4 /*yield*/, swarm.historyPublicService.toArrayForAgent(prompt, clientId, agentName)];
7174
+ return [4 /*yield*/, swarm.historyPublicService.toArrayForAgent(prompt, requestId, clientId, agentName)];
7159
7175
  case 1:
7160
7176
  history = _a.sent();
7161
7177
  return [2 /*return*/, __spreadArray([], __read(history), false)];
@@ -7189,21 +7205,23 @@ var getSessionMode = function (clientId) { return __awaiter(void 0, void 0, void
7189
7205
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
7190
7206
  */
7191
7207
  var commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7192
- var swarmName, currentAgentName;
7208
+ var requestId, swarmName, currentAgentName;
7193
7209
  return __generator(this, function (_a) {
7194
7210
  switch (_a.label) {
7195
7211
  case 0:
7212
+ requestId = functoolsKit.randomString();
7196
7213
  swarm.loggerService.log('function commitToolOutput', {
7197
7214
  toolId: toolId,
7198
7215
  content: content,
7199
7216
  clientId: clientId,
7200
7217
  agentName: agentName,
7218
+ requestId: requestId,
7201
7219
  });
7202
7220
  swarm.agentValidationService.validate(agentName, "commitSystemMessage");
7203
7221
  swarm.sessionValidationService.validate(clientId, "commitToolOutput");
7204
7222
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7205
7223
  swarm.swarmValidationService.validate(swarmName, "commitToolOutput");
7206
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7224
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7207
7225
  case 1:
7208
7226
  currentAgentName = _a.sent();
7209
7227
  if (currentAgentName !== agentName) {
@@ -7215,7 +7233,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
7215
7233
  });
7216
7234
  return [2 /*return*/];
7217
7235
  }
7218
- return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, clientId, swarmName)];
7236
+ return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, requestId, clientId, swarmName)];
7219
7237
  case 2:
7220
7238
  _a.sent();
7221
7239
  return [2 /*return*/];
@@ -7232,20 +7250,22 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
7232
7250
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
7233
7251
  */
7234
7252
  var commitSystemMessage = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7235
- var swarmName, currentAgentName;
7253
+ var requestId, swarmName, currentAgentName;
7236
7254
  return __generator(this, function (_a) {
7237
7255
  switch (_a.label) {
7238
7256
  case 0:
7257
+ requestId = functoolsKit.randomString();
7239
7258
  swarm.loggerService.log('function commitSystemMessage', {
7240
7259
  content: content,
7241
7260
  clientId: clientId,
7242
7261
  agentName: agentName,
7262
+ requestId: requestId,
7243
7263
  });
7244
7264
  swarm.agentValidationService.validate(agentName, "commitSystemMessage");
7245
7265
  swarm.sessionValidationService.validate(clientId, "commitSystemMessage");
7246
7266
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7247
7267
  swarm.swarmValidationService.validate(swarmName, "commitSystemMessage");
7248
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7268
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7249
7269
  case 1:
7250
7270
  currentAgentName = _a.sent();
7251
7271
  if (currentAgentName !== agentName) {
@@ -7256,7 +7276,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
7256
7276
  });
7257
7277
  return [2 /*return*/];
7258
7278
  }
7259
- return [4 /*yield*/, swarm.sessionPublicService.commitSystemMessage(content, clientId, swarmName)];
7279
+ return [4 /*yield*/, swarm.sessionPublicService.commitSystemMessage(content, requestId, clientId, swarmName)];
7260
7280
  case 2:
7261
7281
  _a.sent();
7262
7282
  return [2 /*return*/];
@@ -7272,19 +7292,21 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
7272
7292
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
7273
7293
  */
7274
7294
  var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7275
- var swarmName, currentAgentName;
7295
+ var requestId, swarmName, currentAgentName;
7276
7296
  return __generator(this, function (_a) {
7277
7297
  switch (_a.label) {
7278
7298
  case 0:
7299
+ requestId = functoolsKit.randomString();
7279
7300
  swarm.loggerService.log('function commitFlush', {
7280
7301
  clientId: clientId,
7281
7302
  agentName: agentName,
7303
+ requestId: requestId,
7282
7304
  });
7283
7305
  swarm.agentValidationService.validate(agentName, "commitFlush");
7284
7306
  swarm.sessionValidationService.validate(clientId, "commitFlush");
7285
7307
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7286
7308
  swarm.swarmValidationService.validate(swarmName, "commitFlush");
7287
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7309
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7288
7310
  case 1:
7289
7311
  currentAgentName = _a.sent();
7290
7312
  if (currentAgentName !== agentName) {
@@ -7295,7 +7317,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
7295
7317
  });
7296
7318
  return [2 /*return*/];
7297
7319
  }
7298
- return [4 /*yield*/, swarm.sessionPublicService.commitFlush(clientId, swarmName)];
7320
+ return [4 /*yield*/, swarm.sessionPublicService.commitFlush(requestId, clientId, swarmName)];
7299
7321
  case 2:
7300
7322
  _a.sent();
7301
7323
  return [2 /*return*/];
@@ -7313,20 +7335,22 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
7313
7335
  * @returns {Promise<void>} - A promise that resolves when the execution is complete.
7314
7336
  */
7315
7337
  var execute = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7316
- var swarmName, currentAgentName;
7338
+ var requestId, swarmName, currentAgentName;
7317
7339
  return __generator(this, function (_a) {
7318
7340
  switch (_a.label) {
7319
7341
  case 0:
7342
+ requestId = functoolsKit.randomString();
7320
7343
  swarm.loggerService.log("function execute", {
7321
7344
  content: content,
7322
7345
  clientId: clientId,
7323
7346
  agentName: agentName,
7347
+ requestId: requestId,
7324
7348
  });
7325
7349
  swarm.agentValidationService.validate(agentName, "execute");
7326
7350
  swarm.sessionValidationService.validate(clientId, "execute");
7327
7351
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7328
7352
  swarm.swarmValidationService.validate(swarmName, "execute");
7329
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7353
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7330
7354
  case 1:
7331
7355
  currentAgentName = _a.sent();
7332
7356
  if (currentAgentName !== agentName) {
@@ -7337,7 +7361,7 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
7337
7361
  });
7338
7362
  return [2 /*return*/];
7339
7363
  }
7340
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", clientId, swarmName)];
7364
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", requestId, clientId, swarmName)];
7341
7365
  case 2: return [2 /*return*/, _a.sent()];
7342
7366
  }
7343
7367
  });
@@ -7354,14 +7378,16 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
7354
7378
  * @returns {Promise<void>} A promise that resolves when the content is emitted.
7355
7379
  */
7356
7380
  var emit = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7357
- var swarmName, currentAgentName;
7381
+ var requestId, swarmName, currentAgentName;
7358
7382
  return __generator(this, function (_a) {
7359
7383
  switch (_a.label) {
7360
7384
  case 0:
7385
+ requestId = functoolsKit.randomString();
7361
7386
  swarm.loggerService.log("function emit", {
7362
7387
  content: content,
7363
7388
  clientId: clientId,
7364
7389
  agentName: agentName,
7390
+ requestId: requestId,
7365
7391
  });
7366
7392
  if (swarm.sessionValidationService.getSessionMode(clientId) !== "makeConnection") {
7367
7393
  throw new Error("agent-swarm-kit emit session is not makeConnection clientId=".concat(clientId));
@@ -7370,7 +7396,7 @@ var emit = function (content, clientId, agentName) { return __awaiter(void 0, vo
7370
7396
  swarm.sessionValidationService.validate(clientId, "emit");
7371
7397
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7372
7398
  swarm.swarmValidationService.validate(swarmName, "emit");
7373
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7399
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7374
7400
  case 1:
7375
7401
  currentAgentName = _a.sent();
7376
7402
  if (currentAgentName !== agentName) {
@@ -7381,7 +7407,7 @@ var emit = function (content, clientId, agentName) { return __awaiter(void 0, vo
7381
7407
  });
7382
7408
  return [2 /*return*/];
7383
7409
  }
7384
- return [4 /*yield*/, swarm.sessionPublicService.emit(content, clientId, swarmName)];
7410
+ return [4 /*yield*/, swarm.sessionPublicService.emit(content, requestId, clientId, swarmName)];
7385
7411
  case 2: return [2 /*return*/, _a.sent()];
7386
7412
  }
7387
7413
  });
@@ -7395,19 +7421,21 @@ var emit = function (content, clientId, agentName) { return __awaiter(void 0, vo
7395
7421
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
7396
7422
  */
7397
7423
  var commitToolOutputForce = function (toolId, content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
7398
- var swarmName;
7424
+ var requestId, swarmName;
7399
7425
  return __generator(this, function (_a) {
7400
7426
  switch (_a.label) {
7401
7427
  case 0:
7428
+ requestId = functoolsKit.randomString();
7402
7429
  swarm.loggerService.log('function commitToolOutputForce', {
7403
7430
  toolId: toolId,
7404
7431
  content: content,
7405
7432
  clientId: clientId,
7433
+ requestId: requestId,
7406
7434
  });
7407
7435
  swarm.sessionValidationService.validate(clientId, "commitToolOutputForce");
7408
7436
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7409
7437
  swarm.swarmValidationService.validate(swarmName, "commitToolOutputForce");
7410
- return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, clientId, swarmName)];
7438
+ return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, requestId, clientId, swarmName)];
7411
7439
  case 1:
7412
7440
  _a.sent();
7413
7441
  return [2 /*return*/];
@@ -7423,18 +7451,20 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
7423
7451
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
7424
7452
  */
7425
7453
  var commitSystemMessageForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
7426
- var swarmName;
7454
+ var requestId, swarmName;
7427
7455
  return __generator(this, function (_a) {
7428
7456
  switch (_a.label) {
7429
7457
  case 0:
7458
+ requestId = functoolsKit.randomString();
7430
7459
  swarm.loggerService.log('function commitSystemMessageForce', {
7431
7460
  content: content,
7432
7461
  clientId: clientId,
7462
+ requestId: requestId,
7433
7463
  });
7434
7464
  swarm.sessionValidationService.validate(clientId, "commitSystemMessageForce");
7435
7465
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7436
7466
  swarm.swarmValidationService.validate(swarmName, "commitSystemMessageForce");
7437
- return [4 /*yield*/, swarm.sessionPublicService.commitSystemMessage(content, clientId, swarmName)];
7467
+ return [4 /*yield*/, swarm.sessionPublicService.commitSystemMessage(content, requestId, clientId, swarmName)];
7438
7468
  case 1:
7439
7469
  _a.sent();
7440
7470
  return [2 /*return*/];
@@ -7449,17 +7479,19 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
7449
7479
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
7450
7480
  */
7451
7481
  var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7452
- var swarmName;
7482
+ var requestId, swarmName;
7453
7483
  return __generator(this, function (_a) {
7454
7484
  switch (_a.label) {
7455
7485
  case 0:
7486
+ requestId = functoolsKit.randomString();
7456
7487
  swarm.loggerService.log('function commitFlushForce', {
7457
7488
  clientId: clientId,
7489
+ requestId: requestId,
7458
7490
  });
7459
7491
  swarm.sessionValidationService.validate(clientId, "commitFlushForce");
7460
7492
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7461
7493
  swarm.swarmValidationService.validate(swarmName, "commitFlushForce");
7462
- return [4 /*yield*/, swarm.sessionPublicService.commitFlush(clientId, swarmName)];
7494
+ return [4 /*yield*/, swarm.sessionPublicService.commitFlush(requestId, clientId, swarmName)];
7463
7495
  case 1:
7464
7496
  _a.sent();
7465
7497
  return [2 /*return*/];
@@ -7475,18 +7507,20 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
7475
7507
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
7476
7508
  */
7477
7509
  var commitUserMessageForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
7478
- var swarmName;
7510
+ var requestId, swarmName;
7479
7511
  return __generator(this, function (_a) {
7480
7512
  switch (_a.label) {
7481
7513
  case 0:
7514
+ requestId = functoolsKit.randomString();
7482
7515
  swarm.loggerService.log('function commitSystemMessage', {
7483
7516
  content: content,
7484
7517
  clientId: clientId,
7518
+ requestId: requestId,
7485
7519
  });
7486
7520
  swarm.sessionValidationService.validate(clientId, "commitUserMessageForce");
7487
7521
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7488
7522
  swarm.swarmValidationService.validate(swarmName, "commitUserMessageForce");
7489
- return [4 /*yield*/, swarm.sessionPublicService.commitUserMessage(content, clientId, swarmName)];
7523
+ return [4 /*yield*/, swarm.sessionPublicService.commitUserMessage(content, requestId, clientId, swarmName)];
7490
7524
  case 1:
7491
7525
  _a.sent();
7492
7526
  return [2 /*return*/];
@@ -7505,13 +7539,15 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
7505
7539
  * @returns {Promise<void>} A promise that resolves when the content is emitted.
7506
7540
  */
7507
7541
  var emitForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
7508
- var swarmName;
7542
+ var requestId, swarmName;
7509
7543
  return __generator(this, function (_a) {
7510
7544
  switch (_a.label) {
7511
7545
  case 0:
7546
+ requestId = functoolsKit.randomString();
7512
7547
  swarm.loggerService.log("function emitForce", {
7513
7548
  content: content,
7514
7549
  clientId: clientId,
7550
+ requestId: requestId,
7515
7551
  });
7516
7552
  if (swarm.sessionValidationService.getSessionMode(clientId) !== "makeConnection") {
7517
7553
  throw new Error("agent-swarm-kit emitForce session is not makeConnection clientId=".concat(clientId));
@@ -7519,7 +7555,7 @@ var emitForce = function (content, clientId) { return __awaiter(void 0, void 0,
7519
7555
  swarm.sessionValidationService.validate(clientId, "emitForce");
7520
7556
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7521
7557
  swarm.swarmValidationService.validate(swarmName, "emitForce");
7522
- return [4 /*yield*/, swarm.sessionPublicService.emit(content, clientId, swarmName)];
7558
+ return [4 /*yield*/, swarm.sessionPublicService.emit(content, requestId, clientId, swarmName)];
7523
7559
  case 1: return [2 /*return*/, _a.sent()];
7524
7560
  }
7525
7561
  });
@@ -7536,24 +7572,26 @@ var emitForce = function (content, clientId) { return __awaiter(void 0, void 0,
7536
7572
  * @returns {Promise<void>} - A promise that resolves when the execution is complete.
7537
7573
  */
7538
7574
  var executeForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
7539
- var swarmName;
7575
+ var requestId, swarmName;
7540
7576
  return __generator(this, function (_a) {
7541
7577
  switch (_a.label) {
7542
7578
  case 0:
7579
+ requestId = functoolsKit.randomString();
7543
7580
  swarm.loggerService.log("function executeForce", {
7544
7581
  content: content,
7545
7582
  clientId: clientId,
7583
+ requestId: requestId,
7546
7584
  });
7547
7585
  swarm.sessionValidationService.validate(clientId, "executeForce");
7548
7586
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7549
7587
  swarm.swarmValidationService.validate(swarmName, "executeForce");
7550
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", clientId, swarmName)];
7588
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", requestId, clientId, swarmName)];
7551
7589
  case 1: return [2 /*return*/, _a.sent()];
7552
7590
  }
7553
7591
  });
7554
7592
  }); };
7555
7593
 
7556
- var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
7594
+ var DISALLOWED_EVENT_SOURCE_LIST$2 = new Set([
7557
7595
  "agent-bus",
7558
7596
  "history-bus",
7559
7597
  "session-bus",
@@ -7561,7 +7599,7 @@ var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
7561
7599
  "storage-bus",
7562
7600
  "swarm-bus",
7563
7601
  ]);
7564
- var validateClientId$6 = function (clientId) {
7602
+ var validateClientId$d = function (clientId) {
7565
7603
  if (clientId === "*") {
7566
7604
  return;
7567
7605
  }
@@ -7580,16 +7618,56 @@ var listenEvent = function (clientId, topicName, fn) {
7580
7618
  swarm.loggerService.log("function listenEvent", {
7581
7619
  clientId: clientId,
7582
7620
  });
7583
- if (DISALLOWED_EVENT_SOURCE_LIST$1.has(topicName)) {
7621
+ if (DISALLOWED_EVENT_SOURCE_LIST$2.has(topicName)) {
7584
7622
  throw new Error("agent-swarm listenEvent topic is reserved topicName=".concat(topicName));
7585
7623
  }
7586
- validateClientId$6(clientId);
7624
+ validateClientId$d(clientId);
7587
7625
  return swarm.busService.subscribe(clientId, topicName, function (_a) {
7588
7626
  var payload = _a.payload;
7589
7627
  return fn(payload);
7590
7628
  });
7591
7629
  };
7592
7630
 
7631
+ var DISALLOWED_EVENT_SOURCE_LIST$1 = new Set([
7632
+ "agent-bus",
7633
+ "history-bus",
7634
+ "session-bus",
7635
+ "state-bus",
7636
+ "storage-bus",
7637
+ "swarm-bus",
7638
+ ]);
7639
+ var validateClientId$c = function (clientId) {
7640
+ if (clientId === "*") {
7641
+ return;
7642
+ }
7643
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
7644
+ throw new Error("agent-swarm listenEventOnce session not found for clientId=".concat(clientId));
7645
+ }
7646
+ };
7647
+ /**
7648
+ * Listens for an event on the swarm bus service and executes a callback function when the event is received.
7649
+ *
7650
+ * @template T - The type of the data payload.
7651
+ * @param {string} clientId - The ID of the client to listen for events from.
7652
+ * @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.
7653
+ */
7654
+ var listenEventOnce = function (clientId, topicName, filterFn, fn) {
7655
+ swarm.loggerService.log("function listenEventOnce", {
7656
+ clientId: clientId,
7657
+ });
7658
+ if (DISALLOWED_EVENT_SOURCE_LIST$1.has(topicName)) {
7659
+ throw new Error("agent-swarm listenEventOnce topic is reserved topicName=".concat(topicName));
7660
+ }
7661
+ validateClientId$c(clientId);
7662
+ return swarm.busService.once(clientId, topicName, function (_a) {
7663
+ var payload = _a.payload;
7664
+ return filterFn(payload);
7665
+ }, function (_a) {
7666
+ var payload = _a.payload;
7667
+ return fn(payload);
7668
+ });
7669
+ };
7670
+
7593
7671
  /**
7594
7672
  * Retrieves the last message sent by the user from the client's message history.
7595
7673
  *
@@ -7597,14 +7675,16 @@ var listenEvent = function (clientId, topicName, fn) {
7597
7675
  * @returns {Promise<string | null>} - The content of the last user message, or null if no user message is found.
7598
7676
  */
7599
7677
  var getLastUserMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7600
- var history, last;
7678
+ var requestId, history, last;
7601
7679
  return __generator(this, function (_a) {
7602
7680
  switch (_a.label) {
7603
7681
  case 0:
7682
+ requestId = functoolsKit.randomString();
7604
7683
  swarm.loggerService.log("function getLastUserMessage", {
7605
7684
  clientId: clientId,
7685
+ requestId: requestId,
7606
7686
  });
7607
- return [4 /*yield*/, getRawHistory(clientId)];
7687
+ return [4 /*yield*/, getRawHistory(clientId, requestId)];
7608
7688
  case 1:
7609
7689
  history = _a.sent();
7610
7690
  last = history.findLast(function (_a) {
@@ -7623,14 +7703,16 @@ var getLastUserMessage = function (clientId) { return __awaiter(void 0, void 0,
7623
7703
  * @returns {Promise<Array>} A promise that resolves to an array of history objects filtered by user role.
7624
7704
  */
7625
7705
  var getUserHistory = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7626
- var history;
7706
+ var requestId, history;
7627
7707
  return __generator(this, function (_a) {
7628
7708
  switch (_a.label) {
7629
7709
  case 0:
7710
+ requestId = functoolsKit.randomString();
7630
7711
  swarm.loggerService.log("function getUserHistory", {
7631
7712
  clientId: clientId,
7713
+ requestId: requestId,
7632
7714
  });
7633
- return [4 /*yield*/, getRawHistory(clientId)];
7715
+ return [4 /*yield*/, getRawHistory(clientId, requestId)];
7634
7716
  case 1:
7635
7717
  history = _a.sent();
7636
7718
  return [2 /*return*/, history.filter(function (_a) {
@@ -7648,14 +7730,16 @@ var getUserHistory = function (clientId) { return __awaiter(void 0, void 0, void
7648
7730
  * @returns {Promise<Array>} - A promise that resolves to an array of history objects where the role is "assistant".
7649
7731
  */
7650
7732
  var getAssistantHistory = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7651
- var history;
7733
+ var requestId, history;
7652
7734
  return __generator(this, function (_a) {
7653
7735
  switch (_a.label) {
7654
7736
  case 0:
7737
+ requestId = functoolsKit.randomString();
7655
7738
  swarm.loggerService.log("function getAssistantHistory", {
7656
7739
  clientId: clientId,
7740
+ requestId: requestId,
7657
7741
  });
7658
- return [4 /*yield*/, getRawHistory(clientId)];
7742
+ return [4 /*yield*/, getRawHistory(clientId, requestId)];
7659
7743
  case 1:
7660
7744
  history = _a.sent();
7661
7745
  return [2 /*return*/, history.filter(function (_a) {
@@ -7673,14 +7757,16 @@ var getAssistantHistory = function (clientId) { return __awaiter(void 0, void 0,
7673
7757
  * @returns {Promise<string | null>} - The content of the last assistant message, or null if no user message is found.
7674
7758
  */
7675
7759
  var getLastAssistantMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7676
- var history, last;
7760
+ var requestId, history, last;
7677
7761
  return __generator(this, function (_a) {
7678
7762
  switch (_a.label) {
7679
7763
  case 0:
7764
+ requestId = functoolsKit.randomString();
7680
7765
  swarm.loggerService.log("function getLastAssistantMessage", {
7681
7766
  clientId: clientId,
7767
+ requestId: requestId,
7682
7768
  });
7683
- return [4 /*yield*/, getRawHistory(clientId)];
7769
+ return [4 /*yield*/, getRawHistory(clientId, requestId)];
7684
7770
  case 1:
7685
7771
  history = _a.sent();
7686
7772
  last = history.findLast(function (_a) {
@@ -7699,14 +7785,16 @@ var getLastAssistantMessage = function (clientId) { return __awaiter(void 0, voi
7699
7785
  * @returns {Promise<string | null>} - The content of the last system message, or null if no user message is found.
7700
7786
  */
7701
7787
  var getLastSystemMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7702
- var history, last;
7788
+ var requestId, history, last;
7703
7789
  return __generator(this, function (_a) {
7704
7790
  switch (_a.label) {
7705
7791
  case 0:
7792
+ requestId = functoolsKit.randomString();
7706
7793
  swarm.loggerService.log("function getLastSystemMessage", {
7707
7794
  clientId: clientId,
7795
+ requestId: requestId,
7708
7796
  });
7709
- return [4 /*yield*/, getRawHistory(clientId)];
7797
+ return [4 /*yield*/, getRawHistory(clientId, requestId)];
7710
7798
  case 1:
7711
7799
  history = _a.sent();
7712
7800
  last = history.findLast(function (_a) {
@@ -7810,19 +7898,21 @@ var event = function (clientId, topicName, payload) {
7810
7898
  * @returns {Promise<void>} - A promise that resolves when the output is canceled
7811
7899
  */
7812
7900
  var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
7813
- var swarmName, currentAgentName;
7901
+ var requestId, swarmName, currentAgentName;
7814
7902
  return __generator(this, function (_a) {
7815
7903
  switch (_a.label) {
7816
7904
  case 0:
7905
+ requestId = functoolsKit.randomString();
7817
7906
  swarm.loggerService.log('function cancelOutput', {
7818
7907
  clientId: clientId,
7819
7908
  agentName: agentName,
7909
+ requestId: requestId,
7820
7910
  });
7821
7911
  swarm.agentValidationService.validate(agentName, "cancelOutput");
7822
7912
  swarm.sessionValidationService.validate(clientId, "cancelOutput");
7823
7913
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7824
7914
  swarm.swarmValidationService.validate(swarmName, "cancelOutput");
7825
- return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
7915
+ return [4 /*yield*/, swarm.swarmPublicService.getAgentName(requestId, clientId, swarmName)];
7826
7916
  case 1:
7827
7917
  currentAgentName = _a.sent();
7828
7918
  if (currentAgentName !== agentName) {
@@ -7833,7 +7923,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
7833
7923
  });
7834
7924
  return [2 /*return*/];
7835
7925
  }
7836
- return [4 /*yield*/, swarm.swarmPublicService.cancelOutput(clientId, swarmName)];
7926
+ return [4 /*yield*/, swarm.swarmPublicService.cancelOutput(requestId, clientId, swarmName)];
7837
7927
  case 2:
7838
7928
  _a.sent();
7839
7929
  return [2 /*return*/];
@@ -7849,17 +7939,19 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
7849
7939
  * @returns {Promise<void>} - A promise that resolves when the output is canceled
7850
7940
  */
7851
7941
  var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
7852
- var swarmName;
7942
+ var requestId, swarmName;
7853
7943
  return __generator(this, function (_a) {
7854
7944
  switch (_a.label) {
7855
7945
  case 0:
7946
+ requestId = functoolsKit.randomString();
7856
7947
  swarm.loggerService.log('function cancelOutputForce', {
7857
7948
  clientId: clientId,
7949
+ requestId: requestId
7858
7950
  });
7859
7951
  swarm.sessionValidationService.validate(clientId, "cancelOutputForce");
7860
7952
  swarmName = swarm.sessionValidationService.getSwarm(clientId);
7861
7953
  swarm.swarmValidationService.validate(swarmName, "cancelOutputForce");
7862
- return [4 /*yield*/, swarm.swarmPublicService.cancelOutput(clientId, swarmName)];
7954
+ return [4 /*yield*/, swarm.swarmPublicService.cancelOutput(requestId, clientId, swarmName)];
7863
7955
  case 1:
7864
7956
  _a.sent();
7865
7957
  return [2 /*return*/];
@@ -7867,7 +7959,7 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
7867
7959
  });
7868
7960
  }); };
7869
7961
 
7870
- var validateClientId$5 = function (clientId) {
7962
+ var validateClientId$b = function (clientId) {
7871
7963
  if (clientId === "*") {
7872
7964
  return;
7873
7965
  }
@@ -7885,11 +7977,11 @@ var listenAgentEvent = function (clientId, fn) {
7885
7977
  swarm.loggerService.log("middleware listenAgentEvent", {
7886
7978
  clientId: clientId,
7887
7979
  });
7888
- validateClientId$5(clientId);
7889
- swarm.busService.subscribe(clientId, "agent-bus", fn);
7980
+ validateClientId$b(clientId);
7981
+ return swarm.busService.subscribe(clientId, "agent-bus", fn);
7890
7982
  };
7891
7983
 
7892
- var validateClientId$4 = function (clientId) {
7984
+ var validateClientId$a = function (clientId) {
7893
7985
  if (clientId === "*") {
7894
7986
  return;
7895
7987
  }
@@ -7907,11 +7999,11 @@ var listenHistoryEvent = function (clientId, fn) {
7907
7999
  swarm.loggerService.log("middleware listenHistoryEvent", {
7908
8000
  clientId: clientId,
7909
8001
  });
7910
- validateClientId$4(clientId);
7911
- swarm.busService.subscribe(clientId, "history-bus", fn);
8002
+ validateClientId$a(clientId);
8003
+ return swarm.busService.subscribe(clientId, "history-bus", fn);
7912
8004
  };
7913
8005
 
7914
- var validateClientId$3 = function (clientId) {
8006
+ var validateClientId$9 = function (clientId) {
7915
8007
  if (clientId === "*") {
7916
8008
  return;
7917
8009
  }
@@ -7929,11 +8021,11 @@ var listenSessionEvent = function (clientId, fn) {
7929
8021
  swarm.loggerService.log("middleware listenSessionEvent", {
7930
8022
  clientId: clientId,
7931
8023
  });
7932
- validateClientId$3(clientId);
7933
- swarm.busService.subscribe(clientId, "session-bus", fn);
8024
+ validateClientId$9(clientId);
8025
+ return swarm.busService.subscribe(clientId, "session-bus", fn);
7934
8026
  };
7935
8027
 
7936
- var validateClientId$2 = function (clientId) {
8028
+ var validateClientId$8 = function (clientId) {
7937
8029
  if (clientId === "*") {
7938
8030
  return;
7939
8031
  }
@@ -7951,11 +8043,11 @@ var listenStateEvent = function (clientId, fn) {
7951
8043
  swarm.loggerService.log("middleware listenStateEvent", {
7952
8044
  clientId: clientId,
7953
8045
  });
7954
- validateClientId$2(clientId);
7955
- swarm.busService.subscribe(clientId, "state-bus", fn);
8046
+ validateClientId$8(clientId);
8047
+ return swarm.busService.subscribe(clientId, "state-bus", fn);
7956
8048
  };
7957
8049
 
7958
- var validateClientId$1 = function (clientId) {
8050
+ var validateClientId$7 = function (clientId) {
7959
8051
  if (clientId === "*") {
7960
8052
  return;
7961
8053
  }
@@ -7973,11 +8065,11 @@ var listenStorageEvent = function (clientId, fn) {
7973
8065
  swarm.loggerService.log("middleware listenStorageEvent", {
7974
8066
  clientId: clientId,
7975
8067
  });
7976
- validateClientId$1(clientId);
7977
- swarm.busService.subscribe(clientId, "storage-bus", fn);
8068
+ validateClientId$7(clientId);
8069
+ return swarm.busService.subscribe(clientId, "storage-bus", fn);
7978
8070
  };
7979
8071
 
7980
- var validateClientId = function (clientId) {
8072
+ var validateClientId$6 = function (clientId) {
7981
8073
  if (clientId === "*") {
7982
8074
  return;
7983
8075
  }
@@ -7995,8 +8087,140 @@ var listenSwarmEvent = function (clientId, fn) {
7995
8087
  swarm.loggerService.log("middleware listenSwarmEvent", {
7996
8088
  clientId: clientId,
7997
8089
  });
8090
+ validateClientId$6(clientId);
8091
+ return swarm.busService.subscribe(clientId, "swarm-bus", fn);
8092
+ };
8093
+
8094
+ var validateClientId$5 = function (clientId) {
8095
+ if (clientId === "*") {
8096
+ return;
8097
+ }
8098
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8099
+ throw new Error("agent-swarm listenAgentEventOnce session not found for clientId=".concat(clientId));
8100
+ }
8101
+ };
8102
+ /**
8103
+ * Hook to subscribe to agent events for a specific client.
8104
+ *
8105
+ * @param {string} clientId - The ID of the client to subscribe to events for.
8106
+ * @param {function} fn - The callback function to handle the event.
8107
+ */
8108
+ var listenAgentEventOnce = function (clientId, filterFn, fn) {
8109
+ swarm.loggerService.log("middleware listenAgentEventOnce", {
8110
+ clientId: clientId,
8111
+ });
8112
+ validateClientId$5(clientId);
8113
+ return swarm.busService.once(clientId, "agent-bus", filterFn, fn);
8114
+ };
8115
+
8116
+ var validateClientId$4 = function (clientId) {
8117
+ if (clientId === "*") {
8118
+ return;
8119
+ }
8120
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8121
+ throw new Error("agent-swarm listenHistoryEventOnce session not found for clientId=".concat(clientId));
8122
+ }
8123
+ };
8124
+ /**
8125
+ * Hook to subscribe to history events for a specific client.
8126
+ *
8127
+ * @param {string} clientId - The ID of the client to subscribe to.
8128
+ * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
8129
+ */
8130
+ var listenHistoryEventOnce = function (clientId, filterFn, fn) {
8131
+ swarm.loggerService.log("middleware listenHistoryEventOnce", {
8132
+ clientId: clientId,
8133
+ });
8134
+ validateClientId$4(clientId);
8135
+ return swarm.busService.once(clientId, "history-bus", filterFn, fn);
8136
+ };
8137
+
8138
+ var validateClientId$3 = function (clientId) {
8139
+ if (clientId === "*") {
8140
+ return;
8141
+ }
8142
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8143
+ throw new Error("agent-swarm listenSessionEventOnce session not found for clientId=".concat(clientId));
8144
+ }
8145
+ };
8146
+ /**
8147
+ * Hook to subscribe to session events for a specific client.
8148
+ *
8149
+ * @param {string} clientId - The ID of the client to subscribe to session events for.
8150
+ * @param {function} fn - The callback function to handle the session events.
8151
+ */
8152
+ var listenSessionEventOnce = function (clientId, filterFn, fn) {
8153
+ swarm.loggerService.log("middleware listenSessionEventOnce", {
8154
+ clientId: clientId,
8155
+ });
8156
+ validateClientId$3(clientId);
8157
+ return swarm.busService.once(clientId, "session-bus", filterFn, fn);
8158
+ };
8159
+
8160
+ var validateClientId$2 = function (clientId) {
8161
+ if (clientId === "*") {
8162
+ return;
8163
+ }
8164
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8165
+ throw new Error("agent-swarm listenStateEventOnce session not found for clientId=".concat(clientId));
8166
+ }
8167
+ };
8168
+ /**
8169
+ * Hook to subscribe to state events for a specific client.
8170
+ *
8171
+ * @param {string} clientId - The ID of the client to subscribe to.
8172
+ * @param {function} fn - The callback function to handle the event.
8173
+ */
8174
+ var listenStateEventOnce = function (clientId, filterFn, fn) {
8175
+ swarm.loggerService.log("middleware listenStateEventOnce", {
8176
+ clientId: clientId,
8177
+ });
8178
+ validateClientId$2(clientId);
8179
+ return swarm.busService.once(clientId, "state-bus", filterFn, fn);
8180
+ };
8181
+
8182
+ var validateClientId$1 = function (clientId) {
8183
+ if (clientId === "*") {
8184
+ return;
8185
+ }
8186
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8187
+ throw new Error("agent-swarm listenStorageEventOnce session not found for clientId=".concat(clientId));
8188
+ }
8189
+ };
8190
+ /**
8191
+ * Hook to subscribe to storage events for a specific client.
8192
+ *
8193
+ * @param {string} clientId - The ID of the client to subscribe to storage events for.
8194
+ * @param {function} fn - The callback function to handle the storage event.
8195
+ */
8196
+ var listenStorageEventOnce = function (clientId, filterFn, fn) {
8197
+ swarm.loggerService.log("middleware listenStorageEventOnce", {
8198
+ clientId: clientId,
8199
+ });
8200
+ validateClientId$1(clientId);
8201
+ return swarm.busService.once(clientId, "storage-bus", filterFn, fn);
8202
+ };
8203
+
8204
+ var validateClientId = function (clientId) {
8205
+ if (clientId === "*") {
8206
+ return;
8207
+ }
8208
+ if (!swarm.sessionValidationService.hasSession(clientId)) {
8209
+ throw new Error("agent-swarm listenSwarmEventOnce session not found for clientId=".concat(clientId));
8210
+ }
8211
+ };
8212
+ /**
8213
+ * Hook to subscribe to swarm events for a specific client.
8214
+ *
8215
+ * @param {string} clientId - The ID of the client to subscribe to events for.
8216
+ * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
8217
+ */
8218
+ var listenSwarmEventOnce = function (clientId, filterFn, fn) {
8219
+ swarm.loggerService.log("middleware listenSwarmEventOnce", {
8220
+ clientId: clientId,
8221
+ });
7998
8222
  validateClientId(clientId);
7999
- swarm.busService.subscribe(clientId, "swarm-bus", fn);
8223
+ return swarm.busService.once(clientId, "swarm-bus", filterFn, fn);
8000
8224
  };
8001
8225
 
8002
8226
  var StorageUtils = /** @class */ (function () {
@@ -8013,21 +8237,24 @@ var StorageUtils = /** @class */ (function () {
8013
8237
  * @template T
8014
8238
  */
8015
8239
  this.take = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8240
+ var requestId;
8016
8241
  return __generator(this, function (_a) {
8017
8242
  switch (_a.label) {
8018
8243
  case 0:
8244
+ requestId = functoolsKit.randomString();
8019
8245
  swarm.loggerService.log("StorageUtils take", {
8020
8246
  search: payload.search,
8021
8247
  total: payload.total,
8022
8248
  clientId: payload.clientId,
8023
8249
  storageName: payload.storageName,
8024
8250
  score: payload.score,
8251
+ requestId: requestId,
8025
8252
  });
8026
8253
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8027
8254
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8028
8255
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (take)"));
8029
8256
  }
8030
- return [4 /*yield*/, swarm.storagePublicService.take(payload.search, payload.total, payload.clientId, payload.storageName, payload.score)];
8257
+ return [4 /*yield*/, swarm.storagePublicService.take(payload.search, payload.total, requestId, payload.clientId, payload.storageName, payload.score)];
8031
8258
  case 1: return [2 /*return*/, (_a.sent())];
8032
8259
  }
8033
8260
  });
@@ -8042,19 +8269,22 @@ var StorageUtils = /** @class */ (function () {
8042
8269
  * @template T
8043
8270
  */
8044
8271
  this.upsert = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8272
+ var requestId;
8045
8273
  return __generator(this, function (_a) {
8046
8274
  switch (_a.label) {
8047
8275
  case 0:
8276
+ requestId = functoolsKit.randomString();
8048
8277
  swarm.loggerService.log("StorageUtils upsert", {
8049
8278
  item: payload.item,
8050
8279
  clientId: payload.clientId,
8051
8280
  storageName: payload.storageName,
8281
+ requestId: requestId,
8052
8282
  });
8053
8283
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8054
8284
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8055
8285
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (upsert)"));
8056
8286
  }
8057
- return [4 /*yield*/, swarm.storagePublicService.upsert(payload.item, payload.clientId, payload.storageName)];
8287
+ return [4 /*yield*/, swarm.storagePublicService.upsert(payload.item, requestId, payload.clientId, payload.storageName)];
8058
8288
  case 1: return [2 /*return*/, _a.sent()];
8059
8289
  }
8060
8290
  });
@@ -8068,19 +8298,22 @@ var StorageUtils = /** @class */ (function () {
8068
8298
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
8069
8299
  */
8070
8300
  this.remove = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8301
+ var requestId;
8071
8302
  return __generator(this, function (_a) {
8072
8303
  switch (_a.label) {
8073
8304
  case 0:
8305
+ requestId = functoolsKit.randomString();
8074
8306
  swarm.loggerService.log("StorageUtils remove", {
8075
8307
  itemId: payload.itemId,
8076
8308
  clientId: payload.clientId,
8077
8309
  storageName: payload.storageName,
8310
+ requestId: requestId,
8078
8311
  });
8079
8312
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8080
8313
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8081
8314
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (remove)"));
8082
8315
  }
8083
- return [4 /*yield*/, swarm.storagePublicService.remove(payload.itemId, payload.clientId, payload.storageName)];
8316
+ return [4 /*yield*/, swarm.storagePublicService.remove(payload.itemId, requestId, payload.clientId, payload.storageName)];
8084
8317
  case 1: return [2 /*return*/, _a.sent()];
8085
8318
  }
8086
8319
  });
@@ -8095,19 +8328,22 @@ var StorageUtils = /** @class */ (function () {
8095
8328
  * @template T
8096
8329
  */
8097
8330
  this.get = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8331
+ var requestId;
8098
8332
  return __generator(this, function (_a) {
8099
8333
  switch (_a.label) {
8100
8334
  case 0:
8335
+ requestId = functoolsKit.randomString();
8101
8336
  swarm.loggerService.log("StorageUtils get", {
8102
8337
  itemId: payload.itemId,
8103
8338
  clientId: payload.clientId,
8104
8339
  storageName: payload.storageName,
8340
+ requestId: requestId,
8105
8341
  });
8106
8342
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8107
8343
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8108
8344
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (get)"));
8109
8345
  }
8110
- return [4 /*yield*/, swarm.storagePublicService.get(payload.itemId, payload.clientId, payload.storageName)];
8346
+ return [4 /*yield*/, swarm.storagePublicService.get(payload.itemId, requestId, payload.clientId, payload.storageName)];
8111
8347
  case 1: return [2 /*return*/, (_a.sent())];
8112
8348
  }
8113
8349
  });
@@ -8122,18 +8358,21 @@ var StorageUtils = /** @class */ (function () {
8122
8358
  * @template T
8123
8359
  */
8124
8360
  this.list = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8361
+ var requestId;
8125
8362
  return __generator(this, function (_a) {
8126
8363
  switch (_a.label) {
8127
8364
  case 0:
8365
+ requestId = functoolsKit.randomString();
8128
8366
  swarm.loggerService.log("StorageUtils list", {
8129
8367
  clientId: payload.clientId,
8130
8368
  storageName: payload.storageName,
8369
+ requestId: requestId,
8131
8370
  });
8132
8371
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8133
8372
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8134
8373
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (list)"));
8135
8374
  }
8136
- return [4 /*yield*/, swarm.storagePublicService.list(payload.clientId, payload.storageName, payload.filter)];
8375
+ return [4 /*yield*/, swarm.storagePublicService.list(requestId, payload.clientId, payload.storageName, payload.filter)];
8137
8376
  case 1: return [2 /*return*/, (_a.sent())];
8138
8377
  }
8139
8378
  });
@@ -8146,18 +8385,21 @@ var StorageUtils = /** @class */ (function () {
8146
8385
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
8147
8386
  */
8148
8387
  this.clear = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8388
+ var requestId;
8149
8389
  return __generator(this, function (_a) {
8150
8390
  switch (_a.label) {
8151
8391
  case 0:
8392
+ requestId = functoolsKit.randomString();
8152
8393
  swarm.loggerService.log("StorageUtils clear", {
8153
8394
  clientId: payload.clientId,
8154
8395
  storageName: payload.storageName,
8396
+ requestId: requestId,
8155
8397
  });
8156
8398
  swarm.storageValidationService.validate(payload.storageName, "StorageUtils");
8157
8399
  if (!swarm.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
8158
8400
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (clear)"));
8159
8401
  }
8160
- return [4 /*yield*/, swarm.storagePublicService.clear(payload.clientId, payload.storageName)];
8402
+ return [4 /*yield*/, swarm.storagePublicService.clear(requestId, payload.clientId, payload.storageName)];
8161
8403
  case 1: return [2 /*return*/, _a.sent()];
8162
8404
  }
8163
8405
  });
@@ -8185,17 +8427,20 @@ var StateUtils = /** @class */ (function () {
8185
8427
  * @throws Will throw an error if the state is not registered in the agent.
8186
8428
  */
8187
8429
  this.getState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
8430
+ var requestId;
8188
8431
  return __generator(this, function (_a) {
8189
8432
  switch (_a.label) {
8190
8433
  case 0:
8434
+ requestId = functoolsKit.randomString();
8191
8435
  swarm.loggerService.log("StateUtils getState", {
8192
8436
  clientId: payload.clientId,
8193
8437
  stateName: payload.stateName,
8438
+ requestId: requestId,
8194
8439
  });
8195
8440
  if (!swarm.agentValidationService.hasState(payload.agentName, payload.stateName)) {
8196
8441
  throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (getState)"));
8197
8442
  }
8198
- return [4 /*yield*/, swarm.statePublicService.getState(payload.clientId, payload.stateName)];
8443
+ return [4 /*yield*/, swarm.statePublicService.getState(requestId, payload.clientId, payload.stateName)];
8199
8444
  case 1: return [2 /*return*/, _a.sent()];
8200
8445
  }
8201
8446
  });
@@ -8212,23 +8457,26 @@ var StateUtils = /** @class */ (function () {
8212
8457
  * @throws Will throw an error if the state is not registered in the agent.
8213
8458
  */
8214
8459
  this.setState = function (dispatchFn, payload) { return __awaiter(_this, void 0, void 0, function () {
8460
+ var requestId;
8215
8461
  var _this = this;
8216
8462
  return __generator(this, function (_a) {
8217
8463
  switch (_a.label) {
8218
8464
  case 0:
8465
+ requestId = functoolsKit.randomString();
8219
8466
  swarm.loggerService.log("StateUtils setState", {
8220
8467
  clientId: payload.clientId,
8221
8468
  stateName: payload.stateName,
8469
+ requestId: requestId,
8222
8470
  });
8223
8471
  if (!swarm.agentValidationService.hasState(payload.agentName, payload.stateName)) {
8224
8472
  throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (setState)"));
8225
8473
  }
8226
8474
  if (!(typeof dispatchFn === "function")) return [3 /*break*/, 2];
8227
- return [4 /*yield*/, swarm.statePublicService.setState(dispatchFn, payload.clientId, payload.stateName)];
8475
+ return [4 /*yield*/, swarm.statePublicService.setState(dispatchFn, requestId, payload.clientId, payload.stateName)];
8228
8476
  case 1: return [2 /*return*/, _a.sent()];
8229
8477
  case 2: return [4 /*yield*/, swarm.statePublicService.setState(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
8230
8478
  return [2 /*return*/, dispatchFn];
8231
- }); }); }, payload.clientId, payload.stateName)];
8479
+ }); }); }, requestId, payload.clientId, payload.stateName)];
8232
8480
  case 3: return [2 /*return*/, _a.sent()];
8233
8481
  }
8234
8482
  });
@@ -8242,10 +8490,30 @@ var StateUtils = /** @class */ (function () {
8242
8490
  */
8243
8491
  var State = new StateUtils();
8244
8492
 
8493
+ var LoggerUtils = /** @class */ (function () {
8494
+ function LoggerUtils() {
8495
+ /**
8496
+ * Sets the provided logger to the logger service.
8497
+ * @param {ILogger} logger - The logger instance to be used.
8498
+ */
8499
+ this.useLogger = function (logger) {
8500
+ swarm.loggerService.log("HistoryInstance useLogger");
8501
+ swarm.loggerService.setLogger(logger);
8502
+ };
8503
+ }
8504
+ return LoggerUtils;
8505
+ }());
8506
+ /**
8507
+ * Instance of LoggerUtils to be used for logging.
8508
+ * @type {LoggerUtils}
8509
+ */
8510
+ var Logger = new LoggerUtils();
8511
+
8245
8512
  exports.ContextService = ContextService;
8246
8513
  exports.History = History;
8247
8514
  exports.HistoryAdapter = HistoryAdapter;
8248
8515
  exports.HistoryInstance = HistoryInstance;
8516
+ exports.Logger = Logger;
8249
8517
  exports.State = State;
8250
8518
  exports.Storage = Storage;
8251
8519
  exports.addAgent = addAgent;
@@ -8283,12 +8551,19 @@ exports.getRawHistory = getRawHistory;
8283
8551
  exports.getSessionMode = getSessionMode;
8284
8552
  exports.getUserHistory = getUserHistory;
8285
8553
  exports.listenAgentEvent = listenAgentEvent;
8554
+ exports.listenAgentEventOnce = listenAgentEventOnce;
8286
8555
  exports.listenEvent = listenEvent;
8556
+ exports.listenEventOnce = listenEventOnce;
8287
8557
  exports.listenHistoryEvent = listenHistoryEvent;
8558
+ exports.listenHistoryEventOnce = listenHistoryEventOnce;
8288
8559
  exports.listenSessionEvent = listenSessionEvent;
8560
+ exports.listenSessionEventOnce = listenSessionEventOnce;
8289
8561
  exports.listenStateEvent = listenStateEvent;
8562
+ exports.listenStateEventOnce = listenStateEventOnce;
8290
8563
  exports.listenStorageEvent = listenStorageEvent;
8564
+ exports.listenStorageEventOnce = listenStorageEventOnce;
8291
8565
  exports.listenSwarmEvent = listenSwarmEvent;
8566
+ exports.listenSwarmEventOnce = listenSwarmEventOnce;
8292
8567
  exports.makeAutoDispose = makeAutoDispose;
8293
8568
  exports.makeConnection = makeConnection;
8294
8569
  exports.session = session;