@duke-dsh-plugins/dsh-token-stats 1.3.3 → 1.4.0

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/typert.host.js CHANGED
@@ -80,6 +80,84 @@ const tokenStatsResultSchema = z.union([
80
80
  .readonly(),
81
81
  ]);
82
82
 
83
+ // ---- quota / balance (套餐余额) ---------------------------------------------
84
+
85
+ const quotaDisplaySchema = z
86
+ .object({
87
+ fiveHrPct: z.union([z.number(), z.null()]),
88
+ weeklyPct: z.union([z.number(), z.null()]),
89
+ fiveHrResetsIn: z.union([z.string(), z.null()]),
90
+ weeklyResetsIn: z.union([z.string(), z.null()]),
91
+ balanceText: z.union([z.string(), z.null()]),
92
+ balanceUsd: z.union([z.number(), z.null()]),
93
+ currency: z.union([z.string(), z.null()]),
94
+ })
95
+ .readonly();
96
+
97
+ const quotaValueSchema = z.union([
98
+ z
99
+ .object({
100
+ ok: z.literal(true).readonly(),
101
+ provider: z.string(),
102
+ display: quotaDisplaySchema,
103
+ })
104
+ .readonly(),
105
+ z
106
+ .object({
107
+ ok: z.literal(false).readonly(),
108
+ provider: z.string(),
109
+ kind: z.string(),
110
+ message: z.string(),
111
+ })
112
+ .readonly(),
113
+ ]);
114
+
115
+ const tokenStatsQuotaResultSchema = z.union([
116
+ z
117
+ .object({
118
+ ok: z.literal(true).readonly(),
119
+ value: quotaValueSchema,
120
+ })
121
+ .readonly(),
122
+ z
123
+ .object({
124
+ ok: z.literal(false).readonly(),
125
+ error: z
126
+ .object({
127
+ code: z.string().readonly(),
128
+ message: z.string().readonly().optional(),
129
+ })
130
+ .readonly(),
131
+ })
132
+ .readonly(),
133
+ ]);
134
+
135
+ const allQuotasValueSchema = z
136
+ .object({
137
+ quotas: z.record(z.string(), quotaValueSchema).readonly(),
138
+ })
139
+ .readonly();
140
+
141
+ const tokenStatsAllQuotasResultSchema = z.union([
142
+ z
143
+ .object({
144
+ ok: z.literal(true).readonly(),
145
+ value: allQuotasValueSchema,
146
+ })
147
+ .readonly(),
148
+ z
149
+ .object({
150
+ ok: z.literal(false).readonly(),
151
+ error: z
152
+ .object({
153
+ code: z.string().readonly(),
154
+ message: z.string().readonly().optional(),
155
+ })
156
+ .readonly(),
157
+ })
158
+ .readonly(),
159
+ ]);
160
+
83
161
  export const TYPERT = {
84
162
  package: "@duke-dsh-plugins/dsh-token-stats",
85
163
  face: "host",
@@ -99,6 +177,66 @@ export const TYPERT = {
99
177
  },
100
178
  sourceLocation: { file: "index.js", line: 1, column: 1 },
101
179
  },
180
+ {
181
+ id: "dsh-token-stats#tokenStats/getQuota",
182
+ service: "tokenStats",
183
+ namespace: "tokenStats",
184
+ method: "getQuota",
185
+ invocation: { kind: "direct" },
186
+ parameters: [
187
+ {
188
+ name: "provider",
189
+ wire: "provider",
190
+ source: "json",
191
+ codec: {
192
+ mode: "strict",
193
+ typeSymbol: "dsh-token-stats#tokenStats/getQuota:provider",
194
+ schema: z.string(),
195
+ },
196
+ },
197
+ {
198
+ name: "force",
199
+ wire: "force",
200
+ source: "json",
201
+ codec: {
202
+ mode: "strict",
203
+ typeSymbol: "dsh-token-stats#tokenStats/getQuota:force",
204
+ schema: z.boolean(),
205
+ },
206
+ },
207
+ ],
208
+ result: {
209
+ mode: "strict",
210
+ typeSymbol: "dsh-token-stats#TokenStatsQuotaResult",
211
+ schema: tokenStatsQuotaResultSchema,
212
+ },
213
+ sourceLocation: { file: "index.js", line: 1, column: 1 },
214
+ },
215
+ {
216
+ id: "dsh-token-stats#tokenStats/getAllQuotas",
217
+ service: "tokenStats",
218
+ namespace: "tokenStats",
219
+ method: "getAllQuotas",
220
+ invocation: { kind: "direct" },
221
+ parameters: [
222
+ {
223
+ name: "force",
224
+ wire: "force",
225
+ source: "json",
226
+ codec: {
227
+ mode: "strict",
228
+ typeSymbol: "dsh-token-stats#tokenStats/getAllQuotas:force",
229
+ schema: z.boolean(),
230
+ },
231
+ },
232
+ ],
233
+ result: {
234
+ mode: "strict",
235
+ typeSymbol: "dsh-token-stats#TokenStatsAllQuotasResult",
236
+ schema: tokenStatsAllQuotasResultSchema,
237
+ },
238
+ sourceLocation: { file: "index.js", line: 1, column: 1 },
239
+ },
102
240
  ],
