@rayadesu/dsh-billing 0.1.0-rc.8
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/AGENTS.md +54 -0
- package/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +118 -0
- package/README.zh.md +114 -0
- package/cordis.patch.yml +20 -0
- package/package.json +33 -0
- package/packages/llm-billing/README.i18n.yaml +6 -0
- package/packages/llm-billing/README.md +44 -0
- package/packages/llm-billing/README.zh.md +44 -0
- package/packages/llm-billing/lib/index.js +562 -0
- package/packages/llm-billing/lib/invariant.js +23 -0
- package/packages/llm-billing/lib/tsconfig.tsbuildinfo +1 -0
- package/packages/llm-billing/lib/typert.host.d.ts +3 -0
- package/packages/llm-billing/lib/typert.host.js +114 -0
- package/packages/llm-billing/lib/typert.remote-client.d.ts +27 -0
- package/packages/llm-billing/lib/typert.remote-client.d.ts.map +1 -0
- package/packages/llm-billing/lib/typert.remote-client.js +108 -0
- package/packages/llm-billing/lib/types/balance.d.ts +71 -0
- package/packages/llm-billing/lib/types/balance.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/balance.js +187 -0
- package/packages/llm-billing/lib/types/balance.js.map +1 -0
- package/packages/llm-billing/lib/types/billing.d.ts +106 -0
- package/packages/llm-billing/lib/types/billing.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/billing.js +163 -0
- package/packages/llm-billing/lib/types/billing.js.map +1 -0
- package/packages/llm-billing/lib/types/index.d.ts +49 -0
- package/packages/llm-billing/lib/types/index.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/index.js +155 -0
- package/packages/llm-billing/lib/types/index.js.map +1 -0
- package/packages/llm-billing/lib/types/invariant.d.ts +16 -0
- package/packages/llm-billing/lib/types/invariant.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/invariant.js +22 -0
- package/packages/llm-billing/lib/types/invariant.js.map +1 -0
- package/packages/llm-billing/lib/types/types/balance.d.ts +71 -0
- package/packages/llm-billing/lib/types/types/balance.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types/balance.js +187 -0
- package/packages/llm-billing/lib/types/types/balance.js.map +1 -0
- package/packages/llm-billing/lib/types/types/billing.d.ts +106 -0
- package/packages/llm-billing/lib/types/types/billing.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types/billing.js +170 -0
- package/packages/llm-billing/lib/types/types/billing.js.map +1 -0
- package/packages/llm-billing/lib/types/types/index.d.ts +49 -0
- package/packages/llm-billing/lib/types/types/index.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types/index.js +156 -0
- package/packages/llm-billing/lib/types/types/index.js.map +1 -0
- package/packages/llm-billing/lib/types/types/invariant.d.ts +16 -0
- package/packages/llm-billing/lib/types/types/invariant.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types/invariant.js +22 -0
- package/packages/llm-billing/lib/types/types/invariant.js.map +1 -0
- package/packages/llm-billing/lib/types/types/types.d.ts +63 -0
- package/packages/llm-billing/lib/types/types/types.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types/types.js +7 -0
- package/packages/llm-billing/lib/types/types/types.js.map +1 -0
- package/packages/llm-billing/lib/types/types.d.ts +63 -0
- package/packages/llm-billing/lib/types/types.d.ts.map +1 -0
- package/packages/llm-billing/lib/types/types.js +7 -0
- package/packages/llm-billing/lib/types/types.js.map +1 -0
- package/packages/llm-billing/node_modules/.bin/cordis +43 -0
- package/packages/llm-billing/node_modules/.bin/cordis.CMD +12 -0
- package/packages/llm-billing/node_modules/.bin/cordis.ps1 +41 -0
- package/packages/llm-billing/package.json +75 -0
- package/packages/llm-billing/src/balance.ts +164 -0
- package/packages/llm-billing/src/billing.ts +251 -0
- package/packages/llm-billing/src/index.ts +219 -0
- package/packages/llm-billing/src/invariant.ts +30 -0
- package/packages/llm-billing/src/types.ts +67 -0
- package/packages/llm-billing/tests/balance.spec.ts +254 -0
- package/packages/llm-billing/tests/billing.spec.ts +216 -0
- package/packages/llm-billing/tsconfig.json +42 -0
- package/packages/ui-billing/README.i18n.yaml +6 -0
- package/packages/ui-billing/README.md +30 -0
- package/packages/ui-billing/README.zh.md +30 -0
- package/packages/ui-billing/lib/client.js +4466 -0
- package/packages/ui-billing/lib/client.js.map +1 -0
- package/packages/ui-billing/lib/index.js +11 -0
- package/packages/ui-billing/lib/invariant.js +25 -0
- package/packages/ui-billing/lib/tsconfig.tsbuildinfo +1 -0
- package/packages/ui-billing/lib/types/client/BalanceBadge.d.ts +33 -0
- package/packages/ui-billing/lib/types/client/BalanceBadge.d.ts.map +1 -0
- package/packages/ui-billing/lib/types/client/BalanceBadge.js +166 -0
- package/packages/ui-billing/lib/types/client/BalanceBadge.js.map +1 -0
- package/packages/ui-billing/lib/types/client/index.d.ts +20 -0
- package/packages/ui-billing/lib/types/client/index.d.ts.map +1 -0
- package/packages/ui-billing/lib/types/client/index.js +55 -0
- package/packages/ui-billing/lib/types/client/index.js.map +1 -0
- package/packages/ui-billing/lib/types/client/locales.d.ts +26 -0
- package/packages/ui-billing/lib/types/client/locales.d.ts.map +1 -0
- package/packages/ui-billing/lib/types/client/locales.js +40 -0
- package/packages/ui-billing/lib/types/client/locales.js.map +1 -0
- package/packages/ui-billing/lib/types/index.d.ts +9 -0
- package/packages/ui-billing/lib/types/index.d.ts.map +1 -0
- package/packages/ui-billing/lib/types/index.js +9 -0
- package/packages/ui-billing/lib/types/index.js.map +1 -0
- package/packages/ui-billing/lib/types/invariant.d.ts +16 -0
- package/packages/ui-billing/lib/types/invariant.d.ts.map +1 -0
- package/packages/ui-billing/lib/types/invariant.js +24 -0
- package/packages/ui-billing/lib/types/invariant.js.map +1 -0
- package/packages/ui-billing/node_modules/.bin/cordis +43 -0
- package/packages/ui-billing/node_modules/.bin/cordis.CMD +12 -0
- package/packages/ui-billing/node_modules/.bin/cordis.ps1 +41 -0
- package/packages/ui-billing/node_modules/.bin/vite +43 -0
- package/packages/ui-billing/node_modules/.bin/vite.CMD +12 -0
- package/packages/ui-billing/node_modules/.bin/vite.ps1 +41 -0
- package/packages/ui-billing/package.json +76 -0
- package/packages/ui-billing/src/client/BalanceBadge.module.css +184 -0
- package/packages/ui-billing/src/client/BalanceBadge.tsx +266 -0
- package/packages/ui-billing/src/client/index.ts +80 -0
- package/packages/ui-billing/src/client/locales.ts +45 -0
- package/packages/ui-billing/src/css-modules.d.ts +6 -0
- package/packages/ui-billing/src/index.ts +9 -0
- package/packages/ui-billing/src/invariant.ts +32 -0
- package/packages/ui-billing/tests/balance-badge.client.spec.tsx +267 -0
- package/packages/ui-billing/tests/browser-plugin.client.spec.ts +205 -0
- package/packages/ui-billing/tsconfig.json +36 -0
- package/packages/ui-billing/tsdown.config.ts +3 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek billing: the peak/off-peak pricing table and the per-session spend
|
|
3
|
+
* pricing. Pure functions over session events and the pricing table, so the
|
|
4
|
+
* Remote gateway stays transport-free and the whole spend is testable without
|
|
5
|
+
* a key.
|
|
6
|
+
* @module @rayadesu/dsh-llm-billing/billing
|
|
7
|
+
*/
|
|
8
|
+
/** Published peak-hour windows (Beijing time): 09:00–12:00 and 14:00–18:00. */
|
|
9
|
+
export const DEFAULT_PEAK_HOURS = [
|
|
10
|
+
{ start: 9, end: 12 },
|
|
11
|
+
{ start: 14, end: 18 },
|
|
12
|
+
];
|
|
13
|
+
/** Official peak/off-peak rates (CNY per 1M tokens), effective 2026-08-17. */
|
|
14
|
+
export const DEFAULT_MODEL_PRICING = [
|
|
15
|
+
{
|
|
16
|
+
model: 'deepseek-v4-flash',
|
|
17
|
+
peak: { cacheHitInput: 0.10, cacheMissInput: 3.0, output: 9.0 },
|
|
18
|
+
offPeak: { cacheHitInput: 0.05, cacheMissInput: 1.5, output: 4.5 },
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
model: 'deepseek-v4-pro',
|
|
22
|
+
peak: { cacheHitInput: 0.30, cacheMissInput: 9.0, output: 27.0 },
|
|
23
|
+
offPeak: { cacheHitInput: 0.15, cacheMissInput: 4.5, output: 13.5 },
|
|
24
|
+
},
|
|
25
|
+
// deepseek-v4-flash-vision-exp bills at the same rates as deepseek-v4-flash;
|
|
26
|
+
// images are converted to tokens at the same per-token price.
|
|
27
|
+
{
|
|
28
|
+
model: 'deepseek-v4-flash-vision-exp',
|
|
29
|
+
peak: { cacheHitInput: 0.10, cacheMissInput: 3.0, output: 9.0 },
|
|
30
|
+
offPeak: { cacheHitInput: 0.05, cacheMissInput: 1.5, output: 4.5 },
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Resolve optional configuration to a pricing table, defaulting omitted or
|
|
35
|
+
* empty rows to the published rates. Schemastery materializes an absent
|
|
36
|
+
* `z.array` as `[]` rather than `undefined`, so emptiness — not just absence —
|
|
37
|
+
* selects the defaults. Explicit non-empty rows override the same model; a
|
|
38
|
+
* supplied non-empty `models` list is authoritative.
|
|
39
|
+
* @param config - optional raw billing configuration.
|
|
40
|
+
* @returns the resolved table and peak-hour windows.
|
|
41
|
+
*/
|
|
42
|
+
export function resolveBilling(config) {
|
|
43
|
+
const peakHours = config?.peakHours !== undefined && config.peakHours.length > 0
|
|
44
|
+
? config.peakHours
|
|
45
|
+
: DEFAULT_PEAK_HOURS;
|
|
46
|
+
const rows = config?.models !== undefined && config.models.length > 0
|
|
47
|
+
? config.models
|
|
48
|
+
: DEFAULT_MODEL_PRICING;
|
|
49
|
+
const models = new Map();
|
|
50
|
+
for (const row of rows)
|
|
51
|
+
models.set(row.model, { peak: row.peak, offPeak: row.offPeak });
|
|
52
|
+
return { peakHours, models };
|
|
53
|
+
}
|
|
54
|
+
/** The Beijing (Asia/Shanghai, UTC+8, no DST) hour of a timestamp. */
|
|
55
|
+
function beijingHour(now) {
|
|
56
|
+
return new Date(now.getTime() + 8 * 3_600_000).getUTCHours();
|
|
57
|
+
}
|
|
58
|
+
/** The Beijing (Asia/Shanghai, UTC+8, no DST) calendar-day key of a timestamp. */
|
|
59
|
+
function beijingDayKey(now) {
|
|
60
|
+
return new Date(now.getTime() + 8 * 3_600_000).toISOString().slice(0, 10);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Whether a timestamp falls inside any peak-hour window (Beijing time).
|
|
64
|
+
* @param billing - resolved pricing with peak-hour windows.
|
|
65
|
+
* @param now - the moment to classify.
|
|
66
|
+
* @returns true during peak hours.
|
|
67
|
+
*/
|
|
68
|
+
export function isPeak(billing, now) {
|
|
69
|
+
const hour = beijingHour(now);
|
|
70
|
+
return billing.peakHours.some(({ start, end }) => hour >= start && hour < end);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Price a set of billed events at the official per-model rates, applying the
|
|
74
|
+
* peak/off-peak table per event by its Beijing-time hour. Each
|
|
75
|
+
* `assistant/message` event with usage contributes cache-hit input, cache-miss
|
|
76
|
+
* input (uncached input plus cache writes), and output (reasoning included)
|
|
77
|
+
* tokens at the rate of its own timestamp, with the three component costs
|
|
78
|
+
* carried separately; a model with usage but no pricing row is omitted (the
|
|
79
|
+
* published table prices only the two V4 rows).
|
|
80
|
+
* @param events - the events to price.
|
|
81
|
+
* @param billing - resolved pricing with peak-hour windows.
|
|
82
|
+
* @param catalog - model display rows, in presentation order.
|
|
83
|
+
* @returns the total cost plus one row per priced model.
|
|
84
|
+
*/
|
|
85
|
+
function priceEvents(events, billing, catalog) {
|
|
86
|
+
const names = new Map(catalog.map(model => [model.id, model.name]));
|
|
87
|
+
const rows = new Map();
|
|
88
|
+
for (const event of events) {
|
|
89
|
+
if (event.type !== 'assistant/message')
|
|
90
|
+
continue;
|
|
91
|
+
const reported = event.data.usage;
|
|
92
|
+
if (reported === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
const model = event.data.message.source.model;
|
|
95
|
+
const pricing = billing.models.get(model);
|
|
96
|
+
if (pricing === undefined)
|
|
97
|
+
continue;
|
|
98
|
+
const peak = isPeak(billing, new Date(event.time));
|
|
99
|
+
const price = peak ? pricing.peak : pricing.offPeak;
|
|
100
|
+
const hit = reported.cacheReadTokens ?? 0;
|
|
101
|
+
const miss = reported.inputTokens + (reported.cacheWriteTokens ?? 0);
|
|
102
|
+
const output = reported.outputTokens;
|
|
103
|
+
const hitCost = (hit * price.cacheHitInput) / 1_000_000;
|
|
104
|
+
const missCost = (miss * price.cacheMissInput) / 1_000_000;
|
|
105
|
+
const outputCost = (output * price.output) / 1_000_000;
|
|
106
|
+
const cost = hitCost + missCost + outputCost;
|
|
107
|
+
let row = rows.get(model);
|
|
108
|
+
if (row === undefined) {
|
|
109
|
+
row = {
|
|
110
|
+
cacheHitInputTokens: 0, cacheMissInputTokens: 0, outputTokens: 0,
|
|
111
|
+
cost: 0, peakCost: 0, offPeakCost: 0,
|
|
112
|
+
cacheHitInputCost: 0, cacheMissInputCost: 0, outputCost: 0,
|
|
113
|
+
};
|
|
114
|
+
rows.set(model, row);
|
|
115
|
+
}
|
|
116
|
+
row.cacheHitInputTokens += hit;
|
|
117
|
+
row.cacheMissInputTokens += miss;
|
|
118
|
+
row.outputTokens += output;
|
|
119
|
+
row.cost += cost;
|
|
120
|
+
row.cacheHitInputCost += hitCost;
|
|
121
|
+
row.cacheMissInputCost += missCost;
|
|
122
|
+
row.outputCost += outputCost;
|
|
123
|
+
if (peak)
|
|
124
|
+
row.peakCost += cost;
|
|
125
|
+
else
|
|
126
|
+
row.offPeakCost += cost;
|
|
127
|
+
}
|
|
128
|
+
const models = [...rows.entries()].map(([model, row]) => ({
|
|
129
|
+
model,
|
|
130
|
+
displayName: names.get(model) ?? model,
|
|
131
|
+
cost: row.cost,
|
|
132
|
+
peakCost: row.peakCost,
|
|
133
|
+
offPeakCost: row.offPeakCost,
|
|
134
|
+
cacheHitInputTokens: row.cacheHitInputTokens,
|
|
135
|
+
cacheMissInputTokens: row.cacheMissInputTokens,
|
|
136
|
+
outputTokens: row.outputTokens,
|
|
137
|
+
cacheHitInputCost: row.cacheHitInputCost,
|
|
138
|
+
cacheMissInputCost: row.cacheMissInputCost,
|
|
139
|
+
outputCost: row.outputCost,
|
|
140
|
+
}));
|
|
141
|
+
return {
|
|
142
|
+
total: models.reduce((sum, model) => sum + model.cost, 0),
|
|
143
|
+
models,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Price one session's complete event log at the official per-model rates.
|
|
148
|
+
* @param events - one session's complete event log.
|
|
149
|
+
* @param billing - resolved pricing with peak-hour windows.
|
|
150
|
+
* @param catalog - model display rows, in presentation order.
|
|
151
|
+
* @returns the session's total cost plus one row per priced model.
|
|
152
|
+
*/
|
|
153
|
+
export function computeSessionSpend(events, billing, catalog) {
|
|
154
|
+
return priceEvents(events, billing, catalog);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Price every event whose Beijing-time calendar day is the day of `now`,
|
|
158
|
+
* aggregating across every session's event log. Events from other Beijing
|
|
159
|
+
* days are ignored, so a caller passes the concatenated logs of all sessions.
|
|
160
|
+
* @param events - every session's complete event log, concatenated.
|
|
161
|
+
* @param billing - resolved pricing with peak-hour windows.
|
|
162
|
+
* @param catalog - model display rows, in presentation order.
|
|
163
|
+
* @param now - the reference moment whose Beijing-time calendar day is "today".
|
|
164
|
+
* @returns today's total cost plus one row per priced model.
|
|
165
|
+
*/
|
|
166
|
+
export function computeTodaySpend(events, billing, catalog, now = new Date()) {
|
|
167
|
+
const day = beijingDayKey(now);
|
|
168
|
+
return priceEvents(events.filter(event => beijingDayKey(new Date(event.time)) === day), billing, catalog);
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/billing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiDH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAqC;IAClE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACrB,EAAE,KAAK,EAAE,E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9C,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC,CAAC,CAAA;IACH,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,MAAM;KACP,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA+B,EAC/B,OAAwB,EACxB,OAAgD;IAEhD,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AAC9C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA+B,EAC/B,OAAwB,EACxB,OAAgD,EAChD,MAAY,IAAI,IAAI,EAAE;IAEtB,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;IAC9B,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AAC3G,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek account balance and session-spend provider, as a standalone host
|
|
3
|
+
* plugin. It resolves the DeepSeek endpoint and API key from its own config and
|
|
4
|
+
* the credential/environment seams, prices each session's billed usage with the
|
|
5
|
+
* peak/off-peak table, and exposes the `billing` Remote (`getBalance`, the
|
|
6
|
+
* per-session `getSessionSpend`, and the all-sessions `getTodaySpend`).
|
|
7
|
+
* @module @rayadesu/dsh-llm-billing
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
import z from '@deepseek-ai/schemastery';
|
|
11
|
+
import type { BillingConfig } from './billing.ts';
|
|
12
|
+
export { DeepSeekBalanceGateway, fetchDeepSeekBalance, parseDeepSeekBalance } from './balance.ts';
|
|
13
|
+
export { computeSessionSpend, computeTodaySpend, DEFAULT_MODEL_PRICING, DEFAULT_PEAK_HOURS, isPeak, resolveBilling, } from './billing.ts';
|
|
14
|
+
export type { BillingConfig, BillingConfigModel, DeepSeekModelPricing, DeepSeekTokenPrice, PeakHourWindow, ResolvedBilling, } from './billing.ts';
|
|
15
|
+
export type * from './types.ts';
|
|
16
|
+
export declare const name = "llm-billing";
|
|
17
|
+
/** Public API default; deployments may point elsewhere via $DEEPSEEK_BASE_URL. */
|
|
18
|
+
export declare const PUBLIC_BASE_URL = "https://api.deepseek.com";
|
|
19
|
+
/** One advisory display row; requests are never restricted to this list. */
|
|
20
|
+
export interface BillingModel {
|
|
21
|
+
/** Wire model id, e.g. `deepseek-v4-flash`. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Selector label; defaults to {@link id}. */
|
|
24
|
+
name?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Plugin config. Every field is optional: the API key resolves per call from
|
|
28
|
+
* {@link Config.apiKeyEnv} (credentials seam, then environment), the endpoint
|
|
29
|
+
* falls back to `$DEEPSEEK_BASE_URL` then the public API, and the pricing
|
|
30
|
+
* table and peak-hour windows fall back to the published DeepSeek rates.
|
|
31
|
+
*/
|
|
32
|
+
export interface Config {
|
|
33
|
+
/** Credential reference (environment-variable name); defaults to `DEEPSEEK_API_KEY`. */
|
|
34
|
+
apiKeyEnv?: string;
|
|
35
|
+
/** Endpoint base; defaults to `$DEEPSEEK_BASE_URL`, then `https://api.deepseek.com`. */
|
|
36
|
+
baseURL?: string;
|
|
37
|
+
/** Advisory display rows, in presentation order; defaults to V4 Flash, V4 Pro, and V4 Flash Vision Exp. */
|
|
38
|
+
models?: BillingModel[];
|
|
39
|
+
/** Pricing table and peak-hour windows; omission uses the published defaults. */
|
|
40
|
+
billing?: BillingConfig;
|
|
41
|
+
}
|
|
42
|
+
export declare const Config: z<Config>;
|
|
43
|
+
/**
|
|
44
|
+
* Register the `billing` Remote under the `billing` namespace.
|
|
45
|
+
* @param ctx - owning plugin context.
|
|
46
|
+
* @param config - validated plugin config.
|
|
47
|
+
*/
|
|
48
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAcxC,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAA;AAGrE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACjG,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,EACN,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAA;AACrB,mBAAmB,YAAY,CAAA;AAE/B,eAAO,MAAM,IAAI,gBAAgB,CAAA;AAIjC,kFAAkF;AAClF,eAAO,MAAM,eAAe,6BAA6B,CAAA;AAEzD,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,EAAE,EAAE,MAAM,CAAA;IACV,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAQD;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2GAA2G;IAC3G,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,iFAAiF;IACjF,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB;AAyBD,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAK3B,CAAA;AA4DF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAyCxD"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek account balance and session-spend provider, as a standalone host
|
|
3
|
+
* plugin. It resolves the DeepSeek endpoint and API key from its own config and
|
|
4
|
+
* the credential/environment seams, prices each session's billed usage with the
|
|
5
|
+
* peak/off-peak table, and exposes the `billing` Remote (`getBalance`, the
|
|
6
|
+
* per-session `getSessionSpend`, and the all-sessions `getTodaySpend`).
|
|
7
|
+
* @module @rayadesu/dsh-llm-billing
|
|
8
|
+
*/
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
import { assertUsableApiKey, LlmError } from '@deepseek-ai/dsh-llm';
|
|
11
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials';
|
|
12
|
+
import { launchEnvironmentOf } from '@deepseek-ai/dsh-launch-environment';
|
|
13
|
+
import { DeepSeekBalanceGateway, fetchDeepSeekBalance } from "./balance.js";
|
|
14
|
+
import { computeSessionSpend, computeTodaySpend, DEFAULT_MODEL_PRICING, DEFAULT_PEAK_HOURS, resolveBilling, } from "./billing.js";
|
|
15
|
+
export { DeepSeekBalanceGateway, fetchDeepSeekBalance, parseDeepSeekBalance } from "./balance.js";
|
|
16
|
+
export { computeSessionSpend, computeTodaySpend, DEFAULT_MODEL_PRICING, DEFAULT_PEAK_HOURS, isPeak, resolveBilling, } from "./billing.js";
|
|
17
|
+
export const name = 'llm-billing';
|
|
18
|
+
const DEFAULT_API_KEY_ENV = 'DEEPSEEK_API_KEY';
|
|
19
|
+
const BASE_URL_ENV = 'DEEPSEEK_BASE_URL';
|
|
20
|
+
/** Public API default; deployments may point elsewhere via $DEEPSEEK_BASE_URL. */
|
|
21
|
+
export const PUBLIC_BASE_URL = 'https://api.deepseek.com';
|
|
22
|
+
const DEFAULT_MODELS = [
|
|
23
|
+
{ id: 'deepseek-v4-flash', name: 'DeepSeek-V4-Flash' },
|
|
24
|
+
{ id: 'deepseek-v4-pro', name: 'DeepSeek-V4-Pro' },
|
|
25
|
+
{ id: 'deepseek-v4-flash-vision-exp', name: 'DeepSeek-V4-Flash-Vision-Exp' },
|
|
26
|
+
];
|
|
27
|
+
const billingModel = z.object({
|
|
28
|
+
id: z.string().required(),
|
|
29
|
+
name: z.string(),
|
|
30
|
+
});
|
|
31
|
+
const tokenPrice = z.object({
|
|
32
|
+
cacheHitInput: z.number().min(0),
|
|
33
|
+
cacheMissInput: z.number().min(0),
|
|
34
|
+
output: z.number().min(0),
|
|
35
|
+
});
|
|
36
|
+
const billingConfig = z.object({
|
|
37
|
+
peakHours: z.array(z.object({
|
|
38
|
+
start: z.number().step(1).min(0).max(23),
|
|
39
|
+
end: z.number().step(1).min(0).max(24),
|
|
40
|
+
})).default(DEFAULT_PEAK_HOURS),
|
|
41
|
+
models: z.array(z.object({
|
|
42
|
+
model: z.string().required(),
|
|
43
|
+
peak: tokenPrice,
|
|
44
|
+
offPeak: tokenPrice,
|
|
45
|
+
})).default(DEFAULT_MODEL_PRICING),
|
|
46
|
+
});
|
|
47
|
+
export const Config = z.object({
|
|
48
|
+
apiKeyEnv: z.string().role('credential-ref').default(DEFAULT_API_KEY_ENV),
|
|
49
|
+
baseURL: z.string(),
|
|
50
|
+
models: z.array(billingModel).default(DEFAULT_MODELS),
|
|
51
|
+
billing: billingConfig,
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Read one session's event log: the live SessionStore first, then the
|
|
55
|
+
* persistence backend for a flushed session.
|
|
56
|
+
* @param ctx - plugin context carrying the SessionStore and optional persistence.
|
|
57
|
+
* @param sessionId - the session to read.
|
|
58
|
+
* @returns the session's complete event log.
|
|
59
|
+
* @throws {@link LlmError} with code `NOT_FOUND` when the session is unknown.
|
|
60
|
+
*/
|
|
61
|
+
async function sessionEvents(ctx, sessionId) {
|
|
62
|
+
const sessions = ctx.get('sessions');
|
|
63
|
+
const live = sessions?.get(sessionId);
|
|
64
|
+
if (live !== undefined)
|
|
65
|
+
return live.events;
|
|
66
|
+
const persistence = ctx.get('sessionPersistence');
|
|
67
|
+
if (persistence !== undefined) {
|
|
68
|
+
for (const header of await persistence.list()) {
|
|
69
|
+
if (header.id !== sessionId)
|
|
70
|
+
continue;
|
|
71
|
+
const inspection = await persistence.inspect(sessionId);
|
|
72
|
+
return inspection.events;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw new LlmError(`llm-billing: session ${sessionId} not found`, 'NOT_FOUND');
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Read every session's event log, concatenated: each live SessionStore
|
|
79
|
+
* session first (its log may hold events not yet flushed), then each persisted
|
|
80
|
+
* session that is not live, so no event is counted twice. Events are appended
|
|
81
|
+
* one at a time: spreading a very large log into `push(...)` exceeds the
|
|
82
|
+
* engine's argument limit and throws a stack RangeError.
|
|
83
|
+
* @param ctx - plugin context carrying the SessionStore and optional persistence.
|
|
84
|
+
* @returns every session's complete event log, concatenated.
|
|
85
|
+
*/
|
|
86
|
+
async function allSessionEvents(ctx) {
|
|
87
|
+
const events = [];
|
|
88
|
+
const sessions = ctx.get('sessions');
|
|
89
|
+
const liveIds = new Set();
|
|
90
|
+
if (sessions !== undefined) {
|
|
91
|
+
for (const session of sessions.list()) {
|
|
92
|
+
liveIds.add(session.id);
|
|
93
|
+
for (const event of session.events)
|
|
94
|
+
events.push(event);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const persistence = ctx.get('sessionPersistence');
|
|
98
|
+
if (persistence !== undefined) {
|
|
99
|
+
for (const header of await persistence.list()) {
|
|
100
|
+
if (liveIds.has(header.id))
|
|
101
|
+
continue;
|
|
102
|
+
try {
|
|
103
|
+
const inspection = await persistence.inspect(header.id);
|
|
104
|
+
for (const event of inspection.events)
|
|
105
|
+
events.push(event);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
// One unreadable session must not blank the whole-day aggregate.
|
|
109
|
+
ctx.logger.warn(`llm-billing: skipping unreadable session ${header.id}: ${String(error)}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return events;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Register the `billing` Remote under the `billing` namespace.
|
|
117
|
+
* @param ctx - owning plugin context.
|
|
118
|
+
* @param config - validated plugin config.
|
|
119
|
+
*/
|
|
120
|
+
export function apply(ctx, config) {
|
|
121
|
+
const baseURL = () => config.baseURL
|
|
122
|
+
?? launchEnvironmentOf(ctx).get(BASE_URL_ENV)?.value
|
|
123
|
+
?? PUBLIC_BASE_URL;
|
|
124
|
+
const apiKeyRef = credentialRef(config.apiKeyEnv ?? DEFAULT_API_KEY_ENV);
|
|
125
|
+
const resolveApiKey = async () => {
|
|
126
|
+
const credentials = ctx.get('credentials');
|
|
127
|
+
if (credentials !== undefined) {
|
|
128
|
+
const hit = await credentials.resolve(apiKeyRef);
|
|
129
|
+
if (hit !== undefined)
|
|
130
|
+
return assertUsableApiKey(hit.value, 'llm-billing', apiKeyRef);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const ambient = launchEnvironmentOf(ctx).get(apiKeyRef);
|
|
134
|
+
if (ambient !== undefined && ambient.value.length > 0) {
|
|
135
|
+
return assertUsableApiKey(ambient.value, 'llm-billing', apiKeyRef);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
throw new LlmError(`llm-billing: no API key; store ${apiKeyRef} through the credentials service or export it`, 'MISSING_CREDENTIAL');
|
|
139
|
+
};
|
|
140
|
+
const fetchBalance = async () => {
|
|
141
|
+
const apiKey = await resolveApiKey();
|
|
142
|
+
return fetchDeepSeekBalance(baseURL(), apiKey);
|
|
143
|
+
};
|
|
144
|
+
const fetchSessionSpend = async (sessionId) => {
|
|
145
|
+
const billing = resolveBilling(config.billing);
|
|
146
|
+
const catalog = (config.models ?? DEFAULT_MODELS).map(model => ({ id: model.id, name: model.name ?? model.id }));
|
|
147
|
+
return computeSessionSpend(await sessionEvents(ctx, sessionId), billing, catalog);
|
|
148
|
+
};
|
|
149
|
+
const fetchTodaySpend = async () => {
|
|
150
|
+
const billing = resolveBilling(config.billing);
|
|
151
|
+
const catalog = (config.models ?? DEFAULT_MODELS).map(model => ({ id: model.id, name: model.name ?? model.id }));
|
|
152
|
+
return computeTodaySpend(await allSessionEvents(ctx), billing, catalog);
|
|
153
|
+
};
|
|
154
|
+
new DeepSeekBalanceGateway(ctx, { fetchBalance, fetchSessionSpend, fetchTodaySpend });
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAGzE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,GACf,MAAM,cAAc,CAAA;AAIrB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CA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AE,iBAAiB,EAAE,eAAe,EAAE,CAAC,CAAA;AACvF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@rayadesu/dsh-llm-billing`.
|
|
3
|
+
* @module @rayadesu/dsh-llm-billing/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "llm-billing-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,0BAA0B,CAAA;AAC3C,2EAA2E;AAC3E,eAAO,MAAM,MAAM,UAAiB,CAAA;AAQpC;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACU,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@rayadesu/dsh-llm-billing`.
|
|
3
|
+
* @module @rayadesu/dsh-llm-billing/invariant
|
|
4
|
+
*/
|
|
5
|
+
const PACKAGE_NAME = '@rayadesu/dsh-llm-billing';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export const name = 'llm-billing-invariant';
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export const inject = ['invariants'];
|
|
10
|
+
/**
|
|
11
|
+
* No runtime invariant: this package is a read-only Remote projection over the
|
|
12
|
+
* provider balance and session logs, and owns no cross-plugin mutable state.
|
|
13
|
+
*/
|
|
14
|
+
const install = () => { };
|
|
15
|
+
/**
|
|
16
|
+
* Register this package's invariant companion.
|
|
17
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
18
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
19
|
+
*/
|
|
20
|
+
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
21
|
+
/* jscpd:ignore-end */
|
|
22
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,YAAY,GAAG,6BAA6B,CAAA;AAElD,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,uBAAuB,CAAA;AAC3C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,OAAO,GAAuB,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAuB,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;AACjE,sBAAsB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-safe balance and spend vocabulary shared by the `billing` Remote,
|
|
3
|
+
* its generated artifacts, and the web UI.
|
|
4
|
+
* @module @rayadesu/dsh-llm-billing/types
|
|
5
|
+
*/
|
|
6
|
+
/** One currency line of the account balance returned by `GET /user/balance`. */
|
|
7
|
+
export interface DeepSeekBalanceLine {
|
|
8
|
+
/** Currency code, e.g. `CNY` or `USD`. */
|
|
9
|
+
currency: string;
|
|
10
|
+
/** Total available balance (granted plus topped up). */
|
|
11
|
+
total: string;
|
|
12
|
+
/** Non-expired granted (free) balance. */
|
|
13
|
+
granted: string;
|
|
14
|
+
/** Topped-up (paid) balance. */
|
|
15
|
+
toppedUp: string;
|
|
16
|
+
}
|
|
17
|
+
/** DeepSeek account balance returned by `GET /user/balance`. */
|
|
18
|
+
export interface DeepSeekBalance {
|
|
19
|
+
/** Whether the account has any balance available for API calls. */
|
|
20
|
+
isAvailable: boolean;
|
|
21
|
+
/** Balance lines, one per currency; empty when the provider reports none. */
|
|
22
|
+
lines: readonly DeepSeekBalanceLine[];
|
|
23
|
+
}
|
|
24
|
+
/** One model's billed spend within one session, priced by the peak/off-peak table. */
|
|
25
|
+
export interface DeepSeekSessionSpendModel {
|
|
26
|
+
/** Wire model id, e.g. `deepseek-v4-flash`. */
|
|
27
|
+
model: string;
|
|
28
|
+
/** Selector label, e.g. `DeepSeek-V4-Flash`. */
|
|
29
|
+
displayName: string;
|
|
30
|
+
/** Billed cost in CNY (peak plus off-peak portions). */
|
|
31
|
+
cost: number;
|
|
32
|
+
/** Cost portion billed at peak rates. */
|
|
33
|
+
peakCost: number;
|
|
34
|
+
/** Cost portion billed at off-peak rates. */
|
|
35
|
+
offPeakCost: number;
|
|
36
|
+
/** Cache-hit input tokens billed at the hit rate. */
|
|
37
|
+
cacheHitInputTokens: number;
|
|
38
|
+
/** Cache-miss input tokens (uncached input plus cache writes), billed at the miss rate. */
|
|
39
|
+
cacheMissInputTokens: number;
|
|
40
|
+
/** Output tokens (reasoning included), billed at the output rate. */
|
|
41
|
+
outputTokens: number;
|
|
42
|
+
/** Billed cost of cache-hit input tokens in CNY. */
|
|
43
|
+
cacheHitInputCost: number;
|
|
44
|
+
/** Billed cost of cache-miss input tokens (uncached input plus cache writes) in CNY. */
|
|
45
|
+
cacheMissInputCost: number;
|
|
46
|
+
/** Billed cost of output tokens (reasoning included) in CNY. */
|
|
47
|
+
outputCost: number;
|
|
48
|
+
}
|
|
49
|
+
/** The billed spend of one session, priced per event by its Beijing-time peak/off-peak hour. */
|
|
50
|
+
export interface DeepSeekSessionSpend {
|
|
51
|
+
/** Total billed cost in CNY across every priced model. */
|
|
52
|
+
total: number;
|
|
53
|
+
/** One row per model that reported usage AND has a pricing row; empty when the session has no priced usage. */
|
|
54
|
+
models: readonly DeepSeekSessionSpendModel[];
|
|
55
|
+
}
|
|
56
|
+
/** The billed spend of every session on one Beijing-time calendar day, priced per event by its peak/off-peak hour. */
|
|
57
|
+
export interface DeepSeekTodaySpend {
|
|
58
|
+
/** Total billed cost in CNY across every priced model and every session. */
|
|
59
|
+
total: number;
|
|
60
|
+
/** One row per model that reported usage AND has a pricing row; empty when today has no priced usage. */
|
|
61
|
+
models: readonly DeepSeekSessionSpendModel[];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAA;IAChB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,WAAW,EAAE,OAAO,CAAA;IACpB,6EAA6E;IAC7E,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAA;CACtC;AAED,sFAAsF;AACtF,MAAM,WAAW,yBAAyB;IACxC,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IACZ,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAA;IACnB,qDAAqD;IACrD,mBAAmB,EAAE,MAAM,CAAA;IAC3B,2FAA2F;IAC3F,oBAAoB,EAAE,MAAM,CAAA;IAC5B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAA;IACpB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAA;IACzB,wFAAwF;IACxF,kBAAkB,EAAE,MAAM,CAAA;IAC1B,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,gGAAgG;AAChG,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,+GAA+G;IAC/G,MAAM,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAC7C;AAED,sHAAsH;AACtH,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAA;IACb,yGAAyG;IACzG,MAAM,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-safe balance and spend vocabulary shared by the `billing` Remote,
|
|
3
|
+
* its generated artifacts, and the web UI.
|
|
4
|
+
* @module @rayadesu/dsh-llm-billing/types
|
|
5
|
+
*/
|
|
6
|
+
/** One currency line of the account balance returned by `GET /user/balance`. */
|
|
7
|
+
export interface DeepSeekBalanceLine {
|
|
8
|
+
/** Currency code, e.g. `CNY` or `USD`. */
|
|
9
|
+
currency: string;
|
|
10
|
+
/** Total available balance (granted plus topped up). */
|
|
11
|
+
total: string;
|
|
12
|
+
/** Non-expired granted (free) balance. */
|
|
13
|
+
granted: string;
|
|
14
|
+
/** Topped-up (paid) balance. */
|
|
15
|
+
toppedUp: string;
|
|
16
|
+
}
|
|
17
|
+
/** DeepSeek account balance returned by `GET /user/balance`. */
|
|
18
|
+
export interface DeepSeekBalance {
|
|
19
|
+
/** Whether the account has any balance available for API calls. */
|
|
20
|
+
isAvailable: boolean;
|
|
21
|
+
/** Balance lines, one per currency; empty when the provider reports none. */
|
|
22
|
+
lines: readonly DeepSeekBalanceLine[];
|
|
23
|
+
}
|
|
24
|
+
/** One model's billed spend within one session, priced by the peak/off-peak table. */
|
|
25
|
+
export interface DeepSeekSessionSpendModel {
|
|
26
|
+
/** Wire model id, e.g. `deepseek-v4-flash`. */
|
|
27
|
+
model: string;
|
|
28
|
+
/** Selector label, e.g. `DeepSeek-V4-Flash`. */
|
|
29
|
+
displayName: string;
|
|
30
|
+
/** Billed cost in CNY (peak plus off-peak portions). */
|
|
31
|
+
cost: number;
|
|
32
|
+
/** Cost portion billed at peak rates. */
|
|
33
|
+
peakCost: number;
|
|
34
|
+
/** Cost portion billed at off-peak rates. */
|
|
35
|
+
offPeakCost: number;
|
|
36
|
+
/** Cache-hit input tokens billed at the hit rate. */
|
|
37
|
+
cacheHitInputTokens: number;
|
|
38
|
+
/** Cache-miss input tokens (uncached input plus cache writes), billed at the miss rate. */
|
|
39
|
+
cacheMissInputTokens: number;
|
|
40
|
+
/** Output tokens (reasoning included), billed at the output rate. */
|
|
41
|
+
outputTokens: number;
|
|
42
|
+
/** Billed cost of cache-hit input tokens in CNY. */
|
|
43
|
+
cacheHitInputCost: number;
|
|
44
|
+
/** Billed cost of cache-miss input tokens (uncached input plus cache writes) in CNY. */
|
|
45
|
+
cacheMissInputCost: number;
|
|
46
|
+
/** Billed cost of output tokens (reasoning included) in CNY. */
|
|
47
|
+
outputCost: number;
|
|
48
|
+
}
|
|
49
|
+
/** The billed spend of one session, priced per event by its Beijing-time peak/off-peak hour. */
|
|
50
|
+
export interface DeepSeekSessionSpend {
|
|
51
|
+
/** Total billed cost in CNY across every priced model. */
|
|
52
|
+
total: number;
|
|
53
|
+
/** One row per model that reported usage AND has a pricing row; empty when the session has no priced usage. */
|
|
54
|
+
models: readonly DeepSeekSessionSpendModel[];
|
|
55
|
+
}
|
|
56
|
+
/** The billed spend of every session on one Beijing-time calendar day, priced per event by its peak/off-peak hour. */
|
|
57
|
+
export interface DeepSeekTodaySpend {
|
|
58
|
+
/** Total billed cost in CNY across every priced model and every session. */
|
|
59
|
+
total: number;
|
|
60
|
+
/** One row per model that reported usage AND has a pricing row; empty when today has no priced usage. */
|
|
61
|
+
models: readonly DeepSeekSessionSpendModel[];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAA;IAChB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,WAAW,EAAE,OAAO,CAAA;IACpB,6EAA6E;IAC7E,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAA;CACtC;AAED,sFAAsF;AACtF,MAAM,WAAW,yBAAyB;IACxC,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IACZ,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAA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