@ai-sdk/openai 2.0.136 → 2.0.138

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.
@@ -2005,7 +2005,12 @@ var openaiTranscriptionResponseSchema = lazyValidator9(
2005
2005
  compression_ratio: z10.number(),
2006
2006
  no_speech_prob: z10.number()
2007
2007
  })
2008
- ).nullish()
2008
+ ).nullish(),
2009
+ // Lenient: an unexpected usage shape must not fail the transcription.
2010
+ usage: z10.object({
2011
+ type: z10.string().nullish(),
2012
+ seconds: z10.number().nullish()
2013
+ }).nullish().catch(void 0)
2009
2014
  })
2010
2015
  )
2011
2016
  );
@@ -2141,10 +2146,10 @@ var OpenAITranscriptionModel = class {
2141
2146
  prompt: openAIOptions.prompt,
2142
2147
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
2143
2148
  // prefer verbose_json to get segments for models that support it
2144
- response_format: [
2145
- "gpt-4o-transcribe",
2146
- "gpt-4o-mini-transcribe"
2147
- ].includes(this.modelId) ? "json" : "verbose_json",
2149
+ // gpt-4o(-mini)-transcribe (incl. snapshots) and gpt-transcribe reject verbose_json:
2150
+ response_format: ["gpt-4o-transcribe", "gpt-4o-mini-transcribe"].includes(
2151
+ this.modelId
2152
+ ) || this.modelId.startsWith("gpt-4o-mini-transcribe-") || this.modelId === "gpt-transcribe" || this.modelId.startsWith("gpt-transcribe-") ? "json" : "verbose_json",
2148
2153
  temperature: openAIOptions.temperature,
2149
2154
  timestamp_granularities: openAIOptions.timestampGranularities
2150
2155
  };
@@ -2166,7 +2171,7 @@ var OpenAITranscriptionModel = class {
2166
2171
  };
2167
2172
  }
2168
2173
  async doGenerate(options) {
2169
- var _a2, _b, _c, _d, _e, _f, _g, _h;
2174
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2170
2175
  const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2171
2176
  const { formData, warnings } = await this.getArgs(options);
2172
2177
  const {
@@ -2200,7 +2205,8 @@ var OpenAITranscriptionModel = class {
2200
2205
  endSecond: word.end
2201
2206
  }))) != null ? _g : [],
2202
2207
  language,
2203
- durationInSeconds: (_h = response.duration) != null ? _h : void 0,
2208
+ // Duration-billed json responses report the duration only in `usage`:
2209
+ 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,
2204
2210
  warnings,
2205
2211
  response: {
2206
2212
  timestamp: currentDate,
@@ -4540,7 +4546,7 @@ var OpenAIResponsesLanguageModel = class {
4540
4546
  type: "tool-result",
4541
4547
  toolCallId: part.id,
4542
4548
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
4543
- result: mapWebSearchOutput(part.action),
4549
+ ...mapWebSearchResult(part),
4544
4550
  providerExecuted: true
4545
4551
  });
4546
4552
  break;
@@ -4872,7 +4878,7 @@ var OpenAIResponsesLanguageModel = class {
4872
4878
  type: "tool-result",
4873
4879
  toolCallId: value.item.id,
4874
4880
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
4875
- result: mapWebSearchOutput(value.item.action),
4881
+ ...mapWebSearchResult(value.item),
4876
4882
  providerExecuted: true
4877
4883
  });
4878
4884
  } else if (value.item.type === "computer_call") {
@@ -5201,6 +5207,12 @@ function isResponseAnnotationAddedChunk(chunk) {
5201
5207
  function isErrorChunk(chunk) {
5202
5208
  return chunk.type === "error";
5203
5209
  }
5210
+ function mapWebSearchResult({
5211
+ action,
5212
+ status
5213
+ }) {
5214
+ return status === "completed" ? { result: mapWebSearchOutput(action) } : { isError: true, result: { status } };
5215
+ }
5204
5216
  function mapWebSearchOutput(action) {
5205
5217
  var _a2;
5206
5218
  if (action == null) {