@kenz1117/dsh-ui-usage-billing 1.0.23 → 1.0.25
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/client.js +2 -2
- package/lib/index.js +16 -11
- package/package.json +34 -19
package/lib/index.js
CHANGED
|
@@ -267,7 +267,7 @@ function tierAt(timeMs) {
|
|
|
267
267
|
}
|
|
268
268
|
/** 时刻是否落在北京时间周末(周六/周日)。 */
|
|
269
269
|
function isBeijingWeekend(timeMs) {
|
|
270
|
-
const day = new Date(timeMs +
|
|
270
|
+
const day = new Date(timeMs + 288e5).getUTCDay();
|
|
271
271
|
return day === 0 || day === 6;
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
@@ -3104,7 +3104,11 @@ function tc3Authorization(secretId, secretKey, payload, timestamp) {
|
|
|
3104
3104
|
const canonicalRequest = `POST\n/\n\n${`content-type:application/json; charset=utf-8\nhost:${TOKENHUB_HOST}\n`}\ncontent-type;host\n${createHash("sha256").update(payload).digest("hex")}`;
|
|
3105
3105
|
const hashedCanonical = createHash("sha256").update(canonicalRequest).digest("hex");
|
|
3106
3106
|
const stringToSign = `TC3-HMAC-SHA256\n${String(timestamp)}\n${date}/${TOKENHUB_SERVICE}/tc3_request\n${hashedCanonical}`;
|
|
3107
|
-
|
|
3107
|
+
const kDate = createHmac("sha256", date).update(secretKey).digest();
|
|
3108
|
+
const kService = createHmac("sha256", kDate).update(TOKENHUB_SERVICE).digest();
|
|
3109
|
+
const kSigning = createHmac("sha256", kService).update("tc3_request").digest();
|
|
3110
|
+
const signature = createHmac("sha256", kSigning).update(stringToSign).digest("hex");
|
|
3111
|
+
return `TC3-HMAC-SHA256 Credential=${secretId}/${date}/${TOKENHUB_SERVICE}/tc3_request, SignedHeaders=content-type;host, Signature=${signature}`;
|
|
3108
3112
|
}
|
|
3109
3113
|
/** 调用一次 TokenHub 管控面接口:TC3 签名 + 超时保护,返回响应 JSON 的 `Response`。 */
|
|
3110
3114
|
async function callTokenHub(secretId, secretKey, action, params) {
|
|
@@ -3449,7 +3453,7 @@ const declaredGate = createCooldownGate({
|
|
|
3449
3453
|
cooldownMs: 6e4
|
|
3450
3454
|
});
|
|
3451
3455
|
/** 会触及原型链的路径段:一律拒绝(读结果不是文档自带字段)。 */
|
|
3452
|
-
const FORBIDDEN_SEGMENTS = new Set([
|
|
3456
|
+
const FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set([
|
|
3453
3457
|
"__proto__",
|
|
3454
3458
|
"constructor",
|
|
3455
3459
|
"prototype"
|
|
@@ -3999,7 +4003,7 @@ function asPrice(value) {
|
|
|
3999
4003
|
*/
|
|
4000
4004
|
function buildExtraModels(data) {
|
|
4001
4005
|
if (data === null || typeof data !== "object") return [];
|
|
4002
|
-
const catalogKeys = new Set([...MODEL_CATALOG.map((entry) => entry.key.toLowerCase()), ...Object.keys(MODEL_KEY_ALIASES).map((key) => MODEL_KEY_ALIASES[key]?.toLowerCase() ?? key.toLowerCase())]);
|
|
4006
|
+
const catalogKeys = /* @__PURE__ */ new Set([...MODEL_CATALOG.map((entry) => entry.key.toLowerCase()), ...Object.keys(MODEL_KEY_ALIASES).map((key) => MODEL_KEY_ALIASES[key]?.toLowerCase() ?? key.toLowerCase())]);
|
|
4003
4007
|
const extras = [];
|
|
4004
4008
|
for (const [providerId, providerDoc] of Object.entries(data)) {
|
|
4005
4009
|
if (providerDoc === null || typeof providerDoc !== "object") continue;
|
|
@@ -4673,7 +4677,7 @@ const relayGate = createCooldownGate({
|
|
|
4673
4677
|
/** Abort a relay fetch when the upstream hangs beyond this budget. */
|
|
4674
4678
|
const FETCH_TIMEOUT_MS = 8e3;
|
|
4675
4679
|
/** 指纹识别缓存 TTL(毫秒):识别结果低频变化,5 分钟内同 origin 不再重复探测。 */
|
|
4676
|
-
const FINGERPRINT_TTL_MS =
|
|
4680
|
+
const FINGERPRINT_TTL_MS = 3e5;
|
|
4677
4681
|
/** 每 origin 的识别结果缓存:`kind` 是识别出的中转站程序,`at` 是探测时刻。 */
|
|
4678
4682
|
const fingerprintCache = /* @__PURE__ */ new Map();
|
|
4679
4683
|
/** Number, or null when the value is not a finite number (nor numeric string). */
|
|
@@ -4809,7 +4813,7 @@ function originOf(baseURL) {
|
|
|
4809
4813
|
* 子路径只会得到 404/非中转站格式,因而面板应排除它们,避免误判为
|
|
4810
4814
|
* 「未识别」。中转站面板只列真正的第三方中转程序。
|
|
4811
4815
|
*/
|
|
4812
|
-
const OFFICIAL_HOSTS = new Set([
|
|
4816
|
+
const OFFICIAL_HOSTS = /* @__PURE__ */ new Set([
|
|
4813
4817
|
"api.deepseek.com",
|
|
4814
4818
|
"api.openai.com",
|
|
4815
4819
|
"open.bigmodel.cn",
|
|
@@ -5059,10 +5063,10 @@ const usageBillingSettingsNs = validateSettingsNamespace(BILLING_SETTINGS_NAMESP
|
|
|
5059
5063
|
/** 该命名空间的 wire schema:`enableUsageStatsTool` 布尔,默认关闭(issue 诉求)。 */
|
|
5060
5064
|
const UsageBillingSettingsSchema = z.object({ [ENABLE_USAGE_STATS_TOOL_FIELD]: z.boolean().default(false) });
|
|
5061
5065
|
/** 实时定价的后台刷新间隔(毫秒):汇率/模型价低频变化,6 小时一次足够。 */
|
|
5062
|
-
const PRICING_REFRESH_INTERVAL_MS =
|
|
5066
|
+
const PRICING_REFRESH_INTERVAL_MS = 216e5;
|
|
5063
5067
|
/** 订阅套餐额度缓存时长(毫秒):上游配额 API 低频变化,5 分钟足够。 */
|
|
5064
|
-
const SUBSCRIPTION_CACHE_MS =
|
|
5065
|
-
const BALANCE_CACHE_MS =
|
|
5068
|
+
const SUBSCRIPTION_CACHE_MS = 3e5;
|
|
5069
|
+
const BALANCE_CACHE_MS = 3e5;
|
|
5066
5070
|
/** DeepSeek 余额查询的默认凭据引用(与 llm-deepseek 的默认引用一致)。 */
|
|
5067
5071
|
const DEFAULT_BALANCE_API_KEY_ENV = "DEEPSEEK_API_KEY";
|
|
5068
5072
|
/**
|
|
@@ -5073,7 +5077,7 @@ const PACKAGE_VERSION = createRequire(import.meta.url)("../package.json").versio
|
|
|
5073
5077
|
/** 统计快照的落盘节流(毫秒):前端 30 秒轮询,快照最多每 30 秒写一次。 */
|
|
5074
5078
|
const SNAPSHOT_INTERVAL_MS = 3e4;
|
|
5075
5079
|
/** 鉴权失败告警冷却(毫秒):同一 provider 在窗口内只提示一次,避免 30 秒轮询刷屏。 */
|
|
5076
|
-
const AUTH_WARN_COOLDOWN_MS =
|
|
5080
|
+
const AUTH_WARN_COOLDOWN_MS = 18e5;
|
|
5077
5081
|
/**
|
|
5078
5082
|
* 鉴权失败分类告警(P1-5):余额 / 订阅查询返回 unauthorized 时,按
|
|
5079
5083
|
* `source:provider` 去重并冷却告警,提示检查 llm-pi-ai 里该 provider 的 apiKeyEnv。
|
|
@@ -5317,7 +5321,8 @@ function apply(ctx, config = {}) {
|
|
|
5317
5321
|
})();
|
|
5318
5322
|
const persistReconcileRef = () => {
|
|
5319
5323
|
if (reconcileRef === null) return;
|
|
5320
|
-
|
|
5324
|
+
const payload = JSON.stringify({ ref: reconcileRef });
|
|
5325
|
+
writeFileAtomic(reconcilePath, payload, {
|
|
5321
5326
|
mode: 384,
|
|
5322
5327
|
dirMode: 448
|
|
5323
5328
|
}).catch(() => {});
|
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.0.
|
|
4
|
+
"version": "1.0.25",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"dshReleases": {
|
|
44
44
|
"0.1.2-alpha.1": "compatible",
|
|
45
45
|
"0.1.2-alpha.2": "compatible",
|
|
46
|
-
"0.1.2-alpha.3": "compatible"
|
|
46
|
+
"0.1.2-alpha.3": "compatible",
|
|
47
|
+
"0.1.2-alpha.4": "compatible",
|
|
48
|
+
"0.1.2-alpha.5": "compatible"
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
},
|
|
@@ -57,18 +59,18 @@
|
|
|
57
59
|
"node": "^22.19.0 || >=24.0.0"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
62
|
+
"@deepseek-ai/cordis": "*",
|
|
60
63
|
"@deepseek-ai/dsh-api-remotes": "*",
|
|
61
64
|
"@deepseek-ai/dsh-api-session-controller": "*",
|
|
62
65
|
"@deepseek-ai/dsh-atomic-write": "*",
|
|
63
|
-
"@deepseek-ai/dsh-host-webserver": "*",
|
|
64
66
|
"@deepseek-ai/dsh-client-locale": "*",
|
|
65
67
|
"@deepseek-ai/dsh-client-store": "*",
|
|
66
68
|
"@deepseek-ai/dsh-client-ui-conversation": "*",
|
|
67
69
|
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-renderer": "*",
|
|
69
70
|
"@deepseek-ai/dsh-client-ui-sidebar": "*",
|
|
70
71
|
"@deepseek-ai/dsh-client-ui-slots": "*",
|
|
71
72
|
"@deepseek-ai/dsh-credentials": "*",
|
|
73
|
+
"@deepseek-ai/dsh-host-webserver": "*",
|
|
72
74
|
"@deepseek-ai/dsh-invariants": "*",
|
|
73
75
|
"@deepseek-ai/dsh-llm": "*",
|
|
74
76
|
"@deepseek-ai/dsh-session": "*",
|
|
@@ -76,31 +78,44 @@
|
|
|
76
78
|
"@deepseek-ai/dsh-settings": "*",
|
|
77
79
|
"@deepseek-ai/dsh-tools": "*",
|
|
78
80
|
"@deepseek-ai/schemastery": "*",
|
|
79
|
-
"@deepseek-ai/cordis": "*",
|
|
80
81
|
"react": "^18.2.0"
|
|
81
82
|
},
|
|
82
83
|
"dependencies": {
|
|
83
84
|
"clsx": "^2.1.1"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
|
-
"@deepseek-ai/
|
|
87
|
-
"@deepseek-ai/
|
|
88
|
-
"@deepseek-ai/
|
|
89
|
-
"@deepseek-ai/dsh-
|
|
90
|
-
"@deepseek-ai/dsh-
|
|
91
|
-
"@deepseek-ai/dsh-
|
|
92
|
-
"@deepseek-ai/dsh-client-
|
|
93
|
-
"@deepseek-ai/dsh-client-
|
|
94
|
-
"@deepseek-ai/dsh-client-ui-
|
|
95
|
-
"@deepseek-ai/dsh-
|
|
87
|
+
"@deepseek-ai/cordis": "*",
|
|
88
|
+
"@deepseek-ai/cordis-plugin-include": "^1.0.7",
|
|
89
|
+
"@deepseek-ai/cordis-plugin-loader": "^1.0.3",
|
|
90
|
+
"@deepseek-ai/dsh-api-remotes": "0.1.2-alpha.5",
|
|
91
|
+
"@deepseek-ai/dsh-api-session-controller": "0.1.2-alpha.5",
|
|
92
|
+
"@deepseek-ai/dsh-atomic-write": "0.1.2-alpha.5",
|
|
93
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-alpha.5",
|
|
94
|
+
"@deepseek-ai/dsh-client-store": "0.1.2-alpha.5",
|
|
95
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.1.2-alpha.5",
|
|
96
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.2-alpha.5",
|
|
97
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-alpha.5",
|
|
98
|
+
"@deepseek-ai/dsh-credentials": "0.1.2-alpha.5",
|
|
99
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-alpha.5",
|
|
100
|
+
"@deepseek-ai/dsh-invariants": "0.1.2-alpha.5",
|
|
101
|
+
"@deepseek-ai/dsh-llm": "0.1.2-alpha.5",
|
|
102
|
+
"@deepseek-ai/dsh-scope": "0.1.2-alpha.5",
|
|
103
|
+
"@deepseek-ai/dsh-session": "0.1.2-alpha.5",
|
|
104
|
+
"@deepseek-ai/dsh-session-persistence": "0.1.2-alpha.5",
|
|
105
|
+
"@deepseek-ai/dsh-settings": "0.1.2-alpha.5",
|
|
106
|
+
"@deepseek-ai/dsh-tools": "0.1.2-alpha.5",
|
|
107
|
+
"@deepseek-ai/schemastery": "^3.18.2",
|
|
108
|
+
"@testing-library/dom": "^10.4.1",
|
|
96
109
|
"@testing-library/react": "^16.1.0",
|
|
97
|
-
"@types/react": "~18.3.1",
|
|
98
110
|
"@types/node": "^22.20.0",
|
|
99
|
-
"@
|
|
111
|
+
"@types/react": "~18.3.1",
|
|
112
|
+
"jsdom": "^26.1.0",
|
|
113
|
+
"lightningcss": "^1.32.0",
|
|
100
114
|
"react": "^18.2.0",
|
|
101
115
|
"react-dom": "^18.2.0",
|
|
102
|
-
"
|
|
103
|
-
"
|
|
116
|
+
"tsdown": "^0.22.2",
|
|
117
|
+
"use-sync-external-store": "1.2.0",
|
|
118
|
+
"vitest": "^4.1.8"
|
|
104
119
|
},
|
|
105
120
|
"files": [
|
|
106
121
|
"lib/index.js",
|