@kenkaiiii/gg-ai 5.13.2 → 5.13.3
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 +39 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +39 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -175,6 +175,10 @@ interface StreamOptions {
|
|
|
175
175
|
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
176
176
|
/** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
|
|
177
177
|
accountId?: string;
|
|
178
|
+
/** Stable conversation identity for Codex transport headers. This is distinct from
|
|
179
|
+
* promptCacheKey: sessions with matching prefixes may share a cache key, but must
|
|
180
|
+
* retain independent session/thread identities. */
|
|
181
|
+
transportSessionId?: string;
|
|
178
182
|
/** Google Cloud/Code Assist project ID used by Gemini OAuth transport. */
|
|
179
183
|
projectId?: string;
|
|
180
184
|
/** Enable provider-native web search. Each provider uses its own format:
|
package/dist/index.d.ts
CHANGED
|
@@ -175,6 +175,10 @@ interface StreamOptions {
|
|
|
175
175
|
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
176
176
|
/** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
|
|
177
177
|
accountId?: string;
|
|
178
|
+
/** Stable conversation identity for Codex transport headers. This is distinct from
|
|
179
|
+
* promptCacheKey: sessions with matching prefixes may share a cache key, but must
|
|
180
|
+
* retain independent session/thread identities. */
|
|
181
|
+
transportSessionId?: string;
|
|
178
182
|
/** Google Cloud/Code Assist project ID used by Gemini OAuth transport. */
|
|
179
183
|
projectId?: string;
|
|
180
184
|
/** Enable provider-native web search. Each provider uses its own format:
|
package/dist/index.js
CHANGED
|
@@ -1711,11 +1711,16 @@ function getEnvironment() {
|
|
|
1711
1711
|
// src/providers/openai.ts
|
|
1712
1712
|
function extractOpenAIUsage(usage) {
|
|
1713
1713
|
let cacheRead = 0;
|
|
1714
|
+
let cacheWrite = 0;
|
|
1714
1715
|
const details = usage.prompt_tokens_details;
|
|
1715
1716
|
if (details?.cached_tokens) {
|
|
1716
1717
|
cacheRead = details.cached_tokens;
|
|
1717
1718
|
}
|
|
1718
1719
|
const usageAny = usage;
|
|
1720
|
+
const detailsAny = details;
|
|
1721
|
+
if (typeof detailsAny?.cache_write_tokens === "number") {
|
|
1722
|
+
cacheWrite = detailsAny.cache_write_tokens;
|
|
1723
|
+
}
|
|
1719
1724
|
if (!cacheRead && typeof usageAny.cached_tokens === "number" && usageAny.cached_tokens > 0) {
|
|
1720
1725
|
cacheRead = usageAny.cached_tokens;
|
|
1721
1726
|
}
|
|
@@ -1723,9 +1728,10 @@ function extractOpenAIUsage(usage) {
|
|
|
1723
1728
|
cacheRead = usageAny.prompt_cache_hit_tokens;
|
|
1724
1729
|
}
|
|
1725
1730
|
return {
|
|
1726
|
-
inputTokens: usage.prompt_tokens - cacheRead,
|
|
1731
|
+
inputTokens: usage.prompt_tokens - cacheRead - cacheWrite,
|
|
1727
1732
|
outputTokens: usage.completion_tokens,
|
|
1728
|
-
cacheRead
|
|
1733
|
+
cacheRead,
|
|
1734
|
+
cacheWrite
|
|
1729
1735
|
};
|
|
1730
1736
|
}
|
|
1731
1737
|
var openaiClientCache = /* @__PURE__ */ new Map();
|
|
@@ -1790,8 +1796,9 @@ async function* runStream2(options) {
|
|
|
1790
1796
|
if (options.provider === "openai" || options.provider === "moonshot") {
|
|
1791
1797
|
const paramsAny = params;
|
|
1792
1798
|
paramsAny.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ggcoder");
|
|
1793
|
-
|
|
1794
|
-
|
|
1799
|
+
if (options.provider === "openai" && options.model.startsWith("gpt-5.6")) {
|
|
1800
|
+
paramsAny.prompt_cache_options = { mode: "implicit", ttl: "30m" };
|
|
1801
|
+
} else if ((options.cacheRetention ?? "short") === "long") {
|
|
1795
1802
|
paramsAny.prompt_cache_retention = "24h";
|
|
1796
1803
|
}
|
|
1797
1804
|
}
|
|
@@ -1842,6 +1849,7 @@ async function* runStream2(options) {
|
|
|
1842
1849
|
let inputTokens = 0;
|
|
1843
1850
|
let outputTokens = 0;
|
|
1844
1851
|
let cacheRead = 0;
|
|
1852
|
+
let cacheWrite = 0;
|
|
1845
1853
|
let finishReason = null;
|
|
1846
1854
|
let receivedAnyChunk = false;
|
|
1847
1855
|
try {
|
|
@@ -1849,7 +1857,7 @@ async function* runStream2(options) {
|
|
|
1849
1857
|
receivedAnyChunk = true;
|
|
1850
1858
|
const choice = chunk.choices?.[0];
|
|
1851
1859
|
if (chunk.usage) {
|
|
1852
|
-
({ inputTokens, outputTokens, cacheRead } = extractOpenAIUsage(chunk.usage));
|
|
1860
|
+
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(chunk.usage));
|
|
1853
1861
|
}
|
|
1854
1862
|
if (!choice) continue;
|
|
1855
1863
|
if (choice.finish_reason) {
|
|
@@ -1929,7 +1937,12 @@ async function* runStream2(options) {
|
|
|
1929
1937
|
content: contentParts.length > 0 ? contentParts : textAccum || ""
|
|
1930
1938
|
},
|
|
1931
1939
|
stopReason,
|
|
1932
|
-
usage: {
|
|
1940
|
+
usage: {
|
|
1941
|
+
inputTokens,
|
|
1942
|
+
outputTokens,
|
|
1943
|
+
...cacheRead > 0 && { cacheRead },
|
|
1944
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
1945
|
+
}
|
|
1933
1946
|
};
|
|
1934
1947
|
yield { type: "done", stopReason };
|
|
1935
1948
|
return response;
|
|
@@ -2002,8 +2015,9 @@ function completionToResponse(completion) {
|
|
|
2002
2015
|
let inputTokens = 0;
|
|
2003
2016
|
let outputTokens = 0;
|
|
2004
2017
|
let cacheRead = 0;
|
|
2018
|
+
let cacheWrite = 0;
|
|
2005
2019
|
if (completion.usage) {
|
|
2006
|
-
({ inputTokens, outputTokens, cacheRead } = extractOpenAIUsage(completion.usage));
|
|
2020
|
+
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(completion.usage));
|
|
2007
2021
|
}
|
|
2008
2022
|
const stopReason = normalizeOpenAIStopReason(choice?.finish_reason ?? null);
|
|
2009
2023
|
return {
|
|
@@ -2012,7 +2026,12 @@ function completionToResponse(completion) {
|
|
|
2012
2026
|
content: contentParts.length > 0 ? contentParts : textAccum
|
|
2013
2027
|
},
|
|
2014
2028
|
stopReason,
|
|
2015
|
-
usage: {
|
|
2029
|
+
usage: {
|
|
2030
|
+
inputTokens,
|
|
2031
|
+
outputTokens,
|
|
2032
|
+
...cacheRead > 0 && { cacheRead },
|
|
2033
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
2034
|
+
}
|
|
2016
2035
|
};
|
|
2017
2036
|
}
|
|
2018
2037
|
function classifyOpenAICompatLimit(args) {
|
|
@@ -2192,10 +2211,9 @@ async function* runStream3(options) {
|
|
|
2192
2211
|
if (options.accountId) {
|
|
2193
2212
|
headers["chatgpt-account-id"] = options.accountId;
|
|
2194
2213
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
headers["
|
|
2198
|
-
headers["x-client-request-id"] = cacheScopeId;
|
|
2214
|
+
if (options.transportSessionId) {
|
|
2215
|
+
headers["session_id"] = options.transportSessionId;
|
|
2216
|
+
headers["x-client-request-id"] = options.transportSessionId;
|
|
2199
2217
|
}
|
|
2200
2218
|
const response = await fetch(url, {
|
|
2201
2219
|
method: "POST",
|
|
@@ -2239,6 +2257,7 @@ async function* runStream3(options) {
|
|
|
2239
2257
|
let inputTokens = 0;
|
|
2240
2258
|
let outputTokens = 0;
|
|
2241
2259
|
let cacheRead = 0;
|
|
2260
|
+
let cacheWrite = 0;
|
|
2242
2261
|
const diagStart = Date.now();
|
|
2243
2262
|
const diagSeen = /* @__PURE__ */ new Set();
|
|
2244
2263
|
for await (const event of parseSSE(response.body)) {
|
|
@@ -2415,7 +2434,8 @@ async function* runStream3(options) {
|
|
|
2415
2434
|
const usage = resp?.usage;
|
|
2416
2435
|
if (usage) {
|
|
2417
2436
|
cacheRead = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
2418
|
-
|
|
2437
|
+
cacheWrite = usage.input_tokens_details?.cache_write_tokens ?? 0;
|
|
2438
|
+
inputTokens = (usage.input_tokens ?? 0) - cacheRead - cacheWrite;
|
|
2419
2439
|
outputTokens = usage.output_tokens ?? 0;
|
|
2420
2440
|
}
|
|
2421
2441
|
}
|
|
@@ -2463,7 +2483,12 @@ async function* runStream3(options) {
|
|
|
2463
2483
|
content: contentParts.length > 0 ? contentParts : textAccum || ""
|
|
2464
2484
|
},
|
|
2465
2485
|
stopReason,
|
|
2466
|
-
usage: {
|
|
2486
|
+
usage: {
|
|
2487
|
+
inputTokens,
|
|
2488
|
+
outputTokens,
|
|
2489
|
+
...cacheRead > 0 && { cacheRead },
|
|
2490
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
2491
|
+
}
|
|
2467
2492
|
};
|
|
2468
2493
|
yield { type: "done", stopReason };
|
|
2469
2494
|
return streamResponse;
|