@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.
package/dist/index.mjs CHANGED
@@ -3266,6 +3266,11 @@ var openaiResponsesChunkSchema = lazySchema17(
3266
3266
  action: z19.object({
3267
3267
  commands: z19.array(z19.string())
3268
3268
  })
3269
+ }),
3270
+ z19.object({
3271
+ type: z19.literal("compaction"),
3272
+ id: z19.string(),
3273
+ encrypted_content: z19.string()
3269
3274
  })
3270
3275
  ])
3271
3276
  }),
@@ -3357,6 +3362,13 @@ var openaiResponsesChunkSchema = lazySchema17(
3357
3362
  output_index: z19.number(),
3358
3363
  diff: z19.string()
3359
3364
  }),
3365
+ z19.object({
3366
+ type: z19.literal("response.output_text.done"),
3367
+ item_id: z19.string(),
3368
+ output_index: z19.number(),
3369
+ content_index: z19.number(),
3370
+ text: z19.string()
3371
+ }),
3360
3372
  z19.object({
3361
3373
  type: z19.literal("error"),
3362
3374
  sequence_number: z19.number(),
@@ -4783,6 +4795,8 @@ var OpenAIResponsesLanguageModel = class {
4783
4795
  let hasFunctionCall = false;
4784
4796
  const activeReasoning = {};
4785
4797
  let serviceTier;
4798
+ const textEndEmitted = /* @__PURE__ */ new Set();
4799
+ let finishEmitted = false;
4786
4800
  return {
4787
4801
  stream: response.pipeThrough(
4788
4802
  new TransformStream({
@@ -4955,20 +4969,36 @@ var OpenAIResponsesLanguageModel = class {
4955
4969
  }
4956
4970
  });
4957
4971
  }
4972
+ } else if (isOutputTextDoneChunk(value)) {
4973
+ textEndEmitted.add(value.item_id);
4974
+ controller.enqueue({
4975
+ type: "text-end",
4976
+ id: value.item_id,
4977
+ providerMetadata: {
4978
+ [providerOptionsName]: {
4979
+ itemId: value.item_id,
4980
+ ...ongoingAnnotations.length > 0 && {
4981
+ annotations: ongoingAnnotations
4982
+ }
4983
+ }
4984
+ }
4985
+ });
4958
4986
  } else if (isResponseOutputItemDoneChunk(value)) {
4959
4987
  if (value.item.type === "message") {
4960
- controller.enqueue({
4961
- type: "text-end",
4962
- id: value.item.id,
4963
- providerMetadata: {
4964
- [providerOptionsName]: {
4965
- itemId: value.item.id,
4966
- ...ongoingAnnotations.length > 0 && {
4967
- annotations: ongoingAnnotations
4988
+ if (!textEndEmitted.has(value.item.id)) {
4989
+ controller.enqueue({
4990
+ type: "text-end",
4991
+ id: value.item.id,
4992
+ providerMetadata: {
4993
+ [providerOptionsName]: {
4994
+ itemId: value.item.id,
4995
+ ...ongoingAnnotations.length > 0 && {
4996
+ annotations: ongoingAnnotations
4997
+ }
4968
4998
  }
4969
4999
  }
4970
- }
4971
- });
5000
+ });
5001
+ }
4972
5002
  } else if (value.item.type === "function_call") {
4973
5003
  ongoingToolCalls[value.output_index] = void 0;
4974
5004
  hasFunctionCall = true;
@@ -5205,6 +5235,15 @@ var OpenAIResponsesLanguageModel = class {
5205
5235
  });
5206
5236
  }
5207
5237
  delete activeReasoning[value.item.id];
5238
+ } else if (value.item.type === "compaction") {
5239
+ controller.enqueue({
5240
+ type: "compaction",
5241
+ id: value.item.id,
5242
+ encrypted_content: value.item.encrypted_content,
5243
+ providerMetadata: {
5244
+ [providerOptionsName]: { itemId: value.item.id }
5245
+ }
5246
+ });
5208
5247
  }
5209
5248
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
5210
5249
  const toolCall = ongoingToolCalls[value.output_index];
@@ -5371,6 +5410,24 @@ var OpenAIResponsesLanguageModel = class {
5371
5410
  if (typeof value.response.service_tier === "string") {
5372
5411
  serviceTier = value.response.service_tier;
5373
5412
  }
5413
+ if (!finishEmitted) {
5414
+ finishEmitted = true;
5415
+ const providerMetadata = {
5416
+ [providerOptionsName]: {
5417
+ responseId,
5418
+ ...serviceTier !== void 0 && { serviceTier }
5419
+ }
5420
+ };
5421
+ if (logprobs.length > 0) {
5422
+ providerMetadata[providerOptionsName].logprobs = logprobs;
5423
+ }
5424
+ controller.enqueue({
5425
+ type: "finish",
5426
+ finishReason,
5427
+ usage: convertOpenAIResponsesUsage(usage),
5428
+ providerMetadata
5429
+ });
5430
+ }
5374
5431
  } else if (isResponseAnnotationAddedChunk(value)) {
5375
5432
  ongoingAnnotations.push(value.annotation);
5376
5433
  if (value.annotation.type === "url_citation") {
@@ -5434,6 +5491,9 @@ var OpenAIResponsesLanguageModel = class {
5434
5491
  }
5435
5492
  },
5436
5493
  flush(controller) {
5494
+ if (finishEmitted) {
5495
+ return;
5496
+ }
5437
5497
  const providerMetadata = {
5438
5498
  [providerOptionsName]: {
5439
5499
  responseId
@@ -5462,6 +5522,9 @@ var OpenAIResponsesLanguageModel = class {
5462
5522
  function isTextDeltaChunk(chunk) {
5463
5523
  return chunk.type === "response.output_text.delta";
5464
5524
  }
5525
+ function isOutputTextDoneChunk(chunk) {
5526
+ return chunk.type === "response.output_text.done";
5527
+ }
5465
5528
  function isResponseOutputItemDoneChunk(chunk) {
5466
5529
  return chunk.type === "response.output_item.done";
5467
5530
  }
@@ -5888,7 +5951,7 @@ var OpenAITranscriptionModel = class {
5888
5951
  };
5889
5952
 
5890
5953
  // src/version.ts
5891
- var VERSION = true ? "3.0.27" : "0.0.0-test";
5954
+ var VERSION = true ? "3.0.29" : "0.0.0-test";
5892
5955
 
5893
5956
  // src/openai-provider.ts
5894
5957
  function createOpenAI(options = {}) {