@ravshansbox/pi-quota 0.7.0 → 0.8.0
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 +2 -2
- package/index.ts +8 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,11 +12,11 @@ Add `-l` to install it in project settings.
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Pi loads the extension from `./index.ts` and shows the remaining quota for the provider backing the active model
|
|
15
|
+
Pi loads the extension from `./index.ts` and shows the remaining quota for the provider backing the active model above the editor.
|
|
16
16
|
|
|
17
17
|
- Calls the Anthropic usage endpoint once on session start, then reads the Anthropic quota from the rate limit headers of each Anthropic response
|
|
18
18
|
- Polls the OpenAI Codex usage endpoint on session start, then at every 10-minute wall-clock mark (`HH:00`, `HH:10`, `HH:20`, `HH:30`, `HH:40`, `HH:50`)
|
|
19
|
-
- Shows a
|
|
19
|
+
- Shows a widget above the editor for the provider backing the **active model**, and only when quota data for that provider has been polled; switching models re-renders it immediately
|
|
20
20
|
- The text stays compact, e.g. `93% 1h29m · 67% 3d13h`, where the 5-hour window comes first and the 7-day window second, and each window shows its remaining percentage followed by time until reset
|
|
21
21
|
- Available resets, when present, are appended as `· 2x 5h` (count, then time until the soonest expires)
|
|
22
22
|
- Both providers are checked on session start whenever their credentials exist, so quota is already known when the active model changes
|
package/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type ExtensionAPI,
|
|
7
7
|
type ExtensionContext,
|
|
8
8
|
} from '@earendil-works/pi-coding-agent';
|
|
9
|
+
import { Text } from '@earendil-works/pi-tui';
|
|
9
10
|
|
|
10
11
|
interface QuotaConfig {
|
|
11
12
|
codexResets?: { autoRedeem?: boolean };
|
|
@@ -68,7 +69,7 @@ type CodexResetConsumeResponse = { code?: string };
|
|
|
68
69
|
|
|
69
70
|
const modelProviderNames: Record<QuotaState['provider'], string> = {
|
|
70
71
|
anthropic: 'anthropic',
|
|
71
|
-
'openai-codex': 'openai',
|
|
72
|
+
'openai-codex': 'openai-codex',
|
|
72
73
|
};
|
|
73
74
|
|
|
74
75
|
const requestTimeoutMs = 30_000;
|
|
@@ -234,7 +235,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
234
235
|
const text = buildStatusText();
|
|
235
236
|
const line = text === undefined ? undefined : ctxRef.ui.theme.fg('muted', text);
|
|
236
237
|
|
|
237
|
-
ctxRef.ui.
|
|
238
|
+
ctxRef.ui.setWidget('pi-quota', line === undefined ? undefined : () => new Text(line, 0, 0), {
|
|
239
|
+
placement: 'aboveEditor',
|
|
240
|
+
});
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
function windowResetDetected(
|
|
@@ -623,10 +626,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
623
626
|
function scheduleCheck() {
|
|
624
627
|
const next = nextMarkAfter(new Date());
|
|
625
628
|
const delay = Math.max(0, next.getTime() - Date.now());
|
|
626
|
-
|
|
629
|
+
const timer = setTimeout(async () => {
|
|
627
630
|
await runCycle(false);
|
|
628
|
-
scheduleCheck();
|
|
631
|
+
if (checkTimer === timer) scheduleCheck();
|
|
629
632
|
}, delay);
|
|
633
|
+
checkTimer = timer;
|
|
630
634
|
}
|
|
631
635
|
|
|
632
636
|
function stopTimers() {
|