agent-swarm-kit 1.0.111 → 1.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -1671,6 +1671,7 @@ var AgentSchemaService = /** @class */ (function () {
1671
1671
 
1672
1672
  var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1673
1673
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1674
+ var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1674
1675
  var getPlaceholder = function () {
1675
1676
  return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
1676
1677
  };
@@ -1687,6 +1688,7 @@ var ClientAgent = /** @class */ (function () {
1687
1688
  var _this = this;
1688
1689
  this.params = params;
1689
1690
  this._agentChangeSubject = new functoolsKit.Subject();
1691
+ this._toolStopSubject = new functoolsKit.Subject();
1690
1692
  this._toolErrorSubject = new functoolsKit.Subject();
1691
1693
  this._toolCommitSubject = new functoolsKit.Subject();
1692
1694
  this._outputSubject = new functoolsKit.Subject();
@@ -1987,6 +1989,35 @@ var ClientAgent = /** @class */ (function () {
1987
1989
  }
1988
1990
  });
1989
1991
  }); };
1992
+ /**
1993
+ * Commits change of agent to prevent the next tool execution from being called.
1994
+ * @returns {Promise<void>}
1995
+ */
1996
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
1997
+ return __generator(this, function (_a) {
1998
+ switch (_a.label) {
1999
+ case 0:
2000
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2001
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitStopTools"));
2002
+ return [4 /*yield*/, this._toolStopSubject.next(TOOL_STOP_SYMBOL)];
2003
+ case 1:
2004
+ _a.sent();
2005
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
2006
+ type: "commit-stop-tools",
2007
+ source: "agent-bus",
2008
+ input: {},
2009
+ output: {},
2010
+ context: {
2011
+ agentName: this.params.agentName,
2012
+ },
2013
+ clientId: this.params.clientId,
2014
+ })];
2015
+ case 2:
2016
+ _a.sent();
2017
+ return [2 /*return*/];
2018
+ }
2019
+ });
2020
+ }); };
1990
2021
  /**
1991
2022
  * Commits a system message to the history.
1992
2023
  * @param {string} message - The system message to commit.
@@ -2117,9 +2148,9 @@ var ClientAgent = /** @class */ (function () {
2117
2148
  this.execute = functoolsKit.queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
2118
2149
  var rawMessage, message, toolCalls, _loop_1, this_1, idx, state_1, result, validation, result1;
2119
2150
  var _this = this;
2120
- var _a, _b, _c, _d, _e, _f, _g;
2121
- return __generator(this, function (_h) {
2122
- switch (_h.label) {
2151
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2152
+ return __generator(this, function (_j) {
2153
+ switch (_j.label) {
2123
2154
  case 0:
2124
2155
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2125
2156
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
@@ -2132,13 +2163,13 @@ var ClientAgent = /** @class */ (function () {
2132
2163
  content: incoming.trim(),
2133
2164
  })];
2134
2165
  case 1:
2135
- _h.sent();
2166
+ _j.sent();
2136
2167
  return [4 /*yield*/, this.getCompletion(mode)];
2137
2168
  case 2:
2138
- rawMessage = _h.sent();
2169
+ rawMessage = _j.sent();
2139
2170
  return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2140
2171
  case 3:
2141
- message = _h.sent();
2172
+ message = _j.sent();
2142
2173
  if (!message.tool_calls) return [3 /*break*/, 9];
2143
2174
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2144
2175
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
@@ -2152,11 +2183,11 @@ var ClientAgent = /** @class */ (function () {
2152
2183
  });
2153
2184
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2154
2185
  case 4:
2155
- _h.sent();
2186
+ _j.sent();
2156
2187
  _loop_1 = function (idx) {
2157
2188
  var tool, targetFn, result_2, result_3, status, result_4;
2158
- return __generator(this, function (_j) {
2159
- switch (_j.label) {
2189
+ return __generator(this, function (_k) {
2190
+ switch (_k.label) {
2160
2191
  case 0:
2161
2192
  tool = toolCalls[idx];
2162
2193
  targetFn = (_a = this_1.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
@@ -2165,12 +2196,12 @@ var ClientAgent = /** @class */ (function () {
2165
2196
  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);
2166
2197
  return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
2167
2198
  case 1:
2168
- result_2 = _j.sent();
2199
+ result_2 = _k.sent();
2169
2200
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2170
2201
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
2171
2202
  return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
2172
2203
  case 2:
2173
- _j.sent();
2204
+ _k.sent();
2174
2205
  return [2 /*return*/, { value: void 0 }];
2175
2206
  case 3:
2176
2207
  ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
@@ -2182,17 +2213,17 @@ var ClientAgent = /** @class */ (function () {
2182
2213
  toolCalls: toolCalls,
2183
2214
  }))];
2184
2215
  case 4:
2185
- if (!_j.sent()) return [3 /*break*/, 7];
2216
+ if (!_k.sent()) return [3 /*break*/, 7];
2186
2217
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2187
2218
  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"));
2188
2219
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2189
2220
  case 5:
2190
- result_3 = _j.sent();
2221
+ result_3 = _k.sent();
2191
2222
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2192
2223
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
2193
2224
  return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
2194
2225
  case 6:
2195
- _j.sent();
2226
+ _k.sent();
2196
2227
  return [2 /*return*/, { value: void 0 }];
2197
2228
  case 7:
2198
2229
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
@@ -2232,10 +2263,11 @@ var ClientAgent = /** @class */ (function () {
2232
2263
  this_1._agentChangeSubject.toPromise(),
2233
2264
  this_1._toolCommitSubject.toPromise(),
2234
2265
  this_1._toolErrorSubject.toPromise(),
2266
+ this_1._toolStopSubject.toPromise(),
2235
2267
  this_1._outputSubject.toPromise(),
2236
2268
  ])];
2237
2269
  case 8:
2238
- status = _j.sent();
2270
+ status = _k.sent();
2239
2271
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2240
2272
  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"));
2241
2273
  if (status === AGENT_CHANGE_SYMBOL) {
@@ -2245,17 +2277,24 @@ var ClientAgent = /** @class */ (function () {
2245
2277
  this_1.params.callbacks.onAfterToolCalls(this_1.params.clientId, this_1.params.agentName, toolCalls);
2246
2278
  return [2 /*return*/, { value: void 0 }];
2247
2279
  }
2280
+ if (status === TOOL_STOP_SYMBOL) {
2281
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2282
+ 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"));
2283
+ ((_g = this_1.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2284
+ this_1.params.callbacks.onAfterToolCalls(this_1.params.clientId, this_1.params.agentName, toolCalls);
2285
+ return [2 /*return*/, { value: void 0 }];
2286
+ }
2248
2287
  if (!(status === TOOL_ERROR_SYMBOL)) return [3 /*break*/, 11];
2249
2288
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2250
2289
  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"));
2251
2290
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function call failed with error: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2252
2291
  case 9:
2253
- result_4 = _j.sent();
2292
+ result_4 = _k.sent();
2254
2293
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2255
2294
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_4));
2256
2295
  return [4 /*yield*/, this_1._emitOuput(mode, result_4)];
2257
2296
  case 10:
2258
- _j.sent();
2297
+ _k.sent();
2259
2298
  return [2 /*return*/, { value: void 0 }];
2260
2299
  case 11: return [2 /*return*/];
2261
2300
  }
@@ -2263,20 +2302,20 @@ var ClientAgent = /** @class */ (function () {
2263
2302
  };
2264
2303
  this_1 = this;
2265
2304
  idx = 0;
2266
- _h.label = 5;
2305
+ _j.label = 5;
2267
2306
  case 5:
2268
2307
  if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
2269
2308
  return [5 /*yield**/, _loop_1(idx)];
2270
2309
  case 6:
2271
- state_1 = _h.sent();
2310
+ state_1 = _j.sent();
2272
2311
  if (typeof state_1 === "object")
2273
2312
  return [2 /*return*/, state_1.value];
2274
- _h.label = 7;
2313
+ _j.label = 7;
2275
2314
  case 7:
2276
2315
  idx++;
2277
2316
  return [3 /*break*/, 5];
2278
2317
  case 8:
2279
- ((_g = this.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2318
+ ((_h = this.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2280
2319
  this.params.callbacks.onAfterToolCalls(this.params.clientId, this.params.agentName, toolCalls);
2281
2320
  return [2 /*return*/];
2282
2321
  case 9:
@@ -2286,29 +2325,29 @@ var ClientAgent = /** @class */ (function () {
2286
2325
  }
2287
2326
  return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2288
2327
  case 10:
2289
- result = _h.sent();
2328
+ result = _j.sent();
2290
2329
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2291
2330
  case 11:
2292
- _h.sent();
2331
+ _j.sent();
2293
2332
  validation = null;
2294
2333
  return [4 /*yield*/, this.params.validate(result)];
2295
2334
  case 12:
2296
- if (!(validation = _h.sent())) return [3 /*break*/, 15];
2335
+ if (!(validation = _j.sent())) return [3 /*break*/, 15];
2297
2336
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2298
2337
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
2299
2338
  return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
2300
2339
  case 13:
2301
- result1 = _h.sent();
2340
+ result1 = _j.sent();
2302
2341
  return [4 /*yield*/, this._emitOuput(mode, result1)];
2303
2342
  case 14:
2304
- _h.sent();
2343
+ _j.sent();
2305
2344
  return [2 /*return*/];
2306
2345
  case 15:
2307
2346
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2308
2347
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
2309
2348
  return [4 /*yield*/, this._emitOuput(mode, result)];
2310
2349
  case 16:
2311
- _h.sent();
2350
+ _j.sent();
2312
2351
  return [2 /*return*/];
2313
2352
  }
2314
2353
  });
@@ -2499,6 +2538,21 @@ var AgentConnectionService = /** @class */ (function () {
2499
2538
  }
2500
2539
  });
2501
2540
  }); };
2541
+ /**
2542
+ * Prevent the next tool from being executed
2543
+ * @returns {Promise<any>} The commit result.
2544
+ */
2545
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
2546
+ return __generator(this, function (_a) {
2547
+ switch (_a.label) {
2548
+ case 0:
2549
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
2550
+ this.loggerService.info("agentConnectionService commitStopTools");
2551
+ return [4 /*yield*/, this.getAgent(this.methodContextService.context.clientId, this.methodContextService.context.agentName).commitStopTools()];
2552
+ case 1: return [2 /*return*/, _a.sent()];
2553
+ }
2554
+ });
2555
+ }); };
2502
2556
  /**
2503
2557
  * Commits flush of agent history
2504
2558
  * @returns {Promise<any>} The commit result.
@@ -3792,6 +3846,39 @@ var ClientSession = /** @class */ (function () {
3792
3846
  }
3793
3847
  });
3794
3848
  }); };
3849
+ /**
3850
+ * Commits stop of the nexttool execution
3851
+ * @returns {Promise<void>}
3852
+ */
3853
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
3854
+ var agent, result;
3855
+ return __generator(this, function (_a) {
3856
+ switch (_a.label) {
3857
+ case 0:
3858
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3859
+ this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitStopTools"));
3860
+ return [4 /*yield*/, this.params.swarm.getAgent()];
3861
+ case 1:
3862
+ agent = _a.sent();
3863
+ return [4 /*yield*/, agent.commitStopTools()];
3864
+ case 2:
3865
+ result = _a.sent();
3866
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
3867
+ type: "commit-stop-tools",
3868
+ source: "session-bus",
3869
+ input: {},
3870
+ output: {},
3871
+ context: {
3872
+ swarmName: this.params.swarmName,
3873
+ },
3874
+ clientId: this.params.clientId,
3875
+ })];
3876
+ case 3:
3877
+ _a.sent();
3878
+ return [2 /*return*/, result];
3879
+ }
3880
+ });
3881
+ }); };
3795
3882
  /**
3796
3883
  * Commits a system message.
3797
3884
  * @param {string} message - The system message to commit.
@@ -4119,6 +4206,22 @@ var SessionConnectionService = /** @class */ (function () {
4119
4206
  }
4120
4207
  });
