@prestyj/ai 5.4.1 → 5.5.0
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 +45 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +45 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -873,7 +873,7 @@ function toAnthropicThinking(level, maxTokens, model) {
|
|
|
873
873
|
};
|
|
874
874
|
}
|
|
875
875
|
const VISIBLE_FLOOR = 1024;
|
|
876
|
-
const effectiveLevel = level === "xhigh" || level === "max" ? "high" : level;
|
|
876
|
+
const effectiveLevel = level === "xhigh" || level === "max" || level === "ultra" ? "high" : level;
|
|
877
877
|
const budgetMap = {
|
|
878
878
|
low: Math.max(1024, Math.floor(maxTokens * 0.2)),
|
|
879
879
|
medium: Math.max(2048, Math.floor(maxTokens * 0.45)),
|
|
@@ -1041,7 +1041,7 @@ function toOpenAIToolChoice(choice) {
|
|
|
1041
1041
|
return { type: "function", function: { name: choice.name } };
|
|
1042
1042
|
}
|
|
1043
1043
|
function toOpenAIReasoningEffort(level, model) {
|
|
1044
|
-
const effort = level === "max" ? "xhigh" : level;
|
|
1044
|
+
const effort = level === "max" || level === "ultra" ? "xhigh" : level;
|
|
1045
1045
|
if (model.startsWith("fugu") && (effort === "low" || effort === "medium")) {
|
|
1046
1046
|
return "high";
|
|
1047
1047
|
}
|
|
@@ -1767,11 +1767,16 @@ function getEnvironment() {
|
|
|
1767
1767
|
// src/providers/openai.ts
|
|
1768
1768
|
function extractOpenAIUsage(usage) {
|
|
1769
1769
|
let cacheRead = 0;
|
|
1770
|
+
let cacheWrite = 0;
|
|
1770
1771
|
const details = usage.prompt_tokens_details;
|
|
1771
1772
|
if (details?.cached_tokens) {
|
|
1772
1773
|
cacheRead = details.cached_tokens;
|
|
1773
1774
|
}
|
|
1774
1775
|
const usageAny = usage;
|
|
1776
|
+
const detailsAny = details;
|
|
1777
|
+
if (typeof detailsAny?.cache_write_tokens === "number") {
|
|
1778
|
+
cacheWrite = detailsAny.cache_write_tokens;
|
|
1779
|
+
}
|
|
1775
1780
|
if (!cacheRead && typeof usageAny.cached_tokens === "number" && usageAny.cached_tokens > 0) {
|
|
1776
1781
|
cacheRead = usageAny.cached_tokens;
|
|
1777
1782
|
}
|
|
@@ -1779,9 +1784,10 @@ function extractOpenAIUsage(usage) {
|
|
|
1779
1784
|
cacheRead = usageAny.prompt_cache_hit_tokens;
|
|
1780
1785
|
}
|
|
1781
1786
|
return {
|
|
1782
|
-
inputTokens: usage.prompt_tokens - cacheRead,
|
|
1787
|
+
inputTokens: usage.prompt_tokens - cacheRead - cacheWrite,
|
|
1783
1788
|
outputTokens: usage.completion_tokens,
|
|
1784
|
-
cacheRead
|
|
1789
|
+
cacheRead,
|
|
1790
|
+
cacheWrite
|
|
1785
1791
|
};
|
|
1786
1792
|
}
|
|
1787
1793
|
var openaiClientCache = /* @__PURE__ */ new Map();
|
|
@@ -1846,8 +1852,9 @@ async function* runStream2(options) {
|
|
|
1846
1852
|
if (options.provider === "openai" || options.provider === "moonshot") {
|
|
1847
1853
|
const paramsAny = params;
|
|
1848
1854
|
paramsAny.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ezcoder");
|
|
1849
|
-
|
|
1850
|
-
|
|
1855
|
+
if (options.provider === "openai" && options.model.startsWith("gpt-5.6")) {
|
|
1856
|
+
paramsAny.prompt_cache_options = { mode: "implicit", ttl: "30m" };
|
|
1857
|
+
} else if ((options.cacheRetention ?? "short") === "long") {
|
|
1851
1858
|
paramsAny.prompt_cache_retention = "24h";
|
|
1852
1859
|
}
|
|
1853
1860
|
}
|
|
@@ -1898,6 +1905,7 @@ async function* runStream2(options) {
|
|
|
1898
1905
|
let inputTokens = 0;
|
|
1899
1906
|
let outputTokens = 0;
|
|
1900
1907
|
let cacheRead = 0;
|
|
1908
|
+
let cacheWrite = 0;
|
|
1901
1909
|
let finishReason = null;
|
|
1902
1910
|
let receivedAnyChunk = false;
|
|
1903
1911
|
try {
|
|
@@ -1905,7 +1913,7 @@ async function* runStream2(options) {
|
|
|
1905
1913
|
receivedAnyChunk = true;
|
|
1906
1914
|
const choice = chunk.choices?.[0];
|
|
1907
1915
|
if (chunk.usage) {
|
|
1908
|
-
({ inputTokens, outputTokens, cacheRead } = extractOpenAIUsage(chunk.usage));
|
|
1916
|
+
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(chunk.usage));
|
|
1909
1917
|
}
|
|
1910
1918
|
if (!choice) continue;
|
|
1911
1919
|
if (choice.finish_reason) {
|
|
@@ -1985,7 +1993,12 @@ async function* runStream2(options) {
|
|
|
1985
1993
|
content: contentParts.length > 0 ? contentParts : textAccum || ""
|
|
1986
1994
|
},
|
|
1987
1995
|
stopReason,
|
|
1988
|
-
usage: {
|
|
1996
|
+
usage: {
|
|
1997
|
+
inputTokens,
|
|
1998
|
+
outputTokens,
|
|
1999
|
+
...cacheRead > 0 && { cacheRead },
|
|
2000
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
2001
|
+
}
|
|
1989
2002
|
};
|
|
1990
2003
|
yield { type: "done", stopReason };
|
|
1991
2004
|
return response;
|
|
@@ -2058,8 +2071,9 @@ function completionToResponse(completion) {
|
|
|
2058
2071
|
let inputTokens = 0;
|
|
2059
2072
|
let outputTokens = 0;
|
|
2060
2073
|
let cacheRead = 0;
|
|
2074
|
+
let cacheWrite = 0;
|
|
2061
2075
|
if (completion.usage) {
|
|
2062
|
-
({ inputTokens, outputTokens, cacheRead } = extractOpenAIUsage(completion.usage));
|
|
2076
|
+
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(completion.usage));
|
|
2063
2077
|
}
|
|
2064
2078
|
const stopReason = normalizeOpenAIStopReason(choice?.finish_reason ?? null);
|
|
2065
2079
|
return {
|
|
@@ -2068,7 +2082,12 @@ function completionToResponse(completion) {
|
|
|
2068
2082
|
content: contentParts.length > 0 ? contentParts : textAccum
|
|
2069
2083
|
},
|
|
2070
2084
|
stopReason,
|
|
2071
|
-
usage: {
|
|
2085
|
+
usage: {
|
|
2086
|
+
inputTokens,
|
|
2087
|
+
outputTokens,
|
|
2088
|
+
...cacheRead > 0 && { cacheRead },
|
|
2089
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
2090
|
+
}
|
|
2072
2091
|
};
|
|
2073
2092
|
}
|
|
2074
2093
|
function classifyOpenAICompatLimit(args) {
|
|
@@ -2228,7 +2247,8 @@ async function* runStream3(options) {
|
|
|
2228
2247
|
body.temperature = options.temperature;
|
|
2229
2248
|
}
|
|
2230
2249
|
body.reasoning = {
|
|
2231
|
-
|
|
2250
|
+
// `ultra` is a client orchestration preset, not a Codex API effort.
|
|
2251
|
+
effort: options.thinking === "ultra" ? "max" : options.thinking ?? "none",
|
|
2232
2252
|
summary: "auto",
|
|
2233
2253
|
...responsesLite ? { context: "all_turns" } : {}
|
|
2234
2254
|
};
|
|
@@ -2247,10 +2267,9 @@ async function* runStream3(options) {
|
|
|
2247
2267
|
if (options.accountId) {
|
|
2248
2268
|
headers["chatgpt-account-id"] = options.accountId;
|
|
2249
2269
|
}
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
headers["
|
|
2253
|
-
headers["x-client-request-id"] = cacheScopeId;
|
|
2270
|
+
if (options.transportSessionId) {
|
|
2271
|
+
headers["session_id"] = options.transportSessionId;
|
|
2272
|
+
headers["x-client-request-id"] = options.transportSessionId;
|
|
2254
2273
|
}
|
|
2255
2274
|
const response = await fetch(url, {
|
|
2256
2275
|
method: "POST",
|
|
@@ -2294,6 +2313,7 @@ async function* runStream3(options) {
|
|
|
2294
2313
|
let inputTokens = 0;
|
|
2295
2314
|
let outputTokens = 0;
|
|
2296
2315
|
let cacheRead = 0;
|
|
2316
|
+
let cacheWrite = 0;
|
|
2297
2317
|
const diagStart = Date.now();
|
|
2298
2318
|
const diagSeen = /* @__PURE__ */ new Set();
|
|
2299
2319
|
for await (const event of parseSSE(response.body)) {
|
|
@@ -2470,7 +2490,8 @@ async function* runStream3(options) {
|
|
|
2470
2490
|
const usage = resp?.usage;
|
|
2471
2491
|
if (usage) {
|
|
2472
2492
|
cacheRead = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
2473
|
-
|
|
2493
|
+
cacheWrite = usage.input_tokens_details?.cache_write_tokens ?? 0;
|
|
2494
|
+
inputTokens = (usage.input_tokens ?? 0) - cacheRead - cacheWrite;
|
|
2474
2495
|
outputTokens = usage.output_tokens ?? 0;
|
|
2475
2496
|
}
|
|
2476
2497
|
}
|
|
@@ -2518,7 +2539,12 @@ async function* runStream3(options) {
|
|
|
2518
2539
|
content: contentParts.length > 0 ? contentParts : textAccum || ""
|
|
2519
2540
|
},
|
|
2520
2541
|
stopReason,
|
|
2521
|
-
usage: {
|
|
2542
|
+
usage: {
|
|
2543
|
+
inputTokens,
|
|
2544
|
+
outputTokens,
|
|
2545
|
+
...cacheRead > 0 && { cacheRead },
|
|
2546
|
+
...cacheWrite > 0 && { cacheWrite }
|
|
2547
|
+
}
|
|
2522
2548
|
};
|
|
2523
2549
|
yield { type: "done", stopReason };
|
|
2524
2550
|
return streamResponse;
|
|
@@ -2881,6 +2907,7 @@ function toGemini3ThinkingLevel(level) {
|
|
|
2881
2907
|
case "high":
|
|
2882
2908
|
case "xhigh":
|
|
2883
2909
|
case "max":
|
|
2910
|
+
case "ultra":
|
|
2884
2911
|
return "HIGH";
|
|
2885
2912
|
}
|
|
2886
2913
|
}
|
|
@@ -2893,6 +2920,7 @@ function toThinkingBudget(level) {
|
|
|
2893
2920
|
case "high":
|
|
2894
2921
|
case "xhigh":
|
|
2895
2922
|
case "max":
|
|
2923
|
+
case "ultra":
|
|
2896
2924
|
return 8192;
|
|
2897
2925
|
}
|
|
2898
2926
|
}
|