opencode-copilot-account-switcher 0.12.3 → 0.12.4
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.
|
@@ -44,6 +44,12 @@ function ratio(remaining, entitlement) {
|
|
|
44
44
|
function value(value) {
|
|
45
45
|
return value === undefined ? "n/a" : String(value);
|
|
46
46
|
}
|
|
47
|
+
function renderWindow(label, window) {
|
|
48
|
+
if (window.entitlement === 100 && window.remaining !== undefined) {
|
|
49
|
+
return `${label}: ${window.remaining}% left`;
|
|
50
|
+
}
|
|
51
|
+
return `${label}: ${ratio(window.remaining, window.entitlement)}`;
|
|
52
|
+
}
|
|
47
53
|
function renderStatus(status) {
|
|
48
54
|
return [
|
|
49
55
|
"Codex status updated.",
|
|
@@ -52,8 +58,8 @@ function renderStatus(status) {
|
|
|
52
58
|
`email: ${value(status.identity.email)}`,
|
|
53
59
|
`plan: ${value(status.identity.plan)}`,
|
|
54
60
|
"[usage]",
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
renderWindow("5h", status.windows.primary),
|
|
62
|
+
renderWindow("week", status.windows.secondary),
|
|
57
63
|
`credits: ${ratio(status.credits.remaining, status.credits.total)}`,
|
|
58
64
|
].join("\n");
|
|
59
65
|
}
|
|
@@ -64,8 +70,8 @@ function renderCachedStatus(store) {
|
|
|
64
70
|
`email: ${value(store.account?.email ?? store.activeEmail)}`,
|
|
65
71
|
`plan: ${value(store.account?.plan)}`,
|
|
66
72
|
"[usage]",
|
|
67
|
-
|
|
68
|
-
"
|
|
73
|
+
renderWindow("5h", store.status?.premium ?? {}),
|
|
74
|
+
"week: n/a",
|
|
69
75
|
"credits: n/a",
|
|
70
76
|
].join("\n");
|
|
71
77
|
}
|
|
@@ -10,6 +10,12 @@ function readString(input) {
|
|
|
10
10
|
function readNumber(input) {
|
|
11
11
|
return typeof input === "number" && Number.isFinite(input) ? input : undefined;
|
|
12
12
|
}
|
|
13
|
+
function readTimestamp(input) {
|
|
14
|
+
const value = readNumber(input);
|
|
15
|
+
if (value === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
return value >= 1e12 ? value : value * 1000;
|
|
18
|
+
}
|
|
13
19
|
function pickRecord(source, keys) {
|
|
14
20
|
for (const key of keys) {
|
|
15
21
|
const value = asRecord(source[key]);
|
|
@@ -19,10 +25,13 @@ function pickRecord(source, keys) {
|
|
|
19
25
|
return undefined;
|
|
20
26
|
}
|
|
21
27
|
function pickWindow(source, key) {
|
|
28
|
+
const rateLimit = pickRecord(source, ["rate_limit", "rateLimit"]);
|
|
29
|
+
const rateLimitKey = key === "primary" ? "primary_window" : "secondary_window";
|
|
30
|
+
const rateLimitWindow = rateLimit ? asRecord(rateLimit[rateLimitKey]) : undefined;
|
|
22
31
|
const windows = pickRecord(source, ["windows", "usage_windows", "quota_windows"]);
|
|
23
32
|
const block = windows ? asRecord(windows[key]) : undefined;
|
|
24
33
|
const fallback = asRecord(source[key]);
|
|
25
|
-
const raw = block ?? fallback;
|
|
34
|
+
const raw = rateLimitWindow ?? block ?? fallback;
|
|
26
35
|
if (!raw) {
|
|
27
36
|
return {
|
|
28
37
|
entitlement: undefined,
|
|
@@ -31,11 +40,17 @@ function pickWindow(source, key) {
|
|
|
31
40
|
resetAt: undefined,
|
|
32
41
|
};
|
|
33
42
|
}
|
|
43
|
+
const entitlement = readNumber(raw.entitlement);
|
|
44
|
+
const remainingPercent = readNumber(raw.remaining_percent);
|
|
45
|
+
const usedPercent = readNumber(raw.used_percent);
|
|
46
|
+
const remaining = readNumber(raw.remaining) ?? remainingPercent;
|
|
47
|
+
const used = readNumber(raw.used) ?? usedPercent;
|
|
48
|
+
const percentBased = remainingPercent !== undefined || usedPercent !== undefined;
|
|
34
49
|
return {
|
|
35
|
-
entitlement:
|
|
36
|
-
remaining:
|
|
37
|
-
used
|
|
38
|
-
resetAt:
|
|
50
|
+
entitlement: entitlement ?? (percentBased ? 100 : undefined),
|
|
51
|
+
remaining: remaining ?? (used !== undefined ? Math.max(0, 100 - used) : undefined),
|
|
52
|
+
used,
|
|
53
|
+
resetAt: readTimestamp(raw.resetAt ?? raw.reset_at),
|
|
39
54
|
};
|
|
40
55
|
}
|
|
41
56
|
function normalizeUsageStatus(payload, now) {
|
|
@@ -46,7 +61,7 @@ function normalizeUsageStatus(payload, now) {
|
|
|
46
61
|
identity: {
|
|
47
62
|
accountId: readString(account.id) ?? readString(source.account_id) ?? readString(source.accountId),
|
|
48
63
|
email: readString(account.email) ?? readString(source.email),
|
|
49
|
-
plan: readString(account.plan) ?? readString(source.plan),
|
|
64
|
+
plan: readString(account.plan) ?? readString(source.plan) ?? readString(source.plan_type),
|
|
50
65
|
},
|
|
51
66
|
windows: {
|
|
52
67
|
primary: pickWindow(source, "primary"),
|