marketplace.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from typing import Optional
  2. from pydantic import BaseModel, Field, model_validator
  3. from core.model_runtime.entities.provider_entities import ProviderEntity
  4. from core.plugin.entities.endpoint import EndpointProviderDeclaration
  5. from core.plugin.entities.plugin import PluginResourceRequirements
  6. from core.tools.entities.common_entities import I18nObject
  7. from core.tools.entities.tool_entities import ToolProviderEntity
  8. class MarketplacePluginDeclaration(BaseModel):
  9. name: str = Field(..., description="Unique identifier for the plugin within the marketplace")
  10. org: str = Field(..., description="Organization or developer responsible for creating and maintaining the plugin")
  11. plugin_id: str = Field(..., description="Globally unique identifier for the plugin across all marketplaces")
  12. icon: str = Field(..., description="URL or path to the plugin's visual representation")
  13. label: I18nObject = Field(..., description="Localized display name for the plugin in different languages")
  14. brief: I18nObject = Field(..., description="Short, localized description of the plugin's functionality")
  15. resource: PluginResourceRequirements = Field(
  16. ..., description="Specification of computational resources needed to run the plugin"
  17. )
  18. endpoint: Optional[EndpointProviderDeclaration] = Field(
  19. None, description="Configuration for the plugin's API endpoint, if applicable"
  20. )
  21. model: Optional[ProviderEntity] = Field(None, description="Details of the AI model used by the plugin, if any")
  22. tool: Optional[ToolProviderEntity] = Field(
  23. None, description="Information about the tool functionality provided by the plugin, if any"
  24. )
  25. latest_version: str = Field(
  26. ..., description="Most recent version number of the plugin available in the marketplace"
  27. )
  28. latest_package_identifier: str = Field(
  29. ..., description="Unique identifier for the latest package release of the plugin"
  30. )
  31. status: str = Field(..., description="Indicate the status of marketplace plugin, enum from `active` `deleted`")
  32. deprecated_reason: str = Field(
  33. ..., description="Not empty when status='deleted', indicates the reason why this plugin is deleted(deprecated)"
  34. )
  35. alternative_plugin_id: str = Field(
  36. ..., description="Optional, indicates the alternative plugin for user to switch to"
  37. )
  38. @model_validator(mode="before")
  39. @classmethod
  40. def transform_declaration(cls, data: dict):
  41. if "endpoint" in data and not data["endpoint"]:
  42. del data["endpoint"]
  43. if "model" in data and not data["model"]:
  44. del data["model"]
  45. if "tool" in data and not data["tool"]:
  46. del data["tool"]
  47. return data