@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.
package/dist/index.d.cts CHANGED
@@ -440,6 +440,7 @@ declare class Catalog {
440
440
  resolveId(idOrAlias: string): string | undefined;
441
441
  get(idOrAlias: string): CatalogModel | undefined;
442
442
  require(idOrAlias: string): CatalogModel;
443
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
443
444
  list(filter?: {
444
445
  type?: ModelType;
445
446
  lifecycle?: Lifecycle[];
@@ -450,6 +451,18 @@ declare class Catalog {
450
451
  replace(rows: CatalogModel[]): void;
451
452
  }
452
453
 
454
+ /**
455
+ * Picker order for every surface: `display.sortOrder` descending (a higher
456
+ * number shows first), rows without one after the ordered ones, then `label`
457
+ * ascending (case-insensitive), then `id` so the order is total.
458
+ *
459
+ * pro-backend applies the same rule in SQL (`ORDER BY sortOrder DESC NULLS
460
+ * LAST, lower(label), id`); this comparator covers the snapshot and cache
461
+ * fallbacks and any consumer that sorts a subset.
462
+ */
463
+ declare function compareCatalogOrder(a: CatalogModel, b: CatalogModel): number;
464
+ declare function sortCatalogRows<T extends CatalogModel>(rows: readonly T[]): T[];
465
+
453
466
  /** Seeded from Cowork, Space Builder and trigger-workflows. See catalog/*.ts. */
454
467
  declare const MODELS: CatalogModel[];
455
468
 
@@ -748,4 +761,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
748
761
  /** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
749
762
  declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
750
763
 
751
- export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, 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 CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, 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, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
764
+ export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, 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 CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, 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, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
package/dist/index.d.ts CHANGED
@@ -440,6 +440,7 @@ declare class Catalog {
440
440
  resolveId(idOrAlias: string): string | undefined;
441
441
  get(idOrAlias: string): CatalogModel | undefined;
442
442
  require(idOrAlias: string): CatalogModel;
443
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
443
444
  list(filter?: {
444
445
  type?: ModelType;
445
446
  lifecycle?: Lifecycle[];
@@ -450,6 +451,18 @@ declare class Catalog {
450
451
  replace(rows: CatalogModel[]): void;
451
452
  }
452
453
 
454
+ /**
455
+ * Picker order for every surface: `display.sortOrder` descending (a higher
456
+ * number shows first), rows without one after the ordered ones, then `label`
457
+ * ascending (case-insensitive), then `id` so the order is total.
458
+ *
459
+ * pro-backend applies the same rule in SQL (`ORDER BY sortOrder DESC NULLS
460
+ * LAST, lower(label), id`); this comparator covers the snapshot and cache
461
+ * fallbacks and any consumer that sorts a subset.
462
+ */
463
+ declare function compareCatalogOrder(a: CatalogModel, b: CatalogModel): number;
464
+ declare function sortCatalogRows<T extends CatalogModel>(rows: readonly T[]): T[];
465
+
453
466
  /** Seeded from Cowork, Space Builder and trigger-workflows. See catalog/*.ts. */
454
467
  declare const MODELS: CatalogModel[];
455
468
 
@@ -748,4 +761,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
748
761
  /** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
749
762
  declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
750
763
 
751
- export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, 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 CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, 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, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
764
+ export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, 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 CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, 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, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
package/dist/index.js CHANGED
@@ -27,6 +27,22 @@ function isModelKitError(err) {
27
27
  return err instanceof ModelKitError;
28
28
  }
29
29
 
30
+ // src/catalog/order.ts
31
+ function compareCatalogOrder(a, b) {
32
+ const sa = a.display?.sortOrder;
33
+ const sb = b.display?.sortOrder;
34
+ if (sa !== void 0 && sb !== void 0 && sa !== sb) return sb - sa;
35
+ if (sa !== void 0 && sb === void 0) return -1;
36
+ if (sa === void 0 && sb !== void 0) return 1;
37
+ return compareText(a.label.toLowerCase(), b.label.toLowerCase()) || compareText(a.id, b.id);
38
+ }
39
+ function compareText(a, b) {
40
+ return a < b ? -1 : a > b ? 1 : 0;
41
+ }
42
+ function sortCatalogRows(rows) {
43
+ return [...rows].sort(compareCatalogOrder);
44
+ }
45
+
30
46
  // src/catalog/registry.ts
31
47
  var Catalog = class _Catalog {
32
48
  byId = /* @__PURE__ */ new Map();
@@ -83,11 +99,12 @@ var Catalog = class _Catalog {
83
99
  }
84
100
  return model;
85
101
  }
102
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
86
103
  list(filter = {}) {
87
104
  const lifecycles = filter.lifecycle ?? ["active"];
88
105
  return [...this.byId.values()].filter(
89
106
  (m) => (filter.type ? m.type === filter.type : true) && lifecycles.includes(m.lifecycle)
90
- );
107
+ ).sort(compareCatalogOrder);
91
108
  }
92
109
  /** Merge rows by id. Used for catalogOverride. */
93
110
  withOverrides(rows) {
@@ -1325,7 +1342,7 @@ var VIDEO_MODELS = [
1325
1342
  // reference clip keeps its own framing.
1326
1343
  aspectRatios: [...OMNI_RATIOS],
1327
1344
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1328
- references: { images: 6, videos: 3 },
1345
+ references: { images: 6, videos: 1 },
1329
1346
  supports: []
1330
1347
  },
1331
1348
  defaults: {},
@@ -1351,7 +1368,7 @@ var VIDEO_MODELS = [
1351
1368
  aspectRatios: [...OMNI_RATIOS],
1352
1369
  resolutions: ["360p", "720p", "1080p", "4k"],
1353
1370
  durations: [3, 4, 5, 6, 7, 8, 9, 10],
1354
- references: { images: 6, videos: 3 },
1371
+ references: { images: 6, videos: 1 },
1355
1372
  supports: []
1356
1373
  },
1357
1374
  defaults: {},
@@ -1478,7 +1495,7 @@ var VIDEO_MODELS = [
1478
1495
  resolutions: ["480p", "720p"],
1479
1496
  durations: { min: 1, max: 15 },
1480
1497
  durationPresets: [4, 6, 8, 10],
1481
- references: { images: 7 },
1498
+ references: { images: 5 },
1482
1499
  supports: []
1483
1500
  },
1484
1501
  // No resolution default: xAI picks its own unless the caller asks.
@@ -1487,7 +1504,7 @@ var VIDEO_MODELS = [
1487
1504
  pricingKind: "video_per_second",
1488
1505
  display: {
1489
1506
  provider: "xai",
1490
- description: "xAI's reference-to-video model. Generates short clips conditioned on up to 7 reference images with flexible aspect ratios.",
1507
+ description: "xAI's reference-to-video model. Generates short clips conditioned on up to 5 reference images with flexible aspect ratios.",
1491
1508
  logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/858b7fcc-9bd5-411d-aea1-a7b35ecfffab_compressed.png"
1492
1509
  },
1493
1510
  capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
@@ -7163,7 +7180,7 @@ async function generateXaiVideo(req, ctx, deps) {
7163
7180
  retryable: false
7164
7181
  });
7165
7182
  }
7166
- const refUrls = (req.referenceImages ?? []).map(refToUrl).slice(0, 7);
7183
+ const refUrls = (req.referenceImages ?? []).map(refToUrl).slice(0, 5);
7167
7184
  const xaiOptions = {
7168
7185
  pollIntervalMs: POLL_INTERVAL_MS2,
7169
7186
  pollTimeoutMs: POLL_TIMEOUT_MS2
@@ -7338,6 +7355,7 @@ export {
7338
7355
  arkAdapter,
7339
7356
  aspectRatioToSize,
7340
7357
  classifyHttpError,
7358
+ compareCatalogOrder,
7341
7359
  createDefaultModelKit,
7342
7360
  createModelKit,
7343
7361
  describe,
@@ -7375,6 +7393,7 @@ export {
7375
7393
  resolveVideoOptions,
7376
7394
  shouldRetry,
7377
7395
  sleep,
7396
+ sortCatalogRows,
7378
7397
  streamObject,
7379
7398
  streamText,
7380
7399
  textUsageEvent,