import { Accessor } from "solid-js"; import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, GenerationPersistenceOptions, InferGenerationOutputFromReturn, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from "@tanstack/ai-client"; import { ByokClient } from "@tanstack/ai-client/byok"; import { StreamChunk } from "@tanstack/ai"; import { ProviderId } from "@tanstack/ai/byok"; //#region src/use-generate-video.d.ts /** * Options for the useGenerateVideo hook. * * @template TOutput - The transformed output type (defaults to VideoGenerateResult) */ interface UseGenerateVideoOptions { /** Connect-based adapter for streaming transport (server handles polling) */ connection?: ConnectConnectionAdapter; /** Direct async function that returns a completed video result */ fetcher?: GenerationFetcher; /** Additional body parameters to send with connect-based adapter requests */ body?: Record; /** Optional BYOK keyring. Keys go in `x-byok-*` headers, never the body. */ byok?: ByokClient; /** Optional provider id. If it returns a slug, only that key is sent. If no slug resolves (`byokProvider`, then `body.provider`), generate throws. */ byokProvider?: () => ProviderId | undefined; /** Display options for TanStack AI Devtools. */ devtools?: AIDevtoolsDisplayOptions; /** * How this generation persists across reloads. * - Omit / `false`: ephemeral, in-memory only. * - `true`: server-driven — on mount the client hydrates the last generation * for its `threadId` from the server (needs a connection with a * `hydrateGeneration` handler) and repaints it; it never auto-starts a run. */ persistence?: boolean; /** * The **scope** this generation belongs to: a stable, app-chosen name for the * slot successive runs fill — not a link to a chat conversation. * * The hook starts empty and produces many runs over its life; each gets its * own `runId`, but all belong to one scope. Persistence keys on this, so * derive it from your own domain and keep it identical across reloads (e.g. * `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread * id on the wire, which the protocol requires. * * **Required whenever `persistence` is set** — an app that cannot name the * scope has nothing to restore to. Optional for ephemeral generations. If * omitted, the client mints a wire id after mount. */ threadId?: string; /** * Server-driven hydration handler for `persistence: true` when the * connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` / * `rpcStream()` adapter built without handlers) — typically a one-line * server-function call. The connection's own handler takes precedence. */ hydrateGeneration?: ConnectConnectionAdapter['hydrateGeneration']; /** * Re-attach handler that replays a run still generating to completion on * mount, when the connection doesn't carry one. Without it, a restored * `running` snapshot surfaces as an (interrupted) error. The connection's * own handler takes precedence. */ joinRun?: ConnectConnectionAdapter['joinRun']; /** * Callback when video generation completes. Can optionally return a transformed value. * * - Return a non-null value to transform and store it as the result * - Return `null` to keep the previous result unchanged * - Return nothing (`void`) to store the raw result as-is */ onResult?: (result: VideoGenerateResult) => TOutput | null | void; /** Callback when an error occurs */ onError?: (error: Error) => void; /** Callback when progress is reported (0-100) */ onProgress?: (progress: number, message?: string) => void; /** Callback when a video job is created */ onJobCreated?: (jobId: string) => void; /** Callback on each status update */ onStatusUpdate?: (status: VideoStatusInfo) => void; /** Callback for each stream chunk (connect-based adapter mode only) */ onChunk?: (chunk: StreamChunk) => void; } /** * Return type for the useGenerateVideo hook. * * @template TOutput - The transformed output type (defaults to VideoGenerateResult) */ interface UseGenerateVideoReturn { /** Trigger video generation */ generate: (input: VideoGenerateInput) => Promise; /** The final video result (with URL), or null */ result: Accessor; /** The current job ID, or null */ jobId: Accessor; /** Current video generation status info, or null */ videoStatus: Accessor; /** Whether generation/polling is in progress */ isLoading: Accessor; /** Current error, if any */ error: Accessor; /** Current state of the generation */ status: Accessor; /** Abort the current generation/polling */ stop: () => void; /** Clear all state and return to idle */ reset: () => void; /** * The id of the generation job currently running, or `null` when nothing is in * flight. Each call to `generate` is one job with its own id. Pass it to your * own endpoint to cancel or poll the provider job — `stop()` only aborts the * local stream, it does not stop work already running on the provider. */ runId: Accessor; } /** * Solid hook for generating videos using AI models. * * Video generation is asynchronous: a job is created, then polled for status * until completion. This hook handles the full lifecycle. * * @example * ```tsx * import { useGenerateVideo } from '@tanstack/ai-solid' * import { fetchServerSentEvents } from '@tanstack/ai-client' * * function VideoGenerator() { * const { generate, result, videoStatus, isLoading } = useGenerateVideo({ * connection: fetchServerSentEvents('/api/generate/video'), * onStatusUpdate: (status) => console.log(`Progress: ${status.progress}%`), * }) * * return ( *
* * {isLoading() && videoStatus() && ( *

Status: {videoStatus()!.status} ({videoStatus()!.progress}%)

* )} * {result() &&
* ) * } * ``` */ declare function useGenerateVideo(options: Omit & { onResult?: (result: VideoGenerateResult) => TTransformed; } & GenerationPersistenceOptions): UseGenerateVideoReturn>; //#endregion export { UseGenerateVideoOptions, UseGenerateVideoReturn, useGenerateVideo }; //# sourceMappingURL=use-generate-video.d.ts.map