feat(plugin): add pre-reset plugin data event (#5957)

This commit is contained in:
InfinityPacer
2026-06-17 06:34:15 +08:00
committed by GitHub
parent d5bac81881
commit 93056ed1ff
4 changed files with 75 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ from starlette.responses import StreamingResponse
from app import schemas
from app.command import Command
from app.core.config import settings
from app.core.event import eventmanager
from app.core.plugin import PluginManager
from app.core.security import (
resource_token_cookie,
@@ -30,7 +31,8 @@ from app.helper.server import MoviePilotServerHelper
from app.helper.plugin import PluginHelper
from app.log import logger
from app.scheduler import Scheduler
from app.schemas.types import SystemConfigKey
from app.schemas.event import PluginDataResetEventData
from app.schemas.types import ChainEventType, SystemConfigKey
PROTECTED_ROUTES = {"/api/v1/openapi.json", "/docs", "/docs/oauth2-redirect", "/redoc"}
PLUGIN_PREFIX = f"{settings.API_V1_STR}/plugin"
@@ -530,6 +532,12 @@ def reset_plugin(
根据插件ID重置插件配置及数据
"""
plugin_manager = PluginManager()
eventmanager.send_event(
ChainEventType.PluginDataReset,
PluginDataResetEventData(plugin_id=plugin_id, reset_config=True, reset_data=True),
)
# 事件处理器需要运行中插件完成补偿;补偿后先停止插件,避免删除数据时仍有任务读写旧状态。
plugin_manager.stop(plugin_id)
# 删除配置
plugin_manager.delete_plugin_config(plugin_id)
# 删除插件所有数据

View File

@@ -64,6 +64,19 @@ class ChainEventData(BaseEventData):
pass
class PluginDataResetEventData(ChainEventData):
"""
PluginDataReset 事件的数据模型。
在主程序清空某个插件配置或插件数据前发出,插件可在数据被删除前完成
自有状态补偿。事件处理器只应处理 plugin_id 与自身匹配的事件。
"""
plugin_id: str = Field(..., description="即将被重置的插件 ID")
reset_config: bool = Field(default=False, description="是否即将重置插件配置")
reset_data: bool = Field(default=False, description="是否即将重置插件数据")
class AgentLLMProviderEventData(ChainEventData):
"""
Agent LLM 供应商选择事件数据。

View File

@@ -163,6 +163,8 @@ EVENT_TYPE_NAMES = {
# 同步链式事件
class ChainEventType(Enum):
# 插件数据重置前
PluginDataReset = "plugin.data.reset"
# 名称识别
NameRecognize = "name.recognize"
# 认证验证