@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/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;
|
|
@@ -412,28 +412,25 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.
|
|
415
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/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.
|
|
418
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
421
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/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.
|
|
424
|
+
// 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
|
|
425
425
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
426
426
|
|
|
427
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.
|
|
427
|
+
// 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
|
|
428
428
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
429
429
|
|
|
430
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.
|
|
430
|
+
// 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
|
|
431
431
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
432
432
|
|
|
433
|
-
// node_modules/.pnpm
|
|
434
|
-
import { ZodOptional } from "zod";
|
|
435
|
-
|
|
436
|
-
// 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
|
|
433
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
437
434
|
function combineHeaders(...headers) {
|
|
438
435
|
return headers.reduce(
|
|
439
436
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -470,7 +467,7 @@ var createIdGenerator = ({
|
|
|
470
467
|
};
|
|
471
468
|
var generateId = createIdGenerator();
|
|
472
469
|
function isAbortError(error) {
|
|
473
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
470
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
474
471
|
error.name === "TimeoutError");
|
|
475
472
|
}
|
|
476
473
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
@@ -1191,6 +1188,7 @@ import { z as z5 } from "zod/v4";
|
|
|
1191
1188
|
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1192
1189
|
id: z5.string().optional(),
|
|
1193
1190
|
model: z5.string().optional(),
|
|
1191
|
+
provider: z5.string().optional(),
|
|
1194
1192
|
usage: z5.object({
|
|
1195
1193
|
prompt_tokens: z5.number(),
|
|
1196
1194
|
prompt_tokens_details: z5.object({
|
|
@@ -1224,7 +1222,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
|
|
|
1224
1222
|
arguments: z5.string()
|
|
1225
1223
|
})
|
|
1226
1224
|
})
|
|
1227
|
-
).optional()
|
|
1225
|
+
).optional(),
|
|
1226
|
+
annotations: z5.array(
|
|
1227
|
+
z5.object({
|
|
1228
|
+
type: z5.enum(["url_citation"]),
|
|
1229
|
+
url_citation: z5.object({
|
|
1230
|
+
end_index: z5.number(),
|
|
1231
|
+
start_index: z5.number(),
|
|
1232
|
+
title: z5.string(),
|
|
1233
|
+
url: z5.string(),
|
|
1234
|
+
content: z5.string().optional()
|
|
1235
|
+
})
|
|
1236
|
+
})
|
|
1237
|
+
).nullish()
|
|
1228
1238
|
}),
|
|
1229
1239
|
index: z5.number().nullish(),
|
|
1230
1240
|
logprobs: z5.object({
|
|
@@ -1264,6 +1274,18 @@ var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
|
1264
1274
|
arguments: z5.string().nullish()
|
|
1265
1275
|
})
|
|
1266
1276
|
})
|
|
1277
|
+
).nullish(),
|
|
1278
|
+
annotations: z5.array(
|
|
1279
|
+
z5.object({
|
|
1280
|
+
type: z5.enum(["url_citation"]),
|
|
1281
|
+
url_citation: z5.object({
|
|
1282
|
+
end_index: z5.number(),
|
|
1283
|
+
start_index: z5.number(),
|
|
1284
|
+
title: z5.string(),
|
|
1285
|
+
url: z5.string(),
|
|
1286
|
+
content: z5.string().optional()
|
|
1287
|
+
})
|
|
1288
|
+
})
|
|
1267
1289
|
).nullish()
|
|
1268
1290
|
}).nullish(),
|
|
1269
1291
|
logprobs: z5.object({
|
|
@@ -1346,7 +1368,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1346
1368
|
// OpenRouter specific settings:
|
|
1347
1369
|
include_reasoning: this.settings.includeReasoning,
|
|
1348
1370
|
reasoning: this.settings.reasoning,
|
|
1349
|
-
usage: this.settings.usage
|
|
1371
|
+
usage: this.settings.usage,
|
|
1372
|
+
// Web search settings:
|
|
1373
|
+
plugins: this.settings.plugins,
|
|
1374
|
+
web_search_options: this.settings.web_search_options,
|
|
1375
|
+
// Provider routing settings:
|
|
1376
|
+
provider: this.settings.provider
|
|
1350
1377
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1351
1378
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1352
1379
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1379,7 +1406,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1379
1406
|
return baseArgs;
|
|
1380
1407
|
}
|
|
1381
1408
|
async doGenerate(options) {
|
|
1382
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1409
|
+
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;
|
|
1383
1410
|
const providerOptions = options.providerOptions || {};
|
|
1384
1411
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1385
1412
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1473,6 +1500,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1473
1500
|
});
|
|
1474
1501
|
}
|
|
1475
1502
|
}
|
|
1503
|
+
if (choice.message.annotations) {
|
|
1504
|
+
for (const annotation of choice.message.annotations) {
|
|
1505
|
+
if (annotation.type === "url_citation") {
|
|
1506
|
+
content.push({
|
|
1507
|
+
type: "source",
|
|
1508
|
+
sourceType: "url",
|
|
1509
|
+
id: annotation.url_citation.url,
|
|
1510
|
+
url: annotation.url_citation.url,
|
|
1511
|
+
title: annotation.url_citation.title,
|
|
1512
|
+
providerMetadata: {
|
|
1513
|
+
openrouter: {
|
|
1514
|
+
content: annotation.url_citation.content || ""
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1476
1521
|
return {
|
|
1477
1522
|
content,
|
|
1478
1523
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -1480,19 +1525,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1480
1525
|
warnings: [],
|
|
1481
1526
|
providerMetadata: {
|
|
1482
1527
|
openrouter: {
|
|
1528
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
1483
1529
|
usage: {
|
|
1484
|
-
promptTokens: (
|
|
1485
|
-
completionTokens: (
|
|
1486
|
-
totalTokens: (
|
|
1487
|
-
cost: (
|
|
1530
|
+
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
1531
|
+
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
1532
|
+
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
1533
|
+
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
1488
1534
|
promptTokensDetails: {
|
|
1489
|
-
cachedTokens: (
|
|
1535
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1490
1536
|
},
|
|
1491
1537
|
completionTokensDetails: {
|
|
1492
|
-
reasoningTokens: (
|
|
1538
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1493
1539
|
},
|
|
1494
1540
|
costDetails: {
|
|
1495
|
-
upstreamInferenceCost: (
|
|
1541
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1496
1542
|
}
|
|
1497
1543
|
}
|
|
1498
1544
|
}
|
|
@@ -1545,6 +1591,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1545
1591
|
let textId;
|
|
1546
1592
|
let reasoningId;
|
|
1547
1593
|
let openrouterResponseId;
|
|
1594
|
+
let provider;
|
|
1548
1595
|
return {
|
|
1549
1596
|
stream: response.pipeThrough(
|
|
1550
1597
|
new TransformStream({
|
|
@@ -1561,6 +1608,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1561
1608
|
controller.enqueue({ type: "error", error: value.error });
|
|
1562
1609
|
return;
|
|
1563
1610
|
}
|
|
1611
|
+
if (value.provider) {
|
|
1612
|
+
provider = value.provider;
|
|
1613
|
+
}
|
|
1564
1614
|
if (value.id) {
|
|
1565
1615
|
openrouterResponseId = value.id;
|
|
1566
1616
|
controller.enqueue({
|
|
@@ -1647,10 +1697,17 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1647
1697
|
}
|
|
1648
1698
|
}
|
|
1649
1699
|
}
|
|
1650
|
-
} else if (delta.reasoning
|
|
1700
|
+
} else if (delta.reasoning) {
|
|
1651
1701
|
emitReasoningChunk(delta.reasoning);
|
|
1652
1702
|
}
|
|
1653
|
-
if (delta.content
|
|
1703
|
+
if (delta.content) {
|
|
1704
|
+
if (reasoningStarted && !textStarted) {
|
|
1705
|
+
controller.enqueue({
|
|
1706
|
+
type: "reasoning-end",
|
|
1707
|
+
id: reasoningId || generateId()
|
|
1708
|
+
});
|
|
1709
|
+
reasoningStarted = false;
|
|
1710
|
+
}
|
|
1654
1711
|
if (!textStarted) {
|
|
1655
1712
|
textId = openrouterResponseId || generateId();
|
|
1656
1713
|
controller.enqueue({
|
|
@@ -1665,6 +1722,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1665
1722
|
id: textId || generateId()
|
|
1666
1723
|
});
|
|
1667
1724
|
}
|
|
1725
|
+
if (delta.annotations) {
|
|
1726
|
+
for (const annotation of delta.annotations) {
|
|
1727
|
+
if (annotation.type === "url_citation") {
|
|
1728
|
+
controller.enqueue({
|
|
1729
|
+
type: "source",
|
|
1730
|
+
sourceType: "url",
|
|
1731
|
+
id: annotation.url_citation.url,
|
|
1732
|
+
url: annotation.url_citation.url,
|
|
1733
|
+
title: annotation.url_citation.title,
|
|
1734
|
+
providerMetadata: {
|
|
1735
|
+
openrouter: {
|
|
1736
|
+
content: annotation.url_citation.content || ""
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1668
1743
|
if (delta.tool_calls != null) {
|
|
1669
1744
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1670
1745
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
@@ -1775,26 +1850,30 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1775
1850
|
}
|
|
1776
1851
|
}
|
|
1777
1852
|
}
|
|
1853
|
+
if (reasoningStarted) {
|
|
1854
|
+
controller.enqueue({
|
|
1855
|
+
type: "reasoning-end",
|
|
1856
|
+
id: reasoningId || generateId()
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1778
1859
|
if (textStarted) {
|
|
1779
1860
|
controller.enqueue({
|
|
1780
1861
|
type: "text-end",
|
|
1781
1862
|
id: textId || generateId()
|
|
1782
1863
|
});
|
|
1783
1864
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1865
|
+
const openrouterMetadata = {
|
|
1866
|
+
usage: openrouterUsage
|
|
1867
|
+
};
|
|
1868
|
+
if (provider !== void 0) {
|
|
1869
|
+
openrouterMetadata.provider = provider;
|
|
1789
1870
|
}
|
|
1790
1871
|
controller.enqueue({
|
|
1791
1872
|
type: "finish",
|
|
1792
1873
|
finishReason,
|
|
1793
1874
|
usage,
|
|
1794
1875
|
providerMetadata: {
|
|
1795
|
-
openrouter:
|
|
1796
|
-
usage: openrouterUsage
|
|
1797
|
-
}
|
|
1876
|
+
openrouter: openrouterMetadata
|
|
1798
1877
|
}
|
|
1799
1878
|
});
|
|
1800
1879
|
}
|