agent-swarm-kit 1.0.110 → 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.
@@ -5859,7 +6033,10 @@ var SessionValidationService = /** @class */ (function () {
5859
6033
  * @param {string} source - The source of the validation request.
5860
6034
  * @throws Will throw an error if the session does not exist.
5861
6035
  */
5862
- this.validate = function (clientId, source) {
6036
+ this.validate = functoolsKit.memoize(function (_a) {
6037
+ var _b = __read(_a, 1), clientId = _b[0];
6038
+ return "".concat(clientId);
6039
+ }, function (clientId, source) {
5863
6040
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
5864
6041
  _this.loggerService.info("sessionValidationService validate", {
5865
6042
  clientId: clientId,
@@ -5871,7 +6048,7 @@ var SessionValidationService = /** @class */ (function () {
5871
6048
  throw new Error("agent-swarm session clientId=".concat(clientId, " not exist source=").concat(source));
5872
6049
  }
5873
6050
  return {};
5874
- };
6051
+ });
5875
6052
  /**
5876
6053
  * Removes a session.
5877
6054
  * @param {SessionId} clientId - The ID of the client.
@@ -5884,6 +6061,13 @@ var SessionValidationService = /** @class */ (function () {
5884
6061
  _this._sessionSwarmMap.delete(clientId);
5885
6062
  _this._sessionModeMap.delete(clientId);
5886
6063
  };
6064
+ /**
6065
+ * Dispose a session validation cache.
6066
+ * @param {SessionId} clientId - The ID of the client.
6067
+ */
6068
+ this.dispose = function (clientId) {
6069
+ _this.validate.clear(clientId);
6070
+ };
5887
6071
  }
5888
6072
  return SessionValidationService;
5889
6073
  }());
@@ -7246,6 +7430,53 @@ var ClientState = /** @class */ (function () {
7246
7430
  }
7247
7431
  });
7248
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
+ }); };
7249
7480
  /**
7250
7481
  * Gets the current state.
7251
7482
  * @returns {Promise<State>}
@@ -7383,6 +7614,26 @@ var StateConnectionService = /** @class */ (function () {
7383
7614
  }
7384
7615
  });
7385
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
+ }); };
7386
7637
  /**
7387
7638
  * Gets the state.
7388
7639
  * @returns {Promise<T>} The current state.
@@ -7480,6 +7731,42 @@ var StatePublicService = /** @class */ (function () {
7480
7731
  }
7481
7732
  });
7482
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
+ }); };
7483
7770
  /**
7484
7771
  * Gets the current state.
7485
7772
  * @param {string} clientId - The client ID.
@@ -8349,6 +8636,26 @@ var SharedStateConnectionService = /** @class */ (function () {
8349
8636
  }
8350
8637
  });
8351
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
+ }); };
8352
8659
  /**
8353
8660
  * Gets the state.
8354
8661
  * @returns {Promise<T>} The current state.
@@ -8582,6 +8889,40 @@ var SharedStatePublicService = /** @class */ (function () {
8582
8889
  }
8583
8890
  });
