@openrouter/ai-sdk-provider 1.0.0-beta.1 → 1.0.0-beta.3
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 +59 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -39
- 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 +59 -39
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +59 -39
- 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({
|
|
@@ -903,10 +904,10 @@ var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSc
|
|
|
903
904
|
var import_v42 = require("zod/v4");
|
|
904
905
|
var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
905
906
|
error: import_v42.z.object({
|
|
906
|
-
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),
|
|
907
908
|
message: import_v42.z.string(),
|
|
908
|
-
type: import_v42.z.string().nullable(),
|
|
909
|
-
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)
|
|
910
911
|
})
|
|
911
912
|
});
|
|
912
913
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1136,7 +1137,10 @@ var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
|
1136
1137
|
reasoning_tokens: import_v44.z.number()
|
|
1137
1138
|
}).nullish(),
|
|
1138
1139
|
total_tokens: import_v44.z.number(),
|
|
1139
|
-
cost: import_v44.z.number().optional()
|
|
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()
|
|
1140
1144
|
}).nullish()
|
|
1141
1145
|
});
|
|
1142
1146
|
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
@@ -1301,7 +1305,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1301
1305
|
return baseArgs;
|
|
1302
1306
|
}
|
|
1303
1307
|
async doGenerate(options) {
|
|
1304
|
-
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;
|
|
1305
1309
|
const providerOptions = options.providerOptions || {};
|
|
1306
1310
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1307
1311
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1413,6 +1417,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1413
1417
|
},
|
|
1414
1418
|
completionTokensDetails: {
|
|
1415
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
|
|
1416
1423
|
}
|
|
1417
1424
|
}
|
|
1418
1425
|
}
|
|
@@ -1460,6 +1467,11 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1460
1467
|
cachedInputTokens: Number.NaN
|
|
1461
1468
|
};
|
|
1462
1469
|
const openrouterUsage = {};
|
|
1470
|
+
let textStarted = false;
|
|
1471
|
+
let reasoningStarted = false;
|
|
1472
|
+
let textId;
|
|
1473
|
+
let reasoningId;
|
|
1474
|
+
let openrouterResponseId;
|
|
1463
1475
|
return {
|
|
1464
1476
|
stream: response.pipeThrough(
|
|
1465
1477
|
new TransformStream({
|
|
@@ -1477,6 +1489,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1477
1489
|
return;
|
|
1478
1490
|
}
|
|
1479
1491
|
if (value.id) {
|
|
1492
|
+
openrouterResponseId = value.id;
|
|
1480
1493
|
controller.enqueue({
|
|
1481
1494
|
type: "response-metadata",
|
|
1482
1495
|
id: value.id
|
|
@@ -1520,55 +1533,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1520
1533
|
}
|
|
1521
1534
|
const delta = choice.delta;
|
|
1522
1535
|
if (delta.content != null) {
|
|
1536
|
+
if (!textStarted) {
|
|
1537
|
+
textId = openrouterResponseId || generateId();
|
|
1538
|
+
controller.enqueue({
|
|
1539
|
+
type: "text-start",
|
|
1540
|
+
id: textId
|
|
1541
|
+
});
|
|
1542
|
+
textStarted = true;
|
|
1543
|
+
}
|
|
1523
1544
|
controller.enqueue({
|
|
1524
1545
|
type: "text-delta",
|
|
1525
1546
|
delta: delta.content,
|
|
1526
|
-
id: generateId()
|
|
1547
|
+
id: textId || generateId()
|
|
1527
1548
|
});
|
|
1528
1549
|
}
|
|
1529
|
-
|
|
1550
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1551
|
+
if (!reasoningStarted) {
|
|
1552
|
+
reasoningId = openrouterResponseId || generateId();
|
|
1553
|
+
controller.enqueue({
|
|
1554
|
+
type: "reasoning-start",
|
|
1555
|
+
id: reasoningId
|
|
1556
|
+
});
|
|
1557
|
+
reasoningStarted = true;
|
|
1558
|
+
}
|
|
1530
1559
|
controller.enqueue({
|
|
1531
1560
|
type: "reasoning-delta",
|
|
1532
|
-
delta:
|
|
1533
|
-
id: generateId()
|
|
1561
|
+
delta: chunkText,
|
|
1562
|
+
id: reasoningId || generateId()
|
|
1534
1563
|
});
|
|
1564
|
+
};
|
|
1565
|
+
if (delta.reasoning != null) {
|
|
1566
|
+
emitReasoningChunk(delta.reasoning);
|
|
1535
1567
|
}
|
|
1536
1568
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1537
1569
|
for (const detail of delta.reasoning_details) {
|
|
1538
1570
|
switch (detail.type) {
|
|
1539
1571
|
case "reasoning.text" /* Text */: {
|
|
1540
1572
|
if (detail.text) {
|
|
1541
|
-
|
|
1542
|
-
type: "reasoning-delta",
|
|
1543
|
-
delta: detail.text,
|
|
1544
|
-
id: generateId()
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
if (detail.signature) {
|
|
1548
|
-
controller.enqueue({
|
|
1549
|
-
type: "reasoning-end",
|
|
1550
|
-
id: generateId()
|
|
1551
|
-
});
|
|
1573
|
+
emitReasoningChunk(detail.text);
|
|
1552
1574
|
}
|
|
1553
1575
|
break;
|
|
1554
1576
|
}
|
|
1555
1577
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1556
1578
|
if (detail.data) {
|
|
1557
|
-
|
|
1558
|
-
type: "reasoning-delta",
|
|
1559
|
-
delta: "[REDACTED]",
|
|
1560
|
-
id: generateId()
|
|
1561
|
-
});
|
|
1579
|
+
emitReasoningChunk("[REDACTED]");
|
|
1562
1580
|
}
|
|
1563
1581
|
break;
|
|
1564
1582
|
}
|
|
1565
1583
|
case "reasoning.summary" /* Summary */: {
|
|
1566
1584
|
if (detail.summary) {
|
|
1567
|
-
|
|
1568
|
-
type: "reasoning-delta",
|
|
1569
|
-
delta: detail.summary,
|
|
1570
|
-
id: generateId()
|
|
1571
|
-
});
|
|
1585
|
+
emitReasoningChunk(detail.summary);
|
|
1572
1586
|
}
|
|
1573
1587
|
break;
|
|
1574
1588
|
}
|
|
@@ -1686,6 +1700,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1686
1700
|
}
|
|
1687
1701
|
}
|
|
1688
1702
|
}
|
|
1703
|
+
if (textStarted) {
|
|
1704
|
+
controller.enqueue({ type: "text-end", id: textId || generateId() });
|
|
1705
|
+
}
|
|
1706
|
+
if (reasoningStarted) {
|
|
1707
|
+
controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
|
|
1708
|
+
}
|
|
1689
1709
|
controller.enqueue({
|
|
1690
1710
|
type: "finish",
|
|
1691
1711
|
finishReason,
|