@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/index.mjs
CHANGED
|
@@ -975,6 +975,15 @@ function getFileUrl({
|
|
|
975
975
|
}
|
|
976
976
|
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
977
977
|
}
|
|
978
|
+
function getMediaType(dataUrl, defaultMediaType) {
|
|
979
|
+
var _a15;
|
|
980
|
+
const match = dataUrl.match(/^data:([^;]+)/);
|
|
981
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
982
|
+
}
|
|
983
|
+
function getBase64FromDataUrl(dataUrl) {
|
|
984
|
+
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
985
|
+
return match ? match[1] : dataUrl;
|
|
986
|
+
}
|
|
978
987
|
|
|
979
988
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
980
989
|
function getCacheControl(providerMetadata) {
|
|
@@ -1187,101 +1196,119 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1187
1196
|
}
|
|
1188
1197
|
|
|
1189
1198
|
// src/chat/schemas.ts
|
|
1199
|
+
import { z as z6 } from "zod/v4";
|
|
1200
|
+
|
|
1201
|
+
// src/schemas/image.ts
|
|
1190
1202
|
import { z as z5 } from "zod/v4";
|
|
1191
|
-
var
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1203
|
+
var ImageResponseSchema = z5.object({
|
|
1204
|
+
type: z5.literal("image_url"),
|
|
1205
|
+
image_url: z5.object({
|
|
1206
|
+
url: z5.string()
|
|
1207
|
+
})
|
|
1208
|
+
});
|
|
1209
|
+
var ImageResponseWithUnknownSchema = z5.union([
|
|
1210
|
+
ImageResponseSchema,
|
|
1211
|
+
z5.unknown().transform(() => null)
|
|
1212
|
+
]);
|
|
1213
|
+
var ImageResponseArraySchema = z5.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
1214
|
+
|
|
1215
|
+
// src/chat/schemas.ts
|
|
1216
|
+
var LLMGatewayChatCompletionBaseResponseSchema = z6.object({
|
|
1217
|
+
id: z6.string().optional(),
|
|
1218
|
+
model: z6.string().optional(),
|
|
1219
|
+
usage: z6.object({
|
|
1220
|
+
prompt_tokens: z6.number(),
|
|
1221
|
+
prompt_tokens_details: z6.object({
|
|
1222
|
+
cached_tokens: z6.number()
|
|
1198
1223
|
}).nullish(),
|
|
1199
|
-
completion_tokens:
|
|
1200
|
-
completion_tokens_details:
|
|
1201
|
-
reasoning_tokens:
|
|
1224
|
+
completion_tokens: z6.number(),
|
|
1225
|
+
completion_tokens_details: z6.object({
|
|
1226
|
+
reasoning_tokens: z6.number()
|
|
1202
1227
|
}).nullish(),
|
|
1203
|
-
total_tokens:
|
|
1204
|
-
cost:
|
|
1205
|
-
cost_details:
|
|
1206
|
-
upstream_inference_cost:
|
|
1228
|
+
total_tokens: z6.number(),
|
|
1229
|
+
cost: z6.number().optional(),
|
|
1230
|
+
cost_details: z6.object({
|
|
1231
|
+
upstream_inference_cost: z6.number().nullish()
|
|
1207
1232
|
}).nullish()
|
|
1208
1233
|
}).nullish()
|
|
1209
1234
|
});
|
|
1210
1235
|
var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1211
|
-
choices:
|
|
1212
|
-
|
|
1213
|
-
message:
|
|
1214
|
-
role:
|
|
1215
|
-
content:
|
|
1216
|
-
reasoning:
|
|
1236
|
+
choices: z6.array(
|
|
1237
|
+
z6.object({
|
|
1238
|
+
message: z6.object({
|
|
1239
|
+
role: z6.literal("assistant"),
|
|
1240
|
+
content: z6.string().nullable().optional(),
|
|
1241
|
+
reasoning: z6.string().nullable().optional(),
|
|
1217
1242
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1243
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1244
|
+
tool_calls: z6.array(
|
|
1245
|
+
z6.object({
|
|
1246
|
+
id: z6.string().optional().nullable(),
|
|
1247
|
+
type: z6.literal("function"),
|
|
1248
|
+
function: z6.object({
|
|
1249
|
+
name: z6.string(),
|
|
1250
|
+
arguments: z6.string()
|
|
1225
1251
|
})
|
|
1226
1252
|
})
|
|
1227
1253
|
).optional()
|
|
1228
1254
|
}),
|
|
1229
|
-
index:
|
|
1230
|
-
logprobs:
|
|
1231
|
-
content:
|
|
1232
|
-
|
|
1233
|
-
token:
|
|
1234
|
-
logprob:
|
|
1235
|
-
top_logprobs:
|
|
1236
|
-
|
|
1237
|
-
token:
|
|
1238
|
-
logprob:
|
|
1255
|
+
index: z6.number().nullish(),
|
|
1256
|
+
logprobs: z6.object({
|
|
1257
|
+
content: z6.array(
|
|
1258
|
+
z6.object({
|
|
1259
|
+
token: z6.string(),
|
|
1260
|
+
logprob: z6.number(),
|
|
1261
|
+
top_logprobs: z6.array(
|
|
1262
|
+
z6.object({
|
|
1263
|
+
token: z6.string(),
|
|
1264
|
+
logprob: z6.number()
|
|
1239
1265
|
})
|
|
1240
1266
|
)
|
|
1241
1267
|
})
|
|
1242
1268
|
).nullable()
|
|
1243
1269
|
}).nullable().optional(),
|
|
1244
|
-
finish_reason:
|
|
1270
|
+
finish_reason: z6.string().optional().nullable()
|
|
1245
1271
|
})
|
|
1246
1272
|
)
|
|
1247
1273
|
});
|
|
1248
|
-
var LLMGatewayStreamChatCompletionChunkSchema =
|
|
1274
|
+
var LLMGatewayStreamChatCompletionChunkSchema = z6.union([
|
|
1249
1275
|
LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
1250
|
-
choices:
|
|
1251
|
-
|
|
1252
|
-
delta:
|
|
1253
|
-
role:
|
|
1254
|
-
content:
|
|
1255
|
-
reasoning:
|
|
1276
|
+
choices: z6.array(
|
|
1277
|
+
z6.object({
|
|
1278
|
+
delta: z6.object({
|
|
1279
|
+
role: z6.enum(["assistant"]).optional(),
|
|
1280
|
+
content: z6.string().nullish(),
|
|
1281
|
+
reasoning: z6.string().nullish().optional(),
|
|
1256
1282
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1283
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1284
|
+
tool_calls: z6.array(
|
|
1285
|
+
z6.object({
|
|
1286
|
+
index: z6.number().nullish(),
|
|
1287
|
+
id: z6.string().nullish(),
|
|
1288
|
+
type: z6.literal("function").optional(),
|
|
1289
|
+
function: z6.object({
|
|
1290
|
+
name: z6.string().nullish(),
|
|
1291
|
+
arguments: z6.string().nullish()
|
|
1265
1292
|
})
|
|
1266
1293
|
})
|
|
1267
1294
|
).nullish()
|
|
1268
1295
|
}).nullish(),
|
|
1269
|
-
logprobs:
|
|
1270
|
-
content:
|
|
1271
|
-
|
|
1272
|
-
token:
|
|
1273
|
-
logprob:
|
|
1274
|
-
top_logprobs:
|
|
1275
|
-
|
|
1276
|
-
token:
|
|
1277
|
-
logprob:
|
|
1296
|
+
logprobs: z6.object({
|
|
1297
|
+
content: z6.array(
|
|
1298
|
+
z6.object({
|
|
1299
|
+
token: z6.string(),
|
|
1300
|
+
logprob: z6.number(),
|
|
1301
|
+
top_logprobs: z6.array(
|
|
1302
|
+
z6.object({
|
|
1303
|
+
token: z6.string(),
|
|
1304
|
+
logprob: z6.number()
|
|
1278
1305
|
})
|
|
1279
1306
|
)
|
|
1280
1307
|
})
|
|
1281
1308
|
).nullable()
|
|
1282
1309
|
}).nullish(),
|
|
1283
|
-
finish_reason:
|
|
1284
|
-
index:
|
|
1310
|
+
finish_reason: z6.string().nullable().optional(),
|
|
1311
|
+
index: z6.number().nullish()
|
|
1285
1312
|
})
|
|
1286
1313
|
)
|
|
1287
1314
|
}),
|
|
@@ -1479,6 +1506,33 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1479
1506
|
});
|
|
1480
1507
|
}
|
|
1481
1508
|
}
|
|
1509
|
+
if (choice.message.images) {
|
|
1510
|
+
for (const image of choice.message.images) {
|
|
1511
|
+
content.push({
|
|
1512
|
+
type: "file",
|
|
1513
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1514
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (choice.message.annotations) {
|
|
1519
|
+
for (const annotation of choice.message.annotations) {
|
|
1520
|
+
if (annotation.type === "url_citation") {
|
|
1521
|
+
content.push({
|
|
1522
|
+
type: "source",
|
|
1523
|
+
sourceType: "url",
|
|
1524
|
+
id: annotation.url_citation.url,
|
|
1525
|
+
url: annotation.url_citation.url,
|
|
1526
|
+
title: annotation.url_citation.title,
|
|
1527
|
+
providerMetadata: {
|
|
1528
|
+
openrouter: {
|
|
1529
|
+
content: annotation.url_citation.content || ""
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1482
1536
|
return {
|
|
1483
1537
|
content,
|
|
1484
1538
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
@@ -1764,6 +1818,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1764
1818
|
}
|
|
1765
1819
|
}
|
|
1766
1820
|
}
|
|
1821
|
+
if (delta.images != null) {
|
|
1822
|
+
for (const image of delta.images) {
|
|
1823
|
+
controller.enqueue({
|
|
1824
|
+
type: "file",
|
|
1825
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
1826
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1767
1830
|
},
|
|
1768
1831
|
flush(controller) {
|
|
1769
1832
|
var _a16;
|
|
@@ -1917,36 +1980,36 @@ ${assistantMessage}
|
|
|
1917
1980
|
}
|
|
1918
1981
|
|
|
1919
1982
|
// src/completion/schemas.ts
|
|
1920
|
-
import { z as
|
|
1921
|
-
var LLMGatewayCompletionChunkSchema =
|
|
1922
|
-
|
|
1923
|
-
id:
|
|
1924
|
-
model:
|
|
1925
|
-
choices:
|
|
1926
|
-
|
|
1927
|
-
text:
|
|
1928
|
-
reasoning:
|
|
1983
|
+
import { z as z7 } from "zod/v4";
|
|
1984
|
+
var LLMGatewayCompletionChunkSchema = z7.union([
|
|
1985
|
+
z7.object({
|
|
1986
|
+
id: z7.string().optional(),
|
|
1987
|
+
model: z7.string().optional(),
|
|
1988
|
+
choices: z7.array(
|
|
1989
|
+
z7.object({
|
|
1990
|
+
text: z7.string(),
|
|
1991
|
+
reasoning: z7.string().nullish().optional(),
|
|
1929
1992
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1930
|
-
finish_reason:
|
|
1931
|
-
index:
|
|
1932
|
-
logprobs:
|
|
1933
|
-
tokens:
|
|
1934
|
-
token_logprobs:
|
|
1935
|
-
top_logprobs:
|
|
1993
|
+
finish_reason: z7.string().nullish(),
|
|
1994
|
+
index: z7.number().nullish(),
|
|
1995
|
+
logprobs: z7.object({
|
|
1996
|
+
tokens: z7.array(z7.string()),
|
|
1997
|
+
token_logprobs: z7.array(z7.number()),
|
|
1998
|
+
top_logprobs: z7.array(z7.record(z7.string(), z7.number())).nullable()
|
|
1936
1999
|
}).nullable().optional()
|
|
1937
2000
|
})
|
|
1938
2001
|
),
|
|
1939
|
-
usage:
|
|
1940
|
-
prompt_tokens:
|
|
1941
|
-
prompt_tokens_details:
|
|
1942
|
-
cached_tokens:
|
|
2002
|
+
usage: z7.object({
|
|
2003
|
+
prompt_tokens: z7.number(),
|
|
2004
|
+
prompt_tokens_details: z7.object({
|
|
2005
|
+
cached_tokens: z7.number()
|
|
1943
2006
|
}).nullish(),
|
|
1944
|
-
completion_tokens:
|
|
1945
|
-
completion_tokens_details:
|
|
1946
|
-
reasoning_tokens:
|
|
2007
|
+
completion_tokens: z7.number(),
|
|
2008
|
+
completion_tokens_details: z7.object({
|
|
2009
|
+
reasoning_tokens: z7.number()
|
|
1947
2010
|
}).nullish(),
|
|
1948
|
-
total_tokens:
|
|
1949
|
-
cost:
|
|
2011
|
+
total_tokens: z7.number(),
|
|
2012
|
+
cost: z7.number().optional()
|
|
1950
2013
|
}).nullish()
|
|
1951
2014
|
}),
|
|
1952
2015
|
LLMGatewayErrorResponseSchema
|