@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.
@@ -934,9 +934,23 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
934
934
 
935
935
  // src/schemas/provider-metadata.ts
936
936
  import { z as z3 } from "zod/v4";
937
+ var FileAnnotationSchema = z3.object({
938
+ type: z3.literal("file"),
939
+ file: z3.object({
940
+ hash: z3.string(),
941
+ name: z3.string(),
942
+ content: z3.array(
943
+ z3.object({
944
+ type: z3.string(),
945
+ text: z3.string().optional()
946
+ }).passthrough()
947
+ ).optional()
948
+ }).passthrough()
949
+ });
937
950
  var OpenRouterProviderMetadataSchema = z3.object({
938
951
  provider: z3.string(),
939
952
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
953
+ annotations: z3.array(FileAnnotationSchema).optional(),
940
954
  usage: z3.object({
941
955
  promptTokens: z3.number(),
942
956
  promptTokensDetails: z3.object({
@@ -955,7 +969,8 @@ var OpenRouterProviderMetadataSchema = z3.object({
955
969
  }).passthrough();
956
970
  var OpenRouterProviderOptionsSchema = z3.object({
957
971
  openrouter: z3.object({
958
- reasoning_details: z3.array(ReasoningDetailUnionSchema).optional()
972
+ reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
973
+ annotations: z3.array(FileAnnotationSchema).optional()
959
974
  }).optional()
960
975
  }).optional();
961
976
 
@@ -1069,7 +1084,7 @@ function getCacheControl(providerMetadata) {
1069
1084
  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;
1070
1085
  }
1071
1086
  function convertToOpenRouterChatMessages(prompt) {
1072
- var _a15, _b, _c, _d, _e, _f, _g, _h;
1087
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1073
1088
  const messages = [];
1074
1089
  for (const { role, content, providerOptions } of prompt) {
1075
1090
  switch (role) {
@@ -1223,6 +1238,7 @@ function convertToOpenRouterChatMessages(prompt) {
1223
1238
  }
1224
1239
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1225
1240
  const messageReasoningDetails = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.reasoning_details : void 0;
1241
+ const messageAnnotations = parsedProviderOptions.success ? (_i = (_h = parsedProviderOptions.data) == null ? void 0 : _h.openrouter) == null ? void 0 : _i.annotations : void 0;
1226
1242
  const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1227
1243
  messages.push({
1228
1244
  role: "assistant",
@@ -1230,6 +1246,7 @@ function convertToOpenRouterChatMessages(prompt) {
1230
1246
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1231
1247
  reasoning: reasoning || void 0,
1232
1248
  reasoning_details: finalReasoningDetails,
1249
+ annotations: messageAnnotations,
1233
1250
  cache_control: getCacheControl(providerOptions)
1234
1251
  });
1235
1252
  break;
@@ -1241,7 +1258,7 @@ function convertToOpenRouterChatMessages(prompt) {
1241
1258
  role: "tool",
1242
1259
  tool_call_id: toolResponse.toolCallId,
1243
1260
  content: content2,
1244
- cache_control: (_h = getCacheControl(providerOptions)) != null ? _h : getCacheControl(toolResponse.providerOptions)
1261
+ cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
1245
1262
  });
1246
1263
  }
1247
1264
  break;
@@ -1500,6 +1517,7 @@ var OpenRouterChatLanguageModel = class {
1500
1517
  this.specificationVersion = "v2";
1501
1518
  this.provider = "openrouter";
1502
1519
  this.defaultObjectGenerationMode = "tool";
1520
+ this.supportsImageUrls = true;
1503
1521
  this.supportedUrls = {
1504
1522
  "image/*": [
1505
1523
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -1594,7 +1612,7 @@ var OpenRouterChatLanguageModel = class {
1594
1612
  return baseArgs;
1595
1613
  }
1596
1614
  async doGenerate(options) {
1597
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
1615
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1598
1616
  const providerOptions = options.providerOptions || {};
1599
1617
  const openrouterOptions = providerOptions.openrouter || {};
1600
1618
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1752,6 +1770,9 @@ var OpenRouterChatLanguageModel = class {
1752
1770
  }
1753
1771
  }
1754
1772
  }
1773
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1774
+ (a) => a.type === "file"
1775
+ );
1755
1776
  return {
1756
1777
  content,
1757
1778
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1759,22 +1780,23 @@ var OpenRouterChatLanguageModel = class {
1759
1780
  warnings: [],
1760
1781
  providerMetadata: {
1761
1782
  openrouter: OpenRouterProviderMetadataSchema.parse({
1762
- provider: (_k = response.provider) != null ? _k : "",
1763
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1783
+ provider: (_l = response.provider) != null ? _l : "",
1784
+ reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
1785
+ annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
1764
1786
  usage: __spreadValues(__spreadValues(__spreadValues({
1765
- promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1766
- completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1767
- totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1768
- cost: (_p = response.usage) == null ? void 0 : _p.cost
1769
- }, ((_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? {
1787
+ promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
1788
+ completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
1789
+ totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
1790
+ cost: (_q = response.usage) == null ? void 0 : _q.cost
1791
+ }, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
1770
1792
  promptTokensDetails: {
1771
1793
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1772
1794
  }
1773
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
1795
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1774
1796
  completionTokensDetails: {
1775
1797
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1776
1798
  }
1777
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
1799
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1778
1800
  costDetails: {
1779
1801
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1780
1802
  }
@@ -2336,6 +2358,7 @@ var OpenRouterCompletionLanguageModel = class {
2336
2358
  constructor(modelId, settings, config) {
2337
2359
  this.specificationVersion = "v2";
2338
2360
  this.provider = "openrouter";
2361
+ this.supportsImageUrls = true;
2339
2362
  this.supportedUrls = {
2340
2363
  "image/*": [
2341
2364
  /^data:image\/[a-zA-Z]+;base64,/,