@specode/pi-subscription-usage 1.3.0 → 1.4.0
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 +83 -85
- package/README.zh-CN.md +85 -87
- package/package.json +4 -3
- package/src/codex-reset-core.ts +9 -17
- package/src/codex-resets.ts +6 -7
- package/src/providers/antigravity.ts +372 -0
- package/src/query.ts +203 -18
- package/src/types.ts +1 -0
- package/src/usage.ts +25 -25
package/src/usage.ts
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
CODEX_RESET_CONFIRMATION_OPTIONS,
|
|
21
21
|
codexResetCount,
|
|
22
22
|
formatCodexResetOutcome,
|
|
23
|
-
genericCodexResetOption,
|
|
24
23
|
isCodexResetConfirmed,
|
|
25
24
|
resetOptionExpiration,
|
|
26
25
|
type CodexResetOption,
|
|
@@ -70,7 +69,10 @@ type StableCurrent = {
|
|
|
70
69
|
|
|
71
70
|
export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
72
71
|
const cache = new UsageCache(CACHE_TTL_MS);
|
|
73
|
-
const failureBackoff = new Map<
|
|
72
|
+
const failureBackoff = new Map<
|
|
73
|
+
string,
|
|
74
|
+
{ until: number; message: string; status: "unsupported" | "query-failed" }
|
|
75
|
+
>();
|
|
74
76
|
const activeControllers = new Set<AbortController>();
|
|
75
77
|
let sessionActive = false;
|
|
76
78
|
let displayMode: UsageDisplayMode = DEFAULT_USAGE_DISPLAY_MODE;
|
|
@@ -225,7 +227,7 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
225
227
|
state: {
|
|
226
228
|
providerId: adapter.id,
|
|
227
229
|
providerName: adapter.displayName,
|
|
228
|
-
status:
|
|
230
|
+
status: failure.status,
|
|
229
231
|
message: failure.message,
|
|
230
232
|
},
|
|
231
233
|
fingerprint: auth.fingerprint,
|
|
@@ -252,15 +254,19 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
252
254
|
} catch (error) {
|
|
253
255
|
if (isAbortError(error) || !sessionActive) throw error;
|
|
254
256
|
const message = errorMessage(error);
|
|
257
|
+
const status = error instanceof UsageUnsupportedError
|
|
258
|
+
? "unsupported"
|
|
259
|
+
: "query-failed";
|
|
255
260
|
failureBackoff.set(failureKey, {
|
|
256
261
|
until: Date.now() + FAILURE_BACKOFF_MS,
|
|
257
262
|
message,
|
|
263
|
+
status,
|
|
258
264
|
});
|
|
259
265
|
return {
|
|
260
266
|
state: {
|
|
261
267
|
providerId: adapter.id,
|
|
262
268
|
providerName: adapter.displayName,
|
|
263
|
-
status
|
|
269
|
+
status,
|
|
264
270
|
message,
|
|
265
271
|
},
|
|
266
272
|
fingerprint: auth.fingerprint,
|
|
@@ -417,46 +423,40 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
417
423
|
}
|
|
418
424
|
const expectedModel = modelIdentity(current.model);
|
|
419
425
|
const isOpenAI = current.model?.provider === OPENAI_PROVIDER_ID;
|
|
420
|
-
const
|
|
426
|
+
const resetNoun = isOpenAI ? "account" : "Codex";
|
|
421
427
|
if (modelIdentity(ctx.model) !== expectedModel) throw new Error("Model changed; reset cancelled.");
|
|
422
|
-
const summaryCount = codexResetCount(current.outcome.state.report) ?? 0;
|
|
423
428
|
let auth = await awaitWithDeadline(
|
|
424
429
|
() => resolveCodexResetAuth(ctx),
|
|
425
430
|
controller.signal,
|
|
426
431
|
QUERY_TIMEOUT_MS,
|
|
427
|
-
"resolving
|
|
432
|
+
"resolving reset authentication",
|
|
428
433
|
);
|
|
429
434
|
if (auth.usageFingerprint !== current.outcome.fingerprint) {
|
|
430
435
|
throw new Error("Account changed since usage was displayed; run /usage again.");
|
|
431
436
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
);
|
|
439
|
-
} catch (error) {
|
|
440
|
-
if (isOpenAI || isAbortError(error) || summaryCount <= 0) throw error;
|
|
441
|
-
availability = {
|
|
442
|
-
availableCount: summaryCount,
|
|
443
|
-
options: [genericCodexResetOption()],
|
|
444
|
-
};
|
|
445
|
-
}
|
|
437
|
+
// A failed listing never falls back to an unscoped, server-chosen reset.
|
|
438
|
+
const availability = await listCodexResetCredits(
|
|
439
|
+
auth,
|
|
440
|
+
controller.signal,
|
|
441
|
+
QUERY_TIMEOUT_MS,
|
|
442
|
+
);
|
|
446
443
|
if (availability.availableCount <= 0 || availability.options.length === 0) {
|
|
447
|
-
ctx.ui.notify(
|
|
444
|
+
ctx.ui.notify(`No ${resetNoun} reset credits available.`, "info");
|
|
448
445
|
return undefined;
|
|
449
446
|
}
|
|
450
447
|
const labels = availability.options.map(
|
|
451
448
|
(option: CodexResetOption, index: number) =>
|
|
452
449
|
`${index + 1}. ${option.title} · ${resetOptionExpiration(option)}`,
|
|
453
450
|
);
|
|
454
|
-
const selected = await ctx.ui.select(
|
|
451
|
+
const selected = await ctx.ui.select(
|
|
452
|
+
isOpenAI ? "Choose an Account Reset" : "Choose a Codex Reset",
|
|
453
|
+
labels,
|
|
454
|
+
);
|
|
455
455
|
if (!selected) return undefined;
|
|
456
456
|
const option = availability.options[labels.indexOf(selected)];
|
|
457
457
|
if (!option) return undefined;
|
|
458
458
|
const confirmation = await ctx.ui.select(
|
|
459
|
-
`Redeem one ${
|
|
459
|
+
`Redeem one ${resetNoun} reset?\n${option.title}\n${option.description}\n${resetOptionExpiration(option)}${isOpenAI ? "\nConsumes a reset from the companion Codex account. Only ticket-supported account windows are reset; clearing this app's quota is not guaranteed." : ""}`,
|
|
460
460
|
[...CODEX_RESET_CONFIRMATION_OPTIONS],
|
|
461
461
|
);
|
|
462
462
|
if (!isCodexResetConfirmed(confirmation)) return undefined;
|
|
@@ -470,7 +470,7 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
470
470
|
() => resolveCodexResetAuth(ctx),
|
|
471
471
|
controller.signal,
|
|
472
472
|
QUERY_TIMEOUT_MS,
|
|
473
|
-
"revalidating
|
|
473
|
+
"revalidating reset authentication",
|
|
474
474
|
);
|
|
475
475
|
if (
|
|
476
476
|
modelIdentity(ctx.model) !== expectedModel ||
|