dsh-codex-subscription 3.2.19 → 3.2.21

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/client.js CHANGED
@@ -1249,10 +1249,11 @@ window.__ModuleLoader__.load({
1249
1249
  "sketch/result",
1250
1250
  "sketch/disconnect"
1251
1251
  ]);
1252
- function createSubscriptionRpcClient(transport) {
1252
+ function createSubscriptionRpcClient(transport, incidents) {
1253
1253
  return Object.freeze({ call(channel, endpoint, payload, signal) {
1254
1254
  if (channel !== "/codex-subscription" || !RPC_ENDPOINTS.includes(endpoint)) throw new Error("Invalid subscription RPC target");
1255
- return transport.call("/api", `codex-subscription/${endpoint}`, payload, signal);
1255
+ const send = () => transport.call("/api", `codex-subscription/${endpoint}`, payload, signal);
1256
+ return incidents ? incidents.observeRpc(endpoint, send, signal) : send();
1256
1257
  } });
1257
1258
  }
1258
1259
  function unwrap(response) {
@@ -11779,7 +11780,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
11779
11780
  }
11780
11781
  //#endregion
11781
11782
  //#region src/version.js
11782
- const PACKAGE_VERSION = "3.2.19";
11783
+ const PACKAGE_VERSION = "3.2.21";
11783
11784
  //#endregion
11784
11785
  //#region src/client-recovery.js
11785
11786
  async function recoveryCall(rpc, endpoint, payload = {}, timeoutMs = endpoint === "usage" || endpoint.startsWith("usage/") ? 3e4 : 1e4) {
@@ -12376,11 +12377,12 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12376
12377
  }, item.id))
12377
12378
  });
12378
12379
  }
12379
- function CodexModelSelect({ locked, available, directory, load, select, preference, t }) {
12380
+ function CodexModelSelect({ locked, available, directory, load, select, preference, t, openPickerTrace }) {
12380
12381
  const state = (0, react.useSyncExternalStore)(directory.subscribe, directory.getSnapshot);
12381
12382
  const preferenceSnapshot = usePreferenceSnapshot(preference);
12382
12383
  const [open, setOpen] = (0, react.useState)(false);
12383
12384
  const [pane, setPane] = (0, react.useState)("root");
12385
+ const trace = (0, react.useRef)(null);
12384
12386
  const [query, setQuery] = (0, react.useState)("");
12385
12387
  const menuRef = (0, react.useRef)(null);
12386
12388
  const triggerRef = (0, react.useRef)(null);
@@ -12480,6 +12482,8 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12480
12482
  verbositySupported
12481
12483
  ]);
12482
12484
  const close = (restoreFocus = false) => {
12485
+ trace.current?.("closed");
12486
+ trace.current = null;
12483
12487
  setOpen(false);
12484
12488
  setPane("root");
12485
12489
  setQuery("");
@@ -12499,11 +12503,13 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12499
12503
  if (accepted) close(true);
12500
12504
  };
12501
12505
  const chooseModel = (selection) => {
12506
+ trace.current?.("activated");
12502
12507
  if (state.current?.provider === selection.provider && state.current.model === selection.model) {
12508
+ trace.current?.("already-selected");
12503
12509
  close(true);
12504
12510
  return;
12505
12511
  }
12506
- select(selection).then(settleSelection);
12512
+ select(selection, trace.current).then(settleSelection);
12507
12513
  };
12508
12514
  const chooseEffort = (effort) => {
12509
12515
  if (state.current === null) return;
@@ -12525,12 +12531,13 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12525
12531
  close(true);
12526
12532
  preference.set({ [OUTPUT_VERBOSITY_FIELD]: outputVerbosity });
12527
12533
  };
