修改了 AgentNamespace 类,将全局实例变量替换为字典,使用用户 UUID 作为键
This commit is contained in:
@@ -63,6 +63,11 @@ class VSCodeNamespace(Namespace):
|
|||||||
|
|
||||||
|
|
||||||
class AgentNamespace(Namespace):
|
class AgentNamespace(Namespace):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
# 使用字典存储每个用户的chatmanager和ase_client,避免多用户冲突
|
||||||
|
self.user_chatmanagers = {}
|
||||||
|
self.user_ase_clients = {}
|
||||||
|
|
||||||
def _load_learning_progress(self, chatmanager, user_id, course_id, chapter_name, lesson_name, continue_learn):
|
def _load_learning_progress(self, chatmanager, user_id, course_id, chapter_name, lesson_name, continue_learn):
|
||||||
"""加载并恢复用户学习进度
|
"""加载并恢复用户学习进度
|
||||||
@@ -153,8 +158,9 @@ class AgentNamespace(Namespace):
|
|||||||
if chatmanager.chat_historys:
|
if chatmanager.chat_historys:
|
||||||
emit('messages', chatmanager.chat_historys, room=user_uuid, namespace='/agent')
|
emit('messages', chatmanager.chat_historys, room=user_uuid, namespace='/agent')
|
||||||
|
|
||||||
self.chatmanager = chatmanager
|
# 存储每个用户的chatmanager和ase_client到字典中,使用用户UUID作为键
|
||||||
self.ase_client = user_uuid2ase_client[user_uuid]
|
self.user_chatmanagers[user_uuid] = chatmanager
|
||||||
|
self.user_ase_clients[user_uuid] = user_uuid2ase_client[user_uuid]
|
||||||
|
|
||||||
# 将restart设置为False,避免后续重复处理
|
# 将restart设置为False,避免后续重复处理
|
||||||
restart = chatmanager.restart
|
restart = chatmanager.restart
|
||||||
|
|||||||
@@ -75,9 +75,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
folder: user_data.folder
|
folder: user_data.folder
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('Connecting to WebSocket server at wss://${host}/agent');
|
|
||||||
console.log(user_data);
|
|
||||||
|
|
||||||
// 初始化聊天消息管理器
|
// 初始化聊天消息管理器
|
||||||
chatManager = new ChatMessageManager();
|
chatManager = new ChatMessageManager();
|
||||||
socket.on('connect', function () {
|
socket.on('connect', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user