@ai-sdk/openai 2.0.135 → 2.0.137

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.
@@ -65,7 +65,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
65
65
  // src/openai-error.ts
66
66
  var import_v4 = require("zod/v4");
67
67
  var import_provider_utils = require("@ai-sdk/provider-utils");
68
- var openaiErrorDataSchema = import_v4.z.object({
68
+ var openaiErrorDataSchema = () => import_v4.z.object({
69
69
  error: import_v4.z.object({
70
70
  message: import_v4.z.string(),
71
71
  // The additional information below is handled loosely to support
@@ -76,8 +76,11 @@ var openaiErrorDataSchema = import_v4.z.object({
76
76
  code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
77
77
  })
78
78
  });
79
+ var openaiErrorDataSchemaValidator = (0, import_provider_utils.lazySchema)(
80
+ () => (0, import_provider_utils.zodSchema)(openaiErrorDataSchema())
81
+ );
79
82
  var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
80
- errorSchema: openaiErrorDataSchema,
83
+ errorSchema: openaiErrorDataSchemaValidator,
81
84
  errorToMessage: (data) => data.error.message
82
85
  });
83
86
 
@@ -547,7 +550,7 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
547
550
  }).nullish()
548
551
  }).nullish()
549
552
  }),
550
- openaiErrorDataSchema
553
+ openaiErrorDataSchema()
551
554
  ])
552
555
  )
553
556
  );
@@ -1350,7 +1353,7 @@ var openaiCompletionChunkSchema = (0, import_provider_utils6.lazyValidator)(
1350
1353
  total_tokens: import_v44.z.number()
1351
1354
  }).nullish()
1352
1355
  }),
1353
- openaiErrorDataSchema
1356
+ openaiErrorDataSchema()
1354
1357
  ])
1355
1358
  )
1356
1359
  );
@@ -1790,7 +1793,7 @@ function getMaxImagesPerCall(modelId) {
1790
1793
  var _a2;
1791
1794
  return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
1792
1795
  }
