The chat-interface
actor serves as the central hub for user interactions in the Claude Chat system. It manages HTTP/WebSocket connections, serves the web frontend, and coordinates communications between users and their conversation actors.
User Browser <----> chat-interface <----> chat-state (multiple instances)
|
v
anthropic-proxy
- Serve static frontend assets (HTML, CSS, JavaScript)
- Handle RESTful API requests
- Manage WebSocket connections for real-time communication
- Maintain active WebSocket connections
- Track user sessions and their active conversations
- Handle connection establishment, maintenance, and cleanup
- Maintain a registry of all conversations
- Track conversation metadata (title, creation time, message count)
- Map conversation IDs to their respective
chat-state
actor IDs
- Create new
chat-state
actors for new conversations - Monitor the health of
chat-state
actors - Handle actor recovery if needed
- Route messages from users to the appropriate
chat-state
actors - Return responses from
chat-state
actors to the correct users
struct InterfaceState {
// Active WebSocket connections
connections: HashMap<u64, ConnectionInfo>,
// Mapping of conversation IDs to actor IDs
conversation_actors: HashMap<String, String>,
// Conversation metadata for UI display
conversation_metadata: HashMap<String, ConversationMetadata>,
// Server configuration
server_config: ServerConfig,
}
struct ConnectionInfo {
connection_id: u64,
active_conversation_id: Option<String>,
connected_at: u64,
last_activity: u64,
}
struct ConversationMetadata {
id: String,
title: String,
created_at: u64,
updated_at: u64,
message_count: u32,
last_message_preview: Option<String>,
}
struct ServerConfig {
port: u16,
host: String,
max_connections: u32,
}
GET /
- Serve the main applicationGET /index.html
- Alias for main applicationGET /styles.css
- Serve application CSSGET /bundle.js
- Serve application JavaScriptGET /api/conversations
- List available conversationsGET /api/conversations/:id/metadata
- Get conversation metadataGET /api/health
- System health check
WS /ws
- WebSocket endpoint for real-time communication
{
"action": "new_conversation",
"system": "Optional system prompt"
}
{
"action": "send_message",
"conversation_id": "conv-1234567890",
"message": "User message content"
}
{
"action": "list_conversations"
}
{
"message_type": "conversation_created",
"conversation_id": "conv-1234567890",
"content": "New conversation created"
}
{
"message_type": "message",
"conversation_id": "conv-1234567890",
"content": "Assistant response content"
}
{
"message_type": "error",
"conversation_id": "conv-1234567890",
"content": "Error description",
"error": "ERROR_CODE"
}
- Receive "new_conversation" action from client
- Generate a unique conversation ID
- Spawn a new
chat-state
actor with initial parameters - Save the actor ID and conversation ID mapping
- Create basic metadata for the conversation
- Send confirmation to the client with the conversation ID
- Receive "send_message" action from client with conversation ID
- Look up the corresponding
chat-state
actor ID - Forward the message to the
chat-state
actor - Receive response from the
chat-state
actor - Update the conversation metadata (message count, timestamps)
- Forward the response to the client
- Receive "list_conversations" action from client
- Compile metadata from the
conversation_metadata
map - Return the list to the client
- Handle WebSocket disconnections gracefully
- Allow reconnection and session resumption
- Clean up abandoned connections after timeout
- Detect when a
chat-state
actor becomes unresponsive - Attempt to restart failed actors
- Provide appropriate error messages to users
- Implement connection limits and throttling if needed
- Queue messages during high load scenarios
- Add user accounts and login functionality
- Implement session management
- Support for user-specific conversation storage
- Conversation tagging and categorization
- Search functionality across conversations
- Conversation star/favorite capability
- Conversation sharing
- Collaborative chat sessions
- User permissions and access controls
- System monitoring dashboard
- Usage statistics and reporting
- User and conversation management
- Use the Theater actor model for efficient message passing
- WebSocket handling should prioritize reliability
- State should be periodically persisted to prevent data loss
- Implement clear logging for diagnostics and debugging
- Design with horizontal scaling in mind for future growth