@ai-sdk/openai-compatible 2.0.0-beta.56 → 2.0.0-beta.58
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 +17 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -224,7 +224,7 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
|
224
224
|
case "tool_calls":
|
|
225
225
|
return "tool-calls";
|
|
226
226
|
default:
|
|
227
|
-
return "
|
|
227
|
+
return "other";
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -418,7 +418,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
420
|
async doGenerate(options) {
|
|
421
|
-
var _a, _b, _c, _d, _e;
|
|
421
|
+
var _a, _b, _c, _d, _e, _f;
|
|
422
422
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
423
423
|
const body = JSON.stringify(args);
|
|
424
424
|
const {
|
|
@@ -477,7 +477,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
477
477
|
}
|
|
478
478
|
return {
|
|
479
479
|
content,
|
|
480
|
-
finishReason:
|
|
480
|
+
finishReason: {
|
|
481
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
482
|
+
raw: (_f = choice.finish_reason) != null ? _f : void 0
|
|
483
|
+
},
|
|
481
484
|
usage: convertOpenAICompatibleChatUsage(responseBody.usage),
|
|
482
485
|
providerMetadata,
|
|
483
486
|
request: { body },
|
|
@@ -514,7 +517,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
514
517
|
fetch: this.config.fetch
|
|
515
518
|
});
|
|
516
519
|
const toolCalls = [];
|
|
517
|
-
let finishReason =
|
|
520
|
+
let finishReason = {
|
|
521
|
+
unified: "other",
|
|
522
|
+
raw: void 0
|
|
523
|
+
};
|
|
518
524
|
let usage = void 0;
|
|
519
525
|
let isFirstChunk = true;
|
|
520
526
|
const providerOptionsName = this.providerOptionsName;
|
|
@@ -527,18 +533,18 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
527
533
|
controller.enqueue({ type: "stream-start", warnings });
|
|
528
534
|
},
|
|
529
535
|
transform(chunk, controller) {
|
|
530
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
536
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
531
537
|
if (options.includeRawChunks) {
|
|
532
538
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
533
539
|
}
|
|
534
540
|
if (!chunk.success) {
|
|
535
|
-
finishReason = "error";
|
|
541
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
536
542
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
537
543
|
return;
|
|
538
544
|
}
|
|
539
545
|
metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
|
|
540
546
|
if ("error" in chunk.value) {
|
|
541
|
-
finishReason = "error";
|
|
547
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
542
548
|
controller.enqueue({
|
|
543
549
|
type: "error",
|
|
544
550
|
error: chunk.value.error.message
|
|
@@ -558,15 +564,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
558
564
|
}
|
|
559
565
|
const choice = value.choices[0];
|
|
560
566
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
561
|
-
finishReason =
|
|
562
|
-
choice.finish_reason
|
|
563
|
-
|
|
567
|
+
finishReason = {
|
|
568
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
569
|
+
raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
|
|
570
|
+
};
|
|
564
571
|
}
|
|
565
572
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
566
573
|
return;
|
|
567
574
|
}
|
|
568
575
|
const delta = choice.delta;
|
|
569
|
-
const reasoningContent = (
|
|
576
|
+
const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
|
|
570
577
|
if (reasoningContent) {
|
|
571
578
|
if (!isActiveReasoning) {
|
|
572
579
|
controller.enqueue({
|
|
@@ -602,7 +609,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
602
609
|
message: `Expected 'id' to be a string.`
|
|
603
610
|
});
|
|
604
611
|
}
|
|
605
|
-
if (((
|
|
612
|
+
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
|
|
606
613
|
throw new InvalidResponseDataError({
|
|
607
614
|
data: toolCallDelta,
|
|
608
615
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -618,12 +625,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
618
625
|
type: "function",
|
|
619
626
|
function: {
|
|
620
627
|
name: toolCallDelta.function.name,
|
|
621
|
-
arguments: (
|
|
628
|
+
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
|
|
622
629
|
},
|
|
623
630
|
hasFinished: false
|
|
624
631
|
};
|
|
625
632
|
const toolCall2 = toolCalls[index];
|
|
626
|
-
if (((
|
|
633
|
+
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
|
|
627
634
|
if (toolCall2.function.arguments.length > 0) {
|
|
628
635
|
controller.enqueue({
|
|
629
636
|
type: "tool-input-delta",
|
|
@@ -638,7 +645,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
638
645
|
});
|
|
639
646
|
controller.enqueue({
|
|
640
647
|
type: "tool-call",
|
|
641
|
-
toolCallId: (
|
|
648
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
|
|
642
649
|
toolName: toolCall2.function.name,
|
|
643
650
|
input: toolCall2.function.arguments
|
|
644
651
|
});
|
|
@@ -651,22 +658,22 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
651
658
|
if (toolCall.hasFinished) {
|
|
652
659
|
continue;
|
|
653
660
|
}
|
|
654
|
-
if (((
|
|
655
|
-
toolCall.function.arguments += (
|
|
661
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
662
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
656
663
|
}
|
|
657
664
|
controller.enqueue({
|
|
658
665
|
type: "tool-input-delta",
|
|
659
666
|
id: toolCall.id,
|
|
660
|
-
delta: (
|
|
667
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
661
668
|
});
|
|
662
|
-
if (((
|
|
669
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
663
670
|
controller.enqueue({
|
|
664
671
|
type: "tool-input-end",
|
|
665
672
|
id: toolCall.id
|
|
666
673
|
});
|
|
667
674
|
controller.enqueue({
|
|
668
675
|
type: "tool-call",
|
|
669
|
-
toolCallId: (
|
|
676
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
670
677
|
toolName: toolCall.function.name,
|
|
671
678
|
input: toolCall.function.arguments
|
|
672
679
|
});
|
|
@@ -943,7 +950,7 @@ function mapOpenAICompatibleFinishReason2(finishReason) {
|
|
|
943
950
|
case "tool_calls":
|
|
944
951
|
return "tool-calls";
|
|
945
952
|
default:
|
|
946
|
-
return "
|
|
953
|
+
return "other";
|
|
947
954
|
}
|
|
948
955
|
}
|
|
949
956
|
|
|
@@ -1089,7 +1096,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1089
1096
|
return {
|
|
1090
1097
|
content,
|
|
1091
1098
|
usage: convertOpenAICompatibleCompletionUsage(response.usage),
|
|
1092
|
-
finishReason:
|
|
1099
|
+
finishReason: {
|
|
1100
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
1101
|
+
raw: choice.finish_reason
|
|
1102
|
+
},
|
|
1093
1103
|
request: { body: args },
|
|
1094
1104
|
response: {
|
|
1095
1105
|
...getResponseMetadata2(response),
|
|
@@ -1121,7 +1131,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1121
1131
|
abortSignal: options.abortSignal,
|
|
1122
1132
|
fetch: this.config.fetch
|
|
1123
1133
|
});
|
|
1124
|
-
let finishReason =
|
|
1134
|
+
let finishReason = {
|
|
1135
|
+
unified: "other",
|
|
1136
|
+
raw: void 0
|
|
1137
|
+
};
|
|
1125
1138
|
let usage = void 0;
|
|
1126
1139
|
let isFirstChunk = true;
|
|
1127
1140
|
return {
|
|
@@ -1131,17 +1144,18 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1131
1144
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1132
1145
|
},
|
|
1133
1146
|
transform(chunk, controller) {
|
|
1147
|
+
var _a;
|
|
1134
1148
|
if (options.includeRawChunks) {
|
|
1135
1149
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1136
1150
|
}
|
|
1137
1151
|
if (!chunk.success) {
|
|
1138
|
-
finishReason = "error";
|
|
1152
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1139
1153
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1140
1154
|
return;
|
|
1141
1155
|
}
|
|
1142
1156
|
const value = chunk.value;
|
|
1143
1157
|
if ("error" in value) {
|
|
1144
|
-
finishReason = "error";
|
|
1158
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1145
1159
|
controller.enqueue({ type: "error", error: value.error });
|
|
1146
1160
|
return;
|
|
1147
1161
|
}
|
|
@@ -1161,9 +1175,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1161
1175
|
}
|
|
1162
1176
|
const choice = value.choices[0];
|
|
1163
1177
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1164
|
-
finishReason =
|
|
1165
|
-
choice.finish_reason
|
|
1166
|
-
|
|
1178
|
+
finishReason = {
|
|
1179
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
1180
|
+
raw: (_a = choice.finish_reason) != null ? _a : void 0
|
|
1181
|
+
};
|
|
1167
1182
|
}
|
|
1168
1183
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1169
1184
|
controller.enqueue({
|
|
@@ -1475,7 +1490,7 @@ import {
|
|
|
1475
1490
|
} from "@ai-sdk/provider-utils";
|
|
1476
1491
|
|
|
1477
1492
|
// src/version.ts
|
|
1478
|
-
var VERSION = true ? "2.0.0-beta.
|
|
1493
|
+
var VERSION = true ? "2.0.0-beta.58" : "0.0.0-test";
|
|
1479
1494
|
|
|
1480
1495
|
// src/openai-compatible-provider.ts
|
|
1481
1496
|
function createOpenAICompatible(options) {
|