@shop-os/modelkit 0.17.1 → 0.18.1
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 +24 -0
- package/dist/catalog.cjs +241 -15
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +78 -3
- package/dist/catalog.d.ts +78 -3
- package/dist/catalog.js +241 -15
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +328 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -3
- package/dist/index.d.ts +86 -3
- package/dist/index.js +326 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -450,6 +450,25 @@ var NANO_BANANA_2_1_RATIOS = [
|
|
|
450
450
|
"adaptive"
|
|
451
451
|
];
|
|
452
452
|
var GEMINI_PROMPT_MAX_CHARS = 5e4;
|
|
453
|
+
var GPT_IMAGE_2_6_ANIMATION = {
|
|
454
|
+
frameSizes: [
|
|
455
|
+
{ size: "288x288", minFrames: 2, maxFrames: 16 },
|
|
456
|
+
{ size: "384x384", minFrames: 2, maxFrames: 16 },
|
|
457
|
+
{ size: "512x288", minFrames: 2, maxFrames: 16 },
|
|
458
|
+
{ size: "288x512", minFrames: 2, maxFrames: 16 },
|
|
459
|
+
{ size: "512x512", minFrames: 2, maxFrames: 16 },
|
|
460
|
+
{ size: "768x768", minFrames: 2, maxFrames: 12 }
|
|
461
|
+
],
|
|
462
|
+
frameDurationMs: { min: 20, max: 2e3 },
|
|
463
|
+
defaultFrameCount: 9,
|
|
464
|
+
defaultFrameDurationMs: 200
|
|
465
|
+
};
|
|
466
|
+
var GPT_IMAGE_2_6_OUTPUT = {
|
|
467
|
+
imageFormats: ["png", "gif", "svg"],
|
|
468
|
+
backgrounds: ["auto", "opaque", "transparent"],
|
|
469
|
+
animation: GPT_IMAGE_2_6_ANIMATION,
|
|
470
|
+
svgModel: "gpt-6.1-sol"
|
|
471
|
+
};
|
|
453
472
|
var GPT_IMAGE_PROMPT = { referenceSyntax: "numbered", maxChars: 32e3 };
|
|
454
473
|
function geminiImage(id, label, aliases, sizes, display, exposure, references, promptMaxChars, aspectRatios = GEMINI_RATIOS) {
|
|
455
474
|
const prompt = { referenceSyntax: "caption" };
|
|
@@ -618,7 +637,8 @@ var IMAGE_MODELS = [
|
|
|
618
637
|
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
619
638
|
references: { images: 16 },
|
|
620
639
|
supports: ["quality", "count", "outputFormat"],
|
|
621
|
-
prompt: GPT_IMAGE_PROMPT
|
|
640
|
+
prompt: GPT_IMAGE_PROMPT,
|
|
641
|
+
...GPT_IMAGE_2_6_OUTPUT
|
|
622
642
|
},
|
|
623
643
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
624
644
|
usage: { ...IMAGE_USAGE3 },
|
|
@@ -653,7 +673,8 @@ var IMAGE_MODELS = [
|
|
|
653
673
|
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
654
674
|
references: { images: 16 },
|
|
655
675
|
supports: ["quality", "count", "outputFormat"],
|
|
656
|
-
prompt: GPT_IMAGE_PROMPT
|
|
676
|
+
prompt: GPT_IMAGE_PROMPT,
|
|
677
|
+
...GPT_IMAGE_2_6_OUTPUT
|
|
657
678
|
},
|
|
658
679
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
659
680
|
usage: { ...IMAGE_USAGE3 },
|
|
@@ -6026,6 +6047,44 @@ var VIDEO_MODELS = [
|
|
|
6026
6047
|
lastFrameRequiresFirstFrame: true
|
|
6027
6048
|
}
|
|
6028
6049
|
},
|
|
6050
|
+
{
|
|
6051
|
+
// https://aistudio.google.com/docs/omni (2026-11-05): the 1.1 Interactions API with
|
|
6052
|
+
// 3-15 s output; first-to-last-frame and each extension stay at 3-10 s (the adapter
|
|
6053
|
+
// refuses more), extended clips stop at 30 s, and 11-15 s clips take one reference video.
|
|
6054
|
+
id: "gemini-omni-1.2-flash",
|
|
6055
|
+
aliases: ["gemini-omni-1.2-video", "gemini-omni-1.2-reference", "gemini-omni-1.2-edit"],
|
|
6056
|
+
label: "Gemini Omni 1.2 Flash",
|
|
6057
|
+
type: "video",
|
|
6058
|
+
adapter: "google-genai",
|
|
6059
|
+
providerModelId: "gemini-omni-1.2-flash",
|
|
6060
|
+
lifecycle: "active",
|
|
6061
|
+
exposure: ["cowork", "space_builder"],
|
|
6062
|
+
constraints: {
|
|
6063
|
+
aspectRatios: [...OMNI_RATIOS],
|
|
6064
|
+
resolutions: ["360p", "720p", "1080p", "4k"],
|
|
6065
|
+
durations: { min: 3, max: 15 },
|
|
6066
|
+
durationPresets: [3, 5, 8, 10, 15],
|
|
6067
|
+
references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
|
|
6068
|
+
sourceVideoSeconds: { max: 15 },
|
|
6069
|
+
supports: ["videoExtension", "lastFrame"],
|
|
6070
|
+
extension: { segmentSeconds: 10, maxTotalSeconds: 30, returns: "joined" },
|
|
6071
|
+
prompt: OMNI_PROMPT,
|
|
6072
|
+
audio: "always"
|
|
6073
|
+
},
|
|
6074
|
+
defaults: {},
|
|
6075
|
+
usage: { ...VIDEO_USAGE3 },
|
|
6076
|
+
pricingKind: "video_per_second",
|
|
6077
|
+
display: {
|
|
6078
|
+
provider: "google",
|
|
6079
|
+
logo: GOOGLE_LOGO3,
|
|
6080
|
+
description: "Google Gemini Omni Flash 1.2 conversational video generation, editing and extension; text, image, and up to 15-second video input, 3-15 second output at up to 4K and 24 FPS (start and end frames up to 10 seconds), extendable to 30 seconds."
|
|
6081
|
+
},
|
|
6082
|
+
capabilities: {
|
|
6083
|
+
acceptsSourceVideo: true,
|
|
6084
|
+
videoEdit: true,
|
|
6085
|
+
lastFrameRequiresFirstFrame: true
|
|
6086
|
+
}
|
|
6087
|
+
},
|
|
6029
6088
|
{
|
|
6030
6089
|
// vibe-triggers and Space Builder drop the ratio when a frame is wired; Cowork always sends it.
|
|
6031
6090
|
id: "seedance-2.0",
|
|
@@ -7879,7 +7938,20 @@ var AspectRatioSchema = z3.enum([
|
|
|
7879
7938
|
var ImageSizeSchema = z3.enum(["512", "1K", "2K", "4K"]);
|
|
7880
7939
|
var VideoResolutionSchema = z3.enum(["360p", "480p", "720p", "768p", "1080p", "2k", "4k"]);
|
|
7881
7940
|
var ImageQualitySchema = z3.enum(["auto", "low", "medium", "high", "xhigh", "max"]);
|
|
7882
|
-
var OutputFormatSchema = z3.enum(["png", "jpeg", "webp"]);
|
|
7941
|
+
var OutputFormatSchema = z3.enum(["png", "jpeg", "webp", "gif", "svg"]);
|
|
7942
|
+
var ImageBackgroundSchema = z3.enum(["auto", "opaque", "transparent"]);
|
|
7943
|
+
var AnimationLimitsSchema = z3.looseObject({
|
|
7944
|
+
frameSizes: z3.array(
|
|
7945
|
+
z3.looseObject({
|
|
7946
|
+
size: z3.string().regex(/^\d+x\d+$/u),
|
|
7947
|
+
minFrames: z3.number().int().positive(),
|
|
7948
|
+
maxFrames: z3.number().int().positive()
|
|
7949
|
+
})
|
|
7950
|
+
).min(1),
|
|
7951
|
+
frameDurationMs: z3.looseObject({ min: z3.number().positive(), max: z3.number().positive() }),
|
|
7952
|
+
defaultFrameCount: z3.number().int().positive(),
|
|
7953
|
+
defaultFrameDurationMs: z3.number().positive()
|
|
7954
|
+
});
|
|
7883
7955
|
var RequiredInputSchema = z3.enum(["firstFrame", "sourceVideo", "references", "sourceAudio"]);
|
|
7884
7956
|
var SupportedOptionSchema = z3.enum([
|
|
7885
7957
|
"seed",
|
|
@@ -8033,6 +8105,10 @@ var ModelConstraintsSchema = z3.looseObject({
|
|
|
8033
8105
|
}).optional(),
|
|
8034
8106
|
languages: z3.array(LanguageOptionSchema).optional(),
|
|
8035
8107
|
outputFormats: z3.array(z3.string().min(1)).min(1).optional(),
|
|
8108
|
+
imageFormats: z3.array(OutputFormatSchema).min(1).optional(),
|
|
8109
|
+
backgrounds: z3.array(ImageBackgroundSchema).min(1).optional(),
|
|
8110
|
+
animation: AnimationLimitsSchema.optional(),
|
|
8111
|
+
svgModel: z3.string().min(1).optional(),
|
|
8036
8112
|
sourceVideoPixels: VideoPixelLimitsSchema.optional(),
|
|
8037
8113
|
sourceVideoSeconds: VideoSecondsLimitsSchema.omit({ total: true }).extend({ inReferenceTotal: z3.boolean().optional() }).optional(),
|
|
8038
8114
|
// segmentSeconds/maxTotalSeconds stay required: a kit before 0.3.0 drops a row whose
|
|
@@ -13823,6 +13899,7 @@ var VEO_POLL_INTERVAL_MS = 5e3;
|
|
|
13823
13899
|
var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
13824
13900
|
var RESULT_TIMEOUT_MS3 = 15 * 60 * 1e3;
|
|
13825
13901
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
13902
|
+
var OMNI_FRAMES_MAX_SECONDS = 10;
|
|
13826
13903
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 10 * 1024 * 1024;
|
|
13827
13904
|
var errorTextSchema = z24.string();
|
|
13828
13905
|
function isGoogleGenaiVideoKnown(providerModelId) {
|
|
@@ -14137,6 +14214,13 @@ async function generateOmniVideo(req, ctx, createGenAIClient) {
|
|
|
14137
14214
|
model: modelId
|
|
14138
14215
|
});
|
|
14139
14216
|
}
|
|
14217
|
+
if ((extend || lastFrame !== void 0) && duration > OMNI_FRAMES_MAX_SECONDS) {
|
|
14218
|
+
throw new ModelKitError({
|
|
14219
|
+
code: "unsupported_option",
|
|
14220
|
+
message: `${modelId} ${extend ? "extension" : "start-and-end-frame video"} is at most ${OMNI_FRAMES_MAX_SECONDS} s; got ${duration} s`,
|
|
14221
|
+
model: modelId
|
|
14222
|
+
});
|
|
14223
|
+
}
|
|
14140
14224
|
const task = extend ? "extend" : req.sourceVideo ? "edit" : firstFrame ? "image_to_video" : images.length > 0 || videos.length > 0 ? "reference_to_video" : "text_to_video";
|
|
14141
14225
|
const isOmniV1 = providerModelId === "gemini-omni-flash-preview";
|
|
14142
14226
|
const responseFormat = { type: "video", delivery: "uri" };
|
|
@@ -15831,7 +15915,37 @@ var lumaAdapter = {
|
|
|
15831
15915
|
// src/adapters/openai-image.ts
|
|
15832
15916
|
import OpenAI from "openai";
|
|
15833
15917
|
import { z as z28 } from "zod";
|
|
15918
|
+
|
|
15919
|
+
// src/adapters/svg-sanitize.ts
|
|
15920
|
+
var BLOCK_ELEMENTS = /<(script|foreignObject|iframe|object|embed|audio|video|handler|listener)\b[\s\S]*?<\/\1\s*>/giu;
|
|
15921
|
+
var SELF_CLOSING = /<(script|foreignObject|iframe|object|embed|audio|video|handler|listener)\b[^>]*\/>/giu;
|
|
15922
|
+
var EVENT_ATTRIBUTE = /\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/giu;
|
|
15923
|
+
var EXTERNAL_HREF = /\s+(xlink:)?href\s*=\s*("(?!#)[^"]*"|'(?!#)[^']*')/giu;
|
|
15924
|
+
var STYLE_IMPORT = /@import\b[^;]*;?/giu;
|
|
15925
|
+
var STILL_ACTIVE = /<(script|foreignObject|iframe|object|embed)\b|\son[a-z]+\s*=|javascript:|<!ENTITY|<\?xml-stylesheet/iu;
|
|
15926
|
+
function sanitizeSvg(svg, model) {
|
|
15927
|
+
const cleaned = svg.replace(BLOCK_ELEMENTS, "").replace(SELF_CLOSING, "").replace(EVENT_ATTRIBUTE, "").replace(EXTERNAL_HREF, "").replace(STYLE_IMPORT, "");
|
|
15928
|
+
if (!/<svg\b/iu.test(cleaned) || STILL_ACTIVE.test(cleaned)) {
|
|
15929
|
+
throw new ModelKitError({
|
|
15930
|
+
code: "provider_rejected",
|
|
15931
|
+
message: `${model} returned an SVG that could not be made safe`,
|
|
15932
|
+
provider: "openai-image",
|
|
15933
|
+
model,
|
|
15934
|
+
retryable: false
|
|
15935
|
+
});
|
|
15936
|
+
}
|
|
15937
|
+
return cleaned;
|
|
15938
|
+
}
|
|
15939
|
+
|
|
15940
|
+
// src/adapters/openai-image.ts
|
|
15834
15941
|
var MAX_EDIT_REFERENCES = 16;
|
|
15942
|
+
var MIME_BY_FORMAT = {
|
|
15943
|
+
png: "image/png",
|
|
15944
|
+
jpeg: "image/jpeg",
|
|
15945
|
+
webp: "image/webp",
|
|
15946
|
+
gif: "image/gif",
|
|
15947
|
+
svg: "image/svg+xml"
|
|
15948
|
+
};
|
|
15835
15949
|
function aspectRatioToSize(ratio, tier) {
|
|
15836
15950
|
const TIER_LONG_EDGE = {
|
|
15837
15951
|
"1K": 1024,
|
|
@@ -15943,7 +16057,6 @@ var openaiImageAdapter = {
|
|
|
15943
16057
|
const isEdit = refs.length > 0;
|
|
15944
16058
|
const quality = req.quality ?? (isEdit ? "medium" : "auto");
|
|
15945
16059
|
const sdkQuality = quality;
|
|
15946
|
-
const count2 = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
|
|
15947
16060
|
let outputFormat = req.outputFormat;
|
|
15948
16061
|
if (outputFormat === "webp") {
|
|
15949
16062
|
ctx.warnings.push({
|
|
@@ -15955,35 +16068,50 @@ var openaiImageAdapter = {
|
|
|
15955
16068
|
});
|
|
15956
16069
|
outputFormat = "png";
|
|
15957
16070
|
}
|
|
15958
|
-
|
|
15959
|
-
|
|
16071
|
+
if (isEdit && outputFormat === "svg") {
|
|
16072
|
+
throw new ModelKitError({
|
|
16073
|
+
code: "unsupported_option",
|
|
16074
|
+
message: `${ctx.model.id} cannot make an SVG from reference images`,
|
|
16075
|
+
provider: "openai-image",
|
|
16076
|
+
model: ctx.model.id,
|
|
16077
|
+
retryable: false
|
|
16078
|
+
});
|
|
16079
|
+
}
|
|
16080
|
+
const svgModel = ctx.model.constraints.svgModel;
|
|
16081
|
+
if (outputFormat === "svg" && !svgModel) {
|
|
16082
|
+
throw new ModelKitError({
|
|
16083
|
+
code: "unsupported_option",
|
|
16084
|
+
message: `${ctx.model.id} names no svgModel to write the SVG`,
|
|
16085
|
+
provider: "openai-image",
|
|
16086
|
+
model: ctx.model.id,
|
|
16087
|
+
retryable: false
|
|
16088
|
+
});
|
|
16089
|
+
}
|
|
16090
|
+
const params = {
|
|
16091
|
+
model: ctx.model.providerModelId,
|
|
16092
|
+
prompt: req.prompt,
|
|
16093
|
+
quality: sdkQuality,
|
|
16094
|
+
...size !== void 0 && { size },
|
|
16095
|
+
// SVG takes no `n` at all (OpenAI: "Use n=1"), not even 1.
|
|
16096
|
+
...req.count !== void 0 && req.count > 1 && outputFormat !== "svg" && { n: req.count },
|
|
16097
|
+
...outputFormat !== void 0 && { output_format: outputFormat },
|
|
16098
|
+
...req.background !== void 0 && { background: req.background },
|
|
16099
|
+
...outputFormat === "gif" && req.animation?.frameCount !== void 0 && {
|
|
16100
|
+
frame_count: req.animation.frameCount
|
|
16101
|
+
},
|
|
16102
|
+
...outputFormat === "gif" && req.animation?.frameDurationMs !== void 0 && {
|
|
16103
|
+
frame_duration_ms: req.animation.frameDurationMs
|
|
16104
|
+
},
|
|
16105
|
+
...outputFormat === "svg" && { svg: { model: svgModel } }
|
|
16106
|
+
};
|
|
16107
|
+
const mime = MIME_BY_FORMAT[outputFormat ?? "png"];
|
|
15960
16108
|
const retryOptions = mediaRetryOptions(ctx.call, ctx.signal);
|
|
15961
16109
|
const response = await withRetry(async () => {
|
|
15962
16110
|
try {
|
|
15963
16111
|
if (!isEdit) {
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
model: ctx.model.providerModelId,
|
|
15968
|
-
prompt: req.prompt,
|
|
15969
|
-
size,
|
|
15970
|
-
quality: sdkQuality,
|
|
15971
|
-
...count2,
|
|
15972
|
-
...format
|
|
15973
|
-
},
|
|
15974
|
-
{ signal: ctx.signal }
|
|
15975
|
-
);
|
|
15976
|
-
}
|
|
15977
|
-
return await client2.images.generate(
|
|
15978
|
-
{
|
|
15979
|
-
model: ctx.model.providerModelId,
|
|
15980
|
-
prompt: req.prompt,
|
|
15981
|
-
quality: sdkQuality,
|
|
15982
|
-
...count2,
|
|
15983
|
-
...format
|
|
15984
|
-
},
|
|
15985
|
-
{ signal: ctx.signal }
|
|
15986
|
-
);
|
|
16112
|
+
return await client2.images.generate(params, {
|
|
16113
|
+
signal: ctx.signal
|
|
16114
|
+
});
|
|
15987
16115
|
}
|
|
15988
16116
|
const files = await Promise.all(
|
|
15989
16117
|
refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
|
|
@@ -15998,37 +16126,19 @@ var openaiImageAdapter = {
|
|
|
15998
16126
|
);
|
|
15999
16127
|
const single = files.length === 1 ? files[0] : void 0;
|
|
16000
16128
|
const imageInput = single ?? files;
|
|
16001
|
-
if (size !== void 0) {
|
|
16002
|
-
return await client2.images.edit(
|
|
16003
|
-
{
|
|
16004
|
-
model: ctx.model.providerModelId,
|
|
16005
|
-
image: imageInput,
|
|
16006
|
-
prompt: req.prompt,
|
|
16007
|
-
size,
|
|
16008
|
-
quality: sdkQuality,
|
|
16009
|
-
...count2,
|
|
16010
|
-
...format
|
|
16011
|
-
},
|
|
16012
|
-
{ signal: ctx.signal }
|
|
16013
|
-
);
|
|
16014
|
-
}
|
|
16015
16129
|
return await client2.images.edit(
|
|
16016
|
-
{
|
|
16017
|
-
model: ctx.model.providerModelId,
|
|
16018
|
-
image: imageInput,
|
|
16019
|
-
prompt: req.prompt,
|
|
16020
|
-
quality: sdkQuality,
|
|
16021
|
-
...count2,
|
|
16022
|
-
...format
|
|
16023
|
-
},
|
|
16130
|
+
{ ...params, image: imageInput },
|
|
16024
16131
|
{ signal: ctx.signal }
|
|
16025
16132
|
);
|
|
16026
16133
|
} catch (cause) {
|
|
16027
16134
|
throw toProviderError2(cause, ctx);
|
|
16028
16135
|
}
|
|
16029
16136
|
}, retryOptions);
|
|
16137
|
+
const decode = (b64) => outputFormat === "svg" ? new TextEncoder().encode(
|
|
16138
|
+
sanitizeSvg(new TextDecoder().decode(base64ToBytes(b64)), ctx.model.id)
|
|
16139
|
+
) : base64ToBytes(b64);
|
|
16030
16140
|
const images = (response.data ?? []).flatMap(
|
|
16031
|
-
(item) => item.b64_json ? [{ bytes:
|
|
16141
|
+
(item) => item.b64_json ? [{ bytes: decode(item.b64_json), mime }] : []
|
|
16032
16142
|
);
|
|
16033
16143
|
if (images.length === 0)
|
|
16034
16144
|
throw classifyHttpError(
|
|
@@ -17612,6 +17722,155 @@ function fileCatalogCache(path) {
|
|
|
17612
17722
|
};
|
|
17613
17723
|
}
|
|
17614
17724
|
|
|
17725
|
+
// src/resolve-image-output.ts
|
|
17726
|
+
var BASE_FORMATS = ["png", "jpeg", "webp"];
|
|
17727
|
+
var ONE_K_FRAME_PIXELS = 288 * 512;
|
|
17728
|
+
function imageOutputFormats(model) {
|
|
17729
|
+
return model.constraints.imageFormats ?? BASE_FORMATS;
|
|
17730
|
+
}
|
|
17731
|
+
function animationTier(model, frameSize) {
|
|
17732
|
+
const [w, h] = frameSize.split("x").map(Number);
|
|
17733
|
+
const tier = (w ?? 0) * (h ?? 0) <= ONE_K_FRAME_PIXELS ? "1K" : "2K";
|
|
17734
|
+
const offered = model.constraints.sizes ?? ["1K", "2K", "4K"];
|
|
17735
|
+
if (offered.includes(tier)) return tier;
|
|
17736
|
+
return offered[offered.length - 1] ?? tier;
|
|
17737
|
+
}
|
|
17738
|
+
function refuse(model, message) {
|
|
17739
|
+
throw new ModelKitError({ code: "unsupported_option", message, model: model.id });
|
|
17740
|
+
}
|
|
17741
|
+
function clamp(value, min, max) {
|
|
17742
|
+
return Math.min(Math.max(value, min), max);
|
|
17743
|
+
}
|
|
17744
|
+
function applyAnimation(model, req, onUnsupported, warnings) {
|
|
17745
|
+
const limits = model.constraints.animation;
|
|
17746
|
+
if (!limits) return;
|
|
17747
|
+
const sizes = limits.frameSizes;
|
|
17748
|
+
let frameSize = sizes.find((s) => s.size === req.exactSize);
|
|
17749
|
+
if (!frameSize) {
|
|
17750
|
+
const fallback = sizes[0];
|
|
17751
|
+
if (req.exactSize !== void 0) {
|
|
17752
|
+
if (onUnsupported === "error") {
|
|
17753
|
+
refuse(
|
|
17754
|
+
model,
|
|
17755
|
+
`${model.id} makes GIF frames at ${sizes.map((s) => s.size).join(", ")}; got ${req.exactSize}`
|
|
17756
|
+
);
|
|
17757
|
+
}
|
|
17758
|
+
warnings.push({
|
|
17759
|
+
code: "option_ignored",
|
|
17760
|
+
field: "exactSize",
|
|
17761
|
+
from: req.exactSize,
|
|
17762
|
+
to: fallback.size,
|
|
17763
|
+
message: `${model.id} has no ${req.exactSize} GIF frame; using ${fallback.size}`
|
|
17764
|
+
});
|
|
17765
|
+
}
|
|
17766
|
+
frameSize = fallback;
|
|
17767
|
+
}
|
|
17768
|
+
req.exactSize = frameSize.size;
|
|
17769
|
+
delete req.aspectRatio;
|
|
17770
|
+
const animation = { ...req.animation };
|
|
17771
|
+
const asked = animation.frameCount;
|
|
17772
|
+
const frames = asked ?? clamp(limits.defaultFrameCount, frameSize.minFrames, frameSize.maxFrames);
|
|
17773
|
+
if (frames < frameSize.minFrames || frames > frameSize.maxFrames || !Number.isInteger(frames)) {
|
|
17774
|
+
if (onUnsupported === "error") {
|
|
17775
|
+
refuse(
|
|
17776
|
+
model,
|
|
17777
|
+
`${model.id} makes ${frameSize.minFrames} to ${frameSize.maxFrames} frames at ${frameSize.size}; got ${frames}`
|
|
17778
|
+
);
|
|
17779
|
+
}
|
|
17780
|
+
const snapped = clamp(Math.round(frames), frameSize.minFrames, frameSize.maxFrames);
|
|
17781
|
+
warnings.push({
|
|
17782
|
+
code: "option_ignored",
|
|
17783
|
+
field: "animation.frameCount",
|
|
17784
|
+
from: frames,
|
|
17785
|
+
to: snapped,
|
|
17786
|
+
message: `${model.id} makes ${frameSize.minFrames} to ${frameSize.maxFrames} frames at ${frameSize.size}; using ${snapped}`
|
|
17787
|
+
});
|
|
17788
|
+
animation.frameCount = snapped;
|
|
17789
|
+
} else {
|
|
17790
|
+
animation.frameCount = frames;
|
|
17791
|
+
}
|
|
17792
|
+
const { min, max } = limits.frameDurationMs;
|
|
17793
|
+
const duration = animation.frameDurationMs ?? limits.defaultFrameDurationMs;
|
|
17794
|
+
if (duration < min || duration > max) {
|
|
17795
|
+
if (onUnsupported === "error") {
|
|
17796
|
+
refuse(model, `${model.id} shows each GIF frame ${min} to ${max} ms; got ${duration}`);
|
|
17797
|
+
}
|
|
17798
|
+
const snapped = clamp(duration, min, max);
|
|
17799
|
+
warnings.push({
|
|
17800
|
+
code: "option_ignored",
|
|
17801
|
+
field: "animation.frameDurationMs",
|
|
17802
|
+
from: duration,
|
|
17803
|
+
to: snapped,
|
|
17804
|
+
message: `${model.id} shows each GIF frame ${min} to ${max} ms; using ${snapped}`
|
|
17805
|
+
});
|
|
17806
|
+
animation.frameDurationMs = snapped;
|
|
17807
|
+
} else {
|
|
17808
|
+
animation.frameDurationMs = duration;
|
|
17809
|
+
}
|
|
17810
|
+
req.animation = animation;
|
|
17811
|
+
req.size = animationTier(model, frameSize.size);
|
|
17812
|
+
}
|
|
17813
|
+
function applyImageOutputRules(model, req, onUnsupported, warnings) {
|
|
17814
|
+
const c = model.constraints;
|
|
17815
|
+
const format = req.outputFormat;
|
|
17816
|
+
if (format !== void 0 && !imageOutputFormats(model).includes(format)) {
|
|
17817
|
+
if (onUnsupported === "error") {
|
|
17818
|
+
refuse(
|
|
17819
|
+
model,
|
|
17820
|
+
`${model.id} does not offer outputFormat ${format}. Supported: ${imageOutputFormats(model).join(", ")}.`
|
|
17821
|
+
);
|
|
17822
|
+
}
|
|
17823
|
+
warnings.push({
|
|
17824
|
+
code: "option_ignored",
|
|
17825
|
+
field: "outputFormat",
|
|
17826
|
+
from: format,
|
|
17827
|
+
message: `${model.id} does not offer ${format}; ignored`
|
|
17828
|
+
});
|
|
17829
|
+
delete req.outputFormat;
|
|
17830
|
+
}
|
|
17831
|
+
if (req.background !== void 0 && !(c.backgrounds ?? []).includes(req.background)) {
|
|
17832
|
+
if (onUnsupported === "error") {
|
|
17833
|
+
refuse(model, `${model.id} does not offer background ${req.background}`);
|
|
17834
|
+
}
|
|
17835
|
+
warnings.push({
|
|
17836
|
+
code: "option_ignored",
|
|
17837
|
+
field: "background",
|
|
17838
|
+
from: req.background,
|
|
17839
|
+
message: `${model.id} does not offer background ${req.background}; ignored`
|
|
17840
|
+
});
|
|
17841
|
+
delete req.background;
|
|
17842
|
+
}
|
|
17843
|
+
if (req.outputFormat === "gif") {
|
|
17844
|
+
applyAnimation(model, req, onUnsupported, warnings);
|
|
17845
|
+
} else if (req.animation !== void 0) {
|
|
17846
|
+
warnings.push({
|
|
17847
|
+
code: "option_ignored",
|
|
17848
|
+
field: "animation",
|
|
17849
|
+
message: `animation applies to GIF output only; ignored`
|
|
17850
|
+
});
|
|
17851
|
+
delete req.animation;
|
|
17852
|
+
}
|
|
17853
|
+
if (req.outputFormat === "svg") {
|
|
17854
|
+
if (!c.svgModel) refuse(model, `${model.id} names no svgModel to write the SVG`);
|
|
17855
|
+
if ((req.references ?? []).length > 0) {
|
|
17856
|
+
refuse(model, `${model.label} cannot make an SVG from reference images`);
|
|
17857
|
+
}
|
|
17858
|
+
if ((req.count ?? 1) > 1) {
|
|
17859
|
+
if (onUnsupported === "error") {
|
|
17860
|
+
refuse(model, `${model.label} makes one SVG per call`);
|
|
17861
|
+
}
|
|
17862
|
+
warnings.push({
|
|
17863
|
+
code: "option_ignored",
|
|
17864
|
+
field: "count",
|
|
17865
|
+
from: req.count,
|
|
17866
|
+
to: 1,
|
|
17867
|
+
message: `${model.id} makes one SVG per call; using 1`
|
|
17868
|
+
});
|
|
17869
|
+
req.count = 1;
|
|
17870
|
+
}
|
|
17871
|
+
}
|
|
17872
|
+
}
|
|
17873
|
+
|
|
17615
17874
|
// src/resolve-lists.ts
|
|
17616
17875
|
function preview(listed2) {
|
|
17617
17876
|
const shown = listed2.slice(0, 12).join(", ");
|
|
@@ -17924,6 +18183,7 @@ function resolveImageOptions(model, request, onUnsupported = "error") {
|
|
|
17924
18183
|
"points",
|
|
17925
18184
|
"boxes"
|
|
17926
18185
|
]);
|
|
18186
|
+
applyImageOutputRules(model, merged, onUnsupported, warnings);
|
|
17927
18187
|
const factor = merged.scaleFactor;
|
|
17928
18188
|
if (factor !== void 0 && c.scaleFactors && !c.scaleFactors.includes(factor)) {
|
|
17929
18189
|
if (onUnsupported === "error") {
|
|
@@ -18260,7 +18520,7 @@ function setOrDelete(req, field, refs) {
|
|
|
18260
18520
|
else delete req[field];
|
|
18261
18521
|
}
|
|
18262
18522
|
function isImageFormat(format) {
|
|
18263
|
-
return format === "png" || format === "jpeg" || format === "webp";
|
|
18523
|
+
return format === "png" || format === "jpeg" || format === "webp" || format === "gif" || format === "svg";
|
|
18264
18524
|
}
|
|
18265
18525
|
function stripUndefined(obj) {
|
|
18266
18526
|
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
@@ -18467,7 +18727,7 @@ function resolveTranscriptionOptions(model, request, onUnsupported = "error") {
|
|
|
18467
18727
|
}
|
|
18468
18728
|
|
|
18469
18729
|
// src/resolve-voice.ts
|
|
18470
|
-
function
|
|
18730
|
+
function refuse2(model, code, message) {
|
|
18471
18731
|
return new ModelKitError({ code, message: `${model.label} ${message}`, model: model.id });
|
|
18472
18732
|
}
|
|
18473
18733
|
function checkSample(model, sample, index) {
|
|
@@ -18476,7 +18736,7 @@ function checkSample(model, sample, index) {
|
|
|
18476
18736
|
if (limits === void 0 || length === void 0) return;
|
|
18477
18737
|
if (limits.min !== void 0 && length < limits.min || limits.max !== void 0 && length > limits.max) {
|
|
18478
18738
|
const range2 = `${limits.min ?? 0}-${limits.max ?? "any"} s`;
|
|
18479
|
-
throw
|
|
18739
|
+
throw refuse2(
|
|
18480
18740
|
model,
|
|
18481
18741
|
"unsupported_option",
|
|
18482
18742
|
`takes samples of ${range2}; sample ${index + 1} is ${length} s`
|
|
@@ -18485,11 +18745,11 @@ function checkSample(model, sample, index) {
|
|
|
18485
18745
|
}
|
|
18486
18746
|
function resolveVoiceCloneOptions(model, request) {
|
|
18487
18747
|
const title = request.title.trim();
|
|
18488
|
-
if (!title) throw
|
|
18489
|
-
if (request.samples.length === 0) throw
|
|
18748
|
+
if (!title) throw refuse2(model, "missing_input", "needs a title");
|
|
18749
|
+
if (request.samples.length === 0) throw refuse2(model, "missing_input", "needs a voice sample");
|
|
18490
18750
|
const max = model.constraints.references?.audios;
|
|
18491
18751
|
if (max !== void 0 && request.samples.length > max) {
|
|
18492
|
-
throw
|
|
18752
|
+
throw refuse2(
|
|
18493
18753
|
model,
|
|
18494
18754
|
"unsupported_option",
|
|
18495
18755
|
`takes up to ${max} samples; got ${request.samples.length}`
|
|
@@ -18499,7 +18759,7 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18499
18759
|
const total = model.constraints.references?.audioSeconds?.total;
|
|
18500
18760
|
const seconds3 = request.samples.reduce((sum, s) => sum + (s.audio.durationSeconds ?? 0), 0);
|
|
18501
18761
|
if (total !== void 0 && seconds3 > total) {
|
|
18502
|
-
throw
|
|
18762
|
+
throw refuse2(
|
|
18503
18763
|
model,
|
|
18504
18764
|
"unsupported_option",
|
|
18505
18765
|
`takes up to ${total} s of samples; got ${seconds3} s`
|
|
@@ -18508,7 +18768,7 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18508
18768
|
for (const field of ["transcript", "designSignature"]) {
|
|
18509
18769
|
const set = request.samples.filter((s) => s[field]?.trim()).length;
|
|
18510
18770
|
if (set !== 0 && set !== request.samples.length) {
|
|
18511
|
-
throw
|
|
18771
|
+
throw refuse2(model, "missing_input", `needs ${field} on every sample or on none`);
|
|
18512
18772
|
}
|
|
18513
18773
|
}
|
|
18514
18774
|
return { request: { ...request, model: model.id, title }, warnings: [] };
|
|
@@ -18516,10 +18776,10 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18516
18776
|
function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
18517
18777
|
const warnings = [];
|
|
18518
18778
|
const prompt = request.prompt.trim();
|
|
18519
|
-
if (!prompt) throw
|
|
18779
|
+
if (!prompt) throw refuse2(model, "missing_input", "needs a voice description");
|
|
18520
18780
|
const maxChars = promptConventions(model).maxChars;
|
|
18521
18781
|
if (maxChars !== void 0 && prompt.length > maxChars) {
|
|
18522
|
-
throw
|
|
18782
|
+
throw refuse2(
|
|
18523
18783
|
model,
|
|
18524
18784
|
"unsupported_option",
|
|
18525
18785
|
`takes up to ${maxChars} characters; got ${prompt.length}`
|
|
@@ -18530,7 +18790,7 @@ function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
|
18530
18790
|
const preview2 = request.previewText?.trim();
|
|
18531
18791
|
if (preview2) {
|
|
18532
18792
|
if (limits !== void 0 && preview2.length > limits.previewMaxChars) {
|
|
18533
|
-
throw
|
|
18793
|
+
throw refuse2(
|
|
18534
18794
|
model,
|
|
18535
18795
|
"unsupported_option",
|
|
18536
18796
|
`takes a preview line of up to ${limits.previewMaxChars} characters; got ${preview2.length}`
|
|
@@ -18546,7 +18806,7 @@ function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
|
18546
18806
|
const cap = limits?.maxCandidates ?? count2;
|
|
18547
18807
|
if (!Number.isInteger(count2) || count2 < 1 || count2 > cap) {
|
|
18548
18808
|
if (onUnsupported === "error" || !Number.isInteger(count2)) {
|
|
18549
|
-
throw
|
|
18809
|
+
throw refuse2(
|
|
18550
18810
|
model,
|
|
18551
18811
|
"unsupported_option",
|
|
18552
18812
|
`returns 1-${cap} candidates; got ${count2}`
|
|
@@ -20062,6 +20322,7 @@ export {
|
|
|
20062
20322
|
VideoResolutionSchema,
|
|
20063
20323
|
adapterServesType,
|
|
20064
20324
|
aiSdkTextAdapter,
|
|
20325
|
+
animationTier,
|
|
20065
20326
|
arkAdapter,
|
|
20066
20327
|
aspectRatioToSize,
|
|
20067
20328
|
byokProviderForModel,
|
|
@@ -20087,6 +20348,7 @@ export {
|
|
|
20087
20348
|
googleImageAdapter,
|
|
20088
20349
|
hasAwsCredentials,
|
|
20089
20350
|
higgsfieldAdapter,
|
|
20351
|
+
imageOutputFormats,
|
|
20090
20352
|
isArrayInputSpecKey,
|
|
20091
20353
|
isInputSpecKey,
|
|
20092
20354
|
isListed,
|