mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
feat: add explicit handling for /ai messages to bypass media interactions
This commit is contained in:
+14
-14
@@ -298,6 +298,20 @@ class MessageChain(ChainBase):
|
|||||||
)
|
)
|
||||||
return bool(processing_status)
|
return bool(processing_status)
|
||||||
|
|
||||||
|
if text.lower().startswith("/ai"):
|
||||||
|
return self._handle_ai_message(
|
||||||
|
text=text,
|
||||||
|
channel=channel,
|
||||||
|
source=source,
|
||||||
|
userid=userid,
|
||||||
|
username=username,
|
||||||
|
original_message_id=original_message_id,
|
||||||
|
original_chat_id=original_chat_id,
|
||||||
|
images=images,
|
||||||
|
files=files,
|
||||||
|
has_audio_input=has_audio_input,
|
||||||
|
)
|
||||||
|
|
||||||
latest_slash_interaction = self._get_latest_slash_interaction(userid)
|
latest_slash_interaction = self._get_latest_slash_interaction(userid)
|
||||||
if latest_slash_interaction == "sites":
|
if latest_slash_interaction == "sites":
|
||||||
if SiteChain().handle_text_interaction(
|
if SiteChain().handle_text_interaction(
|
||||||
@@ -339,20 +353,6 @@ class MessageChain(ChainBase):
|
|||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if text.lower().startswith("/ai"):
|
|
||||||
return self._handle_ai_message(
|
|
||||||
text=text,
|
|
||||||
channel=channel,
|
|
||||||
source=source,
|
|
||||||
userid=userid,
|
|
||||||
username=username,
|
|
||||||
original_message_id=original_message_id,
|
|
||||||
original_chat_id=original_chat_id,
|
|
||||||
images=images,
|
|
||||||
files=files,
|
|
||||||
has_audio_input=has_audio_input,
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
settings.AI_AGENT_ENABLE
|
settings.AI_AGENT_ENABLE
|
||||||
and (settings.AI_AGENT_GLOBAL or images or files or has_audio_input)
|
and (settings.AI_AGENT_GLOBAL or images or files or has_audio_input)
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from app.chain.message import MessageChain
|
||||||
|
from app.helper.interaction import media_interaction_manager
|
||||||
|
from app.schemas.types import MessageChannel
|
||||||
|
|
||||||
|
|
||||||
|
def test_explicit_ai_message_bypasses_pending_media_interaction():
|
||||||
|
"""显式 /ai 消息应绕过误触发的媒体交互状态并回到 Agent 会话。"""
|
||||||
|
chain = MessageChain()
|
||||||
|
media_interaction_manager.clear()
|
||||||
|
media_interaction_manager.create_or_replace(
|
||||||
|
user_id="10001",
|
||||||
|
channel=MessageChannel.Wechat,
|
||||||
|
source="wechat-test",
|
||||||
|
username="tester",
|
||||||
|
action="Search",
|
||||||
|
keyword="确认",
|
||||||
|
title="确认",
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with patch.object(chain, "_record_user_message"), patch(
|
||||||
|
"app.chain.message.MediaInteractionChain.handle_text_interaction",
|
||||||
|
return_value=True,
|
||||||
|
) as handle_media_interaction, patch.object(
|
||||||
|
chain, "_handle_ai_message", return_value=True
|
||||||
|
) as handle_ai_message:
|
||||||
|
chain.handle_message(
|
||||||
|
channel=MessageChannel.Wechat,
|
||||||
|
source="wechat-test",
|
||||||
|
userid="10001",
|
||||||
|
username="tester",
|
||||||
|
text="/ai 确认",
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
media_interaction_manager.clear()
|
||||||
|
|
||||||
|
handle_ai_message.assert_called_once()
|
||||||
|
handle_media_interaction.assert_not_called()
|
||||||
Reference in New Issue
Block a user