大段粘贴检测
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
# myapp/services/backboard_service.py
|
# myapp/services/backboard_service.py
|
||||||
import os
|
import os
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from flask_socketio import emit
|
||||||
from backboardManager import Backboard # 你已有的类
|
from backboardManager import Backboard # 你已有的类
|
||||||
from ..utils.sudoUtil import sudo_open
|
from ..utils.sudoUtil import sudo_open
|
||||||
|
from ..extension_ase.ase_client import HSAEngineClient
|
||||||
|
from manager import ChatManager
|
||||||
|
|
||||||
def _to_wsl_path_if_needed(path: str) -> str:
|
def _to_wsl_path_if_needed(path: str) -> str:
|
||||||
cfg = current_app.config["VSCODE_WEB_PATH"]
|
cfg = current_app.config["VSCODE_WEB_PATH"]
|
||||||
@@ -44,6 +47,19 @@ def realtime_response(config: dict, realtime_action: dict) -> None:
|
|||||||
bb.pasted_content = realtime_action.get("content")
|
bb.pasted_content = realtime_action.get("content")
|
||||||
with open(os.path.join(bb.root_path, bb.active_file_path), "r", encoding="utf-8") as f:
|
with open(os.path.join(bb.root_path, bb.active_file_path), "r", encoding="utf-8") as f:
|
||||||
bb.active_file_content = f.read()
|
bb.active_file_content = f.read()
|
||||||
|
#处理粘贴事件
|
||||||
|
|
||||||
|
# paste_data = {
|
||||||
|
# 'pasted_file_path': file_path,
|
||||||
|
# 'pasted_content': bb.pasted_content,
|
||||||
|
# 'pasted_content_length': len(bb.pasted_content)
|
||||||
|
# }
|
||||||
|
# emit('paste_detected', paste_data)
|
||||||
|
|
||||||
|
#判断一下,如果粘帖内容过多就发送,后期可加入更多条件判断
|
||||||
|
if bb.pasted_content and len(bb.pasted_content) > 300:
|
||||||
|
chatmanager.ase_client.send("pasted_detected_in", {"file_path": file_path, "content": bb.pasted_content})
|
||||||
|
|
||||||
|
|
||||||
elif rtype == "fileEdit":
|
elif rtype == "fileEdit":
|
||||||
file_path = realtime_action.get("filePath")
|
file_path = realtime_action.get("filePath")
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ class AgentNamespace(Namespace):
|
|||||||
entry=self,
|
entry=self,
|
||||||
init_data={'room': user_uuid}
|
init_data={'room': user_uuid}
|
||||||
)
|
)
|
||||||
|
user_uuid2ase_client[user_uuid].register_route_with_entry(
|
||||||
|
route='paste_detected',
|
||||||
|
callback=self.receive_ase_paste_detected,
|
||||||
|
entry=self,
|
||||||
|
init_data={'room': user_uuid}
|
||||||
|
)
|
||||||
user_uuid2ase_client[user_uuid].connect()
|
user_uuid2ase_client[user_uuid].connect()
|
||||||
|
|
||||||
|
|
||||||
@@ -179,6 +185,12 @@ class AgentNamespace(Namespace):
|
|||||||
ase_client.send_text("chapter-start", "")
|
ase_client.send_text("chapter-start", "")
|
||||||
namespace_entry.emit('message', "Multi-Agents服务已连接", room=init_data['room'], namespace='/agent')
|
namespace_entry.emit('message', "Multi-Agents服务已连接", room=init_data['room'], namespace='/agent')
|
||||||
|
|
||||||
|
#接受消息回来直接让message监听发送
|
||||||
|
def receive_ase_paste_detected(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||||
|
print("receive_ase_paste_detected", data)
|
||||||
|
client_entry.chatmanager.chat_historys.append({'role': 'assistant', 'content': data['data']})
|
||||||
|
namespace_entry.emit('message', data['data'], room=init_data['room'], namespace='/agent')
|
||||||
|
|
||||||
def receive_ase_dialog(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
def receive_ase_dialog(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||||
print("receive_ase_dialog", data)
|
print("receive_ase_dialog", data)
|
||||||
client_entry.chatmanager.chat_historys.append({'role': 'assistant', 'content': data['data']})
|
client_entry.chatmanager.chat_historys.append({'role': 'assistant', 'content': data['data']})
|
||||||
@@ -195,7 +207,6 @@ class AgentNamespace(Namespace):
|
|||||||
def receive_ase_process(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
def receive_ase_process(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||||
namespace_entry.emit('process', data['data'], room=init_data['room'], namespace='/agent')
|
namespace_entry.emit('process', data['data'], room=init_data['room'], namespace='/agent')
|
||||||
|
|
||||||
|
|
||||||
def receive_ase_judge(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
def receive_ase_judge(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||||
print("receive_ase_judge", data)
|
print("receive_ase_judge", data)
|
||||||
namespace_entry.emit('request_function', data, room=init_data['room'], namespace='/agent') # data 是一个列表 /dict也支持
|
namespace_entry.emit('request_function', data, room=init_data['room'], namespace='/agent') # data 是一个列表 /dict也支持
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"username": "agnes"}
|
{"username": "Agnes"}
|
||||||
@@ -1 +1 @@
|
|||||||
{"username": "ttt"}
|
{"username": "Ttt"}
|
||||||
Reference in New Issue
Block a user