@ai-sdk/openai 2.0.51 → 2.0.52

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.
@@ -2392,6 +2392,9 @@ async function convertToOpenAIResponsesInput({
2392
2392
  input.push(reasoningMessages[reasoningId]);
2393
2393
  } else {
2394
2394
  reasoningMessage.summary.push(...summaryParts);
2395
+ if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
2396
+ reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
2397
+ }
2395
2398
  }
2396
2399
  }
2397
2400
  } else {
@@ -2737,6 +2740,11 @@ var openaiResponsesChunkSchema = lazyValidator11(
2737
2740
  summary_index: z14.number(),
2738
2741
  delta: z14.string()
2739
2742
  }),
2743
+ z14.object({
2744
+ type: z14.literal("response.reasoning_summary_part.done"),
2745
+ item_id: z14.string(),
2746
+ summary_index: z14.number()
2747
+ }),
2740
2748
  z14.object({
2741
2749
  type: z14.literal("error"),
2742
2750
  code: z14.string(),
@@ -3624,7 +3632,8 @@ var OpenAIResponsesLanguageModel = class {
3624
3632
  tools: openaiTools,
3625
3633
  tool_choice: openaiToolChoice
3626
3634
  },
3627
- warnings: [...warnings, ...toolWarnings]
3635
+ warnings: [...warnings, ...toolWarnings],
3636
+ store
3628
3637
  };
3629
3638
  }
