| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | from datetime import datetimefrom typing import Optionalfrom pydantic import BaseModel, Field, model_validatorfrom configs import dify_configfrom core.entities.provider_entities import ProviderConfigfrom core.plugin.entities.base import BasePluginEntityclass EndpointDeclaration(BaseModel):    """    declaration of an endpoint    """    path: str    method: str    hidden: bool = Field(default=False)class EndpointProviderDeclaration(BaseModel):    """    declaration of an endpoint group    """    settings: list[ProviderConfig] = Field(default_factory=list)    endpoints: Optional[list[EndpointDeclaration]] = Field(default_factory=list)class EndpointEntity(BasePluginEntity):    """    entity of an endpoint    """    settings: dict    tenant_id: str    plugin_id: str    expired_at: datetime    declaration: EndpointProviderDeclaration = Field(default_factory=EndpointProviderDeclaration)class EndpointEntityWithInstance(EndpointEntity):    name: str    enabled: bool    url: str    hook_id: str    @model_validator(mode="before")    @classmethod    def render_url_template(cls, values):        if "url" not in values:            url_template = dify_config.ENDPOINT_URL_TEMPLATE            values["url"] = url_template.replace("{hook_id}", values["hook_id"])        return values
 |