| 438 | // ---------- Index endpoints ---------- |
| 439 | |
| 440 | async createIndex(name: string, description?: string, metadata: Record<string, unknown> = {}): Promise<{ index_id: string }> { |
| 441 | const resp = await fetch(`${API_BASE_URL}/indexes`, { |
| 442 | method: 'POST', |
| 443 | headers: { 'Content-Type': 'application/json' }, |
| 444 | body: JSON.stringify({ name, description, metadata }), |
| 445 | }); |
| 446 | if (!resp.ok) { |
| 447 | const err = await resp.json().catch(() => ({})); |
| 448 | throw new Error(`Create index error: ${err.error || resp.statusText}`); |
| 449 | } |
| 450 | return resp.json(); |
| 451 | } |
| 452 | |
| 453 | async uploadFilesToIndex(indexId: string, files: File[]): Promise<{ message: string; uploaded_files: any[] }> { |
| 454 | const fd = new FormData(); |