@shop-os/modelkit 0.2.4 → 0.2.5

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) {
@@ -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,