dsh-codearts 1.4.5 → 1.4.6

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,24 @@
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.6] - 2026-11-18
7
+
8
+ ### 新增
9
+
10
+ - **企业租户的第三方模型清单**:企业内部专业版由管理员注册的自定义模型,现在也会
11
+ 进入模型目录。发现链路新增一路 `GET /v1/third-party-model/model/list`,先用
12
+ `GET /v1/llm/tenant/settings` 判断租户是否启用第三方模型:未启用的账号不请求清单、
13
+ 也不记错误;只有明确启用后清单失败才上报。与 agent-center 清单重复的模型按现有
14
+ 合并规则去重,输出上限同样兼容 `output_context_window`。
15
+
16
+ ### 修复
17
+
18
+ - **守护进程空窗期不再让凭证裸奔**:插件以前只要看到 keeper 心跳新鲜就完全不
19
+ 自己刷,而 keeper 两轮 tick 之间有 20 分钟空窗 —— 万一下一轮撞上锁忙跳过了,
20
+ 两边就一起不刷,凭证一路走到过期(11-18 凌晨缺 4 轮 tick 那次就是这样)。
21
+ 现在改成「keeper 活着 **且** 下一轮 tick 已经临近」才让路,其余时间插件自己刷,
22
+ 跨进程锁照旧把两边串起来。
23
+
6
24
  ## [1.4.5] - 2026-11-18
7
25
 
8
26
  ### 修复
