@ai-sdk/openai 2.0.13 → 2.0.15

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.
@@ -2606,7 +2606,7 @@ var OpenAIResponsesLanguageModel = class {
2606
2606
  });
2607
2607
  }
2608
2608
  }
2609
- if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2609
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelConfig.supportsFlexProcessing) {
2610
2610
  warnings.push({
2611
2611
  type: "unsupported-setting",
2612
2612
  setting: "serviceTier",
@@ -2614,7 +2614,7 @@ var OpenAIResponsesLanguageModel = class {
2614
2614
  });
2615
2615
  delete baseArgs.service_tier;
2616
2616
  }
2617
- if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !supportsPriorityProcessing2(this.modelId)) {
2617
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !modelConfig.supportsPriorityProcessing) {
2618
2618
  warnings.push({
2619
2619
  type: "unsupported-setting",
2620
2620
  setting: "serviceTier",
@@ -2641,7 +2641,7 @@ var OpenAIResponsesLanguageModel = class {
2641
2641
  };
2642
2642
  }
2643
2643
  async doGenerate(options) {
2644
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2644
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2645
2645
  const { args: body, warnings } = await this.getArgs(options);
2646
2646
  const url = this.config.url({
2647
2647
  path: "/responses",
@@ -2677,13 +2677,22 @@ var OpenAIResponsesLanguageModel = class {
2677
2677
  text: import_v416.z.string(),
2678
2678
  logprobs: LOGPROBS_SCHEMA.nullish(),
2679
2679
  annotations: import_v416.z.array(
2680
- import_v416.z.object({
2681
- type: import_v416.z.literal("url_citation"),
2682
- start_index: import_v416.z.number(),
2683
- end_index: import_v416.z.number(),
2684
- url: import_v416.z.string(),
2685
- title: import_v416.z.string()
2686
- })
2680
+ import_v416.z.discriminatedUnion("type", [
2681
+ import_v416.z.object({
2682
+ type: import_v416.z.literal("url_citation"),
2683
+ start_index: import_v416.z.number(),
2684
+ end_index: import_v416.z.number(),
2685
+ url: import_v416.z.string(),
2686
+ title: import_v416.z.string()
2687
+ }),
2688
+ import_v416.z.object({
2689
+ type: import_v416.z.literal("file_citation"),
2690
+ start_index: import_v416.z.number(),
2691
+ end_index: import_v416.z.number(),
2692
+ file_id: import_v416.z.string(),
2693
+ quote: import_v416.z.string()
2694
+ })
2695
+ ])
2687
2696
  )
2688
2697
  })
2689
2698
  )
@@ -2698,7 +2707,11 @@ var OpenAIResponsesLanguageModel = class {
2698
2707
  import_v416.z.object({
2699
2708
  type: import_v416.z.literal("web_search_call"),
2700
2709
  id: import_v416.z.string(),
2701
- status: import_v416.z.string().optional()
2710
+ status: import_v416.z.string().optional(),
2711
+ action: import_v416.z.object({
2712
+ type: import_v416.z.literal("search"),
2713
+ query: import_v416.z.string().optional()
2714
+ }).nullish()
2702
2715
  }),
2703
2716
  import_v416.z.object({
2704
2717
  type: import_v416.z.literal("computer_call"),
@@ -2789,13 +2802,24 @@ var OpenAIResponsesLanguageModel = class {
2789
2802
  }
2790
2803
  });
2791
2804
  for (const annotation of contentPart.annotations) {
2792
- content.push({
2793
- type: "source",
2794
- sourceType: "url",
2795
- id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils14.generateId)(),
2796
- url: annotation.url,
2797
- title: annotation.title
2798
- });
2805
+ if (annotation.type === "url_citation") {
2806
+ content.push({
2807
+ type: "source",
2808
+ sourceType: "url",
2809
+ id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils14.generateId)(),
2810
+ url: annotation.url,
2811
+ title: annotation.title
2812
+ });
2813
+ } else if (annotation.type === "file_citation") {
2814
+ content.push({
2815
+ type: "source",
2816
+ sourceType: "document",
2817
+ id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils14.generateId)(),
2818
+ mediaType: "text/plain",
2819
+ title: annotation.quote,
2820
+ filename: annotation.file_id
2821
+ });
2822
+ }
2799
2823
  }
2800
2824
  }
2801
2825
  break;
@@ -2819,14 +2843,17 @@ var OpenAIResponsesLanguageModel = class {
2819
2843
  type: "tool-call",
2820
2844
  toolCallId: part.id,
2821
2845
  toolName: "web_search_preview",
2822
- input: "",
2846
+ input: (_k = (_j = part.action) == null ? void 0 : _j.query) != null ? _k : "",
2823
2847
  providerExecuted: true
2824
2848
  });
2825
2849
  content.push({
2826
2850
  type: "tool-result",
2827
2851
  toolCallId: part.id,
2828
2852
  toolName: "web_search_preview",
2829
- result: { status: part.status || "completed" },
2853
+ result: {
2854
+ status: part.status || "completed",
2855
+ ...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
2856
+ },
2830
2857
  providerExecuted: true
2831
2858
  });
