@rayadesu/dsh-llm-billing 0.2.0 → 0.2.1
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/index.js +3165 -587
- package/lib/invariant.js +3 -3
- package/lib/typert.host.js +18 -30
- package/lib/typert.remote-client.d.ts +3 -3
- package/lib/typert.remote-client.js +18 -30
- package/lib/types/balance.d.ts +6 -14
- package/lib/types/balance.js +5 -9
- package/lib/types/billing.d.ts +7 -88
- package/lib/types/billing.js +62 -171
- package/lib/types/index.d.ts +5 -22
- package/lib/types/index.js +53 -64
- package/lib/types/invariant.d.ts +2 -2
- package/lib/types/invariant.js +3 -3
- package/lib/types/types.d.ts +3 -3
- package/lib/types/types.js +1 -1
- package/package.json +1 -1
- package/lib/types/projection.d.ts +0 -69
- package/lib/types/projection.js +0 -88
- package/lib/types/today-spend.d.ts +0 -138
- package/lib/types/today-spend.js +0 -246
package/lib/invariant.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//#region lib/types/invariant.js
|
|
2
2
|
/**
|
|
3
|
-
* Package-owned invariant companion for `@
|
|
4
|
-
* @module @
|
|
3
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-llm-billing`.
|
|
4
|
+
* @module @deepseek-ai/dsh-llm-billing/invariant
|
|
5
5
|
*/
|
|
6
|
-
const PACKAGE_NAME = "@
|
|
6
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-llm-billing";
|
|
7
7
|
/** Cordis companion plugin name. */
|
|
8
8
|
const name = "llm-billing-invariant";
|
|
9
9
|
/** Service required before the companion can reserve package ownership. */
|
package/lib/typert.host.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const _deepseek_ai_dsh_llm_billing_billing_getBalance_result$schema = z.object({
|
|
5
5
|
'isAvailable': z.boolean(),
|
|
6
6
|
'lines': z.array(z.object({
|
|
7
7
|
'currency': z.string(),
|
|
@@ -10,8 +10,8 @@ const _rayadesu_dsh_llm_billing_billing_getBalance_result$schema = z.object({
|
|
|
10
10
|
'toppedUp': z.string(),
|
|
11
11
|
})),
|
|
12
12
|
})
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_parameter_0$schema = z.intersection(z.string(), z.unknown())
|
|
14
|
+
const _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_result$schema = z.object({
|
|
15
15
|
'total': z.number(),
|
|
16
16
|
'models': z.array(z.object({
|
|
17
17
|
'model': z.string(),
|
|
@@ -27,8 +27,7 @@ const _rayadesu_dsh_llm_billing_billing_getSessionSpend_result$schema = z.object
|
|
|
27
27
|
'outputCost': z.number(),
|
|
28
28
|
})),
|
|
29
29
|
})
|
|
30
|
-
const
|
|
31
|
-
const _rayadesu_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
30
|
+
const _deepseek_ai_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
32
31
|
'total': z.number(),
|
|
33
32
|
'models': z.array(z.object({
|
|
34
33
|
'model': z.string(),
|
|
@@ -46,13 +45,13 @@ const _rayadesu_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
export const TYPERT = {
|
|
49
|
-
package: '@
|
|
48
|
+
package: '@deepseek-ai/dsh-llm-billing',
|
|
50
49
|
face: 'host',
|
|
51
50
|
schemas: [
|
|
52
51
|
],
|
|
53
52
|
invocations: [
|
|
54
53
|
{
|
|
55
|
-
id: '@
|
|
54
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getBalance',
|
|
56
55
|
service: 'billing',
|
|
57
56
|
namespace: 'billing',
|
|
58
57
|
method: 'getBalance',
|
|
@@ -61,13 +60,13 @@ export const TYPERT = {
|
|
|
61
60
|
],
|
|
62
61
|
result: {
|
|
63
62
|
mode: 'strict',
|
|
64
|
-
typeSymbol: '@
|
|
65
|
-
schema:
|
|
63
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekBalance',
|
|
64
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getBalance_result$schema,
|
|
66
65
|
},
|
|
67
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
66
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":139,"column":3},
|
|
68
67
|
},
|
|
69
68
|
{
|
|
70
|
-
id: '@
|
|
69
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getSessionSpend',
|
|
71
70
|
service: 'billing',
|
|
72
71
|
namespace: 'billing',
|
|
73
72
|
method: 'getSessionSpend',
|
|
@@ -80,42 +79,31 @@ export const TYPERT = {
|
|
|
80
79
|
codec: {
|
|
81
80
|
mode: 'strict',
|
|
82
81
|
typeSymbol: '@deepseek-ai/dsh-session/types#SessionId',
|
|
83
|
-
schema:
|
|
82
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_parameter_0$schema,
|
|
84
83
|
},
|
|
85
84
|
},
|
|
86
85
|
],
|
|
87
86
|
result: {
|
|
88
87
|
mode: 'strict',
|
|
89
|
-
typeSymbol: '@
|
|
90
|
-
schema:
|
|
88
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekSessionSpend',
|
|
89
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_result$schema,
|
|
91
90
|
},
|
|
92
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
91
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":149,"column":3},
|
|
93
92
|
},
|
|
94
93
|
{
|
|
95
|
-
id: '@
|
|
94
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getTodaySpend',
|
|
96
95
|
service: 'billing',
|
|
97
96
|
namespace: 'billing',
|
|
98
97
|
method: 'getTodaySpend',
|
|
99
98
|
invocation: { kind: 'direct' },
|
|
100
99
|
parameters: [
|
|
101
|
-
{
|
|
102
|
-
name: 'force',
|
|
103
|
-
wire: 'force',
|
|
104
|
-
source: 'json',
|
|
105
|
-
acceptsUndefined: true,
|
|
106
|
-
codec: {
|
|
107
|
-
mode: 'strict',
|
|
108
|
-
typeSymbol: '@rayadesu/dsh-llm-billing#billing/getTodaySpend:force',
|
|
109
|
-
schema: _rayadesu_dsh_llm_billing_billing_getTodaySpend_parameter_0$schema,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
100
|
],
|
|
113
101
|
result: {
|
|
114
102
|
mode: 'strict',
|
|
115
|
-
typeSymbol: '@
|
|
116
|
-
schema:
|
|
103
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekTodaySpend',
|
|
104
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getTodaySpend_result$schema,
|
|
117
105
|
},
|
|
118
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
106
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":159,"column":3},
|
|
119
107
|
},
|
|
120
108
|
],
|
|
121
109
|
model: {
|
|
@@ -3,19 +3,19 @@ import type {
|
|
|
3
3
|
RemoteResult,
|
|
4
4
|
TypertRemoteContribution,
|
|
5
5
|
} from '@deepseek-ai/dsh-typert-protocol'
|
|
6
|
+
import type { DeepSeekBalance, DeepSeekSessionSpend, DeepSeekTodaySpend } from '@deepseek-ai/dsh-llm-billing/types'
|
|
6
7
|
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
7
|
-
import type { DeepSeekBalance, DeepSeekSessionSpend, DeepSeekTodaySpend } from '@rayadesu/dsh-llm-billing/types'
|
|
8
8
|
|
|
9
9
|
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
10
10
|
interface TypertRemoteNamespace$62696c6c696e67 {
|
|
11
11
|
getBalance: () => Promise<RemoteResult<DeepSeekBalance>>
|
|
12
12
|
getSessionSpend: (sessionId: SessionId) => Promise<RemoteResult<DeepSeekSessionSpend>>
|
|
13
|
-
getTodaySpend: (
|
|
13
|
+
getTodaySpend: () => Promise<RemoteResult<DeepSeekTodaySpend>>
|
|
14
14
|
}
|
|
15
15
|
interface TypertRemoteMap {
|
|
16
16
|
'billing/getBalance': () => Promise<RemoteResult<DeepSeekBalance>>
|
|
17
17
|
'billing/getSessionSpend': (sessionId: SessionId) => Promise<RemoteResult<DeepSeekSessionSpend>>
|
|
18
|
-
'billing/getTodaySpend': (
|
|
18
|
+
'billing/getTodaySpend': () => Promise<RemoteResult<DeepSeekTodaySpend>>
|
|
19
19
|
}
|
|
20
20
|
interface TypertRemoteNamespaceMap {
|
|
21
21
|
'billing': TypertRemoteNamespace$62696c6c696e67
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Generated by @deepseek-ai/dsh-typert-generator from the Host FaceModel — do not edit. */
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const _deepseek_ai_dsh_llm_billing_billing_getBalance_result$schema = z.object({
|
|
5
5
|
'isAvailable': z.boolean(),
|
|
6
6
|
'lines': z.array(z.object({
|
|
7
7
|
'currency': z.string(),
|
|
@@ -10,8 +10,8 @@ const _rayadesu_dsh_llm_billing_billing_getBalance_result$schema = z.object({
|
|
|
10
10
|
'toppedUp': z.string(),
|
|
11
11
|
})),
|
|
12
12
|
})
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_parameter_0$schema = z.intersection(z.string(), z.unknown())
|
|
14
|
+
const _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_result$schema = z.object({
|
|
15
15
|
'total': z.number(),
|
|
16
16
|
'models': z.array(z.object({
|
|
17
17
|
'model': z.string(),
|
|
@@ -27,8 +27,7 @@ const _rayadesu_dsh_llm_billing_billing_getSessionSpend_result$schema = z.object
|
|
|
27
27
|
'outputCost': z.number(),
|
|
28
28
|
})),
|
|
29
29
|
})
|
|
30
|
-
const
|
|
31
|
-
const _rayadesu_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
30
|
+
const _deepseek_ai_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
32
31
|
'total': z.number(),
|
|
33
32
|
'models': z.array(z.object({
|
|
34
33
|
'model': z.string(),
|
|
@@ -46,10 +45,10 @@ const _rayadesu_dsh_llm_billing_billing_getTodaySpend_result$schema = z.object({
|
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
export const TYPERT_REMOTE = {
|
|
49
|
-
package: '@
|
|
48
|
+
package: '@deepseek-ai/dsh-llm-billing',
|
|
50
49
|
descriptors: [
|
|
51
50
|
{
|
|
52
|
-
id: '@
|
|
51
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getBalance',
|
|
53
52
|
service: 'billing',
|
|
54
53
|
namespace: 'billing',
|
|
55
54
|
method: 'getBalance',
|
|
@@ -58,13 +57,13 @@ export const TYPERT_REMOTE = {
|
|
|
58
57
|
],
|
|
59
58
|
result: {
|
|
60
59
|
mode: 'strict',
|
|
61
|
-
typeSymbol: '@
|
|
62
|
-
schema:
|
|
60
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekBalance',
|
|
61
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getBalance_result$schema,
|
|
63
62
|
},
|
|
64
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
63
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":139,"column":3},
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
|
-
id: '@
|
|
66
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getSessionSpend',
|
|
68
67
|
service: 'billing',
|
|
69
68
|
namespace: 'billing',
|
|
70
69
|
method: 'getSessionSpend',
|
|
@@ -77,42 +76,31 @@ export const TYPERT_REMOTE = {
|
|
|
77
76
|
codec: {
|
|
78
77
|
mode: 'strict',
|
|
79
78
|
typeSymbol: '@deepseek-ai/dsh-session/types#SessionId',
|
|
80
|
-
schema:
|
|
79
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_parameter_0$schema,
|
|
81
80
|
},
|
|
82
81
|
},
|
|
83
82
|
],
|
|
84
83
|
result: {
|
|
85
84
|
mode: 'strict',
|
|
86
|
-
typeSymbol: '@
|
|
87
|
-
schema:
|
|
85
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekSessionSpend',
|
|
86
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getSessionSpend_result$schema,
|
|
88
87
|
},
|
|
89
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
88
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":149,"column":3},
|
|
90
89
|
},
|
|
91
90
|
{
|
|
92
|
-
id: '@
|
|
91
|
+
id: '@deepseek-ai/dsh-llm-billing#billing/getTodaySpend',
|
|
93
92
|
service: 'billing',
|
|
94
93
|
namespace: 'billing',
|
|
95
94
|
method: 'getTodaySpend',
|
|
96
95
|
invocation: { kind: 'direct' },
|
|
97
96
|
parameters: [
|
|
98
|
-
{
|
|
99
|
-
name: 'force',
|
|
100
|
-
wire: 'force',
|
|
101
|
-
source: 'json',
|
|
102
|
-
acceptsUndefined: true,
|
|
103
|
-
codec: {
|
|
104
|
-
mode: 'strict',
|
|
105
|
-
typeSymbol: '@rayadesu/dsh-llm-billing#billing/getTodaySpend:force',
|
|
106
|
-
schema: _rayadesu_dsh_llm_billing_billing_getTodaySpend_parameter_0$schema,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
97
|
],
|
|
110
98
|
result: {
|
|
111
99
|
mode: 'strict',
|
|
112
|
-
typeSymbol: '@
|
|
113
|
-
schema:
|
|
100
|
+
typeSymbol: '@deepseek-ai/dsh-llm-billing/types#DeepSeekTodaySpend',
|
|
101
|
+
schema: _deepseek_ai_dsh_llm_billing_billing_getTodaySpend_result$schema,
|
|
114
102
|
},
|
|
115
|
-
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":
|
|
103
|
+
sourceLocation: {"file":"packages/llm/llm-billing/src/balance.ts","line":159,"column":3},
|
|
116
104
|
},
|
|
117
105
|
],
|
|
118
106
|
}
|
package/lib/types/balance.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* takes an already-resolved endpoint and bearer token so the registering
|
|
5
5
|
* plugin stays the one owner of credential policy; the gateway carries only a
|
|
6
6
|
* `fetchBalance` thunk for the same reason.
|
|
7
|
-
* @module @
|
|
7
|
+
* @module @deepseek-ai/dsh-llm-billing/balance
|
|
8
8
|
*/
|
|
9
9
|
import type { Context } from '@deepseek-ai/cordis';
|
|
10
10
|
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
@@ -32,12 +32,8 @@ export interface DeepSeekBalanceGatewayOptions {
|
|
|
32
32
|
fetchBalance: () => Promise<DeepSeekBalance>;
|
|
33
33
|
/** Compute one session's billed spend through the plugin's resolved facts. */
|
|
34
34
|
fetchSessionSpend: (sessionId: SessionId) => Promise<DeepSeekSessionSpend>;
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
* resolved facts. `force` bypasses the host-side time window (the manual
|
|
38
|
-
* refresh path); a `force` miss still reuses revision-gated increments.
|
|
39
|
-
*/
|
|
40
|
-
fetchTodaySpend: (force?: boolean) => Promise<DeepSeekTodaySpend>;
|
|
35
|
+
/** Compute today's billed spend across every session through the plugin's resolved facts. */
|
|
36
|
+
fetchTodaySpend: () => Promise<DeepSeekTodaySpend>;
|
|
41
37
|
}
|
|
42
38
|
/**
|
|
43
39
|
* Remote-only service exposing the DeepSeek account balance and session spend.
|
|
@@ -59,21 +55,17 @@ export declare class DeepSeekBalanceGateway extends TypertRemoteService {
|
|
|
59
55
|
*/
|
|
60
56
|
getBalance(): Promise<DeepSeekBalance>;
|
|
61
57
|
/**
|
|
62
|
-
* Read one session's billed spend, priced per event by its
|
|
63
|
-
* peak/off-peak hour and weekday (weekends are always off-peak).
|
|
58
|
+
* Read one session's billed spend, priced per event by its peak/off-peak hour.
|
|
64
59
|
* @param sessionId - the session whose spend to compute.
|
|
65
60
|
* @returns the session's total cost plus one row per priced model.
|
|
66
61
|
*/
|
|
67
62
|
getSessionSpend(sessionId: SessionId): Promise<DeepSeekSessionSpend>;
|
|
68
63
|
/**
|
|
69
64
|
* Read today's billed spend across every session, priced per event by its
|
|
70
|
-
* Beijing-time calendar day
|
|
71
|
-
* @param force - bypass the host-side 60s cache (manual refresh); omitted
|
|
72
|
-
* means a cached read. Remote parameters cannot carry default values, so
|
|
73
|
-
* the thunk receives `undefined` for an omitted argument.
|
|
65
|
+
* Beijing-time calendar day and peak/off-peak hour.
|
|
74
66
|
* @returns today's total cost plus one row per priced model.
|
|
75
67
|
*/
|
|
76
|
-
getTodaySpend(
|
|
68
|
+
getTodaySpend(): Promise<DeepSeekTodaySpend>;
|
|
77
69
|
}
|
|
78
70
|
export default DeepSeekBalanceGateway;
|
|
79
71
|
//# sourceMappingURL=balance.d.ts.map
|
package/lib/types/balance.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* takes an already-resolved endpoint and bearer token so the registering
|
|
5
5
|
* plugin stays the one owner of credential policy; the gateway carries only a
|
|
6
6
|
* `fetchBalance` thunk for the same reason.
|
|
7
|
-
* @module @
|
|
7
|
+
* @module @deepseek-ai/dsh-llm-billing/balance
|
|
8
8
|
*/
|
|
9
9
|
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
10
10
|
var useValue = arguments.length > 2;
|
|
@@ -165,8 +165,7 @@ let DeepSeekBalanceGateway = (() => {
|
|
|
165
165
|
return this.options.fetchBalance();
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
* Read one session's billed spend, priced per event by its
|
|
169
|
-
* peak/off-peak hour and weekday (weekends are always off-peak).
|
|
168
|
+
* Read one session's billed spend, priced per event by its peak/off-peak hour.
|
|
170
169
|
* @param sessionId - the session whose spend to compute.
|
|
171
170
|
* @returns the session's total cost plus one row per priced model.
|
|
172
171
|
*/
|
|
@@ -175,14 +174,11 @@ let DeepSeekBalanceGateway = (() => {
|
|
|
175
174
|
}
|
|
176
175
|
/**
|
|
177
176
|
* Read today's billed spend across every session, priced per event by its
|
|
178
|
-
* Beijing-time calendar day
|
|
179
|
-
* @param force - bypass the host-side 60s cache (manual refresh); omitted
|
|
180
|
-
* means a cached read. Remote parameters cannot carry default values, so
|
|
181
|
-
* the thunk receives `undefined` for an omitted argument.
|
|
177
|
+
* Beijing-time calendar day and peak/off-peak hour.
|
|
182
178
|
* @returns today's total cost plus one row per priced model.
|
|
183
179
|
*/
|
|
184
|
-
getTodaySpend(
|
|
185
|
-
return this.options.fetchTodaySpend(
|
|
180
|
+
getTodaySpend() {
|
|
181
|
+
return this.options.fetchTodaySpend();
|
|
186
182
|
}
|
|
187
183
|
};
|
|
188
184
|
})();
|
package/lib/types/billing.d.ts
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
* pricing. Pure functions over session events and the pricing table, so the
|
|
4
4
|
* Remote gateway stays transport-free and the whole spend is testable without
|
|
5
5
|
* a key.
|
|
6
|
-
*
|
|
7
|
-
* The per-event pricing lives in {@link priceEvent}, the one shared fold
|
|
8
|
-
* primitive: the events-scan paths ({@link computeSessionSpend},
|
|
9
|
-
* {@link computeTodaySpend}) and the session-projection unit
|
|
10
|
-
* (`billingTodaySpend` in projection.ts) all fold the same contribution, so a
|
|
11
|
-
* pricing-table change cannot drift one path from the others.
|
|
12
|
-
* @module @rayadesu/dsh-llm-billing/billing
|
|
6
|
+
* @module @deepseek-ai/dsh-llm-billing/billing
|
|
13
7
|
*/
|
|
14
8
|
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
15
9
|
import type { DeepSeekSessionSpend, DeepSeekTodaySpend } from './types.ts';
|
|
@@ -38,7 +32,7 @@ export interface BillingConfigModel {
|
|
|
38
32
|
/** Off-peak price. */
|
|
39
33
|
offPeak: DeepSeekTokenPrice;
|
|
40
34
|
}
|
|
41
|
-
/** One peak-hour window on a 24h Beijing-time clock
|
|
35
|
+
/** One peak-hour window on a 24h Beijing-time clock. */
|
|
42
36
|
export interface PeakHourWindow {
|
|
43
37
|
/** Inclusive start hour, `0`–`23`. */
|
|
44
38
|
start: number;
|
|
@@ -47,19 +41,12 @@ export interface PeakHourWindow {
|
|
|
47
41
|
}
|
|
48
42
|
/** Optional billing configuration; omission uses the published defaults. */
|
|
49
43
|
export interface BillingConfig {
|
|
50
|
-
/**
|
|
51
|
-
* Peak-hour windows in Beijing time, applied on weekdays (Monday–Friday)
|
|
52
|
-
* only; weekends (Saturday and Sunday) are always off-peak.
|
|
53
|
-
*/
|
|
44
|
+
/** Peak-hour windows in Beijing time. */
|
|
54
45
|
peakHours?: PeakHourWindow[];
|
|
55
|
-
/** Per-model pricing rows; omission uses the V4 Flash
|
|
46
|
+
/** Per-model pricing rows; omission uses the V4 Flash and V4 Pro defaults. */
|
|
56
47
|
models?: BillingConfigModel[];
|
|
57
48
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Published peak-hour windows (Beijing time): 09:00–12:00 and 14:00–18:00,
|
|
60
|
-
* applied on weekdays (Monday–Friday) only — weekends are always off-peak
|
|
61
|
-
* (effective 2026-08-23).
|
|
62
|
-
*/
|
|
49
|
+
/** Published peak-hour windows (Beijing time): 09:00–12:00 and 14:00–18:00. */
|
|
63
50
|
export declare const DEFAULT_PEAK_HOURS: {
|
|
64
51
|
start: number;
|
|
65
52
|
end: number;
|
|
@@ -84,81 +71,13 @@ export interface ResolvedBilling {
|
|
|
84
71
|
* @returns the resolved table and peak-hour windows.
|
|
85
72
|
*/
|
|
86
73
|
export declare function resolveBilling(config: BillingConfig | undefined): ResolvedBilling;
|
|
87
|
-
/** The Beijing (Asia/Shanghai, UTC+8, no DST) calendar-day key of a timestamp. */
|
|
88
|
-
export declare function beijingDayKey(now: Date): string;
|
|
89
74
|
/**
|
|
90
|
-
* Whether a timestamp falls inside any peak-hour window (Beijing time
|
|
91
|
-
* weekdays Monday–Friday only). Weekends (Saturday and Sunday) are always
|
|
92
|
-
* off-peak, matching the published peak-hours rule.
|
|
75
|
+
* Whether a timestamp falls inside any peak-hour window (Beijing time).
|
|
93
76
|
* @param billing - resolved pricing with peak-hour windows.
|
|
94
77
|
* @param now - the moment to classify.
|
|
95
|
-
* @returns true during
|
|
78
|
+
* @returns true during peak hours.
|
|
96
79
|
*/
|
|
97
80
|
export declare function isPeak(billing: ResolvedBilling, now: Date): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* One priced billed event's contribution: the model row plus the Beijing
|
|
100
|
-
* calendar day its timestamp falls on. `undefined` when the event carries no
|
|
101
|
-
* priced usage (not an `assistant/message`, no usage report, or a model
|
|
102
|
-
* without a pricing row).
|
|
103
|
-
*/
|
|
104
|
-
export interface BillingEventContribution {
|
|
105
|
-
/** Beijing-time calendar-day key of the event's timestamp. */
|
|
106
|
-
dayKey: string;
|
|
107
|
-
/** Wire model id, e.g. `deepseek-v4-flash`. */
|
|
108
|
-
model: string;
|
|
109
|
-
/** Selector label for the model. */
|
|
110
|
-
displayName: string;
|
|
111
|
-
/** Billed cost in CNY (peak plus off-peak portions). */
|
|
112
|
-
cost: number;
|
|
113
|
-
/** Cost portion billed at peak rates. */
|
|
114
|
-
peakCost: number;
|
|
115
|
-
/** Cost portion billed at off-peak rates. */
|
|
116
|
-
offPeakCost: number;
|
|
117
|
-
/** Cache-hit input tokens billed at the hit rate. */
|
|
118
|
-
cacheHitInputTokens: number;
|
|
119
|
-
/** Cache-miss input tokens (uncached input plus cache writes), billed at the miss rate. */
|
|
120
|
-
cacheMissInputTokens: number;
|
|
121
|
-
/** Output tokens (reasoning included), billed at the output rate. */
|
|
122
|
-
outputTokens: number;
|
|
123
|
-
/** Billed cost of cache-hit input tokens in CNY. */
|
|
124
|
-
cacheHitInputCost: number;
|
|
125
|
-
/** Billed cost of cache-miss input tokens (uncached input plus cache writes) in CNY. */
|
|
126
|
-
cacheMissInputCost: number;
|
|
127
|
-
/** Billed cost of output tokens (reasoning included) in CNY. */
|
|
128
|
-
outputCost: number;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Price one event at the official per-model rates, applying the peak/off-peak
|
|
132
|
-
* table by its Beijing-time hour and weekday (peak windows apply Monday–Friday
|
|
133
|
-
* only; weekends are off-peak). Each `assistant/message` event with usage
|
|
134
|
-
* contributes cache-hit input, cache-miss input (uncached input plus cache
|
|
135
|
-
* writes), and output (reasoning included) tokens at the rate of its own
|
|
136
|
-
* timestamp; a model with usage but no pricing row contributes nothing (the
|
|
137
|
-
* published table prices only the two V4 rows).
|
|
138
|
-
* @param event - the event to price.
|
|
139
|
-
* @param billing - resolved pricing with peak-hour windows.
|
|
140
|
-
* @param names - model id → display label.
|
|
141
|
-
* @returns the priced contribution, or `undefined` when the event has no priced usage.
|
|
142
|
-
*/
|
|
143
|
-
export declare function priceEvent(event: SessionEvent, billing: ResolvedBilling, names: ReadonlyMap<string, string>): BillingEventContribution | undefined;
|
|
144
|
-
/** A spend with no priced usage. */
|
|
145
|
-
export declare function emptyTodaySpend(): DeepSeekTodaySpend;
|
|
146
|
-
/**
|
|
147
|
-
* Merge one priced event's contribution into an accumulator spend (pure:
|
|
148
|
-
* returns a new spend, never mutates its input).
|
|
149
|
-
* @param spend - the accumulator (per session and day, or across sessions).
|
|
150
|
-
* @param priced - the priced contribution to add.
|
|
151
|
-
* @returns the merged spend.
|
|
152
|
-
*/
|
|
153
|
-
export declare function addEventContribution(spend: DeepSeekTodaySpend, priced: BillingEventContribution): DeepSeekTodaySpend;
|
|
154
|
-
/**
|
|
155
|
-
* Sum two spends (per session and day, or across sessions) into one (pure:
|
|
156
|
-
* returns a new spend, never mutates its inputs).
|
|
157
|
-
* @param target - the accumulator spend.
|
|
158
|
-
* @param source - the spend to add.
|
|
159
|
-
* @returns the summed spend.
|
|
160
|
-
*/
|
|
161
|
-
export declare function mergeTodaySpend(target: DeepSeekTodaySpend, source: DeepSeekTodaySpend): DeepSeekTodaySpend;
|
|
162
81
|
/**
|
|
163
82
|
* Price one session's complete event log at the official per-model rates.
|
|
164
83
|
* @param events - one session's complete event log.
|