@openrouter/ai-sdk-provider 1.0.0-beta.3 → 1.0.0-beta.5
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +96 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -35
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +96 -35
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +96 -35
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -412,28 +412,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@
|
|
415
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
416
416
|
import * as z4 from "zod/v4";
|
|
417
417
|
|
|
418
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
418
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
419
419
|
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
420
420
|
|
|
421
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
421
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
422
422
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
423
423
|
|
|
424
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
424
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
425
425
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
426
426
|
|
|
427
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
427
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
428
428
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
429
429
|
|
|
430
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
430
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
431
431
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
432
432
|
|
|
433
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
433
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
434
434
|
import { ZodOptional } from "zod";
|
|
435
435
|
|
|
436
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@
|
|
436
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
437
437
|
function combineHeaders(...headers) {
|
|
438
438
|
return headers.reduce(
|
|
439
439
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -943,6 +943,39 @@ function mapOpenRouterFinishReason(finishReason) {
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
|
|
946
|
+
// src/chat/is-url.ts
|
|
947
|
+
function isUrl({
|
|
948
|
+
url,
|
|
949
|
+
protocols
|
|
950
|
+
}) {
|
|
951
|
+
try {
|
|
952
|
+
const urlObj = new URL(url);
|
|
953
|
+
return protocols.has(urlObj.protocol);
|
|
954
|
+
} catch (_) {
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// src/chat/file-url-utils.ts
|
|
960
|
+
function getFileUrl({
|
|
961
|
+
part,
|
|
962
|
+
defaultMediaType
|
|
963
|
+
}) {
|
|
964
|
+
var _a15, _b;
|
|
965
|
+
if (part.data instanceof Uint8Array) {
|
|
966
|
+
const base64 = convertUint8ArrayToBase64(part.data);
|
|
967
|
+
return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
|
|
968
|
+
}
|
|
969
|
+
const stringUrl = part.data.toString();
|
|
970
|
+
if (isUrl({
|
|
971
|
+
url: stringUrl,
|
|
972
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
973
|
+
})) {
|
|
974
|
+
return stringUrl;
|
|
975
|
+
}
|
|
976
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
977
|
+
}
|
|
978
|
+
|
|
946
979
|
// src/chat/convert-to-openrouter-chat-messages.ts
|
|
947
980
|
function getCacheControl(providerMetadata) {
|
|
948
981
|
var _a15, _b, _c;
|
|
@@ -982,7 +1015,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
982
1015
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
983
1016
|
const contentParts = content.map(
|
|
984
1017
|
(part) => {
|
|
985
|
-
var _a16, _b2, _c2, _d, _e, _f
|
|
1018
|
+
var _a16, _b2, _c2, _d, _e, _f;
|
|
986
1019
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
987
1020
|
switch (part.type) {
|
|
988
1021
|
case "text":
|
|
@@ -992,29 +1025,49 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
992
1025
|
// For text parts, only use part-specific cache control
|
|
993
1026
|
cache_control: cacheControl
|
|
994
1027
|
};
|
|
995
|
-
case "file":
|
|
1028
|
+
case "file": {
|
|
996
1029
|
if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
|
|
1030
|
+
const url = getFileUrl({
|
|
1031
|
+
part,
|
|
1032
|
+
defaultMediaType: "image/jpeg"
|
|
1033
|
+
});
|
|
997
1034
|
return {
|
|
998
1035
|
type: "image_url",
|
|
999
1036
|
image_url: {
|
|
1000
|
-
url
|
|
1001
|
-
part.data instanceof Uint8Array ? part.data : new Uint8Array()
|
|
1002
|
-
)}`
|
|
1037
|
+
url
|
|
1003
1038
|
},
|
|
1004
1039
|
// For image parts, use part-specific or message-level cache control
|
|
1005
1040
|
cache_control: cacheControl
|
|
1006
1041
|
};
|
|
1007
1042
|
}
|
|
1043
|
+
const fileName = String(
|
|
1044
|
+
(_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
|
|
1045
|
+
);
|
|
1046
|
+
const fileData = getFileUrl({
|
|
1047
|
+
part,
|
|
1048
|
+
defaultMediaType: "application/pdf"
|
|
1049
|
+
});
|
|
1050
|
+
if (isUrl({
|
|
1051
|
+
url: fileData,
|
|
1052
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
1053
|
+
})) {
|
|
1054
|
+
return {
|
|
1055
|
+
type: "file",
|
|
1056
|
+
file: {
|
|
1057
|
+
filename: fileName,
|
|
1058
|
+
file_data: fileData
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1008
1062
|
return {
|
|
1009
1063
|
type: "file",
|
|
1010
1064
|
file: {
|
|
1011
|
-
filename:
|
|
1012
|
-
|
|
1013
|
-
),
|
|
1014
|
-
file_data: part.data instanceof Uint8Array ? `data:${part.mediaType};base64,${convertUint8ArrayToBase64(part.data)}` : `data:${part.mediaType};base64,${part.data}`
|
|
1065
|
+
filename: fileName,
|
|
1066
|
+
file_data: fileData
|
|
1015
1067
|
},
|
|
1016
1068
|
cache_control: cacheControl
|
|
1017
1069
|
};
|
|
1070
|
+
}
|
|
1018
1071
|
default: {
|
|
1019
1072
|
return {
|
|
1020
1073
|
type: "text",
|
|
@@ -1352,15 +1405,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1352
1405
|
cachedInputTokens: 0
|
|
1353
1406
|
};
|
|
1354
1407
|
const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
|
|
1355
|
-
reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1356
|
-
var _a16;
|
|
1408
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1357
1409
|
switch (detail.type) {
|
|
1358
1410
|
case "reasoning.text" /* Text */: {
|
|
1359
1411
|
if (detail.text) {
|
|
1360
1412
|
return {
|
|
1361
|
-
type: "
|
|
1362
|
-
text: detail.text
|
|
1363
|
-
signature: (_a16 = detail.signature) != null ? _a16 : void 0
|
|
1413
|
+
type: "reasoning",
|
|
1414
|
+
text: detail.text
|
|
1364
1415
|
};
|
|
1365
1416
|
}
|
|
1366
1417
|
break;
|
|
@@ -1368,7 +1419,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1368
1419
|
case "reasoning.summary" /* Summary */: {
|
|
1369
1420
|
if (detail.summary) {
|
|
1370
1421
|
return {
|
|
1371
|
-
type: "
|
|
1422
|
+
type: "reasoning",
|
|
1372
1423
|
text: detail.summary
|
|
1373
1424
|
};
|
|
1374
1425
|
}
|
|
@@ -1377,8 +1428,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1377
1428
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1378
1429
|
if (detail.data) {
|
|
1379
1430
|
return {
|
|
1380
|
-
type: "
|
|
1381
|
-
|
|
1431
|
+
type: "reasoning",
|
|
1432
|
+
text: "[REDACTED]"
|
|
1382
1433
|
};
|
|
1383
1434
|
}
|
|
1384
1435
|
break;
|
|
@@ -1390,11 +1441,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1390
1441
|
return null;
|
|
1391
1442
|
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
1392
1443
|
{
|
|
1393
|
-
type: "
|
|
1444
|
+
type: "reasoning",
|
|
1394
1445
|
text: choice.message.reasoning
|
|
1395
1446
|
}
|
|
1396
1447
|
] : [];
|
|
1397
1448
|
const content = [];
|
|
1449
|
+
content.push(...reasoning);
|
|
1398
1450
|
if (choice.message.content) {
|
|
1399
1451
|
content.push({
|
|
1400
1452
|
type: "text",
|
|
@@ -1487,7 +1539,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1487
1539
|
stream: response.pipeThrough(
|
|
1488
1540
|
new TransformStream({
|
|
1489
1541
|
transform(chunk, controller) {
|
|
1490
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
1542
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1491
1543
|
if (!chunk.success) {
|
|
1492
1544
|
finishReason = "error";
|
|
1493
1545
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1633,6 +1685,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1633
1685
|
name: toolCallDelta.function.name,
|
|
1634
1686
|
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1635
1687
|
},
|
|
1688
|
+
inputStarted: false,
|
|
1636
1689
|
sent: false
|
|
1637
1690
|
};
|
|
1638
1691
|
const toolCall2 = toolCalls[index];
|
|
@@ -1640,6 +1693,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1640
1693
|
throw new Error("Tool call is missing");
|
|
1641
1694
|
}
|
|
1642
1695
|
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1696
|
+
toolCall2.inputStarted = true;
|
|
1643
1697
|
controller.enqueue({
|
|
1644
1698
|
type: "tool-input-start",
|
|
1645
1699
|
id: toolCall2.id,
|
|
@@ -1668,25 +1722,26 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1668
1722
|
if (toolCall == null) {
|
|
1669
1723
|
throw new Error("Tool call is missing");
|
|
1670
1724
|
}
|
|
1671
|
-
if (
|
|
1725
|
+
if (!toolCall.inputStarted) {
|
|
1726
|
+
toolCall.inputStarted = true;
|
|
1672
1727
|
controller.enqueue({
|
|
1673
1728
|
type: "tool-input-start",
|
|
1674
1729
|
id: toolCall.id,
|
|
1675
1730
|
toolName: toolCall.function.name
|
|
1676
1731
|
});
|
|
1677
1732
|
}
|
|
1678
|
-
if (((
|
|
1679
|
-
toolCall.function.arguments += (
|
|
1733
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
1734
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
1680
1735
|
}
|
|
1681
1736
|
controller.enqueue({
|
|
1682
1737
|
type: "tool-input-delta",
|
|
1683
1738
|
id: toolCall.id,
|
|
1684
|
-
delta: (
|
|
1739
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
1685
1740
|
});
|
|
1686
|
-
if (((
|
|
1741
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1687
1742
|
controller.enqueue({
|
|
1688
1743
|
type: "tool-call",
|
|
1689
|
-
toolCallId: (
|
|
1744
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
1690
1745
|
toolName: toolCall.function.name,
|
|
1691
1746
|
input: toolCall.function.arguments
|
|
1692
1747
|
});
|
|
@@ -1712,10 +1767,16 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1712
1767
|
}
|
|
1713
1768
|
}
|
|
1714
1769
|
if (textStarted) {
|
|
1715
|
-
controller.enqueue({
|
|
1770
|
+
controller.enqueue({
|
|
1771
|
+
type: "text-end",
|
|
1772
|
+
id: textId || generateId()
|
|
1773
|
+
});
|
|
1716
1774
|
}
|
|
1717
1775
|
if (reasoningStarted) {
|
|
1718
|
-
controller.enqueue({
|
|
1776
|
+
controller.enqueue({
|
|
1777
|
+
type: "reasoning-end",
|
|
1778
|
+
id: reasoningId || generateId()
|
|
1779
|
+
});
|
|
1719
1780
|
}
|
|
1720
1781
|
controller.enqueue({
|
|
1721
1782
|
type: "finish",
|