Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(api): type plugin migration results with TypedDict (#34627)

Statxc2883ad6764ec
diff --git a/api/services/plugin/plugin_migration.py b/api/services/plugin/plugin_migration.py
index 442ccef1da6..d6f6ee8086c 100644
--- a/api/services/plugin/plugin_migration.py
+++ b/api/services/plugin/plugin_migration.py
@@ -5,7 +5,7 @@ import time
from collections.abc import Mapping, Sequence
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
-from typing import Any, TypedDict
+from typing import TypedDict
from uuid import uuid4
import click
@@ -42,6 +42,16 @@ class _TenantPluginRecord(TypedDict):
_tenant_plugin_adapter: TypeAdapter[_TenantPluginRecord] = TypeAdapter(_TenantPluginRecord)
+class ExtractedPluginsDict(TypedDict):
+ plugins: dict[str, str]
+ plugin_not_exist: list[str]
+
+
+class PluginInstallResultDict(TypedDict):
+ success: list[str]
+ failed: list[str]
+
+
class PluginMigration:
@classmethod
def extract_plugins(cls, filepath: str, workers: int):
@@ -310,7 +320,7 @@ class PluginMigration:
Path(output_file).write_text(json.dumps(cls.extract_unique_plugins(extracted_plugins)))
@classmethod
- def extract_unique_plugins(cls, extracted_plugins: str) -> Mapping[str, Any]:
+ def extract_unique_plugins(cls, extracted_plugins: str) -> ExtractedPluginsDict:
plugins: dict[str, str] = {}
plugin_ids = []
plugin_not_exist = []
@@ -524,7 +534,7 @@ class PluginMigration:
@classmethod
def handle_plugin_instance_install(
cls, tenant_id: str, plugin_identifiers_map: Mapping[str, str]
- ) -> Mapping[str, Any]:
+ ) -> PluginInstallResultDict:
"""
Install plugins for a tenant.
"""