dsh-codearts 1.4.14 → 1.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  本文件记录本插件的重要改动。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
4
4
  版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
5
5
 
6
+ ## [1.4.15] - 2026-11-27
7
+
8
+ ### 修复
9
+
10
+ - **冷却期不再把请求打回宿主盲退避**(#22):账号全在冷却时,以前立刻回 429,
11
+ 而解冻时刻插件自己精确知道(冷却最长 30 秒)—— 落在冷却窗内的宿主重试注定
12
+ 失败,一次上游 5xx 会被放大成一串失败记录。现在轮换在两轮之间内联等到最近
13
+ 一个号解冻再发;超过轮换截止点的冷却(例如积分耗尽的 30 分钟)仍立即报错,
14
+ 并写明本地已等冷却多少秒。
15
+ - **与 billion-context 共存时的大请求不再被拒**(#23):bili 会对「未归属会话、
16
+ 又超过静默直连上限(8 MiB)」的请求在本地回 422 + `x-bili-gate:
17
+ oversize-refusal*`,根本没出网。现在认出这个标记后改走插件自己的
18
+ `node:http(s)` 连接直发,签名与请求体原样保留;真正的上游 422 不带该标记头,
19
+ 仍按原分类处理。
20
+
6
21
  ## [1.4.14] - 2026-11-26
7
22
 
8
23
  ### 修复
@@ -584,7 +584,7 @@ async function clearCredential(path) {
584
584
  async function claimIfPossible(cred) {
585
585
  if (!cred.accessKeyId || !cred.secretAccessKey) return;
586
586
  try {
587
- const { claimBenefit } = await import("./upstream-DA3AC1mv.mjs").then((n) => n.z);
587
+ const { claimBenefit } = await import("./upstream-D1NN-sbL.mjs").then((n) => n.z);
588
588
  await claimBenefit({
589
589
  token: cred.token,
590
590
  accessKeyId: cred.accessKeyId,
package/lib/bin.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-fN1w-DqH.mjs";
3
- import { J as isBenefitModel, l as fetchCallerIdentity } from "./upstream-DA3AC1mv.mjs";
4
- import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DcfKEx5Z.mjs";
2
+ import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-qnSuuDGW.mjs";
3
+ import { J as isBenefitModel, l as fetchCallerIdentity } from "./upstream-D1NN-sbL.mjs";
4
+ import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-BJniJ4eN.mjs";
5
5
  import { existsSync, statSync } from "node:fs";
6
6
  //#region src/bin.ts
7
7
  /**
@@ -194,129 +194,129 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
194
194
  document.head.appendChild(tag);
195
195
  }
196
196
  var CodeArtsPluginCard_module_css_default = {
197
- "windowInputSet": "xoziZG_windowInputSet",
198
- "count": "xoziZG_count",
199
- "windowUnit": "xoziZG_windowUnit",
197
+ "statValue": "xoziZG_statValue",
198
+ "balanceMeta": "xoziZG_balanceMeta",
199
+ "groupHead": "xoziZG_groupHead",
200
200
  "area": "xoziZG_area",
201
- "creditBlock": "xoziZG_creditBlock",
202
- "modelSpec": "xoziZG_modelSpec",
201
+ "accountHint": "xoziZG_accountHint",
202
+ "manualForm": "xoziZG_manualForm",
203
+ "expiryLabel": "xoziZG_expiryLabel",
204
+ "sectionLabel": "xoziZG_sectionLabel",
205
+ "creditFooter": "xoziZG_creditFooter",
206
+ "heatGrid": "xoziZG_heatGrid",
207
+ "concurrencyStepper": "xoziZG_concurrencyStepper",
208
+ "actions": "xoziZG_actions",
209
+ "accountRowActions": "xoziZG_accountRowActions",
210
+ "modelRow": "xoziZG_modelRow",
211
+ "updated": "xoziZG_updated",
212
+ "bar": "xoziZG_bar",
213
+ "creditLink": "xoziZG_creditLink",
214
+ "modelFill": "xoziZG_modelFill",
215
+ "windowUnit": "xoziZG_windowUnit",
203
216
  "usageTipName": "xoziZG_usageTipName",
204
- "body": "xoziZG_body",
205
- "manualSummary": "xoziZG_manualSummary",
217
+ "accountName": "xoziZG_accountName",
218
+ "choiceRow": "xoziZG_choiceRow",
219
+ "statusLine": "xoziZG_statusLine",
220
+ "usageTipSep": "xoziZG_usageTipSep",
221
+ "concurrencyButton": "xoziZG_concurrencyButton",
222
+ "accountInfo": "xoziZG_accountInfo",
223
+ "windowAnchor": "xoziZG_windowAnchor",
224
+ "fieldLabel": "xoziZG_fieldLabel",
225
+ "statSub": "xoziZG_statSub",
226
+ "usageTipRow": "xoziZG_usageTipRow",
227
+ "heatLegend": "xoziZG_heatLegend",
228
+ "groupLabel": "xoziZG_groupLabel",
229
+ "concurrencyValue": "xoziZG_concurrencyValue",
230
+ "skeletonRow": "xoziZG_skeletonRow",
231
+ "statLabel": "xoziZG_statLabel",
232
+ "statGrid": "xoziZG_statGrid",
206
233
  "heatLegendChip": "xoziZG_heatLegendChip",
207
- "windowRange": "xoziZG_windowRange",
208
- "sectionHead": "xoziZG_sectionHead",
234
+ "windowButtonSet": "xoziZG_windowButtonSet",
235
+ "usageBar": "xoziZG_usageBar",
236
+ "modelSpec": "xoziZG_modelSpec",
237
+ "accountGrid": "xoziZG_accountGrid",
238
+ "groupHeadFirst": "xoziZG_groupHeadFirst",
239
+ "field": "xoziZG_field",
240
+ "barFill": "xoziZG_barFill",
241
+ "skeleton": "xoziZG_skeleton",
242
+ "manual": "xoziZG_manual",
209
243
  "heatAxisSlot": "xoziZG_heatAxisSlot",
210
- "heatCell": "xoziZG_heatCell",
211
- "creditRow": "xoziZG_creditRow",
212
- "windowButton": "xoziZG_windowButton",
244
+ "accountMenuItem": "xoziZG_accountMenuItem",
213
245
  "windowPopoverRow": "xoziZG_windowPopoverRow",
214
- "field": "xoziZG_field",
215
- "accountNameRow": "xoziZG_accountNameRow",
216
- "updated": "xoziZG_updated",
217
- "claimAllRow": "xoziZG_claimAllRow",
218
- "windowHint": "xoziZG_windowHint",
219
- "link": "xoziZG_link",
220
- "modelTokens": "xoziZG_modelTokens",
221
- "fieldLabel": "xoziZG_fieldLabel",
222
- "error": "xoziZG_error",
223
- "name": "xoziZG_name",
224
- "usageFill": "xoziZG_usageFill",
225
- "heatLegend": "xoziZG_heatLegend",
226
- "check": "xoziZG_check",
227
- "concurrencyStepper": "xoziZG_concurrencyStepper",
228
- "tabPanel": "xoziZG_tabPanel",
229
246
  "windowButtonOpen": "xoziZG_windowButtonOpen",
230
- "modelCheck": "xoziZG_modelCheck",
231
- "accountClearHint": "xoziZG_accountClearHint",
232
- "balanceUnit": "xoziZG_balanceUnit",
233
- "accountToolbar": "xoziZG_accountToolbar",
234
- "manual": "xoziZG_manual",
235
- "windowSection": "xoziZG_windowSection",
236
- "accountCard": "xoziZG_accountCard",
237
- "modelName": "xoziZG_modelName",
238
- "heatGrid": "xoziZG_heatGrid",
239
- "accountConcurrencyInline": "xoziZG_accountConcurrencyInline",
240
- "windowInput": "xoziZG_windowInput",
241
- "section": "xoziZG_section",
242
- "skeleton": "xoziZG_skeleton",
243
- "headText": "xoziZG_headText",
244
- "hint": "xoziZG_hint",
245
- "modelMeta": "xoziZG_modelMeta",
246
247
  "expiryRow": "xoziZG_expiryRow",
247
- "creditFooter": "xoziZG_creditFooter",
248
- "modelTrack": "xoziZG_modelTrack",
249
- "accountEntry": "xoziZG_accountEntry",
250
- "accountMenu": "xoziZG_accountMenu",
251
- "concurrencyValue": "xoziZG_concurrencyValue",
252
- "usageTipSep": "xoziZG_usageTipSep",
253
- "modelRow": "xoziZG_modelRow",
254
- "modelShare": "xoziZG_modelShare",
255
- "manualForm": "xoziZG_manualForm",
256
- "heatHourCell": "xoziZG_heatHourCell",
257
- "usageTip": "xoziZG_usageTip",
258
- "statValue": "xoziZG_statValue",
248
+ "skeletonBreath": "xoziZG_skeletonBreath",
259
249
  "creditHint": "xoziZG_creditHint",
260
- "doctorList": "xoziZG_doctorList",
261
- "choiceRow": "xoziZG_choiceRow",
262
- "desc": "xoziZG_desc",
250
+ "creditRows": "xoziZG_creditRows",
251
+ "heatWeekday": "xoziZG_heatWeekday",
252
+ "modelChart": "xoziZG_modelChart",
253
+ "windowHint": "xoziZG_windowHint",
254
+ "hint": "xoziZG_hint",
255
+ "trendTip": "xoziZG_trendTip",
256
+ "windowSection": "xoziZG_windowSection",
257
+ "modelMeta": "xoziZG_modelMeta",
263
258
  "choiceTail": "xoziZG_choiceTail",
264
- "heatAxis": "xoziZG_heatAxis",
265
259
  "modelRequests": "xoziZG_modelRequests",
266
- "heatHours": "xoziZG_heatHours",
267
- "accountMenuItem": "xoziZG_accountMenuItem",
260
+ "accountMenuAnchor": "xoziZG_accountMenuAnchor",
261
+ "balanceRow": "xoziZG_balanceRow",
262
+ "modelTrack": "xoziZG_modelTrack",
263
+ "accountConcurrencyInline": "xoziZG_accountConcurrencyInline",
264
+ "creditRow": "xoziZG_creditRow",
265
+ "tabs": "xoziZG_tabs",
266
+ "body": "xoziZG_body",
267
+ "header": "xoziZG_header",
268
+ "accountEntry": "xoziZG_accountEntry",
269
+ "accountToolbar": "xoziZG_accountToolbar",
268
270
  "accountToggle": "xoziZG_accountToggle",
271
+ "accountClearHint": "xoziZG_accountClearHint",
272
+ "section": "xoziZG_section",
273
+ "check": "xoziZG_check",
269
274
  "meta": "xoziZG_meta",
270
- "accountRow": "xoziZG_accountRow",
271
- "statCard": "xoziZG_statCard",
272
- "windowAnchor": "xoziZG_windowAnchor",
273
- "concurrencyButton": "xoziZG_concurrencyButton",
274
- "windowButtonSet": "xoziZG_windowButtonSet",
275
- "accountClear": "xoziZG_accountClear",
276
- "doctorRow": "xoziZG_doctorRow",
277
- "windowCaret": "xoziZG_windowCaret",
278
- "header": "xoziZG_header",
275
+ "doctorList": "xoziZG_doctorList",
279
276
  "card": "xoziZG_card",
280
- "balance": "xoziZG_balance",
281
- "barFill": "xoziZG_barFill",
277
+ "heatCell": "xoziZG_heatCell",
278
+ "windowInput": "xoziZG_windowInput",
279
+ "windowButton": "xoziZG_windowButton",
280
+ "count": "xoziZG_count",
282
281
  "windowPopover": "xoziZG_windowPopover",
282
+ "link": "xoziZG_link",
283
283
  "avatar": "xoziZG_avatar",
284
284
  "windowPopoverValue": "xoziZG_windowPopoverValue",
285
- "accountMenuAnchor": "xoziZG_accountMenuAnchor",
286
- "balanceMeta": "xoziZG_balanceMeta",
287
- "choices": "xoziZG_choices",
288
- "accountInfo": "xoziZG_accountInfo",
285
+ "windowRange": "xoziZG_windowRange",
289
286
  "accountConcurrencyLabel": "xoziZG_accountConcurrencyLabel",
290
- "bar": "xoziZG_bar",
291
- "groupHead": "xoziZG_groupHead",
292
- "statLabel": "xoziZG_statLabel",
287
+ "modelName": "xoziZG_modelName",
288
+ "name": "xoziZG_name",
289
+ "balance": "xoziZG_balance",
290
+ "tabPanel": "xoziZG_tabPanel",
293
291
  "doctorName": "xoziZG_doctorName",
294
- "usageBar": "xoziZG_usageBar",
295
- "balanceRow": "xoziZG_balanceRow",
296
- "accountRowActions": "xoziZG_accountRowActions",
297
- "groupHeadFirst": "xoziZG_groupHeadFirst",
298
- "expiryLabel": "xoziZG_expiryLabel",
299
- "tabs": "xoziZG_tabs",
300
- "actions": "xoziZG_actions",
301
- "skeletonBreath": "xoziZG_skeletonBreath",
292
+ "desc": "xoziZG_desc",
293
+ "accountCard": "xoziZG_accountCard",
294
+ "accountNameRow": "xoziZG_accountNameRow",
295
+ "statCard": "xoziZG_statCard",
296
+ "claimAllRow": "xoziZG_claimAllRow",
297
+ "heatAxis": "xoziZG_heatAxis",
298
+ "usageFill": "xoziZG_usageFill",
299
+ "modelCheck": "xoziZG_modelCheck",
300
+ "error": "xoziZG_error",
301
+ "modelShare": "xoziZG_modelShare",
302
+ "sectionHead": "xoziZG_sectionHead",
303
+ "windowCaret": "xoziZG_windowCaret",
304
+ "accountMenu": "xoziZG_accountMenu",
305
+ "headText": "xoziZG_headText",
306
+ "creditBlock": "xoziZG_creditBlock",
307
+ "balanceUnit": "xoziZG_balanceUnit",
308
+ "manualSummary": "xoziZG_manualSummary",
309
+ "accountRow": "xoziZG_accountRow",
310
+ "choices": "xoziZG_choices",
311
+ "modelTokens": "xoziZG_modelTokens",
312
+ "windowPopoverHead": "xoziZG_windowPopoverHead",
313
+ "doctorRow": "xoziZG_doctorRow",
314
+ "usageTip": "xoziZG_usageTip",
315
+ "windowInputSet": "xoziZG_windowInputSet",
302
316
  "danger": "xoziZG_danger",
303
- "statSub": "xoziZG_statSub",
304
- "modelChart": "xoziZG_modelChart",
305
- "usageTipRow": "xoziZG_usageTipRow",
306
- "sectionLabel": "xoziZG_sectionLabel",
307
- "accountName": "xoziZG_accountName",
308
- "accountGrid": "xoziZG_accountGrid",
309
- "modelFill": "xoziZG_modelFill",
310
- "skeletonRow": "xoziZG_skeletonRow",
311
- "statGrid": "xoziZG_statGrid",
312
- "statusLine": "xoziZG_statusLine",
313
- "accountHint": "xoziZG_accountHint",
314
- "creditRows": "xoziZG_creditRows",
315
- "creditLink": "xoziZG_creditLink",
316
- "trendTip": "xoziZG_trendTip",
317
- "groupLabel": "xoziZG_groupLabel",
318
- "heatWeekday": "xoziZG_heatWeekday",
319
- "windowPopoverHead": "xoziZG_windowPopoverHead"
317
+ "accountClear": "xoziZG_accountClear",
318
+ "heatHours": "xoziZG_heatHours",
319
+ "heatHourCell": "xoziZG_heatHourCell"
320
320
  };
321
321
  //#endregion
322
322
  //#region src/client/CodeArtsPluginCard.tsx
@@ -3648,13 +3648,13 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
3648
3648
  document.head.appendChild(tag);
3649
3649
  }
3650
3650
  var CodeArtsPanel_module_css_default = {
3651
- "desc": "Z66cgG_desc",
3652
- "body": "Z66cgG_body",
3653
- "back": "Z66cgG_back",
3654
- "icon": "Z66cgG_icon",
3655
- "backCaret": "Z66cgG_backCaret",
3656
3651
  "title": "Z66cgG_title",
3657
3652
  "head": "Z66cgG_head",
3653
+ "backCaret": "Z66cgG_backCaret",
3654
+ "back": "Z66cgG_back",
3655
+ "body": "Z66cgG_body",
3656
+ "icon": "Z66cgG_icon",
3657
+ "desc": "Z66cgG_desc",
3658
3658
  "page": "Z66cgG_page"
3659
3659
  };
3660
3660
  //#endregion
package/lib/index.d.mts CHANGED
@@ -1366,6 +1366,21 @@ declare class CodeArtsAccountPool {
1366
1366
  * subagent)必然误伤;现在与上游排队对齐 —— 先短时等待,等不到再报错。
1367
1367
  */
1368
1368
  waitForFreeSlot(maxWaitMs: number, signal?: AbortSignal): Promise<boolean>;
1369
+ /**
1370
+ * 最近一个冷却账号的解冻时刻(epoch ms);没有冷却中的号返回 undefined。
1371
+ *
1372
+ * 与「槽位满」不同:解冻时刻是池子自己记的倒计时,精确已知 —— 值得内联等到
1373
+ * 那一刻再发,而不是立刻回 429 让宿主在冷却窗里盲退避(issue #22)。禁用/暂停
1374
+ * 的号不会自己恢复,不参与。
1375
+ */
1376
+ earliestCooldownEnd(): number | undefined;
1377
+ /**
1378
+ * 睡到最近一个冷却账号解冻,最多 `maxWaitMs`。
1379
+ *
1380
+ * 返回 true = 已经醒了(可能刚好到解冻时刻);false = 没有冷却中的号、预算不够
1381
+ * 或等待被中止。调用方醒后要重新走一遍选号:解冻的号可能又发了新请求。
1382
+ */
1383
+ waitForCooldownEnd(maxWaitMs: number, signal?: AbortSignal): Promise<boolean>;
1369
1384
  /**
1370
1385
  * 撞到上游并发上限。
1371
1386
  *
package/lib/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { a as codeartsAuthPath, c as credentialFromOAuth, g as startLogin, i as codeartsAccountsPath, n as CodeArtsCredentialStore, o as codeartsDebugLogPath, r as MANUAL_ACCOUNT_ID, s as codeartsRefreshLogPath, t as CodeArtsAccountStore } from "./auth-fN1w-DqH.mjs";
2
- import { A as overrideValueFor, B as CodeArtsCatalog, C as isQueueableRate, D as learnedContextWindowFor, E as learnContextWindow, F as setMaxTokenOverride, G as filterEnabledModels, I as setMaxTokenOverrides, J as isBenefitModel, K as forgetModelUnavailable, L as signedGet, M as prepareChatBody, N as queueFrame, O as maxTokensCeilingFor, P as rateLimitFrame, Q as modelUnavailableReason, R as upstreamErrorMessage, S as isQueueRejectText, T as isWelfareClaimedStatus, U as clearBenefitBlocked, V as FALLBACK_CODEARTS_MODELS, W as creditRatioLabel, Y as markModelUnavailable, _ as isIamTokenError, a as claimDailyWelfare, b as isParamInvalidFrame, c as degradeTokenCeiling, d as fetchQueueStatus, et as withContextWindowOverride, f as fetchWelfareCampaigns, g as isCreditExhausted, h as isContextOverflowText, i as chatStream, j as pickDailyWelfareCampaign, k as modelUnavailableReasonText, l as fetchCallerIdentity, m as isConcurrencyCap, n as SNAP_HOST, o as clearQueueStatus, p as firstFrameError, q as isBenefitBlocked, r as canonicalModel, s as contextWindowOverrideFor, t as MAX_TOKENS_FLOOR, tt as withMaxTokensOverride, u as fetchModels, v as isModelNotAccessible, w as isTpmLimit, x as isQueueReject, y as isNotMultimodal } from "./upstream-DA3AC1mv.mjs";
3
- import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DcfKEx5Z.mjs";
1
+ import { a as codeartsAuthPath, c as credentialFromOAuth, g as startLogin, i as codeartsAccountsPath, n as CodeArtsCredentialStore, o as codeartsDebugLogPath, r as MANUAL_ACCOUNT_ID, s as codeartsRefreshLogPath, t as CodeArtsAccountStore } from "./auth-qnSuuDGW.mjs";
2
+ import { A as overrideValueFor, B as CodeArtsCatalog, C as isQueueableRate, D as learnedContextWindowFor, E as learnContextWindow, F as setMaxTokenOverride, G as filterEnabledModels, I as setMaxTokenOverrides, J as isBenefitModel, K as forgetModelUnavailable, L as signedGet, M as prepareChatBody, N as queueFrame, O as maxTokensCeilingFor, P as rateLimitFrame, Q as modelUnavailableReason, R as upstreamErrorMessage, S as isQueueRejectText, T as isWelfareClaimedStatus, U as clearBenefitBlocked, V as FALLBACK_CODEARTS_MODELS, W as creditRatioLabel, Y as markModelUnavailable, _ as isIamTokenError, a as claimDailyWelfare, b as isParamInvalidFrame, c as degradeTokenCeiling, d as fetchQueueStatus, et as withContextWindowOverride, f as fetchWelfareCampaigns, g as isCreditExhausted, h as isContextOverflowText, i as chatStream, j as pickDailyWelfareCampaign, k as modelUnavailableReasonText, l as fetchCallerIdentity, m as isConcurrencyCap, n as SNAP_HOST, o as clearQueueStatus, p as firstFrameError, q as isBenefitBlocked, r as canonicalModel, s as contextWindowOverrideFor, t as MAX_TOKENS_FLOOR, tt as withMaxTokensOverride, u as fetchModels, v as isModelNotAccessible, w as isTpmLimit, x as isQueueReject, y as isNotMultimodal } from "./upstream-D1NN-sbL.mjs";
3
+ import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-BJniJ4eN.mjs";
4
4
  import { i as lazyApi, r as createProvider } from "./models-CgKCibpk.mjs";
5
5
  import { c as keeperLogPath, f as keeperStats, i as clearKeeperHandoff, l as keeperNextPassAt, m as stopKeeper, n as KEEPER_STALE_MS, p as spawnKeeper, s as keeperHandoffRecent, u as keeperScriptPath } from "./keeper-BWHQDFAh.mjs";
6
6
  import { appendFileSync, statSync, writeFileSync } from "node:fs";
@@ -33,6 +33,8 @@ const CAP_SAMPLE_MIN_MS = 5e3;
33
33
  const CAP_SAMPLE_MAX_MS = 12e4;
34
34
  /** 参与中位数的最近样本数。 */
35
35
  const CAP_SAMPLE_KEEP = 5;
36
+ /** 睡到解冻时刻后再多醒一点,防止定时器抖动导致醒来时 `coolUntil` 还差几毫秒。 */
37
+ const COOLDOWN_WAKE_EPSILON_MS = 250;
36
38
  /**
37
39
  * 这个号的「优先避开」窗口:量到过就用实测中位数,没量过用默认提示。
38
40
  *
@@ -256,6 +258,48 @@ var CodeArtsAccountPool = class {
256
258
  });
257
259
  }
258
260
  /**
261
+ * 最近一个冷却账号的解冻时刻(epoch ms);没有冷却中的号返回 undefined。
262
+ *
263
+ * 与「槽位满」不同:解冻时刻是池子自己记的倒计时,精确已知 —— 值得内联等到
264
+ * 那一刻再发,而不是立刻回 429 让宿主在冷却窗里盲退避(issue #22)。禁用/暂停
265
+ * 的号不会自己恢复,不参与。
266
+ */
267
+ earliestCooldownEnd() {
268
+ const now = this.now();
269
+ let soonest;
270
+ for (const account of this.accounts.values()) {
271
+ if (account.disabled || this.paused.has(account.id) || account.coolUntil <= now) continue;
272
+ if (soonest === void 0 || account.coolUntil < soonest) soonest = account.coolUntil;
273
+ }
274
+ return soonest;
275
+ }
276
+ /**
277
+ * 睡到最近一个冷却账号解冻,最多 `maxWaitMs`。
278
+ *
279
+ * 返回 true = 已经醒了(可能刚好到解冻时刻);false = 没有冷却中的号、预算不够
280
+ * 或等待被中止。调用方醒后要重新走一遍选号:解冻的号可能又发了新请求。
281
+ */
282
+ waitForCooldownEnd(maxWaitMs, signal) {
283
+ const thawAt = this.earliestCooldownEnd();
284
+ if (thawAt === void 0 || maxWaitMs <= 0) return Promise.resolve(false);
285
+ if (signal?.aborted === true) return Promise.resolve(false);
286
+ const waitMs = Math.min(maxWaitMs, Math.max(0, thawAt - this.now()));
287
+ return new Promise((resolve) => {
288
+ let settled = false;
289
+ const finish = (value) => {
290
+ if (settled) return;
291
+ settled = true;
292
+ clearTimeout(timer);
293
+ signal?.removeEventListener("abort", onAbort);
294
+ resolve(value);
295
+ };
296
+ const onAbort = () => finish(false);
297
+ const timer = setTimeout(() => finish(true), waitMs + COOLDOWN_WAKE_EPSILON_MS);
298
+ timer.unref?.();
299
+ signal?.addEventListener("abort", onAbort, { once: true });
300
+ });
301
+ }
302
+ /**
259
303
  * 撞到上游并发上限。
260
304
  *
261
305
  * **不冷却账号** —— 账号没坏,只是会话槽位暂时满了(约 52 秒释放)。冷却会
@@ -1211,6 +1255,11 @@ const MAX_CEILING_HEALS = 3;
1211
1255
  */
1212
1256
  const ROTATE_MIN_ATTEMPTS = 3;
1213
1257
  const ROTATE_MAX_ATTEMPTS = 6;
1258
+ /**
1259
+ * 轮换最多跑几轮:每轮重新按账号试一遍。轮间要么等本地槽位释放(槽满),
1260
+ * 要么等冷却到点解冻(全在冷却)—— 两种都会让时间往前走,所以是有限的。
1261
+ */
1262
+ const ROTATE_MAX_ROUNDS = 3;
1214
1263
  /** 开始下一次尝试前必须留下的预算:一次挂号短探(默认 5 秒)再加一次开流。 */
1215
1264
  const ATTEMPT_RESERVE_MS = 2e4;
1216
1265
  /**
@@ -1605,6 +1654,7 @@ function createCodeArtsShim(options) {
1605
1654
  let queuedAccount;
1606
1655
  let queueWaitedMs = 0;
1607
1656
  let localSlotWaitedMs = 0;
1657
+ let cooldownWaitedMs = 0;
1608
1658
  let lastKind;
1609
1659
  let lastAccountId;
1610
1660
  let lastStatus = 0;
@@ -1618,7 +1668,7 @@ function createCodeArtsShim(options) {
1618
1668
  * 再跑第二轮。以前这里直接落到「没有可用账号」的 429,并发派发(一次 5 个
1619
1669
  * subagent)必然误伤(issue #8)。
1620
1670
  */
1621
- for (let round = 0; round < 2; round += 1) {
1671
+ for (let round = 0; round < ROTATE_MAX_ROUNDS; round += 1) {
1622
1672
  tried.clear();
1623
1673
  for (let attempt = 0; attempt < attempts; attempt += 1) {
1624
1674
  if (Date.now() + ATTEMPT_RESERVE_MS > rotateDeadline) break;
@@ -1705,7 +1755,19 @@ function createCodeArtsShim(options) {
1705
1755
  }
1706
1756
  }
1707
1757
  if (lastKind !== void 0 || controller.signal.aborted) break;
1708
- if (!pool.hasBusyWaitable()) break;
1758
+ if (!pool.hasBusyWaitable()) {
1759
+ const thawAt = pool.earliestCooldownEnd();
1760
+ const thawBudget = rotateDeadline - ATTEMPT_RESERVE_MS - Date.now();
1761
+ if (thawAt === void 0 || thawBudget <= 0) break;
1762
+ if (thawAt - Date.now() > thawBudget) break;
1763
+ const coolingSince = Date.now();
1764
+ debug?.(`cooldown wait start req=${requestTag} thawIn=${thawAt - coolingSince}ms`);
1765
+ const thawed = await pool.waitForCooldownEnd(thawBudget, controller.signal);
1766
+ cooldownWaitedMs += Date.now() - coolingSince;
1767
+ debug?.(`cooldown wait ${thawed ? "done" : "timeout"} req=${requestTag} waited=${Date.now() - coolingSince}ms`);
1768
+ if (!thawed) break;
1769
+ continue;
1770
+ }
1709
1771
  const waitBudget = Math.min(localSlotWaitBudgetMs, rotateDeadline - ATTEMPT_RESERVE_MS - Date.now());
1710
1772
  if (waitBudget <= 0) break;
1711
1773
  const waitingSince = Date.now();
@@ -1761,6 +1823,7 @@ function createCodeArtsShim(options) {
1761
1823
  const waits = [];
1762
1824
  if (queueWaitedMs >= 1e3) waits.push(`排队重试 ${Math.round(queueWaitedMs / 1e3)} 秒`);
1763
1825
  if (localSlotWaitedMs >= 1e3) waits.push(`等本地槽位 ${Math.round(localSlotWaitedMs / 1e3)} 秒`);
1826
+ if (cooldownWaitedMs >= 1e3) waits.push(`等冷却解冻 ${Math.round(cooldownWaitedMs / 1e3)} 秒`);
1764
1827
  const waited = waits.length > 0 ? `(本地已${waits.join("、")})` : "";
1765
1828
  const failedKind = isQueueRejectText(lastMessage) ? "queued" : lastKind;
1766
1829
  usage?.noteFailure(failedKind, lastAccountId);
@@ -1,4 +1,4 @@
1
- import { d as refreshLockPath, f as withRefreshLock, h as refreshToken, i as codeartsAccountsPath, l as readAccountDocument, m as defaultLoginConfig, p as OAuthTokenError, u as writeJsonAtomic } from "./auth-fN1w-DqH.mjs";
1
+ import { d as refreshLockPath, f as withRefreshLock, h as refreshToken, i as codeartsAccountsPath, l as readAccountDocument, m as defaultLoginConfig, p as OAuthTokenError, u as writeJsonAtomic } from "./auth-qnSuuDGW.mjs";
2
2
  import { _ as writeKeeperState, a as clearKeeperState, c as keeperLogPath, d as keeperStatePath, f as keeperStats, g as writeKeeperHandoff, h as stopRequested, i as clearKeeperHandoff, o as isDshInstallerTempDir, r as KEEPER_TICK_MS, t as KEEPER_HEARTBEAT_MS } from "./keeper-BWHQDFAh.mjs";
3
3
  import { appendFileSync, existsSync, unlinkSync, watch } from "node:fs";
4
4
  import { dirname, join } from "node:path";
@@ -1,5 +1,8 @@
1
1
  import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.mjs";
2
2
  import { createHash, createHmac, randomBytes } from "node:crypto";
3
+ import { request } from "node:http";
4
+ import { request as request$1 } from "node:https";
5
+ import { Readable } from "node:stream";
3
6
  //#region src/catalog.ts
4
7
  /**
5
8
  * 参数表(不是模型名单):只给**发现到的**模型补 `contextWindow` / `maxTokens` /
@@ -1384,12 +1387,63 @@ async function dispatch(req, body, signal) {
1384
1387
  req.headers.forEach((value, key) => {
1385
1388
  headers[key] = value;
1386
1389
  });
1387
- return fetch(req.url, {
1390
+ const res = await fetch(req.url, {
1388
1391
  method: req.method,
1389
1392
  headers,
1390
1393
  ...body === void 0 ? {} : { body },
1391
1394
  ...signal === void 0 ? {} : { signal }
1392
1395
  });
1396
+ if (!isNeighborGateRefusal(res)) return res;
1397
+ await res.body?.cancel().catch(() => {});
1398
+ return dispatchDirect(req.url, req.method, headers, body, signal);
1399
+ }
1400
+ /**
1401
+ * billion-context 这类宿主层压缩代理会**在本地**拒收「不属于 bili 会话、又超过
1402
+ * 静默直连字节上限」的请求(实测上限 8 MiB),回 422 + `x-bili-gate:
1403
+ * oversize-refusal*`,根本没出网(issue #23)。它的拦截只挂在 `globalThis.fetch`
1404
+ * 上,所以收到这个标记时换一份自己的 node:http(s) 连接直发 —— 签名与请求体
1405
+ * 都不变,只是不再经过这层代理。
1406
+ *
1407
+ * 只认它自己的标记头:真正的上游 422 不带这个头,照常按 no_live_state 等
1408
+ * 分类处理。
1409
+ */
1410
+ function isNeighborGateRefusal(res) {
1411
+ if (res.status !== 422) return false;
1412
+ return (res.headers.get("x-bili-gate") ?? "").startsWith("oversize-refusal");
1413
+ }
1414
+ /** 绕开 `globalThis.fetch` 的直连发送;响应流原样转成 web Response。 */
1415
+ function dispatchDirect(url, method, headers, body, signal) {
1416
+ const target = new URL(url);
1417
+ const send = target.protocol === "http:" ? request : request$1;
1418
+ return new Promise((resolve, reject) => {
1419
+ if (signal?.aborted === true) {
1420
+ reject(/* @__PURE__ */ new Error("This operation was aborted"));
1421
+ return;
1422
+ }
1423
+ const req = send(target, {
1424
+ method,
1425
+ headers
1426
+ }, (res) => {
1427
+ const stream = Readable.toWeb(res);
1428
+ resolve(new Response(stream, {
1429
+ status: res.statusCode ?? 502,
1430
+ headers: res.headers
1431
+ }));
1432
+ });
1433
+ const onAbort = () => {
1434
+ const error = /* @__PURE__ */ new Error("This operation was aborted");
1435
+ error.name = "AbortError";
1436
+ req.destroy(error);
1437
+ };
1438
+ signal?.addEventListener("abort", onAbort, { once: true });
1439
+ req.on("error", (error) => {
1440
+ signal?.removeEventListener("abort", onAbort);
1441
+ reject(error);
1442
+ });
1443
+ req.on("close", () => signal?.removeEventListener("abort", onAbort));
1444
+ if (body !== void 0) req.write(body);
1445
+ req.end();
1446
+ });
1393
1447
  }
1394
1448
  const enc = new TextEncoder();
1395
1449
  function openAIData(obj) {
@@ -1,5 +1,5 @@
1
- import { u as writeJsonAtomic } from "./auth-fN1w-DqH.mjs";
2
- import { $ as setDiscoveredBenefitModels, H as carryKnownWindows, J as isBenefitModel, X as mergeModelLists, Z as modelDisplayName, u as fetchModels } from "./upstream-DA3AC1mv.mjs";
1
+ import { u as writeJsonAtomic } from "./auth-qnSuuDGW.mjs";
2
+ import { $ as setDiscoveredBenefitModels, H as carryKnownWindows, J as isBenefitModel, X as mergeModelLists, Z as modelDisplayName, u as fetchModels } from "./upstream-D1NN-sbL.mjs";
3
3
  import { existsSync } from "node:fs";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { homedir } from "node:os";
@@ -536,6 +536,6 @@ function percentileOf(buckets, ratio) {
536
536
  }
537
537
  //#endregion
538
538
  //#region src/version.ts
539
- const CODEARTS_VERSION = "1.4.14";
539
+ const CODEARTS_VERSION = "1.4.15";
540
540
  //#endregion
541
541
  export { refreshCatalog as a, discoverModels as i, CodeArtsUsageTracker as n, codeartsUsagePath as r, CODEARTS_VERSION as t };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-codearts",
3
3
  "displayName": "DSH CodeArts Connect",
4
4
  "description": "把华为云 CodeArts 接入 DeepSeek Harness —— 内置 OAuth2 登录(PKCE + DPoP),登录后即可在 DSH 对话窗口使用 CodeArts 的模型。",
5
- "version": "1.4.14",
5
+ "version": "1.4.15",
6
6
  "packageManager": "pnpm@11.24.0",
7
7
  "author": "elegant01",
8
8
  "keywords": [