feat(codex): 增强 OAuth 导入解析与账号信息提取,优化维护调度器线程模型

Codex OAuth:
- 导入解析支持附加账号字段(account_id/plan_type/user_id/email)
- enrich_codex 扩展从 access_token 和直接字段提取账号信息
- parse_codex_id_token 支持 JWT/JSON 字符串/dict 三种输入格式
- request patching 新增 openai:compact 格式支持
- codex_usage_parser 新增 credits_unlimited 字段解析

维护调度器:
- 同步 DB 操作迁移到线程池执行,避免阻塞事件循环
- 新增 request_candidates 定期清理任务
- 新增每周 VACUUM ANALYZE 数据库表维护任务
- 新增 enable_db_maintenance 配置项

前端:
- ElapsedTimeText 从 setInterval 改为 requestAnimationFrame
- 时间线过滤 available/unused 占位记录
- Usage 页面默认关闭全局自动刷新
- 移除号池管理中的配额更新时间显示
This commit is contained in:
fawney19
2026-03-04 10:00:38 +08:00
parent e181329a81
commit 82a9fb3c39
17 changed files with 822 additions and 317 deletions

View File

@@ -0,0 +1,70 @@
from __future__ import annotations
import json
import jwt
from src.core.provider_oauth_utils import parse_codex_id_token
def _encode_unsigned_jwt(payload: dict[str, object]) -> str:
token = jwt.encode(payload, key="", algorithm="none")
return token.decode("utf-8") if isinstance(token, bytes) else token
def test_parse_codex_id_token_extracts_auth_claim_fields() -> None:
token = _encode_unsigned_jwt(
{
"email": "u@example.com",
"https://api.openai.com/auth": {
"chatgpt_account_id": "acc-1",
"chatgpt_plan_type": "team",
"chatgpt_user_id": "user-1",
},
}
)
parsed = parse_codex_id_token(token)
assert parsed == {
"email": "u@example.com",
"account_id": "acc-1",
"plan_type": "team",
"user_id": "user-1",
}
def test_parse_codex_id_token_accepts_json_payload_string() -> None:
payload = {
"email": "u@example.com",
"chatgpt_account_id": "acc-2",
"chatgpt_plan_type": "plus",
"chatgpt_user_id": "user-2",
}
parsed = parse_codex_id_token(json.dumps(payload))
assert parsed == {
"email": "u@example.com",
"account_id": "acc-2",
"plan_type": "plus",
"user_id": "user-2",
}
def test_parse_codex_id_token_accepts_dict_payload() -> None:
parsed = parse_codex_id_token(
{
"email": "u@example.com",
"accountId": "acc-3",
"planType": "enterprise",
"userId": "user-3",
}
)
assert parsed == {
"email": "u@example.com",
"account_id": "acc-3",
"plan_type": "enterprise",
"user_id": "user-3",
}