refactor: rename plugin manager to plugin client and rename path from manager to impl (#18876)

This commit is contained in:
Yeuoly
2025-04-27 14:22:25 +08:00
committed by GitHub
parent d91828dd90
commit abafa68647
38 changed files with 116 additions and 103 deletions

View File

@@ -1,7 +1,7 @@
from configs import dify_config
from core.helper import marketplace
from core.plugin.entities.plugin import ModelProviderID, PluginDependency, PluginInstallationSource, ToolProviderID
from core.plugin.manager.plugin import PluginInstallationManager
from core.plugin.impl.plugin import PluginInstaller
class DependenciesAnalysisService:
@@ -38,7 +38,7 @@ class DependenciesAnalysisService:
for dependency in dependencies:
required_plugin_unique_identifiers.append(dependency.value.plugin_unique_identifier)
manager = PluginInstallationManager()
manager = PluginInstaller()
# get leaked dependencies
missing_plugins = manager.fetch_missing_dependencies(tenant_id, required_plugin_unique_identifiers)
@@ -64,7 +64,7 @@ class DependenciesAnalysisService:
Generate dependencies through the list of plugin ids
"""
dependencies = list(set(dependencies))
manager = PluginInstallationManager()
manager = PluginInstaller()
plugins = manager.fetch_plugin_installation_by_ids(tenant_id, dependencies)
result = []
for plugin in plugins:

View File

@@ -1,10 +1,10 @@
from core.plugin.manager.endpoint import PluginEndpointManager
from core.plugin.impl.endpoint import PluginEndpointClient
class EndpointService:
@classmethod
def create_endpoint(cls, tenant_id: str, user_id: str, plugin_unique_identifier: str, name: str, settings: dict):
return PluginEndpointManager().create_endpoint(
return PluginEndpointClient().create_endpoint(
tenant_id=tenant_id,
user_id=user_id,
plugin_unique_identifier=plugin_unique_identifier,
@@ -14,7 +14,7 @@ class EndpointService:
@classmethod
def list_endpoints(cls, tenant_id: str, user_id: str, page: int, page_size: int):
return PluginEndpointManager().list_endpoints(
return PluginEndpointClient().list_endpoints(
tenant_id=tenant_id,
user_id=user_id,
page=page,
@@ -23,7 +23,7 @@ class EndpointService:
@classmethod
def list_endpoints_for_single_plugin(cls, tenant_id: str, user_id: str, plugin_id: str, page: int, page_size: int):
return PluginEndpointManager().list_endpoints_for_single_plugin(
return PluginEndpointClient().list_endpoints_for_single_plugin(
tenant_id=tenant_id,
user_id=user_id,
plugin_id=plugin_id,
@@ -33,7 +33,7 @@ class EndpointService:
@classmethod
def update_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict):
return PluginEndpointManager().update_endpoint(
return PluginEndpointClient().update_endpoint(
tenant_id=tenant_id,
user_id=user_id,
endpoint_id=endpoint_id,
@@ -43,7 +43,7 @@ class EndpointService:
@classmethod
def delete_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
return PluginEndpointManager().delete_endpoint(
return PluginEndpointClient().delete_endpoint(
tenant_id=tenant_id,
user_id=user_id,
endpoint_id=endpoint_id,
@@ -51,7 +51,7 @@ class EndpointService:
@classmethod
def enable_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
return PluginEndpointManager().enable_endpoint(
return PluginEndpointClient().enable_endpoint(
tenant_id=tenant_id,
user_id=user_id,
endpoint_id=endpoint_id,
@@ -59,7 +59,7 @@ class EndpointService:
@classmethod
def disable_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
return PluginEndpointManager().disable_endpoint(
return PluginEndpointClient().disable_endpoint(
tenant_id=tenant_id,
user_id=user_id,
endpoint_id=endpoint_id,

View File

@@ -0,0 +1,7 @@
from core.plugin.impl.base import BasePluginClient
class OAuthService(BasePluginClient):
@classmethod
def get_authorization_url(cls, tenant_id: str, user_id: str, provider_name: str) -> str:
return "1234567890"

View File

@@ -17,7 +17,7 @@ from core.agent.entities import AgentToolEntity
from core.helper import marketplace
from core.plugin.entities.plugin import ModelProviderID, PluginInstallationSource, ToolProviderID
from core.plugin.entities.plugin_daemon import PluginInstallTaskStatus
from core.plugin.manager.plugin import PluginInstallationManager
from core.plugin.impl.plugin import PluginInstaller
from core.tools.entities.tool_entities import ToolProviderType
from models.account import Tenant
from models.engine import db
@@ -331,7 +331,7 @@ class PluginMigration:
"""
Install plugins.
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
plugins = cls.extract_unique_plugins(extracted_plugins)
not_installed = []
@@ -426,7 +426,7 @@ class PluginMigration:
"""
Install plugins for a tenant.
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
# download all the plugins and upload
thread_pool = ThreadPoolExecutor(max_workers=10)

View File

@@ -18,9 +18,9 @@ from core.plugin.entities.plugin import (
PluginInstallationSource,
)
from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginUploadResponse
from core.plugin.manager.asset import PluginAssetManager
from core.plugin.manager.debugging import PluginDebuggingManager
from core.plugin.manager.plugin import PluginInstallationManager
from core.plugin.impl.asset import PluginAssetManager
from core.plugin.impl.debugging import PluginDebuggingClient
from core.plugin.impl.plugin import PluginInstaller
from extensions.ext_redis import redis_client
logger = logging.getLogger(__name__)
@@ -91,7 +91,7 @@ class PluginService:
"""
get the debugging key of the tenant
"""
manager = PluginDebuggingManager()
manager = PluginDebuggingClient()
return manager.get_debugging_key(tenant_id)
@staticmethod
@@ -106,7 +106,7 @@ class PluginService:
"""
list all plugins of the tenant
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
plugins = manager.list_plugins(tenant_id)
return plugins
@@ -115,7 +115,7 @@ class PluginService:
"""
List plugin installations from ids
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.fetch_plugin_installation_by_ids(tenant_id, ids)
@staticmethod
@@ -133,7 +133,7 @@ class PluginService:
"""
check if the plugin unique identifier is already installed by other tenant
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.fetch_plugin_by_identifier(tenant_id, plugin_unique_identifier)
@staticmethod
@@ -141,7 +141,7 @@ class PluginService:
"""
Fetch plugin manifest
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.fetch_plugin_manifest(tenant_id, plugin_unique_identifier)
@staticmethod
@@ -149,12 +149,12 @@ class PluginService:
"""
Fetch plugin installation tasks
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.fetch_plugin_installation_tasks(tenant_id, page, page_size)
@staticmethod
def fetch_install_task(tenant_id: str, task_id: str) -> PluginInstallTask:
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.fetch_plugin_installation_task(tenant_id, task_id)
@staticmethod
@@ -162,7 +162,7 @@ class PluginService:
"""
Delete a plugin installation task
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.delete_plugin_installation_task(tenant_id, task_id)
@staticmethod
@@ -172,7 +172,7 @@ class PluginService:
"""
Delete all plugin installation task items
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.delete_all_plugin_installation_task_items(tenant_id)
@staticmethod
@@ -180,7 +180,7 @@ class PluginService:
"""
Delete a plugin installation task item
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.delete_plugin_installation_task_item(tenant_id, task_id, identifier)
@staticmethod
@@ -197,7 +197,7 @@ class PluginService:
raise ValueError("you should not upgrade plugin with the same plugin")
# check if plugin pkg is already downloaded
manager = PluginInstallationManager()
manager = PluginInstaller()
try:
manager.fetch_plugin_manifest(tenant_id, new_plugin_unique_identifier)
@@ -230,7 +230,7 @@ class PluginService:
"""
Upgrade plugin with github
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.upgrade_plugin(
tenant_id,
original_plugin_unique_identifier,
@@ -250,7 +250,7 @@ class PluginService:
returns: plugin_unique_identifier
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.upload_pkg(tenant_id, pkg, verify_signature)
@staticmethod
@@ -265,7 +265,7 @@ class PluginService:
f"https://github.com/{repo}/releases/download/{version}/{package}", dify_config.PLUGIN_MAX_PACKAGE_SIZE
)
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.upload_pkg(
tenant_id,
pkg,
@@ -279,12 +279,12 @@ class PluginService:
"""
Upload a plugin bundle and return the dependencies.
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.upload_bundle(tenant_id, bundle, verify_signature)
@staticmethod
def install_from_local_pkg(tenant_id: str, plugin_unique_identifiers: Sequence[str]):
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.install_from_identifiers(
tenant_id,
plugin_unique_identifiers,
@@ -298,7 +298,7 @@ class PluginService:
Install plugin from github release package files,
returns plugin_unique_identifier
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.install_from_identifiers(
tenant_id,
[plugin_unique_identifier],
@@ -322,7 +322,7 @@ class PluginService:
if not dify_config.MARKETPLACE_ENABLED:
raise ValueError("marketplace is not enabled")
manager = PluginInstallationManager()
manager = PluginInstaller()
try:
declaration = manager.fetch_plugin_manifest(tenant_id, plugin_unique_identifier)
except Exception:
@@ -342,7 +342,7 @@ class PluginService:
if not dify_config.MARKETPLACE_ENABLED:
raise ValueError("marketplace is not enabled")
manager = PluginInstallationManager()
manager = PluginInstaller()
# check if already downloaded
for plugin_unique_identifier in plugin_unique_identifiers:
@@ -368,7 +368,7 @@ class PluginService:
@staticmethod
def uninstall(tenant_id: str, plugin_installation_id: str) -> bool:
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.uninstall(tenant_id, plugin_installation_id)
@staticmethod
@@ -376,5 +376,5 @@ class PluginService:
"""
Check if the tools exist
"""
manager = PluginInstallationManager()
manager = PluginInstaller()
return manager.check_tools_existence(tenant_id, provider_ids)