agent-swarm-kit 1.0.111 → 1.0.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.mjs CHANGED
@@ -1669,6 +1669,7 @@ var AgentSchemaService = /** @class */ (function () {
1669
1669
 
1670
1670
  var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1671
1671
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1672
+ var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1672
1673
  var getPlaceholder = function () {
1673
1674
  return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
1674
1675
  };
@@ -1686,6 +1687,7 @@ var ClientAgent = /** @class */ (function () {
1686
1687
  this.params = params;
1687
1688
  this._agentChangeSubject = new Subject();
1688
1689
  this._toolErrorSubject = new Subject();
1690
+ this._toolStopSubject = new Subject();
1689
1691
  this._toolCommitSubject = new Subject();
1690
1692
  this._outputSubject = new Subject();
1691
1693
  /**
@@ -1985,6 +1987,35 @@ var ClientAgent = /** @class */ (function () {
1985
1987
  }
1986
1988
  });
1987
1989
  }); };
1990
+ /**
1991
+ * Commits change of agent to prevent the next tool execution from being called.
1992
+ * @returns {Promise<void>}
1993
+ */
1994
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
1995
+ return __generator(this, function (_a) {
1996
+ switch (_a.label) {
1997
+ case 0:
1998
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1999
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitStopTools"));
2000
+ return [4 /*yield*/, this._toolStopSubject.next(TOOL_STOP_SYMBOL)];
2001
+ case 1:
2002
+ _a.sent();
2003
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2004
+ type: "commit-stop-tools",
2005
+ source: "agent-bus",
2006
+ input: {},
2007
+ output: {},
2008
+ context: {
2009
+ agentName: this.params.agentName,
2010
+ },
2011
+ clientId: this.params.clientId,
2012
+ })];
2013
+ case 2:
2014
+ _a.sent();
2015
+ return [2 /*return*/];
2016
+ }
2017
+ });
2018
+ }); };
1988
2019
  /**
1989
2020
  * Commits a system message to the history.
1990
2021
  * @param {string} message - The system message to commit.
@@ -2115,9 +2146,9 @@ var ClientAgent = /** @class */ (function () {
2115
2146
  this.execute = queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
2116
2147
  var rawMessage, message, toolCalls, _loop_1, this_1, idx, state_1, result, validation, result1;
2117
2148
  var _this = this;
2118
- var _a, _b, _c, _d, _e, _f, _g;
2119
- return __generator(this, function (_h) {
2120
- switch (_h.label) {
2149
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2150
+ return __generator(this, function (_j) {
2151
+ switch (_j.label) {
2121
2152
  case 0:
2122
2153
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2123
2154
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
@@ -2130,13 +2161,13 @@ var ClientAgent = /** @class */ (function () {
2130
2161
  content: incoming.trim(),
2131
2162
  })];
2132
2163
  case 1:
2133
- _h.sent();
2164
+ _j.sent();
2134
2165
  return [4 /*yield*/, this.getCompletion(mode)];
2135
2166
  case 2:
2136
- rawMessage = _h.sent();
2167
+ rawMessage = _j.sent();
2137
2168
  return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2138
2169
  case 3:
2139
- message = _h.sent();
2170
+ message = _j.sent();
2140
2171
  if (!message.tool_calls) return [3 /*break*/, 9];
2141
2172
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2142
2173
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
@@ -2150,11 +2181,11 @@ var ClientAgent = /** @class */ (function () {
2150
2181
  });
2151
2182
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2152
2183
  case 4:
2153
- _h.sent();
2184
+ _j.sent();
2154
2185
  _loop_1 = function (idx) {
2155
2186
  var tool, targetFn, result_2, result_3, status, result_4;
2156
- return __generator(this, function (_j) {
2157
- switch (_j.label) {
2187
+ return __generator(this, function (_k) {
2188
+ switch (_k.label) {
2158
2189
  case 0:
2159
2190
  tool = toolCalls[idx];
2160
2191
  targetFn = (_a = this_1.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
@@ -2163,12 +2194,12 @@ var ClientAgent = /** @class */ (function () {
2163
2194
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), this_1.params.tools);
2164
2195
  return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
2165
2196
  case 1:
2166
- result_2 = _j.sent();
2197
+ result_2 = _k.sent();
2167
2198
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2168
2199
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
2169
2200
  return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
2170
2201
  case 2:
2171
- _j.sent();
2202
+ _k.sent();
2172
2203
  return [2 /*return*/, { value: void 0 }];
2173
2204
  case 3:
2174
2205
  ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
@@ -2180,17 +2211,17 @@ var ClientAgent = /** @class */ (function () {
2180
2211
  toolCalls: toolCalls,
2181
2212
  }))];
2182
2213
  case 4:
2183
- if (!_j.sent()) return [3 /*break*/, 7];
2214
+ if (!_k.sent()) return [3 /*break*/, 7];
2184
2215
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2185
2216
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
2186
2217
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2187
2218
  case 5:
2188
- result_3 = _j.sent();
2219
+ result_3 = _k.sent();
2189
2220
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2190
2221
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
2191
2222
  return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
2192
2223
  case 6:
2193
- _j.sent();
2224
+ _k.sent();
2194
2225
  return [2 /*return*/, { value: void 0 }];
2195
2226
  case 7:
2196
2227
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
@@ -2230,10 +2261,11 @@ var ClientAgent = /** @class */ (function () {
2230
2261
  this_1._agentChangeSubject.toPromise(),
2231
2262
  this_1._toolCommitSubject.toPromise(),
2232
2263
  this_1._toolErrorSubject.toPromise(),
2264
+ this_1._toolStopSubject.toPromise(),
2233
2265
  this_1._outputSubject.toPromise(),
2234
2266
  ])];
2235
2267
  case 8:
2236
- status = _j.sent();
2268
+ status = _k.sent();
2237
2269
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2238
2270
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
2239
2271
  if (status === AGENT_CHANGE_SYMBOL) {
@@ -2243,17 +2275,24 @@ var ClientAgent = /** @class */ (function () {
2243
2275
  this_1.params.callbacks.onAfterToolCalls(this_1.params.clientId, this_1.params.agentName, toolCalls);
2244
2276
  return [2 /*return*/, { value: void 0 }];
2245
2277
  }
2278
+ if (status === TOOL_STOP_SYMBOL) {
2279
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2280
+ this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the commitStopTools call"));
2281
+ ((_g = this_1.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2282
+ this_1.params.callbacks.onAfterToolCalls(this_1.params.clientId, this_1.params.agentName, toolCalls);
2283
+ return [2 /*return*/, { value: void 0 }];
2284
+ }
2246
2285
  if (!(status === TOOL_ERROR_SYMBOL)) return [3 /*break*/, 11];
2247
2286
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2248
2287
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the call error"));
2249
2288
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function call failed with error: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2250
2289
  case 9:
2251
- result_4 = _j.sent();
2290
+ result_4 = _k.sent();
2252
2291
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2253
2292
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_4));
2254
2293
  return [4 /*yield*/, this_1._emitOuput(mode, result_4)];
2255
2294
  case 10:
2256
- _j.sent();
2295
+ _k.sent();
2257
2296
  return [2 /*return*/, { value: void 0 }];
2258
2297
  case 11: return [2 /*return*/];
2259
2298
  }
@@ -2261,20 +2300,20 @@ var ClientAgent = /** @class */ (function () {
2261
2300
  };
2262
2301
  this_1 = this;
2263
2302
  idx = 0;
2264
- _h.label = 5;
2303
+ _j.label = 5;
2265
2304
  case 5:
2266
2305
  if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
2267
2306
  return [5 /*yield**/, _loop_1(idx)];
2268
2307
  case 6:
2269
- state_1 = _h.sent();
2308
+ state_1 = _j.sent();
2270
2309
  if (typeof state_1 === "object")
2271
2310
  return [2 /*return*/, state_1.value];
2272
- _h.label = 7;
2311
+ _j.label = 7;
2273
2312
  case 7:
2274
2313
  idx++;
2275
2314
  return [3 /*break*/, 5];
2276
2315
  case 8:
2277
- ((_g = this.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2316
+ ((_h = this.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2278
2317
  this.params.callbacks.onAfterToolCalls(this.params.clientId, this.params.agentName, toolCalls);
2279
2318
  return [2 /*return*/];
2280
2319
  case 9:
@@ -2284,29 +2323,29 @@ var ClientAgent = /** @class */ (function () {
2284
2323
  }
2285
2324
  return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2286
2325
  case 10:
2287
- result = _h.sent();
2326
+ result = _j.sent();
2288
2327
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2289
2328
  case 11:
2290
- _h.sent();
2329
+ _j.sent();
2291
2330
  validation = null;
2292
2331
  return [4 /*yield*/, this.params.validate(result)];
2293
2332
  case 12:
2294
- if (!(validation = _h.sent())) return [3 /*break*/, 15];
2333
+ if (!(validation = _j.sent())) return [3 /*break*/, 15];
2295
2334
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2296
2335
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
2297
2336
  return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
2298
2337
  case 13:
2299
- result1 = _h.sent();
2338
+ result1 = _j.sent();
2300
2339
  return [4 /*yield*/, this._emitOuput(mode, result1)];
2301
2340
  case 14:
2302
- _h.sent();
2341
+ _j.sent();
2303
2342
  return [2 /*return*/];
2304
2343
  case 15:
2305
2344
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2306
2345
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
2307
2346
  return [4 /*yield*/, this._emitOuput(mode, result)];
2308
2347
  case 16:
2309
- _h.sent();
2348
+ _j.sent();
2310
2349
  return [2 /*return*/];
2311
2350
  }
2312
2351
  });
@@ -2497,6 +2536,21 @@ var AgentConnectionService = /** @class */ (function () {
2497
2536
  }
2498
2537
  });
2499
2538
  }); };
2539
+ /**
2540
+ * Prevent the next tool from being executed
2541
+ * @returns {Promise<any>} The commit result.
2542
+ */
2543
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
2544
+ return __generator(this, function (_a) {
2545
+ switch (_a.label) {
2546
+ case 0:
2547
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
2548
+ this.loggerService.info("agentConnectionService commitStopTools");
2549
+ return [4 /*yield*/, this.getAgent(this.methodContextService.context.clientId, this.methodContextService.context.agentName).commitStopTools()];
2550
+ case 1: return [2 /*return*/, _a.sent()];
2551
+ }
2552
+ });
2553
+ }); };
2500
2554
  /**
2501
2555
  * Commits flush of agent history
2502
2556
  * @returns {Promise<any>} The commit result.
@@ -3790,6 +3844,39 @@ var ClientSession = /** @class */ (function () {
3790
3844
  }
3791
3845
  });
3792
3846
  }); };
3847
+ /**
3848
+ * Commits stop of the nexttool execution
3849
+ * @returns {Promise<void>}
3850
+ */
3851
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
3852
+ var agent, result;
3853
+ return __generator(this, function (_a) {
3854
+ switch (_a.label) {
3855
+ case 0:
3856
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3857
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitStopTools"));
3858
+ return [4 /*yield*/, this.params.swarm.getAgent()];
3859
+ case 1:
3860
+ agent = _a.sent();
3861
+ return [4 /*yield*/, agent.commitStopTools()];
3862
+ case 2:
3863
+ result = _a.sent();
3864
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
3865
+ type: "commit-stop-tools",
3866
+ source: "session-bus",
3867
+ input: {},
3868
+ output: {},
3869
+ context: {
3870
+ swarmName: this.params.swarmName,
3871
+ },
3872
+ clientId: this.params.clientId,
3873
+ })];
3874
+ case 3:
3875
+ _a.sent();
3876
+ return [2 /*return*/, result];
3877
+ }
3878
+ });
3879
+ }); };
3793
3880
  /**
3794
3881
  * Commits a system message.
3795
3882
  * @param {string} message - The system message to commit.
@@ -4117,6 +4204,22 @@ var SessionConnectionService = /** @class */ (function () {
4117
4204
  }
4118
4205
  });
