Merge branch 'dev-s4u' into dev

This commit is contained in:
SengokuCola
2025-07-01 19:33:06 +08:00
committed by GitHub
12 changed files with 1197 additions and 3 deletions

View File

@@ -13,8 +13,11 @@ from src.chat.utils.prompt_builder import Prompt, global_prompt_manager
from src.config.config import global_config
from src.plugin_system.core.component_registry import component_registry # 导入新插件系统
from src.plugin_system.base.base_command import BaseCommand
from src.mais4u.mais4u_chat.s4u_msg_processor import S4UMessageProcessor
# 定义日志配置
ENABLE_S4U_CHAT = True
# 仅内部开启
# 配置主程序日志格式
logger = get_logger("chat")
@@ -30,6 +33,7 @@ class ChatBot:
# 创建初始化PFC管理器的任务会在_ensure_started时执行
self.only_process_chat = MessageProcessor()
self.pfc_manager = PFCManager.get_instance()
self.s4u_message_processor = S4UMessageProcessor()
async def _ensure_started(self):
"""确保所有任务已启动"""
@@ -176,6 +180,14 @@ class ChatBot:
# 如果在私聊中
if group_info is None:
logger.debug("检测到私聊消息")
if ENABLE_S4U_CHAT:
logger.debug("进入S4U私聊处理流程")
await self.s4u_message_processor.process_message(message)
return
if global_config.experimental.pfc_chatting:
logger.debug("进入PFC私聊处理流程")
# 创建聊天流
@@ -188,6 +200,13 @@ class ChatBot:
await self.heartflow_message_receiver.process_message(message)
# 群聊默认进入心流消息处理逻辑
else:
if ENABLE_S4U_CHAT:
logger.debug("进入S4U私聊处理流程")
await self.s4u_message_processor.process_message(message)
return
logger.debug(f"检测到群聊消息群ID: {group_info.group_id}")
await self.heartflow_message_receiver.process_message(message)

View File

@@ -305,6 +305,7 @@ class MessageSending(MessageProcessBase):
is_emoji: bool = False,
thinking_start_time: float = 0,
apply_set_reply_logic: bool = False,
reply_to: str = None,
):
# 调用父类初始化
super().__init__(
@@ -322,6 +323,8 @@ class MessageSending(MessageProcessBase):
self.is_head = is_head
self.is_emoji = is_emoji
self.apply_set_reply_logic = apply_set_reply_logic
self.reply_to = reply_to
# 用于显示发送内容与显示不一致的情况
self.display_message = display_message

View File

@@ -35,8 +35,12 @@ class MessageStorage:
filtered_display_message = re.sub(pattern, "", display_message, flags=re.DOTALL)
else:
filtered_display_message = ""
reply_to = message.reply_to
else:
filtered_display_message = ""
reply_to = ""
chat_info_dict = chat_stream.to_dict()
user_info_dict = message.message_info.user_info.to_dict()
@@ -54,6 +58,7 @@ class MessageStorage:
time=float(message.message_info.time),
chat_id=chat_stream.stream_id,
# Flattened chat_info
reply_to=reply_to,
chat_info_stream_id=chat_info_dict.get("stream_id"),
chat_info_platform=chat_info_dict.get("platform"),
chat_info_user_platform=user_info_from_chat.get("platform"),

View File

@@ -174,6 +174,7 @@ def _build_readable_messages_internal(
truncate: bool = False,
pic_id_mapping: Dict[str, str] = None,
pic_counter: int = 1,
show_pic: bool = True,
) -> Tuple[str, List[Tuple[float, str, str]], Dict[str, str], int]:
"""
内部辅助函数,构建可读消息字符串和原始消息详情列表。
@@ -260,7 +261,9 @@ def _build_readable_messages_internal(
content = content.replace("", "")
# 处理图片ID
content = process_pic_ids(content)
if show_pic:
content = process_pic_ids(content)
# 检查必要信息是否存在
if not all([platform, user_id, timestamp is not None]):
@@ -532,6 +535,7 @@ def build_readable_messages(
read_mark: float = 0.0,
truncate: bool = False,
show_actions: bool = False,
show_pic: bool = True,
) -> str:
"""
将消息列表转换为可读的文本格式。
@@ -601,7 +605,7 @@ def build_readable_messages(
if read_mark <= 0:
# 没有有效的 read_mark直接格式化所有消息
formatted_string, _, pic_id_mapping, _ = _build_readable_messages_internal(
copy_messages, replace_bot_name, merge_messages, timestamp_mode, truncate
copy_messages, replace_bot_name, merge_messages, timestamp_mode, truncate, show_pic=show_pic
)
# 生成图片映射信息并添加到最前面
@@ -628,9 +632,10 @@ def build_readable_messages(
truncate,
pic_id_mapping,
pic_counter,
show_pic=show_pic
)
formatted_after, _, pic_id_mapping, _ = _build_readable_messages_internal(
messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, False, pic_id_mapping, pic_counter
messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, False, pic_id_mapping, pic_counter, show_pic=show_pic
)
read_mark_line = "\n--- 以上消息是你已经看过,请关注以下未读的新消息---\n"