@@ -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-B_KAbdPy.mjs").then((n) => n.P);
587
+ const { claimBenefit } = await import("./upstream-COqsw56c.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-B5PDMG7r.mjs";
3
- import { H as isBenefitModel, l as fetchCallerIdentity } from "./upstream-B_KAbdPy.mjs";
4
- import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DZ47veC-.mjs";
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";
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
- "count": "xoziZG_count",
160
- "field": "xoziZG_field",
161
- "hint": "xoziZG_hint",
162
- "meta": "xoziZG_meta",
163
- "check": "xoziZG_check",
159
+ "accountName": "xoziZG_accountName",
160
+ "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",
164
167
  "area": "xoziZG_area",
168
+ "usageTipRow": "xoziZG_usageTipRow",
169
+ "groupHead": "xoziZG_groupHead",
170
+ "windowAnchor": "xoziZG_windowAnchor",
171
+ "modelTrack": "xoziZG_modelTrack",
172
+ "windowUnit": "xoziZG_windowUnit",
173
+ "heatGrid": "xoziZG_heatGrid",
174
+ "sectionLabel": "xoziZG_sectionLabel",
165
175
  "modelMeta": "xoziZG_modelMeta",
166
- "choiceRow": "xoziZG_choiceRow",
167
- "updated": "xoziZG_updated",
168
- "statValue": "xoziZG_statValue",
169
- "skeletonRow": "xoziZG_skeletonRow",
176
+ "creditHint": "xoziZG_creditHint",
177
+ "name": "xoziZG_name",
178
+ "usageTip": "xoziZG_usageTip",
179
+ "count": "xoziZG_count",
180
+ "windowRange": "xoziZG_windowRange",
181
+ "sectionHead": "xoziZG_sectionHead",
170
182
  "card": "xoziZG_card",
171
- "headText": "xoziZG_headText",
172
- "windowPopoverValue": "xoziZG_windowPopoverValue",
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
+ "usageFill": "xoziZG_usageFill",
191
+ "windowPopoverHead": "xoziZG_windowPopoverHead",
192
+ "meta": "xoziZG_meta",
193
+ "accountClearHint": "xoziZG_accountClearHint",
194
+ "avatar": "xoziZG_avatar",
173
195
  "windowButtonSet": "xoziZG_windowButtonSet",
174
- "heatAxis": "xoziZG_heatAxis",
175
- "usageTipRow": "xoziZG_usageTipRow",
176
196
  "desc": "xoziZG_desc",
177
- "windowCaret": "xoziZG_windowCaret",
178
- "body": "xoziZG_body",
179
- "usageFill": "xoziZG_usageFill",
180
- "danger": "xoziZG_danger",
181
- "usageTipName": "xoziZG_usageTipName",
182
- "statusLine": "xoziZG_statusLine",
183
- "balance": "xoziZG_balance",
184
- "balanceUnit": "xoziZG_balanceUnit",
185
- "actions": "xoziZG_actions",
186
- "statSub": "xoziZG_statSub",
187
- "accountRowActions": "xoziZG_accountRowActions",
188
- "choiceTail": "xoziZG_choiceTail",
189
- "doctorList": "xoziZG_doctorList",
190
- "bar": "xoziZG_bar",
191
- "accountToolbar": "xoziZG_accountToolbar",
197
+ "updated": "xoziZG_updated",
192
198
  "windowPopover": "xoziZG_windowPopover",
193
- "tabs": "xoziZG_tabs",
194
- "windowButton": "xoziZG_windowButton",
195
- "accountNameRow": "xoziZG_accountNameRow",
196
- "accountRow": "xoziZG_accountRow",
197
- "choices": "xoziZG_choices",
198
- "windowPopoverRow": "xoziZG_windowPopoverRow",
199
- "accountClearHint": "xoziZG_accountClearHint",
200
- "doctorName": "xoziZG_doctorName",
201
- "accountName": "xoziZG_accountName",
202
- "creditRow": "xoziZG_creditRow",
203
- "accountToggle": "xoziZG_accountToggle",
204
- "groupHeadFirst": "xoziZG_groupHeadFirst",
205
- "groupLabel": "xoziZG_groupLabel",
206
- "sectionHead": "xoziZG_sectionHead",
207
- "windowRange": "xoziZG_windowRange",
208
- "usageTipSep": "xoziZG_usageTipSep",
209
- "manual": "xoziZG_manual",
210
- "error": "xoziZG_error",
211
- "accountMenuAnchor": "xoziZG_accountMenuAnchor",
212
- "sectionLabel": "xoziZG_sectionLabel",
213
- "modelShare": "xoziZG_modelShare",
214
- "statCard": "xoziZG_statCard",
215
- "manualForm": "xoziZG_manualForm",
216
- "modelCheck": "xoziZG_modelCheck",
217
- "name": "xoziZG_name",
218
- "accountGrid": "xoziZG_accountGrid",
219
- "creditFooter": "xoziZG_creditFooter",
220
- "balanceRow": "xoziZG_balanceRow",
221
- "fieldLabel": "xoziZG_fieldLabel",
222
- "usageBar": "xoziZG_usageBar",
223
- "statLabel": "xoziZG_statLabel",
224
- "doctorRow": "xoziZG_doctorRow",
199
+ "windowInput": "xoziZG_windowInput",
200
+ "modelSpec": "xoziZG_modelSpec",
201
+ "danger": "xoziZG_danger",
225
202
  "modelName": "xoziZG_modelName",
226
- "accountInfo": "xoziZG_accountInfo",
227
- "heatHours": "xoziZG_heatHours",
228
- "modelFill": "xoziZG_modelFill",
229
- "creditRows": "xoziZG_creditRows",
230
- "balanceMeta": "xoziZG_balanceMeta",
231
203
  "heatAxisSlot": "xoziZG_heatAxisSlot",
232
- "heatLegendChip": "xoziZG_heatLegendChip",
233
- "heatCell": "xoziZG_heatCell",
234
- "skeletonBreath": "xoziZG_skeletonBreath",
235
- "creditHint": "xoziZG_creditHint",
236
- "modelSpec": "xoziZG_modelSpec",
237
- "accountCard": "xoziZG_accountCard",
238
- "statGrid": "xoziZG_statGrid",
239
- "heatHourCell": "xoziZG_heatHourCell",
204
+ "check": "xoziZG_check",
205
+ "tabs": "xoziZG_tabs",
240
206
  "header": "xoziZG_header",
241
- "trendTip": "xoziZG_trendTip",
242
- "modelChart": "xoziZG_modelChart",
243
- "section": "xoziZG_section",
207
+ "doctorRow": "xoziZG_doctorRow",
208
+ "balanceMeta": "xoziZG_balanceMeta",
209
+ "error": "xoziZG_error",
244
210
  "manualSummary": "xoziZG_manualSummary",
245
- "windowButtonOpen": "xoziZG_windowButtonOpen",
246
- "accountClear": "xoziZG_accountClear",
247
- "modelTrack": "xoziZG_modelTrack",
248
- "windowInputSet": "xoziZG_windowInputSet",
249
- "skeleton": "xoziZG_skeleton",
250
- "tabPanel": "xoziZG_tabPanel",
251
- "windowHint": "xoziZG_windowHint",
252
- "link": "xoziZG_link",
211
+ "claimAllRow": "xoziZG_claimAllRow",
212
+ "expiryRow": "xoziZG_expiryRow",
253
213
  "modelRequests": "xoziZG_modelRequests",
254
- "barFill": "xoziZG_barFill",
255
- "accountHint": "xoziZG_accountHint",
256
- "heatGrid": "xoziZG_heatGrid",
257
- "windowInput": "xoziZG_windowInput",
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",
224
+ "balanceRow": "xoziZG_balanceRow",
225
+ "balanceUnit": "xoziZG_balanceUnit",
226
+ "accountMenuAnchor": "xoziZG_accountMenuAnchor",
258
227
  "accountMenuItem": "xoziZG_accountMenuItem",
259
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",
260
237
  "accountEntry": "xoziZG_accountEntry",
261
- "expiryRow": "xoziZG_expiryRow",
262
- "windowPopoverHead": "xoziZG_windowPopoverHead",
238
+ "heatHours": "xoziZG_heatHours",
263
239
  "creditLink": "xoziZG_creditLink",
264
- "modelTokens": "xoziZG_modelTokens",
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",
254
+ "accountGrid": "xoziZG_accountGrid",
265
255
  "accountMenu": "xoziZG_accountMenu",
266
- "avatar": "xoziZG_avatar",
267
- "usageTip": "xoziZG_usageTip",
268
- "windowAnchor": "xoziZG_windowAnchor",
269
- "windowUnit": "xoziZG_windowUnit",
270
- "groupHead": "xoziZG_groupHead",
271
- "heatLegend": "xoziZG_heatLegend",
272
256
  "heatWeekday": "xoziZG_heatWeekday",
273
- "claimAllRow": "xoziZG_claimAllRow",
257
+ "actions": "xoziZG_actions",
258
+ "modelTokens": "xoziZG_modelTokens",
259
+ "heatCell": "xoziZG_heatCell",
260
+ "section": "xoziZG_section",
261
+ "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",
269
+ "usageTipName": "xoziZG_usageTipName",
270
+ "doctorList": "xoziZG_doctorList",
271
+ "statGrid": "xoziZG_statGrid",
272
+ "accountToggle": "xoziZG_accountToggle",
274
273
  "expiryLabel": "xoziZG_expiryLabel",
275
- "creditBlock": "xoziZG_creditBlock"
274
+ "groupHeadFirst": "xoziZG_groupHeadFirst",
275
+ "skeleton": "xoziZG_skeleton"
276
276
  };
