Spaces:
Running

axeronis commited on
Commit
3b6bb06
·
1 Parent(s): 5b47862

Feature: Remove catalog duplication and add bot identity configuration

Browse files

- Remove Products tab from Brain settings (moved to Knowledge page only)
- Add Bot Identity UI section with name and role fields
- Remove hardcoded defaults (Alex, Sales Assistant) from backend
- Update API to save/load ai_identity from database

backend/app/services/ai_core.py CHANGED
@@ -533,8 +533,8 @@ class AICore:
533
 
534
  # Extract bot name and identity from tenant
535
  ai_identity = tenant.ai_identity or {}
536
- bot_name = ai_identity.get("bot_name", "Alex")
537
- bot_role = ai_identity.get("bot_role", "Sales Assistant")
538
  company_name = tenant.business_name or tenant.name or "Our Company"
539
 
540
  # Extract AI settings
@@ -859,9 +859,9 @@ TASK 3 TESTING LOGIC:
859
 
860
  # Get tenant info
861
  tenant = lead.tenant
862
- bot_name = "AI Assistant"
863
  if tenant and tenant.ai_identity:
864
- bot_name = tenant.ai_identity.get("bot_name", "Alex")
865
 
866
  lead_name = lead.name or "Client"
867
 
 
533
 
534
  # Extract bot name and identity from tenant
535
  ai_identity = tenant.ai_identity or {}
536
+ bot_name = ai_identity.get("bot_name", "") # Empty if not set
537
+ bot_role = ai_identity.get("bot_role", "") # Empty if not set
538
  company_name = tenant.business_name or tenant.name or "Our Company"
539
 
540
  # Extract AI settings
 
859
 
860
  # Get tenant info
861
  tenant = lead.tenant
862
+ bot_name = ""
863
  if tenant and tenant.ai_identity:
864
+ bot_name = tenant.ai_identity.get("bot_name", "")
865
 
866
  lead_name = lead.name or "Client"
867
 
frontend/app/settings/brain/page.tsx CHANGED
@@ -11,7 +11,6 @@ import { motion, AnimatePresence } from 'framer-motion'
11
  import { cn } from '@/lib/utils'
12
  import { api } from '@/lib/api'
13
  import BookingSettings from '@/components/BookingSettings'
14
- import ProductSettings from '@/components/settings/ProductSettings'
15
 
