@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.93
4
+
5
+ ### Patch Changes
6
+
7
+ - fa64d70: fix(openai): change web search tool action to be optional
8
+
9
+ ## 2.0.92
10
+
11
+ ### Patch Changes
12
+
13
+ - c680a01: fix(openai): add changeset and tests for per-image usage metadata
14
+
3
15
  ## 2.0.91
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -34,7 +34,7 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
34
34
  * An object describing the specific action taken in this web search call.
35
35
  * Includes details on how the model used the web (search, open_page, findInPage).
36
36
  */
37
- action: {
37
+ action?: {
38
38
  /**
39
39
  * Action type "search" - Performs a web search query.
40
40
  */
@@ -276,7 +276,7 @@ declare const openaiTools: {
276
276
  * @deprecated Use `webSearch` instead.
277
277
  */
278
278
  webSearchPreview: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{}, {
279
- action: {
279
+ action?: {
280
280
  type: "search";
281
281
  query?: string;
282
282
  } | {
@@ -308,7 +308,7 @@ declare const openaiTools: {
308
308
  * @param userLocation - The user location to use for the web search.
309
309
  */
310
310
  webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
311
- action: {
311
+ action?: {
312
312
  type: "search";
313
313
  query?: string;
314
314
  } | {
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
34
34
  * An object describing the specific action taken in this web search call.
35
35
  * Includes details on how the model used the web (search, open_page, findInPage).
36
36
  */
37
- action: {
37
+ action?: {
38
38
  /**
39
39
  * Action type "search" - Performs a web search query.
40
40
  */
@@ -276,7 +276,7 @@ declare const openaiTools: {
276
276
  * @deprecated Use `webSearch` instead.
277
277
  */
278
278
  webSearchPreview: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{}, {
279
- action: {
279
+ action?: {
280
280
  type: "search";
281
281
  query?: string;
282
282
  } | {
@@ -308,7 +308,7 @@ declare const openaiTools: {
308
308
  * @param userLocation - The user location to use for the web search.
309
309
  */
310
310
  webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
311
- action: {
311
+ action?: {
312
312
  type: "search";
313
313
  query?: string;
314
314
  } | {
package/dist/index.js CHANGED
@@ -1745,42 +1745,50 @@ var OpenAIImageModel = class {
1745
1745
  },
1746
1746
  providerMetadata: {
1747
1747
  openai: {
1748
- images: response.data.map((item, index) => {
1749
- var _a2;
1750
- return {
1751
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1752
- ...response.created != null ? { created: response.created } : {},
1753
- ...response.size != null ? { size: response.size } : {},
1754
- ...response.quality != null ? { quality: response.quality } : {},
1755
- ...response.background != null ? { background: response.background } : {},
1756
- ...response.output_format != null ? { outputFormat: response.output_format } : {},
1757
- ...distributeTokenDetails(
1758
- (_a2 = response.usage) == null ? void 0 : _a2.input_tokens_details,
1759
- index,
1760
- response.data.length
1761
- )
1762
- };
1763
- })
1748
+ images: response.data.map((item, index) => ({
1749
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1750
+ ...response.created != null ? { created: response.created } : {},
1751
+ ...response.size != null ? { size: response.size } : {},
1752
+ ...response.quality != null ? { quality: response.quality } : {},
1753
+ ...response.background != null ? { background: response.background } : {},
1754
+ ...response.output_format != null ? { outputFormat: response.output_format } : {},
1755
+ ...distributeTokenDetails(
1756
+ response.usage,
1757
+ index,
1758
+ response.data.length
1759
+ )
1760
+ }))
1764
1761
  }
1765
1762
  }
1766
1763
  };
1767
1764
  }
1768
1765
  };
1769
- function distributeTokenDetails(details, index, total) {
1770
- if (details == null) {
1766
+ function distributeTokenDetails(usage, index, total) {
1767
+ if (usage == null) {
1771
1768
  return {};
1772
1769
  }
1773
1770
  const result = {};
1774
- if (details.image_tokens != null) {
1771
+ const details = usage.input_tokens_details;
1772
+ if ((details == null ? void 0 : details.image_tokens) != null) {
1775
1773
  const base = Math.floor(details.image_tokens / total);
1776
1774
  const remainder = details.image_tokens - base * (total - 1);
1777
1775
  result.imageTokens = index === total - 1 ? remainder : base;
1778
1776
  }
1779
- if (details.text_tokens != null) {
1777
+ if ((details == null ? void 0 : details.text_tokens) != null) {
1780
1778
  const base = Math.floor(details.text_tokens / total);
1781
1779
  const remainder = details.text_tokens - base * (total - 1);
1782
1780
  result.textTokens = index === total - 1 ? remainder : base;
1783
1781
  }
1782
+ if (usage.input_tokens != null) {
1783
+ const base = Math.floor(usage.input_tokens / total);
1784
+ const remainder = usage.input_tokens - base * (total - 1);
1785
+ result.inputTokens = index === total - 1 ? remainder : base;
1786
+ }
1787
+ if (usage.output_tokens != null) {
1788
+ const base = Math.floor(usage.output_tokens / total);
1789
+ const remainder = usage.output_tokens - base * (total - 1);
1790
+ result.outputTokens = index === total - 1 ? remainder : base;
1791
+ }
1784
1792
  return result;
1785
1793
  }
1786
1794
 
@@ -1979,7 +1987,7 @@ var webSearchOutputSchema = (0, import_provider_utils18.lazySchema)(
1979
1987
  url: import_v413.z.string().nullish(),
1980
1988
  pattern: import_v413.z.string().nullish()
1981
1989
  })
1982
- ]),
1990
+ ]).optional(),
1983
1991
  sources: import_v413.z.array(
1984
1992
  import_v413.z.discriminatedUnion("type", [
1985
1993
  import_v413.z.object({ type: import_v413.z.literal("url"), url: import_v413.z.string() }),
@@ -2034,7 +2042,7 @@ var webSearchPreviewOutputSchema = (0, import_provider_utils19.lazySchema)(
2034
2042
  url: import_v414.z.string().nullish(),
2035
2043
  pattern: import_v414.z.string().nullish()
2036
2044
  })
2037
- ])
2045
+ ]).optional()
2038
2046
  })
2039
2047
  )
2040
2048
  );
@@ -2583,7 +2591,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2583
2591
  url: import_v416.z.string().nullish(),
2584
2592
  pattern: import_v416.z.string().nullish()
2585
2593
  })
2586
- ])
2594
+ ]).nullish()
2587
2595
  }),
