@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/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({
|
|
@@ -949,10 +950,10 @@ var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSc
|
|
|
949
950
|
var import_v42 = require("zod/v4");
|
|
950
951
|
var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
951
952
|
error: import_v42.z.object({
|
|
952
|
-
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),
|
|
953
954
|
message: import_v42.z.string(),
|
|
954
|
-
type: import_v42.z.string().nullable(),
|
|
955
|
-
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)
|
|
956
957
|
})
|
|
957
958
|
});
|
|
958
959
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1182,7 +1183,10 @@ var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
|
1182
1183
|
reasoning_tokens: import_v44.z.number()
|
|
1183
1184
|
}).nullish(),
|
|
1184
1185
|
total_tokens: import_v44.z.number(),
|
|
1185
|
-
cost: import_v44.z.number().optional()
|
|
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()
|
|
1186
1190
|
}).nullish()
|
|
1187
1191
|
});
|
|
1188
1192
|
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
@@ -1347,7 +1351,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1347
1351
|
return baseArgs;
|
|
1348
1352
|
}
|
|
1349
1353
|
async doGenerate(options) {
|
|
1350
|
-
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;
|
|
1351
1355
|
const providerOptions = options.providerOptions || {};
|
|
1352
1356
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1353
1357
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1459,6 +1463,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1459
1463
|
},
|
|
1460
1464
|
completionTokensDetails: {
|
|
1461
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
|
|
1462
1469
|
}
|
|
1463
1470
|
}
|
|
1464
1471
|
}
|
|
@@ -1506,6 +1513,11 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1506
1513
|
cachedInputTokens: Number.NaN
|
|
1507
1514
|
};
|
|
1508
1515
|
const openrouterUsage = {};
|
|
1516
|
+
let textStarted = false;
|
|
1517
|
+
let reasoningStarted = false;
|
|
1518
|
+
let textId;
|
|
1519
|
+
let reasoningId;
|
|
1520
|
+
let openrouterResponseId;
|
|
1509
1521
|
return {
|
|
1510
1522
|
stream: response.pipeThrough(
|
|
1511
1523
|
new TransformStream({
|
|
@@ -1523,6 +1535,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1523
1535
|
return;
|
|
1524
1536
|
}
|
|
1525
1537
|
if (value.id) {
|
|
1538
|
+
openrouterResponseId = value.id;
|
|
1526
1539
|
controller.enqueue({
|
|
1527
1540
|
type: "response-metadata",
|
|
1528
1541
|
id: value.id
|
|
@@ -1566,55 +1579,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1566
1579
|
}
|
|
1567
1580
|
const delta = choice.delta;
|
|
1568
1581
|
if (delta.content != null) {
|
|
1582
|
+
if (!textStarted) {
|
|
1583
|
+
textId = openrouterResponseId || generateId();
|
|
1584
|
+
controller.enqueue({
|
|
1585
|
+
type: "text-start",
|
|
1586
|
+
id: textId
|
|
1587
|
+
});
|
|
1588
|
+
textStarted = true;
|
|
1589
|
+
}
|
|
1569
1590
|
controller.enqueue({
|
|
1570
1591
|
type: "text-delta",
|
|
1571
1592
|
delta: delta.content,
|
|
1572
|
-
id: generateId()
|
|
1593
|
+
id: textId || generateId()
|
|
1573
1594
|
});
|
|
1574
1595
|
}
|
|
1575
|
-
|
|
1596
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1597
|
+
if (!reasoningStarted) {
|
|
1598
|
+
reasoningId = openrouterResponseId || generateId();
|
|
1599
|
+
controller.enqueue({
|
|
1600
|
+
type: "reasoning-start",
|
|
1601
|
+
id: reasoningId
|
|
1602
|
+
});
|
|
1603
|
+
reasoningStarted = true;
|
|
1604
|
+
}
|
|
1576
1605
|
controller.enqueue({
|
|
1577
1606
|
type: "reasoning-delta",
|
|
1578
|
-
delta:
|
|
1579
|
-
id: generateId()
|
|
1607
|
+
delta: chunkText,
|
|
1608
|
+
id: reasoningId || generateId()
|
|
1580
1609
|
});
|
|
1610
|
+
};
|
|
1611
|
+
if (delta.reasoning != null) {
|
|
1612
|
+
emitReasoningChunk(delta.reasoning);
|
|
1581
1613
|
}
|
|
1582
1614
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1583
1615
|
for (const detail of delta.reasoning_details) {
|
|
1584
1616
|
switch (detail.type) {
|
|
1585
1617
|
case "reasoning.text" /* Text */: {
|
|
1586
1618
|
if (detail.text) {
|
|
1587
|
-
|
|
1588
|
-
type: "reasoning-delta",
|
|
1589
|
-
delta: detail.text,
|
|
1590
|
-
id: generateId()
|
|
1591
|
-
});
|
|
1592
|
-
}
|
|
1593
|
-
if (detail.signature) {
|
|
1594
|
-
controller.enqueue({
|
|
1595
|
-
type: "reasoning-end",
|
|
1596
|
-
id: generateId()
|
|
1597
|
-
});
|
|
1619
|
+
emitReasoningChunk(detail.text);
|
|
1598
1620
|
}
|
|
1599
1621
|
break;
|
|
1600
1622
|
}
|
|
1601
1623
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1602
1624
|
if (detail.data) {
|
|
1603
|
-
|
|
1604
|
-
type: "reasoning-delta",
|
|
1605
|
-
delta: "[REDACTED]",
|
|
1606
|
-
id: generateId()
|
|
1607
|
-
});
|
|
1625
|
+
emitReasoningChunk("[REDACTED]");
|
|
1608
1626
|
}
|
|
1609
1627
|
break;
|
|
1610
1628
|
}
|
|
1611
1629
|
case "reasoning.summary" /* Summary */: {
|
|
1612
1630
|
if (detail.summary) {
|
|
1613
|
-
|
|
1614
|
-
type: "reasoning-delta",
|
|
1615
|
-
delta: detail.summary,
|
|
1616
|
-
id: generateId()
|
|
1617
|
-
});
|
|
1631
|
+
emitReasoningChunk(detail.summary);
|
|
1618
1632
|
}
|
|
1619
1633
|
break;
|
|
1620
1634
|
}
|
|
@@ -1732,6 +1746,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1732
1746
|
}
|
|
1733
1747
|
}
|
|
1734
1748
|
}
|
|
1749
|
+
if (textStarted) {
|
|
1750
|
+
controller.enqueue({ type: "text-end", id: textId || generateId() });
|
|
1751
|
+
}
|
|
1752
|
+
if (reasoningStarted) {
|
|
1753
|
+
controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
|
|
1754
|
+
}
|
|
1735
1755
|
controller.enqueue({
|
|
1736
1756
|
type: "finish",
|
|
1737
1757
|
finishReason,
|