@ai-sdk/openai 2.0.134 → 2.0.135

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,13 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.135
4
+
5
+ ### Patch Changes
6
+
7
+ - c883c47: fix(openai): send assistant text and function calls with content instead of an item reference when their reasoning was removed
8
+
9
+ 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.
10
+
3
11
  ## 2.0.134
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2550,6 +2550,7 @@ async function convertToOpenAIResponsesInput({
2550
2550
  explicitMessageItemType = false,
2551
2551
  fileIdPrefixes,
2552
2552
  store,
2553
+ isReasoningModel = false,
2553
2554
  configurationUpdateUnsupportedReason,
2554
2555
  hasLocalShellTool = false,
2555
2556
  webSearchToolName
@@ -2703,12 +2704,14 @@ async function convertToOpenAIResponsesInput({
2703
2704
  case "assistant": {
2704
2705
  const reasoningMessages = {};
2705
2706
  const toolCallParts = {};
2707
+ let hasPrecedingReasoning = false;
2706
2708
  for (const part of content) {
2707
2709
  switch (part.type) {
2708
2710
  case "text": {
2709
2711
  const id = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.itemId;
2710
2712
  const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
2711
- if (store && id != null) {
2713
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2714
+ if (store && canUseItemId) {
2712
2715
  input.push({ type: "item_reference", id });
2713
2716
  break;
2714
2717
  }
@@ -2716,7 +2719,7 @@ async function convertToOpenAIResponsesInput({
2716
2719
  ...explicitMessageItemType && { type: "message" },
2717
2720
  role: "assistant",
2718
2721
  content: [{ type: "output_text", text: part.text }],
2719
- id,
2722
+ id: canUseItemId ? id : void 0,
2720
2723
  ...phase != null && { phase }
2721
2724
  });
2722
2725
  break;
@@ -2728,7 +2731,8 @@ async function convertToOpenAIResponsesInput({
2728
2731
  }
2729
2732
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2730
2733
  const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2731
- if (store && id != null) {
2734
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
2735
+ if (store && canUseItemId) {
2732
2736
  input.push({ type: "item_reference", id });
2733
2737
  break;
2734
2738
  }
@@ -2758,7 +2762,7 @@ async function convertToOpenAIResponsesInput({
2758
2762
  name: part.toolName,
2759
2763
  arguments: JSON.stringify(part.input),
2760
2764
  ...isAsync != null && { async: isAsync },
2761
- id
2765
+ id: canUseItemId ? id : void 0
2762
2766
  });
2763
2767
  break;
2764
2768
  }
@@ -2790,6 +2794,7 @@ async function convertToOpenAIResponsesInput({
2790
2794
  break;
2791
2795
  }
2792
2796
  case "reasoning": {
2797
+ hasPrecedingReasoning = true;
2793
2798
  const providerOptions2 = await (0, import_provider_utils22.parseProviderOptions)({
2794
2799
  provider: "openai",
2795
2800
  providerOptions: part.providerOptions,
@@ -3720,6 +3725,7 @@ var OpenAIResponsesLanguageModel = class {
3720
3725
  explicitMessageItemType: this.config.explicitMessageItemType,
3721
3726
  fileIdPrefixes: this.config.fileIdPrefixes,
3722
3727
  store: (_b = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _b : true,
3728
+ isReasoningModel: modelCapabilities.isReasoningModel,
3723
3729
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3724
3730
  webSearchToolName
3725
3731
  });
@@ -5206,7 +5212,7 @@ var OpenAITranscriptionModel = class {
5206
5212
  };
5207
5213
 
5208
5214
  // src/version.ts
5209
- var VERSION = true ? "2.0.134" : "0.0.0-test";
5215
+ var VERSION = true ? "2.0.135" : "0.0.0-test";
5210
5216
 
5211
5217
  // src/openai-provider.ts
5212
5218
  function createOpenAI(options = {}) {