8584
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
+ }); };
8585
8926
  /**
8586
8927
  * Gets the current state.
8587
8928
  * @param {StateName} stateName - The name of the state.
@@ -8952,7 +9293,7 @@ var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, b
8952
9293
  init();
8953
9294
  var swarm$1 = swarm;
8954
9295
 
8955
- var METHOD_NAME$J = "cli.dumpDocs";
9296
+ var METHOD_NAME$L = "cli.dumpDocs";
8956
9297
  /**
8957
9298
  * Dumps the documentation for the agents and swarms.
8958
9299
  *
@@ -8963,7 +9304,7 @@ var METHOD_NAME$J = "cli.dumpDocs";
8963
9304
  var dumpDocs = function (dirName, PlantUML) {
8964
9305
  if (dirName === void 0) { dirName = "./docs/chat"; }
8965
9306
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
8966
- swarm$1.loggerService.log(METHOD_NAME$J, {
9307
+ swarm$1.loggerService.log(METHOD_NAME$L, {
8967
9308
  dirName: dirName,
8968
9309
  });
8969
9310
  if (PlantUML) {
@@ -8974,12 +9315,12 @@ var dumpDocs = function (dirName, PlantUML) {
8974
9315
  swarm$1.agentValidationService
8975
9316
  .getAgentList()
8976
9317
  .forEach(function (agentName) {
8977
- return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
9318
+ return swarm$1.agentValidationService.validate(agentName, METHOD_NAME$L);
8978
9319
  });
8979
9320
  swarm$1.swarmValidationService
8980
9321
  .getSwarmList()
8981
9322
  .forEach(function (swarmName) {
8982
- return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9323
+ return swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$L);
8983
9324
  });
8984
9325
  swarm$1.agentValidationService.getAgentList().forEach(function (agentName) {
8985
9326
  var dependsOn = swarm$1.agentSchemaService.get(agentName).dependsOn;
@@ -8990,7 +9331,7 @@ var dumpDocs = function (dirName, PlantUML) {
8990
9331
  return swarm$1.docService.dumpDocs(dirName);
8991
9332
  };
8992
9333
 
8993
- var METHOD_NAME$I = "cli.dumpAgent";
9334
+ var METHOD_NAME$K = "cli.dumpAgent";
8994
9335
  /**
8995
9336
  * Dumps the agent information into PlantUML format.
8996
9337
  *
@@ -9000,14 +9341,14 @@ var METHOD_NAME$I = "cli.dumpAgent";
9000
9341
  var dumpAgent = function (agentName, _a) {
9001
9342
  var _b = _a === void 0 ? {} : _a, _c = _b.withSubtree, withSubtree = _c === void 0 ? false : _c;
9002
9343
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9003
- swarm$1.loggerService.log(METHOD_NAME$I, {
9344
+ swarm$1.loggerService.log(METHOD_NAME$K, {
9004
9345
  agentName: agentName,
9005
9346
  });
9006
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$I);
9347
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$K);
9007
9348
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
9008
9349
  };
9009
9350
 
9010
- var METHOD_NAME$H = "cli.dumpSwarm";
9351
+ var METHOD_NAME$J = "cli.dumpSwarm";
9011
9352
  /**
9012
9353
  * Dumps the swarm information into PlantUML format.
9013
9354
  *
@@ -9016,14 +9357,14 @@ var METHOD_NAME$H = "cli.dumpSwarm";
9016
9357
  */
