Skip to content

🎥 Make videos programmatically with React

Replace PromptInput with LandingPageInput and extract shared types

ASchwadf36c1adb1ebe
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 22d61baed4..be0f38ce15 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
@@ -8,10 +8,7 @@ import { CodeEditor } from "../../components/CodeEditor";
import { AnimationPlayer } from "../../components/AnimationPlayer";
import { PageLayout } from "../../components/PageLayout";
import { ChatSidebar, type ChatSidebarRef } from "../../components/ChatSidebar";
-import {
- type StreamPhase,
- type GenerationErrorType,
-} from "../../components/PromptInput";
+import type { StreamPhase, GenerationErrorType } from "../../types/generation";
import { examples } from "../../examples/code";
import { useAnimationState } from "../../hooks/useAnimationState";
import { useConversationState } from "../../hooks/useConversationState";
@@ -60,7 +57,7 @@ function GeneratePageContent() {
addAssistantMessage,
addErrorMessage,
markManualEdit,
- getRecentContext,
+ getFullContext,
getPreviouslyUsedSkills,
setPendingMessage,
clearPendingMessage,
@@ -227,7 +224,7 @@ function GeneratePageContent() {
isCollapsed={isSidebarCollapsed}
onToggleCollapse={() => setIsSidebarCollapsed(!isSidebarCollapsed)}
hasManualEdits={hasManualEdits}
- // PromptInput props for embedded input
+ // Generation props for embedded input
onCodeGenerated={handleCodeChange}
onStreamingChange={handleStreamingChange}
onStreamPhaseChange={setStreamPhase}
@@ -235,7 +232,7 @@ function GeneratePageContent() {
prompt={prompt}
onPromptChange={setPrompt}
currentCode={code}
- conversationHistory={getRecentContext(3)}
+ conversationHistory={getFullContext()}
previouslyUsedSkills={getPreviouslyUsedSkills()}
isFollowUp={!isFirstGeneration}
onMessageSent={handleMessageSent}
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 9e6bff140d..f22633ede0 100644
--- a/packages/template-prompt-to-motion-graphics/src/app/page.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/app/page.tsx
@@ -3,7 +3,8 @@
import { useState } from "react";
import type { NextPage } from "next";
import { useRouter } from "next/navigation";
-import { PromptInput, type ModelId } from "@/components/PromptInput";
+import { LandingPageInput } from "@/components/LandingPageInput";
+import type { ModelId } from "@/types/generation";
import { PageLayout } from "@/components/PageLayout";
const Home: NextPage = () => {
@@ -18,8 +19,7 @@ const Home: NextPage = () => {
return (
<PageLayout>
- <PromptInput
- variant="landing"
+ <LandingPageInput
onNavigate={handleNavigate}
isNavigating={isNavigating}
showCodeExamplesLink
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 f88ddfa1be..0759f394ce 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
@@ -9,7 +9,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
-import { type ModelId, MODELS } from "../PromptInput";
+import { type ModelId, MODELS } from "@/types/generation";
interface ChatInputProps {
prompt: string;
@@ -35,7 +35,8 @@ export function ChatInput({
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
+ // Submit on Enter (Shift+Enter for new line)
+ if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
handleSubmit(e);
}
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 ab78c940ad..b76d151d37 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
@@ -34,7 +34,7 @@ import {
type GenerationErrorType,
type ModelId,
MODELS,
-} from "../PromptInput";
+} from "@/types/generation";
import { ChatInput } from "./ChatInput";
import { useGenerationApi } from "@/hooks/useGenerationApi";
diff --git a/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx
new file mode 100644
index 0000000000..683d232f5c
--- /dev/null
+++ b/packages/template-prompt-to-motion-graphics/src/components/LandingPageInput.tsx
@@ -0,0 +1,152 @@
+"use client";
+
+import { useState } from "react";
+import Link from "next/link";
+import {
+ ArrowUp,
+ SquareArrowOutUpRight,
+ Type,
+ MessageCircle,
+ Hash,
+ BarChart3,
+ Disc,
+ type LucideIcon,
+} from "lucide-react";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Button } from "@/components/ui/button";
+import { examplePrompts } from "@/examples/prompts";
+import { type ModelId, MODELS } from "@/types/generation";
+
+const iconMap: Record<string, LucideIcon> = {
+ Type,
+ MessageCircle,
+ Hash,
+ BarChart3,
+ Disc,
+};
+
+interface LandingPageInputProps {
+ onNavigate: (prompt: string, model: ModelId) => void;
+ isNavigating?: boolean;
+ showCodeExamplesLink?: boolean;
+}
+
+export function LandingPageInput({
+ onNavigate,
+ isNavigating = false,
+ showCodeExamplesLink = false,
+}: LandingPageInputProps) {
+ const [prompt, setPrompt] = useState("");
+ const [model, setModel] = useState<ModelId>("gpt-5.2:low");
+
+ const handleSubmit = (e: React.FormEvent) => {
+ e.preventDefault();
+ if (!prompt.trim() || isNavigating) return;
+ onNavigate(prompt, model);
+ };
+
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
+ // Submit on Enter (Shift+Enter for new line)
+ if (e.key === "Enter" && !e.shiftKey) {
+ e.preventDefault();
+ handleSubmit(e);
+ }
+ };
+
+ return (
+ <div className="flex flex-col items-center justify-center flex-1 px-4">
+ <h1 className="text-5xl font-bold text-white mb-10 text-center">
+ What do you want to create?
+ </h1>
+
+ <form onSubmit={handleSubmit} className="w-full max-w-3xl">
+ <div className="bg-background-elevated rounded-xl border border-border p-4">
+ <textarea
+ value={prompt}
+ onChange={(e) => setPrompt(e.target.value)}
+ onKeyDown={handleKeyDown}
+ placeholder="Describe your animation..."
+ 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}
+ />
+
+ <div className="flex justify-between items-center mt-3 pt-3 border-t border-border">
+ <Select
+ value={model}
+ onValueChange={(value) => setModel(value as ModelId)}
+ disabled={isNavigating}
+ >
+ <SelectTrigger className="w-auto bg-transparent border-none text-muted-foreground hover:text-foreground transition-colors">
+ <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"
+ >
+ {m.name}
+ </SelectItem>
+ ))}
+ </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>
+ </div>
+
+ <div className="flex flex-wrap items-center gap-1.5 mt-3 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">
+ <Link
+ href="/code-examples"
+ className="text-muted-foreground-dim hover:text-muted-foreground text-xs transition-colors flex items-center gap-1"
+ >
+ View Code examples
+ <SquareArrowOutUpRight className="w-3 h-3" />
+ </Link>
+ </div>
+ )}
+ </form>
+ </div>
+ );
+}
diff --git a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx b/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx
deleted file mode 100644
index 0809afd202..0000000000
--- a/packages/template-prompt-to-motion-graphics/src/components/PromptInput.tsx
+++ /dev/null
@@ -1,451 +0,0 @@
-"use client";
-
-import { useState, forwardRef, useImperativeHandle } from "react";
-import Link from "next/link";
-import {
- ArrowUp,
- SquareArrowOutUpRight,
- Type,
- MessageCircle,
- Hash,
- BarChart3,
- Disc,
- Pencil,
- AlertTriangle,
- type LucideIcon,
-} from "lucide-react";
-import type {
- ConversationContextMessage,
- AssistantMetadata,
- ErrorCorrectionContext,
-} from "@/types/conversation";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select";
-import { Button } from "@/components/ui/button";
-import { examplePrompts } from "@/examples/prompts";
-import {
- validateGptResponse,
- extractComponentCode,
-} from "@/helpers/sanitize-response";
-
-const iconMap: Record<string, LucideIcon> = {
- Type,
- MessageCircle,
- Hash,
- BarChart3,
- Disc,
-};
-
-export const MODELS = [
- { id: "gpt-5.2:none", name: "GPT-5.2 (No Reasoning)" },
- { id: "gpt-5.2:low", name: "GPT-5.2 (Low Reasoning)" },
- { id: "gpt-5.2:medium", name: "GPT-5.2 (Medium Reasoning)" },
- { id: "gpt-5.2:high", name: "GPT-5.2 (High Reasoning)" },
- { id: "gpt-5.2-pro:medium", name: "GPT-5.2 Pro (Medium)" },
- { id: "gpt-5.2-pro:high", name: "GPT-5.2 Pro (High)" },
- { id: "gpt-5.2-pro:xhigh", name: "GPT-5.2 Pro (XHigh)" },
-] as const;
-
-export type ModelId = (typeof MODELS)[number]["id"];
-
-export type StreamPhase = "idle" | "reasoning" | "generating";
-
-export type GenerationErrorType = "validation" | "api";
-
-export interface PromptInputRef {
- triggerGeneration: () => void;
-}
-
-interface PromptInputProps {
- onCodeGenerated?: (code: string) => void;
- onStreamingChange?: (isStreaming: boolean) => void;
- onStreamPhaseChange?: (phase: StreamPhase) => void;
- onError?: (error: string, type: GenerationErrorType) => void;
- variant?: "landing" | "editor";
- prompt?: string;
- onPromptChange?: (prompt: string) => void;
- /** Called when landing variant submits - receives prompt and model for navigation */
- onNavigate?: (prompt: string, model: ModelId) => void;
- /** Whether navigation is in progress (for landing variant) */
- isNavigating?: boolean;
- /** Whether to show the "View Code examples" link (landing variant) */
- showCodeExamplesLink?: boolean;
- /** Current code in the editor for follow-up context */
- currentCode?: string;
- /** Conversation history for context */
- conversationHistory?: ConversationContextMessage[];
- /** Whether this is a follow-up edit (has existing code) */
- isFollowUp?: boolean;
- /** Whether the code has manual edits */
- hasManualEdits?: boolean;
- /** Callback when a message is sent (for history tracking) */
- onMessageSent?: (prompt: string) => void;
- /** Callback when generation completes (for history tracking) */
- onGenerationComplete?: (
- code: string,
- summary?: string,
- metadata?: AssistantMetadata
- ) => void;
- /** Callback when an error occurs (for history tracking) */
- onErrorMessage?: (
- message: string,
- errorType: "edit_failed" | "api" | "validation"
- ) => 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>(
- function PromptInput(
- {
- onCodeGenerated,
- onStreamingChange,
- onStreamPhaseChange,
- onError,
- variant = "editor",
- prompt: controlledPrompt,
- onPromptChange,
- onNavigate,
- isNavigating = false,
- showCodeExamplesLink = false,
- currentCode,
- conversationHistory = [],
- isFollowUp = false,
- hasManualEdits = false,
- onMessageSent,
- onGenerationComplete,
- onErrorMessage,
- errorCorrection,
- showExamplePrompts = true,
- compact = false,
- },
- ref,
- ) {
- const [uncontrolledPrompt, setUncontrolledPrompt] = useState("");
- const [model, setModel] = useState<ModelId>("gpt-5.2:low");
-
- // Support both controlled and uncontrolled modes
- const prompt =
- controlledPrompt !== undefined ? controlledPrompt : uncontrolledPrompt;
- const setPrompt = onPromptChange || setUncontrolledPrompt;
- const [isLoading, setIsLoading] = useState(false);
-
- const runGeneration = async () => {
- if (!prompt.trim() || isLoading) return;
-
- setIsLoading(true);
- onStreamingChange?.(true);
- onStreamPhaseChange?.("reasoning");
-
- // Track the message for history
- onMessageSent?.(prompt);
-
- 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}`;
- // Check if this is a validation error or edit failure from the API
- 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);
- }
-
- // Check content type to determine response format
- const contentType = response.headers.get("content-type") || "";
-
- // FOLLOW-UP: Non-streaming JSON response with metadata
- if (contentType.includes("application/json")) {
- const data = await response.json();
- const { code, summary, metadata } = data;
-
- // Update the editor with the code
- onCodeGenerated?.(code);
-
- // Track generation completion with metadata and summary
- onGenerationComplete?.(code, summary, metadata);
-
- const validation = validateGptResponse(code);
- if (!validation.isValid && validation.error) {
- onError?.(validation.error, "validation");
- }
- return;
- }
-
- // INITIAL: Streaming SSE response
- 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 });
-
- // Parse SSE events from the buffer
- const lines = buffer.split("\n");
- buffer = lines.pop() || ""; // Keep incomplete line in buffer
-
- for (const line of lines) {
- if (!line.startsWith("data: ")) continue;
- const data = line.slice(6); // Remove "data: " prefix
-
- if (data === "[DONE]") continue;
-
- try {
- const event = JSON.parse(data);
-
- // Track phase changes
- if (event.type === "reasoning-start") {
- onStreamPhaseChange?.("reasoning");
- } else if (event.type === "text-start") {
- onStreamPhaseChange?.("generating");
- } else if (event.type === "text-delta") {
- accumulatedText += event.delta;
-
- // Strip markdown code block markers and show raw code during streaming
- 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) {
- // Only re-throw if it's an actual Error we created, not a JSON parse error
- if (
- parseError instanceof Error &&
- parseError.message !== "Unexpected token"
- ) {
- throw parseError;
- }
- }
- }
- }
-
- // Sanitize the final response (strip markdown code block wrappers and trailing text)
- let finalCode = accumulatedText;
- finalCode = finalCode.replace(/^```(?:tsx?|jsx?)?\n?/, "");
- finalCode = finalCode.replace(/\n?```\s*$/, "");
- finalCode = extractComponentCode(finalCode);
-
- // Update the editor with the cleaned code
- onCodeGenerated?.(finalCode);
-
- // Track generation completion for history (no metadata for streaming)
- 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");
- }
- };
-
- // Expose triggerGeneration via ref
- useImperativeHandle(ref, () => ({
- triggerGeneration: runGeneration,
- }));
-
- const handleSubmit = async (e: React.FormEvent) => {
- e.preventDefault();
- if (!prompt.trim()) return;
-
- // Landing variant uses navigation instead of API call
- if (isLanding && onNavigate) {
- onNavigate(prompt, model);
- return;
- }
-
- await runGeneration();
- };
-
- const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
- // Submit on Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
- e.preventDefault();
- handleSubmit(e);
- }
- };
-
- const isLanding = variant === "landing";
- const isDisabled = isLanding ? isNavigating : isLoading;
-
- return (
- <div
- className={
- isLanding
- ? "flex flex-col items-center justify-center flex-1 px-4"
- : "flex flex-col gap-2"
- }
- >
- {isLanding && (
- <h1 className="text-5xl font-bold text-white mb-10 text-center">
- What do you want to create?
- </h1>
- )}
-
- <form
- onSubmit={handleSubmit}
- className={isLanding ? "w-full max-w-3xl" : ""}
- >
- <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" />
- Auto-fixing error (attempt {errorCorrection.attemptNumber}/
- {errorCorrection.maxAttempts})
- </div>
- )}
- {isFollowUp && !errorCorrection && !isLanding && (
- <div className="text-xs text-muted-foreground-dim mb-2 flex items-center gap-1">
- <Pencil className="w-3 h-3" />
- Editing existing animation
- {hasManualEdits && " (includes your edits)"}
- </div>
- )}
- <textarea
- value={prompt}
- onChange={(e) => setPrompt(e.target.value)}
- onKeyDown={handleKeyDown}
- 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]"
- : 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 ${compact ? "mt-2 pt-2" : "mt-3 pt-3"} border-t border-border`}>
- <Select
- value={model}
- onValueChange={(value) => setModel(value as ModelId)}
- disabled={isDisabled}
- >
- <SelectTrigger className="w-auto bg-transparent border-none text-muted-foreground hover:text-foreground transition-colors">
- <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"
- >
- {m.name}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
-
- <Button
- type="submit"
- size="icon-sm"
- disabled={!prompt.trim() || isDisabled}
- loading={isDisabled}
- className="bg-foreground text-background hover:bg-gray-200"
- >
- <ArrowUp className="w-5 h-5" />
- </Button>
- </div>
- </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">
- <Link
- href="/code-examples"
- className="text-muted-foreground-dim hover:text-muted-foreground text-xs transition-colors flex items-center gap-1"
- >
- View Code examples
- <SquareArrowOutUpRight className="w-3 h-3" />
- </Link>
- </div>
- )}
- </form>
- </div>
- );
- },
-);
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 5a94c2d9e4..6e61c4befd 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
@@ -108,21 +108,16 @@ export function useConversationState() {
}));
}, []);
- // Get the last N conversation exchanges for context (excludes error messages)
- const getRecentContext = useCallback(
- (count: number = 3): ConversationContextMessage[] => {
- // Filter out error messages - they're not part of the conversation context for the AI
- const conversationMessages = state.messages.filter(
- (m) => m.role === "user" || m.role === "assistant",
- );
- const recentMessages = conversationMessages.slice(-count * 2);
- return recentMessages.map((m) => ({
+ // Get full conversation context (excludes error messages)
+ const getFullContext = useCallback((): ConversationContextMessage[] => {
+ // Filter out error messages - they're not part of the conversation context for the AI
+ return state.messages
+ .filter((m) => m.role === "user" || m.role === "assistant")
+ .map((m) => ({
role: m.role as "user" | "assistant",
content: m.role === "user" ? m.content : "[Generated Code]",
}));
- },
- [state.messages],
- );
+ }, [state.messages]);
// Get all skills that have been used in the conversation (to avoid redundant skill content)
const getPreviouslyUsedSkills = useCallback((): string[] => {
@@ -142,7 +137,7 @@ export function useConversationState() {
addErrorMessage,
markManualEdit,
clearConversation,
- getRecentContext,
+ getFullContext,
getPreviouslyUsedSkills,
setPendingMessage,
clearPendingMessage,
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 02158e6b91..9175164a3b 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useGenerationApi.ts
@@ -4,7 +4,7 @@ import type {
AssistantMetadata,
ErrorCorrectionContext,
} from "@/types/conversation";
-import type { StreamPhase, GenerationErrorType, ModelId } from "@/components/PromptInput";
+import type { StreamPhase, GenerationErrorType, ModelId } from "@/types/generation";
import {
validateGptResponse,
extractComponentCode,
diff --git a/packages/template-prompt-to-motion-graphics/src/types/generation.ts b/packages/template-prompt-to-motion-graphics/src/types/generation.ts
new file mode 100644
index 0000000000..cb3e55f075
--- /dev/null
+++ b/packages/template-prompt-to-motion-graphics/src/types/generation.ts
@@ -0,0 +1,15 @@
+export const MODELS = [
+ { id: "gpt-5.2:none", name: "GPT-5.2 (No Reasoning)" },
+ { id: "gpt-5.2:low", name: "GPT-5.2 (Low Reasoning)" },
+ { id: "gpt-5.2:medium", name: "GPT-5.2 (Medium Reasoning)" },
+ { id: "gpt-5.2:high", name: "GPT-5.2 (High Reasoning)" },
+ { id: "gpt-5.2-pro:medium", name: "GPT-5.2 Pro (Medium)" },
+ { id: "gpt-5.2-pro:high", name: "GPT-5.2 Pro (High)" },
+ { id: "gpt-5.2-pro:xhigh", name: "GPT-5.2 Pro (XHigh)" },
+] as const;
+
+export type ModelId = (typeof MODELS)[number]["id"];
+
+export type StreamPhase = "idle" | "reasoning" | "generating";
+
+export type GenerationErrorType = "validation" | "api";