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.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
feat: route Gemini VLM through HypiHub
rpone22b2d57b2a61
diff --git a/packages/provider-hypihub/src/gemini.ts b/packages/provider-hypihub/src/gemini.tsnew file mode 100644index 00000000..f8fbe78d--- /dev/null+++ b/packages/provider-hypihub/src/gemini.ts@@ -0,0 +1,69 @@+export type HypiHubGeminiPart =+ | { readonly text: string }+ | { readonly inlineData: { readonly mimeType: string; readonly data: string } };++export type HypiHubGeminiGeneratorOptions = {+ readonly apiKey: string;+ readonly model?: string;+ readonly baseUrl?: string;+ readonly requestTimeoutMs?: number;+ readonly fetch?: typeof globalThis.fetch;+};++export type HypiHubGeminiGenerateInput = {+ readonly parts: readonly HypiHubGeminiPart[];+ readonly instruction: string;+};++function assert(condition: unknown, message: string): asserts condition {+ if (!condition) throw new Error(message);+}++function partValue(part: HypiHubGeminiPart): Record<string, unknown> {+ if ("text" in part) return { text: part.text };+ if ("inlineData" in part) {+ assert(typeof part.inlineData.mimeType === "string" && typeof part.inlineData.data === "string",+ "HypiHub Gemini inline media part is incomplete");+ return { inlineData: { mimeType: part.inlineData.mimeType, data: part.inlineData.data } };+ }+ throw new Error("HypiHub Gemini only supports text and inline media parts");+}++/** Create a small native-Gemini generator for callers that previously used Vertex. */+export function createHypiHubGeminiGenerator(options: HypiHubGeminiGeneratorOptions) {+ const apiKey = options.apiKey.trim();+ assert(apiKey.length > 0, "HypiHub API key is empty");+ const baseUrl = (options.baseUrl ?? "https://hypit.ai").replace(/\/$/u, "");+ const model = options.model?.trim() || "gemini-3.1-pro-preview";+ const timeout = options.requestTimeoutMs ?? 120_000;+ const fetcher = options.fetch ?? globalThis.fetch;++ return async (input: HypiHubGeminiGenerateInput): Promise<string> => {+ const controller = new AbortController();+ const timer = setTimeout(() => controller.abort(), timeout);+ try {+ const response = await fetcher(`${baseUrl}/v1beta/models/${encodeURIComponent(model)}:generateContent`, {+ method: "POST",+ signal: controller.signal,+ headers: { "x-goog-api-key": apiKey, "content-type": "application/json" },+ body: JSON.stringify({+ systemInstruction: { parts: [{ text: input.instruction }] },+ contents: [{ role: "user", parts: input.parts.map(partValue) }],+ generationConfig: { temperature: 1, responseMimeType: "text/plain" },+ }),+ });+ const text = await response.text();+ if (!response.ok) throw new Error(`HypiHub Gemini returned HTTP ${response.status}: ${text.slice(0, 300)}`);+ let body: unknown;+ try { body = JSON.parse(text); } catch { throw new Error("HypiHub Gemini returned invalid JSON"); }+ const candidates = (body as { readonly candidates?: readonly { readonly content?: { readonly parts?: readonly { readonly text?: unknown }[] } }[] }).candidates;+ const output = candidates?.flatMap((candidate) => candidate.content?.parts ?? [])+ .map((part) => typeof part.text === "string" ? part.text : "")+ .join("").trim() ?? "";+ assert(output.length > 0, "HypiHub Gemini returned an empty response");+ return output;+ } finally {+ clearTimeout(timer);+ }+ };+}diff --git a/packages/provider-hypihub/src/index.ts b/packages/provider-hypihub/src/index.tsindex 7a2d86aa..1e853459 100644--- a/packages/provider-hypihub/src/index.ts+++ b/packages/provider-hypihub/src/index.ts@@ -1,2 +1,4 @@export { createHypiHubProvider, hypiHubProviderModuleRef } from "./provider.js";export type { CreateHypiHubProviderOptions } from "./provider.js";+export { createHypiHubGeminiGenerator } from "./gemini.js";+export type { HypiHubGeminiGenerateInput, HypiHubGeminiGeneratorOptions, HypiHubGeminiPart } from "./gemini.js";diff --git a/packages/reference-video-tools/package.json b/packages/reference-video-tools/package.jsonindex 45b59c99..cfec7525 100644--- a/packages/reference-video-tools/package.json+++ b/packages/reference-video-tools/package.json@@ -28,6 +28,7 @@"@hypit/run-markup": "workspace:*","@hypit/provider-whisperx-local": "workspace:*","@hypit/provider-media-local": "workspace:*",+ "@hypit/provider-hypihub": "workspace:*","@hypit/script": "workspace:*","@hypit/speech": "workspace:*","@hypit/speech-evidence": "workspace:*",diff --git a/packages/reference-video-tools/src/tools.ts b/packages/reference-video-tools/src/tools.tsindex 14b253a2..83e2cd30 100644--- a/packages/reference-video-tools/src/tools.ts+++ b/packages/reference-video-tools/src/tools.ts@@ -21,6 +21,7 @@ import { VISUAL_STYLE_ENUM_VALUES_V1, VISUAL_STYLE_NAMES_V1 } from "@hypit/visuaimport { describeSchema } from "./contract.js";import { videoCliDistribution } from "@hypit/video-cli";+import { createHypiHubGeminiGenerator } from "@hypit/provider-hypihub";import { authorSource, invokedFrom, nearestPackageRoot, referenceRoot, referenceWords, renderElement, renderPreviews, spokenRange, standInSidecarPath, tokenWindow } from "./authoring.js";import type { RenderElementInput, RenderPreviewsInput, SpokenRange, StandInFocus, StandInSidecar } from "./authoring.js";@@ -788,6 +789,18 @@ function positiveInt(value: number, label: string): number {}async function defaultGenerate(model: string): Promise<GenerateText> {+ const hypiHubKey = process.env.HYPIHUB_API_KEY?.trim();+ if (hypiHubKey) {+ const generate = createHypiHubGeminiGenerator({+ apiKey: hypiHubKey,+ model,+ baseUrl: process.env.HYPIHUB_BASE_URL?.trim() || "https://hypit.ai",+ });+ return async ({ parts, instruction }) => await generate({+ parts: parts as unknown as Parameters<typeof generate>[0]["parts"],+ instruction,+ });+ }const project = process.env.GOOGLE_CLOUD_PROJECT?.trim();const credentials = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON?.trim();assert(project, "GOOGLE_CLOUD_PROJECT is required");diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d0922184..e6e3b0d6 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2321,6 +2321,9 @@ importers:'@hypit/protocol':specifier: workspace:*version: link:../protocol+ '@hypit/provider-hypihub':+ specifier: workspace:*+ version: link:../provider-hypihub'@hypit/provider-media-local':specifier: workspace:*version: link:../provider-media-local