@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/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
|
}),
|
|
@@ -1310,7 +1337,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1310
1337
|
tools,
|
|
1311
1338
|
toolChoice
|
|
1312
1339
|
}) {
|
|
1313
|
-
var _a15;
|
|
1314
1340
|
const baseArgs = __spreadValues(__spreadValues({
|
|
1315
1341
|
// model id:
|
|
1316
1342
|
model: this.modelId,
|
|
@@ -1344,10 +1370,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1344
1370
|
response_format: {
|
|
1345
1371
|
type: "json_schema",
|
|
1346
1372
|
json_schema: {
|
|
1347
|
-
name: responseFormat.
|
|
1348
|
-
description: responseFormat.
|
|
1373
|
+
name: responseFormat.name || "response",
|
|
1374
|
+
description: responseFormat.description,
|
|
1349
1375
|
schema: responseFormat.schema,
|
|
1350
|
-
strict:
|
|
1376
|
+
strict: true
|
|
1351
1377
|
}
|
|
1352
1378
|
}
|
|
1353
1379
|
});
|
|
@@ -1470,6 +1496,33 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1470
1496
|
});
|
|
1471
1497
|
}
|
|
1472
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
|
+
}
|
|
1473
1526
|
return {
|
|
1474
1527
|
content,
|
|
1475
1528
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
@@ -1755,6 +1808,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1755
1808
|
}
|
|
1756
1809
|
}
|
|
1757
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
|
+
}
|
|
1758
1820
|
},
|
|
1759
1821
|
flush(controller) {
|
|
1760
1822
|
var _a16;
|
|
@@ -1908,36 +1970,36 @@ ${assistantMessage}
|
|
|
1908
1970
|
}
|
|
1909
1971
|
|
|
1910
1972
|
// src/completion/schemas.ts
|
|
1911
|
-
var
|
|
1912
|
-
var LLMGatewayCompletionChunkSchema =
|
|
1913
|
-
|
|
1914
|
-
id:
|
|
1915
|
-
model:
|
|
1916
|
-
choices:
|
|
1917
|
-
|
|
1918
|
-
text:
|
|
1919
|
-
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(),
|
|
1920
1982
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1921
|
-
finish_reason:
|
|
1922
|
-
index:
|
|
1923
|
-
logprobs:
|
|
1924
|
-
tokens:
|
|
1925
|
-
token_logprobs:
|
|
1926
|
-
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()
|
|
1927
1989
|
}).nullable().optional()
|
|
1928
1990
|
})
|
|
1929
1991
|
),
|
|
1930
|
-
usage:
|
|
1931
|
-
prompt_tokens:
|
|
1932
|
-
prompt_tokens_details:
|
|
1933
|
-
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()
|
|
1934
1996
|
}).nullish(),
|
|
1935
|
-
completion_tokens:
|
|
1936
|
-
completion_tokens_details:
|
|
1937
|
-
reasoning_tokens:
|
|
1997
|
+
completion_tokens: import_v46.z.number(),
|
|
1998
|
+
completion_tokens_details: import_v46.z.object({
|
|
1999
|
+
reasoning_tokens: import_v46.z.number()
|
|
1938
2000
|
}).nullish(),
|
|
1939
|
-
total_tokens:
|
|
1940
|
-
cost:
|
|
2001
|
+
total_tokens: import_v46.z.number(),
|
|
2002
|
+
cost: import_v46.z.number().optional()
|
|
1941
2003
|
}).nullish()
|
|
1942
2004
|
}),
|
|
1943
2005
|
LLMGatewayErrorResponseSchema
|