12528
- const option = ({ key, label, description, selected, disabled, onClick }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
12534
+ const option = ({ key, label, description, selected, disabled, onClick, onPointerDown }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
12529
12535
  type: "button",
12530
12536
  role: "menuitemradio",
12531
12537
  "aria-checked": selected,
12532
12538
  className: "codexModelSelectOption",
12533
12539
  disabled,
12540
+ onPointerDown,
12534
12541
  onClick,
12535
12542
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
12536
12543
  className: "codexModelSelectOptionCopy",
@@ -12551,6 +12558,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12551
12558
  role: "menuitem",
12552
12559
  className: "codexModelSelectCell",
12553
12560
  onClick: () => {
12561
+ if (target === "model") trace.current?.("model-list");
12554
12562
  setQuery("");
12555
12563
  setPane(target);
12556
12564
  },
@@ -12627,6 +12635,7 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12627
12635
  label: model.name,
12628
12636
  selected: state.current?.provider === entry.id && state.current.model === model.id,
12629
12637
  disabled: busy,
12638
+ onPointerDown: () => trace.current?.("pointer-down"),
12630
12639
  onClick: () => chooseModel({
12631
12640
  provider: entry.id,
12632
12641
  model: model.id
@@ -12699,6 +12708,9 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12699
12708
  role: pane === "model" ? "group" : "menu",
12700
12709
  "aria-label": t("modelMenuAria"),
12701
12710
  "aria-busy": state.status === "loading" || busy,
12711
+ onMouseDown: (event) => {
12712
+ if (pane === "model" && event.button === 0 && event.target.closest?.("button[role=\"menuitemradio\"]") && event.currentTarget.ownerDocument.activeElement?.getAttribute("role") === "searchbox") event.preventDefault();
12713
+ },
12702
12714
  onKeyDown: (event) => {
12703
12715
  if (event.key !== "Escape") return;
12704
12716
  event.preventDefault();
@@ -12726,7 +12738,16 @@ a.codexVoiceCall{display:flex;align-items:center;justify-content:center;box-sizi
12726
12738
  "aria-controls": open ? `${id}-menu` : void 0,
12727
12739
  title: fast ? `${modelLabel} · ${t(speedKey)}` : modelLabel,
12728
12740
  disabled: locked,
12729
- onClick: () => open ? close() : (setPane("root"), setOpen(true), load()),
12741
+ onClick: () => {
12742
+ if (open) {
12743
+ close();
12744
+ return;
12745
+ }
12746
+ trace.current = openPickerTrace?.();
12747
+ setPane("root");
12748
+ setOpen(true);
12749
+ load();
12750
+ },
12730
12751
  children: [
12731
12752
  fast && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ForwardRef, {
12732
12753
  className: "codexModelSelectBolt",
@@ -17359,6 +17380,7 @@ void main(){
17359
17380
  error: report.error
17360
17381
  } : {},
17361
17382
  ...!report.client?.topology?.length ? { clientDiagnostics: "unavailable" } : {},
17383
+ ...report.client?.incidents && Object.keys(report.client.incidents).length ? { clientIncidents: report.client.incidents } : {},
17362
17384
  account: report.account?.status,
17363
17385
  catalog: report.catalog,
17364
17386
  configuration,
@@ -20937,6 +20959,141 @@ void main(){
20937
20959
  return typeof navigation?.openBundle === "function" ? () => navigation.openBundle(name) : void 0;
20938
20960
  }
20939
20961
  //#endregion
20962
+ //#region src/client-incident-diagnostics.js
20963
+ const knownCodes = /* @__PURE__ */ new Set([
20964
+ "unavailable",
20965
+ "invalid-input",
20966
+ "not-found",
20967
+ "internal",
20968
+ "operation-error",
20969
+ "timeout"
20970
+ ]);
20971
+ const pickerStages = /* @__PURE__ */ new Set([
20972
+ "opened",
20973
+ "model-list",
20974
+ "pointer-down",
20975
+ "activated",
20976
+ "already-selected",
20977
+ "submitted",
20978
+ "rejected",
20979
+ "threw",
20980
+ "matched-at-return",
20981
+ "different-at-return",
20982
+ "readback-unavailable",
20983
+ "closed"
20984
+ ]);
20985
+ function createClientIncidentDiagnostics(now = Date.now) {
20986
+ const failures = /* @__PURE__ */ new Map();
20987
+ const pending = /* @__PURE__ */ new Set();
20988
+ const modelPicker = [];
20989
+ let activeCount = 0;
20990
+ let menuId = 0;
20991
+ let pickerTruncated = false;
20992
+ return {
20993
+ openPicker() {
20994
+ const id = ++menuId;
20995
+ const record = (stage) => {
20996
+ if (!pickerStages.has(stage)) return;
20997
+ modelPicker.push({
20998
+ id,
20999
+ stage,
21000
+ at: now()
21001
+ });
21002
+ if (modelPicker.length > 32) {
21003
+ modelPicker.shift();
21004
+ pickerTruncated = true;
21005
+ }
21006
+ };
21007
+ record("opened");
21008
+ return record;
21009
+ },
21010
+ async observeRpc(endpoint, run, signal) {
21011
+ if (!RPC_ENDPOINTS.includes(endpoint) || endpoint === "diagnostics") return run();
21012
+ const start = now();
21013
+ const entry = {
21014
+ endpoint,
21015
+ start
21016
+ };
21017
+ activeCount++;
21018
+ if (pending.size < 32) pending.add(entry);
21019
+ let active = true;
21020
+ const finish = () => {
21021
+ if (active) {
21022
+ active = false;
21023
+ activeCount--;
21024
+ pending.delete(entry);
21025
+ }
21026
+ };
21027
+ const fail = (kind, code) => failures.set(endpoint, {
21028
+ endpoint,
21029
+ kind,
21030
+ at: now(),
21031
+ durationMs: Math.max(0, now() - start),
21032
+ ...knownCodes.has(code) ? { code } : {}
21033
+ });
21034
+ const aborted = () => {
21035
+ finish();
21036
+ if (signal.reason?.code === "timeout" || signal.reason?.name === "TimeoutError") fail("timeout");
21037
+ };
21038
+ if (signal?.aborted) aborted();
21039
+ else signal?.addEventListener("abort", aborted, { once: true });
21040
+ try {
21041
+ const result = await run();
21042
+ if (!signal?.aborted) if (result?.ok !== true) fail(result?.ok === false ? "rpc-rejected" : "invalid-response", result?.error?.code);
21043
+ else {
21044
+ const last = failures.get(endpoint);
21045
+ if (last && last.nextSuccessAt === void 0) last.nextSuccessAt = now();
21046
+ }
21047
+ return result;
21048
+ } catch (error) {
21049
+ if (!signal?.aborted) fail("transport-threw", error?.code);
21050
+ throw error;
21051
+ } finally {
21052
+ signal?.removeEventListener("abort", aborted);
21053
+ finish();
21054
+ }
21055
+ },
21056
+ snapshot() {
21057
+ const at = now();
21058
+ const active = Array.from(pending).slice(0, 32);
21059
+ return {
21060
+ ...failures.size ? { rpcFailures: Array.from(failures.values(), (value) => ({ ...value })) } : {},
21061
+ ...active.length ? { inFlight: active.map(({ endpoint, start }) => ({
21062
+ endpoint,
21063
+ ageMs: Math.max(0, at - start)
21064
+ })) } : {},
21065
+ ...modelPicker.length ? { modelPicker: modelPicker.slice() } : {},
21066
+ ...pickerTruncated || activeCount > active.length ? { truncated: true } : {}
21067
+ };
21068
+ }
21069
+ };
21070
+ }
21071
+ async function selectWithDiagnostics(directory, selection, record) {
21072
+ record?.("submitted");
21073
+ let result;
21074
+ try {
21075
+ result = await directory.select(selection);
21076
+ } catch {
21077
+ record?.("threw");
21078
+ return false;
21079
+ }
21080
+ if (result?.ok === false) {
21081
+ record?.("rejected");
21082
+ return false;
21083
+ }
21084
+ if (record) {
21085
+ let current;
21086
+ try {
21087
+ current = directory.store.getSnapshot().current;
21088
+ } catch {
21089
+ record("readback-unavailable");
21090
+ return true;
21091
+ }
21092
+ record(current?.provider === selection.provider && current?.model === selection.model && (selection.reasoningEffort === void 0 || current?.reasoningEffort === selection.reasoningEffort) ? "matched-at-return" : "different-at-return");
21093
+ }
21094
+ return true;
21095
+ }
21096
+ //#endregion
20940
21097
  //#region src/diagnostic-checks.js
20941
21098
  const states = /* @__PURE__ */ new Set([
20942
21099
  "pass",
@@ -21043,7 +21200,7 @@ void main(){
21043
21200
  };
21044
21201
  });
21045
21202
  }
21046
- function createHostDiagnostics() {
21203
+ function createHostDiagnostics(incidents) {
21047
21204
  const scopes = /* @__PURE__ */ new Map();
21048
21205
  let sequence = 0;
21049
21206
  return {
@@ -21088,6 +21245,7 @@ void main(){
21088
21245
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
21089
21246
  checks,
21090
21247
  topology,
21248
+ incidents: incidents?.snapshot(),
21091
21249
  truncated: scopes.size > active.length,
21092
21250
  interpretation: "host-selection-not-visual-or-execution-proof"
21093
21251
  };
@@ -21659,7 +21817,8 @@ void main(){
21659
21817
  unsubscribe();
21660
21818
  };
21661
21819
  }, "codex-subscription: browser voice conversation"));
21662
- const diagnostics = createHostDiagnostics();
21820
+ const incidents = createClientIncidentDiagnostics();
21821
+ const diagnostics = createHostDiagnostics(incidents);
21663
21822
  ctx.effect(() => diagnostics.register(ctx.slots), "codex-subscription: host inspection");
21664
21823
  const imageViewer = new SubscriptionImageViewerService();
21665
21824
  ctx.effect(() => ctx.locale.register(NS, dictionaries), "codex-subscription: copy");
@@ -21670,7 +21829,7 @@ void main(){
21670
21829
  document.head.append(tag);
21671
21830
  return () => tag.remove();
21672
21831
  }, "codex-subscription: style");
21673
- const rpc = createSubscriptionRpcClient(ctx.get("connection").rpc);
21832
+ const rpc = createSubscriptionRpcClient(ctx.get("connection").rpc, incidents);
21674
21833
  const preference = createPreferenceController(rpc);
21675
21834
  const quotaUsage = quotaUsageController(rpc);
21676
21835
  ctx.effect(() => {
@@ -21784,14 +21943,8 @@ void main(){
21784
21943
  load: () => {
21785
21944
  if (available) directory.load().catch(() => {});
21786
21945
  },
21787
- select: async (selection) => {
21788
- if (!available) return false;
21789
- try {
21790
- return (await directory.select(selection))?.ok !== false;
21791
- } catch {
21792
- return false;
21793
- }
21794
- }
21946
+ openPickerTrace: incidents.openPicker,
21947
+ select: async (selection, trace) => available && selectWithDiagnostics(directory, selection, trace)
21795
21948
  };
21796
21949
  }, CodexModelSelect, CodexNativeModelOptions, CodexModelLabel, () => watchComposerModelPickerConflict(scope.get("remote.pluginManager"), scope.get("remote"), preference.setComposerModelPickerConflict, (refresh) => scope.on("connection/reset", refresh)));
21797
21950
  };
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.21";
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.21",
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",