@kenkaiiii/gg-ai 4.3.193 → 4.3.194

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
@@ -1208,6 +1208,25 @@ function toError(err) {
1208
1208
 
1209
1209
  // src/providers/openai.ts
1210
1210
  var import_openai = __toESM(require("openai"), 1);
1211
+
1212
+ // src/providers/prompt-cache-key.ts
1213
+ var MAX_PROMPT_CACHE_KEY_LENGTH = 64;
1214
+ function normalizePromptCacheKey(key) {
1215
+ if (key.length <= MAX_PROMPT_CACHE_KEY_LENGTH) return key;
1216
+ const hash = fnv1aHash(key);
1217
+ const prefixLength = MAX_PROMPT_CACHE_KEY_LENGTH - hash.length - 1;
1218
+ return `${key.slice(0, prefixLength)}:${hash}`;
1219
+ }
1220
+ function fnv1aHash(value) {
1221
+ let hash = 2166136261;
1222
+ for (let index = 0; index < value.length; index++) {
1223
+ hash ^= value.charCodeAt(index);
1224
+ hash = Math.imul(hash, 16777619);
1225
+ }
1226
+ return (hash >>> 0).toString(16).padStart(8, "0");
1227
+ }
1228
+
1229
+ // src/providers/openai.ts
1211
1230
  function isJsonObject2(value) {
1212
1231
  return value != null && typeof value === "object" && !Array.isArray(value);
1213
1232
  }
@@ -1259,7 +1278,7 @@ async function* runStream2(options) {
1259
1278
  };
1260
1279
  if (options.provider === "openai" || options.provider === "moonshot") {
1261
1280
  const paramsAny = params;
1262
- paramsAny.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
1281
+ paramsAny.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
1263
1282
  const retention = options.cacheRetention ?? "short";
1264
1283
  if (retention === "long") {
1265
1284
  paramsAny.prompt_cache_retention = "24h";
@@ -1566,24 +1585,23 @@ async function* runStream3(options) {
1566
1585
  input,
1567
1586
  tool_choice: "auto",
1568
1587
  parallel_tool_calls: true,
1569
- include: ["reasoning.encrypted_content"]
1588
+ include: ["reasoning.encrypted_content"],
1589
+ ...options.maxTokens ? { max_output_tokens: options.maxTokens } : {}
1570
1590
  };
1571
1591
  if (options.tools?.length) {
1572
1592
  body.tools = toCodexTools(options.tools);
1573
1593
  }
1574
- body.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
1594
+ body.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
1575
1595
  if (options.cacheRetention === "long") {
1576
1596
  body.prompt_cache_retention = "24h";
1577
1597
  }
1578
1598
  if (options.temperature != null && !options.thinking) {
1579
1599
  body.temperature = options.temperature;
1580
1600
  }
1581
- if (options.thinking) {
1582
- body.reasoning = {
1583
- effort: options.thinking,
1584
- summary: "auto"
1585
- };
1586
- }
1601
+ body.reasoning = {
1602
+ effort: options.thinking ?? "none",
1603
+ summary: "auto"
1604
+ };
1587
1605
  const headers = {
1588
1606
  "Content-Type": "application/json",
1589
1607
  Accept: "text/event-stream",
@@ -1672,7 +1690,7 @@ async function* runStream3(options) {
1672
1690
  const key = outputTextKey(itemId, contentIndex);
1673
1691
  outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
1674
1692
  if (itemId && outputItemTypes.get(itemId) === "reasoning") {
1675
- yield { type: "thinking_delta", text: delta };
1693
+ if (options.thinking) yield { type: "thinking_delta", text: delta };
1676
1694
  } else {
1677
1695
  textAccum += delta;
1678
1696
  yield { type: "text_delta", text: delta };
@@ -1689,7 +1707,7 @@ async function* runStream3(options) {
1689
1707
  outputTextByPart.set(key, fullText);
1690
1708
  if (missingText && fullText.startsWith(streamedText)) {
1691
1709
  if (itemId && outputItemTypes.get(itemId) === "reasoning") {
1692
- yield { type: "thinking_delta", text: missingText };
1710
+ if (options.thinking) yield { type: "thinking_delta", text: missingText };
1693
1711
  } else {
1694
1712
  textAccum += missingText;
1695
1713
  yield { type: "text_delta", text: missingText };
@@ -1699,7 +1717,7 @@ async function* runStream3(options) {
1699
1717
  }
1700
1718
  if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
1701
1719
  const delta = event.delta;
1702
- yield { type: "thinking_delta", text: delta };
1720
+ if (options.thinking) yield { type: "thinking_delta", text: delta };
1703
1721
  }
1704
1722
  if (type === "response.output_item.added") {
1705
1723
  const item = event.item;
@@ -1708,7 +1726,7 @@ async function* runStream3(options) {
1708
1726
  if (itemId && itemType) {
1709
1727
  outputItemTypes.set(itemId, itemType);
1710
1728
  }
1711
- if (itemType === "reasoning") {
1729
+ if (itemType === "reasoning" && options.thinking) {
1712
1730
  yield { type: "thinking_delta", text: "" };
1713
1731
  }
1714
1732
  }