(
params: GenerateVideoArgs,
context?: ServerToolContext
)
| 44 | name: GenerateVideo.id, |
| 45 | |
| 46 | async execute( |
| 47 | params: GenerateVideoArgs, |
| 48 | context?: ServerToolContext |
| 49 | ): Promise<GenerateVideoResult> { |
| 50 | if (!context?.userId) { |
| 51 | throw new Error('Authentication required') |
| 52 | } |
| 53 | const workspaceId = context.workspaceId |
| 54 | if (!workspaceId) { |
| 55 | return { success: false, message: 'Workspace ID is required' } |
| 56 | } |
| 57 | if (!params.prompt) { |
| 58 | return { success: false, message: 'prompt is required' } |
| 59 | } |
| 60 | |
| 61 | try { |
| 62 | let imageDataUri: string | undefined |
| 63 | const refPath = params.inputs?.files?.[0]?.path |
| 64 | if (refPath) { |
| 65 | const fileRecord = await resolveWorkspaceFileReference(workspaceId, refPath) |
| 66 | if (!fileRecord) { |
| 67 | return { success: false, message: `Reference image not found: ${refPath}` } |
| 68 | } |
| 69 | const buffer = await fetchWorkspaceFileBuffer(fileRecord) |
| 70 | const mime = fileRecord.type || 'image/png' |
| 71 | imageDataUri = `data:${mime};base64,${buffer.toString('base64')}` |
| 72 | } |
| 73 | |
| 74 | logger.info('Generating video', { |
| 75 | model: params.model || 'veo-3.1-fast', |
| 76 | promptLength: params.prompt.length, |
| 77 | imageToVideo: Boolean(imageDataUri), |
| 78 | }) |
| 79 | |
| 80 | const result = await generateFalVideo({ |
| 81 | prompt: params.prompt, |
| 82 | model: params.model, |
| 83 | aspectRatio: params.aspectRatio, |
| 84 | resolution: params.resolution, |
| 85 | duration: params.duration, |
| 86 | generateAudio: params.generateAudio, |
| 87 | negativePrompt: params.negativePrompt, |
| 88 | promptOptimizer: params.promptOptimizer, |
| 89 | imageDataUri, |
| 90 | }) |
| 91 | |
| 92 | const outputFile = params.outputs?.files?.[0] |
| 93 | const outputPath = outputFile?.path || 'files/generated-video.mp4' |
| 94 | const mode = outputFile?.mode ?? 'create' |
| 95 | |
| 96 | assertServerToolNotAborted(context) |
| 97 | const written = await writeWorkspaceFileByPath({ |
| 98 | workspaceId, |
| 99 | userId: context.userId, |
| 100 | target: { path: outputPath, mode, mimeType: outputFile?.mimeType }, |
| 101 | buffer: result.buffer, |
| 102 | inferredMimeType: result.contentType, |
| 103 | }) |
nothing calls this directly
no test coverage detected