@llmgateway/ai-sdk-provider 3.6.0 → 3.8.0
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/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +53 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +8 -2
- package/dist/internal/index.d.ts +8 -2
- package/dist/internal/index.js +51 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +51 -3
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -94,7 +94,9 @@ type LLMGatewayCompletionSettings = {
|
|
|
94
94
|
} & LLMGatewaySharedSettings;
|
|
95
95
|
|
|
96
96
|
type LLMGatewayImageModelId = string;
|
|
97
|
-
type LLMGatewayImageSettings = {
|
|
97
|
+
type LLMGatewayImageSettings = {
|
|
98
|
+
extraBody?: Record<string, unknown>;
|
|
99
|
+
};
|
|
98
100
|
|
|
99
101
|
type LLMGatewayCompletionConfig = {
|
|
100
102
|
provider: string;
|
|
@@ -128,6 +130,10 @@ type LLMGatewayImageConfig = {
|
|
|
128
130
|
path: string;
|
|
129
131
|
}) => string;
|
|
130
132
|
fetch?: typeof fetch;
|
|
133
|
+
extraBody?: Record<string, unknown>;
|
|
134
|
+
};
|
|
135
|
+
type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
|
|
136
|
+
quality?: string;
|
|
131
137
|
};
|
|
132
138
|
declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
133
139
|
readonly specificationVersion: "v3";
|
|
@@ -137,7 +143,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
|
137
143
|
readonly settings: LLMGatewayImageSettings;
|
|
138
144
|
private readonly config;
|
|
139
145
|
constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
|
|
140
|
-
doGenerate(options:
|
|
146
|
+
doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
|
|
141
147
|
images: Array<string>;
|
|
142
148
|
warnings: Array<SharedV3Warning>;
|
|
143
149
|
response: {
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -94,7 +94,9 @@ type LLMGatewayCompletionSettings = {
|
|
|
94
94
|
} & LLMGatewaySharedSettings;
|
|
95
95
|
|
|
96
96
|
type LLMGatewayImageModelId = string;
|
|
97
|
-
type LLMGatewayImageSettings = {
|
|
97
|
+
type LLMGatewayImageSettings = {
|
|
98
|
+
extraBody?: Record<string, unknown>;
|
|
99
|
+
};
|
|
98
100
|
|
|
99
101
|
type LLMGatewayCompletionConfig = {
|
|
100
102
|
provider: string;
|
|
@@ -128,6 +130,10 @@ type LLMGatewayImageConfig = {
|
|
|
128
130
|
path: string;
|
|
129
131
|
}) => string;
|
|
130
132
|
fetch?: typeof fetch;
|
|
133
|
+
extraBody?: Record<string, unknown>;
|
|
134
|
+
};
|
|
135
|
+
type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
|
|
136
|
+
quality?: string;
|
|
131
137
|
};
|
|
132
138
|
declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
133
139
|
readonly specificationVersion: "v3";
|
|
@@ -137,7 +143,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
|
137
143
|
readonly settings: LLMGatewayImageSettings;
|
|
138
144
|
private readonly config;
|
|
139
145
|
constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
|
|
140
|
-
doGenerate(options:
|
|
146
|
+
doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
|
|
141
147
|
images: Array<string>;
|
|
142
148
|
warnings: Array<SharedV3Warning>;
|
|
143
149
|
response: {
|
package/dist/internal/index.js
CHANGED
|
@@ -2275,6 +2275,29 @@ function getBase64FromDataUrl(dataUrl) {
|
|
|
2275
2275
|
}
|
|
2276
2276
|
|
|
2277
2277
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
2278
|
+
var AUDIO_FORMAT_BY_MIME = {
|
|
2279
|
+
"audio/wav": "wav",
|
|
2280
|
+
"audio/wave": "wav",
|
|
2281
|
+
"audio/x-wav": "wav",
|
|
2282
|
+
"audio/mpeg": "mp3",
|
|
2283
|
+
"audio/mp3": "mp3",
|
|
2284
|
+
"audio/mp4": "mp4",
|
|
2285
|
+
"audio/m4a": "m4a",
|
|
2286
|
+
"audio/x-m4a": "m4a",
|
|
2287
|
+
"audio/aac": "aac",
|
|
2288
|
+
"audio/ogg": "ogg",
|
|
2289
|
+
"audio/flac": "flac",
|
|
2290
|
+
"audio/aiff": "aiff",
|
|
2291
|
+
"audio/x-aiff": "aiff",
|
|
2292
|
+
"audio/webm": "webm"
|
|
2293
|
+
};
|
|
2294
|
+
function audioFormatFromMime(mime) {
|
|
2295
|
+
var _a16;
|
|
2296
|
+
if (!mime) return void 0;
|
|
2297
|
+
const lower = (_a16 = mime.toLowerCase().split(";")[0]) == null ? void 0 : _a16.trim();
|
|
2298
|
+
if (!lower) return void 0;
|
|
2299
|
+
return AUDIO_FORMAT_BY_MIME[lower];
|
|
2300
|
+
}
|
|
2278
2301
|
function getCacheControl(providerOptions) {
|
|
2279
2302
|
var _a16, _b16, _c;
|
|
2280
2303
|
const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
@@ -2313,7 +2336,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2313
2336
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
2314
2337
|
const contentParts = content.map(
|
|
2315
2338
|
(part) => {
|
|
2316
|
-
var _a17, _b17, _c2, _d, _e, _f;
|
|
2339
|
+
var _a17, _b17, _c2, _d, _e, _f, _g;
|
|
2317
2340
|
const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
|
|
2318
2341
|
switch (part.type) {
|
|
2319
2342
|
case "text":
|
|
@@ -2338,8 +2361,27 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2338
2361
|
cache_control: cacheControl
|
|
2339
2362
|
};
|
|
2340
2363
|
}
|
|
2364
|
+
if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
|
|
2365
|
+
const format = audioFormatFromMime(part.mediaType);
|
|
2366
|
+
if (format) {
|
|
2367
|
+
const fileUrl = getFileUrl({
|
|
2368
|
+
part,
|
|
2369
|
+
defaultMediaType: part.mediaType
|
|
2370
|
+
});
|
|
2371
|
+
if (fileUrl.startsWith("data:")) {
|
|
2372
|
+
return {
|
|
2373
|
+
type: "input_audio",
|
|
2374
|
+
input_audio: {
|
|
2375
|
+
data: getBase64FromDataUrl(fileUrl),
|
|
2376
|
+
format
|
|
2377
|
+
},
|
|
2378
|
+
cache_control: cacheControl
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2341
2383
|
const fileName = String(
|
|
2342
|
-
(
|
|
2384
|
+
(_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.llmgateway) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
|
|
2343
2385
|
);
|
|
2344
2386
|
const fileData = getFileUrl({
|
|
2345
2387
|
part,
|
|
@@ -3626,13 +3668,19 @@ var LLMGatewayImageModel = class {
|
|
|
3626
3668
|
if (options.aspectRatio != null) {
|
|
3627
3669
|
body.aspect_ratio = options.aspectRatio;
|
|
3628
3670
|
}
|
|
3671
|
+
if (options.quality != null) {
|
|
3672
|
+
body.quality = options.quality;
|
|
3673
|
+
}
|
|
3674
|
+
const providerOptions = options.providerOptions || {};
|
|
3675
|
+
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
3676
|
+
const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, body), this.config.extraBody), this.settings.extraBody), llmgatewayOptions);
|
|
3629
3677
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
3630
3678
|
url: this.config.url({
|
|
3631
3679
|
path: hasFiles ? "/images/edits" : "/images/generations",
|
|
3632
3680
|
modelId: this.modelId
|
|
3633
3681
|
}),
|
|
3634
3682
|
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3635
|
-
body,
|
|
3683
|
+
body: requestBody,
|
|
3636
3684
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
3637
3685
|
successfulResponseHandler: createJsonResponseHandler(
|
|
3638
3686
|
LLMGatewayImageResponseSchema
|