@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.
package/dist/index.mjs CHANGED
@@ -1771,42 +1771,50 @@ var OpenAIImageModel = class {
1771
1771
  },
1772
1772
  providerMetadata: {
1773
1773
  openai: {
1774
- images: response.data.map((item, index) => {
1775
- var _a2;
1776
- return {
1777
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1778
- ...response.created != null ? { created: response.created } : {},
1779
- ...response.size != null ? { size: response.size } : {},
1780
- ...response.quality != null ? { quality: response.quality } : {},
1781
- ...response.background != null ? { background: response.background } : {},
1782
- ...response.output_format != null ? { outputFormat: response.output_format } : {},
1783
- ...distributeTokenDetails(
1784
- (_a2 = response.usage) == null ? void 0 : _a2.input_tokens_details,
1785
- index,
1786
- response.data.length
1787
- )
1788
- };
1789
- })
1774
+ images: response.data.map((item, index) => ({
1775
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1776
+ ...response.created != null ? { created: response.created } : {},
1777
+ ...response.size != null ? { size: response.size } : {},
1778
+ ...response.quality != null ? { quality: response.quality } : {},
1779
+ ...response.background != null ? { background: response.background } : {},
1780
+ ...response.output_format != null ? { outputFormat: response.output_format } : {},
1781
+ ...distributeTokenDetails(
1782
+ response.usage,
1783
+ index,
1784
+ response.data.length
1785
+ )
1786
+ }))
1790
1787
  }
1791
1788
  }
1792
1789
  };
1793
1790
  }
1794
1791
  };
1795
- function distributeTokenDetails(details, index, total) {
1796
- if (details == null) {
1792
+ function distributeTokenDetails(usage, index, total) {
1793
+ if (usage == null) {
1797
1794
  return {};
1798
1795
  }
1799
1796
  const result = {};
1800
- if (details.image_tokens != null) {
1797
+ const details = usage.input_tokens_details;
1798
+ if ((details == null ? void 0 : details.image_tokens) != null) {
1801
1799
  const base = Math.floor(details.image_tokens / total);
1802
1800
  const remainder = details.image_tokens - base * (total - 1);
1803
1801
  result.imageTokens = index === total - 1 ? remainder : base;
1804
1802
  }
1805
- if (details.text_tokens != null) {
1803
+ if ((details == null ? void 0 : details.text_tokens) != null) {
1806
1804
  const base = Math.floor(details.text_tokens / total);
1807
1805
  const remainder = details.text_tokens - base * (total - 1);
1808
1806
  result.textTokens = index === total - 1 ? remainder : base;
1809
1807
  }
1808
+ if (usage.input_tokens != null) {
1809
+ const base = Math.floor(usage.input_tokens / total);
1810
+ const remainder = usage.input_tokens - base * (total - 1);
1811
+ result.inputTokens = index === total - 1 ? remainder : base;
1812
+ }
1813
+ if (usage.output_tokens != null) {
1814
+ const base = Math.floor(usage.output_tokens / total);
1815
+ const remainder = usage.output_tokens - base * (total - 1);
1816
+ result.outputTokens = index === total - 1 ? remainder : base;
1817
+ }
1810
1818
  return result;
1811
1819
  }
1812
1820
 
@@ -2025,7 +2033,7 @@ var webSearchOutputSchema = lazySchema5(
2025
2033
  url: z13.string().nullish(),
2026
2034
  pattern: z13.string().nullish()
2027
2035
  })
2028
- ]),
2036
+ ]).optional(),
2029
2037
  sources: z13.array(
2030
2038
  z13.discriminatedUnion("type", [
2031
2039
  z13.object({ type: z13.literal("url"), url: z13.string() }),
@@ -2084,7 +2092,7 @@ var webSearchPreviewOutputSchema = lazySchema6(
2084
2092
  url: z14.string().nullish(),
2085
2093
  pattern: z14.string().nullish()
2086
2094
  })
2087
- ])
2095
+ ]).optional()
2088
2096
  })
2089
2097
  )
2090
2098
  );
@@ -2651,7 +2659,7 @@ var openaiResponsesChunkSchema = lazyValidator8(
2651
2659
  url: z16.string().nullish(),
2652
2660
  pattern: z16.string().nullish()
2653
2661
  })
2654
- ])
2662
+ ]).nullish()
2655
2663
  }),
2656
2664
  z16.object({
2657
2665
  type: z16.literal("file_search_call"),
@@ -2848,7 +2856,10 @@ var openaiResponsesResponseSchema = lazyValidator8(
2848
2856
  sources: z16.array(
2849
2857
  z16.discriminatedUnion("type", [
2850
2858
  z16.object({ type: z16.literal("url"), url: z16.string() }),
2851
- z16.object({ type: z16.literal("api"), name: z16.string() })
2859
+ z16.object({
2860
+ type: z16.literal("api"),
2861
+ name: z16.string()
2862
+ })
2852
2863
  ])
2853
2864
  ).nullish()
2854
2865
  }),
@@ -2861,7 +2872,7 @@ var openaiResponsesResponseSchema = lazyValidator8(
2861
2872
  url: z16.string().nullish(),
2862
2873
  pattern: z16.string().nullish()
2863
2874
  })
2864
- ])
2875
+ ]).nullish()
2865
2876
  }),
2866
2877
  z16.object({
2867
2878
  type: z16.literal("file_search_call"),
@@ -4290,6 +4301,9 @@ function isErrorChunk(chunk) {
4290
4301
  }
4291
4302
  function mapWebSearchOutput(action) {
4292
4303
  var _a;
4304
+ if (action == null) {
4305
+ return {};
4306
+ }
4293
4307
  switch (action.type) {
4294
4308
  case "search":
4295
4309
  return {
@@ -4681,7 +4695,7 @@ var OpenAITranscriptionModel = class {
4681
4695
  };
4682
4696
 
4683
4697
  // src/version.ts
4684
- var VERSION = true ? "2.0.91" : "0.0.0-test";
4698
+ var VERSION = true ? "2.0.93" : "0.0.0-test";
4685
4699
 
4686
4700
  // src/openai-provider.ts
4687
4701
  function createOpenAI(options = {}) {