16
  interface AISettings {
17
  business_description: string
@@ -28,7 +27,12 @@ interface AIPersona {
28
  manager_monthly_salary: number
29
  }
30
 
31
- type TabType = 'persona' | 'booking' | 'products'
 
 
 
 
 
32
 
33
  const TONE_OPTIONS = [
34
  { value: 'Professional', label: 'Профессиональный', icon: Shield, description: 'Деловой, формальный тон' },
@@ -94,6 +98,11 @@ export default function BrainSettingsPage() {
94
  manager_monthly_salary: 1000
95
  })
96
 
 
 
 
 
 
97
 
98
  useEffect(() => {
99
  if (user) {
@@ -117,6 +126,10 @@ export default function BrainSettingsPage() {
117
  banned_words: data.banned_words || [],
118
  manager_monthly_salary: data.manager_monthly_salary || 1000
119
  })
 
 
 
 
120
  setBookingSettings(data.booking_settings)
121
  } catch (error) {
122
  console.error('Failed to fetch AI settings:', error)
@@ -132,6 +145,10 @@ export default function BrainSettingsPage() {
132
  try {
133
  await api.patch(`/api/v1/tenants/${user.tenant_id}`, {
134
  ai_settings: settings,
 
 
 
 
135
  ...persona
136
  })
137
  alert('✅ Настройки AI Brain сохранены!')
@@ -260,18 +277,7 @@ export default function BrainSettingsPage() {
260
  Личность & Правила
261
  </button>
262
 
263
- <button
264
- onClick={() => setActiveTab('products')}
265
- className={cn(
266
- "px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
267
- activeTab === 'products'
268
- ? "bg-slate-100 text-slate-900 shadow-sm"
269
- : "text-slate-500 hover:text-slate-700 hover:bg-slate-50"
270
- )}
271
- >
272
- <ShoppingBag className="w-4 h-4" />
273
- Товары (RAG)
274
- </button>
275
 
276
  <button
277
  onClick={() => setActiveTab('booking')}
@@ -288,9 +294,7 @@ export default function BrainSettingsPage() {
288
  </div>
289
  </motion.div>
290
 
291
- {activeTab === 'products' && (
292
- <ProductSettings />
293
- )}
294
 
295
  {activeTab === 'booking' && (
296
  <BookingSettings
@@ -306,6 +310,53 @@ export default function BrainSettingsPage() {
306
  animate="show"
307
  className="space-y-6"
308
  >
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  {/* Tone of Voice */}
310
  <motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
311
  <div className="flex items-center gap-3 mb-6">
 
11
  import { cn } from '@/lib/utils'
12
  import { api } from '@/lib/api'
13
  import BookingSettings from '@/components/BookingSettings'
 
14
 
15
  interface AISettings {
16
  business_description: string
 
27
  manager_monthly_salary: number
28
  }
29
 
30
+ type TabType = 'persona' | 'booking'
31
+
32
+ interface BotIdentity {
33
+ bot_name: string
34
+ bot_role: string
35
+ }
36
 
37
  const TONE_OPTIONS = [
38
  { value: 'Professional', label: 'Профессиональный', icon: Shield, description: 'Деловой, формальный тон' },
 
98
  manager_monthly_salary: 1000
99
  })
100
 
101
+ const [botIdentity, setBotIdentity] = useState<BotIdentity>({
102
+ bot_name: '',
103
+ bot_role: ''
104
+ })
105
+
106
 
107
  useEffect(() => {
108
  if (user) {
 
126
  banned_words: data.banned_words || [],
127
  manager_monthly_salary: data.manager_monthly_salary || 1000
128
  })
129
+ setBotIdentity({
130
+ bot_name: data.ai_identity?.bot_name || '',
131
+ bot_role: data.ai_identity?.bot_role || ''
132
+ })
133
  setBookingSettings(data.booking_settings)
134
  } catch (error) {
135
  console.error('Failed to fetch AI settings:', error)
 
145
  try {
146
  await api.patch(`/api/v1/tenants/${user.tenant_id}`, {
147
  ai_settings: settings,
148
+ ai_identity: {
149
+ bot_name: botIdentity.bot_name,
150
+ bot_role: botIdentity.bot_role
151
+ },
152
  ...persona
153
  })
154
  alert('✅ Настройки AI Brain сохранены!')
 
277
  Личность & Правила
278
  </button>
279
 
280
+
 
 
 
 
 
 
 
 
 
 
 
281
 
282
  <button
283
  onClick={() => setActiveTab('booking')}
 
294
  </div>
295
  </motion.div>
296
 
297
+
 
 
298
 
299
  {activeTab === 'booking' && (
300
  <BookingSettings
 
310
  animate="show"
311
  className="space-y-6"
312
  >
313
+ {/* Bot Identity - NEW SECTION */}
314
+ <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">
315
+ <div className="flex items-center gap-3 mb-6">
316
+ <div className="p-2 bg-indigo-100 rounded-xl text-indigo-600">
317
+ <Brain className="w-6 h-6" />
318
+ </div>
319
+ <div>
320
+ <h2 className="text-xl font-bold text-slate-900">Личность бота</h2>
321
+ <p className="text-sm text-slate-600">Имя и роль вашего AI помощника</p>
322
+ </div>
323
+ </div>
324
+
325
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
326
+ <div>
327
+ <label className="block text-sm font-bold text-slate-700 mb-2">
328
+ Имя бота
329
+ </label>
330
+ <input
331
+ type="text"
332
+ value={botIdentity.bot_name}
333
+ onChange={(e) => setBotIdentity({ ...botIdentity, bot_name: e.target.value })}
334
+ placeholder="Например: Alex, Мария, Дмитрий"
335
+ 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"
336
+ />
337
+ <p className="mt-2 text-xs text-slate-500">
338
+ Как бот будет представляться клиентам
339
+ </p>
340
+ </div>
341
+
342
+ <div>
343
+ <label className="block text-sm font-bold text-slate-700 mb-2">
344
+ Роль / Должность
345
+ </label>
346
+ <input
347
+ type="text"
348
+ value={botIdentity.bot_role}
349
+ onChange={(e) => setBotIdentity({ ...botIdentity, bot_role: e.target.value })}
350
+ placeholder="Например: Менеджер по продажам, Консультант"
351
+ 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"
352
+ />
353
+ <p className="mt-2 text-xs text-slate-500">
354
+ Профессиональная роль бота
355
+ </p>
356
+ </div>
357
+ </div>
358
+ </motion.div>
359
+
360
  {/* Tone of Voice */}
361
  <motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
362
  <div className="flex items-center gap-3 mb-6">