@ai-sdk/openai 2.0.49 → 2.0.51

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.
@@ -2171,7 +2171,7 @@ async function convertToOpenAIResponsesInput({
2171
2171
  store,
2172
2172
  hasLocalShellTool = false
2173
2173
  }) {
2174
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2174
+ var _a, _b, _c, _d;
2175
2175
  const input = [];
2176
2176
  const warnings = [];
2177
2177
  for (const { role, content } of prompt) {
@@ -2252,10 +2252,15 @@ async function convertToOpenAIResponsesInput({
2252
2252
  for (const part of content) {
2253
2253
  switch (part.type) {
2254
2254
  case "text": {
2255
+ const id = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId;
2256
+ if (store && id != null) {
2257
+ input.push({ type: "item_reference", id });
2258
+ break;
2259
+ }
2255
2260
  input.push({
2256
2261
  role: "assistant",
2257
2262
  content: [{ type: "output_text", text: part.text }],
2258
- id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
2263
+ id
2259
2264
  });
2260
2265
  break;
2261
2266
  }
@@ -2264,6 +2269,11 @@ async function convertToOpenAIResponsesInput({
2264
2269
  if (part.providerExecuted) {
2265
2270
  break;
2266
2271
  }
2272
+ const id = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.itemId;
2273
+ if (store && id != null) {
2274
+ input.push({ type: "item_reference", id });
2275
+ break;
2276
+ }
2267
2277
  if (hasLocalShellTool && part.toolName === "local_shell") {
2268
2278
  const parsedInput = await (0, import_provider_utils20.validateTypes)({
2269
2279
  value: part.input,
@@ -2272,7 +2282,7 @@ async function convertToOpenAIResponsesInput({
2272
2282
  input.push({
2273
2283
  type: "local_shell_call",
2274
2284
  call_id: part.toolCallId,
2275
- id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0,
2285
+ id,
2276
2286
  action: {
2277
2287
  type: "exec",
2278
2288
  command: parsedInput.action.command,
@@ -2289,7 +2299,7 @@ async function convertToOpenAIResponsesInput({
2289
2299
  call_id: part.toolCallId,
2290
2300
  name: part.toolName,
2291
2301
  arguments: JSON.stringify(part.input),
2292
- id: (_i = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.itemId) != null ? _i : void 0
2302
+ id
2293
2303
  });
2294
2304
  break;
2295
2305
  }
@@ -2512,11 +2522,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2512
2522
  import_v414.z.object({
2513
2523
  type: import_v414.z.literal("web_search_call"),
2514
2524
  id: import_v414.z.string(),
2515
- status: import_v414.z.string(),
2516
- action: import_v414.z.object({
2517
- type: import_v414.z.literal("search"),
2518
- query: import_v414.z.string().optional()
2519
- }).nullish()
2525
+ status: import_v414.z.string()
2520
2526
  }),
2521
2527
  import_v414.z.object({
2522
2528
  type: import_v414.z.literal("computer_call"),
@@ -2602,7 +2608,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2602
2608
  url: import_v414.z.string(),
2603
2609
  pattern: import_v414.z.string()
2604
2610
  })
2605
- ]).nullish()
2611
+ ])
2606
2612
  }),
2607
2613
  import_v414.z.object({
2608
2614
  type: import_v414.z.literal("file_search_call"),
@@ -2783,7 +2789,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2783
2789
  url: import_v414.z.string(),
2784
2790
  pattern: import_v414.z.string()
2785
2791
  })
2786
- ]).nullish()
2792
+ ])
2787
2793
  }),
2788
2794
  import_v414.z.object({
2789
2795
  type: import_v414.z.literal("file_search_call"),
@@ -3078,9 +3084,7 @@ var import_v418 = require("zod/v4");
3078
3084
  var webSearchArgsSchema = (0, import_provider_utils25.lazySchema)(
3079
3085
  () => (0, import_provider_utils25.zodSchema)(
3080
3086
  import_v418.z.object({
3081
- filters: import_v418.z.object({
3082
- allowedDomains: import_v418.z.array(import_v418.z.string()).optional()
3083
- }).optional(),
3087
+ filters: import_v418.z.object({ allowedDomains: import_v418.z.array(import_v418.z.string()).optional() }).optional(),
3084
3088
  searchContextSize: import_v418.z.enum(["low", "medium", "high"]).optional(),
3085
3089
  userLocation: import_v418.z.object({
3086
3090
  type: import_v418.z.literal("approximate"),
@@ -3092,16 +3096,17 @@ var webSearchArgsSchema = (0, import_provider_utils25.lazySchema)(
3092
3096
  })
3093
3097
  )
3094
3098
  );
3095
- var webSearchInputSchema = (0, import_provider_utils25.lazySchema)(
3099
+ var webSearchInputSchema = (0, import_provider_utils25.lazySchema)(() => (0, import_provider_utils25.zodSchema)(import_v418.z.object({})));
3100
+ var webSearchOutputSchema = (0, import_provider_utils25.lazySchema)(
3096
3101
  () => (0, import_provider_utils25.zodSchema)(
3097
3102
  import_v418.z.object({
3098
3103
  action: import_v418.z.discriminatedUnion("type", [
3099
3104
  import_v418.z.object({
3100
3105
  type: import_v418.z.literal("search"),
3101
- query: import_v418.z.string().nullish()
3106
+ query: import_v418.z.string().optional()
3102
3107
  }),
3103
3108
  import_v418.z.object({
3104
- type: import_v418.z.literal("open_page"),
3109
+ type: import_v418.z.literal("openPage"),
3105
3110
  url: import_v418.z.string()
3106
3111
  }),
3107
3112
  import_v418.z.object({
@@ -3109,14 +3114,15 @@ var webSearchInputSchema = (0, import_provider_utils25.lazySchema)(
3109
3114
  url: import_v418.z.string(),
3110
3115
  pattern: import_v418.z.string()
3111
3116
  })
3112
- ]).nullish()
3117
+ ])
3113
3118
  })
3114
3119
  )
3115
3120
  );
3116
- var webSearchToolFactory = (0, import_provider_utils25.createProviderDefinedToolFactory)({
3121
+ var webSearchToolFactory = (0, import_provider_utils25.createProviderDefinedToolFactoryWithOutputSchema)({
3117
3122
  id: "openai.web_search",
3118
3123
  name: "web_search",
3119
- inputSchema: webSearchInputSchema
3124
+ inputSchema: webSearchInputSchema,
3125
+ outputSchema: webSearchOutputSchema
3120
3126
  });
3121
3127
 
3122
3128
  // src/tool/web-search-preview.ts
@@ -3125,51 +3131,30 @@ var import_v419 = require("zod/v4");
3125
3131
  var webSearchPreviewArgsSchema = (0, import_provider_utils26.lazySchema)(
3126
3132
  () => (0, import_provider_utils26.zodSchema)(
3127
3133
  import_v419.z.object({
3128
- /**
3129
- * Search context size to use for the web search.
3130
- * - high: Most comprehensive context, highest cost, slower response
3131
- * - medium: Balanced context, cost, and latency (default)
3132
- * - low: Least context, lowest cost, fastest response
3133
- */
3134
3134
  searchContextSize: import_v419.z.enum(["low", "medium", "high"]).optional(),
3135
- /**
3136
- * User location information to provide geographically relevant search results.
3137
- */
3138
3135
  userLocation: import_v419.z.object({
3139
- /**
3140
- * Type of location (always 'approximate')
3141
- */
3142
3136
  type: import_v419.z.literal("approximate"),
3143
- /**
3144
- * Two-letter ISO country code (e.g., 'US', 'GB')
3145
- */
3146
3137
  country: import_v419.z.string().optional(),
3147
- /**
3148
- * City name (free text, e.g., 'Minneapolis')
3149
- */
3150
3138
  city: import_v419.z.string().optional(),
3151
- /**
3152
- * Region name (free text, e.g., 'Minnesota')
3153
- */
3154
3139
  region: import_v419.z.string().optional(),
3155
- /**
3156
- * IANA timezone (e.g., 'America/Chicago')
3157
- */
3158
3140
  timezone: import_v419.z.string().optional()
3159
3141
  }).optional()
3160
3142
  })
3161
3143
  )
3162
3144
  );
3163
3145
  var webSearchPreviewInputSchema = (0, import_provider_utils26.lazySchema)(
3146
+ () => (0, import_provider_utils26.zodSchema)(import_v419.z.object({}))
3147
+ );
3148
+ var webSearchPreviewOutputSchema = (0, import_provider_utils26.lazySchema)(
3164
3149
  () => (0, import_provider_utils26.zodSchema)(
3165
3150
  import_v419.z.object({
3166
3151
  action: import_v419.z.discriminatedUnion("type", [
3167
3152
  import_v419.z.object({
3168
3153
  type: import_v419.z.literal("search"),
3169
- query: import_v419.z.string().nullish()
3154
+ query: import_v419.z.string().optional()
3170
3155
  }),
3171
3156
  import_v419.z.object({
3172
- type: import_v419.z.literal("open_page"),
3157
+ type: import_v419.z.literal("openPage"),
3173
3158
  url: import_v419.z.string()
3174
3159
  }),
3175
3160
  import_v419.z.object({
@@ -3177,14 +3162,15 @@ var webSearchPreviewInputSchema = (0, import_provider_utils26.lazySchema)(
3177
3162
  url: import_v419.z.string(),
3178
3163
  pattern: import_v419.z.string()
3179
3164
  })
3180
- ]).nullish()
3165
+ ])
3181
3166
  })
3182
3167
  )
3183
3168
  );
3184
- var webSearchPreview = (0, import_provider_utils26.createProviderDefinedToolFactory)({
3169
+ var webSearchPreview = (0, import_provider_utils26.createProviderDefinedToolFactoryWithOutputSchema)({
3185
3170
  id: "openai.web_search_preview",
3186
3171
  name: "web_search_preview",
3187
- inputSchema: webSearchPreviewInputSchema
3172
+ inputSchema: webSearchPreviewInputSchema,
3173
+ outputSchema: webSearchPreviewOutputSchema
3188
3174
  });
3189
3175
 
3190
3176
  // src/tool/image-generation.ts
@@ -3729,14 +3715,14 @@ var OpenAIResponsesLanguageModel = class {
3729
3715
  type: "tool-call",
3730
3716
  toolCallId: part.id,
3731
3717
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3732
- input: JSON.stringify({ action: part.action }),
3718
+ input: JSON.stringify({}),
3733
3719
  providerExecuted: true
3734
3720
  });
3735
3721
  content.push({
3736
3722
  type: "tool-result",
3737
3723
  toolCallId: part.id,
3738
3724
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3739
- result: { status: part.status },
3725
+ result: mapWebSearchOutput(part.action),
3740
3726
  providerExecuted: true
3741
3727
  });
3742
3728
  break;
@@ -3920,6 +3906,17 @@ var OpenAIResponsesLanguageModel = class {
3920
3906
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3921
3907
  providerExecuted: true
3922
3908
  });
3909
+ controller.enqueue({
3910
+ type: "tool-input-end",
3911
+ id: value.item.id
3912
+ });
3913
+ controller.enqueue({
3914
+ type: "tool-call",
3915
+ toolCallId: value.item.id,
3916
+ toolName: "web_search",
3917
+ input: JSON.stringify({}),
3918
+ providerExecuted: true
3919
+ });
3923
3920
  } else if (value.item.type === "computer_call") {
3924
3921
  ongoingToolCalls[value.output_index] = {
3925
3922
  toolName: "computer_use",
@@ -4013,22 +4010,11 @@ var OpenAIResponsesLanguageModel = class {
4013
4010
  });
4014
4011
  } else if (value.item.type === "web_search_call") {
4015
4012
  ongoingToolCalls[value.output_index] = void 0;
4016
- controller.enqueue({
4017
- type: "tool-input-end",
4018
- id: value.item.id
4019
- });
4020
- controller.enqueue({
4021
- type: "tool-call",
4022
- toolCallId: value.item.id,
4023
- toolName: "web_search",
4024
- input: JSON.stringify({ action: value.item.action }),
4025
- providerExecuted: true
4026
- });
4027
4013
  controller.enqueue({
4028
4014
  type: "tool-result",
4029
4015
  toolCallId: value.item.id,
4030
4016
  toolName: "web_search",
4031
- result: { status: value.item.status },
4017
+ result: mapWebSearchOutput(value.item.action),
4032
4018
  providerExecuted: true
4033
4019
  });
4034
4020
  } else if (value.item.type === "computer_call") {
@@ -4359,6 +4345,19 @@ function getResponsesModelConfig(modelId) {
4359
4345
  isReasoningModel: false
4360
4346
  };
4361
4347
  }
4348
+ function mapWebSearchOutput(action) {
4349
+ var _a;
4350
+ switch (action.type) {
4351
+ case "search":
4352
+ return { action: { type: "search", query: (_a = action.query) != null ? _a : void 0 } };
4353
+ case "open_page":
4354
+ return { action: { type: "openPage", url: action.url } };
4355
+ case "find":
4356
+ return {
4357
+ action: { type: "find", url: action.url, pattern: action.pattern }
4358
+ };
4359
+ }
4360
+ }
4362
4361
  // Annotate the CommonJS export names for ESM import in node:
4363
4362
  0 && (module.exports = {
4364
4363
  OpenAIChatLanguageModel,