@openrouter/ai-sdk-provider 1.0.0-beta.0 → 1.0.0-beta.1
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.js +115 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -115
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +115 -115
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +115 -115
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -884,9 +884,6 @@ function withoutTrailingSlash(url) {
|
|
|
884
884
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
885
885
|
}
|
|
886
886
|
|
|
887
|
-
// src/chat/index.ts
|
|
888
|
-
import { z as z5 } from "zod/v4";
|
|
889
|
-
|
|
890
887
|
// src/schemas/reasoning-details.ts
|
|
891
888
|
import { z } from "zod/v4";
|
|
892
889
|
var ReasoningDetailSummarySchema = z.object({
|
|
@@ -1135,6 +1132,105 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1135
1132
|
}
|
|
1136
1133
|
}
|
|
1137
1134
|
|
|
1135
|
+
// src/chat/schemas.ts
|
|
1136
|
+
import { z as z5 } from "zod/v4";
|
|
1137
|
+
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1138
|
+
id: z5.string().optional(),
|
|
1139
|
+
model: z5.string().optional(),
|
|
1140
|
+
usage: z5.object({
|
|
1141
|
+
prompt_tokens: z5.number(),
|
|
1142
|
+
prompt_tokens_details: z5.object({
|
|
1143
|
+
cached_tokens: z5.number()
|
|
1144
|
+
}).nullish(),
|
|
1145
|
+
completion_tokens: z5.number(),
|
|
1146
|
+
completion_tokens_details: z5.object({
|
|
1147
|
+
reasoning_tokens: z5.number()
|
|
1148
|
+
}).nullish(),
|
|
1149
|
+
total_tokens: z5.number(),
|
|
1150
|
+
cost: z5.number().optional()
|
|
1151
|
+
}).nullish()
|
|
1152
|
+
});
|
|
1153
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1154
|
+
choices: z5.array(
|
|
1155
|
+
z5.object({
|
|
1156
|
+
message: z5.object({
|
|
1157
|
+
role: z5.literal("assistant"),
|
|
1158
|
+
content: z5.string().nullable().optional(),
|
|
1159
|
+
reasoning: z5.string().nullable().optional(),
|
|
1160
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1161
|
+
tool_calls: z5.array(
|
|
1162
|
+
z5.object({
|
|
1163
|
+
id: z5.string().optional().nullable(),
|
|
1164
|
+
type: z5.literal("function"),
|
|
1165
|
+
function: z5.object({
|
|
1166
|
+
name: z5.string(),
|
|
1167
|
+
arguments: z5.string()
|
|
1168
|
+
})
|
|
1169
|
+
})
|
|
1170
|
+
).optional()
|
|
1171
|
+
}),
|
|
1172
|
+
index: z5.number().nullish(),
|
|
1173
|
+
logprobs: z5.object({
|
|
1174
|
+
content: z5.array(
|
|
1175
|
+
z5.object({
|
|
1176
|
+
token: z5.string(),
|
|
1177
|
+
logprob: z5.number(),
|
|
1178
|
+
top_logprobs: z5.array(
|
|
1179
|
+
z5.object({
|
|
1180
|
+
token: z5.string(),
|
|
1181
|
+
logprob: z5.number()
|
|
1182
|
+
})
|
|
1183
|
+
)
|
|
1184
|
+
})
|
|
1185
|
+
).nullable()
|
|
1186
|
+
}).nullable().optional(),
|
|
1187
|
+
finish_reason: z5.string().optional().nullable()
|
|
1188
|
+
})
|
|
1189
|
+
)
|
|
1190
|
+
});
|
|
1191
|
+
var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
1192
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1193
|
+
choices: z5.array(
|
|
1194
|
+
z5.object({
|
|
1195
|
+
delta: z5.object({
|
|
1196
|
+
role: z5.enum(["assistant"]).optional(),
|
|
1197
|
+
content: z5.string().nullish(),
|
|
1198
|
+
reasoning: z5.string().nullish().optional(),
|
|
1199
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1200
|
+
tool_calls: z5.array(
|
|
1201
|
+
z5.object({
|
|
1202
|
+
index: z5.number().nullish(),
|
|
1203
|
+
id: z5.string().nullish(),
|
|
1204
|
+
type: z5.literal("function").optional(),
|
|
1205
|
+
function: z5.object({
|
|
1206
|
+
name: z5.string().nullish(),
|
|
1207
|
+
arguments: z5.string().nullish()
|
|
1208
|
+
})
|
|
1209
|
+
})
|
|
1210
|
+
).nullish()
|
|
1211
|
+
}).nullish(),
|
|
1212
|
+
logprobs: z5.object({
|
|
1213
|
+
content: z5.array(
|
|
1214
|
+
z5.object({
|
|
1215
|
+
token: z5.string(),
|
|
1216
|
+
logprob: z5.number(),
|
|
1217
|
+
top_logprobs: z5.array(
|
|
1218
|
+
z5.object({
|
|
1219
|
+
token: z5.string(),
|
|
1220
|
+
logprob: z5.number()
|
|
1221
|
+
})
|
|
1222
|
+
)
|
|
1223
|
+
})
|
|
1224
|
+
).nullable()
|
|
1225
|
+
}).nullish(),
|
|
1226
|
+
finish_reason: z5.string().nullable().optional(),
|
|
1227
|
+
index: z5.number().nullish()
|
|
1228
|
+
})
|
|
1229
|
+
)
|
|
1230
|
+
}),
|
|
1231
|
+
OpenRouterErrorResponseSchema
|
|
1232
|
+
]);
|
|
1233
|
+
|
|
1138
1234
|
// src/chat/index.ts
|
|
1139
1235
|
var OpenRouterChatLanguageModel = class {
|
|
1140
1236
|
constructor(modelId, settings, config) {
|
|
@@ -1379,7 +1475,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1379
1475
|
stream: response.pipeThrough(
|
|
1380
1476
|
new TransformStream({
|
|
1381
1477
|
transform(chunk, controller) {
|
|
1382
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1478
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1383
1479
|
if (!chunk.success) {
|
|
1384
1480
|
finishReason = "error";
|
|
1385
1481
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1496,7 +1592,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1496
1592
|
}
|
|
1497
1593
|
if (delta.tool_calls != null) {
|
|
1498
1594
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1499
|
-
const index = toolCallDelta.index;
|
|
1595
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
1500
1596
|
if (toolCalls[index] == null) {
|
|
1501
1597
|
if (toolCallDelta.type !== "function") {
|
|
1502
1598
|
throw new InvalidResponseDataError({
|
|
@@ -1510,7 +1606,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1510
1606
|
message: `Expected 'id' to be a string.`
|
|
1511
1607
|
});
|
|
1512
1608
|
}
|
|
1513
|
-
if (((
|
|
1609
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
1514
1610
|
throw new InvalidResponseDataError({
|
|
1515
1611
|
data: toolCallDelta,
|
|
1516
1612
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1521,7 +1617,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1521
1617
|
type: "function",
|
|
1522
1618
|
function: {
|
|
1523
1619
|
name: toolCallDelta.function.name,
|
|
1524
|
-
arguments: (
|
|
1620
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1525
1621
|
},
|
|
1526
1622
|
sent: false
|
|
1527
1623
|
};
|
|
@@ -1529,7 +1625,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1529
1625
|
if (toolCall2 == null) {
|
|
1530
1626
|
throw new Error("Tool call is missing");
|
|
1531
1627
|
}
|
|
1532
|
-
if (((
|
|
1628
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1533
1629
|
controller.enqueue({
|
|
1534
1630
|
type: "tool-input-start",
|
|
1535
1631
|
id: toolCall2.id,
|
|
@@ -1558,25 +1654,25 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1558
1654
|
if (toolCall == null) {
|
|
1559
1655
|
throw new Error("Tool call is missing");
|
|
1560
1656
|
}
|
|
1561
|
-
if (((
|
|
1657
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
|
|
1562
1658
|
controller.enqueue({
|
|
1563
1659
|
type: "tool-input-start",
|
|
1564
1660
|
id: toolCall.id,
|
|
1565
1661
|
toolName: toolCall.function.name
|
|
1566
1662
|
});
|
|
1567
1663
|
}
|
|
1568
|
-
if (((
|
|
1569
|
-
toolCall.function.arguments += (
|
|
1664
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
1665
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
1570
1666
|
}
|
|
1571
1667
|
controller.enqueue({
|
|
1572
1668
|
type: "tool-input-delta",
|
|
1573
1669
|
id: toolCall.id,
|
|
1574
|
-
delta: (
|
|
1670
|
+
delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
1575
1671
|
});
|
|
1576
|
-
if (((
|
|
1672
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1577
1673
|
controller.enqueue({
|
|
1578
1674
|
type: "tool-call",
|
|
1579
|
-
toolCallId: (
|
|
1675
|
+
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
1580
1676
|
toolName: toolCall.function.name,
|
|
1581
1677
|
input: toolCall.function.arguments
|
|
1582
1678
|
});
|
|
@@ -1620,105 +1716,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1620
1716
|
};
|
|
1621
1717
|
}
|
|
1622
1718
|
};
|
|
1623
|
-
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1624
|
-
id: z5.string().optional(),
|
|
1625
|
-
model: z5.string().optional(),
|
|
1626
|
-
usage: z5.object({
|
|
1627
|
-
prompt_tokens: z5.number(),
|
|
1628
|
-
prompt_tokens_details: z5.object({
|
|
1629
|
-
cached_tokens: z5.number()
|
|
1630
|
-
}).nullish(),
|
|
1631
|
-
completion_tokens: z5.number(),
|
|
1632
|
-
completion_tokens_details: z5.object({
|
|
1633
|
-
reasoning_tokens: z5.number()
|
|
1634
|
-
}).nullish(),
|
|
1635
|
-
total_tokens: z5.number(),
|
|
1636
|
-
cost: z5.number().optional()
|
|
1637
|
-
}).nullish()
|
|
1638
|
-
});
|
|
1639
|
-
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1640
|
-
choices: z5.array(
|
|
1641
|
-
z5.object({
|
|
1642
|
-
message: z5.object({
|
|
1643
|
-
role: z5.literal("assistant"),
|
|
1644
|
-
content: z5.string().nullable().optional(),
|
|
1645
|
-
reasoning: z5.string().nullable().optional(),
|
|
1646
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1647
|
-
tool_calls: z5.array(
|
|
1648
|
-
z5.object({
|
|
1649
|
-
id: z5.string().optional().nullable(),
|
|
1650
|
-
type: z5.literal("function"),
|
|
1651
|
-
function: z5.object({
|
|
1652
|
-
name: z5.string(),
|
|
1653
|
-
arguments: z5.string()
|
|
1654
|
-
})
|
|
1655
|
-
})
|
|
1656
|
-
).optional()
|
|
1657
|
-
}),
|
|
1658
|
-
index: z5.number(),
|
|
1659
|
-
logprobs: z5.object({
|
|
1660
|
-
content: z5.array(
|
|
1661
|
-
z5.object({
|
|
1662
|
-
token: z5.string(),
|
|
1663
|
-
logprob: z5.number(),
|
|
1664
|
-
top_logprobs: z5.array(
|
|
1665
|
-
z5.object({
|
|
1666
|
-
token: z5.string(),
|
|
1667
|
-
logprob: z5.number()
|
|
1668
|
-
})
|
|
1669
|
-
)
|
|
1670
|
-
})
|
|
1671
|
-
).nullable()
|
|
1672
|
-
}).nullable().optional(),
|
|
1673
|
-
finish_reason: z5.string().optional().nullable()
|
|
1674
|
-
})
|
|
1675
|
-
)
|
|
1676
|
-
});
|
|
1677
|
-
var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
1678
|
-
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1679
|
-
choices: z5.array(
|
|
1680
|
-
z5.object({
|
|
1681
|
-
delta: z5.object({
|
|
1682
|
-
role: z5.enum(["assistant"]).optional(),
|
|
1683
|
-
content: z5.string().nullish(),
|
|
1684
|
-
reasoning: z5.string().nullish().optional(),
|
|
1685
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1686
|
-
tool_calls: z5.array(
|
|
1687
|
-
z5.object({
|
|
1688
|
-
index: z5.number(),
|
|
1689
|
-
id: z5.string().nullish(),
|
|
1690
|
-
type: z5.literal("function").optional(),
|
|
1691
|
-
function: z5.object({
|
|
1692
|
-
name: z5.string().nullish(),
|
|
1693
|
-
arguments: z5.string().nullish()
|
|
1694
|
-
})
|
|
1695
|
-
})
|
|
1696
|
-
).nullish()
|
|
1697
|
-
}).nullish(),
|
|
1698
|
-
logprobs: z5.object({
|
|
1699
|
-
content: z5.array(
|
|
1700
|
-
z5.object({
|
|
1701
|
-
token: z5.string(),
|
|
1702
|
-
logprob: z5.number(),
|
|
1703
|
-
top_logprobs: z5.array(
|
|
1704
|
-
z5.object({
|
|
1705
|
-
token: z5.string(),
|
|
1706
|
-
logprob: z5.number()
|
|
1707
|
-
})
|
|
1708
|
-
)
|
|
1709
|
-
})
|
|
1710
|
-
).nullable()
|
|
1711
|
-
}).nullish(),
|
|
1712
|
-
finish_reason: z5.string().nullable().optional(),
|
|
1713
|
-
index: z5.number()
|
|
1714
|
-
})
|
|
1715
|
-
)
|
|
1716
|
-
}),
|
|
1717
|
-
OpenRouterErrorResponseSchema
|
|
1718
|
-
]);
|
|
1719
|
-
|
|
1720
|
-
// src/completion/index.ts
|
|
1721
|
-
import { z as z6 } from "zod/v4";
|
|
1722
1719
|
|
|
1723
1720
|
// src/completion/convert-to-openrouter-completion-prompt.ts
|
|
1724
1721
|
function convertToOpenRouterCompletionPrompt({
|
|
@@ -1823,7 +1820,8 @@ ${assistantMessage}
|
|
|
1823
1820
|
};
|
|
1824
1821
|
}
|
|
1825
1822
|
|
|
1826
|
-
// src/completion/
|
|
1823
|
+
// src/completion/schemas.ts
|
|
1824
|
+
import { z as z6 } from "zod/v4";
|
|
1827
1825
|
var OpenRouterCompletionChunkSchema = z6.union([
|
|
1828
1826
|
z6.object({
|
|
1829
1827
|
id: z6.string().optional(),
|
|
@@ -1834,7 +1832,7 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1834
1832
|
reasoning: z6.string().nullish().optional(),
|
|
1835
1833
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1836
1834
|
finish_reason: z6.string().nullish(),
|
|
1837
|
-
index: z6.number(),
|
|
1835
|
+
index: z6.number().nullish(),
|
|
1838
1836
|
logprobs: z6.object({
|
|
1839
1837
|
tokens: z6.array(z6.string()),
|
|
1840
1838
|
token_logprobs: z6.array(z6.number()),
|
|
@@ -1857,6 +1855,8 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1857
1855
|
}),
|
|
1858
1856
|
OpenRouterErrorResponseSchema
|
|
1859
1857
|
]);
|
|
1858
|
+
|
|
1859
|
+
// src/completion/index.ts
|
|
1860
1860
|
var OpenRouterCompletionLanguageModel = class {
|
|
1861
1861
|
constructor(modelId, settings, config) {
|
|
1862
1862
|
this.specificationVersion = "v2";
|