@ai-sdk/openai-compatible 2.0.73 → 2.0.75
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 +18 -0
- package/dist/index.js +65 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/chat/openai-compatible-chat-language-model.ts +91 -16
package/dist/index.mjs
CHANGED
|
@@ -573,11 +573,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
573
573
|
fetch: this.config.fetch
|
|
574
574
|
});
|
|
575
575
|
const choice = responseBody.choices[0];
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
576
|
+
if (choice == null) {
|
|
577
|
+
throw new InvalidResponseDataError({
|
|
578
|
+
data: rawResponse,
|
|
579
|
+
message: "Response did not contain any choices."
|
|
580
|
+
});
|
|
580
581
|
}
|
|
582
|
+
const content = [];
|
|
583
|
+
content.push(...convertOpenAICompatibleContent(choice.message.content));
|
|
581
584
|
const reasoning = (_a = choice.message.reasoning_content) != null ? _a : choice.message.reasoning;
|
|
582
585
|
if (reasoning != null && reasoning.length > 0) {
|
|
583
586
|
content.push({
|
|
@@ -711,8 +714,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
711
714
|
return;
|
|
712
715
|
}
|
|
713
716
|
const delta = choice.delta;
|
|
714
|
-
const
|
|
715
|
-
|
|
717
|
+
const enqueueReasoningDelta = (reasoningDelta) => {
|
|
718
|
+
if (isActiveText) {
|
|
719
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
720
|
+
isActiveText = false;
|
|
721
|
+
}
|
|
716
722
|
if (!isActiveReasoning) {
|
|
717
723
|
controller.enqueue({
|
|
718
724
|
type: "reasoning-start",
|
|
@@ -723,10 +729,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
723
729
|
controller.enqueue({
|
|
724
730
|
type: "reasoning-delta",
|
|
725
731
|
id: "reasoning-0",
|
|
726
|
-
delta:
|
|
732
|
+
delta: reasoningDelta
|
|
727
733
|
});
|
|
728
|
-
}
|
|
729
|
-
|
|
734
|
+
};
|
|
735
|
+
const enqueueTextDelta = (textDelta) => {
|
|
730
736
|
if (isActiveReasoning) {
|
|
731
737
|
controller.enqueue({
|
|
732
738
|
type: "reasoning-end",
|
|
@@ -741,10 +747,23 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
741
747
|
controller.enqueue({
|
|
742
748
|
type: "text-delta",
|
|
743
749
|
id: "txt-0",
|
|
744
|
-
delta:
|
|
750
|
+
delta: textDelta
|
|
745
751
|
});
|
|
752
|
+
};
|
|
753
|
+
const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
|
|
754
|
+
if (reasoningContent) {
|
|
755
|
+
enqueueReasoningDelta(reasoningContent);
|
|
746
756
|
}
|
|
747
|
-
|
|
757
|
+
for (const contentPart of convertOpenAICompatibleContent(
|
|
758
|
+
delta.content
|
|
759
|
+
)) {
|
|
760
|
+
if (contentPart.type === "reasoning") {
|
|
761
|
+
enqueueReasoningDelta(contentPart.text);
|
|
762
|
+
} else {
|
|
763
|
+
enqueueTextDelta(contentPart.text);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
if (delta.tool_calls != null && delta.tool_calls.length > 0) {
|
|
748
767
|
if (isActiveReasoning) {
|
|
749
768
|
controller.enqueue({
|
|
750
769
|
type: "reasoning-end",
|
|
@@ -944,6 +963,38 @@ var openaiCompatibleTokenUsageSchema = z3.looseObject({
|
|
|
944
963
|
rejected_prediction_tokens: z3.number().nullish()
|
|
945
964
|
}).nullish()
|
|
946
965
|
}).nullish();
|
|
966
|
+
var openAICompatibleContentSchema = z3.union([
|
|
967
|
+
z3.string(),
|
|
968
|
+
z3.array(
|
|
969
|
+
z3.looseObject({
|
|
970
|
+
type: z3.string()
|
|
971
|
+
})
|
|
972
|
+
)
|
|
973
|
+
]).nullish();
|
|
974
|
+
function convertOpenAICompatibleContent(content) {
|
|
975
|
+
if (content == null) {
|
|
976
|
+
return [];
|
|
977
|
+
}
|
|
978
|
+
if (typeof content === "string") {
|
|
979
|
+
return content.length > 0 ? [{ type: "text", text: content }] : [];
|
|
980
|
+
}
|
|
981
|
+
const result = [];
|
|
982
|
+
for (const part of content) {
|
|
983
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
984
|
+
if (part.text.length > 0) {
|
|
985
|
+
result.push({ type: "text", text: part.text });
|
|
986
|
+
}
|
|
987
|
+
} else if (part.type === "thinking" && Array.isArray(part.thinking)) {
|
|
988
|
+
const reasoningText = part.thinking.filter(
|
|
989
|
+
(chunk) => chunk != null && typeof chunk === "object" && "type" in chunk && chunk.type === "text" && "text" in chunk && typeof chunk.text === "string"
|
|
990
|
+
).map((chunk) => chunk.text).join("");
|
|
991
|
+
if (reasoningText.length > 0) {
|
|
992
|
+
result.push({ type: "reasoning", text: reasoningText });
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return result;
|
|
997
|
+
}
|
|
947
998
|
var OpenAICompatibleChatResponseSchema = z3.looseObject({
|
|
948
999
|
id: z3.string().nullish(),
|
|
949
1000
|
created: z3.number().nullish(),
|
|
@@ -952,7 +1003,7 @@ var OpenAICompatibleChatResponseSchema = z3.looseObject({
|
|
|
952
1003
|
z3.object({
|
|
953
1004
|
message: z3.object({
|
|
954
1005
|
role: z3.literal("assistant").nullish(),
|
|
955
|
-
content:
|
|
1006
|
+
content: openAICompatibleContentSchema,
|
|
956
1007
|
reasoning_content: z3.string().nullish(),
|
|
957
1008
|
reasoning: z3.string().nullish(),
|
|
958
1009
|
tool_calls: z3.array(
|
|
@@ -984,7 +1035,7 @@ var chunkBaseSchema = z3.looseObject({
|
|
|
984
1035
|
z3.object({
|
|
985
1036
|
delta: z3.object({
|
|
986
1037
|
role: z3.enum(["assistant", ""]).nullish(),
|
|
987
|
-
content:
|
|
1038
|
+
content: openAICompatibleContentSchema,
|
|
988
1039
|
// Most openai-compatible models set `reasoning_content`, but some
|
|
989
1040
|
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
990
1041
|
reasoning_content: z3.string().nullish(),
|
|
@@ -1741,7 +1792,7 @@ import {
|
|
|
1741
1792
|
} from "@ai-sdk/provider-utils";
|
|
1742
1793
|
|
|
1743
1794
|
// src/version.ts
|
|
1744
|
-
var VERSION = true ? "2.0.
|
|
1795
|
+
var VERSION = true ? "2.0.75" : "0.0.0-test";
|
|
1745
1796
|
|
|
1746
1797
|
// src/openai-compatible-provider.ts
|
|
1747
1798
|
function createOpenAICompatible(options) {
|