@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.
@@ -2392,6 +2392,9 @@ async function convertToOpenAIResponsesInput({
2392
2392
  input.push(reasoningMessages[reasoningId]);
2393
2393
  } else {
2394
2394
  reasoningMessage.summary.push(...summaryParts);
2395
+ if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
2396
+ reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
2397
+ }
2395
2398
  }
2396
2399
  }
2397
2400
  } else {
@@ -2561,11 +2564,7 @@ var openaiResponsesChunkSchema = lazyValidator11(
2561
2564
  z14.object({
2562
2565
  type: z14.literal("web_search_call"),
2563
2566
  id: z14.string(),
2564
- status: z14.string(),
2565
- action: z14.object({
2566
- type: z14.literal("search"),
2567
- query: z14.string().optional()
2568
- }).nullish()
2567
+ status: z14.string()
2569
2568
  }),
2570
2569
  z14.object({
2571
2570
  type: z14.literal("computer_call"),
@@ -2651,7 +2650,7 @@ var openaiResponsesChunkSchema = lazyValidator11(
2651
2650
  url: z14.string(),
2652
2651
  pattern: z14.string()
2653
2652
  })
2654
- ]).nullish()
2653
+ ])
2655
2654
  }),
2656
2655
  z14.object({
2657
2656
  type: z14.literal("file_search_call"),
@@ -2741,6 +2740,11 @@ var openaiResponsesChunkSchema = lazyValidator11(
2741
2740
  summary_index: z14.number(),
2742
2741
  delta: z14.string()
2743
2742
  }),
2743
+ z14.object({
2744
+ type: z14.literal("response.reasoning_summary_part.done"),
2745
+ item_id: z14.string(),
2746
+ summary_index: z14.number()
2747
+ }),
2744
2748
  z14.object({
2745
2749
  type: z14.literal("error"),
2746
2750
  code: z14.string(),
@@ -2832,7 +2836,7 @@ var openaiResponsesResponseSchema = lazyValidator11(
2832
2836
  url: z14.string(),
2833
2837
  pattern: z14.string()
2834
2838
  })
2835
- ]).nullish()
2839
+ ])
2836
2840
  }),