4121
4208
  }); };
4209
+ /**
4210
+ * Commits user message to the agent without answer.
4211
+ * @param {string} message - The message to commit.
4212
+ * @returns {Promise<void>} A promise that resolves when the message is committed.
4213
+ */
4214
+ this.commitStopTools = function () { return __awaiter(_this, void 0, void 0, function () {
4215
+ return __generator(this, function (_a) {
4216
+ switch (_a.label) {
4217
+ case 0:
4218
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4219
+ this.loggerService.info("sessionConnectionService commitStopTools");
4220
+ return [4 /*yield*/, this.getSession(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).commitStopTools()];
4221
+ case 1: return [2 /*return*/, _a.sent()];
4222
+ }
4223
+ });
4224
+ }); };
4122
4225
  /**
4123
4226
  * Disposes of the session connection service.
4124
4227
  * @returns {Promise<void>} A promise that resolves when the service is disposed.
@@ -4491,6 +4594,42 @@ var AgentPublicService = /** @class */ (function () {
4491
4594
  }
4492
4595
  });
4493
4596
  }); };
4597
+ /**
4598
+ * Prevent the next tool from being executed
4599
+ * @param {string} clientId - The client ID.
4600
+ * @param {AgentName} agentName - The name of the agent.
4601
+ * @returns {Promise<unknown>} The commit result.
4602
+ */
4603
+ this.commitStopTools = function (methodName, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
4604
+ var _this = this;
4605
+ return __generator(this, function (_a) {
4606
+ switch (_a.label) {
4607
+ case 0:
4608
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
4609
+ this.loggerService.info("agentPublicService commitStopTools", {
4610
+ methodName: methodName,
4611
+ clientId: clientId,
4612
+ agentName: agentName,
4613
+ });
4614
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
4615
+ return __generator(this, function (_a) {
4616
+ switch (_a.label) {
4617
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitStopTools()];
4618
+ case 1: return [2 /*return*/, _a.sent()];
4619
+ }
4620
+ });
4621
+ }); }, {
4622
+ methodName: methodName,
4623
+ clientId: clientId,
4624
+ agentName: agentName,
4625
+ swarmName: "",
4626
+ storageName: "",
4627
+ stateName: "",
4628
+ })];
4629
+ case 1: return [2 /*return*/, _a.sent()];
4630
+ }
4631
+ });
4632
+ }); };
4494
4633
  /**
4495
4634
  * Disposes of the agent.
4496
4635
  * @param {string} clientId - The client ID.
@@ -5004,6 +5143,41 @@ var SessionPublicService = /** @class */ (function () {
5004
5143
  }
5005
5144
  });