9017
9358
  var dumpSwarm = function (swarmName) {
9018
9359
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9019
- swarm$1.loggerService.log(METHOD_NAME$H, {
9360
+ swarm$1.loggerService.log(METHOD_NAME$J, {
9020
9361
  swarmName: swarmName,
9021
9362
  });
9022
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
9363
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
9023
9364
  return swarm$1.swarmMetaService.toUML(swarmName);
9024
9365
  };
9025
9366
 
9026
- var METHOD_NAME$G = "function.addAgent";
9367
+ var METHOD_NAME$I = "function.addAgent";
9027
9368
  /**
9028
9369
  * Adds a new agent to the agent registry. The swarm takes only those agents which was registered
9029
9370
  *
@@ -9032,7 +9373,7 @@ var METHOD_NAME$G = "function.addAgent";
9032
9373
  */
9033
9374
  var addAgent = function (agentSchema) {
9034
9375
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9035
- swarm$1.loggerService.log(METHOD_NAME$G, {
9376
+ swarm$1.loggerService.log(METHOD_NAME$I, {
9036
9377
  agentSchema: agentSchema,
9037
9378
  });
9038
9379
  swarm$1.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
@@ -9040,7 +9381,7 @@ var addAgent = function (agentSchema) {
9040
9381
  return agentSchema.agentName;
9041
9382
  };
9042
9383
 
9043
- var METHOD_NAME$F = "function.addCompletion";
9384
+ var METHOD_NAME$H = "function.addCompletion";
9044
9385
  /**
9045
9386
  * Adds a completion engine for agents. Agents could use different models and
9046
9387
  * framewords for completion like: mock, gpt4all, ollama, openai
@@ -9050,7 +9391,7 @@ var METHOD_NAME$F = "function.addCompletion";
9050
9391
  */
9051
9392
  var addCompletion = function (completionSchema) {
9052
9393
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9053
- swarm$1.loggerService.log(METHOD_NAME$F, {
9394
+ swarm$1.loggerService.log(METHOD_NAME$H, {
9054
9395
  completionSchema: completionSchema,
9055
9396
  });
9056
9397
  swarm$1.completionValidationService.addCompletion(completionSchema.completionName);
@@ -9058,7 +9399,7 @@ var addCompletion = function (completionSchema) {
9058
9399
  return completionSchema.completionName;
9059
9400
  };
9060
9401
 
9061
- var METHOD_NAME$E = "function.addSwarm";
9402
+ var METHOD_NAME$G = "function.addSwarm";
9062
9403
  /**
9063
9404
  * Adds a new swarm to the system. The swarm is a root for starting client session
9064
9405
  *
@@ -9067,7 +9408,7 @@ var METHOD_NAME$E = "function.addSwarm";
9067
9408
  */
9068
9409
  var addSwarm = function (swarmSchema) {
9069
9410
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9070
- swarm$1.loggerService.log(METHOD_NAME$E, {
9411
+ swarm$1.loggerService.log(METHOD_NAME$G, {
9071
9412
  swarmSchema: swarmSchema,
9072
9413
  });
9073
9414
  swarm$1.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
@@ -9075,7 +9416,7 @@ var addSwarm = function (swarmSchema) {
9075
9416
  return swarmSchema.swarmName;
9076
9417
  };
9077
9418
 
9078
- var METHOD_NAME$D = "function.addTool";
9419
+ var METHOD_NAME$F = "function.addTool";
9079
9420
  /**
9080
9421
  * Adds a new tool for agents in a swarm. Tool should be registered in `addAgent`
9081
9422
  * declaration
@@ -9085,7 +9426,7 @@ var METHOD_NAME$D = "function.addTool";
9085
9426
  */
9086
9427
  var addTool = function (toolSchema) {
9087
9428
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9088
- swarm$1.loggerService.log(METHOD_NAME$D, {
9429
+ swarm$1.loggerService.log(METHOD_NAME$F, {
9089
9430
  toolSchema: toolSchema,
9090
9431
  });
9091
9432
  swarm$1.toolValidationService.addTool(toolSchema.toolName, toolSchema);
@@ -9093,7 +9434,7 @@ var addTool = function (toolSchema) {
9093
9434
  return toolSchema.toolName;
9094
9435
  };
9095
9436
 
9096
- var METHOD_NAME$C = "function.addState";
9437
+ var METHOD_NAME$E = "function.addState";
9097
9438
  /**
9098
9439
  * Adds a new state to the state registry. The swarm takes only those states which was registered
9099
9440
  *
@@ -9102,7 +9443,7 @@ var METHOD_NAME$C = "function.addState";
9102
9443
  */
9103
9444
  var addState = function (stateSchema) {
9104
9445
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9105
- swarm$1.loggerService.log(METHOD_NAME$C, {
9446
+ swarm$1.loggerService.log(METHOD_NAME$E, {
9106
9447
  stateSchema: stateSchema,
9107
9448
  });
9108
9449
  swarm$1.stateSchemaService.register(stateSchema.stateName, stateSchema);
@@ -9114,7 +9455,7 @@ var addState = function (stateSchema) {
9114
9455
  return stateSchema.stateName;
9115
9456
  };
9116
9457
 
9117
- var METHOD_NAME$B = "function.addEmbedding";
9458
+ var METHOD_NAME$D = "function.addEmbedding";
9118
9459
  /**
9119
9460
  * Adds a new embedding to the embedding registry. The swarm takes only those embeddings which was registered
9120
9461
  *
@@ -9123,7 +9464,7 @@ var METHOD_NAME$B = "function.addEmbedding";
9123
9464
  */
9124
9465
  var addEmbedding = function (embeddingSchema) {
9125
9466
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9126
- swarm$1.loggerService.log(METHOD_NAME$B, {
9467
+ swarm$1.loggerService.log(METHOD_NAME$D, {
9127
9468
  embeddingSchema: embeddingSchema,
9128
9469
  });
9129
9470
  swarm$1.embeddingValidationService.addEmbedding(embeddingSchema.embeddingName, embeddingSchema);
@@ -9131,7 +9472,7 @@ var addEmbedding = function (embeddingSchema) {
9131
9472
  return embeddingSchema.embeddingName;
9132
9473
  };
9133
9474
 
9134
- var METHOD_NAME$A = "function.addStorage";
9475
+ var METHOD_NAME$C = "function.addStorage";
9135
9476
  /**
9136
9477
  * Adds a new storage to the storage registry. The swarm takes only those storages which was registered
9137
9478
  *
@@ -9140,7 +9481,7 @@ var METHOD_NAME$A = "function.addStorage";
9140
9481
  */
9141
9482
  var addStorage = function (storageSchema) {
9142
9483
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9143
- swarm$1.loggerService.log(METHOD_NAME$A, {
9484
+ swarm$1.loggerService.log(METHOD_NAME$C, {
9144
9485
  storageSchema: storageSchema,
9145
9486
  });
9146
9487
  swarm$1.storageValidationService.addStorage(storageSchema.storageName, storageSchema);
@@ -9153,7 +9494,7 @@ var addStorage = function (storageSchema) {
9153
9494
  return storageSchema.storageName;
9154
9495
  };
9155
9496
 
9156
- var METHOD_NAME$z = "function.commitToolOutput";
9497
+ var METHOD_NAME$B = "function.commitToolOutput";
9157
9498
  /**
9158
9499
  * Commits the tool output to the active agent in a swarm session
9159
9500
  *
@@ -9168,17 +9509,17 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9168
9509
  switch (_a.label) {
9169
9510
  case 0:
9170
9511
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9171
- swarm$1.loggerService.log(METHOD_NAME$z, {
9512
+ swarm$1.loggerService.log(METHOD_NAME$B, {
9172
9513
  toolId: toolId,
9173
9514
  content: content,
9174
9515
  clientId: clientId,
9175
9516
  agentName: agentName,
9176
9517
  });
9177
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
9178
- 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);
9179
9520
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9180
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
9181
- 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)];
9182
9523
  case 1:
9183
9524
  currentAgentName = _a.sent();
9184
9525
  if (currentAgentName !== agentName) {
@@ -9191,7 +9532,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9191
9532
  });
9192
9533
  return [2 /*return*/];
9193
9534
  }
9194
- 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)];
9195
9536
  case 2:
9196
9537
  _a.sent();
9197
9538
  return [2 /*return*/];
@@ -9199,7 +9540,7 @@ var commitToolOutput = function (toolId, content, clientId, agentName) { return
9199
9540
  });
9200
9541
  }); };
9201
9542
 
9202
- var METHOD_NAME$y = "function.commitSystemMessage";
9543
+ var METHOD_NAME$A = "function.commitSystemMessage";
9203
9544
  /**
9204
9545
  * Commits a system message to the active agent in the swarm.
9205
9546
  *
@@ -9214,16 +9555,16 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9214
9555
  switch (_a.label) {
9215
9556
  case 0:
9216
9557
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9217
- swarm$1.loggerService.log(METHOD_NAME$y, {
9558
+ swarm$1.loggerService.log(METHOD_NAME$A, {
9218
9559
  content: content,
9219
9560
  clientId: clientId,
9220
9561
  agentName: agentName,
9221
9562
  });
9222
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$y);
9223
- 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);
9224
9565
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9225
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
9226
- 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)];
9227
9568
  case 1:
9228
9569
  currentAgentName = _a.sent();
9229
9570
  if (currentAgentName !== agentName) {
@@ -9235,7 +9576,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9235
9576
  });
9236
9577
  return [2 /*return*/];
9237
9578
  }
9238
- 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)];
9239
9580
  case 2:
9240
9581
  _a.sent();
9241
9582
  return [2 /*return*/];
@@ -9243,7 +9584,7 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
9243
9584
  });
9244
9585
  }); };
9245
9586
 
9246
- var METHOD_NAME$x = "function.commitFlush";
9587
+ var METHOD_NAME$z = "function.commitFlush";
9247
9588
  /**
9248
9589
  * Commits flush of agent history
9249
9590
  *
@@ -9257,15 +9598,15 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9257
9598
  switch (_a.label) {
9258
9599
  case 0:
9259
9600
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9260
- swarm$1.loggerService.log(METHOD_NAME$x, {
9601
+ swarm$1.loggerService.log(METHOD_NAME$z, {
9261
9602
  clientId: clientId,
9262
9603
  agentName: agentName,
9263
9604
  });
9264
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
9265
- 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);
9266
9607
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9267
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
9268
- 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)];
9269
9610
  case 1:
9270
9611
  currentAgentName = _a.sent();
9271
9612
  if (currentAgentName !== agentName) {
@@ -9277,7 +9618,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9277
9618
  });
9278
9619
  return [2 /*return*/];
9279
9620
  }
9280
- 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)];
9281
9622
  case 2:
9282
9623
  _a.sent();
9283
9624
  return [2 /*return*/];
@@ -9285,7 +9626,7 @@ var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void
9285
9626
  });
