@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.mjs
CHANGED
|
@@ -412,28 +412,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
415
|
+
// 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
|
|
416
416
|
import * as z4 from "zod/v4";
|
|
417
417
|
|
|
418
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
418
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
419
419
|
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
420
420
|
|
|
421
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
421
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
422
422
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
423
423
|
|
|
424
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
424
|
+
// 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
|
|
425
425
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
426
426
|
|
|
427
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
427
|
+
// 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
|
|
428
428
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
429
429
|
|
|
430
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
430
|
+
// 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
|
|
431
431
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
432
432
|
|
|
433
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
433
|
+
// 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
|
|
434
434
|
import { ZodOptional } from "zod";
|
|
435
435
|
|
|
436
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
436
|
+
// 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
|
|
437
437
|
function combineHeaders(...headers) {
|
|
438
438
|
return headers.reduce(
|
|
439
439
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -470,7 +470,8 @@ var createIdGenerator = ({
|
|
|
470
470
|
};
|
|
471
471
|
var generateId = createIdGenerator();
|
|
472
472
|
function isAbortError(error) {
|
|
473
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
473
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
474
|
+
error.name === "TimeoutError");
|
|
474
475
|
}
|
|
475
476
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
476
477
|
function handleFetchError({
|
|
@@ -884,9 +885,6 @@ function withoutTrailingSlash(url) {
|
|
|
884
885
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
885
886
|
}
|
|
886
887
|
|
|
887
|
-
// src/chat/index.ts
|
|
888
|
-
import { z as z5 } from "zod/v4";
|
|
889
|
-
|
|
890
888
|
// src/schemas/reasoning-details.ts
|
|
891
889
|
import { z } from "zod/v4";
|
|
892
890
|
var ReasoningDetailSummarySchema = z.object({
|
|
@@ -917,10 +915,10 @@ var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).tran
|
|
|
917
915
|
import { z as z2 } from "zod/v4";
|
|
918
916
|
var OpenRouterErrorResponseSchema = z2.object({
|
|
919
917
|
error: z2.object({
|
|
920
|
-
code: z2.union([z2.string(), z2.number()]).nullable(),
|
|
918
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
921
919
|
message: z2.string(),
|
|
922
|
-
type: z2.string().nullable(),
|
|
923
|
-
param: z2.any().nullable()
|
|
920
|
+
type: z2.string().nullable().optional().default(null),
|
|
921
|
+
param: z2.any().nullable().optional().default(null)
|
|
924
922
|
})
|
|
925
923
|
});
|
|
926
924
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1135,6 +1133,108 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1135
1133
|
}
|
|
1136
1134
|
}
|
|
1137
1135
|
|
|
1136
|
+
// src/chat/schemas.ts
|
|
1137
|
+
import { z as z5 } from "zod/v4";
|
|
1138
|
+
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1139
|
+
id: z5.string().optional(),
|
|
1140
|
+
model: z5.string().optional(),
|
|
1141
|
+
usage: z5.object({
|
|
1142
|
+
prompt_tokens: z5.number(),
|
|
1143
|
+
prompt_tokens_details: z5.object({
|
|
1144
|
+
cached_tokens: z5.number()
|
|
1145
|
+
}).nullish(),
|
|
1146
|
+
completion_tokens: z5.number(),
|
|
1147
|
+
completion_tokens_details: z5.object({
|
|
1148
|
+
reasoning_tokens: z5.number()
|
|
1149
|
+
}).nullish(),
|
|
1150
|
+
total_tokens: z5.number(),
|
|
1151
|
+
cost: z5.number().optional(),
|
|
1152
|
+
cost_details: z5.object({
|
|
1153
|
+
upstream_inference_cost: z5.number().nullish()
|
|
1154
|
+
}).nullish()
|
|
1155
|
+
}).nullish()
|
|
1156
|
+
});
|
|
1157
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1158
|
+
choices: z5.array(
|
|
1159
|
+
z5.object({
|
|
1160
|
+
message: z5.object({
|
|
1161
|
+
role: z5.literal("assistant"),
|
|
1162
|
+
content: z5.string().nullable().optional(),
|
|
1163
|
+
reasoning: z5.string().nullable().optional(),
|
|
1164
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1165
|
+
tool_calls: z5.array(
|
|
1166
|
+
z5.object({
|
|
1167
|
+
id: z5.string().optional().nullable(),
|
|
1168
|
+
type: z5.literal("function"),
|
|
1169
|
+
function: z5.object({
|
|
1170
|
+
name: z5.string(),
|
|
1171
|
+
arguments: z5.string()
|
|
1172
|
+
})
|
|
1173
|
+
})
|
|
1174
|
+
).optional()
|
|
1175
|
+
}),
|
|
1176
|
+
index: z5.number().nullish(),
|
|
1177
|
+
logprobs: z5.object({
|
|
1178
|
+
content: z5.array(
|
|
1179
|
+
z5.object({
|
|
1180
|
+
token: z5.string(),
|
|
1181
|
+
logprob: z5.number(),
|
|
1182
|
+
top_logprobs: z5.array(
|
|
1183
|
+
z5.object({
|
|
1184
|
+
token: z5.string(),
|
|
1185
|
+
logprob: z5.number()
|
|
1186
|
+
})
|
|
1187
|
+
)
|
|
1188
|
+
})
|
|
1189
|
+
).nullable()
|
|
1190
|
+
}).nullable().optional(),
|
|
1191
|
+
finish_reason: z5.string().optional().nullable()
|
|
1192
|
+
})
|
|
1193
|
+
)
|
|
1194
|
+
});
|
|
1195
|
+
var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
1196
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1197
|
+
choices: z5.array(
|
|
1198
|
+
z5.object({
|
|
1199
|
+
delta: z5.object({
|
|
1200
|
+
role: z5.enum(["assistant"]).optional(),
|
|
1201
|
+
content: z5.string().nullish(),
|
|
1202
|
+
reasoning: z5.string().nullish().optional(),
|
|
1203
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1204
|
+
tool_calls: z5.array(
|
|
1205
|
+
z5.object({
|
|
1206
|
+
index: z5.number().nullish(),
|
|
1207
|
+
id: z5.string().nullish(),
|
|
1208
|
+
type: z5.literal("function").optional(),
|
|
1209
|
+
function: z5.object({
|
|
1210
|
+
name: z5.string().nullish(),
|
|
1211
|
+
arguments: z5.string().nullish()
|
|
1212
|
+
})
|
|
1213
|
+
})
|
|
1214
|
+
).nullish()
|
|
1215
|
+
}).nullish(),
|
|
1216
|
+
logprobs: z5.object({
|
|
1217
|
+
content: z5.array(
|
|
1218
|
+
z5.object({
|
|
1219
|
+
token: z5.string(),
|
|
1220
|
+
logprob: z5.number(),
|
|
1221
|
+
top_logprobs: z5.array(
|
|
1222
|
+
z5.object({
|
|
1223
|
+
token: z5.string(),
|
|
1224
|
+
logprob: z5.number()
|
|
1225
|
+
})
|
|
1226
|
+
)
|
|
1227
|
+
})
|
|
1228
|
+
).nullable()
|
|
1229
|
+
}).nullish(),
|
|
1230
|
+
finish_reason: z5.string().nullable().optional(),
|
|
1231
|
+
index: z5.number().nullish()
|
|
1232
|
+
})
|
|
1233
|
+
)
|
|
1234
|
+
}),
|
|
1235
|
+
OpenRouterErrorResponseSchema
|
|
1236
|
+
]);
|
|
1237
|
+
|
|
1138
1238
|
// src/chat/index.ts
|
|
1139
1239
|
var OpenRouterChatLanguageModel = class {
|
|
1140
1240
|
constructor(modelId, settings, config) {
|
|
@@ -1216,7 +1316,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1216
1316
|
return baseArgs;
|
|
1217
1317
|
}
|
|
1218
1318
|
async doGenerate(options) {
|
|
1219
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1319
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1220
1320
|
const providerOptions = options.providerOptions || {};
|
|
1221
1321
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1222
1322
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1328,6 +1428,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1328
1428
|
},
|
|
1329
1429
|
completionTokensDetails: {
|
|
1330
1430
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1431
|
+
},
|
|
1432
|
+
costDetails: {
|
|
1433
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1331
1434
|
}
|
|
1332
1435
|
}
|
|
1333
1436
|
}
|
|
@@ -1375,11 +1478,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1375
1478
|
cachedInputTokens: Number.NaN
|
|
1376
1479
|
};
|
|
1377
1480
|
const openrouterUsage = {};
|
|
1481
|
+
let textStarted = false;
|
|
1482
|
+
let reasoningStarted = false;
|
|
1378
1483
|
return {
|
|
1379
1484
|
stream: response.pipeThrough(
|
|
1380
1485
|
new TransformStream({
|
|
1381
1486
|
transform(chunk, controller) {
|
|
1382
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1487
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1383
1488
|
if (!chunk.success) {
|
|
1384
1489
|
finishReason = "error";
|
|
1385
1490
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1435,55 +1540,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1435
1540
|
}
|
|
1436
1541
|
const delta = choice.delta;
|
|
1437
1542
|
if (delta.content != null) {
|
|
1543
|
+
if (!textStarted) {
|
|
1544
|
+
controller.enqueue({
|
|
1545
|
+
type: "text-start",
|
|
1546
|
+
id: generateId()
|
|
1547
|
+
});
|
|
1548
|
+
textStarted = true;
|
|
1549
|
+
}
|
|
1438
1550
|
controller.enqueue({
|
|
1439
1551
|
type: "text-delta",
|
|
1440
1552
|
delta: delta.content,
|
|
1441
1553
|
id: generateId()
|
|
1442
1554
|
});
|
|
1443
1555
|
}
|
|
1444
|
-
|
|
1556
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1557
|
+
if (!reasoningStarted) {
|
|
1558
|
+
controller.enqueue({
|
|
1559
|
+
type: "reasoning-start",
|
|
1560
|
+
id: generateId()
|
|
1561
|
+
});
|
|
1562
|
+
reasoningStarted = true;
|
|
1563
|
+
}
|
|
1445
1564
|
controller.enqueue({
|
|
1446
1565
|
type: "reasoning-delta",
|
|
1447
|
-
delta:
|
|
1566
|
+
delta: chunkText,
|
|
1448
1567
|
id: generateId()
|
|
1449
1568
|
});
|
|
1569
|
+
};
|
|
1570
|
+
if (delta.reasoning != null) {
|
|
1571
|
+
emitReasoningChunk(delta.reasoning);
|
|
1450
1572
|
}
|
|
1451
1573
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1452
1574
|
for (const detail of delta.reasoning_details) {
|
|
1453
1575
|
switch (detail.type) {
|
|
1454
1576
|
case "reasoning.text" /* Text */: {
|
|
1455
1577
|
if (detail.text) {
|
|
1456
|
-
|
|
1457
|
-
type: "reasoning-delta",
|
|
1458
|
-
delta: detail.text,
|
|
1459
|
-
id: generateId()
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
if (detail.signature) {
|
|
1463
|
-
controller.enqueue({
|
|
1464
|
-
type: "reasoning-end",
|
|
1465
|
-
id: generateId()
|
|
1466
|
-
});
|
|
1578
|
+
emitReasoningChunk(detail.text);
|
|
1467
1579
|
}
|
|
1468
1580
|
break;
|
|
1469
1581
|
}
|
|
1470
1582
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1471
1583
|
if (detail.data) {
|
|
1472
|
-
|
|
1473
|
-
type: "reasoning-delta",
|
|
1474
|
-
delta: "[REDACTED]",
|
|
1475
|
-
id: generateId()
|
|
1476
|
-
});
|
|
1584
|
+
emitReasoningChunk("[REDACTED]");
|
|
1477
1585
|
}
|
|
1478
1586
|
break;
|
|
1479
1587
|
}
|
|
1480
1588
|
case "reasoning.summary" /* Summary */: {
|
|
1481
1589
|
if (detail.summary) {
|
|
1482
|
-
|
|
1483
|
-
type: "reasoning-delta",
|
|
1484
|
-
delta: detail.summary,
|
|
1485
|
-
id: generateId()
|
|
1486
|
-
});
|
|
1590
|
+
emitReasoningChunk(detail.summary);
|
|
1487
1591
|
}
|
|
1488
1592
|
break;
|
|
1489
1593
|
}
|
|
@@ -1496,7 +1600,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1496
1600
|
}
|
|
1497
1601
|
if (delta.tool_calls != null) {
|
|
1498
1602
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1499
|
-
const index = toolCallDelta.index;
|
|
1603
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
1500
1604
|
if (toolCalls[index] == null) {
|
|
1501
1605
|
if (toolCallDelta.type !== "function") {
|
|
1502
1606
|
throw new InvalidResponseDataError({
|
|
@@ -1510,7 +1614,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1510
1614
|
message: `Expected 'id' to be a string.`
|
|
1511
1615
|
});
|
|
1512
1616
|
}
|
|
1513
|
-
if (((
|
|
1617
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
1514
1618
|
throw new InvalidResponseDataError({
|
|
1515
1619
|
data: toolCallDelta,
|
|
1516
1620
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1521,7 +1625,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1521
1625
|
type: "function",
|
|
1522
1626
|
function: {
|
|
1523
1627
|
name: toolCallDelta.function.name,
|
|
1524
|
-
arguments: (
|
|
1628
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1525
1629
|
},
|
|
1526
1630
|
sent: false
|
|
1527
1631
|
};
|
|
@@ -1529,7 +1633,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1529
1633
|
if (toolCall2 == null) {
|
|
1530
1634
|
throw new Error("Tool call is missing");
|
|
1531
1635
|
}
|
|
1532
|
-
if (((
|
|
1636
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1533
1637
|
controller.enqueue({
|
|
1534
1638
|
type: "tool-input-start",
|
|
1535
1639
|
id: toolCall2.id,
|
|
@@ -1558,25 +1662,25 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1558
1662
|
if (toolCall == null) {
|
|
1559
1663
|
throw new Error("Tool call is missing");
|
|
1560
1664
|
}
|
|
1561
|
-
if (((
|
|
1665
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
|
|
1562
1666
|
controller.enqueue({
|
|
1563
1667
|
type: "tool-input-start",
|
|
1564
1668
|
id: toolCall.id,
|
|
1565
1669
|
toolName: toolCall.function.name
|
|
1566
1670
|
});
|
|
1567
1671
|
}
|
|
1568
|
-
if (((
|
|
1569
|
-
toolCall.function.arguments += (
|
|
1672
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
1673
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
1570
1674
|
}
|
|
1571
1675
|
controller.enqueue({
|
|
1572
1676
|
type: "tool-input-delta",
|
|
1573
1677
|
id: toolCall.id,
|
|
1574
|
-
delta: (
|
|
1678
|
+
delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
1575
1679
|
});
|
|
1576
|
-
if (((
|
|
1680
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1577
1681
|
controller.enqueue({
|
|
1578
1682
|
type: "tool-call",
|
|
1579
|
-
toolCallId: (
|
|
1683
|
+
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
1580
1684
|
toolName: toolCall.function.name,
|
|
1581
1685
|
input: toolCall.function.arguments
|
|
1582
1686
|
});
|
|
@@ -1601,6 +1705,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1601
1705
|
}
|
|
1602
1706
|
}
|
|
1603
1707
|
}
|
|
1708
|
+
if (textStarted) {
|
|
1709
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1710
|
+
}
|
|
1711
|
+
if (reasoningStarted) {
|
|
1712
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1713
|
+
}
|
|
1604
1714
|
controller.enqueue({
|
|
1605
1715
|
type: "finish",
|
|
1606
1716
|
finishReason,
|
|
@@ -1620,105 +1730,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1620
1730
|
};
|
|
1621
1731
|
}
|
|
1622
1732
|
};
|
|
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
1733
|
|
|
1723
1734
|
// src/completion/convert-to-openrouter-completion-prompt.ts
|
|
1724
1735
|
function convertToOpenRouterCompletionPrompt({
|
|
@@ -1823,7 +1834,8 @@ ${assistantMessage}
|
|
|
1823
1834
|
};
|
|
1824
1835
|
}
|
|
1825
1836
|
|
|
1826
|
-
// src/completion/
|
|
1837
|
+
// src/completion/schemas.ts
|
|
1838
|
+
import { z as z6 } from "zod/v4";
|
|
1827
1839
|
var OpenRouterCompletionChunkSchema = z6.union([
|
|
1828
1840
|
z6.object({
|
|
1829
1841
|
id: z6.string().optional(),
|
|
@@ -1834,7 +1846,7 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1834
1846
|
reasoning: z6.string().nullish().optional(),
|
|
1835
1847
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1836
1848
|
finish_reason: z6.string().nullish(),
|
|
1837
|
-
index: z6.number(),
|
|
1849
|
+
index: z6.number().nullish(),
|
|
1838
1850
|
logprobs: z6.object({
|
|
1839
1851
|
tokens: z6.array(z6.string()),
|
|
1840
1852
|
token_logprobs: z6.array(z6.number()),
|
|
@@ -1857,6 +1869,8 @@ var OpenRouterCompletionChunkSchema = z6.union([
|
|
|
1857
1869
|
}),
|
|
1858
1870
|
OpenRouterErrorResponseSchema
|
|
1859
1871
|
]);
|
|
1872
|
+
|
|
1873
|
+
// src/completion/index.ts
|
|
1860
1874
|
var OpenRouterCompletionLanguageModel = class {
|
|
1861
1875
|
constructor(modelId, settings, config) {
|
|
1862
1876
|
this.specificationVersion = "v2";
|