5006
5145
  }); };
5146
+ /**
5147
+ * Prevent the next tool from being executed
5148
+ * @param {string} clientId - The client ID.
5149
+ * @param {SwarmName} swarmName - The swarm name.
5150
+ * @returns {Promise<void>}
5151
+ */
5152
+ this.commitStopTools = function (methodName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
5153
+ var _this = this;
5154
+ return __generator(this, function (_a) {
5155
+ switch (_a.label) {
5156
+ case 0:
5157
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5158
+ this.loggerService.info("sessionPublicService commitStopTools", {
5159
+ clientId: clientId,
5160
+ swarmName: swarmName,
5161
+ });
5162
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
5163
+ return __generator(this, function (_a) {
5164
+ switch (_a.label) {
5165
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitStopTools()];
5166
+ case 1: return [2 /*return*/, _a.sent()];
5167
+ }
5168
+ });
5169
+ }); }, {
5170
+ methodName: methodName,
5171
+ clientId: clientId,
5172
+ swarmName: swarmName,
5173
+ agentName: "",
5174
+ storageName: "",
5175
+ stateName: "",
5176
+ })];
5177
+ case 1: return [2 /*return*/, _a.sent()];
5178
+ }
5179
+ });
5180
+ }); };
5007
5181
  /**
5008
5182
  * Disposes of the session.
5009
5183
  * @param {string} clientId - The client ID.
@@ -7256,6 +7430,53 @@ var ClientState = /** @class */ (function () {
7256
7430
  }
7257
7431
  });
7258
7432
  }); };
7433
+ /**
7434
+ * Sets the to initial value
7435
+ * @returns {Promise<State>}
7436
+ */
7437
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
7438
+ var _this = this;
7439
+ var _a;
7440
+ return __generator(this, function (_b) {
7441
+ switch (_b.label) {
7442
+ case 0:
7443
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7444
+ this.params.logger.debug("ClientState stateName=".concat(this.params.stateName, " clientId=").concat(this.params.clientId, " shared=").concat(this.params.shared, " clearState"));
7445
+ return [4 /*yield*/, this.dispatch("write", function () { return __awaiter(_this, void 0, void 0, function () {
7446
+ return __generator(this, function (_a) {
7447
+ switch (_a.label) {
7448
+ case 0: return [4 /*yield*/, this.params.getState(this.params.clientId, this.params.stateName)];
7449
+ case 1: return [2 /*return*/, _a.sent()];
7450
+ }
7451
+ });
7452
+ }); })];
7453
+ case 1:
7454
+ _b.sent();
7455
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7456
+ 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 });
7457
+ this.params.setState &&
7458
+ this.params.setState(this._state, this.params.clientId, this.params.stateName);
7459
+ if ((_a = this.params.callbacks) === null || _a === void 0 ? void 0 : _a.onWrite) {
7460
+ this.params.callbacks.onWrite(this._state, this.params.clientId, this.params.stateName);
7461
+ }
7462
+ return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
7463
+ type: "clear-state",
7464
+ source: "state-bus",
7465
+ input: {},
7466
+ output: {
7467
+ state: this._state,
7468
+ },
7469
+ context: {
7470
+ stateName: this.params.stateName,
7471
+ },
7472
+ clientId: this.params.clientId,
7473
+ })];
7474
+ case 2:
7475
+ _b.sent();
7476
+ return [2 /*return*/, this._state];
7477
+ }
7478
+ });
7479
+ }); };
7259
7480
  /**
7260
7481
  * Gets the current state.
7261
7482
  * @returns {Promise<State>}
@@ -7393,6 +7614,26 @@ var StateConnectionService = /** @class */ (function () {
7393
7614
  }
7394
7615
  });
7395
7616
  }); };
7617
+ /**
7618
+ * Set the state to initial value
7619
+ * @returns {Promise<T>} The initial state.
7620
+ */
7621
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
7622
+ var state;
7623
+ return __generator(this, function (_a) {
7624
+ switch (_a.label) {
7625
+ case 0:
7626
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7627
+ this.loggerService.info("stateConnectionService clearState");
7628
+ state = this.getStateRef(this.methodContextService.context.clientId, this.methodContextService.context.stateName);
7629
+ return [4 /*yield*/, state.waitForInit()];
7630
+ case 1:
7631
+ _a.sent();
7632
+ return [4 /*yield*/, state.clearState()];
7633
+ case 2: return [2 /*return*/, _a.sent()];
7634
+ }
7635
+ });
7636
+ }); };
7396
7637
  /**
7397
7638
  * Gets the state.
7398
7639
  * @returns {Promise<T>} The current state.
@@ -7490,6 +7731,42 @@ var StatePublicService = /** @class */ (function () {
7490
7731
  }
7491
7732
  });
7492
7733
  }); };
7734
+ /**
7735
+ * Set the state to initial value
7736
+ * @param {string} clientId - The client ID.
7737
+ * @param {StateName} stateName - The name of the state.
7738
+ * @returns {Promise<T>} - The initial state.
7739
+ */
7740
+ this.clearState = function (methodName, clientId, stateName) { return __awaiter(_this, void 0, void 0, function () {
7741
+ var _this = this;
7742
+ return __generator(this, function (_a) {
7743
+ switch (_a.label) {
7744
+ case 0:
7745
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7746
+ this.loggerService.info("statePublicService clearState", {
7747
+ methodName: methodName,
7748
+ clientId: clientId,
7749
+ stateName: stateName,
7750
+ });
7751
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
7752
+ return __generator(this, function (_a) {
7753
+ switch (_a.label) {
7754
+ case 0: return [4 /*yield*/, this.stateConnectionService.clearState()];
7755
+ case 1: return [2 /*return*/, _a.sent()];
7756
+ }
7757
+ });
7758
+ }); }, {
7759
+ methodName: methodName,
7760
+ clientId: clientId,
7761
+ stateName: stateName,
7762
+ agentName: "",
7763
+ swarmName: "",
7764
+ storageName: "",
7765
+ })];
7766
+ case 1: return [2 /*return*/, _a.sent()];
7767
+ }
7768
+ });
7769
+ }); };
7493
7770
  /**
7494
7771
  * Gets the current state.
7495
7772
  * @param {string} clientId - The client ID.
@@ -8359,6 +8636,26 @@ var SharedStateConnectionService = /** @class */ (function () {
8359
8636
  }
8360
8637
  });
