feat(chat): 添加Chatter处理状态跟踪机制
在StreamLoopManager中添加is_chatter_processing标志来精确跟踪Chatter处理状态,优化消息打断检查逻辑。 - 在distribution_manager中设置和清除Chatter处理标志 - 在message_manager中基于处理状态进行打断检查 - 在数据模型中添加is_chatter_processing字段
This commit is contained in:
@@ -391,6 +391,10 @@ class StreamLoopManager:
|
|||||||
child_tasks.add(energy_task)
|
child_tasks.add(energy_task)
|
||||||
energy_task.add_done_callback(lambda t: child_tasks.discard(t))
|
energy_task.add_done_callback(lambda t: child_tasks.discard(t))
|
||||||
|
|
||||||
|
# 设置 Chatter 正在处理的标志
|
||||||
|
context.is_chatter_processing = True
|
||||||
|
logger.debug(f"设置 Chatter 处理标志: {stream_id}")
|
||||||
|
|
||||||
# 直接调用chatter_manager处理流上下文
|
# 直接调用chatter_manager处理流上下文
|
||||||
results = await self.chatter_manager.process_stream_context(stream_id, context)
|
results = await self.chatter_manager.process_stream_context(stream_id, context)
|
||||||
success = results.get("success", False)
|
success = results.get("success", False)
|
||||||
@@ -423,6 +427,10 @@ class StreamLoopManager:
|
|||||||
child_task.cancel()
|
child_task.cancel()
|
||||||
return False
|
return False
|
||||||
finally:
|
finally:
|
||||||
|
# 清除 Chatter 处理标志
|
||||||
|
context.is_chatter_processing = False
|
||||||
|
logger.debug(f"清除 Chatter 处理标志: {stream_id}")
|
||||||
|
|
||||||
# 无论成功或失败,都要设置处理状态为未处理
|
# 无论成功或失败,都要设置处理状态为未处理
|
||||||
self._set_stream_processing_status(stream_id, False)
|
self._set_stream_processing_status(stream_id, False)
|
||||||
|
|
||||||
|
|||||||
@@ -374,8 +374,15 @@ class MessageManager:
|
|||||||
logger.info(f"消息 {message.message_id} 是表情包或Emoji,跳过打断检查")
|
logger.info(f"消息 {message.message_id} 是表情包或Emoji,跳过打断检查")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 检查是否有 stream_loop_task 在运行
|
# 检查上下文
|
||||||
context = chat_stream.context_manager.context
|
context = chat_stream.context_manager.context
|
||||||
|
|
||||||
|
# 只有当 Chatter 真正在处理时才检查打断
|
||||||
|
if not context.is_chatter_processing:
|
||||||
|
logger.debug(f"聊天流 {chat_stream.stream_id} Chatter 未在处理,跳过打断检查")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 检查是否有 stream_loop_task 在运行
|
||||||
stream_loop_task = context.stream_loop_task
|
stream_loop_task = context.stream_loop_task
|
||||||
|
|
||||||
if stream_loop_task and not stream_loop_task.done():
|
if stream_loop_task and not stream_loop_task.done():
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class StreamContext(BaseDataModel):
|
|||||||
is_active: bool = True
|
is_active: bool = True
|
||||||
processing_task: asyncio.Task | None = None
|
processing_task: asyncio.Task | None = None
|
||||||
stream_loop_task: asyncio.Task | None = None # 流循环任务
|
stream_loop_task: asyncio.Task | None = None # 流循环任务
|
||||||
|
is_chatter_processing: bool = False # Chatter 是否正在处理
|
||||||
interruption_count: int = 0 # 打断计数器
|
interruption_count: int = 0 # 打断计数器
|
||||||
last_interruption_time: float = 0.0 # 上次打断时间
|
last_interruption_time: float = 0.0 # 上次打断时间
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user