@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.js CHANGED
@@ -1159,6 +1159,25 @@ function toError(err) {
1159
1159
 
1160
1160
  // src/providers/openai.ts
1161
1161
  import OpenAI from "openai";
1162
+
1163
+ // src/providers/prompt-cache-key.ts
1164
+ var MAX_PROMPT_CACHE_KEY_LENGTH = 64;
1165
+ function normalizePromptCacheKey(key) {
1166
+ if (key.length <= MAX_PROMPT_CACHE_KEY_LENGTH) return key;
1167
+ const hash = fnv1aHash(key);
1168
+ const prefixLength = MAX_PROMPT_CACHE_KEY_LENGTH - hash.length - 1;
1169
+ return `${key.slice(0, prefixLength)}:${hash}`;
1170
+ }
1171
+ function fnv1aHash(value) {
1172
+ let hash = 2166136261;
1173
+ for (let index = 0; index < value.length; index++) {
1174
+ hash ^= value.charCodeAt(index);
1175
+ hash = Math.imul(hash, 16777619);
1176
+ }
1177
+ return (hash >>> 0).toString(16).padStart(8, "0");
1178
+ }
1179
+
1180
+ // src/providers/openai.ts
1162
1181
  function isJsonObject2(value) {
1163
1182
  return value != null && typeof value === "object" && !Array.isArray(value);
1164
1183
  }
@@ -1210,7 +1229,7 @@ async function* runStream2(options) {
1210
1229
  };
1211
1230
  if (options.provider === "openai" || options.provider === "moonshot") {
1212
1231
  const paramsAny = params;
1213
- paramsAny.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
1232
+ paramsAny.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
1214
1233
  const retention = options.cacheRetention ?? "short";
1215
1234
  if (retention === "long") {
1216
1235
  paramsAny.prompt_cache_retention = "24h";
@@ -1517,24 +1536,23 @@ async function* runStream3(options) {
1517
1536
  input,
1518
1537
  tool_choice: "auto",
1519
1538
  parallel_tool_calls: true,
1520
- include: ["reasoning.encrypted_content"]
1539
+ include: ["reasoning.encrypted_content"],
1540
+ ...options.maxTokens ? { max_output_tokens: options.maxTokens } : {}
1521
1541
  };
1522
1542
  if (options.tools?.length) {
1523
1543
  body.tools = toCodexTools(options.tools);
1524
1544
  }
1525
- body.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
1545
+ body.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
1526
1546
  if (options.cacheRetention === "long") {
1527
1547
  body.prompt_cache_retention = "24h";
1528
1548
  }
1529
1549
  if (options.temperature != null && !options.thinking) {
1530
1550
  body.temperature = options.temperature;
1531
1551
  }
1532
- if (options.thinking) {
1533
- body.reasoning = {
1534
- effort: options.thinking,
1535
- summary: "auto"
1536
- };
1537
- }
1552
+ body.reasoning = {
1553
+ effort: options.thinking ?? "none",
1554
+ summary: "auto"
1555
+ };
1538
1556
  const headers = {
1539
1557
  "Content-Type": "application/json",
1540
1558
  Accept: "text/event-stream",
@@ -1623,7 +1641,7 @@ async function* runStream3(options) {
1623
1641
  const key = outputTextKey(itemId, contentIndex);
1624
1642
  outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
1625
1643
  if (itemId && outputItemTypes.get(itemId) === "reasoning") {
1626
- yield { type: "thinking_delta", text: delta };
1644
+ if (options.thinking) yield { type: "thinking_delta", text: delta };
1627
1645
  } else {
1628
1646
  textAccum += delta;
1629
1647
  yield { type: "text_delta", text: delta };
@@ -1640,7 +1658,7 @@ async function* runStream3(options) {
1640
1658
  outputTextByPart.set(key, fullText);
1641
1659
  if (missingText && fullText.startsWith(streamedText)) {
1642
1660
  if (itemId && outputItemTypes.get(itemId) === "reasoning") {
1643
- yield { type: "thinking_delta", text: missingText };
1661
+ if (options.thinking) yield { type: "thinking_delta", text: missingText };
1644
1662
  } else {
1645
1663
  textAccum += missingText;
1646
1664
  yield { type: "text_delta", text: missingText };
@@ -1650,7 +1668,7 @@ async function* runStream3(options) {
1650
1668
  }
1651
1669
  if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
1652
1670
  const delta = event.delta;
1653
- yield { type: "thinking_delta", text: delta };
1671
+ if (options.thinking) yield { type: "thinking_delta", text: delta };
1654
1672
  }
1655
1673
  if (type === "response.output_item.added") {
1656
1674
  const item = event.item;
@@ -1659,7 +1677,7 @@ async function* runStream3(options) {
1659
1677
  if (itemId && itemType) {
1660
1678
  outputItemTypes.set(itemId, itemType);
1661
1679
  }
1662
- if (itemType === "reasoning") {
1680
+ if (itemType === "reasoning" && options.thinking) {
1663
1681
  yield { type: "thinking_delta", text: "" };
1664
1682
  }
1665
1683
  }