@ai-sdk/openai-compatible 2.0.57 → 2.0.59
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 +21 -0
- package/dist/index.js +91 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -72
- package/dist/index.mjs.map +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/src/chat/convert-to-openai-compatible-chat-messages.ts +1 -1
- package/src/chat/openai-compatible-chat-language-model.ts +118 -84
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
createJsonErrorResponseHandler,
|
|
9
9
|
createJsonResponseHandler,
|
|
10
10
|
generateId,
|
|
11
|
-
isParsableJson,
|
|
12
11
|
parseProviderOptions,
|
|
13
12
|
postJsonToApi
|
|
14
13
|
} from "@ai-sdk/provider-utils";
|
|
@@ -261,7 +260,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
261
260
|
contentValue = output.value;
|
|
262
261
|
break;
|
|
263
262
|
case "execution-denied":
|
|
264
|
-
contentValue = (_c = output.reason) != null ? _c : "Tool execution denied.";
|
|
263
|
+
contentValue = (_c = output.reason) != null ? _c : "Tool call execution denied.";
|
|
265
264
|
break;
|
|
266
265
|
case "content":
|
|
267
266
|
case "json":
|
|
@@ -657,6 +656,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
657
656
|
fetch: this.config.fetch
|
|
658
657
|
});
|
|
659
658
|
const toolCalls = [];
|
|
659
|
+
const pendingToolCalls = /* @__PURE__ */ new Map();
|
|
660
660
|
let finishReason = {
|
|
661
661
|
unified: "other",
|
|
662
662
|
raw: void 0
|
|
@@ -674,7 +674,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
674
674
|
controller.enqueue({ type: "stream-start", warnings });
|
|
675
675
|
},
|
|
676
676
|
transform(chunk, controller) {
|
|
677
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
677
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
678
678
|
if (options.includeRawChunks) {
|
|
679
679
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
680
680
|
}
|
|
@@ -758,35 +758,84 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
758
758
|
for (const toolCallDelta of delta.tool_calls) {
|
|
759
759
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
|
|
760
760
|
if (toolCalls[index] == null) {
|
|
761
|
-
if (toolCallDelta.
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
761
|
+
if (toolCallDelta.index != null) {
|
|
762
|
+
let pending = pendingToolCalls.get(index);
|
|
763
|
+
if (pending == null) {
|
|
764
|
+
pending = {
|
|
765
|
+
id: (_d = toolCallDelta.id) != null ? _d : null,
|
|
766
|
+
bufferedArguments: "",
|
|
767
|
+
thoughtSignature: (_g = (_f = (_e = toolCallDelta.extra_content) == null ? void 0 : _e.google) == null ? void 0 : _f.thought_signature) != null ? _g : void 0
|
|
768
|
+
};
|
|
769
|
+
pendingToolCalls.set(index, pending);
|
|
770
|
+
} else {
|
|
771
|
+
if (pending.id == null && toolCallDelta.id != null) {
|
|
772
|
+
pending.id = toolCallDelta.id;
|
|
773
|
+
}
|
|
774
|
+
if (pending.thoughtSignature == null && ((_i = (_h = toolCallDelta.extra_content) == null ? void 0 : _h.google) == null ? void 0 : _i.thought_signature) != null) {
|
|
775
|
+
pending.thoughtSignature = toolCallDelta.extra_content.google.thought_signature;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
const argumentsDelta = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments;
|
|
779
|
+
if (argumentsDelta != null) {
|
|
780
|
+
pending.bufferedArguments += argumentsDelta;
|
|
781
|
+
}
|
|
782
|
+
const name = (_k = toolCallDelta.function) == null ? void 0 : _k.name;
|
|
783
|
+
if (name == null) {
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
pendingToolCalls.delete(index);
|
|
787
|
+
if (pending.id == null) {
|
|
788
|
+
throw new InvalidResponseDataError({
|
|
789
|
+
data: toolCallDelta,
|
|
790
|
+
message: `Expected 'id' to be a string.`
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
controller.enqueue({
|
|
794
|
+
type: "tool-input-start",
|
|
795
|
+
id: pending.id,
|
|
796
|
+
toolName: name
|
|
765
797
|
});
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
798
|
+
toolCalls[index] = {
|
|
799
|
+
id: pending.id,
|
|
800
|
+
type: "function",
|
|
801
|
+
function: {
|
|
802
|
+
name,
|
|
803
|
+
arguments: pending.bufferedArguments
|
|
804
|
+
},
|
|
805
|
+
hasFinished: false,
|
|
806
|
+
thoughtSignature: pending.thoughtSignature
|
|
807
|
+
};
|
|
808
|
+
} else {
|
|
809
|
+
if (toolCallDelta.id == null) {
|
|
810
|
+
throw new InvalidResponseDataError({
|
|
811
|
+
data: toolCallDelta,
|
|
812
|
+
message: `Expected 'id' to be a string.`
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
if (((_l = toolCallDelta.function) == null ? void 0 : _l.name) == null) {
|
|
816
|
+
throw new InvalidResponseDataError({
|
|
817
|
+
data: toolCallDelta,
|
|
818
|
+
message: `Expected 'function.name' to be a string.`
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
controller.enqueue({
|
|
822
|
+
type: "tool-input-start",
|
|
823
|
+
id: toolCallDelta.id,
|
|
824
|
+
toolName: toolCallDelta.function.name
|
|
771
825
|
});
|
|
826
|
+
toolCalls[index] = {
|
|
827
|
+
id: toolCallDelta.id,
|
|
828
|
+
type: "function",
|
|
829
|
+
function: {
|
|
830
|
+
name: toolCallDelta.function.name,
|
|
831
|
+
arguments: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
832
|
+
},
|
|
833
|
+
hasFinished: false,
|
|
834
|
+
thoughtSignature: (_p = (_o = (_n = toolCallDelta.extra_content) == null ? void 0 : _n.google) == null ? void 0 : _o.thought_signature) != null ? _p : void 0
|
|
835
|
+
};
|
|
772
836
|
}
|
|
773
|
-
controller.enqueue({
|
|
774
|
-
type: "tool-input-start",
|
|
775
|
-
id: toolCallDelta.id,
|
|
776
|
-
toolName: toolCallDelta.function.name
|
|
777
|
-
});
|
|
778
|
-
toolCalls[index] = {
|
|
779
|
-
id: toolCallDelta.id,
|
|
780
|
-
type: "function",
|
|
781
|
-
function: {
|
|
782
|
-
name: toolCallDelta.function.name,
|
|
783
|
-
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
784
|
-
},
|
|
785
|
-
hasFinished: false,
|
|
786
|
-
thoughtSignature: (_h = (_g = (_f = toolCallDelta.extra_content) == null ? void 0 : _f.google) == null ? void 0 : _g.thought_signature) != null ? _h : void 0
|
|
787
|
-
};
|
|
788
837
|
const toolCall2 = toolCalls[index];
|
|
789
|
-
if (((
|
|
838
|
+
if (((_q = toolCall2.function) == null ? void 0 : _q.name) != null && ((_r = toolCall2.function) == null ? void 0 : _r.arguments) != null) {
|
|
790
839
|
if (toolCall2.function.arguments.length > 0) {
|
|
791
840
|
controller.enqueue({
|
|
792
841
|
type: "tool-input-delta",
|
|
@@ -794,26 +843,6 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
794
843
|
delta: toolCall2.function.arguments
|
|
795
844
|
});
|
|
796
845
|
}
|
|
797
|
-
if (isParsableJson(toolCall2.function.arguments)) {
|
|
798
|
-
controller.enqueue({
|
|
799
|
-
type: "tool-input-end",
|
|
800
|
-
id: toolCall2.id
|
|
801
|
-
});
|
|
802
|
-
controller.enqueue({
|
|
803
|
-
type: "tool-call",
|
|
804
|
-
toolCallId: (_k = toolCall2.id) != null ? _k : generateId(),
|
|
805
|
-
toolName: toolCall2.function.name,
|
|
806
|
-
input: toolCall2.function.arguments,
|
|
807
|
-
...toolCall2.thoughtSignature ? {
|
|
808
|
-
providerMetadata: {
|
|
809
|
-
[providerOptionsName]: {
|
|
810
|
-
thoughtSignature: toolCall2.thoughtSignature
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
} : {}
|
|
814
|
-
});
|
|
815
|
-
toolCall2.hasFinished = true;
|
|
816
|
-
}
|
|
817
846
|
}
|
|
818
847
|
continue;
|
|
819
848
|
}
|
|
@@ -821,34 +850,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
821
850
|
if (toolCall.hasFinished) {
|
|
822
851
|
continue;
|
|
823
852
|
}
|
|
824
|
-
if (((
|
|
825
|
-
toolCall.function.arguments += (
|
|
853
|
+
if (((_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null) {
|
|
854
|
+
toolCall.function.arguments += (_u = (_t = toolCallDelta.function) == null ? void 0 : _t.arguments) != null ? _u : "";
|
|
826
855
|
}
|
|
827
856
|
controller.enqueue({
|
|
828
857
|
type: "tool-input-delta",
|
|
829
858
|
id: toolCall.id,
|
|
830
|
-
delta: (
|
|
859
|
+
delta: (_v = toolCallDelta.function.arguments) != null ? _v : ""
|
|
831
860
|
});
|
|
832
|
-
if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
833
|
-
controller.enqueue({
|
|
834
|
-
type: "tool-input-end",
|
|
835
|
-
id: toolCall.id
|
|
836
|
-
});
|
|
837
|
-
controller.enqueue({
|
|
838
|
-
type: "tool-call",
|
|
839
|
-
toolCallId: (_r = toolCall.id) != null ? _r : generateId(),
|
|
840
|
-
toolName: toolCall.function.name,
|
|
841
|
-
input: toolCall.function.arguments,
|
|
842
|
-
...toolCall.thoughtSignature ? {
|
|
843
|
-
providerMetadata: {
|
|
844
|
-
[providerOptionsName]: {
|
|
845
|
-
thoughtSignature: toolCall.thoughtSignature
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
} : {}
|
|
849
|
-
});
|
|
850
|
-
toolCall.hasFinished = true;
|
|
851
|
-
}
|
|
852
861
|
}
|
|
853
862
|
}
|
|
854
863
|
},
|
|
@@ -860,6 +869,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
860
869
|
if (isActiveText) {
|
|
861
870
|
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
862
871
|
}
|
|
872
|
+
for (const [index, pending] of pendingToolCalls) {
|
|
873
|
+
throw new InvalidResponseDataError({
|
|
874
|
+
data: {
|
|
875
|
+
index,
|
|
876
|
+
id: pending.id,
|
|
877
|
+
function: { arguments: pending.bufferedArguments }
|
|
878
|
+
},
|
|
879
|
+
message: `Expected 'function.name' to be a string.`
|
|
880
|
+
});
|
|
881
|
+
}
|
|
863
882
|
for (const toolCall of toolCalls.filter(
|
|
864
883
|
(toolCall2) => !toolCall2.hasFinished
|
|
865
884
|
)) {
|
|
@@ -1715,7 +1734,7 @@ import {
|
|
|
1715
1734
|
} from "@ai-sdk/provider-utils";
|
|
1716
1735
|
|
|
1717
1736
|
// src/version.ts
|
|
1718
|
-
var VERSION = true ? "2.0.
|
|
1737
|
+
var VERSION = true ? "2.0.59" : "0.0.0-test";
|
|
1719
1738
|
|
|
1720
1739
|
// src/openai-compatible-provider.ts
|
|
1721
1740
|
function createOpenAICompatible(options) {
|