@ai-sdk/openai 2.0.50 → 2.0.52

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
@@ -1954,7 +1954,7 @@ var localShell = createProviderDefinedToolFactoryWithOutputSchema4({
1954
1954
 
1955
1955
  // src/tool/web-search.ts
1956
1956
  import {
1957
- createProviderDefinedToolFactory,
1957
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema5,
1958
1958
  lazySchema as lazySchema5,
1959
1959
  zodSchema as zodSchema12
1960
1960
  } from "@ai-sdk/provider-utils";
@@ -1962,9 +1962,7 @@ import { z as z13 } from "zod/v4";
1962
1962
  var webSearchArgsSchema = lazySchema5(
1963
1963
  () => zodSchema12(
1964
1964
  z13.object({
1965
- filters: z13.object({
1966
- allowedDomains: z13.array(z13.string()).optional()
1967
- }).optional(),
1965
+ filters: z13.object({ allowedDomains: z13.array(z13.string()).optional() }).optional(),
1968
1966
  searchContextSize: z13.enum(["low", "medium", "high"]).optional(),
1969
1967
  userLocation: z13.object({
1970
1968
  type: z13.literal("approximate"),
@@ -1976,16 +1974,17 @@ var webSearchArgsSchema = lazySchema5(
1976
1974
  })
1977
1975
  )
1978
1976
  );
1979
- var webSearchInputSchema = lazySchema5(
1977
+ var webSearchInputSchema = lazySchema5(() => zodSchema12(z13.object({})));
1978
+ var webSearchOutputSchema = lazySchema5(
1980
1979
  () => zodSchema12(
1981
1980
  z13.object({
1982
1981
  action: z13.discriminatedUnion("type", [
1983
1982
  z13.object({
1984
1983
  type: z13.literal("search"),
1985
- query: z13.string().nullish()
1984
+ query: z13.string().optional()
1986
1985
  }),
1987
1986
  z13.object({
1988
- type: z13.literal("open_page"),
1987
+ type: z13.literal("openPage"),
1989
1988
  url: z13.string()
1990
1989
  }),
1991
1990
  z13.object({
@@ -1993,22 +1992,21 @@ var webSearchInputSchema = lazySchema5(
1993
1992
  url: z13.string(),
1994
1993
  pattern: z13.string()
1995
1994
  })
1996
- ]).nullish()
1995
+ ])
1997
1996
  })
1998
1997
  )
1999
1998
  );
2000
- var webSearchToolFactory = createProviderDefinedToolFactory({
1999
+ var webSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema5({
2001
2000
  id: "openai.web_search",
2002
2001
  name: "web_search",
2003
- inputSchema: webSearchInputSchema
2002
+ inputSchema: webSearchInputSchema,
2003
+ outputSchema: webSearchOutputSchema
2004
2004
  });
2005
- var webSearch = (args = {}) => {
2006
- return webSearchToolFactory(args);
2007
- };
2005
+ var webSearch = (args = {}) => webSearchToolFactory(args);
2008
2006
 
2009
2007
  // src/tool/web-search-preview.ts
2010
2008
  import {
2011
- createProviderDefinedToolFactory as createProviderDefinedToolFactory2,
2009
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema6,
2012
2010
  lazySchema as lazySchema6,
2013
2011
  zodSchema as zodSchema13
2014
2012
  } from "@ai-sdk/provider-utils";
@@ -2016,51 +2014,30 @@ import { z as z14 } from "zod/v4";
2016
2014
  var webSearchPreviewArgsSchema = lazySchema6(
2017
2015
  () => zodSchema13(
2018
2016
  z14.object({
2019
- /**
2020
- * Search context size to use for the web search.
2021
- * - high: Most comprehensive context, highest cost, slower response
2022
- * - medium: Balanced context, cost, and latency (default)
2023
- * - low: Least context, lowest cost, fastest response
2024
- */
2025
2017
  searchContextSize: z14.enum(["low", "medium", "high"]).optional(),
2026
- /**
2027
- * User location information to provide geographically relevant search results.
2028
- */
2029
2018
  userLocation: z14.object({
2030
- /**
2031
- * Type of location (always 'approximate')
2032
- */
2033
2019
  type: z14.literal("approximate"),
2034
- /**
2035
- * Two-letter ISO country code (e.g., 'US', 'GB')
2036
- */
2037
2020
  country: z14.string().optional(),
2038
- /**
2039
- * City name (free text, e.g., 'Minneapolis')
2040
- */
2041
2021
  city: z14.string().optional(),
2042
- /**
2043
- * Region name (free text, e.g., 'Minnesota')
2044
- */
2045
2022
  region: z14.string().optional(),
2046
- /**
2047
- * IANA timezone (e.g., 'America/Chicago')
2048
- */
2049
2023
  timezone: z14.string().optional()
2050
2024
  }).optional()
2051
2025
  })
2052
2026
  )
2053
2027
  );
2054
2028
  var webSearchPreviewInputSchema = lazySchema6(
2029
+ () => zodSchema13(z14.object({}))
2030
+ );
2031
+ var webSearchPreviewOutputSchema = lazySchema6(
2055
2032
  () => zodSchema13(
2056
2033
  z14.object({
2057
2034
  action: z14.discriminatedUnion("type", [
2058
2035
  z14.object({
2059
2036
  type: z14.literal("search"),
2060
- query: z14.string().nullish()
2037
+ query: z14.string().optional()
2061
2038
  }),
2062
2039
  z14.object({
2063
- type: z14.literal("open_page"),
2040
+ type: z14.literal("openPage"),
2064
2041
  url: z14.string()
2065
2042
  }),
2066
2043
  z14.object({
@@ -2068,14 +2045,15 @@ var webSearchPreviewInputSchema = lazySchema6(
2068
2045
  url: z14.string(),
2069
2046
  pattern: z14.string()
2070
2047
  })
2071
- ]).nullish()
2048
+ ])
2072
2049
  })
2073
2050
  )
2074
2051
  );
2075
- var webSearchPreview = createProviderDefinedToolFactory2({
2052
+ var webSearchPreview = createProviderDefinedToolFactoryWithOutputSchema6({
2076
2053
  id: "openai.web_search_preview",
2077
2054
  name: "web_search_preview",
2078
- inputSchema: webSearchPreviewInputSchema
2055
+ inputSchema: webSearchPreviewInputSchema,
2056
+ outputSchema: webSearchPreviewOutputSchema
2079
2057
  });
2080
2058
 
2081
2059
  // src/openai-tools.ts
@@ -2370,6 +2348,9 @@ async function convertToOpenAIResponsesInput({
2370
2348
  input.push(reasoningMessages[reasoningId]);
2371
2349
  } else {
2372
2350
  reasoningMessage.summary.push(...summaryParts);
2351
+ if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
2352
+ reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
2353
+ }
2373
2354
  }
2374
2355
  }
2375
2356
  } else {
@@ -2539,11 +2520,7 @@ var openaiResponsesChunkSchema = lazyValidator8(
2539
2520
  z16.object({
2540
2521
  type: z16.literal("web_search_call"),
2541
2522
  id: z16.string(),
2542
- status: z16.string(),
2543
- action: z16.object({
2544
- type: z16.literal("search"),
2545
- query: z16.string().optional()
2546
- }).nullish()
2523
+ status: z16.string()
2547
2524
  }),
2548
2525
  z16.object({
2549
2526
  type: z16.literal("computer_call"),
@@ -2629,7 +2606,7 @@ var openaiResponsesChunkSchema = lazyValidator8(
2629
2606
  url: z16.string(),
2630
2607
  pattern: z16.string()
2631
2608
  })
2632
- ]).nullish()
2609
+ ])
2633
2610
  }),
2634
2611
  z16.object({
2635
2612
  type: z16.literal("file_search_call"),
@@ -2719,6 +2696,11 @@ var openaiResponsesChunkSchema = lazyValidator8(
2719
2696
  summary_index: z16.number(),
2720
2697
  delta: z16.string()
2721
2698
  }),
2699
+ z16.object({
2700
+ type: z16.literal("response.reasoning_summary_part.done"),
2701
+ item_id: z16.string(),
2702
+ summary_index: z16.number()
2703
+ }),
2722
2704
  z16.object({
2723
2705
  type: z16.literal("error"),
2724
2706
  code: z16.string(),
@@ -2810,7 +2792,7 @@ var openaiResponsesResponseSchema = lazyValidator8(
2810
2792
  url: z16.string(),
2811
2793
  pattern: z16.string()
2812
2794
  })
2813
- ]).nullish()
2795
+ ])
2814
2796
  }),
