dsh-codearts 1.4.5 → 1.4.7
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 +37 -0
- package/lib/{auth-B5PDMG7r.mjs → auth-BRlNY6dB.mjs} +1 -1
- package/lib/bin.mjs +3 -3
- package/lib/client/index.js +105 -105
- package/lib/index.d.mts +7 -6
- package/lib/index.mjs +58 -19
- package/lib/{keeper-CA6PKtcv.mjs → keeper-BWHQDFAh.mjs} +15 -1
- package/lib/keeper-main.mjs +2 -2
- package/lib/{upstream-B_KAbdPy.mjs → upstream-CgQXomCI.mjs} +113 -5
- package/lib/{version-DZ47veC-.mjs → version-DNEBIi8C.mjs} +6 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,43 @@
|
|
|
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.7] - 2026-11-20
|
|
7
|
+
|
|
8
|
+
### 修复
|
|
9
|
+
|
|
10
|
+
- **「成功但不完整」的一轮发现不再把已知上下文窗口降级**(#12):发现是逐路并行
|
|
11
|
+
的,某一路(如企业租户 thirdparty)瞬时失败时,同一模型仍可能由别的路返回,但
|
|
12
|
+
不带 `contextWindow`,于是被 32768 兜底值覆盖,而且一直错到下一轮完整发现 ——
|
|
13
|
+
长会话在 400 context_overflow 上反复失败。现在提交前按 id 回查上一轮目录:本轮
|
|
14
|
+
没拿到可信窗口的记录沿用上一轮的值(`contextWindowKnown` 与标称值一起带过去),
|
|
15
|
+
本轮已可信的值不动,上游下架的模型照常消失。
|
|
16
|
+
- **无头 / 一次性进程启动时模型列表不再为空**(#13):`apply` 以前是同步函数,
|
|
17
|
+
模型发现与 provider 注册都在它返回之后的异步链里,而宿主只等 `apply` 的返回值 ——
|
|
18
|
+
`--list-models`、headless 任务、平台的本机运行时在 profile 加载完立刻下结论,
|
|
19
|
+
拿到空目录(`has no configured model`)且零日志。现在 `apply` 等待「shim 就绪 →
|
|
20
|
+
首轮发现 → 注册」整条链,首轮发现 10 秒超时、启动总预算 15 秒,超时按空目录继续
|
|
21
|
+
并告警,不会拖死启动;目录为空注册时补一条 `warn`。
|
|
22
|
+
- 首次发现不再多打一轮上游:启动引导跑完首轮后由退避循环接棒,而不是循环自己
|
|
23
|
+
立刻再发现一次。
|
|
24
|
+
|
|
25
|
+
## [1.4.6] - 2026-11-18
|
|
26
|
+
|
|
27
|
+
### 新增
|
|
28
|
+
|
|
29
|
+
- **企业租户的第三方模型清单**:企业内部专业版由管理员注册的自定义模型,现在也会
|
|
30
|
+
进入模型目录。发现链路新增一路 `GET /v1/third-party-model/model/list`,先用
|
|
31
|
+
`GET /v1/llm/tenant/settings` 判断租户是否启用第三方模型:未启用的账号不请求清单、
|
|
32
|
+
也不记错误;只有明确启用后清单失败才上报。与 agent-center 清单重复的模型按现有
|
|
33
|
+
合并规则去重,输出上限同样兼容 `output_context_window`。
|
|
34
|
+
|
|
35
|
+
### 修复
|
|
36
|
+
|
|
37
|
+
- **守护进程空窗期不再让凭证裸奔**:插件以前只要看到 keeper 心跳新鲜就完全不
|
|
38
|
+
自己刷,而 keeper 两轮 tick 之间有 20 分钟空窗 —— 万一下一轮撞上锁忙跳过了,
|
|
39
|
+
两边就一起不刷,凭证一路走到过期(11-18 凌晨缺 4 轮 tick 那次就是这样)。
|
|
40
|
+
现在改成「keeper 活着 **且** 下一轮 tick 已经临近」才让路,其余时间插件自己刷,
|
|
41
|
+
跨进程锁照旧把两边串起来。
|
|
42
|
+
|
|
6
43
|
## [1.4.5] - 2026-11-18
|
|
7
44
|
|
|
8
45
|
### 修复
|
|
@@ -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-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-
|
|
3
|
-
import {
|
|
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-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-DNEBIi8C.mjs";
|
|
5
5
|
import { existsSync, statSync } from "node:fs";
|
|
6
6
|
//#region src/bin.ts
|
|
7
7
|
/**
|
package/lib/client/index.js
CHANGED
|
@@ -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
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"headText": "xoziZG_headText",
|
|
172
|
-
"windowPopoverValue": "xoziZG_windowPopoverValue",
|
|
173
|
-
"windowButtonSet": "xoziZG_windowButtonSet",
|
|
174
|
-
"heatAxis": "xoziZG_heatAxis",
|
|
175
|
-
"usageTipRow": "xoziZG_usageTipRow",
|
|
159
|
+
"expiryRow": "xoziZG_expiryRow",
|
|
160
|
+
"accountInfo": "xoziZG_accountInfo",
|
|
161
|
+
"sectionHead": "xoziZG_sectionHead",
|
|
162
|
+
"accountHint": "xoziZG_accountHint",
|
|
163
|
+
"modelRow": "xoziZG_modelRow",
|
|
164
|
+
"accountName": "xoziZG_accountName",
|
|
165
|
+
"accountMenuAnchor": "xoziZG_accountMenuAnchor",
|
|
166
|
+
"usageBar": "xoziZG_usageBar",
|
|
167
|
+
"barFill": "xoziZG_barFill",
|
|
168
|
+
"actions": "xoziZG_actions",
|
|
169
|
+
"modelChart": "xoziZG_modelChart",
|
|
170
|
+
"accountToggle": "xoziZG_accountToggle",
|
|
176
171
|
"desc": "xoziZG_desc",
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"
|
|
172
|
+
"accountEntry": "xoziZG_accountEntry",
|
|
173
|
+
"modelShare": "xoziZG_modelShare",
|
|
174
|
+
"doctorName": "xoziZG_doctorName",
|
|
175
|
+
"accountCard": "xoziZG_accountCard",
|
|
176
|
+
"modelRequests": "xoziZG_modelRequests",
|
|
177
|
+
"balanceUnit": "xoziZG_balanceUnit",
|
|
178
|
+
"groupHead": "xoziZG_groupHead",
|
|
179
|
+
"statGrid": "xoziZG_statGrid",
|
|
180
|
+
"accountRow": "xoziZG_accountRow",
|
|
181
|
+
"statCard": "xoziZG_statCard",
|
|
182
|
+
"modelName": "xoziZG_modelName",
|
|
183
|
+
"heatGrid": "xoziZG_heatGrid",
|
|
184
|
+
"heatLegendChip": "xoziZG_heatLegendChip",
|
|
185
|
+
"manualSummary": "xoziZG_manualSummary",
|
|
182
186
|
"statusLine": "xoziZG_statusLine",
|
|
187
|
+
"check": "xoziZG_check",
|
|
183
188
|
"balance": "xoziZG_balance",
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"doctorList": "xoziZG_doctorList",
|
|
190
|
-
"bar": "xoziZG_bar",
|
|
191
|
-
"accountToolbar": "xoziZG_accountToolbar",
|
|
192
|
-
"windowPopover": "xoziZG_windowPopover",
|
|
193
|
-
"tabs": "xoziZG_tabs",
|
|
189
|
+
"expiryLabel": "xoziZG_expiryLabel",
|
|
190
|
+
"usageTipName": "xoziZG_usageTipName",
|
|
191
|
+
"skeletonBreath": "xoziZG_skeletonBreath",
|
|
192
|
+
"headText": "xoziZG_headText",
|
|
193
|
+
"creditRows": "xoziZG_creditRows",
|
|
194
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
195
|
"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
196
|
"sectionLabel": "xoziZG_sectionLabel",
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
"
|
|
217
|
-
"
|
|
218
|
-
"accountGrid": "xoziZG_accountGrid",
|
|
219
|
-
"creditFooter": "xoziZG_creditFooter",
|
|
220
|
-
"balanceRow": "xoziZG_balanceRow",
|
|
221
|
-
"fieldLabel": "xoziZG_fieldLabel",
|
|
222
|
-
"usageBar": "xoziZG_usageBar",
|
|
197
|
+
"modelTokens": "xoziZG_modelTokens",
|
|
198
|
+
"modelSpec": "xoziZG_modelSpec",
|
|
199
|
+
"body": "xoziZG_body",
|
|
200
|
+
"creditHint": "xoziZG_creditHint",
|
|
201
|
+
"danger": "xoziZG_danger",
|
|
223
202
|
"statLabel": "xoziZG_statLabel",
|
|
203
|
+
"creditBlock": "xoziZG_creditBlock",
|
|
204
|
+
"count": "xoziZG_count",
|
|
224
205
|
"doctorRow": "xoziZG_doctorRow",
|
|
225
|
-
"
|
|
226
|
-
"
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
"
|
|
206
|
+
"link": "xoziZG_link",
|
|
207
|
+
"accountMenuItem": "xoziZG_accountMenuItem",
|
|
208
|
+
"usageTipRow": "xoziZG_usageTipRow",
|
|
209
|
+
"windowHint": "xoziZG_windowHint",
|
|
210
|
+
"hint": "xoziZG_hint",
|
|
211
|
+
"accountGrid": "xoziZG_accountGrid",
|
|
212
|
+
"fieldLabel": "xoziZG_fieldLabel",
|
|
213
|
+
"windowPopoverValue": "xoziZG_windowPopoverValue",
|
|
214
|
+
"accountNameRow": "xoziZG_accountNameRow",
|
|
233
215
|
"heatCell": "xoziZG_heatCell",
|
|
234
|
-
"
|
|
235
|
-
"
|
|
236
|
-
"modelSpec": "xoziZG_modelSpec",
|
|
237
|
-
"accountCard": "xoziZG_accountCard",
|
|
238
|
-
"statGrid": "xoziZG_statGrid",
|
|
239
|
-
"heatHourCell": "xoziZG_heatHourCell",
|
|
216
|
+
"heatAxis": "xoziZG_heatAxis",
|
|
217
|
+
"field": "xoziZG_field",
|
|
240
218
|
"header": "xoziZG_header",
|
|
241
|
-
"
|
|
242
|
-
"modelChart": "xoziZG_modelChart",
|
|
219
|
+
"accountMenu": "xoziZG_accountMenu",
|
|
243
220
|
"section": "xoziZG_section",
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
221
|
+
"manualForm": "xoziZG_manualForm",
|
|
222
|
+
"groupHeadFirst": "xoziZG_groupHeadFirst",
|
|
223
|
+
"statSub": "xoziZG_statSub",
|
|
224
|
+
"tabs": "xoziZG_tabs",
|
|
247
225
|
"modelTrack": "xoziZG_modelTrack",
|
|
226
|
+
"modelCheck": "xoziZG_modelCheck",
|
|
227
|
+
"windowPopover": "xoziZG_windowPopover",
|
|
228
|
+
"windowRange": "xoziZG_windowRange",
|
|
229
|
+
"manual": "xoziZG_manual",
|
|
248
230
|
"windowInputSet": "xoziZG_windowInputSet",
|
|
249
|
-
"skeleton": "xoziZG_skeleton",
|
|
250
|
-
"tabPanel": "xoziZG_tabPanel",
|
|
251
|
-
"windowHint": "xoziZG_windowHint",
|
|
252
|
-
"link": "xoziZG_link",
|
|
253
|
-
"modelRequests": "xoziZG_modelRequests",
|
|
254
|
-
"barFill": "xoziZG_barFill",
|
|
255
|
-
"accountHint": "xoziZG_accountHint",
|
|
256
|
-
"heatGrid": "xoziZG_heatGrid",
|
|
257
|
-
"windowInput": "xoziZG_windowInput",
|
|
258
|
-
"accountMenuItem": "xoziZG_accountMenuItem",
|
|
259
|
-
"modelRow": "xoziZG_modelRow",
|
|
260
|
-
"accountEntry": "xoziZG_accountEntry",
|
|
261
|
-
"expiryRow": "xoziZG_expiryRow",
|
|
262
|
-
"windowPopoverHead": "xoziZG_windowPopoverHead",
|
|
263
|
-
"creditLink": "xoziZG_creditLink",
|
|
264
|
-
"modelTokens": "xoziZG_modelTokens",
|
|
265
|
-
"accountMenu": "xoziZG_accountMenu",
|
|
266
|
-
"avatar": "xoziZG_avatar",
|
|
267
231
|
"usageTip": "xoziZG_usageTip",
|
|
232
|
+
"area": "xoziZG_area",
|
|
233
|
+
"accountRowActions": "xoziZG_accountRowActions",
|
|
268
234
|
"windowAnchor": "xoziZG_windowAnchor",
|
|
235
|
+
"claimAllRow": "xoziZG_claimAllRow",
|
|
236
|
+
"heatHourCell": "xoziZG_heatHourCell",
|
|
237
|
+
"accountToolbar": "xoziZG_accountToolbar",
|
|
238
|
+
"usageFill": "xoziZG_usageFill",
|
|
239
|
+
"accountClearHint": "xoziZG_accountClearHint",
|
|
240
|
+
"creditLink": "xoziZG_creditLink",
|
|
241
|
+
"doctorList": "xoziZG_doctorList",
|
|
242
|
+
"heatHours": "xoziZG_heatHours",
|
|
243
|
+
"modelMeta": "xoziZG_modelMeta",
|
|
269
244
|
"windowUnit": "xoziZG_windowUnit",
|
|
270
|
-
"
|
|
245
|
+
"choiceTail": "xoziZG_choiceTail",
|
|
246
|
+
"name": "xoziZG_name",
|
|
247
|
+
"windowPopoverHead": "xoziZG_windowPopoverHead",
|
|
248
|
+
"choiceRow": "xoziZG_choiceRow",
|
|
249
|
+
"accountClear": "xoziZG_accountClear",
|
|
250
|
+
"skeleton": "xoziZG_skeleton",
|
|
251
|
+
"meta": "xoziZG_meta",
|
|
271
252
|
"heatLegend": "xoziZG_heatLegend",
|
|
253
|
+
"card": "xoziZG_card",
|
|
254
|
+
"windowPopoverRow": "xoziZG_windowPopoverRow",
|
|
255
|
+
"balanceMeta": "xoziZG_balanceMeta",
|
|
256
|
+
"error": "xoziZG_error",
|
|
272
257
|
"heatWeekday": "xoziZG_heatWeekday",
|
|
273
|
-
"
|
|
274
|
-
"
|
|
275
|
-
"
|
|
258
|
+
"heatAxisSlot": "xoziZG_heatAxisSlot",
|
|
259
|
+
"balanceRow": "xoziZG_balanceRow",
|
|
260
|
+
"usageTipSep": "xoziZG_usageTipSep",
|
|
261
|
+
"avatar": "xoziZG_avatar",
|
|
262
|
+
"choices": "xoziZG_choices",
|
|
263
|
+
"skeletonRow": "xoziZG_skeletonRow",
|
|
264
|
+
"trendTip": "xoziZG_trendTip",
|
|
265
|
+
"updated": "xoziZG_updated",
|
|
266
|
+
"windowCaret": "xoziZG_windowCaret",
|
|
267
|
+
"tabPanel": "xoziZG_tabPanel",
|
|
268
|
+
"creditFooter": "xoziZG_creditFooter",
|
|
269
|
+
"windowButtonSet": "xoziZG_windowButtonSet",
|
|
270
|
+
"bar": "xoziZG_bar",
|
|
271
|
+
"windowButtonOpen": "xoziZG_windowButtonOpen",
|
|
272
|
+
"windowInput": "xoziZG_windowInput",
|
|
273
|
+
"creditRow": "xoziZG_creditRow",
|
|
274
|
+
"modelFill": "xoziZG_modelFill",
|
|
275
|
+
"statValue": "xoziZG_statValue"
|
|
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
|
-
"desc": "Z66cgG_desc",
|
|
3294
|
-
"icon": "Z66cgG_icon",
|
|
3295
|
-
"page": "Z66cgG_page",
|
|
3296
3292
|
"body": "Z66cgG_body",
|
|
3297
|
-
"
|
|
3293
|
+
"page": "Z66cgG_page",
|
|
3298
3294
|
"head": "Z66cgG_head",
|
|
3299
|
-
"backCaret": "Z66cgG_backCaret"
|
|
3295
|
+
"backCaret": "Z66cgG_backCaret",
|
|
3296
|
+
"title": "Z66cgG_title",
|
|
3297
|
+
"desc": "Z66cgG_desc",
|
|
3298
|
+
"icon": "Z66cgG_icon",
|
|
3299
|
+
"back": "Z66cgG_back"
|
|
3300
3300
|
};
|
|
3301
3301
|
//#endregion
|
|
3302
3302
|
//#region src/client/CodeArtsPanel.tsx
|
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
|
-
*
|
|
1003
|
-
*
|
|
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
|
|
@@ -1922,6 +1923,6 @@ interface Config {
|
|
|
1922
1923
|
queueWaitUntilReady?: boolean;
|
|
1923
1924
|
}
|
|
1924
1925
|
declare const Config: z<Config>;
|
|
1925
|
-
declare function apply(ctx: Context, rawConfig: Config): void
|
|
1926
|
+
declare function apply(ctx: Context, rawConfig: Config): Promise<void>;
|
|
1926
1927
|
//#endregion
|
|
1927
1928
|
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,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-
|
|
2
|
-
import { A as queueFrame, B as
|
|
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-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-DNEBIi8C.mjs";
|
|
4
4
|
import { i as lazyApi, r as createProvider } from "./models-CgKCibpk.mjs";
|
|
5
|
-
import { c as keeperLogPath,
|
|
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";
|
|
@@ -3138,7 +3138,7 @@ const Config = z.object({
|
|
|
3138
3138
|
function settingsCompatNamespace(ctx) {
|
|
3139
3139
|
return resolveSettingsNamespaceCompat(ctx, ctx.get("settings"), CODEARTS_SETTINGS_NS);
|
|
3140
3140
|
}
|
|
3141
|
-
function apply(ctx, rawConfig) {
|
|
3141
|
+
async function apply(ctx, rawConfig) {
|
|
3142
3142
|
const config = unwrapConfig(rawConfig);
|
|
3143
3143
|
const accountsPath = codeartsAccountsPath();
|
|
3144
3144
|
/**
|
|
@@ -3542,11 +3542,22 @@ function apply(ctx, rawConfig) {
|
|
|
3542
3542
|
const CATALOG_REFRESH_MS = 36e5;
|
|
3543
3543
|
const CATALOG_EMPTY_RETRY_MS = 6e4;
|
|
3544
3544
|
const CATALOG_EMPTY_RETRY_MAX_MS = 3e5;
|
|
3545
|
+
/**
|
|
3546
|
+
* 启动首轮发现的预算(issue #13)。
|
|
3547
|
+
*
|
|
3548
|
+
* 一次性宿主(`--list-models`、`dsh headless`、Multica 的本机运行时)在 profile
|
|
3549
|
+
* 加载完就列模型 / 解析模型,等不到后台的任何一轮重试 —— 目录空就是定论。所以
|
|
3550
|
+
* 首轮发现要挡在注册之前、并让 `apply` 等它。但上游挂住时不能把启动一起拖死:
|
|
3551
|
+
* 超时按空目录继续注册,循环随后照常补。手动刷新那条路是 60s,启动不能照抄。
|
|
3552
|
+
*/
|
|
3553
|
+
const STARTUP_DISCOVERY_MS = 1e4;
|
|
3554
|
+
/** 启动引导的总预算:发现另有 10s 自己的预算,这里防的是 shim 启动 / probe 卡住。 */
|
|
3555
|
+
const STARTUP_WAIT_MS = 15e3;
|
|
3545
3556
|
const abort = new AbortController();
|
|
3546
|
-
const discover = async () => {
|
|
3557
|
+
const discover = async (signal = abort.signal) => {
|
|
3547
3558
|
if (stopped) return;
|
|
3548
3559
|
try {
|
|
3549
|
-
const outcome = await refreshCatalog(store, catalog,
|
|
3560
|
+
const outcome = await refreshCatalog(store, catalog, signal, current().contextWindowOverrides);
|
|
3550
3561
|
if (outcome === void 0 || stopped) return;
|
|
3551
3562
|
if (outcome.anySucceeded) {
|
|
3552
3563
|
const free = outcome.models.filter((model) => model.benefit === true).length;
|
|
@@ -3559,21 +3570,26 @@ function apply(ctx, rawConfig) {
|
|
|
3559
3570
|
let discoveryTimer;
|
|
3560
3571
|
/** 连续多少轮目录是空的(用来算退避);一旦有货就归零。 */
|
|
3561
3572
|
let emptyStreak = 0;
|
|
3562
|
-
/**
|
|
3563
|
-
const
|
|
3564
|
-
await discover();
|
|
3565
|
-
if (stopped) return;
|
|
3566
|
-
let delay;
|
|
3573
|
+
/** 下一轮发现该隔多久:目录为空时退避(60s → 5min 封顶),有货后回到每小时。 */
|
|
3574
|
+
const nextDiscoveryDelay = () => {
|
|
3567
3575
|
if (catalog.current().length === 0) {
|
|
3568
|
-
delay = Math.min(CATALOG_EMPTY_RETRY_MS * 2 ** emptyStreak, CATALOG_EMPTY_RETRY_MAX_MS);
|
|
3576
|
+
const delay = Math.min(CATALOG_EMPTY_RETRY_MS * 2 ** emptyStreak, CATALOG_EMPTY_RETRY_MAX_MS);
|
|
3569
3577
|
emptyStreak += 1;
|
|
3570
|
-
|
|
3571
|
-
emptyStreak = 0;
|
|
3572
|
-
delay = CATALOG_REFRESH_MS;
|
|
3578
|
+
return delay;
|
|
3573
3579
|
}
|
|
3580
|
+
emptyStreak = 0;
|
|
3581
|
+
return CATALOG_REFRESH_MS;
|
|
3582
|
+
};
|
|
3583
|
+
const scheduleDiscovery = (delay) => {
|
|
3574
3584
|
discoveryTimer = setTimeout(() => void discoverLoop(), delay);
|
|
3575
3585
|
discoveryTimer.unref?.();
|
|
3576
3586
|
};
|
|
3587
|
+
/** 自我重排的发现循环:首轮由启动引导跑完后从这里接棒,不再立刻多打一轮上游。 */
|
|
3588
|
+
const discoverLoop = async () => {
|
|
3589
|
+
await discover();
|
|
3590
|
+
if (stopped) return;
|
|
3591
|
+
scheduleDiscovery(nextDiscoveryDelay());
|
|
3592
|
+
};
|
|
3577
3593
|
ctx.effect(() => () => {
|
|
3578
3594
|
abort.abort();
|
|
3579
3595
|
if (discoveryTimer !== void 0) clearTimeout(discoveryTimer);
|
|
@@ -3592,9 +3608,26 @@ function apply(ctx, rawConfig) {
|
|
|
3592
3608
|
*/
|
|
3593
3609
|
const KEEP_ALIVE_INTERVAL_MS = 12e5;
|
|
3594
3610
|
let keepAliveTimer;
|
|
3611
|
+
/**
|
|
3612
|
+
* 这一轮该不该把续期让给守护进程。
|
|
3613
|
+
*
|
|
3614
|
+
* 原来只看 `keeperRunning()`(心跳新鲜 + pid 活着)。问题是那个条件在 keeper 的
|
|
3615
|
+
* **两轮 tick 之间(20 分钟空窗)同样成立**,于是插件整段时间完全不刷;万一 keeper
|
|
3616
|
+
* 那一轮撞上锁忙跳过了,两边就一起不刷,凭证一路裸奔到过期(2026-11-18 凌晨
|
|
3617
|
+
* 06:46–08:06 缺 4 轮 tick 时就是这样,见 `keeper-main.ts` 的睡眠补偿注释)。
|
|
3618
|
+
*
|
|
3619
|
+
* 现在改成「keeper 活着 **且** 它马上要来」才让路:只有当下一轮 tick 已到最后
|
|
3620
|
+
* 一个心跳周期的窗口里(或者已经过点了),才把续期权交给它。其余时间插件自己刷,
|
|
3621
|
+
* 反正跨进程锁会把两边串起来。
|
|
3622
|
+
*/
|
|
3623
|
+
const shouldDeferToKeeper = () => {
|
|
3624
|
+
const stats = keeperStats();
|
|
3625
|
+
if (!stats.alive) return false;
|
|
3626
|
+
return Date.now() >= keeperNextPassAt(stats.state) - KEEPER_STALE_MS;
|
|
3627
|
+
};
|
|
3595
3628
|
const keepAliveLoop = async () => {
|
|
3596
3629
|
if (stopped) return;
|
|
3597
|
-
if (
|
|
3630
|
+
if (shouldDeferToKeeper()) await store.reloadFromDisk().catch(() => {});
|
|
3598
3631
|
else try {
|
|
3599
3632
|
const outcome = await store.keepAlive();
|
|
3600
3633
|
if (outcome.refreshed > 0) ctx.logger.debug(`dsh-codearts: refreshed ${outcome.refreshed} credential(s) in the background`);
|
|
@@ -3694,12 +3727,13 @@ function apply(ctx, rawConfig) {
|
|
|
3694
3727
|
waitInQueue: () => current().queueWaitUntilReady === true
|
|
3695
3728
|
});
|
|
3696
3729
|
usage.load().catch(() => {});
|
|
3697
|
-
shim.ready.then(async () => {
|
|
3730
|
+
const settled = shim.ready.then(async () => {
|
|
3698
3731
|
if (stopped) return;
|
|
3699
|
-
discoverLoop();
|
|
3700
3732
|
keepAliveLoop();
|
|
3701
3733
|
armAutoClaim();
|
|
3702
3734
|
armKeepAliveDaemon();
|
|
3735
|
+
await discover(AbortSignal.any([abort.signal, AbortSignal.timeout(STARTUP_DISCOVERY_MS)]));
|
|
3736
|
+
if (stopped) return;
|
|
3703
3737
|
const incompatible = await probePiAiCompat();
|
|
3704
3738
|
if (incompatible !== void 0) ctx.logger.error(`dsh-codearts: ${incompatible}`);
|
|
3705
3739
|
const codearts = createCodeArtsAdapter({
|
|
@@ -3734,9 +3768,14 @@ function apply(ctx, rawConfig) {
|
|
|
3734
3768
|
releaseAdapter?.();
|
|
3735
3769
|
releaseDirectory?.();
|
|
3736
3770
|
}
|
|
3771
|
+
if (catalog.current().length === 0) ctx.logger.warn("dsh-codearts: CodeArts provider registered with an empty model catalog; models stay unavailable until discovery succeeds");
|
|
3772
|
+
if (!stopped) scheduleDiscovery(nextDiscoveryDelay());
|
|
3737
3773
|
}).catch((error) => {
|
|
3738
3774
|
ctx.logger.error("dsh-codearts: loopback shim failed to start; provider not registered", error);
|
|
3739
3775
|
});
|
|
3776
|
+
await Promise.race([settled, new Promise((resolve) => {
|
|
3777
|
+
setTimeout(resolve, STARTUP_WAIT_MS).unref?.();
|
|
3778
|
+
})]);
|
|
3740
3779
|
}
|
|
3741
3780
|
//#endregion
|
|
3742
3781
|
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 };
|
|
@@ -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,
|
|
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 };
|
package/lib/keeper-main.mjs
CHANGED
|
@@ -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-
|
|
2
|
-
import { a as clearKeeperState, c as keeperLogPath, d as
|
|
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
|
+
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
|
|
@@ -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`:那个函数按「参数更全/大小写更像注册名」
|
|
@@ -505,6 +533,13 @@ const EP_BENEFIT_CONFIG = "/api/v1/gateway/config";
|
|
|
505
533
|
const EP_AGENT_LIST = "/v1/agent-center/agents/useragents";
|
|
506
534
|
const EP_AGENT_DETAIL = "/v1/agent-center/agents/detail";
|
|
507
535
|
/**
|
|
536
|
+
* 企业租户设置与第三方模型清单(26.11 客户端)。官方客户端先按套餐门禁
|
|
537
|
+
* (`is_credit_package && spec_code 含 enterprise`,或白名单)判断后才请求,
|
|
538
|
+
* 普通账号不会走到。见 `fetchThirdPartyModels`。
|
|
539
|
+
*/
|
|
540
|
+
const EP_TENANT_SETTINGS = "/v1/llm/tenant/settings";
|
|
541
|
+
const EP_THIRD_PARTY_MODELS = "/v1/third-party-model/model/list";
|
|
542
|
+
/**
|
|
508
543
|
* 模型的思考强度清单(26.10.0 新增)。**必须带 `Agent-Type: PromptCenter`**:
|
|
509
544
|
* 不带头时上游回 `TM.00001001 请求头Agent-Type为空`(实测)。
|
|
510
545
|
*/
|
|
@@ -1593,6 +1628,70 @@ async function fetchAgentModels(credential, signal) {
|
|
|
1593
1628
|
}
|
|
1594
1629
|
return out;
|
|
1595
1630
|
}
|
|
1631
|
+
/** 租户是否启用了第三方模型;读不到明确值时返回 undefined(交给调用方决定)。 */
|
|
1632
|
+
function thirdPartyModelsEnabled(value) {
|
|
1633
|
+
const body = asRecord(value);
|
|
1634
|
+
for (const candidate of [
|
|
1635
|
+
body.third_party_model_enabled,
|
|
1636
|
+
asRecord(body.data).third_party_model_enabled,
|
|
1637
|
+
asRecord(body.settings).third_party_model_enabled
|
|
1638
|
+
]) {
|
|
1639
|
+
if (candidate === true) return true;
|
|
1640
|
+
if (candidate === false) return false;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* 企业租户的第三方模型清单:先 `GET /v1/llm/tenant/settings` 拿门禁,再
|
|
1645
|
+
* `GET /v1/third-party-model/model/list`(分页,官方客户端一页取 100 条)。
|
|
1646
|
+
*
|
|
1647
|
+
* 这类模型是企业管理员注册的 MaaS 通道(企业内部专业版的主力),与 agent-center
|
|
1648
|
+
* 的 `gpts.models` 同源但不完全重合:没挂到 CodeAgent 上的模型只在清单里出现。
|
|
1649
|
+
*
|
|
1650
|
+
* 门禁失败或未启用时返回空数组且不记 errors —— 官方客户端对普通账号根本不会
|
|
1651
|
+
* 请求这两条接口,我们照做,免得每个个人账号每轮刷新都多两条噪音。只有租户明确
|
|
1652
|
+
* 启用后清单仍失败,才把失败带回去(那说明企业账号的发现链路真断了)。
|
|
1653
|
+
*
|
|
1654
|
+
* 条目形状以 `model_parameters` 为准,也兼容参数摊平在顶层的写法(官方客户端两处
|
|
1655
|
+
* 都兼容)。输出上限同样可能放在 `output_context_window`(#11)。
|
|
1656
|
+
*/
|
|
1657
|
+
async function fetchThirdPartyModels(credential, signal) {
|
|
1658
|
+
const settingsResp = await signedGet(`${SNAP_HOST}${EP_TENANT_SETTINGS}`, credential, "PromptCenter", signal);
|
|
1659
|
+
if (!settingsResp.ok) return [];
|
|
1660
|
+
const enabled = thirdPartyModelsEnabled(parseJson(settingsResp.text));
|
|
1661
|
+
if (enabled === false) return [];
|
|
1662
|
+
const listResp = await signedGet(`${SNAP_HOST}${EP_THIRD_PARTY_MODELS}?page_num=1&page_size=100`, credential, "PromptCenter", signal);
|
|
1663
|
+
if (!listResp.ok) {
|
|
1664
|
+
if (enabled === true) throw new Error(`third-party model list HTTP ${listResp.status} ${listResp.message}`);
|
|
1665
|
+
return [];
|
|
1666
|
+
}
|
|
1667
|
+
const body = asRecord(parseJson(listResp.text));
|
|
1668
|
+
const error = body.error ?? asRecord(body.data).error;
|
|
1669
|
+
if (error !== void 0) {
|
|
1670
|
+
if (enabled === true) throw new Error(`third-party model list error: ${JSON.stringify(error).slice(0, 200)}`);
|
|
1671
|
+
return [];
|
|
1672
|
+
}
|
|
1673
|
+
const out = [];
|
|
1674
|
+
for (const raw of asArray(body.list ?? asRecord(body.data).list)) {
|
|
1675
|
+
const item = asRecord(raw);
|
|
1676
|
+
const params = asRecord(item.model_parameters);
|
|
1677
|
+
const flat = Object.keys(params).length > 0 ? params : item;
|
|
1678
|
+
if (item.enable === false || item.display_enabled === false) continue;
|
|
1679
|
+
const id = firstString(flat.model_id, item.model_id, item.model_alias, flat.service_name, flat.third_party_model);
|
|
1680
|
+
if (id === "") continue;
|
|
1681
|
+
const ratio = creditRatioOf(item) ?? creditRatioOf(flat);
|
|
1682
|
+
const contextWindow = positive(flat.context_window);
|
|
1683
|
+
out.push({
|
|
1684
|
+
id,
|
|
1685
|
+
name: firstString(item.model_name, item.model_alias, flat.model_name, id),
|
|
1686
|
+
contextWindow,
|
|
1687
|
+
...contextWindow > 0 ? { contextWindowKnown: true } : {},
|
|
1688
|
+
maxTokens: positive(flat.max_tokens) || positive(flat.output_context_window),
|
|
1689
|
+
supportsImages: item.supports_images === true || flat.supports_images === true,
|
|
1690
|
+
...ratio === void 0 ? {} : { ratio }
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
return out;
|
|
1694
|
+
}
|
|
1596
1695
|
/**
|
|
1597
1696
|
* 思考强度清单:`POST /v1/model/thinking-variants`,body `{ model_names }`。
|
|
1598
1697
|
*
|
|
@@ -1716,10 +1815,11 @@ async function clearQueueStatus(credential, chatId, model, signal) {
|
|
|
1716
1815
|
}
|
|
1717
1816
|
}
|
|
1718
1817
|
/**
|
|
1719
|
-
*
|
|
1818
|
+
* 动态发现当前账号可用的模型清单(四路合并)。
|
|
1720
1819
|
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1820
|
+
* 内置、限时福利、agent-center、企业第三方模型四路各自独立,任一路失败只记进
|
|
1821
|
+
* `errors` 不阻断 —— 福利网关抖动时仍能拿到内置模型。第三方模型那一路有门禁:
|
|
1822
|
+
* 租户未启用时返回空且不算来源(见 `fetchThirdPartyModels`)。
|
|
1723
1823
|
*
|
|
1724
1824
|
* 上标的两个「实测 vs 标称」处理(很重要,别照搬标称值):
|
|
1725
1825
|
* - **maxTokens 钳到该模型的实测上限**(`MEASURED_MAX_TOKENS`)。上游
|
|
@@ -1730,7 +1830,7 @@ async function clearQueueStatus(credential, chatId, model, signal) {
|
|
|
1730
1830
|
* 用户配置的按模型覆盖值与进程内学到的真实上界在这里压过发现值(issue #9)。
|
|
1731
1831
|
*
|
|
1732
1832
|
* @param contextWindowOverrides 按模型 id 覆盖 contextWindow(大小写不敏感)
|
|
1733
|
-
* @throws
|
|
1833
|
+
* @throws 所有来源全失败,或合并结果为空。
|
|
1734
1834
|
*/
|
|
1735
1835
|
async function fetchModels(credential, signal, contextWindowOverrides = {}) {
|
|
1736
1836
|
const settled = await Promise.all([
|
|
@@ -1754,6 +1854,13 @@ async function fetchModels(credential, signal, contextWindowOverrides = {}) {
|
|
|
1754
1854
|
}), (error) => ({
|
|
1755
1855
|
source: "agent",
|
|
1756
1856
|
error
|
|
1857
|
+
})),
|
|
1858
|
+
fetchThirdPartyModels(credential, signal).then((models) => ({
|
|
1859
|
+
source: "thirdparty",
|
|
1860
|
+
models
|
|
1861
|
+
}), (error) => ({
|
|
1862
|
+
source: "thirdparty",
|
|
1863
|
+
error
|
|
1757
1864
|
}))
|
|
1758
1865
|
]);
|
|
1759
1866
|
const sources = [];
|
|
@@ -1763,6 +1870,7 @@ async function fetchModels(credential, signal, contextWindowOverrides = {}) {
|
|
|
1763
1870
|
source: item.source,
|
|
1764
1871
|
message: item.error.message
|
|
1765
1872
|
});
|
|
1873
|
+
else if (item.source === "thirdparty" && item.models.length === 0) continue;
|
|
1766
1874
|
else {
|
|
1767
1875
|
sources.push(item.source);
|
|
1768
1876
|
discovered.push(item.models);
|
|
@@ -2016,4 +2124,4 @@ async function claimDailyWelfare(credential, signal) {
|
|
|
2016
2124
|
};
|
|
2017
2125
|
}
|
|
2018
2126
|
//#endregion
|
|
2019
|
-
export { queueFrame as A,
|
|
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-
|
|
2
|
-
import { G as
|
|
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
|
-
|
|
89
|
-
|
|
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.
|
|
539
|
+
const CODEARTS_VERSION = "1.4.7";
|
|
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.
|
|
5
|
+
"version": "1.4.7",
|
|
6
6
|
"packageManager": "pnpm@11.24.0",
|
|
7
7
|
"author": "elegant01",
|
|
8
8
|
"keywords": [
|