fix: honor published first-frame video aspect ratios

This commit is contained in:
WuYongJie 2026-11-16 11:51:57 +08:00
parent dff2e22ffd
commit c655bbd81e
3 changed files with 57 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { canonicalVip98kVideoRatio, vip98kVideoDurationBounds, vip98kVideoContentTypes, vip98kVideoImageRoles } from "./vip98k-video-parameters"; import { canonicalVip98kVideoRatio, vip98kVideoDurationBounds, vip98kVideoContentTypes, vip98kVideoImageRoles, vip98kFirstFrameRatio } from "./vip98k-video-parameters";
import { VIP98K_TASK_POLL_SECONDS } from "./vip98k-runtime-config"; import { VIP98K_TASK_POLL_SECONDS } from "./vip98k-runtime-config";
import { import {
hasVerifiedVip98kGptImage25ResolutionTiers, hasVerifiedVip98kGptImage25ResolutionTiers,
@ -885,7 +885,8 @@ function createVideoPreset(
...(supportsFramePair ? ["first-last-frame"] : []), ...(supportsFramePair ? ["first-last-frame"] : []),
...(supportsIngredients ? ["reference-images"] : []), ...(supportsIngredients ? ["reference-images"] : []),
]; ];
const ratios = parseStringArray(toRecord(schema.aspect_ratio || schema.ratio)?.enum).map(canonicalVip98kVideoRatio).filter(value => value !== "adaptive"); const ratios = parseStringArray(toRecord(schema.aspect_ratio || schema.ratio)?.enum).map(canonicalVip98kVideoRatio);
const firstFrameRatio = vip98kFirstFrameRatio(invocation?.input_schema);
const maxReferenceImages = Number(toRecord(schema.file_urls)?.maxItems) || (contentTypes.includes("image_url") ? 30 : supportsReferenceImages ? 1 : 0); const maxReferenceImages = Number(toRecord(schema.file_urls)?.maxItems) || (contentTypes.includes("image_url") ? 30 : supportsReferenceImages ? 1 : 0);
return { return {
@ -907,6 +908,10 @@ function createVideoPreset(
outputModes, outputModes,
supportedResolutions, supportedResolutions,
supportedRatios: ratios.length ? ratios : [...DEFAULT_VIDEO_RATIOS], supportedRatios: ratios.length ? ratios : [...DEFAULT_VIDEO_RATIOS],
...(firstFrameRatio ? { modeConstraints: {
"first-frame": { ratioOptions: [firstFrameRatio] },
"first-last-frame": { ratioOptions: [firstFrameRatio] },
} } : {}),
durationOptions: durations, durationOptions: durations,
durationRange: durations.length durationRange: durations.length
? { min: durations[0], max: durations[durations.length - 1] } ? { min: durations[0], max: durations[durations.length - 1] }

View File

@ -6,6 +6,19 @@ export function canonicalVip98kVideoRatio(value: string) {
return value === "landscape" ? "16:9" : value === "portrait" ? "9:16" : value; return value === "landscape" ? "16:9" : value === "portrait" ? "9:16" : value;
} }
export function vip98kFirstFrameRatio(schema: unknown): string | undefined {
const current = object(schema);
const content = object(object(object(current.if).properties).content);
const role = object(object(object(content.contains).properties).role).const;
const properties = object(object(current.then).properties);
const ratio = object(properties.ratio || properties.aspect_ratio).const;
if (role === "first_frame" && typeof ratio === "string") return ratio;
for (const child of Array.isArray(current.allOf) ? current.allOf : []) {
const value = vip98kFirstFrameRatio(child);
if (value) return value;
}
}
export function vip98kVideoDurationBounds(schema: unknown, resolution?: string) { export function vip98kVideoDurationBounds(schema: unknown, resolution?: string) {
let min = 0, max = Infinity; let min = 0, max = Infinity;
let durations: number[] | undefined; let durations: number[] | undefined;
@ -34,6 +47,13 @@ export function vip98kVideoDurationBounds(schema: unknown, resolution?: string)
export function mapVip98kVideoParameters(body: Record<string, unknown>, schema: unknown) { export function mapVip98kVideoParameters(body: Record<string, unknown>, schema: unknown) {
const properties = object(object(schema).properties); const properties = object(object(schema).properties);
const frameRatio = vip98kFirstFrameRatio(schema);
if (frameRatio && Array.isArray(body.content) && body.content.some(item => object(item).role === "first_frame")) {
const field = properties.ratio ? "ratio" : "aspect_ratio";
if (body[field] && body[field] !== "auto" && body[field] !== frameRatio)
throw Error("当前首帧模式沿用原图比例,请选择自动比例");
body[field] = frameRatio;
}
const ratios = object(properties.aspect_ratio).enum; const ratios = object(properties.aspect_ratio).enum;
if (Array.isArray(ratios) && !ratios.includes(body.aspect_ratio)) { if (Array.isArray(ratios) && !ratios.includes(body.aspect_ratio)) {
const alias = body.aspect_ratio === "16:9" ? "landscape" : body.aspect_ratio === "9:16" ? "portrait" : undefined; const alias = body.aspect_ratio === "16:9" ? "landscape" : body.aspect_ratio === "9:16" ? "portrait" : undefined;

View File

@ -8,6 +8,7 @@ import { audioRequestSchema } from "@/lib/video-canvas/audio-contract";
import { buildVip98kAudioBody, vip98kAudioContracts } from "@/lib/video-canvas/vip98k-audio-contract"; import { buildVip98kAudioBody, vip98kAudioContracts } from "@/lib/video-canvas/vip98k-audio-contract";
import { vip98kVideoDurationBounds } from "@/lib/ai/vip98k-video-parameters"; import { vip98kVideoDurationBounds } from "@/lib/ai/vip98k-video-parameters";
import { readVip98kAudioFile } from "@/lib/video-canvas/vip98k-audio-file"; import { readVip98kAudioFile } from "@/lib/video-canvas/vip98k-audio-file";
import { getCanvasVideoParameters } from "@/lib/video-canvas/model-matching";
test("Anthropic-only routes preserve tool calls and relay routing", async () => { test("Anthropic-only routes preserve tool calls and relay routing", async () => {
let sent: any; let sent: any;
@ -70,6 +71,35 @@ test("Seedance content binds prompts and reference roles", () => {
expect(vip98kVideoDurationBounds(i.inputSchema)).toMatchObject({min:4,max:30}); expect(vip98kVideoDurationBounds(i.inputSchema)).toMatchObject({min:4,max:30});
}); });
test("published first-frame ratio constraints reach the canvas and submission", () => {
const schema = {
properties: {
content: { items: { oneOf: [
{ properties: { type: { const: "text" } } },
{ properties: { type: { const: "image_url" }, role: { enum: ["first_frame", "last_frame", "reference_image"] } } },
] } },
ratio: { enum: ["16:9", "1:1", "adaptive"] },
},
allOf: [{ allOf: [{
if: { properties: { content: { contains: { properties: { type: { const: "image_url" }, role: { const: "first_frame" } }, required: ["type"] } } } },
then: { properties: { ratio: { const: "adaptive" } } },
}] }],
};
const [model] = buildVip98kModelPresets([{ id: "video-fixture", type: "video", input_modes: ["image_url"], invocation: {
kind: "task", path: "/extensions/v1/tasks", input_schema: schema, request_example: { model: "video-fixture", ratio: "adaptive" },
} }]);
expect(getCanvasVideoParameters(model, "first-frame").ratios).toEqual(["adaptive"]);
expect(getCanvasVideoParameters(model, "first-last-frame").ratios).toEqual(["adaptive"]);
expect(getCanvasVideoParameters(model, "reference-images").ratios).toContain("16:9");
const config = { ...invocation(schema.properties), inputSchema: schema };
const request = { ...params, kind: "video", imageParams: {}, imageUrls: ["https://example.com/qa.png"], videoParams: { mode: "first-frame", ratio: "adaptive" } };
expect(buildTaskBody(request, config).body.ratio).toBe("adaptive");
expect(() => buildTaskBody({ ...request, videoParams: { mode: "first-frame", ratio: "16:9" } }, config)).toThrow("沿用原图比例");
const reference = buildTaskBody({ ...request, videoParams: { mode: "reference-images", ratio: "16:9" } }, config).body;
expect(reference.ratio).toBe("16:9");
expect(reference.content).toContainEqual({ type: "image_url", image_url: { url: "https://example.com/qa.png" }, role: "reference_image" });
});
test("all fourteen audio entries expose distinct supported modes", () => { test("all fourteen audio entries expose distinct supported modes", () => {
expect(Object.keys(vip98kAudioContracts)).toHaveLength(14); expect(Object.keys(vip98kAudioContracts)).toHaveLength(14);
expect(vip98kAudioContracts["mimo-v2.5-asr"].kind).toBe("asr"); expect(vip98kAudioContracts["mimo-v2.5-asr"].kind).toBe("asr");