4119
4206
  }); };
4207
+ /**
4208
+ * Commits user message to the agent without answer.
4209
+ * @param {string} message - The message to commit.
4210
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
4211
+ */
4212
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
4213
+ return __generator(this, function (_a) {
4214
+ switch (_a.label) {
4215
+ case 0:
4216
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4217
+ this.loggerService.info("sessionConnectionService commitStopTools");
4218
+ return [4 /*yield*/, this.getSession(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).commitStopTools()];
4219
+ case 1: return [2 /*return*/, _a.sent()];
4220
+ }
4221
+ });
4222
+ }); };
4120
4223
  /**
4121
4224
  * Disposes of the session connection service.
4122
4225
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -4489,6 +4592,42 @@ var AgentPublicService = /** @class */ (function () {
4489
4592
  }
4490
4593
  });
4491
4594
  }); };
4595
+ /**
4596
+ * Prevent the next tool from being executed
4597
+ * @param {string} clientId - The client ID.
4598
+ * @param {AgentName} agentName - The name of the agent.
4599
+ * @returns {Promise<unknown>} The commit result.
4600
+ */
4601
+ this.commitStopTools = function (methodName, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
4602
+ var _this = this;
4603
+ return __generator(this, function (_a) {
4604
+ switch (_a.label) {
4605
+ case 0:
4606
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4607
+ this.loggerService.info("agentPublicService commitStopTools", {
4608
+ methodName: methodName,
4609
+ clientId: clientId,
4610
+ agentName: agentName,
4611
+ });
4612
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4613
+ return __generator(this, function (_a) {
4614
+ switch (_a.label) {
4615
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitStopTools()];
4616
+ case 1: return [2 /*return*/, _a.sent()];
4617
+ }
4618
+ });
4619
+ }); }, {
4620
+ methodName: methodName,
4621
+ clientId: clientId,
4622
+ agentName: agentName,
4623
+ swarmName: "",
4624
+ storageName: "",
4625
+ stateName: "",
4626
+ })];
4627
+ case 1: return [2 /*return*/, _a.sent()];
4628
+ }
4629
+ });
4630
+ }); };
4492
4631
  /**
4493
4632
  * Disposes of the agent.
4494
4633
  * @param {string} clientId - The client ID.
@@ -5002,6 +5141,41 @@ var SessionPublicService = /** @class */ (function () {
5002
5141
  }
5003
5142
  });
