@openrouter/ai-sdk-provider 1.0.0-beta.1 → 1.0.0-beta.2
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 +51 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -37
- 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 +51 -37
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +51 -37
- 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,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1426
1433
|
cachedInputTokens: Number.NaN
|
|
1427
1434
|
};
|
|
1428
1435
|
const openrouterUsage = {};
|
|
1436
|
+
let textStarted = false;
|
|
1437
|
+
let reasoningStarted = false;
|
|
1429
1438
|
return {
|
|
1430
1439
|
stream: response.pipeThrough(
|
|
1431
1440
|
new TransformStream({
|
|
@@ -1486,55 +1495,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1486
1495
|
}
|
|
1487
1496
|
const delta = choice.delta;
|
|
1488
1497
|
if (delta.content != null) {
|
|
1498
|
+
if (!textStarted) {
|
|
1499
|
+
controller.enqueue({
|
|
1500
|
+
type: "text-start",
|
|
1501
|
+
id: generateId()
|
|
1502
|
+
});
|
|
1503
|
+
textStarted = true;
|
|
1504
|
+
}
|
|
1489
1505
|
controller.enqueue({
|
|
1490
1506
|
type: "text-delta",
|
|
1491
1507
|
delta: delta.content,
|
|
1492
1508
|
id: generateId()
|
|
1493
1509
|
});
|
|
1494
1510
|
}
|
|
1495
|
-
|
|
1511
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1512
|
+
if (!reasoningStarted) {
|
|
1513
|
+
controller.enqueue({
|
|
1514
|
+
type: "reasoning-start",
|
|
1515
|
+
id: generateId()
|
|
1516
|
+
});
|
|
1517
|
+
reasoningStarted = true;
|
|
1518
|
+
}
|
|
1496
1519
|
controller.enqueue({
|
|
1497
1520
|
type: "reasoning-delta",
|
|
1498
|
-
delta:
|
|
1521
|
+
delta: chunkText,
|
|
1499
1522
|
id: generateId()
|
|
1500
1523
|
});
|
|
1524
|
+
};
|
|
1525
|
+
if (delta.reasoning != null) {
|
|
1526
|
+
emitReasoningChunk(delta.reasoning);
|
|
1501
1527
|
}
|
|
1502
1528
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1503
1529
|
for (const detail of delta.reasoning_details) {
|
|
1504
1530
|
switch (detail.type) {
|
|
1505
1531
|
case "reasoning.text" /* Text */: {
|
|
1506
1532
|
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
|
-
});
|
|
1533
|
+
emitReasoningChunk(detail.text);
|
|
1518
1534
|
}
|
|
1519
1535
|
break;
|
|
1520
1536
|
}
|
|
1521
1537
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1522
1538
|
if (detail.data) {
|
|
1523
|
-
|
|
1524
|
-
type: "reasoning-delta",
|
|
1525
|
-
delta: "[REDACTED]",
|
|
1526
|
-
id: generateId()
|
|
1527
|
-
});
|
|
1539
|
+
emitReasoningChunk("[REDACTED]");
|
|
1528
1540
|
}
|
|
1529
1541
|
break;
|
|
1530
1542
|
}
|
|
1531
1543
|
case "reasoning.summary" /* Summary */: {
|
|
1532
1544
|
if (detail.summary) {
|
|
1533
|
-
|
|
1534
|
-
type: "reasoning-delta",
|
|
1535
|
-
delta: detail.summary,
|
|
1536
|
-
id: generateId()
|
|
1537
|
-
});
|
|
1545
|
+
emitReasoningChunk(detail.summary);
|
|
1538
1546
|
}
|
|
1539
1547
|
break;
|
|
1540
1548
|
}
|
|
@@ -1652,6 +1660,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1652
1660
|
}
|
|
1653
1661
|
}
|
|
1654
1662
|
}
|
|
1663
|
+
if (textStarted) {
|
|
1664
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1665
|
+
}
|
|
1666
|
+
if (reasoningStarted) {
|
|
1667
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1668
|
+
}
|
|
1655
1669
|
controller.enqueue({
|
|
1656
1670
|
type: "finish",
|
|
1657
1671
|
finishReason,
|