9286
9627
  }); };
9287
9628
 
9288
- var METHOD_NAME$w = "function.commitSystemMessage";
9629
+ var METHOD_NAME$y = "function.commitSystemMessage";
9289
9630
  /**
9290
9631
  * Commits a user message to the active agent history in as swarm without answer.
9291
9632
  *
@@ -9300,16 +9641,16 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9300
9641
  switch (_a.label) {
9301
9642
  case 0:
9302
9643
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9303
- swarm$1.loggerService.log(METHOD_NAME$w, {
9644
+ swarm$1.loggerService.log(METHOD_NAME$y, {
9304
9645
  content: content,
9305
9646
  clientId: clientId,
9306
9647
  agentName: agentName,
9307
9648
  });
9308
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
9309
- 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);
9310
9651
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9311
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
9312
- 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)];
9313
9654
  case 1:
9314
9655
  currentAgentName = _a.sent();
9315
9656
  if (currentAgentName !== agentName) {
@@ -9321,7 +9662,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9321
9662
  });
9322
9663
  return [2 /*return*/];
9323
9664
  }
9324
- 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)];
9325
9666
  case 2:
9326
9667
  _a.sent();
9327
9668
  return [2 /*return*/];
@@ -9329,7 +9670,7 @@ var commitUserMessage = function (content, clientId, agentName) { return __await
9329
9670
  });
