選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

plugin_daemon.py 5.4KB

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