agent-swarm-kit 1.0.109 → 1.0.111

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.
Files changed (4) hide show
  1. package/build/index.cjs +1330 -276
  2. package/build/index.mjs +1327 -277
  3. package/package.json +1 -1
  4. package/types.d.ts +431 -63
package/build/index.cjs CHANGED
@@ -187,7 +187,9 @@ var connectionServices$1 = {
187
187
  swarmConnectionService: Symbol('swarmConnectionService'),
188
188
  sessionConnectionService: Symbol('sessionConnectionService'),
189
189
  storageConnectionService: Symbol('storageConnectionService'),
190
+ sharedStorageConnectionService: Symbol('sharedStorageConnectionService'),
190
191
  stateConnectionService: Symbol('stateConnectionService'),
192
+ sharedStateConnectionService: Symbol('sharedStateConnectionService'),
191
193
  };
192
194
  var schemaServices$1 = {
193
195
  completionSchemaService: Symbol('completionSchemaService'),
@@ -208,7 +210,9 @@ var publicServices$1 = {
208
210
  sessionPublicService: Symbol('sessionPublicService'),
209
211
  swarmPublicService: Symbol('swarmPublicService'),
210
212
  storagePublicService: Symbol('storagePublicService'),
213
+ sharedStoragePublicService: Symbol('sharedStoragePublicService'),
211
214
  statePublicService: Symbol('statePublicService'),
215
+ sharedStatePublicService: Symbol('sharedStatePublicService'),
212
216
  };
213
217
  var validationServices$1 = {
214
218
  agentValidationService: Symbol('agentValidationService'),
@@ -1718,6 +1722,8 @@ var ClientAgent = /** @class */ (function () {
1718
1722
  }
1719
1723
  this.params.onOutput &&
1720
1724
  this.params.onOutput(this.params.clientId, this.params.agentName, result_1);
1725
+ this.params.onAssistantMessage &&
1726
+ this.params.onAssistantMessage(this.params.clientId, this.params.agentName, result_1);
1721
1727
  return [4 /*yield*/, this._outputSubject.next(result_1)];
1722
1728
  case 6:
1723
1729
  _a.sent();
@@ -2020,6 +2026,45 @@ var ClientAgent = /** @class */ (function () {
2020
2026
  }
2021
2027
  });
2022
2028
  }); };
2029
+ /**
2030
+ * Commits an assistant message to the history without execute.
2031
+ * @param {string} message - The system message to commit.
2032
+ * @returns {Promise<void>}
2033
+ */
2034
+ this.commitAssistantMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
2035
+ return __generator(this, function (_a) {
2036
+ switch (_a.label) {
2037
+ case 0:
2038
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2039
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitAssistantMessage"), { message: message });
2040
+ this.params.onAssistantMessage &&
2041
+ this.params.onAssistantMessage(this.params.clientId, this.params.agentName, message);
2042
+ return [4 /*yield*/, this.params.history.push({
2043
+ role: "assistant",
2044
+ agentName: this.params.agentName,
2045
+ mode: "tool",
2046
+ content: message.trim(),
2047
+ })];
2048
+ case 1:
2049
+ _a.sent();
2050
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2051
+ type: "commit-assistant-message",
2052
+ source: "agent-bus",
2053
+ input: {
2054
+ message: message,
2055
+ },
2056
+ output: {},
2057
+ context: {
2058
+ agentName: this.params.agentName,
2059
+ },
2060
+ clientId: this.params.clientId,
2061
+ })];
2062
+ case 2:
2063
+ _a.sent();
2064
+ return [2 /*return*/];
2065
+ }
2066
+ });
2067
+ }); };
2023
2068
  /**
2024
2069
  * Commits the tool output to the history.
2025
2070
  * @param {string} content - The tool output content.
@@ -2386,8 +2431,8 @@ var AgentConnectionService = /** @class */ (function () {
2386
2431
  });
2387
2432
  }); };
2388
2433
  /**
2389
- * Commits a system message.
2390
- * @param {string} message - The system message.
2434
+ * Commits an assistant message.
2435
+ * @param {string} message - The assistant message.
2391
2436
  * @returns {Promise<any>} The commit result.
2392
2437
  */
2393
2438
  this.commitSystemMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
@@ -2403,6 +2448,24 @@ var AgentConnectionService = /** @class */ (function () {
2403
2448
  }
2404
2449
  });
2405
2450
  }); };
2451
+ /**
2452
+ * Commits a system message.
2453
+ * @param {string} message - The system message.
2454
+ * @returns {Promise<any>} The commit result.
2455
+ */
2456
+ this.commitAssistantMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
2457
+ return __generator(this, function (_a) {
2458
+ switch (_a.label) {
2459
+ case 0:
2460
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
2461
+ this.loggerService.info("agentConnectionService commitAssistantMessage", {
2462
+ message: message,
2463
+ });
2464
+ return [4 /*yield*/, this.getAgent(this.methodContextService.context.clientId, this.methodContextService.context.agentName).commitAssistantMessage(message)];
2465
+ case 1: return [2 /*return*/, _a.sent()];
2466
+ }
2467
+ });
2468
+ }); };
2406
2469
  /**
2407
2470
  * Commits a user message without answer.
2408
2471
  * @param {string} message - The message.
@@ -3767,6 +3830,44 @@ var ClientSession = /** @class */ (function () {
3767
3830
  }
3768
3831
  });
3769
3832
  }); };
3833
+ /**
3834
+ * Commits an assistant message.
3835
+ * @param {string} message - The assistant message to commit.
3836
+ * @returns {Promise<void>}
3837
+ */
3838
+ this.commitAssistantMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
3839
+ var agent, result;
3840
+ return __generator(this, function (_a) {
3841
+ switch (_a.label) {
3842
+ case 0:
3843
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3844
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitAssistantMessage"), {
3845
+ message: message,
3846
+ });
3847
+ return [4 /*yield*/, this.params.swarm.getAgent()];
3848
+ case 1:
3849
+ agent = _a.sent();
3850
+ return [4 /*yield*/, agent.commitAssistantMessage(message)];
3851
+ case 2:
3852
+ result = _a.sent();
3853
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
3854
+ type: "commit-assistant-message",
3855
+ source: "session-bus",
3856
+ input: {
3857
+ message: message,
3858
+ },
3859
+ output: {},
3860
+ context: {
3861
+ swarmName: this.params.swarmName,
3862
+ },
3863
+ clientId: this.params.clientId,
3864
+ })];
3865
+ case 3:
3866
+ _a.sent();
3867
+ return [2 /*return*/, result];
3868
+ }
3869
+ });
3870
+ }); };
3770
3871
  /**
3771
3872
  * Connects the session to a connector function.
3772
3873
  * @param {SendMessageFn} connector - The connector function.
@@ -3966,6 +4067,24 @@ var SessionConnectionService = /** @class */ (function () {
3966
4067
  }
3967
4068
  });
3968
4069
  }); };
4070
+ /**
4071
+ * Commits an assistant message to the session.
4072
+ * @param {string} message - The message to commit.
4073
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
4074
+ */
4075
+ this.commitAssistantMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
4076
+ return __generator(this, function (_a) {
4077
+ switch (_a.label) {
4078
+ case 0:
4079
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4080
+ this.loggerService.info("sessionConnectionService commitAssistantMessage", {
4081
+ message: message,
4082
+ });
4083
+ return [4 /*yield*/, this.getSession(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).commitAssistantMessage(message)];
4084
+ case 1: return [2 /*return*/, _a.sent()];
4085
+ }
4086
+ });
4087
+ }); };
3969
4088
  /**
3970
4089
  * Commits user message to the agent without answer.
3971
4090
  * @param {string} message - The message to commit.
@@ -4224,6 +4343,44 @@ var AgentPublicService = /** @class */ (function () {
4224
4343
  }
4225
4344
  });
4226
4345
  }); };
4346
+ /**
4347
+ * Commits an assistant message to the agent history.
4348
+ * @param {string} message - The message to commit.
4349
+ * @param {string} clientId - The client ID.
4350
+ * @param {AgentName} agentName - The name of the agent.
4351
+ * @returns {Promise<unknown>} The commit result.
4352
+ */
4353
+ this.commitAssistantMessage = function (message, methodName, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
4354
+ var _this = this;
4355
+ return __generator(this, function (_a) {
4356
+ switch (_a.label) {
4357
+ case 0:
4358
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4359
+ this.loggerService.info("agentPublicService commitAssistantMessage", {
4360
+ methodName: methodName,
4361
+ message: message,
4362
+ clientId: clientId,
4363
+ agentName: agentName,
4364
+ });
4365
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4366
+ return __generator(this, function (_a) {
4367
+ switch (_a.label) {
4368
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitAssistantMessage(message)];
4369
+ case 1: return [2 /*return*/, _a.sent()];
4370
+ }
4371
+ });
4372
+ }); }, {
4373
+ methodName: methodName,
4374
+ clientId: clientId,
4375
+ agentName: agentName,
4376
+ swarmName: "",
4377
+ storageName: "",
4378
+ stateName: "",
4379
+ })];
4380
+ case 1: return [2 /*return*/, _a.sent()];
4381
+ }
4382
+ });
4383
+ }); };
4227
4384
  /**
4228
4385
  * Commits user message to the agent without answer.
4229
4386
  * @param {string} message - The message to commit.
@@ -4736,6 +4893,44 @@ var SessionPublicService = /** @class */ (function () {
4736
4893
  }
4737
4894
  });
4738
4895
  }); };
