2024-09-29 00:13:53 +08:00
|
|
|
from datetime import datetime
|
2024-09-20 21:35:19 +08:00
|
|
|
from enum import Enum
|
2024-09-20 14:43:01 +08:00
|
|
|
from typing import Generic, Optional, TypeVar
|
|
|
|
|
2024-09-29 00:13:53 +08:00
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
2024-09-20 14:43:01 +08:00
|
|
|
|
2024-09-29 00:13:53 +08:00
|
|
|
from core.model_runtime.entities.model_entities import AIModelEntity
|
|
|
|
from core.model_runtime.entities.provider_entities import ProviderEntity
|
2024-10-14 17:52:29 +08:00
|
|
|
from core.plugin.entities.base import BasePluginEntity
|
2024-09-23 18:06:16 +08:00
|
|
|
from core.tools.entities.tool_entities import ToolProviderEntityWithPlugin
|
|
|
|
|
2024-10-14 17:52:29 +08:00
|
|
|
T = TypeVar("T", bound=(BaseModel | dict | list | bool | str))
|
2024-09-20 14:43:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PluginDaemonBasicResponse(BaseModel, Generic[T]):
|
|
|
|
"""
|
|
|
|
Basic response from plugin daemon.
|
|
|
|
"""
|
|
|
|
|
|
|
|
code: int
|
|
|
|
message: str
|
|
|
|
data: Optional[T]
|
2024-09-20 21:35:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
class InstallPluginMessage(BaseModel):
|
|
|
|
"""
|
|
|
|
Message for installing a plugin.
|
|
|
|
"""
|
2024-09-29 00:13:53 +08:00
|
|
|
|
2024-09-20 21:35:19 +08:00
|
|
|
class Event(Enum):
|
|
|
|
Info = "info"
|
|
|
|
Done = "done"
|
|
|
|
Error = "error"
|
|
|
|
|
|
|
|
event: Event
|
2024-09-23 18:06:16 +08:00
|
|
|
data: str
|
|
|
|
|
|
|
|
|
|
|
|
class PluginToolProviderEntity(BaseModel):
|
|
|
|
provider: str
|
|
|
|
plugin_unique_identifier: str
|
|
|
|
plugin_id: str
|
2024-09-23 21:13:02 +08:00
|
|
|
declaration: ToolProviderEntityWithPlugin
|
|
|
|
|
|
|
|
|
|
|
|
class PluginBasicBooleanResponse(BaseModel):
|
|
|
|
"""
|
|
|
|
Basic boolean response from plugin daemon.
|
|
|
|
"""
|
2024-09-29 00:13:53 +08:00
|
|
|
|
|
|
|
result: bool
|
|
|
|
|
|
|
|
|
|
|
|
class PluginModelSchemaEntity(BaseModel):
|
|
|
|
model_schema: AIModelEntity = Field(description="The model schema.")
|
|
|
|
|
|
|
|
# pydantic configs
|
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
|
|
|
|
|
|
|
class PluginModelProviderEntity(BaseModel):
|
2024-09-30 17:46:31 +08:00
|
|
|
id: str = Field(description="ID")
|
|
|
|
created_at: datetime = Field(description="The created at time of the model provider.")
|
|
|
|
updated_at: datetime = Field(description="The updated at time of the model provider.")
|
2024-09-29 00:13:53 +08:00
|
|
|
provider: str = Field(description="The provider of the model.")
|
|
|
|
tenant_id: str = Field(description="The tenant ID.")
|
|
|
|
plugin_unique_identifier: str = Field(description="The plugin unique identifier.")
|
|
|
|
plugin_id: str = Field(description="The plugin ID.")
|
|
|
|
declaration: ProviderEntity = Field(description="The declaration of the model provider.")
|
|
|
|
|
|
|
|
|
|
|
|
class PluginNumTokensResponse(BaseModel):
|
|
|
|
"""
|
|
|
|
Response for number of tokens.
|
|
|
|
"""
|
|
|
|
|
|
|
|
num_tokens: int = Field(description="The number of tokens.")
|
|
|
|
|
|
|
|
|
|
|
|
class PluginStringResultResponse(BaseModel):
|
|
|
|
result: str = Field(description="The result of the string.")
|
|
|
|
|
|
|
|
|
|
|
|
class PluginVoiceEntity(BaseModel):
|
|
|
|
name: str = Field(description="The name of the voice.")
|
|
|
|
value: str = Field(description="The value of the voice.")
|
|
|
|
|
|
|
|
|
|
|
|
class PluginVoicesResponse(BaseModel):
|
|
|
|
voices: list[PluginVoiceEntity] = Field(description="The result of the voices.")
|
2024-09-29 13:12:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PluginDaemonError(BaseModel):
|
|
|
|
"""
|
|
|
|
Error from plugin daemon.
|
|
|
|
"""
|
|
|
|
|
|
|
|
error_type: str
|
|
|
|
message: str
|
|
|
|
args: Optional[dict] = None
|
|
|
|
|
|
|
|
|
|
|
|
class PluginDaemonInnerError(Exception):
|
|
|
|
code: int
|
|
|
|
message: str
|
|
|
|
|
|
|
|
def __init__(self, code: int, message: str):
|
|
|
|
self.code = code
|
|
|
|
self.message = message
|
2024-10-14 17:52:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PluginInstallTaskStatus(str, Enum):
|
|
|
|
Pending = "pending"
|
|
|
|
Running = "running"
|
|
|
|
Success = "success"
|
|
|
|
Failed = "failed"
|
|
|
|
|
|
|
|
|
|
|
|
class PluginInstallTaskPluginStatus(BaseModel):
|
|
|
|
plugin_unique_identifier: str = Field(description="The plugin unique identifier of the install task.")
|
|
|
|
plugin_id: str = Field(description="The plugin ID of the install task.")
|
|
|
|
status: PluginInstallTaskStatus = Field(description="The status of the install task.")
|
|
|
|
message: str = Field(description="The message of the install task.")
|
|
|
|
|
|
|
|
|
|
|
|
class PluginInstallTask(BasePluginEntity):
|
|
|
|
status: PluginInstallTaskStatus = Field(description="The status of the install task.")
|
|
|
|
total_plugins: int = Field(description="The total number of plugins to be installed.")
|
|
|
|
completed_plugins: int = Field(description="The number of plugins that have been installed.")
|
|
|
|
plugins: list[PluginInstallTaskPluginStatus] = Field(description="The status of the plugins.")
|