@specode/pi-subscription-usage 1.3.0 → 1.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.
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/package.json +1 -1
- package/src/codex-reset-core.ts +9 -17
- package/src/codex-resets.ts +6 -7
- package/src/query.ts +58 -12
- package/src/usage.ts +15 -22
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ A Pi extension that shows the active account's subscription quota in one consist
|
|
|
6
6
|
|
|
7
7
|
Supported providers:
|
|
8
8
|
|
|
9
|
-
- **OpenAI (ChatGPT subscription)** — separate `Plan limits` and app-limit groups for Pi's `openai` OAuth login, rendered with the existing quota bars. The footer and status event use `Plan limits`, matching the ChatGPT usage page. Also requires `openai-codex` OAuth in Pi for the same ChatGPT account/workspace
|
|
9
|
+
- **OpenAI (ChatGPT subscription)** — separate `Plan limits` and app-limit groups for Pi's `openai` OAuth login, rendered with the existing quota bars. The footer and status event use `Plan limits`, matching the ChatGPT usage page. Also requires `openai-codex` OAuth in Pi for the same ChatGPT account/workspace, because OpenAI rejects the Sign in with ChatGPT token on ChatGPT usage and reset endpoints; run `/login openai-codex` once and keep OpenAI as the active model (see [Stability](#stability)). The Codex backend credential reads `/wham/usage` for website plan windows (`rate_limit`) and credits, and `/wham/usage/chatpass/apps` for the exact active application registration. Plan and app windows have distinct percentages and reset times; neither substitutes for the other. `App Allowance` is the configured usage cap, not remaining quota. Both credentials participate in cache invalidation. No browser cookies are used. Available account reset tickets are shown as `Account Resets`; redemption uses the companion Codex account's reset endpoint with explicit confirmation, not an app-specific reset endpoint.
|
|
10
10
|
|
|
11
|
-
- **OpenAI Codex** — 5-hour and weekly quota, model-specific quota, and confirmed reset-credit redemption.
|
|
11
|
+
- **OpenAI Codex** — 5-hour and weekly quota, model-specific quota, and confirmed reset-credit redemption. `Resets Left` counts only redeemable tickets from the reset-credit list, not the usage summary.
|
|
12
12
|
- **OpenCode Go** — 5-hour, weekly, and monthly windows.
|
|
13
13
|
- **Grok** — weekly and/or monthly quota using only Pi's `xai` / `xai-auth` OAuth credentials, with account identity verification. A weekly `currentPeriod` with an omitted `creditUsagePercent` is treated as 0% used (proto3 omits zero after reset). Unified SuperGrok billing is still probed from the default monthly endpoint, but that probe is no longer required when the weekly window is already displayable. Windows use the same `5h / 1w / 1m` status format as other providers.
|
|
14
14
|
- **Kimi Coding** — 5-hour and weekly windows, plus the membership plan reported by the usage API.
|
|
@@ -76,7 +76,7 @@ The setting applies to the footer status, `/usage` quota bars, and the structure
|
|
|
76
76
|
|
|
77
77
|
## OpenAI / Codex reset safety
|
|
78
78
|
|
|
79
|
-
OpenAI
|
|
79
|
+
OpenAI and Codex modes both use the same `/wham/rate-limit-reset-credits` and `/consume` endpoints as the ChatGPT usage page, authenticated with the Codex account's backend credential and scoped to that token's own account (`chatgpt-account-id`) for both display and redemption. Both modes count and offer only explicit, available, plan-supported, unexpired `codex_rate_limits` tickets, and always redeem a specific ticket: neither a summary count nor a failed listing falls back to a server-chosen reset. In OpenAI mode, tickets reset server-defined account windows, **not necessarily the current app's window**; the confirmation states this scope. Reset availability failure does not hide quota; successful redemption invalidates both providers' usage caches.
|
|
80
80
|
|
|
81
81
|
Before redeeming a reset credit, the extension:
|
|
82
82
|
|
|
@@ -131,7 +131,7 @@ pi --no-extensions --offline -e ./index.ts --list-models
|
|
|
131
131
|
|
|
132
132
|
## Stability
|
|
133
133
|
|
|
134
|
-
OpenAI app usage also depends on an undocumented ChatGPT endpoint.
|
|
134
|
+
OpenAI app usage also depends on an undocumented ChatGPT endpoint. OpenAI rejects Sign in with ChatGPT tokens on these ChatGPT usage and reset endpoints (HTTP 401), so the companion Codex login is required: run `/login openai-codex` once with the same account/workspace. It is used only to read usage; keep OpenAI as the active model. Without it, check usage at https://chatgpt.com/settings/usage. An account/workspace mismatch, missing registration, or missing windows produces an error rather than displaying another account's quota. `App Allowance` is the configured share the app may use, not its remaining percentage. `Source` identifies this as the matching app in Pi's Codex account; matching application IDs is not independent cryptographic verification of both token identities.
|
|
135
135
|
|
|
136
136
|
Codex reset, Grok billing, and Kimi usage rely on undocumented provider APIs that may change. When an API fails, the extension reports the query error and does not fall back to uncontrolled credential or proxy paths.
|
|
137
137
|
|
package/README.zh-CN.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
支持以下提供商:
|
|
8
8
|
|
|
9
|
-
- **OpenAI(ChatGPT 订阅)**:将套餐 `Plan limits` 与当前应用额度分组展示,沿用原有进度条。底部及状态事件默认展示 `Plan limits`,与 ChatGPT 用量页对齐。同时需要在 Pi 登录同一 ChatGPT 账户/工作区的 `openai-codex
|
|
9
|
+
- **OpenAI(ChatGPT 订阅)**:将套餐 `Plan limits` 与当前应用额度分组展示,沿用原有进度条。底部及状态事件默认展示 `Plan limits`,与 ChatGPT 用量页对齐。同时需要在 Pi 登录同一 ChatGPT 账户/工作区的 `openai-codex`,因为 OpenAI 会拒绝 Sign in with ChatGPT 令牌访问 ChatGPT 用量和重置接口;执行一次 `/login openai-codex` 即可,当前模型仍保持 OpenAI(见[稳定性](#稳定性))。插件用 Codex 后端凭据从 `/wham/usage` 的 `rate_limit` 读取网页套餐窗口及积分余额,并从 `/wham/usage/chatpass/apps` 精确匹配当前应用窗口。两组各自保留百分比与重置时间,不互相冒充。`App Allowance` 是配置的使用上限,不是剩余额度;任一凭据变化都会使缓存失效。不读取浏览器 Cookie。可用账户重置票据显示为 `Account Resets`;明确确认后,通过配套 Codex 账户的重置接口兑换,并非应用专属重置接口。
|
|
10
10
|
|
|
11
|
-
- **OpenAI Codex**:5
|
|
11
|
+
- **OpenAI Codex**:5 小时与每周额度、模型专属额度,以及需要确认的重置次数兑换。`Resets Left` 只统计重置票据列表中可兑换的票据,不采用用量接口的汇总数。
|
|
12
12
|
- **OpenCode Go**:5 小时、每周和每月窗口。
|
|
13
13
|
- **Grok**:每周和/或每月额度;只使用 Pi 的 `xai` / `xai-auth` OAuth 凭据,并先验证账户身份。若 weekly `currentPeriod` 存在但省略了 `creditUsagePercent`,按已用 0% 处理(proto3 在周期重置后会省略 0)。统一账单账户仍会探测默认月度接口,但 weekly 窗口已经可展示时,月度探测失败不再让整次查询失败。窗口与其他提供商一样使用 `5h / 1w / 1m` 状态格式。
|
|
14
14
|
- **Kimi Coding**:5 小时和每周窗口,以及额度接口返回的会员套餐。
|
|
@@ -76,7 +76,7 @@ OpenAI 和 Codex 模式都仅在确认有可兑换重置次数时显示重置菜
|
|
|
76
76
|
|
|
77
77
|
## OpenAI / Codex 重置安全措施
|
|
78
78
|
|
|
79
|
-
OpenAI
|
|
79
|
+
OpenAI 与 Codex 模式都使用 ChatGPT 用量页相同的 `/wham/rate-limit-reset-credits` 和 `/consume` 接口,并以 Codex 账户的后端凭据认证;显示和兑换时都通过 `chatgpt-account-id` 限定为该令牌自身的账户。两种模式都只统计和提供明确存在、可用、套餐支持且未过期的 `codex_rate_limits` 票据,且始终指定具体票据兑换:仅有汇总次数或列表查询失败时,都不会退回由服务端选票的兑换。OpenAI 模式下,票据重置的是服务端定义的账户窗口,**不保证清空当前应用窗口**,确认框会说明这一范围。查询重置次数失败不会隐藏额度;兑换成功会使两种模式的额度缓存失效。
|
|
80
80
|
|
|
81
81
|
兑换重置次数前,本扩展会:
|
|
82
82
|
|
|
@@ -131,7 +131,7 @@ pi --no-extensions --offline -e ./index.ts --list-models
|
|
|
131
131
|
|
|
132
132
|
## 稳定性
|
|
133
133
|
|
|
134
|
-
OpenAI 应用额度也依赖未公开的 ChatGPT
|
|
134
|
+
OpenAI 应用额度也依赖未公开的 ChatGPT 接口。OpenAI 会拒绝 Sign in with ChatGPT 令牌访问这些 ChatGPT 用量和重置接口(HTTP 401),因此必须配套 Codex 登录:用同一账户/工作区执行一次 `/login openai-codex`。它只用于读取用量,当前模型仍可保持 OpenAI。未登录时,可在 https://chatgpt.com/settings/usage 查看用量。账户/工作区不匹配、找不到应用注册或额度窗口时会报告错误,不展示其他账户的额度。`App Allowance` 表示允许应用使用的套餐份额,不是剩余额度百分比。`Source` 明确标注这是 Pi Codex 登录账户内匹配应用的数据;应用 ID 匹配不是对两套令牌身份的独立验签证明。
|
|
135
135
|
|
|
136
136
|
Codex 重置、Grok 账单和 Kimi 额度依赖未公开的提供商 API,这些 API 可能发生变化。如果 API 调用失败,本扩展只会报告查询错误,不会退回到不受控制的凭据或代理路径。
|
|
137
137
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specode/pi-subscription-usage",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Show subscription quota for OpenAI, Codex, OpenCode Go, Grok, and Kimi, plus OpenAI and Codex account reset credits in Pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/codex-reset-core.ts
CHANGED
|
@@ -43,13 +43,6 @@ export function codexResetCount(report: UsageReport): number | undefined {
|
|
|
43
43
|
: undefined;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export function genericCodexResetOption(): CodexResetOption {
|
|
47
|
-
return {
|
|
48
|
-
title: "Full Reset",
|
|
49
|
-
description: "Resets the current usage windows.",
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
46
|
export function resetOptionExpiration(option: CodexResetOption): string {
|
|
54
47
|
if (option.expiresAt === undefined) return "No Expiry";
|
|
55
48
|
const expiration = new Date(option.expiresAt * 1_000);
|
|
@@ -105,9 +98,13 @@ export function verifyCodexStoredOAuthCredential(
|
|
|
105
98
|
return accountId;
|
|
106
99
|
}
|
|
107
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Offer only explicit, plan-supported, unexpired tickets. Redemption is
|
|
103
|
+
* irreversible, so a summary count alone never becomes a server-chosen reset.
|
|
104
|
+
*/
|
|
108
105
|
export function normalizeCodexResetCreditsPayload(
|
|
109
106
|
payload: Record<string, unknown>,
|
|
110
|
-
options: {
|
|
107
|
+
options: { now?: number } = {},
|
|
111
108
|
): CodexResetAvailability {
|
|
112
109
|
const availableCount = nonnegativeInteger(payload.available_count);
|
|
113
110
|
if (availableCount === undefined) {
|
|
@@ -128,9 +125,9 @@ export function normalizeCodexResetCreditsPayload(
|
|
|
128
125
|
) {
|
|
129
126
|
continue;
|
|
130
127
|
}
|
|
131
|
-
if (
|
|
128
|
+
if (credit.is_supported_by_plan !== true) continue;
|
|
132
129
|
const option = normalizeResetOption(credit);
|
|
133
|
-
if (
|
|
130
|
+
if (option.expiresAt !== undefined &&
|
|
134
131
|
option.expiresAt * 1_000 <= (options.now ?? Date.now())) continue;
|
|
135
132
|
resetOptions.push(option);
|
|
136
133
|
}
|
|
@@ -140,12 +137,7 @@ export function normalizeCodexResetCreditsPayload(
|
|
|
140
137
|
(right.expiresAt ?? Number.MAX_SAFE_INTEGER),
|
|
141
138
|
);
|
|
142
139
|
resetOptions.splice(Math.min(availableCount, 32));
|
|
143
|
-
|
|
144
|
-
resetOptions.push(genericCodexResetOption());
|
|
145
|
-
return {
|
|
146
|
-
availableCount: options.requireExplicitCredit ? resetOptions.length : availableCount,
|
|
147
|
-
options: resetOptions,
|
|
148
|
-
};
|
|
140
|
+
return { availableCount: resetOptions.length, options: resetOptions };
|
|
149
141
|
}
|
|
150
142
|
|
|
151
143
|
export function parseCodexResetOutcome(
|
|
@@ -207,7 +199,7 @@ function isOutcomeCode(value: unknown): value is CodexResetOutcomeCode {
|
|
|
207
199
|
);
|
|
208
200
|
}
|
|
209
201
|
|
|
210
|
-
function codexAccountIdFromAccessToken(access: string): string | undefined {
|
|
202
|
+
export function codexAccountIdFromAccessToken(access: string): string | undefined {
|
|
211
203
|
try {
|
|
212
204
|
const parts = access.split(".");
|
|
213
205
|
if (parts.length !== 3 || !parts[1]) return undefined;
|
package/src/codex-resets.ts
CHANGED
|
@@ -41,15 +41,15 @@ export async function resolveCodexResetAuth(
|
|
|
41
41
|
}
|
|
42
42
|
const expectedModel = `${model.provider}/${model.id}`;
|
|
43
43
|
const adapter = adapterForProvider(model.provider);
|
|
44
|
-
if (!adapter) throw new Error(
|
|
44
|
+
if (!adapter) throw new Error(`Usage support for ${model.provider} is unavailable.`);
|
|
45
45
|
const auth = await resolveUsageAuth(ctx, adapter, salt);
|
|
46
46
|
if (`${ctx.model?.provider}/${ctx.model?.id}` !== expectedModel) {
|
|
47
47
|
throw new Error(
|
|
48
|
-
"The current model changed while resolving
|
|
48
|
+
"The current model changed while resolving reset authentication.",
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
if (!auth)
|
|
52
|
-
throw new Error(
|
|
52
|
+
throw new Error(`No runtime credential is configured for ${adapter.displayName}.`);
|
|
53
53
|
|
|
54
54
|
const resolvedAccess =
|
|
55
55
|
bearerToken(headerValue(auth.headers, "Authorization")) ?? auth.apiKey;
|
|
@@ -98,7 +98,6 @@ export async function listCodexResetCredits(
|
|
|
98
98
|
timeoutMs,
|
|
99
99
|
"Codex reset endpoint",
|
|
100
100
|
),
|
|
101
|
-
{ requireExplicitCredit: auth.actualProviderId === OPENAI_PROVIDER_ID },
|
|
102
101
|
);
|
|
103
102
|
}
|
|
104
103
|
|
|
@@ -111,8 +110,8 @@ export async function consumeCodexResetCredit(
|
|
|
111
110
|
): Promise<CodexResetOutcome> {
|
|
112
111
|
if (!redeemRequestId)
|
|
113
112
|
throw new Error("Codex reset request ID must not be empty.");
|
|
114
|
-
if (
|
|
115
|
-
throw new Error("
|
|
113
|
+
if (!option.creditId) {
|
|
114
|
+
throw new Error("Account resets require an explicitly selected credit.");
|
|
116
115
|
}
|
|
117
116
|
return parseCodexResetOutcome(
|
|
118
117
|
await fetchProviderJson(
|
|
@@ -125,7 +124,7 @@ export async function consumeCodexResetCredit(
|
|
|
125
124
|
method: "POST",
|
|
126
125
|
body: {
|
|
127
126
|
redeem_request_id: redeemRequestId,
|
|
128
|
-
|
|
127
|
+
credit_id: option.creditId,
|
|
129
128
|
},
|
|
130
129
|
},
|
|
131
130
|
),
|
package/src/query.ts
CHANGED
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
redactUsageError,
|
|
10
10
|
} from "./core.ts";
|
|
11
11
|
import { CODEX_PROVIDER_ID } from "./providers/codex-constants.ts";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
codexAccountIdFromAccessToken,
|
|
14
|
+
normalizeCodexResetCreditsPayload,
|
|
15
|
+
} from "./codex-reset-core.ts";
|
|
13
16
|
import {
|
|
14
17
|
codexEmailFromAuthorization,
|
|
15
18
|
normalizeCodexUsage,
|
|
@@ -35,6 +38,8 @@ import type {
|
|
|
35
38
|
} from "./types.ts";
|
|
36
39
|
|
|
37
40
|
const CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
41
|
+
const RESET_CREDITS_URL =
|
|
42
|
+
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits";
|
|
38
43
|
const OPENCODE_GO_USAGE_URL = "https://opencode.ai/zen/go/v1/usage";
|
|
39
44
|
const KIMI_USAGE_URL = "https://api.kimi.com/coding/v1/usages";
|
|
40
45
|
const GROK_USER_URL = "https://cli-chat-proxy.grok.com/v1/user";
|
|
@@ -68,15 +73,11 @@ export const SUPPORTED_ADAPTERS: readonly UsageProviderAdapter[] = [
|
|
|
68
73
|
fetchProviderJson(CODEX_USAGE_URL, auth, signal, timeoutMs, "OpenAI plan usage endpoint"),
|
|
69
74
|
]);
|
|
70
75
|
const report = normalizeOpenAIPlanUsage(appPayload, planPayload, auth.openaiClientId, Date.now());
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits",
|
|
74
|
-
auth, signal, timeoutMs, "Account reset credits endpoint",
|
|
75
|
-
), { requireExplicitCredit: true });
|
|
76
|
-
report.metrics.push({ id: "reset-credits", label: "Account Resets", value: credits.availableCount, unit: "count" });
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (isAbortError(error) || signal.aborted) throw error;
|
|
76
|
+
const resetCount = await fetchRedeemableResetCount(auth, signal, timeoutMs);
|
|
77
|
+
if (resetCount === undefined) {
|
|
79
78
|
report.notes = ["Account reset availability could not be verified."];
|
|
79
|
+
} else {
|
|
80
|
+
report.metrics.push({ id: "reset-credits", label: "Account Resets", value: resetCount, unit: "count" });
|
|
80
81
|
}
|
|
81
82
|
return report;
|
|
82
83
|
},
|
|
@@ -91,17 +92,30 @@ export const SUPPORTED_ADAPTERS: readonly UsageProviderAdapter[] = [
|
|
|
91
92
|
label: "ChatGPT subscription limits",
|
|
92
93
|
},
|
|
93
94
|
async query(auth, signal, timeoutMs) {
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
const [payload, resetCount] = await Promise.all([
|
|
96
|
+
fetchProviderJson(
|
|
96
97
|
CODEX_USAGE_URL,
|
|
97
98
|
auth,
|
|
98
99
|
signal,
|
|
99
100
|
timeoutMs,
|
|
100
101
|
"Codex usage endpoint",
|
|
101
102
|
),
|
|
103
|
+
fetchRedeemableResetCount(auth, signal, timeoutMs),
|
|
104
|
+
]);
|
|
105
|
+
// The usage summary also counts tickets the reset menu would refuse.
|
|
106
|
+
const report = normalizeCodexUsage(
|
|
107
|
+
{
|
|
108
|
+
...payload,
|
|
109
|
+
rate_limit_reset_credits:
|
|
110
|
+
resetCount === undefined ? undefined : { available_count: resetCount },
|
|
111
|
+
},
|
|
102
112
|
Date.now(),
|
|
103
113
|
codexEmailFromAuthorization(auth.headers.Authorization),
|
|
104
114
|
);
|
|
115
|
+
if (resetCount === undefined) {
|
|
116
|
+
report.notes = ["Reset availability could not be verified."];
|
|
117
|
+
}
|
|
118
|
+
return report;
|
|
105
119
|
},
|
|
106
120
|
},
|
|
107
121
|
{
|
|
@@ -266,7 +280,8 @@ export async function resolveUsageAuth(
|
|
|
266
280
|
const codexAdapter = adapterForProvider(CODEX_PROVIDER_ID)!;
|
|
267
281
|
const companion = await resolveUsageAuth(ctx, { ...codexAdapter, requiresOAuth: true }, salt);
|
|
268
282
|
if (!companion) {
|
|
269
|
-
|
|
283
|
+
// ChatGPT backend usage rejects these app tokens (401 rejected_by_access_enforcement).
|
|
284
|
+
throw new Error("OpenAI rejects Sign in with ChatGPT tokens for ChatGPT usage and reset data. Run /login openai-codex once with the same ChatGPT account/workspace; it is used only to read usage, so keep OpenAI as the active model. You can also check https://chatgpt.com/settings/usage.");
|
|
270
285
|
}
|
|
271
286
|
return {
|
|
272
287
|
actualProviderId: model.provider,
|
|
@@ -289,6 +304,37 @@ export async function resolveUsageAuth(
|
|
|
289
304
|
};
|
|
290
305
|
}
|
|
291
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Undefined means unverified: usage still displays, but no reset is offered.
|
|
309
|
+
* Scope the listing to the backend token's own account, as redemption does.
|
|
310
|
+
*/
|
|
311
|
+
async function fetchRedeemableResetCount(
|
|
312
|
+
auth: ResolvedUsageAuth,
|
|
313
|
+
signal: AbortSignal,
|
|
314
|
+
timeoutMs: number,
|
|
315
|
+
): Promise<number | undefined> {
|
|
316
|
+
const access = /^Bearer\s+(\S+)$/iu.exec(
|
|
317
|
+
headerValue(auth.headers, "Authorization") ?? "",
|
|
318
|
+
)?.[1];
|
|
319
|
+
const accountId = access ? codexAccountIdFromAccessToken(access) : undefined;
|
|
320
|
+
if (!accountId) return undefined;
|
|
321
|
+
try {
|
|
322
|
+
return normalizeCodexResetCreditsPayload(
|
|
323
|
+
await fetchProviderJson(
|
|
324
|
+
RESET_CREDITS_URL,
|
|
325
|
+
auth,
|
|
326
|
+
signal,
|
|
327
|
+
timeoutMs,
|
|
328
|
+
"Reset credits endpoint",
|
|
329
|
+
{ headers: { "chatgpt-account-id": accountId } },
|
|
330
|
+
),
|
|
331
|
+
).availableCount;
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (isAbortError(error) || signal.aborted) throw error;
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
292
338
|
export async function queryProviderUsage(
|
|
293
339
|
adapter: UsageProviderAdapter,
|
|
294
340
|
auth: ResolvedUsageAuth,
|
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,
|
|
@@ -417,46 +416,40 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
417
416
|
}
|
|
418
417
|
const expectedModel = modelIdentity(current.model);
|
|
419
418
|
const isOpenAI = current.model?.provider === OPENAI_PROVIDER_ID;
|
|
420
|
-
const
|
|
419
|
+
const resetNoun = isOpenAI ? "account" : "Codex";
|
|
421
420
|
if (modelIdentity(ctx.model) !== expectedModel) throw new Error("Model changed; reset cancelled.");
|
|
422
|
-
const summaryCount = codexResetCount(current.outcome.state.report) ?? 0;
|
|
423
421
|
let auth = await awaitWithDeadline(
|
|
424
422
|
() => resolveCodexResetAuth(ctx),
|
|
425
423
|
controller.signal,
|
|
426
424
|
QUERY_TIMEOUT_MS,
|
|
427
|
-
"resolving
|
|
425
|
+
"resolving reset authentication",
|
|
428
426
|
);
|
|
429
427
|
if (auth.usageFingerprint !== current.outcome.fingerprint) {
|
|
430
428
|
throw new Error("Account changed since usage was displayed; run /usage again.");
|
|
431
429
|
}
|
|
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
|
-
}
|
|
430
|
+
// A failed listing never falls back to an unscoped, server-chosen reset.
|
|
431
|
+
const availability = await listCodexResetCredits(
|
|
432
|
+
auth,
|
|
433
|
+
controller.signal,
|
|
434
|
+
QUERY_TIMEOUT_MS,
|
|
435
|
+
);
|
|
446
436
|
if (availability.availableCount <= 0 || availability.options.length === 0) {
|
|
447
|
-
ctx.ui.notify(
|
|
437
|
+
ctx.ui.notify(`No ${resetNoun} reset credits available.`, "info");
|
|
448
438
|
return undefined;
|
|
449
439
|
}
|
|
450
440
|
const labels = availability.options.map(
|
|
451
441
|
(option: CodexResetOption, index: number) =>
|
|
452
442
|
`${index + 1}. ${option.title} · ${resetOptionExpiration(option)}`,
|
|
453
443
|
);
|
|
454
|
-
const selected = await ctx.ui.select(
|
|
444
|
+
const selected = await ctx.ui.select(
|
|
445
|
+
isOpenAI ? "Choose an Account Reset" : "Choose a Codex Reset",
|
|
446
|
+
labels,
|
|
447
|
+
);
|
|
455
448
|
if (!selected) return undefined;
|
|
456
449
|
const option = availability.options[labels.indexOf(selected)];
|
|
457
450
|
if (!option) return undefined;
|
|
458
451
|
const confirmation = await ctx.ui.select(
|
|
459
|
-
`Redeem one ${
|
|
452
|
+
`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
453
|
[...CODEX_RESET_CONFIRMATION_OPTIONS],
|
|
461
454
|
);
|
|
462
455
|
if (!isCodexResetConfirmed(confirmation)) return undefined;
|
|
@@ -470,7 +463,7 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
|
|
|
470
463
|
() => resolveCodexResetAuth(ctx),
|
|
471
464
|
controller.signal,
|
|
472
465
|
QUERY_TIMEOUT_MS,
|
|
473
|
-
"revalidating
|
|
466
|
+
"revalidating reset authentication",
|
|
474
467
|
);
|
|
475
468
|
if (
|
|
476
469
|
modelIdentity(ctx.model) !== expectedModel ||
|