4896
+ /**
4897
+ * Commits an assistant message to the session.
4898
+ * @param {string} message - The message to commit.
4899
+ * @param {string} clientId - The client ID.
4900
+ * @param {SwarmName} swarmName - The swarm name.
4901
+ * @returns {Promise<void>``}
4902
+ */
4903
+ this.commitAssistantMessage = function (message, methodName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
4904
+ var _this = this;
4905
+ return __generator(this, function (_a) {
4906
+ switch (_a.label) {
4907
+ case 0:
4908
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4909
+ this.loggerService.info("sessionPublicService commitAssistantMessage", {
4910
+ methodName: methodName,
4911
+ message: message,
4912
+ clientId: clientId,
4913
+ swarmName: swarmName,
4914
+ });
4915
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4916
+ return __generator(this, function (_a) {
4917
+ switch (_a.label) {
4918
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitAssistantMessage(message)];
4919
+ case 1: return [2 /*return*/, _a.sent()];
4920
+ }
4921
+ });
4922
+ }); }, {
4923
+ methodName: methodName,
4924
+ clientId: clientId,
4925
+ swarmName: swarmName,
4926
+ agentName: "",
4927
+ storageName: "",
4928
+ stateName: "",
4929
+ })];
4930
+ case 1: return [2 /*return*/, _a.sent()];
4931
+ }
4932
+ });
4933
+ }); };
4739
4934
  /**
4740
4935
  * Commits user message to the agent without answer.
4741
4936
  * @param {string} message - The message to commit.
@@ -5664,7 +5859,10 @@ var SessionValidationService = /** @class */ (function () {
5664
5859
  * @param {string} source - The source of the validation request.
5665
5860
  * @throws Will throw an error if the session does not exist.
5666
5861
  */
5667
- this.validate = function (clientId, source) {
5862
+ this.validate = functoolsKit.memoize(function (_a) {
5863
+ var _b = __read(_a, 1), clientId = _b[0];
5864
+ return "".concat(clientId);
5865
+ }, function (clientId, source) {
5668
5866
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5669
5867
  _this.loggerService.info("sessionValidationService validate", {
5670
5868
  clientId: clientId,
@@ -5676,7 +5874,7 @@ var SessionValidationService = /** @class */ (function () {
5676
5874
  throw new Error("agent-swarm session clientId=".concat(clientId, " not exist source=").concat(source));
5677
5875
  }
5678
5876
  return {};
5679
- };
5877
+ });
5680
5878
  /**
5681
5879
  * Removes a session.
5682
5880
  * @param {SessionId} clientId - The ID of the client.
@@ -5689,6 +5887,13 @@ var SessionValidationService = /** @class */ (function () {
5689
5887
  _this._sessionSwarmMap.delete(clientId);
5690
5888
  _this._sessionModeMap.delete(clientId);
5691
5889
  };
5890
+ /**
5891
+ * Dispose a session validation cache.
5892
+ * @param {SessionId} clientId - The ID of the client.
5893
+ */
5894
+ this.dispose = function (clientId) {
5895
+ _this.validate.clear(clientId);
5896
+ };
5692
5897
  }
5693
5898
  return SessionValidationService;
5694
5899
  }());
@@ -6314,23 +6519,8 @@ var StorageConnectionService = /** @class */ (function () {
6314
6519
  this.storageSchemaService = inject(TYPES.storageSchemaService);
6315
6520
  this.sessionValidationService = inject(TYPES.sessionValidationService);
6316
6521
  this.embeddingSchemaService = inject(TYPES.embeddingSchemaService);
6317
- /**
6318
- * Retrieves a shared storage instance based on storage name.
6319
- * @param {string} clientId - The client ID.
6320
- * @param {string} storageName - The storage name.
6321
- * @returns {ClientStorage} The client storage instance.
6322
- */
6323
- this.getSharedStorage = functoolsKit.memoize(function (_a) {
6324
- var _b = __read(_a, 2), storageName = _b[1];
6325
- return "".concat(storageName);
6326
- }, function (clientId, storageName) {
6327
- var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, shared = _a.shared, callbacks = _a.callbacks;
6328
- var _b = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _b.calculateSimilarity, createEmbedding = _b.createEmbedding, embedding = _b.callbacks;
6329
- if (!shared) {
6330
- throw new Error("agent-swarm storage not shared storageName=".concat(storageName));
6331
- }
6332
- return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService, bus: _this.busService }, embedding), { callbacks: callbacks }));
6333
- });
6522
+ this.sharedStorageConnectionService = inject(TYPES.sharedStorageConnectionService);
6523
+ this._sharedStorageSet = new Set();
6334
6524
  /**
6335
6525
  * Retrieves a storage instance based on client ID and storage name.
6336
6526
  * @param {string} clientId - The client ID.
@@ -6344,7 +6534,8 @@ var StorageConnectionService = /** @class */ (function () {
6344
6534
  _this.sessionValidationService.addStorageUsage(clientId, storageName);
6345
6535
  var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, _b = _a.shared, shared = _b === void 0 ? false : _b, callbacks = _a.callbacks;
6346
6536
  if (shared) {
6347
- return _this.getSharedStorage(clientId, storageName);
6537
+ _this._sharedStorageSet.add(storageName);
6538
+ return _this.sharedStorageConnectionService.getStorage(storageName);
6348
6539
  }
6349
6540
  var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
6350
6541
  return new ClientStorage(__assign(__assign({ clientId: clientId, storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService, bus: _this.busService }, embedding), { callbacks: callbacks }));
@@ -6500,8 +6691,8 @@ var StorageConnectionService = /** @class */ (function () {
6500
6691
  if (!this.getStorage.has(key)) {
6501
6692
  return [2 /*return*/];
6502
6693
  }
6503
- if (!!this.getSharedStorage.has(this.methodContextService.context.storageName)) return [3 /*break*/, 3];
6504
- storage = this.getSharedStorage(this.methodContextService.context.clientId, this.methodContextService.context.storageName);
6694
+ if (!!this._sharedStorageSet.has(this.methodContextService.context.storageName)) return [3 /*break*/, 3];
6695
+ storage = this.getStorage(this.methodContextService.context.clientId, this.methodContextService.context.storageName);
6505
6696
  return [4 /*yield*/, storage.waitForInit()];
6506
6697
  case 1:
6507
6698
  _a.sent();
@@ -7005,33 +7196,36 @@ var ClientState = /** @class */ (function () {
7005
7196
  var e_1, _c;
7006
7197
  return __generator(this, function (_d) {
7007
7198
  switch (_d.label) {
7008
- case 0:
7009
- _d.trys.push([0, 5, 6, 7]);
7010
- _a = __values(this.params.middlewares), _b = _a.next();
7011
- _d.label = 1;
7199
+ case 0: return [4 /*yield*/, dispatchFn(currentState)];
7012
7200
  case 1:
7013
- if (!!_b.done) return [3 /*break*/, 4];
7014
- middleware = _b.value;
7015
- return [4 /*yield*/, middleware(currentState, this.params.clientId, this.params.stateName)];
7016
- case 2:
7017
7201
  currentState = _d.sent();
7202
+ _d.label = 2;
7203
+ case 2:
7204
+ _d.trys.push([2, 7, 8, 9]);
7205
+ _a = __values(this.params.middlewares), _b = _a.next();
7018
7206
  _d.label = 3;
7019
7207
  case 3:
7020
- _b = _a.next();
7021
- return [3 /*break*/, 1];
7022
- case 4: return [3 /*break*/, 7];
7208
+ if (!!_b.done) return [3 /*break*/, 6];
7209
+ middleware = _b.value;
7210
+ return [4 /*yield*/, middleware(currentState, this.params.clientId, this.params.stateName)];
7211
+ case 4:
7212
+ currentState = _d.sent();
7213
+ _d.label = 5;
7023
7214
  case 5:
7215
+ _b = _a.next();
7216
+ return [3 /*break*/, 3];
7217
+ case 6: return [3 /*break*/, 9];
7218
+ case 7:
7024
7219
  e_1_1 = _d.sent();
7025
7220
  e_1 = { error: e_1_1 };
7026
- return [3 /*break*/, 7];
7027
- case 6:
7221
+ return [3 /*break*/, 9];
7222
+ case 8:
7028
7223
  try {
7029
7224
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
7030
7225
  }
7031
7226
  finally { if (e_1) throw e_1.error; }
7032
7227
  return [7 /*endfinally*/];
7033
- case 7: return [4 /*yield*/, dispatchFn(currentState)];
7034
- case 8: return [2 /*return*/, _d.sent()];
7228
+ case 9: return [2 /*return*/, currentState];
7035
7229
  }
7036
7230
  });
7037
7231
  }); })];
@@ -7136,45 +7330,8 @@ var StateConnectionService = /** @class */ (function () {
7136
7330
  this.methodContextService = inject(TYPES.methodContextService);
7137
7331
  this.stateSchemaService = inject(TYPES.stateSchemaService);
7138
7332
  this.sessionValidationService = inject(TYPES.sessionValidationService);
7139
- /**
7140
- * Memoized function to get a shared state reference.
7141
- * @param {string} clientId - The client ID.
7142
- * @param {StateName} stateName - The state name.
7143
- * @returns {ClientState} The client state.
7144
- */
7145
- this.getSharedStateRef = functoolsKit.memoize(function (_a) {
7146
- var _b = __read(_a, 2), stateName = _b[1];
7147
- return "".concat(stateName);
7148
- }, function (clientId, stateName) {
7149
- _this.sessionValidationService.addStateUsage(clientId, stateName);
7150
- var _a = _this.stateSchemaService.get(stateName), getState = _a.getState, setState = _a.setState, _b = _a.middlewares, middlewares = _b === void 0 ? [] : _b, shared = _a.shared, callbacks = _a.callbacks;
7151
- if (!shared) {
7152
- throw new Error("agent-swarm state not shared stateName=".concat(stateName));
7153
- }
7154
- return new ClientState({
7155
- clientId: clientId,
7156
- stateName: stateName,
7157
- logger: _this.loggerService,
7158
- bus: _this.busService,
7159
- setState: setState
7160
- ? functoolsKit.queued(function () {
7161
- var args = [];
7162
- for (var _i = 0; _i < arguments.length; _i++) {
7163
- args[_i] = arguments[_i];
7164
- }
7165
- return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
7166
- switch (_a.label) {
7167
- case 0: return [4 /*yield*/, setState.apply(void 0, __spreadArray([], __read(args), false))];
7168
- case 1: return [2 /*return*/, _a.sent()];
7169
- }
7170
- }); });
7171
- })
7172
- : setState,
7173
- getState: getState,
7174
- middlewares: middlewares,
7175
- callbacks: callbacks,
7176
- });
7177
- });
7333
+ this.sharedStateConnectionService = inject(TYPES.sharedStateConnectionService);
7334
+ this._sharedStateSet = new Set();
7178
7335
  /**
7179
7336
  * Memoized function to get a state reference.
7180
7337
  * @param {string} clientId - The client ID.
@@ -7188,7 +7345,8 @@ var StateConnectionService = /** @class */ (function () {
7188
7345
  _this.sessionValidationService.addStateUsage(clientId, stateName);
7189
7346
  var _a = _this.stateSchemaService.get(stateName), getState = _a.getState, setState = _a.setState, _b = _a.middlewares, middlewares = _b === void 0 ? [] : _b, callbacks = _a.callbacks, _c = _a.shared, shared = _c === void 0 ? false : _c;
7190
7347
  if (shared) {
7191
- return _this.getSharedStateRef(clientId, stateName);
7348
+ _this._sharedStateSet.add(stateName);
7349
+ return _this.sharedStateConnectionService.getStateRef(stateName);
7192
7350
  }
7193
7351
  return new ClientState({
7194
7352
  clientId: clientId,
@@ -7270,7 +7428,7 @@ var StateConnectionService = /** @class */ (function () {
7270
7428
  if (!this.getStateRef.has(key)) {
7271
7429
  return [2 /*return*/];
7272
7430
  }
7273
- if (!!this.getSharedStateRef.has(this.methodContextService.context.stateName)) return [3 /*break*/, 3];
7431
+ if (!!this._sharedStateSet.has(this.methodContextService.context.stateName)) return [3 /*break*/, 3];
7274
7432
  state = this.getStateRef(this.methodContextService.context.clientId, this.methodContextService.context.stateName);
7275
7433
  return [4 /*yield*/, state.waitForInit()];
7276
7434
  case 1:
@@ -8130,30 +8288,593 @@ var DocService = /** @class */ (function () {
8130
8288
  return DocService;
8131
8289
  }());
8132
8290
 
8133
- {
8134
- provide(TYPES.docService, function () { return new DocService(); });
8135
- provide(TYPES.busService, function () { return new BusService(); });
8136
- provide(TYPES.loggerService, function () { return new LoggerService(); });
8137
- }
8138
- {
8139
- provide(TYPES.methodContextService, function () { return new MethodContextService(); });
8140
- provide(TYPES.executionContextService, function () { return new ExecutionContextService(); });
8141
- }
8142
- {
8143
- provide(TYPES.agentConnectionService, function () { return new AgentConnectionService(); });
8144
- provide(TYPES.historyConnectionService, function () { return new HistoryConnectionService(); });
8145
- provide(TYPES.swarmConnectionService, function () { return new SwarmConnectionService(); });
8146
- provide(TYPES.sessionConnectionService, function () { return new SessionConnectionService(); });
8147
- provide(TYPES.storageConnectionService, function () { return new StorageConnectionService(); });
8148
- provide(TYPES.stateConnectionService, function () { return new StateConnectionService(); });
8149
- }
8150
- {
8151
- provide(TYPES.agentSchemaService, function () { return new AgentSchemaService(); });
8152
- provide(TYPES.toolSchemaService, function () { return new ToolSchemaService(); });
8153
- provide(TYPES.swarmSchemaService, function () { return new SwarmSchemaService(); });
8154
- provide(TYPES.completionSchemaService, function () { return new CompletionSchemaService(); });
8155
- provide(TYPES.embeddingSchemaService, function () { return new EmbeddingSchemaService(); });
8156
- provide(TYPES.storageSchemaService, function () { return new StorageSchemaService(); });
8291
+ /**
8292
+ * Service for managing shared state connections.
8293
+ * @template T - The type of state data.
8294
+ * @implements {IState<T>}
8295
+ */
8296
+ var SharedStateConnectionService = /** @class */ (function () {
8297
+ function SharedStateConnectionService() {
8298
+ var _this = this;
8299
+ this.loggerService = inject(TYPES.loggerService);
8300
+ this.busService = inject(TYPES.busService);
8301
+ this.methodContextService = inject(TYPES.methodContextService);
8302
+ this.stateSchemaService = inject(TYPES.stateSchemaService);
8303
+ /**
8304
+ * Memoized function to get a shared state reference.
8305
+ * @param {string} clientId - The client ID.
8306
+ * @param {StateName} stateName - The state name.
8307
+ * @returns {ClientState} The client state.
8308
+ */
8309
+ this.getStateRef = functoolsKit.memoize(function (_a) {
8310
+ var _b = __read(_a, 1), stateName = _b[0];
8311
+ return "".concat(stateName);
8312
+ }, function (stateName) {
8313
+ var _a = _this.stateSchemaService.get(stateName), getState = _a.getState, setState = _a.setState, _b = _a.middlewares, middlewares = _b === void 0 ? [] : _b, shared = _a.shared, callbacks = _a.callbacks;
8314
+ if (!shared) {
8315
+ throw new Error("agent-swarm state not shared stateName=".concat(stateName));
8316
+ }
8317
+ return new ClientState({
8318
+ clientId: "*",
8319
+ stateName: stateName,
8320
+ logger: _this.loggerService,
8321
+ bus: _this.busService,
8322
+ setState: setState
8323
+ ? functoolsKit.queued(function () {
8324
+ var args = [];
8325
+ for (var _i = 0; _i < arguments.length; _i++) {
8326
+ args[_i] = arguments[_i];
8327
+ }
8328
+ return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
8329
+ switch (_a.label) {
8330
+ case 0: return [4 /*yield*/, setState.apply(void 0, __spreadArray([], __read(args), false))];
8331
+ case 1: return [2 /*return*/, _a.sent()];
8332
+ }
8333
+ }); });
8334
+ })
8335
+ : setState,
8336
+ getState: getState,
8337
+ middlewares: middlewares,
8338
+ callbacks: callbacks,
8339
+ });
8340
+ });
8341
+ /**
8342
+ * Sets the state.
8343
+ * @param {function(T): Promise<T>} dispatchFn - The function to dispatch the new state.
8344
+ * @returns {Promise<T>} The new state.
8345
+ */
8346
+ this.setState = function (dispatchFn) { return __awaiter(_this, void 0, void 0, function () {
8347
+ var state;
8348
+ return __generator(this, function (_a) {
8349
+ switch (_a.label) {
8350
+ case 0:
8351
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8352
+ this.loggerService.info("sharedStateConnectionService setState");
8353
+ state = this.getStateRef(this.methodContextService.context.stateName);
8354
+ return [4 /*yield*/, state.waitForInit()];
8355
+ case 1:
8356
+ _a.sent();
8357
+ return [4 /*yield*/, state.setState(dispatchFn)];
8358
+ case 2: return [2 /*return*/, _a.sent()];
8359
+ }
8360
+ });
8361
+ }); };
8362
+ /**
8363
+ * Gets the state.
8364
+ * @returns {Promise<T>} The current state.
8365
+ */
8366
+ this.getState = function () { return __awaiter(_this, void 0, void 0, function () {
8367
+ var state;
8368
+ return __generator(this, function (_a) {
8369
+ switch (_a.label) {
8370
+ case 0:
8371
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8372
+ this.loggerService.info("sharedStateConnectionService getState");
8373
+ state = this.getStateRef(this.methodContextService.context.stateName);
8374
+ return [4 /*yield*/, state.waitForInit()];
8375
+ case 1:
8376
+ _a.sent();
8377
+ return [4 /*yield*/, state.getState()];
8378
+ case 2: return [2 /*return*/, _a.sent()];
8379
+ }
8380
+ });
8381
+ }); };
8382
+ }
8383
+ return SharedStateConnectionService;
8384
+ }());
8385
+
8386
+ /**
8387
+ * Service for managing storage connections.
8388
+ * @implements {IStorage}
8389
+ */
8390
+ var SharedStorageConnectionService = /** @class */ (function () {
8391
+ function SharedStorageConnectionService() {
8392
+ var _this = this;
8393
+ this.loggerService = inject(TYPES.loggerService);
8394
+ this.busService = inject(TYPES.busService);
8395
+ this.methodContextService = inject(TYPES.methodContextService);
8396
+ this.storageSchemaService = inject(TYPES.storageSchemaService);
8397
+ this.embeddingSchemaService = inject(TYPES.embeddingSchemaService);
8398
+ /**
8399
+ * Retrieves a storage instance based on client ID and storage name.
8400
+ * @param {string} clientId - The client ID.
8401
+ * @param {string} storageName - The storage name.
8402
+ * @returns {ClientStorage} The client storage instance.
8403
+ */
8404
+ this.getStorage = functoolsKit.memoize(function (_a) {
8405
+ var _b = __read(_a, 1), storageName = _b[0];
8406
+ return "".concat(storageName);
8407
+ }, function (storageName) {
8408
+ var _a = _this.storageSchemaService.get(storageName), createIndex = _a.createIndex, getData = _a.getData, embeddingName = _a.embedding, _b = _a.shared, shared = _b === void 0 ? false : _b, callbacks = _a.callbacks;
8409
+ if (!shared) {
8410
+ throw new Error("agent-swarm storage not shared storageName=".concat(storageName));
8411
+ }
8412
+ var _c = _this.embeddingSchemaService.get(embeddingName), calculateSimilarity = _c.calculateSimilarity, createEmbedding = _c.createEmbedding, embedding = _c.callbacks;
8413
+ return new ClientStorage(__assign(__assign({ clientId: "*", storageName: storageName, embedding: embeddingName, calculateSimilarity: calculateSimilarity, createEmbedding: createEmbedding, createIndex: createIndex, getData: getData, shared: shared, logger: _this.loggerService, bus: _this.busService }, embedding), { callbacks: callbacks }));
8414
+ });
8415
+ /**
8416
+ * Retrieves a list of storage data based on a search query and total number of items.
8417
+ * @param {string} search - The search query.
8418
+ * @param {number} total - The total number of items to retrieve.
8419
+ * @returns {Promise<IStorageData[]>} The list of storage data.
8420
+ */
8421
+ this.take = function (search, total, score) { return __awaiter(_this, void 0, void 0, function () {
8422
+ var storage;
8423
+ return __generator(this, function (_a) {
8424
+ switch (_a.label) {
8425
+ case 0:
8426
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8427
+ this.loggerService.info("sharedStorageConnectionService take", {
8428
+ search: search,
8429
+ total: total,
8430
+ score: score,
8431
+ });
8432
+ storage = this.getStorage(this.methodContextService.context.storageName);
8433
+ return [4 /*yield*/, storage.waitForInit()];
8434
+ case 1:
8435
+ _a.sent();
8436
+ return [4 /*yield*/, storage.take(search, total, score)];
8437
+ case 2: return [2 /*return*/, _a.sent()];
8438
+ }
8439
+ });
8440
+ }); };
8441
+ /**
8442
+ * Upserts an item in the storage.
8443
+ * @param {IStorageData} item - The item to upsert.
8444
+ * @returns {Promise<void>}
8445
+ */
8446
+ this.upsert = function (item) { return __awaiter(_this, void 0, void 0, function () {
8447
+ var storage;
8448
+ return __generator(this, function (_a) {
8449
+ switch (_a.label) {
8450
+ case 0:
8451
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8452
+ this.loggerService.info("sharedStorageConnectionService upsert", {
8453
+ item: item,
8454
+ });
8455
+ storage = this.getStorage(this.methodContextService.context.storageName);
8456
+ return [4 /*yield*/, storage.waitForInit()];
8457
+ case 1:
8458
+ _a.sent();
8459
+ return [4 /*yield*/, storage.upsert(item)];
8460
+ case 2: return [2 /*return*/, _a.sent()];
8461
+ }
8462
+ });
8463
+ }); };
8464
+ /**
8465
+ * Removes an item from the storage.
8466
+ * @param {IStorageData["id"]} itemId - The ID of the item to remove.
8467
+ * @returns {Promise<void>}
8468
+ */
8469
+ this.remove = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
8470
+ var storage;
8471
+ return __generator(this, function (_a) {
8472
+ switch (_a.label) {
8473
+ case 0:
8474
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8475
+ this.loggerService.info("sharedStorageConnectionService remove", {
8476
+ itemId: itemId,
8477
+ });
8478
+ storage = this.getStorage(this.methodContextService.context.storageName);
8479
+ return [4 /*yield*/, storage.waitForInit()];
8480
+ case 1:
8481
+ _a.sent();
8482
+ return [4 /*yield*/, storage.remove(itemId)];
8483
+ case 2: return [2 /*return*/, _a.sent()];
8484
+ }
8485
+ });
8486
+ }); };
8487
+ /**
8488
+ * Retrieves an item from the storage by its ID.
8489
+ * @param {IStorageData["id"]} itemId - The ID of the item to retrieve.
8490
+ * @returns {Promise<IStorageData>} The retrieved item.
8491
+ */
8492
+ this.get = function (itemId) { return __awaiter(_this, void 0, void 0, function () {
8493
+ var storage;
8494
+ return __generator(this, function (_a) {
8495
+ switch (_a.label) {
8496
+ case 0:
8497
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8498
+ this.loggerService.info("sharedStorageConnectionService get", {
8499
+ itemId: itemId,
8500
+ });
8501
+ storage = this.getStorage(this.methodContextService.context.storageName);
8502
+ return [4 /*yield*/, storage.waitForInit()];
8503
+ case 1:
8504
+ _a.sent();
8505
+ return [4 /*yield*/, storage.get(itemId)];
8506
+ case 2: return [2 /*return*/, _a.sent()];
8507
+ }
8508
+ });
8509
+ }); };
8510
+ /**
8511
+ * Retrieves a list of items from the storage, optionally filtered by a predicate function.
8512
+ * @param {function(IStorageData): boolean} [filter] - The optional filter function.
8513
+ * @returns {Promise<IStorageData[]>} The list of items.
8514
+ */
8515
+ this.list = function (filter) { return __awaiter(_this, void 0, void 0, function () {
8516
+ var storage;
8517
+ return __generator(this, function (_a) {
8518
+ switch (_a.label) {
8519
+ case 0:
8520
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8521
+ this.loggerService.info("sharedStorageConnectionService list");
8522
+ storage = this.getStorage(this.methodContextService.context.storageName);
8523
+ return [4 /*yield*/, storage.waitForInit()];
8524
+ case 1:
8525
+ _a.sent();
8526
+ return [4 /*yield*/, storage.list(filter)];
8527
+ case 2: return [2 /*return*/, _a.sent()];
8528
+ }
8529
+ });
8530
+ }); };
8531
+ /**
8532
+ * Clears all items from the storage.
8533
+ * @returns {Promise<void>}
8534
+ */
8535
+ this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
8536
+ var storage;
8537
+ return __generator(this, function (_a) {
8538
+ switch (_a.label) {
8539
+ case 0:
8540
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8541
+ this.loggerService.info("sharedStorageConnectionService clear");
8542
+ storage = this.getStorage(this.methodContextService.context.storageName);
8543
+ return [4 /*yield*/, storage.waitForInit()];
8544
+ case 1:
8545
+ _a.sent();
8546
+ return [4 /*yield*/, storage.clear()];
8547
+ case 2: return [2 /*return*/, _a.sent()];
8548
+ }
8549
+ });
8550
+ }); };
8551
+ }
8552
+ return SharedStorageConnectionService;
8553
+ }());
8554
+
8555
+ var SharedStatePublicService = /** @class */ (function () {
8556
+ function SharedStatePublicService() {
8557
+ var _this = this;
8558
+ this.loggerService = inject(TYPES.loggerService);
8559
+ this.sharedStateConnectionService = inject(TYPES.sharedStateConnectionService);
8560
+ /**
8561
+ * Sets the state using the provided dispatch function.
8562
+ * @param {function(T): Promise<T>} dispatchFn - The function to dispatch the state change.
8563
+ * @param {StateName} stateName - The name of the state.
8564
+ * @returns {Promise<T>} - The updated state.
8565
+ */
8566
+ this.setState = function (dispatchFn, methodName, stateName) { return __awaiter(_this, void 0, void 0, function () {
8567
+ var _this = this;
8568
+ return __generator(this, function (_a) {
8569
+ switch (_a.label) {
8570
+ case 0:
8571
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8572
+ this.loggerService.info("sharedStatePublicService setState", {
8573
+ methodName: methodName,
8574
+ stateName: stateName,
8575
+ });
8576
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8577
+ return __generator(this, function (_a) {
8578
+ switch (_a.label) {
8579
+ case 0: return [4 /*yield*/, this.sharedStateConnectionService.setState(dispatchFn)];
8580
+ case 1: return [2 /*return*/, _a.sent()];
8581
+ }
8582
+ });
8583
+ }); }, {
8584
+ methodName: methodName,
8585
+ clientId: "",
8586
+ stateName: stateName,
8587
+ agentName: "",
8588
+ swarmName: "",
8589
+ storageName: "",
8590
+ })];
8591
+ case 1: return [2 /*return*/, _a.sent()];
8592
+ }
8593
+ });
8594
+ }); };
8595
+ /**
8596
+ * Gets the current state.
8597
+ * @param {StateName} stateName - The name of the state.
8598
+ * @returns {Promise<T>} - The current state.
8599
+ */
8600
+ this.getState = function (methodName, stateName) { return __awaiter(_this, void 0, void 0, function () {
8601
+ var _this = this;
8602
+ return __generator(this, function (_a) {
8603
+ switch (_a.label) {
8604
+ case 0:
8605
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8606
+ this.loggerService.info("sharedStatePublicService getState", {
8607
+ stateName: stateName,
8608
+ });
8609
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8610
+ return __generator(this, function (_a) {
8611
+ switch (_a.label) {
8612
+ case 0: return [4 /*yield*/, this.sharedStateConnectionService.getState()];
8613
+ case 1: return [2 /*return*/, _a.sent()];
8614
+ }
8615
+ });
8616
+ }); }, {
8617
+ methodName: methodName,
8618
+ clientId: "",
8619
+ stateName: stateName,
8620
+ agentName: "",
8621
+ swarmName: "",
8622
+ storageName: "",
8623
+ })];
8624
+ case 1: return [2 /*return*/, _a.sent()];
8625
+ }
8626
+ });
8627
+ }); };
8628
+ }
8629
+ return SharedStatePublicService;
8630
+ }());
8631
+
8632
+ /**
8633
+ * Service for managing public storage interactions.
8634
+ */
8635
+ var SharedStoragePublicService = /** @class */ (function () {
8636
+ function SharedStoragePublicService() {
8637
+ var _this = this;
8638
+ this.loggerService = inject(TYPES.loggerService);
8639
+ this.sharedStorageConnectionService = inject(TYPES.sharedStorageConnectionService);
8640
+ /**
8641
+ * Retrieves a list of storage data based on a search query and total number of items.
8642
+ * @param {string} search - The search query.
8643
+ * @param {number} total - The total number of items to retrieve.
8644
+ * @returns {Promise<IStorageData[]>} The list of storage data.
8645
+ */
8646
+ this.take = function (search, total, methodName, storageName, score) { return __awaiter(_this, void 0, void 0, function () {
8647
+ var _this = this;
8648
+ return __generator(this, function (_a) {
8649
+ switch (_a.label) {
8650
+ case 0:
8651
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8652
+ this.loggerService.info("sharedStoragePublicService take", {
8653
+ methodName: methodName,
8654
+ search: search,
8655
+ total: total,
8656
+ storageName: storageName,
8657
+ score: score,
8658
+ });
8659
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8660
+ return __generator(this, function (_a) {
8661
+ switch (_a.label) {
8662
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.take(search, total, score)];
8663
+ case 1: return [2 /*return*/, _a.sent()];
8664
+ }
8665
+ });
8666
+ }); }, {
8667
+ methodName: methodName,
8668
+ clientId: "",
8669
+ storageName: storageName,
8670
+ agentName: "",
8671
+ swarmName: "",
8672
+ stateName: "",
8673
+ })];
8674
+ case 1: return [2 /*return*/, _a.sent()];
8675
+ }
8676
+ });
8677
+ }); };
8678
+ /**
8679
+ * Upserts an item in the storage.
8680
+ * @param {IStorageData} item - The item to upsert.
8681
+ * @returns {Promise<void>}
8682
+ */
8683
+ this.upsert = function (item, methodName, storageName) { return __awaiter(_this, void 0, void 0, function () {
8684
+ var _this = this;
8685
+ return __generator(this, function (_a) {
8686
+ switch (_a.label) {
8687
+ case 0:
8688
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8689
+ this.loggerService.info("sharedStoragePublicService upsert", {
8690
+ item: item,
8691
+ storageName: storageName,
8692
+ });
8693
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8694
+ return __generator(this, function (_a) {
8695
+ switch (_a.label) {
8696
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.upsert(item)];
8697
+ case 1: return [2 /*return*/, _a.sent()];
8698
+ }
8699
+ });
8700
+ }); }, {
8701
+ methodName: methodName,
8702
+ clientId: "",
8703
+ storageName: storageName,
8704
+ agentName: "",
8705
+ swarmName: "",
8706
+ stateName: "",
8707
+ })];
8708
+ case 1: return [2 /*return*/, _a.sent()];
8709
+ }
8710
+ });
8711
+ }); };
8712
+ /**
8713
+ * Removes an item from the storage.
8714
+ * @param {IStorageData["id"]} itemId - The ID of the item to remove.
8715
+ * @returns {Promise<void>}
8716
+ */
8717
+ this.remove = function (itemId, methodName, storageName) { return __awaiter(_this, void 0, void 0, function () {
8718
+ var _this = this;
8719
+ return __generator(this, function (_a) {
8720
+ switch (_a.label) {
8721
+ case 0:
8722
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8723
+ this.loggerService.info("sharedStoragePublicService remove", {
8724
+ itemId: itemId,
8725
+ storageName: storageName,
8726
+ });
8727
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8728
+ return __generator(this, function (_a) {
8729
+ switch (_a.label) {
8730
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.remove(itemId)];
8731
+ case 1: return [2 /*return*/, _a.sent()];
8732
+ }
8733
+ });
8734
+ }); }, {
8735
+ methodName: methodName,
8736
+ clientId: "",
8737
+ storageName: storageName,
8738
+ agentName: "",
8739
+ swarmName: "",
8740
+ stateName: "",
8741
+ })];
8742
+ case 1: return [2 /*return*/, _a.sent()];
8743
+ }
8744
+ });
8745
+ }); };
8746
+ /**
8747
+ * Retrieves an item from the storage by its ID.
8748
+ * @param {IStorageData["id"]} itemId - The ID of the item to retrieve.
8749
+ * @returns {Promise<IStorageData>} The retrieved item.
8750
+ */
8751
+ this.get = function (itemId, methodName, storageName) { return __awaiter(_this, void 0, void 0, function () {
8752
+ var _this = this;
8753
+ return __generator(this, function (_a) {
8754
+ switch (_a.label) {
8755
+ case 0:
8756
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8757
+ this.loggerService.info("sharedStoragePublicService get", {
8758
+ methodName: methodName,
8759
+ itemId: itemId,
8760
+ storageName: storageName,
8761
+ });
8762
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8763
+ return __generator(this, function (_a) {
8764
+ switch (_a.label) {
8765
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.get(itemId)];
8766
+ case 1: return [2 /*return*/, _a.sent()];
8767
+ }
8768
+ });
8769
+ }); }, {
8770
+ methodName: methodName,
8771
+ clientId: "",
8772
+ storageName: storageName,
8773
+ agentName: "",
8774
+ swarmName: "",
8775
+ stateName: "",
8776
+ })];
8777
+ case 1: return [2 /*return*/, _a.sent()];
8778
+ }
8779
+ });
8780
+ }); };
8781
+ /**
8782
+ * Retrieves a list of items from the storage, optionally filtered by a predicate function.
8783
+ * @param {function(IStorageData): boolean} [filter] - The optional filter function.
8784
+ * @returns {Promise<IStorageData[]>} The list of items.
8785
+ */
8786
+ this.list = function (methodName, storageName, filter) { return __awaiter(_this, void 0, void 0, function () {
8787
+ var _this = this;
8788
+ return __generator(this, function (_a) {
8789
+ switch (_a.label) {
8790
+ case 0:
8791
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8792
+ this.loggerService.info("sharedStoragePublicService list", {
8793
+ methodName: methodName,
8794
+ storageName: storageName,
8795
+ });
8796
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8797
+ return __generator(this, function (_a) {
8798
+ switch (_a.label) {
8799
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.list(filter)];
8800
+ case 1: return [2 /*return*/, _a.sent()];
8801
+ }
8802
+ });
8803
+ }); }, {
8804
+ methodName: methodName,
8805
+ clientId: "",
8806
+ storageName: storageName,
8807
+ agentName: "",
8808
+ swarmName: "",
8809
+ stateName: "",
8810
+ })];
8811
+ case 1: return [2 /*return*/, _a.sent()];
8812
+ }
8813
+ });
8814
+ }); };
8815
+ /**
8816
+ * Clears all items from the storage.
8817
+ * @returns {Promise<void>}
8818
+ */
8819
+ this.clear = function (methodName, storageName) { return __awaiter(_this, void 0, void 0, function () {
8820
+ var _this = this;
8821
+ return __generator(this, function (_a) {
8822
+ switch (_a.label) {
8823
+ case 0:
8824
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8825
+ this.loggerService.info("sharedStoragePublicService clear", {
8826
+ methodName: methodName,
8827
+ storageName: storageName,
8828
+ });
8829
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8830
+ return __generator(this, function (_a) {
8831
+ switch (_a.label) {
8832
+ case 0: return [4 /*yield*/, this.sharedStorageConnectionService.clear()];
8833
+ case 1: return [2 /*return*/, _a.sent()];
8834
+ }
8835
+ });
8836
+ }); }, {
8837
+ methodName: methodName,
8838
+ clientId: "",
8839
+ storageName: storageName,
8840
+ agentName: "",
8841
+ swarmName: "",
8842
+ stateName: "",
8843
+ })];
8844
+ case 1: return [2 /*return*/, _a.sent()];
8845
+ }
8846
+ });
8847
+ }); };
8848
+ }
8849
+ return SharedStoragePublicService;
8850
+ }());
8851
+
8852
+ {
8853
+ provide(TYPES.docService, function () { return new DocService(); });
8854
+ provide(TYPES.busService, function () { return new BusService(); });
8855
+ provide(TYPES.loggerService, function () { return new LoggerService(); });
8856
+ }
8857
+ {
8858
+ provide(TYPES.methodContextService, function () { return new MethodContextService(); });
8859
+ provide(TYPES.executionContextService, function () { return new ExecutionContextService(); });
8860
+ }
8861
+ {
8862
+ provide(TYPES.agentConnectionService, function () { return new AgentConnectionService(); });
8863
+ provide(TYPES.historyConnectionService, function () { return new HistoryConnectionService(); });
8864
+ provide(TYPES.swarmConnectionService, function () { return new SwarmConnectionService(); });
8865
+ provide(TYPES.sessionConnectionService, function () { return new SessionConnectionService(); });
8866
+ provide(TYPES.storageConnectionService, function () { return new StorageConnectionService(); });
8867
+ provide(TYPES.sharedStorageConnectionService, function () { return new SharedStorageConnectionService(); });
8868
+ provide(TYPES.stateConnectionService, function () { return new StateConnectionService(); });
8869
+ provide(TYPES.sharedStateConnectionService, function () { return new SharedStateConnectionService(); });
8870
+ }
8871
+ {
8872
+ provide(TYPES.agentSchemaService, function () { return new AgentSchemaService(); });
8873
+ provide(TYPES.toolSchemaService, function () { return new ToolSchemaService(); });
8874
+ provide(TYPES.swarmSchemaService, function () { return new SwarmSchemaService(); });
8875
+ provide(TYPES.completionSchemaService, function () { return new CompletionSchemaService(); });
8876
+ provide(TYPES.embeddingSchemaService, function () { return new EmbeddingSchemaService(); });
8877
+ provide(TYPES.storageSchemaService, function () { return new StorageSchemaService(); });
8157
8878
  provide(TYPES.stateSchemaService, function () { return new StateSchemaService(); });
8158
8879
  }
