@openrouter/ai-sdk-provider 1.0.0-beta.0 → 1.0.0-beta.2
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 +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +165 -151
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +165 -151
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -0
- package/dist/internal/index.d.ts +3 -0
- package/dist/internal/index.js +165 -151
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +165 -151
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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.
|
|
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
|
|
451
451
|
var z4 = __toESM(require("zod/v4"), 1);
|
|
452
452
|
|
|
453
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
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
|
|
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@
|
|
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
|
|
457
457
|
var import_zod4 = require("zod");
|
|
458
458
|
|
|
459
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
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
|
|
460
460
|
var import_zod = require("zod");
|
|
461
461
|
|
|
462
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
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
|
|
463
463
|
var import_zod2 = require("zod");
|
|
464
464
|
|
|
465
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
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
|
|
466
466
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
467
467
|
|
|
468
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
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
|
|
469
469
|
var import_zod3 = require("zod");
|
|
470
470
|
|
|
471
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
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
|
|
472
472
|
function combineHeaders(...headers) {
|
|
473
473
|
return headers.reduce(
|
|
474
474
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -505,7 +505,8 @@ var createIdGenerator = ({
|
|
|
505
505
|
};
|
|
506
506
|
var generateId = createIdGenerator();
|
|
507
507
|
function isAbortError(error) {
|
|
508
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
508
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
509
|
+
error.name === "TimeoutError");
|
|
509
510
|
}
|
|
510
511
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
511
512
|
function handleFetchError({
|
|
@@ -919,9 +920,6 @@ function withoutTrailingSlash(url) {
|
|
|
919
920
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
920
921
|
}
|
|
921
922
|
|
|
922
|
-
// src/chat/index.ts
|
|
923
|
-
var import_v44 = require("zod/v4");
|
|
924
|
-
|
|
925
923
|
// src/schemas/reasoning-details.ts
|
|
926
924
|
var import_v4 = require("zod/v4");
|
|
927
925
|
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
@@ -952,10 +950,10 @@ var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSc
|
|
|
952
950
|
var import_v42 = require("zod/v4");
|
|
953
951
|
var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
954
952
|
error: import_v42.z.object({
|
|
955
|
-
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullable(),
|
|
953
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullable().optional().default(null),
|
|
956
954
|
message: import_v42.z.string(),
|
|
957
|
-
type: import_v42.z.string().nullable(),
|
|
958
|
-
param: import_v42.z.any().nullable()
|
|
955
|
+
type: import_v42.z.string().nullable().optional().default(null),
|
|
956
|
+
param: import_v42.z.any().nullable().optional().default(null)
|
|
959
957
|
})
|
|
960
958
|
});
|
|
961
959
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1170,6 +1168,108 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1170
1168
|
}
|
|
1171
1169
|
}
|
|
1172
1170
|
|
|
1171
|
+
// src/chat/schemas.ts
|
|
1172
|
+
var import_v44 = require("zod/v4");
|
|
1173
|
+
var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
1174
|
+
id: import_v44.z.string().optional(),
|
|
1175
|
+
model: import_v44.z.string().optional(),
|
|
1176
|
+
usage: import_v44.z.object({
|
|
1177
|
+
prompt_tokens: import_v44.z.number(),
|
|
1178
|
+
prompt_tokens_details: import_v44.z.object({
|
|
1179
|
+
cached_tokens: import_v44.z.number()
|
|
1180
|
+
}).nullish(),
|
|
1181
|
+
completion_tokens: import_v44.z.number(),
|
|
1182
|
+
completion_tokens_details: import_v44.z.object({
|
|
1183
|
+
reasoning_tokens: import_v44.z.number()
|
|
1184
|
+
}).nullish(),
|
|
1185
|
+
total_tokens: import_v44.z.number(),
|
|
1186
|
+
cost: import_v44.z.number().optional(),
|
|
1187
|
+
cost_details: import_v44.z.object({
|
|
1188
|
+
upstream_inference_cost: import_v44.z.number().nullish()
|
|
1189
|
+
}).nullish()
|
|
1190
|
+
}).nullish()
|
|
1191
|
+
});
|
|
1192
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1193
|
+
choices: import_v44.z.array(
|
|
1194
|
+
import_v44.z.object({
|
|
1195
|
+
message: import_v44.z.object({
|
|
1196
|
+
role: import_v44.z.literal("assistant"),
|
|
1197
|
+
content: import_v44.z.string().nullable().optional(),
|
|
1198
|
+
reasoning: import_v44.z.string().nullable().optional(),
|
|
1199
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1200
|
+
tool_calls: import_v44.z.array(
|
|
1201
|
+
import_v44.z.object({
|
|
1202
|
+
id: import_v44.z.string().optional().nullable(),
|
|
1203
|
+
type: import_v44.z.literal("function"),
|
|
1204
|
+
function: import_v44.z.object({
|
|
1205
|
+
name: import_v44.z.string(),
|
|
1206
|
+
arguments: import_v44.z.string()
|
|
1207
|
+
})
|
|
1208
|
+
})
|
|
1209
|
+
).optional()
|
|
1210
|
+
}),
|
|
1211
|
+
index: import_v44.z.number().nullish(),
|
|
1212
|
+
logprobs: import_v44.z.object({
|
|
1213
|
+
content: import_v44.z.array(
|
|
1214
|
+
import_v44.z.object({
|
|
1215
|
+
token: import_v44.z.string(),
|
|
1216
|
+
logprob: import_v44.z.number(),
|
|
1217
|
+
top_logprobs: import_v44.z.array(
|
|
1218
|
+
import_v44.z.object({
|
|
1219
|
+
token: import_v44.z.string(),
|
|
1220
|
+
logprob: import_v44.z.number()
|
|
1221
|
+
})
|
|
1222
|
+
)
|
|
1223
|
+
})
|
|
1224
|
+
).nullable()
|
|
1225
|
+
}).nullable().optional(),
|
|
1226
|
+
finish_reason: import_v44.z.string().optional().nullable()
|
|
1227
|
+
})
|
|
1228
|
+
)
|
|
1229
|
+
});
|
|
1230
|
+
var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
|
|
1231
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1232
|
+
choices: import_v44.z.array(
|
|
1233
|
+
import_v44.z.object({
|
|
1234
|
+
delta: import_v44.z.object({
|
|
1235
|
+
role: import_v44.z.enum(["assistant"]).optional(),
|
|
1236
|
+
content: import_v44.z.string().nullish(),
|
|
1237
|
+
reasoning: import_v44.z.string().nullish().optional(),
|
|
1238
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1239
|
+
tool_calls: import_v44.z.array(
|
|
1240
|
+
import_v44.z.object({
|
|
1241
|
+
index: import_v44.z.number().nullish(),
|
|
1242
|
+
id: import_v44.z.string().nullish(),
|
|
1243
|
+
type: import_v44.z.literal("function").optional(),
|
|
1244
|
+
function: import_v44.z.object({
|
|
1245
|
+
name: import_v44.z.string().nullish(),
|
|
1246
|
+
arguments: import_v44.z.string().nullish()
|
|
1247
|
+
})
|
|
1248
|
+
})
|
|
1249
|
+
).nullish()
|
|
1250
|
+
}).nullish(),
|
|
1251
|
+
logprobs: import_v44.z.object({
|
|
1252
|
+
content: import_v44.z.array(
|
|
1253
|
+
import_v44.z.object({
|
|
1254
|
+
token: import_v44.z.string(),
|
|
1255
|
+
logprob: import_v44.z.number(),
|
|
1256
|
+
top_logprobs: import_v44.z.array(
|
|
1257
|
+
import_v44.z.object({
|
|
1258
|
+
token: import_v44.z.string(),
|
|
1259
|
+
logprob: import_v44.z.number()
|
|
1260
|
+
})
|
|
1261
|
+
)
|
|
1262
|
+
})
|
|
1263
|
+
).nullable()
|
|
1264
|
+
}).nullish(),
|
|
1265
|
+
finish_reason: import_v44.z.string().nullable().optional(),
|
|
1266
|
+
index: import_v44.z.number().nullish()
|
|
1267
|
+
})
|
|
1268
|
+
)
|
|
1269
|
+
}),
|
|
1270
|
+
OpenRouterErrorResponseSchema
|
|
1271
|
+
]);
|
|
1272
|
+
|
|
1173
1273
|
// src/chat/index.ts
|
|
1174
1274
|
var OpenRouterChatLanguageModel = class {
|
|
1175
1275
|
constructor(modelId, settings, config) {
|
|
@@ -1251,7 +1351,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1251
1351
|
return baseArgs;
|
|
1252
1352
|
}
|
|
1253
1353
|
async doGenerate(options) {
|
|
1254
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1354
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1255
1355
|
const providerOptions = options.providerOptions || {};
|
|
1256
1356
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1257
1357
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1363,6 +1463,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1363
1463
|
},
|
|
1364
1464
|
completionTokensDetails: {
|
|
1365
1465
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1466
|
+
},
|
|
1467
|
+
costDetails: {
|
|
1468
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1366
1469
|
}
|
|
1367
1470
|
}
|
|
1368
1471
|
}
|
|
@@ -1410,11 +1513,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1410
1513
|
cachedInputTokens: Number.NaN
|
|
1411
1514
|
};
|
|
1412
1515
|
const openrouterUsage = {};
|
|
1516
|
+
let textStarted = false;
|
|
1517
|
+
let reasoningStarted = false;
|
|
1413
1518
|
return {
|
|
1414
1519
|
stream: response.pipeThrough(
|
|
1415
1520
|
new TransformStream({
|
|
1416
1521
|
transform(chunk, controller) {
|
|
1417
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1522
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1418
1523
|
if (!chunk.success) {
|
|
1419
1524
|
finishReason = "error";
|
|
1420
1525
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1470,55 +1575,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1470
1575
|
}
|
|
1471
1576
|
const delta = choice.delta;
|
|
1472
1577
|
if (delta.content != null) {
|
|
1578
|
+
if (!textStarted) {
|
|
1579
|
+
controller.enqueue({
|
|
1580
|
+
type: "text-start",
|
|
1581
|
+
id: generateId()
|
|
1582
|
+
});
|
|
1583
|
+
textStarted = true;
|
|
1584
|
+
}
|
|
1473
1585
|
controller.enqueue({
|
|
1474
1586
|
type: "text-delta",
|
|
1475
1587
|
delta: delta.content,
|
|
1476
1588
|
id: generateId()
|
|
1477
1589
|
});
|
|
1478
1590
|
}
|
|
1479
|
-
|
|
1591
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1592
|
+
if (!reasoningStarted) {
|
|
1593
|
+
controller.enqueue({
|
|
1594
|
+
type: "reasoning-start",
|
|
1595
|
+
id: generateId()
|
|
1596
|
+
});
|
|
1597
|
+
reasoningStarted = true;
|
|
1598
|
+
}
|
|
1480
1599
|
controller.enqueue({
|
|
1481
1600
|
type: "reasoning-delta",
|
|
1482
|
-
delta:
|
|
1601
|
+
delta: chunkText,
|
|
1483
1602
|
id: generateId()
|
|
1484
1603
|
});
|
|
1604
|
+
};
|
|
1605
|
+
if (delta.reasoning != null) {
|
|
1606
|
+
emitReasoningChunk(delta.reasoning);
|
|
1485
1607
|
}
|
|
1486
1608
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1487
1609
|
for (const detail of delta.reasoning_details) {
|
|
1488
1610
|
switch (detail.type) {
|
|
1489
1611
|
case "reasoning.text" /* Text */: {
|
|
1490
1612
|
if (detail.text) {
|
|
1491
|
-
|
|
1492
|
-
type: "reasoning-delta",
|
|
1493
|
-
delta: detail.text,
|
|
1494
|
-
id: generateId()
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
if (detail.signature) {
|
|
1498
|
-
controller.enqueue({
|
|
1499
|
-
type: "reasoning-end",
|
|
1500
|
-
id: generateId()
|
|
1501
|
-
});
|
|
1613
|
+
emitReasoningChunk(detail.text);
|
|
1502
1614
|
}
|
|
1503
1615
|
break;
|
|
1504
1616
|
}
|
|
1505
1617
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1506
1618
|
if (detail.data) {
|
|
1507
|
-
|
|
1508
|
-
type: "reasoning-delta",
|
|
1509
|
-
delta: "[REDACTED]",
|
|
1510
|
-
id: generateId()
|
|
1511
|
-
});
|
|
1619
|
+
emitReasoningChunk("[REDACTED]");
|
|
1512
1620
|
}
|
|
1513
1621
|
break;
|
|
1514
1622
|
}
|
|
1515
1623
|
case "reasoning.summary" /* Summary */: {
|
|
1516
1624
|
if (detail.summary) {
|
|
1517
|
-
|
|
1518
|
-
type: "reasoning-delta",
|
|
1519
|
-
delta: detail.summary,
|
|
1520
|
-
id: generateId()
|
|
1521
|
-
});
|
|
1625
|
+
emitReasoningChunk(detail.summary);
|
|
1522
1626
|
}
|
|
1523
1627
|
break;
|
|
1524
1628
|
}
|
|
@@ -1531,7 +1635,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1531
1635
|
}
|
|
1532
1636
|
if (delta.tool_calls != null) {
|
|
1533
1637
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1534
|
-
const index = toolCallDelta.index;
|
|
1638
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
1535
1639
|
if (toolCalls[index] == null) {
|
|
1536
1640
|
if (toolCallDelta.type !== "function") {
|
|
1537
1641
|
throw new InvalidResponseDataError({
|
|
@@ -1545,7 +1649,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1545
1649
|
message: `Expected 'id' to be a string.`
|
|
1546
1650
|
});
|
|
1547
1651
|
}
|
|
1548
|
-
if (((
|
|
1652
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
1549
1653
|
throw new InvalidResponseDataError({
|
|
1550
1654
|
data: toolCallDelta,
|
|
1551
1655
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1556,7 +1660,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1556
1660
|
type: "function",
|
|
1557
1661
|
function: {
|
|
1558
1662
|
name: toolCallDelta.function.name,
|
|
1559
|
-
arguments: (
|
|
1663
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1560
1664
|
},
|
|
1561
1665
|
sent: false
|
|
1562
1666
|
};
|
|
@@ -1564,7 +1668,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1564
1668
|
if (toolCall2 == null) {
|
|
1565
1669
|
throw new Error("Tool call is missing");
|
|
1566
1670
|
}
|
|
1567
|
-
if (((
|
|
1671
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1568
1672
|
controller.enqueue({
|
|
1569
1673
|
type: "tool-input-start",
|
|
1570
1674
|
id: toolCall2.id,
|
|
@@ -1593,25 +1697,25 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1593
1697
|
if (toolCall == null) {
|
|
1594
1698
|
throw new Error("Tool call is missing");
|
|
1595
1699
|
}
|
|
1596
|
-
if (((
|
|
1700
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
|
|
1597
1701
|
controller.enqueue({
|
|
1598
1702
|
type: "tool-input-start",
|
|
1599
1703
|
id: toolCall.id,
|
|
1600
1704
|
toolName: toolCall.function.name
|
|
1601
1705
|
});
|
|
1602
1706
|
}
|
|
1603
|
-
if (((
|
|
1604
|
-
toolCall.function.arguments += (
|
|
1707
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
1708
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
1605
1709
|
}
|
|
1606
1710
|
controller.enqueue({
|
|
1607
1711
|
type: "tool-input-delta",
|
|
1608
1712
|
id: toolCall.id,
|
|
1609
|
-
delta: (
|
|
1713
|
+
delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
1610
1714
|
});
|
|
1611
|
-
if (((
|
|
1715
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1612
1716
|
controller.enqueue({
|
|
1613
1717
|
type: "tool-call",
|
|
1614
|
-
toolCallId: (
|
|
1718
|
+
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
1615
1719
|
toolName: toolCall.function.name,
|
|
1616
1720
|
input: toolCall.function.arguments
|
|
1617
1721
|
});
|
|
@@ -1636,6 +1740,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1636
1740
|
}
|
|
1637
1741
|
}
|
|
1638
1742
|
}
|
|
1743
|
+
if (textStarted) {
|
|
1744
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1745
|
+
}
|
|
1746
|
+
if (reasoningStarted) {
|
|
1747
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1748
|
+
}
|
|
1639
1749
|
controller.enqueue({
|
|
1640
1750
|
type: "finish",
|
|
1641
1751
|
finishReason,
|
|
@@ -1655,105 +1765,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1655
1765
|
};
|
|
1656
1766
|
}
|
|
1657
1767
|
};
|
|
1658
|
-
var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
1659
|
-
id: import_v44.z.string().optional(),
|
|
1660
|
-
model: import_v44.z.string().optional(),
|
|
1661
|
-
usage: import_v44.z.object({
|
|
1662
|
-
prompt_tokens: import_v44.z.number(),
|
|
1663
|
-
prompt_tokens_details: import_v44.z.object({
|
|
1664
|
-
cached_tokens: import_v44.z.number()
|
|
1665
|
-
}).nullish(),
|
|
1666
|
-
completion_tokens: import_v44.z.number(),
|
|
1667
|
-
completion_tokens_details: import_v44.z.object({
|
|
1668
|
-
reasoning_tokens: import_v44.z.number()
|
|
1669
|
-
}).nullish(),
|
|
1670
|
-
total_tokens: import_v44.z.number(),
|
|
1671
|
-
cost: import_v44.z.number().optional()
|
|
1672
|
-
}).nullish()
|
|
1673
|
-
});
|
|
1674
|
-
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1675
|
-
choices: import_v44.z.array(
|
|
1676
|
-
import_v44.z.object({
|
|
1677
|
-
message: import_v44.z.object({
|
|
1678
|
-
role: import_v44.z.literal("assistant"),
|
|
1679
|
-
content: import_v44.z.string().nullable().optional(),
|
|
1680
|
-
reasoning: import_v44.z.string().nullable().optional(),
|
|
1681
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1682
|
-
tool_calls: import_v44.z.array(
|
|
1683
|
-
import_v44.z.object({
|
|
1684
|
-
id: import_v44.z.string().optional().nullable(),
|
|
1685
|
-
type: import_v44.z.literal("function"),
|
|
1686
|
-
function: import_v44.z.object({
|
|
1687
|
-
name: import_v44.z.string(),
|
|
1688
|
-
arguments: import_v44.z.string()
|
|
1689
|
-
})
|
|
1690
|
-
})
|
|
1691
|
-
).optional()
|
|
1692
|
-
}),
|
|
1693
|
-
index: import_v44.z.number(),
|
|
1694
|
-
logprobs: import_v44.z.object({
|
|
1695
|
-
content: import_v44.z.array(
|
|
1696
|
-
import_v44.z.object({
|
|
1697
|
-
token: import_v44.z.string(),
|
|
1698
|
-
logprob: import_v44.z.number(),
|
|
1699
|
-
top_logprobs: import_v44.z.array(
|
|
1700
|
-
import_v44.z.object({
|
|
1701
|
-
token: import_v44.z.string(),
|
|
1702
|
-
logprob: import_v44.z.number()
|
|
1703
|
-
})
|
|
1704
|
-
)
|
|
1705
|
-
})
|
|
1706
|
-
).nullable()
|
|
1707
|
-
}).nullable().optional(),
|
|
1708
|
-
finish_reason: import_v44.z.string().optional().nullable()
|
|
1709
|
-
})
|
|
1710
|
-
)
|
|
1711
|
-
});
|
|
1712
|
-
var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
|
|
1713
|
-
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1714
|
-
choices: import_v44.z.array(
|
|
1715
|
-
import_v44.z.object({
|
|
1716
|
-
delta: import_v44.z.object({
|
|
1717
|
-
role: import_v44.z.enum(["assistant"]).optional(),
|
|
1718
|
-
content: import_v44.z.string().nullish(),
|
|
1719
|
-
reasoning: import_v44.z.string().nullish().optional(),
|
|
1720
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1721
|
-
tool_calls: import_v44.z.array(
|
|
1722
|
-
import_v44.z.object({
|
|
1723
|
-
index: import_v44.z.number(),
|
|
1724
|
-
id: import_v44.z.string().nullish(),
|
|
1725
|
-
type: import_v44.z.literal("function").optional(),
|
|
1726
|
-
function: import_v44.z.object({
|
|
1727
|
-
name: import_v44.z.string().nullish(),
|
|
1728
|
-
arguments: import_v44.z.string().nullish()
|
|
1729
|
-
})
|
|
1730
|
-
})
|
|
1731
|
-
).nullish()
|
|
1732
|
-
}).nullish(),
|
|
1733
|
-
logprobs: import_v44.z.object({
|
|
1734
|
-
content: import_v44.z.array(
|
|
1735
|
-
import_v44.z.object({
|
|
1736
|
-
token: import_v44.z.string(),
|
|
1737
|
-
logprob: import_v44.z.number(),
|
|
1738
|
-
top_logprobs: import_v44.z.array(
|
|
1739
|
-
import_v44.z.object({
|
|
1740
|
-
token: import_v44.z.string(),
|
|
1741
|
-
logprob: import_v44.z.number()
|
|
1742
|
-
})
|
|
1743
|
-
)
|
|
1744
|
-
})
|
|
1745
|
-
).nullable()
|
|
1746
|
-
}).nullish(),
|
|
1747
|
-
finish_reason: import_v44.z.string().nullable().optional(),
|
|
1748
|
-
index: import_v44.z.number()
|
|
1749
|
-
})
|
|
1750
|
-
)
|
|
1751
|
-
}),
|
|
1752
|
-
OpenRouterErrorResponseSchema
|
|
1753
|
-
]);
|
|
1754
|
-
|
|
1755
|
-
// src/completion/index.ts
|
|
1756
|
-
var import_v45 = require("zod/v4");
|
|
1757
1768
|
|
|
1758
1769
|
// src/completion/convert-to-openrouter-completion-prompt.ts
|
|
1759
1770
|
function convertToOpenRouterCompletionPrompt({
|
|
@@ -1858,7 +1869,8 @@ ${assistantMessage}
|
|
|
1858
1869
|
};
|
|
1859
1870
|
}
|
|
1860
1871
|
|
|
1861
|
-
// src/completion/
|
|
1872
|
+
// src/completion/schemas.ts
|
|
1873
|
+
var import_v45 = require("zod/v4");
|
|
1862
1874
|
var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
1863
1875
|
import_v45.z.object({
|
|
1864
1876
|
id: import_v45.z.string().optional(),
|
|
@@ -1869,7 +1881,7 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
|
1869
1881
|
reasoning: import_v45.z.string().nullish().optional(),
|
|
1870
1882
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1871
1883
|
finish_reason: import_v45.z.string().nullish(),
|
|
1872
|
-
index: import_v45.z.number(),
|
|
1884
|
+
index: import_v45.z.number().nullish(),
|
|
1873
1885
|
logprobs: import_v45.z.object({
|
|
1874
1886
|
tokens: import_v45.z.array(import_v45.z.string()),
|
|
1875
1887
|
token_logprobs: import_v45.z.array(import_v45.z.number()),
|
|
@@ -1892,6 +1904,8 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
|
1892
1904
|
}),
|
|
1893
1905
|
OpenRouterErrorResponseSchema
|
|
1894
1906
|
]);
|
|
1907
|
+
|
|
1908
|
+
// src/completion/index.ts
|
|
1895
1909
|
var OpenRouterCompletionLanguageModel = class {
|
|
1896
1910
|
constructor(modelId, settings, config) {
|
|
1897
1911
|
this.specificationVersion = "v2";
|