feat: support install plugin
parent
56b7853afe
commit
e27a03ae15
@ -1,10 +1,77 @@
|
||||
import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from core.model_runtime.entities.provider_entities import ProviderEntity
|
||||
from core.plugin.entities.base import BasePluginEntity
|
||||
from core.plugin.entities.endpoint import EndpointEntity
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.entities.tool_entities import ToolProviderEntity
|
||||
|
||||
|
||||
class PluginResourceRequirements(BaseModel):
|
||||
memory: int
|
||||
|
||||
class Permission(BaseModel):
|
||||
class Tool(BaseModel):
|
||||
enabled: Optional[bool] = Field(default=False)
|
||||
|
||||
class Model(BaseModel):
|
||||
enabled: Optional[bool] = Field(default=False)
|
||||
llm: Optional[bool] = Field(default=False)
|
||||
text_embedding: Optional[bool] = Field(default=False)
|
||||
rerank: Optional[bool] = Field(default=False)
|
||||
tts: Optional[bool] = Field(default=False)
|
||||
speech2text: Optional[bool] = Field(default=False)
|
||||
moderation: Optional[bool] = Field(default=False)
|
||||
|
||||
class Node(BaseModel):
|
||||
enabled: Optional[bool] = Field(default=False)
|
||||
|
||||
class Endpoint(BaseModel):
|
||||
enabled: Optional[bool] = Field(default=False)
|
||||
|
||||
class Storage(BaseModel):
|
||||
enabled: Optional[bool] = Field(default=False)
|
||||
size: int = Field(ge=1024, le=1073741824, default=1048576)
|
||||
|
||||
tool: Optional[Tool] = Field(default=None)
|
||||
model: Optional[Model] = Field(default=None)
|
||||
node: Optional[Node] = Field(default=None)
|
||||
endpoint: Optional[Endpoint] = Field(default=None)
|
||||
storage: Storage = Field(default=None)
|
||||
|
||||
permission: Optional[Permission]
|
||||
|
||||
|
||||
class PluginDeclaration(BaseModel):
|
||||
class Plugins(BaseModel):
|
||||
tools: list[str] = Field(default_factory=list)
|
||||
models: list[str] = Field(default_factory=list)
|
||||
endpoints: list[str] = Field(default_factory=list)
|
||||
|
||||
version: str = Field(..., pattern=r"^\d{1,4}(\.\d{1,4}){1,3}(-\w{1,16})?$")
|
||||
author: Optional[str] = Field(..., pattern=r"^[a-zA-Z0-9_-]{1,64}$")
|
||||
name: str = Field(..., pattern=r"^[a-z0-9_-]{1,128}$")
|
||||
icon: str
|
||||
label: I18nObject
|
||||
created_at: datetime.datetime
|
||||
resource: PluginResourceRequirements
|
||||
plugins: Plugins
|
||||
tool: Optional[ToolProviderEntity] = None
|
||||
model: Optional[ProviderEntity] = None
|
||||
endpoint: Optional[EndpointEntity] = None
|
||||
|
||||
|
||||
class PluginEntity(BasePluginEntity):
|
||||
name: str
|
||||
plugin_id: str
|
||||
plugin_unique_identifier: str
|
||||
declaration: PluginDeclaration
|
||||
installation_id: str
|
||||
tenant_id: str
|
||||
endpoints_setups: int
|
||||
endpoints_active: int
|
||||
runtime_type: str
|
||||
version: str
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
from core.plugin.manager.debugging import PluginDebuggingManager
|
||||
|
||||
|
||||
class PluginDebuggingService:
|
||||
@staticmethod
|
||||
def get_plugin_debugging_key(tenant_id: str) -> str:
|
||||
manager = PluginDebuggingManager()
|
||||
return manager.get_debugging_key(tenant_id)
|
||||
@ -0,0 +1,45 @@
|
||||
from collections.abc import Generator
|
||||
from mimetypes import guess_type
|
||||
|
||||
from core.plugin.entities.plugin import PluginEntity
|
||||
from core.plugin.entities.plugin_daemon import InstallPluginMessage, PluginDaemonInnerError
|
||||
from core.plugin.manager.asset import PluginAssetManager
|
||||
from core.plugin.manager.debugging import PluginDebuggingManager
|
||||
from core.plugin.manager.plugin import PluginInstallationManager
|
||||
|
||||
|
||||
class PluginService:
|
||||
@staticmethod
|
||||
def get_plugin_debugging_key(tenant_id: str) -> str:
|
||||
manager = PluginDebuggingManager()
|
||||
return manager.get_debugging_key(tenant_id)
|
||||
|
||||
@staticmethod
|
||||
def list_plugins(tenant_id: str) -> list[PluginEntity]:
|
||||
manager = PluginInstallationManager()
|
||||
return manager.list_plugins(tenant_id)
|
||||
|
||||
@staticmethod
|
||||
def get_asset(tenant_id: str, asset_file: str) -> tuple[bytes, str]:
|
||||
manager = PluginAssetManager()
|
||||
# guess mime type
|
||||
mime_type, _ = guess_type(asset_file)
|
||||
return manager.fetch_asset(tenant_id, asset_file), mime_type or "application/octet-stream"
|
||||
|
||||
@staticmethod
|
||||
def check_plugin_unique_identifier(tenant_id: str, plugin_unique_identifier: str) -> bool:
|
||||
manager = PluginInstallationManager()
|
||||
return manager.fetch_plugin_by_identifier(tenant_id, plugin_unique_identifier)
|
||||
|
||||
@staticmethod
|
||||
def install_plugin_from_unique_identifier(tenant_id: str, plugin_unique_identifier: str) -> bool:
|
||||
manager = PluginInstallationManager()
|
||||
return manager.install_from_identifier(tenant_id, plugin_unique_identifier)
|
||||
|
||||
@staticmethod
|
||||
def install_plugin_from_pkg(tenant_id: str, pkg: bytes) -> Generator[InstallPluginMessage, None, None]:
|
||||
manager = PluginInstallationManager()
|
||||
try:
|
||||
yield from manager.install_from_pkg(tenant_id, pkg)
|
||||
except PluginDaemonInnerError as e:
|
||||
yield InstallPluginMessage(event=InstallPluginMessage.Event.Error, data=str(e.message))
|
||||
Loading…
Reference in New Issue