@shop-os/modelkit 0.2.0 → 0.2.3
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/CHANGELOG.md +40 -0
- package/dist/catalog.cjs +98 -93
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +25 -9
- package/dist/catalog.d.ts +25 -9
- package/dist/catalog.js +98 -93
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +256 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -9
- package/dist/index.d.ts +25 -9
- package/dist/index.js +255 -217
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -121,7 +121,13 @@ var GEMINI_RATIOS = [
|
|
|
121
121
|
"5:4",
|
|
122
122
|
"adaptive"
|
|
123
123
|
];
|
|
124
|
-
function geminiImage(id, label, aliases, sizes, display, exposure) {
|
|
124
|
+
function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
125
|
+
const constraints = {
|
|
126
|
+
aspectRatios: [...GEMINI_RATIOS],
|
|
127
|
+
sizes,
|
|
128
|
+
supports: ["safetySettings", "temperature"]
|
|
129
|
+
};
|
|
130
|
+
if (references !== void 0) constraints.references = references;
|
|
125
131
|
const model = {
|
|
126
132
|
id,
|
|
127
133
|
aliases,
|
|
@@ -131,11 +137,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure) {
|
|
|
131
137
|
providerModelId: id,
|
|
132
138
|
lifecycle: "active",
|
|
133
139
|
exposure,
|
|
134
|
-
constraints
|
|
135
|
-
aspectRatios: [...GEMINI_RATIOS],
|
|
136
|
-
sizes,
|
|
137
|
-
supports: ["safetySettings", "temperature"]
|
|
138
|
-
},
|
|
140
|
+
constraints,
|
|
139
141
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
140
142
|
usage: { ...IMAGE_USAGE, slug: "gemini" },
|
|
141
143
|
pricingKind: "image_size",
|
|
@@ -154,7 +156,8 @@ var IMAGE_MODELS = [
|
|
|
154
156
|
description: "Create stunning, production-quality visuals with exceptional realism, detail, and typography. Best for campaigns, e-commerce, product photography, and hero creatives.",
|
|
155
157
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
|
|
156
158
|
},
|
|
157
|
-
"catalog"
|
|
159
|
+
"catalog",
|
|
160
|
+
{ images: 14 }
|
|
158
161
|
),
|
|
159
162
|
geminiImage(
|
|
160
163
|
"gemini-3.1-flash-image-preview",
|
|
@@ -167,7 +170,8 @@ var IMAGE_MODELS = [
|
|
|
167
170
|
description: "Generate high-quality images at speed. Perfect for brainstorming, moodboards, concept testing, creative exploration, and large batch workflows.",
|
|
168
171
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
|
|
169
172
|
},
|
|
170
|
-
"catalog"
|
|
173
|
+
"catalog",
|
|
174
|
+
{ images: 14 }
|
|
171
175
|
),
|
|
172
176
|
geminiImage(
|
|
173
177
|
"gemini-3.1-flash-lite-image",
|
|
@@ -179,14 +183,15 @@ var IMAGE_MODELS = [
|
|
|
179
183
|
description: "The fastest and most affordable image model. Ideal for rapid drafts, bulk exploration, and iterative concept testing at 1K resolution.",
|
|
180
184
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
|
|
181
185
|
},
|
|
182
|
-
"catalog"
|
|
186
|
+
"catalog",
|
|
187
|
+
{ images: 14 }
|
|
183
188
|
),
|
|
184
189
|
// trigger-workflows validates 1K only; pricing seeds 2K/4K rows so allow all three.
|
|
185
190
|
geminiImage(
|
|
186
191
|
"gemini-2.5-flash-image",
|
|
187
192
|
"Gemini 2.5 Flash Image",
|
|
188
193
|
[],
|
|
189
|
-
["1K"
|
|
194
|
+
["1K"],
|
|
190
195
|
{
|
|
191
196
|
provider: "google",
|
|
192
197
|
description: "Nano Banana (legacy Gemini 2.5 Flash Image) native image generation and editing model for high-volume, low-latency creative workflows."
|
|
@@ -217,7 +222,7 @@ var IMAGE_MODELS = [
|
|
|
217
222
|
sizes: ["1K", "2K", "4K"],
|
|
218
223
|
qualityOptions: ["auto", "low", "medium", "high"],
|
|
219
224
|
references: { images: 16 },
|
|
220
|
-
supports: ["quality", "count"]
|
|
225
|
+
supports: ["quality", "count", "outputFormat"]
|
|
221
226
|
},
|
|
222
227
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
223
228
|
usage: { ...IMAGE_USAGE, slug: "gpt" },
|
|
@@ -237,7 +242,7 @@ var IMAGE_MODELS = [
|
|
|
237
242
|
adapter: "openai-image",
|
|
238
243
|
providerModelId: "gpt-image-2.5-sunburst",
|
|
239
244
|
lifecycle: "active",
|
|
240
|
-
exposure: "
|
|
245
|
+
exposure: "catalog",
|
|
241
246
|
constraints: {
|
|
242
247
|
exactSizes: {
|
|
243
248
|
"1:1": "1024x1024",
|
|
@@ -250,15 +255,16 @@ var IMAGE_MODELS = [
|
|
|
250
255
|
},
|
|
251
256
|
aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
|
|
252
257
|
sizes: ["1K", "2K", "4K"],
|
|
253
|
-
qualityOptions: ["auto", "low", "medium", "high"],
|
|
258
|
+
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
254
259
|
references: { images: 16 },
|
|
255
|
-
supports: ["quality", "count"]
|
|
260
|
+
supports: ["quality", "count", "outputFormat"]
|
|
256
261
|
},
|
|
257
262
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
258
263
|
usage: { ...IMAGE_USAGE },
|
|
259
264
|
pricingKind: "image_size",
|
|
260
265
|
display: {
|
|
261
266
|
provider: "openai",
|
|
267
|
+
sortOrder: 20,
|
|
262
268
|
description: "OpenAI's most capable GPT Image 2.5 tier, built for editing precision; takes text and image input and outputs images in low, medium, high, xhigh, or max quality."
|
|
263
269
|
}
|
|
264
270
|
},
|
|
@@ -271,7 +277,7 @@ var IMAGE_MODELS = [
|
|
|
271
277
|
adapter: "openai-image",
|
|
272
278
|
providerModelId: "gpt-image-2.5-flare",
|
|
273
279
|
lifecycle: "active",
|
|
274
|
-
exposure: "
|
|
280
|
+
exposure: "catalog",
|
|
275
281
|
constraints: {
|
|
276
282
|
exactSizes: {
|
|
277
283
|
"1:1": "1024x1024",
|
|
@@ -284,15 +290,16 @@ var IMAGE_MODELS = [
|
|
|
284
290
|
},
|
|
285
291
|
aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
|
|
286
292
|
sizes: ["1K", "2K", "4K"],
|
|
287
|
-
qualityOptions: ["auto", "low", "medium", "high"],
|
|
293
|
+
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
288
294
|
references: { images: 16 },
|
|
289
|
-
supports: ["quality", "count"]
|
|
295
|
+
supports: ["quality", "count", "outputFormat"]
|
|
290
296
|
},
|
|
291
297
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
292
298
|
usage: { ...IMAGE_USAGE },
|
|
293
299
|
pricingKind: "image_size",
|
|
294
300
|
display: {
|
|
295
301
|
provider: "openai",
|
|
302
|
+
sortOrder: 10,
|
|
296
303
|
description: "OpenAI's fastest GPT Image 2.5 tier for high-quality everyday image generation and editing; takes text and image input and outputs images."
|
|
297
304
|
}
|
|
298
305
|
},
|
|
@@ -316,8 +323,6 @@ var IMAGE_MODELS = [
|
|
|
316
323
|
"2:3",
|
|
317
324
|
"3:4",
|
|
318
325
|
"9:16",
|
|
319
|
-
"4:5",
|
|
320
|
-
"5:4",
|
|
321
326
|
"9:21",
|
|
322
327
|
"adaptive"
|
|
323
328
|
],
|
|
@@ -349,7 +354,7 @@ var IMAGE_MODELS = [
|
|
|
349
354
|
references: { images: 10 },
|
|
350
355
|
// Ark's Images API has no output-format, quality or count field; only
|
|
351
356
|
// the seed is forwarded, so anything else must warn, not vanish.
|
|
352
|
-
supports: ["seed"]
|
|
357
|
+
supports: ["seed", "outputFormat"]
|
|
353
358
|
},
|
|
354
359
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
355
360
|
usage: { ...IMAGE_USAGE },
|
|
@@ -385,7 +390,7 @@ var IMAGE_MODELS = [
|
|
|
385
390
|
"21:9",
|
|
386
391
|
"9:21"
|
|
387
392
|
],
|
|
388
|
-
sizes: ["
|
|
393
|
+
sizes: ["2K", "4K"],
|
|
389
394
|
references: { images: 10 },
|
|
390
395
|
supports: ["seed"]
|
|
391
396
|
},
|
|
@@ -437,7 +442,7 @@ var IMAGE_MODELS = [
|
|
|
437
442
|
aspectRatios: ["1:1", "2:3", "3:2", "4:3", "3:4", "4:5", "5:4", "9:16", "16:9", "21:9"],
|
|
438
443
|
sizes: ["1K", "2K", "4K"],
|
|
439
444
|
requires: ["references"],
|
|
440
|
-
supports: [
|
|
445
|
+
supports: []
|
|
441
446
|
},
|
|
442
447
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
443
448
|
usage: { ...IMAGE_USAGE },
|
|
@@ -462,7 +467,7 @@ var IMAGE_MODELS = [
|
|
|
462
467
|
aspectRatios: ["1:1", "2:3", "3:4", "4:3", "9:16", "16:9", "21:9"],
|
|
463
468
|
sizes: ["1K"],
|
|
464
469
|
requires: ["references"],
|
|
465
|
-
supports: [
|
|
470
|
+
supports: []
|
|
466
471
|
},
|
|
467
472
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
468
473
|
usage: { ...IMAGE_USAGE },
|
|
@@ -514,7 +519,6 @@ var IMAGE_MODELS = [
|
|
|
514
519
|
aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
|
|
515
520
|
sizes: [],
|
|
516
521
|
references: { images: 1 },
|
|
517
|
-
requires: ["references"],
|
|
518
522
|
supports: []
|
|
519
523
|
},
|
|
520
524
|
defaults: { aspectRatio: "1:1" },
|
|
@@ -1233,7 +1237,7 @@ var VIDEO_MODELS = [
|
|
|
1233
1237
|
resolutions: ["720p", "1080p", "4k"],
|
|
1234
1238
|
durations: [8],
|
|
1235
1239
|
references: { images: 3 },
|
|
1236
|
-
supports: ["lastFrame"]
|
|
1240
|
+
supports: ["lastFrame", "seed"]
|
|
1237
1241
|
},
|
|
1238
1242
|
defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
|
|
1239
1243
|
usage: { ...VIDEO_USAGE, slug: "veo" },
|
|
@@ -1261,9 +1265,9 @@ var VIDEO_MODELS = [
|
|
|
1261
1265
|
constraints: {
|
|
1262
1266
|
aspectRatios: [...OMNI_RATIOS],
|
|
1263
1267
|
resolutions: ["720p", "1080p", "4k"],
|
|
1264
|
-
durations: [4, 8],
|
|
1268
|
+
durations: [4, 6, 8],
|
|
1265
1269
|
references: { images: 3 },
|
|
1266
|
-
supports: ["lastFrame"]
|
|
1270
|
+
supports: ["lastFrame", "seed"]
|
|
1267
1271
|
},
|
|
1268
1272
|
defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
|
|
1269
1273
|
usage: { ...VIDEO_USAGE },
|
|
@@ -1290,9 +1294,8 @@ var VIDEO_MODELS = [
|
|
|
1290
1294
|
constraints: {
|
|
1291
1295
|
aspectRatios: [...OMNI_RATIOS],
|
|
1292
1296
|
resolutions: ["720p", "1080p"],
|
|
1293
|
-
durations: [4, 8],
|
|
1294
|
-
|
|
1295
|
-
supports: ["lastFrame"]
|
|
1297
|
+
durations: [4, 6, 8],
|
|
1298
|
+
supports: ["lastFrame", "seed"]
|
|
1296
1299
|
},
|
|
1297
1300
|
defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
|
|
1298
1301
|
usage: { ...VIDEO_USAGE },
|
|
@@ -1324,7 +1327,7 @@ var VIDEO_MODELS = [
|
|
|
1324
1327
|
// reference clip keeps its own framing.
|
|
1325
1328
|
aspectRatios: [...OMNI_RATIOS],
|
|
1326
1329
|
durations: [3, 4, 5, 6, 7, 8, 9, 10],
|
|
1327
|
-
references: { images: 6, videos:
|
|
1330
|
+
references: { images: 6, videos: 3 },
|
|
1328
1331
|
supports: []
|
|
1329
1332
|
},
|
|
1330
1333
|
defaults: {},
|
|
@@ -1350,7 +1353,7 @@ var VIDEO_MODELS = [
|
|
|
1350
1353
|
aspectRatios: [...OMNI_RATIOS],
|
|
1351
1354
|
resolutions: ["360p", "720p", "1080p", "4k"],
|
|
1352
1355
|
durations: [3, 4, 5, 6, 7, 8, 9, 10],
|
|
1353
|
-
references: { images: 6, videos:
|
|
1356
|
+
references: { images: 6, videos: 3 },
|
|
1354
1357
|
supports: []
|
|
1355
1358
|
},
|
|
1356
1359
|
defaults: {},
|
|
@@ -1379,7 +1382,7 @@ var VIDEO_MODELS = [
|
|
|
1379
1382
|
durations: { min: 4, max: 15 },
|
|
1380
1383
|
durationPresets: [4, 6, 8, 10, 12, 15],
|
|
1381
1384
|
references: { images: 9, videos: 3, audios: 3, audioOnly: false },
|
|
1382
|
-
ratioIgnoredWith: ["firstFrame"],
|
|
1385
|
+
ratioIgnoredWith: ["firstFrame", "sourceVideo"],
|
|
1383
1386
|
supports: ["generateAudio", "seed", "lastFrame", "watermark"]
|
|
1384
1387
|
},
|
|
1385
1388
|
defaults: {
|
|
@@ -1411,7 +1414,7 @@ var VIDEO_MODELS = [
|
|
|
1411
1414
|
resolutions: ["480p", "720p"],
|
|
1412
1415
|
durations: { min: 4, max: 15 },
|
|
1413
1416
|
references: { images: 9, videos: 3, audios: 3, audioOnly: false },
|
|
1414
|
-
ratioIgnoredWith: ["firstFrame"],
|
|
1417
|
+
ratioIgnoredWith: ["firstFrame", "sourceVideo"],
|
|
1415
1418
|
supports: ["generateAudio", "seed", "lastFrame", "watermark"]
|
|
1416
1419
|
},
|
|
1417
1420
|
defaults: {
|
|
@@ -1444,7 +1447,7 @@ var VIDEO_MODELS = [
|
|
|
1444
1447
|
resolutions: ["480p", "720p", "1080p"],
|
|
1445
1448
|
durations: { min: 4, max: 30 },
|
|
1446
1449
|
references: { images: 30, videos: 10, audios: 10 },
|
|
1447
|
-
ratioIgnoredWith: ["firstFrame"],
|
|
1450
|
+
ratioIgnoredWith: ["firstFrame", "sourceVideo"],
|
|
1448
1451
|
supports: ["generateAudio", "seed", "lastFrame", "watermark"]
|
|
1449
1452
|
},
|
|
1450
1453
|
defaults: {
|
|
@@ -1563,18 +1566,7 @@ var VIDEO_MODELS = [
|
|
|
1563
1566
|
lifecycle: "active",
|
|
1564
1567
|
exposure: "catalog",
|
|
1565
1568
|
constraints: {
|
|
1566
|
-
aspectRatios: [
|
|
1567
|
-
"1:1",
|
|
1568
|
-
"16:9",
|
|
1569
|
-
"9:16",
|
|
1570
|
-
"4:3",
|
|
1571
|
-
"3:4",
|
|
1572
|
-
"3:2",
|
|
1573
|
-
"2:3",
|
|
1574
|
-
"21:9",
|
|
1575
|
-
"4:5",
|
|
1576
|
-
"adaptive"
|
|
1577
|
-
],
|
|
1569
|
+
aspectRatios: [...KLING_RATIOS],
|
|
1578
1570
|
resolutions: ["720p", "1080p"],
|
|
1579
1571
|
durations: { min: 3, max: 15 },
|
|
1580
1572
|
references: { images: 7 },
|
|
@@ -2036,30 +2028,34 @@ var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
|
|
|
2036
2028
|
});
|
|
2037
2029
|
|
|
2038
2030
|
// src/catalog/live.ts
|
|
2039
|
-
var
|
|
2031
|
+
var KEY = /* @__PURE__ */ Symbol.for("@shop-os/modelkit/live-catalog");
|
|
2032
|
+
var store = globalThis;
|
|
2033
|
+
var liveState = store[KEY] ??= {
|
|
2034
|
+
catalog: new Catalog(MODELS),
|
|
2035
|
+
memo: void 0,
|
|
2036
|
+
timer: void 0,
|
|
2037
|
+
revision: void 0,
|
|
2038
|
+
origin: "snapshot"
|
|
2039
|
+
};
|
|
2040
|
+
var liveCatalog = liveState.catalog;
|
|
2040
2041
|
|
|
2041
2042
|
// src/catalog/load.ts
|
|
2042
|
-
|
|
2043
|
-
var timer;
|
|
2044
|
-
var revision;
|
|
2045
|
-
var origin = "snapshot";
|
|
2043
|
+
import { z as z2 } from "zod";
|
|
2046
2044
|
function rowCount() {
|
|
2047
2045
|
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2048
2046
|
}
|
|
2049
2047
|
function authHeaders(auth) {
|
|
2050
2048
|
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2051
2049
|
}
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
if (typeof rev === "string") return { rows, revision: rev };
|
|
2062
|
-
return { rows };
|
|
2050
|
+
var EnvelopeSchema = z2.object({
|
|
2051
|
+
rows: CatalogSchema,
|
|
2052
|
+
revision: z2.string().optional()
|
|
2053
|
+
});
|
|
2054
|
+
function toEnvelope(data) {
|
|
2055
|
+
if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
|
|
2056
|
+
const envelope = { rows: data.rows };
|
|
2057
|
+
if (data.revision !== void 0) envelope.revision = data.revision;
|
|
2058
|
+
return envelope;
|
|
2063
2059
|
}
|
|
2064
2060
|
function logPrimed(logger, result) {
|
|
2065
2061
|
const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
|
|
@@ -2072,7 +2068,7 @@ function logPrimed(logger, result) {
|
|
|
2072
2068
|
async function fetchRemote(source, logger) {
|
|
2073
2069
|
const fetchImpl = source.fetch ?? globalThis.fetch;
|
|
2074
2070
|
const headers2 = authHeaders(source.auth);
|
|
2075
|
-
if (revision !== void 0) headers2["If-None-Match"] = `"${revision}"`;
|
|
2071
|
+
if (liveState.revision !== void 0) headers2["If-None-Match"] = `"${liveState.revision}"`;
|
|
2076
2072
|
const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
|
|
2077
2073
|
headers: headers2,
|
|
2078
2074
|
signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
|
|
@@ -2080,7 +2076,9 @@ async function fetchRemote(source, logger) {
|
|
|
2080
2076
|
if (res.status === 304) return { kept: true };
|
|
2081
2077
|
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2082
2078
|
const json = await res.json();
|
|
2083
|
-
const
|
|
2079
|
+
const parsed = EnvelopeSchema.safeParse(json);
|
|
2080
|
+
if (!parsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2081
|
+
const { rows, revision: rev } = toEnvelope(parsed.data);
|
|
2084
2082
|
if (rev === void 0) return { rows, fromCache: false };
|
|
2085
2083
|
return { rows, revision: rev, fromCache: false };
|
|
2086
2084
|
}
|
|
@@ -2096,40 +2094,46 @@ async function prime(source, logger) {
|
|
|
2096
2094
|
try {
|
|
2097
2095
|
const fetched = await fetchRemote(source, logger);
|
|
2098
2096
|
if ("kept" in fetched) {
|
|
2099
|
-
const result2 = { origin, rowCount: rowCount() };
|
|
2100
|
-
if (revision !== void 0) result2.revision = revision;
|
|
2097
|
+
const result2 = { origin: liveState.origin, rowCount: rowCount() };
|
|
2098
|
+
if (liveState.revision !== void 0) result2.revision = liveState.revision;
|
|
2101
2099
|
logPrimed(logger, result2);
|
|
2102
2100
|
return result2;
|
|
2103
2101
|
}
|
|
2104
2102
|
liveCatalog.replace(fetched.rows);
|
|
2105
|
-
origin = "remote";
|
|
2106
|
-
revision = fetched.revision;
|
|
2103
|
+
liveState.origin = "remote";
|
|
2104
|
+
liveState.revision = fetched.revision;
|
|
2107
2105
|
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2108
|
-
const result = { origin, rowCount: rowCount() };
|
|
2106
|
+
const result = { origin: liveState.origin, rowCount: rowCount() };
|
|
2109
2107
|
if (fetched.revision !== void 0) result.revision = fetched.revision;
|
|
2110
2108
|
logPrimed(logger, result);
|
|
2111
2109
|
return result;
|
|
2112
2110
|
} catch (err) {
|
|
2113
2111
|
logger.warn("[modelkit] catalog remote failed, trying cache", err);
|
|
2114
|
-
const error =
|
|
2112
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
2115
2113
|
try {
|
|
2116
2114
|
const cached = await source.cache?.get();
|
|
2117
2115
|
if (!cached) throw new Error("no cached catalog");
|
|
2118
|
-
const
|
|
2116
|
+
const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
|
|
2117
|
+
if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2118
|
+
const { rows, revision: rev } = toEnvelope(cachedParsed.data);
|
|
2119
2119
|
liveCatalog.replace(rows);
|
|
2120
|
-
origin = "last-good";
|
|
2121
|
-
revision = rev;
|
|
2122
|
-
const result = {
|
|
2120
|
+
liveState.origin = "last-good";
|
|
2121
|
+
liveState.revision = rev;
|
|
2122
|
+
const result = {
|
|
2123
|
+
origin: liveState.origin,
|
|
2124
|
+
rowCount: rowCount(),
|
|
2125
|
+
error
|
|
2126
|
+
};
|
|
2123
2127
|
if (rev !== void 0) result.revision = rev;
|
|
2124
2128
|
logPrimed(logger, result);
|
|
2125
2129
|
return result;
|
|
2126
2130
|
} catch (cacheErr) {
|
|
2127
2131
|
logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
|
|
2128
2132
|
liveCatalog.replace([...MODELS]);
|
|
2129
|
-
origin = "snapshot";
|
|
2130
|
-
revision = void 0;
|
|
2133
|
+
liveState.origin = "snapshot";
|
|
2134
|
+
liveState.revision = void 0;
|
|
2131
2135
|
const result = {
|
|
2132
|
-
origin,
|
|
2136
|
+
origin: liveState.origin,
|
|
2133
2137
|
rowCount: rowCount(),
|
|
2134
2138
|
error
|
|
2135
2139
|
};
|
|
@@ -2143,47 +2147,50 @@ async function refresh(source, logger) {
|
|
|
2143
2147
|
const fetched = await fetchRemote(source, logger);
|
|
2144
2148
|
if ("kept" in fetched) return;
|
|
2145
2149
|
liveCatalog.replace(fetched.rows);
|
|
2146
|
-
origin = "remote";
|
|
2147
|
-
revision = fetched.revision;
|
|
2150
|
+
liveState.origin = "remote";
|
|
2151
|
+
liveState.revision = fetched.revision;
|
|
2148
2152
|
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2149
2153
|
} catch (err) {
|
|
2150
2154
|
logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
|
|
2151
2155
|
}
|
|
2152
2156
|
}
|
|
2153
2157
|
function primeCatalog(source) {
|
|
2154
|
-
if (memo) return memo;
|
|
2158
|
+
if (liveState.memo) return liveState.memo;
|
|
2155
2159
|
const logger = source.logger ?? console;
|
|
2156
|
-
|
|
2160
|
+
const pending = prime(source, logger).then((result) => {
|
|
2157
2161
|
const ttlMs = source.ttlMs ?? 3e5;
|
|
2158
|
-
if (ttlMs > 0 && timer === void 0) {
|
|
2159
|
-
timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2160
|
-
|
|
2161
|
-
maybeUnref.unref?.();
|
|
2162
|
+
if (ttlMs > 0 && liveState.timer === void 0) {
|
|
2163
|
+
liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2164
|
+
liveState.timer.unref?.();
|
|
2162
2165
|
}
|
|
2163
2166
|
return result;
|
|
2164
2167
|
});
|
|
2165
|
-
|
|
2168
|
+
liveState.memo = pending;
|
|
2169
|
+
return pending;
|
|
2166
2170
|
}
|
|
2167
2171
|
function resetLiveCatalog() {
|
|
2168
|
-
if (timer !== void 0) {
|
|
2169
|
-
clearInterval(timer);
|
|
2170
|
-
timer = void 0;
|
|
2172
|
+
if (liveState.timer !== void 0) {
|
|
2173
|
+
clearInterval(liveState.timer);
|
|
2174
|
+
liveState.timer = void 0;
|
|
2171
2175
|
}
|
|
2172
|
-
memo = void 0;
|
|
2173
|
-
revision = void 0;
|
|
2174
|
-
origin = "snapshot";
|
|
2176
|
+
liveState.memo = void 0;
|
|
2177
|
+
liveState.revision = void 0;
|
|
2178
|
+
liveState.origin = "snapshot";
|
|
2175
2179
|
liveCatalog.replace([...MODELS]);
|
|
2176
2180
|
}
|
|
2177
2181
|
|
|
2178
2182
|
// src/catalog/file-cache.ts
|
|
2179
2183
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
2184
|
+
function isErrnoException(err) {
|
|
2185
|
+
return err instanceof Error && "code" in err;
|
|
2186
|
+
}
|
|
2180
2187
|
function fileCatalogCache(path) {
|
|
2181
2188
|
return {
|
|
2182
2189
|
async get() {
|
|
2183
2190
|
try {
|
|
2184
2191
|
return await readFile(path, "utf8");
|
|
2185
2192
|
} catch (err) {
|
|
2186
|
-
if (err
|
|
2193
|
+
if (isErrnoException(err) && err.code === "ENOENT") return null;
|
|
2187
2194
|
throw err;
|
|
2188
2195
|
}
|
|
2189
2196
|
},
|
|
@@ -2620,21 +2627,21 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2620
2627
|
}
|
|
2621
2628
|
|
|
2622
2629
|
// src/retry.ts
|
|
2623
|
-
import { z as
|
|
2630
|
+
import { z as z4 } from "zod";
|
|
2624
2631
|
|
|
2625
2632
|
// src/json.ts
|
|
2626
|
-
import { z as
|
|
2627
|
-
var JsonValueSchema =
|
|
2628
|
-
() =>
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2633
|
+
import { z as z3 } from "zod";
|
|
2634
|
+
var JsonValueSchema = z3.lazy(
|
|
2635
|
+
() => z3.union([
|
|
2636
|
+
z3.string(),
|
|
2637
|
+
z3.number(),
|
|
2638
|
+
z3.boolean(),
|
|
2639
|
+
z3.null(),
|
|
2640
|
+
z3.array(JsonValueSchema),
|
|
2641
|
+
z3.record(z3.string(), JsonValueSchema)
|
|
2635
2642
|
])
|
|
2636
2643
|
);
|
|
2637
|
-
var JsonObjectSchema =
|
|
2644
|
+
var JsonObjectSchema = z3.record(z3.string(), JsonValueSchema);
|
|
2638
2645
|
async function readErrorBody(res) {
|
|
2639
2646
|
const text2 = await res.text().catch(() => "");
|
|
2640
2647
|
try {
|
|
@@ -2643,11 +2650,11 @@ async function readErrorBody(res) {
|
|
|
2643
2650
|
return text2;
|
|
2644
2651
|
}
|
|
2645
2652
|
}
|
|
2646
|
-
var thrownErrorSchema =
|
|
2647
|
-
message:
|
|
2648
|
-
status:
|
|
2649
|
-
statusCode:
|
|
2650
|
-
responseBody:
|
|
2653
|
+
var thrownErrorSchema = z3.object({
|
|
2654
|
+
message: z3.string().optional(),
|
|
2655
|
+
status: z3.number().optional(),
|
|
2656
|
+
statusCode: z3.number().optional(),
|
|
2657
|
+
responseBody: z3.string().optional()
|
|
2651
2658
|
});
|
|
2652
2659
|
function describeThrown(cause) {
|
|
2653
2660
|
const parsed = thrownErrorSchema.safeParse(cause);
|
|
@@ -2658,7 +2665,7 @@ function describeThrown(cause) {
|
|
|
2658
2665
|
}
|
|
2659
2666
|
|
|
2660
2667
|
// src/retry.ts
|
|
2661
|
-
var textBody =
|
|
2668
|
+
var textBody = z4.string();
|
|
2662
2669
|
function classifyHttpError(status, body, provider, model) {
|
|
2663
2670
|
const asText = textBody.safeParse(body);
|
|
2664
2671
|
const text2 = asText.success ? asText.data : JSON.stringify(body);
|
|
@@ -2715,12 +2722,12 @@ function sleep(ms, signal) {
|
|
|
2715
2722
|
rejectAborted();
|
|
2716
2723
|
return;
|
|
2717
2724
|
}
|
|
2718
|
-
let
|
|
2725
|
+
let timer;
|
|
2719
2726
|
const onAbort = () => {
|
|
2720
|
-
if (
|
|
2727
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
2721
2728
|
rejectAborted();
|
|
2722
2729
|
};
|
|
2723
|
-
|
|
2730
|
+
timer = setTimeout(() => {
|
|
2724
2731
|
signal?.removeEventListener("abort", onAbort);
|
|
2725
2732
|
resolve();
|
|
2726
2733
|
}, ms);
|
|
@@ -2873,7 +2880,7 @@ import {
|
|
|
2873
2880
|
streamObject as aiStreamObject2,
|
|
2874
2881
|
streamText as aiStreamText2
|
|
2875
2882
|
} from "ai";
|
|
2876
|
-
import { z as
|
|
2883
|
+
import { z as z6 } from "zod";
|
|
2877
2884
|
|
|
2878
2885
|
// src/adapters/media-ref.ts
|
|
2879
2886
|
function isUrlRef(ref) {
|
|
@@ -2958,7 +2965,7 @@ import { createPerplexity } from "@ai-sdk/perplexity";
|
|
|
2958
2965
|
import { createXai } from "@ai-sdk/xai";
|
|
2959
2966
|
import { createDeepSeek } from "@ai-sdk/deepseek";
|
|
2960
2967
|
import { createMoonshotAI } from "@ai-sdk/moonshotai";
|
|
2961
|
-
import { z as
|
|
2968
|
+
import { z as z5 } from "zod";
|
|
2962
2969
|
var TEXT_PROVIDERS = [
|
|
2963
2970
|
"openai",
|
|
2964
2971
|
"anthropic",
|
|
@@ -2969,7 +2976,7 @@ var TEXT_PROVIDERS = [
|
|
|
2969
2976
|
"moonshot",
|
|
2970
2977
|
"minimax"
|
|
2971
2978
|
];
|
|
2972
|
-
var textProviderSchema =
|
|
2979
|
+
var textProviderSchema = z5.enum(TEXT_PROVIDERS);
|
|
2973
2980
|
function isTextProvider(value) {
|
|
2974
2981
|
return textProviderSchema.safeParse(value).success;
|
|
2975
2982
|
}
|
|
@@ -3139,10 +3146,10 @@ function textAbortOptions(sdk, context) {
|
|
|
3139
3146
|
if (abortSignal) return { abortSignal };
|
|
3140
3147
|
return {};
|
|
3141
3148
|
}
|
|
3142
|
-
var catalogId =
|
|
3143
|
-
var exactSize =
|
|
3144
|
-
var sdkRatio =
|
|
3145
|
-
var sizeTier =
|
|
3149
|
+
var catalogId = z6.string();
|
|
3150
|
+
var exactSize = z6.templateLiteral([z6.number(), "x", z6.number()]);
|
|
3151
|
+
var sdkRatio = z6.templateLiteral([z6.number(), ":", z6.number()]);
|
|
3152
|
+
var sizeTier = z6.enum(["512", "1K", "2K", "4K"]);
|
|
3146
3153
|
function isCatalogId(model) {
|
|
3147
3154
|
return catalogId.safeParse(model).success;
|
|
3148
3155
|
}
|
|
@@ -3663,7 +3670,7 @@ function createModelKit(config, adapters) {
|
|
|
3663
3670
|
}
|
|
3664
3671
|
|
|
3665
3672
|
// src/adapters/ark.ts
|
|
3666
|
-
import { z as
|
|
3673
|
+
import { z as z7 } from "zod";
|
|
3667
3674
|
var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
3668
3675
|
var SUBMIT_PATH = "/contents/generations/tasks";
|
|
3669
3676
|
var SEEDANCE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -3740,7 +3747,7 @@ function arkKey(ctx) {
|
|
|
3740
3747
|
return key;
|
|
3741
3748
|
}
|
|
3742
3749
|
function throwArkError(status, body, model) {
|
|
3743
|
-
const parsed =
|
|
3750
|
+
const parsed = z7.string().safeParse(body);
|
|
3744
3751
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
3745
3752
|
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
3746
3753
|
const init = {
|
|
@@ -3778,13 +3785,13 @@ function sniffedImageMime(bytes) {
|
|
|
3778
3785
|
return "image/webp";
|
|
3779
3786
|
return "image/jpeg";
|
|
3780
3787
|
}
|
|
3781
|
-
var SeedreamImageSchema =
|
|
3782
|
-
url:
|
|
3783
|
-
b64_json:
|
|
3788
|
+
var SeedreamImageSchema = z7.object({
|
|
3789
|
+
url: z7.string().optional(),
|
|
3790
|
+
b64_json: z7.string().optional()
|
|
3784
3791
|
});
|
|
3785
|
-
var SeedreamResponseSchema =
|
|
3786
|
-
data:
|
|
3787
|
-
error:
|
|
3792
|
+
var SeedreamResponseSchema = z7.object({
|
|
3793
|
+
data: z7.array(SeedreamImageSchema).optional(),
|
|
3794
|
+
error: z7.object({ message: z7.string().optional(), code: z7.string().optional() }).optional()
|
|
3788
3795
|
});
|
|
3789
3796
|
function retryOptsFor(ctx, attempts = 3) {
|
|
3790
3797
|
const opts = { attempts };
|
|
@@ -3813,6 +3820,18 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3813
3820
|
watermark: false
|
|
3814
3821
|
};
|
|
3815
3822
|
if (req.seed !== void 0) body.seed = req.seed;
|
|
3823
|
+
if (req.outputFormat !== void 0) {
|
|
3824
|
+
if (req.outputFormat === "webp") {
|
|
3825
|
+
ctx.warnings.push({
|
|
3826
|
+
code: "option_ignored",
|
|
3827
|
+
field: "outputFormat",
|
|
3828
|
+
from: "webp",
|
|
3829
|
+
to: "png",
|
|
3830
|
+
message: `${modelId} accepts png or jpeg output; using png`
|
|
3831
|
+
});
|
|
3832
|
+
}
|
|
3833
|
+
body.output_format = req.outputFormat === "jpeg" ? "jpeg" : "png";
|
|
3834
|
+
}
|
|
3816
3835
|
const firstRef = refs[0];
|
|
3817
3836
|
if (refs.length === 1 && firstRef !== void 0) body.image = firstRef;
|
|
3818
3837
|
else if (refs.length > 1) body.image = refs;
|
|
@@ -3856,21 +3875,21 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3856
3875
|
if (req.quality !== void 0) usage2.imageQuality = req.quality;
|
|
3857
3876
|
return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
|
|
3858
3877
|
}
|
|
3859
|
-
var SeedanceUsageSchema =
|
|
3860
|
-
total_tokens:
|
|
3861
|
-
completion_tokens:
|
|
3878
|
+
var SeedanceUsageSchema = z7.object({
|
|
3879
|
+
total_tokens: z7.number().optional(),
|
|
3880
|
+
completion_tokens: z7.number().optional()
|
|
3862
3881
|
});
|
|
3863
|
-
var SeedanceResponseSchema =
|
|
3864
|
-
id:
|
|
3865
|
-
status:
|
|
3866
|
-
content:
|
|
3882
|
+
var SeedanceResponseSchema = z7.object({
|
|
3883
|
+
id: z7.string().optional(),
|
|
3884
|
+
status: z7.string().optional(),
|
|
3885
|
+
content: z7.object({ video_url: z7.string().optional() }).optional(),
|
|
3867
3886
|
usage: SeedanceUsageSchema.optional(),
|
|
3868
|
-
duration:
|
|
3869
|
-
framespersecond:
|
|
3870
|
-
resolution:
|
|
3871
|
-
error:
|
|
3887
|
+
duration: z7.number().optional(),
|
|
3888
|
+
framespersecond: z7.number().optional(),
|
|
3889
|
+
resolution: z7.string().optional(),
|
|
3890
|
+
error: z7.union([z7.string(), z7.object({ message: z7.string().optional() })]).optional()
|
|
3872
3891
|
});
|
|
3873
|
-
var SeedanceErrorMessageSchema =
|
|
3892
|
+
var SeedanceErrorMessageSchema = z7.object({ message: z7.string().optional() });
|
|
3874
3893
|
function seedanceUsage(ctx, req, duration) {
|
|
3875
3894
|
const usage2 = {
|
|
3876
3895
|
model: ctx.model.id,
|
|
@@ -3884,7 +3903,7 @@ function seedanceUsage(ctx, req, duration) {
|
|
|
3884
3903
|
return usage2;
|
|
3885
3904
|
}
|
|
3886
3905
|
function seedanceErrorMessage(error, status) {
|
|
3887
|
-
const asString =
|
|
3906
|
+
const asString = z7.string().safeParse(error);
|
|
3888
3907
|
if (asString.success) return asString.data;
|
|
3889
3908
|
const asObject = SeedanceErrorMessageSchema.safeParse(error);
|
|
3890
3909
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
@@ -4033,7 +4052,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
4033
4052
|
}
|
|
4034
4053
|
|
|
4035
4054
|
// src/adapters/fal.ts
|
|
4036
|
-
import { z as
|
|
4055
|
+
import { z as z8 } from "zod";
|
|
4037
4056
|
import { createFalClient } from "@fal-ai/client";
|
|
4038
4057
|
var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
|
|
4039
4058
|
var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
|
|
@@ -4041,7 +4060,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
|
|
|
4041
4060
|
var FAL_QUEUE_HOST = "https://queue.fal.run";
|
|
4042
4061
|
var PASSTHROUGH_POLL_MS = 2e3;
|
|
4043
4062
|
var PASSTHROUGH_MAX_WAIT_MS = 18e4;
|
|
4044
|
-
var falSubscribePayloadSchema =
|
|
4063
|
+
var falSubscribePayloadSchema = z8.object({ data: JsonValueSchema });
|
|
4045
4064
|
function defaultCreateFalClient(opts) {
|
|
4046
4065
|
const client2 = createFalClient(opts);
|
|
4047
4066
|
return {
|
|
@@ -4091,7 +4110,7 @@ function createFalAdapter(deps = defaultDeps) {
|
|
|
4091
4110
|
};
|
|
4092
4111
|
}
|
|
4093
4112
|
var falAdapter = createFalAdapter();
|
|
4094
|
-
var falDetailSchema =
|
|
4113
|
+
var falDetailSchema = z8.object({ detail: JsonValueSchema });
|
|
4095
4114
|
function liftDetail(body) {
|
|
4096
4115
|
const parsed = falDetailSchema.safeParse(body);
|
|
4097
4116
|
const detail = parsed.success ? parsed.data.detail : void 0;
|
|
@@ -4100,11 +4119,11 @@ function liftDetail(body) {
|
|
|
4100
4119
|
function falError(status, body, model) {
|
|
4101
4120
|
return classifyHttpError(status, liftDetail(body), "fal", model);
|
|
4102
4121
|
}
|
|
4103
|
-
var falSdkThrownSchema =
|
|
4104
|
-
status:
|
|
4105
|
-
statusCode:
|
|
4122
|
+
var falSdkThrownSchema = z8.object({
|
|
4123
|
+
status: z8.number().optional(),
|
|
4124
|
+
statusCode: z8.number().optional(),
|
|
4106
4125
|
body: JsonValueSchema.optional(),
|
|
4107
|
-
message:
|
|
4126
|
+
message: z8.string().optional()
|
|
4108
4127
|
});
|
|
4109
4128
|
function falSdkError(cause, model) {
|
|
4110
4129
|
const parsed = falSdkThrownSchema.safeParse(cause);
|
|
@@ -4148,12 +4167,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
|
|
|
4148
4167
|
if (init.body !== void 0) request.body = init.body;
|
|
4149
4168
|
return fetchImpl(cfg.baseUrl, request);
|
|
4150
4169
|
}
|
|
4151
|
-
var falQueueSubmitSchema =
|
|
4152
|
-
request_id:
|
|
4153
|
-
status_url:
|
|
4154
|
-
response_url:
|
|
4170
|
+
var falQueueSubmitSchema = z8.object({
|
|
4171
|
+
request_id: z8.string(),
|
|
4172
|
+
status_url: z8.string(),
|
|
4173
|
+
response_url: z8.string()
|
|
4155
4174
|
});
|
|
4156
|
-
var falQueueStatusSchema =
|
|
4175
|
+
var falQueueStatusSchema = z8.object({ status: z8.string() });
|
|
4157
4176
|
async function passthroughRequest(ctx, endpoint, input) {
|
|
4158
4177
|
const cfg = gatewayConfig(ctx);
|
|
4159
4178
|
const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
|
|
@@ -4279,11 +4298,11 @@ async function decodeImage(ctx, url, contentType) {
|
|
|
4279
4298
|
const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
|
|
4280
4299
|
return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
|
|
4281
4300
|
}
|
|
4282
|
-
var museImageResultSchema =
|
|
4283
|
-
images:
|
|
4284
|
-
|
|
4285
|
-
url:
|
|
4286
|
-
content_type:
|
|
4301
|
+
var museImageResultSchema = z8.object({
|
|
4302
|
+
images: z8.array(
|
|
4303
|
+
z8.object({
|
|
4304
|
+
url: z8.string().optional(),
|
|
4305
|
+
content_type: z8.string().nullable().optional()
|
|
4287
4306
|
})
|
|
4288
4307
|
).optional()
|
|
4289
4308
|
});
|
|
@@ -4375,8 +4394,8 @@ function klingO1Input(req) {
|
|
|
4375
4394
|
if (refs.length > 0) input.image_urls = refs;
|
|
4376
4395
|
return input;
|
|
4377
4396
|
}
|
|
4378
|
-
var falVideoResultSchema =
|
|
4379
|
-
video:
|
|
4397
|
+
var falVideoResultSchema = z8.object({
|
|
4398
|
+
video: z8.object({ url: z8.string().optional() }).optional()
|
|
4380
4399
|
});
|
|
4381
4400
|
function extractVideoUrl(result, endpoint, model) {
|
|
4382
4401
|
const parsed = falVideoResultSchema.safeParse(result);
|
|
@@ -4566,13 +4585,13 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
|
|
|
4566
4585
|
}
|
|
4567
4586
|
|
|
4568
4587
|
// src/adapters/google-genai.ts
|
|
4569
|
-
import { z as
|
|
4588
|
+
import { z as z10 } from "zod";
|
|
4570
4589
|
import {
|
|
4571
4590
|
GoogleGenAI
|
|
4572
4591
|
} from "@google/genai";
|
|
4573
4592
|
|
|
4574
4593
|
// src/adapters/google-files.ts
|
|
4575
|
-
import { z as
|
|
4594
|
+
import { z as z9 } from "zod";
|
|
4576
4595
|
var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
|
|
4577
4596
|
var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
|
|
4578
4597
|
var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -4582,17 +4601,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
4582
4601
|
"binary/octet-stream",
|
|
4583
4602
|
"application/binary"
|
|
4584
4603
|
]);
|
|
4585
|
-
var uploadedFileSchema =
|
|
4586
|
-
file:
|
|
4587
|
-
uri:
|
|
4588
|
-
name:
|
|
4589
|
-
state:
|
|
4590
|
-
mimeType:
|
|
4604
|
+
var uploadedFileSchema = z9.object({
|
|
4605
|
+
file: z9.object({
|
|
4606
|
+
uri: z9.string().optional(),
|
|
4607
|
+
name: z9.string().optional(),
|
|
4608
|
+
state: z9.string().optional(),
|
|
4609
|
+
mimeType: z9.string().optional()
|
|
4591
4610
|
}).optional()
|
|
4592
4611
|
});
|
|
4593
|
-
var fileStateSchema =
|
|
4594
|
-
state:
|
|
4595
|
-
error:
|
|
4612
|
+
var fileStateSchema = z9.object({
|
|
4613
|
+
state: z9.string().optional(),
|
|
4614
|
+
error: z9.object({ message: z9.string().optional() }).optional()
|
|
4596
4615
|
});
|
|
4597
4616
|
function resolveMime(declared, fallback) {
|
|
4598
4617
|
const clean = declared?.split(";")[0]?.trim().toLowerCase();
|
|
@@ -4805,7 +4824,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
|
4805
4824
|
var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
|
|
4806
4825
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
4807
4826
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
|
|
4808
|
-
var errorTextSchema =
|
|
4827
|
+
var errorTextSchema = z10.string();
|
|
4809
4828
|
function createGoogleGenaiAdapter(deps = defaultDeps2) {
|
|
4810
4829
|
const { createGenAIClient } = deps;
|
|
4811
4830
|
return {
|
|
@@ -4958,6 +4977,7 @@ async function generateVeoVideo(req, ctx, createGenAIClient) {
|
|
|
4958
4977
|
const config = { durationSeconds: duration, personGeneration };
|
|
4959
4978
|
if (req.aspectRatio !== void 0) config.aspectRatio = req.aspectRatio;
|
|
4960
4979
|
if (req.resolution !== void 0) config.resolution = req.resolution;
|
|
4980
|
+
if (req.seed !== void 0) config.seed = req.seed;
|
|
4961
4981
|
if (lastFrame !== void 0) config.lastFrame = lastFrame;
|
|
4962
4982
|
if (referenceImages !== void 0) config.referenceImages = referenceImages;
|
|
4963
4983
|
const requestBody = {
|
|
@@ -5363,15 +5383,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
|
|
|
5363
5383
|
// src/adapters/google-image.ts
|
|
5364
5384
|
import { createGoogleGenerativeAI as createGoogleGenerativeAI2 } from "@ai-sdk/google";
|
|
5365
5385
|
import { generateText } from "ai";
|
|
5366
|
-
import { z as
|
|
5386
|
+
import { z as z11 } from "zod";
|
|
5367
5387
|
var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
|
|
5368
5388
|
var defaultGoogleImageDeps = {
|
|
5369
5389
|
createGoogleClient: (opts) => createGoogleGenerativeAI2(opts),
|
|
5370
5390
|
runTextGeneration: (opts) => generateText(opts)
|
|
5371
5391
|
};
|
|
5372
|
-
var causeChainNodeSchema =
|
|
5373
|
-
message:
|
|
5374
|
-
cause:
|
|
5392
|
+
var causeChainNodeSchema = z11.object({
|
|
5393
|
+
message: z11.string().optional(),
|
|
5394
|
+
cause: z11.unknown().optional()
|
|
5375
5395
|
});
|
|
5376
5396
|
function extractBlockReason(cause) {
|
|
5377
5397
|
let current = cause;
|
|
@@ -5492,7 +5512,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
5492
5512
|
var googleImageAdapter = createGoogleImageAdapter();
|
|
5493
5513
|
|
|
5494
5514
|
// src/adapters/higgsfield.ts
|
|
5495
|
-
import { z as
|
|
5515
|
+
import { z as z12 } from "zod";
|
|
5496
5516
|
|
|
5497
5517
|
// src/adapters/higgsfield-motions.ts
|
|
5498
5518
|
var MOTION_MAP = {
|
|
@@ -5680,14 +5700,14 @@ function videoUsage3(ctx, req, duration) {
|
|
|
5680
5700
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
5681
5701
|
return event;
|
|
5682
5702
|
}
|
|
5683
|
-
var klingCreateSchema =
|
|
5684
|
-
var klingStatusSchema =
|
|
5685
|
-
status:
|
|
5686
|
-
video:
|
|
5703
|
+
var klingCreateSchema = z12.object({ status_url: z12.string() });
|
|
5704
|
+
var klingStatusSchema = z12.object({
|
|
5705
|
+
status: z12.string().optional(),
|
|
5706
|
+
video: z12.object({ url: z12.string().optional() }).optional(),
|
|
5687
5707
|
error: JsonValueSchema.optional()
|
|
5688
5708
|
});
|
|
5689
|
-
var errorMessageSchema =
|
|
5690
|
-
var textValueSchema =
|
|
5709
|
+
var errorMessageSchema = z12.object({ message: z12.string().optional() });
|
|
5710
|
+
var textValueSchema = z12.string();
|
|
5691
5711
|
function klingErrorDetail(error) {
|
|
5692
5712
|
if (error === void 0) return "unknown_error";
|
|
5693
5713
|
const asText = textValueSchema.safeParse(error);
|
|
@@ -5821,8 +5841,8 @@ async function generateKlingVideo(req, ctx) {
|
|
|
5821
5841
|
}
|
|
5822
5842
|
};
|
|
5823
5843
|
}
|
|
5824
|
-
var dopMotionOptionsSchema =
|
|
5825
|
-
modelkit:
|
|
5844
|
+
var dopMotionOptionsSchema = z12.object({
|
|
5845
|
+
modelkit: z12.object({ motion: z12.string().optional() }).optional()
|
|
5826
5846
|
});
|
|
5827
5847
|
function dopMotionId(ctx) {
|
|
5828
5848
|
const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
|
|
@@ -5838,7 +5858,7 @@ function dopMotionId(ctx) {
|
|
|
5838
5858
|
});
|
|
5839
5859
|
return id;
|
|
5840
5860
|
}
|
|
5841
|
-
var jsonRecordSchema =
|
|
5861
|
+
var jsonRecordSchema = z12.record(z12.string(), JsonValueSchema);
|
|
5842
5862
|
var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
|
|
5843
5863
|
var DOP_NESTED_KEYS = ["video", "result", "results"];
|
|
5844
5864
|
function dopUrl(body) {
|
|
@@ -5866,8 +5886,8 @@ function dopUrl(body) {
|
|
|
5866
5886
|
}
|
|
5867
5887
|
return void 0;
|
|
5868
5888
|
}
|
|
5869
|
-
var dopCreateSchema =
|
|
5870
|
-
var dopStatusSchema =
|
|
5889
|
+
var dopCreateSchema = z12.object({ id: z12.string() });
|
|
5890
|
+
var dopStatusSchema = z12.object({ status: z12.string().optional() });
|
|
5871
5891
|
async function generateDopVideo(req, ctx) {
|
|
5872
5892
|
const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
|
|
5873
5893
|
if (!firstFrame) {
|
|
@@ -5987,7 +6007,7 @@ var higgsfieldAdapter = {
|
|
|
5987
6007
|
|
|
5988
6008
|
// src/adapters/openai-image.ts
|
|
5989
6009
|
import OpenAI from "openai";
|
|
5990
|
-
import { z as
|
|
6010
|
+
import { z as z13 } from "zod";
|
|
5991
6011
|
var MAX_EDIT_REFERENCES = 16;
|
|
5992
6012
|
function aspectRatioToSize(ratio, tier) {
|
|
5993
6013
|
const TIER_LONG_EDGE = {
|
|
@@ -6070,9 +6090,9 @@ function toProviderError2(cause, ctx) {
|
|
|
6070
6090
|
ctx.model.id
|
|
6071
6091
|
);
|
|
6072
6092
|
}
|
|
6073
|
-
var openaiUsageSchema =
|
|
6074
|
-
input_tokens:
|
|
6075
|
-
output_tokens:
|
|
6093
|
+
var openaiUsageSchema = z13.object({
|
|
6094
|
+
input_tokens: z13.number().optional(),
|
|
6095
|
+
output_tokens: z13.number().optional()
|
|
6076
6096
|
});
|
|
6077
6097
|
var openaiImageAdapter = {
|
|
6078
6098
|
id: "openai-image",
|
|
@@ -6101,6 +6121,19 @@ var openaiImageAdapter = {
|
|
|
6101
6121
|
const quality = req.quality ?? (isEdit ? "medium" : "auto");
|
|
6102
6122
|
const sdkQuality = quality;
|
|
6103
6123
|
const count = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
|
|
6124
|
+
let outputFormat = req.outputFormat;
|
|
6125
|
+
if (outputFormat === "webp") {
|
|
6126
|
+
ctx.warnings.push({
|
|
6127
|
+
code: "option_ignored",
|
|
6128
|
+
field: "outputFormat",
|
|
6129
|
+
from: "webp",
|
|
6130
|
+
to: "png",
|
|
6131
|
+
message: `${ctx.model.id} returns PNG for output_format webp; using png`
|
|
6132
|
+
});
|
|
6133
|
+
outputFormat = "png";
|
|
6134
|
+
}
|
|
6135
|
+
const format = outputFormat !== void 0 ? { output_format: outputFormat } : {};
|
|
6136
|
+
const mime = outputFormat === "jpeg" ? "image/jpeg" : "image/png";
|
|
6104
6137
|
const retryOptions = {};
|
|
6105
6138
|
if (ctx.signal !== void 0) retryOptions.signal = ctx.signal;
|
|
6106
6139
|
const response = await withRetry(async () => {
|
|
@@ -6113,7 +6146,8 @@ var openaiImageAdapter = {
|
|
|
6113
6146
|
prompt: req.prompt,
|
|
6114
6147
|
size,
|
|
6115
6148
|
quality: sdkQuality,
|
|
6116
|
-
...count
|
|
6149
|
+
...count,
|
|
6150
|
+
...format
|
|
6117
6151
|
},
|
|
6118
6152
|
{ signal: ctx.signal }
|
|
6119
6153
|
);
|
|
@@ -6123,20 +6157,21 @@ var openaiImageAdapter = {
|
|
|
6123
6157
|
model: ctx.model.providerModelId,
|
|
6124
6158
|
prompt: req.prompt,
|
|
6125
6159
|
quality: sdkQuality,
|
|
6126
|
-
...count
|
|
6160
|
+
...count,
|
|
6161
|
+
...format
|
|
6127
6162
|
},
|
|
6128
6163
|
{ signal: ctx.signal }
|
|
6129
6164
|
);
|
|
6130
6165
|
}
|
|
6131
6166
|
const files = await Promise.all(
|
|
6132
6167
|
refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
|
|
6133
|
-
const { bytes, mime } = await mediaRefToBytes(ref, ctx.fetch, {
|
|
6168
|
+
const { bytes, mime: mime2 } = await mediaRefToBytes(ref, ctx.fetch, {
|
|
6134
6169
|
signal: ctx.signal,
|
|
6135
6170
|
provider: "openai-image",
|
|
6136
6171
|
model: ctx.model.id
|
|
6137
6172
|
});
|
|
6138
|
-
const ext =
|
|
6139
|
-
return new File([bytes], `ref-${i}.${ext}`, { type:
|
|
6173
|
+
const ext = mime2.includes("jpeg") ? "jpg" : mime2.includes("webp") ? "webp" : "png";
|
|
6174
|
+
return new File([bytes], `ref-${i}.${ext}`, { type: mime2 });
|
|
6140
6175
|
})
|
|
6141
6176
|
);
|
|
6142
6177
|
const single = files.length === 1 ? files[0] : void 0;
|
|
@@ -6149,7 +6184,8 @@ var openaiImageAdapter = {
|
|
|
6149
6184
|
prompt: req.prompt,
|
|
6150
6185
|
size,
|
|
6151
6186
|
quality: sdkQuality,
|
|
6152
|
-
...count
|
|
6187
|
+
...count,
|
|
6188
|
+
...format
|
|
6153
6189
|
},
|
|
6154
6190
|
{ signal: ctx.signal }
|
|
6155
6191
|
);
|
|
@@ -6160,7 +6196,8 @@ var openaiImageAdapter = {
|
|
|
6160
6196
|
image: imageInput,
|
|
6161
6197
|
prompt: req.prompt,
|
|
6162
6198
|
quality: sdkQuality,
|
|
6163
|
-
...count
|
|
6199
|
+
...count,
|
|
6200
|
+
...format
|
|
6164
6201
|
},
|
|
6165
6202
|
{ signal: ctx.signal }
|
|
6166
6203
|
);
|
|
@@ -6169,7 +6206,7 @@ var openaiImageAdapter = {
|
|
|
6169
6206
|
}
|
|
6170
6207
|
}, retryOptions);
|
|
6171
6208
|
const images = (response.data ?? []).flatMap(
|
|
6172
|
-
(item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime
|
|
6209
|
+
(item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime }] : []
|
|
6173
6210
|
);
|
|
6174
6211
|
if (images.length === 0)
|
|
6175
6212
|
throw classifyHttpError(
|
|
@@ -6462,7 +6499,7 @@ var prodiaAdapter = {
|
|
|
6462
6499
|
|
|
6463
6500
|
// src/adapters/replicate.ts
|
|
6464
6501
|
import Replicate from "replicate";
|
|
6465
|
-
import { z as
|
|
6502
|
+
import { z as z14 } from "zod";
|
|
6466
6503
|
var POLL_INTERVAL_MS = 1e3;
|
|
6467
6504
|
var POLL_TIMEOUT_MS = 15 * 6e4;
|
|
6468
6505
|
var defaultReplicateDeps = {
|
|
@@ -6498,8 +6535,8 @@ function route(providerModelId) {
|
|
|
6498
6535
|
if (!providerModelId.includes("/")) return { version: providerModelId };
|
|
6499
6536
|
return { model: providerModelId };
|
|
6500
6537
|
}
|
|
6501
|
-
var replicateResponseStatusSchema =
|
|
6502
|
-
response:
|
|
6538
|
+
var replicateResponseStatusSchema = z14.object({
|
|
6539
|
+
response: z14.object({ status: z14.number() }).partial()
|
|
6503
6540
|
});
|
|
6504
6541
|
function replicateError(cause, ctx) {
|
|
6505
6542
|
if (isModelKitError(cause)) return cause;
|
|
@@ -6526,7 +6563,7 @@ function isUrlFn(value) {
|
|
|
6526
6563
|
function extractOutputUrl(output) {
|
|
6527
6564
|
const root = Array.isArray(output) ? output[0] : output;
|
|
6528
6565
|
if (root === void 0) throw noOutput();
|
|
6529
|
-
const asString =
|
|
6566
|
+
const asString = z14.string().safeParse(root);
|
|
6530
6567
|
if (asString.success && asString.data) return asString.data;
|
|
6531
6568
|
if (root instanceof URL) return root.href;
|
|
6532
6569
|
if (isObjectOutput(root)) {
|
|
@@ -6535,15 +6572,15 @@ function extractOutputUrl(output) {
|
|
|
6535
6572
|
if (urlValue !== void 0 && isUrlFn(urlValue)) {
|
|
6536
6573
|
const called = urlValue();
|
|
6537
6574
|
if (called instanceof URL) return called.href;
|
|
6538
|
-
const calledString =
|
|
6575
|
+
const calledString = z14.string().safeParse(called);
|
|
6539
6576
|
if (calledString.success && calledString.data) return calledString.data;
|
|
6540
6577
|
} else {
|
|
6541
|
-
const direct =
|
|
6578
|
+
const direct = z14.string().safeParse(urlValue);
|
|
6542
6579
|
if (direct.success && direct.data) return direct.data;
|
|
6543
6580
|
}
|
|
6544
6581
|
}
|
|
6545
6582
|
if ("default" in root) {
|
|
6546
|
-
const fallback =
|
|
6583
|
+
const fallback = z14.string().safeParse(root.default);
|
|
6547
6584
|
if (fallback.success && fallback.data) return fallback.data;
|
|
6548
6585
|
}
|
|
6549
6586
|
}
|
|
@@ -6604,7 +6641,7 @@ async function runPrediction(ctx, input, deps) {
|
|
|
6604
6641
|
}
|
|
6605
6642
|
return void 0;
|
|
6606
6643
|
}, pollOpts);
|
|
6607
|
-
const predictTime =
|
|
6644
|
+
const predictTime = z14.number().safeParse(done.metrics?.predict_time);
|
|
6608
6645
|
if (done.output === void 0) throw noOutput();
|
|
6609
6646
|
return {
|
|
6610
6647
|
url: extractOutputUrl(done.output),
|
|
@@ -6947,7 +6984,7 @@ async function generateReplicateVideo(req, ctx, deps) {
|
|
|
6947
6984
|
throw replicateError(cause, ctx);
|
|
6948
6985
|
}
|
|
6949
6986
|
if (current.status === "succeeded") {
|
|
6950
|
-
const predictTime =
|
|
6987
|
+
const predictTime = z14.number().safeParse(current.metrics?.predict_time);
|
|
6951
6988
|
if (current.output === void 0) throw noOutput();
|
|
6952
6989
|
return {
|
|
6953
6990
|
url: extractOutputUrl(current.output),
|
|
@@ -7079,7 +7116,7 @@ async function generateReplicateAudio(req, ctx, deps) {
|
|
|
7079
7116
|
// src/adapters/xai-video.ts
|
|
7080
7117
|
import { experimental_generateVideo } from "ai";
|
|
7081
7118
|
import { createXai as createXai2 } from "@ai-sdk/xai";
|
|
7082
|
-
import { z as
|
|
7119
|
+
import { z as z15 } from "zod";
|
|
7083
7120
|
var POLL_INTERVAL_MS2 = 1e4;
|
|
7084
7121
|
var POLL_TIMEOUT_MS2 = 15 * 6e4;
|
|
7085
7122
|
var defaultXaiDeps = {
|
|
@@ -7092,8 +7129,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
|
|
|
7092
7129
|
};
|
|
7093
7130
|
}
|
|
7094
7131
|
var xaiVideoAdapter = createXaiVideoAdapter();
|
|
7095
|
-
var xaiResponseStatusSchema =
|
|
7096
|
-
response:
|
|
7132
|
+
var xaiResponseStatusSchema = z15.object({
|
|
7133
|
+
response: z15.object({ status: z15.number() }).partial()
|
|
7097
7134
|
});
|
|
7098
7135
|
function xaiError(cause, ctx) {
|
|
7099
7136
|
const info = describeThrown(cause);
|
|
@@ -7101,12 +7138,12 @@ function xaiError(cause, ctx) {
|
|
|
7101
7138
|
const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
|
|
7102
7139
|
return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
|
|
7103
7140
|
}
|
|
7104
|
-
var xaiMetaSchema =
|
|
7141
|
+
var xaiMetaSchema = z15.object({
|
|
7105
7142
|
videoUrl: JsonValueSchema.optional(),
|
|
7106
7143
|
costInUsdTicks: JsonValueSchema.optional(),
|
|
7107
7144
|
duration: JsonValueSchema.optional()
|
|
7108
7145
|
});
|
|
7109
|
-
var xaiProviderMetadataSchema =
|
|
7146
|
+
var xaiProviderMetadataSchema = z15.object({ xai: xaiMetaSchema });
|
|
7110
7147
|
function metaOf(result) {
|
|
7111
7148
|
const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
|
|
7112
7149
|
if (!parsed.success) return {};
|
|
@@ -7213,7 +7250,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7213
7250
|
};
|
|
7214
7251
|
}
|
|
7215
7252
|
const meta = metaOf(result);
|
|
7216
|
-
const videoUrl =
|
|
7253
|
+
const videoUrl = z15.string().safeParse(meta.videoUrl);
|
|
7217
7254
|
if (videoUrl.success && videoUrl.data) {
|
|
7218
7255
|
const res = await ctx.fetch(videoUrl.data);
|
|
7219
7256
|
if (!res.ok) {
|
|
@@ -7236,7 +7273,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7236
7273
|
});
|
|
7237
7274
|
}
|
|
7238
7275
|
function usage(ctx, req, meta) {
|
|
7239
|
-
const costTicks =
|
|
7276
|
+
const costTicks = z15.number().safeParse(meta.costInUsdTicks);
|
|
7240
7277
|
const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
|
|
7241
7278
|
const event = {
|
|
7242
7279
|
model: ctx.model.id,
|
|
@@ -7317,6 +7354,7 @@ export {
|
|
|
7317
7354
|
keysFromEnv,
|
|
7318
7355
|
languageModel,
|
|
7319
7356
|
liveCatalog,
|
|
7357
|
+
liveState,
|
|
7320
7358
|
mergeTextProviderOptions,
|
|
7321
7359
|
nearestAspectRatio,
|
|
7322
7360
|
openaiImageAdapter,
|