@shop-os/modelkit 0.17.1 → 0.18.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 +14 -0
- package/dist/catalog.cjs +203 -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 +203 -15
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +282 -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 +280 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ __export(index_exports, {
|
|
|
58
58
|
VideoResolutionSchema: () => VideoResolutionSchema,
|
|
59
59
|
adapterServesType: () => adapterServesType,
|
|
60
60
|
aiSdkTextAdapter: () => aiSdkTextAdapter,
|
|
61
|
+
animationTier: () => animationTier,
|
|
61
62
|
arkAdapter: () => arkAdapter,
|
|
62
63
|
aspectRatioToSize: () => aspectRatioToSize,
|
|
63
64
|
byokProviderForModel: () => byokProviderForModel,
|
|
@@ -83,6 +84,7 @@ __export(index_exports, {
|
|
|
83
84
|
googleImageAdapter: () => googleImageAdapter,
|
|
84
85
|
hasAwsCredentials: () => hasAwsCredentials,
|
|
85
86
|
higgsfieldAdapter: () => higgsfieldAdapter,
|
|
87
|
+
imageOutputFormats: () => imageOutputFormats,
|
|
86
88
|
isArrayInputSpecKey: () => isArrayInputSpecKey,
|
|
87
89
|
isInputSpecKey: () => isInputSpecKey,
|
|
88
90
|
isListed: () => isListed,
|
|
@@ -598,6 +600,25 @@ var NANO_BANANA_2_1_RATIOS = [
|
|
|
598
600
|
"adaptive"
|
|
599
601
|
];
|
|
600
602
|
var GEMINI_PROMPT_MAX_CHARS = 5e4;
|
|
603
|
+
var GPT_IMAGE_2_6_ANIMATION = {
|
|
604
|
+
frameSizes: [
|
|
605
|
+
{ size: "288x288", minFrames: 2, maxFrames: 16 },
|
|
606
|
+
{ size: "384x384", minFrames: 2, maxFrames: 16 },
|
|
607
|
+
{ size: "512x288", minFrames: 2, maxFrames: 16 },
|
|
608
|
+
{ size: "288x512", minFrames: 2, maxFrames: 16 },
|
|
609
|
+
{ size: "512x512", minFrames: 2, maxFrames: 16 },
|
|
610
|
+
{ size: "768x768", minFrames: 2, maxFrames: 12 }
|
|
611
|
+
],
|
|
612
|
+
frameDurationMs: { min: 20, max: 2e3 },
|
|
613
|
+
defaultFrameCount: 9,
|
|
614
|
+
defaultFrameDurationMs: 200
|
|
615
|
+
};
|
|
616
|
+
var GPT_IMAGE_2_6_OUTPUT = {
|
|
617
|
+
imageFormats: ["png", "gif", "svg"],
|
|
618
|
+
backgrounds: ["auto", "opaque", "transparent"],
|
|
619
|
+
animation: GPT_IMAGE_2_6_ANIMATION,
|
|
620
|
+
svgModel: "gpt-6.1-sol"
|
|
621
|
+
};
|
|
601
622
|
var GPT_IMAGE_PROMPT = { referenceSyntax: "numbered", maxChars: 32e3 };
|
|
602
623
|
function geminiImage(id, label, aliases, sizes, display, exposure, references, promptMaxChars, aspectRatios = GEMINI_RATIOS) {
|
|
603
624
|
const prompt = { referenceSyntax: "caption" };
|
|
@@ -766,7 +787,8 @@ var IMAGE_MODELS = [
|
|
|
766
787
|
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
767
788
|
references: { images: 16 },
|
|
768
789
|
supports: ["quality", "count", "outputFormat"],
|
|
769
|
-
prompt: GPT_IMAGE_PROMPT
|
|
790
|
+
prompt: GPT_IMAGE_PROMPT,
|
|
791
|
+
...GPT_IMAGE_2_6_OUTPUT
|
|
770
792
|
},
|
|
771
793
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
772
794
|
usage: { ...IMAGE_USAGE3 },
|
|
@@ -801,7 +823,8 @@ var IMAGE_MODELS = [
|
|
|
801
823
|
qualityOptions: ["auto", "low", "medium", "high", "xhigh", "max"],
|
|
802
824
|
references: { images: 16 },
|
|
803
825
|
supports: ["quality", "count", "outputFormat"],
|
|
804
|
-
prompt: GPT_IMAGE_PROMPT
|
|
826
|
+
prompt: GPT_IMAGE_PROMPT,
|
|
827
|
+
...GPT_IMAGE_2_6_OUTPUT
|
|
805
828
|
},
|
|
806
829
|
defaults: { size: "1K", aspectRatio: "adaptive", quality: "auto" },
|
|
807
830
|
usage: { ...IMAGE_USAGE3 },
|
|
@@ -8027,7 +8050,20 @@ var AspectRatioSchema = import_zod3.z.enum([
|
|
|
8027
8050
|
var ImageSizeSchema = import_zod3.z.enum(["512", "1K", "2K", "4K"]);
|
|
8028
8051
|
var VideoResolutionSchema = import_zod3.z.enum(["360p", "480p", "720p", "768p", "1080p", "2k", "4k"]);
|
|
8029
8052
|
var ImageQualitySchema = import_zod3.z.enum(["auto", "low", "medium", "high", "xhigh", "max"]);
|
|
8030
|
-
var OutputFormatSchema = import_zod3.z.enum(["png", "jpeg", "webp"]);
|
|
8053
|
+
var OutputFormatSchema = import_zod3.z.enum(["png", "jpeg", "webp", "gif", "svg"]);
|
|
8054
|
+
var ImageBackgroundSchema = import_zod3.z.enum(["auto", "opaque", "transparent"]);
|
|
8055
|
+
var AnimationLimitsSchema = import_zod3.z.looseObject({
|
|
8056
|
+
frameSizes: import_zod3.z.array(
|
|
8057
|
+
import_zod3.z.looseObject({
|
|
8058
|
+
size: import_zod3.z.string().regex(/^\d+x\d+$/u),
|
|
8059
|
+
minFrames: import_zod3.z.number().int().positive(),
|
|
8060
|
+
maxFrames: import_zod3.z.number().int().positive()
|
|
8061
|
+
})
|
|
8062
|
+
).min(1),
|
|
8063
|
+
frameDurationMs: import_zod3.z.looseObject({ min: import_zod3.z.number().positive(), max: import_zod3.z.number().positive() }),
|
|
8064
|
+
defaultFrameCount: import_zod3.z.number().int().positive(),
|
|
8065
|
+
defaultFrameDurationMs: import_zod3.z.number().positive()
|
|
8066
|
+
});
|
|
8031
8067
|
var RequiredInputSchema = import_zod3.z.enum(["firstFrame", "sourceVideo", "references", "sourceAudio"]);
|
|
8032
8068
|
var SupportedOptionSchema = import_zod3.z.enum([
|
|
8033
8069
|
"seed",
|
|
@@ -8181,6 +8217,10 @@ var ModelConstraintsSchema = import_zod3.z.looseObject({
|
|
|
8181
8217
|
}).optional(),
|
|
8182
8218
|
languages: import_zod3.z.array(LanguageOptionSchema).optional(),
|
|
8183
8219
|
outputFormats: import_zod3.z.array(import_zod3.z.string().min(1)).min(1).optional(),
|
|
8220
|
+
imageFormats: import_zod3.z.array(OutputFormatSchema).min(1).optional(),
|
|
8221
|
+
backgrounds: import_zod3.z.array(ImageBackgroundSchema).min(1).optional(),
|
|
8222
|
+
animation: AnimationLimitsSchema.optional(),
|
|
8223
|
+
svgModel: import_zod3.z.string().min(1).optional(),
|
|
8184
8224
|
sourceVideoPixels: VideoPixelLimitsSchema.optional(),
|
|
8185
8225
|
sourceVideoSeconds: VideoSecondsLimitsSchema.omit({ total: true }).extend({ inReferenceTotal: import_zod3.z.boolean().optional() }).optional(),
|
|
8186
8226
|
// segmentSeconds/maxTotalSeconds stay required: a kit before 0.3.0 drops a row whose
|
|
@@ -15977,7 +16017,37 @@ var lumaAdapter = {
|
|
|
15977
16017
|
// src/adapters/openai-image.ts
|
|
15978
16018
|
var import_openai2 = __toESM(require("openai"), 1);
|
|
15979
16019
|
var import_zod28 = require("zod");
|
|
16020
|
+
|
|
16021
|
+
// src/adapters/svg-sanitize.ts
|
|
16022
|
+
var BLOCK_ELEMENTS = /<(script|foreignObject|iframe|object|embed|audio|video|handler|listener)\b[\s\S]*?<\/\1\s*>/giu;
|
|
16023
|
+
var SELF_CLOSING = /<(script|foreignObject|iframe|object|embed|audio|video|handler|listener)\b[^>]*\/>/giu;
|
|
16024
|
+
var EVENT_ATTRIBUTE = /\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/giu;
|
|
16025
|
+
var EXTERNAL_HREF = /\s+(xlink:)?href\s*=\s*("(?!#)[^"]*"|'(?!#)[^']*')/giu;
|
|
16026
|
+
var STYLE_IMPORT = /@import\b[^;]*;?/giu;
|
|
16027
|
+
var STILL_ACTIVE = /<(script|foreignObject|iframe|object|embed)\b|\son[a-z]+\s*=|javascript:|<!ENTITY|<\?xml-stylesheet/iu;
|
|
16028
|
+
function sanitizeSvg(svg, model) {
|
|
16029
|
+
const cleaned = svg.replace(BLOCK_ELEMENTS, "").replace(SELF_CLOSING, "").replace(EVENT_ATTRIBUTE, "").replace(EXTERNAL_HREF, "").replace(STYLE_IMPORT, "");
|
|
16030
|
+
if (!/<svg\b/iu.test(cleaned) || STILL_ACTIVE.test(cleaned)) {
|
|
16031
|
+
throw new ModelKitError({
|
|
16032
|
+
code: "provider_rejected",
|
|
16033
|
+
message: `${model} returned an SVG that could not be made safe`,
|
|
16034
|
+
provider: "openai-image",
|
|
16035
|
+
model,
|
|
16036
|
+
retryable: false
|
|
16037
|
+
});
|
|
16038
|
+
}
|
|
16039
|
+
return cleaned;
|
|
16040
|
+
}
|
|
16041
|
+
|
|
16042
|
+
// src/adapters/openai-image.ts
|
|
15980
16043
|
var MAX_EDIT_REFERENCES = 16;
|
|
16044
|
+
var MIME_BY_FORMAT = {
|
|
16045
|
+
png: "image/png",
|
|
16046
|
+
jpeg: "image/jpeg",
|
|
16047
|
+
webp: "image/webp",
|
|
16048
|
+
gif: "image/gif",
|
|
16049
|
+
svg: "image/svg+xml"
|
|
16050
|
+
};
|
|
15981
16051
|
function aspectRatioToSize(ratio, tier) {
|
|
15982
16052
|
const TIER_LONG_EDGE = {
|
|
15983
16053
|
"1K": 1024,
|
|
@@ -16089,7 +16159,6 @@ var openaiImageAdapter = {
|
|
|
16089
16159
|
const isEdit = refs.length > 0;
|
|
16090
16160
|
const quality = req.quality ?? (isEdit ? "medium" : "auto");
|
|
16091
16161
|
const sdkQuality = quality;
|
|
16092
|
-
const count2 = req.count !== void 0 && req.count > 1 ? { n: req.count } : {};
|
|
16093
16162
|
let outputFormat = req.outputFormat;
|
|
16094
16163
|
if (outputFormat === "webp") {
|
|
16095
16164
|
ctx.warnings.push({
|
|
@@ -16101,35 +16170,50 @@ var openaiImageAdapter = {
|
|
|
16101
16170
|
});
|
|
16102
16171
|
outputFormat = "png";
|
|
16103
16172
|
}
|
|
16104
|
-
|
|
16105
|
-
|
|
16173
|
+
if (isEdit && outputFormat === "svg") {
|
|
16174
|
+
throw new ModelKitError({
|
|
16175
|
+
code: "unsupported_option",
|
|
16176
|
+
message: `${ctx.model.id} cannot make an SVG from reference images`,
|
|
16177
|
+
provider: "openai-image",
|
|
16178
|
+
model: ctx.model.id,
|
|
16179
|
+
retryable: false
|
|
16180
|
+
});
|
|
16181
|
+
}
|
|
16182
|
+
const svgModel = ctx.model.constraints.svgModel;
|
|
16183
|
+
if (outputFormat === "svg" && !svgModel) {
|
|
16184
|
+
throw new ModelKitError({
|
|
16185
|
+
code: "unsupported_option",
|
|
16186
|
+
message: `${ctx.model.id} names no svgModel to write the SVG`,
|
|
16187
|
+
provider: "openai-image",
|
|
16188
|
+
model: ctx.model.id,
|
|
16189
|
+
retryable: false
|
|
16190
|
+
});
|
|
16191
|
+
}
|
|
16192
|
+
const params = {
|
|
16193
|
+
model: ctx.model.providerModelId,
|
|
16194
|
+
prompt: req.prompt,
|
|
16195
|
+
quality: sdkQuality,
|
|
16196
|
+
...size !== void 0 && { size },
|
|
16197
|
+
// SVG takes no `n` at all (OpenAI: "Use n=1"), not even 1.
|
|
16198
|
+
...req.count !== void 0 && req.count > 1 && outputFormat !== "svg" && { n: req.count },
|
|
16199
|
+
...outputFormat !== void 0 && { output_format: outputFormat },
|
|
16200
|
+
...req.background !== void 0 && { background: req.background },
|
|
16201
|
+
...outputFormat === "gif" && req.animation?.frameCount !== void 0 && {
|
|
16202
|
+
frame_count: req.animation.frameCount
|
|
16203
|
+
},
|
|
16204
|
+
...outputFormat === "gif" && req.animation?.frameDurationMs !== void 0 && {
|
|
16205
|
+
frame_duration_ms: req.animation.frameDurationMs
|
|
16206
|
+
},
|
|
16207
|
+
...outputFormat === "svg" && { svg: { model: svgModel } }
|
|
16208
|
+
};
|
|
16209
|
+
const mime = MIME_BY_FORMAT[outputFormat ?? "png"];
|
|
16106
16210
|
const retryOptions = mediaRetryOptions(ctx.call, ctx.signal);
|
|
16107
16211
|
const response = await withRetry(async () => {
|
|
16108
16212
|
try {
|
|
16109
16213
|
if (!isEdit) {
|
|
16110
|
-
|
|
16111
|
-
|
|
16112
|
-
|
|
16113
|
-
model: ctx.model.providerModelId,
|
|
16114
|
-
prompt: req.prompt,
|
|
16115
|
-
size,
|
|
16116
|
-
quality: sdkQuality,
|
|
16117
|
-
...count2,
|
|
16118
|
-
...format
|
|
16119
|
-
},
|
|
16120
|
-
{ signal: ctx.signal }
|
|
16121
|
-
);
|
|
16122
|
-
}
|
|
16123
|
-
return await client2.images.generate(
|
|
16124
|
-
{
|
|
16125
|
-
model: ctx.model.providerModelId,
|
|
16126
|
-
prompt: req.prompt,
|
|
16127
|
-
quality: sdkQuality,
|
|
16128
|
-
...count2,
|
|
16129
|
-
...format
|
|
16130
|
-
},
|
|
16131
|
-
{ signal: ctx.signal }
|
|
16132
|
-
);
|
|
16214
|
+
return await client2.images.generate(params, {
|
|
16215
|
+
signal: ctx.signal
|
|
16216
|
+
});
|
|
16133
16217
|
}
|
|
16134
16218
|
const files = await Promise.all(
|
|
16135
16219
|
refs.slice(0, MAX_EDIT_REFERENCES).map(async (ref, i) => {
|
|
@@ -16144,37 +16228,19 @@ var openaiImageAdapter = {
|
|
|
16144
16228
|
);
|
|
16145
16229
|
const single = files.length === 1 ? files[0] : void 0;
|
|
16146
16230
|
const imageInput = single ?? files;
|
|
16147
|
-
if (size !== void 0) {
|
|
16148
|
-
return await client2.images.edit(
|
|
16149
|
-
{
|
|
16150
|
-
model: ctx.model.providerModelId,
|
|
16151
|
-
image: imageInput,
|
|
16152
|
-
prompt: req.prompt,
|
|
16153
|
-
size,
|
|
16154
|
-
quality: sdkQuality,
|
|
16155
|
-
...count2,
|
|
16156
|
-
...format
|
|
16157
|
-
},
|
|
16158
|
-
{ signal: ctx.signal }
|
|
16159
|
-
);
|
|
16160
|
-
}
|
|
16161
16231
|
return await client2.images.edit(
|
|
16162
|
-
{
|
|
16163
|
-
model: ctx.model.providerModelId,
|
|
16164
|
-
image: imageInput,
|
|
16165
|
-
prompt: req.prompt,
|
|
16166
|
-
quality: sdkQuality,
|
|
16167
|
-
...count2,
|
|
16168
|
-
...format
|
|
16169
|
-
},
|
|
16232
|
+
{ ...params, image: imageInput },
|
|
16170
16233
|
{ signal: ctx.signal }
|
|
16171
16234
|
);
|
|
16172
16235
|
} catch (cause) {
|
|
16173
16236
|
throw toProviderError2(cause, ctx);
|
|
16174
16237
|
}
|
|
16175
16238
|
}, retryOptions);
|
|
16239
|
+
const decode = (b64) => outputFormat === "svg" ? new TextEncoder().encode(
|
|
16240
|
+
sanitizeSvg(new TextDecoder().decode(base64ToBytes(b64)), ctx.model.id)
|
|
16241
|
+
) : base64ToBytes(b64);
|
|
16176
16242
|
const images = (response.data ?? []).flatMap(
|
|
16177
|
-
(item) => item.b64_json ? [{ bytes:
|
|
16243
|
+
(item) => item.b64_json ? [{ bytes: decode(item.b64_json), mime }] : []
|
|
16178
16244
|
);
|
|
16179
16245
|
if (images.length === 0)
|
|
16180
16246
|
throw classifyHttpError(
|
|
@@ -17758,6 +17824,155 @@ function fileCatalogCache(path) {
|
|
|
17758
17824
|
};
|
|
17759
17825
|
}
|
|
17760
17826
|
|
|
17827
|
+
// src/resolve-image-output.ts
|
|
17828
|
+
var BASE_FORMATS = ["png", "jpeg", "webp"];
|
|
17829
|
+
var ONE_K_FRAME_PIXELS = 288 * 512;
|
|
17830
|
+
function imageOutputFormats(model) {
|
|
17831
|
+
return model.constraints.imageFormats ?? BASE_FORMATS;
|
|
17832
|
+
}
|
|
17833
|
+
function animationTier(model, frameSize) {
|
|
17834
|
+
const [w, h] = frameSize.split("x").map(Number);
|
|
17835
|
+
const tier = (w ?? 0) * (h ?? 0) <= ONE_K_FRAME_PIXELS ? "1K" : "2K";
|
|
17836
|
+
const offered = model.constraints.sizes ?? ["1K", "2K", "4K"];
|
|
17837
|
+
if (offered.includes(tier)) return tier;
|
|
17838
|
+
return offered[offered.length - 1] ?? tier;
|
|
17839
|
+
}
|
|
17840
|
+
function refuse(model, message) {
|
|
17841
|
+
throw new ModelKitError({ code: "unsupported_option", message, model: model.id });
|
|
17842
|
+
}
|
|
17843
|
+
function clamp(value, min, max) {
|
|
17844
|
+
return Math.min(Math.max(value, min), max);
|
|
17845
|
+
}
|
|
17846
|
+
function applyAnimation(model, req, onUnsupported, warnings) {
|
|
17847
|
+
const limits = model.constraints.animation;
|
|
17848
|
+
if (!limits) return;
|
|
17849
|
+
const sizes = limits.frameSizes;
|
|
17850
|
+
let frameSize = sizes.find((s) => s.size === req.exactSize);
|
|
17851
|
+
if (!frameSize) {
|
|
17852
|
+
const fallback = sizes[0];
|
|
17853
|
+
if (req.exactSize !== void 0) {
|
|
17854
|
+
if (onUnsupported === "error") {
|
|
17855
|
+
refuse(
|
|
17856
|
+
model,
|
|
17857
|
+
`${model.id} makes GIF frames at ${sizes.map((s) => s.size).join(", ")}; got ${req.exactSize}`
|
|
17858
|
+
);
|
|
17859
|
+
}
|
|
17860
|
+
warnings.push({
|
|
17861
|
+
code: "option_ignored",
|
|
17862
|
+
field: "exactSize",
|
|
17863
|
+
from: req.exactSize,
|
|
17864
|
+
to: fallback.size,
|
|
17865
|
+
message: `${model.id} has no ${req.exactSize} GIF frame; using ${fallback.size}`
|
|
17866
|
+
});
|
|
17867
|
+
}
|
|
17868
|
+
frameSize = fallback;
|
|
17869
|
+
}
|
|
17870
|
+
req.exactSize = frameSize.size;
|
|
17871
|
+
delete req.aspectRatio;
|
|
17872
|
+
const animation = { ...req.animation };
|
|
17873
|
+
const asked = animation.frameCount;
|
|
17874
|
+
const frames = asked ?? clamp(limits.defaultFrameCount, frameSize.minFrames, frameSize.maxFrames);
|
|
17875
|
+
if (frames < frameSize.minFrames || frames > frameSize.maxFrames || !Number.isInteger(frames)) {
|
|
17876
|
+
if (onUnsupported === "error") {
|
|
17877
|
+
refuse(
|
|
17878
|
+
model,
|
|
17879
|
+
`${model.id} makes ${frameSize.minFrames} to ${frameSize.maxFrames} frames at ${frameSize.size}; got ${frames}`
|
|
17880
|
+
);
|
|
17881
|
+
}
|
|
17882
|
+
const snapped = clamp(Math.round(frames), frameSize.minFrames, frameSize.maxFrames);
|
|
17883
|
+
warnings.push({
|
|
17884
|
+
code: "option_ignored",
|
|
17885
|
+
field: "animation.frameCount",
|
|
17886
|
+
from: frames,
|
|
17887
|
+
to: snapped,
|
|
17888
|
+
message: `${model.id} makes ${frameSize.minFrames} to ${frameSize.maxFrames} frames at ${frameSize.size}; using ${snapped}`
|
|
17889
|
+
});
|
|
17890
|
+
animation.frameCount = snapped;
|
|
17891
|
+
} else {
|
|
17892
|
+
animation.frameCount = frames;
|
|
17893
|
+
}
|
|
17894
|
+
const { min, max } = limits.frameDurationMs;
|
|
17895
|
+
const duration = animation.frameDurationMs ?? limits.defaultFrameDurationMs;
|
|
17896
|
+
if (duration < min || duration > max) {
|
|
17897
|
+
if (onUnsupported === "error") {
|
|
17898
|
+
refuse(model, `${model.id} shows each GIF frame ${min} to ${max} ms; got ${duration}`);
|
|
17899
|
+
}
|
|
17900
|
+
const snapped = clamp(duration, min, max);
|
|
17901
|
+
warnings.push({
|
|
17902
|
+
code: "option_ignored",
|
|
17903
|
+
field: "animation.frameDurationMs",
|
|
17904
|
+
from: duration,
|
|
17905
|
+
to: snapped,
|
|
17906
|
+
message: `${model.id} shows each GIF frame ${min} to ${max} ms; using ${snapped}`
|
|
17907
|
+
});
|
|
17908
|
+
animation.frameDurationMs = snapped;
|
|
17909
|
+
} else {
|
|
17910
|
+
animation.frameDurationMs = duration;
|
|
17911
|
+
}
|
|
17912
|
+
req.animation = animation;
|
|
17913
|
+
req.size = animationTier(model, frameSize.size);
|
|
17914
|
+
}
|
|
17915
|
+
function applyImageOutputRules(model, req, onUnsupported, warnings) {
|
|
17916
|
+
const c = model.constraints;
|
|
17917
|
+
const format = req.outputFormat;
|
|
17918
|
+
if (format !== void 0 && !imageOutputFormats(model).includes(format)) {
|
|
17919
|
+
if (onUnsupported === "error") {
|
|
17920
|
+
refuse(
|
|
17921
|
+
model,
|
|
17922
|
+
`${model.id} does not offer outputFormat ${format}. Supported: ${imageOutputFormats(model).join(", ")}.`
|
|
17923
|
+
);
|
|
17924
|
+
}
|
|
17925
|
+
warnings.push({
|
|
17926
|
+
code: "option_ignored",
|
|
17927
|
+
field: "outputFormat",
|
|
17928
|
+
from: format,
|
|
17929
|
+
message: `${model.id} does not offer ${format}; ignored`
|
|
17930
|
+
});
|
|
17931
|
+
delete req.outputFormat;
|
|
17932
|
+
}
|
|
17933
|
+
if (req.background !== void 0 && !(c.backgrounds ?? []).includes(req.background)) {
|
|
17934
|
+
if (onUnsupported === "error") {
|
|
17935
|
+
refuse(model, `${model.id} does not offer background ${req.background}`);
|
|
17936
|
+
}
|
|
17937
|
+
warnings.push({
|
|
17938
|
+
code: "option_ignored",
|
|
17939
|
+
field: "background",
|
|
17940
|
+
from: req.background,
|
|
17941
|
+
message: `${model.id} does not offer background ${req.background}; ignored`
|
|
17942
|
+
});
|
|
17943
|
+
delete req.background;
|
|
17944
|
+
}
|
|
17945
|
+
if (req.outputFormat === "gif") {
|
|
17946
|
+
applyAnimation(model, req, onUnsupported, warnings);
|
|
17947
|
+
} else if (req.animation !== void 0) {
|
|
17948
|
+
warnings.push({
|
|
17949
|
+
code: "option_ignored",
|
|
17950
|
+
field: "animation",
|
|
17951
|
+
message: `animation applies to GIF output only; ignored`
|
|
17952
|
+
});
|
|
17953
|
+
delete req.animation;
|
|
17954
|
+
}
|
|
17955
|
+
if (req.outputFormat === "svg") {
|
|
17956
|
+
if (!c.svgModel) refuse(model, `${model.id} names no svgModel to write the SVG`);
|
|
17957
|
+
if ((req.references ?? []).length > 0) {
|
|
17958
|
+
refuse(model, `${model.label} cannot make an SVG from reference images`);
|
|
17959
|
+
}
|
|
17960
|
+
if ((req.count ?? 1) > 1) {
|
|
17961
|
+
if (onUnsupported === "error") {
|
|
17962
|
+
refuse(model, `${model.label} makes one SVG per call`);
|
|
17963
|
+
}
|
|
17964
|
+
warnings.push({
|
|
17965
|
+
code: "option_ignored",
|
|
17966
|
+
field: "count",
|
|
17967
|
+
from: req.count,
|
|
17968
|
+
to: 1,
|
|
17969
|
+
message: `${model.id} makes one SVG per call; using 1`
|
|
17970
|
+
});
|
|
17971
|
+
req.count = 1;
|
|
17972
|
+
}
|
|
17973
|
+
}
|
|
17974
|
+
}
|
|
17975
|
+
|
|
17761
17976
|
// src/resolve-lists.ts
|
|
17762
17977
|
function preview(listed2) {
|
|
17763
17978
|
const shown = listed2.slice(0, 12).join(", ");
|
|
@@ -18070,6 +18285,7 @@ function resolveImageOptions(model, request, onUnsupported = "error") {
|
|
|
18070
18285
|
"points",
|
|
18071
18286
|
"boxes"
|
|
18072
18287
|
]);
|
|
18288
|
+
applyImageOutputRules(model, merged, onUnsupported, warnings);
|
|
18073
18289
|
const factor = merged.scaleFactor;
|
|
18074
18290
|
if (factor !== void 0 && c.scaleFactors && !c.scaleFactors.includes(factor)) {
|
|
18075
18291
|
if (onUnsupported === "error") {
|
|
@@ -18406,7 +18622,7 @@ function setOrDelete(req, field, refs) {
|
|
|
18406
18622
|
else delete req[field];
|
|
18407
18623
|
}
|
|
18408
18624
|
function isImageFormat(format) {
|
|
18409
|
-
return format === "png" || format === "jpeg" || format === "webp";
|
|
18625
|
+
return format === "png" || format === "jpeg" || format === "webp" || format === "gif" || format === "svg";
|
|
18410
18626
|
}
|
|
18411
18627
|
function stripUndefined(obj) {
|
|
18412
18628
|
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
@@ -18613,7 +18829,7 @@ function resolveTranscriptionOptions(model, request, onUnsupported = "error") {
|
|
|
18613
18829
|
}
|
|
18614
18830
|
|
|
18615
18831
|
// src/resolve-voice.ts
|
|
18616
|
-
function
|
|
18832
|
+
function refuse2(model, code, message) {
|
|
18617
18833
|
return new ModelKitError({ code, message: `${model.label} ${message}`, model: model.id });
|
|
18618
18834
|
}
|
|
18619
18835
|
function checkSample(model, sample, index) {
|
|
@@ -18622,7 +18838,7 @@ function checkSample(model, sample, index) {
|
|
|
18622
18838
|
if (limits === void 0 || length === void 0) return;
|
|
18623
18839
|
if (limits.min !== void 0 && length < limits.min || limits.max !== void 0 && length > limits.max) {
|
|
18624
18840
|
const range2 = `${limits.min ?? 0}-${limits.max ?? "any"} s`;
|
|
18625
|
-
throw
|
|
18841
|
+
throw refuse2(
|
|
18626
18842
|
model,
|
|
18627
18843
|
"unsupported_option",
|
|
18628
18844
|
`takes samples of ${range2}; sample ${index + 1} is ${length} s`
|
|
@@ -18631,11 +18847,11 @@ function checkSample(model, sample, index) {
|
|
|
18631
18847
|
}
|
|
18632
18848
|
function resolveVoiceCloneOptions(model, request) {
|
|
18633
18849
|
const title = request.title.trim();
|
|
18634
|
-
if (!title) throw
|
|
18635
|
-
if (request.samples.length === 0) throw
|
|
18850
|
+
if (!title) throw refuse2(model, "missing_input", "needs a title");
|
|
18851
|
+
if (request.samples.length === 0) throw refuse2(model, "missing_input", "needs a voice sample");
|
|
18636
18852
|
const max = model.constraints.references?.audios;
|
|
18637
18853
|
if (max !== void 0 && request.samples.length > max) {
|
|
18638
|
-
throw
|
|
18854
|
+
throw refuse2(
|
|
18639
18855
|
model,
|
|
18640
18856
|
"unsupported_option",
|
|
18641
18857
|
`takes up to ${max} samples; got ${request.samples.length}`
|
|
@@ -18645,7 +18861,7 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18645
18861
|
const total = model.constraints.references?.audioSeconds?.total;
|
|
18646
18862
|
const seconds3 = request.samples.reduce((sum, s) => sum + (s.audio.durationSeconds ?? 0), 0);
|
|
18647
18863
|
if (total !== void 0 && seconds3 > total) {
|
|
18648
|
-
throw
|
|
18864
|
+
throw refuse2(
|
|
18649
18865
|
model,
|
|
18650
18866
|
"unsupported_option",
|
|
18651
18867
|
`takes up to ${total} s of samples; got ${seconds3} s`
|
|
@@ -18654,7 +18870,7 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18654
18870
|
for (const field of ["transcript", "designSignature"]) {
|
|
18655
18871
|
const set = request.samples.filter((s) => s[field]?.trim()).length;
|
|
18656
18872
|
if (set !== 0 && set !== request.samples.length) {
|
|
18657
|
-
throw
|
|
18873
|
+
throw refuse2(model, "missing_input", `needs ${field} on every sample or on none`);
|
|
18658
18874
|
}
|
|
18659
18875
|
}
|
|
18660
18876
|
return { request: { ...request, model: model.id, title }, warnings: [] };
|
|
@@ -18662,10 +18878,10 @@ function resolveVoiceCloneOptions(model, request) {
|
|
|
18662
18878
|
function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
18663
18879
|
const warnings = [];
|
|
18664
18880
|
const prompt = request.prompt.trim();
|
|
18665
|
-
if (!prompt) throw
|
|
18881
|
+
if (!prompt) throw refuse2(model, "missing_input", "needs a voice description");
|
|
18666
18882
|
const maxChars = promptConventions(model).maxChars;
|
|
18667
18883
|
if (maxChars !== void 0 && prompt.length > maxChars) {
|
|
18668
|
-
throw
|
|
18884
|
+
throw refuse2(
|
|
18669
18885
|
model,
|
|
18670
18886
|
"unsupported_option",
|
|
18671
18887
|
`takes up to ${maxChars} characters; got ${prompt.length}`
|
|
@@ -18676,7 +18892,7 @@ function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
|
18676
18892
|
const preview2 = request.previewText?.trim();
|
|
18677
18893
|
if (preview2) {
|
|
18678
18894
|
if (limits !== void 0 && preview2.length > limits.previewMaxChars) {
|
|
18679
|
-
throw
|
|
18895
|
+
throw refuse2(
|
|
18680
18896
|
model,
|
|
18681
18897
|
"unsupported_option",
|
|
18682
18898
|
`takes a preview line of up to ${limits.previewMaxChars} characters; got ${preview2.length}`
|
|
@@ -18692,7 +18908,7 @@ function resolveVoiceDesignOptions(model, request, onUnsupported = "error") {
|
|
|
18692
18908
|
const cap = limits?.maxCandidates ?? count2;
|
|
18693
18909
|
if (!Number.isInteger(count2) || count2 < 1 || count2 > cap) {
|
|
18694
18910
|
if (onUnsupported === "error" || !Number.isInteger(count2)) {
|
|
18695
|
-
throw
|
|
18911
|
+
throw refuse2(
|
|
18696
18912
|
model,
|
|
18697
18913
|
"unsupported_option",
|
|
18698
18914
|
`returns 1-${cap} candidates; got ${count2}`
|
|
@@ -20202,6 +20418,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
20202
20418
|
VideoResolutionSchema,
|
|
20203
20419
|
adapterServesType,
|
|
20204
20420
|
aiSdkTextAdapter,
|
|
20421
|
+
animationTier,
|
|
20205
20422
|
arkAdapter,
|
|
20206
20423
|
aspectRatioToSize,
|
|
20207
20424
|
byokProviderForModel,
|
|
@@ -20227,6 +20444,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
20227
20444
|
googleImageAdapter,
|
|
20228
20445
|
hasAwsCredentials,
|
|
20229
20446
|
higgsfieldAdapter,
|
|
20447
|
+
imageOutputFormats,
|
|
20230
20448
|
isArrayInputSpecKey,
|
|
20231
20449
|
isInputSpecKey,
|
|
20232
20450
|
isListed,
|