import React, { useState, useCallback } from 'react'; import { TopicList } from './components/TopicList'; import { ContentView } from './components/ContentView'; import { LogView } from './components/LogView'; import { QUANTUM_BANKING_TOPICS } from './constants'; import { generateStoryContent, generateStoryImage } from './services/geminiService'; import type { StoryContent, LogEntry } from './types'; import { Terminal, Download, FileText, X, BrainCircuit } from 'lucide-react'; const App: React.FC = () => { const [sessionAnalyses, setSessionAnalyses] = useState([]); const [sessionStarted, setSessionStarted] = useState(false); const [isLoading, setIsLoading] = useState(false); const [loadingStage, setLoadingStage] = useState(''); const [error, setError] = useState(null); const [logs, setLogs] = useState([]); const [showLogs, setShowLogs] = useState(false); const addLog = useCallback((message: string, type: 'info' | 'error' | 'success' = 'info') => { setLogs(prevLogs => [...prevLogs, { timestamp: new Date(), message, type }]); }, []); const handleSelectTopic = useCallback(async (topic: string) => { if (isLoading) return; setIsLoading(true); if (!sessionStarted) { setSessionStarted(true); } setError(null); addLog(`Analysis initiated for: "${topic}"`); try { // Step 1: Generate Story & Next Topics setLoadingStage('Synthesizing quantum data...'); const contentWithoutImage = await generateStoryContent(topic, sessionAnalyses); addLog(`Text analysis and topic generation successful for: "${topic}"`, 'success'); // Add partial content to show text while image loads setSessionAnalyses(prev => [...prev, { ...contentWithoutImage, imageUrl: '' }]); // Step 2: Generate Image setLoadingStage('Visualizing quantum circuits...'); const imageBase64 = await generateStoryImage(contentWithoutImage.story); addLog(`Image generation successful for topic: "${topic}"`, 'success'); const finalContent = { ...contentWithoutImage, imageUrl: `data:image/jpeg;base64,${imageBase64}` }; // Replace the last item (the one without image) with the full content setSessionAnalyses(prev => [...prev.slice(0, -1), finalContent]); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.'; console.error(errorMessage); setError(`Failed to generate analysis. ${errorMessage}`); addLog(`Error during generation: ${errorMessage}`, 'error'); // Remove the placeholder analysis that was added temporarily setSessionAnalyses(prev => prev.filter(a => a.imageUrl !== '')); } finally { setIsLoading(false); setLoadingStage(''); } }, [isLoading, addLog, sessionAnalyses, sessionStarted]); const downloadStoryAsHtml = () => { if (sessionAnalyses.length === 0) return; addLog('HTML download initiated.'); const analysesHtml = sessionAnalyses.map(analysis => `

${analysis.title}

Topic: ${analysis.topic}

Generated image for ${analysis.title}

Table of Contents

    ${analysis.tableOfContents.map(item => `
  • ${item}
  • `).join('')}

Detailed Analysis

${analysis.story.replace(/```(python|pseudocode)?\n([\s\S]*?)\n```/g, '
$2
').replace(/\n/g, '
').replace(/
(
)/g, '$1').replace(/(<\/pre>)
/g, '$1')}
`).join('
'); const htmlContent = ` Quantum Code Architect - Session Report ${analysesHtml} `; const blob = new Blob([htmlContent], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `qca-session-report-${new Date().toISOString().split('T')[0]}.html`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; (window as any).__APP_LOGS__ = logs; return (

Quantum Code Architect

AI-Powered Technical Analysis for Quantum Finance Developers

{sessionAnalyses.length > 0 && ( )}
{showLogs && (

Activity Log

)}
); }; // Helper function for downloading logs const downloadLogs = () => { const logState = (window as any).__APP_LOGS__; if (!logState || logState.length === 0) return; const logText = logState.map((log: LogEntry) => `[${new Date(log.timestamp).toISOString()}] [${log.type.toUpperCase()}] ${log.message}`).join('\n'); const blob = new Blob([logText], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `qca-logs-${new Date().toISOString()}.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; export default App;