@kenkaiiii/gg-ai 4.3.193 → 4.3.195
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 +32 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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";
|
|
@@ -1522,19 +1541,17 @@ async function* runStream3(options) {
|
|
|
1522
1541
|
if (options.tools?.length) {
|
|
1523
1542
|
body.tools = toCodexTools(options.tools);
|
|
1524
1543
|
}
|
|
1525
|
-
body.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
|
|
1544
|
+
body.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
|
|
1526
1545
|
if (options.cacheRetention === "long") {
|
|
1527
1546
|
body.prompt_cache_retention = "24h";
|
|
1528
1547
|
}
|
|
1529
1548
|
if (options.temperature != null && !options.thinking) {
|
|
1530
1549
|
body.temperature = options.temperature;
|
|
1531
1550
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1551
|
+
body.reasoning = {
|
|
1552
|
+
effort: options.thinking ?? "none",
|
|
1553
|
+
summary: "auto"
|
|
1554
|
+
};
|
|
1538
1555
|
const headers = {
|
|
1539
1556
|
"Content-Type": "application/json",
|
|
1540
1557
|
Accept: "text/event-stream",
|
|
@@ -1561,7 +1578,7 @@ async function* runStream3(options) {
|
|
|
1561
1578
|
const text = await response.text().catch(() => "");
|
|
1562
1579
|
const parsed = parseCodexErrorBody(text);
|
|
1563
1580
|
const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
|
|
1564
|
-
const requestId = parsed.requestId ?? response.headers.get("x-request-id") ?? response.headers.get("openai-request-id") ?? void 0;
|
|
1581
|
+
const requestId = parsed.requestId ?? response.headers.get("x-request-id") ?? response.headers.get("openai-request-id") ?? response.headers.get("x-oai-request-id") ?? void 0;
|
|
1565
1582
|
let hint;
|
|
1566
1583
|
if (response.status === 400 && text.includes("not supported")) {
|
|
1567
1584
|
if (options.model === "gpt-5.5-pro") {
|
|
@@ -1623,7 +1640,7 @@ async function* runStream3(options) {
|
|
|
1623
1640
|
const key = outputTextKey(itemId, contentIndex);
|
|
1624
1641
|
outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
|
|
1625
1642
|
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1626
|
-
yield { type: "thinking_delta", text: delta };
|
|
1643
|
+
if (options.thinking) yield { type: "thinking_delta", text: delta };
|
|
1627
1644
|
} else {
|
|
1628
1645
|
textAccum += delta;
|
|
1629
1646
|
yield { type: "text_delta", text: delta };
|
|
@@ -1640,7 +1657,7 @@ async function* runStream3(options) {
|
|
|
1640
1657
|
outputTextByPart.set(key, fullText);
|
|
1641
1658
|
if (missingText && fullText.startsWith(streamedText)) {
|
|
1642
1659
|
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1643
|
-
yield { type: "thinking_delta", text: missingText };
|
|
1660
|
+
if (options.thinking) yield { type: "thinking_delta", text: missingText };
|
|
1644
1661
|
} else {
|
|
1645
1662
|
textAccum += missingText;
|
|
1646
1663
|
yield { type: "text_delta", text: missingText };
|
|
@@ -1650,7 +1667,7 @@ async function* runStream3(options) {
|
|
|
1650
1667
|
}
|
|
1651
1668
|
if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
|
|
1652
1669
|
const delta = event.delta;
|
|
1653
|
-
yield { type: "thinking_delta", text: delta };
|
|
1670
|
+
if (options.thinking) yield { type: "thinking_delta", text: delta };
|
|
1654
1671
|
}
|
|
1655
1672
|
if (type === "response.output_item.added") {
|
|
1656
1673
|
const item = event.item;
|
|
@@ -1659,7 +1676,7 @@ async function* runStream3(options) {
|
|
|
1659
1676
|
if (itemId && itemType) {
|
|
1660
1677
|
outputItemTypes.set(itemId, itemType);
|
|
1661
1678
|
}
|
|
1662
|
-
if (itemType === "reasoning") {
|
|
1679
|
+
if (itemType === "reasoning" && options.thinking) {
|
|
1663
1680
|
yield { type: "thinking_delta", text: "" };
|
|
1664
1681
|
}
|
|
1665
1682
|
}
|
|
@@ -1899,7 +1916,8 @@ function parseCodexErrorBody(text) {
|
|
|
1899
1916
|
try {
|
|
1900
1917
|
const parsed = JSON.parse(text);
|
|
1901
1918
|
const error = parsed.error;
|
|
1902
|
-
const
|
|
1919
|
+
const detail = parsed.detail;
|
|
1920
|
+
const message = error?.message ?? parsed.message ?? (typeof detail === "string" ? detail : void 0);
|
|
1903
1921
|
const requestId = parsed.request_id ?? error?.request_id ?? (message ? extractCodexRequestId(message) : void 0);
|
|
1904
1922
|
return { ...message ? { message } : {}, ...requestId ? { requestId } : {} };
|
|
1905
1923
|
} catch {
|