From de1ba08d7e5739f7abd8246b97094076179ddab9 Mon Sep 17 00:00:00 2001 From: CakeCN Date: Fri, 9 Jan 2026 11:23:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20AgentNamespace=20?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=B0=86=E5=85=A8=E5=B1=80=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=AD=97=E5=85=B8?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=E7=94=A8=E6=88=B7=20UUID=20?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Html/apps/sockets/namespaces.py | 10 ++++++++-- Html/apps/static/js/chatbox.js | 3 --- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Html/apps/sockets/namespaces.py b/Html/apps/sockets/namespaces.py index 48dd91a..8f40c80 100644 --- a/Html/apps/sockets/namespaces.py +++ b/Html/apps/sockets/namespaces.py @@ -63,6 +63,11 @@ class VSCodeNamespace(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): """加载并恢复用户学习进度 @@ -153,8 +158,9 @@ class AgentNamespace(Namespace): if chatmanager.chat_historys: emit('messages', chatmanager.chat_historys, room=user_uuid, namespace='/agent') - self.chatmanager = chatmanager - self.ase_client = user_uuid2ase_client[user_uuid] + # 存储每个用户的chatmanager和ase_client到字典中,使用用户UUID作为键 + self.user_chatmanagers[user_uuid] = chatmanager + self.user_ase_clients[user_uuid] = user_uuid2ase_client[user_uuid] # 将restart设置为False,避免后续重复处理 restart = chatmanager.restart diff --git a/Html/apps/static/js/chatbox.js b/Html/apps/static/js/chatbox.js index 7027d82..c160d6c 100644 --- a/Html/apps/static/js/chatbox.js +++ b/Html/apps/static/js/chatbox.js @@ -75,9 +75,6 @@ document.addEventListener('DOMContentLoaded', function () { folder: user_data.folder } }); - console.log('Connecting to WebSocket server at wss://${host}/agent'); - console.log(user_data); - // 初始化聊天消息管理器 chatManager = new ChatMessageManager(); socket.on('connect', function () {