1793
- var baseImageModelOptionsObject = import_v49.z.object({
1796
+ var baseImageModelOptionsObject = () => import_v49.z.object({
1794
1797
  /**
1795
1798
  * Quality of the generated image(s).
1796
1799
  *
@@ -1820,11 +1823,11 @@ var baseImageModelOptionsObject = import_v49.z.object({
1820
1823
  user: import_v49.z.string().optional()
1821
1824
  });
1822
1825
  var openaiImageModelOptions = (0, import_provider_utils13.lazyValidator)(
1823
- () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject)
1826
+ () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
1824
1827
  );
1825
1828
  var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazyValidator)(
1826
1829
  () => (0, import_provider_utils13.zodSchema)(
1827
- baseImageModelOptionsObject.extend({
1830
+ baseImageModelOptionsObject().extend({
1828
1831
  /**
1829
1832
  * Style of the generated image. `vivid` produces hyper-real and
1830
1833
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -1997,7 +2000,12 @@ var openaiTranscriptionResponseSchema = (0, import_provider_utils15.lazyValidato
1997
2000
  compression_ratio: import_v410.z.number(),
1998
2001
  no_speech_prob: import_v410.z.number()
1999
2002
  })
2000
- ).nullish()
2003
+ ).nullish(),
2004
+ // Lenient: an unexpected usage shape must not fail the transcription.
2005
+ usage: import_v410.z.object({
2006
+ type: import_v410.z.string().nullish(),
2007
+ seconds: import_v410.z.number().nullish()
2008
+ }).nullish().catch(void 0)
2001
2009
  })
2002
2010
  )
2003
2011
  );
@@ -2130,10 +2138,10 @@ var OpenAITranscriptionModel = class {
2130
2138
  prompt: openAIOptions.prompt,
2131
2139
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
2132
2140
  // prefer verbose_json to get segments for models that support it
2133
- response_format: [
2134
- "gpt-4o-transcribe",
2135
- "gpt-4o-mini-transcribe"
2136
- ].includes(this.modelId) ? "json" : "verbose_json",
2141
+ // gpt-4o(-mini)-transcribe (incl. snapshots) and gpt-transcribe reject verbose_json:
2142
+ response_format: ["gpt-4o-transcribe", "gpt-4o-mini-transcribe"].includes(
2143
+ this.modelId
2144
+ ) || this.modelId.startsWith("gpt-4o-mini-transcribe-") || this.modelId === "gpt-transcribe" || this.modelId.startsWith("gpt-transcribe-") ? "json" : "verbose_json",
2137
2145
  temperature: openAIOptions.temperature,
2138
2146
  timestamp_granularities: openAIOptions.timestampGranularities
2139
2147
  };
@@ -2155,7 +2163,7 @@ var OpenAITranscriptionModel = class {
2155
2163
  };
2156
2164
  }
2157
2165
  async doGenerate(options) {
2158
- var _a2, _b, _c, _d, _e, _f, _g, _h;
2166
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2159
2167
  const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2160
2168
  const { formData, warnings } = await this.getArgs(options);
2161
2169
  const {
@@ -2189,7 +2197,8 @@ var OpenAITranscriptionModel = class {
2189
2197
  endSecond: word.end
2190
2198
  }))) != null ? _g : [],
2191
2199
  language,
2192
- durationInSeconds: (_h = response.duration) != null ? _h : void 0,
2200
+ // Duration-billed json responses report the duration only in `usage`:
2201
+ durationInSeconds: (_j = response.duration) != null ? _j : ((_h = response.usage) == null ? void 0 : _h.type) === "duration" ? (_i = response.usage.seconds) != null ? _i : void 0 : void 0,
2193
2202
  warnings,
2194
2203
  response: {
2195
2204
  timestamp: currentDate,
@@ -3081,10 +3090,14 @@ async function convertToOpenAIResponsesInput({
3081
3090
  }
3082
3091
  return { input, warnings };
3083
3092
  }
3084
- var openaiResponsesReasoningProviderOptionsSchema = import_v416.z.object({
3085
- itemId: import_v416.z.string().nullish(),
3086
- reasoningEncryptedContent: import_v416.z.string().nullish()
3087
- });
3093
+ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils23.lazySchema)(
3094
+ () => (0, import_provider_utils23.zodSchema)(
3095
+ import_v416.z.object({
3096
+ itemId: import_v416.z.string().nullish(),
3097
+ reasoningEncryptedContent: import_v416.z.string().nullish()
3098
+ })
3099
+ )
3100
+ );
3088
3101
 
3089
3102
  // src/responses/map-openai-responses-finish-reason.ts
3090
3103
  function mapOpenAIResponseFinishReason({
@@ -3642,15 +3655,16 @@ var codeInterpreter = (args = {}) => {
3642
3655
  // src/tool/file-search.ts
3643
3656
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
3644
3657
  var import_v419 = require("zod/v4");
3645
- var comparisonFilterSchema = import_v419.z.object({
3658
+ var comparisonFilterSchema = () => import_v419.z.object({
3646
3659
  key: import_v419.z.string(),
3647
3660
  type: import_v419.z.enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
3648
3661
  value: import_v419.z.union([import_v419.z.string(), import_v419.z.number(), import_v419.z.boolean(), import_v419.z.array(import_v419.z.string())])
3649
3662
  });
3650
- var compoundFilterSchema = import_v419.z.object({
3663
+ var cachedCompoundFilterSchema;
3664
+ var compoundFilterSchema = () => cachedCompoundFilterSchema != null ? cachedCompoundFilterSchema : cachedCompoundFilterSchema = import_v419.z.object({
3651
3665
  type: import_v419.z.enum(["and", "or"]),
3652
3666
  filters: import_v419.z.array(
3653
- import_v419.z.union([comparisonFilterSchema, import_v419.z.lazy(() => compoundFilterSchema)])
3667
+ import_v419.z.union([comparisonFilterSchema(), import_v419.z.lazy(() => compoundFilterSchema())])
3654
3668
  )
3655
3669
  });
3656
3670
  var fileSearchArgsSchema = (0, import_provider_utils26.lazySchema)(
@@ -3662,7 +3676,7 @@ var fileSearchArgsSchema = (0, import_provider_utils26.lazySchema)(
3662
3676
  ranker: import_v419.z.string().optional(),
3663
3677
  scoreThreshold: import_v419.z.number().optional()
3664
3678
  }).optional(),
3665
- filters: import_v419.z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
3679
+ filters: import_v419.z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
3666
3680
  })
3667
3681
  )
3668
3682
  );