Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

plugin_daemon.py 5.1KB

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