'use client'; import { type FC, useCallback } from 'react'; import { EmbeddedChat } from '@/components/chat/EmbeddedChat'; import { useChatTurns, type AskFn } from '@/hooks/useChatTurns'; import { type BotTemplate } from '@/lib/bot-templates'; import { getAccentColorBgTintClass } from '@/lib/config/colors'; interface CreatedBot { template: BotTemplate; name: string; systemPrompt: string; } interface QuickChatProps { bot: CreatedBot; onReset: () => void; } export const QuickChat: FC = ({ bot, onReset }) => { const getWelcomeMessage = useCallback(() => { const { template, name } = bot; if (template.category === 'memorial') { if (template.id.includes('dog')) { return `*tail wagging excitedly* Hi! I'm ${name}! I'm so happy to see you! 🐕`; } if (template.id.includes('cat')) { return `*looks up with knowing eyes* ...Hello. It's ${name}. I suppose I'm glad you're here. *slow blink*`; } return `Hello, my dear. It's ${name}. I'm here with you now. What would you like to talk about?`; } if (template.category === 'legends') { return `Greetings. I am ${name}. What wisdom do you seek?`; } if (template.category === 'gods') { return `I am ${name}. Speak, mortal, and I shall listen.`; } if (template.category === 'magical') { if (template.id.includes('wizard')) { return `*adjusts pointed hat* Ah, a seeker of knowledge. I am ${name}. What mysteries draw you here?`; } if (template.id.includes('fairy')) { return `*sparkles appear* Hello hello! ✨ I'm ${name}! What wish can I help with today?`; } return `Greetings, traveler. I am ${name}. What brings you to me?`; } if (template.category === 'helpers') { if (template.id.includes('butler')) { return `Good day. I am ${name}, at your service. How may I assist you?`; } if (template.id.includes('chef')) { return `Buongiorno! I am ${name}. Are you hungry? Let's talk about food!`; } return `Hello! I'm ${name}. I'm here to help. What can I do for you?`; } return `Hello! I'm ${name}. How can I help you today?`; }, [bot]); const ask = useCallback( async (message, _history, signal) => { const response = await fetch('/api/quick-chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message, systemPrompt: bot.systemPrompt, additionalContext: `Bot name: ${bot.name}. Template: ${bot.template.name}.`, }), signal, }); if (!response.ok) throw new Error('Failed to get response'); const data = await response.json(); // API returns { success: true, data: { response: "..." } } return { content: data.data?.response || data.response || data.message || "I'm sorry, I couldn't generate a response.", }; }, [bot], ); const chat = useChatTurns(ask, { initial: [{ id: 'welcome', role: 'assistant', content: getWelcomeMessage() }], failedText: "I'm sorry, I had trouble responding. Please try again.", }); const accentTint = getAccentColorBgTintClass(bot.template.accentColor); return (
{/* Header */}
{bot.template.emoji}

{bot.name}

{bot.template.name}

{/* Chat Container */}
{/* Info Footer */}

This is a preview. In the full version, {bot.name} will remember your conversations and learn more about you over time.

); };