3630
3639
  async doGenerate(options) {
@@ -3899,7 +3908,8 @@ var OpenAIResponsesLanguageModel = class {
3899
3908
  const {
3900
3909
  args: body,
3901
3910
  warnings,
3902
- webSearchToolName
3911
+ webSearchToolName,
3912
+ store
3903
3913
  } = await this.getArgs(options);
3904
3914
  const { responseHeaders, value: response } = await postJsonToApi6({
3905
3915
  url: this.config.url({
@@ -3938,7 +3948,7 @@ var OpenAIResponsesLanguageModel = class {
3938
3948
  controller.enqueue({ type: "stream-start", warnings });
3939
3949
  },
3940
3950
  transform(chunk, controller) {
3941
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3951
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3942
3952
  if (options.includeRawChunks) {
3943
3953
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3944
3954
  }
@@ -4037,10 +4047,10 @@ var OpenAIResponsesLanguageModel = class {
4037
4047
  }
4038
4048
  }
4039
4049
  });
4040
- } else if (isResponseOutputItemAddedReasoningChunk(value)) {
4050
+ } else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
4041
4051
  activeReasoning[value.item.id] = {
4042
4052
  encryptedContent: value.item.encrypted_content,
4043
- summaryParts: [0]
4053
+ summaryParts: { 0: "active" }
4044
4054
  };
4045
4055
  controller.enqueue({
4046
4056
  type: "reasoning-start",
@@ -4168,9 +4178,14 @@ var OpenAIResponsesLanguageModel = class {
4168
4178
  type: "text-end",
4169
4179
  id: value.item.id
4170
4180
  });
4171
- } else if (isResponseOutputItemDoneReasoningChunk(value)) {
4181
+ } else if (value.item.type === "reasoning") {
4172
4182
  const activeReasoningPart = activeReasoning[value.item.id];
4173
- for (const summaryIndex of activeReasoningPart.summaryParts) {
4183
+ const summaryPartIndices = Object.entries(
4184
+ activeReasoningPart.summaryParts
4185
+ ).filter(
4186
+ ([_, status]) => status === "active" || status === "can-conclude"
4187
+ ).map(([summaryIndex]) => summaryIndex);
4188
+ for (const summaryIndex of summaryPartIndices) {
4174
4189
  controller.enqueue({
4175
4190
  type: "reasoning-end",
4176
4191
  id: `${value.item.id}:${summaryIndex}`,
@@ -4244,23 +4259,34 @@ var OpenAIResponsesLanguageModel = class {
4244
4259
  if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
4245
4260
  logprobs.push(value.logprobs);
4246
4261
  }
4247
- } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
4262
+ } else if (value.type === "response.reasoning_summary_part.added") {
4248
4263
  if (value.summary_index > 0) {
4249
- (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.summaryParts.push(
4250
- value.summary_index
4251
- );
4264
+ const activeReasoningPart = activeReasoning[value.item_id];
4265
+ activeReasoningPart.summaryParts[value.summary_index] = "active";
4266
+ for (const summaryIndex of Object.keys(
4267
+ activeReasoningPart.summaryParts
4268
+ )) {
4269
+ if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
4270
+ controller.enqueue({
4271
+ type: "reasoning-end",
4272
+ id: `${value.item_id}:${summaryIndex}`,
4273
+ providerMetadata: { openai: { itemId: value.item_id } }
4274
+ });
4275
+ activeReasoningPart.summaryParts[summaryIndex] = "concluded";
4276
+ }
4277
+ }
4252
4278
  controller.enqueue({
4253
4279
  type: "reasoning-start",
4254
4280
  id: `${value.item_id}:${value.summary_index}`,
4255
4281
  providerMetadata: {
4256
4282
  openai: {
4257
4283
  itemId: value.item_id,
4258
- reasoningEncryptedContent: (_i = (_h = activeReasoning[value.item_id]) == null ? void 0 : _h.encryptedContent) != null ? _i : null
4284
+ reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
4259
4285
  }
4260
4286
  }
4261
4287
  });
4262
4288
  }
4263
- } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
4289
+ } else if (value.type === "response.reasoning_summary_text.delta") {
4264
4290
  controller.enqueue({
4265
4291
  type: "reasoning-delta",
4266
4292
  id: `${value.item_id}:${value.summary_index}`,
@@ -4271,16 +4297,29 @@ var OpenAIResponsesLanguageModel = class {
4271
4297
  }
4272
4298
  }
4273
4299
  });
4300
+ } else if (value.type === "response.reasoning_summary_part.done") {
4301
+ if (store) {
4302
+ controller.enqueue({
4303
+ type: "reasoning-end",
4304
+ id: `${value.item_id}:${value.summary_index}`,
4305
+ providerMetadata: {
4306
+ openai: { itemId: value.item_id }
4307
+ }
4308
+ });
4309
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
4310
+ } else {
4311
+ activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
4312
+ }
4274
4313
  } else if (isResponseFinishedChunk(value)) {
4275
4314
  finishReason = mapOpenAIResponseFinishReason({
4276
- finishReason: (_j = value.response.incomplete_details) == null ? void 0 : _j.reason,
4315
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4277
4316
  hasFunctionCall
4278
4317
  });
4279
4318
  usage.inputTokens = value.response.usage.input_tokens;
4280
4319
  usage.outputTokens = value.response.usage.output_tokens;
4281
4320
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
4282
- usage.reasoningTokens = (_l = (_k = value.response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0;
4283
- usage.cachedInputTokens = (_n = (_m = value.response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0;
4321
+ usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
4322
+ usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
4284
4323
  if (typeof value.response.service_tier === "string") {
4285
4324
  serviceTier = value.response.service_tier;
4286
4325
  }
@@ -4289,7 +4328,7 @@ var OpenAIResponsesLanguageModel = class {
4289
4328
  controller.enqueue({
4290
4329
  type: "source",
4291
4330
  sourceType: "url",
4292
- id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
4331
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
4293
4332
  url: value.annotation.url,
4294
4333
  title: value.annotation.title
4295
4334
  });
@@ -4297,10 +4336,10 @@ var OpenAIResponsesLanguageModel = class {
4297
4336
  controller.enqueue({
4298
4337
  type: "source",
4299
4338
  sourceType: "document",
4300
- id: (_t = (_s = (_r = self.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
4339
+ id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
4301
4340
  mediaType: "text/plain",
4302
- title: (_v = (_u = value.annotation.quote) != null ? _u : value.annotation.filename) != null ? _v : "Document",
4303
- filename: (_w = value.annotation.filename) != null ? _w : value.annotation.file_id
4341
+ title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
4342
+ filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id
4304
4343
  });
4305
4344
  }
4306
4345
  } else if (isErrorChunk(value)) {
@@ -4339,9 +4378,6 @@ function isTextDeltaChunk(chunk) {
4339
4378
  function isResponseOutputItemDoneChunk(chunk) {
4340
4379
  return chunk.type === "response.output_item.done";
4341
4380
  }
4342
- function isResponseOutputItemDoneReasoningChunk(chunk) {
4343
- return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
4344
- }
4345
4381
  function isResponseFinishedChunk(chunk) {
4346
4382
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
4347
4383
  }
@@ -4360,18 +4396,9 @@ function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
4360
4396
  function isResponseOutputItemAddedChunk(chunk) {
4361
4397
  return chunk.type === "response.output_item.added";
4362
4398
  }
4363
- function isResponseOutputItemAddedReasoningChunk(chunk) {
4364
- return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
4365
- }
4366
4399
  function isResponseAnnotationAddedChunk(chunk) {
4367
4400
  return chunk.type === "response.output_text.annotation.added";
4368
4401
  }
4369
- function isResponseReasoningSummaryPartAddedChunk(chunk) {
4370
- return chunk.type === "response.reasoning_summary_part.added";
4371
- }
4372
- function isResponseReasoningSummaryTextDeltaChunk(chunk) {
4373
- return chunk.type === "response.reasoning_summary_text.delta";
4374
- }
4375
4402
  function isErrorChunk(chunk) {
4376
4403
  return chunk.type === "error";
4377
4404
  }