@linxin666/dsh-usage 0.4.5 → 0.4.7
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/README.i18n.yaml +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/client.js +45 -38
- package/lib/client.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/types/client/voucher.d.ts +27 -9
- package/package.json +18 -18
- package/src/client/UsageSectionCard.tsx +10 -10
- package/src/client/locales.ts +4 -4
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/voucher.ts +33 -11
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 474e17535c150db2c19ebee756c7b89fcddc5a9b
|
|
6
|
+
README.zh.md: 7efc2ea94d5c8f507845b40a4b67b5cef060b453
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-usage?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -39,7 +39,7 @@ The published rule bills a Chinese public holiday entirely off-peak even on a Mo
|
|
|
39
39
|
|
|
40
40
|
## Install
|
|
41
41
|
|
|
42
|
-
Requires DSH 0.2.
|
|
42
|
+
Requires DSH 0.2.1-rc.2 or later: the plugin is developed against the 0.2.1-rc.2 DSH cohort (its settings page is the Host-generated page of the plugin's own Config schema) and its `@deepseek-ai/*` runtime imports are provided by the host itself.
|
|
43
43
|
|
|
44
44
|
In your profile (e.g. `~/.dsh/profiles/web`):
|
|
45
45
|
|
package/README.zh.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-usage?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
## 安装
|
|
41
41
|
|
|
42
|
-
要求 DSH 0.2.
|
|
42
|
+
要求 DSH 0.2.1-rc.2 或更高:插件基于 0.2.1-rc.2 DSH cohort 开发(其设置页即宿主根据插件自身 Config schema 生成的页面),`@deepseek-ai/*` 运行时导入由宿主本体提供。
|
|
43
43
|
|
|
44
44
|
在 profile(如 `~/.dsh/profiles/web`)中:
|
|
45
45
|
|
package/lib/client.js
CHANGED
|
@@ -4,22 +4,10 @@ window.__ModuleLoader__.load({
|
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
|
|
7
8
|
let react = require("react");
|
|
8
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
10
|
let react_dom_client = require("react-dom/client");
|
|
10
|
-
//#region \0dsh-store-engine
|
|
11
|
-
const platform = ["@deepseek-ai/dsh-client", "-store"].join("");
|
|
12
|
-
const legacy = ["@deepseek-ai/dsh-client-runtime", "/client"].join("");
|
|
13
|
-
let engine;
|
|
14
|
-
try {
|
|
15
|
-
engine = require(platform);
|
|
16
|
-
} catch {
|
|
17
|
-
engine = require(legacy);
|
|
18
|
-
}
|
|
19
|
-
engine.createSnapshotStore;
|
|
20
|
-
const defineStore = engine.defineStore;
|
|
21
|
-
engine.shallowEqual;
|
|
22
|
-
//#endregion
|
|
23
11
|
//#region src/client/usage-store.ts
|
|
24
12
|
/**
|
|
25
13
|
* Browser-side usage store: the overview snapshot polled from the host plus
|
|
@@ -29,7 +17,7 @@ window.__ModuleLoader__.load({
|
|
|
29
17
|
*/
|
|
30
18
|
/** Create the usage store handle (apply world only; never module-level). */
|
|
31
19
|
function createUsageStore() {
|
|
32
|
-
return defineStore({
|
|
20
|
+
return (0, _deepseek_ai_dsh_client_store.defineStore)({
|
|
33
21
|
init: () => ({
|
|
34
22
|
snapshot: null,
|
|
35
23
|
status: "loading",
|
|
@@ -107,8 +95,8 @@ window.__ModuleLoader__.load({
|
|
|
107
95
|
"usage.config.pollIntervalSec": "轮询间隔(秒)",
|
|
108
96
|
"usage.config.saveFailed": "保存失败:设置未被接受。",
|
|
109
97
|
"usage.bank.title": "鲸元券",
|
|
110
|
-
"usage.bank.hint": "官方 API 每消耗 100 万 tokens 铸造 1 鲸元;保存或分享这张票券。",
|
|
111
|
-
"usage.bank.noUsage": "暂无 DeepSeek
|
|
98
|
+
"usage.bank.hint": "DeepSeek 官方 API 与 MiMo 每消耗 100 万 tokens 铸造 1 鲸元;保存或分享这张票券。",
|
|
99
|
+
"usage.bank.noUsage": "暂无 DeepSeek 官方 / MiMo 用量数据(统计自插件启用起)",
|
|
112
100
|
"usage.bank.minted": "累计铸造 {minted} 鲸元({tokens} tokens)",
|
|
113
101
|
"usage.bank.spend.observed": "官方余额实测花费 ¥{cost}(自 {since} 起)",
|
|
114
102
|
"usage.bank.spend.estimated": "消费估算:约 ¥{cost}",
|
|
@@ -173,8 +161,8 @@ window.__ModuleLoader__.load({
|
|
|
173
161
|
"usage.config.pollIntervalSec": "Poll interval (seconds)",
|
|
174
162
|
"usage.config.saveFailed": "Save failed: the deployment did not accept the setting.",
|
|
175
163
|
"usage.bank.title": "Whale-yuan voucher",
|
|
176
|
-
"usage.bank.hint": "Every 1,000,000 tokens spent on the official API mint one whale yuan; save or share the note.",
|
|
177
|
-
"usage.bank.noUsage": "No official
|
|
164
|
+
"usage.bank.hint": "Every 1,000,000 tokens spent on the DeepSeek official API or on MiMo mint one whale yuan; save or share the note.",
|
|
165
|
+
"usage.bank.noUsage": "No DeepSeek official or MiMo usage yet (counting starts when the plugin is enabled)",
|
|
178
166
|
"usage.bank.minted": "Minted {minted} whale yuan ({tokens} tokens)",
|
|
179
167
|
"usage.bank.spend.observed": "Spent ¥{cost} observed on the official balance (watching since {since})",
|
|
180
168
|
"usage.bank.spend.estimated": "Estimated spend: about ¥{cost}",
|
|
@@ -1067,8 +1055,8 @@ window.__ModuleLoader__.load({
|
|
|
1067
1055
|
//#endregion
|
|
1068
1056
|
//#region src/client/voucher.ts
|
|
1069
1057
|
/**
|
|
1070
|
-
* The Whale-yuan voucher (鲸元券): the
|
|
1071
|
-
*
|
|
1058
|
+
* The Whale-yuan voucher (鲸元券): the mint family's retained ledger totals
|
|
1059
|
+
* stamped onto the banknote artwork as a denomination, ready
|
|
1072
1060
|
* to save or share. The canvas copy is deliberately locale-neutral (digits,
|
|
1073
1061
|
* latin captions, ISO dates) so the exported image needs no dictionary;
|
|
1074
1062
|
* everything user-facing around it lives in the section's locales. The pure
|
|
@@ -1090,21 +1078,41 @@ window.__ModuleLoader__.load({
|
|
|
1090
1078
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
1091
1079
|
}
|
|
1092
1080
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1081
|
+
* Provider route ids minted beside the DeepSeek official family: the MiMo
|
|
1082
|
+
* gateway, which a profile may run as its default route and which the ledger
|
|
1083
|
+
* records under its own route id. The bank counts the tokens a profile spends,
|
|
1084
|
+
* not only the ones DeepSeek bills. Route ids rather than adapter families
|
|
1085
|
+
* because minting is an accounting decision that must never widen the
|
|
1086
|
+
* credential or probing paths — the same split `isDeepSeekProviderRoute()`
|
|
1087
|
+
* keeps against `adapterFor()` (issue #1772). An empty list mints exactly the
|
|
1088
|
+
* official family, which is how a profile that never runs MiMo behaves.
|
|
1089
|
+
*/
|
|
1090
|
+
const EXTRA_MINT_ROUTE_IDS = ["mimo"];
|
|
1091
|
+
/** Whether one provider route's ledger rows mint whale yuan. */
|
|
1092
|
+
function mintsWhaleYuan(provider) {
|
|
1093
|
+
return isDeepSeekProviderRoute(provider) || EXTRA_MINT_ROUTE_IDS.includes(provider);
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Sum the mint family's rows out of a usage window: the whole DeepSeek
|
|
1097
|
+
* official family (the `deepseek` catalog alias, the live `deepseek-official`
|
|
1098
|
+
* route and the signed-in `deepseek-account` route all fold into one voucher)
|
|
1099
|
+
* plus {@link EXTRA_MINT_ROUTE_IDS}. Undefined when the window is absent
|
|
1100
|
+
* (older host) or the family has no usage — a zero-token note mints nothing.
|
|
1101
|
+
*
|
|
1102
|
+
* Only the priced family contributes `cost`: MiMo ships no price book, so it
|
|
1103
|
+
* mints tokens and calls while the spend line keeps reporting the official
|
|
1104
|
+
* family's fold-time estimate (and the observed-balance watch above it).
|
|
1097
1105
|
*/
|
|
1098
|
-
function
|
|
1106
|
+
function voucherData(window) {
|
|
1099
1107
|
if (window === void 0) return void 0;
|
|
1100
1108
|
let tokens = 0;
|
|
1101
1109
|
let calls = 0;
|
|
1102
1110
|
let cost = 0;
|
|
1103
1111
|
for (const row of window.providers) {
|
|
1104
|
-
if (!
|
|
1112
|
+
if (!mintsWhaleYuan(row.provider)) continue;
|
|
1105
1113
|
tokens += totalTokens(row.totals);
|
|
1106
1114
|
calls += row.totals.calls;
|
|
1107
|
-
cost += row.totals.cost;
|
|
1115
|
+
if (isDeepSeekProviderRoute(row.provider)) cost += row.totals.cost;
|
|
1108
1116
|
}
|
|
1109
1117
|
if (tokens <= 0) return void 0;
|
|
1110
1118
|
return {
|
|
@@ -1791,18 +1799,18 @@ window.__ModuleLoader__.load({
|
|
|
1791
1799
|
return totals.inputTokens + totals.cacheReadTokens + totals.cacheWriteTokens + totals.outputTokens;
|
|
1792
1800
|
}
|
|
1793
1801
|
/**
|
|
1794
|
-
* The Token 银行 card: the
|
|
1795
|
-
* minted onto the whale-yuan note at 1,000,000 tokens
|
|
1796
|
-
* window is the whole retained ledger by default (the
|
|
1797
|
-
* falling back to the 30-day trend when an older host serves
|
|
1798
|
-
* single day the user picked; the spend line prefers the
|
|
1799
|
-
* watch (whole window only) and falls back to the fold-time
|
|
1800
|
-
*
|
|
1801
|
-
* down.
|
|
1802
|
+
* The Token 银行 card: the mint family's (DeepSeek official + MiMo)
|
|
1803
|
+
* retained-ledger usage minted onto the whale-yuan note at 1,000,000 tokens
|
|
1804
|
+
* per whale yuan. The window is the whole retained ledger by default (the
|
|
1805
|
+
* host's aggregate, falling back to the 30-day trend when an older host serves
|
|
1806
|
+
* no `all`) or the single day the user picked; the spend line prefers the
|
|
1807
|
+
* official balance watch (whole window only) and falls back to the fold-time
|
|
1808
|
+
* estimate, which only the priced family feeds; the artwork draw failure
|
|
1809
|
+
* degrades to an error line and never takes the section down.
|
|
1802
1810
|
*/
|
|
1803
1811
|
function VoucherCard(props) {
|
|
1804
1812
|
const { window: ledger, observedSpend, loading, error } = props;
|
|
1805
|
-
const data =
|
|
1813
|
+
const data = voucherData(ledger);
|
|
1806
1814
|
const canvasRef = (0, react.useRef)(null);
|
|
1807
1815
|
const [drawError, setDrawError] = (0, react.useState)(void 0);
|
|
1808
1816
|
(0, react.useEffect)(() => {
|
|
@@ -2558,8 +2566,7 @@ window.__ModuleLoader__.load({
|
|
|
2558
2566
|
base: void 0,
|
|
2559
2567
|
user: void 0,
|
|
2560
2568
|
revision: void 0,
|
|
2561
|
-
writable: false
|
|
2562
|
-
mode: "host"
|
|
2569
|
+
writable: false
|
|
2563
2570
|
};
|
|
2564
2571
|
}
|
|
2565
2572
|
/**
|