dsh-bottom-info-bar 1.27.3 → 1.29.0
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.md +20 -0
- package/README.zh-CN.md +20 -0
- package/lib/accounting.js +78 -8
- package/lib/client.js +155 -21
- package/lib/constants.js +30 -0
- package/lib/index.js +69 -15
- package/lib/locales.js +52 -0
- package/lib/native.js +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,26 @@ On **DSH 0.2.2 with the native activity/usage buttons**, the native line sits on
|
|
|
27
27
|
|
|
28
28
|
On **older hosts**, clicking the bar still switches between **Full** and **Compact**: Full keeps the legacy statistics row, Compact collapses it. Plugin fields remain identical in both modes. Compatibility is detected from the host's live extension entries, rather than a version string.
|
|
29
29
|
|
|
30
|
+
## DSH Go
|
|
31
|
+
|
|
32
|
+
Since v1.25.0, the bar and its settings page also adapt to **DSH Go**, the touch host for DeepSeek Harness — same package, no separate build, detected from the host's live layout signals rather than a version string. On the Go surface the account row becomes a card matched to the composer's material, the whole bar is a single touch target, and the details the desktop shows as hover tooltips open as an expandable details card instead, because touch has no hover. Wide Go windows gain two extra spend columns: today and the last 30 days.
|
|
33
|
+
|
|
34
|
+
The bar running under the composer in DSH Go:
|
|
35
|
+
|
|
36
|
+
<img src="assets/promo-dsh-go/dsh-go-info-bar-success.png" width="360" alt="Bottom Info Bar running under the composer in DSH Go">
|
|
37
|
+
|
|
38
|
+
Tapped open, the same card carries the full details:
|
|
39
|
+
|
|
40
|
+
<img src="assets/promo-dsh-go/dsh-go-info-bar-expanded.png" width="360" alt="Bottom Info Bar expanded into its details card in DSH Go">
|
|
41
|
+
|
|
42
|
+
The settings page adapts too, with a live preview of the bar and the same field switches:
|
|
43
|
+
|
|
44
|
+
<img src="assets/promo-dsh-go/dsh-go-plugin-settings-controls.png" width="360" alt="Bottom Info Bar settings with live preview in DSH Go">
|
|
45
|
+
|
|
46
|
+
And the plugin's own page in DSH Go carries the info bar card natively (v1.26.0):
|
|
47
|
+
|
|
48
|
+
<img src="assets/promo-dsh-go/dsh-go-plugin-settings-final.png" width="360" alt="Bottom Info Bar plugin page with the info bar card in DSH Go">
|
|
49
|
+
|
|
30
50
|
## Install
|
|
31
51
|
|
|
32
52
|
Recommended: open the DSH plugin page, choose **Add plugin**, and enter the npm package name — DSH fetches the published package from npm, with no commands and no build:
|
package/README.zh-CN.md
CHANGED
|
@@ -27,6 +27,26 @@ DeepSeek Harness 插件:把输入框下方那行统计栏换成一行信息栏
|
|
|
27
27
|
|
|
28
28
|
**旧宿主**仍保留点击信息栏切换**完整/简洁**:完整显示旧统计行,简洁收起它;插件字段在两种模式下一致。兼容方式通过实际扩展入口判断,不依赖版本号猜测。
|
|
29
29
|
|
|
30
|
+
## DSH Go
|
|
31
|
+
|
|
32
|
+
v1.25.0 起,信息栏与设置页同样适配 **DSH Go**(DeepSeek Harness 的触屏宿主)——还是同一个包,不用另装,靠宿主的实时布局信号识别,不看版本号。在 Go 里,账户信息行变成与输入框同材质的卡片,整条栏是一个触控目标;桌面端靠悬停提示展示的明细,在触屏上改为点开一张可展开的明细卡,因为触屏没有悬停。Go 宽屏窗口还会多出两列花费:今天与近 30 天。
|
|
33
|
+
|
|
34
|
+
信息栏在 DSH Go 输入框下方的运行画面:
|
|
35
|
+
|
|
36
|
+
<img src="assets/promo-dsh-go/dsh-go-info-bar-success.png" width="360" alt="信息栏在 DSH Go 输入框下方运行">
|
|
37
|
+
|
|
38
|
+
点开后,同一张卡承载完整明细:
|
|
39
|
+
|
|
40
|
+
<img src="assets/promo-dsh-go/dsh-go-info-bar-expanded.png" width="360" alt="信息栏在 DSH Go 里展开为明细卡">
|
|
41
|
+
|
|
42
|
+
设置页同样适配,带信息栏的实时预览与全部显示开关:
|
|
43
|
+
|
|
44
|
+
<img src="assets/promo-dsh-go/dsh-go-plugin-settings-controls.png" width="360" alt="DSH Go 里的信息栏设置页与实时预览">
|
|
45
|
+
|
|
46
|
+
DSH Go 里的插件页也原生带上信息栏卡片(v1.26.0):
|
|
47
|
+
|
|
48
|
+
<img src="assets/promo-dsh-go/dsh-go-plugin-settings-final.png" width="360" alt="DSH Go 里带信息栏卡片的插件页">
|
|
49
|
+
|
|
30
50
|
## 安装
|
|
31
51
|
|
|
32
52
|
最推荐:打开 DSH 的插件页 → **添加插件**,在「包名或地址」里填 npm 包名——DSH 会直接从 npm 下载已发布的版本,不用敲命令,也不用构建:
|
package/lib/accounting.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 峰谷日历、币种与账户映射,否则两边算出的金额会漂移。这里保持纯函数 + 一张可增量更新的
|
|
6
6
|
// PRICING 表:host 用 createAccounting() 得到自己的实例,worker 也各建一份,远程价目由
|
|
7
7
|
// host 通过 setRemotePricingEntries 同步给 worker。
|
|
8
|
-
import { PROVIDER_DEFAULT_CURRENCY, PROVIDER_IDENTITY } from './constants.js'
|
|
8
|
+
import { PROVIDER_DEFAULT_CURRENCY, PROVIDER_IDENTITY, DISPLAY_CURRENCY_META, DISPLAY_CURRENCIES } from './constants.js'
|
|
9
9
|
|
|
10
10
|
const BEIJING_OFFSET_MS = 8 * 3600 * 1000
|
|
11
11
|
|
|
@@ -17,6 +17,18 @@ export function accountForProvider(pid) {
|
|
|
17
17
|
return meta ? meta.account : null
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// DeepSeek 计费域作用域映射(issue #317 第二阶段):同一模型名按账户结算币种走不同价目表
|
|
21
|
+
// (美元表与人民币表是两张独立价目,不是简单汇率换算——见 deepseek-usd: 条目注释)。
|
|
22
|
+
// 'deepseek' 与 'deepseek-official' 在 PROVIDER_IDENTITY 里同属 account 'deepseek';
|
|
23
|
+
// 'deepseek-account'(DSH 桌面内置账号)刻意不在 PROVIDER_IDENTITY 里(见 host.js 的
|
|
24
|
+
// PLATFORM_BALANCE_PROVIDERS),此处单列。billingCurrency 非 'USD' 时原样返回,
|
|
25
|
+
// 调用方不传币种即沿用既有行为(人民币价)。
|
|
26
|
+
export function pricingProviderFor(provider, billingCurrency) {
|
|
27
|
+
if (billingCurrency !== 'USD' || typeof provider !== 'string' || provider.length === 0) return provider
|
|
28
|
+
if (accountForProvider(provider) === 'deepseek' || provider === 'deepseek-account') return 'deepseek-usd'
|
|
29
|
+
return provider
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
// 桶/索引的键都来自落盘记录(账户、币种、会话 ID)。JSON.parse 产生的 __proto__ 自有属性无害,
|
|
21
33
|
// 但 obj[key]= 赋值会触发原型污染——统一过一道键名护栏。
|
|
22
34
|
export function safeMapKey(value) {
|
|
@@ -30,11 +42,14 @@ export function safeMapKey(value) {
|
|
|
30
42
|
const WEEKEND_OFFPEAK_EFFECTIVE_AT = Date.UTC(2026, 7, 22, 16, 0, 0);
|
|
31
43
|
// Official holiday leave ranges (including adjacent leave days, not make-up workdays).
|
|
32
44
|
// https://www.gov.cn/zhengce/content/202511/content_7047090.htm
|
|
45
|
+
// 2027: 国务院办公厅关于2027年部分节假日安排的通知(国办发明电〔2026〕10号,2026-11-05)。
|
|
33
46
|
// Update this calendar after each year's State Council notice; unknown years
|
|
34
47
|
// retain the weekday/weekend rule rather than guessing lunar holiday dates.
|
|
35
48
|
const CHINESE_PUBLIC_HOLIDAYS = {
|
|
36
49
|
2026: [['01-01', '01-03'], ['02-15', '02-23'], ['04-04', '04-06'],
|
|
37
50
|
['05-01', '05-05'], ['06-19', '06-21'], ['09-25', '09-27'], ['10-01', '10-07']],
|
|
51
|
+
2027: [['01-01', '01-03'], ['02-05', '02-13'], ['04-03', '04-05'],
|
|
52
|
+
['05-01', '05-05'], ['06-09', '06-09'], ['09-15', '09-15'], ['10-01', '10-07']],
|
|
38
53
|
};
|
|
39
54
|
function isChinesePublicHoliday(nowMs) {
|
|
40
55
|
const d = new Date(nowMs + BEIJING_OFFSET_MS);
|
|
@@ -93,6 +108,29 @@ export const BUILTIN_PRICING = {
|
|
|
93
108
|
peak: { inputCacheHit: 0.30, inputCacheMiss: 9.0, output: 27.0 },
|
|
94
109
|
offpeak:{ inputCacheHit: 0.15, inputCacheMiss: 4.5, output: 13.5 },
|
|
95
110
|
},
|
|
111
|
+
// ---------- DeepSeek 美元计费域(issue #317 第二阶段;官方英文价目页,2026-11-26 核对) ----------
|
|
112
|
+
// 来源:https://api-docs.deepseek.com/quick_start/pricing(USD/百万 tokens)。
|
|
113
|
+
// 美元表与人民币表是两张独立价目、不是简单汇率换算:Flash 两档与美元×6.67 分毫不差,
|
|
114
|
+
// v4-pro 人民币价比美元×6.67 高约 2%(如未命中 $1.32→¥9.0,汇率换算应为 ¥8.80),
|
|
115
|
+
// 所以美元账户必须按美元表计价、不能拿人民币价折算。峰谷窗口与人民币表完全一致
|
|
116
|
+
// (UTC 周一至周五 01:00–04:00、06:00–10:00 = 北京时间 09:00–12:00、14:00–18:00,
|
|
117
|
+
// 空闲价为高峰价一半,周末与中国法定节假日全天空闲)。
|
|
118
|
+
// 作用域键遵循 Kimi 先例(moonshotai-cn:kimi-*):账户结算币种为 USD 时,
|
|
119
|
+
// host 按余额快照把 deepseek 系 provider 映射到 deepseek-usd 作用域(见 pricingProviderFor)。
|
|
120
|
+
'deepseek-usd:deepseek-flash': {
|
|
121
|
+
currency: 'USD', mode: 'peak-valley',
|
|
122
|
+
peak: { inputCacheHit: 0.006, inputCacheMiss: 0.30, output: 1.20 },
|
|
123
|
+
offpeak:{ inputCacheHit: 0.003, inputCacheMiss: 0.15, output: 0.60 },
|
|
124
|
+
},
|
|
125
|
+
'deepseek-usd:deepseek-v4-pro': {
|
|
126
|
+
currency: 'USD', mode: 'peak-valley',
|
|
127
|
+
peak: { inputCacheHit: 0.044, inputCacheMiss: 1.32, output: 3.96 },
|
|
128
|
+
offpeak:{ inputCacheHit: 0.022, inputCacheMiss: 0.66, output: 1.98 },
|
|
129
|
+
},
|
|
130
|
+
// deepseek-chat:2026-11-26 核对时已不在官方中英文价目页上(仅剩 flash 与 v4-pro),
|
|
131
|
+
// 但 DSH 侧仍可能以该模型名发起调用;本条目为兼容保留(最后已知官方价,flat),
|
|
132
|
+
// 待 DeepSeek 明确该模型名退役后再移除。美元域无此模型官方价,故不建 deepseek-usd 键——
|
|
133
|
+
// 美元账户调 deepseek-chat 时回退人民币价(与此前行为一致),不编造价格。
|
|
96
134
|
'deepseek-chat': { currency: 'CNY', mode: 'flat', price: { inputCacheHit: 0.5, inputCacheMiss: 2.0, output: 8.0 } },
|
|
97
135
|
'gpt-4o': { currency: 'USD', mode: 'flat', price: { inputCacheHit: 1.25, inputCacheMiss: 2.5, output: 10.0 } },
|
|
98
136
|
'gpt-4o-mini': { currency: 'USD', mode: 'flat', price: { inputCacheHit: 0.15, inputCacheMiss: 0.15, output: 0.6 } },
|
|
@@ -137,23 +175,50 @@ export const BUILTIN_PRICING = {
|
|
|
137
175
|
|
|
138
176
|
// 每个调用方各持一份可变的价目副本:host 主线程用一份算金额,worker 用另一份做迁移/回填;
|
|
139
177
|
// 远程目录合并后由 host 把增量同步给 worker(见 ledger-client.setPricing)。
|
|
178
|
+
// ---------- 显示货币换算(issue #317,纯函数,只供显示层调用) ----------
|
|
179
|
+
// 账本永远不调这里:换算只发生在金额落屏那一刻,换算值绝不写回账本与导出。
|
|
180
|
+
// 枢纽 USD:先把原生币种折成美元,再折成目标币种。target='auto' 或目标与原生
|
|
181
|
+
// 相同 → 不换算(converted=false)。未知币种 / 非有限数 → 原样返回、不换算。
|
|
182
|
+
// 顶层导出(native.js 直接 import);createAccounting 的返回值里同样挂一份。
|
|
183
|
+
export function convertMoney(value, fromCurrency, toCurrency) {
|
|
184
|
+
const n = Number(value)
|
|
185
|
+
if (!Number.isFinite(n)) return { value: value, currency: fromCurrency, converted: false }
|
|
186
|
+
const from = DISPLAY_CURRENCY_META[fromCurrency]
|
|
187
|
+
const to = DISPLAY_CURRENCY_META[toCurrency]
|
|
188
|
+
if (!from || !to || toCurrency === 'auto' || fromCurrency === toCurrency) {
|
|
189
|
+
return { value: n, currency: fromCurrency, converted: false }
|
|
190
|
+
}
|
|
191
|
+
const usd = fromCurrency === 'USD' ? n : n / from.perUsd
|
|
192
|
+
const out = toCurrency === 'USD' ? usd : usd * to.perUsd
|
|
193
|
+
return { value: Number.isFinite(out) ? out : n, currency: toCurrency, converted: Number.isFinite(out) }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 显示货币归一(宽松版:客户端与 native 共用):合法值原样返回,其余一律回 'auto',
|
|
197
|
+
// 绝不抛错。host 的严格版(非法即拒收)在 host.js 里另写,与 quotaDisplayMode 同规。
|
|
198
|
+
export function normalizeDisplayCurrency(value) {
|
|
199
|
+
return DISPLAY_CURRENCIES.indexOf(value) !== -1 ? value : 'auto'
|
|
200
|
+
}
|
|
201
|
+
|
|
140
202
|
export function createAccounting() {
|
|
141
203
|
const PRICING = Object.assign(Object.create(null), BUILTIN_PRICING)
|
|
142
204
|
|
|
143
205
|
// ---------- 价目查询 ----------
|
|
144
|
-
|
|
145
|
-
|
|
206
|
+
// billingCurrency(可选):调用方已知的账户结算币种。传了才改变作用域(DeepSeek 美元域),
|
|
207
|
+
// 不传即沿用既有行为;record.currency(落盘时冻结的币种)同样经此参数传入,forecast 重算
|
|
208
|
+
// 才不会把美元账户的历史记录按人民币价重算。
|
|
209
|
+
function modelCurrency(provider, model, billingCurrency) {
|
|
210
|
+
// 服务商作用域键优先:同名模型跨计费域时(Kimi 国内外、DeepSeek 双币种),币种必须跟作用域走
|
|
146
211
|
if (typeof provider !== 'string' || provider.trim().length === 0
|
|
147
212
|
|| typeof model !== 'string' || model.trim().length === 0) return null;
|
|
148
|
-
const entry = pricingEntryFor(provider, model);
|
|
213
|
+
const entry = pricingEntryFor(provider, model, billingCurrency);
|
|
149
214
|
if (entry && entry.currency) return entry.currency;
|
|
150
215
|
if (Object.hasOwn(PROVIDER_DEFAULT_CURRENCY, provider)) return PROVIDER_DEFAULT_CURRENCY[provider];
|
|
151
216
|
if (model && /^(gpt|o1|o3|claude|gemini|grok)/.test(model)) return 'USD';
|
|
152
217
|
return 'CNY';
|
|
153
218
|
}
|
|
154
219
|
|
|
155
|
-
function pricingEntryFor(provider, model) {
|
|
156
|
-
const scopedKey = provider + ':' + model;
|
|
220
|
+
function pricingEntryFor(provider, model, billingCurrency) {
|
|
221
|
+
const scopedKey = pricingProviderFor(provider, billingCurrency) + ':' + model;
|
|
157
222
|
const scoped = Object.hasOwn(PRICING, scopedKey) ? PRICING[scopedKey] : null;
|
|
158
223
|
return scoped && typeof scoped === 'object'
|
|
159
224
|
? scoped
|
|
@@ -161,11 +226,13 @@ export function createAccounting() {
|
|
|
161
226
|
}
|
|
162
227
|
|
|
163
228
|
// ---------- 花费计算 ----------
|
|
164
|
-
function costOf(record, forceOffpeak) {
|
|
229
|
+
function costOf(record, forceOffpeak, billingCurrency) {
|
|
165
230
|
// v2 ledger records carry the charge as observed. Use it for normal
|
|
166
231
|
// reporting; only the "all-offpeak" forecast intentionally recalculates.
|
|
167
232
|
if (!forceOffpeak && Number.isFinite(record.cost) && record.cost >= 0) return record.cost;
|
|
168
|
-
|
|
233
|
+
// 未传 billingCurrency 时用记录冻结的币种定作用域(forecast 重算);新记录落盘时
|
|
234
|
+
// host 传余额快照的账户币种;两者都没有 → 既有默认(DeepSeek 人民币价)。
|
|
235
|
+
const entry = pricingEntryFor(record.provider, record.model, billingCurrency || record.currency);
|
|
169
236
|
if (!entry) return null;
|
|
170
237
|
let p;
|
|
171
238
|
if (entry.mode === 'peak-valley') {
|
|
@@ -192,9 +259,12 @@ export function createAccounting() {
|
|
|
192
259
|
|
|
193
260
|
return {
|
|
194
261
|
PRICING: PRICING,
|
|
262
|
+
pricingProviderFor: pricingProviderFor,
|
|
195
263
|
pricingEntryFor: pricingEntryFor,
|
|
196
264
|
modelCurrency: modelCurrency,
|
|
197
265
|
costOf: costOf,
|
|
198
266
|
setRemotePricingEntries: setRemotePricingEntries,
|
|
267
|
+
convertMoney: convertMoney,
|
|
268
|
+
normalizeDisplayCurrency: normalizeDisplayCurrency,
|
|
199
269
|
};
|
|
200
270
|
}
|