dsh-codex-subscription 3.2.3 → 3.2.4

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/lib/index.js CHANGED
@@ -869,6 +869,51 @@ const setAuthFailureLogger = (fn) => {
869
869
  logAuthFailure = fn;
870
870
  };
871
871
  const SIGN_IN_RENEW = "ChatGPT sign-in needs to be renewed";
872
+ const ACCESS_DENIED = "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.";
873
+ const DEVICE_LIMIT = "ChatGPT does not allow this paid account on this device. Use another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear this restriction.";
874
+ const PURCHASE_LIMIT = "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.";
875
+ const PUBLIC_ACCESS_MESSAGES = /* @__PURE__ */ new Set([
876
+ ACCESS_DENIED,
877
+ DEVICE_LIMIT,
878
+ PURCHASE_LIMIT
879
+ ]);
880
+ const isAccessFailureMessage = (message) => PUBLIC_ACCESS_MESSAGES.has(message);
881
+ const isRestrictionFailureMessage = (message) => message === "ChatGPT does not allow this paid account on this device. Use another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear this restriction." || message === "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.";
882
+ function restrictionMessage(value) {
883
+ if (typeof value !== "string" || value.length > 8192) return void 0;
884
+ let text = value.trim().replace(/^Codex error:\s*/u, "");
885
+ try {
886
+ const body = JSON.parse(text);
887
+ text = body?.error?.message ?? body?.detail?.message ?? body?.detail ?? body?.message;
888
+ } catch {}
889
+ if (typeof text !== "string") return void 0;
890
+ text = text.trim().replace(/\s+/gu, " ");
891
+ if (PUBLIC_ACCESS_MESSAGES.has(text)) return text;
892
+ if (/^Device limit reached[.!]?$/iu.test(text)) return DEVICE_LIMIT;
893
+ if (/^Too many subscriptions associated with this card or device\. We can[’']t complete this purchase\.$/u.test(text)) return PURCHASE_LIMIT;
894
+ }
895
+ async function responseRestrictionMessage(response) {
896
+ if (typeof response?.clone !== "function") return void 0;
897
+ if (!/json|text\/plain/iu.test(response.headers?.get?.("content-type") ?? "")) return void 0;
898
+ let reader;
899
+ try {
900
+ reader = response.clone().body?.getReader();
901
+ if (!reader) return void 0;
902
+ const decoder = new TextDecoder();
903
+ let text = "", size = 0;
904
+ while (true) {
905
+ const { done, value } = await reader.read();
906
+ if (done) return restrictionMessage(text + decoder.decode());
907
+ size += value.byteLength;
908
+ if (size > 8192) return void 0;
909
+ text += decoder.decode(value, { stream: true });
910
+ }
911
+ } catch {
912
+ return;
913
+ } finally {
914
+ reader?.cancel().catch(() => {});
915
+ }
916
+ }
872
917
  const REQUEST_BLOCKED = "ChatGPT blocked this request before it reached your account (HTTP 403); your sign-in is fine, try again later or check your network, proxy or VPN";
873
918
  const CHALLENGE_MARKERS = /just a moment|cf-chl|_cf_chl_opt|attention required|enable javascript and cookies|challenge-platform/iu;
874
919
  /** Whether error text is a Cloudflare / network-protection page (pi-ai keeps only the body of a failed request, not its status). */
@@ -887,14 +932,18 @@ async function isBlockedByNetwork(response) {
887
932
  return false;
888
933
  }
889
934
  }
890
- /** The error message for a 401 or 403 answer, or undefined for any other status. */
935
+ /** Known restrictions take precedence over status-based authentication advice. */
891
936
  async function authFailureMessage(response) {
892
- if (response?.status !== 401 && response?.status !== 403) return void 0;
937
+ if (!response || response.ok || response.status < 400) return void 0;
938
+ const restriction = await responseRestrictionMessage(response);
939
+ if (restriction !== void 0) return restriction;
940
+ if (response.status !== 401 && response.status !== 403) return void 0;
893
941
  const blocked = response.status === 403 && await isBlockedByNetwork(response);
894
942
  await noteAuthFailure(response, blocked);
895
- return blocked ? REQUEST_BLOCKED : SIGN_IN_RENEW;
943
+ return blocked ? REQUEST_BLOCKED : response.status === 401 ? SIGN_IN_RENEW : ACCESS_DENIED;
896
944
  }
897
945
  async function noteAuthFailure(response, blocked) {
946
+ if (typeof logAuthFailure !== "function") return;
898
947
  try {
899
948
  const text = blocked || typeof response.clone !== "function" ? "" : (await response.clone().text()).slice(0, 400);
900
949
  logAuthFailure?.(blocked ? "HTTP 403 from the network layer in front of ChatGPT" : `ChatGPT answered HTTP ${response.status}`, text === "" ? void 0 : text);
@@ -2187,6 +2236,7 @@ function hoistLeadingSystem(context) {
2187
2236
  //#endregion
2188
2237
  //#region src/model-retry-hint.js
2189
2238
  const CODEX_OVERLOADED = /^\s*(?:Codex error:\s*)?Our servers are currently overloaded\. Please try again later\.\s*$/u;
2239
+ const CODEX_REQUEST_FAILED = /^\s*(?:Codex error:\s*)?An error occurred while processing your request\. You can retry your request, or contact us through our help center at help\.openai\.com if the error persists\. Please include the request ID [\w-]+ in your message\.?\s*$/u;
2190
2240
  /** Keep the provider's wait as a fact; only DSH decides whether and when to retry. */
2191
2241
  function providerRetryAfterMs(headers, at = Date.now()) {
2192
2242
  const read = (key) => typeof headers?.get === "function" ? headers.get(key) : headers?.[key];
@@ -2201,8 +2251,11 @@ function providerRetryAfterMs(headers, at = Date.now()) {
2201
2251
  return Number.isFinite(value) && value > 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : void 0;
2202
2252
  }
2203
2253
  function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } = {}) {
2204
- let response, responseStatus, outputStarted = false;
2254
+ let response, responseStatus, accessFailure, outputStarted = false;
2205
2255
  return {
2256
+ onAccessFailure(message) {
2257
+ accessFailure = message;
2258
+ },
2206
2259
  onResponse(info) {
2207
2260
  responseStatus = info?.status;
2208
2261
  response = [429, 503].includes(info?.status) ? {
@@ -2218,7 +2271,18 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
2218
2271
  ].includes(event.type)) outputStarted = true;
2219
2272
  },
2220
2273
  failure(original, signal) {
2221
- if (signal?.aborted || outputStarted || !original || typeof original.message !== "string" || [
2274
+ if (signal?.aborted || !original || original.code === "ABORTED" || typeof original.message !== "string") return original;
2275
+ const restriction = accessFailure ?? restrictionMessage(original.message) ?? (responseStatus === 403 ? "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." : responseStatus === 401 ? "ChatGPT sign-in needs to be renewed" : void 0);
2276
+ if (restriction !== void 0) {
2277
+ const { providerRetryAfterMs: _delay, ...failure } = original;
2278
+ return {
2279
+ ...failure,
2280
+ message: restriction,
2281
+ code: "AUTH",
2282
+ ...responseStatus === void 0 ? {} : { status: responseStatus }
2283
+ };
2284
+ }
2285
+ if (outputStarted || [
2222
2286
  "ABORTED",
2223
2287
  "AUTH",
2224
2288
  "INVALID_REQUEST",
@@ -2227,8 +2291,8 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
2227
2291
  "QUOTA_EXCEEDED"
2228
2292
  ].includes(original.code) || typeof dshLlm.isQuotaExceededError === "function" && dshLlm.isQuotaExceededError(original.message)) return original;
2229
2293
  const status = responseStatus ?? original.status;
2230
- const overloaded = original.code === "PI_AI_ERROR" && CODEX_OVERLOADED.test(original.message) && (status === void 0 || status >= 200 && status < 300);
2231
- if (!response && !overloaded) return original;
2294
+ const transientStreamFailure = original.code === "PI_AI_ERROR" && (CODEX_OVERLOADED.test(original.message) || CODEX_REQUEST_FAILED.test(original.message)) && (status === void 0 || status >= 200 && status < 300);
2295
+ if (!response && !transientStreamFailure) return original;
2232
2296
  if (/You have hit your ChatGPT usage limit/iu.test(original.message) || response?.status === 429 && original.code !== "RATE_LIMIT") return original;
2233
2297
  const code = response?.status === 429 ? "RATE_LIMIT" : "SERVER";
2234
2298
  let error;
@@ -2718,6 +2782,11 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
2718
2782
  networkFailure = safeFetchFailure(error);
2719
2783
  attempt.fetchFailure(error);
2720
2784
  scopedNetwork?.onFetchFailure?.(error);
2785
+ },
2786
+ async transformResponse(response, target) {
2787
+ const value = await (scopedNetwork?.transformResponse?.(response, target) ?? response);
2788
+ if (retryHint) retryHint.onAccessFailure(value.ok ? void 0 : await authFailureMessage(value));
2789
+ return value;
2721
2790
  }
2722
2791
  }
2723
2792
  };
@@ -2840,7 +2909,8 @@ Object.freeze([
2840
2909
  "1.1.0",
2841
2910
  "1.2.0",
2842
2911
  "1.3.0",
2843
- "1.4.0"
2912
+ "1.4.0",
2913
+ "1.5.0"
2844
2914
  ]);
2845
2915
  //#endregion
2846
2916
  //#region src/reasoning-json.js
@@ -4329,7 +4399,7 @@ function inheritedOriginalImageRef(session, assetId) {
4329
4399
  }
4330
4400
  //#endregion
4331
4401
  //#region src/version.js
4332
- const PACKAGE_VERSION = "3.2.3";
4402
+ const PACKAGE_VERSION = "3.2.4";
4333
4403
  const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
4334
4404
  //#endregion
4335
4405
  //#region src/codex-images.js
@@ -4852,7 +4922,7 @@ function createCodexImageTool(options) {
4852
4922
  if (!response.ok) {
4853
4923
  const authFailure = await authFailureMessage(response);
4854
4924
  const requestId = supportId(response);
4855
- if (response.status === 403 && authFailure === "ChatGPT sign-in needs to be renewed") throw new Error(`${await refusalMessage(response, editing)}${requestId}`);
4925
+ if (response.status === 403 && authFailure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.") throw new Error(`${await refusalMessage(response, editing)}${requestId}`);
4856
4926
  if (authFailure !== void 0) throw new Error(authFailure);
4857
4927
  if (response.status === 429) throw new Error(`${await limitMessage(response)}${requestId}`);
4858
4928
  throw new Error(`Codex image ${editing ? "edit" : "generation"} failed (HTTP ${response.status})${requestId}`);
@@ -10708,6 +10778,15 @@ function emailFromAccessToken(access) {
10708
10778
  const payload = decodeJwtPayload(access);
10709
10779
  return normalizeAccountEmail(payload?.["https://api.openai.com/profile"]?.email ?? payload?.email);
10710
10780
  }
10781
+ function sameOAuthAccount(previous, next) {
10782
+ if (typeof previous.accountId !== "string" || previous.accountId.length === 0 || previous.accountId !== next.accountId) return false;
10783
+ const old = decodeJwtPayload(previous.access);
10784
+ const fresh = decodeJwtPayload(next.access);
10785
+ const oldUser = old?.["https://api.openai.com/auth"]?.chatgpt_user_id;
10786
+ const freshUser = fresh?.["https://api.openai.com/auth"]?.chatgpt_user_id;
10787
+ if (typeof oldUser === "string" && oldUser && typeof freshUser === "string" && freshUser) return oldUser === freshUser;
10788
+ return typeof old?.sub === "string" && old.sub.length > 0 && old.sub === fresh?.sub;
10789
+ }
10711
10790
  /** Normalize the one non-secret account attribute that may cross the UI boundary. */
10712
10791
  function sanitizeOAuthCredential(value) {
10713
10792
  const credential = assertOAuthCredential$1(value);
@@ -10920,6 +10999,18 @@ var DshOAuthAccountVault = class {
10920
10999
  activeId() {
10921
11000
  return this.#enqueue(async () => (await this.#ensurePayload())?.activeId);
10922
11001
  }
11002
+ renew(id, credential, signal) {
11003
+ const next = sanitizeOAuthCredential(credential);
11004
+ return this.modifyAccount(id, (current) => {
11005
+ signal?.throwIfAborted();
11006
+ if (!sameOAuthAccount(current, next)) {
11007
+ const error = /* @__PURE__ */ new Error("Codex login did not match the saved account");
11008
+ error.code = "account-mismatch";
11009
+ throw error;
11010
+ }
11011
+ return next;
11012
+ });
11013
+ }
10923
11014
  add(label, credential) {
10924
11015
  return this.#enqueue(async () => {
10925
11016
  const normalizedLabel = normalizeLabel(label);
@@ -11166,14 +11257,16 @@ function createCodexAuthService(models, store, options = {}) {
11166
11257
  };
11167
11258
  },
11168
11259
  login(interaction, input = {}) {
11169
- if (input.label !== void 0) {
11260
+ if (input.label !== void 0 || input.renewId !== void 0) {
11170
11261
  if (accountVault === void 0 || createLoginModels === void 0) throw new Error("Codex multi-account is unavailable");
11171
11262
  return runLogin(async () => {
11172
11263
  const pending = createPendingStore();
11173
11264
  await createLoginModels(pending).login(PROVIDER$2, "oauth", interaction);
11174
11265
  const credential = pending.credential();
11175
11266
  if (credential === void 0) throw new Error("Codex login did not return credentials");
11176
- await accountVault.add(input.label, credential);
11267
+ interaction.signal?.throwIfAborted();
11268
+ if (input.renewId !== void 0) await accountVault.renew(input.renewId, credential, interaction.signal);
11269
+ else await accountVault.add(input.label, credential);
11177
11270
  });
11178
11271
  }
11179
11272
  return runLogin(() => models.login(PROVIDER$2, "oauth", interaction));
@@ -11317,10 +11410,12 @@ const PUBLIC_FAILURES = /* @__PURE__ */ new Set([
11317
11410
  "account-claim",
11318
11411
  "network",
11319
11412
  "token-exchange",
11320
- "callback"
11413
+ "callback",
11414
+ "account-mismatch"
11321
11415
  ]);
11322
11416
  const publicFailure = (kind) => PUBLIC_FAILURES.has(kind) ? kind : void 0;
11323
11417
  function classifyLoginFailure(error) {
11418
+ if (error?.code === "account-mismatch") return "account-mismatch";
11324
11419
  const message = error instanceof Error ? error.message : "";
11325
11420
  if (/token exchange failed/iu.test(message)) return "token-exchange";
11326
11421
  if (/fetch failed|\b(?:ECONN|ENOTFOUND|ETIMEDOUT|CERT_|socket|network)\b/iu.test(message)) return "network";
@@ -11349,9 +11444,10 @@ var CodexLoginCoordinator = class {
11349
11444
  ...active.view.phase === "failed" ? { failure: classifyLoginFailure(active.hostError) } : {}
11350
11445
  };
11351
11446
  }
11352
- async start({ method, label }) {
11447
+ async start({ method, label, renewId }) {
11353
11448
  if (!LOGIN_METHODS.has(method)) throw new Error(`unsupported Codex login method: ${String(method)}`);
11354
11449
  if (label !== void 0 && (typeof label !== "string" || label.trim().length === 0 || label.trim().length > 48)) throw new Error("unsupported Codex account label");
11450
+ if (renewId !== void 0 && (label !== void 0 || typeof renewId !== "string" || !/^[\w-]{1,128}$/u.test(renewId))) throw new Error("unsupported Codex renewal target");
11355
11451
  const active = this.#activeId === void 0 ? void 0 : this.#sessions.get(this.#activeId);
11356
11452
  if (active !== void 0 && !TERMINAL_PHASES.has(active.view.phase)) {
11357
11453
  active.view = {
@@ -11436,7 +11532,7 @@ var CodexLoginCoordinator = class {
11436
11532
  publishReady();
11437
11533
  }
11438
11534
  };
11439
- session.run = Promise.resolve().then(() => this.auth.login(interaction, label === void 0 ? {} : { label: label.trim() })).then(async () => {
11535
+ session.run = Promise.resolve().then(() => this.auth.login(interaction, renewId !== void 0 ? { renewId } : label === void 0 ? {} : { label: label.trim() })).then(async () => {
11440
11536
  if (controller.signal.aborted) return;
11441
11537
  const status = await this.auth.status();
11442
11538
  session.view = {
@@ -11459,7 +11555,8 @@ var CodexLoginCoordinator = class {
11459
11555
  return;
11460
11556
  }
11461
11557
  try {
11462
- if (label !== void 0) throw error;
11558
+ if (restrictionMessage(error?.message) !== void 0) throw error;
11559
+ if (label !== void 0 || renewId !== void 0) throw error;
11463
11560
  const status = await this.auth.status();
11464
11561
  if (status.authenticated === true) {
11465
11562
  session.view = {
@@ -11480,7 +11577,7 @@ var CodexLoginCoordinator = class {
11480
11577
  method,
11481
11578
  phase: "failed",
11482
11579
  authenticated: false,
11483
- error: "Codex login failed",
11580
+ error: restrictionMessage(error?.message) ?? "Codex login failed",
11484
11581
  failure: publicFailure(classifyLoginFailure(error))
11485
11582
  };
11486
11583
  session.hostError = error;
@@ -11554,7 +11651,8 @@ function createCodexRpcHandler(coordinator, options = {}) {
11554
11651
  if (endpoint === "login/start") {
11555
11652
  const started = await coordinator.start({
11556
11653
  method: input.method,
11557
- label: input.label
11654
+ label: input.label,
11655
+ renewId: input.renewId
11558
11656
  });
11559
11657
  if (input.openExternal !== true) return ok(started);
11560
11658
  const url = started.authUrl ?? started.deviceCode?.verificationUri;
@@ -12104,7 +12202,7 @@ function createOfficialModelCatalog(options = {}) {
12104
12202
  }
12105
12203
  });
12106
12204
  if (!current(flight) || accountId !== id) return false;
12107
- if (response.status !== 304 && !response.ok) throw new Error(`Codex model catalog failed (HTTP ${response.status})`);
12205
+ if (response.status !== 304 && !response.ok) throw new Error(await authFailureMessage(response) ?? `Codex model catalog failed (HTTP ${response.status})`);
12108
12206
  const raw = response.status === 304 ? rawCatalog : await response.json();
12109
12207
  if (!current(flight) || accountId !== id) return false;
12110
12208
  if (raw === void 0) throw new Error("Codex returned HTTP 304 without a cached model catalog");
@@ -12134,7 +12232,7 @@ function createOfficialModelCatalog(options = {}) {
12134
12232
  }, (error) => {
12135
12233
  if (flight.generation === generation) {
12136
12234
  refreshStatus = signal?.aborted ? "idle" : "failed";
12137
- if (!signal?.aborted) scheduleRetry(flight.generation);
12235
+ if (!signal?.aborted && !isRestrictionFailureMessage(error?.message)) scheduleRetry(flight.generation);
12138
12236
  }
12139
12237
  throw error;
12140
12238
  }).finally(() => {
@@ -12301,7 +12399,7 @@ function createCodexSearchProvider(options) {
12301
12399
  if (typeof access !== "string" || access.length === 0 || typeof accountId !== "string" || accountId.length === 0) throw new WebError("ChatGPT subscription is not signed in", "WEB_PROVIDER_CREDENTIAL_MISSING");
12302
12400
  const model = nonEmpty(options.resolveModel?.()) ?? DEFAULT_MODEL;
12303
12401
  const id = nonEmpty(options.resolveSessionId?.()) ?? randomUUID();
12304
- let response;
12402
+ let response, authFailure;
12305
12403
  try {
12306
12404
  const init = {
12307
12405
  method: "POST",
@@ -12333,9 +12431,10 @@ function createCodexSearchProvider(options) {
12333
12431
  for (let attempt = 0; attempt < 2; attempt++) {
12334
12432
  response = await fetchSearch(CODEX_SEARCH_URL, init);
12335
12433
  signal?.throwIfAborted();
12434
+ authFailure = response.ok ? void 0 : await authFailureMessage(response);
12336
12435
  const requestId = response.headers?.get?.("x-request-id") ?? response.headers?.get?.("cf-ray");
12337
12436
  const detail = `model=${model}, mode=${preferences.searchMode}, attempt=${attempt + 1}${typeof requestId === "string" && /^[a-zA-Z0-9._:-]{1,128}$/u.test(requestId) ? `, requestId=${requestId}` : ""}`;
12338
- const retry = attempt === 0 && RETRYABLE_STATUSES.has(response.status);
12437
+ const retry = authFailure === void 0 && attempt === 0 && RETRYABLE_STATUSES.has(response.status);
12339
12438
  diagnosticLog.log(response.ok ? "info" : "warn", "search", `Codex search HTTP ${response.status}${retry ? "; retrying once on the same source" : ""}`, detail);
12340
12439
  if (!retry) break;
12341
12440
  try {
@@ -12348,7 +12447,6 @@ function createCodexSearchProvider(options) {
12348
12447
  throw new WebError("Codex search request failed", "WEB_PROVIDER_ERROR", { cause: error });
12349
12448
  }
12350
12449
  if (!response.ok) {
12351
- const authFailure = await authFailureMessage(response);
12352
12450
  if (signal?.aborted) throw new WebError("Codex search aborted", "WEB_ABORTED", { cause: signal.reason });
12353
12451
  throw authFailure === "ChatGPT sign-in needs to be renewed" ? new WebError(authFailure, "WEB_PROVIDER_CREDENTIAL_MISSING") : authFailure !== void 0 ? new WebError(authFailure, "WEB_PROVIDER_ERROR") : new WebError(`Codex search request failed (HTTP ${response.status})`, "WEB_PROVIDER_ERROR");
12354
12452
  }
@@ -12571,12 +12669,12 @@ function createCodexFetchProvider(options) {
12571
12669
  activeSignal.throwIfAborted();
12572
12670
  diagnosticLog.info("fetch", `Codex webpage HTTP ${response.status}`, `attempt=${attempt}`);
12573
12671
  if (!response.ok) {
12574
- if (RETRYABLE.has(response.status) && attempt === 1) {
12672
+ const authFailure = await authFailureMessage(response);
12673
+ if (authFailure === void 0 && RETRYABLE.has(response.status) && attempt === 1) {
12575
12674
  await response.body?.cancel();
12576
12675
  await setTimeout$1(options.retryDelayMs ?? 250, void 0, { signal: activeSignal });
12577
12676
  continue;
12578
12677
  }
12579
- const authFailure = await authFailureMessage(response);
12580
12678
  throw new WebError(authFailure ?? `Codex webpage request failed (HTTP ${response.status})`, authFailure === "ChatGPT sign-in needs to be renewed" ? "WEB_PROVIDER_CREDENTIAL_MISSING" : "WEB_PROVIDER_ERROR");
12581
12679
  }
12582
12680
  const value = await response.json();
@@ -13805,7 +13903,7 @@ function createCodexUsageReader(options) {
13805
13903
  read({ force = false, signal } = {}) {
13806
13904
  if (signal?.aborted) return Promise.reject(signal.reason);
13807
13905
  if (failed !== void 0 && now() < failed.retryAt) return Promise.reject(new Error(failed.message));
13808
- if (!force && cached !== void 0 && now() - cached.fetchedAt < ttlFor(cached)) return Promise.resolve(structuredClone(cached));
13906
+ if (!force && failed === void 0 && cached !== void 0 && now() - cached.fetchedAt < ttlFor(cached)) return Promise.resolve(structuredClone(cached));
13809
13907
  return requests.run("read", async (sharedSignal) => {
13810
13908
  const currentGeneration = generation;
13811
13909
  try {
@@ -13895,7 +13993,7 @@ function createAccountUsageReader({ vault, createModels, fetch, expirySkewMs = 0
13895
13993
  const summarize = (error, signal) => {
13896
13994
  if (signal?.aborted) throw error;
13897
13995
  const message = error instanceof Error ? error.message : "";
13898
- return ["ChatGPT subscription is not signed in", "ChatGPT sign-in needs to be renewed"].includes(message) || message.includes("blocked this request") ? message : "Could not read ChatGPT usage";
13996
+ return isAccessFailureMessage(message) || ["ChatGPT subscription is not signed in", "ChatGPT sign-in needs to be renewed"].includes(message) || message.includes("blocked this request") ? message : "Could not read ChatGPT usage";
13899
13997
  };
13900
13998
  return Object.freeze({
13901
13999
  /** One entry per account: its usage reading, or the reason it could not be read. */
@@ -14014,7 +14112,10 @@ function createReportReader({ url, parse, label, getAuth, readCredential, fetch:
14014
14112
  available: false,
14015
14113
  fetchedAt: now()
14016
14114
  };
14017
- if (!response.ok) throw new Error(response.status === 401 ? SIGN_IN_RENEW : response.status === 403 ? await isBlockedByNetwork(response) ? REQUEST_BLOCKED : `ChatGPT does not offer the ${label} to this account` : `ChatGPT ${label} request failed (HTTP ${response.status})`);
14115
+ if (!response.ok) {
14116
+ const failure = await authFailureMessage(response);
14117
+ throw new Error(failure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." ? `ChatGPT does not offer the ${label} to this account` : failure ?? `ChatGPT ${label} request failed (HTTP ${response.status})`);
14118
+ }
14018
14119
  let body;
14019
14120
  try {
14020
14121
  body = await response.json();
@@ -14196,9 +14297,10 @@ function createConnectorsClient({ getAuth, readCredential, fetch: fetchRpc = fet
14196
14297
  }),
14197
14298
  signal: signal === void 0 ? timeout : AbortSignal.any([signal, timeout])
14198
14299
  });
14199
- if (response.status === 401) throw new Error(SIGN_IN_RENEW);
14200
- if (response.status === 403) throw new Error(await isBlockedByNetwork(response) ? REQUEST_BLOCKED : "ChatGPT does not offer connectors to this account");
14201
- if (!response.ok) throw new Error(`ChatGPT connectors request failed (HTTP ${response.status})`);
14300
+ if (!response.ok) {
14301
+ const failure = await authFailureMessage(response);
14302
+ throw new Error(failure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." ? "ChatGPT does not offer connectors to this account" : failure ?? `ChatGPT connectors request failed (HTTP ${response.status})`);
14303
+ }
14202
14304
  const message = await readRpc(response);
14203
14305
  if (record$1(message.error)) throw new Error(`Connector error: ${clip(oneLine(String(message.error.message ?? message.error.code ?? "failed")), 200)}`);
14204
14306
  return {
@@ -14573,6 +14675,7 @@ function createCodexQuotaRetryHandler({ usageReader, provider = "openai-codex",
14573
14675
  } catch {}
14574
14676
  };
14575
14677
  const handler = async ({ agent, turn, step, provider: requestProvider, failure, signal }, next) => {
14678
+ if (requestProvider === provider && isRestrictionFailureMessage(failure?.message)) return void 0;
14576
14679
  if (requestProvider !== provider || !isCodexRateLimit(failure) || !enabled()) return next();
14577
14680
  if (signal?.aborted) return void 0;
14578
14681
  let wakeRevision = wakeSignal.revision();
@@ -15642,7 +15745,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
15642
15745
  "ChatGPT sign-in needs to be renewed",
15643
15746
  REQUEST_BLOCKED
15644
15747
  ]);
15645
- const message = error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage";
15748
+ const message = error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage";
15646
15749
  return publicError("internal", message);
15647
15750
  }
15648
15751
  if (endpoint === "usage/profile") try {
@@ -15661,7 +15764,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
15661
15764
  "ChatGPT sign-in needs to be renewed",
15662
15765
  REQUEST_BLOCKED
15663
15766
  ]);
15664
- return publicError("internal", error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage profile");
15767
+ return publicError("internal", error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage profile");
15665
15768
  }
15666
15769
  if (endpoint === "usage/accounts") try {
15667
15770
  signal.throwIfAborted();
@@ -15692,7 +15795,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
15692
15795
  "ChatGPT sign-in needs to be renewed",
15693
15796
  REQUEST_BLOCKED
15694
15797
  ]);
15695
- return publicError("internal", error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage history");
15798
+ return publicError("internal", error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage history");
15696
15799
  }
15697
15800
  if (endpoint === "reset-credit/inspect" || endpoint === "reset-credit/prepare" || endpoint === "reset-credit/consume") try {
15698
15801
  signal.throwIfAborted();
@@ -15723,7 +15826,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
15723
15826
  "The signed-in ChatGPT account changed"
15724
15827
  ]);
15725
15828
  const fallback = endpoint === "reset-credit/inspect" ? "Could not read quota reset details" : endpoint === "reset-credit/prepare" ? "Could not prepare a quota reset" : "Could not use the quota reset";
15726
- const message = error instanceof Error && known.has(error.message) ? error.message : fallback;
15829
+ const message = error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : fallback;
15727
15830
  return publicError("internal", message);
15728
15831
  }
15729
15832
  const result = await authHandler(endpoint, payload, signal);
@@ -15738,6 +15841,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
15738
15841
  () => onAccountChanged?.()
15739
15842
  ];
15740
15843
  if (endpoint === "logout") tasks.push(() => usageReader.clear(), () => accountUsageReader?.clear());
15844
+ if (endpoint === "login/status") tasks.push(() => accountUsageReader?.clear());
15741
15845
  if (endpoint === "account/remove" && typeof payload?.id === "string") tasks.push(() => usageReader.clearScope(payload.id));
15742
15846
  const outcomes = await Promise.allSettled(tasks.map((task) => Promise.resolve().then(task)));
15743
15847
  const catalogOutcomes = endpoint === "logout" ? [] : await Promise.allSettled([Promise.resolve().then(() => modelCatalog?.initialize())]);
@@ -17547,7 +17651,7 @@ function apply(ctx, config = {}) {
17547
17651
  }, next).finally(() => activeQuotaRetries.delete(tracked));
17548
17652
  activeQuotaRetries.add(tracked);
17549
17653
  return tracked;
17550
- });
17654
+ }, true);
17551
17655
  ctx.effect(() => async () => {
17552
17656
  disposeQuotaRetry();
17553
17657
  quotaRetryLifetime.abort(/* @__PURE__ */ new Error("codex-subscription quota retry disposed"));
package/locale/en.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Codex Subscription",
4
- "description": "Use your ChatGPT / Codex subscription in DSH. Sign in to access models, track quota, search the web and generate images. No API key required. Beta: control DSH from the ChatGPT mobile app."
4
+ "description": "Use your ChatGPT / Codex subscription for models, quota, web search and images in DSH. No API key required. Includes voice chat and phone remote control (Beta).",
5
+ "detail": "docs/plugin/DETAIL.md"
5
6
  }
6
7
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Codex 订阅",
4
- "description": "在 DSH 中使用 ChatGPT / Codex 订阅。登录即可选模型、查额度、搜索和生图,无需 API Key。还能用 ChatGPT 手机 App 远程控制 DSH(Beta)。"
4
+ "description": "在 DSH 中使用 ChatGPT / Codex 订阅:模型、额度、搜索与生图,无需 API Key。支持语音对话和手机远程控制(Beta)。",
5
+ "detail": "docs/plugin/DETAIL.zh.md"
5
6
  }
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-codex-subscription",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "description": "Use ChatGPT and Codex subscriptions in DeepSeek Harness with OAuth, quota, safe resets, web search, images and Fast mode, and control DSH from the ChatGPT mobile app (Beta)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -15,6 +15,7 @@
15
15
  "lib/*.js",
16
16
  "native/linux-voice-helper.py",
17
17
  "locale/*.json",
18
+ "docs/plugin/*.md",
18
19
  "cordis.patch.yml",
19
20
  "README.md",
20
21
  "README.en.md",
@@ -95,7 +96,7 @@
95
96
  "@deepseek-ai/dsh-tools": "0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-alpha.1 || 0.2.1-alpha.2 || 0.2.1-alpha.3 || 0.2.1-alpha.4 || 0.2.1-alpha.5 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-alpha.2",
96
97
  "@deepseek-ai/dsh-web": "0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-alpha.1 || 0.2.1-alpha.2 || 0.2.1-alpha.3 || 0.2.1-alpha.4 || 0.2.1-alpha.5 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-alpha.2",
97
98
  "@deepseek-ai/schemastery": "3.18.1 || ^3.18.2 || 3.18.6-alpha.1",
98
- "@earendil-works/pi-ai": "0.85.1 || 0.87.1 || 1.1.0 || 1.2.0 || 1.3.0 || 1.4.0",
99
+ "@earendil-works/pi-ai": "0.85.1 || 0.87.1 || 1.1.0 || 1.2.0 || 1.3.0 || 1.4.0 || 1.5.0",
99
100
  "react": "^18.2.0",
100
101
  "react-dom": "^18.2.0"
101
102
  },