reduce onlogin
This commit is contained in:
@@ -62,376 +62,181 @@ class VSCodeNamespace(Namespace):
|
|||||||
|
|
||||||
|
|
||||||
class AgentNamespace(Namespace):
|
class AgentNamespace(Namespace):
|
||||||
def _setup_initial_state(self, data):
|
def _parse_login_data(self, data):
|
||||||
"""Set up initial state, parse data, and join user to room."""
|
"""解析登录数据"""
|
||||||
self.app = current_app
|
|
||||||
ex = current_app.extensions
|
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
|
return {
|
||||||
|
'user_uuid': data['user_uuid'],
|
||||||
|
'course_id': data['course_id'],
|
||||||
|
'lesson_name': data['lesson_name'],
|
||||||
|
'chapter_name': data['chapter_name']
|
||||||
|
}
|
||||||
|
|
||||||
# Extract required fields
|
def _setup_user_session(self, user_uuid, uuid2username):
|
||||||
user_uuid = data['user_uuid']
|
"""设置用户会话和加入房间"""
|
||||||
course_id = data['course_id']
|
|
||||||
lesson_name = data['lesson_name']
|
|
||||||
chapter_name = data['chapter_name']
|
|
||||||
|
|
||||||
# Get user_id and set session
|
|
||||||
uuid2username = ex["uuid2username"]
|
|
||||||
user_id = uuid2username[user_uuid]
|
user_id = uuid2username[user_uuid]
|
||||||
session['user_uuid'] = user_uuid
|
session['user_uuid'] = user_uuid
|
||||||
|
join_room(user_uuid, namespace='/agent') # 将该用户加入以user_id为名的room
|
||||||
# Join user to room
|
|
||||||
join_room(user_uuid, namespace='/agent')
|
|
||||||
print(f'User connected with session user_uuid: {user_uuid}')
|
print(f'User connected with session user_uuid: {user_uuid}')
|
||||||
|
return user_id
|
||||||
|
|
||||||
return {
|
def _manage_ase_client_connection(self, user_uuid, ex):
|
||||||
'ex': ex,
|
"""管理ASE客户端连接"""
|
||||||
'user_uuid': user_uuid,
|
|
||||||
'user_id': user_id,
|
|
||||||
'course_id': course_id,
|
|
||||||
'lesson_name': lesson_name,
|
|
||||||
'chapter_name': chapter_name
|
|
||||||
}
|
|
||||||
|
|
||||||
def _manage_ase_client(self, ex, user_uuid):
|
|
||||||
"""Manage ASE client: disconnect existing if connected and return chatmanager."""
|
|
||||||
user_uuid2chatmanager = ex["user_uuid2chatmanager"]
|
|
||||||
user_uuid2ase_client = ex["user_uuid2ase_client"]
|
user_uuid2ase_client = ex["user_uuid2ase_client"]
|
||||||
|
if (user_uuid2ase_client.get(user_uuid, None) is not None and user_uuid2ase_client[user_uuid].connected):
|
||||||
# Disconnect existing ASE client if connected
|
|
||||||
if user_uuid2ase_client.get(user_uuid) is not None and user_uuid2ase_client[user_uuid].connected:
|
|
||||||
user_uuid2ase_client[user_uuid].disconnect()
|
user_uuid2ase_client[user_uuid].disconnect()
|
||||||
|
return user_uuid2ase_client
|
||||||
|
|
||||||
# Get chatmanager
|
def _configure_chatmanager_functions(self, chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid):
|
||||||
chatmanager = user_uuid2chatmanager[user_uuid]
|
"""配置聊天管理器的函数"""
|
||||||
|
chatmanager.function_manager.add_function(judge, {'course_id': course_id, 'root_path': f'/home/{user_id}/{course_id}/{chapter_name}/{lesson_name}'})
|
||||||
return {
|
chatmanager.function_manager.add_function(next_chapter, {'user_uuid': user_uuid})
|
||||||
'chatmanager': chatmanager,
|
|
||||||
'user_uuid2ase_client': user_uuid2ase_client
|
|
||||||
}
|
|
||||||
|
|
||||||
def on_login(self, data):
|
|
||||||
initial_state = self._setup_initial_state(data)
|
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
def _register_chatmanager_functions(self, chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid):
|
|
||||||
"""Register required functions to chatmanager's function manager."""
|
|
||||||
# Add judge function
|
|
||||||
chatmanager.function_manager.add_function(
|
|
||||||
judge,
|
|
||||||
{'course_id': course_id, 'root_path': f'/home/{user_id}/{course_id}/{chapter_name}/{lesson_name}'}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add next_chapter function
|
|
||||||
chatmanager.function_manager.add_function(
|
|
||||||
next_chapter,
|
|
||||||
{'user_uuid': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
return not chatmanager.restart
|
|
||||||
|
|
||||||
def on_login(self, data):
|
|
||||||
initial_state = self._setup_initial_state(data)
|
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
ase_management = self._manage_ase_client(ex, user_uuid)
|
|
||||||
chatmanager = ase_management['chatmanager']
|
|
||||||
user_uuid2ase_client = ase_management['user_uuid2ase_client']
|
|
||||||
|
|
||||||
def _load_and_restore_progress(self, chatmanager, user_id, course_id, chapter_name, lesson_name):
|
def _load_and_restore_progress(self, chatmanager, user_id, course_id, chapter_name, lesson_name):
|
||||||
"""Load and restore user learning progress if available."""
|
"""加载和恢复学习进度"""
|
||||||
|
continue_learn = not chatmanager.restart
|
||||||
need_skip_chapters = 0
|
need_skip_chapters = 0
|
||||||
|
|
||||||
# Load learning progress
|
if continue_learn: # 尝试加载用户学习进度
|
||||||
progress_result = load_learning_progress(user_id, course_id, chapter_name, lesson_name)
|
progress_result = load_learning_progress(user_id, course_id, chapter_name, lesson_name)
|
||||||
|
|
||||||
if progress_result['exists']:
|
if progress_result['exists']:
|
||||||
progress = progress_result['data']
|
progress = progress_result['data']
|
||||||
|
# 恢复学习进度数据
|
||||||
|
if 'scores' in progress:
|
||||||
|
# 根据scores的数量确定需要跳过的章节数
|
||||||
|
need_skip_chapters = len(progress['scores'])
|
||||||
|
chatmanager.scores = progress['scores']
|
||||||
|
|
||||||
# Restore scores and calculate chapters to skip
|
# 恢复聊天历史
|
||||||
if 'scores' in progress:
|
if 'chat_historys' in progress:
|
||||||
need_skip_chapters = len(progress['scores'])
|
chatmanager.chat_historys = progress['chat_historys']
|
||||||
chatmanager.scores = progress['scores']
|
else:
|
||||||
|
chatmanager.chat_historys = []
|
||||||
|
|
||||||
# Restore chat history
|
# 恢复当前章节链
|
||||||
chatmanager.chat_historys = progress.get('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 = progress_result['data']['chat_historys']
|
||||||
|
chatmanager.scores = progress_result['data']['scores']
|
||||||
|
|
||||||
# Restore chapter chain
|
return continue_learn, need_skip_chapters
|
||||||
if 'chapter_chain_now' in progress:
|
|
||||||
chatmanager.chapter_chain_now = progress['chapter_chain_now']
|
|
||||||
|
|
||||||
# Upload progress to cloud
|
def _initialize_chatmanager(self, user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client):
|
||||||
upload_learning_progress_to_cloud(progress)
|
"""初始化聊天管理器"""
|
||||||
else:
|
|
||||||
# Use default values from progress_result
|
|
||||||
chatmanager.chat_historys = progress_result['data']['chat_historys']
|
|
||||||
chatmanager.scores = progress_result['data']['scores']
|
|
||||||
|
|
||||||
return need_skip_chapters
|
|
||||||
|
|
||||||
def on_login(self, data):
|
|
||||||
initial_state = self._setup_initial_state(data)
|
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
ase_management = self._manage_ase_client(ex, user_uuid)
|
|
||||||
chatmanager = ase_management['chatmanager']
|
|
||||||
user_uuid2ase_client = ase_management['user_uuid2ase_client']
|
|
||||||
|
|
||||||
continue_learn = self._register_chatmanager_functions(
|
|
||||||
chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid
|
|
||||||
)
|
|
||||||
|
|
||||||
need_skip_chapters = 0
|
|
||||||
if continue_learn:
|
|
||||||
need_skip_chapters = self._load_and_restore_progress(
|
|
||||||
chatmanager, user_id, course_id, chapter_name, lesson_name
|
|
||||||
)
|
|
||||||
|
|
||||||
def _initialize_ase_client_and_chatmanager(self, user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client):
|
|
||||||
"""Initialize ASE client and chatmanager with required parameters."""
|
|
||||||
# Load full markdown file
|
|
||||||
fmd, fmdp, fsp = load_full_markdown_file(course_id, chapter_name, lesson_name)
|
fmd, fmdp, fsp = load_full_markdown_file(course_id, chapter_name, lesson_name)
|
||||||
|
user_uuid2ase_client[user_uuid] = HSAEngineClient(
|
||||||
# Create and initialize ASE client
|
|
||||||
ase_client = HSAEngineClient(
|
|
||||||
current_app.config["ASE_ENGINE_URL"],
|
current_app.config["ASE_ENGINE_URL"],
|
||||||
current_app.config["ASE_ENGINE_NAMESPACE"],
|
current_app.config["ASE_ENGINE_NAMESPACE"],
|
||||||
id=user_id,
|
id=user_id,
|
||||||
chatmanager=chatmanager
|
chatmanager=chatmanager
|
||||||
)
|
)
|
||||||
user_uuid2ase_client[user_uuid] = ase_client
|
|
||||||
|
|
||||||
# Initialize chatmanager
|
|
||||||
chatmanager.init(
|
chatmanager.init(
|
||||||
user_uuid,
|
user_uuid,
|
||||||
ase_client,
|
user_uuid2ase_client[user_uuid],
|
||||||
fmd,
|
fmd, fmdp, fsp,
|
||||||
fmdp,
|
course_id, chapter_name, lesson_name,
|
||||||
fsp,
|
|
||||||
course_id,
|
|
||||||
chapter_name,
|
|
||||||
lesson_name,
|
|
||||||
max_iter=5,
|
max_iter=5,
|
||||||
app=current_app,
|
app=current_app,
|
||||||
socketio=self
|
socketio=self
|
||||||
)
|
)
|
||||||
|
return user_uuid2ase_client
|
||||||
|
|
||||||
return ase_client
|
def _setup_backboard(self, user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, backboard_manager):
|
||||||
|
"""设置背板管理器"""
|
||||||
def _setup_backboard(self, backboard_manager, user_uuid, user_id, course_id, lesson_name, chapter_name, chatmanager):
|
backboard_manager.add_backboard(
|
||||||
"""Set up backboard for the user and associate with chatmanager."""
|
user_uuid,
|
||||||
# Add backboard
|
user_id,
|
||||||
root_path = f'/home/{user_id}/{course_id}/{chapter_name}/{lesson_name}'
|
course_id,
|
||||||
backboard_manager.add_backboard(user_uuid, user_id, course_id, lesson_name, root_path=root_path)
|
lesson_name,
|
||||||
|
root_path=f'/home/{user_id}/{course_id}/{chapter_name}/{lesson_name}'
|
||||||
# Associate backboard with chatmanager
|
)
|
||||||
chatmanager.bb = backboard_manager.get_backboard(user_uuid)
|
chatmanager.bb = backboard_manager.get_backboard(user_uuid)
|
||||||
|
|
||||||
def on_login(self, data):
|
def _skip_completed_chapters(self, chatmanager, continue_learn, need_skip_chapters):
|
||||||
initial_state = self._setup_initial_state(data)
|
"""跳过已完成章节"""
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
ase_management = self._manage_ase_client(ex, user_uuid)
|
|
||||||
chatmanager = ase_management['chatmanager']
|
|
||||||
user_uuid2ase_client = ase_management['user_uuid2ase_client']
|
|
||||||
|
|
||||||
continue_learn = self._register_chatmanager_functions(
|
|
||||||
chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid
|
|
||||||
)
|
|
||||||
|
|
||||||
need_skip_chapters = 0
|
|
||||||
if continue_learn:
|
if continue_learn:
|
||||||
need_skip_chapters = self._load_and_restore_progress(
|
for _ in range(need_skip_chapters):
|
||||||
chatmanager, user_id, course_id, chapter_name, lesson_name
|
chatmanager.next_chapter()
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize ASE client and chatmanager
|
def _register_ase_routes(self, user_uuid, user_uuid2ase_client, chatmanager):
|
||||||
ase_client = self._initialize_ase_client_and_chatmanager(
|
"""注册ASE客户端的各种路由回调"""
|
||||||
user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client
|
user_uuid2ase_client[user_uuid].register_on_connect_entry(
|
||||||
)
|
|
||||||
|
|
||||||
def _skip_completed_chapters(self, chatmanager, need_skip_chapters):
|
|
||||||
"""Skip chapters that have already been completed based on learning progress."""
|
|
||||||
for _ in range(need_skip_chapters):
|
|
||||||
chatmanager.next_chapter()
|
|
||||||
|
|
||||||
def on_login(self, data):
|
|
||||||
initial_state = self._setup_initial_state(data)
|
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
ase_management = self._manage_ase_client(ex, user_uuid)
|
|
||||||
chatmanager = ase_management['chatmanager']
|
|
||||||
user_uuid2ase_client = ase_management['user_uuid2ase_client']
|
|
||||||
|
|
||||||
continue_learn = self._register_chatmanager_functions(
|
|
||||||
chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid
|
|
||||||
)
|
|
||||||
|
|
||||||
need_skip_chapters = 0
|
|
||||||
if continue_learn:
|
|
||||||
need_skip_chapters = self._load_and_restore_progress(
|
|
||||||
chatmanager, user_id, course_id, chapter_name, lesson_name
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize ASE client and chatmanager
|
|
||||||
ase_client = self._initialize_ase_client_and_chatmanager(
|
|
||||||
user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set up backboard
|
|
||||||
self._setup_backboard(backboard_manager, user_uuid, user_id, course_id, lesson_name, chapter_name, chatmanager)
|
|
||||||
|
|
||||||
# Skip completed chapters if continuing learning
|
|
||||||
if continue_learn:
|
|
||||||
self._skip_completed_chapters(chatmanager, need_skip_chapters)
|
|
||||||
|
|
||||||
def _register_ase_routes(self, ase_client, user_uuid, chatmanager):
|
|
||||||
"""Register all required routes with ASE client."""
|
|
||||||
# Register on_connect entry
|
|
||||||
ase_client.register_on_connect_entry(
|
|
||||||
callback=on_connect_to_ase,
|
callback=on_connect_to_ase,
|
||||||
entry=(self, ase_client),
|
entry=(self, user_uuid2ase_client[user_uuid]),
|
||||||
init_data={'room': user_uuid, 'restart': chatmanager.restart}
|
init_data={'room': user_uuid, 'restart': chatmanager.restart}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register dialog route
|
# 注册各种路由回调
|
||||||
ase_client.register_route_with_entry(
|
route_configs = [
|
||||||
route='dialog',
|
{'route': 'dialog', 'callback': receive_ase_dialog, 'entry': self},
|
||||||
callback=receive_ase_dialog,
|
{'route': 'dialog-hint', 'callback': receive_ase_message_hint, 'entry': self},
|
||||||
entry=self,
|
{'route': 'voice_out', 'callback': receive_ase_voice_out, 'entry': self},
|
||||||
init_data={'room': user_uuid}
|
{'route': 'judge', 'callback': receive_ase_judge, 'entry': self},
|
||||||
)
|
{'route': 'next_chapter', 'callback': receive_ase_next_chapter, 'entry': self},
|
||||||
|
{'route': 'chapter_score', 'callback': receive_ase_chapter_score, 'entry': (get_or_load_current_user(), chatmanager)},
|
||||||
|
{'route': 'process', 'callback': receive_ase_process, 'entry': self},
|
||||||
|
{'route': 'paste_detected', 'callback': receive_ase_paste_detected, 'entry': self}
|
||||||
|
]
|
||||||
|
|
||||||
# Register dialog-hint route
|
for config in route_configs:
|
||||||
ase_client.register_route_with_entry(
|
user_uuid2ase_client[user_uuid].register_route_with_entry(
|
||||||
route='dialog-hint',
|
route=config['route'],
|
||||||
callback=receive_ase_message_hint,
|
callback=config['callback'],
|
||||||
entry=self,
|
entry=config['entry'],
|
||||||
init_data={'room': user_uuid}
|
init_data={'room': user_uuid}
|
||||||
)
|
|
||||||
|
|
||||||
# Register voice_out route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='voice_out',
|
|
||||||
callback=receive_ase_voice_out,
|
|
||||||
entry=self,
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register judge route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='judge',
|
|
||||||
callback=receive_ase_judge,
|
|
||||||
entry=self,
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register next_chapter route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='next_chapter',
|
|
||||||
callback=receive_ase_next_chapter,
|
|
||||||
entry=self,
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register chapter_score route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='chapter_score',
|
|
||||||
callback=receive_ase_chapter_score,
|
|
||||||
entry=(get_or_load_current_user(), chatmanager),
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register process route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='process',
|
|
||||||
callback=receive_ase_process,
|
|
||||||
entry=self,
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register paste_detected route
|
|
||||||
ase_client.register_route_with_entry(
|
|
||||||
route='paste_detected',
|
|
||||||
callback=receive_ase_paste_detected,
|
|
||||||
entry=self,
|
|
||||||
init_data={'room': user_uuid}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Connect the ASE client
|
|
||||||
ase_client.connect()
|
|
||||||
|
|
||||||
def on_login(self, data):
|
|
||||||
initial_state = self._setup_initial_state(data)
|
|
||||||
ex = initial_state['ex']
|
|
||||||
user_uuid = initial_state['user_uuid']
|
|
||||||
user_id = initial_state['user_id']
|
|
||||||
course_id = initial_state['course_id']
|
|
||||||
lesson_name = initial_state['lesson_name']
|
|
||||||
chapter_name = initial_state['chapter_name']
|
|
||||||
backboard_manager = ex["backboard_manager"]
|
|
||||||
|
|
||||||
ase_management = self._manage_ase_client(ex, user_uuid)
|
|
||||||
chatmanager = ase_management['chatmanager']
|
|
||||||
user_uuid2ase_client = ase_management['user_uuid2ase_client']
|
|
||||||
|
|
||||||
continue_learn = self._register_chatmanager_functions(
|
|
||||||
chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid
|
|
||||||
)
|
|
||||||
|
|
||||||
need_skip_chapters = 0
|
|
||||||
if continue_learn:
|
|
||||||
need_skip_chapters = self._load_and_restore_progress(
|
|
||||||
chatmanager, user_id, course_id, chapter_name, lesson_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize ASE client and chatmanager
|
user_uuid2ase_client[user_uuid].connect()
|
||||||
ase_client = self._initialize_ase_client_and_chatmanager(
|
|
||||||
user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set up backboard
|
def on_login(self, data):
|
||||||
self._setup_backboard(backboard_manager, user_uuid, user_id, course_id, lesson_name, chapter_name, chatmanager)
|
"""登录处理主方法"""
|
||||||
|
self.app = current_app
|
||||||
|
ex = current_app.extensions
|
||||||
|
uuid2username = ex["uuid2username"]
|
||||||
|
backboard_manager = ex["backboard_manager"]
|
||||||
|
|
||||||
# Skip completed chapters if continuing learning
|
# 1. 解析登录数据
|
||||||
if continue_learn:
|
login_data = self._parse_login_data(data)
|
||||||
self._skip_completed_chapters(chatmanager, need_skip_chapters)
|
user_uuid = login_data['user_uuid']
|
||||||
|
course_id = login_data['course_id']
|
||||||
|
lesson_name = login_data['lesson_name']
|
||||||
|
chapter_name = login_data['chapter_name']
|
||||||
|
|
||||||
# Set instance variables
|
# 2. 设置用户会话和加入房间
|
||||||
|
user_id = self._setup_user_session(user_uuid, uuid2username)
|
||||||
|
|
||||||
|
# 3. 获取聊天管理器
|
||||||
|
user_uuid2chatmanager = ex["user_uuid2chatmanager"]
|
||||||
|
chatmanager = user_uuid2chatmanager[user_uuid]
|
||||||
|
|
||||||
|
# 4. 管理ASE客户端连接
|
||||||
|
user_uuid2ase_client = self._manage_ase_client_connection(user_uuid, ex)
|
||||||
|
|
||||||
|
# 5. 配置聊天管理器的函数
|
||||||
|
self._configure_chatmanager_functions(chatmanager, course_id, user_id, chapter_name, lesson_name, user_uuid)
|
||||||
|
|
||||||
|
# 6. 加载和恢复学习进度
|
||||||
|
continue_learn, need_skip_chapters = self._load_and_restore_progress(chatmanager, user_id, course_id, chapter_name, lesson_name)
|
||||||
|
|
||||||
|
# 7. 初始化聊天管理器
|
||||||
|
user_uuid2ase_client = self._initialize_chatmanager(user_uuid, user_id, course_id, chapter_name, lesson_name, chatmanager, user_uuid2ase_client)
|
||||||
|
|
||||||
|
# 8. 设置背板管理器
|
||||||
|
self._setup_backboard(user_uuid, user_id, course_id, lesson_name, chatmanager, backboard_manager)
|
||||||
|
|
||||||
|
# 9. 跳过已完成章节
|
||||||
|
self._skip_completed_chapters(chatmanager, continue_learn, need_skip_chapters)
|
||||||
|
|
||||||
|
# 10. 保存引用
|
||||||
self.chatmanager = chatmanager
|
self.chatmanager = chatmanager
|
||||||
self.ase_client = ase_client
|
self.ase_client = user_uuid2ase_client[user_uuid]
|
||||||
|
|
||||||
# Register all ASE routes and connect
|
# 11. 注册ASE路由
|
||||||
self._register_ase_routes(ase_client, user_uuid, chatmanager)
|
self._register_ase_routes(user_uuid, user_uuid2ase_client, chatmanager)
|
||||||
|
|
||||||
|
|
||||||
def on_language(self, language):
|
def on_language(self, language):
|
||||||
|
|||||||
Reference in New Issue
Block a user