5004
5143
  }); };
5144
+ /**
5145
+ * Prevent the next tool from being executed
5146
+ * @param {string} clientId - The client ID.
5147
+ * @param {SwarmName} swarmName - The swarm name.
5148
+ * @returns {Promise<void>}
5149
+ */
5150
+ this.commitStopTools = function (methodName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
5151
+ var _this = this;
5152
+ return __generator(this, function (_a) {
5153
+ switch (_a.label) {
5154
+ case 0:
5155
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5156
+ this.loggerService.info("sessionPublicService commitStopTools", {
5157
+ clientId: clientId,
5158
+ swarmName: swarmName,
5159
+ });
5160
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
5161
+ return __generator(this, function (_a) {
5162
+ switch (_a.label) {
5163
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitStopTools()];
5164
+ case 1: return [2 /*return*/, _a.sent()];
5165
+ }
5166
+ });
5167
+ }); }, {
5168
+ methodName: methodName,
5169
+ clientId: clientId,
5170
+ swarmName: swarmName,
5171
+ agentName: "",
5172
+ storageName: "",
5173
+ stateName: "",
5174
+ })];
5175
+ case 1: return [2 /*return*/, _a.sent()];
5176
+ }
5177
+ });
5178
+ }); };
5005
5179
  /**
5006
5180
  * Disposes of the session.
5007
5181
  * @param {string} clientId - The client ID.
@@ -7254,6 +7428,53 @@ var ClientState = /** @class */ (function () {
7254
7428
  }
7255
7429
  });
7256
7430
  }); };
7431
+ /**
7432
+ * Sets the to initial value
7433
+ * @returns {Promise<State>}
7434
+ */
7435
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
7436
+ var _this = this;
7437
+ var _a;
7438
+ return __generator(this, function (_b) {
7439
+ switch (_b.label) {
7440
+ case 0:
7441
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7442
+ this.params.logger.debug("ClientState stateName=".concat(this.params.stateName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " clearState"));
7443
+ return [4 /*yield*/, this.dispatch("write", function () { return __awaiter(_this, void 0, void 0, function () {
7444
+ return __generator(this, function (_a) {
7445
+ switch (_a.label) {
7446
+ case 0: return [4 /*yield*/, this.params.getState(this.params.clientId, this.params.stateName)];
7447
+ case 1: return [2 /*return*/, _a.sent()];
7448
+ }
7449
+ });
7450
+ }); })];
7451
+ case 1:
7452
+ _b.sent();
7453
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7454
+ this.params.logger.debug("ClientState stateName=".concat(this.params.stateName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " clearState output"), { pendingState: this._state });
7455
+ this.params.setState &&
7456
+ this.params.setState(this._state, this.params.clientId, this.params.stateName);
7457
+ if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onWrite) {
7458
+ this.params.callbacks.onWrite(this._state, this.params.clientId, this.params.stateName);
7459
+ }
7460
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
7461
+ type: "clear-state",
7462
+ source: "state-bus",
7463
+ input: {},
7464
+ output: {
7465
+ state: this._state,
7466
+ },
7467
+ context: {
7468
+ stateName: this.params.stateName,
7469
+ },
7470
+ clientId: this.params.clientId,
7471
+ })];
7472
+ case 2:
7473
+ _b.sent();
7474
+ return [2 /*return*/, this._state];
7475
+ }
7476
+ });
7477
+ }); };
7257
7478
  /**
7258
7479
  * Gets the current state.
7259
7480
  * @returns {Promise<State>}
@@ -7391,6 +7612,26 @@ var StateConnectionService = /** @class */ (function () {
7391
7612
  }
7392
7613
  });
7393
7614
  }); };
7615
+ /**
7616
+ * Set the state to initial value
7617
+ * @returns {Promise<T>} The initial state.
7618
+ */
7619
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
7620
+ var state;
7621
+ return __generator(this, function (_a) {
7622
+ switch (_a.label) {
7623
+ case 0:
7624
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7625
+ this.loggerService.info("stateConnectionService clearState");
7626
+ state = this.getStateRef(this.methodContextService.context.clientId, this.methodContextService.context.stateName);
7627
+ return [4 /*yield*/, state.waitForInit()];
7628
+ case 1:
7629
+ _a.sent();
7630
+ return [4 /*yield*/, state.clearState()];
7631
+ case 2: return [2 /*return*/, _a.sent()];
7632
+ }
7633
+ });
7634
+ }); };
7394
7635
  /**
7395
7636
  * Gets the state.
7396
7637
  * @returns {Promise<T>} The current state.
@@ -7488,6 +7729,42 @@ var StatePublicService = /** @class */ (function () {
7488
7729
  }
7489
7730
  });
7490
7731
  }); };
7732
+ /**
7733
+ * Set the state to initial value
7734
+ * @param {string} clientId - The client ID.
7735
+ * @param {StateName} stateName - The name of the state.
7736
+ * @returns {Promise<T>} - The initial state.
7737
+ */
7738
+ this.clearState = function (methodName, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
7739
+ var _this = this;
7740
+ return __generator(this, function (_a) {
7741
+ switch (_a.label) {
7742
+ case 0:
7743
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7744
+ this.loggerService.info("statePublicService clearState", {
7745
+ methodName: methodName,
7746
+ clientId: clientId,
7747
+ stateName: stateName,
7748
+ });
7749
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
7750
+ return __generator(this, function (_a) {
7751
+ switch (_a.label) {
7752
+ case 0: return [4 /*yield*/, this.stateConnectionService.clearState()];
7753
+ case 1: return [2 /*return*/, _a.sent()];
7754
+ }
7755
+ });
7756
+ }); }, {
7757
+ methodName: methodName,
7758
+ clientId: clientId,
7759
+ stateName: stateName,
7760
+ agentName: "",
7761
+ swarmName: "",
7762
+ storageName: "",
7763
+ })];
7764
+ case 1: return [2 /*return*/, _a.sent()];
7765
+ }
7766
+ });
7767
+ }); };
7491
7768
  /**
7492
7769
  * Gets the current state.
7493
7770
  * @param {string} clientId - The client ID.
@@ -8357,6 +8634,26 @@ var SharedStateConnectionService = /** @class */ (function () {
8357
8634
  }
8358
8635
  });
