@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.
@@ -136,7 +136,7 @@ type OpenRouterChatSettings = {
136
136
  token from being generated.
137
137
  */
138
138
  logitBias?: Record<number, number>;
139
- /**s
139
+ /**
140
140
  Return the log probabilities of the tokens. Including logprobs will increase
141
141
  the response size and can slow down response times. However, it can
142
142
  be useful to better understand how the model is behaving.
@@ -136,7 +136,7 @@ type OpenRouterChatSettings = {
136
136
  token from being generated.
137
137
  */
138
138
  logitBias?: Record<number, number>;
139
- /**s
139
+ /**
140
140
  Return the log probabilities of the tokens. Including logprobs will increase
141
141
  the response size and can slow down response times. However, it can
142
142
  be useful to better understand how the model is behaving.
@@ -436,28 +436,28 @@ var EventSourceParserStream = class extends TransformStream {
436
436
  }
437
437
  };
438
438
 
439
- // 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
439
+ // 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
440
440
  var z4 = __toESM(require("zod/v4"), 1);
441
441
 
442
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/Options.js
442
+ // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
443
443
  var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
444
444
 
445
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/selectParser.js
445
+ // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
446
446
  var import_zod4 = require("zod");
447
447
 
448
- // 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
448
+ // 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
449
449
  var import_zod = require("zod");
450
450
 
451
- // 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
451
+ // 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
452
452
  var import_zod2 = require("zod");
453
453
 
454
- // 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
454
+ // 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
455
455
  var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
456
456
 
457
- // 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
457
+ // 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
458
458
  var import_zod3 = require("zod");
459
459
 
460
- // 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
460
+ // 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
461
461
  function combineHeaders(...headers) {
462
462
  return headers.reduce(
463
463
  (combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
@@ -932,6 +932,39 @@ function mapOpenRouterFinishReason(finishReason) {
932
932
  }
933
933
  }
934
934
 
935
+ // src/chat/is-url.ts
936
+ function isUrl({
937
+ url,
938
+ protocols
939
+ }) {
940
+ try {
941
+ const urlObj = new URL(url);
942
+ return protocols.has(urlObj.protocol);
943
+ } catch (_) {
944
+ return false;
945
+ }
946
+ }
947
+
948
+ // src/chat/file-url-utils.ts
949
+ function getFileUrl({
950
+ part,
951
+ defaultMediaType
952
+ }) {
953
+ var _a15, _b;
954
+ if (part.data instanceof Uint8Array) {
955
+ const base64 = convertUint8ArrayToBase64(part.data);
956
+ return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
957
+ }
958
+ const stringUrl = part.data.toString();
959
+ if (isUrl({
960
+ url: stringUrl,
961
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
962
+ })) {
963
+ return stringUrl;
964
+ }
965
+ return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
966
+ }
967
+
935
968
  // src/chat/convert-to-openrouter-chat-messages.ts
936
969
  function getCacheControl(providerMetadata) {
937
970
  var _a15, _b, _c;
@@ -971,7 +1004,7 @@ function convertToOpenRouterChatMessages(prompt) {
971
1004
  const messageCacheControl = getCacheControl(providerOptions);
972
1005
  const contentParts = content.map(
973
1006
  (part) => {
974
- var _a16, _b2, _c2, _d, _e, _f, _g;
1007
+ var _a16, _b2, _c2, _d, _e, _f;
975
1008
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
976
1009
  switch (part.type) {
977
1010
  case "text":
@@ -981,29 +1014,49 @@ function convertToOpenRouterChatMessages(prompt) {
981
1014
  // For text parts, only use part-specific cache control
982
1015
  cache_control: cacheControl
983
1016
  };
984
- case "file":
1017
+ case "file": {
985
1018
  if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
1019
+ const url = getFileUrl({
1020
+ part,
1021
+ defaultMediaType: "image/jpeg"
1022
+ });
986
1023
  return {
987
1024
  type: "image_url",
988
1025
  image_url: {
989
- url: part.data instanceof URL ? part.data.toString() : `data:${(_c2 = part.mediaType) != null ? _c2 : "image/jpeg"};base64,${convertUint8ArrayToBase64(
990
- part.data instanceof Uint8Array ? part.data : new Uint8Array()
991
- )}`
1026
+ url
992
1027
  },
993
1028
  // For image parts, use part-specific or message-level cache control
994
1029
  cache_control: cacheControl
995
1030
  };
996
1031
  }
1032
+ const fileName = String(
1033
+ (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
1034
+ );
1035
+ const fileData = getFileUrl({
1036
+ part,
1037
+ defaultMediaType: "application/pdf"
1038
+ });
1039
+ if (isUrl({
1040
+ url: fileData,
1041
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1042
+ })) {
1043
+ return {
1044
+ type: "file",
1045
+ file: {
1046
+ filename: fileName,
1047
+ file_data: fileData
1048
+ }
1049
+ };
1050
+ }
997
1051
  return {
998
1052
  type: "file",
999
1053
  file: {
1000
- filename: String(
1001
- (_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
1002
- ),
1003
- file_data: part.data instanceof Uint8Array ? `data:${part.mediaType};base64,${convertUint8ArrayToBase64(part.data)}` : `data:${part.mediaType};base64,${part.data}`
1054
+ filename: fileName,
1055
+ file_data: fileData
1004
1056
  },
1005
1057
  cache_control: cacheControl
1006
1058
  };
1059
+ }
1007
1060
  default: {
1008
1061
  return {
1009
1062
  type: "text",
@@ -1341,15 +1394,13 @@ var OpenRouterChatLanguageModel = class {
1341
1394
  cachedInputTokens: 0
1342
1395
  };
1343
1396
  const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
1344
- reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
1345
- var _a16;
1397
+ const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
1346
1398
  switch (detail.type) {
1347
1399
  case "reasoning.text" /* Text */: {
1348
1400
  if (detail.text) {
1349
1401
  return {
1350
- type: "text",
1351
- text: detail.text,
1352
- signature: (_a16 = detail.signature) != null ? _a16 : void 0
1402
+ type: "reasoning",
1403
+ text: detail.text
1353
1404
  };
1354
1405
  }
1355
1406
  break;
@@ -1357,7 +1408,7 @@ var OpenRouterChatLanguageModel = class {
1357
1408
  case "reasoning.summary" /* Summary */: {
1358
1409
  if (detail.summary) {
1359
1410
  return {
1360
- type: "text",
1411
+ type: "reasoning",
1361
1412
  text: detail.summary
1362
1413
  };
1363
1414
  }
@@ -1366,8 +1417,8 @@ var OpenRouterChatLanguageModel = class {
1366
1417
  case "reasoning.encrypted" /* Encrypted */: {
1367
1418
  if (detail.data) {
1368
1419
  return {
1369
- type: "redacted",
1370
- data: detail.data
1420
+ type: "reasoning",
1421
+ text: "[REDACTED]"
1371
1422
  };
1372
1423
  }
1373
1424
  break;
@@ -1379,11 +1430,12 @@ var OpenRouterChatLanguageModel = class {
1379
1430
  return null;
1380
1431
  }).filter((p) => p !== null) : choice.message.reasoning ? [
1381
1432
  {
1382
- type: "text",
1433
+ type: "reasoning",
1383
1434
  text: choice.message.reasoning
1384
1435
  }
1385
1436
  ] : [];
1386
1437
  const content = [];
1438
+ content.push(...reasoning);
1387
1439
  if (choice.message.content) {
1388
1440
  content.push({
1389
1441
  type: "text",
@@ -1476,7 +1528,7 @@ var OpenRouterChatLanguageModel = class {
1476
1528
  stream: response.pipeThrough(
1477
1529
  new TransformStream({
1478
1530
  transform(chunk, controller) {
1479
- var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1531
+ var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1480
1532
  if (!chunk.success) {
1481
1533
  finishReason = "error";
1482
1534
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1622,6 +1674,7 @@ var OpenRouterChatLanguageModel = class {
1622
1674
  name: toolCallDelta.function.name,
1623
1675
  arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
1624
1676
  },
1677
+ inputStarted: false,
1625
1678
  sent: false
1626
1679
  };
1627
1680
  const toolCall2 = toolCalls[index];
@@ -1629,6 +1682,7 @@ var OpenRouterChatLanguageModel = class {
1629
1682
  throw new Error("Tool call is missing");
1630
1683
  }
1631
1684
  if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
1685
+ toolCall2.inputStarted = true;
1632
1686
  controller.enqueue({
1633
1687
  type: "tool-input-start",
1634
1688
  id: toolCall2.id,
@@ -1657,25 +1711,26 @@ var OpenRouterChatLanguageModel = class {
1657
1711
  if (toolCall == null) {
1658
1712
  throw new Error("Tool call is missing");
1659
1713
  }
1660
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
1714
+ if (!toolCall.inputStarted) {
1715
+ toolCall.inputStarted = true;
1661
1716
  controller.enqueue({
1662
1717
  type: "tool-input-start",
1663
1718
  id: toolCall.id,
1664
1719
  toolName: toolCall.function.name
1665
1720
  });
1666
1721
  }
1667
- if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
1668
- toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
1722
+ if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
1723
+ toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
1669
1724
  }
1670
1725
  controller.enqueue({
1671
1726
  type: "tool-input-delta",
1672
1727
  id: toolCall.id,
1673
- delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
1728
+ delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
1674
1729
  });
1675
- if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1730
+ if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1676
1731
  controller.enqueue({
1677
1732
  type: "tool-call",
1678
- toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
1733
+ toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
1679
1734
  toolName: toolCall.function.name,
1680
1735
  input: toolCall.function.arguments
1681
1736
  });
@@ -1701,10 +1756,16 @@ var OpenRouterChatLanguageModel = class {
1701
1756
  }
1702
1757
  }
1703
1758
  if (textStarted) {
1704
- controller.enqueue({ type: "text-end", id: textId || generateId() });
1759
+ controller.enqueue({
1760
+ type: "text-end",
1761
+ id: textId || generateId()
1762
+ });
1705
1763
  }
1706
1764
  if (reasoningStarted) {
1707
- controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
1765
+ controller.enqueue({
1766
+ type: "reasoning-end",
1767
+ id: reasoningId || generateId()
1768
+ });
1708
1769
  }
1709
1770
  controller.enqueue({
1710
1771
  type: "finish",