AI Tool Orchestration Service

Server-Sent Events service with AI-powered tool selection for Flutter apps

Chat Processing EndpointPOST
Submit user queries for AI-powered tool selection and execution

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.

Payload: {"user_id": "user123", "query": "What's the weather like?"}
Chat History EndpointGET
Retrieve chat request history for a specific user

GET /api/chat/history/[userId]

Get all chat requests and their processing results for a specific user.

SSE Stream EndpointGET
Connect your Flutter app to receive real-time messages 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.

Message Injection EndpointPOST
Push JSON messages to a specific user's connected clients

POST /api/sse/inject/[userId]

Send JSON payload to broadcast messages to a specific user's connected Flutter clients.

Status EndpointGET
Monitor all connected users and connection statistics

GET /api/sse/status

View real-time statistics of all connected users and their connection counts.

Usage Examples

Flutter Integration Flow:

// 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?'
  })
);

Chat Processing Example:

# 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!"}'

SSE Message Types:

chat_started: Initial confirmation that processing has begun
progress: Updates during AI analysis, tool selection, and execution
completed: Final result with tool response data
error: Error messages if processing fails