2815
2797
  z16.object({
2816
2798
  type: z16.literal("file_search_call"),
@@ -3358,7 +3340,8 @@ var OpenAIResponsesLanguageModel = class {
3358
3340
  tools: openaiTools2,
3359
3341
  tool_choice: openaiToolChoice
3360
3342
  },
3361
- warnings: [...warnings, ...toolWarnings]
3343
+ warnings: [...warnings, ...toolWarnings],
3344
+ store
3362
3345
  };
3363
3346
  }
3364
3347
  async doGenerate(options) {
@@ -3513,14 +3496,14 @@ var OpenAIResponsesLanguageModel = class {
3513
3496
  type: "tool-call",
3514
3497
  toolCallId: part.id,
3515
3498
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3516
- input: JSON.stringify({ action: part.action }),
3499
+ input: JSON.stringify({}),
3517
3500
  providerExecuted: true
3518
3501
  });
3519
3502
  content.push({
3520
3503
  type: "tool-result",
3521
3504
  toolCallId: part.id,
3522
3505
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3523
- result: { status: part.status },
3506
+ result: mapWebSearchOutput(part.action),
3524
3507
  providerExecuted: true
3525
3508
  });
3526
3509
  break;
@@ -3633,7 +3616,8 @@ var OpenAIResponsesLanguageModel = class {
3633
3616
  const {
3634
3617
  args: body,
3635
3618
  warnings,
3636
- webSearchToolName
3619
+ webSearchToolName,
3620
+ store
3637
3621
  } = await this.getArgs(options);
3638
3622
  const { responseHeaders, value: response } = await postJsonToApi5({
3639
3623
  url: this.config.url({
@@ -3672,7 +3656,7 @@ var OpenAIResponsesLanguageModel = class {
3672
3656
  controller.enqueue({ type: "stream-start", warnings });
3673
3657
  },
3674
3658
  transform(chunk, controller) {
3675
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3659
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3676
3660
  if (options.includeRawChunks) {
3677
3661
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3678
3662
  }
@@ -3704,6 +3688,17 @@ var OpenAIResponsesLanguageModel = class {
3704
3688
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3705
3689
  providerExecuted: true
3706
3690
  });
3691
+ controller.enqueue({
3692
+ type: "tool-input-end",
3693
+ id: value.item.id
3694
+ });
3695
+ controller.enqueue({
3696
+ type: "tool-call",
3697
+ toolCallId: value.item.id,
3698
+ toolName: "web_search",
3699
+ input: JSON.stringify({}),
3700
+ providerExecuted: true
3701
+ });
3707
3702
  } else if (value.item.type === "computer_call") {
3708
3703
  ongoingToolCalls[value.output_index] = {
3709
3704
  toolName: "computer_use",
@@ -3760,10 +3755,10 @@ var OpenAIResponsesLanguageModel = class {
3760
3755
  }
3761
3756
  }
3762
3757
  });
3763
- } else if (isResponseOutputItemAddedReasoningChunk(value)) {
3758
+ } else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
3764
3759
  activeReasoning[value.item.id] = {
3765
3760
  encryptedContent: value.item.encrypted_content,
3766
- summaryParts: [0]
3761
+ summaryParts: { 0: "active" }
3767
3762
  };
3768
3763
  controller.enqueue({
3769
3764
  type: "reasoning-start",
@@ -3797,22 +3792,11 @@ var OpenAIResponsesLanguageModel = class {
3797
3792
  });
3798
3793
  } else if (value.item.type === "web_search_call") {
3799
3794
  ongoingToolCalls[value.output_index] = void 0;
3800
- controller.enqueue({
3801
- type: "tool-input-end",
3802
- id: value.item.id
3803
- });
3804
- controller.enqueue({
3805
- type: "tool-call",
3806
- toolCallId: value.item.id,
3807
- toolName: "web_search",
3808
- input: JSON.stringify({ action: value.item.action }),
3809
- providerExecuted: true
3810
- });
3811
3795
  controller.enqueue({
3812
3796
  type: "tool-result",
3813
3797
  toolCallId: value.item.id,
3814
3798
  toolName: "web_search",
3815
- result: { status: value.item.status },
3799
+ result: mapWebSearchOutput(value.item.action),
3816
3800
  providerExecuted: true
3817
3801
  });
3818
3802
  } else if (value.item.type === "computer_call") {
@@ -3902,9 +3886,14 @@ var OpenAIResponsesLanguageModel = class {
3902
3886
  type: "text-end",
3903
3887
  id: value.item.id
3904
3888
  });
3905
- } else if (isResponseOutputItemDoneReasoningChunk(value)) {
3889
+ } else if (value.item.type === "reasoning") {
3906
3890
  const activeReasoningPart = activeReasoning[value.item.id];
3907
- for (const summaryIndex of activeReasoningPart.summaryParts) {
3891
+ const summaryPartIndices = Object.entries(
3892
+ activeReasoningPart.summaryParts
3893
+ ).filter(
3894
+ ([_, status]) => status === "active" || status === "can-conclude"
3895
+ ).map(([summaryIndex]) => summaryIndex);
3896
+ for (const summaryIndex of summaryPartIndices) {
3908
3897
  controller.enqueue({
3909
3898
  type: "reasoning-end",
3910
3899
  id: `${value.item.id}:${summaryIndex}`,
@@ -3978,23 +3967,34 @@ var OpenAIResponsesLanguageModel = class {
3978
3967
  if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
3979
3968
  logprobs.push(value.logprobs);
3980
3969
  }
3981
- } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
3970
+ } else if (value.type === "response.reasoning_summary_part.added") {
3982
3971
  if (value.summary_index > 0) {
3983
- (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.summaryParts.push(
3984
- value.summary_index
3985
- );
3972
+ const activeReasoningPart = activeReasoning[value.item_id];
3973
+ activeReasoningPart.summaryParts[value.summary_index] = "active";
3974
+ for (const summaryIndex of Object.keys(
3975
+ activeReasoningPart.summaryParts
3976
+ )) {
3977
+ if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
3978
+ controller.enqueue({
3979
+ type: "reasoning-end",
3980
+ id: `${value.item_id}:${summaryIndex}`,
3981
+ providerMetadata: { openai: { itemId: value.item_id } }
3982
+ });
3983
+ activeReasoningPart.summaryParts[summaryIndex] = "concluded";
3984
+ }
3985
+ }
3986
3986
  controller.enqueue({
3987
3987
  type: "reasoning-start",
3988
3988
  id: `${value.item_id}:${value.summary_index}`,
3989
3989
  providerMetadata: {
3990
3990
  openai: {
3991
3991
  itemId: value.item_id,
3992
- reasoningEncryptedContent: (_i = (_h = activeReasoning[value.item_id]) == null ? void 0 : _h.encryptedContent) != null ? _i : null
3992
+ reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
3993
3993
  }
3994
3994
  }
3995
3995
  });
3996
3996
  }
3997
- } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
3997
+ } else if (value.type === "response.reasoning_summary_text.delta") {
3998
3998
  controller.enqueue({
3999
3999
  type: "reasoning-delta",
4000
4000
  id: `${value.item_id}:${value.summary_index}`,
@@ -4005,16 +4005,29 @@ var OpenAIResponsesLanguageModel = class {
4005
4005
  }
4006
4006
  }
4007
4007
  });
4008
+ } else if (value.type === "response.reasoning_summary_part.done") {
4009
+ if (store) {
4010
+ controller.enqueue({
4011
+ type: "reasoning-end",
4012
+ id: `${value.item_id}:${value.summary_index}`,
4013
+ providerMetadata: {
4014
+ openai: { itemId: value.item_id }
4015
+ }
4016
+ });
4017
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
4018
+ } else {
4019
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
4020
+ }
4008
4021
  } else if (isResponseFinishedChunk(value)) {
4009
4022
  finishReason = mapOpenAIResponseFinishReason({
4010
- finishReason: (_j = value.response.incomplete_details) == null ? void 0 : _j.reason,
4023
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4011
4024
  hasFunctionCall
4012
4025
  });
4013
4026
  usage.inputTokens = value.response.usage.input_tokens;
4014
4027
  usage.outputTokens = value.response.usage.output_tokens;
4015
4028
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
4016
- usage.reasoningTokens = (_l = (_k = value.response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0;
4017
- usage.cachedInputTokens = (_n = (_m = value.response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0;
4029
+ usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
4030
+ usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
4018
4031
  if (typeof value.response.service_tier === "string") {
4019
4032
  serviceTier = value.response.service_tier;
4020
4033
  }
@@ -4023,7 +4036,7 @@ var OpenAIResponsesLanguageModel = class {
4023
4036
  controller.enqueue({
4024
4037
  type: "source",
4025
4038
  sourceType: "url",
4026
- id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
4039
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
4027
4040
  url: value.annotation.url,
4028
4041
  title: value.annotation.title
4029
4042
  });
@@ -4031,10 +4044,10 @@ var OpenAIResponsesLanguageModel = class {
4031
4044
  controller.enqueue({
4032
4045
  type: "source",
4033
4046
  sourceType: "document",
4034
- id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
4047
+ id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
4035
4048
  mediaType: "text/plain",
4036
- title: (_v = (_u = value.annotation.quote) != null ? _u : value.annotation.filename) != null ? _v : "Document",
4037
- filename: (_w = value.annotation.filename) != null ? _w : value.annotation.file_id
4049
+ title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
4050
+ filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id
4038
4051
  });
4039
4052
  }
4040
4053
  } else if (isErrorChunk(value)) {
@@ -4073,9 +4086,6 @@ function isTextDeltaChunk(chunk) {
4073
4086
  function isResponseOutputItemDoneChunk(chunk) {
4074
4087
  return chunk.type === "response.output_item.done";
4075
4088
  }
4076
- function isResponseOutputItemDoneReasoningChunk(chunk) {
4077
- return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
4078
- }
4079
4089
  function isResponseFinishedChunk(chunk) {
4080
4090
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
4081
4091
  }
@@ -4094,18 +4104,9 @@ function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
4094
4104
  function isResponseOutputItemAddedChunk(chunk) {
4095
4105
  return chunk.type === "response.output_item.added";
4096
4106
  }
4097
- function isResponseOutputItemAddedReasoningChunk(chunk) {
4098
- return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
4099
- }
4100
4107
  function isResponseAnnotationAddedChunk(chunk) {
4101
4108
  return chunk.type === "response.output_text.annotation.added";
4102
4109
  }
4103
- function isResponseReasoningSummaryPartAddedChunk(chunk) {
4104
- return chunk.type === "response.reasoning_summary_part.added";
4105
- }
4106
- function isResponseReasoningSummaryTextDeltaChunk(chunk) {
4107
- return chunk.type === "response.reasoning_summary_text.delta";
4108
- }
4109
4110
  function isErrorChunk(chunk) {
4110
4111
  return chunk.type === "error";
4111
4112
  }
@@ -4143,6 +4144,19 @@ function getResponsesModelConfig(modelId) {
4143
4144
  isReasoningModel: false
4144
4145
  };
4145
4146
  }
4147
+ function mapWebSearchOutput(action) {
4148
+ var _a;
4149
+ switch (action.type) {
4150
+ case "search":
4151
+ return { action: { type: "search", query: (_a = action.query) != null ? _a : void 0 } };
4152
+ case "open_page":
4153
+ return { action: { type: "openPage", url: action.url } };
4154
+ case "find":
4155
+ return {
4156
+ action: { type: "find", url: action.url, pattern: action.pattern }
4157
+ };
4158
+ }
4159
+ }
4146
4160
 
4147
4161
  // src/speech/openai-speech-model.ts
4148
4162
  import {
@@ -4515,7 +4529,7 @@ var OpenAITranscriptionModel = class {
4515
4529
  };
4516
4530
 
4517
4531
  // src/version.ts
4518
- var VERSION = true ? "2.0.50" : "0.0.0-test";
4532
+ var VERSION = true ? "2.0.52" : "0.0.0-test";
4519
4533
 
4520
4534
  // src/openai-provider.ts
4521
4535
  function createOpenAI(options = {}) {