agent-swarm-kit 1.0.20 → 1.0.22

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
@@ -294,13 +294,13 @@ var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaite
294
294
  });
295
295
  }); };
296
296
  var CC_KEEP_MESSAGES = 5;
297
- var CC_ANSWER_TIMEOUT_SECONDS = 120000;
297
+ var CC_ANSWER_TIMEOUT = 120000;
298
298
  var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
299
299
  var GLOBAL_CONFIG = {
300
300
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
301
301
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
302
302
  CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
303
- CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
303
+ CC_ANSWER_TIMEOUT: CC_ANSWER_TIMEOUT,
304
304
  CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
305
305
  CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
306
306
  CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
@@ -1249,7 +1249,7 @@ var ClientSwarm = /** @class */ (function () {
1249
1249
  START_TIME = Date.now();
1250
1250
  _c.label = 1;
1251
1251
  case 1:
1252
- if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
1252
+ if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT) {
1253
1253
  throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
1254
1254
  }
1255
1255
  return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
@@ -4189,6 +4189,60 @@ var getLastSystemMessage = function (clientId) { return __awaiter(void 0, void 0
4189
4189
  });
4190
4190
  }); };
4191
4191
 
4192
+ var DEFAULT_TIMEOUT = 15 * 60;
4193
+ /**
4194
+ * Creates an auto-dispose mechanism for a client in a swarm.
4195
+ *
4196
+ * @param {string} clientId - The ID of the client.
4197
+ * @param {SwarmName} swarmName - The name of the swarm.
4198
+ * @param {Partial<IMakeDisposeParams>} [params={}] - Optional parameters for auto-dispose.
4199
+ * @returns {Object} An object with tick and stop methods to control the auto-dispose.
4200
+ */
4201
+ var makeAutoDispose = function (clientId, swarmName, _a) {
4202
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeoutSeconds, timeoutSeconds = _c === void 0 ? DEFAULT_TIMEOUT : _c;
4203
+ var stateEmitter = new functoolsKit.Subject();
4204
+ var unSource = functoolsKit.Source.join([
4205
+ stateEmitter.toObserver(),
4206
+ functoolsKit.Source.fromInterval(1000),
4207
+ ])
4208
+ .reduce(function (acm, _a) {
4209
+ var _b = __read(_a, 1), isOk = _b[0];
4210
+ if (isOk) {
4211
+ return acm + 1;
4212
+ }
4213
+ return 0;
4214
+ }, 0)
4215
+ .filter(function (ticker) { return ticker >= timeoutSeconds; })
4216
+ .once(function () { return __awaiter(void 0, void 0, void 0, function () {
4217
+ return __generator(this, function (_a) {
4218
+ switch (_a.label) {
4219
+ case 0:
4220
+ unSource();
4221
+ if (!swarm.sessionValidationService.hasSession(clientId)) return [3 /*break*/, 2];
4222
+ return [4 /*yield*/, disposeConnection(clientId, swarmName)];
4223
+ case 1:
4224
+ _a.sent();
4225
+ _a.label = 2;
4226
+ case 2: return [2 /*return*/];
4227
+ }
4228
+ });
4229
+ }); });
4230
+ return {
4231
+ /**
4232
+ * Signals that the client is active, resetting the auto-dispose timer.
4233
+ */
4234
+ tick: function () {
4235
+ stateEmitter.next(true);
4236
+ },
4237
+ /**
4238
+ * Stops the auto-dispose mechanism.
4239
+ */
4240
+ stop: function () {
4241
+ unSource();
4242
+ },
4243
+ };
4244
+ };
4245
+
4192
4246
  exports.ContextService = ContextService;
4193
4247
  exports.addAgent = addAgent;
4194
4248
  exports.addCompletion = addCompletion;
@@ -4210,6 +4264,7 @@ exports.getLastSystemMessage = getLastSystemMessage;
4210
4264
  exports.getLastUserMessage = getLastUserMessage;
4211
4265
  exports.getRawHistory = getRawHistory;
4212
4266
  exports.getUserHistory = getUserHistory;
4267
+ exports.makeAutoDispose = makeAutoDispose;
4213
4268
  exports.makeConnection = makeConnection;
4214
4269
  exports.session = session;
4215
4270
  exports.setConfig = setConfig;
package/build/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { scoped } from 'di-scoped';
2
- import { ToolRegistry, sleep, PubsubArrayAdapter, Subject, queued, not, trycatch, memoize, schedule, ttl, singleshot } from 'functools-kit';
2
+ import { ToolRegistry, sleep, PubsubArrayAdapter, Subject, queued, not, trycatch, memoize, schedule, ttl, singleshot, Source } from 'functools-kit';
3
3
  import { createActivator } from 'di-kit';
4
4
  import { omit } from 'lodash-es';
5
5
  import xml2js from 'xml2js';
@@ -292,13 +292,13 @@ var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaite
292
292
  });
293
293
  }); };
294
294
  var CC_KEEP_MESSAGES = 5;
295
- var CC_ANSWER_TIMEOUT_SECONDS = 120000;
295
+ var CC_ANSWER_TIMEOUT = 120000;
296
296
  var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
