Spaces:
Running

axeronis commited on
Commit
2c5de26
·
1 Parent(s): fe8c5f7

feat: expand Smart Correction with Products/Services CRUD and improved UI

Browse files
backend/alembic/versions/2026_01_09_1857-174972d4acec_add_profile_fields.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """add_profile_fields
2
+
3
+ Revision ID: 174972d4acec
4
+ Revises: 8116ec174400
5
+ Create Date: 2026-01-09 18:57:27.871252
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision: str = '174972d4acec'
17
+ down_revision: Union[str, None] = '8116ec174400'
18
+ branch_labels: Union[str, Sequence[str], None] = None
19
+ depends_on: Union[str, Sequence[str], None] = None
20
+
21
+
22
+ def upgrade() -> None:
23
+ # ### commands auto generated by Alembic - please adjust! ###
24
+ op.add_column('users', sa.Column('avatar_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
25
+ op.add_column('users', sa.Column('phone', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
26
+ # ### end Alembic commands ###
27
+
28
+
29
+ def downgrade() -> None:
30
+ # ### commands auto generated by Alembic - please adjust! ###
31
+ op.drop_column('users', 'phone')
32
+ op.drop_column('users', 'avatar_url')
33
+ # ### end Alembic commands ###
backend/app/api/auth.py CHANGED
@@ -57,10 +57,11 @@ class UserResponse(BaseModel):
57
  email: str
58
  full_name: Optional[str]
59
  avatar_url: Optional[str] = None
 
60
  tenant_id: UUID
61
  tenant_name: str
62
  is_active: bool
63
- is_superuser: bool = False # Added field
64
  role: str # OWNER or MANAGER
65
 
66
 
@@ -98,7 +99,7 @@ class ChangePasswordRequest(BaseModel):
98
  class UpdateProfileRequest(BaseModel):
99
  full_name: Optional[str] = None
100
  avatar_url: Optional[str] = None
101
- # avatar_url will be handled separately via file upload
102
 
103
 
104
  # ============================================================================
@@ -244,6 +245,7 @@ async def register(
244
  "email": new_user.email,
245
  "full_name": new_user.full_name,
246
  "avatar_url": new_user.avatar_url,
 
247
  "tenant_id": str(new_user.tenant_id),
248
  "tenant_name": new_tenant.name,
249
  "role": new_user.role,
@@ -334,6 +336,7 @@ async def login(
334
  "email": user.email,
335
  "full_name": user.full_name,
336
  "avatar_url": user.avatar_url,
 
337
  "tenant_id": str(user.tenant_id),
338
  "tenant_name": tenant.name if tenant else "Unknown",
339
  "role": user.role,
@@ -361,6 +364,7 @@ async def get_me(
361
  email=current_user.email,
362
  full_name=current_user.full_name,
363
  avatar_url=current_user.avatar_url,
 
364
  tenant_id=current_user.tenant_id,
365
  tenant_name=tenant.name if tenant else "Unknown",
366
  is_active=current_user.is_active,
@@ -383,6 +387,8 @@ async def update_me(
383
  current_user.full_name = body.full_name
384
  if body.avatar_url is not None:
385
  current_user.avatar_url = body.avatar_url
 
 
386
 
387
  session.add(current_user)
388
  await session.commit()
@@ -399,6 +405,7 @@ async def update_me(
399
  email=current_user.email,
400
  full_name=current_user.full_name,
401
  avatar_url=current_user.avatar_url,
 
402
  tenant_id=current_user.tenant_id,
403
  tenant_name=tenant.name if tenant else "Unknown",
404
  is_active=current_user.is_active,
@@ -475,6 +482,7 @@ async def google_auth(
475
  "email": existing_user.email,
476
  "full_name": existing_user.full_name,
477
  "avatar_url": existing_user.avatar_url,
 
478
  "tenant_id": str(existing_user.tenant_id),
479
  "tenant_name": tenant.name if tenant else "Unknown",
480
  "role": existing_user.role,
@@ -534,6 +542,7 @@ async def google_auth(
534
  "email": new_user.email,
535
  "full_name": new_user.full_name,
536
  "avatar_url": new_user.avatar_url,
 
537
  "tenant_id": str(new_user.tenant_id),
538
  "tenant_name": new_tenant.name,
539
  "role": new_user.role,
@@ -603,6 +612,8 @@ async def verify(
603
  "id": str(user.id),
604
  "email": user.email,
605
  "full_name": user.full_name,
 
 
606
  "tenant_id": str(user.tenant_id),
607
  "tenant_name": tenant.name if tenant else "Unknown",
608
  "role": user.role,
 
57
  email: str
58
  full_name: Optional[str]
59
  avatar_url: Optional[str] = None
60
+ phone: Optional[str] = None
61
  tenant_id: UUID
62
  tenant_name: str
63
  is_active: bool
64
+ is_superuser: bool = False
65
  role: str # OWNER or MANAGER
66
 
67
 
 
99
  class UpdateProfileRequest(BaseModel):
100
  full_name: Optional[str] = None
101
  avatar_url: Optional[str] = None
102
+ phone: Optional[str] = None
103
 
104
 
105
  # ============================================================================
 
245
  "email": new_user.email,
246
  "full_name": new_user.full_name,
247
  "avatar_url": new_user.avatar_url,
248
+ "phone": new_user.phone,
249
  "tenant_id": str(new_user.tenant_id),
250
  "tenant_name": new_tenant.name,
251
  "role": new_user.role,
 
336
  "email": user.email,
337
  "full_name": user.full_name,
338
  "avatar_url": user.avatar_url,
339
+ "phone": user.phone,
340
  "tenant_id": str(user.tenant_id),
341
  "tenant_name": tenant.name if tenant else "Unknown",
342
  "role": user.role,
 
364
  email=current_user.email,
365
  full_name=current_user.full_name,
366
  avatar_url=current_user.avatar_url,
367
+ phone=current_user.phone,
368
  tenant_id=current_user.tenant_id,
369
  tenant_name=tenant.name if tenant else "Unknown",
370
  is_active=current_user.is_active,
 
387
  current_user.full_name = body.full_name
388
  if body.avatar_url is not None:
389
  current_user.avatar_url = body.avatar_url
390
+ if body.phone is not None:
391
+ current_user.phone = body.phone
392
 
393
  session.add(current_user)
394
  await session.commit()
 
405
  email=current_user.email,
406
  full_name=current_user.full_name,
407
  avatar_url=current_user.avatar_url,
408
+ phone=current_user.phone,
409
  tenant_id=current_user.tenant_id,
410
  tenant_name=tenant.name if tenant else "Unknown",
411
  is_active=current_user.is_active,
 
482
  "email": existing_user.email,
483
  "full_name": existing_user.full_name,
484
  "avatar_url": existing_user.avatar_url,
485
+ "phone": existing_user.phone,
486
  "tenant_id": str(existing_user.tenant_id),
487
  "tenant_name": tenant.name if tenant else "Unknown",
488
  "role": existing_user.role,
 
542
  "email": new_user.email,
543
  "full_name": new_user.full_name,
544
  "avatar_url": new_user.avatar_url,
545
+ "phone": new_user.phone,
546
  "tenant_id": str(new_user.tenant_id),
547
  "tenant_name": new_tenant.name,
548
  "role": new_user.role,
 
612
  "id": str(user.id),
613
  "email": user.email,
614
  "full_name": user.full_name,
615
+ "avatar_url": user.avatar_url,
616
+ "phone": user.phone,
617
  "tenant_id": str(user.tenant_id),
618
  "tenant_name": tenant.name if tenant else "Unknown",
619
  "role": user.role,
backend/app/api/demo.py CHANGED
@@ -10,8 +10,12 @@ from app.api.deps import get_current_user
10
  from app.core.database import get_async_session
11
  from app.models.user import User
12
  from app.models.tenant import Tenant
 
 
13
  from app.services.ai_memory_manager import memory_manager
14
  from app.core.config import settings
 
 
15
 
16
  logger = logging.getLogger(__name__)
17
  router = APIRouter(prefix="/demo", tags=["Demo"])
@@ -355,6 +359,89 @@ async def confirm_smart_correction(
355
  full_value = change.get("full_value", new_value.replace("...", ""))
356
  ai_settings["ideal_customer_profile"] = full_value
357
  applied_count += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
 
359
 
360
  if applied_count > 0:
@@ -425,6 +512,35 @@ async def smart_correct(
425
  ai_identity = ai_settings.get("ai_identity", {})
426
  playbook = ai_settings.get("playbook", {})
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  # Build comprehensive context
429
  current_config = f"""
