@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.
@@ -429,6 +429,15 @@ declare const ADAPTER_IDS: readonly ["ai-sdk-text", "google-image", "openai-imag
429
429
  declare const CatalogModelSchema: z.ZodType<CatalogModel>;
430
430
  declare const CatalogSchema: z.ZodType<CatalogModel[]>;
431
431
 
432
+ type CatalogOrigin = "remote" | "last-good" | "snapshot";
433
+ interface LiveCatalogState {
434
+ catalog: Catalog;
435
+ memo: Promise<unknown> | undefined;
436
+ timer: ReturnType<typeof setInterval> | undefined;
437
+ revision: string | undefined;
438
+ origin: CatalogOrigin;
439
+ }
440
+ declare const liveState: LiveCatalogState;
432
441
  declare const liveCatalog: Catalog;
433
442
 
434
443
  interface CatalogCache {
@@ -450,7 +459,7 @@ interface CatalogSource {
450
459
  fetch?: typeof fetch;
451
460
  logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
452
461
  }
453
- type CatalogOrigin = "remote" | "last-good" | "snapshot";
462
+
454
463
  interface PrimeCatalogResult {
455
464
  origin: CatalogOrigin;
456
465
  rowCount: number;
@@ -459,7 +468,7 @@ interface PrimeCatalogResult {
459
468
  }
460
469
  /** Fetch, validate, swap into liveCatalog. Never throws. Second call returns the same promise. */
461
470
  declare function primeCatalog(source: CatalogSource): Promise<PrimeCatalogResult>;
462
- /** Test seam: stop the refresh timer and reset liveCatalog to MODELS and clear the memo. */
471
+ /** Test seam: stop the refresh timer, reset liveCatalog to MODELS and clear the memo. */
463
472
  declare function resetLiveCatalog(): void;
464
473
 
465
474
  declare const IMAGE_MODELS: CatalogModel[];
@@ -516,4 +525,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
516
525
  /** Resolve caller options against a catalog row, dispatching on `model.type`. */
517
526
  declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
518
527
 
519
- export { ADAPTER_IDS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, type SupportedOption, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, isModelKitError, liveCatalog, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions };
528
+ export { ADAPTER_IDS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, type SupportedOption, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, isModelKitError, liveCatalog, liveState, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions };
package/dist/catalog.d.ts CHANGED
@@ -429,6 +429,15 @@ declare const ADAPTER_IDS: readonly ["ai-sdk-text", "google-image", "openai-imag
429
429
  declare const CatalogModelSchema: z.ZodType<CatalogModel>;
430
430
  declare const CatalogSchema: z.ZodType<CatalogModel[]>;
431
431
 
432
+ type CatalogOrigin = "remote" | "last-good" | "snapshot";
433
+ interface LiveCatalogState {
434
+ catalog: Catalog;
435
+ memo: Promise<unknown> | undefined;
436
+ timer: ReturnType<typeof setInterval> | undefined;
437
+ revision: string | undefined;
438
+ origin: CatalogOrigin;
439
+ }
440
+ declare const liveState: LiveCatalogState;
432
441
  declare const liveCatalog: Catalog;
433
442
 
434
443
  interface CatalogCache {
@@ -450,7 +459,7 @@ interface CatalogSource {
450
459
  fetch?: typeof fetch;
451
460
  logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
452
461
  }
453
- type CatalogOrigin = "remote" | "last-good" | "snapshot";
462
+
454
463
  interface PrimeCatalogResult {
455
464
  origin: CatalogOrigin;
456
465
  rowCount: number;
@@ -459,7 +468,7 @@ interface PrimeCatalogResult {
459
468
  }
460
469
  /** Fetch, validate, swap into liveCatalog. Never throws. Second call returns the same promise. */
461
470
  declare function primeCatalog(source: CatalogSource): Promise<PrimeCatalogResult>;
462
- /** Test seam: stop the refresh timer and reset liveCatalog to MODELS and clear the memo. */
471
+ /** Test seam: stop the refresh timer, reset liveCatalog to MODELS and clear the memo. */
463
472
  declare function resetLiveCatalog(): void;
464
473
 
465
474
  declare const IMAGE_MODELS: CatalogModel[];
@@ -516,4 +525,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
516
525
  /** Resolve caller options against a catalog row, dispatching on `model.type`. */
517
526
  declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
518
527
 
519
- export { ADAPTER_IDS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, type SupportedOption, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, isModelKitError, liveCatalog, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions };
528
+ export { ADAPTER_IDS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, type SupportedOption, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, isModelKitError, liveCatalog, liveState, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions };
package/dist/catalog.js CHANGED
@@ -118,7 +118,7 @@ var GEMINI_RATIOS = [
118
118
  "5:4",
119
119
  "adaptive"
120
120
  ];
121
- function geminiImage(id, label, aliases, sizes, display, exposure) {
121
+ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
122
122
  const model = {
123
123
  id,
124
124
  aliases,
@@ -131,7 +131,8 @@ function geminiImage(id, label, aliases, sizes, display, exposure) {
131
131
  constraints: {
132
132
  aspectRatios: [...GEMINI_RATIOS],
133
133
  sizes,
134
- supports: ["safetySettings", "temperature"]
134
+ supports: ["safetySettings", "temperature"],
135
+ ...references ? { references } : {}
135
136
  },
136
137
  defaults: { size: "1K", aspectRatio: "1:1" },
137
138
  usage: { ...IMAGE_USAGE, slug: "gemini" },
@@ -151,7 +152,8 @@ var IMAGE_MODELS = [
151
152
  description: "Create stunning, production-quality visuals with exceptional realism, detail, and typography. Best for campaigns, e-commerce, product photography, and hero creatives.",
152
153
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
153
154
  },
154
- "catalog"
155
+ "catalog",
156
+ { images: 14 }
155
157
  ),
156
158
  geminiImage(
157
159
  "gemini-3.1-flash-image-preview",
@@ -164,7 +166,8 @@ var IMAGE_MODELS = [
164
166
  description: "Generate high-quality images at speed. Perfect for brainstorming, moodboards, concept testing, creative exploration, and large batch workflows.",
165
167
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
166
168
  },
167
- "catalog"
169
+ "catalog",
170
+ { images: 14 }
168
171
  ),
169
172
  geminiImage(
170
173
  "gemini-3.1-flash-lite-image",
@@ -176,14 +179,15 @@ var IMAGE_MODELS = [
176
179
  description: "The fastest and most affordable image model. Ideal for rapid drafts, bulk exploration, and iterative concept testing at 1K resolution.",
177
180
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/192485d2-a76a-4657-9c06-930b2c70badd_compressed.png"
178
181
  },
179
- "catalog"
182
+ "catalog",
183
+ { images: 14 }
180
184
  ),
181
185
  // trigger-workflows validates 1K only; pricing seeds 2K/4K rows so allow all three.
182
186
  geminiImage(
183
187
  "gemini-2.5-flash-image",
184
188
  "Gemini 2.5 Flash Image",
185
189
  [],
186
- ["1K", "2K", "4K"],
190
+ ["1K"],
187
191
  {
188
192
  provider: "google",
189
193
  description: "Nano Banana (legacy Gemini 2.5 Flash Image) native image generation and editing model for high-volume, low-latency creative workflows."
@@ -214,7 +218,7 @@ var IMAGE_MODELS = [
214
218
  sizes: ["1K", "2K", "4K"],
215
219
  qualityOptions: ["auto", "low", "medium", "high"],
216
220
  references: { images: 16 },
217
- supports: ["quality", "count"]
221
+ supports: ["quality", "count", "outputFormat"]
218
222
  },
219
223
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
220
224
  usage: { ...IMAGE_USAGE, slug: "gpt" },
@@ -234,7 +238,7 @@ var IMAGE_MODELS = [
234
238
  adapter: "openai-image",
235
239
  providerModelId: "gpt-image-2.5-sunburst",
236
240
  lifecycle: "active",
237
- exposure: "internal",
241
+ exposure: "catalog",
238
242
  constraints: {
239
243
  exactSizes: {
240
244
  "1:1": "1024x1024",
@@ -247,9 +251,9 @@ var IMAGE_MODELS = [
247
251
  },
248
252
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
249
253
  sizes: ["1K", "2K", "4K"],
250
- qualityOptions: ["auto", "low", "medium", "high"],
254
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
251
255
  references: { images: 16 },
252
- supports: ["quality", "count"]
256
+ supports: ["quality", "count", "outputFormat"]
253
257
  },
254
258
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
255
259
  usage: { ...IMAGE_USAGE },
@@ -268,7 +272,7 @@ var IMAGE_MODELS = [
268
272
  adapter: "openai-image",
269
273
  providerModelId: "gpt-image-2.5-flare",
270
274
  lifecycle: "active",
271
- exposure: "internal",
275
+ exposure: "catalog",
272
276
  constraints: {
273
277
  exactSizes: {
274
278
  "1:1": "1024x1024",
@@ -281,9 +285,9 @@ var IMAGE_MODELS = [
281
285
  },
282
286
  aspectRatios: ["1:1", "3:2", "2:3", "16:9", "9:16", "4:5", "5:4", "adaptive"],
283
287
  sizes: ["1K", "2K", "4K"],
284
- qualityOptions: ["auto", "low", "medium", "high"],
288
+ qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
285
289
  references: { images: 16 },
286
- supports: ["quality", "count"]
290
+ supports: ["quality", "count", "outputFormat"]
287
291
  },
288
292
  defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
289
293
  usage: { ...IMAGE_USAGE },
@@ -313,8 +317,6 @@ var IMAGE_MODELS = [
313
317
  "2:3",
314
318
  "3:4",
315
319
  "9:16",
316
- "4:5",
317
- "5:4",
318
320
  "9:21",
319
321
  "adaptive"
320
322
  ],
@@ -346,7 +348,7 @@ var IMAGE_MODELS = [
346
348
  references: { images: 10 },
347
349
  // Ark's Images API has no output-format, quality or count field; only
348
350
  // the seed is forwarded, so anything else must warn, not vanish.
349
- supports: ["seed"]
351
+ supports: ["seed", "outputFormat"]
350
352
  },
351
353
  defaults: { size: "1K", aspectRatio: "1:1" },
352
354
  usage: { ...IMAGE_USAGE },
@@ -382,7 +384,7 @@ var IMAGE_MODELS = [
382
384
  "21:9",
383
385
  "9:21"
384
386
  ],
385
- sizes: ["1K", "2K", "4K"],
387
+ sizes: ["2K", "4K"],
386
388
  references: { images: 10 },
387
389
  supports: ["seed"]
388
390
  },
@@ -434,7 +436,7 @@ var IMAGE_MODELS = [
434
436
  aspectRatios: ["1:1", "2:3", "3:2", "4:3", "3:4", "4:5", "5:4", "9:16", "16:9", "21:9"],
435
437
  sizes: ["1K", "2K", "4K"],
436
438
  requires: ["references"],
437
- supports: ["seed"]
439
+ supports: []
438
440
  },
439
441
  defaults: { size: "1K", aspectRatio: "1:1" },
440
442
  usage: { ...IMAGE_USAGE },
@@ -459,7 +461,7 @@ var IMAGE_MODELS = [
459
461
  aspectRatios: ["1:1", "2:3", "3:4", "4:3", "9:16", "16:9", "21:9"],
460
462
  sizes: ["1K"],
461
463
  requires: ["references"],
462
- supports: ["seed"]
464
+ supports: []
463
465
  },
464
466
  defaults: { size: "1K", aspectRatio: "1:1" },
465
467
  usage: { ...IMAGE_USAGE },
@@ -511,7 +513,6 @@ var IMAGE_MODELS = [
511
513
  aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
512
514
  sizes: [],
513
515
  references: { images: 1 },
514
- requires: ["references"],
515
516
  supports: []
516
517
  },
517
518
  defaults: { aspectRatio: "1:1" },
@@ -1230,7 +1231,7 @@ var VIDEO_MODELS = [
1230
1231
  resolutions: ["720p", "1080p", "4k"],
1231
1232
  durations: [8],
1232
1233
  references: { images: 3 },
1233
- supports: ["lastFrame"]
1234
+ supports: ["lastFrame", "seed"]
1234
1235
  },
1235
1236
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1236
1237
  usage: { ...VIDEO_USAGE, slug: "veo" },
@@ -1258,9 +1259,9 @@ var VIDEO_MODELS = [
1258
1259
  constraints: {
1259
1260
  aspectRatios: [...OMNI_RATIOS],
1260
1261
  resolutions: ["720p", "1080p", "4k"],
1261
- durations: [4, 8],
1262
+ durations: [4, 6, 8],
1262
1263
  references: { images: 3 },
1263
- supports: ["lastFrame"]
1264
+ supports: ["lastFrame", "seed"]
1264
1265
  },
1265
1266
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1266
1267
  usage: { ...VIDEO_USAGE },
@@ -1287,9 +1288,8 @@ var VIDEO_MODELS = [
1287
1288
  constraints: {
1288
1289
  aspectRatios: [...OMNI_RATIOS],
1289
1290
  resolutions: ["720p", "1080p"],
1290
- durations: [4, 8],
1291
- references: { images: 3 },
1292
- supports: ["lastFrame"]
1291
+ durations: [4, 6, 8],
1292
+ supports: ["lastFrame", "seed"]
1293
1293
  },
1294
1294
  defaults: { durationSeconds: 8, resolution: "720p", aspectRatio: "16:9" },
1295
1295
  usage: { ...VIDEO_USAGE },
@@ -1321,7 +1321,7 @@ var VIDEO_MODELS = [
1321
1321
  // reference clip keeps its own framing.
1322
1322
  aspectRatios: [...OMNI_RATIOS],
1323
1323
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1324
- references: { images: 6, videos: 1 },
1324
+ references: { images: 6, videos: 3 },
1325
1325
  supports: []
1326
1326
  },
1327
1327
  defaults: {},
@@ -1347,7 +1347,7 @@ var VIDEO_MODELS = [
1347
1347
  aspectRatios: [...OMNI_RATIOS],
1348
1348
  resolutions: ["360p", "720p", "1080p", "4k"],
1349
1349
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1350
- references: { images: 6, videos: 1 },
1350
+ references: { images: 6, videos: 3 },
1351
1351
  supports: []
1352
1352
  },
1353
1353
  defaults: {},
@@ -1376,7 +1376,7 @@ var VIDEO_MODELS = [
1376
1376
  durations: { min: 4, max: 15 },
1377
1377
  durationPresets: [4, 6, 8, 10, 12, 15],
1378
1378
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1379
- ratioIgnoredWith: ["firstFrame"],
1379
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1380
1380
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1381
1381
  },
1382
1382
  defaults: {
@@ -1408,7 +1408,7 @@ var VIDEO_MODELS = [
1408
1408
  resolutions: ["480p", "720p"],
1409
1409
  durations: { min: 4, max: 15 },
1410
1410
  references: { images: 9, videos: 3, audios: 3, audioOnly: false },
1411
- ratioIgnoredWith: ["firstFrame"],
1411
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1412
1412
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1413
1413
  },
1414
1414
  defaults: {
@@ -1441,7 +1441,7 @@ var VIDEO_MODELS = [
1441
1441
  resolutions: ["480p", "720p", "1080p"],
1442
1442
  durations: { min: 4, max: 30 },
1443
1443
  references: { images: 30, videos: 10, audios: 10 },
1444
- ratioIgnoredWith: ["firstFrame"],
1444
+ ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1445
1445
  supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1446
1446
  },
1447
1447
  defaults: {
@@ -1560,18 +1560,7 @@ var VIDEO_MODELS = [
1560
1560
  lifecycle: "active",
1561
1561
  exposure: "catalog",
1562
1562
  constraints: {
1563
- aspectRatios: [
1564
- "1:1",
1565
- "16:9",
1566
- "9:16",
1567
- "4:3",
1568
- "3:4",
1569
- "3:2",
1570
- "2:3",
1571
- "21:9",
1572
- "4:5",
1573
- "adaptive"
1574
- ],
1563
+ aspectRatios: [...KLING_RATIOS],
1575
1564
  resolutions: ["720p", "1080p"],
1576
1565
  durations: { min: 3, max: 15 },
1577
1566
  references: { images: 7 },
@@ -2033,13 +2022,18 @@ var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
2033
2022
  });
2034
2023
 
2035
2024
  // src/catalog/live.ts
2036
- var liveCatalog = new Catalog(MODELS);
2025
+ var KEY = /* @__PURE__ */ Symbol.for("@shop-os/modelkit/live-catalog");
2026
+ var store = globalThis;
2027
+ var liveState = store[KEY] ??= {
2028
+ catalog: new Catalog(MODELS),
2029
+ memo: void 0,
2030
+ timer: void 0,
2031
+ revision: void 0,
2032
+ origin: "snapshot"
2033
+ };
2034
+ var liveCatalog = liveState.catalog;
2037
2035
 
2038
2036
  // src/catalog/load.ts
2039
- var memo;
2040
- var timer;
2041
- var revision;
2042
- var origin = "snapshot";
2043
2037
  function rowCount() {
2044
2038
  return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
2045
2039
  }
@@ -2069,7 +2063,7 @@ function logPrimed(logger, result) {
2069
2063
  async function fetchRemote(source, logger) {
2070
2064
  const fetchImpl = source.fetch ?? globalThis.fetch;
2071
2065
  const headers = authHeaders(source.auth);
2072
- if (revision !== void 0) headers["If-None-Match"] = `"${revision}"`;
2066
+ if (liveState.revision !== void 0) headers["If-None-Match"] = `"${liveState.revision}"`;
2073
2067
  const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
2074
2068
  headers,
2075
2069
  signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
@@ -2093,16 +2087,16 @@ async function prime(source, logger) {
2093
2087
  try {
2094
2088
  const fetched = await fetchRemote(source, logger);
2095
2089
  if ("kept" in fetched) {
2096
- const result2 = { origin, rowCount: rowCount() };
2097
- if (revision !== void 0) result2.revision = revision;
2090
+ const result2 = { origin: liveState.origin, rowCount: rowCount() };
2091
+ if (liveState.revision !== void 0) result2.revision = liveState.revision;
2098
2092
  logPrimed(logger, result2);
2099
2093
  return result2;
2100
2094
  }
2101
2095
  liveCatalog.replace(fetched.rows);
2102
- origin = "remote";
2103
- revision = fetched.revision;
2096
+ liveState.origin = "remote";
2097
+ liveState.revision = fetched.revision;
2104
2098
  await writeCache(source, logger, fetched.rows, fetched.revision);
2105
- const result = { origin, rowCount: rowCount() };
2099
+ const result = { origin: liveState.origin, rowCount: rowCount() };
2106
2100
  if (fetched.revision !== void 0) result.revision = fetched.revision;
2107
2101
  logPrimed(logger, result);
2108
2102
  return result;
@@ -2114,19 +2108,23 @@ async function prime(source, logger) {
2114
2108
  if (!cached) throw new Error("no cached catalog");
2115
2109
  const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
2116
2110
  liveCatalog.replace(rows);
2117
- origin = "last-good";
2118
- revision = rev;
2119
- const result = { origin, rowCount: rowCount(), error };
2111
+ liveState.origin = "last-good";
2112
+ liveState.revision = rev;
2113
+ const result = {
2114
+ origin: liveState.origin,
2115
+ rowCount: rowCount(),
2116
+ error
2117
+ };
2120
2118
  if (rev !== void 0) result.revision = rev;
2121
2119
  logPrimed(logger, result);
2122
2120
  return result;
2123
2121
  } catch (cacheErr) {
2124
2122
  logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2125
2123
  liveCatalog.replace([...MODELS]);
2126
- origin = "snapshot";
2127
- revision = void 0;
2124
+ liveState.origin = "snapshot";
2125
+ liveState.revision = void 0;
2128
2126
  const result = {
2129
- origin,
2127
+ origin: liveState.origin,
2130
2128
  rowCount: rowCount(),
2131
2129
  error
2132
2130
  };
@@ -2140,35 +2138,36 @@ async function refresh(source, logger) {
2140
2138
  const fetched = await fetchRemote(source, logger);
2141
2139
  if ("kept" in fetched) return;
2142
2140
  liveCatalog.replace(fetched.rows);
2143
- origin = "remote";
2144
- revision = fetched.revision;
2141
+ liveState.origin = "remote";
2142
+ liveState.revision = fetched.revision;
2145
2143
  await writeCache(source, logger, fetched.rows, fetched.revision);
2146
2144
  } catch (err) {
2147
2145
  logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2148
2146
  }
2149
2147
  }
2150
2148
  function primeCatalog(source) {
2149
+ const memo = liveState.memo;
2151
2150
  if (memo) return memo;
2152
2151
  const logger = source.logger ?? console;
2153
- memo = prime(source, logger).then((result) => {
2152
+ liveState.memo = prime(source, logger).then((result) => {
2154
2153
  const ttlMs = source.ttlMs ?? 3e5;
2155
- if (ttlMs > 0 && timer === void 0) {
2156
- timer = setInterval(() => void refresh(source, logger), ttlMs);
2157
- const maybeUnref = timer;
2154
+ if (ttlMs > 0 && liveState.timer === void 0) {
2155
+ liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
2156
+ const maybeUnref = liveState.timer;
2158
2157
  maybeUnref.unref?.();
2159
2158
  }
2160
2159
  return result;
2161
2160
  });
2162
- return memo;
2161
+ return liveState.memo;
2163
2162
  }
2164
2163
  function resetLiveCatalog() {
2165
- if (timer !== void 0) {
2166
- clearInterval(timer);
2167
- timer = void 0;
2164
+ if (liveState.timer !== void 0) {
2165
+ clearInterval(liveState.timer);
2166
+ liveState.timer = void 0;
2168
2167
  }
2169
- memo = void 0;
2170
- revision = void 0;
2171
- origin = "snapshot";
2168
+ liveState.memo = void 0;
2169
+ liveState.revision = void 0;
2170
+ liveState.origin = "snapshot";
2172
2171
  liveCatalog.replace([...MODELS]);
2173
2172
  }
2174
2173
 
@@ -2566,6 +2565,7 @@ export {
2566
2565
  VIDEO_MODELS,
2567
2566
  isModelKitError,
2568
2567
  liveCatalog,
2568
+ liveState,
2569
2569
  nearestAspectRatio,
2570
2570
  primeCatalog,
2571
2571
  resetLiveCatalog,