@ai-sdk/openai 2.0.16 → 2.0.18

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.
@@ -420,7 +420,23 @@ var webSearchPreviewArgsSchema = z4.object({
420
420
  var webSearchPreview = createProviderDefinedToolFactory2({
421
421
  id: "openai.web_search_preview",
422
422
  name: "web_search_preview",
423
- inputSchema: z4.object({})
423
+ inputSchema: z4.object({
424
+ action: z4.discriminatedUnion("type", [
425
+ z4.object({
426
+ type: z4.literal("search"),
427
+ query: z4.string()
428
+ }),
429
+ z4.object({
430
+ type: z4.literal("open_page"),
431
+ url: z4.string()
432
+ }),
433
+ z4.object({
434
+ type: z4.literal("find"),
435
+ url: z4.string(),
436
+ pattern: z4.string()
437
+ })
438
+ ]).nullish()
439
+ })
424
440
  });
425
441
 
426
442
  // src/chat/openai-chat-prepare-tools.ts
@@ -2205,9 +2221,10 @@ async function convertToOpenAIResponsesMessages({
2205
2221
  };
2206
2222
  } else if (part.mediaType === "application/pdf") {
2207
2223
  if (part.data instanceof URL) {
2208
- throw new UnsupportedFunctionalityError4({
2209
- functionality: "PDF file parts with URLs"
2210
- });
2224
+ return {
2225
+ type: "input_file",
2226
+ file_url: part.data.toString()
2227
+ };
2211
2228
  }
2212
2229
  return {
2213
2230
  type: "input_file",
@@ -2466,6 +2483,26 @@ function prepareResponsesTools({
2466
2483
  }
2467
2484
 
2468
2485
  // src/responses/openai-responses-language-model.ts
2486
+ var webSearchCallItem = z16.object({
2487
+ type: z16.literal("web_search_call"),
2488
+ id: z16.string(),
2489
+ status: z16.string(),
2490
+ action: z16.discriminatedUnion("type", [
2491
+ z16.object({
2492
+ type: z16.literal("search"),
2493
+ query: z16.string()
2494
+ }),
2495
+ z16.object({
2496
+ type: z16.literal("open_page"),
2497
+ url: z16.string()
2498
+ }),
2499
+ z16.object({
2500
+ type: z16.literal("find"),
2501
+ url: z16.string(),
2502
+ pattern: z16.string()
2503
+ })
2504
+ ]).nullish()
2505
+ });
2469
2506
  var TOP_LOGPROBS_MAX = 20;
2470
2507
  var LOGPROBS_SCHEMA = z16.array(
2471
2508
  z16.object({
@@ -2483,7 +2520,8 @@ var OpenAIResponsesLanguageModel = class {
2483
2520
  constructor(modelId, config) {
2484
2521
  this.specificationVersion = "v2";
2485
2522
  this.supportedUrls = {
2486
- "image/*": [/^https?:\/\/.*$/]
2523
+ "image/*": [/^https?:\/\/.*$/],
2524
+ "application/pdf": [/^https?:\/\/.*$/]
2487
2525
  };
2488
2526
  this.modelId = modelId;
2489
2527
  this.config = config;
@@ -2661,7 +2699,7 @@ var OpenAIResponsesLanguageModel = class {
2661
2699
  };
2662
2700
  }
2663
2701
  async doGenerate(options) {
2664
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2702
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2665
2703
  const { args: body, warnings } = await this.getArgs(options);
2666
2704
  const url = this.config.url({
2667
2705
  path: "/responses",
@@ -2724,15 +2762,7 @@ var OpenAIResponsesLanguageModel = class {
2724
2762
  arguments: z16.string(),
2725
2763
  id: z16.string()
2726
2764
  }),
2727
- z16.object({
2728
- type: z16.literal("web_search_call"),
2729
- id: z16.string(),
2730
- status: z16.string().optional(),
2731
- action: z16.object({
2732
- type: z16.literal("search"),
2733
- query: z16.string().optional()
2734
- }).nullish()
2735
- }),
2765
+ webSearchCallItem,
2736
2766
  z16.object({
2737
2767
  type: z16.literal("computer_call"),
2738
2768
  id: z16.string(),
@@ -2863,17 +2893,14 @@ var OpenAIResponsesLanguageModel = class {
2863
2893
  type: "tool-call",
2864
2894
  toolCallId: part.id,
2865
2895
  toolName: "web_search_preview",
2866
- input: (_k = (_j = part.action) == null ? void 0 : _j.query) != null ? _k : "",
2896
+ input: JSON.stringify({ action: part.action }),
2867
2897
  providerExecuted: true
2868
2898
  });
2869
2899
  content.push({
2870
2900
  type: "tool-result",
2871
2901
  toolCallId: part.id,
2872
2902
  toolName: "web_search_preview",
2873
- result: {
2874
- status: part.status || "completed",
2875
- ...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
2876
- },
2903
+ result: { status: part.status },
2877
2904
  providerExecuted: true
2878
2905
  });
2879
2906
  break;
@@ -2931,15 +2958,15 @@ var OpenAIResponsesLanguageModel = class {
2931
2958
  return {
2932
2959
  content,
2933
2960
  finishReason: mapOpenAIResponseFinishReason({
2934
- finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
2961
+ finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
2935
2962
  hasToolCalls: content.some((part) => part.type === "tool-call")
2936
2963
  }),
2937
2964
  usage: {
2938
2965
  inputTokens: response.usage.input_tokens,
2939
2966
  outputTokens: response.usage.output_tokens,
2940
2967
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2941
- reasoningTokens: (_o = (_n = response.usage.output_tokens_details) == null ? void 0 : _n.reasoning_tokens) != null ? _o : void 0,
2942
- cachedInputTokens: (_q = (_p = response.usage.input_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
2968
+ reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
2969
+ cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
2943
2970
  },
2944
2971
  request: { body },
2945
2972
  response: {
@@ -2991,7 +3018,7 @@ var OpenAIResponsesLanguageModel = class {
2991
3018
  controller.enqueue({ type: "stream-start", warnings });
2992
3019
  },
2993
3020
  transform(chunk, controller) {
2994
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
3021
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2995
3022
  if (options.includeRawChunks) {
2996
3023
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2997
3024
  }
@@ -3098,20 +3125,14 @@ var OpenAIResponsesLanguageModel = class {
3098
3125
  type: "tool-call",
3099
3126
  toolCallId: value.item.id,
3100
3127
  toolName: "web_search_preview",
3101
- input: (_c = (_b = value.item.action) == null ? void 0 : _b.query) != null ? _c : "",
3128
+ input: JSON.stringify({ action: value.item.action }),
3102
3129
  providerExecuted: true
3103
3130
  });
3104
3131
  controller.enqueue({
3105
3132
  type: "tool-result",
3106
3133
  toolCallId: value.item.id,
3107
3134
  toolName: "web_search_preview",
3108
- result: {
3109
- type: "web_search_tool_result",
3110
- status: value.item.status || "completed",
3111
- ...((_d = value.item.action) == null ? void 0 : _d.query) && {
3112
- query: value.item.action.query
3113
- }
3114
- },
3135
+ result: { status: value.item.status },
3115
3136
  providerExecuted: true
3116
3137
  });
3117
3138
  } else if (value.item.type === "computer_call") {
@@ -3178,7 +3199,7 @@ var OpenAIResponsesLanguageModel = class {
3178
3199
  providerMetadata: {
3179
3200
  openai: {
3180
3201
  itemId: value.item.id,
3181
- reasoningEncryptedContent: (_e = value.item.encrypted_content) != null ? _e : null
3202
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
3182
3203
  }
3183
3204
  }
3184
3205
  });
@@ -3213,7 +3234,7 @@ var OpenAIResponsesLanguageModel = class {
3213
3234
  }
3214
3235
  } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
3215
3236
  if (value.summary_index > 0) {
3216
- (_f = activeReasoning[value.item_id]) == null ? void 0 : _f.summaryParts.push(
3237
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
3217
3238
  value.summary_index
3218
3239
  );
3219
3240
  controller.enqueue({
@@ -3222,7 +3243,7 @@ var OpenAIResponsesLanguageModel = class {
3222
3243
  providerMetadata: {
3223
3244
  openai: {
3224
3245
  itemId: value.item_id,
3225
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
3246
+ reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
3226
3247
  }
3227
3248
  }
3228
3249
  });
@@ -3240,20 +3261,20 @@ var OpenAIResponsesLanguageModel = class {
3240
3261
  });
3241
3262
  } else if (isResponseFinishedChunk(value)) {
3242
3263
  finishReason = mapOpenAIResponseFinishReason({
3243
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
3264
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
3244
3265
  hasToolCalls
3245
3266
  });
3246
3267
  usage.inputTokens = value.response.usage.input_tokens;
3247
3268
  usage.outputTokens = value.response.usage.output_tokens;
3248
3269
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
3249
- usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
3250
- usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
3270
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
3271
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
3251
3272
  } else if (isResponseAnnotationAddedChunk(value)) {
3252
3273
  if (value.annotation.type === "url_citation") {
3253
3274
  controller.enqueue({
3254
3275
  type: "source",
3255
3276
  sourceType: "url",
3256
- id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
3277
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
3257
3278
  url: value.annotation.url,
3258
3279
  title: value.annotation.title
3259
3280
  });
@@ -3261,7 +3282,7 @@ var OpenAIResponsesLanguageModel = class {
3261
3282
  controller.enqueue({
3262
3283
  type: "source",
3263
3284
  sourceType: "document",
3264
- id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
3285
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
3265
3286
  mediaType: "text/plain",
3266
3287
  title: value.annotation.quote,
3267
3288
  filename: value.annotation.file_id
@@ -3401,15 +3422,7 @@ var responseOutputItemDoneSchema = z16.object({
3401
3422
  arguments: z16.string(),
3402
3423
  status: z16.literal("completed")
3403
3424
  }),
3404
- z16.object({
3405
- type: z16.literal("web_search_call"),
3406
- id: z16.string(),
3407
- status: z16.literal("completed"),
3408
- action: z16.object({
3409
- type: z16.literal("search"),
3410
- query: z16.string().optional()
3411
- }).nullish()
3412
- }),
3425
+ webSearchCallItem,
3413
3426
  z16.object({
3414
3427
  type: z16.literal("computer_call"),
3415
3428
  id: z16.string(),