@alexpeng/dsh-custom-plugin 0.1.4 → 0.1.5
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 +7 -0
- package/lib/client.js +28 -7
- package/lib/client.js.map +1 -1
- package/lib/index.js +81 -36
- package/lib/types/client/api.d.ts +1 -0
- package/lib/types/host-service.d.ts +2 -0
- package/lib/types/pricing.d.ts +4 -3
- package/lib/types/protocol.d.ts +4 -0
- package/lib/types/usage.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,13 @@ follow [Semantic Versioning](https://semver.org/).
|
|
|
8
8
|
|
|
9
9
|
### Fixed
|
|
10
10
|
|
|
11
|
+
- Usage scans now preserve the live ledger when a session read fails or new
|
|
12
|
+
usage arrives during replay, and return the replayed Beijing day so a
|
|
13
|
+
midnight-crossing scan cannot relabel its result.
|
|
14
|
+
- Legacy API-key migration no longer overwrites an existing system credential;
|
|
15
|
+
failed system-key deletion is reported instead of being treated as success.
|
|
16
|
+
- Legacy usage rows without a recoverable peak/off-peak split are marked as
|
|
17
|
+
inexact and are no longer shown with a misleading cost estimate.
|
|
11
18
|
- DeepSeek peak/off-peak cost estimates now treat only Beijing Monday-Friday
|
|
12
19
|
09:00–12:00 / 14:00–18:00 as peak; weekends are off-peak.
|
|
13
20
|
- The browser usage panel now uses the same Beijing-time day bucket as the
|
package/lib/client.js
CHANGED
|
@@ -33,6 +33,19 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
* exact. The published peak/off-peak schedule and the ledger day buckets are
|
|
34
34
|
* both defined on this clock, independent of the host's local timezone. */
|
|
35
35
|
const CST_OFFSET_MS = 8 * 36e5;
|
|
36
|
+
const PEAK_COUNTER_KEYS = [
|
|
37
|
+
"peakIn",
|
|
38
|
+
"peakCacheIn",
|
|
39
|
+
"peakCacheW",
|
|
40
|
+
"peakOut"
|
|
41
|
+
];
|
|
42
|
+
function hasAllPeakCounters(row) {
|
|
43
|
+
return PEAK_COUNTER_KEYS.every((key) => typeof row[key] === "number");
|
|
44
|
+
}
|
|
45
|
+
/** Whether a row has enough persisted information for exact tariff math. */
|
|
46
|
+
function hasKnownPeakSplit(row) {
|
|
47
|
+
return row.peakSplitKnown === true || row.peakSplitKnown === void 0 && hasAllPeakCounters(row);
|
|
48
|
+
}
|
|
36
49
|
function cstParts(time) {
|
|
37
50
|
const d = new Date(time + CST_OFFSET_MS);
|
|
38
51
|
return {
|
|
@@ -52,6 +65,12 @@ window.__ModuleLoader__.load({
|
|
|
52
65
|
}
|
|
53
66
|
//#endregion
|
|
54
67
|
//#region src/pricing.ts
|
|
68
|
+
/**
|
|
69
|
+
* DeepSeek cost-estimation helpers shared by the host-facing usage model and
|
|
70
|
+
* the browser panel. Prices are CNY per 1M tokens at peak rate; off-peak is
|
|
71
|
+
* applied to the portion without a peak counter.
|
|
72
|
+
* @module @alexpeng/dsh-custom-plugin/pricing
|
|
73
|
+
*/
|
|
55
74
|
/** Official source used for the built-in estimate and shown in the panel. */
|
|
56
75
|
const DEEPSEEK_PRICING_SOURCE_URL = "https://api-docs.deepseek.com/zh-cn/quick_start/pricing/";
|
|
57
76
|
/** Date on which the built-in rule was checked against the official page. */
|
|
@@ -79,9 +98,8 @@ window.__ModuleLoader__.load({
|
|
|
79
98
|
}
|
|
80
99
|
/**
|
|
81
100
|
* Split one row into peak/off-peak token volume and CNY cost. Rows without
|
|
82
|
-
* peak counters
|
|
83
|
-
*
|
|
84
|
-
* tracking existed; a rescan can rebuild the row with exact split counters.
|
|
101
|
+
* peak counters retain the old all-off-peak numeric fallback for compatibility,
|
|
102
|
+
* but `exact` is false until a rescan rebuilds the row with split counters.
|
|
85
103
|
*/
|
|
86
104
|
function usageCostBreakdown(row, model) {
|
|
87
105
|
const price = priceOf(model);
|
|
@@ -92,6 +110,7 @@ window.__ModuleLoader__.load({
|
|
|
92
110
|
const peakCost = peakIn * price.input + peakCacheIn * price.cacheHit + peakCacheW * price.input + peakOut * price.output;
|
|
93
111
|
const offPeakCost = (row.in - peakIn) * price.input + (row.cacheIn - peakCacheIn) * price.cacheHit + (row.cacheW - peakCacheW) * price.input + (row.out - peakOut) * price.output;
|
|
94
112
|
return {
|
|
113
|
+
exact: hasKnownPeakSplit(row),
|
|
95
114
|
peakTokens: peakIn + peakCacheIn + peakCacheW + peakOut,
|
|
96
115
|
offPeakTokens: row.in - peakIn + (row.cacheIn - peakCacheIn) + (row.cacheW - peakCacheW) + (row.out - peakOut),
|
|
97
116
|
peakCostCny: peakCost / 1e6,
|
|
@@ -3067,9 +3086,10 @@ window.__ModuleLoader__.load({
|
|
|
3067
3086
|
const result = await apiUsageScan();
|
|
3068
3087
|
if (result.ok === true) {
|
|
3069
3088
|
S.usage = { ...S.usage };
|
|
3070
|
-
|
|
3089
|
+
const scanDay = result.day || dayKey();
|
|
3090
|
+
S.usage[scanDay] = result.usageToday;
|
|
3071
3091
|
setS({ usage: S.usage });
|
|
3072
|
-
toast(
|
|
3092
|
+
toast(`已扫描 ${scanDay} 会话日志(${String(result.scannedSessions)} 个活跃会话)`, "info");
|
|
3073
3093
|
} else toast(result.error ?? "扫描失败", "error");
|
|
3074
3094
|
} catch (error) {
|
|
3075
3095
|
toast("扫描失败: " + String(error?.message ?? error), "error");
|
|
@@ -3291,13 +3311,14 @@ window.__ModuleLoader__.load({
|
|
|
3291
3311
|
row: day[model],
|
|
3292
3312
|
breakdown: usageCostBreakdown(day[model], model)
|
|
3293
3313
|
}));
|
|
3314
|
+
const allSplitsKnown = rows.every((item) => item.breakdown.exact);
|
|
3294
3315
|
const totalPeakTokens = rows.reduce((sum, item) => sum + item.breakdown.peakTokens, 0);
|
|
3295
3316
|
const totalOffPeakTokens = rows.reduce((sum, item) => sum + item.breakdown.offPeakTokens, 0);
|
|
3296
3317
|
const totalPeakCost = rows.reduce((sum, item) => sum + item.breakdown.peakCostCny, 0);
|
|
3297
3318
|
const totalOffPeakCost = rows.reduce((sum, item) => sum + item.breakdown.offPeakCostCny, 0);
|
|
3298
3319
|
return react.createElement("div", null, react.createElement("table", { className: "vx-table" }, react.createElement("thead", null, react.createElement("tr", null, react.createElement("th", null, "模型"), react.createElement("th", null, "输入"), react.createElement("th", null, "缓存"), react.createElement("th", null, "输出"), react.createElement("th", null, "调用"), react.createElement("th", null, "费用 ¥"))), react.createElement("tbody", null, rows.map(({ model, row, breakdown }) => {
|
|
3299
|
-
return react.createElement("tr", { key: model }, react.createElement("td", null, model), react.createElement("td", null, row.in ?? 0), react.createElement("td", null, row.cacheIn ?? 0), react.createElement("td", null, row.out ?? 0), react.createElement("td", null, row.calls ?? 0), react.createElement("td", { title: `峰 ¥${breakdown.peakCostCny.toFixed(4)} · 闲 ¥${breakdown.offPeakCostCny.toFixed(4)}` }, breakdown.totalCostCny.toFixed(4)));
|
|
3300
|
-
}))), react.createElement("div", { className: "vx-muted" }, `峰 token ${formatTokenCount(totalPeakTokens)} · 闲 token ${formatTokenCount(totalOffPeakTokens)} · 峰费用 ¥${totalPeakCost.toFixed(4)} · 闲费用 ¥${totalOffPeakCost.toFixed(4)}`), react.createElement("div", { className: "vx-muted" }, `规则核对于 ${DEEPSEEK_PRICING_CHECKED_ON} · `, react.createElement("a", {
|
|
3320
|
+
return react.createElement("tr", { key: model }, react.createElement("td", null, model), react.createElement("td", null, row.in ?? 0), react.createElement("td", null, row.cacheIn ?? 0), react.createElement("td", null, row.out ?? 0), react.createElement("td", null, row.calls ?? 0), react.createElement("td", { title: breakdown.exact ? `峰 ¥${breakdown.peakCostCny.toFixed(4)} · 闲 ¥${breakdown.offPeakCostCny.toFixed(4)}` : "旧用量缺少峰闲时拆分,请先扫描今日会话日志" }, breakdown.exact ? breakdown.totalCostCny.toFixed(4) : "—"));
|
|
3321
|
+
}))), allSplitsKnown ? react.createElement("div", { className: "vx-muted" }, `峰 token ${formatTokenCount(totalPeakTokens)} · 闲 token ${formatTokenCount(totalOffPeakTokens)} · 峰费用 ¥${totalPeakCost.toFixed(4)} · 闲费用 ¥${totalOffPeakCost.toFixed(4)}`) : react.createElement("div", { className: "vx-muted" }, "部分旧用量缺少峰闲时拆分,费用暂不估算;请先扫描今日会话日志。"), react.createElement("div", { className: "vx-muted" }, `规则核对于 ${DEEPSEEK_PRICING_CHECKED_ON} · `, react.createElement("a", {
|
|
3301
3322
|
href: DEEPSEEK_PRICING_SOURCE_URL,
|
|
3302
3323
|
target: "_blank",
|
|
3303
3324
|
rel: "noreferrer"
|