@kenz1117/dsh-ui-usage-billing 1.6.3 → 1.6.4
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/lib/index.js +70 -18
- package/lib/types/config.d.ts +21 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/routes/usage-tool.d.ts +2 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1311,6 +1311,18 @@ const BUILTIN_MODEL_CATALOG = [
|
|
|
1311
1311
|
output: 16.8
|
|
1312
1312
|
}
|
|
1313
1313
|
},
|
|
1314
|
+
{
|
|
1315
|
+
key: "minimax-m3.1-flash",
|
|
1316
|
+
name: "MiniMax-M3.1-Flash",
|
|
1317
|
+
provider: "MiniMax",
|
|
1318
|
+
colorVar: "ds-amber",
|
|
1319
|
+
price: {
|
|
1320
|
+
currency: "CNY",
|
|
1321
|
+
input: 1,
|
|
1322
|
+
cacheHit: .1,
|
|
1323
|
+
output: 4
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1314
1326
|
{
|
|
1315
1327
|
key: "minimax-m3.1-flash-preview",
|
|
1316
1328
|
name: "MiniMax M3.1 Flash Preview",
|
|
@@ -2423,6 +2435,8 @@ const BUILTIN_MODEL_KEY_ALIASES = {
|
|
|
2423
2435
|
"minimax-m2-7": "minimax-m2.7",
|
|
2424
2436
|
"minimax-m2-7-highspeed": "minimax-m2.7-highspeed",
|
|
2425
2437
|
"minimax-m2-7-high-speed": "minimax-m2.7-highspeed",
|
|
2438
|
+
"minimax-m3.1-flash": "minimax-m3.1-flash",
|
|
2439
|
+
"minimax-m3-1-flash": "minimax-m3.1-flash",
|
|
2426
2440
|
"minimax-m3.1-flash-preview": "minimax-m3.1-flash-preview",
|
|
2427
2441
|
"minimax-m3-1-flash-preview": "minimax-m3.1-flash-preview",
|
|
2428
2442
|
"u2-flash": "u2-flash",
|
|
@@ -7290,6 +7304,8 @@ function registerBalanceRoute(ctx, deps) {
|
|
|
7290
7304
|
*
|
|
7291
7305
|
* usage_stats 工具开关:插件自带的读/写接口(不依赖宿主浏览器设置白名单)。
|
|
7292
7306
|
* GET 返回当前是否注入;POST 写设置命名空间(重启应用后工具注入随新值生效)。
|
|
7307
|
+
* 写回失败回 503 + 宿主错误文案(issue #98:此前 200 + 笼统 invalid,开关无声
|
|
7308
|
+
* 弹回且无任何诊断线索);body 非 JSON 回 400。
|
|
7293
7309
|
*
|
|
7294
7310
|
* 双世代宿主(issue #19 + #28 + v1.4.19)的接线在装配器里完成:
|
|
7295
7311
|
* - 旧宿主 ≤0.1.6 走 `settings.register` 命名空间 scope。
|
|
@@ -7322,32 +7338,43 @@ function registerUsageToolRoute(ctx, deps) {
|
|
|
7322
7338
|
return;
|
|
7323
7339
|
}
|
|
7324
7340
|
}
|
|
7325
|
-
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
7326
7341
|
if (req.method === "GET") {
|
|
7342
|
+
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
7327
7343
|
res.end(JSON.stringify({ enabled: deps.read() }));
|
|
7328
7344
|
return;
|
|
7329
7345
|
}
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
return;
|
|
7338
|
-
}
|
|
7346
|
+
let body = "";
|
|
7347
|
+
for await (const chunk of req) {
|
|
7348
|
+
body += String(chunk);
|
|
7349
|
+
if (body.length > 512) {
|
|
7350
|
+
res.writeHead(413, { "content-type": "application/json; charset=utf-8" });
|
|
7351
|
+
res.end(JSON.stringify({ error: "body too large" }));
|
|
7352
|
+
return;
|
|
7339
7353
|
}
|
|
7340
|
-
|
|
7354
|
+
}
|
|
7355
|
+
let next;
|
|
7356
|
+
try {
|
|
7357
|
+
next = JSON.parse(body === "" ? "{}" : body).enabled === true;
|
|
7358
|
+
} catch {
|
|
7359
|
+
res.writeHead(400, { "content-type": "application/json; charset=utf-8" });
|
|
7360
|
+
res.end(JSON.stringify({ error: "invalid json body" }));
|
|
7361
|
+
return;
|
|
7362
|
+
}
|
|
7363
|
+
try {
|
|
7341
7364
|
await deps.write(next);
|
|
7342
|
-
deps.syncTool();
|
|
7343
|
-
res.end(JSON.stringify({
|
|
7344
|
-
ok: true,
|
|
7345
|
-
enabled: next
|
|
7346
|
-
}));
|
|
7347
7365
|
} catch (error) {
|
|
7366
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
7348
7367
|
console.warn("[usage-billing] usage-tool toggle write-back failed:", error);
|
|
7349
|
-
res.
|
|
7368
|
+
res.writeHead(503, { "content-type": "application/json; charset=utf-8" });
|
|
7369
|
+
res.end(JSON.stringify({ error: `write failed: ${detail}` }));
|
|
7370
|
+
return;
|
|
7350
7371
|
}
|
|
7372
|
+
deps.syncTool();
|
|
7373
|
+
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
7374
|
+
res.end(JSON.stringify({
|
|
7375
|
+
ok: true,
|
|
7376
|
+
enabled: next
|
|
7377
|
+
}));
|
|
7351
7378
|
}
|
|
7352
7379
|
}), "usage-billing: usage-tool route");
|
|
7353
7380
|
}
|
|
@@ -7583,6 +7610,31 @@ const BILLING_SETTINGS_NAMESPACE = "ui-usage-billing";
|
|
|
7583
7610
|
/** 该命名空间下用户可编辑的字段名。 */
|
|
7584
7611
|
const ENABLE_USAGE_STATS_TOOL_FIELD = "enableUsageStatsTool";
|
|
7585
7612
|
//#endregion
|
|
7613
|
+
//#region lib/types/config.js
|
|
7614
|
+
/**
|
|
7615
|
+
* Plugin configuration(v1.5.2 抽出):UsageBillingConfig 原本声明在 src/index.ts
|
|
7616
|
+
* 顶部,src/index.ts 收缩为装配器后被 src/routes/usage-stats.ts 等路由文件
|
|
7617
|
+
* 引用(作为 Deps 类型签名),把它单独放这里让 route 文件能从 src/ 根 import。
|
|
7618
|
+
* 仍由 src/index.ts 的 apply(ctx, config) 消费:路由层只通过 Deps 拿到它,
|
|
7619
|
+
* 不直接构造。
|
|
7620
|
+
*
|
|
7621
|
+
* ⚠️ Config 运行时 schema 必须经 src/index.ts re-export(issue #98):宿主
|
|
7622
|
+
* dsh-settings@0.2.1-rc.2 的 settings.update 写回要求本插件条目在 loader fiber
|
|
7623
|
+
* 上有 `Config` schema(`entry.fiber.runtime.Config` 且带 toJSON),缺失时抛
|
|
7624
|
+
* `No configurable plugin entry`——v1.6.0 拆分时把 schema 退化成纯类型,「注入
|
|
7625
|
+
* 用量查询」开关随之失效(#80 方案的回归)。schemastery 非 strict object 会
|
|
7626
|
+
* merge 未声明键,其余 config 字段(statsPath / routeAliases 等)不受影响。
|
|
7627
|
+
*/
|
|
7628
|
+
/**
|
|
7629
|
+
* 宿主侧条目 config schema(#80 / #98):宿主 0.1.7+ 的设置系统据此把
|
|
7630
|
+
* `enableUsageStatsTool` 投影为 volatile 引用(设置写入即时反映 + 写回走
|
|
7631
|
+
* settings.update)。**必须**经 src/index.ts re-export 给 loader——宿主从插件
|
|
7632
|
+
* 运行时模块的 `Config` 导出发现它;只声明类型等于没有。schemastery 非 strict
|
|
7633
|
+
* object 透传未声明键,其余 config 字段不受影响;未导出 Config 的旧宿主直接
|
|
7634
|
+
* 把原始 config 交给 apply,普通布尔形态由读取端兼容。
|
|
7635
|
+
*/
|
|
7636
|
+
const Config = z.object({ [ENABLE_USAGE_STATS_TOOL_FIELD]: z.boolean().default(false).volatile() });
|
|
7637
|
+
//#endregion
|
|
7586
7638
|
//#region lib/types/index.js
|
|
7587
7639
|
/**
|
|
7588
7640
|
* Usage billing surface plugin, node half.
|
|
@@ -8477,4 +8529,4 @@ function apply(ctx, config = {}) {
|
|
|
8477
8529
|
});
|
|
8478
8530
|
}
|
|
8479
8531
|
//#endregion
|
|
8480
|
-
export { adaptSessionPersistence, apply, createFileUsageLedgerStore, guardLoopback, hostNameOf, inject, isLoopbackHost, isLoopbackOrigin, isLoopbackPeer, normalizeTrustedHosts, readPiAiProviderRoutes, readRegisteredProviderIds, resolveSubscriptionKeys };
|
|
8532
|
+
export { Config, adaptSessionPersistence, apply, createFileUsageLedgerStore, guardLoopback, hostNameOf, inject, isLoopbackHost, isLoopbackOrigin, isLoopbackPeer, normalizeTrustedHosts, readPiAiProviderRoutes, readRegisteredProviderIds, resolveSubscriptionKeys };
|
package/lib/types/config.d.ts
CHANGED
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
* 引用(作为 Deps 类型签名),把它单独放这里让 route 文件能从 src/ 根 import。
|
|
5
5
|
* 仍由 src/index.ts 的 apply(ctx, config) 消费:路由层只通过 Deps 拿到它,
|
|
6
6
|
* 不直接构造。
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ Config 运行时 schema 必须经 src/index.ts re-export(issue #98):宿主
|
|
9
|
+
* dsh-settings@0.2.1-rc.2 的 settings.update 写回要求本插件条目在 loader fiber
|
|
10
|
+
* 上有 `Config` schema(`entry.fiber.runtime.Config` 且带 toJSON),缺失时抛
|
|
11
|
+
* `No configurable plugin entry`——v1.6.0 拆分时把 schema 退化成纯类型,「注入
|
|
12
|
+
* 用量查询」开关随之失效(#80 方案的回归)。schemastery 非 strict object 会
|
|
13
|
+
* merge 未声明键,其余 config 字段(statsPath / routeAliases 等)不受影响。
|
|
7
14
|
*/
|
|
15
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
16
|
import type { CustomBalanceConfig, DeclaredEndpointConfig, SubscriptionPlanConfig } from './pricing-shared.ts';
|
|
9
17
|
/** 宿主 0.1.7+ 经 Config schema 解析后,volatile 字段在 config 中的稳定引用形态
|
|
10
18
|
* (cosmokit `Volatile<T>` 的最小结构镜像,避免为类型引入直接依赖)。 */
|
|
@@ -12,6 +20,19 @@ export interface VolatileToggle {
|
|
|
12
20
|
/** @returns 当前生效的布尔快照(设置写入后原位更新,无需重载插件)。 */
|
|
13
21
|
get(): boolean;
|
|
14
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 宿主侧条目 config schema(#80 / #98):宿主 0.1.7+ 的设置系统据此把
|
|
25
|
+
* `enableUsageStatsTool` 投影为 volatile 引用(设置写入即时反映 + 写回走
|
|
26
|
+
* settings.update)。**必须**经 src/index.ts re-export 给 loader——宿主从插件
|
|
27
|
+
* 运行时模块的 `Config` 导出发现它;只声明类型等于没有。schemastery 非 strict
|
|
28
|
+
* object 透传未声明键,其余 config 字段不受影响;未导出 Config 的旧宿主直接
|
|
29
|
+
* 把原始 config 交给 apply,普通布尔形态由读取端兼容。
|
|
30
|
+
*/
|
|
31
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
32
|
+
enableUsageStatsTool: z<boolean, boolean, "volatile-defined">;
|
|
33
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
34
|
+
enableUsageStatsTool: z<boolean, boolean, "volatile-defined">;
|
|
35
|
+
}>>, "plain">;
|
|
15
36
|
/** Plugin configuration. */
|
|
16
37
|
export interface UsageBillingConfig {
|
|
17
38
|
/** Absolute path to a `.dsh-usage-stats.json` fallback file. */
|
package/lib/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ interface SettingsReader {
|
|
|
28
28
|
}[];
|
|
29
29
|
}
|
|
30
30
|
export type { UsageBillingConfig } from './config.ts';
|
|
31
|
+
export { Config } from './config.ts';
|
|
31
32
|
/**
|
|
32
33
|
* Create the atomic file-backed durable-ledger store. The previous complete file
|
|
33
34
|
* is retained as `.bak`; a malformed/missing main file falls back to that backup.
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* usage_stats 工具开关:插件自带的读/写接口(不依赖宿主浏览器设置白名单)。
|
|
5
5
|
* GET 返回当前是否注入;POST 写设置命名空间(重启应用后工具注入随新值生效)。
|
|
6
|
+
* 写回失败回 503 + 宿主错误文案(issue #98:此前 200 + 笼统 invalid,开关无声
|
|
7
|
+
* 弹回且无任何诊断线索);body 非 JSON 回 400。
|
|
6
8
|
*
|
|
7
9
|
* 双世代宿主(issue #19 + #28 + v1.4.19)的接线在装配器里完成:
|
|
8
10
|
* - 旧宿主 ≤0.1.6 走 `settings.register` 命名空间 scope。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.4",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|