8159
8880
  {
@@ -8162,7 +8883,9 @@ var DocService = /** @class */ (function () {
8162
8883
  provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
8163
8884
  provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
8164
8885
  provide(TYPES.storagePublicService, function () { return new StoragePublicService(); });
8886
+ provide(TYPES.sharedStoragePublicService, function () { return new SharedStoragePublicService(); });
8165
8887
  provide(TYPES.statePublicService, function () { return new StatePublicService(); });
8888
+ provide(TYPES.sharedStatePublicService, function () { return new SharedStatePublicService(); });
8166
8889
  }
8167
8890
  {
8168
8891
  provide(TYPES.swarmMetaService, function () { return new SwarmMetaService(); });
@@ -8199,7 +8922,9 @@ var connectionServices = {
8199
8922
  swarmConnectionService: inject(TYPES.swarmConnectionService),
8200
8923
  sessionConnectionService: inject(TYPES.sessionConnectionService),
8201
8924
  storageConnectionService: inject(TYPES.storageConnectionService),
8925
+ sharedStorageConnectionService: inject(TYPES.sharedStorageConnectionService),
8202
8926
  stateConnectionService: inject(TYPES.stateConnectionService),
8927
+ sharedStateConnectionService: inject(TYPES.sharedStateConnectionService),
8203
8928
  };
8204
8929
  var schemaServices = {
8205
8930
  agentSchemaService: inject(TYPES.agentSchemaService),
@@ -8216,7 +8941,9 @@ var publicServices = {
8216
8941
  sessionPublicService: inject(TYPES.sessionPublicService),
8217
8942
  swarmPublicService: inject(TYPES.swarmPublicService),
8218
8943
  storagePublicService: inject(TYPES.storagePublicService),
8944
+ sharedStoragePublicService: inject(TYPES.sharedStoragePublicService),
8219
8945
  statePublicService: inject(TYPES.statePublicService),
8946
+ sharedStatePublicService: inject(TYPES.sharedStatePublicService),
8220
8947
  };
8221
8948
  var metaServices = {
8222
8949
  agentMetaService: inject(TYPES.agentMetaService),
@@ -8235,7 +8962,7 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
8235
8962
  init();
8236
8963
  var swarm$1 = swarm;
8237
8964
 
8238
- var METHOD_NAME$H = "cli.dumpDocs";
8965
+ var METHOD_NAME$J = "cli.dumpDocs";
8239
8966
  /**
8240
8967
  * Dumps the documentation for the agents and swarms.
8241
8968
  *
@@ -8246,7 +8973,7 @@ var METHOD_NAME$H = "cli.dumpDocs";
8246
8973
  var dumpDocs = function (dirName, PlantUML) {
8247
8974
  if (dirName === void 0) { dirName = "./docs/chat"; }
8248
8975
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8249
- swarm$1.loggerService.log(METHOD_NAME$H, {
8976
+ swarm$1.loggerService.log(METHOD_NAME$J, {
8250
8977
  dirName: dirName,
8251
8978
  });
8252
8979
  if (PlantUML) {
@@ -8257,12 +8984,12 @@ var dumpDocs = function (dirName, PlantUML) {
8257
8984
  swarm$1.agentValidationService
8258
8985
  .getAgentList()
8259
8986
  .forEach(function (agentName) {
8260
- return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$H);
8987
+ return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
8261
8988
  });
8262
8989
  swarm$1.swarmValidationService
8263
8990
  .getSwarmList()
8264
8991
  .forEach(function (swarmName) {
8265
- return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
8992
+ return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
8266
8993
  });
8267
8994
  swarm$1.agentValidationService.getAgentList().forEach(function (agentName) {
8268
8995
  var dependsOn = swarm$1.agentSchemaService.get(agentName).dependsOn;
@@ -8273,7 +9000,7 @@ var dumpDocs = function (dirName, PlantUML) {
8273
9000
  return swarm$1.docService.dumpDocs(dirName);
8274
9001
  };
8275
9002
 
8276
- var METHOD_NAME$G = "cli.dumpAgent";
9003
+ var METHOD_NAME$I = "cli.dumpAgent";
8277
9004
  /**
8278
9005
  * Dumps the agent information into PlantUML format.
8279
9006
  *
@@ -8283,14 +9010,14 @@ var METHOD_NAME$G = "cli.dumpAgent";
8283
9010
  var dumpAgent = function (agentName, _a) {
8284
9011
  var _b = _a === void 0 ? {} : _a, _c = _b.withSubtree, withSubtree = _c === void 0 ? false : _c;
8285
9012
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8286
- swarm$1.loggerService.log(METHOD_NAME$G, {
9013
+ swarm$1.loggerService.log(METHOD_NAME$I, {
8287
9014
  agentName: agentName,
8288
9015
  });
8289
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$G);
9016
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$I);
8290
9017
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
8291
9018
  };
8292
9019
 
8293
- var METHOD_NAME$F = "cli.dumpSwarm";
9020
+ var METHOD_NAME$H = "cli.dumpSwarm";
8294
9021
  /**
8295
9022
  * Dumps the swarm information into PlantUML format.
8296
9023
  *
@@ -8299,14 +9026,14 @@ var METHOD_NAME$F = "cli.dumpSwarm";
8299
9026
  */
8300
9027
  var dumpSwarm = function (swarmName) {
8301
9028
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8302
- swarm$1.loggerService.log(METHOD_NAME$F, {
9029
+ swarm$1.loggerService.log(METHOD_NAME$H, {
8303
9030
  swarmName: swarmName,
8304
9031
  });
8305
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$F);
9032
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
8306
9033
  return swarm$1.swarmMetaService.toUML(swarmName);
8307
9034
  };
8308
9035
 
8309
- var METHOD_NAME$E = "function.addAgent";
9036
+ var METHOD_NAME$G = "function.addAgent";
8310
9037
  /**
8311
9038
  * Adds a new agent to the agent registry. The swarm takes only those agents which was registered
8312
9039
  *
@@ -8315,7 +9042,7 @@ var METHOD_NAME$E = "function.addAgent";
8315
9042
  */
8316
9043
  var addAgent = function (agentSchema) {
8317
9044
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8318
- swarm$1.loggerService.log(METHOD_NAME$E, {
9045
+ swarm$1.loggerService.log(METHOD_NAME$G, {
8319
9046
  agentSchema: agentSchema,
8320
9047
  });
8321
9048
  swarm$1.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
@@ -8323,7 +9050,7 @@ var addAgent = function (agentSchema) {
8323
9050
  return agentSchema.agentName;
8324
9051
  };
8325
9052
 
8326
- var METHOD_NAME$D = "function.addCompletion";
9053
+ var METHOD_NAME$F = "function.addCompletion";
8327
9054
  /**
8328
9055
  * Adds a completion engine for agents. Agents could use different models and
8329
9056
  * framewords for completion like: mock, gpt4all, ollama, openai
@@ -8333,7 +9060,7 @@ var METHOD_NAME$D = "function.addCompletion";
8333
9060
  */
8334
9061
  var addCompletion = function (completionSchema) {
8335
9062
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8336
- swarm$1.loggerService.log(METHOD_NAME$D, {
9063
+ swarm$1.loggerService.log(METHOD_NAME$F, {
8337
9064
  completionSchema: completionSchema,
8338
9065
  });
8339
9066
  swarm$1.completionValidationService.addCompletion(completionSchema.completionName);
@@ -8341,7 +9068,7 @@ var addCompletion = function (completionSchema) {
8341
9068
  return completionSchema.completionName;
8342
9069
  };
8343
9070
 
8344
- var METHOD_NAME$C = "function.addSwarm";
9071
+ var METHOD_NAME$E = "function.addSwarm";
8345
9072
  /**
8346
9073
  * Adds a new swarm to the system. The swarm is a root for starting client session
8347
9074
  *
@@ -8350,7 +9077,7 @@ var METHOD_NAME$C = "function.addSwarm";
8350
9077
  */
8351
9078
  var addSwarm = function (swarmSchema) {
8352
9079
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8353
- swarm$1.loggerService.log(METHOD_NAME$C, {
9080
+ swarm$1.loggerService.log(METHOD_NAME$E, {
8354
9081
  swarmSchema: swarmSchema,
8355
9082
  });
8356
9083
  swarm$1.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
@@ -8358,7 +9085,7 @@ var addSwarm = function (swarmSchema) {
8358
9085
  return swarmSchema.swarmName;
8359
9086
  };
8360
9087
 
8361
- var METHOD_NAME$B = "function.addTool";
9088
+ var METHOD_NAME$D = "function.addTool";
8362
9089
  /**
8363
9090
  * Adds a new tool for agents in a swarm. Tool should be registered in `addAgent`
8364
9091
  * declaration
@@ -8368,7 +9095,7 @@ var METHOD_NAME$B = "function.addTool";
8368
9095
  */
8369
9096
  var addTool = function (toolSchema) {
8370
9097
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8371
- swarm$1.loggerService.log(METHOD_NAME$B, {
9098
+ swarm$1.loggerService.log(METHOD_NAME$D, {
8372
9099
  toolSchema: toolSchema,
8373
9100
  });
8374
9101
  swarm$1.toolValidationService.addTool(toolSchema.toolName, toolSchema);
@@ -8376,7 +9103,7 @@ var addTool = function (toolSchema) {
8376
9103
  return toolSchema.toolName;
8377
9104
  };
8378
9105
 
8379
- var METHOD_NAME$A = "function.addState";
9106
+ var METHOD_NAME$C = "function.addState";
8380
9107
  /**
8381
9108
  * Adds a new state to the state registry. The swarm takes only those states which was registered
8382
9109
  *
@@ -8385,19 +9112,19 @@ var METHOD_NAME$A = "function.addState";
8385
9112
  */
8386
9113
  var addState = function (stateSchema) {
8387
9114
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8388
- swarm$1.loggerService.log(METHOD_NAME$A, {
9115
+ swarm$1.loggerService.log(METHOD_NAME$C, {
8389
9116
  stateSchema: stateSchema,
8390
9117
  });
8391
9118
  swarm$1.stateSchemaService.register(stateSchema.stateName, stateSchema);
8392
9119
  if (stateSchema.shared) {
8393
- swarm$1.stateConnectionService
8394
- .getSharedStateRef("shared", stateSchema.stateName)
9120
+ swarm$1.sharedStateConnectionService
9121
+ .getStateRef(stateSchema.stateName)
8395
9122
  .waitForInit();
8396
9123
  }
8397
9124
  return stateSchema.stateName;
8398
9125
  };
8399
9126
 
8400
- var METHOD_NAME$z = "function.addEmbedding";
9127
+ var METHOD_NAME$B = "function.addEmbedding";
8401
9128
  /**
8402
9129
  * Adds a new embedding to the embedding registry. The swarm takes only those embeddings which was registered
8403
9130
  *
@@ -8406,7 +9133,7 @@ var METHOD_NAME$z = "function.addEmbedding";
8406
9133
  */
8407
9134
  var addEmbedding = function (embeddingSchema) {
8408
9135
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8409
- swarm$1.loggerService.log(METHOD_NAME$z, {
9136
+ swarm$1.loggerService.log(METHOD_NAME$B, {
8410
9137
  embeddingSchema: embeddingSchema,
8411
9138
  });
8412
9139
  swarm$1.embeddingValidationService.addEmbedding(embeddingSchema.embeddingName, embeddingSchema);
@@ -8414,7 +9141,7 @@ var addEmbedding = function (embeddingSchema) {
8414
9141
  return embeddingSchema.embeddingName;
8415
9142
  };
8416
9143
 
8417
- var METHOD_NAME$y = "function.addStorage";
9144
+ var METHOD_NAME$A = "function.addStorage";
8418
9145
  /**
8419
9146
  * Adds a new storage to the storage registry. The swarm takes only those storages which was registered
8420
9147
  *
@@ -8423,20 +9150,20 @@ var METHOD_NAME$y = "function.addStorage";
8423
9150
  */
8424
9151
  var addStorage = function (storageSchema) {
8425
9152
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8426
- swarm$1.loggerService.log(METHOD_NAME$y, {
9153
+ swarm$1.loggerService.log(METHOD_NAME$A, {
8427
9154
  storageSchema: storageSchema,
8428
9155
  });
8429
9156
  swarm$1.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
8430
9157
  swarm$1.storageSchemaService.register(storageSchema.storageName, storageSchema);
8431
9158
  if (storageSchema.shared) {
8432
- swarm$1.storageConnectionService
8433
- .getSharedStorage("shared", storageSchema.storageName)
9159
+ swarm$1.sharedStorageConnectionService
9160
+ .getStorage(storageSchema.storageName)
8434
9161
  .waitForInit();
8435
9162
  }
8436
9163
  return storageSchema.storageName;
8437
9164
  };
8438
9165
 
8439
- var METHOD_NAME$x = "function.commitToolOutput";
9166
+ var METHOD_NAME$z = "function.commitToolOutput";
8440
9167
  /**
8441
9168
  * Commits the tool output to the active agent in a swarm session
8442
9169
  *
@@ -8451,17 +9178,17 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
8451
9178
  switch (_a.label) {
8452
9179
  case 0:
8453
9180
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8454
- swarm$1.loggerService.log(METHOD_NAME$x, {
9181
+ swarm$1.loggerService.log(METHOD_NAME$z, {
8455
9182
  toolId: toolId,
8456
9183
  content: content,
8457
9184
  clientId: clientId,
8458
9185
  agentName: agentName,
8459
9186
  });
8460
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
8461
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9187
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9188
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
8462
9189
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8463
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
8464
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$x, clientId, swarmName)];
9190
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9191
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName)];
8465
9192
  case 1:
8466
9193
  currentAgentName = _a.sent();
8467
9194
  if (currentAgentName !== agentName) {
@@ -8474,7 +9201,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
8474
9201
  });
8475
9202
  return [2 /*return*/];
8476
9203
  }
8477
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$x, clientId, swarmName)];
9204
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$z, clientId, swarmName)];
8478
9205
  case 2:
8479
9206
  _a.sent();
8480
9207
  return [2 /*return*/];
@@ -8482,7 +9209,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
8482
9209
  });
8483
9210
  }); };
8484
9211
 
8485
- var METHOD_NAME$w = "function.commitSystemMessage";
9212
+ var METHOD_NAME$y = "function.commitSystemMessage";
8486
9213
  /**
8487
9214
  * Commits a system message to the active agent in the swarm.
8488
9215
  *
@@ -8497,16 +9224,16 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
8497
9224
  switch (_a.label) {
8498
9225
  case 0:
8499
9226
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8500
- swarm$1.loggerService.log(METHOD_NAME$w, {
9227
+ swarm$1.loggerService.log(METHOD_NAME$y, {
8501
9228
  content: content,
8502
9229
  clientId: clientId,
8503
9230
  agentName: agentName,
8504
9231
  });
8505
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
8506
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9232
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9233
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
8507
9234
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8508
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
8509
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$w, clientId, swarmName)];
9235
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9236
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName)];
8510
9237
  case 1:
8511
9238
  currentAgentName = _a.sent();
8512
9239
  if (currentAgentName !== agentName) {
@@ -8518,7 +9245,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
8518
9245
  });
8519
9246
  return [2 /*return*/];
8520
9247
  }
8521
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$w, clientId, swarmName)];
9248
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$y, clientId, swarmName)];
8522
9249
  case 2:
8523
9250
  _a.sent();
8524
9251
  return [2 /*return*/];
@@ -8526,7 +9253,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
8526
9253
  });
8527
9254
  }); };
8528
9255
 
8529
- var METHOD_NAME$v = "function.commitFlush";
9256
+ var METHOD_NAME$x = "function.commitFlush";
8530
9257
  /**
8531
9258
  * Commits flush of agent history
8532
9259
  *
@@ -8540,15 +9267,15 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
8540
9267
  switch (_a.label) {
8541
9268
  case 0:
8542
9269
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8543
- swarm$1.loggerService.log(METHOD_NAME$v, {
9270
+ swarm$1.loggerService.log(METHOD_NAME$x, {
8544
9271
  clientId: clientId,
8545
9272
  agentName: agentName,
8546
9273
  });
8547
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$v);
8548
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9274
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
9275
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
8549
9276
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8550
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
8551
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$v, clientId, swarmName)];
9277
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9278
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$x, clientId, swarmName)];
8552
9279
  case 1:
8553
9280
  currentAgentName = _a.sent();
8554
9281
  if (currentAgentName !== agentName) {
@@ -8560,7 +9287,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
8560
9287
  });
8561
9288
  return [2 /*return*/];
8562
9289
  }
8563
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$v, clientId, swarmName)];
9290
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$x, clientId, swarmName)];
8564
9291
  case 2:
