feat: Complete dashboard integration and full system testing
✅ Frontend-Backend Integration - Created API service layer (frontend/src/services/api.ts) - Updated ChatInterface component to use real API endpoints - Added project management (download, delete) functionality - Implemented proper error handling and loading states ✅ FastAPI Backend Enhancements - Fixed user_id field in project metadata - Added comprehensive API endpoints for chat, generation, and projects - Implemented WebSocket support for real-time chat - Fixed project listing and download functionality ✅ Mock Mode Implementation - Added intelligent mock responses for testing - Smart parsing of BPM, genre, and key from user input - Realistic project configurations based on user requests - Works without API keys (currently enabled) ✅ System Testing - Tested complete flow: chat → generation → download - Verified ALS file generation and format - Validated all API endpoints - Created comprehensive TESTING_REPORT.md - Created QUICK_START.md guide ✅ Bug Fixes - Fixed BPM extraction regex in mock mode - Fixed project metadata user_id inclusion - Resolved TypeScript compilation errors - Fixed import syntax for type-only imports 📊 Test Results: - Chat API: ✅ Working (mock responses) - Project Generation: ✅ Working (creates valid ALS) - Download: ✅ Working (818 byte ALS files) - Project Listing: ✅ Working (filters by user_id) - ALS Files: ✅ Valid XML/gzip format 🔧 Current Status: - MOCK_MODE=true (full functionality without API keys) - GLM4.6: Insufficient balance - Minimax M2: Endpoint 404 - Ready for production after API fixes 🤖 Features: - Multi-genre support (House, Techno, Hip-Hop, etc.) - Automatic BPM/key detection - Complete Ableton Live project structure - Project history and management Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
134
frontend/src/services/api.ts
Normal file
134
frontend/src/services/api.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* API Service for MusiaIA Frontend
|
||||
* Handles all communication with the FastAPI backend
|
||||
*/
|
||||
|
||||
const API_BASE_URL = 'http://localhost:8000';
|
||||
|
||||
export interface ChatMessageRequest {
|
||||
user_id: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ChatMessageResponse {
|
||||
response: string;
|
||||
history: Array<{
|
||||
role: string;
|
||||
content: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProjectRequest {
|
||||
user_id: string;
|
||||
requirements: string;
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
genre: string;
|
||||
bpm: number;
|
||||
key: string;
|
||||
download_url: string;
|
||||
}
|
||||
|
||||
export interface ProjectResponse extends Project {}
|
||||
|
||||
export interface UserProjectsResponse {
|
||||
projects: Project[];
|
||||
}
|
||||
|
||||
class ApiService {
|
||||
private userId: string;
|
||||
|
||||
constructor(userId: string = 'default-user') {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a chat message to the AI
|
||||
*/
|
||||
async sendChatMessage(message: string): Promise<ChatMessageResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_id: this.userId,
|
||||
message,
|
||||
} as ChatMessageRequest),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Chat request failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a music project from requirements
|
||||
*/
|
||||
async generateProject(requirements: string): Promise<ProjectResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/generate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_id: this.userId,
|
||||
requirements,
|
||||
} as ProjectRequest),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Project generation failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects for the current user
|
||||
*/
|
||||
async getUserProjects(): Promise<UserProjectsResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/projects/${this.userId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch projects: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the download URL for a project
|
||||
*/
|
||||
getProjectDownloadUrl(projectId: string): string {
|
||||
return `${API_BASE_URL}/api/download/${projectId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a project
|
||||
*/
|
||||
async deleteProject(projectId: string): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/projects/${projectId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to delete project: ${response.statusText}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a WebSocket connection for real-time chat
|
||||
*/
|
||||
createChatWebSocket(): WebSocket {
|
||||
const wsUrl = `ws://localhost:8000/ws/chat/${this.userId}`;
|
||||
return new WebSocket(wsUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export const apiService = new ApiService();
|
||||
Reference in New Issue
Block a user