@prestyj/ai 5.17.0 → 5.20.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 +24 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1109,13 +1109,11 @@ function toOpenAIMessages(messages, options) {
|
|
|
1109
1109
|
const parts = typeof msg.content === "string" ? msg.content : void 0;
|
|
1110
1110
|
const toolCalls = typeof msg.content !== "string" ? msg.content.filter(
|
|
1111
1111
|
(p) => p.type === "tool_call"
|
|
1112
|
-
).map(
|
|
1113
|
-
(tc)
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
})
|
|
1118
|
-
) : void 0;
|
|
1112
|
+
).map((tc) => ({
|
|
1113
|
+
id: remapToolCallId(tc.id, idMap),
|
|
1114
|
+
type: "function",
|
|
1115
|
+
function: { name: tc.name, arguments: JSON.stringify(tc.args) }
|
|
1116
|
+
})) : void 0;
|
|
1119
1117
|
const textParts = typeof msg.content !== "string" ? msg.content.filter((p) => p.type === "text").map((p) => p.text).join("") : void 0;
|
|
1120
1118
|
const thinkingParts = typeof msg.content !== "string" ? msg.content.filter((p) => p.type === "thinking").map((p) => p.text).join("") : void 0;
|
|
1121
1119
|
const contentValue = parts || textParts || null;
|
|
@@ -2508,7 +2506,7 @@ function extractRequestIdFromMessage(message) {
|
|
|
2508
2506
|
|
|
2509
2507
|
// src/providers/openai-codex.ts
|
|
2510
2508
|
var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
2511
|
-
var CODEX_CLIENT_VERSION = "0.
|
|
2509
|
+
var CODEX_CLIENT_VERSION = "0.155.1";
|
|
2512
2510
|
var CODEX_REQUEST_COMPRESSION_MIN_BYTES = 16 * 1024;
|
|
2513
2511
|
var zstdInitPromise;
|
|
2514
2512
|
async function encodeCodexRequest(body) {
|
|
@@ -2583,7 +2581,7 @@ function toCodexToolChoice(choice, tools) {
|
|
|
2583
2581
|
function streamOpenAICodex(options) {
|
|
2584
2582
|
return new StreamResult(runStream3(options), options.signal);
|
|
2585
2583
|
}
|
|
2586
|
-
async function* runStream3(options) {
|
|
2584
|
+
async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
2587
2585
|
const baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
2588
2586
|
const url = `${baseUrl}/codex/responses`;
|
|
2589
2587
|
const downgradedImages = downgradeUnsupportedImages(options.messages, options.supportsImages);
|
|
@@ -2615,6 +2613,9 @@ async function* runStream3(options) {
|
|
|
2615
2613
|
summary: "auto",
|
|
2616
2614
|
...responsesLite ? { context: "all_turns" } : {}
|
|
2617
2615
|
};
|
|
2616
|
+
if (responsesLite) {
|
|
2617
|
+
body.text = { verbosity: "low" };
|
|
2618
|
+
}
|
|
2618
2619
|
const headers = {
|
|
2619
2620
|
"Content-Type": "application/json",
|
|
2620
2621
|
Accept: "text/event-stream",
|
|
@@ -2653,6 +2654,20 @@ async function* runStream3(options) {
|
|
|
2653
2654
|
const parsed = parseCodexErrorBody(text, response.status);
|
|
2654
2655
|
const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
|
|
2655
2656
|
const requestId = parsed.requestId ?? readHeader(response.headers, "x-request-id", "openai-request-id", "x-oai-request-id");
|
|
2657
|
+
if (!retriedWithoutReasoning && !options.signal?.aborted && response.status === 400 && (parsed.errorObj?.code === "invalid_encrypted_content" || /encrypted content.*could not be (?:verified|decrypted|parsed)/i.test(message)) && options.messages.some(
|
|
2658
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) && msg.content.some((part) => part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2659
|
+
)) {
|
|
2660
|
+
providerDiag("codex_retry_without_encrypted_reasoning", { status: response.status });
|
|
2661
|
+
const messages = options.messages.map(
|
|
2662
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) ? {
|
|
2663
|
+
...msg,
|
|
2664
|
+
content: msg.content.filter(
|
|
2665
|
+
(part) => !(part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2666
|
+
)
|
|
2667
|
+
} : msg
|
|
2668
|
+
);
|
|
2669
|
+
return yield* runStream3({ ...options, messages }, true);
|
|
2670
|
+
}
|
|
2656
2671
|
const usageLimit = codexUsageLimitError(parsed.errorObj, response.status, requestId);
|
|
2657
2672
|
if (usageLimit) throw usageLimit;
|
|
2658
2673
|
let hint;
|