Skip to content

Conversation

acepgh
Copy link

@acepgh acepgh commented Jun 22, 2025

Description

This PR introduces multi-user collaborative chat sessions to Onyx, allowing up to 3 users to participate in real-time chat conversations with AI. This is a new feature that runs alongside the existing static 'Share' functionality.

Key Features

  • Real-time collaboration: Multiple users can join and interact in the same chat thread
  • Invite-only access: Chat owners control who can join their sessions
  • Simple permissions: Owner can invite/remove participants; Collaborators can send messages
  • WebSocket integration: Real-time updates using Socket.io for instant message delivery
  • Read receipts & typing indicators: See who's active and what they've read

Implementation Details

Backend Components

  • Database schema changes with migration (26a9d522abca_add_multi_user_chat_collaboration.py)
  • API endpoints for managing collaboration (/api/chat/session/{id}/collaboration/*)
  • Socket.io server for real-time events at /ws
  • Access control updates to check participant permissions
  • Helper functions in chat_collaboration.py

Frontend Components

  • SocketService (socketService.ts): Manages WebSocket connections with hooks
  • CollaborationControls (CollaborationControls.tsx): UI for managing collaboration
  • InviteUsersModal (InviteUsersModal.tsx): Modal for inviting users
  • SocketProvider: Integrated into AppProvider for global socket management
  • Updated Messages: Shows sender information in collaborative chats
  • ChatPage Integration: Full real-time event handling for participants, typing, and messages

What's Included

Backend

  • ✅ Database migrations with new tables and columns
  • ✅ REST API endpoints for collaboration management
  • ✅ Socket.io server with JWT authentication
  • ✅ Permission-based access control
  • ✅ User search endpoint for invitations

Frontend

  • ✅ Socket.io client integration with React hooks
  • ✅ Collaboration controls UI component
  • ✅ Invite users modal with search functionality
  • ✅ Real-time participant updates
  • ✅ Typing indicators
  • ✅ Message sender attribution
  • ✅ Automatic room join/leave on navigation

Documentation

  • ✅ Comprehensive implementation guide in docs/multi-user-chat-implementation.md

Testing Instructions

  1. Run database migration: �lembic upgrade head
  2. Start the backend with Socket.io support
  3. As a chat owner:
    • Toggle 'Collaborate' switch in chat controls
    • Click 'Invite' to search and invite users
  4. As an invited user:
    • Accept the invitation (via API or future UI)
    • Join the chat session
  5. Verify real-time features:
    • Messages appear instantly for all participants
    • Typing indicators show when users are typing
    • Participant list updates when users join/leave

Limitations

  • Maximum 3 participants per chat (configurable)
  • No external email invitations
  • No invitation expiration
  • Internal users only

Note

This is a Droid-assisted PR. All changes have been implemented and tested according to the specifications.

acepgh added 10 commits June 22, 2025 12:02
- Add ChatSessionParticipant table to track participants and their roles
- Add ChatInvitation table for managing invitations
- Add collaboration_enabled field to ChatSession
- Add sender_id to ChatMessage to track message authors
- Create migration and update models/enums
- Create chat_collaboration.py with comprehensive helper functions
- Update create_new_chat_message to support sender_id parameter
- Update get_chat_session_by_id to check participant access
- Add user_can_access_chat_session with collaboration awareness
- Update get_chat_message to allow participant access
- Add python-socketio and uvicorn[standard] dependencies
- Create socketio_server.py with authentication and event handlers
- Integrate Socket.io app with main FastAPI application under /ws
- Handle events: connect, disconnect, join/leave chat, new messages, typing, read receipts
- Create comprehensive API for managing chat collaboration
- Add endpoints for enable/disable, invitations, participants
- Update chat session models to include collaboration info
- Update chat backend to return participant counts
- Include router in main application
- Replace get_user_manager with direct JWT decoding
- Fetch user from database using decoded user_id
- Simplify authentication flow
- Document database schema changes
- List all API endpoints with permissions
- Detail Socket.io events for real-time communication
- Provide usage flow example
- Outline frontend implementation requirements
- Update chat interfaces to include collaboration types
- Create Socket.io client service with hooks
- Add collaboration API client functions
- Create CollaborationControls component
- Install socket.io-client dependency
- Add SocketProvider to AppProvider with JWT token handling
- Add InviteUsersModal for user invitations
- Integrate collaboration state and socket hooks into ChatPage
- Add real-time event handlers for participants, typing, and messages
- Add collaboration control handlers for enable/disable and remove participant
- Update Messages component to display sender information
- Add user search API endpoint for invite functionality
- Update InviteUsersModal to handle correct API response format
- Fix collaboration controls positioning in ChatPage
- Feature overview and architecture
- Database schema documentation
- API endpoint reference
- WebSocket event documentation
- Frontend implementation guide
- Security considerations
- Usage guide and future improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant