@ai-sdk/openai 4.0.33 → 4.0.35

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.
@@ -864,6 +864,7 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
864
864
  type: "response.output_text.delta";
865
865
  item_id: string;
866
866
  delta: string;
867
+ output_index?: number | null | undefined;
867
868
  logprobs?: {
868
869
  token: string;
869
870
  logprob: number;
@@ -1519,15 +1520,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
1519
1520
  type: "response.reasoning_summary_part.added";
1520
1521
  item_id: string;
1521
1522
  summary_index: number;
1523
+ output_index?: number | null | undefined;
1522
1524
  } | {
1523
1525
  type: "response.reasoning_summary_text.delta";
1524
1526
  item_id: string;
1525
1527
  summary_index: number;
1526
1528
  delta: string;
1529
+ output_index?: number | null | undefined;
1527
1530
  } | {
1528
1531
  type: "response.reasoning_summary_part.done";
1529
1532
  item_id: string;
1530
1533
  summary_index: number;
1534
+ output_index?: number | null | undefined;
1531
1535
  } | {
1532
1536
  type: "response.apply_patch_call_operation_diff.delta";
1533
1537
  item_id: string;
@@ -4497,6 +4497,7 @@ var openaiResponsesChunkSchema = lazySchema18(
4497
4497
  z20.object({
4498
4498
  type: z20.literal("response.output_text.delta"),
4499
4499
  item_id: z20.string(),
4500
+ output_index: z20.number().nullish(),
4500
4501
  delta: z20.string(),
4501
4502
  logprobs: z20.array(
4502
4503
  z20.object({
@@ -5021,17 +5022,20 @@ var openaiResponsesChunkSchema = lazySchema18(
5021
5022
  z20.object({
5022
5023
  type: z20.literal("response.reasoning_summary_part.added"),
5023
5024
  item_id: z20.string(),
5025
+ output_index: z20.number().nullish(),
5024
5026
  summary_index: z20.number()
5025
5027
  }),
5026
5028
  z20.object({
5027
5029
  type: z20.literal("response.reasoning_summary_text.delta"),
5028
5030
  item_id: z20.string(),
5031
+ output_index: z20.number().nullish(),
5029
5032
  summary_index: z20.number(),
5030
5033
  delta: z20.string()
5031
5034
  }),
5032
5035
  z20.object({
5033
5036
  type: z20.literal("response.reasoning_summary_part.done"),
5034
5037
  item_id: z20.string(),
5038
+ output_index: z20.number().nullish(),
5035
5039
  summary_index: z20.number()
5036
5040
  }),
5037
5041
  z20.object({
@@ -7358,6 +7362,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7358
7362
  let activeMessagePhase;
7359
7363
  let hasFunctionCall = false;
7360
7364
  const activeReasoning = {};
7365
+ const activeOutputItemIds = {};
7366
+ const resolveOutputItemId = ({
7367
+ itemId,
7368
+ outputIndex
7369
+ }) => {
7370
+ var _a2;
7371
+ return outputIndex == null ? itemId : (_a2 = activeOutputItemIds[outputIndex]) != null ? _a2 : itemId;
7372
+ };
7361
7373
  let serviceTier;
7362
7374
  let reasoningContext;
7363
7375
  const hostedToolSearchCallIds = [];
@@ -7369,7 +7381,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7369
7381
  controller.enqueue({ type: "stream-start", warnings });
7370
7382
  },
7371
7383
  transform(chunk, controller) {
7372
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O;
7384
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
7373
7385
  if (options.includeRawChunks) {
7374
7386
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
7375
7387
  }
@@ -7547,6 +7559,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7547
7559
  };
7548
7560
  } else if (value.item.type === "shell_call_output") {
7549
7561
  } else if (value.item.type === "message") {
7562
+ activeOutputItemIds[value.output_index] = value.item.id;
7550
7563
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
7551
7564
  activeMessagePhase = (_c = value.item.phase) != null ? _c : void 0;
7552
7565
  controller.enqueue({
@@ -7562,6 +7575,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7562
7575
  }
7563
7576
  });
7564
7577
  } else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
7578
+ activeOutputItemIds[value.output_index] = value.item.id;
7565
7579
  activeReasoning[value.item.id] = {
7566
7580
  encryptedContent: value.item.encrypted_content,
7567
7581
  summaryParts: { 0: "active" }
@@ -7579,14 +7593,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7579
7593
  }
7580
7594
  } else if (isResponseOutputItemDoneChunk(value)) {
7581
7595
  if (value.item.type === "message") {
7596
+ const itemId = resolveOutputItemId({
7597
+ itemId: value.item.id,
7598
+ outputIndex: value.output_index
7599
+ });
7582
7600
  const phase = (_e = value.item.phase) != null ? _e : activeMessagePhase;
7583
7601
  activeMessagePhase = void 0;
7584
7602
  controller.enqueue({
7585
7603
  type: "text-end",
7586
- id: value.item.id,
7604
+ id: itemId,
7587
7605
  providerMetadata: {
7588
7606
  [providerOptionsName]: {
7589
- itemId: value.item.id,
7607
+ itemId,
7590
7608
  ...phase != null && { phase },
7591
7609
  ...ongoingAnnotations.length > 0 && {
7592
7610
  annotations: ongoingAnnotations
@@ -7594,6 +7612,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7594
7612
  }
7595
7613
  }
7596
7614
  });
7615
+ activeOutputItemIds[value.output_index] = void 0;
7597
7616
  } else if (value.item.type === "function_call") {
7598
7617
  ongoingToolCalls[value.output_index] = void 0;
7599
7618
  hasFunctionCall = true;
@@ -7980,25 +7999,32 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7980
7999
  }
7981
8000
  });
7982
8001
  } else if (value.item.type === "reasoning") {
7983
- const activeReasoningPart = activeReasoning[value.item.id];
7984
- const summaryPartIndices = Object.entries(
7985
- activeReasoningPart.summaryParts
7986
- ).filter(
7987
- ([_, status]) => status === "active" || status === "can-conclude"
7988
- ).map(([summaryIndex]) => summaryIndex);
7989
- for (const summaryIndex of summaryPartIndices) {
7990
- controller.enqueue({
7991
- type: "reasoning-end",
7992
- id: `${value.item.id}:${summaryIndex}`,
7993
- providerMetadata: {
7994
- [providerOptionsName]: {
7995
- itemId: value.item.id,
7996
- reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
8002
+ const itemId = resolveOutputItemId({
8003
+ itemId: value.item.id,
8004
+ outputIndex: value.output_index
8005
+ });
8006
+ const activeReasoningPart = activeReasoning[itemId];
8007
+ if (activeReasoningPart != null) {
8008
+ const summaryPartIndices = Object.entries(
8009
+ activeReasoningPart.summaryParts
8010
+ ).filter(
8011
+ ([_, status]) => status === "active" || status === "can-conclude"
8012
+ ).map(([summaryIndex]) => summaryIndex);
8013
+ for (const summaryIndex of summaryPartIndices) {
8014
+ controller.enqueue({
8015
+ type: "reasoning-end",
8016
+ id: `${itemId}:${summaryIndex}`,
8017
+ providerMetadata: {
8018
+ [providerOptionsName]: {
8019
+ itemId,
8020
+ reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
8021
+ }
7997
8022
  }
7998
- }
7999
- });
8023
+ });
8024
+ }
8025
+ delete activeReasoning[itemId];
8000
8026
  }
8001
- delete activeReasoning[value.item.id];
8027
+ activeOutputItemIds[value.output_index] = void 0;
8002
8028
  } else if (value.item.type === "compaction") {
8003
8029
  controller.enqueue({
8004
8030
  type: "custom",
@@ -8113,88 +8139,109 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8113
8139
  modelId: value.response.model
8114
8140
  });
8115
8141
  } else if (isTextDeltaChunk(value)) {
8142
+ const itemId = resolveOutputItemId({
8143
+ itemId: value.item_id,
8144
+ outputIndex: value.output_index
8145
+ });
8116
8146
  controller.enqueue({
8117
8147
  type: "text-delta",
8118
- id: value.item_id,
8148
+ id: itemId,
8119
8149
  delta: value.delta
8120
8150
  });
8121
8151
  if (((_t = (_s = options.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.logprobs) && value.logprobs) {
8122
8152
  logprobs.push(value.logprobs);
8123
8153
  }
8124
8154
  } else if (value.type === "response.reasoning_summary_part.added") {
8155
+ const itemId = resolveOutputItemId({
8156
+ itemId: value.item_id,
8157
+ outputIndex: value.output_index
8158
+ });
8125
8159
  if (value.summary_index > 0) {
8126
- const activeReasoningPart = activeReasoning[value.item_id];
8127
- activeReasoningPart.summaryParts[value.summary_index] = "active";
8128
- for (const summaryIndex of Object.keys(
8129
- activeReasoningPart.summaryParts
8130
- )) {
8131
- if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
8132
- controller.enqueue({
8133
- type: "reasoning-end",
8134
- id: `${value.item_id}:${summaryIndex}`,
8135
- providerMetadata: {
8136
- [providerOptionsName]: {
8137
- itemId: value.item_id
8160
+ const activeReasoningPart = activeReasoning[itemId];
8161
+ if (activeReasoningPart != null) {
8162
+ activeReasoningPart.summaryParts[value.summary_index] = "active";
8163
+ for (const summaryIndex of Object.keys(
8164
+ activeReasoningPart.summaryParts
8165
+ )) {
8166
+ if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
8167
+ controller.enqueue({
8168
+ type: "reasoning-end",
8169
+ id: `${itemId}:${summaryIndex}`,
8170
+ providerMetadata: {
8171
+ [providerOptionsName]: {
8172
+ itemId
8173
+ }
8138
8174
  }
8139
- }
8140
- });
8141
- activeReasoningPart.summaryParts[summaryIndex] = "concluded";
8142
- }
8143
- }
8144
- controller.enqueue({
8145
- type: "reasoning-start",
8146
- id: `${value.item_id}:${value.summary_index}`,
8147
- providerMetadata: {
8148
- [providerOptionsName]: {
8149
- itemId: value.item_id,
8150
- reasoningEncryptedContent: (_v = (_u = activeReasoning[value.item_id]) == null ? void 0 : _u.encryptedContent) != null ? _v : null
8175
+ });
8176
+ activeReasoningPart.summaryParts[summaryIndex] = "concluded";
8151
8177
  }
8152
8178
  }
8153
- });
8179
+ controller.enqueue({
8180
+ type: "reasoning-start",
8181
+ id: `${itemId}:${value.summary_index}`,
8182
+ providerMetadata: {
8183
+ [providerOptionsName]: {
8184
+ itemId,
8185
+ reasoningEncryptedContent: (_u = activeReasoningPart.encryptedContent) != null ? _u : null
8186
+ }
8187
+ }
8188
+ });
8189
+ }
8154
8190
  }
8155
8191
  } else if (value.type === "response.reasoning_summary_text.delta") {
8192
+ const itemId = resolveOutputItemId({
8193
+ itemId: value.item_id,
8194
+ outputIndex: value.output_index
8195
+ });
8156
8196
  controller.enqueue({
8157
8197
  type: "reasoning-delta",
8158
- id: `${value.item_id}:${value.summary_index}`,
8198
+ id: `${itemId}:${value.summary_index}`,
8159
8199
  delta: value.delta,
8160
8200
  providerMetadata: {
8161
8201
  [providerOptionsName]: {
8162
- itemId: value.item_id
8202
+ itemId
8163
8203
  }
8164
8204
  }
8165
8205
  });
8166
8206
  } else if (value.type === "response.reasoning_summary_part.done") {
8167
- if (store) {
8168
- controller.enqueue({
8169
- type: "reasoning-end",
8170
- id: `${value.item_id}:${value.summary_index}`,
8171
- providerMetadata: {
8172
- [providerOptionsName]: {
8173
- itemId: value.item_id
8207
+ const itemId = resolveOutputItemId({
8208
+ itemId: value.item_id,
8209
+ outputIndex: value.output_index
8210
+ });
8211
+ const activeReasoningPart = activeReasoning[itemId];
8212
+ if (activeReasoningPart != null) {
8213
+ if (store) {
8214
+ controller.enqueue({
8215
+ type: "reasoning-end",
8216
+ id: `${itemId}:${value.summary_index}`,
8217
+ providerMetadata: {
8218
+ [providerOptionsName]: {
8219
+ itemId
8220
+ }
8174
8221
  }
8175
- }
8176
- });
8177
- activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
8178
- } else {
8179
- activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
8222
+ });
8223
+ activeReasoningPart.summaryParts[value.summary_index] = "concluded";
8224
+ } else {
8225
+ activeReasoningPart.summaryParts[value.summary_index] = "can-conclude";
8226
+ }
8180
8227
  }
8181
8228
  } else if (isResponseFinishedChunk(value)) {
8182
8229
  finishReason = {
8183
8230
  unified: mapOpenAIResponseFinishReason({
8184
- finishReason: (_w = value.response.incomplete_details) == null ? void 0 : _w.reason,
8231
+ finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
8185
8232
  hasFunctionCall
8186
8233
  }),
8187
- raw: (_y = (_x = value.response.incomplete_details) == null ? void 0 : _x.reason) != null ? _y : void 0
8234
+ raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
8188
8235
  };
8189
8236
  usage = value.response.usage;
8190
8237
  if (typeof value.response.service_tier === "string") {
8191
8238
  serviceTier = value.response.service_tier;
8192
8239
  }
8193
- if (((_z = value.response.reasoning) == null ? void 0 : _z.context) != null) {
8240
+ if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
8194
8241
  reasoningContext = value.response.reasoning.context;
8195
8242
  }
8196
8243
  } else if (isResponseFailedChunk(value)) {
8197
- const incompleteReason = (_A = value.response.incomplete_details) == null ? void 0 : _A.reason;
8244
+ const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
8198
8245
  finishReason = {
8199
8246
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
8200
8247
  finishReason: incompleteReason,
@@ -8202,8 +8249,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8202
8249
  }) : "error",
8203
8250
  raw: incompleteReason != null ? incompleteReason : "error"
8204
8251
  };
8205
- usage = (_B = value.response.usage) != null ? _B : void 0;
8206
- if (((_C = value.response.reasoning) == null ? void 0 : _C.context) != null) {
8252
+ usage = (_A = value.response.usage) != null ? _A : void 0;
8253
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
8207
8254
  reasoningContext = value.response.reasoning.context;
8208
8255
  }
8209
8256
  if (!encounteredStreamError && value.response.error != null) {
@@ -8227,7 +8274,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8227
8274
  controller.enqueue({
8228
8275
  type: "source",
8229
8276
  sourceType: "url",
8230
- id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId2(),
8277
+ id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
8231
8278
  url: value.annotation.url,
8232
8279
  title: value.annotation.title
8233
8280
  });
@@ -8235,7 +8282,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8235
8282
  controller.enqueue({
8236
8283
  type: "source",
8237
8284
  sourceType: "document",
8238
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
8285
+ id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
8239
8286
  mediaType: "text/plain",
8240
8287
  title: value.annotation.filename,
8241
8288
  filename: value.annotation.filename,
@@ -8251,7 +8298,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8251
8298
  controller.enqueue({
8252
8299
  type: "source",
8253
8300
  sourceType: "document",
8254
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
8301
+ id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
8255
8302
  mediaType: "text/plain",
8256
8303
  title: value.annotation.filename,
8257
8304
  filename: value.annotation.filename,
@@ -8267,7 +8314,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8267
8314
  controller.enqueue({
8268
8315
  type: "source",
8269
8316
  sourceType: "document",
8270
- id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
8317
+ id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
8271
8318
  mediaType: "application/octet-stream",
8272
8319
  title: value.annotation.file_id,
8273
8320
  filename: value.annotation.file_id,