@shop-os/modelkit 0.31.0 → 0.33.0
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 +37 -0
- package/dist/catalog.cjs +80 -16
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +14 -0
- package/dist/catalog.d.ts +14 -0
- package/dist/catalog.js +80 -16
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +94 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +94 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -799,6 +799,10 @@ interface ModelConstraints {
|
|
|
799
799
|
} | number[];
|
|
800
800
|
/** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
|
|
801
801
|
durationPresets?: number[];
|
|
802
|
+
/** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
|
|
803
|
+
maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
|
|
804
|
+
/** Pickers pre-select `defaults.durationSeconds` over their own product default. */
|
|
805
|
+
preferDefaultDuration?: boolean;
|
|
802
806
|
/** Curated quality choices for rows whose `supports` includes "quality". */
|
|
803
807
|
qualityOptions?: string[];
|
|
804
808
|
/** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
|
|
@@ -1401,6 +1405,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
|
|
|
1401
1405
|
max: z.ZodNumber;
|
|
1402
1406
|
}, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
|
|
1403
1407
|
durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
1408
|
+
maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
|
|
1409
|
+
"360p": "360p";
|
|
1410
|
+
"480p": "480p";
|
|
1411
|
+
"720p": "720p";
|
|
1412
|
+
"768p": "768p";
|
|
1413
|
+
"1080p": "1080p";
|
|
1414
|
+
"2k": "2k";
|
|
1415
|
+
"4k": "4k";
|
|
1416
|
+
}> & z.core.$partial, z.ZodNumber>>;
|
|
1417
|
+
preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
|
|
1404
1418
|
qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1405
1419
|
scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
1406
1420
|
exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -799,6 +799,10 @@ interface ModelConstraints {
|
|
|
799
799
|
} | number[];
|
|
800
800
|
/** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
|
|
801
801
|
durationPresets?: number[];
|
|
802
|
+
/** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
|
|
803
|
+
maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
|
|
804
|
+
/** Pickers pre-select `defaults.durationSeconds` over their own product default. */
|
|
805
|
+
preferDefaultDuration?: boolean;
|
|
802
806
|
/** Curated quality choices for rows whose `supports` includes "quality". */
|
|
803
807
|
qualityOptions?: string[];
|
|
804
808
|
/** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
|
|
@@ -1401,6 +1405,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
|
|
|
1401
1405
|
max: z.ZodNumber;
|
|
1402
1406
|
}, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
|
|
1403
1407
|
durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
1408
|
+
maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
|
|
1409
|
+
"360p": "360p";
|
|
1410
|
+
"480p": "480p";
|
|
1411
|
+
"720p": "720p";
|
|
1412
|
+
"768p": "768p";
|
|
1413
|
+
"1080p": "1080p";
|
|
1414
|
+
"2k": "2k";
|
|
1415
|
+
"4k": "4k";
|
|
1416
|
+
}> & z.core.$partial, z.ZodNumber>>;
|
|
1417
|
+
preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
|
|
1404
1418
|
qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1405
1419
|
scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
1406
1420
|
exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
package/dist/index.js
CHANGED
|
@@ -5158,6 +5158,22 @@ var TEXT_MODELS = [
|
|
|
5158
5158
|
contextWindow: 1e6
|
|
5159
5159
|
}
|
|
5160
5160
|
}),
|
|
5161
|
+
text("claude-sonnet-5-5", "Claude Sonnet 5.5", "claude-sonnet-5-5", {
|
|
5162
|
+
exposure: [],
|
|
5163
|
+
// Sonnet 5.5 rejects a forced tool_choice, which is how Bedrock's SDK asks for JSON on Sonnet 5.
|
|
5164
|
+
providerOptions: { modelkit: { structuredOutputMode: "outputFormat" } },
|
|
5165
|
+
display: {
|
|
5166
|
+
chat: { providerOptions: ANTHROPIC_ADAPTIVE },
|
|
5167
|
+
provider: "anthropic",
|
|
5168
|
+
costTier: 3,
|
|
5169
|
+
description: "Anthropic Claude Sonnet 5.5 balanced model; text and image input, 1M-token context."
|
|
5170
|
+
},
|
|
5171
|
+
capabilities: {
|
|
5172
|
+
reasoning: true,
|
|
5173
|
+
vision: true,
|
|
5174
|
+
contextWindow: 1e6
|
|
5175
|
+
}
|
|
5176
|
+
}),
|
|
5161
5177
|
text("claude-opus-4-8", "Claude Opus 4.8", "claude-opus-4-8", {
|
|
5162
5178
|
exposure: ["cowork", "space_builder"],
|
|
5163
5179
|
aliases: ["claude-opus-4.8", "claude-opus-4", "claude-opus-4.0", "claude-opus-4-20250514"],
|
|
@@ -5748,7 +5764,9 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5748
5764
|
aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
|
|
5749
5765
|
resolutions: ["720p", "1080p", "4k"],
|
|
5750
5766
|
durations: { min: 3, max: 30 },
|
|
5751
|
-
|
|
5767
|
+
preferDefaultDuration: true,
|
|
5768
|
+
// A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
|
|
5769
|
+
maxSecondsByResolution: { "4k": 15 },
|
|
5752
5770
|
references: {
|
|
5753
5771
|
...NO_REFERENCES,
|
|
5754
5772
|
images: 10,
|
|
@@ -5787,6 +5805,8 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5787
5805
|
inputBilling: "kling-v4",
|
|
5788
5806
|
resolutions: ["720p", "1080p", "4k"],
|
|
5789
5807
|
durations: { min: 3, max: 30 },
|
|
5808
|
+
// A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
|
|
5809
|
+
maxSecondsByResolution: { "4k": 15 },
|
|
5790
5810
|
references: { ...NO_REFERENCES, images: 10 },
|
|
5791
5811
|
requires: ["sourceVideo"],
|
|
5792
5812
|
sourceVideoSeconds: { min: 3, max: 30.05 },
|
|
@@ -5824,7 +5844,7 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5824
5844
|
aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
|
|
5825
5845
|
resolutions: ["720p"],
|
|
5826
5846
|
durations: { min: 3, max: 20 },
|
|
5827
|
-
|
|
5847
|
+
preferDefaultDuration: true,
|
|
5828
5848
|
references: {
|
|
5829
5849
|
...NO_REFERENCES,
|
|
5830
5850
|
images: 10,
|
|
@@ -6679,7 +6699,6 @@ var VIDEO_MODELS = [
|
|
|
6679
6699
|
aspectRatios: [...OMNI_RATIOS],
|
|
6680
6700
|
resolutions: ["360p", "720p", "1080p", "4k"],
|
|
6681
6701
|
durations: { min: 3, max: 15 },
|
|
6682
|
-
durationPresets: [3, 5, 8, 10, 15],
|
|
6683
6702
|
references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
|
|
6684
6703
|
sourceVideoSeconds: { max: 15 },
|
|
6685
6704
|
supports: ["videoExtension", "lastFrame"],
|
|
@@ -7246,7 +7265,7 @@ var VIDEO_MODELS = [
|
|
|
7246
7265
|
aspectRatios: [...WAN_RATIOS],
|
|
7247
7266
|
resolutions: ["480p", "720p", "1080p"],
|
|
7248
7267
|
durations: { min: 2, max: 30 },
|
|
7249
|
-
|
|
7268
|
+
preferDefaultDuration: true,
|
|
7250
7269
|
references: {
|
|
7251
7270
|
images: 10,
|
|
7252
7271
|
videos: 5,
|
|
@@ -7288,7 +7307,7 @@ var VIDEO_MODELS = [
|
|
|
7288
7307
|
aspectRatios: [...WAN_RATIOS],
|
|
7289
7308
|
resolutions: ["480p", "720p", "1080p"],
|
|
7290
7309
|
durations: { min: 2, max: 30 },
|
|
7291
|
-
|
|
7310
|
+
preferDefaultDuration: true,
|
|
7292
7311
|
references: {
|
|
7293
7312
|
images: 10,
|
|
7294
7313
|
videos: 5,
|
|
@@ -8840,6 +8859,8 @@ var ModelConstraintsSchema = z3.looseObject({
|
|
|
8840
8859
|
resolutions: z3.array(VideoResolutionSchema).optional(),
|
|
8841
8860
|
durations: z3.union([z3.looseObject({ min: z3.number(), max: z3.number() }), z3.array(z3.number())]).optional(),
|
|
8842
8861
|
durationPresets: z3.array(z3.number()).optional(),
|
|
8862
|
+
maxSecondsByResolution: z3.partialRecord(VideoResolutionSchema, z3.number().positive()).optional(),
|
|
8863
|
+
preferDefaultDuration: z3.boolean().optional(),
|
|
8843
8864
|
qualityOptions: z3.array(z3.string()).optional(),
|
|
8844
8865
|
scaleFactors: z3.array(z3.number().positive()).min(1).optional(),
|
|
8845
8866
|
exactSizes: z3.record(z3.string(), z3.string()).optional(),
|
|
@@ -9066,6 +9087,19 @@ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
|
|
|
9066
9087
|
}
|
|
9067
9088
|
}
|
|
9068
9089
|
}
|
|
9090
|
+
const durations = row2.constraints.durations;
|
|
9091
|
+
for (const [resolution, max] of Object.entries(
|
|
9092
|
+
row2.constraints.maxSecondsByResolution ?? {}
|
|
9093
|
+
)) {
|
|
9094
|
+
const inRange = durations === void 0 || (Array.isArray(durations) ? durations.some((d) => d <= max) && max <= Math.max(...durations) : max >= durations.min && max <= durations.max);
|
|
9095
|
+
if (!Number.isInteger(max) || !inRange) {
|
|
9096
|
+
ctx.addIssue({
|
|
9097
|
+
code: "custom",
|
|
9098
|
+
path: ["constraints", "maxSecondsByResolution", resolution],
|
|
9099
|
+
message: "a resolution cap must be whole seconds within the row's durations"
|
|
9100
|
+
});
|
|
9101
|
+
}
|
|
9102
|
+
}
|
|
9069
9103
|
const audio = row2.constraints.audio;
|
|
9070
9104
|
if (audio !== void 0 && !AudioOutputSchema.safeParse(audio).success) {
|
|
9071
9105
|
ctx.addIssue({
|
|
@@ -9293,9 +9327,20 @@ function missingKey(ctx, name) {
|
|
|
9293
9327
|
}
|
|
9294
9328
|
function bedrockMiddleware(ctx, canonicalModelId) {
|
|
9295
9329
|
let warned = false;
|
|
9330
|
+
const structuredOutputMode = ctx.model.providerOptions?.["modelkit"]?.["structuredOutputMode"];
|
|
9296
9331
|
return {
|
|
9297
9332
|
specificationVersion: "v3",
|
|
9298
|
-
transformParams: async ({ params }) => {
|
|
9333
|
+
transformParams: async ({ params: incoming }) => {
|
|
9334
|
+
const params = typeof structuredOutputMode === "string" && incoming.responseFormat?.type === "json" && incoming.providerOptions?.["anthropic"]?.["structuredOutputMode"] === void 0 ? {
|
|
9335
|
+
...incoming,
|
|
9336
|
+
providerOptions: {
|
|
9337
|
+
...incoming.providerOptions,
|
|
9338
|
+
anthropic: {
|
|
9339
|
+
...incoming.providerOptions?.["anthropic"],
|
|
9340
|
+
structuredOutputMode
|
|
9341
|
+
}
|
|
9342
|
+
}
|
|
9343
|
+
} : incoming;
|
|
9299
9344
|
const anthropic = params.providerOptions?.["anthropic"];
|
|
9300
9345
|
if (typeof anthropic !== "object" || anthropic === null || !("cacheControl" in anthropic))
|
|
9301
9346
|
return params;
|
|
@@ -10508,15 +10553,16 @@ function hasReferences(req) {
|
|
|
10508
10553
|
return count(req.referenceImages) + count(req.referenceVideos) > 0;
|
|
10509
10554
|
}
|
|
10510
10555
|
var KLING_V4_4K_MAX_SECONDS = 15;
|
|
10511
|
-
function klingV4FourK(seconds3, req) {
|
|
10556
|
+
function klingV4FourK(seconds3, req, model) {
|
|
10512
10557
|
if (req.resolution !== "4k") return void 0;
|
|
10558
|
+
const max = model.constraints.maxSecondsByResolution?.["4k"] ?? KLING_V4_4K_MAX_SECONDS;
|
|
10513
10559
|
if (seconds3 === void 0) {
|
|
10514
|
-
return missing(`needs a measured source video of up to ${
|
|
10560
|
+
return missing(`needs a measured source video of up to ${max} s at 4K`);
|
|
10515
10561
|
}
|
|
10516
|
-
return seconds3 >
|
|
10562
|
+
return seconds3 > max ? unsupported3(`renders at most ${max} s at 4K`) : void 0;
|
|
10517
10563
|
}
|
|
10518
|
-
function klingV4(req) {
|
|
10519
|
-
const fourK = klingV4FourK(req.durationSeconds ?? 5, req);
|
|
10564
|
+
function klingV4(req, model) {
|
|
10565
|
+
const fourK = klingV4FourK(req.durationSeconds ?? 5, req, model);
|
|
10520
10566
|
if (fourK !== void 0) return fourK;
|
|
10521
10567
|
if (hasReferences(req)) {
|
|
10522
10568
|
if (req.lastFrame !== void 0) {
|
|
@@ -10531,10 +10577,10 @@ function klingV4(req) {
|
|
|
10531
10577
|
}
|
|
10532
10578
|
return needsPrompt(req);
|
|
10533
10579
|
}
|
|
10534
|
-
function klingV4Flash(req) {
|
|
10580
|
+
function klingV4Flash(req, model) {
|
|
10535
10581
|
if (req.lastFrame !== void 0) return unsupported3("takes no end frame");
|
|
10536
10582
|
if (!hasReferences(req) && req.firstFrame !== void 0) return void 0;
|
|
10537
|
-
return klingV4(req);
|
|
10583
|
+
return klingV4(req, model);
|
|
10538
10584
|
}
|
|
10539
10585
|
function h3Turbo(req) {
|
|
10540
10586
|
if (count(req.referenceImages) + count(req.referenceVideos) > 0) {
|
|
@@ -10637,7 +10683,7 @@ var RULES = new Map([
|
|
|
10637
10683
|
[KLING_V4, klingV4],
|
|
10638
10684
|
[
|
|
10639
10685
|
KLING_V4_EDIT,
|
|
10640
|
-
(req) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req) ?? needsPrompt(req)
|
|
10686
|
+
(req, model) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req, model) ?? needsPrompt(req)
|
|
10641
10687
|
],
|
|
10642
10688
|
[KLING_V4_FLASH, klingV4Flash],
|
|
10643
10689
|
[KLING_V4_FLASH_EDIT, (req) => needsSource(req) ?? needsPrompt(req)],
|
|
@@ -10657,8 +10703,8 @@ var RULES = new Map([
|
|
|
10657
10703
|
[LTX25_T2V, ltx(null)],
|
|
10658
10704
|
[LTX25_FAST_T2V, ltx(["720p", "1080p"])]
|
|
10659
10705
|
]);
|
|
10660
|
-
function falVideoProblem(
|
|
10661
|
-
return RULES.get(providerModelId.toLowerCase())?.(req);
|
|
10706
|
+
function falVideoProblem(model, req) {
|
|
10707
|
+
return RULES.get(model.providerModelId.toLowerCase())?.(req, model);
|
|
10662
10708
|
}
|
|
10663
10709
|
function viduSilentWarning(model) {
|
|
10664
10710
|
return {
|
|
@@ -10689,7 +10735,7 @@ function fillKlingModeResolution(model, req) {
|
|
|
10689
10735
|
}
|
|
10690
10736
|
function applyFalVideoRules(model, req, callerRatio, warnings) {
|
|
10691
10737
|
if (model.adapter !== "fal" && model.adapter !== "alibaba") return;
|
|
10692
|
-
const problem = falVideoProblem(model
|
|
10738
|
+
const problem = falVideoProblem(model, withPromptForResolve(req));
|
|
10693
10739
|
if (problem !== void 0) throw ruleRefusal(model, problem.message, problem.code);
|
|
10694
10740
|
const id = model.providerModelId.toLowerCase();
|
|
10695
10741
|
const references = count(req.referenceImages) + count(req.referenceAudios);
|
|
@@ -10802,7 +10848,7 @@ function happyHorseBody(req, ctx) {
|
|
|
10802
10848
|
}
|
|
10803
10849
|
function planAlibabaVideo(req, ctx) {
|
|
10804
10850
|
const id = ctx.model.providerModelId.toLowerCase();
|
|
10805
|
-
const problem = falVideoProblem(
|
|
10851
|
+
const problem = falVideoProblem(ctx.model, req);
|
|
10806
10852
|
if (problem !== void 0) throw ruleRefusal(ctx.model, problem.message, problem.code);
|
|
10807
10853
|
if (WAN_VIDEO_IDS.has(id)) return wanBody(req, ctx);
|
|
10808
10854
|
if (id === HAPPY_HORSE_FAMILY) return happyHorseBody(req, ctx);
|
|
@@ -14099,7 +14145,7 @@ function planFalFamilyVideo(req, ctx) {
|
|
|
14099
14145
|
const id = ctx.model.providerModelId.toLowerCase();
|
|
14100
14146
|
const family = FAMILIES2.find((f) => f.ids.has(id));
|
|
14101
14147
|
if (family === void 0) return void 0;
|
|
14102
|
-
const problem = falVideoProblem(
|
|
14148
|
+
const problem = falVideoProblem(ctx.model, req);
|
|
14103
14149
|
if (problem !== void 0) throw refusal2(ctx, problem.message, problem.code);
|
|
14104
14150
|
return family.plan(req, ctx);
|
|
14105
14151
|
}
|
|
@@ -19891,6 +19937,27 @@ function resolveDuration(requested, durations, model, onUnsupported, warnings) {
|
|
|
19891
19937
|
});
|
|
19892
19938
|
return to;
|
|
19893
19939
|
}
|
|
19940
|
+
function capDurationAtResolution(seconds3, resolution, model, onUnsupported, warnings) {
|
|
19941
|
+
if (seconds3 === void 0 || resolution === void 0) return seconds3;
|
|
19942
|
+
const max = model.constraints.maxSecondsByResolution?.[resolution];
|
|
19943
|
+
if (max === void 0 || seconds3 <= max) return seconds3;
|
|
19944
|
+
const shown = resolution.endsWith("k") ? resolution.toUpperCase() : resolution;
|
|
19945
|
+
if (onUnsupported === "error") {
|
|
19946
|
+
throw new ModelKitError({
|
|
19947
|
+
code: "unsupported_option",
|
|
19948
|
+
message: `${model.id} renders at most ${max} s at ${shown}`,
|
|
19949
|
+
model: model.id
|
|
19950
|
+
});
|
|
19951
|
+
}
|
|
19952
|
+
warnings.push({
|
|
19953
|
+
code: "duration_coerced",
|
|
19954
|
+
field: "durationSeconds",
|
|
19955
|
+
from: seconds3,
|
|
19956
|
+
to: max,
|
|
19957
|
+
message: `duration ${seconds3}s coerced to ${max}s for ${model.id} at ${shown}`
|
|
19958
|
+
});
|
|
19959
|
+
return max;
|
|
19960
|
+
}
|
|
19894
19961
|
function resolveAspectRatio(requested, supported, model, onUnsupported, warnings) {
|
|
19895
19962
|
if (requested === void 0 || requested === "adaptive" || !supported) return requested;
|
|
19896
19963
|
if (supported.includes(requested)) return requested;
|
|
@@ -20210,6 +20277,14 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
|
|
|
20210
20277
|
warnings
|
|
20211
20278
|
);
|
|
20212
20279
|
if (duration !== void 0) merged.durationSeconds = duration;
|
|
20280
|
+
const capped = capDurationAtResolution(
|
|
20281
|
+
merged.durationSeconds,
|
|
20282
|
+
resolution,
|
|
20283
|
+
model,
|
|
20284
|
+
onUnsupported,
|
|
20285
|
+
warnings
|
|
20286
|
+
);
|
|
20287
|
+
if (capped !== void 0) merged.durationSeconds = capped;
|
|
20213
20288
|
const limits = c.references ?? {};
|
|
20214
20289
|
let images = trim(
|
|
20215
20290
|
"referenceImages",
|