@ai-sdk/openai 3.0.0-beta.27 → 3.0.0-beta.29

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
@@ -1943,7 +1943,7 @@ var localShell = createProviderDefinedToolFactoryWithOutputSchema4({
1943
1943
 
1944
1944
  // src/tool/web-search.ts
1945
1945
  import {
1946
- createProviderDefinedToolFactory,
1946
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema5,
1947
1947
  lazySchema as lazySchema12,
1948
1948
  zodSchema as zodSchema12
1949
1949
  } from "@ai-sdk/provider-utils";
@@ -1951,9 +1951,7 @@ import { z as z13 } from "zod/v4";
1951
1951
  var webSearchArgsSchema = lazySchema12(
1952
1952
  () => zodSchema12(
1953
1953
  z13.object({
1954
- filters: z13.object({
1955
- allowedDomains: z13.array(z13.string()).optional()
1956
- }).optional(),
1954
+ filters: z13.object({ allowedDomains: z13.array(z13.string()).optional() }).optional(),
1957
1955
  searchContextSize: z13.enum(["low", "medium", "high"]).optional(),
1958
1956
  userLocation: z13.object({
1959
1957
  type: z13.literal("approximate"),
@@ -1965,16 +1963,17 @@ var webSearchArgsSchema = lazySchema12(
1965
1963
  })
1966
1964
  )
1967
1965
  );
1968
- var webSearchInputSchema = lazySchema12(
1966
+ var webSearchInputSchema = lazySchema12(() => zodSchema12(z13.object({})));
1967
+ var webSearchOutputSchema = lazySchema12(
1969
1968
  () => zodSchema12(
1970
1969
  z13.object({
1971
1970
  action: z13.discriminatedUnion("type", [
1972
1971
  z13.object({
1973
1972
  type: z13.literal("search"),
1974
- query: z13.string().nullish()
1973
+ query: z13.string().optional()
1975
1974
  }),
1976
1975
  z13.object({
1977
- type: z13.literal("open_page"),
1976
+ type: z13.literal("openPage"),
1978
1977
  url: z13.string()
1979
1978
  }),
1980
1979
  z13.object({
@@ -1982,22 +1981,21 @@ var webSearchInputSchema = lazySchema12(
1982
1981
  url: z13.string(),
1983
1982
  pattern: z13.string()
1984
1983
  })
1985
- ]).nullish()
1984
+ ])
1986
1985
  })
1987
1986
  )
1988
1987
  );
1989
- var webSearchToolFactory = createProviderDefinedToolFactory({
1988
+ var webSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema5({
1990
1989
  id: "openai.web_search",
1991
1990
  name: "web_search",
1992
- inputSchema: webSearchInputSchema
1991
+ inputSchema: webSearchInputSchema,
1992
+ outputSchema: webSearchOutputSchema
1993
1993
  });
1994
- var webSearch = (args = {}) => {
1995
- return webSearchToolFactory(args);
1996
- };
1994
+ var webSearch = (args = {}) => webSearchToolFactory(args);
1997
1995
 
1998
1996
  // src/tool/web-search-preview.ts
1999
1997
  import {
2000
- createProviderDefinedToolFactory as createProviderDefinedToolFactory2,
1998
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema6,
2001
1999
  lazySchema as lazySchema13,
2002
2000
  zodSchema as zodSchema13
2003
2001
  } from "@ai-sdk/provider-utils";
@@ -2005,51 +2003,30 @@ import { z as z14 } from "zod/v4";
2005
2003
  var webSearchPreviewArgsSchema = lazySchema13(
2006
2004
  () => zodSchema13(
2007
2005
  z14.object({
2008
- /**
2009
- * Search context size to use for the web search.
2010
- * - high: Most comprehensive context, highest cost, slower response
2011
- * - medium: Balanced context, cost, and latency (default)
2012
- * - low: Least context, lowest cost, fastest response
2013
- */
2014
2006
  searchContextSize: z14.enum(["low", "medium", "high"]).optional(),
2015
- /**
2016
- * User location information to provide geographically relevant search results.
2017
- */
2018
2007
  userLocation: z14.object({
2019
- /**
2020
- * Type of location (always 'approximate')
2021
- */
2022
2008
  type: z14.literal("approximate"),
2023
- /**
2024
- * Two-letter ISO country code (e.g., 'US', 'GB')
2025
- */
2026
2009
  country: z14.string().optional(),
2027
- /**
2028
- * City name (free text, e.g., 'Minneapolis')
2029
- */
2030
2010
  city: z14.string().optional(),
2031
- /**
2032
- * Region name (free text, e.g., 'Minnesota')
2033
- */
2034
2011
  region: z14.string().optional(),
2035
- /**
2036
- * IANA timezone (e.g., 'America/Chicago')
2037
- */
2038
2012
  timezone: z14.string().optional()
2039
2013
  }).optional()
2040
2014
  })
2041
2015
  )
2042
2016
  );
2043
2017
  var webSearchPreviewInputSchema = lazySchema13(
2018
+ () => zodSchema13(z14.object({}))
2019
+ );
2020
+ var webSearchPreviewOutputSchema = lazySchema13(
2044
2021
  () => zodSchema13(
2045
2022
  z14.object({
2046
2023
  action: z14.discriminatedUnion("type", [
2047
2024
  z14.object({
2048
2025
  type: z14.literal("search"),
2049
- query: z14.string().nullish()
2026
+ query: z14.string().optional()
2050
2027
  }),
2051
2028
  z14.object({
2052
- type: z14.literal("open_page"),
2029
+ type: z14.literal("openPage"),
2053
2030
  url: z14.string()
2054
2031
  }),
2055
2032
  z14.object({
@@ -2057,14 +2034,15 @@ var webSearchPreviewInputSchema = lazySchema13(
2057
2034
  url: z14.string(),
2058
2035
  pattern: z14.string()
2059
2036
  })
2060
- ]).nullish()
2037
+ ])
2061
2038
  })
2062
2039
  )
2063
2040
  );
2064
- var webSearchPreview = createProviderDefinedToolFactory2({
2041
+ var webSearchPreview = createProviderDefinedToolFactoryWithOutputSchema6({
2065
2042
  id: "openai.web_search_preview",
2066
2043
  name: "web_search_preview",
2067
- inputSchema: webSearchPreviewInputSchema
2044
+ inputSchema: webSearchPreviewInputSchema,
2045
+ outputSchema: webSearchPreviewOutputSchema
2068
2046
  });
2069
2047
 
2070
2048
  // src/openai-tools.ts
@@ -2364,6 +2342,9 @@ async function convertToOpenAIResponsesInput({
2364
2342
  input.push(reasoningMessages[reasoningId]);
2365
2343
  } else {
2366
2344
  reasoningMessage.summary.push(...summaryParts);
2345
+ if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
2346
+ reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
2347
+ }
2367
2348
  }
2368
2349
  }
2369
2350
  } else {
@@ -2533,11 +2514,7 @@ var openaiResponsesChunkSchema = lazySchema14(
2533
2514
  z16.object({
2534
2515
  type: z16.literal("web_search_call"),
2535
2516
  id: z16.string(),
2536
- status: z16.string(),
2537
- action: z16.object({
2538
- type: z16.literal("search"),
2539
- query: z16.string().optional()
2540
- }).nullish()
2517
+ status: z16.string()
2541
2518
  }),
2542
2519
  z16.object({
2543
2520
  type: z16.literal("computer_call"),
@@ -2623,7 +2600,7 @@ var openaiResponsesChunkSchema = lazySchema14(
2623
2600
  url: z16.string(),
2624
2601
  pattern: z16.string()
2625
2602
  })
2626
- ]).nullish()
2603
+ ])
2627
2604
  }),
2628
2605
  z16.object({
2629
2606
  type: z16.literal("file_search_call"),
@@ -2713,6 +2690,11 @@ var openaiResponsesChunkSchema = lazySchema14(
2713
2690
  summary_index: z16.number(),
2714
2691
  delta: z16.string()
2715
2692
  }),
2693
+ z16.object({
2694
+ type: z16.literal("response.reasoning_summary_part.done"),
2695
+ item_id: z16.string(),
2696
+ summary_index: z16.number()
2697
+ }),
2716
2698
  z16.object({
2717
2699
  type: z16.literal("error"),
2718
2700
  code: z16.string(),
@@ -2804,7 +2786,7 @@ var openaiResponsesResponseSchema = lazySchema14(
2804
2786
  url: z16.string(),
2805
2787
  pattern: z16.string()
2806
2788
  })
2807
- ]).nullish()
2789
+ ])
2808
2790
  }),