8361
8638
  }); };
8639
+ /**
8640
+ * Set the state to initial value
8641
+ * @returns {Promise<T>} The new state.
8642
+ */
8643
+ this.clearState = function () { return __awaiter(_this, void 0, void 0, function () {
8644
+ var state;
8645
+ return __generator(this, function (_a) {
8646
+ switch (_a.label) {
8647
+ case 0:
8648
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8649
+ this.loggerService.info("sharedStateConnectionService clearState");
8650
+ state = this.getStateRef(this.methodContextService.context.stateName);
8651
+ return [4 /*yield*/, state.waitForInit()];
8652
+ case 1:
8653
+ _a.sent();
8654
+ return [4 /*yield*/, state.clearState()];
8655
+ case 2: return [2 /*return*/, _a.sent()];
8656
+ }
8657
+ });
8658
+ }); };
8362
8659
  /**
8363
8660
  * Gets the state.
8364
8661
  * @returns {Promise<T>} The current state.
@@ -8592,6 +8889,40 @@ var SharedStatePublicService = /** @class */ (function () {
8592
8889
  }
8593
8890
  });
8594
8891
  }); };
8892
+ /**
8893
+ * Set the state to initial value
8894
+ * @param {StateName} stateName - The name of the state.
8895
+ * @returns {Promise<T>} - The initial state.
8896
+ */
8897
+ this.clearState = function (methodName, stateName) { return __awaiter(_this, void 0, void 0, function () {
8898
+ var _this = this;
8899
+ return __generator(this, function (_a) {
8900
+ switch (_a.label) {
8901
+ case 0:
8902
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8903
+ this.loggerService.info("sharedStatePublicService clearState", {
8904
+ methodName: methodName,
8905
+ stateName: stateName,
8906
+ });
8907
+ return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
8908
+ return __generator(this, function (_a) {
8909
+ switch (_a.label) {
8910
+ case 0: return [4 /*yield*/, this.sharedStateConnectionService.clearState()];
8911
+ case 1: return [2 /*return*/, _a.sent()];
8912
+ }
8913
+ });
8914
+ }); }, {
8915
+ methodName: methodName,
8916
+ clientId: "",
8917
+ stateName: stateName,
8918
+ agentName: "",
8919
+ swarmName: "",
8920
+ storageName: "",
8921
+ })];
8922
+ case 1: return [2 /*return*/, _a.sent()];
8923
+ }
8924
+ });
8925
+ }); };
8595
8926
  /**
8596
8927
  * Gets the current state.
8597
8928
  * @param {StateName} stateName - The name of the state.
@@ -8962,7 +9293,7 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
8962
9293
  init();
8963
9294
  var swarm$1 = swarm;
8964
9295
 
8965
- var METHOD_NAME$J = "cli.dumpDocs";
9296
+ var METHOD_NAME$L = "cli.dumpDocs";
8966
9297
  /**
8967
9298
  * Dumps the documentation for the agents and swarms.
8968
9299
  *
@@ -8973,7 +9304,7 @@ var METHOD_NAME$J = "cli.dumpDocs";
8973
9304
  var dumpDocs = function (dirName, PlantUML) {
8974
9305
  if (dirName === void 0) { dirName = "./docs/chat"; }
8975
9306
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8976
- swarm$1.loggerService.log(METHOD_NAME$J, {
9307
+ swarm$1.loggerService.log(METHOD_NAME$L, {
8977
9308
  dirName: dirName,
8978
9309
  });
8979
9310
  if (PlantUML) {
@@ -8984,12 +9315,12 @@ var dumpDocs = function (dirName, PlantUML) {
8984
9315
  swarm$1.agentValidationService
8985
9316
  .getAgentList()
8986
9317
  .forEach(function (agentName) {
8987
- return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
9318
+ return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$L);
8988
9319
  });
8989
9320
  swarm$1.swarmValidationService
8990
9321
  .getSwarmList()
8991
9322
  .forEach(function (swarmName) {
8992
- return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9323
+ return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$L);
8993
9324
  });
8994
9325
  swarm$1.agentValidationService.getAgentList().forEach(function (agentName) {
8995
9326
  var dependsOn = swarm$1.agentSchemaService.get(agentName).dependsOn;
@@ -9000,7 +9331,7 @@ var dumpDocs = function (dirName, PlantUML) {
9000
9331
  return swarm$1.docService.dumpDocs(dirName);
9001
9332
  };
9002
9333
 
9003
- var METHOD_NAME$I = "cli.dumpAgent";
9334
+ var METHOD_NAME$K = "cli.dumpAgent";
9004
9335
  /**
9005
9336
  * Dumps the agent information into PlantUML format.
9006
9337
  *
@@ -9010,14 +9341,14 @@ var METHOD_NAME$I = "cli.dumpAgent";
9010
9341
  var dumpAgent = function (agentName, _a) {
9011
9342
  var _b = _a === void 0 ? {} : _a, _c = _b.withSubtree, withSubtree = _c === void 0 ? false : _c;
9012
9343
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9013
- swarm$1.loggerService.log(METHOD_NAME$I, {
9344
+ swarm$1.loggerService.log(METHOD_NAME$K, {
9014
9345
  agentName: agentName,
9015
9346
  });
9016
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$I);
9347
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$K);
9017
9348
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
9018
9349
  };
9019
9350
 
9020
- var METHOD_NAME$H = "cli.dumpSwarm";
9351
+ var METHOD_NAME$J = "cli.dumpSwarm";
9021
9352
  /**
9022
9353
  * Dumps the swarm information into PlantUML format.
9023
9354
  *
@@ -9026,14 +9357,14 @@ var METHOD_NAME$H = "cli.dumpSwarm";
9026
9357
  */
