# -*- coding: utf-8 -*- """配置页 Internal Server Error · 修改后(摘自 Dify 1.16.1 docker-api-1:/app/api/services/tools/builtin_tools_manage_service.py 函数 get_builtin_tool_provider_credential_info)。 相对修改前只多了 try/except:插件不存在时返回空凭据 JSON,HTTP 200。 应用请用:python scripts_cursor/作业1_06_修复配置页InternalServerError.py """ from __future__ import annotations import logging from sqlalchemy.orm import Session from core.tools.entities.api_entities import ToolProviderCredentialInfoApiEntity from core.tools.tool_manager import ToolManager from models.account import Account logger = logging.getLogger(__name__) class BuiltinToolManageService: @staticmethod def get_builtin_tool_provider_credential_info( tenant_id: str, provider: str, session: Session, user: Account | None = None, include_credential_ids: list[str] | None = None, ) -> ToolProviderCredentialInfoApiEntity: """ get builtin tool provider credential info """ try: provider_controller = ToolManager.get_builtin_provider(provider, tenant_id) except Exception as exc: err = str(exc).lower() if type(exc).__name__ in ( "PluginNotFoundError", "ToolProviderNotFoundError", ) or "plugin not found" in err: logger.warning( "skip builtin credential/info for non-plugin provider %s: %s", provider, exc, ) return ToolProviderCredentialInfoApiEntity( supported_credential_types=[], is_oauth_custom_client_enabled=False, credentials=[], ) raise supported_credential_types = provider_controller.get_supported_credential_types() credentials = BuiltinToolManageService.get_builtin_tool_provider_credentials( tenant_id, provider, session=session, user=user, include_credential_ids=include_credential_ids, ) credential_info = ToolProviderCredentialInfoApiEntity( supported_credential_types=supported_credential_types, is_oauth_custom_client_enabled=BuiltinToolManageService.is_oauth_custom_client_enabled(tenant_id, provider), credentials=credentials, ) return credential_info