openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
81 lines (80 loc) • 3.13 kB
JavaScript
import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs";
import { x as uniqueValues } from "./string-normalization-DLmfYZXI.mjs";
import { t as positiveDurationError } from "./positive-duration-Zq7en3h8.mjs";
//#region src/video-generation/capabilities.ts
function listSupportedVideoGenerationModes(e) {
const t = ["generate"];
if (e.capabilities.imageToVideo?.enabled) t.push("imageToVideo");
if (e.capabilities.videoToVideo?.enabled) t.push("videoToVideo");
return t;
}
function resolveVideoGenerationModeCapabilities(e) {
const t = e.inputImageCount ?? 0;
const n = e.inputVideoCount ?? 0;
let r = "generate";
if (t > 0 && n > 0) r = null;
else if (n > 0) r = "videoToVideo";
else if (t > 0) r = "imageToVideo";
const i = e.provider?.capabilities;
const withModelLimits = (t) => {
const n = e.model?.trim();
if (!t || !n) return t;
const r = t.maxInputImagesByModel?.[n];
const i = t.maxInputVideosByModel?.[n];
const a = t.maxInputAudiosByModel?.[n];
if (typeof r !== "number" && typeof i !== "number" && typeof a !== "number") return t;
return {
...t,
...typeof r === "number" ? { maxInputImages: r } : {},
...typeof i === "number" ? { maxInputVideos: i } : {},
...typeof a === "number" ? { maxInputAudios: a } : {}
};
};
if (!i) return {
mode: r,
capabilities: void 0
};
if (r) return {
mode: r,
capabilities: withModelLimits(i[r])
};
const a = withModelLimits(i.videoToVideo);
if (t > 0 && n > 0 && a?.enabled && (a.maxInputImages ?? 0) > 0) return {
mode: r,
capabilities: a
};
return {
mode: r,
capabilities: void 0
};
}
//#endregion
//#region src/video-generation/duration-support.ts
function resolveVideoGenerationSupportedDurations(e) {
const { capabilities: t } = resolveVideoGenerationModeCapabilities(e);
const n = e.model?.trim();
const r = (n && t?.supportedDurationSecondsByModel ? t.supportedDurationSecondsByModel[n] : void 0) ?? t?.supportedDurationSeconds;
if (!Array.isArray(r) || r.length === 0) return;
const i = uniqueValues(r).filter((e) => Number.isFinite(e) && e > 0).map((e) => Math.round(e)).filter((e) => e > 0).toSorted((e, t) => e - t);
return i.length > 0 ? i : void 0;
}
function normalizeVideoGenerationDuration(e) {
if (e.durationSeconds === void 0) return;
const t = parseStrictPositiveInteger(Math.round(e.durationSeconds));
if (t === void 0) throw positiveDurationError("durationSeconds", "s");
const n = e.supportedDurationSeconds ?? resolveVideoGenerationSupportedDurations(e);
if (!n || n.length === 0) return t;
return selectSupportedVideoDuration(t, n);
}
/** Select from a nonempty duration list, preferring the longer value on ties. */
function selectSupportedVideoDuration(e, t) {
return t.reduce((t, n) => {
const r = Math.abs(n - e);
const i = Math.abs(t - e);
if (r < i) return n;
if (r === i && n > t) return n;
return t;
});
}
//#endregion
export { resolveVideoGenerationModeCapabilities as a, listSupportedVideoGenerationModes as i, resolveVideoGenerationSupportedDurations as n, selectSupportedVideoDuration as r, normalizeVideoGenerationDuration as t };