feat: Codex/Kiro 配额自动刷新增加 5 分钟过期检查

- Codex: 新增 Token 即将过期检查 + 配额数据过期检查
- Kiro: 新增配额数据过期检查
- 三个 OAuth Provider 的自动刷新逻辑现在完全一致
This commit is contained in:
AAEE86
2026-02-10 21:12:31 +08:00
parent d8addec077
commit 347bd3345c

View File

@@ -1632,21 +1632,29 @@ function formatKiroSubscription(title: string | undefined): string {
function shouldAutoRefreshCodexQuota(): boolean { function shouldAutoRefreshCodexQuota(): boolean {
if (provider.value?.provider_type !== 'codex') return false if (provider.value?.provider_type !== 'codex') return false
const now = Math.floor(Date.now() / 1000)
for (const { key } of allKeys.value) { for (const { key } of allKeys.value) {
if (!key.is_active) continue if (!key.is_active) continue
if (isTokenExpiringSoon(key, now)) return true
const meta: UpstreamMetadata | null | undefined = key.upstream_metadata const meta: UpstreamMetadata | null | undefined = key.upstream_metadata
// 只要有一个活跃 key 没有配额数据,就刷新一次 // 只要有一个活跃 key 没有配额数据,就刷新一次
if (!hasCodexQuotaData(meta)) { if (!hasCodexQuotaData(meta)) {
return true return true
} }
// 配额数据超过 5 分钟未更新,也触发刷新
const updatedAt = meta?.codex?.updated_at
if (typeof updatedAt !== 'number' || (now - updatedAt) > AUTO_QUOTA_REFRESH_STALE_SECONDS) {
return true
}
} }
return false return false
} }
// 检查 OAuth Token 是否即将过期Antigravity / Kiro // 检查 OAuth Token 是否即将过期(Codex / Antigravity / Kiro
function isTokenExpiringSoon(key: EndpointAPIKey, now: number): boolean { function isTokenExpiringSoon(key: EndpointAPIKey, now: number): boolean {
return key.oauth_invalid_at == null return key.oauth_invalid_at == null
&& typeof key.oauth_expires_at === 'number' && typeof key.oauth_expires_at === 'number'
@@ -1687,8 +1695,14 @@ function shouldAutoRefreshKiroQuota(): boolean {
if (isTokenExpiringSoon(key, now)) return true if (isTokenExpiringSoon(key, now)) return true
const meta = key.upstream_metadata
// 只要有一个活跃 key 没有配额数据,就刷新一次 // 只要有一个活跃 key 没有配额数据,就刷新一次
if (!hasKiroQuotaData(key.upstream_metadata)) { if (!hasKiroQuotaData(meta)) {
return true
}
// 配额数据超过 5 分钟未更新,也触发刷新
const updatedAt = meta?.kiro?.updated_at
if (typeof updatedAt !== 'number' || (now - updatedAt) > AUTO_QUOTA_REFRESH_STALE_SECONDS) {
return true return true
} }
} }