"use client" import { useState } from "react" import { useUser } from "@stackframe/stack" import { useRouter } from "next/navigation" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Textarea } from "@/components/ui/textarea" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { ModelSelector } from "@/components/model-selector" import { DEFAULT_MODEL } from "@/types/prompt" import ReactMarkdown from "react-markdown" import { BookOpen, Sparkles, Copy, Check, ChevronRight, Lightbulb, Play, Loader2, Save } from "lucide-react" interface Framework { id: string name: string acronym: string description: string color: string sections: { letter: string name: string description: string placeholder: string }[] example: string } const FRAMEWORKS: Framework[] = [ { id: "race", name: "RACE", acronym: "Role, Action, Context, Expectation", description: "Define who the AI is, what to do, the situation, and desired outcome", color: "from-blue-500 to-cyan-500", sections: [ { letter: "R", name: "Role", description: "Who should the AI act as?", placeholder: "e.g., Act as an experienced marketing consultant" }, { letter: "A", name: "Action", description: "What should the AI do?", placeholder: "e.g., Create a marketing strategy for..." }, { letter: "C", name: "Context", description: "What's the situation?", placeholder: "e.g., For a startup launching a new mobile app" }, { letter: "E", name: "Expectation", description: "What's the desired outcome?", placeholder: "e.g., Provide 5 actionable strategies with timelines" }, ], example: "Act as an experienced marketing consultant. Create a comprehensive marketing strategy for a B2B SaaS startup launching a project management tool. The target audience is small to medium businesses. Provide 5 actionable strategies with detailed implementation timelines and expected ROI." }, { id: "care", name: "CARE", acronym: "Context, Action, Result, Example", description: "Provide background, specify task, define output, and show examples", color: "from-green-500 to-emerald-500", sections: [ { letter: "C", name: "Context", description: "What's the background?", placeholder: "e.g., I'm building an e-commerce website" }, { letter: "A", name: "Action", description: "What task needs to be done?", placeholder: "e.g., Write product descriptions" }, { letter: "R", name: "Result", description: "What output do you want?", placeholder: "e.g., 100-word descriptions with features and benefits" }, { letter: "E", name: "Example", description: "Show an example if possible", placeholder: "e.g., Here's a sample description format..." }, ], example: "Context: I'm launching a premium coffee subscription service targeting busy professionals. Action: Write compelling email subject lines for our welcome sequence. Result: Give me 10 subject lines under 50 characters that drive high open rates. Example: 'Your morning ritual just upgraded' is the tone I'm looking for." }, { id: "ape", name: "APE", acronym: "Action, Purpose, Expectation", description: "Simple framework focusing on task, reason, and outcome", color: "from-orange-500 to-red-500", sections: [ { letter: "A", name: "Action", description: "What action should be taken?", placeholder: "e.g., Analyze this sales data" }, { letter: "P", name: "Purpose", description: "Why is this being done?", placeholder: "e.g., To identify top-performing products" }, { letter: "E", name: "Expectation", description: "What's the expected output?", placeholder: "e.g., A ranked list with insights" }, ], example: "Analyze the quarterly sales report I'll provide. The purpose is to identify our top 3 performing products and understand why they're successful. I expect a summary with percentage growth, key success factors, and recommendations for other products." }, { id: "create", name: "CREATE", acronym: "Character, Request, Examples, Adjustments, Type, Extras", description: "Comprehensive framework for detailed, nuanced prompts", color: "from-purple-500 to-pink-500", sections: [ { letter: "C", name: "Character", description: "Who is the AI?", placeholder: "e.g., You are a senior UX designer" }, { letter: "R", name: "Request", description: "What's the main request?", placeholder: "e.g., Review this app's user flow" }, { letter: "E", name: "Examples", description: "Provide examples", placeholder: "e.g., Good flows: Spotify, Bad flows: ..." }, { letter: "A", name: "Adjustments", description: "Any constraints?", placeholder: "e.g., Focus on mobile, ignore web" }, { letter: "T", name: "Type", description: "Output format?", placeholder: "e.g., Bullet points with priority levels" }, { letter: "E", name: "Extras", description: "Additional notes?", placeholder: "e.g., Be critical, I need honest feedback" }, ], example: "Character: You are a senior UX designer with 10+ years experience in mobile apps. Request: Review my fitness app's onboarding flow. Examples: Reference the smooth onboarding in Headspace and Duolingo. Adjustments: Focus only on the first-time user experience. Type: Provide feedback as numbered points with severity ratings (1-5). Extras: Be brutally honest - I need to ship next week." }, { id: "risen", name: "RISEN", acronym: "Role, Instructions, Steps, End goal, Narrowing", description: "Step-by-step framework with clear constraints", color: "from-indigo-500 to-violet-500", sections: [ { letter: "R", name: "Role", description: "Define the AI's role", placeholder: "e.g., Technical writer" }, { letter: "I", name: "Instructions", description: "Core instructions", placeholder: "e.g., Document this API" }, { letter: "S", name: "Steps", description: "Step-by-step process", placeholder: "e.g., 1. Overview 2. Endpoints 3. Examples" }, { letter: "E", name: "End goal", description: "Final objective", placeholder: "e.g., Complete API documentation" }, { letter: "N", name: "Narrowing", description: "Constraints & limits", placeholder: "e.g., Max 2 pages, no jargon" }, ], example: "Role: You are a technical writer specializing in developer documentation. Instructions: Create documentation for our REST API. Steps: Start with a quick overview, then list each endpoint with method/URL/params, add code examples, and end with error codes. End goal: A developer should be able to integrate within 30 minutes. Narrowing: Keep it under 3 pages, use simple language, and include curl examples only." }, ] export default function FrameworksClient() { const user = useUser() const router = useRouter() const [selectedFramework, setSelectedFramework] = useState(null) const [sectionValues, setSectionValues] = useState>({}) const [generatedPrompt, setGeneratedPrompt] = useState("") const [copied, setCopied] = useState(false) // AI Testing state const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL) const [aiOutput, setAiOutput] = useState("") const [isRunning, setIsRunning] = useState(false) // Save state const [isSaving, setIsSaving] = useState(false) const [promptTitle, setPromptTitle] = useState("") // Select a framework const selectFramework = (framework: Framework) => { setSelectedFramework(framework) setSectionValues({}) setGeneratedPrompt("") } // Update section value const updateSection = (letter: string, value: string) => { setSectionValues(prev => ({ ...prev, [letter]: value })) } // Generate prompt from sections const generatePrompt = () => { if (!selectedFramework) return const parts = selectedFramework.sections .map(section => { const value = sectionValues[section.letter] if (value?.trim()) { return `**${section.name}:** ${value}` } return null }) .filter(Boolean) setGeneratedPrompt(parts.join("\n\n")) } // Copy prompt const copyPrompt = async () => { await navigator.clipboard.writeText(generatedPrompt) setCopied(true) setTimeout(() => setCopied(false), 2000) } // Use example const useExample = () => { if (!selectedFramework) return setGeneratedPrompt(selectedFramework.example) } // Run with AI const runWithAI = async () => { if (!generatedPrompt.trim()) return setIsRunning(true) setAiOutput("") try { const response = await fetch("/api/run", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt: generatedPrompt, model: selectedModel, }), }) const reader = response.body?.getReader() const decoder = new TextDecoder() if (reader) { while (true) { const { done, value } = await reader.read() if (done) break const chunk = decoder.decode(value) setAiOutput(prev => prev + chunk) } } } catch (error) { console.error("Failed to run:", error) setAiOutput("Error: Failed to get AI response") } finally { setIsRunning(false) } } // Save to Library const saveToLibrary = async () => { if (!generatedPrompt.trim() || !selectedFramework) return setIsSaving(true) try { const response = await fetch("/api/prompts", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: promptTitle || `${selectedFramework.name} Framework Prompt`, prompt: generatedPrompt, description: `Created using ${selectedFramework.name} framework`, category: "general", visibility: "private", creatorId: undefined, // handled server-side }), }) if (response.ok) { const data = await response.json() router.push(`/p/${data.slug}`) } } catch (error) { console.error("Failed to save:", error) } finally { setIsSaving(false) } } return (
{/* Hero Section */}

Prompt Frameworks

Use proven frameworks to create better prompts. Guided templates for consistent results.

{/* Framework Selector */}

Choose a Framework

{FRAMEWORKS.map(framework => ( selectFramework(framework)} >
{framework.name}

{framework.acronym}

{framework.description}

))}
{/* Framework Builder */}
{selectedFramework ? (
{selectedFramework.name} Framework Builder {selectedFramework.acronym}
{/* Section Inputs */}
{selectedFramework.sections.map(section => (