@zenning/openai 3.0.27 → 3.0.29

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.
@@ -3189,6 +3189,11 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3189
3189
  action: import_v416.z.object({
3190
3190
  commands: import_v416.z.array(import_v416.z.string())
3191
3191
  })
3192
+ }),
3193
+ import_v416.z.object({
3194
+ type: import_v416.z.literal("compaction"),
3195
+ id: import_v416.z.string(),
3196
+ encrypted_content: import_v416.z.string()
3192
3197
  })
3193
3198
  ])
3194
3199
  }),
@@ -3280,6 +3285,13 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3280
3285
  output_index: import_v416.z.number(),
3281
3286
  diff: import_v416.z.string()
3282
3287
  }),
3288
+ import_v416.z.object({
3289
+ type: import_v416.z.literal("response.output_text.done"),
3290
+ item_id: import_v416.z.string(),
3291
+ output_index: import_v416.z.number(),
3292
+ content_index: import_v416.z.number(),
3293
+ text: import_v416.z.string()
3294
+ }),
3283
3295
  import_v416.z.object({
3284
3296
  type: import_v416.z.literal("error"),
3285
3297
  sequence_number: import_v416.z.number(),
@@ -4996,6 +5008,8 @@ var OpenAIResponsesLanguageModel = class {
4996
5008
  let hasFunctionCall = false;
4997
5009
  const activeReasoning = {};
4998
5010
  let serviceTier;
5011
+ const textEndEmitted = /* @__PURE__ */ new Set();
5012
+ let finishEmitted = false;
4999
5013
  return {
5000
5014
  stream: response.pipeThrough(
5001
5015
  new TransformStream({
@@ -5168,20 +5182,36 @@ var OpenAIResponsesLanguageModel = class {
5168
5182
  }
5169
5183
  });
5170
5184
  }
5185
+ } else if (isOutputTextDoneChunk(value)) {
5186
+ textEndEmitted.add(value.item_id);
5187
+ controller.enqueue({
5188
+ type: "text-end",
5189
+ id: value.item_id,
5190
+ providerMetadata: {
5191
+ [providerOptionsName]: {
5192
+ itemId: value.item_id,
5193
+ ...ongoingAnnotations.length > 0 && {
5194
+ annotations: ongoingAnnotations
5195
+ }
5196
+ }
5197
+ }
5198
+ });
5171
5199
  } else if (isResponseOutputItemDoneChunk(value)) {
5172
5200
  if (value.item.type === "message") {
5173
- controller.enqueue({
5174
- type: "text-end",
5175
- id: value.item.id,
5176
- providerMetadata: {
5177
- [providerOptionsName]: {
5178
- itemId: value.item.id,
5179
- ...ongoingAnnotations.length > 0 && {
5180
- annotations: ongoingAnnotations
5201
+ if (!textEndEmitted.has(value.item.id)) {
5202
+ controller.enqueue({
5203
+ type: "text-end",
5204
+ id: value.item.id,
5205
+ providerMetadata: {
5206
+ [providerOptionsName]: {
5207
+ itemId: value.item.id,
5208
+ ...ongoingAnnotations.length > 0 && {
5209
+ annotations: ongoingAnnotations
5210
+ }
5181
5211
  }
5182
5212
  }
5183
- }
5184
- });
5213
+ });
5214
+ }
5185
5215
  } else if (value.item.type === "function_call") {
5186
5216
  ongoingToolCalls[value.output_index] = void 0;
5187
5217
  hasFunctionCall = true;
@@ -5418,6 +5448,15 @@ var OpenAIResponsesLanguageModel = class {
5418
5448
  });
5419
5449
  }
5420
5450
  delete activeReasoning[value.item.id];
5451
+ } else if (value.item.type === "compaction") {
5452
+ controller.enqueue({
5453
+ type: "compaction",
5454
+ id: value.item.id,
5455
+ encrypted_content: value.item.encrypted_content,
5456
+ providerMetadata: {
5457
+ [providerOptionsName]: { itemId: value.item.id }
5458
+ }
5459
+ });
5421
5460
  }
5422
5461
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
5423
5462
  const toolCall = ongoingToolCalls[value.output_index];
@@ -5584,6 +5623,24 @@ var OpenAIResponsesLanguageModel = class {
5584
5623
  if (typeof value.response.service_tier === "string") {
5585
5624
  serviceTier = value.response.service_tier;
5586
5625
  }
5626
+ if (!finishEmitted) {
5627
+ finishEmitted = true;
5628
+ const providerMetadata = {
5629
+ [providerOptionsName]: {
5630
+ responseId,
5631
+ ...serviceTier !== void 0 && { serviceTier }
5632
+ }
5633
+ };
5634
+ if (logprobs.length > 0) {
5635
+ providerMetadata[providerOptionsName].logprobs = logprobs;
5636
+ }
5637
+ controller.enqueue({
5638
+ type: "finish",
5639
+ finishReason,
5640
+ usage: convertOpenAIResponsesUsage(usage),
5641
+ providerMetadata
5642
+ });
5643
+ }
5587
5644
  } else if (isResponseAnnotationAddedChunk(value)) {
5588
5645
  ongoingAnnotations.push(value.annotation);
5589
5646
  if (value.annotation.type === "url_citation") {
@@ -5647,6 +5704,9 @@ var OpenAIResponsesLanguageModel = class {
5647
5704
  }
5648
5705
  },
5649
5706
  flush(controller) {
5707
+ if (finishEmitted) {
5708
+ return;
5709
+ }
5650
5710
  const providerMetadata = {
5651
5711
  [providerOptionsName]: {
5652
5712
  responseId
@@ -5675,6 +5735,9 @@ var OpenAIResponsesLanguageModel = class {
5675
5735
  function isTextDeltaChunk(chunk) {
5676
5736
  return chunk.type === "response.output_text.delta";
5677
5737
  }
5738
+ function isOutputTextDoneChunk(chunk) {
5739
+ return chunk.type === "response.output_text.done";
5740
+ }
5678
5741
  function isResponseOutputItemDoneChunk(chunk) {
5679
5742
  return chunk.type === "response.output_item.done";
5680
5743
  }