@ai-sdk/openai-compatible 1.0.0-alpha.9 → 1.0.0-beta.2
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 +86 -0
- package/dist/index.d.mts +13 -86
- package/dist/index.d.ts +13 -86
- package/dist/index.js +179 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -33
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +15 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +15 -2
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
parseProviderOptions,
|
13
13
|
postJsonToApi
|
14
14
|
} from "@ai-sdk/provider-utils";
|
15
|
-
import { z as z3 } from "zod";
|
15
|
+
import { z as z3 } from "zod/v4";
|
16
16
|
|
17
17
|
// src/convert-to-openai-compatible-chat-messages.ts
|
18
18
|
import {
|
@@ -86,7 +86,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
86
86
|
type: "function",
|
87
87
|
function: {
|
88
88
|
name: part.toolName,
|
89
|
-
arguments: JSON.stringify(part.
|
89
|
+
arguments: JSON.stringify(part.input)
|
90
90
|
},
|
91
91
|
...partMetadata
|
92
92
|
});
|
@@ -104,11 +104,24 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
104
104
|
}
|
105
105
|
case "tool": {
|
106
106
|
for (const toolResponse of content) {
|
107
|
+
const output = toolResponse.output;
|
108
|
+
let contentValue;
|
109
|
+
switch (output.type) {
|
110
|
+
case "text":
|
111
|
+
case "error-text":
|
112
|
+
contentValue = output.value;
|
113
|
+
break;
|
114
|
+
case "content":
|
115
|
+
case "json":
|
116
|
+
case "error-json":
|
117
|
+
contentValue = JSON.stringify(output.value);
|
118
|
+
break;
|
119
|
+
}
|
107
120
|
const toolResponseMetadata = getOpenAIMetadata(toolResponse);
|
108
121
|
messages.push({
|
109
122
|
role: "tool",
|
110
123
|
tool_call_id: toolResponse.toolCallId,
|
111
|
-
content:
|
124
|
+
content: contentValue,
|
112
125
|
...toolResponseMetadata
|
113
126
|
});
|
114
127
|
}
|
@@ -154,7 +167,7 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
154
167
|
}
|
155
168
|
|
156
169
|
// src/openai-compatible-chat-options.ts
|
157
|
-
import { z } from "zod";
|
170
|
+
import { z } from "zod/v4";
|
158
171
|
var openaiCompatibleProviderOptions = z.object({
|
159
172
|
/**
|
160
173
|
* A unique identifier representing your end-user, which can help the provider to
|
@@ -168,7 +181,7 @@ var openaiCompatibleProviderOptions = z.object({
|
|
168
181
|
});
|
169
182
|
|
170
183
|
// src/openai-compatible-error.ts
|
171
|
-
import { z as z2 } from "zod";
|
184
|
+
import { z as z2 } from "zod/v4";
|
172
185
|
var openaiCompatibleErrorDataSchema = z2.object({
|
173
186
|
error: z2.object({
|
174
187
|
message: z2.string(),
|
@@ -208,7 +221,7 @@ function prepareTools({
|
|
208
221
|
function: {
|
209
222
|
name: tool.name,
|
210
223
|
description: tool.description,
|
211
|
-
parameters: tool.
|
224
|
+
parameters: tool.inputSchema
|
212
225
|
}
|
213
226
|
});
|
214
227
|
}
|
@@ -384,10 +397,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
384
397
|
for (const toolCall of choice.message.tool_calls) {
|
385
398
|
content.push({
|
386
399
|
type: "tool-call",
|
387
|
-
toolCallType: "function",
|
388
400
|
toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
|
389
401
|
toolName: toolCall.function.name,
|
390
|
-
|
402
|
+
input: toolCall.function.arguments
|
391
403
|
});
|
392
404
|
}
|
393
405
|
}
|
@@ -465,6 +477,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
465
477
|
};
|
466
478
|
let isFirstChunk = true;
|
467
479
|
const providerOptionsName = this.providerOptionsName;
|
480
|
+
let isActiveReasoning = false;
|
481
|
+
let isActiveText = false;
|
468
482
|
return {
|
469
483
|
stream: response.pipeThrough(
|
470
484
|
new TransformStream({
|
@@ -474,6 +488,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
474
488
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
475
489
|
transform(chunk, controller) {
|
476
490
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
491
|
+
if (options.includeRawChunks) {
|
492
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
493
|
+
}
|
477
494
|
if (!chunk.success) {
|
478
495
|
finishReason = "error";
|
479
496
|
controller.enqueue({ type: "error", error: chunk.error });
|
@@ -528,15 +545,28 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
528
545
|
}
|
529
546
|
const delta = choice.delta;
|
530
547
|
if (delta.reasoning_content != null) {
|
548
|
+
if (!isActiveReasoning) {
|
549
|
+
controller.enqueue({
|
550
|
+
type: "reasoning-start",
|
551
|
+
id: "reasoning-0"
|
552
|
+
});
|
553
|
+
isActiveReasoning = true;
|
554
|
+
}
|
531
555
|
controller.enqueue({
|
532
|
-
type: "reasoning",
|
533
|
-
|
556
|
+
type: "reasoning-delta",
|
557
|
+
id: "reasoning-0",
|
558
|
+
delta: delta.reasoning_content
|
534
559
|
});
|
535
560
|
}
|
536
561
|
if (delta.content != null) {
|
562
|
+
if (!isActiveText) {
|
563
|
+
controller.enqueue({ type: "text-start", id: "txt-0" });
|
564
|
+
isActiveText = true;
|
565
|
+
}
|
537
566
|
controller.enqueue({
|
538
|
-
type: "text",
|
539
|
-
|
567
|
+
type: "text-delta",
|
568
|
+
id: "txt-0",
|
569
|
+
delta: delta.content
|
540
570
|
});
|
541
571
|
}
|
542
572
|
if (delta.tool_calls != null) {
|
@@ -561,6 +591,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
561
591
|
message: `Expected 'function.name' to be a string.`
|
562
592
|
});
|
563
593
|
}
|
594
|
+
controller.enqueue({
|
595
|
+
type: "tool-input-start",
|
596
|
+
id: toolCallDelta.id,
|
597
|
+
toolName: toolCallDelta.function.name
|
598
|
+
});
|
564
599
|
toolCalls[index] = {
|
565
600
|
id: toolCallDelta.id,
|
566
601
|
type: "function",
|
@@ -574,20 +609,21 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
574
609
|
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
|
575
610
|
if (toolCall2.function.arguments.length > 0) {
|
576
611
|
controller.enqueue({
|
577
|
-
type: "tool-
|
578
|
-
|
579
|
-
|
580
|
-
toolName: toolCall2.function.name,
|
581
|
-
argsTextDelta: toolCall2.function.arguments
|
612
|
+
type: "tool-input-start",
|
613
|
+
id: toolCall2.id,
|
614
|
+
toolName: toolCall2.function.name
|
582
615
|
});
|
583
616
|
}
|
584
617
|
if (isParsableJson(toolCall2.function.arguments)) {
|
618
|
+
controller.enqueue({
|
619
|
+
type: "tool-input-end",
|
620
|
+
id: toolCall2.id
|
621
|
+
});
|
585
622
|
controller.enqueue({
|
586
623
|
type: "tool-call",
|
587
|
-
toolCallType: "function",
|
588
624
|
toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
|
589
625
|
toolName: toolCall2.function.name,
|
590
|
-
|
626
|
+
input: toolCall2.function.arguments
|
591
627
|
});
|
592
628
|
toolCall2.hasFinished = true;
|
593
629
|
}
|
@@ -602,19 +638,20 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
602
638
|
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
|
603
639
|
}
|
604
640
|
controller.enqueue({
|
605
|
-
type: "tool-
|
606
|
-
|
607
|
-
|
608
|
-
toolName: toolCall.function.name,
|
609
|
-
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
641
|
+
type: "tool-input-delta",
|
642
|
+
id: toolCall.id,
|
643
|
+
delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
610
644
|
});
|
611
645
|
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
646
|
+
controller.enqueue({
|
647
|
+
type: "tool-input-end",
|
648
|
+
id: toolCall.id
|
649
|
+
});
|
612
650
|
controller.enqueue({
|
613
651
|
type: "tool-call",
|
614
|
-
toolCallType: "function",
|
615
652
|
toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
|
616
653
|
toolName: toolCall.function.name,
|
617
|
-
|
654
|
+
input: toolCall.function.arguments
|
618
655
|
});
|
619
656
|
toolCall.hasFinished = true;
|
620
657
|
}
|
@@ -623,6 +660,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
623
660
|
},
|
624
661
|
flush(controller) {
|
625
662
|
var _a2, _b, _c, _d, _e;
|
663
|
+
if (isActiveReasoning) {
|
664
|
+
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
665
|
+
}
|
666
|
+
if (isActiveText) {
|
667
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
668
|
+
}
|
626
669
|
const providerMetadata = {
|
627
670
|
[providerOptionsName]: {},
|
628
671
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
@@ -732,7 +775,7 @@ import {
|
|
732
775
|
parseProviderOptions as parseProviderOptions2,
|
733
776
|
postJsonToApi as postJsonToApi2
|
734
777
|
} from "@ai-sdk/provider-utils";
|
735
|
-
import { z as z5 } from "zod";
|
778
|
+
import { z as z5 } from "zod/v4";
|
736
779
|
|
737
780
|
// src/convert-to-openai-compatible-completion-prompt.ts
|
738
781
|
import {
|
@@ -813,7 +856,7 @@ ${user}:`]
|
|
813
856
|
}
|
814
857
|
|
815
858
|
// src/openai-compatible-completion-options.ts
|
816
|
-
import { z as z4 } from "zod";
|
859
|
+
import { z as z4 } from "zod/v4";
|
817
860
|
var openaiCompatibleCompletionProviderOptions = z4.object({
|
818
861
|
/**
|
819
862
|
* Echo back the prompt in addition to the completion.
|
@@ -1006,6 +1049,9 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1006
1049
|
},
|
1007
1050
|
transform(chunk, controller) {
|
1008
1051
|
var _a, _b, _c;
|
1052
|
+
if (options.includeRawChunks) {
|
1053
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
1054
|
+
}
|
1009
1055
|
if (!chunk.success) {
|
1010
1056
|
finishReason = "error";
|
1011
1057
|
controller.enqueue({ type: "error", error: chunk.error });
|
@@ -1023,6 +1069,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1023
1069
|
type: "response-metadata",
|
1024
1070
|
...getResponseMetadata(value)
|
1025
1071
|
});
|
1072
|
+
controller.enqueue({
|
1073
|
+
type: "text-start",
|
1074
|
+
id: "0"
|
1075
|
+
});
|
1026
1076
|
}
|
1027
1077
|
if (value.usage != null) {
|
1028
1078
|
usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
|
@@ -1037,12 +1087,16 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1037
1087
|
}
|
1038
1088
|
if ((choice == null ? void 0 : choice.text) != null) {
|
1039
1089
|
controller.enqueue({
|
1040
|
-
type: "text",
|
1041
|
-
|
1090
|
+
type: "text-delta",
|
1091
|
+
id: "0",
|
1092
|
+
delta: choice.text
|
1042
1093
|
});
|
1043
1094
|
}
|
1044
1095
|
},
|
1045
1096
|
flush(controller) {
|
1097
|
+
if (!isFirstChunk) {
|
1098
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
1099
|
+
}
|
1046
1100
|
controller.enqueue({
|
1047
1101
|
type: "finish",
|
1048
1102
|
finishReason,
|
@@ -1101,10 +1155,10 @@ import {
|
|
1101
1155
|
parseProviderOptions as parseProviderOptions3,
|
1102
1156
|
postJsonToApi as postJsonToApi3
|
1103
1157
|
} from "@ai-sdk/provider-utils";
|
1104
|
-
import { z as z7 } from "zod";
|
1158
|
+
import { z as z7 } from "zod/v4";
|
1105
1159
|
|
1106
1160
|
// src/openai-compatible-embedding-options.ts
|
1107
|
-
import { z as z6 } from "zod";
|
1161
|
+
import { z as z6 } from "zod/v4";
|
1108
1162
|
var openaiCompatibleEmbeddingProviderOptions = z6.object({
|
1109
1163
|
/**
|
1110
1164
|
* The number of dimensions the resulting output embeddings should have.
|
@@ -1211,7 +1265,7 @@ import {
|
|
1211
1265
|
createJsonResponseHandler as createJsonResponseHandler4,
|
1212
1266
|
postJsonToApi as postJsonToApi4
|
1213
1267
|
} from "@ai-sdk/provider-utils";
|
1214
|
-
import { z as z8 } from "zod";
|
1268
|
+
import { z as z8 } from "zod/v4";
|
1215
1269
|
var OpenAICompatibleImageModel = class {
|
1216
1270
|
constructor(modelId, config) {
|
1217
1271
|
this.modelId = modelId;
|