@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.136
4
+
5
+ ### Patch Changes
6
+
7
+ - 2d22edb: Defer validation schema construction until first use to reduce provider import time.
8
+ - Updated dependencies [d7b0ffa]
9
+ - Updated dependencies [4146790]
10
+ - @ai-sdk/provider-utils@3.0.42
11
+
12
+ ## 2.0.135
13
+
14
+ ### Patch Changes
15
+
16
+ - c883c47: fix(openai): send assistant text and function calls with content instead of an item reference when their reasoning was removed
17
+
18
+ With reasoning models, pruning reasoning (e.g. `pruneMessages({ reasoning: 'all' })`) caused follow-up requests to fail with "Item 'msg*...' of type 'message' was provided without its required 'reasoning' item" or "Item 'fc*...' of type 'function_call' was provided without its required 'reasoning' item". Assistant text and function call parts are now only sent as item references, or with their item id, when they are preceded by reasoning in the same assistant message.
19
+
3
20
  ## 2.0.134
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
36
36
  // src/openai-error.ts
37
37
  var import_v4 = require("zod/v4");
38
38
  var import_provider_utils = require("@ai-sdk/provider-utils");
39
- var openaiErrorDataSchema = import_v4.z.object({
39
+ var openaiErrorDataSchema = () => import_v4.z.object({
40
40
  error: import_v4.z.object({
41
41
  message: import_v4.z.string(),
42
42
  // The additional information below is handled loosely to support
@@ -47,8 +47,11 @@ var openaiErrorDataSchema = import_v4.z.object({
47
47
  code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
48
48
  })
49
49
  });
50
+ var openaiErrorDataSchemaValidator = (0, import_provider_utils.lazySchema)(
51
+ () => (0, import_provider_utils.zodSchema)(openaiErrorDataSchema())
52
+ );
50
53
  var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
51
- errorSchema: openaiErrorDataSchema,
54
+ errorSchema: openaiErrorDataSchemaValidator,
52
55
  errorToMessage: (data) => data.error.message
53
56
  });
54
57
 
@@ -518,7 +521,7 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
518
521
  }).nullish()
519
522
  }).nullish()
520
523
  }),
521
- openaiErrorDataSchema
524
+ openaiErrorDataSchema()
522
525
  ])
523
526
  )
524
527
  );
@@ -1321,7 +1324,7 @@ var openaiCompletionChunkSchema = (0, import_provider_utils6.lazyValidator)(
1321
1324
  total_tokens: import_v44.z.number()
1322
1325
  }).nullish()
1323
1326
  }),
1324
- openaiErrorDataSchema
1327
+ openaiErrorDataSchema()
1325
1328
  ])
1326
1329
  )
1327
1330
  );
@@ -1761,7 +1764,7 @@ function getMaxImagesPerCall(modelId) {
1761
1764
  var _a2;
1762
1765
  return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
1763
1766
  }
