repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(quota): parse minimax percent fallback

05b0f8b5575e891fb7083717cd4d9108c9bb3d61

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

MiniMax coding plan now returns total/usage = 0 and exposes
current_interval_remaining_percent / current_weekly_remaining_percent.
Use percent as fallback when totals are absent so footer renders.

Changed files (2)

extensions/quota/__tests__/harness.test.ts

Modified
64 64 fiveH: { used: 70, total: 100, remaining: 30 },
65 65 weekly: { used: 200, total: 1000, remaining: 800 },
68 + expect(
69 + __test.parseMinimax({
70 + base_resp: { status_code: 0, status_msg: "" },
71 + model_remains: [
72 + {
73 + model_name: "general",
74 + current_interval_total_count: 0,
75 + current_interval_usage_count: 0,
76 + current_interval_remaining_percent: 25,
77 + current_weekly_total_count: 0,
78 + current_weekly_usage_count: 0,
79 + current_weekly_remaining_percent: 80,
80 + },
81 + ],
82 + }),
83 + ).toMatchObject({
84 + name: "MiniMax",
85 + fiveH: { used: 75, total: 100, remaining: 25 },
86 + weekly: { used: 20, total: 100, remaining: 80 },
87 + });

extensions/quota/index.ts

Modified
27 27 current_interval_usage_count: number;
28 28 current_weekly_total_count?: number;
29 29 current_weekly_usage_count?: number;
30 + current_interval_remaining_percent?: number;
31 + current_weekly_remaining_percent?: number;
30 32 remains_time?: number;
31 33 start_time?: number;
32 34 end_time?: number;
268 270 weekly: { used: 0, total: 0, remaining: 0 },
273 + function quota(
274 + totalValue: unknown,
275 + remainingValue: unknown,
276 + percentValue: unknown,
277 + ) {
278 + const total = Number(totalValue) || 0;
279 + const remaining = Number(remainingValue) || 0;
280 + if (total > 0) return { used: total - remaining, total, remaining };
281 + const percent = Number(percentValue);
282 + if (Number.isFinite(percent) && percent > 0)
283 + return { used: 100 - percent, total: 100, remaining: percent };
284 + return { used: 0, total: 0, remaining: 0 };
271 287 // API field is misleadingly named — usage_count is remaining count.
272 - const total = Number(bucket.current_interval_total_count) || 0;
273 - const remaining = Number(bucket.current_interval_usage_count) || 0;
274 - const weeklyTotal = Number(bucket.current_weekly_total_count) || 0;
275 - const weeklyRemaining = Number(bucket.current_weekly_usage_count) || 0;
276 288 return {
278 290 fiveH: {
279 - used: total - remaining,
280 - total,
281 - remaining,
291 + ...quota(
292 + bucket.current_interval_total_count,
293 + bucket.current_interval_usage_count,
294 + bucket.current_interval_remaining_percent,
295 + ),
282 296 resetAt:
283 297 parseDateish(bucket.end_time) ||
284 298 (bucket.remains_time ? Date.now() + bucket.remains_time : undefined),
286 300 weekly: {
287 - used: weeklyTotal - weeklyRemaining,
288 - total: weeklyTotal,
289 - remaining: weeklyRemaining,
301 + ...quota(
302 + bucket.current_weekly_total_count,
303 + bucket.current_weekly_usage_count,
304 + bucket.current_weekly_remaining_percent,
305 + ),
290 306 resetAt: parseDateish(bucket.weekly_end_time) || undefined,