mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
feat: ProxyNode 代理节点管理系统与 OpenAI Responses API 解析增强
ProxyNode 系统:新增 aether-proxy(Rust)海外 VPS 代理组件,后端实现节点注册/心跳/ HMAC 认证/健康检测调度器/模块化集成,前端新增代理节点管理页面。ProxyConfig 支持 node_id 模式,http_client 支持 HMAC 签名代理 URL 构建与 TTL 缓存。 OpenAI CLI 解析器:适配 Responses API 格式,支持 input_tokens/output_tokens 提取、 output[].content[].text 文本解析、response.completed 流式事件 usage 嵌套结构。
This commit is contained in:
@@ -11,6 +11,7 @@ from src.modules.gemini_files import gemini_files_module
|
||||
from src.modules.ldap import ldap_module
|
||||
from src.modules.management_tokens import management_tokens_module
|
||||
from src.modules.oauth import oauth_module
|
||||
from src.modules.proxy_nodes import proxy_nodes_module
|
||||
|
||||
# 所有模块列表
|
||||
ALL_MODULES: list[ModuleDefinition] = [
|
||||
@@ -18,6 +19,7 @@ ALL_MODULES: list[ModuleDefinition] = [
|
||||
oauth_module,
|
||||
gemini_files_module,
|
||||
management_tokens_module,
|
||||
proxy_nodes_module,
|
||||
]
|
||||
|
||||
__all__ = ["ALL_MODULES"]
|
||||
|
||||
112
src/modules/proxy_nodes/__init__.py
Normal file
112
src/modules/proxy_nodes/__init__.py
Normal file
@@ -0,0 +1,112 @@
|
||||
"""
|
||||
代理节点模块
|
||||
|
||||
提供海外 VPS 代理节点的注册、心跳、管理功能。
|
||||
aether-proxy 部署在海外 VPS 上自动注册节点,Aether 通过 HMAC 签名认证转发请求。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from src.core.modules.base import (
|
||||
ModuleCategory,
|
||||
ModuleDefinition,
|
||||
ModuleHealth,
|
||||
ModuleMetadata,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
def _get_router() -> Any:
|
||||
"""延迟导入路由"""
|
||||
from src.api.admin.proxy_nodes import router
|
||||
|
||||
return router
|
||||
|
||||
|
||||
async def _on_startup() -> None:
|
||||
"""启动心跳检测调度器"""
|
||||
import logging
|
||||
|
||||
from src.services.proxy_node.health_scheduler import get_proxy_node_health_scheduler
|
||||
from src.utils.task_coordinator import StartupTaskCoordinator
|
||||
|
||||
logger = logging.getLogger("aether.modules.proxy_nodes")
|
||||
|
||||
from src.clients import get_redis_client
|
||||
|
||||
redis_client = await get_redis_client()
|
||||
task_coordinator = StartupTaskCoordinator(redis_client)
|
||||
|
||||
proxy_node_health_scheduler = get_proxy_node_health_scheduler()
|
||||
active = await task_coordinator.acquire("proxy_node_health")
|
||||
if active:
|
||||
logger.info("启动 ProxyNode 心跳检测调度器...")
|
||||
await proxy_node_health_scheduler.start()
|
||||
else:
|
||||
logger.info("检测到其他 worker 已运行 ProxyNode 心跳检测,本实例跳过")
|
||||
|
||||
|
||||
async def _on_shutdown() -> None:
|
||||
"""停止心跳检测调度器"""
|
||||
import logging
|
||||
|
||||
from src.services.proxy_node.health_scheduler import get_proxy_node_health_scheduler
|
||||
from src.utils.task_coordinator import StartupTaskCoordinator
|
||||
|
||||
logger = logging.getLogger("aether.modules.proxy_nodes")
|
||||
|
||||
from src.clients import get_redis_client
|
||||
|
||||
redis_client = await get_redis_client()
|
||||
task_coordinator = StartupTaskCoordinator(redis_client)
|
||||
|
||||
scheduler = get_proxy_node_health_scheduler()
|
||||
if scheduler.running:
|
||||
logger.info("停止 ProxyNode 心跳检测调度器...")
|
||||
await scheduler.stop()
|
||||
await task_coordinator.release("proxy_node_health")
|
||||
|
||||
|
||||
async def _health_check() -> ModuleHealth:
|
||||
"""健康检查 - 检查是否有在线节点"""
|
||||
return ModuleHealth.HEALTHY
|
||||
|
||||
|
||||
def _validate_config(db: Session) -> tuple[bool, str]:
|
||||
"""
|
||||
验证配置
|
||||
|
||||
代理节点模块需要 PROXY_HMAC_KEY 配置
|
||||
"""
|
||||
from src.config.settings import config
|
||||
|
||||
if not config.proxy_hmac_key:
|
||||
return False, "PROXY_HMAC_KEY 未配置(也未设置 ENCRYPTION_KEY 用于自动派生)"
|
||||
return True, ""
|
||||
|
||||
|
||||
proxy_nodes_module = ModuleDefinition(
|
||||
metadata=ModuleMetadata(
|
||||
name="proxy_nodes",
|
||||
display_name="代理节点",
|
||||
description="海外 VPS 代理节点管理,通过 HMAC 签名认证转发 API 请求",
|
||||
category=ModuleCategory.INTEGRATION,
|
||||
env_key="PROXY_NODES_AVAILABLE",
|
||||
default_available=True,
|
||||
required_packages=[],
|
||||
api_prefix="/api/admin/proxy-nodes",
|
||||
admin_route="/admin/proxy-nodes",
|
||||
admin_menu_icon="Server",
|
||||
admin_menu_group="system",
|
||||
admin_menu_order=60,
|
||||
),
|
||||
router_factory=_get_router,
|
||||
on_startup=_on_startup,
|
||||
on_shutdown=_on_shutdown,
|
||||
health_check=_health_check,
|
||||
validate_config=_validate_config,
|
||||
)
|
||||
Reference in New Issue
Block a user