8565
9292
  _a.sent();
8566
9293
  return [2 /*return*/];
@@ -8568,7 +9295,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
8568
9295
  });
8569
9296
  }); };
8570
9297
 
8571
- var METHOD_NAME$u = "function.commitSystemMessage";
9298
+ var METHOD_NAME$w = "function.commitSystemMessage";
8572
9299
  /**
8573
9300
  * Commits a user message to the active agent history in as swarm without answer.
8574
9301
  *
@@ -8583,16 +9310,16 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
8583
9310
  switch (_a.label) {
8584
9311
  case 0:
8585
9312
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8586
- swarm$1.loggerService.log(METHOD_NAME$u, {
9313
+ swarm$1.loggerService.log(METHOD_NAME$w, {
8587
9314
  content: content,
8588
9315
  clientId: clientId,
8589
9316
  agentName: agentName,
8590
9317
  });
8591
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$u);
8592
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9318
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
9319
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
8593
9320
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8594
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
8595
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$u, clientId, swarmName)];
9321
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9322
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$w, clientId, swarmName)];
8596
9323
  case 1:
8597
9324
  currentAgentName = _a.sent();
8598
9325
  if (currentAgentName !== agentName) {
@@ -8604,7 +9331,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
8604
9331
  });
8605
9332
  return [2 /*return*/];
