mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
- 删除全部 Python 源码 (src/) 及 Alembic 迁移脚本,归档至 _deprecated_py_src/ - 重构 Rust gateway ai_pipeline: 拆分 planner/finalize 模块,新增 contracts/adaptation 层 - 重组 handlers 模块为 admin/public/proxy/internal/shared 子模块结构 - 新增 executor 模块,引入 Rust 原生数据库迁移 (aether-data/migrations) - 简化 CI/Docker 构建流程,移除 base image 二级构建,统一为单一 app image - 移除 Python 相关基础设施文件 (entrypoint.sh, gunicorn_conf.py, Dockerfile.base)
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""Provider-specific upstream request header hooks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any, Callable
|
|
|
|
from src.core.provider_types import normalize_provider_type
|
|
from src.services.provider.envelope import ensure_providers_bootstrapped
|
|
|
|
UpstreamHeadersHookFn = Callable[..., dict[str, str]]
|
|
|
|
_hooks: dict[tuple[str, str], UpstreamHeadersHookFn] = {}
|
|
|
|
|
|
def register_upstream_headers_hook(
|
|
provider_type: str,
|
|
endpoint_sig: str,
|
|
hook: UpstreamHeadersHookFn,
|
|
) -> None:
|
|
"""Register a provider-specific extra upstream headers builder."""
|
|
pt = normalize_provider_type(provider_type)
|
|
sig = str(endpoint_sig or "").strip().lower()
|
|
if not pt or not sig:
|
|
return
|
|
_hooks[(pt, sig)] = hook
|
|
|
|
|
|
def build_upstream_extra_headers(
|
|
*,
|
|
provider_type: str | None,
|
|
endpoint_sig: str | None,
|
|
request_body: Any,
|
|
original_headers: Mapping[str, Any] | None,
|
|
decrypted_auth_config: dict[str, Any] | None,
|
|
) -> dict[str, str]:
|
|
"""Build provider-specific extra upstream headers for the current request."""
|
|
pt = normalize_provider_type(provider_type)
|
|
sig = str(endpoint_sig or "").strip().lower()
|
|
if not pt or not sig:
|
|
return {}
|
|
|
|
ensure_providers_bootstrapped(provider_types=[pt])
|
|
hook = _hooks.get((pt, sig))
|
|
if hook is None:
|
|
return {}
|
|
|
|
return hook(
|
|
request_body,
|
|
original_headers,
|
|
decrypted_auth_config=decrypted_auth_config,
|
|
)
|
|
|
|
|
|
__all__ = [
|
|
"UpstreamHeadersHookFn",
|
|
"build_upstream_extra_headers",
|
|
"register_upstream_headers_hook",
|
|
]
|