@angelyeye/dsh-cost-tracker 1.9.1 → 1.9.3
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 +119 -0
- package/README.en.md +60 -8
- package/README.md +65 -18
- package/client.js +202 -47
- package/config.js +10 -3
- package/index.js +42 -15
- package/package.json +2 -2
- package/pricing.js +181 -53
- package/sync.js +1 -1
- package/vendor-catalog.js +1 -1
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { readFileSync, writeFileSync, mkdirSync, renameSync, existsSync, realpat
|
|
|
10
10
|
import { join, dirname } from 'node:path'
|
|
11
11
|
import { homedir } from 'node:os'
|
|
12
12
|
import { createStore, collectTotals, DETAIL_DAYS, MAX_AXIS_DAYS } from './store.js'
|
|
13
|
-
import { PRICE_ERAS, V41_EFFECTIVE_AT,
|
|
13
|
+
import { PRICE_ERAS, V41_EFFECTIVE_AT, exactModelsAt, eraAt, SUBSCRIPTION_RATES, PROVIDER_RATES, GENERIC_RATES, PEAK_WINDOWS, PEAK_HOUR_WINDOWS, isPeak, peakPhaseAt, priceFor, computeCost, normalizeTokens, subscriptionPlanFor, volcenginePlanModels, VOLCENGINE_PLAN_PROVIDER_KEYS, VOLCENGINE_PLAN_RATES, setSyncedEras, getSyncedEras, setPriceOverrides, getPriceOverrides, setPeakHolidays, getPeakHolidays } from './pricing.js'
|
|
14
14
|
import {
|
|
15
15
|
normalizePeakConfig, defaultPeakConfig, peakEffective,
|
|
16
16
|
normalizeCloudConfig, defaultCloudConfig, normalizePluginConfig,
|
|
@@ -33,12 +33,14 @@ import { createCredSeam, migrateLegacySecrets, safeFetch, CRED_REFS, hostnameOf
|
|
|
33
33
|
import { listSessionLogs, planAndBuildImports, loadManifest, IMPORT_SOURCE } from './import.js'
|
|
34
34
|
|
|
35
35
|
/** 插件版本(写入上报信封,便于云端排查版本差异) */
|
|
36
|
-
const PLUGIN_VERSION = '1.9.
|
|
36
|
+
const PLUGIN_VERSION = '1.9.3'
|
|
37
37
|
setPluginVersion(PLUGIN_VERSION)
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
* v1.9.0
|
|
41
|
-
*
|
|
39
|
+
/** 配置面板可写的字段(与 settings 命名空间一致)。
|
|
40
|
+
* v1.9.0 起配置面板承载**全部**设置(峰谷/订阅/计费/目录/导入/同步/界面显示);
|
|
41
|
+
* v1.9.3 起入口内迁到「设置 → 花费统计 → 右上角齿轮」(旧宿主仍可用
|
|
42
|
+
* 「设置 → 插件 → 插件配置」卡片,两处同一组件),这里声明的是字段全集;
|
|
43
|
+
* 密钥类字段 role('secret') 只进凭据库。 */
|
|
42
44
|
const SyncSchema = Schema.object({
|
|
43
45
|
deviceName: Schema.string().default(undefined).description('本机在看板上显示的名字'),
|
|
44
46
|
cloudEnabled: Schema.boolean().default(undefined).description('启用云端同步'),
|
|
@@ -63,6 +65,7 @@ const SyncSchema = Schema.object({
|
|
|
63
65
|
peakAlertTarget: Schema.string().default(undefined).description('提醒类型:both / peak / offpeak'),
|
|
64
66
|
peakAlertPosition: Schema.string().default(undefined).description('弹窗位置:corner / center'),
|
|
65
67
|
peakAlertWebNotify: Schema.boolean().default(undefined).description('同步发送浏览器系统通知'),
|
|
68
|
+
peakHolidays: Schema.string().default(undefined).description('中国法定节假日列表(空=内置表;none=停用;否则 "YYYY-MM-DD" 逗号/空白分隔)'),
|
|
66
69
|
// 双轨计费 + 价格目录(v1.9.0)
|
|
67
70
|
showTotalWithPlan: Schema.boolean().default(undefined).description('金额含 Plan 等值总额(关闭只算按量)'),
|
|
68
71
|
priceMatch: Schema.string().default(undefined).description('目录匹配模式:fuzzy / exact'),
|
|
@@ -271,8 +274,8 @@ export default {
|
|
|
271
274
|
// ---------- plugin config(峰谷计价 + 云端同步) ----------
|
|
272
275
|
// 与记录分开存储:$DSH_HOME/storages/cost-tracker-config.json。
|
|
273
276
|
// 提供读写与校验(默认值见 config.js),写失败不阻断(下次改设置重试)。
|
|
274
|
-
// 若部署里存在 @deepseek-ai/dsh-settings
|
|
275
|
-
// `cost-tracker`
|
|
277
|
+
// 若部署里存在 @deepseek-ai/dsh-settings(旧宿主;0.1.7 起该服务已无 installSection),
|
|
278
|
+
// 另外注册一个 `cost-tracker` 命名空间:旧宿主设置面里改的字段
|
|
276
279
|
// 通过 settings/updated 回灌到本文件,保证两个入口读写同一份配置。
|
|
277
280
|
const CONFIG_FILE = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'storages', 'cost-tracker-config.json')
|
|
278
281
|
/** 官方价格同步产物(同步时代 + 最近核对结果),与配置/账本分开存 */
|
|
@@ -304,6 +307,8 @@ export default {
|
|
|
304
307
|
} catch (e) {
|
|
305
308
|
if (!configLoadWarned) { console.error('cost tracker config load failed, using defaults', e); configLoadWarned = true }
|
|
306
309
|
}
|
|
310
|
+
// 峰谷口径依赖节假日表:配置载入后立刻注入定价层(否则首个调用会按内置表判定)
|
|
311
|
+
applyPeakRuntime()
|
|
307
312
|
}
|
|
308
313
|
|
|
309
314
|
function saveConfig() {
|
|
@@ -319,8 +324,18 @@ export default {
|
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
|
|
327
|
+
/**
|
|
328
|
+
* 把峰谷配置里的法定节假日列表注入定价层。
|
|
329
|
+
* 官方口径把「中国法定节假日」全天计入空闲时段,因此 isPeak / peakPhaseAt 必须
|
|
330
|
+
* 拿到用户配置——记账(recordUsage 判峰谷)、时段条相位、切换提醒共用同一份。
|
|
331
|
+
*/
|
|
332
|
+
function applyPeakRuntime() {
|
|
333
|
+
setPeakHolidays(peakConfig.peakHolidays)
|
|
334
|
+
}
|
|
335
|
+
|
|
322
336
|
function setPeakConfig(raw) {
|
|
323
337
|
peakConfig = normalizePeakConfig(Object.assign({}, peakConfig, raw))
|
|
338
|
+
applyPeakRuntime()
|
|
324
339
|
saveConfig()
|
|
325
340
|
return peakConfig
|
|
326
341
|
}
|
|
@@ -470,7 +485,7 @@ export default {
|
|
|
470
485
|
applyGroup(() => cloudConfig, (p) => { cloudConfig = normalizeCloudConfig(Object.assign({}, cloudConfig, p)) }, cloudPatch)
|
|
471
486
|
applyGroup(() => uiConfig, (p) => { uiConfig = normalizeUiConfig(Object.assign({}, uiConfig, p)) }, uiPatch)
|
|
472
487
|
applyGroup(() => volcengineConfig, (p) => { volcengineConfig = normalizeVolcengineConfig(Object.assign({}, volcengineConfig, p)) }, volcPatch)
|
|
473
|
-
applyGroup(() => peakConfig, (p) => { peakConfig = normalizePeakConfig(Object.assign({}, peakConfig, p)) }, peakPatch)
|
|
488
|
+
applyGroup(() => peakConfig, (p) => { peakConfig = normalizePeakConfig(Object.assign({}, peakConfig, p)); applyPeakRuntime() }, peakPatch)
|
|
474
489
|
applyGroup(() => billingConfig, (p) => { billingConfig = normalizeBillingConfig(Object.assign({}, billingConfig, p)); applyPricingRuntime() }, billingPatch)
|
|
475
490
|
applyGroup(() => importConfig, (p) => { importConfig = normalizeImportConfig(Object.assign({}, importConfig, p)) }, importPatch)
|
|
476
491
|
applyGroup(() => priceSyncConfig, (p) => { priceSyncConfig = normalizePriceSyncConfig(Object.assign({}, priceSyncConfig, p)) }, priceSyncPatch)
|
|
@@ -528,6 +543,8 @@ export default {
|
|
|
528
543
|
phase,
|
|
529
544
|
peakWindows: PEAK_WINDOWS,
|
|
530
545
|
peakHours: PEAK_HOUR_WINDOWS,
|
|
546
|
+
// 法定节假日(官方把节假日全天计入空闲时段):回显来源与条数,供配置卡展示
|
|
547
|
+
holidays: getPeakHolidays(peakConfig.peakHolidays),
|
|
531
548
|
effectiveAt: peakConfig.peakEffectiveAt,
|
|
532
549
|
// 前端显隐开关(只影响渲染;与峰谷计价本身无关,因此不参与 enabled/effective 判定)
|
|
533
550
|
ui: Object.assign({}, uiConfig),
|
|
@@ -1099,7 +1116,8 @@ export default {
|
|
|
1099
1116
|
// 全部价格时代(含生效时刻与路由规则),供工具/接口展示
|
|
1100
1117
|
eras: PRICE_ERAS.map((e) => ({ id: e.id, label: e.label, since: e.since, models: e.models, routes: e.routes || {} })),
|
|
1101
1118
|
v41EffectiveAt: V41_EFFECTIVE_AT,
|
|
1102
|
-
|
|
1119
|
+
// 法定节假日(影响峰谷判定;官方口径:节假日全天闲时)
|
|
1120
|
+
peakHolidays: getPeakHolidays(peakConfig.peakHolidays),
|
|
1103
1121
|
subscription: SUBSCRIPTION_RATES,
|
|
1104
1122
|
// 火山方舟 Coding Plan 订阅:套餐内模型清单(等效参考价,非真实扣费)
|
|
1105
1123
|
volcenginePlan: {
|
|
@@ -1782,7 +1800,7 @@ export default {
|
|
|
1782
1800
|
// 令牌在凭据库(v1.9.0 起配置文件不落明文);此处只做「有没有配置」的快速判定,
|
|
1783
1801
|
// 真正取值在下方 resolveCloudToken()(异步,凭据服务可能晚于本插件注册)
|
|
1784
1802
|
if (!cloudConfig.cloudEnabled || !cloudConfig.cloudUrl) {
|
|
1785
|
-
return { ok: false, error: '云端同步未配置(在「设置 →
|
|
1803
|
+
return { ok: false, error: '云端同步未配置(在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」填写服务地址与令牌)', code: 'NOT_CONFIGURED' }
|
|
1786
1804
|
}
|
|
1787
1805
|
const key = JSON.stringify(query)
|
|
1788
1806
|
const hit = cloudCache.get(key)
|
|
@@ -2035,7 +2053,13 @@ export default {
|
|
|
2035
2053
|
}
|
|
2036
2054
|
lines.push('', '当前生效:' + v.eraLabel + '(era=' + v.era + ')')
|
|
2037
2055
|
lines.push('模型名口径:官方现役名为 deepseek-flash(被路由的请求一律以此名入账);deepseek-v4.1-flash 等写法归一化后命中同一档。')
|
|
2038
|
-
lines.push('V4-Pro
|
|
2056
|
+
lines.push('deepseek-v4-pro 维持 V4-Pro 自有牌价 9/27/0.30(官方 2026-09-14 撤销了「路由到 V4.1 Flash」的下线计划),不做路由。')
|
|
2057
|
+
if (v.peakHolidays) {
|
|
2058
|
+
lines.push('法定节假日(全天闲时):' + (v.peakHolidays.disabled
|
|
2059
|
+
? '已停用(仅按周末判定)'
|
|
2060
|
+
: (v.peakHolidays.count || 0) + ' 天' + (v.peakHolidays.builtin ? '(内置表)' : '(自定义)')
|
|
2061
|
+
+ (v.peakHolidays.invalid && v.peakHolidays.invalid.length ? ',忽略无法识别:' + v.peakHolidays.invalid.join(' ') : '')))
|
|
2062
|
+
}
|
|
2039
2063
|
lines.push('视觉模型 deepseek-v4-flash-vision-exp:图片按官方规则换算 token(每张上限 384),以接口用量计费(已含在 inputTokens 内)。')
|
|
2040
2064
|
lines.push('kimi-coding(订阅等效,估算):输入 6.5 / 缓存命中(含缓存写入)1.1 / 输出 27.0')
|
|
2041
2065
|
lines.push('缓存写入(cache write)按缓存命中价计费,与官方规则一致。其他 provider 兜底为估算平价(openai 10/30/5,anthropic 15/75/1.5,gemini 2.5/10/0.625,未知 2/8/0.5);ollama/local 为 0。')
|
|
@@ -2117,7 +2141,7 @@ export default {
|
|
|
2117
2141
|
|
|
2118
2142
|
ctx.tools.register({
|
|
2119
2143
|
name: 'cost_peak',
|
|
2120
|
-
description: '查询当前 DeepSeek 峰谷计价档位与下次切换倒计时(北京时间:高峰时段为周一至周五 9:00-12:00、14:00-18:00
|
|
2144
|
+
description: '查询当前 DeepSeek 峰谷计价档位与下次切换倒计时(北京时间:高峰时段为周一至周五 9:00-12:00、14:00-18:00,且不含中国法定节假日;其余时段含周末与法定节假日全天均为闲时)。',
|
|
2121
2145
|
parameters: {
|
|
2122
2146
|
type: 'object',
|
|
2123
2147
|
properties: {},
|
|
@@ -2127,7 +2151,8 @@ export default {
|
|
|
2127
2151
|
schema: { type: 'object', additionalProperties: true },
|
|
2128
2152
|
render: (args, v) => {
|
|
2129
2153
|
const p = v.phase
|
|
2130
|
-
const
|
|
2154
|
+
const offLabel = p && p.allDayOff ? (p.holiday ? '法定节假日全天闲时(全谷价)' : '周末全天闲时(全谷价)') : ''
|
|
2155
|
+
const phaseText = !p ? '未知' : p.allDayOff ? offLabel : p.inPeak ? '高峰时段(按峰时价)' : '闲时时段(按谷时价)'
|
|
2131
2156
|
const nextText = p ? new Date(p.nextAtMs + 28800000).toISOString().replace('T', ' ').slice(0, 16).replace(/-/g, '/') + ' 转' + (p.nextIntoPeak ? '峰' : '谷') : '未知'
|
|
2132
2157
|
return [{ type: 'text', text: '峰谷计价:' + (v.enabled ? '已启用' : '已停用') + '(' + v.peakWindows + ')\n当前档位:' + phaseText + '\n下次切换:' + nextText + (v.effective ? '' : '(峰谷未生效,按平价计费)') }]
|
|
2133
2158
|
},
|
|
@@ -2234,7 +2259,7 @@ export default {
|
|
|
2234
2259
|
'待上报:' + st.pending + ' 条 · 已上报水位 seq=' + st.watermark + ' · 日汇总已同步 ' + st.rollupsSent + ' 项',
|
|
2235
2260
|
]
|
|
2236
2261
|
if (st.lastError) lines.push('最近错误:' + st.lastError + (st.backoffMs ? '(退避 ' + Math.round(st.backoffMs / 1000) + 's)' : ''))
|
|
2237
|
-
if (st.needAuth) lines.push('⚠ 令牌无效:请在「设置 →
|
|
2262
|
+
if (st.needAuth) lines.push('⚠ 令牌无效:请在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」更新共享引导令牌')
|
|
2238
2263
|
if (v.action === 'now' && v.result) {
|
|
2239
2264
|
lines.push('本次同步:新增 ' + (v.result.accepted || 0) + ' 条 · 去重 ' + (v.result.duplicates || 0) + ' 条 · 日汇总 ' + (v.result.rollups || 0) + ' 项' + (v.result.error ? ' · 失败:' + v.result.error : ''))
|
|
2240
2265
|
}
|
|
@@ -2297,7 +2322,9 @@ export default {
|
|
|
2297
2322
|
if (!settingsOk) {
|
|
2298
2323
|
// settings 是可选服务(宿主未组合时不报错、不阻断启动),但不能像 1.8.0 那样只探一次:
|
|
2299
2324
|
// 它晚于本插件就绪时,那一次 ctx.get('settings') 必然落空 → 命名空间永不注册 →
|
|
2300
|
-
//
|
|
2325
|
+
// 旧宿主的「设置 → 插件 → 插件配置」里永远没有本插件的卡片。
|
|
2326
|
+
// (0.1.7-alpha.2 起宿主已移除 settings.installSection 与插件配置插槽,本路径自然 inert;
|
|
2327
|
+
// 配置入口改由客户端「设置 → 花费统计 → 右上角齿轮」承担,见 client.js 的 CostSection。)
|
|
2301
2328
|
// 与 dsh-context 的 installSettings 同款写法:ctx.inject 等它就绪后再装,始终缺席则自然 inert。
|
|
2302
2329
|
try {
|
|
2303
2330
|
ctx.inject(['settings'], (sctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angelyeye/dsh-cost-tracker",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) plugin: LLM token usage & cost tracking with a settings dashboard, agent tools, HTTP API, persistent storage, multi-device cloud sync, session-log history import, official price sync and a multi-vendor price catalog.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"test": "node test/storage.test.js && node test/pricing.test.js && node test/volcengine-plan.test.js && node test/volcengine-host.test.js && node test/config.test.js && node test/recompute.test.js && node test/credstore.test.js && node test/vendor-catalog.test.js && node test/price-sync.test.js && node test/import.test.js && node test/client-registration.test.js && node test/ui-display.test.js && node test/client-render.test.js && node test/cloud-read.test.js && node --no-warnings test/cloud-view-e2e.test.js && node test/sync.test.js && node test/view.test.js"
|
|
36
|
+
"test": "node test/storage.test.js && node test/pricing.test.js && node test/peak-holidays.test.js && node test/volcengine-plan.test.js && node test/volcengine-host.test.js && node test/config.test.js && node test/recompute.test.js && node test/credstore.test.js && node test/vendor-catalog.test.js && node test/price-sync.test.js && node test/import.test.js && node test/client-registration.test.js && node test/ui-display.test.js && node test/client-render.test.js && node test/cloud-read.test.js && node --no-warnings test/cloud-view-e2e.test.js && node test/sync.test.js && node test/view.test.js"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"dsh-plugin",
|
package/pricing.js
CHANGED
|
@@ -3,18 +3,26 @@
|
|
|
3
3
|
//
|
|
4
4
|
// 单价来源:DeepSeek 官方定价页
|
|
5
5
|
// https://api-docs.deepseek.com/zh-cn/quick_start/pricing
|
|
6
|
-
// - 高峰时段(北京时间周一至周五 9:00-12:00、14:00-18:00
|
|
7
|
-
//
|
|
6
|
+
// - 高峰时段(北京时间周一至周五 9:00-12:00、14:00-18:00,**不含中国法定节假日**)
|
|
7
|
+
// 为表内价格;其余时段(含周末与法定节假日全天)= 高峰 × 0.5。
|
|
8
8
|
// - **单价随时间调整**:故单价表按生效时刻分版(见 PRICE_ERAS),按记录时间戳选版。
|
|
9
9
|
// · legacy :V4-Flash 3.0/9.0/0.10、V4-Pro 9.0/27.0/0.30
|
|
10
10
|
// · v41 :V4.1 Flash 2.0/8.0/0.04(北京时间 2026-09-10 12:00 起生效)。
|
|
11
11
|
// 官方现役模型名为 `deepseek-flash`;旧名 `deepseek-v4-flash` 与
|
|
12
12
|
// `deepseek-v4-flash-vision-exp` 已下线但仍可调用,请求由 V4.1 Flash
|
|
13
13
|
// 提供服务并按 Flash 价计费,故一并路由到 `deepseek-flash`。
|
|
14
|
-
//
|
|
15
|
-
// 12:00
|
|
16
|
-
//
|
|
17
|
-
//
|
|
14
|
+
// **V4-Pro 维持自有牌价(9.0/27.0/0.30),不做任何路由**:
|
|
15
|
+
// 09-10 新闻稿确实预告过「9-14 12:00 之后 pro 请求全部路由到 V4.1 Flash
|
|
16
|
+
// 并按 Flash 单价计费」,v1.9.0/1.9.1 据此实现了 v41pro 时代;但官方
|
|
17
|
+
// **更新日志随后改为**「为响应广大用户的需求,我们决定在 2026 年 9 月 14 日
|
|
18
|
+
// 之后继续提供 DeepSeek V4 Pro 的 API 调用服务,计费方式保持不变」,
|
|
19
|
+
// 且现行价目页仍为 pro **单列价格**(9.0/27.0/0.30)与**独立并发 500**
|
|
20
|
+
// (flash 为 2500),脚注只把旧 flash 名与 `deepseek-v4.1-flash` 路由到
|
|
21
|
+
// flash。故 v1.9.2 起**取消 pro 的反向路由**:否则会按 Flash 价计 pro 调用
|
|
22
|
+
// (输入 2 vs 9、输出 8 vs 27),显著低估。
|
|
23
|
+
// - 法定节假日(isPeak / peakPhaseAt 的 offAllDay):官方口径把节假日全天计入空闲时段,
|
|
24
|
+
// 数据来自国务院办公厅节假日安排通知(见 CN_HOLIDAYS)。调休补班的周六/周日**不**计高峰
|
|
25
|
+
// —— 定价规则只看「周一至周五」,调休不改变这一点。
|
|
18
26
|
// - deepseek-v4-flash-vision-exp 与 deepseek-v4-flash 在 legacy 时代单价一致。
|
|
19
27
|
// - 模型名归一化后 `deepseek-v4.1-flash` 等同为 `deepseek-flash` 的等价写法,命中同一档。
|
|
20
28
|
//
|
|
@@ -43,14 +51,6 @@
|
|
|
43
51
|
/** V4.1 Flash 价格的生效时刻:北京时间 2026-09-10 12:00(UTC+8)= 2026-09-10T04:00:00Z */
|
|
44
52
|
export const V41_EFFECTIVE_AT = Date.UTC(2026, 8, 10, 4, 0, 0)
|
|
45
53
|
|
|
46
|
-
/**
|
|
47
|
-
* V4-Pro 请求被路由到 V4.1 Flash 的生效时刻:北京时间 2026-09-14 12:00。
|
|
48
|
-
* 官方表述:「北京时间 2026 年 9 月 14 日 12:00 之后,至未来 V4.1 Pro 上线之前,
|
|
49
|
-
* 用户访问 deepseek-v4-pro 的请求将全部路由到 V4.1 Flash,并按 V4.1 Flash 单价计费」。
|
|
50
|
-
* 注意它与 V41_EFFECTIVE_AT(9-10 12:00)不是同一时刻,提前折算会低估 V4-Pro 花费。
|
|
51
|
-
*/
|
|
52
|
-
export const V41_PRO_ROUTE_AT = Date.UTC(2026, 8, 14, 4, 0, 0)
|
|
53
|
-
|
|
54
54
|
/**
|
|
55
55
|
* V4.1 Flash 档的规范(官方现役)模型名。
|
|
56
56
|
* 官方文档:「模型名请使用 `deepseek-flash`」——被路由的请求一律以此名入账,
|
|
@@ -72,33 +72,17 @@ export const PRICE_ERAS = [
|
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
id: 'v41',
|
|
75
|
-
label: 'V4.1 Flash 价(2026-09-10 12:00 起;V4-Pro
|
|
75
|
+
label: 'V4.1 Flash 价(2026-09-10 12:00 起;V4-Pro 维持自有牌价)',
|
|
76
76
|
since: V41_EFFECTIVE_AT,
|
|
77
77
|
models: {
|
|
78
78
|
// 高峰价:输入(缓存命中)0.04 / 输入(缓存未命中)2 / 输出 8;空闲减半
|
|
79
79
|
[V41_FLASH_MODEL]: { input: 2.0, output: 8.0, cacheRead: 0.04, cacheWrite: 0.04 },
|
|
80
|
-
// V4-Pro
|
|
81
|
-
//
|
|
80
|
+
// V4-Pro 维持自有牌价:官方 9-14 撤销了下线计划(「继续提供服务,计费方式保持不变」),
|
|
81
|
+
// 现行价目页仍为其单列 9.0/27.0/0.30 与独立并发 500 —— 因此**不做路由**。
|
|
82
82
|
'deepseek-v4-pro': { input: 9.0, output: 27.0, cacheRead: 0.30, cacheWrite: 0.30 },
|
|
83
83
|
},
|
|
84
84
|
// 旧 V4-Flash 系(含视觉版)已下线,请求由 V4.1 Flash 提供并按 Flash 价计费。
|
|
85
|
-
// V4-Pro 此时尚未路由(官方路由时刻为 9-14 12:00,见下一个时代)。
|
|
86
|
-
routes: {
|
|
87
|
-
'deepseek-v4-flash': V41_FLASH_MODEL,
|
|
88
|
-
'deepseek-v4-flash-vision-exp': V41_FLASH_MODEL,
|
|
89
|
-
},
|
|
90
|
-
proRouteSince: V41_PRO_ROUTE_AT,
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
id: 'v41pro',
|
|
94
|
-
label: 'V4.1 Flash 价 + V4-Pro 路由(2026-09-14 12:00 起)',
|
|
95
|
-
since: V41_PRO_ROUTE_AT,
|
|
96
|
-
models: {
|
|
97
|
-
[V41_FLASH_MODEL]: { input: 2.0, output: 8.0, cacheRead: 0.04, cacheWrite: 0.04 },
|
|
98
|
-
},
|
|
99
|
-
// V4.1 Pro 上线前,V4-Pro 的请求全部路由到 V4.1 Flash 并按 V4.1 Flash 单价计费。
|
|
100
85
|
routes: {
|
|
101
|
-
'deepseek-v4-pro': V41_FLASH_MODEL,
|
|
102
86
|
'deepseek-v4-flash': V41_FLASH_MODEL,
|
|
103
87
|
'deepseek-v4-flash-vision-exp': V41_FLASH_MODEL,
|
|
104
88
|
},
|
|
@@ -187,7 +171,7 @@ export function setSyncedEras(eras) {
|
|
|
187
171
|
/** 当前注入的同步时代(只读副本,供状态回显) */
|
|
188
172
|
export function getSyncedEras() { return SYNCED_ERAS.slice() }
|
|
189
173
|
|
|
190
|
-
// ---------- 手动覆盖价(v1.9.0
|
|
174
|
+
// ---------- 手动覆盖价(v1.9.0,配置面板维护) ----------
|
|
191
175
|
let PRICE_OVERRIDES = new Map()
|
|
192
176
|
function overrideKey(np, model) {
|
|
193
177
|
return normalizeModelName(np) + '/' + normalizeModelName(model)
|
|
@@ -403,8 +387,8 @@ export const PROVIDER_RATES = {
|
|
|
403
387
|
/** 未知模型兜底单价(估算);缓存写入按缓存命中价计。 */
|
|
404
388
|
export const GENERIC_RATES = { input: 2.0, output: 8.0, cacheRead: 0.5, cacheWrite: 0.5 }
|
|
405
389
|
|
|
406
|
-
/**
|
|
407
|
-
export const PEAK_WINDOWS = '周一至周五 9:00-12:00 · 14:00-18:00
|
|
390
|
+
/** 高峰时段(北京时间,仅周一至周五且非法定节假日),空闲时段 = 高峰 × 0.5 */
|
|
391
|
+
export const PEAK_WINDOWS = '周一至周五 9:00-12:00 · 14:00-18:00(周末与法定节假日全天闲时)'
|
|
408
392
|
|
|
409
393
|
/** 视觉模型名(DeepSeek DeepSeek-V4-Flash-Vision-Exp) */
|
|
410
394
|
export const VISION_MODEL = 'deepseek-v4-flash-vision-exp'
|
|
@@ -412,11 +396,133 @@ export const VISION_MODEL = 'deepseek-v4-flash-vision-exp'
|
|
|
412
396
|
/** 每张图片换算 token 的上限(官方规则) */
|
|
413
397
|
export const VISION_IMAGE_MAX_TOKENS = 384
|
|
414
398
|
|
|
415
|
-
|
|
399
|
+
// ------------------------------------------------------------
|
|
400
|
+
// 中国法定节假日(官方峰谷口径:节假日全天计入空闲时段)
|
|
401
|
+
//
|
|
402
|
+
// 官方价目页脚注:「北京时间周一至周五(**不含中国法定节假日**)9:00-12:00、
|
|
403
|
+
// 14:00-18:00 为高峰时段;其余时段,包括周末及中国法定节假日全天均为空闲时段。」
|
|
404
|
+
// 因此仅排除周末是不够的:节假日落在一周内时,峰段也必须按闲时计(否则会多计 1 倍)。
|
|
405
|
+
//
|
|
406
|
+
// 数据来源:国务院办公厅关于节假日安排的通知。
|
|
407
|
+
// · 2026 年:国办发明电〔2025〕7 号(2025-11-04 发布)
|
|
408
|
+
// https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm
|
|
409
|
+
// 调休补班的周六/周日**不计高峰**:定价规则只看「周一至周五」,调休不改变这一点。
|
|
410
|
+
// 新一年度的安排通常在上一年 11 月公布,届时更新本表并随版本发布;也可在配置面板
|
|
411
|
+
// 用 `peakHolidays` 覆盖(见 setPeakHolidays)。
|
|
412
|
+
// ------------------------------------------------------------
|
|
413
|
+
export const CN_HOLIDAYS = [
|
|
414
|
+
// 2026 · 元旦 1/1-1/3
|
|
415
|
+
'2026-01-01', '2026-01-02', '2026-01-03',
|
|
416
|
+
// 2026 · 春节 2/15-2/23
|
|
417
|
+
'2026-02-15', '2026-02-16', '2026-02-17', '2026-02-18', '2026-02-19',
|
|
418
|
+
'2026-02-20', '2026-02-21', '2026-02-22', '2026-02-23',
|
|
419
|
+
// 2026 · 清明 4/4-4/6
|
|
420
|
+
'2026-04-04', '2026-04-05', '2026-04-06',
|
|
421
|
+
// 2026 · 劳动节 5/1-5/5
|
|
422
|
+
'2026-05-01', '2026-05-02', '2026-05-03', '2026-05-04', '2026-05-05',
|
|
423
|
+
// 2026 · 端午 6/19-6/21
|
|
424
|
+
'2026-06-19', '2026-06-20', '2026-06-21',
|
|
425
|
+
// 2026 · 中秋 9/25-9/27
|
|
426
|
+
'2026-09-25', '2026-09-26', '2026-09-27',
|
|
427
|
+
// 2026 · 国庆 10/1-10/7
|
|
428
|
+
'2026-10-01', '2026-10-02', '2026-10-03', '2026-10-04',
|
|
429
|
+
'2026-10-05', '2026-10-06', '2026-10-07',
|
|
430
|
+
]
|
|
431
|
+
|
|
432
|
+
/** 把 'YYYY-MM-DD' / 'YYYY/M/D' 归一为 'YYYY-MM-DD';非法返回 '' */
|
|
433
|
+
function normHolidayKey(s) {
|
|
434
|
+
const m = /^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/.exec(String(s == null ? '' : s).trim())
|
|
435
|
+
if (!m) return ''
|
|
436
|
+
const mm = Number(m[2])
|
|
437
|
+
const dd = Number(m[3])
|
|
438
|
+
if (!(mm >= 1 && mm <= 12) || !(dd >= 1 && dd <= 31)) return ''
|
|
439
|
+
return m[1] + '-' + (mm < 10 ? '0' + mm : String(mm)) + '-' + (dd < 10 ? '0' + dd : String(dd))
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** 归一化节假日列表:接受数组或「逗号/分号/空白分隔」的整串,去重并升序 */
|
|
443
|
+
export function normalizeHolidayList(input) {
|
|
444
|
+
const out = []
|
|
445
|
+
if (Array.isArray(input)) {
|
|
446
|
+
for (const s of input) { const k = normHolidayKey(s); if (k) out.push(k) }
|
|
447
|
+
} else if (typeof input === 'string') {
|
|
448
|
+
for (const s of input.split(/[\s,,;;]+/)) { const k = normHolidayKey(s); if (k) out.push(k) }
|
|
449
|
+
}
|
|
450
|
+
return Array.from(new Set(out)).sort()
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// null = 使用内置表 CN_HOLIDAYS;[] = 显式停用(不排除任何节假日);否则为用户覆盖列表
|
|
454
|
+
let PEAK_HOLIDAY_LIST = null
|
|
455
|
+
let PEAK_HOLIDAY_SET = null // Set<string>(null 时按需从 CN_HOLIDAYS 构建)
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* 覆盖法定节假日列表(配置面板的「峰谷计价与提示」)。语义防呆:
|
|
459
|
+
* · 传 null / undefined / '' → 恢复内置表(默认);config 里存空串即走这条;
|
|
460
|
+
* · 传 'none' / 'off' / '0' → 显式停用(不排除任何节假日,等价于按「仅周末」计);
|
|
461
|
+
* · 传数组或分隔字符串 → 用该列表**整体替换**内置表(不追加);
|
|
462
|
+
* · 传了内容但一条都解析不出 → 视为停用并记入 invalid,如实回显,
|
|
463
|
+
* 避免「以为关掉了节假日,其实还在用内置表」。
|
|
464
|
+
* @returns {{dates:string[], mode:'builtin'|'custom'|'disabled', builtin:boolean, disabled:boolean, count:number, invalid:string[]}}
|
|
465
|
+
*/
|
|
466
|
+
export function setPeakHolidays(input) {
|
|
467
|
+
if (Array.isArray(input)) {
|
|
468
|
+
PEAK_HOLIDAY_LIST = normalizeHolidayList(input)
|
|
469
|
+
} else if (input === null || input === undefined) {
|
|
470
|
+
PEAK_HOLIDAY_LIST = null
|
|
471
|
+
} else {
|
|
472
|
+
const raw = String(input).trim()
|
|
473
|
+
if (raw === '') PEAK_HOLIDAY_LIST = null
|
|
474
|
+
else if (/^(none|off|0|无|关|关闭)$/i.test(raw)) PEAK_HOLIDAY_LIST = []
|
|
475
|
+
else PEAK_HOLIDAY_LIST = normalizeHolidayList(raw)
|
|
476
|
+
}
|
|
477
|
+
PEAK_HOLIDAY_SET = null
|
|
478
|
+
return getPeakHolidays(typeof input === 'string' ? input : undefined)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* 当前生效的节假日列表(含来源标记,便于配置卡回显与双端比对)。
|
|
483
|
+
* @param {string} [rawInput] - 可选:原始配置字符串(用于统计被忽略的非法条目)
|
|
484
|
+
*/
|
|
485
|
+
export function getPeakHolidays(rawInput) {
|
|
486
|
+
const list = PEAK_HOLIDAY_LIST === null ? CN_HOLIDAYS : PEAK_HOLIDAY_LIST
|
|
487
|
+
const invalid = []
|
|
488
|
+
if (typeof rawInput === 'string' && rawInput.trim() !== '' && !/^(none|off|0|无|关|关闭)$/i.test(rawInput.trim())) {
|
|
489
|
+
for (const tok of rawInput.split(/[\s,,;;]+/)) {
|
|
490
|
+
if (tok && !normHolidayKey(tok)) invalid.push(tok)
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const mode = PEAK_HOLIDAY_LIST === null ? 'builtin' : (PEAK_HOLIDAY_LIST.length === 0 ? 'disabled' : 'custom')
|
|
494
|
+
return { dates: list.slice(), mode, builtin: mode === 'builtin', disabled: mode === 'disabled', count: list.length, invalid }
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** 某时刻所属的北京日历日('YYYY-MM-DD') */
|
|
498
|
+
export function holidayKeyAt(ts) {
|
|
499
|
+
const t = Number(ts)
|
|
500
|
+
if (!Number.isFinite(t)) return ''
|
|
501
|
+
const d = new Date(t + 28800000)
|
|
502
|
+
const p = (n) => (n < 10 ? '0' + n : String(n))
|
|
503
|
+
return d.getUTCFullYear() + '-' + p(d.getUTCMonth() + 1) + '-' + p(d.getUTCDate())
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** 北京日 index(D0,北京午夜为界)→ 'YYYY-MM-DD' */
|
|
507
|
+
function holidayKeyOfDayIndex(D) {
|
|
508
|
+
return holidayKeyAt(D * 86400000 - 28800000 + 43200000) // 该北京日正午,避免边界歧义
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** 某时刻是否落在(配置生效的)中国法定节假日 */
|
|
512
|
+
export function isCnHoliday(ts) {
|
|
513
|
+
const key = holidayKeyAt(ts)
|
|
514
|
+
if (!key) return false
|
|
515
|
+
const set = PEAK_HOLIDAY_SET || (PEAK_HOLIDAY_SET = new Set(PEAK_HOLIDAY_LIST === null ? CN_HOLIDAYS : PEAK_HOLIDAY_LIST))
|
|
516
|
+
return set.has(key)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** 是否高峰时段(北京时间 UTC+8:周一至周五、非节假日、落在峰窗口内) */
|
|
416
520
|
export function isPeak(ts) {
|
|
417
|
-
const
|
|
521
|
+
const t = Number(ts)
|
|
522
|
+
const d = new Date(t + 28800000)
|
|
418
523
|
const day = d.getUTCDay() // 0=周日 … 6=周六
|
|
419
524
|
if (day === 0 || day === 6) return false // 周末不计高峰
|
|
525
|
+
if (isCnHoliday(t)) return false // 法定节假日全天闲时
|
|
420
526
|
const h = d.getUTCHours()
|
|
421
527
|
return (h >= 9 && h < 12) || (h >= 14 && h < 18)
|
|
422
528
|
}
|
|
@@ -426,31 +532,42 @@ export const PEAK_HOUR_WINDOWS = [{ start: 9, end: 12 }, { start: 14, end: 18 }]
|
|
|
426
532
|
|
|
427
533
|
/**
|
|
428
534
|
* 某一时刻所处的峰谷相位与相邻切换点(供时段条 / 倒计时 / 切换前弹窗)。
|
|
429
|
-
* 与 isPeak 同口径(北京时间 UTC+8
|
|
430
|
-
* -
|
|
431
|
-
* -
|
|
432
|
-
*
|
|
535
|
+
* 与 isPeak 同口径(北京时间 UTC+8),并处理「全天谷价日」:
|
|
536
|
+
* - 普通工作日:按峰窗口判定 inPeak,扫描前后 N 天收集切换点;
|
|
537
|
+
* - 周末 / 法定节假日:inPeak=false、allDayOff=true,日内无切换点(价格恒为谷),
|
|
538
|
+
* 下一个价格切换点为下一个「工作日且非节假日」的首个峰窗口起点;
|
|
539
|
+
* weekend / holiday 分别标记具体原因(节假日落在周末时 weekend 优先)。
|
|
433
540
|
* @param {number} ts - epoch ms
|
|
434
|
-
* @param {number} [spanDays=5] -
|
|
435
|
-
* @returns {{inPeak:boolean, weekend:boolean,
|
|
436
|
-
* nextIntoPeak:boolean}|null}
|
|
541
|
+
* @param {number} [spanDays=5] - 前后扫描天数(须覆盖最长连休:春节 9 天,故内部下限取 12)
|
|
542
|
+
* @returns {{inPeak:boolean, weekend:boolean, holiday:boolean, allDayOff:boolean,
|
|
543
|
+
* prevAtMs:number, nextAtMs:number, nextIntoPeak:boolean}|null}
|
|
544
|
+
* prevAtMs/nextAtMs 为相邻切换点 epoch ms(全天谷价日的 prevAtMs = 本段连休起点)
|
|
437
545
|
*/
|
|
438
546
|
export function peakPhaseAt(ts, spanDays) {
|
|
439
547
|
if (!Number.isFinite(ts)) return null
|
|
440
|
-
|
|
548
|
+
// 连休最长可达 9 天(春节),默认扫描窗口必须比它大,否则会找不到下一切换点。
|
|
549
|
+
const SPAN = Math.max(12, (Number.isFinite(spanDays) && spanDays >= 1) ? Math.floor(spanDays) : 5)
|
|
441
550
|
const DAY_MS = 86400000
|
|
442
551
|
// 北京时间日 index 与星期(0=周日 … 6=周六;1970-01-01 为周四)。
|
|
443
552
|
const D0 = Math.floor((ts + 28800000) / DAY_MS)
|
|
444
553
|
const weekday = (D0 + 4) % 7
|
|
445
554
|
const isWeekendNow = weekday === 6 || weekday === 0
|
|
555
|
+
const isHolidayNow = isCnHoliday(ts)
|
|
556
|
+
const allDayOffNow = isWeekendNow || isHolidayNow
|
|
446
557
|
// 某北京时间日 D 的某时 h 对应的 epoch ms(北京 = UTC+8)。
|
|
447
558
|
const atBeijing = (D, h) => D * DAY_MS - 28800000 + h * 3600000
|
|
448
|
-
//
|
|
559
|
+
// 某北京时间日 D 是否为「全天谷价日」:周末或法定节假日。
|
|
560
|
+
const dayOff = (D) => {
|
|
561
|
+
const wd = (D + 4) % 7
|
|
562
|
+
if (wd === 6 || wd === 0) return true
|
|
563
|
+
const set = PEAK_HOLIDAY_SET || (PEAK_HOLIDAY_SET = new Set(PEAK_HOLIDAY_LIST === null ? CN_HOLIDAYS : PEAK_HOLIDAY_LIST))
|
|
564
|
+
return set.has(holidayKeyOfDayIndex(D))
|
|
565
|
+
}
|
|
566
|
+
// 收集 ±SPAN 天内全部窗口边界切换点,剔除落在全天谷价日(无价格变化)的点。
|
|
449
567
|
const points = []
|
|
450
568
|
for (let off = -SPAN; off <= SPAN; off += 1) {
|
|
451
569
|
const D = D0 + off
|
|
452
|
-
|
|
453
|
-
if (wd === 6 || wd === 0) continue // 周末日内无切换
|
|
570
|
+
if (dayOff(D)) continue // 周末 / 节假日日内无切换
|
|
454
571
|
for (const w of PEAK_HOUR_WINDOWS) {
|
|
455
572
|
points.push({ at: atBeijing(D, w.start), intoPeak: true })
|
|
456
573
|
points.push({ at: atBeijing(D, w.end), intoPeak: false })
|
|
@@ -462,13 +579,24 @@ export function peakPhaseAt(ts, spanDays) {
|
|
|
462
579
|
if (p.at <= ts && (prev === null || p.at > prev.at)) prev = p
|
|
463
580
|
if (p.at > ts && (next === null || p.at < next.at)) next = p
|
|
464
581
|
}
|
|
465
|
-
if (
|
|
466
|
-
//
|
|
582
|
+
if (allDayOffNow) {
|
|
583
|
+
// 全天谷价:当前谷,下一切换 = 下一个非谷价日的首个峰窗口起点;
|
|
584
|
+
// prev = 本段连休起点(北京时间 00:00),便于「本段已持续多久」类展示。
|
|
467
585
|
if (next === null) return null
|
|
468
|
-
|
|
586
|
+
let start = D0
|
|
587
|
+
for (let i = 0; i < SPAN && dayOff(start - 1); i += 1) start -= 1
|
|
588
|
+
return {
|
|
589
|
+
inPeak: false,
|
|
590
|
+
weekend: isWeekendNow,
|
|
591
|
+
holiday: isHolidayNow && !isWeekendNow,
|
|
592
|
+
allDayOff: true,
|
|
593
|
+
prevAtMs: start * DAY_MS - 28800000,
|
|
594
|
+
nextAtMs: next.at,
|
|
595
|
+
nextIntoPeak: next.intoPeak,
|
|
596
|
+
}
|
|
469
597
|
}
|
|
470
598
|
if (prev === null || next === null) return null
|
|
471
|
-
return { inPeak: isPeak(ts), weekend: false, prevAtMs: prev.at, nextAtMs: next.at, nextIntoPeak: next.intoPeak }
|
|
599
|
+
return { inPeak: isPeak(ts), weekend: false, holiday: false, allDayOff: false, prevAtMs: prev.at, nextAtMs: next.at, nextIntoPeak: next.intoPeak }
|
|
472
600
|
}
|
|
473
601
|
|
|
474
602
|
/**
|
package/sync.js
CHANGED
|
@@ -240,7 +240,7 @@ function classifyStatus(status, body) {
|
|
|
240
240
|
if (status === 200 && body && body.ok) return { ok: true }
|
|
241
241
|
const code = (body && body.code) || ''
|
|
242
242
|
if (status === 401 || code === 'TOKEN_INVALID' || code === 'TOKEN_MISSING') {
|
|
243
|
-
return { ok: false, code: 'TOKEN_INVALID', needAuth: true, message: '
|
|
243
|
+
return { ok: false, code: 'TOKEN_INVALID', needAuth: true, message: '云端令牌无效,请在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」更新' }
|
|
244
244
|
}
|
|
245
245
|
if (status === 403) {
|
|
246
246
|
return { ok: false, code, needAuth: false, message: (body && body.error) || '云端拒绝:设备被禁用或未开启自注册' }
|
package/vendor-catalog.js
CHANGED