AtlasAgentChat Component
import React, { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { FiSend } from 'react-icons/fi';
// Mocked agent replies for demonstration
const agentReplies = {
ideation: [
{ text: 'How about a story about a time-traveling detective?', agent: 'Ideation Agent', emoji: '🎨', color: 'bg-purple-500' },
{ text: 'Or perhaps a mystery set in a futuristic city?', agent: 'Ideation Agent', emoji: '🎨', color: 'bg-purple-500' },
],
structure: [
{ text: 'Let\'s break down the story into three acts.', agent: 'Structure Agent', emoji: '🧱', color: 'bg-blue-500' },
{ text: 'The first act should introduce the protagonist\'s world.', agent: 'Structure Agent', emoji: '🧱', color: 'bg-blue-500' },
],
dialogue: [
{ text: 'The dialogue should reflect the character\'s background.', agent: 'Dialogue Agent', emoji: '🗣️', color: 'bg-green-500' },
{ text: 'Subtext is key to making the dialogue more engaging.', agent: 'Dialogue Agent', emoji: '🗣️', color: 'bg-green-500' },
],
genre: [
{ text: 'For a sci-fi story, we need to establish the rules of the world.', agent: 'Genre Agent', emoji: '🕵️♀️', color: 'bg-yellow-500' },
{ text: 'Consistency is crucial in maintaining the genre.', agent: 'Genre Agent', emoji: '🕵️♀️', color: 'bg-yellow-500' },
],
editor: [
{ text: 'Tightening the pacing will improve the overall flow.', agent: 'Editor Agent', emoji: '✂️', color: 'bg-red-500' },
{ text: 'Cutting unnecessary scenes will enhance the narrative.', agent: 'Editor Agent', emoji: '✂️', color: 'bg-red-500' },
],
};
const AtlasAgentChat = () => {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const handleSendMessage = () => {
if (input.trim() === '') return;
// Add user message
setMessages((prevMessages) => [...prevMessages, { text: input, isUser: true }]);
// Simulate AI responses
const agents = Object.values(agentReplies).flat();
const delayedAgents = agents.map((agent, index) => ({ ...agent, delay: index * 0.5 }));
setTimeout(() => {
delayedAgents.forEach((agent, index) => {
setTimeout(() => {
setMessages((prevMessages) => [...prevMessages, { text: agent.text, agent: agent.agent, emoji: agent.emoji, color: agent.color }]);
}, agent.delay * 1000);
});
}, 500);
setInput('');
};
return (
<div className="h-screen flex flex-col">
<header className="fixed top-0 w-full bg-gray-900 text-white p-4 flex justify-between items-center z-10">
<h1 className="text-lg font-bold">Atlas Agent</h1>
<div className="w-6 h-6 bg-gray-700 rounded-full flex justify-center items-center">
<span className="text-xs">AI</span>
</div>
</header>
<div className="flex-1 overflow-y-auto p-4 pt-16 pb-24">
<AnimatePresence>
{messages.map((message, index) => (
<motion.div
key={index}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
className={`mb-4 ${message.isUser ? 'text-right' : ''}`}
>
{message.isUser ? (
<div className="inline-block bg-gray-200 p-2 rounded-lg">
{message.text}
</div>
) : (
<div className="flex items-center mb-2">
<span className={`mr-2 ${message.color} text-white p-1 rounded-full text-xs`}>{message.emoji}</span>
<span className="text-xs text-gray-500">{message.agent}</span>
</div>
)}
{!message.isUser && (
<div className="inline-block bg-gray-100 p-2 rounded-lg">
{message.text}
</div>
)}
</motion.div>
))}
</AnimatePresence>
</div>
<div className="fixed bottom-0 w-full bg-white p-4 border-t border-gray-200 flex items-center">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
className="flex-1 p-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Type a message..."
/>
<button
onClick={handleSendMessage}
className="ml-2 bg-blue-500 text-white p-2 rounded-lg hover:bg-blue-600 transition-colors"
>
<FiSend size={20} />
</button>
</div>
</div>
);
};
export default AtlasAgentChat;