@zenning/openai 3.0.26 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.28
4
+
5
+ ### Patch Changes
6
+
7
+ - text end
8
+
3
9
  ## 3.0.26
4
10
 
5
11
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/dist/index.js CHANGED
@@ -3289,6 +3289,13 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3289
3289
  output_index: import_v419.z.number(),
3290
3290
  diff: import_v419.z.string()
3291
3291
  }),
3292
+ import_v419.z.object({
3293
+ type: import_v419.z.literal("response.output_text.done"),
3294
+ item_id: import_v419.z.string(),
3295
+ output_index: import_v419.z.number(),
3296
+ content_index: import_v419.z.number(),
3297
+ text: import_v419.z.string()
3298
+ }),
3292
3299
  import_v419.z.object({
3293
3300
  type: import_v419.z.literal("error"),
3294
3301
  sequence_number: import_v419.z.number(),
@@ -4713,6 +4720,8 @@ var OpenAIResponsesLanguageModel = class {
4713
4720
  let hasFunctionCall = false;
4714
4721
  const activeReasoning = {};
4715
4722
  let serviceTier;
4723
+ const textEndEmitted = /* @__PURE__ */ new Set();
4724
+ let finishEmitted = false;
4716
4725
  return {
4717
4726
  stream: response.pipeThrough(
4718
4727
  new TransformStream({
@@ -4885,20 +4894,36 @@ var OpenAIResponsesLanguageModel = class {
4885
4894
  }
4886
4895
  });
4887
4896
  }
4897
+ } else if (isOutputTextDoneChunk(value)) {
4898
+ textEndEmitted.add(value.item_id);
4899
+ controller.enqueue({
4900
+ type: "text-end",
4901
+ id: value.item_id,
4902
+ providerMetadata: {
4903
+ [providerOptionsName]: {
4904
+ itemId: value.item_id,
4905
+ ...ongoingAnnotations.length > 0 && {
4906
+ annotations: ongoingAnnotations
4907
+ }
4908
+ }
4909
+ }
4910
+ });
4888
4911
  } else if (isResponseOutputItemDoneChunk(value)) {
4889
4912
  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
4913
+ if (!textEndEmitted.has(value.item.id)) {
4914
+ controller.enqueue({
4915
+ type: "text-end",
4916
+ id: value.item.id,
4917
+ providerMetadata: {
4918
+ [providerOptionsName]: {
4919
+ itemId: value.item.id,
4920
+ ...ongoingAnnotations.length > 0 && {
4921
+ annotations: ongoingAnnotations
4922
+ }
4898
4923
  }
4899
4924
  }
4900
- }
4901
- });
4925
+ });
4926
+ }
4902
4927
  } else if (value.item.type === "function_call") {
4903
4928
  ongoingToolCalls[value.output_index] = void 0;
4904
4929
  hasFunctionCall = true;
@@ -5301,6 +5326,24 @@ var OpenAIResponsesLanguageModel = class {
5301
5326
  if (typeof value.response.service_tier === "string") {
5302
5327
  serviceTier = value.response.service_tier;
5303
5328
  }
5329
+ if (!finishEmitted) {
5330
+ finishEmitted = true;
5331
+ const providerMetadata = {
5332
+ [providerOptionsName]: {
5333
+ responseId,
5334
+ ...serviceTier !== void 0 && { serviceTier }
5335
+ }
5336
+ };
5337
+ if (logprobs.length > 0) {
5338
+ providerMetadata[providerOptionsName].logprobs = logprobs;
5339
+ }
5340
+ controller.enqueue({
5341
+ type: "finish",
5342
+ finishReason,
5343
+ usage: convertOpenAIResponsesUsage(usage),
5344
+ providerMetadata
5345
+ });
5346
+ }
5304
5347
  } else if (isResponseAnnotationAddedChunk(value)) {
5305
5348
  ongoingAnnotations.push(value.annotation);
5306
5349
  if (value.annotation.type === "url_citation") {
@@ -5364,6 +5407,9 @@ var OpenAIResponsesLanguageModel = class {
5364
5407
  }
5365
5408
  },
5366
5409
  flush(controller) {
5410
+ if (finishEmitted) {
5411
+ return;
5412
+ }
5367
5413
  const providerMetadata = {
5368
5414
  [providerOptionsName]: {
5369
5415
  responseId
@@ -5392,6 +5438,9 @@ var OpenAIResponsesLanguageModel = class {
5392
5438
  function isTextDeltaChunk(chunk) {
5393
5439
  return chunk.type === "response.output_text.delta";
5394
5440
  }
5441
+ function isOutputTextDoneChunk(chunk) {
5442
+ return chunk.type === "response.output_text.done";
5443
+ }
5395
5444
  function isResponseOutputItemDoneChunk(chunk) {
5396
5445
  return chunk.type === "response.output_item.done";
5397
5446
  }
@@ -5806,7 +5855,7 @@ var OpenAITranscriptionModel = class {
5806
5855
  };
5807
5856
 
5808
5857
  // src/version.ts
5809
- var VERSION = true ? "3.0.26" : "0.0.0-test";
5858
+ var VERSION = true ? "3.0.28" : "0.0.0-test";
5810
5859
 
5811
5860
  // src/openai-provider.ts
5812
5861
  function createOpenAI(options = {}) {