diff --git a/app/agent/__init__.py b/app/agent/__init__.py index cd2a2759..e893da4f 100644 --- a/app/agent/__init__.py +++ b/app/agent/__init__.py @@ -663,7 +663,7 @@ class MoviePilotAgent: and self.should_dispatch_reply and not self._tool_context.get("user_reply_sent") ): - await self.send_agent_message(remaining_text) + await self.send_agent_message(remaining_text, is_streaming_fallback=True) elif ( remaining_text and self.persist_output_message @@ -743,17 +743,20 @@ class MoviePilotAgent: # 确保停止流式输出 await self.stream_handler.stop_streaming() - async def send_agent_message(self, message: str, title: str = ""): + async def send_agent_message(self, message: str, title: str = "", is_streaming_fallback: bool = False): """ 通过原渠道发送消息给用户 """ + mtype = NotificationType.System if is_streaming_fallback else NotificationType.Agent await AgentChain().async_post_message( Notification( channel=self.channel, source=self.source, - mtype=NotificationType.Agent, + mtype=mtype, userid=self.user_id, username=self.username, + original_message_id=self.original_message_id, + original_chat_id=self.original_chat_id, title=title, text=message, ) diff --git a/app/modules/feishu/feishu.py b/app/modules/feishu/feishu.py index b57c1344..4072d2b7 100644 --- a/app/modules/feishu/feishu.py +++ b/app/modules/feishu/feishu.py @@ -1240,13 +1240,14 @@ class Feishu: card_id = str(stream_meta.get("card_id") or "").strip() element_id = str(stream_meta.get("element_id") or self.STREAM_CARD_BODY_ELEMENT_ID).strip() sequence = int(stream_meta.get("sequence") or 0) + 1 + # 无论远端是否响应成功都自增 sequence,防止某次超时导致后续 sequence 一直因为没有递增而被拒绝 + stream_meta["sequence"] = sequence if card_id and element_id and self._update_streaming_card_content( card_id=card_id, element_id=element_id, content=self._escape_card_text(text).strip() or " ", sequence=sequence, ): - stream_meta["sequence"] = sequence return True card = self._build_card(title=title, text=text, link=None, buttons=buttons)