@kenkaiiii/gg-ai 5.60.0 → 5.60.2

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;
@@ -2646,7 +2644,7 @@ function toCodexToolChoice(choice, tools) {
2646
2644
  function streamOpenAICodex(options) {
2647
2645
  return new StreamResult(runStream3(options), options.signal);
2648
2646
  }
2649
- async function* runStream3(options) {
2647
+ async function* runStream3(options, retriedWithoutReasoning = false) {
2650
2648
  const baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
2651
2649
  const url = `${baseUrl}/codex/responses`;
2652
2650
  const downgradedImages = downgradeUnsupportedImages(options.messages, options.supportsImages);
@@ -2716,6 +2714,20 @@ async function* runStream3(options) {
2716
2714
  const parsed = parseCodexErrorBody(text, response.status);
2717
2715
  const message = parsed.message ?? `Codex API returned HTTP ${response.status}.`;
2718
2716
  const requestId = parsed.requestId ?? readHeader(response.headers, "x-request-id", "openai-request-id", "x-oai-request-id");
2717
+ 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(
2718
+ (msg) => msg.role === "assistant" && Array.isArray(msg.content) && msg.content.some((part) => part.type === "raw" && isEncryptedReasoning(part.data))
2719
+ )) {
2720
+ providerDiag("codex_retry_without_encrypted_reasoning", { status: response.status });
2721
+ const messages = options.messages.map(
2722
+ (msg) => msg.role === "assistant" && Array.isArray(msg.content) ? {
2723
+ ...msg,
2724
+ content: msg.content.filter(
2725
+ (part) => !(part.type === "raw" && isEncryptedReasoning(part.data))
2726
+ )
2727
+ } : msg
2728
+ );
2729
+ return yield* runStream3({ ...options, messages }, true);
2730
+ }
2719
2731
  const usageLimit = codexUsageLimitError(parsed.errorObj, response.status, requestId);
2720
2732
  if (usageLimit) throw usageLimit;
2721
2733
  let hint;