@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.d.ts
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -436,28 +436,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
436
436
|
}
|
|
437
437
|
};
|
|
438
438
|
|
|
439
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
439
|
+
// 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
|
|
440
440
|
var z4 = __toESM(require("zod/v4"), 1);
|
|
441
441
|
|
|
442
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
442
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
443
443
|
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
444
444
|
|
|
445
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
445
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
446
446
|
var import_zod4 = require("zod");
|
|
447
447
|
|
|
448
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
448
|
+
// 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
|
|
449
449
|
var import_zod = require("zod");
|
|
450
450
|
|
|
451
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
451
|
+
// 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
|
|
452
452
|
var import_zod2 = require("zod");
|
|
453
453
|
|
|
454
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
454
|
+
// 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
|
|
455
455
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
456
456
|
|
|
457
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
457
|
+
// 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
|
|
458
458
|
var import_zod3 = require("zod");
|
|
459
459
|
|
|
460
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
460
|
+
// 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
|
|
461
461
|
function combineHeaders(...headers) {
|
|
462
462
|
return headers.reduce(
|
|
463
463
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -494,7 +494,8 @@ var createIdGenerator = ({
|
|
|
494
494
|
};
|
|
495
495
|
var generateId = createIdGenerator();
|
|
496
496
|
function isAbortError(error) {
|
|
497
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
497
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
498
|
+
error.name === "TimeoutError");
|
|
498
499
|
}
|
|
499
500
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
500
501
|
function handleFetchError({
|
|
@@ -873,9 +874,6 @@ function convertUint8ArrayToBase64(array) {
|
|
|
873
874
|
return btoa(latin1string);
|
|
874
875
|
}
|
|
875
876
|
|
|
876
|
-
// src/chat/index.ts
|
|
877
|
-
var import_v44 = require("zod/v4");
|
|
878
|
-
|
|
879
877
|
// src/schemas/reasoning-details.ts
|
|
880
878
|
var import_v4 = require("zod/v4");
|
|
881
879
|
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
@@ -906,10 +904,10 @@ var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSc
|
|
|
906
904
|
var import_v42 = require("zod/v4");
|
|
907
905
|
var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
908
906
|
error: import_v42.z.object({
|
|
909
|
-
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullable(),
|
|
907
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullable().optional().default(null),
|
|
910
908
|
message: import_v42.z.string(),
|
|
911
|
-
type: import_v42.z.string().nullable(),
|
|
912
|
-
param: import_v42.z.any().nullable()
|
|
909
|
+
type: import_v42.z.string().nullable().optional().default(null),
|
|
910
|
+
param: import_v42.z.any().nullable().optional().default(null)
|
|
913
911
|
})
|
|
914
912
|
});
|
|
915
913
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1124,6 +1122,108 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1124
1122
|
}
|
|
1125
1123
|
}
|
|
1126
1124
|
|
|
1125
|
+
// src/chat/schemas.ts
|
|
1126
|
+
var import_v44 = require("zod/v4");
|
|
1127
|
+
var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
1128
|
+
id: import_v44.z.string().optional(),
|
|
1129
|
+
model: import_v44.z.string().optional(),
|
|
1130
|
+
usage: import_v44.z.object({
|
|
1131
|
+
prompt_tokens: import_v44.z.number(),
|
|
1132
|
+
prompt_tokens_details: import_v44.z.object({
|
|
1133
|
+
cached_tokens: import_v44.z.number()
|
|
1134
|
+
}).nullish(),
|
|
1135
|
+
completion_tokens: import_v44.z.number(),
|
|
1136
|
+
completion_tokens_details: import_v44.z.object({
|
|
1137
|
+
reasoning_tokens: import_v44.z.number()
|
|
1138
|
+
}).nullish(),
|
|
1139
|
+
total_tokens: import_v44.z.number(),
|
|
1140
|
+
cost: import_v44.z.number().optional(),
|
|
1141
|
+
cost_details: import_v44.z.object({
|
|
1142
|
+
upstream_inference_cost: import_v44.z.number().nullish()
|
|
1143
|
+
}).nullish()
|
|
1144
|
+
}).nullish()
|
|
1145
|
+
});
|
|
1146
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1147
|
+
choices: import_v44.z.array(
|
|
1148
|
+
import_v44.z.object({
|
|
1149
|
+
message: import_v44.z.object({
|
|
1150
|
+
role: import_v44.z.literal("assistant"),
|
|
1151
|
+
content: import_v44.z.string().nullable().optional(),
|
|
1152
|
+
reasoning: import_v44.z.string().nullable().optional(),
|
|
1153
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1154
|
+
tool_calls: import_v44.z.array(
|
|
1155
|
+
import_v44.z.object({
|
|
1156
|
+
id: import_v44.z.string().optional().nullable(),
|
|
1157
|
+
type: import_v44.z.literal("function"),
|
|
1158
|
+
function: import_v44.z.object({
|
|
1159
|
+
name: import_v44.z.string(),
|
|
1160
|
+
arguments: import_v44.z.string()
|
|
1161
|
+
})
|
|
1162
|
+
})
|
|
1163
|
+
).optional()
|
|
1164
|
+
}),
|
|
1165
|
+
index: import_v44.z.number().nullish(),
|
|
1166
|
+
logprobs: import_v44.z.object({
|
|
1167
|
+
content: import_v44.z.array(
|
|
1168
|
+
import_v44.z.object({
|
|
1169
|
+
token: import_v44.z.string(),
|
|
1170
|
+
logprob: import_v44.z.number(),
|
|
1171
|
+
top_logprobs: import_v44.z.array(
|
|
1172
|
+
import_v44.z.object({
|
|
1173
|
+
token: import_v44.z.string(),
|
|
1174
|
+
logprob: import_v44.z.number()
|
|
1175
|
+
})
|
|
1176
|
+
)
|
|
1177
|
+
})
|
|
1178
|
+
).nullable()
|
|
1179
|
+
}).nullable().optional(),
|
|
1180
|
+
finish_reason: import_v44.z.string().optional().nullable()
|
|
1181
|
+
})
|
|
1182
|
+
)
|
|
1183
|
+
});
|
|
1184
|
+
var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
|
|
1185
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1186
|
+
choices: import_v44.z.array(
|
|
1187
|
+
import_v44.z.object({
|
|
1188
|
+
delta: import_v44.z.object({
|
|
1189
|
+
role: import_v44.z.enum(["assistant"]).optional(),
|
|
1190
|
+
content: import_v44.z.string().nullish(),
|
|
1191
|
+
reasoning: import_v44.z.string().nullish().optional(),
|
|
1192
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1193
|
+
tool_calls: import_v44.z.array(
|
|
1194
|
+
import_v44.z.object({
|
|
1195
|
+
index: import_v44.z.number().nullish(),
|
|
1196
|
+
id: import_v44.z.string().nullish(),
|
|
1197
|
+
type: import_v44.z.literal("function").optional(),
|
|
1198
|
+
function: import_v44.z.object({
|
|
1199
|
+
name: import_v44.z.string().nullish(),
|
|
1200
|
+
arguments: import_v44.z.string().nullish()
|
|
1201
|
+
})
|
|
1202
|
+
})
|
|
1203
|
+
).nullish()
|
|
1204
|
+
}).nullish(),
|
|
1205
|
+
logprobs: import_v44.z.object({
|
|
1206
|
+
content: import_v44.z.array(
|
|
1207
|
+
import_v44.z.object({
|
|
1208
|
+
token: import_v44.z.string(),
|
|
1209
|
+
logprob: import_v44.z.number(),
|
|
1210
|
+
top_logprobs: import_v44.z.array(
|
|
1211
|
+
import_v44.z.object({
|
|
1212
|
+
token: import_v44.z.string(),
|
|
1213
|
+
logprob: import_v44.z.number()
|
|
1214
|
+
})
|
|
1215
|
+
)
|
|
1216
|
+
})
|
|
1217
|
+
).nullable()
|
|
1218
|
+
}).nullish(),
|
|
1219
|
+
finish_reason: import_v44.z.string().nullable().optional(),
|
|
1220
|
+
index: import_v44.z.number().nullish()
|
|
1221
|
+
})
|
|
1222
|
+
)
|
|
1223
|
+
}),
|
|
1224
|
+
OpenRouterErrorResponseSchema
|
|
1225
|
+
]);
|
|
1226
|
+
|
|
1127
1227
|
// src/chat/index.ts
|
|
1128
1228
|
var OpenRouterChatLanguageModel = class {
|
|
1129
1229
|
constructor(modelId, settings, config) {
|
|
@@ -1205,7 +1305,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1205
1305
|
return baseArgs;
|
|
1206
1306
|
}
|
|
1207
1307
|
async doGenerate(options) {
|
|
1208
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1308
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1209
1309
|
const providerOptions = options.providerOptions || {};
|
|
1210
1310
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1211
1311
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1317,6 +1417,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1317
1417
|
},
|
|
1318
1418
|
completionTokensDetails: {
|
|
1319
1419
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1420
|
+
},
|
|
1421
|
+
costDetails: {
|
|
1422
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1320
1423
|
}
|
|
1321
1424
|
}
|
|
1322
1425
|
}
|
|
@@ -1364,11 +1467,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1364
1467
|
cachedInputTokens: Number.NaN
|
|
1365
1468
|
};
|
|
1366
1469
|
const openrouterUsage = {};
|
|
1470
|
+
let textStarted = false;
|
|
1471
|
+
let reasoningStarted = false;
|
|
1367
1472
|
return {
|
|
1368
1473
|
stream: response.pipeThrough(
|
|
1369
1474
|
new TransformStream({
|
|
1370
1475
|
transform(chunk, controller) {
|
|
1371
|
-
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1476
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1372
1477
|
if (!chunk.success) {
|
|
1373
1478
|
finishReason = "error";
|
|
1374
1479
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1424,55 +1529,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1424
1529
|
}
|
|
1425
1530
|
const delta = choice.delta;
|
|
1426
1531
|
if (delta.content != null) {
|
|
1532
|
+
if (!textStarted) {
|
|
1533
|
+
controller.enqueue({
|
|
1534
|
+
type: "text-start",
|
|
1535
|
+
id: generateId()
|
|
1536
|
+
});
|
|
1537
|
+
textStarted = true;
|
|
1538
|
+
}
|
|
1427
1539
|
controller.enqueue({
|
|
1428
1540
|
type: "text-delta",
|
|
1429
1541
|
delta: delta.content,
|
|
1430
1542
|
id: generateId()
|
|
1431
1543
|
});
|
|
1432
1544
|
}
|
|
1433
|
-
|
|
1545
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1546
|
+
if (!reasoningStarted) {
|
|
1547
|
+
controller.enqueue({
|
|
1548
|
+
type: "reasoning-start",
|
|
1549
|
+
id: generateId()
|
|
1550
|
+
});
|
|
1551
|
+
reasoningStarted = true;
|
|
1552
|
+
}
|
|
1434
1553
|
controller.enqueue({
|
|
1435
1554
|
type: "reasoning-delta",
|
|
1436
|
-
delta:
|
|
1555
|
+
delta: chunkText,
|
|
1437
1556
|
id: generateId()
|
|
1438
1557
|
});
|
|
1558
|
+
};
|
|
1559
|
+
if (delta.reasoning != null) {
|
|
1560
|
+
emitReasoningChunk(delta.reasoning);
|
|
1439
1561
|
}
|
|
1440
1562
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1441
1563
|
for (const detail of delta.reasoning_details) {
|
|
1442
1564
|
switch (detail.type) {
|
|
1443
1565
|
case "reasoning.text" /* Text */: {
|
|
1444
1566
|
if (detail.text) {
|
|
1445
|
-
|
|
1446
|
-
type: "reasoning-delta",
|
|
1447
|
-
delta: detail.text,
|
|
1448
|
-
id: generateId()
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
if (detail.signature) {
|
|
1452
|
-
controller.enqueue({
|
|
1453
|
-
type: "reasoning-end",
|
|
1454
|
-
id: generateId()
|
|
1455
|
-
});
|
|
1567
|
+
emitReasoningChunk(detail.text);
|
|
1456
1568
|
}
|
|
1457
1569
|
break;
|
|
1458
1570
|
}
|
|
1459
1571
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1460
1572
|
if (detail.data) {
|
|
1461
|
-
|
|
1462
|
-
type: "reasoning-delta",
|
|
1463
|
-
delta: "[REDACTED]",
|
|
1464
|
-
id: generateId()
|
|
1465
|
-
});
|
|
1573
|
+
emitReasoningChunk("[REDACTED]");
|
|
1466
1574
|
}
|
|
1467
1575
|
break;
|
|
1468
1576
|
}
|
|
1469
1577
|
case "reasoning.summary" /* Summary */: {
|
|
1470
1578
|
if (detail.summary) {
|
|
1471
|
-
|
|
1472
|
-
type: "reasoning-delta",
|
|
1473
|
-
delta: detail.summary,
|
|
1474
|
-
id: generateId()
|
|
1475
|
-
});
|
|
1579
|
+
emitReasoningChunk(detail.summary);
|
|
1476
1580
|
}
|
|
1477
1581
|
break;
|
|
1478
1582
|
}
|
|
@@ -1485,7 +1589,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1485
1589
|
}
|
|
1486
1590
|
if (delta.tool_calls != null) {
|
|
1487
1591
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1488
|
-
const index = toolCallDelta.index;
|
|
1592
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
1489
1593
|
if (toolCalls[index] == null) {
|
|
1490
1594
|
if (toolCallDelta.type !== "function") {
|
|
1491
1595
|
throw new InvalidResponseDataError({
|
|
@@ -1499,7 +1603,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1499
1603
|
message: `Expected 'id' to be a string.`
|
|
1500
1604
|
});
|
|
1501
1605
|
}
|
|
1502
|
-
if (((
|
|
1606
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
1503
1607
|
throw new InvalidResponseDataError({
|
|
1504
1608
|
data: toolCallDelta,
|
|
1505
1609
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1510,7 +1614,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1510
1614
|
type: "function",
|
|
1511
1615
|
function: {
|
|
1512
1616
|
name: toolCallDelta.function.name,
|
|
1513
|
-
arguments: (
|
|
1617
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
1514
1618
|
},
|
|
1515
1619
|
sent: false
|
|
1516
1620
|
};
|
|
@@ -1518,7 +1622,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1518
1622
|
if (toolCall2 == null) {
|
|
1519
1623
|
throw new Error("Tool call is missing");
|
|
1520
1624
|
}
|
|
1521
|
-
if (((
|
|
1625
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1522
1626
|
controller.enqueue({
|
|
1523
1627
|
type: "tool-input-start",
|
|
1524
1628
|
id: toolCall2.id,
|
|
@@ -1547,25 +1651,25 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1547
1651
|
if (toolCall == null) {
|
|
1548
1652
|
throw new Error("Tool call is missing");
|
|
1549
1653
|
}
|
|
1550
|
-
if (((
|
|
1654
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.name) != null) {
|
|
1551
1655
|
controller.enqueue({
|
|
1552
1656
|
type: "tool-input-start",
|
|
1553
1657
|
id: toolCall.id,
|
|
1554
1658
|
toolName: toolCall.function.name
|
|
1555
1659
|
});
|
|
1556
1660
|
}
|
|
1557
|
-
if (((
|
|
1558
|
-
toolCall.function.arguments += (
|
|
1661
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
1662
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
1559
1663
|
}
|
|
1560
1664
|
controller.enqueue({
|
|
1561
1665
|
type: "tool-input-delta",
|
|
1562
1666
|
id: toolCall.id,
|
|
1563
|
-
delta: (
|
|
1667
|
+
delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
1564
1668
|
});
|
|
1565
|
-
if (((
|
|
1669
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1566
1670
|
controller.enqueue({
|
|
1567
1671
|
type: "tool-call",
|
|
1568
|
-
toolCallId: (
|
|
1672
|
+
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
1569
1673
|
toolName: toolCall.function.name,
|
|
1570
1674
|
input: toolCall.function.arguments
|
|
1571
1675
|
});
|
|
@@ -1590,6 +1694,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1590
1694
|
}
|
|
1591
1695
|
}
|
|
1592
1696
|
}
|
|
1697
|
+
if (textStarted) {
|
|
1698
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1699
|
+
}
|
|
1700
|
+
if (reasoningStarted) {
|
|
1701
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1702
|
+
}
|
|
1593
1703
|
controller.enqueue({
|
|
1594
1704
|
type: "finish",
|
|
1595
1705
|
finishReason,
|
|
@@ -1609,105 +1719,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1609
1719
|
};
|
|
1610
1720
|
}
|
|
1611
1721
|
};
|
|
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
1722
|
|
|
1712
1723
|
// src/completion/convert-to-openrouter-completion-prompt.ts
|
|
1713
1724
|
function convertToOpenRouterCompletionPrompt({
|
|
@@ -1812,7 +1823,8 @@ ${assistantMessage}
|
|
|
1812
1823
|
};
|
|
1813
1824
|
}
|
|
1814
1825
|
|
|
1815
|
-
// src/completion/
|
|
1826
|
+
// src/completion/schemas.ts
|
|
1827
|
+
var import_v45 = require("zod/v4");
|
|
1816
1828
|
var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
1817
1829
|
import_v45.z.object({
|
|
1818
1830
|
id: import_v45.z.string().optional(),
|
|
@@ -1823,7 +1835,7 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
|
1823
1835
|
reasoning: import_v45.z.string().nullish().optional(),
|
|
1824
1836
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1825
1837
|
finish_reason: import_v45.z.string().nullish(),
|
|
1826
|
-
index: import_v45.z.number(),
|
|
1838
|
+
index: import_v45.z.number().nullish(),
|
|
1827
1839
|
logprobs: import_v45.z.object({
|
|
1828
1840
|
tokens: import_v45.z.array(import_v45.z.string()),
|
|
1829
1841
|
token_logprobs: import_v45.z.array(import_v45.z.number()),
|
|
@@ -1846,6 +1858,8 @@ var OpenRouterCompletionChunkSchema = import_v45.z.union([
|
|
|
1846
1858
|
}),
|
|
1847
1859
|
OpenRouterErrorResponseSchema
|
|
1848
1860
|
]);
|
|
1861
|
+
|
|
1862
|
+
// src/completion/index.ts
|
|
1849
1863
|
var OpenRouterCompletionLanguageModel = class {
|
|
1850
1864
|
constructor(modelId, settings, config) {
|
|
1851
1865
|
this.specificationVersion = "v2";
|