maxpool 1.24.56 → 1.24.58
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/package.json +1 -1
- package/src/account-manager.js +33 -1
- package/src/prober.js +11 -0
- package/src/tui.js +21 -2
- package/src/zai-subs.js +43 -0
package/package.json
CHANGED
package/src/account-manager.js
CHANGED
|
@@ -1385,7 +1385,20 @@ export class AccountManager {
|
|
|
1385
1385
|
const ticket = requestInfo.queueTicket;
|
|
1386
1386
|
if (!ticket) return true;
|
|
1387
1387
|
this._reapStaleQueueHead();
|
|
1388
|
-
|
|
1388
|
+
// BOUNDED HEAD-SKIP (council red-team #5, 2026-10-31): strict FIFO let an
|
|
1389
|
+
// unserveable HEAD (claude-profile with every Claude weekly-walled) block a
|
|
1390
|
+
// serveable follower (all-profile, healthy GLM) for the head's full window —
|
|
1391
|
+
// up to 25 min of "pool dead" while capacity idled. A waiter that has already
|
|
1392
|
+
// waited HEAD_SKIP_MS may be admitted even when tickets ahead of it exist.
|
|
1393
|
+
// Fairness stays: the skip only fires after a real wait, and the head's own
|
|
1394
|
+
// window (queueAndRetry's ceiling) still bounds IT.
|
|
1395
|
+
const HEAD_SKIP_MS = 60_000;
|
|
1396
|
+
if (this.queueState.waiting[0]?.id === ticket.id) {
|
|
1397
|
+
// fast path: unchanged FIFO
|
|
1398
|
+
} else {
|
|
1399
|
+
const waited = Date.now() - (ticket.queuedAt ?? Date.now());
|
|
1400
|
+
if (waited < HEAD_SKIP_MS) return false;
|
|
1401
|
+
}
|
|
1389
1402
|
const now = Date.now();
|
|
1390
1403
|
if (now < this.queueState.rampUntil && now - this.queueState.lastAdmissionAt < 250) return false;
|
|
1391
1404
|
this.queueState.waiting.shift();
|
|
@@ -3706,6 +3719,25 @@ export class AccountManager {
|
|
|
3706
3719
|
|
|
3707
3720
|
/** Store the latest reset-card listing for an account (prober piggyback).
|
|
3708
3721
|
* Read by redeem policy AND by _scoreAccount's reset-aware preference. */
|
|
3722
|
+
/** Monthly-normalized price for the Capacity page's $/1M column (display-only;
|
|
3723
|
+
* never touches routing). Claude accounts read config.scheduler.monthlyPriceUSD
|
|
3724
|
+
* (name → USD/mo; no per-account price API exists), providers get theirs from
|
|
3725
|
+
* the z.ai subscription API via the prober. */
|
|
3726
|
+
applyMonthlyPrice(accountIndex, usd) {
|
|
3727
|
+
const a = this.accounts[accountIndex];
|
|
3728
|
+
if (a) a.monthlyPriceUSD = usd;
|
|
3729
|
+
}
|
|
3730
|
+
|
|
3731
|
+
monthlyPriceFor(account) {
|
|
3732
|
+
if (account?.type === 'provider') return account.monthlyPriceUSD ?? null;
|
|
3733
|
+
const tbl = this.scheduler?.monthlyPriceUSD;
|
|
3734
|
+
if (tbl && typeof tbl === 'object') {
|
|
3735
|
+
const hit = tbl[account?.name] ?? tbl['*'];
|
|
3736
|
+
if (Number.isFinite(hit)) return hit;
|
|
3737
|
+
}
|
|
3738
|
+
return null;
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3709
3741
|
applyResetCards(accountIndex, cards) {
|
|
3710
3742
|
const account = this.accounts[accountIndex];
|
|
3711
3743
|
if (!account || !cards) return;
|
package/src/prober.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { fetchUsage, fetchProviderUsage } from './oauth.js';
|
|
11
11
|
import { listResetCards, redeemResetCard, fetchZaiModelUsage } from './zai-reset-cards.js';
|
|
12
|
+
import { listSubscriptions, monthlyPriceUSD } from './zai-subs.js';
|
|
12
13
|
import { listResetGrants, claimResetGrant } from './claude-reset-grants.js';
|
|
13
14
|
import { decideZai, decideClaude } from './reset-policy.js';
|
|
14
15
|
import { zaiHourlyCalls, compareOutsideUsage, isUsableZaiUsage, OUTSIDE_CHECK_MS } from './outside-usage.js';
|
|
@@ -205,6 +206,16 @@ export class Prober {
|
|
|
205
206
|
// A duplicate-guard-benched copy never redeems: the team pool owns that key now,
|
|
206
207
|
// and two pools redeeming one key would burn two cards for one reset.
|
|
207
208
|
if (account.enabled !== false && account.credential && !account.poolBenchedBy) {
|
|
209
|
+
// Subscription (price-per-token column): same cadence, same key, best-effort.
|
|
210
|
+
if (account.provider === 'zai' && this.am.applyMonthlyPrice) {
|
|
211
|
+
try {
|
|
212
|
+
if (!account._subsCheckedAt || Date.now() - account._subsCheckedAt > 24 * 3600_000) {
|
|
213
|
+
const subs = await this._withTimeout(listSubscriptions(account.credential));
|
|
214
|
+
account._subsCheckedAt = Date.now();
|
|
215
|
+
if (subs && !subs.error) this.am.applyMonthlyPrice(account.index, monthlyPriceUSD(subs.subscriptions));
|
|
216
|
+
}
|
|
217
|
+
} catch { /* price is display-only */ }
|
|
218
|
+
}
|
|
208
219
|
if (account.provider === 'zai' && this.am.applyResetCards) {
|
|
209
220
|
try {
|
|
210
221
|
const cards = await this._withTimeout(this.cardsFn(account.credential));
|
package/src/tui.js
CHANGED
|
@@ -2703,11 +2703,11 @@ export class TUI {
|
|
|
2703
2703
|
// Current is the live window (estimate while it runs; frozen into the columns at
|
|
2704
2704
|
// close). Prev/Avg/N are the completed-cycle history. The no-weekly account's
|
|
2705
2705
|
// weekly view approximates capacity as avg session tank × 33.6 (7×24/5h windows).
|
|
2706
|
-
const ALL_COLS = ['Current', 'Prev', 'Avg', 'N'];
|
|
2706
|
+
const ALL_COLS = ['Current', 'Prev', 'Avg', 'N', '$/1M'];
|
|
2707
2707
|
const CW = 11;
|
|
2708
2708
|
const nameW = 12;
|
|
2709
2709
|
let COLS = ALL_COLS;
|
|
2710
|
-
while (COLS.length > 1 && (nameW + PROVIDER_W + 2 + COLS.length * CW +
|
|
2710
|
+
while (COLS.length > 1 && (nameW + PROVIDER_W + 2 + COLS.length * CW + 22) > W) {
|
|
2711
2711
|
COLS = COLS.slice(0, -1);
|
|
2712
2712
|
}
|
|
2713
2713
|
const header = ' ' + 'Account'.padEnd(nameW) + ' ' + 'Provider'.padEnd(PROVIDER_W) + ' '
|
|
@@ -2730,6 +2730,11 @@ export class TUI {
|
|
|
2730
2730
|
const approx = sesTank && sesTank.n > 0
|
|
2731
2731
|
? formatTokens(Math.round(sesTank.avg * (7 * 24) / 5)) : '--';
|
|
2732
2732
|
const cellsByName = { Current: cyan(approx), Prev: '--', Avg: '--', N: sesTank?.n ? String(sesTank.n) : '--' };
|
|
2733
|
+
// Same price cell as the main path: this account's weekly capacity IS the
|
|
2734
|
+
// derived tank (avg 5h × 33.6) — the price column must not go blank here.
|
|
2735
|
+
const p2 = this.am.monthlyPriceFor?.(a);
|
|
2736
|
+
cellsByName['$/1M'] = gray((sesTank?.avg && p2)
|
|
2737
|
+
? ('$' + (p2 / (Math.round(sesTank.avg * (7 * 24) / 5) / 1e6)).toFixed(2)).padStart(CW) : '--'.padStart(CW));
|
|
2733
2738
|
out.push(' ' + name + ' ' + prov + ' '
|
|
2734
2739
|
+ COLS.map(c => cellsByName[c].padStart(CW)).join('')
|
|
2735
2740
|
+ dim(' no weekly limit · avg 5h × 33.6'));
|
|
@@ -2761,6 +2766,19 @@ export class TUI {
|
|
|
2761
2766
|
Avg: (tank?.source === 'cycles' ? formatTokens(tank.avg) : '--'),
|
|
2762
2767
|
N: (tank?.source === 'cycles' ? String(tank.n) : '--'),
|
|
2763
2768
|
};
|
|
2769
|
+
// $/1M (owner 2026-10-31 "price per token, not per subscription"): the measured
|
|
2770
|
+
// weekly tank divided by the plan's monthly-normalized price. Weekly in BOTH
|
|
2771
|
+
// views — a 5h tank refills ~33.6x per week, so the weekly figure is what a
|
|
2772
|
+
// month of subscription actually buys. '--' until a tank reading AND a price exist.
|
|
2773
|
+
const sesTankObj = this.am.capacityTank?.(i, 'ses');
|
|
2774
|
+
const wkTank = (a.quota?.weeklyAbsent && a.type === 'provider')
|
|
2775
|
+
? (sesTankObj?.avg ? Math.round(sesTankObj.avg * (7 * 24) / 5) : null)
|
|
2776
|
+
: (this.am.capacityTank?.(i, 'wk')?.avg ?? null);
|
|
2777
|
+
const price = this.am.monthlyPriceFor?.(a);
|
|
2778
|
+
const priceCell = (wkTank && price)
|
|
2779
|
+
? '$' + (price / (wkTank / 1e6)).toFixed(2)
|
|
2780
|
+
: '--';
|
|
2781
|
+
cellsByName['$/1M'] = gray(priceCell.padStart(CW));
|
|
2764
2782
|
const row = ' ' + name + ' ' + prov + ' '
|
|
2765
2783
|
+ COLS.map(c => cellsByName[c].padStart(CW)).join('');
|
|
2766
2784
|
out.push(row + (curPct ? ' ' + curPct : ''));
|
|
@@ -2769,6 +2787,7 @@ export class TUI {
|
|
|
2769
2787
|
out.push('');
|
|
2770
2788
|
out.push(' ' + dim('Capacity = tokens ÷ how full the provider said the window was, at close.'));
|
|
2771
2789
|
out.push(' ' + dim('Current @% = live window, % full now · no-weekly weekly = avg 5h × 33.6.'));
|
|
2790
|
+
out.push(' ' + dim('$/1M = plan price ÷ measured weekly tank (monthly-normalized). -- = no price or tank yet.'));
|
|
2772
2791
|
return out;
|
|
2773
2792
|
}
|
|
2774
2793
|
|
package/src/zai-subs.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** z.ai subscription list — the FACT source for a GLM plan's billing cycle and
|
|
2
|
+
* price (same API the finops forecast uses; 2026-10-31). Used for the
|
|
3
|
+
* price-per-token column on the Capacity page: tank tokens ÷ normalized monthly
|
|
4
|
+
* price. Values are cached per account; a failed read degrades the column to
|
|
5
|
+
* '--' and never touches routing. */
|
|
6
|
+
const SUBS_URL = 'https://api.z.ai/api/biz/subscription/list';
|
|
7
|
+
const CYCLE_MONTHS = { monthly: 1, quarterly: 3, annually: 12 };
|
|
8
|
+
|
|
9
|
+
export async function listSubscriptions(token, { signal, fetchImpl = fetch } = {}) {
|
|
10
|
+
try {
|
|
11
|
+
const res = await fetchImpl(SUBS_URL, {
|
|
12
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
13
|
+
signal: signal ?? AbortSignal.timeout(20_000),
|
|
14
|
+
});
|
|
15
|
+
if (!res.ok) return { error: `HTTP ${res.status}` };
|
|
16
|
+
const env = await res.json();
|
|
17
|
+
const rows = env?.data;
|
|
18
|
+
if (!Array.isArray(rows)) return { error: 'bad_payload' };
|
|
19
|
+
return { subscriptions: rows.map(s => ({
|
|
20
|
+
id: s.id,
|
|
21
|
+
product: s.productName || null,
|
|
22
|
+
billingCycle: s.billingCycle || null,
|
|
23
|
+
price: Number(s.renewPrice ?? s.actualPrice ?? 0) || null,
|
|
24
|
+
autoRenew: Number(s.autoRenew ?? 0) === 1,
|
|
25
|
+
status: s.status || null,
|
|
26
|
+
})) };
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return { error: err?.name === 'AbortError' ? 'timeout' : (err?.message || 'error') };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Monthly-normalized price in USD, or null. An annually-billed plan's per-month
|
|
33
|
+
* cost is price/12 — the token tank it buys is the same every month. */
|
|
34
|
+
export function monthlyPriceUSD(subscriptions) {
|
|
35
|
+
if (!subscriptions?.length) return null;
|
|
36
|
+
// Prefer the VALID auto-renewing plan; fall back to the first row.
|
|
37
|
+
const s = subscriptions.find(x => x.status === 'VALID' && x.autoRenew)
|
|
38
|
+
|| subscriptions.find(x => x.status === 'VALID')
|
|
39
|
+
|| subscriptions[0];
|
|
40
|
+
const months = CYCLE_MONTHS[s?.billingCycle] || 0;
|
|
41
|
+
if (!months || !s?.price) return null;
|
|
42
|
+
return s.price / months;
|
|
43
|
+
}
|