@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.
- package/dist/index.js +154 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -92
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +154 -92
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +154 -92
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1010,6 +1010,15 @@ function getFileUrl({
|
|
|
1010
1010
|
}
|
|
1011
1011
|
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
1012
1012
|
}
|
|
1013
|
+
function getMediaType(dataUrl, defaultMediaType) {
|
|
1014
|
+
var _a15;
|
|
1015
|
+
const match = dataUrl.match(/^data:([^;]+)/);
|
|
1016
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
1017
|
+
}
|
|
1018
|
+
function getBase64FromDataUrl(dataUrl) {
|
|
1019
|
+
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
1020
|
+
return match ? match[1] : dataUrl;
|
|
1021
|
+
}
|
|
1013
1022
|
|
|
1014
1023
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
1015
1024
|
function getCacheControl(providerMetadata) {
|
|
@@ -1222,101 +1231,119 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1222
1231
|
}
|
|
1223
1232
|
|
|
1224
1233
|
// src/chat/schemas.ts
|
|
1234
|
+
var import_v45 = require("zod/v4");
|
|
1235
|
+
|
|
1236
|
+
// src/schemas/image.ts
|
|
1225
1237
|
var import_v44 = require("zod/v4");
|
|
1226
|
-
var
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1238
|
+
var ImageResponseSchema = import_v44.z.object({
|
|
1239
|
+
type: import_v44.z.literal("image_url"),
|
|
1240
|
+
image_url: import_v44.z.object({
|
|
1241
|
+
url: import_v44.z.string()
|
|
1242
|
+
})
|
|
1243
|
+
});
|
|
1244
|
+
var ImageResponseWithUnknownSchema = import_v44.z.union([
|
|
1245
|
+
ImageResponseSchema,
|
|
1246
|
+
import_v44.z.unknown().transform(() => null)
|
|
1247
|
+
]);
|
|
1248
|
+
var ImageResponseArraySchema = import_v44.z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
1249
|
+
|
|
1250
|
+
// src/chat/schemas.ts
|
|
1251
|
+
var LLMGatewayChatCompletionBaseResponseSchema = import_v45.z.object({
|
|
1252
|
+
id: import_v45.z.string().optional(),
|
|
1253
|
+
model: import_v45.z.string().optional(),
|
|
1254
|
+
usage: import_v45.z.object({
|
|
1255
|
+
prompt_tokens: import_v45.z.number(),
|
|
1256
|
+
prompt_tokens_details: import_v45.z.object({
|
|
1257
|
+
cached_tokens: import_v45.z.number()
|
|
1233
1258
|
}).nullish(),
|
|
1234
|
-
completion_tokens:
|
|
1235
|
-
completion_tokens_details:
|
|
1236
|
-
reasoning_tokens:
|
|
1259
|
+
completion_tokens: import_v45.z.number(),
|
|
1260
|
+
completion_tokens_details: import_v45.z.object({
|
|
1261
|
+
reasoning_tokens: import_v45.z.number()
|
|
1237
1262
|
}).nullish(),
|
|
1238
|
-
total_tokens:
|
|
1239
|
-
cost:
|
|
1240
|
-
cost_details:
|
|
1241
|
-
upstream_inference_cost:
|
|
1263
|
+
total_tokens: import_v45.z.number(),
|
|
1264
|
+
cost: import_v45.z.number().optional(),
|
|
1265
|
+
cost_details: import_v45.z.object({
|
|
1266
|
+
upstream_inference_cost: import_v45.z.number().nullish()
|
|
1242
1267
|
}).nullish()
|
|
1243
1268
|
}).nullish()
|
|
1244
1269
|
});
|
|
1245
1270
|
var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1246
|
-
choices:
|
|
1247
|
-
|
|
1248
|
-
message:
|
|
1249
|
-
role:
|
|
1250
|
-
content:
|
|
1251
|
-
reasoning:
|
|
1271
|
+
choices: import_v45.z.array(
|
|
1272
|
+
import_v45.z.object({
|
|
1273
|
+
message: import_v45.z.object({
|
|
1274
|
+
role: import_v45.z.literal("assistant"),
|
|
1275
|
+
content: import_v45.z.string().nullable().optional(),
|
|
1276
|
+
reasoning: import_v45.z.string().nullable().optional(),
|
|
1252
1277
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1278
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1279
|
+
tool_calls: import_v45.z.array(
|
|
1280
|
+
import_v45.z.object({
|
|
1281
|
+
id: import_v45.z.string().optional().nullable(),
|
|
1282
|
+
type: import_v45.z.literal("function"),
|
|
1283
|
+
function: import_v45.z.object({
|
|
1284
|
+
name: import_v45.z.string(),
|
|
1285
|
+
arguments: import_v45.z.string()
|
|
1260
1286
|
})
|
|
1261
1287
|
})
|
|
1262
1288
|
).optional()
|
|
1263
1289
|
}),
|
|
1264
|
-
index:
|
|
1265
|
-
logprobs:
|
|
1266
|
-
content:
|
|
1267
|
-
|
|
1268
|
-
token:
|
|
1269
|
-
logprob:
|
|
1270
|
-
top_logprobs:
|
|
1271
|
-
|
|
1272
|
-
token:
|
|
1273
|
-
logprob:
|
|
1290
|
+
index: import_v45.z.number().nullish(),
|
|
1291
|
+
logprobs: import_v45.z.object({
|
|
1292
|
+
content: import_v45.z.array(
|
|
1293
|
+
import_v45.z.object({
|
|
1294
|
+
token: import_v45.z.string(),
|
|
1295
|
+
logprob: import_v45.z.number(),
|
|
1296
|
+
top_logprobs: import_v45.z.array(
|
|
1297
|
+
import_v45.z.object({
|
|
1298
|
+
token: import_v45.z.string(),
|
|
1299
|
+
logprob: import_v45.z.number()
|
|
1274
1300
|
})
|
|
1275
1301
|
)
|
|
1276
1302
|
})
|
|
1277
1303
|
).nullable()
|
|
1278
1304
|
}).nullable().optional(),
|
|
1279
|
-
finish_reason:
|
|
1305
|
+
finish_reason: import_v45.z.string().optional().nullable()
|
|
1280
1306
|
})
|
|
1281
1307
|
)
|
|
1282
1308
|
});
|
|
1283
|
-
var LLMGatewayStreamChatCompletionChunkSchema =
|
|
1309
|
+
var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
1284
1310
|
LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1285
|
-
choices:
|
|
1286
|
-
|
|
1287
|
-
delta:
|
|
1288
|
-
role:
|
|
1289
|
-
content:
|
|
1290
|
-
reasoning:
|
|
1311
|
+
choices: import_v45.z.array(
|
|
1312
|
+
import_v45.z.object({
|
|
1313
|
+
delta: import_v45.z.object({
|
|
1314
|
+
role: import_v45.z.enum(["assistant"]).optional(),
|
|
1315
|
+
content: import_v45.z.string().nullish(),
|
|
1316
|
+
reasoning: import_v45.z.string().nullish().optional(),
|
|
1291
1317
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1318
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1319
|
+
tool_calls: import_v45.z.array(
|
|
1320
|
+
import_v45.z.object({
|
|
1321
|
+
index: import_v45.z.number().nullish(),
|
|
1322
|
+
id: import_v45.z.string().nullish(),
|
|
1323
|
+
type: import_v45.z.literal("function").optional(),
|
|
1324
|
+
function: import_v45.z.object({
|
|
1325
|
+
name: import_v45.z.string().nullish(),
|
|
1326
|
+
arguments: import_v45.z.string().nullish()
|
|
1300
1327
|
})
|
|
1301
1328
|
})
|
|
1302
1329
|
).nullish()
|
|
1303
1330
|
}).nullish(),
|
|
1304
|
-
logprobs:
|
|
1305
|
-
content:
|
|
1306
|
-
|
|
1307
|
-
token:
|
|
1308
|
-
logprob:
|
|
1309
|
-
top_logprobs:
|
|
1310
|
-
|
|
1311
|
-
token:
|
|
1312
|
-
logprob:
|
|
1331
|
+
logprobs: import_v45.z.object({
|
|
1332
|
+
content: import_v45.z.array(
|
|
1333
|
+
import_v45.z.object({
|
|
1334
|
+
token: import_v45.z.string(),
|
|
1335
|
+
logprob: import_v45.z.number(),
|
|
1336
|
+
top_logprobs: import_v45.z.array(
|
|
1337
|
+
import_v45.z.object({
|
|
1338
|
+
token: import_v45.z.string(),
|
|
1339
|
+
logprob: import_v45.z.number()
|
|
1313
1340
|
})
|
|
1314
1341
|
)
|
|
1315
1342
|
})
|
|
1316
1343
|
).nullable()
|
|
1317
1344
|
}).nullish(),
|
|
1318
|
-
finish_reason:
|
|
1319
|
-
index:
|
|
1345
|
+
finish_reason: import_v45.z.string().nullable().optional(),
|
|
1346
|
+
index: import_v45.z.number().nullish()
|
|
1320
1347
|
})
|
|
1321
1348
|
)
|
|
1322
1349
|
}),
|
|
@@ -1355,7 +1382,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1355
1382
|
tools,
|
|
1356
1383
|
toolChoice
|
|
1357
1384
|
}) {
|
|
1358
|
-
var _a15;
|
|
1359
1385
|
const baseArgs = __spreadValues(__spreadValues({
|
|
1360
1386
|
// model id:
|
|
1361
1387
|
model: this.modelId,
|
|
@@ -1389,10 +1415,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1389
1415
|
response_format: {
|
|
1390
1416
|
type: "json_schema",
|
|
1391
1417
|
json_schema: {
|
|
1392
|
-
name: responseFormat.
|
|
1393
|
-
description: responseFormat.
|
|
1418
|
+
name: responseFormat.name || "response",
|
|
1419
|
+
description: responseFormat.description,
|
|
1394
1420
|
schema: responseFormat.schema,
|
|
1395
|
-
strict:
|
|
1421
|
+
strict: true
|
|
1396
1422
|
}
|
|
1397
1423
|
}
|
|
1398
1424
|
});
|
|
@@ -1515,6 +1541,33 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1515
1541
|
});
|
|
1516
1542
|
}
|
|
1517
1543
|
}
|
|
1544
|
+
if (choice.message.images) {
|
|
1545
|
+
for (const image of choice.message.images) {
|
|
1546
|
+
content.push({
|
|
1547
|
+
type: "file",
|
|
1548
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1549
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
if (choice.message.annotations) {
|
|
1554
|
+
for (const annotation of choice.message.annotations) {
|
|
1555
|
+
if (annotation.type === "url_citation") {
|
|
1556
|
+
content.push({
|
|
1557
|
+
type: "source",
|
|
1558
|
+
sourceType: "url",
|
|
1559
|
+
id: annotation.url_citation.url,
|
|
1560
|
+
url: annotation.url_citation.url,
|
|
1561
|
+
title: annotation.url_citation.title,
|
|
1562
|
+
providerMetadata: {
|
|
1563
|
+
openrouter: {
|
|
1564
|
+
content: annotation.url_citation.content || ""
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1518
1571
|
return {
|
|
1519
1572
|
content,
|
|
1520
1573
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
@@ -1800,6 +1853,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1800
1853
|
}
|
|
1801
1854
|
}
|
|
1802
1855
|
}
|
|
1856
|
+
if (delta.images != null) {
|
|
1857
|
+
for (const image of delta.images) {
|
|
1858
|
+
controller.enqueue({
|
|
1859
|
+
type: "file",
|
|
1860
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1861
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1803
1865
|
},
|
|
1804
1866
|
flush(controller) {
|
|
1805
1867
|
var _a16;
|
|
@@ -1953,36 +2015,36 @@ ${assistantMessage}
|
|
|
1953
2015
|
}
|
|
1954
2016
|
|
|
1955
2017
|
// src/completion/schemas.ts
|
|
1956
|
-
var
|
|
1957
|
-
var LLMGatewayCompletionChunkSchema =
|
|
1958
|
-
|
|
1959
|
-
id:
|
|
1960
|
-
model:
|
|
1961
|
-
choices:
|
|
1962
|
-
|
|
1963
|
-
text:
|
|
1964
|
-
reasoning:
|
|
2018
|
+
var import_v46 = require("zod/v4");
|
|
2019
|
+
var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
2020
|
+
import_v46.z.object({
|
|
2021
|
+
id: import_v46.z.string().optional(),
|
|
2022
|
+
model: import_v46.z.string().optional(),
|
|
2023
|
+
choices: import_v46.z.array(
|
|
2024
|
+
import_v46.z.object({
|
|
2025
|
+
text: import_v46.z.string(),
|
|
2026
|
+
reasoning: import_v46.z.string().nullish().optional(),
|
|
1965
2027
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1966
|
-
finish_reason:
|
|
1967
|
-
index:
|
|
1968
|
-
logprobs:
|
|
1969
|
-
tokens:
|
|
1970
|
-
token_logprobs:
|
|
1971
|
-
top_logprobs:
|
|
2028
|
+
finish_reason: import_v46.z.string().nullish(),
|
|
2029
|
+
index: import_v46.z.number().nullish(),
|
|
2030
|
+
logprobs: import_v46.z.object({
|
|
2031
|
+
tokens: import_v46.z.array(import_v46.z.string()),
|
|
2032
|
+
token_logprobs: import_v46.z.array(import_v46.z.number()),
|
|
2033
|
+
top_logprobs: import_v46.z.array(import_v46.z.record(import_v46.z.string(), import_v46.z.number())).nullable()
|
|
1972
2034
|
}).nullable().optional()
|
|
1973
2035
|
})
|
|
1974
2036
|
),
|
|
1975
|
-
usage:
|
|
1976
|
-
prompt_tokens:
|
|
1977
|
-
prompt_tokens_details:
|
|
1978
|
-
cached_tokens:
|
|
2037
|
+
usage: import_v46.z.object({
|
|
2038
|
+
prompt_tokens: import_v46.z.number(),
|
|
2039
|
+
prompt_tokens_details: import_v46.z.object({
|
|
2040
|
+
cached_tokens: import_v46.z.number()
|
|
1979
2041
|
}).nullish(),
|
|
1980
|
-
completion_tokens:
|
|
1981
|
-
completion_tokens_details:
|
|
1982
|
-
reasoning_tokens:
|
|
2042
|
+
completion_tokens: import_v46.z.number(),
|
|
2043
|
+
completion_tokens_details: import_v46.z.object({
|
|
2044
|
+
reasoning_tokens: import_v46.z.number()
|
|
1983
2045
|
}).nullish(),
|
|
1984
|
-
total_tokens:
|
|
1985
|
-
cost:
|
|
2046
|
+
total_tokens: import_v46.z.number(),
|
|
2047
|
+
cost: import_v46.z.number().optional()
|
|
1986
2048
|
}).nullish()
|
|
1987
2049
|
}),
|
|
1988
2050
|
LLMGatewayErrorResponseSchema
|