@goodandready/dsh-cost-meter 0.8.12 → 0.8.13
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/tariff.js +23 -5
- package/package.json +1 -1
package/lib/tariff.js
CHANGED
|
@@ -30,9 +30,24 @@ export const VENDOR_ALIASES = {
|
|
|
30
30
|
'meta': 'meta-llama',
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** Recursively unwrap cosmokit / Schemastery Volatile<T> reference objects into plain values. */
|
|
34
|
+
export function unwrapVolatile(value) {
|
|
35
|
+
if (value && typeof value.get === 'function') {
|
|
36
|
+
return unwrapVolatile(value.get())
|
|
37
|
+
}
|
|
38
|
+
if (!value || typeof value !== 'object') return value
|
|
39
|
+
if (Array.isArray(value)) return value.map(unwrapVolatile)
|
|
40
|
+
const out = {}
|
|
41
|
+
for (const [k, v] of Object.entries(value)) {
|
|
42
|
+
out[k] = unwrapVolatile(v)
|
|
43
|
+
}
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
33
47
|
/** OpenRouter prices are USD per token; the widget speaks per 1M tokens. */
|
|
34
48
|
export function perMillion(value) {
|
|
35
|
-
const
|
|
49
|
+
const unwrapped = value && typeof value.get === 'function' ? value.get() : value
|
|
50
|
+
const n = Number(unwrapped)
|
|
36
51
|
return Number.isFinite(n) ? n * 1e6 : 0
|
|
37
52
|
}
|
|
38
53
|
|
|
@@ -61,8 +76,9 @@ export function parseWindow(spec) {
|
|
|
61
76
|
}
|
|
62
77
|
|
|
63
78
|
export function overrideBucket(overrideVal, baseVal) {
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
const val = overrideVal && typeof overrideVal.get === 'function' ? overrideVal.get() : overrideVal
|
|
80
|
+
if (val !== undefined && val !== null && val !== '') {
|
|
81
|
+
const n = Number(val)
|
|
66
82
|
if (Number.isFinite(n)) return n * 1e6
|
|
67
83
|
}
|
|
68
84
|
return baseVal
|
|
@@ -165,8 +181,9 @@ export function indexCatalog(models) {
|
|
|
165
181
|
* Resolve one route's tariff: manual config wins, then DeepSeek's own table,
|
|
166
182
|
* then the OpenRouter catalog.
|
|
167
183
|
*/
|
|
168
|
-
export function resolveTariff(
|
|
184
|
+
export function resolveTariff(rawCfg, index, route) {
|
|
169
185
|
if (!route) return { schedule: null, source: 'none', matchedId: null }
|
|
186
|
+
const cfg = unwrapVolatile(rawCfg) || {}
|
|
170
187
|
const key = route.provider ? route.provider + '/' + route.model : route.model
|
|
171
188
|
const prices = cfg.prices || {}
|
|
172
189
|
const manual = prices[key] || prices[route.model] || prices['*']
|
|
@@ -180,7 +197,8 @@ export function resolveTariff(cfg, index, route) {
|
|
|
180
197
|
}
|
|
181
198
|
const factor = Number(cfg.manualOffPeakMultiplier) || 1
|
|
182
199
|
const windows = []
|
|
183
|
-
|
|
200
|
+
const peakWindows = Array.isArray(cfg.manualPeakWindowsUtc) ? cfg.manualPeakWindowsUtc : []
|
|
201
|
+
for (const spec of peakWindows) {
|
|
184
202
|
const parsed = parseWindow(spec)
|
|
185
203
|
if (parsed) windows.push({ start: parsed.start, end: parsed.end, rates: base })
|
|
186
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cost-meter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.13",
|
|
4
4
|
"description": "DeepSeek Harness plugin: a session cost chip in the conversation header - live token usage by bucket, peak/off-peak tariff, and a countdown to the next tariff switch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|