8359
8636
  }); };
8637
+ /**
8638
+ * Set the state to initial value
8639
+ * @returns {Promise<T>} The new state.
8640
+ */
8641
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
8642
+ var state;
8643
+ return __generator(this, function (_a) {
8644
+ switch (_a.label) {
8645
+ case 0:
8646
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8647
+ this.loggerService.info("sharedStateConnectionService clearState");
8648
+ state = this.getStateRef(this.methodContextService.context.stateName);
8649
+ return [4 /*yield*/, state.waitForInit()];
8650
+ case 1:
8651
+ _a.sent();
8652
+ return [4 /*yield*/, state.clearState()];
8653
+ case 2: return [2 /*return*/, _a.sent()];
8654
+ }
8655
+ });
8656
+ }); };
8360
8657
  /**
8361
8658
  * Gets the state.
8362
8659
  * @returns {Promise<T>} The current state.
@@ -8590,6 +8887,40 @@ var SharedStatePublicService = /** @class */ (function () {
8590
8887
  }
8591
8888
  });
8592
8889
  }); };
8890
+ /**
8891
+ * Set the state to initial value
8892
+ * @param {StateName} stateName - The name of the state.
8893
+ * @returns {Promise<T>} - The initial state.
8894
+ */
8895
+ this.clearState = function (methodName, stateName) { return __awaiter(_this, void 0, void 0, function () {
8896
+ var _this = this;
8897
+ return __generator(this, function (_a) {
8898
+ switch (_a.label) {
8899
+ case 0:
8900
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8901
+ this.loggerService.info("sharedStatePublicService clearState", {
8902
+ methodName: methodName,
8903
+ stateName: stateName,
8904
+ });
8905
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8906
+ return __generator(this, function (_a) {
8907
+ switch (_a.label) {
8908
+ case 0: return [4 /*yield*/, this.sharedStateConnectionService.clearState()];
8909
+ case 1: return [2 /*return*/, _a.sent()];
8910
+ }
8911
+ });
8912
+ }); }, {
8913
+ methodName: methodName,
8914
+ clientId: "",
8915
+ stateName: stateName,
8916
+ agentName: "",
8917
+ swarmName: "",
8918
+ storageName: "",
8919
+ })];
8920
+ case 1: return [2 /*return*/, _a.sent()];
8921
+ }
8922
+ });
8923
+ }); };
8593
8924
  /**
8594
8925
  * Gets the current state.
8595
8926
  * @param {StateName} stateName - The name of the state.
@@ -8889,12 +9220,6 @@ var SharedStoragePublicService = /** @class */ (function () {
8889
9220
  provide(TYPES.swarmMetaService, function () { return new SwarmMetaService(); });
8890
9221
  provide(TYPES.agentMetaService, function () { return new AgentMetaService(); });
8891
9222
  }
8892
- {
8893
- provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
8894
- provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
8895
- provide(TYPES.sessionPublicService, function () { return new SessionPublicService(); });
8896
- provide(TYPES.swarmPublicService, function () { return new SwarmPublicService(); });
8897
- }
8898
9223
  {
8899
9224
  provide(TYPES.agentValidationService, function () { return new AgentValidationService(); });
8900
9225
  provide(TYPES.completionValidationService, function () { return new CompletionValidationService(); });
@@ -8960,7 +9285,7 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
8960
9285
  init();
8961
9286
  var swarm$1 = swarm;
8962
9287
 
8963
- var METHOD_NAME$J = "cli.dumpDocs";
9288
+ var METHOD_NAME$L = "cli.dumpDocs";
8964
9289
  /**
8965
9290
  * Dumps the documentation for the agents and swarms.
8966
9291
  *
@@ -8971,7 +9296,7 @@ var METHOD_NAME$J = "cli.dumpDocs";
8971
9296
  var dumpDocs = function (dirName, PlantUML) {
8972
9297
  if (dirName === void 0) { dirName = "./docs/chat"; }
8973
9298
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8974
- swarm$1.loggerService.log(METHOD_NAME$J, {
9299
+ swarm$1.loggerService.log(METHOD_NAME$L, {
8975
9300
  dirName: dirName,
8976
9301
  });
8977
9302
  if (PlantUML) {
@@ -8982,12 +9307,12 @@ var dumpDocs = function (dirName, PlantUML) {
8982
9307
  swarm$1.agentValidationService
8983
9308
  .getAgentList()
8984
9309
  .forEach(function (agentName) {
8985
- return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
9310
+ return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$L);
8986
9311
  });
8987
9312
  swarm$1.swarmValidationService
8988
9313
  .getSwarmList()
8989
9314
  .forEach(function (swarmName) {
8990
- return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9315
+ return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$L);
8991
9316
  });
8992
9317
  swarm$1.agentValidationService.getAgentList().forEach(function (agentName) {
8993
9318
  var dependsOn = swarm$1.agentSchemaService.get(agentName).dependsOn;
@@ -8998,7 +9323,7 @@ var dumpDocs = function (dirName, PlantUML) {
8998
9323
  return swarm$1.docService.dumpDocs(dirName);
8999
9324
  };
9000
9325
 
9001
- var METHOD_NAME$I = "cli.dumpAgent";
9326
+ var METHOD_NAME$K = "cli.dumpAgent";
9002
9327
  /**
9003
9328
  * Dumps the agent information into PlantUML format.
9004
9329
  *
@@ -9008,14 +9333,14 @@ var METHOD_NAME$I = "cli.dumpAgent";
9008
9333
  var dumpAgent = function (agentName, _a) {
9009
9334
  var _b = _a === void 0 ? {} : _a, _c = _b.withSubtree, withSubtree = _c === void 0 ? false : _c;
9010
9335
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9011
- swarm$1.loggerService.log(METHOD_NAME$I, {
9336
+ swarm$1.loggerService.log(METHOD_NAME$K, {
9012
9337
  agentName: agentName,
9013
9338
  });
9014
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$I);
9339
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$K);
9015
9340
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
9016
9341
  };
9017
9342
 
9018
- var METHOD_NAME$H = "cli.dumpSwarm";
9343
+ var METHOD_NAME$J = "cli.dumpSwarm";
9019
9344
  /**
9020
9345
  * Dumps the swarm information into PlantUML format.
9021
9346
  *
@@ -9024,14 +9349,14 @@ var METHOD_NAME$H = "cli.dumpSwarm";
9024
9349
  */
9025
9350
  var dumpSwarm = function (swarmName) {
9026
9351
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9027
- swarm$1.loggerService.log(METHOD_NAME$H, {
9352
+ swarm$1.loggerService.log(METHOD_NAME$J, {
9028
9353
  swarmName: swarmName,
9029
9354
  });
9030
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
9355
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9031
9356
  return swarm$1.swarmMetaService.toUML(swarmName);
9032
9357
  };
9033
9358
 
9034
- var METHOD_NAME$G = "function.addAgent";
9359
+ var METHOD_NAME$I = "function.addAgent";
9035
9360
  /**
9036
9361
  * Adds a new agent to the agent registry. The swarm takes only those agents which was registered
9037
9362
  *
@@ -9040,7 +9365,7 @@ var METHOD_NAME$G = "function.addAgent";
9040
9365
  */
9041
9366
  var addAgent = function (agentSchema) {
9042
9367
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9043
- swarm$1.loggerService.log(METHOD_NAME$G, {
9368
+ swarm$1.loggerService.log(METHOD_NAME$I, {
9044
9369
  agentSchema: agentSchema,
9045
9370
  });
9046
9371
  swarm$1.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
@@ -9048,7 +9373,7 @@ var addAgent = function (agentSchema) {
9048
9373
  return agentSchema.agentName;
9049
9374
  };
9050
9375
 
9051
- var METHOD_NAME$F = "function.addCompletion";
9376
+ var METHOD_NAME$H = "function.addCompletion";
9052
9377
  /**
9053
9378
  * Adds a completion engine for agents. Agents could use different models and
9054
9379
  * framewords for completion like: mock, gpt4all, ollama, openai
@@ -9058,7 +9383,7 @@ var METHOD_NAME$F = "function.addCompletion";
9058
9383
  */
9059
9384
  var addCompletion = function (completionSchema) {
9060
9385
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9061
- swarm$1.loggerService.log(METHOD_NAME$F, {
9386
+ swarm$1.loggerService.log(METHOD_NAME$H, {
9062
9387
  completionSchema: completionSchema,
9063
9388
  });
9064
9389
  swarm$1.completionValidationService.addCompletion(completionSchema.completionName);
@@ -9066,7 +9391,7 @@ var addCompletion = function (completionSchema) {
9066
9391
  return completionSchema.completionName;
9067
9392
  };
9068
9393
 
9069
- var METHOD_NAME$E = "function.addSwarm";
9394
+ var METHOD_NAME$G = "function.addSwarm";
9070
9395
  /**
9071
9396
  * Adds a new swarm to the system. The swarm is a root for starting client session
9072
9397
  *
@@ -9075,7 +9400,7 @@ var METHOD_NAME$E = "function.addSwarm";
9075
9400
  */
9076
9401
  var addSwarm = function (swarmSchema) {
9077
9402
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9078
- swarm$1.loggerService.log(METHOD_NAME$E, {
9403
+ swarm$1.loggerService.log(METHOD_NAME$G, {
9079
9404
  swarmSchema: swarmSchema,
9080
9405
  });
9081
9406
  swarm$1.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
@@ -9083,7 +9408,7 @@ var addSwarm = function (swarmSchema) {
9083
9408
  return swarmSchema.swarmName;
9084
9409
  };
9085
9410
 
9086
- var METHOD_NAME$D = "function.addTool";
9411
+ var METHOD_NAME$F = "function.addTool";
9087
9412
  /**
9088
9413
  * Adds a new tool for agents in a swarm. Tool should be registered in `addAgent`
9089
9414
  * declaration
@@ -9093,7 +9418,7 @@ var METHOD_NAME$D = "function.addTool";
9093
9418
  */
9094
9419
  var addTool = function (toolSchema) {
9095
9420
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9096
- swarm$1.loggerService.log(METHOD_NAME$D, {
9421
+ swarm$1.loggerService.log(METHOD_NAME$F, {
9097
9422
  toolSchema: toolSchema,
9098
9423
  });
9099
9424
  swarm$1.toolValidationService.addTool(toolSchema.toolName, toolSchema);
@@ -9101,7 +9426,7 @@ var addTool = function (toolSchema) {
9101
9426
  return toolSchema.toolName;
9102
9427
  };
9103
9428
 
9104
- var METHOD_NAME$C = "function.addState";
9429
+ var METHOD_NAME$E = "function.addState";
9105
9430
  /**
9106
9431
  * Adds a new state to the state registry. The swarm takes only those states which was registered
9107
9432
  *
@@ -9110,7 +9435,7 @@ var METHOD_NAME$C = "function.addState";
9110
9435
  */
9111
9436
  var addState = function (stateSchema) {
9112
9437
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9113
- swarm$1.loggerService.log(METHOD_NAME$C, {
9438
+ swarm$1.loggerService.log(METHOD_NAME$E, {
9114
9439
  stateSchema: stateSchema,
9115
9440
  });
9116
9441
  swarm$1.stateSchemaService.register(stateSchema.stateName, stateSchema);
@@ -9122,7 +9447,7 @@ var addState = function (stateSchema) {
9122
9447
  return stateSchema.stateName;
9123
9448
  };
9124
9449
 
9125
- var METHOD_NAME$B = "function.addEmbedding";
9450
+ var METHOD_NAME$D = "function.addEmbedding";
9126
9451
  /**
9127
9452
  * Adds a new embedding to the embedding registry. The swarm takes only those embeddings which was registered
9128
9453
  *
@@ -9131,7 +9456,7 @@ var METHOD_NAME$B = "function.addEmbedding";
9131
9456
  */
9132
9457
  var addEmbedding = function (embeddingSchema) {
9133
9458
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9134
- swarm$1.loggerService.log(METHOD_NAME$B, {
9459
+ swarm$1.loggerService.log(METHOD_NAME$D, {
9135
9460
  embeddingSchema: embeddingSchema,
9136
9461
  });
9137
9462
  swarm$1.embeddingValidationService.addEmbedding(embeddingSchema.embeddingName, embeddingSchema);
@@ -9139,7 +9464,7 @@ var addEmbedding = function (embeddingSchema) {
9139
9464
  return embeddingSchema.embeddingName;
9140
9465
  };
9141
9466
 
9142
- var METHOD_NAME$A = "function.addStorage";
9467
+ var METHOD_NAME$C = "function.addStorage";
9143
9468
  /**
9144
9469
  * Adds a new storage to the storage registry. The swarm takes only those storages which was registered
9145
9470
  *
@@ -9148,7 +9473,7 @@ var METHOD_NAME$A = "function.addStorage";
9148
9473
  */
9149
9474
  var addStorage = function (storageSchema) {
9150
9475
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9151
- swarm$1.loggerService.log(METHOD_NAME$A, {
9476
+ swarm$1.loggerService.log(METHOD_NAME$C, {
9152
9477
  storageSchema: storageSchema,
9153
9478
  });
9154
9479
  swarm$1.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
@@ -9161,7 +9486,7 @@ var addStorage = function (storageSchema) {
9161
9486
  return storageSchema.storageName;
9162
9487
  };
9163
9488
 
9164
- var METHOD_NAME$z = "function.commitToolOutput";
9489
+ var METHOD_NAME$B = "function.commitToolOutput";
9165
9490
  /**
9166
9491
  * Commits the tool output to the active agent in a swarm session
9167
9492
  *
@@ -9176,17 +9501,17 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9176
9501
  switch (_a.label) {
9177
9502
  case 0:
9178
9503
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9179
- swarm$1.loggerService.log(METHOD_NAME$z, {
9504
+ swarm$1.loggerService.log(METHOD_NAME$B, {
9180
9505
  toolId: toolId,
9181
9506
  content: content,
9182
9507
  clientId: clientId,
9183
9508
  agentName: agentName,
9184
9509
  });
9185
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9186
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
9510
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$B);
9511
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
9187
9512
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9188
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9189
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName)];
9513
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
9514
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$B, clientId, swarmName)];
9190
9515
  case 1:
9191
9516
  currentAgentName = _a.sent();
9192
9517
  if (currentAgentName !== agentName) {
@@ -9199,7 +9524,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9199
9524
  });
9200
9525
  return [2 /*return*/];
9201
9526
  }
9202
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$z, clientId, swarmName)];
9527
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$B, clientId, swarmName)];
9203
9528
  case 2:
9204
9529
  _a.sent();
9205
9530
  return [2 /*return*/];
@@ -9207,7 +9532,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9207
9532
  });
9208
9533
  }); };
9209
9534
 
9210
- var METHOD_NAME$y = "function.commitSystemMessage";
9535
+ var METHOD_NAME$A = "function.commitSystemMessage";
9211
9536
  /**
9212
9537
  * Commits a system message to the active agent in the swarm.
9213
9538
  *
@@ -9222,16 +9547,16 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9222
9547
  switch (_a.label) {
9223
9548
  case 0:
9224
9549
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9225
- swarm$1.loggerService.log(METHOD_NAME$y, {
9550
+ swarm$1.loggerService.log(METHOD_NAME$A, {
9226
9551
  content: content,
9227
9552
  clientId: clientId,
9228
9553
  agentName: agentName,
9229
9554
  });
9230
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9231
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
9555
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$A);
9556
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
9232
9557
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9233
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9234
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName)];
9558
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
9559
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$A, clientId, swarmName)];
9235
9560
  case 1:
9236
9561
  currentAgentName = _a.sent();
9237
9562
  if (currentAgentName !== agentName) {
@@ -9243,7 +9568,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9243
9568
  });
9244
9569
  return [2 /*return*/];
9245
9570
  }
9246
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$y, clientId, swarmName)];
9571
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$A, clientId, swarmName)];
9247
9572
  case 2:
9248
9573
  _a.sent();
9249
9574
  return [2 /*return*/];
@@ -9251,7 +9576,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9251
9576
  });
9252
9577
  }); };
9253
9578
 
9254
- var METHOD_NAME$x = "function.commitFlush";
9579
+ var METHOD_NAME$z = "function.commitFlush";
9255
9580
  /**
9256
9581
  * Commits flush of agent history
9257
9582
  *
@@ -9265,15 +9590,15 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9265
9590
  switch (_a.label) {
9266
9591
  case 0:
9267
9592
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9268
- swarm$1.loggerService.log(METHOD_NAME$x, {
9593
+ swarm$1.loggerService.log(METHOD_NAME$z, {
9269
9594
  clientId: clientId,
9270
9595
  agentName: agentName,
9271
9596
  });
9272
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
9273
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9597
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9598
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
9274
9599
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9275
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9276
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$x, clientId, swarmName)];
9600
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9601
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName)];
9277
9602
  case 1:
9278
9603
  currentAgentName = _a.sent();
9279
9604
  if (currentAgentName !== agentName) {
@@ -9285,7 +9610,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9285
9610
  });
9286
9611
  return [2 /*return*/];
9287
9612
  }
9288
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$x, clientId, swarmName)];
9613
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$z, clientId, swarmName)];
9289
9614
  case 2:
