feat: Codex 请求转换引入 patch_for_variant 快速路径,Kiro 重复账号允许覆盖

- FormatNormalizer 新增 patch_for_variant 可选方法,同格式 + variant 场景
  跳过 internal 往返,直接在原始请求体上做最小补丁
- OpenAICliNormalizer 实现 Codex variant 快速路径,registry 优先尝试
- Codex request_patching 补充 stream=true、parallel_tool_calls=true、
  移除 previous_response_id
- Kiro 重复账号从拒绝改为允许覆盖(用户重新导入同一账号场景)
- Kiro Key 命名增加 auth_method 后缀,提取 _build_kiro_key_name 辅助函数
- Kiro token refresh 错误日志从 debug 提升为 warning,响应体截取增至 500 字符
This commit is contained in:
fawney19
2026-02-21 03:53:29 +08:00
parent 457fe83a4f
commit a1d972419d
6 changed files with 103 additions and 28 deletions

View File

@@ -48,6 +48,21 @@ class FormatNormalizer(ABC):
"""
raise NotImplementedError
# ============ 同格式变体补丁(可选) ============
def patch_for_variant(
self,
request: dict[str, Any],
variant: str,
) -> dict[str, Any] | None:
"""同格式 + variant 场景下的轻量补丁(跳过 internal 转换)。
子类可覆盖此方法,对已知 variant 直接在原始请求体上做最小修改。
返回 None 表示不支持该 variant 的快速路径registry 将回退到完整的
request_to_internal -> request_from_internal 流程。
"""
return None
# ============ 响应转换 ============
@abstractmethod

View File

@@ -112,6 +112,20 @@ class OpenAICliNormalizer(FormatNormalizer):
# Requests
# =========================
def patch_for_variant(
self,
request: dict[str, Any],
variant: str,
) -> dict[str, Any] | None:
"""Codex 同格式透传:直接在原始请求体上做最小补丁,跳过 internal 转换。"""
if variant.lower() != "codex":
return None
from src.services.provider.adapters.codex.request_patching import (
patch_openai_cli_request_for_codex,
)
return patch_openai_cli_request_for_codex(request)
def request_to_internal(self, request: dict[str, Any]) -> InternalRequest:
model = str(request.get("model") or "")

View File

@@ -110,6 +110,16 @@ class FormatConversionRegistry:
if str(source_format).upper() == str(target_format).upper() and not target_variant:
return request
# 同格式 + variant: 优先尝试轻量补丁(跳过 internal 转换)
if str(source_format).upper() == str(target_format).upper() and target_variant:
normalizer = self._require_normalizer(source_format)
with _track_conversion_metrics(
"request_patch", str(source_format).upper(), str(target_format).upper()
):
patched = normalizer.patch_for_variant(request, target_variant)
if patched is not None:
return patched
src = self._require_normalizer(source_format)
tgt = self._require_normalizer(target_format)
@@ -137,6 +147,16 @@ class FormatConversionRegistry:
if str(source_format).upper() == str(target_format).upper() and not target_variant:
return request
# 同格式 + variant: 优先尝试轻量补丁(跳过 internal 转换)
if str(source_format).upper() == str(target_format).upper() and target_variant:
normalizer = self._require_normalizer(source_format)
with _track_conversion_metrics(
"request_patch", str(source_format).upper(), str(target_format).upper()
):
patched = normalizer.patch_for_variant(request, target_variant)
if patched is not None:
return patched
src = self._require_normalizer(source_format)
tgt = self._require_normalizer(target_format)