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 DatasourceProviderApiEntity.to_dict with TypedDict (#34879)

volcano30340e23ce8dc4d
diff --git a/api/core/datasource/entities/api_entities.py b/api/core/datasource/entities/api_entities.py
index 14d1af2e8b4..5f90ba067c6 100644
--- a/api/core/datasource/entities/api_entities.py
+++ b/api/core/datasource/entities/api_entities.py
@@ -1,10 +1,10 @@
-from typing import Literal, Optional
+from typing import Any, Literal, Optional, TypedDict
from graphon.model_runtime.utils.encoders import jsonable_encoder
from pydantic import BaseModel, Field, field_validator
from core.datasource.entities.datasource_entities import DatasourceParameter
-from core.tools.entities.common_entities import I18nObject
+from core.tools.entities.common_entities import I18nObject, I18nObjectDict
class DatasourceApiEntity(BaseModel):
@@ -20,6 +20,23 @@ class DatasourceApiEntity(BaseModel):
ToolProviderTypeApiLiteral = Optional[Literal["builtin", "api", "workflow"]]
+class DatasourceProviderApiEntityDict(TypedDict):
+ id: str
+ author: str
+ name: str
+ plugin_id: str | None
+ plugin_unique_identifier: str | None
+ description: I18nObjectDict
+ icon: str | dict
+ label: I18nObjectDict
+ type: str
+ team_credentials: dict | None
+ is_team_authorization: bool
+ allow_delete: bool
+ datasources: list[Any]
+ labels: list[str]
+
+
class DatasourceProviderApiEntity(BaseModel):
id: str
author: str
@@ -42,7 +59,7 @@ class DatasourceProviderApiEntity(BaseModel):
def convert_none_to_empty_list(cls, v):
return v if v is not None else []
- def to_dict(self) -> dict:
+ def to_dict(self) -> DatasourceProviderApiEntityDict:
# -------------
# overwrite datasource parameter types for temp fix
datasources = jsonable_encoder(self.datasources)
@@ -53,7 +70,7 @@ class DatasourceProviderApiEntity(BaseModel):
parameter["type"] = "files"
# -------------
- return {
+ result: DatasourceProviderApiEntityDict = {
"id": self.id,
"author": self.author,
"name": self.name,
@@ -69,3 +86,4 @@ class DatasourceProviderApiEntity(BaseModel):
"datasources": datasources,
"labels": self.labels,
}
+ return result