9027
9358
  var dumpSwarm = function (swarmName) {
9028
9359
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9029
- swarm$1.loggerService.log(METHOD_NAME$H, {
9360
+ swarm$1.loggerService.log(METHOD_NAME$J, {
9030
9361
  swarmName: swarmName,
9031
9362
  });
9032
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
9363
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9033
9364
  return swarm$1.swarmMetaService.toUML(swarmName);
9034
9365
  };
9035
9366
 
9036
- var METHOD_NAME$G = "function.addAgent";
9367
+ var METHOD_NAME$I = "function.addAgent";
9037
9368
  /**
9038
9369
  * Adds a new agent to the agent registry. The swarm takes only those agents which was registered
9039
9370
  *
@@ -9042,7 +9373,7 @@ var METHOD_NAME$G = "function.addAgent";
9042
9373
  */
9043
9374
  var addAgent = function (agentSchema) {
9044
9375
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9045
- swarm$1.loggerService.log(METHOD_NAME$G, {
9376
+ swarm$1.loggerService.log(METHOD_NAME$I, {
9046
9377
  agentSchema: agentSchema,
9047
9378
  });
9048
9379
  swarm$1.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
@@ -9050,7 +9381,7 @@ var addAgent = function (agentSchema) {
9050
9381
  return agentSchema.agentName;
9051
9382
  };
9052
9383
 
9053
- var METHOD_NAME$F = "function.addCompletion";
9384
+ var METHOD_NAME$H = "function.addCompletion";
9054
9385
  /**
9055
9386
  * Adds a completion engine for agents. Agents could use different models and
9056
9387
  * framewords for completion like: mock, gpt4all, ollama, openai
@@ -9060,7 +9391,7 @@ var METHOD_NAME$F = "function.addCompletion";
9060
9391
  */
9061
9392
  var addCompletion = function (completionSchema) {
9062
9393
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9063
- swarm$1.loggerService.log(METHOD_NAME$F, {
9394
+ swarm$1.loggerService.log(METHOD_NAME$H, {
9064
9395
  completionSchema: completionSchema,
9065
9396
  });
9066
9397
  swarm$1.completionValidationService.addCompletion(completionSchema.completionName);
@@ -9068,7 +9399,7 @@ var addCompletion = function (completionSchema) {
9068
9399
  return completionSchema.completionName;
9069
9400
  };
9070
9401
 
9071
- var METHOD_NAME$E = "function.addSwarm";
9402
+ var METHOD_NAME$G = "function.addSwarm";
9072
9403
  /**
9073
9404
  * Adds a new swarm to the system. The swarm is a root for starting client session
9074
9405
  *
@@ -9077,7 +9408,7 @@ var METHOD_NAME$E = "function.addSwarm";
9077
9408
  */
9078
9409
  var addSwarm = function (swarmSchema) {
9079
9410
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9080
- swarm$1.loggerService.log(METHOD_NAME$E, {
9411
+ swarm$1.loggerService.log(METHOD_NAME$G, {
9081
9412
  swarmSchema: swarmSchema,
9082
9413
  });
9083
9414
  swarm$1.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
@@ -9085,7 +9416,7 @@ var addSwarm = function (swarmSchema) {
9085
9416
  return swarmSchema.swarmName;
9086
9417
  };
9087
9418
 
9088
- var METHOD_NAME$D = "function.addTool";
9419
+ var METHOD_NAME$F = "function.addTool";
9089
9420
  /**
9090
9421
  * Adds a new tool for agents in a swarm. Tool should be registered in `addAgent`
9091
9422
  * declaration
@@ -9095,7 +9426,7 @@ var METHOD_NAME$D = "function.addTool";
9095
9426
  */
9096
9427
  var addTool = function (toolSchema) {
9097
9428
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9098
- swarm$1.loggerService.log(METHOD_NAME$D, {
9429
+ swarm$1.loggerService.log(METHOD_NAME$F, {
9099
9430
  toolSchema: toolSchema,
9100
9431
  });
9101
9432
  swarm$1.toolValidationService.addTool(toolSchema.toolName, toolSchema);
@@ -9103,7 +9434,7 @@ var addTool = function (toolSchema) {
9103
9434
  return toolSchema.toolName;
9104
9435
  };
9105
9436
 
9106
- var METHOD_NAME$C = "function.addState";
9437
+ var METHOD_NAME$E = "function.addState";
9107
9438
  /**
9108
9439
  * Adds a new state to the state registry. The swarm takes only those states which was registered
9109
9440
  *
@@ -9112,7 +9443,7 @@ var METHOD_NAME$C = "function.addState";
9112
9443
  */
9113
9444
  var addState = function (stateSchema) {
9114
9445
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9115
- swarm$1.loggerService.log(METHOD_NAME$C, {
9446
+ swarm$1.loggerService.log(METHOD_NAME$E, {
9116
9447
  stateSchema: stateSchema,
9117
9448
  });
9118
9449
  swarm$1.stateSchemaService.register(stateSchema.stateName, stateSchema);
@@ -9124,7 +9455,7 @@ var addState = function (stateSchema) {
9124
9455
  return stateSchema.stateName;
9125
9456
  };
9126
9457
 
9127
- var METHOD_NAME$B = "function.addEmbedding";
9458
+ var METHOD_NAME$D = "function.addEmbedding";
9128
9459
  /**
9129
9460
  * Adds a new embedding to the embedding registry. The swarm takes only those embeddings which was registered
9130
9461
  *
@@ -9133,7 +9464,7 @@ var METHOD_NAME$B = "function.addEmbedding";
9133
9464
  */
9134
9465
  var addEmbedding = function (embeddingSchema) {
9135
9466
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9136
- swarm$1.loggerService.log(METHOD_NAME$B, {
9467
+ swarm$1.loggerService.log(METHOD_NAME$D, {
9137
9468
  embeddingSchema: embeddingSchema,
9138
9469
  });
9139
9470
  swarm$1.embeddingValidationService.addEmbedding(embeddingSchema.embeddingName, embeddingSchema);
@@ -9141,7 +9472,7 @@ var addEmbedding = function (embeddingSchema) {
9141
9472
  return embeddingSchema.embeddingName;
9142
9473
  };
9143
9474
 
9144
- var METHOD_NAME$A = "function.addStorage";
9475
+ var METHOD_NAME$C = "function.addStorage";
9145
9476
  /**
9146
9477
  * Adds a new storage to the storage registry. The swarm takes only those storages which was registered
9147
9478
  *
@@ -9150,7 +9481,7 @@ var METHOD_NAME$A = "function.addStorage";
9150
9481
  */
9151
9482
  var addStorage = function (storageSchema) {
9152
9483
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9153
- swarm$1.loggerService.log(METHOD_NAME$A, {
9484
+ swarm$1.loggerService.log(METHOD_NAME$C, {
9154
9485
  storageSchema: storageSchema,
9155
9486
  });
9156
9487
  swarm$1.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
@@ -9163,7 +9494,7 @@ var addStorage = function (storageSchema) {
9163
9494
  return storageSchema.storageName;
9164
9495
  };
9165
9496
 
9166
- var METHOD_NAME$z = "function.commitToolOutput";
9497
+ var METHOD_NAME$B = "function.commitToolOutput";
9167
9498
  /**
9168
9499
  * Commits the tool output to the active agent in a swarm session
9169
9500
  *
@@ -9178,17 +9509,17 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9178
9509
  switch (_a.label) {
9179
9510
  case 0:
9180
9511
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9181
- swarm$1.loggerService.log(METHOD_NAME$z, {
9512
+ swarm$1.loggerService.log(METHOD_NAME$B, {
9182
9513
  toolId: toolId,
9183
9514
  content: content,
9184
9515
  clientId: clientId,
9185
9516
  agentName: agentName,
9186
9517
  });
9187
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9188
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
9518
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$B);
9519
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
9189
9520
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9190
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9191
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName)];
9521
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
9522
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$B, clientId, swarmName)];
9192
9523
  case 1:
9193
9524
  currentAgentName = _a.sent();
9194
9525
  if (currentAgentName !== agentName) {
@@ -9201,7 +9532,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9201
9532
  });
9202
9533
  return [2 /*return*/];
9203
9534
  }
9204
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$z, clientId, swarmName)];
9535
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$B, clientId, swarmName)];
9205
9536
  case 2:
9206
9537
  _a.sent();
9207
9538
  return [2 /*return*/];
@@ -9209,7 +9540,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9209
9540
  });
9210
9541
  }); };
9211
9542
 
9212
- var METHOD_NAME$y = "function.commitSystemMessage";
9543
+ var METHOD_NAME$A = "function.commitSystemMessage";
9213
9544
  /**
9214
9545
  * Commits a system message to the active agent in the swarm.
9215
9546
  *
@@ -9224,16 +9555,16 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9224
9555
  switch (_a.label) {
9225
9556
  case 0:
9226
9557
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9227
- swarm$1.loggerService.log(METHOD_NAME$y, {
9558
+ swarm$1.loggerService.log(METHOD_NAME$A, {
9228
9559
  content: content,
9229
9560
  clientId: clientId,
9230
9561
  agentName: agentName,
9231
9562
  });
9232
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9233
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
9563
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$A);
9564
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
9234
9565
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9235
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9236
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName)];
9566
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
9567
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$A, clientId, swarmName)];
9237
9568
  case 1:
9238
9569
  currentAgentName = _a.sent();
9239
9570
  if (currentAgentName !== agentName) {
@@ -9245,7 +9576,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9245
9576
  });
9246
9577
  return [2 /*return*/];
9247
9578
  }
9248
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$y, clientId, swarmName)];
9579
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$A, clientId, swarmName)];
9249
9580
  case 2:
9250
9581
  _a.sent();
9251
9582
  return [2 /*return*/];
@@ -9253,7 +9584,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9253
9584
  });
9254
9585
  }); };
9255
9586
 
9256
- var METHOD_NAME$x = "function.commitFlush";
9587
+ var METHOD_NAME$z = "function.commitFlush";
9257
9588
  /**
9258
9589
  * Commits flush of agent history
9259
9590
  *
@@ -9267,15 +9598,15 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9267
9598
  switch (_a.label) {
9268
9599
  case 0:
9269
9600
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9270
- swarm$1.loggerService.log(METHOD_NAME$x, {
9601
+ swarm$1.loggerService.log(METHOD_NAME$z, {
9271
9602
  clientId: clientId,
9272
9603
  agentName: agentName,
9273
9604
  });
9274
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
9275
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9605
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9606
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
9276
9607
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9277
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9278
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$x, clientId, swarmName)];
9608
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9609
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName)];
9279
9610
  case 1:
9280
9611
  currentAgentName = _a.sent();
9281
9612
  if (currentAgentName !== agentName) {
@@ -9287,7 +9618,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9287
9618
  });
9288
9619
  return [2 /*return*/];
