@angelyeye/dsh-cost-tracker 1.9.5 → 1.10.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/CHANGELOG.md +103 -0
- package/README.en.md +58 -3
- package/README.md +56 -6
- package/account.js +222 -0
- package/client.js +72 -12
- package/docs/THIRD-PARTY-NOTICES.md +1 -1
- package/docs/provider-pricing.json +585 -91
- package/import.js +42 -6
- package/index.js +128 -43
- package/package.json +4 -2
- package/pricing.js +47 -9
- package/settings.js +95 -0
- package/vendor-catalog.js +7 -5
package/import.js
CHANGED
|
@@ -114,6 +114,45 @@ export function readSessionRecords(path) {
|
|
|
114
114
|
return records
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 会话日志文件名:`session[.vN].jsonl[.zstd]`。
|
|
119
|
+
*
|
|
120
|
+
* **不写死版本号**(v1.9.6 修):0.2.x 起宿主把新会话写成
|
|
121
|
+
* `session.v4.jsonl.zstd`,而旧实现只枚举
|
|
122
|
+
* `['session.v3.jsonl.zstd','session.v3.jsonl','session.jsonl.zstd','session.jsonl']`
|
|
123
|
+
* —— 于是 v4 及以后的新会话被**静默跳过**(导入清单里 0 个 v4、也没有任何报错,
|
|
124
|
+
* 表现为「历史导入突然不再补录新会话」)。内容层其实兼容(实测 v4 日志的事件与
|
|
125
|
+
* usage/source 形状未变,回放能正常重建调用),断点只在文件名。
|
|
126
|
+
*/
|
|
127
|
+
const SESSION_LOG_NAME_RE = /^session(?:\.v(\d+))?\.jsonl(\.zstd)?$/
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 从一个会话目录里挑一份日志:版本号高者优先(v5 > v4 > v3 > 无版本号),
|
|
131
|
+
* 同版本 zstd 优先。这样宿主再升 v5/v6 时不需要再改枚举。
|
|
132
|
+
* @param {string} dir - 单个会话目录
|
|
133
|
+
* @returns {string} 命中的文件名;没有则返回空串
|
|
134
|
+
*/
|
|
135
|
+
function pickSessionLogName(dir) {
|
|
136
|
+
let entries
|
|
137
|
+
try { entries = readdirSync(dir, { withFileTypes: true }) } catch (e) { return '' }
|
|
138
|
+
let best = ''
|
|
139
|
+
let bestVersion = -1
|
|
140
|
+
let bestZstd = -1
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
if (!entry.isFile()) continue
|
|
143
|
+
const m = SESSION_LOG_NAME_RE.exec(entry.name)
|
|
144
|
+
if (!m) continue
|
|
145
|
+
const version = m[1] ? Number(m[1]) : 0
|
|
146
|
+
const zstd = m[2] ? 1 : 0
|
|
147
|
+
if (version > bestVersion || (version === bestVersion && zstd > bestZstd)) {
|
|
148
|
+
best = entry.name
|
|
149
|
+
bestVersion = version
|
|
150
|
+
bestZstd = zstd
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return best
|
|
154
|
+
}
|
|
155
|
+
|
|
117
156
|
/**
|
|
118
157
|
* 枚举会话根目录下全部会话日志(<root>/<项目>/<会话>/session*.jsonl[.zstd])。
|
|
119
158
|
* @param {string} root - 会话根目录($DSH_HOME/sessions)
|
|
@@ -128,12 +167,9 @@ export function listSessionLogs(root) {
|
|
|
128
167
|
try { sessions = readdirSync(join(root, project.name), { withFileTypes: true }) } catch (e) { continue }
|
|
129
168
|
for (const session of sessions) {
|
|
130
169
|
if (!session.isDirectory()) continue
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (statSync(path).isFile()) { paths.push(path); break } // 同一会话多种编码互斥,取先命中者
|
|
135
|
-
} catch (e) { /* 继续尝试另一后缀 */ }
|
|
136
|
-
}
|
|
170
|
+
const dir = join(root, project.name, session.name)
|
|
171
|
+
const name = pickSessionLogName(dir)
|
|
172
|
+
if (name) paths.push(join(dir, name)) // 同一会话多种编码互斥,只取最优的一份
|
|
137
173
|
}
|
|
138
174
|
}
|
|
139
175
|
return paths
|
package/index.js
CHANGED
|
@@ -30,10 +30,14 @@ import { Schema } from './schema.js'
|
|
|
30
30
|
import { catalogEntryFor, CATALOG_META, catalogProviders, catalogFingerprint, CATALOG_FX_DEFAULT } from './vendor-catalog.js'
|
|
31
31
|
import { fetchOfficialPrices, buildSyncedEra, diffAgainstEra } from './price-sync.js'
|
|
32
32
|
import { createCredSeam, migrateLegacySecrets, safeFetch, CRED_REFS, hostnameOf } from './credstore.js'
|
|
33
|
+
// 账号登录态(DSH 0.2.1-rc.2+)余额投影:纯函数,单独成文件便于单测
|
|
34
|
+
import { accountClientMeta, mapAccountBalance, accountBalanceFailure } from './account.js'
|
|
35
|
+
// 跨版本读取 settings(0.2.x 的 SettingsForms 已无 get(),改走 describe())
|
|
36
|
+
import { readSettingsSection } from './settings.js'
|
|
33
37
|
import { listSessionLogs, planAndBuildImports, loadManifest, IMPORT_SOURCE } from './import.js'
|
|
34
38
|
|
|
35
39
|
/** 插件版本(写入上报信封,便于云端排查版本差异) */
|
|
36
|
-
const PLUGIN_VERSION = '1.
|
|
40
|
+
const PLUGIN_VERSION = '1.10.0'
|
|
37
41
|
setPluginVersion(PLUGIN_VERSION)
|
|
38
42
|
|
|
39
43
|
/** 配置面板可写的字段(与 settings 命名空间一致)。
|
|
@@ -728,16 +732,14 @@ export default {
|
|
|
728
732
|
function kimiKeyEnv() {
|
|
729
733
|
const settings = ctx.get('settings')
|
|
730
734
|
if (settings) {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
740
|
-
} catch (e) {}
|
|
735
|
+
const v = readSettingsSection(settings, 'llm-pi-ai')
|
|
736
|
+
const providers = v && v.providers
|
|
737
|
+
if (providers) {
|
|
738
|
+
const kc = providers['kimi-coding']
|
|
739
|
+
if (kc && kc.apiKeyEnv) return String(kc.apiKeyEnv)
|
|
740
|
+
const k = providers['kimi']
|
|
741
|
+
if (k && k.apiKeyEnv) return String(k.apiKeyEnv)
|
|
742
|
+
}
|
|
741
743
|
}
|
|
742
744
|
return 'KIMI_CODING_API_KEY'
|
|
743
745
|
}
|
|
@@ -745,15 +747,11 @@ export default {
|
|
|
745
747
|
function deepseekKeyEnv() {
|
|
746
748
|
const settings = ctx.get('settings')
|
|
747
749
|
if (settings) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const v = settings.get('llm-pi-ai')
|
|
754
|
-
const p = v && v.providers && v.providers['deepseek']
|
|
755
|
-
if (p && p.apiKeyEnv) return String(p.apiKeyEnv)
|
|
756
|
-
} catch (e) {}
|
|
750
|
+
const v = readSettingsSection(settings, 'llm-deepseek')
|
|
751
|
+
if (v && v.apiKeyEnv) return String(v.apiKeyEnv)
|
|
752
|
+
const p = readSettingsSection(settings, 'llm-pi-ai')
|
|
753
|
+
const deepseek = p && p.providers && p.providers['deepseek']
|
|
754
|
+
if (deepseek && deepseek.apiKeyEnv) return String(deepseek.apiKeyEnv)
|
|
757
755
|
}
|
|
758
756
|
return 'DEEPSEEK_API_KEY'
|
|
759
757
|
}
|
|
@@ -865,22 +863,20 @@ export default {
|
|
|
865
863
|
const inference = []
|
|
866
864
|
const settings = ctx.get('settings')
|
|
867
865
|
if (settings) {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
} catch (e) {}
|
|
866
|
+
const v = readSettingsSection(settings, 'llm-pi-ai')
|
|
867
|
+
const providers = (v && v.providers) || {}
|
|
868
|
+
for (const [id, p] of Object.entries(providers)) {
|
|
869
|
+
if (!p) continue
|
|
870
|
+
const base = String(p.baseURL || '')
|
|
871
|
+
const looksArkCoding = /ark\.cn-beijing\.volces\.com\/api\/coding/i.test(base)
|
|
872
|
+
const looksVolc = /volcengine/i.test(id) || /volces\.com/i.test(base)
|
|
873
|
+
if (!looksArkCoding && !looksVolc) continue
|
|
874
|
+
const env = p.apiKeyEnv ? String(p.apiKeyEnv) : ''
|
|
875
|
+
if (!env) continue
|
|
876
|
+
// 推理 Key 只登记到 inference(用于给出「你配的是推理 Key」这种有价值的提示)
|
|
877
|
+
if (looksLikeInferenceKeyEnv(env)) inference.push(env)
|
|
878
|
+
else keys.push(env)
|
|
879
|
+
}
|
|
884
880
|
}
|
|
885
881
|
return { keys, inference }
|
|
886
882
|
}
|
|
@@ -1040,22 +1036,111 @@ export default {
|
|
|
1040
1036
|
}
|
|
1041
1037
|
|
|
1042
1038
|
// ---------- deepseek balance ----------
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1039
|
+
// 两种余额来源(v1.9.6 起):
|
|
1040
|
+
// ① 账号登录态(DSH 0.2.1-rc.2+):走宿主服务 deepseekAccount.getBalance(),
|
|
1041
|
+
// 拿的是 **Platform 钱包**(充值钱包 normal_wallets 与赠金钱包 bonus_wallets 分离)。
|
|
1042
|
+
// 账号态推理用 x-dsh-auth-token 走 Platform 网关,运行时
|
|
1043
|
+
// @deepseek-ai/dsh-llm-deepseek-account 的 README 明确「不会回退到 API key」——
|
|
1044
|
+
// 也就是说登录**不会下发 API Key**,旧版只认 DEEPSEEK_API_KEY 的实现
|
|
1045
|
+
// 在纯账号态下必然报「未找到 DeepSeek API Key」。
|
|
1046
|
+
// ② API Key 态:沿用 https://api.deepseek.com/user/balance(token 口径不变)。
|
|
1047
|
+
// 优先级:面板手填 Key > 账号登录态 > 配置/环境里的 API Key。
|
|
1048
|
+
// · 手填是用户显式动作,意图最强;
|
|
1049
|
+
// · 账号态优先于 API Key:账号态下真正被扣的是 Platform 钱包,且「登录了账号」
|
|
1050
|
+
// 本身就是用户的选择;此时回退到 API Key 会显示**另一个账户**的数字,更误导。
|
|
1051
|
+
// 旧 DSH(没有 deepseekAccount 服务)自动走原路径,不需要版本号判断。
|
|
1052
|
+
|
|
1053
|
+
/** 取账号服务;不存在(旧宿主)返回 null。 */
|
|
1054
|
+
function accountService() {
|
|
1055
|
+
try {
|
|
1056
|
+
const svc = ctx.get('deepseekAccount')
|
|
1057
|
+
return svc && typeof svc.getBalance === 'function' ? svc : null
|
|
1058
|
+
} catch (e) {
|
|
1059
|
+
return null
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
* 尝试账号登录态余额。
|
|
1065
|
+
* @param {object} [args] - HTTP 参数(可带 locale / timezoneOffsetSeconds,由浏览器半端提供)
|
|
1066
|
+
* @returns {{handled:boolean, service:boolean, result?:object}}
|
|
1067
|
+
* handled=true → result 即最终结果,不再回退 API Key;
|
|
1068
|
+
* handled=false → 没有可用的账号登录态(未登录/无该服务),由调用方回退;
|
|
1069
|
+
* service 表示宿主是否提供账号服务,用于区分「未找到 Key」的文案。
|
|
1070
|
+
*/
|
|
1071
|
+
async function tryAccountBalance(args) {
|
|
1072
|
+
const svc = accountService()
|
|
1073
|
+
if (!svc) return { handled: false, service: false }
|
|
1074
|
+
let details
|
|
1075
|
+
try {
|
|
1076
|
+
// client 元数据**必填**:运行时 platformClientHeaders 直接读
|
|
1077
|
+
// version / locale / timezoneOffsetSeconds,缺字段会抛 TypeError。
|
|
1078
|
+
details = await svc.getBalance(accountClientMeta(args, PLUGIN_VERSION))
|
|
1079
|
+
} catch (e) {
|
|
1080
|
+
return {
|
|
1081
|
+
handled: true,
|
|
1082
|
+
service: true,
|
|
1083
|
+
result: accountBalanceFailure('账号余额查询失败:' + toStr(e && e.message ? e.message : e)
|
|
1084
|
+
+ '(若是 DSH 升级导致的服务形状变化,请反馈;期间可在下方手动填入 API Key 查询)'),
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
// 契约里只有 null 表示「没有已存授权 / 查询期间凭据被清除」,此时才回退 API Key;
|
|
1088
|
+
// undefined 属于契约外(服务没实现好或 RPC 出错)—— 回退可能显示**另一个账户**的数字,
|
|
1089
|
+
// 所以按失败处理并留证,不装作「未登录」。
|
|
1090
|
+
if (details === null) return { handled: false, service: true }
|
|
1091
|
+
if (details === undefined) {
|
|
1092
|
+
return {
|
|
1093
|
+
handled: true,
|
|
1094
|
+
service: true,
|
|
1095
|
+
result: accountBalanceFailure('账号余额查询失败:宿主服务未返回结果(服务未就绪或版本不匹配),可稍后重试或手动填入 API Key'),
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
if (details.status !== 'ready') {
|
|
1099
|
+
return {
|
|
1100
|
+
handled: true,
|
|
1101
|
+
service: true,
|
|
1102
|
+
result: accountBalanceFailure('账号余额查询失败:Platform 未返回可用数据(网络超时或接口异常,可稍后重试)'),
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
const mapped = mapAccountBalance(details)
|
|
1106
|
+
if (!mapped) {
|
|
1107
|
+
return { handled: true, service: true, result: accountBalanceFailure('账号余额查询失败:返回的钱包数据无法解析') }
|
|
1108
|
+
}
|
|
1109
|
+
return { handled: true, service: true, result: mapped }
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/** API Key 路径(与 v1.9.5 完全一致,仅新增 source 字段用于视图区分来源)。 */
|
|
1113
|
+
async function balanceWithApiKey(key) {
|
|
1047
1114
|
try {
|
|
1048
1115
|
const r = await httpJson('https://api.deepseek.com/user/balance', { Authorization: 'Bearer ' + key.value }, 15000, allowHostsFor('deepseek'))
|
|
1049
|
-
if (r.status !== 200 || !r.body) return { ok: false, error: 'HTTP ' + (r.status || 0) + (r.error ? ' · ' + r.error : ''), available: false, total: '', granted: '', toppedUp: '', currency: 'CNY', keySource: key.source }
|
|
1116
|
+
if (r.status !== 200 || !r.body) return { ok: false, error: 'HTTP ' + (r.status || 0) + (r.error ? ' · ' + r.error : ''), available: false, total: '', granted: '', toppedUp: '', currency: 'CNY', source: 'apikey', keySource: key.source }
|
|
1050
1117
|
const j = JSON.parse(r.body)
|
|
1051
1118
|
const infos = Array.isArray(j.balance_infos) ? j.balance_infos : []
|
|
1052
1119
|
let info = null
|
|
1053
1120
|
for (const b of infos) { if (b && b.currency === 'CNY') { info = b; break } }
|
|
1054
1121
|
if (!info) info = infos[0] || {}
|
|
1055
|
-
return { ok: true, error: '', available: !!j.is_available, total: toStr(info.total_balance), granted: toStr(info.granted_balance), toppedUp: toStr(info.topped_up_balance), currency: toStr(info.currency) || 'CNY', keySource: key.source }
|
|
1122
|
+
return { ok: true, error: '', available: !!j.is_available, total: toStr(info.total_balance), granted: toStr(info.granted_balance), toppedUp: toStr(info.topped_up_balance), currency: toStr(info.currency) || 'CNY', source: 'apikey', keySource: key.source }
|
|
1056
1123
|
} catch (e) {
|
|
1057
|
-
return { ok: false, error: toStr(e && e.message ? e.message : e), available: false, total: '', granted: '', toppedUp: '', currency: 'CNY', keySource: key.source }
|
|
1124
|
+
return { ok: false, error: toStr(e && e.message ? e.message : e), available: false, total: '', granted: '', toppedUp: '', currency: 'CNY', source: 'apikey', keySource: key.source }
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
async function balance(args) {
|
|
1129
|
+
const manual = args && typeof args.apiKey === 'string' ? args.apiKey.trim() : ''
|
|
1130
|
+
if (manual) return balanceWithApiKey({ value: manual, source: 'manual' })
|
|
1131
|
+
const acct = await tryAccountBalance(args)
|
|
1132
|
+
if (acct.handled) return acct.result
|
|
1133
|
+
const key = await resolveApiKey(deepseekKeyEnv())
|
|
1134
|
+
if (!key.value) {
|
|
1135
|
+
return {
|
|
1136
|
+
ok: false,
|
|
1137
|
+
error: acct.service
|
|
1138
|
+
? '未找到 DeepSeek API Key,也没有已登录的 DeepSeek 账号(DSH 0.2.1+ 可在「设置 → 账号与余额」登录后查询账号余额)'
|
|
1139
|
+
: '未找到 DeepSeek API Key',
|
|
1140
|
+
available: false, total: '', granted: '', toppedUp: '', currency: 'CNY', source: 'none', keySource: 'none',
|
|
1141
|
+
}
|
|
1058
1142
|
}
|
|
1143
|
+
return balanceWithApiKey(key)
|
|
1059
1144
|
}
|
|
1060
1145
|
|
|
1061
1146
|
// ---------- csv export ----------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angelyeye/dsh-cost-tracker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
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",
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
"price-sync.js",
|
|
19
19
|
"credstore.js",
|
|
20
20
|
"import.js",
|
|
21
|
+
"account.js",
|
|
22
|
+
"settings.js",
|
|
21
23
|
"docs/provider-pricing.json",
|
|
22
24
|
"docs/THIRD-PARTY-NOTICES.md",
|
|
23
25
|
"cordis.patch.yml",
|
|
@@ -33,7 +35,7 @@
|
|
|
33
35
|
"./package.json": "./package.json"
|
|
34
36
|
},
|
|
35
37
|
"scripts": {
|
|
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 && node test/release-notes.test.js"
|
|
38
|
+
"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/balance-account.test.js && node test/session-log-v4.test.js && node test/settings-compat.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 && node test/release-notes.test.js"
|
|
37
39
|
},
|
|
38
40
|
"keywords": [
|
|
39
41
|
"dsh-plugin",
|
package/pricing.js
CHANGED
|
@@ -289,10 +289,14 @@ export const VOLCENGINE_PLAN_DEDICATED_PROVIDERS = [
|
|
|
289
289
|
/**
|
|
290
290
|
* 火山方舟 Coding Plan 覆盖的具体模型(原始名,归一化后匹配)。
|
|
291
291
|
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
292
|
+
* 清单按官方 2026-10 文档「Coding Plan 个人版快速开始」复核:可配置 Model Name
|
|
293
|
+
* 共 13 个(另有控制台托管的 ark-code-latest / Auto)。方舟模型 id 普遍带
|
|
294
|
+
* **6 位日期后缀**(`glm-5-3-flash-260828`、`deepseek-v4-1-flash-260910`、
|
|
295
|
+
* `doubao-seed-2-1-pro-260915`),故匹配时先剥掉该后缀再查表——否则泛
|
|
296
|
+
* volcengine 分支会把套餐内模型漏配成「按量计费 · 价格为估算」。
|
|
297
|
+
*
|
|
298
|
+
* 沿用旧清单的 9 个 id 未删:官方下线公告页本机取不到正文,删错会把仍在售的
|
|
299
|
+
* 套餐内模型误标按量;保留的代价只是极端情况下少算按量花费,方向更安全。
|
|
296
300
|
*/
|
|
297
301
|
const VOLCENGINE_PLAN_MODEL_IDS = [
|
|
298
302
|
'ark-code-latest',
|
|
@@ -302,15 +306,30 @@ const VOLCENGINE_PLAN_MODEL_IDS = [
|
|
|
302
306
|
'doubao-seed-2.0-pro',
|
|
303
307
|
'doubao-seed-2.0-lite',
|
|
304
308
|
'doubao-seed-2.1-pro',
|
|
309
|
+
// 2026-10 官方清单新增:豆包 2.1 Lite / 2.0 Mini / 自动演进档
|
|
310
|
+
'doubao-seed-2.1-lite',
|
|
311
|
+
'doubao-seed-2.0-mini',
|
|
312
|
+
'doubao-seed-evolving',
|
|
305
313
|
// 智谱(含用户配置里的 5.3 flash 带日期变体)
|
|
306
314
|
'glm-4.7',
|
|
307
315
|
'glm-5.1',
|
|
316
|
+
'glm-5.2',
|
|
317
|
+
'glm-5.3',
|
|
308
318
|
'glm-5.3-flash',
|
|
319
|
+
// glm-latest 是官方给 glm-5.3 的别名,归一化后是另一个键,必须单独登记
|
|
320
|
+
'glm-latest',
|
|
309
321
|
// Kimi / DeepSeek / MiniMax
|
|
310
322
|
'kimi-k2.5',
|
|
323
|
+
// 2026-08 起方舟新增的 Kimi 档(原生侧叫 kimi-for-coding / k3 系)
|
|
324
|
+
'kimi-k2.8-preview',
|
|
325
|
+
'kimi-k3',
|
|
326
|
+
'kimi-k3.1-pro',
|
|
311
327
|
'deepseek-v3.2',
|
|
312
328
|
'deepseek-v4-pro',
|
|
313
329
|
'deepseek-v4.1-flash',
|
|
330
|
+
// 2026-10 官方清单新增:经济档与旧名 V4-Flash
|
|
331
|
+
'deepseek-v4.1-flash-economy',
|
|
332
|
+
'deepseek-v4-flash',
|
|
314
333
|
'minimax-m2.5',
|
|
315
334
|
]
|
|
316
335
|
|
|
@@ -345,6 +364,15 @@ export function volcenginePlanModels() {
|
|
|
345
364
|
return out
|
|
346
365
|
}
|
|
347
366
|
|
|
367
|
+
/**
|
|
368
|
+
* 剥掉方舟模型 id 的 6 位日期后缀(归一化后的尾部 `\d{6}`)。
|
|
369
|
+
* 只用于火山白名单匹配,不改变全局 normalizeModelName 的语义。
|
|
370
|
+
* @param {string} n - 已归一化的模型名
|
|
371
|
+
*/
|
|
372
|
+
export function stripVolcDateSuffix(n) {
|
|
373
|
+
return String(n == null ? '' : n).replace(/\d{6}$/, '')
|
|
374
|
+
}
|
|
375
|
+
|
|
348
376
|
/**
|
|
349
377
|
* 解析某次调用是否命中订阅套餐。
|
|
350
378
|
* @param {string} np - 归一化 provider 名
|
|
@@ -366,17 +394,27 @@ export function subscriptionPlanFor(np, model) {
|
|
|
366
394
|
if (VOLCENGINE_PLAN_PROVIDER_KEYS.indexOf(np) < 0) return null
|
|
367
395
|
if (VOLCENGINE_PLAN_DEDICATED_PROVIDERS.indexOf(np) >= 0) return VOLC_PLAN_RATES
|
|
368
396
|
const n = normalizeModelName(model)
|
|
369
|
-
|
|
397
|
+
const bare = stripVolcDateSuffix(n)
|
|
398
|
+
const idx = volcModelIndex()
|
|
399
|
+
if (idx[n] !== undefined || (bare !== n && idx[bare] !== undefined)) return VOLC_PLAN_RATES
|
|
370
400
|
for (const p of VOLCENGINE_PLAN_MODEL_PREFIXES) {
|
|
371
|
-
if (n.startsWith(p)) return VOLC_PLAN_RATES
|
|
401
|
+
if (n.startsWith(p) || (bare !== n && bare.startsWith(p))) return VOLC_PLAN_RATES
|
|
372
402
|
}
|
|
373
403
|
return null
|
|
374
404
|
}
|
|
375
405
|
|
|
376
|
-
/**
|
|
377
|
-
*
|
|
406
|
+
/** DeepSeek 官方渠道的兜底单价(含峰谷 tiered)。
|
|
407
|
+
* 兜底已同步至 V4.1 Flash 档(2.0/8.0/0.04),未知模型不再按旧价高估。 */
|
|
408
|
+
const DEEPSEEK_PROVIDER_RATES = { rates: { input: 2.0, output: 8.0, cacheRead: 0.04, cacheWrite: 0.04 }, tiered: true }
|
|
409
|
+
|
|
410
|
+
/** Provider 兜底单价(估算);缓存写入按缓存命中价计。 */
|
|
378
411
|
export const PROVIDER_RATES = {
|
|
379
|
-
deepseek:
|
|
412
|
+
deepseek: DEEPSEEK_PROVIDER_RATES,
|
|
413
|
+
// DSH 0.2.x「DeepSeek 账号登录」的推理 provider 名是 `deepseek-account`
|
|
414
|
+
// (鉴权走 x-dsh-auth-token,模型与官方单价仍是同一套)。不登记它的话,
|
|
415
|
+
// 精确价表之外的模型会落到 GENERIC_RATES(缓存价 0.5 而非 0.04、且无峰谷半价),
|
|
416
|
+
// 账号态的新模型会被静默高估 —— 所以这里与 deepseek 共用同一份兜底价。
|
|
417
|
+
'deepseek-account': DEEPSEEK_PROVIDER_RATES,
|
|
380
418
|
openai: { rates: { input: 10.0, output: 30.0, cacheRead: 5.0, cacheWrite: 5.0 }, tiered: false },
|
|
381
419
|
anthropic: { rates: { input: 15.0, output: 75.0, cacheRead: 1.5, cacheWrite: 1.5 }, tiered: false },
|
|
382
420
|
gemini: { rates: { input: 2.5, output: 10.0, cacheRead: 0.625, cacheWrite: 0.625 }, tiered: false },
|
package/settings.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 跨版本读取 profile 条目的「生效配置」(DSH settings 服务)
|
|
3
|
+
//
|
|
4
|
+
// 背景:插件有几处「按用户配置决定用哪个 Key 名」的逻辑(DeepSeek / Kimi /
|
|
5
|
+
// 火山方舟),旧实现直接 `ctx.get('settings').get('llm-deepseek')`。
|
|
6
|
+
// 但 0.2.x 的 SettingsForms 已经**没有 `get()`**(只剩 configure / describe /
|
|
7
|
+
// update / replace / mutate / write / prepareDocument),那段代码抛 TypeError
|
|
8
|
+
// 被各自的 try/catch 吞掉 → **静默**退化成永远使用硬编码默认名。
|
|
9
|
+
// 标准部署(默认名与官方一致)看不出问题;自定义 `apiKeyEnv` 的部署会去查
|
|
10
|
+
// 一个不存在的 Key 名,表现为「明明配了 Key 却报未找到」。
|
|
11
|
+
//
|
|
12
|
+
// 0.2.x 的正确读法:`settings.describe()` 返回所有条目的表单描述,
|
|
13
|
+
// 其中 `value` 是该条目 **volatile 字段的生效值** —— `apiKeyEnv` 正是
|
|
14
|
+
// `.volatile()` 字段(见 dsh-llm-deepseek-api-key 的 Config)。旧宿主(0.1.x)
|
|
15
|
+
// 则保留 `get(namespace)`。因此这里做一次「双 API 兼容读」:
|
|
16
|
+
//
|
|
17
|
+
// 1) settings.describe() 命中 ns → 用 row.value(0.2.x)
|
|
18
|
+
// 2) 否则 settings.get(ns)(旧版)
|
|
19
|
+
// 3) 都没有 / 都失败 → null,由调用方回落各自默认名
|
|
20
|
+
//
|
|
21
|
+
// describe() 要遍历全部 profile 条目并逐条做 schema 投影,比一次 `get` 重得多,
|
|
22
|
+
// 而余额 / Kimi / 火山三个入口在一次面板刷新里会各调一次 —— 所以按 settings
|
|
23
|
+
// 实例做 10s 短缓存,避免重复做全量投影。
|
|
24
|
+
// ============================================================
|
|
25
|
+
|
|
26
|
+
/** describe() 结果的缓存时长(毫秒)。配置变更在设置页写入后最迟 10s 生效。 */
|
|
27
|
+
const CACHE_TTL_MS = 10000
|
|
28
|
+
|
|
29
|
+
/** settings 实例 → { rows: Array|null, at: number } */
|
|
30
|
+
const rowsCache = new WeakMap()
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 取 describe() 的行数组(带短缓存)。
|
|
34
|
+
* @param {object} settings - settings 服务
|
|
35
|
+
* @param {number} now - 当前时刻(毫秒)
|
|
36
|
+
* @returns {Array|null} 行数组;describe 不可用或抛错时为 null
|
|
37
|
+
*/
|
|
38
|
+
function describedRows(settings, now) {
|
|
39
|
+
const hit = rowsCache.get(settings)
|
|
40
|
+
if (hit && now - hit.at < CACHE_TTL_MS) return hit.rows
|
|
41
|
+
let rows = null
|
|
42
|
+
try {
|
|
43
|
+
const out = settings.describe()
|
|
44
|
+
if (Array.isArray(out)) rows = out
|
|
45
|
+
} catch (e) {
|
|
46
|
+
rows = null
|
|
47
|
+
}
|
|
48
|
+
rowsCache.set(settings, { rows, at: now })
|
|
49
|
+
return rows
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 读取某个 profile 条目(ns)的生效配置对象。
|
|
54
|
+
*
|
|
55
|
+
* @param {object|undefined} settings - `ctx.get('settings')`
|
|
56
|
+
* @param {string} ns - profile 条目 id(如 `llm-deepseek` / `llm-pi-ai`)
|
|
57
|
+
* @param {number} [now] - 仅测试用:注入当前时刻
|
|
58
|
+
* @returns {object|null} 配置对象;不可得时 null
|
|
59
|
+
*/
|
|
60
|
+
export function readSettingsSection(settings, ns, now) {
|
|
61
|
+
if (!settings || typeof ns !== 'string' || !ns) return null
|
|
62
|
+
const at = typeof now === 'number' ? now : Date.now()
|
|
63
|
+
// ---- 0.2.x:describe() 的 value 是 volatile 字段的生效值 ----
|
|
64
|
+
if (typeof settings.describe === 'function') {
|
|
65
|
+
const rows = describedRows(settings, at)
|
|
66
|
+
if (rows) {
|
|
67
|
+
for (const row of rows) {
|
|
68
|
+
if (!row || row.ns !== ns) continue
|
|
69
|
+
const value = row.value
|
|
70
|
+
return value && typeof value === 'object' ? value : null
|
|
71
|
+
}
|
|
72
|
+
// describe() 正常返回但没有该条目:不要再回退 get()(0.2.x 上它一定抛错,
|
|
73
|
+
// 而且在「条目确实不存在」时也更该返回 null)
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ---- 旧宿主:get(namespace) ----
|
|
78
|
+
if (typeof settings.get === 'function') {
|
|
79
|
+
try {
|
|
80
|
+
const value = settings.get(ns)
|
|
81
|
+
return value && typeof value === 'object' ? value : null
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 清掉某个 settings 实例的缓存(仅测试/显式失效用)。
|
|
91
|
+
* @param {object} settings
|
|
92
|
+
*/
|
|
93
|
+
export function resetSettingsCache(settings) {
|
|
94
|
+
if (settings && typeof settings === 'object') rowsCache.delete(settings)
|
|
95
|
+
}
|
package/vendor-catalog.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// ============================================================
|
|
2
2
|
// DSH 花费统计插件 —— 多厂商模型价格目录(纯逻辑,可独立测试)
|
|
3
3
|
//
|
|
4
|
-
// 数据来源:docs/provider-pricing.json ——
|
|
5
|
-
//
|
|
6
|
-
// sourceUrl / checkedAt
|
|
4
|
+
// 数据来源:docs/provider-pricing.json —— 初版改编自 dsh-cost-meter(MIT License)
|
|
5
|
+
// 的「已核对官方价格目录」,2026-10-25 起按各厂商官方定价页逐条复核刷新
|
|
6
|
+
// (官方页不可达时才用网关价并标注),保留每个条目的 sourceUrl / checkedAt
|
|
7
|
+
// 以便溯源;条目单价为 **USD / 1M tokens**。
|
|
7
8
|
//
|
|
8
9
|
// 本插件账本恒以人民币(CNY)入账,因此目录价在计费时按 `catalogFxRate`
|
|
9
10
|
// (默认 7.2,可在配置面板修改)折算为 CNY。缓存写入价沿用目录约定:
|
|
@@ -25,9 +26,9 @@ import { readFileSync } from 'node:fs'
|
|
|
25
26
|
import { createHash } from 'node:crypto'
|
|
26
27
|
|
|
27
28
|
export const CATALOG_META = {
|
|
28
|
-
generatedAt: '2026-
|
|
29
|
+
generatedAt: '2026-10-25',
|
|
29
30
|
note: 'USD per 1M tokens; unpriced entries have no verified official price.',
|
|
30
|
-
origin: 'adapted from dsh-cost-meter docs/provider-pricing.json (MIT)',
|
|
31
|
+
origin: 'adapted from dsh-cost-meter docs/provider-pricing.json (MIT); refreshed from vendor pricing pages 2026-10-25',
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/** 目录价 USD→CNY 默认汇率(可在配置中覆盖) */
|
|
@@ -53,6 +54,7 @@ export const PROVIDER_ALIASES = {
|
|
|
53
54
|
upstage: 'upstage', solar: 'upstage',
|
|
54
55
|
nvidia: 'nvidia', 'nvidia-nim': 'nvidia',
|
|
55
56
|
mistral: 'mistral', mistralai: 'mistral',
|
|
57
|
+
meta: 'meta', 'meta-ai': 'meta', muse: 'meta',
|
|
56
58
|
opencode: 'opencode-go', 'opencode-go': 'opencode-go', opencodego: 'opencode-go',
|
|
57
59
|
}
|
|
58
60
|
|