pi-usage-limits 0.1.2 → 0.1.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.
- package/README.md +3 -1
- package/index.ts +18 -10
- package/package.json +1 -1
- package/usage.ts +5 -1
package/README.md
CHANGED
|
@@ -25,7 +25,9 @@ A [pi](https://github.com/earendil-works/pi) extension that shows your **Claude*
|
|
|
25
25
|
| Active model | Source | Shows |
|
|
26
26
|
|---|---|---|
|
|
27
27
|
| Model id contains `claude` | Claude Agent SDK (Claude Code login) | 5-hour and 7-day utilization |
|
|
28
|
-
| `openai-codex` provider, or model id contains `codex` | ChatGPT usage endpoint (pi's `openai-codex` login) | 5-hour and weekly usage |
|
|
28
|
+
| `openai` or `openai-codex` provider, or model id contains `codex` | ChatGPT usage endpoint (pi's `openai-codex` login) | 5-hour and weekly usage |
|
|
29
|
+
|
|
30
|
+
OpenAI models such as `(openai) gpt-6.1-sol` show the same ChatGPT subscription limits using your `openai-codex` login, not OpenAI API limits.
|
|
29
31
|
|
|
30
32
|
Other models show `<model> not supported yet`.
|
|
31
33
|
|
package/index.ts
CHANGED
|
@@ -5,17 +5,25 @@ import type {
|
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { getUsage } from "./usage";
|
|
7
7
|
|
|
8
|
-
// pi awaits handler promises, so awaiting here blocks the redraw.
|
|
9
|
-
function refresh(_event: ExtensionEvent, ctx: ExtensionContext) {
|
|
10
|
-
if (!ctx.model) return;
|
|
11
|
-
getUsage(ctx.model, ctx.modelRegistry)
|
|
12
|
-
.then((usage) =>
|
|
13
|
-
ctx.ui.setStatus("model-usage", ctx.ui.theme.fg("dim", usage)),
|
|
14
|
-
)
|
|
15
|
-
.catch((e) => ctx.ui.setStatus("model-usage", ctx.ui.theme.fg("dim", e)));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
8
|
export default function (pi: ExtensionAPI) {
|
|
9
|
+
let generation = 0;
|
|
10
|
+
|
|
11
|
+
// pi awaits handler promises, so awaiting here blocks the redraw.
|
|
12
|
+
function refresh(_event: ExtensionEvent, ctx: ExtensionContext) {
|
|
13
|
+
const current = ++generation;
|
|
14
|
+
if (ctx.mode !== "tui" || !ctx.model) return;
|
|
15
|
+
|
|
16
|
+
const setStatus = (text: string) => {
|
|
17
|
+
// Shutdown or a newer refresh invalidates this captured context.
|
|
18
|
+
if (current !== generation) return;
|
|
19
|
+
ctx.ui.setStatus("model-usage", ctx.ui.theme.fg("dim", text));
|
|
20
|
+
};
|
|
21
|
+
getUsage(ctx.model, ctx.modelRegistry).then(setStatus, setStatus);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pi.on("session_shutdown", () => {
|
|
25
|
+
generation++;
|
|
26
|
+
});
|
|
19
27
|
pi.on("session_start", refresh);
|
|
20
28
|
pi.on("model_select", refresh);
|
|
21
29
|
pi.on("agent_settled", refresh);
|
package/package.json
CHANGED
package/usage.ts
CHANGED
|
@@ -14,7 +14,11 @@ export async function getUsage(
|
|
|
14
14
|
model: { id: string; provider?: string },
|
|
15
15
|
auth: TokenSource,
|
|
16
16
|
): Promise<string> {
|
|
17
|
-
if (
|
|
17
|
+
if (
|
|
18
|
+
model.provider === "openai" ||
|
|
19
|
+
model.provider === "openai-codex" ||
|
|
20
|
+
model.id.includes("codex")
|
|
21
|
+
) {
|
|
18
22
|
return getCodexUsage(auth);
|
|
19
23
|
}
|
|
20
24
|
|