9330
9671
  }); };
9331
9672
 
9332
- var METHOD_NAME$v = "function.commitToolOutputForce";
9673
+ var METHOD_NAME$x = "function.commitToolOutputForce";
9333
9674
  /**
9334
9675
  * Commits the tool output to the active agent in a swarm session without checking active agent
9335
9676
  *
@@ -9343,15 +9684,15 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9343
9684
  switch (_a.label) {
9344
9685
  case 0:
9345
9686
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9346
- swarm$1.loggerService.log(METHOD_NAME$v, {
9687
+ swarm$1.loggerService.log(METHOD_NAME$x, {
9347
9688
  toolId: toolId,
9348
9689
  content: content,
9349
9690
  clientId: clientId,
9350
9691
  });
9351
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9692
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
9352
9693
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9353
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
9354
- 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)];
9355
9696
  case 1:
9356
9697
  _a.sent();
9357
9698
  return [2 /*return*/];
@@ -9359,7 +9700,7 @@ var commitToolOutputForce = function (toolId, content, clientId) { return __awai
9359
9700
  });
9360
9701
  }); };
9361
9702
 
9362
- var METHOD_NAME$u = "function.commitSystemMessageForce";
9703
+ var METHOD_NAME$w = "function.commitSystemMessageForce";
9363
9704
  /**
9364
9705
  * Commits a system message to the active agent in as swarm without checking active agent.
9365
9706
  *
@@ -9373,14 +9714,14 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9373
9714
  switch (_a.label) {
9374
9715
  case 0:
9375
9716
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9376
- swarm$1.loggerService.log(METHOD_NAME$u, {
9717
+ swarm$1.loggerService.log(METHOD_NAME$w, {
9377
9718
  content: content,
9378
9719
  clientId: clientId,
9379
9720
  });
9380
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9721
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
9381
9722
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9382
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
9383
- 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)];
9384
9725
  case 1:
9385
9726
  _a.sent();
9386
9727
  return [2 /*return*/];