2832
2859
  break;
@@ -2884,15 +2911,15 @@ var OpenAIResponsesLanguageModel = class {
2884
2911
  return {
2885
2912
  content,
2886
2913
  finishReason: mapOpenAIResponseFinishReason({
2887
- finishReason: (_g = response.incomplete_details) == null ? void 0 : _g.reason,
2914
+ finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
2888
2915
  hasToolCalls: content.some((part) => part.type === "tool-call")
2889
2916
  }),
2890
2917
  usage: {
2891
2918
  inputTokens: response.usage.input_tokens,
2892
2919
  outputTokens: response.usage.output_tokens,
2893
2920
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2894
- reasoningTokens: (_i = (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens) != null ? _i : void 0,
2895
- cachedInputTokens: (_k = (_j = response.usage.input_tokens_details) == null ? void 0 : _j.cached_tokens) != null ? _k : void 0
2921
+ reasoningTokens: (_o = (_n = response.usage.output_tokens_details) == null ? void 0 : _n.reasoning_tokens) != null ? _o : void 0,
2922
+ cachedInputTokens: (_q = (_p = response.usage.input_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
2896
2923
  },
2897
2924
  request: { body },
2898
2925
  response: {
@@ -2944,7 +2971,7 @@ var OpenAIResponsesLanguageModel = class {
2944
2971
  controller.enqueue({ type: "stream-start", warnings });
2945
2972
  },
2946
2973
  transform(chunk, controller) {
2947
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2974
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2948
2975
  if (options.includeRawChunks) {
2949
2976
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2950
2977
  }
@@ -3051,7 +3078,7 @@ var OpenAIResponsesLanguageModel = class {
3051
3078
  type: "tool-call",
3052
3079
  toolCallId: value.item.id,
3053
3080
  toolName: "web_search_preview",
3054
- input: "",
3081
+ input: (_c = (_b = value.item.action) == null ? void 0 : _b.query) != null ? _c : "",
3055
3082
  providerExecuted: true
3056
3083
  });
3057
3084
  controller.enqueue({
@@ -3060,7 +3087,10 @@ var OpenAIResponsesLanguageModel = class {
3060
3087
  toolName: "web_search_preview",
3061
3088
  result: {
3062
3089
  type: "web_search_tool_result",
3063
- status: value.item.status || "completed"
3090
+ status: value.item.status || "completed",
3091
+ ...((_d = value.item.action) == null ? void 0 : _d.query) && {
3092
+ query: value.item.action.query
3093
+ }
3064
3094
  },
3065
3095
  providerExecuted: true
3066
3096
  });
@@ -3128,7 +3158,7 @@ var OpenAIResponsesLanguageModel = class {
3128
3158
  providerMetadata: {
3129
3159
  openai: {
3130
3160
  itemId: value.item.id,
3131
- reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
3161
+ reasoningEncryptedContent: (_e = value.item.encrypted_content) != null ? _e : null
3132
3162
  }
3133
3163
  }
3134
3164
  });
@@ -3163,7 +3193,7 @@ var OpenAIResponsesLanguageModel = class {
3163
3193
  }
3164
3194
  } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
3165
3195
  if (value.summary_index > 0) {
3166
- (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
3196
+ (_f = activeReasoning[value.item_id]) == null ? void 0 : _f.summaryParts.push(
3167
3197
  value.summary_index
3168
3198
  );
3169
3199
  controller.enqueue({
@@ -3172,7 +3202,7 @@ var OpenAIResponsesLanguageModel = class {
3172
3202
  providerMetadata: {
3173
3203
  openai: {
3174
3204
  itemId: value.item_id,
3175
- reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
3205
+ reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
3176
3206
  }
3177
3207
  }
3178
3208
  });
@@ -3190,22 +3220,33 @@ var OpenAIResponsesLanguageModel = class {
3190
3220
  });
3191
3221
  } else if (isResponseFinishedChunk(value)) {
3192
3222
  finishReason = mapOpenAIResponseFinishReason({
3193
- finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
3223
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
3194
3224
  hasToolCalls
3195
3225
  });
3196
3226
  usage.inputTokens = value.response.usage.input_tokens;
3197
3227
  usage.outputTokens = value.response.usage.output_tokens;
3198
3228
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
3199
- usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
3200
- usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
3229
+ usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
3230
+ usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
3201
3231
  } else if (isResponseAnnotationAddedChunk(value)) {
3202
- controller.enqueue({
3203
- type: "source",
3204
- sourceType: "url",
3205
- id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils14.generateId)(),
3206
- url: value.annotation.url,
3207
- title: value.annotation.title
3208
- });
3232
+ if (value.annotation.type === "url_citation") {
3233
+ controller.enqueue({
3234
+ type: "source",
3235
+ sourceType: "url",
3236
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils14.generateId)(),
3237
+ url: value.annotation.url,
3238
+ title: value.annotation.title
3239
+ });
3240
+ } else if (value.annotation.type === "file_citation") {
3241
+ controller.enqueue({
3242
+ type: "source",
3243
+ sourceType: "document",
3244
+ id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : (0, import_provider_utils14.generateId)(),
3245
+ mediaType: "text/plain",
3246
+ title: value.annotation.quote,
3247
+ filename: value.annotation.file_id
3248
+ });
3249
+ }
3209
3250
  } else if (isErrorChunk(value)) {
3210
3251
  controller.enqueue({ type: "error", error: value });
3211
3252
  }
@@ -3290,7 +3331,11 @@ var responseOutputItemAddedSchema = import_v416.z.object({
3290
3331
  import_v416.z.object({
3291
3332
  type: import_v416.z.literal("web_search_call"),
3292
3333
  id: import_v416.z.string(),
3293
- status: import_v416.z.string()
3334
+ status: import_v416.z.string(),
3335
+ action: import_v416.z.object({
3336
+ type: import_v416.z.literal("search"),
3337
+ query: import_v416.z.string().optional()
3338
+ }).nullish()
3294
3339
  }),
3295
3340
  import_v416.z.object({
3296
3341
  type: import_v416.z.literal("computer_call"),
@@ -3339,7 +3384,11 @@ var responseOutputItemDoneSchema = import_v416.z.object({
3339
3384
  import_v416.z.object({
3340
3385
  type: import_v416.z.literal("web_search_call"),
3341
3386
  id: import_v416.z.string(),
3342
- status: import_v416.z.literal("completed")
3387
+ status: import_v416.z.literal("completed"),
3388
+ action: import_v416.z.object({
3389
+ type: import_v416.z.literal("search"),
3390
+ query: import_v416.z.string().optional()
3391
+ }).nullish()
3343
3392
  }),
3344
3393
  import_v416.z.object({
3345
3394
  type: import_v416.z.literal("computer_call"),
@@ -3372,11 +3421,18 @@ var responseFunctionCallArgumentsDeltaSchema = import_v416.z.object({
3372
3421
  });
3373
3422
  var responseAnnotationAddedSchema = import_v416.z.object({
3374
3423
  type: import_v416.z.literal("response.output_text.annotation.added"),
3375
- annotation: import_v416.z.object({
3376
- type: import_v416.z.literal("url_citation"),
3377
- url: import_v416.z.string(),
3378
- title: import_v416.z.string()
3379
- })
3424
+ annotation: import_v416.z.discriminatedUnion("type", [
3425
+ import_v416.z.object({
3426
+ type: import_v416.z.literal("url_citation"),
3427
+ url: import_v416.z.string(),
3428
+ title: import_v416.z.string()
3429
+ }),
3430
+ import_v416.z.object({
3431
+ type: import_v416.z.literal("file_citation"),
3432
+ file_id: import_v416.z.string(),
3433
+ quote: import_v416.z.string()
3434
+ })
3435
+ ])
3380
3436
  });
3381
3437
  var responseReasoningSummaryPartAddedSchema = import_v416.z.object({
3382
3438
  type: import_v416.z.literal("response.reasoning_summary_part.added"),
@@ -3440,39 +3496,39 @@ function isErrorChunk(chunk) {
3440
3496
  return chunk.type === "error";
3441
3497
  }
3442
3498
  function getResponsesModelConfig(modelId) {
3499
+ const supportsFlexProcessing2 = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
3500
+ const supportsPriorityProcessing2 = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3501
+ const defaults = {
3502
+ requiredAutoTruncation: false,
3503
+ systemMessageMode: "system",
3504
+ supportsFlexProcessing: supportsFlexProcessing2,
3505
+ supportsPriorityProcessing: supportsPriorityProcessing2
3506
+ };
3443
3507
  if (modelId.startsWith("gpt-5-chat")) {
3444
3508
  return {
3445
- isReasoningModel: false,
3446
- systemMessageMode: "system",
3447
- requiredAutoTruncation: false
3509
+ ...defaults,
3510
+ isReasoningModel: false
3448
3511
  };
3449
3512
  }
3450
3513
  if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
3451
3514
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
3452
3515
  return {
3516
+ ...defaults,
3453
3517
  isReasoningModel: true,
3454
- systemMessageMode: "remove",
3455
- requiredAutoTruncation: false
3518
+ systemMessageMode: "remove"
3456
3519
  };
3457
3520
  }
3458
3521
  return {
3522
+ ...defaults,
3459
3523
  isReasoningModel: true,
3460
- systemMessageMode: "developer",
3461
- requiredAutoTruncation: false
3524
+ systemMessageMode: "developer"
3462
3525
  };
3463
3526
  }
3464
3527
  return {
3465
- isReasoningModel: false,
3466
- systemMessageMode: "system",
3467
- requiredAutoTruncation: false
3528
+ ...defaults,
3529
+ isReasoningModel: false
3468
3530
  };
3469
3531
  }
3470
- function supportsFlexProcessing2(modelId) {
3471
- return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
3472
- }
3473
- function supportsPriorityProcessing2(modelId) {
3474
- return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3475
- }
3476
3532
  var openaiResponsesProviderOptionsSchema = import_v416.z.object({
3477
3533
  metadata: import_v416.z.any().nullish(),
3478
3534
  parallelToolCalls: import_v416.z.boolean().nullish(),