| 294 | } |
| 295 | |
| 296 | async uploadFiles(sessionId: string, files: File[]): Promise<{ |
| 297 | message: string; |
| 298 | uploaded_files: {filename: string, stored_path: string}[]; |
| 299 | }> { |
| 300 | try { |
| 301 | const formData = new FormData(); |
| 302 | files.forEach((file) => { |
| 303 | formData.append('files', file, file.name); |
| 304 | }); |
| 305 | |
| 306 | const response = await fetch(`${API_BASE_URL}/sessions/${sessionId}/upload`, { |
| 307 | method: 'POST', |
| 308 | body: formData, |
| 309 | }); |
| 310 | |
| 311 | if (!response.ok) { |
| 312 | const errorData = await response.json().catch(() => ({ error: 'Upload failed' })); |
| 313 | throw new Error(`Upload error: ${errorData.error || response.statusText}`); |
| 314 | } |
| 315 | return await response.json(); |
| 316 | } catch (error) { |
| 317 | console.error('File upload failed:', error); |
| 318 | throw error; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | async indexDocuments(sessionId: string): Promise<{ message: string }> { |
| 323 | try { |