Server-Sent Events service with AI-powered tool selection for Flutter apps
POST /api/chat/process
Send user queries that will be analyzed by AI, matched to appropriate tools, and executed with real-time progress updates via SSE.
GET /api/chat/history/[userId]
Get all chat requests and their processing results for a specific user.
GET /api/sse/stream/[userId]
This endpoint provides Server-Sent Events stream for a specific user. Each user gets their own isolated message stream with real-time processing updates.
POST /api/sse/inject/[userId]
Send JSON payload to broadcast messages to a specific user's connected Flutter clients.
GET /api/sse/status
View real-time statistics of all connected users and their connection counts.
// 1. Connect to SSE stream for real-time updates
String userId = "user123";
EventSource eventSource = EventSource.connect(
Uri.parse('http://your-domain/api/sse/stream/$userId')
);
eventSource.listen((event) {
Map<String, dynamic> data = jsonDecode(event.data);
switch(data['type']) {
case 'chat_started':
print('Processing started: ${data['message']}');
break;
case 'progress':
print('Progress: ${data['message']} (Step: ${data['step']})');
break;
case 'completed':
print('Completed: ${data['result']}');
break;
case 'error':
print('Error: ${data['error']}');
break;
}
});
// 2. Submit chat query
final response = await http.post(
Uri.parse('http://your-domain/api/chat/process'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'user_id': userId,
'query': 'What is the weather like in New York?'
})
);# Submit a chat query
curl -X POST http://your-domain/api/chat/process \
-H "Content-Type: application/json" \
-d '{"user_id": "user123", "query": "Send an email to john@example.com"}'
# Get chat history for a user
curl http://your-domain/api/chat/history/user123
# Direct message injection (for testing)
curl -X POST http://your-domain/api/sse/inject/user123 \
-H "Content-Type: application/json" \
-d '{"type": "notification", "message": "Hello user123!"}'