@ai-sdk/openai-compatible 2.0.6 → 2.0.8
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 +12 -0
- package/dist/index.js +92 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -28
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +9 -0
- package/dist/internal/index.d.ts +9 -0
- package/dist/internal/index.js +12 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +12 -3
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 2.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 78fcb18: fix(compat,groq): send reasoning-end before text-start in streaming
|
|
8
|
+
|
|
9
|
+
## 2.0.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cd7bb0e: feat(openai-compat): add thoughtSignature handling for google models
|
|
14
|
+
|
|
3
15
|
## 2.0.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -99,7 +99,7 @@ function getOpenAIMetadata(message) {
|
|
|
99
99
|
return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
|
|
100
100
|
}
|
|
101
101
|
function convertToOpenAICompatibleChatMessages(prompt) {
|
|
102
|
-
var _a;
|
|
102
|
+
var _a, _b, _c;
|
|
103
103
|
const messages = [];
|
|
104
104
|
for (const { role, content, ...message } of prompt) {
|
|
105
105
|
const metadata = getOpenAIMetadata({ ...message });
|
|
@@ -158,6 +158,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
158
158
|
break;
|
|
159
159
|
}
|
|
160
160
|
case "tool-call": {
|
|
161
|
+
const thoughtSignature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.thoughtSignature;
|
|
161
162
|
toolCalls.push({
|
|
162
163
|
id: part.toolCallId,
|
|
163
164
|
type: "function",
|
|
@@ -165,7 +166,15 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
165
166
|
name: part.toolName,
|
|
166
167
|
arguments: JSON.stringify(part.input)
|
|
167
168
|
},
|
|
168
|
-
...partMetadata
|
|
169
|
+
...partMetadata,
|
|
170
|
+
// Include extra_content for Google Gemini thought signatures
|
|
171
|
+
...thoughtSignature ? {
|
|
172
|
+
extra_content: {
|
|
173
|
+
google: {
|
|
174
|
+
thought_signature: String(thoughtSignature)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} : {}
|
|
169
178
|
});
|
|
170
179
|
break;
|
|
171
180
|
}
|
|
@@ -192,7 +201,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
192
201
|
contentValue = output.value;
|
|
193
202
|
break;
|
|
194
203
|
case "execution-denied":
|
|
195
|
-
contentValue = (
|
|
204
|
+
contentValue = (_c = output.reason) != null ? _c : "Tool execution denied.";
|
|
196
205
|
break;
|
|
197
206
|
case "content":
|
|
198
207
|
case "json":
|
|
@@ -437,7 +446,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
437
446
|
};
|
|
438
447
|
}
|
|
439
448
|
async doGenerate(options) {
|
|
440
|
-
var _a, _b, _c, _d, _e, _f;
|
|
449
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
441
450
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
442
451
|
const body = JSON.stringify(args);
|
|
443
452
|
const {
|
|
@@ -473,21 +482,27 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
473
482
|
}
|
|
474
483
|
if (choice.message.tool_calls != null) {
|
|
475
484
|
for (const toolCall of choice.message.tool_calls) {
|
|
485
|
+
const thoughtSignature = (_c = (_b = toolCall.extra_content) == null ? void 0 : _b.google) == null ? void 0 : _c.thought_signature;
|
|
476
486
|
content.push({
|
|
477
487
|
type: "tool-call",
|
|
478
|
-
toolCallId: (
|
|
488
|
+
toolCallId: (_d = toolCall.id) != null ? _d : (0, import_provider_utils2.generateId)(),
|
|
479
489
|
toolName: toolCall.function.name,
|
|
480
|
-
input: toolCall.function.arguments
|
|
490
|
+
input: toolCall.function.arguments,
|
|
491
|
+
...thoughtSignature ? {
|
|
492
|
+
providerMetadata: {
|
|
493
|
+
[this.providerOptionsName]: { thoughtSignature }
|
|
494
|
+
}
|
|
495
|
+
} : {}
|
|
481
496
|
});
|
|
482
497
|
}
|
|
483
498
|
}
|
|
484
499
|
const providerMetadata = {
|
|
485
500
|
[this.providerOptionsName]: {},
|
|
486
|
-
...await ((
|
|
501
|
+
...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
|
|
487
502
|
parsedBody: rawResponse
|
|
488
503
|
}))
|
|
489
504
|
};
|
|
490
|
-
const completionTokenDetails = (
|
|
505
|
+
const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
|
|
491
506
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
492
507
|
providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
493
508
|
}
|
|
@@ -498,7 +513,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
498
513
|
content,
|
|
499
514
|
finishReason: {
|
|
500
515
|
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
501
|
-
raw: (
|
|
516
|
+
raw: (_h = choice.finish_reason) != null ? _h : void 0
|
|
502
517
|
},
|
|
503
518
|
usage: convertOpenAICompatibleChatUsage(responseBody.usage),
|
|
504
519
|
providerMetadata,
|
|
@@ -552,7 +567,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
552
567
|
controller.enqueue({ type: "stream-start", warnings });
|
|
553
568
|
},
|
|
554
569
|
transform(chunk, controller) {
|
|
555
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
570
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
556
571
|
if (options.includeRawChunks) {
|
|
557
572
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
558
573
|
}
|
|
@@ -608,6 +623,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
608
623
|
});
|
|
609
624
|
}
|
|
610
625
|
if (delta.content) {
|
|
626
|
+
if (isActiveReasoning) {
|
|
627
|
+
controller.enqueue({
|
|
628
|
+
type: "reasoning-end",
|
|
629
|
+
id: "reasoning-0"
|
|
630
|
+
});
|
|
631
|
+
isActiveReasoning = false;
|
|
632
|
+
}
|
|
611
633
|
if (!isActiveText) {
|
|
612
634
|
controller.enqueue({ type: "text-start", id: "txt-0" });
|
|
613
635
|
isActiveText = true;
|
|
@@ -619,8 +641,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
619
641
|
});
|
|
620
642
|
}
|
|
621
643
|
if (delta.tool_calls != null) {
|
|
644
|
+
if (isActiveReasoning) {
|
|
645
|
+
controller.enqueue({
|
|
646
|
+
type: "reasoning-end",
|
|
647
|
+
id: "reasoning-0"
|
|
648
|
+
});
|
|
649
|
+
isActiveReasoning = false;
|
|
650
|
+
}
|
|
622
651
|
for (const toolCallDelta of delta.tool_calls) {
|
|
623
|
-
const index = toolCallDelta.index;
|
|
652
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
|
|
624
653
|
if (toolCalls[index] == null) {
|
|
625
654
|
if (toolCallDelta.id == null) {
|
|
626
655
|
throw new import_provider3.InvalidResponseDataError({
|
|
@@ -628,7 +657,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
628
657
|
message: `Expected 'id' to be a string.`
|
|
629
658
|
});
|
|
630
659
|
}
|
|
631
|
-
if (((
|
|
660
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
632
661
|
throw new import_provider3.InvalidResponseDataError({
|
|
633
662
|
data: toolCallDelta,
|
|
634
663
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -644,12 +673,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
644
673
|
type: "function",
|
|
645
674
|
function: {
|
|
646
675
|
name: toolCallDelta.function.name,
|
|
647
|
-
arguments: (
|
|
676
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
648
677
|
},
|
|
649
|
-
hasFinished: false
|
|
678
|
+
hasFinished: false,
|
|
679
|
+
thoughtSignature: (_h = (_g = (_f = toolCallDelta.extra_content) == null ? void 0 : _f.google) == null ? void 0 : _g.thought_signature) != null ? _h : void 0
|
|
650
680
|
};
|
|
651
681
|
const toolCall2 = toolCalls[index];
|
|
652
|
-
if (((
|
|
682
|
+
if (((_i = toolCall2.function) == null ? void 0 : _i.name) != null && ((_j = toolCall2.function) == null ? void 0 : _j.arguments) != null) {
|
|
653
683
|
if (toolCall2.function.arguments.length > 0) {
|
|
654
684
|
controller.enqueue({
|
|
655
685
|
type: "tool-input-delta",
|
|
@@ -664,9 +694,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
664
694
|
});
|
|
665
695
|
controller.enqueue({
|
|
666
696
|
type: "tool-call",
|
|
667
|
-
toolCallId: (
|
|
697
|
+
toolCallId: (_k = toolCall2.id) != null ? _k : (0, import_provider_utils2.generateId)(),
|
|
668
698
|
toolName: toolCall2.function.name,
|
|
669
|
-
input: toolCall2.function.arguments
|
|
699
|
+
input: toolCall2.function.arguments,
|
|
700
|
+
...toolCall2.thoughtSignature ? {
|
|
701
|
+
providerMetadata: {
|
|
702
|
+
[providerOptionsName]: {
|
|
703
|
+
thoughtSignature: toolCall2.thoughtSignature
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
} : {}
|
|
670
707
|
});
|
|
671
708
|
toolCall2.hasFinished = true;
|
|
672
709
|
}
|
|
@@ -677,24 +714,31 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
677
714
|
if (toolCall.hasFinished) {
|
|
678
715
|
continue;
|
|
679
716
|
}
|
|
680
|
-
if (((
|
|
681
|
-
toolCall.function.arguments += (
|
|
717
|
+
if (((_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null) {
|
|
718
|
+
toolCall.function.arguments += (_n = (_m = toolCallDelta.function) == null ? void 0 : _m.arguments) != null ? _n : "";
|
|
682
719
|
}
|
|
683
720
|
controller.enqueue({
|
|
684
721
|
type: "tool-input-delta",
|
|
685
722
|
id: toolCall.id,
|
|
686
|
-
delta: (
|
|
723
|
+
delta: (_o = toolCallDelta.function.arguments) != null ? _o : ""
|
|
687
724
|
});
|
|
688
|
-
if (((
|
|
725
|
+
if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
689
726
|
controller.enqueue({
|
|
690
727
|
type: "tool-input-end",
|
|
691
728
|
id: toolCall.id
|
|
692
729
|
});
|
|
693
730
|
controller.enqueue({
|
|
694
731
|
type: "tool-call",
|
|
695
|
-
toolCallId: (
|
|
732
|
+
toolCallId: (_r = toolCall.id) != null ? _r : (0, import_provider_utils2.generateId)(),
|
|
696
733
|
toolName: toolCall.function.name,
|
|
697
|
-
input: toolCall.function.arguments
|
|
734
|
+
input: toolCall.function.arguments,
|
|
735
|
+
...toolCall.thoughtSignature ? {
|
|
736
|
+
providerMetadata: {
|
|
737
|
+
[providerOptionsName]: {
|
|
738
|
+
thoughtSignature: toolCall.thoughtSignature
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
} : {}
|
|
698
742
|
});
|
|
699
743
|
toolCall.hasFinished = true;
|
|
700
744
|
}
|
|
@@ -720,7 +764,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
720
764
|
type: "tool-call",
|
|
721
765
|
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils2.generateId)(),
|
|
722
766
|
toolName: toolCall.function.name,
|
|
723
|
-
input: toolCall.function.arguments
|
|
767
|
+
input: toolCall.function.arguments,
|
|
768
|
+
...toolCall.thoughtSignature ? {
|
|
769
|
+
providerMetadata: {
|
|
770
|
+
[providerOptionsName]: {
|
|
771
|
+
thoughtSignature: toolCall.thoughtSignature
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
} : {}
|
|
724
775
|
});
|
|
725
776
|
}
|
|
726
777
|
const providerMetadata = {
|
|
@@ -777,7 +828,13 @@ var OpenAICompatibleChatResponseSchema = import_v43.z.looseObject({
|
|
|
777
828
|
function: import_v43.z.object({
|
|
778
829
|
name: import_v43.z.string(),
|
|
779
830
|
arguments: import_v43.z.string()
|
|
780
|
-
})
|
|
831
|
+
}),
|
|
832
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
833
|
+
extra_content: import_v43.z.object({
|
|
834
|
+
google: import_v43.z.object({
|
|
835
|
+
thought_signature: import_v43.z.string().nullish()
|
|
836
|
+
}).nullish()
|
|
837
|
+
}).nullish()
|
|
781
838
|
})
|
|
782
839
|
).nullish()
|
|
783
840
|
}),
|
|
@@ -801,12 +858,19 @@ var chunkBaseSchema = import_v43.z.looseObject({
|
|
|
801
858
|
reasoning: import_v43.z.string().nullish(),
|
|
802
859
|
tool_calls: import_v43.z.array(
|
|
803
860
|
import_v43.z.object({
|
|
804
|
-
index: import_v43.z.number(),
|
|
861
|
+
index: import_v43.z.number().nullish(),
|
|
862
|
+
//google does not send index
|
|
805
863
|
id: import_v43.z.string().nullish(),
|
|
806
864
|
function: import_v43.z.object({
|
|
807
865
|
name: import_v43.z.string().nullish(),
|
|
808
866
|
arguments: import_v43.z.string().nullish()
|
|
809
|
-
})
|
|
867
|
+
}),
|
|
868
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
869
|
+
extra_content: import_v43.z.object({
|
|
870
|
+
google: import_v43.z.object({
|
|
871
|
+
thought_signature: import_v43.z.string().nullish()
|
|
872
|
+
}).nullish()
|
|
873
|
+
}).nullish()
|
|
810
874
|
})
|
|
811
875
|
).nullish()
|
|
812
876
|
}).nullish(),
|
|
@@ -1479,7 +1543,7 @@ async function fileToBlob(file) {
|
|
|
1479
1543
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1480
1544
|
|
|
1481
1545
|
// src/version.ts
|
|
1482
|
-
var VERSION = true ? "2.0.
|
|
1546
|
+
var VERSION = true ? "2.0.8" : "0.0.0-test";
|
|
1483
1547
|
|
|
1484
1548
|
// src/openai-compatible-provider.ts
|
|
1485
1549
|
function createOpenAICompatible(options) {
|