@shop-os/modelkit 0.2.0 → 0.2.2

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,7 @@ 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) {
215
216
  const model = {
216
217
  id,
217
218
  aliases,
@@ -224,7 +225,8 @@ function geminiImage(id, label, aliases, sizes, display, exposure) {
224
225
  constraints: {
225
226
  aspectRatios: [...GEMINI_RATIOS],
226
227
  sizes,
227
- supports: ["safetySettings", "temperature"]
228
+ supports: ["safetySettings", "temperature"],
229
+ ...references ? { references } : {}
228
230
  },
229
231
  defaults: { size: "1K", aspectRatio: "1:1" },
230
232
  usage: { ...IMAGE_USAGE, slug: "gemini" },
@@ -244,7 +246,8 @@ var IMAGE_MODELS = [
244
246
  description: "Create stunning, production-quality visuals with exceptional realism, detail, and typography. Best for campaigns, e-commerce, product photography, and hero creatives.",
245
247
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
246
248
  },
247
- "catalog"
249
+ "catalog",
250
+ { images: 14 }
248
251
  ),
249
252
  geminiImage(
250
253
  "gemini-3.1-flash-image-preview",
@@ -257,7 +260,8 @@ var IMAGE_MODELS = [
257
260
  description: "Generate high-quality images at speed. Perfect for brainstorming, moodboards, concept testing, creative exploration, and large batch workflows.",
258
261
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
259
262
  },
260
- "catalog"
263
+ "catalog",
264
+ { images: 14 }
261
265
  ),
262
266
  geminiImage(
263
267
  "gemini-3.1-flash-lite-image",
@@ -269,14 +273,15 @@ var IMAGE_MODELS = [
269
273
  description: "The fastest and most affordable image model. Ideal for rapid drafts, bulk exploration, and iterative concept testing at 1K resolution.",
270
274
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
271
275
  },
272
- "catalog"
276
+ "catalog",
277
+ { images: 14 }
273
278
  ),
274
279
  // trigger-workflows validates 1K only; pricing seeds 2K/4K rows so allow all three.
275
280
  geminiImage(
276
281
  "gemini-2.5-flash-image",
277
282
  "Gemini 2.5 Flash Image",
278
283
  [],
279
- ["1K", "2K", "4K"],
284
+ ["1K"],
280
285
  {
281
286
  provider: "google",
282
287
  description: "Nano Banana (legacy Gemini 2.5 Flash Image) native image generation and editing model for high-volume, low-latency creative workflows."
@@ -307,7 +312,7 @@ var IMAGE_MODELS = [
307
312
  sizes: ["1K", "2K", "4K"],
308
313
  qualityOptions: ["auto", "low", "medium", "high"],
309
314
  references: { images: 16 },
310
- supports: ["quality", "count"]
315
+ supports: ["quality", "count", "outputFormat"]
311
316
  },
312
317
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
313
318
  usage: { ...IMAGE_USAGE, slug: "gpt" },
@@ -327,7 +332,7 @@ var IMAGE_MODELS = [
327
332
  adapter: "openai-image",
328
333
  providerModelId: "gpt-image-2.5-sunburst",
329
334
  lifecycle: "active",
330
- exposure: "internal",
335
+ exposure: "catalog",
331
336
  constraints: {
332
337
  exactSizes: {
333
338
  "1:1": "1024x1024",
@@ -340,9 +345,9 @@ var IMAGE_MODELS = [
340
345
  },
341
346
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
342
347
  sizes: ["1K", "2K", "4K"],
343
- qualityOptions: ["auto", "low", "medium", "high"],
348
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
344
349
  references: { images: 16 },
345
- supports: ["quality", "count"]
350
+ supports: ["quality", "count", "outputFormat"]
346
351
  },
347
352
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
348
353
  usage: { ...IMAGE_USAGE },
@@ -361,7 +366,7 @@ var IMAGE_MODELS = [
361
366
  adapter: "openai-image",
362
367
  providerModelId: "gpt-image-2.5-flare",
363
368
  lifecycle: "active",
364
- exposure: "internal",
369
+ exposure: "catalog",
365
370
  constraints: {
366
371
  exactSizes: {
367
372
  "1:1": "1024x1024",
@@ -374,9 +379,9 @@ var IMAGE_MODELS = [
374
379
  },
375
380
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
376
381
  sizes: ["1K", "2K", "4K"],
377
- qualityOptions: ["auto", "low", "medium", "high"],
382
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
378
383
  references: { images: 16 },
379
- supports: ["quality", "count"]
384
+ supports: ["quality", "count", "outputFormat"]
380
385
  },
381
386
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
382
387
  usage: { ...IMAGE_USAGE },
@@ -406,8 +411,6 @@ var IMAGE_MODELS = [
406
411
  "2:3",
407
412
  "3:4",
408
413
  "9:16",
409
- "4:5",
410
- "5:4",
411
414
  "9:21",
412
415
  "adaptive"
413
416
  ],
@@ -439,7 +442,7 @@ var IMAGE_MODELS = [
439
442
  references: { images: 10 },
440
443
  // Ark's Images API has no output-format, quality or count field; only
441
444
  // the seed is forwarded, so anything else must warn, not vanish.
442
- supports: ["seed"]
445
+ supports: ["seed", "outputFormat"]
443
446
  },
444
447
  defaults: { size: "1K", aspectRatio: "1:1" },
445
448
  usage: { ...IMAGE_USAGE },
@@ -475,7 +478,7 @@ var IMAGE_MODELS = [
475
478
  "21:9",
476
479
  "9:21"
477
480
  ],
478
- sizes: ["1K", "2K", "4K"],
481
+ sizes: ["2K", "4K"],
479
482
  references: { images: 10 },
480
483
  supports: ["seed"]
481
484
  },
@@ -527,7 +530,7 @@ var IMAGE_MODELS = [
527
530
  aspectRatios: ["1:1", "2:3", "3:2", "4:3", "3:4", "4:5", "5:4", "9:16", "16:9", "21:9"],
528
531
  sizes: ["1K", "2K", "4K"],
529
532
  requires: ["references"],
530
- supports: ["seed"]
533
+ supports: []
531
534
  },
532
535
  defaults: { size: "1K", aspectRatio: "1:1" },
533
536
  usage: { ...IMAGE_USAGE },
@@ -552,7 +555,7 @@ var IMAGE_MODELS = [
552
555
  aspectRatios: ["1:1", "2:3", "3:4", "4:3", "9:16", "16:9", "21:9"],
553
556
  sizes: ["1K"],
554
557
  requires: ["references"],
555
- supports: ["seed"]
558
+ supports: []
556
559
  },
557
560
  defaults: { size: "1K", aspectRatio: "1:1" },
558
561
  usage: { ...IMAGE_USAGE },
@@ -604,7 +607,6 @@ var IMAGE_MODELS = [
604
607
  aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
605
608
  sizes: [],
606
609
  references: { images: 1 },
607
- requires: ["references"],
608
610
  supports: []
609
611
  },
610
612
  defaults: { aspectRatio: "1:1" },
@@ -1323,7 +1325,7 @@ var VIDEO_MODELS = [
1323
1325
  resolutions: ["720p", "1080p", "4k"],
1324
1326
  durations: [8],
1325
1327
  references: { images: 3 },
1326
- supports: ["lastFrame"]
1328
+ supports: ["lastFrame", "seed"]
1327
1329
  },
1328
1330
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1329
1331
  usage: { ...VIDEO_USAGE, slug: "veo" },
@@ -1351,9 +1353,9 @@ var VIDEO_MODELS = [
1351
1353
  constraints: {
1352
1354
  aspectRatios: [...OMNI_RATIOS],
1353
1355
  resolutions: ["720p", "1080p", "4k"],
1354
- durations: [4, 8],
1356
+ durations: [4, 6, 8],
1355
1357
  references: { images: 3 },
1356
- supports: ["lastFrame"]
1358
+ supports: ["lastFrame", "seed"]
1357
1359
  },
1358
1360
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1359
1361
  usage: { ...VIDEO_USAGE },
@@ -1380,9 +1382,8 @@ var VIDEO_MODELS = [
1380
1382
  constraints: {
1381
1383
  aspectRatios: [...OMNI_RATIOS],
1382
1384
  resolutions: ["720p", "1080p"],
1383
- durations: [4, 8],
1384
- references: { images: 3 },
1385
- supports: ["lastFrame"]
1385
+ durations: [4, 6, 8],
1386
+ supports: ["lastFrame", "seed"]
1386
1387
  },
1387
1388
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1388
1389
  usage: { ...VIDEO_USAGE },
@@ -1414,7 +1415,7 @@ var VIDEO_MODELS = [
1414
1415
  // reference clip keeps its own framing.
1415
1416
  aspectRatios: [...OMNI_RATIOS],
1416
1417
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1417
- references: { images: 6, videos: 1 },
1418
+ references: { images: 6, videos: 3 },
1418
1419
  supports: []
1419
1420
  },
1420
1421
  defaults: {},
@@ -1440,7 +1441,7 @@ var VIDEO_MODELS = [
1440
1441
  aspectRatios: [...OMNI_RATIOS],
1441
1442
  resolutions: ["360p", "720p", "1080p", "4k"],
1442
1443
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1443
- references: { images: 6, videos: 1 },
1444
+ references: { images: 6, videos: 3 },
1444
1445
  supports: []
1445
1446
  },
1446
1447
  defaults: {},
@@ -1469,7 +1470,7 @@ var VIDEO_MODELS = [
1469
1470
  durations: { min: 4, max: 15 },
1470
1471
  durationPresets: [4, 6, 8, 10, 12, 15],
1471
1472
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1472
- ratioIgnoredWith: ["firstFrame"],
1473
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1473
1474
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1474
1475
  },
1475
1476
  defaults: {
@@ -1501,7 +1502,7 @@ var VIDEO_MODELS = [
1501
1502
  resolutions: ["480p", "720p"],
1502
1503
  durations: { min: 4, max: 15 },
1503
1504
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1504
- ratioIgnoredWith: ["firstFrame"],
1505
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1505
1506
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1506
1507
  },
1507
1508
  defaults: {
@@ -1534,7 +1535,7 @@ var VIDEO_MODELS = [
1534
1535
  resolutions: ["480p", "720p", "1080p"],
1535
1536
  durations: { min: 4, max: 30 },
1536
1537
  references: { images: 30, videos: 10, audios: 10 },
1537
- ratioIgnoredWith: ["firstFrame"],
1538
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1538
1539
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1539
1540
  },
1540
1541
  defaults: {
@@ -1653,18 +1654,7 @@ var VIDEO_MODELS = [
1653
1654
  lifecycle: "active",
1654
1655
  exposure: "catalog",
1655
1656
  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
- ],
1657
+ aspectRatios: [...KLING_RATIOS],
1668
1658
  resolutions: ["720p", "1080p"],
1669
1659
  durations: { min: 3, max: 15 },
1670
1660
  references: { images: 7 },
@@ -2126,13 +2116,18 @@ var CatalogSchema = import_zod.z.array(CatalogModelSchemaBase).superRefine((rows
2126
2116
  });
2127
2117
 
2128
2118
  // src/catalog/live.ts
2129
- var liveCatalog = new Catalog(MODELS);
2119
+ var KEY = /* @__PURE__ */ Symbol.for("@shop-os/modelkit/live-catalog");
2120
+ var store = globalThis;
2121
+ var liveState = store[KEY] ??= {
2122
+ catalog: new Catalog(MODELS),
2123
+ memo: void 0,
2124
+ timer: void 0,
2125
+ revision: void 0,
2126
+ origin: "snapshot"
2127
+ };
2128
+ var liveCatalog = liveState.catalog;
2130
2129
 
2131
2130
  // src/catalog/load.ts
2132
- var memo;
2133
- var timer;
2134
- var revision;
2135
- var origin = "snapshot";
2136
2131
  function rowCount() {
2137
2132
  return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
2138
2133
  }
@@ -2162,7 +2157,7 @@ function logPrimed(logger, result) {
2162
2157
  async function fetchRemote(source, logger) {
2163
2158
  const fetchImpl = source.fetch ?? globalThis.fetch;
2164
2159
  const headers2 = authHeaders(source.auth);
2165
- if (revision !== void 0) headers2["If-None-Match"] = `"${revision}"`;
2160
+ if (liveState.revision !== void 0) headers2["If-None-Match"] = `"${liveState.revision}"`;
2166
2161
  const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
2167
2162
  headers: headers2,
2168
2163
  signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
@@ -2186,16 +2181,16 @@ async function prime(source, logger) {
2186
2181
  try {
2187
2182
  const fetched = await fetchRemote(source, logger);
2188
2183
  if ("kept" in fetched) {
2189
- const result2 = { origin, rowCount: rowCount() };
2190
- if (revision !== void 0) result2.revision = revision;
2184
+ const result2 = { origin: liveState.origin, rowCount: rowCount() };
2185
+ if (liveState.revision !== void 0) result2.revision = liveState.revision;
2191
2186
  logPrimed(logger, result2);
2192
2187
  return result2;
2193
2188
  }
2194
2189
  liveCatalog.replace(fetched.rows);
2195
- origin = "remote";
2196
- revision = fetched.revision;
2190
+ liveState.origin = "remote";
2191
+ liveState.revision = fetched.revision;
2197
2192
  await writeCache(source, logger, fetched.rows, fetched.revision);
2198
- const result = { origin, rowCount: rowCount() };
2193
+ const result = { origin: liveState.origin, rowCount: rowCount() };
2199
2194
  if (fetched.revision !== void 0) result.revision = fetched.revision;
2200
2195
  logPrimed(logger, result);
2201
2196
  return result;
@@ -2207,19 +2202,23 @@ async function prime(source, logger) {
2207
2202
  if (!cached) throw new Error("no cached catalog");
2208
2203
  const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
2209
2204
  liveCatalog.replace(rows);
2210
- origin = "last-good";
2211
- revision = rev;
2212
- const result = { origin, rowCount: rowCount(), error };
2205
+ liveState.origin = "last-good";
2206
+ liveState.revision = rev;
2207
+ const result = {
2208
+ origin: liveState.origin,
2209
+ rowCount: rowCount(),
2210
+ error
2211
+ };
2213
2212
  if (rev !== void 0) result.revision = rev;
2214
2213
  logPrimed(logger, result);
2215
2214
  return result;
2216
2215
  } catch (cacheErr) {
2217
2216
  logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2218
2217
  liveCatalog.replace([...MODELS]);
2219
- origin = "snapshot";
2220
- revision = void 0;
2218
+ liveState.origin = "snapshot";
2219
+ liveState.revision = void 0;
2221
2220
  const result = {
2222
- origin,
2221
+ origin: liveState.origin,
2223
2222
  rowCount: rowCount(),
2224
2223
  error
2225
2224
  };
@@ -2233,35 +2232,36 @@ async function refresh(source, logger) {
2233
2232
  const fetched = await fetchRemote(source, logger);
2234
2233
  if ("kept" in fetched) return;
2235
2234
  liveCatalog.replace(fetched.rows);
2236
- origin = "remote";
2237
- revision = fetched.revision;
2235
+ liveState.origin = "remote";
2236
+ liveState.revision = fetched.revision;
2238
2237
  await writeCache(source, logger, fetched.rows, fetched.revision);
2239
2238
  } catch (err) {
2240
2239
  logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2241
2240
  }
2242
2241
  }
2243
2242
  function primeCatalog(source) {
2243
+ const memo = liveState.memo;
2244
2244
  if (memo) return memo;
2245
2245
  const logger = source.logger ?? console;
2246
- memo = prime(source, logger).then((result) => {
2246
+ liveState.memo = prime(source, logger).then((result) => {
2247
2247
  const ttlMs = source.ttlMs ?? 3e5;
2248
- if (ttlMs > 0 && timer === void 0) {
2249
- timer = setInterval(() => void refresh(source, logger), ttlMs);
2250
- const maybeUnref = timer;
2248
+ if (ttlMs > 0 && liveState.timer === void 0) {
2249
+ liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
2250
+ const maybeUnref = liveState.timer;
2251
2251
  maybeUnref.unref?.();
2252
2252
  }
2253
2253
  return result;
2254
2254
  });
2255
- return memo;
2255
+ return liveState.memo;
2256
2256
  }
2257
2257
  function resetLiveCatalog() {
2258
- if (timer !== void 0) {
2259
- clearInterval(timer);
2260
- timer = void 0;
2258
+ if (liveState.timer !== void 0) {
2259
+ clearInterval(liveState.timer);
2260
+ liveState.timer = void 0;
2261
2261
  }
2262
- memo = void 0;
2263
- revision = void 0;
2264
- origin = "snapshot";
2262
+ liveState.memo = void 0;
2263
+ liveState.revision = void 0;
2264
+ liveState.origin = "snapshot";
2265
2265
  liveCatalog.replace([...MODELS]);
2266
2266
  }
2267
2267
 
@@ -2805,12 +2805,12 @@ function sleep(ms, signal) {
2805
2805
  rejectAborted();
2806
2806
  return;
2807
2807
  }
2808
- let timer2;
2808
+ let timer;
2809
2809
  const onAbort = () => {
2810
- if (timer2 !== void 0) clearTimeout(timer2);
2810
+ if (timer !== void 0) clearTimeout(timer);
2811
2811
  rejectAborted();
2812
2812
  };
2813
- timer2 = setTimeout(() => {
2813
+ timer = setTimeout(() => {
2814
2814
  signal?.removeEventListener("abort", onAbort);
2815
2815
  resolve();
2816
2816
  }, ms);
@@ -3896,6 +3896,18 @@ async function generateSeedreamImage(req, ctx) {
3896
3896
  watermark: false
3897
3897
  };
3898
3898
  if (req.seed !== void 0) body.seed = req.seed;
3899
+ if (req.outputFormat !== void 0) {
3900
+ if (req.outputFormat === "webp") {
3901
+ ctx.warnings.push({
3902
+ code: "option_ignored",
3903
+ field: "outputFormat",
3904
+ from: "webp",
3905
+ to: "png",
3906
+ message: `${modelId} accepts png or jpeg output; using png`
3907
+ });
3908
+ }
3909
+ body.output_format = req.outputFormat === "jpeg" ? "jpeg" : "png";
3910
+ }
3899
3911
  const firstRef = refs[0];
3900
3912
  if (refs.length === 1 && firstRef !== void 0) body.image = firstRef;
3901
3913
  else if (refs.length > 1) body.image = refs;
@@ -5039,6 +5051,7 @@ async function generateVeoVideo(req, ctx, createGenAIClient) {
5039
5051
  const config = { durationSeconds: duration, personGeneration };
5040
5052
  if (req.aspectRatio !== void 0) config.aspectRatio = req.aspectRatio;
5041
5053
  if (req.resolution !== void 0) config.resolution = req.resolution;
5054
+ if (req.seed !== void 0) config.seed = req.seed;
5042
5055
  if (lastFrame !== void 0) config.lastFrame = lastFrame;
5043
5056
  if (referenceImages !== void 0) config.referenceImages = referenceImages;
5044
5057
  const requestBody = {
@@ -6182,6 +6195,19 @@ var openaiImageAdapter = {
6182
6195
  const quality = req.quality ?? (isEdit ? "medium" : "auto");
6183
6196
  const sdkQuality = quality;
6184
6197
  const count = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
6198
+ let outputFormat = req.outputFormat;
6199
+ if (outputFormat === "webp") {
6200
+ ctx.warnings.push({
6201
+ code: "option_ignored",
6202
+ field: "outputFormat",
6203
+ from: "webp",
6204
+ to: "png",
6205
+ message: `${ctx.model.id} returns PNG for output_format webp; using png`
6206
+ });
6207
+ outputFormat = "png";
6208
+ }
6209
+ const format = outputFormat !== void 0 ? { output_format: outputFormat } : {};
6210
+ const mime = outputFormat === "jpeg" ? "image/jpeg" : "image/png";
6185
6211
  const retryOptions = {};
6186
6212
  if (ctx.signal !== void 0) retryOptions.signal = ctx.signal;
6187
6213
  const response = await withRetry(async () => {
@@ -6194,7 +6220,8 @@ var openaiImageAdapter = {
6194
6220
  prompt: req.prompt,
6195
6221
  size,
6196
6222
  quality: sdkQuality,
6197
- ...count
6223
+ ...count,
6224
+ ...format
6198
6225
  },
6199
6226
  { signal: ctx.signal }
6200
6227
  );
@@ -6204,20 +6231,21 @@ var openaiImageAdapter = {
6204
6231
  model: ctx.model.providerModelId,
6205
6232
  prompt: req.prompt,
6206
6233
  quality: sdkQuality,
6207
- ...count
6234
+ ...count,
6235
+ ...format
6208
6236
  },
6209
6237
  { signal: ctx.signal }
6210
6238
  );
6211
6239
  }
6212
6240
  const files = await Promise.all(
6213
6241
  refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
6214
- const { bytes, mime } = await mediaRefToBytes(ref, ctx.fetch, {
6242
+ const { bytes, mime: mime2 } = await mediaRefToBytes(ref, ctx.fetch, {
6215
6243
  signal: ctx.signal,
6216
6244
  provider: "openai-image",
6217
6245
  model: ctx.model.id
6218
6246
  });
6219
- const ext = mime.includes("jpeg") ? "jpg" : mime.includes("webp") ? "webp" : "png";
6220
- return new File([bytes], `ref-${i}.${ext}`, { type: mime });
6247
+ const ext = mime2.includes("jpeg") ? "jpg" : mime2.includes("webp") ? "webp" : "png";
6248
+ return new File([bytes], `ref-${i}.${ext}`, { type: mime2 });
6221
6249
  })
6222
6250
  );
6223
6251
  const single = files.length === 1 ? files[0] : void 0;
@@ -6230,7 +6258,8 @@ var openaiImageAdapter = {
6230
6258
  prompt: req.prompt,
6231
6259
  size,
6232
6260
  quality: sdkQuality,
6233
- ...count
6261
+ ...count,
6262
+ ...format
6234
6263
  },
6235
6264
  { signal: ctx.signal }
6236
6265
  );
@@ -6241,7 +6270,8 @@ var openaiImageAdapter = {
6241
6270
  image: imageInput,
6242
6271
  prompt: req.prompt,
6243
6272
  quality: sdkQuality,
6244
- ...count
6273
+ ...count,
6274
+ ...format
6245
6275
  },
6246
6276
  { signal: ctx.signal }
6247
6277
  );
@@ -6250,7 +6280,7 @@ var openaiImageAdapter = {
6250
6280
  }
6251
6281
  }, retryOptions);
6252
6282
  const images = (response.data ?? []).flatMap(
6253
- (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime: "image/png" }] : []
6283
+ (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime }] : []
6254
6284
  );
6255
6285
  if (images.length === 0)
6256
6286
  throw classifyHttpError(
@@ -7399,6 +7429,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
7399
7429
  keysFromEnv,
7400
7430
  languageModel,
7401
7431
  liveCatalog,
7432
+ liveState,
7402
7433
  mergeTextProviderOptions,
7403
7434
  nearestAspectRatio,
7404
7435
  openaiImageAdapter,