@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.
@@ -873,9 +873,6 @@ function convertUint8ArrayToBase64(array) {
873
873
  return btoa(latin1string);
874
874
  }
875
875
 
876
- // src/chat/index.ts
877
- var import_v44 = require("zod/v4");
878
-
879
876
  // src/schemas/reasoning-details.ts
880
877
  var import_v4 = require("zod/v4");
881
878
  var ReasoningDetailSummarySchema = import_v4.z.object({
@@ -1124,6 +1121,105 @@ function getChatCompletionToolChoice(toolChoice) {
1124
1121
  }
1125
1122
  }
1126
1123
 
1124
+ // src/chat/schemas.ts
1125
+ var import_v44 = require("zod/v4");
1126
+ var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
1127
+ id: import_v44.z.string().optional(),
1128
+ model: import_v44.z.string().optional(),
1129
+ usage: import_v44.z.object({
1130
+ prompt_tokens: import_v44.z.number(),
1131
+ prompt_tokens_details: import_v44.z.object({
1132
+ cached_tokens: import_v44.z.number()
1133
+ }).nullish(),
1134
+ completion_tokens: import_v44.z.number(),
1135
+ completion_tokens_details: import_v44.z.object({
1136
+ reasoning_tokens: import_v44.z.number()
1137
+ }).nullish(),
1138
+ total_tokens: import_v44.z.number(),
1139
+ cost: import_v44.z.number().optional()
1140
+ }).nullish()
1141
+ });
1142
+ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
1143
+ choices: import_v44.z.array(
1144
+ import_v44.z.object({
1145
+ message: import_v44.z.object({
1146
+ role: import_v44.z.literal("assistant"),
1147
+ content: import_v44.z.string().nullable().optional(),
1148
+ reasoning: import_v44.z.string().nullable().optional(),
1149
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
1150
+ tool_calls: import_v44.z.array(
1151
+ import_v44.z.object({
1152
+ id: import_v44.z.string().optional().nullable(),
1153
+ type: import_v44.z.literal("function"),
1154
+ function: import_v44.z.object({
1155
+ name: import_v44.z.string(),
1156
+ arguments: import_v44.z.string()
1157
+ })
1158
+ })
1159
+ ).optional()
1160
+ }),
1161
+ index: import_v44.z.number().nullish(),
1162
+ logprobs: import_v44.z.object({
1163
+ content: import_v44.z.array(
1164
+ import_v44.z.object({
1165
+ token: import_v44.z.string(),
1166
+ logprob: import_v44.z.number(),
1167
+ top_logprobs: import_v44.z.array(
1168
+ import_v44.z.object({
1169
+ token: import_v44.z.string(),
1170
+ logprob: import_v44.z.number()
1171
+ })
1172
+ )
1173
+ })
1174
+ ).nullable()
1175
+ }).nullable().optional(),
1176
+ finish_reason: import_v44.z.string().optional().nullable()
1177
+ })
1178
+ )
1179
+ });
1180
+ var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
1181
+ OpenRouterChatCompletionBaseResponseSchema.extend({
1182
+ choices: import_v44.z.array(
1183
+ import_v44.z.object({
1184
+ delta: import_v44.z.object({
1185
+ role: import_v44.z.enum(["assistant"]).optional(),
1186
+ content: import_v44.z.string().nullish(),
1187
+ reasoning: import_v44.z.string().nullish().optional(),
1188
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
1189
+ tool_calls: import_v44.z.array(
1190
+ import_v44.z.object({
1191
+ index: import_v44.z.number().nullish(),
1192
+ id: import_v44.z.string().nullish(),
1193
+ type: import_v44.z.literal("function").optional(),
1194
+ function: import_v44.z.object({
1195
+ name: import_v44.z.string().nullish(),
1196
+ arguments: import_v44.z.string().nullish()
1197
+ })
1198
+ })
1199
+ ).nullish()
1200
+ }).nullish(),
1201
+ logprobs: import_v44.z.object({
1202
+ content: import_v44.z.array(
1203
+ import_v44.z.object({
1204
+ token: import_v44.z.string(),
1205
+ logprob: import_v44.z.number(),
1206
+ top_logprobs: import_v44.z.array(
1207
+ import_v44.z.object({
1208
+ token: import_v44.z.string(),
1209
+ logprob: import_v44.z.number()
1210
+ })
1211
+ )
1212
+ })
1213
+ ).nullable()
1214
+ }).nullish(),
1215
+ finish_reason: import_v44.z.string().nullable().optional(),
1216
+ index: import_v44.z.number().nullish()
1217
+ })
1218
+ )
1219
+ }),
1220
+ OpenRouterErrorResponseSchema
1221
+ ]);
1222
+
1127
1223
  // src/chat/index.ts
