Skip to content

🎥 Make videos programmatically with React

Add multi-image attachment support and improve image UX

ASchwadc7b7d42c3f87
diff --git a/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts b/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
index accd5bcc3d..6918fc64c8 100644
--- a/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
+++ b/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
@@ -273,8 +273,8 @@ interface GenerateRequest {
errorCorrection?: ErrorCorrectionContext;
/** Skills already used in this conversation (to avoid redundant skill content) */
previouslyUsedSkills?: string[];
- /** Base64 image data URL for visual context */
- frameImage?: string;
+ /** Base64 image data URLs for visual context */
+ frameImages?: string[];
}
interface GenerateResponse {
@@ -298,7 +298,7 @@ export async function POST(req: Request) {
hasManualEdits = false,
errorCorrection,
previouslyUsedSkills = [],
- frameImage,
+ frameImages,
}: GenerateRequest = await req.json();
const apiKey = process.env.OPENAI_API_KEY;
@@ -455,7 +455,7 @@ ${errorCorrectionNotice}
## USER REQUEST:
${prompt}
-${frameImage ? "\n(See the attached image for visual reference)" : ""}
+${frameImages && frameImages.length > 0 ? `\n(See the attached ${frameImages.length === 1 ? "image" : "images"} for visual reference)` : ""}
Analyze the request and decide: use targeted edits (type: "edit") for small changes, or full replacement (type: "full") for major restructuring.`;
@@ -466,22 +466,25 @@ Analyze the request and decide: use targeted edits (type: "edit") for small chan
modelName,
"skills:",
detectedSkills.length > 0 ? detectedSkills.join(", ") : "general",
- frameImage ? "(with image)" : ""
+ frameImages && frameImages.length > 0 ? `(with ${frameImages.length} image(s))` : ""
);
- // Build messages array - include image if provided
+ // Build messages array - include images if provided
+ const editMessageContent: Array<{ type: "text"; text: string } | { type: "image"; image: string }> = [
+ { type: "text" as const, text: editPromptText },
+ ];
+ if (frameImages && frameImages.length > 0) {
+ for (const img of frameImages) {
+ editMessageContent.push({ type: "image" as const, image: img });
+ }
+ }
const editMessages: Array<{
role: "user";
content: Array<{ type: "text"; text: string } | { type: "image"; image: string }>;
}> = [
{
role: "user" as const,
- content: frameImage
- ? [
- { type: "text" as const, text: editPromptText },
- { type: "image" as const, image: frameImage },
- ]
- : [{ type: "text" as const, text: editPromptText }],
+ content: editMessageContent,
},
];
@@ -561,23 +564,28 @@ Analyze the request and decide: use targeted edits (type: "edit") for small chan
// INITIAL GENERATION: Use streaming for new animations
try {
- // Build messages for initial generation (supports image reference)
- const initialPromptText = frameImage
- ? `${prompt}\n\n(See the attached image for visual reference)`
+ // Build messages for initial generation (supports image references)
+ const hasImages = frameImages && frameImages.length > 0;
+ const initialPromptText = hasImages
+ ? `${prompt}\n\n(See the attached ${frameImages.length === 1 ? "image" : "images"} for visual reference)`
: prompt;
+ const initialMessageContent: Array<{ type: "text"; text: string } | { type: "image"; image: string }> = [
+ { type: "text" as const, text: initialPromptText },
+ ];
+ if (hasImages) {
+ for (const img of frameImages) {
+ initialMessageContent.push({ type: "image" as const, image: img });
+ }
+ }
+
const initialMessages: Array<{
role: "user";
content: Array<{ type: "text"; text: string } | { type: "image"; image: string }>;
}> = [
{
role: "user" as const,
- content: frameImage
- ? [
- { type: "text" as const, text: initialPromptText },
- { type: "image" as const, image: frameImage },
- ]
- : [{ type: "text" as const, text: initialPromptText }],
+ content: initialMessageContent,
},
];
@@ -602,7 +610,7 @@ Analyze the request and decide: use targeted edits (type: "edit") for small chan
"skills:",
detectedSkills.length > 0 ? detectedSkills.join(", ") : "general",
reasoningEffort ? `reasoning_effort: ${reasoningEffort}` : "",
- frameImage ? "(with image)" : ""
+ hasImages ? `(with ${frameImages.length} image(s))` : ""
);
// Get the original stream response
diff --git a/packages/template-prompt-to-motion-graphics/src/app/generate/page.tsx b/packages/template-prompt-to-motion-graphics/src/app/generate/page.tsx
index 8cb6887ffd..9e52662372 100644
--- a/packages/template-prompt-to-motion-graphics/src/app/generate/page.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/app/generate/page.tsx
@@ -157,8 +157,8 @@ function GeneratePageContent() {
// Handle message sent for history
const handleMessageSent = useCallback(
- (promptText: string, attachedImage?: string) => {
- addUserMessage(promptText, attachedImage);
+ (promptText: string, attachedImages?: string[]) => {
+ addUserMessage(promptText, attachedImages);
},
[addUserMessage],
);
@@ -214,13 +214,19 @@ function GeneratePageContent() {
useEffect(() => {
if (initialPrompt && !hasAutoStarted && chatSidebarRef.current) {
setHasAutoStarted(true);
- // Check for initial attached image from sessionStorage
- const storedImage = sessionStorage.getItem("initialAttachedImage");
- if (storedImage) {
- sessionStorage.removeItem("initialAttachedImage");
+ // Check for initial attached images from sessionStorage
+ const storedImagesJson = sessionStorage.getItem("initialAttachedImages");
+ let storedImages: string[] | undefined;
+ if (storedImagesJson) {
+ try {
+ storedImages = JSON.parse(storedImagesJson);
+ } catch {
+ // Ignore parse errors
+ }
+ sessionStorage.removeItem("initialAttachedImages");
}
setTimeout(() => {
- chatSidebarRef.current?.triggerGeneration({ attachedImage: storedImage ?? undefined });
+ chatSidebarRef.current?.triggerGeneration({ attachedImages: storedImages });
}, 100);
}
}, [initialPrompt, hasAutoStarted]);
diff --git a/packages/template-prompt-to-motion-graphics/src/app/page.tsx b/packages/template-prompt-to-motion-graphics/src/app/page.tsx
index 708c55a343..8f3f8b3d09 100644
--- a/packages/template-prompt-to-motion-graphics/src/app/page.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/app/page.tsx
@@ -11,13 +11,13 @@ const Home: NextPage = () => {
const router = useRouter();
const [isNavigating, setIsNavigating] = useState(false);
- const handleNavigate = (prompt: string, model: ModelId, attachedImage?: string) => {
+ const handleNavigate = (prompt: string, model: ModelId, attachedImages?: string[]) => {
setIsNavigating(true);
- // Store image in sessionStorage (too large for URL params)
- if (attachedImage) {
- sessionStorage.setItem("initialAttachedImage", attachedImage);
+ // Store images in sessionStorage (too large for URL params)
+ if (attachedImages && attachedImages.length > 0) {
+ sessionStorage.setItem("initialAttachedImages", JSON.stringify(attachedImages));
} else {
- sessionStorage.removeItem("initialAttachedImage");
+ sessionStorage.removeItem("initialAttachedImages");
}
const params = new URLSearchParams({ prompt, model });
router.push(`/generate?${params.toString()}`);
diff --git a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx
index 7637926274..d38873eaf8 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatInput.tsx
@@ -1,7 +1,7 @@
"use client";
-import { useState, type ComponentType, type DragEvent } from "react";
-import { ArrowUp, Camera, X } from "lucide-react";
+import { useState, useRef, type ComponentType, type DragEvent, type ChangeEvent } from "react";
+import { ArrowUp, Camera, X, Paperclip } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Select,
@@ -13,13 +13,15 @@ import {
import { type ModelId, MODELS } from "@/types/generation";
import { captureFrame, fileToBase64 } from "@/helpers/capture-frame";
+const MAX_ATTACHED_IMAGES = 4;
+
interface ChatInputProps {
prompt: string;
onPromptChange: (prompt: string) => void;
model: ModelId;
onModelChange: (model: ModelId) => void;
isLoading: boolean;
- onSubmit: (attachedImage?: string) => void;
+ onSubmit: (attachedImages?: string[]) => void;
// Frame capture props
Component?: ComponentType | null;
fps?: number;
@@ -39,15 +41,35 @@ export function ChatInput({
durationInFrames = 150,
currentFrame = 0,
}: ChatInputProps) {
- const [attachedImage, setAttachedImage] = useState<string | null>(null);
+ const [attachedImages, setAttachedImages] = useState<string[]>([]);
const [isCapturing, setIsCapturing] = useState(false);
const [isDragging, setIsDragging] = useState(false);
+ const fileInputRef = useRef<HTMLInputElement>(null);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!prompt.trim()) return;
- onSubmit(attachedImage ?? undefined);
- setAttachedImage(null); // Clear after submit
+ onSubmit(attachedImages.length > 0 ? attachedImages : undefined);
+ setAttachedImages([]); // Clear after submit
+ };
+
+ const addImages = (newImages: string[]) => {
+ setAttachedImages((prev) => {
+ const combined = [...prev, ...newImages];
+ return combined.slice(0, MAX_ATTACHED_IMAGES);
+ });
+ };
+
+ const removeImage = (index: number) => {
+ setAttachedImages((prev) => prev.filter((_, i) => i !== index));
+ };
+
+ const handleFileSelect = async (e: ChangeEvent<HTMLInputElement>) => {
+ const files = Array.from(e.target.files || []);
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
+ const base64Images = await Promise.all(imageFiles.map(fileToBase64));
+ addImages(base64Images);
+ e.target.value = "";
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
@@ -59,7 +81,7 @@ export function ChatInput({
};
const handleCapture = async () => {
- if (!Component || isCapturing) return;
+ if (!Component || isCapturing || attachedImages.length >= MAX_ATTACHED_IMAGES) return;
setIsCapturing(true);
try {
@@ -69,7 +91,7 @@ export function ChatInput({
fps,
durationInFrames,
});
- setAttachedImage(base64);
+ addImages([base64]);
} catch (error) {
console.error("Failed to capture frame:", error);
} finally {
@@ -79,16 +101,14 @@ export function ChatInput({
const handlePaste = async (e: React.ClipboardEvent) => {
const items = Array.from(e.clipboardData.items);
- for (const item of items) {
- if (item.type.startsWith("image/")) {
- e.preventDefault();
- const file = item.getAsFile();
- if (file) {
- const base64 = await fileToBase64(file);
- setAttachedImage(base64);
- }
- break;
- }
+ const imageItems = items.filter((item) => item.type.startsWith("image/"));
+ if (imageItems.length > 0) {
+ e.preventDefault();
+ const files = imageItems
+ .map((item) => item.getAsFile())
+ .filter((f): f is File => f !== null);
+ const base64Images = await Promise.all(files.map(fileToBase64));
+ addImages(base64Images);
}
};
@@ -107,16 +127,12 @@ export function ChatInput({
setIsDragging(false);
const files = Array.from(e.dataTransfer.files);
- for (const file of files) {
- if (file.type.startsWith("image/")) {
- const base64 = await fileToBase64(file);
- setAttachedImage(base64);
- break;
- }
- }
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
+ const base64Images = await Promise.all(imageFiles.map(fileToBase64));
+ addImages(base64Images);
};
- const canCapture = Component && !isLoading && !isCapturing;
+ const canCapture = Component && !isLoading && !isCapturing && attachedImages.length < MAX_ATTACHED_IMAGES;
return (
<div className="p-4">
@@ -129,22 +145,26 @@ export function ChatInput({
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
- {/* Image preview */}
- {attachedImage && (
- <div className="mb-2 relative inline-block">
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img
- src={attachedImage}
- alt="Attached"
- className="h-16 w-auto rounded border border-border object-cover"
- />
- <button
- type="button"
- onClick={() => setAttachedImage(null)}
- className="absolute -top-1.5 -right-1.5 bg-background border border-border rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors"
- >
- <X className="w-3 h-3" />
- </button>
+ {/* Image previews */}
+ {attachedImages.length > 0 && (
+ <div className="mb-2 flex gap-2 overflow-x-auto pb-1 pt-2">
+ {attachedImages.map((img, index) => (
+ <div key={index} className="relative flex-shrink-0">
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ src={img}
+ alt={`Attached ${index + 1}`}
+ className="h-16 w-auto rounded border border-border object-cover"
+ />
+ <button
+ type="button"
+ onClick={() => removeImage(index)}
+ className="absolute -top-1.5 -right-1.5 bg-background border border-border rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors"
+ >
+ <X className="w-3 h-3" />
+ </button>
+ </div>
+ ))}
</div>
)}
@@ -154,12 +174,22 @@ export function ChatInput({
onKeyDown={handleKeyDown}
onPaste={handlePaste}
placeholder={
- isDragging ? "Drop image here..." : "Tune your animation..."
+ isDragging ? "Drop images here..." : "Tune your animation... (paste or drop images)"
}
className="w-full bg-transparent text-foreground placeholder:text-muted-foreground-dim focus:outline-none resize-none text-sm min-h-[36px] max-h-[120px]"
style={{ fieldSizing: "content" } as React.CSSProperties}
disabled={isLoading}
/>
+ {/* Hidden file input */}
+ <input
+ ref={fileInputRef}
+ type="file"
+ accept="image/*"
+ multiple
+ onChange={handleFileSelect}
+ className="hidden"
+ />
+
<div className="flex justify-between items-center mt-2 pt-2 border-t border-border/50">
<Select
value={model}
@@ -187,12 +217,25 @@ export function ChatInput({
type="button"
variant="ghost"
size="icon-sm"
+ onClick={() => fileInputRef.current?.click()}
+ disabled={isLoading || attachedImages.length >= MAX_ATTACHED_IMAGES}
+ className="text-muted-foreground hover:text-foreground h-7 w-7"
+ title="Attach images"
+ >
+ <Paperclip className="w-4 h-4" />
+ </Button>
+
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
disabled={!canCapture}
onClick={handleCapture}
- className="text-muted-foreground hover:text-foreground h-7 w-7"
- title="Capture current frame"
+ className="text-muted-foreground hover:text-foreground h-7 px-2 text-xs"
+ title="Use current frame of Preview as image in chat"
>
- <Camera className="w-4 h-4" />
+ <Camera className="w-3.5 h-3.5 mr-1" />
+ Use Frame
</Button>
<Button
diff --git a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatSidebar.tsx b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatSidebar.tsx
index 83d48eb5e5..2b2290d616 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatSidebar.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/ChatSidebar/ChatSidebar.tsx
@@ -41,7 +41,7 @@ import { ChatInput } from "./ChatInput";
import { useGenerationApi } from "@/hooks/useGenerationApi";
export interface ChatSidebarRef {
- triggerGeneration: (options?: { silent?: boolean; attachedImage?: string }) => void;
+ triggerGeneration: (options?: { silent?: boolean; attachedImages?: string[] }) => void;
}
interface ChatSidebarProps {
@@ -64,7 +64,7 @@ interface ChatSidebarProps {
conversationHistory?: ConversationContextMessage[];
previouslyUsedSkills?: string[];
isFollowUp?: boolean;
- onMessageSent?: (prompt: string, attachedImage?: string) => void;
+ onMessageSent?: (prompt: string, attachedImages?: string[]) => void;
onGenerationComplete?: (
code: string,
summary?: string,
@@ -136,7 +136,7 @@ export const ChatSidebar = forwardRef<ChatSidebarRef, ChatSidebarProps>(
const handleGeneration = async (options?: {
silent?: boolean;
- attachedImage?: string;
+ attachedImages?: string[];
}) => {
const currentPrompt = promptRef.current;
if (!currentPrompt.trim()) return;
@@ -153,7 +153,7 @@ export const ChatSidebar = forwardRef<ChatSidebarRef, ChatSidebarProps>(
isFollowUp,
hasManualEdits,
errorCorrection,
- frameImage: options?.attachedImage,
+ frameImages: options?.attachedImages,
},
{
onCodeGenerated,
@@ -248,8 +248,8 @@ export const ChatSidebar = forwardRef<ChatSidebarRef, ChatSidebarProps>(
model={model}
onModelChange={setModel}
isLoading={isLoading}
- onSubmit={(attachedImage) =>
- handleGeneration({ attachedImage })
+ onSubmit={(attachedImages) =>
+ handleGeneration({ attachedImages })
}
Component={Component}
fps={fps}
@@ -282,13 +282,18 @@ function ChatMessage({ message }: { message: ConversationMessage }) {
</div>
<div className="text-sm text-foreground leading-relaxed bg-secondary/50 rounded-lg px-3 py-2">
{message.content}
- {message.attachedImage && (
- // eslint-disable-next-line @next/next/no-img-element
- <img
- src={message.attachedImage}
- alt="Attached"
- className="h-20 w-auto rounded border border-border object-cover mt-2"
- />
+ {message.attachedImages && message.attachedImages.length > 0 && (
+ <div className="flex gap-2 mt-2 overflow-x-auto">
+ {message.attachedImages.map((img, index) => (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img
+ key={index}
+ src={img}
+ alt={`Attached ${index + 1}`}
+ className="h-20 w-auto rounded border border-border object-cover flex-shrink-0"
+ />
+ ))}
+ </div>
)}
</div>
</div>
diff --git a/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx
index b5ba240042..e00dd063a1 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useState, type DragEvent } from "react";
+import { useState, useRef, type DragEvent, type ChangeEvent } from "react";
import Link from "next/link";
import {
ArrowUp,
@@ -11,6 +11,7 @@ import {
BarChart3,
Disc,
X,
+ Paperclip,
type LucideIcon,
} from "lucide-react";
import { fileToBase64 } from "@/helpers/capture-frame";
@@ -33,8 +34,10 @@ const iconMap: Record<string, LucideIcon> = {
Disc,
};
+const MAX_ATTACHED_IMAGES = 4;
+
interface LandingPageInputProps {
- onNavigate: (prompt: string, model: ModelId, attachedImage?: string) => void;
+ onNavigate: (prompt: string, model: ModelId, attachedImages?: string[]) => void;
isNavigating?: boolean;
showCodeExamplesLink?: boolean;
}
@@ -46,13 +49,34 @@ export function LandingPageInput({
}: LandingPageInputProps) {
const [prompt, setPrompt] = useState("");
const [model, setModel] = useState<ModelId>("gpt-5.2:medium");
- const [attachedImage, setAttachedImage] = useState<string | null>(null);
+ const [attachedImages, setAttachedImages] = useState<string[]>([]);
const [isDragging, setIsDragging] = useState(false);
+ const fileInputRef = useRef<HTMLInputElement>(null);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!prompt.trim() || isNavigating) return;
- onNavigate(prompt, model, attachedImage ?? undefined);
+ onNavigate(prompt, model, attachedImages.length > 0 ? attachedImages : undefined);
+ };
+
+ const addImages = (newImages: string[]) => {
+ setAttachedImages((prev) => {
+ const combined = [...prev, ...newImages];
+ return combined.slice(0, MAX_ATTACHED_IMAGES);
+ });
+ };
+
+ const removeImage = (index: number) => {
+ setAttachedImages((prev) => prev.filter((_, i) => i !== index));
+ };
+
+ const handleFileSelect = async (e: ChangeEvent<HTMLInputElement>) => {
+ const files = Array.from(e.target.files || []);
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
+ const base64Images = await Promise.all(imageFiles.map(fileToBase64));
+ addImages(base64Images);
+ // Reset input so same file can be selected again
+ e.target.value = "";
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
@@ -65,16 +89,14 @@ export function LandingPageInput({
const handlePaste = async (e: React.ClipboardEvent) => {
const items = Array.from(e.clipboardData.items);
- for (const item of items) {
- if (item.type.startsWith("image/")) {
- e.preventDefault();
- const file = item.getAsFile();
- if (file) {
- const base64 = await fileToBase64(file);
- setAttachedImage(base64);
- }
- break;
- }
+ const imageItems = items.filter((item) => item.type.startsWith("image/"));
+ if (imageItems.length > 0) {
+ e.preventDefault();
+ const files = imageItems
+ .map((item) => item.getAsFile())
+ .filter((f): f is File => f !== null);
+ const base64Images = await Promise.all(files.map(fileToBase64));
+ addImages(base64Images);
}
};
@@ -93,13 +115,9 @@ export function LandingPageInput({
setIsDragging(false);
const files = Array.from(e.dataTransfer.files);
- for (const file of files) {
- if (file.type.startsWith("image/")) {
- const base64 = await fileToBase64(file);
- setAttachedImage(base64);
- break;
- }
- }
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
+ const base64Images = await Promise.all(imageFiles.map(fileToBase64));
+ addImages(base64Images);
};
return (
@@ -117,22 +135,26 @@ export function LandingPageInput({
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
- {/* Image preview */}
- {attachedImage && (
- <div className="mb-3 relative inline-block">
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img
- src={attachedImage}
- alt="Attached"
- className="h-20 w-auto rounded border border-border object-cover"
- />
- <button
- type="button"
- onClick={() => setAttachedImage(null)}
- className="absolute -top-1.5 -right-1.5 bg-background border border-border rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors"
- >
- <X className="w-3 h-3" />
- </button>
+ {/* Image previews */}
+ {attachedImages.length > 0 && (
+ <div className="mb-3 flex gap-2 overflow-x-auto pb-1 pt-2">
+ {attachedImages.map((img, index) => (
+ <div key={index} className="relative flex-shrink-0">
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ src={img}
+ alt={`Attached ${index + 1}`}
+ className="h-20 w-auto rounded border border-border object-cover"
+ />
+ <button
+ type="button"
+ onClick={() => removeImage(index)}
+ className="absolute -top-1.5 -right-1.5 bg-background border border-border rounded-full p-0.5 hover:bg-destructive hover:text-destructive-foreground transition-colors"
+ >
+ <X className="w-3 h-3" />
+ </button>
+ </div>
+ ))}
</div>
)}
@@ -141,12 +163,22 @@ export function LandingPageInput({
onChange={(e) => setPrompt(e.target.value)}
onKeyDown={handleKeyDown}
onPaste={handlePaste}
- placeholder={isDragging ? "Drop image here..." : "Describe your animation..."}
+ placeholder={isDragging ? "Drop images here..." : "Describe your animation... (paste or drop images)"}
className="w-full bg-transparent text-foreground placeholder:text-muted-foreground-dim focus:outline-none resize-none overflow-y-auto text-base min-h-[60px] max-h-[200px]"
style={{ fieldSizing: "content" }}
disabled={isNavigating}
/>
+ {/* Hidden file input */}
+ <input
+ ref={fileInputRef}
+ type="file"
+ accept="image/*"
+ multiple
+ onChange={handleFileSelect}
+ className="hidden"
+ />
+
<div className="flex justify-between items-center mt-3 pt-3 border-t border-border">
<Select
value={model}
@@ -169,19 +201,33 @@ export function LandingPageInput({
</SelectContent>
</Select>
- <Button
- type="submit"
- size="icon-sm"
- disabled={!prompt.trim() || isNavigating}
- loading={isNavigating}
- className="bg-foreground text-background hover:bg-gray-200"
- >
- <ArrowUp className="w-5 h-5" />
- </Button>
+ <div className="flex items-center gap-1">
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-sm"
+ onClick={() => fileInputRef.current?.click()}
+ disabled={isNavigating || attachedImages.length >= MAX_ATTACHED_IMAGES}
+ className="text-muted-foreground hover:text-foreground"
+ title="Attach images"
+ >
+ <Paperclip className="w-5 h-5" />
+ </Button>
+
+ <Button
+ type="submit"
+ size="icon-sm"
+ disabled={!prompt.trim() || isNavigating}
+ loading={isNavigating}
+ className="bg-foreground text-background hover:bg-gray-200"
+ >
+ <ArrowUp className="w-5 h-5" />
+ </Button>
+ </div>
</div>
</div>
- <div className="flex flex-wrap items-center gap-1.5 mt-3 justify-center mt-6 gap-2">
+ <div className="flex flex-wrap items-center justify-center mt-6 gap-2">
<span className="text-muted-foreground-dim text-xs mr-1">
Prompt Examples
</span>
diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
index c6f88a6415..73de894ff2 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
@@ -18,13 +18,13 @@ export function useConversationState() {
// Track the last AI-generated code to detect manual edits
const lastAiCodeRef = useRef<string>("");
- const addUserMessage = useCallback((content: string, attachedImage?: string) => {
+ const addUserMessage = useCallback((content: string, attachedImages?: string[]) => {
const message: ConversationMessage = {
id: `user-${Date.now()}`,
role: "user",
content,
timestamp: Date.now(),
- attachedImage,
+ attachedImages,
};
setState((prev) => ({
...prev,
diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts
index 2e286d3f24..d5731901c2 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts
@@ -22,7 +22,7 @@ interface GenerationCallbacks {
onStreamingChange?: (isStreaming: boolean) => void;
onStreamPhaseChange?: (phase: StreamPhase) => void;
onError?: (error: string, type: GenerationErrorType, failedEdit?: FailedEditInfo) => void;
- onMessageSent?: (prompt: string, attachedImage?: string) => void;
+ onMessageSent?: (prompt: string, attachedImages?: string[]) => void;
onGenerationComplete?: (
code: string,
summary?: string,
@@ -44,7 +44,7 @@ interface GenerationContext {
isFollowUp: boolean;
hasManualEdits: boolean;
errorCorrection?: ErrorCorrectionContext;
- frameImage?: string;
+ frameImages?: string[];
}
interface UseGenerationApiReturn {
@@ -78,7 +78,7 @@ export function useGenerationApi(): UseGenerationApiReturn {
isFollowUp,
hasManualEdits,
errorCorrection,
- frameImage,
+ frameImages,
} = context;
const {
@@ -99,7 +99,7 @@ export function useGenerationApi(): UseGenerationApiReturn {
// Only add user message if not a silent retry
if (!options?.silent) {
- onMessageSent?.(prompt, frameImage);
+ onMessageSent?.(prompt, frameImages);
}
try {
@@ -115,7 +115,7 @@ export function useGenerationApi(): UseGenerationApiReturn {
isFollowUp,
hasManualEdits,
errorCorrection,
- frameImage,
+ frameImages,
}),
});
diff --git a/packages/template-prompt-to-motion-graphics/src/types/conversation.ts b/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
index 9806b3c7c4..814bd9fcf5 100644
--- a/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
+++ b/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
@@ -21,8 +21,8 @@ export interface ConversationMessage {
role: "user" | "assistant" | "error";
content: string;
timestamp: number;
- /** For user messages, store attached image as base64 data URL */
- attachedImage?: string;
+ /** For user messages, store attached images as base64 data URLs */
+ attachedImages?: string[];
/** For assistant messages, store the code snapshot at time of generation */
codeSnapshot?: string;
/** For assistant messages, store metadata about the generation */