@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/internal/index.mjs
CHANGED
|
@@ -402,28 +402,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
404
|
|
|
405
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
405
|
+
// 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
|
|
406
406
|
import * as z4 from "zod/v4";
|
|
407
407
|
|
|
408
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
408
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
409
409
|
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
410
410
|
|
|
411
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
411
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
412
412
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
413
413
|
|
|
414
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
414
|
+
// 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
|
|
415
415
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
416
416
|
|
|
417
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
417
|
+
// 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
|
|
418
418
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
419
419
|
|
|
420
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
420
|
+
// 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
|
|
421
421
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
422
422
|
|
|
423
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
423
|
+
// 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
|
|
424
424
|
import { ZodOptional } from "zod";
|
|
425
425
|
|
|
426
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
426
|
+
// 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
|
|
427
427
|
function combineHeaders(...headers) {
|
|
428
428
|
return headers.reduce(
|
|
429
429
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -460,7 +460,8 @@ var createIdGenerator = ({
|
|
|
460
460
|
};
|
|
461
461
|
var generateId = createIdGenerator();
|
|
462
462
|
function isAbortError(error) {
|
|
463
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
463
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
464
|
+
error.name === "TimeoutError");
|
|
464
465
|
}
|
|
465
466
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
466
467
|
function handleFetchError({
|
|
@@ -839,9 +840,6 @@ function convertUint8ArrayToBase64(array) {
|
|
|
839
840
|
return btoa(latin1string);
|
|
840
841
|
}
|
|
841
842
|
|
|
842
|
-
// src/chat/index.ts
|
|
843
|
-
import { z as z5 } from "zod/v4";
|
|
844
|
-
|
|
845
843
|
// src/schemas/reasoning-details.ts
|
|
846
844
|
import { z } from "zod/v4";
|
|
847
845
|
var ReasoningDetailSummarySchema = z.object({
|
|
@@ -872,10 +870,10 @@ var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).tran
|
|
|
872
870
|
import { z as z2 } from "zod/v4";
|
|
873
871
|
var OpenRouterErrorResponseSchema = z2.object({
|
|
874
872
|
error: z2.object({
|
|
875
|
-
code: z2.union([z2.string(), z2.number()]).nullable(),
|
|
873
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
876
874
|
message: z2.string(),
|
|
877
|
-
type: z2.string().nullable(),
|
|
878
|
-
param: z2.any().nullable()
|
|
875
|
+
type: z2.string().nullable().optional().default(null),
|
|
876
|
+
param: z2.any().nullable().optional().default(null)
|
|
879
877
|
})
|
|
880
878
|
});
|
|
881
879
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1090,6 +1088,108 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1090
1088
|
}
|
|
1091
1089
|
}
|
|
1092
1090
|
|
|
1091
|
+
// src/chat/schemas.ts
|
|
1092
|
+
import { z as z5 } from "zod/v4";
|
|
1093
|
+
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1094
|
+
id: z5.string().optional(),
|
|
1095
|
+
model: z5.string().optional(),
|
|
1096
|
+
usage: z5.object({
|
|
1097
|
+
prompt_tokens: z5.number(),
|
|
1098
|
+
prompt_tokens_details: z5.object({
|
|
1099
|
+
cached_tokens: z5.number()
|
|
1100
|
+
}).nullish(),
|
|
1101
|
+
completion_tokens: z5.number(),
|
|
1102
|
+
completion_tokens_details: z5.object({
|
|
1103
|
+
reasoning_tokens: z5.number()
|
|
1104
|
+
}).nullish(),
|
|
1105
|
+
total_tokens: z5.number(),
|
|
1106
|
+
cost: z5.number().optional(),
|
|
1107
|
+
cost_details: z5.object({
|
|
1108
|
+
upstream_inference_cost: z5.number().nullish()
|
|
1109
|
+
}).nullish()
|
|
1110
|
+
}).nullish()
|
|
1111
|
+
});
|
|
1112
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1113
|
+
choices: z5.array(
|
|
1114
|
+
z5.object({
|
|
1115
|
+
message: z5.object({
|
|
1116
|
+
role: z5.literal("assistant"),
|
|
1117
|
+
content: z5.string().nullable().optional(),
|
|
1118
|
+
reasoning: z5.string().nullable().optional(),
|
|
1119
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1120
|
+
tool_calls: z5.array(
|
|
1121
|
+
z5.object({
|
|
1122
|
+
id: z5.string().optional().nullable(),
|
|
1123
|
+
type: z5.literal("function"),
|
|
1124
|
+
function: z5.object({
|
|
1125
|
+
name: z5.string(),
|
|
1126
|
+
arguments: z5.string()
|
|
1127
|
+
})
|
|
1128
|
+
})
|
|
1129
|
+
).optional()
|
|
1130
|
+
}),
|
|
1131
|
+
index: z5.number().nullish(),
|
|
1132
|
+
logprobs: z5.object({
|
|
1133
|
+
content: z5.array(
|
|
1134
|
+
z5.object({
|
|
1135
|
+
token: z5.string(),
|
|
1136
|
+
logprob: z5.number(),
|
|
1137
|
+
top_logprobs: z5.array(
|
|
1138
|
+
z5.object({
|
|
1139
|
+
token: z5.string(),
|
|
1140
|
+
logprob: z5.number()
|
|
1141
|
+
})
|
|
1142
|
+
)
|
|
1143
|
+
})
|
|
1144
|
+
).nullable()
|
|
1145
|
+
}).nullable().optional(),
|
|
1146
|
+
finish_reason: z5.string().optional().nullable()
|
|
1147
|
+
})
|
|
1148
|
+
)
|
|
1149
|
+
});
|
|
1150
|
+
var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
1151
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1152
|
+
choices: z5.array(
|
|
1153
|
+
z5.object({
|
|
1154
|
+
delta: z5.object({
|
|
1155
|
+
role: z5.enum(["assistant"]).optional(),
|
|
1156
|
+
content: z5.string().nullish(),
|
|
1157
|
+
reasoning: z5.string().nullish().optional(),
|
|
1158
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1159
|
+
tool_calls: z5.array(
|
|
1160
|
+
z5.object({
|
|
1161
|
+
index: z5.number().nullish(),
|
|
1162
|
+
id: z5.string().nullish(),
|
|
1163
|
+
type: z5.literal("function").optional(),
|
|
1164
|
+
function: z5.object({
|
|
1165
|
+
name: z5.string().nullish(),
|
|
1166
|
+
arguments: z5.string().nullish()
|
|
1167
|
+
})
|
|
1168
|
+
})
|
|
1169
|
+
).nullish()
|
|
1170
|
+
}).nullish(),
|
|
1171
|
+
logprobs: z5.object({
|
|
1172
|
+
content: z5.array(
|
|
1173
|
+
z5.object({
|
|
1174
|
+
token: z5.string(),
|
|
1175
|
+
logprob: z5.number(),
|
|
1176
|
+
top_logprobs: z5.array(
|
|
1177
|
+
z5.object({
|
|
1178
|
+
token: z5.string(),
|
|
1179
|
+
logprob: z5.number()
|
|
1180
|
+
})
|
|
1181
|
+
)
|
|
1182
|
+
})
|
|
1183
|
+
).nullable()
|
|
1184
|
+
}).nullish(),
|
|
1185
|
+
finish_reason: z5.string().nullable().optional(),
|
|
1186
|
+
index: z5.number().nullish()
|
|
1187
|
+
})
|
|
1188
|
+
)
|
|
1189
|
+
}),
|
|
1190
|
+
OpenRouterErrorResponseSchema
|
|
1191
|
+
]);
|
|
1192
|
+
|
|
1093
1193
|
// src/chat/index.ts
|
|
1094
1194
|
var OpenRouterChatLanguageModel = class {
|
|
1095
1195
|
constructor(modelId, settings, config) {
|
|
@@ -1171,7 +1271,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1171
1271
|
return baseArgs;
|
|
1172
1272
|
}
|
|
1173
1273
|
async doGenerate(options) {
|
|
1174
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1274
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1175
1275
|
const providerOptions = options.providerOptions || {};
|
|
1176
1276
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1177
1277
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1283,6 +1383,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1283
1383
|
},
|
|
1284
1384
|
completionTokensDetails: {
|
|
1285
1385
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1386
|
+
},
|
|
1387
|
+
costDetails: {
|
|
1388
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1286
1389
|
}
|
|
1287
1390
|
}
|
|
1288
1391
|
}
|
|
@@ -1330,11 +1433,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1330
1433
|
cachedInputTokens: Number.NaN
|
|
1331
1434
|
};
|
|
1332
1435
|
const openrouterUsage = {};
|
|
1436
|
+
let textStarted = false;
|
|
1437
|
+
let reasoningStarted = false;
|
|
1333
1438
|
return {
|
|
1334
1439
|
stream: response.pipeThrough(
|
|
1335
1440
|
new TransformStream({
|
|
1336
1441
|
transform(chunk, controller) {
|
|
1337
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1442
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1338
1443
|
if (!chunk.success) {
|
|
1339
1444
|
finishReason = "error";
|
|
1340
1445
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1390,55 +1495,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1390
1495
|
}
|
|
1391
1496
|
const delta = choice.delta;
|
|
1392
1497
|
if (delta.content != null) {
|
|
1498
|
+
if (!textStarted) {
|
|
1499
|
+
controller.enqueue({
|
|
1500
|
+
type: "text-start",
|
|
1501
|
+
id: generateId()
|
|
1502
|
+
});
|
|
1503
|
+
textStarted = true;
|
|
1504
|
+
}
|
|
1393
1505
|
controller.enqueue({
|
|
1394
1506
|
type: "text-delta",
|
|
1395
1507
|
delta: delta.content,
|
|
1396
1508
|
id: generateId()
|
|
1397
1509
|
});
|
|
1398
1510
|
}
|
|
1399
|
-
|
|
1511
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1512
|
+
if (!reasoningStarted) {
|
|
1513
|
+
controller.enqueue({
|
|
1514
|
+
type: "reasoning-start",
|
|
1515
|
+
id: generateId()
|
|
1516
|
+
});
|
|
1517
|
+
reasoningStarted = true;
|
|
1518
|
+
}
|
|
1400
1519
|
controller.enqueue({
|
|
1401
1520
|
type: "reasoning-delta",
|
|
1402
|
-
delta:
|
|
1521
|
+
delta: chunkText,
|
|
1403
1522
|
id: generateId()
|
|
1404
1523
|
});
|
|
1524
|
+
};
|
|
1525
|
+
if (delta.reasoning != null) {
|
|
1526
|
+
emitReasoningChunk(delta.reasoning);
|
|
1405
1527
|
}
|
|
1406
1528
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1407
1529
|
for (const detail of delta.reasoning_details) {
|
|
1408
1530
|
switch (detail.type) {
|
|
1409
1531
|
case "reasoning.text" /* Text */: {
|
|
1410
1532
|
if (detail.text) {
|
|
1411
|
-
|
|
1412
|
-
type: "reasoning-delta",
|
|
1413
|
-
delta: detail.text,
|
|
1414
|
-
id: generateId()
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
if (detail.signature) {
|
|
1418
|
-
controller.enqueue({
|
|
1419
|
-
type: "reasoning-end",
|
|
1420
|
-
id: generateId()
|
|
1421
|
-
});
|
|
1533
|
+
emitReasoningChunk(detail.text);
|
|
1422
1534
|
}
|
|
1423
1535
|
break;
|
|
1424
1536
|
}
|
|
1425
1537
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1426
1538
|
if (detail.data) {
|
|
1427
|
-
|
|
1428
|
-
type: "reasoning-delta",
|
|
1429
|
-
delta: "[REDACTED]",
|
|
1430
|
-
id: generateId()
|
|
1431
|
-
});
|
|
1539
|
+
emitReasoningChunk("[REDACTED]");
|
|
1432
1540
|
}
|
|
1433
1541
|
break;
|
|
1434
1542
|
}
|
|
1435
1543
|
case "reasoning.summary" /* Summary */: {
|
|
1436
1544
|
if (detail.summary) {
|
|
1437
|
-
|
|
1438
|
-
type: "reasoning-delta",
|
|
1439
|
-
delta: detail.summary,
|
|
1440
|
-
id: generateId()
|
|
1441
|
-
});
|
|
1545
|
+
emitReasoningChunk(detail.summary);
|
|
1442
1546
|
}
|
|
1443
1547
|
break;
|
|
1444
1548
|
}
|
|
@@ -1451,7 +1555,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1451
1555
|
}
|
|
1452
1556
|
if (delta.tool_calls != null) {
|
|
1453
1557
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1454
|
-
const index = toolCallDelta.index;
|
|
1558
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
1455
1559
|
if (toolCalls[index] == null) {
|
|
1456
1560
|
if (toolCallDelta.type !== "function") {
|
|
1457
1561
|
throw new InvalidResponseDataError({
|
|
@@ -1465,7 +1569,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1465
1569
|
message: `Expected 'id' to be a string.`
|
|
1466
1570
|
});
|
|
1467
1571
|
}
|
|
1468
|
-
if (((
|
|
1572
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
1469
1573
|
throw new InvalidResponseDataError({
|
|
1470
1574
|
data: toolCallDelta,
|
|
1471
1575
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1476,7 +1580,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1476
1580
|
type: "function",
|
|
1477
1581
|
function: {
|
|
1478
1582
|
name: toolCallDelta.function.name,
|
|
1479
|
-
arguments: (
|
|
1583
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1480
1584
|
},
|
|
1481
1585
|
sent: false
|
|
1482
1586
|
};
|
|
@@ -1484,7 +1588,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1484
1588
|
if (toolCall2 == null) {
|
|
1485
1589
|
throw new Error("Tool call is missing");
|
|
1486
1590
|
}
|
|
1487
|
-
if (((
|
|
1591
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1488
1592
|
controller.enqueue({
|
|
1489
1593
|
type: "tool-input-start",
|
|
1490
1594
|
id: toolCall2.id,
|
|
@@ -1513,25 +1617,25 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1513
1617
|
if (toolCall == null) {
|
|
1514
1618
|
throw new Error("Tool call is missing");
|
|
1515
1619
|
}
|
|
1516
|
-
if (((
|
|
1620
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
|
|
1517
1621
|
controller.enqueue({
|
|
1518
1622
|
type: "tool-input-start",
|
|
1519
1623
|
id: toolCall.id,
|
|
1520
1624
|
toolName: toolCall.function.name
|
|
1521
1625
|
});
|
|
1522
1626
|
}
|
|
1523
|
-
if (((
|
|
1524
|
-
toolCall.function.arguments += (
|
|
1627
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
1628
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
1525
1629
|
}
|
|
1526
1630
|
controller.enqueue({
|
|
1527
1631
|
type: "tool-input-delta",
|
|
1528
1632
|
id: toolCall.id,
|
|
1529
|
-
delta: (
|
|
1633
|
+
delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
1530
1634
|
});
|
|
1531
|
-
if (((
|
|
1635
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1532
1636
|
controller.enqueue({
|
|
1533
1637
|
type: "tool-call",
|
|
1534
|
-
toolCallId: (
|
|
1638
|
+
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
1535
1639
|
toolName: toolCall.function.name,
|
|
1536
1640
|
input: toolCall.function.arguments
|
|
1537
1641
|
});
|
|
@@ -1556,6 +1660,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1556
1660
|
}
|
|
1557
1661
|
}
|
|
1558
1662
|
}
|
|
1663
|
+
if (textStarted) {
|
|
1664
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1665
|
+
}
|
|
1666
|
+
if (reasoningStarted) {
|
|
1667
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1668
|
+
}
|
|
1559
1669
|
controller.enqueue({
|
|
1560
1670
|
type: "finish",
|
|
1561
1671
|
finishReason,
|
|
@@ -1575,105 +1685,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1575
1685
|
};
|
|
1576
1686
|
}
|
|
1577
1687
|
};
|
|
1578
|
-
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1579
|
-
id: z5.string().optional(),
|
|
1580
|
-
model: z5.string().optional(),
|
|
1581
|
-
usage: z5.object({
|
|
1582
|
-
prompt_tokens: z5.number(),
|
|
1583
|
-
prompt_tokens_details: z5.object({
|
|
1584
|
-
cached_tokens: z5.number()
|
|
1585
|
-
}).nullish(),
|
|
1586
|
-
completion_tokens: z5.number(),
|
|
1587
|
-
completion_tokens_details: z5.object({
|
|
1588
|
-
reasoning_tokens: z5.number()
|
|
1589
|
-
}).nullish(),
|
|
1590
|
-
total_tokens: z5.number(),
|
|
1591
|
-
cost: z5.number().optional()
|
|
1592
|
-
}).nullish()
|
|
1593
|
-
});
|
|
1594
|
-
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1595
|
-
choices: z5.array(
|
|
1596
|
-
z5.object({
|
|
1597
|
-
message: z5.object({
|
|
1598
|
-
role: z5.literal("assistant"),
|
|
1599
|
-
content: z5.string().nullable().optional(),
|
|
1600
|
-
reasoning: z5.string().nullable().optional(),
|
|
1601
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1602
|
-
tool_calls: z5.array(
|
|
1603
|
-
z5.object({
|
|
1604
|
-
id: z5.string().optional().nullable(),
|
|
1605
|
-
type: z5.literal("function"),
|
|
1606
|
-
function: z5.object({
|
|
1607
|
-
name: z5.string(),
|
|
1608
|
-
arguments: z5.string()
|
|
1609
|
-
})
|
|
1610
|
-
})
|
|
1611
|
-
).optional()
|
|
1612
|
-
}),
|
|
1613
|
-
index: z5.number(),
|
|
1614
|
-
logprobs: z5.object({
|
|
1615
|
-
content: z5.array(
|
|
1616
|
-
z5.object({
|
|
1617
|
-
token: z5.string(),
|
|
1618
|
-
logprob: z5.number(),
|
|
1619
|
-
top_logprobs: z5.array(
|
|
1620
|
-
z5.object({
|
|
1621
|
-
token: z5.string(),
|
|
1622
|
-
logprob: z5.number()
|
|
1623
|
-
})
|
|
1624
|
-
)
|
|
1625
|
-
})
|
|
1626
|
-
).nullable()
|
|
1627
|
-
}).nullable().optional(),
|
|
1628
|
-
finish_reason: z5.string().optional().nullable()
|
|
1629
|
-
})
|
|
1630
|
-
)
|
|
1631
|
-
});
|
|
1632
|
-
var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
1633
|
-
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1634
|
-
choices: z5.array(
|
|
1635
|
-
z5.object({
|
|
1636
|
-
delta: z5.object({
|
|
1637
|
-
role: z5.enum(["assistant"]).optional(),
|
|
1638
|
-
content: z5.string().nullish(),
|
|
1639
|
-
reasoning: z5.string().nullish().optional(),
|
|
1640
|
-
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1641
|
-
tool_calls: z5.array(
|
|
1642
|
-
z5.object({
|
|
1643
|
-
index: z5.number(),
|
|
1644
|
-
id: z5.string().nullish(),
|
|
1645
|
-
type: z5.literal("function").optional(),
|
|
1646
|
-
function: z5.object({
|
|
1647
|
-
name: z5.string().nullish(),
|
|
1648
|
-
arguments: z5.string().nullish()
|
|
1649
|
-
})
|
|
1650
|
-
})
|
|
1651
|
-
).nullish()
|
|
1652
|
-
}).nullish(),
|
|
1653
|
-
logprobs: z5.object({
|
|
1654
|
-
content: z5.array(
|
|
1655
|
-
z5.object({
|
|
1656
|
-
token: z5.string(),
|
|
1657
|
-
logprob: z5.number(),
|
|
1658
|
-
top_logprobs: z5.array(
|
|
1659
|
-
z5.object({
|
|
1660
|
-
token: z5.string(),
|
|
1661
|
-
logprob: z5.number()
|
|
1662
|
-
})
|
|
1663
|
-
)
|
|
1664
|
-
})
|
|
1665
|
-
).nullable()
|
|
1666
|
-
}).nullish(),
|
|
1667
|
-
finish_reason: z5.string().nullable().optional(),
|
|
1668
|
-
index: z5.number()
|
|
1669
|
-
})
|
|
1670
|
-
)
|
|
1671
|
-
}),
|
|
1672
|
-
OpenRouterErrorResponseSchema
|
|
1673
|
-
]);
|
|
1674
|
-
|
|
1675
|
-
// src/completion/index.ts
|
|
1676
|
-
import { z as z6 } from "zod/v4";
|
|
1677
1688
|
|
|
1678
1689
|
// src/completion/convert-to-openrouter-completion-prompt.ts
|
|
1679
1690
|
function convertToOpenRouterCompletionPrompt({
|
|
@@ -1778,7 +1789,8 @@ ${assistantMessage}
|
|
|
1778
1789
|
};
|
|
1779
1790
|
}
|
|
1780
1791
|
|
|
1781
|
-
// src/completion/
|
|
1792
|
+
// src/completion/schemas.ts
|
|
1793
|
+
import { z as z6 } from "zod/v4";
|
|
1782
1794
|
var OpenRouterCompletionChunkSchema = z6.union([
|
|
1783
1795
|
z6.object({
|
|
1784
1796
|
id: z6.string().optional(),
|
|
@@ -1789,7 +1801,7 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1789
1801
|
reasoning: z6.string().nullish().optional(),
|
|
1790
1802
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1791
1803
|
finish_reason: z6.string().nullish(),
|
|
1792
|
-
index: z6.number(),
|
|
1804
|
+
index: z6.number().nullish(),
|
|
1793
1805
|
logprobs: z6.object({
|
|
1794
1806
|
tokens: z6.array(z6.string()),
|
|
1795
1807
|
token_logprobs: z6.array(z6.number()),
|
|
@@ -1812,6 +1824,8 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1812
1824
|
}),
|
|
1813
1825
|
OpenRouterErrorResponseSchema
|
|
1814
1826
|
]);
|
|
1827
|
+
|
|
1828
|
+
// src/completion/index.ts
|
|
1815
1829
|
var OpenRouterCompletionLanguageModel = class {
|
|
1816
1830
|
constructor(modelId, settings, config) {
|
|
1817
1831
|
this.specificationVersion = "v2";
|