@bacnh85/pi-sub 0.1.38 → 0.1.39

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.39 (2026-09-12)
4
+
5
+ ### Fixed
6
+
7
+ - **Guarded footer render against an uninitialized theme proxy** (pi-budget
8
+ parity): `renderSubscriptionLine` dereferenced `ctx.ui.theme.fg` unguarded —
9
+ if the theme isn't ready yet the throw escapes as a rejected promise and can
10
+ exit pi (the same unhandledRejection class 0.1.37/0.1.38 fixed elsewhere).
11
+ The footer is now best-effort: skipped when the theme isn't available.
12
+ - **Finite-cost guard on `message_end` accumulation** (pi-budget parity): a
13
+ string or NaN `cost.total` previously hit `+=` directly — a string cost
14
+ concatenated onto the accumulator and garbled every subsequent footer.
15
+ Costs are now coerced with `Number()` and only finite positive values
16
+ accumulate.
17
+ - README intro: Router (pi-router) listed among supported providers.
18
+
3
19
  ## 0.1.38 (2026-09-07)
4
20
 
5
21
  ### Fixed
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Pi extension that shows subscription usage for the currently selected supported model provider.
4
4
 
5
- Supports OpenAI Codex (`openai-codex`) with live usage windows from ChatGPT's usage endpoint, OpenCode Go (`opencode-go`) with session cost tracking, and Z.ai GLM Coding Plan — both the international (`zai`) and China (`zai-coding-cn`, `open.bigmodel.cn`) endpoints — with quota monitoring. Also tracks Command Code (`commandcode`) 5-hour/weekly windows and monthly credit balance. Displays a subscription footer status after Pi's built-in status/token usage line.
5
+ Supports OpenAI Codex (`openai-codex`) with live usage windows from ChatGPT's usage endpoint, OpenCode Go (`opencode-go`) with session cost tracking, and Z.ai GLM Coding Plan — both the international (`zai`) and China (`zai-coding-cn`, `open.bigmodel.cn`) endpoints — with quota monitoring. Also tracks Router (pi-router, `router` provider) with response-speed tracking and optional OmniRoute quota windows, and Command Code (`commandcode`) 5-hour/weekly windows and monthly credit balance. Displays a subscription footer status after Pi's built-in status/token usage line.
6
6
 
7
7
  ## Install
8
8
 
@@ -1103,6 +1103,9 @@ export function renderSubscriptionLine(state: State): void {
1103
1103
  const ctx = state.ctx;
1104
1104
  if (!ctx) return;
1105
1105
  const theme = ctx.ui.theme;
1106
+ // pi-budget parity: the theme proxy may not be initialized yet — dereferencing
1107
+ // theme.fg throws (unhandledRejection → pi exits). Best-effort footer: skip.
1108
+ if (!theme?.fg) return;
1106
1109
  if (!state.adapter) {
1107
1110
  // Unsupported provider (e.g. Ollama): still show the last response speed.
1108
1111
  ctx.ui.setStatus(STATUS_KEY, state.lastTokPerSec !== undefined ? theme.fg("dim", `${state.lastTokPerSec} tok/s`) : undefined);
@@ -1340,7 +1343,11 @@ export default function (pi: ExtensionAPI) {
1340
1343
 
1341
1344
  pi.on("message_end", async (event, _ctx) => {
1342
1345
  if (event.message.role === "assistant") {
1343
- state.cumulativeCost += (event.message.usage as any)?.cost?.total ?? 0;
1346
+ // pi-budget parity: coerce + finite guard so a string/NaN cost.total can
1347
+ // never poison the accumulator (string concat garbles every subsequent
1348
+ // footer).
1349
+ const cost = Number((event.message.usage as any)?.cost?.total);
1350
+ if (Number.isFinite(cost) && cost > 0) state.cumulativeCost += cost;
1344
1351
  if (state.responseStartTime) {
1345
1352
  // usage.output already includes reasoning tokens (Pi SDK contract) —
1346
1353
  // this is total tok/s in both thinking and normal mode.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bacnh85/pi-sub",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Pi extension showing subscription usage for supported model providers.",
5
5
  "type": "module",
6
6
  "license": "MIT",