@ai-sdk/openai 2.0.95 → 2.0.97

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,19 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.97
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6a2f01b]
8
+ - Updated dependencies [17d64e3]
9
+ - @ai-sdk/provider-utils@3.0.22
10
+
11
+ ## 2.0.96
12
+
13
+ ### Patch Changes
14
+
15
+ - e867b5c: Support `phase` parameter on Responses API message items. The `phase` field (`'commentary'` or `'final_answer'`) is returned by models like `gpt-5.3-codex` on assistant message output items and must be preserved when sending follow-up requests. The phase value is available in `providerMetadata.openai.phase` on text parts and is automatically included on assistant messages sent back to the API.
16
+
3
17
  ## 2.0.95
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2145,7 +2145,7 @@ async function convertToOpenAIResponsesInput({
2145
2145
  store,
2146
2146
  hasLocalShellTool = false
2147
2147
  }) {
2148
- var _a, _b, _c, _d;
2148
+ var _a, _b, _c, _d, _e, _f;
2149
2149
  const input = [];
2150
2150
  const warnings = [];
2151
2151
  for (const { role, content } of prompt) {
@@ -2227,6 +2227,7 @@ async function convertToOpenAIResponsesInput({
2227
2227
  switch (part.type) {
2228
2228
  case "text": {
2229
2229
  const id = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId;
2230
+ const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
2230
2231
  if (store && id != null) {
2231
2232
  input.push({ type: "item_reference", id });
2232
2233
  break;
@@ -2234,7 +2235,8 @@ async function convertToOpenAIResponsesInput({
2234
2235
  input.push({
2235
2236
  role: "assistant",
2236
2237
  content: [{ type: "output_text", text: part.text }],
2237
- id
2238
+ id,
2239
+ ...phase != null && { phase }
2238
2240
  });
2239
2241
  break;
2240
2242
  }
@@ -2243,7 +2245,7 @@ async function convertToOpenAIResponsesInput({
2243
2245
  if (part.providerExecuted) {
2244
2246
  break;
2245
2247
  }
2246
- const id = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.itemId;
2248
+ const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2247
2249
  if (store && id != null) {
2248
2250
  input.push({ type: "item_reference", id });
2249
2251
  break;
@@ -2482,7 +2484,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2482
2484
  item: import_v416.z.discriminatedUnion("type", [
2483
2485
  import_v416.z.object({
2484
2486
  type: import_v416.z.literal("message"),
2485
- id: import_v416.z.string()
2487
+ id: import_v416.z.string(),
2488
+ phase: import_v416.z.enum(["commentary", "final_answer"]).nullish()
2486
2489
  }),
2487
2490
  import_v416.z.object({
2488
2491
  type: import_v416.z.literal("reasoning"),
@@ -2535,7 +2538,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazyValidator)(
2535
2538
  item: import_v416.z.discriminatedUnion("type", [
2536
2539
  import_v416.z.object({
2537
2540
  type: import_v416.z.literal("message"),
2538
- id: import_v416.z.string()
2541
+ id: import_v416.z.string(),
2542
+ phase: import_v416.z.enum(["commentary", "final_answer"]).nullish()
2539
2543
  }),
2540
2544
  import_v416.z.object({
2541
2545
  type: import_v416.z.literal("reasoning"),
@@ -2724,6 +2728,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazyValidator)(
2724
2728
  type: import_v416.z.literal("message"),
2725
2729
  role: import_v416.z.literal("assistant"),
2726
2730
  id: import_v416.z.string(),
2731
+ phase: import_v416.z.enum(["commentary", "final_answer"]).nullish(),
2727
2732
  content: import_v416.z.array(
2728
2733
  import_v416.z.object({
2729
2734
  type: import_v416.z.literal("output_text"),
@@ -3505,7 +3510,8 @@ var OpenAIResponsesLanguageModel = class {
3505
3510
  text: contentPart.text,
3506
3511
  providerMetadata: {
3507
3512
  [providerKey]: {
3508
- itemId: part.id
3513
+ itemId: part.id,
3514
+ ...part.phase != null && { phase: part.phase }
3509
3515
  }
3510
3516
  }
3511
3517
  });
@@ -3745,6 +3751,7 @@ var OpenAIResponsesLanguageModel = class {
3745
3751
  let responseId = null;
3746
3752
  const ongoingToolCalls = {};
3747
3753
  const ongoingAnnotations = [];
3754
+ let activeMessagePhase;
3748
3755
  let hasFunctionCall = false;
3749
3756
  const activeReasoning = {};
3750
3757
  let serviceTier;
@@ -3755,7 +3762,7 @@ var OpenAIResponsesLanguageModel = class {
3755
3762
  controller.enqueue({ type: "stream-start", warnings });
3756
3763
  },
3757
3764
  transform(chunk, controller) {
3758
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3765
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
3759
3766
  if (options.includeRawChunks) {
3760
3767
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3761
3768
  }
@@ -3846,12 +3853,16 @@ var OpenAIResponsesLanguageModel = class {
3846
3853
  });
3847
3854
  } else if (value.item.type === "message") {
3848
3855
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
3856
+ activeMessagePhase = (_a = value.item.phase) != null ? _a : void 0;
3849
3857
  controller.enqueue({
3850
3858
  type: "text-start",
3851
3859
  id: value.item.id,
3852
3860
  providerMetadata: {
3853
3861
  [providerKey]: {
3854
- itemId: value.item.id
3862
+ itemId: value.item.id,
3863
+ ...value.item.phase != null && {
3864
+ phase: value.item.phase
3865
+ }
3855
3866
  }
3856
3867
  }
3857
3868
  });
@@ -3866,19 +3877,22 @@ var OpenAIResponsesLanguageModel = class {
3866
3877
  providerMetadata: {
3867
3878
  [providerKey]: {
3868
3879
  itemId: value.item.id,
3869
- reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
3880
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
3870
3881
  }
3871
3882
  }
3872
3883
  });
3873
3884
  }
3874
3885
  } else if (isResponseOutputItemDoneChunk(value)) {
3875
3886
  if (value.item.type === "message") {
3887
+ const phase = (_c = value.item.phase) != null ? _c : activeMessagePhase;
3888
+ activeMessagePhase = void 0;
3876
3889
  controller.enqueue({
3877
3890
  type: "text-end",
3878
3891
  id: value.item.id,
3879
3892
  providerMetadata: {
3880
3893
  [providerKey]: {
3881
3894
  itemId: value.item.id,
3895
+ ...phase != null && { phase },
3882
3896
  ...ongoingAnnotations.length > 0 && {
3883
3897
  annotations: ongoingAnnotations
3884
3898
  }
@@ -3943,13 +3957,13 @@ var OpenAIResponsesLanguageModel = class {
3943
3957
  toolName: "file_search",
3944
3958
  result: {
3945
3959
  queries: value.item.queries,
3946
- results: (_c = (_b = value.item.results) == null ? void 0 : _b.map((result) => ({
3960
+ results: (_e = (_d = value.item.results) == null ? void 0 : _d.map((result) => ({
3947
3961
  attributes: result.attributes,
3948
3962
  fileId: result.file_id,
3949
3963
  filename: result.filename,
3950
3964
  score: result.score,
3951
3965
  text: result.text
3952
- }))) != null ? _c : null
3966
+ }))) != null ? _e : null
3953
3967
  },
3954
3968
  providerExecuted: true
3955
3969
  });
@@ -4008,7 +4022,7 @@ var OpenAIResponsesLanguageModel = class {
4008
4022
  providerMetadata: {
4009
4023
  [providerKey]: {
4010
4024
  itemId: value.item.id,
4011
- reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
4025
+ reasoningEncryptedContent: (_f = value.item.encrypted_content) != null ? _f : null
4012
4026
  }
4013
4027
  }
4014
4028
  });
@@ -4072,7 +4086,7 @@ var OpenAIResponsesLanguageModel = class {
4072
4086
  id: value.item_id,
4073
4087
  delta: value.delta
4074
4088
  });
4075
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
4089
+ if (((_h = (_g = options.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.logprobs) && value.logprobs) {
4076
4090
  logprobs.push(value.logprobs);
4077
4091
  }
4078
4092
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -4099,7 +4113,7 @@ var OpenAIResponsesLanguageModel = class {
4099
4113
  providerMetadata: {
4100
4114
  [providerKey]: {
4101
4115
  itemId: value.item_id,
4102
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
4116
+ reasoningEncryptedContent: (_j = (_i = activeReasoning[value.item_id]) == null ? void 0 : _i.encryptedContent) != null ? _j : null
4103
4117
  }
4104
4118
  }
4105
4119
  });
@@ -4130,14 +4144,14 @@ var OpenAIResponsesLanguageModel = class {
4130
4144
  }
4131
4145
  } else if (isResponseFinishedChunk(value)) {
4132
4146
  finishReason = mapOpenAIResponseFinishReason({
4133
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4147
+ finishReason: (_k = value.response.incomplete_details) == null ? void 0 : _k.reason,
4134
4148
  hasFunctionCall
4135
4149
  });
4136
4150
  usage.inputTokens = value.response.usage.input_tokens;
4137
4151
  usage.outputTokens = value.response.usage.output_tokens;
4138
4152
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
4139
- usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
4140
- usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
4153
+ usage.reasoningTokens = (_m = (_l = value.response.usage.output_tokens_details) == null ? void 0 : _l.reasoning_tokens) != null ? _m : void 0;
4154
+ usage.cachedInputTokens = (_o = (_n = value.response.usage.input_tokens_details) == null ? void 0 : _n.cached_tokens) != null ? _o : void 0;
4141
4155
  if (typeof value.response.service_tier === "string") {
4142
4156
  serviceTier = value.response.service_tier;
4143
4157
  }
@@ -4147,7 +4161,7 @@ var OpenAIResponsesLanguageModel = class {
4147
4161
  controller.enqueue({
4148
4162
  type: "source",
4149
4163
  sourceType: "url",
4150
- id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils24.generateId)(),
4164
+ id: (_r = (_q = (_p = self.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : (0, import_provider_utils24.generateId)(),
4151
4165
  url: value.annotation.url,
4152
4166
  title: value.annotation.title
4153
4167
  });
@@ -4155,10 +4169,10 @@ var OpenAIResponsesLanguageModel = class {
4155
4169
  controller.enqueue({
4156
4170
  type: "source",
4157
4171
  sourceType: "document",
4158
- id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : (0, import_provider_utils24.generateId)(),
4172
+ id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils24.generateId)(),
4159
4173
  mediaType: "text/plain",
4160
- title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
4161
- filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id,
4174
+ title: (_w = (_v = value.annotation.quote) != null ? _v : value.annotation.filename) != null ? _w : "Document",
4175
+ filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
4162
4176
  ...value.annotation.file_id ? {
4163
4177
  providerMetadata: {
4164
4178
  [providerKey]: {
@@ -4606,7 +4620,7 @@ var OpenAITranscriptionModel = class {
4606
4620
  };
4607
4621
 
4608
4622
  // src/version.ts
4609
- var VERSION = true ? "2.0.95" : "0.0.0-test";
4623
+ var VERSION = true ? "2.0.97" : "0.0.0-test";
4610
4624
 
4611
4625
  // src/openai-provider.ts
4612
4626
  function createOpenAI(options = {}) {