297
297
  var GLOBAL_CONFIG = {
298
298
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
299
299
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
300
300
  CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
301
- CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
301
+ CC_ANSWER_TIMEOUT: CC_ANSWER_TIMEOUT,
302
302
  CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
303
303
  CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
304
304
  CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
@@ -1247,7 +1247,7 @@ var ClientSwarm = /** @class */ (function () {
1247
1247
  START_TIME = Date.now();
1248
1248
  _c.label = 1;
1249
1249
  case 1:
1250
- if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
1250
+ if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT) {
1251
1251
  throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
1252
1252
  }
1253
1253
  return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
@@ -4187,4 +4187,58 @@ var getLastSystemMessage = function (clientId) { return __awaiter(void 0, void 0
4187
4187
  });
4188
4188
  }); };
4189
4189
 
4190
- export { ContextService, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeConnection, session, setConfig, swarm };
4190
+ var DEFAULT_TIMEOUT = 15 * 60;
4191
+ /**
4192
+ * Creates an auto-dispose mechanism for a client in a swarm.
4193
+ *
4194
+ * @param {string} clientId - The ID of the client.
4195
+ * @param {SwarmName} swarmName - The name of the swarm.
4196
+ * @param {Partial<IMakeDisposeParams>} [params={}] - Optional parameters for auto-dispose.
4197
+ * @returns {Object} An object with tick and stop methods to control the auto-dispose.
4198
+ */
4199
+ var makeAutoDispose = function (clientId, swarmName, _a) {
4200
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeoutSeconds, timeoutSeconds = _c === void 0 ? DEFAULT_TIMEOUT : _c;
4201
+ var stateEmitter = new Subject();
4202
+ var unSource = Source.join([
4203
+ stateEmitter.toObserver(),
4204
+ Source.fromInterval(1000),
4205
+ ])
4206
+ .reduce(function (acm, _a) {
4207
+ var _b = __read(_a, 1), isOk = _b[0];
4208
+ if (isOk) {
4209
+ return acm + 1;
4210
+ }
4211
+ return 0;
4212
+ }, 0)
4213
+ .filter(function (ticker) { return ticker >= timeoutSeconds; })
4214
+ .once(function () { return __awaiter(void 0, void 0, void 0, function () {
4215
+ return __generator(this, function (_a) {
4216
+ switch (_a.label) {
4217
+ case 0:
4218
+ unSource();
4219
+ if (!swarm.sessionValidationService.hasSession(clientId)) return [3 /*break*/, 2];
4220
+ return [4 /*yield*/, disposeConnection(clientId, swarmName)];
4221
+ case 1:
4222
+ _a.sent();
4223
+ _a.label = 2;
4224
+ case 2: return [2 /*return*/];
4225
+ }
4226
+ });
4227
+ }); });
4228
+ return {
4229
+ /**
4230
+ * Signals that the client is active, resetting the auto-dispose timer.
4231
+ */
4232
+ tick: function () {
4233
+ stateEmitter.next(true);
4234
+ },
4235
+ /**
4236
+ * Stops the auto-dispose mechanism.
4237
+ */
4238
+ stop: function () {
4239
+ unSource();
4240
+ },
4241
+ };
4242
+ };
4243
+
4244
+ export { ContextService, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -1766,15 +1766,43 @@ declare const getLastAssistantMessage: (clientId: string) => Promise<string>;
1766
1766
  */
1767
1767
  declare const getLastSystemMessage: (clientId: string) => Promise<string>;
1768
1768
 
1769
+ /**
1770
+ * Interface for the parameters of the makeAutoDispose function.
1771
+ */
1772
+ interface IMakeDisposeParams {
1773
+ /**
1774
+ * Timeout in seconds before auto-dispose is triggered.
1775
+ */
1776
+ timeoutSeconds: number;
1777
+ }
1778
+ /**
1779
+ * Creates an auto-dispose mechanism for a client in a swarm.
1780
+ *
1781
+ * @param {string} clientId - The ID of the client.
1782
+ * @param {SwarmName} swarmName - The name of the swarm.
1783
+ * @param {Partial<IMakeDisposeParams>} [params={}] - Optional parameters for auto-dispose.
1784
+ * @returns {Object} An object with tick and stop methods to control the auto-dispose.
1785
+ */
1786
+ declare const makeAutoDispose: (clientId: string, swarmName: SwarmName, { timeoutSeconds }?: Partial<IMakeDisposeParams>) => {
1787
+ /**
1788
+ * Signals that the client is active, resetting the auto-dispose timer.
1789
+ */
1790
+ tick(): void;
1791
+ /**
1792
+ * Stops the auto-dispose mechanism.
1793
+ */
1794
+ stop(): void;
1795
+ };
1796
+
1769
1797
  declare const GLOBAL_CONFIG: {
1770
1798
  CC_TOOL_CALL_EXCEPTION_PROMPT: string;
1771
1799
  CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
1772
1800
  CC_KEEP_MESSAGES: number;
1773
- CC_ANSWER_TIMEOUT_SECONDS: number;
1801
+ CC_ANSWER_TIMEOUT: number;
1774
1802
  CC_GET_AGENT_HISTORY: (clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>;
1775
1803
  CC_SWARM_AGENT_CHANGED: (clientId: string, agentName: AgentName, swarmName: SwarmName) => Promise<void>;
1776
1804
  CC_SWARM_DEFAULT_AGENT: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName>;
1777
1805
  };
1778
1806
  declare const setConfig: (config: typeof GLOBAL_CONFIG) => void;
1779
1807
 
1780
- export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeConnection, session, setConfig, swarm };
1808
+ export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };