mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 07:56:52 +08:00
refactor(config): retire RuntimeSettingsCompat host usage
This commit is contained in:
@@ -9,11 +9,10 @@ from app.adapters.external.market import PluginHelper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.application.plugin.gateway import get_plugin_install_service
|
||||
from app.application.plugin.runtime import get_plugin_manager
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.schemas.plugin import PluginRuntimeStatus
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
|
||||
# 默认只向智能体返回一个可读预览,避免超大插件数据挤爆上下文窗口。
|
||||
DEFAULT_PLUGIN_DATA_PREVIEW_CHARS = 12_000
|
||||
@@ -395,7 +394,7 @@ async def uninstall_plugin_runtime(plugin_id: str) -> dict[str, Any]:
|
||||
elif was_clone:
|
||||
plugin_manager.delete_plugin_config(plugin_id)
|
||||
plugin_manager.delete_plugin_data(plugin_id)
|
||||
plugin_base_dir = settings.ROOT_PATH / "app" / "plugins" / plugin_id.lower()
|
||||
plugin_base_dir = get_runtime_setting('ROOT_PATH') / "app" / "plugins" / plugin_id.lower()
|
||||
try:
|
||||
clone_files_removed = await run_agent_blocking(
|
||||
"plugin",
|
||||
|
||||
@@ -14,10 +14,8 @@ from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.agent.tools.impl._command_safety import validate_command_safety
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
if os.name == "posix":
|
||||
import fcntl as _fcntl
|
||||
@@ -151,10 +149,10 @@ class _TerminalSessionManager:
|
||||
def _normalize_cwd(cwd: Optional[str]) -> str:
|
||||
"""解析工作目录,未传入时默认使用 MoviePilot 项目根目录。"""
|
||||
if not cwd:
|
||||
return str(settings.ROOT_PATH)
|
||||
return str(get_runtime_setting('ROOT_PATH'))
|
||||
path = Path(cwd).expanduser()
|
||||
if not path.is_absolute():
|
||||
path = (settings.ROOT_PATH / path).resolve()
|
||||
path = (get_runtime_setting('ROOT_PATH') / path).resolve()
|
||||
else:
|
||||
path = path.resolve()
|
||||
if not path.exists():
|
||||
|
||||
@@ -12,9 +12,8 @@ from app.agent.tools.tags import ToolTag
|
||||
from app.chain.download import DownloadChain
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.search import SearchChain
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.domain.context import Context
|
||||
from app.domain.metainfo import MetaInfo
|
||||
from app.application.agentdata import get_agent_site_port
|
||||
@@ -142,7 +141,7 @@ class AddDownloadTasksTool(MoviePilotTool):
|
||||
@staticmethod
|
||||
def _merge_labels_with_system_tag(labels: Optional[str]) -> Optional[str]:
|
||||
"""合并用户标签与系统默认标签,确保任务可被系统管理"""
|
||||
system_tag = (settings.TORRENT_TAG or "").strip()
|
||||
system_tag = (get_runtime_setting('TORRENT_TAG') or "").strip()
|
||||
user_labels = [item.strip() for item in (labels or "").split(",") if item.strip()]
|
||||
|
||||
if system_tag and system_tag not in user_labels:
|
||||
|
||||
@@ -7,9 +7,8 @@ from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.application.agentdata import get_agent_chat_port
|
||||
from app.application.agentdata import get_agent_task_port
|
||||
from app.runtime.scheduling import TimerUtils
|
||||
@@ -73,7 +72,7 @@ class CreateAgentTaskInput(BaseModel):
|
||||
self.trigger_type, self.trigger = TimerUtils.normalize_schedule_trigger(
|
||||
trigger_type=self.trigger_type,
|
||||
trigger_value=self.trigger,
|
||||
timezone_name=settings.TZ,
|
||||
timezone_name=get_runtime_setting('TZ'),
|
||||
require_future=True,
|
||||
)
|
||||
return self
|
||||
@@ -105,14 +104,14 @@ class CreateAgentTaskTool(MoviePilotTool):
|
||||
|
||||
trigger_value = payload.trigger
|
||||
if payload.trigger_type == "date" and payload.delay_minutes is not None:
|
||||
timezone = pytz.timezone(settings.TZ)
|
||||
timezone = pytz.timezone(get_runtime_setting('TZ'))
|
||||
trigger_value = (
|
||||
datetime.now(timezone) + timedelta(minutes=payload.delay_minutes)
|
||||
).isoformat(timespec="seconds")
|
||||
_, trigger_value = TimerUtils.normalize_schedule_trigger(
|
||||
trigger_type=payload.trigger_type,
|
||||
trigger_value=trigger_value,
|
||||
timezone_name=settings.TZ,
|
||||
timezone_name=get_runtime_setting('TZ'),
|
||||
require_future=True,
|
||||
)
|
||||
chat = get_agent_chat_port().get(
|
||||
@@ -136,7 +135,7 @@ class CreateAgentTaskTool(MoviePilotTool):
|
||||
return get_agent_task_port().to_dict(
|
||||
task,
|
||||
next_run_at=next_run_at,
|
||||
timezone=settings.TZ,
|
||||
timezone=get_runtime_setting('TZ'),
|
||||
)
|
||||
|
||||
async def run(
|
||||
@@ -149,7 +148,7 @@ class CreateAgentTaskTool(MoviePilotTool):
|
||||
**kwargs: object,
|
||||
) -> str:
|
||||
"""创建 Agent 自主定时任务。"""
|
||||
if not settings.AI_AGENT_ENABLE:
|
||||
if not get_runtime_setting('AI_AGENT_ENABLE'):
|
||||
return "AI Agent 未启用,无法创建自主定时任务"
|
||||
payload = CreateAgentTaskInput(
|
||||
name=name,
|
||||
|
||||
@@ -5,10 +5,8 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.application.agentdata import get_agent_task_port
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
|
||||
class QueryAgentTasksInput(BaseModel):
|
||||
@@ -63,7 +61,7 @@ class QueryAgentTasksTool(MoviePilotTool):
|
||||
data = oper.to_dict(
|
||||
task,
|
||||
next_run_at=get_agent_task_next_run(task.id),
|
||||
timezone=settings.TZ,
|
||||
timezone=get_runtime_setting('TZ'),
|
||||
)
|
||||
if task_id:
|
||||
data["recent_runs"] = [
|
||||
|
||||
@@ -9,9 +9,8 @@ from pydantic import BaseModel, Field
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.chain.media import MediaChain
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.domain.context import Context
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
from app.domain.metainfo import MetaInfo
|
||||
@@ -104,7 +103,7 @@ class RecognizeMediaTool(MoviePilotTool):
|
||||
}, ensure_ascii=False)
|
||||
|
||||
is_audio_path = bool(
|
||||
path and Path(path).suffix.lower() in settings.RMT_AUDIOEXT
|
||||
path and Path(path).suffix.lower() in get_runtime_setting('RMT_AUDIOEXT')
|
||||
)
|
||||
recognize_music = media_type_enum == MediaType.MUSIC or (
|
||||
media_type_enum is None and is_audio_path
|
||||
|
||||
@@ -10,9 +10,8 @@ from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.scraping import ScrapingChain
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.workflow import FileItem
|
||||
from app.schemas.types import (
|
||||
@@ -184,7 +183,7 @@ class ScrapeMetadataTool(MoviePilotTool):
|
||||
scraping_chain = ScrapingChain()
|
||||
is_audio_file = (
|
||||
fileitem.type == "file"
|
||||
and Path(path).suffix.lower() in settings.RMT_AUDIOEXT
|
||||
and Path(path).suffix.lower() in get_runtime_setting('RMT_AUDIOEXT')
|
||||
)
|
||||
scrape_music = media_type_enum == MediaType.MUSIC or (
|
||||
media_type_enum is None and is_audio_file
|
||||
|
||||
@@ -9,10 +9,8 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
# 搜索超时时间(秒)
|
||||
SEARCH_TIMEOUT = 20
|
||||
@@ -412,7 +410,7 @@ class SearchWebTool(MoviePilotTool):
|
||||
"""在线程中执行同步搜索"""
|
||||
results = []
|
||||
ddgs_kwargs = {"timeout": SEARCH_TIMEOUT}
|
||||
proxy_url = self._get_proxy_url(settings.PROXY)
|
||||
proxy_url = self._get_proxy_url(get_runtime_setting('PROXY'))
|
||||
if proxy_url:
|
||||
ddgs_kwargs["proxy"] = proxy_url
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@ from pydantic import BaseModel, Field
|
||||
from app.agent.llm.capability import AgentCapabilityManager
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.message import Message
|
||||
from app.schemas.message import MessageType
|
||||
@@ -96,7 +95,7 @@ class SendVoiceMessageTool(MoviePilotTool):
|
||||
voice_path=voice_path,
|
||||
voice_caption=(
|
||||
message
|
||||
if voice_path and settings.AUDIO_OUTPUT_INCLUDE_TEXT
|
||||
if voice_path and get_runtime_setting('AUDIO_OUTPUT_INCLUDE_TEXT')
|
||||
else None
|
||||
),
|
||||
save_history=False,
|
||||
|
||||
@@ -7,11 +7,9 @@ from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.application.agentdata import get_agent_task_port
|
||||
from app.runtime.scheduling import TimerUtils
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
|
||||
|
||||
class UpdateAgentTaskInput(BaseModel):
|
||||
@@ -115,7 +113,7 @@ class UpdateAgentTaskTool(MoviePilotTool):
|
||||
trigger_type = payload.trigger_type or task.trigger_type
|
||||
trigger_value = payload.trigger
|
||||
if trigger_type == "date" and payload.delay_minutes is not None:
|
||||
timezone = pytz.timezone(settings.TZ)
|
||||
timezone = pytz.timezone(get_runtime_setting('TZ'))
|
||||
trigger_value = (
|
||||
datetime.now(timezone) + timedelta(minutes=payload.delay_minutes)
|
||||
).isoformat(timespec="seconds")
|
||||
@@ -134,7 +132,7 @@ class UpdateAgentTaskTool(MoviePilotTool):
|
||||
normalized_type, normalized_trigger = TimerUtils.normalize_schedule_trigger(
|
||||
trigger_type=trigger_type,
|
||||
trigger_value=trigger_value,
|
||||
timezone_name=settings.TZ,
|
||||
timezone_name=get_runtime_setting('TZ'),
|
||||
require_future=bool(
|
||||
trigger_type == "date"
|
||||
and (
|
||||
@@ -181,7 +179,7 @@ class UpdateAgentTaskTool(MoviePilotTool):
|
||||
return oper.to_dict(
|
||||
updated_task,
|
||||
next_run_at=next_run_at,
|
||||
timezone=settings.TZ,
|
||||
timezone=get_runtime_setting('TZ'),
|
||||
)
|
||||
|
||||
async def run(
|
||||
|
||||
Reference in New Issue
Block a user