@ai-sdk/openai 2.0.134 → 2.0.136

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.
@@ -65,7 +65,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
65
65
  // src/openai-error.ts
66
66
  var import_v4 = require("zod/v4");
67
67
  var import_provider_utils = require("@ai-sdk/provider-utils");
68
- var openaiErrorDataSchema = import_v4.z.object({
68
+ var openaiErrorDataSchema = () => import_v4.z.object({
69
69
  error: import_v4.z.object({
70
70
  message: import_v4.z.string(),
71
71
  // The additional information below is handled loosely to support
@@ -76,8 +76,11 @@ var openaiErrorDataSchema = import_v4.z.object({
76
76
  code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
77
77
  })
78
78
  });
79
+ var openaiErrorDataSchemaValidator = (0, import_provider_utils.lazySchema)(
80
+ () => (0, import_provider_utils.zodSchema)(openaiErrorDataSchema())
81
+ );
79
82
  var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
80
- errorSchema: openaiErrorDataSchema,
83
+ errorSchema: openaiErrorDataSchemaValidator,
81
84
  errorToMessage: (data) => data.error.message
82
85
  });
83
86
 
@@ -547,7 +550,7 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
547
550
  }).nullish()
548
551
  }).nullish()
549
552
  }),
550
- openaiErrorDataSchema
553
+ openaiErrorDataSchema()
551
554
  ])
552
555
  )
553
556
  );
@@ -1350,7 +1353,7 @@ var openaiCompletionChunkSchema = (0, import_provider_utils6.lazyValidator)(
1350
1353
  total_tokens: import_v44.z.number()
1351
1354
  }).nullish()
1352
1355
  }),
1353
- openaiErrorDataSchema
1356
+ openaiErrorDataSchema()
1354
1357
  ])
1355
1358
  )
1356
1359
  );
@@ -1790,7 +1793,7 @@ function getMaxImagesPerCall(modelId) {
1790
1793
  var _a2;
1791
1794
  return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
1792
1795
  }