1128
1224
  var OpenRouterChatLanguageModel = class {
1129
1225
  constructor(modelId, settings, config) {
@@ -1368,7 +1464,7 @@ var OpenRouterChatLanguageModel = class {
1368
1464
  stream: response.pipeThrough(
1369
1465
  new TransformStream({
1370
1466
  transform(chunk, controller) {
1371
- var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1467
+ var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1372
1468
  if (!chunk.success) {
1373
1469
  finishReason = "error";
1374
1470
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1485,7 +1581,7 @@ var OpenRouterChatLanguageModel = class {
1485
1581
  }
1486
1582
  if (delta.tool_calls != null) {
1487
1583
  for (const toolCallDelta of delta.tool_calls) {
1488
- const index = toolCallDelta.index;
1584
+ const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
1489
1585
  if (toolCalls[index] == null) {
1490
1586
  if (toolCallDelta.type !== "function") {
1491
1587
  throw new InvalidResponseDataError({
@@ -1499,7 +1595,7 @@ var OpenRouterChatLanguageModel = class {
1499
1595
  message: `Expected 'id' to be a string.`
1500
1596
  });
1501
1597
  }
1502
- if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
1598
+ if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
1503
1599
  throw new InvalidResponseDataError({
1504
1600
  data: toolCallDelta,
1505
1601
  message: `Expected 'function.name' to be a string.`
@@ -1510,7 +1606,7 @@ var OpenRouterChatLanguageModel = class {
1510
1606
  type: "function",
1511
1607
  function: {
1512
1608
  name: toolCallDelta.function.name,
1513
- arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
1609
+ arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
1514
1610
  },
1515
1611
  sent: false
1516
1612
  };
@@ -1518,7 +1614,7 @@ var OpenRouterChatLanguageModel = class {
1518
1614
  if (toolCall2 == null) {
1519
1615
  throw new Error("Tool call is missing");
1520
1616
  }
1521
- if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
1617
+ if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
1522
1618
  controller.enqueue({
1523
1619
  type: "tool-input-start",
1524
1620
  id: toolCall2.id,
@@ -1547,25 +1643,25 @@ var OpenRouterChatLanguageModel = class {
1547
1643
  if (toolCall == null) {
1548
1644
  throw new Error("Tool call is missing");
1549
1645
  }
1550
- if (((_g = toolCallDelta.function) == null ? void 0 : _g.name) != null) {
1646
+ if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
1551
1647
  controller.enqueue({
1552
1648
  type: "tool-input-start",
1553
1649
  id: toolCall.id,
1554
1650
  toolName: toolCall.function.name
1555
1651
  });
1556
1652
  }
1557
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
1558
- toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
1653
+ if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
1654
+ toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
1559
1655
  }
1560
1656
  controller.enqueue({
1561
1657
  type: "tool-input-delta",
1562
1658
  id: toolCall.id,
1563
- delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
1659
+ delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
1564
1660
  });
1565
- if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1661
+ if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
1566
1662
  controller.enqueue({
1567
1663
  type: "tool-call",
1568
- toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
1664
+ toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
1569
1665
  toolName: toolCall.function.name,
1570
1666
  input: toolCall.function.arguments
1571
1667
  });
@@ -1609,105 +1705,6 @@ var OpenRouterChatLanguageModel = class {
1609
1705
  };
1610
1706
  }
1611
1707
  };
1612
- var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
1613
- id: import_v44.z.string().optional(),
1614
- model: import_v44.z.string().optional(),
1615
- usage: import_v44.z.object({
1616
- prompt_tokens: import_v44.z.number(),
1617
- prompt_tokens_details: import_v44.z.object({
1618
- cached_tokens: import_v44.z.number()
1619
- }).nullish(),
1620
- completion_tokens: import_v44.z.number(),
1621
- completion_tokens_details: import_v44.z.object({
1622
- reasoning_tokens: import_v44.z.number()
1623
- }).nullish(),
1624
- total_tokens: import_v44.z.number(),
1625
- cost: import_v44.z.number().optional()
1626
- }).nullish()
1627
- });
1628
- var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
1629
- choices: import_v44.z.array(
1630
- import_v44.z.object({
1631
- message: import_v44.z.object({
1632
- role: import_v44.z.literal("assistant"),
1633
- content: import_v44.z.string().nullable().optional(),
1634
- reasoning: import_v44.z.string().nullable().optional(),
1635
- reasoning_details: ReasoningDetailArraySchema.nullish(),
1636
- tool_calls: import_v44.z.array(
1637
- import_v44.z.object({
1638
- id: import_v44.z.string().optional().nullable(),
1639
- type: import_v44.z.literal("function"),
1640
- function: import_v44.z.object({
1641
- name: import_v44.z.string(),
1642
- arguments: import_v44.z.string()
1643
- })
1644
- })
1645
- ).optional()
1646
- }),
1647
- index: import_v44.z.number(),
1648
- logprobs: import_v44.z.object({
1649
- content: import_v44.z.array(
1650
- import_v44.z.object({
1651
- token: import_v44.z.string(),
1652
- logprob: import_v44.z.number(),
1653
- top_logprobs: import_v44.z.array(
1654
- import_v44.z.object({
1655
- token: import_v44.z.string(),
1656
- logprob: import_v44.z.number()
1657
- })
1658
- )
1659
- })
1660
- ).nullable()
1661
- }).nullable().optional(),
1662
- finish_reason: import_v44.z.string().optional().nullable()
1663
- })
1664
- )
1665
- });
1666
- var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
1667
- OpenRouterChatCompletionBaseResponseSchema.extend({
1668
- choices: import_v44.z.array(
1669
- import_v44.z.object({
1670
- delta: import_v44.z.object({
1671
- role: import_v44.z.enum(["assistant"]).optional(),
1672
- content: import_v44.z.string().nullish(),
1673
- reasoning: import_v44.z.string().nullish().optional(),
1674
- reasoning_details: ReasoningDetailArraySchema.nullish(),
1675
- tool_calls: import_v44.z.array(
1676
- import_v44.z.object({
1677
- index: import_v44.z.number(),
1678
- id: import_v44.z.string().nullish(),
1679
- type: import_v44.z.literal("function").optional(),
1680
- function: import_v44.z.object({
1681
- name: import_v44.z.string().nullish(),
1682
- arguments: import_v44.z.string().nullish()
1683
- })
1684
- })
1685
- ).nullish()
1686
- }).nullish(),
1687
- logprobs: import_v44.z.object({
1688
- content: import_v44.z.array(
1689
- import_v44.z.object({
1690
- token: import_v44.z.string(),
1691
- logprob: import_v44.z.number(),
1692
- top_logprobs: import_v44.z.array(
1693
- import_v44.z.object({
1694
- token: import_v44.z.string(),
1695
- logprob: import_v44.z.number()
1696
- })
1697
- )
1698
- })
1699
- ).nullable()
1700
- }).nullish(),
1701
- finish_reason: import_v44.z.string().nullable().optional(),
1702
- index: import_v44.z.number()
1703
- })
1704
- )
1705
- }),
1706
- OpenRouterErrorResponseSchema
1707
- ]);
1708
-
1709
- // src/completion/index.ts
1710
- var import_v45 = require("zod/v4");
1711
1708
 
1712
1709
  // src/completion/convert-to-openrouter-completion-prompt.ts
1713
1710
  function convertToOpenRouterCompletionPrompt({
@@ -1812,7 +1809,8 @@ ${assistantMessage}
1812
1809
  };
1813
1810
  }
1814
1811
 
1815
- // src/completion/index.ts
1812
+ // src/completion/schemas.ts
1813
+ var import_v45 = require("zod/v4");
1816
1814
  var OpenRouterCompletionChunkSchema = import_v45.z.union([
1817
1815
  import_v45.z.object({
1818
1816
  id: import_v45.z.string().optional(),
@@ -1823,7 +1821,7 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
1823
1821
  reasoning: import_v45.z.string().nullish().optional(),
1824
1822
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1825
1823
  finish_reason: import_v45.z.string().nullish(),
1826
- index: import_v45.z.number(),
1824
+ index: import_v45.z.number().nullish(),
1827
1825
  logprobs: import_v45.z.object({
1828
1826
  tokens: import_v45.z.array(import_v45.z.string()),
1829
1827
  token_logprobs: import_v45.z.array(import_v45.z.number()),
@@ -1846,6 +1844,8 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
1846
1844
  }),
1847
1845
  OpenRouterErrorResponseSchema
1848
1846
  ]);
1847
+
1848
+ // src/completion/index.ts
1849
1849
  var OpenRouterCompletionLanguageModel = class {
1850
1850
  constructor(modelId, settings, config) {
1851
1851
  this.specificationVersion = "v2";