dsh-codearts 1.4.6 → 1.4.8

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,40 @@
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.8] - 2026-11-20
7
+
8
+ ### 新增
9
+
10
+ - `llm-codearts.config.retryPolicy`:可按需覆盖 `maxRetries` / `initialDelayMs` /
11
+ `maxDelayMs`。策略在注册 provider 时被宿主快照,改完需要重载插件才生效。
12
+
13
+ ### 修复
14
+
15
+ - **重试预算跨得过账号冷却窗了**(#14):软限流 / 5xx 后账号会被冷却 30 秒,期间
16
+ 请求回 429 交给宿主重试;而宿主默认预算(5 次指数退避,累计约 15.5 秒)在冷却
17
+ 前段**确定性地**烧尽,变成可见的轮次失败。现在 provider 注册的重试策略默认对齐
18
+ 到 8 次(0.5+1+2+4+8+10+10+10 ≈45.5 秒,含抖动下限也稳过 30 秒)。
19
+ 代价:持续性故障的暴露时间从约 15.5 秒变约 45.5 秒。
20
+
21
+ ## [1.4.7] - 2026-11-20
22
+
23
+ ### 修复
24
+
25
+ - **「成功但不完整」的一轮发现不再把已知上下文窗口降级**(#12):发现是逐路并行
26
+ 的,某一路(如企业租户 thirdparty)瞬时失败时,同一模型仍可能由别的路返回,但
27
+ 不带 `contextWindow`,于是被 32768 兜底值覆盖,而且一直错到下一轮完整发现 ——
28
+ 长会话在 400 context_overflow 上反复失败。现在提交前按 id 回查上一轮目录:本轮
29
+ 没拿到可信窗口的记录沿用上一轮的值(`contextWindowKnown` 与标称值一起带过去),
30
+ 本轮已可信的值不动,上游下架的模型照常消失。
31
+ - **无头 / 一次性进程启动时模型列表不再为空**(#13):`apply` 以前是同步函数,
32
+ 模型发现与 provider 注册都在它返回之后的异步链里,而宿主只等 `apply` 的返回值 ——
33
+ `--list-models`、headless 任务、平台的本机运行时在 profile 加载完立刻下结论,
34
+ 拿到空目录(`has no configured model`)且零日志。现在 `apply` 等待「shim 就绪 →
35
+ 首轮发现 → 注册」整条链,首轮发现 10 秒超时、启动总预算 15 秒,超时按空目录继续
36
+ 并告警,不会拖死启动;目录为空注册时补一条 `warn`。
37
+ - 首次发现不再多打一轮上游:启动引导跑完首轮后由退避循环接棒,而不是循环自己
38
+ 立刻再发现一次。
39
+
6
40
  ## [1.4.6] - 2026-11-18
7
41
 
8
42
  ### 新增
@@ -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-COqsw56c.mjs").then((n) => n.P);
587
+ const { claimBenefit } = await import("./upstream-CgQXomCI.mjs").then((n) => n.P);
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-q6MY-TXM.mjs";
3
- import { H as isBenefitModel, l as fetchCallerIdentity } from "./upstream-COqsw56c.mjs";
4
- import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-BZuhJ6R9.mjs";
2
+ import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-BRlNY6dB.mjs";
3
+ import { U as isBenefitModel, l as fetchCallerIdentity } from "./upstream-CgQXomCI.mjs";
4
+ import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-qgKLf1Cq.mjs";
5
5
  import { existsSync, statSync } from "node:fs";
6
6
  //#region src/bin.ts
7
7
  /**
@@ -156,123 +156,123 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
156
156
  document.head.appendChild(tag);
157
157
  }
158
158
  var CodeArtsPluginCard_module_css_default = {
159
- "accountName": "xoziZG_accountName",
159
+ "accountMenu": "xoziZG_accountMenu",
160
+ "bar": "xoziZG_bar",
161
+ "modelChart": "xoziZG_modelChart",
160
162
  "windowHint": "xoziZG_windowHint",
161
- "creditRows": "xoziZG_creditRows",
162
- "windowButton": "xoziZG_windowButton",
163
- "creditFooter": "xoziZG_creditFooter",
164
- "skeletonBreath": "xoziZG_skeletonBreath",
165
- "accountInfo": "xoziZG_accountInfo",
166
- "heatLegendChip": "xoziZG_heatLegendChip",
163
+ "manualSummary": "xoziZG_manualSummary",
164
+ "balance": "xoziZG_balance",
165
+ "modelMeta": "xoziZG_modelMeta",
166
+ "manualForm": "xoziZG_manualForm",
167
+ "windowInput": "xoziZG_windowInput",
168
+ "windowButtonOpen": "xoziZG_windowButtonOpen",
169
+ "groupLabel": "xoziZG_groupLabel",
170
+ "tabPanel": "xoziZG_tabPanel",
171
+ "choiceTail": "xoziZG_choiceTail",
172
+ "modelFill": "xoziZG_modelFill",
173
+ "claimAllRow": "xoziZG_claimAllRow",
167
174
  "area": "xoziZG_area",
168
- "usageTipRow": "xoziZG_usageTipRow",
169
- "groupHead": "xoziZG_groupHead",
170
- "windowAnchor": "xoziZG_windowAnchor",
171
- "modelTrack": "xoziZG_modelTrack",
172
- "windowUnit": "xoziZG_windowUnit",
175
+ "creditRow": "xoziZG_creditRow",
176
+ "creditBlock": "xoziZG_creditBlock",
177
+ "modelName": "xoziZG_modelName",
173
178
  "heatGrid": "xoziZG_heatGrid",
174
- "sectionLabel": "xoziZG_sectionLabel",
175
- "modelMeta": "xoziZG_modelMeta",
179
+ "danger": "xoziZG_danger",
180
+ "heatLegend": "xoziZG_heatLegend",
181
+ "choiceRow": "xoziZG_choiceRow",
182
+ "usageTipSep": "xoziZG_usageTipSep",
183
+ "accountName": "xoziZG_accountName",
184
+ "modelCheck": "xoziZG_modelCheck",
185
+ "balanceMeta": "xoziZG_balanceMeta",
186
+ "groupHeadFirst": "xoziZG_groupHeadFirst",
187
+ "fieldLabel": "xoziZG_fieldLabel",
188
+ "modelSpec": "xoziZG_modelSpec",
189
+ "statusLine": "xoziZG_statusLine",
190
+ "windowUnit": "xoziZG_windowUnit",
191
+ "statLabel": "xoziZG_statLabel",
192
+ "modelTokens": "xoziZG_modelTokens",
193
+ "accountHint": "xoziZG_accountHint",
194
+ "modelRow": "xoziZG_modelRow",
195
+ "accountNameRow": "xoziZG_accountNameRow",
176
196
  "creditHint": "xoziZG_creditHint",
177
- "name": "xoziZG_name",
197
+ "creditRows": "xoziZG_creditRows",
198
+ "avatar": "xoziZG_avatar",
199
+ "modelTrack": "xoziZG_modelTrack",
200
+ "statSub": "xoziZG_statSub",
201
+ "doctorRow": "xoziZG_doctorRow",
202
+ "check": "xoziZG_check",
203
+ "windowCaret": "xoziZG_windowCaret",
178
204
  "usageTip": "xoziZG_usageTip",
179
- "count": "xoziZG_count",
205
+ "windowAnchor": "xoziZG_windowAnchor",
206
+ "heatAxisSlot": "xoziZG_heatAxisSlot",
180
207
  "windowRange": "xoziZG_windowRange",
181
- "sectionHead": "xoziZG_sectionHead",
182
- "card": "xoziZG_card",
183
- "choiceTail": "xoziZG_choiceTail",
184
- "statSub": "xoziZG_statSub",
185
- "heatLegend": "xoziZG_heatLegend",
186
- "accountHint": "xoziZG_accountHint",
187
- "statValue": "xoziZG_statValue",
188
- "heatHourCell": "xoziZG_heatHourCell",
189
- "modelCheck": "xoziZG_modelCheck",
190
208
  "usageFill": "xoziZG_usageFill",
209
+ "error": "xoziZG_error",
210
+ "body": "xoziZG_body",
211
+ "accountEntry": "xoziZG_accountEntry",
191
212
  "windowPopoverHead": "xoziZG_windowPopoverHead",
192
- "meta": "xoziZG_meta",
193
- "accountClearHint": "xoziZG_accountClearHint",
194
- "avatar": "xoziZG_avatar",
195
- "windowButtonSet": "xoziZG_windowButtonSet",
196
- "desc": "xoziZG_desc",
197
- "updated": "xoziZG_updated",
198
- "windowPopover": "xoziZG_windowPopover",
199
- "windowInput": "xoziZG_windowInput",
200
- "modelSpec": "xoziZG_modelSpec",
201
- "danger": "xoziZG_danger",
202
- "modelName": "xoziZG_modelName",
203
- "heatAxisSlot": "xoziZG_heatAxisSlot",
204
- "check": "xoziZG_check",
205
213
  "tabs": "xoziZG_tabs",
214
+ "actions": "xoziZG_actions",
215
+ "modelShare": "xoziZG_modelShare",
216
+ "windowPopoverRow": "xoziZG_windowPopoverRow",
217
+ "creditLink": "xoziZG_creditLink",
218
+ "heatWeekday": "xoziZG_heatWeekday",
219
+ "accountMenuItem": "xoziZG_accountMenuItem",
220
+ "doctorName": "xoziZG_doctorName",
221
+ "statGrid": "xoziZG_statGrid",
206
222
  "header": "xoziZG_header",
207
- "doctorRow": "xoziZG_doctorRow",
208
- "balanceMeta": "xoziZG_balanceMeta",
209
- "error": "xoziZG_error",
210
- "manualSummary": "xoziZG_manualSummary",
211
- "claimAllRow": "xoziZG_claimAllRow",
223
+ "groupHead": "xoziZG_groupHead",
224
+ "accountInfo": "xoziZG_accountInfo",
212
225
  "expiryRow": "xoziZG_expiryRow",
226
+ "choices": "xoziZG_choices",
227
+ "accountToggle": "xoziZG_accountToggle",
228
+ "accountRowActions": "xoziZG_accountRowActions",
229
+ "skeleton": "xoziZG_skeleton",
230
+ "meta": "xoziZG_meta",
213
231
  "modelRequests": "xoziZG_modelRequests",
214
- "statusLine": "xoziZG_statusLine",
215
- "manualForm": "xoziZG_manualForm",
216
- "accountCard": "xoziZG_accountCard",
217
- "skeletonRow": "xoziZG_skeletonRow",
218
- "accountRow": "xoziZG_accountRow",
219
- "hint": "xoziZG_hint",
220
- "creditBlock": "xoziZG_creditBlock",
221
- "usageBar": "xoziZG_usageBar",
222
- "usageTipSep": "xoziZG_usageTipSep",
223
- "trendTip": "xoziZG_trendTip",
232
+ "heatHours": "xoziZG_heatHours",
233
+ "usageTipRow": "xoziZG_usageTipRow",
224
234
  "balanceRow": "xoziZG_balanceRow",
235
+ "updated": "xoziZG_updated",
225
236
  "balanceUnit": "xoziZG_balanceUnit",
226
- "accountMenuAnchor": "xoziZG_accountMenuAnchor",
227
- "accountMenuItem": "xoziZG_accountMenuItem",
228
- "modelRow": "xoziZG_modelRow",
229
- "accountToolbar": "xoziZG_accountToolbar",
230
- "heatAxis": "xoziZG_heatAxis",
231
- "creditRow": "xoziZG_creditRow",
232
- "statCard": "xoziZG_statCard",
233
- "windowButtonOpen": "xoziZG_windowButtonOpen",
234
- "modelShare": "xoziZG_modelShare",
235
- "statLabel": "xoziZG_statLabel",
236
- "modelChart": "xoziZG_modelChart",
237
- "accountEntry": "xoziZG_accountEntry",
238
- "heatHours": "xoziZG_heatHours",
239
- "creditLink": "xoziZG_creditLink",
240
- "fieldLabel": "xoziZG_fieldLabel",
241
- "groupLabel": "xoziZG_groupLabel",
242
- "bar": "xoziZG_bar",
243
- "body": "xoziZG_body",
244
- "tabPanel": "xoziZG_tabPanel",
245
- "accountRowActions": "xoziZG_accountRowActions",
246
- "windowPopoverRow": "xoziZG_windowPopoverRow",
247
- "manual": "xoziZG_manual",
248
- "accountNameRow": "xoziZG_accountNameRow",
249
- "accountClear": "xoziZG_accountClear",
250
- "balance": "xoziZG_balance",
251
- "barFill": "xoziZG_barFill",
252
- "link": "xoziZG_link",
253
- "modelFill": "xoziZG_modelFill",
237
+ "skeletonRow": "xoziZG_skeletonRow",
238
+ "count": "xoziZG_count",
254
239
  "accountGrid": "xoziZG_accountGrid",
255
- "accountMenu": "xoziZG_accountMenu",
256
- "heatWeekday": "xoziZG_heatWeekday",
257
- "actions": "xoziZG_actions",
258
- "modelTokens": "xoziZG_modelTokens",
240
+ "field": "xoziZG_field",
241
+ "heatLegendChip": "xoziZG_heatLegendChip",
242
+ "skeletonBreath": "xoziZG_skeletonBreath",
243
+ "barFill": "xoziZG_barFill",
244
+ "windowPopoverValue": "xoziZG_windowPopoverValue",
259
245
  "heatCell": "xoziZG_heatCell",
260
- "section": "xoziZG_section",
246
+ "windowButtonSet": "xoziZG_windowButtonSet",
247
+ "usageBar": "xoziZG_usageBar",
248
+ "accountClear": "xoziZG_accountClear",
249
+ "accountCard": "xoziZG_accountCard",
250
+ "windowPopover": "xoziZG_windowPopover",
261
251
  "windowInputSet": "xoziZG_windowInputSet",
262
- "choices": "xoziZG_choices",
263
- "windowPopoverValue": "xoziZG_windowPopoverValue",
264
- "windowCaret": "xoziZG_windowCaret",
265
- "field": "xoziZG_field",
266
- "doctorName": "xoziZG_doctorName",
267
- "choiceRow": "xoziZG_choiceRow",
268
- "headText": "xoziZG_headText",
252
+ "manual": "xoziZG_manual",
269
253
  "usageTipName": "xoziZG_usageTipName",
270
- "doctorList": "xoziZG_doctorList",
271
- "statGrid": "xoziZG_statGrid",
272
- "accountToggle": "xoziZG_accountToggle",
254
+ "accountRow": "xoziZG_accountRow",
255
+ "name": "xoziZG_name",
256
+ "desc": "xoziZG_desc",
273
257
  "expiryLabel": "xoziZG_expiryLabel",
274
- "groupHeadFirst": "xoziZG_groupHeadFirst",
275
- "skeleton": "xoziZG_skeleton"
258
+ "accountToolbar": "xoziZG_accountToolbar",
259
+ "card": "xoziZG_card",
260
+ "sectionLabel": "xoziZG_sectionLabel",
261
+ "hint": "xoziZG_hint",
262
+ "statCard": "xoziZG_statCard",
263
+ "statValue": "xoziZG_statValue",
264
+ "trendTip": "xoziZG_trendTip",
265
+ "headText": "xoziZG_headText",
266
+ "section": "xoziZG_section",
267
+ "accountMenuAnchor": "xoziZG_accountMenuAnchor",
268
+ "sectionHead": "xoziZG_sectionHead",
269
+ "heatHourCell": "xoziZG_heatHourCell",
270
+ "heatAxis": "xoziZG_heatAxis",
271
+ "windowButton": "xoziZG_windowButton",
272
+ "doctorList": "xoziZG_doctorList",
273
+ "link": "xoziZG_link",
274
+ "creditFooter": "xoziZG_creditFooter",
275
+ "accountClearHint": "xoziZG_accountClearHint"
276
276
  };
277
277
  //#endregion
278
278
  //#region src/client/CodeArtsPluginCard.tsx
@@ -3289,14 +3289,14 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
3289
3289
  document.head.appendChild(tag);
3290
3290
  }
3291
3291
  var CodeArtsPanel_module_css_default = {
3292
- "back": "Z66cgG_back",
3293
- "title": "Z66cgG_title",
3292
+ "head": "Z66cgG_head",
3294
3293
  "body": "Z66cgG_body",
3295
3294
  "page": "Z66cgG_page",
3296
3295
  "icon": "Z66cgG_icon",
3297
- "desc": "Z66cgG_desc",
3298
- "head": "Z66cgG_head",
3299
- "backCaret": "Z66cgG_backCaret"
3296
+ "back": "Z66cgG_back",
3297
+ "backCaret": "Z66cgG_backCaret",
3298
+ "title": "Z66cgG_title",
3299
+ "desc": "Z66cgG_desc"
3300
3300
  };
3301
3301
  //#endregion
3302
3302
  //#region src/client/CodeArtsPanel.tsx
package/lib/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import z from "@deepseek-ai/schemastery";
3
+ import "@deepseek-ai/dsh-llm";
3
4
  import { PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
4
5
  import { SettingsNamespace } from "@deepseek-ai/dsh-settings";
5
6
  import { Context } from "@deepseek-ai/cordis";
@@ -1675,10 +1676,21 @@ declare function createCodeArtsShim(options: CodeArtsShimOptions): CodeArtsShim;
1675
1676
  //#region src/adapter.d.ts
1676
1677
  /** Provider route this bundle owns. Keep in sync with cordis.patch.yml. */
1677
1678
  declare const CODEARTS_PROVIDER = "codearts";
1679
+ /** 用户在 `llm-codearts.config.retryPolicy` 里可调的三个旋钮。 */
1680
+ interface CodeArtsRetryPolicyConfig {
1681
+ /** 首次请求之后最多重试几次(默认 8,覆盖 30s 冷却窗)。 */
1682
+ maxRetries?: number;
1683
+ /** 首档退避毫秒数(默认 500)。 */
1684
+ initialDelayMs?: number;
1685
+ /** 单档退避上限毫秒数(默认 10000)。 */
1686
+ maxDelayMs?: number;
1687
+ }
1678
1688
  interface CodeArtsAdapterOptions {
1679
1689
  shim: CodeArtsShim;
1680
1690
  catalog: CodeArtsCatalog;
1681
1691
  enabledModels?: () => readonly string[] | undefined;
1692
+ /** issue #14 的 `retryPolicy` 配置;缺省按默认预算(8 次)注册。 */
1693
+ retryPolicy?: CodeArtsRetryPolicyConfig;
1682
1694
  resolveAttachments?: () => AttachmentStore | undefined;
1683
1695
  }
1684
1696
  interface CodeArtsAdapter {
@@ -1870,6 +1882,19 @@ interface Config {
1870
1882
  * 进程内按实测学到的上界仍会在此基础上继续往下钳。
1871
1883
  */
1872
1884
  contextWindowOverrides?: Record<string, number>;
1885
+ /**
1886
+ * 宿主的请求重试预算(issue #14)。
1887
+ *
1888
+ * 账号撞上软限流/5xx 会被冷却 30s,期间所有请求回 429 交给宿主重试。宿主的
1889
+ * 默认预算(5 次指数退避 ≈15.5s)跨不过前段 30s 窗口,会变成可见的轮次失败;
1890
+ * 插件默认已对齐到 8 次(≈45.5s),这里允许按需调整。值在注册 provider 时被
1891
+ * 宿主快照,改了要重载插件才生效。
1892
+ */
1893
+ retryPolicy?: {
1894
+ maxRetries?: number;
1895
+ initialDelayMs?: number;
1896
+ maxDelayMs?: number;
1897
+ };
1873
1898
  /** 对话输入框下方那行「积分 N」是否显示。缺省 = 显示(老配置不改行为)。 */
1874
1899
  showCreditDock?: boolean;
1875
1900
  /** 等上游开流时那行「排队第 N 位」是否显示。缺省 = 显示。 */
@@ -1923,6 +1948,6 @@ interface Config {
1923
1948
  queueWaitUntilReady?: boolean;
1924
1949
  }
1925
1950
  declare const Config: z<Config>;
1926
- declare function apply(ctx: Context, rawConfig: Config): void;
1951
+ declare function apply(ctx: Context, rawConfig: Config): Promise<void>;
1927
1952
  //#endregion
1928
1953
  export { type AccountRuntime, BENEFIT_GATEWAY_HOST, CODEARTS_PROVIDER, CODEARTS_SETTINGS_NS, CodeArtsAccountPool, CodeArtsAccountStore, type CodeArtsAccountSummary, type CodeArtsAdapter, CodeArtsCatalog, type CodeArtsCredential, CodeArtsCredentialStore, CodeArtsCreditCache, type CodeArtsCreditCategory, type CodeArtsCreditSnapshot, type CodeArtsCreditState, type CodeArtsCredits, type CodeArtsModelInfo, type CodeArtsShim, type CodeArtsTokenQuota, CodeArtsUsageTracker, Config, type DiscoveryOutcome, FALLBACK_CODEARTS_MODELS, type ModelDiscoveryResult, SNAP_HOST, type UpstreamErrorKind, type UsageSnapshot, type UsageTotals, apply, canonicalModel, chatStream, codeartsAccountsPath, codeartsAuthPath, codeartsUsagePath, createCodeArtsAdapter, createCodeArtsShim, discoverModels, fetchCredits, fetchModels, filterEnabledModels, inject, maxTokensCeilingFor, name, parseCreditStatistics, parseTokenBalance, prepareChatBody, refreshCatalog };
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-q6MY-TXM.mjs";
2
- import { A as queueFrame, B as forgetModelUnavailable, C as isWelfareClaimedStatus, D as modelUnavailableReasonText, E as maxTokensCeilingFor, F as CodeArtsCatalog, H as isBenefitModel, I as FALLBACK_CODEARTS_MODELS, K as modelUnavailableReason, L as clearBenefitBlocked, M as signedGet, N as upstreamErrorMessage, O as pickDailyWelfareCampaign, R as creditRatioLabel, S as isTpmLimit, T as learnedContextWindowFor, U as markModelUnavailable, V as isBenefitBlocked, _ as isNotMultimodal, a as claimDailyWelfare, b as isQueueRejectText, c as degradeTokenCeiling, d as fetchQueueStatus, f as fetchWelfareCampaigns, g as isModelNotAccessible, h as isIamTokenError, i as chatStream, j as rateLimitFrame, k as prepareChatBody, l as fetchCallerIdentity, m as isConcurrencyCap, n as SNAP_HOST, o as clearQueueStatus, p as firstFrameError, r as canonicalModel, s as contextWindowOverrideFor, t as MAX_TOKENS_FLOOR, u as fetchModels, v as isParamInvalidFrame, w as learnContextWindow, x as isQueueableRate, y as isQueueReject, z as filterEnabledModels } from "./upstream-COqsw56c.mjs";
3
- import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-BZuhJ6R9.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-BRlNY6dB.mjs";
2
+ import { A as queueFrame, B as filterEnabledModels, C as isWelfareClaimedStatus, D as modelUnavailableReasonText, E as maxTokensCeilingFor, F as CodeArtsCatalog, H as isBenefitBlocked, I as FALLBACK_CODEARTS_MODELS, M as signedGet, N as upstreamErrorMessage, O as pickDailyWelfareCampaign, R as clearBenefitBlocked, S as isTpmLimit, T as learnedContextWindowFor, U as isBenefitModel, V as forgetModelUnavailable, W as markModelUnavailable, _ as isNotMultimodal, a as claimDailyWelfare, b as isQueueRejectText, c as degradeTokenCeiling, d as fetchQueueStatus, f as fetchWelfareCampaigns, g as isModelNotAccessible, h as isIamTokenError, i as chatStream, j as rateLimitFrame, k as prepareChatBody, l as fetchCallerIdentity, m as isConcurrencyCap, n as SNAP_HOST, o as clearQueueStatus, p as firstFrameError, q as modelUnavailableReason, r as canonicalModel, s as contextWindowOverrideFor, t as MAX_TOKENS_FLOOR, u as fetchModels, v as isParamInvalidFrame, w as learnContextWindow, x as isQueueableRate, y as isQueueReject, z as creditRatioLabel } from "./upstream-CgQXomCI.mjs";
3
+ import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-qgKLf1Cq.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";
@@ -704,10 +704,30 @@ const CODEARTS_PROVIDER = "codearts";
704
704
  *
705
705
  * 90s 而不是常见的 300s:华为免费推理后端实测会流中途停摆(吐几个 token 后
706
706
  * 长时间静默),300s 意味着用户要在"等待"里干等 5 分钟才进入自动重试。
707
- * 90s 足够容忍首 token 冷启动与推理间隙,又能让 DSH 的重试策略
708
- * (maxRetries=5, TIMEOUT 可重试)更快接管。
707
+ * 90s 足够容忍首 token 冷启动与推理间隙,又能让 DSH 的重试策略(TIMEOUT
708
+ * 可重试)更快接管。
709
709
  */
710
710
  const CODEARTS_STREAM_IDLE_TIMEOUT_MS = 9e4;
711
+ const DEFAULT_CODEARTS_INITIAL_DELAY_MS = 500;
712
+ const DEFAULT_CODEARTS_MAX_DELAY_MS = 1e4;
713
+ /** 只认有限正整数;非法值忽略而不是抛错(值来自用户写的配置文件)。 */
714
+ function positiveInt(value) {
715
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : void 0;
716
+ }
717
+ /** 把插件配置解析成宿主快照用的重试策略;缺省值按上面注释对齐冷却窗。 */
718
+ function resolveCodeArtsRetryPolicy(config) {
719
+ const resolved = {
720
+ mode: "normal",
721
+ maxRetries: positiveInt(config?.maxRetries) ?? 8,
722
+ backoff: {
723
+ initialDelayMs: positiveInt(config?.initialDelayMs) ?? DEFAULT_CODEARTS_INITIAL_DELAY_MS,
724
+ maxDelayMs: positiveInt(config?.maxDelayMs) ?? DEFAULT_CODEARTS_MAX_DELAY_MS
725
+ }
726
+ };
727
+ const policy = resolveRetryPolicy(resolved, "dsh-codearts retryPolicy");
728
+ if (policy.mode !== "normal") throw new Error("dsh-codearts retry policy must be normal");
729
+ return policy;
730
+ }
711
731
  /** No per-token pricing is knowable for a subscription quota; report zero. */
712
732
  const NO_COST = {
713
733
  input: 0,
@@ -814,7 +834,7 @@ function createCodeArtsAdapter(options) {
814
834
  provider: CODEARTS_PROVIDER,
815
835
  displayName: "CodeArts",
816
836
  streamIdleTimeoutMs: CODEARTS_STREAM_IDLE_TIMEOUT_MS,
817
- retryPolicy: resolveRetryPolicy(void 0, "dsh-codearts retryPolicy"),
837
+ retryPolicy: resolveCodeArtsRetryPolicy(options.retryPolicy),
818
838
  configuredMaxTokens: /* @__PURE__ */ new Map(),
819
839
  modelErrors: /* @__PURE__ */ new Map(),
820
840
  ...REQUEST_IMAGE_BUDGETS,
@@ -1016,7 +1036,8 @@ function writeOpenAIError(res, status, kind, message) {
1016
1036
  * 种还把真因(比如 billion-context 本地拒签的 403)整个吞掉(issue #1)。
1017
1037
  *
1018
1038
  * 全部被禁用时回 401(宿主只自动重试 429,401 一次就把「去重新登录」说清);
1019
- * 只要还有会自己恢复的(冷却/槽位满)就回 429,宿主重试有概率直接救回来。
1039
+ * 只要还有会自己恢复的(冷却/槽位满)就回 429,让宿主重试接住。默认重试预算
1040
+ * 已对齐 30s 冷却窗(8 次指数退避 ≈45.5s,见 `adapter.ts`),冷却前段也跨得过。
1020
1041
  */
1021
1042
  function noAccountError(accounts, pausedIds = []) {
1022
1043
  const now = Date.now();
@@ -3126,6 +3147,11 @@ function unwrapConfig(value) {
3126
3147
  const Config = z.object({
3127
3148
  enabledModels: z.array(z.string()).description("Model ids offered in the model pickers (empty means every model)").volatile(),
3128
3149
  contextWindowOverrides: z.dict(z.natural()).description("Per-model contextWindow overrides (model id → tokens). Discovery reports the nominal server window, which the free tier may not actually serve (issue #9); an override wins over it, and the in-process learned upper bound still clamps it.").volatile(),
3150
+ retryPolicy: z.object({
3151
+ maxRetries: z.natural(),
3152
+ initialDelayMs: z.natural(),
3153
+ maxDelayMs: z.natural()
3154
+ }).description("Host retry budget for this provider (issue #14). Defaults to 8 retries (≈45.5s of backoff) so it outlasts the 30s account cooldown; changes apply after the plugin reloads.").volatile(),
3129
3155
  showCreditDock: z.boolean().default(true).description("Show the remaining-credits line under the chat input box").volatile(),
3130
3156
  showQueueDock: z.boolean().default(true).description("Show the upstream queue position under the chat input box").volatile(),
3131
3157
  showSidebarPanel: z.boolean().default(false).description("Show a CodeArts icon in the DSH sidebar icon column, opening this page in the middle column").volatile(),
@@ -3138,7 +3164,7 @@ const Config = z.object({
3138
3164
  function settingsCompatNamespace(ctx) {
3139
3165
  return resolveSettingsNamespaceCompat(ctx, ctx.get("settings"), CODEARTS_SETTINGS_NS);
3140
3166
  }
3141
- function apply(ctx, rawConfig) {
3167
+ async function apply(ctx, rawConfig) {
3142
3168
  const config = unwrapConfig(rawConfig);
3143
3169
  const accountsPath = codeartsAccountsPath();
3144
3170
  /**
@@ -3542,11 +3568,22 @@ function apply(ctx, rawConfig) {
3542
3568
  const CATALOG_REFRESH_MS = 36e5;
3543
3569
  const CATALOG_EMPTY_RETRY_MS = 6e4;
3544
3570
  const CATALOG_EMPTY_RETRY_MAX_MS = 3e5;
3571
+ /**
3572
+ * 启动首轮发现的预算(issue #13)。
3573
+ *
3574
+ * 一次性宿主(`--list-models`、`dsh headless`、Multica 的本机运行时)在 profile
3575
+ * 加载完就列模型 / 解析模型,等不到后台的任何一轮重试 —— 目录空就是定论。所以
3576
+ * 首轮发现要挡在注册之前、并让 `apply` 等它。但上游挂住时不能把启动一起拖死:
3577
+ * 超时按空目录继续注册,循环随后照常补。手动刷新那条路是 60s,启动不能照抄。
3578
+ */
3579
+ const STARTUP_DISCOVERY_MS = 1e4;
3580
+ /** 启动引导的总预算:发现另有 10s 自己的预算,这里防的是 shim 启动 / probe 卡住。 */
3581
+ const STARTUP_WAIT_MS = 15e3;
3545
3582
  const abort = new AbortController();
3546
- const discover = async () => {
3583
+ const discover = async (signal = abort.signal) => {
3547
3584
  if (stopped) return;
3548
3585
  try {
3549
- const outcome = await refreshCatalog(store, catalog, abort.signal, current().contextWindowOverrides);
3586
+ const outcome = await refreshCatalog(store, catalog, signal, current().contextWindowOverrides);
3550
3587
  if (outcome === void 0 || stopped) return;
3551
3588
  if (outcome.anySucceeded) {
3552
3589
  const free = outcome.models.filter((model) => model.benefit === true).length;
@@ -3559,21 +3596,26 @@ function apply(ctx, rawConfig) {
3559
3596
  let discoveryTimer;
3560
3597
  /** 连续多少轮目录是空的(用来算退避);一旦有货就归零。 */
3561
3598
  let emptyStreak = 0;
3562
- /** 自我重排的发现循环:目录为空时退避着重试(60s → 5min 封顶),有货后回到每小时。 */
3563
- const discoverLoop = async () => {
3564
- await discover();
3565
- if (stopped) return;
3566
- let delay;
3599
+ /** 下一轮发现该隔多久:目录为空时退避(60s → 5min 封顶),有货后回到每小时。 */
3600
+ const nextDiscoveryDelay = () => {
3567
3601
  if (catalog.current().length === 0) {
3568
- delay = Math.min(CATALOG_EMPTY_RETRY_MS * 2 ** emptyStreak, CATALOG_EMPTY_RETRY_MAX_MS);
3602
+ const delay = Math.min(CATALOG_EMPTY_RETRY_MS * 2 ** emptyStreak, CATALOG_EMPTY_RETRY_MAX_MS);
3569
3603
  emptyStreak += 1;
3570
- } else {
3571
- emptyStreak = 0;
3572
- delay = CATALOG_REFRESH_MS;
3604
+ return delay;
3573
3605
  }
3606
+ emptyStreak = 0;
3607
+ return CATALOG_REFRESH_MS;
3608
+ };
3609
+ const scheduleDiscovery = (delay) => {
3574
3610
  discoveryTimer = setTimeout(() => void discoverLoop(), delay);
3575
3611
  discoveryTimer.unref?.();
3576
3612
  };
3613
+ /** 自我重排的发现循环:首轮由启动引导跑完后从这里接棒,不再立刻多打一轮上游。 */
3614
+ const discoverLoop = async () => {
3615
+ await discover();
3616
+ if (stopped) return;
3617
+ scheduleDiscovery(nextDiscoveryDelay());
3618
+ };
3577
3619
  ctx.effect(() => () => {
3578
3620
  abort.abort();
3579
3621
  if (discoveryTimer !== void 0) clearTimeout(discoveryTimer);
@@ -3711,18 +3753,20 @@ function apply(ctx, rawConfig) {
3711
3753
  waitInQueue: () => current().queueWaitUntilReady === true
3712
3754
  });
3713
3755
  usage.load().catch(() => {});
3714
- shim.ready.then(async () => {
3756
+ const settled = shim.ready.then(async () => {
3715
3757
  if (stopped) return;
3716
- discoverLoop();
3717
3758
  keepAliveLoop();
3718
3759
  armAutoClaim();
3719
3760
  armKeepAliveDaemon();
3761
+ await discover(AbortSignal.any([abort.signal, AbortSignal.timeout(STARTUP_DISCOVERY_MS)]));
3762
+ if (stopped) return;
3720
3763
  const incompatible = await probePiAiCompat();
3721
3764
  if (incompatible !== void 0) ctx.logger.error(`dsh-codearts: ${incompatible}`);
3722
3765
  const codearts = createCodeArtsAdapter({
3723
3766
  shim,
3724
3767
  catalog,
3725
3768
  enabledModels,
3769
+ retryPolicy: current().retryPolicy,
3726
3770
  resolveAttachments: () => ctx.get("attachments")
3727
3771
  });
3728
3772
  let releaseAdapter;
@@ -3751,9 +3795,14 @@ function apply(ctx, rawConfig) {
3751
3795
  releaseAdapter?.();
3752
3796
  releaseDirectory?.();
3753
3797
  }
3798
+ if (catalog.current().length === 0) ctx.logger.warn("dsh-codearts: CodeArts provider registered with an empty model catalog; models stay unavailable until discovery succeeds");
3799
+ if (!stopped) scheduleDiscovery(nextDiscoveryDelay());
3754
3800
  }).catch((error) => {
3755
3801
  ctx.logger.error("dsh-codearts: loopback shim failed to start; provider not registered", error);
3756
3802
  });
3803
+ await Promise.race([settled, new Promise((resolve) => {
3804
+ setTimeout(resolve, STARTUP_WAIT_MS).unref?.();
3805
+ })]);
3757
3806
  }
3758
3807
  //#endregion
3759
3808
  export { BENEFIT_GATEWAY_HOST, CODEARTS_PROVIDER, CODEARTS_SETTINGS_NS, CodeArtsAccountPool, CodeArtsAccountStore, CodeArtsCatalog, CodeArtsCredentialStore, CodeArtsCreditCache, CodeArtsUsageTracker, Config, FALLBACK_CODEARTS_MODELS, SNAP_HOST, apply, canonicalModel, chatStream, codeartsAccountsPath, codeartsAuthPath, codeartsUsagePath, createCodeArtsAdapter, createCodeArtsShim, discoverModels, fetchCredits, fetchModels, filterEnabledModels, inject, maxTokensCeilingFor, name, parseCreditStatistics, parseTokenBalance, prepareChatBody, refreshCatalog };
@@ -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-q6MY-TXM.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-BRlNY6dB.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";
@@ -321,6 +321,34 @@ function richerThan(a, b) {
321
321
  return a.id !== a.id.toLowerCase() && b.id === b.id.toLowerCase();
322
322
  }
323
323
  /**
324
+ * 提交前用上一轮目录兜住上下文窗口(issue #12)。
325
+ *
326
+ * 发现是逐路并行的:某一路(例如租户 thirdparty)瞬时失败时,同一模型仍可能由别的路
327
+ * 返回,但那条记录不带 `contextWindow`,`fetchModels` 于是落 32768 兜底。整份覆盖后,
328
+ * 已经确认过的好窗口(1M)就被抹掉了,而且一直错到下一轮完整发现。
329
+ *
330
+ * 这里只做一件事:本轮没拿到**可信窗口**的记录(`contextWindowKnown !== true`),
331
+ * 沿用上一轮同 id 的可信窗口。两条边界必须守住:
332
+ * - 不保留上一轮多出来的模型 —— 上游下架的必须消失;
333
+ * - 不覆盖本轮已可信的值(用户覆盖、实测学习、上游真给的都算)。
334
+ */
335
+ function carryKnownWindows(previous, next) {
336
+ const known = /* @__PURE__ */ new Map();
337
+ for (const model of previous) if (model.contextWindowKnown === true && model.contextWindow > 0) known.set(model.id.trim().toLowerCase(), model);
338
+ if (known.size === 0) return next;
339
+ return next.map((model) => {
340
+ if (model.contextWindowKnown === true) return model;
341
+ const old = known.get(model.id.trim().toLowerCase());
342
+ if (old === void 0) return model;
343
+ return {
344
+ ...model,
345
+ contextWindow: old.contextWindow,
346
+ contextWindowKnown: true,
347
+ ...old.contextWindowDiscovered === void 0 ? {} : { contextWindowDiscovered: old.contextWindowDiscovered }
348
+ };
349
+ });
350
+ }
351
+ /**
324
352
  * 用参数表给**发现结果**补 0 值字段。参数表里有、上游这次没返回的模型 —— 不塞进目录。
325
353
  *
326
354
  * 为什么不能把参数表一起丢进 `mergeModelLists`:那个函数按「参数更全/大小写更像注册名」
@@ -2096,4 +2124,4 @@ async function claimDailyWelfare(credential, signal) {
2096
2124
  };
2097
2125
  }
2098
2126
  //#endregion
2099
- export { queueFrame as A, forgetModelUnavailable as B, isWelfareClaimedStatus as C, modelUnavailableReasonText as D, maxTokensCeilingFor as E, CodeArtsCatalog as F, modelDisplayName as G, isBenefitModel as H, FALLBACK_CODEARTS_MODELS as I, modelUnavailableReason as K, clearBenefitBlocked as L, signedGet as M, upstreamErrorMessage as N, pickDailyWelfareCampaign as O, upstream_exports as P, creditRatioLabel as R, isTpmLimit as S, learnedContextWindowFor as T, markModelUnavailable as U, isBenefitBlocked as V, mergeModelLists as W, isNotMultimodal as _, claimDailyWelfare as a, isQueueRejectText as b, degradeTokenCeiling as c, fetchQueueStatus as d, fetchWelfareCampaigns as f, isModelNotAccessible as g, isIamTokenError as h, chatStream as i, rateLimitFrame as j, prepareChatBody as k, fetchCallerIdentity as l, isConcurrencyCap as m, SNAP_HOST as n, clearQueueStatus as o, firstFrameError as p, setDiscoveredBenefitModels as q, canonicalModel as r, contextWindowOverrideFor as s, MAX_TOKENS_FLOOR as t, fetchModels as u, isParamInvalidFrame as v, learnContextWindow as w, isQueueableRate as x, isQueueReject as y, filterEnabledModels as z };
2127
+ export { queueFrame as A, filterEnabledModels as B, isWelfareClaimedStatus as C, modelUnavailableReasonText as D, maxTokensCeilingFor as E, CodeArtsCatalog as F, mergeModelLists as G, isBenefitBlocked as H, FALLBACK_CODEARTS_MODELS as I, setDiscoveredBenefitModels as J, modelDisplayName as K, carryKnownWindows as L, signedGet as M, upstreamErrorMessage as N, pickDailyWelfareCampaign as O, upstream_exports as P, clearBenefitBlocked as R, isTpmLimit as S, learnedContextWindowFor as T, isBenefitModel as U, forgetModelUnavailable as V, markModelUnavailable as W, isNotMultimodal as _, claimDailyWelfare as a, isQueueRejectText as b, degradeTokenCeiling as c, fetchQueueStatus as d, fetchWelfareCampaigns as f, isModelNotAccessible as g, isIamTokenError as h, chatStream as i, rateLimitFrame as j, prepareChatBody as k, fetchCallerIdentity as l, isConcurrencyCap as m, SNAP_HOST as n, clearQueueStatus as o, firstFrameError as p, modelUnavailableReason as q, canonicalModel as r, contextWindowOverrideFor as s, MAX_TOKENS_FLOOR as t, fetchModels as u, isParamInvalidFrame as v, learnContextWindow as w, isQueueableRate as x, isQueueReject as y, creditRatioLabel as z };
@@ -1,5 +1,5 @@
1
- import { u as writeJsonAtomic } from "./auth-q6MY-TXM.mjs";
2
- import { G as modelDisplayName, H as isBenefitModel, W as mergeModelLists, q as setDiscoveredBenefitModels, u as fetchModels } from "./upstream-COqsw56c.mjs";
1
+ import { u as writeJsonAtomic } from "./auth-BRlNY6dB.mjs";
2
+ import { G as mergeModelLists, J as setDiscoveredBenefitModels, K as modelDisplayName, L as carryKnownWindows, U as isBenefitModel, u as fetchModels } from "./upstream-CgQXomCI.mjs";
3
3
  import { existsSync } from "node:fs";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { homedir } from "node:os";
@@ -85,8 +85,9 @@ async function discoverModels(store, signal, contextWindowOverrides) {
85
85
  async function refreshCatalog(store, catalog, signal, contextWindowOverrides) {
86
86
  const outcome = await discoverModels(store, signal, contextWindowOverrides);
87
87
  if (!outcome.anySucceeded || outcome.models.length === 0) return outcome;
88
- setDiscoveredBenefitModels(outcome.models.filter((model) => model.benefit === true).map((model) => model.id));
89
- catalog.set(outcome.models.map((model) => {
88
+ const models = carryKnownWindows(catalog.current(), outcome.models);
89
+ setDiscoveredBenefitModels(models.filter((model) => model.benefit === true).map((model) => model.id));
90
+ catalog.set(models.map((model) => {
90
91
  const benefit = isBenefitModel(model.id);
91
92
  return {
92
93
  ...model,
@@ -535,6 +536,6 @@ function percentileOf(buckets, ratio) {
535
536
  }
536
537
  //#endregion
537
538
  //#region src/version.ts
538
- const CODEARTS_VERSION = "1.4.6";
539
+ const CODEARTS_VERSION = "1.4.8";
539
540
  //#endregion
540
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.6",
5
+ "version": "1.4.8",
6
6
  "packageManager": "pnpm@11.24.0",
7
7
  "author": "elegant01",
8
8
  "keywords": [