| 327 | |
| 328 | // Function to get detailed analysis of file content using Gemini |
| 329 | async function getDetailedFileAnalysis(repoFullName: string, filePath: string): Promise<string> { |
| 330 | // Use AbortController to handle timeouts |
| 331 | const controller = new AbortController(); |
| 332 | const timeoutId = setTimeout(() => controller.abort(), 15000); // 15 second timeout |
| 333 | |
| 334 | try { |
| 335 | const response = await fetch( |
| 336 | `/api/analyze-file-content?repo=${encodeURIComponent(repoFullName)}&path=${encodeURIComponent(filePath)}`, |
| 337 | { signal: controller.signal } |
| 338 | ); |
| 339 | |
| 340 | if (!response.ok) { |
| 341 | console.error('API response not OK:', response.status); |
| 342 | throw new Error(`Failed to fetch file analysis: ${response.status}`); |
| 343 | } |
| 344 | |
| 345 | const data = await response.json(); |
| 346 | return data.analysis || 'No detailed analysis available.'; |
| 347 | } catch (err) { |
| 348 | console.error('Error fetching file analysis:', err); |
| 349 | if (typeof err === 'object' && err !== null && 'name' in err && (err as { name?: string }).name === 'AbortError') { |
| 350 | return 'Analysis request timed out. The file might be too large or complex.'; |
| 351 | } |
| 352 | return 'Unable to generate detailed analysis for this file.'; |
| 353 | } finally { |
| 354 | clearTimeout(timeoutId); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // Use a ref to persist cached file contents across renders |
| 359 | const cachedFileContentsRef = React.useRef<{ |