change clear to sync
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
# myapp/sockets/namespaces.py
|
||||
import json
|
||||
import time
|
||||
from flask import current_app, request, session
|
||||
import requests
|
||||
from flask import current_app, request, session, url_for
|
||||
from flask_socketio import Namespace, join_room, leave_room, emit
|
||||
from ..config import Config
|
||||
|
||||
from ..function_tools import judge
|
||||
from ..function_tools import next_chapter
|
||||
@@ -209,9 +211,33 @@ class AgentNamespace(Namespace):
|
||||
print(f"on_connect_to_ase {client_entry}, {namespace_entry}, {init_data}")
|
||||
namespace_entry, ase_client = namespace_entry
|
||||
namespace_entry.emit('open-iframe',"", room=init_data['room'], namespace='/agent')
|
||||
|
||||
# 将异步emit改为同步requests.post请求
|
||||
try:
|
||||
# 构建请求URL,使用配置中的ASE_ENGINE_URL
|
||||
base_url = current_app.config['ASE_ENGINE_URL']
|
||||
clear_url = f"{base_url}/clear_user_session"
|
||||
|
||||
# 准备请求参数
|
||||
payload = {
|
||||
'namespace_url': current_app.config['ASE_ENGINE_URL_TOKEN'], # WebSocket命名空间URL
|
||||
'user_id': init_data['room'], # 用户ID,对应session_info.id
|
||||
'clear_type': 'all' # 清理类型,默认为全部
|
||||
}
|
||||
|
||||
# 添加token认证头
|
||||
headers = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# 发送同步POST请求
|
||||
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", "")
|
||||
ase_client.send_text("clear","")
|
||||
namespace_entry.emit('message', "Multi-Agents服务已连接", room=init_data['room'], namespace='/agent')
|
||||
|
||||
#接受消息回来直接让message监听发送
|
||||
|
||||
Reference in New Issue
Block a user