@ai-sdk/openai 3.0.125 → 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,22 @@
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
+
14
+ ## 3.0.126
15
+
16
+ ### Patch Changes
17
+
18
+ - e8ce454: fix(openai): JSON-encode custom tool input deltas for progressive UI updates
19
+
3
20
  ## 3.0.125
4
21
 
5
22
  ### 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"),
@@ -6919,6 +6924,11 @@ var OpenAIResponsesLanguageModel = class {
6919
6924
  id: value.item.call_id,
6920
6925
  toolName
6921
6926
  });
6927
+ controller.enqueue({
6928
+ type: "tool-input-delta",
6929
+ id: value.item.call_id,
6930
+ delta: '"'
6931
+ });
6922
6932
  } else if (value.item.type === "web_search_call") {
6923
6933
  ongoingToolCalls[value.output_index] = {
6924
6934
  toolName: toolNameMapping.toCustomToolName(
@@ -7207,6 +7217,11 @@ var OpenAIResponsesLanguageModel = class {
7207
7217
  const toolName = toolNameMapping.toCustomToolName(
7208
7218
  value.item.name
7209
7219
  );
7220
+ controller.enqueue({
7221
+ type: "tool-input-delta",
7222
+ id: value.item.call_id,
7223
+ delta: '"'
7224
+ });
7210
7225
  controller.enqueue({
7211
7226
  type: "tool-input-end",
7212
7227
  id: value.item.call_id
@@ -7533,7 +7548,7 @@ var OpenAIResponsesLanguageModel = class {
7533
7548
  controller.enqueue({
7534
7549
  type: "tool-input-delta",
7535
7550
  id: toolCall.toolCallId,
7536
- delta: value.delta
7551
+ delta: escapeJSONDelta(value.delta)
7537
7552
  });
7538
7553
  }
7539
7554
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
@@ -8298,7 +8313,7 @@ var OpenAITranscriptionModel = class {
8298
8313
  };
8299
8314
 
8300
8315
  // src/version.ts
8301
- var VERSION = true ? "3.0.125" : "0.0.0-test";
8316
+ var VERSION = true ? "3.0.127" : "0.0.0-test";
8302
8317
 
8303
8318
  // src/openai-provider.ts
8304
8319
  function createOpenAI(options = {}) {