@ai-sdk/openai 2.0.91 → 2.0.93

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.
@@ -493,7 +493,7 @@ declare const webSearchPreview: _ai_sdk_provider_utils.ProviderDefinedToolFactor
493
493
  * An object describing the specific action taken in this web search call.
494
494
  * Includes details on how the model used the web (search, open_page, findInPage).
495
495
  */
496
- action: {
496
+ action?: {
497
497
  /**
498
498
  * Action type "search" - Performs a web search query.
499
499
  */
@@ -493,7 +493,7 @@ declare const webSearchPreview: _ai_sdk_provider_utils.ProviderDefinedToolFactor
493
493
  * An object describing the specific action taken in this web search call.
494
494
  * Includes details on how the model used the web (search, open_page, findInPage).
495
495
  */
496
- action: {
496
+ action?: {
497
497
  /**
498
498
  * Action type "search" - Performs a web search query.
499
499
  */
@@ -1767,42 +1767,50 @@ var OpenAIImageModel = class {
1767
1767
  },
1768
1768
  providerMetadata: {
1769
1769
  openai: {
1770
- images: response.data.map((item, index) => {
1771
- var _a2;
1772
- return {
1773
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1774
- ...response.created != null ? { created: response.created } : {},
1775
- ...response.size != null ? { size: response.size } : {},
1776
- ...response.quality != null ? { quality: response.quality } : {},
1777
- ...response.background != null ? { background: response.background } : {},
1778
- ...response.output_format != null ? { outputFormat: response.output_format } : {},
1779
- ...distributeTokenDetails(
1780
- (_a2 = response.usage) == null ? void 0 : _a2.input_tokens_details,
1781
- index,
1782
- response.data.length
1783
- )
1784
- };
1785
- })
1770
+ images: response.data.map((item, index) => ({
1771
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1772
+ ...response.created != null ? { created: response.created } : {},
1773
+ ...response.size != null ? { size: response.size } : {},
1774
+ ...response.quality != null ? { quality: response.quality } : {},
1775
+ ...response.background != null ? { background: response.background } : {},
1776
+ ...response.output_format != null ? { outputFormat: response.output_format } : {},
1777
+ ...distributeTokenDetails(
1778
+ response.usage,
1779
+ index,
1780
+ response.data.length
1781
+ )
1782
+ }))
1786
1783
  }
1787
1784
  }
1788
1785
  };
1789
1786
  }
1790
1787
  };
1791
- function distributeTokenDetails(details, index, total) {
1792
- if (details == null) {
1788
+ function distributeTokenDetails(usage, index, total) {
1789
+ if (usage == null) {
1793
1790
  return {};
1794
1791
  }
1795
1792
  const result = {};
1796
- if (details.image_tokens != null) {
1793
+ const details = usage.input_tokens_details;
1794
+ if ((details == null ? void 0 : details.image_tokens) != null) {
1797
1795
  const base = Math.floor(details.image_tokens / total);
1798
1796
  const remainder = details.image_tokens - base * (total - 1);
1799
1797
  result.imageTokens = index === total - 1 ? remainder : base;
1800
1798
  }
1801
- if (details.text_tokens != null) {
1799
+ if ((details == null ? void 0 : details.text_tokens) != null) {
1802
1800
  const base = Math.floor(details.text_tokens / total);
1803
1801
  const remainder = details.text_tokens - base * (total - 1);
1804
1802
  result.textTokens = index === total - 1 ? remainder : base;
1805
1803
  }
1804
+ if (usage.input_tokens != null) {
1805
+ const base = Math.floor(usage.input_tokens / total);
1806
+ const remainder = usage.input_tokens - base * (total - 1);
1807
+ result.inputTokens = index === total - 1 ? remainder : base;
1808
+ }
1809
+ if (usage.output_tokens != null) {
1810
+ const base = Math.floor(usage.output_tokens / total);
1811
+ const remainder = usage.output_tokens - base * (total - 1);
1812
+ result.outputTokens = index === total - 1 ? remainder : base;
1813
+ }
1806
1814
  return result;
1807
1815
  }
1808
1816
 
@@ -2652,7 +2660,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2652
2660
  url: import_v414.z.string().nullish(),
2653
2661
  pattern: import_v414.z.string().nullish()
2654
2662
  })
2655
- ])
2663
+ ]).nullish()
2656
2664
  }),
2657
2665
  import_v414.z.object({
2658
2666
  type: import_v414.z.literal("file_search_call"),
@@ -2849,7 +2857,10 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2849
2857
  sources: import_v414.z.array(
2850
2858
  import_v414.z.discriminatedUnion("type", [
2851
2859
  import_v414.z.object({ type: import_v414.z.literal("url"), url: import_v414.z.string() }),
2852
- import_v414.z.object({ type: import_v414.z.literal("api"), name: import_v414.z.string() })
2860
+ import_v414.z.object({
2861
+ type: import_v414.z.literal("api"),
2862
+ name: import_v414.z.string()
2863
+ })
2853
2864
  ])
2854
2865
  ).nullish()
2855
2866
  }),
@@ -2862,7 +2873,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2862
2873
  url: import_v414.z.string().nullish(),
2863
2874
  pattern: import_v414.z.string().nullish()
2864
2875
  })
2865
- ])
2876
+ ]).nullish()
2866
2877
  }),
2867
2878
  import_v414.z.object({
2868
2879
  type: import_v414.z.literal("file_search_call"),
@@ -3224,7 +3235,7 @@ var webSearchOutputSchema = (0, import_provider_utils25.lazySchema)(
3224
3235
  url: import_v418.z.string().nullish(),
3225
3236
  pattern: import_v418.z.string().nullish()
3226
3237
  })
3227
- ]),
3238
+ ]).optional(),
3228
3239
  sources: import_v418.z.array(
3229
3240
  import_v418.z.discriminatedUnion("type", [
3230
3241
  import_v418.z.object({ type: import_v418.z.literal("url"), url: import_v418.z.string() }),
@@ -3278,7 +3289,7 @@ var webSearchPreviewOutputSchema = (0, import_provider_utils26.lazySchema)(
3278
3289
  url: import_v419.z.string().nullish(),
3279
3290
  pattern: import_v419.z.string().nullish()
3280
3291
  })
3281
- ])
3292
+ ]).optional()
3282
3293
  })
3283
3294
  )
3284
3295
  );
@@ -4521,6 +4532,9 @@ function isErrorChunk(chunk) {
4521
4532
  }
4522
4533
  function mapWebSearchOutput(action) {
4523
4534
  var _a;
4535
+ if (action == null) {
4536
+ return {};
4537
+ }
4524
4538
  switch (action.type) {
4525
4539
  case "search":
4526
4540
  return {