@tanstack/ai-gemini 0.34.1 → 0.34.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -93,7 +93,6 @@ export declare class GeminiVideoAdapter<TModel extends GeminiVideoModel> extends
|
|
|
93
93
|
*/
|
|
94
94
|
private getInteractionsVideoUrl;
|
|
95
95
|
availableDurations(): DurationOptions<GeminiVideoModelDurationByName[TModel]>;
|
|
96
|
-
snapDuration(seconds: number): GeminiVideoModelDurationByName[TModel] | undefined;
|
|
97
96
|
/**
|
|
98
97
|
* Fetch the long-running operation by name. The SDK's
|
|
99
98
|
* `operations.getVideosOperation` needs a real `GenerateVideosOperation`
|
|
@@ -3,7 +3,7 @@ import "../utils/index.js";
|
|
|
3
3
|
import { getGeminiVideoDurationOptions, isInteractionsVideoModel, parseGeminiOmniVideoSize } from "../video/video-provider-options.js";
|
|
4
4
|
import { GenerateVideosOperation, VideoGenerationReferenceType } from "@google/genai";
|
|
5
5
|
import { fileReferenceFor, isFileSource, resolveMediaPrompt, unsupportedFileSourceError } from "@tanstack/ai";
|
|
6
|
-
import { BaseVideoAdapter
|
|
6
|
+
import { BaseVideoAdapter } from "@tanstack/ai/adapters";
|
|
7
7
|
import { arrayBufferToBase64 } from "@tanstack/ai-utils";
|
|
8
8
|
//#region src/adapters/video.ts
|
|
9
9
|
/**
|
|
@@ -397,9 +397,6 @@ var GeminiVideoAdapter = class extends BaseVideoAdapter {
|
|
|
397
397
|
availableDurations() {
|
|
398
398
|
return getGeminiVideoDurationOptions(this.model);
|
|
399
399
|
}
|
|
400
|
-
snapDuration(seconds) {
|
|
401
|
-
return snapToDurationOption(seconds, this.availableDurations());
|
|
402
|
-
}
|
|
403
400
|
/**
|
|
404
401
|
* Fetch the long-running operation by name. The SDK's
|
|
405
402
|
* `operations.getVideosOperation` needs a real `GenerateVideosOperation`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import {\n GenerateVideosOperation,\n VideoGenerationReferenceType,\n} from '@google/genai'\nimport {\n fileReferenceFor,\n isFileSource,\n resolveMediaPrompt,\n unsupportedFileSourceError,\n} from '@tanstack/ai'\nimport { BaseVideoAdapter, snapToDurationOption } from '@tanstack/ai/adapters'\nimport { arrayBufferToBase64 } from '@tanstack/ai-utils'\nimport { createGeminiClient, getGeminiApiKeyFromEnv } from '../utils'\nimport {\n getGeminiVideoDurationOptions,\n isInteractionsVideoModel,\n parseGeminiOmniVideoSize,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n GenerateVideosConfig,\n GoogleGenAI,\n Image,\n Interactions,\n VideoGenerationReferenceImage,\n} from '@google/genai'\nimport type {\n GeminiOmniVideoProviderOptions,\n GeminiVideoModel,\n GeminiVideoModelDurationByName,\n GeminiVideoModelInputModalitiesByName,\n GeminiVideoModelProviderOptionsByName,\n GeminiVideoModelSizeByName,\n GeminiVideoProviderOptions,\n} from '../video/video-provider-options'\nimport type { GeminiClientConfig } from '../utils/client'\n\ntype Interaction = Interactions.Interaction\ntype InteractionContent = Interactions.Content\n\n/**\n * Configuration for Gemini video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GeminiVideoConfig extends GeminiClientConfig {\n /**\n * Opt into fetching HTTP(S) image URL inputs. Veo's predict API accepts\n * only inline `imageBytes` or a `gcsUri`, so an HTTP(S) URL has to be\n * downloaded and base64-encoded locally — which buffers the whole image in\n * memory and can OOM constrained runtimes (e.g. Cloudflare Workers). When\n * `false` (the default), HTTP(S) URL image inputs throw; pass a `data:` URI\n * or a `gs://` reference, or set this to `true` to opt into buffering.\n */\n allowUrlFetch?: boolean\n}\n\n/**\n * Extract a human-readable message from a long-running operation's error,\n * which the SDK types as `Record<string, unknown>` (a google.rpc.Status).\n */\nfunction operationErrorMessage(error: Record<string, unknown>): string {\n if (typeof error.message === 'string' && error.message.length > 0) {\n return error.message\n }\n return JSON.stringify(error)\n}\n\n/**\n * Convert a TanStack image prompt part into the genai `Image` shape Veo\n * accepts: base64 `imageBytes` (data sources, data: URIs, fetched HTTP\n * URLs) or a `gcsUri` passthrough for Cloud Storage references.\n *\n * Unlike `generateContent` (chat / native image generation), Veo's predict\n * API has no `fileData.fileUri` equivalent — `Image` only accepts\n * `imageBytes` or `gcsUri`. An HTTP(S) URL therefore has to be fetched and\n * inlined locally, which buffers the whole image in memory; that only happens\n * when the caller opts in via `allowUrlFetch`, otherwise it throws. Prefer a\n * `gs://` reference on memory-constrained runtimes.\n */\nasync function imagePartToVeoImage(\n part: ImagePart<MediaInputMetadata>,\n allowUrlFetch: boolean,\n): Promise<Image> {\n if (part.source.type === 'data') {\n return {\n imageBytes: part.source.value,\n mimeType: part.source.mimeType || 'image/png',\n }\n }\n if (isFileSource(part.source)) {\n // Veo's predict API accepts only inline bytes or a gs:// reference — there's\n // no way to reference a Files API handle here.\n throw unsupportedFileSourceError(\n 'gemini',\n 'for Veo video generation, which needs inline image bytes or a gs:// reference — pass a data: URI or gs:// URL',\n )\n }\n const url = part.source.value\n if (url.startsWith('gs://')) {\n return {\n gcsUri: url,\n ...(part.source.mimeType && { mimeType: part.source.mimeType }),\n }\n }\n if (url.startsWith('data:')) {\n const match = url.match(/^data:([^;,]+)?(;base64)?,(.*)$/)\n if (!match || !match[2]) {\n throw new Error(\n 'gemini: only base64 data: URIs are supported for video image inputs.',\n )\n }\n return {\n imageBytes: match[3] ?? '',\n mimeType: match[1] || part.source.mimeType || 'image/png',\n }\n }\n if (!allowUrlFetch) {\n throw new Error(\n `gemini Veo: HTTP(S) URL image inputs are not fetched by default because ` +\n `Veo accepts only inline bytes, so the image would be downloaded and ` +\n `buffered in memory (risking OOM on constrained runtimes). Pass a ` +\n `data: URI or a gs:// reference, or set \\`allowUrlFetch: true\\` on the ` +\n `adapter config to opt into fetching. URL: ${url}`,\n )\n }\n const response = await fetch(url)\n if (!response.ok) {\n throw new Error(\n `Failed to fetch image input (${response.status} ${response.statusText}): ${url}`,\n )\n }\n const blob = await response.blob()\n const buffer = await blob.arrayBuffer()\n return {\n imageBytes: arrayBufferToBase64(buffer),\n mimeType: part.source.mimeType || blob.type || 'image/png',\n }\n}\n\n/**\n * Convert an image or video prompt part into an Interactions API content\n * block. Data sources become inline base64 `data`; URL sources pass through\n * as `uri` (Files API URIs — mirrors the Interactions text adapter).\n */\nfunction mediaPartToInteractionsContent(\n part: ImagePart<MediaInputMetadata> | VideoPart<MediaInputMetadata>,\n): InteractionContent {\n // A Gemini Files API reference maps to the `uri` field, same as a public\n // URL (mirrors the Interactions text adapter). `fileReferenceFor` throws\n // when another provider issued the handle.\n const sourceValue = isFileSource(part.source)\n ? fileReferenceFor(part.source, 'gemini')\n : part.source.value\n const mimeType = part.source.mimeType\n if (part.type === 'image') {\n return part.source.type === 'data'\n ? { type: 'image', data: sourceValue, mime_type: mimeType }\n : { type: 'image', uri: sourceValue, mime_type: mimeType }\n }\n return part.source.type === 'data'\n ? { type: 'video', data: sourceValue, mime_type: mimeType }\n : { type: 'video', uri: sourceValue, mime_type: mimeType }\n}\n\n/**\n * Pull the generated video out of a completed interaction. Prefers the\n * SDK's `output_video` sugar, then walks `steps` back-to-front for the last\n * `model_output` step carrying a video content block (the wire shape the\n * raw REST response uses).\n */\nfunction extractInteractionVideo(\n interaction: Interaction,\n): { data?: string; uri?: string; mimeType: string } | undefined {\n const direct = interaction.output_video\n if (direct && (direct.data || direct.uri)) {\n return {\n data: direct.data,\n uri: direct.uri,\n mimeType: direct.mime_type || 'video/mp4',\n }\n }\n const steps = interaction.steps ?? []\n for (let i = steps.length - 1; i >= 0; i--) {\n const step = steps[i]\n if (step?.type !== 'model_output') continue\n for (const block of step.content ?? []) {\n if (block.type === 'video' && (block.data || block.uri)) {\n return {\n data: block.data,\n uri: block.uri,\n mimeType: block.mime_type || 'video/mp4',\n }\n }\n }\n }\n return undefined\n}\n\n/**\n * Map Interactions usage onto the canonical TokenUsage shape. Omni reports\n * video output via `output_tokens_by_modality`; fall back to the video\n * modality entry when the total is absent.\n */\nfunction interactionUsageToTokenUsage(\n usage: Interaction['usage'],\n): TokenUsage | undefined {\n if (!usage) return undefined\n const videoTokens = usage.output_tokens_by_modality?.find(\n (entry) => entry.modality === 'video',\n )?.tokens\n const promptTokens = usage.total_input_tokens ?? 0\n const completionTokens = usage.total_output_tokens ?? videoTokens ?? 0\n return {\n promptTokens,\n completionTokens,\n totalTokens: usage.total_tokens ?? promptTokens + completionTokens,\n }\n}\n\n/**\n * Gemini Video Generation Adapter (Veo + Gemini Omni Flash)\n *\n * Tree-shakeable adapter for Google video generation, routing by model:\n *\n * **Veo models** run as a long-running operation: `createVideoJob` starts\n * the operation via the `:predictLongRunning` endpoint, `getVideoStatus`\n * polls it, and `getVideoUrl` extracts the generated video's URI once it\n * completes. Image prompt parts are routed by `metadata.role`:\n * - `'start_frame'` (or the first un-roled image) → the input image the\n * video starts from\n * - `'end_frame'` → `lastFrame` (the frame the video ends on)\n * - `'reference'` / `'character'` → `referenceImages` (asset references,\n * Veo 3.1)\n *\n * Note: the returned Veo video URI is served by the Gemini Files API and\n * requires the API key (`x-goog-api-key` header or `?key=` query\n * parameter) to download.\n *\n * **Gemini Omni Flash** (`gemini-omni-1.1-flash`, plus the deprecated\n * `gemini-omni-flash-preview` alias) only serves the Interactions API:\n * `createVideoJob` creates a background interaction with\n * `response_modalities: ['video']`, `getVideoStatus` polls it by id, and\n * `getVideoUrl` returns the inline base64 MP4 as a `data:` URL (or the\n * Files API URI when the server delivers by reference). Image and video\n * prompt parts are sent as interaction content blocks, grouped as images,\n * then videos, then the text prompt (interleaving is not preserved); pass\n * `modelOptions.previous_interaction_id` to conversationally edit a prior\n * Omni generation. `size` is an `aspectRatio_resolution` template\n * (`'16:9'` or `'16:9_1080p'`); the optional suffix maps onto\n * `response_format.resolution` (`'360p' | '720p' | '1080p' | '4k'`,\n * default 720p).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport class GeminiVideoAdapter<\n TModel extends GeminiVideoModel,\n> extends BaseVideoAdapter<\n TModel,\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelProviderOptionsByName,\n GeminiVideoModelSizeByName,\n GeminiVideoModelInputModalitiesByName,\n GeminiVideoModelDurationByName\n> {\n readonly name = 'gemini' as const\n // The Interactions path consumes Gemini Files API references as content\n // `uri`s; the Veo path still rejects them (raw bytes / gs:// only).\n override readonly supportsFileSources = true\n\n protected client: GoogleGenAI\n private readonly allowUrlFetch: boolean\n\n constructor(config: GeminiVideoConfig, model: TModel) {\n super({}, model)\n this.client = createGeminiClient(config)\n this.allowUrlFetch = config.allowUrlFetch ?? false\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelSizeByName[TModel],\n GeminiVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { prompt, size, duration, logger } = options\n\n logger.request(\n `activity=video.create provider=${this.name} model=${this.model} size=${size ?? 'default'} duration=${duration ?? 'default'}`,\n { provider: this.name, model: this.model },\n )\n\n if (isInteractionsVideoModel(this.model)) {\n return await this.createInteractionsVideoJob(options)\n }\n const modelOptions = options.modelOptions as\n | GeminiVideoProviderOptions\n | undefined\n\n try {\n const resolved = resolveMediaPrompt(prompt)\n\n if (resolved.videos.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support video prompt parts (model: ${this.model}).`,\n )\n }\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${this.model}).`,\n )\n }\n\n const { image, lastFrame, referenceImages } = await this.routeImageParts(\n resolved.images,\n )\n\n const config: GenerateVideosConfig = {\n ...modelOptions,\n ...(size !== undefined && { aspectRatio: size }),\n ...(duration !== undefined && { durationSeconds: duration }),\n ...(lastFrame && { lastFrame }),\n ...(referenceImages.length > 0 && { referenceImages }),\n }\n\n const operation = await this.client.models.generateVideos({\n model: this.model,\n prompt: resolved.text,\n ...(image && { image }),\n config,\n })\n\n if (!operation.name) {\n throw new Error(\n 'Veo did not return an operation name for the video generation job.',\n )\n }\n\n return { jobId: operation.name, model: this.model }\n } catch (error) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error,\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Gemini Omni Flash job creation via the Interactions API. Creates a\n * background interaction requesting video output; the interaction id is\n * the job id polled by `getVideoStatus` / `getVideoUrl`.\n */\n private async createInteractionsVideoJob(\n options: VideoGenerationOptions<\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelSizeByName[TModel],\n GeminiVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { prompt, size, duration, logger } = options\n const modelOptions = options.modelOptions as\n | GeminiOmniVideoProviderOptions\n | undefined\n\n try {\n const resolved = resolveMediaPrompt(prompt)\n\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${this.model}).`,\n )\n }\n\n const content: Array<InteractionContent> = [\n ...resolved.images.map(mediaPartToInteractionsContent),\n ...resolved.videos.map(mediaPartToInteractionsContent),\n ]\n if (resolved.text) {\n content.push({ type: 'text', text: resolved.text })\n }\n if (content.length === 0) {\n throw new Error(\n `${this.name}.createVideoJob: the prompt produced no content to send (model: ${this.model}).`,\n )\n }\n\n // Reject out-of-range durations locally rather than snapping (which\n // would silently change the clip length the caller asked for) or\n // letting the live API reject them after the round trip.\n const durations = this.availableDurations()\n if (\n duration !== undefined &&\n durations.kind === 'range' &&\n (duration < durations.min || duration > durations.max)\n ) {\n throw new Error(\n `${this.name}.createVideoJob: duration ${duration}s is outside the ${durations.min}–${durations.max}s range supported by ${this.model}. Use snapDuration() to snap arbitrary values into range.`,\n )\n }\n\n // Aspect ratio, clip length, and resolution ride on `response_format`.\n // Duration is a `\"<seconds>s\"` string. Resolution comes from the\n // optional `size` suffix (`'16:9_1080p'`), defaulting to 720p when\n // omitted — https://ai.google.dev/gemini-api/docs/omni\n const parsedSize =\n size !== undefined ? parseGeminiOmniVideoSize(size) : undefined\n const responseFormat =\n parsedSize !== undefined || duration !== undefined\n ? {\n response_format: {\n type: 'video' as const,\n ...(parsedSize !== undefined && {\n aspect_ratio: parsedSize.aspectRatio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...(duration !== undefined && { duration: `${duration}s` }),\n },\n }\n : {}\n\n const interaction = await this.client.interactions.create({\n ...modelOptions,\n model: this.model,\n input: [{ type: 'user_input', content }],\n response_modalities: ['video'],\n background: true,\n ...responseFormat,\n })\n\n if (!interaction.id) {\n throw new Error(\n 'Gemini Omni did not return an interaction id for the video generation job.',\n )\n }\n\n return { jobId: interaction.id, model: this.model }\n } catch (error) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error,\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Route image prompt parts onto Veo's request fields by `metadata.role`.\n */\n private async routeImageParts(\n parts: Array<ImagePart<MediaInputMetadata>>,\n ): Promise<{\n image: Image | undefined\n lastFrame: Image | undefined\n referenceImages: Array<VideoGenerationReferenceImage>\n }> {\n let image: Image | undefined\n let lastFrame: Image | undefined\n const referenceImages: Array<VideoGenerationReferenceImage> = []\n\n for (const part of parts) {\n const role = part.metadata?.role\n switch (role) {\n case 'end_frame': {\n if (lastFrame) {\n throw new Error(\n `${this.name}: Veo accepts at most one 'end_frame' image.`,\n )\n }\n lastFrame = await imagePartToVeoImage(part, this.allowUrlFetch)\n break\n }\n case 'reference':\n case 'character': {\n referenceImages.push({\n image: await imagePartToVeoImage(part, this.allowUrlFetch),\n referenceType: VideoGenerationReferenceType.ASSET,\n })\n break\n }\n case 'start_frame':\n case undefined: {\n if (image) {\n throw new Error(\n `${this.name}: Veo accepts at most one starting image; received multiple 'start_frame'/un-roled images. Use metadata.role ('end_frame', 'reference') to disambiguate the others.`,\n )\n }\n image = await imagePartToVeoImage(part, this.allowUrlFetch)\n break\n }\n case 'mask':\n case 'control':\n throw new Error(\n `${this.name}: unsupported image role \"${role}\" for Veo video generation.`,\n )\n }\n }\n\n return { image, lastFrame, referenceImages }\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n if (isInteractionsVideoModel(this.model)) {\n return await this.getInteractionsVideoStatus(jobId)\n }\n const operation = await this.getOperation(jobId)\n\n if (!operation.done) {\n return { jobId, status: 'processing' }\n }\n\n if (operation.error) {\n return {\n jobId,\n status: 'failed',\n error: operationErrorMessage(operation.error),\n }\n }\n\n // The operation can finish \"successfully\" with every sample dropped by\n // Responsible-AI filters — surface that as a failure instead of letting\n // getVideoUrl() throw on an empty response.\n const videos = operation.response?.generatedVideos ?? []\n if (videos.length === 0) {\n const reasons = operation.response?.raiMediaFilteredReasons\n return {\n jobId,\n status: 'failed',\n error: reasons?.length\n ? `Video was filtered by Responsible-AI: ${reasons.join('; ')}`\n : 'Veo returned no generated videos.',\n }\n }\n\n return { jobId, status: 'completed' }\n }\n\n /**\n * Poll an Omni background interaction. `in_progress` maps to\n * 'processing'; a `completed` interaction with no video content (e.g.\n * filtered output) is surfaced as a failure so `getVideoUrl` doesn't\n * throw on an empty response. `requires_action` also fails: the adapter\n * never sends tools, so it can only arise via\n * `previous_interaction_id` chaining onto a tool-bearing interaction —\n * and such an interaction never progresses without a client response,\n * so polling it would spin until timeout.\n */\n private async getInteractionsVideoStatus(\n jobId: string,\n ): Promise<VideoStatusResult> {\n const interaction = await this.getInteraction(jobId)\n const status = interaction.status\n\n if (status === 'in_progress') {\n return { jobId, status: 'processing' }\n }\n if (status === 'requires_action') {\n return {\n jobId,\n status: 'failed',\n error:\n 'Gemini Omni interaction is waiting on a client action (tool response), which the video jobs flow does not support.',\n }\n }\n if (status === 'completed') {\n if (!extractInteractionVideo(interaction)) {\n return {\n jobId,\n status: 'failed',\n error:\n 'Gemini Omni completed the interaction without returning a video (the output may have been filtered).',\n }\n }\n return { jobId, status: 'completed' }\n }\n return {\n jobId,\n status: 'failed',\n error: `Gemini Omni video generation ended with status \"${status}\".`,\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n if (isInteractionsVideoModel(this.model)) {\n return await this.getInteractionsVideoUrl(jobId)\n }\n const operation = await this.getOperation(jobId)\n\n if (!operation.done) {\n throw new Error(\n `Video is not ready yet. Check status first. Job ID: ${jobId}`,\n )\n }\n\n if (operation.error) {\n throw new Error(\n `Video generation failed: ${operationErrorMessage(operation.error)}`,\n )\n }\n\n const uri = operation.response?.generatedVideos?.[0]?.video?.uri\n if (!uri) {\n const reasons = operation.response?.raiMediaFilteredReasons\n throw new Error(\n reasons?.length\n ? `Video was filtered by Responsible-AI: ${reasons.join('; ')}`\n : `Video URL not found in operation response. Job ID: ${jobId}`,\n )\n }\n\n return { jobId, url: uri }\n }\n\n /**\n * Extract the finished Omni video. Inline base64 output (the API default)\n * becomes a `data:` URL — matching the OpenAI Sora adapter's inline\n * delivery — and URI delivery passes through (Files API URIs need the API\n * key to download, like Veo). Usage carries the video-modality output\n * tokens (Omni bills per second of video, reported as tokens).\n */\n private async getInteractionsVideoUrl(\n jobId: string,\n ): Promise<VideoUrlResult> {\n const interaction = await this.getInteraction(jobId)\n const status = interaction.status\n\n if (status === 'in_progress') {\n throw new Error(\n `Video is not ready yet. Check status first. Job ID: ${jobId}`,\n )\n }\n if (status !== 'completed') {\n throw new Error(\n `Video generation failed: Gemini Omni interaction ended with status \"${status}\". Job ID: ${jobId}`,\n )\n }\n\n const video = extractInteractionVideo(interaction)\n if (!video) {\n throw new Error(\n `Video not found in interaction response (the output may have been filtered). Job ID: ${jobId}`,\n )\n }\n\n const usage = interactionUsageToTokenUsage(interaction.usage)\n const url = video.uri ?? `data:${video.mimeType};base64,${video.data}`\n return { jobId, url, ...(usage && { usage }) }\n }\n\n override availableDurations(): DurationOptions<\n GeminiVideoModelDurationByName[TModel]\n > {\n return getGeminiVideoDurationOptions(this.model)\n }\n\n override snapDuration(\n seconds: number,\n ): GeminiVideoModelDurationByName[TModel] | undefined {\n return snapToDurationOption(seconds, this.availableDurations())\n }\n\n /**\n * Fetch the long-running operation by name. The SDK's\n * `operations.getVideosOperation` needs a real `GenerateVideosOperation`\n * instance (it calls `_fromAPIResponse` on it), so reconstruct one from\n * the job ID rather than passing an object literal.\n */\n private async getOperation(jobId: string): Promise<GenerateVideosOperation> {\n const operation = new GenerateVideosOperation()\n operation.name = jobId\n return await this.client.operations.getVideosOperation({ operation })\n }\n\n /**\n * Fetch an Omni background interaction by id.\n */\n private async getInteraction(jobId: string): Promise<Interaction> {\n return await this.client.interactions.get(jobId)\n }\n}\n\n/** @deprecated Shuts down 2026-09-30. Use `gemini-omni-1.1-flash`. */\nexport function createGeminiVideo(\n model: 'gemini-omni-flash-preview',\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<'gemini-omni-flash-preview'>\n/**\n * Creates a Gemini video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'veo-3.1-generate-preview')\n * @param apiKey - Your Google API key\n * @param config - Optional additional configuration\n * @returns Configured Gemini video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGeminiVideo('veo-3.1-generate-preview', 'your-api-key');\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A beautiful sunset over the ocean',\n * duration: adapter.snapDuration(7), // → 6\n * });\n * ```\n */\nexport function createGeminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel>\nexport function createGeminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel> {\n return new GeminiVideoAdapter({ apiKey, ...config }, model)\n}\n\n/** @deprecated Shuts down 2026-09-30. Use `gemini-omni-1.1-flash`. */\nexport function geminiVideo(\n model: 'gemini-omni-flash-preview',\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<'gemini-omni-flash-preview'>\n/**\n * Creates a Gemini video adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `GOOGLE_API_KEY` or `GEMINI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'veo-3.1-generate-preview')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Gemini video adapter instance with resolved types\n * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses GOOGLE_API_KEY from environment\n * const adapter = geminiVideo('veo-3.1-generate-preview');\n *\n * // Create a video generation job\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A cat playing piano'\n * });\n *\n * // Poll for status\n * const status = await getVideoJobStatus({ adapter, jobId });\n * ```\n */\nexport function geminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel>\nexport function geminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel> {\n const apiKey = getGeminiApiKeyFromEnv()\n return createGeminiVideo(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;;;AAuEA,SAAS,sBAAsB,OAAwC;CACrE,IAAI,OAAO,MAAM,YAAY,YAAY,MAAM,QAAQ,SAAS,GAC9D,OAAO,MAAM;CAEf,OAAO,KAAK,UAAU,KAAK;AAC7B;;;;;;;;;;;;;AAcA,eAAe,oBACb,MACA,eAC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EAEF,IAAI,WAAW,aACb,MAAM,IAAI,MACR,uEAAuE,OAAO,aAAa,OAC7F;EAGF,MAAM,QAAQ,wBAAwB,WAAW;EACjD,IAAI,CAAC,OACH,MAAM,IAAI,MACR,wFAAwF,OAC1F;EAGF,MAAM,QAAQ,6BAA6B,YAAY,KAAK;EAE5D,OAAO;GAAE;GAAO,KADJ,MAAM,OAAO,QAAQ,MAAM,SAAS,UAAU,MAAM;GAC3C,GAAI,SAAS,EAAE,MAAM;EAAG;CAC/C;CAEA,qBAEE;EACA,OAAO,8BAA8B,KAAK,KAAK;CACjD;CAEA,aACE,SACoD;EACpD,OAAO,qBAAqB,SAAS,KAAK,mBAAmB,CAAC;CAChE;;;;;;;CAQA,MAAc,aAAa,OAAiD;EAC1E,MAAM,YAAY,IAAI,wBAAwB;EAC9C,UAAU,OAAO;EACjB,OAAO,MAAM,KAAK,OAAO,WAAW,mBAAmB,EAAE,UAAU,CAAC;CACtE;;;;CAKA,MAAc,eAAe,OAAqC;EAChE,OAAO,MAAM,KAAK,OAAO,aAAa,IAAI,KAAK;CACjD;AACF;AAmCA,SAAgB,kBACd,OACA,QACA,QAC4B;CAC5B,OAAO,IAAI,mBAAmB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC5D;AAyCA,SAAgB,YACd,OACA,QAC4B;CAE5B,OAAO,kBAAkB,OADV,uBACiB,GAAQ,MAAM;AAChD"}
|
|
1
|
+
{"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import {\n GenerateVideosOperation,\n VideoGenerationReferenceType,\n} from '@google/genai'\nimport {\n fileReferenceFor,\n isFileSource,\n resolveMediaPrompt,\n unsupportedFileSourceError,\n} from '@tanstack/ai'\nimport { BaseVideoAdapter } from '@tanstack/ai/adapters'\nimport { arrayBufferToBase64 } from '@tanstack/ai-utils'\nimport { createGeminiClient, getGeminiApiKeyFromEnv } from '../utils'\nimport {\n getGeminiVideoDurationOptions,\n isInteractionsVideoModel,\n parseGeminiOmniVideoSize,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n GenerateVideosConfig,\n GoogleGenAI,\n Image,\n Interactions,\n VideoGenerationReferenceImage,\n} from '@google/genai'\nimport type {\n GeminiOmniVideoProviderOptions,\n GeminiVideoModel,\n GeminiVideoModelDurationByName,\n GeminiVideoModelInputModalitiesByName,\n GeminiVideoModelProviderOptionsByName,\n GeminiVideoModelSizeByName,\n GeminiVideoProviderOptions,\n} from '../video/video-provider-options'\nimport type { GeminiClientConfig } from '../utils/client'\n\ntype Interaction = Interactions.Interaction\ntype InteractionContent = Interactions.Content\n\n/**\n * Configuration for Gemini video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GeminiVideoConfig extends GeminiClientConfig {\n /**\n * Opt into fetching HTTP(S) image URL inputs. Veo's predict API accepts\n * only inline `imageBytes` or a `gcsUri`, so an HTTP(S) URL has to be\n * downloaded and base64-encoded locally — which buffers the whole image in\n * memory and can OOM constrained runtimes (e.g. Cloudflare Workers). When\n * `false` (the default), HTTP(S) URL image inputs throw; pass a `data:` URI\n * or a `gs://` reference, or set this to `true` to opt into buffering.\n */\n allowUrlFetch?: boolean\n}\n\n/**\n * Extract a human-readable message from a long-running operation's error,\n * which the SDK types as `Record<string, unknown>` (a google.rpc.Status).\n */\nfunction operationErrorMessage(error: Record<string, unknown>): string {\n if (typeof error.message === 'string' && error.message.length > 0) {\n return error.message\n }\n return JSON.stringify(error)\n}\n\n/**\n * Convert a TanStack image prompt part into the genai `Image` shape Veo\n * accepts: base64 `imageBytes` (data sources, data: URIs, fetched HTTP\n * URLs) or a `gcsUri` passthrough for Cloud Storage references.\n *\n * Unlike `generateContent` (chat / native image generation), Veo's predict\n * API has no `fileData.fileUri` equivalent — `Image` only accepts\n * `imageBytes` or `gcsUri`. An HTTP(S) URL therefore has to be fetched and\n * inlined locally, which buffers the whole image in memory; that only happens\n * when the caller opts in via `allowUrlFetch`, otherwise it throws. Prefer a\n * `gs://` reference on memory-constrained runtimes.\n */\nasync function imagePartToVeoImage(\n part: ImagePart<MediaInputMetadata>,\n allowUrlFetch: boolean,\n): Promise<Image> {\n if (part.source.type === 'data') {\n return {\n imageBytes: part.source.value,\n mimeType: part.source.mimeType || 'image/png',\n }\n }\n if (isFileSource(part.source)) {\n // Veo's predict API accepts only inline bytes or a gs:// reference — there's\n // no way to reference a Files API handle here.\n throw unsupportedFileSourceError(\n 'gemini',\n 'for Veo video generation, which needs inline image bytes or a gs:// reference — pass a data: URI or gs:// URL',\n )\n }\n const url = part.source.value\n if (url.startsWith('gs://')) {\n return {\n gcsUri: url,\n ...(part.source.mimeType && { mimeType: part.source.mimeType }),\n }\n }\n if (url.startsWith('data:')) {\n const match = url.match(/^data:([^;,]+)?(;base64)?,(.*)$/)\n if (!match || !match[2]) {\n throw new Error(\n 'gemini: only base64 data: URIs are supported for video image inputs.',\n )\n }\n return {\n imageBytes: match[3] ?? '',\n mimeType: match[1] || part.source.mimeType || 'image/png',\n }\n }\n if (!allowUrlFetch) {\n throw new Error(\n `gemini Veo: HTTP(S) URL image inputs are not fetched by default because ` +\n `Veo accepts only inline bytes, so the image would be downloaded and ` +\n `buffered in memory (risking OOM on constrained runtimes). Pass a ` +\n `data: URI or a gs:// reference, or set \\`allowUrlFetch: true\\` on the ` +\n `adapter config to opt into fetching. URL: ${url}`,\n )\n }\n const response = await fetch(url)\n if (!response.ok) {\n throw new Error(\n `Failed to fetch image input (${response.status} ${response.statusText}): ${url}`,\n )\n }\n const blob = await response.blob()\n const buffer = await blob.arrayBuffer()\n return {\n imageBytes: arrayBufferToBase64(buffer),\n mimeType: part.source.mimeType || blob.type || 'image/png',\n }\n}\n\n/**\n * Convert an image or video prompt part into an Interactions API content\n * block. Data sources become inline base64 `data`; URL sources pass through\n * as `uri` (Files API URIs — mirrors the Interactions text adapter).\n */\nfunction mediaPartToInteractionsContent(\n part: ImagePart<MediaInputMetadata> | VideoPart<MediaInputMetadata>,\n): InteractionContent {\n // A Gemini Files API reference maps to the `uri` field, same as a public\n // URL (mirrors the Interactions text adapter). `fileReferenceFor` throws\n // when another provider issued the handle.\n const sourceValue = isFileSource(part.source)\n ? fileReferenceFor(part.source, 'gemini')\n : part.source.value\n const mimeType = part.source.mimeType\n if (part.type === 'image') {\n return part.source.type === 'data'\n ? { type: 'image', data: sourceValue, mime_type: mimeType }\n : { type: 'image', uri: sourceValue, mime_type: mimeType }\n }\n return part.source.type === 'data'\n ? { type: 'video', data: sourceValue, mime_type: mimeType }\n : { type: 'video', uri: sourceValue, mime_type: mimeType }\n}\n\n/**\n * Pull the generated video out of a completed interaction. Prefers the\n * SDK's `output_video` sugar, then walks `steps` back-to-front for the last\n * `model_output` step carrying a video content block (the wire shape the\n * raw REST response uses).\n */\nfunction extractInteractionVideo(\n interaction: Interaction,\n): { data?: string; uri?: string; mimeType: string } | undefined {\n const direct = interaction.output_video\n if (direct && (direct.data || direct.uri)) {\n return {\n data: direct.data,\n uri: direct.uri,\n mimeType: direct.mime_type || 'video/mp4',\n }\n }\n const steps = interaction.steps ?? []\n for (let i = steps.length - 1; i >= 0; i--) {\n const step = steps[i]\n if (step?.type !== 'model_output') continue\n for (const block of step.content ?? []) {\n if (block.type === 'video' && (block.data || block.uri)) {\n return {\n data: block.data,\n uri: block.uri,\n mimeType: block.mime_type || 'video/mp4',\n }\n }\n }\n }\n return undefined\n}\n\n/**\n * Map Interactions usage onto the canonical TokenUsage shape. Omni reports\n * video output via `output_tokens_by_modality`; fall back to the video\n * modality entry when the total is absent.\n */\nfunction interactionUsageToTokenUsage(\n usage: Interaction['usage'],\n): TokenUsage | undefined {\n if (!usage) return undefined\n const videoTokens = usage.output_tokens_by_modality?.find(\n (entry) => entry.modality === 'video',\n )?.tokens\n const promptTokens = usage.total_input_tokens ?? 0\n const completionTokens = usage.total_output_tokens ?? videoTokens ?? 0\n return {\n promptTokens,\n completionTokens,\n totalTokens: usage.total_tokens ?? promptTokens + completionTokens,\n }\n}\n\n/**\n * Gemini Video Generation Adapter (Veo + Gemini Omni Flash)\n *\n * Tree-shakeable adapter for Google video generation, routing by model:\n *\n * **Veo models** run as a long-running operation: `createVideoJob` starts\n * the operation via the `:predictLongRunning` endpoint, `getVideoStatus`\n * polls it, and `getVideoUrl` extracts the generated video's URI once it\n * completes. Image prompt parts are routed by `metadata.role`:\n * - `'start_frame'` (or the first un-roled image) → the input image the\n * video starts from\n * - `'end_frame'` → `lastFrame` (the frame the video ends on)\n * - `'reference'` / `'character'` → `referenceImages` (asset references,\n * Veo 3.1)\n *\n * Note: the returned Veo video URI is served by the Gemini Files API and\n * requires the API key (`x-goog-api-key` header or `?key=` query\n * parameter) to download.\n *\n * **Gemini Omni Flash** (`gemini-omni-1.1-flash`, plus the deprecated\n * `gemini-omni-flash-preview` alias) only serves the Interactions API:\n * `createVideoJob` creates a background interaction with\n * `response_modalities: ['video']`, `getVideoStatus` polls it by id, and\n * `getVideoUrl` returns the inline base64 MP4 as a `data:` URL (or the\n * Files API URI when the server delivers by reference). Image and video\n * prompt parts are sent as interaction content blocks, grouped as images,\n * then videos, then the text prompt (interleaving is not preserved); pass\n * `modelOptions.previous_interaction_id` to conversationally edit a prior\n * Omni generation. `size` is an `aspectRatio_resolution` template\n * (`'16:9'` or `'16:9_1080p'`); the optional suffix maps onto\n * `response_format.resolution` (`'360p' | '720p' | '1080p' | '4k'`,\n * default 720p).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport class GeminiVideoAdapter<\n TModel extends GeminiVideoModel,\n> extends BaseVideoAdapter<\n TModel,\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelProviderOptionsByName,\n GeminiVideoModelSizeByName,\n GeminiVideoModelInputModalitiesByName,\n GeminiVideoModelDurationByName\n> {\n readonly name = 'gemini' as const\n // The Interactions path consumes Gemini Files API references as content\n // `uri`s; the Veo path still rejects them (raw bytes / gs:// only).\n override readonly supportsFileSources = true\n\n protected client: GoogleGenAI\n private readonly allowUrlFetch: boolean\n\n constructor(config: GeminiVideoConfig, model: TModel) {\n super({}, model)\n this.client = createGeminiClient(config)\n this.allowUrlFetch = config.allowUrlFetch ?? false\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelSizeByName[TModel],\n GeminiVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { prompt, size, duration, logger } = options\n\n logger.request(\n `activity=video.create provider=${this.name} model=${this.model} size=${size ?? 'default'} duration=${duration ?? 'default'}`,\n { provider: this.name, model: this.model },\n )\n\n if (isInteractionsVideoModel(this.model)) {\n return await this.createInteractionsVideoJob(options)\n }\n const modelOptions = options.modelOptions as\n | GeminiVideoProviderOptions\n | undefined\n\n try {\n const resolved = resolveMediaPrompt(prompt)\n\n if (resolved.videos.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support video prompt parts (model: ${this.model}).`,\n )\n }\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${this.model}).`,\n )\n }\n\n const { image, lastFrame, referenceImages } = await this.routeImageParts(\n resolved.images,\n )\n\n const config: GenerateVideosConfig = {\n ...modelOptions,\n ...(size !== undefined && { aspectRatio: size }),\n ...(duration !== undefined && { durationSeconds: duration }),\n ...(lastFrame && { lastFrame }),\n ...(referenceImages.length > 0 && { referenceImages }),\n }\n\n const operation = await this.client.models.generateVideos({\n model: this.model,\n prompt: resolved.text,\n ...(image && { image }),\n config,\n })\n\n if (!operation.name) {\n throw new Error(\n 'Veo did not return an operation name for the video generation job.',\n )\n }\n\n return { jobId: operation.name, model: this.model }\n } catch (error) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error,\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Gemini Omni Flash job creation via the Interactions API. Creates a\n * background interaction requesting video output; the interaction id is\n * the job id polled by `getVideoStatus` / `getVideoUrl`.\n */\n private async createInteractionsVideoJob(\n options: VideoGenerationOptions<\n GeminiVideoModelProviderOptionsByName[TModel],\n GeminiVideoModelSizeByName[TModel],\n GeminiVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { prompt, size, duration, logger } = options\n const modelOptions = options.modelOptions as\n | GeminiOmniVideoProviderOptions\n | undefined\n\n try {\n const resolved = resolveMediaPrompt(prompt)\n\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${this.model}).`,\n )\n }\n\n const content: Array<InteractionContent> = [\n ...resolved.images.map(mediaPartToInteractionsContent),\n ...resolved.videos.map(mediaPartToInteractionsContent),\n ]\n if (resolved.text) {\n content.push({ type: 'text', text: resolved.text })\n }\n if (content.length === 0) {\n throw new Error(\n `${this.name}.createVideoJob: the prompt produced no content to send (model: ${this.model}).`,\n )\n }\n\n // Reject out-of-range durations locally rather than snapping (which\n // would silently change the clip length the caller asked for) or\n // letting the live API reject them after the round trip.\n const durations = this.availableDurations()\n if (\n duration !== undefined &&\n durations.kind === 'range' &&\n (duration < durations.min || duration > durations.max)\n ) {\n throw new Error(\n `${this.name}.createVideoJob: duration ${duration}s is outside the ${durations.min}–${durations.max}s range supported by ${this.model}. Use snapDuration() to snap arbitrary values into range.`,\n )\n }\n\n // Aspect ratio, clip length, and resolution ride on `response_format`.\n // Duration is a `\"<seconds>s\"` string. Resolution comes from the\n // optional `size` suffix (`'16:9_1080p'`), defaulting to 720p when\n // omitted — https://ai.google.dev/gemini-api/docs/omni\n const parsedSize =\n size !== undefined ? parseGeminiOmniVideoSize(size) : undefined\n const responseFormat =\n parsedSize !== undefined || duration !== undefined\n ? {\n response_format: {\n type: 'video' as const,\n ...(parsedSize !== undefined && {\n aspect_ratio: parsedSize.aspectRatio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...(duration !== undefined && { duration: `${duration}s` }),\n },\n }\n : {}\n\n const interaction = await this.client.interactions.create({\n ...modelOptions,\n model: this.model,\n input: [{ type: 'user_input', content }],\n response_modalities: ['video'],\n background: true,\n ...responseFormat,\n })\n\n if (!interaction.id) {\n throw new Error(\n 'Gemini Omni did not return an interaction id for the video generation job.',\n )\n }\n\n return { jobId: interaction.id, model: this.model }\n } catch (error) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error,\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Route image prompt parts onto Veo's request fields by `metadata.role`.\n */\n private async routeImageParts(\n parts: Array<ImagePart<MediaInputMetadata>>,\n ): Promise<{\n image: Image | undefined\n lastFrame: Image | undefined\n referenceImages: Array<VideoGenerationReferenceImage>\n }> {\n let image: Image | undefined\n let lastFrame: Image | undefined\n const referenceImages: Array<VideoGenerationReferenceImage> = []\n\n for (const part of parts) {\n const role = part.metadata?.role\n switch (role) {\n case 'end_frame': {\n if (lastFrame) {\n throw new Error(\n `${this.name}: Veo accepts at most one 'end_frame' image.`,\n )\n }\n lastFrame = await imagePartToVeoImage(part, this.allowUrlFetch)\n break\n }\n case 'reference':\n case 'character': {\n referenceImages.push({\n image: await imagePartToVeoImage(part, this.allowUrlFetch),\n referenceType: VideoGenerationReferenceType.ASSET,\n })\n break\n }\n case 'start_frame':\n case undefined: {\n if (image) {\n throw new Error(\n `${this.name}: Veo accepts at most one starting image; received multiple 'start_frame'/un-roled images. Use metadata.role ('end_frame', 'reference') to disambiguate the others.`,\n )\n }\n image = await imagePartToVeoImage(part, this.allowUrlFetch)\n break\n }\n case 'mask':\n case 'control':\n throw new Error(\n `${this.name}: unsupported image role \"${role}\" for Veo video generation.`,\n )\n }\n }\n\n return { image, lastFrame, referenceImages }\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n if (isInteractionsVideoModel(this.model)) {\n return await this.getInteractionsVideoStatus(jobId)\n }\n const operation = await this.getOperation(jobId)\n\n if (!operation.done) {\n return { jobId, status: 'processing' }\n }\n\n if (operation.error) {\n return {\n jobId,\n status: 'failed',\n error: operationErrorMessage(operation.error),\n }\n }\n\n // The operation can finish \"successfully\" with every sample dropped by\n // Responsible-AI filters — surface that as a failure instead of letting\n // getVideoUrl() throw on an empty response.\n const videos = operation.response?.generatedVideos ?? []\n if (videos.length === 0) {\n const reasons = operation.response?.raiMediaFilteredReasons\n return {\n jobId,\n status: 'failed',\n error: reasons?.length\n ? `Video was filtered by Responsible-AI: ${reasons.join('; ')}`\n : 'Veo returned no generated videos.',\n }\n }\n\n return { jobId, status: 'completed' }\n }\n\n /**\n * Poll an Omni background interaction. `in_progress` maps to\n * 'processing'; a `completed` interaction with no video content (e.g.\n * filtered output) is surfaced as a failure so `getVideoUrl` doesn't\n * throw on an empty response. `requires_action` also fails: the adapter\n * never sends tools, so it can only arise via\n * `previous_interaction_id` chaining onto a tool-bearing interaction —\n * and such an interaction never progresses without a client response,\n * so polling it would spin until timeout.\n */\n private async getInteractionsVideoStatus(\n jobId: string,\n ): Promise<VideoStatusResult> {\n const interaction = await this.getInteraction(jobId)\n const status = interaction.status\n\n if (status === 'in_progress') {\n return { jobId, status: 'processing' }\n }\n if (status === 'requires_action') {\n return {\n jobId,\n status: 'failed',\n error:\n 'Gemini Omni interaction is waiting on a client action (tool response), which the video jobs flow does not support.',\n }\n }\n if (status === 'completed') {\n if (!extractInteractionVideo(interaction)) {\n return {\n jobId,\n status: 'failed',\n error:\n 'Gemini Omni completed the interaction without returning a video (the output may have been filtered).',\n }\n }\n return { jobId, status: 'completed' }\n }\n return {\n jobId,\n status: 'failed',\n error: `Gemini Omni video generation ended with status \"${status}\".`,\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n if (isInteractionsVideoModel(this.model)) {\n return await this.getInteractionsVideoUrl(jobId)\n }\n const operation = await this.getOperation(jobId)\n\n if (!operation.done) {\n throw new Error(\n `Video is not ready yet. Check status first. Job ID: ${jobId}`,\n )\n }\n\n if (operation.error) {\n throw new Error(\n `Video generation failed: ${operationErrorMessage(operation.error)}`,\n )\n }\n\n const uri = operation.response?.generatedVideos?.[0]?.video?.uri\n if (!uri) {\n const reasons = operation.response?.raiMediaFilteredReasons\n throw new Error(\n reasons?.length\n ? `Video was filtered by Responsible-AI: ${reasons.join('; ')}`\n : `Video URL not found in operation response. Job ID: ${jobId}`,\n )\n }\n\n return { jobId, url: uri }\n }\n\n /**\n * Extract the finished Omni video. Inline base64 output (the API default)\n * becomes a `data:` URL — matching the OpenAI Sora adapter's inline\n * delivery — and URI delivery passes through (Files API URIs need the API\n * key to download, like Veo). Usage carries the video-modality output\n * tokens (Omni bills per second of video, reported as tokens).\n */\n private async getInteractionsVideoUrl(\n jobId: string,\n ): Promise<VideoUrlResult> {\n const interaction = await this.getInteraction(jobId)\n const status = interaction.status\n\n if (status === 'in_progress') {\n throw new Error(\n `Video is not ready yet. Check status first. Job ID: ${jobId}`,\n )\n }\n if (status !== 'completed') {\n throw new Error(\n `Video generation failed: Gemini Omni interaction ended with status \"${status}\". Job ID: ${jobId}`,\n )\n }\n\n const video = extractInteractionVideo(interaction)\n if (!video) {\n throw new Error(\n `Video not found in interaction response (the output may have been filtered). Job ID: ${jobId}`,\n )\n }\n\n const usage = interactionUsageToTokenUsage(interaction.usage)\n const url = video.uri ?? `data:${video.mimeType};base64,${video.data}`\n return { jobId, url, ...(usage && { usage }) }\n }\n\n override availableDurations(): DurationOptions<\n GeminiVideoModelDurationByName[TModel]\n > {\n return getGeminiVideoDurationOptions(this.model)\n }\n\n /**\n * Fetch the long-running operation by name. The SDK's\n * `operations.getVideosOperation` needs a real `GenerateVideosOperation`\n * instance (it calls `_fromAPIResponse` on it), so reconstruct one from\n * the job ID rather than passing an object literal.\n */\n private async getOperation(jobId: string): Promise<GenerateVideosOperation> {\n const operation = new GenerateVideosOperation()\n operation.name = jobId\n return await this.client.operations.getVideosOperation({ operation })\n }\n\n /**\n * Fetch an Omni background interaction by id.\n */\n private async getInteraction(jobId: string): Promise<Interaction> {\n return await this.client.interactions.get(jobId)\n }\n}\n\n/** @deprecated Shuts down 2026-09-30. Use `gemini-omni-1.1-flash`. */\nexport function createGeminiVideo(\n model: 'gemini-omni-flash-preview',\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<'gemini-omni-flash-preview'>\n/**\n * Creates a Gemini video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'veo-3.1-generate-preview')\n * @param apiKey - Your Google API key\n * @param config - Optional additional configuration\n * @returns Configured Gemini video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGeminiVideo('veo-3.1-generate-preview', 'your-api-key');\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A beautiful sunset over the ocean',\n * duration: adapter.snapDuration(7), // → 6\n * });\n * ```\n */\nexport function createGeminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel>\nexport function createGeminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel> {\n return new GeminiVideoAdapter({ apiKey, ...config }, model)\n}\n\n/** @deprecated Shuts down 2026-09-30. Use `gemini-omni-1.1-flash`. */\nexport function geminiVideo(\n model: 'gemini-omni-flash-preview',\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<'gemini-omni-flash-preview'>\n/**\n * Creates a Gemini video adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `GOOGLE_API_KEY` or `GEMINI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'veo-3.1-generate-preview')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Gemini video adapter instance with resolved types\n * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses GOOGLE_API_KEY from environment\n * const adapter = geminiVideo('veo-3.1-generate-preview');\n *\n * // Create a video generation job\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A cat playing piano'\n * });\n *\n * // Poll for status\n * const status = await getVideoJobStatus({ adapter, jobId });\n * ```\n */\nexport function geminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel>\nexport function geminiVideo<TModel extends GeminiVideoModel>(\n model: TModel,\n config?: Omit<GeminiVideoConfig, 'apiKey'>,\n): GeminiVideoAdapter<TModel> {\n const apiKey = getGeminiApiKeyFromEnv()\n return createGeminiVideo(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;;;AAuEA,SAAS,sBAAsB,OAAwC;CACrE,IAAI,OAAO,MAAM,YAAY,YAAY,MAAM,QAAQ,SAAS,GAC9D,OAAO,MAAM;CAEf,OAAO,KAAK,UAAU,KAAK;AAC7B;;;;;;;;;;;;;AAcA,eAAe,oBACb,MACA,eACgB;CAChB,IAAI,KAAK,OAAO,SAAS,QACvB,OAAO;EACL,YAAY,KAAK,OAAO;EACxB,UAAU,KAAK,OAAO,YAAY;CACpC;CAEF,IAAI,aAAa,KAAK,MAAM,GAG1B,MAAM,2BACJ,UACA,+GACF;CAEF,MAAM,MAAM,KAAK,OAAO;CACxB,IAAI,IAAI,WAAW,OAAO,GACxB,OAAO;EACL,QAAQ;EACR,GAAI,KAAK,OAAO,YAAY,EAAE,UAAU,KAAK,OAAO,SAAS;CAC/D;CAEF,IAAI,IAAI,WAAW,OAAO,GAAG;EAC3B,MAAM,QAAQ,IAAI,MAAM,iCAAiC;EACzD,IAAI,CAAC,SAAS,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IAAI,wBAAwB;EAC9C,UAAU,OAAO;EACjB,OAAO,MAAM,KAAK,OAAO,WAAW,mBAAmB,EAAE,UAAU,CAAC;CACtE;;;;CAKA,MAAc,eAAe,OAAqC;EAChE,OAAO,MAAM,KAAK,OAAO,aAAa,IAAI,KAAK;CACjD;AACF;AAmCA,SAAgB,kBACd,OACA,QACA,QAC4B;CAC5B,OAAO,IAAI,mBAAmB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC5D;AAyCA,SAAgB,YACd,OACA,QAC4B;CAE5B,OAAO,kBAAkB,OADV,uBACiB,GAAQ,MAAM;AAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-gemini",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.2",
|
|
4
4
|
"description": "Google Gemini adapter for TanStack AI chat, images, speech, audio generation, and structured outputs.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"@tanstack/ai-utils": "^0.4.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@tanstack/ai": "^0.
|
|
66
|
+
"@tanstack/ai": "^0.64.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@vitest/coverage-v8": "4.1.10",
|
|
70
70
|
"vite": "^8.2.1",
|
|
71
71
|
"zod": "^4.2.0",
|
|
72
|
-
"@tanstack/ai": "0.
|
|
72
|
+
"@tanstack/ai": "0.64.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "vite build",
|
package/src/adapters/video.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
resolveMediaPrompt,
|
|
9
9
|
unsupportedFileSourceError,
|
|
10
10
|
} from '@tanstack/ai'
|
|
11
|
-
import { BaseVideoAdapter
|
|
11
|
+
import { BaseVideoAdapter } from '@tanstack/ai/adapters'
|
|
12
12
|
import { arrayBufferToBase64 } from '@tanstack/ai-utils'
|
|
13
13
|
import { createGeminiClient, getGeminiApiKeyFromEnv } from '../utils'
|
|
14
14
|
import {
|
|
@@ -666,12 +666,6 @@ export class GeminiVideoAdapter<
|
|
|
666
666
|
return getGeminiVideoDurationOptions(this.model)
|
|
667
667
|
}
|
|
668
668
|
|
|
669
|
-
override snapDuration(
|
|
670
|
-
seconds: number,
|
|
671
|
-
): GeminiVideoModelDurationByName[TModel] | undefined {
|
|
672
|
-
return snapToDurationOption(seconds, this.availableDurations())
|
|
673
|
-
}
|
|
674
|
-
|
|
675
669
|
/**
|
|
676
670
|
* Fetch the long-running operation by name. The SDK's
|
|
677
671
|
* `operations.getVideosOperation` needs a real `GenerateVideosOperation`
|