@zenning/openai 3.0.27 → 3.0.28

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.
@@ -3301,6 +3301,13 @@ var openaiResponsesChunkSchema = lazySchema14(
3301
3301
  output_index: z16.number(),
3302
3302
  diff: z16.string()
3303
3303
  }),
3304
+ z16.object({
3305
+ type: z16.literal("response.output_text.done"),
3306
+ item_id: z16.string(),
3307
+ output_index: z16.number(),
3308
+ content_index: z16.number(),
3309
+ text: z16.string()
3310
+ }),
3304
3311
  z16.object({
3305
3312
  type: z16.literal("error"),
3306
3313
  sequence_number: z16.number(),
@@ -5043,6 +5050,8 @@ var OpenAIResponsesLanguageModel = class {
5043
5050
  let hasFunctionCall = false;
5044
5051
  const activeReasoning = {};
5045
5052
  let serviceTier;
5053
+ const textEndEmitted = /* @__PURE__ */ new Set();
5054
+ let finishEmitted = false;
5046
5055
  return {
5047
5056
  stream: response.pipeThrough(
5048
5057
  new TransformStream({
@@ -5215,20 +5224,36 @@ var OpenAIResponsesLanguageModel = class {
5215
5224
  }
5216
5225
  });
5217
5226
  }
5227
+ } else if (isOutputTextDoneChunk(value)) {
5228
+ textEndEmitted.add(value.item_id);
5229
+ controller.enqueue({
5230
+ type: "text-end",
5231
+ id: value.item_id,
5232
+ providerMetadata: {
5233
+ [providerOptionsName]: {
5234
+ itemId: value.item_id,
5235
+ ...ongoingAnnotations.length > 0 && {
5236
+ annotations: ongoingAnnotations
5237
+ }
5238
+ }
5239
+ }
5240
+ });
5218
5241
  } else if (isResponseOutputItemDoneChunk(value)) {
5219
5242
  if (value.item.type === "message") {
5220
- controller.enqueue({
5221
- type: "text-end",
5222
- id: value.item.id,
5223
- providerMetadata: {
5224
- [providerOptionsName]: {
5225
- itemId: value.item.id,
5226
- ...ongoingAnnotations.length > 0 && {
5227
- annotations: ongoingAnnotations
5243
+ if (!textEndEmitted.has(value.item.id)) {
5244
+ controller.enqueue({
5245
+ type: "text-end",
5246
+ id: value.item.id,
5247
+ providerMetadata: {
5248
+ [providerOptionsName]: {
5249
+ itemId: value.item.id,
5250
+ ...ongoingAnnotations.length > 0 && {
5251
+ annotations: ongoingAnnotations
5252
+ }
5228
5253
  }
5229
5254
  }
5230
- }
5231
- });
5255
+ });
5256
+ }
5232
5257
  } else if (value.item.type === "function_call") {
5233
5258
  ongoingToolCalls[value.output_index] = void 0;
5234
5259
  hasFunctionCall = true;
@@ -5631,6 +5656,24 @@ var OpenAIResponsesLanguageModel = class {
5631
5656
  if (typeof value.response.service_tier === "string") {
5632
5657
  serviceTier = value.response.service_tier;
5633
5658
  }
5659
+ if (!finishEmitted) {
5660
+ finishEmitted = true;
5661
+ const providerMetadata = {
5662
+ [providerOptionsName]: {
5663
+ responseId,
5664
+ ...serviceTier !== void 0 && { serviceTier }
5665
+ }
5666
+ };
5667
+ if (logprobs.length > 0) {
5668
+ providerMetadata[providerOptionsName].logprobs = logprobs;
5669
+ }
5670
+ controller.enqueue({
5671
+ type: "finish",
5672
+ finishReason,
5673
+ usage: convertOpenAIResponsesUsage(usage),
5674
+ providerMetadata
5675
+ });
5676
+ }
5634
5677
  } else if (isResponseAnnotationAddedChunk(value)) {
5635
5678
  ongoingAnnotations.push(value.annotation);
5636
5679
  if (value.annotation.type === "url_citation") {
@@ -5694,6 +5737,9 @@ var OpenAIResponsesLanguageModel = class {
5694
5737
  }
5695
5738
  },
5696
5739
  flush(controller) {
5740
+ if (finishEmitted) {
5741
+ return;
5742
+ }
5697
5743
  const providerMetadata = {
5698
5744
  [providerOptionsName]: {
5699
5745
  responseId
@@ -5722,6 +5768,9 @@ var OpenAIResponsesLanguageModel = class {
5722
5768
  function isTextDeltaChunk(chunk) {
5723
5769
  return chunk.type === "response.output_text.delta";
5724
5770
  }
5771
+ function isOutputTextDoneChunk(chunk) {
5772
+ return chunk.type === "response.output_text.done";
5773
+ }
5725
5774
  function isResponseOutputItemDoneChunk(chunk) {
5726
5775
  return chunk.type === "response.output_item.done";
5727
5776
  }