@openrouter/ai-sdk-provider 1.3.0 → 1.4.0

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.mjs CHANGED
@@ -979,9 +979,23 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
979
979
 
980
980
  // src/schemas/provider-metadata.ts
981
981
  import { z as z3 } from "zod/v4";
982
+ var FileAnnotationSchema = z3.object({
983
+ type: z3.literal("file"),
984
+ file: z3.object({
985
+ hash: z3.string(),
986
+ name: z3.string(),
987
+ content: z3.array(
988
+ z3.object({
989
+ type: z3.string(),
990
+ text: z3.string().optional()
991
+ }).passthrough()
992
+ ).optional()
993
+ }).passthrough()
994
+ });
982
995
  var OpenRouterProviderMetadataSchema = z3.object({
983
996
  provider: z3.string(),
984
997
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
998
+ annotations: z3.array(FileAnnotationSchema).optional(),
985
999
  usage: z3.object({
986
1000
  promptTokens: z3.number(),
987
1001
  promptTokensDetails: z3.object({
@@ -1000,7 +1014,8 @@ var OpenRouterProviderMetadataSchema = z3.object({
1000
1014
  }).passthrough();
1001
1015
  var OpenRouterProviderOptionsSchema = z3.object({
1002
1016
  openrouter: z3.object({
1003
- reasoning_details: z3.array(ReasoningDetailUnionSchema).optional()
1017
+ reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
1018
+ annotations: z3.array(FileAnnotationSchema).optional()
1004
1019
  }).optional()
1005
1020
  }).optional();
1006
1021
 
@@ -1114,7 +1129,7 @@ function getCacheControl(providerMetadata) {
1114
1129
  return (_c = (_b = (_a15 = openrouter2 == null ? void 0 : openrouter2.cacheControl) != null ? _a15 : openrouter2 == null ? void 0 : openrouter2.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
1115
1130
  }
1116
1131
  function convertToOpenRouterChatMessages(prompt) {
1117
- var _a15, _b, _c, _d, _e, _f, _g, _h;
1132
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1118
1133
  const messages = [];
1119
1134
  for (const { role, content, providerOptions } of prompt) {
1120
1135
  switch (role) {
@@ -1268,6 +1283,7 @@ function convertToOpenRouterChatMessages(prompt) {
1268
1283
  }
1269
1284
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1270
1285
  const messageReasoningDetails = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.reasoning_details : void 0;
1286
+ const messageAnnotations = parsedProviderOptions.success ? (_i = (_h = parsedProviderOptions.data) == null ? void 0 : _h.openrouter) == null ? void 0 : _i.annotations : void 0;
1271
1287
  const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1272
1288
  messages.push({
1273
1289
  role: "assistant",
@@ -1275,6 +1291,7 @@ function convertToOpenRouterChatMessages(prompt) {
1275
1291
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1276
1292
  reasoning: reasoning || void 0,
1277
1293
  reasoning_details: finalReasoningDetails,
1294
+ annotations: messageAnnotations,
1278
1295
  cache_control: getCacheControl(providerOptions)
1279
1296
  });
1280
1297
  break;
@@ -1286,7 +1303,7 @@ function convertToOpenRouterChatMessages(prompt) {
1286
1303
  role: "tool",
1287
1304
  tool_call_id: toolResponse.toolCallId,
1288
1305
  content: content2,
1289
- cache_control: (_h = getCacheControl(providerOptions)) != null ? _h : getCacheControl(toolResponse.providerOptions)
1306
+ cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
1290
1307
  });
1291
1308
  }
1292
1309
  break;
@@ -1545,6 +1562,7 @@ var OpenRouterChatLanguageModel = class {
1545
1562
  this.specificationVersion = "v2";
1546
1563
  this.provider = "openrouter";
1547
1564
  this.defaultObjectGenerationMode = "tool";
1565
+ this.supportsImageUrls = true;
1548
1566
  this.supportedUrls = {
1549
1567
  "image/*": [
1550
1568
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -1639,7 +1657,7 @@ var OpenRouterChatLanguageModel = class {
1639
1657
  return baseArgs;
1640
1658
  }
1641
1659
  async doGenerate(options) {
1642
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
1660
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1643
1661
  const providerOptions = options.providerOptions || {};
1644
1662
  const openrouterOptions = providerOptions.openrouter || {};
1645
1663
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1797,6 +1815,9 @@ var OpenRouterChatLanguageModel = class {
1797
1815
  }
1798
1816
  }
1799
1817
  }
1818
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1819
+ (a) => a.type === "file"
1820
+ );
1800
1821
  return {
1801
1822
  content,
1802
1823
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1804,22 +1825,23 @@ var OpenRouterChatLanguageModel = class {
1804
1825
  warnings: [],
1805
1826
  providerMetadata: {
1806
1827
  openrouter: OpenRouterProviderMetadataSchema.parse({
1807
- provider: (_k = response.provider) != null ? _k : "",
1808
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1828
+ provider: (_l = response.provider) != null ? _l : "",
1829
+ reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
1830
+ annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
1809
1831
  usage: __spreadValues(__spreadValues(__spreadValues({
1810
- promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1811
- completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1812
- totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1813
- cost: (_p = response.usage) == null ? void 0 : _p.cost
1814
- }, ((_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? {
1832
+ promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
1833
+ completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
1834
+ totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
1835
+ cost: (_q = response.usage) == null ? void 0 : _q.cost
1836
+ }, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
1815
1837
  promptTokensDetails: {
1816
1838
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1817
1839
  }
1818
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
1840
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1819
1841
  completionTokensDetails: {
1820
1842
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1821
1843
  }
1822
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
1844
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1823
1845
  costDetails: {
1824
1846
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1825
1847
  }
@@ -2381,6 +2403,7 @@ var OpenRouterCompletionLanguageModel = class {
2381
2403
  constructor(modelId, settings, config) {
2382
2404
  this.specificationVersion = "v2";
2383
2405
  this.provider = "openrouter";
2406
+ this.supportsImageUrls = true;
2384
2407
  this.supportedUrls = {
2385
2408
  "image/*": [
2386
2409
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -2678,7 +2701,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2678
2701
  }
2679
2702
 
2680
2703
  // src/version.ts
2681
- var VERSION = false ? "0.0.0-test" : "1.3.0";
2704
+ var VERSION = false ? "0.0.0-test" : "1.4.0";
2682
2705
 
2683
2706
  // src/provider.ts
2684
2707
  function createOpenRouter(options = {}) {