2837
2841
  z14.object({
2838
2842
  type: z14.literal("file_search_call"),
@@ -3136,7 +3140,7 @@ var fileSearch = createProviderDefinedToolFactoryWithOutputSchema3({
3136
3140
 
3137
3141
  // src/tool/web-search.ts
3138
3142
  import {
3139
- createProviderDefinedToolFactory,
3143
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema4,
3140
3144
  lazySchema as lazySchema4,
3141
3145
  zodSchema as zodSchema16
3142
3146
  } from "@ai-sdk/provider-utils";
@@ -3144,9 +3148,7 @@ import { z as z18 } from "zod/v4";
3144
3148
  var webSearchArgsSchema = lazySchema4(
3145
3149
  () => zodSchema16(
3146
3150
  z18.object({
3147
- filters: z18.object({
3148
- allowedDomains: z18.array(z18.string()).optional()
3149
- }).optional(),
3151
+ filters: z18.object({ allowedDomains: z18.array(z18.string()).optional() }).optional(),
3150
3152
  searchContextSize: z18.enum(["low", "medium", "high"]).optional(),
3151
3153
  userLocation: z18.object({
3152
3154
  type: z18.literal("approximate"),
@@ -3158,16 +3160,17 @@ var webSearchArgsSchema = lazySchema4(
3158
3160
  })
3159
3161
  )
3160
3162
  );
3161
- var webSearchInputSchema = lazySchema4(
3163
+ var webSearchInputSchema = lazySchema4(() => zodSchema16(z18.object({})));
3164
+ var webSearchOutputSchema = lazySchema4(
3162
3165
  () => zodSchema16(
3163
3166
  z18.object({
3164
3167
  action: z18.discriminatedUnion("type", [
3165
3168
  z18.object({
3166
3169
  type: z18.literal("search"),
3167
- query: z18.string().nullish()
3170
+ query: z18.string().optional()
3168
3171
  }),
3169
3172
  z18.object({
3170
- type: z18.literal("open_page"),
3173
+ type: z18.literal("openPage"),
3171
3174
  url: z18.string()
3172
3175
  }),
3173
3176
  z18.object({
@@ -3175,19 +3178,20 @@ var webSearchInputSchema = lazySchema4(
3175
3178
  url: z18.string(),
3176
3179
  pattern: z18.string()
3177
3180
  })
3178
- ]).nullish()
3181
+ ])
3179
3182
  })
3180
3183
  )
3181
3184
  );
3182
- var webSearchToolFactory = createProviderDefinedToolFactory({
3185
+ var webSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema4({
3183
3186
  id: "openai.web_search",
3184
3187
  name: "web_search",
3185
- inputSchema: webSearchInputSchema
3188
+ inputSchema: webSearchInputSchema,
3189
+ outputSchema: webSearchOutputSchema
3186
3190
  });
3187
3191
 
3188
3192
  // src/tool/web-search-preview.ts
3189
3193
  import {
3190
- createProviderDefinedToolFactory as createProviderDefinedToolFactory2,
3194
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema5,
3191
3195
  lazySchema as lazySchema5,
3192
3196
  zodSchema as zodSchema17
3193
3197
  } from "@ai-sdk/provider-utils";
@@ -3195,51 +3199,30 @@ import { z as z19 } from "zod/v4";
3195
3199
  var webSearchPreviewArgsSchema = lazySchema5(
3196
3200
  () => zodSchema17(
3197
3201
  z19.object({
3198
- /**
3199
- * Search context size to use for the web search.
3200
- * - high: Most comprehensive context, highest cost, slower response
3201
- * - medium: Balanced context, cost, and latency (default)
3202
- * - low: Least context, lowest cost, fastest response
3203
- */
3204
3202
  searchContextSize: z19.enum(["low", "medium", "high"]).optional(),
3205
- /**
3206
- * User location information to provide geographically relevant search results.
3207
- */
3208
3203
  userLocation: z19.object({
3209
- /**
3210
- * Type of location (always 'approximate')
3211
- */
3212
3204
  type: z19.literal("approximate"),
3213
- /**
3214
- * Two-letter ISO country code (e.g., 'US', 'GB')
3215
- */
3216
3205
  country: z19.string().optional(),
3217
- /**
3218
- * City name (free text, e.g., 'Minneapolis')
3219
- */
3220
3206
  city: z19.string().optional(),
3221
- /**
3222
- * Region name (free text, e.g., 'Minnesota')
3223
- */
3224
3207
  region: z19.string().optional(),
3225
- /**
3226
- * IANA timezone (e.g., 'America/Chicago')
3227
- */
3228
3208
  timezone: z19.string().optional()
3229
3209
  }).optional()
3230
3210
  })
3231
3211
  )
3232
3212
  );
3233
3213
  var webSearchPreviewInputSchema = lazySchema5(
3214
+ () => zodSchema17(z19.object({}))
3215
+ );
3216
+ var webSearchPreviewOutputSchema = lazySchema5(
3234
3217
  () => zodSchema17(
3235
3218
  z19.object({
3236
3219
  action: z19.discriminatedUnion("type", [
3237
3220
  z19.object({
3238
3221
  type: z19.literal("search"),
3239
- query: z19.string().nullish()
3222
+ query: z19.string().optional()
3240
3223
  }),
3241
3224
  z19.object({
3242
- type: z19.literal("open_page"),
3225
+ type: z19.literal("openPage"),
3243
3226
  url: z19.string()
3244
3227
  }),
3245
3228
  z19.object({
@@ -3247,19 +3230,20 @@ var webSearchPreviewInputSchema = lazySchema5(
3247
3230
  url: z19.string(),
3248
3231
  pattern: z19.string()
3249
3232
  })
3250
- ]).nullish()
3233
+ ])
3251
3234
  })
3252
3235
  )
3253
3236
  );
3254
- var webSearchPreview = createProviderDefinedToolFactory2({
3237
+ var webSearchPreview = createProviderDefinedToolFactoryWithOutputSchema5({
3255
3238
  id: "openai.web_search_preview",
3256
3239
  name: "web_search_preview",
3257
- inputSchema: webSearchPreviewInputSchema
3240
+ inputSchema: webSearchPreviewInputSchema,
3241
+ outputSchema: webSearchPreviewOutputSchema
3258
3242
  });
3259
3243
 
3260
3244
  // src/tool/image-generation.ts
3261
3245
  import {
3262
- createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema4,
3246
+ createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema6,
3263
3247
  lazySchema as lazySchema6,
3264
3248
  zodSchema as zodSchema18
3265
3249
  } from "@ai-sdk/provider-utils";
@@ -3287,7 +3271,7 @@ var imageGenerationInputSchema = lazySchema6(() => zodSchema18(z20.object({})));
3287
3271
  var imageGenerationOutputSchema = lazySchema6(
3288
3272
  () => zodSchema18(z20.object({ result: z20.string() }))
3289
3273
  );
3290
- var imageGenerationToolFactory = createProviderDefinedToolFactoryWithOutputSchema4({
3274
+ var imageGenerationToolFactory = createProviderDefinedToolFactoryWithOutputSchema6({
3291
3275
  id: "openai.image_generation",
3292
3276
  name: "image_generation",
3293
3277
  inputSchema: imageGenerationInputSchema,
@@ -3648,7 +3632,8 @@ var OpenAIResponsesLanguageModel = class {
3648
3632
  tools: openaiTools,
3649
3633
  tool_choice: openaiToolChoice
3650
3634
  },
3651
- warnings: [...warnings, ...toolWarnings]
3635
+ warnings: [...warnings, ...toolWarnings],
3636
+ store
3652
3637
  };
3653
3638
  }
3654
3639
  async doGenerate(options) {
@@ -3803,14 +3788,14 @@ var OpenAIResponsesLanguageModel = class {
3803
3788
  type: "tool-call",
3804
3789
  toolCallId: part.id,
3805
3790
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3806
- input: JSON.stringify({ action: part.action }),
3791
+ input: JSON.stringify({}),
3807
3792
  providerExecuted: true
3808
3793
  });
3809
3794
  content.push({
3810
3795
  type: "tool-result",
3811
3796
  toolCallId: part.id,
3812
3797
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3813
- result: { status: part.status },
3798
+ result: mapWebSearchOutput(part.action),
3814
3799
  providerExecuted: true
3815
3800
  });
3816
3801
  break;
@@ -3923,7 +3908,8 @@ var OpenAIResponsesLanguageModel = class {
3923
3908
  const {
3924
3909
  args: body,
3925
3910
  warnings,
3926
- webSearchToolName
3911
+ webSearchToolName,
3912
+ store
3927
3913
  } = await this.getArgs(options);
3928
3914
  const { responseHeaders, value: response } = await postJsonToApi6({
3929
3915
  url: this.config.url({
@@ -3962,7 +3948,7 @@ var OpenAIResponsesLanguageModel = class {
3962
3948
  controller.enqueue({ type: "stream-start", warnings });
3963
3949
  },
3964
3950
  transform(chunk, controller) {
3965
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3951
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3966
3952
  if (options.includeRawChunks) {
3967
3953
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3968
3954
  }
@@ -3994,6 +3980,17 @@ var OpenAIResponsesLanguageModel = class {
3994
3980
  toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3995
3981
  providerExecuted: true
3996
3982
  });
3983
+ controller.enqueue({
3984
+ type: "tool-input-end",
3985
+ id: value.item.id
3986
+ });
3987
+ controller.enqueue({
3988
+ type: "tool-call",
3989
+ toolCallId: value.item.id,
3990
+ toolName: "web_search",
3991
+ input: JSON.stringify({}),
3992
+ providerExecuted: true
3993
+ });
3997
3994
  } else if (value.item.type === "computer_call") {
3998
3995
  ongoingToolCalls[value.output_index] = {
3999
3996
  toolName: "computer_use",
@@ -4050,10 +4047,10 @@ var OpenAIResponsesLanguageModel = class {
4050
4047
  }
4051
4048
  }
4052
4049
  });
4053
- } else if (isResponseOutputItemAddedReasoningChunk(value)) {
4050
+ } else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
4054
4051
  activeReasoning[value.item.id] = {
4055
4052
  encryptedContent: value.item.encrypted_content,
4056
- summaryParts: [0]
4053
+ summaryParts: { 0: "active" }
4057
4054
  };
4058
4055
  controller.enqueue({
4059
4056
  type: "reasoning-start",
@@ -4087,22 +4084,11 @@ var OpenAIResponsesLanguageModel = class {
4087
4084
  });
4088
4085
  } else if (value.item.type === "web_search_call") {
4089
4086
  ongoingToolCalls[value.output_index] = void 0;
4090
- controller.enqueue({
4091
- type: "tool-input-end",
4092
- id: value.item.id
4093
- });
4094
- controller.enqueue({
4095
- type: "tool-call",
4096
- toolCallId: value.item.id,
4097
- toolName: "web_search",
4098
- input: JSON.stringify({ action: value.item.action }),
4099
- providerExecuted: true
4100
- });
4101
4087
  controller.enqueue({
4102
4088
  type: "tool-result",
4103
4089
  toolCallId: value.item.id,
4104
4090
  toolName: "web_search",
4105
- result: { status: value.item.status },
4091
+ result: mapWebSearchOutput(value.item.action),
4106
4092
  providerExecuted: true
4107
4093
  });
4108
4094
  } else if (value.item.type === "computer_call") {
@@ -4192,9 +4178,14 @@ var OpenAIResponsesLanguageModel = class {
4192
4178
  type: "text-end",
4193
4179
  id: value.item.id
4194
4180
  });
4195
- } else if (isResponseOutputItemDoneReasoningChunk(value)) {
4181
+ } else if (value.item.type === "reasoning") {
4196
4182
  const activeReasoningPart = activeReasoning[value.item.id];
4197
- for (const summaryIndex of activeReasoningPart.summaryParts) {
4183
+ const summaryPartIndices = Object.entries(
4184
+ activeReasoningPart.summaryParts
4185
+ ).filter(
4186
+ ([_, status]) => status === "active" || status === "can-conclude"
4187
+ ).map(([summaryIndex]) => summaryIndex);
4188
+ for (const summaryIndex of summaryPartIndices) {
4198
4189
  controller.enqueue({
4199
4190
  type: "reasoning-end",
4200
4191
  id: `${value.item.id}:${summaryIndex}`,
@@ -4268,23 +4259,34 @@ var OpenAIResponsesLanguageModel = class {
4268
4259
  if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
4269
4260
  logprobs.push(value.logprobs);
4270
4261
  }
4271
- } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
4262
+ } else if (value.type === "response.reasoning_summary_part.added") {
4272
4263
  if (value.summary_index > 0) {
4273
- (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.summaryParts.push(
4274
- value.summary_index
4275
- );
4264
+ const activeReasoningPart = activeReasoning[value.item_id];
4265
+ activeReasoningPart.summaryParts[value.summary_index] = "active";
4266
+ for (const summaryIndex of Object.keys(
4267
+ activeReasoningPart.summaryParts
4268
+ )) {
4269
+ if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
4270
+ controller.enqueue({
4271
+ type: "reasoning-end",
4272
+ id: `${value.item_id}:${summaryIndex}`,
4273
+ providerMetadata: { openai: { itemId: value.item_id } }
4274
+ });
4275
+ activeReasoningPart.summaryParts[summaryIndex] = "concluded";
4276
+ }
4277
+ }
4276
4278
  controller.enqueue({
4277
4279
  type: "reasoning-start",
4278
4280
  id: `${value.item_id}:${value.summary_index}`,
4279
4281
  providerMetadata: {
4280
4282
  openai: {
4281
4283
  itemId: value.item_id,
4282
- reasoningEncryptedContent: (_i = (_h = activeReasoning[value.item_id]) == null ? void 0 : _h.encryptedContent) != null ? _i : null
4284
+ reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
4283
4285
  }
4284
4286
  }
4285
4287
  });
4286
4288
  }
4287
- } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
4289
+ } else if (value.type === "response.reasoning_summary_text.delta") {
4288
4290
  controller.enqueue({
4289
4291
  type: "reasoning-delta",
4290
4292
  id: `${value.item_id}:${value.summary_index}`,
@@ -4295,16 +4297,29 @@ var OpenAIResponsesLanguageModel = class {
4295
4297
  }
4296
4298
  }
4297
4299
  });
4300
+ } else if (value.type === "response.reasoning_summary_part.done") {
4301
+ if (store) {
4302
+ controller.enqueue({
4303
+ type: "reasoning-end",
4304
+ id: `${value.item_id}:${value.summary_index}`,
4305
+ providerMetadata: {
4306
+ openai: { itemId: value.item_id }
4307
+ }
4308
+ });
4309
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
4310
+ } else {
4311
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
4312
+ }
4298
4313
  } else if (isResponseFinishedChunk(value)) {
4299
4314
  finishReason = mapOpenAIResponseFinishReason({
4300
- finishReason: (_j = value.response.incomplete_details) == null ? void 0 : _j.reason,
4315
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4301
4316
  hasFunctionCall
4302
4317
  });
4303
4318
  usage.inputTokens = value.response.usage.input_tokens;
4304
4319
  usage.outputTokens = value.response.usage.output_tokens;
4305
4320
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
4306
- usage.reasoningTokens = (_l = (_k = value.response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0;
4307
- usage.cachedInputTokens = (_n = (_m = value.response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0;
4321
+ usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
4322
+ usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
4308
4323
  if (typeof value.response.service_tier === "string") {
4309
4324
  serviceTier = value.response.service_tier;
4310
4325
  }
@@ -4313,7 +4328,7 @@ var OpenAIResponsesLanguageModel = class {
4313
4328
  controller.enqueue({
4314
4329
  type: "source",
4315
4330
  sourceType: "url",
4316
- id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
4331
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
4317
4332
  url: value.annotation.url,
4318
4333
  title: value.annotation.title
4319
4334
  });
@@ -4321,10 +4336,10 @@ var OpenAIResponsesLanguageModel = class {
4321
4336
  controller.enqueue({
4322
4337
  type: "source",
4323
4338
  sourceType: "document",
4324
- id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
4339
+ id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
4325
4340
  mediaType: "text/plain",
4326
- title: (_v = (_u = value.annotation.quote) != null ? _u : value.annotation.filename) != null ? _v : "Document",
4327
- filename: (_w = value.annotation.filename) != null ? _w : value.annotation.file_id
4341
+ title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
4342
+ filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id
4328
4343
  });
4329
4344
  }
4330
4345
  } else if (isErrorChunk(value)) {
@@ -4363,9 +4378,6 @@ function isTextDeltaChunk(chunk) {
4363
4378
  function isResponseOutputItemDoneChunk(chunk) {
4364
4379
  return chunk.type === "response.output_item.done";
4365
4380
  }
4366
- function isResponseOutputItemDoneReasoningChunk(chunk) {
4367
- return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
4368
- }
4369
4381
  function isResponseFinishedChunk(chunk) {
4370
4382
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
4371
4383
  }
@@ -4384,18 +4396,9 @@ function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
4384
4396
  function isResponseOutputItemAddedChunk(chunk) {
4385
4397
  return chunk.type === "response.output_item.added";
4386
4398
  }
4387
- function isResponseOutputItemAddedReasoningChunk(chunk) {
4388
- return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
4389
- }
4390
4399
  function isResponseAnnotationAddedChunk(chunk) {
4391
4400
  return chunk.type === "response.output_text.annotation.added";
4392
4401
  }
4393
- function isResponseReasoningSummaryPartAddedChunk(chunk) {
4394
- return chunk.type === "response.reasoning_summary_part.added";
4395
- }
4396
- function isResponseReasoningSummaryTextDeltaChunk(chunk) {
4397
- return chunk.type === "response.reasoning_summary_text.delta";
4398
- }
4399
4402
  function isErrorChunk(chunk) {
4400
4403
  return chunk.type === "error";
4401
4404
  }
@@ -4433,6 +4436,19 @@ function getResponsesModelConfig(modelId) {
4433
4436
  isReasoningModel: false
4434
4437
  };
4435
4438
  }
4439
+ function mapWebSearchOutput(action) {
4440
+ var _a;
4441
+ switch (action.type) {
4442
+ case "search":
4443
+ return { action: { type: "search", query: (_a = action.query) != null ? _a : void 0 } };
4444
+ case "open_page":
4445
+ return { action: { type: "openPage", url: action.url } };
4446
+ case "find":
4447
+ return {
4448
+ action: { type: "find", url: action.url, pattern: action.pattern }
4449
+ };
4450
+ }
4451
+ }
4436
4452
  export {
4437
4453
  OpenAIChatLanguageModel,
4438
4454
  OpenAICompletionLanguageModel,