@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.
- package/dist/index.js +151 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -88
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +151 -88
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +151 -88
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -965,6 +965,15 @@ function getFileUrl({
|
|
|
965
965
|
}
|
|
966
966
|
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
967
967
|
}
|
|
968
|
+
function getMediaType(dataUrl, defaultMediaType) {
|
|
969
|
+
var _a15;
|
|
970
|
+
const match = dataUrl.match(/^data:([^;]+)/);
|
|
971
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
972
|
+
}
|
|
973
|
+
function getBase64FromDataUrl(dataUrl) {
|
|
974
|
+
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
975
|
+
return match ? match[1] : dataUrl;
|
|
976
|
+
}
|
|
968
977
|
|
|
969
978
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
970
979
|
function getCacheControl(providerMetadata) {
|
|
@@ -1177,101 +1186,119 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1177
1186
|
}
|
|
1178
1187
|
|
|
1179
1188
|
// src/chat/schemas.ts
|
|
1189
|
+
var import_v45 = require("zod/v4");
|
|
1190
|
+
|
|
1191
|
+
// src/schemas/image.ts
|
|
1180
1192
|
var import_v44 = require("zod/v4");
|
|
1181
|
-
var
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1193
|
+
var ImageResponseSchema = import_v44.z.object({
|
|
1194
|
+
type: import_v44.z.literal("image_url"),
|
|
1195
|
+
image_url: import_v44.z.object({
|
|
1196
|
+
url: import_v44.z.string()
|
|
1197
|
+
})
|
|
1198
|
+
});
|
|
1199
|
+
var ImageResponseWithUnknownSchema = import_v44.z.union([
|
|
1200
|
+
ImageResponseSchema,
|
|
1201
|
+
import_v44.z.unknown().transform(() => null)
|
|
1202
|
+
]);
|
|
1203
|
+
var ImageResponseArraySchema = import_v44.z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
1204
|
+
|
|
1205
|
+
// src/chat/schemas.ts
|
|
1206
|
+
var LLMGatewayChatCompletionBaseResponseSchema = import_v45.z.object({
|
|
1207
|
+
id: import_v45.z.string().optional(),
|
|
1208
|
+
model: import_v45.z.string().optional(),
|
|
1209
|
+
usage: import_v45.z.object({
|
|
1210
|
+
prompt_tokens: import_v45.z.number(),
|
|
1211
|
+
prompt_tokens_details: import_v45.z.object({
|
|
1212
|
+
cached_tokens: import_v45.z.number()
|
|
1188
1213
|
}).nullish(),
|
|
1189
|
-
completion_tokens:
|
|
1190
|
-
completion_tokens_details:
|
|
1191
|
-
reasoning_tokens:
|
|
1214
|
+
completion_tokens: import_v45.z.number(),
|
|
1215
|
+
completion_tokens_details: import_v45.z.object({
|
|
1216
|
+
reasoning_tokens: import_v45.z.number()
|
|
1192
1217
|
}).nullish(),
|
|
1193
|
-
total_tokens:
|
|
1194
|
-
cost:
|
|
1195
|
-
cost_details:
|
|
1196
|
-
upstream_inference_cost:
|
|
1218
|
+
total_tokens: import_v45.z.number(),
|
|
1219
|
+
cost: import_v45.z.number().optional(),
|
|
1220
|
+
cost_details: import_v45.z.object({
|
|
1221
|
+
upstream_inference_cost: import_v45.z.number().nullish()
|
|
1197
1222
|
}).nullish()
|
|
1198
1223
|
}).nullish()
|
|
1199
1224
|
});
|
|
1200
1225
|
var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1201
|
-
choices:
|
|
1202
|
-
|
|
1203
|
-
message:
|
|
1204
|
-
role:
|
|
1205
|
-
content:
|
|
1206
|
-
reasoning:
|
|
1226
|
+
choices: import_v45.z.array(
|
|
1227
|
+
import_v45.z.object({
|
|
1228
|
+
message: import_v45.z.object({
|
|
1229
|
+
role: import_v45.z.literal("assistant"),
|
|
1230
|
+
content: import_v45.z.string().nullable().optional(),
|
|
1231
|
+
reasoning: import_v45.z.string().nullable().optional(),
|
|
1207
1232
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1233
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1234
|
+
tool_calls: import_v45.z.array(
|
|
1235
|
+
import_v45.z.object({
|
|
1236
|
+
id: import_v45.z.string().optional().nullable(),
|
|
1237
|
+
type: import_v45.z.literal("function"),
|
|
1238
|
+
function: import_v45.z.object({
|
|
1239
|
+
name: import_v45.z.string(),
|
|
1240
|
+
arguments: import_v45.z.string()
|
|
1215
1241
|
})
|
|
1216
1242
|
})
|
|
1217
1243
|
).optional()
|
|
1218
1244
|
}),
|
|
1219
|
-
index:
|
|
1220
|
-
logprobs:
|
|
1221
|
-
content:
|
|
1222
|
-
|
|
1223
|
-
token:
|
|
1224
|
-
logprob:
|
|
1225
|
-
top_logprobs:
|
|
1226
|
-
|
|
1227
|
-
token:
|
|
1228
|
-
logprob:
|
|
1245
|
+
index: import_v45.z.number().nullish(),
|
|
1246
|
+
logprobs: import_v45.z.object({
|
|
1247
|
+
content: import_v45.z.array(
|
|
1248
|
+
import_v45.z.object({
|
|
1249
|
+
token: import_v45.z.string(),
|
|
1250
|
+
logprob: import_v45.z.number(),
|
|
1251
|
+
top_logprobs: import_v45.z.array(
|
|
1252
|
+
import_v45.z.object({
|
|
1253
|
+
token: import_v45.z.string(),
|
|
1254
|
+
logprob: import_v45.z.number()
|
|
1229
1255
|
})
|
|
1230
1256
|
)
|
|
1231
1257
|
})
|
|
1232
1258
|
).nullable()
|
|
1233
1259
|
}).nullable().optional(),
|
|
1234
|
-
finish_reason:
|
|
1260
|
+
finish_reason: import_v45.z.string().optional().nullable()
|
|
1235
1261
|
})
|
|
1236
1262
|
)
|
|
1237
1263
|
});
|
|
1238
|
-
var LLMGatewayStreamChatCompletionChunkSchema =
|
|
1264
|
+
var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
1239
1265
|
LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1240
|
-
choices:
|
|
1241
|
-
|
|
1242
|
-
delta:
|
|
1243
|
-
role:
|
|
1244
|
-
content:
|
|
1245
|
-
reasoning:
|
|
1266
|
+
choices: import_v45.z.array(
|
|
1267
|
+
import_v45.z.object({
|
|
1268
|
+
delta: import_v45.z.object({
|
|
1269
|
+
role: import_v45.z.enum(["assistant"]).optional(),
|
|
1270
|
+
content: import_v45.z.string().nullish(),
|
|
1271
|
+
reasoning: import_v45.z.string().nullish().optional(),
|
|
1246
1272
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1273
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1274
|
+
tool_calls: import_v45.z.array(
|
|
1275
|
+
import_v45.z.object({
|
|
1276
|
+
index: import_v45.z.number().nullish(),
|
|
1277
|
+
id: import_v45.z.string().nullish(),
|
|
1278
|
+
type: import_v45.z.literal("function").optional(),
|
|
1279
|
+
function: import_v45.z.object({
|
|
1280
|
+
name: import_v45.z.string().nullish(),
|
|
1281
|
+
arguments: import_v45.z.string().nullish()
|
|
1255
1282
|
})
|
|
1256
1283
|
})
|
|
1257
1284
|
).nullish()
|
|
1258
1285
|
}).nullish(),
|
|
1259
|
-
logprobs:
|
|
1260
|
-
content:
|
|
1261
|
-
|
|
1262
|
-
token:
|
|
1263
|
-
logprob:
|
|
1264
|
-
top_logprobs:
|
|
1265
|
-
|
|
1266
|
-
token:
|
|
1267
|
-
logprob:
|
|
1286
|
+
logprobs: import_v45.z.object({
|
|
1287
|
+
content: import_v45.z.array(
|
|
1288
|
+
import_v45.z.object({
|
|
1289
|
+
token: import_v45.z.string(),
|
|
1290
|
+
logprob: import_v45.z.number(),
|
|
1291
|
+
top_logprobs: import_v45.z.array(
|
|
1292
|
+
import_v45.z.object({
|
|
1293
|
+
token: import_v45.z.string(),
|
|
1294
|
+
logprob: import_v45.z.number()
|
|
1268
1295
|
})
|
|
1269
1296
|
)
|
|
1270
1297
|
})
|
|
1271
1298
|
).nullable()
|
|
1272
1299
|
}).nullish(),
|
|
1273
|
-
finish_reason:
|
|
1274
|
-
index:
|
|
1300
|
+
finish_reason: import_v45.z.string().nullable().optional(),
|
|
1301
|
+
index: import_v45.z.number().nullish()
|
|
1275
1302
|
})
|
|
1276
1303
|
)
|
|
1277
1304
|
}),
|
|
@@ -1469,6 +1496,33 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1469
1496
|
});
|
|
1470
1497
|
}
|
|
1471
1498
|
}
|
|
1499
|
+
if (choice.message.images) {
|
|
1500
|
+
for (const image of choice.message.images) {
|
|
1501
|
+
content.push({
|
|
1502
|
+
type: "file",
|
|
1503
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1504
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
if (choice.message.annotations) {
|
|
1509
|
+
for (const annotation of choice.message.annotations) {
|
|
1510
|
+
if (annotation.type === "url_citation") {
|
|
1511
|
+
content.push({
|
|
1512
|
+
type: "source",
|
|
1513
|
+
sourceType: "url",
|
|
1514
|
+
id: annotation.url_citation.url,
|
|
1515
|
+
url: annotation.url_citation.url,
|
|
1516
|
+
title: annotation.url_citation.title,
|
|
1517
|
+
providerMetadata: {
|
|
1518
|
+
openrouter: {
|
|
1519
|
+
content: annotation.url_citation.content || ""
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1472
1526
|
return {
|
|
1473
1527
|
content,
|
|
1474
1528
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
@@ -1754,6 +1808,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1754
1808
|
}
|
|
1755
1809
|
}
|
|
1756
1810
|
}
|
|
1811
|
+
if (delta.images != null) {
|
|
1812
|
+
for (const image of delta.images) {
|
|
1813
|
+
controller.enqueue({
|
|
1814
|
+
type: "file",
|
|
1815
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1816
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1757
1820
|
},
|
|
1758
1821
|
flush(controller) {
|
|
1759
1822
|
var _a16;
|
|
@@ -1907,36 +1970,36 @@ ${assistantMessage}
|
|
|
1907
1970
|
}
|
|
1908
1971
|
|
|
1909
1972
|
// src/completion/schemas.ts
|
|
1910
|
-
var
|
|
1911
|
-
var LLMGatewayCompletionChunkSchema =
|
|
1912
|
-
|
|
1913
|
-
id:
|
|
1914
|
-
model:
|
|
1915
|
-
choices:
|
|
1916
|
-
|
|
1917
|
-
text:
|
|
1918
|
-
reasoning:
|
|
1973
|
+
var import_v46 = require("zod/v4");
|
|
1974
|
+
var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
1975
|
+
import_v46.z.object({
|
|
1976
|
+
id: import_v46.z.string().optional(),
|
|
1977
|
+
model: import_v46.z.string().optional(),
|
|
1978
|
+
choices: import_v46.z.array(
|
|
1979
|
+
import_v46.z.object({
|
|
1980
|
+
text: import_v46.z.string(),
|
|
1981
|
+
reasoning: import_v46.z.string().nullish().optional(),
|
|
1919
1982
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1920
|
-
finish_reason:
|
|
1921
|
-
index:
|
|
1922
|
-
logprobs:
|
|
1923
|
-
tokens:
|
|
1924
|
-
token_logprobs:
|
|
1925
|
-
top_logprobs:
|
|
1983
|
+
finish_reason: import_v46.z.string().nullish(),
|
|
1984
|
+
index: import_v46.z.number().nullish(),
|
|
1985
|
+
logprobs: import_v46.z.object({
|
|
1986
|
+
tokens: import_v46.z.array(import_v46.z.string()),
|
|
1987
|
+
token_logprobs: import_v46.z.array(import_v46.z.number()),
|
|
1988
|
+
top_logprobs: import_v46.z.array(import_v46.z.record(import_v46.z.string(), import_v46.z.number())).nullable()
|
|
1926
1989
|
}).nullable().optional()
|
|
1927
1990
|
})
|
|
1928
1991
|
),
|
|
1929
|
-
usage:
|
|
1930
|
-
prompt_tokens:
|
|
1931
|
-
prompt_tokens_details:
|
|
1932
|
-
cached_tokens:
|
|
1992
|
+
usage: import_v46.z.object({
|
|
1993
|
+
prompt_tokens: import_v46.z.number(),
|
|
1994
|
+
prompt_tokens_details: import_v46.z.object({
|
|
1995
|
+
cached_tokens: import_v46.z.number()
|
|
1933
1996
|
}).nullish(),
|
|
1934
|
-
completion_tokens:
|
|
1935
|
-
completion_tokens_details:
|
|
1936
|
-
reasoning_tokens:
|
|
1997
|
+
completion_tokens: import_v46.z.number(),
|
|
1998
|
+
completion_tokens_details: import_v46.z.object({
|
|
1999
|
+
reasoning_tokens: import_v46.z.number()
|
|
1937
2000
|
}).nullish(),
|
|
1938
|
-
total_tokens:
|
|
1939
|
-
cost:
|
|
2001
|
+
total_tokens: import_v46.z.number(),
|
|
2002
|
+
cost: import_v46.z.number().optional()
|
|
1940
2003
|
}).nullish()
|
|
1941
2004
|
}),
|
|
1942
2005
|
LLMGatewayErrorResponseSchema
|