@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/CHANGELOG.md +10 -0
- package/dist/catalog.cjs +37 -15
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +14 -1
- package/dist/catalog.d.ts +14 -1
- package/dist/catalog.js +37 -15
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +36 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/catalog.d.cts
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.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) {
|
|
@@ -261,7 +278,6 @@ var IMAGE_MODELS = [
|
|
|
261
278
|
pricingKind: "image_size",
|
|
262
279
|
display: {
|
|
263
280
|
provider: "openai",
|
|
264
|
-
sortOrder: 20,
|
|
265
281
|
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."
|
|
266
282
|
}
|
|
267
283
|
},
|
|
@@ -296,7 +312,6 @@ var IMAGE_MODELS = [
|
|
|
296
312
|
pricingKind: "image_size",
|
|
297
313
|
display: {
|
|
298
314
|
provider: "openai",
|
|
299
|
-
sortOrder: 10,
|
|
300
315
|
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."
|
|
301
316
|
}
|
|
302
317
|
},
|
|
@@ -2054,13 +2069,14 @@ function toEnvelope(data) {
|
|
|
2054
2069
|
if (data.revision !== void 0) envelope.revision = data.revision;
|
|
2055
2070
|
return envelope;
|
|
2056
2071
|
}
|
|
2072
|
+
function describeError(err) {
|
|
2073
|
+
return err instanceof Error ? err.message : String(err);
|
|
2074
|
+
}
|
|
2057
2075
|
function logPrimed(logger, result) {
|
|
2058
|
-
const
|
|
2059
|
-
logger.info(
|
|
2060
|
-
origin
|
|
2061
|
-
|
|
2062
|
-
revision: loggedRevision
|
|
2063
|
-
});
|
|
2076
|
+
const revision = result.revision === void 0 ? "" : ` revision=${result.revision}`;
|
|
2077
|
+
logger.info(
|
|
2078
|
+
`[modelkit] catalog primed origin=${result.origin} rowCount=${result.rowCount}${revision}`
|
|
2079
|
+
);
|
|
2064
2080
|
}
|
|
2065
2081
|
async function fetchRemote(source, logger) {
|
|
2066
2082
|
const fetchImpl = source.fetch ?? globalThis.fetch;
|
|
@@ -2084,7 +2100,7 @@ async function writeCache(source, logger, rows, rev) {
|
|
|
2084
2100
|
try {
|
|
2085
2101
|
await source.cache.set(JSON.stringify({ rows, revision: rev }));
|
|
2086
2102
|
} catch (err) {
|
|
2087
|
-
logger.warn(
|
|
2103
|
+
logger.warn(`[modelkit] catalog cache write failed: ${describeError(err)}`);
|
|
2088
2104
|
}
|
|
2089
2105
|
}
|
|
2090
2106
|
async function prime(source, logger) {
|
|
@@ -2105,8 +2121,8 @@ async function prime(source, logger) {
|
|
|
2105
2121
|
logPrimed(logger, result);
|
|
2106
2122
|
return result;
|
|
2107
2123
|
} catch (err) {
|
|
2108
|
-
logger.warn(
|
|
2109
|
-
const error =
|
|
2124
|
+
logger.warn(`[modelkit] catalog remote failed, trying cache: ${describeError(err)}`);
|
|
2125
|
+
const error = describeError(err);
|
|
2110
2126
|
try {
|
|
2111
2127
|
const cached = await source.cache?.get();
|
|
2112
2128
|
if (!cached) throw new Error("no cached catalog");
|
|
@@ -2125,7 +2141,9 @@ async function prime(source, logger) {
|
|
|
2125
2141
|
logPrimed(logger, result);
|
|
2126
2142
|
return result;
|
|
2127
2143
|
} catch (cacheErr) {
|
|
2128
|
-
logger.warn(
|
|
2144
|
+
logger.warn(
|
|
2145
|
+
`[modelkit] catalog cache failed, using snapshot: ${describeError(cacheErr)}`
|
|
2146
|
+
);
|
|
2129
2147
|
liveCatalog.replace([...MODELS]);
|
|
2130
2148
|
liveState.origin = "snapshot";
|
|
2131
2149
|
liveState.revision = void 0;
|
|
@@ -2148,7 +2166,9 @@ async function refresh(source, logger) {
|
|
|
2148
2166
|
liveState.revision = fetched.revision;
|
|
2149
2167
|
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2150
2168
|
} catch (err) {
|
|
2151
|
-
logger.warn(
|
|
2169
|
+
logger.warn(
|
|
2170
|
+
`[modelkit] catalog refresh failed, keeping current rows: ${describeError(err)}`
|
|
2171
|
+
);
|
|
2152
2172
|
}
|
|
2153
2173
|
}
|
|
2154
2174
|
function primeCatalog(source) {
|
|
@@ -2568,6 +2588,7 @@ export {
|
|
|
2568
2588
|
OTHER_MODELS,
|
|
2569
2589
|
TEXT_MODELS,
|
|
2570
2590
|
VIDEO_MODELS,
|
|
2591
|
+
compareCatalogOrder,
|
|
2571
2592
|
isModelKitError,
|
|
2572
2593
|
liveCatalog,
|
|
2573
2594
|
liveState,
|
|
@@ -2577,6 +2598,7 @@ export {
|
|
|
2577
2598
|
resolveAudioOptions,
|
|
2578
2599
|
resolveImageOptions,
|
|
2579
2600
|
resolveOptions,
|
|
2580
|
-
resolveVideoOptions
|
|
2601
|
+
resolveVideoOptions,
|
|
2602
|
+
sortCatalogRows
|
|
2581
2603
|
};
|
|
2582
2604
|
//# sourceMappingURL=catalog.js.map
|