Explorar el Código

feat: support endpoint url template

Yeuoly hace 8 meses
padre
commit
dfaf639790
Se han modificado 2 ficheros con 16 adiciones y 1 borrados
  1. 4 0
      api/configs/feature/__init__.py
  2. 12 1
      api/core/plugin/entities/endpoint.py

+ 4 - 0
api/configs/feature/__init__.py

@@ -164,6 +164,10 @@ class EndpointConfig(BaseSettings):
         default="",
     )
 
+    ENDPOINT_URL_TEMPLATE: str = Field(
+        description="Template url for endpoint plugin", default="http://localhost:5002/e/{hook_id}"
+    )
+
 
 class FileAccessConfig(BaseSettings):
     """

+ 12 - 1
api/core/plugin/entities/endpoint.py

@@ -1,7 +1,8 @@
 from datetime import datetime
 
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, Field, model_validator
 
+from configs import dify_config
 from core.entities.provider_entities import ProviderConfig
 from core.plugin.entities.base import BasePluginEntity
 
@@ -21,8 +22,18 @@ class EndpointEntity(BasePluginEntity):
 
     settings: dict
     name: str
+    enabled: bool
+    url: str
     hook_id: str
     tenant_id: str
     plugin_id: str
     expired_at: datetime
     declaration: EndpointDeclaration = Field(default_factory=EndpointDeclaration)
+
+    @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