9289
9620
  }
9290
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$x, clientId, swarmName)];
9621
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$z, clientId, swarmName)];
9291
9622
  case 2:
9292
9623
  _a.sent();
9293
9624
  return [2 /*return*/];
@@ -9295,7 +9626,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9295
9626
  });
9296
9627
  }); };
9297
9628
 
9298
- var METHOD_NAME$w = "function.commitSystemMessage";
9629
+ var METHOD_NAME$y = "function.commitSystemMessage";
9299
9630
  /**
9300
9631
  * Commits a user message to the active agent history in as swarm without answer.
9301
9632
  *
@@ -9310,16 +9641,16 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9310
9641
  switch (_a.label) {
9311
9642
  case 0:
9312
9643
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9313
- swarm$1.loggerService.log(METHOD_NAME$w, {
9644
+ swarm$1.loggerService.log(METHOD_NAME$y, {
9314
9645
  content: content,
9315
9646
  clientId: clientId,
9316
9647
  agentName: agentName,
9317
9648
  });
9318
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
9319
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9649
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9650
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
9320
9651
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9321
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9322
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$w, clientId, swarmName)];
9652
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9653
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName)];
9323
9654
  case 1:
9324
9655
  currentAgentName = _a.sent();
9325
9656
  if (currentAgentName !== agentName) {
@@ -9331,7 +9662,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9331
9662
  });
9332
9663
  return [2 /*return*/];
9333
9664
  }
9334
- return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$w, clientId, swarmName)];
9665
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$y, clientId, swarmName)];
9335
9666
  case 2:
9336
9667
  _a.sent();
9337
9668
  return [2 /*return*/];
@@ -9339,7 +9670,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9339
9670
  });
9340
9671
  }); };
9341
9672
 
9342
- var METHOD_NAME$v = "function.commitToolOutputForce";
9673
+ var METHOD_NAME$x = "function.commitToolOutputForce";
9343
9674
  /**
9344
9675
  * Commits the tool output to the active agent in a swarm session without checking active agent
9345
9676
  *
@@ -9353,15 +9684,15 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9353
9684
  switch (_a.label) {
9354
9685
  case 0:
9355
9686
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9356
- swarm$1.loggerService.log(METHOD_NAME$v, {
9687
+ swarm$1.loggerService.log(METHOD_NAME$x, {
9357
9688
  toolId: toolId,
9358
9689
  content: content,
9359
9690
  clientId: clientId,
9360
9691
  });
9361
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9692
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9362
9693
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9363
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9364
- return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$v, clientId, swarmName)];
9694
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9695
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$x, clientId, swarmName)];
9365
9696
  case 1:
9366
9697
  _a.sent();
9367
9698
  return [2 /*return*/];
@@ -9369,7 +9700,7 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9369
9700
  });
9370
9701
  }); };
9371
9702
 
9372
- var METHOD_NAME$u = "function.commitSystemMessageForce";
9703
+ var METHOD_NAME$w = "function.commitSystemMessageForce";
9373
9704
  /**
9374
9705
  * Commits a system message to the active agent in as swarm without checking active agent.
9375
9706
  *
@@ -9383,14 +9714,14 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9383
9714
  switch (_a.label) {
9384
9715
  case 0:
9385
9716
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9386
- swarm$1.loggerService.log(METHOD_NAME$u, {
9717
+ swarm$1.loggerService.log(METHOD_NAME$w, {
9387
9718
  content: content,
9388
9719
  clientId: clientId,
9389
9720
  });
9390
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9721
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9391
9722
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9392
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9393
- return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$u, clientId, swarmName)];
9723
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9724
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$w, clientId, swarmName)];
9394
9725
  case 1:
9395
9726
  _a.sent();
9396
9727
  return [2 /*return*/];
@@ -9398,7 +9729,7 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9398
9729
  });
9399
9730
  }); };
9400
9731
 
