@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.mjs
CHANGED
|
@@ -412,28 +412,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
415
|
+
// 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
|
|
416
416
|
import * as z4 from "zod/v4";
|
|
417
417
|
|
|
418
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
418
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/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.5_zod@
|
|
421
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/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.5_zod@
|
|
424
|
+
// 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
|
|
425
425
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
426
426
|
|
|
427
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
427
|
+
// 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
|
|
428
428
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
429
429
|
|
|
430
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
430
|
+
// 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
|
|
431
431
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
432
432
|
|
|
433
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
433
|
+
// 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
|
|
434
434
|
import { ZodOptional } from "zod";
|
|
435
435
|
|
|
436
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
436
|
+
// 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
|
|
437
437
|
function combineHeaders(...headers) {
|
|
438
438
|
return headers.reduce(
|
|
439
439
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -470,7 +470,8 @@ var createIdGenerator = ({
|
|
|
470
470
|
};
|
|
471
471
|
var generateId = createIdGenerator();
|
|
472
472
|
function isAbortError(error) {
|
|
473
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
473
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
474
|
+
error.name === "TimeoutError");
|
|
474
475
|
}
|
|
475
476
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
476
477
|
function handleFetchError({
|
|
@@ -914,10 +915,10 @@ var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).tran
|
|
|
914
915
|
import { z as z2 } from "zod/v4";
|
|
915
916
|
var OpenRouterErrorResponseSchema = z2.object({
|
|
916
917
|
error: z2.object({
|
|
917
|
-
code: z2.union([z2.string(), z2.number()]).nullable(),
|
|
918
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
918
919
|
message: z2.string(),
|
|
919
|
-
type: z2.string().nullable(),
|
|
920
|
-
param: z2.any().nullable()
|
|
920
|
+
type: z2.string().nullable().optional().default(null),
|
|
921
|
+
param: z2.any().nullable().optional().default(null)
|
|
921
922
|
})
|
|
922
923
|
});
|
|
923
924
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1147,7 +1148,10 @@ var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
|
1147
1148
|
reasoning_tokens: z5.number()
|
|
1148
1149
|
}).nullish(),
|
|
1149
1150
|
total_tokens: z5.number(),
|
|
1150
|
-
cost: z5.number().optional()
|
|
1151
|
+
cost: z5.number().optional(),
|
|
1152
|
+
cost_details: z5.object({
|
|
1153
|
+
upstream_inference_cost: z5.number().nullish()
|
|
1154
|
+
}).nullish()
|
|
1151
1155
|
}).nullish()
|
|
1152
1156
|
});
|
|
1153
1157
|
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
@@ -1312,7 +1316,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1312
1316
|
return baseArgs;
|
|
1313
1317
|
}
|
|
1314
1318
|
async doGenerate(options) {
|
|
1315
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1319
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1316
1320
|
const providerOptions = options.providerOptions || {};
|
|
1317
1321
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1318
1322
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1424,6 +1428,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1424
1428
|
},
|
|
1425
1429
|
completionTokensDetails: {
|
|
1426
1430
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1431
|
+
},
|
|
1432
|
+
costDetails: {
|
|
1433
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1427
1434
|
}
|
|
1428
1435
|
}
|
|
1429
1436
|
}
|
|
@@ -1471,6 +1478,11 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1471
1478
|
cachedInputTokens: Number.NaN
|
|
1472
1479
|
};
|
|
1473
1480
|
const openrouterUsage = {};
|
|
1481
|
+
let textStarted = false;
|
|
1482
|
+
let reasoningStarted = false;
|
|
1483
|
+
let textId;
|
|
1484
|
+
let reasoningId;
|
|
1485
|
+
let openrouterResponseId;
|
|
1474
1486
|
return {
|
|
1475
1487
|
stream: response.pipeThrough(
|
|
1476
1488
|
new TransformStream({
|
|
@@ -1488,6 +1500,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1488
1500
|
return;
|
|
1489
1501
|
}
|
|
1490
1502
|
if (value.id) {
|
|
1503
|
+
openrouterResponseId = value.id;
|
|
1491
1504
|
controller.enqueue({
|
|
1492
1505
|
type: "response-metadata",
|
|
1493
1506
|
id: value.id
|
|
@@ -1531,55 +1544,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1531
1544
|
}
|
|
1532
1545
|
const delta = choice.delta;
|
|
1533
1546
|
if (delta.content != null) {
|
|
1547
|
+
if (!textStarted) {
|
|
1548
|
+
textId = openrouterResponseId || generateId();
|
|
1549
|
+
controller.enqueue({
|
|
1550
|
+
type: "text-start",
|
|
1551
|
+
id: textId
|
|
1552
|
+
});
|
|
1553
|
+
textStarted = true;
|
|
1554
|
+
}
|
|
1534
1555
|
controller.enqueue({
|
|
1535
1556
|
type: "text-delta",
|
|
1536
1557
|
delta: delta.content,
|
|
1537
|
-
id: generateId()
|
|
1558
|
+
id: textId || generateId()
|
|
1538
1559
|
});
|
|
1539
1560
|
}
|
|
1540
|
-
|
|
1561
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1562
|
+
if (!reasoningStarted) {
|
|
1563
|
+
reasoningId = openrouterResponseId || generateId();
|
|
1564
|
+
controller.enqueue({
|
|
1565
|
+
type: "reasoning-start",
|
|
1566
|
+
id: reasoningId
|
|
1567
|
+
});
|
|
1568
|
+
reasoningStarted = true;
|
|
1569
|
+
}
|
|
1541
1570
|
controller.enqueue({
|
|
1542
1571
|
type: "reasoning-delta",
|
|
1543
|
-
delta:
|
|
1544
|
-
id: generateId()
|
|
1572
|
+
delta: chunkText,
|
|
1573
|
+
id: reasoningId || generateId()
|
|
1545
1574
|
});
|
|
1575
|
+
};
|
|
1576
|
+
if (delta.reasoning != null) {
|
|
1577
|
+
emitReasoningChunk(delta.reasoning);
|
|
1546
1578
|
}
|
|
1547
1579
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1548
1580
|
for (const detail of delta.reasoning_details) {
|
|
1549
1581
|
switch (detail.type) {
|
|
1550
1582
|
case "reasoning.text" /* Text */: {
|
|
1551
1583
|
if (detail.text) {
|
|
1552
|
-
|
|
1553
|
-
type: "reasoning-delta",
|
|
1554
|
-
delta: detail.text,
|
|
1555
|
-
id: generateId()
|
|
1556
|
-
});
|
|
1557
|
-
}
|
|
1558
|
-
if (detail.signature) {
|
|
1559
|
-
controller.enqueue({
|
|
1560
|
-
type: "reasoning-end",
|
|
1561
|
-
id: generateId()
|
|
1562
|
-
});
|
|
1584
|
+
emitReasoningChunk(detail.text);
|
|
1563
1585
|
}
|
|
1564
1586
|
break;
|
|
1565
1587
|
}
|
|
1566
1588
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1567
1589
|
if (detail.data) {
|
|
1568
|
-
|
|
1569
|
-
type: "reasoning-delta",
|
|
1570
|
-
delta: "[REDACTED]",
|
|
1571
|
-
id: generateId()
|
|
1572
|
-
});
|
|
1590
|
+
emitReasoningChunk("[REDACTED]");
|
|
1573
1591
|
}
|
|
1574
1592
|
break;
|
|
1575
1593
|
}
|
|
1576
1594
|
case "reasoning.summary" /* Summary */: {
|
|
1577
1595
|
if (detail.summary) {
|
|
1578
|
-
|
|
1579
|
-
type: "reasoning-delta",
|
|
1580
|
-
delta: detail.summary,
|
|
1581
|
-
id: generateId()
|
|
1582
|
-
});
|
|
1596
|
+
emitReasoningChunk(detail.summary);
|
|
1583
1597
|
}
|
|
1584
1598
|
break;
|
|
1585
1599
|
}
|
|
@@ -1697,6 +1711,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1697
1711
|
}
|
|
1698
1712
|
}
|
|
1699
1713
|
}
|
|
1714
|
+
if (textStarted) {
|
|
1715
|
+
controller.enqueue({ type: "text-end", id: textId || generateId() });
|
|
1716
|
+
}
|
|
1717
|
+
if (reasoningStarted) {
|
|
1718
|
+
controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
|
|
1719
|
+
}
|
|
1700
1720
|
controller.enqueue({
|
|
1701
1721
|
type: "finish",
|
|
1702
1722
|
finishReason,
|