430
  === ТЕКУЩИЕ НАСТРОЙКИ AI (tenant: {tenant.id}) ===
@@ -438,6 +554,12 @@ async def smart_correct(
438
  - Тон общения: {ai_settings.get('tone_of_voice', 'Professional')}
439
  - Методология продаж: {ai_settings.get('sales_methodology', 'Consultative')}
440
 
 
 
 
 
 
 
441
  [ЗАПРЕТЫ]
442
  - Запрещённые слова: {ai_settings.get('banned_words', [])}
443
 
@@ -445,13 +567,14 @@ async def smart_correct(
445
  {ai_settings.get('custom_instructions', '(пусто)')[:500]}
446
 
447
  [PLAYBOOK - ЭТАПЫ ВОРОНКИ]
448
- {json.dumps(playbook.get('stages', []), ensure_ascii=False, indent=2)[:800] if playbook.get('stages') else '(нет этапов)'}
449
 
450
  [ДРУГОЕ]
451
  - Идеальный клиент: {ai_settings.get('ideal_customer_profile', '(не задано)')[:200]}
452
  - Описание бизнеса: {ai_settings.get('business_description', '(не задано)')[:200]}
453
  """
454
 
 
455
  # Build the analysis prompt
456
  parse_prompt = f"""Ты эксперт по настройке AI-ассистентов. Пользователь указал проблему с ответом бота.
457
 
@@ -467,14 +590,26 @@ async def smart_correct(
467
  3. Верни JSON с изменениями
468
 
469
  === ДОСТУПНЫЕ ДЕЙСТВИЯ ===
 
470
  - "set_bot_name": изменить имя бота (value: новое имя)
471
  - "set_bot_role": изменить роль (value: новая роль)
472
  - "set_bot_gender": изменить пол (value: "male" или "female")
 
473
  - "add_banned_word": добавить запрет (value: слово)
474
  - "remove_banned_word": убрать запрет (value: слово)
475
- - "add_instruction": добавить инструкцию (value: текст инструкции)
476
- - "set_tone": изменить тон (value: Professional/Friendly/Empathetic/Bold)
477
  - "update_ideal_customer": обновить профиль клиента (value: описание)
 
 
 
 
 
 
 
 
 
 
 
478
 
479
  === ФОРМАТ ОТВЕТА ===
480
  Верни JSON объект:
@@ -636,9 +771,125 @@ async def smart_correct(
636
  "section": "AI Мозг → Таргетинг",
637
  "old": old_value[:50] + "..." if old_value else "(пусто)",
638
  "new": value[:50] + "...",
639
- "full_value": value, # Full value for confirm endpoint
640
  "reason": reason
641
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
 
643
 
644
  if applied_changes:
 
10
  from app.core.database import get_async_session
11
  from app.models.user import User
12
  from app.models.tenant import Tenant
13
+ from app.models.product import Product
14
+ from app.models.booking import Service
15
  from app.services.ai_memory_manager import memory_manager
16
  from app.core.config import settings
17
+ from sqlmodel import select
18
+
19
 
20
  logger = logging.getLogger(__name__)
21
  router = APIRouter(prefix="/demo", tags=["Demo"])
 
359
  full_value = change.get("full_value", new_value.replace("...", ""))
360
  ai_settings["ideal_customer_profile"] = full_value
361
  applied_count += 1
362
+
363
+ elif "Описание бизнеса" in field or "бизнес" in field.lower():
364
+ full_value = change.get("full_value", new_value.replace("...", ""))
365
+ ai_settings["business_description"] = full_value
366
+ applied_count += 1
367
+
368
+ # PRODUCT ACTIONS
369
+ action = change.get("action", "")
370
+
371
+ if action == "update_product":
372
+ product_id = change.get("product_id")
373
+ product_field = change.get("product_field")
374
+ product_value = change.get("product_value")
375
+ if product_id and product_field and product_value is not None:
376
+ from uuid import UUID
377
+ product = await session.get(Product, UUID(product_id))
378
+ if product:
379
+ if product_field == "price":
380
+ product.price = float(product_value)
381
+ elif product_field == "name":
382
+ product.name = str(product_value)
383
+ elif product_field == "description":
384
+ product.description = str(product_value)
385
+ session.add(product)
386
+ applied_count += 1
387
+
388
+ elif action == "add_product":
389
+ product_name = change.get("product_name")
390
+ product_price = change.get("product_price", 0)
391
+ product_description = change.get("product_description", "")
392
+ if product_name:
393
+ new_product = Product(
394
+ tenant_id=tenant.id,
395
+ name=product_name,
396
+ price=float(product_price),
397
+ description=product_description,
398
+ currency="RUB"
399
+ )
400
+ session.add(new_product)
401
+ applied_count += 1
402
+
403
+ elif action == "delete_product":
404
+ product_id = change.get("product_id")
405
+ if product_id:
406
+ from uuid import UUID
407
+ product = await session.get(Product, UUID(product_id))
408
+ if product:
409
+ product.is_active = False
410
+ session.add(product)
411
+ applied_count += 1
412
+
413
+ # SERVICE ACTIONS
414
+ elif action == "update_service":
415
+ service_id = change.get("service_id")
416
+ service_field = change.get("service_field")
417
+ service_value = change.get("service_value")
418
+ if service_id and service_field and service_value is not None:
419
+ from uuid import UUID
420
+ service = await session.get(Service, UUID(service_id))
421
+ if service:
422
+ if service_field == "price":
423
+ service.price = float(service_value)
424
+ elif service_field == "name":
425
+ service.name = str(service_value)
426
+ elif service_field == "duration_minutes":
427
+ service.duration_minutes = int(service_value)
428
+ session.add(service)
429
+ applied_count += 1
430
+
431
+ elif action == "add_service":
432
+ service_name = change.get("service_name")
433
+ service_price = change.get("service_price", 0)
434
+ service_duration = change.get("service_duration", 30)
435
+ if service_name:
436
+ new_service = Service(
437
+ tenant_id=tenant.id,
438
+ name=service_name,
439
+ price=float(service_price),
440
+ duration_minutes=int(service_duration),
441
+ currency="RUB"
442
+ )
443
+ session.add(new_service)
444
+ applied_count += 1
445
 
446
 
447
  if applied_count > 0:
 
512
  ai_identity = ai_settings.get("ai_identity", {})
513
  playbook = ai_settings.get("playbook", {})
514
 
515
+ # Fetch Products (catalog)
516
+ products_result = await session.exec(
517
+ select(Product).where(Product.tenant_id == tenant.id, Product.is_active == True).limit(20)
518
+ )
519
+ products = products_result.all()
520
+
521
+ # Fetch Services (booking)
522
+ services_result = await session.exec(
523
+ select(Service).where(Service.tenant_id == tenant.id, Service.is_active == True).limit(20)
524
+ )
525
+ services = services_result.all()
526
+
527
+ # Build products list
528
+ products_text = ""
529
+ for p in products:
530
+ products_text += f" - ID:{p.id} | {p.name} | {p.price} {p.currency}"
531
+ if p.description:
532
+ products_text += f" | {p.description[:50]}"
533
+ products_text += "\n"
534
+ if not products_text:
535
+ products_text = " (нет товаров)"
536
+
537
+ # Build services list
538
+ services_text = ""
539
+ for s in services:
540
+ services_text += f" - ID:{s.id} | {s.name} | {s.price} {s.currency} | {s.duration_minutes} мин\n"
541
+ if not services_text:
542
+ services_text = " (нет услуг)"
543
+
544
  # Build comprehensive context
545
  current_config = f"""
546
  === ТЕКУЩИЕ НАСТРОЙКИ AI (tenant: {tenant.id}) ===
 
554
  - Тон общения: {ai_settings.get('tone_of_voice', 'Professional')}
555
  - Методология продаж: {ai_settings.get('sales_methodology', 'Consultative')}
556
 
557
+ [КАТАЛОГ ТОВАРОВ]
558
+ {products_text}
559
+
560
+ [УСЛУГИ И ЗАПИСИ]
561
+ {services_text}
562
+
563
  [ЗАПРЕТЫ]
564
  - Запрещённые слова: {ai_settings.get('banned_words', [])}
565
 
 
567
  {ai_settings.get('custom_instructions', '(пусто)')[:500]}
568
 
569
  [PLAYBOOK - ЭТАПЫ ВОРОНКИ]
570
+ {json.dumps(playbook.get('stages', []), ensure_ascii=False, indent=2)[:500] if playbook.get('stages') else '(нет этапов)'}
571
 
572
  [ДРУГОЕ]
573
  - Идеальный клиент: {ai_settings.get('ideal_customer_profile', '(не задано)')[:200]}
574
  - Описание бизнеса: {ai_settings.get('business_description', '(не задано)')[:200]}
575
  """
576
 
577
+
578
  # Build the analysis prompt
579
  parse_prompt = f"""Ты эксперт по настройке AI-ассистентов. Пользователь указал проблему с ответом бота.
580
 
 
590
  3. Верни JSON с изменениями
591
 
592
  === ДОСТУПНЫЕ ДЕЙСТВИЯ ===
593
+ НАСТРОЙКИ БОТА:
594
  - "set_bot_name": изменить имя бота (value: новое имя)
595
  - "set_bot_role": изменить роль (value: новая роль)
596
  - "set_bot_gender": изменить пол (value: "male" или "female")
597
+ - "set_tone": изменить тон (value: Professional/Friendly/Empathetic/Bold)
598
  - "add_banned_word": добавить запрет (value: слово)
599
  - "remove_banned_word": убрать запрет (value: слово)
600
+ - "add_instruction": добавить инструкцию (value: текст)
 
601
  - "update_ideal_customer": обновить профиль клиента (value: описание)
602
+ - "update_business_description": обновить описание бизнеса (value: описание)
603
+
604
+ КАТАЛОГ (товары):
605
+ - "update_product": изменить товар (id: UUID товара, field: "name"/"price"/"description", value: новое значение)
606
+ - "add_product": добавить товар (name: название, price: цена, description: описание)
607
+ - "delete_product": удалить товар (id: UUID товара)
608
+
609
+ УСЛУГИ (записи):
610
+ - "update_service": изменить услугу (id: UUID услуги, field: "name"/"price"/"duration_minutes", value: новое значение)
611
+ - "add_service": добавить услугу (name: название, price: цена, duration_minutes: длительность)
612
+
613
 
614
  === ФОРМАТ ОТВЕТА ===
615
  Верни JSON объект:
 
771
  "section": "AI Мозг → Таргетинг",
772
  "old": old_value[:50] + "..." if old_value else "(пусто)",
773
  "new": value[:50] + "...",
774
+ "full_value": value,
775
  "reason": reason
776
  })
777
+
778
+ elif action == "update_business_description" and value:
779
+ old_value = ai_settings.get("business_description", "")
780
+ ai_settings["business_description"] = value
781
+ applied_changes.append({
782
+ "field": "Описание бизнеса",
783
+ "section": "AI Мозг → О компании",
784
+ "old": old_value[:50] + "..." if old_value else "(пусто)",
785
+ "new": value[:50] + "...",
786
+ "full_value": value,
787
+ "reason": reason
788
+ })
789
+
790
+ # PRODUCT ACTIONS
791
+ elif action == "update_product":
792
+ product_id = change.get("id")
793
+ field = change.get("field")
794
+ if product_id and field and value:
795
+ # Find product by ID or name
796
+ product = None
797
+ for p in products:
798
+ if str(p.id) == str(product_id) or p.name.lower() == str(product_id).lower():
799
+ product = p
800
+ break
801
+
802
+ if product:
803
+ old_value = getattr(product, field, None)
804
+ applied_changes.append({
805
+ "action": "update_product",
806
+ "field": f"Товар: {product.name}",
807
+ "section": "Каталог",
808
+ "old": f"{field}: {old_value}",
809
+ "new": f"{field}: {value}",
810
+ "product_id": str(product.id),
811
+ "product_field": field,
812
+ "product_value": value,
813
+ "reason": reason
814
+ })
815
+
816
+ elif action == "add_product":
817
+ name = change.get("name")
818
+ price = change.get("price", 0)
819
+ description = change.get("description", "")
820
+ if name:
821
+ applied_changes.append({
822
+ "action": "add_product",
823
+ "field": f"Новый товар",
824
+ "section": "Каталог",
825
+ "old": "(нет)",
826
+ "new": f"{name} — {price}₽",
827
+ "product_name": name,
828
+ "product_price": float(price) if price else 0,
829
+ "product_description": description,
830
+ "reason": reason
831
+ })
832
+
833
+ elif action == "delete_product":
834
+ product_id = change.get("id")
835
+ if product_id:
836
+ product = None
837
+ for p in products:
838
+ if str(p.id) == str(product_id) or p.name.lower() == str(product_id).lower():
839
+ product = p
840
+ break
841
+ if product:
842
+ applied_changes.append({
843
+ "action": "delete_product",
844
+ "field": f"Удаление товара",
845
+ "section": "Каталог",
846
+ "old": product.name,
847
+ "new": "(удалён)",
848
+ "product_id": str(product.id),
849
+ "reason": reason
850
+ })
851
+
852
+ # SERVICE ACTIONS
853
+ elif action == "update_service":
854
+ service_id = change.get("id")
855
+ field = change.get("field")
856
+ if service_id and field and value:
857
+ service = None
858
+ for s in services:
859
+ if str(s.id) == str(service_id) or s.name.lower() == str(service_id).lower():
860
+ service = s
861
+ break
862
+
863
+ if service:
864
+ old_value = getattr(service, field, None)
865
+ applied_changes.append({
866
+ "action": "update_service",
867
+ "field": f"Услуга: {service.name}",
868
+ "section": "Записи",
869
+ "old": f"{field}: {old_value}",
870
+ "new": f"{field}: {value}",
871
+ "service_id": str(service.id),
872
+ "service_field": field,
873
+ "service_value": value,
874
+ "reason": reason
875
+ })
876
+
877
+ elif action == "add_service":
878
+ name = change.get("name")
879
+ price = change.get("price", 0)
880
+ duration = change.get("duration_minutes", 30)
881
+ if name:
882
+ applied_changes.append({
883
+ "action": "add_service",
884
+ "field": f"Новая услуга",
885
+ "section": "Записи",
886
+ "old": "(нет)",
887
+ "new": f"{name} — {price}₽, {duration} мин",
888
+ "service_name": name,
889
+ "service_price": float(price) if price else 0,
890
+ "service_duration": int(duration) if duration else 30,
891
+ "reason": reason
892
+ })
893
 
894
 
895
  if applied_changes:
backend/app/models/user.py CHANGED
@@ -25,7 +25,8 @@ class User(SQLModel, table=True):
25
  email: str = Field(unique=True, index=True)
26
  hashed_password: str
27
  full_name: Optional[str] = None
28
- avatar_url: Optional[str] = None
 
29
 
30
  # Tenant relationship
31
  tenant_id: UUID = Field(foreign_key="tenants.id")
 
25
  email: str = Field(unique=True, index=True)
26
  hashed_password: str
27
  full_name: Optional[str] = None
28
+ avatar_url: Optional[str] = Field(default=None, nullable=True)
29
+ phone: Optional[str] = Field(default=None, nullable=True)
30
 
31
  # Tenant relationship
32
  tenant_id: UUID = Field(foreign_key="tenants.id")
frontend/app/demo-chat/page.tsx CHANGED
@@ -2,7 +2,7 @@
2
 
3
  import { useState, useRef, useEffect } from 'react'
4
  import { motion } from 'framer-motion'
5
- import { Send, Bot, User, Loader2, Sparkles, Wand2, ArrowLeft, Trash2, CheckCircle, X } from 'lucide-react'
6
  import { api } from '@/lib/api'
7
  import { useToast } from '@/contexts/ToastContext'
8
  import { cn } from '@/lib/utils'
@@ -505,7 +505,7 @@ export default function DemoChatPage() {
505
  <div className="flex-1 min-w-0">
506
  <p className="text-sm font-medium text-amber-200">AI предлагает изменить настройку:</p>
507
  <p className="text-xs text-amber-300/80 mt-1">
508
- 📍 {pendingAction.display_path}
509
  </p>
510
  <p className="text-xs text-white/90 mt-1 bg-black/20 px-2 py-1 rounded font-mono truncate">
511
  → {String(pendingAction.value).substring(0, 100)}{String(pendingAction.value).length > 100 ? '...' : ''}
@@ -515,13 +515,13 @@ export default function DemoChatPage() {
515
  onClick={confirmAction}
516
  className="flex-1 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-medium rounded-lg transition-colors"
517
  >
518
- ✅ Применить
519
  </button>
520
  <button
521
  onClick={rejectAction}
522
  className="flex-1 px-3 py-1.5 bg-white/10 hover:bg-white/20 text-slate-300 text-xs font-medium rounded-lg transition-colors"
523
  >
524
- ❌ Отмена
525
  </button>
526
  </div>
527
  </div>
@@ -531,42 +531,71 @@ export default function DemoChatPage() {
531
 
532
  {/* Pending Smart Correction Confirmation */}
533
  {pendingSmartChanges && pendingSmartChanges.length > 0 && (
534
- <div className="mx-3 mb-2 p-3 bg-violet-500/10 border border-violet-500/30 rounded-xl">
535
- <div className="flex items-start gap-3">
536
- <div className="p-1.5 bg-violet-500/20 rounded-lg">
537
- <Wand2 className="w-4 h-4 text-violet-400" />
 
 
 
 
538
  </div>
539
- <div className="flex-1 min-w-0">
540
- <p className="text-sm font-medium text-violet-200">Подтвердите изменения:</p>
541
- <div className="mt-2 space-y-1 text-xs">
542
- {pendingSmartChanges.map((c: any, i: number) => (
543
- <div key={i} className="bg-black/20 rounded-lg px-2 py-1">
544
- <span className="text-violet-300">{c.field}:</span>
545
- <span className="text-red-400/70 ml-1">{c.old}</span>
546
- <span className="text-violet-400 mx-1">→</span>
547
- <span className="text-green-400">{c.new}</span>
548
- </div>
549
- ))}
550
- </div>
551
- <div className="flex gap-2 mt-3">
552
- <button
553
- onClick={confirmSmartCorrection}
554
- className="flex-1 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-medium rounded-lg transition-colors"
555
- >
556
- ✅ Применить
557
- </button>
558
- <button
559
- onClick={rejectAction}
560
- className="flex-1 px-3 py-1.5 bg-white/10 hover:bg-white/20 text-slate-300 text-xs font-medium rounded-lg transition-colors"
561
- >
562
- ❌ Отмена
563
- </button>
564
- </div>
565
  </div>
566
  </div>
567
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  )}
569
 
 
570
  {/* Input */}
571
  <div className="relative z-10 flex-shrink-0 border-t border-white/5 bg-[#0a0a15]/60 backdrop-blur-xl px-4 py-3 pb-safe">
572
  <div className="max-w-2xl mx-auto">
 
2
 
3
  import { useState, useRef, useEffect } from 'react'
4
  import { motion } from 'framer-motion'
5
+ import { Send, Bot, User, Loader2, Sparkles, Wand2, ArrowLeft, ArrowRight, Trash2, CheckCircle, X } from 'lucide-react'
6
  import { api } from '@/lib/api'
7
  import { useToast } from '@/contexts/ToastContext'
8
  import { cn } from '@/lib/utils'
 
505
  <div className="flex-1 min-w-0">
506
  <p className="text-sm font-medium text-amber-200">AI предлагает изменить настройку:</p>
507
  <p className="text-xs text-amber-300/80 mt-1">
508
+ {pendingAction.display_path}
509
  </p>
510
  <p className="text-xs text-white/90 mt-1 bg-black/20 px-2 py-1 rounded font-mono truncate">
511
  → {String(pendingAction.value).substring(0, 100)}{String(pendingAction.value).length > 100 ? '...' : ''}
 
515
  onClick={confirmAction}
516
  className="flex-1 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-medium rounded-lg transition-colors"
517
  >
518
+ Применить
519
  </button>
520
  <button
521
  onClick={rejectAction}
522
  className="flex-1 px-3 py-1.5 bg-white/10 hover:bg-white/20 text-slate-300 text-xs font-medium rounded-lg transition-colors"
523
  >
524
+ Отмена
525
  </button>
526
  </div>
527
  </div>
 
531
 
532
  {/* Pending Smart Correction Confirmation */}
533
  {pendingSmartChanges && pendingSmartChanges.length > 0 && (
534
+ <motion.div
535
+ initial={{ opacity: 0, y: 20 }}
536
+ animate={{ opacity: 1, y: 0 }}
537
+ className="mx-3 mb-2 p-4 bg-gradient-to-br from-violet-500/10 to-purple-500/5 border border-violet-500/20 rounded-2xl backdrop-blur-sm"
538
+ >
539
+ <div className="flex items-center gap-2 mb-4">
540
+ <div className="p-2 bg-violet-500/20 rounded-xl">
541
+ <Wand2 className="w-5 h-5 text-violet-400" />
542
  </div>
543
+ <div>
544
+ <h3 className="text-sm font-semibold text-white">Предлагаемые изменения</h3>
545
+ <p className="text-xs text-white/50">{pendingSmartChanges.length} изменений</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  </div>
547
  </div>
548
+
549
+ {/* Group changes by section */}
550
+ {(() => {
551
+ const groups: Record<string, any[]> = {};
552
+ pendingSmartChanges.forEach((c: any) => {
553
+ const section = c.section || 'Другое';
554
+ if (!groups[section]) groups[section] = [];
555
+ groups[section].push(c);
556
+ });
557
+
558
+ return Object.entries(groups).map(([section, changes], i) => (
559
+ <div key={i} className="mb-3">
560
+ <div className="text-xs text-violet-400/80 font-medium mb-1.5 uppercase tracking-wide">{section}</div>
561
+ <div className="space-y-1.5">
562
+ {changes.map((c: any, j: number) => (
563
+ <div key={j} className="bg-black/20 rounded-xl px-3 py-2 border border-white/5">
564
+ <div className="text-sm text-white font-medium">{c.field}</div>
565
+ <div className="flex items-center gap-2 mt-1 text-xs">
566
+ <span className="text-red-400/70 line-through">{c.old}</span>
567
+ <ArrowRight className="w-3 h-3 text-violet-400/50" />
568
+ <span className="text-green-400 font-medium">{c.new}</span>
569
+ </div>
570
+ </div>
571
+ ))}
572
+ </div>
573
+ </div>
574
+ ));
575
+ })()}
576
+
577
+ <div className="flex gap-2 mt-4">
578
+ <motion.button
579
+ whileHover={{ scale: 1.02 }}
580
+ whileTap={{ scale: 0.98 }}
581
+ onClick={confirmSmartCorrection}
582
+ className="flex-1 px-4 py-2.5 bg-gradient-to-r from-emerald-600 to-green-600 hover:from-emerald-500 hover:to-green-500 text-white text-sm font-medium rounded-xl transition-all shadow-lg shadow-emerald-500/20"
583
+ >
584
+ Применить изменения
585
+ </motion.button>
586
+ <motion.button
587
+ whileHover={{ scale: 1.02 }}
588
+ whileTap={{ scale: 0.98 }}
589
+ onClick={rejectAction}
590
+ className="px-4 py-2.5 bg-white/5 hover:bg-white/10 text-white/70 text-sm font-medium rounded-xl transition-colors border border-white/10"
591
+ >
592
+ Отмена
593
+ </motion.button>
594
+ </div>
595
+ </motion.div>
596
  )}
597
 
598
+
599
  {/* Input */}
600
  <div className="relative z-10 flex-shrink-0 border-t border-white/5 bg-[#0a0a15]/60 backdrop-blur-xl px-4 py-3 pb-safe">
601
  <div className="max-w-2xl mx-auto">