若干更新迭代

This commit is contained in:
andy committed 2026-10-02 19:56:32 +08:00
1 parent deb9cc5bcf
commit 4ac786aafb
64 files changed
+3251 -291

No files matched your search

+35 -9
View File
@@ -13,6 +13,17 @@ export type BailianTaskResponse = Record<string, unknown> & {
message?: string;
};
export function bailianOutputVideoSeconds(response: BailianTaskResponse): number | undefined {
const usage = response.usage && typeof response.usage === "object" && !Array.isArray(response.usage)
? response.usage as Record<string, unknown>
: {};
for (const value of [usage.output_video_duration, usage.duration]) {
const seconds = typeof value === "number" ? value : NaN;
if (Number.isFinite(seconds) && seconds > 0) return seconds;
}
return undefined;
}
export function getBailianConfig() {
const compatibleBaseUrl = (process.env.BAILIAN_BASE_URL || BAILIAN_DEFAULT_BASE_URL).replace(/\/+$/, "");
return {
@@ -65,25 +76,40 @@ export function validateBailianImageSize(width?: number, height?: number, editin
if (ratio < 1 / 8 || ratio > 8) throw new Error("百炼图片宽高比须在 1:8 至 8:1 之间。");
}
export function buildBailianVideoPayload(input: { prompt: string; materials: PromptMaterial[]; origin: string; settings: Record<string, unknown> }) {
export function buildBailianVideoPayload(input: { prompt: string; materials: PromptMaterial[]; origin: string; settings: Record<string, unknown>; model?: string }) {
const model = input.model || getBailianConfig().videoModel;
const wan30 = model === "wan3.0-video";
const mode = String(input.settings.inputMode || (wan30 ? "reference" : "frames"));
if (mode !== "frames" && mode !== "reference") throw new Error("百炼请选择首尾帧或多图参考模式。");
if (!wan30 && mode === "reference") throw new Error("Wan 2.7 仅支持首尾帧;多图参考请选择 Wan 3.0。");
const images = input.materials.filter((item) => item.type === "image");
if (images.length < 1 || images.length > 2 || input.materials.some((item) => item.type !== "image")) {
if (input.materials.some((item) => item.type !== "image")) {
throw new Error("百炼当前视频模式仅支持图片素材,请移除视频或音频。");
}
if (mode === "reference" && images.length > 10) {
throw new Error("Wan 3.0 多图参考模式最多支持 10 张图片。");
}
if (mode === "frames" && (images.length < 1 || images.length > 2)) {
throw new Error("百炼图生视频仅支持 1 张首帧图,或 2 张首尾帧图。");
}
const duration = numberValue(input.settings.duration) ?? 10;
if (!Number.isInteger(duration) || duration < 2 || duration > 15) throw new Error("百炼视频时长须为 2–15 秒。");
if (!Number.isInteger(duration) || duration < 2 || duration > (wan30 ? 30 : 15)) throw new Error(`百炼视频时长须为 2–${wan30 ? 30 : 15} 秒。`);
const resolution = String(input.settings.resolution || "720P").toUpperCase();
if (resolution !== "720P" && resolution !== "1080P") throw new Error("百炼视频分辨率仅支持 720P 或 1080P。");
if (!["720P", "1080P", ...(wan30 ? ["480P"] : [])].includes(resolution)) throw new Error("百炼视频分辨率不支持当前设置。");
const ratio = input.settings.ratio === undefined ? undefined : String(input.settings.ratio);
if (wan30 && ratio !== undefined && !["adaptive", "21:9", "16:9", "4:3", "1:1", "3:4", "9:16"].includes(ratio)) {
throw new Error("Wan 3.0 画面比例支持自适应、21:9、16:9、4:3、1:1、3:4 或 9:16。");
}
return {
model: getBailianConfig().videoModel,
model,
input: {
prompt: input.prompt,
media: images.map((item, index) => ({
type: index === 0 ? "first_frame" : "last_frame",
...(images.length > 0 ? { media: images.map((item, index) => ({
type: mode === "reference" ? "reference_image" : index === 0 ? "first_frame" : "last_frame",
url: toAbsoluteUrl(item.url, input.origin)
}))
})) } : {})
},
parameters: { resolution, duration, prompt_extend: true, watermark: false }
parameters: { resolution, duration, prompt_extend: true, watermark: false, ...(wan30 && ratio ? { ratio } : {}) }
};
}