2809
2791
  z16.object({
2810
2792
  type: z16.literal("file_search_call"),
@@ -3350,7 +3332,8 @@ var OpenAIResponsesLanguageModel = class {
3350
3332
  tools: openaiTools2,
3351
3333
  tool_choice: openaiToolChoice
3352
3334
  },
3353
- warnings: [...warnings, ...toolWarnings]
3335
+ warnings: [...warnings, ...toolWarnings],
3336
+ store
3354
3337
  };
3355
3338
  }
3356
3339
  async doGenerate(options) {
@@ -3505,14 +3488,14 @@ var OpenAIResponsesLanguageModel = class {
3505
3488
  type: "tool-call",
3506
3489
  toolCallId: part.id,
3507
3490
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3508
- input: JSON.stringify({ action: part.action }),
3491
+ input: JSON.stringify({}),
3509
3492
  providerExecuted: true
3510
3493
  });
3511
3494
  content.push({
3512
3495
  type: "tool-result",
3513
3496
  toolCallId: part.id,
3514
3497
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3515
- result: { status: part.status },
3498
+ result: mapWebSearchOutput(part.action),
3516
3499
  providerExecuted: true
3517
3500
  });
3518
3501
  break;
@@ -3625,7 +3608,8 @@ var OpenAIResponsesLanguageModel = class {
3625
3608
  const {
3626
3609
  args: body,
3627
3610
  warnings,
3628
- webSearchToolName
3611
+ webSearchToolName,
3612
+ store
3629
3613
  } = await this.getArgs(options);
3630
3614
  const { responseHeaders, value: response } = await postJsonToApi5({
3631
3615
  url: this.config.url({
@@ -3664,7 +3648,7 @@ var OpenAIResponsesLanguageModel = class {
3664
3648
  controller.enqueue({ type: "stream-start", warnings });
3665
3649
  },
3666
3650
  transform(chunk, controller) {
3667
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3651
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3668
3652
  if (options.includeRawChunks) {
3669
3653
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3670
3654
  }
@@ -3696,6 +3680,17 @@ var OpenAIResponsesLanguageModel = class {
3696
3680
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3697
3681
  providerExecuted: true
3698
3682
  });
3683
+ controller.enqueue({
3684
+ type: "tool-input-end",
3685
+ id: value.item.id
3686
+ });
3687
+ controller.enqueue({
3688
+ type: "tool-call",
3689
+ toolCallId: value.item.id,
3690
+ toolName: "web_search",
3691
+ input: JSON.stringify({}),
3692
+ providerExecuted: true
3693
+ });
3699
3694
  } else if (value.item.type === "computer_call") {
3700
3695
  ongoingToolCalls[value.output_index] = {
3701
3696
  toolName: "computer_use",
@@ -3752,10 +3747,10 @@ var OpenAIResponsesLanguageModel = class {
3752
3747
  }
3753
3748
  }
3754
3749
  });
3755
- } else if (isResponseOutputItemAddedReasoningChunk(value)) {
3750
+ } else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
3756
3751
  activeReasoning[value.item.id] = {
3757
3752
  encryptedContent: value.item.encrypted_content,
3758
- summaryParts: [0]
3753
+ summaryParts: { 0: "active" }
3759
3754
  };
3760
3755
  controller.enqueue({
3761
3756
  type: "reasoning-start",
@@ -3789,22 +3784,11 @@ var OpenAIResponsesLanguageModel = class {
3789
3784
  });
3790
3785
  } else if (value.item.type === "web_search_call") {
3791
3786
  ongoingToolCalls[value.output_index] = void 0;
3792
- controller.enqueue({
3793
- type: "tool-input-end",
3794
- id: value.item.id
3795
- });
3796
- controller.enqueue({
3797
- type: "tool-call",
3798
- toolCallId: value.item.id,
3799
- toolName: "web_search",
3800
- input: JSON.stringify({ action: value.item.action }),
3801
- providerExecuted: true
3802
- });
3803
3787
  controller.enqueue({
3804
3788
  type: "tool-result",
3805
3789
  toolCallId: value.item.id,
3806
3790
  toolName: "web_search",
3807
- result: { status: value.item.status },
3791
+ result: mapWebSearchOutput(value.item.action),
3808
3792
  providerExecuted: true
3809
3793
  });
3810
3794
  } else if (value.item.type === "computer_call") {
@@ -3894,9 +3878,14 @@ var OpenAIResponsesLanguageModel = class {
3894
3878
  type: "text-end",
3895
3879
  id: value.item.id
3896
3880
  });
3897
- } else if (isResponseOutputItemDoneReasoningChunk(value)) {
3881
+ } else if (value.item.type === "reasoning") {
3898
3882
  const activeReasoningPart = activeReasoning[value.item.id];
3899
- for (const summaryIndex of activeReasoningPart.summaryParts) {
3883
+ const summaryPartIndices = Object.entries(
3884
+ activeReasoningPart.summaryParts
3885
+ ).filter(
3886
+ ([_, status]) => status === "active" || status === "can-conclude"
3887
+ ).map(([summaryIndex]) => summaryIndex);
3888
+ for (const summaryIndex of summaryPartIndices) {
3900
3889
  controller.enqueue({
3901
3890
  type: "reasoning-end",
3902
3891
  id: `${value.item.id}:${summaryIndex}`,
@@ -3981,23 +3970,34 @@ var OpenAIResponsesLanguageModel = class {
3981
3970
  if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
3982
3971
  logprobs.push(value.logprobs);
3983
3972
  }
3984
- } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
3973
+ } else if (value.type === "response.reasoning_summary_part.added") {
3985
3974
  if (value.summary_index > 0) {
3986
- (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.summaryParts.push(
3987
- value.summary_index
3988
- );
3975
+ const activeReasoningPart = activeReasoning[value.item_id];
3976
+ activeReasoningPart.summaryParts[value.summary_index] = "active";
3977
+ for (const summaryIndex of Object.keys(
3978
+ activeReasoningPart.summaryParts
3979
+ )) {
3980
+ if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
3981
+ controller.enqueue({
3982
+ type: "reasoning-end",
3983
+ id: `${value.item_id}:${summaryIndex}`,
3984
+ providerMetadata: { openai: { itemId: value.item_id } }
3985
+ });
3986
+ activeReasoningPart.summaryParts[summaryIndex] = "concluded";
3987
+ }
3988
+ }
3989
3989
  controller.enqueue({
3990
3990
  type: "reasoning-start",
3991
3991
  id: `${value.item_id}:${value.summary_index}`,
3992
3992
  providerMetadata: {
3993
3993
  openai: {
3994
3994
  itemId: value.item_id,
3995
- reasoningEncryptedContent: (_i = (_h = activeReasoning[value.item_id]) == null ? void 0 : _h.encryptedContent) != null ? _i : null
3995
+ reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
3996
3996
  }
3997
3997
  }
3998
3998
  });
3999
3999
  }
4000
- } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
4000
+ } else if (value.type === "response.reasoning_summary_text.delta") {
4001
4001
  controller.enqueue({
4002
4002
  type: "reasoning-delta",
4003
4003
  id: `${value.item_id}:${value.summary_index}`,
@@ -4008,16 +4008,29 @@ var OpenAIResponsesLanguageModel = class {
4008
4008
  }
4009
4009
  }
4010
4010
  });
4011
+ } else if (value.type === "response.reasoning_summary_part.done") {
4012
+ if (store) {
4013
+ controller.enqueue({
4014
+ type: "reasoning-end",
4015
+ id: `${value.item_id}:${value.summary_index}`,
4016
+ providerMetadata: {
4017
+ openai: { itemId: value.item_id }
4018
+ }
4019
+ });
4020
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
4021
+ } else {
4022
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
4023
+ }
4011
4024
  } else if (isResponseFinishedChunk(value)) {
4012
4025
  finishReason = mapOpenAIResponseFinishReason({
4013
- finishReason: (_j = value.response.incomplete_details) == null ? void 0 : _j.reason,
4026
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4014
4027
  hasFunctionCall
4015
4028
  });
4016
4029
  usage.inputTokens = value.response.usage.input_tokens;
4017
4030
  usage.outputTokens = value.response.usage.output_tokens;
4018
4031
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
4019
- usage.reasoningTokens = (_l = (_k = value.response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0;
4020
- usage.cachedInputTokens = (_n = (_m = value.response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0;
4032
+ usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
4033
+ usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
4021
4034
  if (typeof value.response.service_tier === "string") {
4022
4035
  serviceTier = value.response.service_tier;
4023
4036
  }
@@ -4026,7 +4039,7 @@ var OpenAIResponsesLanguageModel = class {
4026
4039
  controller.enqueue({
4027
4040
  type: "source",
4028
4041
  sourceType: "url",
4029
- id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
4042
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
4030
4043
  url: value.annotation.url,
4031
4044
  title: value.annotation.title
4032
4045
  });
@@ -4034,10 +4047,10 @@ var OpenAIResponsesLanguageModel = class {
4034
4047
  controller.enqueue({
4035
4048
  type: "source",
4036
4049
  sourceType: "document",
4037
- id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
4050
+ id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
4038
4051
  mediaType: "text/plain",
4039
- title: (_v = (_u = value.annotation.quote) != null ? _u : value.annotation.filename) != null ? _v : "Document",
4040
- filename: (_w = value.annotation.filename) != null ? _w : value.annotation.file_id
4052
+ title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
4053
+ filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id
4041
4054
  });
4042
4055
  }
4043
4056
  } else if (isErrorChunk(value)) {
@@ -4076,9 +4089,6 @@ function isTextDeltaChunk(chunk) {
4076
4089
  function isResponseOutputItemDoneChunk(chunk) {
4077
4090
  return chunk.type === "response.output_item.done";
4078
4091
  }
4079
- function isResponseOutputItemDoneReasoningChunk(chunk) {
4080
- return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
4081
- }
4082
4092
  function isResponseFinishedChunk(chunk) {
4083
4093
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
4084
4094
  }
@@ -4100,18 +4110,9 @@ function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
4100
4110
  function isResponseOutputItemAddedChunk(chunk) {
4101
4111
  return chunk.type === "response.output_item.added";
4102
4112
  }
4103
- function isResponseOutputItemAddedReasoningChunk(chunk) {
4104
- return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
4105
- }
4106
4113
  function isResponseAnnotationAddedChunk(chunk) {
4107
4114
  return chunk.type === "response.output_text.annotation.added";
4108
4115
  }
4109
- function isResponseReasoningSummaryPartAddedChunk(chunk) {
4110
- return chunk.type === "response.reasoning_summary_part.added";
4111
- }
4112
- function isResponseReasoningSummaryTextDeltaChunk(chunk) {
4113
- return chunk.type === "response.reasoning_summary_text.delta";
4114
- }
4115
4116
  function isErrorChunk(chunk) {
4116
4117
  return chunk.type === "error";
4117
4118
  }
@@ -4149,6 +4150,19 @@ function getResponsesModelConfig(modelId) {
4149
4150
  isReasoningModel: false
4150
4151
  };
4151
4152
  }
4153
+ function mapWebSearchOutput(action) {
4154
+ var _a;
4155
+ switch (action.type) {
4156
+ case "search":
4157
+ return { action: { type: "search", query: (_a = action.query) != null ? _a : void 0 } };
4158
+ case "open_page":
4159
+ return { action: { type: "openPage", url: action.url } };
4160
+ case "find":
4161
+ return {
4162
+ action: { type: "find", url: action.url, pattern: action.pattern }
4163
+ };
4164
+ }
4165
+ }
4152
4166
 
4153
4167
  // src/speech/openai-speech-model.ts
4154
4168
  import {
@@ -4515,7 +4529,7 @@ var OpenAITranscriptionModel = class {
4515
4529
  };
4516
4530
 
4517
4531
  // src/version.ts
4518
- var VERSION = true ? "3.0.0-beta.27" : "0.0.0-test";
4532
+ var VERSION = true ? "3.0.0-beta.29" : "0.0.0-test";
4519
4533
 
4520
4534
  // src/openai-provider.ts
4521
4535
  function createOpenAI(options = {}) {