@laoyuehanni/dsh-token-usage 0.3.7
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/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh.md +182 -0
- package/cordis.patch.yml +7 -0
- package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
- package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
- package/lib/client/CostDeltaFlyLabel.js +24 -0
- package/lib/client/CostDeltaFlyLabel.js.map +1 -0
- package/lib/client/HitRateText.d.ts +21 -0
- package/lib/client/HitRateText.d.ts.map +1 -0
- package/lib/client/HitRateText.js +16 -0
- package/lib/client/HitRateText.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +70 -0
- package/lib/client/QuotaButton.d.ts.map +1 -0
- package/lib/client/QuotaButton.js +346 -0
- package/lib/client/QuotaButton.js.map +1 -0
- package/lib/client/SessionStatsChip.d.ts +47 -0
- package/lib/client/SessionStatsChip.d.ts.map +1 -0
- package/lib/client/SessionStatsChip.js +141 -0
- package/lib/client/SessionStatsChip.js.map +1 -0
- package/lib/client/StatCard.d.ts +26 -0
- package/lib/client/StatCard.d.ts.map +1 -0
- package/lib/client/StatCard.js +10 -0
- package/lib/client/StatCard.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts +41 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -0
- package/lib/client/TokenUsageCard.js +164 -0
- package/lib/client/TokenUsageCard.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +32 -0
- package/lib/client/TokenUsageSection.d.ts.map +1 -0
- package/lib/client/TokenUsageSection.js +266 -0
- package/lib/client/TokenUsageSection.js.map +1 -0
- package/lib/client/TrendChart.d.ts +53 -0
- package/lib/client/TrendChart.d.ts.map +1 -0
- package/lib/client/TrendChart.js +141 -0
- package/lib/client/TrendChart.js.map +1 -0
- package/lib/client/UsageView.d.ts +42 -0
- package/lib/client/UsageView.d.ts.map +1 -0
- package/lib/client/UsageView.js +158 -0
- package/lib/client/UsageView.js.map +1 -0
- package/lib/client/async-resource.d.ts +54 -0
- package/lib/client/async-resource.d.ts.map +1 -0
- package/lib/client/async-resource.js +90 -0
- package/lib/client/async-resource.js.map +1 -0
- package/lib/client/card-form.d.ts +171 -0
- package/lib/client/card-form.d.ts.map +1 -0
- package/lib/client/card-form.js +300 -0
- package/lib/client/card-form.js.map +1 -0
- package/lib/client/cost-inflate-motion.d.ts +17 -0
- package/lib/client/cost-inflate-motion.d.ts.map +1 -0
- package/lib/client/cost-inflate-motion.js +61 -0
- package/lib/client/cost-inflate-motion.js.map +1 -0
- package/lib/client/cost-inflate.d.ts +28 -0
- package/lib/client/cost-inflate.d.ts.map +1 -0
- package/lib/client/cost-inflate.js +49 -0
- package/lib/client/cost-inflate.js.map +1 -0
- package/lib/client/day.d.ts +49 -0
- package/lib/client/day.d.ts.map +1 -0
- package/lib/client/day.js +84 -0
- package/lib/client/day.js.map +1 -0
- package/lib/client/format.d.ts +120 -0
- package/lib/client/format.d.ts.map +1 -0
- package/lib/client/format.js +163 -0
- package/lib/client/format.js.map +1 -0
- package/lib/client/index.d.ts +26 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +131 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/locales.d.ts +131 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/locales.js +230 -0
- package/lib/client/locales.js.map +1 -0
- package/lib/client/quota-format.d.ts +69 -0
- package/lib/client/quota-format.d.ts.map +1 -0
- package/lib/client/quota-format.js +147 -0
- package/lib/client/quota-format.js.map +1 -0
- package/lib/client/session-stats.d.ts +105 -0
- package/lib/client/session-stats.d.ts.map +1 -0
- package/lib/client/session-stats.js +142 -0
- package/lib/client/session-stats.js.map +1 -0
- package/lib/client/trend-chart/axis.d.ts +21 -0
- package/lib/client/trend-chart/axis.d.ts.map +1 -0
- package/lib/client/trend-chart/axis.js +33 -0
- package/lib/client/trend-chart/axis.js.map +1 -0
- package/lib/client/trend-chart/bucket.d.ts +24 -0
- package/lib/client/trend-chart/bucket.d.ts.map +1 -0
- package/lib/client/trend-chart/bucket.js +28 -0
- package/lib/client/trend-chart/bucket.js.map +1 -0
- package/lib/client/trend-chart/index.d.ts +12 -0
- package/lib/client/trend-chart/index.d.ts.map +1 -0
- package/lib/client/trend-chart/index.js +9 -0
- package/lib/client/trend-chart/index.js.map +1 -0
- package/lib/client/trend-chart/points.d.ts +46 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -0
- package/lib/client/trend-chart/points.js +82 -0
- package/lib/client/trend-chart/points.js.map +1 -0
- package/lib/client/trend-chart/scale.d.ts +47 -0
- package/lib/client/trend-chart/scale.d.ts.map +1 -0
- package/lib/client/trend-chart/scale.js +75 -0
- package/lib/client/trend-chart/scale.js.map +1 -0
- package/lib/client/use-color-scheme.d.ts +18 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -0
- package/lib/client/use-color-scheme.js +37 -0
- package/lib/client/use-color-scheme.js.map +1 -0
- package/lib/client/use-cost-inflate.d.ts +33 -0
- package/lib/client/use-cost-inflate.d.ts.map +1 -0
- package/lib/client/use-cost-inflate.js +108 -0
- package/lib/client/use-cost-inflate.js.map +1 -0
- package/lib/client.js +3892 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +599 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +60 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +126 -0
- package/lib/migrate.js.map +1 -0
- package/lib/pricing.d.ts +212 -0
- package/lib/pricing.d.ts.map +1 -0
- package/lib/pricing.js +492 -0
- package/lib/pricing.js.map +1 -0
- package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
- package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
- package/lib/quota/adapters/deepseek-balance.js +76 -0
- package/lib/quota/adapters/deepseek-balance.js.map +1 -0
- package/lib/quota/adapters/kimi.d.ts +26 -0
- package/lib/quota/adapters/kimi.d.ts.map +1 -0
- package/lib/quota/adapters/kimi.js +91 -0
- package/lib/quota/adapters/kimi.js.map +1 -0
- package/lib/quota/adapters/minimax.d.ts +24 -0
- package/lib/quota/adapters/minimax.d.ts.map +1 -0
- package/lib/quota/adapters/minimax.js +136 -0
- package/lib/quota/adapters/minimax.js.map +1 -0
- package/lib/quota/adapters/opencode-go.d.ts +25 -0
- package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
- package/lib/quota/adapters/opencode-go.js +105 -0
- package/lib/quota/adapters/opencode-go.js.map +1 -0
- package/lib/quota/adapters/openrouter.d.ts +15 -0
- package/lib/quota/adapters/openrouter.d.ts.map +1 -0
- package/lib/quota/adapters/openrouter.js +54 -0
- package/lib/quota/adapters/openrouter.js.map +1 -0
- package/lib/quota/adapters/zhipu.d.ts +38 -0
- package/lib/quota/adapters/zhipu.d.ts.map +1 -0
- package/lib/quota/adapters/zhipu.js +246 -0
- package/lib/quota/adapters/zhipu.js.map +1 -0
- package/lib/quota/credentials.d.ts +79 -0
- package/lib/quota/credentials.d.ts.map +1 -0
- package/lib/quota/credentials.js +130 -0
- package/lib/quota/credentials.js.map +1 -0
- package/lib/quota/http.d.ts +49 -0
- package/lib/quota/http.d.ts.map +1 -0
- package/lib/quota/http.js +114 -0
- package/lib/quota/http.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +45 -0
- package/lib/quota/provider-tracking.d.ts.map +1 -0
- package/lib/quota/provider-tracking.js +52 -0
- package/lib/quota/provider-tracking.js.map +1 -0
- package/lib/quota/quota-route.d.ts +22 -0
- package/lib/quota/quota-route.d.ts.map +1 -0
- package/lib/quota/quota-route.js +57 -0
- package/lib/quota/quota-route.js.map +1 -0
- package/lib/quota/quota-service.d.ts +54 -0
- package/lib/quota/quota-service.d.ts.map +1 -0
- package/lib/quota/quota-service.js +171 -0
- package/lib/quota/quota-service.js.map +1 -0
- package/lib/quota/registry.d.ts +24 -0
- package/lib/quota/registry.d.ts.map +1 -0
- package/lib/quota/registry.js +38 -0
- package/lib/quota/registry.js.map +1 -0
- package/lib/quota/types.d.ts +79 -0
- package/lib/quota/types.d.ts.map +1 -0
- package/lib/quota/types.js +24 -0
- package/lib/quota/types.js.map +1 -0
- package/lib/record-cache.d.ts +38 -0
- package/lib/record-cache.d.ts.map +1 -0
- package/lib/record-cache.js +143 -0
- package/lib/record-cache.js.map +1 -0
- package/lib/rollup.d.ts +52 -0
- package/lib/rollup.d.ts.map +1 -0
- package/lib/rollup.js +117 -0
- package/lib/rollup.js.map +1 -0
- package/lib/stats-route.d.ts +88 -0
- package/lib/stats-route.d.ts.map +1 -0
- package/lib/stats-route.js +313 -0
- package/lib/stats-route.js.map +1 -0
- package/lib/stats.d.ts +158 -0
- package/lib/stats.d.ts.map +1 -0
- package/lib/stats.js +426 -0
- package/lib/stats.js.map +1 -0
- package/lib/sync-state.d.ts +27 -0
- package/lib/sync-state.d.ts.map +1 -0
- package/lib/sync-state.js +56 -0
- package/lib/sync-state.js.map +1 -0
- package/lib/sync.d.ts +74 -0
- package/lib/sync.d.ts.map +1 -0
- package/lib/sync.js +64 -0
- package/lib/sync.js.map +1 -0
- package/lib/trend-bucket.d.ts +48 -0
- package/lib/trend-bucket.d.ts.map +1 -0
- package/lib/trend-bucket.js +87 -0
- package/lib/trend-bucket.js.map +1 -0
- package/lib/usage-log.d.ts +64 -0
- package/lib/usage-log.d.ts.map +1 -0
- package/lib/usage-log.js +144 -0
- package/lib/usage-log.js.map +1 -0
- package/lib/usage-record.d.ts +59 -0
- package/lib/usage-record.d.ts.map +1 -0
- package/lib/usage-record.js +115 -0
- package/lib/usage-record.js.map +1 -0
- package/lib/wire.d.ts +452 -0
- package/lib/wire.d.ts.map +1 -0
- package/lib/wire.js +144 -0
- package/lib/wire.js.map +1 -0
- package/package.json +100 -0
package/lib/pricing.js
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing vocabulary and store of the token-usage plugin: the per-model
|
|
3
|
+
* price rules (¥ per million tokens) backing the cost figures of the stats
|
|
4
|
+
* page. Two sources merge on read — the cloud feed mirrored on every dsh
|
|
5
|
+
* startup into `<data dir>/pricing.ccsa.json` (the same model-price-table
|
|
6
|
+
* source cc-switch-analyzer pulls), and the hand-edited `<data
|
|
7
|
+
* dir>/pricing.json`, whose entries always win and replace a model's cloud
|
|
8
|
+
* rules wholesale. Absent files mean no pricing; a malformed file logs once
|
|
9
|
+
* and reads as empty, so a broken table never blocks the stats route.
|
|
10
|
+
*
|
|
11
|
+
* Every record is priced individually through the analyzer's rule chain —
|
|
12
|
+
* time-rule container first, then context tier, then peak slot — and the
|
|
13
|
+
* aggregation keeps rows per (day, model, rate identity), so re-pricing
|
|
14
|
+
* under an updated table needs no rollup rebuild. The context size for tier
|
|
15
|
+
* matching is approximated by the request's input-side tokens (input +
|
|
16
|
+
* cacheRead + cacheWrite): the log does not carry the raw context size.
|
|
17
|
+
*
|
|
18
|
+
* @module token-usage/pricing
|
|
19
|
+
*/
|
|
20
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
21
|
+
import { dirname, join } from 'node:path';
|
|
22
|
+
/** The hand-maintained pricing file inside the data directory. */
|
|
23
|
+
export const PRICING_FILE = 'pricing.json';
|
|
24
|
+
/** The cloud-feed mirror written on every startup. */
|
|
25
|
+
export const PRICING_CCSA_FILE = 'pricing.ccsa.json';
|
|
26
|
+
/**
|
|
27
|
+
* The default domestic (China) cloud pricing feed: the model-price-table
|
|
28
|
+
* repository the analyzer also pulls from (¥ per million tokens, currency
|
|
29
|
+
* RMB). Overridden through the `pricingUrlDomestic` config key.
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_PRICING_URL_DOMESTIC = 'https://gitee.com/oyw125/model-price-table/raw/master/model_pricing.json';
|
|
32
|
+
/**
|
|
33
|
+
* The default overseas cloud pricing feed: the same model-price-table,
|
|
34
|
+
* mirrored to GitHub because the gitee CDN is slow or unreliable outside
|
|
35
|
+
* mainland China. Overridden through the `pricingUrlOverseas` config key.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_PRICING_URL_OVERSEAS = 'https://raw.githubusercontent.com/LaoYueHanNi/model-price-table/master/model_pricing.json';
|
|
38
|
+
/** Backward-compatible alias: the domestic (gitee) default feed. */
|
|
39
|
+
export const DEFAULT_PRICING_URL = DEFAULT_PRICING_URL_DOMESTIC;
|
|
40
|
+
/**
|
|
41
|
+
* The RMB-per-USD rate used for display conversion when the cloud feed's
|
|
42
|
+
* envelope does not carry a usable `usdExchangeRate` (older mirrors). The
|
|
43
|
+
* feed owns the number; this is only the stand-in until it lands.
|
|
44
|
+
*/
|
|
45
|
+
export const DEFAULT_USD_EXCHANGE_RATE = 7;
|
|
46
|
+
/**
|
|
47
|
+
* Resolve the feed URL to fetch: an explicit `pricingUrl` wins outright;
|
|
48
|
+
* otherwise `pricingRegion` picks the domestic (default) or overseas mirror,
|
|
49
|
+
* each overridable through its own key. Deliberately no IP sniffing — the
|
|
50
|
+
* deployer sets the region once in the profile config, so the choice is
|
|
51
|
+
* predictable and never depends on a third-party geo lookup.
|
|
52
|
+
*/
|
|
53
|
+
export function resolvePricingUrl(input = {}) {
|
|
54
|
+
if (input.pricingUrl !== undefined)
|
|
55
|
+
return input.pricingUrl;
|
|
56
|
+
if (input.pricingRegion === 'overseas') {
|
|
57
|
+
return input.pricingUrlOverseas ?? DEFAULT_PRICING_URL_OVERSEAS;
|
|
58
|
+
}
|
|
59
|
+
return input.pricingUrlDomestic ?? DEFAULT_PRICING_URL_DOMESTIC;
|
|
60
|
+
}
|
|
61
|
+
/** A positive (or zero) finite number; rates may be 0 but never negative. */
|
|
62
|
+
function isRate(value) {
|
|
63
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
64
|
+
}
|
|
65
|
+
/** A usable exchange rate: finite and strictly positive (0 would divide by zero). */
|
|
66
|
+
function isExchangeRate(value) {
|
|
67
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
68
|
+
}
|
|
69
|
+
function coerceRates(value) {
|
|
70
|
+
if (typeof value !== 'object' || value === null)
|
|
71
|
+
return null;
|
|
72
|
+
const node = value;
|
|
73
|
+
if (!isRate(node.inputCostPerMillion) || !isRate(node.outputCostPerMillion))
|
|
74
|
+
return null;
|
|
75
|
+
return {
|
|
76
|
+
inputCostPerMillion: node.inputCostPerMillion,
|
|
77
|
+
outputCostPerMillion: node.outputCostPerMillion,
|
|
78
|
+
...(isRate(node.cacheReadCostPerMillion) ? { cacheReadCostPerMillion: node.cacheReadCostPerMillion } : {}),
|
|
79
|
+
...(isRate(node.cacheCreationCostPerMillion) ? { cacheCreationCostPerMillion: node.cacheCreationCostPerMillion } : {}),
|
|
80
|
+
...(Array.isArray(node.dailySlots) ? { dailySlots: node.dailySlots.filter(isCloudSlot) } : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function coerceTier(value) {
|
|
84
|
+
if (typeof value !== 'object' || value === null)
|
|
85
|
+
return null;
|
|
86
|
+
const tier = value;
|
|
87
|
+
if (!isRate(tier.threshold))
|
|
88
|
+
return null;
|
|
89
|
+
const rates = coerceRates(value);
|
|
90
|
+
return rates === null ? null : { ...rates, threshold: tier.threshold };
|
|
91
|
+
}
|
|
92
|
+
function isCloudSlot(value) {
|
|
93
|
+
return coerceSlot(value) !== null;
|
|
94
|
+
}
|
|
95
|
+
function coerceSlot(value) {
|
|
96
|
+
if (typeof value !== 'object' || value === null)
|
|
97
|
+
return null;
|
|
98
|
+
const slot = value;
|
|
99
|
+
if (!Array.isArray(slot.windows))
|
|
100
|
+
return null;
|
|
101
|
+
const windows = [];
|
|
102
|
+
for (const window of slot.windows) {
|
|
103
|
+
if (typeof window !== 'object' || window === null)
|
|
104
|
+
continue;
|
|
105
|
+
const w = window;
|
|
106
|
+
if (isRate(w.startMinute) && isRate(w.endMinute))
|
|
107
|
+
windows.push({ startMinute: w.startMinute, endMinute: w.endMinute });
|
|
108
|
+
}
|
|
109
|
+
if (windows.length === 0)
|
|
110
|
+
return null;
|
|
111
|
+
const rates = coerceRates(value);
|
|
112
|
+
if (rates === null)
|
|
113
|
+
return null;
|
|
114
|
+
return {
|
|
115
|
+
windows,
|
|
116
|
+
inputCostPerMillion: rates.inputCostPerMillion,
|
|
117
|
+
outputCostPerMillion: rates.outputCostPerMillion,
|
|
118
|
+
...(rates.cacheReadCostPerMillion !== undefined ? { cacheReadCostPerMillion: rates.cacheReadCostPerMillion } : {}),
|
|
119
|
+
...(rates.cacheCreationCostPerMillion !== undefined ? { cacheCreationCostPerMillion: rates.cacheCreationCostPerMillion } : {}),
|
|
120
|
+
...(typeof slot.label === 'string' ? { label: slot.label } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function coerceTimeRule(value) {
|
|
124
|
+
if (typeof value !== 'object' || value === null)
|
|
125
|
+
return null;
|
|
126
|
+
const rule = value;
|
|
127
|
+
if (!isRate(rule.startTime) || !isRate(rule.endTime))
|
|
128
|
+
return null;
|
|
129
|
+
const rates = coerceRates(value);
|
|
130
|
+
if (rates === null)
|
|
131
|
+
return null;
|
|
132
|
+
const tiers = Array.isArray(rule.contextTiers)
|
|
133
|
+
? rule.contextTiers.map(coerceTier).filter((tier) => tier !== null)
|
|
134
|
+
: [];
|
|
135
|
+
return {
|
|
136
|
+
...rates,
|
|
137
|
+
startTime: rule.startTime,
|
|
138
|
+
endTime: rule.endTime,
|
|
139
|
+
...(typeof rule.label === 'string' ? { label: rule.label } : {}),
|
|
140
|
+
...(tiers.length > 0 ? { contextTiers: tiers } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Coerce an unknown value into the cloud feed shape, dropping invalid model
|
|
145
|
+
* rows. A wrong envelope (non-array models, non-object) reads as null, and
|
|
146
|
+
* so does a non-RMB `currency` — this plugin bills in ¥ only.
|
|
147
|
+
* @param value - the parsed `pricing.ccsa.json` content.
|
|
148
|
+
* @returns the feed, or null when the value is not a usable RMB feed.
|
|
149
|
+
*/
|
|
150
|
+
export function coerceCloudPricing(value) {
|
|
151
|
+
if (typeof value !== 'object' || value === null)
|
|
152
|
+
return null;
|
|
153
|
+
const feed = value;
|
|
154
|
+
if (!Array.isArray(feed.models))
|
|
155
|
+
return null;
|
|
156
|
+
if (typeof feed.currency !== 'string' || feed.currency !== 'RMB')
|
|
157
|
+
return null;
|
|
158
|
+
const models = [];
|
|
159
|
+
for (const raw of feed.models) {
|
|
160
|
+
if (typeof raw !== 'object' || raw === null)
|
|
161
|
+
continue;
|
|
162
|
+
const row = raw;
|
|
163
|
+
const rates = coerceRates(raw);
|
|
164
|
+
if (rates === null || typeof row.modelId !== 'string' || row.modelId === '')
|
|
165
|
+
continue;
|
|
166
|
+
models.push({
|
|
167
|
+
...rates,
|
|
168
|
+
modelId: row.modelId,
|
|
169
|
+
...(Array.isArray(row.contextTiers)
|
|
170
|
+
? {
|
|
171
|
+
contextTiers: row.contextTiers.map(coerceTier)
|
|
172
|
+
.filter((tier) => tier !== null),
|
|
173
|
+
}
|
|
174
|
+
: {}),
|
|
175
|
+
...(Array.isArray(row.timeRules)
|
|
176
|
+
? {
|
|
177
|
+
timeRules: row.timeRules.map(coerceTimeRule)
|
|
178
|
+
.filter((rule) => rule !== null),
|
|
179
|
+
}
|
|
180
|
+
: {}),
|
|
181
|
+
...(Array.isArray(row.aliases) && row.aliases.every(alias => typeof alias === 'string')
|
|
182
|
+
? { aliases: row.aliases }
|
|
183
|
+
: {}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
version: typeof feed.version === 'number' ? feed.version : 0,
|
|
188
|
+
updatedAt: typeof feed.updatedAt === 'number' ? feed.updatedAt : 0,
|
|
189
|
+
currency: feed.currency,
|
|
190
|
+
...(isExchangeRate(feed.usdExchangeRate) ? { usdExchangeRate: feed.usdExchangeRate } : {}),
|
|
191
|
+
models,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// Cloud feed → ModelRates
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
/** Map one raw rate node onto the wire's per-million prices. */
|
|
198
|
+
function toPricing(rates) {
|
|
199
|
+
return {
|
|
200
|
+
inputPerMillion: rates.inputCostPerMillion,
|
|
201
|
+
outputPerMillion: rates.outputCostPerMillion,
|
|
202
|
+
...(rates.cacheReadCostPerMillion !== undefined ? { cacheReadPerMillion: rates.cacheReadCostPerMillion } : {}),
|
|
203
|
+
...(rates.cacheCreationCostPerMillion !== undefined ? { cacheWritePerMillion: rates.cacheCreationCostPerMillion } : {}),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function toSlots(slots) {
|
|
207
|
+
return slots?.map(slot => ({ windows: slot.windows, rates: toPricing(slot) })) ?? [];
|
|
208
|
+
}
|
|
209
|
+
function toTiers(tiers) {
|
|
210
|
+
return tiers?.map(tier => ({
|
|
211
|
+
threshold: tier.threshold,
|
|
212
|
+
rates: toPricing(tier),
|
|
213
|
+
...(tier.dailySlots !== undefined ? { dailySlots: toSlots(tier.dailySlots) } : {}),
|
|
214
|
+
})) ?? [];
|
|
215
|
+
}
|
|
216
|
+
function toTimeRules(rules) {
|
|
217
|
+
return rules?.map(rule => ({
|
|
218
|
+
startTime: rule.startTime,
|
|
219
|
+
endTime: rule.endTime,
|
|
220
|
+
rates: toPricing(rule),
|
|
221
|
+
...(rule.contextTiers !== undefined ? { contextTiers: toTiers(rule.contextTiers) } : {}),
|
|
222
|
+
...(rule.dailySlots !== undefined ? { dailySlots: toSlots(rule.dailySlots) } : {}),
|
|
223
|
+
...(rule.label !== undefined ? { label: rule.label } : {}),
|
|
224
|
+
})) ?? [];
|
|
225
|
+
}
|
|
226
|
+
/** The full rule set of one raw cloud model row. */
|
|
227
|
+
function cloudModelRates(model) {
|
|
228
|
+
return {
|
|
229
|
+
base: toPricing(model),
|
|
230
|
+
contextTiers: toTiers(model.contextTiers),
|
|
231
|
+
dailySlots: toSlots(model.dailySlots),
|
|
232
|
+
timeRules: toTimeRules(model.timeRules),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Flatten one cloud feed into a pricing table: every `modelId` becomes a key
|
|
237
|
+
* and every alias becomes a key holding the same rule set. Aliases land
|
|
238
|
+
* first, ids last, so a model id always wins a collision with another
|
|
239
|
+
* model's alias.
|
|
240
|
+
* @param feed - the coerced cloud feed.
|
|
241
|
+
* @returns the flat table keyed by model ids and aliases.
|
|
242
|
+
*/
|
|
243
|
+
export function cloudToTable(feed) {
|
|
244
|
+
const table = {};
|
|
245
|
+
for (const model of feed.models) {
|
|
246
|
+
for (const alias of model.aliases ?? []) {
|
|
247
|
+
if (alias !== '' && !(alias in table))
|
|
248
|
+
table[alias] = cloudModelRates(model);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const model of feed.models)
|
|
252
|
+
table[model.modelId] = cloudModelRates(model);
|
|
253
|
+
return table;
|
|
254
|
+
}
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
// Per-record rate resolution (the analyzer's rule chain)
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
/** The context tier matching a context size: the highest threshold it reaches. */
|
|
259
|
+
function resolveTier(tiers, contextSize) {
|
|
260
|
+
let best = null;
|
|
261
|
+
for (const tier of tiers) {
|
|
262
|
+
if (tier.threshold <= contextSize && (best === null || tier.threshold > best.threshold))
|
|
263
|
+
best = tier;
|
|
264
|
+
}
|
|
265
|
+
return best;
|
|
266
|
+
}
|
|
267
|
+
/** The local minute-of-day of a Unix-seconds timestamp under a tz offset in hours. */
|
|
268
|
+
function localMinuteOfDay(epochSeconds, tzOffsetHours) {
|
|
269
|
+
const local = epochSeconds + tzOffsetHours * 3600;
|
|
270
|
+
const secondOfDay = ((local % 86400) + 86400) % 86400;
|
|
271
|
+
return Math.floor(secondOfDay / 60);
|
|
272
|
+
}
|
|
273
|
+
/** The first peak slot whose windows contain the timestamp's local minute; -1 when off-peak. */
|
|
274
|
+
function matchingSlot(slots, epochSeconds, tzOffsetHours) {
|
|
275
|
+
if (slots === undefined || slots.length === 0)
|
|
276
|
+
return -1;
|
|
277
|
+
const minute = localMinuteOfDay(epochSeconds, tzOffsetHours);
|
|
278
|
+
for (let index = 0; index < slots.length; index++) {
|
|
279
|
+
for (const window of slots[index].windows) {
|
|
280
|
+
if (window.startMinute <= minute && minute < window.endMinute)
|
|
281
|
+
return index;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return -1;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Resolve the rate one request was billed at, mirroring the analyzer's chain:
|
|
288
|
+
* the time rule covering the timestamp first (its tiers, its slots), else
|
|
289
|
+
* the model root (its tiers, its slots), else the base rates.
|
|
290
|
+
* @param rates - the model's full rule set.
|
|
291
|
+
* @param timeMs - the request's epoch milliseconds.
|
|
292
|
+
* @param contextTokens - the request's input-side tokens (tier approximation).
|
|
293
|
+
* @param tzOffsetHours - local tz offset in hours for peak windows
|
|
294
|
+
* (defaults to the host's).
|
|
295
|
+
* @returns the billed prices plus the identity they resolved through.
|
|
296
|
+
*/
|
|
297
|
+
export function resolveRate(rates, timeMs, contextTokens, tzOffsetHours = -new Date().getTimezoneOffset() / 60) {
|
|
298
|
+
const seconds = Math.floor(timeMs / 1000);
|
|
299
|
+
const rule = rates.timeRules.find(r => seconds >= r.startTime && seconds <= r.endTime) ?? null;
|
|
300
|
+
const tiers = rule?.contextTiers ?? rates.contextTiers;
|
|
301
|
+
const tier = resolveTier(tiers, contextTokens);
|
|
302
|
+
// Peak slots hang on each node itself (the rule's, the tier's, or the
|
|
303
|
+
// model root's) — a rule without slots bills flat inside its window, they
|
|
304
|
+
// never inherit down from the root.
|
|
305
|
+
const node = tier !== null
|
|
306
|
+
? { rates: tier.rates, slots: tier.dailySlots ?? [] }
|
|
307
|
+
: rule !== null
|
|
308
|
+
? { rates: rule.rates, slots: rule.dailySlots ?? [] }
|
|
309
|
+
: { rates: rates.base, slots: rates.dailySlots };
|
|
310
|
+
const slot = matchingSlot(node.slots, seconds, tzOffsetHours);
|
|
311
|
+
return {
|
|
312
|
+
prices: slot >= 0 ? node.slots[slot].rates : node.rates,
|
|
313
|
+
key: {
|
|
314
|
+
ruleStart: rule?.startTime ?? 0,
|
|
315
|
+
ruleEnd: rule?.endTime ?? 0,
|
|
316
|
+
tier: tier?.threshold ?? 0,
|
|
317
|
+
slot,
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Look the prices of a rate identity back up under the current rule set —
|
|
323
|
+
* the re-pricing path for aggregated rows. Structural drift (a rule window
|
|
324
|
+
* or tier threshold that no longer exists) falls back toward the base rates,
|
|
325
|
+
* so an edited table degrades gracefully instead of mis-billing.
|
|
326
|
+
* @param rates - the model's full rule set.
|
|
327
|
+
* @param key - the identity one aggregation row carries.
|
|
328
|
+
* @returns the prices the key resolves to.
|
|
329
|
+
*/
|
|
330
|
+
export function ratesForKey(rates, key) {
|
|
331
|
+
const rule = key.ruleStart !== 0 || key.ruleEnd !== 0
|
|
332
|
+
? rates.timeRules.find(r => r.startTime === key.ruleStart && r.endTime === key.ruleEnd) ?? null
|
|
333
|
+
: null;
|
|
334
|
+
const tiers = rule?.contextTiers ?? rates.contextTiers;
|
|
335
|
+
const tier = key.tier > 0 ? tiers.find(t => t.threshold === key.tier) ?? null : null;
|
|
336
|
+
// Same node chain as resolveRate: peak slots hang on the node itself.
|
|
337
|
+
const node = tier !== null
|
|
338
|
+
? { rates: tier.rates, slots: tier.dailySlots ?? [] }
|
|
339
|
+
: rule !== null
|
|
340
|
+
? { rates: rule.rates, slots: rule.dailySlots ?? [] }
|
|
341
|
+
: { rates: rates.base, slots: rates.dailySlots };
|
|
342
|
+
return key.slot >= 0 ? node.slots[key.slot]?.rates ?? node.rates : node.rates;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Billed cost of one totals row at resolved prices: each bucket billed at
|
|
346
|
+
* its own per-million rate, cache buckets billed at their rate when present
|
|
347
|
+
* and at the plain input rate otherwise (providers that fold cache tokens
|
|
348
|
+
* into input still bill them, just at the same rate).
|
|
349
|
+
* @param totals - the aggregated token buckets.
|
|
350
|
+
* @param prices - the resolved per-million prices.
|
|
351
|
+
* @returns the cost in ¥.
|
|
352
|
+
*/
|
|
353
|
+
export function costOf(totals, prices) {
|
|
354
|
+
const M = 1_000_000;
|
|
355
|
+
const cacheRead = prices.cacheReadPerMillion ?? prices.inputPerMillion;
|
|
356
|
+
const cacheWrite = prices.cacheWritePerMillion ?? prices.inputPerMillion;
|
|
357
|
+
return (totals.inputTokens * prices.inputPerMillion
|
|
358
|
+
+ totals.outputTokens * prices.outputPerMillion
|
|
359
|
+
+ totals.cacheReadTokens * cacheRead
|
|
360
|
+
+ totals.cacheWriteTokens * cacheWrite) / M;
|
|
361
|
+
}
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// File store: cloud mirror + manual overrides
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
/** Read one JSON file of a data directory, or null when absent/unreadable. */
|
|
366
|
+
async function readJsonFile(dir, name) {
|
|
367
|
+
let text;
|
|
368
|
+
try {
|
|
369
|
+
text = await readFile(join(dir, name), 'utf8');
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
if (error.code === 'ENOENT')
|
|
373
|
+
return null;
|
|
374
|
+
console.error(`[token-usage] cannot read ${name}:`, error);
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
return JSON.parse(text);
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
console.error(`[token-usage] ${name} is not valid JSON; treating as absent`);
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function isModelPricing(value) {
|
|
386
|
+
if (typeof value !== 'object' || value === null)
|
|
387
|
+
return false;
|
|
388
|
+
const pricing = value;
|
|
389
|
+
return isRate(pricing.inputPerMillion) && isRate(pricing.outputPerMillion)
|
|
390
|
+
&& (pricing.cacheReadPerMillion === undefined || isRate(pricing.cacheReadPerMillion))
|
|
391
|
+
&& (pricing.cacheWritePerMillion === undefined || isRate(pricing.cacheWritePerMillion));
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Coerce a hand-edited file body into flat table entries (base rates only):
|
|
395
|
+
* non-object values read as empty, invalid entries drop.
|
|
396
|
+
* @param value - the parsed `pricing.json` content.
|
|
397
|
+
* @returns model id → base rates.
|
|
398
|
+
*/
|
|
399
|
+
export function coercePricingTable(value) {
|
|
400
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
401
|
+
return {};
|
|
402
|
+
const table = {};
|
|
403
|
+
for (const [model, entry] of Object.entries(value)) {
|
|
404
|
+
if (model === '' || !isModelPricing(entry))
|
|
405
|
+
continue;
|
|
406
|
+
table[model] = entry;
|
|
407
|
+
}
|
|
408
|
+
return table;
|
|
409
|
+
}
|
|
410
|
+
/** The hand-maintained entries of one data directory ({} when absent/broken). */
|
|
411
|
+
async function readManualPricing(dir) {
|
|
412
|
+
return coercePricingTable(await readJsonFile(dir, PRICING_FILE));
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* The synced cloud table of one data directory: the coerced feed mirror
|
|
416
|
+
* flattened through {@link cloudToTable} ({} when absent, broken, or non-RMB).
|
|
417
|
+
*/
|
|
418
|
+
async function readSyncedPricing(dir) {
|
|
419
|
+
const feed = coerceCloudPricing(await readJsonFile(dir, PRICING_CCSA_FILE));
|
|
420
|
+
return feed === null ? {} : cloudToTable(feed);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Load the merged pricing table of one data directory: the synced cloud
|
|
424
|
+
* mirror as the base, the hand-edited `pricing.json` layered on top — a
|
|
425
|
+
* manual entry wins for its whole model (base rates, no cloud rules), so
|
|
426
|
+
* manual tweaks survive re-syncs. A missing or malformed file contributes
|
|
427
|
+
* nothing, keeping the stats route alive while the user fixes their table.
|
|
428
|
+
* @param dir - the plugin's data directory.
|
|
429
|
+
* @returns the validated, merged table (possibly empty).
|
|
430
|
+
*/
|
|
431
|
+
export async function readPricingTable(dir) {
|
|
432
|
+
const merged = { ...await readSyncedPricing(dir) };
|
|
433
|
+
for (const [model, base] of Object.entries(await readManualPricing(dir))) {
|
|
434
|
+
merged[model] = { base, contextTiers: [], dailySlots: [], timeRules: [] };
|
|
435
|
+
}
|
|
436
|
+
return merged;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The effective USD conversion rate (RMB per USD) of one data directory:
|
|
440
|
+
* the cloud feed envelope's `usdExchangeRate` when it carries a usable one,
|
|
441
|
+
* else {@link DEFAULT_USD_EXCHANGE_RATE}. Absent, malformed, or non-RMB
|
|
442
|
+
* mirrors fall back the same way — display conversion never blocks on a
|
|
443
|
+
* broken feed. Hand-edited `pricing.json` carries no rate and never wins.
|
|
444
|
+
* @param dir - the plugin's data directory.
|
|
445
|
+
* @returns the positive rate the stats page converts display costs with.
|
|
446
|
+
*/
|
|
447
|
+
export async function readUsdExchangeRate(dir) {
|
|
448
|
+
const feed = coerceCloudPricing(await readJsonFile(dir, PRICING_CCSA_FILE));
|
|
449
|
+
return feed?.usdExchangeRate ?? DEFAULT_USD_EXCHANGE_RATE;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Fetch the cloud pricing feed and mirror it verbatim into
|
|
453
|
+
* `<data dir>/pricing.ccsa.json` (atomically: temp file + rename). The raw
|
|
454
|
+
* feed is stored as received; the flatten-and-merge happens on read.
|
|
455
|
+
* @param dir - the plugin's data directory.
|
|
456
|
+
* @param url - the feed URL (the config override or the default gitee feed).
|
|
457
|
+
* @returns the sync summary.
|
|
458
|
+
*/
|
|
459
|
+
export async function syncCloudPricing(dir, url) {
|
|
460
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(5_000) });
|
|
461
|
+
if (!response.ok)
|
|
462
|
+
throw new Error(`HTTP ${String(response.status)}`);
|
|
463
|
+
const text = await response.text();
|
|
464
|
+
// Mirror the analyzer's payload cap: refuse feeds too big to be sane.
|
|
465
|
+
if (text.length > 1_048_576)
|
|
466
|
+
throw new Error('feed exceeds the 1MB limit');
|
|
467
|
+
let value;
|
|
468
|
+
try {
|
|
469
|
+
value = JSON.parse(text);
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
throw new Error('feed is not valid JSON');
|
|
473
|
+
}
|
|
474
|
+
const feed = coerceCloudPricing(value);
|
|
475
|
+
if (feed === null)
|
|
476
|
+
throw new Error('feed is not a valid RMB pricing table');
|
|
477
|
+
const target = join(dir, PRICING_CCSA_FILE);
|
|
478
|
+
const tmp = join(dir, `${PRICING_CCSA_FILE}.tmp`);
|
|
479
|
+
// A fresh install may not have recorded any usage yet, so the data dir can
|
|
480
|
+
// legitimately not exist — create it (idempotent) before the mirror lands.
|
|
481
|
+
await mkdir(dirname(target), { recursive: true });
|
|
482
|
+
await writeFile(tmp, text.endsWith('\n') ? text : `${text}\n`, 'utf8');
|
|
483
|
+
await rename(tmp, target);
|
|
484
|
+
return {
|
|
485
|
+
version: feed.version,
|
|
486
|
+
updatedAt: feed.updatedAt,
|
|
487
|
+
models: feed.models.length,
|
|
488
|
+
aliases: feed.models.reduce((sum, model) => sum + (model.aliases?.length ?? 0), 0),
|
|
489
|
+
usdExchangeRate: feed.usdExchangeRate ?? DEFAULT_USD_EXCHANGE_RATE,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,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EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAClF,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,yBAAyB;KACnE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek balance adapter: the pay-as-you-go account balance of the
|
|
3
|
+
* official DeepSeek platform — the dsh default provider (`deepseek-official`).
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET {root}/user/balance` with a Bearer key. The root is the
|
|
6
|
+
* profile's inference `baseURL` with a trailing OpenAI-compatible `/v1`
|
|
7
|
+
* stripped (so `https://api.deepseek.com/v1` hits the official
|
|
8
|
+
* `/user/balance`, not `/v1/user/balance`), defaulting to
|
|
9
|
+
* `https://api.deepseek.com`. The response lists one entry per currency;
|
|
10
|
+
* the panel shows the CNY figure. A balance window has no reset and no
|
|
11
|
+
* total — the amount IS the signal.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/quota/adapters/deepseek-balance
|
|
14
|
+
*/
|
|
15
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
16
|
+
/** The DeepSeek account-balance adapter. */
|
|
17
|
+
export declare const deepseekBalanceAdapter: QuotaAdapter;
|
|
18
|
+
//# sourceMappingURL=deepseek-balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek-balance.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/deepseek-balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAA;AAmBjE,4CAA4C;AAC5C,eAAO,MAAM,sBAAsB,EAAE,YA2CpC,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek balance adapter: the pay-as-you-go account balance of the
|
|
3
|
+
* official DeepSeek platform — the dsh default provider (`deepseek-official`).
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET {root}/user/balance` with a Bearer key. The root is the
|
|
6
|
+
* profile's inference `baseURL` with a trailing OpenAI-compatible `/v1`
|
|
7
|
+
* stripped (so `https://api.deepseek.com/v1` hits the official
|
|
8
|
+
* `/user/balance`, not `/v1/user/balance`), defaulting to
|
|
9
|
+
* `https://api.deepseek.com`. The response lists one entry per currency;
|
|
10
|
+
* the panel shows the CNY figure. A balance window has no reset and no
|
|
11
|
+
* total — the amount IS the signal.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/quota/adapters/deepseek-balance
|
|
14
|
+
*/
|
|
15
|
+
import { amountOf, fetchJson, hostOf } from "../http.js";
|
|
16
|
+
import { QuotaQueryError } from "../types.js";
|
|
17
|
+
/** The direct adapter's route key (dsh-llm-deepseek). */
|
|
18
|
+
const ROUTE_OFFICIAL = 'deepseek-official';
|
|
19
|
+
/** Default inference/quota host when the profile carries no override. */
|
|
20
|
+
const DEFAULT_BASE = 'https://api.deepseek.com';
|
|
21
|
+
/**
|
|
22
|
+
* The platform root a balance query should hit: strip trailing slashes and
|
|
23
|
+
* a trailing OpenAI-compatible `/v1` so a profile of
|
|
24
|
+
* `https://api.deepseek.com/v1` lands on `/user/balance`, not
|
|
25
|
+
* `/v1/user/balance`. A proxy path in front of `/v1` is kept
|
|
26
|
+
* (`https://gw.example/deepseek/v1` → `…/deepseek/user/balance`).
|
|
27
|
+
*/
|
|
28
|
+
function balanceRootOf(baseUrl) {
|
|
29
|
+
const raw = baseUrl !== undefined && baseUrl !== '' ? baseUrl : DEFAULT_BASE;
|
|
30
|
+
return raw.replace(/\/+$/u, '').replace(/\/v1$/u, '');
|
|
31
|
+
}
|
|
32
|
+
/** The DeepSeek account-balance adapter. */
|
|
33
|
+
export const deepseekBalanceAdapter = {
|
|
34
|
+
id: 'deepseek-balance',
|
|
35
|
+
label: 'DeepSeek Balance',
|
|
36
|
+
routes: [ROUTE_OFFICIAL],
|
|
37
|
+
matches(input) {
|
|
38
|
+
if (input.provider === ROUTE_OFFICIAL)
|
|
39
|
+
return true;
|
|
40
|
+
const host = hostOf(input.baseUrl);
|
|
41
|
+
return host !== undefined && (host === 'deepseek.com' || host.endsWith('.deepseek.com'));
|
|
42
|
+
},
|
|
43
|
+
async query(ctx) {
|
|
44
|
+
const base = balanceRootOf(ctx.baseUrl);
|
|
45
|
+
const body = await fetchJson(ctx, `${base}/user/balance`, { authorization: `Bearer ${ctx.apiKey}` });
|
|
46
|
+
if (typeof body !== 'object' || body === null) {
|
|
47
|
+
throw new QuotaQueryError('parse', 'response is not an object');
|
|
48
|
+
}
|
|
49
|
+
const record = body;
|
|
50
|
+
const infos = record.balance_infos;
|
|
51
|
+
if (!Array.isArray(infos)) {
|
|
52
|
+
throw new QuotaQueryError('parse', 'missing "balance_infos" array');
|
|
53
|
+
}
|
|
54
|
+
// Prefer the CNY entry; a weird account with only USD falls back to
|
|
55
|
+
// the first entry rather than reporting nothing.
|
|
56
|
+
const pick = infos.find(entry => typeof entry === 'object' && entry !== null && entry.currency === 'CNY') ?? infos.find(entry => typeof entry === 'object' && entry !== null);
|
|
57
|
+
if (pick === undefined) {
|
|
58
|
+
throw new QuotaQueryError('parse', '"balance_infos" is empty');
|
|
59
|
+
}
|
|
60
|
+
const entry = pick;
|
|
61
|
+
// The amounts ship as STRINGS and an overdrawn account answers
|
|
62
|
+
// negative (`"-0.01"` with is_available:false) — the signed string
|
|
63
|
+
// parser keeps both.
|
|
64
|
+
const balance = amountOf(entry.total_balance);
|
|
65
|
+
if (balance === undefined) {
|
|
66
|
+
throw new QuotaQueryError('parse', 'missing numeric "total_balance"');
|
|
67
|
+
}
|
|
68
|
+
const window = {
|
|
69
|
+
tier: 'balance',
|
|
70
|
+
remainingValue: balance,
|
|
71
|
+
unit: entry.currency === 'USD' ? 'usd' : 'cny',
|
|
72
|
+
};
|
|
73
|
+
return { windows: [window] };
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=deepseek-balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek-balance.js","sourceRoot":"","sources":["../../../src/quota/adapters/deepseek-balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,yDAAyD;AACzD,MAAM,cAAc,GAAG,mBAAmB,CAAA;AAC1C,yEAAyE;AACzE,MAAM,YAAY,GAAG,0BAA0B,CAAA;AAE/C;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,OAA2B;IAChD,MAAM,GAAG,GAAG,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAA;IAC5E,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACvD,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,sBAAsB,GAAiB;IAClD,EAAE,EAAE,kBAAkB;IACtB,KAAK,EAAE,kBAAkB;IACzB,MAAM,EAAE,CAAC,cAAc,CAAC;IACxB,OAAO,CAAC,KAAK;QACX,IAAI,KAAK,CAAC,QAAQ,KAAK,cAAc;YAAE,OAAO,IAAI,CAAA;QAClD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAClC,OAAO,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAA;IAC1F,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,GAAG;QACb,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;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,GAAgB;YAC1B,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,OAAO;YACvB,IAAI,EAAE,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;SAC/C,CAAA;QACD,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAA;IAC9B,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi For Coding adapter (月之暗面编程套餐): the 5-hour rolling window(s)
|
|
3
|
+
* and the weekly window of the coding-plan subscription.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://api.kimi.com/coding/v1/usages` with a Bearer key.
|
|
6
|
+
* The response carries `limits[]` — one entry per active 5-hour bucket,
|
|
7
|
+
* and there CAN be several (the window rolls per request batch) — plus a
|
|
8
|
+
* top-level `usage` object for the weekly bucket. Each bucket reports
|
|
9
|
+
* `{ limit, remaining, resetTime }`; the used share is derived.
|
|
10
|
+
*
|
|
11
|
+
* Route matching is host-first: the pi-ai `moonshotai` routes point at the
|
|
12
|
+
* standard Moonshot API (api.moonshot.cn / api.moonshot.ai), which has no
|
|
13
|
+
* coding-plan quota endpoint, so those must never match by route key. The
|
|
14
|
+
* coding plan is identified by its api.kimi.com host — exactly the signal
|
|
15
|
+
* cc-switch's `detect_provider` uses — or by the catalog route
|
|
16
|
+
* `kimi-coding` (whose catalog endpoint is filled in when the profile
|
|
17
|
+
* omits `baseURL`).
|
|
18
|
+
*
|
|
19
|
+
* @module token-usage/quota/adapters/kimi
|
|
20
|
+
*/
|
|
21
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
22
|
+
/** Whether a host is the Kimi coding-plan endpoint (subdomains included). */
|
|
23
|
+
export declare function isKimiHost(baseUrl: string | undefined): boolean;
|
|
24
|
+
/** The Kimi For Coding adapter: 5-hour + weekly windows. */
|
|
25
|
+
export declare const kimiAdapter: QuotaAdapter;
|
|
26
|
+
//# sourceMappingURL=kimi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kimi.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/kimi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAA;AASjE,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAG/D;AAiBD,4DAA4D;AAC5D,eAAO,MAAM,WAAW,EAAE,YAuCzB,CAAA"}
|