9290
9615
  _a.sent();
9291
9616
  return [2 /*return*/];
@@ -9293,7 +9618,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9293
9618
  });
9294
9619
  }); };
9295
9620
 
9296
- var METHOD_NAME$w = "function.commitSystemMessage";
9621
+ var METHOD_NAME$y = "function.commitSystemMessage";
9297
9622
  /**
9298
9623
  * Commits a user message to the active agent history in as swarm without answer.
9299
9624
  *
@@ -9308,16 +9633,16 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9308
9633
  switch (_a.label) {
9309
9634
  case 0:
9310
9635
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9311
- swarm$1.loggerService.log(METHOD_NAME$w, {
9636
+ swarm$1.loggerService.log(METHOD_NAME$y, {
9312
9637
  content: content,
9313
9638
  clientId: clientId,
9314
9639
  agentName: agentName,
9315
9640
  });
9316
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
9317
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9641
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9642
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
9318
9643
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9319
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9320
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$w, clientId, swarmName)];
9644
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9645
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName)];
9321
9646
  case 1:
9322
9647
  currentAgentName = _a.sent();
9323
9648
  if (currentAgentName !== agentName) {
@@ -9329,7 +9654,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9329
9654
  });
9330
9655
  return [2 /*return*/];
9331
9656
  }