8606
9333
  }
8607
- return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$u, clientId, swarmName)];
9334
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$w, clientId, swarmName)];
8608
9335
  case 2:
8609
9336
  _a.sent();
8610
9337
  return [2 /*return*/];
@@ -8612,7 +9339,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
8612
9339
  });
8613
9340
  }); };
8614
9341
 
8615
- var METHOD_NAME$t = "function.commitToolOutputForce";
9342
+ var METHOD_NAME$v = "function.commitToolOutputForce";
8616
9343
  /**
8617
9344
  * Commits the tool output to the active agent in a swarm session without checking active agent
8618
9345
  *
@@ -8626,15 +9353,15 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
8626
9353
  switch (_a.label) {
8627
9354
  case 0:
8628
9355
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8629
- swarm$1.loggerService.log(METHOD_NAME$t, {
9356
+ swarm$1.loggerService.log(METHOD_NAME$v, {
8630
9357
  toolId: toolId,
8631
9358
  content: content,
8632
9359
  clientId: clientId,
8633
9360
  });
8634
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9361
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
8635
9362
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8636
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
8637
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$t, clientId, swarmName)];
9363
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9364
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$v, clientId, swarmName)];
8638
9365
  case 1:
8639
9366
  _a.sent();
8640
9367
  return [2 /*return*/];
