add public chat routes

This commit is contained in:
CREDO23 2026-01-26 13:18:21 +02:00
parent 5fae0f5a58
commit 88a9e623ba
2 changed files with 65 additions and 0 deletions

View file

@ -30,6 +30,7 @@ from .notes_routes import router as notes_router
from .notifications_routes import router as notifications_router
from .notion_add_connector_route import router as notion_add_connector_router
from .podcasts_routes import router as podcasts_router
from .public_chat_routes import router as public_chat_router
from .rbac_routes import router as rbac_router
from .search_source_connectors_routes import router as search_source_connectors_router
from .search_spaces_routes import router as search_spaces_router
@ -67,3 +68,4 @@ router.include_router(circleback_webhook_router) # Circleback meeting webhooks
router.include_router(surfsense_docs_router) # Surfsense documentation for citations
router.include_router(notifications_router) # Notifications with Electric SQL sync
router.include_router(composio_router) # Composio OAuth and toolkit management
router.include_router(public_chat_router) # Public chat sharing and cloning

View file

@ -0,0 +1,63 @@
"""
Routes for public chat access (unauthenticated and mixed-auth endpoints).
"""
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from app.db import User, get_async_session
from app.schemas.new_chat import (
CloneInitiatedResponse,
PublicChatResponse,
)
from app.services.public_chat_service import (
get_public_chat,
get_thread_by_share_token,
)
from app.users import current_active_user
router = APIRouter(prefix="/public", tags=["public"])
@router.get("/{share_token}", response_model=PublicChatResponse)
async def read_public_chat(
share_token: str,
session: AsyncSession = Depends(get_async_session),
):
"""
Get a public chat by share token.
No authentication required.
Returns sanitized content (citations stripped, non-UI tools removed).
"""
return await get_public_chat(session, share_token)
@router.post("/{share_token}/clone", response_model=CloneInitiatedResponse)
async def clone_public_chat(
share_token: str,
session: AsyncSession = Depends(get_async_session),
user: User = Depends(current_active_user),
):
"""
Clone a public chat to the user's account.
Requires authentication.
Initiates a background job to copy the chat.
"""
thread = await get_thread_by_share_token(session, share_token)
if not thread:
raise HTTPException(status_code=404, detail="Not found")
# TODO: Implement Celery task for cloning
# For now, return a placeholder response
# The actual implementation will:
# 1. Get user's default search space
# 2. Queue Celery task to clone thread, messages, and podcasts
# 3. Create notification on completion
raise HTTPException(
status_code=501,
detail="Clone functionality not yet implemented",
)