9332
- return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$w, clientId, swarmName)];
9657
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$y, clientId, swarmName)];
9333
9658
  case 2:
9334
9659
  _a.sent();
9335
9660
  return [2 /*return*/];
@@ -9337,7 +9662,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9337
9662
  });
9338
9663
  }); };
9339
9664
 
9340
- var METHOD_NAME$v = "function.commitToolOutputForce";
9665
+ var METHOD_NAME$x = "function.commitToolOutputForce";
9341
9666
  /**
9342
9667
  * Commits the tool output to the active agent in a swarm session without checking active agent
9343
9668
  *
@@ -9351,15 +9676,15 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9351
9676
  switch (_a.label) {
9352
9677
  case 0:
9353
9678
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9354
- swarm$1.loggerService.log(METHOD_NAME$v, {
9679
+ swarm$1.loggerService.log(METHOD_NAME$x, {
9355
9680
  toolId: toolId,
9356
9681
  content: content,
9357
9682
  clientId: clientId,
9358
9683
  });
9359
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9684
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9360
9685
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9361
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9362
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$v, clientId, swarmName)];
9686
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9687
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$x, clientId, swarmName)];
9363
9688
  case 1:
9364
9689
  _a.sent();
9365
9690
  return [2 /*return*/];
@@ -9367,7 +9692,7 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9367
9692
  });
9368
9693
  }); };
9369
9694
 
9370
- var METHOD_NAME$u = "function.commitSystemMessageForce";
9695
+ var METHOD_NAME$w = "function.commitSystemMessageForce";
9371
9696
  /**
9372
9697
  * Commits a system message to the active agent in as swarm without checking active agent.
9373
9698
  *
@@ -9381,14 +9706,14 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9381
9706
  switch (_a.label) {
9382
9707
  case 0:
9383
9708
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9384
- swarm$1.loggerService.log(METHOD_NAME$u, {
9709
+ swarm$1.loggerService.log(METHOD_NAME$w, {
9385
9710
  content: content,
9386
9711
  clientId: clientId,
9387
9712
  });
9388
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9713
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9389
9714
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9390
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9391
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$u, clientId, swarmName)];
9715
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9716
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$w, clientId, swarmName)];
9392
9717
  case 1:
9393
9718
  _a.sent();
9394
9719
  return [2 /*return*/];
