refactor: 提取 is_codex_url 到公共 utils 模块

将重复的 Codex URL 判断逻辑提取到 src/utils/url_utils.py,
避免 transport.py 和 adapter.py 中的代码重复。
This commit is contained in:
fawney19
2026-02-05 11:17:00 +08:00
parent bb125a1ddc
commit e72e5370c4
3 changed files with 29 additions and 18 deletions

23
src/utils/url_utils.py Normal file
View File

@@ -0,0 +1,23 @@
"""
URL 处理工具函数
提供 URL 模式检测和处理功能。
"""
from __future__ import annotations
def is_codex_url(base_url: str) -> bool:
"""判断是否是 Codex OAuth 端点。
Codex OAuth 端点(如 chatgpt.com/backend-api/codex不走标准 /v1 前缀,
直接使用 /responses 而非 /v1/responses。
Args:
base_url: 端点基础 URL
Returns:
bool: 是否是 Codex 端点
"""
url = base_url.rstrip("/")
return "/backend-api/codex" in url or url.endswith("/codex")