@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.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";
|
|
@@ -1571,19 +1590,17 @@ async function* runStream3(options) {
|
|
|
1571
1590
|
if (options.tools?.length) {
|
|
1572
1591
|
body.tools = toCodexTools(options.tools);
|
|
1573
1592
|
}
|
|
1574
|
-
body.prompt_cache_key = options.promptCacheKey ?? "ggcoder";
|
|
1593
|
+
body.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
|
|
1575
1594
|
if (options.cacheRetention === "long") {
|
|
1576
1595
|
body.prompt_cache_retention = "24h";
|
|
1577
1596
|
}
|
|
1578
1597
|
if (options.temperature != null && !options.thinking) {
|
|
1579
1598
|
body.temperature = options.temperature;
|
|
1580
1599
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
};
|
|
1586
|
-
}
|
|
1600
|
+
body.reasoning = {
|
|
1601
|
+
effort: options.thinking ?? "none",
|
|
1602
|
+
summary: "auto"
|
|
1603
|
+
};
|
|
1587
1604
|
const headers = {
|
|
1588
1605
|
"Content-Type": "application/json",
|
|
1589
1606
|
Accept: "text/event-stream",
|
|
@@ -1610,7 +1627,7 @@ async function* runStream3(options) {
|
|
|
1610
1627
|
const text = await response.text().catch(() => "");
|
|
1611
1628
|
const parsed = parseCodexErrorBody(text);
|
|
1612
1629
|
const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
|
|
1613
|
-
const requestId = parsed.requestId ?? response.headers.get("x-request-id") ?? response.headers.get("openai-request-id") ?? void 0;
|
|
1630
|
+
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;
|
|
1614
1631
|
let hint;
|
|
1615
1632
|
if (response.status === 400 && text.includes("not supported")) {
|
|
1616
1633
|
if (options.model === "gpt-5.5-pro") {
|
|
@@ -1672,7 +1689,7 @@ async function* runStream3(options) {
|
|
|
1672
1689
|
const key = outputTextKey(itemId, contentIndex);
|
|
1673
1690
|
outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
|
|
1674
1691
|
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1675
|
-
yield { type: "thinking_delta", text: delta };
|
|
1692
|
+
if (options.thinking) yield { type: "thinking_delta", text: delta };
|
|
1676
1693
|
} else {
|
|
1677
1694
|
textAccum += delta;
|
|
1678
1695
|
yield { type: "text_delta", text: delta };
|
|
@@ -1689,7 +1706,7 @@ async function* runStream3(options) {
|
|
|
1689
1706
|
outputTextByPart.set(key, fullText);
|
|
1690
1707
|
if (missingText && fullText.startsWith(streamedText)) {
|
|
1691
1708
|
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1692
|
-
yield { type: "thinking_delta", text: missingText };
|
|
1709
|
+
if (options.thinking) yield { type: "thinking_delta", text: missingText };
|
|
1693
1710
|
} else {
|
|
1694
1711
|
textAccum += missingText;
|
|
1695
1712
|
yield { type: "text_delta", text: missingText };
|
|
@@ -1699,7 +1716,7 @@ async function* runStream3(options) {
|
|
|
1699
1716
|
}
|
|
1700
1717
|
if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
|
|
1701
1718
|
const delta = event.delta;
|
|
1702
|
-
yield { type: "thinking_delta", text: delta };
|
|
1719
|
+
if (options.thinking) yield { type: "thinking_delta", text: delta };
|
|
1703
1720
|
}
|
|
1704
1721
|
if (type === "response.output_item.added") {
|
|
1705
1722
|
const item = event.item;
|
|
@@ -1708,7 +1725,7 @@ async function* runStream3(options) {
|
|
|
1708
1725
|
if (itemId && itemType) {
|
|
1709
1726
|
outputItemTypes.set(itemId, itemType);
|
|
1710
1727
|
}
|
|
1711
|
-
if (itemType === "reasoning") {
|
|
1728
|
+
if (itemType === "reasoning" && options.thinking) {
|
|
1712
1729
|
yield { type: "thinking_delta", text: "" };
|
|
1713
1730
|
}
|
|
1714
1731
|
}
|
|
@@ -1948,7 +1965,8 @@ function parseCodexErrorBody(text) {
|
|
|
1948
1965
|
try {
|
|
1949
1966
|
const parsed = JSON.parse(text);
|
|
1950
1967
|
const error = parsed.error;
|
|
1951
|
-
const
|
|
1968
|
+
const detail = parsed.detail;
|
|
1969
|
+
const message = error?.message ?? parsed.message ?? (typeof detail === "string" ? detail : void 0);
|
|
1952
1970
|
const requestId = parsed.request_id ?? error?.request_id ?? (message ? extractCodexRequestId(message) : void 0);
|
|
1953
1971
|
return { ...message ? { message } : {}, ...requestId ? { requestId } : {} };
|
|
1954
1972
|
} catch {
|