@@ -9388,7 +9729,7 @@ var commitSystemMessageForce = function (content, clientId) { return __awaiter(v
9388
9729
  });
9389
9730
  }); };
9390
9731
 
9391
- var METHOD_NAME$t = "function.commitFlushForce";
9732
+ var METHOD_NAME$v = "function.commitFlushForce";
9392
9733
  /**
9393
9734
  * Commits flush of agent history without active agent check
9394
9735
  *
@@ -9401,14 +9742,14 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9401
9742
  switch (_a.label) {
9402
9743
  case 0:
9403
9744
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9404
- swarm$1.loggerService.log(METHOD_NAME$t, {
9745
+ swarm$1.loggerService.log(METHOD_NAME$v, {
9405
9746
  clientId: clientId,
9406
- METHOD_NAME: METHOD_NAME$t,
9747
+ METHOD_NAME: METHOD_NAME$v,
9407
9748
  });
9408
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
9749
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
9409
9750
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9410
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
9411
- 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)];
9412
9753
  case 1:
9413
9754
  _a.sent();
9414
9755
  return [2 /*return*/];
@@ -9416,7 +9757,7 @@ var commitFlushForce = function (clientId) { return __awaiter(void 0, void 0, vo
9416
9757
  });
9417
9758
  }); };
9418
9759
 
9419
- var METHOD_NAME$s = "function.commitSystemMessage";
9760
+ var METHOD_NAME$u = "function.commitSystemMessage";
9420
9761
  /**
9421
9762
  * Commits a user message to the active agent history in as swarm without answer and checking active agent
9422
9763
  *
@@ -9430,14 +9771,14 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9430
9771
  switch (_a.label) {
9431
9772
  case 0:
9432
9773
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9433
- swarm$1.loggerService.log(METHOD_NAME$s, {
9774
+ swarm$1.loggerService.log(METHOD_NAME$u, {
9434
9775
  content: content,
9435
9776
  clientId: clientId,
9436
9777
  });
9437
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9778
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
9438
9779
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9439
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
9440
- 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)];
9441
9782
  case 1:
9442
9783
  _a.sent();
9443
9784
  return [2 /*return*/];
@@ -9445,7 +9786,7 @@ var commitUserMessageForce = function (content, clientId) { return __awaiter(voi
9445
9786
  });
9446
9787
  }); };
9447
9788
 
9448
- var METHOD_NAME$r = "function.commitAssistantMessage";
9789
+ var METHOD_NAME$t = "function.commitAssistantMessage";
9449
9790
  /**
9450
9791
  * Commits an assistant message to the active agent in the swarm.
9451
9792
  *
@@ -9460,16 +9801,16 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9460
9801
  switch (_a.label) {
9461
9802
  case 0:
9462
9803
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9463
- swarm$1.loggerService.log(METHOD_NAME$r, {
9804
+ swarm$1.loggerService.log(METHOD_NAME$t, {
9464
9805
  content: content,
9465
9806
  clientId: clientId,
9466
9807
  agentName: agentName,
9467
9808
  });
9468
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
9469
- 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);
9470
9811
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9471
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
9472
- 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)];
9473
9814
  case 1:
9474
9815
  currentAgentName = _a.sent();
9475
9816
  if (currentAgentName !== agentName) {
@@ -9481,7 +9822,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9481
9822
  });
9482
9823
  return [2 /*return*/];
9483
9824
  }
9484
- 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)];
9485
9826
  case 2:
9486
9827
  _a.sent();
9487
9828
  return [2 /*return*/];
@@ -9489,7 +9830,7 @@ var commitAssistantMessage = function (content, clientId, agentName) { return __
9489
9830
  });
9490
9831
  }); };
9491
9832
 
