pi-minimal-footer 0.3.1 → 0.3.2
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/CHANGELOG.md +8 -1
- package/README.md +5 -9
- package/VISION.md +13 -13
- package/extensions/index.ts +12 -12
- package/extensions/lib/usage-limits.ts +12 -12
- package/extensions/lib/{quota-providers.ts → usage-providers.ts} +8 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.2] - 2026-10-06
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Rename provider quota terminology to subscription usage in documentation, code, and tests; behavior is unchanged
|
|
15
|
+
|
|
10
16
|
## [0.3.1] - 2026-10-06
|
|
11
17
|
|
|
12
18
|
### Fixed
|
|
@@ -141,7 +147,8 @@ First npm-ready release.
|
|
|
141
147
|
|
|
142
148
|
- Project scaffold — `extensions/index.ts` with basic footer structure, `package.json` with pi extension manifest, `README.md`, `LICENSE` (MIT)
|
|
143
149
|
|
|
144
|
-
[Unreleased]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.3.
|
|
150
|
+
[Unreleased]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.3.2...HEAD
|
|
151
|
+
[0.3.2]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.3.1...v0.3.2
|
|
145
152
|
[0.3.1]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.3.0...v0.3.1
|
|
146
153
|
[0.3.0]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.2.0...v0.3.0
|
|
147
154
|
[0.2.0]: https://github.com/Ryu-CZ/pi-minimal-footer/compare/v0.1.3...v0.2.0
|
package/README.md
CHANGED
|
@@ -9,11 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
An opinionated, compact one-line footer for [Pi](https://github.com/earendil-works/pi).
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
~/git/project main 🧠 Karpathy 🪽 Icarus model · 42/200k · ⣿⣿⣿⣤⠀⠀⠀⠀⠀⠀↻1d8h
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Path and branch on the left; extension statuses, model, context, and provider quota on the right. Shrinks to fit narrow terminals. Interactive terminal UI only.
|
|
12
|
+
Path and branch on the left; extension statuses, model, context, and subscription usage bar on the right. Shrinks to fit narrow terminals. Interactive terminal UI only.
|
|
17
13
|
|
|
18
14
|

|
|
19
15
|
|
|
@@ -57,15 +53,15 @@ Edit `minFooter` in Pi's agent `settings.json` (normally `~/.pi/agent/settings.j
|
|
|
57
53
|
- Set `powerlineSeparator` to `false` for plain spaces instead of `` / `` if your font lacks those glyphs. The git icon `` also needs a compatible font; hide it with `showGitBranch: false` if needed.
|
|
58
54
|
- Context `42/200k` means tokens used / context window. `?` means Pi has not reported usage yet, including immediately after compaction.
|
|
59
55
|
|
|
60
|
-
## Reading
|
|
56
|
+
## Reading subscription usage
|
|
61
57
|
|
|
62
|
-
`⣿⣿⣿⣤⠀⠀⠀⠀⠀⠀↻1d8h` shows **
|
|
58
|
+
`⣿⣿⣿⣤⠀⠀⠀⠀⠀⠀↻1d8h` shows **subscription allowance used**, not context usage.
|
|
63
59
|
|
|
64
60
|
- Bar: 5–10 cells, expanding into spare space; green below 85%, amber from 85%, red from 92%. Dim means cached after a refresh failure. Very narrow terminals may show fewer cells or only the reset label.
|
|
65
61
|
- Reset: local `↻HH:mm` through 24 hours; whole days/hours above 24 hours (`↻1d8h`); whole days above 10 days (`↻12d`). Remaining durations round down. No reset reported means bar only.
|
|
66
|
-
- Shows the shortest available
|
|
62
|
+
- Shows the shortest available usage window for the selected provider. Missing credentials, unsupported/local models, or absent limits hide the usage bar. Custom proxy endpoints are not polled.
|
|
67
63
|
|
|
68
|
-
Supported adapters: **OpenAI Codex, Claude OAuth, GitHub Copilot, Gemini CLI, MiniMax, Kimi Coding, and OpenCode Go**. Uses Pi's existing credentials; ordinary Claude API keys do not expose subscription
|
|
64
|
+
Supported adapters: **OpenAI Codex, Claude OAuth, GitHub Copilot, Gemini CLI, MiniMax, Kimi Coding, and OpenCode Go**. Uses Pi's existing credentials; ordinary Claude API keys do not expose subscription usage. Provider availability varies; authenticated endpoints remain unverified live.
|
|
69
65
|
|
|
70
66
|
## Development & design
|
|
71
67
|
|
package/VISION.md
CHANGED
|
@@ -10,15 +10,15 @@ The [README](README.md) is the user manual. This document records current design
|
|
|
10
10
|
|
|
11
11
|
- Directory and git branch form the left group, separated by ``.
|
|
12
12
|
- Each extension status is its own `` tab. Preserve the supplied text; do not invent status labels, parentheses, or pipes.
|
|
13
|
-
- Model, context, and
|
|
13
|
+
- Model, context, and subscription usage form the rightmost group, separated by ` · `. Model identifies the running engine; context describes its usage; the usage bar stays anchored at the right edge.
|
|
14
14
|
- Powerline separators are dim. `powerlineSeparator: false` replaces them with a single space. Font availability cannot be detected reliably.
|
|
15
15
|
- Measure terminal columns with `visibleWidth`, not string length. Preserve ANSI styling and wide-character accounting when truncating.
|
|
16
16
|
|
|
17
17
|
### Space allocation
|
|
18
18
|
|
|
19
|
-
Reserve
|
|
19
|
+
Reserve the usage bar and model/context before allocating location and statuses. Statuses and location may shorten or disappear; on sufficiently narrow terminals, model/context can also shorten or disappear.
|
|
20
20
|
|
|
21
|
-
Lay out other fields with a five-cell
|
|
21
|
+
Lay out other fields with a five-cell usage bar first. Grow the bar only into leftover columns, up to ten cells—never truncate another field solely to enlarge it. At extreme widths, shrink below five cells, show only the reset label, or hide the usage bar if the label cannot fit.
|
|
22
22
|
|
|
23
23
|
Five cells give 2.5% steps; ten give 1.25%. Fill rounds to the nearest eighth-cell step. Only the final partially filled cell uses an intermediate shade:
|
|
24
24
|
|
|
@@ -36,14 +36,14 @@ Five cells give 2.5% steps; ten give 1.25%. Fill rounds to the nearest eighth-ce
|
|
|
36
36
|
|
|
37
37
|
The bar and reset label have no intervening space. Reset formatting uses local clock time through 24 hours, remaining whole days/hours above 24 hours, and whole days above 10 days. Exactly 24 hours stays clock time; exactly 10 days is `↻10d0h`. Missing reset metadata leaves the bar visible without a label.
|
|
38
38
|
|
|
39
|
-
##
|
|
39
|
+
## Subscription usage contract
|
|
40
40
|
|
|
41
|
-
Display only the selected provider's shortest applicable window.
|
|
41
|
+
Display only the selected provider's shortest applicable window. Subscription usage and model context usage are separate measurements.
|
|
42
42
|
|
|
43
43
|
| Provider | Selection / caveat |
|
|
44
44
|
|---|---|
|
|
45
45
|
| OpenAI Codex (`openai-codex`) | Shortest primary/secondary window; supports absolute reset timestamps and relative reset delays |
|
|
46
|
-
| Claude (`anthropic`, OAuth) | Five-hour window, or weekly fallback; ordinary API keys do not expose subscription
|
|
46
|
+
| Claude (`anthropic`, OAuth) | Five-hour window, or weekly fallback; ordinary API keys do not expose subscription usage |
|
|
47
47
|
| GitHub Copilot (`github-copilot`) | Most-used limited quota bucket; unlimited buckets hidden |
|
|
48
48
|
| Gemini CLI (`google-gemini-cli`) | Selected model, with Pro/Flash family fallback; needs a configured provider/model |
|
|
49
49
|
| MiniMax (`minimax`, `minimax-cn`) | Prefer general bucket, then active bucket, then first bucket; shortest interval/weekly window |
|
|
@@ -58,9 +58,9 @@ Reuse Pi's selected-provider credentials. Copilot uses the GitHub login token fr
|
|
|
58
58
|
- Otherwise fetch on startup/provider switch, then every four minutes without a fresh response update; also refresh at the reported reset time.
|
|
59
59
|
- Merge partial windows. A weekly-only signal must not replace a cached shorter window or postpone its refresh.
|
|
60
60
|
- Bound authentication, fetch, and response-body parsing by a shared five-second timeout. Release stalled work so polling can recover.
|
|
61
|
-
- Provider switches clear
|
|
62
|
-
- Missing credentials and explicit empty/unlimited responses clear
|
|
63
|
-
- Invalid optional reset metadata must not discard otherwise valid usage. Zero usage is an empty bar, not an absent
|
|
61
|
+
- Provider switches clear usage immediately, cancel pending work, and invalidate late results. Gemini model switches also refresh model-specific usage.
|
|
62
|
+
- Missing credentials and explicit empty/unlimited responses clear usage. Temporary authentication, network, or parsing failures retain only the current provider's cached usage, dimmed; without cache, hide it.
|
|
63
|
+
- Invalid optional reset metadata must not discard otherwise valid usage. Zero usage is an empty bar, not an absent usage bar.
|
|
64
64
|
- Stop requests and timers on disable, disposal, and session shutdown.
|
|
65
65
|
|
|
66
66
|
### Verification limits
|
|
@@ -93,14 +93,14 @@ For a manual install, copy `extensions/*` into `~/.pi/agent/extensions/`.
|
|
|
93
93
|
### Code map
|
|
94
94
|
|
|
95
95
|
- `extensions/index.ts`: settings, state refresh, layout, footer lifecycle, and `/minfooter`.
|
|
96
|
-
- `extensions/lib/usage-limits.ts`:
|
|
97
|
-
- `extensions/lib/
|
|
98
|
-
- `tests/`: loader-based lifecycle/layout regression tests and
|
|
96
|
+
- `extensions/lib/usage-limits.ts`: usage refresh, cache, cancellation, and bar/reset rendering.
|
|
97
|
+
- `extensions/lib/usage-providers.ts`: authentication, endpoint selection, and response normalization.
|
|
98
|
+
- `tests/`: loader-based lifecycle/layout regression tests and usage parsing tests.
|
|
99
99
|
|
|
100
100
|
Settings live under `minFooter` in Pi's configured agent directory. Read them at session start or explicit toggle; ordinary refreshes use cached settings. Preserve unrelated settings on writes. Only install the footer in interactive terminal mode.
|
|
101
101
|
|
|
102
102
|
### Checking changes
|
|
103
103
|
|
|
104
|
-
For behavior changes, run `npm run check` and `npm test`. Layout tests should cover narrow widths, ANSI text, wide Unicode, field priority, and both separator modes.
|
|
104
|
+
For behavior changes, run `npm run check` and `npm test`. Layout tests should cover narrow widths, ANSI text, wide Unicode, field priority, and both separator modes. Subscription usage changes should cover provider switches, timeouts, stale cache, partial updates, and malformed/missing metadata as applicable. Preview in a real terminal for font-dependent appearance; automated width checks cannot prove glyph availability.
|
|
105
105
|
|
|
106
106
|
Keep release notes in [CHANGELOG.md](CHANGELOG.md), and keep the README focused on installation and daily use. Preserve [upstream MIT attribution](extensions/lib/LICENSE) when changing adapted provider code.
|
package/extensions/index.ts
CHANGED
|
@@ -129,11 +129,11 @@ function updateState(ctx: ExtensionContext, state: FooterState): void {
|
|
|
129
129
|
|
|
130
130
|
// ── Layout ────────────────────────────────────────────────────────────
|
|
131
131
|
//
|
|
132
|
-
// Keep
|
|
132
|
+
// Keep the usage bar and reset time together; shorten location/statuses before model/context.
|
|
133
133
|
// All segment measurements use visible widths, including ANSI and wide characters.
|
|
134
134
|
|
|
135
135
|
const MODEL_GAP = " · ";
|
|
136
|
-
const
|
|
136
|
+
const USAGE_GAP = " · ";
|
|
137
137
|
const LOCATION_GAP_WIDTH = 3;
|
|
138
138
|
const MIN_TEXT_WIDTH = 4;
|
|
139
139
|
const MIN_STATUS_WIDTH = 12;
|
|
@@ -146,10 +146,10 @@ function buildLine(
|
|
|
146
146
|
if (width <= 0) return "";
|
|
147
147
|
let core = [model, context].filter(Boolean).join(MODEL_GAP);
|
|
148
148
|
// Budget the compact bar first; its expanded size must not drive truncation decisions.
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const coreBudget = Math.max(0, width - visibleWidth(
|
|
152
|
-
if (
|
|
149
|
+
const usageBar = usage(width) ?? "";
|
|
150
|
+
const usageGapWidth = usageBar && core ? USAGE_GAP.length : 0;
|
|
151
|
+
const coreBudget = Math.max(0, width - visibleWidth(usageBar) - usageGapWidth);
|
|
152
|
+
if (usageBar && coreBudget < MIN_TEXT_WIDTH) {
|
|
153
153
|
core = "";
|
|
154
154
|
} else if (visibleWidth(core) > coreBudget) {
|
|
155
155
|
const modelGapWidth = model && context ? MODEL_GAP.length : 0;
|
|
@@ -160,7 +160,7 @@ function buildLine(
|
|
|
160
160
|
core = truncateToWidth(context || model, coreBudget, "...");
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
const protectedRight = [core,
|
|
163
|
+
const protectedRight = [core, usageBar].filter(Boolean).join(USAGE_GAP);
|
|
164
164
|
const branchReservation = branch ? visibleWidth(branch) + LOCATION_GAP_WIDTH : 0;
|
|
165
165
|
const statusBudget = width - visibleWidth(protectedRight) - branchReservation - visibleWidth(statusSeparator);
|
|
166
166
|
let fittedStatuses = "";
|
|
@@ -178,12 +178,12 @@ function buildLine(
|
|
|
178
178
|
const pathBudget = leftBudget - visibleWidth(fittedBranch) - pathGapWidth;
|
|
179
179
|
const fittedPath = pathBudget >= MIN_TEXT_WIDTH ? truncateToWidth(path, pathBudget, "...") : "";
|
|
180
180
|
const left = [fittedPath, fittedBranch].filter(Boolean).join(locationSeparator);
|
|
181
|
-
if (
|
|
182
|
-
// A dropped left group needs no divider; those columns belong to the
|
|
181
|
+
if (usageBar) {
|
|
182
|
+
// A dropped left group needs no divider; those columns belong to the usage bar instead.
|
|
183
183
|
const interGroupGapWidth = left && right ? LOCATION_GAP_WIDTH : 0;
|
|
184
184
|
const spareWidth = Math.max(0, width - visibleWidth(left) - visibleWidth(right) - interGroupGapWidth);
|
|
185
|
-
const
|
|
186
|
-
const expandedCore = [core,
|
|
185
|
+
const expandedUsageBar = usage(visibleWidth(usageBar) + spareWidth, MAX_BAR_CELLS) ?? usageBar;
|
|
186
|
+
const expandedCore = [core, expandedUsageBar].filter(Boolean).join(USAGE_GAP);
|
|
187
187
|
right = [fittedStatuses, expandedCore].filter(Boolean).join(statusSeparator);
|
|
188
188
|
}
|
|
189
189
|
return left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(right))) + right;
|
|
@@ -225,7 +225,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
225
225
|
if (disposed) return;
|
|
226
226
|
disposed = true;
|
|
227
227
|
unsub();
|
|
228
|
-
// A superseded renderer must not stop its replacement's
|
|
228
|
+
// A superseded renderer must not stop its replacement's usage polling.
|
|
229
229
|
if (requestRender === request) {
|
|
230
230
|
requestRender = null;
|
|
231
231
|
usageLimits.stop();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright (c) 2025 Can Celik. MIT license: ./LICENSE.
|
|
3
3
|
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
|
|
5
|
-
import { parseUsageWindows, record, shortest, supportedOrigin, usageRequest, windowFrom } from "./
|
|
6
|
-
import type {
|
|
5
|
+
import { parseUsageWindows, record, shortest, supportedOrigin, usageRequest, windowFrom } from "./usage-providers.js";
|
|
6
|
+
import type { UsageWindow } from "./usage-providers.js";
|
|
7
7
|
|
|
8
8
|
const REFRESH_MS = 4 * 60_000;
|
|
9
9
|
const REQUEST_TIMEOUT_MS = 5000;
|
|
@@ -55,15 +55,15 @@ function passiveNumber(value: unknown): number {
|
|
|
55
55
|
return NaN;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function passiveWindow(used: unknown, seconds: number | undefined, reset: unknown, cached:
|
|
58
|
+
function passiveWindow(used: unknown, seconds: number | undefined, reset: unknown, cached: UsageWindow | undefined): UsageWindow | null {
|
|
59
59
|
const window = windowFrom(used, seconds === undefined ? cached?.seconds : seconds, reset);
|
|
60
60
|
// Omitted metadata belongs to the same window only while its duration agrees.
|
|
61
61
|
if (window && reset === undefined && window.seconds === cached?.seconds) window.resetAt = cached.resetAt;
|
|
62
62
|
return window;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function fromHeaders(provider: string, headers: Record<string, string>, cached: Record<string,
|
|
66
|
-
const windows: Record<string,
|
|
65
|
+
function fromHeaders(provider: string, headers: Record<string, string>, cached: Record<string, UsageWindow>): Record<string, UsageWindow> {
|
|
66
|
+
const windows: Record<string, UsageWindow> = {};
|
|
67
67
|
let definitions: readonly (readonly [string, string, number?])[];
|
|
68
68
|
if (provider === "openai-codex") {
|
|
69
69
|
definitions = [["primary", "primary"], ["secondary", "secondary"]];
|
|
@@ -88,14 +88,14 @@ function fromHeaders(provider: string, headers: Record<string, string>, cached:
|
|
|
88
88
|
return windows;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
function fromStream(data: unknown, cached: Record<string,
|
|
91
|
+
function fromStream(data: unknown, cached: Record<string, UsageWindow>): Record<string, UsageWindow> {
|
|
92
92
|
const event = record(data);
|
|
93
93
|
if (event.type !== "codex.rate_limits") return {};
|
|
94
94
|
// Other metered pools may be specific to a different model.
|
|
95
95
|
const pool = event.metered_limit_name ?? event.limit_name;
|
|
96
96
|
if (pool !== undefined && pool !== "codex") return {};
|
|
97
97
|
const limits = record(event.rate_limits);
|
|
98
|
-
const windows: Record<string,
|
|
98
|
+
const windows: Record<string, UsageWindow> = {};
|
|
99
99
|
for (const key of ["primary", "secondary"]) {
|
|
100
100
|
const w = record(limits[key]);
|
|
101
101
|
const window = passiveWindow(passiveNumber(w.used_percent),
|
|
@@ -106,12 +106,12 @@ function fromStream(data: unknown, cached: Record<string, QuotaWindow>): Record<
|
|
|
106
106
|
return windows;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/** Owns
|
|
109
|
+
/** Owns usage requests and timers for the currently displayed footer. */
|
|
110
110
|
export class UsageLimits {
|
|
111
111
|
private provider: string | null = null;
|
|
112
112
|
private selection: string | null = null;
|
|
113
113
|
private ctx: ExtensionContext | null = null;
|
|
114
|
-
private windows: Record<string,
|
|
114
|
+
private windows: Record<string, UsageWindow> = {};
|
|
115
115
|
private updatedAt: Record<string, number> = {};
|
|
116
116
|
private stale = false;
|
|
117
117
|
private attemptedAt = 0;
|
|
@@ -164,12 +164,12 @@ export class UsageLimits {
|
|
|
164
164
|
this.request = null;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
private selectedWindow(): [string,
|
|
167
|
+
private selectedWindow(): [string, UsageWindow] | null {
|
|
168
168
|
const window = shortest(Object.values(this.windows));
|
|
169
169
|
return window ? Object.entries(this.windows).find(([, value]) => value === window)! : null;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
private accept(windows: Record<string,
|
|
172
|
+
private accept(windows: Record<string, UsageWindow>): void {
|
|
173
173
|
if (!this.ctx || !Object.keys(windows).length) return;
|
|
174
174
|
Object.assign(this.windows, windows);
|
|
175
175
|
for (const key of Object.keys(windows)) this.updatedAt[key] = Date.now();
|
|
@@ -202,7 +202,7 @@ export class UsageLimits {
|
|
|
202
202
|
const provider = this.provider!;
|
|
203
203
|
const modelId = model.id;
|
|
204
204
|
const controller = new AbortController();
|
|
205
|
-
// Identity checks below keep late responses from restoring a replaced provider's
|
|
205
|
+
// Identity checks below keep late responses from restoring a replaced provider's usage.
|
|
206
206
|
this.request = controller;
|
|
207
207
|
this.attemptedAt = Date.now();
|
|
208
208
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
@@ -6,7 +6,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
|
|
9
|
-
export interface
|
|
9
|
+
export interface UsageWindow {
|
|
10
10
|
used: number;
|
|
11
11
|
seconds: number | null;
|
|
12
12
|
resetAt: number | null;
|
|
@@ -31,15 +31,15 @@ function resetSeconds(value: unknown): number | undefined {
|
|
|
31
31
|
return seconds !== undefined && seconds > 0 && Number.isFinite(new Date(seconds * 1000).getTime()) ? seconds : undefined;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function windowFrom(used: unknown, seconds: unknown, reset: unknown):
|
|
34
|
+
export function windowFrom(used: unknown, seconds: unknown, reset: unknown): UsageWindow | null {
|
|
35
35
|
if (typeof used !== "number" || !Number.isFinite(used) || used < 0 || used > 100) return null;
|
|
36
36
|
if (seconds != null && (typeof seconds !== "number" || !Number.isFinite(seconds) || seconds <= 0)) return null;
|
|
37
37
|
const validReset = typeof reset === "number" && reset > 0 && Number.isFinite(new Date(reset * 1000).getTime());
|
|
38
38
|
return { used, seconds: typeof seconds === "number" ? seconds : null, resetAt: validReset ? reset * 1000 : null };
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function shortest(windows: (
|
|
42
|
-
return windows.filter((w): w is
|
|
41
|
+
export function shortest(windows: (UsageWindow | null)[]): UsageWindow | null {
|
|
42
|
+
return windows.filter((w): w is UsageWindow => w !== null)
|
|
43
43
|
.sort((a, b) => (a.seconds ?? Infinity) - (b.seconds ?? Infinity) || b.used - a.used)[0] ?? null;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -122,13 +122,13 @@ function relativeReset(value: unknown): number | undefined {
|
|
|
122
122
|
return delay !== undefined && delay >= 0 ? resetSeconds(Date.now() / 1000 + delay) : undefined;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export function parseUsageWindows(provider: string, model: string, payload: unknown): Record<string,
|
|
125
|
+
export function parseUsageWindows(provider: string, model: string, payload: unknown): Record<string, UsageWindow> | null {
|
|
126
126
|
if (!ENDPOINTS[provider]) return null;
|
|
127
|
-
const windows: Record<string,
|
|
127
|
+
const windows: Record<string, UsageWindow> = {};
|
|
128
128
|
let recognized = false;
|
|
129
129
|
let malformed = !isObject(payload);
|
|
130
130
|
const data = record(payload);
|
|
131
|
-
const add = (key: string, value: unknown, parse: (w: Record<string, unknown>) =>
|
|
131
|
+
const add = (key: string, value: unknown, parse: (w: Record<string, unknown>) => UsageWindow | null) => {
|
|
132
132
|
if (value === undefined) return;
|
|
133
133
|
recognized = true;
|
|
134
134
|
if (value === null) return;
|
|
@@ -259,6 +259,6 @@ export function parseUsageWindows(provider: string, model: string, payload: unkn
|
|
|
259
259
|
return finish();
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
export function parseUsage(provider: string, model: string, payload: unknown):
|
|
262
|
+
export function parseUsage(provider: string, model: string, payload: unknown): UsageWindow | null {
|
|
263
263
|
return shortest(Object.values(parseUsageWindows(provider, model, payload) ?? {}));
|
|
264
264
|
}
|
package/package.json
CHANGED