103
241
  model: {
104
242
  services: [
@@ -120,6 +258,26 @@ export const TYPERT = {
120
258
  jsDoc:
121
259
  "/**\n * Return the whole-dataset snapshot: ready/collecting state, backfill progress,\n * per-day per-model aggregates and the ordered model list.\n * @returns success or a business failure.\n */",
122
260
  },
261
+ {
262
+ kind: "method",
263
+ name: "getQuota",
264
+ signature:
265
+ "@Remote('getQuota') async getQuota(provider: string, force: boolean): Promise<TokenStatsQuotaResult>",
266
+ summary:
267
+ "Read one provider's plan quota / balance (minimax | deepseek | kimi | openrouter | zhipu), cached per provider.",
268
+ jsDoc:
269
+ "/**\n * Read the plan quota / balance for one provider through the credentials seam\n * and the provider's own endpoint. Success caches 30 s; failures back off\n * exponentially (5 s → 30 min). `force` drops the cached entry first.\n * @param provider - internal provider key.\n * @param force - bypass the cache.\n * @returns success with the display payload or a business failure.\n */",
270
+ },
271
+ {
272
+ kind: "method",
273
+ name: "getAllQuotas",
274
+ signature:
275
+ "@Remote('getAllQuotas') async getAllQuotas(force: boolean): Promise<TokenStatsAllQuotasResult>",
276
+ summary:
277
+ "Read every supported provider's quota / balance in parallel (settings page balance section).",
278
+ jsDoc:
279
+ "/**\n * Snapshot all supported providers at once; each entry is the same wire\n * value getQuota returns. `force` bypasses every provider's cache.\n * @param force - bypass the caches.\n * @returns success with the per-provider quota map.\n */",
280
+ },
123
281
  ],
124
282
  types: [
125
283
  {
@@ -142,6 +300,31 @@ export const TYPERT = {
142
300
  declaration:
143
301
  "export type TokenStatsResult = { ok: true; value: TokenStatsValue } | { ok: false; error: { code: string; message?: string } };",
144
302
  },
303
+ {
304
+ name: "TokenStatsQuotaDisplay",
305
+ declaration:
306
+ "export interface TokenStatsQuotaDisplay {\n readonly fiveHrPct: number | null;\n readonly weeklyPct: number | null;\n readonly fiveHrResetsIn: string | null;\n readonly weeklyResetsIn: string | null;\n readonly balanceText: string | null;\n readonly balanceUsd: number | null;\n readonly currency: string | null;\n}",
307
+ },
308
+ {
309
+ name: "TokenStatsQuotaValue",
310
+ declaration:
311
+ "export type TokenStatsQuotaValue =\n | { readonly ok: true; readonly provider: string; readonly display: TokenStatsQuotaDisplay }\n | { readonly ok: false; readonly provider: string; readonly kind: string; readonly message: string };",
312
+ },
313
+ {
314
+ name: "TokenStatsQuotaResult",
315
+ declaration:
316
+ "export type TokenStatsQuotaResult = { ok: true; value: TokenStatsQuotaValue } | { ok: false; error: { code: string; message?: string } };",
317
+ },
318
+ {
319
+ name: "TokenStatsAllQuotasValue",
320
+ declaration:
321
+ "export interface TokenStatsAllQuotasValue {\n readonly quotas: Record<string, TokenStatsQuotaValue>;\n}",
322
+ },
323
+ {
324
+ name: "TokenStatsAllQuotasResult",
325
+ declaration:
326
+ "export type TokenStatsAllQuotasResult = { ok: true; value: TokenStatsAllQuotasValue } | { ok: false; error: { code: string; message?: string } };",
327
+ },
145
328
  ],
146
329
  },
147
330
  ],