浏览代码

refactor: add manifest into upload interfaces

Yeuoly 7 月之前
父节点
当前提交
7b62b5578e

+ 6 - 7
api/controllers/console/workspace/plugin.py

@@ -69,7 +69,8 @@ class PluginUploadPkgApi(Resource):
         tenant_id = user.current_tenant_id
         file = request.files["pkg"]
         content = file.read()
-        return {"plugin_unique_identifier": PluginService.upload_pkg(tenant_id, content)}
+
+        return jsonable_encoder(PluginService.upload_pkg(tenant_id, content))
 
 
 class PluginUploadFromPkgApi(Resource):
@@ -92,9 +93,7 @@ class PluginUploadFromPkgApi(Resource):
         content = file.read()
         response = PluginService.upload_pkg(tenant_id, content)
 
-        return {
-            "plugin_unique_identifier": response,
-        }
+        return jsonable_encoder(response)
 
 
 class PluginUploadFromGithubApi(Resource):
@@ -143,7 +142,7 @@ class PluginInstallFromPkgApi(Resource):
 
         response = PluginService.install_from_local_pkg(tenant_id, args["plugin_unique_identifiers"])
 
-        return response.model_dump()
+        return jsonable_encoder(response)
 
 
 class PluginInstallFromGithubApi(Resource):
@@ -172,7 +171,7 @@ class PluginInstallFromGithubApi(Resource):
             args["package"],
         )
 
-        return response.model_dump()
+        return jsonable_encoder(response)
 
 
 class PluginInstallFromMarketplaceApi(Resource):
@@ -197,7 +196,7 @@ class PluginInstallFromMarketplaceApi(Resource):
 
         response = PluginService.install_from_marketplace_pkg(tenant_id, args["plugin_unique_identifiers"])
 
-        return response.model_dump()
+        return jsonable_encoder(response)
 
 
 class PluginFetchManifestApi(Resource):

+ 6 - 0
api/core/plugin/entities/plugin_daemon.py

@@ -7,6 +7,7 @@ from pydantic import BaseModel, ConfigDict, Field
 from core.model_runtime.entities.model_entities import AIModelEntity
 from core.model_runtime.entities.provider_entities import ProviderEntity
 from core.plugin.entities.base import BasePluginEntity
+from core.plugin.entities.plugin import PluginDeclaration
 from core.tools.entities.tool_entities import ToolProviderEntityWithPlugin
 
 T = TypeVar("T", bound=(BaseModel | dict | list | bool | str))
@@ -133,3 +134,8 @@ class PluginInstallTask(BasePluginEntity):
 class PluginInstallTaskStartResponse(BaseModel):
     all_installed: bool = Field(description="Whether all plugins are installed.")
     task_id: str = Field(description="The ID of the install task.")
+
+
+class PluginUploadResponse(BaseModel):
+    unique_identifier: str = Field(description="The unique identifier of the plugin.")
+    manifest: PluginDeclaration

+ 3 - 3
api/core/plugin/manager/plugin.py

@@ -3,7 +3,7 @@ from collections.abc import Sequence
 from pydantic import BaseModel
 
 from core.plugin.entities.plugin import PluginDeclaration, PluginEntity, PluginInstallationSource
-from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginInstallTaskStartResponse
+from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginInstallTaskStartResponse, PluginUploadResponse
 from core.plugin.manager.base import BasePluginManager
 
 
@@ -33,7 +33,7 @@ class PluginInstallationManager(BasePluginManager):
         tenant_id: str,
         pkg: bytes,
         verify_signature: bool = False,
-    ) -> str:
+    ) -> PluginUploadResponse:
         """
         Upload a plugin package and return the plugin unique identifier.
         """
@@ -48,7 +48,7 @@ class PluginInstallationManager(BasePluginManager):
         return self._request_with_plugin_daemon_response(
             "POST",
             f"plugin/{tenant_id}/management/install/upload",
-            str,
+            PluginUploadResponse,
             files=body,
             data=data,
         )

+ 3 - 3
api/services/plugin/plugin_service.py

@@ -5,7 +5,7 @@ from configs import dify_config
 from core.helper.download import download_with_size_limit
 from core.helper.marketplace import download_plugin_pkg
 from core.plugin.entities.plugin import PluginDeclaration, PluginEntity, PluginInstallationSource
-from core.plugin.entities.plugin_daemon import PluginInstallTask
+from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginUploadResponse
 from core.plugin.manager.asset import PluginAssetManager
 from core.plugin.manager.debugging import PluginDebuggingManager
 from core.plugin.manager.plugin import PluginInstallationManager
@@ -67,7 +67,7 @@ class PluginService:
         return manager.delete_plugin_installation_task(tenant_id, task_id)
 
     @staticmethod
-    def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> str:
+    def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> PluginUploadResponse:
         """
         Upload plugin package files
 
@@ -79,7 +79,7 @@ class PluginService:
     @staticmethod
     def upload_pkg_from_github(
         tenant_id: str, repo: str, version: str, package: str, verify_signature: bool = False
-    ) -> str:
+    ) -> PluginUploadResponse:
         """
         Install plugin from github release package files,
         returns plugin_unique_identifier