feat: add version history drawer with release notes

Introduce a footer-triggered Version History drawer with categorized release notes, hardcoded release data, and semver tracking at v0.3.0. Also ships blog blockquote/table styling, site-wide typography, home page image updates, header refinements, and related bug fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
alirez.br
2026-07-02 02:46:20 +03:30
co-authored by Cursor
parent 62163c4ab9
commit a47ec493c5
92 changed files with 4574 additions and 507 deletions
+109
View File
@@ -0,0 +1,109 @@
import type { Transition, Variants } from "motion/react";
/** Smooth ease-out curve for agent UI transitions */
export const agentEase = [0.22, 1, 0.36, 1] as const;
export const agentSpring = {
type: "spring",
stiffness: 380,
damping: 32,
} as const satisfies Transition;
export const agentSoftSpring = {
type: "spring",
stiffness: 260,
damping: 28,
} as const satisfies Transition;
export const agentPanelTransition: Transition = {
duration: 0.48,
ease: agentEase,
};
export const agentLayoutTransition: Transition = {
layout: { duration: 0.52, ease: agentEase },
};
export const agentFadeUp: Variants = {
hidden: { opacity: 0, y: 18 },
visible: {
opacity: 1,
y: 0,
transition: agentPanelTransition,
},
exit: {
opacity: 0,
y: -14,
transition: { duration: 0.32, ease: agentEase },
},
};
export const agentFadeIn: Variants = {
hidden: { opacity: 0, scale: 0.98 },
visible: {
opacity: 1,
scale: 1,
transition: agentPanelTransition,
},
exit: {
opacity: 0,
scale: 0.97,
transition: { duration: 0.3, ease: agentEase },
},
};
export const agentSlideInEnd: Variants = {
hidden: { opacity: 0, x: 28 },
visible: {
opacity: 1,
x: 0,
transition: agentSoftSpring,
},
exit: {
opacity: 0,
x: 28,
transition: { duration: 0.32, ease: agentEase },
},
};
export const agentStaggerContainer: Variants = {
hidden: {},
visible: {
transition: { staggerChildren: 0.07, delayChildren: 0.06 },
},
exit: {
transition: { staggerChildren: 0.04, staggerDirection: -1 },
},
};
export const agentStaggerFast: Variants = {
hidden: {},
visible: {
transition: { staggerChildren: 0.06, delayChildren: 0.12 },
},
};
export const agentCardVariant: Variants = {
hidden: { opacity: 0, y: 20, scale: 0.96 },
visible: {
opacity: 1,
y: 0,
scale: 1,
transition: agentSoftSpring,
},
exit: {
opacity: 0,
y: -10,
scale: 0.94,
transition: { duration: 0.28, ease: agentEase },
},
};
export const agentThreadItem: Variants = {
hidden: { opacity: 0, y: 14 },
visible: {
opacity: 1,
y: 0,
transition: agentPanelTransition,
},
};
@@ -0,0 +1,190 @@
"use client";
import { FileText, Mail, Plus, X } from "lucide-react";
import { motion } from "motion/react";
import { Button } from "@/components/ui/button";
import {
AGENT_AUDIENCE_TAGS,
AGENT_PREVIEW_TAGS,
AGENT_WORKSPACE_TITLE,
} from "./playground-content";
import {
agentFadeUp,
agentLayoutTransition,
agentSlideInEnd,
agentStaggerContainer,
} from "./agent-motion";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
interface AgentPreviewPanelProps {
className?: string;
onClose?: () => void;
}
function TagChip({ label }: { label: string }) {
return (
<motion.span
className={cn(
"inline-flex items-center gap-1 rounded-md border bg-muted/60 px-2 py-1",
type.caption
)}
variants={agentFadeUp}
custom={index}
>
{label}
<X className="size-3 opacity-50" aria-hidden />
</motion.span>
);
}
function AudienceSection({
title,
tags,
}: {
title: string;
tags: readonly string[];
}) {
return (
<motion.div className="space-y-2" variants={agentFadeUp}>
<p className={cn(type.caption, "font-medium uppercase tracking-wide text-muted-foreground")}>
{title}
</p>
<motion.div
className="flex flex-wrap gap-1.5"
variants={agentStaggerContainer}
initial="hidden"
animate="visible"
>
{tags.map((tag, index) => (
<TagChip key={tag} label={tag} />
))}
<motion.button
type="button"
variants={agentFadeUp}
className="inline-flex size-7 items-center justify-center rounded-md border border-dashed text-muted-foreground hover:bg-muted/50"
aria-label={`افزودن ${title}`}
whileHover={{ scale: 1.06 }}
whileTap={{ scale: 0.94 }}
>
<Plus className="size-3.5" aria-hidden />
</motion.button>
</motion.div>
</motion.div>
);
}
export function AgentPreviewPanel({ className, onClose }: AgentPreviewPanelProps) {
return (
<motion.aside
layout
className={cn(
"flex w-full shrink-0 flex-col overflow-hidden border-s bg-card lg:w-72 xl:w-80",
className
)}
variants={agentSlideInEnd}
initial="hidden"
animate="visible"
exit="exit"
transition={agentLayoutTransition}
>
<div className="flex items-center justify-between border-b px-4 py-3">
<h2 className={type["card-title"]}>پیش‌نمایش سناریو</h2>
{onClose && (
<Button
type="button"
variant="ghost"
size="icon-sm"
onClick={onClose}
aria-label="بستن پیش‌نمایش"
>
<X className="size-4" aria-hidden />
</Button>
)}
</div>
<motion.div
className="flex-1 space-y-5 overflow-y-auto p-4"
variants={agentStaggerContainer}
initial="hidden"
animate="visible"
>
<motion.div className="space-y-2" variants={agentFadeUp}>
<p className={cn(type.caption, "font-medium uppercase tracking-wide text-muted-foreground")}>
سناریو
</p>
<h3 className={type.h4}>{AGENT_WORKSPACE_TITLE}</h3>
<p className={cn(type["body-sm"], "text-muted-foreground")}>
سناریوی آزمایشی برای طراحی workflow پشتیبانی و پاسخ‌گویی خودکار به
مشتریان.
</p>
<div className="flex flex-wrap gap-1.5 pt-1">
{AGENT_PREVIEW_TAGS.map((tag, index) => (
<motion.span
key={tag}
className={cn(
"rounded-md bg-primary/10 px-2 py-0.5 text-primary",
type.caption
)}
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: 0.15 + index * 0.06 }}
>
{tag}
</motion.span>
))}
</div>
</motion.div>
<motion.div className="space-y-2" variants={agentFadeUp}>
<p className={cn(type.caption, "font-medium uppercase tracking-wide text-muted-foreground")}>
قالب
</p>
<div className="flex items-center justify-between rounded-xl border bg-muted/30 p-3">
<div className="flex items-center gap-2">
<FileText className="size-4 text-muted-foreground" aria-hidden />
<span className={type["body-sm"]}>پاسخ‌گویی خودکار</span>
</div>
<Button type="button" variant="ghost" size="sm" className="h-7 px-2 text-xs">
تغییر
</Button>
</div>
</motion.div>
<div className="space-y-4">
<p className={cn(type.caption, "font-medium uppercase tracking-wide text-muted-foreground")}>
نمای کلی مخاطب
</p>
<AudienceSection title="نوع شرکت" tags={AGENT_AUDIENCE_TAGS.companyType} />
<AudienceSection title="مرحله" tags={AGENT_AUDIENCE_TAGS.stage} />
<AudienceSection title="اندازه شرکت" tags={AGENT_AUDIENCE_TAGS.companySize} />
<AudienceSection title="منطقه" tags={AGENT_AUDIENCE_TAGS.region} />
</div>
<motion.div className="space-y-2" variants={agentFadeUp}>
<p className={cn(type.caption, "font-medium uppercase tracking-wide text-muted-foreground")}>
ساختار سناریو
</p>
<div className="flex items-center gap-2 rounded-xl border bg-muted/30 px-3 py-2.5">
<Mail className="size-4 text-muted-foreground" aria-hidden />
<span className={type["body-sm"]}>پیام ۱</span>
</div>
</motion.div>
</motion.div>
<motion.div
className="flex gap-2 border-t p-4"
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
>
<Button type="button" variant="outline" className="flex-1">
زمان‌بندی
</Button>
<Button type="button" className="flex-1">
اجرای سناریو
</Button>
</motion.div>
</motion.aside>
);
}
+55
View File
@@ -0,0 +1,55 @@
"use client";
import { motion, useReducedMotion } from "motion/react";
import { cn } from "@/lib/utils";
interface AgentSphereProps {
className?: string;
}
export function AgentSphere({ className }: AgentSphereProps) {
const reduceMotion = useReducedMotion();
return (
<motion.div
className={cn(
"relative flex size-16 items-center justify-center sm:size-20",
className
)}
aria-hidden
initial={{ opacity: 0, scale: 0.8 }}
animate={{
opacity: 1,
scale: 1,
y: reduceMotion ? 0 : [0, -5, 0],
}}
transition={{
opacity: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
scale: { type: "spring", stiffness: 320, damping: 24 },
y: reduceMotion
? undefined
: { duration: 4, repeat: Infinity, ease: "easeInOut" },
}}
>
<motion.div
className="absolute inset-0 rounded-full bg-primary/15 blur-xl"
animate={
reduceMotion
? undefined
: { scale: [1, 1.12, 1], opacity: [0.6, 0.9, 0.6] }
}
transition={{ duration: 3.5, repeat: Infinity, ease: "easeInOut" }}
/>
<div
className="relative size-full rounded-full shadow-lg"
style={{
background:
"radial-gradient(circle at 30% 25%, oklch(0.75 0.12 165), #01796F 45%, oklch(0.35 0.08 175) 100%)",
}}
>
<div className="absolute inset-[18%] rounded-full bg-white/20 blur-sm" />
<div className="absolute left-[22%] top-[18%] size-[28%] rounded-full bg-white/35 blur-[2px]" />
</div>
</motion.div>
);
}
+385
View File
@@ -0,0 +1,385 @@
"use client";
import {
BarChart3,
Check,
ChevronDown,
FileText,
GitBranch,
Loader2,
Megaphone,
Sparkles,
Target,
} from "lucide-react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useState } from "react";
import {
AGENT_AUDIENCE_TAGS,
AGENT_PROGRESS_STAGES,
} from "./playground-content";
import {
agentEase,
agentPanelTransition,
agentSoftSpring,
agentStaggerFast,
agentThreadItem,
} from "./agent-motion";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
import type { ChatMessage } from "./types";
interface AgentThreadProps {
messages: ChatMessage[];
isTyping?: boolean;
bottomRef?: React.RefObject<HTMLDivElement | null>;
}
function ProgressCard() {
const activeStage = 2;
const reduceMotion = useReducedMotion();
return (
<motion.div
className="rounded-2xl border bg-card p-4 shadow-sm"
variants={agentThreadItem}
initial="hidden"
animate="visible"
>
<div className="flex items-center justify-between gap-2">
<h3 className={type["card-title"]}>تولید سناریو آغاز شد</h3>
<span className={cn(type.caption, "text-muted-foreground")}>۵ دقیقه</span>
</div>
<div className="mt-4 flex gap-1">
{AGENT_PROGRESS_STAGES.map((stage, index) => {
const isComplete = index < activeStage;
const isActive = index === activeStage;
return (
<div key={stage} className="flex-1 space-y-1.5">
<div className="h-1.5 overflow-hidden rounded-full bg-muted">
<motion.div
className="h-full rounded-full bg-primary"
initial={{ scaleX: 0 }}
animate={{
scaleX: isComplete || isActive ? 1 : 0,
opacity: isComplete || isActive ? 1 : 0,
}}
style={{ transformOrigin: "right center" }}
transition={{
duration: reduceMotion ? 0 : 0.55,
delay: reduceMotion ? 0 : index * 0.1,
ease: agentEase,
}}
/>
</div>
<motion.p
className={cn(
type.caption,
"text-center text-[10px] uppercase tracking-wide",
isComplete || isActive
? "text-primary"
: "text-muted-foreground"
)}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: reduceMotion ? 0 : 0.15 + index * 0.06 }}
>
{stage}
</motion.p>
</div>
);
})}
</div>
</motion.div>
);
}
function TaskRow({
title,
status,
expanded,
onToggle,
children,
index = 0,
}: {
title: string;
status: "done" | "active" | "pending";
expanded?: boolean;
onToggle?: () => void;
children?: React.ReactNode;
index?: number;
}) {
const reduceMotion = useReducedMotion();
return (
<motion.div
className="overflow-hidden rounded-xl border bg-card"
variants={agentThreadItem}
initial="hidden"
animate="visible"
transition={{ ...agentPanelTransition, delay: reduceMotion ? 0 : 0.08 + index * 0.07 }}
layout
>
<button
type="button"
onClick={onToggle}
className="flex w-full items-center gap-3 px-4 py-3 text-start"
>
<motion.span
className={cn(
"flex size-5 shrink-0 items-center justify-center rounded-full",
status === "done" && "bg-primary/15 text-primary",
status === "active" && "bg-primary text-primary-foreground",
status === "pending" && "border text-muted-foreground"
)}
initial={{ scale: 0.6, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={agentSoftSpring}
>
{status === "done" ? (
<Check className="size-3" aria-hidden />
) : status === "active" ? (
<Loader2 className="size-3 animate-spin" aria-hidden />
) : (
<span className="size-1.5 rounded-full bg-muted-foreground/50" />
)}
</motion.span>
<span className={cn("flex-1", type["body-sm"], status === "pending" && "text-muted-foreground")}>
{title}
</span>
{onToggle && (
<motion.span
animate={{ rotate: expanded ? 180 : 0 }}
transition={{ duration: 0.28, ease: agentEase }}
>
<ChevronDown
className="size-4 shrink-0 text-muted-foreground"
aria-hidden
/>
</motion.span>
)}
</button>
<AnimatePresence initial={false}>
{expanded && children && (
<motion.div
key="content"
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: reduceMotion ? 0 : 0.32, ease: agentEase }}
className="overflow-hidden"
>
<div className="border-t px-4 pb-4 pt-3">{children}</div>
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
}
function AudienceTags() {
const allTags = [
...AGENT_AUDIENCE_TAGS.companyType,
...AGENT_AUDIENCE_TAGS.stage,
...AGENT_AUDIENCE_TAGS.region,
];
const reduceMotion = useReducedMotion();
return (
<div className="flex flex-wrap gap-1.5">
{allTags.map((tag, index) => (
<motion.span
key={tag}
className={cn(
"rounded-md border bg-muted/50 px-2.5 py-1 text-foreground",
type.caption
)}
initial={{ opacity: 0, scale: 0.85, y: 6 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
transition={{
...agentSoftSpring,
delay: reduceMotion ? 0 : index * 0.05,
}}
>
{tag}
</motion.span>
))}
</div>
);
}
function AssistantBubble({ content }: { content: string }) {
return (
<motion.div
className="rounded-2xl border bg-card p-4 shadow-sm"
initial={{ opacity: 0, y: 16 }}
animate={{ opacity: 1, y: 0 }}
transition={agentPanelTransition}
>
<p className={cn(type.chat, "whitespace-pre-wrap break-words text-card-foreground")}>
{content}
</p>
</motion.div>
);
}
export function AgentThread({
messages,
isTyping = false,
bottomRef,
}: AgentThreadProps) {
const [expandedTask, setExpandedTask] = useState(true);
const lastUserMessage = [...messages].reverse().find((m) => m.role === "user");
const assistantMessages = messages.filter((m) => m.role === "assistant");
const lastAssistant = assistantMessages[assistantMessages.length - 1];
return (
<div className="min-h-0 flex-1 overflow-y-auto">
<motion.div
className="flex flex-col gap-4 p-4 sm:p-5"
variants={agentStaggerFast}
initial="hidden"
animate="visible"
>
<AnimatePresence mode="popLayout">
{lastUserMessage && (
<motion.div
key="user-prompt"
className="rounded-2xl bg-muted/50 px-4 py-3.5"
layout
initial={{ opacity: 0, y: -12, scale: 0.98 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, y: -8, scale: 0.98 }}
transition={agentPanelTransition}
>
<p className={cn(type["body-sm"], "whitespace-pre-wrap break-words text-foreground")}>
{lastUserMessage.content}
</p>
</motion.div>
)}
</AnimatePresence>
<AnimatePresence mode="popLayout">
{(isTyping || assistantMessages.length > 0) && (
<motion.div
key="agent-workflow"
className="space-y-4"
layout
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.35, ease: agentEase }}
>
<AnimatePresence>
{isTyping && (
<motion.div
key="progress"
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.38, ease: agentEase }}
>
<ProgressCard />
</motion.div>
)}
</AnimatePresence>
<div className="space-y-2">
<TaskRow title="تحلیل نیازمندی‌ها" status="done" index={0} />
<TaskRow
title="کشف حساب‌ها و سیگنال‌ها"
status={isTyping ? "active" : "done"}
expanded={expandedTask}
onToggle={() => setExpandedTask((v) => !v)}
index={1}
>
<AudienceTags />
</TaskRow>
<TaskRow
title="ساخت پیام‌های شخصی‌سازی‌شده"
status={isTyping ? "pending" : "done"}
index={2}
/>
<TaskRow
title="تنظیم دنباله ارتباطی"
status="pending"
index={3}
/>
</div>
<AnimatePresence>
{!isTyping && lastAssistant && (
<motion.div
key="assistant"
initial={{ opacity: 0, y: 14 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 8 }}
transition={agentPanelTransition}
>
<AssistantBubble content={lastAssistant.content} />
</motion.div>
)}
</AnimatePresence>
<AnimatePresence>
{!isTyping && assistantMessages.length > 0 && (
<motion.div
key="ready-banner"
className="flex items-center justify-between rounded-xl bg-muted/40 px-4 py-2.5"
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ ...agentPanelTransition, delay: 0.1 }}
>
<span className={cn(type["body-sm"], "text-muted-foreground")}>
سناریوی شما آماده است!
</span>
<motion.button
type="button"
className={cn(
"rounded-lg bg-foreground px-3 py-1.5 text-background",
type.caption
)}
whileHover={{ scale: 1.03 }}
whileTap={{ scale: 0.97 }}
>
پیش‌نمایش
</motion.button>
</motion.div>
)}
</AnimatePresence>
</motion.div>
)}
</AnimatePresence>
<div ref={bottomRef} className="h-px shrink-0" aria-hidden />
</motion.div>
</div>
);
}
export function FeatureCardIcon({
icon,
className,
}: {
icon: (typeof import("./playground-content").AGENT_FEATURE_CARDS)[number]["icon"];
className?: string;
}) {
const iconClass = cn("size-4", className);
switch (icon) {
case "megaphone":
return <Megaphone className={iconClass} aria-hidden />;
case "document":
return <FileText className={iconClass} aria-hidden />;
case "sparkles":
return <Sparkles className={iconClass} aria-hidden />;
case "chart":
return <BarChart3 className={iconClass} aria-hidden />;
case "target":
return <Target className={iconClass} aria-hidden />;
case "steps":
return <GitBranch className={iconClass} aria-hidden />;
}
}
+156
View File
@@ -0,0 +1,156 @@
"use client";
import {
AtSign,
CheckSquare,
Mic,
Paperclip,
Play,
Shield,
} from "lucide-react";
import { motion, useReducedMotion } from "motion/react";
import { Button } from "@/components/ui/button";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { agentEase, agentPanelTransition } from "./agent-motion";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
interface ChatComposerProps {
value: string;
onChange: (value: string) => void;
onSubmit: () => void;
disabled?: boolean;
isSending?: boolean;
className?: string;
}
export function ChatComposer({
value,
onChange,
onSubmit,
disabled = false,
isSending = false,
className,
}: ChatComposerProps) {
const canSubmit = value.trim().length > 0 && !disabled && !isSending;
const reduceMotion = useReducedMotion();
function handleKeyDown(event: React.KeyboardEvent<HTMLTextAreaElement>) {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
if (canSubmit) onSubmit();
}
}
return (
<motion.div
className={cn("shrink-0 p-3 sm:p-4", className)}
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={agentPanelTransition}
>
<motion.div
className="rounded-2xl border bg-card p-3 shadow-md sm:p-4"
layout
transition={agentPanelTransition}
whileHover={
reduceMotion ? undefined : { boxShadow: "0 8px 30px -8px rgba(1, 121, 111, 0.12)" }
}
>
<Textarea
value={value}
onChange={(event) => onChange(event.target.value)}
onKeyDown={handleKeyDown}
placeholder="امتحان کنید: «یک سناریو پاسخ‌گویی خودکار برای مشتریان طراحی کن»..."
disabled={disabled || isSending}
rows={2}
className={cn(
"min-h-[4.5rem] resize-none border-0 bg-transparent px-1 py-1 text-start shadow-none transition-[min-height] duration-300 ease-out focus-visible:ring-0",
type["body-sm"]
)}
aria-label="دستور عامل"
/>
<div className="mt-2 flex items-center justify-between gap-2 border-t pt-2">
<div className="flex items-center gap-0.5 sm:gap-1">
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="پیوست"
>
<Paperclip className="size-4" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="اشاره"
>
<AtSign className="size-4" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="وظایف"
>
<CheckSquare className="size-4" aria-hidden />
</Button>
<Select defaultValue="overall">
<SelectTrigger
size="sm"
className="h-8 gap-1 border-0 bg-transparent px-2 shadow-none"
>
<Shield className="size-3.5 text-muted-foreground" aria-hidden />
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="overall">کلی</SelectItem>
<SelectItem value="focused">متمرکز</SelectItem>
<SelectItem value="creative">خلاقانه</SelectItem>
</SelectContent>
</Select>
</div>
<div className="flex items-center gap-1.5">
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="ضبط صدا"
>
<Mic className="size-4" aria-hidden />
</Button>
<motion.div
whileHover={reduceMotion ? undefined : { scale: 1.04 }}
whileTap={reduceMotion ? undefined : { scale: 0.96 }}
transition={{ duration: 0.18, ease: agentEase }}
>
<Button
type="button"
onClick={onSubmit}
disabled={!canSubmit}
className="h-8 gap-1.5 rounded-full px-4"
>
<Play className="size-3.5 fill-current" aria-hidden />
<span className={type.caption}>اجرا</span>
</Button>
</motion.div>
</div>
</div>
</motion.div>
</motion.div>
);
}
@@ -0,0 +1,96 @@
"use client";
import { motion, useReducedMotion } from "motion/react";
import { AGENT_FEATURE_CARDS, AGENT_WELCOME } from "./playground-content";
import { AgentSphere } from "./agent-sphere";
import {
agentCardVariant,
agentEase,
agentFadeUp,
agentStaggerContainer,
} from "./agent-motion";
import { FeatureCardIcon } from "./agent-thread";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
interface ChatEmptyStateProps {
onSelectStarter: (id: string, prompt: string) => void;
disabled?: boolean;
className?: string;
}
export function ChatEmptyState({
onSelectStarter,
disabled = false,
className,
}: ChatEmptyStateProps) {
const reduceMotion = useReducedMotion();
return (
<motion.div
className={cn(
"flex flex-1 flex-col items-center overflow-y-auto px-4 py-6 sm:px-6 sm:py-8",
className
)}
variants={agentStaggerContainer}
initial="hidden"
animate="visible"
exit="exit"
>
<AgentSphere />
<motion.h2
className={cn(type.h3, "mt-5 text-center")}
variants={agentFadeUp}
>
{AGENT_WELCOME.greeting}
</motion.h2>
<motion.p
className={cn(type["body-sm"], "mt-1.5 max-w-md text-center text-muted-foreground")}
variants={agentFadeUp}
>
{AGENT_WELCOME.subtitle}
</motion.p>
<motion.div
className="mt-8 grid w-full max-w-2xl gap-3 sm:grid-cols-2 lg:max-w-3xl"
variants={agentStaggerContainer}
>
{AGENT_FEATURE_CARDS.map((card) => (
<motion.button
key={card.id}
type="button"
disabled={disabled}
variants={agentCardVariant}
onClick={() => onSelectStarter(card.id, card.prompt)}
whileHover={
reduceMotion
? undefined
: { y: -3, scale: 1.015, transition: { duration: 0.22, ease: agentEase } }
}
whileTap={
reduceMotion
? undefined
: { scale: 0.97, transition: { duration: 0.14 } }
}
className={cn(
"group rounded-2xl border bg-card p-4 text-start shadow-sm",
"hover:border-primary/30 hover:shadow-md disabled:opacity-50",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
)}
>
<motion.div
className="flex size-8 items-center justify-center rounded-lg bg-muted text-foreground"
whileHover={reduceMotion ? undefined : { scale: 1.08 }}
transition={{ type: "spring", stiffness: 400, damping: 22 }}
>
<FeatureCardIcon icon={card.icon} />
</motion.div>
<h3 className={cn(type["card-title"], "mt-3")}>{card.title}</h3>
<p className={cn(type["card-desc"], "mt-1")}>{card.description}</p>
</motion.button>
))}
</motion.div>
</motion.div>
);
}
+107
View File
@@ -0,0 +1,107 @@
"use client";
import { Bot, User } from "lucide-react";
import { ScrollArea } from "@/components/ui/scroll-area";
import { cn } from "@/lib/utils";
import { type, typeSpacing } from "@/lib/typography";
import type { ChatMessage } from "./types";
interface ChatMessageListProps {
messages: ChatMessage[];
isTyping?: boolean;
bottomRef?: React.RefObject<HTMLDivElement | null>;
}
function formatTime(date: Date): string {
return date.toLocaleTimeString("fa-IR", {
hour: "2-digit",
minute: "2-digit",
});
}
function TypingIndicator() {
return (
<div className="flex justify-end">
<div className="flex max-w-[85%] items-center gap-2 rounded-2xl rounded-br-md border bg-card px-4 py-3 shadow-sm sm:max-w-[75%]">
<div className="flex size-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary">
<Bot className="size-4" aria-hidden />
</div>
<div className="flex items-center gap-1 py-1" aria-label="در حال نوشتن">
<span className="size-1.5 animate-bounce rounded-full bg-muted-foreground/60 [animation-delay:0ms]" />
<span className="size-1.5 animate-bounce rounded-full bg-muted-foreground/60 [animation-delay:150ms]" />
<span className="size-1.5 animate-bounce rounded-full bg-muted-foreground/60 [animation-delay:300ms]" />
</div>
</div>
</div>
);
}
export function ChatMessageList({
messages,
isTyping = false,
bottomRef,
}: ChatMessageListProps) {
return (
<ScrollArea className="min-h-0 flex-1 pe-1">
<div className="flex flex-col gap-4 p-4 sm:p-5">
{messages.map((message) => {
const isUser = message.role === "user";
return (
<div
key={message.id}
className={cn("flex", isUser ? "justify-start" : "justify-end")}
>
<div
className={cn(
"flex max-w-[92%] gap-2.5 sm:max-w-[80%]",
isUser ? "flex-row" : "flex-row-reverse"
)}
>
<div
className={cn(
"flex size-7 shrink-0 items-center justify-center rounded-full sm:size-8",
isUser
? "bg-primary/10 text-primary"
: "bg-muted text-muted-foreground"
)}
>
{isUser ? (
<User className="size-4" aria-hidden />
) : (
<Bot className="size-4" aria-hidden />
)}
</div>
<div className={cn("min-w-0", typeSpacing.chatMeta)}>
<div
className={cn(
"rounded-2xl px-4 py-3 shadow-sm",
type.chat,
isUser
? "rounded-tr-md bg-primary text-primary-foreground"
: "rounded-bl-md border bg-card text-card-foreground"
)}
>
<p className="whitespace-pre-wrap break-words">{message.content}</p>
</div>
<p
className={cn(
type.caption,
isUser ? "text-start" : "text-end"
)}
>
{isUser ? "شما" : "دستیار"} · {formatTime(message.timestamp)}
</p>
</div>
</div>
</div>
);
})}
{isTyping && <TypingIndicator />}
<div ref={bottomRef} className="h-px shrink-0" aria-hidden />
</div>
</ScrollArea>
);
}
+256
View File
@@ -0,0 +1,256 @@
"use client";
import {
Braces,
ChevronLeft,
MoreVertical,
Pencil,
Settings2,
Share2,
Wand2,
} from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { AgentPreviewPanel } from "./agent-preview-panel";
import { AgentThread } from "./agent-thread";
import { ChatComposer } from "./chat-composer";
import { ChatEmptyState } from "./chat-empty-state";
import {
agentFadeIn,
agentLayoutTransition,
} from "./agent-motion";
import {
AGENT_BREADCRUMB,
AGENT_WORKSPACE_TITLE,
} from "./playground-content";
import type { ChatMessage } from "./types";
import type { ToolsTab } from "./playground-tools-sheet";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
interface ChatPanelProps {
messages: ChatMessage[];
inputValue: string;
onInputChange: (value: string) => void;
onSubmit: () => void;
onStarterSelect: (id: string, prompt: string) => void;
onOpenTools: (tab: ToolsTab) => void;
isSending?: boolean;
isTyping?: boolean;
bottomRef?: React.RefObject<HTMLDivElement | null>;
className?: string;
}
function AgentHeader({
onOpenTools,
}: {
onOpenTools: (tab: ToolsTab) => void;
}) {
return (
<div className="shrink-0 border-b bg-card">
<div className="flex items-center gap-1.5 px-4 py-2 sm:px-5">
<span className={cn(type.caption, "text-muted-foreground")}>
{AGENT_BREADCRUMB.parent}
</span>
<ChevronLeft className="size-3 rotate-180 text-muted-foreground/60" aria-hidden />
<span className={cn(type.caption, "font-medium text-foreground")}>
{AGENT_BREADCRUMB.current}
</span>
</div>
<div className="flex items-center justify-between gap-3 border-t bg-muted/20 px-4 py-2.5 sm:px-5">
<h2 className={cn("min-w-0 truncate", type["card-title"])}>
{AGENT_WORKSPACE_TITLE}
</h2>
<div className="flex shrink-0 items-center gap-0.5">
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="ویرایش"
>
<Pencil className="size-3.5" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="اشتراک‌گذاری"
>
<Share2 className="size-3.5" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="text-muted-foreground"
aria-label="گزینه‌های بیشتر"
>
<MoreVertical className="size-3.5" aria-hidden />
</Button>
<div className="mx-1 hidden h-4 w-px bg-border sm:block" aria-hidden />
<Button
type="button"
variant="ghost"
size="sm"
className="hidden h-8 gap-1.5 px-2 sm:inline-flex"
onClick={() => onOpenTools("scenarios")}
aria-label="سناریوها"
>
<Wand2 className="size-3.5 shrink-0" aria-hidden />
<span className={type.caption}>سناریوها</span>
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="sm:hidden"
onClick={() => onOpenTools("scenarios")}
aria-label="سناریوها"
>
<Wand2 className="size-3.5" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="sm"
className="hidden h-8 gap-1.5 px-2 sm:inline-flex"
onClick={() => onOpenTools("settings")}
aria-label="تنظیمات"
>
<Settings2 className="size-3.5 shrink-0" aria-hidden />
<span className={type.caption}>تنظیمات</span>
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="sm:hidden"
onClick={() => onOpenTools("settings")}
aria-label="تنظیمات"
>
<Settings2 className="size-3.5" aria-hidden />
</Button>
<Button
type="button"
variant="ghost"
size="sm"
className="hidden h-8 gap-1.5 px-2 sm:inline-flex"
onClick={() => onOpenTools("output")}
aria-label="خروجی"
>
<Braces className="size-3.5 shrink-0" aria-hidden />
<span className={type.caption}>خروجی</span>
</Button>
<Button
type="button"
variant="ghost"
size="icon-sm"
className="sm:hidden"
onClick={() => onOpenTools("output")}
aria-label="خروجی"
>
<Braces className="size-3.5" aria-hidden />
</Button>
</div>
</div>
</div>
);
}
export function ChatPanel({
messages,
inputValue,
onInputChange,
onSubmit,
onStarterSelect,
onOpenTools,
isSending = false,
isTyping = false,
bottomRef,
className,
}: ChatPanelProps) {
const showEmptyState = messages.length === 0 && !isTyping;
const showPreview = messages.length > 0 || isTyping;
return (
<Card
className={cn(
"flex min-h-[min(70dvh,42rem)] flex-col gap-0 overflow-hidden border-border/80 bg-muted/30 py-0 shadow-sm md:min-h-[min(75dvh,48rem)]",
className
)}
>
<AgentHeader onOpenTools={onOpenTools} />
<motion.div
layout
className="flex min-h-0 flex-1 flex-col lg:flex-row"
transition={agentLayoutTransition}
>
<motion.div
layout
className="flex min-h-0 min-w-0 flex-1 flex-col bg-background/60"
transition={agentLayoutTransition}
>
<div className="relative min-h-0 flex-1">
<AnimatePresence mode="sync">
{showEmptyState ? (
<motion.div
key="empty"
className="absolute inset-0 flex flex-col"
variants={agentFadeIn}
initial="hidden"
animate="visible"
exit="exit"
>
<ChatEmptyState
onSelectStarter={onStarterSelect}
disabled={isSending}
className="flex-1"
/>
</motion.div>
) : (
<motion.div
key="thread"
className="absolute inset-0 flex flex-col"
variants={agentFadeIn}
initial="hidden"
animate="visible"
exit="exit"
>
<AgentThread
messages={messages}
isTyping={isTyping}
bottomRef={bottomRef}
/>
</motion.div>
)}
</AnimatePresence>
</div>
<motion.div layout transition={agentLayoutTransition}>
<ChatComposer
value={inputValue}
onChange={onInputChange}
onSubmit={onSubmit}
disabled={false}
isSending={isSending}
/>
</motion.div>
</motion.div>
<AnimatePresence>
{showPreview && (
<AgentPreviewPanel key="preview" className="hidden lg:flex" />
)}
</AnimatePresence>
</motion.div>
</Card>
);
}
+56
View File
@@ -0,0 +1,56 @@
import type { ChatMessage, SendMessageOptions } from "./types";
const MOCK_RESPONSES = [
"درخواست شما دریافت شد. این پاسخ آزمایشی است و پس از اتصال به سرویس واقعی، خروجی دقیق‌تری دریافت خواهید کرد.",
"بر اساس متن ارسالی، می‌توانم یک خلاصه کوتاه ارائه دهم. در نسخه فعلی، این بخش به‌صورت شبیه‌سازی‌شده پاسخ می‌دهد.",
"سناریوی انتخاب‌شده برای آزمایش مناسب است. می‌توانید تنظیمات مدل و حالت پاسخ را از پنل کناری تغییر دهید.",
];
function pickMockResponse(userText: string): string {
const lower = userText.toLowerCase();
if (lower.includes("خلاصه") || lower.includes("summary")) {
return "خلاصه آزمایشی: متن شما شامل چند نکته کلیدی است که می‌توان آن‌ها را در قالب گزارش کوتاه ارائه داد. پس از اتصال API، این بخش با مدل واقعی تکمیل می‌شود.";
}
if (lower.includes("ایمیل") || lower.includes("email")) {
return "پیش‌نویس ایمیل آزمایشی:\n\nبا سلام و احترام،\n\nاز پیام شما سپاسگزاریم. در حال بررسی درخواست هستیم و به‌زودی پاسخ کامل ارسال خواهد شد.\n\nبا تشکر";
}
if (lower.includes("پشتیبانی") || lower.includes("مشتری")) {
return "پاسخ پیشنهادی پشتیبانی: مشکل شما ثبت شد. لطفاً شماره پیگیری را نگه دارید. تیم ما در اسرع وقت با شما تماس خواهد گرفت.";
}
const index = userText.length % MOCK_RESPONSES.length;
return MOCK_RESPONSES[index]!;
}
function delay(ms: number, signal?: AbortSignal): Promise<void> {
return new Promise((resolve, reject) => {
const timer = setTimeout(resolve, ms);
signal?.addEventListener("abort", () => {
clearTimeout(timer);
reject(new DOMException("Aborted", "AbortError"));
});
});
}
/**
* Mock AI handler — swap this function body for a real API call later.
* Example future signature: POST /api/playground/chat with messages + options.
*/
export async function sendMessageToAI(
messages: ChatMessage[],
options?: SendMessageOptions
): Promise<string> {
const lastUserMessage = [...messages].reverse().find((m) => m.role === "user");
const userText = lastUserMessage?.content ?? "";
const baseDelay = 700 + Math.min(userText.length * 8, 1200);
const temperature = options?.settings?.temperature ?? 0.7;
const adjustedDelay = Math.round(baseDelay * (0.8 + temperature * 0.4));
await delay(adjustedDelay, options?.signal);
return pickMockResponse(userText);
}
+125
View File
@@ -0,0 +1,125 @@
export const AGENT_BREADCRUMB = {
parent: "عامل‌ها",
current: "دستیار هوشمند",
} as const;
export const AGENT_WORKSPACE_TITLE = "طراحی workflow پشتیبانی — نمونه Q1";
export const AGENT_WELCOME = {
greeting: "سلام! به دستیار فیپ خوش آمدید",
subtitle: "دستیار هوشمند شما برای اتوماسیون و بهینه‌سازی فرایندها",
} as const;
export const AGENT_FEATURE_CARDS = [
{
id: "workflow",
icon: "megaphone" as const,
title: "طراحی workflow",
description: "امتحان کنید: «یک workflow پاسخ‌گویی خودکار طراحی کن»",
prompt: "یک workflow پاسخ‌گویی خودکار برای مشتریان طراحی کن.",
},
{
id: "report",
icon: "document" as const,
title: "گزارش حساب",
description: "گزارش‌ها را در یک دقیقه، خودکار دریافت کنید!",
prompt: "یک گزارش خلاصه از وضعیت حساب‌های فعال تهیه کن.",
},
{
id: "brief",
icon: "sparkles" as const,
title: "خلاصه قرارداد",
description: "خلاصه قرارداد قدرتمند را فوراً از دستیار دریافت کنید",
prompt: "یک خلاصه قرارداد حرفه‌ای برای پروژه جدید بنویس.",
},
{
id: "forecast",
icon: "chart" as const,
title: "پیش‌بینی خط لوله",
description: "تأثیر سناریو را پیش از اجرا پیش‌بینی کنید.",
prompt: "تأثیر اجرای این سناریو بر خط لوله فروش را پیش‌بینی کن.",
},
{
id: "personalize",
icon: "target" as const,
title: "موتور شخصی‌سازی",
description: "بینش‌های واقعی را به هر پیام اضافه کنید.",
prompt: "این پیام را با بینش‌های شخصی‌سازی‌شده غنی کن.",
},
{
id: "sequence",
icon: "steps" as const,
title: "بهینه‌ساز دنباله",
description: "پیگیری‌ها را خودکار بهینه کنید.",
prompt: "دنباله پیگیری‌های این سناریو را بهینه کن.",
},
] as const;
export const AGENT_PROGRESS_STAGES = [
"محتوا",
"مخاطب",
"پیام",
"ساختار",
"بازبینی",
] as const;
export const AGENT_PREVIEW_TAGS = [
"پشتیبانی",
"سناریوی آزمایشی",
] as const;
export const AGENT_AUDIENCE_TAGS = {
companyType: ["استارت‌آپ AI", "SaaS"],
stage: ["مرحله A", "رشد"],
companySize: ["۱۰–۵۰ نفر"],
region: ["ایران", "خاورمیانه"],
} as const;
export const GUIDE_USE_CASES = [
{
title: "آزمایش جریان پرامپت",
description: "پرامپت‌ها و دستورالعمل‌ها را قبل از استقرار در محصول واقعی بسنجید.",
},
{
title: "تعامل مبتنی بر هوش مصنوعی",
description: "نحوه پاسخ‌دهی دستیار را در سناریوهای مختلف کشف و مقایسه کنید.",
},
{
title: "پیش‌نویس پاسخ‌ها",
description: "پاسخ‌های پشتیبانی، ایمیل و پیام‌های سازمانی را سریع‌تر آماده کنید.",
},
{
title: "بررسی خروجی ساختاریافته",
description: "نتیجه تعاملات را در قالب لاگ و JSON برای تحلیل بعدی ببینید.",
},
] as const;
export const GUIDE_SCENARIOS = [
{
title: "پاسخ‌گویی به مشتری",
description: "تبدیل پیام مشتری به پاسخ حرفه‌ای و سازگار با برند.",
},
{
title: "خلاصه‌سازی",
description: "استخراج نکات کلیدی از متن‌ها، گزارش‌ها و یادداشت‌ها.",
},
{
title: "بازنویسی محتوا",
description: "بهبود لحن، وضوح و ساختار متن‌های آماده.",
},
{
title: "ایده‌پردازی workflow",
description: "طراحی اولیه جریان‌های کاری و اتوماسیون مرتبط.",
},
{
title: "استخراج ساختاریافته",
description: "آزمایش استخراج داده و فیلدها از متن آزاد.",
},
] as const;
export const GUIDE_BENEFITS = [
"ایده‌ها را پیش از پیاده‌سازی واقعی آزمایش کنید.",
"کیفیت پاسخ‌های هوش مصنوعی را در سناریوهای مختلف ارزیابی کنید.",
"سناریوهای اتوماسیون و دستیار را بدون ریسک محصولی بررسی کنید.",
"با تیم خود جریان‌های تعاملی آینده را سریع‌تر طراحی کنید.",
] as const;
@@ -0,0 +1,95 @@
import {
GUIDE_BENEFITS,
GUIDE_SCENARIOS,
GUIDE_USE_CASES,
} from "./playground-content";
import { type, typeSpacing } from "@/lib/typography";
import { cn } from "@/lib/utils";
export function PlaygroundGuide() {
return (
<div className="border-t bg-muted/20">
<section className="py-12 md:py-16">
<div className="mx-auto max-w-6xl px-4 sm:px-6">
<div className={cn("mx-auto max-w-3xl text-center", typeSpacing.sectionStack)}>
<h2 className={type.h2}>
در آزمایشگاه فیپ چه کارهایی می‌توانید انجام دهید؟
</h2>
<p className={cn(type["body-sm"], "text-muted-foreground md:text-base")}>
این بخش برای آشنایی با قابلیت‌های آزمایشگاه فیپ است — نه بخشی از
تاریخچه گفتگو.
</p>
</div>
<div className="mt-8 grid gap-4 sm:grid-cols-2">
{GUIDE_USE_CASES.map((item) => (
<div
key={item.title}
className="rounded-2xl border bg-card/80 p-5"
>
<h3 className={type["card-title"]}>
{item.title}
</h3>
<p className={cn(type["card-desc"], "mt-2")}>
{item.description}
</p>
</div>
))}
</div>
</div>
</section>
<section className="border-t bg-background py-12 md:py-16">
<div className="mx-auto max-w-6xl px-4 sm:px-6">
<div className={cn("mx-auto max-w-3xl text-center", typeSpacing.sectionStack)}>
<h2 className={type.h2}>
سناریوهای قابل آزمایش
</h2>
<p className={cn(type["body-sm"], "text-muted-foreground md:text-base")}>
نمونه‌هایی از حوزه‌هایی که می‌توانید در گفتگو امتحان کنید.
</p>
</div>
<div className="mt-8 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{GUIDE_SCENARIOS.map((item) => (
<div
key={item.title}
className="rounded-xl border bg-muted/30 p-4"
>
<h3 className={type["card-title"]}>{item.title}</h3>
<p className={cn(type["body-sm"], "mt-1.5 text-muted-foreground")}>
{item.description}
</p>
</div>
))}
</div>
</div>
</section>
<section className="border-t bg-muted/30 py-12 md:py-16">
<div className="mx-auto max-w-6xl px-4 sm:px-6">
<div className="mx-auto max-w-3xl rounded-2xl border bg-card p-6 md:p-8">
<h2 className={type.h2}>
چرا آزمایشگاه فیپ مهم است؟
</h2>
<p className={cn(type["body-sm"], "mt-3 text-muted-foreground md:text-base")}>
قبل از اتصال به سیستم‌های واقعی، تیم‌ها می‌توانند ایده‌ها و پاسخ‌ها
را در فضایی امن و کنترل‌شده ارزیابی کنند.
</p>
<ul className="mt-6 space-y-3">
{GUIDE_BENEFITS.map((benefit) => (
<li
key={benefit}
className={cn("flex gap-2", type.body, "text-muted-foreground md:text-base")}
>
<span className="mt-2 size-1.5 shrink-0 rounded-full bg-primary" />
<span>{benefit}</span>
</li>
))}
</ul>
</div>
</div>
</section>
</div>
);
}
@@ -0,0 +1,41 @@
"use client";
import { Braces } from "lucide-react";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { PlaygroundOutputPanel } from "./playground-output-panel";
import type { InteractionLog } from "./types";
interface PlaygroundOutputCardProps {
latestLog: InteractionLog | null;
logs: InteractionLog[];
}
export function PlaygroundOutputCard({ latestLog, logs }: PlaygroundOutputCardProps) {
return (
<Card className="h-full">
<CardHeader className="pb-4">
<div className="flex items-center gap-2">
<div className="flex size-8 items-center justify-center rounded-lg bg-primary/10 text-primary">
<Braces className="size-4" aria-hidden />
</div>
<div>
<CardTitle>خروجی ساختاریافته</CardTitle>
<CardDescription>
پیش‌نمایش آخرین تعامل و لاگ اجرا
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<PlaygroundOutputPanel latestLog={latestLog} logs={logs} />
</CardContent>
</Card>
);
}
@@ -0,0 +1,78 @@
"use client";
import { Terminal } from "lucide-react";
import { ScrollArea } from "@/components/ui/scroll-area";
import { type } from "@/lib/typography";
import { cn } from "@/lib/utils";
import type { InteractionLog } from "./types";
interface PlaygroundOutputPanelProps {
latestLog: InteractionLog | null;
logs: InteractionLog[];
}
export function PlaygroundOutputPanel({ latestLog, logs }: PlaygroundOutputPanelProps) {
const preview = latestLog
? {
interactionId: latestLog.id,
model: latestLog.model,
mode: latestLog.responseMode,
durationMs: latestLog.durationMs,
user: latestLog.userMessage,
assistant: latestLog.assistantMessage,
timestamp: latestLog.timestamp,
}
: null;
return (
<div className="space-y-4">
<div className="rounded-xl border bg-muted/30 p-3">
<div className={cn("mb-2 flex items-center gap-2", type.caption)}>
<Terminal className="size-3.5" aria-hidden />
<span>آخرین پاسخ</span>
</div>
{preview ? (
<pre className={cn("max-h-52 overflow-auto rounded-lg bg-background/80 p-3 text-foreground", type.code)}>
{JSON.stringify(preview, null, 2)}
</pre>
) : (
<p className={cn("rounded-lg bg-background/80 p-3", type.caption)}>
هنوز تعاملی ثبت نشده است. یک پیام ارسال کنید تا خروجی ساختاریافته اینجا
نمایش داده شود.
</p>
)}
</div>
<div className="space-y-2">
<p className={cn(type.caption, "font-medium")}>لاگ اجرا</p>
<ScrollArea className="h-48 rounded-xl border bg-muted/20 sm:h-56">
<div className="space-y-2 p-3">
{logs.length === 0 ? (
<p className={type.caption}>لاگی برای نمایش وجود ندارد.</p>
) : (
logs
.slice()
.reverse()
.map((log) => (
<div
key={log.id}
className={cn("rounded-lg border bg-background/70 px-3 py-2", type.code)}
>
<p className="font-medium text-foreground">
{new Date(log.timestamp).toLocaleTimeString("fa-IR")}
</p>
<p className="text-muted-foreground">
مدل: {log.model} · مدت: {log.durationMs}ms
</p>
<p className="mt-1 line-clamp-2 break-words text-foreground/80">
{log.userMessage}
</p>
</div>
))
)}
</div>
</ScrollArea>
</div>
</div>
);
}
@@ -0,0 +1,41 @@
export const PROMPT_STARTERS = [
{
id: "auto-support",
label: "طراحی سناریو پاسخ‌گویی خودکار",
prompt: "برای پاسخ‌گویی خودکار به مشتریان یک سناریو طراحی کن.",
},
{
id: "summarize",
label: "خلاصه‌سازی متن",
prompt: "این متن را خلاصه کن:\n\n[متن خود را اینجا قرار دهید]",
},
{
id: "workflow",
label: "پیشنهاد workflow",
prompt: "برای این فرایند یک workflow پیشنهاد بده:\n\n[فرایند موردنظر]",
},
{
id: "support-reply",
label: "تبدیل پیام مشتری به پاسخ حرفه‌ای",
prompt: "این پیام مشتری را به پاسخ حرفه‌ای تبدیل کن:\n\n[پیام مشتری]",
},
] as const;
export const PLAYGROUND_SCENARIOS = [
...PROMPT_STARTERS,
{
id: "email",
label: "پیش‌نویس ایمیل",
prompt: "یک ایمیل رسمی و محترمانه برای پیگیری درخواست مشتری بنویس.",
},
{
id: "analyze",
label: "تحلیل داده",
prompt: "این داده‌های فروش ماهانه را تحلیل کن و سه بینش کلیدی ارائه بده.",
},
{
id: "rewrite",
label: "بازنویسی محتوا",
prompt: "متن زیر را با لحن حرفه‌ای‌تر و روان‌تر بازنویسی کن.",
},
] as const;
@@ -0,0 +1,68 @@
"use client";
import { Wand2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
import { PLAYGROUND_SCENARIOS } from "./playground-prompts";
export { PLAYGROUND_SCENARIOS };
interface PlaygroundScenariosCardProps {
onSelectScenario: (scenarioId: string, prompt: string) => void;
disabled?: boolean;
activeScenarioId?: string | null;
}
export function PlaygroundScenariosCard({
onSelectScenario,
disabled = false,
activeScenarioId = null,
}: PlaygroundScenariosCardProps) {
return (
<Card className="h-full">
<CardHeader className="pb-4">
<div className="flex items-center gap-2">
<div className="flex size-8 items-center justify-center rounded-lg bg-primary/10 text-primary">
<Wand2 className="size-4" aria-hidden />
</div>
<div>
<CardTitle>سناریوهای آماده</CardTitle>
<CardDescription>
شروع سریع با پرامپت‌های نمونه
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-2">
{PLAYGROUND_SCENARIOS.map((scenario) => (
<Button
key={scenario.id}
type="button"
variant={activeScenarioId === scenario.id ? "default" : "outline"}
size="sm"
disabled={disabled}
onClick={() => onSelectScenario(scenario.id, scenario.prompt)}
className={cn(
"h-auto min-h-8 whitespace-normal rounded-full px-3 py-1.5",
type.caption,
activeScenarioId === scenario.id && "shadow-sm"
)}
>
{scenario.label}
</Button>
))}
</div>
</CardContent>
</Card>
);
}
@@ -0,0 +1,44 @@
"use client";
import { Settings2 } from "lucide-react";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { PlaygroundSettingsPanel } from "./playground-settings-panel";
import type { PlaygroundSettings } from "./types";
interface PlaygroundSettingsCardProps {
settings: PlaygroundSettings;
onChange: (settings: PlaygroundSettings) => void;
}
export function PlaygroundSettingsCard({
settings,
onChange,
}: PlaygroundSettingsCardProps) {
return (
<Card className="h-full">
<CardHeader className="pb-4">
<div className="flex items-center gap-2">
<div className="flex size-8 items-center justify-center rounded-lg bg-primary/10 text-primary">
<Settings2 className="size-4" aria-hidden />
</div>
<div>
<CardTitle>تنظیمات گفتگو</CardTitle>
<CardDescription>
پیکربندی مدل و رفتار پاسخ‌دهی
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<PlaygroundSettingsPanel settings={settings} onChange={onChange} />
</CardContent>
</Card>
);
}
@@ -0,0 +1,109 @@
"use client";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Slider } from "@/components/ui/slider";
import { Switch } from "@/components/ui/switch";
import type { PlaygroundSettings } from "./types";
import { type } from "@/lib/typography";
import { cn } from "@/lib/utils";
interface PlaygroundSettingsPanelProps {
settings: PlaygroundSettings;
onChange: (settings: PlaygroundSettings) => void;
idPrefix?: string;
}
export function PlaygroundSettingsPanel({
settings,
onChange,
idPrefix = "playground",
}: PlaygroundSettingsPanelProps) {
return (
<div className="space-y-5">
<div className="space-y-2">
<Label htmlFor={`${idPrefix}-model`}>مدل</Label>
<Select
value={settings.model}
onValueChange={(model) => onChange({ ...settings, model })}
>
<SelectTrigger id={`${idPrefix}-model`} className="w-full">
<SelectValue placeholder="انتخاب مدل" />
</SelectTrigger>
<SelectContent>
<SelectItem value="fip-assistant">دستیار فیپ (آزمایشی)</SelectItem>
<SelectItem value="fip-fast">فیپ سریع</SelectItem>
<SelectItem value="fip-pro">فیپ پیشرفته</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor={`${idPrefix}-mode`}>حالت پاسخ</Label>
<Select
value={settings.responseMode}
onValueChange={(responseMode) => onChange({ ...settings, responseMode })}
>
<SelectTrigger id={`${idPrefix}-mode`} className="w-full">
<SelectValue placeholder="انتخاب حالت" />
</SelectTrigger>
<SelectContent>
<SelectItem value="balanced">متعادل</SelectItem>
<SelectItem value="concise">مختصر</SelectItem>
<SelectItem value="detailed">مفصل</SelectItem>
<SelectItem value="structured">ساختاریافته</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-3">
<div className="flex items-center justify-between gap-2">
<Label htmlFor={`${idPrefix}-temperature`}>خلاقیت پاسخ</Label>
<span className={cn(type.caption, "tabular-nums")}>
{settings.temperature.toFixed(1)}
</span>
</div>
<Slider
id={`${idPrefix}-temperature`}
min={0}
max={1}
step={0.1}
value={[settings.temperature]}
onValueChange={([temperature]) =>
onChange({ ...settings, temperature: temperature ?? 0.7 })
}
className="w-full"
/>
</div>
<div className="flex items-center justify-between gap-3 rounded-xl border bg-muted/20 p-3">
<div className="space-y-0.5">
<Label htmlFor={`${idPrefix}-memory`} className={type.label}>
حافظه گفتگو
</Label>
<p className={type.caption}>
نگه‌داری زمینه مکالمه در تعاملات بعدی
</p>
</div>
<Switch
id={`${idPrefix}-memory`}
checked={settings.memoryEnabled}
onCheckedChange={(memoryEnabled) =>
onChange({ ...settings, memoryEnabled })
}
/>
</div>
<p className={cn("rounded-lg border border-dashed bg-muted/10 p-3", type.caption)}>
این تنظیمات فعلاً برای آزمایش رابط کاربری فعال هستند و پس از اتصال به سرویس
واقعی، مستقیماً روی پاسخ‌ها اعمال می‌شوند.
</p>
</div>
);
}
@@ -0,0 +1,121 @@
"use client";
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { type } from "@/lib/typography";
import { PlaygroundOutputPanel } from "./playground-output-panel";
import { PlaygroundSettingsPanel } from "./playground-settings-panel";
import { PLAYGROUND_SCENARIOS } from "./playground-prompts";
import type { InteractionLog, PlaygroundSettings } from "./types";
export type ToolsTab = "settings" | "output" | "scenarios";
interface PlaygroundToolsSheetProps {
open: boolean;
onOpenChange: (open: boolean) => void;
activeTab: ToolsTab;
onTabChange: (tab: ToolsTab) => void;
settings: PlaygroundSettings;
onSettingsChange: (settings: PlaygroundSettings) => void;
latestLog: InteractionLog | null;
logs: InteractionLog[];
onSelectScenario: (scenarioId: string, prompt: string) => void;
activeScenarioId?: string | null;
}
export function PlaygroundToolsSheet({
open,
onOpenChange,
activeTab,
onTabChange,
settings,
onSettingsChange,
latestLog,
logs,
onSelectScenario,
activeScenarioId = null,
}: PlaygroundToolsSheetProps) {
function handleScenarioSelect(scenarioId: string, prompt: string) {
onSelectScenario(scenarioId, prompt);
onOpenChange(false);
}
return (
<Sheet open={open} onOpenChange={onOpenChange}>
<SheetContent side="right" className="flex w-full flex-col gap-0 p-0 sm:max-w-md">
<SheetHeader className="border-b px-4 py-4 text-start">
<SheetTitle>ابزارهای آزمایش</SheetTitle>
<SheetDescription>تنظیمات، خروجی و کتابخانه سناریوها</SheetDescription>
</SheetHeader>
<Tabs
value={activeTab}
onValueChange={(value) => onTabChange(value as ToolsTab)}
className="flex min-h-0 flex-1 flex-col gap-0"
>
<div className="border-b px-4 py-3">
<TabsList className="grid h-9 w-full grid-cols-3">
<TabsTrigger value="settings" className={type["body-sm"]}>
تنظیمات
</TabsTrigger>
<TabsTrigger value="output" className={type["body-sm"]}>
خروجی
</TabsTrigger>
<TabsTrigger value="scenarios" className={type["body-sm"]}>
سناریوها
</TabsTrigger>
</TabsList>
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-4 py-4">
<TabsContent value="settings" className="mt-0">
<PlaygroundSettingsPanel
settings={settings}
onChange={onSettingsChange}
idPrefix="sheet"
/>
</TabsContent>
<TabsContent value="output" className="mt-0">
<PlaygroundOutputPanel latestLog={latestLog} logs={logs} />
</TabsContent>
<TabsContent value="scenarios" className="mt-0">
<div className="space-y-3">
<p className={cn(type["body-sm"], "text-muted-foreground")}>
انتخاب سناریو، پرامپت را در کادر پیام قرار می‌دهد تا بتوانید قبل از
ارسال آن را ویرایش کنید.
</p>
<div className="flex flex-col gap-2">
{PLAYGROUND_SCENARIOS.map((scenario) => (
<Button
key={scenario.id}
type="button"
variant={activeScenarioId === scenario.id ? "default" : "outline"}
className={cn(
"h-auto justify-start whitespace-normal px-3 py-2.5 text-start",
type["body-sm"],
activeScenarioId === scenario.id && "shadow-sm"
)}
onClick={() => handleScenarioSelect(scenario.id, scenario.prompt)}
>
{scenario.label}
</Button>
))}
</div>
</div>
</TabsContent>
</div>
</Tabs>
</SheetContent>
</Sheet>
);
}
@@ -0,0 +1,161 @@
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
import { ChatPanel } from "./chat-panel";
import { sendMessageToAI } from "./mock-ai";
import { PlaygroundToolsSheet } from "./playground-tools-sheet";
import type { ToolsTab } from "./playground-tools-sheet";
import type { ChatMessage, InteractionLog, PlaygroundSettings } from "./types";
const DEFAULT_SETTINGS: PlaygroundSettings = {
model: "fip-assistant",
responseMode: "balanced",
temperature: 0.7,
memoryEnabled: true,
};
function createMessage(role: ChatMessage["role"], content: string): ChatMessage {
return {
id: `${role}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
role,
content,
timestamp: new Date(),
};
}
const MODEL_LABELS: Record<string, string> = {
"fip-assistant": "دستیار فیپ (آزمایشی)",
"fip-fast": "فیپ سریع",
"fip-pro": "فیپ پیشرفته",
};
export function PlaygroundWorkspace() {
const [messages, setMessages] = useState<ChatMessage[]>([]);
const [inputValue, setInputValue] = useState("");
const [isSending, setIsSending] = useState(false);
const [isTyping, setIsTyping] = useState(false);
const [settings, setSettings] = useState<PlaygroundSettings>(DEFAULT_SETTINGS);
const [logs, setLogs] = useState<InteractionLog[]>([]);
const [activeScenarioId, setActiveScenarioId] = useState<string | null>(null);
const [toolsOpen, setToolsOpen] = useState(false);
const [toolsTab, setToolsTab] = useState<ToolsTab>("settings");
const bottomRef = useRef<HTMLDivElement>(null);
const abortRef = useRef<AbortController | null>(null);
useEffect(() => {
if (messages.length === 0) return;
bottomRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
}, [messages, isTyping]);
useEffect(() => {
return () => {
abortRef.current?.abort();
};
}, []);
const submitMessage = useCallback(
async (text: string) => {
const trimmed = text.trim();
if (!trimmed || isSending) return;
const userMessage = createMessage("user", trimmed);
const nextMessages = [...messages, userMessage];
setMessages(nextMessages);
setInputValue("");
setIsSending(true);
setIsTyping(true);
setActiveScenarioId(null);
abortRef.current?.abort();
const controller = new AbortController();
abortRef.current = controller;
const startedAt = Date.now();
try {
const assistantText = await sendMessageToAI(nextMessages, {
settings,
signal: controller.signal,
});
const assistantMessage = createMessage("assistant", assistantText);
setMessages((prev) => [...prev, assistantMessage]);
const log: InteractionLog = {
id: `log-${Date.now()}`,
userMessage: trimmed,
assistantMessage: assistantText,
model: MODEL_LABELS[settings.model] ?? settings.model,
responseMode: settings.responseMode,
timestamp: new Date().toISOString(),
durationMs: Date.now() - startedAt,
};
setLogs((prev) => [...prev, log]);
} catch (error) {
if (error instanceof DOMException && error.name === "AbortError") return;
const errorMessage = createMessage(
"assistant",
"متأسفانه در پردازش درخواست خطایی رخ داد. لطفاً دوباره تلاش کنید."
);
setMessages((prev) => [...prev, errorMessage]);
} finally {
setIsTyping(false);
setIsSending(false);
}
},
[isSending, messages, settings]
);
const handleSubmit = useCallback(() => {
void submitMessage(inputValue);
}, [inputValue, submitMessage]);
function handleStarterSelect(_id: string, prompt: string) {
void submitMessage(prompt);
}
function handleScenarioSelect(scenarioId: string, prompt: string) {
setInputValue(prompt);
setActiveScenarioId(scenarioId);
}
function handleOpenTools(tab: ToolsTab) {
setToolsTab(tab);
setToolsOpen(true);
}
const latestLog = logs.length > 0 ? logs[logs.length - 1]! : null;
return (
<>
<ChatPanel
messages={messages}
inputValue={inputValue}
onInputChange={setInputValue}
onSubmit={handleSubmit}
onStarterSelect={handleStarterSelect}
onOpenTools={handleOpenTools}
isSending={isSending}
isTyping={isTyping}
bottomRef={bottomRef}
/>
<PlaygroundToolsSheet
open={toolsOpen}
onOpenChange={setToolsOpen}
activeTab={toolsTab}
onTabChange={setToolsTab}
settings={settings}
onSettingsChange={setSettings}
latestLog={latestLog}
logs={logs}
onSelectScenario={handleScenarioSelect}
activeScenarioId={activeScenarioId}
/>
</>
);
}
+30
View File
@@ -0,0 +1,30 @@
export type MessageRole = "user" | "assistant";
export interface ChatMessage {
id: string;
role: MessageRole;
content: string;
timestamp: Date;
}
export interface PlaygroundSettings {
model: string;
responseMode: string;
temperature: number;
memoryEnabled: boolean;
}
export interface SendMessageOptions {
settings?: PlaygroundSettings;
signal?: AbortSignal;
}
export interface InteractionLog {
id: string;
userMessage: string;
assistantMessage: string;
model: string;
responseMode: string;
timestamp: string;
durationMs: number;
}