@bacnh85/pi-sub 0.1.13 → 0.1.14

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.
@@ -1,6 +1,5 @@
1
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
1
+ import { readStoredCredential, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { createHash } from "node:crypto";
3
- import fs from "node:fs/promises";
4
3
  import os from "node:os";
5
4
  import path from "node:path";
6
5
 
@@ -28,8 +27,6 @@ type UsageApiSnapshot = {
28
27
  plan_type?: string;
29
28
  };
30
29
 
31
- type PiAuthFile = Record<string, PiAuthEntry | undefined>;
32
-
33
30
  type PiAuthEntry = {
34
31
  type?: string;
35
32
  access?: string;
@@ -109,10 +106,6 @@ function piAuthPath(): string {
109
106
  return path.join(configDir, "auth.json");
110
107
  }
111
108
 
112
- async function readJsonFile<T>(file: string): Promise<T> {
113
- return JSON.parse(await fs.readFile(file, "utf8")) as T;
114
- }
115
-
116
109
  function decodeJwtPayload(token: string | undefined): Record<string, any> | undefined {
117
110
  if (!token) return undefined;
118
111
  const parts = token.split(".");
@@ -274,23 +267,20 @@ function parseUsageResponse(body: unknown): UsageApiSnapshot | undefined {
274
267
  }
275
268
 
276
269
  async function readPiCodexAuth(): Promise<PiAuthEntry & { accountId: string }> {
277
- const auth = await readJsonFile<PiAuthFile>(piAuthPath());
278
- const entry = auth[CODEX_PROVIDER];
270
+ const entry = readStoredCredential(CODEX_PROVIDER, piAuthPath()) as PiAuthEntry | undefined;
279
271
  const accountId = getCodexAccountId(entry);
280
272
  if (!entry?.access || !accountId) throw new Error("Missing openai-codex OAuth entry in Pi auth");
281
273
  return { ...entry, accountId };
282
274
  }
283
275
 
284
276
  async function readOpenCodeGoAuth(): Promise<SubscriptionAccountSnapshot> {
285
- const auth = await readJsonFile<PiAuthFile>(piAuthPath());
286
- const entry = auth[OPC_PROVIDER];
277
+ const entry = readStoredCredential(OPC_PROVIDER, piAuthPath()) as PiAuthEntry | undefined;
287
278
  if (!entry?.key && !entry?.accountId) throw new Error("Missing opencode-go API key or accountId in Pi auth");
288
279
  return authAccountSnapshot("OpenCode Go", entry, { plan: "Go" });
289
280
  }
290
281
 
291
282
  async function readZaiAuth(): Promise<{ key: string; account: SubscriptionAccountSnapshot }> {
292
- const auth = await readJsonFile<PiAuthFile>(piAuthPath());
293
- const entry = auth[ZAI_PROVIDER];
283
+ const entry = readStoredCredential(ZAI_PROVIDER, piAuthPath()) as PiAuthEntry | undefined;
294
284
  if (!entry?.key) throw new Error("Missing zai API key in Pi auth");
295
285
  return { key: entry.key, account: authAccountSnapshot("Z.ai", entry) };
296
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bacnh85/pi-sub",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Pi extension showing subscription usage for supported model providers.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,6 +38,6 @@
38
38
  "node": ">=20.3.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@earendil-works/pi-coding-agent": "*"
41
+ "@earendil-works/pi-coding-agent": ">=0.80.8 <0.81.0"
42
42
  }
43
43
  }