agent-swarm-kit 1.0.195 → 1.0.197
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 +196 -0
- package/build/index.mjs +196 -1
- package/package.json +1 -1
- package/types.d.ts +54 -1
package/build/index.cjs
CHANGED
|
@@ -16849,6 +16849,201 @@ class SharedStateUtils {
|
|
|
16849
16849
|
*/
|
|
16850
16850
|
const SharedState = new SharedStateUtils();
|
|
16851
16851
|
|
|
16852
|
+
/** @constant {string} */
|
|
16853
|
+
const CHAT_UTILS_METHOD_NAME_SEND_MESSAGE = "ChatUtils.sendMessage";
|
|
16854
|
+
/** @constant {string} */
|
|
16855
|
+
const CHAT_UTILS_METHOD_NAME_LISTEN_DISPOSE = "ChatUtils.listenDispose";
|
|
16856
|
+
/** @constant {string} */
|
|
16857
|
+
const CHAT_UTILS_METHOD_NAME_DISPOSE = "ChatUtils.dispose";
|
|
16858
|
+
/** @constant {string} */
|
|
16859
|
+
const CHAT_INSTANCE_METHOD_NAME_SEND_MESSAGE = "ChatInstance.sendMessage";
|
|
16860
|
+
/** @constant {string} */
|
|
16861
|
+
const CHAT_INSTANCE_METHOD_NAME_DISPOSE = "ChatInstance.dispose";
|
|
16862
|
+
/** @constant {string} */
|
|
16863
|
+
const CHAT_INSTANCE_METHOD_NAME_LISTEN_DISPOSE = "ChatInstance.listenDispose";
|
|
16864
|
+
/** @constant {number} Time interval in milliseconds for inactivity checks (1 minute) */
|
|
16865
|
+
const INACTIVITY_CHECK = 60 * 1000;
|
|
16866
|
+
/** @constant {number} Time in milliseconds before a chat is considered inactive (15 minutes) */
|
|
16867
|
+
const INACTIVITY_TIMEOUT = 15 * 60 * 1000;
|
|
16868
|
+
/**
|
|
16869
|
+
* Represents a single chat instance for a client
|
|
16870
|
+
* @class
|
|
16871
|
+
*/
|
|
16872
|
+
class ChatInstance {
|
|
16873
|
+
/**
|
|
16874
|
+
* Gets the timestamp of the last activity
|
|
16875
|
+
* @public
|
|
16876
|
+
* @returns {number} Last activity timestamp
|
|
16877
|
+
*/
|
|
16878
|
+
get lastActivity() {
|
|
16879
|
+
return this._lastActivity;
|
|
16880
|
+
}
|
|
16881
|
+
/**
|
|
16882
|
+
* Creates a new ChatInstance
|
|
16883
|
+
* @param {SessionId} clientId - The client identifier
|
|
16884
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16885
|
+
* @param {DisposeFn} onDispose - Callback function for disposal
|
|
16886
|
+
*/
|
|
16887
|
+
constructor(clientId, swarmName, onDispose) {
|
|
16888
|
+
this.clientId = clientId;
|
|
16889
|
+
this.swarmName = swarmName;
|
|
16890
|
+
this.onDispose = onDispose;
|
|
16891
|
+
/** @private @type {Subject<SessionId>} Subject for disposal notifications */
|
|
16892
|
+
this.disposeSubject = new functoolsKit.Subject();
|
|
16893
|
+
/** @private @type {number} Timestamp of last activity */
|
|
16894
|
+
this._lastActivity = Date.now();
|
|
16895
|
+
/**
|
|
16896
|
+
* Sends a message through the chat session
|
|
16897
|
+
* @public
|
|
16898
|
+
* @async
|
|
16899
|
+
* @param {string} content - Message content to send
|
|
16900
|
+
* @returns {Promise<any>} Result of the message completion
|
|
16901
|
+
*/
|
|
16902
|
+
this.sendMessage = async (content) => {
|
|
16903
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16904
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_SEND_MESSAGE, {
|
|
16905
|
+
content,
|
|
16906
|
+
clientId: this.clientId,
|
|
16907
|
+
swarmName: this.swarmName,
|
|
16908
|
+
timestamp: new Date().toISOString(),
|
|
16909
|
+
});
|
|
16910
|
+
this._lastActivity = Date.now();
|
|
16911
|
+
return await this.chatSession.complete(content);
|
|
16912
|
+
};
|
|
16913
|
+
/**
|
|
16914
|
+
* Disposes of the chat instance
|
|
16915
|
+
* @public
|
|
16916
|
+
* @async
|
|
16917
|
+
* @returns {Promise<void>}
|
|
16918
|
+
*/
|
|
16919
|
+
this.dispose = async () => {
|
|
16920
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16921
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
16922
|
+
clientId: this.clientId,
|
|
16923
|
+
swarmName: this.swarmName,
|
|
16924
|
+
timestamp: new Date().toISOString(),
|
|
16925
|
+
});
|
|
16926
|
+
await this.disposeSubject.next(this.clientId);
|
|
16927
|
+
await this.chatSession.dispose();
|
|
16928
|
+
};
|
|
16929
|
+
/**
|
|
16930
|
+
* Subscribes to disposal events
|
|
16931
|
+
* @public
|
|
16932
|
+
* @param {(clientId: SessionId) => void} fn - Callback function for disposal events
|
|
16933
|
+
* @returns {any} Subscription object
|
|
16934
|
+
*/
|
|
16935
|
+
this.listenDispose = (fn) => {
|
|
16936
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16937
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_LISTEN_DISPOSE, {
|
|
16938
|
+
clientId: this.clientId,
|
|
16939
|
+
swarmName: this.swarmName,
|
|
16940
|
+
});
|
|
16941
|
+
return this.disposeSubject.once(fn);
|
|
16942
|
+
};
|
|
16943
|
+
this.chatSession = session(this.clientId, this.swarmName, {
|
|
16944
|
+
onDispose: this.onDispose,
|
|
16945
|
+
});
|
|
16946
|
+
}
|
|
16947
|
+
}
|
|
16948
|
+
/**
|
|
16949
|
+
* Utility class for managing multiple chat instances
|
|
16950
|
+
* @class
|
|
16951
|
+
*/
|
|
16952
|
+
class ChatUtils {
|
|
16953
|
+
constructor() {
|
|
16954
|
+
/** @private @type {Map<SessionId, ChatInstance>} Map of active chat instances */
|
|
16955
|
+
this._chats = new Map();
|
|
16956
|
+
/**
|
|
16957
|
+
* Initializes cleanup interval for inactive chats
|
|
16958
|
+
* @private
|
|
16959
|
+
* @returns {void}
|
|
16960
|
+
*/
|
|
16961
|
+
this.initializeCleanup = functoolsKit.singleshot(() => {
|
|
16962
|
+
const handleCleanup = async () => {
|
|
16963
|
+
const now = Date.now();
|
|
16964
|
+
for (const chat of this._chats.values()) {
|
|
16965
|
+
if (now - chat.lastActivity >= INACTIVITY_TIMEOUT) {
|
|
16966
|
+
await chat.dispose();
|
|
16967
|
+
}
|
|
16968
|
+
}
|
|
16969
|
+
};
|
|
16970
|
+
setInterval(handleCleanup, INACTIVITY_CHECK);
|
|
16971
|
+
});
|
|
16972
|
+
/**
|
|
16973
|
+
* Gets or creates a chat instance for a client
|
|
16974
|
+
* @private
|
|
16975
|
+
* @param {SessionId} clientId - The client identifier
|
|
16976
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16977
|
+
* @returns {ChatInstance} Chat instance for the client
|
|
16978
|
+
*/
|
|
16979
|
+
this.getChatInstance = (clientId, swarmName) => {
|
|
16980
|
+
return this._chats.has(clientId)
|
|
16981
|
+
? this._chats.get(clientId)
|
|
16982
|
+
: this._chats
|
|
16983
|
+
.set(clientId, new ChatInstance(clientId, swarmName, () => {
|
|
16984
|
+
this._chats.delete(clientId);
|
|
16985
|
+
}))
|
|
16986
|
+
.get(clientId);
|
|
16987
|
+
};
|
|
16988
|
+
/**
|
|
16989
|
+
* Sends a message for a specific client
|
|
16990
|
+
* @public
|
|
16991
|
+
* @async
|
|
16992
|
+
* @param {SessionId} clientId - The client identifier
|
|
16993
|
+
* @param {string} message - Message content to send
|
|
16994
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16995
|
+
* @returns {Promise<any>} Result of the message sending
|
|
16996
|
+
*/
|
|
16997
|
+
this.sendMessage = async (clientId, message, swarmName) => {
|
|
16998
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16999
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_SEND_MESSAGE, {
|
|
17000
|
+
clientId,
|
|
17001
|
+
message,
|
|
17002
|
+
swarmName,
|
|
17003
|
+
});
|
|
17004
|
+
this.initializeCleanup();
|
|
17005
|
+
return await this.getChatInstance(clientId, swarmName).sendMessage(message);
|
|
17006
|
+
};
|
|
17007
|
+
/**
|
|
17008
|
+
* Subscribes to disposal events for a specific client
|
|
17009
|
+
* @public
|
|
17010
|
+
* @param {SessionId} clientId - The client identifier
|
|
17011
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
17012
|
+
* @param {(clientId: SessionId) => void} fn - Callback function for disposal events
|
|
17013
|
+
* @returns {any} Subscription object
|
|
17014
|
+
*/
|
|
17015
|
+
this.listenDispose = (clientId, swarmName, fn) => {
|
|
17016
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17017
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_LISTEN_DISPOSE, {
|
|
17018
|
+
clientId,
|
|
17019
|
+
swarmName,
|
|
17020
|
+
});
|
|
17021
|
+
return this.getChatInstance(clientId, swarmName).listenDispose(fn);
|
|
17022
|
+
};
|
|
17023
|
+
/**
|
|
17024
|
+
* Disposes of a specific chat instance for a client
|
|
17025
|
+
* @public
|
|
17026
|
+
* @async
|
|
17027
|
+
* @param {SessionId} clientId - The client identifier for the chat instance to dispose
|
|
17028
|
+
* @param {SwarmName} swarmName - The swarm name associated with the chat instance
|
|
17029
|
+
* @returns {Promise<void>} A promise that resolves when the chat instance has been disposed
|
|
17030
|
+
*/
|
|
17031
|
+
this.dispose = async (clientId, swarmName) => {
|
|
17032
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17033
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_DISPOSE, {
|
|
17034
|
+
clientId,
|
|
17035
|
+
swarmName,
|
|
17036
|
+
});
|
|
17037
|
+
if (!this._chats.has(clientId)) {
|
|
17038
|
+
return;
|
|
17039
|
+
}
|
|
17040
|
+
return await this.getChatInstance(clientId, swarmName).dispose();
|
|
17041
|
+
};
|
|
17042
|
+
}
|
|
17043
|
+
}
|
|
17044
|
+
/** @constant {ChatUtils} Singleton instance of ChatUtils */
|
|
17045
|
+
const Chat = new ChatUtils();
|
|
17046
|
+
|
|
16852
17047
|
/** @private Constant for logging the take method in StorageUtils */
|
|
16853
17048
|
const METHOD_NAME_TAKE$1 = "StorageUtils.take";
|
|
16854
17049
|
/** @private Constant for logging the upsert method in StorageUtils */
|
|
@@ -17633,6 +17828,7 @@ const Utils = {
|
|
|
17633
17828
|
};
|
|
17634
17829
|
|
|
17635
17830
|
exports.Adapter = Adapter;
|
|
17831
|
+
exports.Chat = Chat;
|
|
17636
17832
|
exports.ExecutionContextService = ExecutionContextService;
|
|
17637
17833
|
exports.History = History;
|
|
17638
17834
|
exports.HistoryMemoryInstance = HistoryMemoryInstance;
|
package/build/index.mjs
CHANGED
|
@@ -16847,6 +16847,201 @@ class SharedStateUtils {
|
|
|
16847
16847
|
*/
|
|
16848
16848
|
const SharedState = new SharedStateUtils();
|
|
16849
16849
|
|
|
16850
|
+
/** @constant {string} */
|
|
16851
|
+
const CHAT_UTILS_METHOD_NAME_SEND_MESSAGE = "ChatUtils.sendMessage";
|
|
16852
|
+
/** @constant {string} */
|
|
16853
|
+
const CHAT_UTILS_METHOD_NAME_LISTEN_DISPOSE = "ChatUtils.listenDispose";
|
|
16854
|
+
/** @constant {string} */
|
|
16855
|
+
const CHAT_UTILS_METHOD_NAME_DISPOSE = "ChatUtils.dispose";
|
|
16856
|
+
/** @constant {string} */
|
|
16857
|
+
const CHAT_INSTANCE_METHOD_NAME_SEND_MESSAGE = "ChatInstance.sendMessage";
|
|
16858
|
+
/** @constant {string} */
|
|
16859
|
+
const CHAT_INSTANCE_METHOD_NAME_DISPOSE = "ChatInstance.dispose";
|
|
16860
|
+
/** @constant {string} */
|
|
16861
|
+
const CHAT_INSTANCE_METHOD_NAME_LISTEN_DISPOSE = "ChatInstance.listenDispose";
|
|
16862
|
+
/** @constant {number} Time interval in milliseconds for inactivity checks (1 minute) */
|
|
16863
|
+
const INACTIVITY_CHECK = 60 * 1000;
|
|
16864
|
+
/** @constant {number} Time in milliseconds before a chat is considered inactive (15 minutes) */
|
|
16865
|
+
const INACTIVITY_TIMEOUT = 15 * 60 * 1000;
|
|
16866
|
+
/**
|
|
16867
|
+
* Represents a single chat instance for a client
|
|
16868
|
+
* @class
|
|
16869
|
+
*/
|
|
16870
|
+
class ChatInstance {
|
|
16871
|
+
/**
|
|
16872
|
+
* Gets the timestamp of the last activity
|
|
16873
|
+
* @public
|
|
16874
|
+
* @returns {number} Last activity timestamp
|
|
16875
|
+
*/
|
|
16876
|
+
get lastActivity() {
|
|
16877
|
+
return this._lastActivity;
|
|
16878
|
+
}
|
|
16879
|
+
/**
|
|
16880
|
+
* Creates a new ChatInstance
|
|
16881
|
+
* @param {SessionId} clientId - The client identifier
|
|
16882
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16883
|
+
* @param {DisposeFn} onDispose - Callback function for disposal
|
|
16884
|
+
*/
|
|
16885
|
+
constructor(clientId, swarmName, onDispose) {
|
|
16886
|
+
this.clientId = clientId;
|
|
16887
|
+
this.swarmName = swarmName;
|
|
16888
|
+
this.onDispose = onDispose;
|
|
16889
|
+
/** @private @type {Subject<SessionId>} Subject for disposal notifications */
|
|
16890
|
+
this.disposeSubject = new Subject();
|
|
16891
|
+
/** @private @type {number} Timestamp of last activity */
|
|
16892
|
+
this._lastActivity = Date.now();
|
|
16893
|
+
/**
|
|
16894
|
+
* Sends a message through the chat session
|
|
16895
|
+
* @public
|
|
16896
|
+
* @async
|
|
16897
|
+
* @param {string} content - Message content to send
|
|
16898
|
+
* @returns {Promise<any>} Result of the message completion
|
|
16899
|
+
*/
|
|
16900
|
+
this.sendMessage = async (content) => {
|
|
16901
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16902
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_SEND_MESSAGE, {
|
|
16903
|
+
content,
|
|
16904
|
+
clientId: this.clientId,
|
|
16905
|
+
swarmName: this.swarmName,
|
|
16906
|
+
timestamp: new Date().toISOString(),
|
|
16907
|
+
});
|
|
16908
|
+
this._lastActivity = Date.now();
|
|
16909
|
+
return await this.chatSession.complete(content);
|
|
16910
|
+
};
|
|
16911
|
+
/**
|
|
16912
|
+
* Disposes of the chat instance
|
|
16913
|
+
* @public
|
|
16914
|
+
* @async
|
|
16915
|
+
* @returns {Promise<void>}
|
|
16916
|
+
*/
|
|
16917
|
+
this.dispose = async () => {
|
|
16918
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16919
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
16920
|
+
clientId: this.clientId,
|
|
16921
|
+
swarmName: this.swarmName,
|
|
16922
|
+
timestamp: new Date().toISOString(),
|
|
16923
|
+
});
|
|
16924
|
+
await this.disposeSubject.next(this.clientId);
|
|
16925
|
+
await this.chatSession.dispose();
|
|
16926
|
+
};
|
|
16927
|
+
/**
|
|
16928
|
+
* Subscribes to disposal events
|
|
16929
|
+
* @public
|
|
16930
|
+
* @param {(clientId: SessionId) => void} fn - Callback function for disposal events
|
|
16931
|
+
* @returns {any} Subscription object
|
|
16932
|
+
*/
|
|
16933
|
+
this.listenDispose = (fn) => {
|
|
16934
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
16935
|
+
swarm$1.loggerService.debug(CHAT_INSTANCE_METHOD_NAME_LISTEN_DISPOSE, {
|
|
16936
|
+
clientId: this.clientId,
|
|
16937
|
+
swarmName: this.swarmName,
|
|
16938
|
+
});
|
|
16939
|
+
return this.disposeSubject.once(fn);
|
|
16940
|
+
};
|
|
16941
|
+
this.chatSession = session(this.clientId, this.swarmName, {
|
|
16942
|
+
onDispose: this.onDispose,
|
|
16943
|
+
});
|
|
16944
|
+
}
|
|
16945
|
+
}
|
|
16946
|
+
/**
|
|
16947
|
+
* Utility class for managing multiple chat instances
|
|
16948
|
+
* @class
|
|
16949
|
+
*/
|
|
16950
|
+
class ChatUtils {
|
|
16951
|
+
constructor() {
|
|
16952
|
+
/** @private @type {Map<SessionId, ChatInstance>} Map of active chat instances */
|
|
16953
|
+
this._chats = new Map();
|
|
16954
|
+
/**
|
|
16955
|
+
* Initializes cleanup interval for inactive chats
|
|
16956
|
+
* @private
|
|
16957
|
+
* @returns {void}
|
|
16958
|
+
*/
|
|
16959
|
+
this.initializeCleanup = singleshot(() => {
|
|
16960
|
+
const handleCleanup = async () => {
|
|
16961
|
+
const now = Date.now();
|
|
16962
|
+
for (const chat of this._chats.values()) {
|
|
16963
|
+
if (now - chat.lastActivity >= INACTIVITY_TIMEOUT) {
|
|
16964
|
+
await chat.dispose();
|
|
16965
|
+
}
|
|
16966
|
+
}
|
|
16967
|
+
};
|
|
16968
|
+
setInterval(handleCleanup, INACTIVITY_CHECK);
|
|
16969
|
+
});
|
|
16970
|
+
/**
|
|
16971
|
+
* Gets or creates a chat instance for a client
|
|
16972
|
+
* @private
|
|
16973
|
+
* @param {SessionId} clientId - The client identifier
|
|
16974
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16975
|
+
* @returns {ChatInstance} Chat instance for the client
|
|
16976
|
+
*/
|
|
16977
|
+
this.getChatInstance = (clientId, swarmName) => {
|
|
16978
|
+
return this._chats.has(clientId)
|
|
16979
|
+
? this._chats.get(clientId)
|
|
16980
|
+
: this._chats
|
|
16981
|
+
.set(clientId, new ChatInstance(clientId, swarmName, () => {
|
|
16982
|
+
this._chats.delete(clientId);
|
|
16983
|
+
}))
|
|
16984
|
+
.get(clientId);
|
|
16985
|
+
};
|
|
16986
|
+
/**
|
|
16987
|
+
* Sends a message for a specific client
|
|
16988
|
+
* @public
|
|
16989
|
+
* @async
|
|
16990
|
+
* @param {SessionId} clientId - The client identifier
|
|
16991
|
+
* @param {string} message - Message content to send
|
|
16992
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
16993
|
+
* @returns {Promise<any>} Result of the message sending
|
|
16994
|
+
*/
|
|
16995
|
+
this.sendMessage = async (clientId, message, swarmName) => {
|
|
16996
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16997
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_SEND_MESSAGE, {
|
|
16998
|
+
clientId,
|
|
16999
|
+
message,
|
|
17000
|
+
swarmName,
|
|
17001
|
+
});
|
|
17002
|
+
this.initializeCleanup();
|
|
17003
|
+
return await this.getChatInstance(clientId, swarmName).sendMessage(message);
|
|
17004
|
+
};
|
|
17005
|
+
/**
|
|
17006
|
+
* Subscribes to disposal events for a specific client
|
|
17007
|
+
* @public
|
|
17008
|
+
* @param {SessionId} clientId - The client identifier
|
|
17009
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
17010
|
+
* @param {(clientId: SessionId) => void} fn - Callback function for disposal events
|
|
17011
|
+
* @returns {any} Subscription object
|
|
17012
|
+
*/
|
|
17013
|
+
this.listenDispose = (clientId, swarmName, fn) => {
|
|
17014
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17015
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_LISTEN_DISPOSE, {
|
|
17016
|
+
clientId,
|
|
17017
|
+
swarmName,
|
|
17018
|
+
});
|
|
17019
|
+
return this.getChatInstance(clientId, swarmName).listenDispose(fn);
|
|
17020
|
+
};
|
|
17021
|
+
/**
|
|
17022
|
+
* Disposes of a specific chat instance for a client
|
|
17023
|
+
* @public
|
|
17024
|
+
* @async
|
|
17025
|
+
* @param {SessionId} clientId - The client identifier for the chat instance to dispose
|
|
17026
|
+
* @param {SwarmName} swarmName - The swarm name associated with the chat instance
|
|
17027
|
+
* @returns {Promise<void>} A promise that resolves when the chat instance has been disposed
|
|
17028
|
+
*/
|
|
17029
|
+
this.dispose = async (clientId, swarmName) => {
|
|
17030
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17031
|
+
swarm$1.loggerService.log(CHAT_UTILS_METHOD_NAME_DISPOSE, {
|
|
17032
|
+
clientId,
|
|
17033
|
+
swarmName,
|
|
17034
|
+
});
|
|
17035
|
+
if (!this._chats.has(clientId)) {
|
|
17036
|
+
return;
|
|
17037
|
+
}
|
|
17038
|
+
return await this.getChatInstance(clientId, swarmName).dispose();
|
|
17039
|
+
};
|
|
17040
|
+
}
|
|
17041
|
+
}
|
|
17042
|
+
/** @constant {ChatUtils} Singleton instance of ChatUtils */
|
|
17043
|
+
const Chat = new ChatUtils();
|
|
17044
|
+
|
|
16850
17045
|
/** @private Constant for logging the take method in StorageUtils */
|
|
16851
17046
|
const METHOD_NAME_TAKE$1 = "StorageUtils.take";
|
|
16852
17047
|
/** @private Constant for logging the upsert method in StorageUtils */
|
|
@@ -17630,4 +17825,4 @@ const Utils = {
|
|
|
17630
17825
|
PersistEmbeddingUtils,
|
|
17631
17826
|
};
|
|
17632
17827
|
|
|
17633
|
-
export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, RoundRobin, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
17828
|
+
export { Adapter, Chat, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, RoundRobin, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -10469,6 +10469,59 @@ declare class SharedStateUtils implements TSharedState {
|
|
|
10469
10469
|
*/
|
|
10470
10470
|
declare const SharedState: SharedStateUtils;
|
|
10471
10471
|
|
|
10472
|
+
/**
|
|
10473
|
+
* Utility class for managing multiple chat instances
|
|
10474
|
+
* @class
|
|
10475
|
+
*/
|
|
10476
|
+
declare class ChatUtils {
|
|
10477
|
+
/** @private @type {Map<SessionId, ChatInstance>} Map of active chat instances */
|
|
10478
|
+
private _chats;
|
|
10479
|
+
/**
|
|
10480
|
+
* Initializes cleanup interval for inactive chats
|
|
10481
|
+
* @private
|
|
10482
|
+
* @returns {void}
|
|
10483
|
+
*/
|
|
10484
|
+
private initializeCleanup;
|
|
10485
|
+
/**
|
|
10486
|
+
* Gets or creates a chat instance for a client
|
|
10487
|
+
* @private
|
|
10488
|
+
* @param {SessionId} clientId - The client identifier
|
|
10489
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
10490
|
+
* @returns {ChatInstance} Chat instance for the client
|
|
10491
|
+
*/
|
|
10492
|
+
private getChatInstance;
|
|
10493
|
+
/**
|
|
10494
|
+
* Sends a message for a specific client
|
|
10495
|
+
* @public
|
|
10496
|
+
* @async
|
|
10497
|
+
* @param {SessionId} clientId - The client identifier
|
|
10498
|
+
* @param {string} message - Message content to send
|
|
10499
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
10500
|
+
* @returns {Promise<any>} Result of the message sending
|
|
10501
|
+
*/
|
|
10502
|
+
sendMessage: (clientId: SessionId, message: string, swarmName: SwarmName) => Promise<string>;
|
|
10503
|
+
/**
|
|
10504
|
+
* Subscribes to disposal events for a specific client
|
|
10505
|
+
* @public
|
|
10506
|
+
* @param {SessionId} clientId - The client identifier
|
|
10507
|
+
* @param {SwarmName} swarmName - The swarm name
|
|
10508
|
+
* @param {(clientId: SessionId) => void} fn - Callback function for disposal events
|
|
10509
|
+
* @returns {any} Subscription object
|
|
10510
|
+
*/
|
|
10511
|
+
listenDispose: (clientId: SessionId, swarmName: SwarmName, fn: (clientId: SessionId) => void) => () => void;
|
|
10512
|
+
/**
|
|
10513
|
+
* Disposes of a specific chat instance for a client
|
|
10514
|
+
* @public
|
|
10515
|
+
* @async
|
|
10516
|
+
* @param {SessionId} clientId - The client identifier for the chat instance to dispose
|
|
10517
|
+
* @param {SwarmName} swarmName - The swarm name associated with the chat instance
|
|
10518
|
+
* @returns {Promise<void>} A promise that resolves when the chat instance has been disposed
|
|
10519
|
+
*/
|
|
10520
|
+
dispose: (clientId: SessionId, swarmName: SwarmName) => Promise<void>;
|
|
10521
|
+
}
|
|
10522
|
+
/** @constant {ChatUtils} Singleton instance of ChatUtils */
|
|
10523
|
+
declare const Chat: ChatUtils;
|
|
10524
|
+
|
|
10472
10525
|
/**
|
|
10473
10526
|
* Type definition for a storage object, mapping IStorage keys to unknown values.
|
|
10474
10527
|
* @typedef {{ [key in keyof IStorage]: unknown }} TStorage
|
|
@@ -10837,4 +10890,4 @@ declare const Utils: {
|
|
|
10837
10890
|
PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
|
|
10838
10891
|
};
|
|
10839
10892
|
|
|
10840
|
-
export { Adapter, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
10893
|
+
export { Adapter, Chat, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|