@kenkaiiii/gg-ai 5.19.2 → 5.19.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/dist/index.cjs CHANGED
@@ -309,6 +309,9 @@ function providerGuidance(provider, message, statusCode) {
309
309
  if (statusCode === 503 || lower.includes("service unavailable")) {
310
310
  return `${name} is temporarily unavailable. Retry shortly \u2014 not a GG Coder issue.`;
311
311
  }
312
+ if (statusCode === 507 || lower.includes("exceeded request buffer limit while retrying upstream")) {
313
+ return `${name}'s proxy could not retry this large request. GG Coder already retried automatically \u2014 compact the conversation, then retry.`;
314
+ }
312
315
  if (statusCode === 500 || lower.includes("server_error") || lower.includes("500") && lower.includes("internal server error")) {
313
316
  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.`;
314
317
  }
@@ -321,6 +324,9 @@ function providerGuidance(provider, message, statusCode) {
321
324
  if (lower.includes("context_length_exceeded") || lower.includes("prompt is too long")) {
322
325
  return `Context window for this ${name} model is full. Compact the conversation to shrink history, or start a new session.`;
323
326
  }
327
+ if (lower.includes("many-image request") || lower.includes("image dimensions") && lower.includes("max allowed size")) {
328
+ return `An image in conversation history exceeds ${name}'s many-image limit. Restart GG Coder so restored images are resized, then retry; if it persists, start a new session.`;
329
+ }
324
330
  if (statusCode === 413 || lower.includes("request_too_large") || lower.includes("request exceeds the maximum size")) {
325
331
  return `The request to ${name} is too large. Compact the conversation to shrink history, or start a new session.`;
326
332
  }
@@ -2245,6 +2251,7 @@ function toError2(err, provider = "openai") {
2245
2251
 
2246
2252
  // src/providers/openai-codex.ts
2247
2253
  var import_node_os = __toESM(require("os"), 1);
2254
+ var zstd = __toESM(require("@bokuweb/zstd-wasm"), 1);
2248
2255
 
2249
2256
  // src/utils/sse.ts
2250
2257
  function parseSseBuffer(buffer) {
@@ -2300,6 +2307,50 @@ function extractRequestIdFromMessage(message) {
2300
2307
  // src/providers/openai-codex.ts
2301
2308
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
2302
2309
  var CODEX_CLIENT_VERSION = "0.144.1";
2310
+ var CODEX_REQUEST_COMPRESSION_MIN_BYTES = 16 * 1024;
2311
+ var zstdInitPromise;
2312
+ async function encodeCodexRequest(body) {
2313
+ const json = JSON.stringify(body);
2314
+ const raw = new TextEncoder().encode(json);
2315
+ if (raw.byteLength < CODEX_REQUEST_COMPRESSION_MIN_BYTES) {
2316
+ return {
2317
+ body: json,
2318
+ compressed: false,
2319
+ rawBytes: raw.byteLength,
2320
+ encodedBytes: raw.byteLength
2321
+ };
2322
+ }
2323
+ try {
2324
+ zstdInitPromise ??= zstd.init();
2325
+ await zstdInitPromise;
2326
+ const compressed = Uint8Array.from(zstd.compress(raw));
2327
+ if (compressed.byteLength >= raw.byteLength) {
2328
+ return {
2329
+ body: json,
2330
+ compressed: false,
2331
+ rawBytes: raw.byteLength,
2332
+ encodedBytes: raw.byteLength
2333
+ };
2334
+ }
2335
+ return {
2336
+ body: compressed,
2337
+ compressed: true,
2338
+ rawBytes: raw.byteLength,
2339
+ encodedBytes: compressed.byteLength
2340
+ };
2341
+ } catch (error) {
2342
+ providerDiag("codex_request_compression_failed", {
2343
+ error: error instanceof Error ? error.message : String(error),
2344
+ rawBytes: raw.byteLength
2345
+ });
2346
+ return {
2347
+ body: json,
2348
+ compressed: false,
2349
+ rawBytes: raw.byteLength,
2350
+ encodedBytes: raw.byteLength
2351
+ };
2352
+ }
2353
+ }
2303
2354
  function usesResponsesLite(model) {
2304
2355
  return model.startsWith("gpt-5.6-");
2305
2356
  }
@@ -2377,10 +2428,17 @@ async function* runStream3(options) {
2377
2428
  headers["session_id"] = transportSessionId;
2378
2429
  headers["x-client-request-id"] = transportSessionId;
2379
2430
  }
2431
+ const encodedRequest = await encodeCodexRequest(body);
2432
+ if (encodedRequest.compressed) headers["Content-Encoding"] = "zstd";
2433
+ providerDiag("codex_request_body", {
2434
+ rawBytes: encodedRequest.rawBytes,
2435
+ encodedBytes: encodedRequest.encodedBytes,
2436
+ compressed: encodedRequest.compressed
2437
+ });
2380
2438
  const response = await fetch(url, {
2381
2439
  method: "POST",
2382
2440
  headers,
2383
- body: JSON.stringify(body),
2441
+ body: encodedRequest.body,
2384
2442
  signal: options.signal
2385
2443
  });
2386
2444
  if (!response.ok) {