dsh-codearts 1.4.1 → 1.4.3
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 +41 -0
- package/lib/{auth-C00dJphV.mjs → auth-Cd2SvQIy.mjs} +1 -1
- package/lib/bin.mjs +3 -3
- package/lib/client/index.d.cts +3 -0
- package/lib/client/index.js +134 -98
- package/lib/index.d.mts +36 -11
- package/lib/index.mjs +196 -52
- package/lib/{keeper-MHeAp_eV.mjs → keeper-DJLwIiR4.mjs} +82 -7
- package/lib/keeper-main.mjs +62 -12
- package/lib/{upstream-D1wYeXC7.mjs → upstream-BV4XWB4l.mjs} +74 -10
- package/lib/{version-DC5JRWls.mjs → version-DqzkoxeU.mjs} +3 -3
- package/package.json +1 -1
package/lib/keeper-main.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { d as OAuthTokenError, f as defaultLoginConfig, i as codeartsAccountsPath, l as readAccountDocument, p as refreshToken, u as writeJsonAtomic } from "./auth-
|
|
2
|
-
import { a as keeperLogPath,
|
|
3
|
-
import { appendFileSync, existsSync, unlinkSync } from "node:fs";
|
|
1
|
+
import { d as OAuthTokenError, f as defaultLoginConfig, i as codeartsAccountsPath, l as readAccountDocument, p as refreshToken, u as writeJsonAtomic } from "./auth-Cd2SvQIy.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-DJLwIiR4.mjs";
|
|
3
|
+
import { appendFileSync, existsSync, unlinkSync, watch } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
4
5
|
//#region src/keeper-main.ts
|
|
5
6
|
/**
|
|
6
7
|
* dsh-codearts 凭证守护进程(独立入口,由 DSH 用 `ELECTRON_RUN_AS_NODE=1` 拉起)。
|
|
@@ -39,17 +40,16 @@ function log(message) {
|
|
|
39
40
|
*
|
|
40
41
|
* 从卡片连点两次、或同时开两个 DSH 窗口时,第二次 spawn 必须让路 —— 两个进程同时
|
|
41
42
|
* 刷 refresh_token 就是上面说的那个翻车场景。
|
|
43
|
+
*
|
|
44
|
+
* 判据用 `keeperStats`(心跳 + pid 都算),不能只看 pid:上一份 keeper 被强杀后
|
|
45
|
+
* 状态文件会留在盘上,而 Windows 很快就把那个 pid 发给别的进程 —— 只探 pid 会
|
|
46
|
+
* 把一个正常的新进程当成「已有 keeper」,于是每次启动都立刻退出(2026-11-16 实测)。
|
|
42
47
|
*/
|
|
43
48
|
function alreadyRunning() {
|
|
44
|
-
const
|
|
45
|
-
if (state === void 0) return void 0;
|
|
46
|
-
if (state.pid === process.pid) return void 0;
|
|
47
|
-
|
|
48
|
-
process.kill(state.pid, 0);
|
|
49
|
-
return state.pid;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
return error?.code === "EPERM" ? state.pid : void 0;
|
|
52
|
-
}
|
|
49
|
+
const stats = keeperStats(home);
|
|
50
|
+
if (!stats.alive || stats.state === void 0) return void 0;
|
|
51
|
+
if (stats.state.pid === process.pid) return void 0;
|
|
52
|
+
return stats.state.pid;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* 一轮续期:读文档 → 逐个续 → 写回。
|
|
@@ -144,6 +144,39 @@ async function tick(state) {
|
|
|
144
144
|
};
|
|
145
145
|
if (refreshed > 0 || needsLogin.length > 0) log(`pass done: checked=${checked} refreshed=${refreshed} needsLogin=${needsLogin.length}`);
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* 更新安装器一出现就通知调用方让路。
|
|
149
|
+
*
|
|
150
|
+
* 为什么需要:安装器启动后会枚举进程判断「应用是否已关闭」,keeper 只要还在跑就
|
|
151
|
+
* 可能被当成应用本身,更新在十秒左右中止、也不把应用拉回来(`keeper.ts` 的
|
|
152
|
+
* `bundledNodeExecutable` 注释里有完整现场)。换 node.exe 是主路,这里是双保险 —
|
|
153
|
+
* 安装器就算按安装路径匹配也挡不住。
|
|
154
|
+
*
|
|
155
|
+
* 实现上用 `fs.watch` 盯 `%TEMP%`(事件驱动,不轮询):只有新出现的 `ns*.tmp`
|
|
156
|
+
* 目录里真有安装器的 `window-frame.dll` 才算数,用户装别的软件不会误伤。
|
|
157
|
+
*/
|
|
158
|
+
function watchForUpdateInstaller(onSeen) {
|
|
159
|
+
if (process.platform !== "win32") return;
|
|
160
|
+
const root = process.env.TEMP ?? process.env.TMP;
|
|
161
|
+
if (root === void 0 || root === "") return;
|
|
162
|
+
const confirm = (name, attempt) => {
|
|
163
|
+
if (!name.toLowerCase().startsWith("ns")) return;
|
|
164
|
+
const dir = join(root, name);
|
|
165
|
+
if (isDshInstallerTempDir(dir)) {
|
|
166
|
+
onSeen();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (attempt < 2) setTimeout(() => confirm(name, attempt + 1), 500);
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
watch(root, (_event, filename) => {
|
|
173
|
+
if (filename === null) return;
|
|
174
|
+
confirm(String(filename), 0);
|
|
175
|
+
});
|
|
176
|
+
} catch (error) {
|
|
177
|
+
log(`installer watch unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
147
180
|
async function main() {
|
|
148
181
|
const other = alreadyRunning();
|
|
149
182
|
if (other !== void 0) {
|
|
@@ -167,6 +200,23 @@ async function main() {
|
|
|
167
200
|
clearKeeperState(home);
|
|
168
201
|
process.exit(0);
|
|
169
202
|
};
|
|
203
|
+
clearKeeperHandoff(home);
|
|
204
|
+
/**
|
|
205
|
+
* 为更新安装让路。
|
|
206
|
+
*
|
|
207
|
+
* 和 `shutdown` 的区别只有一条:留一个「让路」标记。插件看到它会知道这是预期内
|
|
208
|
+
* 的退出,不把「常驻保活」开关关掉 —— 新版应用起来后开关还开着,keeper 会照常被
|
|
209
|
+
* 拉起,用户不会发现自己"被关了保活"。
|
|
210
|
+
*/
|
|
211
|
+
const stepAside = (reason) => {
|
|
212
|
+
if (stopped) return;
|
|
213
|
+
log(`keeper stepping aside: ${reason}`);
|
|
214
|
+
writeKeeperHandoff(reason, home);
|
|
215
|
+
clearKeeperState(home);
|
|
216
|
+
stopped = true;
|
|
217
|
+
process.exit(0);
|
|
218
|
+
};
|
|
219
|
+
watchForUpdateInstaller(() => stepAside("update installer detected"));
|
|
170
220
|
for (const signal of [
|
|
171
221
|
"SIGINT",
|
|
172
222
|
"SIGTERM",
|
|
@@ -334,10 +334,12 @@ function backfillParams(discovered, params = FALLBACK_CODEARTS_MODELS) {
|
|
|
334
334
|
for (const fallback of params) {
|
|
335
335
|
const current = byId.get(fallback.id.toLowerCase());
|
|
336
336
|
if (current === void 0) continue;
|
|
337
|
+
const keptWindow = current.contextWindow > 0;
|
|
337
338
|
byId.set(fallback.id.toLowerCase(), {
|
|
338
339
|
id: current.id,
|
|
339
340
|
name: current.name || fallback.name,
|
|
340
|
-
contextWindow:
|
|
341
|
+
contextWindow: keptWindow ? current.contextWindow : fallback.contextWindow,
|
|
342
|
+
...keptWindow && current.contextWindowKnown === true ? { contextWindowKnown: true } : {},
|
|
341
343
|
maxTokens: current.maxTokens > 0 ? current.maxTokens : fallback.maxTokens,
|
|
342
344
|
supportsImages: current.supportsImages || fallback.supportsImages,
|
|
343
345
|
...current.ratio === void 0 ? {} : { ratio: current.ratio },
|
|
@@ -476,6 +478,8 @@ var upstream_exports = /* @__PURE__ */ __exportAll({
|
|
|
476
478
|
isModelNotAccessible: () => isModelNotAccessible,
|
|
477
479
|
isNotMultimodal: () => isNotMultimodal,
|
|
478
480
|
isParamInvalidFrame: () => isParamInvalidFrame,
|
|
481
|
+
isQueueReject: () => isQueueReject,
|
|
482
|
+
isQueueRejectText: () => isQueueRejectText,
|
|
479
483
|
isQueueableRate: () => isQueueableRate,
|
|
480
484
|
isResignRefusal: () => isResignRefusal,
|
|
481
485
|
isTpmLimit: () => isTpmLimit,
|
|
@@ -486,6 +490,8 @@ var upstream_exports = /* @__PURE__ */ __exportAll({
|
|
|
486
490
|
modelUnavailableReasonText: () => modelUnavailableReasonText,
|
|
487
491
|
pickDailyWelfareCampaign: () => pickDailyWelfareCampaign,
|
|
488
492
|
prepareChatBody: () => prepareChatBody,
|
|
493
|
+
queueFrame: () => queueFrame,
|
|
494
|
+
queueRejectMessage: () => queueRejectMessage,
|
|
489
495
|
rateLimitFrame: () => rateLimitFrame,
|
|
490
496
|
signedGet: () => signedGet,
|
|
491
497
|
upstreamErrorMessage: () => upstreamErrorMessage
|
|
@@ -964,9 +970,56 @@ function isTpmLimit(result) {
|
|
|
964
970
|
if (result.ok) return false;
|
|
965
971
|
return MODEL_RATE_CODE.test(result.message) || MODEL_RATE_TEXT.test(result.message);
|
|
966
972
|
}
|
|
967
|
-
/**
|
|
973
|
+
/** 撞到这几类限流/排队都值得原地等,而不是直接甩给 pi-ai 重试。 */
|
|
968
974
|
function isQueueableRate(result) {
|
|
969
|
-
return isConcurrencyCap(result) || isTpmLimit(result);
|
|
975
|
+
return isConcurrencyCap(result) || isTpmLimit(result) || isQueueReject(result);
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* 上游明确回「排队」拒绝(issue #10):HTTP 400 的 body 形如
|
|
979
|
+
* `{"message":"当前请求量较大,您排在第16位。…","type":"queued","code":"queued"}`。
|
|
980
|
+
*
|
|
981
|
+
* 它不是请求写错了,是让客户端等一会儿再来 —— 本地退避重发就有机会。流内首帧
|
|
982
|
+
* (HTTP 200 + error_code/推送帧)也会被 `queueFrame` 归一成 `queued: <文案>`。
|
|
983
|
+
*/
|
|
984
|
+
function isQueueRejectText(text) {
|
|
985
|
+
return /"code"\s*:\s*"queued"|"type"\s*:\s*"queued"|^\s*queued\s*:/i.test(text);
|
|
986
|
+
}
|
|
987
|
+
function isQueueReject(result) {
|
|
988
|
+
return !result.ok && isQueueRejectText(result.message);
|
|
989
|
+
}
|
|
990
|
+
/** 从排队拒绝里取出给人看的那句(JSON 的 message 字段或 `queued: …` 前缀)。 */
|
|
991
|
+
function queueRejectMessage(text) {
|
|
992
|
+
const prefixed = /^\s*queued\s*:\s*/i.exec(text);
|
|
993
|
+
if (prefixed !== null) return text.slice(prefixed[0].length).trim();
|
|
994
|
+
try {
|
|
995
|
+
const parsed = JSON.parse(text);
|
|
996
|
+
return String(parsed.message ?? parsed.error?.message ?? "").trim();
|
|
997
|
+
} catch {
|
|
998
|
+
return "";
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* 从首帧里认出上游的「排队」拒绝(HTTP 200 + 流内帧的形态)。
|
|
1003
|
+
*
|
|
1004
|
+
* 与 `rateLimitFrame` 同理:只在**还没有任何内容产出**的首帧上使用,此时重发安全。
|
|
1005
|
+
*/
|
|
1006
|
+
function queueFrame(text) {
|
|
1007
|
+
for (const line of text.split("\n")) {
|
|
1008
|
+
const trimmed = line.trim();
|
|
1009
|
+
if (!trimmed.startsWith("data:")) continue;
|
|
1010
|
+
const payload = trimmed.slice(5).trim();
|
|
1011
|
+
if (payload === "" || payload === "[DONE]") continue;
|
|
1012
|
+
let ev;
|
|
1013
|
+
try {
|
|
1014
|
+
ev = JSON.parse(payload);
|
|
1015
|
+
} catch {
|
|
1016
|
+
continue;
|
|
1017
|
+
}
|
|
1018
|
+
const code = String(ev.error?.code ?? ev.error_code ?? ev.code ?? "");
|
|
1019
|
+
const type = String(ev.error?.type ?? ev.type ?? "");
|
|
1020
|
+
if (!/^queued$/i.test(code) && !/^queued$/i.test(type)) continue;
|
|
1021
|
+
return { message: String(ev.error?.message ?? ev.error_msg ?? ev.message ?? "") };
|
|
1022
|
+
}
|
|
970
1023
|
}
|
|
971
1024
|
/**
|
|
972
1025
|
* 从一帧已转成 OpenAI 形状的 SSE 里认出「可排队限流」。
|
|
@@ -1012,6 +1065,10 @@ function upstreamErrorMessage(message, status = 0) {
|
|
|
1012
1065
|
if (MODEL_RATE_CODE.test(message) || MODEL_RATE_TEXT.test(message)) return "华为侧该模型当前请求过多(共享 TPM 超限),不是你的账号或插件问题。稍后重试,或临时改用 GLM-5.2 / GLM-5.3。";
|
|
1013
1066
|
if (message.includes("TM.00001041")) return "CodeArts 免费档同时只允许 3 个会话,当前槽位一直占满(被打断的会话约 1 分钟才释放)。请稍后重试。";
|
|
1014
1067
|
if (isBenefitMissing("", message)) return "这个模型属于限时福利,当前福利通道不可用(不是账号问题)。可以刷新模型列表,改用非福利模型。";
|
|
1068
|
+
if (isQueueRejectText(message)) {
|
|
1069
|
+
const inner = queueRejectMessage(message);
|
|
1070
|
+
return `${inner === "" ? "上游提示请求量较大、需要排队。" : inner} 插件已在本地排队重试,仍未轮到,请稍后重试或临时切换模型。`;
|
|
1071
|
+
}
|
|
1015
1072
|
if (isIamTokenError(message)) return "上游判定本次登录凭据(IAM token)已失效。插件已尝试自动续期;若反复出现,请到设置卡片重新登录。";
|
|
1016
1073
|
if (isModelNotAccessible(message)) return "上游说这个模型不存在或当前账号没有权限(可能已下线或改名)。请刷新模型列表后换一个模型;换号没有用,这是模型级的限制。";
|
|
1017
1074
|
if (isNotMultimodal(message)) return "这个模型不支持图片输入(上游 406)。请移除消息里的图片,或改用支持识图的模型。";
|
|
@@ -1444,10 +1501,12 @@ async function fetchBuiltinModels(credential, signal) {
|
|
|
1444
1501
|
const id = firstString(model.model_id, model.model_name);
|
|
1445
1502
|
if (id === "") continue;
|
|
1446
1503
|
const ratio = creditRatioOf(model);
|
|
1504
|
+
const contextWindow = positive(model.context_window);
|
|
1447
1505
|
out.push({
|
|
1448
1506
|
id,
|
|
1449
1507
|
name: firstString(model.model_name, id),
|
|
1450
|
-
contextWindow
|
|
1508
|
+
contextWindow,
|
|
1509
|
+
...contextWindow > 0 ? { contextWindowKnown: true } : {},
|
|
1451
1510
|
maxTokens: positive(model.max_tokens),
|
|
1452
1511
|
supportsImages: model.supports_images === true,
|
|
1453
1512
|
...ratio === void 0 ? {} : { ratio }
|
|
@@ -1472,10 +1531,12 @@ async function fetchBenefitModels(credential, signal) {
|
|
|
1472
1531
|
const id = firstString(model.model_id, model.model_name);
|
|
1473
1532
|
if (id === "") continue;
|
|
1474
1533
|
const ratio = creditRatioOf(model);
|
|
1534
|
+
const contextWindow = positive(model.context_window);
|
|
1475
1535
|
out.push({
|
|
1476
1536
|
id,
|
|
1477
1537
|
name: firstString(model.model_name, id),
|
|
1478
|
-
contextWindow
|
|
1538
|
+
contextWindow,
|
|
1539
|
+
...contextWindow > 0 ? { contextWindowKnown: true } : {},
|
|
1479
1540
|
maxTokens: positive(model.max_tokens),
|
|
1480
1541
|
supportsImages: model.supports_images === true,
|
|
1481
1542
|
...ratio === void 0 ? {} : { ratio },
|
|
@@ -1519,10 +1580,12 @@ async function fetchAgentModels(credential, signal) {
|
|
|
1519
1580
|
const id = firstString(params.model_id, model.model_id, model.model_alias, model.model_name);
|
|
1520
1581
|
if (id === "") continue;
|
|
1521
1582
|
const ratio = creditRatioOf(model) ?? creditRatioOf(params);
|
|
1583
|
+
const contextWindow = positive(params.context_window);
|
|
1522
1584
|
out.push({
|
|
1523
1585
|
id,
|
|
1524
1586
|
name: firstString(model.model_name, model.model_alias, id),
|
|
1525
|
-
contextWindow
|
|
1587
|
+
contextWindow,
|
|
1588
|
+
...contextWindow > 0 ? { contextWindowKnown: true } : {},
|
|
1526
1589
|
maxTokens: positive(params.max_tokens),
|
|
1527
1590
|
supportsImages: model.supports_images === true,
|
|
1528
1591
|
...ratio === void 0 ? {} : { ratio }
|
|
@@ -1721,15 +1784,16 @@ async function fetchModels(credential, signal, contextWindowOverrides = {}) {
|
|
|
1721
1784
|
const thinking = variants.get(model.id.toLowerCase());
|
|
1722
1785
|
const override = contextWindowOverrideFor(contextWindowOverrides, model.id);
|
|
1723
1786
|
const learned = learnedContextWindowFor(model.id);
|
|
1724
|
-
const
|
|
1787
|
+
const upstreamKnown = model.contextWindowKnown === true;
|
|
1788
|
+
const discovered = model.contextWindow > 0 ? model.contextWindow : learned ?? UNKNOWN_CONTEXT_WINDOW;
|
|
1725
1789
|
const base = override ?? discovered;
|
|
1726
1790
|
const contextWindow = learned === void 0 ? base : Math.min(base, learned);
|
|
1727
1791
|
return {
|
|
1728
1792
|
...model,
|
|
1729
1793
|
...thinking === void 0 ? {} : { thinking },
|
|
1730
|
-
|
|
1794
|
+
...override !== void 0 || learned !== void 0 || upstreamKnown ? { contextWindowKnown: true } : {},
|
|
1731
1795
|
contextWindow,
|
|
1732
|
-
...contextWindow
|
|
1796
|
+
...upstreamKnown && contextWindow !== model.contextWindow ? { contextWindowDiscovered: model.contextWindow } : {},
|
|
1733
1797
|
maxTokens: Math.min(model.maxTokens > 0 ? model.maxTokens : UNKNOWN_MAX_TOKENS, maxTokensCeilingFor(model.id))
|
|
1734
1798
|
};
|
|
1735
1799
|
}),
|
|
@@ -1952,4 +2016,4 @@ async function claimDailyWelfare(credential, signal) {
|
|
|
1952
2016
|
};
|
|
1953
2017
|
}
|
|
1954
2018
|
//#endregion
|
|
1955
|
-
export {
|
|
2019
|
+
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as writeJsonAtomic } from "./auth-
|
|
2
|
-
import {
|
|
1
|
+
import { u as writeJsonAtomic } from "./auth-Cd2SvQIy.mjs";
|
|
2
|
+
import { G as modelDisplayName, H as isBenefitModel, W as mergeModelLists, q as setDiscoveredBenefitModels, u as fetchModels } from "./upstream-BV4XWB4l.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.
|
|
538
|
+
const CODEARTS_VERSION = "1.4.3";
|
|
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
|
+
"version": "1.4.3",
|
|
6
6
|
"packageManager": "pnpm@11.24.0",
|
|
7
7
|
"author": "elegant01",
|
|
8
8
|
"keywords": [
|