@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 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
- id: remapToolCallId(tc.id, idMap),
1182
- type: "function",
1183
- function: { name: tc.name, arguments: JSON.stringify(tc.args) }
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;
@@ -2575,7 +2573,7 @@ function extractRequestIdFromMessage(message) {
2575
2573
 
2576
2574
  // src/providers/openai-codex.ts
2577
2575
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
2578
- var CODEX_CLIENT_VERSION = "0.153.4";
2576
+ var CODEX_CLIENT_VERSION = "0.155.1";
2579
2577
  var CODEX_REQUEST_COMPRESSION_MIN_BYTES = 16 * 1024;
2580
2578
  var zstdInitPromise;
2581
2579
  async function encodeCodexRequest(body) {
@@ -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);
@@ -2682,6 +2680,9 @@ async function* runStream3(options) {
2682
2680
  summary: "auto",
2683
2681
  ...responsesLite ? { context: "all_turns" } : {}
2684
2682
  };
2683
+ if (responsesLite) {
2684
+ body.text = { verbosity: "low" };
2685
+ }
2685
2686
  const headers = {
2686
2687
  "Content-Type": "application/json",
2687
2688
  Accept: "text/event-stream",
@@ -2720,6 +2721,20 @@ async function* runStream3(options) {
2720
2721
  const parsed = parseCodexErrorBody(text, response.status);
2721
2722
  const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
2722
2723
  const requestId = parsed.requestId ?? readHeader(response.headers, "x-request-id", "openai-request-id", "x-oai-request-id");
2724
+ 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(
2725
+ (msg) => msg.role === "assistant" && Array.isArray(msg.content) && msg.content.some((part) => part.type === "raw" && isEncryptedReasoning(part.data))
2726
+ )) {
2727
+ providerDiag("codex_retry_without_encrypted_reasoning", { status: response.status });
2728
+ const messages = options.messages.map(
2729
+ (msg) => msg.role === "assistant" && Array.isArray(msg.content) ? {
2730
+ ...msg,
2731
+ content: msg.content.filter(
2732
+ (part) => !(part.type === "raw" && isEncryptedReasoning(part.data))
2733
+ )
2734
+ } : msg
2735
+ );
2736
+ return yield* runStream3({ ...options, messages }, true);
2737
+ }
2723
2738
  const usageLimit = codexUsageLimitError(parsed.errorObj, response.status, requestId);
2724
2739
  if (usageLimit) throw usageLimit;
2725
2740
  let hint;