@shop-os/modelkit 0.2.3 → 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) {
@@ -264,7 +281,6 @@ var IMAGE_MODELS = [
264
281
  pricingKind: "image_size",
265
282
  display: {
266
283
  provider: "openai",
267
- sortOrder: 20,
268
284
  description: "OpenAI's most capable GPT Image 2.5 tier, built for editing precision; takes text and image input and outputs images in low, medium, high, xhigh, or max quality."
269
285
  }
270
286
  },
@@ -299,7 +315,6 @@ var IMAGE_MODELS = [
299
315
  pricingKind: "image_size",
300
316
  display: {
301
317
  provider: "openai",
302
- sortOrder: 10,
303
318
  description: "OpenAI's fastest GPT Image 2.5 tier for high-quality everyday image generation and editing; takes text and image input and outputs images."
304
319
  }
305
320
  },
@@ -2057,13 +2072,14 @@ function toEnvelope(data) {
2057
2072
  if (data.revision !== void 0) envelope.revision = data.revision;
2058
2073
  return envelope;
2059
2074
  }
2075
+ function describeError(err) {
2076
+ return err instanceof Error ? err.message : String(err);
2077
+ }
2060
2078
  function logPrimed(logger, result) {
2061
- const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
2062
- logger.info("[modelkit] catalog primed", {
2063
- origin: loggedOrigin,
2064
- rowCount: loggedCount,
2065
- revision: loggedRevision
2066
- });
2079
+ const revision = result.revision === void 0 ? "" : ` revision=${result.revision}`;
2080
+ logger.info(
2081
+ `[modelkit] catalog primed origin=${result.origin} rowCount=${result.rowCount}${revision}`
2082
+ );
2067
2083
  }
2068
2084
  async function fetchRemote(source, logger) {
2069
2085
  const fetchImpl = source.fetch ?? globalThis.fetch;
@@ -2087,7 +2103,7 @@ async function writeCache(source, logger, rows, rev) {
2087
2103
  try {
2088
2104
  await source.cache.set(JSON.stringify({ rows, revision: rev }));
2089
2105
  } catch (err) {
2090
- logger.warn("[modelkit] catalog cache write failed", err);
2106
+ logger.warn(`[modelkit] catalog cache write failed: ${describeError(err)}`);
2091
2107
  }
2092
2108
  }
2093
2109
  async function prime(source, logger) {
@@ -2108,8 +2124,8 @@ async function prime(source, logger) {
2108
2124
  logPrimed(logger, result);
2109
2125
  return result;
2110
2126
  } catch (err) {
2111
- logger.warn("[modelkit] catalog remote failed, trying cache", err);
2112
- const error = err instanceof Error ? err.message : String(err);
2127
+ logger.warn(`[modelkit] catalog remote failed, trying cache: ${describeError(err)}`);
2128
+ const error = describeError(err);
2113
2129
  try {
2114
2130
  const cached = await source.cache?.get();
2115
2131
  if (!cached) throw new Error("no cached catalog");
@@ -2128,7 +2144,9 @@ async function prime(source, logger) {
2128
2144
  logPrimed(logger, result);
2129
2145
  return result;
2130
2146
  } catch (cacheErr) {
2131
- logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2147
+ logger.warn(
2148
+ `[modelkit] catalog cache failed, using snapshot: ${describeError(cacheErr)}`
2149
+ );
2132
2150
  liveCatalog.replace([...MODELS]);
2133
2151
  liveState.origin = "snapshot";
2134
2152
  liveState.revision = void 0;
@@ -2151,7 +2169,9 @@ async function refresh(source, logger) {
2151
2169
  liveState.revision = fetched.revision;
2152
2170
  await writeCache(source, logger, fetched.rows, fetched.revision);
2153
2171
  } catch (err) {
2154
- logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2172
+ logger.warn(
2173
+ `[modelkit] catalog refresh failed, keeping current rows: ${describeError(err)}`
2174
+ );
2155
2175
  }
2156
2176
  }
2157
2177
  function primeCatalog(source) {
@@ -7335,6 +7355,7 @@ export {
7335
7355
  arkAdapter,
7336
7356
  aspectRatioToSize,
7337
7357
  classifyHttpError,
7358
+ compareCatalogOrder,
7338
7359
  createDefaultModelKit,
7339
7360
  createModelKit,
7340
7361
  describe,
@@ -7372,6 +7393,7 @@ export {
7372
7393
  resolveVideoOptions,
7373
7394
  shouldRetry,
7374
7395
  sleep,
7396
+ sortCatalogRows,
7375
7397
  streamObject,
7376
7398
  streamText,
7377
7399
  textUsageEvent,