mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
refactor(api): type plugin migration results with TypedDict (#34627)
This commit is contained in:
parent
0feff5b048
commit
2883ad6764
@ -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.
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user