dsh-codearts 1.4.14 → 1.4.16
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 +32 -0
- package/lib/{auth-fN1w-DqH.mjs → auth-T5qnGSPp.mjs} +1 -1
- package/lib/bin.mjs +3 -3
- package/lib/client/index.js +107 -107
- package/lib/index.d.mts +16 -1
- package/lib/index.mjs +106 -7
- package/lib/keeper-main.mjs +1 -1
- package/lib/{upstream-DA3AC1mv.mjs → upstream-Cr5tUI75.mjs} +73 -1
- package/lib/{version-DcfKEx5Z.mjs → version-CxhGukAi.mjs} +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.16] - 2026-11-30
|
|
7
|
+
|
|
8
|
+
### 优化
|
|
9
|
+
|
|
10
|
+
- **5xx 冷却单独取短值、连续失败递增**(#22 辅建议):上游 5xx 多为瞬时抖动,
|
|
11
|
+
首次只冷却 4 秒,连续 5xx 按倍数递增、封顶到软限流的 30 秒;软限流与 IAM
|
|
12
|
+
失效仍保持 30 秒,任何非 5xx 结果清零连续计数。内联等待落地后冷却时长就是
|
|
13
|
+
用户实打实的等待,缩短 5xx 冷却可直接省掉白等的时间。
|
|
14
|
+
|
|
15
|
+
### 修复
|
|
16
|
+
|
|
17
|
+
- **API 网关限流(APIG.0308)单独冷却、报文改中文**(#22 后续):上游 API 网关
|
|
18
|
+
的 429(`policy user over ratelimit, limit:100, time:1 minute`)以前与后端软
|
|
19
|
+
限流共用 30 秒冷却,短于网关 1 分钟窗口,可能「解冻即再撞」。现在本地识别该
|
|
20
|
+
错误码与措辞,冷却 65 秒盖过窗口,报文给出中文说明,不再透传网关英文原文。
|
|
21
|
+
纯本地退避,不涉及任何上游操作。
|
|
22
|
+
|
|
23
|
+
## [1.4.15] - 2026-11-27
|
|
24
|
+
|
|
25
|
+
### 修复
|
|
26
|
+
|
|
27
|
+
- **冷却期不再把请求打回宿主盲退避**(#22):账号全在冷却时,以前立刻回 429,
|
|
28
|
+
而解冻时刻插件自己精确知道(冷却最长 30 秒)—— 落在冷却窗内的宿主重试注定
|
|
29
|
+
失败,一次上游 5xx 会被放大成一串失败记录。现在轮换在两轮之间内联等到最近
|
|
30
|
+
一个号解冻再发;超过轮换截止点的冷却(例如积分耗尽的 30 分钟)仍立即报错,
|
|
31
|
+
并写明本地已等冷却多少秒。
|
|
32
|
+
- **与 billion-context 共存时的大请求不再被拒**(#23):bili 会对「未归属会话、
|
|
33
|
+
又超过静默直连上限(8 MiB)」的请求在本地回 422 + `x-bili-gate:
|
|
34
|
+
oversize-refusal*`,根本没出网。现在认出这个标记后改走插件自己的
|
|
35
|
+
`node:http(s)` 连接直发,签名与请求体原样保留;真正的上游 422 不带该标记头,
|
|
36
|
+
仍按原分类处理。
|
|
37
|
+
|
|
6
38
|
## [1.4.14] - 2026-11-26
|
|
7
39
|
|
|
8
40
|
### 修复
|
|
@@ -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-
|
|
587
|
+
const { claimBenefit } = await import("./upstream-Cr5tUI75.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-
|
|
3
|
-
import { J as isBenefitModel, l as fetchCallerIdentity } from "./upstream-
|
|
4
|
-
import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-
|
|
2
|
+
import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-T5qnGSPp.mjs";
|
|
3
|
+
import { J as isBenefitModel, l as fetchCallerIdentity } from "./upstream-Cr5tUI75.mjs";
|
|
4
|
+
import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-CxhGukAi.mjs";
|
|
5
5
|
import { existsSync, statSync } from "node:fs";
|
|
6
6
|
//#region src/bin.ts
|
|
7
7
|
/**
|
package/lib/client/index.js
CHANGED
|
@@ -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
|
-
"
|
|
198
|
-
"count": "xoziZG_count",
|
|
199
|
-
"windowUnit": "xoziZG_windowUnit",
|
|
200
|
-
"area": "xoziZG_area",
|
|
197
|
+
"hint": "xoziZG_hint",
|
|
201
198
|
"creditBlock": "xoziZG_creditBlock",
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
"
|
|
206
|
-
"heatLegendChip": "xoziZG_heatLegendChip",
|
|
207
|
-
"windowRange": "xoziZG_windowRange",
|
|
199
|
+
"windowButtonSet": "xoziZG_windowButtonSet",
|
|
200
|
+
"creditLink": "xoziZG_creditLink",
|
|
201
|
+
"headText": "xoziZG_headText",
|
|
202
|
+
"groupHeadFirst": "xoziZG_groupHeadFirst",
|
|
208
203
|
"sectionHead": "xoziZG_sectionHead",
|
|
209
|
-
"
|
|
210
|
-
"heatCell": "xoziZG_heatCell",
|
|
211
|
-
"creditRow": "xoziZG_creditRow",
|
|
212
|
-
"windowButton": "xoziZG_windowButton",
|
|
213
|
-
"windowPopoverRow": "xoziZG_windowPopoverRow",
|
|
214
|
-
"field": "xoziZG_field",
|
|
215
|
-
"accountNameRow": "xoziZG_accountNameRow",
|
|
216
|
-
"updated": "xoziZG_updated",
|
|
217
|
-
"claimAllRow": "xoziZG_claimAllRow",
|
|
218
|
-
"windowHint": "xoziZG_windowHint",
|
|
204
|
+
"balanceUnit": "xoziZG_balanceUnit",
|
|
219
205
|
"link": "xoziZG_link",
|
|
206
|
+
"heatCell": "xoziZG_heatCell",
|
|
207
|
+
"skeletonBreath": "xoziZG_skeletonBreath",
|
|
208
|
+
"concurrencyStepper": "xoziZG_concurrencyStepper",
|
|
220
209
|
"modelTokens": "xoziZG_modelTokens",
|
|
210
|
+
"windowPopoverHead": "xoziZG_windowPopoverHead",
|
|
211
|
+
"statCard": "xoziZG_statCard",
|
|
212
|
+
"skeleton": "xoziZG_skeleton",
|
|
213
|
+
"modelSpec": "xoziZG_modelSpec",
|
|
214
|
+
"accountToggle": "xoziZG_accountToggle",
|
|
215
|
+
"manualForm": "xoziZG_manualForm",
|
|
216
|
+
"windowInput": "xoziZG_windowInput",
|
|
217
|
+
"usageTipName": "xoziZG_usageTipName",
|
|
221
218
|
"fieldLabel": "xoziZG_fieldLabel",
|
|
219
|
+
"windowPopoverValue": "xoziZG_windowPopoverValue",
|
|
220
|
+
"modelCheck": "xoziZG_modelCheck",
|
|
221
|
+
"balance": "xoziZG_balance",
|
|
222
|
+
"windowRange": "xoziZG_windowRange",
|
|
223
|
+
"sectionLabel": "xoziZG_sectionLabel",
|
|
224
|
+
"danger": "xoziZG_danger",
|
|
225
|
+
"barFill": "xoziZG_barFill",
|
|
226
|
+
"creditFooter": "xoziZG_creditFooter",
|
|
227
|
+
"modelChart": "xoziZG_modelChart",
|
|
228
|
+
"heatAxis": "xoziZG_heatAxis",
|
|
222
229
|
"error": "xoziZG_error",
|
|
223
|
-
"
|
|
224
|
-
"
|
|
225
|
-
"
|
|
226
|
-
"
|
|
227
|
-
"
|
|
230
|
+
"header": "xoziZG_header",
|
|
231
|
+
"windowPopoverRow": "xoziZG_windowPopoverRow",
|
|
232
|
+
"trendTip": "xoziZG_trendTip",
|
|
233
|
+
"accountInfo": "xoziZG_accountInfo",
|
|
234
|
+
"heatAxisSlot": "xoziZG_heatAxisSlot",
|
|
235
|
+
"body": "xoziZG_body",
|
|
228
236
|
"tabPanel": "xoziZG_tabPanel",
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
"
|
|
237
|
+
"accountMenu": "xoziZG_accountMenu",
|
|
238
|
+
"expiryRow": "xoziZG_expiryRow",
|
|
239
|
+
"concurrencyButton": "xoziZG_concurrencyButton",
|
|
240
|
+
"area": "xoziZG_area",
|
|
241
|
+
"accountConcurrencyInline": "xoziZG_accountConcurrencyInline",
|
|
242
|
+
"accountRowActions": "xoziZG_accountRowActions",
|
|
243
|
+
"usageTip": "xoziZG_usageTip",
|
|
244
|
+
"claimAllRow": "xoziZG_claimAllRow",
|
|
245
|
+
"name": "xoziZG_name",
|
|
246
|
+
"bar": "xoziZG_bar",
|
|
247
|
+
"expiryLabel": "xoziZG_expiryLabel",
|
|
248
|
+
"choiceTail": "xoziZG_choiceTail",
|
|
233
249
|
"accountToolbar": "xoziZG_accountToolbar",
|
|
234
|
-
"
|
|
250
|
+
"windowButton": "xoziZG_windowButton",
|
|
235
251
|
"windowSection": "xoziZG_windowSection",
|
|
252
|
+
"check": "xoziZG_check",
|
|
253
|
+
"accountClearHint": "xoziZG_accountClearHint",
|
|
236
254
|
"accountCard": "xoziZG_accountCard",
|
|
237
|
-
"
|
|
238
|
-
"
|
|
239
|
-
"
|
|
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
|
-
"expiryRow": "xoziZG_expiryRow",
|
|
247
|
-
"creditFooter": "xoziZG_creditFooter",
|
|
248
|
-
"modelTrack": "xoziZG_modelTrack",
|
|
255
|
+
"choices": "xoziZG_choices",
|
|
256
|
+
"windowInputSet": "xoziZG_windowInputSet",
|
|
257
|
+
"windowAnchor": "xoziZG_windowAnchor",
|
|
249
258
|
"accountEntry": "xoziZG_accountEntry",
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
259
|
+
"heatLegend": "xoziZG_heatLegend",
|
|
260
|
+
"creditRow": "xoziZG_creditRow",
|
|
261
|
+
"modelTrack": "xoziZG_modelTrack",
|
|
262
|
+
"manualSummary": "xoziZG_manualSummary",
|
|
263
|
+
"statusLine": "xoziZG_statusLine",
|
|
264
|
+
"heatLegendChip": "xoziZG_heatLegendChip",
|
|
265
|
+
"accountName": "xoziZG_accountName",
|
|
266
|
+
"choiceRow": "xoziZG_choiceRow",
|
|
267
|
+
"balanceRow": "xoziZG_balanceRow",
|
|
268
|
+
"usageTipRow": "xoziZG_usageTipRow",
|
|
269
|
+
"balanceMeta": "xoziZG_balanceMeta",
|
|
270
|
+
"statLabel": "xoziZG_statLabel",
|
|
271
|
+
"usageFill": "xoziZG_usageFill",
|
|
272
|
+
"accountMenuAnchor": "xoziZG_accountMenuAnchor",
|
|
273
|
+
"accountClear": "xoziZG_accountClear",
|
|
274
|
+
"windowUnit": "xoziZG_windowUnit",
|
|
256
275
|
"heatHourCell": "xoziZG_heatHourCell",
|
|
257
|
-
"
|
|
276
|
+
"field": "xoziZG_field",
|
|
277
|
+
"windowHint": "xoziZG_windowHint",
|
|
278
|
+
"tabs": "xoziZG_tabs",
|
|
279
|
+
"avatar": "xoziZG_avatar",
|
|
280
|
+
"doctorRow": "xoziZG_doctorRow",
|
|
258
281
|
"statValue": "xoziZG_statValue",
|
|
282
|
+
"modelName": "xoziZG_modelName",
|
|
283
|
+
"manual": "xoziZG_manual",
|
|
284
|
+
"heatGrid": "xoziZG_heatGrid",
|
|
285
|
+
"updated": "xoziZG_updated",
|
|
259
286
|
"creditHint": "xoziZG_creditHint",
|
|
260
|
-
"
|
|
261
|
-
"choiceRow": "xoziZG_choiceRow",
|
|
262
|
-
"desc": "xoziZG_desc",
|
|
263
|
-
"choiceTail": "xoziZG_choiceTail",
|
|
264
|
-
"heatAxis": "xoziZG_heatAxis",
|
|
265
|
-
"modelRequests": "xoziZG_modelRequests",
|
|
266
|
-
"heatHours": "xoziZG_heatHours",
|
|
267
|
-
"accountMenuItem": "xoziZG_accountMenuItem",
|
|
268
|
-
"accountToggle": "xoziZG_accountToggle",
|
|
269
|
-
"meta": "xoziZG_meta",
|
|
287
|
+
"section": "xoziZG_section",
|
|
270
288
|
"accountRow": "xoziZG_accountRow",
|
|
271
|
-
"
|
|
272
|
-
"
|
|
273
|
-
"
|
|
274
|
-
"windowButtonSet": "xoziZG_windowButtonSet",
|
|
275
|
-
"accountClear": "xoziZG_accountClear",
|
|
276
|
-
"doctorRow": "xoziZG_doctorRow",
|
|
277
|
-
"windowCaret": "xoziZG_windowCaret",
|
|
278
|
-
"header": "xoziZG_header",
|
|
279
|
-
"card": "xoziZG_card",
|
|
280
|
-
"balance": "xoziZG_balance",
|
|
281
|
-
"barFill": "xoziZG_barFill",
|
|
289
|
+
"heatHours": "xoziZG_heatHours",
|
|
290
|
+
"groupLabel": "xoziZG_groupLabel",
|
|
291
|
+
"creditRows": "xoziZG_creditRows",
|
|
282
292
|
"windowPopover": "xoziZG_windowPopover",
|
|
283
|
-
"
|
|
284
|
-
"
|
|
285
|
-
"
|
|
286
|
-
"
|
|
287
|
-
"choices": "xoziZG_choices",
|
|
288
|
-
"accountInfo": "xoziZG_accountInfo",
|
|
289
|
-
"accountConcurrencyLabel": "xoziZG_accountConcurrencyLabel",
|
|
290
|
-
"bar": "xoziZG_bar",
|
|
291
|
-
"groupHead": "xoziZG_groupHead",
|
|
292
|
-
"statLabel": "xoziZG_statLabel",
|
|
293
|
-
"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",
|
|
293
|
+
"concurrencyValue": "xoziZG_concurrencyValue",
|
|
294
|
+
"count": "xoziZG_count",
|
|
295
|
+
"modelFill": "xoziZG_modelFill",
|
|
296
|
+
"desc": "xoziZG_desc",
|
|
300
297
|
"actions": "xoziZG_actions",
|
|
301
|
-
"
|
|
302
|
-
"
|
|
303
|
-
"
|
|
304
|
-
"
|
|
305
|
-
"
|
|
306
|
-
"
|
|
307
|
-
"accountName": "xoziZG_accountName",
|
|
298
|
+
"windowCaret": "xoziZG_windowCaret",
|
|
299
|
+
"doctorList": "xoziZG_doctorList",
|
|
300
|
+
"modelShare": "xoziZG_modelShare",
|
|
301
|
+
"statGrid": "xoziZG_statGrid",
|
|
302
|
+
"doctorName": "xoziZG_doctorName",
|
|
303
|
+
"windowButtonOpen": "xoziZG_windowButtonOpen",
|
|
308
304
|
"accountGrid": "xoziZG_accountGrid",
|
|
309
|
-
"
|
|
305
|
+
"card": "xoziZG_card",
|
|
306
|
+
"modelMeta": "xoziZG_modelMeta",
|
|
307
|
+
"usageBar": "xoziZG_usageBar",
|
|
308
|
+
"heatWeekday": "xoziZG_heatWeekday",
|
|
309
|
+
"modelRow": "xoziZG_modelRow",
|
|
310
|
+
"modelRequests": "xoziZG_modelRequests",
|
|
311
|
+
"accountMenuItem": "xoziZG_accountMenuItem",
|
|
310
312
|
"skeletonRow": "xoziZG_skeletonRow",
|
|
311
|
-
"
|
|
312
|
-
"
|
|
313
|
+
"groupHead": "xoziZG_groupHead",
|
|
314
|
+
"accountConcurrencyLabel": "xoziZG_accountConcurrencyLabel",
|
|
315
|
+
"usageTipSep": "xoziZG_usageTipSep",
|
|
313
316
|
"accountHint": "xoziZG_accountHint",
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"groupLabel": "xoziZG_groupLabel",
|
|
318
|
-
"heatWeekday": "xoziZG_heatWeekday",
|
|
319
|
-
"windowPopoverHead": "xoziZG_windowPopoverHead"
|
|
317
|
+
"meta": "xoziZG_meta",
|
|
318
|
+
"statSub": "xoziZG_statSub",
|
|
319
|
+
"accountNameRow": "xoziZG_accountNameRow"
|
|
320
320
|
};
|
|
321
321
|
//#endregion
|
|
322
322
|
//#region src/client/CodeArtsPluginCard.tsx
|
|
@@ -3648,14 +3648,14 @@ 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
3651
|
"body": "Z66cgG_body",
|
|
3653
|
-
"back": "Z66cgG_back",
|
|
3654
3652
|
"icon": "Z66cgG_icon",
|
|
3655
3653
|
"backCaret": "Z66cgG_backCaret",
|
|
3656
3654
|
"title": "Z66cgG_title",
|
|
3657
|
-
"
|
|
3658
|
-
"
|
|
3655
|
+
"desc": "Z66cgG_desc",
|
|
3656
|
+
"back": "Z66cgG_back",
|
|
3657
|
+
"page": "Z66cgG_page",
|
|
3658
|
+
"head": "Z66cgG_head"
|
|
3659
3659
|
};
|
|
3660
3660
|
//#endregion
|
|
3661
3661
|
//#region src/client/CodeArtsPanel.tsx
|
package/lib/index.d.mts
CHANGED
|
@@ -896,7 +896,7 @@ interface OAuthToken {
|
|
|
896
896
|
//#endregion
|
|
897
897
|
//#region src/upstream.d.ts
|
|
898
898
|
declare const SNAP_HOST = "https://snap-access.cn-north-4.myhuaweicloud.com";
|
|
899
|
-
type UpstreamErrorKind = 'hard_credit' | 'soft_rate' | 'session_dead' | 'iam_stale' | 'not_found' | 'server' | 'client';
|
|
899
|
+
type UpstreamErrorKind = 'hard_credit' | 'soft_rate' | 'gate_rate' | 'session_dead' | 'iam_stale' | 'not_found' | 'server' | 'client';
|
|
900
900
|
interface ChatResultOk {
|
|
901
901
|
ok: true;
|
|
902
902
|
/** 已转成 OpenAI 增量 SSE 的 ReadableStream(文本,data: ...\n\n)。 */
|
|
@@ -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-
|
|
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-
|
|
3
|
-
import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-
|
|
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-T5qnGSPp.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-Cr5tUI75.mjs";
|
|
3
|
+
import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-CxhGukAi.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 秒释放)。冷却会
|
|
@@ -1112,6 +1156,7 @@ const REQUEST_BODY_LIMIT = 67108864;
|
|
|
1112
1156
|
const KIND_STATUS = {
|
|
1113
1157
|
hard_credit: 402,
|
|
1114
1158
|
soft_rate: 429,
|
|
1159
|
+
gate_rate: 429,
|
|
1115
1160
|
session_dead: 401,
|
|
1116
1161
|
iam_stale: 401,
|
|
1117
1162
|
not_found: 502,
|
|
@@ -1211,6 +1256,11 @@ const MAX_CEILING_HEALS = 3;
|
|
|
1211
1256
|
*/
|
|
1212
1257
|
const ROTATE_MIN_ATTEMPTS = 3;
|
|
1213
1258
|
const ROTATE_MAX_ATTEMPTS = 6;
|
|
1259
|
+
/**
|
|
1260
|
+
* 轮换最多跑几轮:每轮重新按账号试一遍。轮间要么等本地槽位释放(槽满),
|
|
1261
|
+
* 要么等冷却到点解冻(全在冷却)—— 两种都会让时间往前走,所以是有限的。
|
|
1262
|
+
*/
|
|
1263
|
+
const ROTATE_MAX_ROUNDS = 3;
|
|
1214
1264
|
/** 开始下一次尝试前必须留下的预算:一次挂号短探(默认 5 秒)再加一次开流。 */
|
|
1215
1265
|
const ATTEMPT_RESERVE_MS = 2e4;
|
|
1216
1266
|
/**
|
|
@@ -1239,8 +1289,22 @@ const QUEUE_RETRY_GAP = 5e3;
|
|
|
1239
1289
|
const QUEUE_WAIT_LIMIT_MS = 9e5;
|
|
1240
1290
|
/** 空帧间隔:宿主按「可解析的流事件」算 90 秒空闲,20 秒留足余量。 */
|
|
1241
1291
|
const QUEUE_HEARTBEAT_MS = 2e4;
|
|
1242
|
-
/**
|
|
1292
|
+
/**
|
|
1293
|
+
* 软限流的冷却:上游实测真的会拒约 30 秒、且无 Retry-After 头(issue #22)。
|
|
1294
|
+
* 这是上游的罚站时长,不动。
|
|
1295
|
+
*/
|
|
1243
1296
|
const SERVER_COOLDOWN_MS = 3e4;
|
|
1297
|
+
/**
|
|
1298
|
+
* 上游 5xx 的首次冷却:5xx 多为瞬时抖动,几秒即恢复。借用软限流的 30 秒属于
|
|
1299
|
+
* 保守误伤 —— 内联等待落地后,冷却时长就是用户实打实的等待(issue #22)。
|
|
1300
|
+
* 连续 5xx 按倍数递增、封顶到 SERVER_COOLDOWN_MS,避免持续故障被短冷却连打。
|
|
1301
|
+
*/
|
|
1302
|
+
const SERVER_5XX_COOLDOWN_MS = 4e3;
|
|
1303
|
+
/**
|
|
1304
|
+
* API 网关限流(APIG.0308)的冷却:官方窗口是 1 分钟,必须长于它才能让下次请求
|
|
1305
|
+
* 落在窗口外。65 秒留出边界抖动余量(issue #22 后续,纯本地退避)。
|
|
1306
|
+
*/
|
|
1307
|
+
const GATEWAY_COOLDOWN_MS = 65e3;
|
|
1244
1308
|
/** 零散错误累计到阈值后冷却该账号。 */
|
|
1245
1309
|
const ERROR_COOLDOWN_MS = 6e4;
|
|
1246
1310
|
/**
|
|
@@ -1296,6 +1360,11 @@ function createCodeArtsShim(options) {
|
|
|
1296
1360
|
const localSlotWaitBudgetMs = options.localSlotWaitMs ?? 3e4;
|
|
1297
1361
|
const queueRetryGapMs = options.queueRetryGapMs ?? QUEUE_RETRY_GAP;
|
|
1298
1362
|
const pool = options.pool ?? new CodeArtsAccountPool([]);
|
|
1363
|
+
/**
|
|
1364
|
+
* 连续 5xx 次数(按账号):5xx 冷却按 4s 起翻倍递增、封顶 30s(issue #22 辅建议)。
|
|
1365
|
+
* 跨请求保留,任何非 5xx 结果(成功、软限流、客户端错误)清零。
|
|
1366
|
+
*/
|
|
1367
|
+
const serverStreaks = /* @__PURE__ */ new Map();
|
|
1299
1368
|
const SHARED_SECRET = randomBytes(32).toString("base64url");
|
|
1300
1369
|
function bearerOk(req) {
|
|
1301
1370
|
const header = req.headers.authorization;
|
|
@@ -1605,6 +1674,7 @@ function createCodeArtsShim(options) {
|
|
|
1605
1674
|
let queuedAccount;
|
|
1606
1675
|
let queueWaitedMs = 0;
|
|
1607
1676
|
let localSlotWaitedMs = 0;
|
|
1677
|
+
let cooldownWaitedMs = 0;
|
|
1608
1678
|
let lastKind;
|
|
1609
1679
|
let lastAccountId;
|
|
1610
1680
|
let lastStatus = 0;
|
|
@@ -1618,7 +1688,7 @@ function createCodeArtsShim(options) {
|
|
|
1618
1688
|
* 再跑第二轮。以前这里直接落到「没有可用账号」的 429,并发派发(一次 5 个
|
|
1619
1689
|
* subagent)必然误伤(issue #8)。
|
|
1620
1690
|
*/
|
|
1621
|
-
for (let round = 0; round <
|
|
1691
|
+
for (let round = 0; round < ROTATE_MAX_ROUNDS; round += 1) {
|
|
1622
1692
|
tried.clear();
|
|
1623
1693
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
1624
1694
|
if (Date.now() + ATTEMPT_RESERVE_MS > rotateDeadline) break;
|
|
@@ -1649,6 +1719,7 @@ function createCodeArtsShim(options) {
|
|
|
1649
1719
|
}
|
|
1650
1720
|
if (result.ok) {
|
|
1651
1721
|
pool.noteSuccess(id);
|
|
1722
|
+
serverStreaks.delete(id);
|
|
1652
1723
|
await pipeToResponse(res, result.stream, controller.signal, {
|
|
1653
1724
|
accountId: id,
|
|
1654
1725
|
model: prepared.model,
|
|
@@ -1660,6 +1731,7 @@ function createCodeArtsShim(options) {
|
|
|
1660
1731
|
lastAccountId = id;
|
|
1661
1732
|
lastStatus = result.status;
|
|
1662
1733
|
lastMessage = result.message;
|
|
1734
|
+
if (result.kind !== "server") serverStreaks.delete(id);
|
|
1663
1735
|
if (isConcurrencyCap(result)) {
|
|
1664
1736
|
pool.noteConcurrencyCap(id);
|
|
1665
1737
|
cappedAccount = id;
|
|
@@ -1693,7 +1765,19 @@ function createCodeArtsShim(options) {
|
|
|
1693
1765
|
pool.cooldown(id, CREDIT_COOLDOWN_MS, "该账号积分已耗尽(TM.00001050),额度刷新或领取积分后恢复");
|
|
1694
1766
|
continue;
|
|
1695
1767
|
}
|
|
1696
|
-
if (result.kind === "server"
|
|
1768
|
+
if (result.kind === "server") {
|
|
1769
|
+
const streak = (serverStreaks.get(id) ?? 0) + 1;
|
|
1770
|
+
serverStreaks.set(id, streak);
|
|
1771
|
+
const cooldownMs = Math.min(SERVER_COOLDOWN_MS, SERVER_5XX_COOLDOWN_MS * 2 ** Math.min(streak - 1, 10));
|
|
1772
|
+
pool.cooldown(id, cooldownMs, result.message);
|
|
1773
|
+
debug?.(`server 5xx cooldown account=${id} streak=${streak} ms=${cooldownMs}`);
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
if (result.kind === "gate_rate") {
|
|
1777
|
+
pool.cooldown(id, GATEWAY_COOLDOWN_MS, result.message);
|
|
1778
|
+
break;
|
|
1779
|
+
}
|
|
1780
|
+
if (result.kind === "soft_rate") {
|
|
1697
1781
|
pool.cooldown(id, SERVER_COOLDOWN_MS, result.message);
|
|
1698
1782
|
break;
|
|
1699
1783
|
}
|
|
@@ -1705,7 +1789,19 @@ function createCodeArtsShim(options) {
|
|
|
1705
1789
|
}
|
|
1706
1790
|
}
|
|
1707
1791
|
if (lastKind !== void 0 || controller.signal.aborted) break;
|
|
1708
|
-
if (!pool.hasBusyWaitable())
|
|
1792
|
+
if (!pool.hasBusyWaitable()) {
|
|
1793
|
+
const thawAt = pool.earliestCooldownEnd();
|
|
1794
|
+
const thawBudget = rotateDeadline - ATTEMPT_RESERVE_MS - Date.now();
|
|
1795
|
+
if (thawAt === void 0 || thawBudget <= 0) break;
|
|
1796
|
+
if (thawAt - Date.now() > thawBudget) break;
|
|
1797
|
+
const coolingSince = Date.now();
|
|
1798
|
+
debug?.(`cooldown wait start req=${requestTag} thawIn=${thawAt - coolingSince}ms`);
|
|
1799
|
+
const thawed = await pool.waitForCooldownEnd(thawBudget, controller.signal);
|
|
1800
|
+
cooldownWaitedMs += Date.now() - coolingSince;
|
|
1801
|
+
debug?.(`cooldown wait ${thawed ? "done" : "timeout"} req=${requestTag} waited=${Date.now() - coolingSince}ms`);
|
|
1802
|
+
if (!thawed) break;
|
|
1803
|
+
continue;
|
|
1804
|
+
}
|
|
1709
1805
|
const waitBudget = Math.min(localSlotWaitBudgetMs, rotateDeadline - ATTEMPT_RESERVE_MS - Date.now());
|
|
1710
1806
|
if (waitBudget <= 0) break;
|
|
1711
1807
|
const waitingSince = Date.now();
|
|
@@ -1735,6 +1831,7 @@ function createCodeArtsShim(options) {
|
|
|
1735
1831
|
if (result.ok) {
|
|
1736
1832
|
pool.noteCapRelease(queueAccount);
|
|
1737
1833
|
pool.noteSuccess(queueAccount);
|
|
1834
|
+
serverStreaks.delete(queueAccount);
|
|
1738
1835
|
await pipeToResponse(res, result.stream, controller.signal, {
|
|
1739
1836
|
accountId: queueAccount,
|
|
1740
1837
|
model: opened.prepared.model,
|
|
@@ -1761,6 +1858,7 @@ function createCodeArtsShim(options) {
|
|
|
1761
1858
|
const waits = [];
|
|
1762
1859
|
if (queueWaitedMs >= 1e3) waits.push(`排队重试 ${Math.round(queueWaitedMs / 1e3)} 秒`);
|
|
1763
1860
|
if (localSlotWaitedMs >= 1e3) waits.push(`等本地槽位 ${Math.round(localSlotWaitedMs / 1e3)} 秒`);
|
|
1861
|
+
if (cooldownWaitedMs >= 1e3) waits.push(`等冷却解冻 ${Math.round(cooldownWaitedMs / 1e3)} 秒`);
|
|
1764
1862
|
const waited = waits.length > 0 ? `(本地已${waits.join("、")})` : "";
|
|
1765
1863
|
const failedKind = isQueueRejectText(lastMessage) ? "queued" : lastKind;
|
|
1766
1864
|
usage?.noteFailure(failedKind, lastAccountId);
|
|
@@ -1802,6 +1900,7 @@ function createCodeArtsShim(options) {
|
|
|
1802
1900
|
}
|
|
1803
1901
|
if (opened.result.ok) {
|
|
1804
1902
|
pool.noteSuccess(id);
|
|
1903
|
+
serverStreaks.delete(id);
|
|
1805
1904
|
await pipeToResponse(res, opened.result.stream, controller.signal, {
|
|
1806
1905
|
accountId: id,
|
|
1807
1906
|
model: opened.prepared.model,
|
package/lib/keeper-main.mjs
CHANGED
|
@@ -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-
|
|
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-T5qnGSPp.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` /
|
|
@@ -546,6 +549,7 @@ var upstream_exports = /* @__PURE__ */ __exportAll({
|
|
|
546
549
|
BENEFIT_MISSING_CODE: () => BENEFIT_MISSING_CODE,
|
|
547
550
|
CONCURRENCY_CAP_CODE: () => CONCURRENCY_CAP_CODE,
|
|
548
551
|
CREDIT_EXHAUSTED_CODE: () => CREDIT_EXHAUSTED_CODE,
|
|
552
|
+
GATEWAY_THROTTLE_CODE: () => GATEWAY_THROTTLE_CODE,
|
|
549
553
|
MAX_TOKENS_CEILING: () => MAX_TOKENS_CEILING,
|
|
550
554
|
MAX_TOKENS_FLOOR: () => MAX_TOKENS_FLOOR,
|
|
551
555
|
PARAM_INVALID_CODE: () => PARAM_INVALID_CODE,
|
|
@@ -570,6 +574,7 @@ var upstream_exports = /* @__PURE__ */ __exportAll({
|
|
|
570
574
|
isConcurrencyCap: () => isConcurrencyCap,
|
|
571
575
|
isContextOverflowText: () => isContextOverflowText,
|
|
572
576
|
isCreditExhausted: () => isCreditExhausted,
|
|
577
|
+
isGatewayThrottle: () => isGatewayThrottle,
|
|
573
578
|
isIamTokenError: () => isIamTokenError,
|
|
574
579
|
isModelNotAccessible: () => isModelNotAccessible,
|
|
575
580
|
isNotMultimodal: () => isNotMultimodal,
|
|
@@ -1252,9 +1257,24 @@ function upstreamErrorMessage(message, status = 0) {
|
|
|
1252
1257
|
if (isModelNotAccessible(message)) return "上游说这个模型不存在或当前账号没有权限(可能已下线或改名)。请刷新模型列表后换一个模型;换号没有用,这是模型级的限制。";
|
|
1253
1258
|
if (isNotMultimodal(message)) return "这个模型不支持图片输入(上游 406)。请移除消息里的图片,或改用支持识图的模型。";
|
|
1254
1259
|
if (message.toLowerCase().includes("model is not registered")) return "上游没有注册这个模型,它可能已经下线;请刷新模型列表后重选。";
|
|
1260
|
+
if (isGatewayThrottle(message)) return "上游 API 网关触发了限流(约 1 分钟窗口,通常与共享配额有关),不是你的账号或插件问题。本地已冷却约 1 分钟,稍后重试即可。";
|
|
1255
1261
|
return `codearts 上游错误 (http ${status}): ${message.slice(0, 400)}`;
|
|
1256
1262
|
}
|
|
1257
1263
|
/**
|
|
1264
|
+
* API 网关层的限流(与后端软限流是两回事)。
|
|
1265
|
+
*
|
|
1266
|
+
* 2026-11-27 观测(issue #22 后续):429 + `{"error_msg":"The throttling threshold
|
|
1267
|
+
* has been reached: policy user over ratelimit,limit:100,time:1 minute",
|
|
1268
|
+
* "error_code":"APIG.0308",...}`。窗口是 1 分钟,比后端软限流(约 30 秒)长,
|
|
1269
|
+
* 用后者的冷却去等会在窗口里「解冻即再撞」。这层限流纯客户端无法核实配额归属,
|
|
1270
|
+
* 只在本地按 1 分钟窗口退避,不涉及任何上游操作。
|
|
1271
|
+
*/
|
|
1272
|
+
const GATEWAY_THROTTLE_CODE = "APIG.0308";
|
|
1273
|
+
const GATEWAY_THROTTLE_TEXT = /policy\s+\w+\s+over\s+ratelimit/i;
|
|
1274
|
+
function isGatewayThrottle(text) {
|
|
1275
|
+
return text.includes("APIG.0308") || GATEWAY_THROTTLE_TEXT.test(text);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1258
1278
|
* 「这个账号的套餐积分已耗尽」。
|
|
1259
1279
|
*
|
|
1260
1280
|
* 2026-11-25 实测(issue #20):上游回 HTTP 400 + body
|
|
@@ -1356,6 +1376,7 @@ function classify(status, message) {
|
|
|
1356
1376
|
if (isCreditExhausted(message)) return "hard_credit";
|
|
1357
1377
|
if (status === 401 || status === 403) return "session_dead";
|
|
1358
1378
|
if (status === 402) return "hard_credit";
|
|
1379
|
+
if (isGatewayThrottle(message)) return "gate_rate";
|
|
1359
1380
|
if (status === 429) return "soft_rate";
|
|
1360
1381
|
if (status === 404) return "not_found";
|
|
1361
1382
|
if (status >= 500) return "server";
|
|
@@ -1384,12 +1405,63 @@ async function dispatch(req, body, signal) {
|
|
|
1384
1405
|
req.headers.forEach((value, key) => {
|
|
1385
1406
|
headers[key] = value;
|
|
1386
1407
|
});
|
|
1387
|
-
|
|
1408
|
+
const res = await fetch(req.url, {
|
|
1388
1409
|
method: req.method,
|
|
1389
1410
|
headers,
|
|
1390
1411
|
...body === void 0 ? {} : { body },
|
|
1391
1412
|
...signal === void 0 ? {} : { signal }
|
|
1392
1413
|
});
|
|
1414
|
+
if (!isNeighborGateRefusal(res)) return res;
|
|
1415
|
+
await res.body?.cancel().catch(() => {});
|
|
1416
|
+
return dispatchDirect(req.url, req.method, headers, body, signal);
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* billion-context 这类宿主层压缩代理会**在本地**拒收「不属于 bili 会话、又超过
|
|
1420
|
+
* 静默直连字节上限」的请求(实测上限 8 MiB),回 422 + `x-bili-gate:
|
|
1421
|
+
* oversize-refusal*`,根本没出网(issue #23)。它的拦截只挂在 `globalThis.fetch`
|
|
1422
|
+
* 上,所以收到这个标记时换一份自己的 node:http(s) 连接直发 —— 签名与请求体
|
|
1423
|
+
* 都不变,只是不再经过这层代理。
|
|
1424
|
+
*
|
|
1425
|
+
* 只认它自己的标记头:真正的上游 422 不带这个头,照常按 no_live_state 等
|
|
1426
|
+
* 分类处理。
|
|
1427
|
+
*/
|
|
1428
|
+
function isNeighborGateRefusal(res) {
|
|
1429
|
+
if (res.status !== 422) return false;
|
|
1430
|
+
return (res.headers.get("x-bili-gate") ?? "").startsWith("oversize-refusal");
|
|
1431
|
+
}
|
|
1432
|
+
/** 绕开 `globalThis.fetch` 的直连发送;响应流原样转成 web Response。 */
|
|
1433
|
+
function dispatchDirect(url, method, headers, body, signal) {
|
|
1434
|
+
const target = new URL(url);
|
|
1435
|
+
const send = target.protocol === "http:" ? request : request$1;
|
|
1436
|
+
return new Promise((resolve, reject) => {
|
|
1437
|
+
if (signal?.aborted === true) {
|
|
1438
|
+
reject(/* @__PURE__ */ new Error("This operation was aborted"));
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
const req = send(target, {
|
|
1442
|
+
method,
|
|
1443
|
+
headers
|
|
1444
|
+
}, (res) => {
|
|
1445
|
+
const stream = Readable.toWeb(res);
|
|
1446
|
+
resolve(new Response(stream, {
|
|
1447
|
+
status: res.statusCode ?? 502,
|
|
1448
|
+
headers: res.headers
|
|
1449
|
+
}));
|
|
1450
|
+
});
|
|
1451
|
+
const onAbort = () => {
|
|
1452
|
+
const error = /* @__PURE__ */ new Error("This operation was aborted");
|
|
1453
|
+
error.name = "AbortError";
|
|
1454
|
+
req.destroy(error);
|
|
1455
|
+
};
|
|
1456
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1457
|
+
req.on("error", (error) => {
|
|
1458
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1459
|
+
reject(error);
|
|
1460
|
+
});
|
|
1461
|
+
req.on("close", () => signal?.removeEventListener("abort", onAbort));
|
|
1462
|
+
if (body !== void 0) req.write(body);
|
|
1463
|
+
req.end();
|
|
1464
|
+
});
|
|
1393
1465
|
}
|
|
1394
1466
|
const enc = new TextEncoder();
|
|
1395
1467
|
function openAIData(obj) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as writeJsonAtomic } from "./auth-
|
|
2
|
-
import { $ as setDiscoveredBenefitModels, H as carryKnownWindows, J as isBenefitModel, X as mergeModelLists, Z as modelDisplayName, u as fetchModels } from "./upstream-
|
|
1
|
+
import { u as writeJsonAtomic } from "./auth-T5qnGSPp.mjs";
|
|
2
|
+
import { $ as setDiscoveredBenefitModels, H as carryKnownWindows, J as isBenefitModel, X as mergeModelLists, Z as modelDisplayName, u as fetchModels } from "./upstream-Cr5tUI75.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.
|
|
539
|
+
const CODEARTS_VERSION = "1.4.16";
|
|
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.
|
|
5
|
+
"version": "1.4.16",
|
|
6
6
|
"packageManager": "pnpm@11.24.0",
|
|
7
7
|
"author": "elegant01",
|
|
8
8
|
"keywords": [
|