@llmgateway/ai-sdk-provider 2.2.1 → 2.3.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.
@@ -930,6 +930,15 @@ function getFileUrl({
930
930
  }
931
931
  return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
932
932
  }
933
+ function getMediaType(dataUrl, defaultMediaType) {
934
+ var _a15;
935
+ const match = dataUrl.match(/^data:([^;]+)/);
936
+ return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
937
+ }
938
+ function getBase64FromDataUrl(dataUrl) {
939
+ const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
940
+ return match ? match[1] : dataUrl;
941
+ }
933
942
 
934
943
  // src/chat/convert-to-llmgateway-chat-messages.ts
935
944
  function getCacheControl(providerMetadata) {
@@ -1142,101 +1151,119 @@ function getChatCompletionToolChoice(toolChoice) {
1142
1151
  }
1143
1152
 
1144
1153
  // src/chat/schemas.ts
1154
+ import { z as z6 } from "zod/v4";
1155
+
1156
+ // src/schemas/image.ts
1145
1157
  import { z as z5 } from "zod/v4";
1146
- var LLMGatewayChatCompletionBaseResponseSchema = z5.object({
1147
- id: z5.string().optional(),
1148
- model: z5.string().optional(),
1149
- usage: z5.object({
1150
- prompt_tokens: z5.number(),
1151
- prompt_tokens_details: z5.object({
1152
- cached_tokens: z5.number()
1158
+ var ImageResponseSchema = z5.object({
1159
+ type: z5.literal("image_url"),
1160
+ image_url: z5.object({
1161
+ url: z5.string()
1162
+ })
1163
+ });
1164
+ var ImageResponseWithUnknownSchema = z5.union([
1165
+ ImageResponseSchema,
1166
+ z5.unknown().transform(() => null)
1167
+ ]);
1168
+ var ImageResponseArraySchema = z5.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
1169
+
1170
+ // src/chat/schemas.ts
1171
+ var LLMGatewayChatCompletionBaseResponseSchema = z6.object({
1172
+ id: z6.string().optional(),
1173
+ model: z6.string().optional(),
1174
+ usage: z6.object({
1175
+ prompt_tokens: z6.number(),
1176
+ prompt_tokens_details: z6.object({
1177
+ cached_tokens: z6.number()
1153
1178
  }).nullish(),
1154
- completion_tokens: z5.number(),
1155
- completion_tokens_details: z5.object({
1156
- reasoning_tokens: z5.number()
1179
+ completion_tokens: z6.number(),
1180
+ completion_tokens_details: z6.object({
1181
+ reasoning_tokens: z6.number()
1157
1182
  }).nullish(),
1158
- total_tokens: z5.number(),
1159
- cost: z5.number().optional(),
1160
- cost_details: z5.object({
1161
- upstream_inference_cost: z5.number().nullish()
1183
+ total_tokens: z6.number(),
1184
+ cost: z6.number().optional(),
1185
+ cost_details: z6.object({
1186
+ upstream_inference_cost: z6.number().nullish()
1162
1187
  }).nullish()
1163
1188
  }).nullish()
1164
1189
  });
1165
1190
  var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
1166
- choices: z5.array(
1167
- z5.object({
1168
- message: z5.object({
1169
- role: z5.literal("assistant"),
1170
- content: z5.string().nullable().optional(),
1171
- reasoning: z5.string().nullable().optional(),
1191
+ choices: z6.array(
1192
+ z6.object({
1193
+ message: z6.object({
1194
+ role: z6.literal("assistant"),
1195
+ content: z6.string().nullable().optional(),
1196
+ reasoning: z6.string().nullable().optional(),
1172
1197
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1173
- tool_calls: z5.array(
1174
- z5.object({
1175
- id: z5.string().optional().nullable(),
1176
- type: z5.literal("function"),
1177
- function: z5.object({
1178
- name: z5.string(),
1179
- arguments: z5.string()
1198
+ images: ImageResponseArraySchema.nullish(),
1199
+ tool_calls: z6.array(
1200
+ z6.object({
1201
+ id: z6.string().optional().nullable(),
1202
+ type: z6.literal("function"),
1203
+ function: z6.object({
1204
+ name: z6.string(),
1205
+ arguments: z6.string()
1180
1206
  })
1181
1207
  })
1182
1208
  ).optional()
1183
1209
  }),
1184
- index: z5.number().nullish(),
1185
- logprobs: z5.object({
1186
- content: z5.array(
1187
- z5.object({
1188
- token: z5.string(),
1189
- logprob: z5.number(),
1190
- top_logprobs: z5.array(
1191
- z5.object({
1192
- token: z5.string(),
1193
- logprob: z5.number()
1210
+ index: z6.number().nullish(),
1211
+ logprobs: z6.object({
1212
+ content: z6.array(
1213
+ z6.object({
1214
+ token: z6.string(),
1215
+ logprob: z6.number(),
1216
+ top_logprobs: z6.array(
1217
+ z6.object({
1218
+ token: z6.string(),
1219
+ logprob: z6.number()
1194
1220
  })
1195
1221
  )
1196
1222
  })
1197
1223
  ).nullable()
1198
1224
  }).nullable().optional(),
1199
- finish_reason: z5.string().optional().nullable()
1225
+ finish_reason: z6.string().optional().nullable()
1200
1226
  })
1201
1227
  )
1202
1228
  });
1203
- var LLMGatewayStreamChatCompletionChunkSchema = z5.union([
1229
+ var LLMGatewayStreamChatCompletionChunkSchema = z6.union([
1204
1230
  LLMGatewayChatCompletionBaseResponseSchema.extend({
1205
- choices: z5.array(
1206
- z5.object({
1207
- delta: z5.object({
1208
- role: z5.enum(["assistant"]).optional(),
1209
- content: z5.string().nullish(),
1210
- reasoning: z5.string().nullish().optional(),
1231
+ choices: z6.array(
1232
+ z6.object({
1233
+ delta: z6.object({
1234
+ role: z6.enum(["assistant"]).optional(),
1235
+ content: z6.string().nullish(),
1236
+ reasoning: z6.string().nullish().optional(),
1211
1237
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1212
- tool_calls: z5.array(
1213
- z5.object({
1214
- index: z5.number().nullish(),
1215
- id: z5.string().nullish(),
1216
- type: z5.literal("function").optional(),
1217
- function: z5.object({
1218
- name: z5.string().nullish(),
1219
- arguments: z5.string().nullish()
1238
+ images: ImageResponseArraySchema.nullish(),
1239
+ tool_calls: z6.array(
1240
+ z6.object({
1241
+ index: z6.number().nullish(),
1242
+ id: z6.string().nullish(),
1243
+ type: z6.literal("function").optional(),
1244
+ function: z6.object({
1245
+ name: z6.string().nullish(),
1246
+ arguments: z6.string().nullish()
1220
1247
  })
1221
1248
  })
1222
1249
  ).nullish()
1223
1250
  }).nullish(),
1224
- logprobs: z5.object({
1225
- content: z5.array(
1226
- z5.object({
1227
- token: z5.string(),
1228
- logprob: z5.number(),
1229
- top_logprobs: z5.array(
1230
- z5.object({
1231
- token: z5.string(),
1232
- logprob: z5.number()
1251
+ logprobs: z6.object({
1252
+ content: z6.array(
1253
+ z6.object({
1254
+ token: z6.string(),
1255
+ logprob: z6.number(),
1256
+ top_logprobs: z6.array(
1257
+ z6.object({
1258
+ token: z6.string(),
1259
+ logprob: z6.number()
1233
1260
  })
1234
1261
  )
1235
1262
  })
1236
1263
  ).nullable()
1237
1264
  }).nullish(),
1238
- finish_reason: z5.string().nullable().optional(),
1239
- index: z5.number().nullish()
1265
+ finish_reason: z6.string().nullable().optional(),
1266
+ index: z6.number().nullish()
1240
1267
  })
1241
1268
  )
1242
1269
  }),
@@ -1434,6 +1461,33 @@ var LLMGatewayChatLanguageModel = class {
1434
1461
  });
1435
1462
  }
1436
1463
  }
1464
+ if (choice.message.images) {
1465
+ for (const image of choice.message.images) {
1466
+ content.push({
1467
+ type: "file",
1468
+ mediaType: getMediaType(image.image_url.url, "image/jpeg"),
1469
+ data: getBase64FromDataUrl(image.image_url.url)
1470
+ });
1471
+ }
1472
+ }
1473
+ if (choice.message.annotations) {
1474
+ for (const annotation of choice.message.annotations) {
1475
+ if (annotation.type === "url_citation") {
1476
+ content.push({
1477
+ type: "source",
1478
+ sourceType: "url",
1479
+ id: annotation.url_citation.url,
1480
+ url: annotation.url_citation.url,
1481
+ title: annotation.url_citation.title,
1482
+ providerMetadata: {
1483
+ openrouter: {
1484
+ content: annotation.url_citation.content || ""
1485
+ }
1486
+ }
1487
+ });
1488
+ }
1489
+ }
1490
+ }
1437
1491
  return {
1438
1492
  content,
1439
1493
  finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
@@ -1719,6 +1773,15 @@ var LLMGatewayChatLanguageModel = class {
1719
1773
  }
1720
1774
  }
1721
1775
  }
1776
+ if (delta.images != null) {
1777
+ for (const image of delta.images) {
1778
+ controller.enqueue({
1779
+ type: "file",
1780
+ mediaType: getMediaType(image.image_url.url, "image/jpeg"),
1781
+ data: getBase64FromDataUrl(image.image_url.url)
1782
+ });
1783
+ }
1784
+ }
1722
1785
  },
1723
1786
  flush(controller) {
1724
1787
  var _a16;
@@ -1872,36 +1935,36 @@ ${assistantMessage}
1872
1935
  }
1873
1936
 
1874
1937
  // src/completion/schemas.ts
1875
- import { z as z6 } from "zod/v4";
1876
- var LLMGatewayCompletionChunkSchema = z6.union([
1877
- z6.object({
1878
- id: z6.string().optional(),
1879
- model: z6.string().optional(),
1880
- choices: z6.array(
1881
- z6.object({
1882
- text: z6.string(),
1883
- reasoning: z6.string().nullish().optional(),
1938
+ import { z as z7 } from "zod/v4";
1939
+ var LLMGatewayCompletionChunkSchema = z7.union([
1940
+ z7.object({
1941
+ id: z7.string().optional(),
1942
+ model: z7.string().optional(),
1943
+ choices: z7.array(
1944
+ z7.object({
1945
+ text: z7.string(),
1946
+ reasoning: z7.string().nullish().optional(),
1884
1947
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1885
- finish_reason: z6.string().nullish(),
1886
- index: z6.number().nullish(),
1887
- logprobs: z6.object({
1888
- tokens: z6.array(z6.string()),
1889
- token_logprobs: z6.array(z6.number()),
1890
- top_logprobs: z6.array(z6.record(z6.string(), z6.number())).nullable()
1948
+ finish_reason: z7.string().nullish(),
1949
+ index: z7.number().nullish(),
1950
+ logprobs: z7.object({
1951
+ tokens: z7.array(z7.string()),
1952
+ token_logprobs: z7.array(z7.number()),
1953
+ top_logprobs: z7.array(z7.record(z7.string(), z7.number())).nullable()
1891
1954
  }).nullable().optional()
1892
1955
  })
1893
1956
  ),
1894
- usage: z6.object({
1895
- prompt_tokens: z6.number(),
1896
- prompt_tokens_details: z6.object({
1897
- cached_tokens: z6.number()
1957
+ usage: z7.object({
1958
+ prompt_tokens: z7.number(),
1959
+ prompt_tokens_details: z7.object({
1960
+ cached_tokens: z7.number()
1898
1961
  }).nullish(),
1899
- completion_tokens: z6.number(),
1900
- completion_tokens_details: z6.object({
1901
- reasoning_tokens: z6.number()
1962
+ completion_tokens: z7.number(),
1963
+ completion_tokens_details: z7.object({
1964
+ reasoning_tokens: z7.number()
1902
1965
  }).nullish(),
1903
- total_tokens: z6.number(),
1904
- cost: z6.number().optional()
1966
+ total_tokens: z7.number(),
1967
+ cost: z7.number().optional()
1905
1968
  }).nullish()
1906
1969
  }),
1907
1970
  LLMGatewayErrorResponseSchema