Compare commits
2 Commits
save_load_
...
backboard_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c48d79076 | ||
|
|
5e6e040753 |
@@ -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监听发送
|
||||
|
||||
@@ -43,13 +43,22 @@ class Backboard:
|
||||
f"- File tree: {self.file_tree}{endl}")
|
||||
# f"- Activated file content (current editing 10 lines): {endl}"
|
||||
def add_history(self, realtime_action):
|
||||
if(realtime_action['type']=='config'):return
|
||||
if len(self.history)!=0:
|
||||
if (self.history[-1]['type']=='fileEdit'):
|
||||
if(self.history[-1]['filePath'] == realtime_action['filePath']):
|
||||
# 检查必要的键是否存在,避免KeyError
|
||||
if realtime_action.get('type') == 'config':
|
||||
return
|
||||
if len(self.history) > 0 and realtime_action.get('type') == 'fileEdit':
|
||||
# 安全地获取filePath,并进行比较
|
||||
current_file_path = realtime_action.get('filePath')
|
||||
# 检查最近的历史记录是否包含filePath
|
||||
if current_file_path and self.history[-1].get('filePath') == current_file_path:
|
||||
# 安全地更新content,只有当content存在时才更新
|
||||
if 'content' in realtime_action:
|
||||
self.history[-1]['content'] = realtime_action['content']
|
||||
return
|
||||
return
|
||||
self.history.append(realtime_action)
|
||||
# 限制历史记录的数量
|
||||
if len(self.history) > 500: # 假设最多保留500条记录
|
||||
self.history.pop(0) # 移除最旧的记录
|
||||
|
||||
|
||||
def get_deltatime_mmss(self, start_time, end_time):
|
||||
|
||||
@@ -148,12 +148,14 @@
|
||||
});
|
||||
|
||||
// 防抖处理非粘贴的编辑操作
|
||||
const content = changes.text;
|
||||
// 确保始终使用完整的编辑器内容而非仅变更部分
|
||||
const fullContent = editor.getValue();
|
||||
debounceSendToServer({
|
||||
type: 'fileEdit',
|
||||
filePath: filePath,
|
||||
content: content,
|
||||
content: fullContent,
|
||||
config: code_like_config,
|
||||
timestamp: new Date().getTime() // 添加时间戳以便追踪
|
||||
}, 5000
|
||||
);
|
||||
// saveFile
|
||||
|
||||
Reference in New Issue
Block a user