@latentminds/pi-quotas 0.2.4 → 0.3.1
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/README.md +34 -23
- package/package.json +25 -5
- package/src/config.ts +43 -13
- package/src/extensions/command-quotas/command.ts +23 -1
- package/src/extensions/command-quotas/components/quotas-display.test.ts +154 -0
- package/src/extensions/command-quotas/components/quotas-display.ts +13 -10
- package/src/extensions/command-quotas/provider-commands.test.ts +9 -0
- package/src/extensions/command-quotas/provider-commands.ts +12 -0
- package/src/extensions/command-tokens/command.ts +102 -0
- package/src/extensions/command-tokens/index.ts +1 -0
- package/src/extensions/command-tokens/tokens-display.ts +357 -0
- package/src/extensions/quota-warnings/index.ts +47 -19
- package/src/extensions/token-status/index.ts +241 -0
- package/src/extensions/token-status/provider-detection.test.ts +30 -0
- package/src/extensions/usage-status/index.test.ts +182 -0
- package/src/extensions/usage-status/index.ts +114 -44
- package/src/lib/quotas.ts +12 -1
- package/src/lib/session-tokens.test.ts +137 -0
- package/src/lib/session-tokens.ts +399 -0
- package/src/providers/fetch.test.ts +71 -0
- package/src/providers/fetch.ts +200 -17
- package/src/providers/opencode-go-config.ts +127 -0
- package/src/providers/opencode-go.ts +183 -0
- package/src/providers/parse.test.ts +185 -7
- package/src/providers/providers.ts +229 -21
- package/src/types/quotas.ts +12 -3
- package/src/utils/quotas-severity.test.ts +22 -2
- package/src/utils/quotas-severity.ts +28 -6
|
@@ -53,11 +53,27 @@ export function getProjectedPercent(
|
|
|
53
53
|
return Math.max(0, (usedPercent / effectivePace) * 100);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function absoluteUsageSeverity(
|
|
57
|
+
window: QuotaWindow,
|
|
58
|
+
percent: number,
|
|
59
|
+
): RiskSeverity {
|
|
60
|
+
if (window.limited || percent >= 100) return "critical";
|
|
61
|
+
if (percent >= 90) return "high";
|
|
62
|
+
if (percent >= 80) return "warning";
|
|
63
|
+
return "none";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function maxSeverity(a: RiskSeverity, b: RiskSeverity): RiskSeverity {
|
|
67
|
+
const order: RiskSeverity[] = ["none", "warning", "high", "critical"];
|
|
68
|
+
return order[Math.max(order.indexOf(a), order.indexOf(b))] ?? "none";
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
export function assessWindow(window: QuotaWindow): RiskAssessment {
|
|
57
72
|
const rawPace = window.showPace ? getPacePercent(window) : null;
|
|
58
73
|
const pacePercent =
|
|
59
74
|
rawPace !== null ? rawPace * (window.paceScale ?? 1) : null;
|
|
60
75
|
const projectedPercent = getProjectedPercent(window.usedPercent, pacePercent);
|
|
76
|
+
const absoluteSeverity = absoluteUsageSeverity(window, window.usedPercent);
|
|
61
77
|
|
|
62
78
|
let progress: number | null = null;
|
|
63
79
|
if (pacePercent !== null) progress = pacePercent / 100;
|
|
@@ -70,10 +86,7 @@ export function assessWindow(window: QuotaWindow): RiskAssessment {
|
|
|
70
86
|
};
|
|
71
87
|
|
|
72
88
|
if (progress === null) {
|
|
73
|
-
|
|
74
|
-
if (window.limited || projectedPercent >= 100) severity = "critical";
|
|
75
|
-
else if (projectedPercent >= 90) severity = "high";
|
|
76
|
-
else if (projectedPercent >= 80) severity = "warning";
|
|
89
|
+
const severity = absoluteUsageSeverity(window, projectedPercent);
|
|
77
90
|
|
|
78
91
|
return {
|
|
79
92
|
...base,
|
|
@@ -121,7 +134,7 @@ export function assessWindow(window: QuotaWindow): RiskAssessment {
|
|
|
121
134
|
warnProjectedPercent,
|
|
122
135
|
highProjectedPercent,
|
|
123
136
|
criticalProjectedPercent,
|
|
124
|
-
severity,
|
|
137
|
+
severity: maxSeverity(severity, absoluteSeverity),
|
|
125
138
|
};
|
|
126
139
|
}
|
|
127
140
|
|
|
@@ -129,8 +142,17 @@ export function formatTimeRemaining(date: Date): string {
|
|
|
129
142
|
const ms = date.getTime() - Date.now();
|
|
130
143
|
if (ms <= 0) return "now";
|
|
131
144
|
const totalMins = Math.ceil(ms / (1000 * 60));
|
|
132
|
-
const
|
|
145
|
+
const totalHours = Math.floor(totalMins / 60);
|
|
146
|
+
const days = Math.floor(totalHours / 24);
|
|
147
|
+
const hours = totalHours % 24;
|
|
133
148
|
const mins = totalMins % 60;
|
|
149
|
+
|
|
150
|
+
if (days >= 1) {
|
|
151
|
+
const parts: string[] = [`${days}d`];
|
|
152
|
+
if (hours > 0) parts.push(`${hours}h`);
|
|
153
|
+
if (mins > 0) parts.push(`${mins}m`);
|
|
154
|
+
return parts.join("");
|
|
155
|
+
}
|
|
134
156
|
if (hours >= 1) return mins > 0 ? `${hours}h${mins}m` : `${hours}h`;
|
|
135
157
|
const totalSecs = Math.ceil(ms / 1000);
|
|
136
158
|
return totalMins >= 1 ? `${totalMins}m` : `${totalSecs}s`;
|