9492
- var METHOD_NAME$q = "function.commitAssistantMessageForce";
9833
+ var METHOD_NAME$s = "function.commitAssistantMessageForce";
9493
9834
  /**
9494
9835
  * Commits an assistant message to the active agent in as swarm without checking active agent.
9495
9836
  *
@@ -9503,14 +9844,14 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9503
9844
  switch (_a.label) {
9504
9845
  case 0:
9505
9846
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9506
- swarm$1.loggerService.log(METHOD_NAME$q, {
9847
+ swarm$1.loggerService.log(METHOD_NAME$s, {
9507
9848
  content: content,
9508
9849
  clientId: clientId,
9509
9850
  });
9510
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
9851
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
9511
9852
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9512
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
9513
- 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)];
9514
9855
  case 1:
9515
9856
  _a.sent();
9516
9857
  return [2 /*return*/];
@@ -9518,7 +9859,7 @@ var commitAssistantMessageForce = function (content, clientId) { return __awaite
9518
9859
  });
9519
9860
  }); };
9520
9861
 
9521
- var METHOD_NAME$p = "function.cancelOutput";
9862
+ var METHOD_NAME$r = "function.cancelOutput";
9522
9863
  /**
9523
9864
  * Cancel the await of output by emit of empty string
9524
9865
  *
@@ -9532,15 +9873,15 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9532
9873
  switch (_a.label) {
9533
9874
  case 0:
9534
9875
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9535
- swarm$1.loggerService.log(METHOD_NAME$p, {
9876
+ swarm$1.loggerService.log(METHOD_NAME$r, {
9536
9877
  clientId: clientId,
9537
9878
  agentName: agentName,
9538
9879
  });
9539
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
9540
- 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);
9541
9882
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9542
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
9543
- 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)];
9544
9885
  case 1:
9545
9886
  currentAgentName = _a.sent();
9546
9887
  if (currentAgentName !== agentName) {
@@ -9552,7 +9893,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9552
9893
  });
9553
9894
  return [2 /*return*/];
9554
9895
  }
9555
- 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)];
9556
9897
  case 2:
9557
9898
  _a.sent();
9558
9899
  return [2 /*return*/];
@@ -9560,7 +9901,7 @@ var cancelOutput = function (clientId, agentName) { return __awaiter(void 0, voi
9560
9901
  });
9561
9902
  }); };
9562
9903
 
9563
- var METHOD_NAME$o = "function.cancelOutputForce";
9904
+ var METHOD_NAME$q = "function.cancelOutputForce";
9564
9905
  /**
9565
9906
  * Cancel the await of output by emit of empty string without checking active agent
9566
9907
  *
@@ -9569,6 +9910,75 @@ var METHOD_NAME$o = "function.cancelOutputForce";
9569
9910
  * @returns {Promise<void>} - A promise that resolves when the output is canceled
9570
9911
  */
9571
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 () {
9572
9982
  var swarmName;
9573
9983
  return __generator(this, function (_a) {
9574
9984
  switch (_a.label) {
@@ -9576,11 +9986,12 @@ var cancelOutputForce = function (clientId) { return __awaiter(void 0, void 0, v
9576
9986
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
9577
9987
  swarm$1.loggerService.log(METHOD_NAME$o, {
9578
9988
  clientId: clientId,
9989
+ METHOD_NAME: METHOD_NAME$o,
9579
9990
  });
9580
9991
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$o);
9581
9992
  swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
9582
9993
  swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$o);
9583
- 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)];
9584
9995
  case 1:
9585
9996
  _a.sent();
9586
9997
  return [2 /*return*/];
@@ -9751,6 +10162,7 @@ var disposeConnection = function (clientId_1, swarmName_1) {
9751
10162
  _a.sent();
9752
10163
  swarm$1.sessionValidationService.removeSession(clientId);
9753
10164
  swarm$1.busService.dispose(clientId);
10165
+ swarm$1.sessionValidationService.dispose(clientId);
9754
10166
  return [2 /*return*/];
9755
10167
  }
9756
10168
  });
