@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.cjs
CHANGED
|
@@ -1176,13 +1176,11 @@ function toOpenAIMessages(messages, options) {
|
|
|
1176
1176
|
const parts = typeof msg.content === "string" ? msg.content : void 0;
|
|
1177
1177
|
const toolCalls = typeof msg.content !== "string" ? msg.content.filter(
|
|
1178
1178
|
(p) => p.type === "tool_call"
|
|
1179
|
-
).map(
|
|
1180
|
-
(tc)
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
})
|
|
1185
|
-
) : void 0;
|
|
1179
|
+
).map((tc) => ({
|
|
1180
|
+
id: remapToolCallId(tc.id, idMap),
|
|
1181
|
+
type: "function",
|
|
1182
|
+
function: { name: tc.name, arguments: JSON.stringify(tc.args) }
|
|
1183
|
+
})) : void 0;
|
|
1186
1184
|
const textParts = typeof msg.content !== "string" ? msg.content.filter((p) => p.type === "text").map((p) => p.text).join("") : void 0;
|
|
1187
1185
|
const thinkingParts = typeof msg.content !== "string" ? msg.content.filter((p) => p.type === "thinking").map((p) => p.text).join("") : void 0;
|
|
1188
1186
|
const contentValue = parts || textParts || null;
|
|
@@ -2650,7 +2648,7 @@ function toCodexToolChoice(choice, tools) {
|
|
|
2650
2648
|
function streamOpenAICodex(options) {
|
|
2651
2649
|
return new StreamResult(runStream3(options), options.signal);
|
|
2652
2650
|
}
|
|
2653
|
-
async function* runStream3(options) {
|
|
2651
|
+
async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
2654
2652
|
const baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
2655
2653
|
const url = `${baseUrl}/codex/responses`;
|
|
2656
2654
|
const downgradedImages = downgradeUnsupportedImages(options.messages, options.supportsImages);
|
|
@@ -2720,6 +2718,20 @@ async function* runStream3(options) {
|
|
|
2720
2718
|
const parsed = parseCodexErrorBody(text, response.status);
|
|
2721
2719
|
const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
|
|
2722
2720
|
const requestId = parsed.requestId ?? readHeader(response.headers, "x-request-id", "openai-request-id", "x-oai-request-id");
|
|
2721
|
+
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(
|
|
2722
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) && msg.content.some((part) => part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2723
|
+
)) {
|
|
2724
|
+
providerDiag("codex_retry_without_encrypted_reasoning", { status: response.status });
|
|
2725
|
+
const messages = options.messages.map(
|
|
2726
|
+
(msg) => msg.role === "assistant" && Array.isArray(msg.content) ? {
|
|
2727
|
+
...msg,
|
|
2728
|
+
content: msg.content.filter(
|
|
2729
|
+
(part) => !(part.type === "raw" && isEncryptedReasoning(part.data))
|
|
2730
|
+
)
|
|
2731
|
+
} : msg
|
|
2732
|
+
);
|
|
2733
|
+
return yield* runStream3({ ...options, messages }, true);
|
|
2734
|
+
}
|
|
2723
2735
|
const usageLimit = codexUsageLimitError(parsed.errorObj, response.status, requestId);
|
|
2724
2736
|
if (usageLimit) throw usageLimit;
|
|
2725
2737
|
let hint;
|