diff --git a/Html/apps/extension_ase/ase_client/manager.py b/Html/apps/extension_ase/ase_client/manager.py index 2b3b527..766cd62 100644 --- a/Html/apps/extension_ase/ase_client/manager.py +++ b/Html/apps/extension_ase/ase_client/manager.py @@ -33,7 +33,8 @@ class ProcRecord: class ChatManager: _procs: Dict[str, ProcRecord] = {} _lock = threading.RLock() - def __init__(self): + def __init__(self, restart=False): + self.restart = restart self.chapter_chain_now = -1 self.ase_client = None self.app = None diff --git a/Html/apps/services/asectrl_service.py b/Html/apps/services/asectrl_service.py index bfacae1..ffc034c 100644 --- a/Html/apps/services/asectrl_service.py +++ b/Html/apps/services/asectrl_service.py @@ -11,22 +11,23 @@ def on_connect_to_ase(client_entry, namespace_entry, init_data): namespace_entry.emit('open-iframe',"", room=init_data['room'], namespace='/agent') namespace_entry.emit('message', "Agents服务已连接, 加载教案中", room=init_data['room'], namespace='/agent') - try: - base_url = namespace_entry.app.config['ASE_ENGINE_URL'] - clear_url = f"{base_url}/clear_user_session" - payload = { - 'namespace_url': namespace_entry.app.config['ASE_ENGINE_URL_TOKEN'], # WebSocket命名空间URL - 'user_id': init_data['room'], # 用户ID,对应session_info.id - 'clear_type': 'all' # 清理类型,默认为全部 - } - headers = { - 'Content-Type': 'application/json' - } - response = requests.post(clear_url, json=payload, headers=headers) - response.raise_for_status() # 检查请求是否成功 - print(f"Clear user session successful: {response.json()}") - except Exception as e: - print(f"Error clearing user session: {e}") + if init_data.get("restart", False): + try: + base_url = namespace_entry.app.config['ASE_ENGINE_URL'] + clear_url = f"{base_url}/clear_user_session" + payload = { + 'namespace_url': namespace_entry.app.config['ASE_ENGINE_URL_TOKEN'], # WebSocket命名空间URL + 'user_id': init_data['room'], # 用户ID,对应session_info.id + 'clear_type': 'all' # 清理类型,默认为全部 + } + headers = { + 'Content-Type': 'application/json' + } + response = requests.post(clear_url, json=payload, headers=headers) + response.raise_for_status() # 检查请求是否成功 + print(f"Clear user session successful: {response.json()}") + except Exception as e: + print(f"Error clearing user session: {e}") ase_client.chatmanager.load_next_chapter() ase_client.send_text("chapter-start", "") namespace_entry.emit('message', "教案加载完毕", room=init_data['room'], namespace='/agent') diff --git a/Html/apps/sockets/namespaces.py b/Html/apps/sockets/namespaces.py index 92a4d26..ffb7365 100644 --- a/Html/apps/sockets/namespaces.py +++ b/Html/apps/sockets/namespaces.py @@ -85,31 +85,31 @@ class AgentNamespace(Namespace): chatmanager.function_manager.add_function(judge, {'course_id': course_id, 'root_path': f'/home/{user_id}/{course_id}/{chapter_name}/{lesson_name}'}) chatmanager.function_manager.add_function(next_chapter, {'user_uuid': user_uuid}) - # 尝试加载用户学习进度 - progress = load_learning_progress(user_uuid, course_id, chapter_name, lesson_name) - need_skip_chapters = 0 - - if progress: - # 恢复学习进度数据 - if 'scores' in progress: - # 根据scores的数量确定需要跳过的章节数 - need_skip_chapters = len(progress['scores']) - chatmanager.scores = progress['scores'] - print(f"恢复用户学习进度: {user_uuid}, 已完成 {need_skip_chapters} 个章节") + if not chatmanager.restart:# 尝试加载用户学习进度 + progress = load_learning_progress(user_uuid, course_id, chapter_name, lesson_name) + need_skip_chapters = 0 - # 恢复聊天历史 - if 'chat_historys' in progress: - chatmanager.chat_historys = progress['chat_historys'] + if progress: + # 恢复学习进度数据 + if 'scores' in progress: + # 根据scores的数量确定需要跳过的章节数 + need_skip_chapters = len(progress['scores']) + chatmanager.scores = progress['scores'] + print(f"恢复用户学习进度: {user_uuid}, 已完成 {need_skip_chapters} 个章节") + + # 恢复聊天历史 + if 'chat_historys' in progress: + chatmanager.chat_historys = progress['chat_historys'] + else: + chatmanager.chat_historys = [] + + # 恢复当前章节链 + if 'chapter_chain_now' in progress: + chatmanager.chapter_chain_now = progress['chapter_chain_now'] + upload_learning_progress_to_cloud(progress) else: chatmanager.chat_historys = [] - - # 恢复当前章节链 - if 'chapter_chain_now' in progress: - chatmanager.chapter_chain_now = progress['chapter_chain_now'] - upload_learning_progress_to_cloud(progress) - else: - chatmanager.chat_historys = [] - chatmanager.scores = [] + chatmanager.scores = [] fmd,fmdp,fsp = load_full_markdown_file(course_id, chapter_name, lesson_name) user_uuid2ase_client[user_uuid] = HSAEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"],id=user_id, chatmanager = chatmanager) @@ -127,7 +127,7 @@ class AgentNamespace(Namespace): user_uuid2ase_client[user_uuid].register_on_connect_entry( callback=on_connect_to_ase, entry=(self, user_uuid2ase_client[user_uuid]), - init_data={'room':user_uuid} + init_data={'room':user_uuid, 'restart':chatmanager.restart} ) user_uuid2ase_client[user_uuid].register_route_with_entry( route='dialog', diff --git a/Html/apps/templates/code-like-desktop.html b/Html/apps/templates/code-like-desktop.html index ea90737..e1a9e87 100644 --- a/Html/apps/templates/code-like-desktop.html +++ b/Html/apps/templates/code-like-desktop.html @@ -85,6 +85,22 @@ folder:"{{workspace_path}}" } + diff --git a/Html/apps/templates/confirm_load_history.html b/Html/apps/templates/confirm_load_history.html new file mode 100644 index 0000000..6cc2b4e --- /dev/null +++ b/Html/apps/templates/confirm_load_history.html @@ -0,0 +1,76 @@ + + +
+ + +