@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/internal/index.mjs
CHANGED
|
@@ -402,28 +402,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
404
|
|
|
405
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@
|
|
405
|
+
// 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
|
|
406
406
|
import * as z4 from "zod/v4";
|
|
407
407
|
|
|
408
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
408
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
409
409
|
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
410
410
|
|
|
411
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
411
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
412
412
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
413
413
|
|
|
414
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
414
|
+
// 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
|
|
415
415
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
416
416
|
|
|
417
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
417
|
+
// 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
|
|
418
418
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
419
419
|
|
|
420
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
420
|
+
// 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
|
|
421
421
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
422
422
|
|
|
423
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
423
|
+
// 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
|
|
424
424
|
import { ZodOptional } from "zod";
|
|
425
425
|
|
|
426
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@
|
|
426
|
+
// 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
|
|
427
427
|
function combineHeaders(...headers) {
|
|
428
428
|
return headers.reduce(
|
|
429
429
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -898,6 +898,39 @@ function mapOpenRouterFinishReason(finishReason) {
|
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
+
// src/chat/is-url.ts
|
|
902
|
+
function isUrl({
|
|
903
|
+
url,
|
|
904
|
+
protocols
|
|
905
|
+
}) {
|
|
906
|
+
try {
|
|
907
|
+
const urlObj = new URL(url);
|
|
908
|
+
return protocols.has(urlObj.protocol);
|
|
909
|
+
} catch (_) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/chat/file-url-utils.ts
|
|
915
|
+
function getFileUrl({
|
|
916
|
+
part,
|
|
917
|
+
defaultMediaType
|
|
918
|
+
}) {
|
|
919
|
+
var _a15, _b;
|
|
920
|
+
if (part.data instanceof Uint8Array) {
|
|
921
|
+
const base64 = convertUint8ArrayToBase64(part.data);
|
|
922
|
+
return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
|
|
923
|
+
}
|
|
924
|
+
const stringUrl = part.data.toString();
|
|
925
|
+
if (isUrl({
|
|
926
|
+
url: stringUrl,
|
|
927
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
928
|
+
})) {
|
|
929
|
+
return stringUrl;
|
|
930
|
+
}
|
|
931
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
932
|
+
}
|
|
933
|
+
|
|
901
934
|
// src/chat/convert-to-openrouter-chat-messages.ts
|
|
902
935
|
function getCacheControl(providerMetadata) {
|
|
903
936
|
var _a15, _b, _c;
|
|
@@ -937,7 +970,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
937
970
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
938
971
|
const contentParts = content.map(
|
|
939
972
|
(part) => {
|
|
940
|
-
var _a16, _b2, _c2, _d, _e, _f
|
|
973
|
+
var _a16, _b2, _c2, _d, _e, _f;
|
|
941
974
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
942
975
|
switch (part.type) {
|
|
943
976
|
case "text":
|
|
@@ -947,29 +980,49 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
947
980
|
// For text parts, only use part-specific cache control
|
|
948
981
|
cache_control: cacheControl
|
|
949
982
|
};
|
|
950
|
-
case "file":
|
|
983
|
+
case "file": {
|
|
951
984
|
if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
|
|
985
|
+
const url = getFileUrl({
|
|
986
|
+
part,
|
|
987
|
+
defaultMediaType: "image/jpeg"
|
|
988
|
+
});
|
|
952
989
|
return {
|
|
953
990
|
type: "image_url",
|
|
954
991
|
image_url: {
|
|
955
|
-
url
|
|
956
|
-
part.data instanceof Uint8Array ? part.data : new Uint8Array()
|
|
957
|
-
)}`
|
|
992
|
+
url
|
|
958
993
|
},
|
|
959
994
|
// For image parts, use part-specific or message-level cache control
|
|
960
995
|
cache_control: cacheControl
|
|
961
996
|
};
|
|
962
997
|
}
|
|
998
|
+
const fileName = String(
|
|
999
|
+
(_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
|
|
1000
|
+
);
|
|
1001
|
+
const fileData = getFileUrl({
|
|
1002
|
+
part,
|
|
1003
|
+
defaultMediaType: "application/pdf"
|
|
1004
|
+
});
|
|
1005
|
+
if (isUrl({
|
|
1006
|
+
url: fileData,
|
|
1007
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
1008
|
+
})) {
|
|
1009
|
+
return {
|
|
1010
|
+
type: "file",
|
|
1011
|
+
file: {
|
|
1012
|
+
filename: fileName,
|
|
1013
|
+
file_data: fileData
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
963
1017
|
return {
|
|
964
1018
|
type: "file",
|
|
965
1019
|
file: {
|
|
966
|
-
filename:
|
|
967
|
-
|
|
968
|
-
),
|
|
969
|
-
file_data: part.data instanceof Uint8Array ? `data:${part.mediaType};base64,${convertUint8ArrayToBase64(part.data)}` : `data:${part.mediaType};base64,${part.data}`
|
|
1020
|
+
filename: fileName,
|
|
1021
|
+
file_data: fileData
|
|
970
1022
|
},
|
|
971
1023
|
cache_control: cacheControl
|
|
972
1024
|
};
|
|
1025
|
+
}
|
|
973
1026
|
default: {
|
|
974
1027
|
return {
|
|
975
1028
|
type: "text",
|
|
@@ -1307,15 +1360,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1307
1360
|
cachedInputTokens: 0
|
|
1308
1361
|
};
|
|
1309
1362
|
const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
|
|
1310
|
-
reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1311
|
-
var _a16;
|
|
1363
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1312
1364
|
switch (detail.type) {
|
|
1313
1365
|
case "reasoning.text" /* Text */: {
|
|
1314
1366
|
if (detail.text) {
|
|
1315
1367
|
return {
|
|
1316
|
-
type: "
|
|
1317
|
-
text: detail.text
|
|
1318
|
-
signature: (_a16 = detail.signature) != null ? _a16 : void 0
|
|
1368
|
+
type: "reasoning",
|
|
1369
|
+
text: detail.text
|
|
1319
1370
|
};
|
|
1320
1371
|
}
|
|
1321
1372
|
break;
|
|
@@ -1323,7 +1374,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1323
1374
|
case "reasoning.summary" /* Summary */: {
|
|
1324
1375
|
if (detail.summary) {
|
|
1325
1376
|
return {
|
|
1326
|
-
type: "
|
|
1377
|
+
type: "reasoning",
|
|
1327
1378
|
text: detail.summary
|
|
1328
1379
|
};
|
|
1329
1380
|
}
|
|
@@ -1332,8 +1383,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1332
1383
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1333
1384
|
if (detail.data) {
|
|
1334
1385
|
return {
|
|
1335
|
-
type: "
|
|
1336
|
-
|
|
1386
|
+
type: "reasoning",
|
|
1387
|
+
text: "[REDACTED]"
|
|
1337
1388
|
};
|
|
1338
1389
|
}
|
|
1339
1390
|
break;
|
|
@@ -1345,11 +1396,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1345
1396
|
return null;
|
|
1346
1397
|
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
1347
1398
|
{
|
|
1348
|
-
type: "
|
|
1399
|
+
type: "reasoning",
|
|
1349
1400
|
text: choice.message.reasoning
|
|
1350
1401
|
}
|
|
1351
1402
|
] : [];
|
|
1352
1403
|
const content = [];
|
|
1404
|
+
content.push(...reasoning);
|
|
1353
1405
|
if (choice.message.content) {
|
|
1354
1406
|
content.push({
|
|
1355
1407
|
type: "text",
|
|
@@ -1442,7 +1494,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1442
1494
|
stream: response.pipeThrough(
|
|
1443
1495
|
new TransformStream({
|
|
1444
1496
|
transform(chunk, controller) {
|
|
1445
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
1497
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1446
1498
|
if (!chunk.success) {
|
|
1447
1499
|
finishReason = "error";
|
|
1448
1500
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1588,6 +1640,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1588
1640
|
name: toolCallDelta.function.name,
|
|
1589
1641
|
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1590
1642
|
},
|
|
1643
|
+
inputStarted: false,
|
|
1591
1644
|
sent: false
|
|
1592
1645
|
};
|
|
1593
1646
|
const toolCall2 = toolCalls[index];
|
|
@@ -1595,6 +1648,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1595
1648
|
throw new Error("Tool call is missing");
|
|
1596
1649
|
}
|
|
1597
1650
|
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1651
|
+
toolCall2.inputStarted = true;
|
|
1598
1652
|
controller.enqueue({
|
|
1599
1653
|
type: "tool-input-start",
|
|
1600
1654
|
id: toolCall2.id,
|
|
@@ -1623,25 +1677,26 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1623
1677
|
if (toolCall == null) {
|
|
1624
1678
|
throw new Error("Tool call is missing");
|
|
1625
1679
|
}
|
|
1626
|
-
if (
|
|
1680
|
+
if (!toolCall.inputStarted) {
|
|
1681
|
+
toolCall.inputStarted = true;
|
|
1627
1682
|
controller.enqueue({
|
|
1628
1683
|
type: "tool-input-start",
|
|
1629
1684
|
id: toolCall.id,
|
|
1630
1685
|
toolName: toolCall.function.name
|
|
1631
1686
|
});
|
|
1632
1687
|
}
|
|
1633
|
-
if (((
|
|
1634
|
-
toolCall.function.arguments += (
|
|
1688
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
1689
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
1635
1690
|
}
|
|
1636
1691
|
controller.enqueue({
|
|
1637
1692
|
type: "tool-input-delta",
|
|
1638
1693
|
id: toolCall.id,
|
|
1639
|
-
delta: (
|
|
1694
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
1640
1695
|
});
|
|
1641
|
-
if (((
|
|
1696
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1642
1697
|
controller.enqueue({
|
|
1643
1698
|
type: "tool-call",
|
|
1644
|
-
toolCallId: (
|
|
1699
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
1645
1700
|
toolName: toolCall.function.name,
|
|
1646
1701
|
input: toolCall.function.arguments
|
|
1647
1702
|
});
|
|
@@ -1667,10 +1722,16 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1667
1722
|
}
|
|
1668
1723
|
}
|
|
1669
1724
|
if (textStarted) {
|
|
1670
|
-
controller.enqueue({
|
|
1725
|
+
controller.enqueue({
|
|
1726
|
+
type: "text-end",
|
|
1727
|
+
id: textId || generateId()
|
|
1728
|
+
});
|
|
1671
1729
|
}
|
|
1672
1730
|
if (reasoningStarted) {
|
|
1673
|
-
controller.enqueue({
|
|
1731
|
+
controller.enqueue({
|
|
1732
|
+
type: "reasoning-end",
|
|
1733
|
+
id: reasoningId || generateId()
|
|
1734
|
+
});
|
|
1674
1735
|
}
|
|
1675
1736
|
controller.enqueue({
|
|
1676
1737
|
type: "finish",
|