@charmland/pi-hyper-provider 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/credits.ts +17 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charmland/pi-hyper-provider",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Pi extension for Charm's Hyper inference provider",
5
5
  "license": "MIT",
6
6
  "keywords": [
package/src/credits.ts CHANGED
@@ -20,21 +20,30 @@ const CREDITS_RETRY_DELAY_MS_INITIAL = 5_000;
20
20
  const CREDITS_RETRY_DELAY_MS_MAX = 5 * 60_000;
21
21
  const CREDITS_RETRY_EXPONENT_MAX = 6;
22
22
 
23
- const CreditsPayloadSchema = Type.Object(
24
- {
25
- balance: Type.Number(),
26
- },
27
- { additionalProperties: false },
28
- );
23
+ const CreditsPayloadSchema = Type.Union([
24
+ Type.Object(
25
+ {
26
+ balance: Type.Number(),
27
+ },
28
+ { additionalProperties: false },
29
+ ),
30
+ Type.Object(
31
+ {
32
+ balance_usd: Type.Number(),
33
+ },
34
+ { additionalProperties: false },
35
+ ),
36
+ ]);
29
37
  const CreditsPayloadValidator = Compile(CreditsPayloadSchema);
30
38
 
31
- async function fetchCredits(apiKey: string, signal: AbortSignal): Promise<number> {
39
+ async function fetchCredits(apiKey: string, signal: AbortSignal): Promise<number | undefined> {
32
40
  const payload = await httpClient.fetchJson(`${HYPER_API_BASE_URL}/credits`, {
33
41
  headers: hyperJsonHeaders({ Authorization: `Bearer ${apiKey}` }),
34
42
  signal,
35
43
  timeoutMs: CREDITS_FETCH_TIMEOUT_MS,
36
44
  });
37
- return parseSchema(CreditsPayloadValidator, payload, "Hyper /credits response").balance;
45
+ const credits = parseSchema(CreditsPayloadValidator, payload, "Hyper /credits response");
46
+ return "balance" in credits ? credits.balance : undefined;
38
47
  }
39
48
 
40
49
  function isTransientCreditError(error: unknown): boolean {