@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.mjs
CHANGED
|
@@ -402,28 +402,28 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
404
|
|
|
405
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
405
|
+
// 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
|
|
406
406
|
import * as z4 from "zod/v4";
|
|
407
407
|
|
|
408
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
408
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/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.5_zod@
|
|
411
|
+
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@4.0.5/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.5_zod@
|
|
414
|
+
// 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
|
|
415
415
|
import { ZodFirstPartyTypeKind } from "zod";
|
|
416
416
|
|
|
417
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
417
|
+
// 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
|
|
418
418
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
419
419
|
|
|
420
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
420
|
+
// 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
|
|
421
421
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
422
422
|
|
|
423
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@
|
|
423
|
+
// 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
|
|
424
424
|
import { ZodOptional } from "zod";
|
|
425
425
|
|
|
426
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.
|
|
426
|
+
// 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
|
|
427
427
|
function combineHeaders(...headers) {
|
|
428
428
|
return headers.reduce(
|
|
429
429
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -460,7 +460,8 @@ var createIdGenerator = ({
|
|
|
460
460
|
};
|
|
461
461
|
var generateId = createIdGenerator();
|
|
462
462
|
function isAbortError(error) {
|
|
463
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "
|
|
463
|
+
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
464
|
+
error.name === "TimeoutError");
|
|
464
465
|
}
|
|
465
466
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
466
467
|
function handleFetchError({
|
|
@@ -869,10 +870,10 @@ var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).tran
|
|
|
869
870
|
import { z as z2 } from "zod/v4";
|
|
870
871
|
var OpenRouterErrorResponseSchema = z2.object({
|
|
871
872
|
error: z2.object({
|
|
872
|
-
code: z2.union([z2.string(), z2.number()]).nullable(),
|
|
873
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
873
874
|
message: z2.string(),
|
|
874
|
-
type: z2.string().nullable(),
|
|
875
|
-
param: z2.any().nullable()
|
|
875
|
+
type: z2.string().nullable().optional().default(null),
|
|
876
|
+
param: z2.any().nullable().optional().default(null)
|
|
876
877
|
})
|
|
877
878
|
});
|
|
878
879
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -1102,7 +1103,10 @@ var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
|
1102
1103
|
reasoning_tokens: z5.number()
|
|
1103
1104
|
}).nullish(),
|
|
1104
1105
|
total_tokens: z5.number(),
|
|
1105
|
-
cost: z5.number().optional()
|
|
1106
|
+
cost: z5.number().optional(),
|
|
1107
|
+
cost_details: z5.object({
|
|
1108
|
+
upstream_inference_cost: z5.number().nullish()
|
|
1109
|
+
}).nullish()
|
|
1106
1110
|
}).nullish()
|
|
1107
1111
|
});
|
|
1108
1112
|
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
@@ -1267,7 +1271,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1267
1271
|
return baseArgs;
|
|
1268
1272
|
}
|
|
1269
1273
|
async doGenerate(options) {
|
|
1270
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1274
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1271
1275
|
const providerOptions = options.providerOptions || {};
|
|
1272
1276
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1273
1277
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1379,6 +1383,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1379
1383
|
},
|
|
1380
1384
|
completionTokensDetails: {
|
|
1381
1385
|
reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
|
|
1386
|
+
},
|
|
1387
|
+
costDetails: {
|
|
1388
|
+
upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
|
|
1382
1389
|
}
|
|
1383
1390
|
}
|
|
1384
1391
|
}
|
|
@@ -1426,6 +1433,11 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1426
1433
|
cachedInputTokens: Number.NaN
|
|
1427
1434
|
};
|
|
1428
1435
|
const openrouterUsage = {};
|
|
1436
|
+
let textStarted = false;
|
|
1437
|
+
let reasoningStarted = false;
|
|
1438
|
+
let textId;
|
|
1439
|
+
let reasoningId;
|
|
1440
|
+
let openrouterResponseId;
|
|
1429
1441
|
return {
|
|
1430
1442
|
stream: response.pipeThrough(
|
|
1431
1443
|
new TransformStream({
|
|
@@ -1443,6 +1455,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1443
1455
|
return;
|
|
1444
1456
|
}
|
|
1445
1457
|
if (value.id) {
|
|
1458
|
+
openrouterResponseId = value.id;
|
|
1446
1459
|
controller.enqueue({
|
|
1447
1460
|
type: "response-metadata",
|
|
1448
1461
|
id: value.id
|
|
@@ -1486,55 +1499,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1486
1499
|
}
|
|
1487
1500
|
const delta = choice.delta;
|
|
1488
1501
|
if (delta.content != null) {
|
|
1502
|
+
if (!textStarted) {
|
|
1503
|
+
textId = openrouterResponseId || generateId();
|
|
1504
|
+
controller.enqueue({
|
|
1505
|
+
type: "text-start",
|
|
1506
|
+
id: textId
|
|
1507
|
+
});
|
|
1508
|
+
textStarted = true;
|
|
1509
|
+
}
|
|
1489
1510
|
controller.enqueue({
|
|
1490
1511
|
type: "text-delta",
|
|
1491
1512
|
delta: delta.content,
|
|
1492
|
-
id: generateId()
|
|
1513
|
+
id: textId || generateId()
|
|
1493
1514
|
});
|
|
1494
1515
|
}
|
|
1495
|
-
|
|
1516
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1517
|
+
if (!reasoningStarted) {
|
|
1518
|
+
reasoningId = openrouterResponseId || generateId();
|
|
1519
|
+
controller.enqueue({
|
|
1520
|
+
type: "reasoning-start",
|
|
1521
|
+
id: reasoningId
|
|
1522
|
+
});
|
|
1523
|
+
reasoningStarted = true;
|
|
1524
|
+
}
|
|
1496
1525
|
controller.enqueue({
|
|
1497
1526
|
type: "reasoning-delta",
|
|
1498
|
-
delta:
|
|
1499
|
-
id: generateId()
|
|
1527
|
+
delta: chunkText,
|
|
1528
|
+
id: reasoningId || generateId()
|
|
1500
1529
|
});
|
|
1530
|
+
};
|
|
1531
|
+
if (delta.reasoning != null) {
|
|
1532
|
+
emitReasoningChunk(delta.reasoning);
|
|
1501
1533
|
}
|
|
1502
1534
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1503
1535
|
for (const detail of delta.reasoning_details) {
|
|
1504
1536
|
switch (detail.type) {
|
|
1505
1537
|
case "reasoning.text" /* Text */: {
|
|
1506
1538
|
if (detail.text) {
|
|
1507
|
-
|
|
1508
|
-
type: "reasoning-delta",
|
|
1509
|
-
delta: detail.text,
|
|
1510
|
-
id: generateId()
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
if (detail.signature) {
|
|
1514
|
-
controller.enqueue({
|
|
1515
|
-
type: "reasoning-end",
|
|
1516
|
-
id: generateId()
|
|
1517
|
-
});
|
|
1539
|
+
emitReasoningChunk(detail.text);
|
|
1518
1540
|
}
|
|
1519
1541
|
break;
|
|
1520
1542
|
}
|
|
1521
1543
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1522
1544
|
if (detail.data) {
|
|
1523
|
-
|
|
1524
|
-
type: "reasoning-delta",
|
|
1525
|
-
delta: "[REDACTED]",
|
|
1526
|
-
id: generateId()
|
|
1527
|
-
});
|
|
1545
|
+
emitReasoningChunk("[REDACTED]");
|
|
1528
1546
|
}
|
|
1529
1547
|
break;
|
|
1530
1548
|
}
|
|
1531
1549
|
case "reasoning.summary" /* Summary */: {
|
|
1532
1550
|
if (detail.summary) {
|
|
1533
|
-
|
|
1534
|
-
type: "reasoning-delta",
|
|
1535
|
-
delta: detail.summary,
|
|
1536
|
-
id: generateId()
|
|
1537
|
-
});
|
|
1551
|
+
emitReasoningChunk(detail.summary);
|
|
1538
1552
|
}
|
|
1539
1553
|
break;
|
|
1540
1554
|
}
|
|
@@ -1652,6 +1666,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1652
1666
|
}
|
|
1653
1667
|
}
|
|
1654
1668
|
}
|
|
1669
|
+
if (textStarted) {
|
|
1670
|
+
controller.enqueue({ type: "text-end", id: textId || generateId() });
|
|
1671
|
+
}
|
|
1672
|
+
if (reasoningStarted) {
|
|
1673
|
+
controller.enqueue({ type: "reasoning-end", id: reasoningId || generateId() });
|
|
1674
|
+
}
|
|
1655
1675
|
controller.enqueue({
|
|
1656
1676
|
type: "finish",
|
|
1657
1677
|
finishReason,
|