@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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.29
4
+
5
+ ### Patch Changes
6
+
7
+ - compaction chunks
8
+ - Updated dependencies
9
+ - @zenning/provider@3.0.6
10
+ - @zenning/provider-utils@4.0.8
11
+
12
+ ## 3.0.28
13
+
14
+ ### Patch Changes
15
+
16
+ - text end
17
+
3
18
  ## 3.0.26
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3198,6 +3198,11 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3198
3198
  action: import_v419.z.object({
3199
3199
  commands: import_v419.z.array(import_v419.z.string())
3200
3200
  })
3201
+ }),
3202
+ import_v419.z.object({
3203
+ type: import_v419.z.literal("compaction"),
3204
+ id: import_v419.z.string(),
3205
+ encrypted_content: import_v419.z.string()
3201
3206
  })
3202
3207
  ])
3203
3208
  }),
@@ -3289,6 +3294,13 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3289
3294
  output_index: import_v419.z.number(),
3290
3295
  diff: import_v419.z.string()
3291
3296
  }),
3297
+ import_v419.z.object({
3298
+ type: import_v419.z.literal("response.output_text.done"),
3299
+ item_id: import_v419.z.string(),
3300
+ output_index: import_v419.z.number(),
3301
+ content_index: import_v419.z.number(),
3302
+ text: import_v419.z.string()
3303
+ }),
3292
3304
  import_v419.z.object({
3293
3305
  type: import_v419.z.literal("error"),
3294
3306
  sequence_number: import_v419.z.number(),
@@ -4713,6 +4725,8 @@ var OpenAIResponsesLanguageModel = class {
4713
4725
  let hasFunctionCall = false;
4714
4726
  const activeReasoning = {};
4715
4727
  let serviceTier;
4728
+ const textEndEmitted = /* @__PURE__ */ new Set();
4729
+ let finishEmitted = false;
4716
4730
  return {
4717
4731
  stream: response.pipeThrough(
4718
4732
  new TransformStream({
@@ -4885,20 +4899,36 @@ var OpenAIResponsesLanguageModel = class {
4885
4899
  }
4886
4900
  });
4887
4901
  }
4902
+ } else if (isOutputTextDoneChunk(value)) {
4903
+ textEndEmitted.add(value.item_id);
4904
+ controller.enqueue({
4905
+ type: "text-end",
4906
+ id: value.item_id,
4907
+ providerMetadata: {
4908
+ [providerOptionsName]: {
4909
+ itemId: value.item_id,
4910
+ ...ongoingAnnotations.length > 0 && {
4911
+ annotations: ongoingAnnotations
4912
+ }
4913
+ }
4914
+ }
4915
+ });
4888
4916
  } else if (isResponseOutputItemDoneChunk(value)) {
4889
4917
  if (value.item.type === "message") {
4890
- controller.enqueue({
4891
- type: "text-end",
4892
- id: value.item.id,
4893
- providerMetadata: {
4894
- [providerOptionsName]: {
4895
- itemId: value.item.id,
4896
- ...ongoingAnnotations.length > 0 && {
4897
- annotations: ongoingAnnotations
4918
+ if (!textEndEmitted.has(value.item.id)) {
4919
+ controller.enqueue({
4920
+ type: "text-end",
4921
+ id: value.item.id,
4922
+ providerMetadata: {
4923
+ [providerOptionsName]: {
4924
+ itemId: value.item.id,
4925
+ ...ongoingAnnotations.length > 0 && {
4926
+ annotations: ongoingAnnotations
4927
+ }
4898
4928
  }
4899
4929
  }
4900
- }
4901
- });
4930
+ });
4931
+ }
4902
4932
  } else if (value.item.type === "function_call") {
4903
4933
  ongoingToolCalls[value.output_index] = void 0;
4904
4934
  hasFunctionCall = true;
@@ -5135,6 +5165,15 @@ var OpenAIResponsesLanguageModel = class {
5135
5165
  });
5136
5166
  }
5137
5167
  delete activeReasoning[value.item.id];
5168
+ } else if (value.item.type === "compaction") {
5169
+ controller.enqueue({
5170
+ type: "compaction",
5171
+ id: value.item.id,
5172
+ encrypted_content: value.item.encrypted_content,
5173
+ providerMetadata: {
5174
+ [providerOptionsName]: { itemId: value.item.id }
5175
+ }
5176
+ });
5138
5177
  }
5139
5178
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
5140
5179
  const toolCall = ongoingToolCalls[value.output_index];
@@ -5301,6 +5340,24 @@ var OpenAIResponsesLanguageModel = class {
5301
5340
  if (typeof value.response.service_tier === "string") {
5302
5341
  serviceTier = value.response.service_tier;
5303
5342
  }
5343
+ if (!finishEmitted) {
5344
+ finishEmitted = true;
5345
+ const providerMetadata = {
5346
+ [providerOptionsName]: {
5347
+ responseId,
5348
+ ...serviceTier !== void 0 && { serviceTier }
5349
+ }
5350
+ };
5351
+ if (logprobs.length > 0) {
5352
+ providerMetadata[providerOptionsName].logprobs = logprobs;
5353
+ }
5354
+ controller.enqueue({
5355
+ type: "finish",
5356
+ finishReason,
5357
+ usage: convertOpenAIResponsesUsage(usage),
5358
+ providerMetadata
5359
+ });
5360
+ }
5304
5361
  } else if (isResponseAnnotationAddedChunk(value)) {
5305
5362
  ongoingAnnotations.push(value.annotation);
5306
5363
  if (value.annotation.type === "url_citation") {
@@ -5364,6 +5421,9 @@ var OpenAIResponsesLanguageModel = class {
5364
5421
  }
5365
5422
  },
5366
5423
  flush(controller) {
5424
+ if (finishEmitted) {
5425
+ return;
5426
+ }
5367
5427
  const providerMetadata = {
5368
5428
  [providerOptionsName]: {
5369
5429
  responseId
@@ -5392,6 +5452,9 @@ var OpenAIResponsesLanguageModel = class {
5392
5452
  function isTextDeltaChunk(chunk) {
5393
5453
  return chunk.type === "response.output_text.delta";
5394
5454
  }
5455
+ function isOutputTextDoneChunk(chunk) {
5456
+ return chunk.type === "response.output_text.done";
5457
+ }
5395
5458
  function isResponseOutputItemDoneChunk(chunk) {
5396
5459
  return chunk.type === "response.output_item.done";
5397
5460
  }
@@ -5806,7 +5869,7 @@ var OpenAITranscriptionModel = class {
5806
5869
  };
5807
5870
 
5808
5871
  // src/version.ts
5809
- var VERSION = true ? "3.0.27" : "0.0.0-test";
5872
+ var VERSION = true ? "3.0.29" : "0.0.0-test";
5810
5873
 
5811
5874
  // src/openai-provider.ts
5812
5875
  function createOpenAI(options = {}) {