@ai-sdk/openai 3.0.126 → 3.0.127

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,16 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.127
4
+
5
+ ### Patch Changes
6
+
7
+ - 347b939: fix(openai): send assistant text with content instead of an item reference when its 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". Assistant text 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
+
11
+ - Updated dependencies [604b4d3]
12
+ - @ai-sdk/provider-utils@4.0.58
13
+
3
14
  ## 3.0.126
4
15
 
5
16
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3703,6 +3703,7 @@ async function convertToOpenAIResponsesInput({
3703
3703
  fileIdPrefixes,
3704
3704
  passThroughUnsupportedFiles = false,
3705
3705
  store,
3706
+ isReasoningModel = false,
3706
3707
  hasConversation = false,
3707
3708
  hasPreviousResponseId = false,
3708
3709
  configurationUpdateUnsupportedReason,
@@ -3875,6 +3876,7 @@ async function convertToOpenAIResponsesInput({
3875
3876
  }
3876
3877
  case "assistant": {
3877
3878
  const reasoningMessages = {};
3879
+ let hasPrecedingReasoning = false;
3878
3880
  for (const part of content) {
3879
3881
  switch (part.type) {
3880
3882
  case "text": {
@@ -3884,7 +3886,8 @@ async function convertToOpenAIResponsesInput({
3884
3886
  if (hasConversation && id != null) {
3885
3887
  break;
3886
3888
  }
3887
- if (store && id != null) {
3889
+ const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
3890
+ if (store && canUseItemId) {
3888
3891
  input.push({ type: "item_reference", id });
3889
3892
  break;
3890
3893
  }
@@ -3892,7 +3895,7 @@ async function convertToOpenAIResponsesInput({
3892
3895
  ...explicitMessageItemType && { type: "message" },
3893
3896
  role: "assistant",
3894
3897
  content: [{ type: "output_text", text: part.text }],
3895
- id,
3898
+ id: canUseItemId ? id : void 0,
3896
3899
  ...phase != null && { phase }
3897
3900
  });
3898
3901
  break;
@@ -4126,6 +4129,7 @@ async function convertToOpenAIResponsesInput({
4126
4129
  break;
4127
4130
  }
4128
4131
  case "reasoning": {
4132
+ hasPrecedingReasoning = true;
4129
4133
  const providerOptions2 = await (0, import_provider_utils28.parseProviderOptions)({
4130
4134
  provider: providerOptionsName,
4131
4135
  providerOptions: part.providerOptions,
@@ -6079,6 +6083,7 @@ var OpenAIResponsesLanguageModel = class {
6079
6083
  fileIdPrefixes: this.config.fileIdPrefixes,
6080
6084
  passThroughUnsupportedFiles: (_d = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _d : false,
6081
6085
  store: (_e = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _e : true,
6086
+ isReasoningModel,
6082
6087
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
6083
6088
  hasPreviousResponseId: (openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null,
6084
6089
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
@@ -8308,7 +8313,7 @@ var OpenAITranscriptionModel = class {
8308
8313
  };
8309
8314
 
8310
8315
  // src/version.ts
8311
- var VERSION = true ? "3.0.126" : "0.0.0-test";
8316
+ var VERSION = true ? "3.0.127" : "0.0.0-test";
8312
8317
 
8313
8318
  // src/openai-provider.ts
8314
8319
  function createOpenAI(options = {}) {