dsh-commandcode-quota 0.2.1 → 0.2.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/package.json +2 -2
- package/src/index.js +22 -2
- package/test/host.test.cjs +14 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-commandcode-quota",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Command Code balance and quota panel for DeepSeek Harness: a status row under the composer showing balance and the 5-hour, weekly and monthly windows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@deepseek-ai/dsh-credentials": "
|
|
54
|
+
"@deepseek-ai/dsh-credentials": ">=0.1.0-0 <0.2.0-0 || >=0.2.0-0 <0.3.0-0 || >=0.3.0-0 <0.4.0-0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"@deepseek-ai/dsh-credentials": {
|
package/src/index.js
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
*
|
|
25
25
|
* ESM module format (cordis bundle rule): named exports apply/inject/name.
|
|
26
26
|
*/
|
|
27
|
-
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
28
27
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
29
28
|
import { homedir } from "node:os";
|
|
30
29
|
import { dirname, join } from "node:path";
|
|
@@ -72,7 +71,7 @@ async function ccFetch(baseURL, path, apiKey, timeoutMs) {
|
|
|
72
71
|
headers: {
|
|
73
72
|
authorization: `Bearer ${apiKey}`,
|
|
74
73
|
accept: "application/json",
|
|
75
|
-
"user-agent": "dsh-commandcode-quota/0.2.
|
|
74
|
+
"user-agent": "dsh-commandcode-quota/0.2.3"
|
|
76
75
|
},
|
|
77
76
|
signal: controller.signal
|
|
78
77
|
});
|
|
@@ -265,6 +264,27 @@ async function resolveAccountOptions(ctx, account) {
|
|
|
265
264
|
/** 合法凭据条目名:POSIX shell 标识符,与 dsh-credentials 的 REF_PATTERN 一致。 */
|
|
266
265
|
const REF_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
267
266
|
|
|
267
|
+
/**
|
|
268
|
+
* 把环境变量名校验成凭据引用(等价于 @deepseek-ai/dsh-credentials 的 credentialRef)。
|
|
269
|
+
*
|
|
270
|
+
* 为什么本地实现而不 import 那个包:那是【运行时导入】,而插件的真实路径未必在
|
|
271
|
+
* profile 的 node_modules 里面(本地 junction 安装就是这种情况)。此时
|
|
272
|
+
* "@deepseek-ai/dsh-credentials" 只能靠 profiles/node_modules 下的链接解析,
|
|
273
|
+
* 而 DSH 升级会清空那里的 @deepseek-ai —— 导入立刻抛 ERR_MODULE_NOT_FOUND,
|
|
274
|
+
* 整个宿主端(连带界面面板)都不会上线;市场里的普通用户同样会踩到。
|
|
275
|
+
* 校验规则只有一行正则,本地实现即可让插件零 harness 运行时依赖。
|
|
276
|
+
*
|
|
277
|
+
* @param {unknown} value 候选引用,如 BAILIAN_API_KEY。
|
|
278
|
+
* @returns {string} 通过校验的引用本身。
|
|
279
|
+
* @throws {TypeError} 名字不符合 shell 标识符语法时。
|
|
280
|
+
*/
|
|
281
|
+
function credentialRef(value) {
|
|
282
|
+
if (typeof value !== "string" || !REF_PATTERN.test(value)) {
|
|
283
|
+
throw new TypeError(`credential ref "${String(value)}" must match ${String(REF_PATTERN)}`);
|
|
284
|
+
}
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
|
|
268
288
|
function dshHome() {
|
|
269
289
|
const fromEnv = process.env.DSH_HOME;
|
|
270
290
|
return typeof fromEnv === "string" && fromEnv.length > 0 ? fromEnv : join(homedir(), ".dsh");
|
package/test/host.test.cjs
CHANGED
|
@@ -38,7 +38,6 @@ function load() {
|
|
|
38
38
|
join, dirname,
|
|
39
39
|
homedir: () => fakeHome,
|
|
40
40
|
process: { env: { DSH_HOME: fakeHome } },
|
|
41
|
-
credentialRef: (ref) => ref,
|
|
42
41
|
fetch: async (url, options) => { requests.push({ url, options }); return reply(url, options); },
|
|
43
42
|
});
|
|
44
43
|
vm.runInContext(source.replace(/^import .*;\r?$/gm, "").replace(/^export .*;\r?$/gm, "") +
|
|
@@ -252,6 +251,20 @@ async function main() {
|
|
|
252
251
|
// 发版时最容易漏的一处:user-agent 里的版本号要与 package.json 同步。
|
|
253
252
|
const uaVersion = source.match(/"user-agent":\s*"[^"]*\/([^"]+)"/)?.[1];
|
|
254
253
|
assert.equal(uaVersion, manifest.version, "user-agent 版本必须与 package.json 的 version 一致");
|
|
254
|
+
// 官方包的 peer 范围必须带显式预发布分支。node-semver 只让「相同 major.minor.patch
|
|
255
|
+
// 元组、且自身带预发布标签」的比较符放行预发布版本,所以 '*' 和 '>=0.0.0-0' 都匹配
|
|
256
|
+
// 不到任何 0.x.0-rc.y —— 而那正是 harness 官方包的版本形态。
|
|
257
|
+
const peerRange = manifest.peerDependencies["@deepseek-ai/dsh-credentials"];
|
|
258
|
+
assert.ok(
|
|
259
|
+
typeof peerRange === "string" && /-0/.test(peerRange),
|
|
260
|
+
`官方包 peer 范围必须含显式预发布分支(当前: ${peerRange})`,
|
|
261
|
+
);
|
|
262
|
+
// 宿主端不得再有 @deepseek-ai 的【运行时导入】:插件真实路径可能在 profile 之外,
|
|
263
|
+
// 该包只能靠 profiles/node_modules 下的链接解析,而 DSH 升级会清掉那些链接,
|
|
264
|
+
// 导入即抛 ERR_MODULE_NOT_FOUND,整个插件(含界面)都不上线(2026-10-17 真挂过一次)。
|
|
265
|
+
// peer 声明只用于兼容性判定(读 package.json),不参与运行时解析,因此保留。
|
|
266
|
+
const runtimeHarnessImports = source.match(/^import[^\n]*from\s+"@deepseek-ai\/[^"]+";?$/gm) ?? [];
|
|
267
|
+
assert.deepEqual(runtimeHarnessImports, [], "宿主端不得 import harness 包(会在 profile 之外解析失败)");
|
|
255
268
|
console.log("通过:单账号响应、主/回退凭据、完整/快速查询、缓存、401、405、重试和超时。");
|
|
256
269
|
console.log("通过:凭据端点只回条目名、翻译供应商名、保存后覆盖 patch 配置、非法名被拒、无 key 时依然可用。");
|
|
257
270
|
console.log("通过:宿主端导出、路由、包名与 bundle 补丁层一致。");
|