2588
2596
  import_v416.z.object({
2589
2597
  type: import_v416.z.literal("file_search_call"),
@@ -2780,7 +2788,10 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2780
2788
  sources: import_v416.z.array(
2781
2789
  import_v416.z.discriminatedUnion("type", [
2782
2790
  import_v416.z.object({ type: import_v416.z.literal("url"), url: import_v416.z.string() }),
2783
- import_v416.z.object({ type: import_v416.z.literal("api"), name: import_v416.z.string() })
2791
+ import_v416.z.object({
2792
+ type: import_v416.z.literal("api"),
2793
+ name: import_v416.z.string()
2794
+ })
2784
2795
  ])
2785
2796
  ).nullish()
2786
2797
  }),
@@ -2793,7 +2804,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2793
2804
  url: import_v416.z.string().nullish(),
2794
2805
  pattern: import_v416.z.string().nullish()
2795
2806
  })
2796
- ])
2807
+ ]).nullish()
2797
2808
  }),
2798
2809
  import_v416.z.object({
2799
2810
  type: import_v416.z.literal("file_search_call"),
@@ -4217,6 +4228,9 @@ function isErrorChunk(chunk) {
4217
4228
  }
4218
4229
  function mapWebSearchOutput(action) {
4219
4230
  var _a;
4231
+ if (action == null) {
4232
+ return {};
4233
+ }
4220
4234
  switch (action.type) {
4221
4235
  case "search":
4222
4236
  return {
@@ -4590,7 +4604,7 @@ var OpenAITranscriptionModel = class {
4590
4604
  };
4591
4605
 
4592
4606
  // src/version.ts
4593
- var VERSION = true ? "2.0.91" : "0.0.0-test";
4607
+ var VERSION = true ? "2.0.93" : "0.0.0-test";
4594
4608
 
4595
4609
  // src/openai-provider.ts
4596
4610
  function createOpenAI(options = {}) {