mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
refactor: 全局适配 ApiFamily/EndpointKind 结构化标识体系
将新的 (ApiFamily, EndpointKind) / `family:kind` 签名体系应用到整个代码库: - API Handlers: 所有 adapter/handler 使用新的签名格式 - Services: provider, model, usage, cache, auth 等服务层适配 - Database: ProviderEndpoint 新增 api_family/endpoint_kind 字段 - Frontend: Provider 管理、Usage 表格等组件适配 - Tests: 更新所有相关测试用例
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
- 关键数据(计费)仍然立即 commit
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.logger import logger
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
class BatchCommitter:
|
||||
|
||||
@@ -11,7 +11,6 @@ from src.clients.redis_client import get_redis_client
|
||||
from src.core.logger import logger
|
||||
|
||||
|
||||
|
||||
class CacheService:
|
||||
"""缓存服务"""
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
|
||||
@@ -16,10 +17,10 @@ from cryptography.fernet import Fernet
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||
|
||||
from ..config import config
|
||||
from ..core.exceptions import DecryptionException
|
||||
from src.core.logger import logger
|
||||
|
||||
from ..config import config
|
||||
from ..core.exceptions import DecryptionException
|
||||
|
||||
|
||||
class CryptoService:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
统一的枚举定义
|
||||
避免重复定义造成的不一致
|
||||
|
||||
注意:APIFormat 已移至 src/core/api_format/enums.py
|
||||
注意:APIFormat 架构已移除,统一使用 endpoint signature(family:kind)。
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
错误消息处理工具函数
|
||||
"""
|
||||
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def extract_error_message(error: Exception, status_code: int | None = None) -> str:
|
||||
"""
|
||||
从异常中提取错误消息,优先使用上游原始响应(用于链路追踪/调试)
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from starlette.requests import Request
|
||||
import asyncio
|
||||
import re
|
||||
import traceback
|
||||
@@ -19,6 +18,7 @@ from typing import Any
|
||||
import httpx
|
||||
from fastapi import HTTPException, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from starlette.requests import Request
|
||||
|
||||
from src.core.logger import logger
|
||||
|
||||
@@ -280,9 +280,7 @@ class RateLimitException(ProxyException):
|
||||
class ConcurrencyLimitError(ProxyException):
|
||||
"""并发限制异常"""
|
||||
|
||||
def __init__(
|
||||
self, message: str, endpoint_id: str | None = None, key_id: str | None = None
|
||||
):
|
||||
def __init__(self, message: str, endpoint_id: str | None = None, key_id: str | None = None):
|
||||
details = {}
|
||||
if endpoint_id:
|
||||
details["endpoint_id"] = endpoint_id
|
||||
|
||||
@@ -83,7 +83,9 @@ def get_all_capabilities() -> list[CapabilityDefinition]:
|
||||
|
||||
def get_user_configurable_capabilities() -> list[CapabilityDefinition]:
|
||||
"""获取用户可配置的能力列表"""
|
||||
return [c for c in _capabilities.values() if c.config_mode == CapabilityConfigMode.USER_CONFIGURABLE]
|
||||
return [
|
||||
c for c in _capabilities.values() if c.config_mode == CapabilityConfigMode.USER_CONFIGURABLE
|
||||
]
|
||||
|
||||
|
||||
# ============ 能力匹配检查 ============
|
||||
|
||||
@@ -35,8 +35,7 @@ from loguru import logger
|
||||
# ============================================================================
|
||||
|
||||
IS_DOCKER = (
|
||||
os.path.exists("/.dockerenv")
|
||||
or os.environ.get("DOCKER_CONTAINER", "false").lower() == "true"
|
||||
os.path.exists("/.dockerenv") or os.environ.get("DOCKER_CONTAINER", "false").lower() == "true"
|
||||
)
|
||||
|
||||
# 日志级别: 默认开发环境 DEBUG, 生产环境 INFO
|
||||
@@ -53,9 +52,7 @@ PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
# ============================================================================
|
||||
|
||||
CONSOLE_FORMAT_DEV = (
|
||||
"<green>{time:HH:mm:ss}</green> | "
|
||||
"<level>{level: <8}</level> | "
|
||||
"<cyan>{message}</cyan>"
|
||||
"<green>{time:HH:mm:ss}</green> | " "<level>{level: <8}</level> | " "<cyan>{message}</cyan>"
|
||||
)
|
||||
|
||||
CONSOLE_FORMAT_PROD = "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {message}"
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Awaitable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import APIRouter
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -280,9 +280,7 @@ class ModuleRegistry:
|
||||
logger.warning(f"Module [{name}] health check failed: {e}")
|
||||
return ModuleHealth.UNHEALTHY
|
||||
|
||||
async def get_module_status_async(
|
||||
self, name: str, db: Session
|
||||
) -> ModuleStatus | None:
|
||||
async def get_module_status_async(self, name: str, db: Session) -> ModuleStatus | None:
|
||||
"""异步获取模块状态(包含健康检查)"""
|
||||
if name not in self._modules:
|
||||
return None
|
||||
|
||||
@@ -11,16 +11,15 @@ import threading
|
||||
import time
|
||||
import traceback
|
||||
import uuid
|
||||
from collections.abc import Callable
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime, timezone
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from ..core.exceptions import ProxyException
|
||||
from src.core.logger import logger
|
||||
|
||||
from ..core.exceptions import ProxyException
|
||||
|
||||
|
||||
class ErrorSeverity(Enum):
|
||||
@@ -383,7 +382,9 @@ async def safe_operation(operation_name: str, context: dict[str, Any] = None) ->
|
||||
logger.warning(f"操作警告 [{error_result['error_id']}]: {error_result['user_message']}")
|
||||
|
||||
|
||||
def graceful_degradation(fallback_func: Callable | None = None, fallback_value: Any | None = None) -> Any:
|
||||
def graceful_degradation(
|
||||
fallback_func: Callable | None = None, fallback_value: Any | None = None
|
||||
) -> Any:
|
||||
"""
|
||||
优雅降级装饰器
|
||||
当主要功能失败时,自动切换到备用方案
|
||||
|
||||
@@ -163,7 +163,9 @@ class VertexAuthService:
|
||||
|
||||
except httpx.HTTPStatusError as e:
|
||||
error_body = e.response.text[:500] if e.response.text else "(empty)"
|
||||
raise VertexAuthError(f"Failed to get access token: HTTP {e.response.status_code}: {error_body}")
|
||||
raise VertexAuthError(
|
||||
f"Failed to get access token: HTTP {e.response.status_code}: {error_body}"
|
||||
)
|
||||
except Exception as e:
|
||||
raise VertexAuthError(f"Failed to get access token: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user