mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
refactor: 移除 Python 后端源码,全面迁移至 Rust gateway 架构
- 删除全部 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)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextvars
|
||||
from dataclasses import dataclass, replace
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class KiroRequestContext:
|
||||
"""Per-request context for the Kiro adapter.
|
||||
|
||||
This bridges data from `KiroEnvelope.wrap_request()` (which receives the
|
||||
decrypted auth_config + original request body) to other layers that only
|
||||
expose parameterless hooks (extra_headers) or transport hooks.
|
||||
"""
|
||||
|
||||
region: str
|
||||
machine_id: str
|
||||
kiro_version: str | None = None
|
||||
system_version: str | None = None
|
||||
node_version: str | None = None
|
||||
thinking_enabled: bool = False
|
||||
last_http_status: int | None = None
|
||||
last_http_error_category: str | None = None
|
||||
last_connection_error_category: str | None = None
|
||||
last_connection_error_summary: str | None = None
|
||||
|
||||
|
||||
_kiro_request_context: contextvars.ContextVar[KiroRequestContext | None] = contextvars.ContextVar(
|
||||
"kiro_request_context",
|
||||
default=None,
|
||||
)
|
||||
|
||||
|
||||
def set_kiro_request_context(ctx: KiroRequestContext | None) -> None:
|
||||
_kiro_request_context.set(ctx)
|
||||
|
||||
|
||||
def get_kiro_request_context() -> KiroRequestContext | None:
|
||||
return _kiro_request_context.get()
|
||||
|
||||
|
||||
def update_kiro_http_status(
|
||||
*,
|
||||
status_code: int,
|
||||
category: str,
|
||||
) -> None:
|
||||
ctx = get_kiro_request_context()
|
||||
if ctx is None:
|
||||
return
|
||||
set_kiro_request_context(
|
||||
replace(
|
||||
ctx,
|
||||
last_http_status=int(status_code),
|
||||
last_http_error_category=str(category),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def update_kiro_connection_error(
|
||||
*,
|
||||
category: str,
|
||||
summary: str,
|
||||
) -> None:
|
||||
ctx = get_kiro_request_context()
|
||||
if ctx is None:
|
||||
return
|
||||
set_kiro_request_context(
|
||||
replace(
|
||||
ctx,
|
||||
last_connection_error_category=str(category),
|
||||
last_connection_error_summary=str(summary),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"KiroRequestContext",
|
||||
"get_kiro_request_context",
|
||||
"set_kiro_request_context",
|
||||
"update_kiro_connection_error",
|
||||
"update_kiro_http_status",
|
||||
]
|
||||
Reference in New Issue
Block a user