refactor(api): replace dict type hints with Mapping for improved type safety

Updated type hints in several services to use Mapping instead of dict for better compatibility with various dictionary-like objects. Adjusted credential handling to ensure consistent encryption and decryption processes across ToolManager, DatasourceProviderService, ApiToolManageService, BuiltinToolManageService, and MCPToolManageService. This change enhances code clarity and adheres to strong typing practices.
This commit is contained in:
Harry
2025-10-29 18:10:23 +08:00
parent fb12f31df2
commit 9b5e5f0f50
5 changed files with 9 additions and 11 deletions

View File

@ -374,7 +374,7 @@ class DatasourceProviderService:
def get_tenant_oauth_client(
self, tenant_id: str, datasource_provider_id: DatasourceProviderID, mask: bool = False
) -> dict[str, Any] | None:
) -> Mapping[str, Any] | None:
"""
get tenant oauth client
"""
@ -434,7 +434,7 @@ class DatasourceProviderService:
)
if tenant_oauth_client_params:
encrypter, _ = self.get_oauth_encrypter(tenant_id, datasource_provider_id)
return encrypter.decrypt(tenant_oauth_client_params.client_params)
return dict(encrypter.decrypt(tenant_oauth_client_params.client_params))
provider_controller = self.provider_manager.fetch_datasource_provider(
tenant_id=tenant_id, provider_id=str(datasource_provider_id)