@kenkaiiii/gg-ai 4.3.179 → 4.3.181

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
@@ -1251,6 +1251,9 @@ async function* runStream2(options) {
1251
1251
  if (!cacheRead && typeof usageAny.cached_tokens === "number" && usageAny.cached_tokens > 0) {
1252
1252
  cacheRead = usageAny.cached_tokens;
1253
1253
  }
1254
+ if (!cacheRead && typeof usageAny.prompt_cache_hit_tokens === "number" && usageAny.prompt_cache_hit_tokens > 0) {
1255
+ cacheRead = usageAny.prompt_cache_hit_tokens;
1256
+ }
1254
1257
  inputTokens = chunk.usage.prompt_tokens - cacheRead;
1255
1258
  }
1256
1259
  if (!choice) continue;
@@ -1416,6 +1419,9 @@ function completionToResponse(completion) {
1416
1419
  if (!cacheRead && typeof usageAny.cached_tokens === "number" && usageAny.cached_tokens > 0) {
1417
1420
  cacheRead = usageAny.cached_tokens;
1418
1421
  }
1422
+ if (!cacheRead && typeof usageAny.prompt_cache_hit_tokens === "number" && usageAny.prompt_cache_hit_tokens > 0) {
1423
+ cacheRead = usageAny.prompt_cache_hit_tokens;
1424
+ }
1419
1425
  inputTokens = completion.usage.prompt_tokens - cacheRead;
1420
1426
  }
1421
1427
  const stopReason = normalizeOpenAIStopReason(choice?.finish_reason ?? null);
@@ -1487,8 +1493,9 @@ async function* runStream3(options) {
1487
1493
  if (options.tools?.length) {
1488
1494
  body.tools = toCodexTools(options.tools);
1489
1495
  }
1490
- if (options.promptCacheKey) {
1491
- body.prompt_cache_key = options.promptCacheKey;
1496
+ body.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
1497
+ if (options.cacheRetention === "long") {
1498
+ body.prompt_cache_retention = "24h";
1492
1499
  }
1493
1500
  if (options.temperature != null && !options.thinking) {
1494
1501
  body.temperature = options.temperature;
@@ -1510,6 +1517,11 @@ async function* runStream3(options) {
1510
1517
  if (options.accountId) {
1511
1518
  headers["chatgpt-account-id"] = options.accountId;
1512
1519
  }
1520
+ const cacheScopeId = body.prompt_cache_key;
1521
+ if (cacheScopeId) {
1522
+ headers["session_id"] = cacheScopeId;
1523
+ headers["x-client-request-id"] = cacheScopeId;
1524
+ }
1513
1525
  const response = await fetch(url, {
1514
1526
  method: "POST",
1515
1527
  headers,