@shop-os/modelkit 0.2.24 → 0.2.26
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 +14 -0
- package/README.md +6 -3
- package/dist/catalog.cjs +18 -2
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +6 -3
- package/dist/catalog.d.ts +6 -3
- package/dist/catalog.js +18 -2
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +54 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +52 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
CatalogSchema: () => CatalogSchema,
|
|
41
41
|
DEFAULT_ADAPTERS: () => DEFAULT_ADAPTERS,
|
|
42
42
|
ExposureSchema: () => ExposureSchema,
|
|
43
|
+
IMAGE_INPUT_SPEC_KEYS: () => IMAGE_INPUT_SPEC_KEYS,
|
|
43
44
|
INPUT_SPEC_SUPPORTS_KEYS: () => INPUT_SPEC_SUPPORTS_KEYS,
|
|
44
45
|
InputSpecSchema: () => InputSpecSchema,
|
|
45
46
|
JsonObjectSchema: () => JsonObjectSchema,
|
|
@@ -81,6 +82,7 @@ __export(index_exports, {
|
|
|
81
82
|
liveCatalog: () => liveCatalog,
|
|
82
83
|
liveState: () => liveState,
|
|
83
84
|
mergeTextProviderOptions: () => mergeTextProviderOptions,
|
|
85
|
+
missingTierKeys: () => missingTierKeys,
|
|
84
86
|
nearestAspectRatio: () => nearestAspectRatio,
|
|
85
87
|
normalizeExposure: () => normalizeExposure,
|
|
86
88
|
openaiImageAdapter: () => openaiImageAdapter,
|
|
@@ -2203,6 +2205,14 @@ var VIDEO_INPUT_SPEC_KEYS = [
|
|
|
2203
2205
|
"promptExpansion",
|
|
2204
2206
|
"referenceImages"
|
|
2205
2207
|
];
|
|
2208
|
+
var IMAGE_INPUT_SPEC_KEYS = [
|
|
2209
|
+
"prompt",
|
|
2210
|
+
"references",
|
|
2211
|
+
"aspectRatio",
|
|
2212
|
+
"size",
|
|
2213
|
+
"outputFormat",
|
|
2214
|
+
"seed"
|
|
2215
|
+
];
|
|
2206
2216
|
var AUDIO_INPUT_SPEC_KEYS = [
|
|
2207
2217
|
"prompt",
|
|
2208
2218
|
"durationSeconds",
|
|
@@ -2219,14 +2229,22 @@ var INPUT_SPEC_SUPPORTS_KEYS = [
|
|
|
2219
2229
|
"generateAudio",
|
|
2220
2230
|
"cfgScale",
|
|
2221
2231
|
"promptExpansion",
|
|
2232
|
+
"outputFormat",
|
|
2222
2233
|
"instrumental"
|
|
2223
2234
|
];
|
|
2224
2235
|
var VIDEO_KEY_SET = new Set(VIDEO_INPUT_SPEC_KEYS);
|
|
2236
|
+
var IMAGE_KEY_SET = new Set(IMAGE_INPUT_SPEC_KEYS);
|
|
2225
2237
|
var AUDIO_KEY_SET = new Set(AUDIO_INPUT_SPEC_KEYS);
|
|
2226
2238
|
var ALL_KEY_SET = /* @__PURE__ */ new Set([
|
|
2227
2239
|
...VIDEO_INPUT_SPEC_KEYS,
|
|
2240
|
+
...IMAGE_INPUT_SPEC_KEYS,
|
|
2228
2241
|
...AUDIO_INPUT_SPEC_KEYS
|
|
2229
2242
|
]);
|
|
2243
|
+
var ALLOWED_KEYS_BY_TYPE = /* @__PURE__ */ new Map([
|
|
2244
|
+
["video", VIDEO_KEY_SET],
|
|
2245
|
+
["image", IMAGE_KEY_SET],
|
|
2246
|
+
["audio", AUDIO_KEY_SET]
|
|
2247
|
+
]);
|
|
2230
2248
|
var ProviderScalarSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number(), import_zod2.z.boolean()]);
|
|
2231
2249
|
var FieldsSchema = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.string().min(1)).superRefine((fields, ctx) => {
|
|
2232
2250
|
const keys = Object.keys(fields);
|
|
@@ -2295,13 +2313,13 @@ function validateInputSpec(raw, row) {
|
|
|
2295
2313
|
};
|
|
2296
2314
|
}
|
|
2297
2315
|
const issues = [];
|
|
2298
|
-
|
|
2316
|
+
const allowed = ALLOWED_KEYS_BY_TYPE.get(row.type);
|
|
2317
|
+
if (allowed === void 0) {
|
|
2299
2318
|
issues.push({
|
|
2300
2319
|
path: [],
|
|
2301
2320
|
message: `inputSpec is not supported for "${row.type}" rows`
|
|
2302
2321
|
});
|
|
2303
2322
|
} else {
|
|
2304
|
-
const allowed = row.type === "video" ? VIDEO_KEY_SET : AUDIO_KEY_SET;
|
|
2305
2323
|
for (const key of Object.keys(spec.fields)) {
|
|
2306
2324
|
if (!allowed.has(key)) {
|
|
2307
2325
|
issues.push({
|
|
@@ -6843,6 +6861,12 @@ async function generateReplicateImage(req, ctx, deps) {
|
|
|
6843
6861
|
break;
|
|
6844
6862
|
}
|
|
6845
6863
|
default: {
|
|
6864
|
+
const specResult = replicateInputSpec(req, ctx);
|
|
6865
|
+
if (specResult.kind === "invalid") throw replicateInvalidSpec(ctx, specResult.issues);
|
|
6866
|
+
if (specResult.kind === "ok") {
|
|
6867
|
+
input = specResult.input;
|
|
6868
|
+
break;
|
|
6869
|
+
}
|
|
6846
6870
|
const first = (req.references ?? [])[0];
|
|
6847
6871
|
const imageInput = { prompt: req.prompt };
|
|
6848
6872
|
if (first) imageInput.image = refToUrl(first);
|
|
@@ -8095,10 +8119,22 @@ function hasAll(keys, names) {
|
|
|
8095
8119
|
function hasKey(keys, name) {
|
|
8096
8120
|
return hasAll(keys, [name]);
|
|
8097
8121
|
}
|
|
8122
|
+
function missingTierKeys(config, tier, names) {
|
|
8123
|
+
return names.filter((name) => !hasAll(config.keys[tier], [name]));
|
|
8124
|
+
}
|
|
8098
8125
|
function missingEnterpriseKeys(config, names) {
|
|
8099
|
-
return
|
|
8126
|
+
return missingTierKeys(config, "enterprise", names);
|
|
8100
8127
|
}
|
|
8101
8128
|
function resolveKeys(config, names, tier = "pro") {
|
|
8129
|
+
if (tier === "sloosh") {
|
|
8130
|
+
if (names.length === 0) return config.keys.sloosh ?? {};
|
|
8131
|
+
if (hasAll(config.keys.sloosh, names)) return config.keys.sloosh;
|
|
8132
|
+
throw new ModelKitError({
|
|
8133
|
+
code: "auth",
|
|
8134
|
+
message: `Missing Sloosh API key for ${names.join(", ")}`,
|
|
8135
|
+
retryable: false
|
|
8136
|
+
});
|
|
8137
|
+
}
|
|
8102
8138
|
if (tier === "enterprise" && hasAll(config.keys.enterprise, names))
|
|
8103
8139
|
return config.keys.enterprise;
|
|
8104
8140
|
if (names.length > 0 && !hasAll(config.keys.pro, names)) {
|
|
@@ -8287,6 +8323,7 @@ function resolveAnthropicTransport(model, config, tier, warn) {
|
|
|
8287
8323
|
const preferred = preferredAnthropicTransport(model, config.routing ?? {});
|
|
8288
8324
|
const usable = (transport) => {
|
|
8289
8325
|
const name = transport === "bedrock" ? "aws" : "anthropic";
|
|
8326
|
+
if (tier === "sloosh") return hasKey(config.keys.sloosh, name);
|
|
8290
8327
|
return hasKey(config.keys.pro, name) || tier === "enterprise" && hasKey(config.keys.enterprise, name);
|
|
8291
8328
|
};
|
|
8292
8329
|
if (usable(preferred)) return preferred;
|
|
@@ -8868,11 +8905,19 @@ function createModelKit(config, adapters) {
|
|
|
8868
8905
|
}
|
|
8869
8906
|
|
|
8870
8907
|
// src/default.ts
|
|
8908
|
+
function withSharedAws(keys) {
|
|
8909
|
+
const { pro, sloosh } = keys;
|
|
8910
|
+
if (!sloosh || sloosh.aws || !pro.aws) return keys;
|
|
8911
|
+
return { ...keys, sloosh: { ...sloosh, aws: pro.aws } };
|
|
8912
|
+
}
|
|
8871
8913
|
function createDefaultModelKit(config = {}) {
|
|
8872
|
-
const keys =
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8914
|
+
const keys = withSharedAws(
|
|
8915
|
+
config.keys ?? {
|
|
8916
|
+
pro: keysFromEnv(process.env),
|
|
8917
|
+
enterprise: keysFromEnv(process.env, "ENTERPRISE_"),
|
|
8918
|
+
sloosh: keysFromEnv(process.env, "SLOOSH_")
|
|
8919
|
+
}
|
|
8920
|
+
);
|
|
8876
8921
|
return createModelKit({ ...config, keys }, DEFAULT_ADAPTERS);
|
|
8877
8922
|
}
|
|
8878
8923
|
var generateText2 = (options, call) => createDefaultModelKit().generateText(options, call);
|
|
@@ -8896,6 +8941,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
8896
8941
|
CatalogSchema,
|
|
8897
8942
|
DEFAULT_ADAPTERS,
|
|
8898
8943
|
ExposureSchema,
|
|
8944
|
+
IMAGE_INPUT_SPEC_KEYS,
|
|
8899
8945
|
INPUT_SPEC_SUPPORTS_KEYS,
|
|
8900
8946
|
InputSpecSchema,
|
|
8901
8947
|
JsonObjectSchema,
|
|
@@ -8937,6 +8983,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
8937
8983
|
liveCatalog,
|
|
8938
8984
|
liveState,
|
|
8939
8985
|
mergeTextProviderOptions,
|
|
8986
|
+
missingTierKeys,
|
|
8940
8987
|
nearestAspectRatio,
|
|
8941
8988
|
normalizeExposure,
|
|
8942
8989
|
openaiImageAdapter,
|