@kenkaiiii/gg-ai 5.19.2 → 5.19.3

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/dist/index.js CHANGED
@@ -249,6 +249,9 @@ function providerGuidance(provider, message, statusCode) {
249
249
  if (statusCode === 503 || lower.includes("service unavailable")) {
250
250
  return `${name} is temporarily unavailable. Retry shortly \u2014 not a GG Coder issue.`;
251
251
  }
252
+ if (statusCode === 507 || lower.includes("exceeded request buffer limit while retrying upstream")) {
253
+ return `${name}'s proxy could not retry this large request. GG Coder already retried automatically \u2014 compact the conversation, then retry.`;
254
+ }
252
255
  if (statusCode === 500 || lower.includes("server_error") || lower.includes("500") && lower.includes("internal server error")) {
253
256
  return status ? `This is an error from ${name}, not GG Coder. Retry \u2014 if it keeps happening, check ${status}.` : `This is an error from ${name}, not GG Coder. Retry \u2014 if it keeps happening, try a different model via the model selector.`;
254
257
  }
@@ -2185,6 +2188,7 @@ function toError2(err, provider = "openai") {
2185
2188
 
2186
2189
  // src/providers/openai-codex.ts
2187
2190
  import os from "os";
2191
+ import * as zstd from "@bokuweb/zstd-wasm";
2188
2192
 
2189
2193
  // src/utils/sse.ts
2190
2194
  function parseSseBuffer(buffer) {
@@ -2240,6 +2244,50 @@ function extractRequestIdFromMessage(message) {
2240
2244
  // src/providers/openai-codex.ts
2241
2245
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
2242
2246
  var CODEX_CLIENT_VERSION = "0.144.1";
2247
+ var CODEX_REQUEST_COMPRESSION_MIN_BYTES = 16 * 1024;
2248
+ var zstdInitPromise;
2249
+ async function encodeCodexRequest(body) {
2250
+ const json = JSON.stringify(body);
2251
+ const raw = new TextEncoder().encode(json);
2252
+ if (raw.byteLength < CODEX_REQUEST_COMPRESSION_MIN_BYTES) {
2253
+ return {
2254
+ body: json,
2255
+ compressed: false,
2256
+ rawBytes: raw.byteLength,
2257
+ encodedBytes: raw.byteLength
2258
+ };
2259
+ }
2260
+ try {
2261
+ zstdInitPromise ??= zstd.init();
2262
+ await zstdInitPromise;
2263
+ const compressed = Uint8Array.from(zstd.compress(raw));
2264
+ if (compressed.byteLength >= raw.byteLength) {
2265
+ return {
2266
+ body: json,
2267
+ compressed: false,
2268
+ rawBytes: raw.byteLength,
2269
+ encodedBytes: raw.byteLength
2270
+ };
2271
+ }
2272
+ return {
2273
+ body: compressed,
2274
+ compressed: true,
2275
+ rawBytes: raw.byteLength,
2276
+ encodedBytes: compressed.byteLength
2277
+ };
2278
+ } catch (error) {
2279
+ providerDiag("codex_request_compression_failed", {
2280
+ error: error instanceof Error ? error.message : String(error),
2281
+ rawBytes: raw.byteLength
2282
+ });
2283
+ return {
2284
+ body: json,
2285
+ compressed: false,
2286
+ rawBytes: raw.byteLength,
2287
+ encodedBytes: raw.byteLength
2288
+ };
2289
+ }
2290
+ }
2243
2291
  function usesResponsesLite(model) {
2244
2292
  return model.startsWith("gpt-5.6-");
2245
2293
  }
@@ -2317,10 +2365,17 @@ async function* runStream3(options) {
2317
2365
  headers["session_id"] = transportSessionId;
2318
2366
  headers["x-client-request-id"] = transportSessionId;
2319
2367
  }
2368
+ const encodedRequest = await encodeCodexRequest(body);
2369
+ if (encodedRequest.compressed) headers["Content-Encoding"] = "zstd";
2370
+ providerDiag("codex_request_body", {
2371
+ rawBytes: encodedRequest.rawBytes,
2372
+ encodedBytes: encodedRequest.encodedBytes,
2373
+ compressed: encodedRequest.compressed
2374
+ });
2320
2375
  const response = await fetch(url, {
2321
2376
  method: "POST",
2322
2377
  headers,
2323
- body: JSON.stringify(body),
2378
+ body: encodedRequest.body,
2324
2379
  signal: options.signal
2325
2380
  });
2326
2381
  if (!response.ok) {