mirror of https://github.com/langgenius/dify.git
refactor(api): type tool service dicts with TypedDict (#33836)
This commit is contained in:
parent
609258f42d
commit
55cc24fed7
|
|
@ -1,10 +1,10 @@
|
|||
import json
|
||||
import logging
|
||||
from collections.abc import Mapping
|
||||
from typing import Any, cast
|
||||
|
||||
from httpx import get
|
||||
from sqlalchemy import select
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from core.entities.provider_entities import ProviderConfig
|
||||
from core.tools.__base.tool_runtime import ToolRuntime
|
||||
|
|
@ -28,9 +28,16 @@ from services.tools.tools_transform_service import ToolTransformService
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ApiSchemaParseResult(TypedDict):
|
||||
schema_type: str
|
||||
parameters_schema: list[dict[str, Any]]
|
||||
credentials_schema: list[dict[str, Any]]
|
||||
warning: dict[str, str]
|
||||
|
||||
|
||||
class ApiToolManageService:
|
||||
@staticmethod
|
||||
def parser_api_schema(schema: str) -> Mapping[str, Any]:
|
||||
def parser_api_schema(schema: str) -> ApiSchemaParseResult:
|
||||
"""
|
||||
parse api schema to tool bundle
|
||||
"""
|
||||
|
|
@ -71,7 +78,7 @@ class ApiToolManageService:
|
|||
]
|
||||
|
||||
return cast(
|
||||
Mapping,
|
||||
ApiSchemaParseResult,
|
||||
jsonable_encoder(
|
||||
{
|
||||
"schema_type": schema_type,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from core.helper.provider_cache import NoOpProviderCredentialCache
|
|||
from core.mcp.auth.auth_flow import auth
|
||||
from core.mcp.auth_client import MCPClientWithAuthRetry
|
||||
from core.mcp.error import MCPAuthError, MCPError
|
||||
from core.mcp.types import Tool as MCPTool
|
||||
from core.tools.entities.api_entities import ToolProviderApiEntity
|
||||
from core.tools.utils.encryption import ProviderConfigEncrypter
|
||||
from models.tools import MCPToolProvider
|
||||
|
|
@ -681,7 +682,7 @@ class MCPToolManageService:
|
|||
raise ValueError(f"Failed to re-connect MCP server: {e}") from e
|
||||
|
||||
def _build_tool_provider_response(
|
||||
self, db_provider: MCPToolProvider, provider_entity: MCPProviderEntity, tools: list
|
||||
self, db_provider: MCPToolProvider, provider_entity: MCPProviderEntity, tools: list[MCPTool]
|
||||
) -> ToolProviderApiEntity:
|
||||
"""Build API response for tool provider."""
|
||||
user = db_provider.load_user()
|
||||
|
|
|
|||
Loading…
Reference in New Issue