fix: review fixes, GitHub Releases update check (0.1.1)

- Wallet/subscription/window exhaustion skips a key for 10 minutes instead
  of disabling it; a balance read showing money brings it back. Only the
  gateway's own key refusals and a used-up key cap still disable a key.
- Classify by sub2api's exact wording; a bare 401 or upstream text no
  longer retires a key; 'No available accounts' is capacity, not coverage.
- Hosts keep only an https origin (no doubled /v1); timeouts and HTTP
  answers no longer set a host aside; hand edits are re-probed.
- Balance: inactive subscriptions, per-plan subscription pooling, key caps
  kept out of the total, rate windows shown.
- Endpoint editor no longer empties itself after Save.
- Update check reads GitHub Releases and installs the release tarball;
  release workflow replaces npm publishing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
大阔andClaude Opus 5.5 committed 2026-10-15 01:15:24 +08:00
1 parent 86b8e4d24f
commit f4f4ce55b3
34 files changed
+953 -521

No files matched your search

+27 -21
View File
@@ -5,6 +5,7 @@ import { isQuotaExceededError } from '@deepseek-ai/dsh-llm'
import {
CLIENT_POLICY_FAILURE,
EXHAUSTED_FAILURE,
INVALID_KEY_FAILURE,
QUOTA_FAILURE,
classifyCapacity,
@@ -30,41 +31,47 @@ const OTHER_CLASSES = [
/\b(?:network|connection|socket|fetch)\b|\bECONN[A-Z]+\b|\bterminated\b|premature close/iu,
]
test('recognizes an exhausted key from the gateway wording', () => {
assert.equal(classifyGatewayFailure('402 {"error":{"message":"当前令牌额度已用完"}}'), QUOTA_FAILURE)
assert.equal(classifyGatewayFailure('insufficient quota'), QUOTA_FAILURE)
assert.equal(classifyGatewayFailure('余额不足,请充值'), QUOTA_FAILURE)
test('money that comes back is exhausted, a used-up key cap is quota', () => {
assert.equal(classifyGatewayFailure('403 {"error":{"code":"INSUFFICIENT_BALANCE","message":"余额不足,请充值"}}'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('429 daily usage limit exceeded'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('429 api key 日限额已用完'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('429 api key 5小时限额已用完'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('429 Daily usage quota exhausted for this platform.'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('403 {"code":"SUBSCRIPTION_NOT_FOUND","message":"No active subscription found for this group"}'), EXHAUSTED_FAILURE)
assert.equal(classifyGatewayFailure('429 {"code":"API_KEY_QUOTA_EXHAUSTED","message":"API key 额度已用完"}'), QUOTA_FAILURE)
})
test('recognizes a rejected key from its status or wording', () => {
assert.equal(classifyGatewayFailure('401 {"error":{"message":"无效的令牌"}}'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('invalid api key'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('api key is invalid'), INVALID_KEY_FAILURE)
test('only the gateway\'s own words reject a key; a bare 401 or upstream wording does not', () => {
assert.equal(classifyGatewayFailure('401 {"code":"INVALID_API_KEY","message":"Invalid API key"}'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('401 Unauthorized'), undefined)
assert.equal(classifyGatewayFailure('502 upstream said: 401 {"error":{"type":"authentication_error"}}'), undefined)
assert.equal(classifyGatewayFailure('429 {"error":{"type":"insufficient_quota","message":"You exceeded your current quota"}}'), undefined)
assert.equal(classifyGatewayFailure('当前令牌额度已用完'), undefined)
})
test('leaves transient gateway faults to the key it already used', () => {
const channelFault = '400 {"error":{"code":"model_not_found","message":"当前令牌未覆盖供应商 \\"Anthropic\\"(模型=claude-opus-5-5)"}}'
assert.equal(classifyGatewayFailure(channelFault), undefined)
assert.equal(classifyGatewayFailure('503 {"error":{"message":"分组 cc-sale 下模型 claude-opus-5-5 无可用渠道"}}'), undefined)
assert.equal(classifyGatewayFailure('503 {"error":{"message":"No available accounts"}}'), undefined)
assert.equal(classifyGatewayFailure('502 Upstream service temporarily unavailable'), undefined)
assert.equal(classifyGatewayFailure(''), undefined)
assert.equal(classifyGatewayFailure(undefined), undefined)
})
test('a normalized quota failure lands in the harness quota category', () => {
const raw = '403 {"error":{"message":"当前令牌额度已用完 (request id: 01M4)"}}'
const raw = '403 {"error":{"code":"INSUFFICIENT_BALANCE","message":"余额不足,请充值"}}'
const kind = classifyGatewayFailure(raw)
assert.equal(kind, QUOTA_FAILURE)
assert.equal(kind, EXHAUSTED_FAILURE)
const normalized = normalizeFailureMessage(raw, kind)
assert.equal(isQuotaExceededError(normalized), true)
// The gateway's 403 must not send this into the auth category first.
assert.equal(AUTH_STATUS.test(normalized), false)
// The gateway's own sentence survives, so the user sees what happened.
assert.match(normalized, /当前令牌额度已用完/u)
assert.match(normalized, /余额不足,请充值/u)
assert.match(normalized, /trying the next key/u)
assert.equal(isQuotaExceededError(normalizeFailureMessage('429 API key 额度已用完', QUOTA_FAILURE)), true)
})
test('a normalized key rejection lands in the harness auth category', () => {
const raw = '{"error":{"message":"无效的令牌 (request id: 01M4)"}}'
const raw = '{"error":{"code":"INVALID_API_KEY","message":"Invalid API key"}}'
const kind = classifyGatewayFailure(raw)
assert.equal(kind, INVALID_KEY_FAILURE)
const normalized = normalizeFailureMessage(raw, kind)
@@ -75,8 +82,7 @@ test('a normalized key rejection lands in the harness auth category', () => {
test('a client-policy refusal is never blamed on the key', () => {
const claude = '403 {"error":{"type":"geek2api_api_error","message":"This API endpoint is only accessible via the official Claude CLI (request id: 01M4Q6FJ05BX8Z4SWZ01RXSNSS)"}}'
const codex = '403 {"error":{"message":"我们检测到您的客户端存在异常,请使用标准 Codex 客户端请求,请避免任何基于我方 API 二次分发的 API 转接接入。"}}'
for (const raw of [claude, codex]) {
for (const raw of [claude]) {
assert.equal(classifyClientPolicy(raw), true)
// Not a key fault: nothing may disable or rotate a key for this.
assert.equal(classifyGatewayFailure(raw), undefined)
@@ -106,7 +112,8 @@ test('a busy gateway is told apart from key, quota, and client faults', () => {
assert.equal(classifyCapacity('API Error: 503 {"error":{"type":"geek2api_concurrency_queue_full","message":"账号并发排队已满,请稍后重试。"}}'), true)
assert.equal(classifyCapacity('API Error: 429 rate_limit_error'), true)
assert.equal(classifyCapacity('API Error: 529 overloaded_error'), true)
assert.equal(classifyCapacity('API Error: 401 无效的令牌'), false)
assert.equal(classifyCapacity('API Error: 401 Invalid API key'), false)
assert.equal(classifyCapacity('API Error: 503 No available accounts'), true)
assert.equal(classifyCapacity('Request blocked: official Claude Code CLI only'), false)
const text = explainCliCapacityFailure('Claude Code CLI failed: API Error: 503 queue full', 10)
assert.match(text, /已自动重试 10 次/u)
@@ -121,14 +128,13 @@ test('classifies the sub2api gateway wording', () => {
assert.equal(classifyGatewayFailure('403 {"code":"API_KEY_EXPIRED","message":"API key 已过期"}'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('403 {"message":"API Key 所属分组已删除"}'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('403 {"code":"GROUP_NOT_ALLOWED","message":"API Key 所属专属分组不再允许当前用户使用"}'), INVALID_KEY_FAILURE)
assert.equal(classifyGatewayFailure('403 {"code":"INSUFFICIENT_BALANCE","message":"余额不足,请充值"}'), QUOTA_FAILURE)
assert.equal(classifyGatewayFailure('403 {"code":"SUBSCRIPTION_NOT_FOUND","message":"No active subscription found for this group"}'), QUOTA_FAILURE)
assert.equal(classifyGatewayFailure('403 {"code":"INSUFFICIENT_BALANCE","message":"余额不足,请充值"}'), EXHAUSTED_FAILURE)
// A model the key's group does not serve is coverage, never a key fault.
const missing = `400 {"error":{"message":"Model 'kimi-k3' is not available. Use GET /v1/models to see supported models.","type":"invalid_request_error"}}`
assert.equal(classifyGatewayFailure(missing), undefined)
assert.equal(classifyCoverage(missing), true)
assert.equal(classifyCoverage('503 No available accounts'), true)
assert.equal(classifyCoverage('503 No available accounts'), false, 'a busy pool is not coverage')
assert.equal(classifyCoverage('Model is not allowed'), true)
assert.equal(classifyCoverage('500 upstream exploded'), false)
})