Adjust for unlimited plan option

This commit is contained in:
Jakub Syty
2026-08-26 13:58:31 +02:00
parent 0c847e25bd
commit 1459b4b360
5 changed files with 143 additions and 20 deletions
@@ -13,14 +13,35 @@ const buildCopilotWindows = (payload) => {
const resetAt = toTimestamp(payload?.quota_reset_date);
const windows = {};
// Mirrors the quota semantics of microsoft/vscode-copilot-chat
// (CopilotUserQuotaInfo): each snapshot carries entitlement, remaining,
// unlimited, and percent_remaining. Unlimited plans report no usable
// entitlement; percent_remaining is a server-computed fallback.
const addWindow = (label, snapshot) => {
if (!snapshot) return;
if (snapshot.unlimited === true) {
windows[label] = toUsageWindow({
usedPercent: null,
windowSeconds: null,
resetAt,
valueLabel: 'Unlimited'
});
return;
}
const entitlement = toNumber(snapshot.entitlement);
const remaining = toNumber(snapshot.remaining);
const usedPercent = entitlement && remaining !== null
? Math.max(0, 100 - (remaining / entitlement) * 100)
let usedPercent = entitlement !== null && entitlement > 0 && remaining !== null
? Math.min(100, Math.max(0, 100 - (remaining / entitlement) * 100))
: null;
const valueLabel = entitlement !== null && remaining !== null
if (usedPercent === null) {
const percentRemaining = toNumber(snapshot.percent_remaining);
if (percentRemaining !== null) {
usedPercent = Math.min(100, Math.max(0, 100 - percentRemaining));
}
}
const valueLabel = entitlement !== null && entitlement > 0 && remaining !== null
? `${remaining.toFixed(0)} / ${entitlement.toFixed(0)} left`
: null;
windows[label] = toUsageWindow({
@@ -141,17 +162,12 @@ export const fetchQuotaAddon = async () => {
}
const payload = await response.json();
const windows = buildCopilotWindows(payload);
const premium = windows.premium_interactions
? { premium_interactions: windows.premium_interactions }
: windows;
return buildResult({
providerId: providerIdAddon,
providerName: providerNameAddon,
ok: true,
configured: true,
usage: { windows: premium }
usage: { windows: buildCopilotWindows(payload) }
});
} catch (error) {
return buildResult({