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)
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
import httpx
|
|
|
|
from src.services.billing.rule_service import BillingRuleLookupResult
|
|
from src.services.candidate.submit import SubmitOutcome
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class SubmitPayloadParseResult:
|
|
"""提交响应解析结果。"""
|
|
|
|
payload: dict[str, Any] | None
|
|
error_type: str | None = None
|
|
error_message: str | None = None
|
|
|
|
|
|
class AsyncSubmitOutcomeBuilderService:
|
|
"""异步提交结果构建服务。"""
|
|
|
|
def __init__(self, *, sanitize: Callable[[str], str]) -> None:
|
|
self._sanitize = sanitize
|
|
|
|
def parse_payload(self, *, response: httpx.Response) -> SubmitPayloadParseResult:
|
|
payload: dict[str, Any] | None = None
|
|
try:
|
|
data = response.json()
|
|
if isinstance(data, dict):
|
|
payload = data
|
|
except Exception as exc:
|
|
return SubmitPayloadParseResult(
|
|
payload=None,
|
|
error_type=type(exc).__name__,
|
|
error_message=self._sanitize(str(exc)),
|
|
)
|
|
return SubmitPayloadParseResult(payload=payload)
|
|
|
|
@staticmethod
|
|
def build_success_outcome(
|
|
*,
|
|
candidate: Any,
|
|
candidate_keys: list[dict[str, Any]],
|
|
external_task_id: str,
|
|
rule_lookup: BillingRuleLookupResult | None,
|
|
payload: dict[str, Any] | None,
|
|
response: httpx.Response,
|
|
) -> SubmitOutcome:
|
|
return SubmitOutcome(
|
|
candidate=candidate,
|
|
candidate_keys=candidate_keys,
|
|
external_task_id=external_task_id,
|
|
rule_lookup=rule_lookup,
|
|
upstream_payload=payload,
|
|
upstream_headers=dict(response.headers),
|
|
upstream_status_code=response.status_code,
|
|
)
|