@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.
@@ -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,/,
@@ -1545,7 +1563,16 @@ var OpenRouterChatLanguageModel = class {
1545
1563
  presence_penalty: presencePenalty,
1546
1564
  seed,
1547
1565
  stop: stopSequences,
1548
- response_format: responseFormat,
1566
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
1567
+ type: "json_schema",
1568
+ json_schema: __spreadValues({
1569
+ schema: responseFormat.schema,
1570
+ strict: true,
1571
+ name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1572
+ }, responseFormat.description && {
1573
+ description: responseFormat.description
1574
+ })
1575
+ } : { type: "json_object" } : void 0,
1549
1576
  top_k: topK,
1550
1577
  // messages:
1551
1578
  messages: convertToOpenRouterChatMessages(prompt),
@@ -1561,20 +1588,6 @@ var OpenRouterChatLanguageModel = class {
1561
1588
  // Debug settings:
1562
1589
  debug: this.settings.debug
1563
1590
  }, this.config.extraBody), this.settings.extraBody);
1564
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1565
- return __spreadProps(__spreadValues({}, baseArgs), {
1566
- response_format: {
1567
- type: "json_schema",
1568
- json_schema: __spreadValues({
1569
- schema: responseFormat.schema,
1570
- strict: true,
1571
- name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1572
- }, responseFormat.description && {
1573
- description: responseFormat.description
1574
- })
1575
- }
1576
- });
1577
- }
1578
1591
  if (tools && tools.length > 0) {
1579
1592
  const mappedTools = tools.filter(
1580
1593
  (tool) => tool.type === "function"
@@ -1594,7 +1607,7 @@ var OpenRouterChatLanguageModel = class {
1594
1607
  return baseArgs;
1595
1608
  }
1596
1609
  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;
1610
+ 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
1611
  const providerOptions = options.providerOptions || {};
1599
1612
  const openrouterOptions = providerOptions.openrouter || {};
1600
1613
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1752,6 +1765,9 @@ var OpenRouterChatLanguageModel = class {
1752
1765
  }
1753
1766
  }
1754
1767
  }
1768
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1769
+ (a) => a.type === "file"
1770
+ );
1755
1771
  return {
1756
1772
  content,
1757
1773
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1759,22 +1775,23 @@ var OpenRouterChatLanguageModel = class {
1759
1775
  warnings: [],
1760
1776
  providerMetadata: {
1761
1777
  openrouter: OpenRouterProviderMetadataSchema.parse({
1762
- provider: (_k = response.provider) != null ? _k : "",
1763
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1778
+ provider: (_l = response.provider) != null ? _l : "",
1779
+ reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
1780
+ annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
1764
1781
  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 ? {
1782
+ promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
1783
+ completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
1784
+ totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
1785
+ cost: (_q = response.usage) == null ? void 0 : _q.cost
1786
+ }, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
1770
1787
  promptTokensDetails: {
1771
1788
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1772
1789
  }
1773
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
1790
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1774
1791
  completionTokensDetails: {
1775
1792
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1776
1793
  }
1777
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
1794
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1778
1795
  costDetails: {
1779
1796
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1780
1797
  }
@@ -2336,6 +2353,7 @@ var OpenRouterCompletionLanguageModel = class {
2336
2353
  constructor(modelId, settings, config) {
2337
2354
  this.specificationVersion = "v2";
2338
2355
  this.provider = "openrouter";
2356
+ this.supportsImageUrls = true;
2339
2357
  this.supportedUrls = {
2340
2358
  "image/*": [
2341
2359
  /^data:image\/[a-zA-Z]+;base64,/,