@@ -9396,7 +9721,7 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9396
9721
  });
9397
9722
  }); };
9398
9723
 
9399
- var METHOD_NAME$t = "function.commitFlushForce";
9724
+ var METHOD_NAME$v = "function.commitFlushForce";
9400
9725
  /**
9401
9726
  * Commits flush of agent history without active agent check
9402
9727
  *
@@ -9409,14 +9734,14 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9409
9734
  switch (_a.label) {
9410
9735
  case 0:
9411
9736
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9412
- swarm$1.loggerService.log(METHOD_NAME$t, {
9737
+ swarm$1.loggerService.log(METHOD_NAME$v, {
9413
9738
  clientId: clientId,
9414
- METHOD_NAME: METHOD_NAME$t,
9739
+ METHOD_NAME: METHOD_NAME$v,
9415
9740
  });
9416
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9741
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9417
9742
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9418
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9419
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$t, clientId, swarmName)];
9743
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9744
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$v, clientId, swarmName)];
9420
9745
  case 1:
9421
9746
  _a.sent();
9422
9747
  return [2 /*return*/];
@@ -9424,7 +9749,7 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9424
9749
  });
9425
9750
  }); };
9426
9751
 
9427
- var METHOD_NAME$s = "function.commitSystemMessage";
9752
+ var METHOD_NAME$u = "function.commitSystemMessage";
9428
9753
  /**
9429
9754
  * Commits a user message to the active agent history in as swarm without answer and checking active agent
9430
9755
  *
@@ -9438,14 +9763,14 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9438
9763
  switch (_a.label) {
9439
9764
  case 0:
9440
9765
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9441
- swarm$1.loggerService.log(METHOD_NAME$s, {
9766
+ swarm$1.loggerService.log(METHOD_NAME$u, {
9442
9767
  content: content,
9443
9768
  clientId: clientId,
9444
9769
  });
9445
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9770
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9446
9771
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9447
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
9448
- return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$s, clientId, swarmName)];
9772
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9773
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$u, clientId, swarmName)];
9449
9774
  case 1:
9450
9775
  _a.sent();
9451
9776
  return [2 /*return*/];
@@ -9453,7 +9778,7 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9453
9778
  });
9454
9779
  }); };
9455
9780
 
9456
- var METHOD_NAME$r = "function.commitAssistantMessage";
9781
+ var METHOD_NAME$t = "function.commitAssistantMessage";
9457
9782
  /**
9458
9783
  * Commits an assistant message to the active agent in the swarm.
9459
9784
  *
@@ -9468,16 +9793,16 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9468
9793
  switch (_a.label) {
9469
9794
  case 0:
9470
9795
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9471
- swarm$1.loggerService.log(METHOD_NAME$r, {
9796
+ swarm$1.loggerService.log(METHOD_NAME$t, {
9472
9797
  content: content,
9473
9798
  clientId: clientId,
9474
9799
  agentName: agentName,
9475
9800
  });
9476
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9477
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9801
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$t);
9802
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9478
9803
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9479
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
9480
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName)];
9804
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9805
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$t, clientId, swarmName)];
9481
9806
  case 1:
9482
9807
  currentAgentName = _a.sent();
9483
9808
  if (currentAgentName !== agentName) {
@@ -9489,7 +9814,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9489
9814
  });
9490
9815
  return [2 /*return*/];
9491
9816
  }
9492
- return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$r, clientId, swarmName)];
9817
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$t, clientId, swarmName)];
9493
9818
  case 2:
9494
9819
  _a.sent();
9495
9820
  return [2 /*return*/];
@@ -9497,7 +9822,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9497
9822
  });
9498
9823
  }); };
9499
9824
 
9500
- var METHOD_NAME$q = "function.commitAssistantMessageForce";
9825
+ var METHOD_NAME$s = "function.commitAssistantMessageForce";
9501
9826
  /**
9502
9827
  * Commits an assistant message to the active agent in as swarm without checking active agent.
9503
9828
  *
@@ -9511,14 +9836,14 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9511
9836
  switch (_a.label) {
9512
9837
  case 0:
9513
9838
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9514
- swarm$1.loggerService.log(METHOD_NAME$q, {
9839
+ swarm$1.loggerService.log(METHOD_NAME$s, {
9515
9840
  content: content,
9516
9841
  clientId: clientId,
9517
9842
  });
9518
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
9843
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9519
9844
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9520
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
9521
- return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$q, clientId, swarmName)];
9845
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
9846
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$s, clientId, swarmName)];
9522
9847
  case 1:
9523
9848
  _a.sent();
9524
9849
  return [2 /*return*/];
@@ -9526,7 +9851,7 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9526
9851
  });
9527
9852
  }); };
9528
9853
 
9529
- var METHOD_NAME$p = "function.cancelOutput";
9854
+ var METHOD_NAME$r = "function.cancelOutput";
9530
9855
  /**
9531
9856
  * Cancel the await of output by emit of empty string
9532
9857
  *
@@ -9540,15 +9865,15 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9540
9865
  switch (_a.label) {
9541
9866
  case 0:
9542
9867
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9543
- swarm$1.loggerService.log(METHOD_NAME$p, {
9868
+ swarm$1.loggerService.log(METHOD_NAME$r, {
9544
9869
  clientId: clientId,
9545
9870
  agentName: agentName,
9546
9871
  });
9547
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
9548
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
9872
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9873
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9549
9874
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9550
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
9551
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName)];
9875
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
9876
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName)];
9552
9877
  case 1:
9553
9878
  currentAgentName = _a.sent();
9554
9879
  if (currentAgentName !== agentName) {
@@ -9560,7 +9885,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9560
9885
  });
9561
9886
  return [2 /*return*/];
9562
9887
  }
9563
- return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$p, clientId, swarmName)];
9888
+ return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$r, clientId, swarmName)];
9564
9889
  case 2:
9565
9890
  _a.sent();
9566
9891
  return [2 /*return*/];
@@ -9568,7 +9893,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9568
9893
  });
9569
9894
  }); };
9570
9895
 
9571
- var METHOD_NAME$o = "function.cancelOutputForce";
9896
+ var METHOD_NAME$q = "function.cancelOutputForce";
9572
9897
  /**
9573
9898
  * Cancel the await of output by emit of empty string without checking active agent
9574
9899
  *
@@ -9577,6 +9902,75 @@ var METHOD_NAME$o = "function.cancelOutputForce";
9577
9902
  * @returns {Promise<void>} - A promise that resolves when the output is canceled
9578
9903
  */
9579
9904
  var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
