@prestyj/ai 5.17.0 → 5.19.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 +20 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -8
- 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;
|
|
@@ -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);
|
|
@@ -2653,6 +2651,20 @@ async function* runStream3(options) {
|
|
|
2653
2651
|
const parsed = parseCodexErrorBody(text, response.status);
|
|
2654
2652
|
const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
|
|
2655
2653
|
const requestId = parsed.requestId ?? readHeader(response.headers, "x-request-id", "openai-request-id", "x-oai-request-id");
|
|
2654
|
+
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(
|
|
2655
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) && msg.content.some((part) => part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2656
|
+
)) {
|
|
2657
|
+
providerDiag("codex_retry_without_encrypted_reasoning", { status: response.status });
|
|
2658
|
+
const messages = options.messages.map(
|
|
2659
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) ? {
|
|
2660
|
+
...msg,
|
|
2661
|
+
content: msg.content.filter(
|
|
2662
|
+
(part) => !(part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2663
|
+
)
|
|
2664
|
+
} : msg
|
|
2665
|
+
);
|
|
2666
|
+
return yield* runStream3({ ...options, messages }, true);
|
|
2667
|
+
}
|
|
2656
2668
|
const usageLimit = codexUsageLimitError(parsed.errorObj, response.status, requestId);
|
|
2657
2669
|
if (usageLimit) throw usageLimit;
|
|
2658
2670
|
let hint;
|