dsh-codex-subscription 3.2.19 → 3.2.20

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
@@ -8,6 +8,7 @@ import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep, win
8
8
  import { request } from "node:https";
9
9
  import { AsyncLocalStorage } from "node:async_hooks";
10
10
  import { promisify } from "node:util";
11
+ import { zstdDecompress } from "node:zlib";
11
12
  import { HttpsProxyAgent } from "https-proxy-agent";
12
13
  import WebSocket from "ws";
13
14
  import { ProxyAgent, getGlobalDispatcher } from "undici";
@@ -1201,6 +1202,7 @@ function safeAttempt(value = {}) {
1201
1202
  ...choices.has(value.requestedTransport) ? { requestedTransport: value.requestedTransport } : {},
1202
1203
  ...typeof value.model === "string" && /^gpt-[a-z0-9][a-z0-9.-]{0,63}$/u.test(value.model) ? { model: value.model } : {},
1203
1204
  ...fetchPaths.has(value.fetchPath) ? { fetchPath: value.fetchPath } : {},
1205
+ ...value.requestCompression === "zstd-decoded" ? { requestCompression: value.requestCompression } : {},
1204
1206
  ...value.failure === "context-overflow" ? { failure: value.failure } : {},
1205
1207
  ...Number.isInteger(value.httpStatus) && value.httpStatus >= 100 && value.httpStatus <= 599 ? { httpStatus: value.httpStatus } : {},
1206
1208
  ...typeof value.cloudCompactionRequested === "boolean" ? { cloudCompactionRequested: value.cloudCompactionRequested } : {},
@@ -1485,6 +1487,7 @@ const diagnosticLog = createDiagnosticLog();
1485
1487
  //#endregion
1486
1488
  //#region src/oauth-network.js
1487
1489
  const execFileAsync = promisify(execFile);
1490
+ const decompressZstd = promisify(zstdDecompress);
1488
1491
  const CODEX_AUTH_HOST = "auth.openai.com";
1489
1492
  const CODEX_SUBSCRIPTION_HOST = "chatgpt.com";
1490
1493
  const CODEX_MODEL_SSE_PATH = "/backend-api/codex/responses";
@@ -1701,6 +1704,22 @@ function fetchThroughProxy(input, init, proxyUrl, tls = {}) {
1701
1704
  request$1.end();
1702
1705
  });
1703
1706
  }
1707
+ async function uncompressedModelRequest(input, init) {
1708
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
1709
+ if ((init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase() !== "POST" || headers.get("content-encoding")?.trim().toLowerCase() !== "zstd") return init;
1710
+ const signal = init?.signal ?? input?.signal;
1711
+ signal?.throwIfAborted();
1712
+ const compressed = init?.body ?? (input instanceof Request ? await input.clone().arrayBuffer() : void 0);
1713
+ const body = await decompressZstd(compressed);
1714
+ signal?.throwIfAborted();
1715
+ headers.delete("content-encoding");
1716
+ headers.delete("content-length");
1717
+ return {
1718
+ ...init,
1719
+ headers,
1720
+ body
1721
+ };
1722
+ }
1704
1723
  async function fetchInCodexScope(scope, fetchBeforeScope, input, init) {
1705
1724
  if (scope === void 0) return fetchBeforeScope(input, init);
1706
1725
  const { options: scopedOptions, allowedHosts, resolved } = scope;
@@ -1732,6 +1751,11 @@ async function fetchInCodexScope(scope, fetchBeforeScope, input, init) {
1732
1751
  } catch {}
1733
1752
  let response;
1734
1753
  try {
1754
+ if (scopedOptions.requestFetch && target.origin === `https://${CODEX_SUBSCRIPTION_HOST}` && target.pathname === CODEX_MODEL_SSE_PATH) {
1755
+ const decoded = await uncompressedModelRequest(input, init);
1756
+ if (decoded !== init) scopedOptions.onModelRequestCompression?.("zstd-decoded");
1757
+ init = decoded;
1758
+ }
1735
1759
  if (dedicatedProxy && !route.url) throw new TypeError("Invalid DSH_CODEX_SSE_PROXY. Use an HTTP or HTTPS CONNECT proxy.");
1736
1760
  if (hostModelFetch) if (!route.url || init?.dispatcher) response = await fetchBeforeScope(input, init);
1737
1761
  else {
@@ -3092,6 +3116,9 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
3092
3116
  onModelFetchPath(fetchPath) {
3093
3117
  attempt.configure({ fetchPath });
3094
3118
  },
3119
+ onModelRequestCompression(requestCompression) {
3120
+ attempt.configure({ requestCompression });
3121
+ },
3095
3122
  onModelHttpStatus(status) {
3096
3123
  attempt.response(status);
3097
3124
  },
@@ -4889,7 +4916,7 @@ function inheritedOriginalImageRef(session, assetId) {
4889
4916
  }
4890
4917
  //#endregion
4891
4918
  //#region src/version.js
4892
- const PACKAGE_VERSION = "3.2.19";
4919
+ const PACKAGE_VERSION = "3.2.20";
4893
4920
  const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
4894
4921
  //#endregion
4895
4922
  //#region src/image-original-store.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-codex-subscription",
3
- "version": "3.2.19",
3
+ "version": "3.2.20",
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",