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: replace bare dict with typed annotations in core plugin module (#35096)

dataCenter43083b242be7b8d
diff --git a/api/core/plugin/entities/endpoint.py b/api/core/plugin/entities/endpoint.py
index e5bca140f82..64199636687 100644
--- a/api/core/plugin/entities/endpoint.py
+++ b/api/core/plugin/entities/endpoint.py
@@ -1,4 +1,5 @@
from datetime import datetime
+from typing import Any
from pydantic import BaseModel, Field, model_validator
@@ -31,7 +32,7 @@ class EndpointEntity(BasePluginEntity):
entity of an endpoint
"""
- settings: dict
+ settings: dict[str, Any]
tenant_id: str
plugin_id: str
expired_at: datetime
diff --git a/api/core/plugin/entities/marketplace.py b/api/core/plugin/entities/marketplace.py
index 2177e8af908..fd2094228af 100644
--- a/api/core/plugin/entities/marketplace.py
+++ b/api/core/plugin/entities/marketplace.py
@@ -1,3 +1,5 @@
+from typing import Any
+
from graphon.model_runtime.entities.provider_entities import ProviderEntity
from pydantic import BaseModel, Field, computed_field, model_validator
@@ -40,7 +42,7 @@ class MarketplacePluginDeclaration(BaseModel):
@model_validator(mode="before")
@classmethod
- def transform_declaration(cls, data: dict):
+ def transform_declaration(cls, data: dict[str, Any]) -> dict[str, Any]:
if "endpoint" in data and not data["endpoint"]:
del data["endpoint"]
if "model" in data and not data["model"]:
diff --git a/api/core/plugin/entities/plugin.py b/api/core/plugin/entities/plugin.py
index b095b4998d7..4d28032a57d 100644
--- a/api/core/plugin/entities/plugin.py
+++ b/api/core/plugin/entities/plugin.py
@@ -123,7 +123,7 @@ class PluginDeclaration(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_category(cls, values: dict):
+ def validate_category(cls, values: dict[str, Any]) -> dict[str, Any]:
# auto detect category
if values.get("tool"):
values["category"] = PluginCategory.Tool
diff --git a/api/core/plugin/entities/plugin_daemon.py b/api/core/plugin/entities/plugin_daemon.py
index b57180690e8..e0ddb746c75 100644
--- a/api/core/plugin/entities/plugin_daemon.py
+++ b/api/core/plugin/entities/plugin_daemon.py
@@ -73,7 +73,7 @@ class PluginBasicBooleanResponse(BaseModel):
"""
result: bool
- credentials: dict | None = None
+ credentials: dict[str, Any] | None = None
class PluginModelSchemaEntity(BaseModel):
diff --git a/api/core/plugin/entities/request.py b/api/core/plugin/entities/request.py
index 059f3fa9be1..4a85952dcd1 100644
--- a/api/core/plugin/entities/request.py
+++ b/api/core/plugin/entities/request.py
@@ -49,7 +49,7 @@ class RequestInvokeTool(BaseModel):
tool_type: Literal["builtin", "workflow", "api", "mcp"]
provider: str
tool: str
- tool_parameters: dict
+ tool_parameters: dict[str, Any]
credential_id: str | None = None
@@ -209,7 +209,7 @@ class RequestInvokeEncrypt(BaseModel):
opt: Literal["encrypt", "decrypt", "clear"]
namespace: Literal["endpoint"]
identity: str
- data: dict = Field(default_factory=dict)
+ data: dict[str, Any] = Field(default_factory=dict)
config: list[BasicProviderConfig] = Field(default_factory=list)
diff --git a/api/core/plugin/impl/datasource.py b/api/core/plugin/impl/datasource.py
index ce1ef714944..56c08addbab 100644
--- a/api/core/plugin/impl/datasource.py
+++ b/api/core/plugin/impl/datasource.py
@@ -26,7 +26,7 @@ class PluginDatasourceManager(BasePluginClient):
Fetch datasource providers for the given tenant.
"""
- def transformer(json_response: dict[str, Any]) -> dict:
+ def transformer(json_response: dict[str, Any]) -> dict[str, Any]:
if json_response.get("data"):
for provider in json_response.get("data", []):
declaration = provider.get("declaration", {}) or {}
@@ -68,7 +68,7 @@ class PluginDatasourceManager(BasePluginClient):
Fetch datasource providers for the given tenant.
"""
- def transformer(json_response: dict[str, Any]) -> dict:
+ def transformer(json_response: dict[str, Any]) -> dict[str, Any]:
if json_response.get("data"):
for provider in json_response.get("data", []):
declaration = provider.get("declaration", {}) or {}
@@ -110,7 +110,7 @@ class PluginDatasourceManager(BasePluginClient):
tool_provider_id = DatasourceProviderID(provider_id)
- def transformer(json_response: dict[str, Any]) -> dict:
+ def transformer(json_response: dict[str, Any]) -> dict[str, Any]:
data = json_response.get("data")
if data:
for datasource in data.get("declaration", {}).get("datasources", []):
diff --git a/api/core/plugin/impl/endpoint.py b/api/core/plugin/impl/endpoint.py
index 2db5185a2c7..b335b427633 100644
--- a/api/core/plugin/impl/endpoint.py
+++ b/api/core/plugin/impl/endpoint.py
@@ -1,3 +1,5 @@
+from typing import Any
+
from core.plugin.entities.endpoint import EndpointEntityWithInstance
from core.plugin.impl.base import BasePluginClient
from core.plugin.impl.exc import PluginDaemonInternalServerError
@@ -5,7 +7,12 @@ from core.plugin.impl.exc import PluginDaemonInternalServerError
class PluginEndpointClient(BasePluginClient):
def create_endpoint(
- self, tenant_id: str, user_id: str, plugin_unique_identifier: str, name: str, settings: dict
+ self,
+ tenant_id: str,
+ user_id: str,
+ plugin_unique_identifier: str,
+ name: str,
+ settings: dict[str, Any],
) -> bool:
"""
Create an endpoint for the given plugin.
@@ -49,7 +56,9 @@ class PluginEndpointClient(BasePluginClient):
params={"plugin_id": plugin_id, "page": page, "page_size": page_size},
)
- def update_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict):
+ def update_endpoint(
+ self, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict[str, Any]
+ ) -> bool:
"""
Update the settings of the given endpoint.
"""
diff --git a/api/core/plugin/impl/model.py b/api/core/plugin/impl/model.py
index e54bebd7ac4..703af63f7c1 100644
--- a/api/core/plugin/impl/model.py
+++ b/api/core/plugin/impl/model.py
@@ -80,7 +80,7 @@ class PluginModelClient(BasePluginClient):
return None
def validate_provider_credentials(
- self, tenant_id: str, user_id: str | None, plugin_id: str, provider: str, credentials: dict
+ self, tenant_id: str, user_id: str | None, plugin_id: str, provider: str, credentials: dict[str, Any]
) -> bool:
"""
validate the credentials of the provider
diff --git a/api/core/plugin/impl/plugin.py b/api/core/plugin/impl/plugin.py
index c75c30a98ac..8a7175bb51f 100644
--- a/api/core/plugin/impl/plugin.py
+++ b/api/core/plugin/impl/plugin.py
@@ -1,4 +1,5 @@
from collections.abc import Sequence
+from typing import Any
from requests import HTTPError
@@ -263,7 +264,7 @@ class PluginInstaller(BasePluginClient):
original_plugin_unique_identifier: str,
new_plugin_unique_identifier: str,
source: PluginInstallationSource,
- meta: dict,
+ meta: dict[str, Any],
) -> PluginInstallTaskStartResponse:
"""
Upgrade a plugin.