mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-28 11:12:00 +08:00
feat: add WebAgent support for streaming and notifications
This commit is contained in:
@@ -612,13 +612,30 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta):
|
||||
|
||||
return False
|
||||
|
||||
async def send_notification_message(self, notification: Notification) -> None:
|
||||
"""
|
||||
发送工具通知消息。
|
||||
|
||||
WebAgent 渠道没有后端模块实例,前端流式面板通过 Agent 上下文中的
|
||||
回调直接接收通知;其它渠道继续走统一消息链。
|
||||
"""
|
||||
callback = self._agent_context.get("notification_callback")
|
||||
if (
|
||||
self._channel == MessageChannel.WebAgent.value
|
||||
and callable(callback)
|
||||
):
|
||||
callback(notification)
|
||||
return
|
||||
|
||||
await ToolChain().async_post_message(notification)
|
||||
|
||||
async def send_tool_message(
|
||||
self, message: str, title: str = "", image: Optional[str] = None
|
||||
) -> None:
|
||||
"""
|
||||
发送工具消息
|
||||
"""
|
||||
await ToolChain().async_post_message(
|
||||
await self.send_notification_message(
|
||||
Notification(
|
||||
channel=self._channel,
|
||||
source=self._source,
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Optional, Type
|
||||
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool, ToolChain
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.log import logger
|
||||
from app.schemas import Notification, NotificationType
|
||||
@@ -96,7 +96,7 @@ class SendLocalFileTool(MoviePilotTool):
|
||||
resolved_path,
|
||||
)
|
||||
|
||||
await ToolChain().async_post_message(
|
||||
await self.send_notification_message(
|
||||
Notification(
|
||||
channel=channel,
|
||||
source=self._source,
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Optional, Type
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.agent.llm.capability import AgentCapabilityManager
|
||||
from app.agent.tools.base import MoviePilotTool, ToolChain
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
@@ -86,7 +86,7 @@ class SendVoiceMessageTool(MoviePilotTool):
|
||||
f"use_voice={used_voice}, text_len={len(message)}"
|
||||
)
|
||||
|
||||
await ToolChain().async_post_message(
|
||||
await self.send_notification_message(
|
||||
Notification(
|
||||
channel=self._channel,
|
||||
source=self._source,
|
||||
|
||||
Reference in New Issue
Block a user