@@ -8642,7 +9369,7 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
8642
9369
  });
8643
9370
  }); };
8644
9371
 
8645
- var METHOD_NAME$s = "function.commitSystemMessageForce";
9372
+ var METHOD_NAME$u = "function.commitSystemMessageForce";
8646
9373
  /**
8647
9374
  * Commits a system message to the active agent in as swarm without checking active agent.
8648
9375
  *
@@ -8656,14 +9383,14 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
8656
9383
  switch (_a.label) {
8657
9384
  case 0:
8658
9385
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8659
- swarm$1.loggerService.log(METHOD_NAME$s, {
9386
+ swarm$1.loggerService.log(METHOD_NAME$u, {
8660
9387
  content: content,
8661
9388
  clientId: clientId,
8662
9389
  });
8663
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9390
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
8664
9391
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8665
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
8666
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$s, clientId, swarmName)];
9392
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9393
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$u, clientId, swarmName)];
8667
9394
  case 1:
8668
9395
  _a.sent();
8669
9396
  return [2 /*return*/];
@@ -8671,7 +9398,7 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
8671
9398
  });
8672
9399
  }); };
8673
9400
 
8674
- var METHOD_NAME$r = "function.commitFlushForce";
9401
+ var METHOD_NAME$t = "function.commitFlushForce";
8675
9402
  /**
8676
9403
  * Commits flush of agent history without active agent check
8677
9404
  *
@@ -8684,14 +9411,14 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
8684
9411
  switch (_a.label) {
8685
9412
  case 0:
8686
9413
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8687
- swarm$1.loggerService.log(METHOD_NAME$r, {
9414
+ swarm$1.loggerService.log(METHOD_NAME$t, {
8688
9415
  clientId: clientId,
8689
- METHOD_NAME: METHOD_NAME$r,
9416
+ METHOD_NAME: METHOD_NAME$t,
8690
9417
  });
8691
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9418
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
8692
9419
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8693
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
8694
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$r, clientId, swarmName)];
9420
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9421
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$t, clientId, swarmName)];
8695
9422
  case 1:
8696
9423
  _a.sent();
8697
9424
  return [2 /*return*/];
@@ -8699,7 +9426,7 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
8699
9426
  });
8700
9427
  }); };
8701
9428
 
8702
- var METHOD_NAME$q = "function.commitSystemMessage";
9429
+ var METHOD_NAME$s = "function.commitSystemMessage";
8703
9430
  /**
8704
9431
  * Commits a user message to the active agent history in as swarm without answer and checking active agent
8705
9432
  *
@@ -8708,6 +9435,79 @@ var METHOD_NAME$q = "function.commitSystemMessage";
8708
9435
  * @returns {Promise<void>} - A promise that resolves when the message is committed.
8709
9436
  */
8710
9437
  var commitUserMessageForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
9438
+ var swarmName;
9439
+ return __generator(this, function (_a) {
9440
+ switch (_a.label) {
9441
+ case 0:
9442
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9443
+ swarm$1.loggerService.log(METHOD_NAME$s, {
9444
+ content: content,
9445
+ clientId: clientId,
9446
+ });
9447
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9448
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9449
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
9450
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$s, clientId, swarmName)];
9451
+ case 1:
9452
+ _a.sent();
9453
+ return [2 /*return*/];
9454
+ }
9455
+ });
9456
+ }); };
9457
+
9458
+ var METHOD_NAME$r = "function.commitAssistantMessage";
9459
+ /**
9460
+ * Commits an assistant message to the active agent in the swarm.
9461
+ *
9462
+ * @param {string} content - The content of the assistant message.
9463
+ * @param {string} clientId - The ID of the client.
9464
+ * @param {string} agentName - The name of the agent.
9465
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9466
+ */
9467
+ var commitAssistantMessage = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
9468
+ var swarmName, currentAgentName;
9469
+ return __generator(this, function (_a) {
9470
+ switch (_a.label) {
9471
+ case 0:
9472
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9473
+ swarm$1.loggerService.log(METHOD_NAME$r, {
9474
+ content: content,
9475
+ clientId: clientId,
9476
+ agentName: agentName,
9477
+ });
9478
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9479
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9480
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9481
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
9482
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName)];
9483
+ case 1:
9484
+ currentAgentName = _a.sent();
9485
+ if (currentAgentName !== agentName) {
9486
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9487
+ swarm$1.loggerService.log('function "commitAssistantMessage" skipped due to the agent change', {
9488
+ currentAgentName: currentAgentName,
9489
+ agentName: agentName,
9490
+ clientId: clientId,
9491
+ });
9492
+ return [2 /*return*/];
9493
+ }
9494
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$r, clientId, swarmName)];
9495
+ case 2:
9496
+ _a.sent();
9497
+ return [2 /*return*/];
9498
+ }
9499
+ });
9500
+ }); };
9501
+
9502
+ var METHOD_NAME$q = "function.commitAssistantMessageForce";
9503
+ /**
9504
+ * Commits an assistant message to the active agent in as swarm without checking active agent.
9505
+ *
9506
+ * @param {string} content - The content of the assistant message.
9507
+ * @param {string} clientId - The ID of the client.
9508
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9509
+ */
9510
+ var commitAssistantMessageForce = function (content, clientId) { return __awaiter(void 0, void 0, void 0, function () {
8711
9511
  var swarmName;
8712
9512
  return __generator(this, function (_a) {
8713
9513
  switch (_a.label) {
@@ -8720,7 +9520,7 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
8720
9520
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
8721
9521
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
8722
9522
  swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
8723
- return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$q, clientId, swarmName)];
9523
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$q, clientId, swarmName)];
8724
9524
  case 1:
8725
9525
  _a.sent();
8726
9526
  return [2 /*return*/];
@@ -8892,6 +9692,7 @@ var disposeConnection = function (clientId_1, swarmName_1) {
8892
9692
  clientId: clientId,
8893
9693
  swarmName: swarmName,
8894
9694
  });
9695
+ swarm$1.sessionValidationService.validate(clientId, methodName);
8895
9696
  swarm$1.swarmValidationService.validate(swarmName, methodName);
8896
9697
  return [4 /*yield*/, swarm$1.sessionPublicService.dispose(methodName, clientId, swarmName)];
8897
9698
  case 1:
@@ -8960,6 +9761,7 @@ var disposeConnection = function (clientId_1, swarmName_1) {
8960
9761
  _a.sent();
8961
9762
  swarm$1.sessionValidationService.removeSession(clientId);
8962
9763
  swarm$1.busService.dispose(clientId);
9764
+ swarm$1.sessionValidationService.dispose(clientId);
8963
9765
  return [2 /*return*/];
8964
9766
  }
8965
9767
  });
@@ -10409,47 +11211,203 @@ var validateClientId$1 = function (clientId) {
10409
11211
  }
10410
11212
  };
