@openrouter/ai-sdk-provider 1.3.0 → 1.4.1
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/README.md +58 -0
- package/dist/index.d.mts +128 -2
- package/dist/index.d.ts +128 -2
- package/dist/index.js +150 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -33
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +186 -119
- package/dist/internal/index.d.ts +186 -119
- package/dist/internal/index.js +46 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +46 -28
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -968,9 +968,23 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
968
968
|
|
|
969
969
|
// src/schemas/provider-metadata.ts
|
|
970
970
|
var import_v43 = require("zod/v4");
|
|
971
|
+
var FileAnnotationSchema = import_v43.z.object({
|
|
972
|
+
type: import_v43.z.literal("file"),
|
|
973
|
+
file: import_v43.z.object({
|
|
974
|
+
hash: import_v43.z.string(),
|
|
975
|
+
name: import_v43.z.string(),
|
|
976
|
+
content: import_v43.z.array(
|
|
977
|
+
import_v43.z.object({
|
|
978
|
+
type: import_v43.z.string(),
|
|
979
|
+
text: import_v43.z.string().optional()
|
|
980
|
+
}).passthrough()
|
|
981
|
+
).optional()
|
|
982
|
+
}).passthrough()
|
|
983
|
+
});
|
|
971
984
|
var OpenRouterProviderMetadataSchema = import_v43.z.object({
|
|
972
985
|
provider: import_v43.z.string(),
|
|
973
986
|
reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
|
|
987
|
+
annotations: import_v43.z.array(FileAnnotationSchema).optional(),
|
|
974
988
|
usage: import_v43.z.object({
|
|
975
989
|
promptTokens: import_v43.z.number(),
|
|
976
990
|
promptTokensDetails: import_v43.z.object({
|
|
@@ -989,7 +1003,8 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
|
|
|
989
1003
|
}).passthrough();
|
|
990
1004
|
var OpenRouterProviderOptionsSchema = import_v43.z.object({
|
|
991
1005
|
openrouter: import_v43.z.object({
|
|
992
|
-
reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
|
|
1006
|
+
reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
|
|
1007
|
+
annotations: import_v43.z.array(FileAnnotationSchema).optional()
|
|
993
1008
|
}).optional()
|
|
994
1009
|
}).optional();
|
|
995
1010
|
|
|
@@ -1103,7 +1118,7 @@ function getCacheControl(providerMetadata) {
|
|
|
1103
1118
|
return (_c = (_b = (_a15 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a15 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1104
1119
|
}
|
|
1105
1120
|
function convertToOpenRouterChatMessages(prompt) {
|
|
1106
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
1121
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1107
1122
|
const messages = [];
|
|
1108
1123
|
for (const { role, content, providerOptions } of prompt) {
|
|
1109
1124
|
switch (role) {
|
|
@@ -1257,6 +1272,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1257
1272
|
}
|
|
1258
1273
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1259
1274
|
const messageReasoningDetails = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.reasoning_details : void 0;
|
|
1275
|
+
const messageAnnotations = parsedProviderOptions.success ? (_i = (_h = parsedProviderOptions.data) == null ? void 0 : _h.openrouter) == null ? void 0 : _i.annotations : void 0;
|
|
1260
1276
|
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
|
|
1261
1277
|
messages.push({
|
|
1262
1278
|
role: "assistant",
|
|
@@ -1264,6 +1280,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1264
1280
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1265
1281
|
reasoning: reasoning || void 0,
|
|
1266
1282
|
reasoning_details: finalReasoningDetails,
|
|
1283
|
+
annotations: messageAnnotations,
|
|
1267
1284
|
cache_control: getCacheControl(providerOptions)
|
|
1268
1285
|
});
|
|
1269
1286
|
break;
|
|
@@ -1275,7 +1292,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1275
1292
|
role: "tool",
|
|
1276
1293
|
tool_call_id: toolResponse.toolCallId,
|
|
1277
1294
|
content: content2,
|
|
1278
|
-
cache_control: (
|
|
1295
|
+
cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
|
|
1279
1296
|
});
|
|
1280
1297
|
}
|
|
1281
1298
|
break;
|
|
@@ -1534,6 +1551,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1534
1551
|
this.specificationVersion = "v2";
|
|
1535
1552
|
this.provider = "openrouter";
|
|
1536
1553
|
this.defaultObjectGenerationMode = "tool";
|
|
1554
|
+
this.supportsImageUrls = true;
|
|
1537
1555
|
this.supportedUrls = {
|
|
1538
1556
|
"image/*": [
|
|
1539
1557
|
/^data:image\/[a-zA-Z]+;base64,/,
|
|
@@ -1579,7 +1597,16 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1579
1597
|
presence_penalty: presencePenalty,
|
|
1580
1598
|
seed,
|
|
1581
1599
|
stop: stopSequences,
|
|
1582
|
-
response_format: responseFormat
|
|
1600
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
1601
|
+
type: "json_schema",
|
|
1602
|
+
json_schema: __spreadValues({
|
|
1603
|
+
schema: responseFormat.schema,
|
|
1604
|
+
strict: true,
|
|
1605
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
1606
|
+
}, responseFormat.description && {
|
|
1607
|
+
description: responseFormat.description
|
|
1608
|
+
})
|
|
1609
|
+
} : { type: "json_object" } : void 0,
|
|
1583
1610
|
top_k: topK,
|
|
1584
1611
|
// messages:
|
|
1585
1612
|
messages: convertToOpenRouterChatMessages(prompt),
|
|
@@ -1595,20 +1622,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1595
1622
|
// Debug settings:
|
|
1596
1623
|
debug: this.settings.debug
|
|
1597
1624
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1598
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1599
|
-
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
1600
|
-
response_format: {
|
|
1601
|
-
type: "json_schema",
|
|
1602
|
-
json_schema: __spreadValues({
|
|
1603
|
-
schema: responseFormat.schema,
|
|
1604
|
-
strict: true,
|
|
1605
|
-
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
1606
|
-
}, responseFormat.description && {
|
|
1607
|
-
description: responseFormat.description
|
|
1608
|
-
})
|
|
1609
|
-
}
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
1625
|
if (tools && tools.length > 0) {
|
|
1613
1626
|
const mappedTools = tools.filter(
|
|
1614
1627
|
(tool) => tool.type === "function"
|
|
@@ -1628,7 +1641,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1628
1641
|
return baseArgs;
|
|
1629
1642
|
}
|
|
1630
1643
|
async doGenerate(options) {
|
|
1631
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1644
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1632
1645
|
const providerOptions = options.providerOptions || {};
|
|
1633
1646
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1634
1647
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1786,6 +1799,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1786
1799
|
}
|
|
1787
1800
|
}
|
|
1788
1801
|
}
|
|
1802
|
+
const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
|
|
1803
|
+
(a) => a.type === "file"
|
|
1804
|
+
);
|
|
1789
1805
|
return {
|
|
1790
1806
|
content,
|
|
1791
1807
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -1793,22 +1809,23 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1793
1809
|
warnings: [],
|
|
1794
1810
|
providerMetadata: {
|
|
1795
1811
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
1796
|
-
provider: (
|
|
1797
|
-
reasoning_details: (
|
|
1812
|
+
provider: (_l = response.provider) != null ? _l : "",
|
|
1813
|
+
reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
|
|
1814
|
+
annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
|
|
1798
1815
|
usage: __spreadValues(__spreadValues(__spreadValues({
|
|
1799
|
-
promptTokens: (
|
|
1800
|
-
completionTokens: (
|
|
1801
|
-
totalTokens: (
|
|
1802
|
-
cost: (
|
|
1803
|
-
}, ((
|
|
1816
|
+
promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
|
|
1817
|
+
completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
|
|
1818
|
+
totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
|
|
1819
|
+
cost: (_q = response.usage) == null ? void 0 : _q.cost
|
|
1820
|
+
}, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
|
|
1804
1821
|
promptTokensDetails: {
|
|
1805
1822
|
cachedTokens: response.usage.prompt_tokens_details.cached_tokens
|
|
1806
1823
|
}
|
|
1807
|
-
} : {}), ((
|
|
1824
|
+
} : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
|
|
1808
1825
|
completionTokensDetails: {
|
|
1809
1826
|
reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
|
|
1810
1827
|
}
|
|
1811
|
-
} : {}), ((
|
|
1828
|
+
} : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
|
|
1812
1829
|
costDetails: {
|
|
1813
1830
|
upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
|
|
1814
1831
|
}
|
|
@@ -2370,6 +2387,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2370
2387
|
constructor(modelId, settings, config) {
|
|
2371
2388
|
this.specificationVersion = "v2";
|
|
2372
2389
|
this.provider = "openrouter";
|
|
2390
|
+
this.supportsImageUrls = true;
|
|
2373
2391
|
this.supportedUrls = {
|
|
2374
2392
|
"image/*": [
|
|
2375
2393
|
/^data:image\/[a-zA-Z]+;base64,/,
|