Spaces:
Running
Running
axeronis commited on
Commit ·
6b3e0ab
1
Parent(s): 6725d02
feat: AI Brain overhaul - tone instructions, KB enforcement, booking, banned words, KB edit UI
Browse files- backend/app/api/knowledge.py +49 -0
- backend/app/api/webhook.py +14 -0
- backend/app/services/ai_memory_manager.py +39 -18
- frontend/app/settings/brain/page.tsx +108 -34
- frontend/lib/api.ts +5 -0
backend/app/api/knowledge.py
CHANGED
|
@@ -319,3 +319,52 @@ async def delete_knowledge(
|
|
| 319 |
"message": "Knowledge deleted"
|
| 320 |
}
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
"message": "Knowledge deleted"
|
| 320 |
}
|
| 321 |
|
| 322 |
+
|
| 323 |
+
class KnowledgeUpdate(BaseModel):
|
| 324 |
+
"""Input for updating knowledge."""
|
| 325 |
+
content: Optional[str] = None
|
| 326 |
+
category: Optional[str] = None
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
@router.put("/{knowledge_id}")
|
| 330 |
+
async def update_knowledge(
|
| 331 |
+
knowledge_id: UUID,
|
| 332 |
+
data: KnowledgeUpdate,
|
| 333 |
+
current_user: User = Depends(get_current_user),
|
| 334 |
+
session = Depends(get_session)
|
| 335 |
+
):
|
| 336 |
+
"""Update a knowledge entry (tenant-isolated)."""
|
| 337 |
+
|
| 338 |
+
tenant_id = current_user.tenant_id
|
| 339 |
+
|
| 340 |
+
stmt = select(KnowledgeBase).where(
|
| 341 |
+
KnowledgeBase.tenant_id == tenant_id,
|
| 342 |
+
KnowledgeBase.id == knowledge_id
|
| 343 |
+
)
|
| 344 |
+
result = await session.execute(stmt)
|
| 345 |
+
knowledge = result.scalar_one_or_none()
|
| 346 |
+
|
| 347 |
+
if not knowledge:
|
| 348 |
+
raise HTTPException(status_code=404, detail="Knowledge not found")
|
| 349 |
+
|
| 350 |
+
# Update fields
|
| 351 |
+
if data.content is not None:
|
| 352 |
+
knowledge.content_chunk = data.content
|
| 353 |
+
if data.category is not None:
|
| 354 |
+
knowledge.category = data.category
|
| 355 |
+
|
| 356 |
+
session.add(knowledge)
|
| 357 |
+
await session.commit()
|
| 358 |
+
|
| 359 |
+
# SIGNAL: Invalidate AI Memory
|
| 360 |
+
tenant = await session.get(Tenant, tenant_id)
|
| 361 |
+
if tenant:
|
| 362 |
+
await get_memory_manager().invalidate_memory(session, tenant)
|
| 363 |
+
|
| 364 |
+
return {
|
| 365 |
+
"ok": True,
|
| 366 |
+
"id": str(knowledge.id),
|
| 367 |
+
"message": "Knowledge updated"
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
|
backend/app/api/webhook.py
CHANGED
|
@@ -678,6 +678,20 @@ async def process_ai_response_background(
|
|
| 678 |
|
| 679 |
# --- ORDER INTERCEPTION END ---
|
| 680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
|
| 682 |
|
| 683 |
ai_message = Message(
|
|
|
|
| 678 |
|
| 679 |
# --- ORDER INTERCEPTION END ---
|
| 680 |
|
| 681 |
+
# --- BANNED WORDS POST-CHECK ---
|
| 682 |
+
# Extra safety: replace banned words even if AI ignores the prompt rule
|
| 683 |
+
if tenant.banned_words:
|
| 684 |
+
ai_text = ai_response["text"]
|
| 685 |
+
for word in tenant.banned_words:
|
| 686 |
+
if word and word.lower() in ai_text.lower():
|
| 687 |
+
# Case-insensitive replacement
|
| 688 |
+
import re
|
| 689 |
+
pattern = re.compile(re.escape(word), re.IGNORECASE)
|
| 690 |
+
ai_text = pattern.sub("***", ai_text)
|
| 691 |
+
logger.warning(f"🚫 Replaced banned word: {word}")
|
| 692 |
+
ai_response["text"] = ai_text
|
| 693 |
+
# --- BANNED WORDS POST-CHECK END ---
|
| 694 |
+
|
| 695 |
|
| 696 |
|
| 697 |
ai_message = Message(
|
backend/app/services/ai_memory_manager.py
CHANGED
|
@@ -150,42 +150,63 @@ class AIMemoryManager:
|
|
| 150 |
ai_settings = tenant.ai_settings or {}
|
| 151 |
ai_identity = ai_settings.get("ai_identity", {})
|
| 152 |
bot_name = ai_identity.get("bot_name", "AI Assistant")
|
| 153 |
-
bot_role = ai_identity.get("bot_role", "Sales Manager")
|
| 154 |
company = tenant.business_name or "Our Company"
|
| 155 |
-
business_description = ai_settings.get("business_description", "")
|
| 156 |
|
| 157 |
tone = tenant.tone_of_voice or "Professional"
|
| 158 |
methodology = tenant.sales_methodology or ""
|
| 159 |
custom_instructions = tenant.custom_instructions or ""
|
| 160 |
banned_words = tenant.banned_words or []
|
|
|
|
| 161 |
|
| 162 |
-
# B.
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
context = f"""
|
| 166 |
═══════════════════════════════════════════════════════════════
|
| 167 |
[🚨 КРИТИЧЕСКИЕ ПРАВИЛА - ОБЯЗАТЕЛЬНО СОБЛЮДАТЬ]
|
| 168 |
═══════════════════════════════════════════════════════════════
|
| 169 |
-
ТЫ: {bot_name}, {bot_role} в компании {company}.
|
| 170 |
-
ТОН ОБЩЕНИЯ: {tone}
|
| 171 |
-
{f"МЕТОДОЛОГИЯ: {methodology}" if methodology else ""}
|
| 172 |
-
{banned_text}
|
| 173 |
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
|
| 177 |
- Отвечай ТОЛЬКО на основе [KNOWLEDGE BASE] ниже
|
| 178 |
-
- Если информации НЕТ
|
| 179 |
-
- НИКОГДА не придумывай цены,
|
| 180 |
-
- НЕ отвечай на вопросы не по теме
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
═══════════════════════════════════════════════════════════════
|
| 183 |
[BOT IDENTITY]
|
| 184 |
═════════════════════════════════════════════════════���═════════
|
| 185 |
Имя: {bot_name}
|
| 186 |
-
Роль: {bot_role}
|
| 187 |
Компания: {company}
|
| 188 |
-
{f"Описание: {business_description}" if business_description else ""}
|
| 189 |
"""
|
| 190 |
|
| 191 |
# C. KNOWLEDGE BASE
|
|
@@ -265,11 +286,11 @@ class AIMemoryManager:
|
|
| 265 |
[🔔 НАПОМИНАНИЕ - ПЕРЕД КАЖДЫМ ОТВЕТОМ ПРОВЕРЬ]
|
| 266 |
═══════════════════════════════════════════════════════════════
|
| 267 |
✅ Ты {bot_name}
|
| 268 |
-
✅ Тон: {tone}
|
| 269 |
{f"❌ Запрещено: {', '.join(banned_words)}" if banned_words else ""}
|
| 270 |
{f"📝 Инструкции: {custom_instructions}" if custom_instructions else ""}
|
| 271 |
-
✅
|
| 272 |
-
✅ Если не знаешь
|
| 273 |
⚠️ НЕ ИСПОЛЬЗУЙ Markdown (* _ ` #) - пиши обычным текстом!
|
| 274 |
═══════════════════════════════════════════════════════════════
|
| 275 |
"""
|
|
|
|
| 150 |
ai_settings = tenant.ai_settings or {}
|
| 151 |
ai_identity = ai_settings.get("ai_identity", {})
|
| 152 |
bot_name = ai_identity.get("bot_name", "AI Assistant")
|
|
|
|
| 153 |
company = tenant.business_name or "Our Company"
|
|
|
|
| 154 |
|
| 155 |
tone = tenant.tone_of_voice or "Professional"
|
| 156 |
methodology = tenant.sales_methodology or ""
|
| 157 |
custom_instructions = tenant.custom_instructions or ""
|
| 158 |
banned_words = tenant.banned_words or []
|
| 159 |
+
ideal_customer = ai_settings.get("ideal_customer_profile", "")
|
| 160 |
|
| 161 |
+
# B. TONE INSTRUCTIONS (detailed, not just name)
|
| 162 |
+
tone_instructions = {
|
| 163 |
+
"Professional": "Говори формально на 'Вы'. Избегай сленга и эмодзи. Чёткие, структурированные ответы.",
|
| 164 |
+
"Friendly": "Говори неформально на 'ты'. Используй эмодзи 😊. Будь как друг, который помогает.",
|
| 165 |
+
"Empathetic": "Проявляй понимание и сочувствие. Задавай уточняющие вопросы. Поддерживай клиента.",
|
| 166 |
+
"Bold": "Будь прямолинеен и уверен. Короткие предложения. Призыв к действию в КАЖДОМ ответе."
|
| 167 |
+
}
|
| 168 |
+
tone_detail = tone_instructions.get(tone, tone_instructions["Professional"])
|
| 169 |
+
|
| 170 |
+
# C. BANNED WORDS
|
| 171 |
+
banned_text = f"🚫 ЗАПРЕЩЕНО использовать слова: {', '.join(banned_words)}" if banned_words else ""
|
| 172 |
|
| 173 |
context = f"""
|
| 174 |
═══════════════════════════════════════════════════════════════
|
| 175 |
[🚨 КРИТИЧЕСКИЕ ПРАВИЛА - ОБЯЗАТЕЛЬНО СОБЛЮДАТЬ]
|
| 176 |
═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
1️⃣ ТЫ: {bot_name} в компании {company}.
|
| 179 |
+
|
| 180 |
+
2️⃣ ТОН ОБЩЕНИЯ: {tone}
|
| 181 |
+
{tone_detail}
|
| 182 |
|
| 183 |
+
3️⃣ БАЗА ЗНАНИЙ (СТРОГО!):
|
| 184 |
- Отвечай ТОЛЬКО на основе [KNOWLEDGE BASE] ниже
|
| 185 |
+
- Если информации НЕТ → скажи "К сожалению, у меня нет этой информации. Менеджер свяжется с вами."
|
| 186 |
+
- НИКОГДА не придумывай цены, даты, факты!
|
| 187 |
+
- НЕ отвечай на вопросы не по теме (погода, рецепты, и т.д.)
|
| 188 |
+
|
| 189 |
+
{f"4️⃣ МЕТОДОЛОГИЯ: {methodology}" if methodology else ""}
|
| 190 |
+
|
| 191 |
+
{banned_text}
|
| 192 |
+
|
| 193 |
+
{f"5️⃣ ОСОБЫЕ ИНСТРУКЦИИ: {custom_instructions}" if custom_instructions else ""}
|
| 194 |
+
|
| 195 |
+
{f"6️⃣ ИДЕАЛЬНЫЙ КЛИЕНТ: {ideal_customer}" if ideal_customer else ""}
|
| 196 |
+
|
| 197 |
+
═══════════════════════════════════════════════════════════════
|
| 198 |
+
[📅 СИСТЕМА ЗАПИСИ]
|
| 199 |
+
═══════════════════════════════════════════════════════════════
|
| 200 |
+
Если клиент хочет записаться на встречу/консультацию:
|
| 201 |
+
1. Уточни удобную дату и время
|
| 202 |
+
2. Подтверди запись специальным тегом: [BOOK_CONFIRMED: YYYY-MM-DD HH:MM]
|
| 203 |
+
Пример: [BOOK_CONFIRMED: 2025-12-25 14:00]
|
| 204 |
|
| 205 |
═══════════════════════════════════════════════════════════════
|
| 206 |
[BOT IDENTITY]
|
| 207 |
═════════════════════════════════════════════════════���═════════
|
| 208 |
Имя: {bot_name}
|
|
|
|
| 209 |
Компания: {company}
|
|
|
|
| 210 |
"""
|
| 211 |
|
| 212 |
# C. KNOWLEDGE BASE
|
|
|
|
| 286 |
[🔔 НАПОМИНАНИЕ - ПЕРЕД КАЖДЫМ ОТВЕТОМ ПРОВЕРЬ]
|
| 287 |
═══════════════════════════════════════════════════════════════
|
| 288 |
✅ Ты {bot_name}
|
| 289 |
+
✅ Тон: {tone} ({tone_detail})
|
| 290 |
{f"❌ Запрещено: {', '.join(banned_words)}" if banned_words else ""}
|
| 291 |
{f"📝 Инструкции: {custom_instructions}" if custom_instructions else ""}
|
| 292 |
+
✅ Если клиент хочет записаться → используй [BOOK_CONFIRMED: дата время]
|
| 293 |
+
✅ Если не знаешь → скажи честно, не придумывай
|
| 294 |
⚠️ НЕ ИСПОЛЬЗУЙ Markdown (* _ ` #) - пиши обычным текстом!
|
| 295 |
═══════════════════════════════════════════════════════════════
|
| 296 |
"""
|
frontend/app/settings/brain/page.tsx
CHANGED
|
@@ -148,8 +148,7 @@ export default function BrainSettingsPage() {
|
|
| 148 |
|
| 149 |
const deleteMutation = useMutation({
|
| 150 |
mutationFn: async (id: string) => {
|
| 151 |
-
|
| 152 |
-
return Promise.resolve()
|
| 153 |
},
|
| 154 |
onSuccess: () => {
|
| 155 |
queryClient.invalidateQueries({ queryKey: ['knowledge', user?.tenant_id] })
|
|
@@ -157,6 +156,20 @@ export default function BrainSettingsPage() {
|
|
| 157 |
}
|
| 158 |
})
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
const onDrop = useCallback((acceptedFiles: File[]) => {
|
| 161 |
if (acceptedFiles.length === 0) return
|
| 162 |
|
|
@@ -618,13 +631,22 @@ export default function BrainSettingsPage() {
|
|
| 618 |
<span className="text-xs text-slate-500 font-medium bg-surface px-2 py-1 rounded border border-white/5">
|
| 619 |
{entry.source_type}
|
| 620 |
</span>
|
| 621 |
-
<
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
</div>
|
| 629 |
</div>
|
| 630 |
</div>
|
|
@@ -645,6 +667,74 @@ export default function BrainSettingsPage() {
|
|
| 645 |
</motion.div>
|
| 646 |
)}
|
| 647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
{activeTab === 'persona' && (
|
| 649 |
<motion.div
|
| 650 |
variants={container}
|
|
@@ -670,18 +760,6 @@ export default function BrainSettingsPage() {
|
|
| 670 |
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg text-white placeholder:text-slate-600 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/20 transition-all outline-none"
|
| 671 |
/>
|
| 672 |
</div>
|
| 673 |
-
<div>
|
| 674 |
-
<label className="block text-sm text-slate-300 mb-2">
|
| 675 |
-
Роль
|
| 676 |
-
</label>
|
| 677 |
-
<input
|
| 678 |
-
type="text"
|
| 679 |
-
value={botIdentity.bot_role}
|
| 680 |
-
onChange={(e) => setBotIdentity({ ...botIdentity, bot_role: e.target.value })}
|
| 681 |
-
placeholder="Менеджер, Консультант..."
|
| 682 |
-
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg text-white placeholder:text-slate-600 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/20 transition-all outline-none"
|
| 683 |
-
/>
|
| 684 |
-
</div>
|
| 685 |
</div>
|
| 686 |
</motion.div>
|
| 687 |
|
|
@@ -852,24 +930,20 @@ export default function BrainSettingsPage() {
|
|
| 852 |
</div>
|
| 853 |
</motion.div>
|
| 854 |
|
| 855 |
-
{/* Business Description */}
|
| 856 |
<motion.div variants={item} className="bg-surface-elevated rounded-2xl shadow-sm border border-white/10 p-8">
|
| 857 |
-
<div className="flex items-center gap-3 mb-
|
| 858 |
-
<div className="p-2 bg-
|
| 859 |
-
<
|
| 860 |
</div>
|
| 861 |
<div>
|
| 862 |
-
<h2 className="text-xl font-bold text-white">
|
| 863 |
-
<p className="text-sm text-slate-500">
|
| 864 |
</div>
|
| 865 |
</div>
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
onChange={(e) => setSettings({ ...settings, business_description: e.target.value })}
|
| 870 |
-
placeholder="Например: Мы продаём премиум CRM-системы для малого бизнеса. Наше главное преимущество — простота настройки и внедрения за 1 день."
|
| 871 |
-
className="w-full px-4 py-3 bg-surface border border-white/10 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none resize-none min-h-[120px]"
|
| 872 |
-
/>
|
| 873 |
</motion.div>
|
| 874 |
|
| 875 |
{/* Ideal Customer Profile */}
|
|
|
|
| 148 |
|
| 149 |
const deleteMutation = useMutation({
|
| 150 |
mutationFn: async (id: string) => {
|
| 151 |
+
return await knowledgeApi.delete(id)
|
|
|
|
| 152 |
},
|
| 153 |
onSuccess: () => {
|
| 154 |
queryClient.invalidateQueries({ queryKey: ['knowledge', user?.tenant_id] })
|
|
|
|
| 156 |
}
|
| 157 |
})
|
| 158 |
|
| 159 |
+
// Edit KB entry
|
| 160 |
+
const [editingEntry, setEditingEntry] = useState<{ id: string; content: string; category: string } | null>(null)
|
| 161 |
+
|
| 162 |
+
const updateMutation = useMutation({
|
| 163 |
+
mutationFn: async (data: { id: string; content: string; category: string }) => {
|
| 164 |
+
return await knowledgeApi.update(data.id, { content: data.content, category: data.category })
|
| 165 |
+
},
|
| 166 |
+
onSuccess: () => {
|
| 167 |
+
queryClient.invalidateQueries({ queryKey: ['knowledge', user?.tenant_id] })
|
| 168 |
+
toast.success('Обновлено', 'Запись обновлена')
|
| 169 |
+
setEditingEntry(null)
|
| 170 |
+
}
|
| 171 |
+
})
|
| 172 |
+
|
| 173 |
const onDrop = useCallback((acceptedFiles: File[]) => {
|
| 174 |
if (acceptedFiles.length === 0) return
|
| 175 |
|
|
|
|
| 631 |
<span className="text-xs text-slate-500 font-medium bg-surface px-2 py-1 rounded border border-white/5">
|
| 632 |
{entry.source_type}
|
| 633 |
</span>
|
| 634 |
+
<div className="flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
| 635 |
+
<button
|
| 636 |
+
onClick={() => setEditingEntry({ id: entry.id, content: entry.content, category: entry.category || '' })}
|
| 637 |
+
className="p-1.5 text-slate-400 hover:text-indigo-500 hover:bg-indigo-500/10 rounded-lg transition-colors"
|
| 638 |
+
title="Редактировать"
|
| 639 |
+
>
|
| 640 |
+
<BookOpen className="w-4 h-4" />
|
| 641 |
+
</button>
|
| 642 |
+
<button
|
| 643 |
+
onClick={() => deleteMutation.mutate(entry.id)}
|
| 644 |
+
className="p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-500/10 rounded-lg transition-colors"
|
| 645 |
+
title="Удалить"
|
| 646 |
+
>
|
| 647 |
+
<Trash2 className="w-4 h-4" />
|
| 648 |
+
</button>
|
| 649 |
+
</div>
|
| 650 |
</div>
|
| 651 |
</div>
|
| 652 |
</div>
|
|
|
|
| 667 |
</motion.div>
|
| 668 |
)}
|
| 669 |
|
| 670 |
+
{/* KB Edit Modal */}
|
| 671 |
+
<AnimatePresence>
|
| 672 |
+
{editingEntry && (
|
| 673 |
+
<motion.div
|
| 674 |
+
initial={{ opacity: 0 }}
|
| 675 |
+
animate={{ opacity: 1 }}
|
| 676 |
+
exit={{ opacity: 0 }}
|
| 677 |
+
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm"
|
| 678 |
+
onClick={() => setEditingEntry(null)}
|
| 679 |
+
>
|
| 680 |
+
<motion.div
|
| 681 |
+
initial={{ scale: 0.95 }}
|
| 682 |
+
animate={{ scale: 1 }}
|
| 683 |
+
exit={{ scale: 0.95 }}
|
| 684 |
+
className="bg-surface-elevated rounded-2xl shadow-xl border border-white/10 w-full max-w-2xl p-6"
|
| 685 |
+
onClick={(e) => e.stopPropagation()}
|
| 686 |
+
>
|
| 687 |
+
<div className="flex items-center justify-between mb-6">
|
| 688 |
+
<h3 className="text-xl font-bold text-white">Редактировать запись</h3>
|
| 689 |
+
<button onClick={() => setEditingEntry(null)} className="text-slate-400 hover:text-white">
|
| 690 |
+
<X className="w-5 h-5" />
|
| 691 |
+
</button>
|
| 692 |
+
</div>
|
| 693 |
+
|
| 694 |
+
<div className="space-y-4">
|
| 695 |
+
<div>
|
| 696 |
+
<label className="block text-sm text-slate-400 mb-2">Категория</label>
|
| 697 |
+
<input
|
| 698 |
+
type="text"
|
| 699 |
+
value={editingEntry.category}
|
| 700 |
+
onChange={(e) => setEditingEntry({ ...editingEntry, category: e.target.value })}
|
| 701 |
+
className="w-full px-4 py-3 bg-surface border border-white/10 rounded-xl text-white focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/20 transition-all outline-none"
|
| 702 |
+
placeholder="Категория..."
|
| 703 |
+
/>
|
| 704 |
+
</div>
|
| 705 |
+
<div>
|
| 706 |
+
<label className="block text-sm text-slate-400 mb-2">Содержимое</label>
|
| 707 |
+
<textarea
|
| 708 |
+
value={editingEntry.content}
|
| 709 |
+
onChange={(e) => setEditingEntry({ ...editingEntry, content: e.target.value })}
|
| 710 |
+
rows={10}
|
| 711 |
+
className="w-full px-4 py-3 bg-surface border border-white/10 rounded-xl text-white focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/20 transition-all outline-none resize-none"
|
| 712 |
+
placeholder="Содержимое записи..."
|
| 713 |
+
/>
|
| 714 |
+
</div>
|
| 715 |
+
</div>
|
| 716 |
+
|
| 717 |
+
<div className="flex justify-end gap-3 mt-6">
|
| 718 |
+
<button
|
| 719 |
+
onClick={() => setEditingEntry(null)}
|
| 720 |
+
className="px-4 py-2 text-slate-400 hover:text-white transition-colors"
|
| 721 |
+
>
|
| 722 |
+
Отмена
|
| 723 |
+
</button>
|
| 724 |
+
<button
|
| 725 |
+
onClick={() => updateMutation.mutate(editingEntry)}
|
| 726 |
+
disabled={updateMutation.isPending}
|
| 727 |
+
className="px-6 py-2 bg-indigo-600 hover:bg-indigo-500 text-white rounded-xl font-medium transition-colors flex items-center gap-2"
|
| 728 |
+
>
|
| 729 |
+
{updateMutation.isPending ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
| 730 |
+
Сохранить
|
| 731 |
+
</button>
|
| 732 |
+
</div>
|
| 733 |
+
</motion.div>
|
| 734 |
+
</motion.div>
|
| 735 |
+
)}
|
| 736 |
+
</AnimatePresence>
|
| 737 |
+
|
| 738 |
{activeTab === 'persona' && (
|
| 739 |
<motion.div
|
| 740 |
variants={container}
|
|
|
|
| 760 |
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg text-white placeholder:text-slate-600 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/20 transition-all outline-none"
|
| 761 |
/>
|
| 762 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
</div>
|
| 764 |
</motion.div>
|
| 765 |
|
|
|
|
| 930 |
</div>
|
| 931 |
</motion.div>
|
| 932 |
|
| 933 |
+
{/* Business Description - теперь используется KB */}
|
| 934 |
<motion.div variants={item} className="bg-surface-elevated rounded-2xl shadow-sm border border-white/10 p-8">
|
| 935 |
+
<div className="flex items-center gap-3 mb-4">
|
| 936 |
+
<div className="p-2 bg-green-500/20 rounded-xl text-green-500">
|
| 937 |
+
<CheckCircle2 className="w-6 h-6" />
|
| 938 |
</div>
|
| 939 |
<div>
|
| 940 |
+
<h2 className="text-xl font-bold text-white">Информация о бизнесе</h2>
|
| 941 |
+
<p className="text-sm text-slate-500">Вся информация берётся из Базы знаний</p>
|
| 942 |
</div>
|
| 943 |
</div>
|
| 944 |
+
<p className="text-slate-400 text-sm">
|
| 945 |
+
Добавьте информацию о вашем бизнесе, ценах и услугах во вкладке <span className="text-indigo-400 font-medium">"База знаний"</span>. AI будет использовать только эту информацию для ответов.
|
| 946 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 947 |
</motion.div>
|
| 948 |
|
| 949 |
{/* Ideal Customer Profile */}
|
frontend/lib/api.ts
CHANGED
|
@@ -169,6 +169,11 @@ export const knowledgeApi = {
|
|
| 169 |
delete: async (knowledgeId: string) => {
|
| 170 |
const response = await api.delete(`/api/v1/knowledge/${knowledgeId}`)
|
| 171 |
return response.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
|
|
|
| 169 |
delete: async (knowledgeId: string) => {
|
| 170 |
const response = await api.delete(`/api/v1/knowledge/${knowledgeId}`)
|
| 171 |
return response.data
|
| 172 |
+
},
|
| 173 |
+
|
| 174 |
+
update: async (knowledgeId: string, data: { content?: string; category?: string }) => {
|
| 175 |
+
const response = await api.put(`/api/v1/knowledge/${knowledgeId}`, data)
|
| 176 |
+
return response.data
|
| 177 |
}
|
| 178 |
}
|
| 179 |
|