mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: unify web agent notice event routing
This commit is contained in:
+4
-3
@@ -13,8 +13,8 @@
|
||||
"runtime_to_db": [],
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6545,
|
||||
"edge_sha256": "e74daad54d04652df3946334297eac0dd9a4560ca87f84365b25dc9f553436da",
|
||||
"edge_count": 6546,
|
||||
"edge_sha256": "9799edea47a44d52ae4d5d4bf3e38614b1d1a255f850891b3cc1d8fb85b40735",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -1674,7 +1674,6 @@
|
||||
"app.api.endpoints.agent -> app.chain.message",
|
||||
"app.api.endpoints.agent -> app.runtime",
|
||||
"app.api.endpoints.agent -> app.runtime.config",
|
||||
"app.api.endpoints.agent -> app.runtime.events",
|
||||
"app.api.endpoints.agent -> app.runtime.execution",
|
||||
"app.api.endpoints.agent -> app.runtime.localization",
|
||||
"app.api.endpoints.agent -> app.runtime.log",
|
||||
@@ -2602,8 +2601,10 @@
|
||||
"app.application.mediaserver -> app.schemas.system",
|
||||
"app.application.mediaserver -> app.schemas.types",
|
||||
"app.application.messaging.agent -> app.runtime",
|
||||
"app.application.messaging.agent -> app.runtime.log",
|
||||
"app.application.messaging.agent -> app.runtime.tasks",
|
||||
"app.application.messaging.agent -> app.schemas",
|
||||
"app.application.messaging.agent -> app.schemas.message",
|
||||
"app.application.messaging.agent -> app.schemas.types",
|
||||
"app.application.messaging.chat -> app.application",
|
||||
"app.application.messaging.chat -> app.application.database",
|
||||
|
||||
@@ -2114,7 +2114,7 @@
|
||||
"EventType.NoticeMessage": {
|
||||
"consumers": [
|
||||
{
|
||||
"caller": "app.api.endpoints.agent",
|
||||
"caller": "app.startup.initializers.modules",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1232,6 +1232,25 @@ def test_application_services_do_not_resolve_event_manager_singleton():
|
||||
assert violations == {}
|
||||
|
||||
|
||||
def test_http_endpoints_do_not_register_process_event_listeners():
|
||||
"""HTTP 端点不得拥有进程级事件监听器,监听装配必须留在 startup。"""
|
||||
violations: dict[str, set[str]] = {}
|
||||
for module_name, path in _discover_modules().items():
|
||||
if not module_name.startswith("app.api"):
|
||||
continue
|
||||
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
||||
calls = {
|
||||
node.func.attr
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.Call)
|
||||
and isinstance(node.func, ast.Attribute)
|
||||
and node.func.attr in {"register", "add_event_listener"}
|
||||
}
|
||||
if calls:
|
||||
violations[module_name] = calls
|
||||
assert violations == {}
|
||||
|
||||
|
||||
def test_agent_tools_do_not_import_entrypoint_internals():
|
||||
"""Agent 工具不得穿透导入 HTTP 端点、调度器与命令注册表内部实现。
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ from app.agent.orchestrator import agent_manager
|
||||
from app.api.endpoints.agent import (
|
||||
_WebAgentEventPublisher,
|
||||
_WEB_AGENT_FILE_REGISTRY,
|
||||
_WEB_AGENT_MESSAGE_QUEUES,
|
||||
_apply_web_agent_display_event,
|
||||
_build_web_agent_input_attachments,
|
||||
_build_web_agent_message_events,
|
||||
@@ -23,8 +22,6 @@ from app.api.endpoints.agent import (
|
||||
_build_web_agent_traditional_callback_payload,
|
||||
_build_web_agent_display_message_from_events,
|
||||
_collect_web_agent_traditional_events,
|
||||
_dispatch_web_agent_message_event,
|
||||
_extract_web_agent_message_from_event_data,
|
||||
_get_web_agent_type,
|
||||
_has_web_agent_traditional_interaction,
|
||||
_prepare_web_agent_audio_attachment_path_async,
|
||||
@@ -38,8 +35,15 @@ from app.runtime.events import Event
|
||||
from app.db.oper.agentchat import AgentChatOper
|
||||
from app.db.models.agentchat import AgentChat
|
||||
from app.application.messaging.chat import AgentChatService, configure_agent_chat_service
|
||||
from app.application.messaging.agent import build_web_agent_message_update_event
|
||||
from app.application.messaging.agent import AgentInteractionOption, agent_interaction_manager
|
||||
from app.application.messaging.agent import (
|
||||
AgentInteractionOption,
|
||||
agent_interaction_manager,
|
||||
attach_web_agent_message_queue,
|
||||
build_web_agent_message_update_event,
|
||||
detach_web_agent_message_queue,
|
||||
dispatch_web_agent_message_event,
|
||||
extract_web_agent_message_from_event_data,
|
||||
)
|
||||
from app.application.messaging.skill import skill_interaction_manager
|
||||
from app.chain.message import MessageChain
|
||||
from app.schemas.notification import ChannelCapability, ChannelCapabilityManager
|
||||
@@ -561,7 +565,7 @@ def test_extract_web_agent_message_supports_wrapped_message_event():
|
||||
userid="1",
|
||||
)
|
||||
|
||||
extracted = _extract_web_agent_message_from_event_data(
|
||||
extracted = extract_web_agent_message_from_event_data(
|
||||
{"message": message, "current_time": "2026-06-26 09:18:38"}
|
||||
)
|
||||
|
||||
@@ -571,7 +575,7 @@ def test_extract_web_agent_message_supports_wrapped_message_event():
|
||||
def test_dispatch_web_agent_message_event_accepts_wrapped_message_event():
|
||||
"""WebAgent 等待队列应接收 message 包装格式的 NoticeMessage 事件。"""
|
||||
notice_queue = Queue()
|
||||
_WEB_AGENT_MESSAGE_QUEUES["1"] = [notice_queue]
|
||||
attach_web_agent_message_queue("1", notice_queue)
|
||||
message = schemas.Message(
|
||||
channel=NotificationChannel.WebAgent,
|
||||
source="web-agent",
|
||||
@@ -580,14 +584,14 @@ def test_dispatch_web_agent_message_event_accepts_wrapped_message_event():
|
||||
)
|
||||
|
||||
try:
|
||||
_dispatch_web_agent_message_event(
|
||||
dispatch_web_agent_message_event(
|
||||
Event(
|
||||
EventType.NoticeMessage,
|
||||
{"message": message, "current_time": "2026-06-26 09:18:38"},
|
||||
)
|
||||
)
|
||||
finally:
|
||||
_WEB_AGENT_MESSAGE_QUEUES.pop("1", None)
|
||||
detach_web_agent_message_queue("1", notice_queue)
|
||||
|
||||
assert notice_queue.get_nowait() == message
|
||||
|
||||
|
||||
Reference in New Issue
Block a user