agent-swarm-kit 1.0.21 → 1.0.23

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
@@ -4189,6 +4189,57 @@ 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 isOk = true;
4204
+ var unSource = functoolsKit.Source.fromInterval(1000)
4205
+ .reduce(function (acm) {
4206
+ if (isOk) {
4207
+ isOk = false;
4208
+ return 0;
4209
+ }
4210
+ return acm + 1;
4211
+ }, 0)
4212
+ .filter(function (ticker) { return ticker >= timeoutSeconds; })
4213
+ .once(function () { return __awaiter(void 0, void 0, void 0, function () {
4214
+ return __generator(this, function (_a) {
4215
+ switch (_a.label) {
4216
+ case 0:
4217
+ unSource();
4218
+ if (!swarm.sessionValidationService.hasSession(clientId)) return [3 /*break*/, 2];
4219
+ return [4 /*yield*/, disposeConnection(clientId, swarmName)];
4220
+ case 1:
4221
+ _a.sent();
4222
+ _a.label = 2;
4223
+ case 2: return [2 /*return*/];
4224
+ }
4225
+ });
4226
+ }); });
4227
+ return {
4228
+ /**
4229
+ * Signals that the client is active, resetting the auto-dispose timer.
4230
+ */
4231
+ tick: function () {
4232
+ isOk = true;
4233
+ },
4234
+ /**
4235
+ * Stops the auto-dispose mechanism.
4236
+ */
4237
+ stop: function () {
4238
+ unSource();
4239
+ },
4240
+ };
4241
+ };
4242
+
4192
4243
  exports.ContextService = ContextService;
4193
4244
  exports.addAgent = addAgent;
4194
4245
  exports.addCompletion = addCompletion;
@@ -4210,6 +4261,7 @@ exports.getLastSystemMessage = getLastSystemMessage;
4210
4261
  exports.getLastUserMessage = getLastUserMessage;
4211
4262
  exports.getRawHistory = getRawHistory;
4212
4263
  exports.getUserHistory = getUserHistory;
4264
+ exports.makeAutoDispose = makeAutoDispose;
4213
4265
  exports.makeConnection = makeConnection;
4214
4266
  exports.session = session;
4215
4267
  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';
@@ -4187,4 +4187,55 @@ 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 isOk = true;
4202
+ var unSource = Source.fromInterval(1000)
4203
+ .reduce(function (acm) {
4204
+ if (isOk) {
4205
+ isOk = false;
4206
+ return 0;
4207
+ }
4208
+ return acm + 1;
4209
+ }, 0)
4210
+ .filter(function (ticker) { return ticker >= timeoutSeconds; })
4211
+ .once(function () { return __awaiter(void 0, void 0, void 0, function () {
4212
+ return __generator(this, function (_a) {
4213
+ switch (_a.label) {
4214
+ case 0:
4215
+ unSource();
4216
+ if (!swarm.sessionValidationService.hasSession(clientId)) return [3 /*break*/, 2];
4217
+ return [4 /*yield*/, disposeConnection(clientId, swarmName)];
4218
+ case 1:
4219
+ _a.sent();
4220
+ _a.label = 2;
4221
+ case 2: return [2 /*return*/];
4222
+ }
4223
+ });
4224
+ }); });
4225
+ return {
4226
+ /**
4227
+ * Signals that the client is active, resetting the auto-dispose timer.
4228
+ */
4229
+ tick: function () {
4230
+ isOk = true;
4231
+ },
4232
+ /**
4233
+ * Stops the auto-dispose mechanism.
4234
+ */
4235
+ stop: function () {
4236
+ unSource();
4237
+ },
4238
+ };
4239
+ };
4240
+
4241
+ 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.21",
3
+ "version": "1.0.23",
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,6 +1766,34 @@ 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[];
@@ -1777,4 +1805,4 @@ declare const GLOBAL_CONFIG: {
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 };