Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
125 lines
4.1 KiB
TypeScript
125 lines
4.1 KiB
TypeScript
/**
|
|
* Typed client for Speak Studio — Expo. Turn an OWNED reference image + an OWNED
|
|
* narration audio clip into a lipsync "talking video". Mirrors the B-roll studio
|
|
* flow: `POST /generation/speak/generate` enqueues an async
|
|
* `Job(kind="speak_lipsync")` the caller polls to completion via
|
|
* `GET /generation/speak/generations/{id}`; `GET /generation/speak/providers`
|
|
* lists the bounded, commercial-safe lipsync providers.
|
|
*
|
|
* Every call flows through the shared `x-api-key` transport (no secrets here).
|
|
* Both keys must be uploads the caller owns (minted with `presignAndUpload`);
|
|
* the backend rejects a foreign key with 403 before any billed work.
|
|
*/
|
|
|
|
import { apiRequest as request, type RequestOptions } from "@/src/shared/api";
|
|
import type { JobStateValue } from "@/lib/types";
|
|
|
|
/**
|
|
* Request body for `POST /generation/speak/generate`. `image_key` and
|
|
* `audio_key` are R2 keys the caller owns; `provider` is an optional reviewed
|
|
* lipsync selector (empty resolves a commercial-safe default server-side).
|
|
*/
|
|
export interface SpeakGenerateRequest {
|
|
image_key: string;
|
|
audio_key: string;
|
|
provider?: string;
|
|
}
|
|
|
|
/**
|
|
* One speak generation's lifecycle snapshot (the underlying
|
|
* `Job(kind="speak_lipsync")`). `talking_video_key` / `result_url` are empty
|
|
* until `state` reaches {@link JobState.Complete}.
|
|
*/
|
|
export interface SpeakGeneration {
|
|
generation_id: string;
|
|
state: JobStateValue;
|
|
progress: number;
|
|
talking_video_key: string;
|
|
result_url: string;
|
|
provider: string;
|
|
license_class: string;
|
|
error: string;
|
|
retry_eligible: boolean;
|
|
correlation_id?: string;
|
|
}
|
|
|
|
/** One selectable lipsync provider + its capability and license class. */
|
|
export interface SpeakProvider {
|
|
provider: string;
|
|
capability: string;
|
|
metering_unit: string;
|
|
license_class: string;
|
|
latency_band: string;
|
|
available: boolean;
|
|
}
|
|
|
|
/** The bounded speak engine capability the UI may offer right now. */
|
|
export interface SpeakProviders {
|
|
modes: string[];
|
|
runtime: string;
|
|
providers: SpeakProvider[];
|
|
}
|
|
|
|
/**
|
|
* POST /generation/speak/generate — start one async lipsync render and return
|
|
* its initial snapshot (poll {@link getSpeakGeneration} with `generation_id`).
|
|
*
|
|
* Spends credits: the debit is committed before the render is enqueued, so pass
|
|
* `options.idempotencyKey` to keep an ambiguous transport retry from creating a
|
|
* second billed generation. Surfaces 400 (missing/foreign key), 402
|
|
* (insufficient credits), and 503 (no provider available) as an `ApiError`.
|
|
*/
|
|
export function generateSpeak(
|
|
body: SpeakGenerateRequest,
|
|
options?: RequestOptions,
|
|
): Promise<SpeakGeneration> {
|
|
return request<SpeakGeneration>("/generation/speak/generate", {
|
|
method: "POST",
|
|
body,
|
|
options,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* GET /generation/speak/generations/{id} — poll one owned generation's
|
|
* state/progress (and `talking_video_key` + `result_url` once complete).
|
|
* Owner-scoped: an unknown/foreign/non-speak id is a clean 404.
|
|
*/
|
|
export function getSpeakGeneration(
|
|
generationId: string,
|
|
options?: RequestOptions,
|
|
): Promise<SpeakGeneration> {
|
|
return request<SpeakGeneration>(
|
|
`/generation/speak/generations/${encodeURIComponent(generationId)}`,
|
|
{ options },
|
|
);
|
|
}
|
|
|
|
/**
|
|
* GET /generation/speak/providers — the bounded lipsync selectors + license
|
|
* classes, each flagged `available` when it can actually route now. The shape is
|
|
* normalized defensively so a partial payload degrades to empty lists rather
|
|
* than throwing, and non-object provider rows are dropped.
|
|
*/
|
|
export async function listSpeakProviders(
|
|
options?: RequestOptions,
|
|
): Promise<SpeakProviders> {
|
|
const data = await request<Partial<SpeakProviders>>(
|
|
"/generation/speak/providers",
|
|
{ options },
|
|
);
|
|
const providers = Array.isArray(data?.providers)
|
|
? data.providers.filter(
|
|
(p): p is SpeakProvider =>
|
|
!!p && typeof p === "object" && typeof p.provider === "string",
|
|
)
|
|
: [];
|
|
return {
|
|
modes: Array.isArray(data?.modes)
|
|
? data.modes.filter((m): m is string => typeof m === "string")
|
|
: [],
|
|
runtime: typeof data?.runtime === "string" ? data.runtime : "",
|
|
providers,
|
|
};
|
|
}
|