@llmgateway/ai-sdk-provider 2.2.0 → 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
  }),
@@ -1275,7 +1302,6 @@ var LLMGatewayChatLanguageModel = class {
1275
1302
  tools,
1276
1303
  toolChoice
1277
1304
  }) {
1278
- var _a15;
1279
1305
  const baseArgs = __spreadValues(__spreadValues({
1280
1306
  // model id:
1281
1307
  model: this.modelId,
@@ -1309,10 +1335,10 @@ var LLMGatewayChatLanguageModel = class {
1309
1335
  response_format: {
1310
1336
  type: "json_schema",
1311
1337
  json_schema: {
1312
- name: responseFormat.schema.name || "response",
1313
- description: responseFormat.schema.description,
1338
+ name: responseFormat.name || "response",
1339
+ description: responseFormat.description,
1314
1340
  schema: responseFormat.schema,
1315
- strict: (_a15 = responseFormat.schema.strict) != null ? _a15 : true
1341
+ strict: true
1316
1342
  }
1317
1343
  }
1318
1344
  });
@@ -1435,6 +1461,33 @@ var LLMGatewayChatLanguageModel = class {
1435
1461
  });
1436
1462
  }
1437
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
+ }
1438
1491
  return {
1439
1492
  content,
1440
1493
  finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
@@ -1720,6 +1773,15 @@ var LLMGatewayChatLanguageModel = class {
1720
1773
  }
1721
1774
  }
1722
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
+ }
1723
1785
  },
1724
1786
  flush(controller) {
1725
1787
  var _a16;
@@ -1873,36 +1935,36 @@ ${assistantMessage}
1873
1935
  }
1874
1936
 
1875
1937
  // src/completion/schemas.ts
1876
- import { z as z6 } from "zod/v4";
1877
- var LLMGatewayCompletionChunkSchema = z6.union([
1878
- z6.object({
1879
- id: z6.string().optional(),
1880
- model: z6.string().optional(),
1881
- choices: z6.array(
1882
- z6.object({
1883
- text: z6.string(),
1884
- 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(),
1885
1947
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1886
- finish_reason: z6.string().nullish(),
1887
- index: z6.number().nullish(),
1888
- logprobs: z6.object({
1889
- tokens: z6.array(z6.string()),
1890
- token_logprobs: z6.array(z6.number()),
1891
- 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()
1892
1954
  }).nullable().optional()
1893
1955
  })
1894
1956
  ),
1895
- usage: z6.object({
1896
- prompt_tokens: z6.number(),
1897
- prompt_tokens_details: z6.object({
1898
- cached_tokens: z6.number()
1957
+ usage: z7.object({
1958
+ prompt_tokens: z7.number(),
1959
+ prompt_tokens_details: z7.object({
1960
+ cached_tokens: z7.number()
1899
1961
  }).nullish(),
1900
- completion_tokens: z6.number(),
1901
- completion_tokens_details: z6.object({
1902
- reasoning_tokens: z6.number()
1962
+ completion_tokens: z7.number(),
1963
+ completion_tokens_details: z7.object({
1964
+ reasoning_tokens: z7.number()
1903
1965
  }).nullish(),
1904
- total_tokens: z6.number(),
1905
- cost: z6.number().optional()
1966
+ total_tokens: z7.number(),
1967
+ cost: z7.number().optional()
1906
1968
  }).nullish()
1907
1969
  }),
1908
1970
  LLMGatewayErrorResponseSchema