Group Chat System
Last Updated: 2025-01-16
Primary Source: docs/project_status.md
Service Files: backend/src/services/groupChatPolicy.service.ts, backend/src/services/conversation.service.ts, backend/src/services/conversationLobe.service.ts
Socket Handler: backend/src/socket/groupChatHandler.ts
Frontend Components: aso-portal/src/components/groupchat/GroupChatUI.tsx, aso-portal/src/components/groupchat/GroupChatMessage.tsx, aso-portal/src/components/groupchat/GroupChatInput.tsx
Overview
The Group Chat System enables multi-participant conversations with AI NPCs (Yexian/Chinatsu) and other users. It includes policy-based information filtering to ensure sensitive system-wide knowledge is only shared with authorized participants, and supports real-time messaging via Socket.IO.
Architecture
Group Chat Flow
Core Components
1. Group Chat Policy Service
File: backend/src/services/groupChatPolicy.service.ts
Purpose: Manages information access policies for group chat conversations
Key Functions:
determineGroupChatPolicy(participantIds)
- Analyzes participant roles and account types
- Determines information sharing level
- Returns policy configuration
Policy Rules:
- System-wide knowledge: Only if all participants are trusted
- Cross-user information: Only if all participants are trusted
- Web search: Enabled by default (configurable)
- Context depth: Very high limit (1000) for full context
Information Levels:
public- Only public information, no cross-user datatrusted- Can share information between trusted participantsfull- Full access (CSO-only conversations)
filterSystemWideKnowledge(systemWideKnowledge, policy)
- Filters sensitive information based on policy
- Removes user diaries, projects, activities if not allowed
- Returns filtered knowledge object
2. Group Chat Socket Handler
File: backend/src/socket/groupChatHandler.ts
Namespace: /group
Key Features:
Authentication
- JWT token verification
- User information attached to socket
- Role-based access control
Room Management
joinRoom(conversationId)- Join conversation roomleaveRoom(conversationId)- Leave conversation room- Room format:
room_{conversationId}
Message Handling
groupMessage- User sends messageuserMessage- Broadcast user message to roomnpcResponse- Broadcast NPC response to roomnpcThinking- Indicate NPC is thinkingnpcIdle- Indicate NPC is idle
3. Conversation Service
File: backend/src/services/conversation.service.ts
Key Functions:
getConversation(conversationId)
- Retrieves conversation by ID
- Includes participants
- Returns conversation data
getConversationParticipants(conversationId)
- Gets all participants in conversation
- Returns user IDs and roles
4. Conversation Lobe Service
File: backend/src/services/conversationLobe.service.ts
Purpose: Multi-participant conversation logic
Key Features:
- Handles multiple participants
- Manages conversation context
- Integrates with policy system
Policy System
Participant Roles
Roles:
carbon- Human userssilicon- AI NPCscso- Yexian (Level-8 observer)
Account Types:
core_yexian- Core Yexian instancedeveloper- Developer accountsnpc- NPC accountspublic- Public users
Trusted Participants
Definition: Participants who are:
- CSO role, OR
- Core Yexian account type, OR
- Silicon role with developer account type
Policy Determination
Process:
- Fetch all participants
- Check if all are trusted
- Check if any are regular users (carbon + public)
- Check if CSO-only conversation
- Determine information level
- Return policy configuration
Information Filtering
Filtered Information:
- User diaries (if not trusted)
- Active projects (if not trusted)
- Recent activities (if not trusted)
- Awareness reports (if not full access)
Always Available:
- System summary (safe statistics)
- Public information
Socket.IO Events
Client → Server
joinRoom(conversationId)
- Join conversation room
- Required for receiving messages
leaveRoom(conversationId)
- Leave conversation room
- Stop receiving messages
groupMessage(data)
- Send message to conversation
- Data:
{ conversationId, message, attachmentUrls?, uploadContextId?, imageBase64Array? }
Server → Client
userMessage(payload)
- Broadcast user message to room
- Payload:
{ conversationId, sender, text, timestamp, attachments }
npcResponse(response)
- Broadcast NPC response to room
- Response:
{ conversationId, sender, text, timestamp, ... }
npcThinking({ conversationId })
- Indicate NPC is thinking
- Shows thinking indicator in UI
npcIdle({ conversationId })
- Indicate NPC is idle
- Hides thinking indicator
chatError({ message })
- Error occurred
- Display error to user
Frontend Components
Group Chat UI
File: aso-portal/src/components/groupchat/GroupChatUI.tsx
Features:
- Message history display
- Infinite scroll (load more messages)
- Auto-scroll to bottom
- Thinking indicator
- Message animations
Group Chat Message
File: aso-portal/src/components/groupchat/GroupChatMessage.tsx
Features:
- Message rendering
- User vs NPC distinction
- Attachment display
- Timestamp formatting
Group Chat Input
File: aso-portal/src/components/groupchat/GroupChatInput.tsx
Features:
- Message input
- File attachment support
- Image upload support
- Send button
Data Flow
Integration Points
ASO Service Integration
- Uses
orchestrateNpcResponse()for AI responses - Policy-aware context building
- Memory storage for conversation history
Memory System Integration
- Messages saved to memory
- Conversation context included
- Participant information stored
Authentication Integration
- JWT token verification
- User role extraction
- Permission checking
API Endpoints
Conversation Management
GET /api/conversations/:id- Get conversationGET /api/conversations/:id/participants- Get participantsPOST /api/conversations- Create conversationPOST /api/conversations/:id/participants- Add participant
Source Files
Primary Sources:
backend/src/services/groupChatPolicy.service.ts- Policy managementbackend/src/socket/groupChatHandler.ts- Socket handlerbackend/src/services/conversation.service.ts- Conversation managementbackend/src/services/conversationLobe.service.ts- Multi-participant logic
Frontend Sources:
aso-portal/src/components/groupchat/GroupChatUI.tsx- Main UIaso-portal/src/components/groupchat/GroupChatMessage.tsx- Message componentaso-portal/src/components/groupchat/GroupChatInput.tsx- Input component
Related Files:
backend/src/services/aso.service.ts- ASO orchestrationbackend/src/services/memory.service.ts- Memory storage
Related Documentation
- Authentication & Authorization - User roles and permissions
- Memory System - Memory storage
- Protocol Routing - Role-based routing
- 03-PLATFORMS/Web-Portal.md - Frontend implementation
- 00-OVERVIEW.md - Complete system overview