@laoyuehanni/dsh-token-usage 0.3.7
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/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh.md +182 -0
- package/cordis.patch.yml +7 -0
- package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
- package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
- package/lib/client/CostDeltaFlyLabel.js +24 -0
- package/lib/client/CostDeltaFlyLabel.js.map +1 -0
- package/lib/client/HitRateText.d.ts +21 -0
- package/lib/client/HitRateText.d.ts.map +1 -0
- package/lib/client/HitRateText.js +16 -0
- package/lib/client/HitRateText.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +70 -0
- package/lib/client/QuotaButton.d.ts.map +1 -0
- package/lib/client/QuotaButton.js +346 -0
- package/lib/client/QuotaButton.js.map +1 -0
- package/lib/client/SessionStatsChip.d.ts +47 -0
- package/lib/client/SessionStatsChip.d.ts.map +1 -0
- package/lib/client/SessionStatsChip.js +141 -0
- package/lib/client/SessionStatsChip.js.map +1 -0
- package/lib/client/StatCard.d.ts +26 -0
- package/lib/client/StatCard.d.ts.map +1 -0
- package/lib/client/StatCard.js +10 -0
- package/lib/client/StatCard.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts +41 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -0
- package/lib/client/TokenUsageCard.js +164 -0
- package/lib/client/TokenUsageCard.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +32 -0
- package/lib/client/TokenUsageSection.d.ts.map +1 -0
- package/lib/client/TokenUsageSection.js +266 -0
- package/lib/client/TokenUsageSection.js.map +1 -0
- package/lib/client/TrendChart.d.ts +53 -0
- package/lib/client/TrendChart.d.ts.map +1 -0
- package/lib/client/TrendChart.js +141 -0
- package/lib/client/TrendChart.js.map +1 -0
- package/lib/client/UsageView.d.ts +42 -0
- package/lib/client/UsageView.d.ts.map +1 -0
- package/lib/client/UsageView.js +158 -0
- package/lib/client/UsageView.js.map +1 -0
- package/lib/client/async-resource.d.ts +54 -0
- package/lib/client/async-resource.d.ts.map +1 -0
- package/lib/client/async-resource.js +90 -0
- package/lib/client/async-resource.js.map +1 -0
- package/lib/client/card-form.d.ts +171 -0
- package/lib/client/card-form.d.ts.map +1 -0
- package/lib/client/card-form.js +300 -0
- package/lib/client/card-form.js.map +1 -0
- package/lib/client/cost-inflate-motion.d.ts +17 -0
- package/lib/client/cost-inflate-motion.d.ts.map +1 -0
- package/lib/client/cost-inflate-motion.js +61 -0
- package/lib/client/cost-inflate-motion.js.map +1 -0
- package/lib/client/cost-inflate.d.ts +28 -0
- package/lib/client/cost-inflate.d.ts.map +1 -0
- package/lib/client/cost-inflate.js +49 -0
- package/lib/client/cost-inflate.js.map +1 -0
- package/lib/client/day.d.ts +49 -0
- package/lib/client/day.d.ts.map +1 -0
- package/lib/client/day.js +84 -0
- package/lib/client/day.js.map +1 -0
- package/lib/client/format.d.ts +120 -0
- package/lib/client/format.d.ts.map +1 -0
- package/lib/client/format.js +163 -0
- package/lib/client/format.js.map +1 -0
- package/lib/client/index.d.ts +26 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +131 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/locales.d.ts +131 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/locales.js +230 -0
- package/lib/client/locales.js.map +1 -0
- package/lib/client/quota-format.d.ts +69 -0
- package/lib/client/quota-format.d.ts.map +1 -0
- package/lib/client/quota-format.js +147 -0
- package/lib/client/quota-format.js.map +1 -0
- package/lib/client/session-stats.d.ts +105 -0
- package/lib/client/session-stats.d.ts.map +1 -0
- package/lib/client/session-stats.js +142 -0
- package/lib/client/session-stats.js.map +1 -0
- package/lib/client/trend-chart/axis.d.ts +21 -0
- package/lib/client/trend-chart/axis.d.ts.map +1 -0
- package/lib/client/trend-chart/axis.js +33 -0
- package/lib/client/trend-chart/axis.js.map +1 -0
- package/lib/client/trend-chart/bucket.d.ts +24 -0
- package/lib/client/trend-chart/bucket.d.ts.map +1 -0
- package/lib/client/trend-chart/bucket.js +28 -0
- package/lib/client/trend-chart/bucket.js.map +1 -0
- package/lib/client/trend-chart/index.d.ts +12 -0
- package/lib/client/trend-chart/index.d.ts.map +1 -0
- package/lib/client/trend-chart/index.js +9 -0
- package/lib/client/trend-chart/index.js.map +1 -0
- package/lib/client/trend-chart/points.d.ts +46 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -0
- package/lib/client/trend-chart/points.js +82 -0
- package/lib/client/trend-chart/points.js.map +1 -0
- package/lib/client/trend-chart/scale.d.ts +47 -0
- package/lib/client/trend-chart/scale.d.ts.map +1 -0
- package/lib/client/trend-chart/scale.js +75 -0
- package/lib/client/trend-chart/scale.js.map +1 -0
- package/lib/client/use-color-scheme.d.ts +18 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -0
- package/lib/client/use-color-scheme.js +37 -0
- package/lib/client/use-color-scheme.js.map +1 -0
- package/lib/client/use-cost-inflate.d.ts +33 -0
- package/lib/client/use-cost-inflate.d.ts.map +1 -0
- package/lib/client/use-cost-inflate.js +108 -0
- package/lib/client/use-cost-inflate.js.map +1 -0
- package/lib/client.js +3892 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +599 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +60 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +126 -0
- package/lib/migrate.js.map +1 -0
- package/lib/pricing.d.ts +212 -0
- package/lib/pricing.d.ts.map +1 -0
- package/lib/pricing.js +492 -0
- package/lib/pricing.js.map +1 -0
- package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
- package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
- package/lib/quota/adapters/deepseek-balance.js +76 -0
- package/lib/quota/adapters/deepseek-balance.js.map +1 -0
- package/lib/quota/adapters/kimi.d.ts +26 -0
- package/lib/quota/adapters/kimi.d.ts.map +1 -0
- package/lib/quota/adapters/kimi.js +91 -0
- package/lib/quota/adapters/kimi.js.map +1 -0
- package/lib/quota/adapters/minimax.d.ts +24 -0
- package/lib/quota/adapters/minimax.d.ts.map +1 -0
- package/lib/quota/adapters/minimax.js +136 -0
- package/lib/quota/adapters/minimax.js.map +1 -0
- package/lib/quota/adapters/opencode-go.d.ts +25 -0
- package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
- package/lib/quota/adapters/opencode-go.js +105 -0
- package/lib/quota/adapters/opencode-go.js.map +1 -0
- package/lib/quota/adapters/openrouter.d.ts +15 -0
- package/lib/quota/adapters/openrouter.d.ts.map +1 -0
- package/lib/quota/adapters/openrouter.js +54 -0
- package/lib/quota/adapters/openrouter.js.map +1 -0
- package/lib/quota/adapters/zhipu.d.ts +38 -0
- package/lib/quota/adapters/zhipu.d.ts.map +1 -0
- package/lib/quota/adapters/zhipu.js +246 -0
- package/lib/quota/adapters/zhipu.js.map +1 -0
- package/lib/quota/credentials.d.ts +79 -0
- package/lib/quota/credentials.d.ts.map +1 -0
- package/lib/quota/credentials.js +130 -0
- package/lib/quota/credentials.js.map +1 -0
- package/lib/quota/http.d.ts +49 -0
- package/lib/quota/http.d.ts.map +1 -0
- package/lib/quota/http.js +114 -0
- package/lib/quota/http.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +45 -0
- package/lib/quota/provider-tracking.d.ts.map +1 -0
- package/lib/quota/provider-tracking.js +52 -0
- package/lib/quota/provider-tracking.js.map +1 -0
- package/lib/quota/quota-route.d.ts +22 -0
- package/lib/quota/quota-route.d.ts.map +1 -0
- package/lib/quota/quota-route.js +57 -0
- package/lib/quota/quota-route.js.map +1 -0
- package/lib/quota/quota-service.d.ts +54 -0
- package/lib/quota/quota-service.d.ts.map +1 -0
- package/lib/quota/quota-service.js +171 -0
- package/lib/quota/quota-service.js.map +1 -0
- package/lib/quota/registry.d.ts +24 -0
- package/lib/quota/registry.d.ts.map +1 -0
- package/lib/quota/registry.js +38 -0
- package/lib/quota/registry.js.map +1 -0
- package/lib/quota/types.d.ts +79 -0
- package/lib/quota/types.d.ts.map +1 -0
- package/lib/quota/types.js +24 -0
- package/lib/quota/types.js.map +1 -0
- package/lib/record-cache.d.ts +38 -0
- package/lib/record-cache.d.ts.map +1 -0
- package/lib/record-cache.js +143 -0
- package/lib/record-cache.js.map +1 -0
- package/lib/rollup.d.ts +52 -0
- package/lib/rollup.d.ts.map +1 -0
- package/lib/rollup.js +117 -0
- package/lib/rollup.js.map +1 -0
- package/lib/stats-route.d.ts +88 -0
- package/lib/stats-route.d.ts.map +1 -0
- package/lib/stats-route.js +313 -0
- package/lib/stats-route.js.map +1 -0
- package/lib/stats.d.ts +158 -0
- package/lib/stats.d.ts.map +1 -0
- package/lib/stats.js +426 -0
- package/lib/stats.js.map +1 -0
- package/lib/sync-state.d.ts +27 -0
- package/lib/sync-state.d.ts.map +1 -0
- package/lib/sync-state.js +56 -0
- package/lib/sync-state.js.map +1 -0
- package/lib/sync.d.ts +74 -0
- package/lib/sync.d.ts.map +1 -0
- package/lib/sync.js +64 -0
- package/lib/sync.js.map +1 -0
- package/lib/trend-bucket.d.ts +48 -0
- package/lib/trend-bucket.d.ts.map +1 -0
- package/lib/trend-bucket.js +87 -0
- package/lib/trend-bucket.js.map +1 -0
- package/lib/usage-log.d.ts +64 -0
- package/lib/usage-log.d.ts.map +1 -0
- package/lib/usage-log.js +144 -0
- package/lib/usage-log.js.map +1 -0
- package/lib/usage-record.d.ts +59 -0
- package/lib/usage-record.d.ts.map +1 -0
- package/lib/usage-record.js +115 -0
- package/lib/usage-record.js.map +1 -0
- package/lib/wire.d.ts +452 -0
- package/lib/wire.d.ts.map +1 -0
- package/lib/wire.js +144 -0
- package/lib/wire.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi For Coding adapter (月之暗面编程套餐): the 5-hour rolling window(s)
|
|
3
|
+
* and the weekly window of the coding-plan subscription.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://api.kimi.com/coding/v1/usages` with a Bearer key.
|
|
6
|
+
* The response carries `limits[]` — one entry per active 5-hour bucket,
|
|
7
|
+
* and there CAN be several (the window rolls per request batch) — plus a
|
|
8
|
+
* top-level `usage` object for the weekly bucket. Each bucket reports
|
|
9
|
+
* `{ limit, remaining, resetTime }`; the used share is derived.
|
|
10
|
+
*
|
|
11
|
+
* Route matching is host-first: the pi-ai `moonshotai` routes point at the
|
|
12
|
+
* standard Moonshot API (api.moonshot.cn / api.moonshot.ai), which has no
|
|
13
|
+
* coding-plan quota endpoint, so those must never match by route key. The
|
|
14
|
+
* coding plan is identified by its api.kimi.com host — exactly the signal
|
|
15
|
+
* cc-switch's `detect_provider` uses — or by the catalog route
|
|
16
|
+
* `kimi-coding` (whose catalog endpoint is filled in when the profile
|
|
17
|
+
* omits `baseURL`).
|
|
18
|
+
*
|
|
19
|
+
* @module token-usage/quota/adapters/kimi
|
|
20
|
+
*/
|
|
21
|
+
import { fetchJson, hostOf, numberOf, toEpochMs } from "../http.js";
|
|
22
|
+
import { QuotaQueryError } from "../types.js";
|
|
23
|
+
/** The coding-plan host; the quota endpoint is fixed (no per-route base). */
|
|
24
|
+
const KIMI_HOST = 'api.kimi.com';
|
|
25
|
+
const QUOTA_URL = `https://${KIMI_HOST}/coding/v1/usages`;
|
|
26
|
+
/** The pi-ai catalog route of the coding plan; moonshotai is NOT this. */
|
|
27
|
+
const ROUTE_KIMI_CODING = 'kimi-coding';
|
|
28
|
+
/** Whether a host is the Kimi coding-plan endpoint (subdomains included). */
|
|
29
|
+
export function isKimiHost(baseUrl) {
|
|
30
|
+
const host = hostOf(baseUrl);
|
|
31
|
+
return host === KIMI_HOST || (host?.endsWith(`.${KIMI_HOST}`) ?? false);
|
|
32
|
+
}
|
|
33
|
+
/** One `{ limit, remaining, resetTime }` bucket → a used-percent window. */
|
|
34
|
+
function windowOf(tier, raw) {
|
|
35
|
+
if (typeof raw !== 'object' || raw === null)
|
|
36
|
+
return undefined;
|
|
37
|
+
const bucket = raw;
|
|
38
|
+
const limit = numberOf(bucket.limit);
|
|
39
|
+
const remaining = numberOf(bucket.remaining);
|
|
40
|
+
if (limit === undefined || limit <= 0 || remaining === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
const resetAt = toEpochMs(bucket.resetTime);
|
|
43
|
+
return {
|
|
44
|
+
tier,
|
|
45
|
+
usedPercent: Math.min(100, Math.max(0, ((limit - remaining) / limit) * 100)),
|
|
46
|
+
...(resetAt !== undefined ? { resetAt } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** The Kimi For Coding adapter: 5-hour + weekly windows. */
|
|
50
|
+
export const kimiAdapter = {
|
|
51
|
+
id: 'kimi-coding-plan',
|
|
52
|
+
label: 'Kimi For Coding',
|
|
53
|
+
routes: [ROUTE_KIMI_CODING],
|
|
54
|
+
matches: input => input.provider === ROUTE_KIMI_CODING || isKimiHost(input.baseUrl),
|
|
55
|
+
async query(ctx) {
|
|
56
|
+
const body = await fetchJson(ctx, QUOTA_URL, { authorization: `Bearer ${ctx.apiKey}` });
|
|
57
|
+
if (typeof body !== 'object' || body === null) {
|
|
58
|
+
throw new QuotaQueryError('parse', 'response is not an object');
|
|
59
|
+
}
|
|
60
|
+
const record = body;
|
|
61
|
+
// Several 5-hour buckets can be live at once (the window rolls); the
|
|
62
|
+
// one resetting LATEST is the freshest — the bucket the current
|
|
63
|
+
// requests feed. cc-switch renders every bucket; a single panel column
|
|
64
|
+
// wants that freshest one.
|
|
65
|
+
const buckets = [];
|
|
66
|
+
if (Array.isArray(record.limits)) {
|
|
67
|
+
for (const entry of record.limits) {
|
|
68
|
+
const detail = typeof entry === 'object' && entry !== null
|
|
69
|
+
? entry.detail
|
|
70
|
+
: undefined;
|
|
71
|
+
const window = windowOf('five_hour', detail);
|
|
72
|
+
if (window !== undefined)
|
|
73
|
+
buckets.push(window);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const fiveHour = buckets.length > 0
|
|
77
|
+
? buckets.reduce((latest, next) => (next.resetAt ?? 0) >= (latest.resetAt ?? 0) ? next : latest)
|
|
78
|
+
: undefined;
|
|
79
|
+
const weekly = windowOf('weekly', record.usage);
|
|
80
|
+
const windows = [];
|
|
81
|
+
if (fiveHour !== undefined)
|
|
82
|
+
windows.push(fiveHour);
|
|
83
|
+
if (weekly !== undefined)
|
|
84
|
+
windows.push(weekly);
|
|
85
|
+
if (windows.length === 0) {
|
|
86
|
+
throw new QuotaQueryError('parse', 'no usable limit buckets in response');
|
|
87
|
+
}
|
|
88
|
+
return { windows };
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=kimi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kimi.js","sourceRoot":"","sources":["../../../src/quota/adapters/kimi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,6EAA6E;AAC7E,MAAM,SAAS,GAAG,cAAc,CAAA;AAChC,MAAM,SAAS,GAAG,WAAW,SAAS,mBAAmB,CAAA;AAEzD,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,aAAa,CAAA;AAEvC,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC5B,OAAO,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,IAAI,KAAK,CAAC,CAAA;AACzE,CAAC;AAED,4EAA4E;AAC5E,SAAS,QAAQ,CAAC,IAAyB,EAAE,GAAY;IACvD,IA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AAI,CAAC,MAAM,CAAC,CAAA;QAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,qCAAqC,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,CAAA;IACpB,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MiniMax Coding Plan adapter (国内/国际站): the 5-hour interval window
|
|
3
|
+
* and the optional weekly window.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains`
|
|
6
|
+
* (international `api.minimax.io`, same path) with a Bearer key. Of the
|
|
7
|
+
* `model_remains[]` entries only `model_name: "general"` is the coding
|
|
8
|
+
* quota (video and friends are separate meters). Three semantic quirks
|
|
9
|
+
* cc-switch documented: the percents are REMAINING shares (inverted into
|
|
10
|
+
* used here), a `status == 3` lane is the server's "no entitlement here"
|
|
11
|
+
* PLACEHOLDER (typically a full 100% remaining, sometimes none) that must
|
|
12
|
+
* not paint a window, and business errors ride a 200 with
|
|
13
|
+
* `base_resp.status_code != 0`. The status field itself is optional in
|
|
14
|
+
* live responses — gating on `status == 1` would hide real windows
|
|
15
|
+
* whenever it goes missing — so the guard keys on the placeholder
|
|
16
|
+
* COMBINATION (status 3 with a placeholder-looking percent), not on the
|
|
17
|
+
* status alone (token-monitor's live-verified shapes).
|
|
18
|
+
*
|
|
19
|
+
* @module token-usage/quota/adapters/minimax
|
|
20
|
+
*/
|
|
21
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
22
|
+
/** The MiniMax coding-plan adapter: 5-hour + optional weekly windows. */
|
|
23
|
+
export declare const minimaxAdapter: QuotaAdapter;
|
|
24
|
+
//# sourceMappingURL=minimax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimax.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/minimax.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,aAAa,CAAA;AA2CpF,yEAAyE;AACzE,eAAO,MAAM,cAAc,EAAE,YA2E5B,CAAA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MiniMax Coding Plan adapter (国内/国际站): the 5-hour interval window
|
|
3
|
+
* and the optional weekly window.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains`
|
|
6
|
+
* (international `api.minimax.io`, same path) with a Bearer key. Of the
|
|
7
|
+
* `model_remains[]` entries only `model_name: "general"` is the coding
|
|
8
|
+
* quota (video and friends are separate meters). Three semantic quirks
|
|
9
|
+
* cc-switch documented: the percents are REMAINING shares (inverted into
|
|
10
|
+
* used here), a `status == 3` lane is the server's "no entitlement here"
|
|
11
|
+
* PLACEHOLDER (typically a full 100% remaining, sometimes none) that must
|
|
12
|
+
* not paint a window, and business errors ride a 200 with
|
|
13
|
+
* `base_resp.status_code != 0`. The status field itself is optional in
|
|
14
|
+
* live responses — gating on `status == 1` would hide real windows
|
|
15
|
+
* whenever it goes missing — so the guard keys on the placeholder
|
|
16
|
+
* COMBINATION (status 3 with a placeholder-looking percent), not on the
|
|
17
|
+
* status alone (token-monitor's live-verified shapes).
|
|
18
|
+
*
|
|
19
|
+
* @module token-usage/quota/adapters/minimax
|
|
20
|
+
*/
|
|
21
|
+
import { fetchJson, hostOf, numberOf, toEpochMs } from "../http.js";
|
|
22
|
+
import { QuotaQueryError } from "../types.js";
|
|
23
|
+
/** Quota hosts of the two stations; the path is fixed on both. */
|
|
24
|
+
const DOMESTIC_HOST = 'api.minimaxi.com';
|
|
25
|
+
const INTERNATIONAL_HOST = 'api.minimax.io';
|
|
26
|
+
const QUOTA_PATH = '/v1/api/openplatform/coding_plan/remains';
|
|
27
|
+
/** The pi-ai catalog routes: `minimax` is the international station,
|
|
28
|
+
* `minimax-cn` the domestic one. Host match still catches user-declared
|
|
29
|
+
* routes pointing at the same endpoints. */
|
|
30
|
+
const ROUTE_INTERNATIONAL = 'minimax';
|
|
31
|
+
const ROUTE_DOMESTIC = 'minimax-cn';
|
|
32
|
+
const ROUTES = new Set([ROUTE_INTERNATIONAL, ROUTE_DOMESTIC]);
|
|
33
|
+
/** Which station's quota host a route/base-URL resolves to. Host wins
|
|
34
|
+
* (a catalog route can override its endpoint); the route key is the
|
|
35
|
+
* fallback when the profile omitted `baseURL`. */
|
|
36
|
+
function quotaHost(ctx) {
|
|
37
|
+
const host = hostOf(ctx.baseUrl);
|
|
38
|
+
if (host === INTERNATIONAL_HOST || host?.endsWith(`.${INTERNATIONAL_HOST}`))
|
|
39
|
+
return INTERNATIONAL_HOST;
|
|
40
|
+
if (host === DOMESTIC_HOST || host?.endsWith(`.${DOMESTIC_HOST}`))
|
|
41
|
+
return DOMESTIC_HOST;
|
|
42
|
+
return ctx.provider === ROUTE_INTERNATIONAL ? INTERNATIONAL_HOST : DOMESTIC_HOST;
|
|
43
|
+
}
|
|
44
|
+
/** Invert a remaining-percent field into the used share; undefined stays
|
|
45
|
+
* undefined (the weekly window is legitimately absent on some plans). */
|
|
46
|
+
function usedOf(remaining) {
|
|
47
|
+
const value = numberOf(remaining);
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
return Math.min(100, Math.max(0, 100 - value));
|
|
51
|
+
}
|
|
52
|
+
/** Whether a lane is the server's no-entitlement placeholder: status 3
|
|
53
|
+
* with a placeholder-looking percent (none, or a full 100% remaining).
|
|
54
|
+
* A status-3 lane with a real percent stays visible, and a lane whose
|
|
55
|
+
* status field is simply absent — as live responses can ship it — shows
|
|
56
|
+
* whenever its percent exists. */
|
|
57
|
+
function isPlaceholderLane(entry, percentField, statusField) {
|
|
58
|
+
if (numberOf(entry[statusField]) !== 3)
|
|
59
|
+
return false;
|
|
60
|
+
const percent = numberOf(entry[percentField]);
|
|
61
|
+
return percent === undefined || percent >= 100;
|
|
62
|
+
}
|
|
63
|
+
/** The MiniMax coding-plan adapter: 5-hour + optional weekly windows. */
|
|
64
|
+
export const minimaxAdapter = {
|
|
65
|
+
id: 'minimax-coding-plan',
|
|
66
|
+
label: 'MiniMax Coding Plan',
|
|
67
|
+
routes: [ROUTE_INTERNATIONAL, ROUTE_DOMESTIC],
|
|
68
|
+
matches(input) {
|
|
69
|
+
if (ROUTES.has(input.provider))
|
|
70
|
+
return true;
|
|
71
|
+
const host = hostOf(input.baseUrl);
|
|
72
|
+
return host !== undefined
|
|
73
|
+
&& (host === DOMESTIC_HOST || host.endsWith(`.${DOMESTIC_HOST}`)
|
|
74
|
+
|| host === INTERNATIONAL_HOST || host.endsWith(`.${INTERNATIONAL_HOST}`));
|
|
75
|
+
},
|
|
76
|
+
async query(ctx) {
|
|
77
|
+
const body = await fetchJson(ctx, `https://${quotaHost(ctx)}${QUOTA_PATH}`, {
|
|
78
|
+
authorization: `Bearer ${ctx.apiKey}`,
|
|
79
|
+
});
|
|
80
|
+
if (typeof body !== 'object' || body === null) {
|
|
81
|
+
throw new QuotaQueryError('parse', 'response is not an object');
|
|
82
|
+
}
|
|
83
|
+
const record = body;
|
|
84
|
+
// Business errors ride HTTP 200: a non-zero status_code is the real
|
|
85
|
+
// failure signal (wrong key shape, no plan, …).
|
|
86
|
+
const baseResp = record.base_resp;
|
|
87
|
+
if (typeof baseResp === 'object' && baseResp !== null) {
|
|
88
|
+
const statusCode = baseResp.status_code;
|
|
89
|
+
if (typeof statusCode === 'number' && statusCode !== 0) {
|
|
90
|
+
const message = baseResp.status_msg;
|
|
91
|
+
throw new QuotaQueryError('http', typeof message === 'string' && message !== '' ? message : `status_code ${String(statusCode)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const remains = record.model_remains;
|
|
95
|
+
if (!Array.isArray(remains)) {
|
|
96
|
+
throw new QuotaQueryError('parse', 'missing "model_remains" array');
|
|
97
|
+
}
|
|
98
|
+
const general = remains.find(entry => typeof entry === 'object' && entry !== null
|
|
99
|
+
&& entry.model_name === 'general');
|
|
100
|
+
if (general === undefined) {
|
|
101
|
+
throw new QuotaQueryError('parse', 'no "general" entry in "model_remains"');
|
|
102
|
+
}
|
|
103
|
+
const entry = general;
|
|
104
|
+
// Both lanes suppress only the status-3 placeholder combination —
|
|
105
|
+
// see isPlaceholderLane. Everything else paints whenever its percent
|
|
106
|
+
// exists.
|
|
107
|
+
const intervalUsed = isPlaceholderLane(entry, 'current_interval_remaining_percent', 'current_interval_status')
|
|
108
|
+
? undefined
|
|
109
|
+
: usedOf(entry.current_interval_remaining_percent);
|
|
110
|
+
const intervalReset = toEpochMs(entry.end_time);
|
|
111
|
+
const weeklyUsed = isPlaceholderLane(entry, 'current_weekly_remaining_percent', 'current_weekly_status')
|
|
112
|
+
? undefined
|
|
113
|
+
: usedOf(entry.current_weekly_remaining_percent);
|
|
114
|
+
const weeklyReset = toEpochMs(entry.weekly_end_time);
|
|
115
|
+
const windows = [];
|
|
116
|
+
if (intervalUsed !== undefined) {
|
|
117
|
+
windows.push({
|
|
118
|
+
tier: 'five_hour',
|
|
119
|
+
usedPercent: intervalUsed,
|
|
120
|
+
...(intervalReset !== undefined ? { resetAt: intervalReset } : {}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (weeklyUsed !== undefined) {
|
|
124
|
+
windows.push({
|
|
125
|
+
tier: 'weekly',
|
|
126
|
+
usedPercent: weeklyUsed,
|
|
127
|
+
...(weeklyReset !== undefined ? { resetAt: weeklyReset } : {}),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (windows.length === 0) {
|
|
131
|
+
throw new QuotaQueryError('parse', '"general" entry carries no interval quota');
|
|
132
|
+
}
|
|
133
|
+
return { windows };
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=minimax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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
|
|
2
|
+
* OpenCode Go adapter (Zen Go 订阅套餐): the 5-hour rolling window, the
|
|
3
|
+
* weekly window, and the monthly window of the Go membership.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://opencode.ai/zen/go/v1/usage` with a Bearer key
|
|
6
|
+
* (the same Anthropic-compatible OpenCode key used for inference). The
|
|
7
|
+
* body is `{ usage: { rolling, weekly, monthly } }`; each lane carries
|
|
8
|
+
* `{ status, percent, resetsAt }`. `percent` is the USED share (0–100)
|
|
9
|
+
* — the field lives under `usage`, and a live account with a fresh 5-hour
|
|
10
|
+
* bucket answers `0`. `resetsAt` is ISO-8601. A lane without a computable
|
|
11
|
+
* percent is skipped rather than painted empty; `status: "rate-limited"`
|
|
12
|
+
* still paints when percent is present.
|
|
13
|
+
*
|
|
14
|
+
* Matching must not collide with OpenCode Zen (pay-as-you-go, route
|
|
15
|
+
* `opencode`, path `/zen/v1`): the catalog route is `opencode-go`, and a
|
|
16
|
+
* custom route matches only when its base URL path contains `/zen/go`.
|
|
17
|
+
*
|
|
18
|
+
* @module token-usage/quota/adapters/opencode-go
|
|
19
|
+
*/
|
|
20
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
21
|
+
/** Whether a base URL is the Go subscription (path `/zen/go`), not Zen. */
|
|
22
|
+
export declare function isOpenCodeGoUrl(baseUrl: string | undefined): boolean;
|
|
23
|
+
/** The OpenCode Go adapter: 5-hour + weekly + monthly windows. */
|
|
24
|
+
export declare const opencodeGoAdapter: QuotaAdapter;
|
|
25
|
+
//# sourceMappingURL=opencode-go.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-go.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/opencode-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAA;AAejE,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAUpE;AA2BD,kEAAkE;AAClE,eAAO,MAAM,iBAAiB,EAAE,YA4B/B,CAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Go adapter (Zen Go 订阅套餐): the 5-hour rolling window, the
|
|
3
|
+
* weekly window, and the monthly window of the Go membership.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://opencode.ai/zen/go/v1/usage` with a Bearer key
|
|
6
|
+
* (the same Anthropic-compatible OpenCode key used for inference). The
|
|
7
|
+
* body is `{ usage: { rolling, weekly, monthly } }`; each lane carries
|
|
8
|
+
* `{ status, percent, resetsAt }`. `percent` is the USED share (0–100)
|
|
9
|
+
* — the field lives under `usage`, and a live account with a fresh 5-hour
|
|
10
|
+
* bucket answers `0`. `resetsAt` is ISO-8601. A lane without a computable
|
|
11
|
+
* percent is skipped rather than painted empty; `status: "rate-limited"`
|
|
12
|
+
* still paints when percent is present.
|
|
13
|
+
*
|
|
14
|
+
* Matching must not collide with OpenCode Zen (pay-as-you-go, route
|
|
15
|
+
* `opencode`, path `/zen/v1`): the catalog route is `opencode-go`, and a
|
|
16
|
+
* custom route matches only when its base URL path contains `/zen/go`.
|
|
17
|
+
*
|
|
18
|
+
* @module token-usage/quota/adapters/opencode-go
|
|
19
|
+
*/
|
|
20
|
+
import { fetchJson, numberOf } from "../http.js";
|
|
21
|
+
import { QuotaQueryError } from "../types.js";
|
|
22
|
+
/** The quota endpoint is fixed; inference hosts vary by model protocol. */
|
|
23
|
+
const QUOTA_URL = 'https://opencode.ai/zen/go/v1/usage';
|
|
24
|
+
/** The pi-ai catalog route; `opencode` is Zen pay-as-you-go, not this. */
|
|
25
|
+
const ROUTE_OPENCODE_GO = 'opencode-go';
|
|
26
|
+
/** The three lanes the endpoint reports, in panel order. */
|
|
27
|
+
const LANES = [
|
|
28
|
+
{ field: 'rolling', tier: 'five_hour' },
|
|
29
|
+
{ field: 'weekly', tier: 'weekly' },
|
|
30
|
+
{ field: 'monthly', tier: 'monthly' },
|
|
31
|
+
];
|
|
32
|
+
/** Whether a base URL is the Go subscription (path `/zen/go`), not Zen. */
|
|
33
|
+
export function isOpenCodeGoUrl(baseUrl) {
|
|
34
|
+
if (baseUrl === undefined || baseUrl === '')
|
|
35
|
+
return false;
|
|
36
|
+
try {
|
|
37
|
+
const url = new URL(baseUrl);
|
|
38
|
+
const host = url.hostname.toLowerCase();
|
|
39
|
+
if (host !== 'opencode.ai' && !host.endsWith('.opencode.ai'))
|
|
40
|
+
return false;
|
|
41
|
+
return url.pathname.toLowerCase().includes('/zen/go');
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** ISO-8601 (or epoch) → epoch ms; unparseable values drop the reset. */
|
|
48
|
+
function resetAtOf(value) {
|
|
49
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
50
|
+
const ms = Date.parse(value);
|
|
51
|
+
return Number.isFinite(ms) && ms > 0 ? ms : undefined;
|
|
52
|
+
}
|
|
53
|
+
const n = numberOf(value);
|
|
54
|
+
if (n === undefined || n <= 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
return n < 1e11 ? n * 1000 : n;
|
|
57
|
+
}
|
|
58
|
+
/** One usage lane → a used-percent window, or undefined when unpaintable. */
|
|
59
|
+
function windowOf(tier, raw) {
|
|
60
|
+
if (typeof raw !== 'object' || raw === null)
|
|
61
|
+
return undefined;
|
|
62
|
+
const lane = raw;
|
|
63
|
+
const usedPercent = numberOf(lane.percent);
|
|
64
|
+
if (usedPercent === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
const resetAt = resetAtOf(lane.resetsAt);
|
|
67
|
+
return {
|
|
68
|
+
tier,
|
|
69
|
+
usedPercent: Math.min(100, usedPercent),
|
|
70
|
+
...(resetAt !== undefined ? { resetAt } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The OpenCode Go adapter: 5-hour + weekly + monthly windows. */
|
|
74
|
+
export const opencodeGoAdapter = {
|
|
75
|
+
id: 'opencode-go',
|
|
76
|
+
label: 'OpenCode Go',
|
|
77
|
+
routes: [ROUTE_OPENCODE_GO],
|
|
78
|
+
matches(input) {
|
|
79
|
+
if (input.provider === ROUTE_OPENCODE_GO)
|
|
80
|
+
return true;
|
|
81
|
+
return isOpenCodeGoUrl(input.baseUrl);
|
|
82
|
+
},
|
|
83
|
+
async query(ctx) {
|
|
84
|
+
const body = await fetchJson(ctx, QUOTA_URL, { authorization: `Bearer ${ctx.apiKey}` });
|
|
85
|
+
if (typeof body !== 'object' || body === null) {
|
|
86
|
+
throw new QuotaQueryError('parse', 'response is not an object');
|
|
87
|
+
}
|
|
88
|
+
const usage = body.usage;
|
|
89
|
+
if (typeof usage !== 'object' || usage === null) {
|
|
90
|
+
throw new QuotaQueryError('parse', 'missing "usage" object');
|
|
91
|
+
}
|
|
92
|
+
const record = usage;
|
|
93
|
+
const windows = [];
|
|
94
|
+
for (const lane of LANES) {
|
|
95
|
+
const window = windowOf(lane.tier, record[lane.field]);
|
|
96
|
+
if (window !== undefined)
|
|
97
|
+
windows.push(window);
|
|
98
|
+
}
|
|
99
|
+
if (windows.length === 0) {
|
|
100
|
+
throw new QuotaQueryError('parse', 'no usable rolling/weekly/monthly windows in "usage"');
|
|
101
|
+
}
|
|
102
|
+
return { windows };
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=opencode-go.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-go.js","sourceRoot":"","sources":["../../../src/quota/adapters/opencode-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,2EAA2E;AAC3E,MAA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AAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACvF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,CAAA;QACjE,CAAC;QACD,MAAM,KAAK,GAAI,IAAgC,CAAC,KAAK,CAAA;QACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAA;QAC9D,CAAC;QACD,MAAM,MAAM,GAAG,KAAgC,CAAA;QAC/C,MAAM,OAAO,GAAkB,EAAE,CAAA;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;YACtD,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChD,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,qDAAqD,CAAC,CAAA;QAC3F,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,CAAA;IACpB,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRouter credits adapter: the remaining pay-as-you-go credits of an
|
|
3
|
+
* OpenRouter account.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://openrouter.ai/api/v1/credits` with a Bearer key.
|
|
6
|
+
* The response reports `{ total_credits, total_usage }` in USD; remaining
|
|
7
|
+
* is the difference. Unlike a plain balance, the total is known, so the
|
|
8
|
+
* window also carries `maxValue` and the panel draws a spend-progress bar.
|
|
9
|
+
*
|
|
10
|
+
* @module token-usage/quota/adapters/openrouter
|
|
11
|
+
*/
|
|
12
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
13
|
+
/** The OpenRouter credits adapter. */
|
|
14
|
+
export declare const openrouterAdapter: QuotaAdapter;
|
|
15
|
+
//# sourceMappingURL=openrouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/openrouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAA;AAMjE,sCAAsC;AACtC,eAAO,MAAM,iBAAiB,EAAE,YAkC/B,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRouter credits adapter: the remaining pay-as-you-go credits of an
|
|
3
|
+
* OpenRouter account.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://openrouter.ai/api/v1/credits` with a Bearer key.
|
|
6
|
+
* The response reports `{ total_credits, total_usage }` in USD; remaining
|
|
7
|
+
* is the difference. Unlike a plain balance, the total is known, so the
|
|
8
|
+
* window also carries `maxValue` and the panel draws a spend-progress bar.
|
|
9
|
+
*
|
|
10
|
+
* @module token-usage/quota/adapters/openrouter
|
|
11
|
+
*/
|
|
12
|
+
import { amountOf, fetchJson, hostOf } from "../http.js";
|
|
13
|
+
import { QuotaQueryError } from "../types.js";
|
|
14
|
+
/** The pi-ai catalog route and the account host. */
|
|
15
|
+
const ROUTE_OPENROUTER = 'openrouter';
|
|
16
|
+
const QUOTA_URL = 'https://openrouter.ai/api/v1/credits';
|
|
17
|
+
/** The OpenRouter credits adapter. */
|
|
18
|
+
export const openrouterAdapter = {
|
|
19
|
+
id: 'openrouter-credits',
|
|
20
|
+
label: 'OpenRouter Credits',
|
|
21
|
+
routes: [ROUTE_OPENROUTER],
|
|
22
|
+
matches(input) {
|
|
23
|
+
if (input.provider === ROUTE_OPENROUTER)
|
|
24
|
+
return true;
|
|
25
|
+
const host = hostOf(input.baseUrl);
|
|
26
|
+
return host !== undefined && (host === 'openrouter.ai' || host.endsWith('.openrouter.ai'));
|
|
27
|
+
},
|
|
28
|
+
async query(ctx) {
|
|
29
|
+
const body = await fetchJson(ctx, QUOTA_URL, { authorization: `Bearer ${ctx.apiKey}` });
|
|
30
|
+
if (typeof body !== 'object' || body === null) {
|
|
31
|
+
throw new QuotaQueryError('parse', 'response is not an object');
|
|
32
|
+
}
|
|
33
|
+
const record = body;
|
|
34
|
+
const data = typeof record.data === 'object' && record.data !== null
|
|
35
|
+
? record.data
|
|
36
|
+
: record;
|
|
37
|
+
// The amounts may ship as strings (the same serializer DeepSeek uses);
|
|
38
|
+
// the signed parser takes either form.
|
|
39
|
+
const total = amountOf(data.total_credits);
|
|
40
|
+
const usage = amountOf(data.total_usage);
|
|
41
|
+
if (total === undefined || usage === undefined) {
|
|
42
|
+
throw new QuotaQueryError('parse', 'missing "total_credits" / "total_usage"');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
windows: [{
|
|
46
|
+
tier: 'balance',
|
|
47
|
+
remainingValue: Math.max(0, total - usage),
|
|
48
|
+
maxValue: total,
|
|
49
|
+
unit: 'usd',
|
|
50
|
+
}],
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=openrouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../../../src/quota/adapters/openrouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,oDAAoD;AACpD,MAAM,gBAAgB,GAAG,YAAY,CAAA;AACrC,MAAM,SAAS,GAAG,sCAAsC,CAAA;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AAyC,CAAC,CAAA;QAC/E,CAAC;QACD,OAAO;YACL,OAAO,EAAE,CAAC;oBACR,IAAI,EAAE,SAAS;oBACf,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;oBAC1C,QAAQ,EAAE,KAAK;oBACf,IAAI,EAAE,KAAK;iBACZ,CAAC;SACH,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zhipu GLM Coding Plan adapter (智谱 GLM 套餐): the 5-hour + weekly
|
|
3
|
+
* windows of the personal/international coding-plan subscriptions.
|
|
4
|
+
*
|
|
5
|
+
* Endpoint: `GET https://open.bigmodel.cn/api/monitor/usage/quota/limit`
|
|
6
|
+
* (international `https://api.z.ai/...`, same shape), authorized with the
|
|
7
|
+
* coding-plan API key in the `Authorization` header WITHOUT the `Bearer`
|
|
8
|
+
* prefix — a quirk cc-switch documented; adding the prefix authenticates
|
|
9
|
+
* as anonymous and answers an error envelope.
|
|
10
|
+
*
|
|
11
|
+
* Response (`data.limits[]`): the `unit`/`number` pair gives the window
|
|
12
|
+
* LENGTH (1 days, 3 hours, 5 minutes, 6 weeks — cc-switch and token-monitor
|
|
13
|
+
* read the same table), classifying the bucket: ≤ 6 hours is the 5-hour
|
|
14
|
+
* window, roughly-two-weeks-and-under is weekly, a billing month is
|
|
15
|
+
* monthly; a bare unit 6 stays the weekly bucket whatever its number
|
|
16
|
+
* (observed as 6/1 and 6/7 in the wild). Only when no length is
|
|
17
|
+
* computable does the reset-time-ascending heuristic apply — at a period's
|
|
18
|
+
* end the weekly bucket can reset BEFORE the 5-hour one, so pure time
|
|
19
|
+
* sorting swaps the two (cc-switch issue #3036). The entry `type` names
|
|
20
|
+
* the metered resource: `CREDIT_LIMIT` on the v3 coding plans
|
|
21
|
+
* (usage/currentValue/remaining credits), `TOKENS_LIMIT` on the older
|
|
22
|
+
* ones — the window fields and classification are identical either way.
|
|
23
|
+
* The used share comes from the credit totals when they are present —
|
|
24
|
+
* `max(usage - remaining, currentValue) / usage`, the console's own
|
|
25
|
+
* arithmetic — with `percentage` as the fallback; a share NEITHER source
|
|
26
|
+
* can produce is an unpaintable window, skipped rather than fabricated
|
|
27
|
+
* as 0% used. `nextResetTime` is epoch ms; `data.level` names the plan
|
|
28
|
+
* tier. Tolerances cc-switch learned in the wild: the `type` comparison
|
|
29
|
+
* is case-insensitive (upstream has been observed casing it differently),
|
|
30
|
+
* and an HTTP-200 `success: false` + `msg` envelope is a business error,
|
|
31
|
+
* not a payload to dig into.
|
|
32
|
+
*
|
|
33
|
+
* @module token-usage/quota/adapters/zhipu
|
|
34
|
+
*/
|
|
35
|
+
import type { QuotaAdapter } from '../types.ts';
|
|
36
|
+
/** The Zhipu GLM coding-plan adapter: 5-hour + weekly windows. */
|
|
37
|
+
export declare const zhipuAdapter: QuotaAdapter;
|
|
38
|
+
//# sourceMappingURL=zhipu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zhipu.d.ts","sourceRoot":"","sources":["../../../src/quota/adapters/zhipu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAwD,MAAM,aAAa,CAAA;AA8FrG,kEAAkE;AAClE,eAAO,MAAM,YAAY,EAAE,YAqG1B,CAAA"}
|