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
refactor: decouple HypiHub routes and wire mapping
rpone1f59ff8e6be6
diff --git a/packages/provider-hypihub/README.md b/packages/provider-hypihub/README.mdindex 870a6d7c..a271da42 100644--- a/packages/provider-hypihub/README.md+++ b/packages/provider-hypihub/README.md@@ -16,7 +16,7 @@ Runtime Profile example:"use": "@hypit/provider-hypihub","pool": "hypihub.default","config": {- "baseUrl": "https://apihub.hypit.ai/v1",+ "baseUrl": "https://hypit.ai/v1","apiKey": { "store": "env", "key": "HYPIHUB_API_KEY" },"defaultConcurrency": 4}diff --git a/packages/provider-hypihub/src/mapping.ts b/packages/provider-hypihub/src/mapping.tsnew file mode 100644index 00000000..f82c5af7--- /dev/null+++ b/packages/provider-hypihub/src/mapping.ts@@ -0,0 +1,90 @@+import type { CapabilityRef, ModuleRef } from "@hypit/protocol";+import type { GenerationWireMapping } from "@hypit/generation";++/** HypiHub model IDs and the normalized request fields they accept. */+const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };+const GPT_IMAGE: ModuleRef = { name: "@hypit/gpt-image", version: "1" };+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" },+ resolution: { as: "value", field: "resolution" },+ aspectRatio: { as: "value", field: "aspect_ratio" },+ duration: { as: "value", field: "seconds" },+ },+});++export const hypiHubMappings: readonly GenerationWireMapping[] = [+ seedance("seedance-2", "bytedance/seedance-2"),+ seedance("seedance-2-fast", "bytedance/seedance-2-fast"),+ seedance("seedance-2-mini", "bytedance/seedance-2-mini"),+ seedance("seedance-2.5", "bytedance/seedance-2-5"),+ {+ capability: { module: GPT_IMAGE, name: "gpt-image-2" }, result: "image", routes: [{ model: "gpt-image-2-text-to-image" }],+ fields: {+ prompt: { as: "value", field: "prompt" },+ aspectRatio: { as: "value", field: "aspect_ratio" },+ resolution: { as: "value", field: "size", whenAbsent: "1024x1024" },+ },+ },+ ...(["nano-banana-2", "nano-banana-pro"] as const).map((model) => ({+ capability: { module: NANO_BANANA, name: model }, result: "image" as const, routes: [{ model }],+ fields: {+ prompt: { as: "value" as const, field: "prompt" },+ aspectRatio: { as: "value" as const, field: "aspect_ratio" },+ resolution: { as: "value" as const, field: "size", whenAbsent: "1024x1024" },+ },+ })),+ {+ capability: { module: SEEDREAM, name: "seedream-5-lite" }, result: "image", routes: [{ model: "seedream/5-lite-text-to-image" }],+ fields: {+ prompt: { as: "value", field: "prompt" },+ aspectRatio: { as: "value", field: "aspect_ratio" },+ resolution: { as: "value", field: "size", whenAbsent: "2048x2048" },+ },+ },+ {+ capability: { module: MINIMAX, name: "minimax-h3" }, result: "video", routes: [{ model: "minimax-h3/text-to-video" }],+ fields: {+ prompt: { as: "value", field: "prompt" }, duration: { as: "value", field: "seconds" },+ resolution: { as: "value", field: "resolution" }, aspectRatio: { as: "value", field: "aspect_ratio" },+ },+ },+ {+ capability: { module: GROK, name: "grok-imagine-video" }, result: "video", routes: [{ model: "grok-imagine/text-to-video" }],+ fields: {+ prompt: { as: "value", field: "prompt" }, duration: { as: "value", field: "seconds" },+ resolution: { as: "value", field: "resolution" }, aspectRatio: { as: "value", field: "aspect_ratio" },+ },+ },+ {+ capability: { module: GROK, name: "grok-imagine-video-1.5-preview" }, result: "video", routes: [{ model: "grok-imagine/text-to-video" }],+ fields: {+ prompt: { as: "value", field: "prompt" }, duration: { as: "value", field: "seconds" },+ resolution: { as: "value", field: "resolution" }, aspectRatio: { as: "value", field: "aspect_ratio" },+ },+ },+ {+ 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 {+ return `${ref.module.name}@${ref.module.version}#${ref.name}`;+}++const byCapability = new Map(hypiHubMappings.map((mapping) => [capabilityKey(mapping.capability), mapping]));++export function hypiHubMappingForCapability(capability: CapabilityRef): GenerationWireMapping | undefined {+ return byCapability.get(capabilityKey(capability));+}diff --git a/packages/provider-hypihub/src/provider.ts b/packages/provider-hypihub/src/provider.tsindex 6c4a144f..d4b90450 100644--- a/packages/provider-hypihub/src/provider.ts+++ b/packages/provider-hypihub/src/provider.ts@@ -1,38 +1,13 @@-import type { AsyncEndpoint, EndpointInvocationContext, EndpointPollContext, EndpointStartContext, EndpointOutcome } from "@hypit/endpoint-kit";+import type { AsyncEndpoint, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";import { defineEndpointPackage, wakeAfter } from "@hypit/endpoint-kit";-import { generationTypes, sealGeneratedAudioSet, sealGeneratedImageSet, sealGeneratedVideoSet } from "@hypit/generation";-import type { GenerationRequest } from "@hypit/generation";import { canonicalize } from "@hypit/protocol";-import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/protocol";+import type { BlobRef, CapabilityRef } from "@hypit/protocol";import { credentialRef } from "@hypit/runtime";-import type { CredentialRef } from "@hypit/runtime";+import type { CredentialRef, ArtifactStore } from "@hypit/runtime";+import { hypiHubRouteForCapability, hypiHubRoutes } from "./routes.js";export const hypiHubProviderModuleRef = { name: "@hypit/provider-hypihub", version: "1" } as const;-type Kind = "image" | "video" | "audio";-type Route = { capability: CapabilityRef; model: string; kind: Kind };--const routes: readonly Route[] = [- { capability: { module: { name: "@hypit/seedance", version: "1" }, name: "seedance-2" }, model: "bytedance/seedance-2", kind: "video" },- { capability: { module: { name: "@hypit/seedance", version: "1" }, name: "seedance-2-fast" }, model: "bytedance/seedance-2-fast", kind: "video" },- { capability: { module: { name: "@hypit/seedance", version: "1" }, name: "seedance-2-mini" }, model: "bytedance/seedance-2-mini", kind: "video" },- { capability: { module: { name: "@hypit/seedance", version: "1" }, name: "seedance-2.5" }, model: "bytedance/seedance-2-5", kind: "video" },- { capability: { module: { name: "@hypit/gpt-image", version: "1" }, name: "gpt-image-2" }, model: "gpt-image-2", kind: "image" },- { capability: { module: { name: "@hypit/nano-banana", version: "1" }, name: "nano-banana-2" }, model: "nano-banana-2", kind: "image" },- { capability: { module: { name: "@hypit/nano-banana", version: "1" }, name: "nano-banana-pro" }, model: "nano-banana-pro", kind: "image" },- { capability: { module: { name: "@hypit/seedream", version: "1" }, name: "seedream-5-lite" }, model: "seedream/5-lite-text-to-image", kind: "image" },- { capability: { module: { name: "@hypit/minimax-h3", version: "1" }, name: "minimax-h3" }, model: "minimax-h3/text-to-video", kind: "video" },- { capability: { module: { name: "@hypit/grok-imagine", version: "1" }, name: "grok-imagine-video" }, model: "grok-imagine/text-to-video", kind: "video" },- { capability: { module: { name: "@hypit/grok-imagine", version: "1" }, name: "grok-imagine-video-1.5-preview" }, model: "grok-imagine-video-1-5-preview", kind: "video" },- { capability: { module: { name: "@hypit/mimo-tts", version: "1" }, name: "mimo-v2.5-tts" }, model: "mimo-v2.5-tts", kind: "audio" },-];--function key(capability: CapabilityRef): string {- return `${capability.module.name}@${capability.module.version}#${capability.name}`;-}--const routeMap = new Map(routes.map((route) => [key(route.capability), route]));-export type CreateHypiHubProviderOptions = {readonly instance?: string;readonly pool?: string;@@ -44,193 +19,112 @@ export type CreateHypiHubProviderOptions = {readonly fetch?: typeof globalThis.fetch;};-type Handle = { contract: "hypit.hypihub-operation@1"; jobId: string; route: string; startedAt: number };+type Handle = { readonly contract: "hypit.hypihub-operation@1"; readonly jobId: string; readonly route: string; readonly startedAt: number };function assert(condition: unknown, message: string): asserts condition { if (!condition) throw new Error(message); }function object(value: unknown, subject: string): Record<string, unknown> {assert(value !== null && typeof value === "object" && !Array.isArray(value), `${subject} must be an object`);return value as Record<string, unknown>;}-function scalar(request: GenerationRequest, name: string): unknown {- const value = request.ports[name];- return value === undefined ? undefined : value[0];+function capabilityKey(capability: CapabilityRef): string { return `${capability.module.name}@${capability.module.version}#${capability.name}`; }+function credential(context: EndpointInvocationContext): string {+ const value = context.credentials.apiKey?.secret;+ assert(typeof value === "string" && value.length > 0, "HypiHub API key is unavailable");+ return value;}-function requestFor(route: Route, value: CanonicalValue): Record<string, unknown> {- const request = value as unknown as GenerationRequest;- assert(request.ports !== null && typeof request.ports === "object", "HypiHub request has no ports");- for (const [name, values] of Object.entries(request.ports)) {- if (values.some((item) => item !== undefined && typeof item === "object")) {- throw new Error(`HypiHub Provider does not support reference media yet (${name})`);- }- }- const prompt = scalar(request, "prompt");- if (route.kind === "audio") {- const text = scalar(request, "text");- const voice = scalar(request, "voice");- assert(typeof text === "string" && typeof voice === "string", "HypiHub TTS request requires text and voice");- return { model: route.model, input: text, voice, output: "binary" };- }- assert(typeof prompt === "string", "HypiHub request requires prompt");- if (route.kind === "image") {- const resolution = scalar(request, "resolution");- const aspect = scalar(request, "aspectRatio");- const size = typeof resolution === "string" && resolution.toUpperCase() === "2K" ? "2048x2048"- : typeof resolution === "string" && resolution.toUpperCase() === "4K" ? "4096x4096" : "1024x1024";- return { model: route.model, prompt, ...(aspect === undefined ? {} : { aspect_ratio: aspect }), size, n: 1 };- }- const duration = scalar(request, "duration");- const resolution = scalar(request, "resolution");- const aspect = scalar(request, "aspectRatio");- assert(typeof duration === "number", "HypiHub video request requires duration");- return {- model: route.model,- prompt,- seconds: duration,- ...(resolution === undefined ? {} : { resolution }),- ...(aspect === undefined ? {} : { aspect_ratio: aspect }),- };+function failure(error: unknown): EndpointOutcome {+ return { status: "failed", failure: { code: "HYPIHUB_ERROR", message: error instanceof Error ? error.message : String(error) } };+}+function jobId(value: Record<string, unknown>): string {+ const id = value.id ?? value.job_id;+ assert(typeof id === "string" && id.length > 0, "HypiHub response has no job id");+ return id;}-class Client {+class HypiHubClient {readonly baseUrl: string;readonly timeout: number;readonly fetcher: typeof globalThis.fetch;- constructor(options: { baseUrl: string; timeout: number; fetcher: typeof globalThis.fetch }) {+ constructor(options: { readonly baseUrl: string; readonly timeout: number; readonly fetcher: typeof globalThis.fetch }) {this.baseUrl = options.baseUrl.replace(/\/$/u, ""); this.timeout = options.timeout; this.fetcher = options.fetcher;}async json(path: string, apiKey: string, init: RequestInit = {}): Promise<Record<string, unknown>> {- const controller = new AbortController();- const timer = setTimeout(() => controller.abort(), this.timeout);+ const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), this.timeout);try {- const response = await this.fetcher(`${this.baseUrl}${path}`, {- ...init,- signal: controller.signal,- headers: { authorization: `Bearer ${apiKey}`, ...(init.headers ?? {}) },- });- const text = await response.text();- let body: unknown = {};+ const response = await this.fetcher(`${this.baseUrl}${path}`, { ...init, signal: controller.signal, headers: { authorization: `Bearer ${apiKey}`, ...(init.headers ?? {}) } });+ const text = await response.text(); let body: unknown = {};try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new Error(`HypiHub returned invalid JSON (${response.status})`); }if (!response.ok) throw new Error(`HypiHub returned HTTP ${response.status}: ${text.slice(0, 300)}`);return object(body, "HypiHub response");} finally { clearTimeout(timer); }}- async download(url: string): Promise<{ bytes: Uint8Array; mediaType: string }> {- const response = await this.fetcher(url);- if (!response.ok) throw new Error(`HypiHub asset returned HTTP ${response.status}`);- const mediaType = response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream";- return { bytes: new Uint8Array(await response.arrayBuffer()), mediaType };+ async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {+ const response = await this.fetcher(url); if (!response.ok) throw new Error(`HypiHub asset returned HTTP ${response.status}`);+ return { bytes: new Uint8Array(await response.arrayBuffer()), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };}- async binary(path: string, apiKey: string, body: Record<string, unknown>): Promise<{ bytes: Uint8Array; mediaType: string }> {- const controller = new AbortController();- const timer = setTimeout(() => controller.abort(), this.timeout);- try {- const response = await this.fetcher(`${this.baseUrl}${path}`, {- method: "POST",- signal: controller.signal,- headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },- body: JSON.stringify(body),- });- if (!response.ok) throw new Error(`HypiHub returned HTTP ${response.status}: ${(await response.text()).slice(0, 300)}`);- return {- bytes: new Uint8Array(await response.arrayBuffer()),- mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "audio/wav",- };- } finally { clearTimeout(timer); }+ async binary(path: string, apiKey: string, body: Record<string, unknown>): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {+ const response = await this.fetcher(`${this.baseUrl}${path}`, { method: "POST", headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" }, body: JSON.stringify(body) });+ if (!response.ok) throw new Error(`HypiHub returned HTTP ${response.status}: ${(await response.text()).slice(0, 300)}`);+ return { bytes: new Uint8Array(await response.arrayBuffer()), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "audio/wav" };}}-function failure(error: unknown): EndpointOutcome {- return { status: "failed", failure: { code: "HYPIHUB_ERROR", message: error instanceof Error ? error.message : String(error) } };+async function complete(client: HypiHubClient, apiKey: string, route: (typeof hypiHubRoutes)[number], id: string, artifacts: ArtifactStore): Promise<EndpointOutcome> {+ const response = await client.json(`/jobs/${encodeURIComponent(id)}/assets`, apiKey); const items = response.items;+ assert(Array.isArray(items) && items.length > 0, "HypiHub job has no assets"); const blobs: BlobRef[] = [];+ for (const item of items) { const asset = object(item, "HypiHub asset"); assert(typeof asset.url === "string", "HypiHub asset has no URL"); const downloaded = await client.download(asset.url); blobs.push(await artifacts.put(downloaded.bytes, downloaded.mediaType)); }+ return { status: "completed", result: { value: route.packageResult(blobs) } };}-function credential(context: EndpointInvocationContext): string {- const value = context.credentials.apiKey?.secret;- assert(typeof value === "string" && value.length > 0, "HypiHub API key is unavailable");- return value;-}--function jobId(value: Record<string, unknown>): string {- const id = value.id ?? value.job_id;- assert(typeof id === "string" && id.length > 0, "HypiHub response has no job id");- return id;-}--async function complete(client: Client, apiKey: string, route: Route, job: Record<string, unknown>, artifacts: EndpointInvocationContext["artifacts"]): Promise<EndpointOutcome> {- const assetsResponse = await client.json(`/jobs/${encodeURIComponent(jobId(job))}/assets`, apiKey);- const items = assetsResponse.items;- assert(Array.isArray(items) && items.length > 0, "HypiHub job has no assets");- const blobs: BlobRef[] = [];- for (const item of items) {- const asset = object(item, "HypiHub asset");- assert(typeof asset.url === "string", "HypiHub asset has no URL");- const downloaded = await client.download(asset.url);- blobs.push(await artifacts.put(downloaded.bytes, downloaded.mediaType));- }- const value = route.kind === "image"- ? sealGeneratedImageSet({ images: blobs.filter((blob) => blob.mediaType.startsWith("image/")) })- : sealGeneratedVideoSet({ videos: blobs.filter((blob) => blob.mediaType.startsWith("video/")) });- return { status: "completed", result: { value: { kind: "inline", value: canonicalize(value) } } };+async function synthesizeAudio(client: HypiHubClient, context: EndpointInvocationContext): Promise<EndpointFulfillment> {+ const route = hypiHubRouteForCapability(context.need.capability);+ assert(route !== undefined && route.media === "audio", "HypiHub does not implement this exact capability");+ const compiled = await route.compile(context.need.constraints, async () => {+ throw new Error("HypiHub reference media is not supported yet");+ });+ const audio = await client.binary("/audio/speech", credential(context), { model: compiled.model, ...(compiled.input as Record<string, unknown>) });+ const artifact = await context.artifacts.put(audio.bytes, audio.mediaType);+ return { value: route.packageResult([artifact]) };}-function endpoint(client: Client, pollIntervalMs: number, maxOperationMs: number): AsyncEndpoint {+function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs: number): AsyncEndpoint {return {async start(context: EndpointStartContext) {try {- const route = routeMap.get(key(context.need.capability));- assert(route !== undefined, "HypiHub does not implement this exact capability");- const apiKey = credential(context);- if (route.kind === "audio") {- const audio = await client.binary("/audio/speech", apiKey, requestFor(route, context.need.constraints));- const artifact = await context.artifacts.put(audio.bytes, audio.mediaType);- return { status: "completed", result: { value: { kind: "inline", value: canonicalize(sealGeneratedAudioSet({ audios: [artifact] })) } } };- }- const response = await client.json(`/${route.kind === "image" ? "images/generations" : "videos"}`, apiKey, {- method: "POST",- headers: { "content-type": "application/json", "idempotency-key": context.operation },- body: JSON.stringify(requestFor(route, context.need.constraints)),- });- const status = response.status;- if (status === "succeeded" || status === "completed") return await complete(client, apiKey, route, response, context.artifacts);- const handle: Handle = { contract: "hypit.hypihub-operation@1", jobId: jobId(response), route: key(route.capability), startedAt: Date.now() };+ const route = hypiHubRouteForCapability(context.need.capability);+ assert(route !== undefined, "HypiHub does not implement this exact capability"); const apiKey = credential(context);+ const compiled = await route.compile(context.need.constraints, async () => { throw new Error("HypiHub reference media is not supported yet"); });+ assert(route.media !== "audio", "HypiHub audio capabilities use an immediate endpoint");+ const response = await client.json(route.media === "image" ? "/images/generations" : "/videos", apiKey, { method: "POST", headers: { "content-type": "application/json", "idempotency-key": context.operation }, body: JSON.stringify({ model: compiled.model, ...(compiled.input as Record<string, unknown>) }) });+ const status = response.status; if (status === "succeeded" || status === "completed") return await complete(client, apiKey, route, jobId(response), context.artifacts);+ const handle: Handle = { contract: "hypit.hypihub-operation@1", jobId: jobId(response), route: capabilityKey(route.capability), startedAt: Date.now() };return wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "submitted" });} catch (error) { return failure(error); }},async poll(context: EndpointPollContext) {try {- const handle = object(context.handle, "HypiHub handle") as unknown as Handle;- const route = routeMap.get(key(context.need.capability));- assert(route !== undefined && handle.contract === "hypit.hypihub-operation@1" && handle.route === key(route.capability), "HypiHub handle is invalid");+ const handle = object(context.handle, "HypiHub handle") as unknown as Handle; const route = hypiHubRouteForCapability(context.need.capability);+ assert(route !== undefined && handle.contract === "hypit.hypihub-operation@1" && handle.route === capabilityKey(route.capability), "HypiHub handle is invalid");if (Date.now() - handle.startedAt > maxOperationMs) throw new Error("HypiHub operation timed out");- const apiKey = credential(context);- const job = await client.json(`/jobs/${encodeURIComponent(handle.jobId)}`, apiKey);- const status = job.status;+ const job = await client.json(`/jobs/${encodeURIComponent(handle.jobId)}`, credential(context)); const status = job.status;if (status === "queued" || status === "running" || status === "in_progress") return wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: String(status) });if (status === "failed" || status === "queue_expired") throw new Error(`HypiHub job ${status}`);if (status !== "succeeded" && status !== "completed") throw new Error(`HypiHub returned unknown job status ${String(status)}`);- return await complete(client, apiKey, route, { ...job, id: handle.jobId }, context.artifacts);+ return await complete(client, credential(context), route, handle.jobId, context.artifacts);} catch (error) { return failure(error); }},};}export function createHypiHubProvider(options: CreateHypiHubProviderOptions = {}) {- const baseUrl = options.baseUrl ?? "https://apihub.hypit.ai/v1";- const client = new Client({ baseUrl, timeout: options.requestTimeoutMs ?? 30_000, fetcher: options.fetch ?? globalThis.fetch });+ const client = new HypiHubClient({ baseUrl: options.baseUrl ?? "https://hypit.ai/v1", timeout: options.requestTimeoutMs ?? 30_000, fetcher: options.fetch ?? globalThis.fetch });const asyncEndpoint = endpoint(client, options.pollIntervalMs ?? 5_000, 20 * 60_000);+ const audioEndpoint: ImmediateEndpointHandler = (context) => synthesizeAudio(client, context);return defineEndpointPackage({- module: hypiHubProviderModuleRef,- facet: "gateway",- instance: options.instance ?? "hypihub.default",- pool: options.pool ?? options.instance ?? "hypihub.default",- credentials: { apiKey: options.apiKey ?? credentialRef("env", "HYPIHUB_API_KEY") },- credentialInputs: { apiKey: { label: "HypiHub API key" } },- defaultConcurrency: options.defaultConcurrency ?? 4,- capabilities: routes.map((route) => ({- capability: route.capability,- returns: route.kind === "image" ? generationTypes.imageSet : route.kind === "video" ? generationTypes.videoSet : generationTypes.audioSet,- lifecycle: "asynchronous" as const,- endpoint: asyncEndpoint,- lane: route.capability.name,- })),+ module: hypiHubProviderModuleRef, facet: "gateway", instance: options.instance ?? "hypihub.default", pool: options.pool ?? options.instance ?? "hypihub.default",+ credentials: { apiKey: options.apiKey ?? credentialRef("env", "HYPIHUB_API_KEY") }, credentialInputs: { apiKey: { label: "HypiHub API key" } }, defaultConcurrency: options.defaultConcurrency ?? 4,+ capabilities: hypiHubRoutes.map((route) => route.media === "audio"+ ? { capability: route.capability, returns: route.returns, lifecycle: "immediate" as const, handler: audioEndpoint, lane: route.capability.name }+ : { capability: route.capability, returns: route.returns, lifecycle: "asynchronous" as const, endpoint: asyncEndpoint, lane: route.capability.name }),});}diff --git a/packages/provider-hypihub/src/routes.ts b/packages/provider-hypihub/src/routes.tsnew file mode 100644index 00000000..d72c52cc--- /dev/null+++ b/packages/provider-hypihub/src/routes.ts@@ -0,0 +1,46 @@+import {+ compileWireRequest,+ generationTypes,+ sealGeneratedAudioSet,+ sealGeneratedImageSet,+ sealGeneratedVideoSet,+} from "@hypit/generation";+import type { GenerationArtifactUrlResolver, GenerationRequest } from "@hypit/generation";+import { canonicalize } from "@hypit/protocol";+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";+import { hypiHubMappings } from "./mapping.js";++export type HypiHubRoute = (typeof hypiHubMappings)[number] & {+ readonly key: string;+ readonly returns: TypeRef;+ readonly media: "image" | "video" | "audio";+ readonly compile: (constraints: CanonicalValue, resolve: GenerationArtifactUrlResolver) => Promise<{ readonly model: string; readonly input: CanonicalValue }>;+ readonly packageResult: (artifacts: readonly BlobRef[]) => StoredValue;+};++export const hypiHubRoutes: readonly HypiHubRoute[] = hypiHubMappings.map((mapping) => ({+ ...mapping,+ key: capabilityKey(mapping.capability),+ 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),+ packageResult: (artifacts) => ({+ kind: "inline",+ value: canonicalize(mapping.result === "image"+ ? sealGeneratedImageSet({ images: artifacts })+ : mapping.result === "video"+ ? sealGeneratedVideoSet({ videos: artifacts })+ : sealGeneratedAudioSet({ audios: artifacts })),+ }),+}));++function capabilityKey(capability: { module: { name: string; version: string }; name: string }): string {+ return `${capability.module.name}@${capability.module.version}#${capability.name}`;+}++const byCapability = new Map(hypiHubRoutes.map((route) => [capabilityKey(route.capability), route]));++export function hypiHubRouteForCapability(capability: CapabilityRef): HypiHubRoute | undefined {+ return byCapability.get(capabilityKey(capability));+}