@shop-os/modelkit 0.1.11 → 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.js CHANGED
@@ -96,6 +96,14 @@ var Catalog = class _Catalog {
96
96
  ...rows
97
97
  ]);
98
98
  }
99
+ /** Atomically swap every row. Builds the maps first so a bad batch throws before anything changes. */
100
+ replace(rows) {
101
+ const next = new _Catalog(rows);
102
+ this.byId.clear();
103
+ this.byAlias.clear();
104
+ for (const [id, model] of next.byId) this.byId.set(id, model);
105
+ for (const [alias, id] of next.byAlias) this.byAlias.set(alias, id);
106
+ }
99
107
  };
100
108
 
101
109
  // src/catalog/image.ts
@@ -113,7 +121,7 @@ var GEMINI_RATIOS = [
113
121
  "5:4",
114
122
  "adaptive"
115
123
  ];
116
- function geminiImage(id, label, aliases, sizes, display, exposure) {
124
+ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
117
125
  const model = {
118
126
  id,
119
127
  aliases,
@@ -126,7 +134,8 @@ function geminiImage(id, label, aliases, sizes, display, exposure) {
126
134
  constraints: {
127
135
  aspectRatios: [...GEMINI_RATIOS],
128
136
  sizes,
129
- supports: ["safetySettings", "temperature"]
137
+ supports: ["safetySettings", "temperature"],
138
+ ...references ? { references } : {}
130
139
  },
131
140
  defaults: { size: "1K", aspectRatio: "1:1" },
132
141
  usage: { ...IMAGE_USAGE, slug: "gemini" },
@@ -146,7 +155,8 @@ var IMAGE_MODELS = [
146
155
  description: "Create stunning, production-quality visuals with exceptional realism, detail, and typography. Best for campaigns, e-commerce, product photography, and hero creatives.",
147
156
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
148
157
  },
149
- "catalog"
158
+ "catalog",
159
+ { images: 14 }
150
160
  ),
151
161
  geminiImage(
152
162
  "gemini-3.1-flash-image-preview",
@@ -159,7 +169,8 @@ var IMAGE_MODELS = [
159
169
  description: "Generate high-quality images at speed. Perfect for brainstorming, moodboards, concept testing, creative exploration, and large batch workflows.",
160
170
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
161
171
  },
162
- "catalog"
172
+ "catalog",
173
+ { images: 14 }
163
174
  ),
164
175
  geminiImage(
165
176
  "gemini-3.1-flash-lite-image",
@@ -171,14 +182,15 @@ var IMAGE_MODELS = [
171
182
  description: "The fastest and most affordable image model. Ideal for rapid drafts, bulk exploration, and iterative concept testing at 1K resolution.",
172
183
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
173
184
  },
174
- "catalog"
185
+ "catalog",
186
+ { images: 14 }
175
187
  ),
176
188
  // trigger-workflows validates 1K only; pricing seeds 2K/4K rows so allow all three.
177
189
  geminiImage(
178
190
  "gemini-2.5-flash-image",
179
191
  "Gemini 2.5 Flash Image",
180
192
  [],
181
- ["1K", "2K", "4K"],
193
+ ["1K"],
182
194
  {
183
195
  provider: "google",
184
196
  description: "Nano Banana (legacy Gemini 2.5 Flash Image) native image generation and editing model for high-volume, low-latency creative workflows."
@@ -209,7 +221,7 @@ var IMAGE_MODELS = [
209
221
  sizes: ["1K", "2K", "4K"],
210
222
  qualityOptions: ["auto", "low", "medium", "high"],
211
223
  references: { images: 16 },
212
- supports: ["quality", "count"]
224
+ supports: ["quality", "count", "outputFormat"]
213
225
  },
214
226
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
215
227
  usage: { ...IMAGE_USAGE, slug: "gpt" },
@@ -229,7 +241,7 @@ var IMAGE_MODELS = [
229
241
  adapter: "openai-image",
230
242
  providerModelId: "gpt-image-2.5-sunburst",
231
243
  lifecycle: "active",
232
- exposure: "internal",
244
+ exposure: "catalog",
233
245
  constraints: {
234
246
  exactSizes: {
235
247
  "1:1": "1024x1024",
@@ -242,9 +254,9 @@ var IMAGE_MODELS = [
242
254
  },
243
255
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
244
256
  sizes: ["1K", "2K", "4K"],
245
- qualityOptions: ["auto", "low", "medium", "high"],
257
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
246
258
  references: { images: 16 },
247
- supports: ["quality", "count"]
259
+ supports: ["quality", "count", "outputFormat"]
248
260
  },
249
261
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
250
262
  usage: { ...IMAGE_USAGE },
@@ -263,7 +275,7 @@ var IMAGE_MODELS = [
263
275
  adapter: "openai-image",
264
276
  providerModelId: "gpt-image-2.5-flare",
265
277
  lifecycle: "active",
266
- exposure: "internal",
278
+ exposure: "catalog",
267
279
  constraints: {
268
280
  exactSizes: {
269
281
  "1:1": "1024x1024",
@@ -276,9 +288,9 @@ var IMAGE_MODELS = [
276
288
  },
277
289
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
278
290
  sizes: ["1K", "2K", "4K"],
279
- qualityOptions: ["auto", "low", "medium", "high"],
291
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
280
292
  references: { images: 16 },
281
- supports: ["quality", "count"]
293
+ supports: ["quality", "count", "outputFormat"]
282
294
  },
283
295
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
284
296
  usage: { ...IMAGE_USAGE },
@@ -308,8 +320,6 @@ var IMAGE_MODELS = [
308
320
  "2:3",
309
321
  "3:4",
310
322
  "9:16",
311
- "4:5",
312
- "5:4",
313
323
  "9:21",
314
324
  "adaptive"
315
325
  ],
@@ -341,7 +351,7 @@ var IMAGE_MODELS = [
341
351
  references: { images: 10 },
342
352
  // Ark's Images API has no output-format, quality or count field; only
343
353
  // the seed is forwarded, so anything else must warn, not vanish.
344
- supports: ["seed"]
354
+ supports: ["seed", "outputFormat"]
345
355
  },
346
356
  defaults: { size: "1K", aspectRatio: "1:1" },
347
357
  usage: { ...IMAGE_USAGE },
@@ -377,7 +387,7 @@ var IMAGE_MODELS = [
377
387
  "21:9",
378
388
  "9:21"
379
389
  ],
380
- sizes: ["1K", "2K", "4K"],
390
+ sizes: ["2K", "4K"],
381
391
  references: { images: 10 },
382
392
  supports: ["seed"]
383
393
  },
@@ -429,7 +439,7 @@ var IMAGE_MODELS = [
429
439
  aspectRatios: ["1:1", "2:3", "3:2", "4:3", "3:4", "4:5", "5:4", "9:16", "16:9", "21:9"],
430
440
  sizes: ["1K", "2K", "4K"],
431
441
  requires: ["references"],
432
- supports: ["seed"]
442
+ supports: []
433
443
  },
434
444
  defaults: { size: "1K", aspectRatio: "1:1" },
435
445
  usage: { ...IMAGE_USAGE },
@@ -454,7 +464,7 @@ var IMAGE_MODELS = [
454
464
  aspectRatios: ["1:1", "2:3", "3:4", "4:3", "9:16", "16:9", "21:9"],
455
465
  sizes: ["1K"],
456
466
  requires: ["references"],
457
- supports: ["seed"]
467
+ supports: []
458
468
  },
459
469
  defaults: { size: "1K", aspectRatio: "1:1" },
460
470
  usage: { ...IMAGE_USAGE },
@@ -506,7 +516,6 @@ var IMAGE_MODELS = [
506
516
  aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
507
517
  sizes: [],
508
518
  references: { images: 1 },
509
- requires: ["references"],
510
519
  supports: []
511
520
  },
512
521
  defaults: { aspectRatio: "1:1" },
@@ -1225,7 +1234,7 @@ var VIDEO_MODELS = [
1225
1234
  resolutions: ["720p", "1080p", "4k"],
1226
1235
  durations: [8],
1227
1236
  references: { images: 3 },
1228
- supports: ["lastFrame"]
1237
+ supports: ["lastFrame", "seed"]
1229
1238
  },
1230
1239
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1231
1240
  usage: { ...VIDEO_USAGE, slug: "veo" },
@@ -1253,9 +1262,9 @@ var VIDEO_MODELS = [
1253
1262
  constraints: {
1254
1263
  aspectRatios: [...OMNI_RATIOS],
1255
1264
  resolutions: ["720p", "1080p", "4k"],
1256
- durations: [4, 8],
1265
+ durations: [4, 6, 8],
1257
1266
  references: { images: 3 },
1258
- supports: ["lastFrame"]
1267
+ supports: ["lastFrame", "seed"]
1259
1268
  },
1260
1269
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1261
1270
  usage: { ...VIDEO_USAGE },
@@ -1282,9 +1291,8 @@ var VIDEO_MODELS = [
1282
1291
  constraints: {
1283
1292
  aspectRatios: [...OMNI_RATIOS],
1284
1293
  resolutions: ["720p", "1080p"],
1285
- durations: [4, 8],
1286
- references: { images: 3 },
1287
- supports: ["lastFrame"]
1294
+ durations: [4, 6, 8],
1295
+ supports: ["lastFrame", "seed"]
1288
1296
  },
1289
1297
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1290
1298
  usage: { ...VIDEO_USAGE },
@@ -1316,7 +1324,7 @@ var VIDEO_MODELS = [
1316
1324
  // reference clip keeps its own framing.
1317
1325
  aspectRatios: [...OMNI_RATIOS],
1318
1326
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1319
- references: { images: 6, videos: 1 },
1327
+ references: { images: 6, videos: 3 },
1320
1328
  supports: []
1321
1329
  },
1322
1330
  defaults: {},
@@ -1342,7 +1350,7 @@ var VIDEO_MODELS = [
1342
1350
  aspectRatios: [...OMNI_RATIOS],
1343
1351
  resolutions: ["360p", "720p", "1080p", "4k"],
1344
1352
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1345
- references: { images: 6, videos: 1 },
1353
+ references: { images: 6, videos: 3 },
1346
1354
  supports: []
1347
1355
  },
1348
1356
  defaults: {},
@@ -1371,7 +1379,7 @@ var VIDEO_MODELS = [
1371
1379
  durations: { min: 4, max: 15 },
1372
1380
  durationPresets: [4, 6, 8, 10, 12, 15],
1373
1381
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1374
- ratioIgnoredWith: ["firstFrame"],
1382
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1375
1383
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1376
1384
  },
1377
1385
  defaults: {
@@ -1403,7 +1411,7 @@ var VIDEO_MODELS = [
1403
1411
  resolutions: ["480p", "720p"],
1404
1412
  durations: { min: 4, max: 15 },
1405
1413
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1406
- ratioIgnoredWith: ["firstFrame"],
1414
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1407
1415
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1408
1416
  },
1409
1417
  defaults: {
@@ -1436,7 +1444,7 @@ var VIDEO_MODELS = [
1436
1444
  resolutions: ["480p", "720p", "1080p"],
1437
1445
  durations: { min: 4, max: 30 },
1438
1446
  references: { images: 30, videos: 10, audios: 10 },
1439
- ratioIgnoredWith: ["firstFrame"],
1447
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1440
1448
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1441
1449
  },
1442
1450
  defaults: {
@@ -1555,18 +1563,7 @@ var VIDEO_MODELS = [
1555
1563
  lifecycle: "active",
1556
1564
  exposure: "catalog",
1557
1565
  constraints: {
1558
- aspectRatios: [
1559
- "1:1",
1560
- "16:9",
1561
- "9:16",
1562
- "4:3",
1563
- "3:4",
1564
- "3:2",
1565
- "2:3",
1566
- "21:9",
1567
- "4:5",
1568
- "adaptive"
1569
- ],
1566
+ aspectRatios: [...KLING_RATIOS],
1570
1567
  resolutions: ["720p", "1080p"],
1571
1568
  durations: { min: 3, max: 15 },
1572
1569
  references: { images: 7 },
@@ -1786,6 +1783,417 @@ var MODELS = [
1786
1783
  ...OTHER_MODELS
1787
1784
  ];
1788
1785
 
1786
+ // src/catalog/schema.ts
1787
+ import { z } from "zod";
1788
+ var ADAPTER_IDS = [
1789
+ "ai-sdk-text",
1790
+ "google-image",
1791
+ "openai-image",
1792
+ "google-genai",
1793
+ "ark",
1794
+ "fal",
1795
+ "replicate",
1796
+ "prodia",
1797
+ "higgsfield",
1798
+ "xai-video"
1799
+ ];
1800
+ var ModelTypeSchema = z.enum(["text", "image", "video", "audio", "upscale", "bg-remove"]);
1801
+ var LifecycleSchema = z.enum(["active", "deprecated", "retired"]);
1802
+ var AdapterSchema = z.enum(ADAPTER_IDS);
1803
+ var AspectRatioSchema = z.enum([
1804
+ "1:1",
1805
+ "16:9",
1806
+ "9:16",
1807
+ "4:3",
1808
+ "3:4",
1809
+ "3:2",
1810
+ "2:3",
1811
+ "4:5",
1812
+ "5:4",
1813
+ "21:9",
1814
+ "9:21",
1815
+ "97:30",
1816
+ "adaptive"
1817
+ ]);
1818
+ var ImageSizeSchema = z.enum(["512", "1K", "2K", "4K"]);
1819
+ var VideoResolutionSchema = z.enum(["360p", "480p", "720p", "768p", "1080p", "2k", "4k"]);
1820
+ var ImageQualitySchema = z.enum(["auto", "low", "medium", "high", "xhigh", "max"]);
1821
+ var OutputFormatSchema = z.enum(["png", "jpeg", "webp"]);
1822
+ var RequiredInputSchema = z.enum(["firstFrame", "sourceVideo", "references"]);
1823
+ var SupportedOptionSchema = z.enum([
1824
+ "seed",
1825
+ "quality",
1826
+ "negativePrompt",
1827
+ "cfgScale",
1828
+ "generateAudio",
1829
+ "promptExpansion",
1830
+ "lastFrame",
1831
+ "count",
1832
+ "outputFormat",
1833
+ "scaleFactor",
1834
+ "safetySettings",
1835
+ "temperature",
1836
+ "upscale",
1837
+ "watermark",
1838
+ "safetyChecker",
1839
+ "instrumental"
1840
+ ]);
1841
+ var UsageUnitSchema = z.enum([
1842
+ "tokens",
1843
+ "images",
1844
+ "seconds",
1845
+ "reported_cost_usd",
1846
+ "compute_seconds"
1847
+ ]);
1848
+ var PricingKindSchema = z.enum(["token", "image_size", "video_per_second", "flat"]);
1849
+ var ProviderOptionValueSchema = z.lazy(
1850
+ () => z.union([
1851
+ z.string(),
1852
+ z.number(),
1853
+ z.boolean(),
1854
+ z.array(ProviderOptionValueSchema),
1855
+ z.record(z.string(), ProviderOptionValueSchema)
1856
+ ])
1857
+ );
1858
+ var ProviderOptionsSchema = z.record(z.string(), z.record(z.string(), ProviderOptionValueSchema));
1859
+ var ReferenceLimitsSchema = z.looseObject({
1860
+ images: z.number().optional(),
1861
+ videos: z.number().optional(),
1862
+ audios: z.number().optional(),
1863
+ total: z.number().optional(),
1864
+ audioOnly: z.boolean().optional()
1865
+ });
1866
+ var ModelConstraintsSchema = z.looseObject({
1867
+ aspectRatios: z.array(AspectRatioSchema).optional(),
1868
+ sizes: z.array(ImageSizeSchema).optional(),
1869
+ resolutions: z.array(VideoResolutionSchema).optional(),
1870
+ durations: z.union([z.looseObject({ min: z.number(), max: z.number() }), z.array(z.number())]).optional(),
1871
+ durationPresets: z.array(z.number()).optional(),
1872
+ qualityOptions: z.array(z.string()).optional(),
1873
+ exactSizes: z.record(z.string(), z.string()).optional(),
1874
+ references: ReferenceLimitsSchema.optional(),
1875
+ requires: z.array(RequiredInputSchema).optional(),
1876
+ supports: z.array(SupportedOptionSchema).optional(),
1877
+ ratioIgnoredWith: z.array(z.enum(["firstFrame", "sourceVideo"])).optional()
1878
+ });
1879
+ var MediaRefSchema = z.union([
1880
+ z.looseObject({ url: z.string(), label: z.string().optional() }),
1881
+ z.looseObject({
1882
+ bytes: z.instanceof(Uint8Array),
1883
+ mime: z.string(),
1884
+ label: z.string().optional()
1885
+ })
1886
+ ]);
1887
+ var ImageSafetySettingSchema = z.looseObject({ category: z.string(), threshold: z.string() });
1888
+ var UpscaleOptionsSchema = z.looseObject({
1889
+ enhanceModel: z.string().optional(),
1890
+ subjectDetection: z.string().optional(),
1891
+ faceEnhancement: z.boolean().optional(),
1892
+ faceEnhancementCreativity: z.number().optional(),
1893
+ faceEnhancementStrength: z.number().optional()
1894
+ });
1895
+ var DefaultsSchema = z.looseObject({
1896
+ references: z.array(MediaRefSchema).optional(),
1897
+ aspectRatio: AspectRatioSchema.optional(),
1898
+ size: ImageSizeSchema.optional(),
1899
+ exactSize: z.string().optional(),
1900
+ quality: ImageQualitySchema.optional(),
1901
+ seed: z.number().optional(),
1902
+ count: z.number().optional(),
1903
+ outputFormat: OutputFormatSchema.optional(),
1904
+ scaleFactor: z.number().optional(),
1905
+ safetySettings: z.array(ImageSafetySettingSchema).optional(),
1906
+ temperature: z.number().optional(),
1907
+ upscale: UpscaleOptionsSchema.optional(),
1908
+ firstFrame: MediaRefSchema.optional(),
1909
+ lastFrame: MediaRefSchema.optional(),
1910
+ sourceVideo: MediaRefSchema.optional(),
1911
+ referenceImages: z.array(MediaRefSchema).optional(),
1912
+ referenceVideos: z.array(MediaRefSchema).optional(),
1913
+ referenceAudios: z.array(MediaRefSchema).optional(),
1914
+ resolution: VideoResolutionSchema.optional(),
1915
+ durationSeconds: z.number().optional(),
1916
+ generateAudio: z.boolean().optional(),
1917
+ negativePrompt: z.string().optional(),
1918
+ cfgScale: z.number().optional(),
1919
+ promptExpansion: z.enum(["fast", "balanced", "quality"]).optional(),
1920
+ watermark: z.boolean().optional(),
1921
+ safetyChecker: z.boolean().optional(),
1922
+ mode: z.enum(["standard", "pro"]).optional(),
1923
+ instrumental: z.boolean().optional()
1924
+ });
1925
+ var CatalogDisplaySchema = z.looseObject({
1926
+ provider: z.string(),
1927
+ description: z.string(),
1928
+ logo: z.string().optional(),
1929
+ costTier: z.union([z.literal(1), z.literal(2), z.literal(3)]).optional(),
1930
+ recommended: z.boolean().optional(),
1931
+ sortOrder: z.number().optional(),
1932
+ chat: z.looseObject({
1933
+ providerOptions: ProviderOptionsSchema.optional(),
1934
+ temperature: z.number().optional()
1935
+ }).optional()
1936
+ });
1937
+ var CatalogCapabilitiesSchema = z.looseObject({
1938
+ acceptsSourceVideo: z.boolean().optional(),
1939
+ framesExcludeReferences: z.boolean().optional(),
1940
+ reasoning: z.boolean().optional(),
1941
+ vision: z.boolean().optional(),
1942
+ contextWindow: z.number().optional()
1943
+ });
1944
+ var CatalogModelSchemaBase = z.looseObject({
1945
+ id: z.string().min(1),
1946
+ aliases: z.array(z.string()).default([]),
1947
+ label: z.string().min(1),
1948
+ type: ModelTypeSchema,
1949
+ adapter: AdapterSchema,
1950
+ providerModelId: z.string().min(1),
1951
+ lifecycle: LifecycleSchema,
1952
+ replacedBy: z.string().optional(),
1953
+ exposure: z.enum(["catalog", "internal"]),
1954
+ constraints: ModelConstraintsSchema,
1955
+ defaults: DefaultsSchema,
1956
+ providerOptions: ProviderOptionsSchema.optional(),
1957
+ usage: z.looseObject({
1958
+ unit: UsageUnitSchema,
1959
+ slug: z.string().optional(),
1960
+ providerLabel: z.string().optional()
1961
+ }),
1962
+ pricingKind: PricingKindSchema,
1963
+ display: CatalogDisplaySchema.optional(),
1964
+ capabilities: CatalogCapabilitiesSchema.optional()
1965
+ }).superRefine((row, ctx) => {
1966
+ if (row.lifecycle === "active" && !row.display) {
1967
+ ctx.addIssue({
1968
+ code: "custom",
1969
+ path: ["display"],
1970
+ message: "active rows need display"
1971
+ });
1972
+ }
1973
+ if (row.lifecycle === "active" && row.type === "text" && !row.capabilities?.contextWindow) {
1974
+ ctx.addIssue({
1975
+ code: "custom",
1976
+ path: ["capabilities", "contextWindow"],
1977
+ message: "active text rows need contextWindow"
1978
+ });
1979
+ }
1980
+ if (row.replacedBy !== void 0 && row.replacedBy === row.id) {
1981
+ ctx.addIssue({
1982
+ code: "custom",
1983
+ path: ["replacedBy"],
1984
+ message: "replacedBy must not equal id"
1985
+ });
1986
+ }
1987
+ });
1988
+ var CatalogModelSchema = CatalogModelSchemaBase;
1989
+ var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
1990
+ const seenIds = /* @__PURE__ */ new Map();
1991
+ rows.forEach((row, index) => {
1992
+ if (seenIds.has(row.id)) {
1993
+ ctx.addIssue({
1994
+ code: "custom",
1995
+ path: [index, "id"],
1996
+ message: `Duplicate model id "${row.id}"`
1997
+ });
1998
+ } else {
1999
+ seenIds.set(row.id, index);
2000
+ }
2001
+ });
2002
+ const seenAliases = /* @__PURE__ */ new Map();
2003
+ rows.forEach((row, index) => {
2004
+ row.aliases.forEach((alias, aliasIndex) => {
2005
+ const path = [index, "aliases", aliasIndex];
2006
+ if (alias === row.id || seenIds.has(alias)) {
2007
+ ctx.addIssue({
2008
+ code: "custom",
2009
+ path,
2010
+ message: `Alias "${alias}" collides with a model id`
2011
+ });
2012
+ return;
2013
+ }
2014
+ if (seenAliases.has(alias)) {
2015
+ ctx.addIssue({
2016
+ code: "custom",
2017
+ path,
2018
+ message: `Duplicate alias "${alias}"`
2019
+ });
2020
+ } else {
2021
+ seenAliases.set(alias, index);
2022
+ }
2023
+ });
2024
+ });
2025
+ });
2026
+
2027
+ // src/catalog/live.ts
2028
+ var KEY = /* @__PURE__ */ Symbol.for("@shop-os/modelkit/live-catalog");
2029
+ var store = globalThis;
2030
+ var liveState = store[KEY] ??= {
2031
+ catalog: new Catalog(MODELS),
2032
+ memo: void 0,
2033
+ timer: void 0,
2034
+ revision: void 0,
2035
+ origin: "snapshot"
2036
+ };
2037
+ var liveCatalog = liveState.catalog;
2038
+
2039
+ // src/catalog/load.ts
2040
+ function rowCount() {
2041
+ return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
2042
+ }
2043
+ function authHeaders(auth) {
2044
+ return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
2045
+ }
2046
+ function describeError(err) {
2047
+ return err instanceof Error ? err.message : String(err);
2048
+ }
2049
+ function parseEnvelope(json) {
2050
+ if (typeof json !== "object" || json === null || !("rows" in json)) {
2051
+ throw new Error("invalid catalog response: missing rows");
2052
+ }
2053
+ const rows = CatalogSchema.parse(json.rows);
2054
+ const rev = json.revision;
2055
+ if (typeof rev === "string") return { rows, revision: rev };
2056
+ return { rows };
2057
+ }
2058
+ function logPrimed(logger, result) {
2059
+ const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
2060
+ logger.info("[modelkit] catalog primed", {
2061
+ origin: loggedOrigin,
2062
+ rowCount: loggedCount,
2063
+ revision: loggedRevision
2064
+ });
2065
+ }
2066
+ async function fetchRemote(source, logger) {
2067
+ const fetchImpl = source.fetch ?? globalThis.fetch;
2068
+ const headers2 = authHeaders(source.auth);
2069
+ if (liveState.revision !== void 0) headers2["If-None-Match"] = `"${liveState.revision}"`;
2070
+ const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
2071
+ headers: headers2,
2072
+ signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
2073
+ });
2074
+ if (res.status === 304) return { kept: true };
2075
+ if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
2076
+ const json = await res.json();
2077
+ const { rows, revision: rev } = parseEnvelope(json);
2078
+ if (rev === void 0) return { rows, fromCache: false };
2079
+ return { rows, revision: rev, fromCache: false };
2080
+ }
2081
+ async function writeCache(source, logger, rows, rev) {
2082
+ if (!source.cache) return;
2083
+ try {
2084
+ await source.cache.set(JSON.stringify({ rows, revision: rev }));
2085
+ } catch (err) {
2086
+ logger.warn("[modelkit] catalog cache write failed", err);
2087
+ }
2088
+ }
2089
+ async function prime(source, logger) {
2090
+ try {
2091
+ const fetched = await fetchRemote(source, logger);
2092
+ if ("kept" in fetched) {
2093
+ const result2 = { origin: liveState.origin, rowCount: rowCount() };
2094
+ if (liveState.revision !== void 0) result2.revision = liveState.revision;
2095
+ logPrimed(logger, result2);
2096
+ return result2;
2097
+ }
2098
+ liveCatalog.replace(fetched.rows);
2099
+ liveState.origin = "remote";
2100
+ liveState.revision = fetched.revision;
2101
+ await writeCache(source, logger, fetched.rows, fetched.revision);
2102
+ const result = { origin: liveState.origin, rowCount: rowCount() };
2103
+ if (fetched.revision !== void 0) result.revision = fetched.revision;
2104
+ logPrimed(logger, result);
2105
+ return result;
2106
+ } catch (err) {
2107
+ logger.warn("[modelkit] catalog remote failed, trying cache", err);
2108
+ const error = describeError(err);
2109
+ try {
2110
+ const cached = await source.cache?.get();
2111
+ if (!cached) throw new Error("no cached catalog");
2112
+ const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
2113
+ liveCatalog.replace(rows);
2114
+ liveState.origin = "last-good";
2115
+ liveState.revision = rev;
2116
+ const result = {
2117
+ origin: liveState.origin,
2118
+ rowCount: rowCount(),
2119
+ error
2120
+ };
2121
+ if (rev !== void 0) result.revision = rev;
2122
+ logPrimed(logger, result);
2123
+ return result;
2124
+ } catch (cacheErr) {
2125
+ logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2126
+ liveCatalog.replace([...MODELS]);
2127
+ liveState.origin = "snapshot";
2128
+ liveState.revision = void 0;
2129
+ const result = {
2130
+ origin: liveState.origin,
2131
+ rowCount: rowCount(),
2132
+ error
2133
+ };
2134
+ logPrimed(logger, result);
2135
+ return result;
2136
+ }
2137
+ }
2138
+ }
2139
+ async function refresh(source, logger) {
2140
+ try {
2141
+ const fetched = await fetchRemote(source, logger);
2142
+ if ("kept" in fetched) return;
2143
+ liveCatalog.replace(fetched.rows);
2144
+ liveState.origin = "remote";
2145
+ liveState.revision = fetched.revision;
2146
+ await writeCache(source, logger, fetched.rows, fetched.revision);
2147
+ } catch (err) {
2148
+ logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2149
+ }
2150
+ }
2151
+ function primeCatalog(source) {
2152
+ const memo = liveState.memo;
2153
+ if (memo) return memo;
2154
+ const logger = source.logger ?? console;
2155
+ liveState.memo = prime(source, logger).then((result) => {
2156
+ const ttlMs = source.ttlMs ?? 3e5;
2157
+ if (ttlMs > 0 && liveState.timer === void 0) {
2158
+ liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
2159
+ const maybeUnref = liveState.timer;
2160
+ maybeUnref.unref?.();
2161
+ }
2162
+ return result;
2163
+ });
2164
+ return liveState.memo;
2165
+ }
2166
+ function resetLiveCatalog() {
2167
+ if (liveState.timer !== void 0) {
2168
+ clearInterval(liveState.timer);
2169
+ liveState.timer = void 0;
2170
+ }
2171
+ liveState.memo = void 0;
2172
+ liveState.revision = void 0;
2173
+ liveState.origin = "snapshot";
2174
+ liveCatalog.replace([...MODELS]);
2175
+ }
2176
+
2177
+ // src/catalog/file-cache.ts
2178
+ import { readFile, rename, writeFile } from "fs/promises";
2179
+ function fileCatalogCache(path) {
2180
+ return {
2181
+ async get() {
2182
+ try {
2183
+ return await readFile(path, "utf8");
2184
+ } catch (err) {
2185
+ if (err?.code === "ENOENT") return null;
2186
+ throw err;
2187
+ }
2188
+ },
2189
+ async set(json) {
2190
+ const tmp = `${path}.tmp`;
2191
+ await writeFile(tmp, json, "utf8");
2192
+ await rename(tmp, path);
2193
+ }
2194
+ };
2195
+ }
2196
+
1789
2197
  // src/resolve-options.ts
1790
2198
  var SIZE_ORDER = ["512", "1K", "2K", "4K"];
1791
2199
  var RESOLUTION_ORDER = ["360p", "480p", "720p", "768p", "1080p", "2k", "4k"];
@@ -2211,21 +2619,21 @@ function keysFromEnv(env, prefix = "") {
2211
2619
  }
2212
2620
 
2213
2621
  // src/retry.ts
2214
- import { z as z2 } from "zod";
2622
+ import { z as z3 } from "zod";
2215
2623
 
2216
2624
  // src/json.ts
2217
- import { z } from "zod";
2218
- var JsonValueSchema = z.lazy(
2219
- () => z.union([
2220
- z.string(),
2221
- z.number(),
2222
- z.boolean(),
2223
- z.null(),
2224
- z.array(JsonValueSchema),
2225
- z.record(z.string(), JsonValueSchema)
2625
+ import { z as z2 } from "zod";
2626
+ var JsonValueSchema = z2.lazy(
2627
+ () => z2.union([
2628
+ z2.string(),
2629
+ z2.number(),
2630
+ z2.boolean(),
2631
+ z2.null(),
2632
+ z2.array(JsonValueSchema),
2633
+ z2.record(z2.string(), JsonValueSchema)
2226
2634
  ])
2227
2635
  );
2228
- var JsonObjectSchema = z.record(z.string(), JsonValueSchema);
2636
+ var JsonObjectSchema = z2.record(z2.string(), JsonValueSchema);
2229
2637
  async function readErrorBody(res) {
2230
2638
  const text2 = await res.text().catch(() => "");
2231
2639
  try {
@@ -2234,11 +2642,11 @@ async function readErrorBody(res) {
2234
2642
  return text2;
2235
2643
  }
2236
2644
  }
2237
- var thrownErrorSchema = z.object({
2238
- message: z.string().optional(),
2239
- status: z.number().optional(),
2240
- statusCode: z.number().optional(),
2241
- responseBody: z.string().optional()
2645
+ var thrownErrorSchema = z2.object({
2646
+ message: z2.string().optional(),
2647
+ status: z2.number().optional(),
2648
+ statusCode: z2.number().optional(),
2649
+ responseBody: z2.string().optional()
2242
2650
  });
2243
2651
  function describeThrown(cause) {
2244
2652
  const parsed = thrownErrorSchema.safeParse(cause);
@@ -2249,7 +2657,7 @@ function describeThrown(cause) {
2249
2657
  }
2250
2658
 
2251
2659
  // src/retry.ts
2252
- var textBody = z2.string();
2660
+ var textBody = z3.string();
2253
2661
  function classifyHttpError(status, body, provider, model) {
2254
2662
  const asText = textBody.safeParse(body);
2255
2663
  const text2 = asText.success ? asText.data : JSON.stringify(body);
@@ -2464,7 +2872,7 @@ import {
2464
2872
  streamObject as aiStreamObject2,
2465
2873
  streamText as aiStreamText2
2466
2874
  } from "ai";
2467
- import { z as z4 } from "zod";
2875
+ import { z as z5 } from "zod";
2468
2876
 
2469
2877
  // src/adapters/media-ref.ts
2470
2878
  function isUrlRef(ref) {
@@ -2549,7 +2957,7 @@ import { createPerplexity } from "@ai-sdk/perplexity";
2549
2957
  import { createXai } from "@ai-sdk/xai";
2550
2958
  import { createDeepSeek } from "@ai-sdk/deepseek";
2551
2959
  import { createMoonshotAI } from "@ai-sdk/moonshotai";
2552
- import { z as z3 } from "zod";
2960
+ import { z as z4 } from "zod";
2553
2961
  var TEXT_PROVIDERS = [
2554
2962
  "openai",
2555
2963
  "anthropic",
@@ -2560,7 +2968,7 @@ var TEXT_PROVIDERS = [
2560
2968
  "moonshot",
2561
2969
  "minimax"
2562
2970
  ];
2563
- var textProviderSchema = z3.enum(TEXT_PROVIDERS);
2971
+ var textProviderSchema = z4.enum(TEXT_PROVIDERS);
2564
2972
  function isTextProvider(value) {
2565
2973
  return textProviderSchema.safeParse(value).success;
2566
2974
  }
@@ -2730,10 +3138,10 @@ function textAbortOptions(sdk, context) {
2730
3138
  if (abortSignal) return { abortSignal };
2731
3139
  return {};
2732
3140
  }
2733
- var catalogId = z4.string();
2734
- var exactSize = z4.templateLiteral([z4.number(), "x", z4.number()]);
2735
- var sdkRatio = z4.templateLiteral([z4.number(), ":", z4.number()]);
2736
- var sizeTier = z4.enum(["512", "1K", "2K", "4K"]);
3141
+ var catalogId = z5.string();
3142
+ var exactSize = z5.templateLiteral([z5.number(), "x", z5.number()]);
3143
+ var sdkRatio = z5.templateLiteral([z5.number(), ":", z5.number()]);
3144
+ var sizeTier = z5.enum(["512", "1K", "2K", "4K"]);
2737
3145
  function isCatalogId(model) {
2738
3146
  return catalogId.safeParse(model).success;
2739
3147
  }
@@ -2800,7 +3208,7 @@ function logCoercions(logger, modelId, warnings) {
2800
3208
  logger.warn(`[modelkit] ${modelId} request coerced`, { model: modelId, warnings });
2801
3209
  }
2802
3210
  function createModelKit(config, adapters) {
2803
- const catalog = new Catalog(MODELS).withOverrides(config.catalogOverride ?? []);
3211
+ const catalog = config.catalogOverride ? liveCatalog.withOverrides(config.catalogOverride) : liveCatalog;
2804
3212
  const logger = config.logger ?? console;
2805
3213
  const fetchImpl = config.fetch ?? globalThis.fetch;
2806
3214
  function context(model, call, warnings) {
@@ -3254,7 +3662,7 @@ function createModelKit(config, adapters) {
3254
3662
  }
3255
3663
 
3256
3664
  // src/adapters/ark.ts
3257
- import { z as z5 } from "zod";
3665
+ import { z as z6 } from "zod";
3258
3666
  var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
3259
3667
  var SUBMIT_PATH = "/contents/generations/tasks";
3260
3668
  var SEEDANCE_POLL_INTERVAL_MS = 15e3;
@@ -3331,7 +3739,7 @@ function arkKey(ctx) {
3331
3739
  return key;
3332
3740
  }
3333
3741
  function throwArkError(status, body, model) {
3334
- const parsed = z5.string().safeParse(body);
3742
+ const parsed = z6.string().safeParse(body);
3335
3743
  const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
3336
3744
  if (/sensitive.?content|human.?face/i.test(text2)) {
3337
3745
  const init = {
@@ -3369,13 +3777,13 @@ function sniffedImageMime(bytes) {
3369
3777
  return "image/webp";
3370
3778
  return "image/jpeg";
3371
3779
  }
3372
- var SeedreamImageSchema = z5.object({
3373
- url: z5.string().optional(),
3374
- b64_json: z5.string().optional()
3780
+ var SeedreamImageSchema = z6.object({
3781
+ url: z6.string().optional(),
3782
+ b64_json: z6.string().optional()
3375
3783
  });
3376
- var SeedreamResponseSchema = z5.object({
3377
- data: z5.array(SeedreamImageSchema).optional(),
3378
- error: z5.object({ message: z5.string().optional(), code: z5.string().optional() }).optional()
3784
+ var SeedreamResponseSchema = z6.object({
3785
+ data: z6.array(SeedreamImageSchema).optional(),
3786
+ error: z6.object({ message: z6.string().optional(), code: z6.string().optional() }).optional()
3379
3787
  });
3380
3788
  function retryOptsFor(ctx, attempts = 3) {
3381
3789
  const opts = { attempts };
@@ -3404,6 +3812,18 @@ async function generateSeedreamImage(req, ctx) {
3404
3812
  watermark: false
3405
3813
  };
3406
3814
  if (req.seed !== void 0) body.seed = req.seed;
3815
+ if (req.outputFormat !== void 0) {
3816
+ if (req.outputFormat === "webp") {
3817
+ ctx.warnings.push({
3818
+ code: "option_ignored",
3819
+ field: "outputFormat",
3820
+ from: "webp",
3821
+ to: "png",
3822
+ message: `${modelId} accepts png or jpeg output; using png`
3823
+ });
3824
+ }
3825
+ body.output_format = req.outputFormat === "jpeg" ? "jpeg" : "png";
3826
+ }
3407
3827
  const firstRef = refs[0];
3408
3828
  if (refs.length === 1 && firstRef !== void 0) body.image = firstRef;
3409
3829
  else if (refs.length > 1) body.image = refs;
@@ -3447,21 +3867,21 @@ async function generateSeedreamImage(req, ctx) {
3447
3867
  if (req.quality !== void 0) usage2.imageQuality = req.quality;
3448
3868
  return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
3449
3869
  }
3450
- var SeedanceUsageSchema = z5.object({
3451
- total_tokens: z5.number().optional(),
3452
- completion_tokens: z5.number().optional()
3870
+ var SeedanceUsageSchema = z6.object({
3871
+ total_tokens: z6.number().optional(),
3872
+ completion_tokens: z6.number().optional()
3453
3873
  });
3454
- var SeedanceResponseSchema = z5.object({
3455
- id: z5.string().optional(),
3456
- status: z5.string().optional(),
3457
- content: z5.object({ video_url: z5.string().optional() }).optional(),
3874
+ var SeedanceResponseSchema = z6.object({
3875
+ id: z6.string().optional(),
3876
+ status: z6.string().optional(),
3877
+ content: z6.object({ video_url: z6.string().optional() }).optional(),
3458
3878
  usage: SeedanceUsageSchema.optional(),
3459
- duration: z5.number().optional(),
3460
- framespersecond: z5.number().optional(),
3461
- resolution: z5.string().optional(),
3462
- error: z5.union([z5.string(), z5.object({ message: z5.string().optional() })]).optional()
3879
+ duration: z6.number().optional(),
3880
+ framespersecond: z6.number().optional(),
3881
+ resolution: z6.string().optional(),
3882
+ error: z6.union([z6.string(), z6.object({ message: z6.string().optional() })]).optional()
3463
3883
  });
3464
- var SeedanceErrorMessageSchema = z5.object({ message: z5.string().optional() });
3884
+ var SeedanceErrorMessageSchema = z6.object({ message: z6.string().optional() });
3465
3885
  function seedanceUsage(ctx, req, duration) {
3466
3886
  const usage2 = {
3467
3887
  model: ctx.model.id,
@@ -3475,7 +3895,7 @@ function seedanceUsage(ctx, req, duration) {
3475
3895
  return usage2;
3476
3896
  }
3477
3897
  function seedanceErrorMessage(error, status) {
3478
- const asString = z5.string().safeParse(error);
3898
+ const asString = z6.string().safeParse(error);
3479
3899
  if (asString.success) return asString.data;
3480
3900
  const asObject = SeedanceErrorMessageSchema.safeParse(error);
3481
3901
  if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
@@ -3624,7 +4044,7 @@ async function generateSeedanceVideo(req, ctx) {
3624
4044
  }
3625
4045
 
3626
4046
  // src/adapters/fal.ts
3627
- import { z as z6 } from "zod";
4047
+ import { z as z7 } from "zod";
3628
4048
  import { createFalClient } from "@fal-ai/client";
3629
4049
  var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
3630
4050
  var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
@@ -3632,7 +4052,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
3632
4052
  var FAL_QUEUE_HOST = "https://queue.fal.run";
3633
4053
  var PASSTHROUGH_POLL_MS = 2e3;
3634
4054
  var PASSTHROUGH_MAX_WAIT_MS = 18e4;
3635
- var falSubscribePayloadSchema = z6.object({ data: JsonValueSchema });
4055
+ var falSubscribePayloadSchema = z7.object({ data: JsonValueSchema });
3636
4056
  function defaultCreateFalClient(opts) {
3637
4057
  const client2 = createFalClient(opts);
3638
4058
  return {
@@ -3682,7 +4102,7 @@ function createFalAdapter(deps = defaultDeps) {
3682
4102
  };
3683
4103
  }
3684
4104
  var falAdapter = createFalAdapter();
3685
- var falDetailSchema = z6.object({ detail: JsonValueSchema });
4105
+ var falDetailSchema = z7.object({ detail: JsonValueSchema });
3686
4106
  function liftDetail(body) {
3687
4107
  const parsed = falDetailSchema.safeParse(body);
3688
4108
  const detail = parsed.success ? parsed.data.detail : void 0;
@@ -3691,11 +4111,11 @@ function liftDetail(body) {
3691
4111
  function falError(status, body, model) {
3692
4112
  return classifyHttpError(status, liftDetail(body), "fal", model);
3693
4113
  }
3694
- var falSdkThrownSchema = z6.object({
3695
- status: z6.number().optional(),
3696
- statusCode: z6.number().optional(),
4114
+ var falSdkThrownSchema = z7.object({
4115
+ status: z7.number().optional(),
4116
+ statusCode: z7.number().optional(),
3697
4117
  body: JsonValueSchema.optional(),
3698
- message: z6.string().optional()
4118
+ message: z7.string().optional()
3699
4119
  });
3700
4120
  function falSdkError(cause, model) {
3701
4121
  const parsed = falSdkThrownSchema.safeParse(cause);
@@ -3739,12 +4159,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
3739
4159
  if (init.body !== void 0) request.body = init.body;
3740
4160
  return fetchImpl(cfg.baseUrl, request);
3741
4161
  }
3742
- var falQueueSubmitSchema = z6.object({
3743
- request_id: z6.string(),
3744
- status_url: z6.string(),
3745
- response_url: z6.string()
4162
+ var falQueueSubmitSchema = z7.object({
4163
+ request_id: z7.string(),
4164
+ status_url: z7.string(),
4165
+ response_url: z7.string()
3746
4166
  });
3747
- var falQueueStatusSchema = z6.object({ status: z6.string() });
4167
+ var falQueueStatusSchema = z7.object({ status: z7.string() });
3748
4168
  async function passthroughRequest(ctx, endpoint, input) {
3749
4169
  const cfg = gatewayConfig(ctx);
3750
4170
  const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
@@ -3870,11 +4290,11 @@ async function decodeImage(ctx, url, contentType) {
3870
4290
  const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
3871
4291
  return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
3872
4292
  }
3873
- var museImageResultSchema = z6.object({
3874
- images: z6.array(
3875
- z6.object({
3876
- url: z6.string().optional(),
3877
- content_type: z6.string().nullable().optional()
4293
+ var museImageResultSchema = z7.object({
4294
+ images: z7.array(
4295
+ z7.object({
4296
+ url: z7.string().optional(),
4297
+ content_type: z7.string().nullable().optional()
3878
4298
  })
3879
4299
  ).optional()
3880
4300
  });
@@ -3966,8 +4386,8 @@ function klingO1Input(req) {
3966
4386
  if (refs.length > 0) input.image_urls = refs;
3967
4387
  return input;
3968
4388
  }
3969
- var falVideoResultSchema = z6.object({
3970
- video: z6.object({ url: z6.string().optional() }).optional()
4389
+ var falVideoResultSchema = z7.object({
4390
+ video: z7.object({ url: z7.string().optional() }).optional()
3971
4391
  });
3972
4392
  function extractVideoUrl(result, endpoint, model) {
3973
4393
  const parsed = falVideoResultSchema.safeParse(result);
@@ -4157,13 +4577,13 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
4157
4577
  }
4158
4578
 
4159
4579
  // src/adapters/google-genai.ts
4160
- import { z as z8 } from "zod";
4580
+ import { z as z9 } from "zod";
4161
4581
  import {
4162
4582
  GoogleGenAI
4163
4583
  } from "@google/genai";
4164
4584
 
4165
4585
  // src/adapters/google-files.ts
4166
- import { z as z7 } from "zod";
4586
+ import { z as z8 } from "zod";
4167
4587
  var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
4168
4588
  var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
4169
4589
  var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
@@ -4173,17 +4593,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
4173
4593
  "binary/octet-stream",
4174
4594
  "application/binary"
4175
4595
  ]);
4176
- var uploadedFileSchema = z7.object({
4177
- file: z7.object({
4178
- uri: z7.string().optional(),
4179
- name: z7.string().optional(),
4180
- state: z7.string().optional(),
4181
- mimeType: z7.string().optional()
4596
+ var uploadedFileSchema = z8.object({
4597
+ file: z8.object({
4598
+ uri: z8.string().optional(),
4599
+ name: z8.string().optional(),
4600
+ state: z8.string().optional(),
4601
+ mimeType: z8.string().optional()
4182
4602
  }).optional()
4183
4603
  });
4184
- var fileStateSchema = z7.object({
4185
- state: z7.string().optional(),
4186
- error: z7.object({ message: z7.string().optional() }).optional()
4604
+ var fileStateSchema = z8.object({
4605
+ state: z8.string().optional(),
4606
+ error: z8.object({ message: z8.string().optional() }).optional()
4187
4607
  });
4188
4608
  function resolveMime(declared, fallback) {
4189
4609
  const clean = declared?.split(";")[0]?.trim().toLowerCase();
@@ -4396,7 +4816,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
4396
4816
  var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
4397
4817
  var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
4398
4818
  var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
4399
- var errorTextSchema = z8.string();
4819
+ var errorTextSchema = z9.string();
4400
4820
  function createGoogleGenaiAdapter(deps = defaultDeps2) {
4401
4821
  const { createGenAIClient } = deps;
4402
4822
  return {
@@ -4549,6 +4969,7 @@ async function generateVeoVideo(req, ctx, createGenAIClient) {
4549
4969
  const config = { durationSeconds: duration, personGeneration };
4550
4970
  if (req.aspectRatio !== void 0) config.aspectRatio = req.aspectRatio;
4551
4971
  if (req.resolution !== void 0) config.resolution = req.resolution;
4972
+ if (req.seed !== void 0) config.seed = req.seed;
4552
4973
  if (lastFrame !== void 0) config.lastFrame = lastFrame;
4553
4974
  if (referenceImages !== void 0) config.referenceImages = referenceImages;
4554
4975
  const requestBody = {
@@ -4954,15 +5375,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
4954
5375
  // src/adapters/google-image.ts
4955
5376
  import { createGoogleGenerativeAI as createGoogleGenerativeAI2 } from "@ai-sdk/google";
4956
5377
  import { generateText } from "ai";
4957
- import { z as z9 } from "zod";
5378
+ import { z as z10 } from "zod";
4958
5379
  var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
4959
5380
  var defaultGoogleImageDeps = {
4960
5381
  createGoogleClient: (opts) => createGoogleGenerativeAI2(opts),
4961
5382
  runTextGeneration: (opts) => generateText(opts)
4962
5383
  };
4963
- var causeChainNodeSchema = z9.object({
4964
- message: z9.string().optional(),
4965
- cause: z9.unknown().optional()
5384
+ var causeChainNodeSchema = z10.object({
5385
+ message: z10.string().optional(),
5386
+ cause: z10.unknown().optional()
4966
5387
  });
4967
5388
  function extractBlockReason(cause) {
4968
5389
  let current = cause;
@@ -5083,7 +5504,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
5083
5504
  var googleImageAdapter = createGoogleImageAdapter();
5084
5505
 
5085
5506
  // src/adapters/higgsfield.ts
5086
- import { z as z10 } from "zod";
5507
+ import { z as z11 } from "zod";
5087
5508
 
5088
5509
  // src/adapters/higgsfield-motions.ts
5089
5510
  var MOTION_MAP = {
@@ -5271,14 +5692,14 @@ function videoUsage3(ctx, req, duration) {
5271
5692
  if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
5272
5693
  return event;
5273
5694
  }
5274
- var klingCreateSchema = z10.object({ status_url: z10.string() });
5275
- var klingStatusSchema = z10.object({
5276
- status: z10.string().optional(),
5277
- video: z10.object({ url: z10.string().optional() }).optional(),
5695
+ var klingCreateSchema = z11.object({ status_url: z11.string() });
5696
+ var klingStatusSchema = z11.object({
5697
+ status: z11.string().optional(),
5698
+ video: z11.object({ url: z11.string().optional() }).optional(),
5278
5699
  error: JsonValueSchema.optional()
5279
5700
  });
5280
- var errorMessageSchema = z10.object({ message: z10.string().optional() });
5281
- var textValueSchema = z10.string();
5701
+ var errorMessageSchema = z11.object({ message: z11.string().optional() });
5702
+ var textValueSchema = z11.string();
5282
5703
  function klingErrorDetail(error) {
5283
5704
  if (error === void 0) return "unknown_error";
5284
5705
  const asText = textValueSchema.safeParse(error);
@@ -5412,8 +5833,8 @@ async function generateKlingVideo(req, ctx) {
5412
5833
  }
5413
5834
  };
5414
5835
  }
5415
- var dopMotionOptionsSchema = z10.object({
5416
- modelkit: z10.object({ motion: z10.string().optional() }).optional()
5836
+ var dopMotionOptionsSchema = z11.object({
5837
+ modelkit: z11.object({ motion: z11.string().optional() }).optional()
5417
5838
  });
5418
5839
  function dopMotionId(ctx) {
5419
5840
  const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
@@ -5429,7 +5850,7 @@ function dopMotionId(ctx) {
5429
5850
  });
5430
5851
  return id;
5431
5852
  }
5432
- var jsonRecordSchema = z10.record(z10.string(), JsonValueSchema);
5853
+ var jsonRecordSchema = z11.record(z11.string(), JsonValueSchema);
5433
5854
  var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
5434
5855
  var DOP_NESTED_KEYS = ["video", "result", "results"];
5435
5856
  function dopUrl(body) {
@@ -5457,8 +5878,8 @@ function dopUrl(body) {
5457
5878
  }
5458
5879
  return void 0;
5459
5880
  }
5460
- var dopCreateSchema = z10.object({ id: z10.string() });
5461
- var dopStatusSchema = z10.object({ status: z10.string().optional() });
5881
+ var dopCreateSchema = z11.object({ id: z11.string() });
5882
+ var dopStatusSchema = z11.object({ status: z11.string().optional() });
5462
5883
  async function generateDopVideo(req, ctx) {
5463
5884
  const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
5464
5885
  if (!firstFrame) {
@@ -5578,7 +5999,7 @@ var higgsfieldAdapter = {
5578
5999
 
5579
6000
  // src/adapters/openai-image.ts
5580
6001
  import OpenAI from "openai";
5581
- import { z as z11 } from "zod";
6002
+ import { z as z12 } from "zod";
5582
6003
  var MAX_EDIT_REFERENCES = 16;
5583
6004
  function aspectRatioToSize(ratio, tier) {
5584
6005
  const TIER_LONG_EDGE = {
@@ -5661,9 +6082,9 @@ function toProviderError2(cause, ctx) {
5661
6082
  ctx.model.id
5662
6083
  );
5663
6084
  }
5664
- var openaiUsageSchema = z11.object({
5665
- input_tokens: z11.number().optional(),
5666
- output_tokens: z11.number().optional()
6085
+ var openaiUsageSchema = z12.object({
6086
+ input_tokens: z12.number().optional(),
6087
+ output_tokens: z12.number().optional()
5667
6088
  });
5668
6089
  var openaiImageAdapter = {
5669
6090
  id: "openai-image",
@@ -5692,6 +6113,19 @@ var openaiImageAdapter = {
5692
6113
  const quality = req.quality ?? (isEdit ? "medium" : "auto");
5693
6114
  const sdkQuality = quality;
5694
6115
  const count = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
6116
+ let outputFormat = req.outputFormat;
6117
+ if (outputFormat === "webp") {
6118
+ ctx.warnings.push({
6119
+ code: "option_ignored",
6120
+ field: "outputFormat",
6121
+ from: "webp",
6122
+ to: "png",
6123
+ message: `${ctx.model.id} returns PNG for output_format webp; using png`
6124
+ });
6125
+ outputFormat = "png";
6126
+ }
6127
+ const format = outputFormat !== void 0 ? { output_format: outputFormat } : {};
6128
+ const mime = outputFormat === "jpeg" ? "image/jpeg" : "image/png";
5695
6129
  const retryOptions = {};
5696
6130
  if (ctx.signal !== void 0) retryOptions.signal = ctx.signal;
5697
6131
  const response = await withRetry(async () => {
@@ -5704,7 +6138,8 @@ var openaiImageAdapter = {
5704
6138
  prompt: req.prompt,
5705
6139
  size,
5706
6140
  quality: sdkQuality,
5707
- ...count
6141
+ ...count,
6142
+ ...format
5708
6143
  },
5709
6144
  { signal: ctx.signal }
5710
6145
  );
@@ -5714,20 +6149,21 @@ var openaiImageAdapter = {
5714
6149
  model: ctx.model.providerModelId,
5715
6150
  prompt: req.prompt,
5716
6151
  quality: sdkQuality,
5717
- ...count
6152
+ ...count,
6153
+ ...format
5718
6154
  },
5719
6155
  { signal: ctx.signal }
5720
6156
  );
5721
6157
  }
5722
6158
  const files = await Promise.all(
5723
6159
  refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
5724
- const { bytes, mime } = await mediaRefToBytes(ref, ctx.fetch, {
6160
+ const { bytes, mime: mime2 } = await mediaRefToBytes(ref, ctx.fetch, {
5725
6161
  signal: ctx.signal,
5726
6162
  provider: "openai-image",
5727
6163
  model: ctx.model.id
5728
6164
  });
5729
- const ext = mime.includes("jpeg") ? "jpg" : mime.includes("webp") ? "webp" : "png";
5730
- return new File([bytes], `ref-${i}.${ext}`, { type: mime });
6165
+ const ext = mime2.includes("jpeg") ? "jpg" : mime2.includes("webp") ? "webp" : "png";
6166
+ return new File([bytes], `ref-${i}.${ext}`, { type: mime2 });
5731
6167
  })
5732
6168
  );
5733
6169
  const single = files.length === 1 ? files[0] : void 0;
@@ -5740,7 +6176,8 @@ var openaiImageAdapter = {
5740
6176
  prompt: req.prompt,
5741
6177
  size,
5742
6178
  quality: sdkQuality,
5743
- ...count
6179
+ ...count,
6180
+ ...format
5744
6181
  },
5745
6182
  { signal: ctx.signal }
5746
6183
  );
@@ -5751,7 +6188,8 @@ var openaiImageAdapter = {
5751
6188
  image: imageInput,
5752
6189
  prompt: req.prompt,
5753
6190
  quality: sdkQuality,
5754
- ...count
6191
+ ...count,
6192
+ ...format
5755
6193
  },
5756
6194
  { signal: ctx.signal }
5757
6195
  );
@@ -5760,7 +6198,7 @@ var openaiImageAdapter = {
5760
6198
  }
5761
6199
  }, retryOptions);
5762
6200
  const images = (response.data ?? []).flatMap(
5763
- (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime: "image/png" }] : []
6201
+ (item) => item.b64_json ? [{ bytes: base64ToBytes(item.b64_json), mime }] : []
5764
6202
  );
5765
6203
  if (images.length === 0)
5766
6204
  throw classifyHttpError(
@@ -6053,7 +6491,7 @@ var prodiaAdapter = {
6053
6491
 
6054
6492
  // src/adapters/replicate.ts
6055
6493
  import Replicate from "replicate";
6056
- import { z as z12 } from "zod";
6494
+ import { z as z13 } from "zod";
6057
6495
  var POLL_INTERVAL_MS = 1e3;
6058
6496
  var POLL_TIMEOUT_MS = 15 * 6e4;
6059
6497
  var defaultReplicateDeps = {
@@ -6089,8 +6527,8 @@ function route(providerModelId) {
6089
6527
  if (!providerModelId.includes("/")) return { version: providerModelId };
6090
6528
  return { model: providerModelId };
6091
6529
  }
6092
- var replicateResponseStatusSchema = z12.object({
6093
- response: z12.object({ status: z12.number() }).partial()
6530
+ var replicateResponseStatusSchema = z13.object({
6531
+ response: z13.object({ status: z13.number() }).partial()
6094
6532
  });
6095
6533
  function replicateError(cause, ctx) {
6096
6534
  if (isModelKitError(cause)) return cause;
@@ -6117,7 +6555,7 @@ function isUrlFn(value) {
6117
6555
  function extractOutputUrl(output) {
6118
6556
  const root = Array.isArray(output) ? output[0] : output;
6119
6557
  if (root === void 0) throw noOutput();
6120
- const asString = z12.string().safeParse(root);
6558
+ const asString = z13.string().safeParse(root);
6121
6559
  if (asString.success && asString.data) return asString.data;
6122
6560
  if (root instanceof URL) return root.href;
6123
6561
  if (isObjectOutput(root)) {
@@ -6126,15 +6564,15 @@ function extractOutputUrl(output) {
6126
6564
  if (urlValue !== void 0 && isUrlFn(urlValue)) {
6127
6565
  const called = urlValue();
6128
6566
  if (called instanceof URL) return called.href;
6129
- const calledString = z12.string().safeParse(called);
6567
+ const calledString = z13.string().safeParse(called);
6130
6568
  if (calledString.success && calledString.data) return calledString.data;
6131
6569
  } else {
6132
- const direct = z12.string().safeParse(urlValue);
6570
+ const direct = z13.string().safeParse(urlValue);
6133
6571
  if (direct.success && direct.data) return direct.data;
6134
6572
  }
6135
6573
  }
6136
6574
  if ("default" in root) {
6137
- const fallback = z12.string().safeParse(root.default);
6575
+ const fallback = z13.string().safeParse(root.default);
6138
6576
  if (fallback.success && fallback.data) return fallback.data;
6139
6577
  }
6140
6578
  }
@@ -6195,7 +6633,7 @@ async function runPrediction(ctx, input, deps) {
6195
6633
  }
6196
6634
  return void 0;
6197
6635
  }, pollOpts);
6198
- const predictTime = z12.number().safeParse(done.metrics?.predict_time);
6636
+ const predictTime = z13.number().safeParse(done.metrics?.predict_time);
6199
6637
  if (done.output === void 0) throw noOutput();
6200
6638
  return {
6201
6639
  url: extractOutputUrl(done.output),
@@ -6538,7 +6976,7 @@ async function generateReplicateVideo(req, ctx, deps) {
6538
6976
  throw replicateError(cause, ctx);
6539
6977
  }
6540
6978
  if (current.status === "succeeded") {
6541
- const predictTime = z12.number().safeParse(current.metrics?.predict_time);
6979
+ const predictTime = z13.number().safeParse(current.metrics?.predict_time);
6542
6980
  if (current.output === void 0) throw noOutput();
6543
6981
  return {
6544
6982
  url: extractOutputUrl(current.output),
@@ -6670,7 +7108,7 @@ async function generateReplicateAudio(req, ctx, deps) {
6670
7108
  // src/adapters/xai-video.ts
6671
7109
  import { experimental_generateVideo } from "ai";
6672
7110
  import { createXai as createXai2 } from "@ai-sdk/xai";
6673
- import { z as z13 } from "zod";
7111
+ import { z as z14 } from "zod";
6674
7112
  var POLL_INTERVAL_MS2 = 1e4;
6675
7113
  var POLL_TIMEOUT_MS2 = 15 * 6e4;
6676
7114
  var defaultXaiDeps = {
@@ -6683,8 +7121,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
6683
7121
  };
6684
7122
  }
6685
7123
  var xaiVideoAdapter = createXaiVideoAdapter();
6686
- var xaiResponseStatusSchema = z13.object({
6687
- response: z13.object({ status: z13.number() }).partial()
7124
+ var xaiResponseStatusSchema = z14.object({
7125
+ response: z14.object({ status: z14.number() }).partial()
6688
7126
  });
6689
7127
  function xaiError(cause, ctx) {
6690
7128
  const info = describeThrown(cause);
@@ -6692,12 +7130,12 @@ function xaiError(cause, ctx) {
6692
7130
  const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
6693
7131
  return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
6694
7132
  }
6695
- var xaiMetaSchema = z13.object({
7133
+ var xaiMetaSchema = z14.object({
6696
7134
  videoUrl: JsonValueSchema.optional(),
6697
7135
  costInUsdTicks: JsonValueSchema.optional(),
6698
7136
  duration: JsonValueSchema.optional()
6699
7137
  });
6700
- var xaiProviderMetadataSchema = z13.object({ xai: xaiMetaSchema });
7138
+ var xaiProviderMetadataSchema = z14.object({ xai: xaiMetaSchema });
6701
7139
  function metaOf(result) {
6702
7140
  const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
6703
7141
  if (!parsed.success) return {};
@@ -6804,7 +7242,7 @@ async function mapResult(ctx, req, result) {
6804
7242
  };
6805
7243
  }
6806
7244
  const meta = metaOf(result);
6807
- const videoUrl = z13.string().safeParse(meta.videoUrl);
7245
+ const videoUrl = z14.string().safeParse(meta.videoUrl);
6808
7246
  if (videoUrl.success && videoUrl.data) {
6809
7247
  const res = await ctx.fetch(videoUrl.data);
6810
7248
  if (!res.ok) {
@@ -6827,7 +7265,7 @@ async function mapResult(ctx, req, result) {
6827
7265
  });
6828
7266
  }
6829
7267
  function usage(ctx, req, meta) {
6830
- const costTicks = z13.number().safeParse(meta.costInUsdTicks);
7268
+ const costTicks = z14.number().safeParse(meta.costInUsdTicks);
6831
7269
  const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
6832
7270
  const event = {
6833
7271
  model: ctx.model.id,
@@ -6875,8 +7313,11 @@ var prepareMediaPart = (modelId, ref, mediaType, call) => createDefaultModelKit(
6875
7313
  var languageModel = (modelId, call) => createDefaultModelKit().languageModel(modelId, call);
6876
7314
  var describe = (modelId) => createDefaultModelKit().describe(modelId);
6877
7315
  export {
7316
+ ADAPTER_IDS,
6878
7317
  ADAPTER_KEYS,
6879
7318
  Catalog,
7319
+ CatalogModelSchema,
7320
+ CatalogSchema,
6880
7321
  DEFAULT_ADAPTERS,
6881
7322
  JsonObjectSchema,
6882
7323
  JsonValueSchema,
@@ -6892,6 +7333,7 @@ export {
6892
7333
  describeThrown,
6893
7334
  generateImage as experimental_generateImage,
6894
7335
  falAdapter,
7336
+ fileCatalogCache,
6895
7337
  generateAudio,
6896
7338
  generateImage,
6897
7339
  generateObject,
@@ -6903,15 +7345,19 @@ export {
6903
7345
  isModelKitError,
6904
7346
  keysFromEnv,
6905
7347
  languageModel,
7348
+ liveCatalog,
7349
+ liveState,
6906
7350
  mergeTextProviderOptions,
6907
7351
  nearestAspectRatio,
6908
7352
  openaiImageAdapter,
6909
7353
  passthroughTextModel,
6910
7354
  pollUntil,
6911
7355
  prepareMediaPart,
7356
+ primeCatalog,
6912
7357
  prodiaAdapter,
6913
7358
  readErrorBody,
6914
7359
  replicateAdapter,
7360
+ resetLiveCatalog,
6915
7361
  resolveAudioOptions,
6916
7362
  resolveImageOptions,
6917
7363
  resolveKeys,