Spaces:
Build error
Build error
| import axios, { type AxiosInstance } from "axios"; | |
| /** Base API URL β from env or fallback for local dev */ | |
| const getBaseUrl = (): string => | |
| typeof window !== "undefined" | |
| ? process.env.NEXT_PUBLIC_API_URL || "" | |
| : process.env.NEXT_PUBLIC_API_URL || process.env.API_URL || "http://localhost:8000"; | |
| /** API client instance */ | |
| function createApiClient(): AxiosInstance { | |
| const baseURL = getBaseUrl(); | |
| return axios.create({ | |
| baseURL: baseURL ? `${baseURL.replace(/\/$/, "")}/api/v1` : "/api/v1", | |
| headers: { "Content-Type": "application/json" }, | |
| timeout: 60_000, | |
| }); | |
| } | |
| const api = createApiClient(); | |
| // βββ Types (aligned with backend schemas) βββββββββββββββββββββββββββββββββββββ | |
| export interface GenerationRequest { | |
| prompt: string; | |
| lyrics?: string; | |
| duration?: number; | |
| style?: string; | |
| voice_preset?: string; | |
| vocal_volume?: number; | |
| instrumental_volume?: number; | |
| } | |
| /** Prompt analysis from backend (nested in metadata) */ | |
| export interface PromptAnalysis { | |
| original_prompt?: string; | |
| style?: string; | |
| tempo?: number | string; | |
| mood?: string; | |
| instrumentation?: string[]; | |
| lyrics?: string; | |
| duration_hint?: number; | |
| enriched_prompt?: string; | |
| } | |
| export interface GenerationMetadata { | |
| prompt?: string; | |
| analysis?: PromptAnalysis; | |
| } | |
| export interface GenerationResponse { | |
| id: string; | |
| status: "pending" | "processing" | "completed" | "failed"; | |
| prompt: string; | |
| audio_path?: string | null; | |
| metadata?: GenerationMetadata | null; | |
| processing_time_seconds?: number | null; | |
| error_message?: string | null; | |
| created_at?: string | null; | |
| completed_at?: string | null; | |
| } | |
| export interface GenerationListResponse { | |
| items: GenerationResponse[]; | |
| total: number; | |
| page: number; | |
| page_size: number; | |
| } | |
| // βββ API methods βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| export const generationsApi = { | |
| async create(data: GenerationRequest): Promise<GenerationResponse> { | |
| const { data: res } = await api.post<GenerationResponse>("/generations/", data); | |
| return res; | |
| }, | |
| async get(id: string): Promise<GenerationResponse> { | |
| const { data } = await api.get<GenerationResponse>(`/generations/${id}`); | |
| return data; | |
| }, | |
| async list(page: number = 1, pageSize: number = 20): Promise<GenerationListResponse> { | |
| const { data } = await api.get<GenerationListResponse>("/generations/", { | |
| params: { page, page_size: pageSize }, | |
| }); | |
| return data; | |
| }, | |
| }; | |