plugin_daemon.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. from datetime import datetime
  2. from enum import Enum
  3. from typing import Generic, Optional, TypeVar
  4. from pydantic import BaseModel, ConfigDict, Field
  5. from core.model_runtime.entities.model_entities import AIModelEntity
  6. from core.model_runtime.entities.provider_entities import ProviderEntity
  7. from core.plugin.entities.base import BasePluginEntity
  8. from core.plugin.entities.plugin import PluginDeclaration
  9. from core.tools.entities.tool_entities import ToolProviderEntityWithPlugin
  10. T = TypeVar("T", bound=(BaseModel | dict | list | bool | str))
  11. class PluginDaemonBasicResponse(BaseModel, Generic[T]):
  12. """
  13. Basic response from plugin daemon.
  14. """
  15. code: int
  16. message: str
  17. data: Optional[T]
  18. class InstallPluginMessage(BaseModel):
  19. """
  20. Message for installing a plugin.
  21. """
  22. class Event(Enum):
  23. Info = "info"
  24. Done = "done"
  25. Error = "error"
  26. event: Event
  27. data: str
  28. class PluginToolProviderEntity(BaseModel):
  29. provider: str
  30. plugin_unique_identifier: str
  31. plugin_id: str
  32. declaration: ToolProviderEntityWithPlugin
  33. class PluginBasicBooleanResponse(BaseModel):
  34. """
  35. Basic boolean response from plugin daemon.
  36. """
  37. result: bool
  38. class PluginModelSchemaEntity(BaseModel):
  39. model_schema: AIModelEntity = Field(description="The model schema.")
  40. # pydantic configs
  41. model_config = ConfigDict(protected_namespaces=())
  42. class PluginModelProviderEntity(BaseModel):
  43. id: str = Field(description="ID")
  44. created_at: datetime = Field(description="The created at time of the model provider.")
  45. updated_at: datetime = Field(description="The updated at time of the model provider.")
  46. provider: str = Field(description="The provider of the model.")
  47. tenant_id: str = Field(description="The tenant ID.")
  48. plugin_unique_identifier: str = Field(description="The plugin unique identifier.")
  49. plugin_id: str = Field(description="The plugin ID.")
  50. declaration: ProviderEntity = Field(description="The declaration of the model provider.")
  51. class PluginNumTokensResponse(BaseModel):
  52. """
  53. Response for number of tokens.
  54. """
  55. num_tokens: int = Field(description="The number of tokens.")
  56. class PluginStringResultResponse(BaseModel):
  57. result: str = Field(description="The result of the string.")
  58. class PluginVoiceEntity(BaseModel):
  59. name: str = Field(description="The name of the voice.")
  60. value: str = Field(description="The value of the voice.")
  61. class PluginVoicesResponse(BaseModel):
  62. voices: list[PluginVoiceEntity] = Field(description="The result of the voices.")
  63. class PluginDaemonError(BaseModel):
  64. """
  65. Error from plugin daemon.
  66. """
  67. error_type: str
  68. message: str
  69. args: Optional[dict] = None
  70. class PluginDaemonInnerError(Exception):
  71. code: int
  72. message: str
  73. def __init__(self, code: int, message: str):
  74. self.code = code
  75. self.message = message
  76. class PluginInstallTaskStatus(str, Enum):
  77. Pending = "pending"
  78. Running = "running"
  79. Success = "success"
  80. Failed = "failed"
  81. class PluginInstallTaskPluginStatus(BaseModel):
  82. plugin_unique_identifier: str = Field(description="The plugin unique identifier of the install task.")
  83. plugin_id: str = Field(description="The plugin ID of the install task.")
  84. status: PluginInstallTaskStatus = Field(description="The status of the install task.")
  85. message: str = Field(description="The message of the install task.")
  86. class PluginInstallTask(BasePluginEntity):
  87. status: PluginInstallTaskStatus = Field(description="The status of the install task.")
  88. total_plugins: int = Field(description="The total number of plugins to be installed.")
  89. completed_plugins: int = Field(description="The number of plugins that have been installed.")
  90. plugins: list[PluginInstallTaskPluginStatus] = Field(description="The status of the plugins.")
  91. class PluginInstallTaskStartResponse(BaseModel):
  92. all_installed: bool = Field(description="Whether all plugins are installed.")
  93. task_id: str = Field(description="The ID of the install task.")
  94. class PluginUploadResponse(BaseModel):
  95. unique_identifier: str = Field(description="The unique identifier of the plugin.")
  96. manifest: PluginDeclaration