@openrouter/ai-sdk-provider 2.2.1 → 2.2.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/dist/index.js +48 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -17
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +47 -16
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +47 -16
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2430,23 +2430,34 @@ function isUrl({
|
|
|
2430
2430
|
}
|
|
2431
2431
|
|
|
2432
2432
|
// src/chat/file-url-utils.ts
|
|
2433
|
-
function
|
|
2434
|
-
|
|
2433
|
+
function buildFileDataUrl({
|
|
2434
|
+
data,
|
|
2435
|
+
mediaType,
|
|
2435
2436
|
defaultMediaType
|
|
2436
2437
|
}) {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
return `data:${(_a16 = part.mediaType) != null ? _a16 : defaultMediaType};base64,${base64}`;
|
|
2438
|
+
if (data instanceof Uint8Array) {
|
|
2439
|
+
const base64 = convertUint8ArrayToBase64(data);
|
|
2440
|
+
return `data:${mediaType != null ? mediaType : defaultMediaType};base64,${base64}`;
|
|
2441
2441
|
}
|
|
2442
|
-
const
|
|
2442
|
+
const stringData = data.toString();
|
|
2443
2443
|
if (isUrl({
|
|
2444
|
-
url:
|
|
2444
|
+
url: stringData,
|
|
2445
2445
|
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
2446
2446
|
})) {
|
|
2447
|
-
return
|
|
2447
|
+
return stringData;
|
|
2448
2448
|
}
|
|
2449
|
-
return
|
|
2449
|
+
return stringData.startsWith("data:") ? stringData : `data:${mediaType != null ? mediaType : defaultMediaType};base64,${stringData}`;
|
|
2450
|
+
}
|
|
2451
|
+
function getFileUrl({
|
|
2452
|
+
part,
|
|
2453
|
+
defaultMediaType
|
|
2454
|
+
}) {
|
|
2455
|
+
const data = part.data instanceof URL ? part.data.toString() : part.data;
|
|
2456
|
+
return buildFileDataUrl({
|
|
2457
|
+
data,
|
|
2458
|
+
mediaType: part.mediaType,
|
|
2459
|
+
defaultMediaType
|
|
2460
|
+
});
|
|
2450
2461
|
}
|
|
2451
2462
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
2452
2463
|
var _a16;
|
|
@@ -4403,11 +4414,6 @@ var OpenRouterImageModel = class {
|
|
|
4403
4414
|
} = options;
|
|
4404
4415
|
const openrouterOptions = (providerOptions == null ? void 0 : providerOptions.openrouter) || {};
|
|
4405
4416
|
const warnings = [];
|
|
4406
|
-
if (files !== void 0 && files.length > 0) {
|
|
4407
|
-
throw new UnsupportedFunctionalityError({
|
|
4408
|
-
functionality: "image editing (files parameter)"
|
|
4409
|
-
});
|
|
4410
|
-
}
|
|
4411
4417
|
if (mask !== void 0) {
|
|
4412
4418
|
throw new UnsupportedFunctionalityError({
|
|
4413
4419
|
functionality: "image inpainting (mask parameter)"
|
|
@@ -4428,12 +4434,19 @@ var OpenRouterImageModel = class {
|
|
|
4428
4434
|
});
|
|
4429
4435
|
}
|
|
4430
4436
|
const imageConfig = aspectRatio !== void 0 ? { aspect_ratio: aspectRatio } : void 0;
|
|
4437
|
+
const hasFiles = files !== void 0 && files.length > 0;
|
|
4438
|
+
const userContent = hasFiles ? [
|
|
4439
|
+
...files.map(
|
|
4440
|
+
(file) => convertImageFileToContentPart(file)
|
|
4441
|
+
),
|
|
4442
|
+
{ type: "text", text: prompt != null ? prompt : "" }
|
|
4443
|
+
] : prompt != null ? prompt : "";
|
|
4431
4444
|
const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
4432
4445
|
model: this.modelId,
|
|
4433
4446
|
messages: [
|
|
4434
4447
|
{
|
|
4435
4448
|
role: "user",
|
|
4436
|
-
content:
|
|
4449
|
+
content: userContent
|
|
4437
4450
|
}
|
|
4438
4451
|
],
|
|
4439
4452
|
modalities: ["image", "text"]
|
|
@@ -4484,6 +4497,24 @@ var OpenRouterImageModel = class {
|
|
|
4484
4497
|
};
|
|
4485
4498
|
}
|
|
4486
4499
|
};
|
|
4500
|
+
var DEFAULT_IMAGE_MEDIA_TYPE = "image/png";
|
|
4501
|
+
function convertImageFileToContentPart(file) {
|
|
4502
|
+
if (file.type === "url") {
|
|
4503
|
+
return {
|
|
4504
|
+
type: "image_url",
|
|
4505
|
+
image_url: { url: file.url }
|
|
4506
|
+
};
|
|
4507
|
+
}
|
|
4508
|
+
const url = buildFileDataUrl({
|
|
4509
|
+
data: file.data,
|
|
4510
|
+
mediaType: file.mediaType,
|
|
4511
|
+
defaultMediaType: DEFAULT_IMAGE_MEDIA_TYPE
|
|
4512
|
+
});
|
|
4513
|
+
return {
|
|
4514
|
+
type: "image_url",
|
|
4515
|
+
image_url: { url }
|
|
4516
|
+
};
|
|
4517
|
+
}
|
|
4487
4518
|
|
|
4488
4519
|
// src/utils/remove-undefined.ts
|
|
4489
4520
|
function removeUndefinedEntries(record) {
|
|
@@ -4526,7 +4557,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
4526
4557
|
}
|
|
4527
4558
|
|
|
4528
4559
|
// src/version.ts
|
|
4529
|
-
var VERSION2 = false ? "0.0.0-test" : "2.2.
|
|
4560
|
+
var VERSION2 = false ? "0.0.0-test" : "2.2.2";
|
|
4530
4561
|
|
|
4531
4562
|
// src/provider.ts
|
|
4532
4563
|
function createOpenRouter(options = {}) {
|