@openrouter/ai-sdk-provider 1.0.0-beta.7 → 1.1.0
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 +75 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +112 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +75 -0
- package/dist/internal/index.d.ts +75 -0
- package/dist/internal/index.js +112 -33
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +111 -32
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +9 -10
package/dist/internal/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
|
-
// node_modules/.pnpm/@ai-sdk+provider@2.0.0
|
|
21
|
+
// node_modules/.pnpm/@ai-sdk+provider@2.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
22
22
|
var marker = "vercel.ai.error";
|
|
23
23
|
var symbol = Symbol.for(marker);
|
|
24
24
|
var _a;
|
|
@@ -402,28 +402,25 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
404
|
|
|
405
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.
|
|
405
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/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.
|
|
408
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
411
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
414
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
417
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
420
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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
|
|
424
|
-
import { ZodOptional } from "zod";
|
|
425
|
-
|
|
426
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
423
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
427
424
|
function combineHeaders(...headers) {
|
|
428
425
|
return headers.reduce(
|
|
429
426
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -460,7 +457,7 @@ var createIdGenerator = ({
|
|
|
460
457
|
};
|
|
461
458
|
var generateId = createIdGenerator();
|
|
462
459
|
function isAbortError(error) {
|
|
463
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
460
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
464
461
|
error.name === "TimeoutError");
|
|
465
462
|
}
|
|
466
463
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
@@ -1146,6 +1143,7 @@ import { z as z5 } from "zod/v4";
|
|
|
1146
1143
|
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1147
1144
|
id: z5.string().optional(),
|
|
1148
1145
|
model: z5.string().optional(),
|
|
1146
|
+
provider: z5.string().optional(),
|
|
1149
1147
|
usage: z5.object({
|
|
1150
1148
|
prompt_tokens: z5.number(),
|
|
1151
1149
|
prompt_tokens_details: z5.object({
|
|
@@ -1179,7 +1177,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
|
|
|
1179
1177
|
arguments: z5.string()
|
|
1180
1178
|
})
|
|
1181
1179
|
})
|
|
1182
|
-
).optional()
|
|
1180
|
+
).optional(),
|
|
1181
|
+
annotations: z5.array(
|
|
1182
|
+
z5.object({
|
|
1183
|
+
type: z5.enum(["url_citation"]),
|
|
1184
|
+
url_citation: z5.object({
|
|
1185
|
+
end_index: z5.number(),
|
|
1186
|
+
start_index: z5.number(),
|
|
1187
|
+
title: z5.string(),
|
|
1188
|
+
url: z5.string(),
|
|
1189
|
+
content: z5.string().optional()
|
|
1190
|
+
})
|
|
1191
|
+
})
|
|
1192
|
+
).nullish()
|
|
1183
1193
|
}),
|
|
1184
1194
|
index: z5.number().nullish(),
|
|
1185
1195
|
logprobs: z5.object({
|
|
@@ -1219,6 +1229,18 @@ var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
|
1219
1229
|
arguments: z5.string().nullish()
|
|
1220
1230
|
})
|
|
1221
1231
|
})
|
|
1232
|
+
).nullish(),
|
|
1233
|
+
annotations: z5.array(
|
|
1234
|
+
z5.object({
|
|
1235
|
+
type: z5.enum(["url_citation"]),
|
|
1236
|
+
url_citation: z5.object({
|
|
1237
|
+
end_index: z5.number(),
|
|
1238
|
+
start_index: z5.number(),
|
|
1239
|
+
title: z5.string(),
|
|
1240
|
+
url: z5.string(),
|
|
1241
|
+
content: z5.string().optional()
|
|
1242
|
+
})
|
|
1243
|
+
})
|
|
1222
1244
|
).nullish()
|
|
1223
1245
|
}).nullish(),
|
|
1224
1246
|
logprobs: z5.object({
|
|
@@ -1301,7 +1323,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1301
1323
|
// OpenRouter specific settings:
|
|
1302
1324
|
include_reasoning: this.settings.includeReasoning,
|
|
1303
1325
|
reasoning: this.settings.reasoning,
|
|
1304
|
-
usage: this.settings.usage
|
|
1326
|
+
usage: this.settings.usage,
|
|
1327
|
+
// Web search settings:
|
|
1328
|
+
plugins: this.settings.plugins,
|
|
1329
|
+
web_search_options: this.settings.web_search_options,
|
|
1330
|
+
// Provider routing settings:
|
|
1331
|
+
provider: this.settings.provider
|
|
1305
1332
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1306
1333
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1307
1334
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1334,7 +1361,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1334
1361
|
return baseArgs;
|
|
1335
1362
|
}
|
|
1336
1363
|
async doGenerate(options) {
|
|
1337
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1364
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
1338
1365
|
const providerOptions = options.providerOptions || {};
|
|
1339
1366
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1340
1367
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1428,6 +1455,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1428
1455
|
});
|
|
1429
1456
|
}
|
|
1430
1457
|
}
|
|
1458
|
+
if (choice.message.annotations) {
|
|
1459
|
+
for (const annotation of choice.message.annotations) {
|
|
1460
|
+
if (annotation.type === "url_citation") {
|
|
1461
|
+
content.push({
|
|
1462
|
+
type: "source",
|
|
1463
|
+
sourceType: "url",
|
|
1464
|
+
id: annotation.url_citation.url,
|
|
1465
|
+
url: annotation.url_citation.url,
|
|
1466
|
+
title: annotation.url_citation.title,
|
|
1467
|
+
providerMetadata: {
|
|
1468
|
+
openrouter: {
|
|
1469
|
+
content: annotation.url_citation.content || ""
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1431
1476
|
return {
|
|
1432
1477
|
content,
|
|
1433
1478
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -1435,19 +1480,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1435
1480
|
warnings: [],
|
|
1436
1481
|
providerMetadata: {
|
|
1437
1482
|
openrouter: {
|
|
1483
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
1438
1484
|
usage: {
|
|
1439
|
-
promptTokens: (
|
|
1440
|
-
completionTokens: (
|
|
1441
|
-
totalTokens: (
|
|
1442
|
-
cost: (
|
|
1485
|
+
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
1486
|
+
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
1487
|
+
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
1488
|
+
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
1443
1489
|
promptTokensDetails: {
|
|
1444
|
-
cachedTokens: (
|
|
1490
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1445
1491
|
},
|
|
1446
1492
|
completionTokensDetails: {
|
|
1447
|
-
reasoningTokens: (
|
|
1493
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1448
1494
|
},
|
|
1449
1495
|
costDetails: {
|
|
1450
|
-
upstreamInferenceCost: (
|
|
1496
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1451
1497
|
}
|
|
1452
1498
|
}
|
|
1453
1499
|
}
|
|
@@ -1500,6 +1546,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1500
1546
|
let textId;
|
|
1501
1547
|
let reasoningId;
|
|
1502
1548
|
let openrouterResponseId;
|
|
1549
|
+
let provider;
|
|
1503
1550
|
return {
|
|
1504
1551
|
stream: response.pipeThrough(
|
|
1505
1552
|
new TransformStream({
|
|
@@ -1516,6 +1563,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1516
1563
|
controller.enqueue({ type: "error", error: value.error });
|
|
1517
1564
|
return;
|
|
1518
1565
|
}
|
|
1566
|
+
if (value.provider) {
|
|
1567
|
+
provider = value.provider;
|
|
1568
|
+
}
|
|
1519
1569
|
if (value.id) {
|
|
1520
1570
|
openrouterResponseId = value.id;
|
|
1521
1571
|
controller.enqueue({
|
|
@@ -1602,10 +1652,17 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1602
1652
|
}
|
|
1603
1653
|
}
|
|
1604
1654
|
}
|
|
1605
|
-
} else if (delta.reasoning
|
|
1655
|
+
} else if (delta.reasoning) {
|
|
1606
1656
|
emitReasoningChunk(delta.reasoning);
|
|
1607
1657
|
}
|
|
1608
|
-
if (delta.content
|
|
1658
|
+
if (delta.content) {
|
|
1659
|
+
if (reasoningStarted && !textStarted) {
|
|
1660
|
+
controller.enqueue({
|
|
1661
|
+
type: "reasoning-end",
|
|
1662
|
+
id: reasoningId || generateId()
|
|
1663
|
+
});
|
|
1664
|
+
reasoningStarted = false;
|
|
1665
|
+
}
|
|
1609
1666
|
if (!textStarted) {
|
|
1610
1667
|
textId = openrouterResponseId || generateId();
|
|
1611
1668
|
controller.enqueue({
|
|
@@ -1620,6 +1677,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1620
1677
|
id: textId || generateId()
|
|
1621
1678
|
});
|
|
1622
1679
|
}
|
|
1680
|
+
if (delta.annotations) {
|
|
1681
|
+
for (const annotation of delta.annotations) {
|
|
1682
|
+
if (annotation.type === "url_citation") {
|
|
1683
|
+
controller.enqueue({
|
|
1684
|
+
type: "source",
|
|
1685
|
+
sourceType: "url",
|
|
1686
|
+
id: annotation.url_citation.url,
|
|
1687
|
+
url: annotation.url_citation.url,
|
|
1688
|
+
title: annotation.url_citation.title,
|
|
1689
|
+
providerMetadata: {
|
|
1690
|
+
openrouter: {
|
|
1691
|
+
content: annotation.url_citation.content || ""
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1623
1698
|
if (delta.tool_calls != null) {
|
|
1624
1699
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1625
1700
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
@@ -1730,26 +1805,30 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1730
1805
|
}
|
|
1731
1806
|
}
|
|
1732
1807
|
}
|
|
1808
|
+
if (reasoningStarted) {
|
|
1809
|
+
controller.enqueue({
|
|
1810
|
+
type: "reasoning-end",
|
|
1811
|
+
id: reasoningId || generateId()
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1733
1814
|
if (textStarted) {
|
|
1734
1815
|
controller.enqueue({
|
|
1735
1816
|
type: "text-end",
|
|
1736
1817
|
id: textId || generateId()
|
|
1737
1818
|
});
|
|
1738
1819
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1820
|
+
const openrouterMetadata = {
|
|
1821
|
+
usage: openrouterUsage
|
|
1822
|
+
};
|
|
1823
|
+
if (provider !== void 0) {
|
|
1824
|
+
openrouterMetadata.provider = provider;
|
|
1744
1825
|
}
|
|
1745
1826
|
controller.enqueue({
|
|
1746
1827
|
type: "finish",
|
|
1747
1828
|
finishReason,
|
|
1748
1829
|
usage,
|
|
1749
1830
|
providerMetadata: {
|
|
1750
|
-
openrouter:
|
|
1751
|
-
usage: openrouterUsage
|
|
1752
|
-
}
|
|
1831
|
+
openrouter: openrouterMetadata
|
|
1753
1832
|
}
|
|
1754
1833
|
});
|
|
1755
1834
|
}
|