From 1046e5071732a1238d54edfafe6afe6253cdb878 Mon Sep 17 00:00:00 2001 From: rpone Date: Wed, 11 Nov 2026 13:24:02 +0800 Subject: [PATCH] fix(hypihub): map PixVerse V6 and Bach fields the service accepts - PixVerse V6 sends seed and multi_clip on /v1/videos. - PixVerse aspectRatio auto requires a reference video; Video no longer offers auto, and multiClip cannot be combined with reference videos. - Bach sends reference videos; the earlier client-side block is removed now that HypiHub accepts them on the unified execution contract. - Bach image, video and audio references carry start_time as { url, start_time }; references without an offset stay plain URLs. --- packages/pixverse/src/index.ts | 12 +++++++++--- packages/pixverse/src/surface.ts | 6 +++++- packages/pixverse/src/validation.ts | 9 +++++++-- packages/provider-hypihub/src/mapping.ts | 16 +++++++++++----- packages/provider-hypihub/src/routes.ts | 18 ++++++++++++------ 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/packages/pixverse/src/index.ts b/packages/pixverse/src/index.ts index 44a7a8aad..3fa79d7c9 100644 --- a/packages/pixverse/src/index.ts +++ b/packages/pixverse/src/index.ts @@ -44,6 +44,7 @@ function pixversePortTable(model: PixverseModel): GenerationPortTable { // continuous shot rather than several cuts. { kind: "atMostOneOf", ports: ["multiClip", "lastFrame"] }, { kind: "atMostOneOf", ports: ["multiClip", "referenceImage"] }, + { kind: "atMostOneOf", ports: ["multiClip", "referenceVideo"] }, // The reference videos carry the length of the generated run. { kind: "atMostOneOf", ports: ["duration", "referenceVideo"] }, ] @@ -132,10 +133,15 @@ const pixverseCommonAttributes: readonly SurfaceAttributeVocabulary[] = [ ]; const pixverseAspectRatio: SurfaceAttributeVocabulary = { - name: "aspect-ratio", kind: "literal", required: false, values: [...PIXVERSE_V6_ASPECT_RATIOS], + name: "aspect-ratio", kind: "literal", required: false, values: [...PIXVERSE_ASPECT_RATIOS], summary: "The Frame shape of the generated video.", }; +const pixverseReferenceAspectRatio: SurfaceAttributeVocabulary = { + ...pixverseAspectRatio, values: [...PIXVERSE_V6_ASPECT_RATIOS], + summary: "The Frame shape of the generated video; `auto` takes the shape of the V6 video references.", +}; + const pixverseVideoPort: readonly SurfacePortVocabulary[] = [{ name: "video", type: blobTypes.blob, @@ -197,7 +203,7 @@ export const pixverseMarkupSurfaces = [ ...pixverseCommonAttributes, { name: "duration", kind: "literal" as const, required: false, summary: "How many seconds of video to render, from 1 to 15; video references carry their own length." }, - pixverseAspectRatio, + pixverseReferenceAspectRatio, ], children: [{ tag: "Reference", @@ -220,7 +226,7 @@ export const pixverseMarkupSurfaces = [ pixverseModelNote, "The prompt addresses the references in order as `@ref_1`, `@ref_2` and so on.", "`Reference` carries exactly one of `image` or `video`, and is empty.", - "V6 accepts up to two video references totalling 15 seconds, which carry the length of the run in place of `duration`; `aspect-ratio=\"auto\"` takes their shape.", + "V6 accepts up to two video references totalling 15 seconds, which carry the length of the run in place of `duration`; `aspect-ratio=\"auto\"` takes their shape and requires at least one video reference.", pixversePromptNote, ], }, diff --git a/packages/pixverse/src/surface.ts b/packages/pixverse/src/surface.ts index b0c21a0c8..2e9783d81 100644 --- a/packages/pixverse/src/surface.ts +++ b/packages/pixverse/src/surface.ts @@ -190,7 +190,9 @@ export const decodePixverseVideoSurface: StructuredSurfaceHandler = ({ element, exact(element, VIDEO_ATTRIBUTES, ["id", "model", "prompt", "duration", "quality"]); empty(element); const { endpoint } = selectModel(element); - const frames = ([["firstFrame", "first-frame"], ["lastFrame", "last-frame"]] as const) + assert(element.attributes["aspect-ratio"] !== "auto", + `${element.name}.aspect-ratio auto requires video references; use ReferenceVideo`); + const frames =([["firstFrame", "first-frame"], ["lastFrame", "last-frame"]] as const) .filter(([, attribute]) => element.attributes[attribute] !== undefined) .map(([port, attribute]) => ({ port, role: "image" as const, source: media(element, attribute, "image", resolveReference), @@ -234,6 +236,8 @@ export const decodePixverseReferenceVideoSurface: StructuredSurfaceHandler = ({ capacity(element, endpoint, port, references.filter((item) => item.port === port).length); } const videos = references.some((item) => item.port === "referenceVideo"); + assert(videos || element.attributes["aspect-ratio"] !== "auto", + `${element.name}.aspect-ratio auto requires a video Reference`); if (videos) { assert(element.attributes["duration"] === undefined, `${element.name} takes no duration; its video references carry the length of the run`); diff --git a/packages/pixverse/src/validation.ts b/packages/pixverse/src/validation.ts index cae608022..f8886d644 100644 --- a/packages/pixverse/src/validation.ts +++ b/packages/pixverse/src/validation.ts @@ -3,11 +3,16 @@ import type { PixverseModel } from "./index.js"; /** * Reference videos carry the length of the run, so that mode states no duration. - * Every other mode states its own. + * Every other mode states its own. `aspectRatio` `auto` takes the shape of the + * reference videos, so it requires at least one. */ export function pixverseRequestValidator(model: PixverseModel): (request: GenerationRequest) => void { return (request) => { - if (request.ports.referenceVideo !== undefined || request.ports.duration !== undefined) return; + const videos = (request.ports.referenceVideo?.length ?? 0) > 0; + if (request.ports.aspectRatio?.[0] === "auto" && !videos) { + throw new Error(`${model} aspectRatio auto requires a reference video`); + } + if (videos || request.ports.duration !== undefined) return; throw new Error(`${model} requires duration`); }; } diff --git a/packages/provider-hypihub/src/mapping.ts b/packages/provider-hypihub/src/mapping.ts index b81d2feb9..fa8e2514a 100644 --- a/packages/provider-hypihub/src/mapping.ts +++ b/packages/provider-hypihub/src/mapping.ts @@ -33,8 +33,8 @@ const seedance = (name: string): GenerationWireMapping => ({ /** * PixVerse V6 and C1 on `POST /v1/videos`. Both take the same body; V6 additionally accepts - * reference videos, which carry the length of the run in place of `seconds`. The model's own - * `quality` band is HypiHub's `resolution`. + * reference videos, which carry the length of the run in place of `seconds`, a sampling `seed` + * and the `multi_clip` switch. The model's own `quality` band is HypiHub's `resolution`. */ const pixverse = (name: string, model: string): GenerationWireMapping => ({ capability: { module: PIXVERSE, name }, result: "video", routes: [{ model }], @@ -43,7 +43,11 @@ const pixverse = (name: string, model: string): GenerationWireMapping => ({ firstFrame: { as: "url", field: "first_frame" }, lastFrame: { as: "url", field: "last_frame" }, referenceImage: { as: "urlArray", field: "reference_image_urls" }, - ...(name === "pixverse-v6" ? { referenceVideo: { as: "urlArray" as const, field: "reference_videos" } } : {}), + ...(name === "pixverse-v6" ? { + referenceVideo: { as: "urlArray" as const, field: "reference_videos" }, + seed: { as: "value" as const, field: "seed" }, + multiClip: { as: "value" as const, field: "multi_clip" }, + } : {}), duration: { as: "value", field: "seconds" }, quality: { as: "value", field: "resolution" }, aspectRatio: { as: "value", field: "aspect_ratio" }, @@ -63,8 +67,10 @@ export const hypiHubMappings: readonly GenerationWireMapping[] = [ seed: { as: "value", field: "seed" }, firstFrame: { as: "url", field: "first_frame" }, lastFrame: { as: "url", field: "last_frame" }, - referenceImage: { as: "urlArray", field: "reference_image_urls" }, - referenceAudio: { as: "urlArray", field: "reference_audios" }, + // Each reference may carry a `start_time` offset, sent as `{ url, start_time }`. + referenceImage: { as: "itemObject", field: "reference_image_urls", urlKey: "url", fieldKeys: { startTime: "start_time" } }, + referenceVideo: { as: "itemObject", field: "reference_videos", urlKey: "url", fieldKeys: { startTime: "start_time" } }, + referenceAudio: { as: "itemObject", field: "reference_audios", urlKey: "url", fieldKeys: { startTime: "start_time" } }, }, }, { diff --git a/packages/provider-hypihub/src/routes.ts b/packages/provider-hypihub/src/routes.ts index 8806cac32..ff255a51d 100644 --- a/packages/provider-hypihub/src/routes.ts +++ b/packages/provider-hypihub/src/routes.ts @@ -42,9 +42,6 @@ function hypiHubGenerationRejection( pendingPorts: readonly string[] = [], ): string | undefined { if (mapping.capability.module.name === "@hypit/bach") { - if ((request.ports.referenceVideo?.length ?? 0) > 0 || pendingPorts.includes("referenceVideo")) { - return "HypiHub Bach reference videos await verification of upstream input billing"; - } try { selectWireModelForRequest(mapping, request, pendingPorts); } catch (error) { return error instanceof Error ? error.message : String(error); } return undefined; @@ -146,17 +143,26 @@ function normalizeHypiHubRequest( delete input.last_frame; if (typeof firstFrame === "string" && firstFrame.length > 0) input.first_frame = firstFrame; if (typeof lastFrame === "string" && lastFrame.length > 0) input.last_frame = lastFrame; - if (Array.isArray(imageRefs) && imageRefs.length > 0) input.reference_image_urls = imageRefs; + if (Array.isArray(imageRefs) && imageRefs.length > 0) input.reference_image_urls = referenceItems(imageRefs); if (Array.isArray(genericImageRefs) && genericImageRefs.length > 0) { const urls = genericImageRefs.map((item) => item !== null && typeof item === "object" ? (item as Record).url : item).filter((item): item is string => typeof item === "string" && item.length > 0); if (urls.length > 0) input.reference_image_urls = urls; } - if (Array.isArray(videoRefs) && videoRefs.length > 0) input.reference_videos = videoRefs; - if (Array.isArray(audioRefs) && audioRefs.length > 0) input.reference_audios = audioRefs; + if (Array.isArray(videoRefs) && videoRefs.length > 0) input.reference_videos = referenceItems(videoRefs); + if (Array.isArray(audioRefs) && audioRefs.length > 0) input.reference_audios = referenceItems(audioRefs); return { model: request.model, input: canonicalize(input) }; } +/** A reference with an offset is sent as `{ url, start_time }`; one with only a URL is sent as that URL. */ +function referenceItems(items: readonly unknown[]): readonly unknown[] { + return items.map((item) => { + if (item === null || typeof item !== "object") return item; + const object = item as Record; + return Object.keys(object).length === 1 && typeof object.url === "string" ? object.url : object; + }); +} + function capabilityKey(capability: { module: { name: string; version: string }; name: string }): string { return `${capability.module.name}@${capability.module.version}#${capability.name}`; }