@@ -11237,6 +11649,7 @@ var listenSwarmEventOnce = function (clientId, filterFn, fn) {
11237
11649
 
11238
11650
  var METHOD_NAME_GET$3 = "StateUtils.getState";
11239
11651
  var METHOD_NAME_SET$1 = "StateUtils.setState";
11652
+ var METHOD_NAME_CLEAR$3 = "StateUtils.clearState";
11240
11653
  /**
11241
11654
  * Utility class for managing state in the agent swarm.
11242
11655
  * @implements {TState}
@@ -11263,6 +11676,7 @@ var StateUtils = /** @class */ (function () {
11263
11676
  clientId: payload.clientId,
11264
11677
  stateName: payload.stateName,
11265
11678
  });
11679
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_GET$3);
11266
11680
  if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11267
11681
  throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (getState)"));
11268
11682
  }
@@ -11292,6 +11706,7 @@ var StateUtils = /** @class */ (function () {
11292
11706
  clientId: payload.clientId,
11293
11707
  stateName: payload.stateName,
11294
11708
  });
11709
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_SET$1);
11295
11710
  if (!swarm$1.agentValidationService.hasState(payload.agentName, payload.stateName)) {
11296
11711
  throw new Error("agent-swarm StateUtils ".concat(payload.stateName, " not registered in ").concat(payload.agentName, " (setState)"));
11297
11712
  }
@@ -11305,6 +11720,34 @@ var StateUtils = /** @class */ (function () {
11305
11720
  }
11306
11721
  });
11307
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
+ }); };
11308
11751
  }
11309
11752
  return StateUtils;
11310
11753
  }());
@@ -11316,6 +11759,7 @@ var State = new StateUtils();
11316
11759
 
11317
11760
  var METHOD_NAME_GET$2 = "SharedStateUtils.getSharedState";
11318
11761
  var METHOD_NAME_SET = "SharedStateUtils.setSharedState";
11762
+ var METHOD_NAME_CLEAR$2 = "SharedStateUtils.clearSharedState";
11319
11763
  /**
11320
11764
  * Utility class for managing state in the agent swarm.
11321
11765
  * @implements {TSharedState}
@@ -11380,6 +11824,31 @@ var SharedStateUtils = /** @class */ (function () {
11380
11824
  }
11381
11825
  });
11382
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
+ }); };
11383
11852
  }
11384
11853
  return SharedStateUtils;
11385
11854
  }());
@@ -11420,6 +11889,7 @@ var StorageUtils = /** @class */ (function () {
11420
11889
  storageName: payload.storageName,
11421
11890
  score: payload.score,
11422
11891
  });
11892
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_TAKE$1);
11423
11893
  swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_TAKE$1);
11424
11894
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11425
11895
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (take)"));
@@ -11448,6 +11918,7 @@ var StorageUtils = /** @class */ (function () {
11448
11918
  clientId: payload.clientId,
11449
11919
  storageName: payload.storageName,
11450
11920
  });
11921
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_UPSERT$1);
11451
11922
  swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_UPSERT$1);
11452
11923
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11453
11924
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (upsert)"));
@@ -11475,6 +11946,7 @@ var StorageUtils = /** @class */ (function () {
11475
11946
  clientId: payload.clientId,
11476
11947
  storageName: payload.storageName,
11477
11948
  });
11949
+ swarm$1.sessionValidationService.validate(payload.clientId, METHOD_NAME_REMOVE$1);
11478
11950
  swarm$1.storageValidationService.validate(payload.storageName, METHOD_NAME_REMOVE$1);
11479
11951
  if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
11480
11952
  throw new Error("agent-swarm StorageUtils ".concat(payload.storageName, " not registered in ").concat(payload.agentName, " (remove)"));
@@ -11853,6 +12325,8 @@ exports.commitAssistantMessage = commitAssistantMessage;
11853
12325
  exports.commitAssistantMessageForce = commitAssistantMessageForce;
11854
12326
  exports.commitFlush = commitFlush;
11855
12327
  exports.commitFlushForce = commitFlushForce;
12328
+ exports.commitStopTools = commitStopTools;
12329
+ exports.commitStopToolsForce = commitStopToolsForce;
11856
12330
  exports.commitSystemMessage = commitSystemMessage;
11857
12331
  exports.commitSystemMessageForce = commitSystemMessageForce;
11858
12332
  exports.commitToolOutput = commitToolOutput;