@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/dist/index.cjs CHANGED
@@ -64,6 +64,7 @@ __export(index_exports, {
64
64
  keysFromEnv: () => keysFromEnv,
65
65
  languageModel: () => languageModel,
66
66
  liveCatalog: () => liveCatalog,
67
+ liveState: () => liveState,
67
68
  mergeTextProviderOptions: () => mergeTextProviderOptions,
68
69
  nearestAspectRatio: () => nearestAspectRatio,
69
70
  openaiImageAdapter: () => openaiImageAdapter,
@@ -211,7 +212,13 @@ var GEMINI_RATIOS = [
211
212
  "5:4",
212
213
  "adaptive"
213
214
  ];
214
- function geminiImage(id, label, aliases, sizes, display, exposure) {
215
+ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
216
+ const constraints = {
217
+ aspectRatios: [...GEMINI_RATIOS],
218
+ sizes,
219
+ supports: ["safetySettings", "temperature"]
220
+ };
221
+ if (references !== void 0) constraints.references = references;
215
222
  const model = {
216
223
  id,
217
224
  aliases,
@@ -221,11 +228,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure) {
221
228
  providerModelId: id,
222
229
  lifecycle: "active",
223
230
  exposure,
224
- constraints: {
225
- aspectRatios: [...GEMINI_RATIOS],
226
- sizes,
227
- supports: ["safetySettings", "temperature"]
228
- },
231
+ constraints,
229
232
  defaults: { size: "1K", aspectRatio: "1:1" },
230
233
  usage: { ...IMAGE_USAGE, slug: "gemini" },
231
234
  pricingKind: "image_size",
@@ -244,7 +247,8 @@ var IMAGE_MODELS = [
244
247
  description: "Create stunning, production-quality visuals with exceptional realism, detail, and typography. Best for campaigns, e-commerce, product photography, and hero creatives.",
245
248
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
246
249
  },
247
- "catalog"
250
+ "catalog",
251
+ { images: 14 }
248
252
  ),
249
253
  geminiImage(
250
254
  "gemini-3.1-flash-image-preview",
@@ -257,7 +261,8 @@ var IMAGE_MODELS = [
257
261
  description: "Generate high-quality images at speed. Perfect for brainstorming, moodboards, concept testing, creative exploration, and large batch workflows.",
258
262
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
259
263
  },
260
- "catalog"
264
+ "catalog",
265
+ { images: 14 }
261
266
  ),
262
267
  geminiImage(
263
268
  "gemini-3.1-flash-lite-image",
@@ -269,14 +274,15 @@ var IMAGE_MODELS = [
269
274
  description: "The fastest and most affordable image model. Ideal for rapid drafts, bulk exploration, and iterative concept testing at 1K resolution.",
270
275
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
271
276
  },
272
- "catalog"
277
+ "catalog",
278
+ { images: 14 }
273
279
  ),
274
280
  // trigger-workflows validates 1K only; pricing seeds 2K/4K rows so allow all three.
275
281
  geminiImage(
276
282
  "gemini-2.5-flash-image",
277
283
  "Gemini 2.5 Flash Image",
278
284
  [],
279
- ["1K", "2K", "4K"],
285
+ ["1K"],
280
286
  {
281
287
  provider: "google",
282
288
  description: "Nano Banana (legacy Gemini 2.5 Flash Image) native image generation and editing model for high-volume, low-latency creative workflows."
@@ -307,7 +313,7 @@ var IMAGE_MODELS = [
307
313
  sizes: ["1K", "2K", "4K"],
308
314
  qualityOptions: ["auto", "low", "medium", "high"],
309
315
  references: { images: 16 },
310
- supports: ["quality", "count"]
316
+ supports: ["quality", "count", "outputFormat"]
311
317
  },
312
318
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
313
319
  usage: { ...IMAGE_USAGE, slug: "gpt" },
@@ -327,7 +333,7 @@ var IMAGE_MODELS = [
327
333
  adapter: "openai-image",
328
334
  providerModelId: "gpt-image-2.5-sunburst",
329
335
  lifecycle: "active",
330
- exposure: "internal",
336
+ exposure: "catalog",
331
337
  constraints: {
332
338
  exactSizes: {
333
339
  "1:1": "1024x1024",
@@ -340,15 +346,16 @@ var IMAGE_MODELS = [
340
346
  },
341
347
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
342
348
  sizes: ["1K", "2K", "4K"],
343
- qualityOptions: ["auto", "low", "medium", "high"],
349
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
344
350
  references: { images: 16 },
345
- supports: ["quality", "count"]
351
+ supports: ["quality", "count", "outputFormat"]
346
352
  },
347
353
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
348
354
  usage: { ...IMAGE_USAGE },
349
355
  pricingKind: "image_size",
350
356
  display: {
351
357
  provider: "openai",
358
+ sortOrder: 20,
352
359
  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."
353
360
  }
354
361
  },
@@ -361,7 +368,7 @@ var IMAGE_MODELS = [
361
368
  adapter: "openai-image",
362
369
  providerModelId: "gpt-image-2.5-flare",
363
370
  lifecycle: "active",
364
- exposure: "internal",
371
+ exposure: "catalog",
365
372
  constraints: {
366
373
  exactSizes: {
367
374
  "1:1": "1024x1024",
@@ -374,15 +381,16 @@ var IMAGE_MODELS = [
374
381
  },
375
382
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
376
383
  sizes: ["1K", "2K", "4K"],
377
- qualityOptions: ["auto", "low", "medium", "high"],
384
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
378
385
  references: { images: 16 },
379
- supports: ["quality", "count"]
386
+ supports: ["quality", "count", "outputFormat"]
380
387
  },
381
388
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
382
389
  usage: { ...IMAGE_USAGE },
383
390
  pricingKind: "image_size",
384
391
  display: {
385
392
  provider: "openai",
393
+ sortOrder: 10,
386
394
  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."
387
395
  }
388
396
  },
@@ -406,8 +414,6 @@ var IMAGE_MODELS = [
406
414
  "2:3",
407
415
  "3:4",
408
416
  "9:16",
409
- "4:5",
410
- "5:4",
411
417
  "9:21",
412
418
  "adaptive"
413
419
  ],
@@ -439,7 +445,7 @@ var IMAGE_MODELS = [
439
445
  references: { images: 10 },
440
446
  // Ark's Images API has no output-format, quality or count field; only
441
447
  // the seed is forwarded, so anything else must warn, not vanish.
442
- supports: ["seed"]
448
+ supports: ["seed", "outputFormat"]
443
449
  },
444
450
  defaults: { size: "1K", aspectRatio: "1:1" },
445
451
  usage: { ...IMAGE_USAGE },
@@ -475,7 +481,7 @@ var IMAGE_MODELS = [
475
481
  "21:9",
476
482
  "9:21"
477
483
  ],
478
- sizes: ["1K", "2K", "4K"],
484
+ sizes: ["2K", "4K"],
479
485
  references: { images: 10 },
480
486
  supports: ["seed"]
481
487
  },
@@ -527,7 +533,7 @@ var IMAGE_MODELS = [
527
533
  aspectRatios: ["1:1", "2:3", "3:2", "4:3", "3:4", "4:5", "5:4", "9:16", "16:9", "21:9"],
528
534
  sizes: ["1K", "2K", "4K"],
529
535
  requires: ["references"],
530
- supports: ["seed"]
536
+ supports: []
531
537
  },
532
538
  defaults: { size: "1K", aspectRatio: "1:1" },
533
539
  usage: { ...IMAGE_USAGE },
@@ -552,7 +558,7 @@ var IMAGE_MODELS = [
552
558
  aspectRatios: ["1:1", "2:3", "3:4", "4:3", "9:16", "16:9", "21:9"],
553
559
  sizes: ["1K"],
554
560
  requires: ["references"],
555
- supports: ["seed"]
561
+ supports: []
556
562
  },
557
563
  defaults: { size: "1K", aspectRatio: "1:1" },
558
564
  usage: { ...IMAGE_USAGE },
@@ -604,7 +610,6 @@ var IMAGE_MODELS = [
604
610
  aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
605
611
  sizes: [],
606
612
  references: { images: 1 },
607
- requires: ["references"],
608
613
  supports: []
609
614
  },
610
615
  defaults: { aspectRatio: "1:1" },
@@ -1323,7 +1328,7 @@ var VIDEO_MODELS = [
1323
1328
  resolutions: ["720p", "1080p", "4k"],
1324
1329
  durations: [8],
1325
1330
  references: { images: 3 },
1326
- supports: ["lastFrame"]
1331
+ supports: ["lastFrame", "seed"]
1327
1332
  },
1328
1333
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1329
1334
  usage: { ...VIDEO_USAGE, slug: "veo" },
@@ -1351,9 +1356,9 @@ var VIDEO_MODELS = [
1351
1356
  constraints: {
1352
1357
  aspectRatios: [...OMNI_RATIOS],
1353
1358
  resolutions: ["720p", "1080p", "4k"],
1354
- durations: [4, 8],
1359
+ durations: [4, 6, 8],
1355
1360
  references: { images: 3 },
1356
- supports: ["lastFrame"]
1361
+ supports: ["lastFrame", "seed"]
1357
1362
  },
1358
1363
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1359
1364
  usage: { ...VIDEO_USAGE },
@@ -1380,9 +1385,8 @@ var VIDEO_MODELS = [
1380
1385
  constraints: {
1381
1386
  aspectRatios: [...OMNI_RATIOS],
1382
1387
  resolutions: ["720p", "1080p"],
1383
- durations: [4, 8],
1384
- references: { images: 3 },
1385
- supports: ["lastFrame"]
1388
+ durations: [4, 6, 8],
1389
+ supports: ["lastFrame", "seed"]
1386
1390
  },
1387
1391
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1388
1392
  usage: { ...VIDEO_USAGE },
@@ -1414,7 +1418,7 @@ var VIDEO_MODELS = [
1414
1418
  // reference clip keeps its own framing.
1415
1419
  aspectRatios: [...OMNI_RATIOS],
1416
1420
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1417
- references: { images: 6, videos: 1 },
1421
+ references: { images: 6, videos: 3 },
1418
1422
  supports: []
1419
1423
  },
1420
1424
  defaults: {},
@@ -1440,7 +1444,7 @@ var VIDEO_MODELS = [
1440
1444
  aspectRatios: [...OMNI_RATIOS],
1441
1445
  resolutions: ["360p", "720p", "1080p", "4k"],
1442
1446
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1443
- references: { images: 6, videos: 1 },
1447
+ references: { images: 6, videos: 3 },
1444
1448
  supports: []
1445
1449
  },
1446
1450
  defaults: {},
@@ -1469,7 +1473,7 @@ var VIDEO_MODELS = [
1469
1473
  durations: { min: 4, max: 15 },
1470
1474
  durationPresets: [4, 6, 8, 10, 12, 15],
1471
1475
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1472
- ratioIgnoredWith: ["firstFrame"],
1476
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1473
1477
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1474
1478
  },
1475
1479
  defaults: {
@@ -1501,7 +1505,7 @@ var VIDEO_MODELS = [
1501
1505
  resolutions: ["480p", "720p"],
1502
1506
  durations: { min: 4, max: 15 },
1503
1507
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1504
- ratioIgnoredWith: ["firstFrame"],
1508
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1505
1509
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1506
1510
  },
1507
1511
  defaults: {
@@ -1534,7 +1538,7 @@ var VIDEO_MODELS = [
1534
1538
  resolutions: ["480p", "720p", "1080p"],
1535
1539
  durations: { min: 4, max: 30 },
1536
1540
  references: { images: 30, videos: 10, audios: 10 },
1537
- ratioIgnoredWith: ["firstFrame"],
1541
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1538
1542
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1539
1543
  },
1540
1544
  defaults: {
@@ -1653,18 +1657,7 @@ var VIDEO_MODELS = [
1653
1657
  lifecycle: "active",
1654
1658
  exposure: "catalog",
1655
1659
  constraints: {
1656
- aspectRatios: [
1657
- "1:1",
1658
- "16:9",
1659
- "9:16",
1660
- "4:3",
1661
- "3:4",
1662
- "3:2",
1663
- "2:3",
1664
- "21:9",
1665
- "4:5",
1666
- "adaptive"
1667
- ],
1660
+ aspectRatios: [...KLING_RATIOS],
1668
1661
  resolutions: ["720p", "1080p"],
1669
1662
  durations: { min: 3, max: 15 },
1670
1663
  references: { images: 7 },
@@ -2126,30 +2119,34 @@ var CatalogSchema = import_zod.z.array(CatalogModelSchemaBase).superRefine((rows
2126
2119
  });
2127
2120
 
2128
2121
  // src/catalog/live.ts
2129
- var liveCatalog = new Catalog(MODELS);
2122
+ var KEY = /* @__PURE__ */ Symbol.for("@shop-os/modelkit/live-catalog");
2123
+ var store = globalThis;
2124
+ var liveState = store[KEY] ??= {
2125
+ catalog: new Catalog(MODELS),
2126
+ memo: void 0,
2127
+ timer: void 0,
2128
+ revision: void 0,
2129
+ origin: "snapshot"
2130
+ };
2131
+ var liveCatalog = liveState.catalog;
2130
2132
 
2131
2133
  // src/catalog/load.ts
2132
- var memo;
2133
- var timer;
2134
- var revision;
2135
- var origin = "snapshot";
2134
+ var import_zod2 = require("zod");
2136
2135
  function rowCount() {
2137
2136
  return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
2138
2137
  }
2139
2138
  function authHeaders(auth) {
2140
2139
  return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
2141
2140
  }
2142
- function describeError(err) {
2143
- return err instanceof Error ? err.message : String(err);
2144
- }
2145
- function parseEnvelope(json) {
2146
- if (typeof json !== "object" || json === null || !("rows" in json)) {
2147
- throw new Error("invalid catalog response: missing rows");
2148
- }
2149
- const rows = CatalogSchema.parse(json.rows);
2150
- const rev = json.revision;
2151
- if (typeof rev === "string") return { rows, revision: rev };
2152
- return { rows };
2141
+ var EnvelopeSchema = import_zod2.z.object({
2142
+ rows: CatalogSchema,
2143
+ revision: import_zod2.z.string().optional()
2144
+ });
2145
+ function toEnvelope(data) {
2146
+ if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
2147
+ const envelope = { rows: data.rows };
2148
+ if (data.revision !== void 0) envelope.revision = data.revision;
2149
+ return envelope;
2153
2150
  }
2154
2151
  function logPrimed(logger, result) {
2155
2152
  const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
@@ -2162,7 +2159,7 @@ function logPrimed(logger, result) {
2162
2159
  async function fetchRemote(source, logger) {
2163
2160
  const fetchImpl = source.fetch ?? globalThis.fetch;
2164
2161
  const headers2 = authHeaders(source.auth);
2165
- if (revision !== void 0) headers2["If-None-Match"] = `"${revision}"`;
2162
+ if (liveState.revision !== void 0) headers2["If-None-Match"] = `"${liveState.revision}"`;
2166
2163
  const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
2167
2164
  headers: headers2,
2168
2165
  signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
@@ -2170,7 +2167,9 @@ async function fetchRemote(source, logger) {
2170
2167
  if (res.status === 304) return { kept: true };
2171
2168
  if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
2172
2169
  const json = await res.json();
2173
- const { rows, revision: rev } = parseEnvelope(json);
2170
+ const parsed = EnvelopeSchema.safeParse(json);
2171
+ if (!parsed.success) throw new Error("invalid catalog response: missing rows");
2172
+ const { rows, revision: rev } = toEnvelope(parsed.data);
2174
2173
  if (rev === void 0) return { rows, fromCache: false };
2175
2174
  return { rows, revision: rev, fromCache: false };
2176
2175
  }
@@ -2186,40 +2185,46 @@ async function prime(source, logger) {
2186
2185
  try {
2187
2186
  const fetched = await fetchRemote(source, logger);
2188
2187
  if ("kept" in fetched) {
2189
- const result2 = { origin, rowCount: rowCount() };
2190
- if (revision !== void 0) result2.revision = revision;
2188
+ const result2 = { origin: liveState.origin, rowCount: rowCount() };
2189
+ if (liveState.revision !== void 0) result2.revision = liveState.revision;
2191
2190
  logPrimed(logger, result2);
2192
2191
  return result2;
2193
2192
  }
2194
2193
  liveCatalog.replace(fetched.rows);
2195
- origin = "remote";
2196
- revision = fetched.revision;
2194
+ liveState.origin = "remote";
2195
+ liveState.revision = fetched.revision;
2197
2196
  await writeCache(source, logger, fetched.rows, fetched.revision);
2198
- const result = { origin, rowCount: rowCount() };
2197
+ const result = { origin: liveState.origin, rowCount: rowCount() };
2199
2198
  if (fetched.revision !== void 0) result.revision = fetched.revision;
2200
2199
  logPrimed(logger, result);
2201
2200
  return result;
2202
2201
  } catch (err) {
2203
2202
  logger.warn("[modelkit] catalog remote failed, trying cache", err);
2204
- const error = describeError(err);
2203
+ const error = err instanceof Error ? err.message : String(err);
2205
2204
  try {
2206
2205
  const cached = await source.cache?.get();
2207
2206
  if (!cached) throw new Error("no cached catalog");
2208
- const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
2207
+ const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
2208
+ if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
2209
+ const { rows, revision: rev } = toEnvelope(cachedParsed.data);
2209
2210
  liveCatalog.replace(rows);
2210
- origin = "last-good";
2211
- revision = rev;
2212
- const result = { origin, rowCount: rowCount(), error };
2211
+ liveState.origin = "last-good";
2212
+ liveState.revision = rev;
2213
+ const result = {
2214
+ origin: liveState.origin,
2215
+ rowCount: rowCount(),
2216
+ error
2217
+ };
2213
2218
  if (rev !== void 0) result.revision = rev;
2214
2219
  logPrimed(logger, result);
2215
2220
  return result;
2216
2221
  } catch (cacheErr) {
2217
2222
  logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2218
2223
  liveCatalog.replace([...MODELS]);
2219
- origin = "snapshot";
2220
- revision = void 0;
2224
+ liveState.origin = "snapshot";
2225
+ liveState.revision = void 0;
2221
2226
  const result = {
2222
- origin,
2227
+ origin: liveState.origin,
2223
2228
  rowCount: rowCount(),
2224
2229
  error
2225
2230
  };
@@ -2233,47 +2238,50 @@ async function refresh(source, logger) {
2233
2238
  const fetched = await fetchRemote(source, logger);
2234
2239
  if ("kept" in fetched) return;
2235
2240
  liveCatalog.replace(fetched.rows);
2236
- origin = "remote";
2237
- revision = fetched.revision;
2241
+ liveState.origin = "remote";
2242
+ liveState.revision = fetched.revision;
2238
2243
  await writeCache(source, logger, fetched.rows, fetched.revision);
2239
2244
  } catch (err) {
2240
2245
  logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2241
2246
  }
2242
2247
  }
2243
2248
  function primeCatalog(source) {
2244
- if (memo) return memo;
2249
+ if (liveState.memo) return liveState.memo;
2245
2250
  const logger = source.logger ?? console;
2246
- memo = prime(source, logger).then((result) => {
2251
+ const pending = prime(source, logger).then((result) => {
2247
2252
  const ttlMs = source.ttlMs ?? 3e5;
2248
- if (ttlMs > 0 && timer === void 0) {
2249
- timer = setInterval(() => void refresh(source, logger), ttlMs);
2250
- const maybeUnref = timer;
2251
- maybeUnref.unref?.();
2253
+ if (ttlMs > 0 && liveState.timer === void 0) {
2254
+ liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
2255
+ liveState.timer.unref?.();
2252
2256
  }
2253
2257
  return result;
2254
2258
  });
2255
- return memo;
2259
+ liveState.memo = pending;
2260
+ return pending;
2256
2261
  }
2257
2262
  function resetLiveCatalog() {
2258
- if (timer !== void 0) {
2259
- clearInterval(timer);
2260
- timer = void 0;
2263
+ if (liveState.timer !== void 0) {
2264
+ clearInterval(liveState.timer);
2265
+ liveState.timer = void 0;
2261
2266
  }
2262
- memo = void 0;
2263
- revision = void 0;
2264
- origin = "snapshot";
2267
+ liveState.memo = void 0;
2268
+ liveState.revision = void 0;
2269
+ liveState.origin = "snapshot";
2265
2270
  liveCatalog.replace([...MODELS]);
2266
2271
  }
2267
2272
 
2268
2273
  // src/catalog/file-cache.ts
2269
2274
  var import_promises = require("fs/promises");
2275
+ function isErrnoException(err) {
2276
+ return err instanceof Error && "code" in err;
2277
+ }
2270
2278
  function fileCatalogCache(path) {
2271
2279
  return {
2272
2280
  async get() {
2273
2281
  try {
2274
2282
  return await (0, import_promises.readFile)(path, "utf8");
2275
2283
  } catch (err) {
2276
- if (err?.code === "ENOENT") return null;
2284
+ if (isErrnoException(err) && err.code === "ENOENT") return null;
2277
2285
  throw err;
2278
2286
  }
2279
2287
  },
@@ -2710,21 +2718,21 @@ function keysFromEnv(env, prefix = "") {
2710
2718
  }
2711
2719
 
2712
2720
  // src/retry.ts
2713
- var import_zod3 = require("zod");
2721
+ var import_zod4 = require("zod");
2714
2722
 
2715
2723
  // src/json.ts
2716
- var import_zod2 = require("zod");
2717
- var JsonValueSchema = import_zod2.z.lazy(
2718
- () => import_zod2.z.union([
2719
- import_zod2.z.string(),
2720
- import_zod2.z.number(),
2721
- import_zod2.z.boolean(),
2722
- import_zod2.z.null(),
2723
- import_zod2.z.array(JsonValueSchema),
2724
- import_zod2.z.record(import_zod2.z.string(), JsonValueSchema)
2724
+ var import_zod3 = require("zod");
2725
+ var JsonValueSchema = import_zod3.z.lazy(
2726
+ () => import_zod3.z.union([
2727
+ import_zod3.z.string(),
2728
+ import_zod3.z.number(),
2729
+ import_zod3.z.boolean(),
2730
+ import_zod3.z.null(),
2731
+ import_zod3.z.array(JsonValueSchema),
2732
+ import_zod3.z.record(import_zod3.z.string(), JsonValueSchema)
2725
2733
  ])
2726
2734
  );
2727
- var JsonObjectSchema = import_zod2.z.record(import_zod2.z.string(), JsonValueSchema);
2735
+ var JsonObjectSchema = import_zod3.z.record(import_zod3.z.string(), JsonValueSchema);
2728
2736
  async function readErrorBody(res) {
2729
2737
  const text2 = await res.text().catch(() => "");
2730
2738
  try {
@@ -2733,11 +2741,11 @@ async function readErrorBody(res) {
2733
2741
  return text2;
2734
2742
  }
2735
2743
  }
2736
- var thrownErrorSchema = import_zod2.z.object({
2737
- message: import_zod2.z.string().optional(),
2738
- status: import_zod2.z.number().optional(),
2739
- statusCode: import_zod2.z.number().optional(),
2740
- responseBody: import_zod2.z.string().optional()
2744
+ var thrownErrorSchema = import_zod3.z.object({
2745
+ message: import_zod3.z.string().optional(),
2746
+ status: import_zod3.z.number().optional(),
2747
+ statusCode: import_zod3.z.number().optional(),
2748
+ responseBody: import_zod3.z.string().optional()
2741
2749
  });
2742
2750
  function describeThrown(cause) {
2743
2751
  const parsed = thrownErrorSchema.safeParse(cause);
@@ -2748,7 +2756,7 @@ function describeThrown(cause) {
2748
2756
  }
2749
2757
 
2750
2758
  // src/retry.ts
2751
- var textBody = import_zod3.z.string();
2759
+ var textBody = import_zod4.z.string();
2752
2760
  function classifyHttpError(status, body, provider, model) {
2753
2761
  const asText = textBody.safeParse(body);
2754
2762
  const text2 = asText.success ? asText.data : JSON.stringify(body);
@@ -2805,12 +2813,12 @@ function sleep(ms, signal) {
2805
2813
  rejectAborted();
2806
2814
  return;
2807
2815
  }
2808
- let timer2;
2816
+ let timer;
2809
2817
  const onAbort = () => {
2810
- if (timer2 !== void 0) clearTimeout(timer2);
2818
+ if (timer !== void 0) clearTimeout(timer);
2811
2819
  rejectAborted();
2812
2820
  };
2813
- timer2 = setTimeout(() => {
2821
+ timer = setTimeout(() => {
2814
2822
  signal?.removeEventListener("abort", onAbort);
2815
2823
  resolve();
2816
2824
  }, ms);
@@ -2956,7 +2964,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
2956
2964
 
2957
2965
  // src/client.ts
2958
2966
  var import_ai2 = require("ai");
2959
- var import_zod5 = require("zod");
2967
+ var import_zod6 = require("zod");
2960
2968
 
2961
2969
  // src/adapters/media-ref.ts
2962
2970
  function isUrlRef(ref) {
@@ -3041,7 +3049,7 @@ var import_perplexity = require("@ai-sdk/perplexity");
3041
3049
  var import_xai = require("@ai-sdk/xai");
3042
3050
  var import_deepseek = require("@ai-sdk/deepseek");
3043
3051
  var import_moonshotai = require("@ai-sdk/moonshotai");
3044
- var import_zod4 = require("zod");
3052
+ var import_zod5 = require("zod");
3045
3053
  var TEXT_PROVIDERS = [
3046
3054
  "openai",
3047
3055
  "anthropic",
@@ -3052,7 +3060,7 @@ var TEXT_PROVIDERS = [
3052
3060
  "moonshot",
3053
3061
  "minimax"
3054
3062
  ];
3055
- var textProviderSchema = import_zod4.z.enum(TEXT_PROVIDERS);
3063
+ var textProviderSchema = import_zod5.z.enum(TEXT_PROVIDERS);
3056
3064
  function isTextProvider(value) {
3057
3065
  return textProviderSchema.safeParse(value).success;
3058
3066
  }
@@ -3222,10 +3230,10 @@ function textAbortOptions(sdk, context) {
3222
3230
  if (abortSignal) return { abortSignal };
3223
3231
  return {};
3224
3232
  }
3225
- var catalogId = import_zod5.z.string();
3226
- var exactSize = import_zod5.z.templateLiteral([import_zod5.z.number(), "x", import_zod5.z.number()]);
3227
- var sdkRatio = import_zod5.z.templateLiteral([import_zod5.z.number(), ":", import_zod5.z.number()]);
3228
- var sizeTier = import_zod5.z.enum(["512", "1K", "2K", "4K"]);
3233
+ var catalogId = import_zod6.z.string();
3234
+ var exactSize = import_zod6.z.templateLiteral([import_zod6.z.number(), "x", import_zod6.z.number()]);
3235
+ var sdkRatio = import_zod6.z.templateLiteral([import_zod6.z.number(), ":", import_zod6.z.number()]);
3236
+ var sizeTier = import_zod6.z.enum(["512", "1K", "2K", "4K"]);
3229
3237
  function isCatalogId(model) {
3230
3238
  return catalogId.safeParse(model).success;
3231
3239
  }
@@ -3746,7 +3754,7 @@ function createModelKit(config, adapters) {
3746
3754
  }
3747
3755
 
3748
3756
  // src/adapters/ark.ts
3749
- var import_zod6 = require("zod");
3757
+ var import_zod7 = require("zod");
3750
3758
  var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
3751
3759
  var SUBMIT_PATH = "/contents/generations/tasks";
3752
3760
  var SEEDANCE_POLL_INTERVAL_MS = 15e3;
@@ -3823,7 +3831,7 @@ function arkKey(ctx) {
3823
3831
  return key;
3824
3832
  }
3825
3833
  function throwArkError(status, body, model) {
3826
- const parsed = import_zod6.z.string().safeParse(body);
3834
+ const parsed = import_zod7.z.string().safeParse(body);
3827
3835
  const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
3828
3836
  if (/sensitive.?content|human.?face/i.test(text2)) {
3829
3837
  const init = {
@@ -3861,13 +3869,13 @@ function sniffedImageMime(bytes) {
3861
3869
  return "image/webp";
3862
3870
  return "image/jpeg";
3863
3871
  }
3864
- var SeedreamImageSchema = import_zod6.z.object({
3865
- url: import_zod6.z.string().optional(),
3866
- b64_json: import_zod6.z.string().optional()
3872
+ var SeedreamImageSchema = import_zod7.z.object({
3873
+ url: import_zod7.z.string().optional(),
3874
+ b64_json: import_zod7.z.string().optional()
3867
3875
  });
3868
- var SeedreamResponseSchema = import_zod6.z.object({
3869
- data: import_zod6.z.array(SeedreamImageSchema).optional(),
3870
- error: import_zod6.z.object({ message: import_zod6.z.string().optional(), code: import_zod6.z.string().optional() }).optional()
3876
+ var SeedreamResponseSchema = import_zod7.z.object({
3877
+ data: import_zod7.z.array(SeedreamImageSchema).optional(),
3878
+ error: import_zod7.z.object({ message: import_zod7.z.string().optional(), code: import_zod7.z.string().optional() }).optional()
3871
3879
  });
3872
3880
  function retryOptsFor(ctx, attempts = 3) {
3873
3881
  const opts = { attempts };
@@ -3896,6 +3904,18 @@ async function generateSeedreamImage(req, ctx) {
3896
3904
  watermark: false
3897
3905
  };
3898
3906
  if (req.seed !== void 0) body.seed = req.seed;
3907
+ if (req.outputFormat !== void 0) {
3908
+ if (req.outputFormat === "webp") {
3909
+ ctx.warnings.push({
3910
+ code: "option_ignored",
3911
+ field: "outputFormat",
3912
+ from: "webp",
3913
+ to: "png",
3914
+ message: `${modelId} accepts png or jpeg output; using png`
3915
+ });
3916
+ }
3917
+ body.output_format = req.outputFormat === "jpeg" ? "jpeg" : "png";
3918
+ }
3899
3919
  const firstRef = refs[0];
3900
3920
  if (refs.length === 1 && firstRef !== void 0) body.image = firstRef;
3901
3921
  else if (refs.length > 1) body.image = refs;
@@ -3939,21 +3959,21 @@ async function generateSeedreamImage(req, ctx) {
3939
3959
  if (req.quality !== void 0) usage2.imageQuality = req.quality;
3940
3960
  return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
3941
3961
  }
3942
- var SeedanceUsageSchema = import_zod6.z.object({
3943
- total_tokens: import_zod6.z.number().optional(),
3944
- completion_tokens: import_zod6.z.number().optional()
3962
+ var SeedanceUsageSchema = import_zod7.z.object({
3963
+ total_tokens: import_zod7.z.number().optional(),
3964
+ completion_tokens: import_zod7.z.number().optional()
3945
3965
  });
3946
- var SeedanceResponseSchema = import_zod6.z.object({
3947
- id: import_zod6.z.string().optional(),
3948
- status: import_zod6.z.string().optional(),
3949
- content: import_zod6.z.object({ video_url: import_zod6.z.string().optional() }).optional(),
3966
+ var SeedanceResponseSchema = import_zod7.z.object({
3967
+ id: import_zod7.z.string().optional(),
3968
+ status: import_zod7.z.string().optional(),
3969
+ content: import_zod7.z.object({ video_url: import_zod7.z.string().optional() }).optional(),
3950
3970
  usage: SeedanceUsageSchema.optional(),
3951
- duration: import_zod6.z.number().optional(),
3952
- framespersecond: import_zod6.z.number().optional(),
3953
- resolution: import_zod6.z.string().optional(),
3954
- error: import_zod6.z.union([import_zod6.z.string(), import_zod6.z.object({ message: import_zod6.z.string().optional() })]).optional()
3971
+ duration: import_zod7.z.number().optional(),
3972
+ framespersecond: import_zod7.z.number().optional(),
3973
+ resolution: import_zod7.z.string().optional(),
3974
+ error: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.object({ message: import_zod7.z.string().optional() })]).optional()
3955
3975
  });
3956
- var SeedanceErrorMessageSchema = import_zod6.z.object({ message: import_zod6.z.string().optional() });
3976
+ var SeedanceErrorMessageSchema = import_zod7.z.object({ message: import_zod7.z.string().optional() });
3957
3977
  function seedanceUsage(ctx, req, duration) {
3958
3978
  const usage2 = {
3959
3979
  model: ctx.model.id,
@@ -3967,7 +3987,7 @@ function seedanceUsage(ctx, req, duration) {
3967
3987
  return usage2;
3968
3988
  }
3969
3989
  function seedanceErrorMessage(error, status) {
3970
- const asString = import_zod6.z.string().safeParse(error);
3990
+ const asString = import_zod7.z.string().safeParse(error);
3971
3991
  if (asString.success) return asString.data;
3972
3992
  const asObject = SeedanceErrorMessageSchema.safeParse(error);
3973
3993
  if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
@@ -4116,7 +4136,7 @@ async function generateSeedanceVideo(req, ctx) {
4116
4136
  }
4117
4137
 
4118
4138
  // src/adapters/fal.ts
4119
- var import_zod7 = require("zod");
4139
+ var import_zod8 = require("zod");
4120
4140
  var import_client = require("@fal-ai/client");
4121
4141
  var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
4122
4142
  var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
@@ -4124,7 +4144,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
4124
4144
  var FAL_QUEUE_HOST = "https://queue.fal.run";
4125
4145
  var PASSTHROUGH_POLL_MS = 2e3;
4126
4146
  var PASSTHROUGH_MAX_WAIT_MS = 18e4;
4127
- var falSubscribePayloadSchema = import_zod7.z.object({ data: JsonValueSchema });
4147
+ var falSubscribePayloadSchema = import_zod8.z.object({ data: JsonValueSchema });
4128
4148
  function defaultCreateFalClient(opts) {
4129
4149
  const client2 = (0, import_client.createFalClient)(opts);
4130
4150
  return {
@@ -4174,7 +4194,7 @@ function createFalAdapter(deps = defaultDeps) {
4174
4194
  };
4175
4195
  }
4176
4196
  var falAdapter = createFalAdapter();
4177
- var falDetailSchema = import_zod7.z.object({ detail: JsonValueSchema });
4197
+ var falDetailSchema = import_zod8.z.object({ detail: JsonValueSchema });
4178
4198
  function liftDetail(body) {
4179
4199
  const parsed = falDetailSchema.safeParse(body);
4180
4200
  const detail = parsed.success ? parsed.data.detail : void 0;
@@ -4183,11 +4203,11 @@ function liftDetail(body) {
4183
4203
  function falError(status, body, model) {
4184
4204
  return classifyHttpError(status, liftDetail(body), "fal", model);
4185
4205
  }
4186
- var falSdkThrownSchema = import_zod7.z.object({
4187
- status: import_zod7.z.number().optional(),
4188
- statusCode: import_zod7.z.number().optional(),
4206
+ var falSdkThrownSchema = import_zod8.z.object({
4207
+ status: import_zod8.z.number().optional(),
4208
+ statusCode: import_zod8.z.number().optional(),
4189
4209
  body: JsonValueSchema.optional(),
4190
- message: import_zod7.z.string().optional()
4210
+ message: import_zod8.z.string().optional()
4191
4211
  });
4192
4212
  function falSdkError(cause, model) {
4193
4213
  const parsed = falSdkThrownSchema.safeParse(cause);
@@ -4231,12 +4251,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
4231
4251
  if (init.body !== void 0) request.body = init.body;
4232
4252
  return fetchImpl(cfg.baseUrl, request);
4233
4253
  }
4234
- var falQueueSubmitSchema = import_zod7.z.object({
4235
- request_id: import_zod7.z.string(),
4236
- status_url: import_zod7.z.string(),
4237
- response_url: import_zod7.z.string()
4254
+ var falQueueSubmitSchema = import_zod8.z.object({
4255
+ request_id: import_zod8.z.string(),
4256
+ status_url: import_zod8.z.string(),
4257
+ response_url: import_zod8.z.string()
4238
4258
  });
4239
- var falQueueStatusSchema = import_zod7.z.object({ status: import_zod7.z.string() });
4259
+ var falQueueStatusSchema = import_zod8.z.object({ status: import_zod8.z.string() });
4240
4260
  async function passthroughRequest(ctx, endpoint, input) {
4241
4261
  const cfg = gatewayConfig(ctx);
4242
4262
  const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
@@ -4362,11 +4382,11 @@ async function decodeImage(ctx, url, contentType) {
4362
4382
  const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
4363
4383
  return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
4364
4384
  }
4365
- var museImageResultSchema = import_zod7.z.object({
4366
- images: import_zod7.z.array(
4367
- import_zod7.z.object({
4368
- url: import_zod7.z.string().optional(),
4369
- content_type: import_zod7.z.string().nullable().optional()
4385
+ var museImageResultSchema = import_zod8.z.object({
4386
+ images: import_zod8.z.array(
4387
+ import_zod8.z.object({
4388
+ url: import_zod8.z.string().optional(),
4389
+ content_type: import_zod8.z.string().nullable().optional()
4370
4390
  })
4371
4391
  ).optional()
4372
4392
  });
@@ -4458,8 +4478,8 @@ function klingO1Input(req) {
4458
4478
  if (refs.length > 0) input.image_urls = refs;
4459
4479
  return input;
4460
4480
  }
4461
- var falVideoResultSchema = import_zod7.z.object({
4462
- video: import_zod7.z.object({ url: import_zod7.z.string().optional() }).optional()
4481
+ var falVideoResultSchema = import_zod8.z.object({
4482
+ video: import_zod8.z.object({ url: import_zod8.z.string().optional() }).optional()
4463
4483
  });
4464
4484
  function extractVideoUrl(result, endpoint, model) {
4465
4485
  const parsed = falVideoResultSchema.safeParse(result);
@@ -4649,11 +4669,11 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
4649
4669
  }
4650
4670
 
4651
4671
  // src/adapters/google-genai.ts
4652
- var import_zod9 = require("zod");
4672
+ var import_zod10 = require("zod");
4653
4673
  var import_genai = require("@google/genai");
4654
4674
 
4655
4675
  // src/adapters/google-files.ts
4656
- var import_zod8 = require("zod");
4676
+ var import_zod9 = require("zod");
4657
4677
  var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
4658
4678
  var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
4659
4679
  var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
@@ -4663,17 +4683,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
4663
4683
  "binary/octet-stream",
4664
4684
  "application/binary"
4665
4685
  ]);
4666
- var uploadedFileSchema = import_zod8.z.object({
4667
- file: import_zod8.z.object({
4668
- uri: import_zod8.z.string().optional(),
4669
- name: import_zod8.z.string().optional(),
4670
- state: import_zod8.z.string().optional(),
4671
- mimeType: import_zod8.z.string().optional()
4686
+ var uploadedFileSchema = import_zod9.z.object({
4687
+ file: import_zod9.z.object({
4688
+ uri: import_zod9.z.string().optional(),
4689
+ name: import_zod9.z.string().optional(),
4690
+ state: import_zod9.z.string().optional(),
4691
+ mimeType: import_zod9.z.string().optional()
4672
4692
  }).optional()
4673
4693
  });
4674
- var fileStateSchema = import_zod8.z.object({
4675
- state: import_zod8.z.string().optional(),
4676
- error: import_zod8.z.object({ message: import_zod8.z.string().optional() }).optional()
4694
+ var fileStateSchema = import_zod9.z.object({
4695
+ state: import_zod9.z.string().optional(),
4696
+ error: import_zod9.z.object({ message: import_zod9.z.string().optional() }).optional()
4677
4697
  });
4678
4698
  function resolveMime(declared, fallback) {
4679
4699
  const clean = declared?.split(";")[0]?.trim().toLowerCase();
@@ -4886,7 +4906,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
4886
4906
  var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
4887
4907
  var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
4888
4908
  var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
4889
- var errorTextSchema = import_zod9.z.string();
4909
+ var errorTextSchema = import_zod10.z.string();
4890
4910
  function createGoogleGenaiAdapter(deps = defaultDeps2) {
4891
4911
  const { createGenAIClient } = deps;
4892
4912
  return {
@@ -5039,6 +5059,7 @@ async function generateVeoVideo(req, ctx, createGenAIClient) {
5039
5059
  const config = { durationSeconds: duration, personGeneration };
5040
5060
  if (req.aspectRatio !== void 0) config.aspectRatio = req.aspectRatio;
5041
5061
  if (req.resolution !== void 0) config.resolution = req.resolution;
5062
+ if (req.seed !== void 0) config.seed = req.seed;
5042
5063
  if (lastFrame !== void 0) config.lastFrame = lastFrame;
5043
5064
  if (referenceImages !== void 0) config.referenceImages = referenceImages;
5044
5065
  const requestBody = {
@@ -5444,15 +5465,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
5444
5465
  // src/adapters/google-image.ts
5445
5466
  var import_google2 = require("@ai-sdk/google");
5446
5467
  var import_ai3 = require("ai");
5447
- var import_zod10 = require("zod");
5468
+ var import_zod11 = require("zod");
5448
5469
  var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
5449
5470
  var defaultGoogleImageDeps = {
5450
5471
  createGoogleClient: (opts) => (0, import_google2.createGoogleGenerativeAI)(opts),
5451
5472
  runTextGeneration: (opts) => (0, import_ai3.generateText)(opts)
5452
5473
  };
5453
- var causeChainNodeSchema = import_zod10.z.object({
5454
- message: import_zod10.z.string().optional(),
5455
- cause: import_zod10.z.unknown().optional()
5474
+ var causeChainNodeSchema = import_zod11.z.object({
5475
+ message: import_zod11.z.string().optional(),
5476
+ cause: import_zod11.z.unknown().optional()
5456
5477
  });
5457
5478
  function extractBlockReason(cause) {
5458
5479
  let current = cause;
@@ -5573,7 +5594,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
5573
5594
  var googleImageAdapter = createGoogleImageAdapter();
5574
5595
 
5575
5596
  // src/adapters/higgsfield.ts
5576
- var import_zod11 = require("zod");
5597
+ var import_zod12 = require("zod");
5577
5598
 
5578
5599
  // src/adapters/higgsfield-motions.ts
5579
5600
  var MOTION_MAP = {
@@ -5761,14 +5782,14 @@ function videoUsage3(ctx, req, duration) {
5761
5782
  if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
5762
5783
  return event;
5763
5784
  }
5764
- var klingCreateSchema = import_zod11.z.object({ status_url: import_zod11.z.string() });
5765
- var klingStatusSchema = import_zod11.z.object({
5766
- status: import_zod11.z.string().optional(),
5767
- video: import_zod11.z.object({ url: import_zod11.z.string().optional() }).optional(),
5785
+ var klingCreateSchema = import_zod12.z.object({ status_url: import_zod12.z.string() });
5786
+ var klingStatusSchema = import_zod12.z.object({
5787
+ status: import_zod12.z.string().optional(),
5788
+ video: import_zod12.z.object({ url: import_zod12.z.string().optional() }).optional(),
5768
5789
  error: JsonValueSchema.optional()
5769
5790
  });
5770
- var errorMessageSchema = import_zod11.z.object({ message: import_zod11.z.string().optional() });
5771
- var textValueSchema = import_zod11.z.string();
5791
+ var errorMessageSchema = import_zod12.z.object({ message: import_zod12.z.string().optional() });
5792
+ var textValueSchema = import_zod12.z.string();
5772
5793
  function klingErrorDetail(error) {
5773
5794
  if (error === void 0) return "unknown_error";
5774
5795
  const asText = textValueSchema.safeParse(error);
@@ -5902,8 +5923,8 @@ async function generateKlingVideo(req, ctx) {
5902
5923
  }
5903
5924
  };
5904
5925
  }
5905
- var dopMotionOptionsSchema = import_zod11.z.object({
5906
- modelkit: import_zod11.z.object({ motion: import_zod11.z.string().optional() }).optional()
5926
+ var dopMotionOptionsSchema = import_zod12.z.object({
5927
+ modelkit: import_zod12.z.object({ motion: import_zod12.z.string().optional() }).optional()
5907
5928
  });
5908
5929
  function dopMotionId(ctx) {
5909
5930
  const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
@@ -5919,7 +5940,7 @@ function dopMotionId(ctx) {
5919
5940
  });
5920
5941
  return id;
5921
5942
  }
5922
- var jsonRecordSchema = import_zod11.z.record(import_zod11.z.string(), JsonValueSchema);
5943
+ var jsonRecordSchema = import_zod12.z.record(import_zod12.z.string(), JsonValueSchema);
5923
5944
  var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
5924
5945
  var DOP_NESTED_KEYS = ["video", "result", "results"];
5925
5946
  function dopUrl(body) {
@@ -5947,8 +5968,8 @@ function dopUrl(body) {
5947
5968
  }
5948
5969
  return void 0;
5949
5970
  }
5950
- var dopCreateSchema = import_zod11.z.object({ id: import_zod11.z.string() });
5951
- var dopStatusSchema = import_zod11.z.object({ status: import_zod11.z.string().optional() });
5971
+ var dopCreateSchema = import_zod12.z.object({ id: import_zod12.z.string() });
5972
+ var dopStatusSchema = import_zod12.z.object({ status: import_zod12.z.string().optional() });
5952
5973
  async function generateDopVideo(req, ctx) {
5953
5974
  const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
5954
5975
  if (!firstFrame) {
@@ -6068,7 +6089,7 @@ var higgsfieldAdapter = {
6068
6089
 
6069
6090
  // src/adapters/openai-image.ts
6070
6091
  var import_openai2 = __toESM(require("openai"), 1);
6071
- var import_zod12 = require("zod");
6092
+ var import_zod13 = require("zod");
6072
6093
  var MAX_EDIT_REFERENCES = 16;
6073
6094
  function aspectRatioToSize(ratio, tier) {
6074
6095
  const TIER_LONG_EDGE = {
@@ -6151,9 +6172,9 @@ function toProviderError2(cause, ctx) {
6151
6172
  ctx.model.id
6152
6173
  );
6153
6174
  }
6154
- var openaiUsageSchema = import_zod12.z.object({
6155
- input_tokens: import_zod12.z.number().optional(),
6156
- output_tokens: import_zod12.z.number().optional()
6175
+ var openaiUsageSchema = import_zod13.z.object({
6176
+ input_tokens: import_zod13.z.number().optional(),
6177
+ output_tokens: import_zod13.z.number().optional()
6157
6178
  });
6158
6179
  var openaiImageAdapter = {
6159
6180
  id: "openai-image",
@@ -6182,6 +6203,19 @@ var openaiImageAdapter = {
6182
6203
  const quality = req.quality ?? (isEdit ? "medium" : "auto");
6183
6204
  const sdkQuality = quality;
6184
6205
  const count = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
6206
+ let outputFormat = req.outputFormat;
6207
+ if (outputFormat === "webp") {
6208
+ ctx.warnings.push({
6209
+ code: "option_ignored",
6210
+ field: "outputFormat",
6211
+ from: "webp",
6212
+ to: "png",
6213
+ message: `${ctx.model.id} returns PNG for output_format webp; using png`
6214
+ });
6215
+ outputFormat = "png";
6216
+ }
6217
+ const format = outputFormat !== void 0 ? { output_format: outputFormat } : {};
6218
+ const mime = outputFormat === "jpeg" ? "image/jpeg" : "image/png";
6185
6219
  const retryOptions = {};
6186
6220
  if (ctx.signal !== void 0) retryOptions.signal = ctx.signal;
6187
6221
  const response = await withRetry(async () => {
@@ -6194,7 +6228,8 @@ var openaiImageAdapter = {
6194
6228
  prompt: req.prompt,
6195
6229
  size,
6196
6230
  quality: sdkQuality,
6197
- ...count
6231
+ ...count,
6232
+ ...format
6198
6233
  },
6199
6234
  { signal: ctx.signal }
6200
6235
  );
@@ -6204,20 +6239,21 @@ var openaiImageAdapter = {
6204
6239
  model: ctx.model.providerModelId,
6205
6240
  prompt: req.prompt,
6206
6241
  quality: sdkQuality,
6207
- ...count
6242
+ ...count,
6243
+ ...format
6208
6244
  },
6209
6245
  { signal: ctx.signal }
6210
6246
  );
6211
6247
  }
6212
6248
  const files = await Promise.all(
6213
6249
  refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
6214
- const { bytes, mime } = await mediaRefToBytes(ref, ctx.fetch, {
6250
+ const { bytes, mime: mime2 } = await mediaRefToBytes(ref, ctx.fetch, {
6215
6251
  signal: ctx.signal,
6216
6252
  provider: "openai-image",
6217
6253
  model: ctx.model.id
6218
6254
  });
6219
- const ext = mime.includes("jpeg") ? "jpg" : mime.includes("webp") ? "webp" : "png";
6220
- return new File([bytes], `ref-${i}.${ext}`, { type: mime });
6255
+ const ext = mime2.includes("jpeg") ? "jpg" : mime2.includes("webp") ? "webp" : "png";
6256
+ return new File([bytes], `ref-${i}.${ext}`, { type: mime2 });
6221
6257
  })
6222
6258
  );
6223
6259
  const single = files.length === 1 ? files[0] : void 0;
@@ -6230,7 +6266,8 @@ var openaiImageAdapter = {
6230
6266
  prompt: req.prompt,
6231
6267
  size,
6232
6268
  quality: sdkQuality,
6233
- ...count
6269
+ ...count,
6270
+ ...format
6234
6271
  },
6235
6272
  { signal: ctx.signal }
6236
6273
  );
@@ -6241,7 +6278,8 @@ var openaiImageAdapter = {
6241
6278
  image: imageInput,
6242
6279
  prompt: req.prompt,
6243
6280
  quality: sdkQuality,
6244
- ...count
6281
+ ...count,
6282
+ ...format
6245
6283
  },
6246
6284
  { signal: ctx.signal }
6247
6285
  );
@@ -6250,7 +6288,7 @@ var openaiImageAdapter = {
6250
6288
  }
6251
6289
  }, retryOptions);
6252
6290
  const images = (response.data ?? []).flatMap(
6253
- (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime: "image/png" }] : []
6291
+ (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime }] : []
6254
6292
  );
6255
6293
  if (images.length === 0)
6256
6294
  throw classifyHttpError(
@@ -6543,7 +6581,7 @@ var prodiaAdapter = {
6543
6581
 
6544
6582
  // src/adapters/replicate.ts
6545
6583
  var import_replicate = __toESM(require("replicate"), 1);
6546
- var import_zod13 = require("zod");
6584
+ var import_zod14 = require("zod");
6547
6585
  var POLL_INTERVAL_MS = 1e3;
6548
6586
  var POLL_TIMEOUT_MS = 15 * 6e4;
6549
6587
  var defaultReplicateDeps = {
@@ -6579,8 +6617,8 @@ function route(providerModelId) {
6579
6617
  if (!providerModelId.includes("/")) return { version: providerModelId };
6580
6618
  return { model: providerModelId };
6581
6619
  }
6582
- var replicateResponseStatusSchema = import_zod13.z.object({
6583
- response: import_zod13.z.object({ status: import_zod13.z.number() }).partial()
6620
+ var replicateResponseStatusSchema = import_zod14.z.object({
6621
+ response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
6584
6622
  });
6585
6623
  function replicateError(cause, ctx) {
6586
6624
  if (isModelKitError(cause)) return cause;
@@ -6607,7 +6645,7 @@ function isUrlFn(value) {
6607
6645
  function extractOutputUrl(output) {
6608
6646
  const root = Array.isArray(output) ? output[0] : output;
6609
6647
  if (root === void 0) throw noOutput();
6610
- const asString = import_zod13.z.string().safeParse(root);
6648
+ const asString = import_zod14.z.string().safeParse(root);
6611
6649
  if (asString.success && asString.data) return asString.data;
6612
6650
  if (root instanceof URL) return root.href;
6613
6651
  if (isObjectOutput(root)) {
@@ -6616,15 +6654,15 @@ function extractOutputUrl(output) {
6616
6654
  if (urlValue !== void 0 && isUrlFn(urlValue)) {
6617
6655
  const called = urlValue();
6618
6656
  if (called instanceof URL) return called.href;
6619
- const calledString = import_zod13.z.string().safeParse(called);
6657
+ const calledString = import_zod14.z.string().safeParse(called);
6620
6658
  if (calledString.success && calledString.data) return calledString.data;
6621
6659
  } else {
6622
- const direct = import_zod13.z.string().safeParse(urlValue);
6660
+ const direct = import_zod14.z.string().safeParse(urlValue);
6623
6661
  if (direct.success && direct.data) return direct.data;
6624
6662
  }
6625
6663
  }
6626
6664
  if ("default" in root) {
6627
- const fallback = import_zod13.z.string().safeParse(root.default);
6665
+ const fallback = import_zod14.z.string().safeParse(root.default);
6628
6666
  if (fallback.success && fallback.data) return fallback.data;
6629
6667
  }
6630
6668
  }
@@ -6685,7 +6723,7 @@ async function runPrediction(ctx, input, deps) {
6685
6723
  }
6686
6724
  return void 0;
6687
6725
  }, pollOpts);
6688
- const predictTime = import_zod13.z.number().safeParse(done.metrics?.predict_time);
6726
+ const predictTime = import_zod14.z.number().safeParse(done.metrics?.predict_time);
6689
6727
  if (done.output === void 0) throw noOutput();
6690
6728
  return {
6691
6729
  url: extractOutputUrl(done.output),
@@ -7028,7 +7066,7 @@ async function generateReplicateVideo(req, ctx, deps) {
7028
7066
  throw replicateError(cause, ctx);
7029
7067
  }
7030
7068
  if (current.status === "succeeded") {
7031
- const predictTime = import_zod13.z.number().safeParse(current.metrics?.predict_time);
7069
+ const predictTime = import_zod14.z.number().safeParse(current.metrics?.predict_time);
7032
7070
  if (current.output === void 0) throw noOutput();
7033
7071
  return {
7034
7072
  url: extractOutputUrl(current.output),
@@ -7160,7 +7198,7 @@ async function generateReplicateAudio(req, ctx, deps) {
7160
7198
  // src/adapters/xai-video.ts
7161
7199
  var import_ai4 = require("ai");
7162
7200
  var import_xai2 = require("@ai-sdk/xai");
7163
- var import_zod14 = require("zod");
7201
+ var import_zod15 = require("zod");
7164
7202
  var POLL_INTERVAL_MS2 = 1e4;
7165
7203
  var POLL_TIMEOUT_MS2 = 15 * 6e4;
7166
7204
  var defaultXaiDeps = {
@@ -7173,8 +7211,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
7173
7211
  };
7174
7212
  }
7175
7213
  var xaiVideoAdapter = createXaiVideoAdapter();
7176
- var xaiResponseStatusSchema = import_zod14.z.object({
7177
- response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
7214
+ var xaiResponseStatusSchema = import_zod15.z.object({
7215
+ response: import_zod15.z.object({ status: import_zod15.z.number() }).partial()
7178
7216
  });
7179
7217
  function xaiError(cause, ctx) {
7180
7218
  const info = describeThrown(cause);
@@ -7182,12 +7220,12 @@ function xaiError(cause, ctx) {
7182
7220
  const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
7183
7221
  return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
7184
7222
  }
7185
- var xaiMetaSchema = import_zod14.z.object({
7223
+ var xaiMetaSchema = import_zod15.z.object({
7186
7224
  videoUrl: JsonValueSchema.optional(),
7187
7225
  costInUsdTicks: JsonValueSchema.optional(),
7188
7226
  duration: JsonValueSchema.optional()
7189
7227
  });
7190
- var xaiProviderMetadataSchema = import_zod14.z.object({ xai: xaiMetaSchema });
7228
+ var xaiProviderMetadataSchema = import_zod15.z.object({ xai: xaiMetaSchema });
7191
7229
  function metaOf(result) {
7192
7230
  const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
7193
7231
  if (!parsed.success) return {};
@@ -7294,7 +7332,7 @@ async function mapResult(ctx, req, result) {
7294
7332
  };
7295
7333
  }
7296
7334
  const meta = metaOf(result);
7297
- const videoUrl = import_zod14.z.string().safeParse(meta.videoUrl);
7335
+ const videoUrl = import_zod15.z.string().safeParse(meta.videoUrl);
7298
7336
  if (videoUrl.success && videoUrl.data) {
7299
7337
  const res = await ctx.fetch(videoUrl.data);
7300
7338
  if (!res.ok) {
@@ -7317,7 +7355,7 @@ async function mapResult(ctx, req, result) {
7317
7355
  });
7318
7356
  }
7319
7357
  function usage(ctx, req, meta) {
7320
- const costTicks = import_zod14.z.number().safeParse(meta.costInUsdTicks);
7358
+ const costTicks = import_zod15.z.number().safeParse(meta.costInUsdTicks);
7321
7359
  const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
7322
7360
  const event = {
7323
7361
  model: ctx.model.id,
@@ -7399,6 +7437,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
7399
7437
  keysFromEnv,
7400
7438
  languageModel,
7401
7439
  liveCatalog,
7440
+ liveState,
7402
7441
  mergeTextProviderOptions,
7403
7442
  nearestAspectRatio,
7404
7443
  openaiImageAdapter,