@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.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
  }
@@ -261,6 +264,9 @@ function providerGuidance(provider, message, statusCode) {
261
264
  if (lower.includes("context_length_exceeded") || lower.includes("prompt is too long")) {
262
265
  return `Context window for this ${name} model is full. Compact the conversation to shrink history, or start a new session.`;
263
266
  }
267
+ if (lower.includes("many-image request") || lower.includes("image dimensions") && lower.includes("max allowed size")) {
268
+ 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.`;
269
+ }
264
270
  if (statusCode === 413 || lower.includes("request_too_large") || lower.includes("request exceeds the maximum size")) {
265
271
  return `The request to ${name} is too large. Compact the conversation to shrink history, or start a new session.`;
266
272
  }
@@ -2185,6 +2191,7 @@ function toError2(err, provider = "openai") {
2185
2191
 
2186
2192
  // src/providers/openai-codex.ts
2187
2193
  import os from "os";
2194
+ import * as zstd from "@bokuweb/zstd-wasm";
2188
2195
 
2189
2196
  // src/utils/sse.ts
2190
2197
  function parseSseBuffer(buffer) {
@@ -2240,6 +2247,50 @@ function extractRequestIdFromMessage(message) {
2240
2247
  // src/providers/openai-codex.ts
2241
2248
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
2242
2249
  var CODEX_CLIENT_VERSION = "0.144.1";
2250
+ var CODEX_REQUEST_COMPRESSION_MIN_BYTES = 16 * 1024;
2251
+ var zstdInitPromise;
2252
+ async function encodeCodexRequest(body) {
2253
+ const json = JSON.stringify(body);
2254
+ const raw = new TextEncoder().encode(json);
2255
+ if (raw.byteLength < CODEX_REQUEST_COMPRESSION_MIN_BYTES) {
2256
+ return {
2257
+ body: json,
2258
+ compressed: false,
2259
+ rawBytes: raw.byteLength,
2260
+ encodedBytes: raw.byteLength
2261
+ };
2262
+ }
2263
+ try {
2264
+ zstdInitPromise ??= zstd.init();
2265
+ await zstdInitPromise;
2266
+ const compressed = Uint8Array.from(zstd.compress(raw));
2267
+ if (compressed.byteLength >= raw.byteLength) {
2268
+ return {
2269
+ body: json,
2270
+ compressed: false,
2271
+ rawBytes: raw.byteLength,
2272
+ encodedBytes: raw.byteLength
2273
+ };
2274
+ }
2275
+ return {
2276
+ body: compressed,
2277
+ compressed: true,
2278
+ rawBytes: raw.byteLength,
2279
+ encodedBytes: compressed.byteLength
2280
+ };
2281
+ } catch (error) {
2282
+ providerDiag("codex_request_compression_failed", {
2283
+ error: error instanceof Error ? error.message : String(error),
2284
+ rawBytes: raw.byteLength
2285
+ });
2286
+ return {
2287
+ body: json,
2288
+ compressed: false,
2289
+ rawBytes: raw.byteLength,
2290
+ encodedBytes: raw.byteLength
2291
+ };
2292
+ }
2293
+ }
2243
2294
  function usesResponsesLite(model) {
2244
2295
  return model.startsWith("gpt-5.6-");
2245
2296
  }
@@ -2317,10 +2368,17 @@ async function* runStream3(options) {
2317
2368
  headers["session_id"] = transportSessionId;
2318
2369
  headers["x-client-request-id"] = transportSessionId;
2319
2370
  }
2371
+ const encodedRequest = await encodeCodexRequest(body);
2372
+ if (encodedRequest.compressed) headers["Content-Encoding"] = "zstd";
2373
+ providerDiag("codex_request_body", {
2374
+ rawBytes: encodedRequest.rawBytes,
2375
+ encodedBytes: encodedRequest.encodedBytes,
2376
+ compressed: encodedRequest.compressed
2377
+ });
2320
2378
  const response = await fetch(url, {
2321
2379
  method: "POST",
2322
2380
  headers,
2323
- body: JSON.stringify(body),
2381
+ body: encodedRequest.body,
2324
2382
  signal: options.signal
2325
2383
  });
2326
2384
  if (!response.ok) {