277
277
  //#endregion
278
278
  //#region src/client/CodeArtsPluginCard.tsx
@@ -3290,11 +3290,11 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
3290
3290
  }
3291
3291
  var CodeArtsPanel_module_css_default = {
3292
3292
  "back": "Z66cgG_back",
3293
- "desc": "Z66cgG_desc",
3294
- "icon": "Z66cgG_icon",
3295
- "page": "Z66cgG_page",
3296
- "body": "Z66cgG_body",
3297
3293
  "title": "Z66cgG_title",
3294
+ "body": "Z66cgG_body",
3295
+ "page": "Z66cgG_page",
3296
+ "icon": "Z66cgG_icon",
3297
+ "desc": "Z66cgG_desc",
3298
3298
  "head": "Z66cgG_head",
3299
3299
  "backCaret": "Z66cgG_backCaret"
3300
3300
  };
package/lib/index.d.mts CHANGED
@@ -977,7 +977,7 @@ interface CallerIdentity {
977
977
  * 模型清单的来源。前三路是目录本身(任一路失败都不阻断,只有三路全失败才算失败),
978
978
  * `thinking` 只是目录之上的可选增强:它失败时模型照常可用,只是没有思考档位选择器。
979
979
  */
980
- type ModelSource = 'builtin' | 'benefit' | 'agent' | 'thinking';
980
+ type ModelSource = 'builtin' | 'benefit' | 'agent' | 'thirdparty' | 'thinking';
981
981
  interface ModelDiscoveryResult {
982
982
  /** 合并后的清单(已去重、已排序)。 */
983
983
  models: readonly CodeArtsModelInfo[];
@@ -997,10 +997,11 @@ interface CodeArtsQueueStatus {
997
997
  message: string;
998
998
  }
999
999
  /**
1000
- * 动态发现当前账号可用的模型清单(三路合并)。
1000
+ * 动态发现当前账号可用的模型清单(四路合并)。
1001
1001
  *
1002
- * 与 codearts2api 的 `Client.FetchModels` 等价:内置、限时福利、agent-center 三路
1003
- * 各自独立,任一路失败只记进 `errors` 不阻断 —— 福利网关抖动时仍能拿到内置模型。
1002
+ * 内置、限时福利、agent-center、企业第三方模型四路各自独立,任一路失败只记进
1003
+ * `errors` 不阻断 —— 福利网关抖动时仍能拿到内置模型。第三方模型那一路有门禁:
1004
+ * 租户未启用时返回空且不算来源(见 `fetchThirdPartyModels`)。
1004
1005
  *
1005
1006
  * 上标的两个「实测 vs 标称」处理(很重要,别照搬标称值):
1006
1007
  * - **maxTokens 钳到该模型的实测上限**(`MEASURED_MAX_TOKENS`)。上游
@@ -1011,7 +1012,7 @@ interface CodeArtsQueueStatus {
1011
1012
  * 用户配置的按模型覆盖值与进程内学到的真实上界在这里压过发现值(issue #9)。
1012
1013
  *
1013
1014
  * @param contextWindowOverrides 按模型 id 覆盖 contextWindow(大小写不敏感)
1014
- * @throws 三路全失败,或合并结果为空。
1015
+ * @throws 所有来源全失败,或合并结果为空。
1015
1016
  */
1016
1017
  declare function fetchModels(credential: CodeArtsResolved, signal?: AbortSignal, contextWindowOverrides?: Readonly<Record<string, number>>): Promise<ModelDiscoveryResult>;
1017
1018
  //#endregion
package/lib/index.mjs CHANGED
@@ -1,8 +1,8 @@
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-B5PDMG7r.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-B_KAbdPy.mjs";
3
- import { a as refreshCatalog, i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DZ47veC-.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-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";
4
4
  import { i as lazyApi, r as createProvider } from "./models-CgKCibpk.mjs";
5
- import { c as keeperLogPath, d as keeperStats, f as spawnKeeper, i as clearKeeperHandoff, l as keeperScriptPath, n as KEEPER_STALE_MS, p as stopKeeper, s as keeperHandoffRecent } from "./keeper-CA6PKtcv.mjs";
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";
7
7
  import z from "@deepseek-ai/schemastery";
8
8
  import { randomBytes, timingSafeEqual } from "node:crypto";
@@ -3592,9 +3592,26 @@ function apply(ctx, rawConfig) {
3592
3592
  */
3593
3593
  const KEEP_ALIVE_INTERVAL_MS = 12e5;
3594
3594
  let keepAliveTimer;
3595
+ /**
3596
+ * 这一轮该不该把续期让给守护进程。
3597
+ *
3598
+ * 原来只看 `keeperRunning()`(心跳新鲜 + pid 活着)。问题是那个条件在 keeper 的
3599
+ * **两轮 tick 之间(20 分钟空窗)同样成立**,于是插件整段时间完全不刷;万一 keeper
3600
+ * 那一轮撞上锁忙跳过了,两边就一起不刷,凭证一路裸奔到过期(2026-11-18 凌晨
3601
+ * 06:46–08:06 缺 4 轮 tick 时就是这样,见 `keeper-main.ts` 的睡眠补偿注释)。
3602
+ *
3603
+ * 现在改成「keeper 活着 **且** 它马上要来」才让路:只有当下一轮 tick 已到最后
3604
+ * 一个心跳周期的窗口里(或者已经过点了),才把续期权交给它。其余时间插件自己刷,
3605
+ * 反正跨进程锁会把两边串起来。
3606
+ */
3607
+ const shouldDeferToKeeper = () => {
3608
+ const stats = keeperStats();
3609
+ if (!stats.alive) return false;
3610
+ return Date.now() >= keeperNextPassAt(stats.state) - KEEPER_STALE_MS;
3611
+ };
3595
3612
  const keepAliveLoop = async () => {
3596
3613
  if (stopped) return;
3597
- if (keeperRunning()) await store.reloadFromDisk().catch(() => {});
3614
+ if (shouldDeferToKeeper()) await store.reloadFromDisk().catch(() => {});
3598
3615
  else try {
3599
3616
  const outcome = await store.keepAlive();
3600
3617
  if (outcome.refreshed > 0) ctx.logger.debug(`dsh-codearts: refreshed ${outcome.refreshed} credential(s) in the background`);
@@ -127,6 +127,20 @@ function keeperStats(home) {
127
127
  state
128
128
  };
129
129
  }
130
+ /**
131
+ * 下一个 tick 最晚会在什么时候发生。
132
+ *
133
+ * 守护进程每 `KEEPER_TICK_MS` 跑一轮,但那一刻没在跑不代表它死了 —— 两轮之间就是
134
+ * 20 分钟的空窗。插件要判断「这一轮的续期该由谁来负责」,必须看这个时间点,而不是
135
+ * 只看 `alive`。
136
+ *
137
+ * 补了一点余量(`KEEPER_STALE_MS`):tick 本身要读文档、逐号发请求,慢的时候能拖上
138
+ * 几十秒,卡在边界上会让插件抢在 keeper 落库前就把号刷了 —— 那正是要避免的双刷。
139
+ */
140
+ function keeperNextPassAt(state) {
141
+ if (state === void 0) return 0;
142
+ return (state.lastPass?.at ?? state.startedAt) + KEEPER_TICK_MS + KEEPER_STALE_MS;
143
+ }
130
144
  /** 守护进程的脚本路径:和当前 bundle 同目录的 `keeper-main.mjs`(tsdown 入口名)。 */
131
145
  function keeperScriptPath() {
132
146
  return fileURLToPath(new URL("./keeper-main.mjs", import.meta.url));
@@ -317,4 +331,4 @@ function stopRequested(home) {
317
331
  return existsSync(join(home ?? dshHome(), ".codearts-keeper.stop"));
318
332
  }
319
333
  //#endregion
320
- export { clearKeeperState as a, keeperLogPath as c, keeperStats as d, spawnKeeper as f, writeKeeperState as g, writeKeeperHandoff as h, clearKeeperHandoff as i, keeperScriptPath as l, stopRequested as m, KEEPER_STALE_MS as n, isDshInstallerTempDir as o, stopKeeper as p, KEEPER_TICK_MS as r, keeperHandoffRecent as s, KEEPER_HEARTBEAT_MS as t, keeperStatePath as u };
334
+ export { writeKeeperState as _, clearKeeperState as a, keeperLogPath as c, keeperStatePath as d, keeperStats as f, writeKeeperHandoff as g, stopRequested as h, clearKeeperHandoff as i, keeperNextPassAt as l, stopKeeper as m, KEEPER_STALE_MS as n, isDshInstallerTempDir as o, spawnKeeper as p, KEEPER_TICK_MS as r, keeperHandoffRecent as s, KEEPER_HEARTBEAT_MS as t, keeperScriptPath as u };
@@ -1,5 +1,5 @@
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-B5PDMG7r.mjs";
2
- import { a as clearKeeperState, c as keeperLogPath, d as keeperStats, g as writeKeeperState, h as writeKeeperHandoff, i as clearKeeperHandoff, m as stopRequested, o as isDshInstallerTempDir, r as KEEPER_TICK_MS, t as KEEPER_HEARTBEAT_MS, u as keeperStatePath } from "./keeper-CA6PKtcv.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-q6MY-TXM.mjs";
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";
5
5
  //#region src/keeper-main.ts
@@ -505,6 +505,13 @@ const EP_BENEFIT_CONFIG = "/api/v1/gateway/config";
505
505
  const EP_AGENT_LIST = "/v1/agent-center/agents/useragents";
506
506
  const EP_AGENT_DETAIL = "/v1/agent-center/agents/detail";
507
507
  /**
508
+ * 企业租户设置与第三方模型清单(26.11 客户端)。官方客户端先按套餐门禁
509
+ * (`is_credit_package && spec_code 含 enterprise`,或白名单)判断后才请求,
510
+ * 普通账号不会走到。见 `fetchThirdPartyModels`。
511
+ */
512
+ const EP_TENANT_SETTINGS = "/v1/llm/tenant/settings";
513
+ const EP_THIRD_PARTY_MODELS = "/v1/third-party-model/model/list";
514
+ /**
508
515
  * 模型的思考强度清单(26.10.0 新增)。**必须带 `Agent-Type: PromptCenter`**:
509
516
  * 不带头时上游回 `TM.00001001 请求头Agent-Type为空`(实测)。
510
517
  */
@@ -1593,6 +1600,70 @@ async function fetchAgentModels(credential, signal) {
1593
1600
  }
1594
1601
  return out;
1595
1602
  }
1603
+ /** 租户是否启用了第三方模型;读不到明确值时返回 undefined(交给调用方决定)。 */
1604
+ function thirdPartyModelsEnabled(value) {
1605
+ const body = asRecord(value);
1606
+ for (const candidate of [
1607
+ body.third_party_model_enabled,
1608
+ asRecord(body.data).third_party_model_enabled,
1609
+ asRecord(body.settings).third_party_model_enabled
1610
+ ]) {
1611
+ if (candidate === true) return true;
1612
+ if (candidate === false) return false;
1613
+ }
1614
+ }
1615
+ /**
1616
+ * 企业租户的第三方模型清单:先 `GET /v1/llm/tenant/settings` 拿门禁,再
1617
+ * `GET /v1/third-party-model/model/list`(分页,官方客户端一页取 100 条)。
1618
+ *
1619
+ * 这类模型是企业管理员注册的 MaaS 通道(企业内部专业版的主力),与 agent-center
1620
+ * 的 `gpts.models` 同源但不完全重合:没挂到 CodeAgent 上的模型只在清单里出现。
1621
+ *
1622
+ * 门禁失败或未启用时返回空数组且不记 errors —— 官方客户端对普通账号根本不会
1623
+ * 请求这两条接口,我们照做,免得每个个人账号每轮刷新都多两条噪音。只有租户明确
1624
+ * 启用后清单仍失败,才把失败带回去(那说明企业账号的发现链路真断了)。
1625
+ *
1626
+ * 条目形状以 `model_parameters` 为准,也兼容参数摊平在顶层的写法(官方客户端两处
1627
+ * 都兼容)。输出上限同样可能放在 `output_context_window`(#11)。
1628
+ */
1629
+ async function fetchThirdPartyModels(credential, signal) {
1630
+ const settingsResp = await signedGet(`${SNAP_HOST}${EP_TENANT_SETTINGS}`, credential, "PromptCenter", signal);
1631
+ if (!settingsResp.ok) return [];
1632
+ const enabled = thirdPartyModelsEnabled(parseJson(settingsResp.text));
1633
+ if (enabled === false) return [];
1634
+ const listResp = await signedGet(`${SNAP_HOST}${EP_THIRD_PARTY_MODELS}?page_num=1&page_size=100`, credential, "PromptCenter", signal);
1635
+ if (!listResp.ok) {
1636
+ if (enabled === true) throw new Error(`third-party model list HTTP ${listResp.status} ${listResp.message}`);
1637
+ return [];
1638
+ }
1639
+ const body = asRecord(parseJson(listResp.text));
1640
+ const error = body.error ?? asRecord(body.data).error;
1641
+ if (error !== void 0) {
1642
+ if (enabled === true) throw new Error(`third-party model list error: ${JSON.stringify(error).slice(0, 200)}`);
1643
+ return [];
1644
+ }
1645
+ const out = [];
1646
+ for (const raw of asArray(body.list ?? asRecord(body.data).list)) {
1647
+ const item = asRecord(raw);
1648
+ const params = asRecord(item.model_parameters);
1649
+ const flat = Object.keys(params).length > 0 ? params : item;
1650
+ if (item.enable === false || item.display_enabled === false) continue;
1651
+ const id = firstString(flat.model_id, item.model_id, item.model_alias, flat.service_name, flat.third_party_model);
1652
+ if (id === "") continue;
1653
+ const ratio = creditRatioOf(item) ?? creditRatioOf(flat);
1654
+ const contextWindow = positive(flat.context_window);
1655
+ out.push({
1656
+ id,
1657
+ name: firstString(item.model_name, item.model_alias, flat.model_name, id),
1658
+ contextWindow,
1659
+ ...contextWindow > 0 ? { contextWindowKnown: true } : {},
1660
+ maxTokens: positive(flat.max_tokens) || positive(flat.output_context_window),
1661
+ supportsImages: item.supports_images === true || flat.supports_images === true,
1662
+ ...ratio === void 0 ? {} : { ratio }
1663
+ });
1664
+ }
1665
+ return out;
1666
+ }
1596
1667
  /**
1597
1668
  * 思考强度清单:`POST /v1/model/thinking-variants`,body `{ model_names }`。
1598
1669
  *
@@ -1716,10 +1787,11 @@ async function clearQueueStatus(credential, chatId, model, signal) {
1716
1787
  }
1717
1788
  }
1718
1789
  /**
1719
- * 动态发现当前账号可用的模型清单(三路合并)。
1790
+ * 动态发现当前账号可用的模型清单(四路合并)。
1720
1791
  *
1721
- * 与 codearts2api 的 `Client.FetchModels` 等价:内置、限时福利、agent-center 三路
1722
- * 各自独立,任一路失败只记进 `errors` 不阻断 —— 福利网关抖动时仍能拿到内置模型。
1792
+ * 内置、限时福利、agent-center、企业第三方模型四路各自独立,任一路失败只记进
1793
+ * `errors` 不阻断 —— 福利网关抖动时仍能拿到内置模型。第三方模型那一路有门禁:
1794
+ * 租户未启用时返回空且不算来源(见 `fetchThirdPartyModels`)。
1723
1795
  *
1724
1796
  * 上标的两个「实测 vs 标称」处理(很重要,别照搬标称值):
1725
1797
  * - **maxTokens 钳到该模型的实测上限**(`MEASURED_MAX_TOKENS`)。上游
@@ -1730,7 +1802,7 @@ async function clearQueueStatus(credential, chatId, model, signal) {
1730
1802
  * 用户配置的按模型覆盖值与进程内学到的真实上界在这里压过发现值(issue #9)。
1731
1803
  *
1732
1804
  * @param contextWindowOverrides 按模型 id 覆盖 contextWindow(大小写不敏感)
1733
- * @throws 三路全失败,或合并结果为空。
1805
+ * @throws 所有来源全失败,或合并结果为空。
1734
1806
  */
1735
1807
  async function fetchModels(credential, signal, contextWindowOverrides = {}) {
1736
1808
  const settled = await Promise.all([
@@ -1754,6 +1826,13 @@ async function fetchModels(credential, signal, contextWindowOverrides = {}) {
1754
1826
  }), (error) => ({
1755
1827
  source: "agent",
1756
1828
  error
1829
+ })),
1830
+ fetchThirdPartyModels(credential, signal).then((models) => ({
1831
+ source: "thirdparty",
1832
+ models
1833
+ }), (error) => ({
1834
+ source: "thirdparty",
1835
+ error
1757
1836
  }))
1758
1837
  ]);
1759
1838
  const sources = [];
@@ -1763,6 +1842,7 @@ async function fetchModels(credential, signal, contextWindowOverrides = {}) {
1763
1842
  source: item.source,
1764
1843
  message: item.error.message
1765
1844
  });
1845
+ else if (item.source === "thirdparty" && item.models.length === 0) continue;
1766
1846
  else {
1767
1847
  sources.push(item.source);
1768
1848
  discovered.push(item.models);
@@ -1,5 +1,5 @@
1
- import { u as writeJsonAtomic } from "./auth-B5PDMG7r.mjs";
2
- import { G as modelDisplayName, H as isBenefitModel, W as mergeModelLists, q as setDiscoveredBenefitModels, u as fetchModels } from "./upstream-B_KAbdPy.mjs";
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";
3
3
  import { existsSync } from "node:fs";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { homedir } from "node:os";
@@ -535,6 +535,6 @@ function percentileOf(buckets, ratio) {
535
535
  }
536
536
  //#endregion
537
537
  //#region src/version.ts
538
- const CODEARTS_VERSION = "1.4.5";
538
+ const CODEARTS_VERSION = "1.4.6";
539
539
  //#endregion
540
540
  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",
5
+ "version": "1.4.6",
6
6
  "packageManager": "pnpm@11.24.0",
7
7
  "author": "elegant01",
8
8
  "keywords": [