9905
+ var swarmName;
9906
+ return __generator(this, function (_a) {
9907
+ switch (_a.label) {
9908
+ case 0:
9909
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9910
+ swarm$1.loggerService.log(METHOD_NAME$q, {
9911
+ clientId: clientId,
9912
+ });
9913
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
9914
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9915
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
9916
+ return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$q, clientId, swarmName)];
9917
+ case 1:
9918
+ _a.sent();
9919
+ return [2 /*return*/];
9920
+ }
9921
+ });
9922
+ }); };
9923
+
9924
+ var METHOD_NAME$p = "function.commitStopTools";
9925
+ /**
9926
+ * Prevent the next tool from being executed
9927
+ *
9928
+ * @param {string} clientId - The ID of the client.
9929
+ * @param {string} agentName - The name of the agent.
9930
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9931
+ */
9932
+ var commitStopTools = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
9933
+ var swarmName, currentAgentName;
9934
+ return __generator(this, function (_a) {
9935
+ switch (_a.label) {
9936
+ case 0:
9937
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9938
+ swarm$1.loggerService.log(METHOD_NAME$p, {
9939
+ clientId: clientId,
9940
+ agentName: agentName,
9941
+ });
9942
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
9943
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
9944
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9945
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
9946
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName)];
9947
+ case 1:
9948
+ currentAgentName = _a.sent();
9949
+ if (currentAgentName !== agentName) {
9950
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9951
+ swarm$1.loggerService.log('function "commitStopTools" skipped due to the agent change', {
9952
+ currentAgentName: currentAgentName,
9953
+ agentName: agentName,
9954
+ clientId: clientId,
9955
+ });
9956
+ return [2 /*return*/];
9957
+ }
9958
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$p, clientId, swarmName)];
9959
+ case 2:
9960
+ _a.sent();
9961
+ return [2 /*return*/];
9962
+ }
9963
+ });
9964
+ }); };
9965
+
9966
+ var METHOD_NAME$o = "function.commitStopToolsForce";
9967
+ /**
9968
+ * Prevent the next tool from being executed without active agent check
9969
+ *
9970
+ * @param {string} clientId - The ID of the client.
9971
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9972
+ */
9973
+ var commitStopToolsForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
9580
9974
  var swarmName;
9581
9975
  return __generator(this, function (_a) {
9582
9976
  switch (_a.label) {
@@ -9584,11 +9978,12 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
9584
9978
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9585
9979
  swarm$1.loggerService.log(METHOD_NAME$o, {
9586
9980
  clientId: clientId,
9981
+ METHOD_NAME: METHOD_NAME$o,
9587
9982
  });
9588
9983
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$o);
9589
9984
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9590
9985
  swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$o);
9591
- return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$o, clientId, swarmName)];
9986
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$o, clientId, swarmName)];
9592
9987
  case 1:
9593
9988
  _a.sent();
9594
9989
  return [2 /*return*/];
@@ -11246,6 +11641,7 @@ var listenSwarmEventOnce = function (clientId, filterFn, fn) {
11246
11641
 
11247
11642
  var METHOD_NAME_GET$3 = "StateUtils.getState";
11248
11643
  var METHOD_NAME_SET$1 = "StateUtils.setState";
11644
+ var METHOD_NAME_CLEAR$3 = "StateUtils.clearState";
11249
11645
  /**
11250
11646
  * Utility class for managing state in the agent swarm.
11251
11647
  * @implements {TState}
@@ -11316,6 +11712,34 @@ var StateUtils = /** @class */ (function () {
11316
11712
  }
11317
11713
  });
11318
11714
  }); };
11715
+ /**
11716
+ * Set the state to initial value
11717
+ * @template T
11718
+ * @param {Object} payload - The payload containing client and state information.
11719
+ * @param {string} payload.clientId - The client ID.
11720
+ * @param {AgentName} payload.agentName - The agent name.
11721
+ * @param {StateName} payload.stateName - The state name.
11722
+ * @returns {Promise<void>}
11723
+ * @throws Will throw an error if the state is not registered in the agent.
11724
+ */
11725
+ this.clearState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11726
+ return __generator(this, function (_a) {
11727
+ switch (_a.label) {
11728
+ case 0:
11729
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11730
+ swarm$1.loggerService.log(METHOD_NAME_SET$1, {
11731
+ clientId: payload.clientId,
11732
+ stateName: payload.stateName,
11733
+ });
11734
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_SET$1);
11735
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11736
+ throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (clearState)"));
11737
+ }
11738
+ return [4 /*yield*/, swarm$1.statePublicService.clearState(METHOD_NAME_CLEAR$3, payload.clientId, payload.stateName)];
11739
+ case 1: return [2 /*return*/, _a.sent()];
11740
+ }
11741
+ });
11742
+ }); };
11319
11743
  }
11320
11744
  return StateUtils;
11321
11745
  }());
@@ -11327,6 +11751,7 @@ var State = new StateUtils();
11327
11751
 
11328
11752
  var METHOD_NAME_GET$2 = "SharedStateUtils.getSharedState";
11329
11753
  var METHOD_NAME_SET = "SharedStateUtils.setSharedState";
11754
+ var METHOD_NAME_CLEAR$2 = "SharedStateUtils.clearSharedState";
11330
11755
  /**
11331
11756
  * Utility class for managing state in the agent swarm.
11332
11757
  * @implements {TSharedState}
@@ -11391,6 +11816,31 @@ var SharedStateUtils = /** @class */ (function () {
11391
11816
  }
11392
11817
  });
11393
11818
  }); };
11819
+ /**
11820
+ * Set the state to initial value
11821
+ * @template T
11822
+ * @param {Object} payload - The payload containing client and state information.
11823
+ * @param {AgentName} payload.agentName - The agent name.
11824
+ * @param {StateName} payload.stateName - The state name.
11825
+ * @returns {Promise<void>}
11826
+ * @throws Will throw an error if the state is not registered in the agent.
11827
+ */
11828
+ this.clearState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11829
+ return __generator(this, function (_a) {
11830
+ switch (_a.label) {
11831
+ case 0:
11832
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11833
+ swarm$1.loggerService.log(METHOD_NAME_SET, {
11834
+ stateName: payload.stateName,
11835
+ });
11836
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11837
+ throw new Error("agent-swarm SharedStateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (clearState)"));
11838
+ }
11839
+ return [4 /*yield*/, swarm$1.sharedStatePublicService.clearState(METHOD_NAME_CLEAR$2, payload.stateName)];
11840
+ case 1: return [2 /*return*/, _a.sent()];
11841
+ }
11842
+ });
11843
+ }); };
11394
11844
  }
11395
11845
  return SharedStateUtils;
11396
11846
  }());
@@ -11838,4 +12288,4 @@ var SchemaUtils = /** @class */ (function () {
11838
12288
  */
11839
12289
  var Schema = new SchemaUtils();
11840
12290
 
11841
- export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
12291
+ export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };