The old /assistant/chats/* CRUD endpoints and assistant_chat_service
chat functions were unused — the frontend exclusively uses
/ai-sessions/{id}/chat (unified_chat_service) for all chat operations.
Removed:
- Chat CRUD endpoints (create, list, get, send, delete, conclude)
- assistant_chat_service: create_chat, send_message,
generate_conclusion_summary, CONCLUSION_SYSTEM_PROMPT
- Frontend: assistantChatApi chat methods, dead types
(AssistantChat, AssistantChatMessage, ConcludeChatRequest, etc.)
Kept:
- /assistant/retention endpoints (used by ChatRetentionSettingsPage)
- Shared AI infrastructure (_call_ai, _call_anthropic_cached,
ASSISTANT_SYSTEM_PROMPT, _auto_title) — imported by unified_chat_service
Moved:
- fetch_upload_images + resize_image_for_vision → storage_service.py
(shared location, not tied to dead endpoint)
Also added "Image Analysis" section to system prompt so Claude knows
to describe attached screenshots.
-650 lines of dead code removed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
"""Chat retention settings endpoints.
|
|
|
|
GET /assistant/retention — Get account retention settings
|
|
PATCH /assistant/retention — Update retention settings (owner only)
|
|
|
|
Note: Chat CRUD endpoints were removed — the frontend uses /ai-sessions/{id}/chat
|
|
(unified_chat_service) for all chat operations. The /assistant prefix is kept for
|
|
the retention settings to avoid a frontend URL change.
|
|
"""
|
|
from typing import Annotated, Optional
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.api.deps import get_current_active_user, get_db
|
|
from app.models.user import User
|
|
from app.models.account import Account
|
|
from app.schemas.assistant_chat import (
|
|
RetentionSettingsResponse,
|
|
RetentionSettingsUpdate,
|
|
)
|
|
|
|
router = APIRouter(prefix="/assistant", tags=["assistant-chat"])
|
|
|
|
|
|
@router.get("/retention", response_model=RetentionSettingsResponse)
|
|
async def get_retention_settings(
|
|
current_user: Annotated[User, Depends(get_current_active_user)],
|
|
db: Annotated[AsyncSession, Depends(get_db)],
|
|
):
|
|
"""Get account chat retention settings."""
|
|
result = await db.execute(
|
|
select(Account).where(Account.id == current_user.account_id)
|
|
)
|
|
account = result.scalar_one_or_none()
|
|
if not account:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
|
|
|
return RetentionSettingsResponse(
|
|
chat_retention_days=account.chat_retention_days,
|
|
chat_retention_max_count=account.chat_retention_max_count,
|
|
)
|
|
|
|
|
|
@router.patch("/retention", response_model=RetentionSettingsResponse)
|
|
async def update_retention_settings(
|
|
data: RetentionSettingsUpdate,
|
|
current_user: Annotated[User, Depends(get_current_active_user)],
|
|
db: Annotated[AsyncSession, Depends(get_db)],
|
|
):
|
|
"""Update account chat retention settings (account owner only)."""
|
|
result = await db.execute(
|
|
select(Account).where(Account.id == current_user.account_id)
|
|
)
|
|
account = result.scalar_one_or_none()
|
|
if not account:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
|
|
|
if account.owner_id != current_user.id and not current_user.is_super_admin:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="Only the account owner can update retention settings",
|
|
)
|
|
|
|
if data.chat_retention_days is not None:
|
|
account.chat_retention_days = data.chat_retention_days
|
|
if data.chat_retention_max_count is not None:
|
|
account.chat_retention_max_count = data.chat_retention_max_count
|
|
|
|
await db.commit()
|
|
|
|
return RetentionSettingsResponse(
|
|
chat_retention_days=account.chat_retention_days,
|
|
chat_retention_max_count=account.chat_retention_max_count,
|
|
)
|