9401
- var METHOD_NAME$t = "function.commitFlushForce";
9732
+ var METHOD_NAME$v = "function.commitFlushForce";
9402
9733
  /**
9403
9734
  * Commits flush of agent history without active agent check
9404
9735
  *
@@ -9411,14 +9742,14 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9411
9742
  switch (_a.label) {
9412
9743
  case 0:
9413
9744
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9414
- swarm$1.loggerService.log(METHOD_NAME$t, {
9745
+ swarm$1.loggerService.log(METHOD_NAME$v, {
9415
9746
  clientId: clientId,
9416
- METHOD_NAME: METHOD_NAME$t,
9747
+ METHOD_NAME: METHOD_NAME$v,
9417
9748
  });
9418
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9749
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9419
9750
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9420
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9421
- return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$t, clientId, swarmName)];
9751
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9752
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitFlush(METHOD_NAME$v, clientId, swarmName)];
9422
9753
  case 1:
9423
9754
  _a.sent();
9424
9755
  return [2 /*return*/];
@@ -9426,7 +9757,7 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9426
9757
  });
9427
9758
  }); };
9428
9759
 
9429
- var METHOD_NAME$s = "function.commitSystemMessage";
9760
+ var METHOD_NAME$u = "function.commitSystemMessage";
9430
9761
  /**
9431
9762
  * Commits a user message to the active agent history in as swarm without answer and checking active agent
9432
9763
  *
@@ -9440,14 +9771,14 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9440
9771
  switch (_a.label) {
9441
9772
  case 0:
9442
9773
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9443
- swarm$1.loggerService.log(METHOD_NAME$s, {
9774
+ swarm$1.loggerService.log(METHOD_NAME$u, {
9444
9775
  content: content,
9445
9776
  clientId: clientId,
9446
9777
  });
9447
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9778
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9448
9779
  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)];
9780
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9781
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitUserMessage(content, METHOD_NAME$u, clientId, swarmName)];
9451
9782
  case 1:
9452
9783
  _a.sent();
9453
9784
  return [2 /*return*/];
@@ -9455,7 +9786,7 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9455
9786
  });
9456
9787
  }); };
9457
9788
 
9458
- var METHOD_NAME$r = "function.commitAssistantMessage";
9789
+ var METHOD_NAME$t = "function.commitAssistantMessage";
9459
9790
  /**
9460
9791
  * Commits an assistant message to the active agent in the swarm.
9461
9792
  *
@@ -9470,16 +9801,16 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9470
9801
  switch (_a.label) {
9471
9802
  case 0:
9472
9803
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9473
- swarm$1.loggerService.log(METHOD_NAME$r, {
9804
+ swarm$1.loggerService.log(METHOD_NAME$t, {
9474
9805
  content: content,
9475
9806
  clientId: clientId,
9476
9807
  agentName: agentName,
9477
9808
  });
9478
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9479
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9809
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$t);
9810
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9480
9811
  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)];
9812
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9813
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$t, clientId, swarmName)];
9483
9814
  case 1:
9484
9815
  currentAgentName = _a.sent();
9485
9816
  if (currentAgentName !== agentName) {
@@ -9491,7 +9822,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9491
9822
  });
9492
9823
  return [2 /*return*/];
9493
9824
  }
9494
- return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$r, clientId, swarmName)];
9825
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$t, clientId, swarmName)];
9495
9826
  case 2:
9496
9827
  _a.sent();
9497
9828
  return [2 /*return*/];
@@ -9499,7 +9830,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9499
9830
  });
9500
9831
  }); };
9501
9832
 
9502
- var METHOD_NAME$q = "function.commitAssistantMessageForce";
9833
+ var METHOD_NAME$s = "function.commitAssistantMessageForce";
9503
9834
  /**
9504
9835
  * Commits an assistant message to the active agent in as swarm without checking active agent.
9505
9836
  *
@@ -9513,14 +9844,14 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9513
9844
  switch (_a.label) {
9514
9845
  case 0:
9515
9846
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9516
- swarm$1.loggerService.log(METHOD_NAME$q, {
9847
+ swarm$1.loggerService.log(METHOD_NAME$s, {
9517
9848
  content: content,
9518
9849
  clientId: clientId,
9519
9850
  });
9520
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
9851
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9521
9852
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9522
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
9523
- return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$q, clientId, swarmName)];
9853
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
9854
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$s, clientId, swarmName)];
9524
9855
  case 1:
9525
9856
  _a.sent();
9526
9857
  return [2 /*return*/];
@@ -9528,7 +9859,7 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9528
9859
  });
9529
9860
  }); };
9530
9861
 
9531
- var METHOD_NAME$p = "function.cancelOutput";
9862
+ var METHOD_NAME$r = "function.cancelOutput";
9532
9863
  /**
9533
9864
  * Cancel the await of output by emit of empty string
9534
9865
  *
@@ -9542,15 +9873,15 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9542
9873
  switch (_a.label) {
9543
9874
  case 0:
9544
9875
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9545
- swarm$1.loggerService.log(METHOD_NAME$p, {
9876
+ swarm$1.loggerService.log(METHOD_NAME$r, {
9546
9877
  clientId: clientId,
9547
9878
  agentName: agentName,
9548
9879
  });
9549
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
9550
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
9880
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9881
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
9551
9882
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9552
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
9553
- return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName)];
9883
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
9884
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName)];
9554
9885
  case 1:
9555
9886
  currentAgentName = _a.sent();
9556
9887
  if (currentAgentName !== agentName) {
@@ -9562,7 +9893,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9562
9893
  });
9563
9894
  return [2 /*return*/];
9564
9895
  }
9565
- return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$p, clientId, swarmName)];
9896
+ return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$r, clientId, swarmName)];
9566
9897
  case 2:
9567
9898
  _a.sent();
9568
9899
  return [2 /*return*/];
@@ -9570,7 +9901,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9570
9901
  });
9571
9902
  }); };
9572
9903
 
9573
- var METHOD_NAME$o = "function.cancelOutputForce";
9904
+ var METHOD_NAME$q = "function.cancelOutputForce";
9574
9905
  /**
9575
9906
  * Cancel the await of output by emit of empty string without checking active agent
9576
9907
  *
@@ -9579,6 +9910,75 @@ var METHOD_NAME$o = "function.cancelOutputForce";
9579
9910
  * @returns {Promise<void>} - A promise that resolves when the output is canceled
9580
9911
  */
9581
9912
  var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
