@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/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,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1471
1478
|
cachedInputTokens: Number.NaN
|
|
1472
1479
|
};
|
|
1473
1480
|
const openrouterUsage = {};
|
|
1481
|
+
let textStarted = false;
|
|
1482
|
+
let reasoningStarted = false;
|
|
1474
1483
|
return {
|
|
1475
1484
|
stream: response.pipeThrough(
|
|
1476
1485
|
new TransformStream({
|
|
@@ -1531,55 +1540,54 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1531
1540
|
}
|
|
1532
1541
|
const delta = choice.delta;
|
|
1533
1542
|
if (delta.content != null) {
|
|
1543
|
+
if (!textStarted) {
|
|
1544
|
+
controller.enqueue({
|
|
1545
|
+
type: "text-start",
|
|
1546
|
+
id: generateId()
|
|
1547
|
+
});
|
|
1548
|
+
textStarted = true;
|
|
1549
|
+
}
|
|
1534
1550
|
controller.enqueue({
|
|
1535
1551
|
type: "text-delta",
|
|
1536
1552
|
delta: delta.content,
|
|
1537
1553
|
id: generateId()
|
|
1538
1554
|
});
|
|
1539
1555
|
}
|
|
1540
|
-
|
|
1556
|
+
const emitReasoningChunk = (chunkText) => {
|
|
1557
|
+
if (!reasoningStarted) {
|
|
1558
|
+
controller.enqueue({
|
|
1559
|
+
type: "reasoning-start",
|
|
1560
|
+
id: generateId()
|
|
1561
|
+
});
|
|
1562
|
+
reasoningStarted = true;
|
|
1563
|
+
}
|
|
1541
1564
|
controller.enqueue({
|
|
1542
1565
|
type: "reasoning-delta",
|
|
1543
|
-
delta:
|
|
1566
|
+
delta: chunkText,
|
|
1544
1567
|
id: generateId()
|
|
1545
1568
|
});
|
|
1569
|
+
};
|
|
1570
|
+
if (delta.reasoning != null) {
|
|
1571
|
+
emitReasoningChunk(delta.reasoning);
|
|
1546
1572
|
}
|
|
1547
1573
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1548
1574
|
for (const detail of delta.reasoning_details) {
|
|
1549
1575
|
switch (detail.type) {
|
|
1550
1576
|
case "reasoning.text" /* Text */: {
|
|
1551
1577
|
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
|
-
});
|
|
1578
|
+
emitReasoningChunk(detail.text);
|
|
1563
1579
|
}
|
|
1564
1580
|
break;
|
|
1565
1581
|
}
|
|
1566
1582
|
case "reasoning.encrypted" /* Encrypted */: {
|
|
1567
1583
|
if (detail.data) {
|
|
1568
|
-
|
|
1569
|
-
type: "reasoning-delta",
|
|
1570
|
-
delta: "[REDACTED]",
|
|
1571
|
-
id: generateId()
|
|
1572
|
-
});
|
|
1584
|
+
emitReasoningChunk("[REDACTED]");
|
|
1573
1585
|
}
|
|
1574
1586
|
break;
|
|
1575
1587
|
}
|
|
1576
1588
|
case "reasoning.summary" /* Summary */: {
|
|
1577
1589
|
if (detail.summary) {
|
|
1578
|
-
|
|
1579
|
-
type: "reasoning-delta",
|
|
1580
|
-
delta: detail.summary,
|
|
1581
|
-
id: generateId()
|
|
1582
|
-
});
|
|
1590
|
+
emitReasoningChunk(detail.summary);
|
|
1583
1591
|
}
|
|
1584
1592
|
break;
|
|
1585
1593
|
}
|
|
@@ -1697,6 +1705,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1697
1705
|
}
|
|
1698
1706
|
}
|
|
1699
1707
|
}
|
|
1708
|
+
if (textStarted) {
|
|
1709
|
+
controller.enqueue({ type: "text-end", id: generateId() });
|
|
1710
|
+
}
|
|
1711
|
+
if (reasoningStarted) {
|
|
1712
|
+
controller.enqueue({ type: "reasoning-end", id: generateId() });
|
|
1713
|
+
}
|
|
1700
1714
|
controller.enqueue({
|
|
1701
1715
|
type: "finish",
|
|
1702
1716
|
finishReason,
|