10411
11213
  /**
10412
- * Hook to subscribe to storage events for a specific client.
10413
- *
10414
- * @param {string} clientId - The ID of the client to subscribe to storage events for.
10415
- * @param {function} fn - The callback function to handle the storage event.
11214
+ * Hook to subscribe to storage events for a specific client.
11215
+ *
11216
+ * @param {string} clientId - The ID of the client to subscribe to storage events for.
11217
+ * @param {function} fn - The callback function to handle the storage event.
11218
+ */
11219
+ var listenStorageEventOnce = function (clientId, filterFn, fn) {
11220
+ swarm$1.loggerService.log("middleware listenStorageEventOnce", {
11221
+ clientId: clientId,
11222
+ });
11223
+ validateClientId$1(clientId);
11224
+ return swarm$1.busService.once(clientId, "storage-bus", filterFn, fn);
11225
+ };
11226
+
11227
+ var validateClientId = function (clientId) {
11228
+ if (clientId === "*") {
11229
+ return;
11230
+ }
11231
+ if (!swarm$1.sessionValidationService.hasSession(clientId)) {
11232
+ throw new Error("agent-swarm listenSwarmEventOnce session not found for clientId=".concat(clientId));
11233
+ }
11234
+ };
11235
+ /**
11236
+ * Hook to subscribe to swarm events for a specific client.
11237
+ *
11238
+ * @param {string} clientId - The ID of the client to subscribe to events for.
11239
+ * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
11240
+ */
11241
+ var listenSwarmEventOnce = function (clientId, filterFn, fn) {
11242
+ swarm$1.loggerService.log("middleware listenSwarmEventOnce", {
11243
+ clientId: clientId,
11244
+ });
11245
+ validateClientId(clientId);
11246
+ return swarm$1.busService.once(clientId, "swarm-bus", filterFn, fn);
11247
+ };
11248
+
11249
+ var METHOD_NAME_GET$3 = "StateUtils.getState";
11250
+ var METHOD_NAME_SET$1 = "StateUtils.setState";
11251
+ /**
11252
+ * Utility class for managing state in the agent swarm.
11253
+ * @implements {TState}
11254
+ */
11255
+ var StateUtils = /** @class */ (function () {
11256
+ function StateUtils() {
11257
+ var _this = this;
11258
+ /**
11259
+ * Retrieves the state for a given client and state name.
11260
+ * @template T
11261
+ * @param {Object} payload - The payload containing client and state information.
11262
+ * @param {string} payload.clientId - The client ID.
11263
+ * @param {AgentName} payload.agentName - The agent name.
11264
+ * @param {StateName} payload.stateName - The state name.
11265
+ * @returns {Promise<T>} The state data.
11266
+ * @throws Will throw an error if the state is not registered in the agent.
11267
+ */
11268
+ this.getState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11269
+ return __generator(this, function (_a) {
11270
+ switch (_a.label) {
11271
+ case 0:
11272
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11273
+ swarm$1.loggerService.log(METHOD_NAME_GET$3, {
11274
+ clientId: payload.clientId,
11275
+ stateName: payload.stateName,
11276
+ });
11277
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_GET$3);
11278
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11279
+ throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (getState)"));
11280
+ }
11281
+ return [4 /*yield*/, swarm$1.statePublicService.getState(METHOD_NAME_GET$3, payload.clientId, payload.stateName)];
11282
+ case 1: return [2 /*return*/, _a.sent()];
11283
+ }
11284
+ });
11285
+ }); };
11286
+ /**
11287
+ * Sets the state for a given client and state name.
11288
+ * @template T
11289
+ * @param {T | ((prevState: T) => Promise<T>)} dispatchFn - The new state or a function that returns the new state.
11290
+ * @param {Object} payload - The payload containing client and state information.
11291
+ * @param {string} payload.clientId - The client ID.
11292
+ * @param {AgentName} payload.agentName - The agent name.
11293
+ * @param {StateName} payload.stateName - The state name.
11294
+ * @returns {Promise<void>}
11295
+ * @throws Will throw an error if the state is not registered in the agent.
11296
+ */
11297
+ this.setState = function (dispatchFn, payload) { return __awaiter(_this, void 0, void 0, function () {
11298
+ var _this = this;
11299
+ return __generator(this, function (_a) {
11300
+ switch (_a.label) {
11301
+ case 0:
11302
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11303
+ swarm$1.loggerService.log(METHOD_NAME_SET$1, {
11304
+ clientId: payload.clientId,
11305
+ stateName: payload.stateName,
11306
+ });
11307
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_SET$1);
11308
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11309
+ throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (setState)"));
11310
+ }
11311
+ if (!(typeof dispatchFn === "function")) return [3 /*break*/, 2];
11312
+ return [4 /*yield*/, swarm$1.statePublicService.setState(dispatchFn, METHOD_NAME_SET$1, payload.clientId, payload.stateName)];
11313
+ case 1: return [2 /*return*/, _a.sent()];
11314
+ case 2: return [4 /*yield*/, swarm$1.statePublicService.setState(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
11315
+ return [2 /*return*/, dispatchFn];
11316
+ }); }); }, METHOD_NAME_SET$1, payload.clientId, payload.stateName)];
11317
+ case 3: return [2 /*return*/, _a.sent()];
11318
+ }
11319
+ });
11320
+ }); };
11321
+ }
11322
+ return StateUtils;
11323
+ }());
11324
+ /**
11325
+ * Instance of StateUtils for managing state.
11326
+ * @type {StateUtils}
10416
11327
  */
10417
- var listenStorageEventOnce = function (clientId, filterFn, fn) {
10418
- swarm$1.loggerService.log("middleware listenStorageEventOnce", {
10419
- clientId: clientId,
10420
- });
10421
- validateClientId$1(clientId);
10422
- return swarm$1.busService.once(clientId, "storage-bus", filterFn, fn);
10423
- };
11328
+ var State = new StateUtils();
10424
11329
 
10425
- var validateClientId = function (clientId) {
10426
- if (clientId === "*") {
10427
- return;
10428
- }
10429
- if (!swarm$1.sessionValidationService.hasSession(clientId)) {
10430
- throw new Error("agent-swarm listenSwarmEventOnce session not found for clientId=".concat(clientId));
11330
+ var METHOD_NAME_GET$2 = "SharedStateUtils.getSharedState";
11331
+ var METHOD_NAME_SET = "SharedStateUtils.setSharedState";
11332
+ /**
11333
+ * Utility class for managing state in the agent swarm.
11334
+ * @implements {TSharedState}
11335
+ */
11336
+ var SharedStateUtils = /** @class */ (function () {
11337
+ function SharedStateUtils() {
11338
+ var _this = this;
11339
+ /**
11340
+ * Retrieves the state for a given client and state name.
11341
+ * @template T
11342
+ * @param {Object} payload - The payload containing client and state information.
11343
+ * @param {AgentName} payload.agentName - The agent name.
11344
+ * @param {StateName} payload.stateName - The state name.
11345
+ * @returns {Promise<T>} The state data.
11346
+ * @throws Will throw an error if the state is not registered in the agent.
11347
+ */
11348
+ this.getState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11349
+ return __generator(this, function (_a) {
11350
+ switch (_a.label) {
11351
+ case 0:
11352
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11353
+ swarm$1.loggerService.log(METHOD_NAME_GET$2, {
11354
+ stateName: payload.stateName,
11355
+ });
11356
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11357
+ throw new Error("agent-swarm SharedStateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (getSharedState)"));
11358
+ }
11359
+ return [4 /*yield*/, swarm$1.sharedStatePublicService.getState(METHOD_NAME_GET$2, payload.stateName)];
11360
+ case 1: return [2 /*return*/, _a.sent()];
11361
+ }
11362
+ });
11363
+ }); };
11364
+ /**
11365
+ * Sets the state for a given client and state name.
11366
+ * @template T
11367
+ * @param {T | ((prevSharedState: T) => Promise<T>)} dispatchFn - The new state or a function that returns the new state.
11368
+ * @param {Object} payload - The payload containing client and state information.
11369
+ * @param {AgentName} payload.agentName - The agent name.
11370
+ * @param {StateName} payload.stateName - The state name.
11371
+ * @returns {Promise<void>}
11372
+ * @throws Will throw an error if the state is not registered in the agent.
11373
+ */
11374
+ this.setState = function (dispatchFn, payload) { return __awaiter(_this, void 0, void 0, function () {
11375
+ var _this = this;
11376
+ return __generator(this, function (_a) {
11377
+ switch (_a.label) {
11378
+ case 0:
11379
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11380
+ swarm$1.loggerService.log(METHOD_NAME_SET, {
11381
+ stateName: payload.stateName,
11382
+ });
11383
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11384
+ throw new Error("agent-swarm SharedStateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (setState)"));
11385
+ }
11386
+ if (!(typeof dispatchFn === "function")) return [3 /*break*/, 2];
11387
+ return [4 /*yield*/, swarm$1.sharedStatePublicService.setState(dispatchFn, METHOD_NAME_SET, payload.stateName)];
11388
+ case 1: return [2 /*return*/, _a.sent()];
11389
+ case 2: return [4 /*yield*/, swarm$1.sharedStatePublicService.setState(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
11390
+ return [2 /*return*/, dispatchFn];
11391
+ }); }); }, METHOD_NAME_SET, payload.stateName)];
11392
+ case 3: return [2 /*return*/, _a.sent()];
11393
+ }
11394
+ });
11395
+ }); };
10431
11396
  }
10432
- };
11397
+ return SharedStateUtils;
11398
+ }());
10433
11399
  /**
10434
- * Hook to subscribe to swarm events for a specific client.
10435
- *
10436
- * @param {string} clientId - The ID of the client to subscribe to events for.
10437
- * @param {(event: IBusEvent) => void} fn - The callback function to handle the event.
11400
+ * Instance of SharedStateUtils for managing state.
11401
+ * @type {SharedStateUtils}
10438
11402
  */
10439
- var listenSwarmEventOnce = function (clientId, filterFn, fn) {
10440
- swarm$1.loggerService.log("middleware listenSwarmEventOnce", {
10441
- clientId: clientId,
10442
- });
10443
- validateClientId(clientId);
10444
- return swarm$1.busService.once(clientId, "swarm-bus", filterFn, fn);
10445
- };
11403
+ var SharedState = new SharedStateUtils();
10446
11404
 
10447
- var METHOD_NAME_TAKE = "StorageUtils.take";
10448
- var METHOD_NAME_UPSERT = "StorageUtils.upsert";
10449
- var METHOD_NAME_REMOVE = "StorageUtils.remove";
11405
+ var METHOD_NAME_TAKE$1 = "StorageUtils.take";
11406
+ var METHOD_NAME_UPSERT$1 = "StorageUtils.upsert";
11407
+ var METHOD_NAME_REMOVE$1 = "StorageUtils.remove";
10450
11408
  var METHOD_NAME_GET$1 = "StorageUtils.get";
10451
- var METHOD_NAME_LIST = "StorageUtils.list";
10452
- var METHOD_NAME_CLEAR = "StorageUtils.clear";
11409
+ var METHOD_NAME_LIST$1 = "StorageUtils.list";
11410
+ var METHOD_NAME_CLEAR$1 = "StorageUtils.clear";
10453
11411
  var StorageUtils = /** @class */ (function () {
10454
11412
  function StorageUtils() {
10455
11413
  var _this = this;
@@ -10468,18 +11426,19 @@ var StorageUtils = /** @class */ (function () {
10468
11426
  switch (_a.label) {
10469
11427
  case 0:
10470
11428
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10471
- swarm$1.loggerService.log(METHOD_NAME_TAKE, {
11429
+ swarm$1.loggerService.log(METHOD_NAME_TAKE$1, {
10472
11430
  search: payload.search,
10473
11431
  total: payload.total,
10474
11432
  clientId: payload.clientId,
10475
11433
  storageName: payload.storageName,
10476
11434
  score: payload.score,
10477
11435
  });
10478
- swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_TAKE);
11436
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_TAKE$1);
11437
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_TAKE$1);
10479
11438
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
10480
11439
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (take)"));
10481
11440
  }
10482
- return [4 /*yield*/, swarm$1.storagePublicService.take(payload.search, payload.total, METHOD_NAME_TAKE, payload.clientId, payload.storageName, payload.score)];
11441
+ return [4 /*yield*/, swarm$1.storagePublicService.take(payload.search, payload.total, METHOD_NAME_TAKE$1, payload.clientId, payload.storageName, payload.score)];
10483
11442
  case 1: return [2 /*return*/, (_a.sent())];
10484
11443
  }
10485
11444
  });
@@ -10498,16 +11457,17 @@ var StorageUtils = /** @class */ (function () {
10498
11457
  switch (_a.label) {
10499
11458
  case 0:
10500
11459
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10501
- swarm$1.loggerService.log(METHOD_NAME_UPSERT, {
11460
+ swarm$1.loggerService.log(METHOD_NAME_UPSERT$1, {
10502
11461
  item: payload.item,
10503
11462
  clientId: payload.clientId,
10504
11463
  storageName: payload.storageName,
10505
11464
  });
10506
- swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_UPSERT);
11465
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_UPSERT$1);
11466
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_UPSERT$1);
10507
11467
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
10508
11468
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (upsert)"));
10509
11469
  }
10510
- return [4 /*yield*/, swarm$1.storagePublicService.upsert(payload.item, METHOD_NAME_UPSERT, payload.clientId, payload.storageName)];
11470
+ return [4 /*yield*/, swarm$1.storagePublicService.upsert(payload.item, METHOD_NAME_UPSERT$1, payload.clientId, payload.storageName)];
10511
11471
  case 1: return [2 /*return*/, _a.sent()];
10512
11472
  }
10513
11473
  });
@@ -10525,16 +11485,17 @@ var StorageUtils = /** @class */ (function () {
10525
11485
  switch (_a.label) {
10526
11486
  case 0:
10527
11487
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10528
- swarm$1.loggerService.log(METHOD_NAME_REMOVE, {
11488
+ swarm$1.loggerService.log(METHOD_NAME_REMOVE$1, {
10529
11489
  itemId: payload.itemId,
10530
11490
  clientId: payload.clientId,
10531
11491
  storageName: payload.storageName,
10532
11492
  });
10533
- swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_REMOVE);
11493
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_REMOVE$1);
11494
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_REMOVE$1);
10534
11495
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
10535
11496
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (remove)"));
10536
11497
  }
10537
- return [4 /*yield*/, swarm$1.storagePublicService.remove(payload.itemId, METHOD_NAME_REMOVE, payload.clientId, payload.storageName)];
11498
+ return [4 /*yield*/, swarm$1.storagePublicService.remove(payload.itemId, METHOD_NAME_REMOVE$1, payload.clientId, payload.storageName)];
10538
11499
  case 1: return [2 /*return*/, _a.sent()];
10539
11500
  }
10540
11501
  });
