dsh-bottom-info-bar 1.28.0 → 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/lib/accounting.js +51 -7
- package/lib/constants.js +4 -0
- package/lib/index.js +40 -12
- package/package.json +1 -1
package/lib/accounting.js
CHANGED
|
@@ -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 } },
|
|
@@ -165,19 +203,22 @@ export function createAccounting() {
|
|
|
165
203
|
const PRICING = Object.assign(Object.create(null), BUILTIN_PRICING)
|
|
166
204
|
|
|
167
205
|
// ---------- 价目查询 ----------
|
|
168
|
-
|
|
169
|
-
|
|
206
|
+
// billingCurrency(可选):调用方已知的账户结算币种。传了才改变作用域(DeepSeek 美元域),
|
|
207
|
+
// 不传即沿用既有行为;record.currency(落盘时冻结的币种)同样经此参数传入,forecast 重算
|
|
208
|
+
// 才不会把美元账户的历史记录按人民币价重算。
|
|
209
|
+
function modelCurrency(provider, model, billingCurrency) {
|
|
210
|
+
// 服务商作用域键优先:同名模型跨计费域时(Kimi 国内外、DeepSeek 双币种),币种必须跟作用域走
|
|
170
211
|
if (typeof provider !== 'string' || provider.trim().length === 0
|
|
171
212
|
|| typeof model !== 'string' || model.trim().length === 0) return null;
|
|
172
|
-
const entry = pricingEntryFor(provider, model);
|
|
213
|
+
const entry = pricingEntryFor(provider, model, billingCurrency);
|
|
173
214
|
if (entry && entry.currency) return entry.currency;
|
|
174
215
|
if (Object.hasOwn(PROVIDER_DEFAULT_CURRENCY, provider)) return PROVIDER_DEFAULT_CURRENCY[provider];
|
|
175
216
|
if (model && /^(gpt|o1|o3|claude|gemini|grok)/.test(model)) return 'USD';
|
|
176
217
|
return 'CNY';
|
|
177
218
|
}
|
|
178
219
|
|
|
179
|
-
function pricingEntryFor(provider, model) {
|
|
180
|
-
const scopedKey = provider + ':' + model;
|
|
220
|
+
function pricingEntryFor(provider, model, billingCurrency) {
|
|
221
|
+
const scopedKey = pricingProviderFor(provider, billingCurrency) + ':' + model;
|
|
181
222
|
const scoped = Object.hasOwn(PRICING, scopedKey) ? PRICING[scopedKey] : null;
|
|
182
223
|
return scoped && typeof scoped === 'object'
|
|
183
224
|
? scoped
|
|
@@ -185,11 +226,13 @@ export function createAccounting() {
|
|
|
185
226
|
}
|
|
186
227
|
|
|
187
228
|
// ---------- 花费计算 ----------
|
|
188
|
-
function costOf(record, forceOffpeak) {
|
|
229
|
+
function costOf(record, forceOffpeak, billingCurrency) {
|
|
189
230
|
// v2 ledger records carry the charge as observed. Use it for normal
|
|
190
231
|
// reporting; only the "all-offpeak" forecast intentionally recalculates.
|
|
191
232
|
if (!forceOffpeak && Number.isFinite(record.cost) && record.cost >= 0) return record.cost;
|
|
192
|
-
|
|
233
|
+
// 未传 billingCurrency 时用记录冻结的币种定作用域(forecast 重算);新记录落盘时
|
|
234
|
+
// host 传余额快照的账户币种;两者都没有 → 既有默认(DeepSeek 人民币价)。
|
|
235
|
+
const entry = pricingEntryFor(record.provider, record.model, billingCurrency || record.currency);
|
|
193
236
|
if (!entry) return null;
|
|
194
237
|
let p;
|
|
195
238
|
if (entry.mode === 'peak-valley') {
|
|
@@ -216,6 +259,7 @@ export function createAccounting() {
|
|
|
216
259
|
|
|
217
260
|
return {
|
|
218
261
|
PRICING: PRICING,
|
|
262
|
+
pricingProviderFor: pricingProviderFor,
|
|
219
263
|
pricingEntryFor: pricingEntryFor,
|
|
220
264
|
modelCurrency: modelCurrency,
|
|
221
265
|
costOf: costOf,
|
package/lib/constants.js
CHANGED
|
@@ -271,6 +271,10 @@ export const PROVIDER_DEFAULT_CURRENCY = {
|
|
|
271
271
|
// 不堆冷门币种。symbol 一律前缀、无空格(与现有 $/¥ 写法一致);HKD 用 HK$ 与 $ 区分;
|
|
272
272
|
// JPY/KRW 按惯例 0 位小数,其余 2 位。
|
|
273
273
|
// 本表保留字面量(构建直接提取注入客户端,派生写法提不出来),与上面两个集合同规。
|
|
274
|
+
// 汇率不做实时拉取(issue #317 第二阶段结论):
|
|
275
|
+
// 显示换算本就是近似值(界面以 ~ 明示),汇率日波幅通常 < 1%,实时源反而引入新的网络依赖
|
|
276
|
+
// 与失败面;本表随每次发版复核更新,取数日期见 DISPLAY_FX_AS_OF。自动更新的是价目表
|
|
277
|
+
// (模型单价,远程目录 6 小时刷新),不是汇率——两者别混淆。
|
|
274
278
|
export const DISPLAY_FX_AS_OF = '2026-11-26'
|
|
275
279
|
export const DISPLAY_CURRENCY_META = {
|
|
276
280
|
'USD': { symbol: '$', decimals: 2, perUsd: 1 },
|
package/lib/index.js
CHANGED
|
@@ -2403,22 +2403,40 @@ export default {
|
|
|
2403
2403
|
function sanitizeRemotePricingEntries(raw) {
|
|
2404
2404
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
2405
2405
|
const entries = Object.create(null);
|
|
2406
|
+
// 单档(三价)数值护栏:有限非负、未命中 > 0、命中 ≤ 未命中。flat 与 peak-valley 共用。
|
|
2407
|
+
function sanitizePriceLeg(leg) {
|
|
2408
|
+
if (!leg || typeof leg !== 'object') return null;
|
|
2409
|
+
const hit = parseFiniteNonNegativeAmount(leg.inputCacheHit);
|
|
2410
|
+
const miss = parseFiniteNonNegativeAmount(leg.inputCacheMiss);
|
|
2411
|
+
const out = parseFiniteNonNegativeAmount(leg.output);
|
|
2412
|
+
if (hit == null || miss == null || out == null) return null;
|
|
2413
|
+
if (miss <= 0 || hit < 0 || out < 0) return null;
|
|
2414
|
+
if (hit > miss) return null; // 缓存命中不可能比未命中更贵:脏数据拒收
|
|
2415
|
+
return { inputCacheHit: hit, inputCacheMiss: miss, output: out };
|
|
2416
|
+
}
|
|
2406
2417
|
for (const key of Object.keys(raw)) {
|
|
2407
2418
|
if (Object.keys(entries).length >= 512) break; // 容量上限,防滥用
|
|
2408
2419
|
// 字符集 [A-Za-z0-9._:-] 允许 "provider:model" 作用域键,拒绝空段/前后缀冒号
|
|
2409
2420
|
if (!/^[A-Za-z0-9._-]+(?::[A-Za-z0-9._-]+)?$/.test(key) || key.length > 64) continue;
|
|
2410
2421
|
const e = raw[key];
|
|
2411
2422
|
if (!e || typeof e !== 'object') continue;
|
|
2412
|
-
// v1 仅接受统一价(flat);分时价的窗口规则须随框架参数化后再开放远程下发
|
|
2413
|
-
if (e.mode !== 'flat' || !e.price || typeof e.price !== 'object') continue;
|
|
2414
2423
|
if (e.currency !== 'CNY' && e.currency !== 'USD') continue; // 白名单币种
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
if (
|
|
2420
|
-
|
|
2421
|
-
|
|
2424
|
+
if (e.mode === 'flat') {
|
|
2425
|
+
const price = sanitizePriceLeg(e.price);
|
|
2426
|
+
if (!price) continue;
|
|
2427
|
+
entries[key] = { currency: e.currency, mode: 'flat', price: price };
|
|
2428
|
+
} else if (e.mode === 'peak-valley') {
|
|
2429
|
+
// v2(issue #317 第二阶段):分时价开放远程下发。峰谷窗口规则(何时算高峰)
|
|
2430
|
+
// 仍在 accounting.js(currentPeriod)框架级统一,不随条目下发;条目只带两档数字,
|
|
2431
|
+
// 每档都过同一组护栏,且空闲档三价均不得高于高峰档(官方口径:空闲价 = 高峰价一半)。
|
|
2432
|
+
const peak = sanitizePriceLeg(e.peak);
|
|
2433
|
+
const offpeak = sanitizePriceLeg(e.offpeak);
|
|
2434
|
+
if (!peak || !offpeak) continue;
|
|
2435
|
+
if (offpeak.inputCacheHit > peak.inputCacheHit || offpeak.inputCacheMiss > peak.inputCacheMiss
|
|
2436
|
+
|| offpeak.output > peak.output) continue;
|
|
2437
|
+
entries[key] = { currency: e.currency, mode: 'peak-valley', peak: peak, offpeak: offpeak };
|
|
2438
|
+
}
|
|
2439
|
+
// 其他 mode 一律拒收
|
|
2422
2440
|
}
|
|
2423
2441
|
return Object.keys(entries).length > 0 ? entries : null;
|
|
2424
2442
|
}
|
|
@@ -4663,7 +4681,17 @@ export default {
|
|
|
4663
4681
|
// 单调时间戳由账本 worker 在写入时保证(同毫秒并发也不会串会话),主线程不再查 lastTs。
|
|
4664
4682
|
// Freeze the actual price at usage time. Historical totals must not
|
|
4665
4683
|
// change merely because the plugin's reference price table is updated.
|
|
4666
|
-
|
|
4684
|
+
// 第二阶段(issue #317):DeepSeek 账户结算币种跟余额快照走——美元账户的调用
|
|
4685
|
+
// 按官方美元价目计价(deepseek-usd: 作用域),人民币账户沿用人民币价目;
|
|
4686
|
+
// 快照未就绪(启动初期)或该 provider 无余额概念时回退既有行为(模型价目币种),绝不猜测。
|
|
4687
|
+
// 余额键走 balanceProviderKey(deepseek-official 与 deepseek 共用 deepseek 余额),
|
|
4688
|
+
// 不直接拿 provider 当键。
|
|
4689
|
+
const balanceKey = balanceProviderKey(rec.provider);
|
|
4690
|
+
const balanceSnap = balanceKey ? balances[balanceKey] : null;
|
|
4691
|
+
const accountCurrency = balanceSnap && balanceSnap.data
|
|
4692
|
+
&& (balanceSnap.data.currency === 'USD' || balanceSnap.data.currency === 'CNY')
|
|
4693
|
+
? balanceSnap.data.currency : null;
|
|
4694
|
+
const billed = costOf(rec, false, accountCurrency);
|
|
4667
4695
|
// ① 聚合商在 usage 中直接给出的真实金额(如 OpenRouter 的 usage.cost)——
|
|
4668
4696
|
// 官方报出的钱优先级最高,聚合商场景从此免维护静态价目表;
|
|
4669
4697
|
// ② 价目表换算(当前各家官方单价);③ 都没有 → unpriced 待启动回填。
|
|
@@ -4672,11 +4700,11 @@ export default {
|
|
|
4672
4700
|
rec.cost = reportedCost;
|
|
4673
4701
|
rec.currency = Object.hasOwn(PROVIDER_REPORTED_CURRENCY, rec.provider)
|
|
4674
4702
|
? PROVIDER_REPORTED_CURRENCY[rec.provider]
|
|
4675
|
-
: modelCurrency(rec.provider, rec.model);
|
|
4703
|
+
: modelCurrency(rec.provider, rec.model, accountCurrency);
|
|
4676
4704
|
rec.pricingStatus = 'priced';
|
|
4677
4705
|
rec.pricingVersion = 'provider-reported-' + packageVersion();
|
|
4678
4706
|
} else if (billed != null) {
|
|
4679
|
-
rec.currency = modelCurrency(rec.provider, rec.model);
|
|
4707
|
+
rec.currency = modelCurrency(rec.provider, rec.model, accountCurrency);
|
|
4680
4708
|
rec.cost = billed;
|
|
4681
4709
|
rec.pricingStatus = 'priced';
|
|
4682
4710
|
rec.pricingVersion = 'builtin-' + packageVersion();
|