@ai-sdk/openai-compatible 3.0.0-beta.23 → 3.0.0-beta.24
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 +237 -219
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +24 -47
- package/dist/internal/index.js.map +1 -1
- package/package.json +9 -10
- package/dist/index.d.mts +0 -290
- package/dist/index.mjs +0 -1815
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -193
- package/dist/internal/index.mjs +0 -346
- package/dist/internal/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
OpenAICompatibleChatLanguageModel: () => OpenAICompatibleChatLanguageModel,
|
|
24
|
-
OpenAICompatibleCompletionLanguageModel: () => OpenAICompatibleCompletionLanguageModel,
|
|
25
|
-
OpenAICompatibleEmbeddingModel: () => OpenAICompatibleEmbeddingModel,
|
|
26
|
-
OpenAICompatibleImageModel: () => OpenAICompatibleImageModel,
|
|
27
|
-
VERSION: () => VERSION,
|
|
28
|
-
createOpenAICompatible: () => createOpenAICompatible
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
|
|
32
1
|
// src/chat/openai-compatible-chat-language-model.ts
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
import {
|
|
3
|
+
InvalidResponseDataError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
combineHeaders,
|
|
7
|
+
createEventSourceResponseHandler,
|
|
8
|
+
createJsonErrorResponseHandler,
|
|
9
|
+
createJsonResponseHandler,
|
|
10
|
+
generateId,
|
|
11
|
+
isCustomReasoning,
|
|
12
|
+
isParsableJson,
|
|
13
|
+
parseProviderOptions,
|
|
14
|
+
postJsonToApi
|
|
15
|
+
} from "@ai-sdk/provider-utils";
|
|
16
|
+
import { z as z3 } from "zod/v4";
|
|
36
17
|
|
|
37
18
|
// src/utils/to-camel-case.ts
|
|
38
19
|
function toCamelCase(str) {
|
|
@@ -61,16 +42,16 @@ function warnIfDeprecatedProviderOptionsKey({
|
|
|
61
42
|
}
|
|
62
43
|
|
|
63
44
|
// src/openai-compatible-error.ts
|
|
64
|
-
|
|
65
|
-
var openaiCompatibleErrorDataSchema =
|
|
66
|
-
error:
|
|
67
|
-
message:
|
|
45
|
+
import { z } from "zod/v4";
|
|
46
|
+
var openaiCompatibleErrorDataSchema = z.object({
|
|
47
|
+
error: z.object({
|
|
48
|
+
message: z.string(),
|
|
68
49
|
// The additional information below is handled loosely to support
|
|
69
50
|
// OpenAI-compatible providers that have slightly different error
|
|
70
51
|
// responses:
|
|
71
|
-
type:
|
|
72
|
-
param:
|
|
73
|
-
code:
|
|
52
|
+
type: z.string().nullish(),
|
|
53
|
+
param: z.any().nullish(),
|
|
54
|
+
code: z.union([z.string(), z.number()]).nullish()
|
|
74
55
|
})
|
|
75
56
|
});
|
|
76
57
|
var defaultOpenAICompatibleErrorStructure = {
|
|
@@ -118,8 +99,14 @@ function convertOpenAICompatibleChatUsage(usage) {
|
|
|
118
99
|
}
|
|
119
100
|
|
|
120
101
|
// src/chat/convert-to-openai-compatible-chat-messages.ts
|
|
121
|
-
|
|
122
|
-
|
|
102
|
+
import {
|
|
103
|
+
UnsupportedFunctionalityError
|
|
104
|
+
} from "@ai-sdk/provider";
|
|
105
|
+
import {
|
|
106
|
+
convertBase64ToUint8Array,
|
|
107
|
+
convertToBase64,
|
|
108
|
+
isProviderReference
|
|
109
|
+
} from "@ai-sdk/provider-utils";
|
|
123
110
|
function getOpenAIMetadata(message) {
|
|
124
111
|
var _a, _b;
|
|
125
112
|
return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
|
|
@@ -164,8 +151,8 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
164
151
|
return { type: "text", text: part.text, ...partMetadata };
|
|
165
152
|
}
|
|
166
153
|
case "file": {
|
|
167
|
-
if (
|
|
168
|
-
throw new
|
|
154
|
+
if (isProviderReference(part.data)) {
|
|
155
|
+
throw new UnsupportedFunctionalityError({
|
|
169
156
|
functionality: "file parts with provider references"
|
|
170
157
|
});
|
|
171
158
|
}
|
|
@@ -174,27 +161,27 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
174
161
|
return {
|
|
175
162
|
type: "image_url",
|
|
176
163
|
image_url: {
|
|
177
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
164
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
178
165
|
},
|
|
179
166
|
...partMetadata
|
|
180
167
|
};
|
|
181
168
|
}
|
|
182
169
|
if (part.mediaType.startsWith("audio/")) {
|
|
183
170
|
if (part.data instanceof URL) {
|
|
184
|
-
throw new
|
|
171
|
+
throw new UnsupportedFunctionalityError({
|
|
185
172
|
functionality: "audio file parts with URLs"
|
|
186
173
|
});
|
|
187
174
|
}
|
|
188
175
|
const format = getAudioFormat(part.mediaType);
|
|
189
176
|
if (format === null) {
|
|
190
|
-
throw new
|
|
177
|
+
throw new UnsupportedFunctionalityError({
|
|
191
178
|
functionality: `audio media type ${part.mediaType}`
|
|
192
179
|
});
|
|
193
180
|
}
|
|
194
181
|
return {
|
|
195
182
|
type: "input_audio",
|
|
196
183
|
input_audio: {
|
|
197
|
-
data:
|
|
184
|
+
data: convertToBase64(part.data),
|
|
198
185
|
format
|
|
199
186
|
},
|
|
200
187
|
...partMetadata
|
|
@@ -202,7 +189,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
202
189
|
}
|
|
203
190
|
if (part.mediaType === "application/pdf") {
|
|
204
191
|
if (part.data instanceof URL) {
|
|
205
|
-
throw new
|
|
192
|
+
throw new UnsupportedFunctionalityError({
|
|
206
193
|
functionality: "PDF file parts with URLs"
|
|
207
194
|
});
|
|
208
195
|
}
|
|
@@ -210,14 +197,14 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
210
197
|
type: "file",
|
|
211
198
|
file: {
|
|
212
199
|
filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
|
|
213
|
-
file_data: `data:application/pdf;base64,${
|
|
200
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
214
201
|
},
|
|
215
202
|
...partMetadata
|
|
216
203
|
};
|
|
217
204
|
}
|
|
218
205
|
if (part.mediaType.startsWith("text/")) {
|
|
219
206
|
const textContent = part.data instanceof URL ? part.data.toString() : typeof part.data === "string" ? new TextDecoder().decode(
|
|
220
|
-
|
|
207
|
+
convertBase64ToUint8Array(part.data)
|
|
221
208
|
) : new TextDecoder().decode(part.data);
|
|
222
209
|
return {
|
|
223
210
|
type: "text",
|
|
@@ -225,7 +212,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
225
212
|
...partMetadata
|
|
226
213
|
};
|
|
227
214
|
}
|
|
228
|
-
throw new
|
|
215
|
+
throw new UnsupportedFunctionalityError({
|
|
229
216
|
functionality: `file part media type ${part.mediaType}`
|
|
230
217
|
});
|
|
231
218
|
}
|
|
@@ -353,21 +340,21 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
|
353
340
|
}
|
|
354
341
|
|
|
355
342
|
// src/chat/openai-compatible-chat-options.ts
|
|
356
|
-
|
|
357
|
-
var openaiCompatibleLanguageModelChatOptions =
|
|
343
|
+
import { z as z2 } from "zod/v4";
|
|
344
|
+
var openaiCompatibleLanguageModelChatOptions = z2.object({
|
|
358
345
|
/**
|
|
359
346
|
* A unique identifier representing your end-user, which can help the provider to
|
|
360
347
|
* monitor and detect abuse.
|
|
361
348
|
*/
|
|
362
|
-
user:
|
|
349
|
+
user: z2.string().optional(),
|
|
363
350
|
/**
|
|
364
351
|
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
365
352
|
*/
|
|
366
|
-
reasoningEffort:
|
|
353
|
+
reasoningEffort: z2.string().optional(),
|
|
367
354
|
/**
|
|
368
355
|
* Controls the verbosity of the generated text. Defaults to `medium`.
|
|
369
356
|
*/
|
|
370
|
-
textVerbosity:
|
|
357
|
+
textVerbosity: z2.string().optional(),
|
|
371
358
|
/**
|
|
372
359
|
* Whether to use strict JSON schema validation.
|
|
373
360
|
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
@@ -375,11 +362,13 @@ var openaiCompatibleLanguageModelChatOptions = import_v42.z.object({
|
|
|
375
362
|
*
|
|
376
363
|
* @default true
|
|
377
364
|
*/
|
|
378
|
-
strictJsonSchema:
|
|
365
|
+
strictJsonSchema: z2.boolean().optional()
|
|
379
366
|
});
|
|
380
367
|
|
|
381
368
|
// src/chat/openai-compatible-prepare-tools.ts
|
|
382
|
-
|
|
369
|
+
import {
|
|
370
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
371
|
+
} from "@ai-sdk/provider";
|
|
383
372
|
function prepareTools({
|
|
384
373
|
tools,
|
|
385
374
|
toolChoice
|
|
@@ -428,7 +417,7 @@ function prepareTools({
|
|
|
428
417
|
};
|
|
429
418
|
default: {
|
|
430
419
|
const _exhaustiveCheck = type;
|
|
431
|
-
throw new
|
|
420
|
+
throw new UnsupportedFunctionalityError2({
|
|
432
421
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
433
422
|
});
|
|
434
423
|
}
|
|
@@ -447,7 +436,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
447
436
|
this.chunkSchema = createOpenAICompatibleChatChunkSchema(
|
|
448
437
|
errorStructure.errorSchema
|
|
449
438
|
);
|
|
450
|
-
this.failedResponseHandler =
|
|
439
|
+
this.failedResponseHandler = createJsonErrorResponseHandler(errorStructure);
|
|
451
440
|
this.supportsStructuredOutputs = (_b = config.supportsStructuredOutputs) != null ? _b : false;
|
|
452
441
|
}
|
|
453
442
|
get provider() {
|
|
@@ -482,7 +471,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
482
471
|
}) {
|
|
483
472
|
var _a, _b, _c, _d, _e, _f;
|
|
484
473
|
const warnings = [];
|
|
485
|
-
const deprecatedOptions = await
|
|
474
|
+
const deprecatedOptions = await parseProviderOptions({
|
|
486
475
|
provider: "openai-compatible",
|
|
487
476
|
providerOptions,
|
|
488
477
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
@@ -501,17 +490,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
501
490
|
});
|
|
502
491
|
const compatibleOptions = Object.assign(
|
|
503
492
|
deprecatedOptions != null ? deprecatedOptions : {},
|
|
504
|
-
(_a = await
|
|
493
|
+
(_a = await parseProviderOptions({
|
|
505
494
|
provider: "openaiCompatible",
|
|
506
495
|
providerOptions,
|
|
507
496
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
508
497
|
})) != null ? _a : {},
|
|
509
|
-
(_b = await
|
|
498
|
+
(_b = await parseProviderOptions({
|
|
510
499
|
provider: this.providerOptionsName,
|
|
511
500
|
providerOptions,
|
|
512
501
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
513
502
|
})) != null ? _b : {},
|
|
514
|
-
(_c = await
|
|
503
|
+
(_c = await parseProviderOptions({
|
|
515
504
|
provider: toCamelCase(this.providerOptionsName),
|
|
516
505
|
providerOptions,
|
|
517
506
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
@@ -574,7 +563,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
574
563
|
).includes(key)
|
|
575
564
|
)
|
|
576
565
|
),
|
|
577
|
-
reasoning_effort: (_f = compatibleOptions.reasoningEffort) != null ? _f :
|
|
566
|
+
reasoning_effort: (_f = compatibleOptions.reasoningEffort) != null ? _f : isCustomReasoning(reasoning) && reasoning !== "none" ? reasoning : void 0,
|
|
578
567
|
verbosity: compatibleOptions.textVerbosity,
|
|
579
568
|
// messages:
|
|
580
569
|
messages: convertToOpenAICompatibleChatMessages(prompt),
|
|
@@ -594,15 +583,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
594
583
|
responseHeaders,
|
|
595
584
|
value: responseBody,
|
|
596
585
|
rawValue: rawResponse
|
|
597
|
-
} = await
|
|
586
|
+
} = await postJsonToApi({
|
|
598
587
|
url: this.config.url({
|
|
599
588
|
path: "/chat/completions",
|
|
600
589
|
modelId: this.modelId
|
|
601
590
|
}),
|
|
602
|
-
headers:
|
|
591
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
603
592
|
body: transformedBody,
|
|
604
593
|
failedResponseHandler: this.failedResponseHandler,
|
|
605
|
-
successfulResponseHandler:
|
|
594
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
606
595
|
OpenAICompatibleChatResponseSchema
|
|
607
596
|
),
|
|
608
597
|
abortSignal: options.abortSignal,
|
|
@@ -626,7 +615,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
626
615
|
const thoughtSignature = (_c = (_b = toolCall.extra_content) == null ? void 0 : _b.google) == null ? void 0 : _c.thought_signature;
|
|
627
616
|
content.push({
|
|
628
617
|
type: "tool-call",
|
|
629
|
-
toolCallId: (_d = toolCall.id) != null ? _d :
|
|
618
|
+
toolCallId: (_d = toolCall.id) != null ? _d : generateId(),
|
|
630
619
|
toolName: toolCall.function.name,
|
|
631
620
|
input: toolCall.function.arguments,
|
|
632
621
|
...thoughtSignature ? {
|
|
@@ -679,15 +668,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
679
668
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
680
669
|
});
|
|
681
670
|
const metadataExtractor = (_a = this.config.metadataExtractor) == null ? void 0 : _a.createStreamExtractor();
|
|
682
|
-
const { responseHeaders, value: response } = await
|
|
671
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
683
672
|
url: this.config.url({
|
|
684
673
|
path: "/chat/completions",
|
|
685
674
|
modelId: this.modelId
|
|
686
675
|
}),
|
|
687
|
-
headers:
|
|
676
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
688
677
|
body,
|
|
689
678
|
failedResponseHandler: this.failedResponseHandler,
|
|
690
|
-
successfulResponseHandler:
|
|
679
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
691
680
|
this.chunkSchema
|
|
692
681
|
),
|
|
693
682
|
abortSignal: options.abortSignal,
|
|
@@ -795,13 +784,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
795
784
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
|
|
796
785
|
if (toolCalls[index] == null) {
|
|
797
786
|
if (toolCallDelta.id == null) {
|
|
798
|
-
throw new
|
|
787
|
+
throw new InvalidResponseDataError({
|
|
799
788
|
data: toolCallDelta,
|
|
800
789
|
message: `Expected 'id' to be a string.`
|
|
801
790
|
});
|
|
802
791
|
}
|
|
803
792
|
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
804
|
-
throw new
|
|
793
|
+
throw new InvalidResponseDataError({
|
|
805
794
|
data: toolCallDelta,
|
|
806
795
|
message: `Expected 'function.name' to be a string.`
|
|
807
796
|
});
|
|
@@ -830,14 +819,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
830
819
|
delta: toolCall2.function.arguments
|
|
831
820
|
});
|
|
832
821
|
}
|
|
833
|
-
if (
|
|
822
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
834
823
|
controller.enqueue({
|
|
835
824
|
type: "tool-input-end",
|
|
836
825
|
id: toolCall2.id
|
|
837
826
|
});
|
|
838
827
|
controller.enqueue({
|
|
839
828
|
type: "tool-call",
|
|
840
|
-
toolCallId: (_k = toolCall2.id) != null ? _k :
|
|
829
|
+
toolCallId: (_k = toolCall2.id) != null ? _k : generateId(),
|
|
841
830
|
toolName: toolCall2.function.name,
|
|
842
831
|
input: toolCall2.function.arguments,
|
|
843
832
|
...toolCall2.thoughtSignature ? {
|
|
@@ -865,14 +854,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
865
854
|
id: toolCall.id,
|
|
866
855
|
delta: (_o = toolCallDelta.function.arguments) != null ? _o : ""
|
|
867
856
|
});
|
|
868
|
-
if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null &&
|
|
857
|
+
if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
869
858
|
controller.enqueue({
|
|
870
859
|
type: "tool-input-end",
|
|
871
860
|
id: toolCall.id
|
|
872
861
|
});
|
|
873
862
|
controller.enqueue({
|
|
874
863
|
type: "tool-call",
|
|
875
|
-
toolCallId: (_r = toolCall.id) != null ? _r :
|
|
864
|
+
toolCallId: (_r = toolCall.id) != null ? _r : generateId(),
|
|
876
865
|
toolName: toolCall.function.name,
|
|
877
866
|
input: toolCall.function.arguments,
|
|
878
867
|
...toolCall.thoughtSignature ? {
|
|
@@ -905,7 +894,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
905
894
|
});
|
|
906
895
|
controller.enqueue({
|
|
907
896
|
type: "tool-call",
|
|
908
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 :
|
|
897
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
909
898
|
toolName: toolCall.function.name,
|
|
910
899
|
input: toolCall.function.arguments,
|
|
911
900
|
...toolCall.thoughtSignature ? {
|
|
@@ -941,92 +930,99 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
941
930
|
};
|
|
942
931
|
}
|
|
943
932
|
};
|
|
944
|
-
var openaiCompatibleTokenUsageSchema =
|
|
945
|
-
prompt_tokens:
|
|
946
|
-
completion_tokens:
|
|
947
|
-
total_tokens:
|
|
948
|
-
prompt_tokens_details:
|
|
949
|
-
cached_tokens:
|
|
933
|
+
var openaiCompatibleTokenUsageSchema = z3.looseObject({
|
|
934
|
+
prompt_tokens: z3.number().nullish(),
|
|
935
|
+
completion_tokens: z3.number().nullish(),
|
|
936
|
+
total_tokens: z3.number().nullish(),
|
|
937
|
+
prompt_tokens_details: z3.object({
|
|
938
|
+
cached_tokens: z3.number().nullish()
|
|
950
939
|
}).nullish(),
|
|
951
|
-
completion_tokens_details:
|
|
952
|
-
reasoning_tokens:
|
|
953
|
-
accepted_prediction_tokens:
|
|
954
|
-
rejected_prediction_tokens:
|
|
940
|
+
completion_tokens_details: z3.object({
|
|
941
|
+
reasoning_tokens: z3.number().nullish(),
|
|
942
|
+
accepted_prediction_tokens: z3.number().nullish(),
|
|
943
|
+
rejected_prediction_tokens: z3.number().nullish()
|
|
955
944
|
}).nullish()
|
|
956
945
|
}).nullish();
|
|
957
|
-
var OpenAICompatibleChatResponseSchema =
|
|
958
|
-
id:
|
|
959
|
-
created:
|
|
960
|
-
model:
|
|
961
|
-
choices:
|
|
962
|
-
|
|
963
|
-
message:
|
|
964
|
-
role:
|
|
965
|
-
content:
|
|
966
|
-
reasoning_content:
|
|
967
|
-
reasoning:
|
|
968
|
-
tool_calls:
|
|
969
|
-
|
|
970
|
-
id:
|
|
971
|
-
function:
|
|
972
|
-
name:
|
|
973
|
-
arguments:
|
|
946
|
+
var OpenAICompatibleChatResponseSchema = z3.looseObject({
|
|
947
|
+
id: z3.string().nullish(),
|
|
948
|
+
created: z3.number().nullish(),
|
|
949
|
+
model: z3.string().nullish(),
|
|
950
|
+
choices: z3.array(
|
|
951
|
+
z3.object({
|
|
952
|
+
message: z3.object({
|
|
953
|
+
role: z3.literal("assistant").nullish(),
|
|
954
|
+
content: z3.string().nullish(),
|
|
955
|
+
reasoning_content: z3.string().nullish(),
|
|
956
|
+
reasoning: z3.string().nullish(),
|
|
957
|
+
tool_calls: z3.array(
|
|
958
|
+
z3.object({
|
|
959
|
+
id: z3.string().nullish(),
|
|
960
|
+
function: z3.object({
|
|
961
|
+
name: z3.string(),
|
|
962
|
+
arguments: z3.string()
|
|
974
963
|
}),
|
|
975
964
|
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
976
|
-
extra_content:
|
|
977
|
-
google:
|
|
978
|
-
thought_signature:
|
|
965
|
+
extra_content: z3.object({
|
|
966
|
+
google: z3.object({
|
|
967
|
+
thought_signature: z3.string().nullish()
|
|
979
968
|
}).nullish()
|
|
980
969
|
}).nullish()
|
|
981
970
|
})
|
|
982
971
|
).nullish()
|
|
983
972
|
}),
|
|
984
|
-
finish_reason:
|
|
973
|
+
finish_reason: z3.string().nullish()
|
|
985
974
|
})
|
|
986
975
|
),
|
|
987
976
|
usage: openaiCompatibleTokenUsageSchema
|
|
988
977
|
});
|
|
989
|
-
var chunkBaseSchema =
|
|
990
|
-
id:
|
|
991
|
-
created:
|
|
992
|
-
model:
|
|
993
|
-
choices:
|
|
994
|
-
|
|
995
|
-
delta:
|
|
996
|
-
role:
|
|
997
|
-
content:
|
|
978
|
+
var chunkBaseSchema = z3.looseObject({
|
|
979
|
+
id: z3.string().nullish(),
|
|
980
|
+
created: z3.number().nullish(),
|
|
981
|
+
model: z3.string().nullish(),
|
|
982
|
+
choices: z3.array(
|
|
983
|
+
z3.object({
|
|
984
|
+
delta: z3.object({
|
|
985
|
+
role: z3.enum(["assistant"]).nullish(),
|
|
986
|
+
content: z3.string().nullish(),
|
|
998
987
|
// Most openai-compatible models set `reasoning_content`, but some
|
|
999
988
|
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
1000
|
-
reasoning_content:
|
|
1001
|
-
reasoning:
|
|
1002
|
-
tool_calls:
|
|
1003
|
-
|
|
1004
|
-
index:
|
|
989
|
+
reasoning_content: z3.string().nullish(),
|
|
990
|
+
reasoning: z3.string().nullish(),
|
|
991
|
+
tool_calls: z3.array(
|
|
992
|
+
z3.object({
|
|
993
|
+
index: z3.number().nullish(),
|
|
1005
994
|
//google does not send index
|
|
1006
|
-
id:
|
|
1007
|
-
function:
|
|
1008
|
-
name:
|
|
1009
|
-
arguments:
|
|
995
|
+
id: z3.string().nullish(),
|
|
996
|
+
function: z3.object({
|
|
997
|
+
name: z3.string().nullish(),
|
|
998
|
+
arguments: z3.string().nullish()
|
|
1010
999
|
}),
|
|
1011
1000
|
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
1012
|
-
extra_content:
|
|
1013
|
-
google:
|
|
1014
|
-
thought_signature:
|
|
1001
|
+
extra_content: z3.object({
|
|
1002
|
+
google: z3.object({
|
|
1003
|
+
thought_signature: z3.string().nullish()
|
|
1015
1004
|
}).nullish()
|
|
1016
1005
|
}).nullish()
|
|
1017
1006
|
})
|
|
1018
1007
|
).nullish()
|
|
1019
1008
|
}).nullish(),
|
|
1020
|
-
finish_reason:
|
|
1009
|
+
finish_reason: z3.string().nullish()
|
|
1021
1010
|
})
|
|
1022
1011
|
),
|
|
1023
1012
|
usage: openaiCompatibleTokenUsageSchema
|
|
1024
1013
|
});
|
|
1025
|
-
var createOpenAICompatibleChatChunkSchema = (errorSchema) =>
|
|
1014
|
+
var createOpenAICompatibleChatChunkSchema = (errorSchema) => z3.union([chunkBaseSchema, errorSchema]);
|
|
1026
1015
|
|
|
1027
1016
|
// src/completion/openai-compatible-completion-language-model.ts
|
|
1028
|
-
|
|
1029
|
-
|
|
1017
|
+
import {
|
|
1018
|
+
combineHeaders as combineHeaders2,
|
|
1019
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
1020
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1021
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1022
|
+
parseProviderOptions as parseProviderOptions2,
|
|
1023
|
+
postJsonToApi as postJsonToApi2
|
|
1024
|
+
} from "@ai-sdk/provider-utils";
|
|
1025
|
+
import { z as z5 } from "zod/v4";
|
|
1030
1026
|
|
|
1031
1027
|
// src/completion/convert-openai-compatible-completion-usage.ts
|
|
1032
1028
|
function convertOpenAICompatibleCompletionUsage(usage) {
|
|
@@ -1066,7 +1062,10 @@ function convertOpenAICompatibleCompletionUsage(usage) {
|
|
|
1066
1062
|
}
|
|
1067
1063
|
|
|
1068
1064
|
// src/completion/convert-to-openai-compatible-completion-prompt.ts
|
|
1069
|
-
|
|
1065
|
+
import {
|
|
1066
|
+
InvalidPromptError,
|
|
1067
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1068
|
+
} from "@ai-sdk/provider";
|
|
1070
1069
|
function convertToOpenAICompatibleCompletionPrompt({
|
|
1071
1070
|
prompt,
|
|
1072
1071
|
user = "user",
|
|
@@ -1082,7 +1081,7 @@ function convertToOpenAICompatibleCompletionPrompt({
|
|
|
1082
1081
|
for (const { role, content } of prompt) {
|
|
1083
1082
|
switch (role) {
|
|
1084
1083
|
case "system": {
|
|
1085
|
-
throw new
|
|
1084
|
+
throw new InvalidPromptError({
|
|
1086
1085
|
message: "Unexpected system message in prompt: ${content}",
|
|
1087
1086
|
prompt
|
|
1088
1087
|
});
|
|
@@ -1108,7 +1107,7 @@ ${userMessage}
|
|
|
1108
1107
|
return part.text;
|
|
1109
1108
|
}
|
|
1110
1109
|
case "tool-call": {
|
|
1111
|
-
throw new
|
|
1110
|
+
throw new UnsupportedFunctionalityError3({
|
|
1112
1111
|
functionality: "tool-call messages"
|
|
1113
1112
|
});
|
|
1114
1113
|
}
|
|
@@ -1121,7 +1120,7 @@ ${assistantMessage}
|
|
|
1121
1120
|
break;
|
|
1122
1121
|
}
|
|
1123
1122
|
case "tool": {
|
|
1124
|
-
throw new
|
|
1123
|
+
throw new UnsupportedFunctionalityError3({
|
|
1125
1124
|
functionality: "tool messages"
|
|
1126
1125
|
});
|
|
1127
1126
|
}
|
|
@@ -1171,28 +1170,28 @@ function mapOpenAICompatibleFinishReason2(finishReason) {
|
|
|
1171
1170
|
}
|
|
1172
1171
|
|
|
1173
1172
|
// src/completion/openai-compatible-completion-options.ts
|
|
1174
|
-
|
|
1175
|
-
var openaiCompatibleLanguageModelCompletionOptions =
|
|
1173
|
+
import { z as z4 } from "zod/v4";
|
|
1174
|
+
var openaiCompatibleLanguageModelCompletionOptions = z4.object({
|
|
1176
1175
|
/**
|
|
1177
1176
|
* Echo back the prompt in addition to the completion.
|
|
1178
1177
|
*/
|
|
1179
|
-
echo:
|
|
1178
|
+
echo: z4.boolean().optional(),
|
|
1180
1179
|
/**
|
|
1181
1180
|
* Modify the likelihood of specified tokens appearing in the completion.
|
|
1182
1181
|
*
|
|
1183
1182
|
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
1184
1183
|
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
1185
1184
|
*/
|
|
1186
|
-
logitBias:
|
|
1185
|
+
logitBias: z4.record(z4.string(), z4.number()).optional(),
|
|
1187
1186
|
/**
|
|
1188
1187
|
* The suffix that comes after a completion of inserted text.
|
|
1189
1188
|
*/
|
|
1190
|
-
suffix:
|
|
1189
|
+
suffix: z4.string().optional(),
|
|
1191
1190
|
/**
|
|
1192
1191
|
* A unique identifier representing your end-user, which can help providers to
|
|
1193
1192
|
* monitor and detect abuse.
|
|
1194
1193
|
*/
|
|
1195
|
-
user:
|
|
1194
|
+
user: z4.string().optional()
|
|
1196
1195
|
});
|
|
1197
1196
|
|
|
1198
1197
|
// src/completion/openai-compatible-completion-language-model.ts
|
|
@@ -1207,7 +1206,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1207
1206
|
this.chunkSchema = createOpenAICompatibleCompletionChunkSchema(
|
|
1208
1207
|
errorStructure.errorSchema
|
|
1209
1208
|
);
|
|
1210
|
-
this.failedResponseHandler = (
|
|
1209
|
+
this.failedResponseHandler = createJsonErrorResponseHandler2(errorStructure);
|
|
1211
1210
|
}
|
|
1212
1211
|
get provider() {
|
|
1213
1212
|
return this.config.provider;
|
|
@@ -1242,12 +1241,12 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1242
1241
|
warnings
|
|
1243
1242
|
});
|
|
1244
1243
|
const completionOptions = Object.assign(
|
|
1245
|
-
(_a = await (
|
|
1244
|
+
(_a = await parseProviderOptions2({
|
|
1246
1245
|
provider: this.providerOptionsName,
|
|
1247
1246
|
providerOptions,
|
|
1248
1247
|
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1249
1248
|
})) != null ? _a : {},
|
|
1250
|
-
(_b = await (
|
|
1249
|
+
(_b = await parseProviderOptions2({
|
|
1251
1250
|
provider: toCamelCase(this.providerOptionsName),
|
|
1252
1251
|
providerOptions,
|
|
1253
1252
|
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
@@ -1303,15 +1302,15 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1303
1302
|
responseHeaders,
|
|
1304
1303
|
value: response,
|
|
1305
1304
|
rawValue: rawResponse
|
|
1306
|
-
} = await (
|
|
1305
|
+
} = await postJsonToApi2({
|
|
1307
1306
|
url: this.config.url({
|
|
1308
1307
|
path: "/completions",
|
|
1309
1308
|
modelId: this.modelId
|
|
1310
1309
|
}),
|
|
1311
|
-
headers: (
|
|
1310
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
1312
1311
|
body: args,
|
|
1313
1312
|
failedResponseHandler: this.failedResponseHandler,
|
|
1314
|
-
successfulResponseHandler: (
|
|
1313
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1315
1314
|
openaiCompatibleCompletionResponseSchema
|
|
1316
1315
|
),
|
|
1317
1316
|
abortSignal: options.abortSignal,
|
|
@@ -1346,15 +1345,15 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1346
1345
|
// only include stream_options when in strict compatibility mode:
|
|
1347
1346
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
1348
1347
|
};
|
|
1349
|
-
const { responseHeaders, value: response } = await (
|
|
1348
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1350
1349
|
url: this.config.url({
|
|
1351
1350
|
path: "/completions",
|
|
1352
1351
|
modelId: this.modelId
|
|
1353
1352
|
}),
|
|
1354
|
-
headers: (
|
|
1353
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
1355
1354
|
body,
|
|
1356
1355
|
failedResponseHandler: this.failedResponseHandler,
|
|
1357
|
-
successfulResponseHandler: (
|
|
1356
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
1358
1357
|
this.chunkSchema
|
|
1359
1358
|
),
|
|
1360
1359
|
abortSignal: options.abortSignal,
|
|
@@ -1434,33 +1433,33 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1434
1433
|
};
|
|
1435
1434
|
}
|
|
1436
1435
|
};
|
|
1437
|
-
var usageSchema =
|
|
1438
|
-
prompt_tokens:
|
|
1439
|
-
completion_tokens:
|
|
1440
|
-
total_tokens:
|
|
1436
|
+
var usageSchema = z5.object({
|
|
1437
|
+
prompt_tokens: z5.number(),
|
|
1438
|
+
completion_tokens: z5.number(),
|
|
1439
|
+
total_tokens: z5.number()
|
|
1441
1440
|
});
|
|
1442
|
-
var openaiCompatibleCompletionResponseSchema =
|
|
1443
|
-
id:
|
|
1444
|
-
created:
|
|
1445
|
-
model:
|
|
1446
|
-
choices:
|
|
1447
|
-
|
|
1448
|
-
text:
|
|
1449
|
-
finish_reason:
|
|
1441
|
+
var openaiCompatibleCompletionResponseSchema = z5.object({
|
|
1442
|
+
id: z5.string().nullish(),
|
|
1443
|
+
created: z5.number().nullish(),
|
|
1444
|
+
model: z5.string().nullish(),
|
|
1445
|
+
choices: z5.array(
|
|
1446
|
+
z5.object({
|
|
1447
|
+
text: z5.string(),
|
|
1448
|
+
finish_reason: z5.string()
|
|
1450
1449
|
})
|
|
1451
1450
|
),
|
|
1452
1451
|
usage: usageSchema.nullish()
|
|
1453
1452
|
});
|
|
1454
|
-
var createOpenAICompatibleCompletionChunkSchema = (errorSchema) =>
|
|
1455
|
-
|
|
1456
|
-
id:
|
|
1457
|
-
created:
|
|
1458
|
-
model:
|
|
1459
|
-
choices:
|
|
1460
|
-
|
|
1461
|
-
text:
|
|
1462
|
-
finish_reason:
|
|
1463
|
-
index:
|
|
1453
|
+
var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => z5.union([
|
|
1454
|
+
z5.object({
|
|
1455
|
+
id: z5.string().nullish(),
|
|
1456
|
+
created: z5.number().nullish(),
|
|
1457
|
+
model: z5.string().nullish(),
|
|
1458
|
+
choices: z5.array(
|
|
1459
|
+
z5.object({
|
|
1460
|
+
text: z5.string(),
|
|
1461
|
+
finish_reason: z5.string().nullish(),
|
|
1462
|
+
index: z5.number()
|
|
1464
1463
|
})
|
|
1465
1464
|
),
|
|
1466
1465
|
usage: usageSchema.nullish()
|
|
@@ -1469,23 +1468,31 @@ var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_v45.z.
|
|
|
1469
1468
|
]);
|
|
1470
1469
|
|
|
1471
1470
|
// src/embedding/openai-compatible-embedding-model.ts
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1471
|
+
import {
|
|
1472
|
+
TooManyEmbeddingValuesForCallError
|
|
1473
|
+
} from "@ai-sdk/provider";
|
|
1474
|
+
import {
|
|
1475
|
+
combineHeaders as combineHeaders3,
|
|
1476
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1477
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1478
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1479
|
+
postJsonToApi as postJsonToApi3
|
|
1480
|
+
} from "@ai-sdk/provider-utils";
|
|
1481
|
+
import { z as z7 } from "zod/v4";
|
|
1475
1482
|
|
|
1476
1483
|
// src/embedding/openai-compatible-embedding-options.ts
|
|
1477
|
-
|
|
1478
|
-
var openaiCompatibleEmbeddingModelOptions =
|
|
1484
|
+
import { z as z6 } from "zod/v4";
|
|
1485
|
+
var openaiCompatibleEmbeddingModelOptions = z6.object({
|
|
1479
1486
|
/**
|
|
1480
1487
|
* The number of dimensions the resulting output embeddings should have.
|
|
1481
1488
|
* Only supported in text-embedding-3 and later models.
|
|
1482
1489
|
*/
|
|
1483
|
-
dimensions:
|
|
1490
|
+
dimensions: z6.number().optional(),
|
|
1484
1491
|
/**
|
|
1485
1492
|
* A unique identifier representing your end-user, which can help providers to
|
|
1486
1493
|
* monitor and detect abuse.
|
|
1487
1494
|
*/
|
|
1488
|
-
user:
|
|
1495
|
+
user: z6.string().optional()
|
|
1489
1496
|
});
|
|
1490
1497
|
|
|
1491
1498
|
// src/embedding/openai-compatible-embedding-model.ts
|
|
@@ -1517,7 +1524,7 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1517
1524
|
}) {
|
|
1518
1525
|
var _a, _b, _c;
|
|
1519
1526
|
const warnings = [];
|
|
1520
|
-
const deprecatedOptions = await (
|
|
1527
|
+
const deprecatedOptions = await parseProviderOptions3({
|
|
1521
1528
|
provider: "openai-compatible",
|
|
1522
1529
|
providerOptions,
|
|
1523
1530
|
schema: openaiCompatibleEmbeddingModelOptions
|
|
@@ -1536,19 +1543,19 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1536
1543
|
});
|
|
1537
1544
|
const compatibleOptions = Object.assign(
|
|
1538
1545
|
deprecatedOptions != null ? deprecatedOptions : {},
|
|
1539
|
-
(_a = await (
|
|
1546
|
+
(_a = await parseProviderOptions3({
|
|
1540
1547
|
provider: "openaiCompatible",
|
|
1541
1548
|
providerOptions,
|
|
1542
1549
|
schema: openaiCompatibleEmbeddingModelOptions
|
|
1543
1550
|
})) != null ? _a : {},
|
|
1544
|
-
(_b = await (
|
|
1551
|
+
(_b = await parseProviderOptions3({
|
|
1545
1552
|
provider: this.providerOptionsName,
|
|
1546
1553
|
providerOptions,
|
|
1547
1554
|
schema: openaiCompatibleEmbeddingModelOptions
|
|
1548
1555
|
})) != null ? _b : {}
|
|
1549
1556
|
);
|
|
1550
1557
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1551
|
-
throw new
|
|
1558
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1552
1559
|
provider: this.provider,
|
|
1553
1560
|
modelId: this.modelId,
|
|
1554
1561
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -1559,12 +1566,12 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1559
1566
|
responseHeaders,
|
|
1560
1567
|
value: response,
|
|
1561
1568
|
rawValue
|
|
1562
|
-
} = await (
|
|
1569
|
+
} = await postJsonToApi3({
|
|
1563
1570
|
url: this.config.url({
|
|
1564
1571
|
path: "/embeddings",
|
|
1565
1572
|
modelId: this.modelId
|
|
1566
1573
|
}),
|
|
1567
|
-
headers: (
|
|
1574
|
+
headers: combineHeaders3(this.config.headers(), headers),
|
|
1568
1575
|
body: {
|
|
1569
1576
|
model: this.modelId,
|
|
1570
1577
|
input: values,
|
|
@@ -1572,10 +1579,10 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1572
1579
|
dimensions: compatibleOptions.dimensions,
|
|
1573
1580
|
user: compatibleOptions.user
|
|
1574
1581
|
},
|
|
1575
|
-
failedResponseHandler: (
|
|
1582
|
+
failedResponseHandler: createJsonErrorResponseHandler3(
|
|
1576
1583
|
(_c = this.config.errorStructure) != null ? _c : defaultOpenAICompatibleErrorStructure
|
|
1577
1584
|
),
|
|
1578
|
-
successfulResponseHandler: (
|
|
1585
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1579
1586
|
openaiTextEmbeddingResponseSchema
|
|
1580
1587
|
),
|
|
1581
1588
|
abortSignal,
|
|
@@ -1590,15 +1597,24 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1590
1597
|
};
|
|
1591
1598
|
}
|
|
1592
1599
|
};
|
|
1593
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1594
|
-
data:
|
|
1595
|
-
usage:
|
|
1596
|
-
providerMetadata:
|
|
1600
|
+
var openaiTextEmbeddingResponseSchema = z7.object({
|
|
1601
|
+
data: z7.array(z7.object({ embedding: z7.array(z7.number()) })),
|
|
1602
|
+
usage: z7.object({ prompt_tokens: z7.number() }).nullish(),
|
|
1603
|
+
providerMetadata: z7.record(z7.string(), z7.record(z7.string(), z7.any())).optional()
|
|
1597
1604
|
});
|
|
1598
1605
|
|
|
1599
1606
|
// src/image/openai-compatible-image-model.ts
|
|
1600
|
-
|
|
1601
|
-
|
|
1607
|
+
import {
|
|
1608
|
+
combineHeaders as combineHeaders4,
|
|
1609
|
+
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
1610
|
+
convertToFormData,
|
|
1611
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
1612
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1613
|
+
downloadBlob,
|
|
1614
|
+
postFormDataToApi,
|
|
1615
|
+
postJsonToApi as postJsonToApi4
|
|
1616
|
+
} from "@ai-sdk/provider-utils";
|
|
1617
|
+
import { z as z8 } from "zod/v4";
|
|
1602
1618
|
var OpenAICompatibleImageModel = class {
|
|
1603
1619
|
constructor(modelId, config) {
|
|
1604
1620
|
this.modelId = modelId;
|
|
@@ -1653,13 +1669,13 @@ var OpenAICompatibleImageModel = class {
|
|
|
1653
1669
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1654
1670
|
const args = this.getArgs(providerOptions, warnings);
|
|
1655
1671
|
if (files != null && files.length > 0) {
|
|
1656
|
-
const { value: response2, responseHeaders: responseHeaders2 } = await
|
|
1672
|
+
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
1657
1673
|
url: this.config.url({
|
|
1658
1674
|
path: "/images/edits",
|
|
1659
1675
|
modelId: this.modelId
|
|
1660
1676
|
}),
|
|
1661
|
-
headers: (
|
|
1662
|
-
formData:
|
|
1677
|
+
headers: combineHeaders4(this.config.headers(), headers),
|
|
1678
|
+
formData: convertToFormData({
|
|
1663
1679
|
model: this.modelId,
|
|
1664
1680
|
prompt,
|
|
1665
1681
|
image: await Promise.all(files.map((file) => fileToBlob(file))),
|
|
@@ -1668,10 +1684,10 @@ var OpenAICompatibleImageModel = class {
|
|
|
1668
1684
|
size,
|
|
1669
1685
|
...args
|
|
1670
1686
|
}),
|
|
1671
|
-
failedResponseHandler: (
|
|
1687
|
+
failedResponseHandler: createJsonErrorResponseHandler4(
|
|
1672
1688
|
(_d = this.config.errorStructure) != null ? _d : defaultOpenAICompatibleErrorStructure
|
|
1673
1689
|
),
|
|
1674
|
-
successfulResponseHandler: (
|
|
1690
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1675
1691
|
openaiCompatibleImageResponseSchema
|
|
1676
1692
|
),
|
|
1677
1693
|
abortSignal,
|
|
@@ -1687,12 +1703,12 @@ var OpenAICompatibleImageModel = class {
|
|
|
1687
1703
|
}
|
|
1688
1704
|
};
|
|
1689
1705
|
}
|
|
1690
|
-
const { value: response, responseHeaders } = await (
|
|
1706
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
1691
1707
|
url: this.config.url({
|
|
1692
1708
|
path: "/images/generations",
|
|
1693
1709
|
modelId: this.modelId
|
|
1694
1710
|
}),
|
|
1695
|
-
headers: (
|
|
1711
|
+
headers: combineHeaders4(this.config.headers(), headers),
|
|
1696
1712
|
body: {
|
|
1697
1713
|
model: this.modelId,
|
|
1698
1714
|
prompt,
|
|
@@ -1701,10 +1717,10 @@ var OpenAICompatibleImageModel = class {
|
|
|
1701
1717
|
...args,
|
|
1702
1718
|
response_format: "b64_json"
|
|
1703
1719
|
},
|
|
1704
|
-
failedResponseHandler: (
|
|
1720
|
+
failedResponseHandler: createJsonErrorResponseHandler4(
|
|
1705
1721
|
(_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
|
|
1706
1722
|
),
|
|
1707
|
-
successfulResponseHandler: (
|
|
1723
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1708
1724
|
openaiCompatibleImageResponseSchema
|
|
1709
1725
|
),
|
|
1710
1726
|
abortSignal,
|
|
@@ -1721,32 +1737,35 @@ var OpenAICompatibleImageModel = class {
|
|
|
1721
1737
|
};
|
|
1722
1738
|
}
|
|
1723
1739
|
};
|
|
1724
|
-
var openaiCompatibleImageResponseSchema =
|
|
1725
|
-
data:
|
|
1740
|
+
var openaiCompatibleImageResponseSchema = z8.object({
|
|
1741
|
+
data: z8.array(z8.object({ b64_json: z8.string() }))
|
|
1726
1742
|
});
|
|
1727
1743
|
async function fileToBlob(file) {
|
|
1728
1744
|
if (file.type === "url") {
|
|
1729
|
-
return
|
|
1745
|
+
return downloadBlob(file.url);
|
|
1730
1746
|
}
|
|
1731
|
-
const data = file.data instanceof Uint8Array ? file.data : (
|
|
1747
|
+
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array2(file.data);
|
|
1732
1748
|
return new Blob([data], { type: file.mediaType });
|
|
1733
1749
|
}
|
|
1734
1750
|
|
|
1735
1751
|
// src/openai-compatible-provider.ts
|
|
1736
|
-
|
|
1752
|
+
import {
|
|
1753
|
+
withoutTrailingSlash,
|
|
1754
|
+
withUserAgentSuffix
|
|
1755
|
+
} from "@ai-sdk/provider-utils";
|
|
1737
1756
|
|
|
1738
1757
|
// src/version.ts
|
|
1739
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1758
|
+
var VERSION = true ? "3.0.0-beta.24" : "0.0.0-test";
|
|
1740
1759
|
|
|
1741
1760
|
// src/openai-compatible-provider.ts
|
|
1742
1761
|
function createOpenAICompatible(options) {
|
|
1743
|
-
const baseURL =
|
|
1762
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
1744
1763
|
const providerName = options.name;
|
|
1745
1764
|
const headers = {
|
|
1746
1765
|
...options.apiKey && { Authorization: `Bearer ${options.apiKey}` },
|
|
1747
1766
|
...options.headers
|
|
1748
1767
|
};
|
|
1749
|
-
const getHeaders = () =>
|
|
1768
|
+
const getHeaders = () => withUserAgentSuffix(headers, `ai-sdk/openai-compatible/${VERSION}`);
|
|
1750
1769
|
const getCommonModelConfig = (modelType) => ({
|
|
1751
1770
|
provider: `${providerName}.${modelType}`,
|
|
1752
1771
|
url: ({ path }) => {
|
|
@@ -1785,13 +1804,12 @@ function createOpenAICompatible(options) {
|
|
|
1785
1804
|
provider.imageModel = createImageModel;
|
|
1786
1805
|
return provider;
|
|
1787
1806
|
}
|
|
1788
|
-
|
|
1789
|
-
0 && (module.exports = {
|
|
1807
|
+
export {
|
|
1790
1808
|
OpenAICompatibleChatLanguageModel,
|
|
1791
1809
|
OpenAICompatibleCompletionLanguageModel,
|
|
1792
1810
|
OpenAICompatibleEmbeddingModel,
|
|
1793
1811
|
OpenAICompatibleImageModel,
|
|
1794
1812
|
VERSION,
|
|
1795
1813
|
createOpenAICompatible
|
|
1796
|
-
}
|
|
1814
|
+
};
|
|
1797
1815
|
//# sourceMappingURL=index.js.map
|