fix(agent): reply Feishu agent streams with cards

This commit is contained in:
jxxghp
2026-05-13 06:56:03 +08:00
parent 77aa65bfdc
commit fa939dfbe6
7 changed files with 109 additions and 12 deletions

View File

@@ -263,6 +263,33 @@ class TestAgentToolStreaming(unittest.TestCase):
)
self.assertTrue(handler.has_sent_message)
def test_flush_passes_original_message_context_to_send_direct_message(self):
handler = StreamingHandler()
handler._channel = MessageChannel.Feishu.value
handler._source = "feishu-main"
handler._user_id = "ou_user"
handler._username = "tester"
handler._original_message_id = "om_origin"
handler._original_chat_id = "oc_origin"
handler._streaming_enabled = True
handler.emit("hello")
with patch(
"app.agent.callback.run_in_threadpool", new_callable=AsyncMock
) as run_in_threadpool_mock:
run_in_threadpool_mock.return_value = MessageResponse(
message_id="om_stream",
chat_id="oc_origin",
source="feishu-main",
success=True,
)
asyncio.run(handler._flush())
notification = run_in_threadpool_mock.await_args.args[1]
self.assertEqual(notification.original_message_id, "om_origin")
self.assertEqual(notification.original_chat_id, "oc_origin")
def test_verbose_background_tool_call_does_not_post_message(self):
async def _run():
tool = DummyTool(session_id="session-1", user_id="10001")

View File

@@ -301,6 +301,30 @@ class TestFeishu(unittest.TestCase):
self.assertEqual(message_request.request_body.msg_type, "interactive")
self.assertEqual(json.loads(message_request.request_body.content)["data"]["card_id"], "card_stream")
def test_send_notification_replies_with_streaming_card_for_agent_text(self):
client = self._build_client()
client._api_client, message_api = self._build_message_api(
reply_response=self._success_response(message_id="om_reply", chat_id="oc_stream"),
card_create_response=self._card_create_success_response("card_stream"),
)
result = client.send_notification(
Notification(
mtype=NotificationType.Agent,
title="MoviePilot助手",
text="第一帧内容",
),
userid="ou_user_stream",
original_message_id="om_origin",
)
self.assertTrue(result["success"])
message_api.create.assert_not_called()
reply_request = message_api.reply.call_args.args[0]
self.assertEqual(reply_request.message_id, "om_origin")
self.assertEqual(reply_request.request_body.msg_type, "interactive")
self.assertEqual(json.loads(reply_request.request_body.content)["data"]["card_id"], "card_stream")
def test_edit_message_uses_cardkit_content_for_streaming_card(self):
client = self._build_client()
client._api_client, message_api = self._build_message_api(