@kenz1117/dsh-ui-usage-billing 0.9.6 → 0.9.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/README.en.md +2 -1
- package/README.md +5 -3
- package/lib/client.js +946 -390
- package/lib/index.js +1046 -304
- package/lib/types/aggregate.d.ts +48 -1
- package/lib/types/balance.d.ts +5 -6
- package/lib/types/client/PerfPanel.d.ts +45 -0
- package/lib/types/client/PluginInfoCard.d.ts +12 -0
- package/lib/types/client/TokenPanel.d.ts +24 -0
- package/lib/types/client/UsageBilling.d.ts +117 -1
- package/lib/types/client/heatmap.d.ts +4 -2
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/plan-knowledge.d.ts +24 -5
- package/lib/types/client/plugin-info.d.ts +20 -0
- package/lib/types/client/usage-billing-settings.d.ts +20 -0
- package/lib/types/index.d.ts +28 -2
- package/lib/types/pricing-shared.d.ts +25 -2
- package/lib/types/relay.d.ts +61 -0
- package/lib/types/resilience.d.ts +49 -0
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上游网络请求的稳定性工具:有限重试(指数退避)与每平台熔断冷却门。
|
|
3
|
+
*
|
|
4
|
+
* 计费插件对三类上游做实时请求——pricing(汇率 / OpenRouter / models.dev)、
|
|
5
|
+
* balance(各厂商余额)、subscriptions(各订阅额度)。单次失败会被调用方降级,
|
|
6
|
+
* 但反复的瞬时失败(网络波动 / 5xx / 429)会让 30 秒轮询每次打满超时。这里提供
|
|
7
|
+
* 两个纯工具:`withRetry` 对可重试错误做指数退避,`createCooldownGate` 在单一
|
|
8
|
+
* 上游连续失败后短路一段时间,避免把请求打到已不可用的服务上。
|
|
9
|
+
*/
|
|
10
|
+
/** 是否是可重试的错误:网络性失败(TypeError / Abort / Timeout)或 5xx / 429。
|
|
11
|
+
* 401 / 403 鉴权失败与 404 不可重试——重试只放大错误、不会变好。 */
|
|
12
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
13
|
+
/** 重试配置。 */
|
|
14
|
+
export interface RetryOptions {
|
|
15
|
+
/** 除首次尝试外的额外重试次数(默认 1)。 */
|
|
16
|
+
retries?: number;
|
|
17
|
+
/** 首次退避基数(默认 250ms)。 */
|
|
18
|
+
baseDelayMs?: number;
|
|
19
|
+
/** 退避上限(默认 2000ms)。 */
|
|
20
|
+
maxDelayMs?: number;
|
|
21
|
+
/** 何时重试;默认 {@link isRetryableError}。 */
|
|
22
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 对一次上游请求做有限重试:可重试错误时按指数退避(+同量级抖动)重试。
|
|
26
|
+
* @param fn - 发起请求的异步函数。
|
|
27
|
+
* @param options - 重试策略(见 {@link RetryOptions})。
|
|
28
|
+
* @returns fn 的结果;重试耗尽后抛出最后一次错误。
|
|
29
|
+
*/
|
|
30
|
+
export declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
31
|
+
/** 熔断冷却门配置。 */
|
|
32
|
+
export interface CooldownGateOptions {
|
|
33
|
+
/** 连续失败达到该次数进入冷却(默认 3)。 */
|
|
34
|
+
failures?: number;
|
|
35
|
+
/** 冷却时长(默认 30 秒)。 */
|
|
36
|
+
cooldownMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/** 每平台熔断门:check 是否允许请求;fail / success 上报结果。 */
|
|
39
|
+
export interface CooldownGate {
|
|
40
|
+
/** 该平台是否允许发起请求。false 表示处于冷却中,调用方应短路为不可用。 */
|
|
41
|
+
check(key: string): boolean;
|
|
42
|
+
/** 上报一次失败(可能进入冷却)。 */
|
|
43
|
+
fail(key: string): void;
|
|
44
|
+
/** 上报一次成功(重置失败计数与冷却)。 */
|
|
45
|
+
success(key: string): void;
|
|
46
|
+
}
|
|
47
|
+
/** 每平台冷熔断:连续失败达阈值后短路一段真实时间,成功后复位。 */
|
|
48
|
+
export declare function createCooldownGate(options?: CooldownGateOptions): CooldownGate;
|
|
49
|
+
//# sourceMappingURL=resilience.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.8",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|