@openrouter/ai-sdk-provider 1.0.0-beta.3 → 1.0.0-beta.4
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 +80 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -18
- 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 +106 -44
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +106 -44
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -136,7 +136,7 @@ type OpenRouterChatSettings = {
|
|
|
136
136
|
token from being generated.
|
|
137
137
|
*/
|
|
138
138
|
logitBias?: Record<number, number>;
|
|
139
|
-
/**
|
|
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.
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ type OpenRouterChatSettings = {
|
|
|
136
136
|
token from being generated.
|
|
137
137
|
*/
|
|
138
138
|
logitBias?: Record<number, number>;
|
|
139
|
-
/**
|
|
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.
|
package/dist/internal/index.js
CHANGED
|
@@ -52,6 +52,32 @@ __export(index_exports, {
|
|
|
52
52
|
});
|
|
53
53
|
module.exports = __toCommonJS(index_exports);
|
|
54
54
|
|
|
55
|
+
// src/schemas/reasoning-details.ts
|
|
56
|
+
var import_v4 = require("zod/v4");
|
|
57
|
+
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
58
|
+
type: import_v4.z.literal("reasoning.summary" /* Summary */),
|
|
59
|
+
summary: import_v4.z.string()
|
|
60
|
+
});
|
|
61
|
+
var ReasoningDetailEncryptedSchema = import_v4.z.object({
|
|
62
|
+
type: import_v4.z.literal("reasoning.encrypted" /* Encrypted */),
|
|
63
|
+
data: import_v4.z.string()
|
|
64
|
+
});
|
|
65
|
+
var ReasoningDetailTextSchema = import_v4.z.object({
|
|
66
|
+
type: import_v4.z.literal("reasoning.text" /* Text */),
|
|
67
|
+
text: import_v4.z.string().nullish(),
|
|
68
|
+
signature: import_v4.z.string().nullish()
|
|
69
|
+
});
|
|
70
|
+
var ReasoningDetailUnionSchema = import_v4.z.union([
|
|
71
|
+
ReasoningDetailSummarySchema,
|
|
72
|
+
ReasoningDetailEncryptedSchema,
|
|
73
|
+
ReasoningDetailTextSchema
|
|
74
|
+
]);
|
|
75
|
+
var ReasoningDetailsWithUnknownSchema = import_v4.z.union([
|
|
76
|
+
ReasoningDetailUnionSchema,
|
|
77
|
+
import_v4.z.unknown().transform(() => null)
|
|
78
|
+
]);
|
|
79
|
+
var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
80
|
+
|
|
55
81
|
// node_modules/.pnpm/@ai-sdk+provider@2.0.0-beta.1/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
56
82
|
var marker = "vercel.ai.error";
|
|
57
83
|
var symbol = Symbol.for(marker);
|
|
@@ -874,32 +900,6 @@ function convertUint8ArrayToBase64(array) {
|
|
|
874
900
|
return btoa(latin1string);
|
|
875
901
|
}
|
|
876
902
|
|
|
877
|
-
// src/schemas/reasoning-details.ts
|
|
878
|
-
var import_v4 = require("zod/v4");
|
|
879
|
-
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
880
|
-
type: import_v4.z.literal("reasoning.summary" /* Summary */),
|
|
881
|
-
summary: import_v4.z.string()
|
|
882
|
-
});
|
|
883
|
-
var ReasoningDetailEncryptedSchema = import_v4.z.object({
|
|
884
|
-
type: import_v4.z.literal("reasoning.encrypted" /* Encrypted */),
|
|
885
|
-
data: import_v4.z.string()
|
|
886
|
-
});
|
|
887
|
-
var ReasoningDetailTextSchema = import_v4.z.object({
|
|
888
|
-
type: import_v4.z.literal("reasoning.text" /* Text */),
|
|
889
|
-
text: import_v4.z.string().nullish(),
|
|
890
|
-
signature: import_v4.z.string().nullish()
|
|
891
|
-
});
|
|
892
|
-
var ReasoningDetailUnionSchema = import_v4.z.union([
|
|
893
|
-
ReasoningDetailSummarySchema,
|
|
894
|
-
ReasoningDetailEncryptedSchema,
|
|
895
|
-
ReasoningDetailTextSchema
|
|
896
|
-
]);
|
|
897
|
-
var ReasoningDetailsWithUnknownSchema = import_v4.z.union([
|
|
898
|
-
ReasoningDetailUnionSchema,
|
|
899
|
-
import_v4.z.unknown().transform(() => null)
|
|
900
|
-
]);
|
|
901
|
-
var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
902
|
-
|
|
903
903
|
// src/schemas/error-response.ts
|
|
904
904
|
var import_v42 = require("zod/v4");
|
|
905
905
|
var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
@@ -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
|
|
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
|
|
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:
|
|
1001
|
-
|
|
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",
|
|
@@ -1476,7 +1529,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1476
1529
|
stream: response.pipeThrough(
|
|
1477
1530
|
new TransformStream({
|
|
1478
1531
|
transform(chunk, controller) {
|
|
1479
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
1532
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1480
1533
|
if (!chunk.success) {
|
|
1481
1534
|
finishReason = "error";
|
|
1482
1535
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1622,6 +1675,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1622
1675
|
name: toolCallDelta.function.name,
|
|
1623
1676
|
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1624
1677
|
},
|
|
1678
|
+
inputStarted: false,
|
|
1625
1679
|
sent: false
|
|
1626
1680
|
};
|
|
1627
1681
|
const toolCall2 = toolCalls[index];
|
|
@@ -1629,6 +1683,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1629
1683
|
throw new Error("Tool call is missing");
|
|
1630
1684
|
}
|
|
1631
1685
|
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1686
|
+
toolCall2.inputStarted = true;
|
|
1632
1687
|
controller.enqueue({
|
|
1633
1688
|
type: "tool-input-start",
|
|
1634
1689
|
id: toolCall2.id,
|
|
@@ -1657,25 +1712,26 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1657
1712
|
if (toolCall == null) {
|
|
1658
1713
|
throw new Error("Tool call is missing");
|
|
1659
1714
|
}
|
|
1660
|
-
if (
|
|
1715
|
+
if (!toolCall.inputStarted) {
|
|
1716
|
+
toolCall.inputStarted = true;
|
|
1661
1717
|
controller.enqueue({
|
|
1662
1718
|
type: "tool-input-start",
|
|
1663
1719
|
id: toolCall.id,
|
|
1664
1720
|
toolName: toolCall.function.name
|
|
1665
1721
|
});
|
|
1666
1722
|
}
|
|
1667
|
-
if (((
|
|
1668
|
-
toolCall.function.arguments += (
|
|
1723
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
1724
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
1669
1725
|
}
|
|
1670
1726
|
controller.enqueue({
|
|
1671
1727
|
type: "tool-input-delta",
|
|
1672
1728
|
id: toolCall.id,
|
|
1673
|
-
delta: (
|
|
1729
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
1674
1730
|
});
|
|
1675
|
-
if (((
|
|
1731
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1676
1732
|
controller.enqueue({
|
|
1677
1733
|
type: "tool-call",
|
|
1678
|
-
toolCallId: (
|
|
1734
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
1679
1735
|
toolName: toolCall.function.name,
|
|
1680
1736
|
input: toolCall.function.arguments
|
|
1681
1737
|
});
|
|
@@ -1701,10 +1757,16 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1701
1757
|
}
|
|
1702
1758
|
}
|
|
1703
1759
|
if (textStarted) {
|
|
1704
|
-
controller.enqueue({
|
|
1760
|
+
controller.enqueue({
|
|
1761
|
+
type: "text-end",
|
|
1762
|
+
id: textId || generateId()
|
|
1763
|
+
});
|
|
1705
1764
|
}
|
|
1706
1765
|
if (reasoningStarted) {
|
|
1707
|
-
controller.enqueue({
|
|
1766
|
+
controller.enqueue({
|
|
1767
|
+
type: "reasoning-end",
|
|
1768
|
+
id: reasoningId || generateId()
|
|
1769
|
+
});
|
|
1708
1770
|
}
|
|
1709
1771
|
controller.enqueue({
|
|
1710
1772
|
type: "finish",
|