@shop-os/modelkit 0.2.4 → 0.2.6

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.
@@ -413,6 +413,7 @@ declare class Catalog {
413
413
  resolveId(idOrAlias: string): string | undefined;
414
414
  get(idOrAlias: string): CatalogModel | undefined;
415
415
  require(idOrAlias: string): CatalogModel;
416
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
416
417
  list(filter?: {
417
418
  type?: ModelType;
418
419
  lifecycle?: Lifecycle[];
@@ -423,6 +424,18 @@ declare class Catalog {
423
424
  replace(rows: CatalogModel[]): void;
424
425
  }
425
426
 
427
+ /**
428
+ * Picker order for every surface: `display.sortOrder` descending (a higher
429
+ * number shows first), rows without one after the ordered ones, then `label`
430
+ * ascending (case-insensitive), then `id` so the order is total.
431
+ *
432
+ * pro-backend applies the same rule in SQL (`ORDER BY sortOrder DESC NULLS
433
+ * LAST, lower(label), id`); this comparator covers the snapshot and cache
434
+ * fallbacks and any consumer that sorts a subset.
435
+ */
436
+ declare function compareCatalogOrder(a: CatalogModel, b: CatalogModel): number;
437
+ declare function sortCatalogRows<T extends CatalogModel>(rows: readonly T[]): T[];
438
+
426
439
  /** Seeded from Cowork, Space Builder and trigger-workflows. See catalog/*.ts. */
427
440
  declare const MODELS: CatalogModel[];
428
441
 
@@ -532,4 +545,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
532
545
  /** Resolve caller options against a catalog row, dispatching on `model.type`. */
533
546
  declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
534
547
 
535
- 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 CatalogEnvelope, 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 };
548
+ 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 CatalogEnvelope, 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, compareCatalogOrder, isModelKitError, liveCatalog, liveState, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows };
package/dist/catalog.d.ts CHANGED
@@ -413,6 +413,7 @@ declare class Catalog {
413
413
  resolveId(idOrAlias: string): string | undefined;
414
414
  get(idOrAlias: string): CatalogModel | undefined;
415
415
  require(idOrAlias: string): CatalogModel;
416
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
416
417
  list(filter?: {
417
418
  type?: ModelType;
418
419
  lifecycle?: Lifecycle[];
@@ -423,6 +424,18 @@ declare class Catalog {
423
424
  replace(rows: CatalogModel[]): void;
424
425
  }
425
426
 
427
+ /**
428
+ * Picker order for every surface: `display.sortOrder` descending (a higher
429
+ * number shows first), rows without one after the ordered ones, then `label`
430
+ * ascending (case-insensitive), then `id` so the order is total.
431
+ *
432
+ * pro-backend applies the same rule in SQL (`ORDER BY sortOrder DESC NULLS
433
+ * LAST, lower(label), id`); this comparator covers the snapshot and cache
434
+ * fallbacks and any consumer that sorts a subset.
435
+ */
436
+ declare function compareCatalogOrder(a: CatalogModel, b: CatalogModel): number;
437
+ declare function sortCatalogRows<T extends CatalogModel>(rows: readonly T[]): T[];
438
+
426
439
  /** Seeded from Cowork, Space Builder and trigger-workflows. See catalog/*.ts. */
427
440
  declare const MODELS: CatalogModel[];
428
441
 
@@ -532,4 +545,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
532
545
  /** Resolve caller options against a catalog row, dispatching on `model.type`. */
533
546
  declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
534
547
 
535
- 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 CatalogEnvelope, 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 };
548
+ 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 CatalogEnvelope, 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, compareCatalogOrder, isModelKitError, liveCatalog, liveState, nearestAspectRatio, primeCatalog, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows };
package/dist/catalog.js CHANGED
@@ -24,6 +24,22 @@ function isModelKitError(err) {
24
24
  return err instanceof ModelKitError;
25
25
  }
26
26
 
27
+ // src/catalog/order.ts
28
+ function compareCatalogOrder(a, b) {
29
+ const sa = a.display?.sortOrder;
30
+ const sb = b.display?.sortOrder;
31
+ if (sa !== void 0 && sb !== void 0 && sa !== sb) return sb - sa;
32
+ if (sa !== void 0 && sb === void 0) return -1;
33
+ if (sa === void 0 && sb !== void 0) return 1;
34
+ return compareText(a.label.toLowerCase(), b.label.toLowerCase()) || compareText(a.id, b.id);
35
+ }
36
+ function compareText(a, b) {
37
+ return a < b ? -1 : a > b ? 1 : 0;
38
+ }
39
+ function sortCatalogRows(rows) {
40
+ return [...rows].sort(compareCatalogOrder);
41
+ }
42
+
27
43
  // src/catalog/registry.ts
28
44
  var Catalog = class _Catalog {
29
45
  byId = /* @__PURE__ */ new Map();
@@ -80,11 +96,12 @@ var Catalog = class _Catalog {
80
96
  }
81
97
  return model;
82
98
  }
99
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
83
100
  list(filter = {}) {
84
101
  const lifecycles = filter.lifecycle ?? ["active"];
85
102
  return [...this.byId.values()].filter(
86
103
  (m) => (filter.type ? m.type === filter.type : true) && lifecycles.includes(m.lifecycle)
87
- );
104
+ ).sort(compareCatalogOrder);
88
105
  }
89
106
  /** Merge rows by id. Used for catalogOverride. */
90
107
  withOverrides(rows) {
@@ -1322,7 +1339,7 @@ var VIDEO_MODELS = [
1322
1339
  // reference clip keeps its own framing.
1323
1340
  aspectRatios: [...OMNI_RATIOS],
1324
1341
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1325
- references: { images: 6, videos: 3 },
1342
+ references: { images: 6, videos: 1 },
1326
1343
  supports: []
1327
1344
  },
1328
1345
  defaults: {},
@@ -1348,7 +1365,7 @@ var VIDEO_MODELS = [
1348
1365
  aspectRatios: [...OMNI_RATIOS],
1349
1366
  resolutions: ["360p", "720p", "1080p", "4k"],
1350
1367
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1351
- references: { images: 6, videos: 3 },
1368
+ references: { images: 6, videos: 1 },
1352
1369
  supports: []
1353
1370
  },
1354
1371
  defaults: {},
@@ -1475,7 +1492,7 @@ var VIDEO_MODELS = [
1475
1492
  resolutions: ["480p", "720p"],
1476
1493
  durations: { min: 1, max: 15 },
1477
1494
  durationPresets: [4, 6, 8, 10],
1478
- references: { images: 7 },
1495
+ references: { images: 5 },
1479
1496
  supports: []
1480
1497
  },
1481
1498
  // No resolution default: xAI picks its own unless the caller asks.
@@ -1484,7 +1501,7 @@ var VIDEO_MODELS = [
1484
1501
  pricingKind: "video_per_second",
1485
1502
  display: {
1486
1503
  provider: "xai",
1487
- description: "xAI's reference-to-video model. Generates short clips conditioned on up to 7 reference images with flexible aspect ratios.",
1504
+ description: "xAI's reference-to-video model. Generates short clips conditioned on up to 5 reference images with flexible aspect ratios.",
1488
1505
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/858b7fcc-9bd5-411d-aea1-a7b35ecfffab_compressed.png"
1489
1506
  },
1490
1507
  capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
@@ -2571,6 +2588,7 @@ export {
2571
2588
  OTHER_MODELS,
2572
2589
  TEXT_MODELS,
2573
2590
  VIDEO_MODELS,
2591
+ compareCatalogOrder,
2574
2592
  isModelKitError,
2575
2593
  liveCatalog,
2576
2594
  liveState,
@@ -2580,6 +2598,7 @@ export {
2580
2598
  resolveAudioOptions,
2581
2599
  resolveImageOptions,
2582
2600
  resolveOptions,
2583
- resolveVideoOptions
2601
+ resolveVideoOptions,
2602
+ sortCatalogRows
2584
2603
  };
2585
2604
  //# sourceMappingURL=catalog.js.map