dsh-cost-meter 1.9.2 → 1.9.4
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 +9 -8
- package/README.zh-CN.md +9 -8
- package/docs/display-settings.md +15 -1
- package/docs/opendesign-billing.md +99 -93
- package/docs/performance-2026-10-18.json +1703 -1703
- package/docs/performance-2026-10-18.md +58 -58
- package/docs/update-notes-1.9.3.md +19 -0
- package/docs/update-notes-1.9.4.md +71 -0
- package/lib/client.codex.js +1 -1
- package/lib/client.display.js +2 -2
- package/lib/client.js +5 -5
- package/lib/client.peak.js +3 -0
- package/lib/client.pricing.js +14 -11
- package/lib/client.statistics.js +6 -5
- package/lib/codex-subscription-compat.js +23 -2
- package/lib/index.js +46 -28
- package/lib/model-statistics.js +34 -0
- package/lib/opendesign.js +16 -5
- package/lib/store.js +22 -5
- package/lib/typert.host.js +1063 -1058
- package/package.json +4 -2
package/lib/index.js
CHANGED
|
@@ -43,7 +43,8 @@ import { queryGatewayQuota, emptyGatewayQuota, managementKeyVarOf, gatewaySource
|
|
|
43
43
|
import { stateSchema, TYPERT } from './typert.host.js'
|
|
44
44
|
// dsh-codex-subscription 兼容(契约 A/C/D):纯本地检测 + 历史 codex 用量归类。
|
|
45
45
|
// applyCodexCompatHistory 以别名导入,避免与服务方法/RPC 同名遮蔽。
|
|
46
|
-
import { detectCodexSubscription, codexCompatStatus, ensureCodexCompatPlan, applyCodexCompatHistory as applyCodexCompatHistoryToLedger, dismissCodexCompatPrompt } from './codex-subscription-compat.js'
|
|
46
|
+
import { detectCodexSubscription, codexRuntimeEnabled, codexCompatStatus, ensureCodexCompatPlan, applyCodexCompatHistory as applyCodexCompatHistoryToLedger, dismissCodexCompatPrompt } from './codex-subscription-compat.js'
|
|
47
|
+
import { modelStatisticsAggregate } from './model-statistics.js'
|
|
47
48
|
// @eddyskywalker/dsh-chatgpt-subscription 兼容(W1):9 条订阅线路 provider 归 Plan。
|
|
48
49
|
import { detectChatgptSubscription, ensureChatgptSubscriptionPlan } from './chatgpt-subscription-compat.js'
|
|
49
50
|
// 会话存储兼容(T3):宿主装 better-session(@morlay/session-rdb,SQLite)后会话不再落
|
|
@@ -1248,7 +1249,7 @@ async function buildState(ledger, balance = emptyBalance(), goQuota = emptyGoQuo
|
|
|
1248
1249
|
// 真金白银口径(issue #64):默认只计 API 渠道(apiCost);开启「含 Plan 总额」
|
|
1249
1250
|
// (showTotalWithPlan)后按总等值金额(cost)计,与概览卡片口径一致。
|
|
1250
1251
|
const withPlan = ledger.config?.showTotalWithPlan === true
|
|
1251
|
-
const budgetCostOf = agg => displayUsd(agg, ledger.config, !withPlan)
|
|
1252
|
+
const budgetCostOf = agg => displayUsd(modelStatisticsAggregate(agg, ledger.config, 'budget'), ledger.config, !withPlan)
|
|
1252
1253
|
const budget = ledger.config?.budget ?? {}
|
|
1253
1254
|
let budgetUsed
|
|
1254
1255
|
if (budget.period === 'day') budgetUsed = budgetCostOf(ledger.today())
|
|
@@ -1310,9 +1311,9 @@ async function buildState(ledger, balance = emptyBalance(), goQuota = emptyGoQuo
|
|
|
1310
1311
|
}).filter(Boolean) : []
|
|
1311
1312
|
const state = {
|
|
1312
1313
|
...(billionContextBillingStatus(ledger) ? { billionContext: billionContextBillingStatus(ledger) } : {}),
|
|
1313
|
-
today: ledger.today(),
|
|
1314
|
-
month: ledger.sumDays(monthKey),
|
|
1315
|
-
total: ledger.sumDays(undefined),
|
|
1314
|
+
today: modelStatisticsAggregate(ledger.today(), ledger.config, 'today'),
|
|
1315
|
+
month: modelStatisticsAggregate(ledger.sumDays(monthKey), ledger.config, 'summary'),
|
|
1316
|
+
total: modelStatisticsAggregate(ledger.sumDays(undefined), ledger.config, 'summary'),
|
|
1316
1317
|
budgetUsed,
|
|
1317
1318
|
balance: { ...balance, ...await describeBalanceKey(ctx) },
|
|
1318
1319
|
goQuota,
|
|
@@ -1351,7 +1352,11 @@ async function buildState(ledger, balance = emptyBalance(), goQuota = emptyGoQuo
|
|
|
1351
1352
|
...(secretMigration !== null ? { secretMigration } : {}),
|
|
1352
1353
|
}
|
|
1353
1354
|
// dsh-codex-subscription 兼容(契约 C):仅检测到该插件时下发;键缺席 = 旧宿主/未安装。
|
|
1354
|
-
if (codexCompatDetection !== null)
|
|
1355
|
+
if (codexCompatDetection !== null) {
|
|
1356
|
+
const enabled = codexRuntimeEnabled(ctx)
|
|
1357
|
+
if (enabled) ensureCodexCompatPlan(ledger, codexCompatDetection)
|
|
1358
|
+
state.codexCompat = codexCompatStatus(ledger, codexCompatDetection, enabled)
|
|
1359
|
+
}
|
|
1355
1360
|
// 可用性兑底:若快照与 strict codec 漂移(新增字段 schema 未同步等),
|
|
1356
1361
|
// 逐级降级(空 codingPlans → 空额度状态)重试,而不是让整个 getState 被拒导致「账本不可用」。
|
|
1357
1362
|
// 注意剔除键必须用解构省略而非赋 undefined:被 schema 声明的 optional 键若显式给
|
|
@@ -1451,18 +1456,18 @@ async function describePlanKey(credentials, id, config) {
|
|
|
1451
1456
|
return legacy ? { keyConfigured: true, keySource: 'legacy' } : fallback
|
|
1452
1457
|
}
|
|
1453
1458
|
const legacy = readSecret(config, `codingPlans.${id}`).length > 0
|
|
1454
|
-
const
|
|
1459
|
+
const refs = CODING_PLAN_PROVIDERS[id]?.credentialEnvs ?? []
|
|
1455
1460
|
// scnet 无凭据(credentialEnvs 为空数组,纯本地 Credits 估算),不参与判定。
|
|
1456
|
-
if (
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
// describe 不可用:退回遗留明文判定。
|
|
1461
|
+
if (refs.length === 0) return fallback
|
|
1462
|
+
// Match resolveCodingPlanKey: all credential aliases precede environment aliases.
|
|
1463
|
+
// In particular VELA_CONTROL_KEY is just as usable as OPENDESIGN_CONTROL_KEY.
|
|
1464
|
+
if (credentials !== undefined) for (const ref of refs) {
|
|
1465
|
+
try {
|
|
1466
|
+
const info = await credentials.describe(credentialRef(ref))
|
|
1467
|
+
if (info?.configured === true) return { keyConfigured: true, keySource: typeof info.source === 'string' ? info.source : '' }
|
|
1468
|
+
} catch { /* Try the remaining sources, just like the resolver. */ }
|
|
1465
1469
|
}
|
|
1470
|
+
if (refs.some(ref => String(process.env[ref] ?? '').trim().length > 0)) return { keyConfigured: true, keySource: 'env' }
|
|
1466
1471
|
return legacy ? { keyConfigured: true, keySource: 'legacy' } : fallback
|
|
1467
1472
|
}
|
|
1468
1473
|
|
|
@@ -2105,7 +2110,7 @@ function createService(ctx, ledger, openRouterPrices, openDesignPrices, codexSub
|
|
|
2105
2110
|
})
|
|
2106
2111
|
})().then(result => {
|
|
2107
2112
|
if (!active || codingPlanCaches[id]?.inFlight !== task) return
|
|
2108
|
-
codingPlanCaches[id] = { fetchedAt: Date.now(), value: { status: 'ok', message: '', fetchedAt: Date.now(), windows: result.windows } }
|
|
2113
|
+
codingPlanCaches[id] = { fetchedAt: Date.now(), value: { status: 'ok', message: result.message ?? '', fetchedAt: Date.now(), windows: result.windows } }
|
|
2109
2114
|
// SCNet 百分比来自本地自估(自我引用),不参与采样估算。
|
|
2110
2115
|
if (id !== 'scnet') recordQuotaSamples(id, result.windows)
|
|
2111
2116
|
}, error => {
|
|
@@ -2351,18 +2356,18 @@ function createService(ctx, ledger, openRouterPrices, openDesignPrices, codexSub
|
|
|
2351
2356
|
// 归类变更影响 Plan 配额基线,与 updateConfig 的 planBilling 变更同款处理:
|
|
2352
2357
|
// 清空采样基准 + 延迟重放小时桶,保证历史聚合与新口径一致。
|
|
2353
2358
|
async applyCodexCompatHistory() {
|
|
2354
|
-
const result = applyCodexCompatHistoryToLedger(ledger, codexSubscription)
|
|
2359
|
+
const result = applyCodexCompatHistoryToLedger(ledger, { ...codexSubscription, installed: codexSubscription?.installed === true && codexRuntimeEnabled(ctx) })
|
|
2355
2360
|
if (result.changed) {
|
|
2356
2361
|
ledger.planSamples = {}
|
|
2357
2362
|
schedulePlanHourRepair()
|
|
2358
2363
|
}
|
|
2359
|
-
return build(false)
|
|
2364
|
+
return build(false, true)
|
|
2360
2365
|
},
|
|
2361
2366
|
|
|
2362
2367
|
// 永久关闭一次性兼容提示(×/保持现状/ESC 同语义)。
|
|
2363
2368
|
async dismissCodexCompat() {
|
|
2364
2369
|
dismissCodexCompatPrompt(ledger)
|
|
2365
|
-
return build(false)
|
|
2370
|
+
return build(false, true)
|
|
2366
2371
|
},
|
|
2367
2372
|
|
|
2368
2373
|
/** 把手改过的 OpenRouter 价格交回自动同步(前端「恢复自动同步」按钮)。
|
|
@@ -2516,7 +2521,7 @@ function createService(ctx, ledger, openRouterPrices, openDesignPrices, codexSub
|
|
|
2516
2521
|
const value = codingPlanCaches[id]?.value ?? emptyCodingPlan()
|
|
2517
2522
|
return {
|
|
2518
2523
|
ok: value.status === 'ok',
|
|
2519
|
-
message: value.status === 'ok' ? tmsg(locale, 'codingPlanRefreshed', { provider: label })
|
|
2524
|
+
message: value.status === 'ok' ? value.message || tmsg(locale, 'codingPlanRefreshed', { provider: label })
|
|
2520
2525
|
: value.status === 'off' && value.message ? value.message
|
|
2521
2526
|
: tmsg(locale, 'codingPlanQueryFailed', { provider: label, message: value.message }),
|
|
2522
2527
|
state: await buildCurrentState(),
|
|
@@ -3495,10 +3500,10 @@ export function apply(ctx) {
|
|
|
3495
3500
|
prepareOfficialDeepSeekPrices(ledger)
|
|
3496
3501
|
prepareDefaultPeakPrice(ledger)
|
|
3497
3502
|
prepareSeptemberPrices(ledger)
|
|
3498
|
-
//
|
|
3499
|
-
//
|
|
3503
|
+
// Cache the installed package version; active runtime status is checked on every state read.
|
|
3504
|
+
// Only an active peer defaults new Codex usage to Plan; history still requires confirmation.
|
|
3500
3505
|
const codexSubscription = detectCodexSubscription()
|
|
3501
|
-
ensureCodexCompatPlan(ledger, codexSubscription)
|
|
3506
|
+
if (codexRuntimeEnabled(ctx)) ensureCodexCompatPlan(ledger, codexSubscription)
|
|
3502
3507
|
// @eddyskywalker/dsh-chatgpt-subscription 兼容(W1):9 条订阅线路归类为 Plan(同样只做
|
|
3503
3508
|
// 纯本地检测 + 配置归类,不重算历史 apiCost;UI 展示留到后续任务)。
|
|
3504
3509
|
const chatgptSubscription = detectChatgptSubscription()
|
|
@@ -3629,9 +3634,22 @@ export function apply(ctx) {
|
|
|
3629
3634
|
// dshmarket 1.47 热安装通过独立 Include 挂载 file:// 入口;它不在根 Loader
|
|
3630
3635
|
// 的包名扫描树中,typert-loader 因此漏注册 (#154)。正常包名启动仍由宿主注册。
|
|
3631
3636
|
// 注入上下文拥有注册效果:支持 registry 晚到,卸载/重新挂载时自动撤销/恢复。
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3637
|
+
ctx.inject(['typert'], typertCtx => {
|
|
3638
|
+
const registry = typertCtx.typert
|
|
3639
|
+
if (!registry.getPackage('dsh-cost-meter', 'host')) {
|
|
3640
|
+
if (ctx.fiber?.entry?.options.name?.startsWith('file:')) registry.register(TYPERT)
|
|
3641
|
+
return
|
|
3642
|
+
}
|
|
3643
|
+
// The host caches ./typert until restart. A hot upgrade can load the new
|
|
3644
|
+
// service while retaining an older manifest, leaving these endpoints at 404.
|
|
3645
|
+
// Add only missing compatibility methods; keep the original owner's lifetime.
|
|
3646
|
+
const missing = TYPERT.invocations.filter(def =>
|
|
3647
|
+
['applyCodexCompatHistory', 'dismissCodexCompat'].includes(def.method)
|
|
3648
|
+
&& !registry.local.get(def.namespace + '/' + def.method))
|
|
3649
|
+
if (missing.length) registry.register({
|
|
3650
|
+
package: 'dsh-cost-meter-codex-compat', face: 'host', schemas: [],
|
|
3651
|
+
model: { services: [], events: [], objects: [] },
|
|
3652
|
+
invocations: missing.map(def => ({ ...def, id: 'dsh-cost-meter-codex-compat#costMeter/' + def.method })),
|
|
3635
3653
|
})
|
|
3636
|
-
}
|
|
3654
|
+
})
|
|
3637
3655
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Presentation exclusions only: original model buckets, calls and prices stay in the ledger. */
|
|
2
|
+
import { fxRatesOf } from './exchange-rates.js'
|
|
3
|
+
|
|
4
|
+
const scopes = ['today', 'summary', 'budget']
|
|
5
|
+
const object = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
6
|
+
export function normalizeModelStatistics(raw) {
|
|
7
|
+
if (!object(raw)) return {}
|
|
8
|
+
return Object.fromEntries(Object.entries(raw).filter(([key, value]) => key.includes(':') && key.length <= 512 && object(value))
|
|
9
|
+
.slice(0, 1000).map(([key, value]) => [key, Object.fromEntries(scopes.map(scope => [scope, value[scope] !== false]))])
|
|
10
|
+
.filter(([, value]) => scopes.some(scope => !value[scope])))
|
|
11
|
+
}
|
|
12
|
+
export function validModelStatistics(raw) {
|
|
13
|
+
return object(raw) && Object.keys(raw).length <= 1000 && Object.entries(raw).every(([key, value]) =>
|
|
14
|
+
key.includes(':') && key.length <= 512 && object(value) && Object.entries(value).every(([scope, on]) => scopes.includes(scope) && typeof on === 'boolean'))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function modelStatisticsAggregate(aggregate, config, scope) {
|
|
18
|
+
if (!aggregate) return aggregate
|
|
19
|
+
const excluded = Object.entries(config.modelStatistics ?? {}).filter(([key, flags]) => flags?.[scope] === false && aggregate.byProviderModel?.[key])
|
|
20
|
+
.map(([key]) => [key, aggregate.byProviderModel[key]])
|
|
21
|
+
if (!excluded.length) return aggregate
|
|
22
|
+
const result = { ...aggregate }, rates = fxRatesOf(config)
|
|
23
|
+
for (const field of ['cost', 'apiCost', 'costCny', 'apiCostCny', 'costEur', 'apiCostEur', 'calls', 'input', 'output', 'cacheRead', 'cacheWrite', 'reasoning']) {
|
|
24
|
+
if (!Number.isFinite(aggregate[field])) continue
|
|
25
|
+
const frozen = /^(apiCost|cost)(Cny|Eur)$/.exec(field)
|
|
26
|
+
const amount = row => Number.isFinite(row[field]) ? row[field] : frozen
|
|
27
|
+
? (row[frozen[1]] ?? row.cost ?? 0) * rates[frozen[2] === 'Cny' ? 'CNY' : 'EUR']
|
|
28
|
+
: field === 'apiCost' ? row.cost ?? 0 : 0
|
|
29
|
+
result[field] = Math.max(0, aggregate[field] - excluded.reduce((sum, [, row]) => sum + amount(row), 0))
|
|
30
|
+
}
|
|
31
|
+
// Keep buckets for editing and original records; only the displayed sums are filtered.
|
|
32
|
+
if (Array.isArray(aggregate.sessions)) result.sessions = aggregate.sessions.map(row => modelStatisticsAggregate(row, config, scope))
|
|
33
|
+
return result
|
|
34
|
+
}
|
package/lib/opendesign.js
CHANGED
|
@@ -144,6 +144,14 @@ export async function queryOpenDesignQuota(key, locale, t, { workspaceId, signal
|
|
|
144
144
|
}
|
|
145
145
|
return queryError(zh ? 'OpenDesign:查询失败,请检查控制端凭据、工作区权限和网络。' : 'OpenDesign: query failed; check the control credential, workspace access and connection.', false, failure.kind)
|
|
146
146
|
}
|
|
147
|
+
const partialResult = (windows, endpoint, failures, fallback = false) => ({
|
|
148
|
+
windows, endpoint,
|
|
149
|
+
partial: Object.fromEntries(failures.map(([side, failure]) => [side, failure.kind])),
|
|
150
|
+
message: [
|
|
151
|
+
...(fallback ? [zh ? '钱包余额来自 billing/preflight。' : 'Wallet balance is from billing/preflight.'] : []),
|
|
152
|
+
...failures.map(([side, failure]) => (side === 'usage' ? (zh ? '套餐额度:' : 'Plan quota: ') : (zh ? '钱包端点:' : 'Wallet endpoint: ')) + describe(failure).message),
|
|
153
|
+
].join('\n'),
|
|
154
|
+
})
|
|
147
155
|
try {
|
|
148
156
|
// #274 / #313: do not spend a request on the browser-session-only usage route.
|
|
149
157
|
const [usageRead, walletRead] = await Promise.all([read('/billing/preflight', 'preflight'), read('/wallet/balance', 'wallet')])
|
|
@@ -165,19 +173,22 @@ export async function queryOpenDesignQuota(key, locale, t, { workspaceId, signal
|
|
|
165
173
|
const walletFailure = !walletRead.ok ? walletRead
|
|
166
174
|
: balance === null ? { ok: false, side: 'wallet', kind: OPEN_DESIGN_QUOTA_FAILURES.invalidResponse, source: 'shape', url: walletRead.url } : null
|
|
167
175
|
// A preflight answer carries balanceUsd too; it only fills in when the wallet endpoint failed.
|
|
168
|
-
const fallbackBalance =
|
|
169
|
-
if (
|
|
176
|
+
const fallbackBalance = usageWindows !== null && preflight ? balanceWindowOf(usageRead.value) : null
|
|
177
|
+
if (usageWindows !== null && balance !== null) {
|
|
170
178
|
// Only an identity the quota response actually provides must agree with the wallet member.
|
|
171
179
|
const usageMember = quotaMemberOf(usageRead.value)
|
|
172
180
|
if (usageMember !== undefined && walletRead.value.workspaceMemberId !== usageMember) {
|
|
173
181
|
throw queryError(zh ? 'OpenDesign:钱包与额度的工作区成员不一致。' : 'OpenDesign: wallet and quota member identities do not match.', false, OPEN_DESIGN_QUOTA_FAILURES.identityMismatch)
|
|
174
182
|
}
|
|
175
|
-
return { windows: { ...usageWindows, balance }, endpoint: usageRead.url }
|
|
176
183
|
}
|
|
184
|
+
if (usageFailure === null && walletFailure === null) return { windows: { ...usageWindows, balance }, endpoint: usageRead.url }
|
|
177
185
|
// Partial degradation (issue #274): keep whichever side answered. `partial` names the failing
|
|
178
186
|
// side and its machine-readable cause; it never replaces the existing windows contract.
|
|
179
|
-
if (usageFailure === null) return
|
|
180
|
-
if (walletFailure === null) return {
|
|
187
|
+
if (usageFailure === null) return partialResult(fallbackBalance === null ? usageWindows : { ...usageWindows, balance: fallbackBalance }, usageRead.url, [['wallet', walletFailure]], fallbackBalance !== null)
|
|
188
|
+
if (walletFailure === null) return partialResult({ balance }, walletRead.url, [['usage', usageFailure]])
|
|
189
|
+
// No subscription is a valid preflight answer too: its readable wallet balance
|
|
190
|
+
// must survive an unavailable wallet route, without inventing any quota windows.
|
|
191
|
+
if (fallbackBalance !== null) return partialResult({ balance: fallbackBalance }, usageRead.url, [['usage', usageFailure], ['wallet', walletFailure]], true)
|
|
181
192
|
// Both failed: report the most actionable cause, preferring a definitive account state
|
|
182
193
|
// (no subscription / rejected credential) over a secondary transport or shape failure.
|
|
183
194
|
const priority = [OPEN_DESIGN_QUOTA_FAILURES.noSubscription, OPEN_DESIGN_QUOTA_FAILURES.unauthorized,
|
package/lib/store.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { FX_FIELDS, frozenAmounts, frozenFields, addFrozen, freezeLegacyAmounts, fxRatesOf } from './exchange-rates.js'
|
|
9
|
+
import { normalizeModelStatistics, validModelStatistics } from './model-statistics.js'
|
|
9
10
|
import { readFileSync, renameSync, statSync } from 'node:fs'
|
|
10
11
|
import { randomUUID } from 'node:crypto'
|
|
11
12
|
import { validRequestFee } from './web-request-pricing.js'
|
|
@@ -158,6 +159,7 @@ export function defaultConfig() {
|
|
|
158
159
|
hideOfficialBalance: false, // 隐藏官方账户余额(issue #45):开启后侧边栏/会话页/设置页的官方余额 UI 整体不渲染
|
|
159
160
|
hideBudget: false, // Hide the sidebar budget card without disabling budget tracking.
|
|
160
161
|
hideTodayCost: false, // 隐藏今日消耗金额(issue #46):开启后侧栏今日费用行/预算明细今日行/概览今日卡片不渲染
|
|
162
|
+
modelStatistics: {}, // Per channel/model: today, monthly/all-time summaries and budgets.
|
|
161
163
|
hideSessionCostHeader: false,
|
|
162
164
|
hideSessionCostDock: false,
|
|
163
165
|
hideTurnCost: false,
|
|
@@ -170,6 +172,7 @@ export function defaultConfig() {
|
|
|
170
172
|
includeSubagentCost: false, // 本会话展示可合并连续子代理后代;不重复写入每日账本。
|
|
171
173
|
codexQuotaEnabled: false, // Codex 额度按需开启,避免未使用 Codex 时显示卡片或查询。
|
|
172
174
|
codexQuotaSidebar: true, // 独立控制侧栏卡片,保留会话额度条。
|
|
175
|
+
codexQuotaSource: 'auto', // Codex 额度数据源:auto 自动探测 | connect dsh-codex-connect | subscription dsh-codex-subscription。
|
|
173
176
|
// dsh-codex-subscription 兼容:一次性历史归类提示是否已永久关闭 / 历史归类完成时刻 ms(0 = 未应用)。
|
|
174
177
|
codexCompatPromptDismissed: false,
|
|
175
178
|
codexCompatHistoryAppliedAt: 0,
|
|
@@ -178,7 +181,9 @@ export function defaultConfig() {
|
|
|
178
181
|
sidebarModels: { enabled: false, period: 'today', topN: 5, summary: 'total', position: 'last', defaultOpen: false, remember: true, tokens: false, shares: true, refreshSeconds: 60, dock: false },
|
|
179
182
|
sidebarStyle: 'standard', // 侧边栏进度条样式:standard(标准,纵向单列) | compact(紧凑,额度卡两列网格)
|
|
180
183
|
legacyAutoImportedAt: 0, // 安装前历史自动导入标记(issue #27):完成时刻 ms;0 = 尚未跑过
|
|
181
|
-
peakStyle: 'compact', //
|
|
184
|
+
peakStyle: 'compact', // compact / classic 保留原样;progress 按侧栏布局显示时间进度。
|
|
185
|
+
peakTimeDisplay: 'both', // both / countdown / switch
|
|
186
|
+
peakProgressPromptSeen: false,
|
|
182
187
|
priceMatch: 'auto', // 未知模型名自动匹配价格表:auto(归一化/安全后缀) | exact(仅精确)
|
|
183
188
|
priceMatchDismissed: [], // 从匹配设置中移除的 provider:model 行;不删除用量或改变计价规则。
|
|
184
189
|
priceOverrides: {}, // 手动匹配覆盖:{ 'provider:modelId': 'provider:模型 | deepseek:__default__' };裸模型名 = 同渠道换名(旧版遗留,跨渠道裸 DeepSeek 名由查价兜底自愈,issue #56)
|
|
@@ -788,12 +793,13 @@ const VALIDATION_MESSAGES = {
|
|
|
788
793
|
includeSubagentCost: 'includeSubagentCost 必须是布尔值',
|
|
789
794
|
codexQuotaEnabled: 'codexQuotaEnabled 必须是布尔值',
|
|
790
795
|
codexQuotaSidebar: 'codexQuotaSidebar 必须是布尔值',
|
|
796
|
+
codexQuotaSource: 'codexQuotaSource 必须是 auto / connect / subscription',
|
|
791
797
|
codexCompatPromptDismissed: 'codexCompatPromptDismissed 必须是布尔值',
|
|
792
798
|
codexCompatHistoryAppliedAt: 'codexCompatHistoryAppliedAt 必须是非负数',
|
|
793
799
|
sidebarSimple: '简化显示设置必须是布尔值',
|
|
794
800
|
sidebarModels: '模型花费卡片设置无效:Top-N 为 1–10,刷新间隔为 10–60 秒',
|
|
795
801
|
sidebarStyle: 'sidebarStyle 必须是 standard / compact',
|
|
796
|
-
peakStyle: 'peakStyle 必须是 compact / classic',
|
|
802
|
+
peakStyle: 'peakStyle 必须是 compact / classic / progress',
|
|
797
803
|
priceMatch: 'priceMatch 必须是 auto / exact',
|
|
798
804
|
priceOverrides: 'priceOverrides 必须是字符串→字符串映射',
|
|
799
805
|
priceMatchDismissed: 'priceMatchDismissed 必须是模型键字符串数组(最多 1000 项,每项 1–512 字符)',
|
|
@@ -897,12 +903,13 @@ const VALIDATION_MESSAGES = {
|
|
|
897
903
|
includeSubagentCost: 'includeSubagentCost must be a boolean',
|
|
898
904
|
codexQuotaEnabled: 'codexQuotaEnabled must be a boolean',
|
|
899
905
|
codexQuotaSidebar: 'codexQuotaSidebar must be a boolean',
|
|
906
|
+
codexQuotaSource: 'codexQuotaSource must be auto / connect / subscription',
|
|
900
907
|
codexCompatPromptDismissed: 'codexCompatPromptDismissed must be a boolean',
|
|
901
908
|
codexCompatHistoryAppliedAt: 'codexCompatHistoryAppliedAt must be a non-negative number',
|
|
902
909
|
sidebarSimple: 'Simple display settings must be boolean',
|
|
903
910
|
sidebarModels: 'Invalid model cost card settings: Top-N must be 1–10 and refresh interval 10–60 seconds',
|
|
904
911
|
sidebarStyle: 'sidebarStyle must be standard / compact',
|
|
905
|
-
peakStyle: 'peakStyle must be compact / classic',
|
|
912
|
+
peakStyle: 'peakStyle must be compact / classic / progress',
|
|
906
913
|
priceMatch: 'priceMatch must be auto / exact',
|
|
907
914
|
priceOverrides: 'priceOverrides must be a string→string map',
|
|
908
915
|
priceMatchDismissed: 'priceMatchDismissed must contain at most 1000 model keys of 1–512 characters',
|
|
@@ -1079,6 +1086,7 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1079
1086
|
const candidate = mergeDeep(structuredClone(current), patch)
|
|
1080
1087
|
// 这两张编辑表随对应设置整表提交;逐键深合并会把用户移除的键补回来。
|
|
1081
1088
|
if (Object.hasOwn(patch, 'priceOverrides')) candidate.priceOverrides = structuredClone(patch.priceOverrides)
|
|
1089
|
+
if (Object.hasOwn(patch, 'modelStatistics')) candidate.modelStatistics = structuredClone(patch.modelStatistics)
|
|
1082
1090
|
const qwenPatch = patch.codingPlans?.qwen
|
|
1083
1091
|
if (qwenPatch !== null && typeof qwenPatch === 'object' && !Array.isArray(qwenPatch) && Object.hasOwn(qwenPatch, 'rates')) {
|
|
1084
1092
|
candidate.codingPlans.qwen.rates = structuredClone(qwenPatch.rates)
|
|
@@ -1209,6 +1217,7 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1209
1217
|
if (candidate.hideOfficialBalance !== undefined && typeof candidate.hideOfficialBalance !== 'boolean') errors.push(vmsg(locale, 'hideOfficialBalance'))
|
|
1210
1218
|
if (candidate.hideBudget !== undefined && typeof candidate.hideBudget !== 'boolean') errors.push(vmsg(locale, 'hideBudget'))
|
|
1211
1219
|
if (candidate.hideTodayCost !== undefined && typeof candidate.hideTodayCost !== 'boolean') errors.push(vmsg(locale, 'hideTodayCost'))
|
|
1220
|
+
if (!validModelStatistics(candidate.modelStatistics)) errors.push(locale === 'en' ? 'Invalid per-model statistics switches' : '模型统计开关无效')
|
|
1212
1221
|
for (const key of ['hideSessionCostHeader', 'hideSessionCostDock', 'hideTurnCost']) {
|
|
1213
1222
|
if (candidate[key] !== undefined && typeof candidate[key] !== 'boolean') errors.push(locale === 'en' ? `${key} must be a boolean` : `${key} 必须是布尔值`)
|
|
1214
1223
|
}
|
|
@@ -1222,6 +1231,8 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1222
1231
|
for (const field of ['includeSubagentCost', 'codexQuotaEnabled', 'codexQuotaSidebar', 'codexCompatPromptDismissed']) {
|
|
1223
1232
|
if (candidate[field] !== undefined && typeof candidate[field] !== 'boolean') errors.push(vmsg(locale, field))
|
|
1224
1233
|
}
|
|
1234
|
+
// Codex 额度数据源:auto 自动探测(优先 subscription,失败回退 connect) | connect | subscription。
|
|
1235
|
+
if (candidate.codexQuotaSource !== undefined && !['auto', 'connect', 'subscription'].includes(candidate.codexQuotaSource)) errors.push(vmsg(locale, 'codexQuotaSource'))
|
|
1225
1236
|
// dsh-codex-subscription 兼容:历史归类应用时刻为非负有限数(0 = 尚未应用)。
|
|
1226
1237
|
if (candidate.codexCompatHistoryAppliedAt !== undefined
|
|
1227
1238
|
&& (typeof candidate.codexCompatHistoryAppliedAt !== 'number' || !Number.isFinite(candidate.codexCompatHistoryAppliedAt) || candidate.codexCompatHistoryAppliedAt < 0)) errors.push(vmsg(locale, 'codexCompatHistoryAppliedAt'))
|
|
@@ -1235,7 +1246,9 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1235
1246
|
|| ['enabled', 'defaultOpen', 'remember', 'tokens', 'shares', 'dock'].some(k => typeof sm[k] !== 'boolean')
|
|
1236
1247
|
|| !['today', 'history'].includes(sm.period) || !['total', 'top'].includes(sm.summary) || !['first', 'afterBalance', 'last'].includes(sm.position)
|
|
1237
1248
|
|| !Number.isInteger(sm.topN) || sm.topN < 1 || sm.topN > 10 || !Number.isInteger(sm.refreshSeconds) || sm.refreshSeconds < 10 || sm.refreshSeconds > 60) errors.push(vmsg(locale, 'sidebarModels'))
|
|
1238
|
-
if (
|
|
1249
|
+
if (!['compact', 'classic', 'progress'].includes(candidate.peakStyle)) errors.push(vmsg(locale, 'peakStyle'))
|
|
1250
|
+
if (!['both', 'countdown', 'switch'].includes(candidate.peakTimeDisplay)) errors.push('peakTimeDisplay must be both / countdown / switch')
|
|
1251
|
+
if (typeof candidate.peakProgressPromptSeen !== 'boolean') errors.push('peakProgressPromptSeen must be boolean')
|
|
1239
1252
|
if (candidate.priceMatch !== 'auto' && candidate.priceMatch !== 'exact') errors.push(vmsg(locale, 'priceMatch'))
|
|
1240
1253
|
const overrides = candidate.priceOverrides
|
|
1241
1254
|
if (candidate.priceMatchDismissed !== undefined && (!Array.isArray(candidate.priceMatchDismissed)
|
|
@@ -1566,7 +1579,8 @@ export function sanitizeConfig(raw) {
|
|
|
1566
1579
|
// 枚举收敛。
|
|
1567
1580
|
out.locale = oneOf(out.locale, ['auto', 'zh', 'en'], 'auto')
|
|
1568
1581
|
out.position = oneOf(out.position, ['dock', 'header', 'off'], 'dock')
|
|
1569
|
-
out.peakStyle = oneOf(out.peakStyle, ['compact', 'classic'], 'compact')
|
|
1582
|
+
out.peakStyle = oneOf(out.peakStyle, ['compact', 'classic', 'progress'], 'compact')
|
|
1583
|
+
out.peakTimeDisplay = oneOf(out.peakTimeDisplay, ['both', 'countdown', 'switch'], 'both')
|
|
1570
1584
|
out.priceMatch = oneOf(out.priceMatch, ['auto', 'exact'], 'auto')
|
|
1571
1585
|
// 官方价格币种与价表币种标记(issue #47):非法值回落 USD(价表缺省即 USD)。
|
|
1572
1586
|
out.pricingCurrency = oneOf(out.pricingCurrency, ['USD', 'CNY'], 'USD')
|
|
@@ -1580,6 +1594,7 @@ export function sanitizeConfig(raw) {
|
|
|
1580
1594
|
out.hideOfficialBalance = out.hideOfficialBalance === true
|
|
1581
1595
|
out.hideBudget = out.hideBudget === true
|
|
1582
1596
|
out.hideTodayCost = out.hideTodayCost === true
|
|
1597
|
+
out.modelStatistics = normalizeModelStatistics(out.modelStatistics)
|
|
1583
1598
|
for (const key of ['hideSessionCostHeader', 'hideSessionCostDock', 'hideTurnCost']) out[key] = out[key] === true
|
|
1584
1599
|
out.sessionCostCompact = out.sessionCostCompact === true
|
|
1585
1600
|
out.contextCostsEnabled = out.contextCostsEnabled === true
|
|
@@ -1590,6 +1605,7 @@ export function sanitizeConfig(raw) {
|
|
|
1590
1605
|
out.includeSubagentCost = out.includeSubagentCost === true
|
|
1591
1606
|
out.codexQuotaEnabled = out.codexQuotaEnabled === true
|
|
1592
1607
|
out.codexQuotaSidebar = out.codexQuotaSidebar !== false
|
|
1608
|
+
out.codexQuotaSource = oneOf(out.codexQuotaSource, ['auto', 'connect', 'subscription'], 'auto')
|
|
1593
1609
|
// dsh-codex-subscription 兼容:提示关闭标记收敛为布尔;历史归类完成时刻非法/非正一律归 0。
|
|
1594
1610
|
out.codexCompatPromptDismissed = out.codexCompatPromptDismissed === true
|
|
1595
1611
|
out.codexCompatHistoryAppliedAt = Number.isFinite(out.codexCompatHistoryAppliedAt) && out.codexCompatHistoryAppliedAt > 0 ? out.codexCompatHistoryAppliedAt : 0
|
|
@@ -1862,6 +1878,7 @@ export function sanitizeConfig(raw) {
|
|
|
1862
1878
|
const SECRET_REF_MAP = {
|
|
1863
1879
|
balance: 'DEEPSEEK_BALANCE_API_KEY',
|
|
1864
1880
|
goQuota: 'OPENCODE_GO_API_KEY',
|
|
1881
|
+
'codingPlans.opendesign': 'OPENDESIGN_CONTROL_KEY',
|
|
1865
1882
|
'codingPlans.anthropic': 'ANTHROPIC_OAUTH_TOKEN',
|
|
1866
1883
|
'codingPlans.zai': 'ZAI_API_KEY',
|
|
1867
1884
|
'codingPlans.minimax': 'MINIMAX_API_KEY',
|