1793
- var baseImageModelOptionsObject = import_v49.z.object({
1796
+ var baseImageModelOptionsObject = () => import_v49.z.object({
1794
1797
  /**
1795
1798
  * Quality of the generated image(s).
1796
1799
  *
@@ -1820,11 +1823,11 @@ var baseImageModelOptionsObject = import_v49.z.object({
1820
1823
  user: import_v49.z.string().optional()
1821
1824
  });
1822
1825
  var openaiImageModelOptions = (0, import_provider_utils13.lazyValidator)(
1823
- () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject)
1826
+ () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
1824
1827
  );
1825
1828
  var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazyValidator)(
1826
1829
  () => (0, import_provider_utils13.zodSchema)(
1827
- baseImageModelOptionsObject.extend({
1830
+ baseImageModelOptionsObject().extend({
1828
1831
  /**
1829
1832
  * Style of the generated image. `vivid` produces hyper-real and
1830
1833
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -2679,6 +2682,7 @@ async function convertToOpenAIResponsesInput({
2679
2682
  explicitMessageItemType = false,
2680
2683
  fileIdPrefixes,
2681
2684
  store,
2685
+ isReasoningModel = false,
2682
2686
  configurationUpdateUnsupportedReason,
2683
2687
  hasLocalShellTool = false,
2684
2688
  webSearchToolName
@@ -2832,12 +2836,14 @@ async function convertToOpenAIResponsesInput({
2832
2836
  case "assistant": {
2833
2837
  const reasoningMessages = {};
2834
2838
  const toolCallParts = {};
2839
+ let hasPrecedingReasoning = false;
2835
2840
  for (const part of content) {
2836
2841
  switch (part.type) {
2837
2842
  case "text": {
2838
2843
  const id = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.itemId;
2839
2844
  const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
2840
- if (store && id != null) {
2845
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2846
+ if (store && canUseItemId) {
2841
2847
  input.push({ type: "item_reference", id });
2842
2848
  break;
2843
2849
  }
@@ -2845,7 +2851,7 @@ async function convertToOpenAIResponsesInput({
2845
2851
  ...explicitMessageItemType && { type: "message" },
2846
2852
  role: "assistant",
2847
2853
  content: [{ type: "output_text", text: part.text }],
2848
- id,
2854
+ id: canUseItemId ? id : void 0,
2849
2855
  ...phase != null && { phase }
2850
2856
  });
2851
2857
  break;
@@ -2857,7 +2863,8 @@ async function convertToOpenAIResponsesInput({
2857
2863
  }
2858
2864
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2859
2865
  const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2860
- if (store && id != null) {
2866
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2867
+ if (store && canUseItemId) {
2861
2868
  input.push({ type: "item_reference", id });
2862
2869
  break;
2863
2870
  }
@@ -2887,7 +2894,7 @@ async function convertToOpenAIResponsesInput({
2887
2894
  name: part.toolName,
2888
2895
  arguments: JSON.stringify(part.input),
2889
2896
  ...isAsync != null && { async: isAsync },
2890
- id
2897
+ id: canUseItemId ? id : void 0
2891
2898
  });
2892
2899
  break;
2893
2900
  }
@@ -2919,6 +2926,7 @@ async function convertToOpenAIResponsesInput({
2919
2926
  break;
2920
2927
  }
2921
2928
  case "reasoning": {
2929
+ hasPrecedingReasoning = true;
2922
2930
  const providerOptions2 = await (0, import_provider_utils23.parseProviderOptions)({
2923
2931
  provider: "openai",
2924
2932
  providerOptions: part.providerOptions,
@@ -3076,10 +3084,14 @@ async function convertToOpenAIResponsesInput({
3076
3084
  }
3077
3085
  return { input, warnings };
3078
3086
  }
3079
- var openaiResponsesReasoningProviderOptionsSchema = import_v416.z.object({
3080
- itemId: import_v416.z.string().nullish(),
3081
- reasoningEncryptedContent: import_v416.z.string().nullish()
3082
- });
3087
+ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils23.lazySchema)(
3088
+ () => (0, import_provider_utils23.zodSchema)(
3089
+ import_v416.z.object({
3090
+ itemId: import_v416.z.string().nullish(),
3091
+ reasoningEncryptedContent: import_v416.z.string().nullish()
3092
+ })
3093
+ )
3094
+ );
3083
3095
 
3084
3096
  // src/responses/map-openai-responses-finish-reason.ts
3085
3097
  function mapOpenAIResponseFinishReason({
@@ -3637,15 +3649,16 @@ var codeInterpreter = (args = {}) => {
3637
3649
  // src/tool/file-search.ts
3638
3650
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
3639
3651
  var import_v419 = require("zod/v4");
3640
- var comparisonFilterSchema = import_v419.z.object({
3652
+ var comparisonFilterSchema = () => import_v419.z.object({
3641
3653
  key: import_v419.z.string(),
3642
3654
  type: import_v419.z.enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
3643
3655
  value: import_v419.z.union([import_v419.z.string(), import_v419.z.number(), import_v419.z.boolean(), import_v419.z.array(import_v419.z.string())])
3644
3656
  });
3645
- var compoundFilterSchema = import_v419.z.object({
3657
+ var cachedCompoundFilterSchema;
3658
+ var compoundFilterSchema = () => cachedCompoundFilterSchema != null ? cachedCompoundFilterSchema : cachedCompoundFilterSchema = import_v419.z.object({
3646
3659
  type: import_v419.z.enum(["and", "or"]),
3647
3660
  filters: import_v419.z.array(
3648
- import_v419.z.union([comparisonFilterSchema, import_v419.z.lazy(() => compoundFilterSchema)])
3661
+ import_v419.z.union([comparisonFilterSchema(), import_v419.z.lazy(() => compoundFilterSchema())])
3649
3662
  )
3650
3663
  });
3651
3664
  var fileSearchArgsSchema = (0, import_provider_utils26.lazySchema)(
@@ -3657,7 +3670,7 @@ var fileSearchArgsSchema = (0, import_provider_utils26.lazySchema)(
3657
3670
  ranker: import_v419.z.string().optional(),
3658
3671
  scoreThreshold: import_v419.z.number().optional()
3659
3672
  }).optional(),
3660
- filters: import_v419.z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
3673
+ filters: import_v419.z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
3661
3674
  })
3662
3675
  )
3663
3676
  );
@@ -4030,6 +4043,7 @@ var OpenAIResponsesLanguageModel = class {
4030
4043
  explicitMessageItemType: this.config.explicitMessageItemType,
4031
4044
  fileIdPrefixes: this.config.fileIdPrefixes,
4032
4045
  store: (_b = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _b : true,
4046
+ isReasoningModel: modelCapabilities.isReasoningModel,
4033
4047
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
4034
4048
  webSearchToolName
4035
4049
  });