-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Overview
This issue tracks the frontend migration from the deprecated /api/chat endpoints to the unified /api/conversations API after the Phase 4 Router Unification (PR #589).
Context
- Related Issue: Phase 4: Conversation Router Unification #558 (Phase 4 Router Unification)
- Blocker For: Removing deprecated
chat_router.py - Depends On: PR feat: Implement Phase 4 Router Unification (Issue #558) #589 must be merged first
- Related: Issue Add API router tests for unified conversation endpoints #593 (API router tests)
What Changed in Backend (PR #589)
The following endpoints were unified into /api/conversations:
Chat Endpoints → Conversation Endpoints Mapping
Old Endpoint (/api/chat) |
New Endpoint (/api/conversations) |
Notes |
|---|---|---|
POST /chat/{session_id}/message |
POST /conversations/{session_id}/messages |
Message creation |
GET /chat/{session_id}/messages |
GET /conversations/{session_id}/messages |
Message retrieval |
GET /chat/{session_id}/suggestions |
GET /conversations/{session_id}/suggestions |
Question suggestions |
POST /chat/{session_id}/conversation-suggestions |
POST /conversations/{session_id}/conversation-suggestions |
Smart suggestions |
Note: All endpoints maintain the same request/response schemas for backward compatibility.
Frontend Files to Update
1. API Client Configuration (frontend/src/services/apiClient.ts)
Current state (assumed based on typical React/TypeScript setup):
// Example endpoints to migrate
const CHAT_BASE = '/api/chat';
export const chatApi = {
sendMessage: (sessionId: string, message: string) =>
axios.post(`${CHAT_BASE}/${sessionId}/message`, { message }),
getMessages: (sessionId: string) =>
axios.get(`${CHAT_BASE}/${sessionId}/messages`),
getSuggestions: (sessionId: string, currentMessage: string) =>
axios.get(`${CHAT_BASE}/${sessionId}/suggestions`, { params: { current_message: currentMessage } }),
};Required changes:
// Update base URL
const CONVERSATIONS_BASE = '/api/conversations';
export const conversationApi = {
sendMessage: (sessionId: string, message: string) =>
axios.post(`${CONVERSATIONS_BASE}/${sessionId}/messages`, { message }),
getMessages: (sessionId: string) =>
axios.get(`${CONVERSATIONS_BASE}/${sessionId}/messages`),
getSuggestions: (sessionId: string, currentMessage: string) =>
axios.get(`${CONVERSATIONS_BASE}/${sessionId}/suggestions`, { params: { current_message: currentMessage } }),
};2. Component Updates
Search for all files importing/using chat API endpoints:
# Find all references to /api/chat in frontend
grep -r "/api/chat" frontend/src/
# Find all imports of chatApi or similar
grep -r "chatApi" frontend/src/Common files that may need updates:
frontend/src/components/Chat/ChatInterface.tsxfrontend/src/components/Chat/MessageList.tsxfrontend/src/components/Chat/SuggestionPanel.tsxfrontend/src/hooks/useChat.ts(custom hook)frontend/src/contexts/ChatContext.tsx(context provider)
3. Type Definitions
Update any TypeScript interfaces referencing chat endpoints:
// Before
interface ChatApiClient {
sendMessage: (sessionId: string, message: string) => Promise<MessageResponse>;
getMessages: (sessionId: string) => Promise<Message[]>;
}
// After
interface ConversationApiClient {
sendMessage: (sessionId: string, message: string) => Promise<MessageResponse>;
getMessages: (sessionId: string) => Promise<Message[]>;
}Implementation Plan
Step 1: Create API Migration Layer (Recommended Approach)
Add a compatibility layer to support gradual migration:
// frontend/src/services/conversationApi.ts (new file)
import axios from 'axios';
const BASE_URL = '/api/conversations';
export const conversationApi = {
// Message operations
sendMessage: async (sessionId: string, message: string) => {
return axios.post(`${BASE_URL}/${sessionId}/messages`, { message });
},
getMessages: async (sessionId: string, limit?: number) => {
return axios.get(`${BASE_URL}/${sessionId}/messages`, { params: { limit } });
},
// Suggestion operations
getSuggestions: async (sessionId: string, currentMessage: string, maxSuggestions = 3) => {
return axios.get(`${BASE_URL}/${sessionId}/suggestions`, {
params: { current_message: currentMessage, max_suggestions: maxSuggestions }
});
},
getConversationSuggestions: async (sessionId: string, suggestionInput: ConversationSuggestionInput) => {
return axios.post(`${BASE_URL}/${sessionId}/conversation-suggestions`, suggestionInput);
},
};Step 2: Update Component Imports
// Before
import { chatApi } from '@/services/apiClient';
// After
import { conversationApi } from '@/services/conversationApi';Step 3: Update API Calls
// Before
const messages = await chatApi.getMessages(sessionId);
// After
const messages = await conversationApi.getMessages(sessionId);Step 4: Testing Checklist
- Message sending: Verify messages are created and displayed correctly
- Message retrieval: Verify conversation history loads properly
- Suggestions: Verify question suggestions appear as expected
- Smart suggestions: Verify conversation-aware suggestions work
- Error handling: Verify 404/401/500 errors display user-friendly messages
- Loading states: Verify spinners/skeletons appear during API calls
- Session management: Verify session creation and switching works
Step 5: Remove Old Chat API References
After verification, remove deprecated imports:
# Search for any remaining /api/chat references
grep -r "/api/chat" frontend/src/
# Remove old chatApi.ts if it exists
rm frontend/src/services/chatApi.tsAcceptance Criteria
- All frontend API calls updated to use
/api/conversationsendpoints - No references to
/api/chatremain in frontend code - All chat features work correctly with new endpoints:
- Message sending and receiving
- Message history retrieval
- Question suggestions
- Smart conversation suggestions
- Error handling works correctly (404, 401, 500 responses)
- Loading states display properly during API calls
- No console errors or warnings in browser dev tools
- Frontend integration tests pass (if they exist)
- Manual testing completed across all chat features
Estimated Effort
2-3 hours (depending on frontend codebase size)
- 30 min: Search and identify all
/api/chatreferences - 1 hour: Update API client and component imports
- 30 min: Update type definitions
- 1 hour: Manual testing and verification
Testing Strategy
Manual Testing
-
Create new conversation session
- Verify session creation works
- Verify session appears in session list
-
Send messages
- Send user message
- Verify assistant response appears
- Verify message history updates
-
Test suggestions
- Verify question suggestions load
- Click suggestion and verify it populates input
- Verify smart suggestions work with context
-
Test error scenarios
- Invalid session ID → 404 error
- Unauthenticated request → 401 error
- Server error → 500 error with user-friendly message
Automated Testing (if frontend tests exist)
// Example test update
describe('ConversationApi', () => {
it('should send message to correct endpoint', async () => {
const sessionId = 'test-session-123';
const message = 'Hello, world\!';
await conversationApi.sendMessage(sessionId, message);
expect(mockAxios.post).toHaveBeenCalledWith(
'/api/conversations/test-session-123/messages',
{ message: 'Hello, world\!' }
);
});
});Migration Safety
Backward Compatibility: The backend maintains the same request/response schemas, so this is a low-risk migration. The only changes are:
- URL path (
/api/chat→/api/conversations) - Endpoint names (
/message→/messages)
Rollback Plan: If issues arise, the deprecated chat_router.py remains functional until this migration is verified.
Follow-up Tasks
After this migration is complete:
- Verify Issue Add API router tests for unified conversation endpoints #593 (API router tests) is complete
- Remove deprecated
backend/rag_solution/router/chat_router.py - Update API documentation to remove
/api/chatreferences - Close Issue Phase 4: Conversation Router Unification #558 (Phase 4 Router Unification)
Priority
Medium-High - Required to complete Phase 4 Router Unification, but not blocking current functionality (deprecated endpoints still work).
Labels
frontendenhancementchat