1764
- var baseImageModelOptionsObject = import_v49.z.object({
1767
+ var baseImageModelOptionsObject = () => import_v49.z.object({
1765
1768
  /**
1766
1769
  * Quality of the generated image(s).
1767
1770
  *
@@ -1791,11 +1794,11 @@ var baseImageModelOptionsObject = import_v49.z.object({
1791
1794
  user: import_v49.z.string().optional()
1792
1795
  });
1793
1796
  var openaiImageModelOptions = (0, import_provider_utils13.lazyValidator)(
1794
- () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject)
1797
+ () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
1795
1798
  );
1796
1799
  var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazyValidator)(
1797
1800
  () => (0, import_provider_utils13.zodSchema)(
1798
- baseImageModelOptionsObject.extend({
1801
+ baseImageModelOptionsObject().extend({
1799
1802
  /**
1800
1803
  * Style of the generated image. `vivid` produces hyper-real and
1801
1804
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -1984,15 +1987,16 @@ var codeInterpreter = (args = {}) => {
1984
1987
  // src/tool/file-search.ts
1985
1988
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
1986
1989
  var import_v411 = require("zod/v4");
1987
- var comparisonFilterSchema = import_v411.z.object({
1990
+ var comparisonFilterSchema = () => import_v411.z.object({
1988
1991
  key: import_v411.z.string(),
1989
1992
  type: import_v411.z.enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
1990
1993
  value: import_v411.z.union([import_v411.z.string(), import_v411.z.number(), import_v411.z.boolean(), import_v411.z.array(import_v411.z.string())])
1991
1994
  });
1992
- var compoundFilterSchema = import_v411.z.object({
1995
+ var cachedCompoundFilterSchema;
1996
+ var compoundFilterSchema = () => cachedCompoundFilterSchema != null ? cachedCompoundFilterSchema : cachedCompoundFilterSchema = import_v411.z.object({
1993
1997
  type: import_v411.z.enum(["and", "or"]),
1994
1998
  filters: import_v411.z.array(
1995
- import_v411.z.union([comparisonFilterSchema, import_v411.z.lazy(() => compoundFilterSchema)])
1999
+ import_v411.z.union([comparisonFilterSchema(), import_v411.z.lazy(() => compoundFilterSchema())])
1996
2000
  )
1997
2001
  });
1998
2002
  var fileSearchArgsSchema = (0, import_provider_utils16.lazySchema)(
@@ -2004,7 +2008,7 @@ var fileSearchArgsSchema = (0, import_provider_utils16.lazySchema)(
2004
2008
  ranker: import_v411.z.string().optional(),
2005
2009
  scoreThreshold: import_v411.z.number().optional()
2006
2010
  }).optional(),
2007
- filters: import_v411.z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
2011
+ filters: import_v411.z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
2008
2012
  })
2009
2013
  )
2010
2014
  );
@@ -2550,6 +2554,7 @@ async function convertToOpenAIResponsesInput({
2550
2554
  explicitMessageItemType = false,
2551
2555
  fileIdPrefixes,
2552
2556
  store,
2557
+ isReasoningModel = false,
2553
2558
  configurationUpdateUnsupportedReason,
2554
2559
  hasLocalShellTool = false,
2555
2560
  webSearchToolName
@@ -2703,12 +2708,14 @@ async function convertToOpenAIResponsesInput({
2703
2708
  case "assistant": {
2704
2709
  const reasoningMessages = {};
2705
2710
  const toolCallParts = {};
2711
+ let hasPrecedingReasoning = false;
2706
2712
  for (const part of content) {
2707
2713
  switch (part.type) {
2708
2714
  case "text": {
2709
2715
  const id = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.itemId;
2710
2716
  const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
2711
- if (store && id != null) {
2717
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2718
+ if (store && canUseItemId) {
2712
2719
  input.push({ type: "item_reference", id });
2713
2720
  break;
2714
2721
  }
@@ -2716,7 +2723,7 @@ async function convertToOpenAIResponsesInput({
2716
2723
  ...explicitMessageItemType && { type: "message" },
2717
2724
  role: "assistant",
2718
2725
  content: [{ type: "output_text", text: part.text }],
2719
- id,
2726
+ id: canUseItemId ? id : void 0,
2720
2727
  ...phase != null && { phase }
2721
2728
  });
2722
2729
  break;
@@ -2728,7 +2735,8 @@ async function convertToOpenAIResponsesInput({
2728
2735
  }
2729
2736
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2730
2737
  const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2731
- if (store && id != null) {
2738
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2739
+ if (store && canUseItemId) {
2732
2740
  input.push({ type: "item_reference", id });
2733
2741
  break;
2734
2742
  }
@@ -2758,7 +2766,7 @@ async function convertToOpenAIResponsesInput({
2758
2766
  name: part.toolName,
2759
2767
  arguments: JSON.stringify(part.input),
2760
2768
  ...isAsync != null && { async: isAsync },
2761
- id
2769
+ id: canUseItemId ? id : void 0
2762
2770
  });
2763
2771
  break;
2764
2772
  }
@@ -2790,6 +2798,7 @@ async function convertToOpenAIResponsesInput({
2790
2798
  break;
2791
2799
  }
2792
2800
  case "reasoning": {
2801
+ hasPrecedingReasoning = true;
2793
2802
  const providerOptions2 = await (0, import_provider_utils22.parseProviderOptions)({
2794
2803
  provider: "openai",
2795
2804
  providerOptions: part.providerOptions,
@@ -2947,10 +2956,14 @@ async function convertToOpenAIResponsesInput({
2947
2956
  }
2948
2957
  return { input, warnings };
2949
2958
  }
2950
- var openaiResponsesReasoningProviderOptionsSchema = import_v417.z.object({
2951
- itemId: import_v417.z.string().nullish(),
2952
- reasoningEncryptedContent: import_v417.z.string().nullish()
2953
- });
2959
+ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils22.lazySchema)(
2960
+ () => (0, import_provider_utils22.zodSchema)(
2961
+ import_v417.z.object({
2962
+ itemId: import_v417.z.string().nullish(),
2963
+ reasoningEncryptedContent: import_v417.z.string().nullish()
2964
+ })
2965
+ )
2966
+ );
2954
2967
 
2955
2968
  // src/responses/map-openai-responses-finish-reason.ts
2956
2969
  function mapOpenAIResponseFinishReason({
@@ -3720,6 +3733,7 @@ var OpenAIResponsesLanguageModel = class {
3720
3733
  explicitMessageItemType: this.config.explicitMessageItemType,
3721
3734
  fileIdPrefixes: this.config.fileIdPrefixes,
3722
3735
  store: (_b = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _b : true,
3736
+ isReasoningModel: modelCapabilities.isReasoningModel,
3723
3737
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3724
3738
  webSearchToolName
3725
3739
  });
@@ -5206,7 +5220,7 @@ var OpenAITranscriptionModel = class {
5206
5220
  };
5207
5221
 
5208
5222
  // src/version.ts
5209
- var VERSION = true ? "2.0.134" : "0.0.0-test";
5223
+ var VERSION = true ? "2.0.136" : "0.0.0-test";
5210
5224
 
5211
5225
  // src/openai-provider.ts
5212
5226
  function createOpenAI(options = {}) {