@shop-os/modelkit 0.2.2 → 0.2.3
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 +8 -0
- package/dist/catalog.cjs +31 -26
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +16 -9
- package/dist/catalog.d.ts +16 -9
- package/dist/catalog.js +31 -26
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +147 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.js +147 -139
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/catalog.d.cts
CHANGED
|
@@ -219,8 +219,9 @@ interface CatalogDisplay {
|
|
|
219
219
|
/** Chat picker highlight flag. */
|
|
220
220
|
recommended?: boolean;
|
|
221
221
|
/**
|
|
222
|
-
* Picker position:
|
|
223
|
-
* after the ordered ones.
|
|
222
|
+
* Picker position: higher comes first; rows without one keep catalog order
|
|
223
|
+
* after the ordered ones. Give a new model the next number up to surface
|
|
224
|
+
* it at the top.
|
|
224
225
|
*/
|
|
225
226
|
sortOrder?: number;
|
|
226
227
|
/**
|
|
@@ -430,10 +431,18 @@ declare const CatalogModelSchema: z.ZodType<CatalogModel>;
|
|
|
430
431
|
declare const CatalogSchema: z.ZodType<CatalogModel[]>;
|
|
431
432
|
|
|
432
433
|
type CatalogOrigin = "remote" | "last-good" | "snapshot";
|
|
434
|
+
interface PrimeCatalogResult {
|
|
435
|
+
origin: CatalogOrigin;
|
|
436
|
+
rowCount: number;
|
|
437
|
+
revision?: string;
|
|
438
|
+
error?: string;
|
|
439
|
+
}
|
|
433
440
|
interface LiveCatalogState {
|
|
434
441
|
catalog: Catalog;
|
|
435
|
-
memo: Promise<
|
|
436
|
-
timer: ReturnType<typeof setInterval>
|
|
442
|
+
memo: Promise<PrimeCatalogResult> | undefined;
|
|
443
|
+
timer: (ReturnType<typeof setInterval> & {
|
|
444
|
+
unref?: () => void;
|
|
445
|
+
}) | undefined;
|
|
437
446
|
revision: string | undefined;
|
|
438
447
|
origin: CatalogOrigin;
|
|
439
448
|
}
|
|
@@ -460,11 +469,9 @@ interface CatalogSource {
|
|
|
460
469
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
461
470
|
}
|
|
462
471
|
|
|
463
|
-
interface
|
|
464
|
-
|
|
465
|
-
rowCount: number;
|
|
472
|
+
interface CatalogEnvelope {
|
|
473
|
+
rows: CatalogModel[];
|
|
466
474
|
revision?: string;
|
|
467
|
-
error?: string;
|
|
468
475
|
}
|
|
469
476
|
/** Fetch, validate, swap into liveCatalog. Never throws. Second call returns the same promise. */
|
|
470
477
|
declare function primeCatalog(source: CatalogSource): Promise<PrimeCatalogResult>;
|
|
@@ -525,4 +532,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
|
|
|
525
532
|
/** Resolve caller options against a catalog row, dispatching on `model.type`. */
|
|
526
533
|
declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
|
|
527
534
|
|
|
528
|
-
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 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 };
|
|
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 };
|
package/dist/catalog.d.ts
CHANGED
|
@@ -219,8 +219,9 @@ interface CatalogDisplay {
|
|
|
219
219
|
/** Chat picker highlight flag. */
|
|
220
220
|
recommended?: boolean;
|
|
221
221
|
/**
|
|
222
|
-
* Picker position:
|
|
223
|
-
* after the ordered ones.
|
|
222
|
+
* Picker position: higher comes first; rows without one keep catalog order
|
|
223
|
+
* after the ordered ones. Give a new model the next number up to surface
|
|
224
|
+
* it at the top.
|
|
224
225
|
*/
|
|
225
226
|
sortOrder?: number;
|
|
226
227
|
/**
|
|
@@ -430,10 +431,18 @@ declare const CatalogModelSchema: z.ZodType<CatalogModel>;
|
|
|
430
431
|
declare const CatalogSchema: z.ZodType<CatalogModel[]>;
|
|
431
432
|
|
|
432
433
|
type CatalogOrigin = "remote" | "last-good" | "snapshot";
|
|
434
|
+
interface PrimeCatalogResult {
|
|
435
|
+
origin: CatalogOrigin;
|
|
436
|
+
rowCount: number;
|
|
437
|
+
revision?: string;
|
|
438
|
+
error?: string;
|
|
439
|
+
}
|
|
433
440
|
interface LiveCatalogState {
|
|
434
441
|
catalog: Catalog;
|
|
435
|
-
memo: Promise<
|
|
436
|
-
timer: ReturnType<typeof setInterval>
|
|
442
|
+
memo: Promise<PrimeCatalogResult> | undefined;
|
|
443
|
+
timer: (ReturnType<typeof setInterval> & {
|
|
444
|
+
unref?: () => void;
|
|
445
|
+
}) | undefined;
|
|
437
446
|
revision: string | undefined;
|
|
438
447
|
origin: CatalogOrigin;
|
|
439
448
|
}
|
|
@@ -460,11 +469,9 @@ interface CatalogSource {
|
|
|
460
469
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
461
470
|
}
|
|
462
471
|
|
|
463
|
-
interface
|
|
464
|
-
|
|
465
|
-
rowCount: number;
|
|
472
|
+
interface CatalogEnvelope {
|
|
473
|
+
rows: CatalogModel[];
|
|
466
474
|
revision?: string;
|
|
467
|
-
error?: string;
|
|
468
475
|
}
|
|
469
476
|
/** Fetch, validate, swap into liveCatalog. Never throws. Second call returns the same promise. */
|
|
470
477
|
declare function primeCatalog(source: CatalogSource): Promise<PrimeCatalogResult>;
|
|
@@ -525,4 +532,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
|
|
|
525
532
|
/** Resolve caller options against a catalog row, dispatching on `model.type`. */
|
|
526
533
|
declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
|
|
527
534
|
|
|
528
|
-
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 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 };
|
|
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 };
|
package/dist/catalog.js
CHANGED
|
@@ -119,6 +119,12 @@ var GEMINI_RATIOS = [
|
|
|
119
119
|
"adaptive"
|
|
120
120
|
];
|
|
121
121
|
function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
122
|
+
const constraints = {
|
|
123
|
+
aspectRatios: [...GEMINI_RATIOS],
|
|
124
|
+
sizes,
|
|
125
|
+
supports: ["safetySettings", "temperature"]
|
|
126
|
+
};
|
|
127
|
+
if (references !== void 0) constraints.references = references;
|
|
122
128
|
const model = {
|
|
123
129
|
id,
|
|
124
130
|
aliases,
|
|
@@ -128,12 +134,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
|
128
134
|
providerModelId: id,
|
|
129
135
|
lifecycle: "active",
|
|
130
136
|
exposure,
|
|
131
|
-
constraints
|
|
132
|
-
aspectRatios: [...GEMINI_RATIOS],
|
|
133
|
-
sizes,
|
|
134
|
-
supports: ["safetySettings", "temperature"],
|
|
135
|
-
...references ? { references } : {}
|
|
136
|
-
},
|
|
137
|
+
constraints,
|
|
137
138
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
138
139
|
usage: { ...IMAGE_USAGE, slug: "gemini" },
|
|
139
140
|
pricingKind: "image_size",
|
|
@@ -260,6 +261,7 @@ var IMAGE_MODELS = [
|
|
|
260
261
|
pricingKind: "image_size",
|
|
261
262
|
display: {
|
|
262
263
|
provider: "openai",
|
|
264
|
+
sortOrder: 20,
|
|
263
265
|
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."
|
|
264
266
|
}
|
|
265
267
|
},
|
|
@@ -294,6 +296,7 @@ var IMAGE_MODELS = [
|
|
|
294
296
|
pricingKind: "image_size",
|
|
295
297
|
display: {
|
|
296
298
|
provider: "openai",
|
|
299
|
+
sortOrder: 10,
|
|
297
300
|
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."
|
|
298
301
|
}
|
|
299
302
|
},
|
|
@@ -2034,23 +2037,22 @@ var liveState = store[KEY] ??= {
|
|
|
2034
2037
|
var liveCatalog = liveState.catalog;
|
|
2035
2038
|
|
|
2036
2039
|
// src/catalog/load.ts
|
|
2040
|
+
import { z as z2 } from "zod";
|
|
2037
2041
|
function rowCount() {
|
|
2038
2042
|
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2039
2043
|
}
|
|
2040
2044
|
function authHeaders(auth) {
|
|
2041
2045
|
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2042
2046
|
}
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
if (typeof rev === "string") return { rows, revision: rev };
|
|
2053
|
-
return { rows };
|
|
2047
|
+
var EnvelopeSchema = z2.object({
|
|
2048
|
+
rows: CatalogSchema,
|
|
2049
|
+
revision: z2.string().optional()
|
|
2050
|
+
});
|
|
2051
|
+
function toEnvelope(data) {
|
|
2052
|
+
if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
|
|
2053
|
+
const envelope = { rows: data.rows };
|
|
2054
|
+
if (data.revision !== void 0) envelope.revision = data.revision;
|
|
2055
|
+
return envelope;
|
|
2054
2056
|
}
|
|
2055
2057
|
function logPrimed(logger, result) {
|
|
2056
2058
|
const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
|
|
@@ -2071,7 +2073,9 @@ async function fetchRemote(source, logger) {
|
|
|
2071
2073
|
if (res.status === 304) return { kept: true };
|
|
2072
2074
|
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2073
2075
|
const json = await res.json();
|
|
2074
|
-
const
|
|
2076
|
+
const parsed = EnvelopeSchema.safeParse(json);
|
|
2077
|
+
if (!parsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2078
|
+
const { rows, revision: rev } = toEnvelope(parsed.data);
|
|
2075
2079
|
if (rev === void 0) return { rows, fromCache: false };
|
|
2076
2080
|
return { rows, revision: rev, fromCache: false };
|
|
2077
2081
|
}
|
|
@@ -2102,11 +2106,13 @@ async function prime(source, logger) {
|
|
|
2102
2106
|
return result;
|
|
2103
2107
|
} catch (err) {
|
|
2104
2108
|
logger.warn("[modelkit] catalog remote failed, trying cache", err);
|
|
2105
|
-
const error =
|
|
2109
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
2106
2110
|
try {
|
|
2107
2111
|
const cached = await source.cache?.get();
|
|
2108
2112
|
if (!cached) throw new Error("no cached catalog");
|
|
2109
|
-
const
|
|
2113
|
+
const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
|
|
2114
|
+
if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2115
|
+
const { rows, revision: rev } = toEnvelope(cachedParsed.data);
|
|
2110
2116
|
liveCatalog.replace(rows);
|
|
2111
2117
|
liveState.origin = "last-good";
|
|
2112
2118
|
liveState.revision = rev;
|
|
@@ -2146,19 +2152,18 @@ async function refresh(source, logger) {
|
|
|
2146
2152
|
}
|
|
2147
2153
|
}
|
|
2148
2154
|
function primeCatalog(source) {
|
|
2149
|
-
|
|
2150
|
-
if (memo) return memo;
|
|
2155
|
+
if (liveState.memo) return liveState.memo;
|
|
2151
2156
|
const logger = source.logger ?? console;
|
|
2152
|
-
|
|
2157
|
+
const pending = prime(source, logger).then((result) => {
|
|
2153
2158
|
const ttlMs = source.ttlMs ?? 3e5;
|
|
2154
2159
|
if (ttlMs > 0 && liveState.timer === void 0) {
|
|
2155
2160
|
liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2156
|
-
|
|
2157
|
-
maybeUnref.unref?.();
|
|
2161
|
+
liveState.timer.unref?.();
|
|
2158
2162
|
}
|
|
2159
2163
|
return result;
|
|
2160
2164
|
});
|
|
2161
|
-
|
|
2165
|
+
liveState.memo = pending;
|
|
2166
|
+
return pending;
|
|
2162
2167
|
}
|
|
2163
2168
|
function resetLiveCatalog() {
|
|
2164
2169
|
if (liveState.timer !== void 0) {
|