@ai-sdk/openai-compatible 2.0.72 → 2.0.74

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
@@ -574,10 +574,7 @@ var OpenAICompatibleChatLanguageModel = class {
574
574
  });
575
575
  const choice = responseBody.choices[0];
576
576
  const content = [];
577
- const text = choice.message.content;
578
- if (text != null && text.length > 0) {
579
- content.push({ type: "text", text });
580
- }
577
+ content.push(...convertOpenAICompatibleContent(choice.message.content));
581
578
  const reasoning = (_a = choice.message.reasoning_content) != null ? _a : choice.message.reasoning;
582
579
  if (reasoning != null && reasoning.length > 0) {
583
580
  content.push({
@@ -711,8 +708,11 @@ var OpenAICompatibleChatLanguageModel = class {
711
708
  return;
712
709
  }
713
710
  const delta = choice.delta;
714
- const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
715
- if (reasoningContent) {
711
+ const enqueueReasoningDelta = (reasoningDelta) => {
712
+ if (isActiveText) {
713
+ controller.enqueue({ type: "text-end", id: "txt-0" });
714
+ isActiveText = false;
715
+ }
716
716
  if (!isActiveReasoning) {
717
717
  controller.enqueue({
718
718
  type: "reasoning-start",
@@ -723,10 +723,10 @@ var OpenAICompatibleChatLanguageModel = class {
723
723
  controller.enqueue({
724
724
  type: "reasoning-delta",
725
725
  id: "reasoning-0",
726
- delta: reasoningContent
726
+ delta: reasoningDelta
727
727
  });
728
- }
729
- if (delta.content) {
728
+ };
729
+ const enqueueTextDelta = (textDelta) => {
730
730
  if (isActiveReasoning) {
731
731
  controller.enqueue({
732
732
  type: "reasoning-end",
@@ -741,8 +741,21 @@ var OpenAICompatibleChatLanguageModel = class {
741
741
  controller.enqueue({
742
742
  type: "text-delta",
743
743
  id: "txt-0",
744
- delta: delta.content
744
+ delta: textDelta
745
745
  });
746
+ };
747
+ const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
748
+ if (reasoningContent) {
749
+ enqueueReasoningDelta(reasoningContent);
750
+ }
751
+ for (const contentPart of convertOpenAICompatibleContent(
752
+ delta.content
753
+ )) {
754
+ if (contentPart.type === "reasoning") {
755
+ enqueueReasoningDelta(contentPart.text);
756
+ } else {
757
+ enqueueTextDelta(contentPart.text);
758
+ }
746
759
  }
747
760
  if (delta.tool_calls != null) {
748
761
  if (isActiveReasoning) {
@@ -944,6 +957,38 @@ var openaiCompatibleTokenUsageSchema = z3.looseObject({
944
957
  rejected_prediction_tokens: z3.number().nullish()
945
958
  }).nullish()
946
959
  }).nullish();
960
+ var openAICompatibleContentSchema = z3.union([
961
+ z3.string(),
962
+ z3.array(
963
+ z3.looseObject({
964
+ type: z3.string()
965
+ })
966
+ )
967
+ ]).nullish();
968
+ function convertOpenAICompatibleContent(content) {
969
+ if (content == null) {
970
+ return [];
971
+ }
972
+ if (typeof content === "string") {
973
+ return content.length > 0 ? [{ type: "text", text: content }] : [];
974
+ }
975
+ const result = [];
976
+ for (const part of content) {
977
+ if (part.type === "text" && typeof part.text === "string") {
978
+ if (part.text.length > 0) {
979
+ result.push({ type: "text", text: part.text });
980
+ }
981
+ } else if (part.type === "thinking" && Array.isArray(part.thinking)) {
982
+ const reasoningText = part.thinking.filter(
983
+ (chunk) => chunk != null && typeof chunk === "object" && "type" in chunk && chunk.type === "text" && "text" in chunk && typeof chunk.text === "string"
984
+ ).map((chunk) => chunk.text).join("");
985
+ if (reasoningText.length > 0) {
986
+ result.push({ type: "reasoning", text: reasoningText });
987
+ }
988
+ }
989
+ }
990
+ return result;
991
+ }
947
992
  var OpenAICompatibleChatResponseSchema = z3.looseObject({
948
993
  id: z3.string().nullish(),
949
994
  created: z3.number().nullish(),
@@ -952,7 +997,7 @@ var OpenAICompatibleChatResponseSchema = z3.looseObject({
952
997
  z3.object({
953
998
  message: z3.object({
954
999
  role: z3.literal("assistant").nullish(),
955
- content: z3.string().nullish(),
1000
+ content: openAICompatibleContentSchema,
956
1001
  reasoning_content: z3.string().nullish(),
957
1002
  reasoning: z3.string().nullish(),
958
1003
  tool_calls: z3.array(
@@ -984,7 +1029,7 @@ var chunkBaseSchema = z3.looseObject({
984
1029
  z3.object({
985
1030
  delta: z3.object({
986
1031
  role: z3.enum(["assistant", ""]).nullish(),
987
- content: z3.string().nullish(),
1032
+ content: openAICompatibleContentSchema,
988
1033
  // Most openai-compatible models set `reasoning_content`, but some
989
1034
  // providers serving `gpt-oss` set `reasoning`. See #7866
990
1035
  reasoning_content: z3.string().nullish(),
@@ -1741,7 +1786,7 @@ import {
1741
1786
  } from "@ai-sdk/provider-utils";
1742
1787
 
1743
1788
  // src/version.ts
1744
- var VERSION = true ? "2.0.72" : "0.0.0-test";
1789
+ var VERSION = true ? "2.0.74" : "0.0.0-test";
1745
1790
 
1746
1791
  // src/openai-compatible-provider.ts
1747
1792
  function createOpenAICompatible(options) {