@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 CHANGED
@@ -18,7 +18,7 @@ type OpenRouterChatSettings = {
18
18
  token from being generated.
19
19
  */
20
20
  logitBias?: Record<number, number>;
21
- /**s
21
+ /**
22
22
  Return the log probabilities of the tokens. Including logprobs will increase
23
23
  the response size and can slow down response times. However, it can
24
24
  be useful to better understand how the model is behaving.
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ type OpenRouterChatSettings = {
18
18
  token from being generated.
19
19
  */
20
20
  logitBias?: Record<number, number>;
21
- /**s
21
+ /**
22
22
  Return the log probabilities of the tokens. Including logprobs will increase
23
23
  the response size and can slow down response times. However, it can
24
24
  be useful to better understand how the model is behaving.
package/dist/index.js CHANGED
@@ -447,28 +447,28 @@ var EventSourceParserStream = class extends TransformStream {
447
447
  }
448
448
  };
449
449
 
450
- // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@4.0.5/node_modules/@ai-sdk/provider-utils/dist/index.mjs
450
+ // 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
451
451
  var z4 = __toESM(require("zod/v4"), 1);
452
452
 
453
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/Options.js
453
+ // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
454
454
  var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
455
455
 
456
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/selectParser.js
456
+ // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
457
457
  var import_zod4 = require("zod");
458
458
 
459
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
459
+ // 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
460
460
  var import_zod = require("zod");
461
461
 
462
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
462
+ // 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
463
463
  var import_zod2 = require("zod");
464
464
 
465
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
465
+ // 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
466
466
  var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
467
467
 
468
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
468
+ // 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
469
469
  var import_zod3 = require("zod");
470
470
 
471
- // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@4.0.5/node_modules/@ai-sdk/provider-utils/dist/index.mjs
471
+ // 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
472
472
  function combineHeaders(...headers) {
473
473
  return headers.reduce(
474
474
  (combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
@@ -978,6 +978,39 @@ function mapOpenRouterFinishReason(finishReason) {
978
978
  }
979
979
  }
980
980
 
981
+ // src/chat/is-url.ts
982
+ function isUrl({
983
+ url,
984
+ protocols
985
+ }) {
986
+ try {
987
+ const urlObj = new URL(url);
988
+ return protocols.has(urlObj.protocol);
989
+ } catch (_) {
990
+ return false;
991
+ }
992
+ }
993
+
994
+ // src/chat/file-url-utils.ts
995
+ function getFileUrl({
996
+ part,
997
+ defaultMediaType
998
+ }) {
999
+ var _a15, _b;
1000
+ if (part.data instanceof Uint8Array) {
1001
+ const base64 = convertUint8ArrayToBase64(part.data);
1002
+ return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
1003
+ }
1004
+ const stringUrl = part.data.toString();
1005
+ if (isUrl({
1006
+ url: stringUrl,
1007
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1008
+ })) {
1009
+ return stringUrl;
1010
+ }
1011
+ return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
1012
+ }
1013
+
981
1014
  // src/chat/convert-to-openrouter-chat-messages.ts
982
1015
  function getCacheControl(providerMetadata) {
983
1016
  var _a15, _b, _c;
@@ -1017,7 +1050,7 @@ function convertToOpenRouterChatMessages(prompt) {
1017
1050
  const messageCacheControl = getCacheControl(providerOptions);
1018
1051
  const contentParts = content.map(
1019
1052
  (part) => {
1020
- var _a16, _b2, _c2, _d, _e, _f, _g;
1053
+ var _a16, _b2, _c2, _d, _e, _f;
1021
1054
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1022
1055
  switch (part.type) {
1023
1056
  case "text":
@@ -1027,29 +1060,49 @@ function convertToOpenRouterChatMessages(prompt) {
1027
1060
  // For text parts, only use part-specific cache control
1028
1061
  cache_control: cacheControl
1029
1062
  };
1030
- case "file":
1063
+ case "file": {
1031
1064
  if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
1065
+ const url = getFileUrl({
1066
+ part,
1067
+ defaultMediaType: "image/jpeg"
1068
+ });
1032
1069
  return {
1033
1070
  type: "image_url",
1034
1071
  image_url: {
1035
- url: part.data instanceof URL ? part.data.toString() : `data:${(_c2 = part.mediaType) != null ? _c2 : "image/jpeg"};base64,${convertUint8ArrayToBase64(
1036
- part.data instanceof Uint8Array ? part.data : new Uint8Array()
1037
- )}`
1072
+ url
1038
1073
  },
1039
1074
  // For image parts, use part-specific or message-level cache control
1040
1075
  cache_control: cacheControl
1041
1076
  };
1042
1077
  }
1078
+ const fileName = String(
1079
+ (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
1080
+ );
1081
+ const fileData = getFileUrl({
1082
+ part,
1083
+ defaultMediaType: "application/pdf"
1084
+ });
1085
+ if (isUrl({
1086
+ url: fileData,
1087
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1088
+ })) {
1089
+ return {
1090
+ type: "file",
1091
+ file: {
1092
+ filename: fileName,
1093
+ file_data: fileData
1094
+ }
1095
+ };
1096
+ }
1043
1097
  return {
1044
1098
  type: "file",
1045
1099
  file: {
1046
- filename: String(
1047
- (_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
1048
- ),
1049
- file_data: part.data instanceof Uint8Array ? `data:${part.mediaType};base64,${convertUint8ArrayToBase64(part.data)}` : `data:${part.mediaType};base64,${part.data}`
1100
+ filename: fileName,
1101
+ file_data: fileData
1050
1102
  },
1051
1103
  cache_control: cacheControl
1052
1104
  };
1105
+ }
1053
1106
  default: {
1054
1107
  return {
1055
1108
  type: "text",
@@ -1387,15 +1440,13 @@ var OpenRouterChatLanguageModel = class {
1387
1440
  cachedInputTokens: 0
1388
1441
  };
1389
1442
  const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
1390
- reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
1391
- var _a16;
1443
+ const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
1392
1444
  switch (detail.type) {
1393
1445
  case "reasoning.text" /* Text */: {
1394
1446
  if (detail.text) {
1395
1447
  return {
1396
- type: "text",
1397
- text: detail.text,
1398
- signature: (_a16 = detail.signature) != null ? _a16 : void 0
1448
+ type: "reasoning",
1449
+ text: detail.text
1399
1450
  };
1400
1451
  }
1401
1452
  break;
@@ -1403,7 +1454,7 @@ var OpenRouterChatLanguageModel = class {
1403
1454
  case "reasoning.summary" /* Summary */: {
1404
1455
  if (detail.summary) {
1405
1456
  return {
1406
- type: "text",
1457
+ type: "reasoning",
1407
1458
  text: detail.summary
1408
1459
  };
1409
1460
  }
@@ -1412,8 +1463,8 @@ var OpenRouterChatLanguageModel = class {
1412
1463
  case "reasoning.encrypted" /* Encrypted */: {
1413
1464
  if (detail.data) {
1414
1465
  return {
1415
- type: "redacted",
1416
- data: detail.data
1466
+ type: "reasoning",
1467
+ text: "[REDACTED]"
1417
1468
  };
1418
1469
  }
1419
1470
  break;
@@ -1425,11 +1476,12 @@ var OpenRouterChatLanguageModel = class {
1425
1476
  return null;
1426
1477
  }).filter((p) => p !== null) : choice.message.reasoning ? [
1427
1478
  {
1428
- type: "text",
1479
+ type: "reasoning",
1429
1480
  text: choice.message.reasoning
1430
1481
  }
1431
1482
  ] : [];
1432
1483
  const content = [];
1484
+ content.push(...reasoning);
1433
1485
  if (choice.message.content) {
1434
1486
  content.push({
1435
1487
  type: "text",
@@ -1522,7 +1574,7 @@ var OpenRouterChatLanguageModel = class {
1522
1574
  stream: response.pipeThrough(
1523
1575
  new TransformStream({
1524
1576
  transform(chunk, controller) {
1525
- var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1577
+ var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1526
1578
  if (!chunk.success) {
1527
1579
  finishReason = "error";
1528
1580
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1668,6 +1720,7 @@ var OpenRouterChatLanguageModel = class {
1668
1720
  name: toolCallDelta.function.name,
1669
1721
  arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
1670
1722
  },
1723
+ inputStarted: false,
1671
1724
  sent: false
1672
1725
  };
1673
1726
  const toolCall2 = toolCalls[index];
@@ -1675,6 +1728,7 @@ var OpenRouterChatLanguageModel = class {
1675
1728
  throw new Error("Tool call is missing");
1676
1729
  }
1677
1730
  if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
1731
+ toolCall2.inputStarted = true;
1678
1732
  controller.enqueue({
1679
1733
  type: "tool-input-start",
1680
1734
  id: toolCall2.id,
@@ -1703,25 +1757,26 @@ var OpenRouterChatLanguageModel = class {
1703
1757
  if (toolCall == null) {
1704
1758
  throw new Error("Tool call is missing");
1705
1759
  }
1706
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
1760
+ if (!toolCall.inputStarted) {
1761
+ toolCall.inputStarted = true;
1707
1762
  controller.enqueue({
1708
1763
  type: "tool-input-start",
1709
1764
  id: toolCall.id,
1710
1765
  toolName: toolCall.function.name
1711
1766
  });
1712
1767
  }
1713
- if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
1714
- toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
1768
+ if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
1769
+ toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
1715
1770
  }
1716
1771
  controller.enqueue({
1717
1772
  type: "tool-input-delta",
1718
1773
  id: toolCall.id,
1719
- delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
1774
+ delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
1720
1775
  });
1721
- if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1776
+ if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1722
1777
  controller.enqueue({
1723
1778
  type: "tool-call",
1724
- toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
1779
+ toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
1725
1780
  toolName: toolCall.function.name,
1726
1781
  input: toolCall.function.arguments
1727
1782
  });
@@ -1747,10 +1802,16 @@ var OpenRouterChatLanguageModel = class {
1747
1802
  }
1748
1803
  }
1749
1804
  if (textStarted) {
1750
- controller.enqueue({ type: "text-end", id: textId || generateId() });
1805
+ controller.enqueue({
1806
+ type: "text-end",
1807
+ id: textId || generateId()
1808
+ });
1751
1809
  }
1752
1810
  if (reasoningStarted) {
1753
- controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
1811
+ controller.enqueue({
1812
+ type: "reasoning-end",
1813
+ id: reasoningId || generateId()
1814
+ });
1754
1815
  }
1755
1816
  controller.enqueue({
1756
1817
  type: "finish",