9913
+ var swarmName;
9914
+ return __generator(this, function (_a) {
9915
+ switch (_a.label) {
9916
+ case 0:
9917
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9918
+ swarm$1.loggerService.log(METHOD_NAME$q, {
9919
+ clientId: clientId,
9920
+ });
9921
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
9922
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9923
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
9924
+ return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$q, clientId, swarmName)];
9925
+ case 1:
9926
+ _a.sent();
9927
+ return [2 /*return*/];
9928
+ }
9929
+ });
9930
+ }); };
9931
+
9932
+ var METHOD_NAME$p = "function.commitStopTools";
9933
+ /**
9934
+ * Prevent the next tool from being executed
9935
+ *
9936
+ * @param {string} clientId - The ID of the client.
9937
+ * @param {string} agentName - The name of the agent.
9938
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9939
+ */
9940
+ var commitStopTools = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
9941
+ var swarmName, currentAgentName;
9942
+ return __generator(this, function (_a) {
9943
+ switch (_a.label) {
9944
+ case 0:
9945
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9946
+ swarm$1.loggerService.log(METHOD_NAME$p, {
9947
+ clientId: clientId,
9948
+ agentName: agentName,
9949
+ });
9950
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
9951
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
9952
+ swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9953
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
9954
+ return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName)];
9955
+ case 1:
9956
+ currentAgentName = _a.sent();
9957
+ if (currentAgentName !== agentName) {
9958
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9959
+ swarm$1.loggerService.log('function "commitStopTools" skipped due to the agent change', {
9960
+ currentAgentName: currentAgentName,
9961
+ agentName: agentName,
9962
+ clientId: clientId,
9963
+ });
9964
+ return [2 /*return*/];
9965
+ }
9966
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$p, clientId, swarmName)];
9967
+ case 2:
9968
+ _a.sent();
9969
+ return [2 /*return*/];
9970
+ }
9971
+ });
9972
+ }); };
9973
+
9974
+ var METHOD_NAME$o = "function.commitStopToolsForce";
9975
+ /**
9976
+ * Prevent the next tool from being executed without active agent check
9977
+ *
9978
+ * @param {string} clientId - The ID of the client.
9979
+ * @returns {Promise<void>} - A promise that resolves when the message is committed.
9980
+ */
9981
+ var commitStopToolsForce = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
9582
9982
  var swarmName;
9583
9983
  return __generator(this, function (_a) {
9584
9984
  switch (_a.label) {
@@ -9586,11 +9986,12 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
9586
9986
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9587
9987
  swarm$1.loggerService.log(METHOD_NAME$o, {
9588
9988
  clientId: clientId,
9989
+ METHOD_NAME: METHOD_NAME$o,
9589
9990
  });
9590
9991
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$o);
9591
9992
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9592
9993
  swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$o);
9593
- return [4 /*yield*/, swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$o, clientId, swarmName)];
9994
+ return [4 /*yield*/, swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$o, clientId, swarmName)];
9594
9995
  case 1:
9595
9996
  _a.sent();
9596
9997
  return [2 /*return*/];
@@ -11248,6 +11649,7 @@ var listenSwarmEventOnce = function (clientId, filterFn, fn) {
11248
11649
 
11249
11650
  var METHOD_NAME_GET$3 = "StateUtils.getState";
11250
11651
  var METHOD_NAME_SET$1 = "StateUtils.setState";
11652
+ var METHOD_NAME_CLEAR$3 = "StateUtils.clearState";
11251
11653
  /**
11252
11654
  * Utility class for managing state in the agent swarm.
11253
11655
  * @implements {TState}
@@ -11318,6 +11720,34 @@ var StateUtils = /** @class */ (function () {
11318
11720
  }
11319
11721
  });
11320
11722
  }); };
11723
+ /**
11724
+ * Set the state to initial value
11725
+ * @template T
11726
+ * @param {Object} payload - The payload containing client and state information.
11727
+ * @param {string} payload.clientId - The client ID.
11728
+ * @param {AgentName} payload.agentName - The agent name.
11729
+ * @param {StateName} payload.stateName - The state name.
11730
+ * @returns {Promise<void>}
11731
+ * @throws Will throw an error if the state is not registered in the agent.
11732
+ */
11733
+ this.clearState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11734
+ return __generator(this, function (_a) {
11735
+ switch (_a.label) {
11736
+ case 0:
11737
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11738
+ swarm$1.loggerService.log(METHOD_NAME_SET$1, {
11739
+ clientId: payload.clientId,
11740
+ stateName: payload.stateName,
11741
+ });
11742
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_SET$1);
11743
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11744
+ throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (clearState)"));
11745
+ }
11746
+ return [4 /*yield*/, swarm$1.statePublicService.clearState(METHOD_NAME_CLEAR$3, payload.clientId, payload.stateName)];
11747
+ case 1: return [2 /*return*/, _a.sent()];
11748
+ }
11749
+ });
11750
+ }); };
11321
11751
  }
11322
11752
  return StateUtils;
11323
11753
  }());
@@ -11329,6 +11759,7 @@ var State = new StateUtils();
11329
11759
 
11330
11760
  var METHOD_NAME_GET$2 = "SharedStateUtils.getSharedState";
11331
11761
  var METHOD_NAME_SET = "SharedStateUtils.setSharedState";
11762
+ var METHOD_NAME_CLEAR$2 = "SharedStateUtils.clearSharedState";
11332
11763
  /**
11333
11764
  * Utility class for managing state in the agent swarm.
11334
11765
  * @implements {TSharedState}
@@ -11393,6 +11824,31 @@ var SharedStateUtils = /** @class */ (function () {
11393
11824
  }
11394
11825
  });
11395
11826
  }); };
11827
+ /**
11828
+ * Set the state to initial value
11829
+ * @template T
11830
+ * @param {Object} payload - The payload containing client and state information.
11831
+ * @param {AgentName} payload.agentName - The agent name.
11832
+ * @param {StateName} payload.stateName - The state name.
11833
+ * @returns {Promise<void>}
11834
+ * @throws Will throw an error if the state is not registered in the agent.
11835
+ */
11836
+ this.clearState = function (payload) { return __awaiter(_this, void 0, void 0, function () {
11837
+ return __generator(this, function (_a) {
11838
+ switch (_a.label) {
11839
+ case 0:
11840
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
11841
+ swarm$1.loggerService.log(METHOD_NAME_SET, {
11842
+ stateName: payload.stateName,
11843
+ });
11844
+ if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11845
+ throw new Error("agent-swarm SharedStateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (clearState)"));
11846
+ }
11847
+ return [4 /*yield*/, swarm$1.sharedStatePublicService.clearState(METHOD_NAME_CLEAR$2, payload.stateName)];
11848
+ case 1: return [2 /*return*/, _a.sent()];
11849
+ }
11850
+ });
11851
+ }); };
11396
11852
  }
11397
11853
  return SharedStateUtils;
11398
11854
  }());
@@ -11869,6 +12325,8 @@ exports.commitAssistantMessage = commitAssistantMessage;
11869
12325
  exports.commitAssistantMessageForce = commitAssistantMessageForce;
11870
12326
  exports.commitFlush = commitFlush;
11871
12327
  exports.commitFlushForce = commitFlushForce;
12328
+ exports.commitStopTools = commitStopTools;
12329
+ exports.commitStopToolsForce = commitStopToolsForce;
11872
12330
  exports.commitSystemMessage = commitSystemMessage;
11873
12331
  exports.commitSystemMessageForce = commitSystemMessageForce;
11874
12332
  exports.commitToolOutput = commitToolOutput;