CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
WorkerThreadDebugger-C74wkuOF.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"WorkerThreadDebugger-C74wkuOF.js","sources":["../../components/features/WorkerThreadDebugger.tsx"],"sourcesContent":["import React, { useState, useCallback, useEffect } from 'react';\nimport { BugAntIcon, ArrowDownTrayIcon } from '../icons.tsx';\nimport { analyzeConcurrencyStream } from '../../services/index.ts';\nimport { LoadingSpinner, MarkdownRenderer } from '../shared/index.tsx';\nimport { downloadFile } from '../../services/fileUtils.ts';\n\nconst exampleCode = `// main.js\nconst worker = new Worker('worker.js');\n\n// This object is sent back and forth.\n// A race condition can occur because both threads\n// read the counter, increment it, and send it back.\n// The final value depends on which thread's message\n// is processed last.\nconst data = { counter: 0 };\n\nworker.onmessage = function(e) {\n  // Main thread reads and updates\n  data.counter = e.data.counter;\n  console.log('Main received:', data.counter);\n  data.counter++;\n  worker.postMessage(data);\n};\n\n// Start the process\nconsole.log('Main starting with:', data.counter);\ndata.counter++;\nworker.postMessage(data);\n\n\n// worker.js\n// onmessage = function(e) {\n//   // Worker reads and updates\n//   let receivedCounter = e.data.counter;\n//   console.log('Worker received:', receivedCounter);\n//   receivedCounter++;\n//   postMessage({ counter: receivedCounter });\n// }\n`;\n\nexport const WorkerThreadDebugger: React.FC<{ codeInput?: string }> = ({ codeInput: initialCode }) => {\n    const [codeInput, setCodeInput] = useState(initialCode || exampleCode);\n    const [analysis, setAnalysis] = useState('');\n    const [isLoading, setIsLoading] = useState(false);\n    const [error, setError] = useState('');\n\n    const handleAnalyze = useCallback(async (codeToAnalyze: string) => {\n        if (!codeToAnalyze.trim()) {\n            setError('Please paste some code to analyze.');\n            return;\n        }\n        setIsLoading(true);\n        setError('');\n        setAnalysis('');\n        try {\n            const stream = analyzeConcurrencyStream(codeToAnalyze);\n            let fullResponse = '';\n            for await (const chunk of stream) {\n                fullResponse += chunk;\n                setAnalysis(fullResponse);\n            }\n        } catch (err) {\n            const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n            setError(`Failed to analyze code: ${errorMessage}`);\n        } finally {\n            setIsLoading(false);\n        }\n    }, []);\n\n    useEffect(() => {\n        if (initialCode) {\n            setCodeInput(initialCode);\n            handleAnalyze(initialCode);\n        }\n    }, [initialCode, handleAnalyze]);\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6\">\n                <h1 className=\"text-3xl font-bold flex items-center\">\n                    <BugAntIcon />\n                    <span className=\"ml-3\">AI Concurrency Analyzer</span>\n                </h1>\n                <p className=\"text-text-secondary mt-1\">Analyze JavaScript code for potential Web Worker concurrency issues.</p>\n            </header>\n            <div className=\"flex-grow flex flex-col gap-4 min-h-0\">\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label htmlFor=\"code-input\" className=\"text-sm font-medium text-text-secondary mb-2\">JavaScript Code</label>\n                    <textarea\n                        id=\"code-input\"\n                        value={codeInput}\n                        onChange={(e) => setCodeInput(e.target.value)}\n                        placeholder=\"Paste your worker-related JS code here...\"\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm\"\n                    />\n                </div>\n                 <div className=\"flex-shrink-0\">\n                    <button\n                        onClick={() => handleAnalyze(codeInput)}\n                        disabled={isLoading}\n                        className=\"btn-primary w-full max-w-xs mx-auto flex items-center justify-center px-6 py-3\"\n                    >\n                        {isLoading ? <LoadingSpinner /> : 'Analyze Code'}\n                    </button>\n                </div>\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <div className=\"flex justify-between items-center mb-2\">\n                        <label className=\"text-sm font-medium text-text-secondary\">AI Analysis</label>\n                        {analysis && !isLoading && (\n                             <button onClick={() => downloadFile(analysis, 'analysis.md', 'text/markdown')} className=\"flex items-center gap-1 px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200\">\n                                <ArrowDownTrayIcon className=\"w-4 h-4\"/> Download\n                            </button>\n                        )}\n                    </div>\n                    <div className=\"flex-grow p-4 bg-background border border-border rounded-md overflow-y-auto\">\n                        {isLoading && <div className=\"flex items-center justify-center h-full\"><LoadingSpinner /></div>}\n                        {error && <p className=\"text-red-500\">{error}</p>}\n                        {analysis && !isLoading && <MarkdownRenderer content={analysis} />}\n                        {!isLoading && !analysis && !error && <div className=\"text-text-secondary h-full flex items-center justify-center\">Analysis will appear here.</div>}\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};"],"names":["exampleCode","WorkerThreadDebugger","initialCode","codeInput","setCodeInput","useState","analysis","setAnalysis","isLoading","setIsLoading","error","setError","handleAnalyze","useCallback","codeToAnalyze","stream","analyzeConcurrencyStream","fullResponse","chunk","err","errorMessage","useEffect","jsxs","jsx","BugAntIcon","e","LoadingSpinner","downloadFile","ArrowDownTrayIcon","MarkdownRenderer"],"mappings":"gzFAMA,MAAMA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkCPC,GAAyD,CAAC,CAAE,UAAWC,KAAkB,CAClG,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAASH,GAAeF,CAAW,EAC/D,CAACM,EAAUC,CAAW,EAAIF,EAAAA,SAAS,EAAE,EACrC,CAACG,EAAWC,CAAY,EAAIJ,EAAAA,SAAS,EAAK,EAC1C,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAAS,EAAE,EAE/BO,EAAgBC,cAAY,MAAOC,GAA0B,CAC/D,GAAI,CAACA,EAAc,OAAQ,CACvBH,EAAS,oCAAoC,EAC7C,MACJ,CACAF,EAAa,EAAI,EACjBE,EAAS,EAAE,EACXJ,EAAY,EAAE,EACd,GAAI,CACA,MAAMQ,EAASC,EAAyBF,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