dsh-subscriptions 0.1.2 → 0.1.3
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.md +28 -10
- package/lib/client/ExternalUsageCards.d.ts +11 -1
- package/lib/client/ExternalUsageCards.js +18 -3
- package/lib/client/SubscriptionUsageBadge.d.ts +19 -2
- package/lib/client/SubscriptionUsageBadge.js +60 -5
- package/lib/client/UsageBadgeDisplaySetting.js +2 -2
- package/lib/client/UsageMeter.js +11 -6
- package/lib/client/locales.d.ts +2 -0
- package/lib/client/locales.js +4 -2
- package/lib/client/usage-badge-preferences.d.ts +7 -2
- package/lib/client/usage-badge-preferences.js +3 -2
- package/lib/client/usage-pace.d.ts +14 -1
- package/lib/client/usage-pace.js +14 -1
- package/lib/client.js +101 -26
- package/lib/client.js.map +1 -1
- package/lib/index.js +32 -5
- package/lib/providers/minimax-usage.d.ts +22 -1
- package/lib/providers/minimax-usage.js +37 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1033,7 +1033,37 @@ async function setDefaultAccount(provider, account, path = authFilePath()) {
|
|
|
1033
1033
|
|
|
1034
1034
|
//#endregion
|
|
1035
1035
|
//#region src/providers/minimax-usage.ts
|
|
1036
|
-
/**
|
|
1036
|
+
/**
|
|
1037
|
+
* Used percentage from the legacy counts, read as the official CLI does when no
|
|
1038
|
+
* explicit percentage exists: the count is the quota remaining. Undefined
|
|
1039
|
+
* unless the total is a positive finite number, so a zero total never yields a
|
|
1040
|
+
* bar.
|
|
1041
|
+
*/
|
|
1042
|
+
function usedFromCounts(total, count) {
|
|
1043
|
+
return typeof total === "number" && Number.isFinite(total) && total > 0 && typeof count === "number" ? (1 - count / total) * 100 : void 0;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Read MiniMax subscription quota (M Plan and Token Plan), not the balance API
|
|
1047
|
+
* that `sk-api-*` pay-as-you-go keys use.
|
|
1048
|
+
*
|
|
1049
|
+
* Each `model_remains` row can yield an interval window and a weekly window.
|
|
1050
|
+
* A window needs a finite share: the explicit `*_remaining_percent` (the weekly
|
|
1051
|
+
* one scaled by `weekly_boost_permille`), else the legacy counts. Time-based
|
|
1052
|
+
* plans report zero counts beside the percentage for standard models, so the
|
|
1053
|
+
* percentage stands on its own and a zero total does not hide the window.
|
|
1054
|
+
* Windows that cannot be a finite bar are omitted rather than approximated:
|
|
1055
|
+
* status 3 (unlimited, or no quota in the plan), a weekly pool boosted past
|
|
1056
|
+
* 100% remaining, a percentage outside 0-100, and a row with neither a
|
|
1057
|
+
* percentage nor positive counts. Start and end times are kept only when both
|
|
1058
|
+
* are valid millisecond bounds.
|
|
1059
|
+
* @param key - subscription key for the region; never copied into a result or error.
|
|
1060
|
+
* @param region - `global` or `cn`, which selects the fixed quota host.
|
|
1061
|
+
* @param http - fetch implementation (injectable for tests).
|
|
1062
|
+
* @param signal - caller cancellation from the RPC transport.
|
|
1063
|
+
* @returns the finite windows in the order the API lists them.
|
|
1064
|
+
* @throws when the key is pay-as-you-go, the endpoint or its business status
|
|
1065
|
+
* fails, the body has no `model_remains`, or no window is a finite bar.
|
|
1066
|
+
*/
|
|
1037
1067
|
async function fetchMiniMaxUsage(key, region, http$1 = fetch, signal) {
|
|
1038
1068
|
if (key.startsWith("sk-api-")) throw new Error("MiniMax requires a subscription key, not a pay-as-you-go key");
|
|
1039
1069
|
const response = await http$1(`https://www.minimax.${region === "cn" ? "cn" : "io"}/v1/token_plan/remains`, {
|
|
@@ -1066,10 +1096,7 @@ async function fetchMiniMaxUsage(key, region, http$1 = fetch, signal) {
|
|
|
1066
1096
|
const remaining = row[`${prefix}_remaining_percent`];
|
|
1067
1097
|
const boost = prefix === "current_weekly" ? row.weekly_boost_permille ?? 1e3 : 1e3;
|
|
1068
1098
|
if (typeof boost !== "number" || !Number.isFinite(boost) || boost <= 0) continue;
|
|
1069
|
-
const
|
|
1070
|
-
const count = row[`${prefix}_usage_count`];
|
|
1071
|
-
if (typeof total !== "number" || !Number.isFinite(total) || total <= 0) continue;
|
|
1072
|
-
const usedPercent = typeof remaining === "number" ? 100 - remaining * boost / 1e3 : typeof total === "number" && total > 0 && typeof count === "number" ? (1 - count / total) * 100 : void 0;
|
|
1099
|
+
const usedPercent = typeof remaining === "number" ? 100 - remaining * boost / 1e3 : usedFromCounts(row[`${prefix}_total_count`], row[`${prefix}_usage_count`]);
|
|
1073
1100
|
if (usedPercent === void 0 || !Number.isFinite(usedPercent) || usedPercent < 0 || usedPercent > 100) continue;
|
|
1074
1101
|
const start = row[startKey];
|
|
1075
1102
|
const end = row[endKey];
|
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
import type { ProviderUsage } from './common.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Read MiniMax subscription quota (M Plan and Token Plan), not the balance API
|
|
4
|
+
* that `sk-api-*` pay-as-you-go keys use.
|
|
5
|
+
*
|
|
6
|
+
* Each `model_remains` row can yield an interval window and a weekly window.
|
|
7
|
+
* A window needs a finite share: the explicit `*_remaining_percent` (the weekly
|
|
8
|
+
* one scaled by `weekly_boost_permille`), else the legacy counts. Time-based
|
|
9
|
+
* plans report zero counts beside the percentage for standard models, so the
|
|
10
|
+
* percentage stands on its own and a zero total does not hide the window.
|
|
11
|
+
* Windows that cannot be a finite bar are omitted rather than approximated:
|
|
12
|
+
* status 3 (unlimited, or no quota in the plan), a weekly pool boosted past
|
|
13
|
+
* 100% remaining, a percentage outside 0-100, and a row with neither a
|
|
14
|
+
* percentage nor positive counts. Start and end times are kept only when both
|
|
15
|
+
* are valid millisecond bounds.
|
|
16
|
+
* @param key - subscription key for the region; never copied into a result or error.
|
|
17
|
+
* @param region - `global` or `cn`, which selects the fixed quota host.
|
|
18
|
+
* @param http - fetch implementation (injectable for tests).
|
|
19
|
+
* @param signal - caller cancellation from the RPC transport.
|
|
20
|
+
* @returns the finite windows in the order the API lists them.
|
|
21
|
+
* @throws when the key is pay-as-you-go, the endpoint or its business status
|
|
22
|
+
* fails, the body has no `model_remains`, or no window is a finite bar.
|
|
23
|
+
*/
|
|
3
24
|
export declare function fetchMiniMaxUsage(key: string, region: 'global' | 'cn', http?: typeof fetch, signal?: AbortSignal): Promise<ProviderUsage>;
|
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Used percentage from the legacy counts, read as the official CLI does when no
|
|
3
|
+
* explicit percentage exists: the count is the quota remaining. Undefined
|
|
4
|
+
* unless the total is a positive finite number, so a zero total never yields a
|
|
5
|
+
* bar.
|
|
6
|
+
*/
|
|
7
|
+
function usedFromCounts(total, count) {
|
|
8
|
+
return typeof total === 'number' && Number.isFinite(total) && total > 0 && typeof count === 'number'
|
|
9
|
+
? (1 - count / total) * 100
|
|
10
|
+
: undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read MiniMax subscription quota (M Plan and Token Plan), not the balance API
|
|
14
|
+
* that `sk-api-*` pay-as-you-go keys use.
|
|
15
|
+
*
|
|
16
|
+
* Each `model_remains` row can yield an interval window and a weekly window.
|
|
17
|
+
* A window needs a finite share: the explicit `*_remaining_percent` (the weekly
|
|
18
|
+
* one scaled by `weekly_boost_permille`), else the legacy counts. Time-based
|
|
19
|
+
* plans report zero counts beside the percentage for standard models, so the
|
|
20
|
+
* percentage stands on its own and a zero total does not hide the window.
|
|
21
|
+
* Windows that cannot be a finite bar are omitted rather than approximated:
|
|
22
|
+
* status 3 (unlimited, or no quota in the plan), a weekly pool boosted past
|
|
23
|
+
* 100% remaining, a percentage outside 0-100, and a row with neither a
|
|
24
|
+
* percentage nor positive counts. Start and end times are kept only when both
|
|
25
|
+
* are valid millisecond bounds.
|
|
26
|
+
* @param key - subscription key for the region; never copied into a result or error.
|
|
27
|
+
* @param region - `global` or `cn`, which selects the fixed quota host.
|
|
28
|
+
* @param http - fetch implementation (injectable for tests).
|
|
29
|
+
* @param signal - caller cancellation from the RPC transport.
|
|
30
|
+
* @returns the finite windows in the order the API lists them.
|
|
31
|
+
* @throws when the key is pay-as-you-go, the endpoint or its business status
|
|
32
|
+
* fails, the body has no `model_remains`, or no window is a finite bar.
|
|
33
|
+
*/
|
|
2
34
|
export async function fetchMiniMaxUsage(key, region, http = fetch, signal) {
|
|
3
35
|
if (key.startsWith('sk-api-'))
|
|
4
36
|
throw new Error('MiniMax requires a subscription key, not a pay-as-you-go key');
|
|
@@ -30,13 +62,11 @@ export async function fetchMiniMaxUsage(key, region, http = fetch, signal) {
|
|
|
30
62
|
const boost = prefix === 'current_weekly' ? row.weekly_boost_permille ?? 1000 : 1000;
|
|
31
63
|
if (typeof boost !== 'number' || !Number.isFinite(boost) || boost <= 0)
|
|
32
64
|
continue;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
continue;
|
|
37
|
-
// Official CLI compatibility: absent percentages use legacy remaining counts.
|
|
65
|
+
// An explicit percentage needs no counts: time-based plans send zero
|
|
66
|
+
// counts beside it. Official CLI compatibility: without a percentage, the
|
|
67
|
+
// legacy counts are the quota remaining.
|
|
38
68
|
const usedPercent = typeof remaining === 'number' ? 100 - remaining * boost / 1000
|
|
39
|
-
:
|
|
69
|
+
: usedFromCounts(row[`${prefix}_total_count`], row[`${prefix}_usage_count`]);
|
|
40
70
|
if (usedPercent === undefined || !Number.isFinite(usedPercent) || usedPercent < 0 || usedPercent > 100)
|
|
41
71
|
continue;
|
|
42
72
|
const start = row[startKey];
|