You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin_daemon.py 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. from collections.abc import Mapping, Sequence
  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.model_runtime.entities.model_entities import AIModelEntity
  8. from core.model_runtime.entities.provider_entities import ProviderEntity
  9. from core.plugin.entities.base import BasePluginEntity
  10. from core.plugin.entities.parameters import PluginParameterOption
  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 PluginAgentProviderEntity(BaseModel):
  38. provider: str
  39. plugin_unique_identifier: str
  40. plugin_id: str
  41. declaration: AgentProviderEntityWithPlugin
  42. meta: PluginDeclaration.Meta
  43. class PluginBasicBooleanResponse(BaseModel):
  44. """
  45. Basic boolean response from plugin daemon.
  46. """
  47. result: bool
  48. credentials: dict | None = None
  49. class PluginModelSchemaEntity(BaseModel):
  50. model_schema: AIModelEntity = Field(description="The model schema.")
  51. # pydantic configs
  52. model_config = ConfigDict(protected_namespaces=())
  53. class PluginModelProviderEntity(BaseModel):
  54. id: str = Field(description="ID")
  55. created_at: datetime = Field(description="The created at time of the model provider.")
  56. updated_at: datetime = Field(description="The updated at time of the model provider.")
  57. provider: str = Field(description="The provider of the model.")
  58. tenant_id: str = Field(description="The tenant ID.")
  59. plugin_unique_identifier: str = Field(description="The plugin unique identifier.")
  60. plugin_id: str = Field(description="The plugin ID.")
  61. declaration: ProviderEntity = Field(description="The declaration of the model provider.")
  62. class PluginTextEmbeddingNumTokensResponse(BaseModel):
  63. """
  64. Response for number of tokens.
  65. """
  66. num_tokens: list[int] = Field(description="The number of tokens.")
  67. class PluginLLMNumTokensResponse(BaseModel):
  68. """
  69. Response for number of tokens.
  70. """
  71. num_tokens: int = Field(description="The number of tokens.")
  72. class PluginStringResultResponse(BaseModel):
  73. result: str = Field(description="The result of the string.")
  74. class PluginVoiceEntity(BaseModel):
  75. name: str = Field(description="The name of the voice.")
  76. value: str = Field(description="The value of the voice.")
  77. class PluginVoicesResponse(BaseModel):
  78. voices: list[PluginVoiceEntity] = Field(description="The result of the voices.")
  79. class PluginDaemonError(BaseModel):
  80. """
  81. Error from plugin daemon.
  82. """
  83. error_type: str
  84. message: str
  85. class PluginDaemonInnerError(Exception):
  86. code: int
  87. message: str
  88. def __init__(self, code: int, message: str):
  89. self.code = code
  90. self.message = message
  91. class PluginInstallTaskStatus(StrEnum):
  92. Pending = "pending"
  93. Running = "running"
  94. Success = "success"
  95. Failed = "failed"
  96. class PluginInstallTaskPluginStatus(BaseModel):
  97. plugin_unique_identifier: str = Field(description="The plugin unique identifier of the install task.")
  98. plugin_id: str = Field(description="The plugin ID of the install task.")
  99. status: PluginInstallTaskStatus = Field(description="The status of the install task.")
  100. message: str = Field(description="The message of the install task.")
  101. icon: str = Field(description="The icon of the plugin.")
  102. labels: I18nObject = Field(description="The labels of the plugin.")
  103. class PluginInstallTask(BasePluginEntity):
  104. status: PluginInstallTaskStatus = Field(description="The status of the install task.")
  105. total_plugins: int = Field(description="The total number of plugins to be installed.")
  106. completed_plugins: int = Field(description="The number of plugins that have been installed.")
  107. plugins: list[PluginInstallTaskPluginStatus] = Field(description="The status of the plugins.")
  108. class PluginInstallTaskStartResponse(BaseModel):
  109. all_installed: bool = Field(description="Whether all plugins are installed.")
  110. task_id: str = Field(description="The ID of the install task.")
  111. class PluginVerification(BaseModel):
  112. """
  113. Verification of the plugin.
  114. """
  115. class AuthorizedCategory(StrEnum):
  116. Langgenius = "langgenius"
  117. Partner = "partner"
  118. Community = "community"
  119. authorized_category: AuthorizedCategory = Field(description="The authorized category of the plugin.")
  120. class PluginDecodeResponse(BaseModel):
  121. unique_identifier: str = Field(description="The unique identifier of the plugin.")
  122. manifest: PluginDeclaration
  123. verification: Optional[PluginVerification] = Field(default=None, description="Basic verification information")
  124. class PluginOAuthAuthorizationUrlResponse(BaseModel):
  125. authorization_url: str = Field(description="The URL of the authorization.")
  126. class PluginOAuthCredentialsResponse(BaseModel):
  127. credentials: Mapping[str, Any] = Field(description="The credentials of the OAuth.")
  128. class PluginListResponse(BaseModel):
  129. list: list[PluginEntity]
  130. total: int
  131. class PluginDynamicSelectOptionsResponse(BaseModel):
  132. options: Sequence[PluginParameterOption] = Field(description="The options of the dynamic select.")