Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
397f009
1
Parent(s): e4e4689
revert: Restore AI Brain page to original version before redesign
Browse files- frontend/app/settings/brain/page.tsx +1035 -155
frontend/app/settings/brain/page.tsx
CHANGED
|
@@ -1,83 +1,293 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
-
import { useState, useEffect } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
-
import Link from 'next/link'
|
| 6 |
import {
|
| 7 |
-
Brain,
|
| 8 |
-
|
|
|
|
| 9 |
} from 'lucide-react'
|
| 10 |
-
import { motion } from 'framer-motion'
|
| 11 |
import { cn } from '@/lib/utils'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
{
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
gradient: 'from-violet-500 via-purple-500 to-indigo-600',
|
| 30 |
-
action: 'Открыть',
|
| 31 |
-
href: '/settings/playbook'
|
| 32 |
},
|
| 33 |
{
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
gradient: 'from-slate-600 via-slate-500 to-zinc-600',
|
| 39 |
-
action: 'Настроить',
|
| 40 |
-
href: '/settings/playbook'
|
| 41 |
},
|
| 42 |
{
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
gradient: 'from-amber-400 via-orange-400 to-yellow-500',
|
| 48 |
-
action: 'Настроить',
|
| 49 |
-
href: '/settings'
|
| 50 |
},
|
| 51 |
{
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
gradient: 'from-emerald-400 via-green-400 to-teal-500',
|
| 57 |
-
action: 'Открыть',
|
| 58 |
-
href: '/appointments'
|
| 59 |
},
|
| 60 |
{
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
gradient: 'from-cyan-400 via-sky-400 to-blue-500',
|
| 66 |
-
action: 'Открыть',
|
| 67 |
-
href: '/settings/products'
|
| 68 |
}
|
| 69 |
]
|
| 70 |
|
| 71 |
export default function BrainSettingsPage() {
|
| 72 |
const { user } = useAuth()
|
|
|
|
|
|
|
| 73 |
const [loading, setLoading] = useState(true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
useEffect(() => {
|
| 76 |
if (user) {
|
| 77 |
-
|
| 78 |
}
|
| 79 |
}, [user])
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if (loading) {
|
| 82 |
return (
|
| 83 |
<div className="flex items-center justify-center min-h-screen bg-background">
|
|
@@ -86,134 +296,804 @@ export default function BrainSettingsPage() {
|
|
| 86 |
)
|
| 87 |
}
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return (
|
| 90 |
<div className="min-h-screen bg-background p-8">
|
| 91 |
-
<div className="max-w-
|
| 92 |
-
{/* Header */}
|
| 93 |
<motion.div
|
| 94 |
initial={{ opacity: 0, y: -20 }}
|
| 95 |
animate={{ opacity: 1, y: 0 }}
|
| 96 |
className="mb-8"
|
| 97 |
>
|
| 98 |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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
</div>
|
| 218 |
</div>
|
| 219 |
)
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
+
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
|
|
|
| 5 |
import {
|
| 6 |
+
Brain, Plus, X, Save, Loader2, Sparkles, Target, TrendingUp, Zap, Shield, Users,
|
| 7 |
+
BookOpen, Award, Ban, Calculator, DollarSign, CheckCircle2, AlertCircle,
|
| 8 |
+
LayoutGrid, Calendar, ShoppingBag, Briefcase, FileText, Upload, Trash2, Search
|
| 9 |
} from 'lucide-react'
|
| 10 |
+
import { motion, AnimatePresence } from 'framer-motion'
|
| 11 |
import { cn } from '@/lib/utils'
|
| 12 |
+
import { api, knowledgeApi } from '@/lib/api'
|
| 13 |
+
import BookingSettings from '@/components/BookingSettings'
|
| 14 |
+
import ProductSettings from '@/components/settings/ProductSettings'
|
| 15 |
+
import { useDropzone } from 'react-dropzone'
|
| 16 |
+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
| 17 |
+
import { useToast } from '@/contexts/ToastContext'
|
| 18 |
|
| 19 |
+
interface AISettings {
|
| 20 |
+
business_description: string
|
| 21 |
+
selling_style: 'Consultative' | 'Aggressive' | 'Friendly' | 'Educational'
|
| 22 |
+
custom_fields: string[]
|
| 23 |
+
ideal_customer_profile: string
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
interface AIPersona {
|
| 27 |
+
business_type: 'product' | 'service' | 'hybrid'
|
| 28 |
+
tone_of_voice: 'Professional' | 'Friendly' | 'Empathetic' | 'Bold'
|
| 29 |
+
sales_methodology: 'SPIN' | 'Sandler' | 'Challenger' | 'Consultative' | 'MEDDIC'
|
| 30 |
+
custom_instructions: string
|
| 31 |
+
banned_words: string[]
|
| 32 |
+
manager_monthly_salary: number
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
type TabType = 'persona' | 'knowledge' | 'catalog' | 'booking'
|
| 36 |
+
|
| 37 |
+
interface BotIdentity {
|
| 38 |
+
bot_name: string
|
| 39 |
+
bot_role: string
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const TONE_OPTIONS = [
|
| 43 |
+
{ value: 'Professional', label: 'Профессиональный', icon: Shield, description: 'Деловой, формальный тон' },
|
| 44 |
+
{ value: 'Friendly', label: 'Дружелюбный', icon: Users, description: 'Теплый, неформальный' },
|
| 45 |
+
{ value: 'Empathetic', label: 'Эмпатичный', icon: Sparkles, description: 'Понимающий, заботливый' },
|
| 46 |
+
{ value: 'Bold', label: 'Уверенный', icon: Zap, description: 'Прямолинейный, смелый' }
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
const METHODOLOGY_OPTIONS = [
|
| 50 |
{
|
| 51 |
+
value: 'SPIN',
|
| 52 |
+
label: 'SPIN Selling',
|
| 53 |
+
icon: Target,
|
| 54 |
+
description: 'Ситуация → Проблема → Импликация → Выгода. Глубокие вопросы для понимания потребностей.'
|
|
|
|
|
|
|
|
|
|
| 55 |
},
|
| 56 |
{
|
| 57 |
+
value: 'Sandler',
|
| 58 |
+
label: 'Sandler System',
|
| 59 |
+
icon: Award,
|
| 60 |
+
description: 'Построение доверия, поиск боли, обсуждение бюджета рано. "Не продавай, помогай купить".'
|
|
|
|
|
|
|
|
|
|
| 61 |
},
|
| 62 |
{
|
| 63 |
+
value: 'Challenger',
|
| 64 |
+
label: 'Challenger Sale',
|
| 65 |
+
icon: Zap,
|
| 66 |
+
description: 'Учи клиента, бросай вызов мышлению, контролируй разговор. Для сложных продаж.'
|
|
|
|
|
|
|
|
|
|
| 67 |
},
|
| 68 |
{
|
| 69 |
+
value: 'Consultative',
|
| 70 |
+
label: 'Консультативные продажи',
|
| 71 |
+
icon: Users,
|
| 72 |
+
description: 'Будь советником. Выявляй потребности, предлагай решения. Долгосрочные отношения.'
|
|
|
|
|
|
|
|
|
|
| 73 |
},
|
| 74 |
{
|
| 75 |
+
value: 'MEDDIC',
|
| 76 |
+
label: 'MEDDIC',
|
| 77 |
+
icon: BookOpen,
|
| 78 |
+
description: 'Метрики, Покупатель, Критерии, Процесс, Боль, Чемпион. Для enterprise продаж.'
|
|
|
|
|
|
|
|
|
|
| 79 |
}
|
| 80 |
]
|
| 81 |
|
| 82 |
export default function BrainSettingsPage() {
|
| 83 |
const { user } = useAuth()
|
| 84 |
+
const toast = useToast()
|
| 85 |
+
const queryClient = useQueryClient()
|
| 86 |
const [loading, setLoading] = useState(true)
|
| 87 |
+
const [saving, setSaving] = useState(false)
|
| 88 |
+
const [activeTab, setActiveTab] = useState<TabType>('persona')
|
| 89 |
+
const [bookingSettings, setBookingSettings] = useState<any>(null)
|
| 90 |
+
const [newField, setNewField] = useState('')
|
| 91 |
+
const [newBannedWord, setNewBannedWord] = useState('')
|
| 92 |
+
|
| 93 |
+
// Knowledge State
|
| 94 |
+
const [searchQuery, setSearchQuery] = useState('')
|
| 95 |
+
const [uploadedFiles, setUploadedFiles] = useState<string[]>([])
|
| 96 |
+
|
| 97 |
+
const [settings, setSettings] = useState<AISettings>({
|
| 98 |
+
business_description: '',
|
| 99 |
+
selling_style: 'Consultative',
|
| 100 |
+
custom_fields: [], // Empty by default - user must configure
|
| 101 |
+
ideal_customer_profile: ''
|
| 102 |
+
})
|
| 103 |
+
|
| 104 |
+
const [persona, setPersona] = useState<AIPersona>({
|
| 105 |
+
business_type: 'hybrid',
|
| 106 |
+
tone_of_voice: 'Professional', // Required field, needs UI preselection
|
| 107 |
+
sales_methodology: 'Consultative', // Required field, needs UI preselection
|
| 108 |
+
custom_instructions: '',
|
| 109 |
+
banned_words: [],
|
| 110 |
+
manager_monthly_salary: 1000
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
const [botIdentity, setBotIdentity] = useState<BotIdentity>({
|
| 114 |
+
bot_name: '',
|
| 115 |
+
bot_role: ''
|
| 116 |
+
})
|
| 117 |
+
|
| 118 |
+
// --- Knowledge Queries ---
|
| 119 |
+
const { data: knowledgeData, isLoading: knowledgeLoading } = useQuery({
|
| 120 |
+
queryKey: ['knowledge', user?.tenant_id],
|
| 121 |
+
queryFn: () => knowledgeApi.list({ limit: 100 }),
|
| 122 |
+
enabled: !!user && activeTab === 'knowledge',
|
| 123 |
+
})
|
| 124 |
+
|
| 125 |
+
const { data: searchResults, isLoading: isSearching } = useQuery({
|
| 126 |
+
queryKey: ['knowledge-search', user?.tenant_id, searchQuery],
|
| 127 |
+
queryFn: () => knowledgeApi.search(searchQuery, 10),
|
| 128 |
+
enabled: !!user && searchQuery.length > 2 && activeTab === 'knowledge',
|
| 129 |
+
})
|
| 130 |
+
|
| 131 |
+
const uploadMutation = useMutation({
|
| 132 |
+
mutationFn: async (file: File) => {
|
| 133 |
+
if (!user) throw new Error('Пользователь не авторизован')
|
| 134 |
+
return knowledgeApi.upload(file)
|
| 135 |
+
},
|
| 136 |
+
onSuccess: (data, file) => {
|
| 137 |
+
queryClient.invalidateQueries({ queryKey: ['knowledge', user?.tenant_id] })
|
| 138 |
+
toast.success('Успех!', `Файл "${file.name}" успешно загружен и изучен AI`)
|
| 139 |
+
setUploadedFiles(prev => [...prev, file.name])
|
| 140 |
+
setTimeout(() => {
|
| 141 |
+
setUploadedFiles(prev => prev.filter(f => f !== file.name))
|
| 142 |
+
}, 3000)
|
| 143 |
+
},
|
| 144 |
+
onError: (error: Error) => {
|
| 145 |
+
toast.error('Ошибка', 'Не удалось загрузить файл')
|
| 146 |
+
},
|
| 147 |
+
})
|
| 148 |
+
|
| 149 |
+
const deleteMutation = useMutation({
|
| 150 |
+
mutationFn: async (id: string) => {
|
| 151 |
+
// Implement delete API call here if available, currently mock or pending
|
| 152 |
+
return Promise.resolve()
|
| 153 |
+
},
|
| 154 |
+
onSuccess: () => {
|
| 155 |
+
queryClient.invalidateQueries({ queryKey: ['knowledge', user?.tenant_id] })
|
| 156 |
+
toast.success('Удалено', 'Запись удалена из базы знаний')
|
| 157 |
+
}
|
| 158 |
+
})
|
| 159 |
+
|
| 160 |
+
const onDrop = useCallback((acceptedFiles: File[]) => {
|
| 161 |
+
if (acceptedFiles.length === 0) return
|
| 162 |
+
|
| 163 |
+
acceptedFiles.forEach((file) => {
|
| 164 |
+
uploadMutation.mutate(file)
|
| 165 |
+
})
|
| 166 |
+
}, [uploadMutation])
|
| 167 |
+
|
| 168 |
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
| 169 |
+
onDrop,
|
| 170 |
+
accept: {
|
| 171 |
+
'application/pdf': ['.pdf'],
|
| 172 |
+
'text/plain': ['.txt'],
|
| 173 |
+
},
|
| 174 |
+
})
|
| 175 |
+
// -------------------------
|
| 176 |
|
| 177 |
useEffect(() => {
|
| 178 |
if (user) {
|
| 179 |
+
fetchSettings()
|
| 180 |
}
|
| 181 |
}, [user])
|
| 182 |
|
| 183 |
+
const fetchSettings = async () => {
|
| 184 |
+
try {
|
| 185 |
+
// Using /tenants/me shortcut which is safer and cleaner
|
| 186 |
+
const response = await api.get('/api/v1/tenants/me')
|
| 187 |
+
const data = response.data
|
| 188 |
+
|
| 189 |
+
if (data.ai_settings) {
|
| 190 |
+
setSettings(data.ai_settings)
|
| 191 |
+
}
|
| 192 |
+
setPersona({
|
| 193 |
+
business_type: data.business_type || 'hybrid',
|
| 194 |
+
tone_of_voice: data.tone_of_voice || 'Professional',
|
| 195 |
+
sales_methodology: data.sales_methodology || 'Consultative',
|
| 196 |
+
custom_instructions: data.custom_instructions || '',
|
| 197 |
+
banned_words: data.banned_words || [],
|
| 198 |
+
manager_monthly_salary: data.manager_monthly_salary || 1000
|
| 199 |
+
})
|
| 200 |
+
setBotIdentity({
|
| 201 |
+
bot_name: data.ai_identity?.bot_name || '',
|
| 202 |
+
bot_role: data.ai_identity?.bot_role || ''
|
| 203 |
+
})
|
| 204 |
+
setBookingSettings(data.booking_settings)
|
| 205 |
+
} catch (error) {
|
| 206 |
+
console.error('Failed to fetch AI settings:', error)
|
| 207 |
+
} finally {
|
| 208 |
+
setLoading(false)
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
const handleSave = async () => {
|
| 213 |
+
if (!user?.tenant_id) return
|
| 214 |
+
|
| 215 |
+
setSaving(true)
|
| 216 |
+
try {
|
| 217 |
+
await api.patch(`/api/v1/tenants/${user.tenant_id}`, {
|
| 218 |
+
ai_settings: settings,
|
| 219 |
+
ai_identity: {
|
| 220 |
+
bot_name: botIdentity.bot_name,
|
| 221 |
+
bot_role: botIdentity.bot_role
|
| 222 |
+
},
|
| 223 |
+
...persona
|
| 224 |
+
})
|
| 225 |
+
toast.success('Успех!', 'Настройки AI Brain сохранены')
|
| 226 |
+
} catch (error) {
|
| 227 |
+
console.error('Failed to save AI settings:', error)
|
| 228 |
+
toast.error('Ошибка', 'Не удалось сохранить настройки')
|
| 229 |
+
} finally {
|
| 230 |
+
setSaving(false)
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
const handleBookingSave = async (newSettings: any) => {
|
| 235 |
+
if (!user?.tenant_id) return
|
| 236 |
+
try {
|
| 237 |
+
await api.patch(`/api/v1/tenants/${user.tenant_id}`, {
|
| 238 |
+
booking_settings: newSettings
|
| 239 |
+
})
|
| 240 |
+
toast.success('Успех!', 'Настройки записи сохранены')
|
| 241 |
+
setBookingSettings(newSettings)
|
| 242 |
+
} catch (error) {
|
| 243 |
+
console.error('Failed to save booking settings:', error)
|
| 244 |
+
toast.error('Ошибка', 'Не удалось сохранить настройки записи')
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
const addCustomField = () => {
|
| 250 |
+
if (!newField.trim()) return
|
| 251 |
+
if (settings.custom_fields.includes(newField.trim())) {
|
| 252 |
+
toast.error('Ошибка', 'Это поле уже добавлено')
|
| 253 |
+
return
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
setSettings({
|
| 257 |
+
...settings,
|
| 258 |
+
custom_fields: [...settings.custom_fields, newField.trim()]
|
| 259 |
+
})
|
| 260 |
+
setNewField('')
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
const removeCustomField = (field: string) => {
|
| 264 |
+
setSettings({
|
| 265 |
+
...settings,
|
| 266 |
+
custom_fields: settings.custom_fields.filter(f => f !== field)
|
| 267 |
+
})
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
const addBannedWord = () => {
|
| 271 |
+
if (!newBannedWord.trim()) return
|
| 272 |
+
if (persona.banned_words.includes(newBannedWord.trim())) {
|
| 273 |
+
toast.error('Ошибка', 'Это слово уже в списке')
|
| 274 |
+
return
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
setPersona({
|
| 278 |
+
...persona,
|
| 279 |
+
banned_words: [...persona.banned_words, newBannedWord.trim()]
|
| 280 |
+
})
|
| 281 |
+
setNewBannedWord('')
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
const removeBannedWord = (word: string) => {
|
| 285 |
+
setPersona({
|
| 286 |
+
...persona,
|
| 287 |
+
banned_words: persona.banned_words.filter(w => w !== word)
|
| 288 |
+
})
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
if (loading) {
|
| 292 |
return (
|
| 293 |
<div className="flex items-center justify-center min-h-screen bg-background">
|
|
|
|
| 296 |
)
|
| 297 |
}
|
| 298 |
|
| 299 |
+
const container = {
|
| 300 |
+
hidden: { opacity: 0 },
|
| 301 |
+
show: {
|
| 302 |
+
opacity: 1,
|
| 303 |
+
transition: {
|
| 304 |
+
staggerChildren: 0.1
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
const item = {
|
| 310 |
+
hidden: { opacity: 0, y: 20 },
|
| 311 |
+
show: { opacity: 1, y: 0 }
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
return (
|
| 315 |
<div className="min-h-screen bg-background p-8">
|
| 316 |
+
<div className="max-w-5xl mx-auto">
|
|
|
|
| 317 |
<motion.div
|
| 318 |
initial={{ opacity: 0, y: -20 }}
|
| 319 |
animate={{ opacity: 1, y: 0 }}
|
| 320 |
className="mb-8"
|
| 321 |
>
|
| 322 |
+
<div className="flex items-center gap-4 mb-6">
|
| 323 |
+
<div className="p-3 bg-gradient-to-br from-indigo-600 to-purple-600 rounded-2xl shadow-lg shadow-indigo-500/20">
|
| 324 |
+
<Brain className="w-8 h-8 text-white" />
|
| 325 |
+
</div>
|
| 326 |
+
<div>
|
| 327 |
+
<h1 className="text-3xl font-bold text-white mb-1 tracking-tight">
|
| 328 |
+
База Знаний (Brain)
|
| 329 |
+
</h1>
|
| 330 |
+
<p className="text-slate-400">
|
| 331 |
+
Управление интеллектом, знаниями и навыками вашего цифрового сотрудника
|
| 332 |
+
</p>
|
| 333 |
+
</div>
|
| 334 |
+
</div>
|
| 335 |
+
|
| 336 |
+
{/* Navigation Tabs */}
|
| 337 |
+
<div className="flex flex-wrap gap-2 p-1 bg-[#0D0E18] rounded-xl border border-white/10 w-fit">
|
| 338 |
+
<button
|
| 339 |
+
onClick={() => setActiveTab('persona')}
|
| 340 |
+
className={cn(
|
| 341 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 342 |
+
activeTab === 'persona'
|
| 343 |
+
? "bg-indigo-600 text-white shadow-sm"
|
| 344 |
+
: "text-slate-400 hover:text-white hover:bg-white/5"
|
| 345 |
+
)}
|
| 346 |
+
>
|
| 347 |
+
<Sparkles className="w-4 h-4" />
|
| 348 |
+
Личность & Правила
|
| 349 |
+
</button>
|
| 350 |
+
|
| 351 |
+
<button
|
| 352 |
+
onClick={() => setActiveTab('knowledge')}
|
| 353 |
+
className={cn(
|
| 354 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 355 |
+
activeTab === 'knowledge'
|
| 356 |
+
? "bg-indigo-600 text-white shadow-sm"
|
| 357 |
+
: "text-slate-400 hover:text-white hover:bg-white/5"
|
| 358 |
+
)}
|
| 359 |
+
>
|
| 360 |
+
<FileText className="w-4 h-4" />
|
| 361 |
+
Знания (RAG)
|
| 362 |
+
</button>
|
| 363 |
+
|
| 364 |
+
<button
|
| 365 |
+
onClick={() => setActiveTab('catalog')}
|
| 366 |
+
className={cn(
|
| 367 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 368 |
+
activeTab === 'catalog'
|
| 369 |
+
? "bg-indigo-600 text-white shadow-sm"
|
| 370 |
+
: "text-slate-400 hover:text-white hover:bg-white/5"
|
| 371 |
+
)}
|
| 372 |
+
>
|
| 373 |
+
<ShoppingBag className="w-4 h-4" />
|
| 374 |
+
Товары
|
| 375 |
+
</button>
|
| 376 |
+
|
| 377 |
+
<button
|
| 378 |
+
onClick={() => setActiveTab('booking')}
|
| 379 |
+
className={cn(
|
| 380 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 381 |
+
activeTab === 'booking'
|
| 382 |
+
? "bg-indigo-600 text-white shadow-sm"
|
| 383 |
+
: "text-slate-400 hover:text-white hover:bg-white/5"
|
| 384 |
+
)}
|
| 385 |
+
>
|
| 386 |
+
<Calendar className="w-4 h-4" />
|
| 387 |
+
Запись (Booking)
|
| 388 |
+
</button>
|
| 389 |
+
</div>
|
| 390 |
</motion.div>
|
| 391 |
|
| 392 |
+
{/* --- CONTENT SECTIONS --- */}
|
| 393 |
+
|
| 394 |
+
{activeTab === 'booking' && (
|
| 395 |
+
<BookingSettings
|
| 396 |
+
settings={bookingSettings}
|
| 397 |
+
onSave={handleBookingSave}
|
| 398 |
+
/>
|
| 399 |
+
)}
|
| 400 |
+
|
| 401 |
+
{activeTab === 'catalog' && (
|
| 402 |
+
<motion.div
|
| 403 |
+
variants={container}
|
| 404 |
+
initial="hidden"
|
| 405 |
+
animate="show"
|
| 406 |
+
>
|
| 407 |
+
<ProductSettings />
|
| 408 |
+
</motion.div>
|
| 409 |
+
)}
|
| 410 |
+
|
| 411 |
+
{activeTab === 'knowledge' && (
|
| 412 |
+
<motion.div
|
| 413 |
+
variants={container}
|
| 414 |
+
initial="hidden"
|
| 415 |
+
animate="show"
|
| 416 |
+
className="space-y-6"
|
| 417 |
+
>
|
| 418 |
+
{/* Upload Zone */}
|
| 419 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 420 |
+
<h2 className="text-lg font-bold text-slate-900 mb-6 flex items-center gap-2">
|
| 421 |
+
<Upload className="w-5 h-5 text-indigo-600" />
|
| 422 |
+
Загрузить файлы
|
| 423 |
+
</h2>
|
| 424 |
+
<div
|
| 425 |
+
{...getRootProps()}
|
| 426 |
+
className={cn(
|
| 427 |
+
"border-2 border-dashed rounded-xl p-12 text-center cursor-pointer transition-all duration-300 relative overflow-hidden",
|
| 428 |
+
isDragActive
|
| 429 |
+
? "border-indigo-500 bg-indigo-50/50 scale-[1.01]"
|
| 430 |
+
: "border-slate-200 hover:border-indigo-400 hover:bg-slate-50",
|
| 431 |
+
uploadMutation.isPending && "opacity-75 cursor-wait"
|
| 432 |
+
)}
|
| 433 |
+
>
|
| 434 |
+
<input {...getInputProps()} />
|
| 435 |
+
<div className="flex flex-col items-center gap-4 relative z-10">
|
| 436 |
+
{uploadMutation.isPending ? (
|
| 437 |
+
<>
|
| 438 |
+
<div className="p-4 bg-indigo-50 rounded-full">
|
| 439 |
+
<Loader2 className="w-8 h-8 text-indigo-600 animate-spin" />
|
| 440 |
+
</div>
|
| 441 |
+
<div>
|
| 442 |
+
<p className="text-indigo-900 font-bold text-lg">Обработка файла...</p>
|
| 443 |
+
<p className="text-sm text-indigo-600">AI анализирует содержимое</p>
|
| 444 |
+
</div>
|
| 445 |
+
</>
|
| 446 |
+
) : isDragActive ? (
|
| 447 |
+
<>
|
| 448 |
+
<div className="p-4 bg-indigo-100 rounded-full animate-bounce">
|
| 449 |
+
<Upload className="w-8 h-8 text-indigo-600" />
|
| 450 |
</div>
|
| 451 |
+
<p className="text-indigo-900 font-bold text-lg">Отпустите файлы здесь...</p>
|
| 452 |
+
</>
|
| 453 |
+
) : (
|
| 454 |
+
<>
|
| 455 |
+
<div className="p-4 bg-slate-100 rounded-full group-hover:bg-indigo-50 transition-colors">
|
| 456 |
+
<Upload className="w-8 h-8 text-slate-400 group-hover:text-indigo-600 transition-colors" />
|
| 457 |
+
</div>
|
| 458 |
+
<div>
|
| 459 |
+
<p className="text-slate-900 font-bold text-lg mb-1">
|
| 460 |
+
Перетащите PDF или TXT файлы сюда
|
| 461 |
+
</p>
|
| 462 |
+
<p className="text-sm text-slate-500">или кликните для выбора файлов</p>
|
| 463 |
+
</div>
|
| 464 |
+
<div className="flex items-center gap-4 text-xs font-medium text-slate-400 mt-2">
|
| 465 |
+
<span className="flex items-center gap-1.5 bg-slate-50 px-2 py-1 rounded-md border border-slate-100">
|
| 466 |
+
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-500" />
|
| 467 |
+
PDF документы
|
| 468 |
+
</span>
|
| 469 |
+
<span className="flex items-center gap-1.5 bg-slate-50 px-2 py-1 rounded-md border border-slate-100">
|
| 470 |
+
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-500" />
|
| 471 |
+
TXT файлы
|
| 472 |
+
</span>
|
| 473 |
+
</div>
|
| 474 |
+
</>
|
| 475 |
+
)}
|
| 476 |
+
</div>
|
| 477 |
+
</div>
|
| 478 |
+
|
| 479 |
+
{/* Uploaded Files List */}
|
| 480 |
+
<AnimatePresence>
|
| 481 |
+
{uploadedFiles.length > 0 && (
|
| 482 |
+
<div className="mt-6 space-y-2">
|
| 483 |
+
{uploadedFiles.map((fileName, idx) => (
|
| 484 |
+
<motion.div
|
| 485 |
+
key={`${fileName}-${idx}`}
|
| 486 |
+
initial={{ opacity: 0, x: -20 }}
|
| 487 |
+
animate={{ opacity: 1, x: 0 }}
|
| 488 |
+
exit={{ opacity: 0, x: 20 }}
|
| 489 |
+
className="flex items-center gap-3 p-3 bg-emerald-50 border border-emerald-100 rounded-xl text-emerald-700"
|
| 490 |
+
>
|
| 491 |
+
<CheckCircle2 className="w-5 h-5 text-emerald-500 flex-shrink-0" />
|
| 492 |
+
<span className="text-sm font-medium truncate flex-1">{fileName}</span>
|
| 493 |
+
<span className="text-xs font-bold bg-white/50 px-2 py-1 rounded-md">Загружено</span>
|
| 494 |
+
</motion.div>
|
| 495 |
+
))}
|
| 496 |
+
</div>
|
| 497 |
+
)}
|
| 498 |
+
</AnimatePresence>
|
| 499 |
+
</motion.div>
|
| 500 |
+
|
| 501 |
+
{/* Search & Results */}
|
| 502 |
+
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
| 503 |
+
{/* Search Column */}
|
| 504 |
+
<motion.div variants={item} className="lg:col-span-2 space-y-6">
|
| 505 |
+
<div className="bg-white rounded-2xl shadow-sm border border-slate-200 p-6">
|
| 506 |
+
<h2 className="text-lg font-bold text-slate-900 mb-4 flex items-center gap-2">
|
| 507 |
+
<Search className="w-5 h-5 text-indigo-600" />
|
| 508 |
+
Проверка знаний (Тест)
|
| 509 |
+
</h2>
|
| 510 |
+
<div className="relative">
|
| 511 |
+
<Search className="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5 text-slate-400" />
|
| 512 |
+
<input
|
| 513 |
+
type="text"
|
| 514 |
+
placeholder="Введите вопрос или ключевые слова..."
|
| 515 |
+
value={searchQuery}
|
| 516 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 517 |
+
className="w-full pl-12 pr-10 py-4 bg-slate-50 border-2 border-slate-200 rounded-xl focus:ring-4 focus:ring-indigo-500/10 focus:border-indigo-500 transition-all font-medium text-slate-900 placeholder:text-slate-400"
|
| 518 |
+
/>
|
| 519 |
+
{searchQuery && (
|
| 520 |
+
<button
|
| 521 |
+
onClick={() => setSearchQuery('')}
|
| 522 |
+
className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600"
|
| 523 |
+
>
|
| 524 |
+
<X className="w-4 h-4" />
|
| 525 |
+
</button>
|
| 526 |
+
)}
|
| 527 |
+
</div>
|
| 528 |
|
| 529 |
+
<AnimatePresence mode="wait">
|
| 530 |
+
{searchQuery.length > 2 && (
|
| 531 |
+
<motion.div
|
| 532 |
+
initial={{ opacity: 0, height: 0 }}
|
| 533 |
+
animate={{ opacity: 1, height: 'auto' }}
|
| 534 |
+
exit={{ opacity: 0, height: 0 }}
|
| 535 |
+
className="mt-6"
|
| 536 |
+
>
|
| 537 |
+
<div className="flex items-center justify-between mb-4">
|
| 538 |
+
<h3 className="font-bold text-slate-900 text-sm flex items-center gap-2">
|
| 539 |
+
<Sparkles className="w-4 h-4 text-indigo-600" />
|
| 540 |
+
Результаты поиска
|
| 541 |
+
</h3>
|
| 542 |
+
<span className="text-xs font-medium text-slate-500 bg-slate-100 px-2 py-1 rounded-md">
|
| 543 |
+
{searchResults?.count || 0} найдено
|
| 544 |
+
</span>
|
| 545 |
+
</div>
|
| 546 |
+
|
| 547 |
+
{isSearching ? (
|
| 548 |
+
<div className="flex flex-col items-center justify-center py-12 text-slate-400">
|
| 549 |
+
<Loader2 className="w-8 h-8 animate-spin mb-2" />
|
| 550 |
+
<span className="text-sm">Ищем ответы...</span>
|
| 551 |
+
</div>
|
| 552 |
+
) : searchResults?.results?.length > 0 ? (
|
| 553 |
+
<div className="space-y-4">
|
| 554 |
+
{searchResults.results.map((result: any, idx: number) => (
|
| 555 |
+
<motion.div
|
| 556 |
+
key={idx}
|
| 557 |
+
initial={{ opacity: 0, y: 10 }}
|
| 558 |
+
animate={{ opacity: 1, y: 0 }}
|
| 559 |
+
transition={{ delay: idx * 0.05 }}
|
| 560 |
+
className="group p-4 bg-white border border-slate-200 rounded-xl hover:border-indigo-300 hover:shadow-md transition-all relative overflow-hidden"
|
| 561 |
+
>
|
| 562 |
+
<div className="absolute left-0 top-0 bottom-0 w-1 bg-indigo-500 opacity-0 group-hover:opacity-100 transition-opacity" />
|
| 563 |
+
<p className="text-sm text-slate-700 leading-relaxed mb-3">{result.content}</p>
|
| 564 |
+
<div className="flex items-center justify-between text-xs">
|
| 565 |
+
<span className="font-bold text-indigo-600 bg-indigo-50 px-2 py-1 rounded-md">
|
| 566 |
+
{((result.similarity || 0) * 100).toFixed(0)}% совпадение
|
| 567 |
+
</span>
|
| 568 |
+
<span className="text-slate-400 font-medium uppercase tracking-wide">
|
| 569 |
+
{result.category || 'Общее'}
|
| 570 |
+
</span>
|
| 571 |
+
</div>
|
| 572 |
+
</motion.div>
|
| 573 |
+
))}
|
| 574 |
+
</div>
|
| 575 |
+
) : (
|
| 576 |
+
<div className="text-center py-12 bg-slate-50 rounded-xl border border-dashed border-slate-200">
|
| 577 |
+
<AlertCircle className="w-10 h-10 mx-auto text-slate-300 mb-3" />
|
| 578 |
+
<p className="text-slate-900 font-medium">Ничего не найдено</p>
|
| 579 |
+
<p className="text-sm text-slate-500">Попробуйте из��енить запрос</p>
|
| 580 |
+
</div>
|
| 581 |
+
)}
|
| 582 |
+
</motion.div>
|
| 583 |
+
)}
|
| 584 |
+
</AnimatePresence>
|
| 585 |
+
</div>
|
| 586 |
+
</motion.div>
|
| 587 |
+
|
| 588 |
+
{/* Files List Column */}
|
| 589 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 flex flex-col h-[600px]">
|
| 590 |
+
<div className="p-6 border-b border-slate-100 flex items-center justify-between bg-slate-50/50 rounded-t-2xl">
|
| 591 |
+
<h2 className="text-lg font-bold text-slate-900 flex items-center gap-2">
|
| 592 |
+
<FileText className="w-5 h-5 text-indigo-600" />
|
| 593 |
+
Список файлов
|
| 594 |
+
</h2>
|
| 595 |
+
<span className="text-xs font-bold bg-white border border-slate-200 px-2 py-1 rounded-md text-slate-600">
|
| 596 |
+
{knowledgeData?.count || 0}
|
| 597 |
+
</span>
|
| 598 |
+
</div>
|
| 599 |
+
|
| 600 |
+
<div className="flex-1 overflow-y-auto p-4 space-y-3 custom-scrollbar">
|
| 601 |
+
{knowledgeLoading ? (
|
| 602 |
+
<div className="flex items-center justify-center h-full text-slate-400">
|
| 603 |
+
<Loader2 className="w-8 h-8 animate-spin" />
|
| 604 |
+
</div>
|
| 605 |
+
) : knowledgeData?.entries?.length > 0 ? (
|
| 606 |
+
knowledgeData.entries.map((entry: any) => (
|
| 607 |
+
<motion.div
|
| 608 |
+
key={entry.id}
|
| 609 |
+
layout
|
| 610 |
+
initial={{ opacity: 0 }}
|
| 611 |
+
animate={{ opacity: 1 }}
|
| 612 |
+
className="group p-4 bg-white border border-slate-200 rounded-xl hover:border-indigo-300 hover:shadow-sm transition-all"
|
| 613 |
+
>
|
| 614 |
+
<div className="flex items-start gap-3">
|
| 615 |
+
<div className="p-2 bg-indigo-50 text-indigo-600 rounded-lg flex-shrink-0 group-hover:bg-indigo-100 transition-colors">
|
| 616 |
+
<FileText className="w-5 h-5" />
|
| 617 |
+
</div>
|
| 618 |
+
<div className="flex-1 min-w-0">
|
| 619 |
+
<div className="flex items-center gap-2 mb-1">
|
| 620 |
+
<span className="text-xs font-bold text-indigo-600 uppercase tracking-wide bg-indigo-50 px-1.5 py-0.5 rounded">
|
| 621 |
+
{entry.category || 'DOC'}
|
| 622 |
+
</span>
|
| 623 |
+
<span className="text-[10px] text-slate-400">
|
| 624 |
+
{new Date(entry.created_at).toLocaleDateString()}
|
| 625 |
+
</span>
|
| 626 |
+
</div>
|
| 627 |
+
<p className="text-sm text-slate-700 line-clamp-2 leading-relaxed mb-2">
|
| 628 |
+
{entry.content}
|
| 629 |
+
</p>
|
| 630 |
+
<div className="flex items-center justify-between">
|
| 631 |
+
<span className="text-xs text-slate-500 font-medium bg-slate-50 px-2 py-1 rounded border border-slate-100">
|
| 632 |
+
{entry.source_type}
|
| 633 |
+
</span>
|
| 634 |
+
<button
|
| 635 |
+
onClick={() => deleteMutation.mutate(entry.id)}
|
| 636 |
+
className="p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors opacity-0 group-hover:opacity-100"
|
| 637 |
+
title="Удалить"
|
| 638 |
+
>
|
| 639 |
+
<Trash2 className="w-4 h-4" />
|
| 640 |
+
</button>
|
| 641 |
+
</div>
|
| 642 |
+
</div>
|
| 643 |
+
</div>
|
| 644 |
+
</motion.div>
|
| 645 |
+
))
|
| 646 |
+
) : (
|
| 647 |
+
<div className="flex flex-col items-center justify-center h-full text-center p-8">
|
| 648 |
+
<div className="w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4">
|
| 649 |
+
<FileText className="w-8 h-8 text-slate-300" />
|
| 650 |
</div>
|
| 651 |
+
<h3 className="font-bold text-slate-900 mb-1">Пусто</h3>
|
| 652 |
+
<p className="text-sm text-slate-500">Загрузите файлы, чтобы наполнить базу знаний</p>
|
| 653 |
</div>
|
| 654 |
+
)}
|
| 655 |
+
</div>
|
| 656 |
+
</motion.div>
|
| 657 |
+
</div>
|
| 658 |
+
</motion.div>
|
| 659 |
+
)}
|
| 660 |
|
| 661 |
+
{activeTab === 'persona' && (
|
| 662 |
+
<motion.div
|
| 663 |
+
variants={container}
|
| 664 |
+
initial="hidden"
|
| 665 |
+
animate="show"
|
| 666 |
+
className="space-y-6"
|
| 667 |
+
>
|
| 668 |
+
{/* Bot Identity - NEW SECTION */}
|
| 669 |
+
<motion.div variants={item} className="bg-gradient-to-br from-indigo-50 to-purple-50 rounded-2xl border border-indigo-100 p-8 shadow-sm">
|
| 670 |
+
<div className="flex items-center gap-3 mb-6">
|
| 671 |
+
<div className="p-2 bg-indigo-100 rounded-xl text-indigo-600">
|
| 672 |
+
<Brain className="w-6 h-6" />
|
| 673 |
+
</div>
|
| 674 |
+
<div>
|
| 675 |
+
<h2 className="text-xl font-bold text-slate-900">Личность бота</h2>
|
| 676 |
+
<p className="text-sm text-slate-600">Имя и роль вашего AI помощника</p>
|
| 677 |
+
</div>
|
| 678 |
+
</div>
|
| 679 |
+
|
| 680 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 681 |
+
<div>
|
| 682 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">
|
| 683 |
+
Имя бота
|
| 684 |
+
</label>
|
| 685 |
+
<input
|
| 686 |
+
type="text"
|
| 687 |
+
value={botIdentity.bot_name}
|
| 688 |
+
onChange={(e) => setBotIdentity({ ...botIdentity, bot_name: e.target.value })}
|
| 689 |
+
placeholder="Например: Alex, Мария, Дмитрий"
|
| 690 |
+
className="w-full px-4 py-3 bg-white border border-indigo-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none"
|
| 691 |
+
/>
|
| 692 |
+
<p className="mt-2 text-xs text-slate-500">
|
| 693 |
+
Как бот будет представляться клиентам
|
| 694 |
+
</p>
|
| 695 |
+
</div>
|
| 696 |
+
|
| 697 |
+
<div>
|
| 698 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">
|
| 699 |
+
Роль / Должность
|
| 700 |
+
</label>
|
| 701 |
+
<input
|
| 702 |
+
type="text"
|
| 703 |
+
value={botIdentity.bot_role}
|
| 704 |
+
onChange={(e) => setBotIdentity({ ...botIdentity, bot_role: e.target.value })}
|
| 705 |
+
placeholder="Например: Менеджер по продажам, Консультант"
|
| 706 |
+
className="w-full px-4 py-3 bg-white border border-indigo-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none"
|
| 707 |
+
/>
|
| 708 |
+
<p className="mt-2 text-xs text-slate-500">
|
| 709 |
+
Профессиональная роль бота
|
| 710 |
+
</p>
|
| 711 |
+
</div>
|
| 712 |
+
</div>
|
| 713 |
+
</motion.div>
|
| 714 |
+
|
| 715 |
+
{/* Business Model - NEW SECTION */}
|
| 716 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 717 |
+
<div className="flex items-center gap-3 mb-6">
|
| 718 |
+
<div className="p-2 bg-blue-50 rounded-xl text-blue-600">
|
| 719 |
+
<ShoppingBag className="w-6 h-6" />
|
| 720 |
+
</div>
|
| 721 |
+
<div>
|
| 722 |
+
<h2 className="text-xl font-bold text-slate-900">Бизнес-модель</h2>
|
| 723 |
+
<p className="text-sm text-slate-500">Что вы продаете? Это определит стратегию бота.</p>
|
| 724 |
+
</div>
|
| 725 |
+
</div>
|
| 726 |
+
|
| 727 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 728 |
+
{[
|
| 729 |
+
{ id: 'product', label: 'Товары (Retail)', icon: ShoppingBag, desc: 'Активная продажа, каталог, фото' },
|
| 730 |
+
{ id: 'service', label: 'Услуги (Service)', icon: Briefcase, desc: 'Экспертность, консультации, встречи' },
|
| 731 |
+
{ id: 'hybrid', label: 'Гибрид', icon: Zap, desc: 'Баланс между товарами и услугами' }
|
| 732 |
+
].map((type) => {
|
| 733 |
+
const Icon = type.icon
|
| 734 |
+
const isSelected = persona.business_type === type.id
|
| 735 |
+
return (
|
| 736 |
+
<button
|
| 737 |
+
key={type.id}
|
| 738 |
+
onClick={() => setPersona({ ...persona, business_type: type.id as any })}
|
| 739 |
+
className={cn(
|
| 740 |
+
"p-4 rounded-xl border-2 transition-all duration-200 text-left relative overflow-hidden group h-full",
|
| 741 |
+
isSelected
|
| 742 |
+
? "border-blue-600 bg-blue-50/50 shadow-md"
|
| 743 |
+
: "border-slate-200 hover:border-blue-300 bg-white hover:shadow-sm"
|
| 744 |
+
)}
|
| 745 |
+
>
|
| 746 |
+
<div className="flex flex-col gap-3 relative z-10">
|
| 747 |
+
<div className={cn(
|
| 748 |
+
"w-10 h-10 rounded-lg flex items-center justify-center transition-colors",
|
| 749 |
+
isSelected ? "bg-blue-600 text-white" : "bg-slate-100 text-slate-500 group-hover:bg-blue-50 group-hover:text-blue-600"
|
| 750 |
+
)}>
|
| 751 |
+
<Icon className="w-5 h-5" />
|
| 752 |
+
</div>
|
| 753 |
+
<div>
|
| 754 |
+
<h3 className={cn(
|
| 755 |
+
"font-bold text-base mb-1",
|
| 756 |
+
isSelected ? "text-blue-900" : "text-slate-900"
|
| 757 |
+
)}>
|
| 758 |
+
{type.label}
|
| 759 |
+
</h3>
|
| 760 |
+
<p className="text-xs text-slate-600 leading-relaxed">
|
| 761 |
+
{type.desc}
|
| 762 |
+
</p>
|
| 763 |
+
</div>
|
| 764 |
+
</div>
|
| 765 |
+
{isSelected && (
|
| 766 |
+
<div className="absolute top-3 right-3">
|
| 767 |
+
<CheckCircle2 className="w-5 h-5 text-blue-600" />
|
| 768 |
+
</div>
|
| 769 |
+
)}
|
| 770 |
+
</button>
|
| 771 |
+
)
|
| 772 |
+
})}
|
| 773 |
+
</div>
|
| 774 |
+
</motion.div>
|
| 775 |
+
|
| 776 |
+
{/* Tone of Voice */}
|
| 777 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 778 |
+
<div className="flex items-center gap-3 mb-6">
|
| 779 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 780 |
+
<Sparkles className="w-6 h-6" />
|
| 781 |
+
</div>
|
| 782 |
+
<div>
|
| 783 |
+
<h2 className="text-xl font-bold text-slate-900">Тон общения</h2>
|
| 784 |
+
<p className="text-sm text-slate-500">Выберите стиль общения AI с клиентами</p>
|
| 785 |
+
</div>
|
| 786 |
+
</div>
|
| 787 |
+
|
| 788 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 789 |
+
{TONE_OPTIONS.map((tone) => {
|
| 790 |
+
const Icon = tone.icon
|
| 791 |
+
const isSelected = persona.tone_of_voice === tone.value
|
| 792 |
+
return (
|
| 793 |
+
<button
|
| 794 |
+
key={tone.value}
|
| 795 |
+
onClick={() => setPersona({ ...persona, tone_of_voice: tone.value as any })}
|
| 796 |
+
className={cn(
|
| 797 |
+
"p-4 rounded-xl border-2 transition-all duration-200 text-left relative overflow-hidden group",
|
| 798 |
+
isSelected
|
| 799 |
+
? "border-indigo-600 bg-indigo-50/50 shadow-md"
|
| 800 |
+
: "border-slate-200 hover:border-indigo-300 bg-white hover:shadow-sm"
|
| 801 |
+
)}
|
| 802 |
+
>
|
| 803 |
+
<div className="flex items-center gap-3 mb-2 relative z-10">
|
| 804 |
+
<div className={cn(
|
| 805 |
+
"p-2 rounded-lg transition-colors",
|
| 806 |
+
isSelected ? "bg-indigo-100 text-indigo-600" : "bg-slate-100 text-slate-500 group-hover:bg-indigo-50 group-hover:text-indigo-600"
|
| 807 |
+
)}>
|
| 808 |
+
<Icon className="w-5 h-5" />
|
| 809 |
+
</div>
|
| 810 |
+
<h3 className={cn(
|
| 811 |
+
"font-bold text-lg",
|
| 812 |
+
isSelected ? "text-indigo-900" : "text-slate-900"
|
| 813 |
+
)}>
|
| 814 |
+
{tone.label}
|
| 815 |
+
</h3>
|
| 816 |
+
{isSelected && (
|
| 817 |
+
<CheckCircle2 className="w-5 h-5 text-indigo-600 ml-auto" />
|
| 818 |
+
)}
|
| 819 |
+
</div>
|
| 820 |
+
<p className="text-sm text-slate-600 pl-[52px] relative z-10">{tone.description}</p>
|
| 821 |
+
</button>
|
| 822 |
+
)
|
| 823 |
+
})}
|
| 824 |
+
</div>
|
| 825 |
+
</motion.div>
|
| 826 |
+
|
| 827 |
+
{/* Sales Methodology */}
|
| 828 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 829 |
+
<div className="flex items-center gap-3 mb-6">
|
| 830 |
+
<div className="p-2 bg-purple-50 rounded-xl text-purple-600">
|
| 831 |
+
<BookOpen className="w-6 h-6" />
|
| 832 |
+
</div>
|
| 833 |
+
<div>
|
| 834 |
+
<h2 className="text-xl font-bold text-slate-900">Методология продаж</h2>
|
| 835 |
+
<p className="text-sm text-slate-500">Выберите фреймворк, который AI будет использовать в диалогах</p>
|
| 836 |
+
</div>
|
| 837 |
+
</div>
|
| 838 |
|
| 839 |
<div className="space-y-3">
|
| 840 |
+
{METHODOLOGY_OPTIONS.map((method) => {
|
| 841 |
+
const Icon = method.icon
|
| 842 |
+
const isSelected = persona.sales_methodology === method.value
|
| 843 |
+
return (
|
| 844 |
+
<button
|
| 845 |
+
key={method.value}
|
| 846 |
+
onClick={() => setPersona({ ...persona, sales_methodology: method.value as any })}
|
| 847 |
+
className={cn(
|
| 848 |
+
"w-full p-4 rounded-xl border-2 transition-all duration-200 text-left group",
|
| 849 |
+
isSelected
|
| 850 |
+
? "border-purple-600 bg-purple-50/30 shadow-md"
|
| 851 |
+
: "border-slate-200 hover:border-purple-300 bg-white hover:shadow-sm"
|
| 852 |
+
)}
|
| 853 |
+
>
|
| 854 |
+
<div className="flex items-start gap-4">
|
| 855 |
+
<div className={cn(
|
| 856 |
+
"p-2 rounded-lg mt-0.5 transition-colors",
|
| 857 |
+
isSelected ? "bg-purple-100 text-purple-600" : "bg-slate-100 text-slate-500 group-hover:bg-purple-50 group-hover:text-purple-600"
|
| 858 |
+
)}>
|
| 859 |
+
<Icon className="w-5 h-5" />
|
| 860 |
+
</div>
|
| 861 |
+
<div className="flex-1">
|
| 862 |
+
<div className="flex items-center justify-between mb-1">
|
| 863 |
+
<h3 className={cn(
|
| 864 |
+
"font-bold text-lg",
|
| 865 |
+
isSelected ? "text-purple-900" : "text-slate-900"
|
| 866 |
+
)}>
|
| 867 |
+
{method.label}
|
| 868 |
+
</h3>
|
| 869 |
+
{isSelected && (
|
| 870 |
+
<CheckCircle2 className="w-5 h-5 text-purple-600" />
|
| 871 |
+
)}
|
| 872 |
+
</div>
|
| 873 |
+
<p className="text-sm text-slate-600">{method.description}</p>
|
| 874 |
+
</div>
|
| 875 |
+
</div>
|
| 876 |
+
</button>
|
| 877 |
+
)
|
| 878 |
+
})}
|
| 879 |
+
</div>
|
| 880 |
+
</motion.div>
|
| 881 |
+
|
| 882 |
+
{/* Business Description */}
|
| 883 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 884 |
+
<div className="flex items-center gap-3 mb-6">
|
| 885 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 886 |
+
<Target className="w-6 h-6" />
|
| 887 |
+
</div>
|
| 888 |
+
<div>
|
| 889 |
+
<h2 className="text-xl font-bold text-slate-900">Описание бизнеса</h2>
|
| 890 |
+
<p className="text-sm text-slate-500">Опишите ваш бизнес, что вы продаете, ключевые преимущества</p>
|
| 891 |
+
</div>
|
| 892 |
+
</div>
|
| 893 |
+
|
| 894 |
+
<textarea
|
| 895 |
+
value={settings.business_description}
|
| 896 |
+
onChange={(e) => setSettings({ ...settings, business_description: e.target.value })}
|
| 897 |
+
placeholder="Например: Мы продаём премиум CRM-системы для малого бизнеса. Наше главное преимущество — простота настройки и внедрения за 1 д��нь."
|
| 898 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none resize-none min-h-[120px]"
|
| 899 |
+
/>
|
| 900 |
+
</motion.div>
|
| 901 |
+
|
| 902 |
+
{/* Ideal Customer Profile */}
|
| 903 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 904 |
+
<div className="flex items-center gap-3 mb-6">
|
| 905 |
+
<div className="p-2 bg-purple-50 rounded-xl text-purple-600">
|
| 906 |
+
<Users className="w-6 h-6" />
|
| 907 |
+
</div>
|
| 908 |
+
<div>
|
| 909 |
+
<h2 className="text-xl font-bold text-slate-900">Идеальный клиент (ICP)</h2>
|
| 910 |
+
<p className="text-sm text-slate-500">Портрет вашего идеального клиента для квалификации</p>
|
| 911 |
+
</div>
|
| 912 |
+
</div>
|
| 913 |
+
|
| 914 |
+
<textarea
|
| 915 |
+
value={settings.ideal_customer_profile}
|
| 916 |
+
onChange={(e) => setSettings({ ...settings, ideal_customer_profile: e.target.value })}
|
| 917 |
+
placeholder="Например: Владелец бизнеса с 5-50 сотрудниками, доход от 10 млн руб/год, ищет решение для автоматизации продаж."
|
| 918 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none resize-none min-h-[100px]"
|
| 919 |
+
/>
|
| 920 |
+
</motion.div>
|
| 921 |
+
|
| 922 |
+
{/* Custom Qualification Fields */}
|
| 923 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 924 |
+
<div className="flex items-center gap-3 mb-6">
|
| 925 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 926 |
+
<Brain className="w-6 h-6" />
|
| 927 |
+
</div>
|
| 928 |
+
<div>
|
| 929 |
+
<h2 className="text-xl font-bold text-slate-900">Поля квалификации</h2>
|
| 930 |
+
<p className="text-sm text-slate-500">Какую информацию AI должен собирать о клиентах</p>
|
| 931 |
+
</div>
|
| 932 |
+
</div>
|
| 933 |
+
|
| 934 |
+
<div className="flex flex-wrap gap-2 mb-6">
|
| 935 |
+
{settings.custom_fields.map((field) => (
|
| 936 |
+
<div
|
| 937 |
+
key={field}
|
| 938 |
+
className="inline-flex items-center gap-2 px-3 py-1.5 bg-indigo-50 text-indigo-700 border border-indigo-100 rounded-lg text-sm font-medium"
|
| 939 |
+
>
|
| 940 |
+
<span>{field}</span>
|
| 941 |
+
<button
|
| 942 |
+
onClick={() => removeCustomField(field)}
|
| 943 |
+
className="hover:bg-indigo-200 rounded-md p-0.5 transition-colors"
|
| 944 |
+
>
|
| 945 |
+
<X className="w-3.5 h-3.5" />
|
| 946 |
+
</button>
|
| 947 |
</div>
|
| 948 |
+
))}
|
| 949 |
+
</div>
|
| 950 |
|
| 951 |
+
<div className="flex gap-3">
|
| 952 |
+
<input
|
| 953 |
+
type="text"
|
| 954 |
+
value={newField}
|
| 955 |
+
onChange={(e) => setNewField(e.target.value)}
|
| 956 |
+
onKeyDown={(e) => e.key === 'Enter' && addCustomField()}
|
| 957 |
+
placeholder="Например: Регион, Количество сотрудников..."
|
| 958 |
+
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none"
|
| 959 |
+
/>
|
| 960 |
+
<button
|
| 961 |
+
onClick={addCustomField}
|
| 962 |
+
className="px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl font-bold shadow-lg hover:shadow-indigo-500/25 transition-all flex items-center gap-2"
|
| 963 |
>
|
| 964 |
+
<Plus className="w-5 h-5" />
|
| 965 |
+
Добавить
|
| 966 |
+
</button>
|
| 967 |
+
</div>
|
| 968 |
+
</motion.div>
|
| 969 |
+
|
| 970 |
+
{/* Custom Instructions */}
|
| 971 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 972 |
+
<div className="flex items-center gap-3 mb-6">
|
| 973 |
+
<div className="p-2 bg-emerald-50 rounded-xl text-emerald-600">
|
| 974 |
+
<Award className="w-6 h-6" />
|
| 975 |
+
</div>
|
| 976 |
+
<div>
|
| 977 |
+
<h2 className="text-xl font-bold text-slate-900">Правила поведения (Global Prompt)</h2>
|
| 978 |
+
<p className="text-sm text-slate-500">Специальные инструкции для AI</p>
|
| 979 |
+
</div>
|
| 980 |
+
</div>
|
| 981 |
+
|
| 982 |
+
<textarea
|
| 983 |
+
value={persona.custom_instructions}
|
| 984 |
+
onChange={(e) => setPersona({ ...persona, custom_instructions: e.target.value })}
|
| 985 |
+
placeholder="Например: - Никогда не говори цену до выяснения бюджета - Всегда упоминай наше УТП: внедрение за 1 день - Если клиент сравнивает с конкурентами, подчеркни скорость"
|
| 986 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none resize-none min-h-[150px] font-mono text-sm"
|
| 987 |
+
/>
|
| 988 |
+
</motion.div>
|
| 989 |
+
|
| 990 |
+
{/* Banned Words */}
|
| 991 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 992 |
+
<div className="flex items-center gap-3 mb-6">
|
| 993 |
+
<div className="p-2 bg-red-50 rounded-xl text-red-600">
|
| 994 |
+
<Ban className="w-6 h-6" />
|
| 995 |
+
</div>
|
| 996 |
+
<div>
|
| 997 |
+
<h2 className="text-xl font-bold text-slate-900">Запрещенные слова</h2>
|
| 998 |
+
<p className="text-sm text-slate-500">Слова и фразы, которые AI никогда не должен использовать</p>
|
| 999 |
+
</div>
|
| 1000 |
+
</div>
|
| 1001 |
+
|
| 1002 |
+
<div className="flex flex-wrap gap-2 mb-6">
|
| 1003 |
+
{persona.banned_words.map((word) => (
|
| 1004 |
+
<div
|
| 1005 |
+
key={word}
|
| 1006 |
+
className="inline-flex items-center gap-2 px-3 py-1.5 bg-red-50 text-red-700 border border-red-100 rounded-lg text-sm font-medium"
|
| 1007 |
+
>
|
| 1008 |
+
<span>{word}</span>
|
| 1009 |
+
<button
|
| 1010 |
+
onClick={() => removeBannedWord(word)}
|
| 1011 |
+
className="hover:bg-red-200 rounded-md p-0.5 transition-colors"
|
| 1012 |
+
>
|
| 1013 |
+
<X className="w-3.5 h-3.5" />
|
| 1014 |
+
</button>
|
| 1015 |
</div>
|
| 1016 |
+
))}
|
| 1017 |
+
</div>
|
| 1018 |
|
| 1019 |
+
<div className="flex gap-3">
|
| 1020 |
+
<input
|
| 1021 |
+
type="text"
|
| 1022 |
+
value={newBannedWord}
|
| 1023 |
+
onChange={(e) => setNewBannedWord(e.target.value)}
|
| 1024 |
+
onKeyDown={(e) => e.key === 'Enter' && addBannedWord()}
|
| 1025 |
+
placeholder="Например: дешево, бесплатно, скидка..."
|
| 1026 |
+
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-red-500/20 focus:border-red-500 transition-all outline-none"
|
| 1027 |
+
/>
|
| 1028 |
+
<button
|
| 1029 |
+
onClick={addBannedWord}
|
| 1030 |
+
className="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-xl font-bold shadow-lg hover:shadow-red-500/25 transition-all flex items-center gap-2"
|
| 1031 |
>
|
| 1032 |
+
<Plus className="w-5 h-5" />
|
| 1033 |
+
Добавить
|
| 1034 |
+
</button>
|
| 1035 |
+
</div>
|
| 1036 |
+
</motion.div>
|
| 1037 |
+
|
| 1038 |
+
{/* ROI Calculator Settings */}
|
| 1039 |
+
<motion.div variants={item} className="bg-gradient-to-br from-emerald-50 to-teal-50 rounded-2xl border border-emerald-100 p-8 shadow-sm">
|
| 1040 |
+
<div className="flex items-center gap-3 mb-6">
|
| 1041 |
+
<div className="p-2 bg-emerald-100 rounded-xl text-emerald-600">
|
| 1042 |
+
<Calculator className="w-6 h-6" />
|
| 1043 |
+
</div>
|
| 1044 |
+
<div>
|
| 1045 |
+
<h2 className="text-xl font-bold text-slate-900">Настройки ROI (Калькулятор выгоды)</h2>
|
| 1046 |
+
<p className="text-sm text-slate-600">Настройте расчёт экономии от AI</p>
|
| 1047 |
+
</div>
|
| 1048 |
+
</div>
|
| 1049 |
+
|
| 1050 |
+
<div>
|
| 1051 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">
|
| 1052 |
+
<div className="flex items-center gap-2">
|
| 1053 |
+
<DollarSign className="w-4 h-4 text-emerald-600" />
|
| 1054 |
+
Средняя зарплата менеджера (USD/месяц)
|
| 1055 |
</div>
|
| 1056 |
+
</label>
|
| 1057 |
+
<input
|
| 1058 |
+
type="number"
|
| 1059 |
+
min="0"
|
| 1060 |
+
step="100"
|
| 1061 |
+
value={persona.manager_monthly_salary}
|
| 1062 |
+
onChange={(e) => setPersona({ ...persona, manager_monthly_salary: parseInt(e.target.value) || 1000 })}
|
| 1063 |
+
className="w-full md:w-64 px-4 py-3 bg-white border border-emerald-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none font-semibold text-emerald-900"
|
| 1064 |
+
placeholder="1000"
|
| 1065 |
+
/>
|
| 1066 |
+
<div className="mt-3 flex items-start gap-2 text-xs text-emerald-700 bg-emerald-100/50 p-3 rounded-lg border border-emerald-100">
|
| 1067 |
+
<AlertCircle className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
| 1068 |
+
<p>
|
| 1069 |
+
Мы рассчитываем почасовую ставку (зарплата / 160 часов) и экономию времени AI (3 мин на сообщение).
|
| 1070 |
+
</p>
|
| 1071 |
+
</div>
|
| 1072 |
</div>
|
| 1073 |
</motion.div>
|
| 1074 |
+
|
| 1075 |
+
{/* Save Button */}
|
| 1076 |
+
<motion.div variants={item} className="flex justify-end pt-4 pb-12">
|
| 1077 |
+
<button
|
| 1078 |
+
onClick={handleSave}
|
| 1079 |
+
disabled={saving}
|
| 1080 |
+
className="px-8 py-4 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white rounded-xl font-bold shadow-xl hover:shadow-2xl hover:-translate-y-1 transition-all duration-300 flex items-center gap-3 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none"
|
| 1081 |
+
>
|
| 1082 |
+
{saving ? (
|
| 1083 |
+
<>
|
| 1084 |
+
<Loader2 className="w-6 h-6 animate-spin" />
|
| 1085 |
+
Сохранение...
|
| 1086 |
+
</>
|
| 1087 |
+
) : (
|
| 1088 |
+
<>
|
| 1089 |
+
<Save className="w-6 h-6" />
|
| 1090 |
+
Сохранить настройки
|
| 1091 |
+
</>
|
| 1092 |
+
)}
|
| 1093 |
+
</button>
|
| 1094 |
+
</motion.div>
|
| 1095 |
+
</motion.div>
|
| 1096 |
+
)}
|
| 1097 |
</div>
|
| 1098 |
</div>
|
| 1099 |
)
|