Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: normalize HypiHub request shapes before submission

rpone5e1988836b68
diff --git a/packages/provider-hypihub/README.md b/packages/provider-hypihub/README.md
index 50c7349e..b243e719 100644
--- a/packages/provider-hypihub/README.md
+++ b/packages/provider-hypihub/README.md
@@ -5,10 +5,11 @@ paid generation and Gemini VLM requests; callers may keep their own Provider and
when its key is configured.
It maps the currently shipped image/video model capabilities to HypiHub, including image edits and
-image/video reference inputs, submits jobs, polls them, downloads the first-class assets and persists
-them in Hypit's configured ArtifactStore. References are sent as HypiHub-compatible `data:` URLs, so
-the adapter does not require a provider-specific public upload bucket. It also exports a small
-Gemini-native VLM generator for callers that previously used Vertex.
+image-to-video first-frame inputs, submits jobs, polls them, downloads the first-class assets and
+persists them in Hypit's configured ArtifactStore. Image references are sent as HypiHub-compatible
+`data:` URLs. Video-reference inputs require a public HTTPS URL and are rejected clearly when the
+configured ArtifactStore cannot provide one. It also exports a small Gemini-native VLM generator for
+callers that previously used Vertex.
Runtime Profile example:
diff --git a/packages/provider-hypihub/src/mapping.ts b/packages/provider-hypihub/src/mapping.ts
index 04434f44..55bfc64d 100644
--- a/packages/provider-hypihub/src/mapping.ts
+++ b/packages/provider-hypihub/src/mapping.ts
@@ -8,17 +8,16 @@ const NANO_BANANA: ModuleRef = { name: "@hypit/nano-banana", version: "1" };
const SEEDREAM: ModuleRef = { name: "@hypit/seedream", version: "1" };
const MINIMAX: ModuleRef = { name: "@hypit/minimax-h3", version: "1" };
const GROK: ModuleRef = { name: "@hypit/grok-imagine", version: "1" };
-const MIMO: ModuleRef = { name: "@hypit/mimo-tts", version: "1" };
const seedance = (name: string, model: string): GenerationWireMapping => ({
capability: { module: SEEDANCE, name }, result: "video", routes: [{ model }],
fields: {
prompt: { as: "value", field: "prompt" },
- referenceImage: { as: "urlArray", field: "reference_image_urls" },
- referenceVideo: { as: "urlArray", field: "reference_videos" },
+ referenceImage: { as: "urlArray", field: "reference_image_urls" },
+ referenceVideo: { as: "urlArray", field: "reference_videos" },
referenceAudio: { as: "urlArray", field: "reference_audios" },
- firstFrame: { as: "url", field: "first_image_url" },
- lastFrame: { as: "url", field: "last_image_url" },
+ firstFrame: { as: "url", field: "first_image_url" },
+ lastFrame: { as: "url", field: "last_image_url" },
resolution: { as: "value", field: "resolution" },
aspectRatio: { as: "value", field: "aspect_ratio" },
duration: { as: "value", field: "seconds" },
@@ -41,7 +40,7 @@ export const hypiHubMappings: readonly GenerationWireMapping[] = [
prompt: { as: "value", field: "prompt" },
aspectRatio: { as: "value", field: "aspect_ratio" },
resolution: { as: "value", field: "size", whenAbsent: "1024x1024" },
- images: { as: "urlArray", field: "images" },
+ images: { as: "itemObject", field: "reference_images", urlKey: "url", fieldKeys: {} },
},
},
...(["nano-banana-2", "nano-banana-pro"] as const).map((model) => ({
@@ -79,11 +78,11 @@ export const hypiHubMappings: readonly GenerationWireMapping[] = [
fields: {
prompt: { as: "value", field: "prompt" }, duration: { as: "value", field: "seconds" },
resolution: { as: "value", field: "resolution" }, aspectRatio: { as: "value", field: "aspect_ratio" },
- referenceImage: { as: "urlArray", field: "reference_image_urls" },
- referenceVideo: { as: "urlArray", field: "reference_videos" },
+ referenceImage: { as: "urlArray", field: "reference_image_urls" },
+ referenceVideo: { as: "urlArray", field: "reference_videos" },
referenceAudio: { as: "urlArray", field: "reference_audios" },
- firstFrame: { as: "url", field: "first_image_url" },
- lastFrame: { as: "url", field: "last_image_url" },
+ firstFrame: { as: "url", field: "first_image_url" },
+ lastFrame: { as: "url", field: "last_image_url" },
},
},
{
@@ -109,13 +108,6 @@ export const hypiHubMappings: readonly GenerationWireMapping[] = [
images: { as: "itemObject", field: "reference_images", urlKey: "url", fieldKeys: {} },
},
},
- {
- capability: { module: MIMO, name: "mimo-v2.5-tts" }, result: "audio", routes: [{ model: "mimo-v2.5-tts" }],
- fields: {
- text: { as: "value", field: "input" }, voice: { as: "value", field: "voice" },
- output: { as: "value", field: "output", whenAbsent: "binary" },
- },
- },
];
function capabilityKey(ref: CapabilityRef): string {
diff --git a/packages/provider-hypihub/src/routes.ts b/packages/provider-hypihub/src/routes.ts
index d72c52cc..ace8076f 100644
--- a/packages/provider-hypihub/src/routes.ts
+++ b/packages/provider-hypihub/src/routes.ts
@@ -5,7 +5,7 @@ import {
sealGeneratedImageSet,
sealGeneratedVideoSet,
} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest } from "@hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
import { canonicalize } from "@hypit/protocol";
import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
import { hypiHubMappings } from "./mapping.js";
@@ -24,7 +24,10 @@ export const hypiHubRoutes: readonly HypiHubRoute[] = hypiHubMappings.map((mappi
returns: mapping.result === "image" ? generationTypes.imageSet
: mapping.result === "video" ? generationTypes.videoSet : generationTypes.audioSet,
media: mapping.result,
- compile: (constraints, resolve) => compileWireRequest(mapping, constraints as unknown as GenerationRequest, resolve),
+ compile: async (constraints, resolve) => normalizeHypiHubRequest(
+ mapping,
+ await compileWireRequest(mapping, constraints as unknown as GenerationRequest, resolve),
+ ),
packageResult: (artifacts) => ({
kind: "inline",
value: canonicalize(mapping.result === "image"
@@ -35,6 +38,57 @@ export const hypiHubRoutes: readonly HypiHubRoute[] = hypiHubMappings.map((mappi
}),
}));
+/** Convert the provider-neutral generation wire shape to HypiHub's public API shape. */
+function normalizeHypiHubRequest(
+ mapping: GenerationWireMapping,
+ request: { readonly model: string; readonly input: CanonicalValue },
+): { readonly model: string; readonly input: CanonicalValue } {
+ const input = { ...(request.input as Record<string, unknown>) };
+ if (mapping.result === "image") {
+ const resolution = input.size;
+ if (resolution === "1K") input.size = "1024x1024";
+ else if (resolution === "2K") input.size = "2048x2048";
+ else if (resolution === "4K") input.size = "3840x2160";
+ return { model: request.model, input: canonicalize(input) };
+ }
+
+ if (typeof input.resolution === "string") input.resolution = input.resolution.toLowerCase();
+
+ const imageRefs = input.reference_image_urls;
+ const genericImageRefs = input.reference_images;
+ const videoRefs = input.reference_videos;
+ const firstFrame = input.first_image_url;
+ const lastFrame = input.last_image_url;
+ const audioRefs = input.reference_audios;
+ const sourceTaskId = input.source_task_id;
+ if (Array.isArray(audioRefs) && audioRefs.length > 0) {
+ throw new Error("HypiHub unified video API does not support reference audio inputs");
+ }
+ if (Array.isArray(videoRefs) && videoRefs.length > 0) {
+ throw new Error("HypiHub video reference inputs require a public HTTPS URL; the Runtime ArtifactStore cannot expose one");
+ }
+ if (typeof sourceTaskId === "string" && sourceTaskId.length > 0) {
+ throw new Error("HypiHub unified video API does not support video continuation sourceTaskId");
+ }
+ delete input.reference_image_urls;
+ delete input.reference_images;
+ delete input.reference_videos;
+ delete input.reference_audios;
+ delete input.first_image_url;
+ delete input.last_image_url;
+ delete input.source_task_id;
+ if (typeof firstFrame === "string" && firstFrame.length > 0) input.input_reference = firstFrame;
+ else if (Array.isArray(imageRefs) && imageRefs.length > 0) input.input_reference = imageRefs[0];
+ else if (Array.isArray(genericImageRefs) && genericImageRefs.length > 0) {
+ const first = genericImageRefs[0];
+ if (first !== null && typeof first === "object" && typeof (first as Record<string, unknown>).url === "string") {
+ input.input_reference = (first as Record<string, unknown>).url;
+ }
+ }
+ if (typeof lastFrame === "string" && lastFrame.length > 0) input.last_frame = lastFrame;
+ return { model: request.model, input: canonicalize(input) };
+}
+
function capabilityKey(capability: { module: { name: string; version: string }; name: string }): string {
return `${capability.module.name}@${capability.module.version}#${capability.name}`;
}
diff --git a/packages/provider-hypihub/test/routes.test.ts b/packages/provider-hypihub/test/routes.test.ts
new file mode 100644
index 00000000..90392cb1
--- /dev/null
+++ b/packages/provider-hypihub/test/routes.test.ts
@@ -0,0 +1,63 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { hypiHubRoutes } from "../src/routes.js";
+
+const image = {
+ kind: "blob" as const,
+ digest: `sha256:${"1".repeat(64)}`,
+ size: 3,
+ mediaType: "image/png",
+};
+
+const resolve = async () => "data:image/png;base64,AQID";
+
+test("HypiHub GPT image requests use canonical edit references and size dimensions", async () => {
+ const route = hypiHubRoutes.find((item) => item.capability.name === "gpt-image-2");
+ assert.ok(route);
+ const result = await route.compile({
+ ports: {
+ prompt: ["edit"],
+ aspectRatio: ["1:1"],
+ resolution: ["1K"],
+ images: [{ role: "image", artifact: image }],
+ },
+ }, resolve);
+ assert.equal(result.model, "gpt-image-2-image-to-image");
+ assert.deepEqual(result.input, {
+ prompt: "edit",
+ aspect_ratio: "1:1",
+ size: "1024x1024",
+ reference_images: [{ url: "data:image/png;base64,AQID" }],
+ });
+});
+
+test("HypiHub image-to-video requests use input_reference", async () => {
+ const route = hypiHubRoutes.find((item) => item.capability.name === "minimax-h3");
+ assert.ok(route);
+ const result = await route.compile({
+ ports: {
+ prompt: ["animate"],
+ duration: [5],
+ firstFrame: [{ role: "image", artifact: image }],
+ },
+ }, resolve);
+ assert.equal(result.model, "minimax-h3/image-to-video");
+ assert.deepEqual(result.input, {
+ prompt: "animate",
+ seconds: 5,
+ input_reference: "data:image/png;base64,AQID",
+ });
+});
+
+test("HypiHub rejects reference video/audio that cannot be represented by its public API", async () => {
+ const route = hypiHubRoutes.find((item) => item.capability.name === "minimax-h3");
+ assert.ok(route);
+ await assert.rejects(() => route.compile({
+ ports: {
+ prompt: ["animate"],
+ duration: [5],
+ referenceAudio: [{ role: "audio", artifact: { ...image, mediaType: "audio/wav" } }],
+ },
+ }, resolve), /does not support reference audio/);
+});