@@ -10581,15 +11542,15 @@ var StorageUtils = /** @class */ (function () {
10581
11542
  switch (_a.label) {
10582
11543
  case 0:
10583
11544
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10584
- swarm$1.loggerService.log(METHOD_NAME_LIST, {
11545
+ swarm$1.loggerService.log(METHOD_NAME_LIST$1, {
10585
11546
  clientId: payload.clientId,
10586
11547
  storageName: payload.storageName,
10587
11548
  });
10588
- swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_LIST);
11549
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_LIST$1);
10589
11550
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
10590
11551
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (list)"));
10591
11552
  }
10592
- return [4 /*yield*/, swarm$1.storagePublicService.list(METHOD_NAME_LIST, payload.clientId, payload.storageName, payload.filter)];
11553
+ return [4 /*yield*/, swarm$1.storagePublicService.list(METHOD_NAME_LIST$1, payload.clientId, payload.storageName, payload.filter)];
10593
11554
  case 1: return [2 /*return*/, (_a.sent())];
10594
11555
  }
10595
11556
  });
@@ -10606,15 +11567,15 @@ var StorageUtils = /** @class */ (function () {
10606
11567
  switch (_a.label) {
10607
11568
  case 0:
10608
11569
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10609
- swarm$1.loggerService.log(METHOD_NAME_CLEAR, {
11570
+ swarm$1.loggerService.log(METHOD_NAME_CLEAR$1, {
10610
11571
  clientId: payload.clientId,
10611
11572
  storageName: payload.storageName,
10612
11573
  });
10613
- swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_CLEAR);
11574
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_CLEAR$1);
10614
11575
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
10615
11576
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (clear)"));
10616
11577
  }
10617
- return [4 /*yield*/, swarm$1.storagePublicService.clear(METHOD_NAME_CLEAR, payload.clientId, payload.storageName)];
11578
+ return [4 /*yield*/, swarm$1.storagePublicService.clear(METHOD_NAME_CLEAR$1, payload.clientId, payload.storageName)];
10618
11579
  case 1: return [2 /*return*/, _a.sent()];
10619
11580
  }
10620
11581
  });
@@ -10624,84 +11585,173 @@ var StorageUtils = /** @class */ (function () {
10624
11585
  }());
10625
11586
  var Storage = new StorageUtils();
10626
11587
 
10627
- var METHOD_NAME_GET = "StateUtils.getState";
10628
- var METHOD_NAME_SET = "StateUtils.setState";
10629
- /**
10630
- * Utility class for managing state in the agent swarm.
10631
- * @implements {TState}
10632
- */
10633
- var StateUtils = /** @class */ (function () {
10634
- function StateUtils() {
11588
+ var METHOD_NAME_TAKE = "SharedStorageUtils.take";
11589
+ var METHOD_NAME_UPSERT = "SharedStorageUtils.upsert";
11590
+ var METHOD_NAME_REMOVE = "SharedStorageUtils.remove";
11591
+ var METHOD_NAME_GET = "SharedStorageUtils.get";
11592
+ var METHOD_NAME_LIST = "SharedStorageUtils.list";
11593
+ var METHOD_NAME_CLEAR = "SharedStorageUtils.clear";
11594
+ var SharedStorageUtils = /** @class */ (function () {
11595
+ function SharedStorageUtils() {
10635
11596
  var _this = this;
10636
11597
  /**
10637
- * Retrieves the state for a given client and state name.
11598
+ * Takes items from the storage.
11599
+ * @param {string} search - The search query.
11600
+ * @param {number} total - The total number of items to take.
11601
+ * @param {AgentName} agentName - The agent name.
11602
+ * @param {StorageName} storageName - The storage name.
11603
+ * @returns {Promise<T[]>} - A promise that resolves to an array of items.
10638
11604
  * @template T
10639
- * @param {Object} payload - The payload containing client and state information.
10640
- * @param {string} payload.clientId - The client ID.
10641
- * @param {AgentName} payload.agentName - The agent name.
10642
- * @param {StateName} payload.stateName - The state name.
10643
- * @returns {Promise<T>} The state data.
10644
- * @throws Will throw an error if the state is not registered in the agent.
10645
11605
  */
10646
- this.getState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11606
+ this.take = function (payload) { return __awaiter(_this, void 0, void 0, function () {
10647
11607
  return __generator(this, function (_a) {
10648
11608
  switch (_a.label) {
10649
11609
  case 0:
10650
11610
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10651
- swarm$1.loggerService.log(METHOD_NAME_GET, {
10652
- clientId: payload.clientId,
10653
- stateName: payload.stateName,
11611
+ swarm$1.loggerService.log(METHOD_NAME_TAKE, {
11612
+ search: payload.search,
11613
+ total: payload.total,
11614
+ storageName: payload.storageName,
11615
+ score: payload.score,
10654
11616
  });
10655
- if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
10656
- throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (getState)"));
11617
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_TAKE);
11618
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11619
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (take)"));
11620
+ }
11621
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.take(payload.search, payload.total, METHOD_NAME_TAKE, payload.storageName, payload.score)];
11622
+ case 1: return [2 /*return*/, (_a.sent())];
11623
+ }
11624
+ });
11625
+ }); };
11626
+ /**
11627
+ * Upserts an item in the storage.
11628
+ * @param {T} item - The item to upsert.
11629
+ * @param {AgentName} agentName - The agent name.
11630
+ * @param {StorageName} storageName - The storage name.
11631
+ * @returns {Promise<void>} - A promise that resolves when the operation is complete.
11632
+ * @template T
11633
+ */
11634
+ this.upsert = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11635
+ return __generator(this, function (_a) {
11636
+ switch (_a.label) {
11637
+ case 0:
11638
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11639
+ swarm$1.loggerService.log(METHOD_NAME_UPSERT, {
11640
+ item: payload.item,
11641
+ storageName: payload.storageName,
11642
+ });
11643
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_UPSERT);
11644
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11645
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (upsert)"));
10657
11646
  }
10658
- return [4 /*yield*/, swarm$1.statePublicService.getState(METHOD_NAME_GET, payload.clientId, payload.stateName)];
11647
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.upsert(payload.item, METHOD_NAME_UPSERT, payload.storageName)];
10659
11648
  case 1: return [2 /*return*/, _a.sent()];
10660
11649
  }
10661
11650
  });
10662
11651
  }); };
10663
11652
  /**
10664
- * Sets the state for a given client and state name.
11653
+ * Removes an item from the storage.
11654
+ * @param {IStorageData["id"]} itemId - The ID of the item to remove.
11655
+ * @param {AgentName} agentName - The agent name.
11656
+ * @param {StorageName} storageName - The storage name.
11657
+ * @returns {Promise<void>} - A promise that resolves when the operation is complete.
11658
+ */
11659
+ this.remove = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11660
+ return __generator(this, function (_a) {
11661
+ switch (_a.label) {
11662
+ case 0:
11663
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11664
+ swarm$1.loggerService.log(METHOD_NAME_REMOVE, {
11665
+ itemId: payload.itemId,
11666
+ storageName: payload.storageName,
11667
+ });
11668
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_REMOVE);
11669
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11670
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (remove)"));
11671
+ }
11672
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.remove(payload.itemId, METHOD_NAME_REMOVE, payload.storageName)];
11673
+ case 1: return [2 /*return*/, _a.sent()];
11674
+ }
11675
+ });
11676
+ }); };
11677
+ /**
11678
+ * Gets an item from the storage.
11679
+ * @param {IStorageData["id"]} itemId - The ID of the item to get.
11680
+ * @param {AgentName} agentName - The agent name.
11681
+ * @param {StorageName} storageName - The storage name.
11682
+ * @returns {Promise<T | null>} - A promise that resolves to the item or null if not found.
10665
11683
  * @template T
10666
- * @param {T | ((prevState: T) => Promise<T>)} dispatchFn - The new state or a function that returns the new state.
10667
- * @param {Object} payload - The payload containing client and state information.
10668
- * @param {string} payload.clientId - The client ID.
10669
- * @param {AgentName} payload.agentName - The agent name.
10670
- * @param {StateName} payload.stateName - The state name.
10671
- * @returns {Promise<void>}
10672
- * @throws Will throw an error if the state is not registered in the agent.
10673
11684
  */
10674
- this.setState = function (dispatchFn, payload) { return __awaiter(_this, void 0, void 0, function () {
10675
- var _this = this;
11685
+ this.get = function (payload) { return __awaiter(_this, void 0, void 0, function () {
10676
11686
  return __generator(this, function (_a) {
10677
11687
  switch (_a.label) {
10678
11688
  case 0:
10679
11689
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
10680
- swarm$1.loggerService.log(METHOD_NAME_SET, {
10681
- clientId: payload.clientId,
10682
- stateName: payload.stateName,
11690
+ swarm$1.loggerService.log(METHOD_NAME_GET, {
11691
+ itemId: payload.itemId,
11692
+ storageName: payload.storageName,
10683
11693
  });
10684
- if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
10685
- throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (setState)"));
11694
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_GET);
11695
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11696
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (get)"));
10686
11697
  }
10687
- if (!(typeof dispatchFn === "function")) return [3 /*break*/, 2];
10688
- return [4 /*yield*/, swarm$1.statePublicService.setState(dispatchFn, METHOD_NAME_SET, payload.clientId, payload.stateName)];
11698
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.get(payload.itemId, METHOD_NAME_GET, payload.storageName)];
11699
+ case 1: return [2 /*return*/, (_a.sent())];
11700
+ }
11701
+ });
11702
+ }); };
11703
+ /**
11704
+ * Lists items from the storage.
11705
+ * @param {AgentName} agentName - The agent name.
11706
+ * @param {StorageName} storageName - The storage name.
11707
+ * @param {(item: T) => boolean} [filter] - Optional filter function.
11708
+ * @returns {Promise<T[]>} - A promise that resolves to an array of items.
11709
+ * @template T
11710
+ */
11711
+ this.list = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11712
+ return __generator(this, function (_a) {
11713
+ switch (_a.label) {
11714
+ case 0:
11715
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11716
+ swarm$1.loggerService.log(METHOD_NAME_LIST, {
11717
+ storageName: payload.storageName,
11718
+ });
11719
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_LIST);
11720
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11721
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (list)"));
11722
+ }
11723
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.list(METHOD_NAME_LIST, payload.storageName, payload.filter)];
11724
+ case 1: return [2 /*return*/, (_a.sent())];
11725
+ }
11726
+ });
11727
+ }); };
11728
+ /**
11729
+ * Clears the storage.
11730
+ * @param {AgentName} agentName - The agent name.
11731
+ * @param {StorageName} storageName - The storage name.
11732
+ * @returns {Promise<void>} - A promise that resolves when the operation is complete.
11733
+ */
11734
+ this.clear = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11735
+ return __generator(this, function (_a) {
11736
+ switch (_a.label) {
11737
+ case 0:
11738
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11739
+ swarm$1.loggerService.log(METHOD_NAME_CLEAR, {
11740
+ storageName: payload.storageName,
11741
+ });
11742
+ swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_CLEAR);
11743
+ if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11744
+ throw new Error("agent-swarm SharedStorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (clear)"));
11745
+ }
11746
+ return [4 /*yield*/, swarm$1.sharedStoragePublicService.clear(METHOD_NAME_CLEAR, payload.storageName)];
10689
11747
  case 1: return [2 /*return*/, _a.sent()];
10690
- case 2: return [4 /*yield*/, swarm$1.statePublicService.setState(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
10691
- return [2 /*return*/, dispatchFn];
10692
- }); }); }, METHOD_NAME_SET, payload.clientId, payload.stateName)];
10693
- case 3: return [2 /*return*/, _a.sent()];
10694
11748
  }
10695
11749
  });
10696
11750
  }); };
10697
11751
  }
10698
- return StateUtils;
11752
+ return SharedStorageUtils;
10699
11753
  }());
10700
- /**
10701
- * Instance of StateUtils for managing state.
10702
- * @type {StateUtils}
10703
- */
10704
- var State = new StateUtils();
11754
+ var SharedStorage = new SharedStorageUtils();
10705
11755
 
10706
11756
  /**
10707
11757
  * Function that recursively flattens a nested object to array of entries.
@@ -10799,6 +11849,8 @@ exports.LoggerAdapter = LoggerAdapter;
10799
11849
  exports.LoggerInstance = LoggerInstance;
10800
11850
  exports.MethodContextService = MethodContextService;
10801
11851
  exports.Schema = Schema;
11852
+ exports.SharedState = SharedState;
11853
+ exports.SharedStorage = SharedStorage;
10802
11854
  exports.State = State;
10803
11855
  exports.Storage = Storage;
10804
11856
  exports.addAgent = addAgent;
@@ -10813,6 +11865,8 @@ exports.cancelOutputForce = cancelOutputForce;
10813
11865
  exports.changeToAgent = changeToAgent;
10814
11866
  exports.changeToDefaultAgent = changeToDefaultAgent;
10815
11867
  exports.changeToPrevAgent = changeToPrevAgent;
11868
+ exports.commitAssistantMessage = commitAssistantMessage;
11869
+ exports.commitAssistantMessageForce = commitAssistantMessageForce;
10816
11870
  exports.commitFlush = commitFlush;
10817
11871
  exports.commitFlushForce = commitFlushForce;
10818
11872
  exports.commitSystemMessage = commitSystemMessage;