Skip to content

🎥 Make videos programmatically with React

Move chat input into sidebar and improve chat UX

ASchwad35f66d5c552c
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 b7211254d0..ccac8a46c2 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
@@ -7,11 +7,9 @@ import { Loader2 } from "lucide-react";
import { CodeEditor } from "../../components/CodeEditor";
import { AnimationPlayer } from "../../components/AnimationPlayer";
import { PageLayout } from "../../components/PageLayout";
-import { ChatHistory } from "../../components/ChatHistory";
+import { ChatHistory, type ChatHistoryRef } from "../../components/ChatHistory";
import {
- PromptInput,
type StreamPhase,
- type PromptInputRef,
type GenerationErrorType,
} from "../../components/PromptInput";
import { examples } from "../../examples/code";
@@ -59,7 +57,6 @@ function GeneratePageContent() {
addAssistantMessage,
addErrorMessage,
markManualEdit,
- clearConversation,
getRecentContext,
isFirstGeneration,
} = useConversationState();
@@ -132,7 +129,7 @@ function GeneratePageContent() {
// Trigger generation after a short delay
setTimeout(() => {
- promptInputRef.current?.triggerGeneration();
+ chatHistoryRef.current?.triggerGeneration();
}, 100);
}
}
@@ -192,7 +189,7 @@ function GeneratePageContent() {
// Handle generation complete for history
const handleGenerationComplete = useCallback(
(generatedCode: string, summary?: string, metadata?: AssistantMetadata) => {
- const content = summary || "Generated animation";
+ const content = summary || "Generated your animation, any follow up edits?";
addAssistantMessage(content, generatedCode, metadata);
},
[addAssistantMessage],
@@ -223,14 +220,14 @@ function GeneratePageContent() {
);
// Auto-trigger generation if prompt came from URL
- const promptInputRef = useRef<PromptInputRef>(null);
+ const chatHistoryRef = useRef<ChatHistoryRef>(null);
useEffect(() => {
- if (initialPrompt && !hasAutoStarted && promptInputRef.current) {
+ if (initialPrompt && !hasAutoStarted && chatHistoryRef.current) {
setHasAutoStarted(true);
// Small delay to ensure component is mounted
setTimeout(() => {
- promptInputRef.current?.triggerGeneration();
+ chatHistoryRef.current?.triggerGeneration();
}, 100);
}
}, [initialPrompt, hasAutoStarted]);
@@ -240,11 +237,25 @@ function GeneratePageContent() {
<div className="flex-1 flex min-w-0 overflow-hidden">
{/* Chat History Sidebar */}
<ChatHistory
+ ref={chatHistoryRef}
messages={messages}
isCollapsed={isSidebarCollapsed}
onToggleCollapse={() => setIsSidebarCollapsed(!isSidebarCollapsed)}
- onClear={clearConversation}
hasManualEdits={hasManualEdits}
+ // PromptInput props for embedded input
+ onCodeGenerated={handleCodeChange}
+ onStreamingChange={handleStreamingChange}
+ onStreamPhaseChange={setStreamPhase}
+ onError={handleError}
+ prompt={prompt}
+ onPromptChange={setPrompt}
+ currentCode={code}
+ conversationHistory={getRecentContext(3)}
+ isFollowUp={!isFirstGeneration}
+ onMessageSent={handleMessageSent}
+ onGenerationComplete={handleGenerationComplete}
+ onErrorMessage={addErrorMessage}
+ errorCorrection={errorCorrection ?? undefined}
/>
{/* Main content area */}
@@ -271,24 +282,6 @@ function GeneratePageContent() {
/>
</div>
</div>
-
- <PromptInput
- ref={promptInputRef}
- onCodeGenerated={handleCodeChange}
- onStreamingChange={handleStreamingChange}
- onStreamPhaseChange={setStreamPhase}
- onError={handleError}
- prompt={prompt}
- onPromptChange={setPrompt}
- currentCode={code}
- conversationHistory={getRecentContext(3)}
- isFollowUp={!isFirstGeneration}
- hasManualEdits={hasManualEdits}
- onMessageSent={handleMessageSent}
- onGenerationComplete={handleGenerationComplete}
- onErrorMessage={addErrorMessage}
- errorCorrection={errorCorrection ?? undefined}
- />
</div>
</div>
</PageLayout>
diff --git a/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/ChatHistory.tsx b/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/ChatHistory.tsx
index d62d2f0dbe..f8a098ee65 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/ChatHistory.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/ChatHistory.tsx
@@ -1,212 +1,478 @@
"use client";
import {
- MessageSquare,
- ChevronLeft,
- ChevronRight,
- Trash2,
- Pencil,
+ useState,
+ forwardRef,
+ useImperativeHandle,
+ useRef,
+ useEffect,
+} from "react";
+import {
+ PanelLeftClose,
+ PanelLeftOpen,
+ RotateCcw,
FileCode,
- CheckCircle2,
AlertTriangle,
+ PenLine,
+ ArrowUp,
+ BookOpen,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
-import type { ConversationMessage } from "@/types/conversation";
+import type {
+ ConversationMessage,
+ ConversationContextMessage,
+ AssistantMetadata,
+ ErrorCorrectionContext,
+} from "@/types/conversation";
+import {
+ type StreamPhase,
+ type GenerationErrorType,
+ type ModelId,
+ MODELS,
+} from "../PromptInput";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import {
+ validateGptResponse,
+ extractComponentCode,
+} from "@/helpers/sanitize-response";
+
+export interface ChatHistoryRef {
+ triggerGeneration: () => void;
+}
interface ChatHistoryProps {
messages: ConversationMessage[];
isCollapsed: boolean;
onToggleCollapse: () => void;
- onClear: () => void;
hasManualEdits: boolean;
+ // PromptInput props for embedded chat input
+ onCodeGenerated?: (code: string) => void;
+ onStreamingChange?: (isStreaming: boolean) => void;
+ onStreamPhaseChange?: (phase: StreamPhase) => void;
+ onError?: (error: string, type: GenerationErrorType) => void;
+ prompt?: string;
+ onPromptChange?: (prompt: string) => void;
+ currentCode?: string;
+ conversationHistory?: ConversationContextMessage[];
+ isFollowUp?: boolean;
+ onMessageSent?: (prompt: string) => void;
+ onGenerationComplete?: (
+ code: string,
+ summary?: string,
+ metadata?: AssistantMetadata,
+ ) => void;
+ onErrorMessage?: (
+ message: string,
+ errorType: "edit_failed" | "api" | "validation",
+ ) => void;
+ errorCorrection?: ErrorCorrectionContext;
}
-export function ChatHistory({
- messages,
- isCollapsed,
- onToggleCollapse,
- onClear,
- hasManualEdits,
-}: ChatHistoryProps) {
- if (messages.length === 0) {
- return null;
- }
+export const ChatHistory = forwardRef<ChatHistoryRef, ChatHistoryProps>(
+ function ChatHistory(
+ {
+ messages,
+ isCollapsed,
+ onToggleCollapse,
+ hasManualEdits,
+ // PromptInput props
+ onCodeGenerated,
+ onStreamingChange,
+ onStreamPhaseChange,
+ onError,
+ prompt: controlledPrompt,
+ onPromptChange,
+ currentCode,
+ conversationHistory = [],
+ isFollowUp = false,
+ onMessageSent,
+ onGenerationComplete,
+ onErrorMessage,
+ errorCorrection,
+ },
+ ref,
+ ) {
+ const [uncontrolledPrompt, setUncontrolledPrompt] = useState("");
+ const [model, setModel] = useState<ModelId>("gpt-5.2:low");
+ const [isLoading, setIsLoading] = useState(false);
+ const messagesEndRef = useRef<HTMLDivElement>(null);
- return (
- <div
- className={cn(
- "flex flex-col bg-background-elevated border-r border-border transition-all duration-300 shrink-0",
- isCollapsed ? "w-12" : "w-72",
- )}
- >
- {/* Header */}
- <div className="flex items-center justify-between p-3 border-b border-border">
+ // Auto-scroll to bottom when messages change
+ useEffect(() => {
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
+ }, [messages]);
+
+ const prompt =
+ controlledPrompt !== undefined ? controlledPrompt : uncontrolledPrompt;
+ const setPrompt = onPromptChange || setUncontrolledPrompt;
+
+ // Expose triggerGeneration via ref
+ useImperativeHandle(ref, () => ({
+ triggerGeneration: runGeneration,
+ }));
+
+ const runGeneration = async () => {
+ if (!prompt.trim() || isLoading) return;
+
+ setIsLoading(true);
+ onStreamingChange?.(true);
+ onStreamPhaseChange?.("reasoning");
+ onMessageSent?.(prompt);
+ setPrompt(""); // Clear input immediately after sending
+
+ try {
+ const response = await fetch("/api/generate", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ prompt,
+ model,
+ currentCode: isFollowUp ? currentCode : undefined,
+ conversationHistory: isFollowUp ? conversationHistory : [],
+ isFollowUp,
+ hasManualEdits,
+ errorCorrection,
+ }),
+ });
+
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => ({}));
+ const errorMessage =
+ errorData.error || `API error: ${response.status}`;
+ if (errorData.type === "edit_failed") {
+ onError?.(errorMessage, "validation");
+ onErrorMessage?.(errorMessage, "edit_failed");
+ return;
+ }
+ if (errorData.type === "validation") {
+ onError?.(errorMessage, "validation");
+ onErrorMessage?.(errorMessage, "validation");
+ return;
+ }
+ throw new Error(errorMessage);
+ }
+
+ const contentType = response.headers.get("content-type") || "";
+
+ if (contentType.includes("application/json")) {
+ const data = await response.json();
+ const { code, summary, metadata } = data;
+ onCodeGenerated?.(code);
+ onGenerationComplete?.(code, summary, metadata);
+ const validation = validateGptResponse(code);
+ if (!validation.isValid && validation.error) {
+ onError?.(validation.error, "validation");
+ }
+ return;
+ }
+
+ const reader = response.body?.getReader();
+ if (!reader) throw new Error("No response body");
+
+ const decoder = new TextDecoder();
+ let accumulatedText = "";
+ let buffer = "";
+
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) break;
+
+ buffer += decoder.decode(value, { stream: true });
+ const lines = buffer.split("\n");
+ buffer = lines.pop() || "";
+
+ for (const line of lines) {
+ if (!line.startsWith("data: ")) continue;
+ const data = line.slice(6);
+ if (data === "[DONE]") continue;
+
+ try {
+ const event = JSON.parse(data);
+ if (event.type === "reasoning-start") {
+ onStreamPhaseChange?.("reasoning");
+ } else if (event.type === "text-start") {
+ onStreamPhaseChange?.("generating");
+ } else if (event.type === "text-delta") {
+ accumulatedText += event.delta;
+ let codeToShow = accumulatedText;
+ codeToShow = codeToShow.replace(/^```(?:tsx?|jsx?)?\n?/, "");
+ codeToShow = codeToShow.replace(/\n?```\s*$/, "");
+ onCodeGenerated?.(codeToShow.trim());
+ } else if (event.type === "error") {
+ throw new Error(event.error);
+ }
+ } catch (parseError) {
+ if (
+ parseError instanceof Error &&
+ parseError.message !== "Unexpected token"
+ ) {
+ throw parseError;
+ }
+ }
+ }
+ }
+
+ let finalCode = accumulatedText;
+ finalCode = finalCode.replace(/^```(?:tsx?|jsx?)?\n?/, "");
+ finalCode = finalCode.replace(/\n?```\s*$/, "");
+ finalCode = extractComponentCode(finalCode);
+ onCodeGenerated?.(finalCode);
+ onGenerationComplete?.(finalCode);
+
+ const validation = validateGptResponse(finalCode);
+ if (!validation.isValid && validation.error) {
+ onError?.(validation.error, "validation");
+ }
+ } catch (error) {
+ console.error("Error generating code:", error);
+ const errorMessage =
+ error instanceof Error
+ ? error.message
+ : "An unexpected error occurred";
+ onError?.(errorMessage, "api");
+ } finally {
+ setIsLoading(false);
+ onStreamingChange?.(false);
+ onStreamPhaseChange?.("idle");
+ }
+ };
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ if (!prompt.trim()) return;
+ await runGeneration();
+ };
+
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
+ e.preventDefault();
+ handleSubmit(e);
+ }
+ };
+
+ return (
+ <div
+ className={cn(
+ "flex flex-col bg-background transition-all duration-300 shrink-0",
+ isCollapsed ? "w-12" : "w-96",
+ )}
+ >
+ {/* Header */}
{!isCollapsed && (
- <>
- <div className="flex items-center gap-2">
- <MessageSquare className="w-4 h-4 text-muted-foreground" />
- <span className="text-sm font-medium text-foreground">
- History
- </span>
+ <div className="flex items-start justify-between px-4 mb-3">
+ <h2 className="text-sm font-medium text-muted-foreground">
+ Assistant Chat
+ </h2>
+ <div className="flex items-center gap-1 -mt-1">
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => {
+ if (window.confirm("Start over? This will reset your animation.")) {
+ window.location.href = "/";
+ }
+ }}
+ title="Start over"
+ className="text-muted-foreground hover:text-foreground text-xs gap-1 h-7 px-2"
+ >
+ <RotateCcw className="w-3 h-3" />
+ Reset
+ </Button>
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ onClick={onToggleCollapse}
+ className="text-muted-foreground hover:text-foreground"
+ >
+ <PanelLeftClose className="w-4 h-4" />
+ </Button>
</div>
+ </div>
+ )}
+ {isCollapsed && (
+ <div className="flex justify-center px-4 mb-3">
<Button
variant="ghost"
size="icon-sm"
- onClick={onClear}
- title="Clear history"
+ onClick={onToggleCollapse}
+ className="text-muted-foreground hover:text-foreground"
>
- <Trash2 className="w-4 h-4" />
+ <PanelLeftOpen className="w-4 h-4" />
</Button>
- </>
+ </div>
)}
- <Button
- variant="ghost"
- size="icon-sm"
- onClick={onToggleCollapse}
- className={cn(isCollapsed && "mx-auto")}
- >
- {isCollapsed ? (
- <ChevronRight className="w-4 h-4" />
- ) : (
- <ChevronLeft className="w-4 h-4" />
- )}
- </Button>
- </div>
- {/* Messages */}
- {!isCollapsed && (
- <div className="flex-1 overflow-y-auto p-3 space-y-3">
- {hasManualEdits && (
- <div className="text-xs text-muted-foreground-dim bg-accent rounded px-2 py-1 flex items-center gap-1">
- <Pencil className="w-3 h-3" />
- Code has been manually edited
- </div>
- )}
- {messages.map((message) => (
- <div key={message.id} className="space-y-2">
- <ChatMessage message={message} />
- {/* Show skills as separate bubble */}
- {message.role === "assistant" &&
- message.metadata?.skills &&
- message.metadata.skills.length > 0 && (
- <SkillsBubble skills={message.metadata.skills} />
- )}
- {/* Show each edit as separate bubble */}
- {message.role === "assistant" &&
- message.metadata?.editType === "tool_edit" &&
- message.metadata.edits?.map((edit, i) => (
- <EditBubble key={i} edit={edit} />
- ))}
- {/* Show full replacement indicator */}
- {message.role === "assistant" &&
- message.metadata?.editType === "full_replacement" && (
- <FullReplacementBubble />
- )}
- </div>
- ))}
- </div>
- )}
- </div>
- );
-}
+ {/* Messages - clean timeline style */}
+ {!isCollapsed && (
+ <div className="flex-1 overflow-y-auto px-4 pb-4 space-y-6">
+ {messages.map((message) => (
+ <ChatMessage key={message.id} message={message} />
+ ))}
+ <div ref={messagesEndRef} />
+ </div>
+ )}
+
+ {/* Input - Lovable style */}
+ {!isCollapsed && (
+ <div className="p-4">
+ <form onSubmit={handleSubmit}>
+ <div className="bg-background-elevated rounded-xl border border-border p-3">
+ <textarea
+ value={prompt}
+ onChange={(e) => setPrompt(e.target.value)}
+ onKeyDown={handleKeyDown}
+ placeholder="Tune your animation..."
+ 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" }}
+ disabled={isLoading}
+ />
+ <div className="flex justify-between items-center mt-2 pt-2 border-t border-border/50">
+ <Select
+ value={model}
+ onValueChange={(value) => setModel(value as ModelId)}
+ disabled={isLoading}
+ >
+ <SelectTrigger className="w-auto bg-transparent border-none text-muted-foreground hover:text-foreground transition-colors text-xs h-7 px-2">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent className="bg-background-elevated border-border">
+ {MODELS.map((m) => (
+ <SelectItem
+ key={m.id}
+ value={m.id}
+ className="text-foreground focus:bg-secondary focus:text-foreground text-xs"
+ >
+ {m.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+
+ <Button
+ type="submit"
+ size="icon-sm"
+ disabled={!prompt.trim() || isLoading}
+ loading={isLoading}
+ className="bg-foreground text-background hover:bg-gray-200 h-7 w-7"
+ >
+ <ArrowUp className="w-4 h-4" />
+ </Button>
+ </div>
+ </div>
+ </form>
+ </div>
+ )}
+ </div>
+ );
+ },
+);
function ChatMessage({ message }: { message: ConversationMessage }) {
const isUser = message.role === "user";
const isError = message.role === "error";
+ const metadata = message.metadata;
+
+ // Format time
+ const time = new Date(message.timestamp).toLocaleTimeString([], {
+ hour: "numeric",
+ minute: "2-digit",
+ });
- // User messages - simple display
+ // User messages
if (isUser) {
return (
- <div className="rounded-lg p-2 text-sm bg-primary/10 text-foreground">
- <div className="text-xs text-muted-foreground-dim mb-1">You</div>
- <div className="line-clamp-3">{message.content}</div>
- <div className="text-xs text-muted-foreground-dim mt-1">
- {new Date(message.timestamp).toLocaleTimeString()}
+ <div className="space-y-1">
+ <div className="flex items-center gap-2">
+ <span className="text-xs font-medium text-muted-foreground">You</span>
+ <span className="text-xs text-muted-foreground-dim">{time}</span>
+ </div>
+ <div className="text-sm text-foreground leading-relaxed bg-secondary/50 rounded-lg px-3 py-2">
+ {message.content}
</div>
</div>
);
}
- // Error messages - show the error with retry hint
+ // Error messages
if (isError) {
return (
- <div className="rounded-lg p-2 text-sm bg-red-500/10 border border-red-500/20 text-foreground space-y-1">
- <div className="flex items-center gap-1.5 text-red-400">
- <AlertTriangle className="w-3.5 h-3.5" />
- <span className="font-medium text-xs">Edit Failed</span>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2 text-red-400">
+ <AlertTriangle className="w-4 h-4" />
+ <span className="text-xs font-medium">Edit Failed</span>
</div>
- <div className="text-xs text-red-300/80">{message.content}</div>
- <div className="text-[10px] text-muted-foreground-dim pt-1">
- Try rephrasing your request or be more specific
+ <div className="text-xs text-red-300/80 leading-relaxed pl-6">
+ {message.content}
</div>
</div>
);
}
- // Assistant messages - just summary, edits/skills shown as separate bubbles
+ // Assistant messages - show summary + inline edits
return (
- <div className="rounded-lg p-2 text-sm bg-secondary text-secondary-foreground">
- <div className="font-medium text-foreground">{message.content}</div>
- <div className="text-[10px] text-muted-foreground-dim mt-1">
- {new Date(message.timestamp).toLocaleTimeString()}
+ <div className="space-y-1">
+ <div className="flex items-center gap-2">
+ <span className="text-xs font-medium text-blue-400">Assistant</span>
+ <span className="text-xs text-muted-foreground-dim">{time}</span>
</div>
- </div>
- );
-}
-function SkillsBubble({ skills }: { skills: string[] }) {
- return (
- <div className="rounded-lg p-2 text-sm bg-purple-500/10 border border-purple-500/20">
- <div className="flex items-center gap-1.5 text-purple-400 mb-1.5">
- <FileCode className="w-3 h-3" />
- <span className="text-[10px] uppercase tracking-wide font-medium">
- Skills Used
- </span>
+ {/* Summary */}
+ <div className="text-sm text-foreground leading-relaxed">
+ {message.content}
</div>
- <div className="flex items-center gap-1 flex-wrap">
- {skills.map((skill) => (
- <span
- key={skill}
- className="text-[10px] px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-300 font-medium"
- >
- {skill}
- </span>
- ))}
- </div>
- </div>
- );
-}
-function EditBubble({
- edit,
-}: {
- edit: { description: string; lineNumber?: number };
-}) {
- return (
- <div className="rounded-lg p-2 text-sm bg-green-500/10 border border-green-500/20">
- <div className="flex items-start gap-1.5">
- <CheckCircle2 className="w-3.5 h-3.5 text-green-500 mt-0.5 shrink-0" />
- <div className="flex-1 min-w-0">
- <div className="text-xs text-green-300">{edit.description}</div>
- {edit.lineNumber && (
- <div className="text-[10px] text-muted-foreground-dim font-mono mt-0.5">
- Line {edit.lineNumber}
+ {/* Skills used - inline tags */}
+ {metadata?.skills && metadata.skills.length > 0 && (
+ <div className="flex items-center gap-1.5 flex-wrap">
+ {metadata.skills.map((skill) => (
+ <span
+ key={skill}
+ className="text-[10px] px-2 py-0.5 rounded-full bg-secondary text-muted-foreground inline-flex items-center gap-1"
+ >
+ <BookOpen className="w-3 h-3" />
+ Skill: {skill}
+ </span>
+ ))}
+ </div>
+ )}
+
+ {/* Edits - clean list */}
+ {metadata?.editType === "tool_edit" && metadata.edits && (
+ <div className="space-y-1.5 pl-1">
+ {metadata.edits.map((edit, i) => (
+ <div key={i} className="flex items-center gap-2">
+ <div className="w-5 h-5 rounded-full bg-secondary flex items-center justify-center shrink-0">
+ <PenLine className="w-3 h-3 text-muted-foreground" />
+ </div>
+ <div className="flex-1 min-w-0 leading-none">
+ <span className="text-xs text-muted-foreground">
+ {edit.description}
+ </span>
+ {edit.lineNumber && (
+ <span className="text-[10px] text-muted-foreground-dim font-mono ml-2">
+ L{edit.lineNumber}
+ </span>
+ )}
+ </div>
</div>
- )}
+ ))}
</div>
- </div>
- </div>
- );
-}
+ )}
-function FullReplacementBubble() {
- return (
- <div className="rounded-lg p-2 text-sm bg-blue-500/10 border border-blue-500/20">
- <div className="flex items-center gap-1.5 text-blue-400">
- <FileCode className="w-3.5 h-3.5" />
- <span className="text-xs">Full code rewrite</span>
- </div>
+ {/* Full replacement */}
+ {metadata?.editType === "full_replacement" && (
+ <div className="flex items-center gap-2 text-muted-foreground">
+ <FileCode className="w-3.5 h-3.5" />
+ <span className="text-xs">Full code rewrite</span>
+ </div>
+ )}
</div>
);
}
diff --git a/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/index.ts b/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/index.ts
index ef737bca1f..58b4b9fbc2 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/index.ts
+++ b/packages/template-prompt-to-motion-graphics/src/components/ChatHistory/index.ts
@@ -1 +1 @@
-export { ChatHistory } from "./ChatHistory";
+export { ChatHistory, type ChatHistoryRef } from "./ChatHistory";
diff --git a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx
index c3f1bc8fd1..0809afd202 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx
@@ -98,6 +98,10 @@ interface PromptInputProps {
) => void;
/** Error correction context for self-healing loops */
errorCorrection?: ErrorCorrectionContext;
+ /** Whether to show example prompts below input (default: true) */
+ showExamplePrompts?: boolean;
+ /** Compact mode for sidebar embedding */
+ compact?: boolean;
}
export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(
@@ -121,6 +125,8 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(
onGenerationComplete,
onErrorMessage,
errorCorrection,
+ showExamplePrompts = true,
+ compact = false,
},
ref,
) {
@@ -332,7 +338,7 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(
onSubmit={handleSubmit}
className={isLanding ? "w-full max-w-3xl" : ""}
>
- <div className="bg-background-elevated rounded-xl border border-border p-4">
+ <div className={`bg-background-elevated rounded-xl border border-border ${compact ? "p-3" : "p-4"}`}>
{errorCorrection && !isLanding && (
<div className="text-xs text-amber-500 mb-2 flex items-center gap-1">
<AlertTriangle className="w-3 h-3" />
@@ -351,17 +357,19 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
onKeyDown={handleKeyDown}
- placeholder="Describe your animation..."
+ placeholder={compact ? "Describe changes..." : "Describe your animation..."}
className={`w-full bg-transparent text-foreground placeholder:text-muted-foreground-dim focus:outline-none resize-none overflow-y-auto ${
isLanding
? "text-base min-h-[60px] max-h-[200px]"
- : "text-sm min-h-[40px] max-h-[150px]"
+ : compact
+ ? "text-sm min-h-[32px] max-h-[100px]"
+ : "text-sm min-h-[40px] max-h-[150px]"
}`}
style={{ fieldSizing: "content" }}
disabled={isDisabled}
/>
- <div className="flex justify-between items-center mt-3 pt-3 border-t border-border">
+ <div className={`flex justify-between items-center ${compact ? "mt-2 pt-2" : "mt-3 pt-3"} border-t border-border`}>
<Select
value={model}
onValueChange={(value) => setModel(value as ModelId)}
@@ -395,33 +403,35 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(
</div>
</div>
- <div
- className={`flex flex-wrap items-center gap-1.5 mt-3 ${
- isLanding ? "justify-center mt-6 gap-2" : ""
- }`}
- >
- <span className="text-muted-foreground-dim text-xs mr-1">
- Prompt Examples
- </span>
- {examplePrompts.map((example) => {
- const Icon = iconMap[example.icon];
- return (
- <button
- key={example.id}
- type="button"
- onClick={() => setPrompt(example.prompt)}
- style={{
- borderColor: `${example.color}40`,
- color: example.color,
- }}
- className={`rounded-full bg-background-elevated border hover:brightness-125 transition-all flex items-center gap-1 px-1.5 py-0.5 text-[11px]`}
- >
- <Icon className="w-3 h-3" />
- {example.headline}
- </button>
- );
- })}
- </div>
+ {showExamplePrompts && (
+ <div
+ className={`flex flex-wrap items-center gap-1.5 mt-3 ${
+ isLanding ? "justify-center mt-6 gap-2" : ""
+ }`}
+ >
+ <span className="text-muted-foreground-dim text-xs mr-1">
+ Prompt Examples
+ </span>
+ {examplePrompts.map((example) => {
+ const Icon = iconMap[example.icon];
+ return (
+ <button
+ key={example.id}
+ type="button"
+ onClick={() => setPrompt(example.prompt)}
+ style={{
+ borderColor: `${example.color}40`,
+ color: example.color,
+ }}
+ className={`rounded-full bg-background-elevated border hover:brightness-125 transition-all flex items-center gap-1 px-1.5 py-0.5 text-[11px]`}
+ >
+ <Icon className="w-3 h-3" />
+ {example.headline}
+ </button>
+ );
+ })}
+ </div>
+ )}
{showCodeExamplesLink && (
<div className="flex justify-center mt-4">